diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 6702ce34a4d..f07610cfe78 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -520,19 +520,19 @@ class Categorie /** - * \brief Reconstruit l'arborescence des categories sous la forme d'un tableau - * Renvoi un tableau de tableau('id','id_mere',...) trie selon - * arbre et avec: + * Reconstruit l'arborescence des categories sous la forme d'un tableau + * Renvoi un tableau de tableau('id','id_mere',...) trie 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 - * \param type Type of categories (0=product, 1=suppliers, 2=customers, 3=members) - * \return array Array of categories + * @param type Type of categories (0=product, 1=suppliers, 2=customers, 3=members) + * @param markafterid Mark all categories after this leaf in category tree. + * @return array Array of categories */ - function get_full_arbo($type) + function get_full_arbo($type,$markafterid=0) { $this->cats = array(); @@ -540,6 +540,7 @@ class Categorie $sql = "SELECT fk_categorie_mere as id_mere, fk_categorie_fille as id_fille"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie_association"; + // Load array this->motherof dol_syslog("Categorie::get_full_arbo build motherof array sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) @@ -588,14 +589,34 @@ class Categorie return -1; } - // We add the fulpath property to each elements of first level (no parent exists) + // We add the fullpath property to each elements of first level (no parent exists) dol_syslog("Categorie::get_full_arbo call to build_path_from_id_categ", LOG_DEBUG); foreach($this->cats as $key => $val) { if (isset($this->motherof[$key])) continue; - $this->build_path_from_id_categ($key,0); // Process a path of a root category (no parent exists) + $this->build_path_from_id_categ($key,0); // Process a branch from the root category key (this category has no parent) } + // Exclude tree for $markafterid + if ($markafterid) + { + //print "Look to discard category ".$markafterid."\n"; + $keyfilter1='^'.$markafterid.'$'; + $keyfilter2='_'.$markafterid.'$'; + $keyfilter3='^'.$markafterid.'_'; + $keyfilter4='_'.$markafterid.'_'; + foreach($this->cats as $key => $val) + { + if (preg_match('/'.$keyfilter1.'/',$val['fullpath']) || preg_match('/'.$keyfilter2.'/',$val['fullpath']) + || preg_match('/'.$keyfilter3.'/',$val['fullpath']) || preg_match('/'.$keyfilter4.'/',$val['fullpath'])) + { + //print "Categ discarded ".$this->cats[$key]['fullpath']."\n"; + //$this->cats[$key]['marked']=1; + unset($this->cats[$key]); + } + } + } + dol_syslog("Categorie::get_full_arbo dol_sort_array", LOG_DEBUG); $this->cats=dol_sort_array($this->cats, 'fulllabel', 'asc', true, false); @@ -605,9 +626,9 @@ class Categorie } /** - * \brief For category id_categ and its child available in this->cats, define property fullpath and fulllabel - * \param id_categ id_categ entry to update - * \param protection Deep counter to avoid infinite loop + * For category id_categ and its childs available in this->cats, define property fullpath and fulllabel + * @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) { diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index fde030da32d..f8cc6443b1a 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -119,11 +119,14 @@ print ''; print ''; print ''; + +// Ref print ''; print ''; +// Description print ''; print ''; print ''; + +// Parent category +print ''; + print '
'; print $langs->trans("Ref").''; print '
'.$langs->trans("Description").''; @@ -131,6 +134,12 @@ require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); $doleditor=new DolEditor('description',$categorie->description,200,'dolibarr_notes','',false,true,$conf->fckeditor->enabled,ROWS_6,50); $doleditor->Create(); print '
'.$langs->trans ("In").''; +print $html->select_all_categories($type,$categorie->id_mere,'catMere',64,$categorie->id); +print '
'; print '
'; diff --git a/htdocs/categories/fiche.php b/htdocs/categories/fiche.php index 70576f5af9e..4a4a5eb2a6e 100644 --- a/htdocs/categories/fiche.php +++ b/htdocs/categories/fiche.php @@ -220,15 +220,20 @@ if ($user->rights->categorie->creer) } print ''; + + // Ref print ''; print ''; + + // Description print ''; + // Parent category print ''; diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index dae7d883fcc..55f4d8a98e7 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -161,8 +161,7 @@ print ""; - -$cats = $c->get_filles (); +$cats = $c->get_filles(); if ($cats < 0) { dol_print_error(); @@ -209,7 +208,7 @@ else } else { - print ""; + print ""; } print "
'.$langs->trans("Ref").''; print'
'.$langs->trans("Description").''; require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); $doleditor=new DolEditor('description',$categorie->description,200,'dolibarr_notes','',false,true,$conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC,ROWS_6,50); $doleditor->Create(); print '
'.$langs->trans ("AddIn").''; print $html->select_all_categories($_GET['type'],$_REQUEST['catorigin']); print '
".$langs->trans("NoSubCat")."
'.$langs->trans("NoSubCat")."
\n"; } @@ -227,7 +226,7 @@ if ($c->type == 0) { print "
"; print "\n"; - print "\n"; + print '\n"; if (sizeof ($prods) > 0) { @@ -248,7 +247,7 @@ if ($c->type == 0) } else { - print ""; + print ""; } print "
".$langs->trans("ProductsAndServices")."
'.$langs->trans("ProductsAndServices")."
".$langs->trans("ThisCategoryHasNoProduct")."
'.$langs->trans("ThisCategoryHasNoProduct")."
\n"; } @@ -286,7 +285,7 @@ if ($c->type == 1) } else { - print "".$langs->trans ("ThisCategoryHasNoSupplier").""; + print "".$langs->trans ("ThisCategoryHasNoSupplier").""; } print "\n"; } @@ -323,7 +322,7 @@ if($c->type == 2) } else { - print "".$langs->trans("ThisCategoryHasNoCustomer").""; + print "".$langs->trans("ThisCategoryHasNoCustomer").""; } print "\n"; } @@ -343,7 +342,7 @@ if ($c->type == 3) { print "
"; print "\n"; - print "\n"; + print '\n"; if (sizeof ($prods) > 0) { @@ -364,7 +363,7 @@ if ($c->type == 3) } else { - print ""; + print ""; } print "
".$langs->trans("Member")."
'.$langs->trans("Member")."
".$langs->trans("ThisCategoryHasNoMember")."
'.$langs->trans("ThisCategoryHasNoMember")."
\n"; } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 87079e105fc..86ef014cf7c 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1005,7 +1005,7 @@ class Form } $opt.= '>'; $opt.= $langs->convToOutputCharset($objp->ref).' - '.$langs->convToOutputCharset(dol_trunc($label,32)).' - '; - + $objRef = $objp->ref; if ($filterkey && $filterkey != '') $objRef=preg_replace('/('.preg_quote($filterkey).')/i','$1',$objRef,1); $outval.=$objRef.' - '.dol_trunc($label,32).' - '; @@ -1227,7 +1227,7 @@ class Form if ($selected == $objp->idprodfournprice) $opt.= ' selected="true"'; if ($objp->fprice == '') $opt.=' disabled="disabled"'; $opt.= '>'; - + $objRef = $objp->ref; if ($filterkey && $filterkey != '') $objRef=preg_replace('/('.preg_quote($filterkey).')/i','$1',$objRef,1); $objRefFourn = $objp->ref_fourn; @@ -1749,12 +1749,14 @@ class Form } /** - * \brief Retourne la liste des categories du type choisi - * \param type Type de categories (0=produit, 1=fournisseur, 2=client) - * \param selected Id categorie preselectionnee - * \param select_name Nom formulaire HTML + * Return list of categories having choosed type + * @param type Type de categories (0=product, 1=supplier, 2=customer, 3=member) + * @param selected Id of category preselected + * @param select_name HTML field name + * @param maxlength Maximum length for labels + * @param excludeafterid Exclude all categories after this leaf in category tree. */ - function select_all_categories($type,$selected='',$select_name="",$maxlength=64) + function select_all_categories($type, $selected='', $select_name="", $maxlength=64, $excludeafterid=0) { global $langs; $langs->load("categories"); @@ -1762,7 +1764,7 @@ class Form if ($select_name=="") $select_name="catMere"; $cat = new Categorie($this->db); - $cate_arbo = $cat->get_full_arbo($type); + $cate_arbo = $cat->get_full_arbo($type,$excludeafterid); $output = '