21use Luracast\Restler\Restler;
22use Luracast\Restler\Defaults;
24require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
48 public function __construct($db, $cachedir =
'', $refreshCache =
false)
50 global $conf, $dolibarr_main_url_root;
52 if (empty($cachedir)) {
53 $cachedir = $conf->api->dir_temp;
55 Defaults::$cacheDirectory = $cachedir;
59 $this->r =
new Restler($production_mode, $refreshCache);
61 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
62 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
64 $urlwithouturlrootautodetect = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(DOL_MAIN_URL_ROOT));
65 $urlwithrootautodetect = $urlwithouturlroot.DOL_URL_ROOT;
67 $this->r->setBaseUrls($urlwithouturlroot, $urlwithouturlrootautodetect);
68 $this->r->setAPIVersion(1);
85 if (!is_array($value)) {
87 if (!empty(
$object->fields) && !empty(
$object->fields[$field]) && !empty(
$object->fields[$field][
'type'])) {
88 if (strpos(
$object->fields[$field][
'type'],
'int') || strpos(
$object->fields[$field][
'type'],
'double') || in_array(
$object->fields[$field][
'type'], array(
'real',
'price',
'stock'))) {
91 if (
$object->fields[$field][
'type'] ==
'html') {
94 if (
$object->fields[$field][
'type'] ==
'select') {
98 if (
$object->fields[$field][
'type'] ==
'sellist' ||
$object->fields[$field][
'type'] ==
'checkbox') {
101 if (
$object->fields[$field][
'type'] ==
'boolean' ||
$object->fields[$field][
'type'] ==
'radio') {
104 if (
$object->fields[$field][
'type'] ==
'email') {
107 if (
$object->fields[$field][
'type'] ==
'password') {
113 if (in_array($field, array(
'note',
'note_private',
'note_public',
'desc',
'description'))) {
119 $newarrayvalue = array();
120 foreach ($value as $tmpkey => $tmpvalue) {
124 return $newarrayvalue;
140 if (empty($properties)) {
145 $arr_properties = explode(
',', $properties);
146 $magic_properties = array();
147 $real_properties = get_object_vars(
$object);
151 foreach ($arr_properties as $key) {
152 if (!array_key_exists($key, $real_properties)) {
156 $magic_properties[$key] =
$object->$key;
162 foreach (get_object_vars(
$object) as $key => $value) {
163 if (!in_array($key, $arr_properties)) {
169 foreach ($magic_properties as $key => $value) {
188 unset(
$object->isextrafieldmanaged);
189 unset(
$object->ismultientitymanaged);
190 unset(
$object->restrictiononfksoc);
193 unset(
$object->pass_indatabase);
210 unset(
$object->barcode_type_code);
211 unset(
$object->barcode_type_label);
213 unset(
$object->mode_reglement);
214 unset(
$object->cond_reglement);
223 unset(
$object->timespent_old_duration);
225 unset(
$object->timespent_duration);
226 unset(
$object->timespent_date);
227 unset(
$object->timespent_datehour);
228 unset(
$object->timespent_withhour);
229 unset(
$object->timespent_fk_user);
230 unset(
$object->timespent_note);
231 unset(
$object->fk_delivery_address);
240 unset(
$object->showphoto_on_popup);
248 unset(
$object->stats_commande);
251 unset(
$object->stats_commande_fournisseur);
252 unset(
$object->stats_reception);
253 unset(
$object->stats_mrptoconsume);
254 unset(
$object->stats_mrptoproduce);
256 unset(
$object->fieldsforcombobox);
259 unset(
$object->skip_update_total);
261 unset(
$object->next_prev_filter);
268 unset(
$object->fk_departement);
270 unset(
$object->departement_code);
272 unset(
$object->libelle_statut);
273 unset(
$object->libelle_paiement);
275 unset(
$object->labelStatusShort);
282 if (!isset(
$object->table_element) || ! in_array(
$object->table_element, array(
'expensereport_det',
'ticket'))) {
289 unset(
$object->element_for_permission);
292 unset(
$object->table_element_line);
293 unset(
$object->class_element_line);
295 unset(
$object->linked_objects);
310 $nboflines = count(
$object->lines);
311 for ($i = 0; $i < $nboflines; $i++) {
314 unset(
$object->lines[$i]->contact);
315 unset(
$object->lines[$i]->contact_id);
316 unset(
$object->lines[$i]->country);
317 unset(
$object->lines[$i]->country_id);
318 unset(
$object->lines[$i]->country_code);
319 unset(
$object->lines[$i]->mode_reglement_id);
320 unset(
$object->lines[$i]->mode_reglement_code);
321 unset(
$object->lines[$i]->mode_reglement);
322 unset(
$object->lines[$i]->cond_reglement_id);
323 unset(
$object->lines[$i]->cond_reglement_code);
324 unset(
$object->lines[$i]->cond_reglement);
325 unset(
$object->lines[$i]->fk_delivery_address);
326 unset(
$object->lines[$i]->fk_projet);
327 unset(
$object->lines[$i]->fk_project);
328 unset(
$object->lines[$i]->thirdparty);
329 unset(
$object->lines[$i]->user);
330 unset(
$object->lines[$i]->model_pdf);
331 unset(
$object->lines[$i]->note_public);
332 unset(
$object->lines[$i]->note_private);
333 unset(
$object->lines[$i]->fk_incoterms);
334 unset(
$object->lines[$i]->label_incoterms);
335 unset(
$object->lines[$i]->location_incoterms);
336 unset(
$object->lines[$i]->name);
337 unset(
$object->lines[$i]->lastname);
338 unset(
$object->lines[$i]->firstname);
339 unset(
$object->lines[$i]->civility_id);
340 unset(
$object->lines[$i]->fk_multicurrency);
341 unset(
$object->lines[$i]->multicurrency_code);
342 unset(
$object->lines[$i]->shipping_method_id);
346 if (!empty(
$object->thirdparty) && is_object(
$object->thirdparty)) {
369 protected static function _checkAccessToResource($resource, $resource_id = 0, $dbtablename =
'', $feature2 =
'', $dbt_keyfield =
'fk_soc', $dbt_select =
'rowid')
373 $featuresarray = array($resource);
374 if (preg_match(
'/&/', $resource)) {
375 $featuresarray = explode(
"&", $resource);
376 } elseif (preg_match(
'/\|/', $resource)) {
377 $featuresarray = explode(
"|", $resource);
381 if (!empty($feature2)) {
382 $feature2 = explode(
"|", $feature2);
385 return checkUserAccessToObject(DolibarrApiAccess::$user, $featuresarray, $resource_id, $dbtablename, $feature2, $dbt_keyfield, $dbt_select);
400 $firstandlastparenthesis = 0;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
__construct($db, $cachedir='', $refreshCache=false)
Constructor.
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid')
Check access by user to a given resource.
_checkFilters($sqlfilters, &$error='')
Return if a $sqlfilters parameter is valid Function no more used.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
_cleanObjectDatas($object)
Clean sensible object datas.
static _forge_criteria_callback($matches)
Function to forge a SQL criteria from a Generic filter string.
dolCheckFilters($sqlfilters, &$error='', &$parenthesislevel=0)
Return if a $sqlfilters parameter has a valid balance of parenthesis.
dolForgeCriteriaCallback($matches)
Function to forge a SQL criteria from a Dolibarr filter syntax string.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
sanitizeVal($out='', $check='alphanohtml', $filter=null, $options=null)
Return a sanitized or empty value after checking value against a rule.
checkUserAccessToObject($user, array $featuresarray, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='', $dbt_select='rowid', $parenttableforentity='')
Check that access by a given user to an object is ok.