26use Luracast\Restler\RestException;
28require_once DOL_DOCUMENT_ROOT.
'/main.inc.php';
29require_once DOL_DOCUMENT_ROOT.
'/api/class/api.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/cstate.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/cregion.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/class/ccountry.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/hrm/class/establishment.class.php';
46 private $translations =
null;
75 public function getListOfActionTriggers($sortfield =
"t.rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $elementtype =
'', $lang =
'', $sqlfilters =
'')
79 if ($elementtype ==
'thirdparty') {
80 $elementtype =
'societe';
82 if ($elementtype ==
'contact') {
83 $elementtype =
'socpeople';
86 $sql =
"SELECT t.rowid as id, t.elementtype, t.code, t.contexts, t.label, t.description, t.rang";
87 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_action_trigger as t";
88 if (!empty($elementtype)) {
89 $sql .=
" WHERE t.elementtype = '".$this->db->escape($elementtype).
"'";
96 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
100 $sql .= $this->db->order($sortfield, $sortorder);
106 $offset = $limit * $page;
108 $sql .= $this->db->plimit($limit, $offset);
111 $result = $this->db->query($sql);
113 $num = $this->db->num_rows($result);
114 $min = min($num, ($limit <= 0 ? $num : $limit));
115 for ($i = 0; $i < $min; $i++) {
116 $type = $this->db->fetch_object($result);
121 throw new RestException(503,
'Error when retrieving list of action triggers : '.$this->db->lasterror());
145 public function getOrderingMethods($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
149 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
150 throw new RestException(403);
153 $sql =
"SELECT rowid, code, libelle as label, module";
154 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_input_method as t";
155 $sql .=
" WHERE t.active = ".((int) $active);
161 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
166 $sql .= $this->db->order($sortfield, $sortorder);
172 $offset = $limit * $page;
174 $sql .= $this->db->plimit($limit, $offset);
177 $result = $this->db->query($sql);
180 $num = $this->db->num_rows($result);
181 $min = min($num, ($limit <= 0 ? $num : $limit));
182 for ($i = 0; $i < $min; $i++) {
183 $list[] = $this->db->fetch_object($result);
186 throw new RestException(503, $this->db->lasterror());
209 public function getOrderingOrigins($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
213 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
214 throw new RestException(403);
217 $sql =
"SELECT rowid, code, label, module";
218 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_input_reason as t";
219 $sql .=
" WHERE t.active = ".((int) $active);
225 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
230 $sql .= $this->db->order($sortfield, $sortorder);
236 $offset = $limit * $page;
238 $sql .= $this->db->plimit($limit, $offset);
241 $result = $this->db->query($sql);
244 $num = $this->db->num_rows($result);
245 $min = min($num, ($limit <= 0 ? $num : $limit));
246 for ($i = 0; $i < $min; $i++) {
247 $list[] = $this->db->fetch_object($result);
250 throw new RestException(503, $this->db->lasterror());
274 public function getPaymentTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
278 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire') && !DolibarrApiAccess::$user->hasRight(
'commande',
'lire') && !DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
279 throw new RestException(403);
282 $sql =
"SELECT id, code, type, libelle as label, module";
283 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_paiement as t";
284 $sql .=
" WHERE t.entity IN (".getEntity(
'c_paiement').
")";
285 $sql .=
" AND t.active = ".((int) $active);
291 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
296 $sql .= $this->db->order($sortfield, $sortorder);
302 $offset = $limit * $page;
304 $sql .= $this->db->plimit($limit, $offset);
307 $result = $this->db->query($sql);
310 $num = $this->db->num_rows($result);
311 $min = min($num, ($limit <= 0 ? $num : $limit));
312 for ($i = 0; $i < $min; $i++) {
313 $list[] = $this->db->fetch_object($result);
316 throw new RestException(503, $this->db->lasterror());
340 public function getListOfRegions($sortfield =
"code_region", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $filter =
'', $sqlfilters =
'')
346 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.
"c_regions as t";
347 $sql .=
" WHERE 1 = 1";
349 $sql .=
" AND t.fk_pays = ".((int) $country);
355 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
357 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
358 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
361 $sql .= $this->db->order($sortfield, $sortorder);
367 $offset = $limit * $page;
369 $sql .= $this->db->plimit($limit, $offset);
372 $result = $this->db->query($sql);
375 $num = $this->db->num_rows($result);
376 $min = min($num, ($limit <= 0 ? $num : $limit));
377 for ($i = 0; $i < $min; $i++) {
378 $obj = $this->db->fetch_object($result);
379 $region =
new Cregion($this->db);
380 if ($region->fetch($obj->rowid) > 0) {
381 if (empty($filter) || stripos($region->name, $filter) !==
false) {
387 throw new RestException(503,
'Error when retrieving list of regions');
447 public function getListOfStates($sortfield =
"code_departement", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $filter =
'', $sqlfilters =
'')
453 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.
"c_departements as t";
455 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as d ON t.fk_region = d.code_region";
457 $sql .=
" WHERE 1 = 1";
459 $sql .=
" AND d.fk_pays = ".((int) $country);
466 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
470 $sql .= $this->db->order($sortfield, $sortorder);
476 $offset = $limit * $page;
478 $sql .= $this->db->plimit($limit, $offset);
481 $result = $this->db->query($sql);
484 $num = $this->db->num_rows($result);
485 $min = min($num, ($limit <= 0 ? $num : $limit));
486 for ($i = 0; $i < $min; $i++) {
487 $obj = $this->db->fetch_object($result);
488 $state =
new Cstate($this->db);
489 if ($state->fetch($obj->rowid) > 0) {
490 if (empty($filter) || stripos($state->label, $filter) !==
false) {
496 throw new RestException(503,
'Error when retrieving list of states');
556 public function getListOfCountries($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $filter =
'', $lang =
'', $sqlfilters =
'')
562 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"c_country as t";
563 $sql .=
" WHERE 1 = 1";
569 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
573 $sql .= $this->db->order($sortfield, $sortorder);
579 $offset = $limit * $page;
581 $sql .= $this->db->plimit($limit, $offset);
584 $result = $this->db->query($sql);
587 $num = $this->db->num_rows($result);
588 $min = min($num, ($limit <= 0 ? $num : $limit));
589 for ($i = 0; $i < $min; $i++) {
590 $obj = $this->db->fetch_object($result);
592 if ($country->fetch($obj->rowid) > 0) {
597 if (empty($filter) || stripos($country->label, $filter) !==
false) {
603 throw new RestException(503,
'Error when retrieving list of countries');
671 $region =
new Cregion($this->db);
673 $result = $region->fetch(
$id, $code);
675 throw new RestException(503,
'Error when retrieving region : '.$region->error);
676 } elseif ($result == 0) {
677 throw new RestException(404,
'Region not found');
694 $state =
new Cstate($this->db);
696 $result = $state->fetch(
$id, $code);
698 throw new RestException(503,
'Error when retrieving state : '.$state->error);
699 } elseif ($result == 0) {
700 throw new RestException(404,
'State not found');
721 $result = $country->fetch(
$id, $code, $iso);
724 throw new RestException(503,
'Error when retrieving country : '.$country->error);
725 } elseif ($result == 0) {
726 throw new RestException(404,
'Country not found');
752 public function getAvailability($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
756 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
757 throw new RestException(403);
760 $sql =
"SELECT rowid, code, label";
761 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_availability as t";
762 $sql .=
" WHERE t.active = ".((int) $active);
768 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
773 $sql .= $this->db->order($sortfield, $sortorder);
779 $offset = $limit * $page;
781 $sql .= $this->db->plimit($limit, $offset);
784 $result = $this->db->query($sql);
787 $num = $this->db->num_rows($result);
788 $min = min($num, ($limit <= 0 ? $num : $limit));
789 for ($i = 0; $i < $min; $i++) {
790 $list[] = $this->db->fetch_object($result);
793 throw new RestException(503, $this->db->lasterror());
830 if ($this->translations ==
null || $this->translations->getDefaultLang() !== $lang) {
832 $this->translations =
new Translate(
'', $conf);
833 $this->translations->setDefaultLang($lang);
834 $this->translations->loadLangs($dict);
837 $key = $prefix.$object->code;
839 $translation = $this->translations->trans($key);
840 if ($translation != $key) {
841 $object->label = html_entity_decode($translation);
865 public function getListOfEventTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $type =
'', $module =
'', $active = 1, $sqlfilters =
'')
869 $sql =
"SELECT id, code, type, libelle as label, module";
870 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_actioncomm as t";
871 $sql .=
" WHERE t.active = ".((int) $active);
873 $sql .=
" AND t.type LIKE '%".$this->db->escape($type).
"%'";
876 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
883 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
888 $sql .= $this->db->order($sortfield, $sortorder);
894 $offset = $limit * $page;
896 $sql .= $this->db->plimit($limit, $offset);
899 $result = $this->db->query($sql);
902 $num = $this->db->num_rows($result);
903 $min = min($num, ($limit <= 0 ? $num : $limit));
904 for ($i = 0; $i < $min; $i++) {
905 $list[] = $this->db->fetch_object($result);
908 throw new RestException(503,
'Error when retrieving list of events types : '.$this->db->lasterror());
932 public function getListOfExpenseReportsTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $module =
'', $active = 1, $sqlfilters =
'')
936 $sql =
"SELECT id, code, label, accountancy_code, active, module, position";
937 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees as t";
938 $sql .=
" WHERE t.active = ".((int) $active);
940 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
947 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
952 $sql .= $this->db->order($sortfield, $sortorder);
958 $offset = $limit * $page;
960 $sql .= $this->db->plimit($limit, $offset);
963 $result = $this->db->query($sql);
966 $num = $this->db->num_rows($result);
967 $min = min($num, ($limit <= 0 ? $num : $limit));
968 for ($i = 0; $i < $min; $i++) {
969 $list[] = $this->db->fetch_object($result);
972 throw new RestException(503,
'Error when retrieving list of expense report types : '.$this->db->lasterror());
998 public function getListOfContactTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $type =
'', $module =
'', $active = 1, $lang =
'', $sqlfilters =
'')
1002 $sql =
"SELECT rowid, code, element as type, libelle as label, source, module, position";
1003 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact as t";
1004 $sql .=
" WHERE t.active = ".((int) $active);
1006 $sql .=
" AND type LIKE '%".$this->db->escape($type).
"%'";
1009 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
1015 if ($errormessage) {
1016 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1021 $sql .= $this->db->order($sortfield, $sortorder);
1027 $offset = $limit * $page;
1029 $sql .= $this->db->plimit($limit, $offset);
1032 $result = $this->db->query($sql);
1035 $num = $this->db->num_rows($result);
1036 $min = min($num, ($limit <= 0 ? $num : $limit));
1037 for ($i = 0; $i < $min; $i++) {
1038 $contact_type = $this->db->fetch_object($result);
1039 $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"));
1040 $list[] = $contact_type;
1043 throw new RestException(503,
'Error when retrieving list of contacts types : '.$this->db->lasterror());
1067 public function getListOfCivilities($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $module =
'', $active = 1, $lang =
'', $sqlfilters =
'')
1071 $sql =
"SELECT rowid, code, label, module";
1072 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_civility as t";
1073 $sql .=
" WHERE t.active = ".((int) $active);
1075 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
1081 if ($errormessage) {
1082 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1087 $sql .= $this->db->order($sortfield, $sortorder);
1093 $offset = $limit * $page;
1095 $sql .= $this->db->plimit($limit, $offset);
1098 $result = $this->db->query($sql);
1101 $num = $this->db->num_rows($result);
1102 $min = min($num, ($limit <= 0 ? $num : $limit));
1103 for ($i = 0; $i < $min; $i++) {
1104 $civility = $this->db->fetch_object($result);
1105 $this->
translateLabel($civility, $lang,
'Civility', array(
'dict'));
1106 $list[] = $civility;
1109 throw new RestException(503,
'Error when retrieving list of civility : '.$this->db->lasterror());
1132 public function getListOfCurrencies($multicurrency = 0, $sortfield =
"code_iso", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1135 $sql =
"SELECT t.code_iso, t.label, t.unicode";
1136 if (!empty($multicurrency)) {
1137 $sql .=
" , cr.date_sync, cr.rate ";
1139 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_currencies as t";
1140 if (!empty($multicurrency)) {
1141 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"multicurrency as m ON m.code=t.code_iso";
1142 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"multicurrency_rate as cr ON (m.rowid = cr.fk_multicurrency)";
1144 $sql .=
" WHERE t.active = ".((int) $active);
1145 if (!empty($multicurrency)) {
1146 $sql .=
" AND m.entity IN (".getEntity(
'multicurrency').
")";
1147 if (!empty($multicurrency) && $multicurrency != 2) {
1148 $sql .=
" AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM ".MAIN_DB_PREFIX.
"multicurrency_rate AS cr2 WHERE cr2.fk_multicurrency = m.rowid)";
1156 if ($errormessage) {
1157 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1162 $sql .= $this->db->order($sortfield, $sortorder);
1168 $offset = $limit * $page;
1170 $sql .= $this->db->plimit($limit, $offset);
1173 $result = $this->db->query($sql);
1176 $num = $this->db->num_rows($result);
1177 $min = min($num, ($limit <= 0 ? $num : $limit));
1178 for ($i = 0; $i < $min; $i++) {
1179 $list[] = $this->db->fetch_object($result);
1182 throw new RestException(503,
'Error when retrieving list of currency : '.$this->db->lasterror());
1202 public function getListOfExtrafields($sortfield =
"t.pos", $sortorder =
'ASC', $elementtype =
'', $sqlfilters =
'')
1206 if (!DolibarrApiAccess::$user->admin
1208 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');
1211 if ($elementtype ==
'thirdparty') {
1212 $elementtype =
'societe';
1214 if ($elementtype ==
'contact') {
1215 $elementtype =
'socpeople';
1218 $sql =
"SELECT t.rowid as id, t.name, t.entity, t.elementtype, t.label, t.type, t.size, t.fieldcomputed, t.fielddefault,";
1219 $sql .=
" t.fieldunique, t.fieldrequired, t.perms, t.enabled, t.pos, t.alwayseditable, t.param, t.list, t.printable,";
1220 $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";
1221 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1222 $sql .=
" WHERE t.entity IN (".getEntity(
'extrafields').
")";
1223 if (!empty($elementtype)) {
1224 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
1230 if ($errormessage) {
1231 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1235 $sql .= $this->db->order($sortfield, $sortorder);
1237 $resql = $this->db->query($sql);
1239 if ($this->db->num_rows($resql)) {
1240 while ($tab = $this->db->fetch_object($resql)) {
1242 $list[$tab->elementtype][$tab->name][
'id'] = $tab->id;
1243 $list[$tab->elementtype][$tab->name][
'type'] = $tab->type;
1244 $list[$tab->elementtype][$tab->name][
'label'] = $tab->label;
1245 $list[$tab->elementtype][$tab->name][
'size'] = $tab->size;
1246 $list[$tab->elementtype][$tab->name][
'elementtype'] = $tab->elementtype;
1247 $list[$tab->elementtype][$tab->name][
'default'] = $tab->fielddefault;
1248 $list[$tab->elementtype][$tab->name][
'computed'] = $tab->fieldcomputed;
1249 $list[$tab->elementtype][$tab->name][
'unique'] = $tab->fieldunique;
1250 $list[$tab->elementtype][$tab->name][
'required'] = $tab->fieldrequired;
1251 $list[$tab->elementtype][$tab->name][
'param'] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1252 $list[$tab->elementtype][$tab->name][
'pos'] = $tab->pos;
1253 $list[$tab->elementtype][$tab->name][
'alwayseditable'] = $tab->alwayseditable;
1254 $list[$tab->elementtype][$tab->name][
'perms'] = $tab->perms;
1255 $list[$tab->elementtype][$tab->name][
'list'] = $tab->list;
1256 $list[$tab->elementtype][$tab->name][
'printable'] = $tab->printable;
1257 $list[$tab->elementtype][$tab->name][
'totalizable'] = $tab->totalizable;
1258 $list[$tab->elementtype][$tab->name][
'langs'] = $tab->langs;
1259 $list[$tab->elementtype][$tab->name][
'help'] = $tab->help;
1260 $list[$tab->elementtype][$tab->name][
'css'] = $tab->css;
1261 $list[$tab->elementtype][$tab->name][
'cssview'] = $tab->cssview;
1262 $list[$tab->elementtype][$tab->name][
'csslist'] = $tab->csslist;
1263 $list[$tab->elementtype][$tab->name][
'fk_user_author'] = $tab->fk_user_author;
1264 $list[$tab->elementtype][$tab->name][
'fk_user_modif'] = $tab->fk_user_modif;
1265 $list[$tab->elementtype][$tab->name][
'datec'] = $tab->datec;
1266 $list[$tab->elementtype][$tab->name][
'tms'] = $tab->tms;
1270 throw new RestException(503,
'Error when retrieving list of extra fields : '.$this->db->lasterror());
1288 if (!DolibarrApiAccess::$user->admin) {
1289 throw new RestException(403,
'Only an admin user can delete an extrafield by attrname and elementtype');
1294 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1296 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1299 if (!$extrafields->delete($attrname, $elementtype)) {
1300 throw new RestException(500,
'Error when delete extrafield : '.$extrafields->error);
1306 'message' =>
'Extrafield deleted from attrname and elementtype'
1328 if (!DolibarrApiAccess::$user->admin) {
1329 throw new RestException(403,
'Only an admin user can get list of extrafields');
1332 if ($elementtype ==
'thirdparty') {
1333 $elementtype =
'societe';
1335 if ($elementtype ==
'contact') {
1336 $elementtype =
'socpeople';
1339 $sql =
"SELECT t.rowid as id, t.name, t.entity, t.elementtype, t.label, t.type, t.size, t.fieldcomputed, t.fielddefault,";
1340 $sql .=
" t.fieldunique, t.fieldrequired, t.perms, t.enabled, t.pos, t.alwayseditable, t.param, t.list, t.printable,";
1341 $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";
1342 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1343 $sql .=
" WHERE t.entity IN (".getEntity(
'extrafields').
")";
1344 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
1345 $sql .=
" AND t.name = '".$this->db->escape($attrname).
"'";
1347 $resql = $this->db->query($sql);
1349 if ($this->db->num_rows($resql)) {
1350 while ($tab = $this->db->fetch_object($resql)) {
1352 $answer[$tab->elementtype][$tab->name][
'id'] = $tab->id;
1353 $answer[$tab->elementtype][$tab->name][
'type'] = $tab->type;
1354 $answer[$tab->elementtype][$tab->name][
'label'] = $tab->label;
1355 $answer[$tab->elementtype][$tab->name][
'size'] = $tab->size;
1356 $answer[$tab->elementtype][$tab->name][
'elementtype'] = $tab->elementtype;
1357 $answer[$tab->elementtype][$tab->name][
'default'] = $tab->fielddefault;
1358 $answer[$tab->elementtype][$tab->name][
'computed'] = $tab->fieldcomputed;
1359 $answer[$tab->elementtype][$tab->name][
'unique'] = $tab->fieldunique;
1360 $answer[$tab->elementtype][$tab->name][
'required'] = $tab->fieldrequired;
1361 $answer[$tab->elementtype][$tab->name][
'param'] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1362 $answer[$tab->elementtype][$tab->name][
'pos'] = $tab->pos;
1363 $answer[$tab->elementtype][$tab->name][
'alwayseditable'] = $tab->alwayseditable;
1364 $answer[$tab->elementtype][$tab->name][
'perms'] = $tab->perms;
1365 $answer[$tab->elementtype][$tab->name][
'list'] = $tab->list;
1366 $answer[$tab->elementtype][$tab->name][
'printable'] = $tab->printable;
1367 $answer[$tab->elementtype][$tab->name][
'totalizable'] = $tab->totalizable;
1368 $answer[$tab->elementtype][$tab->name][
'langs'] = $tab->langs;
1369 $answer[$tab->elementtype][$tab->name][
'help'] = $tab->help;
1370 $answer[$tab->elementtype][$tab->name][
'css'] = $tab->css;
1371 $answer[$tab->elementtype][$tab->name][
'cssview'] = $tab->cssview;
1372 $answer[$tab->elementtype][$tab->name][
'csslist'] = $tab->csslist;
1373 $answer[$tab->elementtype][$tab->name][
'fk_user_author'] = $tab->fk_user_author;
1374 $answer[$tab->elementtype][$tab->name][
'fk_user_modif'] = $tab->fk_user_modif;
1375 $answer[$tab->elementtype][$tab->name][
'datec'] = $tab->datec;
1376 $answer[$tab->elementtype][$tab->name][
'tms'] = $tab->tms;
1379 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1382 throw new RestException(503,
'Error when retrieving list of extra fields : '.$this->db->lasterror());
1403 if (!DolibarrApiAccess::$user->admin) {
1404 throw new RestException(403,
'Only an admin user can create an extrafield');
1409 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1411 throw new RestException(409,
'Duplicate extrafield already found from attrname and elementtype');
1417 foreach ($request_data as $field => $value) {
1418 $extrafields->$field = $this->
_checkValForAPI($field, $value, $extrafields);
1421 $entity = DolibarrApiAccess::$user->entity;
1422 if (empty($entity)) {
1429 if ($request_data[
'label']) {
1430 $label = $request_data[
'label'];
1432 throw new RestException(400,
"label field absent in json at root level");
1435 $alwayseditable = $request_data[
'alwayseditable'];
1436 $default_value = $request_data[
'default_value'];
1437 $totalizable = $request_data[
'totalizable'];
1438 $printable = $request_data[
'printable'];
1439 $required = $request_data[
'required'];
1440 $langfile = $request_data[
'langfile'];
1441 $computed = $request_data[
'computed'];
1442 $unique = $request_data[
'unique'];
1443 $param = $request_data[
'param'];
1444 $perms = $request_data[
'perms'];
1445 $size = $request_data[
'size'];
1446 $type = $request_data[
'type'];
1447 $list = $request_data[
'list'];
1448 $help = $request_data[
'help'];
1449 $pos = $request_data[
'pos'];
1450 $moreparams = array();
1452 if (0 > $extrafields->addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $default_value, $param, $alwayseditable, $perms, $list, $help, $computed, $entity, $langfile, $enabled, $totalizable, $printable, $moreparams)) {
1453 throw new RestException(500,
'Error creating extrafield', array_merge(array($extrafields->errno), $extrafields->errors));
1456 $sql =
"SELECT t.rowid as id";
1457 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1458 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1459 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1461 $resql = $this->db->query($sql);
1463 if ($this->db->num_rows($resql)) {
1464 $tab = $this->db->fetch_object($resql);
1465 $id = (int) $tab->id;
1492 if (!DolibarrApiAccess::$user->admin) {
1493 throw new RestException(403,
'Only an admin user can create an extrafield');
1498 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1500 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1503 foreach ($request_data as $field => $value) {
1504 $extrafields->$field = $this->
_checkValForAPI($field, $value, $extrafields);
1507 $entity = DolibarrApiAccess::$user->entity;
1508 if (empty($entity)) {
1514 if ($request_data[
'label']) {
1515 $label = $request_data[
'label'];
1517 throw new RestException(400,
"label field absent in json at root level");
1520 $alwayseditable = $request_data[
'alwayseditable'];
1521 $default_value = $request_data[
'default_value'];
1522 $totalizable = $request_data[
'totalizable'];
1523 $printable = $request_data[
'printable'];
1524 $required = $request_data[
'required'];
1525 $langfile = $request_data[
'langfile'];
1526 $computed = $request_data[
'computed'];
1527 $unique = $request_data[
'unique'];
1528 $param = $request_data[
'param'];
1529 $perms = $request_data[
'perms'];
1530 $size = $request_data[
'size'];
1531 $type = $request_data[
'type'];
1532 $list = $request_data[
'list'];
1533 $help = $request_data[
'help'];
1534 $pos = $request_data[
'pos'];
1535 $moreparams = array();
1537 dol_syslog(get_class($this).
'::updateExtraField', LOG_DEBUG);
1538 if (0 > $extrafields->updateExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique, $required, $default_value, $param, $alwayseditable, $perms, $list, $help, $computed, $entity, $langfile, $enabled, $totalizable, $printable, $moreparams)) {
1539 throw new RestException(500,
'Error updating extrafield', array_merge(array($extrafields->errno), $extrafields->errors));
1542 $sql =
"SELECT t.rowid as id";
1543 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1544 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1545 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1547 $resql = $this->db->query($sql);
1549 if ($this->db->num_rows($resql)) {
1550 $tab = $this->db->fetch_object($resql);
1551 $id = (int) $tab->id;
1580 public function getListOfTowns($sortfield =
"zip,town", $sortorder =
'ASC', $limit = 100, $page = 0, $zipcode =
'', $town =
'', $active = 1, $sqlfilters =
'')
1584 $sql =
"SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
1585 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ziptown as t";
1586 $sql .=
" WHERE t.active = ".((int) $active);
1588 $sql .=
" AND t.zip LIKE '%".$this->db->escape($zipcode).
"%'";
1591 $sql .=
" AND t.town LIKE '%".$this->db->escape($town).
"%'";
1597 if ($errormessage) {
1598 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1603 $sql .= $this->db->order($sortfield, $sortorder);
1609 $offset = $limit * $page;
1611 $sql .= $this->db->plimit($limit, $offset);
1614 $result = $this->db->query($sql);
1617 $num = $this->db->num_rows($result);
1618 $min = min($num, ($limit <= 0 ? $num : $limit));
1619 for ($i = 0; $i < $min; $i++) {
1620 $list[] = $this->db->fetch_object($result);
1623 throw new RestException(503,
'Error when retrieving list of towns : '.$this->db->lasterror());
1647 public function getPaymentTerms($sortfield =
"sortorder", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1651 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire') && !DolibarrApiAccess::$user->hasRight(
'commande',
'lire') && !DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1652 throw new RestException(403);
1655 $sql =
"SELECT rowid as id, code, sortorder, libelle as label, libelle_facture as descr, type_cdr, nbjour, decalage, module";
1656 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_payment_term as t";
1657 $sql .=
" WHERE t.entity IN (".getEntity(
'c_payment_term').
")";
1658 $sql .=
" AND t.active = ".((int) $active);
1663 if ($errormessage) {
1664 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1669 $sql .= $this->db->order($sortfield, $sortorder);
1675 $offset = $limit * $page;
1677 $sql .= $this->db->plimit($limit, $offset);
1680 $result = $this->db->query($sql);
1683 $num = $this->db->num_rows($result);
1684 $min = min($num, ($limit <= 0 ? $num : $limit));
1685 for ($i = 0; $i < $min; $i++) {
1686 $list[] = $this->db->fetch_object($result);
1689 throw new RestException(503, $this->db->lasterror());
1711 public function getShippingModes($limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
1715 $sql =
"SELECT rowid as id, code, libelle as label, description, tracking, module";
1716 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as t";
1717 $sql .=
" WHERE t.entity IN (".getEntity(
'c_shipment_mode').
")";
1718 $sql .=
" AND t.active = ".((int) $active);
1723 if ($errormessage) {
1724 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1735 $offset = $limit * $page;
1737 $sql .= $this->db->plimit($limit, $offset);
1740 $result = $this->db->query($sql);
1743 $num = $this->db->num_rows($result);
1744 $min = min($num, ($limit <= 0 ? $num : $limit));
1745 for ($i = 0; $i < $min; $i++) {
1746 $method = $this->db->fetch_object($result);
1751 throw new RestException(503, $this->db->lasterror());
1773 public function getListOfMeasuringUnits($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1777 $sql =
"SELECT t.rowid, t.code, t.label,t.short_label, t.active, t.scale, t.unit_type";
1778 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_units as t";
1779 $sql .=
" WHERE t.active = ".((int) $active);
1784 if ($errormessage) {
1785 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1790 $sql .= $this->db->order($sortfield, $sortorder);
1796 $offset = $limit * $page;
1798 $sql .= $this->db->plimit($limit, $offset);
1801 $result = $this->db->query($sql);
1804 $num = $this->db->num_rows($result);
1805 $min = min($num, ($limit <= 0 ? $num : $limit));
1806 for ($i = 0; $i < $min; $i++) {
1807 $list[] = $this->db->fetch_object($result);
1810 throw new RestException(503,
'Error when retrieving list of measuring units: '.$this->db->lasterror());
1833 public function getListOfLegalForm($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $active = 1, $sqlfilters =
'')
1837 $sql =
"SELECT t.rowid, t.code, t.fk_pays, t.libelle, t.isvatexempted, t.active, t.module, t.position";
1838 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_forme_juridique as t";
1839 $sql .=
" WHERE t.active = ".((int) $active);
1841 $sql .=
" AND t.fk_pays = ".((int) $country);
1847 if ($errormessage) {
1848 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1853 $sql .= $this->db->order($sortfield, $sortorder);
1859 $offset = $limit * $page;
1861 $sql .= $this->db->plimit($limit, $offset);
1864 $result = $this->db->query($sql);
1867 $num = $this->db->num_rows($result);
1868 $min = min($num, ($limit <= 0 ? $num : $limit));
1869 for ($i = 0; $i < $min; $i++) {
1870 $list[] = $this->db->fetch_object($result);
1873 throw new RestException(503,
'Error when retrieving list of legal form: '.$this->db->lasterror());
1895 public function getListOfStaff($sortfield =
"id", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1899 $sql =
"SELECT t.id, t.code, t.libelle, t.active, t.module";
1900 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_effectif as t";
1901 $sql .=
" WHERE t.active = ".((int) $active);
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 staff: '.$this->db->lasterror());
1954 public function getListOfsocialNetworks($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1958 if (!isModEnabled(
'socialnetworks')) {
1959 throw new RestException(400,
'API not available: this dictionary is not enabled by setup');
1964 $sql =
"SELECT t.rowid, t.entity, t.code, t.label, t.url, t.icon, t.active";
1965 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_socialnetworks as t";
1966 $sql .=
" WHERE t.entity IN (".getEntity(
'c_socialnetworks').
")";
1967 $sql .=
" AND t.active = ".((int) $active);
1972 if ($errormessage) {
1973 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1978 $sql .= $this->db->order($sortfield, $sortorder);
1984 $offset = $limit * $page;
1986 $sql .= $this->db->plimit($limit, $offset);
1989 $result = $this->db->query($sql);
1992 $num = $this->db->num_rows($result);
1993 $min = min($num, ($limit <= 0 ? $num : $limit));
1994 for ($i = 0; $i < $min; $i++) {
1995 $list[] = $this->db->fetch_object($result);
1998 throw new RestException(503,
'Error when retrieving list of social networks: '.$this->db->lasterror());
2021 public function getTicketsCategories($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2025 $sql =
"SELECT rowid, code, pos, label, use_default, description";
2026 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_category as t";
2027 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_category').
")";
2028 $sql .=
" AND t.active = ".((int) $active);
2033 if ($errormessage) {
2034 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2039 $sql .= $this->db->order($sortfield, $sortorder);
2045 $offset = $limit * $page;
2047 $sql .= $this->db->plimit($limit, $offset);
2050 $result = $this->db->query($sql);
2053 $num = $this->db->num_rows($result);
2054 $min = min($num, ($limit <= 0 ? $num : $limit));
2055 for ($i = 0; $i < $min; $i++) {
2056 $category = $this->db->fetch_object($result);
2057 $this->
translateLabel($category, $lang,
'TicketCategoryShort', array(
'ticket'));
2058 $list[] = $category;
2061 throw new RestException(503,
'Error when retrieving list of ticket categories : '.$this->db->lasterror());
2084 public function getTicketsSeverities($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2088 $sql =
"SELECT rowid, code, pos, label, use_default, color, description";
2089 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_severity as t";
2090 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_severity').
")";
2091 $sql .=
" AND t.active = ".((int) $active);
2096 if ($errormessage) {
2097 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2102 $sql .= $this->db->order($sortfield, $sortorder);
2108 $offset = $limit * $page;
2110 $sql .= $this->db->plimit($limit, $offset);
2113 $result = $this->db->query($sql);
2116 $num = $this->db->num_rows($result);
2117 $min = min($num, ($limit <= 0 ? $num : $limit));
2118 for ($i = 0; $i < $min; $i++) {
2119 $severity = $this->db->fetch_object($result);
2120 $this->
translateLabel($severity, $lang,
'TicketSeverityShort', array(
'ticket'));
2121 $list[] = $severity;
2124 throw new RestException(503,
'Error when retrieving list of ticket severities : '.$this->db->lasterror());
2147 public function getTicketsTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2151 $sql =
"SELECT rowid, code, pos, label, use_default, description";
2152 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_type as t";
2153 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_type').
")";
2154 $sql .=
" AND t.active = ".((int) $active);
2160 if ($errormessage) {
2161 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2166 $sql .= $this->db->order($sortfield, $sortorder);
2172 $offset = $limit * $page;
2174 $sql .= $this->db->plimit($limit, $offset);
2177 $result = $this->db->query($sql);
2180 $num = $this->db->num_rows($result);
2181 $min = min($num, ($limit <= 0 ? $num : $limit));
2182 for ($i = 0; $i < $min; $i++) {
2183 $type = $this->db->fetch_object($result);
2184 $this->
translateLabel($type, $lang,
'TicketTypeShort', array(
'ticket'));
2188 throw new RestException(503,
'Error when retrieving list of ticket types : '.$this->db->lasterror());
2210 public function getListOfIncoterms($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2214 $sql =
"SELECT rowid, code, active";
2215 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_incoterms as t";
2216 $sql .=
" WHERE 1=1";
2222 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2224 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
2225 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
2229 $sql .= $this->db->order($sortfield, $sortorder);
2235 $offset = $limit * $page;
2237 $sql .= $this->db->plimit($limit, $offset);
2240 $result = $this->db->query($sql);
2243 $num = $this->db->num_rows($result);
2244 $min = min($num, ($limit <= 0 ? $num : $limit));
2245 for ($i = 0; $i < $min; $i++) {
2246 $type = $this->db->fetch_object($result);
2250 throw new RestException(503,
'Error when retrieving list of incoterm types : '.$this->db->lasterror());
2267 global $conf, $mysoc;
2269 if (!DolibarrApiAccess::$user->admin
2271 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');
2274 unset($mysoc->pays);
2275 unset($mysoc->note);
2278 unset($mysoc->lines);
2280 unset($mysoc->effectif);
2281 unset($mysoc->effectif_id);
2282 unset($mysoc->forme_juridique_code);
2283 unset($mysoc->forme_juridique);
2284 unset($mysoc->mode_reglement_supplier_id);
2285 unset($mysoc->cond_reglement_supplier_id);
2286 unset($mysoc->transport_mode_supplier_id);
2287 unset($mysoc->fk_prospectlevel);
2289 unset($mysoc->total_ht);
2290 unset($mysoc->total_tva);
2291 unset($mysoc->total_localtax1);
2292 unset($mysoc->total_localtax2);
2293 unset($mysoc->total_ttc);
2295 unset($mysoc->lastname);
2296 unset($mysoc->firstname);
2297 unset($mysoc->civility_id);
2299 unset($mysoc->client);
2300 unset($mysoc->prospect);
2301 unset($mysoc->fournisseur);
2302 unset($mysoc->contact_id);
2304 unset($mysoc->fk_incoterms);
2305 unset($mysoc->label_incoterms);
2306 unset($mysoc->location_incoterms);
2326 $sql =
"SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
2327 $sql .=
" FROM ".MAIN_DB_PREFIX.
"establishment as e";
2328 $sql .=
" WHERE e.entity IN (".getEntity(
'establishment').
')';
2333 $result = $this->db->query($sql);
2336 $num = $this->db->num_rows($result);
2337 $min = min($num, ($limit <= 0 ? $num : $limit));
2338 for ($i = 0; $i < $min; $i++) {
2339 $list[] = $this->db->fetch_object($result);
2342 throw new RestException(503,
'Error when retrieving list of establishments : '.$this->db->lasterror());
2363 $result = $establishment->fetch(
$id);
2365 throw new RestException(503,
'Error when retrieving establishment : '.$establishment->error);
2366 } elseif ($result == 0) {
2367 throw new RestException(404,
'Establishment not found');
2390 if (!DolibarrApiAccess::$user->admin
2392 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');
2395 if (!preg_match(
'/^[a-zA-Z0-9_]+$/', $constantname) || !isset($conf->global->$constantname)) {
2396 throw new RestException(400,
'Error Bad or unknown value for constantname');
2399 throw new RestException(403,
'Forbidden. This parameter can not be read with APIs');
2419 global $langs, $conf;
2421 if (!DolibarrApiAccess::$user->admin
2423 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');
2426 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2427 require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
2429 $langs->load(
"admin");
2431 $outexpectedchecksum =
'';
2432 $outcurrentchecksum =
'';
2435 $file_list = array(
'missing' => array(),
'updated' => array());
2440 $xmlfile = DOL_DOCUMENT_ROOT.
'/install/'.$xmlshortfile;
2441 if (!preg_match(
'/\.zip$/i', $xmlfile) &&
dol_is_file($xmlfile.
'.zip')) {
2446 $xmlremote = (($target ==
'default' || $target ==
'local') ?
'' : $target);
2450 $param =
'MAIN_FILECHECK_URL_'.DOL_VERSION;
2454 if (empty($xmlremote)) {
2455 $xmlremote =
'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.
'.xml';
2457 if ($xmlremote && !preg_match(
'/^https?:\/\//i', $xmlremote)) {
2458 $langs->load(
"errors");
2459 throw new RestException(500, $langs->trans(
"ErrorURLMustStartWithHttp", $xmlremote));
2461 if ($xmlremote && !preg_match(
'/\.xml$/', $xmlremote)) {
2462 $langs->load(
"errors");
2463 throw new RestException(500, $langs->trans(
"ErrorURLMustEndWith", $xmlremote,
'.xml'));
2466 if (LIBXML_VERSION < 20900) {
2470 libxml_disable_entity_loader(
true);
2473 if ($target ==
'local') {
2475 $xml = simplexml_load_file($xmlfile);
2477 throw new RestException(500, $langs->trans(
'XmlNotFound').
': /install/'.$xmlshortfile);
2480 $xmlarray =
getURLContent($xmlremote,
'GET',
'', 1, array(), array(
'http',
'https'), 0);
2483 if (!$xmlarray[
'curl_error_no'] && $xmlarray[
'http_code'] !=
'400' && $xmlarray[
'http_code'] !=
'404') {
2484 $xmlfile = $xmlarray[
'content'];
2486 $xml = simplexml_load_string($xmlfile,
'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NONET);
2488 $errormsg = $langs->trans(
'XmlNotFound').
': '.$xmlremote.
' - '.$xmlarray[
'http_code'].(($xmlarray[
'http_code'] == 400 && $xmlarray[
'content']) ?
' '.$xmlarray[
'content'] :
'').
' '.$xmlarray[
'curl_error_no'].
' '.$xmlarray[
'curl_error_msg'];
2489 throw new RestException(500, $errormsg);
2494 $checksumconcat = array();
2495 $file_list = array();
2499 if (is_object($xml->dolibarr_constants[0])) {
2502 $out .=
'<div class="div-table-responsive-no-min">';
2503 $out .=
'<table class="noborder">';
2504 $out .=
'<tr class="liste_titre">';
2505 $out .=
'<td>#</td>';
2506 $out .=
'<td>'.$langs->trans(
"Constant").
'</td>';
2507 $out .=
'<td class="center">'.$langs->trans(
"ExpectedValue").
'</td>';
2508 $out .=
'<td class="center">'.$langs->trans(
"Value").
'</td>';
2509 $out .=
'</tr>'.
"\n";
2512 foreach ($xml->dolibarr_constants[0]->constant as $constant) {
2513 $constname = $constant[
'name'];
2514 $constvalue = (string) $constant;
2515 $constvalue = (empty($constvalue) ?
'0' : $constvalue);
2521 $valueforchecksum = (empty($value) ?
'0' : $value);
2523 $checksumconcat[] = $valueforchecksum;
2526 $out .=
'<tr class="oddeven">';
2527 $out .=
'<td>'.$i.
'</td>'.
"\n";
2528 $out .=
'<td>'.dol_escape_htmltag($constname).
'</td>'.
"\n";
2529 $out .=
'<td class="center">'.dol_escape_htmltag($constvalue).
'</td>'.
"\n";
2530 $out .=
'<td class="center">'.dol_escape_htmltag($valueforchecksum).
'</td>'.
"\n";
2535 $out .=
'<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2544 if (is_object($xml->dolibarr_htdocs_dir[0])) {
2545 $includecustom = (empty($xml->dolibarr_htdocs_dir[0][
'includecustom']) ? 0 : $xml->dolibarr_htdocs_dir[0][
'includecustom']);
2548 $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)$';
2549 $regextoexclude =
'('.($includecustom ?
'' :
'custom|').
'documents|conf|install|dejavu-fonts-ttf-.*|public\/test|sabre\/sabre\/.*\/tests|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$';
2550 $scanfiles =
dol_dir_list(DOL_DOCUMENT_ROOT,
'files', 1, $regextoinclude, $regextoexclude);
2553 $ret =
getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0],
'', DOL_DOCUMENT_ROOT, $checksumconcat);
2555 foreach ($scanfiles as $keyfile => $valfile) {
2556 $tmprelativefilename = preg_replace(
'/^'.preg_quote(DOL_DOCUMENT_ROOT,
'/').
'/',
'', $valfile[
'fullname']);
2557 if (!in_array($tmprelativefilename, $file_list[
'insignature'])) {
2558 $md5newfile = @md5_file($valfile[
'fullname']);
2559 $file_list[
'added'][] = array(
'filename' => $tmprelativefilename,
'md5' => $md5newfile);
2566 $out .=
'<div class="div-table-responsive-no-min">';
2567 $out .=
'<table class="noborder">';
2568 $out .=
'<tr class="liste_titre">';
2569 $out .=
'<td>#</td>';
2570 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2571 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2572 $out .=
'</tr>'.
"\n";
2573 $tmpfilelist =
dol_sort_array($file_list[
'missing'],
'filename');
2574 if (is_array($tmpfilelist) && count($tmpfilelist)) {
2576 foreach ($tmpfilelist as $file) {
2578 $out .=
'<tr class="oddeven">';
2579 $out .=
'<td>'.$i.
'</td>'.
"\n";
2580 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2581 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2585 $out .=
'<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2596 $out .=
'<div class="div-table-responsive-no-min">';
2597 $out .=
'<table class="noborder">';
2598 $out .=
'<tr class="liste_titre">';
2599 $out .=
'<td>#</td>';
2600 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2601 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2602 $out .=
'<td class="center">'.$langs->trans(
"CurrentChecksum").
'</td>';
2603 $out .=
'<td class="right">'.$langs->trans(
"Size").
'</td>';
2604 $out .=
'<td class="right">'.$langs->trans(
"DateModification").
'</td>';
2605 $out .=
'</tr>'.
"\n";
2606 $tmpfilelist2 =
dol_sort_array($file_list[
'updated'],
'filename');
2607 if (is_array($tmpfilelist2) && count($tmpfilelist2)) {
2609 foreach ($tmpfilelist2 as $file) {
2611 $out .=
'<tr class="oddeven">';
2612 $out .=
'<td>'.$i.
'</td>'.
"\n";
2613 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2614 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2615 $out .=
'<td class="center">'.$file[
'md5'].
'</td>'.
"\n";
2616 $size =
dol_filesize(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']);
2617 $totalsize += $size;
2618 $out .=
'<td class="right">'.dol_print_size($size).
'</td>'.
"\n";
2619 $out .=
'<td class="right">'.dol_print_date(
dol_filemtime(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']),
'dayhour').
'</td>'.
"\n";
2622 $out .=
'<tr class="liste_total">';
2623 $out .=
'<td></td>'.
"\n";
2624 $out .=
'<td>'.$langs->trans(
"Total").
'</td>'.
"\n";
2625 $out .=
'<td align="center"></td>'.
"\n";
2626 $out .=
'<td align="center"></td>'.
"\n";
2627 $out .=
'<td class="right">'.dol_print_size($totalsize).
'</td>'.
"\n";
2628 $out .=
'<td class="right"></td>'.
"\n";
2631 $out .=
'<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2642 $out .=
'<div class="div-table-responsive-no-min">';
2643 $out .=
'<table class="noborder">';
2644 $out .=
'<tr class="liste_titre">';
2645 $out .=
'<td>#</td>';
2646 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2647 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2648 $out .=
'<td class="center">'.$langs->trans(
"CurrentChecksum").
'</td>';
2649 $out .=
'<td class="right">'.$langs->trans(
"Size").
'</td>';
2650 $out .=
'<td class="right">'.$langs->trans(
"DateModification").
'</td>';
2651 $out .=
'</tr>'.
"\n";
2653 if (is_array($tmpfilelist3) && count($tmpfilelist3)) {
2655 foreach ($tmpfilelist3 as $file) {
2657 $out .=
'<tr class="oddeven">';
2658 $out .=
'<td>'.$i.
'</td>'.
"\n";
2659 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2660 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2661 $out .=
'<td class="center">'.$file[
'md5'].
'</td>'.
"\n";
2662 $size =
dol_filesize(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']);
2663 $totalsize += $size;
2664 $out .=
'<td class="right">'.dol_print_size($size).
'</td>'.
"\n";
2665 $out .=
'<td class="right">'.dol_print_date(
dol_filemtime(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']),
'dayhour').
'</td>'.
"\n";
2668 $out .=
'<tr class="liste_total">';
2669 $out .=
'<td></td>'.
"\n";
2670 $out .=
'<td>'.$langs->trans(
"Total").
'</td>'.
"\n";
2671 $out .=
'<td align="center"></td>'.
"\n";
2672 $out .=
'<td align="center"></td>'.
"\n";
2673 $out .=
'<td class="right">'.dol_print_size($totalsize).
'</td>'.
"\n";
2674 $out .=
'<td class="right"></td>'.
"\n";
2677 $out .=
'<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2684 if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) {
2690 throw new RestException(500,
'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile);
2695 asort($checksumconcat);
2696 $checksumget = md5(implode(
',', $checksumconcat));
2697 $checksumtoget = trim((
string) $xml->dolibarr_htdocs_dir_checksum);
2699 $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans(
"Unknown"));
2700 if ($checksumget == $checksumtoget) {
2701 if (count($file_list[
'added'])) {
2702 $resultcode =
'warning';
2703 $resultcomment =
'FileIntegrityIsOkButFilesWereAdded';
2705 $outcurrentchecksum = $checksumget;
2708 $resultcomment =
'Success';
2710 $outcurrentchecksum = $checksumget;
2713 $resultcode =
'error';
2714 $resultcomment =
'Error';
2716 $outcurrentchecksum = $checksumget;
2719 throw new RestException(404,
'No signature file known');
2722 return array(
'resultcode' => $resultcode,
'resultcomment' => $resultcomment,
'expectedchecksum' => $outexpectedchecksum,
'currentchecksum' => $outcurrentchecksum,
'out' => $out);
2739 if (!DolibarrApiAccess::$user->admin
2741 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');
2744 sort($conf->modules);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage dictionary Countries (used by imports)
Class to manage dictionary Regions.
Class to manage dictionary States (used by imports)
_checkFilters($sqlfilters, &$error='')
Return if a $sqlfilters parameter is valid Function no more used.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
Class to manage establishments.
getExtrafields($attrname, $elementtype)
get Extrafield object
getShippingModes($limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of shipping methods.
getListOfContactTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $type='', $module='', $active=1, $lang='', $sqlfilters='')
Get the list of contacts types.
getTicketsCategories($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of tickets categories.
getListOfMeasuringUnits($sortfield="rowid", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of measuring units.
_cleanObjectDatas($object)
Clean sensible object datas.
getListOfStaff($sortfield="id", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of staff.
getTicketsSeverities($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of tickets severity.
translateLabel($object, $lang, $prefix='Country', $dict=array('dict'))
Translate the name of the object to the given language.
getCountryByISO($iso, $lang='')
Get country by Iso.
getCheckIntegrity($target)
Do a test of integrity for files and setup.
getListOfExpenseReportsTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $module='', $active=1, $sqlfilters='')
Get the list of Expense Report types.
__construct()
Constructor.
getListOfTowns($sortfield="zip,town", $sortorder='ASC', $limit=100, $page=0, $zipcode='', $town='', $active=1, $sqlfilters='')
Get the list of towns.
getStateByCode($code)
Get state by Code.
getListOfRegions($sortfield="code_region", $sortorder='ASC', $limit=100, $page=0, $country=0, $filter='', $sqlfilters='')
Get the list of regions.
getListOfEventTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $type='', $module='', $active=1, $sqlfilters='')
Get the list of events types.
getEstablishments()
Get the list of establishments.
getListOfLegalForm($sortfield="rowid", $sortorder='ASC', $limit=100, $page=0, $country=0, $active=1, $sqlfilters='')
Get the list of legal form of business.
getListOfCurrencies($multicurrency=0, $sortfield="code_iso", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of currencies.
getListOfsocialNetworks($sortfield="rowid", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of social networks.
_fetchCstate($id, $code='')
Get state.
getEtablishmentByID($id)
Get establishment by ID.
getConf($constantname)
Get value of a setup variables.
updateExtrafields($attrname, $elementtype, $request_data=null)
Update Extrafield object.
deleteExtrafieldsFromNames($attrname, $elementtype)
Delete extrafield.
getListOfIncoterms($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of incoterms.
getCompany()
Get properties of company.
postExtrafields($attrname, $elementtype, $request_data=null)
Create Extrafield object.
getPaymentTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of payments types.
getCountryByID($id, $lang='')
Get country by ID.
_fetchCregion($id, $code='')
Get region.
getCountryByCode($code, $lang='')
Get country by Code.
getPaymentTerms($sortfield="sortorder", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of payments terms.
getOrderingOrigins($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of ordering origins.
getListOfActionTriggers($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $elementtype='', $lang='', $sqlfilters='')
Get the list of Action Triggers.
getListOfStates($sortfield="code_departement", $sortorder='ASC', $limit=100, $page=0, $country=0, $filter='', $sqlfilters='')
Get the list of states/provinces.
getOrderingMethods($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of ordering methods.
_fetchCcountry($id, $code='', $iso='', $lang='')
Get country.
getListOfExtrafields($sortfield="t.pos", $sortorder='ASC', $elementtype='', $sqlfilters='')
Get the list of extra fields.
getStateByID($id)
Get state by ID.
getAvailability($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $sqlfilters='')
Get the list of delivery times.
getTicketsTypes($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $active=1, $lang='', $sqlfilters='')
Get the list of tickets types.
getRegionByCode($code)
Get region by Code.
getListOfCountries($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $filter='', $lang='', $sqlfilters='')
Get the list of countries.
getRegionByID($id)
Get region by ID.
getListOfCivilities($sortfield="code", $sortorder='ASC', $limit=100, $page=0, $module='', $active=1, $lang='', $sqlfilters='')
Get the list of civilities.
getModules()
Get list of enabled modules.
Class to manage translations.
getFilesUpdated(&$file_list, SimpleXMLElement $dir, $path='', $pathref='', &$checksumconcat=array())
Function to get list of updated or modified files.
dol_filemtime($pathoffile)
Return time of a file.
dol_filesize($pathoffile)
Return size of a file.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
isASecretKey($keyname)
Return if string has a name dedicated to store a secret.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
jsonOrUnserialize($stringtodecode)
Decode an encode string.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1)
Function to get a content from an URL (use proxy if proxy defined).