27use Luracast\Restler\RestException;
29require_once DOL_DOCUMENT_ROOT.
'/main.inc.php';
30require_once DOL_DOCUMENT_ROOT.
'/api/class/api.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/cstate.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/cregion.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/core/class/ccountry.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/hrm/class/establishment.class.php';
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/modules/DolibarrModules.class.php';
49 private $translations =
null;
79 public function getListOfActionTriggers($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $elementtype =
'', $lang =
'', $sqlfilters =
'')
83 if ($elementtype ==
'thirdparty') {
84 $elementtype =
'societe';
86 if ($elementtype ==
'contact') {
87 $elementtype =
'socpeople';
90 $sql =
"SELECT t.rowid as id, t.elementtype, t.code, t.contexts, t.label, t.description, t.rang";
91 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_action_trigger as t";
93 if (!empty($elementtype)) {
94 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
99 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
101 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
105 $sql .= $this->db->order($sortfield, $sortorder);
111 $offset = $limit * $page;
113 $sql .= $this->db->plimit($limit, $offset);
116 $result = $this->db->query($sql);
118 $num = $this->db->num_rows($result);
119 $min = min($num, ($limit <= 0 ? $num : $limit));
120 for ($i = 0; $i < $min; $i++) {
121 $type = $this->db->fetch_object($result);
126 throw new RestException(503,
'Error when retrieving list of action triggers : '.$this->db->lasterror());
152 public function getOrderingMethods($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
156 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
157 throw new RestException(403);
160 $sql =
"SELECT rowid, code, libelle as label, module";
161 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_input_method as t";
162 $sql .=
" WHERE t.active = ".((int) $active);
166 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
168 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
173 $sql .= $this->db->order($sortfield, $sortorder);
179 $offset = $limit * $page;
181 $sql .= $this->db->plimit($limit, $offset);
184 $result = $this->db->query($sql);
187 $num = $this->db->num_rows($result);
188 $min = min($num, ($limit <= 0 ? $num : $limit));
189 for ($i = 0; $i < $min; $i++) {
190 $list[] = $this->db->fetch_object($result);
193 throw new RestException(503, $this->db->lasterror());
218 public function getOrderingOrigins($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
222 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
223 throw new RestException(403);
226 $sql =
"SELECT rowid, code, label, module";
227 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_input_reason as t";
228 $sql .=
" WHERE t.active = ".((int) $active);
232 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
234 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
239 $sql .= $this->db->order($sortfield, $sortorder);
245 $offset = $limit * $page;
247 $sql .= $this->db->plimit($limit, $offset);
250 $result = $this->db->query($sql);
253 $num = $this->db->num_rows($result);
254 $min = min($num, ($limit <= 0 ? $num : $limit));
255 for ($i = 0; $i < $min; $i++) {
256 $list[] = $this->db->fetch_object($result);
259 throw new RestException(503, $this->db->lasterror());
285 public function getPaymentTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
289 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire') && !DolibarrApiAccess::$user->hasRight(
'commande',
'lire') && !DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
290 throw new RestException(403);
293 $sql =
"SELECT id, code, type, libelle as label, module";
294 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_paiement as t";
295 $sql .=
" WHERE t.entity IN (".getEntity(
'c_paiement').
")";
296 $sql .=
" AND t.active = ".((int) $active);
300 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
302 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
307 $sql .= $this->db->order($sortfield, $sortorder);
313 $offset = $limit * $page;
315 $sql .= $this->db->plimit($limit, $offset);
318 $result = $this->db->query($sql);
321 $num = $this->db->num_rows($result);
322 $min = min($num, ($limit <= 0 ? $num : $limit));
323 for ($i = 0; $i < $min; $i++) {
324 $list[] = $this->db->fetch_object($result);
327 throw new RestException(503, $this->db->lasterror());
354 public function getListOfRegions($sortfield =
"code_region", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $filter =
'', $sqlfilters =
'')
360 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.
"c_regions as t";
361 $sql .=
" WHERE 1 = 1";
363 $sql .=
" AND t.fk_pays = ".((int) $country);
368 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
370 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
374 $sql .= $this->db->order($sortfield, $sortorder);
380 $offset = $limit * $page;
382 $sql .= $this->db->plimit($limit, $offset);
385 $result = $this->db->query($sql);
388 $num = $this->db->num_rows($result);
389 $min = min($num, ($limit <= 0 ? $num : $limit));
390 for ($i = 0; $i < $min; $i++) {
391 $obj = $this->db->fetch_object($result);
392 $region =
new Cregion($this->db);
393 if ($region->fetch($obj->rowid) > 0) {
394 if (empty($filter) || stripos((
string) $region->name, $filter) !==
false) {
400 throw new RestException(503,
'Error when retrieving list of regions');
466 public function getListOfStates($sortfield =
"code_departement", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $filter =
'', $sqlfilters =
'')
472 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.
"c_departements as t";
474 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as d ON t.fk_region = d.code_region";
476 $sql .=
" WHERE 1 = 1";
478 $sql .=
" AND d.fk_pays = ".((int) $country);
483 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
485 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
489 $sql .= $this->db->order($sortfield, $sortorder);
495 $offset = $limit * $page;
497 $sql .= $this->db->plimit($limit, $offset);
500 $result = $this->db->query($sql);
503 $num = $this->db->num_rows($result);
504 $min = min($num, ($limit <= 0 ? $num : $limit));
505 for ($i = 0; $i < $min; $i++) {
506 $obj = $this->db->fetch_object($result);
507 $state =
new Cstate($this->db);
508 if ($state->fetch($obj->rowid) > 0) {
509 if (empty($filter) || stripos((
string) $state->label, $filter) !==
false) {
515 throw new RestException(503,
'Error when retrieving list of states');
583 public function getListOfCountries($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $filter =
'', $lang =
'', $sqlfilters =
'', $loadregions = 0, $loadstates = 0)
589 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"c_country as t";
590 $sql .=
" WHERE rowid > 0";
594 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
596 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
600 $sql .= $this->db->order($sortfield, $sortorder);
606 $offset = $limit * $page;
608 $sql .= $this->db->plimit($limit, $offset);
611 $result = $this->db->query($sql);
614 $num = $this->db->num_rows($result);
615 $min = min($num, ($limit <= 0 ? $num : $limit));
616 for ($i = 0; $i < $min; $i++) {
617 $obj = $this->db->fetch_object($result);
619 $fetchres = $country->fetch($obj->rowid);
620 if ($fetchres && $loadregions) {
621 $country->regions = $this->
getListOfRegions(
"code_region",
'ASC', 0, 0, $obj->rowid);
623 if ($fetchres && $loadstates) {
624 $country->states = $this->
getListOfStates(
"code_departement",
'ASC', 0, 0, $obj->rowid);
632 if (empty($filter) || stripos((
string) $country->label, $filter) !==
false) {
638 throw new RestException(503,
'Error when retrieving list of countries');
664 throw new RestException(400,
'Error: id < 1');
666 return $this->
_fetchCcountry(
$id,
'',
'', $lang =
'', $loadregions, $loadstates);
688 return $this->
_fetchCcountry(0, $code,
'', $lang =
'', $loadregions, $loadstates);
709 return $this->
_fetchCcountry(0,
'', $iso, $lang =
'', $loadregions, $loadstates);
725 $region =
new Cregion($this->db);
727 $result = $region->fetch(
$id, (
int) $code);
729 throw new RestException(503,
'Error when retrieving region : '.$region->error);
730 } elseif ($result == 0) {
731 throw new RestException(404,
'Region not found');
750 $state =
new Cstate($this->db);
752 $result = $state->fetch(
$id, $code);
754 throw new RestException(503,
'Error when retrieving state : '.$state->error);
755 } elseif ($result == 0) {
756 throw new RestException(404,
'State not found');
777 private function _fetchCcountry(
$id, $code =
'', $iso =
'', $lang =
'', $loadregions = 0, $loadstates = 0)
779 if ($loadregions || $loadstates) {
784 $result = $country->fetch(
$id, $code, $iso);
787 throw new RestException(503,
'Error when retrieving country : '.$country->error);
788 } elseif ($result == 0) {
789 throw new RestException(404,
'Country not found');
791 if ($loadregions > 0) {
792 $regions = $this->
getListOfRegions($sortfield =
"code_region", $sortorder =
'ASC', $limit = 0, $page = 0, $country->id, $filter =
'', $sqlfilters =
'');
793 $country->regions = $regions;
795 if ($loadstates > 0) {
796 $states = $this->
getListOfStates($sortfield =
"code_departement", $sortorder =
'ASC', $limit = 0, $page = 0, $country->id, $filter =
'', $sqlfilters =
'');
797 $country->states = $states;
826 public function getAvailability($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
830 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
831 throw new RestException(403);
834 $sql =
"SELECT rowid, code, label";
835 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_availability as t";
836 $sql .=
" WHERE t.active = ".((int) $active);
840 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
842 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
847 $sql .= $this->db->order($sortfield, $sortorder);
853 $offset = $limit * $page;
855 $sql .= $this->db->plimit($limit, $offset);
858 $result = $this->db->query($sql);
861 $num = $this->db->num_rows($result);
862 $min = min($num, ($limit <= 0 ? $num : $limit));
863 for ($i = 0; $i < $min; $i++) {
864 $list[] = $this->db->fetch_object($result);
867 throw new RestException(503, $this->db->lasterror());
907 if ($this->translations ==
null || $this->translations->getDefaultLang() !== $lang) {
910 $this->translations->setDefaultLang($lang);
911 $this->translations->loadLangs($dict);
914 $key = $prefix.$object->code;
916 $translation = $this->translations->trans($key);
917 if ($translation != $key) {
918 $object->label = html_entity_decode($translation);
944 public function getListOfEventTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $type =
'', $module =
'', $active = 1, $sqlfilters =
'')
948 $sql =
"SELECT id, code, type, libelle as label, module";
949 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_actioncomm as t";
950 $sql .=
" WHERE t.active = ".((int) $active);
952 $sql .=
" AND t.type LIKE '%".$this->db->escape($type).
"%'";
955 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
960 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
962 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
967 $sql .= $this->db->order($sortfield, $sortorder);
973 $offset = $limit * $page;
975 $sql .= $this->db->plimit($limit, $offset);
978 $result = $this->db->query($sql);
981 $num = $this->db->num_rows($result);
982 $min = min($num, ($limit <= 0 ? $num : $limit));
983 for ($i = 0; $i < $min; $i++) {
984 $list[] = $this->db->fetch_object($result);
987 throw new RestException(503,
'Error when retrieving list of events types : '.$this->db->lasterror());
1013 public function getListOfExpenseReportsTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $module =
'', $active = 1, $sqlfilters =
'')
1017 if (!DolibarrApiAccess::$user->hasRight(
'expensereport',
'lire')) {
1018 throw new RestException(403);
1021 $sql =
"SELECT id, code, label, accountancy_code, active, module, position";
1022 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees as t";
1023 $sql .=
" WHERE t.active = ".((int) $active);
1025 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
1030 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1031 if ($errormessage) {
1032 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1037 $sql .= $this->db->order($sortfield, $sortorder);
1043 $offset = $limit * $page;
1045 $sql .= $this->db->plimit($limit, $offset);
1048 $result = $this->db->query($sql);
1051 $num = $this->db->num_rows($result);
1052 $min = min($num, ($limit <= 0 ? $num : $limit));
1053 for ($i = 0; $i < $min; $i++) {
1054 $list[] = $this->db->fetch_object($result);
1057 throw new RestException(503,
'Error when retrieving list of expense report types : '.$this->db->lasterror());
1083 public function getListOfHolidayTypes($sortfield =
"sortorder", $sortorder =
'ASC', $limit = 100, $page = 0, $fk_country =
'', $active = 1, $lang =
'', $sqlfilters =
'')
1086 $langs->loadLangs(array(
'holiday'));
1088 if (!DolibarrApiAccess::$user->hasRight(
'holiday',
'read')) {
1089 throw new RestException(403);
1094 $sql =
"SELECT rowid, code, label, affect, delay, newbymonth, fk_country";
1095 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_holiday_types as t";
1096 $sql .=
" WHERE t.entity IN (".getEntity(
'c_holiday_types').
")";
1097 $sql .=
" AND t.active = ".((int) $active);
1099 $sql .=
" AND (t.fk_country = ".((int) $fk_country);
1100 $sql .=
" OR t.fk_country is null)";
1105 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1106 if ($errormessage) {
1107 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1111 $sql .= $this->db->order($sortfield, $sortorder);
1117 $offset = $limit * $page;
1119 $sql .= $this->db->plimit($limit, $offset);
1122 $result = $this->db->query($sql);
1125 $num = $this->db->num_rows($result);
1126 $min = min($num, ($limit <= 0 ? $num : $limit));
1127 for ($i = 0; $i < $min; $i++) {
1128 $holiday = $this->db->fetch_object($result);
1129 $tmplabel = $langs->trans($holiday->code);
1130 if ($tmplabel != $holiday->code) {
1131 $holiday->label = $tmplabel;
1137 throw new RestException(503,
'Error when retrieving list of holiday : '.$this->db->lasterror());
1163 public function getListOfPublicHolidays($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $fk_country =
'', $active = 1, $lang =
'', $sqlfilters =
'')
1166 $langs->loadLangs(array(
'hrm'));
1168 if (!DolibarrApiAccess::$user->hasRight(
'holiday',
'lire')) {
1169 throw new RestException(403);
1174 $sql =
"SELECT id, code, dayrule, day, month, year, fk_country, code as label";
1175 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_hrm_public_holiday as t";
1176 $sql .=
" WHERE t.entity IN (".getEntity(
'c_hrm_public_holiday').
")";
1177 $sql .=
" AND t.active = ".((int) $active);
1179 $sql .=
" AND (t.fk_country = ".((int) $fk_country);
1180 $sql .=
" OR t.fk_country is null)";
1185 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1186 if ($errormessage) {
1187 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1191 $sql .= $this->db->order($sortfield, $sortorder);
1197 $offset = $limit * $page;
1199 $sql .= $this->db->plimit($limit, $offset);
1202 $result = $this->db->query($sql);
1205 $num = $this->db->num_rows($result);
1206 $min = min($num, ($limit <= 0 ? $num : $limit));
1207 for ($i = 0; $i < $min; $i++) {
1208 $holiday = $this->db->fetch_object($result);
1209 $tmplabel = $langs->trans($holiday->code);
1210 if ($tmplabel != $holiday->code) {
1211 $holiday->label = $tmplabel;
1217 throw new RestException(503,
'Error when retrieving list of public holiday : '.$this->db->lasterror());
1244 public function getListOfContactTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $type =
'', $module =
'', $active = 1, $lang =
'', $sqlfilters =
'')
1248 if ($type ==
'expedition' && !
getDolGlobalInt(
'SHIPPING_USE_ITS_OWN_CONTACTS')) {
1252 $sql =
"SELECT rowid, code, element as type, libelle as label, source, module, position";
1253 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact as t";
1254 $sql .=
" WHERE t.active = ".((int) $active);
1256 $sql .=
" AND t.element LIKE '%".$this->db->escape($type).
"%'";
1259 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
1264 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1265 if ($errormessage) {
1266 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1271 $sql .= $this->db->order($sortfield, $sortorder);
1277 $offset = $limit * $page;
1279 $sql .= $this->db->plimit($limit, $offset);
1282 $result = $this->db->query($sql);
1285 $num = $this->db->num_rows($result);
1286 $min = min($num, ($limit <= 0 ? $num : $limit));
1287 for ($i = 0; $i < $min; $i++) {
1288 $contact_type = $this->db->fetch_object($result);
1289 $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"));
1290 $list[] = $contact_type;
1293 throw new RestException(503,
'Error when retrieving list of contacts types : '.$this->db->lasterror());
1319 public function getListOfCivilities($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $module =
'', $active = 1, $lang =
'', $sqlfilters =
'')
1323 $sql =
"SELECT rowid, code, label, module";
1324 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_civility as t";
1325 $sql .=
" WHERE t.active = ".((int) $active);
1327 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
1332 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1333 if ($errormessage) {
1334 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1339 $sql .= $this->db->order($sortfield, $sortorder);
1345 $offset = $limit * $page;
1347 $sql .= $this->db->plimit($limit, $offset);
1350 $result = $this->db->query($sql);
1353 $num = $this->db->num_rows($result);
1354 $min = min($num, ($limit <= 0 ? $num : $limit));
1355 for ($i = 0; $i < $min; $i++) {
1356 $civility = $this->db->fetch_object($result);
1357 $this->
translateLabel($civility, $lang,
'Civility', array(
'dict'));
1358 $list[] = $civility;
1361 throw new RestException(503,
'Error when retrieving list of civility : '.$this->db->lasterror());
1386 public function getListOfCurrencies($multicurrency = 0, $sortfield =
"code_iso", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1389 $sql =
"SELECT t.code_iso, t.label, t.unicode";
1390 if (!empty($multicurrency)) {
1391 $sql .=
" , cr.date_sync, cr.rate ";
1393 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_currencies as t";
1394 if (!empty($multicurrency)) {
1395 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"multicurrency as m ON m.code=t.code_iso";
1396 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"multicurrency_rate as cr ON (m.rowid = cr.fk_multicurrency)";
1398 $sql .=
" WHERE t.active = ".((int) $active);
1399 if (!empty($multicurrency)) {
1400 $sql .=
" AND m.entity IN (".getEntity(
'multicurrency').
")";
1401 if (!empty($multicurrency) && $multicurrency != 2) {
1402 $sql .=
" AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM ".MAIN_DB_PREFIX.
"multicurrency_rate AS cr2 WHERE cr2.fk_multicurrency = m.rowid)";
1409 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1410 if ($errormessage) {
1411 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1416 $sql .= $this->db->order($sortfield, $sortorder);
1422 $offset = $limit * $page;
1424 $sql .= $this->db->plimit($limit, $offset);
1427 $result = $this->db->query($sql);
1430 $num = $this->db->num_rows($result);
1431 $min = min($num, ($limit <= 0 ? $num : $limit));
1432 for ($i = 0; $i < $min; $i++) {
1433 $list[] = $this->db->fetch_object($result);
1436 throw new RestException(503,
'Error when retrieving list of currency : '.$this->db->lasterror());
1458 public function getListOfExtrafields($sortfield =
"t.pos", $sortorder =
'ASC', $elementtype =
'', $sqlfilters =
'')
1462 if (!DolibarrApiAccess::$user->admin
1464 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_EXTRAFIELDS');
1467 if ($elementtype ==
'thirdparty') {
1468 $elementtype =
'societe';
1470 if ($elementtype ==
'contact') {
1471 $elementtype =
'socpeople';
1474 $sql =
"SELECT t.rowid as id, t.name, t.entity, t.elementtype, t.label, t.type, t.size, t.fieldcomputed, t.fielddefault,";
1475 $sql .=
" t.fieldunique, t.fieldrequired, t.perms, t.enabled, t.pos, t.alwayseditable, t.param, t.list, t.printable,";
1476 $sql .=
" t.totalizable, t.langs, t.help, t.css, t.cssview, t.csslist, t.fk_user_author, t.fk_user_modif, t.datec, t.tms";
1477 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1478 $sql .=
" WHERE t.entity IN (".getEntity(
'extrafields').
")";
1479 if (!empty($elementtype)) {
1480 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
1485 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1486 if ($errormessage) {
1487 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1491 $sql .= $this->db->order($sortfield, $sortorder);
1493 $resql = $this->db->query($sql);
1495 if ($this->db->num_rows($resql)) {
1496 while ($tab = $this->db->fetch_object($resql)) {
1498 $list[$tab->elementtype][$tab->name][
'id'] = $tab->id;
1499 $list[$tab->elementtype][$tab->name][
'type'] = $tab->type;
1500 $list[$tab->elementtype][$tab->name][
'label'] = $tab->label;
1501 $list[$tab->elementtype][$tab->name][
'size'] = $tab->size;
1502 $list[$tab->elementtype][$tab->name][
'elementtype'] = $tab->elementtype;
1503 $list[$tab->elementtype][$tab->name][
'default'] = $tab->fielddefault;
1504 $list[$tab->elementtype][$tab->name][
'computed'] = $tab->fieldcomputed;
1505 $list[$tab->elementtype][$tab->name][
'unique'] = $tab->fieldunique;
1506 $list[$tab->elementtype][$tab->name][
'required'] = $tab->fieldrequired;
1507 $list[$tab->elementtype][$tab->name][
'param'] = ($tab->param ? jsonOrUnserialize($tab->param) :
'');
1508 $list[$tab->elementtype][$tab->name][
'pos'] = $tab->pos;
1509 $list[$tab->elementtype][$tab->name][
'alwayseditable'] = $tab->alwayseditable;
1510 $list[$tab->elementtype][$tab->name][
'perms'] = $tab->perms;
1511 $list[$tab->elementtype][$tab->name][
'list'] = $tab->list;
1512 $list[$tab->elementtype][$tab->name][
'printable'] = $tab->printable;
1513 $list[$tab->elementtype][$tab->name][
'showintooltip'] = $tab->showintooltip;
1514 $list[$tab->elementtype][$tab->name][
'totalizable'] = $tab->totalizable;
1515 $list[$tab->elementtype][$tab->name][
'langs'] = $tab->langs;
1516 $list[$tab->elementtype][$tab->name][
'help'] = $tab->help;
1517 $list[$tab->elementtype][$tab->name][
'css'] = $tab->css;
1518 $list[$tab->elementtype][$tab->name][
'cssview'] = $tab->cssview;
1519 $list[$tab->elementtype][$tab->name][
'csslist'] = $tab->csslist;
1520 $list[$tab->elementtype][$tab->name][
'fk_user_author'] = $tab->fk_user_author;
1521 $list[$tab->elementtype][$tab->name][
'fk_user_modif'] = $tab->fk_user_modif;
1522 $list[$tab->elementtype][$tab->name][
'datec'] = $tab->datec;
1523 $list[$tab->elementtype][$tab->name][
'tms'] = $tab->tms;
1527 throw new RestException(503,
'Error when retrieving list of extra fields : '.$this->db->lasterror());
1546 if (!DolibarrApiAccess::$user->admin) {
1547 throw new RestException(403,
'Only an admin user can delete an extrafield by attrname and elementtype');
1552 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1554 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1557 if (!$extrafields->delete($attrname, $elementtype)) {
1558 throw new RestException(500,
'Error when delete extrafield : '.$extrafields->error);
1564 'message' =>
'Extrafield deleted from attrname and elementtype'
1587 if (!DolibarrApiAccess::$user->admin) {
1588 throw new RestException(403,
'Only an admin user can get list of extrafields');
1591 if ($elementtype ==
'thirdparty') {
1592 $elementtype =
'societe';
1594 if ($elementtype ==
'contact') {
1595 $elementtype =
'socpeople';
1598 $sql =
"SELECT t.rowid as id, t.name, t.entity, t.elementtype, t.label, t.type, t.size, t.fieldcomputed, t.fielddefault,";
1599 $sql .=
" t.fieldunique, t.fieldrequired, t.perms, t.enabled, t.pos, t.alwayseditable, t.param, t.list, t.printable, t.showintooltip,";
1600 $sql .=
" t.totalizable, t.langs, t.help, t.css, t.cssview, t.csslist, t.fk_user_author, t.fk_user_modif, t.datec, t.tms";
1601 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1602 $sql .=
" WHERE t.entity IN (".getEntity(
'extrafields').
")";
1603 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
1604 $sql .=
" AND t.name = '".$this->db->escape($attrname).
"'";
1606 $resql = $this->db->query($sql);
1608 if ($this->db->num_rows($resql)) {
1609 while ($tab = $this->db->fetch_object($resql)) {
1611 $answer[$tab->elementtype][$tab->name][
'id'] = $tab->id;
1612 $answer[$tab->elementtype][$tab->name][
'type'] = $tab->type;
1613 $answer[$tab->elementtype][$tab->name][
'label'] = $tab->label;
1614 $answer[$tab->elementtype][$tab->name][
'size'] = $tab->size;
1615 $answer[$tab->elementtype][$tab->name][
'elementtype'] = $tab->elementtype;
1616 $answer[$tab->elementtype][$tab->name][
'default'] = $tab->fielddefault;
1617 $answer[$tab->elementtype][$tab->name][
'computed'] = $tab->fieldcomputed;
1618 $answer[$tab->elementtype][$tab->name][
'unique'] = $tab->fieldunique;
1619 $answer[$tab->elementtype][$tab->name][
'required'] = $tab->fieldrequired;
1620 $answer[$tab->elementtype][$tab->name][
'param'] = ($tab->param ? jsonOrUnserialize($tab->param) :
'');
1621 $answer[$tab->elementtype][$tab->name][
'pos'] = $tab->pos;
1622 $answer[$tab->elementtype][$tab->name][
'alwayseditable'] = $tab->alwayseditable;
1623 $answer[$tab->elementtype][$tab->name][
'perms'] = $tab->perms;
1624 $answer[$tab->elementtype][$tab->name][
'list'] = $tab->list;
1625 $answer[$tab->elementtype][$tab->name][
'printable'] = $tab->printable;
1626 $answer[$tab->elementtype][$tab->name][
'showintooltip'] = $tab->showintooltip;
1627 $answer[$tab->elementtype][$tab->name][
'totalizable'] = $tab->totalizable;
1628 $answer[$tab->elementtype][$tab->name][
'langs'] = $tab->langs;
1629 $answer[$tab->elementtype][$tab->name][
'help'] = $tab->help;
1630 $answer[$tab->elementtype][$tab->name][
'css'] = $tab->css;
1631 $answer[$tab->elementtype][$tab->name][
'cssview'] = $tab->cssview;
1632 $answer[$tab->elementtype][$tab->name][
'csslist'] = $tab->csslist;
1633 $answer[$tab->elementtype][$tab->name][
'fk_user_author'] = $tab->fk_user_author;
1634 $answer[$tab->elementtype][$tab->name][
'fk_user_modif'] = $tab->fk_user_modif;
1635 $answer[$tab->elementtype][$tab->name][
'datec'] = $tab->datec;
1636 $answer[$tab->elementtype][$tab->name][
'tms'] = $tab->tms;
1639 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1642 throw new RestException(503,
'Error when retrieving list of extra fields : '.$this->db->lasterror());
1664 if (!DolibarrApiAccess::$user->admin) {
1665 throw new RestException(403,
'Only an admin user can create an extrafield');
1670 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1672 throw new RestException(409,
'Duplicate extrafield already found from attrname and elementtype');
1678 foreach ($request_data as $field => $value) {
1679 $extrafields->$field = $this->
_checkValForAPI($field, $value, $extrafields);
1682 $entity = DolibarrApiAccess::$user->entity;
1683 if (empty($entity)) {
1690 if ($request_data[
'label']) {
1691 $label = $request_data[
'label'];
1693 throw new RestException(400,
"label field absent in json at root level");
1696 $alwayseditable = $request_data[
'alwayseditable'];
1697 $default_value = $request_data[
'default'];
1698 $totalizable = $request_data[
'totalizable'];
1699 $printable = $request_data[
'printable'];
1700 $showintooltip = $request_data[
'showintooltip'];
1701 $required = $request_data[
'required'];
1702 $langfile = $request_data[
'langfile'];
1703 $computed = $request_data[
'computed'];
1704 $unique = $request_data[
'unique'];
1705 $param = $request_data[
'param'];
1706 $perms = $request_data[
'perms'];
1707 $size = $request_data[
'size'];
1708 $type = $request_data[
'type'];
1709 $list = $request_data[
'list'];
1710 $help = $request_data[
'help'];
1711 $pos = $request_data[
'pos'];
1712 $moreparams = array();
1714 if (0 > $extrafields->addExtraField($attrname, $label, $type, (
int) $pos, $size, $elementtype, (
int) $unique, (
int) $required, $default_value, $param, (
int) $alwayseditable, $perms, $list, $help, $computed, (
string) $entity, $langfile, (
string) $enabled, (
int) $totalizable, (
int) $printable, $moreparams)) {
1715 throw new RestException(500,
'Error creating extrafield', array_merge(array($extrafields->errno), $extrafields->errors));
1718 $sql =
"SELECT t.rowid as id";
1719 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1720 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1721 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1723 $resql = $this->db->query($sql);
1725 if ($this->db->num_rows($resql)) {
1726 $tab = $this->db->fetch_object($resql);
1727 $id = (int) $tab->id;
1755 if (!DolibarrApiAccess::$user->admin) {
1756 throw new RestException(403,
'Only an admin user can create an extrafield');
1761 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1763 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1766 foreach ($request_data as $field => $value) {
1767 $extrafields->$field = $this->
_checkValForAPI($field, $value, $extrafields);
1770 $entity = DolibarrApiAccess::$user->entity;
1771 if (empty($entity)) {
1777 if ($request_data[
'label']) {
1778 $label = $request_data[
'label'];
1780 throw new RestException(400,
"label field absent in json at root level");
1783 $alwayseditable = $request_data[
'alwayseditable'];
1784 $default_value = $request_data[
'default'];
1785 $totalizable = $request_data[
'totalizable'];
1786 $printable = $request_data[
'printable'];
1787 $showintooltip = $request_data[
'showintooltip'];
1788 $required = $request_data[
'required'];
1789 $langfile = $request_data[
'langfile'];
1790 $computed = $request_data[
'computed'];
1791 $unique = $request_data[
'unique'];
1792 $param = $request_data[
'param'];
1793 $perms = $request_data[
'perms'];
1794 $size = $request_data[
'size'];
1795 $type = $request_data[
'type'];
1796 $list = $request_data[
'list'];
1797 $help = $request_data[
'help'];
1798 $pos = $request_data[
'pos'];
1799 $moreparams = array();
1801 if (0 > $extrafields->updateExtraField($attrname, $label, $type, (
int) $pos, $size, $elementtype, (
int) $unique, (
int) $required, $default_value, $param, (
int) $alwayseditable, $perms, $list, $help, $computed, (
string) $entity, $langfile, (
string) $enabled, (
int) $totalizable, (
int) $printable, $moreparams)) {
1802 throw new RestException(500,
'Error updating extrafield', array_merge(array($extrafields->errno), $extrafields->errors));
1805 $sql =
"SELECT t.rowid as id";
1806 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1807 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1808 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1810 $resql = $this->db->query($sql);
1812 if ($this->db->num_rows($resql)) {
1813 $tab = $this->db->fetch_object($resql);
1814 $id = (int) $tab->id;
1845 public function getListOfTowns($sortfield =
"zip,town", $sortorder =
'ASC', $limit = 100, $page = 0, $zipcode =
'', $town =
'', $active = 1, $sqlfilters =
'')
1849 $sql =
"SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
1850 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ziptown as t";
1851 $sql .=
" WHERE t.active = ".((int) $active);
1853 $sql .=
" AND t.zip LIKE '%".$this->db->escape($zipcode).
"%'";
1856 $sql .=
" AND t.town LIKE '%".$this->db->escape($town).
"%'";
1861 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1862 if ($errormessage) {
1863 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1868 $sql .= $this->db->order($sortfield, $sortorder);
1874 $offset = $limit * $page;
1876 $sql .= $this->db->plimit($limit, $offset);
1879 $result = $this->db->query($sql);
1882 $num = $this->db->num_rows($result);
1883 $min = min($num, ($limit <= 0 ? $num : $limit));
1884 for ($i = 0; $i < $min; $i++) {
1885 $list[] = $this->db->fetch_object($result);
1888 throw new RestException(503,
'Error when retrieving list of towns : '.$this->db->lasterror());
1914 public function getPaymentTerms($sortfield =
"sortorder", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1918 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire') && !DolibarrApiAccess::$user->hasRight(
'commande',
'lire') && !DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1919 throw new RestException(403);
1922 $sql =
"SELECT rowid as id, code, sortorder, libelle as label, libelle_facture as descr, type_cdr, nbjour, decalage, module";
1923 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_payment_term as t";
1924 $sql .=
" WHERE t.entity IN (".getEntity(
'c_payment_term').
")";
1925 $sql .=
" AND t.active = ".((int) $active);
1929 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1930 if ($errormessage) {
1931 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1936 $sql .= $this->db->order($sortfield, $sortorder);
1942 $offset = $limit * $page;
1944 $sql .= $this->db->plimit($limit, $offset);
1947 $result = $this->db->query($sql);
1950 $num = $this->db->num_rows($result);
1951 $min = min($num, ($limit <= 0 ? $num : $limit));
1952 for ($i = 0; $i < $min; $i++) {
1953 $list[] = $this->db->fetch_object($result);
1956 throw new RestException(503, $this->db->lasterror());
1980 public function getShippingModes($limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
1984 $sql =
"SELECT rowid as id, code, libelle as label, description, tracking, module";
1985 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as t";
1986 $sql .=
" WHERE t.entity IN (".getEntity(
'c_shipment_mode').
")";
1987 $sql .=
" AND t.active = ".((int) $active);
1991 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
1992 if ($errormessage) {
1993 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2004 $offset = $limit * $page;
2006 $sql .= $this->db->plimit($limit, $offset);
2009 $result = $this->db->query($sql);
2012 $num = $this->db->num_rows($result);
2013 $min = min($num, ($limit <= 0 ? $num : $limit));
2014 for ($i = 0; $i < $min; $i++) {
2015 $method = $this->db->fetch_object($result);
2020 throw new RestException(503, $this->db->lasterror());
2044 public function getListOfMeasuringUnits($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
2048 $sql =
"SELECT t.rowid, t.code, t.label,t.short_label, t.active, t.scale, t.unit_type";
2049 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_units as t";
2050 $sql .=
" WHERE t.active = ".((int) $active);
2054 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
2055 if ($errormessage) {
2056 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2061 $sql .= $this->db->order($sortfield, $sortorder);
2067 $offset = $limit * $page;
2069 $sql .= $this->db->plimit($limit, $offset);
2072 $result = $this->db->query($sql);
2075 $num = $this->db->num_rows($result);
2076 $min = min($num, ($limit <= 0 ? $num : $limit));
2077 for ($i = 0; $i < $min; $i++) {
2078 $list[] = $this->db->fetch_object($result);
2081 throw new RestException(503,
'Error when retrieving list of measuring units: '.$this->db->lasterror());
2106 public function getListOfLegalForm($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $active = 1, $sqlfilters =
'')
2110 $sql =
"SELECT t.rowid, t.code, t.fk_pays, t.libelle, t.isvatexempted, t.active, t.module, t.position";
2111 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_forme_juridique as t";
2112 $sql .=
" WHERE t.active = ".((int) $active);
2114 $sql .=
" AND t.fk_pays = ".((int) $country);
2119 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
2120 if ($errormessage) {
2121 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2126 $sql .= $this->db->order($sortfield, $sortorder);
2132 $offset = $limit * $page;
2134 $sql .= $this->db->plimit($limit, $offset);
2137 $result = $this->db->query($sql);
2140 $num = $this->db->num_rows($result);
2141 $min = min($num, ($limit <= 0 ? $num : $limit));
2142 for ($i = 0; $i < $min; $i++) {
2143 $list[] = $this->db->fetch_object($result);
2146 throw new RestException(503,
'Error when retrieving list of legal form: '.$this->db->lasterror());
2170 public function getListOfStaff($sortfield =
"id", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
2174 $sql =
"SELECT t.id, t.code, t.libelle, t.active, t.module";
2175 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_effectif as t";
2176 $sql .=
" WHERE t.active = ".((int) $active);
2180 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
2181 if ($errormessage) {
2182 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2187 $sql .= $this->db->order($sortfield, $sortorder);
2193 $offset = $limit * $page;
2195 $sql .= $this->db->plimit($limit, $offset);
2198 $result = $this->db->query($sql);
2201 $num = $this->db->num_rows($result);
2202 $min = min($num, ($limit <= 0 ? $num : $limit));
2203 for ($i = 0; $i < $min; $i++) {
2204 $list[] = $this->db->fetch_object($result);
2207 throw new RestException(503,
'Error when retrieving list of staff: '.$this->db->lasterror());
2231 public function getListOfsocialNetworks($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
2236 throw new RestException(400,
'API not available: this dictionary is not enabled by setup');
2241 $sql =
"SELECT t.rowid, t.entity, t.code, t.label, t.url, t.icon, t.active";
2242 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_socialnetworks as t";
2243 $sql .=
" WHERE t.entity IN (".getEntity(
'c_socialnetworks').
")";
2244 $sql .=
" AND t.active = ".((int) $active);
2248 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
2249 if ($errormessage) {
2250 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2255 $sql .= $this->db->order($sortfield, $sortorder);
2261 $offset = $limit * $page;
2263 $sql .= $this->db->plimit($limit, $offset);
2266 $result = $this->db->query($sql);
2269 $num = $this->db->num_rows($result);
2270 $min = min($num, ($limit <= 0 ? $num : $limit));
2271 for ($i = 0; $i < $min; $i++) {
2272 $list[] = $this->db->fetch_object($result);
2275 throw new RestException(503,
'Error when retrieving list of social networks: '.$this->db->lasterror());
2300 public function getTicketsCategories($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2304 $sql =
"SELECT rowid, code, pos, label, use_default, description";
2305 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_category as t";
2306 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_category').
")";
2307 $sql .=
" AND t.active = ".((int) $active);
2311 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
2312 if ($errormessage) {
2313 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2318 $sql .= $this->db->order($sortfield, $sortorder);
2324 $offset = $limit * $page;
2326 $sql .= $this->db->plimit($limit, $offset);
2329 $result = $this->db->query($sql);
2332 $num = $this->db->num_rows($result);
2333 $min = min($num, ($limit <= 0 ? $num : $limit));
2334 for ($i = 0; $i < $min; $i++) {
2335 $category = $this->db->fetch_object($result);
2336 $this->
translateLabel($category, $lang,
'TicketCategoryShort', array(
'ticket'));
2337 $list[] = $category;
2340 throw new RestException(503,
'Error when retrieving list of ticket categories : '.$this->db->lasterror());
2365 public function getTicketsSeverities($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2369 $sql =
"SELECT rowid, code, pos, label, use_default, color, description";
2370 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_severity as t";
2371 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_severity').
")";
2372 $sql .=
" AND t.active = ".((int) $active);
2376 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
2377 if ($errormessage) {
2378 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2383 $sql .= $this->db->order($sortfield, $sortorder);
2389 $offset = $limit * $page;
2391 $sql .= $this->db->plimit($limit, $offset);
2394 $result = $this->db->query($sql);
2397 $num = $this->db->num_rows($result);
2398 $min = min($num, ($limit <= 0 ? $num : $limit));
2399 for ($i = 0; $i < $min; $i++) {
2400 $severity = $this->db->fetch_object($result);
2401 $this->
translateLabel($severity, $lang,
'TicketSeverityShort', array(
'ticket'));
2402 $list[] = $severity;
2405 throw new RestException(503,
'Error when retrieving list of ticket severities : '.$this->db->lasterror());
2430 public function getTicketsTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2434 $sql =
"SELECT rowid, code, pos, label, use_default, description";
2435 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_type as t";
2436 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_type').
")";
2437 $sql .=
" AND t.active = ".((int) $active);
2442 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
2443 if ($errormessage) {
2444 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2449 $sql .= $this->db->order($sortfield, $sortorder);
2455 $offset = $limit * $page;
2457 $sql .= $this->db->plimit($limit, $offset);
2460 $result = $this->db->query($sql);
2463 $num = $this->db->num_rows($result);
2464 $min = min($num, ($limit <= 0 ? $num : $limit));
2465 for ($i = 0; $i < $min; $i++) {
2466 $type = $this->db->fetch_object($result);
2467 $this->
translateLabel($type, $lang,
'TicketTypeShort', array(
'ticket'));
2471 throw new RestException(503,
'Error when retrieving list of ticket types : '.$this->db->lasterror());
2496 public function getThirdpartiesTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2500 $sql =
"SELECT id, code, libelle as label, fk_country, module, position";
2501 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_typent as t";
2502 $sql .=
" WHERE t.active = ".((int) $active);
2507 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
2508 if ($errormessage) {
2509 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2514 $sql .= $this->db->order($sortfield, $sortorder);
2520 $offset = $limit * $page;
2522 $sql .= $this->db->plimit($limit, $offset);
2525 $result = $this->db->query($sql);
2528 $num = $this->db->num_rows($result);
2529 $min = min($num, ($limit <= 0 ? $num : $limit));
2530 for ($i = 0; $i < $min; $i++) {
2531 $type = $this->db->fetch_object($result);
2536 throw new RestException(503,
'Error when retrieving list of thirdparty types : '.$this->db->lasterror());
2560 public function getListOfIncoterms($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2564 $sql =
"SELECT rowid, code, active";
2565 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_incoterms as t";
2566 $sql .=
" WHERE 1=1";
2571 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
2572 if ($errormessage) {
2573 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2578 $sql .= $this->db->order($sortfield, $sortorder);
2584 $offset = $limit * $page;
2586 $sql .= $this->db->plimit($limit, $offset);
2589 $result = $this->db->query($sql);
2592 $num = $this->db->num_rows($result);
2593 $min = min($num, ($limit <= 0 ? $num : $limit));
2594 for ($i = 0; $i < $min; $i++) {
2595 $type = $this->db->fetch_object($result);
2599 throw new RestException(503,
'Error when retrieving list of incoterm types : '.$this->db->lasterror());
2623 public function getListOfVAT($sortfield =
"taux", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $fk_country = -1, $sqlfilters =
'')
2628 $sql =
"SELECT rowid, code, type_vat, active, fk_pays, taux, localtax1, localtax2, localtax1_type, localtax2_type, note";
2629 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_tva as t";
2630 $sql .=
" WHERE 1=1";
2635 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
2636 if ($errormessage) {
2637 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2641 $sql .=
" AND active = ".((int) $active);
2643 if ($fk_country == -1)
2644 $sql .=
" AND fk_pays =".((int)
$mysoc->country_id);
2647 $sql .=
" AND fk_pays =".((int) $fk_country);
2649 $sql .= $this->db->order($sortfield, $sortorder);
2655 $offset = $limit * $page;
2657 $sql .= $this->db->plimit($limit, $offset);
2660 $result = $this->db->query($sql);
2663 $num = $this->db->num_rows($result);
2664 $min = min($num, ($limit <= 0 ? $num : $limit));
2665 for ($i = 0; $i < $min; $i++) {
2666 $type = $this->db->fetch_object($result);
2670 throw new RestException(503,
'Error when retrieving list of vat types : '.$this->db->lasterror());
2691 if (!DolibarrApiAccess::$user->admin
2693 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');
2703 unset(
$mysoc->effectif_id);
2704 unset(
$mysoc->forme_juridique_code);
2705 unset(
$mysoc->forme_juridique);
2706 unset(
$mysoc->mode_reglement_supplier_id);
2707 unset(
$mysoc->cond_reglement_supplier_id);
2708 unset(
$mysoc->transport_mode_supplier_id);
2709 unset(
$mysoc->fk_prospectlevel);
2712 unset(
$mysoc->total_tva);
2713 unset(
$mysoc->total_localtax1);
2714 unset(
$mysoc->total_localtax2);
2715 unset(
$mysoc->total_ttc);
2718 unset(
$mysoc->firstname);
2719 unset(
$mysoc->civility_id);
2723 unset(
$mysoc->fournisseur);
2724 unset(
$mysoc->contact_id);
2726 unset(
$mysoc->fk_incoterms);
2727 unset(
$mysoc->label_incoterms);
2728 unset(
$mysoc->location_incoterms);
2750 $sql =
"SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
2751 $sql .=
" FROM ".MAIN_DB_PREFIX.
"establishment as e";
2752 $sql .=
" WHERE e.entity IN (".getEntity(
'establishment').
')';
2757 $result = $this->db->query($sql);
2760 $num = $this->db->num_rows($result);
2761 $min = min($num, ($limit <= 0 ? $num : $limit));
2762 for ($i = 0; $i < $min; $i++) {
2763 $list[] = $this->db->fetch_object($result);
2766 throw new RestException(503,
'Error when retrieving list of establishments : '.$this->db->lasterror());
2787 $result = $establishment->fetch(
$id);
2789 throw new RestException(503,
'Error when retrieving establishment : '.$establishment->error);
2790 } elseif ($result == 0) {
2791 throw new RestException(404,
'Establishment not found');
2814 if (!DolibarrApiAccess::$user->admin
2816 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');
2819 if (!preg_match(
'/^[a-zA-Z0-9_]+$/', $constantname) || !isset(
$conf->global->$constantname)) {
2820 throw new RestException(400,
'Error Bad or unknown value for constantname');
2823 throw new RestException(403,
'Forbidden. This parameter can not be read with APIs');
2847 if (!DolibarrApiAccess::$user->admin
2849 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');
2852 $sql =
"select name, value";
2853 $sql .=
" FROM ".MAIN_DB_PREFIX.
"const";
2854 $sql .=
" WHERE entity IN (".getEntity(
'const').
')';
2856 $result = $this->db->query($sql);
2859 $num = $this->db->num_rows($result);
2860 for ($i = 0; $i < $num; $i++) {
2861 $obj = $this->db->fetch_object($result);
2864 $list[$obj->name] = $obj->value;
2868 throw new RestException(503,
'Error when retrieving list of const : '.$this->db->lasterror());
2890 global $langs,
$conf;
2892 if (!DolibarrApiAccess::$user->admin
2894 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');
2897 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2898 require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
2900 $langs->load(
"admin");
2902 $outexpectedchecksum =
'';
2903 $outcurrentchecksum =
'';
2906 $file_list = array(
'missing' => array(),
'updated' => array());
2911 $xmlfile = DOL_DOCUMENT_ROOT.
'/install/'.$xmlshortfile;
2912 if (!preg_match(
'/\.zip$/i', $xmlfile) &&
dol_is_file($xmlfile.
'.zip')) {
2917 $xmlremote = (($target ==
'default' || $target ==
'local') ?
'' : $target);
2921 $param =
'MAIN_FILECHECK_URL_'.DOL_VERSION;
2925 if (empty($xmlremote)) {
2926 $xmlremote =
'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.
'.xml';
2928 if ($xmlremote && !preg_match(
'/^https?:\/\//i', $xmlremote)) {
2929 $langs->load(
"errors");
2930 throw new RestException(500, $langs->trans(
"ErrorURLMustStartWithHttp", $xmlremote));
2932 if ($xmlremote && !preg_match(
'/\.xml$/', $xmlremote)) {
2933 $langs->load(
"errors");
2934 throw new RestException(500, $langs->trans(
"ErrorURLMustEndWith", $xmlremote,
'.xml'));
2937 if (LIBXML_VERSION < 20900) {
2941 libxml_disable_entity_loader(
true);
2944 if ($target ==
'local') {
2946 $xml = simplexml_load_file($xmlfile);
2948 throw new RestException(500, $langs->trans(
'XmlNotFound').
': /install/'.$xmlshortfile);
2951 $xmlarray =
getURLContent($xmlremote,
'GET',
'', 1, array(), array(
'http',
'https'), 0);
2954 if (!$xmlarray[
'curl_error_no'] && $xmlarray[
'http_code'] != 400 && $xmlarray[
'http_code'] != 404) {
2955 $xmlfile = $xmlarray[
'content'];
2957 $xml = simplexml_load_string($xmlfile,
'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NONET);
2959 $errormsg = $langs->trans(
'XmlNotFound').
': '.$xmlremote.
' - '.$xmlarray[
'http_code'].(($xmlarray[
'http_code'] == 400 && $xmlarray[
'content']) ?
' '.$xmlarray[
'content'] :
'').
' '.$xmlarray[
'curl_error_no'].
' '.$xmlarray[
'curl_error_msg'];
2960 throw new RestException(500, $errormsg);
2965 $checksumconcat = array();
2966 $file_list = array();
2970 if (is_object($xml->dolibarr_constants[0])) {
2973 $out .=
'<div class="div-table-responsive-no-min">';
2974 $out .=
'<table class="noborder">';
2975 $out .=
'<tr class="liste_titre">';
2976 $out .=
'<td>#</td>';
2977 $out .=
'<td>'.$langs->trans(
"Constant").
'</td>';
2978 $out .=
'<td class="center">'.$langs->trans(
"ExpectedValue").
'</td>';
2979 $out .=
'<td class="center">'.$langs->trans(
"Value").
'</td>';
2980 $out .=
'</tr>'.
"\n";
2983 foreach ($xml->dolibarr_constants[0]->constant as $constant) {
2984 $constname = $constant[
'name'];
2985 $constvalue = (
string) $constant;
2986 $constvalue = (empty($constvalue) ?
'0' : $constvalue);
2992 $valueforchecksum = (empty($value) ?
'0' : $value);
2994 $checksumconcat[] = $valueforchecksum;
2997 $out .=
'<tr class="oddeven">';
2998 $out .=
'<td>'.$i.
'</td>'.
"\n";
2999 $out .=
'<td>'.dol_escape_htmltag($constname).
'</td>'.
"\n";
3000 $out .=
'<td class="center">'.dol_escape_htmltag($constvalue).
'</td>'.
"\n";
3001 $out .=
'<td class="center">'.dol_escape_htmltag($valueforchecksum).
'</td>'.
"\n";
3006 $out .=
'<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
3015 if (is_object($xml->dolibarr_htdocs_dir[0])) {
3016 $includecustom = (empty($xml->dolibarr_htdocs_dir[0][
'includecustom']) ? 0 : $xml->dolibarr_htdocs_dir[0][
'includecustom']);
3019 $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)$';
3020 $regextoexclude =
'('.($includecustom ?
'' :
'custom|').
'documents|escpos-php\/doc|escpos-php\/example|escpos-php\/test|conf|install|dejavu-fonts-ttf-.*|public\/test|sabre\/sabre\/.*\/tests|Shared\/PCLZip|nusoap\/lib\/Mail|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$';
3021 $scanfiles =
dol_dir_list(DOL_DOCUMENT_ROOT,
'files', 1, $regextoinclude, $regextoexclude);
3024 $ret =
getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0],
'', DOL_DOCUMENT_ROOT, $checksumconcat);
3025 '@phan-var-force array{insignature:string[],missing?:array<array{filename:string,expectedmd5:string,expectedsize:string}>,updated:array<array{filename:string,expectedmd5:string,expectedsize:string,md5:string}>} $file_list';
3027 foreach ($scanfiles as $keyfile => $valfile) {
3028 $tmprelativefilename = preg_replace(
'/^'.preg_quote(DOL_DOCUMENT_ROOT,
'/').
'/',
'', $valfile[
'fullname']);
3029 if (!in_array($tmprelativefilename, $file_list[
'insignature'])) {
3030 $md5newfile = @md5_file($valfile[
'fullname']);
3031 $file_list[
'added'][] = array(
'filename' => $tmprelativefilename,
'md5' => $md5newfile);
3038 $out .=
'<div class="div-table-responsive-no-min">';
3039 $out .=
'<table class="noborder">';
3040 $out .=
'<tr class="liste_titre">';
3041 $out .=
'<td>#</td>';
3042 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
3043 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
3044 $out .=
'</tr>'.
"\n";
3045 $tmpfilelist =
dol_sort_array($file_list[
'missing'],
'filename');
3046 if (is_array($tmpfilelist) && count($tmpfilelist)) {
3048 foreach ($tmpfilelist as $file) {
3050 $out .=
'<tr class="oddeven">';
3051 $out .=
'<td>'.$i.
'</td>'.
"\n";
3052 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
3053 $out .=
'<td class="center">'.(array_key_exists(
'expectedmd5', $file) ? $file[
'expectedmd5'] :
'').
'</td>'.
"\n";
3057 $out .=
'<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
3068 $out .=
'<div class="div-table-responsive-no-min">';
3069 $out .=
'<table class="noborder">';
3070 $out .=
'<tr class="liste_titre">';
3071 $out .=
'<td>#</td>';
3072 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
3073 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
3074 $out .=
'<td class="center">'.$langs->trans(
"CurrentChecksum").
'</td>';
3075 $out .=
'<td class="right">'.$langs->trans(
"Size").
'</td>';
3076 $out .=
'<td class="right">'.$langs->trans(
"DateModification").
'</td>';
3077 $out .=
'</tr>'.
"\n";
3078 $tmpfilelist2 =
dol_sort_array($file_list[
'updated'],
'filename');
3079 if (is_array($tmpfilelist2) && count($tmpfilelist2)) {
3081 foreach ($tmpfilelist2 as $file) {
3083 $out .=
'<tr class="oddeven">';
3084 $out .=
'<td>'.$i.
'</td>'.
"\n";
3085 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
3086 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
3087 $out .=
'<td class="center">'.$file[
'md5'].
'</td>'.
"\n";
3088 $size =
dol_filesize(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']);
3089 $totalsize += $size;
3090 $out .=
'<td class="right">'.dol_print_size($size).
'</td>'.
"\n";
3091 $out .=
'<td class="right">'.dol_print_date(
dol_filemtime(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']),
'dayhour').
'</td>'.
"\n";
3094 $out .=
'<tr class="liste_total">';
3095 $out .=
'<td></td>'.
"\n";
3096 $out .=
'<td>'.$langs->trans(
"Total").
'</td>'.
"\n";
3097 $out .=
'<td align="center"></td>'.
"\n";
3098 $out .=
'<td align="center"></td>'.
"\n";
3099 $out .=
'<td class="right">'.dol_print_size($totalsize).
'</td>'.
"\n";
3100 $out .=
'<td class="right"></td>'.
"\n";
3103 $out .=
'<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
3114 $out .=
'<div class="div-table-responsive-no-min">';
3115 $out .=
'<table class="noborder">';
3116 $out .=
'<tr class="liste_titre">';
3117 $out .=
'<td>#</td>';
3118 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
3119 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
3120 $out .=
'<td class="center">'.$langs->trans(
"CurrentChecksum").
'</td>';
3121 $out .=
'<td class="right">'.$langs->trans(
"Size").
'</td>';
3122 $out .=
'<td class="right">'.$langs->trans(
"DateModification").
'</td>';
3123 $out .=
'</tr>'.
"\n";
3125 if (is_array($tmpfilelist3) && count($tmpfilelist3)) {
3127 foreach ($tmpfilelist3 as $file) {
3129 $out .=
'<tr class="oddeven">';
3130 $out .=
'<td>'.$i.
'</td>'.
"\n";
3131 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
3132 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
3133 $out .=
'<td class="center">'.$file[
'md5'].
'</td>'.
"\n";
3134 $size =
dol_filesize(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']);
3135 $totalsize += $size;
3136 $out .=
'<td class="right">'.dol_print_size($size).
'</td>'.
"\n";
3137 $out .=
'<td class="right">'.dol_print_date(
dol_filemtime(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']),
'dayhour').
'</td>'.
"\n";
3140 $out .=
'<tr class="liste_total">';
3141 $out .=
'<td></td>'.
"\n";
3142 $out .=
'<td>'.$langs->trans(
"Total").
'</td>'.
"\n";
3143 $out .=
'<td align="center"></td>'.
"\n";
3144 $out .=
'<td align="center"></td>'.
"\n";
3145 $out .=
'<td class="right">'.dol_print_size($totalsize).
'</td>'.
"\n";
3146 $out .=
'<td class="right"></td>'.
"\n";
3149 $out .=
'<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
3156 if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) {
3162 throw new RestException(500,
'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile);
3167 asort($checksumconcat);
3168 $checksumget = md5(implode(
',', $checksumconcat));
3169 $checksumtoget = trim((
string) $xml->dolibarr_htdocs_dir_checksum);
3171 $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans(
"Unknown"));
3172 if ($checksumget == $checksumtoget) {
3173 if (count($file_list[
'added'])) {
3174 $resultcode =
'warning';
3175 $resultcomment =
'FileIntegrityIsOkButFilesWereAdded';
3177 $outcurrentchecksum = $checksumget;
3180 $resultcomment =
'Success';
3182 $outcurrentchecksum = $checksumget;
3185 $resultcode =
'error';
3186 $resultcomment =
'Error';
3188 $outcurrentchecksum = $checksumget;
3191 throw new RestException(404,
'No signature file known');
3194 return array(
'resultcode' => $resultcode,
'resultcomment' => $resultcomment,
'expectedchecksum' => $outexpectedchecksum,
'currentchecksum' => $outcurrentchecksum,
'out' => $out);
3210 dol_syslog(
"Setup::getModules is DEPRECATED, use /api/index.php/setup/modules/status", LOG_INFO);
3213 if (!DolibarrApiAccess::$user->admin
3215 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');
3218 sort(
$conf->modules);
3220 return $conf->modules;
3239 if (!DolibarrApiAccess::$user->admin
3241 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');
3244 $filename = array();
3246 foreach ($modulesdir as $dir) {
3249 dol_syslog(
"Scan directory ".$dir.
" for module descriptor files (modXXX.class.php)");
3250 $handle = @opendir($dir);
3251 if (is_resource($handle)) {
3252 while (($file = readdir($handle)) !==
false) {
3254 if (is_readable($dir.$file) && substr($file, 0, 3) ==
'mod' && substr($file,
dol_strlen($file) - 10) ==
'.class.php') {
3255 $modName = substr($file, 0,
dol_strlen($file) - 10);
3256 include_once $dir.$file;
3257 if (class_exists($modName)) {
3258 $objMod =
new $modName(
$db);
3259 $moduleName = strtoupper(preg_replace(
'/^mod/i',
'', get_class($objMod)));
3261 $external = ((
string) $moduleObject->isCoreOrExternalModule() ==
'external');
3263 $version = $objMod->version;
3264 if ($status !=
'all') {
3265 if ($status ==
'active' && $active ==
"") {
3267 } elseif ($status ==
'disabled' && $active == 1) {
3271 if ($origin !=
'all') {
3272 if ($origin ==
'external' && !$external) {
3274 } elseif ($origin ==
'core' && $external) {
3279 $filename[$moduleName] = array(
3280 'modName' => $modName,
3281 'origin' => $external ?
'external' :
'core',
3282 'active' => $active,
3283 'publisher' => $publisher,
3284 'version' => $version
3307 return $this->
_moduleOnOff($modulename, $state =
true);
3322 return $this->
_moduleOnOff($modulename, $state =
false);
3339 if (!DolibarrApiAccess::$user->admin
3341 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');
3345 foreach ($modulesdir as $dir) {
3346 $handle = @opendir($dir);
3347 if (is_resource($handle)) {
3348 while (($file = readdir($handle)) !==
false) {
3349 if (is_readable($dir.$file) && substr($file, 0, 3) ==
'mod' && substr($file,
dol_strlen($file) - 10) ==
'.class.php') {
3351 if ($modulename == substr($file, 0,
dol_strlen($file) - 10)) {
3352 $modName = substr($file, 0,
dol_strlen($file) - 10);
3353 include_once $dir.$file;
3354 if (class_exists($modName)) {
3355 $objMod =
new $modName(
$db);
3358 activateModule($modulename, 1, 0);
3359 return array(
'result' =>
'success',
'message' =>
'Module '.$this->db->escape($modulename).
' activated');
3361 unActivateModule($modulename);
3362 return array(
'result' =>
'success',
'message' =>
'Module '.$this->db->escape($modulename).
' deactivated');
3370 throw new RestException(404,
'Module '.$this->db->escape($modulename).
' not found');
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
Class to manage dictionary Countries (used by imports)
Class to manage dictionary Countries (used by imports)
Class to manage dictionary Regions.
Class to manage dictionary States (used by imports)
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
Class to manage establishments.
getExtrafields($attrname, $elementtype)
get Extrafield object
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.
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 @phpstan-template T.
getListOfStaff($sortfield="id", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of staff.
getListOfCountries($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $filter='', $lang='', $sqlfilters='', $loadregions=0, $loadstates=0)
Get the list of countries.
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.
getCheckIntegrity($target)
Do a test of integrity for files and setup.
getListOfHolidayTypes($sortfield="sortorder", $sortorder='ASC', $limit=100, $page=0, $fk_country='', $active=1, $lang='', $sqlfilters='')
Get the list of holiday types.
getListOfExpenseReportsTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $module='', $active=1, $sqlfilters='')
Get the list of Expense Report types.
__construct()
Constructor.
getThirdpartiesTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of thirdparties types.
getModulesList($status="active", $origin='all')
Get list of modules with status and origin.
getListOfTowns($sortfield="zip,town", $sortorder='ASC', $limit=100, $page=0, $zipcode='', $town='', $active=1, $sqlfilters='')
Get the list of towns.
getCountryByID($id, $lang='', $loadregions=0, $loadstates=0)
Get country by ID.
getStateByCode($code)
Get state by Code.
getConfs()
Get all setup variables.
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.
getCountryByISO($iso, $lang='', $loadregions=0, $loadstates=0)
Get country by Iso.
getListOfPublicHolidays($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $fk_country='', $active=1, $lang='', $sqlfilters='')
Get the list of public holiday.
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.
updateExtrafields($attrname, $elementtype, $request_data=null)
Update Extrafield object.
deleteExtrafieldsFromNames($attrname, $elementtype)
Delete extrafield.
getListOfIncoterms($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of incoterms.
_fetchCcountry($id, $code='', $iso='', $lang='', $loadregions=0, $loadstates=0)
Get country.
getCompany()
Get properties of company.
_moduleOnOff($modulename, $state=false)
switch moduleOnOff
postExtrafields($attrname, $elementtype, $request_data=null)
Create Extrafield object.
getPaymentTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of payments types.
enableModules($modulename)
PUT enable module.
_fetchCregion($id, $code='')
Get region.
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.
getListOfActionTriggers($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $elementtype='', $lang='', $sqlfilters='')
Get the list of Action Triggers.
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.
disableModules($modulename)
PUT enable module.
getListOfExtrafields($sortfield="t.pos", $sortorder='ASC', $elementtype='', $sqlfilters='')
Get the list of extra fields.
getStateByID($id)
Get state by ID.
getCountryByCode($code, $lang='', $loadregions=0, $loadstates=0)
Get country by Code.
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.
getListOfVAT($sortfield="taux", $sortorder='ASC', $limit=100, $page=0, $active=1, $fk_country=-1, $sqlfilters='')
Get the list of vat.
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($utf8_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.
dolGetModulesDirs($subdir='')
Return list of directories that contain modules.
isASecretKey($keyname)
Return if string has a name dedicated to store a secret.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1, $timeoutconnect=0, $timeoutresponse=0, $otherCurlOptions=array(), $morelogsuffix='')
Function to get a content from an URL (use proxy if proxy defined).
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php