36require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/ticket/class/ticket.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/knowledgemanagement/class/knowledgerecord.class.php';
50 const TYPE_PRODUCT =
'product';
51 const TYPE_SUPPLIER =
'supplier';
52 const TYPE_CUSTOMER =
'customer';
53 const TYPE_MEMBER =
'member';
54 const TYPE_CONTACT =
'contact';
55 const TYPE_USER =
'user';
56 const TYPE_PROJECT =
'project';
57 const TYPE_ACCOUNT =
'bank_account';
58 const TYPE_BANK_LINE =
'bank_line';
59 const TYPE_WAREHOUSE =
'warehouse';
60 const TYPE_ACTIONCOMM =
'actioncomm';
61 const TYPE_WEBSITE_PAGE =
'website_page';
62 const TYPE_TICKET =
'ticket';
63 const TYPE_KNOWLEDGEMANAGEMENT =
'knowledgemanagement';
68 public $picto =
'category';
74 protected $MAP_ID = array(
88 'knowledgemanagement' => 13
96 public static $MAP_ID_TO_CODE = array(
108 11 =>
'website_page',
110 13 =>
'knowledgemanagement'
118 public $MAP_CAT_FK = array(
121 'contact' =>
'socpeople',
122 'bank_account' =>
'account',
130 public $MAP_CAT_TABLE = array(
131 'customer' =>
'societe',
132 'supplier' =>
'fournisseur',
133 'bank_account'=>
'account',
141 public $MAP_OBJ_CLASS = array(
142 'product' =>
'Product',
143 'customer' =>
'Societe',
144 'supplier' =>
'Fournisseur',
145 'member' =>
'Adherent',
146 'contact' =>
'Contact',
148 'account' =>
'Account',
149 'bank_account' =>
'Account',
150 'project' =>
'Project',
151 'warehouse'=>
'Entrepot',
152 'actioncomm' =>
'ActionComm',
153 'website_page' =>
'WebsitePage',
154 'ticket' =>
'Ticket',
155 'knowledgemanagement' =>
'KnowledgeRecord'
163 public static $MAP_TYPE_TITLE_AREA = array(
164 'product' =>
'ProductsCategoriesArea',
165 'customer' =>
'CustomersCategoriesArea',
166 'supplier' =>
'SuppliersCategoriesArea',
167 'member' =>
'MembersCategoriesArea',
168 'contact' =>
'ContactsCategoriesArea',
169 'user' =>
'UsersCategoriesArea',
170 'account' =>
'AccountsCategoriesArea',
171 'bank_account' =>
'AccountsCategoriesArea',
172 'project' =>
'ProjectsCategoriesArea',
173 'warehouse'=>
'StocksCategoriesArea',
174 'actioncomm' =>
'ActioncommCategoriesArea',
175 'website_page' =>
'WebsitePageCategoriesArea'
182 public $MAP_OBJ_TABLE = array(
183 'customer' =>
'societe',
184 'supplier' =>
'societe',
185 'member' =>
'adherent',
186 'contact' =>
'socpeople',
187 'account' =>
'bank_account',
188 'project' =>
'projet',
189 'warehouse'=>
'entrepot',
190 'knowledgemanagement' =>
'knowledgemanagement_knowledgerecord'
196 public $element =
'category';
201 public $table_element =
'categorie';
255 public $cats = array();
260 public $motherof = array();
265 public $childs = array();
293 if (is_object($hookmanager)) {
294 $hookmanager->initHooks(array(
'category'));
295 $parameters = array();
296 $reshook = $hookmanager->executeHooks(
'constructCategory', $parameters, $this);
297 if ($reshook >= 0 && !empty($hookmanager->resArray)) {
298 foreach ($hookmanager->resArray as $mapList) {
299 $mapId = $mapList[
'id'];
300 $mapCode = $mapList[
'code'];
301 self::$MAP_ID_TO_CODE[$mapId] = $mapCode;
302 $this->MAP_ID[$mapCode] = $mapId;
303 $this->MAP_CAT_FK[$mapCode] = isset($mapList[
'cat_fk']) ? $mapList[
'cat_fk'] :
null;
304 $this->MAP_CAT_TABLE[$mapCode] = isset($mapList[
'cat_table']) ? $mapList[
'cat_table'] :
null;
305 $this->MAP_OBJ_CLASS[$mapCode] = $mapList[
'obj_class'];
306 $this->MAP_OBJ_TABLE[$mapCode] = $mapList[
'obj_table'];
321 foreach ($this->MAP_ID as $mapCode => $mapId) {
325 'cat_fk' => (empty($this->MAP_CAT_FK[$mapCode]) ? $mapCode : $this->MAP_CAT_FK[$mapCode]),
326 'cat_table' => (empty($this->MAP_CAT_TABLE[$mapCode]) ? $mapCode : $this->MAP_CAT_TABLE[$mapCode]),
327 'obj_class' => (empty($this->MAP_OBJ_CLASS[$mapCode]) ? $mapCode : $this->MAP_OBJ_CLASS[$mapCode]),
328 'obj_table' => (empty($this->MAP_OBJ_TABLE[$mapCode]) ? $mapCode : $this->MAP_OBJ_TABLE[$mapCode])
344 public function fetch($id, $label =
'', $type =
null, $ref_ext =
'')
347 if (empty($id) && empty($label) && empty($ref_ext)) {
348 $this->error =
"No category to search for";
351 if (!is_null($type) && !is_numeric($type)) {
352 $type = $this->MAP_ID[$type];
355 $sql =
"SELECT rowid, fk_parent, entity, label, description, color, fk_soc, visible, type, ref_ext";
356 $sql .=
", date_creation, tms, fk_user_creat, fk_user_modif";
357 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
359 $sql .=
" WHERE rowid = ".((int) $id);
360 } elseif (!empty($ref_ext)) {
361 $sql .=
" WHERE ref_ext LIKE '".$this->db->escape($ref_ext).
"'";
363 $sql .=
" WHERE label = '".$this->db->escape($label).
"' AND entity IN (".
getEntity(
'category').
")";
364 if (!is_null($type)) {
365 $sql .=
" AND type = ".((int) $type);
369 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
370 $resql = $this->db->query($sql);
372 if ($this->db->num_rows($resql) > 0) {
373 $res = $this->db->fetch_array($resql);
375 $this->
id = $res[
'rowid'];
377 $this->fk_parent = (int) $res[
'fk_parent'];
378 $this->label = $res[
'label'];
380 $this->color = $res[
'color'];
381 $this->socid = (int) $res[
'fk_soc'];
382 $this->visible = (int) $res[
'visible'];
383 $this->
type = (int) $res[
'type'];
384 $this->ref_ext = $res[
'ref_ext'];
385 $this->entity = (int) $res[
'entity'];
386 $this->date_creation = $this->db->jdate($res[
'date_creation']);
387 $this->date_modification = $this->db->jdate($res[
'tms']);
388 $this->user_creation_id = (int) $res[
'fk_user_creat'];
389 $this->user_modification_id = (int) $res[
'fk_user_modif'];
395 $this->db->free($resql);
404 $this->error =
"No category found";
409 $this->error = $this->db->lasterror;
410 $this->errors[] = $this->db->lasterror;
425 public function create($user, $notrigger = 0)
427 global $conf, $langs, $hookmanager;
428 $langs->load(
'categories');
432 if (!is_numeric($type)) {
433 $type = $this->MAP_ID[$type];
438 dol_syslog(get_class($this).
'::create', LOG_DEBUG);
441 $this->label = trim($this->label);
443 $this->color = trim($this->color);
444 $this->import_key = trim($this->import_key);
445 $this->ref_ext = trim($this->ref_ext);
446 if (empty($this->visible)) {
449 $this->fk_parent = ($this->fk_parent !=
"" ? intval($this->fk_parent) : 0);
452 $this->error = $langs->trans(
"ImpossibleAddCat", $this->label);
453 $this->error .=
" : ".$langs->trans(
"CategoryExistsAtSameLevel");
460 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie (";
461 $sql .=
"fk_parent,";
463 $sql .=
" description,";
470 $sql .=
" import_key,";
473 $sql .=
" date_creation,";
474 $sql .=
" fk_user_creat";
475 $sql .=
") VALUES (";
476 $sql .= (int) $this->fk_parent.
",";
477 $sql .=
"'".$this->db->escape($this->label).
"', ";
478 $sql .=
"'".$this->db->escape($this->
description).
"', ";
479 $sql .=
"'".$this->db->escape($this->color).
"', ";
481 $sql .= ($this->socid > 0 ? $this->socid :
'null').
", ";
483 $sql .=
"'".$this->db->escape($this->visible).
"', ";
484 $sql .= ((int) $type).
", ";
485 $sql .= (!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
'null').
", ";
486 $sql .= (!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
'null').
", ";
487 $sql .= (int) $conf->entity.
", ";
488 $sql .=
"'".$this->db->idate($now).
"', ";
489 $sql .= (int) $user->id;
492 $res = $this->db->query($sql);
494 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"categorie");
509 if (!$error && !$notrigger) {
511 $result = $this->
call_trigger(
'CATEGORY_CREATE', $user);
522 $this->db->rollback();
526 $this->db->rollback();
530 $this->error = $this->db->error();
531 $this->db->rollback();
552 $this->label = trim($this->label);
554 $this->ref_ext = trim($this->ref_ext);
555 $this->fk_parent = ($this->fk_parent !=
"" ? intval($this->fk_parent) : 0);
556 $this->visible = ($this->visible !=
"" ? intval($this->visible) : 0);
559 $this->error = $langs->trans(
"ImpossibleUpdateCat");
560 $this->error .=
" : ".$langs->trans(
"CategoryExistsAtSameLevel");
566 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"categorie";
567 $sql .=
" SET label = '".$this->db->escape($this->label).
"',";
568 $sql .=
" description = '".$this->db->escape($this->
description).
"',";
569 $sql .=
" ref_ext = '".$this->db->escape($this->ref_ext).
"',";
570 $sql .=
" color = '".$this->db->escape($this->color).
"'";
572 $sql .=
", fk_soc = ".($this->socid > 0 ? $this->socid :
'null');
574 $sql .=
", visible = ".(int) $this->visible;
575 $sql .=
", fk_parent = ".(int) $this->fk_parent;
576 $sql .=
", fk_user_modif = ".(int) $user->id;
577 $sql .=
" WHERE rowid = ".((int) $this->
id);
579 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
580 if ($this->db->query($sql)) {
591 if (!$error && !$notrigger) {
593 $result = $this->
call_trigger(
'CATEGORY_MODIFY', $user);
604 $this->db->rollback();
608 $this->db->rollback();
621 public function delete($user, $notrigger = 0)
626 $this->fk_parent = ($this->fk_parent !=
"" ? intval($this->fk_parent) : 0);
632 if (!$error && !$notrigger) {
634 $result = $this->
call_trigger(
'CATEGORY_DELETE', $user);
643 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"categorie";
644 $sql .=
" SET fk_parent = ".((int) $this->fk_parent);
645 $sql .=
" WHERE fk_parent = ".((int) $this->
id);
647 if (!$this->db->query($sql)) {
648 $this->error = $this->db->lasterror();
653 $arraydelete = array(
654 'categorie_account' =>
'fk_categorie',
655 'categorie_actioncomm' =>
'fk_categorie',
656 'categorie_contact' =>
'fk_categorie',
657 'categorie_fournisseur' =>
'fk_categorie',
658 'categorie_knowledgemanagement' => array(
'field' =>
'fk_categorie',
'enabled' => isModEnabled(
'knowledgemanagement')),
659 'categorie_member' =>
'fk_categorie',
660 'categorie_user' =>
'fk_categorie',
661 'categorie_product' =>
'fk_categorie',
662 'categorie_project' =>
'fk_categorie',
663 'categorie_societe' =>
'fk_categorie',
664 'categorie_ticket' => array(
'field' =>
'fk_categorie',
'enabled' => isModEnabled(
'ticket')),
665 'categorie_warehouse' =>
'fk_categorie',
666 'categorie_website_page' => array(
'field' =>
'fk_categorie',
'enabled' => isModEnabled(
'website')),
667 'bank_class' =>
'fk_categ',
668 'categorie_lang' =>
'fk_category',
669 'categorie' =>
'rowid',
671 foreach ($arraydelete as $key => $value) {
672 if (is_array($value)) {
673 if (empty($value[
'enabled'])) {
676 $value = $value[
'field'];
678 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$key;
679 $sql .=
" WHERE ".$value.
" = ".((int) $this->
id);
680 if (!$this->db->query($sql)) {
681 $this->errors[] = $this->db->lasterror();
682 dol_syslog(
"Error sql=".$sql.
" ".$this->error, LOG_ERR);
692 dol_syslog(get_class($this).
"::delete erreur ".$this->error, LOG_ERR);
700 $this->db->rollback();
721 if ($this->
id == -1) {
726 $type = $obj->element;
729 dol_syslog(get_class($this).
'::add_type', LOG_DEBUG);
733 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
734 $sql .=
" (fk_categorie, fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
")";
735 $sql .=
" VALUES (".((int) $this->
id).
", ".((int) $obj->id).
")";
737 if ($this->db->query($sql)) {
739 $sql =
'SELECT fk_parent FROM '.MAIN_DB_PREFIX.
'categorie';
740 $sql .=
" WHERE rowid = ".((int) $this->
id);
742 dol_syslog(get_class($this).
"::add_type", LOG_DEBUG);
743 $resql = $this->db->query($sql);
745 if ($this->db->num_rows($resql) > 0) {
746 $objparent = $this->db->fetch_object($resql);
748 if (!empty($objparent->fk_parent)) {
750 $cat->id = $objparent->fk_parent;
751 if (!$cat->containsObject($type, $obj->id)) {
752 $result = $cat->add_type($obj, $type);
754 $this->error = $cat->error;
762 $this->error = $this->db->lasterror();
766 $this->db->rollback();
772 $this->context = array(
'linkto'=>$obj);
783 $this->db->rollback();
787 $this->db->rollback();
788 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
789 $this->error = $this->db->lasterrno();
792 $this->error = $this->db->lasterror();
815 if ($type ==
'societe') {
817 dol_syslog(get_class($this).
"::del_type(): type 'societe' is deprecated, please use 'customer' instead", LOG_WARNING);
818 } elseif ($type ==
'fournisseur') {
820 dol_syslog(get_class($this).
"::del_type(): type 'fournisseur' is deprecated, please use 'supplier' instead", LOG_WARNING);
825 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
826 $sql .=
" WHERE fk_categorie = ".((int) $this->
id);
827 $sql .=
" AND fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = ".((
int) $obj->id);
829 dol_syslog(get_class($this).
'::del_type', LOG_DEBUG);
830 if ($this->db->query($sql)) {
832 $this->context = array(
'unlinkoff'=>$obj);
833 $result = $this->
call_trigger(
'CATEGORY_UNLINK', $user);
843 $this->db->rollback();
847 $this->db->rollback();
848 $this->error = $this->db->lasterror();
867 public function getObjectsInCateg($type, $onlyids = 0, $limit = 0, $offset = 0, $sortfield =
'', $sortorder =
'ASC', $filter = array(), $filtermode =
'AND')
873 $classnameforobj = $this->MAP_OBJ_CLASS[$type];
874 $obj =
new $classnameforobj($this->db);
876 $sql =
"SELECT c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]);
877 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]).
" as c";
878 $sql .=
", ".MAIN_DB_PREFIX.(empty($this->MAP_OBJ_TABLE[$type]) ? $type : $this->MAP_OBJ_TABLE[$type]).
" as o";
879 $sql .=
" WHERE o.entity IN (".getEntity($obj->element).
")";
880 $sql .=
" AND c.fk_categorie = ".((int) $this->
id);
882 if ((array_key_exists($type, $this->MAP_OBJ_TABLE) && $this->MAP_OBJ_TABLE[$type] ==
"actioncomm") || $type ==
"actioncomm") {
883 $sql .=
" AND c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = o.id";
885 $sql .=
" AND c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = o.rowid";
888 if (($type ==
'customer' || $type ==
'supplier') && $user->socid > 0) {
889 $sql .=
" AND o.rowid = ".((int) $user->socid);
893 if (count($filter) > 0) {
894 foreach ($filter as $key => $value) {
895 if ($key ==
'o.rowid') {
896 $sqlwhere[] = $key.
" = ".((int) $value);
897 } elseif ($key ==
'customsql') {
898 $sqlwhere[] = $value;
902 if (count($sqlwhere) > 0) {
903 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
905 $sql .= $this->db->order($sortfield, $sortorder);
906 if ($limit > 0 || $offset > 0) {
907 $sql .= $this->db->plimit($limit + 1, $offset);
910 dol_syslog(get_class($this).
"::getObjectsInCateg", LOG_DEBUG);
912 $resql = $this->db->query($sql);
914 while ($rec = $this->db->fetch_array($resql)) {
916 $objs[] = $rec[
'fk_'.(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])];
918 $classnameforobj = $this->MAP_OBJ_CLASS[$type];
920 $obj =
new $classnameforobj($this->db);
921 $obj->fetch($rec[
'fk_'.(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])]);
928 $this->error = $this->db->error().
' sql='.$sql;
943 $sql =
"SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
944 $sql .=
" WHERE fk_categorie = ".((int) $this->
id).
" AND fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = ".((
int) $object_id);
946 dol_syslog(get_class($this).
"::containsObject", LOG_DEBUG);
948 $resql = $this->db->query($sql);
950 return $this->db->fetch_object($resql)->nb;
952 $this->error = $this->db->error();
968 public function getListForItem($id, $type =
'customer', $sortfield =
"s.rowid", $sortorder =
'ASC', $limit = 0, $page = 0)
970 $categories = array();
975 $subcol_name =
"fk_".$type;
976 if ($type ==
"customer") {
977 $sub_type =
"societe";
978 $subcol_name =
"fk_soc";
980 if ($type ==
"supplier") {
981 $sub_type =
"fournisseur";
982 $subcol_name =
"fk_soc";
984 if ($type ==
"contact") {
985 $subcol_name =
"fk_socpeople";
988 $idoftype = array_search($type, self::$MAP_ID_TO_CODE);
990 $sql =
"SELECT s.rowid";
991 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as s, ".MAIN_DB_PREFIX.
"categorie_".$sub_type.
" as sub";
992 $sql .=
' WHERE s.entity IN ('.getEntity(
'category').
')';
993 $sql .=
' AND s.type='.((int) $idoftype);
994 $sql .=
' AND s.rowid = sub.fk_categorie';
995 $sql .=
" AND sub.".$subcol_name.
" = ".((int) $id);
997 $sql .= $this->db->order($sortfield, $sortorder);
1000 $nbtotalofrecords =
'';
1002 $result = $this->db->query($sql);
1003 $nbtotalofrecords = $this->db->num_rows($result);
1004 if (($page * $limit) > $nbtotalofrecords) {
1014 $offset = $limit * $page;
1016 $sql .= $this->db->plimit($limit + 1, $offset);
1019 $result = $this->db->query($sql);
1022 $num = $this->db->num_rows($result);
1023 $min = min($num, ($limit <= 0 ? $num : $limit));
1025 $obj = $this->db->fetch_object($result);
1026 $category_static =
new Categorie($this->db);
1027 if ($category_static->fetch($obj->rowid)) {
1028 $categories[$i][
'id'] = $category_static->id;
1029 $categories[$i][
'fk_parent'] = $category_static->fk_parent;
1030 $categories[$i][
'label'] = $category_static->label;
1031 $categories[$i][
'description'] = $category_static->description;
1032 $categories[$i][
'color'] = $category_static->color;
1033 $categories[$i][
'socid'] = $category_static->socid;
1034 $categories[$i][
'ref_ext'] = $category_static->ref_ext;
1035 $categories[$i][
'visible'] = $category_static->visible;
1036 $categories[$i][
'type'] = $category_static->type;
1037 $categories[$i][
'entity'] = $category_static->entity;
1038 $categories[$i][
'array_options'] = $category_static->array_options;
1041 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && isset($category_static->multilangs)) {
1042 $categories[$i][
'multilangs'] = $category_static->multilangs;
1048 $this->error = $this->db->lasterror();
1051 if (!count($categories)) {
1067 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"categorie";
1068 $sql .=
" WHERE fk_parent = ".((int) $this->
id);
1069 $sql .=
" AND entity IN (".getEntity(
'category').
")";
1071 $res = $this->db->query($sql);
1074 while ($rec = $this->db->fetch_array($res)) {
1076 $cat->fetch($rec[
'rowid']);
1095 $this->motherof = array();
1098 $sql =
"SELECT fk_parent as id_parent, rowid as id_son";
1099 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
1100 $sql .=
" WHERE fk_parent != 0";
1101 $sql .=
" AND entity IN (".getEntity(
'category').
")";
1103 dol_syslog(get_class($this).
"::load_motherof", LOG_DEBUG);
1104 $resql = $this->db->query($sql);
1106 while ($obj = $this->db->fetch_object($resql)) {
1107 $this->motherof[$obj->id_son] = $obj->id_parent;
1141 if (!is_numeric($type)) {
1142 $type = $this->MAP_ID[$type];
1144 if (is_null($type)) {
1145 $this->error =
'BadValueForParameterType';
1149 if (is_string($markafterid)) {
1150 $markafterid = explode(
',', $markafterid);
1151 } elseif (is_numeric($markafterid)) {
1152 if ($markafterid > 0) {
1153 $markafterid = array($markafterid);
1155 $markafterid = array();
1157 } elseif (!is_array($markafterid)) {
1158 $markafterid = array();
1161 $this->cats = array();
1166 $current_lang = $langs->getDefaultLang();
1169 $sql =
"SELECT DISTINCT c.rowid, c.label, c.ref_ext, c.description, c.color, c.fk_parent, c.visible";
1171 $sql .=
", t.label as label_trans, t.description as description_trans";
1173 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as c";
1175 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_lang as t ON t.fk_category=c.rowid AND t.lang='".$this->db->escape($current_lang).
"'";
1177 $sql .=
" WHERE c.entity IN (".getEntity(
'category').
")";
1178 $sql .=
" AND c.type = ".(int) $type;
1180 dol_syslog(get_class($this).
"::get_full_arbo get category list", LOG_DEBUG);
1181 $resql = $this->db->query($sql);
1184 $nbcateg = $this->db->num_rows($resql);
1186 while ($obj = $this->db->fetch_object($resql)) {
1187 $this->cats[$obj->rowid][
'rowid'] = $obj->rowid;
1188 $this->cats[$obj->rowid][
'id'] = $obj->rowid;
1189 $this->cats[$obj->rowid][
'fk_parent'] = $obj->fk_parent;
1190 $this->cats[$obj->rowid][
'label'] = !empty($obj->label_trans) ? $obj->label_trans : $obj->label;
1191 $this->cats[$obj->rowid][
'description'] = !empty($obj->description_trans) ? $obj->description_trans : $obj->description;
1192 $this->cats[$obj->rowid][
'color'] = $obj->color;
1193 $this->cats[$obj->rowid][
'visible'] = $obj->visible;
1194 $this->cats[$obj->rowid][
'ref_ext'] = $obj->ref_ext;
1195 $this->cats[$obj->rowid][
'picto'] =
'category';
1204 dol_syslog(get_class($this).
"::get_full_arbo call to buildPathFromId", LOG_DEBUG);
1205 foreach ($this->cats as $key => $val) {
1211 if (count($markafterid) > 0) {
1212 $keyfiltercatid =
'('.implode(
'|', $markafterid).
')';
1215 $keyfilter1 =
'^'.$keyfiltercatid.
'$';
1216 $keyfilter2 =
'_'.$keyfiltercatid.
'$';
1217 $keyfilter3 =
'^'.$keyfiltercatid.
'_';
1218 $keyfilter4 =
'_'.$keyfiltercatid.
'_';
1219 foreach ($this->cats as $key => $val) {
1220 $test = (preg_match(
'/'.$keyfilter1.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter2.
'/', $val[
'fullpath'])
1221 || preg_match(
'/'.$keyfilter3.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter4.
'/', $val[
'fullpath']));
1223 if (($test && !$include) || (!$test && $include)) {
1224 unset($this->cats[$key]);
1229 dol_syslog(get_class($this).
"::get_full_arbo dol_sort_array", LOG_DEBUG);
1230 $this->cats =
dol_sort_array($this->cats,
'fulllabel',
'asc',
true,
false);
1249 if (!empty($this->cats[$id_categ][
'fullpath'])) {
1251 dol_syslog(get_class($this).
"::buildPathFromId fullpath and fulllabel already defined", LOG_WARNING);
1261 $this->cats[$id_categ][
'fullpath'] =
'_'.$id_categ;
1262 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$id_categ][
'label'];
1264 $cursor_categ = $id_categ;
1266 while ((empty($protection) || $i < $protection) && !empty($this->motherof[$cursor_categ])) {
1268 $this->cats[$id_categ][
'fullpath'] =
'_'.$this->motherof[$cursor_categ].$this->cats[$id_categ][
'fullpath'];
1269 $this->cats[$id_categ][
'fulllabel'] = (empty($this->cats[$this->motherof[$cursor_categ]]) ?
'NotFound' : $this->cats[$this->motherof[$cursor_categ]][
'label']).
' >> '.$this->cats[$id_categ][
'fulllabel'];
1272 $cursor_categ = $this->motherof[$cursor_categ];
1277 $nbunderscore = substr_count($this->cats[$id_categ][
'fullpath'],
'_');
1278 $this->cats[$id_categ][
'level'] = ($nbunderscore ? $nbunderscore :
null);
1295 if (!is_numeric($type)) {
1296 $type = $this->MAP_ID[$type];
1299 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"categorie";
1300 $sql .=
" WHERE entity IN (".getEntity(
'category').
")";
1301 if (!is_null($type)) {
1302 $sql .=
" AND type = ".(int) $type;
1305 $sql .=
" AND fk_parent = 0";
1308 $res = $this->db->query($sql);
1311 while ($rec = $this->db->fetch_array($res)) {
1313 $cat->fetch($rec[
'rowid']);
1314 $cats[$rec[
'rowid']] = $cat;
1345 $type = $this->type;
1347 if (!is_numeric($type)) {
1348 $type = $this->MAP_ID[$type];
1354 $sql =
"SELECT c.rowid";
1355 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as c ";
1356 $sql .=
" WHERE c.entity IN (".getEntity(
'category').
")";
1357 $sql .=
" AND c.type = ".((int) $type);
1358 $sql .=
" AND c.fk_parent = ".((int) $this->fk_parent);
1359 $sql .=
" AND c.label = '".$this->db->escape($this->label).
"'";
1361 dol_syslog(get_class($this).
"::already_exists", LOG_DEBUG);
1362 $resql = $this->db->query($sql);
1364 if ($this->db->num_rows($resql) > 0) {
1365 $obj = $this->db->fetch_array($resql);
1371 if ($obj[0] > 0 && $obj[0] != $this->
id) {
1372 dol_syslog(get_class($this).
"::already_exists category with name=".$this->label.
" and parent ".$this->fk_parent.
" exists: rowid=".$obj[0].
" current_id=".$this->id, LOG_DEBUG);
1376 dol_syslog(get_class($this).
"::already_exists no category with same name=".$this->label.
" and same parent ".$this->fk_parent.
" than category id=".$this->id, LOG_DEBUG);
1379 $this->error = $this->db->error();
1396 public function print_all_ways($sep =
'>>', $url =
'', $nocolor = 0, $addpicto = 0)
1402 foreach ($allways as $way) {
1406 foreach ($way as $cat) {
1409 if (empty($nocolor)) {
1410 $forced_color =
'colortoreplace';
1411 if ($i == count($way)) {
1413 $forced_color =
'categtextwhite';
1416 $forced_color =
'categtextblack';
1423 $link =
'<a href="'.DOL_URL_ROOT.
'/categories/viewcat.php?id='.$cat->id.
'&type='.$cat->type.
'" class="'.$forced_color.
'">';
1425 $w[] = $link.(($addpicto && $i == 1) ?
img_object(
'',
'category',
'class="paddingright"') :
'').$cat->label.$linkend;
1426 } elseif ($url ==
'none') {
1427 $link =
'<span class="'.$forced_color.
'">';
1428 $linkend =
'</span>';
1429 $w[] = $link.(($addpicto && $i == 1) ?
img_object(
'',
'category',
'class="paddingright"') :
'').$cat->label.$linkend;
1431 $w[] =
'<a class="'.$forced_color.
'" href="'.DOL_URL_ROOT.
'/'.$url.
'?catid='.$cat->id.
'">'.($addpicto ?
img_object(
'',
'category') :
'').$cat->label.
'</a>';
1434 $newcategwithpath = preg_replace(
'/colortoreplace/', $forced_color, implode(
'<span class="inline-block valignmiddle paddingleft paddingright '.$forced_color.
'">'.$sep.
'</span>', $w));
1436 $ways[] = $newcategwithpath;
1454 $sql =
"SELECT fk_parent FROM ".MAIN_DB_PREFIX.
"categorie";
1455 $sql .=
" WHERE rowid = ".((int) $this->
id);
1457 $res = $this->db->query($sql);
1460 while ($rec = $this->db->fetch_array($res)) {
1461 if ($rec[
'fk_parent'] > 0) {
1463 $cat->fetch($rec[
'fk_parent']);
1487 if (is_array($parents)) {
1488 foreach ($parents as $parent) {
1489 $allways = $parent->get_all_ways();
1490 foreach ($allways as $way) {
1498 if (count($ways) == 0) {
1499 $ways[0][0] = $this;
1519 if (is_numeric($type)) {
1520 $type = Categorie::$MAP_ID_TO_CODE[$type];
1523 if ($type === Categorie::TYPE_BANK_LINE) {
1525 $sql =
"SELECT c.label, c.rowid";
1526 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_class as a, ".MAIN_DB_PREFIX.
"bank_categ as c";
1527 $sql .=
" WHERE a.lineid=".((int) $id).
" AND a.fk_categ = c.rowid";
1528 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
1529 $sql .=
" ORDER BY c.label";
1531 $res = $this->db->query($sql);
1533 while ($obj = $this->db->fetch_object($res)) {
1534 if ($mode ==
'id') {
1535 $cats[] = $obj->rowid;
1536 } elseif ($mode ==
'label') {
1537 $cats[] = $obj->label;
1540 $cat->id = $obj->rowid;
1541 $cat->label = $obj->label;
1550 $sql =
"SELECT ct.fk_categorie, c.label, c.rowid";
1551 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]).
" as ct, ".MAIN_DB_PREFIX.
"categorie as c";
1552 $sql .=
" WHERE ct.fk_categorie = c.rowid AND ct.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = ".(
int) $id;
1556 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
1558 $res = $this->db->query($sql);
1560 while ($obj = $this->db->fetch_object($res)) {
1561 if ($mode ==
'id') {
1562 $cats[] = $obj->rowid;
1563 } elseif ($mode ==
'label') {
1564 $cats[] = $obj->label;
1567 $cat->fetch($obj->fk_categorie);
1591 public function rechercher($id, $nom, $type, $exact =
false, $case =
false)
1594 if (is_numeric($type)) {
1595 dol_syslog(__METHOD__.
': using numeric types is deprecated.', LOG_WARNING);
1601 if (is_numeric($type)) {
1603 $map_type = array_flip($this->MAP_ID);
1604 $type = $map_type[$type];
1605 dol_syslog(get_class($this).
"::rechercher(): numeric types are deprecated, please use string instead", LOG_WARNING);
1609 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"categorie";
1610 $sql .=
" WHERE type = ".((int) $this->MAP_ID[$type]);
1611 $sql .=
" AND entity IN (".getEntity(
'category').
")";
1614 $nom =
'%'.$this->db->escape(str_replace(
'*',
'%', $nom)).
'%';
1617 $sql .=
" AND label LIKE '".$this->db->escape($nom).
"'";
1619 $sql .=
" AND label LIKE BINARY '".$this->db->escape($nom).
"'";
1623 $sql .=
" AND rowid = ".((int) $id);
1626 $res = $this->db->query($sql);
1628 while ($rec = $this->db->fetch_array($res)) {
1630 $cat->fetch($rec[
'rowid']);
1636 $this->error = $this->db->error().
' sql='.$sql;
1651 $langs->load(
'categories');
1655 $datas[
'label'] = $langs->trans(
"ShowCategory").
': '.($this->
ref ? $this->
ref : $this->label);
1673 public function getNomUrl($withpicto = 0, $option =
'', $maxlength = 0, $moreparam =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value =
'')
1675 global $conf, $hookmanager;
1677 if (!empty($conf->dol_no_mouse_hover)) {
1684 'objecttype' => $this->element,
1685 'option' => $option,
1687 $classfortooltip =
'classfortooltip';
1690 $classfortooltip =
'classforajaxtooltip';
1691 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1697 $url = DOL_URL_ROOT.
'/categories/viewcat.php?id='.$this->
id.
'&type='.$this->
type.$moreparam.
'&backtopage='.urlencode($_SERVER[
'PHP_SELF'].($moreparam ?
'?'.$moreparam :
''));
1699 if ($option !==
'nolink') {
1701 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1702 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1703 $add_save_lastsearch_values = 1;
1705 if ($url && $add_save_lastsearch_values) {
1706 $url .=
'&save_lastsearch_values=1';
1711 $forced_color =
'categtextwhite';
1714 $forced_color =
'categtextblack';
1719 if (empty($notooltip)) {
1721 $label = $langs->trans(
"ShowMyObject");
1722 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1724 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1725 $linkclose .= $dataparams.
' class="'.$classfortooltip.
' '.$forced_color.($morecss ?
' '.$morecss :
'').
'"';
1727 $linkclose = ($morecss ?
' class="'.$forced_color.($morecss ?
' '.$morecss :
'').
'"' :
'');
1730 if ($option ==
'nolink' || empty($url)) {
1731 $linkstart =
'<span';
1733 $linkstart =
'<a href="'.$url.
'"';
1735 $linkstart .= $linkclose.
'>';
1736 if ($option ==
'nolink' || empty($url)) {
1737 $linkend =
'</span>';
1742 $result .= $linkstart;
1745 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1748 if ($withpicto != 2) {
1749 $result .=
dol_trunc(($this->
ref ? $this->
ref : $this->label), $maxlength);
1752 $result .= $linkend;
1755 $hookmanager->initHooks(array($this->element .
'dao'));
1756 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1757 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1759 $result = $hookmanager->resPrint;
1761 $result .= $hookmanager->resPrint;
1778 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1780 $dir = $sdir.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'category').$this->id.
"/";
1783 if (!file_exists($dir)) {
1787 if (file_exists($dir)) {
1788 if (is_array($file[
'name']) && count($file[
'name']) > 0) {
1789 $nbfile = count($file[
'name']);
1790 for ($i = 0; $i <= $nbfile; $i++) {
1791 $originImage = $dir.$file[
'name'][$i];
1796 if (file_exists($originImage)) {
1802 $originImage = $dir.$file[
'name'];
1807 if (file_exists($originImage)) {
1826 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1831 $dirthumb = $dir.
'thumbs/';
1833 if (file_exists($dir)) {
1834 $handle = opendir($dir);
1835 if (is_resource($handle)) {
1836 while (($file = readdir($handle)) !==
false) {
1837 if (
dol_is_file($dir.$file) && preg_match(
'/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $dir.$file)) {
1842 $photo_vignette =
'';
1844 if (preg_match(
'/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $photo, $regs)) {
1845 $photo_vignette = preg_replace(
'/'.$regs[0].
'/i',
'', $photo).
'_small'.$regs[0];
1850 $obj[
'photo'] = $photo;
1851 if ($photo_vignette && is_file($dirthumb.$photo_vignette)) {
1852 $obj[
'photo_vignette'] =
'thumbs/'.$photo_vignette;
1854 $obj[
'photo_vignette'] =
"";
1857 $tabobj[$nbphoto - 1] = $obj;
1860 if ($nbmax && $nbphoto >= $nbmax) {
1883 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1885 $dir = dirname($file).
'/';
1886 $dirthumb = $dir.
'/thumbs/';
1887 $filename = preg_replace(
'/'.preg_quote($dir,
'/').
'/i',
'', $file);
1894 if (preg_match(
'/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $filename, $regs)) {
1895 $photo_vignette = preg_replace(
'/'.$regs[0].
'/i',
'', $filename).
'_small'.$regs[0];
1896 if (file_exists($dirthumb.$photo_vignette)) {
1912 $infoImg = getimagesize($file);
1913 $this->imgWidth = $infoImg[0];
1914 $this->imgHeight = $infoImg[1];
1929 $langs_available = $langs->get_available_languages();
1930 $current_lang = $langs->getDefaultLang();
1932 foreach ($langs_available as $key => $value) {
1933 $sql =
"SELECT rowid";
1934 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_lang";
1935 $sql .=
" WHERE fk_category=".((int) $this->
id);
1936 $sql .=
" AND lang = '".$this->db->escape($key).
"'";
1938 $result = $this->db->query($sql);
1940 if ($key == $current_lang) {
1941 if ($this->db->num_rows($result)) {
1942 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"categorie_lang";
1943 $sql2 .=
" SET label = '".$this->db->escape($this->label).
"',";
1944 $sql2 .=
" description = '".$this->db->escape($this->
description).
"'";
1945 $sql2 .=
" WHERE fk_category = ".((int) $this->
id).
" AND lang = '".$this->db->escape($key).
"'";
1947 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_lang (fk_category, lang, label, description)";
1948 $sql2 .=
" VALUES(".((int) $this->
id).
", '".$this->db->escape($key).
"', '".$this->db->escape($this->label).
"'";
1949 $sql2 .=
", '".$this->db->escape($this->multilangs[$key][
"description"]).
"')";
1951 dol_syslog(get_class($this).
'::setMultiLangs', LOG_DEBUG);
1952 if (!$this->db->query($sql2)) {
1953 $this->error = $this->db->lasterror();
1956 } elseif (isset($this->multilangs[$key])) {
1957 if ($this->db->num_rows($result)) {
1958 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"categorie_lang";
1959 $sql2 .=
" SET label='".$this->db->escape($this->multilangs[$key][
"label"]).
"',";
1960 $sql2 .=
" description='".$this->db->escape($this->multilangs[$key][
"description"]).
"'";
1961 $sql2 .=
" WHERE fk_category=".((int) $this->
id).
" AND lang='".$this->db->escape($key).
"'";
1963 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_lang (fk_category, lang, label, description)";
1964 $sql2 .=
" VALUES(".((int) $this->
id).
", '".$this->db->escape($key).
"', '".$this->db->escape($this->multilangs[$key][
"label"]).
"'";
1965 $sql2 .=
",'".$this->db->escape($this->multilangs[$key][
"description"]).
"')";
1969 if ($this->multilangs[$key][
"label"] || $this->multilangs[$key][
"description"] || $this->multilangs[$key][
"note"]) {
1970 dol_syslog(get_class($this).
'::setMultiLangs', LOG_DEBUG);
1972 if (!$this->db->query($sql2)) {
1973 $this->error = $this->db->lasterror();
1981 $result = $this->
call_trigger(
'CATEGORY_SET_MULTILANGS', $user);
1983 $this->error = $this->db->lasterror();
2001 $current_lang = $langs->getDefaultLang();
2003 $sql =
"SELECT lang, label, description";
2004 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_lang";
2005 $sql .=
" WHERE fk_category=".((int) $this->
id);
2007 $result = $this->db->query($sql);
2009 while ($obj = $this->db->fetch_object($result)) {
2011 if ($obj->lang == $current_lang) {
2012 $this->label = $obj->label;
2015 $this->multilangs[$obj->lang][
"label"] = $obj->label;
2016 $this->multilangs[$obj->lang][
"description"] = $obj->description;
2020 $this->error = $langs->trans(
"Error").
" : ".$this->db->error().
" - ".$sql;
2046 dol_syslog(get_class($this).
"::initAsSpecimen");
2050 $this->fk_parent = 0;
2051 $this->label =
'SPECIMEN';
2052 $this->specimen = 1;
2055 $this->
type = self::TYPE_PRODUCT;
2085 if ($type ==
'bank_account') {
2089 return " LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_".$type.
" as cp ON ".$rowIdName.
" = cp.fk_".$type;
2103 if ($type ==
'bank_account') {
2106 if ($type ==
'customer') {
2109 if ($type ==
'supplier') {
2110 $type =
'fournisseur';
2113 if (empty($searchList) && !is_array($searchList)) {
2117 $searchCategorySqlList = array();
2118 foreach ($searchList as $searchCategory) {
2119 if (intval($searchCategory) == -2) {
2120 $searchCategorySqlList[] =
" cp.fk_categorie IS NULL";
2121 } elseif (intval($searchCategory) > 0) {
2122 $searchCategorySqlList[] =
" ".$rowIdName.
" IN (SELECT fk_".$type.
" FROM ".MAIN_DB_PREFIX.
"categorie_".$type.
" WHERE fk_categorie = ".((int) $searchCategory).
")";
2126 if (!empty($searchCategorySqlList)) {
2127 return " AND (".implode(
' AND ', $searchCategorySqlList).
")";
2140 dol_syslog(get_class($this).
"::count_all_categories", LOG_DEBUG);
2141 $sql =
"SELECT COUNT(rowid) FROM ".MAIN_DB_PREFIX.
"categorie";
2142 $sql .=
" WHERE entity IN (".getEntity(
'category').
")";
2144 $res = $this->db->query($sql);
2146 $obj = $this->db->fetch_object($res);
Class to manage categories.
getListForItem($id, $type='customer', $sortfield="s.rowid", $sortorder='ASC', $limit=0, $page=0)
List categories of an element id.
get_image_size($file)
Load size of image file.
getObjectsInCateg($type, $onlyids=0, $limit=0, $offset=0, $sortfield='', $sortorder='ASC', $filter=array(), $filtermode='AND')
Return list of fetched instance of elements having this category.
load_motherof()
Load the array this->motherof that is array(id_son=>id_parent, ...)
getNomUrl($withpicto=0, $option='', $maxlength=0, $moreparam='', $notooltip=0, $morecss='', $save_lastsearch_value='')
Return name and link of category (with picto) Use ->id, ->ref, ->label, ->color.
getLibStatut($mode)
Return label of contact status.
delete_photo($file)
Efface la photo de la categorie et sa vignette.
containing($id, $type, $mode='object')
Return list of categories (object instances or labels) linked to element of id $id and type $type Sho...
getTooltipContentArray($params)
getTooltipContentArray
countNbOfCategories()
Count all categories.
del_type($obj, $type)
Delete object from category.
buildPathFromId($id_categ, $protection=1000)
For category id_categ and its childs available in this->cats, define property fullpath and fulllabel.
static getFilterSelectQuery($type, $rowIdName, $searchList)
Return the addtional SQL SELECT query for filtering a list by a category.
create($user, $notrigger=0)
Add category into database.
rechercher($id, $nom, $type, $exact=false, $case=false)
Returns categories whose id or name match add wildcards in the name unless $exact = true.
getMultiLangs()
Load array this->multilangs.
already_exists()
Check if no category with same label already exists for this cat's parent or root and for this cat's ...
get_filles()
Return direct childs id of a category into an array.
initAsSpecimen()
Initialise an instance with random values.
get_all_categories($type=null, $parent=false)
Returns all categories.
static getFilterJoinQuery($type, $rowIdName)
Return the addtional SQL JOIN query for filtering a list by a category.
containsObject($type, $object_id)
Check for the presence of an object in a category.
get_main_categories($type=null)
Returns the top level categories (which are not child)
__construct($db)
Constructor.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
setMultiLangs(User $user, $notrigger=0)
Update ou cree les traductions des infos produits.
getMapList()
Get map list.
get_full_arbo($type, $markafterid=0, $include=0)
Rebuilding the category tree as an array Return an array of table('id','id_mere',....
get_meres()
Returns an array containing the list of parent categories.
add_type($obj, $type='')
Link an object to the category.
update(User $user, $notrigger=0)
Update category.
liste_photos($dir, $nbmax=0)
Return tableau de toutes les photos de la categorie.
get_all_ways()
Returns in a table all possible paths to get to the category starting with the major categories repre...
print_all_ways($sep='>>', $url='', $nocolor=0, $addpicto=0)
Returns the path of the category, with the names of the categories separated by $sep (" >> " by defau...
add_photo($sdir, $file)
Deplace fichier uploade sous le nom $file dans le repertoire sdir.
fetch($id, $label='', $type=null, $ref_ext='')
Load category into memory from database.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
deleteExtraFields()
Delete all extra fields values for the current object.
addThumbs($file)
Build thumb.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Make control on an uploaded file from an GUI page and move it to final destination.
dol_is_file($pathoffile)
Return if path is a file.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
colorIsLight($stringcolor)
Return true if the color is light.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type