dolibarr  16.0.5
categorie.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2005 Matthieu Valleton <mv@seeschloss.org>
3  * Copyright (C) 2005 Davoleau Brice <brice.davoleau@gmail.com>
4  * Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
5  * Copyright (C) 2006-2012 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
7  * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
8  * Copyright (C) 2013-2016 Juanjo Menent <jmenent@2byte.es>
9  * Copyright (C) 2013-2018 Philippe Grand <philippe.grand@atoo-net.com>
10  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
11  * Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
12  * Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
13  * Copyright (C) 2018-2022 Frédéric France <frederic.france@netlogic.fr>
14  * Copyright (C) 2023 Benjamin Falière <benjamin.faliere@altairis.fr>
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program. If not, see <https://www.gnu.org/licenses/>.
28  */
29 
36 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/knowledgemanagement/class/knowledgerecord.class.php';
42 
43 
47 class Categorie extends CommonObject
48 {
49  // Categories types (we use string because we want to accept any modules/types in a future)
50  const TYPE_PRODUCT = 'product';
51  const TYPE_SUPPLIER = 'supplier';
52  const TYPE_CUSTOMER = 'customer';
53  const TYPE_MEMBER = 'member';
54  const TYPE_CONTACT = 'contact';
55  const TYPE_USER = 'user';
56  const TYPE_PROJECT = 'project';
57  const TYPE_ACCOUNT = 'bank_account';
58  const TYPE_BANK_LINE = 'bank_line';
59  const TYPE_WAREHOUSE = 'warehouse';
60  const TYPE_ACTIONCOMM = 'actioncomm';
61  const TYPE_WEBSITE_PAGE = 'website_page';
62  const TYPE_TICKET = 'ticket';
63  const TYPE_KNOWLEDGEMANAGEMENT = 'knowledgemanagement';
64 
68  public $picto = 'category';
69 
70 
74  protected $MAP_ID = array(
75  'product' => 0,
76  'supplier' => 1,
77  'customer' => 2,
78  'member' => 3,
79  'contact' => 4,
80  'bank_account' => 5,
81  'project' => 6,
82  'user' => 7,
83  'bank_line' => 8,
84  'warehouse' => 9,
85  'actioncomm' => 10,
86  'website_page' => 11,
87  'ticket' => 12,
88  'knowledgemanagement' => 13
89  );
90 
96  public static $MAP_ID_TO_CODE = array(
97  0 => 'product',
98  1 => 'supplier',
99  2 => 'customer',
100  3 => 'member',
101  4 => 'contact',
102  5 => 'bank_account',
103  6 => 'project',
104  7 => 'user',
105  8 => 'bank_line',
106  9 => 'warehouse',
107  10 => 'actioncomm',
108  11 => 'website_page',
109  12 => 'ticket',
110  13 => 'knowledgemanagement'
111  );
112 
118  public $MAP_CAT_FK = array(
119  'customer' => 'soc',
120  'supplier' => 'soc',
121  'contact' => 'socpeople',
122  'bank_account' => 'account',
123  );
124 
130  public $MAP_CAT_TABLE = array(
131  'customer' => 'societe',
132  'supplier' => 'fournisseur',
133  'bank_account'=> 'account',
134  );
135 
141  public $MAP_OBJ_CLASS = array(
142  'product' => 'Product',
143  'customer' => 'Societe',
144  'supplier' => 'Fournisseur',
145  'member' => 'Adherent',
146  'contact' => 'Contact',
147  'user' => 'User',
148  'account' => 'Account', // old for bank account
149  'bank_account' => 'Account',
150  'project' => 'Project',
151  'warehouse'=> 'Entrepot',
152  'actioncomm' => 'ActionComm',
153  'website_page' => 'WebsitePage',
154  'ticket' => 'Ticket',
155  'knowledgemanagement' => 'KnowledgeRecord'
156  );
157 
163  public static $MAP_TYPE_TITLE_AREA = array(
164  'product' => 'ProductsCategoriesArea',
165  'customer' => 'CustomersCategoriesArea',
166  'supplier' => 'SuppliersCategoriesArea',
167  'member' => 'MembersCategoriesArea',
168  'contact' => 'ContactsCategoriesArea',
169  'user' => 'UsersCategoriesArea',
170  'account' => 'AccountsCategoriesArea', // old for bank account
171  'bank_account' => 'AccountsCategoriesArea',
172  'project' => 'ProjectsCategoriesArea',
173  'warehouse'=> 'StocksCategoriesArea',
174  'actioncomm' => 'ActioncommCategoriesArea',
175  'website_page' => 'WebsitePageCategoriesArea'
176  );
177 
182  public $MAP_OBJ_TABLE = array(
183  'customer' => 'societe',
184  'supplier' => 'societe',
185  'member' => 'adherent',
186  'contact' => 'socpeople',
187  'account' => 'bank_account', // old for bank account
188  'project' => 'projet',
189  'warehouse'=> 'entrepot',
190  'knowledgemanagement' => 'knowledgemanagement_knowledgerecord'
191  );
192 
196  public $element = 'category';
197 
201  public $table_element = 'categorie';
202 
206  public $fk_parent;
207 
211  public $label;
212 
216  public $description;
217 
221  public $color;
222 
226  public $visible;
227 
231  public $socid;
232 
250  public $type;
251 
255  public $cats = array();
256 
260  public $motherof = array();
261 
265  public $childs = array();
266 
267 
273  public function __construct($db)
274  {
275  global $hookmanager;
276 
277  $this->db = $db;
278 
279  if (is_object($hookmanager)) {
280  $hookmanager->initHooks(array('category'));
281  $parameters = array();
282  $reshook = $hookmanager->executeHooks('constructCategory', $parameters, $this); // Note that $action and $object may have been modified by some hooks
283  if ($reshook >= 0 && !empty($hookmanager->resArray)) {
284  foreach ($hookmanager->resArray as $mapList) {
285  $mapId = $mapList['id'];
286  $mapCode = $mapList['code'];
287  self::$MAP_ID_TO_CODE[$mapId] = $mapCode;
288  $this->MAP_ID[$mapCode] = $mapId;
289  $this->MAP_CAT_FK[$mapCode] = $mapList['cat_fk'];
290  $this->MAP_CAT_TABLE[$mapCode] = $mapList['cat_table'];
291  $this->MAP_OBJ_CLASS[$mapCode] = $mapList['obj_class'];
292  $this->MAP_OBJ_TABLE[$mapCode] = $mapList['obj_table'];
293  }
294  }
295  }
296  }
297 
303  public function getMapList()
304  {
305  $mapList = array();
306 
307  foreach ($this->MAP_ID as $mapCode => $mapId) {
308  $mapList[] = array(
309  'id' => $mapId,
310  'code' => $mapCode,
311  'cat_fk' => (empty($this->MAP_CAT_FK[$mapCode]) ? $mapCode : $this->MAP_CAT_FK[$mapCode]),
312  'cat_table' => (empty($this->MAP_CAT_TABLE[$mapCode]) ? $mapCode : $this->MAP_CAT_TABLE[$mapCode]),
313  'obj_class' => (empty($this->MAP_OBJ_CLASS[$mapCode]) ? $mapCode : $this->MAP_OBJ_CLASS[$mapCode]),
314  'obj_table' => (empty($this->MAP_OBJ_TABLE[$mapCode]) ? $mapCode : $this->MAP_OBJ_TABLE[$mapCode])
315  );
316  }
317 
318  return $mapList;
319  }
320 
330  public function fetch($id, $label = '', $type = null, $ref_ext = '')
331  {
332  global $conf;
333 
334  // Check parameters
335  if (empty($id) && empty($label) && empty($ref_ext)) {
336  $this->error = "No category to search for";
337  return -1;
338  }
339  if (!is_null($type) && !is_numeric($type)) {
340  $type = $this->MAP_ID[$type];
341  }
342 
343  $sql = "SELECT rowid, fk_parent, entity, label, description, color, fk_soc, visible, type, ref_ext";
344  $sql .= ", date_creation, tms, fk_user_creat, fk_user_modif";
345  $sql .= " FROM ".MAIN_DB_PREFIX."categorie";
346  if ($id) {
347  $sql .= " WHERE rowid = ".((int) $id);
348  } elseif (!empty($ref_ext)) {
349  $sql .= " WHERE ref_ext LIKE '".$this->db->escape($ref_ext)."'";
350  } else {
351  $sql .= " WHERE label = '".$this->db->escape($label)."' AND entity IN (".getEntity('category').")";
352  if (!is_null($type)) {
353  $sql .= " AND type = ".((int) $type);
354  }
355  }
356 
357  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
358  $resql = $this->db->query($sql);
359  if ($resql) {
360  if ($this->db->num_rows($resql) > 0) {
361  $res = $this->db->fetch_array($resql);
362 
363  $this->id = $res['rowid'];
364  //$this->ref = $res['rowid'];
365  $this->fk_parent = (int) $res['fk_parent'];
366  $this->label = $res['label'];
367  $this->description = $res['description'];
368  $this->color = $res['color'];
369  $this->socid = (int) $res['fk_soc'];
370  $this->visible = (int) $res['visible'];
371  $this->type = (int) $res['type'];
372  $this->ref_ext = $res['ref_ext'];
373  $this->entity = (int) $res['entity'];
374  $this->date_creation = $this->db->jdate($res['date_creation']);
375  $this->date_modification = $this->db->jdate($res['tms']);
376  $this->user_creation_id = (int) $res['fk_user_creat'];
377  $this->user_modification_id = (int) $res['fk_user_modif'];
378  $this->user_creation = (int) $res['fk_user_creat'];
379  $this->user_modification = (int) $res['fk_user_modif'];
380 
381  // Retrieve all extrafield
382  // fetch optionals attributes and labels
383  $this->fetch_optionals();
384 
385  $this->db->free($resql);
386 
387  // multilangs
388  if (!empty($conf->global->MAIN_MULTILANGS)) {
389  $this->getMultiLangs();
390  }
391 
392  return 1;
393  } else {
394  $this->error = "No category found";
395  return 0;
396  }
397  } else {
398  dol_print_error($this->db);
399  $this->error = $this->db->lasterror;
400  $this->errors[] = $this->db->lasterror;
401  return -1;
402  }
403  }
404 
414  public function create($user)
415  {
416  global $conf, $langs, $hookmanager;
417  $langs->load('categories');
418 
419  $type = $this->type;
420 
421  if (!is_numeric($type)) {
422  $type = $this->MAP_ID[$type];
423  }
424 
425  $error = 0;
426 
427  dol_syslog(get_class($this).'::create', LOG_DEBUG);
428 
429  // Clean parameters
430  $this->label = trim($this->label);
431  $this->description = trim($this->description);
432  $this->color = trim($this->color);
433  $this->import_key = trim($this->import_key);
434  $this->ref_ext = trim($this->ref_ext);
435  if (empty($this->visible)) {
436  $this->visible = 0;
437  }
438  $this->fk_parent = ($this->fk_parent != "" ? intval($this->fk_parent) : 0);
439 
440  if ($this->already_exists()) {
441  $this->error = $langs->trans("ImpossibleAddCat", $this->label);
442  $this->error .= " : ".$langs->trans("CategoryExistsAtSameLevel");
443  dol_syslog($this->error, LOG_WARNING);
444  return -4;
445  }
446 
447  $this->db->begin();
448  $now = dol_now();
449  $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (";
450  $sql .= "fk_parent,";
451  $sql .= " label,";
452  $sql .= " description,";
453  $sql .= " color,";
454  if (!empty($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)) {
455  $sql .= "fk_soc,";
456  }
457  $sql .= " visible,";
458  $sql .= " type,";
459  $sql .= " import_key,";
460  $sql .= " ref_ext,";
461  $sql .= " entity,";
462  $sql .= " date_creation,";
463  $sql .= " fk_user_creat";
464  $sql .= ") VALUES (";
465  $sql .= (int) $this->fk_parent.",";
466  $sql .= "'".$this->db->escape($this->label)."', ";
467  $sql .= "'".$this->db->escape($this->description)."', ";
468  $sql .= "'".$this->db->escape($this->color)."', ";
469  if (!empty($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)) {
470  $sql .= ($this->socid > 0 ? $this->socid : 'null').", ";
471  }
472  $sql .= "'".$this->db->escape($this->visible)."', ";
473  $sql .= ((int) $type).", ";
474  $sql .= (!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : 'null').", ";
475  $sql .= (!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : 'null').", ";
476  $sql .= (int) $conf->entity.", ";
477  $sql .= "'".$this->db->idate($now)."', ";
478  $sql .= (int) $user->id;
479  $sql .= ")";
480 
481  $res = $this->db->query($sql);
482  if ($res) {
483  $id = $this->db->last_insert_id(MAIN_DB_PREFIX."categorie");
484 
485  if ($id > 0) {
486  $this->id = $id;
487 
488  $action = 'create';
489 
490  // Actions on extra fields
491  if (!$error) {
492  $result = $this->insertExtraFields();
493  if ($result < 0) {
494  $error++;
495  }
496  }
497 
498  if (!$error) {
499  // Call trigger
500  $result = $this->call_trigger('CATEGORY_CREATE', $user);
501  if ($result < 0) {
502  $error++;
503  }
504  // End call triggers
505  }
506 
507  if (!$error) {
508  $this->db->commit();
509  return $id;
510  } else {
511  $this->db->rollback();
512  return -3;
513  }
514  } else {
515  $this->db->rollback();
516  return -2;
517  }
518  } else {
519  $this->error = $this->db->error();
520  $this->db->rollback();
521  return -1;
522  }
523  }
524 
533  public function update(User $user)
534  {
535  global $conf, $langs, $hookmanager;
536 
537  $error = 0;
538 
539  // Clean parameters
540  $this->label = trim($this->label);
541  $this->description = trim($this->description);
542  $this->ref_ext = trim($this->ref_ext);
543  $this->fk_parent = ($this->fk_parent != "" ? intval($this->fk_parent) : 0);
544  $this->visible = ($this->visible != "" ? intval($this->visible) : 0);
545 
546  if ($this->already_exists()) {
547  $this->error = $langs->trans("ImpossibleUpdateCat");
548  $this->error .= " : ".$langs->trans("CategoryExistsAtSameLevel");
549  return -1;
550  }
551 
552  $this->db->begin();
553 
554  $sql = "UPDATE ".MAIN_DB_PREFIX."categorie";
555  $sql .= " SET label = '".$this->db->escape($this->label)."',";
556  $sql .= " description = '".$this->db->escape($this->description)."',";
557  $sql .= " ref_ext = '".$this->db->escape($this->ref_ext)."',";
558  $sql .= " color = '".$this->db->escape($this->color)."'";
559  if (!empty($conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)) {
560  $sql .= ", fk_soc = ".($this->socid > 0 ? $this->socid : 'null');
561  }
562  $sql .= ", visible = ".(int) $this->visible;
563  $sql .= ", fk_parent = ".(int) $this->fk_parent;
564  $sql .= ", fk_user_modif = ".(int) $user->id;
565  $sql .= " WHERE rowid = ".((int) $this->id);
566 
567  dol_syslog(get_class($this)."::update", LOG_DEBUG);
568  if ($this->db->query($sql)) {
569  $action = 'update';
570 
571  // Actions on extra fields
572  if (!$error) {
573  $result = $this->insertExtraFields();
574  if ($result < 0) {
575  $error++;
576  }
577  }
578 
579  if (!$error) {
580  // Call trigger
581  $result = $this->call_trigger('CATEGORY_MODIFY', $user);
582  if ($result < 0) {
583  $error++; $this->db->rollback(); return -1;
584  }
585  // End call triggers
586  }
587 
588  $this->db->commit();
589 
590  return 1;
591  } else {
592  $this->db->rollback();
593  dol_print_error($this->db);
594  return -1;
595  }
596  }
597 
605  public function delete($user, $notrigger = 0)
606  {
607  global $conf, $langs;
608 
609  $error = 0;
610 
611  // Clean parameters
612  $this->fk_parent = ($this->fk_parent != "" ? intval($this->fk_parent) : 0);
613 
614  dol_syslog(get_class($this)."::remove");
615 
616  $this->db->begin();
617 
618  if (!$error && !$notrigger) {
619  // Call trigger
620  $result = $this->call_trigger('CATEGORY_DELETE', $user);
621  if ($result < 0) {
622  $error++;
623  }
624  // End call triggers
625  }
626 
627  /* FIX #1317 : Check for child category and move up 1 level*/
628  if (!$error) {
629  $sql = "UPDATE ".MAIN_DB_PREFIX."categorie";
630  $sql .= " SET fk_parent = ".((int) $this->fk_parent);
631  $sql .= " WHERE fk_parent = ".((int) $this->id);
632 
633  if (!$this->db->query($sql)) {
634  $this->error = $this->db->lasterror();
635  $error++;
636  }
637  }
638 
639  $arraydelete = array(
640  'categorie_account' => 'fk_categorie',
641  'categorie_actioncomm' => 'fk_categorie',
642  'categorie_contact' => 'fk_categorie',
643  'categorie_fournisseur' => 'fk_categorie',
644  'categorie_knowledgemanagement' => array('field' => 'fk_categorie', 'enabled' => isModEnabled('knowledgemanagement')),
645  'categorie_member' => 'fk_categorie',
646  'categorie_user' => 'fk_categorie',
647  'categorie_product' => 'fk_categorie',
648  'categorie_project' => 'fk_categorie',
649  'categorie_societe' => 'fk_categorie',
650  'categorie_ticket' => array('field' => 'fk_categorie', 'enabled' => isModEnabled('ticket')),
651  'categorie_warehouse' => 'fk_categorie',
652  'categorie_website_page' => array('field' => 'fk_categorie', 'enabled' => isModEnabled('website')),
653  'bank_class' => 'fk_categ',
654  'categorie_lang' => 'fk_category',
655  'categorie' => 'rowid',
656  );
657  foreach ($arraydelete as $key => $value) {
658  if (is_array($value)) {
659  if (empty($value['enabled'])) {
660  continue;
661  }
662  $value = $value['field'];
663  }
664  $sql = "DELETE FROM ".MAIN_DB_PREFIX.$key;
665  $sql .= " WHERE ".$value." = ".((int) $this->id);
666  if (!$this->db->query($sql)) {
667  $this->errors[] = $this->db->lasterror();
668  dol_syslog("Error sql=".$sql." ".$this->error, LOG_ERR);
669  $error++;
670  }
671  }
672 
673  // Removed extrafields
674  if (!$error) {
675  $result = $this->deleteExtraFields();
676  if ($result < 0) {
677  $error++;
678  dol_syslog(get_class($this)."::delete erreur ".$this->error, LOG_ERR);
679  }
680  }
681 
682  if (!$error) {
683  $this->db->commit();
684  return 1;
685  } else {
686  $this->db->rollback();
687  return -1;
688  }
689  }
690 
691  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
699  public function add_type($obj, $type = '')
700  {
701  // phpcs:enable
702  global $user, $langs, $conf;
703 
704  $error = 0;
705 
706  if ($this->id == -1) {
707  return -2;
708  }
709 
710  if (empty($type)) {
711  $type = $obj->element;
712  }
713 
714  $this->db->begin();
715 
716  $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
717  $sql .= " (fk_categorie, fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]).")";
718  $sql .= " VALUES (".((int) $this->id).", ".((int) $obj->id).")";
719 
720  dol_syslog(get_class($this).'::add_type', LOG_DEBUG);
721  if ($this->db->query($sql)) {
722  if (!empty($conf->global->CATEGORIE_RECURSIV_ADD)) {
723  $sql = 'SELECT fk_parent FROM '.MAIN_DB_PREFIX.'categorie';
724  $sql .= " WHERE rowid = ".((int) $this->id);
725 
726  dol_syslog(get_class($this)."::add_type", LOG_DEBUG);
727  $resql = $this->db->query($sql);
728  if ($resql) {
729  if ($this->db->num_rows($resql) > 0) {
730  $objparent = $this->db->fetch_object($resql);
731 
732  if (!empty($objparent->fk_parent)) {
733  $cat = new Categorie($this->db);
734  $cat->id = $objparent->fk_parent;
735  if (!$cat->containsObject($type, $obj->id)) {
736  $result = $cat->add_type($obj, $type);
737  if ($result < 0) {
738  $this->error = $cat->error;
739  $error++;
740  }
741  }
742  }
743  }
744  } else {
745  $error++;
746  $this->error = $this->db->lasterror();
747  }
748 
749  if ($error) {
750  $this->db->rollback();
751  return -1;
752  }
753  }
754 
755  // Call trigger
756  $this->context = array('linkto'=>$obj); // Save object we want to link category to into category instance to provide information to trigger
757  $result = $this->call_trigger('CATEGORY_LINK', $user);
758  if ($result < 0) {
759  $error++;
760  }
761  // End call triggers
762 
763  if (!$error) {
764  $this->db->commit();
765  return 1;
766  } else {
767  $this->db->rollback();
768  return -2;
769  }
770  } else {
771  $this->db->rollback();
772  if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
773  $this->error = $this->db->lasterrno();
774  return -3;
775  } else {
776  $this->error = $this->db->lasterror();
777  }
778  return -1;
779  }
780  }
781 
782  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
791  public function del_type($obj, $type)
792  {
793  // phpcs:enable
794  global $user, $langs, $conf;
795 
796  $error = 0;
797 
798  // For backward compatibility
799  if ($type == 'societe') {
800  $type = 'customer';
801  dol_syslog(get_class($this)."::del_type(): type 'societe' is deprecated, please use 'customer' instead", LOG_WARNING);
802  } elseif ($type == 'fournisseur') {
803  $type = 'supplier';
804  dol_syslog(get_class($this)."::del_type(): type 'fournisseur' is deprecated, please use 'supplier' instead", LOG_WARNING);
805  }
806 
807  $this->db->begin();
808 
809  $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
810  $sql .= " WHERE fk_categorie = ".((int) $this->id);
811  $sql .= " AND fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])." = ".((int) $obj->id);
812 
813  dol_syslog(get_class($this).'::del_type', LOG_DEBUG);
814  if ($this->db->query($sql)) {
815  // Call trigger
816  $this->context = array('unlinkoff'=>$obj); // Save object we want to link category to into category instance to provide information to trigger
817  $result = $this->call_trigger('CATEGORY_UNLINK', $user);
818  if ($result < 0) {
819  $error++;
820  }
821  // End call triggers
822 
823  if (!$error) {
824  $this->db->commit();
825  return 1;
826  } else {
827  $this->db->rollback();
828  return -2;
829  }
830  } else {
831  $this->db->rollback();
832  $this->error = $this->db->lasterror();
833  return -1;
834  }
835  }
836 
849  public function getObjectsInCateg($type, $onlyids = 0, $limit = 0, $offset = 0, $sortfield = '', $sortorder = 'ASC')
850  {
851  global $user;
852 
853  $objs = array();
854 
855  $classnameforobj = $this->MAP_OBJ_CLASS[$type];
856  $obj = new $classnameforobj($this->db);
857 
858  $sql = "SELECT c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type]);
859  $sql .= " FROM ".MAIN_DB_PREFIX."categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type])." as c";
860  $sql .= ", ".MAIN_DB_PREFIX.(empty($this->MAP_OBJ_TABLE[$type]) ? $type : $this->MAP_OBJ_TABLE[$type])." as o";
861  $sql .= " WHERE o.entity IN (".getEntity($obj->element).")";
862  $sql .= " AND c.fk_categorie = ".((int) $this->id);
863  $sql .= " AND c.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])." = o.rowid";
864  // Protection for external users
865  if (($type == 'customer' || $type == 'supplier') && $user->socid > 0) {
866  $sql .= " AND o.rowid = ".((int) $user->socid);
867  }
868  $sql .= $this->db->order($sortfield, $sortorder);
869  if ($limit > 0 || $offset > 0) {
870  $sql .= $this->db->plimit($limit + 1, $offset);
871  }
872 
873  dol_syslog(get_class($this)."::getObjectsInCateg", LOG_DEBUG);
874  $resql = $this->db->query($sql);
875  if ($resql) {
876  while ($rec = $this->db->fetch_array($resql)) {
877  if ($onlyids) {
878  $objs[] = $rec['fk_'.(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])];
879  } else {
880  $classnameforobj = $this->MAP_OBJ_CLASS[$type];
881 
882  $obj = new $classnameforobj($this->db);
883  $obj->fetch($rec['fk_'.(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])]);
884 
885  $objs[] = $obj;
886  }
887  }
888  return $objs;
889  } else {
890  $this->error = $this->db->error().' sql='.$sql;
891  return -1;
892  }
893  }
894 
903  public function containsObject($type, $object_id)
904  {
905  $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."categorie_".(empty($this->MAP_CAT_TABLE[$type]) ? $type : $this->MAP_CAT_TABLE[$type]);
906  $sql .= " WHERE fk_categorie = ".((int) $this->id)." AND fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])." = ".((int) $object_id);
907  dol_syslog(get_class($this)."::containsObject", LOG_DEBUG);
908  $resql = $this->db->query($sql);
909  if ($resql) {
910  return $this->db->fetch_object($resql)->nb;
911  } else {
912  $this->error = $this->db->error().' sql='.$sql;
913  return -1;
914  }
915  }
916 
928  public function getListForItem($id, $type = 'customer', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0)
929  {
930  global $conf;
931 
932  $categories = array();
933 
934  $type = sanitizeVal($type, 'aZ09');
935 
936  $sub_type = $type;
937  $subcol_name = "fk_".$type;
938  if ($type == "customer") {
939  $sub_type = "societe";
940  $subcol_name = "fk_soc";
941  }
942  if ($type == "supplier") {
943  $sub_type = "fournisseur";
944  $subcol_name = "fk_soc";
945  }
946  if ($type == "contact") {
947  $subcol_name = "fk_socpeople";
948  }
949 
950  $idoftype = array_search($type, self::$MAP_ID_TO_CODE);
951 
952  $sql = "SELECT s.rowid";
953  $sql .= " FROM ".MAIN_DB_PREFIX."categorie as s, ".MAIN_DB_PREFIX."categorie_".$sub_type." as sub";
954  $sql .= ' WHERE s.entity IN ('.getEntity('category').')';
955  $sql .= ' AND s.type='.((int) $idoftype);
956  $sql .= ' AND s.rowid = sub.fk_categorie';
957  $sql .= " AND sub.".$subcol_name." = ".((int) $id);
958 
959  $sql .= $this->db->order($sortfield, $sortorder);
960 
961  $offset = 0;
962  $nbtotalofrecords = '';
963  if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
964  $result = $this->db->query($sql);
965  $nbtotalofrecords = $this->db->num_rows($result);
966  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
967  $page = 0;
968  $offset = 0;
969  }
970  }
971 
972  if ($limit) {
973  if ($page < 0) {
974  $page = 0;
975  }
976  $offset = $limit * $page;
977 
978  $sql .= $this->db->plimit($limit + 1, $offset);
979  }
980 
981  $result = $this->db->query($sql);
982  if ($result) {
983  $i = 0;
984  $num = $this->db->num_rows($result);
985  $min = min($num, ($limit <= 0 ? $num : $limit));
986  while ($i < $min) {
987  $obj = $this->db->fetch_object($result);
988  $category_static = new Categorie($this->db);
989  if ($category_static->fetch($obj->rowid)) {
990  $categories[$i]['id'] = $category_static->id;
991  $categories[$i]['fk_parent'] = $category_static->fk_parent;
992  $categories[$i]['label'] = $category_static->label;
993  $categories[$i]['description'] = $category_static->description;
994  $categories[$i]['color'] = $category_static->color;
995  $categories[$i]['socid'] = $category_static->socid;
996  $categories[$i]['ref_ext'] = $category_static->ref_ext;
997  $categories[$i]['visible'] = $category_static->visible;
998  $categories[$i]['type'] = $category_static->type;
999  $categories[$i]['entity'] = $category_static->entity;
1000  $categories[$i]['array_options'] = $category_static->array_options;
1001 
1002  // multilangs
1003  if (!empty($conf->global->MAIN_MULTILANGS) && isset($category_static->multilangs)) {
1004  $categories[$i]['multilangs'] = $category_static->multilangs;
1005  }
1006  }
1007  $i++;
1008  }
1009  } else {
1010  $this->error = $this->db->lasterror();
1011  return -1;
1012  }
1013  if (!count($categories)) {
1014  return 0;
1015  }
1016 
1017  return $categories;
1018  }
1019 
1020  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1026  public function get_filles()
1027  {
1028  // phpcs:enable
1029  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie";
1030  $sql .= " WHERE fk_parent = ".((int) $this->id);
1031  $sql .= " AND entity IN (".getEntity('category').")";
1032 
1033  $res = $this->db->query($sql);
1034  if ($res) {
1035  $cats = array();
1036  while ($rec = $this->db->fetch_array($res)) {
1037  $cat = new Categorie($this->db);
1038  $cat->fetch($rec['rowid']);
1039  $cats[] = $cat;
1040  }
1041  return $cats;
1042  } else {
1043  dol_print_error($this->db);
1044  return -1;
1045  }
1046  }
1047 
1048  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1054  protected function load_motherof()
1055  {
1056  // phpcs:enable
1057  $this->motherof = array();
1058 
1059  // Load array[child]=parent
1060  $sql = "SELECT fk_parent as id_parent, rowid as id_son";
1061  $sql .= " FROM ".MAIN_DB_PREFIX."categorie";
1062  $sql .= " WHERE fk_parent != 0";
1063  $sql .= " AND entity IN (".getEntity('category').")";
1064 
1065  dol_syslog(get_class($this)."::load_motherof", LOG_DEBUG);
1066  $resql = $this->db->query($sql);
1067  if ($resql) {
1068  while ($obj = $this->db->fetch_object($resql)) {
1069  $this->motherof[$obj->id_son] = $obj->id_parent;
1070  }
1071  return 1;
1072  } else {
1073  dol_print_error($this->db);
1074  return -1;
1075  }
1076  }
1077 
1078  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1098  public function get_full_arbo($type, $markafterid = 0, $include = 0)
1099  {
1100  // phpcs:enable
1101  global $conf, $langs;
1102 
1103  if (!is_numeric($type)) {
1104  $type = $this->MAP_ID[$type];
1105  }
1106  if (is_null($type)) {
1107  $this->error = 'BadValueForParameterType';
1108  return -1;
1109  }
1110 
1111  if (is_string($markafterid)) {
1112  $markafterid = explode(',', $markafterid);
1113  } elseif (is_numeric($markafterid)) {
1114  if ($markafterid > 0) {
1115  $markafterid = array($markafterid);
1116  } else {
1117  $markafterid = array();
1118  }
1119  } elseif (!is_array($markafterid)) {
1120  $markafterid = array();
1121  }
1122 
1123  $this->cats = array();
1124 
1125  // Init this->motherof that is array(id_son=>id_parent, ...)
1126  $this->load_motherof();
1127  $current_lang = $langs->getDefaultLang();
1128 
1129  // Init $this->cats array
1130  $sql = "SELECT DISTINCT c.rowid, c.label, c.ref_ext, c.description, c.color, c.fk_parent, c.visible"; // Distinct reduce pb with old tables with duplicates
1131  if (!empty($conf->global->MAIN_MULTILANGS)) {
1132  $sql .= ", t.label as label_trans, t.description as description_trans";
1133  }
1134  $sql .= " FROM ".MAIN_DB_PREFIX."categorie as c";
1135  if (!empty($conf->global->MAIN_MULTILANGS)) {
1136  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_lang as t ON t.fk_category=c.rowid AND t.lang='".$this->db->escape($current_lang)."'";
1137  }
1138  $sql .= " WHERE c.entity IN (".getEntity('category').")";
1139  $sql .= " AND c.type = ".(int) $type;
1140 
1141  dol_syslog(get_class($this)."::get_full_arbo get category list", LOG_DEBUG);
1142  $resql = $this->db->query($sql);
1143  if ($resql) {
1144  $i = 0;
1145  while ($obj = $this->db->fetch_object($resql)) {
1146  $this->cats[$obj->rowid]['rowid'] = $obj->rowid;
1147  $this->cats[$obj->rowid]['id'] = $obj->rowid;
1148  $this->cats[$obj->rowid]['fk_parent'] = $obj->fk_parent;
1149  $this->cats[$obj->rowid]['label'] = !empty($obj->label_trans) ? $obj->label_trans : $obj->label;
1150  $this->cats[$obj->rowid]['description'] = !empty($obj->description_trans) ? $obj->description_trans : $obj->description;
1151  $this->cats[$obj->rowid]['color'] = $obj->color;
1152  $this->cats[$obj->rowid]['visible'] = $obj->visible;
1153  $this->cats[$obj->rowid]['ref_ext'] = $obj->ref_ext;
1154  $i++;
1155  }
1156  } else {
1157  dol_print_error($this->db);
1158  return -1;
1159  }
1160 
1161  // We add the fullpath property to each elements of first level (no parent exists)
1162  dol_syslog(get_class($this)."::get_full_arbo call to buildPathFromId", LOG_DEBUG);
1163  foreach ($this->cats as $key => $val) {
1164  //print 'key='.$key.'<br>'."\n";
1165  $this->buildPathFromId($key, 0); // Process a branch from the root category key (this category has no parent)
1166  }
1167 
1168  // Include or exclude leaf including $markafterid from tree
1169  if (count($markafterid) > 0) {
1170  $keyfiltercatid = '('.implode('|', $markafterid).')';
1171 
1172  //print "Look to discard category ".$markafterid."\n";
1173  $keyfilter1 = '^'.$keyfiltercatid.'$';
1174  $keyfilter2 = '_'.$keyfiltercatid.'$';
1175  $keyfilter3 = '^'.$keyfiltercatid.'_';
1176  $keyfilter4 = '_'.$keyfiltercatid.'_';
1177  foreach ($this->cats as $key => $val) {
1178  $test = (preg_match('/'.$keyfilter1.'/', $val['fullpath']) || preg_match('/'.$keyfilter2.'/', $val['fullpath'])
1179  || preg_match('/'.$keyfilter3.'/', $val['fullpath']) || preg_match('/'.$keyfilter4.'/', $val['fullpath']));
1180 
1181  if (($test && !$include) || (!$test && $include)) {
1182  unset($this->cats[$key]);
1183  }
1184  }
1185  }
1186 
1187  dol_syslog(get_class($this)."::get_full_arbo dol_sort_array", LOG_DEBUG);
1188  $this->cats = dol_sort_array($this->cats, 'fulllabel', 'asc', true, false);
1189 
1190  //$this->debug_cats();
1191 
1192  return $this->cats;
1193  }
1194 
1205  private function buildPathFromId($id_categ, $protection = 1000)
1206  {
1207  //dol_syslog(get_class($this)."::buildPathFromId id_categ=".$id_categ." protection=".$protection, LOG_DEBUG);
1208 
1209  if (!empty($this->cats[$id_categ]['fullpath'])) {
1210  // Already defined
1211  dol_syslog(get_class($this)."::buildPathFromId fullpath and fulllabel already defined", LOG_WARNING);
1212  return;
1213  }
1214 
1215  // First build full array $motherof
1216  //$this->load_motherof(); // Disabled because already done by caller of buildPathFromId
1217 
1218  // $this->cats[$id_categ] is supposed to be already an array. We just want to complete it with property fullpath and fulllabel
1219 
1220  // Define fullpath and fulllabel
1221  $this->cats[$id_categ]['fullpath'] = '_'.$id_categ;
1222  $this->cats[$id_categ]['fulllabel'] = $this->cats[$id_categ]['label'];
1223  $i = 0; $cursor_categ = $id_categ;
1224  //print 'Work for id_categ='.$id_categ.'<br>'."\n";
1225  while ((empty($protection) || $i < $protection) && !empty($this->motherof[$cursor_categ])) {
1226  //print '&nbsp; cursor_categ='.$cursor_categ.' i='.$i.' '.$this->motherof[$cursor_categ].'<br>'."\n";
1227  $this->cats[$id_categ]['fullpath'] = '_'.$this->motherof[$cursor_categ].$this->cats[$id_categ]['fullpath'];
1228  $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'];
1229  //print '&nbsp; Result for id_categ='.$id_categ.' : '.$this->cats[$id_categ]['fullpath'].' '.$this->cats[$id_categ]['fulllabel'].'<br>'."\n";
1230  $i++;
1231  $cursor_categ = $this->motherof[$cursor_categ];
1232  }
1233  //print 'Result for id_categ='.$id_categ.' : '.$this->cats[$id_categ]['fullpath'].'<br>'."\n";
1234 
1235  // We count number of _ to have level
1236  $nbunderscore = substr_count($this->cats[$id_categ]['fullpath'], '_');
1237  $this->cats[$id_categ]['level'] = ($nbunderscore ? $nbunderscore : null);
1238 
1239  return;
1240  }
1241 
1242  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1248  public function debug_cats()
1249  {
1250  // phpcs:enable
1251  // Display $this->cats
1252  foreach ($this->cats as $key => $val) {
1253  print 'id: '.$this->cats[$key]['id'];
1254  print ' label: '.$this->cats[$key]['label'];
1255  print ' mother: '.$this->cats[$key]['fk_parent'];
1256  //print ' children: '.(is_array($this->cats[$key]['id_children'])?join(',',$this->cats[$key]['id_children']):'');
1257  print ' fullpath: '.$this->cats[$key]['fullpath'];
1258  print ' fulllabel: '.$this->cats[$key]['fulllabel'];
1259  print "<br>\n";
1260  }
1261  }
1262 
1263 
1264  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1272  public function get_all_categories($type = null, $parent = false)
1273  {
1274  // phpcs:enable
1275  if (!is_numeric($type)) {
1276  $type = $this->MAP_ID[$type];
1277  }
1278 
1279  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie";
1280  $sql .= " WHERE entity IN (".getEntity('category').")";
1281  if (!is_null($type)) {
1282  $sql .= " AND type = ".(int) $type;
1283  }
1284  if ($parent) {
1285  $sql .= " AND fk_parent = 0";
1286  }
1287 
1288  $res = $this->db->query($sql);
1289  if ($res) {
1290  $cats = array();
1291  while ($rec = $this->db->fetch_array($res)) {
1292  $cat = new Categorie($this->db);
1293  $cat->fetch($rec['rowid']);
1294  $cats[$rec['rowid']] = $cat;
1295  }
1296  return $cats;
1297  } else {
1298  dol_print_error($this->db);
1299  return -1;
1300  }
1301  }
1302 
1303  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1310  public function get_main_categories($type = null)
1311  {
1312  // phpcs:enable
1313  return $this->get_all_categories($type, true);
1314  }
1315 
1316  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1322  public function already_exists()
1323  {
1324  // phpcs:enable
1325  $type = $this->type;
1326 
1327  if (!is_numeric($type)) {
1328  $type = $this->MAP_ID[$type];
1329  }
1330 
1331  /* We have to select any rowid from llx_categorie which category's mother and label
1332  * are equals to those of the calling category
1333  */
1334  $sql = "SELECT c.rowid";
1335  $sql .= " FROM ".MAIN_DB_PREFIX."categorie as c ";
1336  $sql .= " WHERE c.entity IN (".getEntity('category').")";
1337  $sql .= " AND c.type = ".((int) $type);
1338  $sql .= " AND c.fk_parent = ".((int) $this->fk_parent);
1339  $sql .= " AND c.label = '".$this->db->escape($this->label)."'";
1340 
1341  dol_syslog(get_class($this)."::already_exists", LOG_DEBUG);
1342  $resql = $this->db->query($sql);
1343  if ($resql) {
1344  if ($this->db->num_rows($resql) > 0) { // Checking for empty resql
1345  $obj = $this->db->fetch_array($resql);
1346  /* If object called create, obj cannot have is id.
1347  * If object called update, he mustn't have the same label as an other category for this mother.
1348  * So if the result have the same id, update is not for label, and if result have an other one,
1349  * update may be for label.
1350  */
1351  if ($obj[0] > 0 && $obj[0] != $this->id) {
1352  dol_syslog(get_class($this)."::already_exists category with name=".$this->label." and parent ".$this->fk_parent." exists: rowid=".$obj[0]." current_id=".$this->id, LOG_DEBUG);
1353  return 1;
1354  }
1355  }
1356  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);
1357  return 0;
1358  } else {
1359  $this->error = $this->db->error();
1360  return -1;
1361  }
1362  }
1363 
1364 
1365  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1376  public function print_all_ways($sep = '&gt;&gt;', $url = '', $nocolor = 0, $addpicto = 0)
1377  {
1378  // phpcs:enable
1379  $ways = array();
1380 
1381  $allways = $this->get_all_ways(); // Load array of categories
1382  foreach ($allways as $way) {
1383  $w = array();
1384  $i = 0;
1385  $forced_color = '';
1386  foreach ($way as $cat) {
1387  $i++;
1388 
1389  if (empty($nocolor)) {
1390  $forced_color = 'colortoreplace';
1391  if ($i == count($way)) { // Last category in hierarchy
1392  // Check contrast with background and correct text color
1393  $forced_color = 'categtextwhite';
1394  if ($cat->color) {
1395  if (colorIsLight($cat->color)) {
1396  $forced_color = 'categtextblack';
1397  }
1398  }
1399  }
1400  }
1401 
1402  if ($url == '') {
1403  $link = '<a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$cat->id.'&type='.$cat->type.'" class="'.$forced_color.'">';
1404  $linkend = '</a>';
1405  $w[] = $link.(($addpicto && $i == 1) ? img_object('', 'category', 'class="paddingright"') : '').$cat->label.$linkend;
1406  } elseif ($url == 'none') {
1407  $link = '<span class="'.$forced_color.'">';
1408  $linkend = '</span>';
1409  $w[] = $link.(($addpicto && $i == 1) ? img_object('', 'category', 'class="paddingright"') : '').$cat->label.$linkend;
1410  } else {
1411  $w[] = '<a class="'.$forced_color.'" href="'.DOL_URL_ROOT.'/'.$url.'?catid='.$cat->id.'">'.($addpicto ? img_object('', 'category') : '').$cat->label.'</a>';
1412  }
1413  }
1414  $newcategwithpath = preg_replace('/colortoreplace/', $forced_color, implode('<span class="inline-block valignmiddle paddingleft paddingright '.$forced_color.'">'.$sep.'</span>', $w));
1415 
1416  $ways[] = $newcategwithpath;
1417  }
1418 
1419  return $ways;
1420  }
1421 
1422 
1423  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1429  public function get_meres()
1430  {
1431  // phpcs:enable
1432  $parents = array();
1433 
1434  $sql = "SELECT fk_parent FROM ".MAIN_DB_PREFIX."categorie";
1435  $sql .= " WHERE rowid = ".((int) $this->id);
1436 
1437  $res = $this->db->query($sql);
1438 
1439  if ($res) {
1440  while ($rec = $this->db->fetch_array($res)) {
1441  if ($rec['fk_parent'] > 0) {
1442  $cat = new Categorie($this->db);
1443  $cat->fetch($rec['fk_parent']);
1444  $parents[] = $cat;
1445  }
1446  }
1447  return $parents;
1448  } else {
1449  dol_print_error($this->db);
1450  return -1;
1451  }
1452  }
1453 
1454  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1461  public function get_all_ways()
1462  {
1463  // phpcs:enable
1464  $ways = array();
1465 
1466  $parents = $this->get_meres();
1467  if (is_array($parents)) {
1468  foreach ($parents as $parent) {
1469  $allways = $parent->get_all_ways();
1470  foreach ($allways as $way) {
1471  $w = $way;
1472  $w[] = $this;
1473  $ways[] = $w;
1474  }
1475  }
1476  }
1477 
1478  if (count($ways) == 0) {
1479  $ways[0][0] = $this;
1480  }
1481 
1482  return $ways;
1483  }
1484 
1495  public function containing($id, $type, $mode = 'object')
1496  {
1497  $cats = array();
1498 
1499  if (is_numeric($type)) {
1500  $type = Categorie::$MAP_ID_TO_CODE[$type];
1501  }
1502 
1503  if ($type === Categorie::TYPE_BANK_LINE) { // TODO Remove this with standard category code after migration of llx_bank_categ into llx_categorie
1504  // Load bank categories
1505  $sql = "SELECT c.label, c.rowid";
1506  $sql .= " FROM ".MAIN_DB_PREFIX."bank_class as a, ".MAIN_DB_PREFIX."bank_categ as c";
1507  $sql .= " WHERE a.lineid=".((int) $id)." AND a.fk_categ = c.rowid";
1508  $sql .= " AND c.entity IN (".getEntity('category').")";
1509  $sql .= " ORDER BY c.label";
1510 
1511  $res = $this->db->query($sql);
1512  if ($res) {
1513  while ($obj = $this->db->fetch_object($res)) {
1514  if ($mode == 'id') {
1515  $cats[] = $obj->rowid;
1516  } elseif ($mode == 'label') {
1517  $cats[] = $obj->label;
1518  } else {
1519  $cat = new Categorie($this->db);
1520  $cat->id = $obj->rowid;
1521  $cat->label = $obj->label;
1522  $cats[] = $cat;
1523  }
1524  }
1525  } else {
1526  dol_print_error($this->db);
1527  return -1;
1528  }
1529  } else {
1530  $sql = "SELECT ct.fk_categorie, c.label, c.rowid";
1531  $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";
1532  $sql .= " WHERE ct.fk_categorie = c.rowid AND ct.fk_".(empty($this->MAP_CAT_FK[$type]) ? $type : $this->MAP_CAT_FK[$type])." = ".(int) $id;
1533  // This seems useless because the table already contains id of category of 1 unique type. So commented.
1534  // So now it works also with external added categories.
1535  //$sql .= " AND c.type = ".((int) $this->MAP_ID[$type]);
1536  $sql .= " AND c.entity IN (".getEntity('category').")";
1537 
1538  $res = $this->db->query($sql);
1539  if ($res) {
1540  while ($obj = $this->db->fetch_object($res)) {
1541  if ($mode == 'id') {
1542  $cats[] = $obj->rowid;
1543  } elseif ($mode == 'label') {
1544  $cats[] = $obj->label;
1545  } else {
1546  $cat = new Categorie($this->db);
1547  $cat->fetch($obj->fk_categorie);
1548  $cats[] = $cat;
1549  }
1550  }
1551  } else {
1552  dol_print_error($this->db);
1553  return -1;
1554  }
1555  }
1556 
1557  return $cats;
1558  }
1559 
1571  public function rechercher($id, $nom, $type, $exact = false, $case = false)
1572  {
1573  // Deprecation warning
1574  if (is_numeric($type)) {
1575  dol_syslog(__METHOD__.': using numeric types is deprecated.', LOG_WARNING);
1576  }
1577 
1578  $cats = array();
1579 
1580  // For backward compatibility
1581  if (is_numeric($type)) {
1582  // We want to reverse lookup
1583  $map_type = array_flip($this->MAP_ID);
1584  $type = $map_type[$type];
1585  dol_syslog(get_class($this)."::rechercher(): numeric types are deprecated, please use string instead", LOG_WARNING);
1586  }
1587 
1588  // Generation requete recherche
1589  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie";
1590  $sql .= " WHERE type = ".((int) $this->MAP_ID[$type]);
1591  $sql .= " AND entity IN (".getEntity('category').")";
1592  if ($nom) {
1593  if (!$exact) {
1594  $nom = '%'.$this->db->escape(str_replace('*', '%', $nom)).'%';
1595  }
1596  if (!$case) {
1597  $sql .= " AND label LIKE '".$this->db->escape($nom)."'";
1598  } else {
1599  $sql .= " AND label LIKE BINARY '".$this->db->escape($nom)."'";
1600  }
1601  }
1602  if ($id) {
1603  $sql .= " AND rowid = ".((int) $id);
1604  }
1605 
1606  $res = $this->db->query($sql);
1607  if ($res) {
1608  while ($rec = $this->db->fetch_array($res)) {
1609  $cat = new Categorie($this->db);
1610  $cat->fetch($rec['rowid']);
1611  $cats[] = $cat;
1612  }
1613 
1614  return $cats;
1615  } else {
1616  $this->error = $this->db->error().' sql='.$sql;
1617  return -1;
1618  }
1619  }
1620 
1631  public function getNomUrl($withpicto = 0, $option = '', $maxlength = 0, $moreparam = '')
1632  {
1633  global $langs, $hookmanager;
1634 
1635  $result = '';
1636  $label = $langs->trans("ShowCategory").': '.($this->ref ? $this->ref : $this->label);
1637 
1638  // Check contrast with background and correct text color
1639  $forced_color = 'categtextwhite';
1640  if ($this->color) {
1641  if (colorIsLight($this->color)) {
1642  $forced_color = 'categtextblack';
1643  }
1644  }
1645 
1646  $link = '<a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$this->id.'&type='.$this->type.$moreparam.'&backtopage='.urlencode($_SERVER['PHP_SELF'].($moreparam ? '?'.$moreparam : '')).'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip '.$forced_color.'">';
1647  $linkend = '</a>';
1648 
1649  $picto = 'category';
1650 
1651 
1652  if ($withpicto) {
1653  $result .= ($link.img_object($label, $picto, 'class="classfortooltip"').$linkend);
1654  }
1655  if ($withpicto && $withpicto != 2) {
1656  $result .= ' ';
1657  }
1658  if ($withpicto != 2) {
1659  $result .= $link.dol_trunc(($this->ref ? $this->ref : $this->label), $maxlength).$linkend;
1660  }
1661  global $action;
1662  $hookmanager->initHooks(array($this->element . 'dao'));
1663  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
1664  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1665  if ($reshook > 0) {
1666  $result = $hookmanager->resPrint;
1667  } else {
1668  $result .= $hookmanager->resPrint;
1669  }
1670  return $result;
1671  }
1672 
1673 
1674  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1682  public function add_photo($sdir, $file)
1683  {
1684  // phpcs:enable
1685  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1686 
1687  $dir = $sdir.'/'.get_exdir($this->id, 2, 0, 0, $this, 'category').$this->id."/";
1688  $dir .= "photos/";
1689 
1690  if (!file_exists($dir)) {
1691  dol_mkdir($dir);
1692  }
1693 
1694  if (file_exists($dir)) {
1695  if (is_array($file['name']) && count($file['name']) > 0) {
1696  $nbfile = count($file['name']);
1697  for ($i = 0; $i <= $nbfile; $i++) {
1698  $originImage = $dir.$file['name'][$i];
1699 
1700  // Cree fichier en taille origine
1701  dol_move_uploaded_file($file['tmp_name'][$i], $originImage, 1, 0, 0);
1702 
1703  if (file_exists($originImage)) {
1704  // Create thumbs
1705  $this->addThumbs($originImage);
1706  }
1707  }
1708  } else {
1709  $originImage = $dir.$file['name'];
1710 
1711  // Cree fichier en taille origine
1712  dol_move_uploaded_file($file['tmp_name'], $originImage, 1, 0, 0);
1713 
1714  if (file_exists($originImage)) {
1715  // Create thumbs
1716  $this->addThumbs($originImage);
1717  }
1718  }
1719  }
1720  }
1721 
1722  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1730  public function liste_photos($dir, $nbmax = 0)
1731  {
1732  // phpcs:enable
1733  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1734 
1735  $nbphoto = 0;
1736  $tabobj = array();
1737 
1738  $dirthumb = $dir.'thumbs/';
1739 
1740  if (file_exists($dir)) {
1741  $handle = opendir($dir);
1742  if (is_resource($handle)) {
1743  while (($file = readdir($handle)) !== false) {
1744  if (dol_is_file($dir.$file) && preg_match('/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $dir.$file)) {
1745  $nbphoto++;
1746  $photo = $file;
1747 
1748  // On determine nom du fichier vignette
1749  $photo_vignette = '';
1750  if (preg_match('/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $photo, $regs)) {
1751  $photo_vignette = preg_replace('/'.$regs[0].'/i', '', $photo).'_small'.$regs[0];
1752  }
1753 
1754  // Objet
1755  $obj = array();
1756  $obj['photo'] = $photo;
1757  if ($photo_vignette && is_file($dirthumb.$photo_vignette)) {
1758  $obj['photo_vignette'] = 'thumbs/'.$photo_vignette;
1759  } else {
1760  $obj['photo_vignette'] = "";
1761  }
1762 
1763  $tabobj[$nbphoto - 1] = $obj;
1764 
1765  // On continue ou on arrete de boucler
1766  if ($nbmax && $nbphoto >= $nbmax) {
1767  break;
1768  }
1769  }
1770  }
1771 
1772  closedir($handle);
1773  }
1774  }
1775 
1776  return $tabobj;
1777  }
1778 
1779  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1786  public function delete_photo($file)
1787  {
1788  // phpcs:enable
1789  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1790 
1791  $dir = dirname($file).'/'; // Chemin du dossier contenant l'image d'origine
1792  $dirthumb = $dir.'/thumbs/'; // Chemin du dossier contenant la vignette
1793  $filename = preg_replace('/'.preg_quote($dir, '/').'/i', '', $file); // Nom du fichier
1794 
1795  // On efface l'image d'origine
1796  dol_delete_file($file, 1);
1797 
1798  // Si elle existe, on efface la vignette
1799  if (preg_match('/(\.jpeg|\.jpg|\.bmp|\.gif|\.png|\.tiff)$/i', $filename, $regs)) {
1800  $photo_vignette = preg_replace('/'.$regs[0].'/i', '', $filename).'_small'.$regs[0];
1801  if (file_exists($dirthumb.$photo_vignette)) {
1802  dol_delete_file($dirthumb.$photo_vignette, 1);
1803  }
1804  }
1805  }
1806 
1807  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1814  public function get_image_size($file)
1815  {
1816  // phpcs:enable
1817  $infoImg = getimagesize($file); // Recuperation des infos de l'image
1818  $this->imgWidth = $infoImg[0]; // Largeur de l'image
1819  $this->imgHeight = $infoImg[1]; // Hauteur de l'image
1820  }
1821 
1829  public function setMultiLangs($user)
1830  {
1831  global $langs;
1832 
1833  $langs_available = $langs->get_available_languages();
1834  $current_lang = $langs->getDefaultLang();
1835 
1836  foreach ($langs_available as $key => $value) {
1837  $sql = "SELECT rowid";
1838  $sql .= " FROM ".MAIN_DB_PREFIX."categorie_lang";
1839  $sql .= " WHERE fk_category=".((int) $this->id);
1840  $sql .= " AND lang = '".$this->db->escape($key)."'";
1841 
1842  $result = $this->db->query($sql);
1843 
1844  if ($key == $current_lang) {
1845  if ($this->db->num_rows($result)) { // si aucune ligne dans la base
1846  $sql2 = "UPDATE ".MAIN_DB_PREFIX."categorie_lang";
1847  $sql2 .= " SET label = '".$this->db->escape($this->label)."',";
1848  $sql2 .= " description = '".$this->db->escape($this->description)."'";
1849  $sql2 .= " WHERE fk_category = ".((int) $this->id)." AND lang = '".$this->db->escape($key)."'";
1850  } else {
1851  $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."categorie_lang (fk_category, lang, label, description)";
1852  $sql2 .= " VALUES(".((int) $this->id).", '".$this->db->escape($key)."', '".$this->db->escape($this->label)."'";
1853  $sql2 .= ", '".$this->db->escape($this->multilangs["$key"]["description"])."')";
1854  }
1855  dol_syslog(get_class($this).'::setMultiLangs', LOG_DEBUG);
1856  if (!$this->db->query($sql2)) {
1857  $this->error = $this->db->lasterror();
1858  return -1;
1859  }
1860  } elseif (isset($this->multilangs["$key"])) {
1861  if ($this->db->num_rows($result)) { // si aucune ligne dans la base
1862  $sql2 = "UPDATE ".MAIN_DB_PREFIX."categorie_lang";
1863  $sql2 .= " SET label='".$this->db->escape($this->multilangs["$key"]["label"])."',";
1864  $sql2 .= " description='".$this->db->escape($this->multilangs["$key"]["description"])."'";
1865  $sql2 .= " WHERE fk_category=".((int) $this->id)." AND lang='".$this->db->escape($key)."'";
1866  } else {
1867  $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."categorie_lang (fk_category, lang, label, description)";
1868  $sql2 .= " VALUES(".((int) $this->id).", '".$this->db->escape($key)."', '".$this->db->escape($this->multilangs["$key"]["label"])."'";
1869  $sql2 .= ",'".$this->db->escape($this->multilangs["$key"]["description"])."')";
1870  }
1871 
1872  // on ne sauvegarde pas des champs vides
1873  if ($this->multilangs["$key"]["label"] || $this->multilangs["$key"]["description"] || $this->multilangs["$key"]["note"]) {
1874  dol_syslog(get_class($this).'::setMultiLangs', LOG_DEBUG);
1875  }
1876  if (!$this->db->query($sql2)) {
1877  $this->error = $this->db->lasterror();
1878  return -1;
1879  }
1880  }
1881  }
1882 
1883  // Call trigger
1884  $result = $this->call_trigger('CATEGORY_SET_MULTILANGS', $user);
1885  if ($result < 0) {
1886  $this->error = $this->db->lasterror();
1887  return -1;
1888  }
1889  // End call triggers
1890 
1891  return 1;
1892  }
1893 
1899  public function getMultiLangs()
1900  {
1901  global $langs;
1902 
1903  $current_lang = $langs->getDefaultLang();
1904 
1905  $sql = "SELECT lang, label, description";
1906  $sql .= " FROM ".MAIN_DB_PREFIX."categorie_lang";
1907  $sql .= " WHERE fk_category=".((int) $this->id);
1908 
1909  $result = $this->db->query($sql);
1910  if ($result) {
1911  while ($obj = $this->db->fetch_object($result)) {
1912  //print 'lang='.$obj->lang.' current='.$current_lang.'<br>';
1913  if ($obj->lang == $current_lang) { // si on a les traduct. dans la langue courante on les charge en infos principales.
1914  $this->label = $obj->label;
1915  $this->description = $obj->description;
1916  }
1917  $this->multilangs["$obj->lang"]["label"] = $obj->label;
1918  $this->multilangs["$obj->lang"]["description"] = $obj->description;
1919  }
1920  return 1;
1921  } else {
1922  $this->error = $langs->trans("Error")." : ".$this->db->error()." - ".$sql;
1923  return -1;
1924  }
1925  }
1926 
1933  public function getLibStatut($mode)
1934  {
1935  return '';
1936  }
1937 
1938 
1946  public function initAsSpecimen()
1947  {
1948  dol_syslog(get_class($this)."::initAsSpecimen");
1949 
1950  // Initialise parametres
1951  $this->id = 0;
1952  $this->fk_parent = 0;
1953  $this->label = 'SPECIMEN';
1954  $this->specimen = 1;
1955  $this->description = 'This is a description';
1956  $this->socid = 1;
1957  $this->type = self::TYPE_PRODUCT;
1958  }
1959 
1968  public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
1969  {
1970  $tables = array(
1971  'categorie_societe'
1972  );
1973 
1974  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables, 1);
1975  }
1976 
1984  public static function getFilterJoinQuery($type, $rowIdName)
1985  {
1986  if ($type == 'bank_account') {
1987  $type = 'account';
1988  }
1989 
1990  return " LEFT JOIN ".MAIN_DB_PREFIX."categorie_".$type." as cp ON ".$rowIdName." = cp.fk_".$type;
1991  }
1992 
2001  public static function getFilterSelectQuery($type, $rowIdName, $searchList)
2002  {
2003  if ($type == 'bank_account') {
2004  $type = 'account';
2005  }
2006  if ($type == 'customer') {
2007  $type = 'societe';
2008  }
2009  if ($type == 'supplier') {
2010  $type = 'fournisseur';
2011  }
2012 
2013  if (empty($searchList) && !is_array($searchList)) {
2014  return "";
2015  }
2016 
2017  $searchCategorySqlList = array();
2018  foreach ($searchList as $searchCategory) {
2019  if (intval($searchCategory) == -2) {
2020  $searchCategorySqlList[] = " cp.fk_categorie IS NULL";
2021  } elseif (intval($searchCategory) > 0) {
2022  $searchCategorySqlList[] = " ".$rowIdName." IN (SELECT fk_".$type." FROM ".MAIN_DB_PREFIX."categorie_".$type." WHERE fk_categorie = ".((int) $searchCategory).")";
2023  }
2024  }
2025 
2026  if (!empty($searchCategorySqlList)) {
2027  return " AND (".implode(' AND ', $searchCategorySqlList).")";
2028  } else {
2029  return "";
2030  }
2031  }
2032 
2038  public function countNbOfCategories()
2039  {
2040  dol_syslog(get_class($this)."::count_all_categories", LOG_DEBUG);
2041  $sql = "SELECT COUNT(rowid) FROM ".MAIN_DB_PREFIX."categorie";
2042  $sql .= " WHERE entity IN (".getEntity('category').")";
2043 
2044  $res = $this->db->query($sql);
2045  if ($res) {
2046  $obj = $this->db->fetch_object($res);
2047  return $obj->count;
2048  } else {
2049  dol_print_error($this->db);
2050  return -1;
2051  }
2052  }
2053 }
Categorie\get_full_arbo
get_full_arbo($type, $markafterid=0, $include=0)
Rebuilding the category tree as an array Return an array of table('id','id_mere',....
Definition: categorie.class.php:1098
Categorie\replaceThirdparty
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
Definition: categorie.class.php:1968
db
$conf db
API class for accounts.
Definition: inc.php:41
Categorie\delete_photo
delete_photo($file)
Efface la photo de la categorie et sa vignette.
Definition: categorie.class.php:1786
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1468
Categorie\already_exists
already_exists()
Check if no category with same label already exists for this cat's parent or root and for this cat's ...
Definition: categorie.class.php:1322
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
Categorie\del_type
del_type($obj, $type)
Delete object from category.
Definition: categorie.class.php:791
Categorie\get_image_size
get_image_size($file)
Load size of image file.
Definition: categorie.class.php:1814
Categorie\containsObject
containsObject($type, $object_id)
Check for the presence of an object in a category.
Definition: categorie.class.php:903
Categorie\debug_cats
debug_cats()
Display content of $this->cats.
Definition: categorie.class.php:1248
Categorie\liste_photos
liste_photos($dir, $nbmax=0)
Return tableau de toutes les photos de la categorie.
Definition: categorie.class.php:1730
Categorie\load_motherof
load_motherof()
Load the array this->motherof that is array(id_son=>id_parent, ...)
Definition: categorie.class.php:1054
Categorie\get_meres
get_meres()
Returns an array containing the list of parent categories.
Definition: categorie.class.php:1429
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
Categorie\getLibStatut
getLibStatut($mode)
Return label of contact status.
Definition: categorie.class.php:1933
Categorie\getMultiLangs
getMultiLangs()
Load array this->multilangs.
Definition: categorie.class.php:1899
Categorie\update
update(User $user)
Update category.
Definition: categorie.class.php:533
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
dol_sort_array
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
Definition: functions.lib.php:8385
CommonObject\addThumbs
addThumbs($file)
Build thumb.
Definition: commonobject.class.php:5701
Categorie\getListForItem
getListForItem($id, $type='customer', $sortfield="s.rowid", $sortorder='ASC', $limit=0, $page=0)
List categories of an element id.
Definition: categorie.class.php:928
ref
$object ref
Definition: info.php:77
Categorie\create
create($user)
Add category into database.
Definition: categorie.class.php:414
Categorie\countNbOfCategories
countNbOfCategories()
Count all categories.
Definition: categorie.class.php:2038
sanitizeVal
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
Definition: functions.lib.php:825
Categorie
Class to manage categories.
Definition: categorie.class.php:47
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
Categorie\get_all_ways
get_all_ways()
Returns in a table all possible paths to get to the category starting with the major categories repre...
Definition: categorie.class.php:1461
dol_is_file
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:477
Categorie\fetch
fetch($id, $label='', $type=null, $ref_ext='')
Load category into memory from database.
Definition: categorie.class.php:330
dol_delete_file
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.
Definition: files.lib.php:1231
Categorie\get_all_categories
get_all_categories($type=null, $parent=false)
Returns all categories.
Definition: categorie.class.php:1272
get_exdir
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
Definition: functions.lib.php:6549
Categorie\add_type
add_type($obj, $type='')
Link an object to the category.
Definition: categorie.class.php:699
dol_move_uploaded_file
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Make control on an uploaded file from an GUI page and move it to final destination.
Definition: files.lib.php:1092
getEntity
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Definition: functions.lib.php:148
CommonObject\insertExtraFields
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Definition: commonobject.class.php:6156
Categorie\getFilterSelectQuery
static getFilterSelectQuery($type, $rowIdName, $searchList)
Return the addtional SQL SELECT query for filtering a list by a category.
Definition: categorie.class.php:2001
CommonObject\commonReplaceThirdparty
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
Definition: commonobject.class.php:8347
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
Categorie\getObjectsInCateg
getObjectsInCateg($type, $onlyids=0, $limit=0, $offset=0, $sortfield='', $sortorder='ASC')
Return list of fetched instance of elements having this category.
Definition: categorie.class.php:849
CommonObject\fetch_optionals
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...
Definition: commonobject.class.php:6007
Categorie\setMultiLangs
setMultiLangs($user)
Update ou cree les traductions des infos produits.
Definition: categorie.class.php:1829
Categorie\print_all_ways
print_all_ways($sep='&gt;&gt;', $url='', $nocolor=0, $addpicto=0)
Returns the path of the category, with the names of the categories separated by $sep (" >> " by defau...
Definition: categorie.class.php:1376
Categorie\getMapList
getMapList()
Get map list.
Definition: categorie.class.php:303
Categorie\getNomUrl
getNomUrl($withpicto=0, $option='', $maxlength=0, $moreparam='')
Return name and link of category (with picto) Use ->id, ->ref, ->label, ->color.
Definition: categorie.class.php:1631
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
Categorie\rechercher
rechercher($id, $nom, $type, $exact=false, $case=false)
Returns categories whose id or name match add wildcards in the name unless $exact = true.
Definition: categorie.class.php:1571
Categorie\initAsSpecimen
initAsSpecimen()
Initialise an instance with random values.
Definition: categorie.class.php:1946
Categorie\containing
containing($id, $type, $mode='object')
Return list of categories (object instances or labels) linked to element of id $id and type $type Sho...
Definition: categorie.class.php:1495
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Categorie\__construct
__construct($db)
Constructor.
Definition: categorie.class.php:273
CommonObject\deleteExtraFields
deleteExtraFields()
Delete all extra fields values for the current object.
Definition: commonobject.class.php:6116
Categorie\get_main_categories
get_main_categories($type=null)
Returns the top level categories (which are not child)
Definition: categorie.class.php:1310
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4211
Categorie\add_photo
add_photo($sdir, $file)
Deplace fichier uploade sous le nom $files dans le repertoire sdir.
Definition: categorie.class.php:1682
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5791
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6603
colorIsLight
colorIsLight($stringcolor)
Return true if the color is light.
Definition: functions.lib.php:10182
Categorie\get_filles
get_filles()
Return direct childs id of a category into an array.
Definition: categorie.class.php:1026
Categorie\buildPathFromId
buildPathFromId($id_categ, $protection=1000)
For category id_categ and its childs available in this->cats, define property fullpath and fulllabel.
Definition: categorie.class.php:1205
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
Categorie\getFilterJoinQuery
static getFilterJoinQuery($type, $rowIdName)
Return the addtional SQL JOIN query for filtering a list by a category.
Definition: categorie.class.php:1984