37require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/ticket/class/ticket.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/knowledgemanagement/class/knowledgerecord.class.php';
51 const TYPE_PRODUCT =
'product';
52 const TYPE_SUPPLIER =
'supplier';
53 const TYPE_CUSTOMER =
'customer';
54 const TYPE_MEMBER =
'member';
55 const TYPE_CONTACT =
'contact';
56 const TYPE_USER =
'user';
57 const TYPE_PROJECT =
'project';
58 const TYPE_ACCOUNT =
'bank_account';
59 const TYPE_BANK_LINE =
'bank_line';
60 const TYPE_WAREHOUSE =
'warehouse';
61 const TYPE_ACTIONCOMM =
'actioncomm';
62 const TYPE_WEBSITE_PAGE =
'website_page';
63 const TYPE_TICKET =
'ticket';
64 const TYPE_KNOWLEDGEMANAGEMENT =
'knowledgemanagement';
69 public $picto =
'category';
75 protected $MAP_ID = array(
89 'knowledgemanagement' => 13
97 public static $MAP_ID_TO_CODE = array(
109 11 =>
'website_page',
111 13 =>
'knowledgemanagement'
119 public $MAP_CAT_FK = array(
122 'contact' =>
'socpeople',
123 'bank_account' =>
'account',
131 public $MAP_CAT_TABLE = array(
132 'customer' =>
'societe',
133 'supplier' =>
'fournisseur',
134 'bank_account' =>
'account',
142 public $MAP_OBJ_CLASS = array(
143 'product' =>
'Product',
144 'customer' =>
'Societe',
145 'supplier' =>
'Fournisseur',
146 'member' =>
'Adherent',
147 'contact' =>
'Contact',
149 'account' =>
'Account',
150 'bank_account' =>
'Account',
151 'project' =>
'Project',
152 'warehouse' =>
'Entrepot',
153 'actioncomm' =>
'ActionComm',
154 'website_page' =>
'WebsitePage',
155 'ticket' =>
'Ticket',
156 'knowledgemanagement' =>
'KnowledgeRecord'
164 public static $MAP_TYPE_TITLE_AREA = array(
165 'product' =>
'ProductsCategoriesArea',
166 'customer' =>
'CustomersCategoriesArea',
167 'supplier' =>
'SuppliersCategoriesArea',
168 'member' =>
'MembersCategoriesArea',
169 'contact' =>
'ContactsCategoriesArea',
170 'user' =>
'UsersCategoriesArea',
171 'account' =>
'AccountsCategoriesArea',
172 'bank_account' =>
'AccountsCategoriesArea',
173 'project' =>
'ProjectsCategoriesArea',
174 'warehouse' =>
'StocksCategoriesArea',
175 'actioncomm' =>
'ActioncommCategoriesArea',
176 'website_page' =>
'WebsitePageCategoriesArea'
183 public $MAP_OBJ_TABLE = array(
184 'customer' =>
'societe',
185 'supplier' =>
'societe',
186 'member' =>
'adherent',
187 'contact' =>
'socpeople',
188 'account' =>
'bank_account',
189 'project' =>
'projet',
190 'warehouse' =>
'entrepot',
191 'knowledgemanagement' =>
'knowledgemanagement_knowledgerecord'
197 public $element =
'category';
202 public $table_element =
'categorie';
261 public $cats = array();
266 public $motherof = array();
271 public $childs = array();
299 if (is_object($hookmanager)) {
300 $hookmanager->initHooks(array(
'category'));
301 $parameters = array();
302 $reshook = $hookmanager->executeHooks(
'constructCategory', $parameters, $this);
303 if ($reshook >= 0 && !empty($hookmanager->resArray)) {
304 foreach ($hookmanager->resArray as $mapList) {
305 $mapId = $mapList[
'id'];
306 $mapCode = $mapList[
'code'];
307 self::$MAP_ID_TO_CODE[$mapId] = $mapCode;
308 $this->MAP_ID[$mapCode] = $mapId;
309 $this->MAP_CAT_FK[$mapCode] = isset($mapList[
'cat_fk']) ? $mapList[
'cat_fk'] :
null;
310 $this->MAP_CAT_TABLE[$mapCode] = isset($mapList[
'cat_table']) ? $mapList[
'cat_table'] :
null;
311 $this->MAP_OBJ_CLASS[$mapCode] = $mapList[
'obj_class'];
312 $this->MAP_OBJ_TABLE[$mapCode] = $mapList[
'obj_table'];
327 foreach ($this->MAP_ID as $mapCode => $mapId) {
331 'cat_fk' => (empty($this->MAP_CAT_FK[$mapCode]) ? $mapCode : $this->MAP_CAT_FK[$mapCode]),
332 'cat_table' => (empty($this->MAP_CAT_TABLE[$mapCode]) ? $mapCode : $this->MAP_CAT_TABLE[$mapCode]),
333 'obj_class' => (empty($this->MAP_OBJ_CLASS[$mapCode]) ? $mapCode : $this->MAP_OBJ_CLASS[$mapCode]),
334 'obj_table' => (empty($this->MAP_OBJ_TABLE[$mapCode]) ? $mapCode : $this->MAP_OBJ_TABLE[$mapCode])
350 public function fetch($id, $label =
'', $type =
null, $ref_ext =
'')
353 if (empty($id) && empty($label) && empty($ref_ext)) {
354 $this->error =
"No category to search for";
357 if (!is_null($type) && !is_numeric($type)) {
358 $type = $this->MAP_ID[$type];
361 $sql =
"SELECT rowid, fk_parent, entity, label, description, color, position, fk_soc, visible, type, ref_ext";
362 $sql .=
", date_creation, tms, fk_user_creat, fk_user_modif";
363 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
365 $sql .=
" WHERE rowid = ".((int) $id);
366 } elseif (!empty($ref_ext)) {
367 $sql .=
" WHERE ref_ext LIKE '".$this->db->escape($ref_ext).
"'";
369 $sql .=
" WHERE label = '".$this->db->escape($label).
"' AND entity IN (".
getEntity(
'category').
")";
370 if (!is_null($type)) {
371 $sql .=
" AND type = ".((int) $type);
375 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
376 $resql = $this->db->query($sql);
378 if ($this->db->num_rows($resql) > 0 && $res = $this->db->fetch_array($resql)) {
379 $this->
id = $res[
'rowid'];
381 $this->fk_parent = (int) $res[
'fk_parent'];
382 $this->label = $res[
'label'];
384 $this->color = $res[
'color'];
386 $this->socid = (int) $res[
'fk_soc'];
387 $this->visible = (int) $res[
'visible'];
388 $this->
type = $res[
'type'];
389 $this->ref_ext = $res[
'ref_ext'];
390 $this->entity = (int) $res[
'entity'];
391 $this->date_creation = $this->db->jdate($res[
'date_creation']);
392 $this->date_modification = $this->db->jdate($res[
'tms']);
393 $this->user_creation_id = (int) $res[
'fk_user_creat'];
394 $this->user_modification_id = (int) $res[
'fk_user_modif'];
400 $this->db->free($resql);
409 $this->error =
"No category found";
414 $this->error = $this->db->lasterror;
415 $this->errors[] = $this->db->lasterror;
430 public function create($user, $notrigger = 0)
432 global $conf, $langs, $hookmanager;
433 $langs->load(
'categories');
437 if (!is_numeric($type)) {
438 $type = $this->MAP_ID[$type];
443 dol_syslog(get_class($this).
'::create', LOG_DEBUG);
446 $this->label = trim($this->label);
448 $this->color = trim($this->color);
450 $this->import_key = trim($this->import_key);
451 $this->ref_ext = trim($this->ref_ext);
452 if (empty($this->visible)) {
455 $this->fk_parent = ($this->fk_parent !=
"" ? intval($this->fk_parent) : 0);
458 $this->error = $langs->trans(
"ImpossibleAddCat", $this->label);
459 $this->error .=
" : ".$langs->trans(
"CategoryExistsAtSameLevel");
466 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie (";
467 $sql .=
"fk_parent,";
469 $sql .=
" description,";
471 $sql .=
" position,";
477 $sql .=
" import_key,";
480 $sql .=
" date_creation,";
481 $sql .=
" fk_user_creat";
482 $sql .=
") VALUES (";
483 $sql .= (int) $this->fk_parent.
",";
484 $sql .=
"'".$this->db->escape($this->label).
"', ";
485 $sql .=
"'".$this->db->escape($this->
description).
"', ";
486 $sql .=
"'".$this->db->escape($this->color).
"', ";
489 $sql .= ($this->socid > 0 ? $this->socid :
'null').
", ";
491 $sql .=
"'".$this->db->escape($this->visible).
"', ";
492 $sql .= ((int) $type).
", ";
493 $sql .= (!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
'null').
", ";
494 $sql .= (!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
'null').
", ";
495 $sql .= (int) $conf->entity.
", ";
496 $sql .=
"'".$this->db->idate($now).
"', ";
497 $sql .= (int) $user->id;
500 $res = $this->db->query($sql);
502 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"categorie");
517 if (!$error && !$notrigger) {
519 $result = $this->
call_trigger(
'CATEGORY_CREATE', $user);
530 $this->db->rollback();
534 $this->db->rollback();
538 $this->error = $this->db->error();
539 $this->db->rollback();
560 $this->label = trim($this->label);
562 $this->ref_ext = trim($this->ref_ext);
563 $this->fk_parent = ($this->fk_parent !=
"" ? intval($this->fk_parent) : 0);
564 $this->visible = ($this->visible !=
"" ? intval($this->visible) : 0);
567 $this->error = $langs->trans(
"ImpossibleUpdateCat");
568 $this->error .=
" : ".$langs->trans(
"CategoryExistsAtSameLevel");
574 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"categorie";
575 $sql .=
" SET label = '".$this->db->escape($this->label).
"',";
576 $sql .=
" description = '".$this->db->escape($this->
description).
"',";
577 $sql .=
" ref_ext = '".$this->db->escape($this->ref_ext).
"',";
578 $sql .=
" color = '".$this->db->escape($this->color).
"'";
579 $sql .=
", position = ".(int) $this->
position;
581 $sql .=
", fk_soc = ".($this->socid > 0 ? $this->socid :
'null');
583 $sql .=
", visible = ".(int) $this->visible;
584 $sql .=
", fk_parent = ".(int) $this->fk_parent;
585 $sql .=
", fk_user_modif = ".(int) $user->id;
586 $sql .=
" WHERE rowid = ".((int) $this->
id);
588 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
589 if ($this->db->query($sql)) {
600 if (!$error && !$notrigger) {
602 $result = $this->
call_trigger(
'CATEGORY_MODIFY', $user);
613 $this->db->rollback();
617 $this->db->rollback();
630 public function delete($user, $notrigger = 0)
635 $this->fk_parent = ($this->fk_parent !=
"" ? intval($this->fk_parent) : 0);
641 if (!$error && !$notrigger) {
643 $result = $this->
call_trigger(
'CATEGORY_DELETE', $user);
652 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"categorie";
653 $sql .=
" SET fk_parent = ".((int) $this->fk_parent);
654 $sql .=
" WHERE fk_parent = ".((int) $this->
id);
656 if (!$this->db->query($sql)) {
657 $this->error = $this->db->lasterror();
662 $arraydelete = array(
663 'categorie_account' =>
'fk_categorie',
664 'categorie_actioncomm' =>
'fk_categorie',
665 'categorie_contact' =>
'fk_categorie',
666 'categorie_fournisseur' =>
'fk_categorie',
667 'categorie_knowledgemanagement' => array(
'field' =>
'fk_categorie',
'enabled' => isModEnabled(
'knowledgemanagement')),
668 'categorie_member' =>
'fk_categorie',
669 'categorie_user' =>
'fk_categorie',
670 'categorie_product' =>
'fk_categorie',
671 'categorie_project' =>
'fk_categorie',
672 'categorie_societe' =>
'fk_categorie',
673 'categorie_ticket' => array(
'field' =>
'fk_categorie',
'enabled' => isModEnabled(
'ticket')),
674 'categorie_warehouse' =>
'fk_categorie',
675 'categorie_website_page' => array(
'field' =>
'fk_categorie',
'enabled' => isModEnabled(
'website')),
676 'bank_class' =>
'fk_categ',
677 'categorie_lang' =>
'fk_category',
678 'categorie' =>
'rowid',
680 foreach ($arraydelete as $key => $value) {
681 if (is_array($value)) {
682 if (empty($value[
'enabled'])) {
685 $value = $value[
'field'];
687 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$key;
688 $sql .=
" WHERE ".$value.
" = ".((int) $this->
id);
689 if (!$this->db->query($sql)) {
690 $this->errors[] = $this->db->lasterror();
691 dol_syslog(
"Error sql=".$sql.
" ".$this->error, LOG_ERR);
701 dol_syslog(get_class($this).
"::delete erreur ".$this->error, LOG_ERR);
709 $this->db->rollback();
730 if ($this->
id == -1) {
735 $type = $obj->element;
738 dol_syslog(get_class($this).
'::add_type', LOG_DEBUG);
742 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
743 $sql .=
" (fk_categorie, fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
")";
744 $sql .=
" VALUES (".((int) $this->
id).
", ".((int) $obj->id).
")";
746 if ($this->db->query($sql)) {
748 $sql =
'SELECT fk_parent FROM '.MAIN_DB_PREFIX.
'categorie';
749 $sql .=
" WHERE rowid = ".((int) $this->
id);
751 dol_syslog(get_class($this).
"::add_type", LOG_DEBUG);
752 $resql = $this->db->query($sql);
754 if ($this->db->num_rows($resql) > 0) {
755 $objparent = $this->db->fetch_object($resql);
757 if (!empty($objparent->fk_parent)) {
759 $cat->id = $objparent->fk_parent;
760 if (!$cat->containsObject($type, $obj->id)) {
761 $result = $cat->add_type($obj, $type);
763 $this->error = $cat->error;
771 $this->error = $this->db->lasterror();
775 $this->db->rollback();
781 $this->context = array(
'linkto' => $obj);
792 $this->db->rollback();
796 $this->db->rollback();
797 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
798 $this->error = $this->db->lasterrno();
801 $this->error = $this->db->lasterror();
824 if ($type ==
'societe') {
826 dol_syslog(get_class($this).
"::del_type(): type 'societe' is deprecated, please use 'customer' instead", LOG_WARNING);
827 } elseif ($type ==
'fournisseur') {
829 dol_syslog(get_class($this).
"::del_type(): type 'fournisseur' is deprecated, please use 'supplier' instead", LOG_WARNING);
834 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
835 $sql .=
" WHERE fk_categorie = ".((int) $this->
id);
836 $sql .=
" AND fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = ".((
int) $obj->id);
838 dol_syslog(get_class($this).
'::del_type', LOG_DEBUG);
839 if ($this->db->query($sql)) {
841 $this->context = array(
'unlinkoff' => $obj);
842 $result = $this->
call_trigger(
'CATEGORY_UNLINK', $user);
852 $this->db->rollback();
856 $this->db->rollback();
857 $this->error = $this->db->lasterror();
877 public function getObjectsInCateg($type, $onlyids = 0, $limit = 0, $offset = 0, $sortfield =
'', $sortorder =
'ASC', $filter =
'', $filtermode =
'AND')
883 $classnameforobj = $this->MAP_OBJ_CLASS[$type];
884 $obj =
new $classnameforobj($this->db);
886 $sql =
"SELECT c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" as fk_object";
887 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]).
" as c";
888 $sql .=
", ".MAIN_DB_PREFIX.(empty($this->MAP_OBJ_TABLE[$type]) ? $type : $this->MAP_OBJ_TABLE[$type]).
" as o";
889 $sql .=
" WHERE o.entity IN (".getEntity($obj->element).
")";
890 $sql .=
" AND c.fk_categorie = ".((int) $this->
id);
892 if ((array_key_exists($type, $this->MAP_OBJ_TABLE) && $this->MAP_OBJ_TABLE[$type] ==
"actioncomm") || $type ==
"actioncomm") {
893 $sql .=
" AND c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = o.id";
895 $sql .=
" AND c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = o.rowid";
898 if (($type ==
'customer' || $type ==
'supplier') && $user->socid > 0) {
899 $sql .=
" AND o.rowid = ".((int) $user->socid);
905 $this->errors[] = $errormessage;
906 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
910 $sql .= $this->db->order($sortfield, $sortorder);
911 if ($limit > 0 || $offset > 0) {
912 $sql .= $this->db->plimit($limit + 1, $offset);
915 dol_syslog(get_class($this).
"::getObjectsInCateg", LOG_DEBUG);
917 $resql = $this->db->query($sql);
919 while ($rec = $this->db->fetch_array($resql)) {
921 $objs[] = $rec[
'fk_object'];
923 $classnameforobj = $this->MAP_OBJ_CLASS[$type];
925 $obj =
new $classnameforobj($this->db);
926 $obj->fetch($rec[
'fk_object']);
934 $this->error = $this->db->error().
' sql='.$sql;
949 $sql =
"SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
950 $sql .=
" WHERE fk_categorie = ".((int) $this->
id).
" AND fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = ".((
int) $object_id);
952 dol_syslog(get_class($this).
"::containsObject", LOG_DEBUG);
954 $resql = $this->db->query($sql);
956 return $this->db->fetch_object($resql)->nb;
958 $this->error = $this->db->error();
974 public function getListForItem($id, $type =
'customer', $sortfield =
"s.rowid", $sortorder =
'ASC', $limit = 0, $page = 0)
976 $categories = array();
981 $subcol_name =
"fk_".$type;
982 if ($type ==
"customer") {
983 $sub_type =
"societe";
984 $subcol_name =
"fk_soc";
986 if ($type ==
"supplier") {
987 $sub_type =
"fournisseur";
988 $subcol_name =
"fk_soc";
990 if ($type ==
"contact") {
991 $subcol_name =
"fk_socpeople";
994 $idoftype = array_search($type, self::$MAP_ID_TO_CODE);
996 $sql =
"SELECT s.rowid";
997 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as s, ".MAIN_DB_PREFIX.
"categorie_".$sub_type.
" as sub";
998 $sql .=
' WHERE s.entity IN ('.getEntity(
'category').
')';
999 $sql .=
' AND s.type='.((int) $idoftype);
1000 $sql .=
' AND s.rowid = sub.fk_categorie';
1001 $sql .=
" AND sub.".$subcol_name.
" = ".((int) $id);
1003 $sql .= $this->db->order($sortfield, $sortorder);
1006 $nbtotalofrecords =
'';
1008 $result = $this->db->query($sql);
1009 $nbtotalofrecords = $this->db->num_rows($result);
1010 if (($page * $limit) > $nbtotalofrecords) {
1020 $offset = $limit * $page;
1022 $sql .= $this->db->plimit($limit + 1, $offset);
1025 $result = $this->db->query($sql);
1028 $num = $this->db->num_rows($result);
1029 $min = min($num, ($limit <= 0 ? $num : $limit));
1031 $obj = $this->db->fetch_object($result);
1032 $category_static =
new Categorie($this->db);
1033 if ($category_static->fetch($obj->rowid)) {
1034 $categories[$i][
'id'] = $category_static->id;
1035 $categories[$i][
'fk_parent'] = $category_static->fk_parent;
1036 $categories[$i][
'label'] = $category_static->label;
1037 $categories[$i][
'description'] = $category_static->description;
1038 $categories[$i][
'color'] = $category_static->color;
1039 $categories[$i][
'position'] = $category_static->position;
1040 $categories[$i][
'socid'] = $category_static->socid;
1041 $categories[$i][
'ref_ext'] = $category_static->ref_ext;
1042 $categories[$i][
'visible'] = $category_static->visible;
1043 $categories[$i][
'type'] = $category_static->type;
1044 $categories[$i][
'entity'] = $category_static->entity;
1045 $categories[$i][
'array_options'] = $category_static->array_options;
1048 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && isset($category_static->multilangs)) {
1049 $categories[$i][
'multilangs'] = $category_static->multilangs;
1055 $this->error = $this->db->lasterror();
1058 if (!count($categories)) {
1074 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"categorie";
1075 $sql .=
" WHERE fk_parent = ".((int) $this->
id);
1076 $sql .=
" AND entity IN (".getEntity(
'category').
")";
1078 $res = $this->db->query($sql);
1081 while ($rec = $this->db->fetch_array($res)) {
1083 $cat->fetch($rec[
'rowid']);
1102 $this->motherof = array();
1105 $sql =
"SELECT fk_parent as id_parent, rowid as id_son";
1106 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
1107 $sql .=
" WHERE fk_parent != 0";
1108 $sql .=
" AND entity IN (".getEntity(
'category').
")";
1110 dol_syslog(get_class($this).
"::load_motherof", LOG_DEBUG);
1111 $resql = $this->db->query($sql);
1113 while ($obj = $this->db->fetch_object($resql)) {
1114 $this->motherof[$obj->id_son] = $obj->id_parent;
1148 if (!is_numeric($type)) {
1149 $type = $this->MAP_ID[$type];
1151 if (is_null($type)) {
1152 $this->error =
'BadValueForParameterType';
1156 if (is_string($fromid)) {
1157 $fromid = explode(
',', $fromid);
1158 } elseif (is_numeric($fromid)) {
1160 $fromid = array($fromid);
1164 } elseif (!is_array($fromid)) {
1168 $this->cats = array();
1173 $current_lang = $langs->getDefaultLang();
1176 $sql =
"SELECT DISTINCT c.rowid, c.label, c.ref_ext, c.description, c.color, c.position, c.fk_parent, c.visible";
1178 $sql .=
", t.label as label_trans, t.description as description_trans";
1180 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as c";
1182 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_lang as t ON t.fk_category=c.rowid AND t.lang='".$this->db->escape($current_lang).
"'";
1184 $sql .=
" WHERE c.entity IN (".getEntity(
'category').
")";
1185 $sql .=
" AND c.type = ".(int) $type;
1187 dol_syslog(get_class($this).
"::get_full_arbo get category list", LOG_DEBUG);
1188 $resql = $this->db->query($sql);
1191 $nbcateg = $this->db->num_rows($resql);
1193 while ($obj = $this->db->fetch_object($resql)) {
1194 $this->cats[$obj->rowid][
'rowid'] = $obj->rowid;
1195 $this->cats[$obj->rowid][
'id'] = $obj->rowid;
1196 $this->cats[$obj->rowid][
'fk_parent'] = $obj->fk_parent;
1197 $this->cats[$obj->rowid][
'label'] = !empty($obj->label_trans) ? $obj->label_trans : $obj->label;
1198 $this->cats[$obj->rowid][
'description'] = !empty($obj->description_trans) ? $obj->description_trans : $obj->description;
1199 $this->cats[$obj->rowid][
'color'] = $obj->color;
1200 $this->cats[$obj->rowid][
'position'] = $obj->position;
1201 $this->cats[$obj->rowid][
'visible'] = $obj->visible;
1202 $this->cats[$obj->rowid][
'ref_ext'] = $obj->ref_ext;
1203 $this->cats[$obj->rowid][
'picto'] =
'category';
1205 $this->cats[$obj->rowid][
'fullpath'] =
'';
1206 $this->cats[$obj->rowid][
'fulllabel'] =
'';
1215 dol_syslog(get_class($this).
"::get_full_arbo call to buildPathFromId", LOG_DEBUG);
1216 foreach ($this->cats as $key => $val) {
1222 if (count($fromid) > 0) {
1223 $keyfiltercatid =
'('.implode(
'|', $fromid).
')';
1226 $keyfilter1 =
'^'.$keyfiltercatid.
'$';
1227 $keyfilter2 =
'_'.$keyfiltercatid.
'$';
1228 $keyfilter3 =
'^'.$keyfiltercatid.
'_';
1229 $keyfilter4 =
'_'.$keyfiltercatid.
'_';
1230 foreach (array_keys($this->cats) as $key) {
1231 $fullpath = (string) $this->cats[$key][
'fullpath'];
1232 $test = (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
1233 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath));
1235 if (($test && !$include) || (!$test && $include)) {
1236 unset($this->cats[$key]);
1241 dol_syslog(get_class($this).
"::get_full_arbo dol_sort_array", LOG_DEBUG);
1243 $this->cats =
dol_sort_array($this->cats,
'fulllabel',
'asc', 1, 0, 1);
1262 if (!empty($this->cats[$id_categ][
'fullpath'])) {
1264 dol_syslog(get_class($this).
"::buildPathFromId fullpath and fulllabel already defined", LOG_WARNING);
1274 $this->cats[$id_categ][
'fullpath'] =
'_'.$id_categ;
1275 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$id_categ][
'label'];
1277 $cursor_categ = $id_categ;
1279 while ((empty($protection) || $i < $protection) && !empty($this->motherof[$cursor_categ])) {
1281 $this->cats[$id_categ][
'fullpath'] =
'_'.$this->motherof[$cursor_categ].$this->cats[$id_categ][
'fullpath'];
1282 $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'];
1285 $cursor_categ = $this->motherof[$cursor_categ];
1290 $nbunderscore = substr_count($this->cats[$id_categ][
'fullpath'],
'_');
1291 $this->cats[$id_categ][
'level'] = ($nbunderscore ? $nbunderscore :
null);
1308 if (!is_numeric($type)) {
1309 $type = $this->MAP_ID[$type];
1312 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"categorie";
1313 $sql .=
" WHERE entity IN (".getEntity(
'category').
")";
1314 if (!is_null($type)) {
1315 $sql .=
" AND type = ".(int) $type;
1318 $sql .=
" AND fk_parent = 0";
1321 $res = $this->db->query($sql);
1324 while ($rec = $this->db->fetch_array($res)) {
1326 $cat->fetch($rec[
'rowid']);
1327 $cats[$rec[
'rowid']] = $cat;
1358 $type = $this->type;
1360 if (!is_numeric($type)) {
1361 $type = $this->MAP_ID[$type];
1367 $sql =
"SELECT c.rowid";
1368 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as c ";
1369 $sql .=
" WHERE c.entity IN (".getEntity(
'category').
")";
1370 $sql .=
" AND c.type = ".((int) $type);
1371 $sql .=
" AND c.fk_parent = ".((int) $this->fk_parent);
1372 $sql .=
" AND c.label = '".$this->db->escape($this->label).
"'";
1374 dol_syslog(get_class($this).
"::already_exists", LOG_DEBUG);
1376 $resql = $this->db->query($sql);
1378 if ($this->db->num_rows($resql) > 0) {
1379 $obj = $this->db->fetch_object($resql);
1384 if (!empty($obj) && $obj->rowid > 0 && $obj->rowid != $this->id) {
1385 dol_syslog(get_class($this).
"::already_exists category with name=".$this->label.
" and parent ".$this->fk_parent.
" exists: rowid=".$obj->rowid.
" current_id=".$this->id, LOG_DEBUG);
1389 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);
1392 $this->error = $this->db->error();
1409 public function print_all_ways($sep =
'>>', $url =
'', $nocolor = 0, $addpicto = 0)
1415 foreach ($all_ways as $way) {
1419 foreach ($way as $cat) {
1422 if (empty($nocolor)) {
1423 $forced_color =
'colortoreplace';
1424 if ($i == count($way)) {
1426 $forced_color =
'categtextwhite';
1429 $forced_color =
'categtextblack';
1436 $link =
'<a href="'.DOL_URL_ROOT.
'/categories/viewcat.php?id='.$cat->id.
'&type='.$cat->type.
'" class="'.$forced_color.
'">';
1438 $w[] = $link.(($addpicto && $i == 1) ?
img_object(
'',
'category',
'class="paddingright"') :
'').$cat->label.$linkend;
1439 } elseif ($url ==
'none') {
1440 $link =
'<span class="'.$forced_color.
'">';
1441 $linkend =
'</span>';
1442 $w[] = $link.(($addpicto && $i == 1) ?
img_object(
'',
'category',
'class="paddingright"') :
'').$cat->label.$linkend;
1444 $w[] =
'<a class="'.$forced_color.
'" href="'.DOL_URL_ROOT.
'/'.$url.
'?catid='.$cat->id.
'">'.($addpicto ?
img_object(
'',
'category') :
'').$cat->label.
'</a>';
1447 $newcategwithpath = preg_replace(
'/colortoreplace/', $forced_color, implode(
'<span class="inline-block valignmiddle paddingleft paddingright '.$forced_color.
'">'.$sep.
'</span>', $w));
1449 $ways[] = $newcategwithpath;
1467 $sql =
"SELECT fk_parent FROM ".MAIN_DB_PREFIX.
"categorie";
1468 $sql .=
" WHERE rowid = ".((int) $this->
id);
1470 $res = $this->db->query($sql);
1473 while ($rec = $this->db->fetch_array($res)) {
1474 if ($rec[
'fk_parent'] > 0) {
1476 $cat->fetch($rec[
'fk_parent']);
1500 if (is_array($parents)) {
1501 foreach ($parents as $parent) {
1502 $all_ways = $parent->get_all_ways();
1503 foreach ($all_ways as $way) {
1511 if (count($ways) == 0) {
1512 $ways[0][0] = $this;
1532 if (is_numeric($type)) {
1533 $type = Categorie::$MAP_ID_TO_CODE[$type];
1536 if ($type === Categorie::TYPE_BANK_LINE) {
1538 $sql =
"SELECT c.label, c.rowid";
1539 $sql .=
" FROM ".MAIN_DB_PREFIX.
"bank_class as a, ".MAIN_DB_PREFIX.
"bank_categ as c";
1540 $sql .=
" WHERE a.lineid=".((int) $id).
" AND a.fk_categ = c.rowid";
1541 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
1542 $sql .=
" ORDER BY c.label";
1544 $res = $this->db->query($sql);
1546 while ($obj = $this->db->fetch_object($res)) {
1547 if ($mode ==
'id') {
1548 $cats[] = $obj->rowid;
1549 } elseif ($mode ==
'label') {
1550 $cats[] = $obj->label;
1553 $cat->id = $obj->rowid;
1554 $cat->label = $obj->label;
1563 $sql =
"SELECT ct.fk_categorie, c.label, c.rowid";
1564 $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";
1565 $sql .=
" WHERE ct.fk_categorie = c.rowid AND ct.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = ".(
int) $id;
1569 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
1571 $res = $this->db->query($sql);
1573 while ($obj = $this->db->fetch_object($res)) {
1574 if ($mode ==
'id') {
1575 $cats[] = $obj->rowid;
1576 } elseif ($mode ==
'label') {
1577 $cats[] = $obj->label;
1580 $cat->fetch($obj->fk_categorie);
1604 public function rechercher($id, $nom, $type, $exact =
false, $case =
false)
1607 if (is_numeric($type)) {
1608 dol_syslog(__METHOD__.
': using numeric types is deprecated.', LOG_WARNING);
1614 if (is_numeric($type)) {
1616 $map_type = array_flip($this->MAP_ID);
1617 $type = $map_type[$type];
1618 dol_syslog(get_class($this).
"::rechercher(): numeric types are deprecated, please use string instead", LOG_WARNING);
1622 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"categorie";
1623 $sql .=
" WHERE type = ".((int) $this->MAP_ID[$type]);
1624 $sql .=
" AND entity IN (".getEntity(
'category').
")";
1627 $nom =
'%'.$this->db->escape(str_replace(
'*',
'%', $nom)).
'%';
1630 $sql .=
" AND label LIKE '".$this->db->escape($nom).
"'";
1632 $sql .=
" AND label LIKE BINARY '".$this->db->escape($nom).
"'";
1636 $sql .=
" AND rowid = ".((int) $id);
1639 $res = $this->db->query($sql);
1641 while ($rec = $this->db->fetch_array($res)) {
1643 $cat->fetch($rec[
'rowid']);
1649 $this->error = $this->db->error().
' sql='.$sql;
1662 include_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
1663 include_once DOL_DOCUMENT_ROOT .
'/core/lib/images.lib.php';
1665 $sdir .=
'/' .
get_exdir($this->
id, 2, 0, 0, $this,
'category') . $this->
id .
"/photos/";
1668 if (file_exists($dir_osencoded)) {
1669 $handle = opendir($dir_osencoded);
1670 if (is_resource($handle)) {
1671 while (($file = readdir($handle)) !==
false) {
1673 $file = mb_convert_encoding($file,
'UTF-8',
'ISO-8859-1');
1694 $langs->load(
'categories');
1698 $datas[
'label'] = $langs->trans(
"ShowCategory").
': '.($this->
ref ? $this->
ref : $this->label);
1716 public function getNomUrl($withpicto = 0, $option =
'', $maxlength = 0, $moreparam =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = 0)
1718 global $conf, $langs, $hookmanager;
1720 if (!empty($conf->dol_no_mouse_hover)) {
1727 'objecttype' => $this->element,
1728 'option' => $option,
1730 $classfortooltip =
'classfortooltip';
1733 $classfortooltip =
'classforajaxtooltip';
1734 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1740 $url = DOL_URL_ROOT.
'/categories/viewcat.php?id='.$this->
id.
'&type='.$this->
type.$moreparam.
'&backtopage='.urlencode($_SERVER[
'PHP_SELF'].($moreparam ?
'?'.$moreparam :
''));
1742 if ($option !==
'nolink') {
1744 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1745 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1746 $add_save_lastsearch_values = 1;
1748 if ($url && $add_save_lastsearch_values) {
1749 $url .=
'&save_lastsearch_values=1';
1754 $forced_color =
'categtextwhite';
1757 $forced_color =
'categtextblack';
1762 if (empty($notooltip)) {
1764 $label = $langs->trans(
"ShowMyObject");
1765 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1767 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1768 $linkclose .= $dataparams.
' class="'.$classfortooltip.
' '.$forced_color.($morecss ?
' '.$morecss :
'').
'"';
1770 $linkclose = ($morecss ?
' class="'.$forced_color.($morecss ?
' '.$morecss :
'').
'"' :
'');
1773 if ($option ==
'nolink' || empty($url)) {
1774 $linkstart =
'<span';
1776 $linkstart =
'<a href="'.$url.
'"';
1778 $linkstart .= $linkclose.
'>';
1779 if ($option ==
'nolink' || empty($url)) {
1780 $linkend =
'</span>';
1785 $result .= $linkstart;
1788 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1791 if ($withpicto != 2) {
1792 $result .=
dol_trunc(($this->
ref ? $this->
ref : $this->label), $maxlength);
1795 $result .= $linkend;
1798 $hookmanager->initHooks(array($this->element .
'dao'));
1799 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1800 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1802 $result = $hookmanager->resPrint;
1804 $result .= $hookmanager->resPrint;
1821 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1823 $dir = $sdir.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'category').$this->id.
"/";
1826 if (!file_exists($dir)) {
1830 if (file_exists($dir)) {
1831 if (is_array($file[
'name']) && count($file[
'name']) > 0) {
1832 $nbfile = count($file[
'name']);
1833 for ($i = 0; $i < $nbfile; $i++) {
1834 $originImage = $dir.$file[
'name'][$i];
1839 if (file_exists($originImage)) {
1845 $originImage = $dir.$file[
'name'];
1850 if (file_exists($originImage)) {
1869 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1874 $dirthumb = $dir.
'thumbs/';
1876 if (file_exists($dir)) {
1877 $handle = opendir($dir);
1878 if (is_resource($handle)) {
1879 while (($file = readdir($handle)) !==
false) {
1880 if (
dol_is_file($dir.$file) && preg_match(
'/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $dir.$file)) {
1885 $photo_vignette =
'';
1887 if (preg_match(
'/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $photo, $regs)) {
1888 $photo_vignette = preg_replace(
'/'.$regs[0].
'/i',
'', $photo).
'_small'.$regs[0];
1893 $obj[
'photo'] = $photo;
1894 if ($photo_vignette && is_file($dirthumb.$photo_vignette)) {
1895 $obj[
'photo_vignette'] =
'thumbs/'.$photo_vignette;
1897 $obj[
'photo_vignette'] =
"";
1900 $tabobj[$nbphoto - 1] = $obj;
1903 if ($nbmax && $nbphoto >= $nbmax) {
1926 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1928 $dir = dirname($file).
'/';
1929 $dirthumb = $dir.
'/thumbs/';
1930 $filename = preg_replace(
'/'.preg_quote($dir,
'/').
'/i',
'', $file);
1937 if (preg_match(
'/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $filename, $regs)) {
1938 $photo_vignette = preg_replace(
'/'.$regs[0].
'/i',
'', $filename).
'_small'.$regs[0];
1939 if (file_exists($dirthumb.$photo_vignette)) {
1955 $infoImg = getimagesize($file);
1956 $this->imgWidth = $infoImg[0];
1957 $this->imgHeight = $infoImg[1];
1972 $langs_available = $langs->get_available_languages();
1973 $current_lang = $langs->getDefaultLang();
1975 foreach ($langs_available as $key => $value) {
1976 $sql =
"SELECT rowid";
1977 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_lang";
1978 $sql .=
" WHERE fk_category=".((int) $this->
id);
1979 $sql .=
" AND lang = '".$this->db->escape($key).
"'";
1981 $result = $this->db->query($sql);
1983 if ($key == $current_lang) {
1985 if ($this->db->num_rows($result)) {
1986 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"categorie_lang";
1987 $sql2 .=
" SET label = '".$this->db->escape($this->label).
"',";
1988 $sql2 .=
" description = '".$this->db->escape($this->
description).
"'";
1989 $sql2 .=
" WHERE fk_category = ".((int) $this->
id).
" AND lang = '".$this->db->escape($key).
"'";
1990 } elseif (isset($this->multilangs[$key])) {
1991 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_lang (fk_category, lang, label, description)";
1992 $sql2 .=
" VALUES(".((int) $this->
id).
", '".$this->db->escape($key).
"', '".$this->db->escape($this->label).
"'";
1993 $sql2 .=
", '".$this->db->escape($this->multilangs[$key][
"description"]).
"')";
1995 dol_syslog(get_class($this).
'::setMultiLangs', LOG_DEBUG);
1996 if ($sql2 && !$this->db->query($sql2)) {
1997 $this->error = $this->db->lasterror();
2000 } elseif (isset($this->multilangs[$key])) {
2001 if ($this->db->num_rows($result)) {
2002 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"categorie_lang";
2003 $sql2 .=
" SET label='".$this->db->escape($this->multilangs[$key][
"label"]).
"',";
2004 $sql2 .=
" description='".$this->db->escape($this->multilangs[$key][
"description"]).
"'";
2005 $sql2 .=
" WHERE fk_category=".((int) $this->
id).
" AND lang='".$this->db->escape($key).
"'";
2007 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_lang (fk_category, lang, label, description)";
2008 $sql2 .=
" VALUES(".((int) $this->
id).
", '".$this->db->escape($key).
"', '".$this->db->escape($this->multilangs[$key][
"label"]).
"'";
2009 $sql2 .=
",'".$this->db->escape($this->multilangs[$key][
"description"]).
"')";
2013 if ($this->multilangs[$key][
"label"] || $this->multilangs[$key][
"description"] || $this->multilangs[$key][
"note"]) {
2014 dol_syslog(get_class($this).
'::setMultiLangs', LOG_DEBUG);
2016 if (!$this->db->query($sql2)) {
2017 $this->error = $this->db->lasterror();
2025 $result = $this->
call_trigger(
'CATEGORY_SET_MULTILANGS', $user);
2027 $this->error = $this->db->lasterror();
2045 $current_lang = $langs->getDefaultLang();
2047 $sql =
"SELECT lang, label, description";
2048 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_lang";
2049 $sql .=
" WHERE fk_category=".((int) $this->
id);
2051 $result = $this->db->query($sql);
2053 while ($obj = $this->db->fetch_object($result)) {
2055 if ($obj->lang == $current_lang) {
2056 $this->label = $obj->label;
2059 $this->multilangs[$obj->lang][
"label"] = $obj->label;
2060 $this->multilangs[$obj->lang][
"description"] = $obj->description;
2064 $this->error = $langs->trans(
"Error").
" : ".$this->db->error().
" - ".$sql;
2090 dol_syslog(get_class($this).
"::initAsSpecimen");
2094 $this->fk_parent = 0;
2095 $this->label =
'SPECIMEN';
2096 $this->specimen = 1;
2099 $this->
type = self::TYPE_PRODUCT;
2131 if ($type ==
'bank_account') {
2135 return " LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_".$type.
" as cp ON ".$rowIdName.
" = cp.fk_".$type;
2149 if ($type ==
'bank_account') {
2152 if ($type ==
'customer') {
2155 if ($type ==
'supplier') {
2156 $type =
'fournisseur';
2159 if (empty($searchList) && !is_array($searchList)) {
2163 $searchCategorySqlList = array();
2164 foreach ($searchList as $searchCategory) {
2165 if (intval($searchCategory) == -2) {
2166 $searchCategorySqlList[] =
" cp.fk_categorie IS NULL";
2167 } elseif (intval($searchCategory) > 0) {
2168 $searchCategorySqlList[] =
" ".$rowIdName.
" IN (SELECT fk_".$type.
" FROM ".MAIN_DB_PREFIX.
"categorie_".$type.
" WHERE fk_categorie = ".((int) $searchCategory).
")";
2172 if (!empty($searchCategorySqlList)) {
2173 return " AND (".implode(
' AND ', $searchCategorySqlList).
")";
2186 dol_syslog(get_class($this).
"::count_all_categories", LOG_DEBUG);
2187 $sql =
"SELECT COUNT(rowid) FROM ".MAIN_DB_PREFIX.
"categorie";
2188 $sql .=
" WHERE entity IN (".getEntity(
'category').
")";
2190 $res = $this->db->query($sql);
2192 $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.
load_motherof()
Load the array this->motherof that is array(id_son=>id_parent, ...)
get_full_arbo($type, $fromid=0, $include=0)
Rebuilding the category tree as an array Return an array of table('id','id_mere',....
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 children available in this->cats, define property fullpath and fulllabe...
static getFilterSelectQuery($type, $rowIdName, $searchList)
Return the additional 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.
isAnyPhotoAvailable($sdir)
Return if at least one photo is available.
already_exists()
Check if a category with same label already exists for this cat's parent or root and for this cat's t...
get_filles()
Return direct children ids 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 additional 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.
getObjectsInCateg($type, $onlyids=0, $limit=0, $offset=0, $sortfield='', $sortorder='ASC', $filter='', $filtermode='AND')
Return list of fetched instance of elements having this category.
getMapList()
Get map list.
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 an array with all photos inside the directory.
get_all_ways()
Returns in a table all possible paths to get to the category starting with the major categories repre...
getNomUrl($withpicto=0, $option='', $maxlength=0, $moreparam='', $notooltip=0, $morecss='', $save_lastsearch_value=0)
Return name and link of category (with picto) Use ->id, ->ref, ->label, ->color.
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)
Add the image uploaded as $file to the directory $sdir/<category>-<id>/photos/.
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='')
Check validity of a file upload from an GUI page, and move it to its final destination.
dol_is_file($pathoffile)
Return if path is a file.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
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 the value of a given key, which produces ascending (default) or descending out...
colorIsLight($stringcolor)
Return true if the color is light.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
utf8_check($str)
Check if a string is in UTF8.
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)
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type