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);
367 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
371 $sql .= $this->db->order($sortfield, $sortorder);
377 $offset = $limit * $page;
379 $sql .= $this->db->plimit($limit, $offset);
382 $result = $this->db->query($sql);
385 $num = $this->db->num_rows($result);
386 $min = min($num, ($limit <= 0 ? $num : $limit));
387 for ($i = 0; $i < $min; $i++) {
388 $obj = $this->db->fetch_object($result);
389 $region =
new Cregion($this->db);
390 if ($region->fetch($obj->rowid) > 0) {
391 if (empty($filter) || stripos($region->name, $filter) !==
false) {
397 throw new RestException(503,
'Error when retrieving list of regions');
463 public function getListOfStates($sortfield =
"code_departement", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $filter =
'', $sqlfilters =
'')
469 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.
"c_departements as t";
471 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as d ON t.fk_region = d.code_region";
473 $sql .=
" WHERE 1 = 1";
475 $sql .=
" AND d.fk_pays = ".((int) $country);
482 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
486 $sql .= $this->db->order($sortfield, $sortorder);
492 $offset = $limit * $page;
494 $sql .= $this->db->plimit($limit, $offset);
497 $result = $this->db->query($sql);
500 $num = $this->db->num_rows($result);
501 $min = min($num, ($limit <= 0 ? $num : $limit));
502 for ($i = 0; $i < $min; $i++) {
503 $obj = $this->db->fetch_object($result);
504 $state =
new Cstate($this->db);
505 if ($state->fetch($obj->rowid) > 0) {
506 if (empty($filter) || stripos($state->label, $filter) !==
false) {
512 throw new RestException(503,
'Error when retrieving list of states');
578 public function getListOfCountries($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $filter =
'', $lang =
'', $sqlfilters =
'')
584 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"c_country as t";
585 $sql .=
" WHERE 1 = 1";
591 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
595 $sql .= $this->db->order($sortfield, $sortorder);
601 $offset = $limit * $page;
603 $sql .= $this->db->plimit($limit, $offset);
606 $result = $this->db->query($sql);
609 $num = $this->db->num_rows($result);
610 $min = min($num, ($limit <= 0 ? $num : $limit));
611 for ($i = 0; $i < $min; $i++) {
612 $obj = $this->db->fetch_object($result);
614 if ($country->fetch($obj->rowid) > 0) {
619 if (empty($filter) || stripos($country->label, $filter) !==
false) {
625 throw new RestException(503,
'Error when retrieving list of countries');
699 $region =
new Cregion($this->db);
701 $result = $region->fetch(
$id, (
int) $code);
703 throw new RestException(503,
'Error when retrieving region : '.$region->error);
704 } elseif ($result == 0) {
705 throw new RestException(404,
'Region not found');
724 $state =
new Cstate($this->db);
726 $result = $state->fetch(
$id, $code);
728 throw new RestException(503,
'Error when retrieving state : '.$state->error);
729 } elseif ($result == 0) {
730 throw new RestException(404,
'State not found');
753 $result = $country->fetch(
$id, $code, $iso);
756 throw new RestException(503,
'Error when retrieving country : '.$country->error);
757 } elseif ($result == 0) {
758 throw new RestException(404,
'Country not found');
786 public function getAvailability($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
790 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
791 throw new RestException(403);
794 $sql =
"SELECT rowid, code, label";
795 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_availability as t";
796 $sql .=
" WHERE t.active = ".((int) $active);
802 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
807 $sql .= $this->db->order($sortfield, $sortorder);
813 $offset = $limit * $page;
815 $sql .= $this->db->plimit($limit, $offset);
818 $result = $this->db->query($sql);
821 $num = $this->db->num_rows($result);
822 $min = min($num, ($limit <= 0 ? $num : $limit));
823 for ($i = 0; $i < $min; $i++) {
824 $list[] = $this->db->fetch_object($result);
827 throw new RestException(503, $this->db->lasterror());
864 if ($this->translations ==
null || $this->translations->getDefaultLang() !== $lang) {
867 $this->translations->setDefaultLang($lang);
868 $this->translations->loadLangs($dict);
871 $key = $prefix.$object->code;
873 $translation = $this->translations->trans($key);
874 if ($translation != $key) {
875 $object->label = html_entity_decode($translation);
901 public function getListOfEventTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $type =
'', $module =
'', $active = 1, $sqlfilters =
'')
905 $sql =
"SELECT id, code, type, libelle as label, module";
906 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_actioncomm as t";
907 $sql .=
" WHERE t.active = ".((int) $active);
909 $sql .=
" AND t.type LIKE '%".$this->db->escape($type).
"%'";
912 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
919 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
924 $sql .= $this->db->order($sortfield, $sortorder);
930 $offset = $limit * $page;
932 $sql .= $this->db->plimit($limit, $offset);
935 $result = $this->db->query($sql);
938 $num = $this->db->num_rows($result);
939 $min = min($num, ($limit <= 0 ? $num : $limit));
940 for ($i = 0; $i < $min; $i++) {
941 $list[] = $this->db->fetch_object($result);
944 throw new RestException(503,
'Error when retrieving list of events types : '.$this->db->lasterror());
970 public function getListOfExpenseReportsTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $module =
'', $active = 1, $sqlfilters =
'')
974 $sql =
"SELECT id, code, label, accountancy_code, active, module, position";
975 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees as t";
976 $sql .=
" WHERE t.active = ".((int) $active);
978 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
985 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
990 $sql .= $this->db->order($sortfield, $sortorder);
996 $offset = $limit * $page;
998 $sql .= $this->db->plimit($limit, $offset);
1001 $result = $this->db->query($sql);
1004 $num = $this->db->num_rows($result);
1005 $min = min($num, ($limit <= 0 ? $num : $limit));
1006 for ($i = 0; $i < $min; $i++) {
1007 $list[] = $this->db->fetch_object($result);
1010 throw new RestException(503,
'Error when retrieving list of expense report types : '.$this->db->lasterror());
1038 public function getListOfContactTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $type =
'', $module =
'', $active = 1, $lang =
'', $sqlfilters =
'')
1042 $sql =
"SELECT rowid, code, element as type, libelle as label, source, module, position";
1043 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact as t";
1044 $sql .=
" WHERE t.active = ".((int) $active);
1046 $sql .=
" AND t.element LIKE '%".$this->db->escape($type).
"%'";
1049 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
1055 if ($errormessage) {
1056 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1061 $sql .= $this->db->order($sortfield, $sortorder);
1067 $offset = $limit * $page;
1069 $sql .= $this->db->plimit($limit, $offset);
1072 $result = $this->db->query($sql);
1075 $num = $this->db->num_rows($result);
1076 $min = min($num, ($limit <= 0 ? $num : $limit));
1077 for ($i = 0; $i < $min; $i++) {
1078 $contact_type = $this->db->fetch_object($result);
1079 $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"));
1080 $list[] = $contact_type;
1083 throw new RestException(503,
'Error when retrieving list of contacts types : '.$this->db->lasterror());
1109 public function getListOfCivilities($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $module =
'', $active = 1, $lang =
'', $sqlfilters =
'')
1113 $sql =
"SELECT rowid, code, label, module";
1114 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_civility as t";
1115 $sql .=
" WHERE t.active = ".((int) $active);
1117 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
1123 if ($errormessage) {
1124 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1129 $sql .= $this->db->order($sortfield, $sortorder);
1135 $offset = $limit * $page;
1137 $sql .= $this->db->plimit($limit, $offset);
1140 $result = $this->db->query($sql);
1143 $num = $this->db->num_rows($result);
1144 $min = min($num, ($limit <= 0 ? $num : $limit));
1145 for ($i = 0; $i < $min; $i++) {
1146 $civility = $this->db->fetch_object($result);
1147 $this->
translateLabel($civility, $lang,
'Civility', array(
'dict'));
1148 $list[] = $civility;
1151 throw new RestException(503,
'Error when retrieving list of civility : '.$this->db->lasterror());
1176 public function getListOfCurrencies($multicurrency = 0, $sortfield =
"code_iso", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1179 $sql =
"SELECT t.code_iso, t.label, t.unicode";
1180 if (!empty($multicurrency)) {
1181 $sql .=
" , cr.date_sync, cr.rate ";
1183 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_currencies as t";
1184 if (!empty($multicurrency)) {
1185 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"multicurrency as m ON m.code=t.code_iso";
1186 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"multicurrency_rate as cr ON (m.rowid = cr.fk_multicurrency)";
1188 $sql .=
" WHERE t.active = ".((int) $active);
1189 if (!empty($multicurrency)) {
1190 $sql .=
" AND m.entity IN (".getEntity(
'multicurrency').
")";
1191 if (!empty($multicurrency) && $multicurrency != 2) {
1192 $sql .=
" AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM ".MAIN_DB_PREFIX.
"multicurrency_rate AS cr2 WHERE cr2.fk_multicurrency = m.rowid)";
1200 if ($errormessage) {
1201 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1206 $sql .= $this->db->order($sortfield, $sortorder);
1212 $offset = $limit * $page;
1214 $sql .= $this->db->plimit($limit, $offset);
1217 $result = $this->db->query($sql);
1220 $num = $this->db->num_rows($result);
1221 $min = min($num, ($limit <= 0 ? $num : $limit));
1222 for ($i = 0; $i < $min; $i++) {
1223 $list[] = $this->db->fetch_object($result);
1226 throw new RestException(503,
'Error when retrieving list of currency : '.$this->db->lasterror());
1248 public function getListOfExtrafields($sortfield =
"t.pos", $sortorder =
'ASC', $elementtype =
'', $sqlfilters =
'')
1252 if (!DolibarrApiAccess::$user->admin
1254 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');
1257 if ($elementtype ==
'thirdparty') {
1258 $elementtype =
'societe';
1260 if ($elementtype ==
'contact') {
1261 $elementtype =
'socpeople';
1264 $sql =
"SELECT t.rowid as id, t.name, t.entity, t.elementtype, t.label, t.type, t.size, t.fieldcomputed, t.fielddefault,";
1265 $sql .=
" t.fieldunique, t.fieldrequired, t.perms, t.enabled, t.pos, t.alwayseditable, t.param, t.list, t.printable,";
1266 $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";
1267 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1268 $sql .=
" WHERE t.entity IN (".getEntity(
'extrafields').
")";
1269 if (!empty($elementtype)) {
1270 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
1276 if ($errormessage) {
1277 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1281 $sql .= $this->db->order($sortfield, $sortorder);
1283 $resql = $this->db->query($sql);
1285 if ($this->db->num_rows($resql)) {
1286 while ($tab = $this->db->fetch_object($resql)) {
1288 $list[$tab->elementtype][$tab->name][
'id'] = $tab->id;
1289 $list[$tab->elementtype][$tab->name][
'type'] = $tab->type;
1290 $list[$tab->elementtype][$tab->name][
'label'] = $tab->label;
1291 $list[$tab->elementtype][$tab->name][
'size'] = $tab->size;
1292 $list[$tab->elementtype][$tab->name][
'elementtype'] = $tab->elementtype;
1293 $list[$tab->elementtype][$tab->name][
'default'] = $tab->fielddefault;
1294 $list[$tab->elementtype][$tab->name][
'computed'] = $tab->fieldcomputed;
1295 $list[$tab->elementtype][$tab->name][
'unique'] = $tab->fieldunique;
1296 $list[$tab->elementtype][$tab->name][
'required'] = $tab->fieldrequired;
1297 $list[$tab->elementtype][$tab->name][
'param'] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1298 $list[$tab->elementtype][$tab->name][
'pos'] = $tab->pos;
1299 $list[$tab->elementtype][$tab->name][
'alwayseditable'] = $tab->alwayseditable;
1300 $list[$tab->elementtype][$tab->name][
'perms'] = $tab->perms;
1301 $list[$tab->elementtype][$tab->name][
'list'] = $tab->list;
1302 $list[$tab->elementtype][$tab->name][
'printable'] = $tab->printable;
1303 $list[$tab->elementtype][$tab->name][
'totalizable'] = $tab->totalizable;
1304 $list[$tab->elementtype][$tab->name][
'langs'] = $tab->langs;
1305 $list[$tab->elementtype][$tab->name][
'help'] = $tab->help;
1306 $list[$tab->elementtype][$tab->name][
'css'] = $tab->css;
1307 $list[$tab->elementtype][$tab->name][
'cssview'] = $tab->cssview;
1308 $list[$tab->elementtype][$tab->name][
'csslist'] = $tab->csslist;
1309 $list[$tab->elementtype][$tab->name][
'fk_user_author'] = $tab->fk_user_author;
1310 $list[$tab->elementtype][$tab->name][
'fk_user_modif'] = $tab->fk_user_modif;
1311 $list[$tab->elementtype][$tab->name][
'datec'] = $tab->datec;
1312 $list[$tab->elementtype][$tab->name][
'tms'] = $tab->tms;
1316 throw new RestException(503,
'Error when retrieving list of extra fields : '.$this->db->lasterror());
1335 if (!DolibarrApiAccess::$user->admin) {
1336 throw new RestException(403,
'Only an admin user can delete an extrafield by attrname and elementtype');
1341 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1343 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1346 if (!$extrafields->delete($attrname, $elementtype)) {
1347 throw new RestException(500,
'Error when delete extrafield : '.$extrafields->error);
1353 'message' =>
'Extrafield deleted from attrname and elementtype'
1376 if (!DolibarrApiAccess::$user->admin) {
1377 throw new RestException(403,
'Only an admin user can get list of extrafields');
1380 if ($elementtype ==
'thirdparty') {
1381 $elementtype =
'societe';
1383 if ($elementtype ==
'contact') {
1384 $elementtype =
'socpeople';
1387 $sql =
"SELECT t.rowid as id, t.name, t.entity, t.elementtype, t.label, t.type, t.size, t.fieldcomputed, t.fielddefault,";
1388 $sql .=
" t.fieldunique, t.fieldrequired, t.perms, t.enabled, t.pos, t.alwayseditable, t.param, t.list, t.printable,";
1389 $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";
1390 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1391 $sql .=
" WHERE t.entity IN (".getEntity(
'extrafields').
")";
1392 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
1393 $sql .=
" AND t.name = '".$this->db->escape($attrname).
"'";
1395 $resql = $this->db->query($sql);
1397 if ($this->db->num_rows($resql)) {
1398 while ($tab = $this->db->fetch_object($resql)) {
1400 $answer[$tab->elementtype][$tab->name][
'id'] = $tab->id;
1401 $answer[$tab->elementtype][$tab->name][
'type'] = $tab->type;
1402 $answer[$tab->elementtype][$tab->name][
'label'] = $tab->label;
1403 $answer[$tab->elementtype][$tab->name][
'size'] = $tab->size;
1404 $answer[$tab->elementtype][$tab->name][
'elementtype'] = $tab->elementtype;
1405 $answer[$tab->elementtype][$tab->name][
'default'] = $tab->fielddefault;
1406 $answer[$tab->elementtype][$tab->name][
'computed'] = $tab->fieldcomputed;
1407 $answer[$tab->elementtype][$tab->name][
'unique'] = $tab->fieldunique;
1408 $answer[$tab->elementtype][$tab->name][
'required'] = $tab->fieldrequired;
1409 $answer[$tab->elementtype][$tab->name][
'param'] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1410 $answer[$tab->elementtype][$tab->name][
'pos'] = $tab->pos;
1411 $answer[$tab->elementtype][$tab->name][
'alwayseditable'] = $tab->alwayseditable;
1412 $answer[$tab->elementtype][$tab->name][
'perms'] = $tab->perms;
1413 $answer[$tab->elementtype][$tab->name][
'list'] = $tab->list;
1414 $answer[$tab->elementtype][$tab->name][
'printable'] = $tab->printable;
1415 $answer[$tab->elementtype][$tab->name][
'totalizable'] = $tab->totalizable;
1416 $answer[$tab->elementtype][$tab->name][
'langs'] = $tab->langs;
1417 $answer[$tab->elementtype][$tab->name][
'help'] = $tab->help;
1418 $answer[$tab->elementtype][$tab->name][
'css'] = $tab->css;
1419 $answer[$tab->elementtype][$tab->name][
'cssview'] = $tab->cssview;
1420 $answer[$tab->elementtype][$tab->name][
'csslist'] = $tab->csslist;
1421 $answer[$tab->elementtype][$tab->name][
'fk_user_author'] = $tab->fk_user_author;
1422 $answer[$tab->elementtype][$tab->name][
'fk_user_modif'] = $tab->fk_user_modif;
1423 $answer[$tab->elementtype][$tab->name][
'datec'] = $tab->datec;
1424 $answer[$tab->elementtype][$tab->name][
'tms'] = $tab->tms;
1427 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1430 throw new RestException(503,
'Error when retrieving list of extra fields : '.$this->db->lasterror());
1452 if (!DolibarrApiAccess::$user->admin) {
1453 throw new RestException(403,
'Only an admin user can create an extrafield');
1458 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1460 throw new RestException(409,
'Duplicate extrafield already found from attrname and elementtype');
1466 foreach ($request_data as $field => $value) {
1467 $extrafields->$field = $this->
_checkValForAPI($field, $value, $extrafields);
1470 $entity = DolibarrApiAccess::$user->entity;
1471 if (empty($entity)) {
1478 if ($request_data[
'label']) {
1479 $label = $request_data[
'label'];
1481 throw new RestException(400,
"label field absent in json at root level");
1484 $alwayseditable = $request_data[
'alwayseditable'];
1485 $default_value = $request_data[
'default'];
1486 $totalizable = $request_data[
'totalizable'];
1487 $printable = $request_data[
'printable'];
1488 $required = $request_data[
'required'];
1489 $langfile = $request_data[
'langfile'];
1490 $computed = $request_data[
'computed'];
1491 $unique = $request_data[
'unique'];
1492 $param = $request_data[
'param'];
1493 $perms = $request_data[
'perms'];
1494 $size = $request_data[
'size'];
1495 $type = $request_data[
'type'];
1496 $list = $request_data[
'list'];
1497 $help = $request_data[
'help'];
1498 $pos = $request_data[
'pos'];
1499 $moreparams = array();
1501 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)) {
1502 throw new RestException(500,
'Error creating extrafield', array_merge(array($extrafields->errno), $extrafields->errors));
1505 $sql =
"SELECT t.rowid as id";
1506 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1507 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1508 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1510 $resql = $this->db->query($sql);
1512 if ($this->db->num_rows($resql)) {
1513 $tab = $this->db->fetch_object($resql);
1514 $id = (int) $tab->id;
1541 if (!DolibarrApiAccess::$user->admin) {
1542 throw new RestException(403,
'Only an admin user can create an extrafield');
1547 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1549 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1552 foreach ($request_data as $field => $value) {
1553 $extrafields->$field = $this->
_checkValForAPI($field, $value, $extrafields);
1556 $entity = DolibarrApiAccess::$user->entity;
1557 if (empty($entity)) {
1563 if ($request_data[
'label']) {
1564 $label = $request_data[
'label'];
1566 throw new RestException(400,
"label field absent in json at root level");
1569 $alwayseditable = $request_data[
'alwayseditable'];
1570 $default_value = $request_data[
'default'];
1571 $totalizable = $request_data[
'totalizable'];
1572 $printable = $request_data[
'printable'];
1573 $required = $request_data[
'required'];
1574 $langfile = $request_data[
'langfile'];
1575 $computed = $request_data[
'computed'];
1576 $unique = $request_data[
'unique'];
1577 $param = $request_data[
'param'];
1578 $perms = $request_data[
'perms'];
1579 $size = $request_data[
'size'];
1580 $type = $request_data[
'type'];
1581 $list = $request_data[
'list'];
1582 $help = $request_data[
'help'];
1583 $pos = $request_data[
'pos'];
1584 $moreparams = array();
1586 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)) {
1587 throw new RestException(500,
'Error updating extrafield', array_merge(array($extrafields->errno), $extrafields->errors));
1590 $sql =
"SELECT t.rowid as id";
1591 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1592 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1593 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1595 $resql = $this->db->query($sql);
1597 if ($this->db->num_rows($resql)) {
1598 $tab = $this->db->fetch_object($resql);
1599 $id = (int) $tab->id;
1630 public function getListOfTowns($sortfield =
"zip,town", $sortorder =
'ASC', $limit = 100, $page = 0, $zipcode =
'', $town =
'', $active = 1, $sqlfilters =
'')
1634 $sql =
"SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
1635 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ziptown as t";
1636 $sql .=
" WHERE t.active = ".((int) $active);
1638 $sql .=
" AND t.zip LIKE '%".$this->db->escape($zipcode).
"%'";
1641 $sql .=
" AND t.town LIKE '%".$this->db->escape($town).
"%'";
1647 if ($errormessage) {
1648 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1653 $sql .= $this->db->order($sortfield, $sortorder);
1659 $offset = $limit * $page;
1661 $sql .= $this->db->plimit($limit, $offset);
1664 $result = $this->db->query($sql);
1667 $num = $this->db->num_rows($result);
1668 $min = min($num, ($limit <= 0 ? $num : $limit));
1669 for ($i = 0; $i < $min; $i++) {
1670 $list[] = $this->db->fetch_object($result);
1673 throw new RestException(503,
'Error when retrieving list of towns : '.$this->db->lasterror());
1699 public function getPaymentTerms($sortfield =
"sortorder", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1703 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire') && !DolibarrApiAccess::$user->hasRight(
'commande',
'lire') && !DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1704 throw new RestException(403);
1707 $sql =
"SELECT rowid as id, code, sortorder, libelle as label, libelle_facture as descr, type_cdr, nbjour, decalage, module";
1708 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_payment_term as t";
1709 $sql .=
" WHERE t.entity IN (".getEntity(
'c_payment_term').
")";
1710 $sql .=
" AND t.active = ".((int) $active);
1715 if ($errormessage) {
1716 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1721 $sql .= $this->db->order($sortfield, $sortorder);
1727 $offset = $limit * $page;
1729 $sql .= $this->db->plimit($limit, $offset);
1732 $result = $this->db->query($sql);
1735 $num = $this->db->num_rows($result);
1736 $min = min($num, ($limit <= 0 ? $num : $limit));
1737 for ($i = 0; $i < $min; $i++) {
1738 $list[] = $this->db->fetch_object($result);
1741 throw new RestException(503, $this->db->lasterror());
1765 public function getShippingModes($limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
1769 $sql =
"SELECT rowid as id, code, libelle as label, description, tracking, module";
1770 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as t";
1771 $sql .=
" WHERE t.entity IN (".getEntity(
'c_shipment_mode').
")";
1772 $sql .=
" AND t.active = ".((int) $active);
1777 if ($errormessage) {
1778 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1789 $offset = $limit * $page;
1791 $sql .= $this->db->plimit($limit, $offset);
1794 $result = $this->db->query($sql);
1797 $num = $this->db->num_rows($result);
1798 $min = min($num, ($limit <= 0 ? $num : $limit));
1799 for ($i = 0; $i < $min; $i++) {
1800 $method = $this->db->fetch_object($result);
1805 throw new RestException(503, $this->db->lasterror());
1829 public function getListOfMeasuringUnits($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1833 $sql =
"SELECT t.rowid, t.code, t.label,t.short_label, t.active, t.scale, t.unit_type";
1834 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_units as t";
1835 $sql .=
" WHERE t.active = ".((int) $active);
1840 if ($errormessage) {
1841 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1846 $sql .= $this->db->order($sortfield, $sortorder);
1852 $offset = $limit * $page;
1854 $sql .= $this->db->plimit($limit, $offset);
1857 $result = $this->db->query($sql);
1860 $num = $this->db->num_rows($result);
1861 $min = min($num, ($limit <= 0 ? $num : $limit));
1862 for ($i = 0; $i < $min; $i++) {
1863 $list[] = $this->db->fetch_object($result);
1866 throw new RestException(503,
'Error when retrieving list of measuring units: '.$this->db->lasterror());
1891 public function getListOfLegalForm($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $active = 1, $sqlfilters =
'')
1895 $sql =
"SELECT t.rowid, t.code, t.fk_pays, t.libelle, t.isvatexempted, t.active, t.module, t.position";
1896 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_forme_juridique as t";
1897 $sql .=
" WHERE t.active = ".((int) $active);
1899 $sql .=
" AND t.fk_pays = ".((int) $country);
1905 if ($errormessage) {
1906 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1911 $sql .= $this->db->order($sortfield, $sortorder);
1917 $offset = $limit * $page;
1919 $sql .= $this->db->plimit($limit, $offset);
1922 $result = $this->db->query($sql);
1925 $num = $this->db->num_rows($result);
1926 $min = min($num, ($limit <= 0 ? $num : $limit));
1927 for ($i = 0; $i < $min; $i++) {
1928 $list[] = $this->db->fetch_object($result);
1931 throw new RestException(503,
'Error when retrieving list of legal form: '.$this->db->lasterror());
1955 public function getListOfStaff($sortfield =
"id", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1959 $sql =
"SELECT t.id, t.code, t.libelle, t.active, t.module";
1960 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_effectif as t";
1961 $sql .=
" WHERE t.active = ".((int) $active);
1966 if ($errormessage) {
1967 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1972 $sql .= $this->db->order($sortfield, $sortorder);
1978 $offset = $limit * $page;
1980 $sql .= $this->db->plimit($limit, $offset);
1983 $result = $this->db->query($sql);
1986 $num = $this->db->num_rows($result);
1987 $min = min($num, ($limit <= 0 ? $num : $limit));
1988 for ($i = 0; $i < $min; $i++) {
1989 $list[] = $this->db->fetch_object($result);
1992 throw new RestException(503,
'Error when retrieving list of staff: '.$this->db->lasterror());
2016 public function getListOfsocialNetworks($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
2020 if (!isModEnabled(
'socialnetworks')) {
2021 throw new RestException(400,
'API not available: this dictionary is not enabled by setup');
2026 $sql =
"SELECT t.rowid, t.entity, t.code, t.label, t.url, t.icon, t.active";
2027 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_socialnetworks as t";
2028 $sql .=
" WHERE t.entity IN (".getEntity(
'c_socialnetworks').
")";
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 $list[] = $this->db->fetch_object($result);
2060 throw new RestException(503,
'Error when retrieving list of social networks: '.$this->db->lasterror());
2085 public function getTicketsCategories($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2089 $sql =
"SELECT rowid, code, pos, label, use_default, description";
2090 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_category as t";
2091 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_category').
")";
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 $category = $this->db->fetch_object($result);
2121 $this->
translateLabel($category, $lang,
'TicketCategoryShort', array(
'ticket'));
2122 $list[] = $category;
2125 throw new RestException(503,
'Error when retrieving list of ticket categories : '.$this->db->lasterror());
2150 public function getTicketsSeverities($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2154 $sql =
"SELECT rowid, code, pos, label, use_default, color, description";
2155 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_severity as t";
2156 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_severity').
")";
2157 $sql .=
" AND t.active = ".((int) $active);
2162 if ($errormessage) {
2163 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2168 $sql .= $this->db->order($sortfield, $sortorder);
2174 $offset = $limit * $page;
2176 $sql .= $this->db->plimit($limit, $offset);
2179 $result = $this->db->query($sql);
2182 $num = $this->db->num_rows($result);
2183 $min = min($num, ($limit <= 0 ? $num : $limit));
2184 for ($i = 0; $i < $min; $i++) {
2185 $severity = $this->db->fetch_object($result);
2186 $this->
translateLabel($severity, $lang,
'TicketSeverityShort', array(
'ticket'));
2187 $list[] = $severity;
2190 throw new RestException(503,
'Error when retrieving list of ticket severities : '.$this->db->lasterror());
2215 public function getTicketsTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2219 $sql =
"SELECT rowid, code, pos, label, use_default, description";
2220 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_type as t";
2221 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_type').
")";
2222 $sql .=
" AND t.active = ".((int) $active);
2228 if ($errormessage) {
2229 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2234 $sql .= $this->db->order($sortfield, $sortorder);
2240 $offset = $limit * $page;
2242 $sql .= $this->db->plimit($limit, $offset);
2245 $result = $this->db->query($sql);
2248 $num = $this->db->num_rows($result);
2249 $min = min($num, ($limit <= 0 ? $num : $limit));
2250 for ($i = 0; $i < $min; $i++) {
2251 $type = $this->db->fetch_object($result);
2252 $this->
translateLabel($type, $lang,
'TicketTypeShort', array(
'ticket'));
2256 throw new RestException(503,
'Error when retrieving list of ticket types : '.$this->db->lasterror());
2280 public function getListOfIncoterms($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2284 $sql =
"SELECT rowid, code, active";
2285 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_incoterms as t";
2286 $sql .=
" WHERE 1=1";
2292 if ($errormessage) {
2293 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2298 $sql .= $this->db->order($sortfield, $sortorder);
2304 $offset = $limit * $page;
2306 $sql .= $this->db->plimit($limit, $offset);
2309 $result = $this->db->query($sql);
2312 $num = $this->db->num_rows($result);
2313 $min = min($num, ($limit <= 0 ? $num : $limit));
2314 for ($i = 0; $i < $min; $i++) {
2315 $type = $this->db->fetch_object($result);
2319 throw new RestException(503,
'Error when retrieving list of incoterm types : '.$this->db->lasterror());
2338 global
$conf, $mysoc;
2340 if (!DolibarrApiAccess::$user->admin
2342 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');
2345 unset($mysoc->pays);
2346 unset($mysoc->note);
2349 unset($mysoc->lines);
2351 unset($mysoc->effectif);
2352 unset($mysoc->effectif_id);
2353 unset($mysoc->forme_juridique_code);
2354 unset($mysoc->forme_juridique);
2355 unset($mysoc->mode_reglement_supplier_id);
2356 unset($mysoc->cond_reglement_supplier_id);
2357 unset($mysoc->transport_mode_supplier_id);
2358 unset($mysoc->fk_prospectlevel);
2360 unset($mysoc->total_ht);
2361 unset($mysoc->total_tva);
2362 unset($mysoc->total_localtax1);
2363 unset($mysoc->total_localtax2);
2364 unset($mysoc->total_ttc);
2366 unset($mysoc->lastname);
2367 unset($mysoc->firstname);
2368 unset($mysoc->civility_id);
2370 unset($mysoc->client);
2371 unset($mysoc->prospect);
2372 unset($mysoc->fournisseur);
2373 unset($mysoc->contact_id);
2375 unset($mysoc->fk_incoterms);
2376 unset($mysoc->label_incoterms);
2377 unset($mysoc->location_incoterms);
2399 $sql =
"SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
2400 $sql .=
" FROM ".MAIN_DB_PREFIX.
"establishment as e";
2401 $sql .=
" WHERE e.entity IN (".getEntity(
'establishment').
')';
2406 $result = $this->db->query($sql);
2409 $num = $this->db->num_rows($result);
2410 $min = min($num, ($limit <= 0 ? $num : $limit));
2411 for ($i = 0; $i < $min; $i++) {
2412 $list[] = $this->db->fetch_object($result);
2415 throw new RestException(503,
'Error when retrieving list of establishments : '.$this->db->lasterror());
2436 $result = $establishment->fetch(
$id);
2438 throw new RestException(503,
'Error when retrieving establishment : '.$establishment->error);
2439 } elseif ($result == 0) {
2440 throw new RestException(404,
'Establishment not found');
2463 if (!DolibarrApiAccess::$user->admin
2465 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');
2468 if (!preg_match(
'/^[a-zA-Z0-9_]+$/', $constantname) || !isset(
$conf->global->$constantname)) {
2469 throw new RestException(400,
'Error Bad or unknown value for constantname');
2472 throw new RestException(403,
'Forbidden. This parameter can not be read with APIs');
2497 if (!DolibarrApiAccess::$user->admin
2499 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');
2502 $sql =
"select name, value";
2503 $sql .=
" FROM ".MAIN_DB_PREFIX.
"const";
2504 $sql .=
" WHERE entity IN (".getEntity(
'const').
')';
2506 $result = $this->db->query($sql);
2509 $num = $this->db->num_rows($result);
2510 for ($i = 0; $i < $num; $i++) {
2511 $obj = $this->db->fetch_object($result);
2514 $list[$obj->name] = $obj->value;
2518 throw new RestException(503,
'Error when retrieving list of const : '.$this->db->lasterror());
2540 global $langs,
$conf;
2542 if (!DolibarrApiAccess::$user->admin
2544 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');
2547 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2548 require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
2550 $langs->load(
"admin");
2552 $outexpectedchecksum =
'';
2553 $outcurrentchecksum =
'';
2556 $file_list = array(
'missing' => array(),
'updated' => array());
2561 $xmlfile = DOL_DOCUMENT_ROOT.
'/install/'.$xmlshortfile;
2562 if (!preg_match(
'/\.zip$/i', $xmlfile) &&
dol_is_file($xmlfile.
'.zip')) {
2567 $xmlremote = (($target ==
'default' || $target ==
'local') ?
'' : $target);
2571 $param =
'MAIN_FILECHECK_URL_'.DOL_VERSION;
2575 if (empty($xmlremote)) {
2576 $xmlremote =
'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.
'.xml';
2578 if ($xmlremote && !preg_match(
'/^https?:\/\//i', $xmlremote)) {
2579 $langs->load(
"errors");
2580 throw new RestException(500, $langs->trans(
"ErrorURLMustStartWithHttp", $xmlremote));
2582 if ($xmlremote && !preg_match(
'/\.xml$/', $xmlremote)) {
2583 $langs->load(
"errors");
2584 throw new RestException(500, $langs->trans(
"ErrorURLMustEndWith", $xmlremote,
'.xml'));
2587 if (LIBXML_VERSION < 20900) {
2591 libxml_disable_entity_loader(
true);
2594 if ($target ==
'local') {
2596 $xml = simplexml_load_file($xmlfile);
2598 throw new RestException(500, $langs->trans(
'XmlNotFound').
': /install/'.$xmlshortfile);
2601 $xmlarray =
getURLContent($xmlremote,
'GET',
'', 1, array(), array(
'http',
'https'), 0);
2604 if (!$xmlarray[
'curl_error_no'] && $xmlarray[
'http_code'] != 400 && $xmlarray[
'http_code'] != 404) {
2605 $xmlfile = $xmlarray[
'content'];
2607 $xml = simplexml_load_string($xmlfile,
'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NONET);
2609 $errormsg = $langs->trans(
'XmlNotFound').
': '.$xmlremote.
' - '.$xmlarray[
'http_code'].(($xmlarray[
'http_code'] == 400 && $xmlarray[
'content']) ?
' '.$xmlarray[
'content'] :
'').
' '.$xmlarray[
'curl_error_no'].
' '.$xmlarray[
'curl_error_msg'];
2610 throw new RestException(500, $errormsg);
2615 $checksumconcat = array();
2616 $file_list = array();
2620 if (is_object($xml->dolibarr_constants[0])) {
2623 $out .=
'<div class="div-table-responsive-no-min">';
2624 $out .=
'<table class="noborder">';
2625 $out .=
'<tr class="liste_titre">';
2626 $out .=
'<td>#</td>';
2627 $out .=
'<td>'.$langs->trans(
"Constant").
'</td>';
2628 $out .=
'<td class="center">'.$langs->trans(
"ExpectedValue").
'</td>';
2629 $out .=
'<td class="center">'.$langs->trans(
"Value").
'</td>';
2630 $out .=
'</tr>'.
"\n";
2633 foreach ($xml->dolibarr_constants[0]->constant as $constant) {
2634 $constname = $constant[
'name'];
2635 $constvalue = (string) $constant;
2636 $constvalue = (empty($constvalue) ?
'0' : $constvalue);
2642 $valueforchecksum = (empty($value) ?
'0' : $value);
2644 $checksumconcat[] = $valueforchecksum;
2647 $out .=
'<tr class="oddeven">';
2648 $out .=
'<td>'.$i.
'</td>'.
"\n";
2649 $out .=
'<td>'.dol_escape_htmltag($constname).
'</td>'.
"\n";
2650 $out .=
'<td class="center">'.dol_escape_htmltag($constvalue).
'</td>'.
"\n";
2651 $out .=
'<td class="center">'.dol_escape_htmltag($valueforchecksum).
'</td>'.
"\n";
2656 $out .=
'<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2665 if (is_object($xml->dolibarr_htdocs_dir[0])) {
2666 $includecustom = (empty($xml->dolibarr_htdocs_dir[0][
'includecustom']) ? 0 : $xml->dolibarr_htdocs_dir[0][
'includecustom']);
2669 $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)$';
2670 $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)$';
2671 $scanfiles =
dol_dir_list(DOL_DOCUMENT_ROOT,
'files', 1, $regextoinclude, $regextoexclude);
2674 $ret =
getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0],
'', DOL_DOCUMENT_ROOT, $checksumconcat);
2675 '@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';
2677 foreach ($scanfiles as $keyfile => $valfile) {
2678 $tmprelativefilename = preg_replace(
'/^'.preg_quote(DOL_DOCUMENT_ROOT,
'/').
'/',
'', $valfile[
'fullname']);
2679 if (!in_array($tmprelativefilename, $file_list[
'insignature'])) {
2680 $md5newfile = @md5_file($valfile[
'fullname']);
2681 $file_list[
'added'][] = array(
'filename' => $tmprelativefilename,
'md5' => $md5newfile);
2688 $out .=
'<div class="div-table-responsive-no-min">';
2689 $out .=
'<table class="noborder">';
2690 $out .=
'<tr class="liste_titre">';
2691 $out .=
'<td>#</td>';
2692 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2693 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2694 $out .=
'</tr>'.
"\n";
2695 $tmpfilelist =
dol_sort_array($file_list[
'missing'],
'filename');
2696 if (is_array($tmpfilelist) && count($tmpfilelist)) {
2698 foreach ($tmpfilelist as $file) {
2700 $out .=
'<tr class="oddeven">';
2701 $out .=
'<td>'.$i.
'</td>'.
"\n";
2702 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2703 $out .=
'<td class="center">'.(array_key_exists(
'expectedmd5', $file) ? $file[
'expectedmd5'] :
'').
'</td>'.
"\n";
2707 $out .=
'<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2718 $out .=
'<div class="div-table-responsive-no-min">';
2719 $out .=
'<table class="noborder">';
2720 $out .=
'<tr class="liste_titre">';
2721 $out .=
'<td>#</td>';
2722 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2723 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2724 $out .=
'<td class="center">'.$langs->trans(
"CurrentChecksum").
'</td>';
2725 $out .=
'<td class="right">'.$langs->trans(
"Size").
'</td>';
2726 $out .=
'<td class="right">'.$langs->trans(
"DateModification").
'</td>';
2727 $out .=
'</tr>'.
"\n";
2728 $tmpfilelist2 =
dol_sort_array($file_list[
'updated'],
'filename');
2729 if (is_array($tmpfilelist2) && count($tmpfilelist2)) {
2731 foreach ($tmpfilelist2 as $file) {
2733 $out .=
'<tr class="oddeven">';
2734 $out .=
'<td>'.$i.
'</td>'.
"\n";
2735 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2736 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2737 $out .=
'<td class="center">'.$file[
'md5'].
'</td>'.
"\n";
2738 $size =
dol_filesize(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']);
2739 $totalsize += $size;
2740 $out .=
'<td class="right">'.dol_print_size($size).
'</td>'.
"\n";
2741 $out .=
'<td class="right">'.dol_print_date(
dol_filemtime(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']),
'dayhour').
'</td>'.
"\n";
2744 $out .=
'<tr class="liste_total">';
2745 $out .=
'<td></td>'.
"\n";
2746 $out .=
'<td>'.$langs->trans(
"Total").
'</td>'.
"\n";
2747 $out .=
'<td align="center"></td>'.
"\n";
2748 $out .=
'<td align="center"></td>'.
"\n";
2749 $out .=
'<td class="right">'.dol_print_size($totalsize).
'</td>'.
"\n";
2750 $out .=
'<td class="right"></td>'.
"\n";
2753 $out .=
'<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2764 $out .=
'<div class="div-table-responsive-no-min">';
2765 $out .=
'<table class="noborder">';
2766 $out .=
'<tr class="liste_titre">';
2767 $out .=
'<td>#</td>';
2768 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2769 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2770 $out .=
'<td class="center">'.$langs->trans(
"CurrentChecksum").
'</td>';
2771 $out .=
'<td class="right">'.$langs->trans(
"Size").
'</td>';
2772 $out .=
'<td class="right">'.$langs->trans(
"DateModification").
'</td>';
2773 $out .=
'</tr>'.
"\n";
2775 if (is_array($tmpfilelist3) && count($tmpfilelist3)) {
2777 foreach ($tmpfilelist3 as $file) {
2779 $out .=
'<tr class="oddeven">';
2780 $out .=
'<td>'.$i.
'</td>'.
"\n";
2781 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2782 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2783 $out .=
'<td class="center">'.$file[
'md5'].
'</td>'.
"\n";
2784 $size =
dol_filesize(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']);
2785 $totalsize += $size;
2786 $out .=
'<td class="right">'.dol_print_size($size).
'</td>'.
"\n";
2787 $out .=
'<td class="right">'.dol_print_date(
dol_filemtime(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']),
'dayhour').
'</td>'.
"\n";
2790 $out .=
'<tr class="liste_total">';
2791 $out .=
'<td></td>'.
"\n";
2792 $out .=
'<td>'.$langs->trans(
"Total").
'</td>'.
"\n";
2793 $out .=
'<td align="center"></td>'.
"\n";
2794 $out .=
'<td align="center"></td>'.
"\n";
2795 $out .=
'<td class="right">'.dol_print_size($totalsize).
'</td>'.
"\n";
2796 $out .=
'<td class="right"></td>'.
"\n";
2799 $out .=
'<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2806 if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) {
2812 throw new RestException(500,
'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile);
2817 asort($checksumconcat);
2818 $checksumget = md5(implode(
',', $checksumconcat));
2819 $checksumtoget = trim((
string) $xml->dolibarr_htdocs_dir_checksum);
2821 $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans(
"Unknown"));
2822 if ($checksumget == $checksumtoget) {
2823 if (count($file_list[
'added'])) {
2824 $resultcode =
'warning';
2825 $resultcomment =
'FileIntegrityIsOkButFilesWereAdded';
2827 $outcurrentchecksum = $checksumget;
2830 $resultcomment =
'Success';
2832 $outcurrentchecksum = $checksumget;
2835 $resultcode =
'error';
2836 $resultcomment =
'Error';
2838 $outcurrentchecksum = $checksumget;
2841 throw new RestException(404,
'No signature file known');
2844 return array(
'resultcode' => $resultcode,
'resultcomment' => $resultcomment,
'expectedchecksum' => $outexpectedchecksum,
'currentchecksum' => $outcurrentchecksum,
'out' => $out);
2863 if (!DolibarrApiAccess::$user->admin
2865 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');
2868 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)
_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...