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 '
\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 = '