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';
65 const TYPE_FICHINTER =
'fichinter';
70 public $picto =
'category';
76 protected $MAP_ID = array(
90 'knowledgemanagement' => 13,
99 public static $MAP_ID_TO_CODE = array(
111 11 =>
'website_page',
113 13 =>
'knowledgemanagement',
122 public $MAP_CAT_FK = array(
125 'contact' =>
'socpeople',
126 'bank_account' =>
'account',
134 public $MAP_CAT_TABLE = array(
135 'customer' =>
'societe',
136 'supplier' =>
'fournisseur',
137 'bank_account' =>
'account',
145 public $MAP_OBJ_CLASS = array(
146 'product' =>
'Product',
147 'customer' =>
'Societe',
148 'supplier' =>
'Fournisseur',
149 'member' =>
'Adherent',
150 'contact' =>
'Contact',
152 'account' =>
'Account',
153 'bank_account' =>
'Account',
154 'project' =>
'Project',
155 'warehouse' =>
'Entrepot',
156 'actioncomm' =>
'ActionComm',
157 'website_page' =>
'WebsitePage',
158 'ticket' =>
'Ticket',
159 'knowledgemanagement' =>
'KnowledgeRecord',
160 'fichinter' =>
'Fichinter',
168 public static $MAP_TYPE_TITLE_AREA = array(
169 'product' =>
'ProductsCategoriesArea',
170 'customer' =>
'CustomersCategoriesArea',
171 'supplier' =>
'SuppliersCategoriesArea',
172 'member' =>
'MembersCategoriesArea',
173 'contact' =>
'ContactsCategoriesArea',
174 'user' =>
'UsersCategoriesArea',
175 'account' =>
'AccountsCategoriesArea',
176 'bank_account' =>
'AccountsCategoriesArea',
177 'project' =>
'ProjectsCategoriesArea',
178 'warehouse' =>
'StocksCategoriesArea',
179 'actioncomm' =>
'ActioncommCategoriesArea',
180 'website_page' =>
'WebsitePagesCategoriesArea',
181 'ticket' =>
'TicketsCategoriesArea',
182 'knowledgemanagement' =>
'KnowledgemanagementsCategoriesArea',
183 'fichinter' =>
'FichintersCategoriesArea',
190 public $MAP_OBJ_TABLE = array(
191 'customer' =>
'societe',
192 'supplier' =>
'societe',
193 'member' =>
'adherent',
194 'contact' =>
'socpeople',
195 'account' =>
'bank_account',
196 'project' =>
'projet',
197 'warehouse' =>
'entrepot',
198 'knowledgemanagement' =>
'knowledgemanagement_knowledgerecord',
199 'fichinter' =>
'fichinter',
205 public $element =
'category';
210 public $table_element =
'categorie';
270 public $cats = array();
275 public $motherof = array();
280 public $childs = array();
285 public $multilangs = array();
297 public $fields = array(
298 "rowid" => array(
"type" =>
"integer",
"label" =>
"TechnicalID",
"enabled" =>
"1",
'position' => 10,
'notnull' => 1,
"visible" =>
"-1",),
299 "fk_parent" => array(
"type" =>
"integer",
"label" =>
"Fkparent",
"enabled" =>
"1",
'position' => 20,
'notnull' => 1,
"visible" =>
"-1",
"css" =>
"maxwidth500 widthcentpercentminusxx",),
300 "label" => array(
"type" =>
"varchar(180)",
"label" =>
"Label",
"enabled" =>
"1",
'position' => 25,
'notnull' => 1,
"visible" =>
"-1",
"alwayseditable" =>
"1",
"css" =>
"minwidth300",
"cssview" =>
"wordbreak",
"csslist" =>
"tdoverflowmax150",),
301 "ref_ext" => array(
"type" =>
"varchar(255)",
"label" =>
"Refext",
"enabled" =>
"1",
'position' => 30,
'notnull' => 0,
"visible" =>
"0",
"alwayseditable" =>
"1",),
302 "type" => array(
"type" =>
"integer",
"label" =>
"Type",
"enabled" =>
"1",
'position' => 35,
'notnull' => 1,
"visible" =>
"-1",
"alwayseditable" =>
"1",),
303 "description" => array(
"type" =>
"text",
"label" =>
"Description",
"enabled" =>
"1",
'position' => 40,
'notnull' => 0,
"visible" =>
"-1",
"alwayseditable" =>
"1",),
304 "color" => array(
"type" =>
"varchar(8)",
"label" =>
"Color",
"enabled" =>
"1",
'position' => 45,
'notnull' => 0,
"visible" =>
"-1",
"alwayseditable" =>
"1",),
305 "position" => array(
"type" =>
"integer",
"label" =>
"Position",
"enabled" =>
"1",
'position' => 50,
'notnull' => 0,
"visible" =>
"-1",
"alwayseditable" =>
"1",),
306 "fk_soc" => array(
"type" =>
"integer:Societe:societe/class/societe.class.php",
"label" =>
"ThirdParty",
"picto" =>
"company",
"enabled" =>
"1",
'position' => 55,
'notnull' => 0,
"visible" =>
"-1",
"alwayseditable" =>
"1",
"css" =>
"maxwidth500 widthcentpercentminusxx",
"csslist" =>
"tdoverflowmax150",),
307 "visible" => array(
"type" =>
"integer",
"label" =>
"Visible",
"enabled" =>
"1",
'position' => 60,
'notnull' => 1,
"visible" =>
"-1",
"alwayseditable" =>
"1",),
308 "import_key" => array(
"type" =>
"varchar(14)",
"label" =>
"ImportId",
"enabled" =>
"1",
'position' => 900,
'notnull' => 0,
"visible" =>
"-2",
"alwayseditable" =>
"1",),
309 "date_creation" => array(
"type" =>
"datetime",
"label" =>
"Datecreation",
"enabled" =>
"1",
'position' => 70,
'notnull' => 0,
"visible" =>
"-1",
"alwayseditable" =>
"1",),
310 "tms" => array(
"type" =>
"timestamp",
"label" =>
"DateModification",
"enabled" =>
"1",
'position' => 75,
'notnull' => 1,
"visible" =>
"-1",
"alwayseditable" =>
"1",),
311 "fk_user_creat" => array(
"type" =>
"integer:User:user/class/user.class.php",
"label" =>
"UserAuthor",
"enabled" =>
"1",
'position' => 80,
'notnull' => 0,
"visible" =>
"-2",
"alwayseditable" =>
"1",
"css" =>
"maxwidth500 widthcentpercentminusxx",
"csslist" =>
"tdoverflowmax150",),
312 "fk_user_modif" => array(
"type" =>
"integer:User:user/class/user.class.php",
"label" =>
"UserModif",
"enabled" =>
"1",
'position' => 85,
'notnull' => -1,
"visible" =>
"-2",
"alwayseditable" =>
"1",
"css" =>
"maxwidth500 widthcentpercentminusxx",
"csslist" =>
"tdoverflowmax150",),
326 if (is_object($hookmanager)) {
327 $hookmanager->initHooks(array(
'category'));
328 $parameters = array();
329 $reshook = $hookmanager->executeHooks(
'constructCategory', $parameters, $this);
330 if ($reshook >= 0 && !empty($hookmanager->resArray)) {
331 foreach ($hookmanager->resArray as $mapList) {
332 $mapId = $mapList[
'id'];
333 $mapCode = $mapList[
'code'];
334 self::$MAP_ID_TO_CODE[$mapId] = $mapCode;
335 $this->MAP_ID[$mapCode] = $mapId;
336 $this->MAP_CAT_FK[$mapCode] = isset($mapList[
'cat_fk']) ? $mapList[
'cat_fk'] :
null;
337 $this->MAP_CAT_TABLE[$mapCode] = isset($mapList[
'cat_table']) ? $mapList[
'cat_table'] :
null;
338 $this->MAP_OBJ_CLASS[$mapCode] = $mapList[
'obj_class'];
339 $this->MAP_OBJ_TABLE[$mapCode] = $mapList[
'obj_table'];
354 foreach ($this->MAP_ID as $mapCode => $mapId) {
358 'cat_fk' => (empty($this->MAP_CAT_FK[$mapCode]) ? $mapCode : $this->MAP_CAT_FK[$mapCode]),
359 'cat_table' => (empty($this->MAP_CAT_TABLE[$mapCode]) ? $mapCode : $this->MAP_CAT_TABLE[$mapCode]),
360 'obj_class' => (empty($this->MAP_OBJ_CLASS[$mapCode]) ? $mapCode : $this->MAP_OBJ_CLASS[$mapCode]),
361 'obj_table' => (empty($this->MAP_OBJ_TABLE[$mapCode]) ? $mapCode : $this->MAP_OBJ_TABLE[$mapCode])
375 return $this->MAP_ID;
387 public function fetch($id, $label =
'', $type =
null, $ref_ext =
'')
390 if (empty($id) && empty($label) && empty($ref_ext)) {
391 $this->error =
"No category to search for";
394 if (!is_null($type) && !is_numeric($type)) {
395 $type = $this->MAP_ID[$type];
398 $sql =
"SELECT rowid, fk_parent, entity, label, description, color, position, fk_soc, visible, type, ref_ext";
399 $sql .=
", date_creation, tms, fk_user_creat, fk_user_modif";
400 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
402 $sql .=
" WHERE rowid = ".((int) $id);
403 } elseif (!empty($ref_ext)) {
404 $sql .=
" WHERE ref_ext LIKE '".$this->db->escape($ref_ext).
"'";
406 $sql .=
" WHERE label = '".$this->db->escape($label).
"' AND entity IN (".
getEntity(
'category').
")";
407 if (!is_null($type)) {
408 $sql .=
" AND type = ".((int) $type);
412 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
413 $resql = $this->db->query($sql);
415 if ($this->db->num_rows($resql) > 0 && $res = $this->db->fetch_array($resql)) {
416 $this->
id = $res[
'rowid'];
418 $this->fk_parent = (int) $res[
'fk_parent'];
419 $this->label = $res[
'label'];
421 $this->color = $res[
'color'];
423 $this->socid = (int) $res[
'fk_soc'];
424 $this->visible = (int) $res[
'visible'];
425 $this->
type = $res[
'type'];
426 $this->ref_ext = $res[
'ref_ext'];
427 $this->entity = (int) $res[
'entity'];
428 $this->date_creation = $this->db->jdate($res[
'date_creation']);
429 $this->date_modification = $this->db->jdate($res[
'tms']);
430 $this->user_creation_id = (int) $res[
'fk_user_creat'];
431 $this->user_modification_id = (int) $res[
'fk_user_modif'];
437 $this->db->free($resql);
446 $this->error =
"No category found";
451 $this->error = $this->db->lasterror;
452 $this->errors[] = $this->db->lasterror;
467 public function create($user, $notrigger = 0)
469 global
$conf, $langs;
470 $langs->load(
'categories');
474 if (!is_numeric($type)) {
475 $type = $this->MAP_ID[$type];
480 dol_syslog(get_class($this).
'::create', LOG_DEBUG);
483 $this->label = trim($this->label);
485 $this->color = trim($this->color);
487 if (isset($this->import_key)) {
488 $this->import_key = trim($this->import_key);
490 $this->ref_ext = trim($this->ref_ext);
491 if (empty($this->visible)) {
494 $this->fk_parent = ($this->fk_parent !=
"" ? intval($this->fk_parent) : 0);
497 $this->error = $langs->trans(
"ImpossibleAddCat", $this->label);
498 $this->error .=
" : ".$langs->trans(
"CategoryExistsAtSameLevel");
505 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie (";
506 $sql .=
"fk_parent,";
508 $sql .=
" description,";
510 $sql .=
" position,";
516 $sql .=
" import_key,";
519 $sql .=
" date_creation,";
520 $sql .=
" fk_user_creat";
521 $sql .=
") VALUES (";
522 $sql .= (int) $this->fk_parent.
",";
523 $sql .=
"'".$this->db->escape($this->label).
"', ";
524 $sql .=
"'".$this->db->escape($this->
description).
"', ";
525 $sql .=
"'".$this->db->escape($this->color).
"', ";
528 $sql .= ($this->socid > 0 ? $this->socid :
'null').
", ";
530 $sql .=
"'".$this->db->escape($this->visible).
"', ";
531 $sql .= ((int) $type).
", ";
532 $sql .= (!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
'null').
", ";
533 $sql .= (!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
'null').
", ";
534 $sql .= (int)
$conf->entity.
", ";
535 $sql .=
"'".$this->db->idate($now).
"', ";
536 $sql .= (int) $user->id;
539 $res = $this->db->query($sql);
541 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"categorie");
556 if (!$error && !$notrigger) {
558 $result = $this->
call_trigger(
'CATEGORY_CREATE', $user);
569 $this->db->rollback();
573 $this->db->rollback();
577 $this->error = $this->db->error();
578 $this->db->rollback();
599 $this->label = trim($this->label);
601 $this->ref_ext = trim($this->ref_ext);
602 $this->fk_parent = ($this->fk_parent !=
"" ? intval($this->fk_parent) : 0);
603 $this->visible = ($this->visible !=
"" ? intval($this->visible) : 0);
606 $this->error = $langs->trans(
"ImpossibleUpdateCat");
607 $this->error .=
" : ".$langs->trans(
"CategoryExistsAtSameLevel");
613 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"categorie";
614 $sql .=
" SET label = '".$this->db->escape($this->label).
"',";
615 $sql .=
" description = '".$this->db->escape($this->
description).
"',";
616 $sql .=
" ref_ext = '".$this->db->escape($this->ref_ext).
"',";
617 $sql .=
" color = '".$this->db->escape($this->color).
"'";
618 $sql .=
", position = ".(int) $this->
position;
620 $sql .=
", fk_soc = ".($this->socid > 0 ? $this->socid :
'null');
622 $sql .=
", visible = ".(int) $this->visible;
623 $sql .=
", fk_parent = ".(int) $this->fk_parent;
624 $sql .=
", fk_user_modif = ".(int) $user->id;
625 $sql .=
" WHERE rowid = ".((int) $this->
id);
627 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
628 if ($this->db->query($sql)) {
639 if (!$error && !$notrigger) {
641 $result = $this->
call_trigger(
'CATEGORY_MODIFY', $user);
652 $this->db->rollback();
656 $this->db->rollback();
669 public function delete($user, $notrigger = 0)
674 $this->fk_parent = ($this->fk_parent !=
"" ? intval($this->fk_parent) : 0);
680 if (!$error && !$notrigger) {
682 $result = $this->
call_trigger(
'CATEGORY_DELETE', $user);
691 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"categorie";
692 $sql .=
" SET fk_parent = ".((int) $this->fk_parent);
693 $sql .=
" WHERE fk_parent = ".((int) $this->
id);
695 if (!$this->db->query($sql)) {
696 $this->error = $this->db->lasterror();
701 $arraydelete = array(
702 'categorie_account' =>
'fk_categorie',
703 'categorie_actioncomm' =>
'fk_categorie',
704 'categorie_contact' =>
'fk_categorie',
705 'categorie_fournisseur' =>
'fk_categorie',
706 'categorie_knowledgemanagement' => array(
'field' =>
'fk_categorie',
'enabled' => isModEnabled(
'knowledgemanagement')),
707 'categorie_fichinter' => array(
'field' =>
'fk_categorie',
'enabled' => isModEnabled(
'intervention')),
708 'categorie_member' =>
'fk_categorie',
709 'categorie_user' =>
'fk_categorie',
710 'categorie_product' =>
'fk_categorie',
711 'categorie_project' =>
'fk_categorie',
712 'categorie_societe' =>
'fk_categorie',
713 'categorie_ticket' => array(
'field' =>
'fk_categorie',
'enabled' => isModEnabled(
'ticket')),
714 'categorie_warehouse' =>
'fk_categorie',
715 'categorie_website_page' => array(
'field' =>
'fk_categorie',
'enabled' => isModEnabled(
'website')),
716 'category_bankline' =>
'fk_categ',
717 'categorie_lang' =>
'fk_category',
718 'categorie' =>
'rowid',
720 foreach ($arraydelete as $key => $value) {
721 if (is_array($value)) {
722 if (empty($value[
'enabled'])) {
725 $value = $value[
'field'];
727 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$key;
728 $sql .=
" WHERE ".$value.
" = ".((int) $this->
id);
729 if (!$this->db->query($sql)) {
730 $this->errors[] = $this->db->lasterror();
731 dol_syslog(
"Error sql=".$sql.
" ".$this->error, LOG_ERR);
741 dol_syslog(get_class($this).
"::delete erreur ".$this->error, LOG_ERR);
749 $this->db->rollback();
770 if ($this->
id == -1) {
775 $type = $obj->element;
778 dol_syslog(get_class($this).
'::add_type', LOG_DEBUG);
782 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
783 $sql .=
" (fk_categorie, fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
")";
784 $sql .=
" VALUES (".((int) $this->
id).
", ".((int) $obj->id).
")";
786 if ($this->db->query($sql)) {
788 $sql =
'SELECT fk_parent FROM '.MAIN_DB_PREFIX.
'categorie';
789 $sql .=
" WHERE rowid = ".((int) $this->
id);
791 dol_syslog(get_class($this).
"::add_type", LOG_DEBUG);
792 $resql = $this->db->query($sql);
794 if ($this->db->num_rows($resql) > 0) {
795 $objparent = $this->db->fetch_object($resql);
797 if (!empty($objparent->fk_parent)) {
799 $cat->id = $objparent->fk_parent;
800 if (!$cat->containsObject($type, $obj->id)) {
801 $result = $cat->add_type($obj, $type);
803 $this->error = $cat->error;
811 $this->error = $this->db->lasterror();
815 $this->db->rollback();
821 $this->context = array(
'linkto' => $obj);
822 $result = $this->
call_trigger(
'CATEGORY_MODIFY', $user);
832 $this->db->rollback();
836 $this->db->rollback();
837 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
838 $this->error = $this->db->lasterrno();
841 $this->error = $this->db->lasterror();
864 if ($type ==
'societe') {
866 dol_syslog(get_class($this).
"::del_type(): type 'societe' is deprecated, please use 'customer' instead", LOG_WARNING);
867 } elseif ($type ==
'fournisseur') {
869 dol_syslog(get_class($this).
"::del_type(): type 'fournisseur' is deprecated, please use 'supplier' instead", LOG_WARNING);
874 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
875 $sql .=
" WHERE fk_categorie = ".((int) $this->
id);
876 $sql .=
" AND fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = ".((
int) $obj->id);
878 dol_syslog(get_class($this).
'::del_type', LOG_DEBUG);
879 if ($this->db->query($sql)) {
881 $this->context = array(
'unlinkoff' => $obj);
882 $result = $this->
call_trigger(
'CATEGORY_MODIFY', $user);
892 $this->db->rollback();
896 $this->db->rollback();
897 $this->error = $this->db->lasterror();
919 public function getObjectsInCateg($type, $onlyids = 0, $limit = 0, $offset = 0, $sortfield =
'', $sortorder =
'ASC', $filter =
'', $filtermode =
'AND', $filterlang =
'')
925 $classnameforobj = $this->MAP_OBJ_CLASS[$type];
926 $obj =
new $classnameforobj($this->db);
928 $sql =
"SELECT c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" as fk_object";
929 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]).
" as c";
930 $sql .=
", ".MAIN_DB_PREFIX.(empty($this->MAP_OBJ_TABLE[$type]) ? $type : $this->MAP_OBJ_TABLE[$type]).
" as o";
931 if (!empty($filterlang)) {
932 $sql .=
", ".MAIN_DB_PREFIX.(empty($this->MAP_OBJ_TABLE[$type]) ? $type : $this->MAP_OBJ_TABLE[$type]).
"_lang as ol";
934 $sql .=
" WHERE o.entity IN (".getEntity($obj->element).
")";
935 $sql .=
" AND c.fk_categorie = ".((int) $this->
id);
937 if ((array_key_exists($type, $this->MAP_OBJ_TABLE) && $this->MAP_OBJ_TABLE[$type] ==
"actioncomm") || $type ==
"actioncomm") {
938 $sql .=
" AND c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = o.id";
940 $sql .=
" AND c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = o.rowid";
942 if (!empty($filterlang)) {
943 $sql .=
" AND ol.fk_".(empty($this->MAP_OBJ_TABLE[$type]) ? $type : $this->MAP_OBJ_TABLE[$type]).
" = o.rowid";
944 $sql .=
" AND ol.lang = '".$this->db->escape($filterlang).
"'";
947 if (($type ==
'customer' || $type ==
'supplier') && $user->socid > 0) {
948 $sql .=
" AND o.rowid = ".((int) $user->socid);
954 $this->errors[] = $errormessage;
955 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
959 $sql .= $this->db->order($sortfield, $sortorder);
960 if ($limit > 0 || $offset > 0) {
961 $sql .= $this->db->plimit($limit + 1, $offset);
964 dol_syslog(get_class($this).
"::getObjectsInCateg", LOG_DEBUG);
966 $resql = $this->db->query($sql);
968 while ($rec = $this->db->fetch_array($resql)) {
970 $objs[] = $rec[
'fk_object'];
972 $classnameforobj = $this->MAP_OBJ_CLASS[$type];
974 $obj =
new $classnameforobj($this->db);
975 $obj->fetch($rec[
'fk_object']);
983 $this->error = $this->db->error().
' sql='.$sql;
998 $sql =
"SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
999 $sql .=
" WHERE fk_categorie = ".((int) $this->
id).
" AND fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = ".((
int) $object_id);
1001 dol_syslog(get_class($this).
"::containsObject", LOG_DEBUG);
1003 $resql = $this->db->query($sql);
1005 return $this->db->fetch_object($resql)->nb;
1007 $this->error = $this->db->error();
1023 public function getListForItem($id, $type =
'customer', $sortfield =
"s.rowid", $sortorder =
'ASC', $limit = 0, $page = 0)
1025 $categories = array();
1030 $subcol_name =
"fk_".$type;
1031 if ($type ==
"customer") {
1032 $sub_type =
"societe";
1033 $subcol_name =
"fk_soc";
1035 if ($type ==
"supplier") {
1036 $sub_type =
"fournisseur";
1037 $subcol_name =
"fk_soc";
1039 if ($type ==
"contact") {
1040 $subcol_name =
"fk_socpeople";
1043 $idoftype = array_search($type, self::$MAP_ID_TO_CODE);
1045 $sql =
"SELECT s.rowid";
1046 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as s, ".MAIN_DB_PREFIX.
"categorie_".$sub_type.
" as sub";
1047 $sql .=
' WHERE s.entity IN ('.getEntity(
'category').
')';
1048 $sql .=
' AND s.type='.((int) $idoftype);
1049 $sql .=
' AND s.rowid = sub.fk_categorie';
1050 $sql .=
" AND sub.".$subcol_name.
" = ".((int) $id);
1052 $sql .= $this->db->order($sortfield, $sortorder);
1055 $nbtotalofrecords =
'';
1057 $result = $this->db->query($sql);
1058 $nbtotalofrecords = $this->db->num_rows($result);
1059 if (($page * $limit) > $nbtotalofrecords) {
1069 $offset = $limit * $page;
1071 $sql .= $this->db->plimit($limit + 1, $offset);
1074 $result = $this->db->query($sql);
1077 $num = $this->db->num_rows($result);
1078 $min = min($num, ($limit <= 0 ? $num : $limit));
1080 $obj = $this->db->fetch_object($result);
1081 $category_static =
new Categorie($this->db);
1082 if ($category_static->fetch($obj->rowid)) {
1083 $categories[$i][
'id'] = $category_static->id;
1084 $categories[$i][
'fk_parent'] = $category_static->fk_parent;
1085 $categories[$i][
'label'] = $category_static->label;
1086 $categories[$i][
'description'] = $category_static->description;
1087 $categories[$i][
'color'] = $category_static->color;
1088 $categories[$i][
'position'] = $category_static->position;
1089 $categories[$i][
'socid'] = $category_static->socid;
1090 $categories[$i][
'ref_ext'] = $category_static->ref_ext;
1091 $categories[$i][
'visible'] = $category_static->visible;
1092 $categories[$i][
'type'] = $category_static->type;
1093 $categories[$i][
'entity'] = $category_static->entity;
1094 $categories[$i][
'array_options'] = $category_static->array_options;
1097 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && isset($category_static->multilangs)) {
1098 $categories[$i][
'multilangs'] = $category_static->multilangs;
1104 $this->error = $this->db->lasterror();
1107 if (!count($categories)) {
1123 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"categorie";
1124 $sql .=
" WHERE fk_parent = ".((int) $this->
id);
1125 $sql .=
" AND entity IN (".getEntity(
'category').
")";
1127 $res = $this->db->query($sql);
1130 while ($rec = $this->db->fetch_array($res)) {
1132 $cat->fetch($rec[
'rowid']);
1151 $this->motherof = array();
1154 $sql =
"SELECT fk_parent as id_parent, rowid as id_son";
1155 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
1156 $sql .=
" WHERE fk_parent != 0";
1157 $sql .=
" AND entity IN (".getEntity(
'category').
")";
1159 dol_syslog(get_class($this).
"::load_motherof", LOG_DEBUG);
1160 $resql = $this->db->query($sql);
1162 while ($obj = $this->db->fetch_object($resql)) {
1163 $this->motherof[$obj->id_son] = $obj->id_parent;
1197 if (!is_numeric($type)) {
1198 $type = $this->MAP_ID[$type];
1200 if (is_null($type)) {
1201 $this->error =
'BadValueForParameterType';
1205 if (is_string($fromid)) {
1206 $fromid = explode(
',', $fromid);
1207 } elseif (is_numeric($fromid)) {
1209 $fromid = array($fromid);
1213 } elseif (!is_array($fromid)) {
1217 $this->cats = array();
1222 $current_lang = $langs->getDefaultLang();
1225 $sql =
"SELECT DISTINCT c.rowid, c.label, c.ref_ext, c.description, c.color, c.position, c.fk_parent, c.visible";
1227 $sql .=
", t.label as label_trans, t.description as description_trans";
1229 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as c";
1231 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_lang as t ON t.fk_category=c.rowid AND t.lang='".$this->db->escape($current_lang).
"'";
1233 $sql .=
" WHERE c.entity IN (".getEntity(
'category').
")";
1234 $sql .=
" AND c.type = ".(int) $type;
1236 dol_syslog(get_class($this).
"::get_full_arbo get category list", LOG_DEBUG);
1237 $resql = $this->db->query($sql);
1240 $nbcateg = $this->db->num_rows($resql);
1242 while ($obj = $this->db->fetch_object($resql)) {
1243 $this->cats[$obj->rowid][
'rowid'] = $obj->rowid;
1244 $this->cats[$obj->rowid][
'id'] = $obj->rowid;
1245 $this->cats[$obj->rowid][
'fk_parent'] = $obj->fk_parent;
1246 $this->cats[$obj->rowid][
'label'] = !empty($obj->label_trans) ? $obj->label_trans : $obj->label;
1247 $this->cats[$obj->rowid][
'description'] = !empty($obj->description_trans) ? $obj->description_trans : $obj->description;
1248 $this->cats[$obj->rowid][
'color'] = $obj->color;
1249 $this->cats[$obj->rowid][
'position'] = $obj->position;
1250 $this->cats[$obj->rowid][
'visible'] = $obj->visible;
1251 $this->cats[$obj->rowid][
'ref_ext'] = $obj->ref_ext;
1252 $this->cats[$obj->rowid][
'picto'] =
'category';
1254 $this->cats[$obj->rowid][
'fullpath'] =
'';
1255 $this->cats[$obj->rowid][
'fulllabel'] =
'';
1264 dol_syslog(get_class($this).
"::get_full_arbo call to buildPathFromId", LOG_DEBUG);
1265 foreach ($this->cats as $key => $val) {
1271 if (count($fromid) > 0) {
1272 $keyfiltercatid =
'('.implode(
'|', $fromid).
')';
1275 $keyfilter1 =
'^'.$keyfiltercatid.
'$';
1276 $keyfilter2 =
'_'.$keyfiltercatid.
'$';
1277 $keyfilter3 =
'^'.$keyfiltercatid.
'_';
1278 $keyfilter4 =
'_'.$keyfiltercatid.
'_';
1279 foreach (array_keys($this->cats) as $key) {
1280 $fullpath = (string) $this->cats[$key][
'fullpath'];
1281 $test = (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
1282 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath));
1284 if (($test && !$include) || (!$test && $include)) {
1285 unset($this->cats[$key]);
1290 dol_syslog(get_class($this).
"::get_full_arbo dol_sort_array", LOG_DEBUG);
1292 $this->cats =
dol_sort_array($this->cats,
'fulllabel',
'asc', 1, 0, 1);
1311 if (!empty($this->cats[$id_categ][
'fullpath'])) {
1313 dol_syslog(get_class($this).
"::buildPathFromId fullpath and fulllabel already defined", LOG_WARNING);
1323 $this->cats[$id_categ][
'fullpath'] =
'_'.$id_categ;
1324 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$id_categ][
'label'];
1326 $cursor_categ = $id_categ;
1328 while ((empty($protection) || $i < $protection) && !empty($this->motherof[$cursor_categ])) {
1330 $this->cats[$id_categ][
'fullpath'] =
'_'.$this->motherof[$cursor_categ].$this->cats[$id_categ][
'fullpath'];
1331 $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'];
1334 $cursor_categ = $this->motherof[$cursor_categ];
1339 $nbunderscore = substr_count($this->cats[$id_categ][
'fullpath'],
'_');
1340 $this->cats[$id_categ][
'level'] = ($nbunderscore ? $nbunderscore :
null);
1357 if (!is_numeric($type) && !is_null($type)) {
1358 $type = $this->MAP_ID[$type];
1361 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"categorie";
1362 $sql .=
" WHERE entity IN (".getEntity(
'category').
")";
1363 if (!is_null($type)) {
1364 $sql .=
" AND type = ".(int) $type;
1367 $sql .=
" AND fk_parent = 0";
1370 $res = $this->db->query($sql);
1373 while ($rec = $this->db->fetch_array($res)) {
1375 $cat->fetch($rec[
'rowid']);
1376 $cats[$rec[
'rowid']] = $cat;
1407 $type = $this->type;
1409 if (!is_numeric($type)) {
1410 $type = $this->MAP_ID[$type];
1416 $sql =
"SELECT c.rowid";
1417 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as c ";
1418 $sql .=
" WHERE c.entity IN (".getEntity(
'category').
")";
1419 $sql .=
" AND c.type = ".((int) $type);
1420 $sql .=
" AND c.fk_parent = ".((int) $this->fk_parent);
1421 $sql .=
" AND c.label = '".$this->db->escape($this->label).
"'";
1423 dol_syslog(get_class($this).
"::already_exists", LOG_DEBUG);
1425 $resql = $this->db->query($sql);
1427 if ($this->db->num_rows($resql) > 0) {
1428 $obj = $this->db->fetch_object($resql);
1433 if (!empty($obj) && $obj->rowid > 0 && $obj->rowid != $this->id) {
1434 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);
1438 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);
1441 $this->error = $this->db->error();
1458 public function print_all_ways($sep =
'>>', $url =
'', $nocolor = 0, $addpicto = 0)
1464 foreach ($all_ways as $way) {
1468 foreach ($way as $cat) {
1471 if (empty($nocolor)) {
1472 $forced_color =
'colortoreplace';
1473 if ($i == count($way)) {
1475 $forced_color =
'categtextwhite';
1478 $forced_color =
'categtextblack';
1485 $link =
'<a href="'.DOL_URL_ROOT.
'/categories/viewcat.php?id='.$cat->id.
'&type='.$cat->type.
'" class="'.$forced_color.
'">';
1487 $w[] = $link.(($addpicto && $i == 1) ?
img_object(
'',
'category',
'class="paddingright"') :
'').$cat->label.$linkend;
1488 } elseif ($url ==
'none') {
1489 $link =
'<span class="'.$forced_color.
'">';
1490 $linkend =
'</span>';
1491 $w[] = $link.(($addpicto && $i == 1) ?
img_object(
'',
'category',
'class="paddingright"') :
'').$cat->label.$linkend;
1493 $w[] =
'<a class="'.$forced_color.
'" href="'.DOL_URL_ROOT.
'/'.$url.
'?catid='.$cat->id.
'">'.($addpicto ?
img_object(
'',
'category') :
'').$cat->label.
'</a>';
1496 $newcategwithpath = preg_replace(
'/colortoreplace/', $forced_color, implode(
'<span class="inline-block valignmiddle paddingleft paddingright '.$forced_color.
'">'.$sep.
'</span>', $w));
1498 $ways[] = $newcategwithpath;
1516 $sql =
"SELECT fk_parent FROM ".MAIN_DB_PREFIX.
"categorie";
1517 $sql .=
" WHERE rowid = ".((int) $this->
id);
1519 $res = $this->db->query($sql);
1522 while ($rec = $this->db->fetch_array($res)) {
1523 if ($rec[
'fk_parent'] > 0) {
1525 $cat->fetch($rec[
'fk_parent']);
1549 if (is_array($parents)) {
1550 foreach ($parents as $parent) {
1551 $all_ways = $parent->get_all_ways();
1552 foreach ($all_ways as $way) {
1560 if (count($ways) == 0) {
1561 $ways[0][0] = $this;
1581 if (is_numeric($type)) {
1582 $type = Categorie::$MAP_ID_TO_CODE[$type];
1585 if ($type === Categorie::TYPE_BANK_LINE) {
1587 $sql =
"SELECT c.label, c.rowid";
1588 $sql .=
" FROM ".MAIN_DB_PREFIX.
"category_bankline as a, ".MAIN_DB_PREFIX.
"categorie as c";
1589 $sql .=
" WHERE a.lineid=".((int) $id).
" AND a.fk_categ = c.rowid";
1590 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
1591 $sql .=
" ORDER BY c.label";
1593 $res = $this->db->query($sql);
1595 while ($obj = $this->db->fetch_object($res)) {
1596 if ($mode ==
'id') {
1597 $cats[] = $obj->rowid;
1598 } elseif ($mode ==
'label') {
1599 $cats[] = $obj->label;
1602 $cat->id = $obj->rowid;
1603 $cat->label = $obj->label;
1612 $sql =
"SELECT ct.fk_categorie, c.label, c.rowid";
1613 $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";
1614 $sql .=
" WHERE ct.fk_categorie = c.rowid AND ct.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = ".(
int) $id;
1618 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
1620 $res = $this->db->query($sql);
1622 while ($obj = $this->db->fetch_object($res)) {
1623 if ($mode ==
'id') {
1624 $cats[] = $obj->rowid;
1625 } elseif ($mode ==
'label') {
1626 $cats[] = $obj->label;
1629 $cat->fetch($obj->fk_categorie);
1653 public function rechercher($id, $nom, $type, $exact =
false, $case =
false)
1656 if (is_numeric($type)) {
1657 dol_syslog(__METHOD__.
': using numeric types is deprecated.', LOG_WARNING);
1663 if (is_numeric($type)) {
1665 $map_type = array_flip($this->MAP_ID);
1666 $type = $map_type[$type];
1667 dol_syslog(get_class($this).
"::rechercher(): numeric types are deprecated, please use string instead", LOG_WARNING);
1671 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"categorie";
1672 $sql .=
" WHERE type = ".((int) $this->MAP_ID[$type]);
1673 $sql .=
" AND entity IN (".getEntity(
'category').
")";
1676 $nom =
'%'.$this->db->escape(str_replace(
'*',
'%', $nom)).
'%';
1679 $sql .=
" AND label LIKE '".$this->db->escape($nom).
"'";
1681 $sql .=
" AND label LIKE BINARY '".$this->db->escape($nom).
"'";
1685 $sql .=
" AND rowid = ".((int) $id);
1688 $res = $this->db->query($sql);
1690 while ($rec = $this->db->fetch_array($res)) {
1692 $cat->fetch($rec[
'rowid']);
1698 $this->error = $this->db->error().
' sql='.$sql;
1711 include_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
1712 include_once DOL_DOCUMENT_ROOT .
'/core/lib/images.lib.php';
1714 $sdir .=
'/' .
get_exdir($this->
id, 2, 0, 0, $this,
'category') . $this->
id .
"/photos/";
1717 if (file_exists($dir_osencoded)) {
1718 $handle = opendir($dir_osencoded);
1719 if (is_resource($handle)) {
1720 while (($file = readdir($handle)) !==
false) {
1722 $file = mb_convert_encoding($file,
'UTF-8',
'ISO-8859-1');
1743 $langs->load(
'categories');
1747 $datas[
'label'] = $langs->trans(
"ShowCategory").
': '.($this->
ref ? $this->
ref : $this->label);
1765 public function getNomUrl($withpicto = 0, $option =
'', $maxlength = 0, $moreparam =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = 0)
1767 global
$conf, $langs, $hookmanager;
1769 if (!empty(
$conf->dol_no_mouse_hover)) {
1776 'objecttype' => $this->element,
1777 'option' => $option,
1779 $classfortooltip =
'classfortooltip';
1782 $classfortooltip =
'classforajaxtooltip';
1783 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1789 $url = DOL_URL_ROOT.
'/categories/viewcat.php?id='.$this->
id.
'&type='.$this->
type.$moreparam.
'&backtopage='.urlencode($_SERVER[
'PHP_SELF'].($moreparam ?
'?'.$moreparam :
''));
1791 if ($option !==
'nolink') {
1793 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1794 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1795 $add_save_lastsearch_values = 1;
1797 if ($url && $add_save_lastsearch_values) {
1798 $url .=
'&save_lastsearch_values=1';
1803 $forced_color =
'categtextwhite';
1806 $forced_color =
'categtextblack';
1811 if (empty($notooltip)) {
1813 $label = $langs->trans(
"ShowMyObject");
1814 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1816 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1817 $linkclose .= $dataparams.
' class="'.$classfortooltip.
' '.$forced_color.($morecss ?
' '.$morecss :
'').
'"';
1819 $linkclose =
' class="'.$forced_color.($morecss ?
' '.$morecss :
'').
'"';
1822 if ($option ==
'nolink' || empty($url)) {
1823 $linkstart =
'<span';
1825 $linkstart =
'<a href="'.$url.
'"';
1827 $linkstart .= $linkclose.
'>';
1828 if ($option ==
'nolink' || empty($url)) {
1829 $linkend =
'</span>';
1834 $result .= $linkstart;
1837 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1840 if ($withpicto != 2) {
1841 $result .=
dol_trunc(($this->
ref ? $this->
ref : $this->label), $maxlength);
1844 $result .= $linkend;
1847 $hookmanager->initHooks(array($this->element .
'dao'));
1848 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1849 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1851 $result = $hookmanager->resPrint;
1853 $result .= $hookmanager->resPrint;
1870 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1872 $dir = $sdir.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'category').$this->id.
"/";
1875 if (!file_exists($dir)) {
1879 if (file_exists($dir)) {
1880 if (is_array($file[
'name'])) {
1881 $nbfile = count($file[
'name']);
1882 for ($i = 0; $i < $nbfile; $i++) {
1883 $originImage = $dir.$file[
'name'][$i];
1888 if (file_exists($originImage)) {
1894 $originImage = $dir.$file[
'name'];
1899 if (file_exists($originImage)) {
1918 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1923 $dirthumb = $dir.
'thumbs/';
1925 if (file_exists($dir)) {
1926 $handle = opendir($dir);
1927 if (is_resource($handle)) {
1928 while (($file = readdir($handle)) !==
false) {
1929 if (
dol_is_file($dir.$file) && preg_match(
'/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $dir.$file)) {
1934 $photo_vignette =
'';
1936 if (preg_match(
'/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $photo, $regs)) {
1937 $photo_vignette = preg_replace(
'/'.$regs[0].
'/i',
'', $photo).
'_small'.$regs[0];
1942 $obj[
'photo'] = $photo;
1943 if ($photo_vignette && is_file($dirthumb.$photo_vignette)) {
1944 $obj[
'photo_vignette'] =
'thumbs/'.$photo_vignette;
1946 $obj[
'photo_vignette'] =
"";
1949 $tabobj[$nbphoto - 1] = $obj;
1952 if ($nbmax && $nbphoto >= $nbmax) {
1975 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1977 $dir = dirname($file).
'/';
1978 $dirthumb = $dir.
'/thumbs/';
1979 $filename = preg_replace(
'/'.preg_quote($dir,
'/').
'/i',
'', $file);
1986 if (preg_match(
'/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $filename, $regs)) {
1987 $photo_vignette = preg_replace(
'/'.$regs[0].
'/i',
'', $filename).
'_small'.$regs[0];
1988 if (file_exists($dirthumb.$photo_vignette)) {
2004 $infoImg = getimagesize($file);
2005 $this->imgWidth = $infoImg[0];
2006 $this->imgHeight = $infoImg[1];
2021 $langs_available = $langs->get_available_languages();
2022 $current_lang = $langs->getDefaultLang();
2024 foreach ($langs_available as $key => $value) {
2025 $sql =
"SELECT rowid";
2026 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_lang";
2027 $sql .=
" WHERE fk_category=".((int) $this->
id);
2028 $sql .=
" AND lang = '".$this->db->escape($key).
"'";
2030 $result = $this->db->query($sql);
2032 if ($key == $current_lang) {
2034 if ($this->db->num_rows($result)) {
2035 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"categorie_lang";
2036 $sql2 .=
" SET label = '".$this->db->escape($this->label).
"',";
2037 $sql2 .=
" description = '".$this->db->escape($this->
description).
"'";
2038 $sql2 .=
" WHERE fk_category = ".((int) $this->
id).
" AND lang = '".$this->db->escape($key).
"'";
2039 } elseif (isset($this->multilangs[$key])) {
2040 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_lang (fk_category, lang, label, description)";
2041 $sql2 .=
" VALUES(".((int) $this->
id).
", '".$this->db->escape($key).
"', '".$this->db->escape($this->label).
"'";
2042 $sql2 .=
", '".$this->db->escape($this->multilangs[$key][
"description"]).
"')";
2044 dol_syslog(get_class($this).
'::setMultiLangs', LOG_DEBUG);
2045 if ($sql2 && !$this->db->query($sql2)) {
2046 $this->error = $this->db->lasterror();
2049 } elseif (isset($this->multilangs[$key])) {
2050 if ($this->db->num_rows($result)) {
2051 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"categorie_lang";
2052 $sql2 .=
" SET label='".$this->db->escape($this->multilangs[$key][
"label"]).
"',";
2053 $sql2 .=
" description='".$this->db->escape($this->multilangs[$key][
"description"]).
"'";
2054 $sql2 .=
" WHERE fk_category=".((int) $this->
id).
" AND lang='".$this->db->escape($key).
"'";
2056 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_lang (fk_category, lang, label, description)";
2057 $sql2 .=
" VALUES(".((int) $this->
id).
", '".$this->db->escape($key).
"', '".$this->db->escape($this->multilangs[$key][
"label"]).
"'";
2058 $sql2 .=
",'".$this->db->escape($this->multilangs[$key][
"description"]).
"')";
2062 if ($this->multilangs[$key][
"label"] || $this->multilangs[$key][
"description"] || $this->multilangs[$key][
"note"]) {
2063 dol_syslog(get_class($this).
'::setMultiLangs', LOG_DEBUG);
2065 if (!$this->db->query($sql2)) {
2066 $this->error = $this->db->lasterror();
2074 $result = $this->
call_trigger(
'CATEGORY_SET_MULTILANGS', $user);
2076 $this->error = $this->db->lasterror();
2095 $sql =
"DELETE FROM ".$this->db->prefix().
"categorie_lang";
2096 $sql .=
" WHERE fk_category = ".((int) $this->
id).
" AND lang = '".$this->db->escape($langtodelete).
"'";
2098 dol_syslog(get_class($this).
'::delMultiLangs', LOG_DEBUG);
2099 $result = $this->db->query($sql);
2102 $result = $this->
call_trigger(
'CATEGORY_DEL_MULTILANGS', $user);
2104 $this->error = $this->db->lasterror();
2105 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
2111 $this->error = $this->db->lasterror();
2112 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
2126 $current_lang = $langs->getDefaultLang();
2128 $sql =
"SELECT lang, label, description";
2129 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_lang";
2130 $sql .=
" WHERE fk_category=".((int) $this->
id);
2132 $result = $this->db->query($sql);
2134 while ($obj = $this->db->fetch_object($result)) {
2136 if ($obj->lang == $current_lang) {
2137 $this->label = $obj->label;
2140 $this->multilangs[$obj->lang][
"label"] = $obj->label;
2141 $this->multilangs[$obj->lang][
"description"] = $obj->description;
2145 $this->error = $langs->trans(
"Error").
" : ".$this->db->error().
" - ".$sql;
2171 dol_syslog(get_class($this).
"::initAsSpecimen");
2175 $this->fk_parent = 0;
2176 $this->label =
'SPECIMEN';
2177 $this->specimen = 1;
2180 $this->
type = self::TYPE_PRODUCT;
2212 if ($type ==
'bank_account') {
2216 return " LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_".$type.
" as cp ON ".$rowIdName.
" = cp.fk_".$type;
2230 if ($type ==
'bank_account') {
2233 if ($type ==
'customer') {
2236 if ($type ==
'supplier') {
2237 $type =
'fournisseur';
2240 if (empty($searchList) && !is_array($searchList)) {
2244 $searchCategorySqlList = array();
2245 foreach ($searchList as $searchCategory) {
2246 if (intval($searchCategory) == -2) {
2247 $searchCategorySqlList[] =
" cp.fk_categorie IS NULL";
2248 } elseif (intval($searchCategory) > 0) {
2249 $searchCategorySqlList[] =
" ".$rowIdName.
" IN (SELECT fk_".$type.
" FROM ".MAIN_DB_PREFIX.
"categorie_".$type.
" WHERE fk_categorie = ".((int) $searchCategory).
")";
2253 if (!empty($searchCategorySqlList)) {
2254 return " AND (".implode(
' AND ', $searchCategorySqlList).
")";
2267 dol_syslog(get_class($this).
"::count_all_categories", LOG_DEBUG);
2268 $sql =
"SELECT COUNT(rowid) FROM ".MAIN_DB_PREFIX.
"categorie";
2269 $sql .=
" WHERE entity IN (".getEntity(
'category').
")";
2271 $res = $this->db->query($sql);
2273 $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.
delMultiLangs($langtodelete, $user)
Delete a language for this 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.
getObjectsInCateg($type, $onlyids=0, $limit=0, $offset=0, $sortfield='', $sortorder='ASC', $filter='', $filtermode='AND', $filterlang='')
Return list of fetched instance of elements having this category.
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)
Create or Update translations of categories labels.
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 a 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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type