26use Luracast\Restler\RestException;
28require_once DOL_DOCUMENT_ROOT.
'/main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/api/class/api.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/cstate.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/cregion.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/ccountry.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/hrm/class/establishment.class.php';
46 private $translations =
null;
75 public function getListOfActionTriggers($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $elementtype =
'', $lang =
'', $sqlfilters =
'')
79 if ($elementtype ==
'thirdparty') {
80 $elementtype =
'societe';
82 if ($elementtype ==
'contact') {
83 $elementtype =
'socpeople';
86 $sql =
"SELECT t.rowid as id, t.elementtype, t.code, t.contexts, t.label, t.description, t.rang";
87 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_action_trigger as t";
89 if (!empty($elementtype)) {
90 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
97 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
101 $sql .= $this->db->order($sortfield, $sortorder);
107 $offset = $limit * $page;
109 $sql .= $this->db->plimit($limit, $offset);
112 $result = $this->db->query($sql);
114 $num = $this->db->num_rows($result);
115 $min = min($num, ($limit <= 0 ? $num : $limit));
116 for ($i = 0; $i < $min; $i++) {
117 $type = $this->db->fetch_object($result);
122 throw new RestException(503,
'Error when retrieving list of action triggers : '.$this->db->lasterror());
146 public function getOrderingMethods($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
150 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
151 throw new RestException(403);
154 $sql =
"SELECT rowid, code, libelle as label, module";
155 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_input_method as t";
156 $sql .=
" WHERE t.active = ".((int) $active);
162 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
167 $sql .= $this->db->order($sortfield, $sortorder);
173 $offset = $limit * $page;
175 $sql .= $this->db->plimit($limit, $offset);
178 $result = $this->db->query($sql);
181 $num = $this->db->num_rows($result);
182 $min = min($num, ($limit <= 0 ? $num : $limit));
183 for ($i = 0; $i < $min; $i++) {
184 $list[] = $this->db->fetch_object($result);
187 throw new RestException(503, $this->db->lasterror());
210 public function getOrderingOrigins($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
214 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
215 throw new RestException(403);
218 $sql =
"SELECT rowid, code, label, module";
219 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_input_reason as t";
220 $sql .=
" WHERE t.active = ".((int) $active);
226 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
231 $sql .= $this->db->order($sortfield, $sortorder);
237 $offset = $limit * $page;
239 $sql .= $this->db->plimit($limit, $offset);
242 $result = $this->db->query($sql);
245 $num = $this->db->num_rows($result);
246 $min = min($num, ($limit <= 0 ? $num : $limit));
247 for ($i = 0; $i < $min; $i++) {
248 $list[] = $this->db->fetch_object($result);
251 throw new RestException(503, $this->db->lasterror());
275 public function getPaymentTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
279 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire') && !DolibarrApiAccess::$user->hasRight(
'commande',
'lire') && !DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
280 throw new RestException(403);
283 $sql =
"SELECT id, code, type, libelle as label, module";
284 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_paiement as t";
285 $sql .=
" WHERE t.entity IN (".getEntity(
'c_paiement').
")";
286 $sql .=
" AND t.active = ".((int) $active);
292 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
297 $sql .= $this->db->order($sortfield, $sortorder);
303 $offset = $limit * $page;
305 $sql .= $this->db->plimit($limit, $offset);
308 $result = $this->db->query($sql);
311 $num = $this->db->num_rows($result);
312 $min = min($num, ($limit <= 0 ? $num : $limit));
313 for ($i = 0; $i < $min; $i++) {
314 $list[] = $this->db->fetch_object($result);
317 throw new RestException(503, $this->db->lasterror());
341 public function getListOfRegions($sortfield =
"code_region", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $filter =
'', $sqlfilters =
'')
347 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.
"c_regions as t";
348 $sql .=
" WHERE 1 = 1";
350 $sql .=
" AND t.fk_pays = ".((int) $country);
356 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
358 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
359 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
362 $sql .= $this->db->order($sortfield, $sortorder);
368 $offset = $limit * $page;
370 $sql .= $this->db->plimit($limit, $offset);
373 $result = $this->db->query($sql);
376 $num = $this->db->num_rows($result);
377 $min = min($num, ($limit <= 0 ? $num : $limit));
378 for ($i = 0; $i < $min; $i++) {
379 $obj = $this->db->fetch_object($result);
380 $region =
new Cregion($this->db);
381 if ($region->fetch($obj->rowid) > 0) {
382 if (empty($filter) || stripos($region->name, $filter) !==
false) {
388 throw new RestException(503,
'Error when retrieving list of regions');
448 public function getListOfStates($sortfield =
"code_departement", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $filter =
'', $sqlfilters =
'')
454 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.
"c_departements as t";
456 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as d ON t.fk_region = d.code_region";
458 $sql .=
" WHERE 1 = 1";
460 $sql .=
" AND d.fk_pays = ".((int) $country);
467 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
471 $sql .= $this->db->order($sortfield, $sortorder);
477 $offset = $limit * $page;
479 $sql .= $this->db->plimit($limit, $offset);
482 $result = $this->db->query($sql);
485 $num = $this->db->num_rows($result);
486 $min = min($num, ($limit <= 0 ? $num : $limit));
487 for ($i = 0; $i < $min; $i++) {
488 $obj = $this->db->fetch_object($result);
489 $state =
new Cstate($this->db);
490 if ($state->fetch($obj->rowid) > 0) {
491 if (empty($filter) || stripos($state->label, $filter) !==
false) {
497 throw new RestException(503,
'Error when retrieving list of states');
557 public function getListOfCountries($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $filter =
'', $lang =
'', $sqlfilters =
'')
563 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"c_country as t";
564 $sql .=
" WHERE 1 = 1";
570 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
574 $sql .= $this->db->order($sortfield, $sortorder);
580 $offset = $limit * $page;
582 $sql .= $this->db->plimit($limit, $offset);
585 $result = $this->db->query($sql);
588 $num = $this->db->num_rows($result);
589 $min = min($num, ($limit <= 0 ? $num : $limit));
590 for ($i = 0; $i < $min; $i++) {
591 $obj = $this->db->fetch_object($result);
593 if ($country->fetch($obj->rowid) > 0) {
598 if (empty($filter) || stripos($country->label, $filter) !==
false) {
604 throw new RestException(503,
'Error when retrieving list of countries');
672 $region =
new Cregion($this->db);
674 $result = $region->fetch(
$id, $code);
676 throw new RestException(503,
'Error when retrieving region : '.$region->error);
677 } elseif ($result == 0) {
678 throw new RestException(404,
'Region not found');
695 $state =
new Cstate($this->db);
697 $result = $state->fetch(
$id, $code);
699 throw new RestException(503,
'Error when retrieving state : '.$state->error);
700 } elseif ($result == 0) {
701 throw new RestException(404,
'State not found');
722 $result = $country->fetch(
$id, $code, $iso);
725 throw new RestException(503,
'Error when retrieving country : '.$country->error);
726 } elseif ($result == 0) {
727 throw new RestException(404,
'Country not found');
753 public function getAvailability($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
757 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
758 throw new RestException(403);
761 $sql =
"SELECT rowid, code, label";
762 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_availability as t";
763 $sql .=
" WHERE t.active = ".((int) $active);
769 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
774 $sql .= $this->db->order($sortfield, $sortorder);
780 $offset = $limit * $page;
782 $sql .= $this->db->plimit($limit, $offset);
785 $result = $this->db->query($sql);
788 $num = $this->db->num_rows($result);
789 $min = min($num, ($limit <= 0 ? $num : $limit));
790 for ($i = 0; $i < $min; $i++) {
791 $list[] = $this->db->fetch_object($result);
794 throw new RestException(503, $this->db->lasterror());
831 if ($this->translations ==
null || $this->translations->getDefaultLang() !== $lang) {
834 $this->translations->setDefaultLang($lang);
835 $this->translations->loadLangs($dict);
838 $key = $prefix.$object->code;
840 $translation = $this->translations->trans($key);
841 if ($translation != $key) {
842 $object->label = html_entity_decode($translation);
866 public function getListOfEventTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $type =
'', $module =
'', $active = 1, $sqlfilters =
'')
870 $sql =
"SELECT id, code, type, libelle as label, module";
871 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_actioncomm as t";
872 $sql .=
" WHERE t.active = ".((int) $active);
874 $sql .=
" AND t.type LIKE '%".$this->db->escape($type).
"%'";
877 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
884 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
889 $sql .= $this->db->order($sortfield, $sortorder);
895 $offset = $limit * $page;
897 $sql .= $this->db->plimit($limit, $offset);
900 $result = $this->db->query($sql);
903 $num = $this->db->num_rows($result);
904 $min = min($num, ($limit <= 0 ? $num : $limit));
905 for ($i = 0; $i < $min; $i++) {
906 $list[] = $this->db->fetch_object($result);
909 throw new RestException(503,
'Error when retrieving list of events types : '.$this->db->lasterror());
933 public function getListOfExpenseReportsTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $module =
'', $active = 1, $sqlfilters =
'')
937 $sql =
"SELECT id, code, label, accountancy_code, active, module, position";
938 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees as t";
939 $sql .=
" WHERE t.active = ".((int) $active);
941 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
948 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
953 $sql .= $this->db->order($sortfield, $sortorder);
959 $offset = $limit * $page;
961 $sql .= $this->db->plimit($limit, $offset);
964 $result = $this->db->query($sql);
967 $num = $this->db->num_rows($result);
968 $min = min($num, ($limit <= 0 ? $num : $limit));
969 for ($i = 0; $i < $min; $i++) {
970 $list[] = $this->db->fetch_object($result);
973 throw new RestException(503,
'Error when retrieving list of expense report types : '.$this->db->lasterror());
999 public function getListOfContactTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $type =
'', $module =
'', $active = 1, $lang =
'', $sqlfilters =
'')
1003 $sql =
"SELECT rowid, code, element as type, libelle as label, source, module, position";
1004 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact as t";
1005 $sql .=
" WHERE t.active = ".((int) $active);
1007 $sql .=
" AND type LIKE '%".$this->db->escape($type).
"%'";
1010 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
1016 if ($errormessage) {
1017 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1022 $sql .= $this->db->order($sortfield, $sortorder);
1028 $offset = $limit * $page;
1030 $sql .= $this->db->plimit($limit, $offset);
1033 $result = $this->db->query($sql);
1036 $num = $this->db->num_rows($result);
1037 $min = min($num, ($limit <= 0 ? $num : $limit));
1038 for ($i = 0; $i < $min; $i++) {
1039 $contact_type = $this->db->fetch_object($result);
1040 $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"));
1041 $list[] = $contact_type;
1044 throw new RestException(503,
'Error when retrieving list of contacts types : '.$this->db->lasterror());
1068 public function getListOfCivilities($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $module =
'', $active = 1, $lang =
'', $sqlfilters =
'')
1072 $sql =
"SELECT rowid, code, label, module";
1073 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_civility as t";
1074 $sql .=
" WHERE t.active = ".((int) $active);
1076 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
1082 if ($errormessage) {
1083 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1088 $sql .= $this->db->order($sortfield, $sortorder);
1094 $offset = $limit * $page;
1096 $sql .= $this->db->plimit($limit, $offset);
1099 $result = $this->db->query($sql);
1102 $num = $this->db->num_rows($result);
1103 $min = min($num, ($limit <= 0 ? $num : $limit));
1104 for ($i = 0; $i < $min; $i++) {
1105 $civility = $this->db->fetch_object($result);
1106 $this->
translateLabel($civility, $lang,
'Civility', array(
'dict'));
1107 $list[] = $civility;
1110 throw new RestException(503,
'Error when retrieving list of civility : '.$this->db->lasterror());
1133 public function getListOfCurrencies($multicurrency = 0, $sortfield =
"code_iso", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1136 $sql =
"SELECT t.code_iso, t.label, t.unicode";
1137 if (!empty($multicurrency)) {
1138 $sql .=
" , cr.date_sync, cr.rate ";
1140 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_currencies as t";
1141 if (!empty($multicurrency)) {
1142 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"multicurrency as m ON m.code=t.code_iso";
1143 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"multicurrency_rate as cr ON (m.rowid = cr.fk_multicurrency)";
1145 $sql .=
" WHERE t.active = ".((int) $active);
1146 if (!empty($multicurrency)) {
1147 $sql .=
" AND m.entity IN (".getEntity(
'multicurrency').
")";
1148 if (!empty($multicurrency) && $multicurrency != 2) {
1149 $sql .=
" AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM ".MAIN_DB_PREFIX.
"multicurrency_rate AS cr2 WHERE cr2.fk_multicurrency = m.rowid)";
1157 if ($errormessage) {
1158 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1163 $sql .= $this->db->order($sortfield, $sortorder);
1169 $offset = $limit * $page;
1171 $sql .= $this->db->plimit($limit, $offset);
1174 $result = $this->db->query($sql);
1177 $num = $this->db->num_rows($result);
1178 $min = min($num, ($limit <= 0 ? $num : $limit));
1179 for ($i = 0; $i < $min; $i++) {
1180 $list[] = $this->db->fetch_object($result);
1183 throw new RestException(503,
'Error when retrieving list of currency : '.$this->db->lasterror());
1203 public function getListOfExtrafields($sortfield =
"t.pos", $sortorder =
'ASC', $elementtype =
'', $sqlfilters =
'')
1207 if (!DolibarrApiAccess::$user->admin
1209 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');
1212 if ($elementtype ==
'thirdparty') {
1213 $elementtype =
'societe';
1215 if ($elementtype ==
'contact') {
1216 $elementtype =
'socpeople';
1219 $sql =
"SELECT t.rowid as id, t.name, t.entity, t.elementtype, t.label, t.type, t.size, t.fieldcomputed, t.fielddefault,";
1220 $sql .=
" t.fieldunique, t.fieldrequired, t.perms, t.enabled, t.pos, t.alwayseditable, t.param, t.list, t.printable,";
1221 $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";
1222 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1223 $sql .=
" WHERE t.entity IN (".getEntity(
'extrafields').
")";
1224 if (!empty($elementtype)) {
1225 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
1231 if ($errormessage) {
1232 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1236 $sql .= $this->db->order($sortfield, $sortorder);
1238 $resql = $this->db->query($sql);
1240 if ($this->db->num_rows($resql)) {
1241 while ($tab = $this->db->fetch_object($resql)) {
1243 $list[$tab->elementtype][$tab->name][
'id'] = $tab->id;
1244 $list[$tab->elementtype][$tab->name][
'type'] = $tab->type;
1245 $list[$tab->elementtype][$tab->name][
'label'] = $tab->label;
1246 $list[$tab->elementtype][$tab->name][
'size'] = $tab->size;
1247 $list[$tab->elementtype][$tab->name][
'elementtype'] = $tab->elementtype;
1248 $list[$tab->elementtype][$tab->name][
'default'] = $tab->fielddefault;
1249 $list[$tab->elementtype][$tab->name][
'computed'] = $tab->fieldcomputed;
1250 $list[$tab->elementtype][$tab->name][
'unique'] = $tab->fieldunique;
1251 $list[$tab->elementtype][$tab->name][
'required'] = $tab->fieldrequired;
1252 $list[$tab->elementtype][$tab->name][
'param'] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1253 $list[$tab->elementtype][$tab->name][
'pos'] = $tab->pos;
1254 $list[$tab->elementtype][$tab->name][
'alwayseditable'] = $tab->alwayseditable;
1255 $list[$tab->elementtype][$tab->name][
'perms'] = $tab->perms;
1256 $list[$tab->elementtype][$tab->name][
'list'] = $tab->list;
1257 $list[$tab->elementtype][$tab->name][
'printable'] = $tab->printable;
1258 $list[$tab->elementtype][$tab->name][
'totalizable'] = $tab->totalizable;
1259 $list[$tab->elementtype][$tab->name][
'langs'] = $tab->langs;
1260 $list[$tab->elementtype][$tab->name][
'help'] = $tab->help;
1261 $list[$tab->elementtype][$tab->name][
'css'] = $tab->css;
1262 $list[$tab->elementtype][$tab->name][
'cssview'] = $tab->cssview;
1263 $list[$tab->elementtype][$tab->name][
'csslist'] = $tab->csslist;
1264 $list[$tab->elementtype][$tab->name][
'fk_user_author'] = $tab->fk_user_author;
1265 $list[$tab->elementtype][$tab->name][
'fk_user_modif'] = $tab->fk_user_modif;
1266 $list[$tab->elementtype][$tab->name][
'datec'] = $tab->datec;
1267 $list[$tab->elementtype][$tab->name][
'tms'] = $tab->tms;
1271 throw new RestException(503,
'Error when retrieving list of extra fields : '.$this->db->lasterror());
1289 if (!DolibarrApiAccess::$user->admin) {
1290 throw new RestException(403,
'Only an admin user can delete an extrafield by attrname and elementtype');
1295 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1297 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1300 if (!$extrafields->delete($attrname, $elementtype)) {
1301 throw new RestException(500,
'Error when delete extrafield : '.$extrafields->error);
1307 'message' =>
'Extrafield deleted from attrname and elementtype'
1329 if (!DolibarrApiAccess::$user->admin) {
1330 throw new RestException(403,
'Only an admin user can get list of extrafields');
1333 if ($elementtype ==
'thirdparty') {
1334 $elementtype =
'societe';
1336 if ($elementtype ==
'contact') {
1337 $elementtype =
'socpeople';
1340 $sql =
"SELECT t.rowid as id, t.name, t.entity, t.elementtype, t.label, t.type, t.size, t.fieldcomputed, t.fielddefault,";
1341 $sql .=
" t.fieldunique, t.fieldrequired, t.perms, t.enabled, t.pos, t.alwayseditable, t.param, t.list, t.printable,";
1342 $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";
1343 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1344 $sql .=
" WHERE t.entity IN (".getEntity(
'extrafields').
")";
1345 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
1346 $sql .=
" AND t.name = '".$this->db->escape($attrname).
"'";
1348 $resql = $this->db->query($sql);
1350 if ($this->db->num_rows($resql)) {
1351 while ($tab = $this->db->fetch_object($resql)) {
1353 $answer[$tab->elementtype][$tab->name][
'id'] = $tab->id;
1354 $answer[$tab->elementtype][$tab->name][
'type'] = $tab->type;
1355 $answer[$tab->elementtype][$tab->name][
'label'] = $tab->label;
1356 $answer[$tab->elementtype][$tab->name][
'size'] = $tab->size;
1357 $answer[$tab->elementtype][$tab->name][
'elementtype'] = $tab->elementtype;
1358 $answer[$tab->elementtype][$tab->name][
'default'] = $tab->fielddefault;
1359 $answer[$tab->elementtype][$tab->name][
'computed'] = $tab->fieldcomputed;
1360 $answer[$tab->elementtype][$tab->name][
'unique'] = $tab->fieldunique;
1361 $answer[$tab->elementtype][$tab->name][
'required'] = $tab->fieldrequired;
1362 $answer[$tab->elementtype][$tab->name][
'param'] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1363 $answer[$tab->elementtype][$tab->name][
'pos'] = $tab->pos;
1364 $answer[$tab->elementtype][$tab->name][
'alwayseditable'] = $tab->alwayseditable;
1365 $answer[$tab->elementtype][$tab->name][
'perms'] = $tab->perms;
1366 $answer[$tab->elementtype][$tab->name][
'list'] = $tab->list;
1367 $answer[$tab->elementtype][$tab->name][
'printable'] = $tab->printable;
1368 $answer[$tab->elementtype][$tab->name][
'totalizable'] = $tab->totalizable;
1369 $answer[$tab->elementtype][$tab->name][
'langs'] = $tab->langs;
1370 $answer[$tab->elementtype][$tab->name][
'help'] = $tab->help;
1371 $answer[$tab->elementtype][$tab->name][
'css'] = $tab->css;
1372 $answer[$tab->elementtype][$tab->name][
'cssview'] = $tab->cssview;
1373 $answer[$tab->elementtype][$tab->name][
'csslist'] = $tab->csslist;
1374 $answer[$tab->elementtype][$tab->name][
'fk_user_author'] = $tab->fk_user_author;
1375 $answer[$tab->elementtype][$tab->name][
'fk_user_modif'] = $tab->fk_user_modif;
1376 $answer[$tab->elementtype][$tab->name][
'datec'] = $tab->datec;
1377 $answer[$tab->elementtype][$tab->name][
'tms'] = $tab->tms;
1380 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1383 throw new RestException(503,
'Error when retrieving list of extra fields : '.$this->db->lasterror());
1404 if (!DolibarrApiAccess::$user->admin) {
1405 throw new RestException(403,
'Only an admin user can create an extrafield');
1410 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1412 throw new RestException(409,
'Duplicate extrafield already found from attrname and elementtype');
1418 foreach ($request_data as $field => $value) {
1419 $extrafields->$field = $this->
_checkValForAPI($field, $value, $extrafields);
1422 $entity = DolibarrApiAccess::$user->entity;
1423 if (empty($entity)) {
1430 if ($request_data[
'label']) {
1431 $label = $request_data[
'label'];
1433 throw new RestException(400,
"label field absent in json at root level");
1436 $alwayseditable = $request_data[
'alwayseditable'];
1437 $default_value = $request_data[
'default_value'];
1438 $totalizable = $request_data[
'totalizable'];
1439 $printable = $request_data[
'printable'];
1440 $required = $request_data[
'required'];
1441 $langfile = $request_data[
'langfile'];
1442 $computed = $request_data[
'computed'];
1443 $unique = $request_data[
'unique'];
1444 $param = $request_data[
'param'];
1445 $perms = $request_data[
'perms'];
1446 $size = $request_data[
'size'];
1447 $type = $request_data[
'type'];
1448 $list = $request_data[
'list'];
1449 $help = $request_data[
'help'];
1450 $pos = $request_data[
'pos'];
1451 $moreparams = array();
1453 if (0 > $extrafields->addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $default_value, $param, $alwayseditable, $perms, $list, $help, $computed, $entity, $langfile, $enabled, $totalizable, $printable, $moreparams)) {
1454 throw new RestException(500,
'Error creating extrafield', array_merge(array($extrafields->errno), $extrafields->errors));
1457 $sql =
"SELECT t.rowid as id";
1458 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1459 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1460 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1462 $resql = $this->db->query($sql);
1464 if ($this->db->num_rows($resql)) {
1465 $tab = $this->db->fetch_object($resql);
1466 $id = (int) $tab->id;
1493 if (!DolibarrApiAccess::$user->admin) {
1494 throw new RestException(403,
'Only an admin user can create an extrafield');
1499 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1501 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1504 foreach ($request_data as $field => $value) {
1505 $extrafields->$field = $this->
_checkValForAPI($field, $value, $extrafields);
1508 $entity = DolibarrApiAccess::$user->entity;
1509 if (empty($entity)) {
1515 if ($request_data[
'label']) {
1516 $label = $request_data[
'label'];
1518 throw new RestException(400,
"label field absent in json at root level");
1521 $alwayseditable = $request_data[
'alwayseditable'];
1522 $default_value = $request_data[
'default_value'];
1523 $totalizable = $request_data[
'totalizable'];
1524 $printable = $request_data[
'printable'];
1525 $required = $request_data[
'required'];
1526 $langfile = $request_data[
'langfile'];
1527 $computed = $request_data[
'computed'];
1528 $unique = $request_data[
'unique'];
1529 $param = $request_data[
'param'];
1530 $perms = $request_data[
'perms'];
1531 $size = $request_data[
'size'];
1532 $type = $request_data[
'type'];
1533 $list = $request_data[
'list'];
1534 $help = $request_data[
'help'];
1535 $pos = $request_data[
'pos'];
1536 $moreparams = array();
1538 dol_syslog(get_class($this).
'::updateExtraField', LOG_DEBUG);
1539 if (0 > $extrafields->updateExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $default_value, $param, $alwayseditable, $perms, $list, $help, $computed, $entity, $langfile, $enabled, $totalizable, $printable, $moreparams)) {
1540 throw new RestException(500,
'Error updating extrafield', array_merge(array($extrafields->errno), $extrafields->errors));
1543 $sql =
"SELECT t.rowid as id";
1544 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1545 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1546 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1548 $resql = $this->db->query($sql);
1550 if ($this->db->num_rows($resql)) {
1551 $tab = $this->db->fetch_object($resql);
1552 $id = (int) $tab->id;
1581 public function getListOfTowns($sortfield =
"zip,town", $sortorder =
'ASC', $limit = 100, $page = 0, $zipcode =
'', $town =
'', $active = 1, $sqlfilters =
'')
1585 $sql =
"SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
1586 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ziptown as t";
1587 $sql .=
" WHERE t.active = ".((int) $active);
1589 $sql .=
" AND t.zip LIKE '%".$this->db->escape($zipcode).
"%'";
1592 $sql .=
" AND t.town LIKE '%".$this->db->escape($town).
"%'";
1598 if ($errormessage) {
1599 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1604 $sql .= $this->db->order($sortfield, $sortorder);
1610 $offset = $limit * $page;
1612 $sql .= $this->db->plimit($limit, $offset);
1615 $result = $this->db->query($sql);
1618 $num = $this->db->num_rows($result);
1619 $min = min($num, ($limit <= 0 ? $num : $limit));
1620 for ($i = 0; $i < $min; $i++) {
1621 $list[] = $this->db->fetch_object($result);
1624 throw new RestException(503,
'Error when retrieving list of towns : '.$this->db->lasterror());
1648 public function getPaymentTerms($sortfield =
"sortorder", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1652 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire') && !DolibarrApiAccess::$user->hasRight(
'commande',
'lire') && !DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1653 throw new RestException(403);
1656 $sql =
"SELECT rowid as id, code, sortorder, libelle as label, libelle_facture as descr, type_cdr, nbjour, decalage, module";
1657 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_payment_term as t";
1658 $sql .=
" WHERE t.entity IN (".getEntity(
'c_payment_term').
")";
1659 $sql .=
" AND t.active = ".((int) $active);
1664 if ($errormessage) {
1665 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1670 $sql .= $this->db->order($sortfield, $sortorder);
1676 $offset = $limit * $page;
1678 $sql .= $this->db->plimit($limit, $offset);
1681 $result = $this->db->query($sql);
1684 $num = $this->db->num_rows($result);
1685 $min = min($num, ($limit <= 0 ? $num : $limit));
1686 for ($i = 0; $i < $min; $i++) {
1687 $list[] = $this->db->fetch_object($result);
1690 throw new RestException(503, $this->db->lasterror());
1712 public function getShippingModes($limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
1716 $sql =
"SELECT rowid as id, code, libelle as label, description, tracking, module";
1717 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as t";
1718 $sql .=
" WHERE t.entity IN (".getEntity(
'c_shipment_mode').
")";
1719 $sql .=
" AND t.active = ".((int) $active);
1724 if ($errormessage) {
1725 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1736 $offset = $limit * $page;
1738 $sql .= $this->db->plimit($limit, $offset);
1741 $result = $this->db->query($sql);
1744 $num = $this->db->num_rows($result);
1745 $min = min($num, ($limit <= 0 ? $num : $limit));
1746 for ($i = 0; $i < $min; $i++) {
1747 $method = $this->db->fetch_object($result);
1752 throw new RestException(503, $this->db->lasterror());
1774 public function getListOfMeasuringUnits($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1778 $sql =
"SELECT t.rowid, t.code, t.label,t.short_label, t.active, t.scale, t.unit_type";
1779 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_units as t";
1780 $sql .=
" WHERE t.active = ".((int) $active);
1785 if ($errormessage) {
1786 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1791 $sql .= $this->db->order($sortfield, $sortorder);
1797 $offset = $limit * $page;
1799 $sql .= $this->db->plimit($limit, $offset);
1802 $result = $this->db->query($sql);
1805 $num = $this->db->num_rows($result);
1806 $min = min($num, ($limit <= 0 ? $num : $limit));
1807 for ($i = 0; $i < $min; $i++) {
1808 $list[] = $this->db->fetch_object($result);
1811 throw new RestException(503,
'Error when retrieving list of measuring units: '.$this->db->lasterror());
1834 public function getListOfLegalForm($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $active = 1, $sqlfilters =
'')
1838 $sql =
"SELECT t.rowid, t.code, t.fk_pays, t.libelle, t.isvatexempted, t.active, t.module, t.position";
1839 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_forme_juridique as t";
1840 $sql .=
" WHERE t.active = ".((int) $active);
1842 $sql .=
" AND t.fk_pays = ".((int) $country);
1848 if ($errormessage) {
1849 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1854 $sql .= $this->db->order($sortfield, $sortorder);
1860 $offset = $limit * $page;
1862 $sql .= $this->db->plimit($limit, $offset);
1865 $result = $this->db->query($sql);
1868 $num = $this->db->num_rows($result);
1869 $min = min($num, ($limit <= 0 ? $num : $limit));
1870 for ($i = 0; $i < $min; $i++) {
1871 $list[] = $this->db->fetch_object($result);
1874 throw new RestException(503,
'Error when retrieving list of legal form: '.$this->db->lasterror());
1896 public function getListOfStaff($sortfield =
"id", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1900 $sql =
"SELECT t.id, t.code, t.libelle, t.active, t.module";
1901 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_effectif as t";
1902 $sql .=
" WHERE t.active = ".((int) $active);
1907 if ($errormessage) {
1908 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1913 $sql .= $this->db->order($sortfield, $sortorder);
1919 $offset = $limit * $page;
1921 $sql .= $this->db->plimit($limit, $offset);
1924 $result = $this->db->query($sql);
1927 $num = $this->db->num_rows($result);
1928 $min = min($num, ($limit <= 0 ? $num : $limit));
1929 for ($i = 0; $i < $min; $i++) {
1930 $list[] = $this->db->fetch_object($result);
1933 throw new RestException(503,
'Error when retrieving list of staff: '.$this->db->lasterror());
1955 public function getListOfsocialNetworks($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1959 if (!isModEnabled(
'socialnetworks')) {
1960 throw new RestException(400,
'API not available: this dictionary is not enabled by setup');
1965 $sql =
"SELECT t.rowid, t.entity, t.code, t.label, t.url, t.icon, t.active";
1966 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_socialnetworks as t";
1967 $sql .=
" WHERE t.entity IN (".getEntity(
'c_socialnetworks').
")";
1968 $sql .=
" AND t.active = ".((int) $active);
1973 if ($errormessage) {
1974 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1979 $sql .= $this->db->order($sortfield, $sortorder);
1985 $offset = $limit * $page;
1987 $sql .= $this->db->plimit($limit, $offset);
1990 $result = $this->db->query($sql);
1993 $num = $this->db->num_rows($result);
1994 $min = min($num, ($limit <= 0 ? $num : $limit));
1995 for ($i = 0; $i < $min; $i++) {
1996 $list[] = $this->db->fetch_object($result);
1999 throw new RestException(503,
'Error when retrieving list of social networks: '.$this->db->lasterror());
2022 public function getTicketsCategories($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2026 $sql =
"SELECT rowid, code, pos, label, use_default, description";
2027 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_category as t";
2028 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_category').
")";
2029 $sql .=
" AND t.active = ".((int) $active);
2034 if ($errormessage) {
2035 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2040 $sql .= $this->db->order($sortfield, $sortorder);
2046 $offset = $limit * $page;
2048 $sql .= $this->db->plimit($limit, $offset);
2051 $result = $this->db->query($sql);
2054 $num = $this->db->num_rows($result);
2055 $min = min($num, ($limit <= 0 ? $num : $limit));
2056 for ($i = 0; $i < $min; $i++) {
2057 $category = $this->db->fetch_object($result);
2058 $this->
translateLabel($category, $lang,
'TicketCategoryShort', array(
'ticket'));
2059 $list[] = $category;
2062 throw new RestException(503,
'Error when retrieving list of ticket categories : '.$this->db->lasterror());
2085 public function getTicketsSeverities($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2089 $sql =
"SELECT rowid, code, pos, label, use_default, color, description";
2090 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_severity as t";
2091 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_severity').
")";
2092 $sql .=
" AND t.active = ".((int) $active);
2097 if ($errormessage) {
2098 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2103 $sql .= $this->db->order($sortfield, $sortorder);
2109 $offset = $limit * $page;
2111 $sql .= $this->db->plimit($limit, $offset);
2114 $result = $this->db->query($sql);
2117 $num = $this->db->num_rows($result);
2118 $min = min($num, ($limit <= 0 ? $num : $limit));
2119 for ($i = 0; $i < $min; $i++) {
2120 $severity = $this->db->fetch_object($result);
2121 $this->
translateLabel($severity, $lang,
'TicketSeverityShort', array(
'ticket'));
2122 $list[] = $severity;
2125 throw new RestException(503,
'Error when retrieving list of ticket severities : '.$this->db->lasterror());
2148 public function getTicketsTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2152 $sql =
"SELECT rowid, code, pos, label, use_default, description";
2153 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_type as t";
2154 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_type').
")";
2155 $sql .=
" AND t.active = ".((int) $active);
2161 if ($errormessage) {
2162 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2167 $sql .= $this->db->order($sortfield, $sortorder);
2173 $offset = $limit * $page;
2175 $sql .= $this->db->plimit($limit, $offset);
2178 $result = $this->db->query($sql);
2181 $num = $this->db->num_rows($result);
2182 $min = min($num, ($limit <= 0 ? $num : $limit));
2183 for ($i = 0; $i < $min; $i++) {
2184 $type = $this->db->fetch_object($result);
2185 $this->
translateLabel($type, $lang,
'TicketTypeShort', array(
'ticket'));
2189 throw new RestException(503,
'Error when retrieving list of ticket types : '.$this->db->lasterror());
2211 public function getListOfIncoterms($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2215 $sql =
"SELECT rowid, code, active";
2216 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_incoterms as t";
2217 $sql .=
" WHERE 1=1";
2223 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2225 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
2226 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
2230 $sql .= $this->db->order($sortfield, $sortorder);
2236 $offset = $limit * $page;
2238 $sql .= $this->db->plimit($limit, $offset);
2241 $result = $this->db->query($sql);
2244 $num = $this->db->num_rows($result);
2245 $min = min($num, ($limit <= 0 ? $num : $limit));
2246 for ($i = 0; $i < $min; $i++) {
2247 $type = $this->db->fetch_object($result);
2251 throw new RestException(503,
'Error when retrieving list of incoterm types : '.$this->db->lasterror());
2268 global
$conf, $mysoc;
2270 if (!DolibarrApiAccess::$user->admin
2272 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');
2275 unset($mysoc->pays);
2276 unset($mysoc->note);
2279 unset($mysoc->lines);
2281 unset($mysoc->effectif);
2282 unset($mysoc->effectif_id);
2283 unset($mysoc->forme_juridique_code);
2284 unset($mysoc->forme_juridique);
2285 unset($mysoc->mode_reglement_supplier_id);
2286 unset($mysoc->cond_reglement_supplier_id);
2287 unset($mysoc->transport_mode_supplier_id);
2288 unset($mysoc->fk_prospectlevel);
2290 unset($mysoc->total_ht);
2291 unset($mysoc->total_tva);
2292 unset($mysoc->total_localtax1);
2293 unset($mysoc->total_localtax2);
2294 unset($mysoc->total_ttc);
2296 unset($mysoc->lastname);
2297 unset($mysoc->firstname);
2298 unset($mysoc->civility_id);
2300 unset($mysoc->client);
2301 unset($mysoc->prospect);
2302 unset($mysoc->fournisseur);
2303 unset($mysoc->contact_id);
2305 unset($mysoc->fk_incoterms);
2306 unset($mysoc->label_incoterms);
2307 unset($mysoc->location_incoterms);
2327 $sql =
"SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
2328 $sql .=
" FROM ".MAIN_DB_PREFIX.
"establishment as e";
2329 $sql .=
" WHERE e.entity IN (".getEntity(
'establishment').
')';
2334 $result = $this->db->query($sql);
2337 $num = $this->db->num_rows($result);
2338 $min = min($num, ($limit <= 0 ? $num : $limit));
2339 for ($i = 0; $i < $min; $i++) {
2340 $list[] = $this->db->fetch_object($result);
2343 throw new RestException(503,
'Error when retrieving list of establishments : '.$this->db->lasterror());
2364 $result = $establishment->fetch(
$id);
2366 throw new RestException(503,
'Error when retrieving establishment : '.$establishment->error);
2367 } elseif ($result == 0) {
2368 throw new RestException(404,
'Establishment not found');
2391 if (!DolibarrApiAccess::$user->admin
2393 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');
2396 if (!preg_match(
'/^[a-zA-Z0-9_]+$/', $constantname) || !isset(
$conf->global->$constantname)) {
2397 throw new RestException(400,
'Error Bad or unknown value for constantname');
2400 throw new RestException(403,
'Forbidden. This parameter can not be read with APIs');
2420 global $langs,
$conf;
2422 if (!DolibarrApiAccess::$user->admin
2424 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');
2427 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2428 require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
2430 $langs->load(
"admin");
2432 $outexpectedchecksum =
'';
2433 $outcurrentchecksum =
'';
2436 $file_list = array(
'missing' => array(),
'updated' => array());
2441 $xmlfile = DOL_DOCUMENT_ROOT.
'/install/'.$xmlshortfile;
2442 if (!preg_match(
'/\.zip$/i', $xmlfile) &&
dol_is_file($xmlfile.
'.zip')) {
2447 $xmlremote = (($target ==
'default' || $target ==
'local') ?
'' : $target);
2451 $param =
'MAIN_FILECHECK_URL_'.DOL_VERSION;
2455 if (empty($xmlremote)) {
2456 $xmlremote =
'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.
'.xml';
2458 if ($xmlremote && !preg_match(
'/^https?:\/\//i', $xmlremote)) {
2459 $langs->load(
"errors");
2460 throw new RestException(500, $langs->trans(
"ErrorURLMustStartWithHttp", $xmlremote));
2462 if ($xmlremote && !preg_match(
'/\.xml$/', $xmlremote)) {
2463 $langs->load(
"errors");
2464 throw new RestException(500, $langs->trans(
"ErrorURLMustEndWith", $xmlremote,
'.xml'));
2467 if (LIBXML_VERSION < 20900) {
2471 libxml_disable_entity_loader(
true);
2474 if ($target ==
'local') {
2476 $xml = simplexml_load_file($xmlfile);
2478 throw new RestException(500, $langs->trans(
'XmlNotFound').
': /install/'.$xmlshortfile);
2481 $xmlarray =
getURLContent($xmlremote,
'GET',
'', 1, array(), array(
'http',
'https'), 0);
2484 if (!$xmlarray[
'curl_error_no'] && $xmlarray[
'http_code'] !=
'400' && $xmlarray[
'http_code'] !=
'404') {
2485 $xmlfile = $xmlarray[
'content'];
2487 $xml = simplexml_load_string($xmlfile,
'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NONET);
2489 $errormsg = $langs->trans(
'XmlNotFound').
': '.$xmlremote.
' - '.$xmlarray[
'http_code'].(($xmlarray[
'http_code'] == 400 && $xmlarray[
'content']) ?
' '.$xmlarray[
'content'] :
'').
' '.$xmlarray[
'curl_error_no'].
' '.$xmlarray[
'curl_error_msg'];
2490 throw new RestException(500, $errormsg);
2495 $checksumconcat = array();
2496 $file_list = array();
2500 if (is_object($xml->dolibarr_constants[0])) {
2503 $out .=
'<div class="div-table-responsive-no-min">';
2504 $out .=
'<table class="noborder">';
2505 $out .=
'<tr class="liste_titre">';
2506 $out .=
'<td>#</td>';
2507 $out .=
'<td>'.$langs->trans(
"Constant").
'</td>';
2508 $out .=
'<td class="center">'.$langs->trans(
"ExpectedValue").
'</td>';
2509 $out .=
'<td class="center">'.$langs->trans(
"Value").
'</td>';
2510 $out .=
'</tr>'.
"\n";
2513 foreach ($xml->dolibarr_constants[0]->constant as $constant) {
2514 $constname = $constant[
'name'];
2515 $constvalue = (string) $constant;
2516 $constvalue = (empty($constvalue) ?
'0' : $constvalue);
2522 $valueforchecksum = (empty($value) ?
'0' : $value);
2524 $checksumconcat[] = $valueforchecksum;
2527 $out .=
'<tr class="oddeven">';
2528 $out .=
'<td>'.$i.
'</td>'.
"\n";
2529 $out .=
'<td>'.dol_escape_htmltag($constname).
'</td>'.
"\n";
2530 $out .=
'<td class="center">'.dol_escape_htmltag($constvalue).
'</td>'.
"\n";
2531 $out .=
'<td class="center">'.dol_escape_htmltag($valueforchecksum).
'</td>'.
"\n";
2536 $out .=
'<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2545 if (is_object($xml->dolibarr_htdocs_dir[0])) {
2546 $includecustom = (empty($xml->dolibarr_htdocs_dir[0][
'includecustom']) ? 0 : $xml->dolibarr_htdocs_dir[0][
'includecustom']);
2549 $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)$';
2550 $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)$';
2551 $scanfiles =
dol_dir_list(DOL_DOCUMENT_ROOT,
'files', 1, $regextoinclude, $regextoexclude);
2554 $ret =
getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0],
'', DOL_DOCUMENT_ROOT, $checksumconcat);
2555 '@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';
2557 foreach ($scanfiles as $keyfile => $valfile) {
2558 $tmprelativefilename = preg_replace(
'/^'.preg_quote(DOL_DOCUMENT_ROOT,
'/').
'/',
'', $valfile[
'fullname']);
2559 if (!in_array($tmprelativefilename, $file_list[
'insignature'])) {
2560 $md5newfile = @md5_file($valfile[
'fullname']);
2561 $file_list[
'added'][] = array(
'filename' => $tmprelativefilename,
'md5' => $md5newfile);
2568 $out .=
'<div class="div-table-responsive-no-min">';
2569 $out .=
'<table class="noborder">';
2570 $out .=
'<tr class="liste_titre">';
2571 $out .=
'<td>#</td>';
2572 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2573 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2574 $out .=
'</tr>'.
"\n";
2575 $tmpfilelist =
dol_sort_array($file_list[
'missing'],
'filename');
2576 if (is_array($tmpfilelist) && count($tmpfilelist)) {
2578 foreach ($tmpfilelist as $file) {
2580 $out .=
'<tr class="oddeven">';
2581 $out .=
'<td>'.$i.
'</td>'.
"\n";
2582 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2583 $out .=
'<td class="center">'.(array_key_exists(
'expectedmd5', $file) ? $file[
'expectedmd5'] :
'').
'</td>'.
"\n";
2587 $out .=
'<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2598 $out .=
'<div class="div-table-responsive-no-min">';
2599 $out .=
'<table class="noborder">';
2600 $out .=
'<tr class="liste_titre">';
2601 $out .=
'<td>#</td>';
2602 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2603 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2604 $out .=
'<td class="center">'.$langs->trans(
"CurrentChecksum").
'</td>';
2605 $out .=
'<td class="right">'.$langs->trans(
"Size").
'</td>';
2606 $out .=
'<td class="right">'.$langs->trans(
"DateModification").
'</td>';
2607 $out .=
'</tr>'.
"\n";
2608 $tmpfilelist2 =
dol_sort_array($file_list[
'updated'],
'filename');
2609 if (is_array($tmpfilelist2) && count($tmpfilelist2)) {
2611 foreach ($tmpfilelist2 as $file) {
2613 $out .=
'<tr class="oddeven">';
2614 $out .=
'<td>'.$i.
'</td>'.
"\n";
2615 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2616 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2617 $out .=
'<td class="center">'.$file[
'md5'].
'</td>'.
"\n";
2618 $size =
dol_filesize(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']);
2619 $totalsize += $size;
2620 $out .=
'<td class="right">'.dol_print_size($size).
'</td>'.
"\n";
2621 $out .=
'<td class="right">'.dol_print_date(
dol_filemtime(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']),
'dayhour').
'</td>'.
"\n";
2624 $out .=
'<tr class="liste_total">';
2625 $out .=
'<td></td>'.
"\n";
2626 $out .=
'<td>'.$langs->trans(
"Total").
'</td>'.
"\n";
2627 $out .=
'<td align="center"></td>'.
"\n";
2628 $out .=
'<td align="center"></td>'.
"\n";
2629 $out .=
'<td class="right">'.dol_print_size($totalsize).
'</td>'.
"\n";
2630 $out .=
'<td class="right"></td>'.
"\n";
2633 $out .=
'<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2644 $out .=
'<div class="div-table-responsive-no-min">';
2645 $out .=
'<table class="noborder">';
2646 $out .=
'<tr class="liste_titre">';
2647 $out .=
'<td>#</td>';
2648 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2649 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2650 $out .=
'<td class="center">'.$langs->trans(
"CurrentChecksum").
'</td>';
2651 $out .=
'<td class="right">'.$langs->trans(
"Size").
'</td>';
2652 $out .=
'<td class="right">'.$langs->trans(
"DateModification").
'</td>';
2653 $out .=
'</tr>'.
"\n";
2655 if (is_array($tmpfilelist3) && count($tmpfilelist3)) {
2657 foreach ($tmpfilelist3 as $file) {
2659 $out .=
'<tr class="oddeven">';
2660 $out .=
'<td>'.$i.
'</td>'.
"\n";
2661 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2662 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2663 $out .=
'<td class="center">'.$file[
'md5'].
'</td>'.
"\n";
2664 $size =
dol_filesize(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']);
2665 $totalsize += $size;
2666 $out .=
'<td class="right">'.dol_print_size($size).
'</td>'.
"\n";
2667 $out .=
'<td class="right">'.dol_print_date(
dol_filemtime(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']),
'dayhour').
'</td>'.
"\n";
2670 $out .=
'<tr class="liste_total">';
2671 $out .=
'<td></td>'.
"\n";
2672 $out .=
'<td>'.$langs->trans(
"Total").
'</td>'.
"\n";
2673 $out .=
'<td align="center"></td>'.
"\n";
2674 $out .=
'<td align="center"></td>'.
"\n";
2675 $out .=
'<td class="right">'.dol_print_size($totalsize).
'</td>'.
"\n";
2676 $out .=
'<td class="right"></td>'.
"\n";
2679 $out .=
'<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2686 if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) {
2692 throw new RestException(500,
'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile);
2697 asort($checksumconcat);
2698 $checksumget = md5(implode(
',', $checksumconcat));
2699 $checksumtoget = trim((
string) $xml->dolibarr_htdocs_dir_checksum);
2701 $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans(
"Unknown"));
2702 if ($checksumget == $checksumtoget) {
2703 if (count($file_list[
'added'])) {
2704 $resultcode =
'warning';
2705 $resultcomment =
'FileIntegrityIsOkButFilesWereAdded';
2707 $outcurrentchecksum = $checksumget;
2710 $resultcomment =
'Success';
2712 $outcurrentchecksum = $checksumget;
2715 $resultcode =
'error';
2716 $resultcomment =
'Error';
2718 $outcurrentchecksum = $checksumget;
2721 throw new RestException(404,
'No signature file known');
2724 return array(
'resultcode' => $resultcode,
'resultcomment' => $resultcomment,
'expectedchecksum' => $outexpectedchecksum,
'currentchecksum' => $outcurrentchecksum,
'out' => $out);
2741 if (!DolibarrApiAccess::$user->admin
2743 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');
2746 sort(
$conf->modules);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage dictionary Countries (used by imports)
Class to manage dictionary Regions.
Class to manage dictionary States (used by imports)
_checkFilters($sqlfilters, &$error='')
Return if a $sqlfilters parameter is valid Function no more used.
_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.
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.
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.
getCompany()
Get properties of company.
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.
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.
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.
_fetchCcountry($id, $code='', $iso='', $lang='')
Get country.
getListOfExtrafields($sortfield="t.pos", $sortorder='ASC', $elementtype='', $sqlfilters='')
Get the list of extra fields.
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($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.
load_fiche_titre($title, $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 the value of a given key, which produces ascending (default) or descending out...
jsonOrUnserialize($stringtodecode)
Decode an encode string.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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).
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...