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);
282 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
286 $sql .= $this->db->order($sortfield, $sortorder);
292 $offset = $limit * $page;
294 $sql .= $this->db->plimit($limit, $offset);
297 $result = $this->db->query($sql);
300 $num = $this->db->num_rows($result);
301 $min = min($num, ($limit <= 0 ? $num : $limit));
302 for ($i = 0; $i < $min; $i++) {
303 $obj = $this->db->fetch_object($result);
304 $region =
new Cregion($this->db);
305 if ($region->fetch($obj->rowid) > 0) {
306 if (empty($filter) || stripos($region->name, $filter) !==
false) {
312 throw new RestException(503,
'Error when retrieving list of regions');
372 public function getListOfStates($sortfield =
"code_departement", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $filter =
'', $sqlfilters =
'')
378 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.
"c_departements as t";
380 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as d ON t.fk_region = d.code_region";
382 $sql .=
" WHERE 1 = 1";
384 $sql .=
" AND d.fk_pays = ".((int) $country);
391 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
395 $sql .= $this->db->order($sortfield, $sortorder);
401 $offset = $limit * $page;
403 $sql .= $this->db->plimit($limit, $offset);
406 $result = $this->db->query($sql);
409 $num = $this->db->num_rows($result);
410 $min = min($num, ($limit <= 0 ? $num : $limit));
411 for ($i = 0; $i < $min; $i++) {
412 $obj = $this->db->fetch_object($result);
413 $state =
new Cstate($this->db);
414 if ($state->fetch($obj->rowid) > 0) {
415 if (empty($filter) || stripos($state->label, $filter) !==
false) {
421 throw new RestException(503,
'Error when retrieving list of states');
481 public function getListOfCountries($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $filter =
'', $lang =
'', $sqlfilters =
'')
487 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"c_country as t";
488 $sql .=
" WHERE 1 = 1";
494 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
498 $sql .= $this->db->order($sortfield, $sortorder);
504 $offset = $limit * $page;
506 $sql .= $this->db->plimit($limit, $offset);
509 $result = $this->db->query($sql);
512 $num = $this->db->num_rows($result);
513 $min = min($num, ($limit <= 0 ? $num : $limit));
514 for ($i = 0; $i < $min; $i++) {
515 $obj = $this->db->fetch_object($result);
517 if ($country->fetch($obj->rowid) > 0) {
522 if (empty($filter) || stripos($country->label, $filter) !==
false) {
528 throw new RestException(503,
'Error when retrieving list of countries');
596 $region =
new Cregion($this->db);
598 $result = $region->fetch($id, $code);
600 throw new RestException(503,
'Error when retrieving region : '.$region->error);
601 } elseif ($result == 0) {
602 throw new RestException(404,
'Region not found');
619 $state =
new Cstate($this->db);
621 $result = $state->fetch($id, $code);
623 throw new RestException(503,
'Error when retrieving state : '.$state->error);
624 } elseif ($result == 0) {
625 throw new RestException(404,
'State not found');
646 $result = $country->fetch($id, $code, $iso);
649 throw new RestException(503,
'Error when retrieving country : '.$country->error);
650 } elseif ($result == 0) {
651 throw new RestException(404,
'Country not found');
677 public function getAvailability($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
681 if (!DolibarrApiAccess::$user->hasRight(
'commande',
'lire')) {
682 throw new RestException(403);
685 $sql =
"SELECT rowid, code, label";
686 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_availability as t";
687 $sql .=
" WHERE t.active = ".((int) $active);
693 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
698 $sql .= $this->db->order($sortfield, $sortorder);
704 $offset = $limit * $page;
706 $sql .= $this->db->plimit($limit, $offset);
709 $result = $this->db->query($sql);
712 $num = $this->db->num_rows($result);
713 $min = min($num, ($limit <= 0 ? $num : $limit));
714 for ($i = 0; $i < $min; $i++) {
715 $list[] = $this->db->fetch_object($result);
718 throw new RestException(503, $this->db->lasterror());
755 if ($this->translations ==
null || $this->translations->getDefaultLang() !== $lang) {
757 $this->translations =
new Translate(
'', $conf);
758 $this->translations->setDefaultLang($lang);
759 $this->translations->loadLangs($dict);
762 $key = $prefix.$object->code;
764 $translation = $this->translations->trans($key);
765 if ($translation != $key) {
766 $object->label = html_entity_decode($translation);
790 public function getListOfEventTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $type =
'', $module =
'', $active = 1, $sqlfilters =
'')
794 $sql =
"SELECT id, code, type, libelle as label, module";
795 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_actioncomm as t";
796 $sql .=
" WHERE t.active = ".((int) $active);
798 $sql .=
" AND t.type LIKE '%".$this->db->escape($type).
"%'";
801 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
808 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
813 $sql .= $this->db->order($sortfield, $sortorder);
819 $offset = $limit * $page;
821 $sql .= $this->db->plimit($limit, $offset);
824 $result = $this->db->query($sql);
827 $num = $this->db->num_rows($result);
828 $min = min($num, ($limit <= 0 ? $num : $limit));
829 for ($i = 0; $i < $min; $i++) {
830 $list[] = $this->db->fetch_object($result);
833 throw new RestException(503,
'Error when retrieving list of events types : '.$this->db->lasterror());
857 public function getListOfExpenseReportsTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $module =
'', $active = 1, $sqlfilters =
'')
861 $sql =
"SELECT id, code, label, accountancy_code, active, module, position";
862 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees as t";
863 $sql .=
" WHERE t.active = ".((int) $active);
865 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
872 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
877 $sql .= $this->db->order($sortfield, $sortorder);
883 $offset = $limit * $page;
885 $sql .= $this->db->plimit($limit, $offset);
888 $result = $this->db->query($sql);
891 $num = $this->db->num_rows($result);
892 $min = min($num, ($limit <= 0 ? $num : $limit));
893 for ($i = 0; $i < $min; $i++) {
894 $list[] = $this->db->fetch_object($result);
897 throw new RestException(503,
'Error when retrieving list of expense report types : '.$this->db->lasterror());
923 public function getListOfContactTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $type =
'', $module =
'', $active = 1, $lang =
'', $sqlfilters =
'')
927 $sql =
"SELECT rowid, code, element as type, libelle as label, source, module, position";
928 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact as t";
929 $sql .=
" WHERE t.active = ".((int) $active);
931 $sql .=
" AND type LIKE '%".$this->db->escape($type).
"%'";
934 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
941 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
946 $sql .= $this->db->order($sortfield, $sortorder);
952 $offset = $limit * $page;
954 $sql .= $this->db->plimit($limit, $offset);
957 $result = $this->db->query($sql);
960 $num = $this->db->num_rows($result);
961 $min = min($num, ($limit <= 0 ? $num : $limit));
962 for ($i = 0; $i < $min; $i++) {
963 $contact_type = $this->db->fetch_object($result);
964 $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"));
965 $list[] = $contact_type;
968 throw new RestException(503,
'Error when retrieving list of contacts types : '.$this->db->lasterror());
992 public function getListOfCivilities($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $module =
'', $active = 1, $lang =
'', $sqlfilters =
'')
996 $sql =
"SELECT rowid, code, label, module";
997 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_civility as t";
998 $sql .=
" WHERE t.active = ".((int) $active);
1000 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
1006 if ($errormessage) {
1007 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1012 $sql .= $this->db->order($sortfield, $sortorder);
1018 $offset = $limit * $page;
1020 $sql .= $this->db->plimit($limit, $offset);
1023 $result = $this->db->query($sql);
1026 $num = $this->db->num_rows($result);
1027 $min = min($num, ($limit <= 0 ? $num : $limit));
1028 for ($i = 0; $i < $min; $i++) {
1029 $civility = $this->db->fetch_object($result);
1030 $this->
translateLabel($civility, $lang,
'Civility', array(
'dict'));
1031 $list[] = $civility;
1034 throw new RestException(503,
'Error when retrieving list of civility : '.$this->db->lasterror());
1057 public function getListOfCurrencies($multicurrency = 0, $sortfield =
"code_iso", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1060 $sql =
"SELECT t.code_iso, t.label, t.unicode";
1061 if (!empty($multicurrency)) {
1062 $sql .=
" , cr.date_sync, cr.rate ";
1064 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_currencies as t";
1065 if (!empty($multicurrency)) {
1066 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"multicurrency as m ON m.code=t.code_iso";
1067 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"multicurrency_rate as cr ON (m.rowid = cr.fk_multicurrency)";
1069 $sql .=
" WHERE t.active = ".((int) $active);
1070 if (!empty($multicurrency)) {
1071 $sql .=
" AND m.entity IN (".getEntity(
'multicurrency').
")";
1072 if (!empty($multicurrency) && $multicurrency != 2) {
1073 $sql .=
" AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM ".MAIN_DB_PREFIX.
"multicurrency_rate AS cr2 WHERE cr2.fk_multicurrency = m.rowid)";
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 $list[] = $this->db->fetch_object($result);
1107 throw new RestException(503,
'Error when retrieving list of currency : '.$this->db->lasterror());
1127 public function getListOfExtrafields($sortfield =
"t.pos", $sortorder =
'ASC', $elementtype =
'', $sqlfilters =
'')
1131 if (!DolibarrApiAccess::$user->admin) {
1132 throw new RestException(403,
'Only an admin user can get list of extrafields');
1135 if ($elementtype ==
'thirdparty') {
1136 $elementtype =
'societe';
1138 if ($elementtype ==
'contact') {
1139 $elementtype =
'socpeople';
1142 $sql =
"SELECT t.rowid as id, t.name, t.entity, t.elementtype, t.label, t.type, t.size, t.fieldcomputed, t.fielddefault,";
1143 $sql .=
" t.fieldunique, t.fieldrequired, t.perms, t.enabled, t.pos, t.alwayseditable, t.param, t.list, t.printable,";
1144 $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";
1145 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1146 $sql .=
" WHERE t.entity IN (".getEntity(
'extrafields').
")";
1147 if (!empty($elementtype)) {
1148 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
1154 if ($errormessage) {
1155 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1159 $sql .= $this->db->order($sortfield, $sortorder);
1161 $resql = $this->db->query($sql);
1163 if ($this->db->num_rows($resql)) {
1164 while ($tab = $this->db->fetch_object($resql)) {
1166 $list[$tab->elementtype][$tab->name][
'id'] = $tab->id;
1167 $list[$tab->elementtype][$tab->name][
'type'] = $tab->type;
1168 $list[$tab->elementtype][$tab->name][
'label'] = $tab->label;
1169 $list[$tab->elementtype][$tab->name][
'size'] = $tab->size;
1170 $list[$tab->elementtype][$tab->name][
'elementtype'] = $tab->elementtype;
1171 $list[$tab->elementtype][$tab->name][
'default'] = $tab->fielddefault;
1172 $list[$tab->elementtype][$tab->name][
'computed'] = $tab->fieldcomputed;
1173 $list[$tab->elementtype][$tab->name][
'unique'] = $tab->fieldunique;
1174 $list[$tab->elementtype][$tab->name][
'required'] = $tab->fieldrequired;
1175 $list[$tab->elementtype][$tab->name][
'param'] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1176 $list[$tab->elementtype][$tab->name][
'pos'] = $tab->pos;
1177 $list[$tab->elementtype][$tab->name][
'alwayseditable'] = $tab->alwayseditable;
1178 $list[$tab->elementtype][$tab->name][
'perms'] = $tab->perms;
1179 $list[$tab->elementtype][$tab->name][
'list'] = $tab->list;
1180 $list[$tab->elementtype][$tab->name][
'printable'] = $tab->printable;
1181 $list[$tab->elementtype][$tab->name][
'totalizable'] = $tab->totalizable;
1182 $list[$tab->elementtype][$tab->name][
'langs'] = $tab->langs;
1183 $list[$tab->elementtype][$tab->name][
'help'] = $tab->help;
1184 $list[$tab->elementtype][$tab->name][
'css'] = $tab->css;
1185 $list[$tab->elementtype][$tab->name][
'cssview'] = $tab->cssview;
1186 $list[$tab->elementtype][$tab->name][
'csslist'] = $tab->csslist;
1187 $list[$tab->elementtype][$tab->name][
'fk_user_author'] = $tab->fk_user_author;
1188 $list[$tab->elementtype][$tab->name][
'fk_user_modif'] = $tab->fk_user_modif;
1189 $list[$tab->elementtype][$tab->name][
'datec'] = $tab->datec;
1190 $list[$tab->elementtype][$tab->name][
'tms'] = $tab->tms;
1194 throw new RestException(503,
'Error when retrieving list of extra fields : '.$this->db->lasterror());
1212 if (!DolibarrApiAccess::$user->admin) {
1213 throw new RestException(403,
'Only an admin user can delete an extrafield by attrname and elementtype');
1218 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1220 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1223 if (!$extrafields->delete($attrname, $elementtype)) {
1224 throw new RestException(500,
'Error when delete extrafield : '.$extrafields->error);
1230 'message' =>
'Extrafield deleted from attrname and elementtype'
1252 if (!DolibarrApiAccess::$user->admin) {
1253 throw new RestException(403,
'Only an admin user can get list of extrafields');
1256 if ($elementtype ==
'thirdparty') {
1257 $elementtype =
'societe';
1259 if ($elementtype ==
'contact') {
1260 $elementtype =
'socpeople';
1263 $sql =
"SELECT t.rowid as id, t.name, t.entity, t.elementtype, t.label, t.type, t.size, t.fieldcomputed, t.fielddefault,";
1264 $sql .=
" t.fieldunique, t.fieldrequired, t.perms, t.enabled, t.pos, t.alwayseditable, t.param, t.list, t.printable,";
1265 $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";
1266 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1267 $sql .=
" WHERE t.entity IN (".getEntity(
'extrafields').
")";
1268 $sql .=
" AND t.elementtype = '".$this->db->escape($elementtype).
"'";
1269 $sql .=
" AND t.name = '".$this->db->escape($attrname).
"'";
1271 $resql = $this->db->query($sql);
1273 if ($this->db->num_rows($resql)) {
1274 while ($tab = $this->db->fetch_object($resql)) {
1276 $answer[$tab->elementtype][$tab->name][
'id'] = $tab->id;
1277 $answer[$tab->elementtype][$tab->name][
'type'] = $tab->type;
1278 $answer[$tab->elementtype][$tab->name][
'label'] = $tab->label;
1279 $answer[$tab->elementtype][$tab->name][
'size'] = $tab->size;
1280 $answer[$tab->elementtype][$tab->name][
'elementtype'] = $tab->elementtype;
1281 $answer[$tab->elementtype][$tab->name][
'default'] = $tab->fielddefault;
1282 $answer[$tab->elementtype][$tab->name][
'computed'] = $tab->fieldcomputed;
1283 $answer[$tab->elementtype][$tab->name][
'unique'] = $tab->fieldunique;
1284 $answer[$tab->elementtype][$tab->name][
'required'] = $tab->fieldrequired;
1285 $answer[$tab->elementtype][$tab->name][
'param'] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1286 $answer[$tab->elementtype][$tab->name][
'pos'] = $tab->pos;
1287 $answer[$tab->elementtype][$tab->name][
'alwayseditable'] = $tab->alwayseditable;
1288 $answer[$tab->elementtype][$tab->name][
'perms'] = $tab->perms;
1289 $answer[$tab->elementtype][$tab->name][
'list'] = $tab->list;
1290 $answer[$tab->elementtype][$tab->name][
'printable'] = $tab->printable;
1291 $answer[$tab->elementtype][$tab->name][
'totalizable'] = $tab->totalizable;
1292 $answer[$tab->elementtype][$tab->name][
'langs'] = $tab->langs;
1293 $answer[$tab->elementtype][$tab->name][
'help'] = $tab->help;
1294 $answer[$tab->elementtype][$tab->name][
'css'] = $tab->css;
1295 $answer[$tab->elementtype][$tab->name][
'cssview'] = $tab->cssview;
1296 $answer[$tab->elementtype][$tab->name][
'csslist'] = $tab->csslist;
1297 $answer[$tab->elementtype][$tab->name][
'fk_user_author'] = $tab->fk_user_author;
1298 $answer[$tab->elementtype][$tab->name][
'fk_user_modif'] = $tab->fk_user_modif;
1299 $answer[$tab->elementtype][$tab->name][
'datec'] = $tab->datec;
1300 $answer[$tab->elementtype][$tab->name][
'tms'] = $tab->tms;
1303 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1306 throw new RestException(503,
'Error when retrieving list of extra fields : '.$this->db->lasterror());
1327 if (!DolibarrApiAccess::$user->admin) {
1328 throw new RestException(403,
'Only an admin user can create an extrafield');
1333 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1335 throw new RestException(409,
'Duplicate extrafield already found from attrname and elementtype');
1341 foreach ($request_data as $field => $value) {
1342 $extrafields->$field = $this->
_checkValForAPI($field, $value, $extrafields);
1345 $entity = DolibarrApiAccess::$user->entity;
1346 if (empty($entity)) {
1353 if ($request_data[
'label']) {
1354 $label = $request_data[
'label'];
1356 throw new RestException(400,
"label field absent in json at root level");
1359 $alwayseditable = $request_data[
'alwayseditable'];
1360 $default_value = $request_data[
'default_value'];
1361 $totalizable = $request_data[
'totalizable'];
1362 $printable = $request_data[
'printable'];
1363 $required = $request_data[
'required'];
1364 $langfile = $request_data[
'langfile'];
1365 $computed = $request_data[
'computed'];
1366 $unique = $request_data[
'unique'];
1367 $param = $request_data[
'param'];
1368 $perms = $request_data[
'perms'];
1369 $size = $request_data[
'size'];
1370 $type = $request_data[
'type'];
1371 $list = $request_data[
'list'];
1372 $help = $request_data[
'help'];
1373 $pos = $request_data[
'pos'];
1374 $moreparams = array();
1376 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)) {
1377 throw new RestException(500,
'Error creating extrafield', array_merge(array($extrafields->errno), $extrafields->errors));
1380 $sql =
"SELECT t.rowid as id";
1381 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1382 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1383 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1385 $resql = $this->db->query($sql);
1387 if ($this->db->num_rows($resql)) {
1388 $tab = $this->db->fetch_object($resql);
1389 $id = (int) $tab->id;
1416 if (!DolibarrApiAccess::$user->admin) {
1417 throw new RestException(403,
'Only an admin user can create an extrafield');
1422 $result = $extrafields->fetch_name_optionals_label($elementtype,
false, $attrname);
1424 throw new RestException(404,
'Extrafield not found from attrname and elementtype');
1427 foreach ($request_data as $field => $value) {
1428 $extrafields->$field = $this->
_checkValForAPI($field, $value, $extrafields);
1431 $entity = DolibarrApiAccess::$user->entity;
1432 if (empty($entity)) {
1438 if ($request_data[
'label']) {
1439 $label = $request_data[
'label'];
1441 throw new RestException(400,
"label field absent in json at root level");
1444 $alwayseditable = $request_data[
'alwayseditable'];
1445 $default_value = $request_data[
'default_value'];
1446 $totalizable = $request_data[
'totalizable'];
1447 $printable = $request_data[
'printable'];
1448 $required = $request_data[
'required'];
1449 $langfile = $request_data[
'langfile'];
1450 $computed = $request_data[
'computed'];
1451 $unique = $request_data[
'unique'];
1452 $param = $request_data[
'param'];
1453 $perms = $request_data[
'perms'];
1454 $size = $request_data[
'size'];
1455 $type = $request_data[
'type'];
1456 $list = $request_data[
'list'];
1457 $help = $request_data[
'help'];
1458 $pos = $request_data[
'pos'];
1459 $moreparams = array();
1461 dol_syslog(get_class($this).
'::updateExtraField', LOG_DEBUG);
1462 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)) {
1463 throw new RestException(500,
'Error updating extrafield', array_merge(array($extrafields->errno), $extrafields->errors));
1466 $sql =
"SELECT t.rowid as id";
1467 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
1468 $sql .=
" WHERE elementtype = '".$this->db->escape($elementtype).
"'";
1469 $sql .=
" AND name = '".$this->db->escape($attrname).
"'";
1471 $resql = $this->db->query($sql);
1473 if ($this->db->num_rows($resql)) {
1474 $tab = $this->db->fetch_object($resql);
1475 $id = (int) $tab->id;
1504 public function getListOfTowns($sortfield =
"zip,town", $sortorder =
'ASC', $limit = 100, $page = 0, $zipcode =
'', $town =
'', $active = 1, $sqlfilters =
'')
1508 $sql =
"SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
1509 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ziptown as t";
1510 $sql .=
" WHERE t.active = ".((int) $active);
1512 $sql .=
" AND t.zip LIKE '%".$this->db->escape($zipcode).
"%'";
1515 $sql .=
" AND t.town LIKE '%".$this->db->escape($town).
"%'";
1521 if ($errormessage) {
1522 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1527 $sql .= $this->db->order($sortfield, $sortorder);
1533 $offset = $limit * $page;
1535 $sql .= $this->db->plimit($limit, $offset);
1538 $result = $this->db->query($sql);
1541 $num = $this->db->num_rows($result);
1542 $min = min($num, ($limit <= 0 ? $num : $limit));
1543 for ($i = 0; $i < $min; $i++) {
1544 $list[] = $this->db->fetch_object($result);
1547 throw new RestException(503,
'Error when retrieving list of towns : '.$this->db->lasterror());
1571 public function getPaymentTerms($sortfield =
"sortorder", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1575 if (!DolibarrApiAccess::$user->hasRight(
'propal',
'lire') && !DolibarrApiAccess::$user->hasRight(
'commande',
'lire') && !DolibarrApiAccess::$user->hasRight(
'facture',
'lire')) {
1576 throw new RestException(403);
1579 $sql =
"SELECT rowid as id, code, sortorder, libelle as label, libelle_facture as descr, type_cdr, nbjour, decalage, module";
1580 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_payment_term as t";
1581 $sql .=
" WHERE t.entity IN (".getEntity(
'c_payment_term').
")";
1582 $sql .=
" AND t.active = ".((int) $active);
1587 if ($errormessage) {
1588 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1593 $sql .= $this->db->order($sortfield, $sortorder);
1599 $offset = $limit * $page;
1601 $sql .= $this->db->plimit($limit, $offset);
1604 $result = $this->db->query($sql);
1607 $num = $this->db->num_rows($result);
1608 $min = min($num, ($limit <= 0 ? $num : $limit));
1609 for ($i = 0; $i < $min; $i++) {
1610 $list[] = $this->db->fetch_object($result);
1613 throw new RestException(503, $this->db->lasterror());
1635 public function getShippingModes($limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
1639 $sql =
"SELECT rowid as id, code, libelle as label, description, tracking, module";
1640 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as t";
1641 $sql .=
" WHERE t.entity IN (".getEntity(
'c_shipment_mode').
")";
1642 $sql .=
" AND t.active = ".((int) $active);
1647 if ($errormessage) {
1648 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1659 $offset = $limit * $page;
1661 $sql .= $this->db->plimit($limit, $offset);
1664 $result = $this->db->query($sql);
1667 $num = $this->db->num_rows($result);
1668 $min = min($num, ($limit <= 0 ? $num : $limit));
1669 for ($i = 0; $i < $min; $i++) {
1670 $method = $this->db->fetch_object($result);
1675 throw new RestException(503, $this->db->lasterror());
1697 public function getListOfMeasuringUnits($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1701 $sql =
"SELECT t.rowid, t.code, t.label,t.short_label, t.active, t.scale, t.unit_type";
1702 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_units as t";
1703 $sql .=
" WHERE t.active = ".((int) $active);
1708 if ($errormessage) {
1709 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1714 $sql .= $this->db->order($sortfield, $sortorder);
1720 $offset = $limit * $page;
1722 $sql .= $this->db->plimit($limit, $offset);
1725 $result = $this->db->query($sql);
1728 $num = $this->db->num_rows($result);
1729 $min = min($num, ($limit <= 0 ? $num : $limit));
1730 for ($i = 0; $i < $min; $i++) {
1731 $list[] = $this->db->fetch_object($result);
1734 throw new RestException(503,
'Error when retrieving list of measuring units: '.$this->db->lasterror());
1757 public function getListOfLegalForm($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $active = 1, $sqlfilters =
'')
1761 $sql =
"SELECT t.rowid, t.code, t.fk_pays, t.libelle, t.isvatexempted, t.active, t.module, t.position";
1762 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_forme_juridique as t";
1763 $sql .=
" WHERE t.active = ".((int) $active);
1765 $sql .=
" AND t.fk_pays = ".((int) $country);
1771 if ($errormessage) {
1772 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1777 $sql .= $this->db->order($sortfield, $sortorder);
1783 $offset = $limit * $page;
1785 $sql .= $this->db->plimit($limit, $offset);
1788 $result = $this->db->query($sql);
1791 $num = $this->db->num_rows($result);
1792 $min = min($num, ($limit <= 0 ? $num : $limit));
1793 for ($i = 0; $i < $min; $i++) {
1794 $list[] = $this->db->fetch_object($result);
1797 throw new RestException(503,
'Error when retrieving list of legal form: '.$this->db->lasterror());
1819 public function getListOfStaff($sortfield =
"id", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1823 $sql =
"SELECT t.id, t.code, t.libelle, t.active, t.module";
1824 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_effectif as t";
1825 $sql .=
" WHERE t.active = ".((int) $active);
1830 if ($errormessage) {
1831 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1836 $sql .= $this->db->order($sortfield, $sortorder);
1842 $offset = $limit * $page;
1844 $sql .= $this->db->plimit($limit, $offset);
1847 $result = $this->db->query($sql);
1850 $num = $this->db->num_rows($result);
1851 $min = min($num, ($limit <= 0 ? $num : $limit));
1852 for ($i = 0; $i < $min; $i++) {
1853 $list[] = $this->db->fetch_object($result);
1856 throw new RestException(503,
'Error when retrieving list of staff: '.$this->db->lasterror());
1878 public function getListOfsocialNetworks($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1882 if (!isModEnabled(
'socialnetworks')) {
1883 throw new RestException(400,
'API not available: this dictionary is not enabled by setup');
1888 $sql =
"SELECT t.rowid, t.entity, t.code, t.label, t.url, t.icon, t.active";
1889 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_socialnetworks as t";
1890 $sql .=
" WHERE t.entity IN (".getEntity(
'c_socialnetworks').
")";
1891 $sql .=
" AND t.active = ".((int) $active);
1896 if ($errormessage) {
1897 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1902 $sql .= $this->db->order($sortfield, $sortorder);
1908 $offset = $limit * $page;
1910 $sql .= $this->db->plimit($limit, $offset);
1913 $result = $this->db->query($sql);
1916 $num = $this->db->num_rows($result);
1917 $min = min($num, ($limit <= 0 ? $num : $limit));
1918 for ($i = 0; $i < $min; $i++) {
1919 $list[] = $this->db->fetch_object($result);
1922 throw new RestException(503,
'Error when retrieving list of social networks: '.$this->db->lasterror());
1945 public function getTicketsCategories($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
1949 $sql =
"SELECT rowid, code, pos, label, use_default, description";
1950 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_category as t";
1951 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_category').
")";
1952 $sql .=
" AND t.active = ".((int) $active);
1957 if ($errormessage) {
1958 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1963 $sql .= $this->db->order($sortfield, $sortorder);
1969 $offset = $limit * $page;
1971 $sql .= $this->db->plimit($limit, $offset);
1974 $result = $this->db->query($sql);
1977 $num = $this->db->num_rows($result);
1978 $min = min($num, ($limit <= 0 ? $num : $limit));
1979 for ($i = 0; $i < $min; $i++) {
1980 $category = $this->db->fetch_object($result);
1981 $this->
translateLabel($category, $lang,
'TicketCategoryShort', array(
'ticket'));
1982 $list[] = $category;
1985 throw new RestException(503,
'Error when retrieving list of ticket categories : '.$this->db->lasterror());
2008 public function getTicketsSeverities($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2012 $sql =
"SELECT rowid, code, pos, label, use_default, color, description";
2013 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_severity as t";
2014 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_severity').
")";
2015 $sql .=
" AND t.active = ".((int) $active);
2020 if ($errormessage) {
2021 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2026 $sql .= $this->db->order($sortfield, $sortorder);
2032 $offset = $limit * $page;
2034 $sql .= $this->db->plimit($limit, $offset);
2037 $result = $this->db->query($sql);
2040 $num = $this->db->num_rows($result);
2041 $min = min($num, ($limit <= 0 ? $num : $limit));
2042 for ($i = 0; $i < $min; $i++) {
2043 $severity = $this->db->fetch_object($result);
2044 $this->
translateLabel($severity, $lang,
'TicketSeverityShort', array(
'ticket'));
2045 $list[] = $severity;
2048 throw new RestException(503,
'Error when retrieving list of ticket severities : '.$this->db->lasterror());
2071 public function getTicketsTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2075 $sql =
"SELECT rowid, code, pos, label, use_default, description";
2076 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_type as t";
2077 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_type').
")";
2078 $sql .=
" AND t.active = ".((int) $active);
2084 if ($errormessage) {
2085 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2090 $sql .= $this->db->order($sortfield, $sortorder);
2096 $offset = $limit * $page;
2098 $sql .= $this->db->plimit($limit, $offset);
2101 $result = $this->db->query($sql);
2104 $num = $this->db->num_rows($result);
2105 $min = min($num, ($limit <= 0 ? $num : $limit));
2106 for ($i = 0; $i < $min; $i++) {
2107 $type =$this->db->fetch_object($result);
2108 $this->
translateLabel($type, $lang,
'TicketTypeShort', array(
'ticket'));
2112 throw new RestException(503,
'Error when retrieving list of ticket types : '.$this->db->lasterror());
2134 public function getListOfIncoterms($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
2138 $sql =
"SELECT rowid, code, active";
2139 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_incoterms as t";
2140 $sql .=
" WHERE 1=1";
2146 if ($errormessage) {
2147 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
2152 $sql .= $this->db->order($sortfield, $sortorder);
2158 $offset = $limit * $page;
2160 $sql .= $this->db->plimit($limit, $offset);
2163 $result = $this->db->query($sql);
2166 $num = $this->db->num_rows($result);
2167 $min = min($num, ($limit <= 0 ? $num : $limit));
2168 for ($i = 0; $i < $min; $i++) {
2169 $type =$this->db->fetch_object($result);
2173 throw new RestException(503,
'Error when retrieving list of incoterm types : '.$this->db->lasterror());
2190 global $conf, $mysoc;
2192 if (!DolibarrApiAccess::$user->admin
2193 && (!
getDolGlobalString(
'API_LOGINS_ALLOWED_FOR_GET_COMPANY') || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_GET_COMPANY)) {
2194 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');
2197 unset($mysoc->pays);
2198 unset($mysoc->note);
2201 unset($mysoc->lines);
2203 unset($mysoc->effectif);
2204 unset($mysoc->effectif_id);
2205 unset($mysoc->forme_juridique_code);
2206 unset($mysoc->forme_juridique);
2207 unset($mysoc->mode_reglement_supplier_id);
2208 unset($mysoc->cond_reglement_supplier_id);
2209 unset($mysoc->transport_mode_supplier_id);
2210 unset($mysoc->fk_prospectlevel);
2212 unset($mysoc->total_ht);
2213 unset($mysoc->total_tva);
2214 unset($mysoc->total_localtax1);
2215 unset($mysoc->total_localtax2);
2216 unset($mysoc->total_ttc);
2218 unset($mysoc->lastname);
2219 unset($mysoc->firstname);
2220 unset($mysoc->civility_id);
2222 unset($mysoc->client);
2223 unset($mysoc->prospect);
2224 unset($mysoc->fournisseur);
2225 unset($mysoc->contact_id);
2227 unset($mysoc->fk_incoterms);
2228 unset($mysoc->label_incoterms);
2229 unset($mysoc->location_incoterms);
2249 $sql =
"SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
2250 $sql .=
" FROM ".MAIN_DB_PREFIX.
"establishment as e";
2251 $sql .=
" WHERE e.entity IN (".getEntity(
'establishment').
')';
2256 $result = $this->db->query($sql);
2259 $num = $this->db->num_rows($result);
2260 $min = min($num, ($limit <= 0 ? $num : $limit));
2261 for ($i = 0; $i < $min; $i++) {
2262 $list[] = $this->db->fetch_object($result);
2265 throw new RestException(503,
'Error when retrieving list of establishments : '.$this->db->lasterror());
2286 $result = $establishment->fetch($id);
2288 throw new RestException(503,
'Error when retrieving establishment : '.$establishment->error);
2289 } elseif ($result == 0) {
2290 throw new RestException(404,
'Establishment not found');
2313 if (!DolibarrApiAccess::$user->admin
2315 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');
2318 if (!preg_match(
'/^[a-zA-Z0-9_]+$/', $constantname) || !isset($conf->global->$constantname)) {
2319 throw new RestException(400,
'Error Bad or unknown value for constantname');
2322 throw new RestException(403,
'Forbidden. This parameter can not be read with APIs');
2342 global $langs, $conf;
2344 if (!DolibarrApiAccess::$user->admin
2345 && (!
getDolGlobalString(
'API_LOGINS_ALLOWED_FOR_INTEGRITY_CHECK') || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_INTEGRITY_CHECK)) {
2346 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');
2349 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2350 require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
2352 $langs->load(
"admin");
2354 $outexpectedchecksum =
'';
2355 $outcurrentchecksum =
'';
2358 $file_list = array(
'missing' => array(),
'updated' => array());
2363 $xmlfile = DOL_DOCUMENT_ROOT.
'/install/'.$xmlshortfile;
2364 if (!preg_match(
'/\.zip$/i', $xmlfile) &&
dol_is_file($xmlfile.
'.zip')) {
2365 $xmlfile = $xmlfile.
'.zip';
2369 $xmlremote = (($target ==
'default' || $target ==
'local') ?
'' : $target);
2373 $param =
'MAIN_FILECHECK_URL_'.DOL_VERSION;
2377 if (empty($xmlremote)) {
2378 $xmlremote =
'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.
'.xml';
2380 if ($xmlremote && !preg_match(
'/^https?:\/\//i', $xmlremote)) {
2381 $langs->load(
"errors");
2382 throw new RestException(500, $langs->trans(
"ErrorURLMustStartWithHttp", $xmlremote));
2384 if ($xmlremote && !preg_match(
'/\.xml$/', $xmlremote)) {
2385 $langs->load(
"errors");
2386 throw new RestException(500, $langs->trans(
"ErrorURLMustEndWith", $xmlremote,
'.xml'));
2389 if (LIBXML_VERSION < 20900) {
2393 libxml_disable_entity_loader(
true);
2396 if ($target ==
'local') {
2398 $xml = simplexml_load_file($xmlfile);
2400 throw new RestException(500, $langs->trans(
'XmlNotFound').
': /install/'.$xmlshortfile);
2403 $xmlarray =
getURLContent($xmlremote,
'GET',
'', 1, array(), array(
'http',
'https'), 0);
2406 if (!$xmlarray[
'curl_error_no'] && $xmlarray[
'http_code'] !=
'400' && $xmlarray[
'http_code'] !=
'404') {
2407 $xmlfile = $xmlarray[
'content'];
2409 $xml = simplexml_load_string($xmlfile,
'SimpleXMLElement', LIBXML_NOCDATA|LIBXML_NONET);
2411 $errormsg = $langs->trans(
'XmlNotFound').
': '.$xmlremote.
' - '.$xmlarray[
'http_code'].(($xmlarray[
'http_code'] == 400 && $xmlarray[
'content']) ?
' '.$xmlarray[
'content'] :
'').
' '.$xmlarray[
'curl_error_no'].
' '.$xmlarray[
'curl_error_msg'];
2412 throw new RestException(500, $errormsg);
2417 $checksumconcat = array();
2418 $file_list = array();
2422 if (is_object($xml->dolibarr_constants[0])) {
2425 $out .=
'<div class="div-table-responsive-no-min">';
2426 $out .=
'<table class="noborder">';
2427 $out .=
'<tr class="liste_titre">';
2428 $out .=
'<td>#</td>';
2429 $out .=
'<td>'.$langs->trans(
"Constant").
'</td>';
2430 $out .=
'<td class="center">'.$langs->trans(
"ExpectedValue").
'</td>';
2431 $out .=
'<td class="center">'.$langs->trans(
"Value").
'</td>';
2432 $out .=
'</tr>'.
"\n";
2435 foreach ($xml->dolibarr_constants[0]->constant as $constant) {
2436 $constname = $constant[
'name'];
2437 $constvalue = (string) $constant;
2438 $constvalue = (empty($constvalue) ?
'0' : $constvalue);
2444 $valueforchecksum = (empty($value) ?
'0' : $value);
2446 $checksumconcat[] = $valueforchecksum;
2449 $out .=
'<tr class="oddeven">';
2450 $out .=
'<td>'.$i.
'</td>'.
"\n";
2451 $out .=
'<td>'.dol_escape_htmltag($constname).
'</td>'.
"\n";
2452 $out .=
'<td class="center">'.dol_escape_htmltag($constvalue).
'</td>'.
"\n";
2453 $out .=
'<td class="center">'.dol_escape_htmltag($valueforchecksum).
'</td>'.
"\n";
2458 $out .=
'<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2467 if (is_object($xml->dolibarr_htdocs_dir[0])) {
2468 $includecustom = (empty($xml->dolibarr_htdocs_dir[0][
'includecustom']) ? 0 : $xml->dolibarr_htdocs_dir[0][
'includecustom']);
2471 $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)$';
2472 $regextoexclude =
'('.($includecustom ?
'' :
'custom|').
'documents|escpos-php\/doc|conf|install|dejavu-fonts-ttf-.*|public\/test|sabre\/sabre\/.*\/tests|Shared\/PCLZip|nusoap\/lib\/Mail|php\/example|php\/test|geoip\/sample.*\.php|ckeditor\/samples|ckeditor\/adapters)$';
2473 $scanfiles =
dol_dir_list(DOL_DOCUMENT_ROOT,
'files', 1, $regextoinclude, $regextoexclude);
2476 $ret =
getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0],
'', DOL_DOCUMENT_ROOT, $checksumconcat);
2478 foreach ($scanfiles as $keyfile => $valfile) {
2479 $tmprelativefilename = preg_replace(
'/^'.preg_quote(DOL_DOCUMENT_ROOT,
'/').
'/',
'', $valfile[
'fullname']);
2480 if (!in_array($tmprelativefilename, $file_list[
'insignature'])) {
2481 $md5newfile = @md5_file($valfile[
'fullname']);
2482 $file_list[
'added'][] = array(
'filename'=>$tmprelativefilename,
'md5'=>$md5newfile);
2489 $out .=
'<div class="div-table-responsive-no-min">';
2490 $out .=
'<table class="noborder">';
2491 $out .=
'<tr class="liste_titre">';
2492 $out .=
'<td>#</td>';
2493 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2494 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2495 $out .=
'</tr>'.
"\n";
2496 $tmpfilelist =
dol_sort_array($file_list[
'missing'],
'filename');
2497 if (is_array($tmpfilelist) && count($tmpfilelist)) {
2499 foreach ($tmpfilelist as $file) {
2501 $out .=
'<tr class="oddeven">';
2502 $out .=
'<td>'.$i.
'</td>'.
"\n";
2503 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2504 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2508 $out .=
'<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2519 $out .=
'<div class="div-table-responsive-no-min">';
2520 $out .=
'<table class="noborder">';
2521 $out .=
'<tr class="liste_titre">';
2522 $out .=
'<td>#</td>';
2523 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2524 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2525 $out .=
'<td class="center">'.$langs->trans(
"CurrentChecksum").
'</td>';
2526 $out .=
'<td class="right">'.$langs->trans(
"Size").
'</td>';
2527 $out .=
'<td class="right">'.$langs->trans(
"DateModification").
'</td>';
2528 $out .=
'</tr>'.
"\n";
2529 $tmpfilelist2 =
dol_sort_array($file_list[
'updated'],
'filename');
2530 if (is_array($tmpfilelist2) && count($tmpfilelist2)) {
2532 foreach ($tmpfilelist2 as $file) {
2534 $out .=
'<tr class="oddeven">';
2535 $out .=
'<td>'.$i.
'</td>'.
"\n";
2536 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2537 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2538 $out .=
'<td class="center">'.$file[
'md5'].
'</td>'.
"\n";
2539 $size =
dol_filesize(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']);
2540 $totalsize += $size;
2541 $out .=
'<td class="right">'.dol_print_size($size).
'</td>'.
"\n";
2542 $out .=
'<td class="right">'.dol_print_date(
dol_filemtime(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']),
'dayhour').
'</td>'.
"\n";
2545 $out .=
'<tr class="liste_total">';
2546 $out .=
'<td></td>'.
"\n";
2547 $out .=
'<td>'.$langs->trans(
"Total").
'</td>'.
"\n";
2548 $out .=
'<td align="center"></td>'.
"\n";
2549 $out .=
'<td align="center"></td>'.
"\n";
2550 $out .=
'<td class="right">'.dol_print_size($totalsize).
'</td>'.
"\n";
2551 $out .=
'<td class="right"></td>'.
"\n";
2554 $out .=
'<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2565 $out .=
'<div class="div-table-responsive-no-min">';
2566 $out .=
'<table class="noborder">';
2567 $out .=
'<tr class="liste_titre">';
2568 $out .=
'<td>#</td>';
2569 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2570 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2571 $out .=
'<td class="center">'.$langs->trans(
"CurrentChecksum").
'</td>';
2572 $out .=
'<td class="right">'.$langs->trans(
"Size").
'</td>';
2573 $out .=
'<td class="right">'.$langs->trans(
"DateModification").
'</td>';
2574 $out .=
'</tr>'.
"\n";
2576 if (is_array($tmpfilelist3) && count($tmpfilelist3)) {
2578 foreach ($tmpfilelist3 as $file) {
2580 $out .=
'<tr class="oddeven">';
2581 $out .=
'<td>'.$i.
'</td>'.
"\n";
2582 $out .=
'<td>'.dol_escape_htmltag($file[
'filename']).
'</td>'.
"\n";
2583 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2584 $out .=
'<td class="center">'.$file[
'md5'].
'</td>'.
"\n";
2585 $size =
dol_filesize(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']);
2586 $totalsize += $size;
2587 $out .=
'<td class="right">'.dol_print_size($size).
'</td>'.
"\n";
2588 $out .=
'<td class="right">'.dol_print_date(
dol_filemtime(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']),
'dayhour').
'</td>'.
"\n";
2591 $out .=
'<tr class="liste_total">';
2592 $out .=
'<td></td>'.
"\n";
2593 $out .=
'<td>'.$langs->trans(
"Total").
'</td>'.
"\n";
2594 $out .=
'<td align="center"></td>'.
"\n";
2595 $out .=
'<td align="center"></td>'.
"\n";
2596 $out .=
'<td class="right">'.dol_print_size($totalsize).
'</td>'.
"\n";
2597 $out .=
'<td class="right"></td>'.
"\n";
2600 $out .=
'<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2607 if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) {
2613 throw new RestException(500,
'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile);
2618 asort($checksumconcat);
2619 $checksumget = md5(implode(
',', $checksumconcat));
2620 $checksumtoget = trim((
string) $xml->dolibarr_htdocs_dir_checksum);
2622 $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans(
"Unknown"));
2623 if ($checksumget == $checksumtoget) {
2624 if (count($file_list[
'added'])) {
2625 $resultcode =
'warning';
2626 $resultcomment =
'FileIntegrityIsOkButFilesWereAdded';
2628 $outcurrentchecksum = $checksumget;
2631 $resultcomment =
'Success';
2633 $outcurrentchecksum = $checksumget;
2636 $resultcode =
'error';
2637 $resultcomment =
'Error';
2639 $outcurrentchecksum = $checksumget;
2642 throw new RestException(404,
'No signature file known');
2645 return array(
'resultcode'=>$resultcode,
'resultcomment'=>$resultcomment,
'expectedchecksum'=> $outexpectedchecksum,
'currentchecksum'=> $outcurrentchecksum,
'out'=>$out);
2662 if (!DolibarrApiAccess::$user->admin
2663 && (!
getDolGlobalString(
'API_LOGINS_ALLOWED_FOR_GET_MODULES') || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_GET_MODULES)) {
2664 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');
2667 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)
_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).