dolibarr  18.0.0-alpha
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  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
81  if ($errormessage) {
82  throw new RestException(503, 'Error when validating parameter sqlfilters -> '.$errormessage);
83  }
84  }
85 
86 
87  $sql .= $this->db->order($sortfield, $sortorder);
88 
89  if ($limit) {
90  if ($page < 0) {
91  $page = 0;
92  }
93  $offset = $limit * $page;
94 
95  $sql .= $this->db->plimit($limit, $offset);
96  }
97 
98  $result = $this->db->query($sql);
99 
100  if ($result) {
101  $num = $this->db->num_rows($result);
102  $min = min($num, ($limit <= 0 ? $num : $limit));
103  for ($i = 0; $i < $min; $i++) {
104  $list[] = $this->db->fetch_object($result);
105  }
106  } else {
107  throw new RestException(400, $this->db->lasterror());
108  }
109 
110  return $list;
111  }
112 
129  public function getOrderingOrigins($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
130  {
131  $list = array();
132 
133  if (!DolibarrApiAccess::$user->rights->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->rights->propal->lire && !DolibarrApiAccess::$user->rights->commande->lire && !DolibarrApiAccess::$user->rights->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  }
260  public function getListOfStates($sortfield = "code_departement", $sortorder = 'ASC', $limit = 100, $page = 0, $country = 0, $filter = '', $sqlfilters = '')
261  {
262  $list = array();
263 
264  // Note: The filter is not applied in the SQL request because it must
265  // be applied to the translated names, not to the names in database.
266  $sql = "SELECT t.rowid FROM ".MAIN_DB_PREFIX."c_departements as t";
267  if ($country) {
268  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_regions as d ON t.fk_region = d.code_region";
269  }
270  $sql .= " WHERE 1 = 1";
271  if ($country) {
272  $sql .= " AND d.fk_pays = ".((int) $country);
273  }
274  // Add sql filters
275  if ($sqlfilters) {
276  $errormessage = '';
277  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
278  if ($errormessage) {
279  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
280  }
281  }
282 
283  $sql .= $this->db->order($sortfield, $sortorder);
284 
285  if ($limit) {
286  if ($page < 0) {
287  $page = 0;
288  }
289  $offset = $limit * $page;
290 
291  $sql .= $this->db->plimit($limit, $offset);
292  }
293 
294  $result = $this->db->query($sql);
295 
296  if ($result) {
297  $num = $this->db->num_rows($result);
298  $min = min($num, ($limit <= 0 ? $num : $limit));
299  for ($i = 0; $i < $min; $i++) {
300  $obj = $this->db->fetch_object($result);
301  $state = new Cstate($this->db);
302  if ($state->fetch($obj->rowid) > 0) {
303  if (empty($filter) || stripos($state->label, $filter) !== false) {
304  $list[] = $this->_cleanObjectDatas($state);
305  }
306  }
307  }
308  } else {
309  throw new RestException(503, 'Error when retrieving list of states');
310  }
311 
312  return $list;
313  }
314 
325  public function getStateByID($id)
326  {
327  return $this->_fetchCstate($id, '');
328  }
329 
340  public function getStateByCode($code)
341  {
342  return $this->_fetchCstate('', $code);
343  }
344 
366  public function getListOfCountries($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $filter = '', $lang = '', $sqlfilters = '')
367  {
368  $list = array();
369 
370  // Note: The filter is not applied in the SQL request because it must
371  // be applied to the translated names, not to the names in database.
372  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_country as t";
373  $sql .= " WHERE 1 = 1";
374  // Add sql filters
375  if ($sqlfilters) {
376  $errormessage = '';
377  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
378  if ($errormessage) {
379  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
380  }
381  }
382 
383  $sql .= $this->db->order($sortfield, $sortorder);
384 
385  if ($limit) {
386  if ($page < 0) {
387  $page = 0;
388  }
389  $offset = $limit * $page;
390 
391  $sql .= $this->db->plimit($limit, $offset);
392  }
393 
394  $result = $this->db->query($sql);
395 
396  if ($result) {
397  $num = $this->db->num_rows($result);
398  $min = min($num, ($limit <= 0 ? $num : $limit));
399  for ($i = 0; $i < $min; $i++) {
400  $obj = $this->db->fetch_object($result);
401  $country = new Ccountry($this->db);
402  if ($country->fetch($obj->rowid) > 0) {
403  // Translate the name of the country if needed
404  // and then apply the filter if there is one.
405  $this->translateLabel($country, $lang, 'Country');
406 
407  if (empty($filter) || stripos($country->label, $filter) !== false) {
408  $list[] = $this->_cleanObjectDatas($country);
409  }
410  }
411  }
412  } else {
413  throw new RestException(503, 'Error when retrieving list of countries');
414  }
415 
416  return $list;
417  }
418 
430  public function getCountryByID($id, $lang = '')
431  {
432  return $this->_fetchCcountry($id, '', '', $lang);
433  }
434 
446  public function getCountryByCode($code, $lang = '')
447  {
448  return $this->_fetchCcountry('', $code, '', $lang);
449  }
450 
462  public function getCountryByISO($iso, $lang = '')
463  {
464  return $this->_fetchCcountry('', '', $iso, $lang);
465  }
466 
476  private function _fetchCstate($id, $code = '')
477  {
478  $state = new Cstate($this->db);
479 
480  $result = $state->fetch($id, $code);
481  if ($result < 0) {
482  throw new RestException(503, 'Error when retrieving state : '.$state->error);
483  } elseif ($result == 0) {
484  throw new RestException(404, 'State not found');
485  }
486 
487  return $this->_cleanObjectDatas($state);
488  }
489 
501  private function _fetchCcountry($id, $code = '', $iso = '', $lang = '')
502  {
503  $country = new Ccountry($this->db);
504 
505  $result = $country->fetch($id, $code, $iso);
506 
507  if ($result < 0) {
508  throw new RestException(503, 'Error when retrieving country : '.$country->error);
509  } elseif ($result == 0) {
510  throw new RestException(404, 'Country not found');
511  }
512 
513  $this->translateLabel($country, $lang, 'Country');
514 
515  return $this->_cleanObjectDatas($country);
516  }
517 
534  public function getAvailability($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
535  {
536  $list = array();
537 
538  if (!DolibarrApiAccess::$user->rights->commande->lire) {
539  throw new RestException(401);
540  }
541 
542  $sql = "SELECT rowid, code, label";
543  $sql .= " FROM ".MAIN_DB_PREFIX."c_availability as t";
544  $sql .= " WHERE t.active = ".((int) $active);
545  // Add sql filters
546  if ($sqlfilters) {
547  $errormessage = '';
548  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
549  if ($errormessage) {
550  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
551  }
552  }
553 
554 
555  $sql .= $this->db->order($sortfield, $sortorder);
556 
557  if ($limit) {
558  if ($page < 0) {
559  $page = 0;
560  }
561  $offset = $limit * $page;
562 
563  $sql .= $this->db->plimit($limit, $offset);
564  }
565 
566  $result = $this->db->query($sql);
567 
568  if ($result) {
569  $num = $this->db->num_rows($result);
570  $min = min($num, ($limit <= 0 ? $num : $limit));
571  for ($i = 0; $i < $min; $i++) {
572  $list[] = $this->db->fetch_object($result);
573  }
574  } else {
575  throw new RestException(400, $this->db->lasterror());
576  }
577 
578  return $list;
579  }
580 
581  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
588  protected function _cleanObjectDatas($object)
589  {
590  // phpcs:enable
591  $object = parent::_cleanObjectDatas($object);
592 
593  unset($object->error);
594  unset($object->errors);
595 
596  return $object;
597  }
598 
608  private function translateLabel($object, $lang, $prefix = 'Country', $dict = array('dict'))
609  {
610  if (!empty($lang)) {
611  // Load the translations if this is a new language.
612  if ($this->translations == null || $this->translations->getDefaultLang() !== $lang) {
613  global $conf;
614  $this->translations = new Translate('', $conf);
615  $this->translations->setDefaultLang($lang);
616  $this->translations->loadLangs($dict);
617  }
618  if ($object->code) {
619  $key = $prefix.$object->code;
620 
621  $translation = $this->translations->trans($key);
622  if ($translation != $key) {
623  $object->label = html_entity_decode($translation);
624  }
625  }
626  }
627  }
628 
646  public function getListOfEventTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $active = 1, $sqlfilters = '')
647  {
648  $list = array();
649 
650  $sql = "SELECT id, code, type, libelle as label, module";
651  $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t";
652  $sql .= " WHERE t.active = ".((int) $active);
653  if ($type) {
654  $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'";
655  }
656  if ($module) {
657  $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
658  }
659  // Add sql filters
660  if ($sqlfilters) {
661  $errormessage = '';
662  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
663  if ($errormessage) {
664  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
665  }
666  }
667 
668 
669  $sql .= $this->db->order($sortfield, $sortorder);
670 
671  if ($limit) {
672  if ($page < 0) {
673  $page = 0;
674  }
675  $offset = $limit * $page;
676 
677  $sql .= $this->db->plimit($limit, $offset);
678  }
679 
680  $result = $this->db->query($sql);
681 
682  if ($result) {
683  $num = $this->db->num_rows($result);
684  $min = min($num, ($limit <= 0 ? $num : $limit));
685  for ($i = 0; $i < $min; $i++) {
686  $list[] = $this->db->fetch_object($result);
687  }
688  } else {
689  throw new RestException(503, 'Error when retrieving list of events types : '.$this->db->lasterror());
690  }
691 
692  return $list;
693  }
694 
695 
712  public function getListOfExpenseReportsTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $module = '', $active = 1, $sqlfilters = '')
713  {
714  $list = array();
715 
716  $sql = "SELECT id, code, label, accountancy_code, active, module, position";
717  $sql .= " FROM ".MAIN_DB_PREFIX."c_type_fees as t";
718  $sql .= " WHERE t.active = ".((int) $active);
719  if ($module) {
720  $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
721  }
722  // Add sql filters
723  if ($sqlfilters) {
724  $errormessage = '';
725  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
726  if ($errormessage) {
727  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
728  }
729  }
730 
731 
732  $sql .= $this->db->order($sortfield, $sortorder);
733 
734  if ($limit) {
735  if ($page < 0) {
736  $page = 0;
737  }
738  $offset = $limit * $page;
739 
740  $sql .= $this->db->plimit($limit, $offset);
741  }
742 
743  $result = $this->db->query($sql);
744 
745  if ($result) {
746  $num = $this->db->num_rows($result);
747  $min = min($num, ($limit <= 0 ? $num : $limit));
748  for ($i = 0; $i < $min; $i++) {
749  $list[] = $this->db->fetch_object($result);
750  }
751  } else {
752  throw new RestException(503, 'Error when retrieving list of expense report types : '.$this->db->lasterror());
753  }
754 
755  return $list;
756  }
757 
758 
777  public function getListOfContactTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $active = 1, $lang = '', $sqlfilters = '')
778  {
779  $list = array();
780 
781  $sql = "SELECT rowid, code, element as type, libelle as label, source, module, position";
782  $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as t";
783  $sql .= " WHERE t.active = ".((int) $active);
784  if ($type) {
785  $sql .= " AND type LIKE '%".$this->db->escape($type)."%'";
786  }
787  if ($module) {
788  $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
789  }
790  // Add sql filters
791  if ($sqlfilters) {
792  $errormessage = '';
793  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
794  if ($errormessage) {
795  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
796  }
797  }
798 
799 
800  $sql .= $this->db->order($sortfield, $sortorder);
801 
802  if ($limit) {
803  if ($page < 0) {
804  $page = 0;
805  }
806  $offset = $limit * $page;
807 
808  $sql .= $this->db->plimit($limit, $offset);
809  }
810 
811  $result = $this->db->query($sql);
812 
813  if ($result) {
814  $num = $this->db->num_rows($result);
815  $min = min($num, ($limit <= 0 ? $num : $limit));
816  for ($i = 0; $i < $min; $i++) {
817  $contact_type = $this->db->fetch_object($result);
818  $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"));
819  $list[] = $contact_type;
820  }
821  } else {
822  throw new RestException(503, 'Error when retrieving list of contacts types : '.$this->db->lasterror());
823  }
824 
825  return $list;
826  }
827 
845  public function getListOfCivilities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $module = '', $active = 1, $lang = '', $sqlfilters = '')
846  {
847  $list = array();
848 
849  $sql = "SELECT rowid, code, label, module";
850  $sql .= " FROM ".MAIN_DB_PREFIX."c_civility as t";
851  $sql .= " WHERE t.active = ".((int) $active);
852  if ($module) {
853  $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
854  }
855  // Add sql filters
856  if ($sqlfilters) {
857  $errormessage = '';
858  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
859  if ($errormessage) {
860  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
861  }
862  }
863 
864 
865  $sql .= $this->db->order($sortfield, $sortorder);
866 
867  if ($limit) {
868  if ($page < 0) {
869  $page = 0;
870  }
871  $offset = $limit * $page;
872 
873  $sql .= $this->db->plimit($limit, $offset);
874  }
875 
876  $result = $this->db->query($sql);
877 
878  if ($result) {
879  $num = $this->db->num_rows($result);
880  $min = min($num, ($limit <= 0 ? $num : $limit));
881  for ($i = 0; $i < $min; $i++) {
882  $civility = $this->db->fetch_object($result);
883  $this->translateLabel($civility, $lang, 'Civility', array('dict'));
884  $list[] = $civility;
885  }
886  } else {
887  throw new RestException(503, 'Error when retrieving list of civility : '.$this->db->lasterror());
888  }
889 
890  return $list;
891  }
892 
909  public function getListOfCurrencies($multicurrency = 0, $sortfield = "code_iso", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
910  {
911  $list = array();
912  $sql = "SELECT t.code_iso, t.label, t.unicode";
913  if (!empty($multicurrency)) {
914  $sql .= " , cr.date_sync, cr.rate ";
915  }
916  $sql .= " FROM ".MAIN_DB_PREFIX."c_currencies as t";
917  if (!empty($multicurrency)) {
918  $sql .= " JOIN ".MAIN_DB_PREFIX."multicurrency as m ON m.code=t.code_iso";
919  $sql .= " JOIN ".MAIN_DB_PREFIX."multicurrency_rate as cr ON (m.rowid = cr.fk_multicurrency)";
920  }
921  $sql .= " WHERE t.active = ".((int) $active);
922  if (!empty($multicurrency)) {
923  $sql .= " AND m.entity IN (".getEntity('multicurrency').")";
924  if (!empty($multicurrency) && $multicurrency != 2) {
925  $sql .= " AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM ".MAIN_DB_PREFIX."multicurrency_rate AS cr2 WHERE cr2.fk_multicurrency = m.rowid)";
926  }
927  }
928 
929  // Add sql filters
930  if ($sqlfilters) {
931  $errormessage = '';
932  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
933  if ($errormessage) {
934  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
935  }
936  }
937 
938 
939  $sql .= $this->db->order($sortfield, $sortorder);
940 
941  if ($limit) {
942  if ($page < 0) {
943  $page = 0;
944  }
945  $offset = $limit * $page;
946 
947  $sql .= $this->db->plimit($limit, $offset);
948  }
949 
950  $result = $this->db->query($sql);
951 
952  if ($result) {
953  $num = $this->db->num_rows($result);
954  $min = min($num, ($limit <= 0 ? $num : $limit));
955  for ($i = 0; $i < $min; $i++) {
956  $list[] = $this->db->fetch_object($result);
957  }
958  } else {
959  throw new RestException(503, 'Error when retrieving list of currency : '.$this->db->lasterror());
960  }
961 
962  return $list;
963  }
964 
978  public function getListOfExtrafields($sortfield = "t.pos", $sortorder = 'ASC', $type = '', $sqlfilters = '')
979  {
980  $list = array();
981 
982  if (!DolibarrApiAccess::$user->admin) {
983  throw new RestException(401, 'Only an admin user can get list of extrafields');
984  }
985 
986  if ($type == 'thirdparty') {
987  $type = 'societe';
988  }
989  if ($type == 'contact') {
990  $type = 'socpeople';
991  }
992 
993  $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";
994  $sql .= " FROM ".MAIN_DB_PREFIX."extrafields as t";
995  $sql .= " WHERE t.entity IN (".getEntity('extrafields').")";
996  if (!empty($type)) {
997  $sql .= " AND t.elementtype = '".$this->db->escape($type)."'";
998  }
999  // Add sql filters
1000  if ($sqlfilters) {
1001  $errormessage = '';
1002  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1003  if ($errormessage) {
1004  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1005  }
1006  }
1007 
1008  $sql .= $this->db->order($sortfield, $sortorder);
1009 
1010  $resql = $this->db->query($sql);
1011  if ($resql) {
1012  if ($this->db->num_rows($resql)) {
1013  while ($tab = $this->db->fetch_object($resql)) {
1014  // New usage
1015  $list[$tab->elementtype][$tab->name]['type'] = $tab->type;
1016  $list[$tab->elementtype][$tab->name]['label'] = $tab->label;
1017  $list[$tab->elementtype][$tab->name]['size'] = $tab->size;
1018  $list[$tab->elementtype][$tab->name]['elementtype'] = $tab->elementtype;
1019  $list[$tab->elementtype][$tab->name]['default'] = $tab->fielddefault;
1020  $list[$tab->elementtype][$tab->name]['computed'] = $tab->fieldcomputed;
1021  $list[$tab->elementtype][$tab->name]['unique'] = $tab->fieldunique;
1022  $list[$tab->elementtype][$tab->name]['required'] = $tab->fieldrequired;
1023  $list[$tab->elementtype][$tab->name]['param'] = ($tab->param ? jsonOrUnserialize($tab->param) : ''); // This may be a string encoded with serialise() or json_encode()
1024  $list[$tab->elementtype][$tab->name]['pos'] = $tab->pos;
1025  $list[$tab->elementtype][$tab->name]['alwayseditable'] = $tab->alwayseditable;
1026  $list[$tab->elementtype][$tab->name]['perms'] = $tab->perms;
1027  $list[$tab->elementtype][$tab->name]['list'] = $tab->list;
1028  }
1029  }
1030  } else {
1031  throw new RestException(503, 'Error when retrieving list of extra fields : '.$this->db->lasterror());
1032  }
1033 
1034  if (!count($list)) {
1035  throw new RestException(404, 'No extrafield found');
1036  }
1037 
1038  return $list;
1039  }
1040 
1041 
1059  public function getListOfTowns($sortfield = "zip,town", $sortorder = 'ASC', $limit = 100, $page = 0, $zipcode = '', $town = '', $active = 1, $sqlfilters = '')
1060  {
1061  $list = array();
1062 
1063  $sql = "SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
1064  $sql .= " FROM ".MAIN_DB_PREFIX."c_ziptown as t";
1065  $sql .= " WHERE t.active = ".((int) $active);
1066  if ($zipcode) {
1067  $sql .= " AND t.zip LIKE '%".$this->db->escape($zipcode)."%'";
1068  }
1069  if ($town) {
1070  $sql .= " AND t.town LIKE '%".$this->db->escape($town)."%'";
1071  }
1072  // Add sql filters
1073  if ($sqlfilters) {
1074  $errormessage = '';
1075  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1076  if ($errormessage) {
1077  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1078  }
1079  }
1080 
1081 
1082  $sql .= $this->db->order($sortfield, $sortorder);
1083 
1084  if ($limit) {
1085  if ($page < 0) {
1086  $page = 0;
1087  }
1088  $offset = $limit * $page;
1089 
1090  $sql .= $this->db->plimit($limit, $offset);
1091  }
1092 
1093  $result = $this->db->query($sql);
1094 
1095  if ($result) {
1096  $num = $this->db->num_rows($result);
1097  $min = min($num, ($limit <= 0 ? $num : $limit));
1098  for ($i = 0; $i < $min; $i++) {
1099  $list[] = $this->db->fetch_object($result);
1100  }
1101  } else {
1102  throw new RestException(503, 'Error when retrieving list of towns : '.$this->db->lasterror());
1103  }
1104 
1105  return $list;
1106  }
1107 
1124  public function getPaymentTerms($sortfield = "sortorder", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1125  {
1126  $list = array();
1127 
1128  if (!DolibarrApiAccess::$user->rights->propal->lire && !DolibarrApiAccess::$user->rights->commande->lire && !DolibarrApiAccess::$user->rights->facture->lire) {
1129  throw new RestException(401);
1130  }
1131 
1132  $sql = "SELECT rowid as id, code, sortorder, libelle as label, libelle_facture as descr, type_cdr, nbjour, decalage, module";
1133  $sql .= " FROM ".MAIN_DB_PREFIX."c_payment_term as t";
1134  $sql .= " WHERE t.entity IN (".getEntity('c_payment_term').")";
1135  $sql .= " AND t.active = ".((int) $active);
1136  // Add sql filters
1137  if ($sqlfilters) {
1138  $errormessage = '';
1139  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1140  if ($errormessage) {
1141  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1142  }
1143  }
1144 
1145 
1146  $sql .= $this->db->order($sortfield, $sortorder);
1147 
1148  if ($limit) {
1149  if ($page < 0) {
1150  $page = 0;
1151  }
1152  $offset = $limit * $page;
1153 
1154  $sql .= $this->db->plimit($limit, $offset);
1155  }
1156 
1157  $result = $this->db->query($sql);
1158 
1159  if ($result) {
1160  $num = $this->db->num_rows($result);
1161  $min = min($num, ($limit <= 0 ? $num : $limit));
1162  for ($i = 0; $i < $min; $i++) {
1163  $list[] = $this->db->fetch_object($result);
1164  }
1165  } else {
1166  throw new RestException(400, $this->db->lasterror());
1167  }
1168 
1169  return $list;
1170  }
1171 
1187  public function getShippingModes($limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1188  {
1189  $list = array();
1190 
1191  $sql = "SELECT rowid as id, code, libelle as label, description, tracking, module";
1192  $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as t";
1193  $sql .= " WHERE t.entity IN (".getEntity('c_shipment_mode').")";
1194  $sql .= " AND t.active = ".((int) $active);
1195  // Add sql filters
1196  if ($sqlfilters) {
1197  $errormessage = '';
1198  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1199  if ($errormessage) {
1200  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1201  }
1202  }
1203 
1204 
1205  //$sql.= $this->db->order($sortfield, $sortorder);
1206 
1207  if ($limit) {
1208  if ($page < 0) {
1209  $page = 0;
1210  }
1211  $offset = $limit * $page;
1212 
1213  $sql .= $this->db->plimit($limit, $offset);
1214  }
1215 
1216  $result = $this->db->query($sql);
1217 
1218  if ($result) {
1219  $num = $this->db->num_rows($result);
1220  $min = min($num, ($limit <= 0 ? $num : $limit));
1221  for ($i = 0; $i < $min; $i++) {
1222  $method = $this->db->fetch_object($result);
1223  $this->translateLabel($method, $lang, '', array('dict'));
1224  $list[] = $method;
1225  }
1226  } else {
1227  throw new RestException(400, $this->db->lasterror());
1228  }
1229 
1230  return $list;
1231  }
1232 
1248  public function getListOfMeasuringUnits($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1249  {
1250  $list = array();
1251 
1252  $sql = "SELECT t.rowid, t.code, t.label,t.short_label, t.active, t.scale, t.unit_type";
1253  $sql .= " FROM ".MAIN_DB_PREFIX."c_units as t";
1254  $sql .= " WHERE t.active = ".((int) $active);
1255  // Add sql filters
1256  if ($sqlfilters) {
1257  $errormessage = '';
1258  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1259  if ($errormessage) {
1260  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1261  }
1262  }
1263 
1264 
1265  $sql .= $this->db->order($sortfield, $sortorder);
1266 
1267  if ($limit) {
1268  if ($page < 0) {
1269  $page = 0;
1270  }
1271  $offset = $limit * $page;
1272 
1273  $sql .= $this->db->plimit($limit, $offset);
1274  }
1275 
1276  $result = $this->db->query($sql);
1277 
1278  if ($result) {
1279  $num = $this->db->num_rows($result);
1280  $min = min($num, ($limit <= 0 ? $num : $limit));
1281  for ($i = 0; $i < $min; $i++) {
1282  $list[] = $this->db->fetch_object($result);
1283  }
1284  } else {
1285  throw new RestException(503, 'Error when retrieving list of measuring units: '.$this->db->lasterror());
1286  }
1287 
1288  return $list;
1289  }
1290 
1307  public function getListOfLegalForm($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $country = 0, $active = 1, $sqlfilters = '')
1308  {
1309  $list = array();
1310 
1311  $sql = "SELECT t.rowid, t.code, t.fk_pays, t.libelle, t.isvatexempted, t.active, t.module, t.position";
1312  $sql .= " FROM ".MAIN_DB_PREFIX."c_forme_juridique as t";
1313  $sql .= " WHERE t.active = ".((int) $active);
1314  if ($country) {
1315  $sql .= " AND t.fk_pays = ".((int) $country);
1316  }
1317  // Add sql filters
1318  if ($sqlfilters) {
1319  $errormessage = '';
1320  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1321  if ($errormessage) {
1322  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1323  }
1324  }
1325 
1326 
1327  $sql .= $this->db->order($sortfield, $sortorder);
1328 
1329  if ($limit) {
1330  if ($page < 0) {
1331  $page = 0;
1332  }
1333  $offset = $limit * $page;
1334 
1335  $sql .= $this->db->plimit($limit, $offset);
1336  }
1337 
1338  $result = $this->db->query($sql);
1339 
1340  if ($result) {
1341  $num = $this->db->num_rows($result);
1342  $min = min($num, ($limit <= 0 ? $num : $limit));
1343  for ($i = 0; $i < $min; $i++) {
1344  $list[] = $this->db->fetch_object($result);
1345  }
1346  } else {
1347  throw new RestException(503, 'Error when retrieving list of legal form: '.$this->db->lasterror());
1348  }
1349 
1350  return $list;
1351  }
1352 
1368  public function getListOfStaff($sortfield = "id", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1369  {
1370  $list = array();
1371 
1372  $sql = "SELECT t.id, t.code, t.libelle, t.active, t.module";
1373  $sql .= " FROM ".MAIN_DB_PREFIX."c_effectif as t";
1374  $sql .= " WHERE t.active = ".((int) $active);
1375  // Add sql filters
1376  if ($sqlfilters) {
1377  $errormessage = '';
1378  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1379  if ($errormessage) {
1380  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1381  }
1382  }
1383 
1384 
1385  $sql .= $this->db->order($sortfield, $sortorder);
1386 
1387  if ($limit) {
1388  if ($page < 0) {
1389  $page = 0;
1390  }
1391  $offset = $limit * $page;
1392 
1393  $sql .= $this->db->plimit($limit, $offset);
1394  }
1395 
1396  $result = $this->db->query($sql);
1397 
1398  if ($result) {
1399  $num = $this->db->num_rows($result);
1400  $min = min($num, ($limit <= 0 ? $num : $limit));
1401  for ($i = 0; $i < $min; $i++) {
1402  $list[] = $this->db->fetch_object($result);
1403  }
1404  } else {
1405  throw new RestException(503, 'Error when retrieving list of staff: '.$this->db->lasterror());
1406  }
1407 
1408  return $list;
1409  }
1410 
1426  public function getListOfsocialNetworks($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1427  {
1428  global $conf;
1429 
1430  if (!isModEnabled('socialnetworks')) {
1431  throw new RestException(400, 'API not available: this dictionary is not enabled by setup');
1432  }
1433 
1434  $list = array();
1435  //TODO link with multicurrency module
1436  $sql = "SELECT t.rowid, t.entity, t.code, t.label, t.url, t.icon, t.active";
1437  $sql .= " FROM ".MAIN_DB_PREFIX."c_socialnetworks as t";
1438  $sql .= " WHERE t.entity IN (".getEntity('c_socialnetworks').")";
1439  $sql .= " AND t.active = ".((int) $active);
1440  // Add sql filters
1441  if ($sqlfilters) {
1442  $errormessage = '';
1443  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1444  if ($errormessage) {
1445  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1446  }
1447  }
1448 
1449 
1450  $sql .= $this->db->order($sortfield, $sortorder);
1451 
1452  if ($limit) {
1453  if ($page < 0) {
1454  $page = 0;
1455  }
1456  $offset = $limit * $page;
1457 
1458  $sql .= $this->db->plimit($limit, $offset);
1459  }
1460 
1461  $result = $this->db->query($sql);
1462 
1463  if ($result) {
1464  $num = $this->db->num_rows($result);
1465  $min = min($num, ($limit <= 0 ? $num : $limit));
1466  for ($i = 0; $i < $min; $i++) {
1467  $list[] = $this->db->fetch_object($result);
1468  }
1469  } else {
1470  throw new RestException(503, 'Error when retrieving list of social networks: '.$this->db->lasterror());
1471  }
1472 
1473  return $list;
1474  }
1475 
1492  public function getTicketsCategories($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1493  {
1494  $list = array();
1495 
1496  $sql = "SELECT rowid, code, pos, label, use_default, description";
1497  $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t";
1498  $sql .= " WHERE t.entity IN (".getEntity('c_ticket_category').")";
1499  $sql .= " AND t.active = ".((int) $active);
1500  // Add sql filters
1501  if ($sqlfilters) {
1502  $errormessage = '';
1503  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1504  if ($errormessage) {
1505  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1506  }
1507  }
1508 
1509 
1510  $sql .= $this->db->order($sortfield, $sortorder);
1511 
1512  if ($limit) {
1513  if ($page < 0) {
1514  $page = 0;
1515  }
1516  $offset = $limit * $page;
1517 
1518  $sql .= $this->db->plimit($limit, $offset);
1519  }
1520 
1521  $result = $this->db->query($sql);
1522 
1523  if ($result) {
1524  $num = $this->db->num_rows($result);
1525  $min = min($num, ($limit <= 0 ? $num : $limit));
1526  for ($i = 0; $i < $min; $i++) {
1527  $category = $this->db->fetch_object($result);
1528  $this->translateLabel($category, $lang, 'TicketCategoryShort', array('ticket'));
1529  $list[] = $category;
1530  }
1531  } else {
1532  throw new RestException(503, 'Error when retrieving list of ticket categories : '.$this->db->lasterror());
1533  }
1534 
1535  return $list;
1536  }
1537 
1554  public function getTicketsSeverities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1555  {
1556  $list = array();
1557 
1558  $sql = "SELECT rowid, code, pos, label, use_default, color, description";
1559  $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t";
1560  $sql .= " WHERE t.entity IN (".getEntity('c_ticket_severity').")";
1561  $sql .= " AND t.active = ".((int) $active);
1562  // Add sql filters
1563  if ($sqlfilters) {
1564  $errormessage = '';
1565  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1566  if ($errormessage) {
1567  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1568  }
1569  }
1570 
1571 
1572  $sql .= $this->db->order($sortfield, $sortorder);
1573 
1574  if ($limit) {
1575  if ($page < 0) {
1576  $page = 0;
1577  }
1578  $offset = $limit * $page;
1579 
1580  $sql .= $this->db->plimit($limit, $offset);
1581  }
1582 
1583  $result = $this->db->query($sql);
1584 
1585  if ($result) {
1586  $num = $this->db->num_rows($result);
1587  $min = min($num, ($limit <= 0 ? $num : $limit));
1588  for ($i = 0; $i < $min; $i++) {
1589  $severity = $this->db->fetch_object($result);
1590  $this->translateLabel($severity, $lang, 'TicketSeverityShort', array('ticket'));
1591  $list[] = $severity;
1592  }
1593  } else {
1594  throw new RestException(503, 'Error when retrieving list of ticket severities : '.$this->db->lasterror());
1595  }
1596 
1597  return $list;
1598  }
1599 
1616  public function getTicketsTypes($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_type as t";
1622  $sql .= " WHERE t.entity IN (".getEntity('c_ticket_type').")";
1623  $sql .= " AND t.active = ".((int) $active);
1624 
1625  // Add sql filters
1626  if ($sqlfilters) {
1627  $errormessage = '';
1628  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1629  if ($errormessage) {
1630  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1631  }
1632  }
1633 
1634 
1635  $sql .= $this->db->order($sortfield, $sortorder);
1636 
1637  if ($limit) {
1638  if ($page < 0) {
1639  $page = 0;
1640  }
1641  $offset = $limit * $page;
1642 
1643  $sql .= $this->db->plimit($limit, $offset);
1644  }
1645 
1646  $result = $this->db->query($sql);
1647 
1648  if ($result) {
1649  $num = $this->db->num_rows($result);
1650  $min = min($num, ($limit <= 0 ? $num : $limit));
1651  for ($i = 0; $i < $min; $i++) {
1652  $type =$this->db->fetch_object($result);
1653  $this->translateLabel($type, $lang, 'TicketTypeShort', array('ticket'));
1654  $list[] = $type;
1655  }
1656  } else {
1657  throw new RestException(503, 'Error when retrieving list of ticket types : '.$this->db->lasterror());
1658  }
1659 
1660  return $list;
1661  }
1662 
1679  public function getListOfIncoterms($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1680  {
1681  $list = array();
1682 
1683  $sql = "SELECT rowid, code, active";
1684  $sql .= " FROM ".MAIN_DB_PREFIX."c_incoterms as t";
1685  $sql .= " WHERE 1=1";
1686 
1687  // Add sql filters
1688  if ($sqlfilters) {
1689  $errormessage = '';
1690  if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {
1691  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1692  }
1693  $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
1694  $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
1695  }
1696 
1697 
1698  $sql .= $this->db->order($sortfield, $sortorder);
1699 
1700  if ($limit) {
1701  if ($page < 0) {
1702  $page = 0;
1703  }
1704  $offset = $limit * $page;
1705 
1706  $sql .= $this->db->plimit($limit, $offset);
1707  }
1708 
1709  $result = $this->db->query($sql);
1710 
1711  if ($result) {
1712  $num = $this->db->num_rows($result);
1713  $min = min($num, ($limit <= 0 ? $num : $limit));
1714  for ($i = 0; $i < $min; $i++) {
1715  $type =$this->db->fetch_object($result);
1716  $list[] = $type;
1717  }
1718  } else {
1719  throw new RestException(503, 'Error when retrieving list of incoterm types : '.$this->db->lasterror());
1720  }
1721 
1722  return $list;
1723  }
1724 
1734  public function getCompany()
1735  {
1736  global $conf, $mysoc;
1737 
1738  if (!DolibarrApiAccess::$user->admin
1739  && (empty($conf->global->API_LOGINS_ALLOWED_FOR_GET_COMPANY) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_GET_COMPANY)) {
1740  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');
1741  }
1742 
1743  unset($mysoc->pays);
1744  unset($mysoc->note);
1745  unset($mysoc->nom);
1746 
1747  unset($mysoc->lines);
1748 
1749  unset($mysoc->effectif);
1750  unset($mysoc->effectif_id);
1751  unset($mysoc->forme_juridique_code);
1752  unset($mysoc->forme_juridique);
1753  unset($mysoc->mode_reglement_supplier_id);
1754  unset($mysoc->cond_reglement_supplier_id);
1755  unset($mysoc->transport_mode_supplier_id);
1756  unset($mysoc->fk_prospectlevel);
1757 
1758  unset($mysoc->total_ht);
1759  unset($mysoc->total_tva);
1760  unset($mysoc->total_localtax1);
1761  unset($mysoc->total_localtax2);
1762  unset($mysoc->total_ttc);
1763 
1764  unset($mysoc->lastname);
1765  unset($mysoc->firstname);
1766  unset($mysoc->civility_id);
1767 
1768  unset($mysoc->client);
1769  unset($mysoc->prospect);
1770  unset($mysoc->fournisseur);
1771  unset($mysoc->contact_id);
1772 
1773  unset($mysoc->fk_incoterms);
1774  unset($mysoc->label_incoterms);
1775  unset($mysoc->location_incoterms);
1776 
1777  return $this->_cleanObjectDatas($mysoc);
1778  }
1779 
1789  public function getEstablishments()
1790  {
1791  $list = array();
1792 
1793  $limit = 0;
1794 
1795  $sql = "SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
1796  $sql .= " FROM ".MAIN_DB_PREFIX."establishment as e";
1797  $sql .= " WHERE e.entity IN (".getEntity('establishment').')';
1798  // if ($type) $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'";
1799  // if ($module) $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
1800  // Add sql filters
1801 
1802  $result = $this->db->query($sql);
1803 
1804  if ($result) {
1805  $num = $this->db->num_rows($result);
1806  $min = min($num, ($limit <= 0 ? $num : $limit));
1807  for ($i = 0; $i < $min; $i++) {
1808  $list[] = $this->db->fetch_object($result);
1809  }
1810  } else {
1811  throw new RestException(503, 'Error when retrieving list of establishments : '.$this->db->lasterror());
1812  }
1813 
1814  return $list;
1815  }
1816 
1827  public function getEtablishmentByID($id)
1828  {
1829  $establishment = new Establishment($this->db);
1830 
1831  $result = $establishment->fetch($id);
1832  if ($result < 0) {
1833  throw new RestException(503, 'Error when retrieving establishment : '.$establishment->error);
1834  } elseif ($result == 0) {
1835  throw new RestException(404, 'Establishment not found');
1836  }
1837 
1838  return $this->_cleanObjectDatas($establishment);
1839  }
1840 
1854  public function getConf($constantname)
1855  {
1856  global $conf;
1857 
1858  if (!DolibarrApiAccess::$user->admin
1859  && (!getDolGlobalString('API_LOGINS_ALLOWED_FOR_CONST_READ') || DolibarrApiAccess::$user->login != getDolGlobalString('API_LOGINS_ALLOWED_FOR_CONST_READ'))) {
1860  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');
1861  }
1862 
1863  if (!preg_match('/^[a-zA-Z0-9_]+$/', $constantname) || !isset($conf->global->$constantname)) {
1864  throw new RestException(404, 'Error Bad or unknown value for constantname');
1865  }
1866  if (isASecretKey($constantname)) {
1867  throw new RestException(403, 'Forbidden. This parameter cant be read with APIs');
1868  }
1869 
1870  return getDolGlobalString($constantname);
1871  }
1872 
1886  public function getCheckIntegrity($target)
1887  {
1888  global $langs, $conf;
1889 
1890  if (!DolibarrApiAccess::$user->admin
1891  && (empty($conf->global->API_LOGINS_ALLOWED_FOR_INTEGRITY_CHECK) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_INTEGRITY_CHECK)) {
1892  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');
1893  }
1894 
1895  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1896  require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
1897 
1898  $langs->load("admin");
1899 
1900  $outexpectedchecksum = '';
1901  $outcurrentchecksum = '';
1902 
1903  // Modified or missing files
1904  $file_list = array('missing' => array(), 'updated' => array());
1905 
1906  // Local file to compare to
1907  $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));
1908  $xmlfile = DOL_DOCUMENT_ROOT.'/install/'.$xmlshortfile;
1909  // Remote file to compare to
1910  $xmlremote = ($target == 'default' ? '' : $target);
1911  if (empty($xmlremote) && !empty($conf->global->MAIN_FILECHECK_URL)) {
1912  $xmlremote = $conf->global->MAIN_FILECHECK_URL;
1913  }
1914  $param = 'MAIN_FILECHECK_URL_'.DOL_VERSION;
1915  if (empty($xmlremote) && !empty($conf->global->$param)) {
1916  $xmlremote = $conf->global->$param;
1917  }
1918  if (empty($xmlremote)) {
1919  $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml';
1920  }
1921  if ($xmlremote && !preg_match('/^https?:\/\//i', $xmlremote)) {
1922  $langs->load("errors");
1923  throw new RestException(500, $langs->trans("ErrorURLMustStartWithHttp", $xmlremote));
1924  }
1925  if ($xmlremote && !preg_match('/\.xml$/', $xmlremote)) {
1926  $langs->load("errors");
1927  throw new RestException(500, $langs->trans("ErrorURLMustEndWith", $xmlremote, '.xml'));
1928  }
1929 
1930  if ($target == 'local') {
1931  if (dol_is_file($xmlfile)) {
1932  $xml = simplexml_load_file($xmlfile);
1933  } else {
1934  throw new RestException(500, $langs->trans('XmlNotFound').': '.$xmlfile);
1935  }
1936  } else {
1937  $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.
1938 
1939  // Return array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...)
1940  if (!$xmlarray['curl_error_no'] && $xmlarray['http_code'] != '400' && $xmlarray['http_code'] != '404') {
1941  $xmlfile = $xmlarray['content'];
1942  //print "xmlfilestart".$xmlfile."endxmlfile";
1943  $xml = simplexml_load_string($xmlfile, 'SimpleXMLElement', LIBXML_NOCDATA|LIBXML_NONET);
1944  } else {
1945  $errormsg = $langs->trans('XmlNotFound').': '.$xmlremote.' - '.$xmlarray['http_code'].(($xmlarray['http_code'] == 400 && $xmlarray['content']) ? ' '.$xmlarray['content'] : '').' '.$xmlarray['curl_error_no'].' '.$xmlarray['curl_error_msg'];
1946  throw new RestException(500, $errormsg);
1947  }
1948  }
1949 
1950  if ($xml) {
1951  $checksumconcat = array();
1952  $file_list = array();
1953  $out = '';
1954 
1955  // Forced constants
1956  if (is_object($xml->dolibarr_constants[0])) {
1957  $out .= load_fiche_titre($langs->trans("ForcedConstants"));
1958 
1959  $out .= '<div class="div-table-responsive-no-min">';
1960  $out .= '<table class="noborder">';
1961  $out .= '<tr class="liste_titre">';
1962  $out .= '<td>#</td>';
1963  $out .= '<td>'.$langs->trans("Constant").'</td>';
1964  $out .= '<td class="center">'.$langs->trans("ExpectedValue").'</td>';
1965  $out .= '<td class="center">'.$langs->trans("Value").'</td>';
1966  $out .= '</tr>'."\n";
1967 
1968  $i = 0;
1969  foreach ($xml->dolibarr_constants[0]->constant as $constant) { // $constant is a simpleXMLElement
1970  $constname = $constant['name'];
1971  $constvalue = (string) $constant;
1972  $constvalue = (empty($constvalue) ? '0' : $constvalue);
1973  // Value found
1974  $value = '';
1975  if ($constname && $conf->global->$constname != '') {
1976  $value = $conf->global->$constname;
1977  }
1978  $valueforchecksum = (empty($value) ? '0' : $value);
1979 
1980  $checksumconcat[] = $valueforchecksum;
1981 
1982  $i++;
1983  $out .= '<tr class="oddeven">';
1984  $out .= '<td>'.$i.'</td>'."\n";
1985  $out .= '<td>'.$constname.'</td>'."\n";
1986  $out .= '<td class="center">'.$constvalue.'</td>'."\n";
1987  $out .= '<td class="center">'.$valueforchecksum.'</td>'."\n";
1988  $out .= "</tr>\n";
1989  }
1990 
1991  if ($i == 0) {
1992  $out .= '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1993  }
1994  $out .= '</table>';
1995  $out .= '</div>';
1996 
1997  $out .= '<br>';
1998  }
1999 
2000  // Scan htdocs
2001  if (is_object($xml->dolibarr_htdocs_dir[0])) {
2002  $includecustom = (empty($xml->dolibarr_htdocs_dir[0]['includecustom']) ? 0 : $xml->dolibarr_htdocs_dir[0]['includecustom']);
2003 
2004  // Define qualified files (must be same than into generate_filelist_xml.php and in api_setup.class.php)
2005  $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)$';
2006  $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
2007  $scanfiles = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude);
2008 
2009  // Fill file_list with files in signature, new files, modified files
2010  $ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat); // Fill array $file_list
2011  // Complete with list of new files
2012  foreach ($scanfiles as $keyfile => $valfile) {
2013  $tmprelativefilename = preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT, '/').'/', '', $valfile['fullname']);
2014  if (!in_array($tmprelativefilename, $file_list['insignature'])) {
2015  $md5newfile = @md5_file($valfile['fullname']); // Can fails if we don't have permission to open/read file
2016  $file_list['added'][] = array('filename'=>$tmprelativefilename, 'md5'=>$md5newfile);
2017  }
2018  }
2019 
2020  // Files missings
2021  $out .= load_fiche_titre($langs->trans("FilesMissing"));
2022 
2023  $out .= '<div class="div-table-responsive-no-min">';
2024  $out .= '<table class="noborder">';
2025  $out .= '<tr class="liste_titre">';
2026  $out .= '<td>#</td>';
2027  $out .= '<td>'.$langs->trans("Filename").'</td>';
2028  $out .= '<td class="center">'.$langs->trans("ExpectedChecksum").'</td>';
2029  $out .= '</tr>'."\n";
2030  $tmpfilelist = dol_sort_array($file_list['missing'], 'filename');
2031  if (is_array($tmpfilelist) && count($tmpfilelist)) {
2032  $i = 0;
2033  foreach ($tmpfilelist as $file) {
2034  $i++;
2035  $out .= '<tr class="oddeven">';
2036  $out .= '<td>'.$i.'</td>'."\n";
2037  $out .= '<td>'.$file['filename'].'</td>'."\n";
2038  $out .= '<td class="center">'.$file['expectedmd5'].'</td>'."\n";
2039  $out .= "</tr>\n";
2040  }
2041  } else {
2042  $out .= '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
2043  }
2044  $out .= '</table>';
2045  $out .= '</div>';
2046 
2047  $out .= '<br>';
2048 
2049  // Files modified
2050  $out .= load_fiche_titre($langs->trans("FilesModified"));
2051 
2052  $totalsize = 0;
2053  $out .= '<div class="div-table-responsive-no-min">';
2054  $out .= '<table class="noborder">';
2055  $out .= '<tr class="liste_titre">';
2056  $out .= '<td>#</td>';
2057  $out .= '<td>'.$langs->trans("Filename").'</td>';
2058  $out .= '<td class="center">'.$langs->trans("ExpectedChecksum").'</td>';
2059  $out .= '<td class="center">'.$langs->trans("CurrentChecksum").'</td>';
2060  $out .= '<td class="right">'.$langs->trans("Size").'</td>';
2061  $out .= '<td class="right">'.$langs->trans("DateModification").'</td>';
2062  $out .= '</tr>'."\n";
2063  $tmpfilelist2 = dol_sort_array($file_list['updated'], 'filename');
2064  if (is_array($tmpfilelist2) && count($tmpfilelist2)) {
2065  $i = 0;
2066  foreach ($tmpfilelist2 as $file) {
2067  $i++;
2068  $out .= '<tr class="oddeven">';
2069  $out .= '<td>'.$i.'</td>'."\n";
2070  $out .= '<td>'.$file['filename'].'</td>'."\n";
2071  $out .= '<td class="center">'.$file['expectedmd5'].'</td>'."\n";
2072  $out .= '<td class="center">'.$file['md5'].'</td>'."\n";
2073  $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
2074  $totalsize += $size;
2075  $out .= '<td class="right">'.dol_print_size($size).'</td>'."\n";
2076  $out .= '<td class="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']), 'dayhour').'</td>'."\n";
2077  $out .= "</tr>\n";
2078  }
2079  $out .= '<tr class="liste_total">';
2080  $out .= '<td></td>'."\n";
2081  $out .= '<td>'.$langs->trans("Total").'</td>'."\n";
2082  $out .= '<td align="center"></td>'."\n";
2083  $out .= '<td align="center"></td>'."\n";
2084  $out .= '<td class="right">'.dol_print_size($totalsize).'</td>'."\n";
2085  $out .= '<td class="right"></td>'."\n";
2086  $out .= "</tr>\n";
2087  } else {
2088  $out .= '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
2089  }
2090  $out .= '</table>';
2091  $out .= '</div>';
2092 
2093  $out .= '<br>';
2094 
2095  // Files added
2096  $out .= load_fiche_titre($langs->trans("FilesAdded"));
2097 
2098  $totalsize = 0;
2099  $out .= '<div class="div-table-responsive-no-min">';
2100  $out .= '<table class="noborder">';
2101  $out .= '<tr class="liste_titre">';
2102  $out .= '<td>#</td>';
2103  $out .= '<td>'.$langs->trans("Filename").'</td>';
2104  $out .= '<td class="center">'.$langs->trans("ExpectedChecksum").'</td>';
2105  $out .= '<td class="center">'.$langs->trans("CurrentChecksum").'</td>';
2106  $out .= '<td class="right">'.$langs->trans("Size").'</td>';
2107  $out .= '<td class="right">'.$langs->trans("DateModification").'</td>';
2108  $out .= '</tr>'."\n";
2109  $tmpfilelist3 = dol_sort_array($file_list['added'], 'filename');
2110  if (is_array($tmpfilelist3) && count($tmpfilelist3)) {
2111  $i = 0;
2112  foreach ($tmpfilelist3 as $file) {
2113  $i++;
2114  $out .= '<tr class="oddeven">';
2115  $out .= '<td>'.$i.'</td>'."\n";
2116  $out .= '<td>'.$file['filename'].'</td>'."\n";
2117  $out .= '<td class="center">'.$file['expectedmd5'].'</td>'."\n";
2118  $out .= '<td class="center">'.$file['md5'].'</td>'."\n";
2119  $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
2120  $totalsize += $size;
2121  $out .= '<td class="right">'.dol_print_size($size).'</td>'."\n";
2122  $out .= '<td class="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']), 'dayhour').'</td>'."\n";
2123  $out .= "</tr>\n";
2124  }
2125  $out .= '<tr class="liste_total">';
2126  $out .= '<td></td>'."\n";
2127  $out .= '<td>'.$langs->trans("Total").'</td>'."\n";
2128  $out .= '<td align="center"></td>'."\n";
2129  $out .= '<td align="center"></td>'."\n";
2130  $out .= '<td class="right">'.dol_print_size($totalsize).'</td>'."\n";
2131  $out .= '<td class="right"></td>'."\n";
2132  $out .= "</tr>\n";
2133  } else {
2134  $out .= '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
2135  }
2136  $out .= '</table>';
2137  $out .= '</div>';
2138 
2139 
2140  // Show warning
2141  if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) {
2142  //setEventMessages($langs->trans("FileIntegrityIsStrictlyConformedWithReference"), null, 'mesgs');
2143  } else {
2144  //setEventMessages($langs->trans("FileIntegritySomeFilesWereRemovedOrModified"), null, 'warnings');
2145  }
2146  } else {
2147  throw new RestException(500, 'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile);
2148  }
2149 
2150 
2151  // Scan scripts
2152  asort($checksumconcat); // Sort list of checksum
2153  $checksumget = md5(join(',', $checksumconcat));
2154  $checksumtoget = trim((string) $xml->dolibarr_htdocs_dir_checksum);
2155 
2156  $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans("Unknown"));
2157  if ($checksumget == $checksumtoget) {
2158  if (count($file_list['added'])) {
2159  $resultcode = 'warning';
2160  $resultcomment = 'FileIntegrityIsOkButFilesWereAdded';
2161  //$outcurrentchecksum = $checksumget.' - <span class="'.$resultcode.'">'.$langs->trans("FileIntegrityIsOkButFilesWereAdded").'</span>';
2162  $outcurrentchecksum = $checksumget;
2163  } else {
2164  $resultcode = 'ok';
2165  $resultcomment = 'Success';
2166  //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
2167  $outcurrentchecksum = $checksumget;
2168  }
2169  } else {
2170  $resultcode = 'error';
2171  $resultcomment = 'Error';
2172  //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
2173  $outcurrentchecksum = $checksumget;
2174  }
2175  } else {
2176  throw new RestException(404, 'No signature file known');
2177  }
2178 
2179  return array('resultcode'=>$resultcode, 'resultcomment'=>$resultcomment, 'expectedchecksum'=> $outexpectedchecksum, 'currentchecksum'=> $outcurrentchecksum, 'out'=>$out);
2180  }
2181 
2182 
2192  public function getModules()
2193  {
2194  global $conf;
2195 
2196  if (!DolibarrApiAccess::$user->admin
2197  && (empty($conf->global->API_LOGINS_ALLOWED_FOR_GET_MODULES) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_GET_MODULES)) {
2198  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');
2199  }
2200 
2201  sort($conf->modules);
2202 
2203  return $this->_cleanObjectDatas($conf->modules);
2204  }
2205 }
db
$conf db
API class for accounts.
Definition: inc.php:41
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1236
Setup\getCountryByID
getCountryByID($id, $lang='')
Get country by ID.
Definition: api_setup.class.php:430
Setup\getEtablishmentByID
getEtablishmentByID($id)
Get establishment by ID.
Definition: api_setup.class.php:1827
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:260
dol_filemtime
dol_filemtime($pathoffile)
Return time of a file.
Definition: files.lib.php:597
Setup
Definition: api_setup.class.php:37
$sql
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)) $sql
Social contributions to pay.
Definition: index.php:745
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:777
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5363
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:530
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:646
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:8758
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:61
Setup\getCountryByISO
getCountryByISO($iso, $lang='')
Get country by Iso.
Definition: api_setup.class.php:462
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:1616
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:1854
Setup\getModules
getModules()
Get list of enabled modules.
Definition: api_setup.class.php:2192
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:1124
dol_is_file
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:481
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:712
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:266
jsonOrUnserialize
jsonOrUnserialize($stringtodecode)
Decode an encode string.
Definition: functions.lib.php:11571
Setup\getListOfCountries
getListOfCountries($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $filter='', $lang='', $sqlfilters='')
Get the list of countries.
Definition: api_setup.class.php:366
getFilesUpdated
getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path='', $pathref='', &$checksumconcat=array())
Function to get list of updated or modified files.
Definition: files.lib.php:3283
Setup\getShippingModes
getShippingModes($limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of shipping methods.
Definition: api_setup.class.php:1187
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:1426
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:845
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:1492
DolibarrApi\_checkFilters
_checkFilters($sqlfilters, &$error='')
Return if a $sqlfilters parameter is valid Function no more used.
Definition: api.class.php:311
Setup\_fetchCcountry
_fetchCcountry($id, $code='', $iso='', $lang='')
Get country.
Definition: api_setup.class.php:501
Setup\__construct
__construct()
Constructor.
Definition: api_setup.class.php:44
forgeSQLFromUniversalSearchCriteria
forgeSQLFromUniversalSearchCriteria($filter, &$error='')
forgeSQLFromUniversalSearchCriteria
Definition: functions.lib.php:11589
Setup\getCompany
getCompany()
Get properties of company.
Definition: api_setup.class.php:1734
Setup\getCheckIntegrity
getCheckIntegrity($target)
Do a test of integrity for files and setup.
Definition: api_setup.class.php:1886
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:1059
Setup\getStateByID
getStateByID($id)
Get state by ID.
Definition: api_setup.class.php:325
Setup\_cleanObjectDatas
_cleanObjectDatas($object)
Clean sensible object datas.
Definition: api_setup.class.php:588
Setup\getListOfStaff
getListOfStaff($sortfield="id", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of staff.
Definition: api_setup.class.php:1368
Setup\getCountryByCode
getCountryByCode($code, $lang='')
Get country by Code.
Definition: api_setup.class.php:446
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
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:1554
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:147
Setup\getListOfExtrafields
getListOfExtrafields($sortfield="t.pos", $sortorder='ASC', $type='', $sqlfilters='')
Get the list of extra fields.
Definition: api_setup.class.php:978
dol_filesize
dol_filesize($pathoffile)
Return size of a file.
Definition: files.lib.php:585
Setup\_fetchCstate
_fetchCstate($id, $code='')
Get state.
Definition: api_setup.class.php:476
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:1679
Setup\getStateByCode
getStateByCode($code)
Get state by Code.
Definition: api_setup.class.php:340
Setup\getEstablishments
getEstablishments()
Get the list of establishments.
Definition: api_setup.class.php:1789
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:909
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:1307
Establishment
Class to manage establishments.
Definition: establishment.class.php:30
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:534
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:608
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:1248
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:66