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