dolibarr 24.0.2
api_users.class.php
1<?php
2/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
3 * Copyright (C) 2020-2025 Thibault FOUCART <support@ptibogxiv.net>
4 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
6 * Copyright (C) 2025 William Mead <william@m34d.com>
7 * Copyright (C) 2025 Jean François Baillette <jean-francois@swiiptel.net>
8 * Copyright (C) 2026 Charlene Benke <charlene@patas-monkey.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24use Luracast\Restler\RestException;
25
26require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
27require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
28require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
29
30
39class Users extends DolibarrApi
40{
44 public static $FIELDS = array(
45 'login',
46 );
47
51 public $useraccount;
52
56 public function __construct()
57 {
58 global $db;
59
60 $this->db = $db;
61 $this->useraccount = new User($this->db);
62 }
63
64
86 public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = '0', $category = 0, $sqlfilters = '', $properties = '')
87 {
88 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) {
89 throw new RestException(403, "You are not allowed to read list of users");
90 }
91
92 $obj_ret = array();
93
94 // case of external user, $societe param is ignored and replaced by user's socid
95 //$socid = DolibarrApiAccess::$user->socid ?: $societe;
96
97 $sql = "SELECT t.rowid";
98 $sql .= " FROM ".MAIN_DB_PREFIX."user AS t LEFT JOIN ".MAIN_DB_PREFIX."user_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields
99 if ($category > 0) {
100 $sql .= ", ".$this->db->prefix()."categorie_user as c";
101 }
102 $sql .= ' WHERE t.entity IN ('.getEntity('user').')';
103 if ($user_ids) {
104 $sql .= " AND t.rowid IN (".$this->db->sanitize($user_ids).")";
105 }
106
107 // Select products of given category
108 if ($category > 0) {
109 $sql .= " AND c.fk_categorie = ".((int) $category);
110 $sql .= " AND c.fk_user = t.rowid";
111 }
112
113 // Add sql filters
114 if ($sqlfilters) {
115 // List of properties we can't filter on, whatever are permissions (to avoid guess by search binary attack)
116 $forbiddenfilterfields = array(
117 'pass',
118 'pass_crypted',
119 'pass_temp',
120 'api_key',
121 'openid'
122 );
123 $canreadsalary = ((isModEnabled('salaries') && DolibarrApiAccess::$user->hasRight('salaries', 'read')) || !isModEnabled('salaries'));
124 if (!$canreadsalary) {
125 $forbiddenfilterfields[] = 'salary';
126 $forbiddenfilterfields[] = 'salaryextra';
127 $forbiddenfilterfields[] = 'thm';
128 $forbiddenfilterfields[] = 'tjm';
129 }
130
131 $errormessage = '';
132 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage, 0, 0, 0, $forbiddenfilterfields);
133 if ($errormessage) {
134 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
135 }
136 }
137
138 $sql .= $this->db->order($sortfield, $sortorder);
139 if ($limit) {
140 if ($page < 0) {
141 $page = 0;
142 }
143 $offset = $limit * $page;
144
145 $sql .= $this->db->plimit($limit + 1, $offset);
146 }
147
148 $result = $this->db->query($sql);
149
150 if ($result) {
151 $i = 0;
152 $num = $this->db->num_rows($result);
153 $min = min($num, ($limit <= 0 ? $num : $limit));
154 while ($i < $min) {
155 $obj = $this->db->fetch_object($result);
156 $user_static = new User($this->db);
157 if ($user_static->fetch($obj->rowid)) {
158 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($user_static), $properties);
159 }
160 $i++;
161 }
162 } else {
163 throw new RestException(503, 'Error when retrieve User list : '.$this->db->lasterror());
164 }
165
166 return $obj_ret;
167 }
168
184 public function get($id, $includepermissions = 0)
185 {
186 if ($id == 0) {
187 throw new RestException(400, 'No user with id=0 can exist');
188 }
189
190 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin) && DolibarrApiAccess::$user->id != $id) {
191 throw new RestException(403, 'Not allowed');
192 }
193
194 if ($id == 0) {
195 $result = $this->useraccount->initAsSpecimen();
196 } else {
197 $result = $this->useraccount->fetch($id);
198 }
199 if (!$result) {
200 throw new RestException(404, 'User not found');
201 }
202
203 if ($id > 0 && !DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
204 throw new RestException(403, 'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
205 }
206
207 if ($includepermissions) {
208 $this->useraccount->loadRights();
209 }
210
211 return $this->_cleanObjectDatas($this->useraccount);
212 }
213
231 public function getByLogin($login, $includepermissions = 0)
232 {
233 if (empty($login)) {
234 throw new RestException(400, 'Bad parameters');
235 }
236
237 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin) && DolibarrApiAccess::$user->login != $login) {
238 throw new RestException(403, 'Not allowed');
239 }
240
241 $result = $this->useraccount->fetch(0, $login);
242 if (!$result) {
243 throw new RestException(404, 'User not found');
244 }
245
246 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
247 throw new RestException(403, 'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
248 }
249
250 if ($includepermissions) {
251 $this->useraccount->loadRights();
252 }
253
254 return $this->_cleanObjectDatas($this->useraccount);
255 }
256
274 public function getByEmail($email, $includepermissions = 0)
275 {
276 if (empty($email)) {
277 throw new RestException(400, 'Bad parameters');
278 }
279
280 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin) && DolibarrApiAccess::$user->email != $email) {
281 throw new RestException(403, 'Not allowed');
282 }
283
284 $result = $this->useraccount->fetch(0, '', '', 0, -1, $email);
285 if (!$result) {
286 throw new RestException(404, 'User not found');
287 }
288
289 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
290 throw new RestException(403, 'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
291 }
292
293 if ($includepermissions) {
294 $this->useraccount->loadRights();
295 }
296
297 return $this->_cleanObjectDatas($this->useraccount);
298 }
299
315 public function getInfo($includepermissions = 0)
316 {
317 if (!DolibarrApiAccess::$user->hasRight('user', 'self', 'creer') && !DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) {
318 throw new RestException(403, 'Not allowed');
319 }
320
321 $apiUser = DolibarrApiAccess::$user;
322
323 $result = $this->useraccount->fetch($apiUser->id);
324 if (!$result) {
325 throw new RestException(404, 'User not found');
326 }
327
328 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
329 throw new RestException(403, 'Access on this object not allowed to current logged user');
330 }
331
332 if ($includepermissions) {
333 $this->useraccount->loadRights();
334 }
335
336 $usergroup = new UserGroup($this->db);
337 $userGroupList = $usergroup->listGroupsForUser($apiUser->id, false);
338 if (!is_array($userGroupList)) {
339 throw new RestException(404, 'User group not found');
340 }
341
342 $this->useraccount->user_group_list = $this->_cleanUserGroupListDatas($userGroupList);
343
344 return $this->_cleanObjectDatas($this->useraccount);
345 }
346
359 public function post($request_data = null)
360 {
361 // Check user authorization
362 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer') && empty(DolibarrApiAccess::$user->admin)) {
363 throw new RestException(403, "User creation not allowed for login ".DolibarrApiAccess::$user->login);
364 }
365
366 // check mandatory fields
367 if (!isset($request_data["login"]))
368 throw new RestException(500, "login field missing");
369 /*if (!isset($request_data["password"]))
370 throw new RestException(400, "password field missing");
371 if (!isset($request_data["lastname"]))
372 throw new RestException(400, "lastname field missing");*/
373
374 //assign field values
375 foreach ($request_data as $field => $value) {
376 if (in_array($field, array('pass_crypted', 'pass_indatabase', 'pass_indatabase_crypted', 'pass_temp', 'api_key', 'openid'))) {
377 // This properties can't be set/modified with API
378 throw new RestException(405, 'The property '.$field." can't be set/modified using the APIs");
379 }
380 if ($field == 'pass') {
381 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'password')) { // In creation, users is always a different user than the one who create it.
382 throw new RestException(403, 'You are not allowed to modify/set password of other users');
383 }
384 if (!DolibarrApiAccess::$user->admin) { // Only admin can set a password and knowing it. Others can reset with correct rights user->self->password but without knowing it.
385 throw new RestException(403, 'As a non admin user, you are not allowed to set a password from this API. Use the /setPassword endpoint for this.');
386 }
387 }
388
389 $canreadsalary = ((isModEnabled('salaries') && DolibarrApiAccess::$user->hasRight('salaries', 'read')) || !isModEnabled('salaries'));
390 if (!$canreadsalary) {
391 if (in_array($field, array('salary', 'salaryextra', 'thm', 'tjm'))) {
392 // This properties can't be set/modified with API
393 throw new RestException(405, 'The property '.$field." can't be set/modified using the APIs with permission on salaries");
394 }
395 }
396
397 if ($field === 'caller') {
398 // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
399 $this->useraccount->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
400 continue;
401 }
402
403 if (DolibarrApiAccess::$user->admin) { // If user for API is admin
404 if ($field == 'admin' && $value != $this->useraccount->admin && empty($value)) {
405 throw new RestException(403, 'Reseting the admin status of a user is not possible using the API');
406 }
407 } else {
408 if ($field == 'admin' && $value != $this->useraccount->admin) {
409 throw new RestException(403, 'Only an admin user can modify the admin status of another user');
410 }
411 }
412
413 $this->useraccount->$field = $this->_checkValForAPI($field, $value, $this->useraccount);
414 }
415
416 if ($this->useraccount->create(DolibarrApiAccess::$user) < 0) {
417 throw new RestException(500, 'Error creating', array_merge(array($this->useraccount->error), $this->useraccount->errors));
418 }
419 return $this->useraccount->id;
420 }
421
422
438 public function put($id, $request_data = null)
439 {
440 $isSelfUpdate = ((int) $id === (int) DolibarrApiAccess::$user->id);
441
442 // Check user authorization
443 if (
444 !DolibarrApiAccess::$user->hasRight('user', 'user', 'creer')
445 && !DolibarrApiAccess::$user->hasRight('user', 'user', 'write')
446 && !(
447 $isSelfUpdate
448 && (
449 DolibarrApiAccess::$user->hasRight('user', 'self', 'creer')
450 || DolibarrApiAccess::$user->hasRight('user', 'self', 'write')
451 )
452 )
453 && empty(DolibarrApiAccess::$user->admin)
454 ) {
455 throw new RestException(403, "User update not allowed");
456 }
457
458 $result = $this->useraccount->fetch($id);
459 if (!$result) {
460 throw new RestException(404, 'Account not found');
461 }
462
463 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
464 throw new RestException(403, 'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
465 }
466
467 foreach ($request_data as $field => $value) {
468 if (in_array($field, array('pass_crypted', 'pass_indatabase', 'pass_indatabase_crypted', 'pass_temp', 'api_key', 'openid'))) {
469 // This properties can't be set/modified with API
470 throw new RestException(405, 'The property '.$field." can't be set/modified using the APIs");
471 }
472
473 $canreadsalary = ((isModEnabled('salaries') && DolibarrApiAccess::$user->hasRight('salaries', 'read')) || !isModEnabled('salaries'));
474 if (!$canreadsalary) {
475 if (in_array($field, array('salary', 'salaryextra', 'thm', 'tjm'))) {
476 // This properties can't be set/modified with API
477 throw new RestException(405, 'The property '.$field." can't be set/modified using the APIs with permission on salaries");
478 }
479 }
480
481 if ($field == 'id') {
482 continue;
483 }
484 if ($field == 'pass') {
485 if ($this->useraccount->id != DolibarrApiAccess::$user->id && !DolibarrApiAccess::$user->hasRight('user', 'user', 'password')) {
486 throw new RestException(403, 'You are not allowed to modify password of other users');
487 }
488 if ($this->useraccount->id == DolibarrApiAccess::$user->id && !DolibarrApiAccess::$user->hasRight('user', 'self', 'password')) {
489 throw new RestException(403, 'You are not allowed to modify your own password');
490 }
491 if (!DolibarrApiAccess::$user->admin) { // Only admin can set a password and knowing it. Others can reset with correct rights user->self->password but without knowing it.
492 throw new RestException(403, 'As a non admin user, you are not allowed to set a password from this API. Use the /setPassword endpoint for this.');
493 }
494 }
495 if ($field === 'caller') {
496 // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
497 $this->useraccount->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
498 continue;
499 }
500 if ($field == 'array_options' && is_array($value)) {
501 foreach ($value as $index => $val) {
502 $this->useraccount->array_options[$index] = $this->_checkValExtrafieldsForAPI($index, $val, $this->useraccount);
503 }
504 continue;
505 }
506
507 if (DolibarrApiAccess::$user->admin) { // If user for API is admin
508 if ($field == 'admin' && $value != $this->useraccount->admin && empty($value)) {
509 throw new RestException(403, 'Reseting the admin status of a user is not possible using the API');
510 }
511 } else {
512 if ($field == 'admin' && $value != $this->useraccount->admin) {
513 throw new RestException(403, 'Only an admin user can modify the admin status of another user');
514 }
515 }
516 if ($field == 'entity' && $value != $this->useraccount->entity) {
517 throw new RestException(403, 'Changing entity of a user using the APIs is not possible');
518 }
519
520 // The status must be updated using setstatus() because it
521 // is not handled by the update() method.
522 if ($field == 'statut' || $field == 'status') {
523 $result = $this->useraccount->setstatus($value);
524 if ($result < 0) {
525 throw new RestException(500, 'Error when updating status of user: '.$this->useraccount->error);
526 }
527 } else {
528 $this->useraccount->$field = $this->_checkValForAPI($field, $value, $this->useraccount);
529 }
530 }
531
532 // If there is no error, update() returns the number of affected
533 // rows so if the update is a no op, the return value is zezo.
534 if ($this->useraccount->update(DolibarrApiAccess::$user) >= 0) {
535 return $this->get($id);
536 } else {
537 throw new RestException(500, $this->useraccount->error);
538 }
539 }
540
556 public function setPassword($id, $send_password = false)
557 {
558 if (!getDolGlobalInt('API_ENABLE_LOGIN_API')) {
559 throw new RestException(403, "Error: login and password reset APIs are disabled. You can get access token from the backoffice to get access permission but permission and password manipulation from APIs are forbidden.");
560 }
561
562 if (!getDolGlobalString('API_ALLOW_PASSWORD_RESET')) {
563 throw new RestException(403, "Error: password reset APIs are disabled by default. To allow this, the option API_ALLOW_PASSWORD_RESET must be set.");
564 }
565
566 if ($id != DolibarrApiAccess::$user->id && !DolibarrApiAccess::$user->hasRight('user', 'user', 'password')) {
567 throw new RestException(403, 'You are not allowed to modify password of other users');
568 }
569 if ($id == DolibarrApiAccess::$user->id && !DolibarrApiAccess::$user->hasRight('user', 'self', 'password')) {
570 throw new RestException(403, 'You are not allowed to modify your own password');
571 }
572
573 $result = $this->useraccount->fetch($id);
574 if (!$result) {
575 throw new RestException(404, 'User not found, no password changed');
576 }
577
578 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
579 throw new RestException(403, 'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
580 }
581
582 $newpassword = $this->useraccount->setPassword($this->useraccount, ''); // This will generate a new password
583 if (is_int($newpassword) && $newpassword < 0) {
584 throw new RestException(500, 'ErrorFailedToSetNewPassword'.$this->useraccount->error);
585 } else {
586 // Success
587 if ($send_password) {
588 if ($this->useraccount->send_password($this->useraccount, $newpassword) > 0) {
589 return 2;
590 } else {
591 throw new RestException(500, 'ErrorFailedSendingNewPassword - '.$this->useraccount->error);
592 }
593 } else {
594 return 1;
595 }
596 }
597 }
598
615 public function getGroups($id)
616 {
617 if ($id == 0) {
618 throw new RestException(400, 'No user with id=0 can exist');
619 }
620
621 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) {
622 throw new RestException(403);
623 }
624
625 $user = new User($this->db);
626 $result = $user->fetch($id);
627 if (!$result) {
628 throw new RestException(404, 'User not found');
629 }
630 if (!DolibarrApi::_checkAccessToResource('user', $user->id, 'user')) {
631 throw new RestException(403, 'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
632 }
633
634 $usergroup = new UserGroup($this->db);
635 $groups = $usergroup->listGroupsForUser($id, false);
636 $obj_ret = array();
637 foreach ($groups as $group) {
638 $obj_ret[] = $this->_cleanObjectDatas($group);
639 }
640 return $obj_ret;
641 }
642
643
660 public function setGroup($id, $group, $entity = 1)
661 {
662 global $conf;
663
664 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer') && empty(DolibarrApiAccess::$user->admin)) {
665 throw new RestException(403, 'setGroup on users not allowed for login '.DolibarrApiAccess::$user->login);
666 }
667
668 $result = $this->useraccount->fetch($id);
669 if (!$result) {
670 throw new RestException(404, 'User not found');
671 }
672
673 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
674 throw new RestException(403, 'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
675 }
676
677 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE') && !empty(DolibarrApiAccess::$user->admin) && empty(DolibarrApiAccess::$user->entity)) {
678 $entity = (!empty($entity) ? (int) $entity : $conf->entity);
679 } else {
680 // When using API, action is done on entity of logged user because a user of entity X with permission to create user should not be able to
681 // hack the security by giving himself permissions on another entity.
682 $entity = (((int) DolibarrApiAccess::$user->entity) > 0 ? (int) DolibarrApiAccess::$user->entity : $conf->entity);
683 }
684
685 $result = $this->useraccount->SetInGroup($group, $entity);
686 if (!($result > 0)) {
687 throw new RestException(500, $this->useraccount->error);
688 }
689
690 return 1;
691 }
692
706 public function postGroups($request_data = null)
707 {
708 // Check user authorization
709 if (!DolibarrApiAccess::$user->hasRight('user', 'group_advance', 'write') && empty(DolibarrApiAccess::$user->admin)) {
710 throw new RestException(403, "Usergroup creation not allowed for login ".DolibarrApiAccess::$user->login);
711 }
712 $usergroup = new UserGroup($this->db);
713 foreach ($request_data as $field => $value) {
714 if ($field === 'caller') {
715 // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
716 $usergroup->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
717 continue;
718 }
719 if ($field == 'id') {
720 throw new RestException(400, 'Creating with id field is forbidden');
721 }
722
723 $usergroup->$field = $this->_checkValForAPI($field, $value, $usergroup);
724 }
725
726 if ($usergroup->create(1) < 0) {
727 throw new RestException(500, 'Error creating', array_merge(array($usergroup->error), $usergroup->errors));
728 }
729 return $usergroup->id;
730 }
731
749 public function putGroups($group, $request_data = null)
750 {
751 // Check user authorization
752 if (!DolibarrApiAccess::$user->hasRight('user', 'group_advance', 'write') && empty(DolibarrApiAccess::$user->admin)) {
753 throw new RestException(403, "Usergroup update not allowed");
754 }
755
756 $usergroup = new UserGroup($this->db);
757
758 $result = $usergroup->fetch($group);
759 if ($result < 1) {
760 throw new RestException(404, 'Usergroup not found');
761 }
762
763 foreach ($request_data as $field => $value) {
764 if ($field == 'id') {
765 throw new RestException(400, 'Updating with id field is forbidden');
766 }
767 if ($field === 'caller') {
768 // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller
769 $usergroup->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
770 continue;
771 }
772
773 if ($field == 'entity' && $value != $usergroup->entity) {
774 throw new RestException(403, 'Changing entity of a user using the APIs is not possible');
775 }
776
777 $usergroup->$field = $this->_checkValForAPI($field, $value, $usergroup);
778 }
779
780 // If there is no error, update() returns the number of affected
781 // rows so if the update is a no op, the return value is zezo.
782 if ($usergroup->update() >= 0) {
783 return $this->infoGroups($group);
784 } else {
785 throw new RestException(500, $usergroup->error);
786 }
787 }
788
804 public function removeUserFromGroup($id, $group)
805 {
806 global $conf;
807
808 if (!DolibarrApiAccess::$user->admin) {
809 throw new RestException(403, 'Only admin can remove users from groups');
810 }
811
812 $result = $this->useraccount->fetch($id);
813 if (!$result) {
814 throw new RestException(404, 'User not found');
815 }
816
817 // Same entity resolution as setGroup(): the action is done on the entity of the logged user, so an
818 // admin of one entity can not remove the group link of a user in another entity.
819 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE') && empty(DolibarrApiAccess::$user->entity)) {
820 $entity = $conf->entity;
821 } else {
822 $entity = (((int) DolibarrApiAccess::$user->entity) > 0 ? (int) DolibarrApiAccess::$user->entity : $conf->entity);
823 }
824
825 $result = $this->useraccount->RemoveFromGroup($group, $entity);
826 if (!($result > 0)) {
827 throw new RestException(500, $this->useraccount->error);
828 }
829
830 return [
831 'success' => true,
832 'message' => "User $id removed from group $group"
833 ];
834 }
835
860 public function listGroups($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $group_ids = '0', $sqlfilters = '', $properties = '')
861 {
862 $obj_ret = array();
863
864 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) ||
865 getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight('user', 'group_advance', 'read') && empty(DolibarrApiAccess::$user->admin)) {
866 throw new RestException(403, "You are not allowed to read groups");
867 }
868
869 // case of external user, $societe param is ignored and replaced by user's socid
870 //$socid = DolibarrApiAccess::$user->socid ?: $societe;
871
872 $sql = "SELECT t.rowid";
873 $sql .= " FROM ".MAIN_DB_PREFIX."usergroup AS t LEFT JOIN ".MAIN_DB_PREFIX."usergroup_extrafields AS ef ON (ef.fk_object = t.rowid)"; // Modification VMR Global Solutions to include extrafields as search parameters in the API GET call, so we will be able to filter on extrafields
874 $sql .= ' WHERE t.entity IN ('.getEntity('user').')';
875 if ($group_ids) {
876 $sql .= " AND t.rowid IN (".$this->db->sanitize($group_ids).")";
877 }
878 // Add sql filters
879 if ($sqlfilters) {
880 $errormessage = '';
881 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
882 if ($errormessage) {
883 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
884 }
885 }
886
887 $sql .= $this->db->order($sortfield, $sortorder);
888 if ($limit) {
889 if ($page < 0) {
890 $page = 0;
891 }
892 $offset = $limit * $page;
893
894 $sql .= $this->db->plimit($limit + 1, $offset);
895 }
896
897 $result = $this->db->query($sql);
898
899 if ($result) {
900 $i = 0;
901 $num = $this->db->num_rows($result);
902 $min = min($num, ($limit <= 0 ? $num : $limit));
903 while ($i < $min) {
904 $obj = $this->db->fetch_object($result);
905 $group_static = new UserGroup($this->db);
906 if ($group_static->fetch($obj->rowid)) {
907 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($group_static), $properties);
908 }
909 $i++;
910 }
911 } else {
912 throw new RestException(503, 'Error when retrieve Group list : '.$this->db->lasterror());
913 }
914
915 return $obj_ret;
916 }
917
936 public function infoGroups($group, $load_members = 0, $includepermissions = 0)
937 {
938 if ($group == 0) {
939 throw new RestException(400, 'No usergroup with id=0 can exist');
940 }
941
942 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) ||
943 getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight('user', 'group_advance', 'read') && empty(DolibarrApiAccess::$user->admin)) {
944 throw new RestException(403, "You are not allowed to read groups");
945 }
946
947 $group_static = new UserGroup($this->db);
948 $result = $group_static->fetch($group, '', (bool) $load_members);
949
950 if ($result < 1) {
951 throw new RestException(404, 'Usergroup not found');
952 }
953
954 if ($includepermissions) {
955 $group_static->loadRights();
956 }
957
958 if ($load_members > 0 && is_array($group_static->members) && count($group_static->members) > 0) {
959 foreach ($group_static->members as &$member) {
960 $member = $this->_cleanObjectDatas($member);
961 }
962 }
963
964 return $this->_cleanUserGroup($group_static);
965 }
966
980 public function delete($id)
981 {
982 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'supprimer') && empty(DolibarrApiAccess::$user->admin)) {
983 throw new RestException(403, 'Not allowed');
984 }
985 $result = $this->useraccount->fetch($id);
986 if (!$result) {
987 throw new RestException(404, 'User not found');
988 }
989
990 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
991 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
992 }
993
994 if ($this->useraccount->admin && empty(DolibarrApiAccess::$user->admin)) {
995 throw new RestException(403, 'Only admin users can delete admin users');
996 }
997 if ($this->useraccount->admin && empty($this->useraccount->entity) && !empty(DolibarrApiAccess::$user->entity)) {
998 throw new RestException(403, 'Only superadmin users can delete superadmin users');
999 }
1000
1001 $this->useraccount->oldcopy = clone $this->useraccount; // @phan-suppress-current-line PhanTypeMismatchProperty
1002
1003 if (!$this->useraccount->delete(DolibarrApiAccess::$user)) {
1004 throw new RestException(500);
1005 }
1006
1007 return array(
1008 'success' => array(
1009 'code' => 200,
1010 'message' => 'User deleted'
1011 )
1012 );
1013 }
1014
1030 public function deleteGroups($group)
1031 {
1032 if (!DolibarrApiAccess::$user->hasRight('user', 'group_advance', 'delete') && empty(DolibarrApiAccess::$user->admin)) {
1033 throw new RestException(403, 'Not allowed');
1034 }
1035
1036 $usergroup = new UserGroup($this->db);
1037
1038 $result = $usergroup->fetch($group);
1039 if ($result < 0) {
1040 throw new RestException(404, 'Usergroup not found');
1041 }
1042
1043 if (!$usergroup->delete(DolibarrApiAccess::$user)) {
1044 throw new RestException(500);
1045 }
1046
1047 return array(
1048 'success' => array(
1049 'code' => 200,
1050 'message' => 'Usergroup deleted'
1051 )
1052 );
1053 }
1054
1072 public function getUserNotification($id)
1073 {
1074 if (empty($id)) {
1075 throw new RestException(400, 'No user with id=0 can exist');
1076 }
1077 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) {
1078 throw new RestException(403);
1079 }
1081 throw new RestException(403, 'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
1082 }
1083
1088 $sql = "SELECT rowid as id, fk_action as event, fk_user, type, datec, tms";
1089 $sql .= " FROM ".MAIN_DB_PREFIX."notify_def";
1090 $sql .= " WHERE fk_user = ".((int) $id);
1091
1092 $result = $this->db->query($sql);
1093 if ($this->db->num_rows($result) == 0) {
1094 throw new RestException(404, 'Notification not found');
1095 }
1096
1097 $i = 0;
1098
1099 $notifications = array();
1100
1101 if ($result) {
1102 $num = $this->db->num_rows($result);
1103 //$min = min($num, ($limit <= 0 ? $num : $limit));
1104 $min = $num;
1105 while ($i < $min) {
1106 $obj = $this->db->fetch_object($result);
1107 $notifications[] = $obj;
1108 $i++;
1109 }
1110 } else {
1111 throw new RestException(404, 'No notifications found');
1112 }
1113
1114 $fields = array('id', 'fk_user', 'event', 'datec', 'tms', 'type');
1115
1116 $returnNotifications = array();
1117
1118 foreach ($notifications as $notification) {
1119 $object = array();
1120 foreach ($notification as $key => $value) {
1121 if (in_array($key, $fields)) {
1122 $object[$key] = $value;
1123 }
1124 }
1125 $returnNotifications[] = $object;
1126 }
1127
1128 // Too complex for phan ?: @phan-suppress-next-line PhanTypeMismatchReturn
1129 return $returnNotifications;
1130 }
1131
1148 public function createUserNotification($id, $request_data = null)
1149 {
1150 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer')) {
1151 throw new RestException(403, "User has no right to update users");
1152 }
1153 if ($this->useraccount->fetch($id) <= 0) {
1154 throw new RestException(404, 'Error creating User Notification, User doesn\'t exists');
1155 }
1156 $notification = new Notify($this->db);
1157
1158 $notification->fk_user = $id;
1159
1160 foreach ($request_data as $field => $value) {
1161 $notification->$field = $this->_checkValForAPI($field, $value, $notification);
1162 }
1163
1164 $event = $notification->event;
1165 if (!$event) {
1166 throw new RestException(500, 'Error creating User Notification, request_data missing event');
1167 }
1168 $fk_user = $notification->fk_user;
1169
1170 $exists_sql = "SELECT rowid, fk_action as event, fk_user, type, datec, tms as datem";
1171 $exists_sql .= " FROM ".MAIN_DB_PREFIX."notify_def";
1172 $exists_sql .= " WHERE fk_action = '".$this->db->escape((string) $event)."'";
1173 $exists_sql .= " AND fk_user = '".$this->db->escape((string) $fk_user)."'";
1174
1175 $exists_result = $this->db->query($exists_sql);
1176 if ($this->db->num_rows($exists_result) > 0) {
1177 throw new RestException(403, 'Notification already exists');
1178 }
1179
1180 if ($notification->create(DolibarrApiAccess::$user) < 0) {
1181 throw new RestException(500, 'Error creating User Notification');
1182 }
1183
1184 if ($notification->update(DolibarrApiAccess::$user) < 0) {
1185 throw new RestException(500, 'Error updating values');
1186 }
1187
1188 return $this->_cleanObjectDatas($notification);
1189 }
1190
1209 public function createUserNotificationByCode($id, $code, $request_data = null)
1210 {
1211 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer')) {
1212 throw new RestException(403, "User has no right to update users");
1213 }
1214 if ($this->useraccount->fetch($id) <= 0) {
1215 throw new RestException(404, 'Error creating User Notification, User doesn\'t exists');
1216 }
1217 $notification = new Notify($this->db);
1218 $notification->fk_user = $id;
1219
1220 $sql = "SELECT t.rowid as id FROM ".MAIN_DB_PREFIX."c_action_trigger as t";
1221 $sql .= " WHERE t.code = '".$this->db->escape($code)."'";
1222
1223 $result = $this->db->query($sql);
1224 if ($this->db->num_rows($result) == 0) {
1225 throw new RestException(404, 'Action Trigger code not found');
1226 }
1227
1228 $notification->event = $this->db->fetch_row($result)[0];
1229 foreach ($request_data as $field => $value) {
1230 if ($field === 'event') {
1231 throw new RestException(500, 'Error creating User Notification, request_data contains event key');
1232 }
1233 if ($field === 'fk_action') {
1234 throw new RestException(500, 'Error creating User Notification, request_data contains fk_action key');
1235 }
1236 $notification->$field = $this->_checkValForAPI($field, $value, $notification);
1237 }
1238
1239 $event = $notification->event;
1240 $fk_user = $notification->fk_user;
1241
1242 $exists_sql = "SELECT rowid, fk_action as event, fk_user, type, datec, tms as datem";
1243 $exists_sql .= " FROM ".MAIN_DB_PREFIX."notify_def";
1244 $exists_sql .= " WHERE fk_action = '".$this->db->escape((string) $event)."'";
1245 $exists_sql .= " AND fk_user = '".$this->db->escape((string) $fk_user)."'";
1246
1247 $exists_result = $this->db->query($exists_sql);
1248 if ($this->db->num_rows($exists_result) > 0) {
1249 throw new RestException(403, 'Notification already exists');
1250 }
1251
1252 if ($notification->create(DolibarrApiAccess::$user) < 0) {
1253 throw new RestException(500, 'Error creating User Notification, are request_data well formed?');
1254 }
1255
1256 if ($notification->update(DolibarrApiAccess::$user) < 0) {
1257 throw new RestException(500, 'Error updating values');
1258 }
1259
1260 return $this->_cleanObjectDatas($notification);
1261 }
1262
1277 public function deleteUserNotification($id, $notification_id)
1278 {
1279 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer')) {
1280 throw new RestException(403, "User has no right to update users");
1281 }
1282
1283 $notification = new Notify($this->db);
1284
1285 $notification->fetch($notification_id);
1286
1287 $fk_user = (int) $notification->fk_user;
1288
1289 if ($fk_user == $id) {
1290 return $notification->delete(DolibarrApiAccess::$user);
1291 } else {
1292 throw new RestException(403, "Not allowed due to bad consistency of input data");
1293 }
1294 }
1295
1313 public function updateUserNotification($id, $notification_id, $request_data = null)
1314 {
1315 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer')) {
1316 throw new RestException(403, "User has no right to update users");
1317 }
1318 if ($this->useraccount->fetch($id) <= 0) {
1319 throw new RestException(404, 'Error creating Notification, User doesn\'t exists');
1320 }
1321 $notification = new Notify($this->db);
1322
1323 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1324 $notification->fetch($notification_id, $id);
1325
1326 if ($notification->fk_user != $id) {
1327 throw new RestException(403, "Not allowed due to bad consistency of input data");
1328 }
1329
1330 foreach ($request_data as $field => $value) {
1331 $notification->$field = $this->_checkValForAPI($field, $value, $notification);
1332 }
1333
1334 if ($notification->update(DolibarrApiAccess::$user) < 0) {
1335 throw new RestException(500, 'Error updating values');
1336 }
1337
1338 return $this->_cleanObjectDatas($notification);
1339 }
1340
1341 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1351 protected function _cleanObjectDatas($object)
1352 {
1353 // phpcs:enable
1354 $object = parent::_cleanObjectDatas($object);
1355
1356 unset($object->default_values);
1357 unset($object->lastsearch_values);
1358 unset($object->lastsearch_values_tmp);
1359
1360 unset($object->total_ht);
1361 unset($object->total_tva);
1362 unset($object->total_localtax1);
1363 unset($object->total_localtax2);
1364 unset($object->total_ttc);
1365
1366 unset($object->label_incoterms);
1367 unset($object->location_incoterms);
1368
1369 unset($object->fk_delivery_address);
1370 unset($object->fk_incoterms);
1371 unset($object->all_permissions_are_loaded);
1372 unset($object->shipping_method_id);
1373 unset($object->nb_rights);
1374 unset($object->search_sid);
1375 unset($object->ldap_sid);
1376 unset($object->clicktodial_loaded);
1377
1378 unset($object->lines);
1379 unset($object->model_pdf);
1380
1381 // List of properties never returned by API, whatever are permissions
1382 unset($object->pass);
1383 unset($object->pass_indatabase);
1384 unset($object->pass_indatabase_crypted);
1385 unset($object->pass_temp);
1386 unset($object->api_key);
1387 unset($object->clicktodial_password);
1388 unset($object->openid);
1389
1390 $canreadsalary = ((isModEnabled('salaries') && DolibarrApiAccess::$user->hasRight('salaries', 'read')) || !isModEnabled('salaries'));
1391 if (!$canreadsalary) {
1392 unset($object->salary);
1393 unset($object->salaryextra);
1394 unset($object->thm);
1395 unset($object->tjm);
1396 }
1397
1398 return $object;
1399 }
1400
1401 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1408 private function _cleanUserGroup($object)
1409 {
1410 // phpcs:enable
1411 $object = parent::_cleanObjectDatas($object);
1412
1413 unset($object->actiontypecode);
1414 unset($object->all_permissions_are_loaded);
1415 unset($object->barcode_type_coder);
1416 unset($object->barcode_type);
1417 unset($object->canvas);
1418 unset($object->civility_code);
1419 unset($object->civility_id);
1420 unset($object->clicktodial_loaded);
1421 unset($object->cond_reglement_id);
1422 unset($object->cond_reglement_supplier_id);
1423 unset($object->contact_id);
1424 unset($object->contacts_ids_internal);
1425 unset($object->contacts_ids);
1426 unset($object->country_code);
1427 unset($object->country_id);
1428 unset($object->date_cloture);
1429 unset($object->date_creation);
1430 unset($object->date_modification);
1431 unset($object->date_validation);
1432 unset($object->default_values);
1433 unset($object->demand_reason_id);
1434 unset($object->deposit_percent);
1435 unset($object->extraparams);
1436 unset($object->firstname);
1437 unset($object->fk_account);
1438 unset($object->fk_delivery_address);
1439 unset($object->fk_incoterms);
1440 unset($object->fk_multicurrency);
1441 unset($object->fk_project);
1442 unset($object->fk_user_creat);
1443 unset($object->fk_user_modif);
1444 unset($object->globalgroup);
1445 unset($object->import_key);
1446 unset($object->last_main_doc);
1447 unset($object->lastname);
1448 unset($object->lastsearch_values_tmp);
1449 unset($object->lastsearch_values);
1450 unset($object->ldap_sid);
1451 unset($object->libelle_incoterms);
1452 unset($object->lines);
1453 unset($object->linkedObjectsIds);
1454 unset($object->location_incoterms);
1455 unset($object->members);
1456 unset($object->mode_reglement_id);
1457 unset($object->module);
1458 unset($object->multicurrency_code);
1459 unset($object->multicurrency_total_ht);
1460 unset($object->multicurrency_total_localtax1);
1461 unset($object->multicurrency_total_localtax2);
1462 unset($object->multicurrency_total_ttc);
1463 unset($object->multicurrency_total_tva);
1464 unset($object->multicurrency_tx);
1465 unset($object->nb_rights);
1466 unset($object->nb_users);
1467 unset($object->note_public);
1468 unset($object->origin_id);
1469 unset($object->origin_type);
1470 unset($object->product);
1471 unset($object->ref_ext);
1472 unset($object->ref);
1473 unset($object->region_id);
1474 unset($object->retained_warranty_fk_cond_reglement);
1475 unset($object->rights);
1476 unset($object->search_sid);
1477 unset($object->shipping_method_id);
1478 unset($object->shipping_method);
1479 unset($object->specimen);
1480 unset($object->state_id);
1481 unset($object->status);
1482 unset($object->statut);
1483 unset($object->total_ht);
1484 unset($object->total_localtax1);
1485 unset($object->total_localtax2);
1486 unset($object->total_ttc);
1487 unset($object->total_tva);
1488 unset($object->totalpaid_multicurrency);
1489 unset($object->totalpaid);
1490 unset($object->transport_mode_id);
1491 unset($object->TRIGGER_PREFIX);
1492 unset($object->user_closing_id);
1493 unset($object->user_creation_id);
1494 unset($object->user_modification_id);
1495 unset($object->user_validation_id);
1496 unset($object->user);
1497 unset($object->usergroup_entity);
1498 unset($object->warehouse_id);
1499
1500 return $object;
1501 }
1502
1509 private function _cleanUserGroupListDatas($objectList)
1510 {
1511 $cleanObjectList = array();
1512
1513 foreach ($objectList as $object) {
1514 $cleanObject = parent::_cleanObjectDatas($object);
1515
1516 unset($cleanObject->default_values);
1517 unset($cleanObject->lastsearch_values);
1518 unset($cleanObject->lastsearch_values_tmp);
1519
1520 unset($cleanObject->total_ht);
1521 unset($cleanObject->total_tva);
1522 unset($cleanObject->total_localtax1);
1523 unset($cleanObject->total_localtax2);
1524 unset($cleanObject->total_ttc);
1525
1526 unset($cleanObject->libelle_incoterms);
1527 unset($cleanObject->location_incoterms);
1528
1529 unset($cleanObject->fk_delivery_address);
1530 unset($cleanObject->fk_incoterms);
1531 unset($cleanObject->all_permissions_are_loaded);
1532 unset($cleanObject->shipping_method_id);
1533 unset($cleanObject->nb_rights);
1534 unset($cleanObject->search_sid);
1535 unset($cleanObject->ldap_sid);
1536 unset($cleanObject->clicktodial_loaded);
1537
1538 unset($cleanObject->datec);
1539 unset($cleanObject->tms);
1540 unset($cleanObject->members);
1541 unset($cleanObject->note);
1542 unset($cleanObject->note_private);
1543
1544 $cleanObjectList[] = $cleanObject;
1545 }
1546
1547 return $cleanObjectList;
1548 }
1549
1557 private function _validate($data) // @phpstan-ignore-line
1558 {
1559 $account = array();
1560 foreach (Users::$FIELDS as $field) {
1561 if (!isset($data[$field])) {
1562 throw new RestException(400, "$field field missing");
1563 }
1564 $account[$field] = $data[$field];
1565 }
1566 return $account;
1567 }
1568}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
Class for API REST v1.
Definition api.class.php:35
_checkValExtrafieldsForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
_filterObjectProperties($object, $properties)
Filter properties that will be returned on object.
_checkValForAPI($field, $value, $object)
Check and convert a string depending on its type/name.
static _checkAccessToResource($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $parenttableforentity='')
Check access by user to a given resource.
Class to manage the table of subscription to notifications.
Class to manage user groups.
Class to manage Dolibarr users.
put($id, $request_data=null)
Update a user.
listGroups($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $group_ids='0', $sqlfilters='', $properties='')
List groups of the current user (so user of API token)
index($sortfield="t.rowid", $sortorder='ASC', $limit=100, $page=0, $user_ids='0', $category=0, $sqlfilters='', $properties='')
List users.
deleteGroups($group)
Delete a usergroup.
_cleanObjectDatas($object)
Clean sensible object datas @phpstan-template T.
getInfo($includepermissions=0)
Get more properties of the current user (so user of API token).
_cleanUserGroupListDatas($objectList)
Clean sensible user group list datas.
updateUserNotification($id, $notification_id, $request_data=null)
Update a notification for a user.
setGroup($id, $group, $entity=1)
Add a user to a group.
setPassword($id, $send_password=false)
Update a user password.
postGroups($request_data=null)
Create user group.
deleteUserNotification($id, $notification_id)
Delete a notification attached to a user.
_validate($data)
Validate fields before create or update object.
infoGroups($group, $load_members=0, $includepermissions=0)
Get properties of a user group.
getByEmail($email, $includepermissions=0)
Get a user by email.
getGroups($id)
List the groups of a user.
putGroups($group, $request_data=null)
Update user group.
createUserNotificationByCode($id, $code, $request_data=null)
Create a notification for a user using action trigger code.
post($request_data=null)
Create a user.
createUserNotification($id, $request_data=null)
Create a notification for a user.
getByLogin($login, $includepermissions=0)
Get a user by login.
removeUserFromGroup($id, $group)
Remove user from group (only admin)
getUserNotification($id)
Get notifications for a user.
__construct()
Constructor.
_cleanUserGroup($object)
Clean sensible usergroup object datas.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
getDolGlobalString($key, $default='')
Return a 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.
isModEnabled($module)
Is Dolibarr module enabled.