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';
47 private $translations =
null;
77 public function getListOfActionTriggers($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $elementtype =
'', $lang =
'', $sqlfilters =
'')
81 if ($elementtype ==
'thirdparty') {
82 $elementtype =
'societe';
84 if ($elementtype ==
'contact') {
85 $elementtype =
'socpeople';
88 $sql =
"SELECT t.rowid as id, t.elementtype, t.code, t.contexts, t.label, t.description, t.rang";
89 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_action_trigger as t";
91 if (!empty($elementtype)) {
92 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
99 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
103 $sql .= $this->db->order($sortfield, $sortorder);
109 $offset = $limit * $page;
111 $sql .= $this->db->plimit($limit, $offset);
114 $result = $this->db->query($sql);
116 $num = $this->db->num_rows($result);
117 $min = min($num, ($limit <= 0 ? $num : $limit));
118 for ($i = 0; $i < $min; $i++) {
119 $type = $this->db->fetch_object($result);
124 throw new RestException(503,
'Error when retrieving list of action triggers : '.$this->db->lasterror());
150 public function getOrderingMethods($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
154 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
155 throw new RestException(403);
158 $sql =
"SELECT rowid, code, libelle as label, module";
159 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_input_method as t";
160 $sql .=
" WHERE t.active = ".((int) $active);
166 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
171 $sql .= $this->db->order($sortfield, $sortorder);
177 $offset = $limit * $page;
179 $sql .= $this->db->plimit($limit, $offset);
182 $result = $this->db->query($sql);
185 $num = $this->db->num_rows($result);
186 $min = min($num, ($limit <= 0 ? $num : $limit));
187 for ($i = 0; $i < $min; $i++) {
188 $list[] = $this->db->fetch_object($result);
191 throw new RestException(503, $this->db->lasterror());
216 public function getOrderingOrigins($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
220 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
221 throw new RestException(403);
224 $sql =
"SELECT rowid, code, label, module";
225 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_input_reason as t";
226 $sql .=
" WHERE t.active = ".((int) $active);
232 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
237 $sql .= $this->db->order($sortfield, $sortorder);
243 $offset = $limit * $page;
245 $sql .= $this->db->plimit($limit, $offset);
248 $result = $this->db->query($sql);
251 $num = $this->db->num_rows($result);
252 $min = min($num, ($limit <= 0 ? $num : $limit));
253 for ($i = 0; $i < $min; $i++) {
254 $list[] = $this->db->fetch_object($result);
257 throw new RestException(503, $this->db->lasterror());
283 public function getPaymentTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
287 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire') && !DolibarrApiAccess::$user->hasRight(
'commande',
'lire') && !DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
288 throw new RestException(403);
291 $sql =
"SELECT id, code, type, libelle as label, module";
292 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_paiement as t";
293 $sql .=
" WHERE t.entity IN (".getEntity(
'c_paiement').
")";
294 $sql .=
" AND t.active = ".((int) $active);
300 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
305 $sql .= $this->db->order($sortfield, $sortorder);
311 $offset = $limit * $page;
313 $sql .= $this->db->plimit($limit, $offset);
316 $result = $this->db->query($sql);
319 $num = $this->db->num_rows($result);
320 $min = min($num, ($limit <= 0 ? $num : $limit));
321 for ($i = 0; $i < $min; $i++) {
322 $list[] = $this->db->fetch_object($result);
325 throw new RestException(503, $this->db->lasterror());
351 public function getListOfRegions($sortfield =
"code_region", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $filter =
'', $sqlfilters =
'')
357 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.
"c_regions as t";
358 $sql .=
" WHERE 1 = 1";
360 $sql .=
" AND t.fk_pays = ".((int) $country);
366 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
368 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
369 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
372 $sql .= $this->db->order($sortfield, $sortorder);
378 $offset = $limit * $page;
380 $sql .= $this->db->plimit($limit, $offset);
383 $result = $this->db->query($sql);
386 $num = $this->db->num_rows($result);
387 $min = min($num, ($limit <= 0 ? $num : $limit));
388 for ($i = 0; $i < $min; $i++) {
389 $obj = $this->db->fetch_object($result);
390 $region =
new Cregion($this->db);
391 if ($region->fetch($obj->rowid) > 0) {
392 if (empty($filter) || stripos($region->name, $filter) !==
false) {
398 throw new RestException(503,
'Error when retrieving list of regions');
464 public function getListOfStates($sortfield =
"code_departement", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $filter =
'', $sqlfilters =
'')
470 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.
"c_departements as t";
472 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as d ON t.fk_region = d.code_region";
474 $sql .=
" WHERE 1 = 1";
476 $sql .=
" AND d.fk_pays = ".((int) $country);
483 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
487 $sql .= $this->db->order($sortfield, $sortorder);
493 $offset = $limit * $page;
495 $sql .= $this->db->plimit($limit, $offset);
498 $result = $this->db->query($sql);
501 $num = $this->db->num_rows($result);
502 $min = min($num, ($limit <= 0 ? $num : $limit));
503 for ($i = 0; $i < $min; $i++) {
504 $obj = $this->db->fetch_object($result);
505 $state =
new Cstate($this->db);
506 if ($state->fetch($obj->rowid) > 0) {
507 if (empty($filter) || stripos($state->label, $filter) !==
false) {
513 throw new RestException(503,
'Error when retrieving list of states');
579 public function getListOfCountries($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $filter =
'', $lang =
'', $sqlfilters =
'')
585 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"c_country as t";
586 $sql .=
" WHERE 1 = 1";
592 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
596 $sql .= $this->db->order($sortfield, $sortorder);
602 $offset = $limit * $page;
604 $sql .= $this->db->plimit($limit, $offset);
607 $result = $this->db->query($sql);
610 $num = $this->db->num_rows($result);
611 $min = min($num, ($limit <= 0 ? $num : $limit));
612 for ($i = 0; $i < $min; $i++) {
613 $obj = $this->db->fetch_object($result);
615 if ($country->fetch($obj->rowid) > 0) {
620 if (empty($filter) || stripos($country->label, $filter) !==
false) {
626 throw new RestException(503,
'Error when retrieving list of countries');
700 $region =
new Cregion($this->db);
702 $result = $region->fetch(
$id, (
int) $code);
704 throw new RestException(503,
'Error when retrieving region : '.$region->error);
705 } elseif ($result == 0) {
706 throw new RestException(404,
'Region not found');
725 $state =
new Cstate($this->db);
727 $result = $state->fetch(
$id, $code);
729 throw new RestException(503,
'Error when retrieving state : '.$state->error);
730 } elseif ($result == 0) {
731 throw new RestException(404,
'State not found');
754 $result = $country->fetch(
$id, $code, $iso);
757 throw new RestException(503,
'Error when retrieving country : '.$country->error);
758 } elseif ($result == 0) {
759 throw new RestException(404,
'Country not found');
787 public function getAvailability($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
791 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
792 throw new RestException(403);
795 $sql =
"SELECT rowid, code, label";
796 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_availability as t";
797 $sql .=
" WHERE t.active = ".((int) $active);
803 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
808 $sql .= $this->db->order($sortfield, $sortorder);
814 $offset = $limit * $page;
816 $sql .= $this->db->plimit($limit, $offset);
819 $result = $this->db->query($sql);
822 $num = $this->db->num_rows($result);
823 $min = min($num, ($limit <= 0 ? $num : $limit));
824 for ($i = 0; $i < $min; $i++) {
825 $list[] = $this->db->fetch_object($result);
828 throw new RestException(503, $this->db->lasterror());
865 if ($this->translations ==
null || $this->translations->getDefaultLang() !== $lang) {
868 $this->translations->setDefaultLang($lang);
869 $this->translations->loadLangs($dict);
872 $key = $prefix.$object->code;
874 $translation = $this->translations->trans($key);
875 if ($translation != $key) {
876 $object->label = html_entity_decode($translation);
902 public function getListOfEventTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $type =
'', $module =
'', $active = 1, $sqlfilters =
'')
906 $sql =
"SELECT id, code, type, libelle as label, module";
907 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_actioncomm as t";
908 $sql .=
" WHERE t.active = ".((int) $active);
910 $sql .=
" AND t.type LIKE '%".$this->db->escape($type).
"%'";
913 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
920 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
925 $sql .= $this->db->order($sortfield, $sortorder);
931 $offset = $limit * $page;
933 $sql .= $this->db->plimit($limit, $offset);
936 $result = $this->db->query($sql);
939 $num = $this->db->num_rows($result);
940 $min = min($num, ($limit <= 0 ? $num : $limit));
941 for ($i = 0; $i < $min; $i++) {
942 $list[] = $this->db->fetch_object($result);
945 throw new RestException(503,
'Error when retrieving list of events types : '.$this->db->lasterror());
971 public function getListOfExpenseReportsTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $module =
'', $active = 1, $sqlfilters =
'')
975 $sql =
"SELECT id, code, label, accountancy_code, active, module, position";
976 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees as t";
977 $sql .=
" WHERE t.active = ".((int) $active);
979 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
986 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
991 $sql .= $this->db->order($sortfield, $sortorder);
997 $offset = $limit * $page;
999 $sql .= $this->db->plimit($limit, $offset);
1002 $result = $this->db->query($sql);
1005 $num = $this->db->num_rows($result);
1006 $min = min($num, ($limit <= 0 ? $num : $limit));
1007 for ($i = 0; $i < $min; $i++) {
1008 $list[] = $this->db->fetch_object($result);
1011 throw new RestException(503,
'Error when retrieving list of expense report types : '.$this->db->lasterror());
1039 public function getListOfContactTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $type =
'', $module =
'', $active = 1, $lang =
'', $sqlfilters =
'')
1043 $sql =
"SELECT rowid, code, element as type, libelle as label, source, module, position";
1044 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact as t";
1045 $sql .=
" WHERE t.active = ".((int) $active);
1047 $sql .=
" AND t.element LIKE '%".$this->db->escape($type).
"%'";
1050 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
1056 if ($errormessage) {
1057 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1062 $sql .= $this->db->order($sortfield, $sortorder);
1068 $offset = $limit * $page;
1070 $sql .= $this->db->plimit($limit, $offset);
1073 $result = $this->db->query($sql);
1076 $num = $this->db->num_rows($result);
1077 $min = min($num, ($limit <= 0 ? $num : $limit));
1078 for ($i = 0; $i < $min; $i++) {
1079 $contact_type = $this->db->fetch_object($result);
1080 $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"));
1081 $list[] = $contact_type;
1084 throw new RestException(503,
'Error when retrieving list of contacts types : '.$this->db->lasterror());
1110 public function getListOfCivilities($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $module =
'', $active = 1, $lang =
'', $sqlfilters =
'')
1114 $sql =
"SELECT rowid, code, label, module";
1115 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_civility as t";
1116 $sql .=
" WHERE t.active = ".((int) $active);
1118 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
1124 if ($errormessage) {
1125 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1130 $sql .= $this->db->order($sortfield, $sortorder);
1136 $offset = $limit * $page;
1138 $sql .= $this->db->plimit($limit, $offset);
1141 $result = $this->db->query($sql);
1144 $num = $this->db->num_rows($result);
1145 $min = min($num, ($limit <= 0 ? $num : $limit));
1146 for ($i = 0; $i < $min; $i++) {
1147 $civility = $this->db->fetch_object($result);
1148 $this->
translateLabel($civility, $lang,
'Civility', array(
'dict'));
1149 $list[] = $civility;
1152 throw new RestException(503,
'Error when retrieving list of civility : '.$this->db->lasterror());
1177 public function getListOfCurrencies($multicurrency = 0, $sortfield =
"code_iso", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1180 $sql =
"SELECT t.code_iso, t.label, t.unicode";
1181 if (!empty($multicurrency)) {
1182 $sql .=
" , cr.date_sync, cr.rate ";
1184 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_currencies as t";
1185 if (!empty($multicurrency)) {
1186 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"multicurrency as m ON m.code=t.code_iso";
1187 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"multicurrency_rate as cr ON (m.rowid = cr.fk_multicurrency)";
1189 $sql .=
" WHERE t.active = ".((int) $active);
1190 if (!empty($multicurrency)) {
1191 $sql .=
" AND m.entity IN (".getEntity(
'multicurrency').
")";
1192 if (!empty($multicurrency) && $multicurrency != 2) {
1193 $sql .=
" AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM ".MAIN_DB_PREFIX.
"multicurrency_rate AS cr2 WHERE cr2.fk_multicurrency = m.rowid)";
1201 if ($errormessage) {
1202 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1207 $sql .= $this->db->order($sortfield, $sortorder);
1213 $offset = $limit * $page;
1215 $sql .= $this->db->plimit($limit, $offset);
1218 $result = $this->db->query($sql);
1221 $num = $this->db->num_rows($result);
1222 $min = min($num, ($limit <= 0 ? $num : $limit));
1223 for ($i = 0; $i < $min; $i++) {
1224 $list[] = $this->db->fetch_object($result);
1227 throw new RestException(503,
'Error when retrieving list of currency : '.$this->db->lasterror());
1249 public function getListOfExtrafields($sortfield =
"t.pos", $sortorder =
'ASC', $elementtype =
'', $sqlfilters =
'')
1253 if (!DolibarrApiAccess::$user->admin
1255 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');
1258 if ($elementtype ==
'thirdparty') {
1259 $elementtype =
'societe';
1261 if ($elementtype ==
'contact') {
1262 $elementtype =
'socpeople';
1265 $sql =
"SELECT t.rowid as id, t.name, t.entity, t.elementtype, t.label, t.type, t.size, t.fieldcomputed, t.fielddefault,";
1266 $sql .=
" t.fieldunique, t.fieldrequired, t.perms, t.enabled, t.pos, t.alwayseditable, t.param, t.list, t.printable,";
1267 $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";
1268 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1269 $sql .=
" WHERE t.entity IN (".getEntity(
'extrafields').
")";
1270 if (!empty($elementtype)) {
1271 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
1277 if ($errormessage) {
1278 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1282 $sql .= $this->db->order($sortfield, $sortorder);
1284 $resql = $this->db->query($sql);
1286 if ($this->db->num_rows($resql)) {
1287 while ($tab = $this->db->fetch_object($resql)) {
1289 $list[$tab->elementtype][$tab->name][
'id'] = $tab->id;
1290 $list[$tab->elementtype][$tab->name][
'type'] = $tab->type;
1291 $list[$tab->elementtype][$tab->name][
'label'] = $tab->label;
1292 $list[$tab->elementtype][$tab->name][
'size'] = $tab->size;
1293 $list[$tab->elementtype][$tab->name][
'elementtype'] = $tab->elementtype;
1294 $list[$tab->elementtype][$tab->name][
'default'] = $tab->fielddefault;
1295 $list[$tab->elementtype][$tab->name][
'computed'] = $tab->fieldcomputed;
1296 $list[$tab->elementtype][$tab->name][
'unique'] = $tab->fieldunique;
1297 $list[$tab->elementtype][$tab->name][
'required'] = $tab->fieldrequired;
1298 $list[$tab->elementtype][$tab->name][
'param'] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1299 $list[$tab->elementtype][$tab->name][
'pos'] = $tab->pos;
1300 $list[$tab->elementtype][$tab->name][
'alwayseditable'] = $tab->alwayseditable;
1301 $list[$tab->elementtype][$tab->name][
'perms'] = $tab->perms;
1302 $list[$tab->elementtype][$tab->name][
'list'] = $tab->list;
1303 $list[$tab->elementtype][$tab->name][
'printable'] = $tab->printable;
1304 $list[$tab->elementtype][$tab->name][
'totalizable'] = $tab->totalizable;
1305 $list[$tab->elementtype][$tab->name][
'langs'] = $tab->langs;
1306 $list[$tab->elementtype][$tab->name][
'help'] = $tab->help;
1307 $list[$tab->elementtype][$tab->name][
'css'] = $tab->css;
1308 $list[$tab->elementtype][$tab->name][
'cssview'] = $tab->cssview;
1309 $list[$tab->elementtype][$tab->name][
'csslist'] = $tab->csslist;
1310 $list[$tab->elementtype][$tab->name][
'fk_user_author'] = $tab->fk_user_author;
1311 $list[$tab->elementtype][$tab->name][
'fk_user_modif'] = $tab->fk_user_modif;
1312 $list[$tab->elementtype][$tab->name][
'datec'] = $tab->datec;
1313 $list[$tab->elementtype][$tab->name][
'tms'] = $tab->tms;
1317 throw new RestException(503,
'Error when retrieving list of extra fields : '.$this->db->lasterror());
1336 if (!DolibarrApiAccess::$user->admin) {
1337 throw new RestException(403,
'Only an admin user can delete an extrafield by attrname and elementtype');
1342 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1344 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1347 if (!$extrafields->delete($attrname, $elementtype)) {
1348 throw new RestException(500,
'Error when delete extrafield : '.$extrafields->error);
1354 'message' =>
'Extrafield deleted from attrname and elementtype'
1377 if (!DolibarrApiAccess::$user->admin) {
1378 throw new RestException(403,
'Only an admin user can get list of extrafields');
1381 if ($elementtype ==
'thirdparty') {
1382 $elementtype =
'societe';
1384 if ($elementtype ==
'contact') {
1385 $elementtype =
'socpeople';
1388 $sql =
"SELECT t.rowid as id, t.name, t.entity, t.elementtype, t.label, t.type, t.size, t.fieldcomputed, t.fielddefault,";
1389 $sql .=
" t.fieldunique, t.fieldrequired, t.perms, t.enabled, t.pos, t.alwayseditable, t.param, t.list, t.printable,";
1390 $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";
1391 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1392 $sql .=
" WHERE t.entity IN (".getEntity(
'extrafields').
")";
1393 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
1394 $sql .=
" AND t.name = '".$this->db->escape($attrname).
"'";
1396 $resql = $this->db->query($sql);
1398 if ($this->db->num_rows($resql)) {
1399 while ($tab = $this->db->fetch_object($resql)) {
1401 $answer[$tab->elementtype][$tab->name][
'id'] = $tab->id;
1402 $answer[$tab->elementtype][$tab->name][
'type'] = $tab->type;
1403 $answer[$tab->elementtype][$tab->name][
'label'] = $tab->label;
1404 $answer[$tab->elementtype][$tab->name][
'size'] = $tab->size;
1405 $answer[$tab->elementtype][$tab->name][
'elementtype'] = $tab->elementtype;
1406 $answer[$tab->elementtype][$tab->name][
'default'] = $tab->fielddefault;
1407 $answer[$tab->elementtype][$tab->name][
'computed'] = $tab->fieldcomputed;
1408 $answer[$tab->elementtype][$tab->name][
'unique'] = $tab->fieldunique;
1409 $answer[$tab->elementtype][$tab->name][
'required'] = $tab->fieldrequired;
1410 $answer[$tab->elementtype][$tab->name][
'param'] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1411 $answer[$tab->elementtype][$tab->name][
'pos'] = $tab->pos;
1412 $answer[$tab->elementtype][$tab->name][
'alwayseditable'] = $tab->alwayseditable;
1413 $answer[$tab->elementtype][$tab->name][
'perms'] = $tab->perms;
1414 $answer[$tab->elementtype][$tab->name][
'list'] = $tab->list;
1415 $answer[$tab->elementtype][$tab->name][
'printable'] = $tab->printable;
1416 $answer[$tab->elementtype][$tab->name][
'totalizable'] = $tab->totalizable;
1417 $answer[$tab->elementtype][$tab->name][
'langs'] = $tab->langs;
1418 $answer[$tab->elementtype][$tab->name][
'help'] = $tab->help;
1419 $answer[$tab->elementtype][$tab->name][
'css'] = $tab->css;
1420 $answer[$tab->elementtype][$tab->name][
'cssview'] = $tab->cssview;
1421 $answer[$tab->elementtype][$tab->name][
'csslist'] = $tab->csslist;
1422 $answer[$tab->elementtype][$tab->name][
'fk_user_author'] = $tab->fk_user_author;
1423 $answer[$tab->elementtype][$tab->name][
'fk_user_modif'] = $tab->fk_user_modif;
1424 $answer[$tab->elementtype][$tab->name][
'datec'] = $tab->datec;
1425 $answer[$tab->elementtype][$tab->name][
'tms'] = $tab->tms;
1428 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1431 throw new RestException(503,
'Error when retrieving list of extra fields : '.$this->db->lasterror());
1453 if (!DolibarrApiAccess::$user->admin) {
1454 throw new RestException(403,
'Only an admin user can create an extrafield');
1459 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1461 throw new RestException(409,
'Duplicate extrafield already found from attrname and elementtype');
1467 foreach ($request_data as $field => $value) {
1468 $extrafields->$field = $this->
_checkValForAPI($field, $value, $extrafields);
1471 $entity = DolibarrApiAccess::$user->entity;
1472 if (empty($entity)) {
1479 if ($request_data[
'label']) {
1480 $label = $request_data[
'label'];
1482 throw new RestException(400,
"label field absent in json at root level");
1485 $alwayseditable = $request_data[
'alwayseditable'];
1486 $default_value = $request_data[
'default'];
1487 $totalizable = $request_data[
'totalizable'];
1488 $printable = $request_data[
'printable'];
1489 $required = $request_data[
'required'];
1490 $langfile = $request_data[
'langfile'];
1491 $computed = $request_data[
'computed'];
1492 $unique = $request_data[
'unique'];
1493 $param = $request_data[
'param'];
1494 $perms = $request_data[
'perms'];
1495 $size = $request_data[
'size'];
1496 $type = $request_data[
'type'];
1497 $list = $request_data[
'list'];
1498 $help = $request_data[
'help'];
1499 $pos = $request_data[
'pos'];
1500 $moreparams = array();
1502 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)) {
1503 throw new RestException(500,
'Error creating extrafield', array_merge(array($extrafields->errno), $extrafields->errors));
1506 $sql =
"SELECT t.rowid as id";
1507 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1508 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1509 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1511 $resql = $this->db->query($sql);
1513 if ($this->db->num_rows($resql)) {
1514 $tab = $this->db->fetch_object($resql);
1515 $id = (int) $tab->id;
1542 if (!DolibarrApiAccess::$user->admin) {
1543 throw new RestException(403,
'Only an admin user can create an extrafield');
1548 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1550 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1553 foreach ($request_data as $field => $value) {
1554 $extrafields->$field = $this->
_checkValForAPI($field, $value, $extrafields);
1557 $entity = DolibarrApiAccess::$user->entity;
1558 if (empty($entity)) {
1564 if ($request_data[
'label']) {
1565 $label = $request_data[
'label'];
1567 throw new RestException(400,
"label field absent in json at root level");
1570 $alwayseditable = $request_data[
'alwayseditable'];
1571 $default_value = $request_data[
'default'];
1572 $totalizable = $request_data[
'totalizable'];
1573 $printable = $request_data[
'printable'];
1574 $required = $request_data[
'required'];
1575 $langfile = $request_data[
'langfile'];
1576 $computed = $request_data[
'computed'];
1577 $unique = $request_data[
'unique'];
1578 $param = $request_data[
'param'];
1579 $perms = $request_data[
'perms'];
1580 $size = $request_data[
'size'];
1581 $type = $request_data[
'type'];
1582 $list = $request_data[
'list'];
1583 $help = $request_data[
'help'];
1584 $pos = $request_data[
'pos'];
1585 $moreparams = array();
1587 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)) {
1588 throw new RestException(500,
'Error updating extrafield', array_merge(array($extrafields->errno), $extrafields->errors));
1591 $sql =
"SELECT t.rowid as id";
1592 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1593 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1594 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1596 $resql = $this->db->query($sql);
1598 if ($this->db->num_rows($resql)) {
1599 $tab = $this->db->fetch_object($resql);
1600 $id = (int) $tab->id;
1631 public function getListOfTowns($sortfield =
"zip,town", $sortorder =
'ASC', $limit = 100, $page = 0, $zipcode =
'', $town =
'', $active = 1, $sqlfilters =
'')
1635 $sql =
"SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
1636 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ziptown as t";
1637 $sql .=
" WHERE t.active = ".((int) $active);
1639 $sql .=
" AND t.zip LIKE '%".$this->db->escape($zipcode).
"%'";
1642 $sql .=
" AND t.town LIKE '%".$this->db->escape($town).
"%'";
1648 if ($errormessage) {
1649 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1654 $sql .= $this->db->order($sortfield, $sortorder);
1660 $offset = $limit * $page;
1662 $sql .= $this->db->plimit($limit, $offset);
1665 $result = $this->db->query($sql);
1668 $num = $this->db->num_rows($result);
1669 $min = min($num, ($limit <= 0 ? $num : $limit));
1670 for ($i = 0; $i < $min; $i++) {
1671 $list[] = $this->db->fetch_object($result);
1674 throw new RestException(503,
'Error when retrieving list of towns : '.$this->db->lasterror());
1700 public function getPaymentTerms($sortfield =
"sortorder", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1704 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire') && !DolibarrApiAccess::$user->hasRight(
'commande',
'lire') && !DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1705 throw new RestException(403);
1708 $sql =
"SELECT rowid as id, code, sortorder, libelle as label, libelle_facture as descr, type_cdr, nbjour, decalage, module";
1709 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_payment_term as t";
1710 $sql .=
" WHERE t.entity IN (".getEntity(
'c_payment_term').
")";
1711 $sql .=
" AND t.active = ".((int) $active);
1716 if ($errormessage) {
1717 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1722 $sql .= $this->db->order($sortfield, $sortorder);
1728 $offset = $limit * $page;
1730 $sql .= $this->db->plimit($limit, $offset);
1733 $result = $this->db->query($sql);
1736 $num = $this->db->num_rows($result);
1737 $min = min($num, ($limit <= 0 ? $num : $limit));
1738 for ($i = 0; $i < $min; $i++) {
1739 $list[] = $this->db->fetch_object($result);
1742 throw new RestException(503, $this->db->lasterror());
1766 public function getShippingModes($limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
1770 $sql =
"SELECT rowid as id, code, libelle as label, description, tracking, module";
1771 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as t";
1772 $sql .=
" WHERE t.entity IN (".getEntity(
'c_shipment_mode').
")";
1773 $sql .=
" AND t.active = ".((int) $active);
1778 if ($errormessage) {
1779 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1790 $offset = $limit * $page;
1792 $sql .= $this->db->plimit($limit, $offset);
1795 $result = $this->db->query($sql);
1798 $num = $this->db->num_rows($result);
1799 $min = min($num, ($limit <= 0 ? $num : $limit));
1800 for ($i = 0; $i < $min; $i++) {
1801 $method = $this->db->fetch_object($result);
1806 throw new RestException(503, $this->db->lasterror());
1830 public function getListOfMeasuringUnits($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1834 $sql =
"SELECT t.rowid, t.code, t.label,t.short_label, t.active, t.scale, t.unit_type";
1835 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_units as t";
1836 $sql .=
" WHERE t.active = ".((int) $active);
1841 if ($errormessage) {
1842 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1847 $sql .= $this->db->order($sortfield, $sortorder);
1853 $offset = $limit * $page;
1855 $sql .= $this->db->plimit($limit, $offset);
1858 $result = $this->db->query($sql);
1861 $num = $this->db->num_rows($result);
1862 $min = min($num, ($limit <= 0 ? $num : $limit));
1863 for ($i = 0; $i < $min; $i++) {
1864 $list[] = $this->db->fetch_object($result);
1867 throw new RestException(503,
'Error when retrieving list of measuring units: '.$this->db->lasterror());
1892 public function getListOfLegalForm($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $active = 1, $sqlfilters =
'')
1896 $sql =
"SELECT t.rowid, t.code, t.fk_pays, t.libelle, t.isvatexempted, t.active, t.module, t.position";
1897 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_forme_juridique as t";
1898 $sql .=
" WHERE t.active = ".((int) $active);
1900 $sql .=
" AND t.fk_pays = ".((int) $country);
1906 if ($errormessage) {
1907 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1912 $sql .= $this->db->order($sortfield, $sortorder);
1918 $offset = $limit * $page;
1920 $sql .= $this->db->plimit($limit, $offset);
1923 $result = $this->db->query($sql);
1926 $num = $this->db->num_rows($result);
1927 $min = min($num, ($limit <= 0 ? $num : $limit));
1928 for ($i = 0; $i < $min; $i++) {
1929 $list[] = $this->db->fetch_object($result);
1932 throw new RestException(503,
'Error when retrieving list of legal form: '.$this->db->lasterror());
1956 public function getListOfStaff($sortfield =
"id", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1960 $sql =
"SELECT t.id, t.code, t.libelle, t.active, t.module";
1961 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_effectif as t";
1962 $sql .=
" WHERE t.active = ".((int) $active);
1967 if ($errormessage) {
1968 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1973 $sql .= $this->db->order($sortfield, $sortorder);
1979 $offset = $limit * $page;
1981 $sql .= $this->db->plimit($limit, $offset);
1984 $result = $this->db->query($sql);
1987 $num = $this->db->num_rows($result);
1988 $min = min($num, ($limit <= 0 ? $num : $limit));
1989 for ($i = 0; $i < $min; $i++) {
1990 $list[] = $this->db->fetch_object($result);
1993 throw new RestException(503,
'Error when retrieving list of staff: '.$this->db->lasterror());
2017 public function getListOfsocialNetworks($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
2021 if (!isModEnabled(
'socialnetworks')) {
2022 throw new RestException(400,
'API not available: this dictionary is not enabled by setup');
2027 $sql =
"SELECT t.rowid, t.entity, t.code, t.label, t.url, t.icon, t.active";
2028 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_socialnetworks as t";
2029 $sql .=
" WHERE t.entity IN (".getEntity(
'c_socialnetworks').
")";
2030 $sql .=
" AND t.active = ".((int) $active);
2035 if ($errormessage) {
2036 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2041 $sql .= $this->db->order($sortfield, $sortorder);
2047 $offset = $limit * $page;
2049 $sql .= $this->db->plimit($limit, $offset);
2052 $result = $this->db->query($sql);
2055 $num = $this->db->num_rows($result);
2056 $min = min($num, ($limit <= 0 ? $num : $limit));
2057 for ($i = 0; $i < $min; $i++) {
2058 $list[] = $this->db->fetch_object($result);
2061 throw new RestException(503,
'Error when retrieving list of social networks: '.$this->db->lasterror());
2086 public function getTicketsCategories($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2090 $sql =
"SELECT rowid, code, pos, label, use_default, description";
2091 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_category as t";
2092 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_category').
")";
2093 $sql .=
" AND t.active = ".((int) $active);
2098 if ($errormessage) {
2099 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2104 $sql .= $this->db->order($sortfield, $sortorder);
2110 $offset = $limit * $page;
2112 $sql .= $this->db->plimit($limit, $offset);
2115 $result = $this->db->query($sql);
2118 $num = $this->db->num_rows($result);
2119 $min = min($num, ($limit <= 0 ? $num : $limit));
2120 for ($i = 0; $i < $min; $i++) {
2121 $category = $this->db->fetch_object($result);
2122 $this->
translateLabel($category, $lang,
'TicketCategoryShort', array(
'ticket'));
2123 $list[] = $category;
2126 throw new RestException(503,
'Error when retrieving list of ticket categories : '.$this->db->lasterror());
2151 public function getTicketsSeverities($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2155 $sql =
"SELECT rowid, code, pos, label, use_default, color, description";
2156 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_severity as t";
2157 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_severity').
")";
2158 $sql .=
" AND t.active = ".((int) $active);
2163 if ($errormessage) {
2164 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2169 $sql .= $this->db->order($sortfield, $sortorder);
2175 $offset = $limit * $page;
2177 $sql .= $this->db->plimit($limit, $offset);
2180 $result = $this->db->query($sql);
2183 $num = $this->db->num_rows($result);
2184 $min = min($num, ($limit <= 0 ? $num : $limit));
2185 for ($i = 0; $i < $min; $i++) {
2186 $severity = $this->db->fetch_object($result);
2187 $this->
translateLabel($severity, $lang,
'TicketSeverityShort', array(
'ticket'));
2188 $list[] = $severity;
2191 throw new RestException(503,
'Error when retrieving list of ticket severities : '.$this->db->lasterror());
2216 public function getTicketsTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2220 $sql =
"SELECT rowid, code, pos, label, use_default, description";
2221 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_type as t";
2222 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_type').
")";
2223 $sql .=
" AND t.active = ".((int) $active);
2229 if ($errormessage) {
2230 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2235 $sql .= $this->db->order($sortfield, $sortorder);
2241 $offset = $limit * $page;
2243 $sql .= $this->db->plimit($limit, $offset);
2246 $result = $this->db->query($sql);
2249 $num = $this->db->num_rows($result);
2250 $min = min($num, ($limit <= 0 ? $num : $limit));
2251 for ($i = 0; $i < $min; $i++) {
2252 $type = $this->db->fetch_object($result);
2253 $this->
translateLabel($type, $lang,
'TicketTypeShort', array(
'ticket'));
2257 throw new RestException(503,
'Error when retrieving list of ticket types : '.$this->db->lasterror());
2281 public function getListOfIncoterms($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2285 $sql =
"SELECT rowid, code, active";
2286 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_incoterms as t";
2287 $sql .=
" WHERE 1=1";
2293 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2295 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
2296 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
2300 $sql .= $this->db->order($sortfield, $sortorder);
2306 $offset = $limit * $page;
2308 $sql .= $this->db->plimit($limit, $offset);
2311 $result = $this->db->query($sql);
2314 $num = $this->db->num_rows($result);
2315 $min = min($num, ($limit <= 0 ? $num : $limit));
2316 for ($i = 0; $i < $min; $i++) {
2317 $type = $this->db->fetch_object($result);
2321 throw new RestException(503,
'Error when retrieving list of incoterm types : '.$this->db->lasterror());
2340 global
$conf, $mysoc;
2342 if (!DolibarrApiAccess::$user->admin
2344 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');
2347 unset($mysoc->pays);
2348 unset($mysoc->note);
2351 unset($mysoc->lines);
2353 unset($mysoc->effectif);
2354 unset($mysoc->effectif_id);
2355 unset($mysoc->forme_juridique_code);
2356 unset($mysoc->forme_juridique);
2357 unset($mysoc->mode_reglement_supplier_id);
2358 unset($mysoc->cond_reglement_supplier_id);
2359 unset($mysoc->transport_mode_supplier_id);
2360 unset($mysoc->fk_prospectlevel);
2362 unset($mysoc->total_ht);
2363 unset($mysoc->total_tva);
2364 unset($mysoc->total_localtax1);
2365 unset($mysoc->total_localtax2);
2366 unset($mysoc->total_ttc);
2368 unset($mysoc->lastname);
2369 unset($mysoc->firstname);
2370 unset($mysoc->civility_id);
2372 unset($mysoc->client);
2373 unset($mysoc->prospect);
2374 unset($mysoc->fournisseur);
2375 unset($mysoc->contact_id);
2377 unset($mysoc->fk_incoterms);
2378 unset($mysoc->label_incoterms);
2379 unset($mysoc->location_incoterms);
2401 $sql =
"SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
2402 $sql .=
" FROM ".MAIN_DB_PREFIX.
"establishment as e";
2403 $sql .=
" WHERE e.entity IN (".getEntity(
'establishment').
')';
2408 $result = $this->db->query($sql);
2411 $num = $this->db->num_rows($result);
2412 $min = min($num, ($limit <= 0 ? $num : $limit));
2413 for ($i = 0; $i < $min; $i++) {
2414 $list[] = $this->db->fetch_object($result);
2417 throw new RestException(503,
'Error when retrieving list of establishments : '.$this->db->lasterror());
2438 $result = $establishment->fetch(
$id);
2440 throw new RestException(503,
'Error when retrieving establishment : '.$establishment->error);
2441 } elseif ($result == 0) {
2442 throw new RestException(404,
'Establishment not found');
2465 if (!DolibarrApiAccess::$user->admin
2467 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');
2470 if (!preg_match(
'/^[a-zA-Z0-9_]+$/', $constantname) || !isset(
$conf->global->$constantname)) {
2471 throw new RestException(400,
'Error Bad or unknown value for constantname');
2474 throw new RestException(403,
'Forbidden. This parameter can not be read with APIs');
2499 if (!DolibarrApiAccess::$user->admin
2501 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');
2504 $sql =
"select name, value";
2505 $sql .=
" FROM ".MAIN_DB_PREFIX.
"const";
2506 $sql .=
" WHERE entity IN (".getEntity(
'const').
')';
2508 $result = $this->db->query($sql);
2511 $num = $this->db->num_rows($result);
2512 for ($i = 0; $i < $num; $i++) {
2513 $obj = $this->db->fetch_object($result);
2516 $list[$obj->name] = $obj->value;
2520 throw new RestException(503,
'Error when retrieving list of const : '.$this->db->lasterror());
2542 global $langs,
$conf;
2544 if (!DolibarrApiAccess::$user->admin
2546 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');
2549 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2550 require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
2552 $langs->load(
"admin");
2554 $outexpectedchecksum =
'';
2555 $outcurrentchecksum =
'';
2558 $file_list = array(
'missing' => array(),
'updated' => array());
2563 $xmlfile = DOL_DOCUMENT_ROOT.
'/install/'.$xmlshortfile;
2564 if (!preg_match(
'/\.zip$/i', $xmlfile) &&
dol_is_file($xmlfile.
'.zip')) {
2569 $xmlremote = (($target ==
'default' || $target ==
'local') ?
'' : $target);
2573 $param =
'MAIN_FILECHECK_URL_'.DOL_VERSION;
2577 if (empty($xmlremote)) {
2578 $xmlremote =
'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.
'.xml';
2580 if ($xmlremote && !preg_match(
'/^https?:\/\//i', $xmlremote)) {
2581 $langs->load(
"errors");
2582 throw new RestException(500, $langs->trans(
"ErrorURLMustStartWithHttp", $xmlremote));
2584 if ($xmlremote && !preg_match(
'/\.xml$/', $xmlremote)) {
2585 $langs->load(
"errors");
2586 throw new RestException(500, $langs->trans(
"ErrorURLMustEndWith", $xmlremote,
'.xml'));
2589 if (LIBXML_VERSION < 20900) {
2593 libxml_disable_entity_loader(
true);
2596 if ($target ==
'local') {
2598 $xml = simplexml_load_file($xmlfile);
2600 throw new RestException(500, $langs->trans(
'XmlNotFound').
': /install/'.$xmlshortfile);
2603 $xmlarray =
getURLContent($xmlremote,
'GET',
'', 1, array(), array(
'http',
'https'), 0);
2606 if (!$xmlarray[
'curl_error_no'] && $xmlarray[
'http_code'] != 400 && $xmlarray[
'http_code'] != 404) {
2607 $xmlfile = $xmlarray[
'content'];
2609 $xml = simplexml_load_string($xmlfile,
'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NONET);
2611 $errormsg = $langs->trans(
'XmlNotFound').
': '.$xmlremote.
' - '.$xmlarray[
'http_code'].(($xmlarray[
'http_code'] == 400 && $xmlarray[
'content']) ?
' '.$xmlarray[
'content'] :
'').
' '.$xmlarray[
'curl_error_no'].
' '.$xmlarray[
'curl_error_msg'];
2612 throw new RestException(500, $errormsg);
2617 $checksumconcat = array();
2618 $file_list = array();
2622 if (is_object($xml->dolibarr_constants[0])) {
2625 $out .=
'<div class="div-table-responsive-no-min">';
2626 $out .=
'<table class="noborder">';
2627 $out .=
'<tr class="liste_titre">';
2628 $out .=
'<td>#</td>';
2629 $out .=
'<td>'.$langs->trans(
"Constant").
'</td>';
2630 $out .=
'<td class="center">'.$langs->trans(
"ExpectedValue").
'</td>';
2631 $out .=
'<td class="center">'.$langs->trans(
"Value").
'</td>';
2632 $out .=
'</tr>'.
"\n";
2635 foreach ($xml->dolibarr_constants[0]->constant as $constant) {
2636 $constname = $constant[
'name'];
2637 $constvalue = (string) $constant;
2638 $constvalue = (empty($constvalue) ?
'0' : $constvalue);
2644 $valueforchecksum = (empty($value) ?
'0' : $value);
2646 $checksumconcat[] = $valueforchecksum;
2649 $out .=
'<tr class="oddeven">';
2650 $out .=
'<td>'.$i.
'</td>'.
"\n";
2651 $out .=
'<td>'.dol_escape_htmltag($constname).
'</td>'.
"\n";
2652 $out .=
'<td class="center">'.dol_escape_htmltag($constvalue).
'</td>'.
"\n";
2653 $out .=
'<td class="center">'.dol_escape_htmltag($valueforchecksum).
'</td>'.
"\n";
2658 $out .=
'<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2667 if (is_object($xml->dolibarr_htdocs_dir[0])) {
2668 $includecustom = (empty($xml->dolibarr_htdocs_dir[0][
'includecustom']) ? 0 : $xml->dolibarr_htdocs_dir[0][
'includecustom']);
2671 $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)$';
2672 $regextoexclude =
'('.($includecustom ?
'' :
'custom|').
'documents|escpos-php\/doc|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)$';
2673 $scanfiles =
dol_dir_list(DOL_DOCUMENT_ROOT,
'files', 1, $regextoinclude, $regextoexclude);
2676 $ret =
getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0],
'', DOL_DOCUMENT_ROOT, $checksumconcat);
2677 '@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';
2679 foreach ($scanfiles as $keyfile => $valfile) {
2680 $tmprelativefilename = preg_replace(
'/^'.preg_quote(DOL_DOCUMENT_ROOT,
'/').
'/',
'', $valfile[
'fullname']);
2681 if (!in_array($tmprelativefilename, $file_list[
'insignature'])) {
2682 $md5newfile = @md5_file($valfile[
'fullname']);
2683 $file_list[
'added'][] = array(
'filename' => $tmprelativefilename,
'md5' => $md5newfile);
2690 $out .=
'<div class="div-table-responsive-no-min">';
2691 $out .=
'<table class="noborder">';
2692 $out .=
'<tr class="liste_titre">';
2693 $out .=
'<td>#</td>';
2694 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2695 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2696 $out .=
'</tr>'.
"\n";
2697 $tmpfilelist =
dol_sort_array($file_list[
'missing'],
'filename');
2698 if (is_array($tmpfilelist) && count($tmpfilelist)) {
2700 foreach ($tmpfilelist as $file) {
2702 $out .=
'<tr class="oddeven">';
2703 $out .=
'<td>'.$i.
'</td>'.
"\n";
2704 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2705 $out .=
'<td class="center">'.(array_key_exists(
'expectedmd5', $file) ? $file[
'expectedmd5'] :
'').
'</td>'.
"\n";
2709 $out .=
'<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2720 $out .=
'<div class="div-table-responsive-no-min">';
2721 $out .=
'<table class="noborder">';
2722 $out .=
'<tr class="liste_titre">';
2723 $out .=
'<td>#</td>';
2724 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2725 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2726 $out .=
'<td class="center">'.$langs->trans(
"CurrentChecksum").
'</td>';
2727 $out .=
'<td class="right">'.$langs->trans(
"Size").
'</td>';
2728 $out .=
'<td class="right">'.$langs->trans(
"DateModification").
'</td>';
2729 $out .=
'</tr>'.
"\n";
2730 $tmpfilelist2 =
dol_sort_array($file_list[
'updated'],
'filename');
2731 if (is_array($tmpfilelist2) && count($tmpfilelist2)) {
2733 foreach ($tmpfilelist2 as $file) {
2735 $out .=
'<tr class="oddeven">';
2736 $out .=
'<td>'.$i.
'</td>'.
"\n";
2737 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2738 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2739 $out .=
'<td class="center">'.$file[
'md5'].
'</td>'.
"\n";
2740 $size =
dol_filesize(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']);
2741 $totalsize += $size;
2742 $out .=
'<td class="right">'.dol_print_size($size).
'</td>'.
"\n";
2743 $out .=
'<td class="right">'.dol_print_date(
dol_filemtime(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']),
'dayhour').
'</td>'.
"\n";
2746 $out .=
'<tr class="liste_total">';
2747 $out .=
'<td></td>'.
"\n";
2748 $out .=
'<td>'.$langs->trans(
"Total").
'</td>'.
"\n";
2749 $out .=
'<td align="center"></td>'.
"\n";
2750 $out .=
'<td align="center"></td>'.
"\n";
2751 $out .=
'<td class="right">'.dol_print_size($totalsize).
'</td>'.
"\n";
2752 $out .=
'<td class="right"></td>'.
"\n";
2755 $out .=
'<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2766 $out .=
'<div class="div-table-responsive-no-min">';
2767 $out .=
'<table class="noborder">';
2768 $out .=
'<tr class="liste_titre">';
2769 $out .=
'<td>#</td>';
2770 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2771 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2772 $out .=
'<td class="center">'.$langs->trans(
"CurrentChecksum").
'</td>';
2773 $out .=
'<td class="right">'.$langs->trans(
"Size").
'</td>';
2774 $out .=
'<td class="right">'.$langs->trans(
"DateModification").
'</td>';
2775 $out .=
'</tr>'.
"\n";
2777 if (is_array($tmpfilelist3) && count($tmpfilelist3)) {
2779 foreach ($tmpfilelist3 as $file) {
2781 $out .=
'<tr class="oddeven">';
2782 $out .=
'<td>'.$i.
'</td>'.
"\n";
2783 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2784 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2785 $out .=
'<td class="center">'.$file[
'md5'].
'</td>'.
"\n";
2786 $size =
dol_filesize(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']);
2787 $totalsize += $size;
2788 $out .=
'<td class="right">'.dol_print_size($size).
'</td>'.
"\n";
2789 $out .=
'<td class="right">'.dol_print_date(
dol_filemtime(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']),
'dayhour').
'</td>'.
"\n";
2792 $out .=
'<tr class="liste_total">';
2793 $out .=
'<td></td>'.
"\n";
2794 $out .=
'<td>'.$langs->trans(
"Total").
'</td>'.
"\n";
2795 $out .=
'<td align="center"></td>'.
"\n";
2796 $out .=
'<td align="center"></td>'.
"\n";
2797 $out .=
'<td class="right">'.dol_print_size($totalsize).
'</td>'.
"\n";
2798 $out .=
'<td class="right"></td>'.
"\n";
2801 $out .=
'<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2808 if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) {
2814 throw new RestException(500,
'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile);
2819 asort($checksumconcat);
2820 $checksumget = md5(implode(
',', $checksumconcat));
2821 $checksumtoget = trim((
string) $xml->dolibarr_htdocs_dir_checksum);
2823 $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans(
"Unknown"));
2824 if ($checksumget == $checksumtoget) {
2825 if (count($file_list[
'added'])) {
2826 $resultcode =
'warning';
2827 $resultcomment =
'FileIntegrityIsOkButFilesWereAdded';
2829 $outcurrentchecksum = $checksumget;
2832 $resultcomment =
'Success';
2834 $outcurrentchecksum = $checksumget;
2837 $resultcode =
'error';
2838 $resultcomment =
'Error';
2840 $outcurrentchecksum = $checksumget;
2843 throw new RestException(404,
'No signature file known');
2846 return array(
'resultcode' => $resultcode,
'resultcomment' => $resultcomment,
'expectedchecksum' => $outexpectedchecksum,
'currentchecksum' => $outcurrentchecksum,
'out' => $out);
2865 if (!DolibarrApiAccess::$user->admin
2867 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');
2870 sort(
$conf->modules);
$id
Support class for third parties, contacts, members, users or resources.
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.
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.
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.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1, $timeoutconnect=0, $timeoutresponse=0)
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...