dolibarr  17.0.4
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 
431  public function getCountryByID($id, $lang = '')
432  {
433  return $this->_fetchCcountry($id, '', '', $lang);
434  }
435 
448  public function getCountryByCode($code, $lang = '')
449  {
450  return $this->_fetchCcountry('', $code, '', $lang);
451  }
452 
465  public function getCountryByISO($iso, $lang = '')
466  {
467  return $this->_fetchCcountry('', '', $iso, $lang);
468  }
469 
479  private function _fetchCstate($id, $code = '')
480  {
481  $state = new Cstate($this->db);
482 
483  $result = $state->fetch($id, $code);
484  if ($result < 0) {
485  throw new RestException(503, 'Error when retrieving state : '.$state->error);
486  } elseif ($result == 0) {
487  throw new RestException(404, 'State not found');
488  }
489 
490  return $this->_cleanObjectDatas($state);
491  }
492 
505  private function _fetchCcountry($id, $code = '', $iso = '', $lang = '')
506  {
507  $country = new Ccountry($this->db);
508 
509  $result = $country->fetch($id, $code, $iso);
510 
511  if ($result < 0) {
512  throw new RestException(503, 'Error when retrieving country : '.$country->error);
513  } elseif ($result == 0) {
514  throw new RestException(404, 'Country not found');
515  }
516 
517  $this->translateLabel($country, $lang, 'Country');
518 
519  return $this->_cleanObjectDatas($country);
520  }
521 
538  public function getAvailability($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
539  {
540  $list = array();
541 
542  if (!DolibarrApiAccess::$user->rights->commande->lire) {
543  throw new RestException(401);
544  }
545 
546  $sql = "SELECT rowid, code, label";
547  $sql .= " FROM ".MAIN_DB_PREFIX."c_availability as t";
548  $sql .= " WHERE t.active = ".((int) $active);
549  // Add sql filters
550  if ($sqlfilters) {
551  $errormessage = '';
552  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
553  if ($errormessage) {
554  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
555  }
556  }
557 
558 
559  $sql .= $this->db->order($sortfield, $sortorder);
560 
561  if ($limit) {
562  if ($page < 0) {
563  $page = 0;
564  }
565  $offset = $limit * $page;
566 
567  $sql .= $this->db->plimit($limit, $offset);
568  }
569 
570  $result = $this->db->query($sql);
571 
572  if ($result) {
573  $num = $this->db->num_rows($result);
574  $min = min($num, ($limit <= 0 ? $num : $limit));
575  for ($i = 0; $i < $min; $i++) {
576  $list[] = $this->db->fetch_object($result);
577  }
578  } else {
579  throw new RestException(400, $this->db->lasterror());
580  }
581 
582  return $list;
583  }
584 
585  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
592  protected function _cleanObjectDatas($object)
593  {
594  // phpcs:enable
595  $object = parent::_cleanObjectDatas($object);
596 
597  unset($object->error);
598  unset($object->errors);
599 
600  return $object;
601  }
602 
612  private function translateLabel($object, $lang, $prefix = 'Country', $dict = array('dict'))
613  {
614  if (!empty($lang)) {
615  // Load the translations if this is a new language.
616  if ($this->translations == null || $this->translations->getDefaultLang() !== $lang) {
617  global $conf;
618  $this->translations = new Translate('', $conf);
619  $this->translations->setDefaultLang($lang);
620  $this->translations->loadLangs($dict);
621  }
622  if ($object->code) {
623  $key = $prefix.$object->code;
624 
625  $translation = $this->translations->trans($key);
626  if ($translation != $key) {
627  $object->label = html_entity_decode($translation);
628  }
629  }
630  }
631  }
632 
650  public function getListOfEventTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $active = 1, $sqlfilters = '')
651  {
652  $list = array();
653 
654  $sql = "SELECT id, code, type, libelle as label, module";
655  $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t";
656  $sql .= " WHERE t.active = ".((int) $active);
657  if ($type) {
658  $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'";
659  }
660  if ($module) {
661  $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
662  }
663  // Add sql filters
664  if ($sqlfilters) {
665  $errormessage = '';
666  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
667  if ($errormessage) {
668  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
669  }
670  }
671 
672 
673  $sql .= $this->db->order($sortfield, $sortorder);
674 
675  if ($limit) {
676  if ($page < 0) {
677  $page = 0;
678  }
679  $offset = $limit * $page;
680 
681  $sql .= $this->db->plimit($limit, $offset);
682  }
683 
684  $result = $this->db->query($sql);
685 
686  if ($result) {
687  $num = $this->db->num_rows($result);
688  $min = min($num, ($limit <= 0 ? $num : $limit));
689  for ($i = 0; $i < $min; $i++) {
690  $list[] = $this->db->fetch_object($result);
691  }
692  } else {
693  throw new RestException(503, 'Error when retrieving list of events types : '.$this->db->lasterror());
694  }
695 
696  return $list;
697  }
698 
699 
716  public function getListOfExpenseReportsTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $module = '', $active = 1, $sqlfilters = '')
717  {
718  $list = array();
719 
720  $sql = "SELECT id, code, label, accountancy_code, active, module, position";
721  $sql .= " FROM ".MAIN_DB_PREFIX."c_type_fees as t";
722  $sql .= " WHERE t.active = ".((int) $active);
723  if ($module) {
724  $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
725  }
726  // Add sql filters
727  if ($sqlfilters) {
728  $errormessage = '';
729  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
730  if ($errormessage) {
731  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
732  }
733  }
734 
735 
736  $sql .= $this->db->order($sortfield, $sortorder);
737 
738  if ($limit) {
739  if ($page < 0) {
740  $page = 0;
741  }
742  $offset = $limit * $page;
743 
744  $sql .= $this->db->plimit($limit, $offset);
745  }
746 
747  $result = $this->db->query($sql);
748 
749  if ($result) {
750  $num = $this->db->num_rows($result);
751  $min = min($num, ($limit <= 0 ? $num : $limit));
752  for ($i = 0; $i < $min; $i++) {
753  $list[] = $this->db->fetch_object($result);
754  }
755  } else {
756  throw new RestException(503, 'Error when retrieving list of expense report types : '.$this->db->lasterror());
757  }
758 
759  return $list;
760  }
761 
762 
781  public function getListOfContactTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $active = 1, $lang = '', $sqlfilters = '')
782  {
783  $list = array();
784 
785  $sql = "SELECT rowid, code, element as type, libelle as label, source, module, position";
786  $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as t";
787  $sql .= " WHERE t.active = ".((int) $active);
788  if ($type) {
789  $sql .= " AND type LIKE '%".$this->db->escape($type)."%'";
790  }
791  if ($module) {
792  $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
793  }
794  // Add sql filters
795  if ($sqlfilters) {
796  $errormessage = '';
797  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
798  if ($errormessage) {
799  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
800  }
801  }
802 
803 
804  $sql .= $this->db->order($sortfield, $sortorder);
805 
806  if ($limit) {
807  if ($page < 0) {
808  $page = 0;
809  }
810  $offset = $limit * $page;
811 
812  $sql .= $this->db->plimit($limit, $offset);
813  }
814 
815  $result = $this->db->query($sql);
816 
817  if ($result) {
818  $num = $this->db->num_rows($result);
819  $min = min($num, ($limit <= 0 ? $num : $limit));
820  for ($i = 0; $i < $min; $i++) {
821  $contact_type = $this->db->fetch_object($result);
822  $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"));
823  $list[] = $contact_type;
824  }
825  } else {
826  throw new RestException(503, 'Error when retrieving list of contacts types : '.$this->db->lasterror());
827  }
828 
829  return $list;
830  }
831 
849  public function getListOfCivilities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $module = '', $active = 1, $lang = '', $sqlfilters = '')
850  {
851  $list = array();
852 
853  $sql = "SELECT rowid, code, label, module";
854  $sql .= " FROM ".MAIN_DB_PREFIX."c_civility as t";
855  $sql .= " WHERE t.active = ".((int) $active);
856  if ($module) {
857  $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
858  }
859  // Add sql filters
860  if ($sqlfilters) {
861  $errormessage = '';
862  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
863  if ($errormessage) {
864  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
865  }
866  }
867 
868 
869  $sql .= $this->db->order($sortfield, $sortorder);
870 
871  if ($limit) {
872  if ($page < 0) {
873  $page = 0;
874  }
875  $offset = $limit * $page;
876 
877  $sql .= $this->db->plimit($limit, $offset);
878  }
879 
880  $result = $this->db->query($sql);
881 
882  if ($result) {
883  $num = $this->db->num_rows($result);
884  $min = min($num, ($limit <= 0 ? $num : $limit));
885  for ($i = 0; $i < $min; $i++) {
886  $civility = $this->db->fetch_object($result);
887  $this->translateLabel($civility, $lang, 'Civility', array('dict'));
888  $list[] = $civility;
889  }
890  } else {
891  throw new RestException(503, 'Error when retrieving list of civility : '.$this->db->lasterror());
892  }
893 
894  return $list;
895  }
896 
913  public function getListOfCurrencies($multicurrency = 0, $sortfield = "code_iso", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
914  {
915  $list = array();
916  $sql = "SELECT t.code_iso, t.label, t.unicode";
917  if (!empty($multicurrency)) {
918  $sql .= " , cr.date_sync, cr.rate ";
919  }
920  $sql .= " FROM ".MAIN_DB_PREFIX."c_currencies as t";
921  if (!empty($multicurrency)) {
922  $sql .= " JOIN ".MAIN_DB_PREFIX."multicurrency as m ON m.code=t.code_iso";
923  $sql .= " JOIN ".MAIN_DB_PREFIX."multicurrency_rate as cr ON (m.rowid = cr.fk_multicurrency)";
924  }
925  $sql .= " WHERE t.active = ".((int) $active);
926  if (!empty($multicurrency)) {
927  $sql .= " AND m.entity IN (".getEntity('multicurrency').")";
928  if (!empty($multicurrency) && $multicurrency != 2) {
929  $sql .= " AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM ".MAIN_DB_PREFIX."multicurrency_rate AS cr2 WHERE cr2.fk_multicurrency = m.rowid)";
930  }
931  }
932 
933  // Add sql filters
934  if ($sqlfilters) {
935  $errormessage = '';
936  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
937  if ($errormessage) {
938  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
939  }
940  }
941 
942 
943  $sql .= $this->db->order($sortfield, $sortorder);
944 
945  if ($limit) {
946  if ($page < 0) {
947  $page = 0;
948  }
949  $offset = $limit * $page;
950 
951  $sql .= $this->db->plimit($limit, $offset);
952  }
953 
954  $result = $this->db->query($sql);
955 
956  if ($result) {
957  $num = $this->db->num_rows($result);
958  $min = min($num, ($limit <= 0 ? $num : $limit));
959  for ($i = 0; $i < $min; $i++) {
960  $list[] = $this->db->fetch_object($result);
961  }
962  } else {
963  throw new RestException(503, 'Error when retrieving list of currency : '.$this->db->lasterror());
964  }
965 
966  return $list;
967  }
968 
982  public function getListOfExtrafields($sortfield = "t.pos", $sortorder = 'ASC', $type = '', $sqlfilters = '')
983  {
984  $list = array();
985 
986  if (!DolibarrApiAccess::$user->admin) {
987  throw new RestException(401, 'Only an admin user can get list of extrafields');
988  }
989 
990  if ($type == 'thirdparty') {
991  $type = 'societe';
992  }
993  if ($type == 'contact') {
994  $type = 'socpeople';
995  }
996 
997  $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";
998  $sql .= " FROM ".MAIN_DB_PREFIX."extrafields as t";
999  $sql .= " WHERE t.entity IN (".getEntity('extrafields').")";
1000  if (!empty($type)) {
1001  $sql .= " AND t.elementtype = '".$this->db->escape($type)."'";
1002  }
1003  // Add sql filters
1004  if ($sqlfilters) {
1005  $errormessage = '';
1006  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1007  if ($errormessage) {
1008  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1009  }
1010  }
1011 
1012  $sql .= $this->db->order($sortfield, $sortorder);
1013 
1014  $resql = $this->db->query($sql);
1015  if ($resql) {
1016  if ($this->db->num_rows($resql)) {
1017  while ($tab = $this->db->fetch_object($resql)) {
1018  // New usage
1019  $list[$tab->elementtype][$tab->name]['type'] = $tab->type;
1020  $list[$tab->elementtype][$tab->name]['label'] = $tab->label;
1021  $list[$tab->elementtype][$tab->name]['size'] = $tab->size;
1022  $list[$tab->elementtype][$tab->name]['elementtype'] = $tab->elementtype;
1023  $list[$tab->elementtype][$tab->name]['default'] = $tab->fielddefault;
1024  $list[$tab->elementtype][$tab->name]['computed'] = $tab->fieldcomputed;
1025  $list[$tab->elementtype][$tab->name]['unique'] = $tab->fieldunique;
1026  $list[$tab->elementtype][$tab->name]['required'] = $tab->fieldrequired;
1027  $list[$tab->elementtype][$tab->name]['param'] = ($tab->param ? jsonOrUnserialize($tab->param) : ''); // This may be a string encoded with serialise() or json_encode()
1028  $list[$tab->elementtype][$tab->name]['pos'] = $tab->pos;
1029  $list[$tab->elementtype][$tab->name]['alwayseditable'] = $tab->alwayseditable;
1030  $list[$tab->elementtype][$tab->name]['perms'] = $tab->perms;
1031  $list[$tab->elementtype][$tab->name]['list'] = $tab->list;
1032  }
1033  }
1034  } else {
1035  throw new RestException(503, 'Error when retrieving list of extra fields : '.$this->db->lasterror());
1036  }
1037 
1038  if (!count($list)) {
1039  throw new RestException(404, 'No extrafield found');
1040  }
1041 
1042  return $list;
1043  }
1044 
1045 
1063  public function getListOfTowns($sortfield = "zip,town", $sortorder = 'ASC', $limit = 100, $page = 0, $zipcode = '', $town = '', $active = 1, $sqlfilters = '')
1064  {
1065  $list = array();
1066 
1067  $sql = "SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
1068  $sql .= " FROM ".MAIN_DB_PREFIX."c_ziptown as t";
1069  $sql .= " WHERE t.active = ".((int) $active);
1070  if ($zipcode) {
1071  $sql .= " AND t.zip LIKE '%".$this->db->escape($zipcode)."%'";
1072  }
1073  if ($town) {
1074  $sql .= " AND t.town LIKE '%".$this->db->escape($town)."%'";
1075  }
1076  // Add sql filters
1077  if ($sqlfilters) {
1078  $errormessage = '';
1079  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1080  if ($errormessage) {
1081  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1082  }
1083  }
1084 
1085 
1086  $sql .= $this->db->order($sortfield, $sortorder);
1087 
1088  if ($limit) {
1089  if ($page < 0) {
1090  $page = 0;
1091  }
1092  $offset = $limit * $page;
1093 
1094  $sql .= $this->db->plimit($limit, $offset);
1095  }
1096 
1097  $result = $this->db->query($sql);
1098 
1099  if ($result) {
1100  $num = $this->db->num_rows($result);
1101  $min = min($num, ($limit <= 0 ? $num : $limit));
1102  for ($i = 0; $i < $min; $i++) {
1103  $list[] = $this->db->fetch_object($result);
1104  }
1105  } else {
1106  throw new RestException(503, 'Error when retrieving list of towns : '.$this->db->lasterror());
1107  }
1108 
1109  return $list;
1110  }
1111 
1128  public function getPaymentTerms($sortfield = "sortorder", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1129  {
1130  $list = array();
1131 
1132  if (!DolibarrApiAccess::$user->rights->propal->lire && !DolibarrApiAccess::$user->rights->commande->lire && !DolibarrApiAccess::$user->rights->facture->lire) {
1133  throw new RestException(401);
1134  }
1135 
1136  $sql = "SELECT rowid as id, code, sortorder, libelle as label, libelle_facture as descr, type_cdr, nbjour, decalage, module";
1137  $sql .= " FROM ".MAIN_DB_PREFIX."c_payment_term as t";
1138  $sql .= " WHERE t.entity IN (".getEntity('c_payment_term').")";
1139  $sql .= " AND t.active = ".((int) $active);
1140  // Add sql filters
1141  if ($sqlfilters) {
1142  $errormessage = '';
1143  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1144  if ($errormessage) {
1145  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1146  }
1147  }
1148 
1149 
1150  $sql .= $this->db->order($sortfield, $sortorder);
1151 
1152  if ($limit) {
1153  if ($page < 0) {
1154  $page = 0;
1155  }
1156  $offset = $limit * $page;
1157 
1158  $sql .= $this->db->plimit($limit, $offset);
1159  }
1160 
1161  $result = $this->db->query($sql);
1162 
1163  if ($result) {
1164  $num = $this->db->num_rows($result);
1165  $min = min($num, ($limit <= 0 ? $num : $limit));
1166  for ($i = 0; $i < $min; $i++) {
1167  $list[] = $this->db->fetch_object($result);
1168  }
1169  } else {
1170  throw new RestException(400, $this->db->lasterror());
1171  }
1172 
1173  return $list;
1174  }
1175 
1191  public function getShippingModes($limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1192  {
1193  $list = array();
1194 
1195  $sql = "SELECT rowid as id, code, libelle as label, description, tracking, module";
1196  $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as t";
1197  $sql .= " WHERE t.entity IN (".getEntity('c_shipment_mode').")";
1198  $sql .= " AND t.active = ".((int) $active);
1199  // Add sql filters
1200  if ($sqlfilters) {
1201  $errormessage = '';
1202  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1203  if ($errormessage) {
1204  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1205  }
1206  }
1207 
1208 
1209  //$sql.= $this->db->order($sortfield, $sortorder);
1210 
1211  if ($limit) {
1212  if ($page < 0) {
1213  $page = 0;
1214  }
1215  $offset = $limit * $page;
1216 
1217  $sql .= $this->db->plimit($limit, $offset);
1218  }
1219 
1220  $result = $this->db->query($sql);
1221 
1222  if ($result) {
1223  $num = $this->db->num_rows($result);
1224  $min = min($num, ($limit <= 0 ? $num : $limit));
1225  for ($i = 0; $i < $min; $i++) {
1226  $method = $this->db->fetch_object($result);
1227  $this->translateLabel($method, $lang, '', array('dict'));
1228  $list[] = $method;
1229  }
1230  } else {
1231  throw new RestException(400, $this->db->lasterror());
1232  }
1233 
1234  return $list;
1235  }
1236 
1252  public function getListOfMeasuringUnits($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1253  {
1254  $list = array();
1255 
1256  $sql = "SELECT t.rowid, t.code, t.label,t.short_label, t.active, t.scale, t.unit_type";
1257  $sql .= " FROM ".MAIN_DB_PREFIX."c_units as t";
1258  $sql .= " WHERE t.active = ".((int) $active);
1259  // Add sql filters
1260  if ($sqlfilters) {
1261  $errormessage = '';
1262  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1263  if ($errormessage) {
1264  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1265  }
1266  }
1267 
1268 
1269  $sql .= $this->db->order($sortfield, $sortorder);
1270 
1271  if ($limit) {
1272  if ($page < 0) {
1273  $page = 0;
1274  }
1275  $offset = $limit * $page;
1276 
1277  $sql .= $this->db->plimit($limit, $offset);
1278  }
1279 
1280  $result = $this->db->query($sql);
1281 
1282  if ($result) {
1283  $num = $this->db->num_rows($result);
1284  $min = min($num, ($limit <= 0 ? $num : $limit));
1285  for ($i = 0; $i < $min; $i++) {
1286  $list[] = $this->db->fetch_object($result);
1287  }
1288  } else {
1289  throw new RestException(503, 'Error when retrieving list of measuring units: '.$this->db->lasterror());
1290  }
1291 
1292  return $list;
1293  }
1294 
1311  public function getListOfLegalForm($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $country = 0, $active = 1, $sqlfilters = '')
1312  {
1313  $list = array();
1314 
1315  $sql = "SELECT t.rowid, t.code, t.fk_pays, t.libelle, t.isvatexempted, t.active, t.module, t.position";
1316  $sql .= " FROM ".MAIN_DB_PREFIX."c_forme_juridique as t";
1317  $sql .= " WHERE t.active = ".((int) $active);
1318  if ($country) {
1319  $sql .= " AND t.fk_pays = ".((int) $country);
1320  }
1321  // Add sql filters
1322  if ($sqlfilters) {
1323  $errormessage = '';
1324  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1325  if ($errormessage) {
1326  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1327  }
1328  }
1329 
1330 
1331  $sql .= $this->db->order($sortfield, $sortorder);
1332 
1333  if ($limit) {
1334  if ($page < 0) {
1335  $page = 0;
1336  }
1337  $offset = $limit * $page;
1338 
1339  $sql .= $this->db->plimit($limit, $offset);
1340  }
1341 
1342  $result = $this->db->query($sql);
1343 
1344  if ($result) {
1345  $num = $this->db->num_rows($result);
1346  $min = min($num, ($limit <= 0 ? $num : $limit));
1347  for ($i = 0; $i < $min; $i++) {
1348  $list[] = $this->db->fetch_object($result);
1349  }
1350  } else {
1351  throw new RestException(503, 'Error when retrieving list of legal form: '.$this->db->lasterror());
1352  }
1353 
1354  return $list;
1355  }
1356 
1372  public function getListOfStaff($sortfield = "id", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1373  {
1374  $list = array();
1375 
1376  $sql = "SELECT t.id, t.code, t.libelle, t.active, t.module";
1377  $sql .= " FROM ".MAIN_DB_PREFIX."c_effectif as t";
1378  $sql .= " WHERE t.active = ".((int) $active);
1379  // Add sql filters
1380  if ($sqlfilters) {
1381  $errormessage = '';
1382  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1383  if ($errormessage) {
1384  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1385  }
1386  }
1387 
1388 
1389  $sql .= $this->db->order($sortfield, $sortorder);
1390 
1391  if ($limit) {
1392  if ($page < 0) {
1393  $page = 0;
1394  }
1395  $offset = $limit * $page;
1396 
1397  $sql .= $this->db->plimit($limit, $offset);
1398  }
1399 
1400  $result = $this->db->query($sql);
1401 
1402  if ($result) {
1403  $num = $this->db->num_rows($result);
1404  $min = min($num, ($limit <= 0 ? $num : $limit));
1405  for ($i = 0; $i < $min; $i++) {
1406  $list[] = $this->db->fetch_object($result);
1407  }
1408  } else {
1409  throw new RestException(503, 'Error when retrieving list of staff: '.$this->db->lasterror());
1410  }
1411 
1412  return $list;
1413  }
1414 
1430  public function getListOfsocialNetworks($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
1431  {
1432  global $conf;
1433 
1434  if (!isModEnabled('socialnetworks')) {
1435  throw new RestException(400, 'API not available: this dictionary is not enabled by setup');
1436  }
1437 
1438  $list = array();
1439  //TODO link with multicurrency module
1440  $sql = "SELECT t.rowid, t.entity, t.code, t.label, t.url, t.icon, t.active";
1441  $sql .= " FROM ".MAIN_DB_PREFIX."c_socialnetworks as t";
1442  $sql .= " WHERE t.entity IN (".getEntity('c_socialnetworks').")";
1443  $sql .= " AND t.active = ".((int) $active);
1444  // Add sql filters
1445  if ($sqlfilters) {
1446  $errormessage = '';
1447  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1448  if ($errormessage) {
1449  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1450  }
1451  }
1452 
1453 
1454  $sql .= $this->db->order($sortfield, $sortorder);
1455 
1456  if ($limit) {
1457  if ($page < 0) {
1458  $page = 0;
1459  }
1460  $offset = $limit * $page;
1461 
1462  $sql .= $this->db->plimit($limit, $offset);
1463  }
1464 
1465  $result = $this->db->query($sql);
1466 
1467  if ($result) {
1468  $num = $this->db->num_rows($result);
1469  $min = min($num, ($limit <= 0 ? $num : $limit));
1470  for ($i = 0; $i < $min; $i++) {
1471  $list[] = $this->db->fetch_object($result);
1472  }
1473  } else {
1474  throw new RestException(503, 'Error when retrieving list of social networks: '.$this->db->lasterror());
1475  }
1476 
1477  return $list;
1478  }
1479 
1496  public function getTicketsCategories($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1497  {
1498  $list = array();
1499 
1500  $sql = "SELECT rowid, code, pos, label, use_default, description";
1501  $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t";
1502  $sql .= " WHERE t.entity IN (".getEntity('c_ticket_category').")";
1503  $sql .= " AND t.active = ".((int) $active);
1504  // Add sql filters
1505  if ($sqlfilters) {
1506  $errormessage = '';
1507  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1508  if ($errormessage) {
1509  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1510  }
1511  }
1512 
1513 
1514  $sql .= $this->db->order($sortfield, $sortorder);
1515 
1516  if ($limit) {
1517  if ($page < 0) {
1518  $page = 0;
1519  }
1520  $offset = $limit * $page;
1521 
1522  $sql .= $this->db->plimit($limit, $offset);
1523  }
1524 
1525  $result = $this->db->query($sql);
1526 
1527  if ($result) {
1528  $num = $this->db->num_rows($result);
1529  $min = min($num, ($limit <= 0 ? $num : $limit));
1530  for ($i = 0; $i < $min; $i++) {
1531  $category = $this->db->fetch_object($result);
1532  $this->translateLabel($category, $lang, 'TicketCategoryShort', array('ticket'));
1533  $list[] = $category;
1534  }
1535  } else {
1536  throw new RestException(503, 'Error when retrieving list of ticket categories : '.$this->db->lasterror());
1537  }
1538 
1539  return $list;
1540  }
1541 
1558  public function getTicketsSeverities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1559  {
1560  $list = array();
1561 
1562  $sql = "SELECT rowid, code, pos, label, use_default, color, description";
1563  $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t";
1564  $sql .= " WHERE t.entity IN (".getEntity('c_ticket_severity').")";
1565  $sql .= " AND t.active = ".((int) $active);
1566  // Add sql filters
1567  if ($sqlfilters) {
1568  $errormessage = '';
1569  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1570  if ($errormessage) {
1571  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1572  }
1573  }
1574 
1575 
1576  $sql .= $this->db->order($sortfield, $sortorder);
1577 
1578  if ($limit) {
1579  if ($page < 0) {
1580  $page = 0;
1581  }
1582  $offset = $limit * $page;
1583 
1584  $sql .= $this->db->plimit($limit, $offset);
1585  }
1586 
1587  $result = $this->db->query($sql);
1588 
1589  if ($result) {
1590  $num = $this->db->num_rows($result);
1591  $min = min($num, ($limit <= 0 ? $num : $limit));
1592  for ($i = 0; $i < $min; $i++) {
1593  $severity = $this->db->fetch_object($result);
1594  $this->translateLabel($severity, $lang, 'TicketSeverityShort', array('ticket'));
1595  $list[] = $severity;
1596  }
1597  } else {
1598  throw new RestException(503, 'Error when retrieving list of ticket severities : '.$this->db->lasterror());
1599  }
1600 
1601  return $list;
1602  }
1603 
1620  public function getTicketsTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '')
1621  {
1622  $list = array();
1623 
1624  $sql = "SELECT rowid, code, pos, label, use_default, description";
1625  $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_type as t";
1626  $sql .= " WHERE t.entity IN (".getEntity('c_ticket_type').")";
1627  $sql .= " AND t.active = ".((int) $active);
1628 
1629  // Add sql filters
1630  if ($sqlfilters) {
1631  $errormessage = '';
1632  $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1633  if ($errormessage) {
1634  throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
1635  }
1636  }
1637 
1638 
1639  $sql .= $this->db->order($sortfield, $sortorder);
1640 
1641  if ($limit) {
1642  if ($page < 0) {
1643  $page = 0;
1644  }
1645  $offset = $limit * $page;
1646 
1647  $sql .= $this->db->plimit($limit, $offset);
1648  }
1649 
1650  $result = $this->db->query($sql);
1651 
1652  if ($result) {
1653  $num = $this->db->num_rows($result);
1654  $min = min($num, ($limit <= 0 ? $num : $limit));
1655  for ($i = 0; $i < $min; $i++) {
1656  $type =$this->db->fetch_object($result);
1657  $this->translateLabel($type, $lang, 'TicketTypeShort', array('ticket'));
1658  $list[] = $type;
1659  }
1660  } else {
1661  throw new RestException(503, 'Error when retrieving list of ticket types : '.$this->db->lasterror());
1662  }
1663 
1664  return $list;
1665  }
1666 
1676  public function getCompany()
1677  {
1678  global $conf, $mysoc;
1679 
1680  if (!DolibarrApiAccess::$user->admin
1681  && (empty($conf->global->API_LOGINS_ALLOWED_FOR_GET_COMPANY) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_GET_COMPANY)) {
1682  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');
1683  }
1684 
1685  unset($mysoc->skype);
1686  unset($mysoc->twitter);
1687  unset($mysoc->facebook);
1688  unset($mysoc->linkedin);
1689 
1690  unset($mysoc->pays);
1691  unset($mysoc->note);
1692  unset($mysoc->nom);
1693 
1694  unset($mysoc->lines);
1695 
1696  unset($mysoc->effectif);
1697  unset($mysoc->effectif_id);
1698  unset($mysoc->forme_juridique_code);
1699  unset($mysoc->forme_juridique);
1700  unset($mysoc->mode_reglement_supplier_id);
1701  unset($mysoc->cond_reglement_supplier_id);
1702  unset($mysoc->transport_mode_supplier_id);
1703  unset($mysoc->fk_prospectlevel);
1704 
1705  unset($mysoc->total_ht);
1706  unset($mysoc->total_tva);
1707  unset($mysoc->total_localtax1);
1708  unset($mysoc->total_localtax2);
1709  unset($mysoc->total_ttc);
1710 
1711  unset($mysoc->lastname);
1712  unset($mysoc->firstname);
1713  unset($mysoc->civility_id);
1714 
1715  unset($mysoc->client);
1716  unset($mysoc->prospect);
1717  unset($mysoc->fournisseur);
1718  unset($mysoc->contact_id);
1719 
1720  unset($mysoc->fk_incoterms);
1721  unset($mysoc->label_incoterms);
1722  unset($mysoc->location_incoterms);
1723 
1724  return $this->_cleanObjectDatas($mysoc);
1725  }
1726 
1736  public function getEstablishments()
1737  {
1738  $list = array();
1739 
1740  $limit = 0;
1741 
1742  $sql = "SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
1743  $sql .= " FROM ".MAIN_DB_PREFIX."establishment as e";
1744  $sql .= " WHERE e.entity IN (".getEntity('establishment').')';
1745  // if ($type) $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'";
1746  // if ($module) $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'";
1747  // Add sql filters
1748 
1749  $result = $this->db->query($sql);
1750 
1751  if ($result) {
1752  $num = $this->db->num_rows($result);
1753  $min = min($num, ($limit <= 0 ? $num : $limit));
1754  for ($i = 0; $i < $min; $i++) {
1755  $list[] = $this->db->fetch_object($result);
1756  }
1757  } else {
1758  throw new RestException(503, 'Error when retrieving list of establishments : '.$this->db->lasterror());
1759  }
1760 
1761  return $list;
1762  }
1763 
1774  public function getEtablishmentByID($id)
1775  {
1776  $establishment = new Establishment($this->db);
1777 
1778  $result = $establishment->fetch($id);
1779  if ($result < 0) {
1780  throw new RestException(503, 'Error when retrieving establishment : '.$establishment->error);
1781  } elseif ($result == 0) {
1782  throw new RestException(404, 'Establishment not found');
1783  }
1784 
1785  return $this->_cleanObjectDatas($establishment);
1786  }
1787 
1801  public function getConf($constantname)
1802  {
1803  global $conf;
1804 
1805  if (!DolibarrApiAccess::$user->admin
1806  && (empty($conf->global->API_LOGINS_ALLOWED_FOR_CONST_READ) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_CONST_READ)) {
1807  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');
1808  }
1809 
1810  if (!preg_match('/^[a-zA-Z0-9_]+$/', $constantname) || !isset($conf->global->$constantname)) {
1811  throw new RestException(404, 'Error Bad or unknown value for constantname');
1812  }
1813  if (isASecretKey($constantname)) {
1814  throw new RestException(403, 'Forbidden. This parameter cant be read with APIs');
1815  }
1816 
1817  return $conf->global->$constantname;
1818  }
1819 
1833  public function getCheckIntegrity($target)
1834  {
1835  global $langs, $conf;
1836 
1837  if (!DolibarrApiAccess::$user->admin
1838  && (empty($conf->global->API_LOGINS_ALLOWED_FOR_INTEGRITY_CHECK) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_INTEGRITY_CHECK)) {
1839  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');
1840  }
1841 
1842  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1843  require_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
1844 
1845  $langs->load("admin");
1846 
1847  $outexpectedchecksum = '';
1848  $outcurrentchecksum = '';
1849 
1850  // Modified or missing files
1851  $file_list = array('missing' => array(), 'updated' => array());
1852 
1853  // Local file to compare to
1854  $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));
1855  $xmlfile = DOL_DOCUMENT_ROOT.'/install/'.$xmlshortfile;
1856  // Remote file to compare to
1857  $xmlremote = ($target == 'default' ? '' : $target);
1858  if (empty($xmlremote) && !empty($conf->global->MAIN_FILECHECK_URL)) {
1859  $xmlremote = $conf->global->MAIN_FILECHECK_URL;
1860  }
1861  $param = 'MAIN_FILECHECK_URL_'.DOL_VERSION;
1862  if (empty($xmlremote) && !empty($conf->global->$param)) {
1863  $xmlremote = $conf->global->$param;
1864  }
1865  if (empty($xmlremote)) {
1866  $xmlremote = 'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.'.xml';
1867  }
1868  if ($xmlremote && !preg_match('/^https?:\/\//i', $xmlremote)) {
1869  $langs->load("errors");
1870  throw new RestException(500, $langs->trans("ErrorURLMustStartWithHttp", $xmlremote));
1871  }
1872  if ($xmlremote && !preg_match('/\.xml$/', $xmlremote)) {
1873  $langs->load("errors");
1874  throw new RestException(500, $langs->trans("ErrorURLMustEndWith", $xmlremote, '.xml'));
1875  }
1876 
1877  if ($target == 'local') {
1878  if (dol_is_file($xmlfile)) {
1879  $xml = simplexml_load_file($xmlfile);
1880  } else {
1881  throw new RestException(500, $langs->trans('XmlNotFound').': '.$xmlfile);
1882  }
1883  } else {
1884  $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.
1885 
1886  // Return array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...)
1887  if (!$xmlarray['curl_error_no'] && $xmlarray['http_code'] != '400' && $xmlarray['http_code'] != '404') {
1888  $xmlfile = $xmlarray['content'];
1889  //print "xmlfilestart".$xmlfile."endxmlfile";
1890  $xml = simplexml_load_string($xmlfile, 'SimpleXMLElement', LIBXML_NOCDATA|LIBXML_NONET);
1891  } else {
1892  $errormsg = $langs->trans('XmlNotFound').': '.$xmlremote.' - '.$xmlarray['http_code'].(($xmlarray['http_code'] == 400 && $xmlarray['content']) ? ' '.$xmlarray['content'] : '').' '.$xmlarray['curl_error_no'].' '.$xmlarray['curl_error_msg'];
1893  throw new RestException(500, $errormsg);
1894  }
1895  }
1896 
1897  if ($xml) {
1898  $checksumconcat = array();
1899  $file_list = array();
1900  $out = '';
1901 
1902  // Forced constants
1903  if (is_object($xml->dolibarr_constants[0])) {
1904  $out .= load_fiche_titre($langs->trans("ForcedConstants"));
1905 
1906  $out .= '<div class="div-table-responsive-no-min">';
1907  $out .= '<table class="noborder">';
1908  $out .= '<tr class="liste_titre">';
1909  $out .= '<td>#</td>';
1910  $out .= '<td>'.$langs->trans("Constant").'</td>';
1911  $out .= '<td class="center">'.$langs->trans("ExpectedValue").'</td>';
1912  $out .= '<td class="center">'.$langs->trans("Value").'</td>';
1913  $out .= '</tr>'."\n";
1914 
1915  $i = 0;
1916  foreach ($xml->dolibarr_constants[0]->constant as $constant) { // $constant is a simpleXMLElement
1917  $constname = $constant['name'];
1918  $constvalue = (string) $constant;
1919  $constvalue = (empty($constvalue) ? '0' : $constvalue);
1920  // Value found
1921  $value = '';
1922  if ($constname && $conf->global->$constname != '') {
1923  $value = $conf->global->$constname;
1924  }
1925  $valueforchecksum = (empty($value) ? '0' : $value);
1926 
1927  $checksumconcat[] = $valueforchecksum;
1928 
1929  $i++;
1930  $out .= '<tr class="oddeven">';
1931  $out .= '<td>'.$i.'</td>'."\n";
1932  $out .= '<td>'.$constname.'</td>'."\n";
1933  $out .= '<td class="center">'.$constvalue.'</td>'."\n";
1934  $out .= '<td class="center">'.$valueforchecksum.'</td>'."\n";
1935  $out .= "</tr>\n";
1936  }
1937 
1938  if ($i == 0) {
1939  $out .= '<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1940  }
1941  $out .= '</table>';
1942  $out .= '</div>';
1943 
1944  $out .= '<br>';
1945  }
1946 
1947  // Scan htdocs
1948  if (is_object($xml->dolibarr_htdocs_dir[0])) {
1949  $includecustom = (empty($xml->dolibarr_htdocs_dir[0]['includecustom']) ? 0 : $xml->dolibarr_htdocs_dir[0]['includecustom']);
1950 
1951  // Define qualified files (must be same than into generate_filelist_xml.php and in api_setup.class.php)
1952  $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)$';
1953  $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
1954  $scanfiles = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, $regextoinclude, $regextoexclude);
1955 
1956  // Fill file_list with files in signature, new files, modified files
1957  $ret = getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0], '', DOL_DOCUMENT_ROOT, $checksumconcat); // Fill array $file_list
1958  // Complete with list of new files
1959  foreach ($scanfiles as $keyfile => $valfile) {
1960  $tmprelativefilename = preg_replace('/^'.preg_quote(DOL_DOCUMENT_ROOT, '/').'/', '', $valfile['fullname']);
1961  if (!in_array($tmprelativefilename, $file_list['insignature'])) {
1962  $md5newfile = @md5_file($valfile['fullname']); // Can fails if we don't have permission to open/read file
1963  $file_list['added'][] = array('filename'=>$tmprelativefilename, 'md5'=>$md5newfile);
1964  }
1965  }
1966 
1967  // Files missings
1968  $out .= load_fiche_titre($langs->trans("FilesMissing"));
1969 
1970  $out .= '<div class="div-table-responsive-no-min">';
1971  $out .= '<table class="noborder">';
1972  $out .= '<tr class="liste_titre">';
1973  $out .= '<td>#</td>';
1974  $out .= '<td>'.$langs->trans("Filename").'</td>';
1975  $out .= '<td class="center">'.$langs->trans("ExpectedChecksum").'</td>';
1976  $out .= '</tr>'."\n";
1977  $tmpfilelist = dol_sort_array($file_list['missing'], 'filename');
1978  if (is_array($tmpfilelist) && count($tmpfilelist)) {
1979  $i = 0;
1980  foreach ($tmpfilelist as $file) {
1981  $i++;
1982  $out .= '<tr class="oddeven">';
1983  $out .= '<td>'.$i.'</td>'."\n";
1984  $out .= '<td>'.$file['filename'].'</td>'."\n";
1985  $out .= '<td class="center">'.$file['expectedmd5'].'</td>'."\n";
1986  $out .= "</tr>\n";
1987  }
1988  } else {
1989  $out .= '<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
1990  }
1991  $out .= '</table>';
1992  $out .= '</div>';
1993 
1994  $out .= '<br>';
1995 
1996  // Files modified
1997  $out .= load_fiche_titre($langs->trans("FilesModified"));
1998 
1999  $totalsize = 0;
2000  $out .= '<div class="div-table-responsive-no-min">';
2001  $out .= '<table class="noborder">';
2002  $out .= '<tr class="liste_titre">';
2003  $out .= '<td>#</td>';
2004  $out .= '<td>'.$langs->trans("Filename").'</td>';
2005  $out .= '<td class="center">'.$langs->trans("ExpectedChecksum").'</td>';
2006  $out .= '<td class="center">'.$langs->trans("CurrentChecksum").'</td>';
2007  $out .= '<td class="right">'.$langs->trans("Size").'</td>';
2008  $out .= '<td class="right">'.$langs->trans("DateModification").'</td>';
2009  $out .= '</tr>'."\n";
2010  $tmpfilelist2 = dol_sort_array($file_list['updated'], 'filename');
2011  if (is_array($tmpfilelist2) && count($tmpfilelist2)) {
2012  $i = 0;
2013  foreach ($tmpfilelist2 as $file) {
2014  $i++;
2015  $out .= '<tr class="oddeven">';
2016  $out .= '<td>'.$i.'</td>'."\n";
2017  $out .= '<td>'.$file['filename'].'</td>'."\n";
2018  $out .= '<td class="center">'.$file['expectedmd5'].'</td>'."\n";
2019  $out .= '<td class="center">'.$file['md5'].'</td>'."\n";
2020  $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
2021  $totalsize += $size;
2022  $out .= '<td class="right">'.dol_print_size($size).'</td>'."\n";
2023  $out .= '<td class="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']), 'dayhour').'</td>'."\n";
2024  $out .= "</tr>\n";
2025  }
2026  $out .= '<tr class="liste_total">';
2027  $out .= '<td></td>'."\n";
2028  $out .= '<td>'.$langs->trans("Total").'</td>'."\n";
2029  $out .= '<td align="center"></td>'."\n";
2030  $out .= '<td align="center"></td>'."\n";
2031  $out .= '<td class="right">'.dol_print_size($totalsize).'</td>'."\n";
2032  $out .= '<td class="right"></td>'."\n";
2033  $out .= "</tr>\n";
2034  } else {
2035  $out .= '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
2036  }
2037  $out .= '</table>';
2038  $out .= '</div>';
2039 
2040  $out .= '<br>';
2041 
2042  // Files added
2043  $out .= load_fiche_titre($langs->trans("FilesAdded"));
2044 
2045  $totalsize = 0;
2046  $out .= '<div class="div-table-responsive-no-min">';
2047  $out .= '<table class="noborder">';
2048  $out .= '<tr class="liste_titre">';
2049  $out .= '<td>#</td>';
2050  $out .= '<td>'.$langs->trans("Filename").'</td>';
2051  $out .= '<td class="center">'.$langs->trans("ExpectedChecksum").'</td>';
2052  $out .= '<td class="center">'.$langs->trans("CurrentChecksum").'</td>';
2053  $out .= '<td class="right">'.$langs->trans("Size").'</td>';
2054  $out .= '<td class="right">'.$langs->trans("DateModification").'</td>';
2055  $out .= '</tr>'."\n";
2056  $tmpfilelist3 = dol_sort_array($file_list['added'], 'filename');
2057  if (is_array($tmpfilelist3) && count($tmpfilelist3)) {
2058  $i = 0;
2059  foreach ($tmpfilelist3 as $file) {
2060  $i++;
2061  $out .= '<tr class="oddeven">';
2062  $out .= '<td>'.$i.'</td>'."\n";
2063  $out .= '<td>'.$file['filename'].'</td>'."\n";
2064  $out .= '<td class="center">'.$file['expectedmd5'].'</td>'."\n";
2065  $out .= '<td class="center">'.$file['md5'].'</td>'."\n";
2066  $size = dol_filesize(DOL_DOCUMENT_ROOT.'/'.$file['filename']);
2067  $totalsize += $size;
2068  $out .= '<td class="right">'.dol_print_size($size).'</td>'."\n";
2069  $out .= '<td class="right">'.dol_print_date(dol_filemtime(DOL_DOCUMENT_ROOT.'/'.$file['filename']), 'dayhour').'</td>'."\n";
2070  $out .= "</tr>\n";
2071  }
2072  $out .= '<tr class="liste_total">';
2073  $out .= '<td></td>'."\n";
2074  $out .= '<td>'.$langs->trans("Total").'</td>'."\n";
2075  $out .= '<td align="center"></td>'."\n";
2076  $out .= '<td align="center"></td>'."\n";
2077  $out .= '<td class="right">'.dol_print_size($totalsize).'</td>'."\n";
2078  $out .= '<td class="right"></td>'."\n";
2079  $out .= "</tr>\n";
2080  } else {
2081  $out .= '<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
2082  }
2083  $out .= '</table>';
2084  $out .= '</div>';
2085 
2086 
2087  // Show warning
2088  if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) {
2089  //setEventMessages($langs->trans("FileIntegrityIsStrictlyConformedWithReference"), null, 'mesgs');
2090  } else {
2091  //setEventMessages($langs->trans("FileIntegritySomeFilesWereRemovedOrModified"), null, 'warnings');
2092  }
2093  } else {
2094  throw new RestException(500, 'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile);
2095  }
2096 
2097 
2098  // Scan scripts
2099  asort($checksumconcat); // Sort list of checksum
2100  $checksumget = md5(join(',', $checksumconcat));
2101  $checksumtoget = trim((string) $xml->dolibarr_htdocs_dir_checksum);
2102 
2103  $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans("Unknown"));
2104  if ($checksumget == $checksumtoget) {
2105  if (count($file_list['added'])) {
2106  $resultcode = 'warning';
2107  $resultcomment = 'FileIntegrityIsOkButFilesWereAdded';
2108  //$outcurrentchecksum = $checksumget.' - <span class="'.$resultcode.'">'.$langs->trans("FileIntegrityIsOkButFilesWereAdded").'</span>';
2109  $outcurrentchecksum = $checksumget;
2110  } else {
2111  $resultcode = 'ok';
2112  $resultcomment = 'Success';
2113  //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
2114  $outcurrentchecksum = $checksumget;
2115  }
2116  } else {
2117  $resultcode = 'error';
2118  $resultcomment = 'Error';
2119  //$outcurrentchecksum = '<span class="'.$resultcode.'">'.$checksumget.'</span>';
2120  $outcurrentchecksum = $checksumget;
2121  }
2122  } else {
2123  throw new RestException(404, 'No signature file known');
2124  }
2125 
2126  return array('resultcode'=>$resultcode, 'resultcomment'=>$resultcomment, 'expectedchecksum'=> $outexpectedchecksum, 'currentchecksum'=> $outcurrentchecksum, 'out'=>$out);
2127  }
2128 
2129 
2139  public function getModules()
2140  {
2141  global $conf;
2142 
2143  if (!DolibarrApiAccess::$user->admin
2144  && (empty($conf->global->API_LOGINS_ALLOWED_FOR_GET_MODULES) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_GET_MODULES)) {
2145  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');
2146  }
2147 
2148  sort($conf->modules);
2149 
2150  return $this->_cleanObjectDatas($conf->modules);
2151  }
2152 }
Class to manage dictionary Countries (used by imports)
Class to manage dictionary States (used by imports)
Class for API REST v1.
Definition: api.class.php:31
Class to manage establishments.
getShippingModes($limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of shipping methods.
getListOfContactTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $type='', $module='', $active=1, $lang='', $sqlfilters='')
Get the list of contacts types.
getListOfExtrafields($sortfield="t.pos", $sortorder='ASC', $type='', $sqlfilters='')
Get the list of extra fields.
getTicketsCategories($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of tickets categories.
getListOfMeasuringUnits($sortfield="rowid", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of measuring units.
_cleanObjectDatas($object)
Clean sensible object datas.
getListOfStaff($sortfield="id", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of staff.
getTicketsSeverities($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of tickets severity.
translateLabel($object, $lang, $prefix='Country', $dict=array('dict'))
Translate the name of the object to the given language.
getCountryByISO($iso, $lang='')
Get country by Iso.
getCheckIntegrity($target)
Do a test of integrity for files and setup.
getListOfExpenseReportsTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $module='', $active=1, $sqlfilters='')
Get the list of Expense Report types.
__construct()
Constructor.
getListOfTowns($sortfield="zip,town", $sortorder='ASC', $limit=100, $page=0, $zipcode='', $town='', $active=1, $sqlfilters='')
Get the list of towns.
getStateByCode($code)
Get state by Code.
getListOfEventTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $type='', $module='', $active=1, $sqlfilters='')
Get the list of events types.
getEstablishments()
Get the list of establishments.
getListOfLegalForm($sortfield="rowid", $sortorder='ASC', $limit=100, $page=0, $country=0, $active=1, $sqlfilters='')
Get the list of legal form of business.
getListOfCurrencies($multicurrency=0, $sortfield="code_iso", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of currencies.
getListOfsocialNetworks($sortfield="rowid", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of social networks.
_fetchCstate($id, $code='')
Get state.
getEtablishmentByID($id)
Get establishment by ID.
getConf($constantname)
Get value of a setup variables.
getCompany()
Get properties of company.
getPaymentTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of payments types.
getCountryByID($id, $lang='')
Get country by ID.
getCountryByCode($code, $lang='')
Get country by Code.
getPaymentTerms($sortfield="sortorder", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of payments terms.
getOrderingOrigins($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of ordering origins.
getListOfStates($sortfield="code_departement", $sortorder='ASC', $limit=100, $page=0, $country=0, $filter='', $sqlfilters='')
Get the list of states/provinces.
getOrderingMethods($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of ordering methods.
_fetchCcountry($id, $code='', $iso='', $lang='')
Get country.
getStateByID($id)
Get state by ID.
getAvailability($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of delivery times.
getTicketsTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of tickets types.
getListOfCountries($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $filter='', $lang='', $sqlfilters='')
Get the list of countries.
getListOfCivilities($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $module='', $active=1, $lang='', $sqlfilters='')
Get the list of civilities.
getModules()
Get list of enabled modules.
Class to manage translations.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path='', $pathref='', &$checksumconcat=array())
Function to get list of updated or modified files.
Definition: files.lib.php:3255
dol_filemtime($pathoffile)
Return time of a file.
Definition: files.lib.php:597
dol_filesize($pathoffile)
Return size of a file.
Definition: files.lib.php:585
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:481
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:61
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
isASecretKey($keyname)
Return if string has a name dedicated to store a secret.
forgeSQLFromUniversalSearchCriteria($filter, &$error='')
forgeSQLFromUniversalSearchCriteria
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
jsonOrUnserialize($stringtodecode)
Decode an encode string.
isModEnabled($module)
Is Dolibarr module enabled.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1)
Function to get a content from an URL (use proxy if proxy defined).
Definition: geturl.lib.php:41
$conf db
API class for accounts.
Definition: inc.php:41