From 9d43f5ff0e6fcfb25dd03f64d7b7800a5dbacd6b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 28 Apr 2008 21:19:01 +0000 Subject: [PATCH] =?UTF-8?q?Module=20GED=20accepte=20creation=20hierarchie?= =?UTF-8?q?=20de=20r=E9pertoires=20et=20fichiers=20en=20upload.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/categories/categorie.class.php | 42 ++--- htdocs/categories/fiche.php | 3 +- htdocs/categories/liste.php | 3 +- htdocs/ecm/docdir.php | 184 +++++---------------- htdocs/ecm/docmine.php | 44 ++--- htdocs/ecm/ecmdirectory.class.php | 226 +++++++++++++++++++++++--- htdocs/ecm/index.php | 171 ++++++++++++++++++- htdocs/ecm/pre.inc.php | 3 +- htdocs/langs/fr_FR/ecm.lang | 87 +++++----- htdocs/lib/functions.lib.php | 27 +++ 10 files changed, 512 insertions(+), 278 deletions(-) diff --git a/htdocs/categories/categorie.class.php b/htdocs/categories/categorie.class.php index 52063b9c4e6..23fab0b1810 100644 --- a/htdocs/categories/categorie.class.php +++ b/htdocs/categories/categorie.class.php @@ -490,10 +490,10 @@ class Categorie $sql.= " FROM ".MAIN_DB_PREFIX."categorie_association"; dolibarr_syslog("Categorie::get_full_arbo sql=".$sql); - $res = $this->db->query ($sql); - if ($res) + $resql = $this->db->query ($sql); + if ($resql) { - while ($obj= $this->db->fetch_object($res)) + while ($obj= $this->db->fetch_object($resql)) { $this->motherof[$obj->id_fille]=$obj->id_mere; } @@ -513,12 +513,12 @@ class Categorie $sql.= " ORDER BY c.label, c.rowid"; dolibarr_syslog("Categorie::get_full_arbo sql=".$sql); - $res = $this->db->query ($sql); - if ($res) + $resql = $this->db->query($sql); + if ($resql) { $this->cats = array(); $i=0; - while ($obj = $this->db->fetch_object($res)) + while ($obj = $this->db->fetch_object($resql)) { $this->cats[$obj->rowid]['id'] = $obj->rowid; @@ -556,40 +556,18 @@ class Categorie $this->build_path_from_id_categ($key,0); } - $this->cats=$this->sabsi($this->cats,'fulllabel', 'asc', true, false); + $this->cats=dol_sort_array($this->cats, 'fulllabel', 'asc', true, false); //$this->debug_cats(); return $this->cats; } - - /** - * \brief Advanced sort array by second index function, which produces - * ascending (default) or descending output and uses optionally - * natural case insensitive sorting (which can be optionally case - * sensitive as well). - */ - function sabsi ($array, $index, $order='asc', $natsort, $case_sensitive) - { - if (is_array($array) && count($array)>0) - { - foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index]; - if (!$natsort) ($order=='asc') ? asort($temp) : arsort($temp); - else - { - ($case_sensitive) ? natsort($temp) : natcasesort($temp); - if($order!='asc') $temp=array_reverse($temp,TRUE); - } - foreach(array_keys($temp) as $key) (is_numeric($key))? $sorted[]=$array[$key] : $sorted[$key]=$array[$key]; - return $sorted; - } - return $array; - } - /** * \brief Calcule les propriétés fullpath et fulllabel d'une categorie * du tableau this->cats et de toutes ces enfants + * \param id_categ id_categ entry to update + * \param protection Deep counter to avoid infinite loop */ function build_path_from_id_categ($id_categ,$protection=0) { @@ -606,6 +584,8 @@ class Categorie $this->cats[$id_categ]['fullpath']='_'.$id_categ; $this->cats[$id_categ]['fulllabel']=$this->cats[$id_categ]['label']; } + // We count number of _ to have level + $this->cats[$id_categ]['level']=strlen(eregi_replace('[^_]','',$this->cats[$id_categ]['fullpath'])); // Traite ces enfants $protection++; diff --git a/htdocs/categories/fiche.php b/htdocs/categories/fiche.php index 2d6c4e4c617..fbfc66d9f31 100644 --- a/htdocs/categories/fiche.php +++ b/htdocs/categories/fiche.php @@ -17,14 +17,13 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ */ /** \file htdocs/categories/fiche.php \ingroup category \brief Page creation nouvelle categorie + \version $Id$ */ require "./pre.inc.php"; diff --git a/htdocs/categories/liste.php b/htdocs/categories/liste.php index aeb84f4ed36..9f78de910f8 100644 --- a/htdocs/categories/liste.php +++ b/htdocs/categories/liste.php @@ -15,14 +15,13 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ */ /** \file htdocs/categories/liste.php \ingroup category \brief Page liste des categories + \version $Id$ */ require "./pre.inc.php"; diff --git a/htdocs/ecm/docdir.php b/htdocs/ecm/docdir.php index e649f514b21..af26955951a 100644 --- a/htdocs/ecm/docdir.php +++ b/htdocs/ecm/docdir.php @@ -17,15 +17,16 @@ */ /** - \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."/ecm/htmlecm.form.class.php"); require_once(DOL_DOCUMENT_ROOT."/ecm/ecmdirectory.class.php"); // Load traductions files @@ -37,6 +38,7 @@ $langs->load("orders"); $langs->load("propal"); $langs->load("bills"); $langs->load("contracts"); +$langs->load("categories"); // Load permissions $user->getrights('ecm'); @@ -51,10 +53,10 @@ $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="DESC"; +if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="label"; $ecmdir = new ECMDirectory($db); @@ -70,10 +72,10 @@ if (! empty($_GET["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 + ********************************************************************/ // Action ajout d'un produit ou service if ($_POST["action"] == 'add' && $user->rights->ecm->setup) @@ -81,12 +83,13 @@ if ($_POST["action"] == 'add' && $user->rights->ecm->setup) $ecmdir->ref = $_POST["ref"]; $ecmdir->label = $_POST["label"]; $ecmdir->description = $_POST["desc"]; + $ecmdir->fk_parent = $_POST["catParent"]; $id = $ecmdir->create($user); if ($id > 0) { - Header("Location: ".$_SERVER["PHP_SELF"]); + Header("Location: ".DOL_URL_ROOT.'/ecm/docmine.php?section='.$id); exit; } else @@ -107,17 +110,16 @@ 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(); $form=new Form($db); -$ecmdirstatic = new ECMDirectory($db); -$userstatic = new User($db); - +$formecm=new FormEcm($db); + if ($_GET["action"] == 'create') { //*********************** @@ -125,24 +127,28 @@ if ($_GET["action"] == 'create') //*********************** print '
'; print ''; - + $title=$langs->trans("ECMNewSection"); print_fiche_titre($title); if ($mesg) { print $mesg."
"; } - + print ''; // Label - print ''; + print ''."\n"; + + print ''."\n"; // Description print '"; - - print ''; + print ''."\n"; + + print ''."\n"; print '
'.$langs->trans("Label").'
'.$langs->trans("Label").'
'.$langs->trans ("AddIn").''; + print $formecm->select_all_sections($ecmdir->parent,'catParent'); + print '
'.$langs->trans("Description").''; print ''; - print "
'; print '
'; @@ -155,146 +161,40 @@ if (! $_GET["action"] || $_GET["action"] == 'delete_section') // List //*********************** print_fiche_titre($langs->trans("ECMSectionOfDocuments")); - + print '
'; + +/* $ecmdir->ref=$ecmdir->label; print $langs->trans("ECMSection").': '; print img_picto('','object_dir').' '; print ''.$langs->trans("ECMRoot").''; //print ' -> '.$ecmdir->getNomUrl(1).'
'; print "

"; - - /* - * Confirmation de la suppression d'une ligne categorie - */ +*/ + + // 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 '
'; } - // Construit liste des répertoires - if ($mesg) { print $mesg."
"; } - print ''; - print ''; - $param='&socid='.$socid; - print_liste_field_titre($langs->trans("ECMSection"),$_SERVER["PHP_SELF"],"label","",$param,'align="left"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"","",$param,'align="left"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Description"),$_SERVER["PHP_SELF"],"description","",$param,'align="left"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("ECMCreationUser"),$_SERVER["PHP_SELF"],"fk_user_c","",$param,'align="left"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("ECMCreationDate"),$_SERVER["PHP_SELF"],"date_c","",$param,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("ECMNbOfDocs"),$_SERVER["PHP_SELF"],"cachenbofdoc","",$param,'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Action"),$_SERVER["PHP_SELF"],"","",$param,'align="right"',$sortfield,$sortorder); - print ''; - - - $sql ="SELECT ed.rowid, ed.label, ed.description, ed.cachenbofdoc, ed.fk_user_c, ed.fk_user_m,"; - $sql.=" ed.date_c,"; - $sql.=" ed.date_m,"; - $sql.=" ed.fk_parent,"; - $sql.=" u.login"; - $sql.=" FROM ".MAIN_DB_PREFIX."ecm_directories as ed"; - $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = ed.fk_user_c"; - $sql.=" ORDER BY label"; - $resql=$db->query($sql); - if ($resql) - { - $var=true; - $obj = $db->fetch_object($resql); - while ($obj) - { - $var=!$var; - - $ecmdirstatic->id=$obj->rowid; - $ecmdirstatic->ref=$obj->label; - - print ''; - - // Section - print '\n"; - - // Type - print '\n"; - - // Description - print ''; - $userstatic->id=$obj->fk_user_c; - $userstatic->nom=$obj->login; - print ''; - print ''; - - // Nb of docs - //print ''; - print ''; - - print '\n"; - $obj = $db->fetch_object($resql); - } - } - else - { - dolibarr_print_error($db); - } - // Ajout rubriques automatiques - $sectionauto=array( 0 => array('test'=>$conf->societe->enabled, 'label'=>$langs->trans("ThirdParties"), 'desc'=>$langs->trans("ECMDocsByThirdParties")), - 1 => array('test'=>$conf->propal->enabled, 'label'=>$langs->trans("Proposals"), 'desc'=>$langs->trans("ECMDocsByProposals")), - 2 => array('test'=>$conf->commande->enabled,'label'=>$langs->trans("Orders"), 'desc'=>$langs->trans("ECMDocsByOrders")), - 3 => array('test'=>$conf->contrat->enabled, 'label'=>$langs->trans("Contracts"), 'desc'=>$langs->trans("ECMDocsByContracts")), - 4 => array('test'=>$conf->facture->enabled, 'label'=>$langs->trans("Invoices"), 'desc'=>$langs->trans("ECMDocsByInvoices")) - ); - foreach ($sectionauto as $key => $val) - { - if ($val['test']) - { - $var=! $var; - - print ''; - - // Section - print '\n"; - - // Type - print '\n"; - - // Description - print ''; - print ''; - print ''; - print ''; - - print '\n"; - } - } - - print "
'; - print $ecmdirstatic->getNomUrl(1); - print "'; - print $langs->trans("ECMTypeManual"); - print "'.dolibarr_trunc($obj->description,32).''.$userstatic->getNomUrl(1).''.dolibarr_print_date($obj->date_c,"dayhour").''.$obj->cachenbofdoc.'?'; - echo 'rowid).'">'.img_delete().''; - print "
'; - print img_picto('','object_dir').' '; - print ''; - print $val['label']; - print ''; - print "'; - print $langs->trans("ECMTypeAuto"); - print "'.$val['desc'].'    '; - print "
"; - // Fin de zone Ajax + // Construit fiche rubrique + // Actions buttons print '
'; if ($user->rights->ecm->setup) { - print ''.$langs->trans('ECMAddSection').''; + print ''.$langs->trans('Delete').''; } else { - print ''.$langs->trans('ECMAddSection').''; + print ''.$langs->trans('Delete').''; } print '
'; } diff --git a/htdocs/ecm/docmine.php b/htdocs/ecm/docmine.php index e4da3398f9e..40fdb89fa3b 100644 --- a/htdocs/ecm/docmine.php +++ b/htdocs/ecm/docmine.php @@ -27,6 +27,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/ecm/ecmdirectory.class.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/files.lib.php"); // Load traductions files @@ -82,13 +83,15 @@ if ( $_POST["sendit"] && $conf->upload != 0) { $result = dol_move_uploaded_file($_FILES['userfile']['tmp_name'], $upload_dir . "/" . $_FILES['userfile']['name']); if ($result == 1) - { + { $mesg = '
'.$langs->trans("FileTransferComplete").'
'; //print_r($_FILES); + + $result=$ecmdir->changeNbOfFiles('+'); } else if (!$result) { - // Echec transfert (fichier d?passant la limite ?) + // Echec transfert (fichier depassant la limite ?) $mesg = '
'.$langs->trans("ErrorFileNotUploaded").'
'; // print_r($_FILES); } @@ -104,8 +107,11 @@ if ( $_POST["sendit"] && $conf->upload != 0) if ($_POST['action'] == 'confirm_deletefile' && $_POST['confirm'] == 'yes') { $file = $upload_dir . "/" . urldecode($_GET["urlfile"]); - dol_delete_file($file); + $result=dol_delete_file($file); + $mesg = '
'.$langs->trans("FileWasRemoved").'
'; + + $result=$ecmdir->changeNbOfFiles('-'); } @@ -123,11 +129,12 @@ llxHeader(); $form=new Form($db); print_fiche_titre($langs->trans("ECMManualOrg")); +print '
'; $ecmdir->ref=$ecmdir->label; print $langs->trans("ECMSection").': '; print img_picto('','object_dir').' '; -print ''.$langs->trans("ECMRoot").''; +print ''.$langs->trans("ECMRoot").''; print ' -> '.$ecmdir->getNomUrl(1).''; print "

"; @@ -215,34 +222,7 @@ print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"date","",$pa print ' '; print ''; -function compare_file($a, $b) -{ - global $sortorder; - global $sortfield; - - $sortorder=strtoupper($sortorder); - - if ($sortorder == 'ASC') { $retup=-1; $retdown=1; } - else { $retup=1; $retdown=-1; } - - if ($sortfield == 'name') - { - if ($a->name == $b->name) return 0; - return ($a->name < $b->name) ? $retup : $retdown; - } - if ($sortfield == 'date') - { - if ($a->date == $b->date) return 0; - return ($a->date < $b->date) ? $retup : $retdown; - } - if ($sortfield == 'size') - { - if ($a->size == $b->size) return 0; - return ($a->size < $b->size) ? $retup : $retdown; - } -} - -usort($filearray,"compare_file"); +usort($filearray,"dol_compare_file"); $var=true; foreach($filearray as $key => $file) diff --git a/htdocs/ecm/ecmdirectory.class.php b/htdocs/ecm/ecmdirectory.class.php index 3c852822577..40aac5e7adb 100644 --- a/htdocs/ecm/ecmdirectory.class.php +++ b/htdocs/ecm/ecmdirectory.class.php @@ -51,7 +51,7 @@ class EcmDirectory // extends CommonObject var $description; var $tms; - + var $cats=array(); /** @@ -83,7 +83,7 @@ class EcmDirectory // extends CommonObject if (! $this->cachenbofdoc) $this->cachenbofdoc=0; $this->date_c=$now; $this->fk_user_c=$user->id; - + if ($this->fk_parent <= 0) $this->fk_parent=0; // Check parameters // Put here code to add control on parameters values @@ -186,6 +186,34 @@ class EcmDirectory // extends CommonObject /* + * \brief Update database + * \sign '+' or '-' + * \return int <0 if KO, >0 if OK + */ + function changeNbOfFiles($sign) + { + global $conf, $langs; + + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."ecm_directories SET"; + + $sql.= " cachenbofdoc = cachenbofdoc ".$sign." 1"; + $sql.= " WHERE rowid = ".$this->id; + + dolibarr_syslog("Ecm_directories::changeNbOfFiles sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) + { + $this->error="Error ".$this->db->lasterror(); + dolibarr_syslog("Ecm_directories::changeNbOfFiles ".$this->error, LOG_ERR); + return -1; + } + + return 1; + } + + + /* * \brief Load object in memory from database * \param id id object * \param user User that load @@ -262,7 +290,7 @@ class EcmDirectory // extends CommonObject } $file = $conf->ecm->dir_output . "/" . $this->label; - $result=dol_delete_dir($file); + $result=@dol_delete_dir($file); // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/interfaces.class.php"); @@ -290,29 +318,183 @@ class EcmDirectory // extends CommonObject /** - \brief Renvoie nom clicable (avec eventuellement le picto) - \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul - \param option Sur quoi pointe le lien + \brief Renvoie nom clicable (avec eventuellement le picto) + \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul + \param option Sur quoi pointe le lien \return string Chaine avec URL */ - function getNomUrl($withpicto=0,$option='') - { - global $langs; - - $result=''; - - $lien = ''; - $lienfin=''; - - $picto='dir'; + function getNomUrl($withpicto=0,$option='') + { + global $langs; + + $result=''; + + $lien = ''; + $lienfin=''; + + //$picto=DOL_URL_ROOT.'/theme/common/treemenu/folder.gif'; + $picto='dir'; + + $label=$langs->trans("ShowECMSection").': '.$this->ref; + + if ($withpicto) $result.=($lien.img_object($label,$picto,'',1).$lienfin); + if ($withpicto && $withpicto != 2) $result.=' '; + if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin; + return $result; + } - $label=$langs->trans("ShowECMSection").': '.$this->ref; + /** + * \brief Load this->motherof array + * \return int <0 if KO, >0 if OK + */ + function load_motherof() + { + $this->motherof=array(); + + // Charge tableau des meres + $sql = "SELECT fk_parent as id_parent, rowid as id_son"; + $sql.= " FROM ".MAIN_DB_PREFIX."ecm_directories"; + $sql.= " WHERE fk_parent != 0"; + + dolibarr_syslog("ECMDirectory::get_full_arbo sql=".$sql); + $resql = $this->db->query($sql); + if ($resql) + { + while ($obj= $this->db->fetch_object($resql)) + { + $this->motherof[$obj->id_son]=$obj->id_parent; + } + return 1; + } + else + { + dolibarr_print_error ($this->db); + return -1; + } + } - if ($withpicto) $result.=($lien.img_object($label,$picto).$lienfin); - if ($withpicto && $withpicto != 2) $result.=' '; - if ($withpicto != 2) $result.=$lien.$this->ref.$lienfin; - return $result; - } + /** + * \brief Reconstruit l'arborescence des catégories sous la forme d'un tableau + * Renvoi un tableau de tableau('id','id_mere',...) trié selon + * arbre et avec: + * id = id de la categorie + * 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 + * \return array Tableau de array + */ + function get_full_arbo() + { + // Init this->motherof array + $this->load_motherof(); + + // Charge tableau des categories + $sql = "SELECT c.rowid as rowid, c.label as label,"; + $sql.= " c.description as description, c.cachenbofdoc,"; + $sql.= " c.fk_user_c,"; + $sql.= " c.date_c,"; + $sql.= " u.login as login_c,"; + $sql.= " ca.rowid as rowid_fille"; + $sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."ecm_directories as c"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."ecm_directories as ca"; + $sql.= " ON c.rowid=ca.fk_parent"; + $sql.= " WHERE c.fk_user_c = u.rowid"; + $sql.= " ORDER BY c.label, c.rowid"; + + dolibarr_syslog("ECMDirectory::get_full_arbo sql=".$sql); + $resql = $this->db->query ($sql); + if ($resql) + { + $this->cats = array(); + $i=0; + while ($obj = $this->db->fetch_object($resql)) + { + $this->cats[$obj->rowid]['id'] = $obj->rowid; + $this->cats[$obj->rowid]['id_mere'] = $this->motherof[$obj->rowid]; + $this->cats[$obj->rowid]['label'] = $obj->label; + $this->cats[$obj->rowid]['description'] = $obj->description; + $this->cats[$obj->rowid]['cachenbofdoc'] = $obj->cachenbofdoc; + $this->cats[$obj->rowid]['date_c'] = $obj->date_c; + $this->cats[$obj->rowid]['fk_user_c'] = $obj->fk_user_c; + $this->cats[$obj->rowid]['login_c'] = $obj->login_c; + + if ($obj->rowid_fille) + { + if (is_array($this->cats[$obj->rowid]['id_children'])) + { + $newelempos=sizeof($this->cats[$obj->rowid]['id_children']); + //print "this->cats[$i]['id_children'] est deja un tableau de $newelem elements
"; + $this->cats[$obj->rowid]['id_children'][$newelempos]=$obj->rowid_fille; + } + else + { + //print "this->cats[".$obj->rowid."]['id_children'] n'est pas encore un tableau
"; + $this->cats[$obj->rowid]['id_children']=array($obj->rowid_fille); + } + } + $i++; + + } + } + else + { + dolibarr_print_error ($this->db); + return -1; + } + + // On ajoute la propriete fullpath a tous les éléments + foreach($this->cats as $key => $val) + { + if (isset($motherof[$key])) continue; + $this->build_path_from_id_categ($key,0); + } + + $this->cats=dol_sort_array($this->cats, 'fulllabel', 'asc', true, false); + + //$this->debug_cats(); + + return $this->cats; + } + + /** + * \brief Calcule les propriétés fullpath et fulllabel d'une categorie + * du tableau this->cats et de toutes ces enfants + * \param id_categ id_categ entry to update + * \param protection Deep counter to avoid infinite loop + */ + function build_path_from_id_categ($id_categ,$protection=0) + { + // Define fullpath + if (isset($this->cats[$id_categ]['id_mere'])) + { + $this->cats[$id_categ]['fullpath'] =$this->cats[$this->cats[$id_categ]['id_mere']]['fullpath']; + $this->cats[$id_categ]['fullpath'].='_'.$id_categ; + $this->cats[$id_categ]['fulllabel'] =$this->cats[$this->cats[$id_categ]['id_mere']]['fulllabel']; + $this->cats[$id_categ]['fulllabel'].=' >> '.$this->cats[$id_categ]['label']; + } + else + { + $this->cats[$id_categ]['fullpath']='_'.$id_categ; + $this->cats[$id_categ]['fulllabel']=$this->cats[$id_categ]['label']; + } + // We count number of _ to have level + $this->cats[$id_categ]['level']=strlen(eregi_replace('[^_]','',$this->cats[$id_categ]['fullpath'])); + + // Traite ces enfants + $protection++; + if ($protection > 20) return; // On ne traite pas plus de 20 niveaux + if (is_array($this->cats[$id_categ]['id_children'])) + { + foreach($this->cats[$id_categ]['id_children'] as $key => $val) + { + $this->build_path_from_id_categ($val,$protection); + } + } + + return; + } } ?> diff --git a/htdocs/ecm/index.php b/htdocs/ecm/index.php index b4d31f67114..b96fbd5a3e0 100644 --- a/htdocs/ecm/index.php +++ b/htdocs/ecm/index.php @@ -40,13 +40,13 @@ $sortfield=$_GET["sortfield"]; $limit = $conf->liste_limit; $offset = $limit * $page ; -if (! $sortorder) $sortorder="DESC"; +if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="label"; $ecmdir = new ECMDirectory($db); -if (! empty($_GET["section"])) +if (! empty($_REQUEST["section"])) { - $result=$ecmdir->fetch($_GET["section"]); + $result=$ecmdir->fetch($_REQUEST["section"]); if (! $result > 0) { dolibarr_print_error($db,$ecmdir->error); @@ -69,7 +69,6 @@ if ($_POST["action"] == 'add' && $user->rights->ecm->setup) $ecmdir->description = $_POST["desc"]; $id = $ecmdir->create($user); - if ($id > 0) { Header("Location: ".$_SERVER["PHP_SELF"]); @@ -152,6 +151,170 @@ if (! $_GET["action"] || $_GET["action"] == 'delete_section') print ''; print ''; + + + //*********************** + // Files + //*********************** + print_fiche_titre($langs->trans("ECMSectionOfDocuments")); + //print '
'; + +/* + $ecmdir->ref=$ecmdir->label; + print $langs->trans("ECMSection").': '; + print img_picto('','object_dir').' '; + print ''.$langs->trans("ECMRoot").''; + //print ' -> '.$ecmdir->getNomUrl(1).'
'; + print "

"; +*/ + + // 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 ''; + + // Ajout rubriques automatiques + $sectionauto=array(); + if ($conf->societe->enabled) $sectionauto[]=array('test'=>$conf->societe->enabled, 'label'=>$langs->trans("ThirdParties"), 'desc'=>$langs->trans("ECMDocsByThirdParties")); + if ($conf->propal->enabled) $sectionauto[]=array('test'=>$conf->propal->enabled, 'label'=>$langs->trans("Proposals"), 'desc'=>$langs->trans("ECMDocsByProposals")); + if ($conf->commande->enabled) $sectionauto[]=array('test'=>$conf->commande->enabled,'label'=>$langs->trans("Orders"), 'desc'=>$langs->trans("ECMDocsByOrders")); + if ($conf->contrat->enabled) $sectionauto[]=array('test'=>$conf->contrat->enabled, 'label'=>$langs->trans("Contracts"), 'desc'=>$langs->trans("ECMDocsByContracts")); + if ($conf->facture->enabled) $sectionauto[]=array('test'=>$conf->facture->enabled, 'label'=>$langs->trans("Invoices"), 'desc'=>$langs->trans("ECMDocsByInvoices")); + + if (sizeof($sectionauto)) + { + // Automatic sections + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $sectionauto=dol_sort_array($sectionauto,'label',$sortorder,true,false); + + $var=true; + foreach ($sectionauto as $key => $val) + { + if ($val['test']) + { + $var=! $var; + + print ''; + + // Section + print '\n"; + + // Description + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + } + } + } + + + // Manual sections + + print ''; + $param='&socid='.$socid; + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $ecmdirstatic = new ECMDirectory($db); + $rub=$ecmdirstatic->get_full_arbo(); + + $userstatic = new User($db); + + $nbofentries=0; + $var=true; + foreach($rub as $key => $val) + { + $var=!$var; + + $ecmdirstatic->id=$val['id']; + $ecmdirstatic->ref=$val['label']; + + print ''; + + // Section + print '\n"; + + // Description + print ''; + $userstatic->id=$val['fk_user_c']; + $userstatic->nom=$val['login_c']; + print ''; + print ''; + + // Nb of docs + //print ''; + print ''; + + print '\n"; + + $nbofentries++; + } + + // If nothing to show + if ($nbofentries == 0) + { + print ''; + } + + print "
'.$langs->trans("ECMSectionAuto").''.$langs->trans("Description").''.$langs->trans("ECMCreationUser").' '.$langs->trans("ECMNbOfDocs").' 
'; + print img_picto('','object_dir').' '; + print ''; + print $val['label']; + print ''; + print "'.$val['desc'].''.$langs->trans("ECMTypeAuto").' ? 
'.$langs->trans("ECMSectionManual").''.$langs->trans("Description").''.$langs->trans("ECMCreationUser").''.$langs->trans("ECMCreationDate").''.$langs->trans("ECMNbOfDocs").' 
'; + print str_repeat('     ',$val['level']-1); + print $ecmdirstatic->getNomUrl(1); + print "'.dolibarr_trunc($val['description'],32).''.$userstatic->getNomUrl(1).''.dolibarr_print_date($val['date_c'],"dayhour").''.$obj->cachenbofdoc.''.$val['cachenbofdoc'].''; + if ($val['cachenbofdoc'] == 0 && $val['level'] >= $rub[$key+1]['level']) + { + print ''.img_delete().''; + } + else + { + print ' '; + } + print "
'.$langs->trans("ECMNoDirecotyYet").'
"; + // Fin de zone Ajax + + + // Actions buttons + /* + print '
'; + if ($user->rights->ecm->setup) + { + print ''.$langs->trans('ECMAddSection').''; + } + else + { + print ''.$langs->trans('ECMAddSection').''; + } + print '
'; + */ } diff --git a/htdocs/ecm/pre.inc.php b/htdocs/ecm/pre.inc.php index 210d7097c6a..96c9ecda6bc 100644 --- a/htdocs/ecm/pre.inc.php +++ b/htdocs/ecm/pre.inc.php @@ -39,7 +39,8 @@ function llxHeader($head = "", $title="", $help_url='') $menu = new Menu(); $menu->add(DOL_URL_ROOT."/ecm/index.php?mainmenu=ecm&idmenu=".$_SESSION["idmenu"], $langs->trans("MenuECM"),0,$user->rights->ecm->read); - $menu->add_submenu(DOL_URL_ROOT."/ecm/docdir.php?mainmenu=ecm&idmenu=".$_SESSION["idmenu"], $langs->trans("List"),1,$user->rights->ecm->read); + //$menu->add_submenu(DOL_URL_ROOT."/ecm/docdir.php?mainmenu=ecm&idmenu=".$_SESSION["idmenu"], $langs->trans("List"),1,$user->rights->ecm->read); + $menu->add_submenu(DOL_URL_ROOT."/ecm/index.php?mainmenu=ecm&idmenu=".$_SESSION["idmenu"], $langs->trans("List"),1,$user->rights->ecm->read); $menu->add_submenu(DOL_URL_ROOT."/ecm/index?mainmenu=ecm&action=create&idmenu=".$_SESSION["idmenu"], $langs->trans("ECMNewDocument"),1,$user->rights->ecm->create); $menu->add_submenu(DOL_URL_ROOT."/ecm/docdir?mainmenu=ecm&action=create&idmenu=".$_SESSION["idmenu"], $langs->trans("ECMNewSection"),1,$user->rights->ecm->setup); diff --git a/htdocs/langs/fr_FR/ecm.lang b/htdocs/langs/fr_FR/ecm.lang index 830ffd1c582..7c5ce9cc266 100644 --- a/htdocs/langs/fr_FR/ecm.lang +++ b/htdocs/langs/fr_FR/ecm.lang @@ -1,42 +1,45 @@ -# Dolibarr language file - fr_FR - ecm -MenuECM=Documents -DocsMine=Mes documents -DocsGlobal=Documents globaux -DocsExternal=Documents externes -DocsGenerated=Documents générés -DocsElements=Documents élements -DocsThirdParties=Documents tiers -DocsContracts=Documents contrats -DocsProposals=Documents propositions -DocsOrders=Documents commandes -DocsInvoices=Documents factures -ECMNbOfDocs=Nb de documents -ECMSection=Rubrique -ECMSections=Rubriques -ECMRoot=Racine -ECMNewSection=Nouvelle rubrique -ECMAddSection=Ajouter rubrique manuelle -ECMNewSection=Nouvelle rubrique manuelle -ECMNewDocument=Nouveau document -ECMCreationDate=Date création -ECMCreationUser=Créateur -ECMArea=Espace Gestion de documents -ECMAreaDesc=L'espace Gestion des documents vous permet de stocker et retrouver rapidement des documents dans Dolibarr. -ECMAreaDesc2=Vous pouvez creer des rubriques manuelles ou y ajouter des documents.
Les rubriques automatiques sont alimentées automatiquement lors de l'ajout d'un document depuis une fiche objet. -ECMSectionWasRemoved=La rubrique %s a été effacée. -ECMDocumentsSection=Document de la section -ECMSearchByKeywords=Recherche par mots clés -ECMSearchByEntity=Recherche par objet -ECMSectionOfDocuments=Rubriques des documents -ECMTypeManual=Manuelle -ECMTypeAuto=Automatique -ECMDocsByThirdParties=Documents associés aux tiers -ECMDocsByProposals=Documents associés aux propositions -ECMDocsByOrders=Documents associés aux commandes -ECMDocsByContracts=Documents associés aux contrats -ECMDocsByInvoices=Documents associés aux factures -ECMManualOrg=Rubrique manuelle -ECMAutoOrg=Rubrique automatique -ShowECMSection=Afficher rubrique -DeleteSection=Suppression rubrique -ConfirmDeleteSection=Confirmez-vous la suppression de la rubique %s ? +# Dolibarr language file - fr_FR - ecm +MenuECM=Documents +DocsMine=Mes documents +DocsGlobal=Documents globaux +DocsExternal=Documents externes +DocsGenerated=Documents générés +DocsElements=Documents élements +DocsThirdParties=Documents tiers +DocsContracts=Documents contrats +DocsProposals=Documents propositions +DocsOrders=Documents commandes +DocsInvoices=Documents factures +ECMNbOfDocs=Nb doc +ECMSection=Rubrique +ECMSectionManual=Rubriques manuelles +ECMSectionAuto=Rubriques automatique +ECMSections=Rubriques +ECMRoot=Racine +ECMNewSection=Nouvelle rubrique +ECMAddSection=Ajouter rubrique manuelle +ECMNewSection=Nouvelle rubrique manuelle +ECMNewDocument=Nouveau document +ECMCreationDate=Date création +ECMCreationUser=Créateur +ECMArea=Espace Gestion de documents +ECMAreaDesc=L'espace Gestion des documents vous permet de stocker et retrouver rapidement des documents dans Dolibarr. +ECMAreaDesc2=* Les rubriques automatiques sont alimentées automatiquement lors de l'ajout d'un document depuis une fiche objet.
* Les rubriques manuelles peuvent etre utilisées pour stocker des documents liés à aucun élément particulier. +ECMSectionWasRemoved=La rubrique %s a été effacée. +ECMDocumentsSection=Document de la section +ECMSearchByKeywords=Recherche par mots clés +ECMSearchByEntity=Recherche par objet +ECMSectionOfDocuments=Rubriques des documents +ECMTypeManual=Manuelle +ECMTypeAuto=Automatique +ECMDocsByThirdParties=Documents associés aux tiers +ECMDocsByProposals=Documents associés aux propositions +ECMDocsByOrders=Documents associés aux commandes +ECMDocsByContracts=Documents associés aux contrats +ECMDocsByInvoices=Documents associés aux factures +ECMManualOrg=Rubrique manuelle +ECMAutoOrg=Rubrique automatique +ECMNoDirecotyYet=Aucune rubrique créée +ShowECMSection=Afficher rubrique +DeleteSection=Suppression rubrique +ConfirmDeleteSection=Confirmez-vous la suppression de la rubique %s ? diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 261ad200596..390cea511d8 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -3007,4 +3007,31 @@ function stopwithmem() exit; } + +/** +* \brief Advanced sort array by second index function, which produces +* ascending (default) or descending output and uses optionally +* natural case insensitive sorting (which can be optionally case +* sensitive as well). +*/ +function dol_sort_array($array, $index, $order='asc', $natsort, $case_sensitive) +{ + // Clean parameters + $order=strtolower($order); + + if (is_array($array) && count($array)>0) + { + foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index]; + if (!$natsort) ($order=='asc') ? asort($temp) : arsort($temp); + else + { + ($case_sensitive) ? natsort($temp) : natcasesort($temp); + if($order!='asc') $temp=array_reverse($temp,TRUE); + } + foreach(array_keys($temp) as $key) (is_numeric($key))? $sorted[]=$array[$key] : $sorted[$key]=$array[$key]; + return $sorted; + } + return $array; +} + ?>