diff --git a/htdocs/ecm/ecmdirectory.class.php b/htdocs/ecm/ecmdirectory.class.php index 6b141d65d01..f8a17f66992 100644 --- a/htdocs/ecm/ecmdirectory.class.php +++ b/htdocs/ecm/ecmdirectory.class.php @@ -431,7 +431,7 @@ class EcmDirectory // extends CommonObject } /** - * \brief Load this->motherof array + * \brief Load this->motherof that is array(id_son=>id_parent, ...) * \return int <0 if KO, >0 if OK */ function load_motherof() @@ -469,9 +469,14 @@ class EcmDirectory // extends CommonObject * id_mere = id de la categorie mere * id_children = tableau des id enfant * label = nom de la categorie - * fulllabel = nom avec chemin complet de la categorie - * fullpath = chemin complet compose des id - * \param force Force reload of full arbo even if already loaded + * cachenbofdoc = nb of documents + * date_c = date creation + * fk_user_c = user creation + * login_c = login creation + * fullpath Full path (Added by build_path_from_id_categ call) + * fulllabel Full label (Added by build_path_from_id_categ call) + * level Level of line (Added by build_path_from_id_categ call) + * \param force Force reload of full arbo even if already loaded * \return array Tableau de array */ function get_full_arbo($force=0) @@ -481,8 +486,8 @@ class EcmDirectory // extends CommonObject return $this->cats; } - // Init this->motherof array - $this->load_motherof(); + // Init this->motherof that is array(id_son=>id_parent, ...) + $this->load_motherof(); // Charge tableau des categories $sql = "SELECT c.rowid as rowid, c.label as label,"; diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php index bde92b547a2..3394c571e45 100644 --- a/htdocs/ecm/index.php +++ b/htdocs/ecm/index.php @@ -17,16 +17,17 @@ */ /** - \file htdoc/ecm/index.php - \ingroup ecm - \brief Main page for ECM section area - \version $Id$ - \author Laurent Destailleur -*/ + \file htdoc/ecm/index.php + \ingroup ecm + \brief Main page for ECM section area + \version $Id$ + \author Laurent Destailleur + */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/ecm.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/treeview.lib.php"); require_once(DOL_DOCUMENT_ROOT."/ecm/ecmdirectory.class.php"); @@ -46,15 +47,15 @@ $user->getrights('ecm'); // Get parameters $socid = isset($_GET["socid"])?$_GET["socid"]:''; $action = isset($_GET["action"])?$_GET["action"]:$_POST['action']; +$section=isset($_GET["section"])?$_GET["section"]:$_POST['section']; +if (! $section) $section=0; -$section=$_GET["section"]; -if (! $section) $section='misc'; $upload_dir = $conf->ecm->dir_output.'/'.$section; $page=$_GET["page"]; $sortorder=$_GET["sortorder"]; $sortfield=$_GET["sortfield"]; - + $limit = $conf->liste_limit; $offset = $limit * $page ; if (! $sortorder) $sortorder="ASC"; @@ -73,10 +74,79 @@ if (! empty($_REQUEST["section"])) /******************************************************************* -* ACTIONS -* -* Put here all code to do according to value of "action" parameter -********************************************************************/ + * ACTIONS + * + * Put here all code to do according to value of "action" parameter + ********************************************************************/ + +// Envoie fichier +if ( $_POST["sendit"] && $conf->upload != 0) +{ + $result=$ecmdir->fetch($_REQUEST["section"]); + if (! $result > 0) + { + dolibarr_print_error($db,$ecmdir->error); + exit; + } + $relativepath=$ecmdir->getRelativePath(); + $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; + + if (! is_dir($upload_dir)) + { + $result=create_exdir($upload_dir); + } + + if (is_dir($upload_dir)) + { + $result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name'],0); + if ($result > 0) + { + //$mesg = '
'.$langs->trans("FileTransferComplete").'
'; + //print_r($_FILES); + $result=$ecmdir->changeNbOfFiles('+'); + } + else if ($result < 0) + { + // Echec transfert (fichier depassant la limite ?) + $langs->load("errors"); + $mesg = '
'.$langs->trans("ErrorFileNotUploaded").'
'; + // print_r($_FILES); + } + else + { + // File infected by a virus + $langs->load("errors"); + $mesg = '
'.$langs->trans("ErrorFileIsInfectedWith",$result).'
'; + } + } + else + { + // Echec transfert (fichier depassant la limite ?) + $langs->load("errors"); + $mesg = '
'.$langs->trans("ErrorFailToCreateDir",$upload_dir).'
'; + } +} + +// Remove file +if ($_POST['action'] == 'confirm_deletefile' && $_POST['confirm'] == 'yes') +{ + $result=$ecmdir->fetch($_REQUEST["section"]); + if (! $result > 0) + { + dolibarr_print_error($db,$ecmdir->error); + exit; + } + $relativepath=$ecmdir->getRelativePath(); + $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; + $file = $upload_dir . "/" . urldecode($_GET["urlfile"]); + + $result=dol_delete_file($file); + + $mesg = '
'.$langs->trans("FileWasRemoved").'
'; + + $result=$ecmdir->changeNbOfFiles('-'); + $action='file_manager'; +} // Action ajout d'un produit ou service if ($_POST["action"] == 'add' && $user->rights->ecm->setup) @@ -109,10 +179,10 @@ if ($_POST['action'] == 'confirm_deletesection' && $_POST['confirm'] == 'yes') /******************************************************************* -* PAGE -* -* Put here all code to do according to value of "action" parameter -********************************************************************/ + * PAGE + * + * Put here all code to do according to value of "action" parameter + ********************************************************************/ llxHeader(); @@ -143,11 +213,14 @@ print $langs->trans("ECMAreaDesc")."
"; print $langs->trans("ECMAreaDesc2")."
"; print "
\n"; +// Confirm remove file +if ($_GET['action'] == 'delete') +{ + $form->form_confirm($_SERVER["PHP_SELF"].'?section='.$_REQUEST["section"].'&urlfile='.urldecode($_GET["urlfile"]), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile'); + print '
'; +} -print ''; -// Right area - - - - - -print '
'; - -// Left area - +if ($mesg) { print $mesg."
"; } // Tool bar $selected='file_manager'; @@ -155,14 +228,18 @@ if (eregi('search',$action)) $selected='search_form'; $head = ecm_prepare_head_fm($fac); dolibarr_fiche_head($head, $selected, '', 1); -print ''; + + // Actions buttons -print '
'; +print '
'; + +print '\n"; @@ -272,10 +352,10 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action)) // Edit link print ''; - + // Add link print ''; - + // Info print ''; - + print "\n"; - + $oldvallevel=$val['level']; - $nbofentries++; + $nbofentries++; } } } - + // Manual sections title line - print '
'; + +// Left area +print ''; print ''; print ''; print ''; @@ -242,9 +322,9 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action)) print ''; //print ''; print ''; - - $sectionauto=dol_sort_array($sectionauto,'label',$sortorder,true,false); - + + $sectionauto=dol_sort_array($sectionauto,'label','ASC',true,false); + $nbofentries=0; $oldvallevel=0; foreach ($sectionauto as $key => $val) @@ -252,8 +332,8 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action)) if ($val['test']) { $var=false; - - print ''; + + print ''; // Section print '
'; if (eregi('search',$action)) { //print_fiche_titre($langs->trans("ECMManualOrg")); - + print '
'; - print ''; + print '
'; print ""; print ''; print "'; @@ -171,14 +248,14 @@ if (eregi('search',$action)) print "'; print "
'.$langs->trans("ECMSearchByKeywords").'
".$langs->trans("Ref").':
".$langs->trans("Keyword").':
"; //print $langs->trans("ECMManualOrgDesc"); - + //print_fiche_titre($langs->trans("ECMAutoOrg")); - + print '
'; print ''; print ""; print ''; - + $buthtml=''; $butshown=0; foreach($sectionauto as $section) @@ -195,44 +272,47 @@ if (eregi('search',$action)) $butshown++; } if ($butshown % 2 == 1) print ''; - + print ''; print "
'.$langs->trans("ECMSearchByEntity").'
  
"; //print $langs->trans("ECMAutoOrgDesc"); } -if (empty($action) || $action == 'file_manager' || eregi('refresh',$action)) +if (empty($action) || $action == 'file_manager' || eregi('refresh',$action) || $action == 'delete') { + $userstatic = new User($db); + $ecmdirstatic = new ECMDirectory($db); + // Confirmation de la suppression d'une ligne categorie if ($_GET['action'] == 'delete_section') { $form->form_confirm($_SERVER["PHP_SELF"].'?section='.urldecode($_GET["section"]), $langs->trans('DeleteSection'), $langs->trans('ConfirmDeleteSection',$ecmdir->label), 'confirm_deletesection'); print '
'; } - - if ($mesg) { print $mesg."
"; } - - + // Construit liste des répertoires print ''; - + print ''; - print ''; + print ''; print ''; - + if (sizeof($sectionauto)) { // Automatic sections title line - print ''; + print ''; + print '
'; + print ''.$langs->trans("ECMSections").''; print ''.$langs->trans("Refresh").' '.img_picto($langs->trans("Refresh"),'refresh').''; print '
'; + print '
'; print ''; print ''; - print '
'; print img_picto_common('','treemenu/base.gif'); print ''.$langs->trans("ECMRoot").' ('.$langs->trans("ECMSectionAuto").')'; print '
'; + print '
   '.$langs->trans("ECMNbOfDocsSmall").' '.img_picto($langs->trans("Refresh"),'refresh').'
'; @@ -261,8 +341,8 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action)) print tree_showpad($sectionauto,$key); print ''; print img_picto('','object_dir'); - print ''; - print '  '; + print ' '; + print ''; print $val['label']; print '
'; print "
  '; $htmltooltip=''.$langs->trans("ECMSection").': '.$val['label'].'
'; @@ -284,17 +364,17 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action)) $htmltooltip.=''.$langs->trans("Description").': '.$val['desc']; print $form->textwithhelp('',$htmltooltip,1,0); print '
'; + print '
'; print ''; print ''; print ''; - print ''; + //print ''; + print ''; print ''; print ''; - - $ecmdirstatic = new ECMDirectory($db); - $rub=$ecmdirstatic->get_full_arbo(); - - $userstatic = new User($db); - + + $fulltree=$ecmdirstatic->get_full_arbo(); + + // Define fullpathselected ( _x_y_z ) + $fullpathselected=''; + foreach($fulltree as $key => $val) + { + //print $val['id']."-".$section."
"; + if ($val['id'] == $section) + { + $fullpathselected=$val['fullpath']; + break; + } + } + //print "fullpathselected=".$fullpathselected."
"; + $nbofentries=0; $oldvallevel=0; $var=true; - foreach($rub as $key => $val) + foreach($fulltree as $key => $val) { $var=false; $ecmdirstatic->id=$val['id']; $ecmdirstatic->ref=$val['label']; - + // Refresh cache if (eregi('refresh',$_GET['action'])) { $result=$ecmdirstatic->fetch($val['id']); $ecmdirstatic->ref=$ecmdirstatic->label; - + $result=$ecmdirstatic->refreshcachenboffile(); $val['cachenbofdoc']=$result; } - - - print ''; - - // Section - print '\n"; - - // Nb of docs - print ''; - - // Edit link - print ''; - - // Add link - print ''; - - // Info - print '"; - - print "\n"; - + + // Show line if level 1 or level selected + $showline=0; + $fullpathparent=eregi_replace('_[^_]+$','',$val['fullpath']); + // If directory is son of selected directory, we show line + if ($val['id_mere'] == $section) $showline=5; + // If directory is brother of selected directory, we show line + elseif ($val['id'] != $section && $val['id_mere'] == $ecmdirstatic->motherof[$section]) $showline=4; + // If directory is parent of selected directory or is selected directory, we show line + elseif (eregi($val['fullpath'].'_',$fullpathselected.'_')) $showline=3; + // If parent directory is in a same path than selected directory + elseif (eregi($fullpathparent.'_',$fullpathselected.'_')) $showline=2; + // If we are level one we show line + elseif ($val['level'] < 2) $showline=1; + + if ($showline) + { + print ''; + + // Show tree graph pictos + print '\n"; + + // Nb of docs + print ''; + + // Edit link + print ''; + + // Add link + //print ''; + print ''; + + // Info + print '"; + + print "\n"; + } + $oldvallevel=$val['level']; $nbofentries++; } - - // If nothing to show + + // If nothing to show if ($nbofentries == 0) { print ''; } - + print "
'; print img_picto_common('','treemenu/base.gif'); @@ -304,89 +384,155 @@ if (empty($action) || $action == 'file_manager' || eregi('refresh',$action)) print ''; print ' '.img_edit_add().''.img_edit_add().' '; $htmltooltip=$langs->trans("ECMAreaDesc2"); print $form->textwithhelp('',$htmltooltip,1,0); print '
'; - print '
'; - print tree_showpad($rub,$key); - print ''; - print $ecmdirstatic->getNomUrl(1,'index'); - print ''; - print ' 
'; - print "
'.$val['cachenbofdoc'].''.img_edit().''.img_edit_add().''; - $userstatic->id=$val['fk_user_c']; - $userstatic->nom=$val['login_c']; - $htmltooltip=''.$langs->trans("ECMSection").': '.$val['label'].'
'; - $htmltooltip=''.$langs->trans("Type").': '.$langs->trans("ECMManualOrg").'
'; - $htmltooltip.=''.$langs->trans("ECMCreationUser").': '.$userstatic->getNomUrl(1).'
'; - $htmltooltip.=''.$langs->trans("ECMCreationDate").': '.dolibarr_print_date($val['date_c'],"dayhour").'
'; - $htmltooltip.=''.$langs->trans("Description").': '.$val['description']; - print $form->textwithhelp('',$htmltooltip,1,0); - print "
'; + print ''; + // Show picto + print ''; + // Show link + print ''; + print ''; + print '
'; + print tree_showpad($fulltree,$key); + print ''; + //print $fullpathparent.'-'.$val['fullpath']."(".$showline.")"; + if ($showline == 5) print img_picto('','/theme/common/treemenu/plustop2.gif','',1).img_picto('','/theme/common/treemenu/folder.gif','',1); + elseif ($showline == 4) print img_picto('','/theme/common/treemenu/plustop2.gif','',1).img_picto('','/theme/common/treemenu/folder.gif','',1); + elseif ($showline == 3) print img_picto('','/theme/common/treemenu/minustop2.gif','',1).img_picto('','/theme/common/treemenu/folder-expanded.gif','',1); + elseif ($showline == 2) print img_picto('','/theme/common/treemenu/plustop2.gif','',1).img_picto('','/theme/common/treemenu/folder.gif','',1); + elseif ($showline == 1) print img_picto('','/theme/common/treemenu/plustop2.gif','',1).img_picto('','/theme/common/treemenu/folder.gif','',1); + print ''; + if ($section == $val['id']) print ' '; + print $ecmdirstatic->getNomUrl(0,'index'); + if ($section == $val['id']) print ''; + print ' 
'; + print "
'.$val['cachenbofdoc'].''.img_edit().''.img_edit_add().' '; + $userstatic->id=$val['fk_user_c']; + $userstatic->nom=$val['login_c']; + $htmltooltip=''.$langs->trans("ECMSection").': '.$val['label'].'
'; + $htmltooltip=''.$langs->trans("Type").': '.$langs->trans("ECMManualOrg").'
'; + $htmltooltip.=''.$langs->trans("ECMCreationUser").': '.$userstatic->getNomUrl(1).'
'; + $htmltooltip.=''.$langs->trans("ECMCreationDate").': '.dolibarr_print_date($val['date_c'],"dayhour").'
'; + $htmltooltip.=''.$langs->trans("Description").': '.$val['description']; + print $form->textwithhelp('',$htmltooltip,1,0); + print "
'.$langs->trans("ECMNoDirecotyYet").'
"; // Fin de zone Ajax +} + +print '
'; + +print '
'; + +// Right area +$relativepath=$ecmdir->getRelativePath(); +$upload_dir = $conf->ecm->dir_output.'/'.$relativepath; +$filearray=dol_dir_list($upload_dir,"files",0,'','\.meta$',$sortfield,(strtolower($sortorder)=='desc'?SORT_ASC:SORT_DESC),1); + +$formfile=new FormFile($db); +$param='&section='.$section; +$formfile->list_of_documents($filearray,'','ecm',$param,1,$relativepath,$user->rights->ecm->create,1); + +// print ''; + +// print '
'; + + + +print '
'; if ($user->rights->ecm->setup) { print ''.$langs->trans('ECMAddSection').''; @@ -395,22 +541,15 @@ else { print ''.$langs->trans('ECMAddSection').''; } -print ''; - - -} - -print '
'; - print '
'; +if ($user->rights->ecm->create && ! empty($section)) +{ + $formfile->form_attach_new_file(DOL_URL_ROOT.'/ecm/index.php','',0,$section,1); +} +else print ' '; +print '
'; +print ''; print '
'; diff --git a/htdocs/html.formfile.class.php b/htdocs/html.formfile.class.php index 7272684a185..a73f5f1892c 100644 --- a/htdocs/html.formfile.class.php +++ b/htdocs/html.formfile.class.php @@ -46,12 +46,12 @@ class FormFile /** - * \brief Affiche formulaire ajout fichier + * \brief Show file add form * \param url Url * \param titre Titre zone * \param addcancel 1=Ajoute un bouton 'Annuler' * \param sectionid If upload must be done inside a particular ECM section - * \return int <0 si ko, >0 si ok + * \return int <0 si ko, >0 si ok */ function form_attach_new_file($url,$titre='',$addcancel=0, $sectionid=0) { @@ -98,7 +98,7 @@ class FormFile print ""; print ''; - print '
'; + if (empty($sectionid)) print '
'; print "\n\n\n"; } @@ -384,17 +384,18 @@ class FormFile * \param forcedownload Mime type is forced to 'application/binary' to have a download * \param relativepath Relative path of docs (autodefined if not provided) * \param permtodelete Permission to delete - * \return int <0 if KO, nb of files shown if OK + * \param useinecm Change output for use in ecm module + * \return int <0 if KO, nb of files shown if OK */ - function list_of_documents($filearray,$object,$modulepart,$param,$forcedownload=0,$relativepath='',$permtodelete=1) + function list_of_documents($filearray,$object,$modulepart,$param,$forcedownload=0,$relativepath='',$permtodelete=1,$useinecm=0) { global $user, $conf, $langs; global $bc; global $sortfield, $sortorder; // Affiche liste des documents existant - print_titre($langs->trans("AttachedFiles")); - + if (empty($useinecm)) print_titre($langs->trans("AttachedFiles")); + else { $bc[true]=''; $bc[false]=''; }; $url=$_SERVER["PHP_SELF"]; print ''; print ''; diff --git a/htdocs/lib/treeview.lib.php b/htdocs/lib/treeview.lib.php index b113ce1ee14..7d95e71db88 100644 --- a/htdocs/lib/treeview.lib.php +++ b/htdocs/lib/treeview.lib.php @@ -24,13 +24,14 @@ * \version $Id$ */ + /** * Show picto of a tree view * * @param unknown_type $tab Array of entries in correct order - * @param unknown_type $key Key of value + * @param unknown_type $key Key of value to show picto */ -function tree_showpad(&$tab,$key) +function tree_showpad(&$tab,$key,$selected=0) { $pos=1; while ($pos <= $tab[$key]['level'] && $tab[$key]['level'] > 0) @@ -54,8 +55,6 @@ function tree_showpad(&$tab,$key) - - // ------------------------------- Used by enu editor ----------------- /** diff --git a/htdocs/theme/common/treemenu/branch.gif b/htdocs/theme/common/treemenu/branch.gif index 32e0f683d80..7c568e46f87 100644 Binary files a/htdocs/theme/common/treemenu/branch.gif and b/htdocs/theme/common/treemenu/branch.gif differ diff --git a/htdocs/theme/common/treemenu/branchbottom.gif b/htdocs/theme/common/treemenu/branchbottom.gif index 55ceb453fba..8fd24836533 100644 Binary files a/htdocs/theme/common/treemenu/branchbottom.gif and b/htdocs/theme/common/treemenu/branchbottom.gif differ diff --git a/htdocs/theme/common/treemenu/branchtop.gif b/htdocs/theme/common/treemenu/branchtop.gif index f6bd127b420..e1dfbcfa1b4 100644 Binary files a/htdocs/theme/common/treemenu/branchtop.gif and b/htdocs/theme/common/treemenu/branchtop.gif differ diff --git a/htdocs/theme/common/treemenu/line.gif b/htdocs/theme/common/treemenu/line.gif index a567ef9e53e..46c38e04c21 100644 Binary files a/htdocs/theme/common/treemenu/line.gif and b/htdocs/theme/common/treemenu/line.gif differ diff --git a/htdocs/theme/common/treemenu/minus.gif b/htdocs/theme/common/treemenu/minus.gif index a2bff1276c7..010ab770969 100644 Binary files a/htdocs/theme/common/treemenu/minus.gif and b/htdocs/theme/common/treemenu/minus.gif differ diff --git a/htdocs/theme/common/treemenu/minustop2.gif b/htdocs/theme/common/treemenu/minustop2.gif new file mode 100644 index 00000000000..0675a8fc023 Binary files /dev/null and b/htdocs/theme/common/treemenu/minustop2.gif differ diff --git a/htdocs/theme/common/treemenu/plus.gif b/htdocs/theme/common/treemenu/plus.gif index 5bc24cfb746..ae746fb1cfd 100644 Binary files a/htdocs/theme/common/treemenu/plus.gif and b/htdocs/theme/common/treemenu/plus.gif differ diff --git a/htdocs/theme/common/treemenu/plusbottom.gif b/htdocs/theme/common/treemenu/plusbottom.gif index 4aa0bde92f5..ab5bccc456b 100644 Binary files a/htdocs/theme/common/treemenu/plusbottom.gif and b/htdocs/theme/common/treemenu/plusbottom.gif differ diff --git a/htdocs/theme/common/treemenu/plustop2.gif b/htdocs/theme/common/treemenu/plustop2.gif new file mode 100644 index 00000000000..5abc420e4cf Binary files /dev/null and b/htdocs/theme/common/treemenu/plustop2.gif differ