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