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';
72 const TYPE_SUPPLIER_PROPOSAL =
'supplier_proposal';
73 const TYPE_PROPOSAL =
'propal';
74 const TYPE_PROJECT_TASK =
'project_task';
81 public $picto =
'category';
87 public $MAP_ID = array(
100 'website_page' => 11,
102 'knowledgemanagement' => 13,
106 'supplier_order' => 20,
107 'supplier_invoice' => 21,
108 'supplier_proposal' => 22,
110 'project_task' => 24,
149 public $MAP_CAT_FK = array(
152 'contact' =>
'socpeople',
153 'bank_account' =>
'account',
159 public $MAP_CAT_TABLE = array(
160 'customer' =>
'societe',
161 'supplier' =>
'fournisseur',
162 'bank_account' =>
'account',
168 public $MAP_OBJ_CLASS = array(
169 'product' =>
'Product',
170 'service' =>
'Product',
171 'customer' =>
'Societe',
172 'supplier' =>
'Fournisseur',
173 'member' =>
'Adherent',
174 'contact' =>
'Contact',
176 'account' =>
'Account',
177 'bank_account' =>
'Account',
178 'project' =>
'Project',
179 'warehouse' =>
'Entrepot',
180 'actioncomm' =>
'ActionComm',
181 'website_page' =>
'WebsitePage',
182 'ticket' =>
'Ticket',
183 'knowledgemanagement' =>
'KnowledgeRecord',
184 'fichinter' =>
'Fichinter',
185 'order' =>
'Commande',
186 'invoice' =>
'Facture',
187 'supplier_order' =>
'CommandeFournisseur',
188 'supplier_invoice' =>
'FactureFournisseur',
189 'supplier_proposal' =>
'SupplierProposal',
190 'propal' =>
'Propal',
191 'project_task' =>
'Task',
198 public static $MAP_TYPE_TITLE_AREA = array(
199 'product' =>
'Products',
200 'service' =>
'Services',
201 'customer' =>
'ProspectsOrCustomers',
202 'supplier' =>
'Suppliers',
203 'member' =>
'Members',
204 'contact' =>
'Contacts',
206 'account' =>
'Accounts',
207 'bank_account' =>
'BankAccounts',
208 'bank_line' =>
'BankTransactions',
209 'project' =>
'Projects',
210 'warehouse' =>
'Warehouse',
211 'actioncomm' =>
'AgendaEvents',
212 'website_page' =>
'WebsitePages',
213 'ticket' =>
'Tickets',
214 'knowledgemanagement' =>
'KnowledgeRecords',
215 'fichinter' =>
'Interventions',
217 'invoice' =>
'Invoices',
218 'supplier_order' =>
'SuppliersOrders',
219 'supplier_invoice' =>
'SuppliersInvoices',
220 'propal' =>
'Proposals',
221 'supplier_proposal' =>
'SupplierProposals',
222 'project_task' =>
'Tasks',
230 public $MAP_OBJ_TABLE = array(
231 'customer' =>
'societe',
232 'supplier' =>
'societe',
233 'member' =>
'adherent',
234 'contact' =>
'socpeople',
235 'account' =>
'bank_account',
236 'project' =>
'projet',
237 'warehouse' =>
'entrepot',
238 'knowledgemanagement' =>
'knowledgemanagement_knowledgerecord',
239 'fichinter' =>
'fichinter',
240 'order' =>
'commande',
241 'invoice' =>
'facture',
242 'supplier_order' =>
'commande_fournisseur',
243 'supplier_invoice' =>
'facture_fourn',
244 'project_task' =>
'projet_task',
251 public $element =
'category';
256 public $table_element =
'categorie';
321 public $cats = array();
326 public $motherof = array();
331 public $childs = array();
336 public $multilangs = array();
373 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'position' => 10,
'notnull' => 1,
'visible' => 0,),
374 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => 0,
'default' =>
'1',
'notnull' => 1,
'index' => 1,
'position' => 5),
375 'fk_parent' => array(
'type' =>
'integer',
'label' =>
'ParentCategory',
'enabled' => 1,
'position' => 20,
'notnull' => 1,
'visible' => 0,
'css' =>
'maxwidth500 widthcentpercentminusxx',),
376 '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),
377 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'position' => 30,
'notnull' => 0,
'visible' => 0,
'alwayseditable' => 1,),
378 'type' => array(
'type' =>
'integer',
'label' =>
'Type',
'enabled' => 1,
'position' => 35,
'notnull' => 1,
'visible' => 0,
'alwayseditable' => 1,),
379 'description' => array(
'type' =>
'text',
'label' =>
'Description',
'enabled' => 1,
'position' => 40,
'notnull' => 0,
'visible' => 1,
'alwayseditable' => 1,),
380 'color' => array(
'type' =>
'varchar(8)',
'label' =>
'Color',
'enabled' => 1,
'position' => 45,
'notnull' => 0,
'visible' => 1,
'alwayseditable' => 1,),
381 'position' => array(
'type' =>
'integer',
'label' =>
'Position',
'enabled' => 1,
'position' => 50,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
382 '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',),
383 'visible' => array(
'type' =>
'integer',
'label' =>
'Visible',
'enabled' => 1,
'position' => 60,
'notnull' => 1,
'visible' => 0,
'alwayseditable' => 1,),
384 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'position' => 900,
'notnull' => 0,
'visible' => -2,
'alwayseditable' => 1,),
385 'date_creation' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'position' => 70,
'notnull' => 0,
'visible' => -1,
'alwayseditable' => 1,),
386 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'position' => 75,
'notnull' => 1,
'visible' => -1,
'alwayseditable' => 1,),
387 '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',),
388 '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',),
396 public function __construct($db)
402 $this->ismultientitymanaged = 1;
403 $this->isextrafieldmanaged = 1;
405 if (is_object($hookmanager)) {
406 $hookmanager->initHooks(array(
'category'));
407 $parameters = array();
408 $reshook = $hookmanager->executeHooks(
'constructCategory', $parameters, $this);
409 if ($reshook >= 0 && !empty($hookmanager->resArray)) {
410 foreach ($hookmanager->resArray as $mapList) {
412 $mapId = $mapList[
'id'];
413 $mapCode = $mapList[
'code'];
415 $this->MAP_ID[$mapCode] = $mapId;
416 $this->MAP_CAT_FK[$mapCode] = isset($mapList[
'cat_fk']) ? $mapList[
'cat_fk'] :
null;
417 $this->MAP_CAT_TABLE[$mapCode] = isset($mapList[
'cat_table']) ? $mapList[
'cat_table'] :
null;
418 $this->MAP_OBJ_CLASS[$mapCode] = $mapList[
'obj_class'];
419 $this->MAP_OBJ_TABLE[$mapCode] = $mapList[
'obj_table'];
420 self::$MAP_TYPE_TITLE_AREA[$mapCode] = isset($mapList[
'label']) ? $mapList[
'label'] :
null;
435 foreach ($this->MAP_ID as $mapCode => $mapId) {
439 'cat_fk' => (empty($this->MAP_CAT_FK[$mapCode]) ? $mapCode : $this->MAP_CAT_FK[$mapCode]),
440 'cat_table' => (empty($this->MAP_CAT_TABLE[$mapCode]) ? $mapCode : $this->MAP_CAT_TABLE[$mapCode]),
441 'obj_class' => (empty($this->MAP_OBJ_CLASS[$mapCode]) ? $mapCode : $this->MAP_OBJ_CLASS[$mapCode]),
442 'obj_table' => (empty($this->MAP_OBJ_TABLE[$mapCode]) ? $mapCode : $this->MAP_OBJ_TABLE[$mapCode]),
456 return $this->MAP_ID;
468 public function fetch($id, $label =
'', $type =
null, $ref_ext =
'')
471 if (empty($id) && empty($label) && empty($ref_ext)) {
472 $this->error =
"No category to search for";
475 if (!is_null($type) && !is_numeric($type)) {
476 $type = $this->MAP_ID[$type];
479 $sql =
"SELECT rowid, fk_parent, entity, label, description, color, position, fk_soc, visible, type, ref_ext";
480 $sql .=
", date_creation, tms, fk_user_creat, fk_user_modif, import_key";
481 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
483 $sql .=
" WHERE rowid = ".((int) $id);
484 } elseif (!empty($ref_ext)) {
485 $sql .=
" WHERE ref_ext LIKE '".$this->db->escape($ref_ext).
"'";
487 $sql .=
" WHERE label = '".$this->db->escape($label).
"' AND entity IN (".
getEntity(
'category').
")";
488 if (!is_null($type)) {
489 $sql .=
" AND type = ".((int) $type);
493 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
494 $resql = $this->db->query($sql);
496 if ($this->db->num_rows($resql) > 0 && $res = $this->db->fetch_array($resql)) {
497 $this->
id = $res[
'rowid'];
499 $this->fk_parent = (int) $res[
'fk_parent'];
500 $this->label = $res[
'label'];
502 $this->color = $res[
'color'];
504 $this->socid = (int) $res[
'fk_soc'];
505 $this->visible = (int) $res[
'visible'];
506 $this->
type = $res[
'type'];
507 $this->ref_ext = $res[
'ref_ext'];
508 $this->entity = (int) $res[
'entity'];
509 $this->date_creation = $this->db->jdate($res[
'date_creation']);
510 $this->date_modification = $this->db->jdate($res[
'tms']);
511 $this->user_creation_id = (int) $res[
'fk_user_creat'];
512 $this->user_modification_id = (int) $res[
'fk_user_modif'];
513 $this->import_key = $res[
'import_key'];
519 $this->db->free($resql);
528 $this->error =
"No category found";
533 $this->error = $this->db->lasterror;
534 $this->errors[] = $this->db->lasterror;
549 public function create($user, $notrigger = 0)
551 global
$conf, $langs;
552 $langs->load(
'categories');
556 if (!is_numeric($type)) {
557 $type = $this->MAP_ID[$type];
562 dol_syslog(get_class($this).
'::create', LOG_DEBUG);
565 $this->label = trim((
string) $this->label);
567 $this->color = trim((
string) $this->color);
569 if (isset($this->import_key)) {
570 $this->import_key = trim($this->import_key);
572 $this->ref_ext = trim((
string) $this->ref_ext);
573 if (empty($this->visible)) {
576 $this->fk_parent = ($this->fk_parent !=
"" ? intval($this->fk_parent) : 0);
579 $this->error = $langs->trans(
"ImpossibleAddCat", $this->label);
580 $this->error .=
" : ".$langs->trans(
"CategoryExistsAtSameLevel");
587 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie (";
588 $sql .=
"fk_parent,";
590 $sql .=
" description,";
592 $sql .=
" position,";
598 $sql .=
" import_key,";
601 $sql .=
" date_creation,";
602 $sql .=
" fk_user_creat";
603 $sql .=
") VALUES (";
604 $sql .= (int) $this->fk_parent.
",";
605 $sql .=
"'".$this->db->escape($this->label).
"', ";
606 $sql .=
"'".$this->db->escape($this->description).
"', ";
607 $sql .=
"'".$this->db->escape($this->color).
"', ";
610 $sql .= ($this->socid > 0 ? ((int) $this->socid) :
'null').
", ";
612 $sql .=
"'".$this->db->escape((
string) $this->visible).
"', ";
613 $sql .= ((int) $type).
", ";
614 $sql .= (!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
'null').
", ";
615 $sql .= (!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
'null').
", ";
616 $sql .= (int)
$conf->entity.
", ";
617 $sql .=
"'".$this->db->idate($now).
"', ";
618 $sql .= (int) $user->id;
621 $res = $this->db->query($sql);
623 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"categorie");
636 if (!$error && !$notrigger) {
638 $result = $this->call_trigger(
'CATEGORY_CREATE', $user);
649 $this->db->rollback();
653 $this->db->rollback();
657 $this->error = $this->db->error();
658 $this->db->rollback();
679 $this->label = trim((
string) $this->label);
681 $this->ref_ext = trim((
string) $this->ref_ext);
682 $this->fk_parent = ($this->fk_parent !=
"" ? intval($this->fk_parent) : 0);
683 $this->visible = ($this->visible !=
"" ? intval($this->visible) : 0);
685 if ($this->fk_parent > 0 && $this->fk_parent == $this->
id) {
686 $langs->load(
'categories');
687 $this->error = $langs->trans(
"ErrorCategoryCannotBeItsOwnParent");
693 if (empty($this->oldcopy) || $this->fk_parent != $this->oldcopy->fk_parent) {
694 $ancestorid = $this->fk_parent;
696 while ($ancestorid > 0 && $protection-- > 0) {
697 $resql = $this->db->query(
"SELECT fk_parent FROM ".MAIN_DB_PREFIX.
"categorie WHERE rowid = ".((
int) $ancestorid));
698 $obj = $resql ? $this->db->fetch_object($resql) :
null;
699 $ancestorid = $obj ? (int) $obj->fk_parent : 0;
700 if ($ancestorid == $this->
id) {
701 $langs->load(
'categories');
702 $this->error = $langs->trans(
"ErrorCategoryCannotBeMovedIntoItsDescendant");
710 $this->error = $langs->trans(
"ImpossibleUpdateCat");
711 $this->error .=
" : ".$langs->trans(
"CategoryExistsAtSameLevel");
717 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"categorie";
718 $sql .=
" SET label = '".$this->db->escape($this->label).
"',";
719 $sql .=
" description = '".$this->db->escape($this->description).
"',";
720 $sql .=
" ref_ext = '".$this->db->escape($this->ref_ext).
"',";
721 $sql .=
" color = '".$this->db->escape($this->color).
"'";
722 $sql .=
", position = ".(int) $this->
position;
724 $sql .=
", fk_soc = ".($this->socid > 0 ? ((int) $this->socid) :
'null');
726 $sql .=
", visible = ".(int) $this->visible;
727 $sql .=
", fk_parent = ".(int) $this->fk_parent;
728 $sql .=
", fk_user_modif = ".(int) $user->id;
729 $sql .=
" WHERE rowid = ".((int) $this->
id);
731 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
732 if ($this->db->query($sql)) {
736 $this->db->rollback();
749 if (!$error && !$notrigger) {
751 $result = $this->call_trigger(
'CATEGORY_MODIFY', $user);
762 $this->db->rollback();
766 $this->db->rollback();
779 public function delete($user, $notrigger = 0)
784 $this->fk_parent = ($this->fk_parent !=
"" ? intval($this->fk_parent) : 0);
792 $result = $this->call_trigger(
'CATEGORY_DELETE', $user);
801 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"categorie";
802 $sql .=
" SET fk_parent = ".((int) $this->fk_parent);
803 $sql .=
" WHERE fk_parent = ".((int) $this->
id);
805 if (!$this->db->query($sql)) {
806 $this->error = $this->db->lasterror();
811 $arraydelete = array(
812 'categorie_account' =>
'fk_categorie',
813 'categorie_actioncomm' =>
'fk_categorie',
814 'categorie_contact' =>
'fk_categorie',
815 'categorie_fournisseur' =>
'fk_categorie',
816 'categorie_knowledgemanagement' => array(
'field' =>
'fk_categorie',
'enabled' =>
isModEnabled(
'knowledgemanagement')),
817 'categorie_fichinter' => array(
'field' =>
'fk_categorie',
'enabled' =>
false ),
818 'categorie_member' =>
'fk_categorie',
819 'categorie_user' =>
'fk_categorie',
820 'categorie_product' =>
'fk_categorie',
821 'categorie_project' =>
'fk_categorie',
822 'categorie_project_task' => array(
'field' =>
'fk_categorie',
'enabled' =>
isModEnabled(
'project')),
823 'categorie_societe' =>
'fk_categorie',
824 'categorie_ticket' => array(
'field' =>
'fk_categorie',
'enabled' =>
isModEnabled(
'ticket')),
825 'categorie_warehouse' => array(
'field' =>
'fk_categorie',
'enabled' =>
isModEnabled(
'stock')),
826 'categorie_website_page' => array(
'field' =>
'fk_categorie',
'enabled' =>
isModEnabled(
'website')),
827 'category_bankline' =>
'fk_categ',
828 'categorie_lang' =>
'fk_category',
829 'categorie' =>
'rowid',
833 $typecode = is_numeric($this->
type) ? array_search((
int) $this->
type, $this->MAP_ID) : $this->type;
834 if (!empty($typecode) && $typecode !=
'bank_line') {
835 $linktable =
'categorie_'.(empty($this->MAP_CAT_TABLE[$typecode]) ? $typecode : $this->MAP_CAT_TABLE[$typecode]);
836 if (array_key_exists($linktable, $arraydelete)) {
837 $arraydelete[$linktable] =
'fk_categorie';
839 $arraydelete = array($linktable =>
'fk_categorie') + $arraydelete;
842 foreach ($arraydelete as $key => $value) {
843 $sanitizedvalue = $value;
844 if (is_array($value)) {
845 if (empty($value[
'enabled'])) {
848 $sanitizedvalue = $value[
'field'];
851 $sql =
"DELETE FROM ".$this->db->sanitize(MAIN_DB_PREFIX.$key);
852 $sql .=
" WHERE ".$this->db->sanitize($sanitizedvalue).
" = ".((int) $this->
id);
853 if (!$this->db->query($sql)) {
854 $this->errors[] = $this->db->lasterror();
855 dol_syslog(
"Error sql=".$sql.
" ".$this->error, LOG_ERR);
865 dol_syslog(get_class($this).
"::delete erreur ".$this->error, LOG_ERR);
873 $this->db->rollback();
894 if ($this->
id == -1) {
899 $type = $obj->element;
902 dol_syslog(get_class($this).
'::add_type', LOG_DEBUG);
906 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
907 $sql .=
" (fk_categorie, fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
")";
908 $sql .=
" VALUES (".((int) $this->
id).
", ".((int) $obj->id).
")";
910 if ($this->db->query($sql)) {
912 $sql =
'SELECT fk_parent FROM '.MAIN_DB_PREFIX.
'categorie';
913 $sql .=
" WHERE rowid = ".((int) $this->
id);
915 dol_syslog(get_class($this).
"::add_type", LOG_DEBUG);
916 $resql = $this->db->query($sql);
918 if ($this->db->num_rows($resql) > 0) {
919 $objparent = $this->db->fetch_object($resql);
921 if (!empty($objparent->fk_parent)) {
923 $cat->id = $objparent->fk_parent;
924 if (!$cat->containsObject($type, $obj->id)) {
925 $result = $cat->add_type($obj, $type);
927 $this->error = $cat->error;
935 $this->error = $this->db->lasterror();
939 $this->db->rollback();
945 $this->context = array(
'linkto' => $obj);
946 $result = $this->call_trigger(
'CATEGORY_MODIFY', $user);
956 $this->db->rollback();
960 $this->db->rollback();
961 if ($this->db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
962 $this->error = $this->db->lasterrno();
965 $this->error = $this->db->lasterror();
988 if ($type ==
'societe') {
990 dol_syslog(get_class($this).
"::del_type(): type 'societe' is deprecated, please use 'customer' instead", LOG_WARNING);
991 } elseif ($type ==
'fournisseur') {
993 dol_syslog(get_class($this).
"::del_type(): type 'fournisseur' is deprecated, please use 'supplier' instead", LOG_WARNING);
998 $sql =
"DELETE 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);
1000 $sql .=
" AND fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = ".((
int) $obj->id);
1002 dol_syslog(get_class($this).
'::del_type', LOG_DEBUG);
1003 if ($this->db->query($sql)) {
1005 $this->context = array(
'unlinkoff' => $obj);
1006 $result = $this->call_trigger(
'CATEGORY_MODIFY', $user);
1013 $this->db->commit();
1016 $this->db->rollback();
1020 $this->db->rollback();
1021 $this->error = $this->db->lasterror();
1044 public function getObjectsInCateg($type, $onlyids = 0, $limit = 0, $offset = 0, $sortfield =
'', $sortorder =
'ASC', $filter =
'', $filtermode =
'AND', $filterlang =
'')
1048 if (empty($onlyids)) {
1049 dol_syslog(
"getObjectsInCateg: This method used with parameter onlyids=0 is deprecated. Try by using instead getListForItem().", LOG_WARNING);
1054 $classnameforobj = $this->MAP_OBJ_CLASS[$type];
1055 if (!empty($classnameforobj) && class_exists($classnameforobj)) {
1056 $tmpobj =
new $classnameforobj($this->db);
1059 $sql =
"SELECT c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" as fk_object";
1060 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]).
" as c";
1061 $sql .=
", ".MAIN_DB_PREFIX.(empty($this->MAP_OBJ_TABLE[$type]) ? $type : $this->MAP_OBJ_TABLE[$type]).
" as o";
1062 if (!empty($filterlang)) {
1063 $sql .=
", ".MAIN_DB_PREFIX.(empty($this->MAP_OBJ_TABLE[$type]) ? $type : $this->MAP_OBJ_TABLE[$type]).
"_lang as ol";
1065 $sql .=
" WHERE o.entity IN (".getEntity($tmpobj->element).
")";
1066 $sql .=
" AND c.fk_categorie = ".((int) $this->
id);
1068 if ((array_key_exists($type, $this->MAP_OBJ_TABLE) && $this->MAP_OBJ_TABLE[$type] ==
"actioncomm") || $type ==
"actioncomm") {
1069 $sql .=
" AND c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = o.id";
1071 $sql .=
" AND c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = o.rowid";
1073 if (!empty($filterlang)) {
1074 $sql .=
" AND ol.fk_".(empty($this->MAP_OBJ_TABLE[$type]) ? $type : $this->MAP_OBJ_TABLE[$type]).
" = o.rowid";
1075 $sql .=
" AND ol.lang = '".$this->db->escape($filterlang).
"'";
1078 if (($type ==
'customer' || $type ==
'supplier') && $user->socid > 0) {
1079 $sql .=
" AND o.rowid = ".((int) $user->socid);
1084 global $hookmanager;
1085 if (is_object($hookmanager)) {
1086 $parameters = array(
'type' => $type,
'alias' =>
'o');
1087 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
1088 $sql .= $hookmanager->resPrint;
1093 if ($errormessage) {
1094 $this->errors[] = $errormessage;
1095 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
1099 $sql .= $this->db->order($sortfield, $sortorder);
1100 if ($limit > 0 || $offset > 0) {
1101 $sql .= $this->db->plimit($limit + 1, $offset);
1104 dol_syslog(get_class($this).
"::getObjectsInCateg", LOG_DEBUG);
1106 $resql = $this->db->query($sql);
1108 while ($rec = $this->db->fetch_array($resql)) {
1110 $objs[] = $rec[
'fk_object'];
1112 $tmpobj =
new $classnameforobj($this->db);
1113 $tmpobj->fetch($rec[
'fk_object']);
1115 if ($tmpobj->id > 0) {
1121 $this->error = $this->db->error().
' sql='.$sql;
1139 $sql =
"SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX.
"categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
1140 $sql .=
" WHERE fk_categorie = ".((int) $this->
id).
" AND fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = ".((
int) $object_id);
1142 dol_syslog(get_class($this).
"::containsObject", LOG_DEBUG);
1144 $resql = $this->db->query($sql);
1146 return $this->db->fetch_object($resql)->nb;
1148 $this->error = $this->db->error();
1165 public function getListForItem($id, $type =
'customer', $sortfield =
"s.rowid", $sortorder =
'ASC', $limit = 0, $page = 0)
1167 $categories = array();
1172 $subcol_name =
"fk_".$type;
1173 if ($type ==
"customer") {
1174 $sub_type =
"societe";
1175 $subcol_name =
"fk_soc";
1177 if ($type ==
"supplier") {
1178 $sub_type =
"fournisseur";
1179 $subcol_name =
"fk_soc";
1181 if ($type ==
"contact") {
1182 $subcol_name =
"fk_socpeople";
1185 $idoftype = (int) (array_key_exists($type, $this->MAP_ID) ? $this->MAP_ID[$type] : -1);
1187 $sql =
"SELECT s.rowid";
1189 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as s, ".MAIN_DB_PREFIX.
"categorie_".$this->db->sanitize($sub_type).
" as sub";
1190 $sql .=
' WHERE s.entity IN ('.getEntity(
'category').
')';
1191 $sql .=
' AND s.type = '.((int) $idoftype);
1192 $sql .=
' AND s.rowid = sub.fk_categorie';
1193 $sql .=
" AND sub.".$this->db->sanitize($subcol_name).
" = ".((int) $id);
1196 $nbtotalofrecords =
'';
1198 $sqlforcount = preg_replace(
'/^'.preg_quote($sqlfields,
'/').
'/',
'SELECT COUNT(*) as nbtotalofrecords', $sql);
1199 $sqlforcount = preg_replace(
'/GROUP BY .*$/',
'', $sqlforcount);
1201 $resql = $this->db->query($sqlforcount);
1203 $objforcount = $this->db->fetch_object($resql);
1204 $nbtotalofrecords = $objforcount->nbtotalofrecords;
1209 if (($limit >= (
int) $nbtotalofrecords) && $page > 0) {
1213 if (($page * $limit) >= (
int) $nbtotalofrecords) {
1217 $this->db->free($resql);
1220 $sql .= $this->db->order($sortfield, $sortorder);
1225 $offset = $limit * $page;
1227 $sql .= $this->db->plimit($limit + 1, $offset);
1230 $result = $this->db->query($sql);
1233 $num = $this->db->num_rows($result);
1234 $min = min($num, ($limit <= 0 ? $num : $limit));
1236 $obj = $this->db->fetch_object($result);
1237 $category_static =
new Categorie($this->db);
1238 if ($category_static->fetch($obj->rowid)) {
1239 $categories[$i][
'id'] = $category_static->id;
1240 $categories[$i][
'fk_parent'] = $category_static->fk_parent;
1241 $categories[$i][
'label'] = $category_static->label;
1242 $categories[$i][
'description'] = $category_static->description;
1243 $categories[$i][
'color'] = $category_static->color;
1244 $categories[$i][
'position'] = $category_static->position;
1245 $categories[$i][
'socid'] = $category_static->socid;
1246 $categories[$i][
'ref_ext'] = $category_static->ref_ext;
1247 $categories[$i][
'visible'] = $category_static->visible;
1248 $categories[$i][
'type'] = $category_static->type;
1249 $categories[$i][
'entity'] = $category_static->entity;
1250 $categories[$i][
'array_options'] = $category_static->array_options;
1253 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && isset($category_static->multilangs)) {
1254 $categories[$i][
'multilangs'] = $category_static->multilangs;
1260 $this->error = $this->db->lasterror();
1263 if (!count($categories)) {
1279 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"categorie";
1280 $sql .=
" WHERE fk_parent = ".((int) $this->
id);
1281 $sql .=
" AND entity IN (".getEntity(
'category').
")";
1283 $res = $this->db->query($sql);
1286 while ($rec = $this->db->fetch_array($res)) {
1288 $cat->fetch($rec[
'rowid']);
1308 $this->motherof = array();
1311 $sql =
"SELECT fk_parent as id_parent, rowid as id_son";
1312 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie";
1313 $sql .=
" WHERE fk_parent <> 0";
1314 $sql .=
" AND entity IN (".getEntity(
'category').
")";
1316 dol_syslog(get_class($this).
"::load_motherof", LOG_DEBUG);
1317 $resql = $this->db->query($sql);
1319 while ($obj = $this->db->fetch_object($resql)) {
1320 $this->motherof[$obj->id_son] = $obj->id_parent;
1350 public function get_full_arbo($type, $fromid = 0, $include = 0, $forcelangcode =
'')
1355 if (!is_numeric($type)) {
1356 $type = $this->MAP_ID[$type];
1358 if (is_null($type)) {
1359 $this->error =
'BadValueForParameterType';
1363 if (is_string($fromid)) {
1364 $fromid = explode(
',', $fromid);
1365 } elseif (is_numeric($fromid)) {
1367 $fromid = array($fromid);
1371 } elseif (!is_array($fromid)) {
1375 $this->cats = array();
1381 if ($forcelangcode) {
1382 $current_lang = $forcelangcode;
1384 $current_lang = $langs->getDefaultLang();
1389 $sql =
"SELECT DISTINCT c.rowid, c.label, c.ref_ext, c.description, c.color, c.position, c.fk_parent, c.visible, c.entity";
1391 $sql .=
", t.label as label_trans, t.description as description_trans";
1393 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as c";
1395 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_lang as t ON t.fk_category = c.rowid AND t.lang = '".$this->db->escape($current_lang).
"'";
1397 $sql .=
" WHERE c.entity IN (".getEntity(
'category').
")";
1398 $sql .=
" AND c.type = ".(int) $type;
1400 dol_syslog(get_class($this).
"::get_full_arbo get category list", LOG_DEBUG);
1402 $resql = $this->db->query($sql);
1405 $nbcateg = $this->db->num_rows($resql);
1407 while ($obj = $this->db->fetch_object($resql)) {
1408 $this->cats[(int) $obj->rowid]
1410 'rowid' => (
int) $obj->rowid,
1411 'id' => (int) $obj->rowid,
1412 'fk_parent' => (
int) $obj->fk_parent,
1413 'label' => !empty($obj->label_trans) ? (
string) $obj->label_trans : (
string) $obj->label,
1414 'description' => !empty($obj->description_trans) ? (
string) $obj->description_trans : (
string) $obj->description,
1415 'color' => (
string) $obj->color,
1416 'position' => (
string) $obj->position,
1417 'visible' => (
int) $obj->visible,
1418 'ref_ext' => (
string) $obj->ref_ext,
1419 'entity' => (
int) $obj->entity,
1420 'picto' =>
'category',
1435 global $hookmanager;
1436 if (is_object($hookmanager)) {
1437 $parameters = array(
'cats' => &$this->cats,
'motherof' => &$this->motherof,
'type' => $type);
1438 $reshook = $hookmanager->executeHooks(
'completeCategoryFullTree', $parameters, $this);
1445 dol_syslog(get_class($this).
"::get_full_arbo call to buildPathFromId", LOG_DEBUG);
1447 foreach ($this->cats as $key => $val) {
1453 if (count($fromid) > 0) {
1454 $keyfiltercatid =
'('.implode(
'|', $fromid).
')';
1457 $keyfilter1 =
'^'.$keyfiltercatid.
'$';
1458 $keyfilter2 =
'_'.$keyfiltercatid.
'$';
1459 $keyfilter3 =
'^'.$keyfiltercatid.
'_';
1460 $keyfilter4 =
'_'.$keyfiltercatid.
'_';
1461 foreach (array_keys($this->cats) as $key) {
1462 $fullpath = (
string) $this->cats[$key][
'fullpath'];
1463 $test = (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
1464 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath));
1466 if (($test && !$include) || (!$test && $include)) {
1467 unset($this->cats[$key]);
1472 dol_syslog(get_class($this).
"::get_full_arbo dol_sort_array", LOG_DEBUG);
1474 $this->cats =
dol_sort_array($this->cats,
'fulllabel',
'asc', 1, 0, 1);
1493 if (!empty($this->cats[$id_categ][
'fullpath'])) {
1495 dol_syslog(get_class($this).
"::buildPathFromId fullpath and fulllabel already defined", LOG_WARNING);
1502 $this->cats[$id_categ][
'fullpath'] =
'_'.$id_categ;
1503 $this->cats[$id_categ][
'fulllabel'] = $this->cats[$id_categ][
'label'];
1505 $cursor_categ = $id_categ;
1507 while ((empty($protection) || $i < $protection) && !empty($this->motherof[$cursor_categ])) {
1509 $this->cats[$id_categ][
'fullpath'] =
'_'.$this->motherof[$cursor_categ].$this->cats[$id_categ][
'fullpath'];
1510 $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'];
1513 $cursor_categ = $this->motherof[$cursor_categ];
1518 $nbunderscore = substr_count($this->cats[$id_categ][
'fullpath'],
'_');
1519 $this->cats[$id_categ][
'level'] = ($nbunderscore ? $nbunderscore :
null);
1536 if (!is_numeric($type) && !is_null($type)) {
1537 $type = $this->MAP_ID[$type];
1540 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"categorie";
1541 $sql .=
" WHERE entity IN (".getEntity(
'category').
")";
1542 if (!is_null($type)) {
1543 $sql .=
" AND type = ".(int) $type;
1546 $sql .=
" AND fk_parent = 0";
1549 $res = $this->db->query($sql);
1552 while ($rec = $this->db->fetch_array($res)) {
1554 $cat->fetch($rec[
'rowid']);
1555 $cats[$rec[
'rowid']] = $cat;
1586 $type = $this->type;
1588 if (!is_numeric($type)) {
1589 $type = $this->MAP_ID[$type];
1595 $sql =
"SELECT c.rowid";
1596 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie as c ";
1597 $sql .=
" WHERE c.entity IN (".getEntity(
'category').
")";
1598 $sql .=
" AND c.type = ".((int) $type);
1599 $sql .=
" AND c.fk_parent = ".((int) $this->fk_parent);
1600 $sql .=
" AND c.label = '".$this->db->escape($this->label).
"'";
1602 dol_syslog(get_class($this).
"::already_exists", LOG_DEBUG);
1604 $resql = $this->db->query($sql);
1606 if ($this->db->num_rows($resql) > 0) {
1607 $obj = $this->db->fetch_object($resql);
1612 if (!empty($obj) && $obj->rowid > 0 && $obj->rowid != $this->id) {
1613 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);
1617 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);
1620 $this->error = $this->db->error();
1638 public function print_all_ways($sep =
'auto', $url =
'', $nocolor = 0, $addpicto = 0, $notrunc = 0)
1643 if ($sep ==
'auto') {
1649 foreach ($all_ways as $way) {
1653 foreach ($way as $cat) {
1656 if (empty($nocolor)) {
1657 $forced_color =
'colortoreplace';
1658 if ($i == count($way)) {
1660 $forced_color =
'categtextwhite';
1662 $forced_color =
'categtextblack';
1668 if (($i < count($way) && empty($notrunc)) && $i > 1) {
1672 $link =
'<a href="'.DOL_URL_ROOT.
'/categories/viewcat.php?id='.((int) $cat->id).
'&type='.urlencode($cat->type).
'" class="'.(($i < count($way) && empty($notrunc)) ?
'small ' :
'').$forced_color.
'">';
1675 $s = $link.(($addpicto && $i == 1) ?
img_object(
'',
'category',
'class="paddingright"') :
'');
1676 $s .= (($i < count($way) && empty($notrunc)) ? ($i == 1 ?
dol_trunc($cat->label, 3) :
'') : $cat->label);
1679 } elseif ($url ==
'none') {
1680 if (($i < count($way) && empty($notrunc)) && $i > 1) {
1684 $link =
'<span class="valignmiddle '.($i < count($way) ?
'small ' :
'').$forced_color.
'">';
1685 $linkend =
'</span>';
1687 $s = $link.(($addpicto && $i == 1) ?
img_object(
'',
'category',
'class="paddingright"') :
'');
1688 $s .= (($i < count($way) && empty($notrunc)) ? ($i == 1 ?
dol_trunc($cat->label, 3) :
'') : $cat->label);
1692 $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>';
1695 $newcategwithpath = preg_replace(
'/colortoreplace/', $forced_color, implode(
'<span class="inline-block valignmiddle paddingleft paddingright small '.$forced_color.
'">'.$sep.
'</span>', $w));
1697 $ways[] = $newcategwithpath;
1716 $sql =
"SELECT fk_parent FROM ".MAIN_DB_PREFIX.
"categorie";
1717 $sql .=
" WHERE rowid = ".((int) $this->
id);
1719 $res = $this->db->query($sql);
1722 while ($rec = $this->db->fetch_array($res)) {
1723 if ($rec[
'fk_parent'] > 0) {
1725 $cat->fetch($rec[
'fk_parent']);
1749 if (is_array($parents)) {
1750 foreach ($parents as $parent) {
1751 $all_ways = $parent->get_all_ways();
1752 foreach ($all_ways as $way) {
1760 if (count($ways) == 0) {
1761 $ways[0][0] = $this;
1781 if (is_numeric($type)) {
1782 $type = array_search($type, $this->MAP_ID);
1785 if ($type === Categorie::TYPE_BANK_LINE) {
1787 $sql =
"SELECT c.label, c.rowid";
1788 $sql .=
" FROM ".MAIN_DB_PREFIX.
"category_bankline as a, ".MAIN_DB_PREFIX.
"categorie as c";
1789 $sql .=
" WHERE a.lineid=".((int) $id).
" AND a.fk_categ = c.rowid";
1790 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
1791 $sql .=
" ORDER BY c.label";
1793 $res = $this->db->query($sql);
1795 while ($obj = $this->db->fetch_object($res)) {
1796 if ($mode ==
'id') {
1797 $cats[] = $obj->rowid;
1798 } elseif ($mode ==
'label') {
1799 $cats[] = $obj->label;
1802 $cat->id = $obj->rowid;
1803 $cat->label = $obj->label;
1812 $sql =
"SELECT ct.fk_categorie, c.label, c.rowid";
1813 $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";
1814 $sql .=
" WHERE ct.fk_categorie = c.rowid AND ct.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).
" = ".(
int) $id;
1818 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
1820 $res = $this->db->query($sql);
1822 while ($obj = $this->db->fetch_object($res)) {
1823 if ($mode ==
'id') {
1824 $cats[] = $obj->rowid;
1825 } elseif ($mode ==
'label') {
1826 $cats[] = $obj->label;
1829 $cat->fetch($obj->fk_categorie);
1853 public function rechercher($id, $nom, $type, $exact =
false, $case =
false)
1856 if (is_numeric($type)) {
1857 dol_syslog(__METHOD__.
': using numeric types is deprecated.', LOG_WARNING);
1863 if (is_numeric($type)) {
1865 $map_type = array_flip($this->MAP_ID);
1866 $type = $map_type[$type];
1867 dol_syslog(get_class($this).
"::rechercher(): numeric types are deprecated, please use string instead", LOG_WARNING);
1871 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"categorie";
1872 $sql .=
" WHERE type = ".((int) $this->MAP_ID[$type]);
1873 $sql .=
" AND entity IN (".getEntity(
'category').
")";
1876 $nom =
'%'.$this->db->escape(str_replace(
'*',
'%', $nom)).
'%';
1879 $sql .=
" AND label LIKE '".$this->db->escape($nom).
"'";
1881 $sql .=
" AND label LIKE BINARY '".$this->db->escape($nom).
"'";
1885 $sql .=
" AND rowid = ".((int) $id);
1888 $res = $this->db->query($sql);
1890 while ($rec = $this->db->fetch_array($res)) {
1892 $cat->fetch($rec[
'rowid']);
1898 $this->error = $this->db->error().
' sql='.$sql;
1911 include_once DOL_DOCUMENT_ROOT .
'/core/lib/files.lib.php';
1912 include_once DOL_DOCUMENT_ROOT .
'/core/lib/images.lib.php';
1914 $sdir .=
'/' .
get_exdir($this->
id, 2, 0, 0, $this,
'category') . $this->
id .
"/photos/";
1917 if (file_exists($dir_osencoded)) {
1918 $handle = opendir($dir_osencoded);
1919 if (is_resource($handle)) {
1920 while (($file = readdir($handle)) !==
false) {
1922 $file = mb_convert_encoding($file,
'UTF-8',
'ISO-8859-1');
1943 $langs->load(
'categories');
1947 $datas[
'label'] = $langs->trans(
"ShowCategory").
': '.($this->
ref ? $this->
ref : $this->label);
1965 public function getNomUrl($withpicto = 0, $option =
'', $maxlength = 0, $moreparam =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = 0)
1967 global
$conf, $langs, $hookmanager;
1969 if (!empty(
$conf->dol_no_mouse_hover)) {
1976 'objecttype' => $this->element,
1977 'option' => $option,
1979 $classfortooltip =
'classfortooltip';
1982 $classfortooltip =
'classforajaxtooltip';
1983 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1989 $url = DOL_URL_ROOT.
'/categories/viewcat.php?id='.$this->
id.
'&type='.$this->
type.$moreparam.
'&backtopage='.urlencode($_SERVER[
'PHP_SELF'].($moreparam ?
'?'.$moreparam :
''));
1991 if ($option !==
'nolink') {
1993 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1994 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1995 $add_save_lastsearch_values = 1;
1997 if ( $add_save_lastsearch_values) {
1998 $url .=
'&save_lastsearch_values=1';
2003 $forced_color =
'categtextwhite';
2006 $forced_color =
'categtextblack';
2011 if (empty($notooltip)) {
2013 $label = $langs->trans(
"ShowCategory");
2014 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
2016 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
2017 $linkclose .= $dataparams.
' class="'.$classfortooltip.
' '.$forced_color.($morecss ?
' '.$morecss :
'').
'"';
2019 $linkclose =
' class="'.$forced_color.($morecss ?
' '.$morecss :
'').
'"';
2022 if ($option ==
'nolink' ) {
2023 $linkstart =
'<span';
2025 $linkstart =
'<a href="'.$url.
'"';
2027 $linkstart .= $linkclose.
'>';
2028 if ($option ==
'nolink' ) {
2029 $linkend =
'</span>';
2034 $result .= $linkstart;
2037 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"'), 0, 0, $notooltip ? 0 : 1);
2040 if ($withpicto != 2) {
2041 $result .=
dol_trunc(($this->
ref ? $this->
ref : $this->label), $maxlength);
2044 $result .= $linkend;
2047 $hookmanager->initHooks(array($this->element .
'dao'));
2048 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
2049 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2051 $result = $hookmanager->resPrint;
2053 $result .= $hookmanager->resPrint;
2070 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2072 $dir = $sdir.
'/'.
get_exdir($this->
id, 2, 0, 0, $this,
'category').$this->id.
"/";
2075 if (!file_exists($dir)) {
2079 if (file_exists($dir)) {
2080 if (is_array($file[
'name'])) {
2081 $nbfile = count($file[
'name']);
2082 for ($i = 0; $i < $nbfile; $i++) {
2083 $originImage = $dir.$file[
'name'][$i];
2088 if (file_exists($originImage)) {
2094 $originImage = $dir.$file[
'name'];
2099 if (file_exists($originImage)) {
2118 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2123 $dirthumb = $dir.
'thumbs/';
2125 if (file_exists($dir)) {
2126 $handle = opendir($dir);
2127 if (is_resource($handle)) {
2128 while (($file = readdir($handle)) !==
false) {
2129 if (
dol_is_file($dir.$file) && preg_match(
'/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $dir.$file)) {
2134 $photo_vignette =
'';
2136 if (preg_match(
'/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $photo, $regs)) {
2137 $photo_vignette = preg_replace(
'/'.$regs[0].
'/i',
'', $photo).
'_small'.$regs[0];
2142 $obj[
'photo'] = $photo;
2143 if ($photo_vignette && is_file($dirthumb.$photo_vignette)) {
2144 $obj[
'photo_vignette'] =
'thumbs/'.$photo_vignette;
2146 $obj[
'photo_vignette'] =
"";
2149 $tabobj[$nbphoto - 1] = $obj;
2152 if ($nbmax && $nbphoto >= $nbmax) {
2175 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2177 $dir = dirname($file).
'/';
2178 $dirthumb = $dir.
'/thumbs/';
2179 $filename = preg_replace(
'/'.preg_quote($dir,
'/').
'/i',
'', $file);
2186 if (preg_match(
'/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $filename, $regs)) {
2187 $photo_vignette = preg_replace(
'/'.$regs[0].
'/i',
'', $filename).
'_small'.$regs[0];
2188 if (file_exists($dirthumb.$photo_vignette)) {
2204 $infoImg = getimagesize($file);
2205 $this->imgWidth = $infoImg[0];
2206 $this->imgHeight = $infoImg[1];
2221 $langs_available = $langs->get_available_languages();
2222 $current_lang = $langs->getDefaultLang();
2224 foreach ($langs_available as $key => $value) {
2225 $sql =
"SELECT rowid";
2226 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_lang";
2227 $sql .=
" WHERE fk_category=".((int) $this->
id);
2228 $sql .=
" AND lang = '".$this->db->escape($key).
"'";
2230 $result = $this->db->query($sql);
2232 if ($key == $current_lang) {
2234 if ($this->db->num_rows($result)) {
2235 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"categorie_lang";
2236 $sql2 .=
" SET label = '".$this->db->escape($this->label).
"',";
2237 $sql2 .=
" description = '".$this->db->escape($this->
description).
"'";
2238 $sql2 .=
" WHERE fk_category = ".((int) $this->
id).
" AND lang = '".$this->db->escape($key).
"'";
2240 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_lang (fk_category, lang, label, description)";
2241 $sql2 .=
" VALUES(".((int) $this->
id).
", '".$this->db->escape($key).
"', '".$this->db->escape($this->label).
"'";
2242 $sql2 .=
", '".$this->db->escape($this->
description).
"')";
2244 dol_syslog(get_class($this).
'::setMultiLangs', LOG_DEBUG);
2245 if (!$this->db->query($sql2)) {
2246 $this->error = $this->db->lasterror();
2249 $this->multilangs[$key][
"label"] = $this->label;
2250 $this->multilangs[$key][
"description"] = $this->description;
2251 } elseif (isset($this->multilangs[$key])) {
2252 if ($this->db->num_rows($result)) {
2253 $sql2 =
"UPDATE ".MAIN_DB_PREFIX.
"categorie_lang";
2254 $sql2 .=
" SET label='".$this->db->escape($this->multilangs[$key][
"label"]).
"',";
2255 $sql2 .=
" description='".$this->db->escape($this->multilangs[$key][
"description"]).
"'";
2256 $sql2 .=
" WHERE fk_category=".((int) $this->
id).
" AND lang='".$this->db->escape($key).
"'";
2258 $sql2 =
"INSERT INTO ".MAIN_DB_PREFIX.
"categorie_lang (fk_category, lang, label, description)";
2259 $sql2 .=
" VALUES(".((int) $this->
id).
", '".$this->db->escape($key).
"', '".$this->db->escape($this->multilangs[$key][
"label"]).
"'";
2260 $sql2 .=
",'".$this->db->escape($this->multilangs[$key][
"description"]).
"')";
2264 if ($this->multilangs[$key][
"label"] || $this->multilangs[$key][
"description"]) {
2265 dol_syslog(get_class($this).
'::setMultiLangs', LOG_DEBUG);
2267 if (!$this->db->query($sql2)) {
2268 $this->error = $this->db->lasterror();
2276 $result = $this->call_trigger(
'CATEGORY_SET_MULTILANGS', $user);
2278 $this->error = $this->db->lasterror();
2298 $sql =
"DELETE FROM ".$this->db->prefix().
"categorie_lang";
2299 $sql .=
" WHERE fk_category = ".((int) $this->
id).
" AND lang = '".$this->db->escape($langtodelete).
"'";
2301 dol_syslog(get_class($this).
'::delMultiLangs', LOG_DEBUG);
2302 $result = $this->db->query($sql);
2304 if (empty($notrigger)) {
2306 $result = $this->call_trigger(
'CATEGORY_DEL_MULTILANGS', $user);
2308 $this->error = $this->db->lasterror();
2309 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
2316 $this->error = $this->db->lasterror();
2317 dol_syslog(get_class($this).
'::delMultiLangs error='.$this->error, LOG_ERR);
2331 $current_lang = $langs->getDefaultLang();
2333 $sql =
"SELECT lang, label, description";
2334 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_lang";
2335 $sql .=
" WHERE fk_category=".((int) $this->
id);
2337 $result = $this->db->query($sql);
2339 while ($obj = $this->db->fetch_object($result)) {
2341 if ($obj->lang == $current_lang) {
2342 $this->label = $obj->label;
2345 $this->multilangs[$obj->lang][
"label"] = $obj->label;
2346 $this->multilangs[$obj->lang][
"description"] = $obj->description;
2350 $this->error = $langs->trans(
"Error").
" : ".$this->db->error().
" - ".$sql;
2376 dol_syslog(get_class($this).
"::initAsSpecimen");
2380 $this->fk_parent = 0;
2381 $this->label =
'SPECIMEN';
2382 $this->specimen = 1;
2385 $this->
type = self::TYPE_PRODUCT;
2417 if ($type ==
'bank_account') {
2421 return " LEFT JOIN ".MAIN_DB_PREFIX.
"categorie_".$type.
" as cp ON ".$rowIdName.
" = cp.fk_".$type;
2435 if ($type ==
'bank_account') {
2438 if ($type ==
'customer') {
2441 if ($type ==
'supplier') {
2442 $type =
'fournisseur';
2445 if (empty($searchList) && !is_array($searchList)) {
2449 $searchCategorySqlList = array();
2450 foreach ($searchList as $searchCategory) {
2451 if (intval($searchCategory) == -2) {
2452 $searchCategorySqlList[] =
" cp.fk_categorie IS NULL";
2453 } elseif (intval($searchCategory) > 0) {
2454 $searchCategorySqlList[] =
" ".$rowIdName.
" IN (SELECT fk_".$type.
" FROM ".MAIN_DB_PREFIX.
"categorie_".$type.
" WHERE fk_categorie = ".((int) $searchCategory).
")";
2458 if (!empty($searchCategorySqlList)) {
2459 return " AND (".implode(
' AND ', $searchCategorySqlList).
")";
2472 dol_syslog(get_class($this).
"::count_all_categories", LOG_DEBUG);
2473 $sql =
"SELECT COUNT(rowid) FROM ".MAIN_DB_PREFIX.
"categorie";
2474 $sql .=
" WHERE entity IN (".getEntity(
'category').
")";
2476 $res = $this->db->query($sql);
2478 $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.
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)
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.
print_all_ways($sep='auto', $url='', $nocolor=0, $addpicto=0, $notrunc=0)
Returns the path of the category, with the names of the categories separated by $sep (" >> " by defau...
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.
delMultiLangs($langtodelete, $user, $notrigger=0)
Delete a language for this category.
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.
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_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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)
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...
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
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.
isModEnabled($module)
Is Dolibarr module enabled.
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.
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
if(preg_match('/(crypted|dolcrypt):/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...