diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 011d5cd2f4b..99b0ace26d0 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -6830,6 +6830,8 @@ abstract class CommonObject
// 2 : key fields name (if differ of rowid)
// 3 : key field parent (for dependent lists)
// 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value
+ // 5 : id category type
+ // 6 : ids categories list separated by comma for category root
$keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid');
if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
@@ -6844,112 +6846,130 @@ abstract class CommonObject
$keyList .= ', '.$parentField;
}
- $fields_label = explode('|', $InfoFieldList[1]);
- if (is_array($fields_label)) {
- $keyList .= ', ';
- $keyList .= implode(', ', $fields_label);
+ $filter_categorie = false;
+ if (count($InfoFieldList) > 5) {
+ if ($InfoFieldList[0] == 'categorie') {
+ $filter_categorie = true;
+ }
}
- $sqlwhere = '';
- $sql = "SELECT ".$keyList;
- $sql .= " FROM ".$this->db->prefix().$InfoFieldList[0];
- if (!empty($InfoFieldList[4])) {
- // can use SELECT request
- if (strpos($InfoFieldList[4], '$SEL$') !== false) {
- $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]);
+ if ($filter_categorie === false) {
+ $fields_label = explode('|', $InfoFieldList[1]);
+ if (is_array($fields_label)) {
+ $keyList .= ', ';
+ $keyList .= implode(', ', $fields_label);
}
- // current object id can be use into filter
- if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) {
- $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]);
- } else {
- $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]);
- }
-
- //We have to join on extrafield table
- if (strpos($InfoFieldList[4], 'extra') !== false) {
- $sql .= " as main, ".$this->db->prefix().$InfoFieldList[0]."_extrafields as extra";
- $sqlwhere .= " WHERE extra.fk_object=main.".$InfoFieldList[2]." AND ".$InfoFieldList[4];
- } else {
- $sqlwhere .= " WHERE ".$InfoFieldList[4];
- }
- } else {
- $sqlwhere .= ' WHERE 1=1';
- }
- // Some tables may have field, some other not. For the moment we disable it.
- if (in_array($InfoFieldList[0], array('tablewithentity'))) {
- $sqlwhere .= " AND entity = ".((int) $conf->entity);
- }
- $sql .= $sqlwhere;
- //print $sql;
-
- $sql .= ' ORDER BY '.implode(', ', $fields_label);
-
- dol_syslog(get_class($this).'::showInputField type=sellist', LOG_DEBUG);
- $resql = $this->db->query($sql);
- if ($resql) {
- $out .= '';
- $num = $this->db->num_rows($resql);
- $i = 0;
- while ($i < $num) {
- $labeltoshow = '';
- $obj = $this->db->fetch_object($resql);
-
- // Several field into label (eq table:code|libelle:rowid)
- $notrans = false;
- $fields_label = explode('|', $InfoFieldList[1]);
- if (count($fields_label) > 1) {
- $notrans = true;
- foreach ($fields_label as $field_toshow) {
- $labeltoshow .= $obj->$field_toshow.' ';
- }
- } else {
- $labeltoshow = $obj->{$InfoFieldList[1]};
+ $sqlwhere = '';
+ $sql = "SELECT " . $keyList;
+ $sql .= " FROM " . $this->db->prefix() . $InfoFieldList[0];
+ if (!empty($InfoFieldList[4])) {
+ // can use SELECT request
+ if (strpos($InfoFieldList[4], '$SEL$') !== false) {
+ $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]);
}
- $labeltoshow = dol_trunc($labeltoshow, 45);
- if ($value == $obj->rowid) {
- foreach ($fields_label as $field_toshow) {
- $translabel = $langs->trans($obj->$field_toshow);
- if ($translabel != $obj->$field_toshow) {
- $labeltoshow = dol_trunc($translabel).' ';
- } else {
- $labeltoshow = dol_trunc($obj->$field_toshow).' ';
- }
- }
- $out .= '';
+ // current object id can be use into filter
+ if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) {
+ $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]);
} else {
- if (!$notrans) {
- $translabel = $langs->trans($obj->{$InfoFieldList[1]});
- if ($translabel != $obj->{$InfoFieldList[1]}) {
- $labeltoshow = dol_trunc($translabel, 18);
- } else {
- $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]});
+ $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]);
+ }
+
+ //We have to join on extrafield table
+ if (strpos($InfoFieldList[4], 'extra') !== false) {
+ $sql .= " as main, " . $this->db->prefix() . $InfoFieldList[0] . "_extrafields as extra";
+ $sqlwhere .= " WHERE extra.fk_object=main." . $InfoFieldList[2] . " AND " . $InfoFieldList[4];
+ } else {
+ $sqlwhere .= " WHERE " . $InfoFieldList[4];
+ }
+ } else {
+ $sqlwhere .= ' WHERE 1=1';
+ }
+ // Some tables may have field, some other not. For the moment we disable it.
+ if (in_array($InfoFieldList[0], array('tablewithentity'))) {
+ $sqlwhere .= " AND entity = " . ((int)$conf->entity);
+ }
+ $sql .= $sqlwhere;
+ //print $sql;
+
+ $sql .= ' ORDER BY ' . implode(', ', $fields_label);
+
+ dol_syslog(get_class($this) . '::showInputField type=sellist', LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if ($resql) {
+ $out .= '';
+ $num = $this->db->num_rows($resql);
+ $i = 0;
+ while ($i < $num) {
+ $labeltoshow = '';
+ $obj = $this->db->fetch_object($resql);
+
+ // Several field into label (eq table:code|libelle:rowid)
+ $notrans = false;
+ $fields_label = explode('|', $InfoFieldList[1]);
+ if (count($fields_label) > 1) {
+ $notrans = true;
+ foreach ($fields_label as $field_toshow) {
+ $labeltoshow .= $obj->$field_toshow . ' ';
}
+ } else {
+ $labeltoshow = $obj->{$InfoFieldList[1]};
}
- if (empty($labeltoshow)) {
- $labeltoshow = '(not defined)';
- }
+ $labeltoshow = dol_trunc($labeltoshow, 45);
+
if ($value == $obj->rowid) {
- $out .= '';
+ foreach ($fields_label as $field_toshow) {
+ $translabel = $langs->trans($obj->$field_toshow);
+ if ($translabel != $obj->$field_toshow) {
+ $labeltoshow = dol_trunc($translabel) . ' ';
+ } else {
+ $labeltoshow = dol_trunc($obj->$field_toshow) . ' ';
+ }
+ }
+ $out .= '';
+ } else {
+ if (!$notrans) {
+ $translabel = $langs->trans($obj->{$InfoFieldList[1]});
+ if ($translabel != $obj->{$InfoFieldList[1]}) {
+ $labeltoshow = dol_trunc($translabel, 18);
+ } else {
+ $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]});
+ }
+ }
+ if (empty($labeltoshow)) {
+ $labeltoshow = '(not defined)';
+ }
+ if ($value == $obj->rowid) {
+ $out .= '';
+ }
+
+ if (!empty($InfoFieldList[3]) && $parentField) {
+ $parent = $parentName . ':' . $obj->{$parentField};
+ $isDependList = 1;
+ }
+
+ $out .= '';
}
- if (!empty($InfoFieldList[3]) && $parentField) {
- $parent = $parentName.':'.$obj->{$parentField};
- $isDependList = 1;
- }
-
- $out .= '';
+ $i++;
}
-
- $i++;
+ $this->db->free($resql);
+ } else {
+ print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.
';
}
- $this->db->free($resql);
} else {
- print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.
';
+ require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
+ $data = $form->select_all_categories(Categorie::$MAP_ID_TO_CODE[$InfoFieldList[5]], '', 'parent', 64, $InfoFieldList[6], 1, 1);
+ $out .= '';
+ foreach ($data as $data_key => $data_value) {
+ $out .= '