dolibarr  x.y.z
api_setup.class.php
1 <?php
2 /* Copyright (C) 2016 Xebax Christy <xebax@wanadoo.fr>
3  * Copyright (C) 2016 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2017 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2017 Neil Orley <neil.orley@oeris.fr>
6  * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
7  * Copyright (C) 2018-2022 Thibault FOUCART <support@ptibogxiv.net>
8  *
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
24 use Luracast\Restler\RestException;
25 
26 require_once DOL_DOCUMENT_ROOT.'/main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/class/cstate.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/ccountry.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php';
30 
37 class Setup extends DolibarrApi
38 {
39  private $translations = null;
40 
44  public function __construct()
45  {
46  global $db;
47  $this->db = $db;
48  }
49 
66  public function getOrderingMethods($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
67  {
68  $list = array();
69 
70  if (!DolibarrApiAccess::$user->rights->commande->lire) {
71  throw new RestException(401);
72  }
73 
74  $sql = "SELECT rowid, code, libelle as label, module";
75  $sql .= " FROM ".MAIN_DB_PREFIX."c_input_method as t";
76  $sql .= " WHERE t.active = ".((int) $active);
77  // Add sql filters
78  if ($sqlfilters) {
79  $errormessage = '';
80  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
81  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
82  }
83  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
84  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
85  }
86 
87 
88  $sql .= $this->db->order($sortfield, $sortorder);
89 
90  if ($limit) {
91  if ($page < 0) {
92  $page = 0;
93  }
94  $offset = $limit * $page;
95 
96  $sql .= $this->db->plimit($limit, $offset);
97  }
98 
99  $result = $this->db->query($sql);
100 
101  if ($result) {
102  $num = $this->db->num_rows($result);
103  $min = min($num, ($limit <= 0 ? $num : $limit));
104  for ($i = 0; $i < $min; $i++) {
105  $list[] = $this->db->fetch_object($result);
106  }
107  } else {
108  throw new RestException(400, $this->db->lasterror());
109  }
110 
111  return $list;
112  }
113 
130  public function getOrderingOrigins($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
131  {
132  $list = array();
133 
134  if (!DolibarrApiAccess::$user->rights->commande->lire) {
135  throw new RestException(401);
136  }
137 
138  $sql = "SELECT rowid, code, label, module";
139  $sql .= " FROM ".MAIN_DB_PREFIX."c_input_reason as t";
140  $sql .= " WHERE t.active = ".((int) $active);
141  // Add sql filters
142  if ($sqlfilters) {
143  $errormessage = '';
144  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
145  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
146  }
147  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
148  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
149  }
150 
151 
152  $sql .= $this->db->order($sortfield, $sortorder);
153 
154  if ($limit) {
155  if ($page < 0) {
156  $page = 0;
157  }
158  $offset = $limit * $page;
159 
160  $sql .= $this->db->plimit($limit, $offset);
161  }
162 
163  $result = $this->db->query($sql);
164 
165  if ($result) {
166  $num = $this->db->num_rows($result);
167  $min = min($num, ($limit <= 0 ? $num : $limit));
168  for ($i = 0; $i < $min; $i++) {
169  $list[] = $this->db->fetch_object($result);
170  }
171  } else {
172  throw new RestException(400, $this->db->lasterror());
173  }
174 
175  return $list;
176  }
177 
194  public function getPaymentTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
195  {
196  $list = array();
197 
198  if (!DolibarrApiAccess::$user->rights->propal->lire && !DolibarrApiAccess::$user->rights->commande->lire && !DolibarrApiAccess::$user->rights->facture->lire) {
199  throw new RestException(401);
200  }
201 
202  $sql = "SELECT id, code, type, libelle as label, module";
203  $sql .= " FROM ".MAIN_DB_PREFIX."c_paiement as t";
204  $sql .= " WHERE t.entity IN (".getEntity('c_paiement').")";
205  $sql .= " AND t.active = ".((int) $active);
206  // Add sql filters
207  if ($sqlfilters) {
208  $errormessage = '';
209  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
210  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
211  }
212  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
213  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
214  }
215 
216 
217  $sql .= $this->db->order($sortfield, $sortorder);
218 
219  if ($limit) {
220  if ($page < 0) {
221  $page = 0;
222  }
223  $offset = $limit * $page;
224 
225  $sql .= $this->db->plimit($limit, $offset);
226  }
227 
228  $result = $this->db->query($sql);
229 
230  if ($result) {
231  $num = $this->db->num_rows($result);
232  $min = min($num, ($limit <= 0 ? $num : $limit));
233  for ($i = 0; $i < $min; $i++) {
234  $list[] = $this->db->fetch_object($result);
235  }
236  } else {
237  throw new RestException(400, $this->db->lasterror());
238  }
239 
240  return $list;
241  }
263  public function getListOfStates($sortfield = "code_departement", $sortorder = 'ASC', $limit = 100, $page = 0, $country = 0, $filter = '', $sqlfilters = '')
264  {
265  $list = array();
266 
267  // Note: The filter is not applied in the SQL request because it must
268  // be applied to the translated names, not to the names in database.
269  $sql = "SELECT t.rowid FROM ".MAIN_DB_PREFIX."c_departements as t";
270  if ($country) {
271  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_regions as d ON t.fk_region = d.code_region";
272  }
273  $sql .= " WHERE 1 = 1";
274  if ($country) {
275  $sql .= " AND d.fk_pays = ".((int) $country);
276  }
277  // Add sql filters
278  if ($sqlfilters) {
279  $errormessage = '';
280  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
281  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
282  }
283  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
284  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
285  }
286 
287  $sql .= $this->db->order($sortfield, $sortorder);
288 
289  if ($limit) {
290  if ($page < 0) {
291  $page = 0;
292  }
293  $offset = $limit * $page;
294 
295  $sql .= $this->db->plimit($limit, $offset);
296  }
297 
298  $result = $this->db->query($sql);
299 
300  if ($result) {
301  $num = $this->db->num_rows($result);
302  $min = min($num, ($limit <= 0 ? $num : $limit));
303  for ($i = 0; $i < $min; $i++) {
304  $obj = $this->db->fetch_object($result);
305  $state = new Cstate($this->db);
306  if ($state->fetch($obj->rowid) > 0) {
307  if (empty($filter) || stripos($state->label, $filter) !== false) {
308  $list[] = $this->_cleanObjectDatas($state);
309  }
310  }
311  }
312  } else {
313  throw new RestException(503, 'Error when retrieving list of states');
314  }
315 
316  return $list;
317  }
318 
329  public function getStateByID($id)
330  {
331  return $this->_fetchCstate($id, '');
332  }
333 
344  public function getStateByCode($code)
345  {
346  return $this->_fetchCstate('', $code);
347  }
348 
370  public function getListOfCountries($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $filter = '', $lang = '', $sqlfilters = '')
371  {
372  $list = array();
373 
374  // Note: The filter is not applied in the SQL request because it must
375  // be applied to the translated names, not to the names in database.
376  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_country as t";
377  $sql .= " WHERE 1 = 1";
378  // Add sql filters
379  if ($sqlfilters) {
380  $errormessage = '';
381  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
382  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
383  }
384  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
385  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
386  }
387 
388  $sql .= $this->db->order($sortfield, $sortorder);
389 
390  if ($limit) {
391  if ($page < 0) {
392  $page = 0;
393  }
394  $offset = $limit * $page;
395 
396  $sql .= $this->db->plimit($limit, $offset);
397  }
398 
399  $result = $this->db->query($sql);
400 
401  if ($result) {
402  $num = $this->db->num_rows($result);
403  $min = min($num, ($limit <= 0 ? $num : $limit));
404  for ($i = 0; $i < $min; $i++) {
405  $obj = $this->db->fetch_object($result);
406  $country = new Ccountry($this->db);
407  if ($country->fetch($obj->rowid) > 0) {
408  // Translate the name of the country if needed
409  // and then apply the filter if there is one.
410  $this->translateLabel($country, $lang, 'Country');
411 
412  if (empty($filter) || stripos($country->label, $filter) !== false) {
413  $list[] = $this->_cleanObjectDatas($country);
414  }
415  }
416  }
417  } else {
418  throw new RestException(503, 'Error when retrieving list of countries');
419  }
420 
421  return $list;
422  }
423 
435  public function getCountryByID($id, $lang = '')
436  {
437  return $this->_fetchCcountry($id, '', '', $lang);
438  }
439 
451  public function getCountryByCode($code, $lang = '')
452  {
453  return $this->_fetchCcountry('', $code, '', $lang);
454  }
455 
467  public function getCountryByISO($iso, $lang = '')
468  {
469  return $this->_fetchCcountry('', '', $iso, $lang);
470  }
471 
481  private function _fetchCstate($id, $code = '')
482  {
483  $state = new Cstate($this->db);
484 
485  $result = $state->fetch($id, $code);
486  if ($result < 0) {
487  throw new RestException(503, 'Error when retrieving state : '.$state->error);
488  } elseif ($result == 0) {
489  throw new RestException(404, 'State not found');
490  }
491 
492  return $this->_cleanObjectDatas($state);
493  }
494 
506  private function _fetchCcountry($id, $code = '', $iso = '', $lang = '')
507  {
508  $country = new Ccountry($this->db);
509 
510  $result = $country->fetch($id, $code, $iso);
511 
512  if ($result < 0) {
513  throw new RestException(503, 'Error when retrieving country : '.$country->error);
514  } elseif ($result == 0) {
515  throw new RestException(404, 'Country not found');
516  }
517 
518  $this->translateLabel($country, $lang, 'Country');
519 
520  return $this->_cleanObjectDatas($country);
521  }
522 
539  public function getAvailability($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
540  {
541  $list = array();
542 
543  if (!DolibarrApiAccess::$user->rights->commande->lire) {
544  throw new RestException(401);
545  }
546 
547  $sql = "SELECT rowid, code, label";
548  $sql .= " FROM ".MAIN_DB_PREFIX."c_availability as t";
549  $sql .= " WHERE t.active = ".((int) $active);
550  // Add sql filters
551  if ($sqlfilters) {
552  $errormessage = '';
553  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
554  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
555  }
556  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
557  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
558  }
559 
560 
561  $sql .= $this->db->order($sortfield, $sortorder);
562 
563  if ($limit) {
564  if ($page < 0) {
565  $page = 0;
566  }
567  $offset = $limit * $page;
568 
569  $sql .= $this->db->plimit($limit, $offset);
570  }
571 
572  $result = $this->db->query($sql);
573 
574  if ($result) {
575  $num = $this->db->num_rows($result);
576  $min = min($num, ($limit <= 0 ? $num : $limit));
577  for ($i = 0; $i < $min; $i++) {
578  $list[] = $this->db->fetch_object($result);
579  }
580  } else {
581  throw new RestException(400, $this->db->lasterror());
582  }
583 
584  return $list;
585  }
586 
587  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
594  protected function _cleanObjectDatas($object)
595  {
596  // phpcs:enable
597  $object = parent::_cleanObjectDatas($object);
598 
599  unset($object->error);
600  unset($object->errors);
601 
602  return $object;
603  }
604 
614  private function translateLabel($object, $lang, $prefix = 'Country', $dict = array('dict'))
615  {
616  if (!empty($lang)) {
617  // Load the translations if this is a new language.
618  if ($this->translations == null || $this->translations->getDefaultLang() !== $lang) {
619  global $conf;
620  $this->translations = new Translate('', $conf);
621  $this->translations->setDefaultLang($lang);
622  $this->translations->loadLangs($dict);
623  }
624  if ($object->code) {
625  $key = $prefix.$object->code;
626 
627  $translation = $this->translations->trans($key);
628  if ($translation != $key) {
629  $object->label = html_entity_decode($translation);
630  }
631  }
632  }
633  }
634 
652  public function getListOfEventTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $active = 1, $sqlfilters = '')
653  {
654  $list = array();
655 
656  $sql = "SELECT id, code, type, libelle as label, module";
657  $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t";
658  $sql .= " WHERE t.active = ".((int) $active);
659  if ($type) {
660  $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'";
661  }
662  if ($module) {
663  $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
664  }
665  // Add sql filters
666  if ($sqlfilters) {
667  $errormessage = '';
668  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
669  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
670  }
671  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
672  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
673  }
674 
675 
676  $sql .= $this->db->order($sortfield, $sortorder);
677 
678  if ($limit) {
679  if ($page < 0) {
680  $page = 0;
681  }
682  $offset = $limit * $page;
683 
684  $sql .= $this->db->plimit($limit, $offset);
685  }
686 
687  $result = $this->db->query($sql);
688 
689  if ($result) {
690  $num = $this->db->num_rows($result);
691  $min = min($num, ($limit <= 0 ? $num : $limit));
692  for ($i = 0; $i < $min; $i++) {
693  $list[] = $this->db->fetch_object($result);
694  }
695  } else {
696  throw new RestException(503, 'Error when retrieving list of events types : '.$this->db->lasterror());
697  }
698 
699  return $list;
700  }
701 
702 
719  public function getListOfExpenseReportsTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $module = '', $active = 1, $sqlfilters = '')
720  {
721  $list = array();
722 
723  $sql = "SELECT id, code, label, accountancy_code, active, module, position";
724  $sql .= " FROM ".MAIN_DB_PREFIX."c_type_fees as t";
725  $sql .= " WHERE t.active = ".((int) $active);
726  if ($module) {
727  $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
728  }
729  // Add sql filters
730  if ($sqlfilters) {
731  $errormessage = '';
732  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
733  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
734  }
735  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
736  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
737  }
738 
739 
740  $sql .= $this->db->order($sortfield, $sortorder);
741 
742  if ($limit) {
743  if ($page < 0) {
744  $page = 0;
745  }
746  $offset = $limit * $page;
747 
748  $sql .= $this->db->plimit($limit, $offset);
749  }
750 
751  $result = $this->db->query($sql);
752 
753  if ($result) {
754  $num = $this->db->num_rows($result);
755  $min = min($num, ($limit <= 0 ? $num : $limit));
756  for ($i = 0; $i < $min; $i++) {
757  $list[] = $this->db->fetch_object($result);
758  }
759  } else {
760  throw new RestException(503, 'Error when retrieving list of expense report types : '.$this->db->lasterror());
761  }
762 
763  return $list;
764  }
765 
766 
785  public function getListOfContactTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $active = 1, $lang = '', $sqlfilters = '')
786  {
787  $list = array();
788 
789  $sql = "SELECT rowid, code, element as type, libelle as label, source, module, position";
790  $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as t";
791  $sql .= " WHERE t.active = ".((int) $active);
792  if ($type) {
793  $sql .= " AND type LIKE '%".$this->db->escape($type)."%'";
794  }
795  if ($module) {
796  $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
797  }
798  // Add sql filters
799  if ($sqlfilters) {
800  $errormessage = '';
801  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
802  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
803  }
804  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
805  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
806  }
807 
808 
809  $sql .= $this->db->order($sortfield, $sortorder);
810 
811  if ($limit) {
812  if ($page < 0) {
813  $page = 0;
814  }
815  $offset = $limit * $page;
816 
817  $sql .= $this->db->plimit($limit, $offset);
818  }
819 
820  $result = $this->db->query($sql);
821 
822  if ($result) {
823  $num = $this->db->num_rows($result);
824  $min = min($num, ($limit <= 0 ? $num : $limit));
825  for ($i = 0; $i < $min; $i++) {
826  $contact_type = $this->db->fetch_object($result);
827  $this->translateLabel($contact_type, $lang, 'TypeContact_'.$contact_type->type.'_'.$contact_type->source.'_', array("eventorganization", "resource", "projects", "contracts", "bills", "orders", "agenda", "propal", "stocks", "supplier_proposal", "interventions", "sendings", "ticket"));
828  $list[] = $contact_type;
829  }
830  } else {
831  throw new RestException(503, 'Error when retrieving list of contacts types : '.$this->db->lasterror());
832  }
833 
834  return $list;
835  }
836 
854  public function getListOfCivilities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $module = '', $active = 1, $lang = '', $sqlfilters = '')
855  {
856  $list = array();
857 
858  $sql = "SELECT rowid, code, label, module";
859  $sql .= " FROM ".MAIN_DB_PREFIX."c_civility as t";
860  $sql .= " WHERE t.active = ".((int) $active);
861  if ($module) {
862  $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
863  }
864  // Add sql filters
865  if ($sqlfilters) {
866  $errormessage = '';
867  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
868  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
869  }
870  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
871  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
872  }
873 
874 
875  $sql .= $this->db->order($sortfield, $sortorder);
876 
877  if ($limit) {
878  if ($page < 0) {
879  $page = 0;
880  }
881  $offset = $limit * $page;
882 
883  $sql .= $this->db->plimit($limit, $offset);
884  }
885 
886  $result = $this->db->query($sql);
887 
888  if ($result) {
889  $num = $this->db->num_rows($result);
890  $min = min($num, ($limit <= 0 ? $num : $limit));
891  for ($i = 0; $i < $min; $i++) {
892  $civility = $this->db->fetch_object($result);
893  $this->translateLabel($civility, $lang, 'Civility', array('dict'));
894  $list[] = $civility;
895  }
896  } else {
897  throw new RestException(503, 'Error when retrieving list of civility : '.$this->db->lasterror());
898  }
899 
900  return $list;
901  }
902 
919  public function getListOfCurrencies($multicurrency = 0, $sortfield = "code_iso", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
920  {
921  $list = array();
922  $sql = "SELECT t.code_iso, t.label, t.unicode";
923  if (!empty($multicurrency)) {
924  $sql .= " , cr.date_sync, cr.rate ";
925  }
926  $sql .= " FROM ".MAIN_DB_PREFIX."c_currencies as t";
927  if (!empty($multicurrency)) {
928  $sql .= " JOIN ".MAIN_DB_PREFIX."multicurrency as m ON m.code=t.code_iso";
929  $sql .= " JOIN ".MAIN_DB_PREFIX."multicurrency_rate as cr ON (m.rowid = cr.fk_multicurrency)";
930  }
931  $sql .= " WHERE t.active = ".((int) $active);
932  if (!empty($multicurrency)) {
933  $sql .= " AND m.entity IN (".getEntity('multicurrency').")";
934  if (!empty($multicurrency) && $multicurrency != 2) {
935  $sql .= " AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM ".MAIN_DB_PREFIX."multicurrency_rate AS cr2 WHERE cr2.fk_multicurrency = m.rowid)";
936  }
937  }
938 
939  // Add sql filters
940  if ($sqlfilters) {
941  $errormessage = '';
942  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
943  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
944  }
945  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
946  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
947  }
948 
949 
950  $sql .= $this->db->order($sortfield, $sortorder);
951 
952  if ($limit) {
953  if ($page < 0) {
954  $page = 0;
955  }
956  $offset = $limit * $page;
957 
958  $sql .= $this->db->plimit($limit, $offset);
959  }
960 
961  $result = $this->db->query($sql);
962 
963  if ($result) {
964  $num = $this->db->num_rows($result);
965  $min = min($num, ($limit <= 0 ? $num : $limit));
966  for ($i = 0; $i < $min; $i++) {
967  $list[] = $this->db->fetch_object($result);
968  }
969  } else {
970  throw new RestException(503, 'Error when retrieving list of currency : '.$this->db->lasterror());
971  }
972 
973  return $list;
974  }
975 
989  public function getListOfExtrafields($sortfield = "t.pos", $sortorder = 'ASC', $type = '', $sqlfilters = '')
990  {
991  $list = array();
992 
993  if (!DolibarrApiAccess::$user->admin) {
994  throw new RestException(401, 'Only an admin user can get list of extrafields');
995  }
996 
997  if ($type == 'thirdparty') {
998  $type = 'societe';
999  }
1000  if ($type == 'contact') {
1001  $type = 'socpeople';
1002  }
1003 
1004  $sql = "SELECT t.rowid, t.name, t.label, t.type, t.size, t.elementtype, t.fieldunique, t.fieldrequired, t.param, t.pos, t.alwayseditable, t.perms, t.list, t.fielddefault, t.fieldcomputed";
1005  $sql .= " FROM ".MAIN_DB_PREFIX."extrafields as t";
1006  $sql .= " WHERE t.entity IN (".getEntity('extrafields').")";
1007  if (!empty($type)) {
1008  $sql .= " AND t.elementtype = '".$this->db->escape($type)."'";
1009  }
1010  // Add sql filters
1011  if ($sqlfilters) {
1012  $errormessage = '';
1013  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
1014  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1015  }
1016  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
1017  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
1018  }
1019 
1020  $sql .= $this->db->order($sortfield, $sortorder);
1021 
1022  $resql = $this->db->query($sql);
1023  if ($resql) {
1024  if ($this->db->num_rows($resql)) {
1025  while ($tab = $this->db->fetch_object($resql)) {
1026  // New usage
1027  $list[$tab->elementtype][$tab->name]['type'] = $tab->type;
1028  $list[$tab->elementtype][$tab->name]['label'] = $tab->label;
1029  $list[$tab->elementtype][$tab->name]['size'] = $tab->size;
1030  $list[$tab->elementtype][$tab->name]['elementtype'] = $tab->elementtype;
1031  $list[$tab->elementtype][$tab->name]['default'] = $tab->fielddefault;
1032  $list[$tab->elementtype][$tab->name]['computed'] = $tab->fieldcomputed;
1033  $list[$tab->elementtype][$tab->name]['unique'] = $tab->fieldunique;
1034  $list[$tab->elementtype][$tab->name]['required'] = $tab->fieldrequired;
1035  $list[$tab->elementtype][$tab->name]['param'] = ($tab->param ? jsonOrUnserialize($tab->param) : ''); // This may be a string encoded with serialise() or json_encode()
1036  $list[$tab->elementtype][$tab->name]['pos'] = $tab->pos;
1037  $list[$tab->elementtype][$tab->name]['alwayseditable'] = $tab->alwayseditable;
1038  $list[$tab->elementtype][$tab->name]['perms'] = $tab->perms;
1039  $list[$tab->elementtype][$tab->name]['list'] = $tab->list;
1040  }
1041  }
1042  } else {
1043  throw new RestException(503, 'Error when retrieving list of extra fields : '.$this->db->lasterror());
1044  }
1045 
1046  if (!count($list)) {
1047  throw new RestException(404, 'No extrafield found');
1048  }
1049 
1050  return $list;
1051  }
1052 
1053 
1071  public function getListOfTowns($sortfield = "zip,town", $sortorder = 'ASC', $limit = 100, $page = 0, $zipcode = '', $town = '', $active = 1, $sqlfilters = '')
1072  {
1073  $list = array();
1074 
1075  $sql = "SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
1076  $sql .= " FROM ".MAIN_DB_PREFIX."c_ziptown as t";
1077  $sql .= " WHERE t.active = ".((int) $active);
1078  if ($zipcode) {
1079  $sql .= " AND t.zip LIKE '%".$this->db->escape($zipcode)."%'";
1080  }
1081  if ($town) {
1082  $sql .= " AND t.town LIKE '%".$this->db->escape($town)."%'";
1083  }
1084  // Add sql filters
1085  if ($sqlfilters) {
1086  $errormessage = '';
1087  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
1088  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1089  }
1090  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
1091  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
1092  }
1093 
1094 
1095  $sql .= $this->db->order($sortfield, $sortorder);
1096 
1097  if ($limit) {
1098  if ($page < 0) {
1099  $page = 0;
1100  }
1101  $offset = $limit * $page;
1102 
1103  $sql .= $this->db->plimit($limit, $offset);
1104  }
1105 
1106  $result = $this->db->query($sql);
1107 
1108  if ($result) {
1109  $num = $this->db->num_rows($result);
1110  $min = min($num, ($limit <= 0 ? $num : $limit));
1111  for ($i = 0; $i < $min; $i++) {
1112  $list[] = $this->db->fetch_object($result);
1113  }
1114  } else {
1115  throw new RestException(503, 'Error when retrieving list of towns : '.$this->db->lasterror());
1116  }
1117 
1118  return $list;
1119  }
1120 
1137  public function getPaymentTerms($sortfield = "sortorder", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1138  {
1139  $list = array();
1140 
1141  if (!DolibarrApiAccess::$user->rights->propal->lire && !DolibarrApiAccess::$user->rights->commande->lire && !DolibarrApiAccess::$user->rights->facture->lire) {
1142  throw new RestException(401);
1143  }
1144 
1145  $sql = "SELECT rowid as id, code, sortorder, libelle as label, libelle_facture as descr, type_cdr, nbjour, decalage, module";
1146  $sql .= " FROM ".MAIN_DB_PREFIX."c_payment_term as t";
1147  $sql .= " WHERE t.entity IN (".getEntity('c_payment_term').")";
1148  $sql .= " AND t.active = ".((int) $active);
1149  // Add sql filters
1150  if ($sqlfilters) {
1151  $errormessage = '';
1152  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
1153  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1154  }
1155  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
1156  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
1157  }
1158 
1159 
1160  $sql .= $this->db->order($sortfield, $sortorder);
1161 
1162  if ($limit) {
1163  if ($page < 0) {
1164  $page = 0;
1165  }
1166  $offset = $limit * $page;
1167 
1168  $sql .= $this->db->plimit($limit, $offset);
1169  }
1170 
1171  $result = $this->db->query($sql);
1172 
1173  if ($result) {
1174  $num = $this->db->num_rows($result);
1175  $min = min($num, ($limit <= 0 ? $num : $limit));
1176  for ($i = 0; $i < $min; $i++) {
1177  $list[] = $this->db->fetch_object($result);
1178  }
1179  } else {
1180  throw new RestException(400, $this->db->lasterror());
1181  }
1182 
1183  return $list;
1184  }
1185 
1201  public function getShippingModes($limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1202  {
1203  $list = array();
1204 
1205  $sql = "SELECT rowid as id, code, libelle as label, description, tracking, module";
1206  $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as t";
1207  $sql .= " WHERE t.entity IN (".getEntity('c_shipment_mode').")";
1208  $sql .= " AND t.active = ".((int) $active);
1209  // Add sql filters
1210  if ($sqlfilters) {
1211  $errormessage = '';
1212  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
1213  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1214  }
1215  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
1216  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
1217  }
1218 
1219 
1220  //$sql.= $this->db->order($sortfield, $sortorder);
1221 
1222  if ($limit) {
1223  if ($page < 0) {
1224  $page = 0;
1225  }
1226  $offset = $limit * $page;
1227 
1228  $sql .= $this->db->plimit($limit, $offset);
1229  }
1230 
1231  $result = $this->db->query($sql);
1232 
1233  if ($result) {
1234  $num = $this->db->num_rows($result);
1235  $min = min($num, ($limit <= 0 ? $num : $limit));
1236  for ($i = 0; $i < $min; $i++) {
1237  $method = $this->db->fetch_object($result);
1238  $this->translateLabel($method, $lang, '', array('dict'));
1239  $list[] = $method;
1240  }
1241  } else {
1242  throw new RestException(400, $this->db->lasterror());
1243  }
1244 
1245  return $list;
1246  }
1247 
1263  public function getListOfMeasuringUnits($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1264  {
1265  $list = array();
1266 
1267  $sql = "SELECT t.rowid, t.code, t.label,t.short_label, t.active, t.scale, t.unit_type";
1268  $sql .= " FROM ".MAIN_DB_PREFIX."c_units as t";
1269  $sql .= " WHERE t.active = ".((int) $active);
1270  // Add sql filters
1271  if ($sqlfilters) {
1272  $errormessage = '';
1273  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
1274  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1275  }
1276  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
1277  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
1278  }
1279 
1280 
1281  $sql .= $this->db->order($sortfield, $sortorder);
1282 
1283  if ($limit) {
1284  if ($page < 0) {
1285  $page = 0;
1286  }
1287  $offset = $limit * $page;
1288 
1289  $sql .= $this->db->plimit($limit, $offset);
1290  }
1291 
1292  $result = $this->db->query($sql);
1293 
1294  if ($result) {
1295  $num = $this->db->num_rows($result);
1296  $min = min($num, ($limit <= 0 ? $num : $limit));
1297  for ($i = 0; $i < $min; $i++) {
1298  $list[] = $this->db->fetch_object($result);
1299  }
1300  } else {
1301  throw new RestException(503, 'Error when retrieving list of measuring units: '.$this->db->lasterror());
1302  }
1303 
1304  return $list;
1305  }
1306 
1323  public function getListOfLegalForm($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $country = 0, $active = 1, $sqlfilters = '')
1324  {
1325  $list = array();
1326 
1327  $sql = "SELECT t.rowid, t.code, t.fk_pays, t.libelle, t.isvatexempted, t.active, t.module, t.position";
1328  $sql .= " FROM ".MAIN_DB_PREFIX."c_forme_juridique as t";
1329  $sql .= " WHERE t.active = ".((int) $active);
1330  if ($country) {
1331  $sql .= " AND t.fk_pays = ".((int) $country);
1332  }
1333  // Add sql filters
1334  if ($sqlfilters) {
1335  $errormessage = '';
1336  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
1337  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1338  }
1339  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
1340  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
1341  }
1342 
1343 
1344  $sql .= $this->db->order($sortfield, $sortorder);
1345 
1346  if ($limit) {
1347  if ($page < 0) {
1348  $page = 0;
1349  }
1350  $offset = $limit * $page;
1351 
1352  $sql .= $this->db->plimit($limit, $offset);
1353  }
1354 
1355  $result = $this->db->query($sql);
1356 
1357  if ($result) {
1358  $num = $this->db->num_rows($result);
1359  $min = min($num, ($limit <= 0 ? $num : $limit));
1360  for ($i = 0; $i < $min; $i++) {
1361  $list[] = $this->db->fetch_object($result);
1362  }
1363  } else {
1364  throw new RestException(503, 'Error when retrieving list of legal form: '.$this->db->lasterror());
1365  }
1366 
1367  return $list;
1368  }
1369 
1385  public function getListOfStaff($sortfield = "id", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1386  {
1387  $list = array();
1388 
1389  $sql = "SELECT t.id, t.code, t.libelle, t.active, t.module";
1390  $sql .= " FROM ".MAIN_DB_PREFIX."c_effectif as t";
1391  $sql .= " WHERE t.active = ".((int) $active);
1392  // Add sql filters
1393  if ($sqlfilters) {
1394  $errormessage = '';
1395  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
1396  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1397  }
1398  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
1399  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
1400  }
1401 
1402 
1403  $sql .= $this->db->order($sortfield, $sortorder);
1404 
1405  if ($limit) {
1406  if ($page < 0) {
1407  $page = 0;
1408  }
1409  $offset = $limit * $page;
1410 
1411  $sql .= $this->db->plimit($limit, $offset);
1412  }
1413 
1414  $result = $this->db->query($sql);
1415 
1416  if ($result) {
1417  $num = $this->db->num_rows($result);
1418  $min = min($num, ($limit <= 0 ? $num : $limit));
1419  for ($i = 0; $i < $min; $i++) {
1420  $list[] = $this->db->fetch_object($result);
1421  }
1422  } else {
1423  throw new RestException(503, 'Error when retrieving list of staff: '.$this->db->lasterror());
1424  }
1425 
1426  return $list;
1427  }
1428 
1444  public function getListOfsocialNetworks($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1445  {
1446  global $conf;
1447 
1448  if (!isModEnabled('socialnetworks')) {
1449  throw new RestException(400, 'API not available: this dictionary is not enabled by setup');
1450  }
1451 
1452  $list = array();
1453  //TODO link with multicurrency module
1454  $sql = "SELECT t.rowid, t.entity, t.code, t.label, t.url, t.icon, t.active";
1455  $sql .= " FROM ".MAIN_DB_PREFIX."c_socialnetworks as t";
1456  $sql .= " WHERE t.entity IN (".getEntity('c_socialnetworks').")";
1457  $sql .= " AND t.active = ".((int) $active);
1458  // Add sql filters
1459  if ($sqlfilters) {
1460  $errormessage = '';
1461  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
1462  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1463  }
1464  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
1465  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
1466  }
1467 
1468 
1469  $sql .= $this->db->order($sortfield, $sortorder);
1470 
1471  if ($limit) {
1472  if ($page < 0) {
1473  $page = 0;
1474  }
1475  $offset = $limit * $page;
1476 
1477  $sql .= $this->db->plimit($limit, $offset);
1478  }
1479 
1480  $result = $this->db->query($sql);
1481 
1482  if ($result) {
1483  $num = $this->db->num_rows($result);
1484  $min = min($num, ($limit <= 0 ? $num : $limit));
1485  for ($i = 0; $i < $min; $i++) {
1486  $list[] = $this->db->fetch_object($result);
1487  }
1488  } else {
1489  throw new RestException(503, 'Error when retrieving list of social networks: '.$this->db->lasterror());
1490  }
1491 
1492  return $list;
1493  }
1494 
1511  public function getTicketsCategories($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1512  {
1513  $list = array();
1514 
1515  $sql = "SELECT rowid, code, pos, label, use_default, description";
1516  $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t";
1517  $sql .= " WHERE t.entity IN (".getEntity('c_ticket_category').")";
1518  $sql .= " AND t.active = ".((int) $active);
1519  // Add sql filters
1520  if ($sqlfilters) {
1521  $errormessage = '';
1522  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
1523  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1524  }
1525  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
1526  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
1527  }
1528 
1529 
1530  $sql .= $this->db->order($sortfield, $sortorder);
1531 
1532  if ($limit) {
1533  if ($page < 0) {
1534  $page = 0;
1535  }
1536  $offset = $limit * $page;
1537 
1538  $sql .= $this->db->plimit($limit, $offset);
1539  }
1540 
1541  $result = $this->db->query($sql);
1542 
1543  if ($result) {
1544  $num = $this->db->num_rows($result);
1545  $min = min($num, ($limit <= 0 ? $num : $limit));
1546  for ($i = 0; $i < $min; $i++) {
1547  $category = $this->db->fetch_object($result);
1548  $this->translateLabel($category, $lang, 'TicketCategoryShort', array('ticket'));
1549  $list[] = $category;
1550  }
1551  } else {
1552  throw new RestException(503, 'Error when retrieving list of ticket categories : '.$this->db->lasterror());
1553  }
1554 
1555  return $list;
1556  }
1557 
1574  public function getTicketsSeverities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1575  {
1576  $list = array();
1577 
1578  $sql = "SELECT rowid, code, pos, label, use_default, color, description";
1579  $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t";
1580  $sql .= " WHERE t.entity IN (".getEntity('c_ticket_severity').")";
1581  $sql .= " AND t.active = ".((int) $active);
1582  // Add sql filters
1583  if ($sqlfilters) {
1584  $errormessage = '';
1585  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
1586  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1587  }
1588  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
1589  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
1590  }
1591 
1592 
1593  $sql .= $this->db->order($sortfield, $sortorder);
1594 
1595  if ($limit) {
1596  if ($page < 0) {
1597  $page = 0;
1598  }
1599  $offset = $limit * $page;
1600 
1601  $sql .= $this->db->plimit($limit, $offset);
1602  }
1603 
1604  $result = $this->db->query($sql);
1605 
1606  if ($result) {
1607  $num = $this->db->num_rows($result);
1608  $min = min($num, ($limit <= 0 ? $num : $limit));
1609  for ($i = 0; $i < $min; $i++) {
1610  $severity = $this->db->fetch_object($result);
1611  $this->translateLabel($severity, $lang, 'TicketSeverityShort', array('ticket'));
1612  $list[] = $severity;
1613  }
1614  } else {
1615  throw new RestException(503, 'Error when retrieving list of ticket severities : '.$this->db->lasterror());
1616  }
1617 
1618  return $list;
1619  }
1620 
1637  public function getTicketsTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1638  {
1639  $list = array();
1640 
1641  $sql = "SELECT rowid, code, pos, label, use_default, description";
1642  $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_type as t";
1643  $sql .= " WHERE t.entity IN (".getEntity('c_ticket_type').")";
1644  $sql .= " AND t.active = ".((int) $active);
1645 
1646  // Add sql filters
1647  if ($sqlfilters) {
1648  $errormessage = '';
1649  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
1650  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1651  }
1652  $regexstring = '\‍(([^:\'\‍(\‍)]+:[^:\'\‍(\‍)]+:[^\‍(\‍)]+)\‍)';
1653  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
1654  }
1655 
1656 
1657  $sql .= $this->db->order($sortfield, $sortorder);
1658 
1659  if ($limit) {
1660  if ($page < 0) {
1661  $page = 0;
1662  }
1663  $offset = $limit * $page;
1664 
1665  $sql .= $this->db->plimit($limit, $offset);
1666  }
1667 
1668  $result = $this->db->query($sql);
1669 
1670  if ($result) {
1671  $num = $this->db->num_rows($result);
1672  $min = min($num, ($limit <= 0 ? $num : $limit));
1673  for ($i = 0; $i < $min; $i++) {
1674  $type =$this->db->fetch_object($result);
1675  $this->translateLabel($type, $lang, 'TicketTypeShort', array('ticket'));
1676  $list[] = $type;
1677  }
1678  } else {
1679  throw new RestException(503, 'Error when retrieving list of ticket types : '.$this->db->lasterror());
1680  }
1681 
1682  return $list;
1683  }
1684 
1694  public function getCompany()
1695  {
1696  global $conf, $mysoc;
1697 
1698  if (!DolibarrApiAccess::$user->admin
1699  && (empty($conf->global->API_LOGINS_ALLOWED_FOR_GET_COMPANY) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_GET_COMPANY)) {
1700  throw new RestException(403, 'Error API open to admin users only or to the users with logins defined into constant API_LOGINS_ALLOWED_FOR_GET_COMPANY');
1701  }
1702 
1703  unset($mysoc->skype);
1704  unset($mysoc->twitter);
1705  unset($mysoc->facebook);
1706  unset($mysoc->linkedin);
1707 
1708  unset($mysoc->pays);
1709  unset($mysoc->note);
1710  unset($mysoc->nom);
1711 
1712  unset($mysoc->lines);
1713 
1714  unset($mysoc->effectif);
1715  unset($mysoc->effectif_id);
1716  unset($mysoc->forme_juridique_code);
1717  unset($mysoc->forme_juridique);
1718  unset($mysoc->mode_reglement_supplier_id);
1719  unset($mysoc->cond_reglement_supplier_id);
1720  unset($mysoc->transport_mode_supplier_id);
1721  unset($mysoc->fk_prospectlevel);
1722 
1723  unset($mysoc->total_ht);
1724  unset($mysoc->total_tva);
1725  unset($mysoc->total_localtax1);
1726  unset($mysoc->total_localtax2);
1727  unset($mysoc->total_ttc);
1728 
1729  unset($mysoc->lastname);
1730  unset($mysoc->firstname);
1731  unset($mysoc->civility_id);
1732 
1733  unset($mysoc->client);
1734  unset($mysoc->prospect);
1735  unset($mysoc->fournisseur);
1736  unset($mysoc->contact_id);
1737 
1738  unset($mysoc->fk_incoterms);
1739  unset($mysoc->label_incoterms);
1740  unset($mysoc->location_incoterms);
1741 
1742  return $this->_cleanObjectDatas($mysoc);
1743  }
1744 
1754  public function getEstablishments()
1755  {
1756  $list = array();
1757 
1758  $limit = 0;
1759 
1760  $sql = "SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
1761  $sql .= " FROM ".MAIN_DB_PREFIX."establishment as e";
1762  $sql .= " WHERE e.entity IN (".getEntity('establishment').')';
1763  // if ($type) $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'";
1764  // if ($module) $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
1765  // Add sql filters
1766 
1767  $result = $this->db->query($sql);
1768 
1769  if ($result) {
1770  $num = $this->db->num_rows($result);
1771  $min = min($num, ($limit <= 0 ? $num : $limit));
1772  for ($i = 0; $i < $min; $i++) {
1773  $list[] = $this->db->fetch_object($result);
1774  }
1775  } else {
1776  throw new RestException(503, 'Error when retrieving list of establishments : '.$this->db->lasterror());
1777  }
1778 
1779  return $list;
1780  }
1781 
1792  public function getEtablishmentByID($id)
1793  {
1794  $establishment = new Establishment($this->db);
1795 
1796  $result = $establishment->fetch($id);
1797  if ($result < 0) {
1798  throw new RestException(503, 'Error when retrieving establishment : '.$establishment->error);
1799  } elseif ($result == 0) {
1800  throw new RestException(404, 'Establishment not found');
1801  }
1802 
1803  return $this->_cleanObjectDatas($establishment);
1804  }
1805 
1819  public function getConf($constantname)
1820  {
1821  global $conf;
1822 
1823  if (!DolibarrApiAccess::$user->admin
1824  && (!getDolGlobalString('API_LOGINS_ALLOWED_FOR_CONST_READ') || DolibarrApiAccess::$user->login != getDolGlobalString('API_LOGINS_ALLOWED_FOR_CONST_READ'))) {
1825  throw new RestException(403, 'Error API open to admin users only or to the users with logins defined into constant API_LOGINS_ALLOWED_FOR_CONST_READ');
1826  }
1827 
1828  if (!preg_match('/^[a-zA-Z0-9_]+$/', $constantname) || !isset($conf->global->$constantname)) {
1829  throw new RestException(404, 'Error Bad or unknown value for constantname');
1830  }
1831  if (isASecretKey($constantname)) {
1832  throw new RestException(403, 'Forbidden. This parameter cant be read with APIs');
1833  }
1834 
1835  return getDolGlobalString($constantname);
1836  }
1837 
1851  public function getCheckIntegrity($target)
1852  {
1853  global $langs, $conf;
1854 
1855  if (!DolibarrApiAccess::$user->admin
1856  && (empty($conf->global->API_LOGINS_ALLOWED_FOR_INTEGRITY_CHECK) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_INTEGRITY_CHECK)) {
1857  throw new RestException(403, 'Error API open to admin users only or to the users with logins defined into constant API_LOGINS_ALLOWED_FOR_INTEGRITY_CHECK');
1858  }
1859 
1860  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1861  require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
1862 
1863  $langs->load("admin");
1864 
1865  $outexpectedchecksum = '';
1866  $outcurrentchecksum = '';
1867 
1868  // Modified or missing files
1869  $file_list = array('missing' => array(), 'updated' => array());
1870 
1871  // Local file to compare to
1872  $xmlshortfile = dol_sanitizeFileName(GETPOST('xmlshortfile', 'alpha') ? GETPOST('xmlshortfile', 'alpha') : 'filelist-'.DOL_VERSION.(empty($conf->global->MAIN_FILECHECK_LOCAL_SUFFIX) ? '' : $conf->global->MAIN_FILECHECK_LOCAL_SUFFIX).'.xml'.(empty($conf->global->MAIN_FILECHECK_LOCAL_EXT) ? '' : $conf->global->MAIN_FILECHECK_LOCAL_EXT));
1873  $xmlfile = DOL_DOCUMENT_ROOT.'/install/'.$xmlshortfile;
1874  // Remote file to compare to
1875  $xmlremote = ($target == 'default' ? '' : $target);
1876  if (empty($xmlremote) && !empty($conf->global->MAIN_FILECHECK_URL)) {
1877  $xmlremote = $conf->global->MAIN_FILECHECK_URL;
1878  }
1879  $param = 'MAIN_FILECHECK_URL_'.DOL_VERSION;
1880  if (empty($xmlremote) && !empty($conf->global->$param)) {
1881  $xmlremote = $conf->global->$param;
1882  }
1883  if (empty($xmlremote)) {
1884  $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml';
1885  }
1886  if ($xmlremote && !preg_match('/^https?:\/\//i', $xmlremote)) {
1887  $langs->load("errors");
1888  throw new RestException(500, $langs->trans("ErrorURLMustStartWithHttp", $xmlremote));
1889  }
1890  if ($xmlremote && !preg_match('/\.xml$/', $xmlremote)) {
1891  $langs->load("errors");
1892  throw new RestException(500, $langs->trans("ErrorURLMustEndWith", $xmlremote, '.xml'));
1893  }
1894 
1895  if ($target == 'local') {
1896  if (dol_is_file($xmlfile)) {
1897  $xml = simplexml_load_file($xmlfile);
1898  } else {
1899  throw new RestException(500, $langs->trans('XmlNotFound').': '.$xmlfile);
1900  }
1901  } else {
1902  $xmlarray = getURLContent($xmlremote, 'GET', '', 1, array(), array('http', 'https'), 0); // Accept http or https links on external remote server only. Same is used into filecheck.php.
1903 
1904  // Return array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...)
1905  if (!$xmlarray['curl_error_no'] && $xmlarray['http_code'] != '400' && $xmlarray['http_code'] != '404') {
1906  $xmlfile = $xmlarray['content'];
1907  //print "xmlfilestart".$xmlfile."endxmlfile";
1908  $xml = simplexml_load_string($xmlfile, 'SimpleXMLElement', LIBXML_NOCDATA|LIBXML_NONET);
1909  } else {
1910  $errormsg = $langs->trans('XmlNotFound').': '.$xmlremote.' - '.$xmlarray['http_code'].(($xmlarray['http_code'] == 400 && $xmlarray['content']) ? ' '.$xmlarray['content'] : '').' '.$xmlarray['curl_error_no'].' '.$xmlarray['curl_error_msg'];
1911  throw new RestException(500, $errormsg);
1912  }
1913  }
1914 
1915  if ($xml) {
1916  $checksumconcat = array();
1917  $file_list = array();
1918  $out = '';
1919 
1920  // Forced constants
1921  if (is_object($xml->dolibarr_constants[0])) {
1922  $out .= load_fiche_titre($langs->trans("ForcedConstants"));
1923 
1924  $out .= '<div class="div-table-responsive-no-min">';
1925  $out .= '<table class="noborder">';
1926  $out .= '<tr class="liste_titre">';
1927  $out .= '<td>#</td>';
1928  $out .= '<td>'.$langs->trans("Constant").'</td>';
1929  $out .= '<td class="center">'.$langs->trans("ExpectedValue").'</td>';
1930  $out .= '<td class="center">'.$langs->trans("Value").'</td>';
1931  $out .= '</tr>'."\n";
1932 
1933  $i = 0;
1934  foreach ($xml->dolibarr_constants[0]->constant as $constant) { // $constant is a simpleXMLElement
1935  $constname = $constant['name'];
1936  $constvalue = (string) $constant;
1937  $constvalue = (empty($constvalue) ? '0' : $constvalue);
1938  // Value found
1939  $value = '';
1940  if ($constname && $conf->global->$constname != '') {
1941  $value = $conf->global->$constname;
1942  }
1943  $valueforchecksum = (empty($value) ? '0' : $value);
1944 
1945  $checksumconcat[] = $valueforchecksum;
1946 
1947  $i++;
1948  $out .= '<tr class="oddeven">';
1949  $out .= '<td>'.$i.'</td>'."\n";
1950  $out .= '<td>'.$constname.'</td>'."\n";
1951  $out .= '<td class="center">'.$constvalue.'</td>'."\n";
1952  $out .= '<td class="center">'.$valueforchecksum.'</td>'."\n";
1953  $out .= "</tr>\n";
1954  }
1955 
1956  if ($i == 0) {
1957  $out .= '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1958  }
1959  $out .= '</table>';
1960  $out .= '</div>';
1961 
1962  $out .= '<br>';
1963  }
1964 
1965  // Scan htdocs
1966  if (is_object($xml->dolibarr_htdocs_dir[0])) {
1967  $includecustom = (empty($xml->dolibarr_htdocs_dir[0]['includecustom']) ? 0 : $xml->dolibarr_htdocs_dir[0]['includecustom']);
1968 
1969  // Define qualified files (must be same than into generate_filelist_xml.php and in api_setup.class.php)
1970  $regextoinclude = '\.(php|php3|php4|php5|phtml|phps|phar|inc|css|scss|html|xml|js|json|tpl|jpg|jpeg|png|gif|ico|sql|lang|txt|yml|bak|md|mp3|mp4|wav|mkv|z|gz|zip|rar|tar|less|svg|eot|woff|woff2|ttf|manifest)$';
1971  $regextoexclude = '('.($includecustom ? '' : 'custom|').'documents|conf|install|dejavu-fonts-ttf-.*|public\/test|sabre\/sabre\/.*\/tests|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$'; // Exclude dirs
1972  $scanfiles = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude);
1973 
1974  // Fill file_list with files in signature, new files, modified files
1975  $ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat); // Fill array $file_list
1976  // Complete with list of new files
1977  foreach ($scanfiles as $keyfile => $valfile) {
1978  $tmprelativefilename = preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT, '/').'/', '', $valfile['fullname']);
1979  if (!in_array($tmprelativefilename, $file_list['insignature'])) {
1980  $md5newfile = @md5_file($valfile['fullname']); // Can fails if we don't have permission to open/read file
1981  $file_list['added'][] = array('filename'=>$tmprelativefilename, 'md5'=>$md5newfile);
1982  }
1983  }
1984 
1985  // Files missings
1986  $out .= load_fiche_titre($langs->trans("FilesMissing"));
1987 
1988  $out .= '<div class="div-table-responsive-no-min">';
1989  $out .= '<table class="noborder">';
1990  $out .= '<tr class="liste_titre">';
1991  $out .= '<td>#</td>';
1992  $out .= '<td>'.$langs->trans("Filename").'</td>';
1993  $out .= '<td class="center">'.$langs->trans("ExpectedChecksum").'</td>';
1994  $out .= '</tr>'."\n";
1995  $tmpfilelist = dol_sort_array($file_list['missing'], 'filename');
1996  if (is_array($tmpfilelist) && count($tmpfilelist)) {
1997  $i = 0;
1998  foreach ($tmpfilelist as $file) {
1999  $i++;
2000  $out .= '<tr class="oddeven">';
2001  $out .= '<td>'.$i.'</td>'."\n";
2002  $out .= '<td>'.$file['filename'].'</td>'."\n";
2003  $out .= '<td class="center">'.$file['expectedmd5'].'</td>'."\n";
2004  $out .= "</tr>\n";
2005  }
2006  } else {
2007  $out .= '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
2008  }
2009  $out .= '</table>';
2010  $out .= '</div>';
2011 
2012  $out .= '<br>';
2013 
2014  // Files modified
2015  $out .= load_fiche_titre($langs->trans("FilesModified"));
2016 
2017  $totalsize = 0;
2018  $out .= '<div class="div-table-responsive-no-min">';
2019  $out .= '<table class="noborder">';
2020  $out .= '<tr class="liste_titre">';
2021  $out .= '<td>#</td>';
2022  $out .= '<td>'.$langs->trans("Filename").'</td>';
2023  $out .= '<td class="center">'.$langs->trans("ExpectedChecksum").'</td>';
2024  $out .= '<td class="center">'.$langs->trans("CurrentChecksum").'</td>';
2025  $out .= '<td class="right">'.$langs->trans("Size").'</td>';
2026  $out .= '<td class="right">'.$langs->trans("DateModification").'</td>';
2027  $out .= '</tr>'."\n";
2028  $tmpfilelist2 = dol_sort_array($file_list['updated'], 'filename');
2029  if (is_array($tmpfilelist2) && count($tmpfilelist2)) {
2030  $i = 0;
2031  foreach ($tmpfilelist2 as $file) {
2032  $i++;
2033  $out .= '<tr class="oddeven">';
2034  $out .= '<td>'.$i.'</td>'."\n";
2035  $out .= '<td>'.$file['filename'].'</td>'."\n";
2036  $out .= '<td class="center">'.$file['expectedmd5'].'</td>'."\n";
2037  $out .= '<td class="center">'.$file['md5'].'</td>'."\n";
2038  $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
2039  $totalsize += $size;
2040  $out .= '<td class="right">'.dol_print_size($size).'</td>'."\n";
2041  $out .= '<td class="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']), 'dayhour').'</td>'."\n";
2042  $out .= "</tr>\n";
2043  }
2044  $out .= '<tr class="liste_total">';
2045  $out .= '<td></td>'."\n";
2046  $out .= '<td>'.$langs->trans("Total").'</td>'."\n";
2047  $out .= '<td align="center"></td>'."\n";
2048  $out .= '<td align="center"></td>'."\n";
2049  $out .= '<td class="right">'.dol_print_size($totalsize).'</td>'."\n";
2050  $out .= '<td class="right"></td>'."\n";
2051  $out .= "</tr>\n";
2052  } else {
2053  $out .= '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
2054  }
2055  $out .= '</table>';
2056  $out .= '</div>';
2057 
2058  $out .= '<br>';
2059 
2060  // Files added
2061  $out .= load_fiche_titre($langs->trans("FilesAdded"));
2062 
2063  $totalsize = 0;
2064  $out .= '<div class="div-table-responsive-no-min">';
2065  $out .= '<table class="noborder">';
2066  $out .= '<tr class="liste_titre">';
2067  $out .= '<td>#</td>';
2068  $out .= '<td>'.$langs->trans("Filename").'</td>';
2069  $out .= '<td class="center">'.$langs->trans("ExpectedChecksum").'</td>';
2070  $out .= '<td class="center">'.$langs->trans("CurrentChecksum").'</td>';
2071  $out .= '<td class="right">'.$langs->trans("Size").'</td>';
2072  $out .= '<td class="right">'.$langs->trans("DateModification").'</td>';
2073  $out .= '</tr>'."\n";
2074  $tmpfilelist3 = dol_sort_array($file_list['added'], 'filename');
2075  if (is_array($tmpfilelist3) && count($tmpfilelist3)) {
2076  $i = 0;
2077  foreach ($tmpfilelist3 as $file) {
2078  $i++;
2079  $out .= '<tr class="oddeven">';
2080  $out .= '<td>'.$i.'</td>'."\n";
2081  $out .= '<td>'.$file['filename'].'</td>'."\n";
2082  $out .= '<td class="center">'.$file['expectedmd5'].'</td>'."\n";
2083  $out .= '<td class="center">'.$file['md5'].'</td>'."\n";
2084  $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
2085  $totalsize += $size;
2086  $out .= '<td class="right">'.dol_print_size($size).'</td>'."\n";
2087  $out .= '<td class="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']), 'dayhour').'</td>'."\n";
2088  $out .= "</tr>\n";
2089  }
2090  $out .= '<tr class="liste_total">';
2091  $out .= '<td></td>'."\n";
2092  $out .= '<td>'.$langs->trans("Total").'</td>'."\n";
2093  $out .= '<td align="center"></td>'."\n";
2094  $out .= '<td align="center"></td>'."\n";
2095  $out .= '<td class="right">'.dol_print_size($totalsize).'</td>'."\n";
2096  $out .= '<td class="right"></td>'."\n";
2097  $out .= "</tr>\n";
2098  } else {
2099  $out .= '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
2100  }
2101  $out .= '</table>';
2102  $out .= '</div>';
2103 
2104 
2105  // Show warning
2106  if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) {
2107  //setEventMessages($langs->trans("FileIntegrityIsStrictlyConformedWithReference"), null, 'mesgs');
2108  } else {
2109  //setEventMessages($langs->trans("FileIntegritySomeFilesWereRemovedOrModified"), null, 'warnings');
2110  }
2111  } else {
2112  throw new RestException(500, 'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile);
2113  }
2114 
2115 
2116  // Scan scripts
2117  asort($checksumconcat); // Sort list of checksum
2118  $checksumget = md5(join(',', $checksumconcat));
2119  $checksumtoget = trim((string) $xml->dolibarr_htdocs_dir_checksum);
2120 
2121  $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans("Unknown"));
2122  if ($checksumget == $checksumtoget) {
2123  if (count($file_list['added'])) {
2124  $resultcode = 'warning';
2125  $resultcomment = 'FileIntegrityIsOkButFilesWereAdded';
2126  //$outcurrentchecksum = $checksumget.' - <span class="'.$resultcode.'">'.$langs->trans("FileIntegrityIsOkButFilesWereAdded").'</span>';
2127  $outcurrentchecksum = $checksumget;
2128  } else {
2129  $resultcode = 'ok';
2130  $resultcomment = 'Success';
2131  //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
2132  $outcurrentchecksum = $checksumget;
2133  }
2134  } else {
2135  $resultcode = 'error';
2136  $resultcomment = 'Error';
2137  //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
2138  $outcurrentchecksum = $checksumget;
2139  }
2140  } else {
2141  throw new RestException(404, 'No signature file known');
2142  }
2143 
2144  return array('resultcode'=>$resultcode, 'resultcomment'=>$resultcomment, 'expectedchecksum'=> $outexpectedchecksum, 'currentchecksum'=> $outcurrentchecksum, 'out'=>$out);
2145  }
2146 
2147 
2157  public function getModules()
2158  {
2159  global $conf;
2160 
2161  if (!DolibarrApiAccess::$user->admin
2162  && (empty($conf->global->API_LOGINS_ALLOWED_FOR_GET_MODULES) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_GET_MODULES)) {
2163  throw new RestException(403, 'Error API open to admin users only or to the users with logins defined into constant API_LOGINS_ALLOWED_FOR_GET_MODULES');
2164  }
2165 
2166  sort($conf->modules);
2167 
2168  return $this->_cleanObjectDatas($conf->modules);
2169  }
2170 }
Class to manage dictionary Countries (used by imports)
Class to manage dictionary States (used by imports)
Class for API REST v1.
Definition: api.class.php:31
_checkFilters($sqlfilters, &$error='')
Return if a $sqlfilters parameter is valid.
Definition: api.class.php:310
Class to manage establishments.
getShippingModes($limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of shipping methods.
getListOfContactTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $type='', $module='', $active=1, $lang='', $sqlfilters='')
Get the list of contacts types.
getListOfExtrafields($sortfield="t.pos", $sortorder='ASC', $type='', $sqlfilters='')
Get the list of extra fields.
getTicketsCategories($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of tickets categories.
getListOfMeasuringUnits($sortfield="rowid", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of measuring units.
_cleanObjectDatas($object)
Clean sensible object datas.
getListOfStaff($sortfield="id", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of staff.
getTicketsSeverities($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of tickets severity.
translateLabel($object, $lang, $prefix='Country', $dict=array('dict'))
Translate the name of the object to the given language.
getCountryByISO($iso, $lang='')
Get country by Iso.
getCheckIntegrity($target)
Do a test of integrity for files and setup.
getListOfExpenseReportsTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $module='', $active=1, $sqlfilters='')
Get the list of Expense Report types.
__construct()
Constructor.
getListOfTowns($sortfield="zip,town", $sortorder='ASC', $limit=100, $page=0, $zipcode='', $town='', $active=1, $sqlfilters='')
Get the list of towns.
getStateByCode($code)
Get state by Code.
getListOfEventTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $type='', $module='', $active=1, $sqlfilters='')
Get the list of events types.
getEstablishments()
Get the list of establishments.
getListOfLegalForm($sortfield="rowid", $sortorder='ASC', $limit=100, $page=0, $country=0, $active=1, $sqlfilters='')
Get the list of legal form of business.
getListOfCurrencies($multicurrency=0, $sortfield="code_iso", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of currencies.
getListOfsocialNetworks($sortfield="rowid", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of social networks.
_fetchCstate($id, $code='')
Get state.
getEtablishmentByID($id)
Get establishment by ID.
getConf($constantname)
Get value of a setup variables.
getCompany()
Get properties of company.
getPaymentTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of payments types.
getCountryByID($id, $lang='')
Get country by ID.
getCountryByCode($code, $lang='')
Get country by Code.
getPaymentTerms($sortfield="sortorder", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of payments terms.
getOrderingOrigins($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of ordering origins.
getListOfStates($sortfield="code_departement", $sortorder='ASC', $limit=100, $page=0, $country=0, $filter='', $sqlfilters='')
Get the list of states/provinces.
getOrderingMethods($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of ordering methods.
_fetchCcountry($id, $code='', $iso='', $lang='')
Get country.
getStateByID($id)
Get state by ID.
getAvailability($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of delivery times.
getTicketsTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of tickets types.
getListOfCountries($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $filter='', $lang='', $sqlfilters='')
Get the list of countries.
getListOfCivilities($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $module='', $active=1, $lang='', $sqlfilters='')
Get the list of civilities.
getModules()
Get list of enabled modules.
Class to manage translations.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path='', $pathref='', &$checksumconcat=array())
Function to get list of updated or modified files.
Definition: files.lib.php:3239
dol_filemtime($pathoffile)
Return time of a file.
Definition: files.lib.php:596
dol_filesize($pathoffile)
Return size of a file.
Definition: files.lib.php:584
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:480
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:61
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
isASecretKey($keyname)
Return if string has a name dedicated to store a secret.
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
jsonOrUnserialize($stringtodecode)
Decode an encode string.
isModEnabled($module)
Is Dolibarr module enabled.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1)
Function to get a content from an URL (use proxy if proxy defined).
Definition: geturl.lib.php:41
$conf db
API class for accounts.
Definition: inc.php:41