25use Luracast\Restler\RestException;
27require_once DOL_DOCUMENT_ROOT.
'/main.inc.php';
28require_once DOL_DOCUMENT_ROOT.
'/api/class/api.class.php';
29require_once DOL_DOCUMENT_ROOT.
'/core/class/cstate.class.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/class/cregion.class.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/class/ccountry.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/hrm/class/establishment.class.php';
42 private $translations =
null;
71 public function getOrderingMethods($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
75 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
76 throw new RestException(403);
79 $sql =
"SELECT rowid, code, libelle as label, module";
80 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_input_method as t";
81 $sql .=
" WHERE t.active = ".((int) $active);
87 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
92 $sql .= $this->db->order($sortfield, $sortorder);
98 $offset = $limit * $page;
100 $sql .= $this->db->plimit($limit, $offset);
103 $result = $this->db->query($sql);
106 $num = $this->db->num_rows($result);
107 $min = min($num, ($limit <= 0 ? $num : $limit));
108 for ($i = 0; $i < $min; $i++) {
109 $list[] = $this->db->fetch_object($result);
112 throw new RestException(503, $this->db->lasterror());
135 public function getOrderingOrigins($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
139 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
140 throw new RestException(403);
143 $sql =
"SELECT rowid, code, label, module";
144 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_input_reason as t";
145 $sql .=
" WHERE t.active = ".((int) $active);
151 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
156 $sql .= $this->db->order($sortfield, $sortorder);
162 $offset = $limit * $page;
164 $sql .= $this->db->plimit($limit, $offset);
167 $result = $this->db->query($sql);
170 $num = $this->db->num_rows($result);
171 $min = min($num, ($limit <= 0 ? $num : $limit));
172 for ($i = 0; $i < $min; $i++) {
173 $list[] = $this->db->fetch_object($result);
176 throw new RestException(503, $this->db->lasterror());
200 public function getPaymentTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
204 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire') && !DolibarrApiAccess::$user->hasRight(
'commande',
'lire') && !DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
205 throw new RestException(403);
208 $sql =
"SELECT id, code, type, libelle as label, module";
209 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_paiement as t";
210 $sql .=
" WHERE t.entity IN (".getEntity(
'c_paiement').
")";
211 $sql .=
" AND t.active = ".((int) $active);
217 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
222 $sql .= $this->db->order($sortfield, $sortorder);
228 $offset = $limit * $page;
230 $sql .= $this->db->plimit($limit, $offset);
233 $result = $this->db->query($sql);
236 $num = $this->db->num_rows($result);
237 $min = min($num, ($limit <= 0 ? $num : $limit));
238 for ($i = 0; $i < $min; $i++) {
239 $list[] = $this->db->fetch_object($result);
242 throw new RestException(503, $this->db->lasterror());
266 public function getListOfRegions($sortfield =
"code_region", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $filter =
'', $sqlfilters =
'')
272 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.
"c_regions as t";
273 $sql .=
" WHERE 1 = 1";
275 $sql .=
" AND t.fk_pays = ".((int) $country);
281 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
283 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
284 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
287 $sql .= $this->db->order($sortfield, $sortorder);
293 $offset = $limit * $page;
295 $sql .= $this->db->plimit($limit, $offset);
298 $result = $this->db->query($sql);
301 $num = $this->db->num_rows($result);
302 $min = min($num, ($limit <= 0 ? $num : $limit));
303 for ($i = 0; $i < $min; $i++) {
304 $obj = $this->db->fetch_object($result);
305 $region =
new Cregion($this->db);
306 if ($region->fetch($obj->rowid) > 0) {
307 if (empty($filter) || stripos($region->name, $filter) !==
false) {
313 throw new RestException(503,
'Error when retrieving list of regions');
373 public function getListOfStates($sortfield =
"code_departement", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $filter =
'', $sqlfilters =
'')
379 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.
"c_departements as t";
381 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as d ON t.fk_region = d.code_region";
383 $sql .=
" WHERE 1 = 1";
385 $sql .=
" AND d.fk_pays = ".((int) $country);
392 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
396 $sql .= $this->db->order($sortfield, $sortorder);
402 $offset = $limit * $page;
404 $sql .= $this->db->plimit($limit, $offset);
407 $result = $this->db->query($sql);
410 $num = $this->db->num_rows($result);
411 $min = min($num, ($limit <= 0 ? $num : $limit));
412 for ($i = 0; $i < $min; $i++) {
413 $obj = $this->db->fetch_object($result);
414 $state =
new Cstate($this->db);
415 if ($state->fetch($obj->rowid) > 0) {
416 if (empty($filter) || stripos($state->label, $filter) !==
false) {
422 throw new RestException(503,
'Error when retrieving list of states');
482 public function getListOfCountries($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $filter =
'', $lang =
'', $sqlfilters =
'')
488 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"c_country as t";
489 $sql .=
" WHERE 1 = 1";
495 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
499 $sql .= $this->db->order($sortfield, $sortorder);
505 $offset = $limit * $page;
507 $sql .= $this->db->plimit($limit, $offset);
510 $result = $this->db->query($sql);
513 $num = $this->db->num_rows($result);
514 $min = min($num, ($limit <= 0 ? $num : $limit));
515 for ($i = 0; $i < $min; $i++) {
516 $obj = $this->db->fetch_object($result);
518 if ($country->fetch($obj->rowid) > 0) {
523 if (empty($filter) || stripos($country->label, $filter) !==
false) {
529 throw new RestException(503,
'Error when retrieving list of countries');
597 $region =
new Cregion($this->db);
599 $result = $region->fetch($id, $code);
601 throw new RestException(503,
'Error when retrieving region : '.$region->error);
602 } elseif ($result == 0) {
603 throw new RestException(404,
'Region not found');
620 $state =
new Cstate($this->db);
622 $result = $state->fetch($id, $code);
624 throw new RestException(503,
'Error when retrieving state : '.$state->error);
625 } elseif ($result == 0) {
626 throw new RestException(404,
'State not found');
647 $result = $country->fetch($id, $code, $iso);
650 throw new RestException(503,
'Error when retrieving country : '.$country->error);
651 } elseif ($result == 0) {
652 throw new RestException(404,
'Country not found');
678 public function getAvailability($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
682 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
683 throw new RestException(403);
686 $sql =
"SELECT rowid, code, label";
687 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_availability as t";
688 $sql .=
" WHERE t.active = ".((int) $active);
694 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
699 $sql .= $this->db->order($sortfield, $sortorder);
705 $offset = $limit * $page;
707 $sql .= $this->db->plimit($limit, $offset);
710 $result = $this->db->query($sql);
713 $num = $this->db->num_rows($result);
714 $min = min($num, ($limit <= 0 ? $num : $limit));
715 for ($i = 0; $i < $min; $i++) {
716 $list[] = $this->db->fetch_object($result);
719 throw new RestException(503, $this->db->lasterror());
756 if ($this->translations ==
null || $this->translations->getDefaultLang() !== $lang) {
758 $this->translations =
new Translate(
'', $conf);
759 $this->translations->setDefaultLang($lang);
760 $this->translations->loadLangs($dict);
763 $key = $prefix.$object->code;
765 $translation = $this->translations->trans($key);
766 if ($translation != $key) {
767 $object->label = html_entity_decode($translation);
791 public function getListOfEventTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $type =
'', $module =
'', $active = 1, $sqlfilters =
'')
795 $sql =
"SELECT id, code, type, libelle as label, module";
796 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_actioncomm as t";
797 $sql .=
" WHERE t.active = ".((int) $active);
799 $sql .=
" AND t.type LIKE '%".$this->db->escape($type).
"%'";
802 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
809 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
814 $sql .= $this->db->order($sortfield, $sortorder);
820 $offset = $limit * $page;
822 $sql .= $this->db->plimit($limit, $offset);
825 $result = $this->db->query($sql);
828 $num = $this->db->num_rows($result);
829 $min = min($num, ($limit <= 0 ? $num : $limit));
830 for ($i = 0; $i < $min; $i++) {
831 $list[] = $this->db->fetch_object($result);
834 throw new RestException(503,
'Error when retrieving list of events types : '.$this->db->lasterror());
858 public function getListOfExpenseReportsTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $module =
'', $active = 1, $sqlfilters =
'')
862 $sql =
"SELECT id, code, label, accountancy_code, active, module, position";
863 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees as t";
864 $sql .=
" WHERE t.active = ".((int) $active);
866 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
873 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
878 $sql .= $this->db->order($sortfield, $sortorder);
884 $offset = $limit * $page;
886 $sql .= $this->db->plimit($limit, $offset);
889 $result = $this->db->query($sql);
892 $num = $this->db->num_rows($result);
893 $min = min($num, ($limit <= 0 ? $num : $limit));
894 for ($i = 0; $i < $min; $i++) {
895 $list[] = $this->db->fetch_object($result);
898 throw new RestException(503,
'Error when retrieving list of expense report types : '.$this->db->lasterror());
924 public function getListOfContactTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $type =
'', $module =
'', $active = 1, $lang =
'', $sqlfilters =
'')
928 $sql =
"SELECT rowid, code, element as type, libelle as label, source, module, position";
929 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact as t";
930 $sql .=
" WHERE t.active = ".((int) $active);
932 $sql .=
" AND type LIKE '%".$this->db->escape($type).
"%'";
935 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
942 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
947 $sql .= $this->db->order($sortfield, $sortorder);
953 $offset = $limit * $page;
955 $sql .= $this->db->plimit($limit, $offset);
958 $result = $this->db->query($sql);
961 $num = $this->db->num_rows($result);
962 $min = min($num, ($limit <= 0 ? $num : $limit));
963 for ($i = 0; $i < $min; $i++) {
964 $contact_type = $this->db->fetch_object($result);
965 $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"));
966 $list[] = $contact_type;
969 throw new RestException(503,
'Error when retrieving list of contacts types : '.$this->db->lasterror());
993 public function getListOfCivilities($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $module =
'', $active = 1, $lang =
'', $sqlfilters =
'')
997 $sql =
"SELECT rowid, code, label, module";
998 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_civility as t";
999 $sql .=
" WHERE t.active = ".((int) $active);
1001 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
1007 if ($errormessage) {
1008 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1013 $sql .= $this->db->order($sortfield, $sortorder);
1019 $offset = $limit * $page;
1021 $sql .= $this->db->plimit($limit, $offset);
1024 $result = $this->db->query($sql);
1027 $num = $this->db->num_rows($result);
1028 $min = min($num, ($limit <= 0 ? $num : $limit));
1029 for ($i = 0; $i < $min; $i++) {
1030 $civility = $this->db->fetch_object($result);
1031 $this->
translateLabel($civility, $lang,
'Civility', array(
'dict'));
1032 $list[] = $civility;
1035 throw new RestException(503,
'Error when retrieving list of civility : '.$this->db->lasterror());
1058 public function getListOfCurrencies($multicurrency = 0, $sortfield =
"code_iso", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1061 $sql =
"SELECT t.code_iso, t.label, t.unicode";
1062 if (!empty($multicurrency)) {
1063 $sql .=
" , cr.date_sync, cr.rate ";
1065 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_currencies as t";
1066 if (!empty($multicurrency)) {
1067 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"multicurrency as m ON m.code=t.code_iso";
1068 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"multicurrency_rate as cr ON (m.rowid = cr.fk_multicurrency)";
1070 $sql .=
" WHERE t.active = ".((int) $active);
1071 if (!empty($multicurrency)) {
1072 $sql .=
" AND m.entity IN (".getEntity(
'multicurrency').
")";
1073 if (!empty($multicurrency) && $multicurrency != 2) {
1074 $sql .=
" AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM ".MAIN_DB_PREFIX.
"multicurrency_rate AS cr2 WHERE cr2.fk_multicurrency = m.rowid)";
1082 if ($errormessage) {
1083 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1088 $sql .= $this->db->order($sortfield, $sortorder);
1094 $offset = $limit * $page;
1096 $sql .= $this->db->plimit($limit, $offset);
1099 $result = $this->db->query($sql);
1102 $num = $this->db->num_rows($result);
1103 $min = min($num, ($limit <= 0 ? $num : $limit));
1104 for ($i = 0; $i < $min; $i++) {
1105 $list[] = $this->db->fetch_object($result);
1108 throw new RestException(503,
'Error when retrieving list of currency : '.$this->db->lasterror());
1128 public function getListOfExtrafields($sortfield =
"t.pos", $sortorder =
'ASC', $elementtype =
'', $sqlfilters =
'')
1132 if (!DolibarrApiAccess::$user->admin) {
1133 throw new RestException(403,
'Only an admin user can get list of extrafields');
1136 if ($elementtype ==
'thirdparty') {
1137 $elementtype =
'societe';
1139 if ($elementtype ==
'contact') {
1140 $elementtype =
'socpeople';
1143 $sql =
"SELECT t.rowid as id, t.name, t.entity, t.elementtype, t.label, t.type, t.size, t.fieldcomputed, t.fielddefault,";
1144 $sql .=
" t.fieldunique, t.fieldrequired, t.perms, t.enabled, t.pos, t.alwayseditable, t.param, t.list, t.printable,";
1145 $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";
1146 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1147 $sql .=
" WHERE t.entity IN (".getEntity(
'extrafields').
")";
1148 if (!empty($elementtype)) {
1149 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
1155 if ($errormessage) {
1156 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1160 $sql .= $this->db->order($sortfield, $sortorder);
1162 $resql = $this->db->query($sql);
1164 if ($this->db->num_rows($resql)) {
1165 while ($tab = $this->db->fetch_object($resql)) {
1167 $list[$tab->elementtype][$tab->name][
'id'] = $tab->id;
1168 $list[$tab->elementtype][$tab->name][
'type'] = $tab->type;
1169 $list[$tab->elementtype][$tab->name][
'label'] = $tab->label;
1170 $list[$tab->elementtype][$tab->name][
'size'] = $tab->size;
1171 $list[$tab->elementtype][$tab->name][
'elementtype'] = $tab->elementtype;
1172 $list[$tab->elementtype][$tab->name][
'default'] = $tab->fielddefault;
1173 $list[$tab->elementtype][$tab->name][
'computed'] = $tab->fieldcomputed;
1174 $list[$tab->elementtype][$tab->name][
'unique'] = $tab->fieldunique;
1175 $list[$tab->elementtype][$tab->name][
'required'] = $tab->fieldrequired;
1176 $list[$tab->elementtype][$tab->name][
'param'] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1177 $list[$tab->elementtype][$tab->name][
'pos'] = $tab->pos;
1178 $list[$tab->elementtype][$tab->name][
'alwayseditable'] = $tab->alwayseditable;
1179 $list[$tab->elementtype][$tab->name][
'perms'] = $tab->perms;
1180 $list[$tab->elementtype][$tab->name][
'list'] = $tab->list;
1181 $list[$tab->elementtype][$tab->name][
'printable'] = $tab->printable;
1182 $list[$tab->elementtype][$tab->name][
'totalizable'] = $tab->totalizable;
1183 $list[$tab->elementtype][$tab->name][
'langs'] = $tab->langs;
1184 $list[$tab->elementtype][$tab->name][
'help'] = $tab->help;
1185 $list[$tab->elementtype][$tab->name][
'css'] = $tab->css;
1186 $list[$tab->elementtype][$tab->name][
'cssview'] = $tab->cssview;
1187 $list[$tab->elementtype][$tab->name][
'csslist'] = $tab->csslist;
1188 $list[$tab->elementtype][$tab->name][
'fk_user_author'] = $tab->fk_user_author;
1189 $list[$tab->elementtype][$tab->name][
'fk_user_modif'] = $tab->fk_user_modif;
1190 $list[$tab->elementtype][$tab->name][
'datec'] = $tab->datec;
1191 $list[$tab->elementtype][$tab->name][
'tms'] = $tab->tms;
1195 throw new RestException(503,
'Error when retrieving list of extra fields : '.$this->db->lasterror());
1213 if (!DolibarrApiAccess::$user->admin) {
1214 throw new RestException(403,
'Only an admin user can delete an extrafield by attrname and elementtype');
1219 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1221 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1224 if (!$extrafields->delete($attrname, $elementtype)) {
1225 throw new RestException(500,
'Error when delete extrafield : '.$extrafields->error);
1231 'message' =>
'Extrafield deleted from attrname and elementtype'
1253 if (!DolibarrApiAccess::$user->admin) {
1254 throw new RestException(403,
'Only an admin user can get list of 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 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
1270 $sql .=
" AND t.name = '".$this->db->escape($attrname).
"'";
1272 $resql = $this->db->query($sql);
1274 if ($this->db->num_rows($resql)) {
1275 while ($tab = $this->db->fetch_object($resql)) {
1277 $answer[$tab->elementtype][$tab->name][
'id'] = $tab->id;
1278 $answer[$tab->elementtype][$tab->name][
'type'] = $tab->type;
1279 $answer[$tab->elementtype][$tab->name][
'label'] = $tab->label;
1280 $answer[$tab->elementtype][$tab->name][
'size'] = $tab->size;
1281 $answer[$tab->elementtype][$tab->name][
'elementtype'] = $tab->elementtype;
1282 $answer[$tab->elementtype][$tab->name][
'default'] = $tab->fielddefault;
1283 $answer[$tab->elementtype][$tab->name][
'computed'] = $tab->fieldcomputed;
1284 $answer[$tab->elementtype][$tab->name][
'unique'] = $tab->fieldunique;
1285 $answer[$tab->elementtype][$tab->name][
'required'] = $tab->fieldrequired;
1286 $answer[$tab->elementtype][$tab->name][
'param'] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1287 $answer[$tab->elementtype][$tab->name][
'pos'] = $tab->pos;
1288 $answer[$tab->elementtype][$tab->name][
'alwayseditable'] = $tab->alwayseditable;
1289 $answer[$tab->elementtype][$tab->name][
'perms'] = $tab->perms;
1290 $answer[$tab->elementtype][$tab->name][
'list'] = $tab->list;
1291 $answer[$tab->elementtype][$tab->name][
'printable'] = $tab->printable;
1292 $answer[$tab->elementtype][$tab->name][
'totalizable'] = $tab->totalizable;
1293 $answer[$tab->elementtype][$tab->name][
'langs'] = $tab->langs;
1294 $answer[$tab->elementtype][$tab->name][
'help'] = $tab->help;
1295 $answer[$tab->elementtype][$tab->name][
'css'] = $tab->css;
1296 $answer[$tab->elementtype][$tab->name][
'cssview'] = $tab->cssview;
1297 $answer[$tab->elementtype][$tab->name][
'csslist'] = $tab->csslist;
1298 $answer[$tab->elementtype][$tab->name][
'fk_user_author'] = $tab->fk_user_author;
1299 $answer[$tab->elementtype][$tab->name][
'fk_user_modif'] = $tab->fk_user_modif;
1300 $answer[$tab->elementtype][$tab->name][
'datec'] = $tab->datec;
1301 $answer[$tab->elementtype][$tab->name][
'tms'] = $tab->tms;
1304 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1307 throw new RestException(503,
'Error when retrieving list of extra fields : '.$this->db->lasterror());
1328 if (!DolibarrApiAccess::$user->admin) {
1329 throw new RestException(403,
'Only an admin user can create an extrafield');
1334 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1336 throw new RestException(409,
'Duplicate extrafield already found from attrname and elementtype');
1342 foreach ($request_data as $field => $value) {
1343 $extrafields->$field = $this->
_checkValForAPI($field, $value, $extrafields);
1346 $entity = DolibarrApiAccess::$user->entity;
1347 if (empty($entity)) {
1354 if ($request_data[
'label']) {
1355 $label = $request_data[
'label'];
1357 throw new RestException(400,
"label field absent in json at root level");
1360 $alwayseditable = $request_data[
'alwayseditable'];
1361 $default_value = $request_data[
'default_value'];
1362 $totalizable = $request_data[
'totalizable'];
1363 $printable = $request_data[
'printable'];
1364 $required = $request_data[
'required'];
1365 $langfile = $request_data[
'langfile'];
1366 $computed = $request_data[
'computed'];
1367 $unique = $request_data[
'unique'];
1368 $param = $request_data[
'param'];
1369 $perms = $request_data[
'perms'];
1370 $size = $request_data[
'size'];
1371 $type = $request_data[
'type'];
1372 $list = $request_data[
'list'];
1373 $help = $request_data[
'help'];
1374 $pos = $request_data[
'pos'];
1375 $moreparams = array();
1377 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)) {
1378 throw new RestException(500,
'Error creating extrafield', array_merge(array($extrafields->errno), $extrafields->errors));
1381 $sql =
"SELECT t.rowid as id";
1382 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1383 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1384 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1386 $resql = $this->db->query($sql);
1388 if ($this->db->num_rows($resql)) {
1389 $tab = $this->db->fetch_object($resql);
1390 $id = (int) $tab->id;
1417 if (!DolibarrApiAccess::$user->admin) {
1418 throw new RestException(403,
'Only an admin user can create an extrafield');
1423 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1425 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1428 foreach ($request_data as $field => $value) {
1429 $extrafields->$field = $this->
_checkValForAPI($field, $value, $extrafields);
1432 $entity = DolibarrApiAccess::$user->entity;
1433 if (empty($entity)) {
1439 if ($request_data[
'label']) {
1440 $label = $request_data[
'label'];
1442 throw new RestException(400,
"label field absent in json at root level");
1445 $alwayseditable = $request_data[
'alwayseditable'];
1446 $default_value = $request_data[
'default_value'];
1447 $totalizable = $request_data[
'totalizable'];
1448 $printable = $request_data[
'printable'];
1449 $required = $request_data[
'required'];
1450 $langfile = $request_data[
'langfile'];
1451 $computed = $request_data[
'computed'];
1452 $unique = $request_data[
'unique'];
1453 $param = $request_data[
'param'];
1454 $perms = $request_data[
'perms'];
1455 $size = $request_data[
'size'];
1456 $type = $request_data[
'type'];
1457 $list = $request_data[
'list'];
1458 $help = $request_data[
'help'];
1459 $pos = $request_data[
'pos'];
1460 $moreparams = array();
1462 dol_syslog(get_class($this).
'::updateExtraField', LOG_DEBUG);
1463 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)) {
1464 throw new RestException(500,
'Error updating extrafield', array_merge(array($extrafields->errno), $extrafields->errors));
1467 $sql =
"SELECT t.rowid as id";
1468 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1469 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1470 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1472 $resql = $this->db->query($sql);
1474 if ($this->db->num_rows($resql)) {
1475 $tab = $this->db->fetch_object($resql);
1476 $id = (int) $tab->id;
1505 public function getListOfTowns($sortfield =
"zip,town", $sortorder =
'ASC', $limit = 100, $page = 0, $zipcode =
'', $town =
'', $active = 1, $sqlfilters =
'')
1509 $sql =
"SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
1510 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ziptown as t";
1511 $sql .=
" WHERE t.active = ".((int) $active);
1513 $sql .=
" AND t.zip LIKE '%".$this->db->escape($zipcode).
"%'";
1516 $sql .=
" AND t.town LIKE '%".$this->db->escape($town).
"%'";
1522 if ($errormessage) {
1523 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1528 $sql .= $this->db->order($sortfield, $sortorder);
1534 $offset = $limit * $page;
1536 $sql .= $this->db->plimit($limit, $offset);
1539 $result = $this->db->query($sql);
1542 $num = $this->db->num_rows($result);
1543 $min = min($num, ($limit <= 0 ? $num : $limit));
1544 for ($i = 0; $i < $min; $i++) {
1545 $list[] = $this->db->fetch_object($result);
1548 throw new RestException(503,
'Error when retrieving list of towns : '.$this->db->lasterror());
1572 public function getPaymentTerms($sortfield =
"sortorder", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1576 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire') && !DolibarrApiAccess::$user->hasRight(
'commande',
'lire') && !DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1577 throw new RestException(403);
1580 $sql =
"SELECT rowid as id, code, sortorder, libelle as label, libelle_facture as descr, type_cdr, nbjour, decalage, module";
1581 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_payment_term as t";
1582 $sql .=
" WHERE t.entity IN (".getEntity(
'c_payment_term').
")";
1583 $sql .=
" AND t.active = ".((int) $active);
1588 if ($errormessage) {
1589 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1594 $sql .= $this->db->order($sortfield, $sortorder);
1600 $offset = $limit * $page;
1602 $sql .= $this->db->plimit($limit, $offset);
1605 $result = $this->db->query($sql);
1608 $num = $this->db->num_rows($result);
1609 $min = min($num, ($limit <= 0 ? $num : $limit));
1610 for ($i = 0; $i < $min; $i++) {
1611 $list[] = $this->db->fetch_object($result);
1614 throw new RestException(503, $this->db->lasterror());
1636 public function getShippingModes($limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
1640 $sql =
"SELECT rowid as id, code, libelle as label, description, tracking, module";
1641 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as t";
1642 $sql .=
" WHERE t.entity IN (".getEntity(
'c_shipment_mode').
")";
1643 $sql .=
" AND t.active = ".((int) $active);
1648 if ($errormessage) {
1649 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1660 $offset = $limit * $page;
1662 $sql .= $this->db->plimit($limit, $offset);
1665 $result = $this->db->query($sql);
1668 $num = $this->db->num_rows($result);
1669 $min = min($num, ($limit <= 0 ? $num : $limit));
1670 for ($i = 0; $i < $min; $i++) {
1671 $method = $this->db->fetch_object($result);
1676 throw new RestException(503, $this->db->lasterror());
1698 public function getListOfMeasuringUnits($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1702 $sql =
"SELECT t.rowid, t.code, t.label,t.short_label, t.active, t.scale, t.unit_type";
1703 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_units as t";
1704 $sql .=
" WHERE t.active = ".((int) $active);
1709 if ($errormessage) {
1710 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1715 $sql .= $this->db->order($sortfield, $sortorder);
1721 $offset = $limit * $page;
1723 $sql .= $this->db->plimit($limit, $offset);
1726 $result = $this->db->query($sql);
1729 $num = $this->db->num_rows($result);
1730 $min = min($num, ($limit <= 0 ? $num : $limit));
1731 for ($i = 0; $i < $min; $i++) {
1732 $list[] = $this->db->fetch_object($result);
1735 throw new RestException(503,
'Error when retrieving list of measuring units: '.$this->db->lasterror());
1758 public function getListOfLegalForm($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $active = 1, $sqlfilters =
'')
1762 $sql =
"SELECT t.rowid, t.code, t.fk_pays, t.libelle, t.isvatexempted, t.active, t.module, t.position";
1763 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_forme_juridique as t";
1764 $sql .=
" WHERE t.active = ".((int) $active);
1766 $sql .=
" AND t.fk_pays = ".((int) $country);
1772 if ($errormessage) {
1773 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1778 $sql .= $this->db->order($sortfield, $sortorder);
1784 $offset = $limit * $page;
1786 $sql .= $this->db->plimit($limit, $offset);
1789 $result = $this->db->query($sql);
1792 $num = $this->db->num_rows($result);
1793 $min = min($num, ($limit <= 0 ? $num : $limit));
1794 for ($i = 0; $i < $min; $i++) {
1795 $list[] = $this->db->fetch_object($result);
1798 throw new RestException(503,
'Error when retrieving list of legal form: '.$this->db->lasterror());
1820 public function getListOfStaff($sortfield =
"id", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1824 $sql =
"SELECT t.id, t.code, t.libelle, t.active, t.module";
1825 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_effectif as t";
1826 $sql .=
" WHERE t.active = ".((int) $active);
1831 if ($errormessage) {
1832 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1837 $sql .= $this->db->order($sortfield, $sortorder);
1843 $offset = $limit * $page;
1845 $sql .= $this->db->plimit($limit, $offset);
1848 $result = $this->db->query($sql);
1851 $num = $this->db->num_rows($result);
1852 $min = min($num, ($limit <= 0 ? $num : $limit));
1853 for ($i = 0; $i < $min; $i++) {
1854 $list[] = $this->db->fetch_object($result);
1857 throw new RestException(503,
'Error when retrieving list of staff: '.$this->db->lasterror());
1879 public function getListOfsocialNetworks($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1883 if (!isModEnabled(
'socialnetworks')) {
1884 throw new RestException(400,
'API not available: this dictionary is not enabled by setup');
1889 $sql =
"SELECT t.rowid, t.entity, t.code, t.label, t.url, t.icon, t.active";
1890 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_socialnetworks as t";
1891 $sql .=
" WHERE t.entity IN (".getEntity(
'c_socialnetworks').
")";
1892 $sql .=
" AND t.active = ".((int) $active);
1897 if ($errormessage) {
1898 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1903 $sql .= $this->db->order($sortfield, $sortorder);
1909 $offset = $limit * $page;
1911 $sql .= $this->db->plimit($limit, $offset);
1914 $result = $this->db->query($sql);
1917 $num = $this->db->num_rows($result);
1918 $min = min($num, ($limit <= 0 ? $num : $limit));
1919 for ($i = 0; $i < $min; $i++) {
1920 $list[] = $this->db->fetch_object($result);
1923 throw new RestException(503,
'Error when retrieving list of social networks: '.$this->db->lasterror());
1946 public function getTicketsCategories($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
1950 $sql =
"SELECT rowid, code, pos, label, use_default, description";
1951 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_category as t";
1952 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_category').
")";
1953 $sql .=
" AND t.active = ".((int) $active);
1958 if ($errormessage) {
1959 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1964 $sql .= $this->db->order($sortfield, $sortorder);
1970 $offset = $limit * $page;
1972 $sql .= $this->db->plimit($limit, $offset);
1975 $result = $this->db->query($sql);
1978 $num = $this->db->num_rows($result);
1979 $min = min($num, ($limit <= 0 ? $num : $limit));
1980 for ($i = 0; $i < $min; $i++) {
1981 $category = $this->db->fetch_object($result);
1982 $this->
translateLabel($category, $lang,
'TicketCategoryShort', array(
'ticket'));
1983 $list[] = $category;
1986 throw new RestException(503,
'Error when retrieving list of ticket categories : '.$this->db->lasterror());
2009 public function getTicketsSeverities($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2013 $sql =
"SELECT rowid, code, pos, label, use_default, color, description";
2014 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_severity as t";
2015 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_severity').
")";
2016 $sql .=
" AND t.active = ".((int) $active);
2021 if ($errormessage) {
2022 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2027 $sql .= $this->db->order($sortfield, $sortorder);
2033 $offset = $limit * $page;
2035 $sql .= $this->db->plimit($limit, $offset);
2038 $result = $this->db->query($sql);
2041 $num = $this->db->num_rows($result);
2042 $min = min($num, ($limit <= 0 ? $num : $limit));
2043 for ($i = 0; $i < $min; $i++) {
2044 $severity = $this->db->fetch_object($result);
2045 $this->
translateLabel($severity, $lang,
'TicketSeverityShort', array(
'ticket'));
2046 $list[] = $severity;
2049 throw new RestException(503,
'Error when retrieving list of ticket severities : '.$this->db->lasterror());
2072 public function getTicketsTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2076 $sql =
"SELECT rowid, code, pos, label, use_default, description";
2077 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_type as t";
2078 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_type').
")";
2079 $sql .=
" AND t.active = ".((int) $active);
2085 if ($errormessage) {
2086 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2091 $sql .= $this->db->order($sortfield, $sortorder);
2097 $offset = $limit * $page;
2099 $sql .= $this->db->plimit($limit, $offset);
2102 $result = $this->db->query($sql);
2105 $num = $this->db->num_rows($result);
2106 $min = min($num, ($limit <= 0 ? $num : $limit));
2107 for ($i = 0; $i < $min; $i++) {
2108 $type =$this->db->fetch_object($result);
2109 $this->
translateLabel($type, $lang,
'TicketTypeShort', array(
'ticket'));
2113 throw new RestException(503,
'Error when retrieving list of ticket types : '.$this->db->lasterror());
2135 public function getListOfIncoterms($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2139 $sql =
"SELECT rowid, code, active";
2140 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_incoterms as t";
2141 $sql .=
" WHERE 1=1";
2147 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2149 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
2150 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
2154 $sql .= $this->db->order($sortfield, $sortorder);
2160 $offset = $limit * $page;
2162 $sql .= $this->db->plimit($limit, $offset);
2165 $result = $this->db->query($sql);
2168 $num = $this->db->num_rows($result);
2169 $min = min($num, ($limit <= 0 ? $num : $limit));
2170 for ($i = 0; $i < $min; $i++) {
2171 $type =$this->db->fetch_object($result);
2175 throw new RestException(503,
'Error when retrieving list of incoterm types : '.$this->db->lasterror());
2192 global $conf, $mysoc;
2194 if (!DolibarrApiAccess::$user->admin
2195 && (!
getDolGlobalString(
'API_LOGINS_ALLOWED_FOR_GET_COMPANY') || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_GET_COMPANY)) {
2196 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');
2199 unset($mysoc->pays);
2200 unset($mysoc->note);
2203 unset($mysoc->lines);
2205 unset($mysoc->effectif);
2206 unset($mysoc->effectif_id);
2207 unset($mysoc->forme_juridique_code);
2208 unset($mysoc->forme_juridique);
2209 unset($mysoc->mode_reglement_supplier_id);
2210 unset($mysoc->cond_reglement_supplier_id);
2211 unset($mysoc->transport_mode_supplier_id);
2212 unset($mysoc->fk_prospectlevel);
2214 unset($mysoc->total_ht);
2215 unset($mysoc->total_tva);
2216 unset($mysoc->total_localtax1);
2217 unset($mysoc->total_localtax2);
2218 unset($mysoc->total_ttc);
2220 unset($mysoc->lastname);
2221 unset($mysoc->firstname);
2222 unset($mysoc->civility_id);
2224 unset($mysoc->client);
2225 unset($mysoc->prospect);
2226 unset($mysoc->fournisseur);
2227 unset($mysoc->contact_id);
2229 unset($mysoc->fk_incoterms);
2230 unset($mysoc->label_incoterms);
2231 unset($mysoc->location_incoterms);
2251 $sql =
"SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
2252 $sql .=
" FROM ".MAIN_DB_PREFIX.
"establishment as e";
2253 $sql .=
" WHERE e.entity IN (".getEntity(
'establishment').
')';
2258 $result = $this->db->query($sql);
2261 $num = $this->db->num_rows($result);
2262 $min = min($num, ($limit <= 0 ? $num : $limit));
2263 for ($i = 0; $i < $min; $i++) {
2264 $list[] = $this->db->fetch_object($result);
2267 throw new RestException(503,
'Error when retrieving list of establishments : '.$this->db->lasterror());
2288 $result = $establishment->fetch($id);
2290 throw new RestException(503,
'Error when retrieving establishment : '.$establishment->error);
2291 } elseif ($result == 0) {
2292 throw new RestException(404,
'Establishment not found');
2315 if (!DolibarrApiAccess::$user->admin
2317 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');
2320 if (!preg_match(
'/^[a-zA-Z0-9_]+$/', $constantname) || !isset($conf->global->$constantname)) {
2321 throw new RestException(400,
'Error Bad or unknown value for constantname');
2324 throw new RestException(403,
'Forbidden. This parameter can not be read with APIs');
2344 global $langs, $conf;
2346 if (!DolibarrApiAccess::$user->admin
2347 && (!
getDolGlobalString(
'API_LOGINS_ALLOWED_FOR_INTEGRITY_CHECK') || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_INTEGRITY_CHECK)) {
2348 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');
2351 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2352 require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
2354 $langs->load(
"admin");
2356 $outexpectedchecksum =
'';
2357 $outcurrentchecksum =
'';
2360 $file_list = array(
'missing' => array(),
'updated' => array());
2365 $xmlfile = DOL_DOCUMENT_ROOT.
'/install/'.$xmlshortfile;
2366 if (!preg_match(
'/\.zip$/i', $xmlfile) &&
dol_is_file($xmlfile.
'.zip')) {
2367 $xmlfile = $xmlfile.
'.zip';
2371 $xmlremote = (($target ==
'default' || $target ==
'local') ?
'' : $target);
2375 $param =
'MAIN_FILECHECK_URL_'.DOL_VERSION;
2379 if (empty($xmlremote)) {
2380 $xmlremote =
'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.
'.xml';
2382 if ($xmlremote && !preg_match(
'/^https?:\/\//i', $xmlremote)) {
2383 $langs->load(
"errors");
2384 throw new RestException(500, $langs->trans(
"ErrorURLMustStartWithHttp", $xmlremote));
2386 if ($xmlremote && !preg_match(
'/\.xml$/', $xmlremote)) {
2387 $langs->load(
"errors");
2388 throw new RestException(500, $langs->trans(
"ErrorURLMustEndWith", $xmlremote,
'.xml'));
2391 if (LIBXML_VERSION < 20900) {
2395 libxml_disable_entity_loader(
true);
2398 if ($target ==
'local') {
2400 $xml = simplexml_load_file($xmlfile);
2402 throw new RestException(500, $langs->trans(
'XmlNotFound').
': /install/'.$xmlshortfile);
2405 $xmlarray =
getURLContent($xmlremote,
'GET',
'', 1, array(), array(
'http',
'https'), 0);
2408 if (!$xmlarray[
'curl_error_no'] && $xmlarray[
'http_code'] !=
'400' && $xmlarray[
'http_code'] !=
'404') {
2409 $xmlfile = $xmlarray[
'content'];
2411 $xml = simplexml_load_string($xmlfile,
'SimpleXMLElement', LIBXML_NOCDATA|LIBXML_NONET);
2413 $errormsg = $langs->trans(
'XmlNotFound').
': '.$xmlremote.
' - '.$xmlarray[
'http_code'].(($xmlarray[
'http_code'] == 400 && $xmlarray[
'content']) ?
' '.$xmlarray[
'content'] :
'').
' '.$xmlarray[
'curl_error_no'].
' '.$xmlarray[
'curl_error_msg'];
2414 throw new RestException(500, $errormsg);
2419 $checksumconcat = array();
2420 $file_list = array();
2424 if (is_object($xml->dolibarr_constants[0])) {
2427 $out .=
'<div class="div-table-responsive-no-min">';
2428 $out .=
'<table class="noborder">';
2429 $out .=
'<tr class="liste_titre">';
2430 $out .=
'<td>#</td>';
2431 $out .=
'<td>'.$langs->trans(
"Constant").
'</td>';
2432 $out .=
'<td class="center">'.$langs->trans(
"ExpectedValue").
'</td>';
2433 $out .=
'<td class="center">'.$langs->trans(
"Value").
'</td>';
2434 $out .=
'</tr>'.
"\n";
2437 foreach ($xml->dolibarr_constants[0]->constant as $constant) {
2438 $constname = $constant[
'name'];
2439 $constvalue = (string) $constant;
2440 $constvalue = (empty($constvalue) ?
'0' : $constvalue);
2446 $valueforchecksum = (empty($value) ?
'0' : $value);
2448 $checksumconcat[] = $valueforchecksum;
2451 $out .=
'<tr class="oddeven">';
2452 $out .=
'<td>'.$i.
'</td>'.
"\n";
2453 $out .=
'<td>'.dol_escape_htmltag($constname).
'</td>'.
"\n";
2454 $out .=
'<td class="center">'.dol_escape_htmltag($constvalue).
'</td>'.
"\n";
2455 $out .=
'<td class="center">'.dol_escape_htmltag($valueforchecksum).
'</td>'.
"\n";
2460 $out .=
'<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2469 if (is_object($xml->dolibarr_htdocs_dir[0])) {
2470 $includecustom = (empty($xml->dolibarr_htdocs_dir[0][
'includecustom']) ? 0 : $xml->dolibarr_htdocs_dir[0][
'includecustom']);
2473 $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)$';
2474 $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)$';
2475 $scanfiles =
dol_dir_list(DOL_DOCUMENT_ROOT,
'files', 1, $regextoinclude, $regextoexclude);
2478 $ret =
getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0],
'', DOL_DOCUMENT_ROOT, $checksumconcat);
2480 foreach ($scanfiles as $keyfile => $valfile) {
2481 $tmprelativefilename = preg_replace(
'/^'.preg_quote(DOL_DOCUMENT_ROOT,
'/').
'/',
'', $valfile[
'fullname']);
2482 if (!in_array($tmprelativefilename, $file_list[
'insignature'])) {
2483 $md5newfile = @md5_file($valfile[
'fullname']);
2484 $file_list[
'added'][] = array(
'filename'=>$tmprelativefilename,
'md5'=>$md5newfile);
2491 $out .=
'<div class="div-table-responsive-no-min">';
2492 $out .=
'<table class="noborder">';
2493 $out .=
'<tr class="liste_titre">';
2494 $out .=
'<td>#</td>';
2495 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2496 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2497 $out .=
'</tr>'.
"\n";
2498 $tmpfilelist =
dol_sort_array($file_list[
'missing'],
'filename');
2499 if (is_array($tmpfilelist) && count($tmpfilelist)) {
2501 foreach ($tmpfilelist as $file) {
2503 $out .=
'<tr class="oddeven">';
2504 $out .=
'<td>'.$i.
'</td>'.
"\n";
2505 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2506 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2510 $out .=
'<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2521 $out .=
'<div class="div-table-responsive-no-min">';
2522 $out .=
'<table class="noborder">';
2523 $out .=
'<tr class="liste_titre">';
2524 $out .=
'<td>#</td>';
2525 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2526 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2527 $out .=
'<td class="center">'.$langs->trans(
"CurrentChecksum").
'</td>';
2528 $out .=
'<td class="right">'.$langs->trans(
"Size").
'</td>';
2529 $out .=
'<td class="right">'.$langs->trans(
"DateModification").
'</td>';
2530 $out .=
'</tr>'.
"\n";
2531 $tmpfilelist2 =
dol_sort_array($file_list[
'updated'],
'filename');
2532 if (is_array($tmpfilelist2) && count($tmpfilelist2)) {
2534 foreach ($tmpfilelist2 as $file) {
2536 $out .=
'<tr class="oddeven">';
2537 $out .=
'<td>'.$i.
'</td>'.
"\n";
2538 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2539 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2540 $out .=
'<td class="center">'.$file[
'md5'].
'</td>'.
"\n";
2541 $size =
dol_filesize(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']);
2542 $totalsize += $size;
2543 $out .=
'<td class="right">'.dol_print_size($size).
'</td>'.
"\n";
2544 $out .=
'<td class="right">'.dol_print_date(
dol_filemtime(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']),
'dayhour').
'</td>'.
"\n";
2547 $out .=
'<tr class="liste_total">';
2548 $out .=
'<td></td>'.
"\n";
2549 $out .=
'<td>'.$langs->trans(
"Total").
'</td>'.
"\n";
2550 $out .=
'<td align="center"></td>'.
"\n";
2551 $out .=
'<td align="center"></td>'.
"\n";
2552 $out .=
'<td class="right">'.dol_print_size($totalsize).
'</td>'.
"\n";
2553 $out .=
'<td class="right"></td>'.
"\n";
2556 $out .=
'<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2567 $out .=
'<div class="div-table-responsive-no-min">';
2568 $out .=
'<table class="noborder">';
2569 $out .=
'<tr class="liste_titre">';
2570 $out .=
'<td>#</td>';
2571 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2572 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2573 $out .=
'<td class="center">'.$langs->trans(
"CurrentChecksum").
'</td>';
2574 $out .=
'<td class="right">'.$langs->trans(
"Size").
'</td>';
2575 $out .=
'<td class="right">'.$langs->trans(
"DateModification").
'</td>';
2576 $out .=
'</tr>'.
"\n";
2578 if (is_array($tmpfilelist3) && count($tmpfilelist3)) {
2580 foreach ($tmpfilelist3 as $file) {
2582 $out .=
'<tr class="oddeven">';
2583 $out .=
'<td>'.$i.
'</td>'.
"\n";
2584 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2585 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2586 $out .=
'<td class="center">'.$file[
'md5'].
'</td>'.
"\n";
2587 $size =
dol_filesize(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']);
2588 $totalsize += $size;
2589 $out .=
'<td class="right">'.dol_print_size($size).
'</td>'.
"\n";
2590 $out .=
'<td class="right">'.dol_print_date(
dol_filemtime(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']),
'dayhour').
'</td>'.
"\n";
2593 $out .=
'<tr class="liste_total">';
2594 $out .=
'<td></td>'.
"\n";
2595 $out .=
'<td>'.$langs->trans(
"Total").
'</td>'.
"\n";
2596 $out .=
'<td align="center"></td>'.
"\n";
2597 $out .=
'<td align="center"></td>'.
"\n";
2598 $out .=
'<td class="right">'.dol_print_size($totalsize).
'</td>'.
"\n";
2599 $out .=
'<td class="right"></td>'.
"\n";
2602 $out .=
'<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2609 if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) {
2615 throw new RestException(500,
'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile);
2620 asort($checksumconcat);
2621 $checksumget = md5(implode(
',', $checksumconcat));
2622 $checksumtoget = trim((
string) $xml->dolibarr_htdocs_dir_checksum);
2624 $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans(
"Unknown"));
2625 if ($checksumget == $checksumtoget) {
2626 if (count($file_list[
'added'])) {
2627 $resultcode =
'warning';
2628 $resultcomment =
'FileIntegrityIsOkButFilesWereAdded';
2630 $outcurrentchecksum = $checksumget;
2633 $resultcomment =
'Success';
2635 $outcurrentchecksum = $checksumget;
2638 $resultcode =
'error';
2639 $resultcomment =
'Error';
2641 $outcurrentchecksum = $checksumget;
2644 throw new RestException(404,
'No signature file known');
2647 return array(
'resultcode'=>$resultcode,
'resultcomment'=>$resultcomment,
'expectedchecksum'=> $outexpectedchecksum,
'currentchecksum'=> $outcurrentchecksum,
'out'=>$out);
2664 if (!DolibarrApiAccess::$user->admin
2665 && (!
getDolGlobalString(
'API_LOGINS_ALLOWED_FOR_GET_MODULES') || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_GET_MODULES)) {
2666 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');
2669 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.
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 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).