24 use Luracast\Restler\RestException;
26 require_once DOL_DOCUMENT_ROOT.
'/main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/class/cstate.class.php';
28 require_once DOL_DOCUMENT_ROOT.
'/core/class/ccountry.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/hrm/class/establishment.class.php';
39 private $translations =
null;
66 public function getOrderingMethods($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
70 if (!DolibarrApiAccess::$user->rights->commande->lire) {
71 throw new RestException(401);
74 $sql =
"SELECT rowid, code, libelle as label, module";
75 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_input_method as t";
76 $sql .=
" WHERE t.active = ".((int) $active);
82 throw new RestException(503,
'Error when validating parameter sqlfilters -> '.$errormessage);
87 $sql .= $this->
db->order($sortfield, $sortorder);
93 $offset = $limit * $page;
95 $sql .= $this->
db->plimit($limit, $offset);
98 $result = $this->
db->query(
$sql);
101 $num = $this->
db->num_rows($result);
102 $min = min($num, ($limit <= 0 ? $num : $limit));
103 for ($i = 0; $i < $min; $i++) {
104 $list[] = $this->
db->fetch_object($result);
107 throw new RestException(400, $this->
db->lasterror());
129 public function getOrderingOrigins($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
133 if (!DolibarrApiAccess::$user->rights->commande->lire) {
134 throw new RestException(401);
137 $sql =
"SELECT rowid, code, label, module";
138 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_input_reason as t";
139 $sql .=
" WHERE t.active = ".((int) $active);
145 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
150 $sql .= $this->
db->order($sortfield, $sortorder);
156 $offset = $limit * $page;
158 $sql .= $this->
db->plimit($limit, $offset);
161 $result = $this->
db->query(
$sql);
164 $num = $this->
db->num_rows($result);
165 $min = min($num, ($limit <= 0 ? $num : $limit));
166 for ($i = 0; $i < $min; $i++) {
167 $list[] = $this->
db->fetch_object($result);
170 throw new RestException(400, $this->
db->lasterror());
192 public function getPaymentTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
196 if (!DolibarrApiAccess::$user->rights->propal->lire && !DolibarrApiAccess::$user->rights->commande->lire && !DolibarrApiAccess::$user->rights->facture->lire) {
197 throw new RestException(401);
200 $sql =
"SELECT id, code, type, libelle as label, module";
201 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_paiement as t";
202 $sql .=
" WHERE t.entity IN (".getEntity(
'c_paiement').
")";
203 $sql .=
" AND t.active = ".((int) $active);
209 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
214 $sql .= $this->
db->order($sortfield, $sortorder);
220 $offset = $limit * $page;
222 $sql .= $this->
db->plimit($limit, $offset);
225 $result = $this->
db->query(
$sql);
228 $num = $this->
db->num_rows($result);
229 $min = min($num, ($limit <= 0 ? $num : $limit));
230 for ($i = 0; $i < $min; $i++) {
231 $list[] = $this->
db->fetch_object($result);
234 throw new RestException(400, $this->
db->lasterror());
260 public function getListOfStates($sortfield =
"code_departement", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $filter =
'', $sqlfilters =
'')
266 $sql =
"SELECT t.rowid FROM ".MAIN_DB_PREFIX.
"c_departements as t";
268 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as d ON t.fk_region = d.code_region";
270 $sql .=
" WHERE 1 = 1";
272 $sql .=
" AND d.fk_pays = ".((int) $country);
279 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
283 $sql .= $this->
db->order($sortfield, $sortorder);
289 $offset = $limit * $page;
291 $sql .= $this->
db->plimit($limit, $offset);
294 $result = $this->
db->query(
$sql);
297 $num = $this->
db->num_rows($result);
298 $min = min($num, ($limit <= 0 ? $num : $limit));
299 for ($i = 0; $i < $min; $i++) {
300 $obj = $this->
db->fetch_object($result);
302 if ($state->fetch($obj->rowid) > 0) {
303 if (empty($filter) || stripos($state->label, $filter) !==
false) {
309 throw new RestException(503,
'Error when retrieving list of states');
366 public function getListOfCountries($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $filter =
'', $lang =
'', $sqlfilters =
'')
372 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"c_country as t";
373 $sql .=
" WHERE 1 = 1";
379 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
383 $sql .= $this->
db->order($sortfield, $sortorder);
389 $offset = $limit * $page;
391 $sql .= $this->
db->plimit($limit, $offset);
394 $result = $this->
db->query(
$sql);
397 $num = $this->
db->num_rows($result);
398 $min = min($num, ($limit <= 0 ? $num : $limit));
399 for ($i = 0; $i < $min; $i++) {
400 $obj = $this->
db->fetch_object($result);
402 if ($country->fetch($obj->rowid) > 0) {
407 if (empty($filter) || stripos($country->label, $filter) !==
false) {
413 throw new RestException(503,
'Error when retrieving list of countries');
480 $result = $state->fetch($id, $code);
482 throw new RestException(503,
'Error when retrieving state : '.$state->error);
483 } elseif ($result == 0) {
484 throw new RestException(404,
'State not found');
505 $result = $country->fetch($id, $code, $iso);
508 throw new RestException(503,
'Error when retrieving country : '.$country->error);
509 } elseif ($result == 0) {
510 throw new RestException(404,
'Country not found');
534 public function getAvailability($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
538 if (!DolibarrApiAccess::$user->rights->commande->lire) {
539 throw new RestException(401);
542 $sql =
"SELECT rowid, code, label";
543 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_availability as t";
544 $sql .=
" WHERE t.active = ".((int) $active);
550 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
555 $sql .= $this->
db->order($sortfield, $sortorder);
561 $offset = $limit * $page;
563 $sql .= $this->
db->plimit($limit, $offset);
566 $result = $this->
db->query(
$sql);
569 $num = $this->
db->num_rows($result);
570 $min = min($num, ($limit <= 0 ? $num : $limit));
571 for ($i = 0; $i < $min; $i++) {
572 $list[] = $this->
db->fetch_object($result);
575 throw new RestException(400, $this->
db->lasterror());
591 $object = parent::_cleanObjectDatas($object);
593 unset($object->error);
594 unset($object->errors);
608 private function translateLabel($object, $lang, $prefix =
'Country', $dict = array(
'dict'))
612 if ($this->translations ==
null || $this->translations->getDefaultLang() !== $lang) {
614 $this->translations =
new Translate(
'', $conf);
615 $this->translations->setDefaultLang($lang);
616 $this->translations->loadLangs($dict);
619 $key = $prefix.$object->code;
621 $translation = $this->translations->trans($key);
622 if ($translation != $key) {
623 $object->label = html_entity_decode($translation);
646 public function getListOfEventTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $type =
'', $module =
'', $active = 1, $sqlfilters =
'')
650 $sql =
"SELECT id, code, type, libelle as label, module";
651 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_actioncomm as t";
652 $sql .=
" WHERE t.active = ".((int) $active);
654 $sql .=
" AND t.type LIKE '%".$this->db->escape($type).
"%'";
657 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
664 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
669 $sql .= $this->
db->order($sortfield, $sortorder);
675 $offset = $limit * $page;
677 $sql .= $this->
db->plimit($limit, $offset);
680 $result = $this->
db->query(
$sql);
683 $num = $this->
db->num_rows($result);
684 $min = min($num, ($limit <= 0 ? $num : $limit));
685 for ($i = 0; $i < $min; $i++) {
686 $list[] = $this->
db->fetch_object($result);
689 throw new RestException(503,
'Error when retrieving list of events types : '.$this->
db->lasterror());
712 public function getListOfExpenseReportsTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $module =
'', $active = 1, $sqlfilters =
'')
716 $sql =
"SELECT id, code, label, accountancy_code, active, module, position";
717 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_fees as t";
718 $sql .=
" WHERE t.active = ".((int) $active);
720 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
727 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
732 $sql .= $this->
db->order($sortfield, $sortorder);
738 $offset = $limit * $page;
740 $sql .= $this->
db->plimit($limit, $offset);
743 $result = $this->
db->query(
$sql);
746 $num = $this->
db->num_rows($result);
747 $min = min($num, ($limit <= 0 ? $num : $limit));
748 for ($i = 0; $i < $min; $i++) {
749 $list[] = $this->
db->fetch_object($result);
752 throw new RestException(503,
'Error when retrieving list of expense report types : '.$this->
db->lasterror());
777 public function getListOfContactTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $type =
'', $module =
'', $active = 1, $lang =
'', $sqlfilters =
'')
781 $sql =
"SELECT rowid, code, element as type, libelle as label, source, module, position";
782 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact as t";
783 $sql .=
" WHERE t.active = ".((int) $active);
785 $sql .=
" AND type LIKE '%".$this->db->escape($type).
"%'";
788 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
795 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
800 $sql .= $this->
db->order($sortfield, $sortorder);
806 $offset = $limit * $page;
808 $sql .= $this->
db->plimit($limit, $offset);
811 $result = $this->
db->query(
$sql);
814 $num = $this->
db->num_rows($result);
815 $min = min($num, ($limit <= 0 ? $num : $limit));
816 for ($i = 0; $i < $min; $i++) {
817 $contact_type = $this->
db->fetch_object($result);
818 $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"));
819 $list[] = $contact_type;
822 throw new RestException(503,
'Error when retrieving list of contacts types : '.$this->
db->lasterror());
845 public function getListOfCivilities($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $module =
'', $active = 1, $lang =
'', $sqlfilters =
'')
849 $sql =
"SELECT rowid, code, label, module";
850 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_civility as t";
851 $sql .=
" WHERE t.active = ".((int) $active);
853 $sql .=
" AND t.module LIKE '%".$this->db->escape($module).
"%'";
860 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
865 $sql .= $this->
db->order($sortfield, $sortorder);
871 $offset = $limit * $page;
873 $sql .= $this->
db->plimit($limit, $offset);
876 $result = $this->
db->query(
$sql);
879 $num = $this->
db->num_rows($result);
880 $min = min($num, ($limit <= 0 ? $num : $limit));
881 for ($i = 0; $i < $min; $i++) {
882 $civility = $this->
db->fetch_object($result);
883 $this->
translateLabel($civility, $lang,
'Civility', array(
'dict'));
887 throw new RestException(503,
'Error when retrieving list of civility : '.$this->
db->lasterror());
909 public function getListOfCurrencies($multicurrency = 0, $sortfield =
"code_iso", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
912 $sql =
"SELECT t.code_iso, t.label, t.unicode";
913 if (!empty($multicurrency)) {
914 $sql .=
" , cr.date_sync, cr.rate ";
916 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_currencies as t";
917 if (!empty($multicurrency)) {
918 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"multicurrency as m ON m.code=t.code_iso";
919 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"multicurrency_rate as cr ON (m.rowid = cr.fk_multicurrency)";
921 $sql .=
" WHERE t.active = ".((int) $active);
922 if (!empty($multicurrency)) {
923 $sql .=
" AND m.entity IN (".getEntity(
'multicurrency').
")";
924 if (!empty($multicurrency) && $multicurrency != 2) {
925 $sql .=
" AND cr.date_sync = (SELECT MAX(cr2.date_sync) FROM ".MAIN_DB_PREFIX.
"multicurrency_rate AS cr2 WHERE cr2.fk_multicurrency = m.rowid)";
934 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
939 $sql .= $this->
db->order($sortfield, $sortorder);
945 $offset = $limit * $page;
947 $sql .= $this->
db->plimit($limit, $offset);
950 $result = $this->
db->query(
$sql);
953 $num = $this->
db->num_rows($result);
954 $min = min($num, ($limit <= 0 ? $num : $limit));
955 for ($i = 0; $i < $min; $i++) {
956 $list[] = $this->
db->fetch_object($result);
959 throw new RestException(503,
'Error when retrieving list of currency : '.$this->
db->lasterror());
982 if (!DolibarrApiAccess::$user->admin) {
983 throw new RestException(401,
'Only an admin user can get list of extrafields');
986 if ($type ==
'thirdparty') {
989 if ($type ==
'contact') {
993 $sql =
"SELECT t.rowid, t.name, t.label, t.type, t.size, t.elementtype, t.fieldunique, t.fieldrequired, t.param, t.pos, t.alwayseditable, t.perms, t.list, t.fielddefault, t.fieldcomputed";
994 $sql .=
" FROM ".MAIN_DB_PREFIX.
"extrafields as t";
995 $sql .=
" WHERE t.entity IN (".getEntity(
'extrafields').
")";
997 $sql .=
" AND t.elementtype = '".$this->db->escape($type).
"'";
1003 if ($errormessage) {
1004 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1008 $sql .= $this->
db->order($sortfield, $sortorder);
1010 $resql = $this->
db->query(
$sql);
1012 if ($this->
db->num_rows($resql)) {
1013 while ($tab = $this->
db->fetch_object($resql)) {
1015 $list[$tab->elementtype][$tab->name][
'type'] = $tab->type;
1016 $list[$tab->elementtype][$tab->name][
'label'] = $tab->label;
1017 $list[$tab->elementtype][$tab->name][
'size'] = $tab->size;
1018 $list[$tab->elementtype][$tab->name][
'elementtype'] = $tab->elementtype;
1019 $list[$tab->elementtype][$tab->name][
'default'] = $tab->fielddefault;
1020 $list[$tab->elementtype][$tab->name][
'computed'] = $tab->fieldcomputed;
1021 $list[$tab->elementtype][$tab->name][
'unique'] = $tab->fieldunique;
1022 $list[$tab->elementtype][$tab->name][
'required'] = $tab->fieldrequired;
1023 $list[$tab->elementtype][$tab->name][
'param'] = ($tab->param ?
jsonOrUnserialize($tab->param) :
'');
1024 $list[$tab->elementtype][$tab->name][
'pos'] = $tab->pos;
1025 $list[$tab->elementtype][$tab->name][
'alwayseditable'] = $tab->alwayseditable;
1026 $list[$tab->elementtype][$tab->name][
'perms'] = $tab->perms;
1027 $list[$tab->elementtype][$tab->name][
'list'] = $tab->list;
1031 throw new RestException(503,
'Error when retrieving list of extra fields : '.$this->
db->lasterror());
1034 if (!count($list)) {
1035 throw new RestException(404,
'No extrafield found');
1059 public function getListOfTowns($sortfield =
"zip,town", $sortorder =
'ASC', $limit = 100, $page = 0, $zipcode =
'', $town =
'', $active = 1, $sqlfilters =
'')
1063 $sql =
"SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
1064 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ziptown as t";
1065 $sql .=
" WHERE t.active = ".((int) $active);
1067 $sql .=
" AND t.zip LIKE '%".$this->db->escape($zipcode).
"%'";
1070 $sql .=
" AND t.town LIKE '%".$this->db->escape($town).
"%'";
1076 if ($errormessage) {
1077 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1082 $sql .= $this->
db->order($sortfield, $sortorder);
1088 $offset = $limit * $page;
1090 $sql .= $this->
db->plimit($limit, $offset);
1093 $result = $this->
db->query(
$sql);
1096 $num = $this->
db->num_rows($result);
1097 $min = min($num, ($limit <= 0 ? $num : $limit));
1098 for ($i = 0; $i < $min; $i++) {
1099 $list[] = $this->
db->fetch_object($result);
1102 throw new RestException(503,
'Error when retrieving list of towns : '.$this->
db->lasterror());
1124 public function getPaymentTerms($sortfield =
"sortorder", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1128 if (!DolibarrApiAccess::$user->rights->propal->lire && !DolibarrApiAccess::$user->rights->commande->lire && !DolibarrApiAccess::$user->rights->facture->lire) {
1129 throw new RestException(401);
1132 $sql =
"SELECT rowid as id, code, sortorder, libelle as label, libelle_facture as descr, type_cdr, nbjour, decalage, module";
1133 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_payment_term as t";
1134 $sql .=
" WHERE t.entity IN (".getEntity(
'c_payment_term').
")";
1135 $sql .=
" AND t.active = ".((int) $active);
1140 if ($errormessage) {
1141 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1146 $sql .= $this->
db->order($sortfield, $sortorder);
1152 $offset = $limit * $page;
1154 $sql .= $this->
db->plimit($limit, $offset);
1157 $result = $this->
db->query(
$sql);
1160 $num = $this->
db->num_rows($result);
1161 $min = min($num, ($limit <= 0 ? $num : $limit));
1162 for ($i = 0; $i < $min; $i++) {
1163 $list[] = $this->
db->fetch_object($result);
1166 throw new RestException(400, $this->
db->lasterror());
1187 public function getShippingModes($limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
1191 $sql =
"SELECT rowid as id, code, libelle as label, description, tracking, module";
1192 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_shipment_mode as t";
1193 $sql .=
" WHERE t.entity IN (".getEntity(
'c_shipment_mode').
")";
1194 $sql .=
" AND t.active = ".((int) $active);
1199 if ($errormessage) {
1200 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1211 $offset = $limit * $page;
1213 $sql .= $this->
db->plimit($limit, $offset);
1216 $result = $this->
db->query(
$sql);
1219 $num = $this->
db->num_rows($result);
1220 $min = min($num, ($limit <= 0 ? $num : $limit));
1221 for ($i = 0; $i < $min; $i++) {
1222 $method = $this->
db->fetch_object($result);
1227 throw new RestException(400, $this->
db->lasterror());
1248 public function getListOfMeasuringUnits($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1252 $sql =
"SELECT t.rowid, t.code, t.label,t.short_label, t.active, t.scale, t.unit_type";
1253 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_units as t";
1254 $sql .=
" WHERE t.active = ".((int) $active);
1259 if ($errormessage) {
1260 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1265 $sql .= $this->
db->order($sortfield, $sortorder);
1271 $offset = $limit * $page;
1273 $sql .= $this->
db->plimit($limit, $offset);
1276 $result = $this->
db->query(
$sql);
1279 $num = $this->
db->num_rows($result);
1280 $min = min($num, ($limit <= 0 ? $num : $limit));
1281 for ($i = 0; $i < $min; $i++) {
1282 $list[] = $this->
db->fetch_object($result);
1285 throw new RestException(503,
'Error when retrieving list of measuring units: '.$this->
db->lasterror());
1307 public function getListOfLegalForm($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $country = 0, $active = 1, $sqlfilters =
'')
1311 $sql =
"SELECT t.rowid, t.code, t.fk_pays, t.libelle, t.isvatexempted, t.active, t.module, t.position";
1312 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_forme_juridique as t";
1313 $sql .=
" WHERE t.active = ".((int) $active);
1315 $sql .=
" AND t.fk_pays = ".((int) $country);
1321 if ($errormessage) {
1322 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1327 $sql .= $this->
db->order($sortfield, $sortorder);
1333 $offset = $limit * $page;
1335 $sql .= $this->
db->plimit($limit, $offset);
1338 $result = $this->
db->query(
$sql);
1341 $num = $this->
db->num_rows($result);
1342 $min = min($num, ($limit <= 0 ? $num : $limit));
1343 for ($i = 0; $i < $min; $i++) {
1344 $list[] = $this->
db->fetch_object($result);
1347 throw new RestException(503,
'Error when retrieving list of legal form: '.$this->
db->lasterror());
1368 public function getListOfStaff($sortfield =
"id", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1372 $sql =
"SELECT t.id, t.code, t.libelle, t.active, t.module";
1373 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_effectif as t";
1374 $sql .=
" WHERE t.active = ".((int) $active);
1379 if ($errormessage) {
1380 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1385 $sql .= $this->
db->order($sortfield, $sortorder);
1391 $offset = $limit * $page;
1393 $sql .= $this->
db->plimit($limit, $offset);
1396 $result = $this->
db->query(
$sql);
1399 $num = $this->
db->num_rows($result);
1400 $min = min($num, ($limit <= 0 ? $num : $limit));
1401 for ($i = 0; $i < $min; $i++) {
1402 $list[] = $this->
db->fetch_object($result);
1405 throw new RestException(503,
'Error when retrieving list of staff: '.$this->
db->lasterror());
1426 public function getListOfsocialNetworks($sortfield =
"rowid", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters =
'')
1431 throw new RestException(400,
'API not available: this dictionary is not enabled by setup');
1436 $sql =
"SELECT t.rowid, t.entity, t.code, t.label, t.url, t.icon, t.active";
1437 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_socialnetworks as t";
1438 $sql .=
" WHERE t.entity IN (".getEntity(
'c_socialnetworks').
")";
1439 $sql .=
" AND t.active = ".((int) $active);
1444 if ($errormessage) {
1445 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1450 $sql .= $this->
db->order($sortfield, $sortorder);
1456 $offset = $limit * $page;
1458 $sql .= $this->
db->plimit($limit, $offset);
1461 $result = $this->
db->query(
$sql);
1464 $num = $this->
db->num_rows($result);
1465 $min = min($num, ($limit <= 0 ? $num : $limit));
1466 for ($i = 0; $i < $min; $i++) {
1467 $list[] = $this->
db->fetch_object($result);
1470 throw new RestException(503,
'Error when retrieving list of social networks: '.$this->
db->lasterror());
1492 public function getTicketsCategories($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
1496 $sql =
"SELECT rowid, code, pos, label, use_default, description";
1497 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_category as t";
1498 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_category').
")";
1499 $sql .=
" AND t.active = ".((int) $active);
1504 if ($errormessage) {
1505 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1510 $sql .= $this->
db->order($sortfield, $sortorder);
1516 $offset = $limit * $page;
1518 $sql .= $this->
db->plimit($limit, $offset);
1521 $result = $this->
db->query(
$sql);
1524 $num = $this->
db->num_rows($result);
1525 $min = min($num, ($limit <= 0 ? $num : $limit));
1526 for ($i = 0; $i < $min; $i++) {
1527 $category = $this->
db->fetch_object($result);
1528 $this->
translateLabel($category, $lang,
'TicketCategoryShort', array(
'ticket'));
1529 $list[] = $category;
1532 throw new RestException(503,
'Error when retrieving list of ticket categories : '.$this->
db->lasterror());
1554 public function getTicketsSeverities($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
1558 $sql =
"SELECT rowid, code, pos, label, use_default, color, description";
1559 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_severity as t";
1560 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_severity').
")";
1561 $sql .=
" AND t.active = ".((int) $active);
1566 if ($errormessage) {
1567 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1572 $sql .= $this->
db->order($sortfield, $sortorder);
1578 $offset = $limit * $page;
1580 $sql .= $this->
db->plimit($limit, $offset);
1583 $result = $this->
db->query(
$sql);
1586 $num = $this->
db->num_rows($result);
1587 $min = min($num, ($limit <= 0 ? $num : $limit));
1588 for ($i = 0; $i < $min; $i++) {
1589 $severity = $this->
db->fetch_object($result);
1590 $this->
translateLabel($severity, $lang,
'TicketSeverityShort', array(
'ticket'));
1591 $list[] = $severity;
1594 throw new RestException(503,
'Error when retrieving list of ticket severities : '.$this->
db->lasterror());
1616 public function getTicketsTypes($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
1620 $sql =
"SELECT rowid, code, pos, label, use_default, description";
1621 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_type as t";
1622 $sql .=
" WHERE t.entity IN (".getEntity(
'c_ticket_type').
")";
1623 $sql .=
" AND t.active = ".((int) $active);
1629 if ($errormessage) {
1630 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1635 $sql .= $this->
db->order($sortfield, $sortorder);
1641 $offset = $limit * $page;
1643 $sql .= $this->
db->plimit($limit, $offset);
1646 $result = $this->
db->query(
$sql);
1649 $num = $this->
db->num_rows($result);
1650 $min = min($num, ($limit <= 0 ? $num : $limit));
1651 for ($i = 0; $i < $min; $i++) {
1652 $type =$this->
db->fetch_object($result);
1653 $this->
translateLabel($type, $lang,
'TicketTypeShort', array(
'ticket'));
1657 throw new RestException(503,
'Error when retrieving list of ticket types : '.$this->
db->lasterror());
1679 public function getListOfIncoterms($sortfield =
"code", $sortorder =
'ASC', $limit = 100, $page = 0, $active = 1, $lang =
'', $sqlfilters =
'')
1683 $sql =
"SELECT rowid, code, active";
1684 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_incoterms as t";
1685 $sql .=
" WHERE 1=1";
1691 throw new RestException(400,
'Error when validating parameter sqlfilters -> '.$errormessage);
1693 $regexstring =
'\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)';
1694 $sql .=
" AND (".preg_replace_callback(
'/'.$regexstring.
'/',
'DolibarrApi::_forge_criteria_callback', $sqlfilters).
")";
1698 $sql .= $this->
db->order($sortfield, $sortorder);
1704 $offset = $limit * $page;
1706 $sql .= $this->
db->plimit($limit, $offset);
1709 $result = $this->
db->query(
$sql);
1712 $num = $this->
db->num_rows($result);
1713 $min = min($num, ($limit <= 0 ? $num : $limit));
1714 for ($i = 0; $i < $min; $i++) {
1715 $type =$this->
db->fetch_object($result);
1719 throw new RestException(503,
'Error when retrieving list of incoterm types : '.$this->
db->lasterror());
1736 global $conf, $mysoc;
1738 if (!DolibarrApiAccess::$user->admin
1739 && (empty($conf->global->API_LOGINS_ALLOWED_FOR_GET_COMPANY) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_GET_COMPANY)) {
1740 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');
1743 unset($mysoc->pays);
1744 unset($mysoc->note);
1747 unset($mysoc->lines);
1749 unset($mysoc->effectif);
1750 unset($mysoc->effectif_id);
1751 unset($mysoc->forme_juridique_code);
1752 unset($mysoc->forme_juridique);
1753 unset($mysoc->mode_reglement_supplier_id);
1754 unset($mysoc->cond_reglement_supplier_id);
1755 unset($mysoc->transport_mode_supplier_id);
1756 unset($mysoc->fk_prospectlevel);
1758 unset($mysoc->total_ht);
1759 unset($mysoc->total_tva);
1760 unset($mysoc->total_localtax1);
1761 unset($mysoc->total_localtax2);
1762 unset($mysoc->total_ttc);
1764 unset($mysoc->lastname);
1765 unset($mysoc->firstname);
1766 unset($mysoc->civility_id);
1768 unset($mysoc->client);
1769 unset($mysoc->prospect);
1770 unset($mysoc->fournisseur);
1771 unset($mysoc->contact_id);
1773 unset($mysoc->fk_incoterms);
1774 unset($mysoc->label_incoterms);
1775 unset($mysoc->location_incoterms);
1795 $sql =
"SELECT e.rowid, e.rowid as ref, e.label, e.address, e.zip, e.town, e.status";
1796 $sql .=
" FROM ".MAIN_DB_PREFIX.
"establishment as e";
1797 $sql .=
" WHERE e.entity IN (".getEntity(
'establishment').
')';
1802 $result = $this->
db->query(
$sql);
1805 $num = $this->
db->num_rows($result);
1806 $min = min($num, ($limit <= 0 ? $num : $limit));
1807 for ($i = 0; $i < $min; $i++) {
1808 $list[] = $this->
db->fetch_object($result);
1811 throw new RestException(503,
'Error when retrieving list of establishments : '.$this->
db->lasterror());
1831 $result = $establishment->fetch($id);
1833 throw new RestException(503,
'Error when retrieving establishment : '.$establishment->error);
1834 } elseif ($result == 0) {
1835 throw new RestException(404,
'Establishment not found');
1858 if (!DolibarrApiAccess::$user->admin
1860 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');
1863 if (!preg_match(
'/^[a-zA-Z0-9_]+$/', $constantname) || !isset($conf->global->$constantname)) {
1864 throw new RestException(404,
'Error Bad or unknown value for constantname');
1867 throw new RestException(403,
'Forbidden. This parameter cant be read with APIs');
1888 global $langs, $conf;
1890 if (!DolibarrApiAccess::$user->admin
1891 && (empty($conf->global->API_LOGINS_ALLOWED_FOR_INTEGRITY_CHECK) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_INTEGRITY_CHECK)) {
1892 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');
1895 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1896 require_once DOL_DOCUMENT_ROOT.
'/core/lib/geturl.lib.php';
1898 $langs->load(
"admin");
1900 $outexpectedchecksum =
'';
1901 $outcurrentchecksum =
'';
1904 $file_list = array(
'missing' => array(),
'updated' => array());
1907 $xmlshortfile =
dol_sanitizeFileName(
GETPOST(
'xmlshortfile',
'alpha') ?
GETPOST(
'xmlshortfile',
'alpha') :
'filelist-'.DOL_VERSION.(empty($conf->global->MAIN_FILECHECK_LOCAL_SUFFIX) ?
'' : $conf->global->MAIN_FILECHECK_LOCAL_SUFFIX).
'.xml'.(empty($conf->global->MAIN_FILECHECK_LOCAL_EXT) ?
'' : $conf->global->MAIN_FILECHECK_LOCAL_EXT));
1908 $xmlfile = DOL_DOCUMENT_ROOT.
'/install/'.$xmlshortfile;
1910 $xmlremote = ($target ==
'default' ?
'' : $target);
1911 if (empty($xmlremote) && !empty($conf->global->MAIN_FILECHECK_URL)) {
1912 $xmlremote = $conf->global->MAIN_FILECHECK_URL;
1914 $param =
'MAIN_FILECHECK_URL_'.DOL_VERSION;
1915 if (empty($xmlremote) && !empty($conf->global->$param)) {
1916 $xmlremote = $conf->global->$param;
1918 if (empty($xmlremote)) {
1919 $xmlremote =
'https://www.dolibarr.org/files/stable/signatures/filelist-'.DOL_VERSION.
'.xml';
1921 if ($xmlremote && !preg_match(
'/^https?:\/\//i', $xmlremote)) {
1922 $langs->load(
"errors");
1923 throw new RestException(500, $langs->trans(
"ErrorURLMustStartWithHttp", $xmlremote));
1925 if ($xmlremote && !preg_match(
'/\.xml$/', $xmlremote)) {
1926 $langs->load(
"errors");
1927 throw new RestException(500, $langs->trans(
"ErrorURLMustEndWith", $xmlremote,
'.xml'));
1930 if ($target ==
'local') {
1932 $xml = simplexml_load_file($xmlfile);
1934 throw new RestException(500, $langs->trans(
'XmlNotFound').
': '.$xmlfile);
1937 $xmlarray =
getURLContent($xmlremote,
'GET',
'', 1, array(), array(
'http',
'https'), 0);
1940 if (!$xmlarray[
'curl_error_no'] && $xmlarray[
'http_code'] !=
'400' && $xmlarray[
'http_code'] !=
'404') {
1941 $xmlfile = $xmlarray[
'content'];
1943 $xml = simplexml_load_string($xmlfile,
'SimpleXMLElement', LIBXML_NOCDATA|LIBXML_NONET);
1945 $errormsg = $langs->trans(
'XmlNotFound').
': '.$xmlremote.
' - '.$xmlarray[
'http_code'].(($xmlarray[
'http_code'] == 400 && $xmlarray[
'content']) ?
' '.$xmlarray[
'content'] :
'').
' '.$xmlarray[
'curl_error_no'].
' '.$xmlarray[
'curl_error_msg'];
1946 throw new RestException(500, $errormsg);
1951 $checksumconcat = array();
1952 $file_list = array();
1956 if (is_object($xml->dolibarr_constants[0])) {
1959 $out .=
'<div class="div-table-responsive-no-min">';
1960 $out .=
'<table class="noborder">';
1961 $out .=
'<tr class="liste_titre">';
1962 $out .=
'<td>#</td>';
1963 $out .=
'<td>'.$langs->trans(
"Constant").
'</td>';
1964 $out .=
'<td class="center">'.$langs->trans(
"ExpectedValue").
'</td>';
1965 $out .=
'<td class="center">'.$langs->trans(
"Value").
'</td>';
1966 $out .=
'</tr>'.
"\n";
1969 foreach ($xml->dolibarr_constants[0]->constant as $constant) {
1970 $constname = $constant[
'name'];
1971 $constvalue = (string) $constant;
1972 $constvalue = (empty($constvalue) ?
'0' : $constvalue);
1975 if ($constname && $conf->global->$constname !=
'') {
1976 $value = $conf->global->$constname;
1978 $valueforchecksum = (empty($value) ?
'0' : $value);
1980 $checksumconcat[] = $valueforchecksum;
1983 $out .=
'<tr class="oddeven">';
1984 $out .=
'<td>'.$i.
'</td>'.
"\n";
1985 $out .=
'<td>'.$constname.
'</td>'.
"\n";
1986 $out .=
'<td class="center">'.$constvalue.
'</td>'.
"\n";
1987 $out .=
'<td class="center">'.$valueforchecksum.
'</td>'.
"\n";
1992 $out .=
'<tr class="oddeven"><td colspan="4" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2001 if (is_object($xml->dolibarr_htdocs_dir[0])) {
2002 $includecustom = (empty($xml->dolibarr_htdocs_dir[0][
'includecustom']) ? 0 : $xml->dolibarr_htdocs_dir[0][
'includecustom']);
2005 $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)$';
2006 $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)$';
2007 $scanfiles =
dol_dir_list(DOL_DOCUMENT_ROOT,
'files', 1, $regextoinclude, $regextoexclude);
2010 $ret =
getFilesUpdated($file_list, $xml->dolibarr_htdocs_dir[0],
'', DOL_DOCUMENT_ROOT, $checksumconcat);
2012 foreach ($scanfiles as $keyfile => $valfile) {
2013 $tmprelativefilename = preg_replace(
'/^'.preg_quote(DOL_DOCUMENT_ROOT,
'/').
'/',
'', $valfile[
'fullname']);
2014 if (!in_array($tmprelativefilename, $file_list[
'insignature'])) {
2015 $md5newfile = @md5_file($valfile[
'fullname']);
2016 $file_list[
'added'][] = array(
'filename'=>$tmprelativefilename,
'md5'=>$md5newfile);
2023 $out .=
'<div class="div-table-responsive-no-min">';
2024 $out .=
'<table class="noborder">';
2025 $out .=
'<tr class="liste_titre">';
2026 $out .=
'<td>#</td>';
2027 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2028 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2029 $out .=
'</tr>'.
"\n";
2030 $tmpfilelist =
dol_sort_array($file_list[
'missing'],
'filename');
2031 if (is_array($tmpfilelist) && count($tmpfilelist)) {
2033 foreach ($tmpfilelist as $file) {
2035 $out .=
'<tr class="oddeven">';
2036 $out .=
'<td>'.$i.
'</td>'.
"\n";
2037 $out .=
'<td>'.$file[
'filename'].
'</td>'.
"\n";
2038 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2042 $out .=
'<tr class="oddeven"><td colspan="3" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2053 $out .=
'<div class="div-table-responsive-no-min">';
2054 $out .=
'<table class="noborder">';
2055 $out .=
'<tr class="liste_titre">';
2056 $out .=
'<td>#</td>';
2057 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2058 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2059 $out .=
'<td class="center">'.$langs->trans(
"CurrentChecksum").
'</td>';
2060 $out .=
'<td class="right">'.$langs->trans(
"Size").
'</td>';
2061 $out .=
'<td class="right">'.$langs->trans(
"DateModification").
'</td>';
2062 $out .=
'</tr>'.
"\n";
2063 $tmpfilelist2 =
dol_sort_array($file_list[
'updated'],
'filename');
2064 if (is_array($tmpfilelist2) && count($tmpfilelist2)) {
2066 foreach ($tmpfilelist2 as $file) {
2068 $out .=
'<tr class="oddeven">';
2069 $out .=
'<td>'.$i.
'</td>'.
"\n";
2070 $out .=
'<td>'.$file[
'filename'].
'</td>'.
"\n";
2071 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2072 $out .=
'<td class="center">'.$file[
'md5'].
'</td>'.
"\n";
2073 $size =
dol_filesize(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']);
2074 $totalsize += $size;
2075 $out .=
'<td class="right">'.dol_print_size($size).
'</td>'.
"\n";
2076 $out .=
'<td class="right">'.dol_print_date(
dol_filemtime(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']),
'dayhour').
'</td>'.
"\n";
2079 $out .=
'<tr class="liste_total">';
2080 $out .=
'<td></td>'.
"\n";
2081 $out .=
'<td>'.$langs->trans(
"Total").
'</td>'.
"\n";
2082 $out .=
'<td align="center"></td>'.
"\n";
2083 $out .=
'<td align="center"></td>'.
"\n";
2084 $out .=
'<td class="right">'.dol_print_size($totalsize).
'</td>'.
"\n";
2085 $out .=
'<td class="right"></td>'.
"\n";
2088 $out .=
'<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2099 $out .=
'<div class="div-table-responsive-no-min">';
2100 $out .=
'<table class="noborder">';
2101 $out .=
'<tr class="liste_titre">';
2102 $out .=
'<td>#</td>';
2103 $out .=
'<td>'.$langs->trans(
"Filename").
'</td>';
2104 $out .=
'<td class="center">'.$langs->trans(
"ExpectedChecksum").
'</td>';
2105 $out .=
'<td class="center">'.$langs->trans(
"CurrentChecksum").
'</td>';
2106 $out .=
'<td class="right">'.$langs->trans(
"Size").
'</td>';
2107 $out .=
'<td class="right">'.$langs->trans(
"DateModification").
'</td>';
2108 $out .=
'</tr>'.
"\n";
2110 if (is_array($tmpfilelist3) && count($tmpfilelist3)) {
2112 foreach ($tmpfilelist3 as $file) {
2114 $out .=
'<tr class="oddeven">';
2115 $out .=
'<td>'.$i.
'</td>'.
"\n";
2116 $out .=
'<td>'.$file[
'filename'].
'</td>'.
"\n";
2117 $out .=
'<td class="center">'.$file[
'expectedmd5'].
'</td>'.
"\n";
2118 $out .=
'<td class="center">'.$file[
'md5'].
'</td>'.
"\n";
2119 $size =
dol_filesize(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']);
2120 $totalsize += $size;
2121 $out .=
'<td class="right">'.dol_print_size($size).
'</td>'.
"\n";
2122 $out .=
'<td class="right">'.dol_print_date(
dol_filemtime(DOL_DOCUMENT_ROOT.
'/'.$file[
'filename']),
'dayhour').
'</td>'.
"\n";
2125 $out .=
'<tr class="liste_total">';
2126 $out .=
'<td></td>'.
"\n";
2127 $out .=
'<td>'.$langs->trans(
"Total").
'</td>'.
"\n";
2128 $out .=
'<td align="center"></td>'.
"\n";
2129 $out .=
'<td align="center"></td>'.
"\n";
2130 $out .=
'<td class="right">'.dol_print_size($totalsize).
'</td>'.
"\n";
2131 $out .=
'<td class="right"></td>'.
"\n";
2134 $out .=
'<tr class="oddeven"><td colspan="5" class="opacitymedium">'.$langs->trans(
"None").
'</td></tr>';
2141 if (empty($tmpfilelist) && empty($tmpfilelist2) && empty($tmpfilelist3)) {
2147 throw new RestException(500,
'Error: Failed to found dolibarr_htdocs_dir into XML file '.$xmlfile);
2152 asort($checksumconcat);
2153 $checksumget = md5(join(
',', $checksumconcat));
2154 $checksumtoget = trim((
string) $xml->dolibarr_htdocs_dir_checksum);
2156 $outexpectedchecksum = ($checksumtoget ? $checksumtoget : $langs->trans(
"Unknown"));
2157 if ($checksumget == $checksumtoget) {
2158 if (count($file_list[
'added'])) {
2159 $resultcode =
'warning';
2160 $resultcomment =
'FileIntegrityIsOkButFilesWereAdded';
2162 $outcurrentchecksum = $checksumget;
2165 $resultcomment =
'Success';
2167 $outcurrentchecksum = $checksumget;
2170 $resultcode =
'error';
2171 $resultcomment =
'Error';
2173 $outcurrentchecksum = $checksumget;
2176 throw new RestException(404,
'No signature file known');
2179 return array(
'resultcode'=>$resultcode,
'resultcomment'=>$resultcomment,
'expectedchecksum'=> $outexpectedchecksum,
'currentchecksum'=> $outcurrentchecksum,
'out'=>$out);
2196 if (!DolibarrApiAccess::$user->admin
2197 && (empty($conf->global->API_LOGINS_ALLOWED_FOR_GET_MODULES) || DolibarrApiAccess::$user->login != $conf->global->API_LOGINS_ALLOWED_FOR_GET_MODULES)) {
2198 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');
2201 sort($conf->modules);