dolibarr 25.0.0-alpha
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->errorsToString());
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->errorsToString());
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->errorsToString());
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->errorsToString());
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->errorsToString());
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 if (!DolibarrApi::_checkAccessToResource('user', $usergroup->id, 'usergroup&usergroup')) {
764 throw new RestException(403, 'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
765 }
766
767 foreach ($request_data as $field => $value) {
768 if ($field == 'id') {
769 throw new RestException(400, 'Updating with id field is forbidden');
770 }
771 if ($field === 'caller') {
772 // 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
773 $usergroup->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09');
774 continue;
775 }
776
777 if ($field == 'entity' && $value != $usergroup->entity) {
778 throw new RestException(403, 'Changing entity of a user using the APIs is not possible');
779 }
780
781 $usergroup->$field = $this->_checkValForAPI($field, $value, $usergroup);
782 }
783
784 // If there is no error, update() returns the number of affected
785 // rows so if the update is a no op, the return value is zezo.
786 if ($usergroup->update() >= 0) {
787 return $this->infoGroups($group);
788 } else {
789 throw new RestException(500, $usergroup->errorsToString());
790 }
791 }
792
808 public function removeUserFromGroup($id, $group)
809 {
810 global $conf;
811
812 if (!DolibarrApiAccess::$user->admin) {
813 throw new RestException(403, 'Only admin can remove users from groups');
814 }
815
816 $result = $this->useraccount->fetch($id);
817 if (!$result) {
818 throw new RestException(404, 'User not found');
819 }
820
821 // Same entity resolution as setGroup(): the action is done on the entity of the logged user, so an
822 // admin of one entity can not remove the group link of a user in another entity.
823 if (isModEnabled('multicompany') && getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE') && empty(DolibarrApiAccess::$user->entity)) {
824 $entity = $conf->entity;
825 } else {
826 $entity = (((int) DolibarrApiAccess::$user->entity) > 0 ? (int) DolibarrApiAccess::$user->entity : $conf->entity);
827 }
828
829 $result = $this->useraccount->removeFromGroup($group, $entity);
830 if (!($result > 0)) {
831 throw new RestException(500, $this->useraccount->error);
832 }
833
834 return [
835 'success' => true,
836 'message' => "User $id removed from group $group"
837 ];
838 }
839
864 public function listGroups($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $group_ids = '0', $sqlfilters = '', $properties = '')
865 {
866 $obj_ret = array();
867
868 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) ||
869 getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight('user', 'group_advance', 'read') && empty(DolibarrApiAccess::$user->admin)) {
870 throw new RestException(403, "You are not allowed to read groups");
871 }
872
873 // case of external user, $societe param is ignored and replaced by user's socid
874 //$socid = DolibarrApiAccess::$user->socid ?: $societe;
875
876 $sql = "SELECT t.rowid";
877 $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
878 $sql .= ' WHERE t.entity IN ('.getEntity('user').')';
879 if ($group_ids) {
880 $sql .= " AND t.rowid IN (".$this->db->sanitize($group_ids).")";
881 }
882 // Add sql filters
883 if ($sqlfilters) {
884 $errormessage = '';
885 $sql .= forgeSQLFromUniversalSearchCriteria($sqlfilters, $errormessage);
886 if ($errormessage) {
887 throw new RestException(400, 'Error when validating parameter sqlfilters -> '.$errormessage);
888 }
889 }
890
891 $sql .= $this->db->order($sortfield, $sortorder);
892 if ($limit) {
893 if ($page < 0) {
894 $page = 0;
895 }
896 $offset = $limit * $page;
897
898 $sql .= $this->db->plimit($limit + 1, $offset);
899 }
900
901 $result = $this->db->query($sql);
902
903 if ($result) {
904 $i = 0;
905 $num = $this->db->num_rows($result);
906 $min = min($num, ($limit <= 0 ? $num : $limit));
907 while ($i < $min) {
908 $obj = $this->db->fetch_object($result);
909 $group_static = new UserGroup($this->db);
910 if ($group_static->fetch($obj->rowid)) {
911 $obj_ret[] = $this->_filterObjectProperties($this->_cleanObjectDatas($group_static), $properties);
912 }
913 $i++;
914 }
915 } else {
916 throw new RestException(503, 'Error when retrieve Group list : '.$this->db->lasterror());
917 }
918
919 return $obj_ret;
920 }
921
940 public function infoGroups($group, $load_members = 0, $includepermissions = 0)
941 {
942 if ($group == 0) {
943 throw new RestException(400, 'No usergroup with id=0 can exist');
944 }
945
946 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) ||
947 getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !DolibarrApiAccess::$user->hasRight('user', 'group_advance', 'read') && empty(DolibarrApiAccess::$user->admin)) {
948 throw new RestException(403, "You are not allowed to read groups");
949 }
950
951 $group_static = new UserGroup($this->db);
952 $result = $group_static->fetch($group, '', (bool) $load_members);
953
954 if ($result < 1) {
955 throw new RestException(404, 'Usergroup not found');
956 }
957
958 if (!DolibarrApi::_checkAccessToResource('user', $group_static->id, 'usergroup&usergroup')) {
959 throw new RestException(403, 'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
960 }
961
962 if ($includepermissions) {
963 $group_static->loadRights();
964 }
965
966 if ($load_members > 0 && is_array($group_static->members) && count($group_static->members) > 0) {
967 foreach ($group_static->members as &$member) {
968 $member = $this->_cleanObjectDatas($member);
969 }
970 }
971
972 return $this->_cleanUserGroup($group_static);
973 }
974
988 public function delete($id)
989 {
990 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'supprimer') && empty(DolibarrApiAccess::$user->admin)) {
991 throw new RestException(403, 'Not allowed');
992 }
993 $result = $this->useraccount->fetch($id);
994 if (!$result) {
995 throw new RestException(404, 'User not found');
996 }
997
998 if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) {
999 throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
1000 }
1001
1002 if ($this->useraccount->admin && empty(DolibarrApiAccess::$user->admin)) {
1003 throw new RestException(403, 'Only admin users can delete admin users');
1004 }
1005 if ($this->useraccount->admin && empty($this->useraccount->entity) && !empty(DolibarrApiAccess::$user->entity)) {
1006 throw new RestException(403, 'Only superadmin users can delete superadmin users');
1007 }
1008
1009 $this->useraccount->oldcopy = clone $this->useraccount; // @phan-suppress-current-line PhanTypeMismatchProperty
1010
1011 if (!$this->useraccount->delete(DolibarrApiAccess::$user)) {
1012 throw new RestException(500);
1013 }
1014
1015 return array(
1016 'success' => array(
1017 'code' => 200,
1018 'message' => 'User deleted'
1019 )
1020 );
1021 }
1022
1038 public function deleteGroups($group)
1039 {
1040 if (!DolibarrApiAccess::$user->hasRight('user', 'group_advance', 'delete') && empty(DolibarrApiAccess::$user->admin)) {
1041 throw new RestException(403, 'Not allowed');
1042 }
1043
1044 $usergroup = new UserGroup($this->db);
1045
1046 $result = $usergroup->fetch($group);
1047 if ($result < 0) {
1048 throw new RestException(404, 'Usergroup not found');
1049 }
1050
1051 if (!DolibarrApi::_checkAccessToResource('user', $usergroup->id, 'usergroup&usergroup')) {
1052 throw new RestException(403, 'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
1053 }
1054
1055 if (!$usergroup->delete(DolibarrApiAccess::$user)) {
1056 throw new RestException(500);
1057 }
1058
1059 return array(
1060 'success' => array(
1061 'code' => 200,
1062 'message' => 'Usergroup deleted'
1063 )
1064 );
1065 }
1066
1084 public function getUserNotification($id)
1085 {
1086 if (empty($id)) {
1087 throw new RestException(400, 'No user with id=0 can exist');
1088 }
1089 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'lire') && empty(DolibarrApiAccess::$user->admin)) {
1090 throw new RestException(403);
1091 }
1093 throw new RestException(403, 'Access on this object not allowed for login '.DolibarrApiAccess::$user->login);
1094 }
1095
1100 $sql = "SELECT rowid as id, fk_action as event, fk_user, type, datec, tms";
1101 $sql .= " FROM ".MAIN_DB_PREFIX."notify_def";
1102 $sql .= " WHERE fk_user = ".((int) $id);
1103
1104 $result = $this->db->query($sql);
1105 if ($this->db->num_rows($result) == 0) {
1106 throw new RestException(404, 'Notification not found');
1107 }
1108
1109 $i = 0;
1110
1111 $notifications = array();
1112
1113 if ($result) {
1114 $num = $this->db->num_rows($result);
1115 //$min = min($num, ($limit <= 0 ? $num : $limit));
1116 $min = $num;
1117 while ($i < $min) {
1118 $obj = $this->db->fetch_object($result);
1119 $notifications[] = $obj;
1120 $i++;
1121 }
1122 } else {
1123 throw new RestException(404, 'No notifications found');
1124 }
1125
1126 $fields = array('id', 'fk_user', 'event', 'datec', 'tms', 'type');
1127
1128 $returnNotifications = array();
1129
1130 foreach ($notifications as $notification) {
1131 $object = array();
1132 foreach ($notification as $key => $value) {
1133 if (in_array($key, $fields)) {
1134 $object[$key] = $value;
1135 }
1136 }
1137 $returnNotifications[] = $object;
1138 }
1139
1140 // Too complex for phan ?: @phan-suppress-next-line PhanTypeMismatchReturn
1141 return $returnNotifications;
1142 }
1143
1160 public function createUserNotification($id, $request_data = null)
1161 {
1162 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer')) {
1163 throw new RestException(403, "User has no right to update users");
1164 }
1165 if ($this->useraccount->fetch($id) <= 0) {
1166 throw new RestException(404, 'Error creating User Notification, User doesn\'t exists');
1167 }
1168 $notification = new Notify($this->db);
1169
1170 $notification->fk_user = $id;
1171
1172 foreach ($request_data as $field => $value) {
1173 $notification->$field = $this->_checkValForAPI($field, $value, $notification);
1174 }
1175
1176 $event = $notification->event;
1177 if (!$event) {
1178 throw new RestException(500, 'Error creating User Notification, request_data missing event');
1179 }
1180 $fk_user = $notification->fk_user;
1181
1182 $exists_sql = "SELECT rowid, fk_action as event, fk_user, type, datec, tms as datem";
1183 $exists_sql .= " FROM ".MAIN_DB_PREFIX."notify_def";
1184 $exists_sql .= " WHERE fk_action = '".$this->db->escape((string) $event)."'";
1185 $exists_sql .= " AND fk_user = '".$this->db->escape((string) $fk_user)."'";
1186
1187 $exists_result = $this->db->query($exists_sql);
1188 if ($this->db->num_rows($exists_result) > 0) {
1189 throw new RestException(403, 'Notification already exists');
1190 }
1191
1192 if ($notification->create(DolibarrApiAccess::$user) < 0) {
1193 throw new RestException(500, 'Error creating User Notification');
1194 }
1195
1196 if ($notification->update(DolibarrApiAccess::$user) < 0) {
1197 throw new RestException(500, 'Error updating values');
1198 }
1199
1200 return $this->_cleanObjectDatas($notification);
1201 }
1202
1221 public function createUserNotificationByCode($id, $code, $request_data = null)
1222 {
1223 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer')) {
1224 throw new RestException(403, "User has no right to update users");
1225 }
1226 if ($this->useraccount->fetch($id) <= 0) {
1227 throw new RestException(404, 'Error creating User Notification, User doesn\'t exists');
1228 }
1229 $notification = new Notify($this->db);
1230 $notification->fk_user = $id;
1231
1232 $sql = "SELECT t.rowid as id FROM ".MAIN_DB_PREFIX."c_action_trigger as t";
1233 $sql .= " WHERE t.code = '".$this->db->escape($code)."'";
1234
1235 $result = $this->db->query($sql);
1236 if ($this->db->num_rows($result) == 0) {
1237 throw new RestException(404, 'Action Trigger code not found');
1238 }
1239
1240 $notification->event = $this->db->fetch_row($result)[0];
1241 foreach ($request_data as $field => $value) {
1242 if ($field === 'event') {
1243 throw new RestException(500, 'Error creating User Notification, request_data contains event key');
1244 }
1245 if ($field === 'fk_action') {
1246 throw new RestException(500, 'Error creating User Notification, request_data contains fk_action key');
1247 }
1248 $notification->$field = $this->_checkValForAPI($field, $value, $notification);
1249 }
1250
1251 $event = $notification->event;
1252 $fk_user = $notification->fk_user;
1253
1254 $exists_sql = "SELECT rowid, fk_action as event, fk_user, type, datec, tms as datem";
1255 $exists_sql .= " FROM ".MAIN_DB_PREFIX."notify_def";
1256 $exists_sql .= " WHERE fk_action = '".$this->db->escape((string) $event)."'";
1257 $exists_sql .= " AND fk_user = '".$this->db->escape((string) $fk_user)."'";
1258
1259 $exists_result = $this->db->query($exists_sql);
1260 if ($this->db->num_rows($exists_result) > 0) {
1261 throw new RestException(403, 'Notification already exists');
1262 }
1263
1264 if ($notification->create(DolibarrApiAccess::$user) < 0) {
1265 throw new RestException(500, 'Error creating User Notification, are request_data well formed?');
1266 }
1267
1268 if ($notification->update(DolibarrApiAccess::$user) < 0) {
1269 throw new RestException(500, 'Error updating values');
1270 }
1271
1272 return $this->_cleanObjectDatas($notification);
1273 }
1274
1289 public function deleteUserNotification($id, $notification_id)
1290 {
1291 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer')) {
1292 throw new RestException(403, "User has no right to update users");
1293 }
1294
1295 $notification = new Notify($this->db);
1296
1297 $notification->fetch($notification_id);
1298
1299 $fk_user = (int) $notification->fk_user;
1300
1301 if ($fk_user == $id) {
1302 return $notification->delete(DolibarrApiAccess::$user);
1303 } else {
1304 throw new RestException(403, "Not allowed due to bad consistency of input data");
1305 }
1306 }
1307
1325 public function updateUserNotification($id, $notification_id, $request_data = null)
1326 {
1327 if (!DolibarrApiAccess::$user->hasRight('user', 'user', 'creer')) {
1328 throw new RestException(403, "User has no right to update users");
1329 }
1330 if ($this->useraccount->fetch($id) <= 0) {
1331 throw new RestException(404, 'Error creating Notification, User doesn\'t exists');
1332 }
1333 $notification = new Notify($this->db);
1334
1335 // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1336 $notification->fetch($notification_id, $id);
1337
1338 if ($notification->fk_user != $id) {
1339 throw new RestException(403, "Not allowed due to bad consistency of input data");
1340 }
1341
1342 foreach ($request_data as $field => $value) {
1343 $notification->$field = $this->_checkValForAPI($field, $value, $notification);
1344 }
1345
1346 if ($notification->update(DolibarrApiAccess::$user) < 0) {
1347 throw new RestException(500, 'Error updating values');
1348 }
1349
1350 return $this->_cleanObjectDatas($notification);
1351 }
1352
1353 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1363 protected function _cleanObjectDatas($object)
1364 {
1365 // phpcs:enable
1366 $object = parent::_cleanObjectDatas($object);
1367
1368 unset($object->default_values);
1369 unset($object->lastsearch_values);
1370 unset($object->lastsearch_values_tmp);
1371
1372 unset($object->total_ht);
1373 unset($object->total_tva);
1374 unset($object->total_localtax1);
1375 unset($object->total_localtax2);
1376 unset($object->total_ttc);
1377
1378 unset($object->label_incoterms);
1379 unset($object->location_incoterms);
1380
1381 unset($object->fk_delivery_address);
1382 unset($object->fk_incoterms);
1383 unset($object->all_permissions_are_loaded);
1384 unset($object->shipping_method_id);
1385 unset($object->nb_rights);
1386 unset($object->search_sid);
1387 unset($object->ldap_sid);
1388 unset($object->clicktodial_loaded);
1389
1390 unset($object->lines);
1391 unset($object->model_pdf);
1392
1393 // List of properties never returned by API, whatever are permissions
1394 unset($object->pass);
1395 unset($object->pass_indatabase);
1396 unset($object->pass_indatabase_crypted);
1397 unset($object->pass_temp);
1398 unset($object->api_key);
1399 unset($object->clicktodial_password);
1400 unset($object->openid);
1401
1402 $canreadsalary = ((isModEnabled('salaries') && DolibarrApiAccess::$user->hasRight('salaries', 'read')) || !isModEnabled('salaries'));
1403 if (!$canreadsalary) {
1404 unset($object->salary);
1405 unset($object->salaryextra);
1406 unset($object->thm);
1407 unset($object->tjm);
1408 }
1409
1410 return $object;
1411 }
1412
1413 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore
1420 private function _cleanUserGroup($object)
1421 {
1422 // phpcs:enable
1423 $object = parent::_cleanObjectDatas($object);
1424
1425 unset($object->actiontypecode);
1426 unset($object->all_permissions_are_loaded);
1427 unset($object->barcode_type_coder);
1428 unset($object->barcode_type);
1429 unset($object->canvas);
1430 unset($object->civility_code);
1431 unset($object->civility_id);
1432 unset($object->clicktodial_loaded);
1433 unset($object->cond_reglement_id);
1434 unset($object->cond_reglement_supplier_id);
1435 unset($object->contact_id);
1436 unset($object->contacts_ids_internal);
1437 unset($object->contacts_ids);
1438 unset($object->country_code);
1439 unset($object->country_id);
1440 unset($object->date_cloture);
1441 unset($object->date_creation);
1442 unset($object->date_modification);
1443 unset($object->date_validation);
1444 unset($object->default_values);
1445 unset($object->demand_reason_id);
1446 unset($object->deposit_percent);
1447 unset($object->extraparams);
1448 unset($object->firstname);
1449 unset($object->fk_account);
1450 unset($object->fk_delivery_address);
1451 unset($object->fk_incoterms);
1452 unset($object->fk_multicurrency);
1453 unset($object->fk_project);
1454 unset($object->fk_user_creat);
1455 unset($object->fk_user_modif);
1456 unset($object->globalgroup);
1457 unset($object->import_key);
1458 unset($object->last_main_doc);
1459 unset($object->lastname);
1460 unset($object->lastsearch_values_tmp);
1461 unset($object->lastsearch_values);
1462 unset($object->ldap_sid);
1463 unset($object->libelle_incoterms);
1464 unset($object->lines);
1465 unset($object->linkedObjectsIds);
1466 unset($object->location_incoterms);
1467 unset($object->members);
1468 unset($object->mode_reglement_id);
1469 unset($object->module);
1470 unset($object->multicurrency_code);
1471 unset($object->multicurrency_total_ht);
1472 unset($object->multicurrency_total_localtax1);
1473 unset($object->multicurrency_total_localtax2);
1474 unset($object->multicurrency_total_ttc);
1475 unset($object->multicurrency_total_tva);
1476 unset($object->multicurrency_tx);
1477 unset($object->nb_rights);
1478 unset($object->nb_users);
1479 unset($object->note_public);
1480 unset($object->origin_id);
1481 unset($object->origin_type);
1482 unset($object->product);
1483 unset($object->ref_ext);
1484 unset($object->ref);
1485 unset($object->region_id);
1486 unset($object->retained_warranty_fk_cond_reglement);
1487 unset($object->rights);
1488 unset($object->search_sid);
1489 unset($object->shipping_method_id);
1490 unset($object->shipping_method);
1491 unset($object->specimen);
1492 unset($object->state_id);
1493 unset($object->status);
1494 unset($object->statut);
1495 unset($object->total_ht);
1496 unset($object->total_localtax1);
1497 unset($object->total_localtax2);
1498 unset($object->total_ttc);
1499 unset($object->total_tva);
1500 unset($object->totalpaid_multicurrency);
1501 unset($object->totalpaid);
1502 unset($object->transport_mode_id);
1503 unset($object->TRIGGER_PREFIX);
1504 unset($object->user_closing_id);
1505 unset($object->user_creation_id);
1506 unset($object->user_modification_id);
1507 unset($object->user_validation_id);
1508 unset($object->user);
1509 unset($object->usergroup_entity);
1510 unset($object->warehouse_id);
1511
1512 return $object;
1513 }
1514
1521 private function _cleanUserGroupListDatas($objectList)
1522 {
1523 $cleanObjectList = array();
1524
1525 foreach ($objectList as $object) {
1526 $cleanObject = parent::_cleanObjectDatas($object);
1527
1528 unset($cleanObject->default_values);
1529 unset($cleanObject->lastsearch_values);
1530 unset($cleanObject->lastsearch_values_tmp);
1531
1532 unset($cleanObject->total_ht);
1533 unset($cleanObject->total_tva);
1534 unset($cleanObject->total_localtax1);
1535 unset($cleanObject->total_localtax2);
1536 unset($cleanObject->total_ttc);
1537
1538 unset($cleanObject->libelle_incoterms);
1539 unset($cleanObject->location_incoterms);
1540
1541 unset($cleanObject->fk_delivery_address);
1542 unset($cleanObject->fk_incoterms);
1543 unset($cleanObject->all_permissions_are_loaded);
1544 unset($cleanObject->shipping_method_id);
1545 unset($cleanObject->nb_rights);
1546 unset($cleanObject->search_sid);
1547 unset($cleanObject->ldap_sid);
1548 unset($cleanObject->clicktodial_loaded);
1549
1550 unset($cleanObject->datec);
1551 unset($cleanObject->tms);
1552 unset($cleanObject->members);
1553 unset($cleanObject->note);
1554 unset($cleanObject->note_private);
1555
1556 $cleanObjectList[] = $cleanObject;
1557 }
1558
1559 return $cleanObjectList;
1560 }
1561
1569 private function _validate($data) // @phpstan-ignore-line
1570 {
1571 $account = array();
1572 foreach (Users::$FIELDS as $field) {
1573 if (!isset($data[$field])) {
1574 throw new RestException(400, "$field field missing");
1575 }
1576 $account[$field] = $data[$field];
1577 }
1578 return $account;
1579 }
1580}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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").
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.