20 use Luracast\Restler\Restler;
21 use Luracast\Restler\RestException;
22 use Luracast\Restler\Defaults;
23 use Luracast\Restler\Format\UploadFormat;
25 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
50 public function __construct($db, $cachedir =
'', $refreshCache =
false)
52 global $conf, $dolibarr_main_url_root;
54 if (empty($cachedir)) $cachedir = $conf->api->dir_temp;
55 Defaults::$cacheDirectory = $cachedir;
58 $production_mode = (empty($conf->global->API_PRODUCTION_MODE) ?
false :
true);
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);
103 unset($object->isextrafieldmanaged);
104 unset($object->ismultientitymanaged);
105 unset($object->restrictiononfksoc);
106 unset($object->table_rowid);
109 unset($object->linkedObjects);
111 unset($object->fields);
112 unset($object->oldline);
114 unset($object->error);
115 unset($object->errors);
116 unset($object->errorhidden);
118 unset($object->ref_previous);
119 unset($object->ref_next);
120 unset($object->ref_int);
122 unset($object->projet);
123 unset($object->project);
124 unset($object->author);
125 unset($object->timespent_old_duration);
126 unset($object->timespent_id);
127 unset($object->timespent_duration);
128 unset($object->timespent_date);
129 unset($object->timespent_datehour);
130 unset($object->timespent_withhour);
131 unset($object->timespent_fk_user);
132 unset($object->timespent_note);
133 unset($object->fk_delivery_address);
135 unset($object->statuts);
136 unset($object->statuts_short);
137 unset($object->statuts_logo);
138 unset($object->statuts_long);
139 unset($object->labelStatus);
140 unset($object->labelStatusShort);
142 unset($object->stats_propale);
143 unset($object->stats_commande);
144 unset($object->stats_contrat);
145 unset($object->stats_facture);
146 unset($object->stats_commande_fournisseur);
147 unset($object->stats_reception);
148 unset($object->stats_mrptoconsume);
149 unset($object->stats_mrptoproduce);
151 unset($object->element);
152 unset($object->fk_element);
153 unset($object->table_element);
154 unset($object->table_element_line);
155 unset($object->class_element_line);
156 unset($object->picto);
158 unset($object->fieldsforcombobox);
160 unset($object->skip_update_total);
161 unset($object->context);
162 unset($object->next_prev_filter);
164 unset($object->region);
165 unset($object->region_code);
167 unset($object->libelle_statut);
168 unset($object->libelle_paiement);
170 unset($object->prefix_comm);
172 unset($object->sendtoid);
173 unset($object->name_bis);
174 unset($object->newref);
176 if (!isset($object->table_element) || $object->table_element !=
'ticket') {
177 unset($object->comments);
189 unset($object->oldcopy);
192 if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) {
193 $nboflines = count($object->lines);
194 for ($i = 0; $i < $nboflines; $i++)
198 unset($object->lines[$i]->contact);
199 unset($object->lines[$i]->contact_id);
200 unset($object->lines[$i]->country);
201 unset($object->lines[$i]->country_id);
202 unset($object->lines[$i]->country_code);
203 unset($object->lines[$i]->mode_reglement_id);
204 unset($object->lines[$i]->mode_reglement_code);
205 unset($object->lines[$i]->mode_reglement);
206 unset($object->lines[$i]->cond_reglement_id);
207 unset($object->lines[$i]->cond_reglement_code);
208 unset($object->lines[$i]->cond_reglement);
209 unset($object->lines[$i]->fk_delivery_address);
210 unset($object->lines[$i]->fk_projet);
211 unset($object->lines[$i]->fk_project);
212 unset($object->lines[$i]->thirdparty);
213 unset($object->lines[$i]->user);
214 unset($object->lines[$i]->model_pdf);
215 unset($object->lines[$i]->modelpdf);
216 unset($object->lines[$i]->note_public);
217 unset($object->lines[$i]->note_private);
218 unset($object->lines[$i]->fk_incoterms);
219 unset($object->lines[$i]->label_incoterms);
220 unset($object->lines[$i]->location_incoterms);
221 unset($object->lines[$i]->name);
222 unset($object->lines[$i]->lastname);
223 unset($object->lines[$i]->firstname);
224 unset($object->lines[$i]->civility_id);
225 unset($object->lines[$i]->fk_multicurrency);
226 unset($object->lines[$i]->multicurrency_code);
227 unset($object->lines[$i]->shipping_method_id);
231 if (!empty($object->thirdparty) && is_object($object->thirdparty)) {
252 protected static function _checkAccessToResource($resource, $resource_id = 0, $dbtablename =
'', $feature2 =
'', $dbt_keyfield =
'fk_soc', $dbt_select =
'rowid')
256 $featuresarray = array($resource);
257 if (preg_match(
'/&/', $resource)) {
258 $featuresarray = explode(
"&", $resource);
259 } elseif (preg_match(
'/\|/', $resource)) {
260 $featuresarray = explode(
"|", $resource);
264 if (!empty($feature2)) {
265 $feature2 = explode(
"|", $feature2);
268 return checkUserAccessToObject(DolibarrApiAccess::$user, $featuresarray, $resource_id, $dbtablename, $feature2, $dbt_keyfield, $dbt_select);
285 $i = 0; $nb = strlen($tmp);
289 if ($tmp[$i] ==
'(') $counter++;
290 if ($tmp[$i] ==
')') $counter--;
293 $error =
"Bad sqlfilters=".$sqlfilters;
316 if (empty($matches[1]))
return '';
317 $tmp = explode(
':', $matches[1]);
318 if (count($tmp) < 3)
return '';
320 $tmpescaped = $tmp[2];
322 if (preg_match(
'/^\'(.*)\'$/', $tmpescaped, $regbis))
324 $tmpescaped =
"'".$db->escape($regbis[1]).
"'";
326 $tmpescaped = $db->escape($tmpescaped);
328 return $db->escape($tmp[0]).
' '.strtoupper($db->escape($tmp[1])).
" ".$tmpescaped;
checkUserAccessToObject($user, $featuresarray, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= '', $dbt_select= 'rowid', $parenttableforentity= '')
Check access by user to object.
_cleanObjectDatas($object)
Executed method when API is called without parameter.
$conf db
API class for accounts.
_checkFilters($sqlfilters)
Return if a $sqlfilters parameter is valid.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid')
Check user access to a resource.
static _forge_criteria_callback($matches)
Function to forge a SQL criteria.
__construct($db, $cachedir= '', $refreshCache=false)
Constructor.