dolibarr  18.0.0
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/cregion.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/ccountry.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/hrm/class/establishment.class.php';
31 
38 class Setup extends DolibarrApi
39 {
40  private $translations = null;
41 
45  public function __construct()
46  {
47  global $db;
48  $this->db = $db;
49  }
50 
67  public function getOrderingMethods($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
68  {
69  $list = array();
70 
71  if (!DolibarrApiAccess::$user->hasRight('commande', 'lire')) {
72  throw new RestException(401);
73  }
74 
75  $sql = "SELECT rowid, code, libelle as label, module";
76  $sql .= " FROM ".MAIN_DB_PREFIX."c_input_method as t";
77  $sql .= " WHERE t.active = ".((int) $active);
78  // Add sql filters
79  if ($sqlfilters) {
80  $errormessage = '';
81  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
82  if ($errormessage) {
83  throw new RestException(503, 'Error when validating parameter sqlfilters -> '.$errormessage);
84  }
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 
129  public function getOrderingOrigins($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
130  {
131  $list = array();
132 
133  if (!DolibarrApiAccess::$user->hasRight('commande', 'lire')) {
134  throw new RestException(401);
135  }
136 
137  $sql = "SELECT rowid, code, label, module";
138  $sql .= " FROM ".MAIN_DB_PREFIX."c_input_reason as t";
139  $sql .= " WHERE t.active = ".((int) $active);
140  // Add sql filters
141  if ($sqlfilters) {
142  $errormessage = '';
143  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
144  if ($errormessage) {
145  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
146  }
147  }
148 
149 
150  $sql .= $this->db->order($sortfield, $sortorder);
151 
152  if ($limit) {
153  if ($page < 0) {
154  $page = 0;
155  }
156  $offset = $limit * $page;
157 
158  $sql .= $this->db->plimit($limit, $offset);
159  }
160 
161  $result = $this->db->query($sql);
162 
163  if ($result) {
164  $num = $this->db->num_rows($result);
165  $min = min($num, ($limit <= 0 ? $num : $limit));
166  for ($i = 0; $i < $min; $i++) {
167  $list[] = $this->db->fetch_object($result);
168  }
169  } else {
170  throw new RestException(400, $this->db->lasterror());
171  }
172 
173  return $list;
174  }
175 
192  public function getPaymentTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
193  {
194  $list = array();
195 
196  if (!DolibarrApiAccess::$user->hasRight('propal', 'lire') && !DolibarrApiAccess::$user->hasRight('commande', 'lire') && !DolibarrApiAccess::$user->hasRight('facture', 'lire')) {
197  throw new RestException(401);
198  }
199 
200  $sql = "SELECT id, code, type, libelle as label, module";
201  $sql .= " FROM ".MAIN_DB_PREFIX."c_paiement as t";
202  $sql .= " WHERE t.entity IN (".getEntity('c_paiement').")";
203  $sql .= " AND t.active = ".((int) $active);
204  // Add sql filters
205  if ($sqlfilters) {
206  $errormessage = '';
207  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
208  if ($errormessage) {
209  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
210  }
211  }
212 
213 
214  $sql .= $this->db->order($sortfield, $sortorder);
215 
216  if ($limit) {
217  if ($page < 0) {
218  $page = 0;
219  }
220  $offset = $limit * $page;
221 
222  $sql .= $this->db->plimit($limit, $offset);
223  }
224 
225  $result = $this->db->query($sql);
226 
227  if ($result) {
228  $num = $this->db->num_rows($result);
229  $min = min($num, ($limit <= 0 ? $num : $limit));
230  for ($i = 0; $i < $min; $i++) {
231  $list[] = $this->db->fetch_object($result);
232  }
233  } else {
234  throw new RestException(400, $this->db->lasterror());
235  }
236 
237  return $list;
238  }
257  public function getListOfRegions($sortfield = "code_region", $sortorder = 'ASC', $limit = 100, $page = 0, $country = 0, $filter = '', $sqlfilters = '')
258  {
259  $list = array();
260 
261  // Note: The filter is not applied in the SQL request because it must
262  // be applied to the translated names, not to the names in database.
263  $sql = "SELECT t.rowid FROM ".MAIN_DB_PREFIX."c_regions as t";
264  $sql .= " WHERE 1 = 1";
265  if ($country) {
266  $sql .= " AND t.fk_pays = ".((int) $country);
267  }
268  // Add sql filters
269  if ($sqlfilters) {
270  $errormessage = '';
271  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
272  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
273  }
274  $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
275  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
276  }
277 
278  $sql .= $this->db->order($sortfield, $sortorder);
279 
280  if ($limit) {
281  if ($page < 0) {
282  $page = 0;
283  }
284  $offset = $limit * $page;
285 
286  $sql .= $this->db->plimit($limit, $offset);
287  }
288 
289  $result = $this->db->query($sql);
290 
291  if ($result) {
292  $num = $this->db->num_rows($result);
293  $min = min($num, ($limit <= 0 ? $num : $limit));
294  for ($i = 0; $i < $min; $i++) {
295  $obj = $this->db->fetch_object($result);
296  $region = new Cregion($this->db);
297  if ($region->fetch($obj->rowid) > 0) {
298  if (empty($filter) || stripos($region->name, $filter) !== false) {
299  $list[] = $this->_cleanObjectDatas($region);
300  }
301  }
302  }
303  } else {
304  throw new RestException(503, 'Error when retrieving list of regions');
305  }
306 
307  return $list;
308  }
309 
320  public function getRegionByID($id)
321  {
322  return $this->_fetchCregion($id, '');
323  }
324 
335  public function getRegionByCode($code)
336  {
337  return $this->_fetchCregion('', $code);
338  }
339 
361  public function getListOfStates($sortfield = "code_departement", $sortorder = 'ASC', $limit = 100, $page = 0, $country = 0, $filter = '', $sqlfilters = '')
362  {
363  $list = array();
364 
365  // Note: The filter is not applied in the SQL request because it must
366  // be applied to the translated names, not to the names in database.
367  $sql = "SELECT t.rowid FROM ".MAIN_DB_PREFIX."c_departements as t";
368  if ($country) {
369  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_regions as d ON t.fk_region = d.code_region";
370  }
371  $sql .= " WHERE 1 = 1";
372  if ($country) {
373  $sql .= " AND d.fk_pays = ".((int) $country);
374  }
375  // Add sql filters
376  if ($sqlfilters) {
377  $errormessage = '';
378  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
379  if ($errormessage) {
380  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
381  }
382  }
383 
384  $sql .= $this->db->order($sortfield, $sortorder);
385 
386  if ($limit) {
387  if ($page < 0) {
388  $page = 0;
389  }
390  $offset = $limit * $page;
391 
392  $sql .= $this->db->plimit($limit, $offset);
393  }
394 
395  $result = $this->db->query($sql);
396 
397  if ($result) {
398  $num = $this->db->num_rows($result);
399  $min = min($num, ($limit <= 0 ? $num : $limit));
400  for ($i = 0; $i < $min; $i++) {
401  $obj = $this->db->fetch_object($result);
402  $state = new Cstate($this->db);
403  if ($state->fetch($obj->rowid) > 0) {
404  if (empty($filter) || stripos($state->label, $filter) !== false) {
405  $list[] = $this->_cleanObjectDatas($state);
406  }
407  }
408  }
409  } else {
410  throw new RestException(503, 'Error when retrieving list of states');
411  }
412 
413  return $list;
414  }
415 
426  public function getStateByID($id)
427  {
428  return $this->_fetchCstate($id, '');
429  }
430 
441  public function getStateByCode($code)
442  {
443  return $this->_fetchCstate('', $code);
444  }
445 
467  public function getListOfCountries($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $filter = '', $lang = '', $sqlfilters = '')
468  {
469  $list = array();
470 
471  // Note: The filter is not applied in the SQL request because it must
472  // be applied to the translated names, not to the names in database.
473  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_country as t";
474  $sql .= " WHERE 1 = 1";
475  // Add sql filters
476  if ($sqlfilters) {
477  $errormessage = '';
478  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
479  if ($errormessage) {
480  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
481  }
482  }
483 
484  $sql .= $this->db->order($sortfield, $sortorder);
485 
486  if ($limit) {
487  if ($page < 0) {
488  $page = 0;
489  }
490  $offset = $limit * $page;
491 
492  $sql .= $this->db->plimit($limit, $offset);
493  }
494 
495  $result = $this->db->query($sql);
496 
497  if ($result) {
498  $num = $this->db->num_rows($result);
499  $min = min($num, ($limit <= 0 ? $num : $limit));
500  for ($i = 0; $i < $min; $i++) {
501  $obj = $this->db->fetch_object($result);
502  $country = new Ccountry($this->db);
503  if ($country->fetch($obj->rowid) > 0) {
504  // Translate the name of the country if needed
505  // and then apply the filter if there is one.
506  $this->translateLabel($country, $lang, 'Country');
507 
508  if (empty($filter) || stripos($country->label, $filter) !== false) {
509  $list[] = $this->_cleanObjectDatas($country);
510  }
511  }
512  }
513  } else {
514  throw new RestException(503, 'Error when retrieving list of countries');
515  }
516 
517  return $list;
518  }
519 
531  public function getCountryByID($id, $lang = '')
532  {
533  return $this->_fetchCcountry($id, '', '', $lang);
534  }
535 
547  public function getCountryByCode($code, $lang = '')
548  {
549  return $this->_fetchCcountry('', $code, '', $lang);
550  }
551 
563  public function getCountryByISO($iso, $lang = '')
564  {
565  return $this->_fetchCcountry('', '', $iso, $lang);
566  }
567 
577  private function _fetchCregion($id, $code = '')
578  {
579  $region = new Cregion($this->db);
580 
581  $result = $region->fetch($id, $code);
582  if ($result < 0) {
583  throw new RestException(503, 'Error when retrieving region : '.$region->error);
584  } elseif ($result == 0) {
585  throw new RestException(404, 'Region not found');
586  }
587 
588  return $this->_cleanObjectDatas($region);
589  }
590 
600  private function _fetchCstate($id, $code = '')
601  {
602  $state = new Cstate($this->db);
603 
604  $result = $state->fetch($id, $code);
605  if ($result < 0) {
606  throw new RestException(503, 'Error when retrieving state : '.$state->error);
607  } elseif ($result == 0) {
608  throw new RestException(404, 'State not found');
609  }
610 
611  return $this->_cleanObjectDatas($state);
612  }
613 
625  private function _fetchCcountry($id, $code = '', $iso = '', $lang = '')
626  {
627  $country = new Ccountry($this->db);
628 
629  $result = $country->fetch($id, $code, $iso);
630 
631  if ($result < 0) {
632  throw new RestException(503, 'Error when retrieving country : '.$country->error);
633  } elseif ($result == 0) {
634  throw new RestException(404, 'Country not found');
635  }
636 
637  $this->translateLabel($country, $lang, 'Country');
638 
639  return $this->_cleanObjectDatas($country);
640  }
641 
658  public function getAvailability($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
659  {
660  $list = array();
661 
662  if (!DolibarrApiAccess::$user->hasRight('commande', 'lire')) {
663  throw new RestException(401);
664  }
665 
666  $sql = "SELECT rowid, code, label";
667  $sql .= " FROM ".MAIN_DB_PREFIX."c_availability as t";
668  $sql .= " WHERE t.active = ".((int) $active);
669  // Add sql filters
670  if ($sqlfilters) {
671  $errormessage = '';
672  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
673  if ($errormessage) {
674  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
675  }
676  }
677 
678 
679  $sql .= $this->db->order($sortfield, $sortorder);
680 
681  if ($limit) {
682  if ($page < 0) {
683  $page = 0;
684  }
685  $offset = $limit * $page;
686 
687  $sql .= $this->db->plimit($limit, $offset);
688  }
689 
690  $result = $this->db->query($sql);
691 
692  if ($result) {
693  $num = $this->db->num_rows($result);
694  $min = min($num, ($limit <= 0 ? $num : $limit));
695  for ($i = 0; $i < $min; $i++) {
696  $list[] = $this->db->fetch_object($result);
697  }
698  } else {
699  throw new RestException(400, $this->db->lasterror());
700  }
701 
702  return $list;
703  }
704 
705  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
712  protected function _cleanObjectDatas($object)
713  {
714  // phpcs:enable
715  $object = parent::_cleanObjectDatas($object);
716 
717  unset($object->error);
718  unset($object->errors);
719 
720  return $object;
721  }
722 
732  private function translateLabel($object, $lang, $prefix = 'Country', $dict = array('dict'))
733  {
734  if (!empty($lang)) {
735  // Load the translations if this is a new language.
736  if ($this->translations == null || $this->translations->getDefaultLang() !== $lang) {
737  global $conf;
738  $this->translations = new Translate('', $conf);
739  $this->translations->setDefaultLang($lang);
740  $this->translations->loadLangs($dict);
741  }
742  if ($object->code) {
743  $key = $prefix.$object->code;
744 
745  $translation = $this->translations->trans($key);
746  if ($translation != $key) {
747  $object->label = html_entity_decode($translation);
748  }
749  }
750  }
751  }
752 
770  public function getListOfEventTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $active = 1, $sqlfilters = '')
771  {
772  $list = array();
773 
774  $sql = "SELECT id, code, type, libelle as label, module";
775  $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t";
776  $sql .= " WHERE t.active = ".((int) $active);
777  if ($type) {
778  $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'";
779  }
780  if ($module) {
781  $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
782  }
783  // Add sql filters
784  if ($sqlfilters) {
785  $errormessage = '';
786  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
787  if ($errormessage) {
788  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
789  }
790  }
791 
792 
793  $sql .= $this->db->order($sortfield, $sortorder);
794 
795  if ($limit) {
796  if ($page < 0) {
797  $page = 0;
798  }
799  $offset = $limit * $page;
800 
801  $sql .= $this->db->plimit($limit, $offset);
802  }
803 
804  $result = $this->db->query($sql);
805 
806  if ($result) {
807  $num = $this->db->num_rows($result);
808  $min = min($num, ($limit <= 0 ? $num : $limit));
809  for ($i = 0; $i < $min; $i++) {
810  $list[] = $this->db->fetch_object($result);
811  }
812  } else {
813  throw new RestException(503, 'Error when retrieving list of events types : '.$this->db->lasterror());
814  }
815 
816  return $list;
817  }
818 
819 
836  public function getListOfExpenseReportsTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $module = '', $active = 1, $sqlfilters = '')
837  {
838  $list = array();
839 
840  $sql = "SELECT id, code, label, accountancy_code, active, module, position";
841  $sql .= " FROM ".MAIN_DB_PREFIX."c_type_fees as t";
842  $sql .= " WHERE t.active = ".((int) $active);
843  if ($module) {
844  $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
845  }
846  // Add sql filters
847  if ($sqlfilters) {
848  $errormessage = '';
849  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
850  if ($errormessage) {
851  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
852  }
853  }
854 
855 
856  $sql .= $this->db->order($sortfield, $sortorder);
857 
858  if ($limit) {
859  if ($page < 0) {
860  $page = 0;
861  }
862  $offset = $limit * $page;
863 
864  $sql .= $this->db->plimit($limit, $offset);
865  }
866 
867  $result = $this->db->query($sql);
868 
869  if ($result) {
870  $num = $this->db->num_rows($result);
871  $min = min($num, ($limit <= 0 ? $num : $limit));
872  for ($i = 0; $i < $min; $i++) {
873  $list[] = $this->db->fetch_object($result);
874  }
875  } else {
876  throw new RestException(503, 'Error when retrieving list of expense report types : '.$this->db->lasterror());
877  }
878 
879  return $list;
880  }
881 
882 
901  public function getListOfContactTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $active = 1, $lang = '', $sqlfilters = '')
902  {
903  $list = array();
904 
905  $sql = "SELECT rowid, code, element as type, libelle as label, source, module, position";
906  $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as t";
907  $sql .= " WHERE t.active = ".((int) $active);
908  if ($type) {
909  $sql .= " AND type LIKE '%".$this->db->escape($type)."%'";
910  }
911  if ($module) {
912  $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
913  }
914  // Add sql filters
915  if ($sqlfilters) {
916  $errormessage = '';
917  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
918  if ($errormessage) {
919  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
920  }
921  }
922 
923 
924  $sql .= $this->db->order($sortfield, $sortorder);
925 
926  if ($limit) {
927  if ($page < 0) {
928  $page = 0;
929  }
930  $offset = $limit * $page;
931 
932  $sql .= $this->db->plimit($limit, $offset);
933  }
934 
935  $result = $this->db->query($sql);
936 
937  if ($result) {
938  $num = $this->db->num_rows($result);
939  $min = min($num, ($limit <= 0 ? $num : $limit));
940  for ($i = 0; $i < $min; $i++) {
941  $contact_type = $this->db->fetch_object($result);
942  $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"));
943  $list[] = $contact_type;
944  }
945  } else {
946  throw new RestException(503, 'Error when retrieving list of contacts types : '.$this->db->lasterror());
947  }
948 
949  return $list;
950  }
951 
969  public function getListOfCivilities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $module = '', $active = 1, $lang = '', $sqlfilters = '')
970  {
971  $list = array();
972 
973  $sql = "SELECT rowid, code, label, module";
974  $sql .= " FROM ".MAIN_DB_PREFIX."c_civility as t";
975  $sql .= " WHERE t.active = ".((int) $active);
976  if ($module) {
977  $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
978  }
979  // Add sql filters
980  if ($sqlfilters) {
981  $errormessage = '';
982  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
983  if ($errormessage) {
984  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
985  }
986  }
987 
988 
989  $sql .= $this->db->order($sortfield, $sortorder);
990 
991  if ($limit) {
992  if ($page < 0) {
993  $page = 0;
994  }
995  $offset = $limit * $page;
996 
997  $sql .= $this->db->plimit($limit, $offset);
998  }
999 
1000  $result = $this->db->query($sql);
1001 
1002  if ($result) {
1003  $num = $this->db->num_rows($result);
1004  $min = min($num, ($limit <= 0 ? $num : $limit));
1005  for ($i = 0; $i < $min; $i++) {
1006  $civility = $this->db->fetch_object($result);
1007  $this->translateLabel($civility, $lang, 'Civility', array('dict'));
1008  $list[] = $civility;
1009  }
1010  } else {
1011  throw new RestException(503, 'Error when retrieving list of civility : '.$this->db->lasterror());
1012  }
1013 
1014  return $list;
1015  }
1016 
1033  public function getListOfCurrencies($multicurrency = 0, $sortfield = "code_iso", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1034  {
1035  $list = array();
1036  $sql = "SELECT t.code_iso, t.label, t.unicode";
1037  if (!empty($multicurrency)) {
1038  $sql .= " , cr.date_sync, cr.rate ";
1039  }
1040  $sql .= " FROM ".MAIN_DB_PREFIX."c_currencies as t";
1041  if (!empty($multicurrency)) {
1042  $sql .= " JOIN ".MAIN_DB_PREFIX."multicurrency as m ON m.code=t.code_iso";
1043  $sql .= " JOIN ".MAIN_DB_PREFIX."multicurrency_rate as cr ON (m.rowid = cr.fk_multicurrency)";
1044  }
1045  $sql .= " WHERE t.active = ".((int) $active);
1046  if (!empty($multicurrency)) {
1047  $sql .= " AND m.entity IN (".getEntity('multicurrency').")";
1048  if (!empty($multicurrency) && $multicurrency != 2) {
1049  $sql .= " AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM ".MAIN_DB_PREFIX."multicurrency_rate AS cr2 WHERE cr2.fk_multicurrency = m.rowid)";
1050  }
1051  }
1052 
1053  // Add sql filters
1054  if ($sqlfilters) {
1055  $errormessage = '';
1056  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1057  if ($errormessage) {
1058  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1059  }
1060  }
1061 
1062 
1063  $sql .= $this->db->order($sortfield, $sortorder);
1064 
1065  if ($limit) {
1066  if ($page < 0) {
1067  $page = 0;
1068  }
1069  $offset = $limit * $page;
1070 
1071  $sql .= $this->db->plimit($limit, $offset);
1072  }
1073 
1074  $result = $this->db->query($sql);
1075 
1076  if ($result) {
1077  $num = $this->db->num_rows($result);
1078  $min = min($num, ($limit <= 0 ? $num : $limit));
1079  for ($i = 0; $i < $min; $i++) {
1080  $list[] = $this->db->fetch_object($result);
1081  }
1082  } else {
1083  throw new RestException(503, 'Error when retrieving list of currency : '.$this->db->lasterror());
1084  }
1085 
1086  return $list;
1087  }
1088 
1102  public function getListOfExtrafields($sortfield = "t.pos", $sortorder = 'ASC', $type = '', $sqlfilters = '')
1103  {
1104  $list = array();
1105 
1106  if (!DolibarrApiAccess::$user->admin) {
1107  throw new RestException(401, 'Only an admin user can get list of extrafields');
1108  }
1109 
1110  if ($type == 'thirdparty') {
1111  $type = 'societe';
1112  }
1113  if ($type == 'contact') {
1114  $type = 'socpeople';
1115  }
1116 
1117  $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";
1118  $sql .= " FROM ".MAIN_DB_PREFIX."extrafields as t";
1119  $sql .= " WHERE t.entity IN (".getEntity('extrafields').")";
1120  if (!empty($type)) {
1121  $sql .= " AND t.elementtype = '".$this->db->escape($type)."'";
1122  }
1123  // Add sql filters
1124  if ($sqlfilters) {
1125  $errormessage = '';
1126  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1127  if ($errormessage) {
1128  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1129  }
1130  }
1131 
1132  $sql .= $this->db->order($sortfield, $sortorder);
1133 
1134  $resql = $this->db->query($sql);
1135  if ($resql) {
1136  if ($this->db->num_rows($resql)) {
1137  while ($tab = $this->db->fetch_object($resql)) {
1138  // New usage
1139  $list[$tab->elementtype][$tab->name]['type'] = $tab->type;
1140  $list[$tab->elementtype][$tab->name]['label'] = $tab->label;
1141  $list[$tab->elementtype][$tab->name]['size'] = $tab->size;
1142  $list[$tab->elementtype][$tab->name]['elementtype'] = $tab->elementtype;
1143  $list[$tab->elementtype][$tab->name]['default'] = $tab->fielddefault;
1144  $list[$tab->elementtype][$tab->name]['computed'] = $tab->fieldcomputed;
1145  $list[$tab->elementtype][$tab->name]['unique'] = $tab->fieldunique;
1146  $list[$tab->elementtype][$tab->name]['required'] = $tab->fieldrequired;
1147  $list[$tab->elementtype][$tab->name]['param'] = ($tab->param ? jsonOrUnserialize($tab->param) : ''); // This may be a string encoded with serialise() or json_encode()
1148  $list[$tab->elementtype][$tab->name]['pos'] = $tab->pos;
1149  $list[$tab->elementtype][$tab->name]['alwayseditable'] = $tab->alwayseditable;
1150  $list[$tab->elementtype][$tab->name]['perms'] = $tab->perms;
1151  $list[$tab->elementtype][$tab->name]['list'] = $tab->list;
1152  }
1153  }
1154  } else {
1155  throw new RestException(503, 'Error when retrieving list of extra fields : '.$this->db->lasterror());
1156  }
1157 
1158  if (!count($list)) {
1159  throw new RestException(404, 'No extrafield found');
1160  }
1161 
1162  return $list;
1163  }
1164 
1165 
1183  public function getListOfTowns($sortfield = "zip,town", $sortorder = 'ASC', $limit = 100, $page = 0, $zipcode = '', $town = '', $active = 1, $sqlfilters = '')
1184  {
1185  $list = array();
1186 
1187  $sql = "SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
1188  $sql .= " FROM ".MAIN_DB_PREFIX."c_ziptown as t";
1189  $sql .= " WHERE t.active = ".((int) $active);
1190  if ($zipcode) {
1191  $sql .= " AND t.zip LIKE '%".$this->db->escape($zipcode)."%'";
1192  }
1193  if ($town) {
1194  $sql .= " AND t.town LIKE '%".$this->db->escape($town)."%'";
1195  }
1196  // Add sql filters
1197  if ($sqlfilters) {
1198  $errormessage = '';
1199  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1200  if ($errormessage) {
1201  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1202  }
1203  }
1204 
1205 
1206  $sql .= $this->db->order($sortfield, $sortorder);
1207 
1208  if ($limit) {
1209  if ($page < 0) {
1210  $page = 0;
1211  }
1212  $offset = $limit * $page;
1213 
1214  $sql .= $this->db->plimit($limit, $offset);
1215  }
1216 
1217  $result = $this->db->query($sql);
1218 
1219  if ($result) {
1220  $num = $this->db->num_rows($result);
1221  $min = min($num, ($limit <= 0 ? $num : $limit));
1222  for ($i = 0; $i < $min; $i++) {
1223  $list[] = $this->db->fetch_object($result);
1224  }
1225  } else {
1226  throw new RestException(503, 'Error when retrieving list of towns : '.$this->db->lasterror());
1227  }
1228 
1229  return $list;
1230  }
1231 
1248  public function getPaymentTerms($sortfield = "sortorder", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1249  {
1250  $list = array();
1251 
1252  if (!DolibarrApiAccess::$user->hasRight('propal', 'lire') && !DolibarrApiAccess::$user->hasRight('commande', 'lire') && !DolibarrApiAccess::$user->hasRight('facture', 'lire')) {
1253  throw new RestException(401);
1254  }
1255 
1256  $sql = "SELECT rowid as id, code, sortorder, libelle as label, libelle_facture as descr, type_cdr, nbjour, decalage, module";
1257  $sql .= " FROM ".MAIN_DB_PREFIX."c_payment_term as t";
1258  $sql .= " WHERE t.entity IN (".getEntity('c_payment_term').")";
1259  $sql .= " AND t.active = ".((int) $active);
1260  // Add sql filters
1261  if ($sqlfilters) {
1262  $errormessage = '';
1263  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1264  if ($errormessage) {
1265  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1266  }
1267  }
1268 
1269 
1270  $sql .= $this->db->order($sortfield, $sortorder);
1271 
1272  if ($limit) {
1273  if ($page < 0) {
1274  $page = 0;
1275  }
1276  $offset = $limit * $page;
1277 
1278  $sql .= $this->db->plimit($limit, $offset);
1279  }
1280 
1281  $result = $this->db->query($sql);
1282 
1283  if ($result) {
1284  $num = $this->db->num_rows($result);
1285  $min = min($num, ($limit <= 0 ? $num : $limit));
1286  for ($i = 0; $i < $min; $i++) {
1287  $list[] = $this->db->fetch_object($result);
1288  }
1289  } else {
1290  throw new RestException(400, $this->db->lasterror());
1291  }
1292 
1293  return $list;
1294  }
1295 
1311  public function getShippingModes($limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1312  {
1313  $list = array();
1314 
1315  $sql = "SELECT rowid as id, code, libelle as label, description, tracking, module";
1316  $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as t";
1317  $sql .= " WHERE t.entity IN (".getEntity('c_shipment_mode').")";
1318  $sql .= " AND t.active = ".((int) $active);
1319  // Add sql filters
1320  if ($sqlfilters) {
1321  $errormessage = '';
1322  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1323  if ($errormessage) {
1324  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1325  }
1326  }
1327 
1328 
1329  //$sql.= $this->db->order($sortfield, $sortorder);
1330 
1331  if ($limit) {
1332  if ($page < 0) {
1333  $page = 0;
1334  }
1335  $offset = $limit * $page;
1336 
1337  $sql .= $this->db->plimit($limit, $offset);
1338  }
1339 
1340  $result = $this->db->query($sql);
1341 
1342  if ($result) {
1343  $num = $this->db->num_rows($result);
1344  $min = min($num, ($limit <= 0 ? $num : $limit));
1345  for ($i = 0; $i < $min; $i++) {
1346  $method = $this->db->fetch_object($result);
1347  $this->translateLabel($method, $lang, '', array('dict'));
1348  $list[] = $method;
1349  }
1350  } else {
1351  throw new RestException(400, $this->db->lasterror());
1352  }
1353 
1354  return $list;
1355  }
1356 
1372  public function getListOfMeasuringUnits($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1373  {
1374  $list = array();
1375 
1376  $sql = "SELECT t.rowid, t.code, t.label,t.short_label, t.active, t.scale, t.unit_type";
1377  $sql .= " FROM ".MAIN_DB_PREFIX."c_units as t";
1378  $sql .= " WHERE t.active = ".((int) $active);
1379  // Add sql filters
1380  if ($sqlfilters) {
1381  $errormessage = '';
1382  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1383  if ($errormessage) {
1384  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1385  }
1386  }
1387 
1388 
1389  $sql .= $this->db->order($sortfield, $sortorder);
1390 
1391  if ($limit) {
1392  if ($page < 0) {
1393  $page = 0;
1394  }
1395  $offset = $limit * $page;
1396 
1397  $sql .= $this->db->plimit($limit, $offset);
1398  }
1399 
1400  $result = $this->db->query($sql);
1401 
1402  if ($result) {
1403  $num = $this->db->num_rows($result);
1404  $min = min($num, ($limit <= 0 ? $num : $limit));
1405  for ($i = 0; $i < $min; $i++) {
1406  $list[] = $this->db->fetch_object($result);
1407  }
1408  } else {
1409  throw new RestException(503, 'Error when retrieving list of measuring units: '.$this->db->lasterror());
1410  }
1411 
1412  return $list;
1413  }
1414 
1431  public function getListOfLegalForm($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $country = 0, $active = 1, $sqlfilters = '')
1432  {
1433  $list = array();
1434 
1435  $sql = "SELECT t.rowid, t.code, t.fk_pays, t.libelle, t.isvatexempted, t.active, t.module, t.position";
1436  $sql .= " FROM ".MAIN_DB_PREFIX."c_forme_juridique as t";
1437  $sql .= " WHERE t.active = ".((int) $active);
1438  if ($country) {
1439  $sql .= " AND t.fk_pays = ".((int) $country);
1440  }
1441  // Add sql filters
1442  if ($sqlfilters) {
1443  $errormessage = '';
1444  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1445  if ($errormessage) {
1446  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1447  }
1448  }
1449 
1450 
1451  $sql .= $this->db->order($sortfield, $sortorder);
1452 
1453  if ($limit) {
1454  if ($page < 0) {
1455  $page = 0;
1456  }
1457  $offset = $limit * $page;
1458 
1459  $sql .= $this->db->plimit($limit, $offset);
1460  }
1461 
1462  $result = $this->db->query($sql);
1463 
1464  if ($result) {
1465  $num = $this->db->num_rows($result);
1466  $min = min($num, ($limit <= 0 ? $num : $limit));
1467  for ($i = 0; $i < $min; $i++) {
1468  $list[] = $this->db->fetch_object($result);
1469  }
1470  } else {
1471  throw new RestException(503, 'Error when retrieving list of legal form: '.$this->db->lasterror());
1472  }
1473 
1474  return $list;
1475  }
1476 
1492  public function getListOfStaff($sortfield = "id", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1493  {
1494  $list = array();
1495 
1496  $sql = "SELECT t.id, t.code, t.libelle, t.active, t.module";
1497  $sql .= " FROM ".MAIN_DB_PREFIX."c_effectif as t";
1498  $sql .= " WHERE t.active = ".((int) $active);
1499  // Add sql filters
1500  if ($sqlfilters) {
1501  $errormessage = '';
1502  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1503  if ($errormessage) {
1504  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1505  }
1506  }
1507 
1508 
1509  $sql .= $this->db->order($sortfield, $sortorder);
1510 
1511  if ($limit) {
1512  if ($page < 0) {
1513  $page = 0;
1514  }
1515  $offset = $limit * $page;
1516 
1517  $sql .= $this->db->plimit($limit, $offset);
1518  }
1519 
1520  $result = $this->db->query($sql);
1521 
1522  if ($result) {
1523  $num = $this->db->num_rows($result);
1524  $min = min($num, ($limit <= 0 ? $num : $limit));
1525  for ($i = 0; $i < $min; $i++) {
1526  $list[] = $this->db->fetch_object($result);
1527  }
1528  } else {
1529  throw new RestException(503, 'Error when retrieving list of staff: '.$this->db->lasterror());
1530  }
1531 
1532  return $list;
1533  }
1534 
1550  public function getListOfsocialNetworks($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1551  {
1552  global $conf;
1553 
1554  if (!isModEnabled('socialnetworks')) {
1555  throw new RestException(400, 'API not available: this dictionary is not enabled by setup');
1556  }
1557 
1558  $list = array();
1559  //TODO link with multicurrency module
1560  $sql = "SELECT t.rowid, t.entity, t.code, t.label, t.url, t.icon, t.active";
1561  $sql .= " FROM ".MAIN_DB_PREFIX."c_socialnetworks as t";
1562  $sql .= " WHERE t.entity IN (".getEntity('c_socialnetworks').")";
1563  $sql .= " AND t.active = ".((int) $active);
1564  // Add sql filters
1565  if ($sqlfilters) {
1566  $errormessage = '';
1567  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1568  if ($errormessage) {
1569  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1570  }
1571  }
1572 
1573 
1574  $sql .= $this->db->order($sortfield, $sortorder);
1575 
1576  if ($limit) {
1577  if ($page < 0) {
1578  $page = 0;
1579  }
1580  $offset = $limit * $page;
1581 
1582  $sql .= $this->db->plimit($limit, $offset);
1583  }
1584 
1585  $result = $this->db->query($sql);
1586 
1587  if ($result) {
1588  $num = $this->db->num_rows($result);
1589  $min = min($num, ($limit <= 0 ? $num : $limit));
1590  for ($i = 0; $i < $min; $i++) {
1591  $list[] = $this->db->fetch_object($result);
1592  }
1593  } else {
1594  throw new RestException(503, 'Error when retrieving list of social networks: '.$this->db->lasterror());
1595  }
1596 
1597  return $list;
1598  }
1599 
1616  public function getTicketsCategories($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1617  {
1618  $list = array();
1619 
1620  $sql = "SELECT rowid, code, pos, label, use_default, description";
1621  $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t";
1622  $sql .= " WHERE t.entity IN (".getEntity('c_ticket_category').")";
1623  $sql .= " AND t.active = ".((int) $active);
1624  // Add sql filters
1625  if ($sqlfilters) {
1626  $errormessage = '';
1627  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1628  if ($errormessage) {
1629  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1630  }
1631  }
1632 
1633 
1634  $sql .= $this->db->order($sortfield, $sortorder);
1635 
1636  if ($limit) {
1637  if ($page < 0) {
1638  $page = 0;
1639  }
1640  $offset = $limit * $page;
1641 
1642  $sql .= $this->db->plimit($limit, $offset);
1643  }
1644 
1645  $result = $this->db->query($sql);
1646 
1647  if ($result) {
1648  $num = $this->db->num_rows($result);
1649  $min = min($num, ($limit <= 0 ? $num : $limit));
1650  for ($i = 0; $i < $min; $i++) {
1651  $category = $this->db->fetch_object($result);
1652  $this->translateLabel($category, $lang, 'TicketCategoryShort', array('ticket'));
1653  $list[] = $category;
1654  }
1655  } else {
1656  throw new RestException(503, 'Error when retrieving list of ticket categories : '.$this->db->lasterror());
1657  }
1658 
1659  return $list;
1660  }
1661 
1678  public function getTicketsSeverities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1679  {
1680  $list = array();
1681 
1682  $sql = "SELECT rowid, code, pos, label, use_default, color, description";
1683  $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t";
1684  $sql .= " WHERE t.entity IN (".getEntity('c_ticket_severity').")";
1685  $sql .= " AND t.active = ".((int) $active);
1686  // Add sql filters
1687  if ($sqlfilters) {
1688  $errormessage = '';
1689  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1690  if ($errormessage) {
1691  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1692  }
1693  }
1694 
1695 
1696  $sql .= $this->db->order($sortfield, $sortorder);
1697 
1698  if ($limit) {
1699  if ($page < 0) {
1700  $page = 0;
1701  }
1702  $offset = $limit * $page;
1703 
1704  $sql .= $this->db->plimit($limit, $offset);
1705  }
1706 
1707  $result = $this->db->query($sql);
1708 
1709  if ($result) {
1710  $num = $this->db->num_rows($result);
1711  $min = min($num, ($limit <= 0 ? $num : $limit));
1712  for ($i = 0; $i < $min; $i++) {
1713  $severity = $this->db->fetch_object($result);
1714  $this->translateLabel($severity, $lang, 'TicketSeverityShort', array('ticket'));
1715  $list[] = $severity;
1716  }
1717  } else {
1718  throw new RestException(503, 'Error when retrieving list of ticket severities : '.$this->db->lasterror());
1719  }
1720 
1721  return $list;
1722  }
1723 
1740  public function getTicketsTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1741  {
1742  $list = array();
1743 
1744  $sql = "SELECT rowid, code, pos, label, use_default, description";
1745  $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_type as t";
1746  $sql .= " WHERE t.entity IN (".getEntity('c_ticket_type').")";
1747  $sql .= " AND t.active = ".((int) $active);
1748 
1749  // Add sql filters
1750  if ($sqlfilters) {
1751  $errormessage = '';
1752  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1753  if ($errormessage) {
1754  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1755  }
1756  }
1757 
1758 
1759  $sql .= $this->db->order($sortfield, $sortorder);
1760 
1761  if ($limit) {
1762  if ($page < 0) {
1763  $page = 0;
1764  }
1765  $offset = $limit * $page;
1766 
1767  $sql .= $this->db->plimit($limit, $offset);
1768  }
1769 
1770  $result = $this->db->query($sql);
1771 
1772  if ($result) {
1773  $num = $this->db->num_rows($result);
1774  $min = min($num, ($limit <= 0 ? $num : $limit));
1775  for ($i = 0; $i < $min; $i++) {
1776  $type =$this->db->fetch_object($result);
1777  $this->translateLabel($type, $lang, 'TicketTypeShort', array('ticket'));
1778  $list[] = $type;
1779  }
1780  } else {
1781  throw new RestException(503, 'Error when retrieving list of ticket types : '.$this->db->lasterror());
1782  }
1783 
1784  return $list;
1785  }
1786 
1803  public function getListOfIncoterms($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1804  {
1805  $list = array();
1806 
1807  $sql = "SELECT rowid, code, active";
1808  $sql .= " FROM ".MAIN_DB_PREFIX."c_incoterms as t";
1809  $sql .= " WHERE 1=1";
1810 
1811  // Add sql filters
1812  if ($sqlfilters) {
1813  $errormessage = '';
1814  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
1815  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1816  }
1817  $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
1818  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
1819  }
1820 
1821 
1822  $sql .= $this->db->order($sortfield, $sortorder);
1823 
1824  if ($limit) {
1825  if ($page < 0) {
1826  $page = 0;
1827  }
1828  $offset = $limit * $page;
1829 
1830  $sql .= $this->db->plimit($limit, $offset);
1831  }
1832 
1833  $result = $this->db->query($sql);
1834 
1835  if ($result) {
1836  $num = $this->db->num_rows($result);
1837  $min = min($num, ($limit <= 0 ? $num : $limit));
1838  for ($i = 0; $i < $min; $i++) {
1839  $type =$this->db->fetch_object($result);
1840  $list[] = $type;
1841  }
1842  } else {
1843  throw new RestException(503, 'Error when retrieving list of incoterm types : '.$this->db->lasterror());
1844  }
1845 
1846  return $list;
1847  }
1848 
1858  public function getCompany()
1859  {
1860  global $conf, $mysoc;
1861 
1862  if (!DolibarrApiAccess::$user->admin
1863  && (empty($conf->global->API_LOGINS_ALLOWED_FOR_GET_COMPANY) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_GET_COMPANY)) {
1864  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');
1865  }
1866 
1867  unset($mysoc->pays);
1868  unset($mysoc->note);
1869  unset($mysoc->nom);
1870 
1871  unset($mysoc->lines);
1872 
1873  unset($mysoc->effectif);
1874  unset($mysoc->effectif_id);
1875  unset($mysoc->forme_juridique_code);
1876  unset($mysoc->forme_juridique);
1877  unset($mysoc->mode_reglement_supplier_id);
1878  unset($mysoc->cond_reglement_supplier_id);
1879  unset($mysoc->transport_mode_supplier_id);
1880  unset($mysoc->fk_prospectlevel);
1881 
1882  unset($mysoc->total_ht);
1883  unset($mysoc->total_tva);
1884  unset($mysoc->total_localtax1);
1885  unset($mysoc->total_localtax2);
1886  unset($mysoc->total_ttc);
1887 
1888  unset($mysoc->lastname);
1889  unset($mysoc->firstname);
1890  unset($mysoc->civility_id);
1891 
1892  unset($mysoc->client);
1893  unset($mysoc->prospect);
1894  unset($mysoc->fournisseur);
1895  unset($mysoc->contact_id);
1896 
1897  unset($mysoc->fk_incoterms);
1898  unset($mysoc->label_incoterms);
1899  unset($mysoc->location_incoterms);
1900 
1901  return $this->_cleanObjectDatas($mysoc);
1902  }
1903 
1913  public function getEstablishments()
1914  {
1915  $list = array();
1916 
1917  $limit = 0;
1918 
1919  $sql = "SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
1920  $sql .= " FROM ".MAIN_DB_PREFIX."establishment as e";
1921  $sql .= " WHERE e.entity IN (".getEntity('establishment').')';
1922  // if ($type) $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'";
1923  // if ($module) $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
1924  // Add sql filters
1925 
1926  $result = $this->db->query($sql);
1927 
1928  if ($result) {
1929  $num = $this->db->num_rows($result);
1930  $min = min($num, ($limit <= 0 ? $num : $limit));
1931  for ($i = 0; $i < $min; $i++) {
1932  $list[] = $this->db->fetch_object($result);
1933  }
1934  } else {
1935  throw new RestException(503, 'Error when retrieving list of establishments : '.$this->db->lasterror());
1936  }
1937 
1938  return $list;
1939  }
1940 
1951  public function getEtablishmentByID($id)
1952  {
1953  $establishment = new Establishment($this->db);
1954 
1955  $result = $establishment->fetch($id);
1956  if ($result < 0) {
1957  throw new RestException(503, 'Error when retrieving establishment : '.$establishment->error);
1958  } elseif ($result == 0) {
1959  throw new RestException(404, 'Establishment not found');
1960  }
1961 
1962  return $this->_cleanObjectDatas($establishment);
1963  }
1964 
1978  public function getConf($constantname)
1979  {
1980  global $conf;
1981 
1982  if (!DolibarrApiAccess::$user->admin
1983  && (!getDolGlobalString('API_LOGINS_ALLOWED_FOR_CONST_READ') || DolibarrApiAccess::$user->login != getDolGlobalString('API_LOGINS_ALLOWED_FOR_CONST_READ'))) {
1984  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');
1985  }
1986 
1987  if (!preg_match('/^[a-zA-Z0-9_]+$/', $constantname) || !isset($conf->global->$constantname)) {
1988  throw new RestException(404, 'Error Bad or unknown value for constantname');
1989  }
1990  if (isASecretKey($constantname)) {
1991  throw new RestException(403, 'Forbidden. This parameter cant be read with APIs');
1992  }
1993 
1994  return getDolGlobalString($constantname);
1995  }
1996 
2010  public function getCheckIntegrity($target)
2011  {
2012  global $langs, $conf;
2013 
2014  if (!DolibarrApiAccess::$user->admin
2015  && (empty($conf->global->API_LOGINS_ALLOWED_FOR_INTEGRITY_CHECK) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_INTEGRITY_CHECK)) {
2016  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');
2017  }
2018 
2019  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2020  require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
2021 
2022  $langs->load("admin");
2023 
2024  $outexpectedchecksum = '';
2025  $outcurrentchecksum = '';
2026 
2027  // Modified or missing files
2028  $file_list = array('missing' => array(), 'updated' => array());
2029 
2030  // Local file to compare to
2031  $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));
2032  $xmlfile = DOL_DOCUMENT_ROOT.'/install/'.$xmlshortfile;
2033  // Remote file to compare to
2034  $xmlremote = ($target == 'default' ? '' : $target);
2035  if (empty($xmlremote) && !empty($conf->global->MAIN_FILECHECK_URL)) {
2036  $xmlremote = $conf->global->MAIN_FILECHECK_URL;
2037  }
2038  $param = 'MAIN_FILECHECK_URL_'.DOL_VERSION;
2039  if (empty($xmlremote) && !empty($conf->global->$param)) {
2040  $xmlremote = $conf->global->$param;
2041  }
2042  if (empty($xmlremote)) {
2043  $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml';
2044  }
2045  if ($xmlremote && !preg_match('/^https?:\/\//i', $xmlremote)) {
2046  $langs->load("errors");
2047  throw new RestException(500, $langs->trans("ErrorURLMustStartWithHttp", $xmlremote));
2048  }
2049  if ($xmlremote && !preg_match('/\.xml$/', $xmlremote)) {
2050  $langs->load("errors");
2051  throw new RestException(500, $langs->trans("ErrorURLMustEndWith", $xmlremote, '.xml'));
2052  }
2053 
2054  if ($target == 'local') {
2055  if (dol_is_file($xmlfile)) {
2056  $xml = simplexml_load_file($xmlfile);
2057  } else {
2058  throw new RestException(500, $langs->trans('XmlNotFound').': '.$xmlfile);
2059  }
2060  } else {
2061  $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.
2062 
2063  // Return array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...)
2064  if (!$xmlarray['curl_error_no'] && $xmlarray['http_code'] != '400' && $xmlarray['http_code'] != '404') {
2065  $xmlfile = $xmlarray['content'];
2066  //print "xmlfilestart".$xmlfile."endxmlfile";
2067  $xml = simplexml_load_string($xmlfile, 'SimpleXMLElement', LIBXML_NOCDATA|LIBXML_NONET);
2068  } else {
2069  $errormsg = $langs->trans('XmlNotFound').': '.$xmlremote.' - '.$xmlarray['http_code'].(($xmlarray['http_code'] == 400 && $xmlarray['content']) ? ' '.$xmlarray['content'] : '').' '.$xmlarray['curl_error_no'].' '.$xmlarray['curl_error_msg'];
2070  throw new RestException(500, $errormsg);
2071  }
2072  }
2073 
2074  if ($xml) {
2075  $checksumconcat = array();
2076  $file_list = array();
2077  $out = '';
2078 
2079  // Forced constants
2080  if (is_object($xml->dolibarr_constants[0])) {
2081  $out .= load_fiche_titre($langs->trans("ForcedConstants"));
2082 
2083  $out .= '<div class="div-table-responsive-no-min">';
2084  $out .= '<table class="noborder">';
2085  $out .= '<tr class="liste_titre">';
2086  $out .= '<td>#</td>';
2087  $out .= '<td>'.$langs->trans("Constant").'</td>';
2088  $out .= '<td class="center">'.$langs->trans("ExpectedValue").'</td>';
2089  $out .= '<td class="center">'.$langs->trans("Value").'</td>';
2090  $out .= '</tr>'."\n";
2091 
2092  $i = 0;
2093  foreach ($xml->dolibarr_constants[0]->constant as $constant) { // $constant is a simpleXMLElement
2094  $constname = $constant['name'];
2095  $constvalue = (string) $constant;
2096  $constvalue = (empty($constvalue) ? '0' : $constvalue);
2097  // Value found
2098  $value = '';
2099  if ($constname && $conf->global->$constname != '') {
2100  $value = $conf->global->$constname;
2101  }
2102  $valueforchecksum = (empty($value) ? '0' : $value);
2103 
2104  $checksumconcat[] = $valueforchecksum;
2105 
2106  $i++;
2107  $out .= '<tr class="oddeven">';
2108  $out .= '<td>'.$i.'</td>'."\n";
2109  $out .= '<td>'.$constname.'</td>'."\n";
2110  $out .= '<td class="center">'.$constvalue.'</td>'."\n";
2111  $out .= '<td class="center">'.$valueforchecksum.'</td>'."\n";
2112  $out .= "</tr>\n";
2113  }
2114 
2115  if ($i == 0) {
2116  $out .= '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
2117  }
2118  $out .= '</table>';
2119  $out .= '</div>';
2120 
2121  $out .= '<br>';
2122  }
2123 
2124  // Scan htdocs
2125  if (is_object($xml->dolibarr_htdocs_dir[0])) {
2126  $includecustom = (empty($xml->dolibarr_htdocs_dir[0]['includecustom']) ? 0 : $xml->dolibarr_htdocs_dir[0]['includecustom']);
2127 
2128  // Define qualified files (must be same than into generate_filelist_xml.php and in api_setup.class.php)
2129  $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)$';
2130  $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
2131  $scanfiles = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude);
2132 
2133  // Fill file_list with files in signature, new files, modified files
2134  $ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat); // Fill array $file_list
2135  // Complete with list of new files
2136  foreach ($scanfiles as $keyfile => $valfile) {
2137  $tmprelativefilename = preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT, '/').'/', '', $valfile['fullname']);
2138  if (!in_array($tmprelativefilename, $file_list['insignature'])) {
2139  $md5newfile = @md5_file($valfile['fullname']); // Can fails if we don't have permission to open/read file
2140  $file_list['added'][] = array('filename'=>$tmprelativefilename, 'md5'=>$md5newfile);
2141  }
2142  }
2143 
2144  // Files missings
2145  $out .= load_fiche_titre($langs->trans("FilesMissing"));
2146 
2147  $out .= '<div class="div-table-responsive-no-min">';
2148  $out .= '<table class="noborder">';
2149  $out .= '<tr class="liste_titre">';
2150  $out .= '<td>#</td>';
2151  $out .= '<td>'.$langs->trans("Filename").'</td>';
2152  $out .= '<td class="center">'.$langs->trans("ExpectedChecksum").'</td>';
2153  $out .= '</tr>'."\n";
2154  $tmpfilelist = dol_sort_array($file_list['missing'], 'filename');
2155  if (is_array($tmpfilelist) && count($tmpfilelist)) {
2156  $i = 0;
2157  foreach ($tmpfilelist as $file) {
2158  $i++;
2159  $out .= '<tr class="oddeven">';
2160  $out .= '<td>'.$i.'</td>'."\n";
2161  $out .= '<td>'.$file['filename'].'</td>'."\n";
2162  $out .= '<td class="center">'.$file['expectedmd5'].'</td>'."\n";
2163  $out .= "</tr>\n";
2164  }
2165  } else {
2166  $out .= '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
2167  }
2168  $out .= '</table>';
2169  $out .= '</div>';
2170 
2171  $out .= '<br>';
2172 
2173  // Files modified
2174  $out .= load_fiche_titre($langs->trans("FilesModified"));
2175 
2176  $totalsize = 0;
2177  $out .= '<div class="div-table-responsive-no-min">';
2178  $out .= '<table class="noborder">';
2179  $out .= '<tr class="liste_titre">';
2180  $out .= '<td>#</td>';
2181  $out .= '<td>'.$langs->trans("Filename").'</td>';
2182  $out .= '<td class="center">'.$langs->trans("ExpectedChecksum").'</td>';
2183  $out .= '<td class="center">'.$langs->trans("CurrentChecksum").'</td>';
2184  $out .= '<td class="right">'.$langs->trans("Size").'</td>';
2185  $out .= '<td class="right">'.$langs->trans("DateModification").'</td>';
2186  $out .= '</tr>'."\n";
2187  $tmpfilelist2 = dol_sort_array($file_list['updated'], 'filename');
2188  if (is_array($tmpfilelist2) && count($tmpfilelist2)) {
2189  $i = 0;
2190  foreach ($tmpfilelist2 as $file) {
2191  $i++;
2192  $out .= '<tr class="oddeven">';
2193  $out .= '<td>'.$i.'</td>'."\n";
2194  $out .= '<td>'.$file['filename'].'</td>'."\n";
2195  $out .= '<td class="center">'.$file['expectedmd5'].'</td>'."\n";
2196  $out .= '<td class="center">'.$file['md5'].'</td>'."\n";
2197  $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
2198  $totalsize += $size;
2199  $out .= '<td class="right">'.dol_print_size($size).'</td>'."\n";
2200  $out .= '<td class="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']), 'dayhour').'</td>'."\n";
2201  $out .= "</tr>\n";
2202  }
2203  $out .= '<tr class="liste_total">';
2204  $out .= '<td></td>'."\n";
2205  $out .= '<td>'.$langs->trans("Total").'</td>'."\n";
2206  $out .= '<td align="center"></td>'."\n";
2207  $out .= '<td align="center"></td>'."\n";
2208  $out .= '<td class="right">'.dol_print_size($totalsize).'</td>'."\n";
2209  $out .= '<td class="right"></td>'."\n";
2210  $out .= "</tr>\n";
2211  } else {
2212  $out .= '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
2213  }
2214  $out .= '</table>';
2215  $out .= '</div>';
2216 
2217  $out .= '<br>';
2218 
2219  // Files added
2220  $out .= load_fiche_titre($langs->trans("FilesAdded"));
2221 
2222  $totalsize = 0;
2223  $out .= '<div class="div-table-responsive-no-min">';
2224  $out .= '<table class="noborder">';
2225  $out .= '<tr class="liste_titre">';
2226  $out .= '<td>#</td>';
2227  $out .= '<td>'.$langs->trans("Filename").'</td>';
2228  $out .= '<td class="center">'.$langs->trans("ExpectedChecksum").'</td>';
2229  $out .= '<td class="center">'.$langs->trans("CurrentChecksum").'</td>';
2230  $out .= '<td class="right">'.$langs->trans("Size").'</td>';
2231  $out .= '<td class="right">'.$langs->trans("DateModification").'</td>';
2232  $out .= '</tr>'."\n";
2233  $tmpfilelist3 = dol_sort_array($file_list['added'], 'filename');
2234  if (is_array($tmpfilelist3) && count($tmpfilelist3)) {
2235  $i = 0;
2236  foreach ($tmpfilelist3 as $file) {
2237  $i++;
2238  $out .= '<tr class="oddeven">';
2239  $out .= '<td>'.$i.'</td>'."\n";
2240  $out .= '<td>'.$file['filename'].'</td>'."\n";
2241  $out .= '<td class="center">'.$file['expectedmd5'].'</td>'."\n";
2242  $out .= '<td class="center">'.$file['md5'].'</td>'."\n";
2243  $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
2244  $totalsize += $size;
2245  $out .= '<td class="right">'.dol_print_size($size).'</td>'."\n";
2246  $out .= '<td class="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']), 'dayhour').'</td>'."\n";
2247  $out .= "</tr>\n";
2248  }
2249  $out .= '<tr class="liste_total">';
2250  $out .= '<td></td>'."\n";
2251  $out .= '<td>'.$langs->trans("Total").'</td>'."\n";
2252  $out .= '<td align="center"></td>'."\n";
2253  $out .= '<td align="center"></td>'."\n";
2254  $out .= '<td class="right">'.dol_print_size($totalsize).'</td>'."\n";
2255  $out .= '<td class="right"></td>'."\n";
2256  $out .= "</tr>\n";
2257  } else {
2258  $out .= '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
2259  }
2260  $out .= '</table>';
2261  $out .= '</div>';
2262 
2263 
2264  // Show warning
2265  if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) {
2266  //setEventMessages($langs->trans("FileIntegrityIsStrictlyConformedWithReference"), null, 'mesgs');
2267  } else {
2268  //setEventMessages($langs->trans("FileIntegritySomeFilesWereRemovedOrModified"), null, 'warnings');
2269  }
2270  } else {
2271  throw new RestException(500, 'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile);
2272  }
2273 
2274 
2275  // Scan scripts
2276  asort($checksumconcat); // Sort list of checksum
2277  $checksumget = md5(join(',', $checksumconcat));
2278  $checksumtoget = trim((string) $xml->dolibarr_htdocs_dir_checksum);
2279 
2280  $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans("Unknown"));
2281  if ($checksumget == $checksumtoget) {
2282  if (count($file_list['added'])) {
2283  $resultcode = 'warning';
2284  $resultcomment = 'FileIntegrityIsOkButFilesWereAdded';
2285  //$outcurrentchecksum = $checksumget.' - <span class="'.$resultcode.'">'.$langs->trans("FileIntegrityIsOkButFilesWereAdded").'</span>';
2286  $outcurrentchecksum = $checksumget;
2287  } else {
2288  $resultcode = 'ok';
2289  $resultcomment = 'Success';
2290  //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
2291  $outcurrentchecksum = $checksumget;
2292  }
2293  } else {
2294  $resultcode = 'error';
2295  $resultcomment = 'Error';
2296  //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
2297  $outcurrentchecksum = $checksumget;
2298  }
2299  } else {
2300  throw new RestException(404, 'No signature file known');
2301  }
2302 
2303  return array('resultcode'=>$resultcode, 'resultcomment'=>$resultcomment, 'expectedchecksum'=> $outexpectedchecksum, 'currentchecksum'=> $outcurrentchecksum, 'out'=>$out);
2304  }
2305 
2306 
2316  public function getModules()
2317  {
2318  global $conf;
2319 
2320  if (!DolibarrApiAccess::$user->admin
2321  && (empty($conf->global->API_LOGINS_ALLOWED_FOR_GET_MODULES) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_GET_MODULES)) {
2322  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');
2323  }
2324 
2325  sort($conf->modules);
2326 
2327  return $this->_cleanObjectDatas($conf->modules);
2328  }
2329 }
Cregion
Class to manage dictionary Regions.
Definition: cregion.class.php:28
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1323
forgeSQLFromUniversalSearchCriteria
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
Definition: functions.lib.php:11933
Setup\getCountryByID
getCountryByID($id, $lang='')
Get country by ID.
Definition: api_setup.class.php:531
Setup\getEtablishmentByID
getEtablishmentByID($id)
Get establishment by ID.
Definition: api_setup.class.php:1951
Setup\getListOfStates
getListOfStates($sortfield="code_departement", $sortorder='ASC', $limit=100, $page=0, $country=0, $filter='', $sqlfilters='')
Get the list of states/provinces.
Definition: api_setup.class.php:361
dol_filemtime
dol_filemtime($pathoffile)
Return time of a file.
Definition: files.lib.php:599
Setup
Definition: api_setup.class.php:38
Setup\getListOfContactTypes
getListOfContactTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $type='', $module='', $active=1, $lang='', $sqlfilters='')
Get the list of contacts types.
Definition: api_setup.class.php:901
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5477
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:609
Setup\getListOfEventTypes
getListOfEventTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $type='', $module='', $active=1, $sqlfilters='')
Get the list of events types.
Definition: api_setup.class.php:770
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:8922
Translate
Class to manage translations.
Definition: translate.class.php:30
dol_dir_list
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:62
Setup\getCountryByISO
getCountryByISO($iso, $lang='')
Get country by Iso.
Definition: api_setup.class.php:563
Setup\_fetchCregion
_fetchCregion($id, $code='')
Get region.
Definition: api_setup.class.php:577
Setup\getTicketsTypes
getTicketsTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of tickets types.
Definition: api_setup.class.php:1740
Ccountry
Class to manage dictionary Countries (used by imports)
Definition: ccountry.class.php:33
Setup\getConf
getConf($constantname)
Get value of a setup variables.
Definition: api_setup.class.php:1978
Setup\getModules
getModules()
Get list of enabled modules.
Definition: api_setup.class.php:2316
Setup\getRegionByID
getRegionByID($id)
Get region by ID.
Definition: api_setup.class.php:320
Setup\getPaymentTerms
getPaymentTerms($sortfield="sortorder", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of payments terms.
Definition: api_setup.class.php:1248
dol_is_file
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:483
Setup\getListOfExpenseReportsTypes
getListOfExpenseReportsTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $module='', $active=1, $sqlfilters='')
Get the list of Expense Report types.
Definition: api_setup.class.php:836
getURLContent
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
DolibarrApi
Class for API REST v1.
Definition: api.class.php:30
isASecretKey
isASecretKey($keyname)
Return if string has a name dedicated to store a secret.
Definition: functions.lib.php:343
jsonOrUnserialize
jsonOrUnserialize($stringtodecode)
Decode an encode string.
Definition: functions.lib.php:11909
Setup\getListOfCountries
getListOfCountries($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $filter='', $lang='', $sqlfilters='')
Get the list of countries.
Definition: api_setup.class.php:467
getFilesUpdated
getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path='', $pathref='', &$checksumconcat=array())
Function to get list of updated or modified files.
Definition: files.lib.php:3381
Setup\getShippingModes
getShippingModes($limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of shipping methods.
Definition: api_setup.class.php:1311
Setup\getRegionByCode
getRegionByCode($code)
Get region by Code.
Definition: api_setup.class.php:335
Setup\getListOfsocialNetworks
getListOfsocialNetworks($sortfield="rowid", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of social networks.
Definition: api_setup.class.php:1550
Setup\getListOfCivilities
getListOfCivilities($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $module='', $active=1, $lang='', $sqlfilters='')
Get the list of civilities.
Definition: api_setup.class.php:969
Setup\getTicketsCategories
getTicketsCategories($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of tickets categories.
Definition: api_setup.class.php:1616
DolibarrApi\_checkFilters
_checkFilters($sqlfilters, &$error='')
Return if a $sqlfilters parameter is valid Function no more used.
Definition: api.class.php:310
Setup\_fetchCcountry
_fetchCcountry($id, $code='', $iso='', $lang='')
Get country.
Definition: api_setup.class.php:625
Setup\__construct
__construct()
Constructor.
Definition: api_setup.class.php:45
Setup\getCompany
getCompany()
Get properties of company.
Definition: api_setup.class.php:1858
Setup\getCheckIntegrity
getCheckIntegrity($target)
Do a test of integrity for files and setup.
Definition: api_setup.class.php:2010
Cstate
Class to manage dictionary States (used by imports)
Definition: cstate.class.php:27
Setup\getListOfTowns
getListOfTowns($sortfield="zip,town", $sortorder='ASC', $limit=100, $page=0, $zipcode='', $town='', $active=1, $sqlfilters='')
Get the list of towns.
Definition: api_setup.class.php:1183
Setup\getStateByID
getStateByID($id)
Get state by ID.
Definition: api_setup.class.php:426
Setup\_cleanObjectDatas
_cleanObjectDatas($object)
Clean sensible object datas.
Definition: api_setup.class.php:712
Setup\getListOfStaff
getListOfStaff($sortfield="id", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of staff.
Definition: api_setup.class.php:1492
Setup\getCountryByCode
getCountryByCode($code, $lang='')
Get country by Code.
Definition: api_setup.class.php:547
$sql
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
Definition: index.php:746
Setup\getTicketsSeverities
getTicketsSeverities($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of tickets severity.
Definition: api_setup.class.php:1678
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:207
getDolGlobalString
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:142
Setup\getListOfExtrafields
getListOfExtrafields($sortfield="t.pos", $sortorder='ASC', $type='', $sqlfilters='')
Get the list of extra fields.
Definition: api_setup.class.php:1102
dol_filesize
dol_filesize($pathoffile)
Return size of a file.
Definition: files.lib.php:587
Setup\_fetchCstate
_fetchCstate($id, $code='')
Get state.
Definition: api_setup.class.php:600
Setup\getListOfIncoterms
getListOfIncoterms($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of incoterms.
Definition: api_setup.class.php:1803
Setup\getStateByCode
getStateByCode($code)
Get state by Code.
Definition: api_setup.class.php:441
Setup\getEstablishments
getEstablishments()
Get the list of establishments.
Definition: api_setup.class.php:1913
Setup\getListOfCurrencies
getListOfCurrencies($multicurrency=0, $sortfield="code_iso", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of currencies.
Definition: api_setup.class.php:1033
Setup\getPaymentTypes
getPaymentTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of payments types.
Definition: api_setup.class.php:192
Setup\getListOfLegalForm
getListOfLegalForm($sortfield="rowid", $sortorder='ASC', $limit=100, $page=0, $country=0, $active=1, $sqlfilters='')
Get the list of legal form of business.
Definition: api_setup.class.php:1431
Establishment
Class to manage establishments.
Definition: establishment.class.php:30
Setup\getListOfRegions
getListOfRegions($sortfield="code_region", $sortorder='ASC', $limit=100, $page=0, $country=0, $filter='', $sqlfilters='')
Get the list of regions.
Definition: api_setup.class.php:257
Setup\getAvailability
getAvailability($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of delivery times.
Definition: api_setup.class.php:658
Setup\getOrderingOrigins
getOrderingOrigins($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of ordering origins.
Definition: api_setup.class.php:129
Setup\translateLabel
translateLabel($object, $lang, $prefix='Country', $dict=array('dict'))
Translate the name of the object to the given language.
Definition: api_setup.class.php:732
Setup\getListOfMeasuringUnits
getListOfMeasuringUnits($sortfield="rowid", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of measuring units.
Definition: api_setup.class.php:1372
Setup\getOrderingMethods
getOrderingMethods($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of ordering methods.
Definition: api_setup.class.php:67