39require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/ticket/class/ticket.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/knowledgemanagement/class/knowledgerecord.class.php';
53 const TYPE_PRODUCT =
'product';
54 const TYPE_SUPPLIER =
'supplier';
55 const TYPE_CUSTOMER =
'customer';
56 const TYPE_MEMBER =
'member';
57 const TYPE_CONTACT =
'contact';
58 const TYPE_USER =
'user';
59 const TYPE_PROJECT =
'project';
60 const TYPE_ACCOUNT =
'bank_account';
61 const TYPE_BANK_LINE =
'bank_line';
62 const TYPE_WAREHOUSE =
'warehouse';
63 const TYPE_ACTIONCOMM =
'actioncomm';
64 const TYPE_WEBSITE_PAGE =
'website_page';
65 const TYPE_TICKET =
'ticket';
66 const TYPE_KNOWLEDGEMANAGEMENT =
'knowledgemanagement';
67 const TYPE_FICHINTER =
'fichinter';
68 const TYPE_ORDER =
'order';
69 const TYPE_INVOICE =
'invoice';
70 const TYPE_SUPPLIER_ORDER =
'supplier_order';
71 const TYPE_SUPPLIER_INVOICE =
'supplier_invoice';
77 public $picto =
'category';
83 public $MAP_ID = array(
98 'knowledgemanagement' => 13,
102 'supplier_order' => 20,
103 'supplier_invoice' => 21
111 public static $MAP_ID_TO_CODE = array(
123 11 =>
'website_page',
125 13 =>
'knowledgemanagement',
129 20 =>
'supplier_order',
130 21 =>
'supplier_invoice'
138 public $MAP_CAT_FK = array(
141 'contact' =>
'socpeople',
142 'bank_account' =>
'account',
150 public $MAP_CAT_TABLE = array(
151 'customer' =>
'societe',
152 'supplier' =>
'fournisseur',
153 'bank_account' =>
'account',
161 public $MAP_OBJ_CLASS = array(
162 'product' =>
'Product',
163 'service' =>
'Product',
164 'customer' =>
'Societe',
165 'supplier' =>
'Fournisseur',
166 'member' =>
'Adherent',
167 'contact' =>
'Contact',
169 'account' =>
'Account',
170 'bank_account' =>
'Account',
171 'project' =>
'Project',
172 'warehouse' =>
'Entrepot',
173 'actioncomm' =>
'ActionComm',
174 'website_page' =>
'WebsitePage',
175 'ticket' =>
'Ticket',
176 'knowledgemanagement' =>
'KnowledgeRecord',
177 'fichinter' =>
'Fichinter',
178 'order' =>
'Commande',
179 'invoice' =>
'Facture',
180 'supplier_order' =>
'CommandeFournisseur',
181 'supplier_invoice' =>
'FactureFournisseur'
189 public static $MAP_TYPE_TITLE_AREA = array(
190 'product' =>
'Products',
191 'service' =>
'Services',
192 'customer' =>
'ProspectsOrCustomers',
193 'supplier' =>
'Suppliers',
194 'member' =>
'Members',
195 'contact' =>
'Contacts',
197 'account' =>
'Accounts',
198 'bank_account' =>
'BankAccounts',
199 'bank_line' =>
'BankTransactions',
200 'project' =>
'Projects',
201 'warehouse' =>
'Warehouse',
202 'actioncomm' =>
'AgendaEvents',
203 'website_page' =>
'WebsitePages',
204 'ticket' =>
'Tickets',
205 'knowledgemanagement' =>
'KnowledgeRecords',
206 'fichinter' =>
'Interventions',
208 'invoice' =>
'Invoices',
209 'supplier_order' =>
'SuppliersOrders',
210 'supplier_invoice' =>
'SuppliersInvoices'
217 public $MAP_OBJ_TABLE = array(
218 'customer' =>
'societe',
219 'supplier' =>
'societe',
220 'member' =>
'adherent',
221 'contact' =>
'socpeople',
222 'account' =>
'bank_account',
223 'project' =>
'projet',
224 'warehouse' =>
'entrepot',
225 'knowledgemanagement' =>
'knowledgemanagement_knowledgerecord',
226 'fichinter' =>
'fichinter',
227 'order' =>
'commande',
228 'invoice' =>
'facture',
229 'supplier_order' =>
'commande_fournisseur',
230 'supplier_invoice' =>
'facture_fourn'
236 public $element =
'category';
241 public $table_element =
'categorie';
305 public $cats = array();
310 public $motherof = array();
315 public $childs = array();
320 public $multilangs = array();
357 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'position' => 10,
'notnull' => 1,
'visible' => 0,),
358 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => 0,
'default' =>
'1',
'notnull' => 1,
'index' => 1,
'position' => 5),
359 'fk_parent' => array(
'type' =>
'integer',
'label' =>
'ParentCategory',
'enabled' => 1,
'position' => 20,
'notnull' => 1,
'visible' => 0,
'css' =>
'maxwidth500 widthcentpercentminusxx',),
360 'label' => array(
'type' =>
'varchar(180)',
'label' =>
'Ref',
'enabled' => 1,
'position' => 25,
'notnull' => 1,
'visible' => 1,
'alwayseditable' => 1,
'css' =>
'minwidth300',
'cssview' =>
'wordbreak',
'csslist' =>
'tdoverflowmax150',
'showoncombobox' => 1),
361 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'position' => 30,
'notnull' => 0,
'visible' => 0,
'alwayseditable' => 1,),
362 'type' => array(
'type' =>
'integer',
'label' =>
'Type',
'enabled' => 1,
'position' => 35,
'notnull' => 1,
'visible' => 0,
'alwayseditable' => 1,),
363 'description' => array(
'type' =>
'text',
'label' =>
'Description',
'enabled' => 1,
'position' => 40,
'notnull' => 0,
'visible' => 1,
'alwayseditable' => 1,),
364 'color' => array(
'type' =>
'varchar(8)',
'label' =>
'Color',
'enabled' => 1,
'position' => 45,
'notnull' => 0,
'visible' => 1,
'alwayseditable' => 1,),
365 'position' => array(
'type' =>
'integer',
'label' =>
'Position',
'enabled' => 1,
'position' => 50,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
366 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'picto' =>
'company',
'enabled' => 1,
'position' => 55,
'notnull' => 0,
'visible' => 0,
'alwayseditable' => 1,
'css' =>
'maxwidth500 widthcentpercentminusxx',
'csslist' =>
'tdoverflowmax150',),
367 'visible' => array(
'type' =>
'integer',
'label' =>
'Visible',
'enabled' => 1,
'position' => 60,
'notnull' => 1,
'visible' => 0,
'alwayseditable' => 1,),
368 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'position' => 900,
'notnull' => 0,
'visible' => -2,
'alwayseditable' => 1,),
369 'date_creation' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'position' => 70,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
370 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'position' => 75,
'notnull' => 1,
'visible' => -1,
'alwayseditable' => 1,),
371 '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',),
372 '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',),
386 $this->ismultientitymanaged = 1;
387 $this->isextrafieldmanaged = 1;
389 if (is_object($hookmanager)) {
390 $hookmanager->initHooks(array(
'category'));
391 $parameters = array();
392 $reshook = $hookmanager->executeHooks(
'constructCategory', $parameters, $this);
393 if ($reshook >= 0 && !empty($hookmanager->resArray)) {
394 foreach ($hookmanager->resArray as $mapList) {
395 $mapId = $mapList[
'id'];
396 $mapCode = $mapList[
'code'];
397 self::$MAP_ID_TO_CODE[$mapId] = $mapCode;
398 $this->MAP_ID[$mapCode] = $mapId;
399 $this->MAP_CAT_FK[$mapCode] = isset($mapList[
'cat_fk']) ? $mapList[
'cat_fk'] :
null;
400 $this->MAP_CAT_TABLE[$mapCode] = isset($mapList[
'cat_table']) ? $mapList[
'cat_table'] :
null;
401 $this->MAP_OBJ_CLASS[$mapCode] = $mapList[
'obj_class'];
402 $this->MAP_OBJ_TABLE[$mapCode] = $mapList[
'obj_table'];
417 foreach ($this->MAP_ID as $mapCode => $mapId) {
421 'cat_fk' => (empty($this->MAP_CAT_FK[$mapCode]) ? $mapCode : $this->MAP_CAT_FK[$mapCode]),
422 'cat_table' => (empty($this->MAP_CAT_TABLE[$mapCode]) ? $mapCode : $this->MAP_CAT_TABLE[$mapCode]),
423 'obj_class' => (empty($this->MAP_OBJ_CLASS[$mapCode]) ? $mapCode : $this->MAP_OBJ_CLASS[$mapCode]),
424 'obj_table' => (empty($this->MAP_OBJ_TABLE[$mapCode]) ? $mapCode : $this->MAP_OBJ_TABLE[$mapCode])
438 return $this->MAP_ID;
450 public function fetch($id, $label =
'', $type =
null, $ref_ext =
'')
453 if (empty($id) && empty($label) && empty($ref_ext)) {
454 $this->error =
"No category to search for";
457 if (!is_null($type) && !is_numeric($type)) {
458 $type = $this->MAP_ID[$type];
461 $sql =
"SELECT rowid, fk_parent, entity, label, description, color, position, fk_soc, visible, type, ref_ext";
462 $sql .=
", date_creation, tms, fk_user_creat, fk_user_modif";
463 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
465 $sql .=
" WHERE rowid = ".((int) $id);
466 } elseif (!empty($ref_ext)) {
467 $sql .=
" WHERE ref_ext LIKE '".$this->db->escape($ref_ext).
"'";
469 $sql .=
" WHERE label = '".$this->db->escape($label).
"' AND entity IN (".
getEntity(
'category').
")";
470 if (!is_null($type)) {
471 $sql .=
" AND type = ".((int) $type);
475 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
476 $resql = $this->db->query($sql);
478 if ($this->db->num_rows($resql) > 0 && $res = $this->db->fetch_array($resql)) {
479 $this->
id = $res[
'rowid'];
481 $this->fk_parent = (int) $res[
'fk_parent'];
482 $this->label = $res[
'label'];
484 $this->color = $res[
'color'];
486 $this->socid = (int) $res[
'fk_soc'];
487 $this->visible = (int) $res[
'visible'];
488 $this->
type = $res[
'type'];
489 $this->ref_ext = $res[
'ref_ext'];
490 $this->entity = (int) $res[
'entity'];
491 $this->date_creation = $this->db->jdate($res[
'date_creation']);
492 $this->date_modification = $this->db->jdate($res[
'tms']);
493 $this->user_creation_id = (int) $res[
'fk_user_creat'];
494 $this->user_modification_id = (int) $res[
'fk_user_modif'];
500 $this->db->free($resql);
509 $this->error =
"No category found";
514 $this->error = $this->db->lasterror;
515 $this->errors[] = $this->db->lasterror;
530 public function create($user, $notrigger = 0)
532 global
$conf, $langs;
533 $langs->load(
'categories');
537 if (!is_numeric($type)) {
538 $type = $this->MAP_ID[$type];
543 dol_syslog(get_class($this).
'::create', LOG_DEBUG);
546 $this->label = trim($this->label);
548 $this->color = trim($this->color);
550 if (isset($this->import_key)) {
551 $this->import_key = trim($this->import_key);
553 $this->ref_ext = trim($this->ref_ext);
554 if (empty($this->visible)) {
557 $this->fk_parent = ($this->fk_parent !=
"" ? intval($this->fk_parent) : 0);
560 $this->error = $langs->trans(
"ImpossibleAddCat", $this->label);
561 $this->error .=
" : ".$langs->trans(
"CategoryExistsAtSameLevel");
568 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie (";
569 $sql .=
"fk_parent,";
571 $sql .=
" description,";
573 $sql .=
" position,";
579 $sql .=
" import_key,";
582 $sql .=
" date_creation,";
583 $sql .=
" fk_user_creat";
584 $sql .=
") VALUES (";
585 $sql .= (int) $this->fk_parent.
",";
586 $sql .=
"'".$this->db->escape($this->label).
"', ";
587 $sql .=
"'".$this->db->escape($this->
description).
"', ";
588 $sql .=
"'".$this->db->escape($this->color).
"', ";
591 $sql .= ($this->socid > 0 ? $this->socid :
'null').
", ";
593 $sql .=
"'".$this->db->escape((
string) $this->visible).
"', ";
594 $sql .= ((int) $type).
", ";
595 $sql .= (!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
'null').
", ";
596 $sql .= (!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
'null').
", ";
597 $sql .= (int)
$conf->entity.
", ";
598 $sql .=
"'".$this->db->idate($now).
"', ";
599 $sql .= (int) $user->id;
602 $res = $this->db->query($sql);
604 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"categorie");
617 if (!$error && !$notrigger) {
619 $result = $this->
call_trigger(
'CATEGORY_CREATE', $user);
630 $this->db->rollback();
634 $this->db->rollback();
638 $this->error = $this->db->error();
639 $this->db->rollback();
660 $this->label = trim($this->label);
662 $this->ref_ext = trim($this->ref_ext);
663 $this->fk_parent = ($this->fk_parent !=
"" ? intval($this->fk_parent) : 0);
664 $this->visible = ($this->visible !=
"" ? intval($this->visible) : 0);
667 $this->error = $langs->trans(
"ImpossibleUpdateCat");
668 $this->error .=
" : ".$langs->trans(
"CategoryExistsAtSameLevel");
674 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"categorie";
675 $sql .=
" SET label = '".$this->db->escape($this->label).
"',";
676 $sql .=
" description = '".$this->db->escape($this->
description).
"',";
677 $sql .=
" ref_ext = '".$this->db->escape($this->ref_ext).
"',";
678 $sql .=
" color = '".$this->db->escape($this->color).
"'";
679 $sql .=
", position = ".(int) $this->
position;
681 $sql .=
", fk_soc = ".($this->socid > 0 ? $this->socid :
'null');
683 $sql .=
", visible = ".(int) $this->visible;
684 $sql .=
", fk_parent = ".(int) $this->fk_parent;
685 $sql .=
", fk_user_modif = ".(int) $user->id;
686 $sql .=
" WHERE rowid = ".((int) $this->
id);
688 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
689 if ($this->db->query($sql)) {
698 if (!$error && !$notrigger) {
700 $result = $this->
call_trigger(
'CATEGORY_MODIFY', $user);
711 $this->db->rollback();
715 $this->db->rollback();
728 public function delete($user, $notrigger = 0)
733 $this->fk_parent = ($this->fk_parent !=
"" ? intval($this->fk_parent) : 0);
741 $result = $this->
call_trigger(
'CATEGORY_DELETE', $user);
750 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"categorie";
751 $sql .=
" SET fk_parent = ".((int) $this->fk_parent);
752 $sql .=
" WHERE fk_parent = ".((int) $this->
id);
754 if (!$this->db->query($sql)) {
755 $this->error = $this->db->lasterror();
760 $arraydelete = array(
761 'categorie_account' =>
'fk_categorie',
762 'categorie_actioncomm' =>
'fk_categorie',
763 'categorie_contact' =>
'fk_categorie',
764 'categorie_fournisseur' =>
'fk_categorie',
765 'categorie_knowledgemanagement' => array(
'field' =>
'fk_categorie',
'enabled' => isModEnabled(
'knowledgemanagement')),
766 'categorie_fichinter' => array(
'field' =>
'fk_categorie',
'enabled' =>
false ),
767 'categorie_member' =>
'fk_categorie',
768 'categorie_user' =>
'fk_categorie',
769 'categorie_product' =>
'fk_categorie',
770 'categorie_project' =>
'fk_categorie',
771 'categorie_societe' =>
'fk_categorie',
772 'categorie_ticket' => array(
'field' =>
'fk_categorie',
'enabled' => isModEnabled(
'ticket')),
773 'categorie_warehouse' =>
'fk_categorie',
774 'categorie_website_page' => array(
'field' =>
'fk_categorie',
'enabled' => isModEnabled(
'website')),
775 'category_bankline' =>
'fk_categ',
776 'categorie_lang' =>
'fk_category',
777 'categorie' =>
'rowid',
779 foreach ($arraydelete as $key => $value) {
780 if (is_array($value)) {
781 if (empty($value[
'enabled'])) {
784 $value = $value[
'field'];
786 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$key;
787 $sql .=
" WHERE ".$value.
" = ".((int) $this->
id);
788 if (!$this->db->query($sql)) {
789 $this->errors[] = $this->db->lasterror();
790 dol_syslog(
"Error sql=".$sql.
" ".$this->error, LOG_ERR);
800 dol_syslog(get_class($this).
"::delete erreur ".$this->error, LOG_ERR);
808 $this->db->rollback();
829 if ($this->
id == -1) {
834 $type = $obj->element;
837 dol_syslog(get_class($this).
'::add_type', LOG_DEBUG);
841 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
842 $sql .=
" (fk_categorie, fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
")";
843 $sql .=
" VALUES (".((int) $this->
id).
", ".((int) $obj->id).
")";
845 if ($this->db->query($sql)) {
847 $sql =
'SELECT fk_parent FROM '.MAIN_DB_PREFIX.
'categorie';
848 $sql .=
" WHERE rowid = ".((int) $this->
id);
850 dol_syslog(get_class($this).
"::add_type", LOG_DEBUG);
851 $resql = $this->db->query($sql);
853 if ($this->db->num_rows($resql) > 0) {
854 $objparent = $this->db->fetch_object($resql);
856 if (!empty($objparent->fk_parent)) {
858 $cat->id = $objparent->fk_parent;
859 if (!$cat->containsObject($type, $obj->id)) {
860 $result = $cat->add_type($obj, $type);
862 $this->error = $cat->error;
870 $this->error = $this->db->lasterror();
874 $this->db->rollback();
880 $this->context = array(
'linkto' => $obj);
881 $result = $this->
call_trigger(
'CATEGORY_MODIFY', $user);
891 $this->db->rollback();
895 $this->db->rollback();
896 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
897 $this->error = $this->db->lasterrno();
900 $this->error = $this->db->lasterror();
923 if ($type ==
'societe') {
925 dol_syslog(get_class($this).
"::del_type(): type 'societe' is deprecated, please use 'customer' instead", LOG_WARNING);
926 } elseif ($type ==
'fournisseur') {
928 dol_syslog(get_class($this).
"::del_type(): type 'fournisseur' is deprecated, please use 'supplier' instead", LOG_WARNING);
933 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
934 $sql .=
" WHERE fk_categorie = ".((int) $this->
id);
935 $sql .=
" AND fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = ".((
int) $obj->id);
937 dol_syslog(get_class($this).
'::del_type', LOG_DEBUG);
938 if ($this->db->query($sql)) {
940 $this->context = array(
'unlinkoff' => $obj);
941 $result = $this->
call_trigger(
'CATEGORY_MODIFY', $user);
951 $this->db->rollback();
955 $this->db->rollback();
956 $this->error = $this->db->lasterror();
979 public function getObjectsInCateg($type, $onlyids = 0, $limit = 0, $offset = 0, $sortfield =
'', $sortorder =
'ASC', $filter =
'', $filtermode =
'AND', $filterlang =
'')
983 if (empty($onlyids)) {
984 dol_syslog(
"getObjectsInCateg: This method used with parameter onlyids=0 is deprecated. Try by using instead getListForItem().", LOG_WARNING);
989 $classnameforobj = $this->MAP_OBJ_CLASS[$type];
990 if (!empty($classnameforobj) && class_exists($classnameforobj)) {
991 $tmpobj =
new $classnameforobj($this->db);
994 $sql =
"SELECT c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" as fk_object";
995 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]).
" as c";
996 $sql .=
", ".MAIN_DB_PREFIX.(empty($this->MAP_OBJ_TABLE[$type]) ? $type : $this->MAP_OBJ_TABLE[$type]).
" as o";
997 if (!empty($filterlang)) {
998 $sql .=
", ".MAIN_DB_PREFIX.(empty($this->MAP_OBJ_TABLE[$type]) ? $type : $this->MAP_OBJ_TABLE[$type]).
"_lang as ol";
1000 $sql .=
" WHERE o.entity IN (".getEntity($tmpobj->element).
")";
1001 $sql .=
" AND c.fk_categorie = ".((int) $this->
id);
1003 if ((array_key_exists($type, $this->MAP_OBJ_TABLE) && $this->MAP_OBJ_TABLE[$type] ==
"actioncomm") || $type ==
"actioncomm") {
1004 $sql .=
" AND c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = o.id";
1006 $sql .=
" AND c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = o.rowid";
1008 if (!empty($filterlang)) {
1009 $sql .=
" AND ol.fk_".(empty($this->MAP_OBJ_TABLE[$type]) ? $type : $this->MAP_OBJ_TABLE[$type]).
" = o.rowid";
1010 $sql .=
" AND ol.lang = '".$this->db->escape($filterlang).
"'";
1013 if (($type ==
'customer' || $type ==
'supplier') && $user->socid > 0) {
1014 $sql .=
" AND o.rowid = ".((int) $user->socid);
1019 if ($errormessage) {
1020 $this->errors[] = $errormessage;
1021 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1025 $sql .= $this->db->order($sortfield, $sortorder);
1026 if ($limit > 0 || $offset > 0) {
1027 $sql .= $this->db->plimit($limit + 1, $offset);
1030 dol_syslog(get_class($this).
"::getObjectsInCateg", LOG_DEBUG);
1032 $resql = $this->db->query($sql);
1034 while ($rec = $this->db->fetch_array($resql)) {
1036 $objs[] = $rec[
'fk_object'];
1039 $tmpobj->fetch($rec[
'fk_object']);
1041 if ($tmpobj->id > 0) {
1042 $objs[] = clone $tmpobj;
1047 $this->error = $this->db->error().
' sql='.$sql;
1065 $sql =
"SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
1066 $sql .=
" WHERE fk_categorie = ".((int) $this->
id).
" AND fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = ".((
int) $object_id);
1068 dol_syslog(get_class($this).
"::containsObject", LOG_DEBUG);
1070 $resql = $this->db->query($sql);
1072 return $this->db->fetch_object($resql)->nb;
1074 $this->error = $this->db->error();
1091 public function getListForItem($id, $type =
'customer', $sortfield =
"s.rowid", $sortorder =
'ASC', $limit = 0, $page = 0)
1093 $categories = array();
1098 $subcol_name =
"fk_".$type;
1099 if ($type ==
"customer") {
1100 $sub_type =
"societe";
1101 $subcol_name =
"fk_soc";
1103 if ($type ==
"supplier") {
1104 $sub_type =
"fournisseur";
1105 $subcol_name =
"fk_soc";
1107 if ($type ==
"contact") {
1108 $subcol_name =
"fk_socpeople";
1111 $idoftype = (int) (array_key_exists($type, $this->MAP_ID) ? $this->MAP_ID[$type] : -1);
1113 $sql =
"SELECT s.rowid";
1115 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as s, ".MAIN_DB_PREFIX.
"categorie_".$this->db->sanitize($sub_type).
" as sub";
1116 $sql .=
' WHERE s.entity IN ('.getEntity(
'category').
')';
1117 $sql .=
' AND s.type = '.((int) $idoftype);
1118 $sql .=
' AND s.rowid = sub.fk_categorie';
1119 $sql .=
" AND sub.".$this->db->sanitize($subcol_name).
" = ".((int) $id);
1122 $nbtotalofrecords =
'';
1124 $sqlforcount = preg_replace(
'/^'.preg_quote($sqlfields,
'/').
'/',
'SELECT COUNT(*) as nbtotalofrecords', $sql);
1125 $sqlforcount = preg_replace(
'/GROUP BY .*$/',
'', $sqlforcount);
1127 $resql = $this->db->query($sqlforcount);
1129 $objforcount = $this->db->fetch_object($resql);
1130 $nbtotalofrecords = $objforcount->nbtotalofrecords;
1135 if (($page * $limit) > $nbtotalofrecords) {
1139 $this->db->free($resql);
1142 $sql .= $this->db->order($sortfield, $sortorder);
1147 $offset = $limit * $page;
1149 $sql .= $this->db->plimit($limit + 1, $offset);
1152 $result = $this->db->query($sql);
1155 $num = $this->db->num_rows($result);
1156 $min = min($num, ($limit <= 0 ? $num : $limit));
1158 $obj = $this->db->fetch_object($result);
1159 $category_static =
new Categorie($this->db);
1160 if ($category_static->fetch($obj->rowid)) {
1161 $categories[$i][
'id'] = $category_static->id;
1162 $categories[$i][
'fk_parent'] = $category_static->fk_parent;
1163 $categories[$i][
'label'] = $category_static->label;
1164 $categories[$i][
'description'] = $category_static->description;
1165 $categories[$i][
'color'] = $category_static->color;
1166 $categories[$i][
'position'] = $category_static->position;
1167 $categories[$i][
'socid'] = $category_static->socid;
1168 $categories[$i][
'ref_ext'] = $category_static->ref_ext;
1169 $categories[$i][
'visible'] = $category_static->visible;
1170 $categories[$i][
'type'] = $category_static->type;
1171 $categories[$i][
'entity'] = $category_static->entity;
1172 $categories[$i][
'array_options'] = $category_static->array_options;
1175 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && isset($category_static->multilangs)) {
1176 $categories[$i][
'multilangs'] = $category_static->multilangs;
1182 $this->error = $this->db->lasterror();
1185 if (!count($categories)) {
1201 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"categorie";
1202 $sql .=
" WHERE fk_parent = ".((int) $this->
id);
1203 $sql .=
" AND entity IN (".getEntity(
'category').
")";
1205 $res = $this->db->query($sql);
1208 while ($rec = $this->db->fetch_array($res)) {
1210 $cat->fetch($rec[
'rowid']);
1230 $this->motherof = array();
1233 $sql =
"SELECT fk_parent as id_parent, rowid as id_son";
1234 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
1235 $sql .=
" WHERE fk_parent <> 0";
1236 $sql .=
" AND entity IN (".getEntity(
'category').
")";
1238 dol_syslog(get_class($this).
"::load_motherof", LOG_DEBUG);
1239 $resql = $this->db->query($sql);
1241 while ($obj = $this->db->fetch_object($resql)) {
1242 $this->motherof[$obj->id_son] = $obj->id_parent;
1272 public function get_full_arbo($type, $fromid = 0, $include = 0, $forcelangcode =
'')
1277 if (!is_numeric($type)) {
1278 $type = $this->MAP_ID[$type];
1280 if (is_null($type)) {
1281 $this->error =
'BadValueForParameterType';
1285 if (is_string($fromid)) {
1286 $fromid = explode(
',', $fromid);
1287 } elseif (is_numeric($fromid)) {
1289 $fromid = array($fromid);
1293 } elseif (!is_array($fromid)) {
1297 $this->cats = array();
1303 if ($forcelangcode) {
1304 $current_lang = $forcelangcode;
1306 $current_lang = $langs->getDefaultLang();
1311 $sql =
"SELECT DISTINCT c.rowid, c.label, c.ref_ext, c.description, c.color, c.position, c.fk_parent, c.visible";
1313 $sql .=
", t.label as label_trans, t.description as description_trans";
1315 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as c";
1317 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_lang as t ON t.fk_category = c.rowid AND t.lang = '".$this->db->escape($current_lang).
"'";
1319 $sql .=
" WHERE c.entity IN (".getEntity(
'category').
")";
1320 $sql .=
" AND c.type = ".(int) $type;
1322 dol_syslog(get_class($this).
"::get_full_arbo get category list", LOG_DEBUG);
1324 $resql = $this->db->query($sql);
1327 $nbcateg = $this->db->num_rows($resql);
1329 while ($obj = $this->db->fetch_object($resql)) {
1330 $this->cats[$obj->rowid][
'rowid'] = $obj->rowid;
1331 $this->cats[$obj->rowid][
'id'] = $obj->rowid;
1332 $this->cats[$obj->rowid][
'fk_parent'] = $obj->fk_parent;
1333 $this->cats[$obj->rowid][
'label'] = !empty($obj->label_trans) ? $obj->label_trans : $obj->label;
1334 $this->cats[$obj->rowid][
'description'] = !empty($obj->description_trans) ? $obj->description_trans : $obj->description;
1335 $this->cats[$obj->rowid][
'color'] = $obj->color;
1336 $this->cats[$obj->rowid][
'position'] = $obj->position;
1337 $this->cats[$obj->rowid][
'visible'] = $obj->visible;
1338 $this->cats[$obj->rowid][
'ref_ext'] = $obj->ref_ext;
1339 $this->cats[$obj->rowid][
'picto'] =
'category';
1341 $this->cats[$obj->rowid][
'fullpath'] =
'';
1342 $this->cats[$obj->rowid][
'fulllabel'] =
'';
1351 dol_syslog(get_class($this).
"::get_full_arbo call to buildPathFromId", LOG_DEBUG);
1353 foreach ($this->cats as $key => $val) {
1359 if (count($fromid) > 0) {
1360 $keyfiltercatid =
'('.implode(
'|', $fromid).
')';
1363 $keyfilter1 =
'^'.$keyfiltercatid.
'$';
1364 $keyfilter2 =
'_'.$keyfiltercatid.
'$';
1365 $keyfilter3 =
'^'.$keyfiltercatid.
'_';
1366 $keyfilter4 =
'_'.$keyfiltercatid.
'_';
1367 foreach (array_keys($this->cats) as $key) {
1368 $fullpath = (string) $this->cats[$key][
'fullpath'];
1369 $test = (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
1370 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath));
1372 if (($test && !$include) || (!$test && $include)) {
1373 unset($this->cats[$key]);
1378 dol_syslog(get_class($this).
"::get_full_arbo dol_sort_array", LOG_DEBUG);
1380 $this->cats =
dol_sort_array($this->cats,
'fulllabel',
'asc', 1, 0, 1);
1399 if (!empty($this->cats[$id_categ][
'fullpath'])) {
1401 dol_syslog(get_class($this).
"::buildPathFromId fullpath and fulllabel already defined", LOG_WARNING);
1408 $this->cats[$id_categ][
'fullpath'] =
'_'.$id_categ;
1409 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$id_categ][
'label'];
1411 $cursor_categ = $id_categ;
1413 while ((empty($protection) || $i < $protection) && !empty($this->motherof[$cursor_categ])) {
1415 $this->cats[$id_categ][
'fullpath'] =
'_'.$this->motherof[$cursor_categ].$this->cats[$id_categ][
'fullpath'];
1416 $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'];
1419 $cursor_categ = $this->motherof[$cursor_categ];
1424 $nbunderscore = substr_count($this->cats[$id_categ][
'fullpath'],
'_');
1425 $this->cats[$id_categ][
'level'] = ($nbunderscore ? $nbunderscore :
null);
1442 if (!is_numeric($type) && !is_null($type)) {
1443 $type = $this->MAP_ID[$type];
1446 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"categorie";
1447 $sql .=
" WHERE entity IN (".getEntity(
'category').
")";
1448 if (!is_null($type)) {
1449 $sql .=
" AND type = ".(int) $type;
1452 $sql .=
" AND fk_parent = 0";
1455 $res = $this->db->query($sql);
1458 while ($rec = $this->db->fetch_array($res)) {
1460 $cat->fetch($rec[
'rowid']);
1461 $cats[$rec[
'rowid']] = $cat;
1492 $type = $this->type;
1494 if (!is_numeric($type)) {
1495 $type = $this->MAP_ID[$type];
1501 $sql =
"SELECT c.rowid";
1502 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as c ";
1503 $sql .=
" WHERE c.entity IN (".getEntity(
'category').
")";
1504 $sql .=
" AND c.type = ".((int) $type);
1505 $sql .=
" AND c.fk_parent = ".((int) $this->fk_parent);
1506 $sql .=
" AND c.label = '".$this->db->escape($this->label).
"'";
1508 dol_syslog(get_class($this).
"::already_exists", LOG_DEBUG);
1510 $resql = $this->db->query($sql);
1512 if ($this->db->num_rows($resql) > 0) {
1513 $obj = $this->db->fetch_object($resql);
1518 if (!empty($obj) && $obj->rowid > 0 && $obj->rowid != $this->id) {
1519 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);
1523 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);
1526 $this->error = $this->db->error();
1543 public function print_all_ways($sep =
'>>', $url =
'', $nocolor = 0, $addpicto = 0)
1550 foreach ($all_ways as $way) {
1554 foreach ($way as $cat) {
1557 if (empty($nocolor)) {
1558 $forced_color =
'colortoreplace';
1559 if ($i == count($way)) {
1561 $forced_color =
'categtextwhite';
1564 $forced_color =
'categtextblack';
1571 $link =
'<a href="'.DOL_URL_ROOT.
'/categories/viewcat.php?id='.((int) $cat->id).
'&type='.urlencode($cat->type).
'" class="'.($i < count($way) ?
'small ' :
'').$forced_color.
'">';
1573 $w[] = $link.(($addpicto && $i == 1) ?
img_object(
'',
'category',
'class="paddingright"') :
'').$cat->label.$linkend;
1574 } elseif ($url ==
'none') {
1575 $link =
'<span class="valignmiddle '.($i < count($way) ?
'small ' :
'').$forced_color.
'">';
1576 $linkend =
'</span>';
1577 $w[] = $link.(($addpicto && $i == 1) ?
img_object(
'',
'category',
'class="paddingright"') :
'').$cat->label.$linkend;
1579 $w[] =
'<a class="valignmiddle '.($i < count($way) ?
'small ' :
'').$forced_color.
'" href="'.DOL_URL_ROOT.
'/'.$url.
'?catid='.((
int) $cat->id).
'">'.($addpicto ?
img_object(
'',
'category') :
'').$cat->label.
'</a>';
1582 $newcategwithpath = preg_replace(
'/colortoreplace/', $forced_color, implode(
'<span class="inline-block valignmiddle paddingleft paddingright '.$forced_color.
'">'.$sep.
'</span>', $w));
1584 $ways[] = $newcategwithpath;
1603 $sql =
"SELECT fk_parent FROM ".MAIN_DB_PREFIX.
"categorie";
1604 $sql .=
" WHERE rowid = ".((int) $this->
id);
1606 $res = $this->db->query($sql);
1609 while ($rec = $this->db->fetch_array($res)) {
1610 if ($rec[
'fk_parent'] > 0) {
1612 $cat->fetch($rec[
'fk_parent']);
1636 if (is_array($parents)) {
1637 foreach ($parents as $parent) {
1638 $all_ways = $parent->get_all_ways();
1639 foreach ($all_ways as $way) {
1647 if (count($ways) == 0) {
1648 $ways[0][0] = $this;
1668 if (is_numeric($type)) {
1669 $type = array_search($type, $this->MAP_ID);
1672 if ($type === Categorie::TYPE_BANK_LINE) {
1674 $sql =
"SELECT c.label, c.rowid";
1675 $sql .=
" FROM ".MAIN_DB_PREFIX.
"category_bankline as a, ".MAIN_DB_PREFIX.
"categorie as c";
1676 $sql .=
" WHERE a.lineid=".((int) $id).
" AND a.fk_categ = c.rowid";
1677 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
1678 $sql .=
" ORDER BY c.label";
1680 $res = $this->db->query($sql);
1682 while ($obj = $this->db->fetch_object($res)) {
1683 if ($mode ==
'id') {
1684 $cats[] = $obj->rowid;
1685 } elseif ($mode ==
'label') {
1686 $cats[] = $obj->label;
1689 $cat->id = $obj->rowid;
1690 $cat->label = $obj->label;
1699 $sql =
"SELECT ct.fk_categorie, c.label, c.rowid";
1700 $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";
1701 $sql .=
" WHERE ct.fk_categorie = c.rowid AND ct.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = ".(
int) $id;
1705 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
1707 $res = $this->db->query($sql);
1709 while ($obj = $this->db->fetch_object($res)) {
1710 if ($mode ==
'id') {
1711 $cats[] = $obj->rowid;
1712 } elseif ($mode ==
'label') {
1713 $cats[] = $obj->label;
1716 $cat->fetch($obj->fk_categorie);
1740 public function rechercher($id, $nom, $type, $exact =
false, $case =
false)
1743 if (is_numeric($type)) {
1744 dol_syslog(__METHOD__.
': using numeric types is deprecated.', LOG_WARNING);
1750 if (is_numeric($type)) {
1752 $map_type = array_flip($this->MAP_ID);
1753 $type = $map_type[$type];
1754 dol_syslog(get_class($this).
"::rechercher(): numeric types are deprecated, please use string instead", LOG_WARNING);
1758 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"categorie";
1759 $sql .=
" WHERE type = ".((int) $this->MAP_ID[$type]);
1760 $sql .=
" AND entity IN (".getEntity(
'category').
")";
1763 $nom =
'%'.$this->db->escape(str_replace(
'*',
'%', $nom)).
'%';
1766 $sql .=
" AND label LIKE '".$this->db->escape($nom).
"'";
1768 $sql .=
" AND label LIKE BINARY '".$this->db->escape($nom).
"'";
1772 $sql .=
" AND rowid = ".((int) $id);
1775 $res = $this->db->query($sql);
1777 while ($rec = $this->db->fetch_array($res)) {
1779 $cat->fetch($rec[
'rowid']);
1785 $this->error = $this->db->error().
' sql='.$sql;
1798 include_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
1799 include_once DOL_DOCUMENT_ROOT .
'/core/lib/images.lib.php';
1801 $sdir .=
'/' .
get_exdir($this->
id, 2, 0, 0, $this,
'category') . $this->
id .
"/photos/";
1804 if (file_exists($dir_osencoded)) {
1805 $handle = opendir($dir_osencoded);
1806 if (is_resource($handle)) {
1807 while (($file = readdir($handle)) !==
false) {
1809 $file = mb_convert_encoding($file,
'UTF-8',
'ISO-8859-1');
1830 $langs->load(
'categories');
1834 $datas[
'label'] = $langs->trans(
"ShowCategory").
': '.($this->
ref ? $this->
ref : $this->label);
1852 public function getNomUrl($withpicto = 0, $option =
'', $maxlength = 0, $moreparam =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = 0)
1854 global
$conf, $langs, $hookmanager;
1856 if (!empty(
$conf->dol_no_mouse_hover)) {
1863 'objecttype' => $this->element,
1864 'option' => $option,
1866 $classfortooltip =
'classfortooltip';
1869 $classfortooltip =
'classforajaxtooltip';
1870 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1876 $url = DOL_URL_ROOT.
'/categories/viewcat.php?id='.$this->
id.
'&type='.$this->
type.$moreparam.
'&backtopage='.urlencode($_SERVER[
'PHP_SELF'].($moreparam ?
'?'.$moreparam :
''));
1878 if ($option !==
'nolink') {
1880 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1881 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1882 $add_save_lastsearch_values = 1;
1884 if ( $add_save_lastsearch_values) {
1885 $url .=
'&save_lastsearch_values=1';
1890 $forced_color =
'categtextwhite';
1893 $forced_color =
'categtextblack';
1898 if (empty($notooltip)) {
1900 $label = $langs->trans(
"ShowMyObject");
1901 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1903 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1904 $linkclose .= $dataparams.
' class="'.$classfortooltip.
' '.$forced_color.($morecss ?
' '.$morecss :
'').
'"';
1906 $linkclose =
' class="'.$forced_color.($morecss ?
' '.$morecss :
'').
'"';
1909 if ($option ==
'nolink' ) {
1910 $linkstart =
'<span';
1912 $linkstart =
'<a href="'.$url.
'"';
1914 $linkstart .= $linkclose.
'>';
1915 if ($option ==
'nolink' ) {
1916 $linkend =
'</span>';
1921 $result .= $linkstart;
1924 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
1927 if ($withpicto != 2) {
1928 $result .=
dol_trunc(($this->
ref ? $this->
ref : $this->label), $maxlength);
1931 $result .= $linkend;
1934 $hookmanager->initHooks(array($this->element .
'dao'));
1935 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1936 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1938 $result = $hookmanager->resPrint;
1940 $result .= $hookmanager->resPrint;
1957 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1959 $dir = $sdir.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'category').$this->id.
"/";
1962 if (!file_exists($dir)) {
1966 if (file_exists($dir)) {
1967 if (is_array($file[
'name'])) {
1968 $nbfile = count($file[
'name']);
1969 for ($i = 0; $i < $nbfile; $i++) {
1970 $originImage = $dir.$file[
'name'][$i];
1975 if (file_exists($originImage)) {
1981 $originImage = $dir.$file[
'name'];
1986 if (file_exists($originImage)) {
2005 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2010 $dirthumb = $dir.
'thumbs/';
2012 if (file_exists($dir)) {
2013 $handle = opendir($dir);
2014 if (is_resource($handle)) {
2015 while (($file = readdir($handle)) !==
false) {
2016 if (
dol_is_file($dir.$file) && preg_match(
'/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $dir.$file)) {
2021 $photo_vignette =
'';
2023 if (preg_match(
'/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $photo, $regs)) {
2024 $photo_vignette = preg_replace(
'/'.$regs[0].
'/i',
'', $photo).
'_small'.$regs[0];
2029 $obj[
'photo'] = $photo;
2030 if ($photo_vignette && is_file($dirthumb.$photo_vignette)) {
2031 $obj[
'photo_vignette'] =
'thumbs/'.$photo_vignette;
2033 $obj[
'photo_vignette'] =
"";
2036 $tabobj[$nbphoto - 1] = $obj;
2039 if ($nbmax && $nbphoto >= $nbmax) {
2062 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2064 $dir = dirname($file).
'/';
2065 $dirthumb = $dir.
'/thumbs/';
2066 $filename = preg_replace(
'/'.preg_quote($dir,
'/').
'/i',
'', $file);
2073 if (preg_match(
'/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $filename, $regs)) {
2074 $photo_vignette = preg_replace(
'/'.$regs[0].
'/i',
'', $filename).
'_small'.$regs[0];
2075 if (file_exists($dirthumb.$photo_vignette)) {
2091 $infoImg = getimagesize($file);
2092 $this->imgWidth = $infoImg[0];
2093 $this->imgHeight = $infoImg[1];
2108 $langs_available = $langs->get_available_languages();
2109 $current_lang = $langs->getDefaultLang();
2111 foreach ($langs_available as $key => $value) {
2112 $sql =
"SELECT rowid";
2113 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_lang";
2114 $sql .=
" WHERE fk_category=".((int) $this->
id);
2115 $sql .=
" AND lang = '".$this->db->escape($key).
"'";
2117 $result = $this->db->query($sql);
2119 if ($key == $current_lang) {
2121 if ($this->db->num_rows($result)) {
2122 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"categorie_lang";
2123 $sql2 .=
" SET label = '".$this->db->escape($this->label).
"',";
2124 $sql2 .=
" description = '".$this->db->escape($this->
description).
"'";
2125 $sql2 .=
" WHERE fk_category = ".((int) $this->
id).
" AND lang = '".$this->db->escape($key).
"'";
2126 } elseif (isset($this->multilangs[$key])) {
2127 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_lang (fk_category, lang, label, description)";
2128 $sql2 .=
" VALUES(".((int) $this->
id).
", '".$this->db->escape($key).
"', '".$this->db->escape($this->label).
"'";
2129 $sql2 .=
", '".$this->db->escape($this->multilangs[$key][
"description"]).
"')";
2131 dol_syslog(get_class($this).
'::setMultiLangs', LOG_DEBUG);
2132 if ($sql2 && !$this->db->query($sql2)) {
2133 $this->error = $this->db->lasterror();
2136 } elseif (isset($this->multilangs[$key])) {
2137 if ($this->db->num_rows($result)) {
2138 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"categorie_lang";
2139 $sql2 .=
" SET label='".$this->db->escape($this->multilangs[$key][
"label"]).
"',";
2140 $sql2 .=
" description='".$this->db->escape($this->multilangs[$key][
"description"]).
"'";
2141 $sql2 .=
" WHERE fk_category=".((int) $this->
id).
" AND lang='".$this->db->escape($key).
"'";
2143 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_lang (fk_category, lang, label, description)";
2144 $sql2 .=
" VALUES(".((int) $this->
id).
", '".$this->db->escape($key).
"', '".$this->db->escape($this->multilangs[$key][
"label"]).
"'";
2145 $sql2 .=
",'".$this->db->escape($this->multilangs[$key][
"description"]).
"')";
2149 if ($this->multilangs[$key][
"label"] || $this->multilangs[$key][
"description"] || $this->multilangs[$key][
"note"]) {
2150 dol_syslog(get_class($this).
'::setMultiLangs', LOG_DEBUG);
2152 if (!$this->db->query($sql2)) {
2153 $this->error = $this->db->lasterror();
2161 $result = $this->
call_trigger(
'CATEGORY_SET_MULTILANGS', $user);
2163 $this->error = $this->db->lasterror();
2182 $sql =
"DELETE FROM ".$this->db->prefix().
"categorie_lang";
2183 $sql .=
" WHERE fk_category = ".((int) $this->
id).
" AND lang = '".$this->db->escape($langtodelete).
"'";
2185 dol_syslog(get_class($this).
'::delMultiLangs', LOG_DEBUG);
2186 $result = $this->db->query($sql);
2189 $result = $this->
call_trigger(
'CATEGORY_DEL_MULTILANGS', $user);
2191 $this->error = $this->db->lasterror();
2192 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
2198 $this->error = $this->db->lasterror();
2199 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
2213 $current_lang = $langs->getDefaultLang();
2215 $sql =
"SELECT lang, label, description";
2216 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_lang";
2217 $sql .=
" WHERE fk_category=".((int) $this->
id);
2219 $result = $this->db->query($sql);
2221 while ($obj = $this->db->fetch_object($result)) {
2223 if ($obj->lang == $current_lang) {
2224 $this->label = $obj->label;
2227 $this->multilangs[$obj->lang][
"label"] = $obj->label;
2228 $this->multilangs[$obj->lang][
"description"] = $obj->description;
2232 $this->error = $langs->trans(
"Error").
" : ".$this->db->error().
" - ".$sql;
2258 dol_syslog(get_class($this).
"::initAsSpecimen");
2262 $this->fk_parent = 0;
2263 $this->label =
'SPECIMEN';
2264 $this->specimen = 1;
2267 $this->
type = self::TYPE_PRODUCT;
2299 if ($type ==
'bank_account') {
2303 return " LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_".$type.
" as cp ON ".$rowIdName.
" = cp.fk_".$type;
2317 if ($type ==
'bank_account') {
2320 if ($type ==
'customer') {
2323 if ($type ==
'supplier') {
2324 $type =
'fournisseur';
2327 if (empty($searchList) && !is_array($searchList)) {
2331 $searchCategorySqlList = array();
2332 foreach ($searchList as $searchCategory) {
2333 if (intval($searchCategory) == -2) {
2334 $searchCategorySqlList[] =
" cp.fk_categorie IS NULL";
2335 } elseif (intval($searchCategory) > 0) {
2336 $searchCategorySqlList[] =
" ".$rowIdName.
" IN (SELECT fk_".$type.
" FROM ".MAIN_DB_PREFIX.
"categorie_".$type.
" WHERE fk_categorie = ".((int) $searchCategory).
")";
2340 if (!empty($searchCategorySqlList)) {
2341 return " AND (".implode(
' AND ', $searchCategorySqlList).
")";
2354 dol_syslog(get_class($this).
"::count_all_categories", LOG_DEBUG);
2355 $sql =
"SELECT COUNT(rowid) FROM ".MAIN_DB_PREFIX.
"categorie";
2356 $sql .=
" WHERE entity IN (".getEntity(
'category').
")";
2358 $res = $this->db->query($sql);
2360 $obj = $this->db->fetch_object($res);
Class to manage categories.
getListForItem($id, $type='customer', $sortfield="s.rowid", $sortorder='ASC', $limit=0, $page=0)
Return the list of the categories of a given element (a product, a customer, ...).
get_image_size($file)
Load size of image file.
load_motherof()
Load the array this->motherof that is array(id_son=>id_parent, ...), so array of all child categories...
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 a given object having id $id and typ...
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 matches.
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 a given object in the current category.
get_main_categories($type=null)
Returns the first 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.
$fields
'type' if the field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter...
get_meres()
Returns an array containing the list of parent categories Note: A category can only have one parent b...
get_full_arbo($type, $fromid=0, $include=0, $forcelangcode='')
Rebuilding the category tree as an array Return an array of table('id','id_mere',....
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 array all possible paths to go to the category starting with the major categories repres...
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.
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.
addThumbs($file, $quality=50)
Build thumb.
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_is_file($pathoffile)
Return if path is a file.
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $keyforsourcefile='addedfile', $upload_dir='', $mode=0)
Check validity of a file upload from an GUI page, and move it to its final destination.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type