40require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/commonpeople.class.php';
56 public $element =
'user';
61 public $table_element =
'user';
66 public $fk_element =
'fk_user';
71 public $picto =
'user';
110 public $civility_code;
135 public $email_oauth2;
140 public $personal_email;
145 public $socialnetworks;
160 public $office_phone;
175 public $personal_mobile;
200 public $pass_crypted;
205 public $pass_indatabase;
210 public $pass_indatabase_crypted;
254 public $fk_user_expense_validator;
259 public $fk_user_holiday_validator;
264 public $clicktodial_url;
269 public $clicktodial_login;
274 public $clicktodial_password;
279 public $clicktodial_poste;
284 public $clicktodial_loaded;
290 public $datelastpassvalidation;
294 public $datelastlogin;
298 public $datepreviouslogin;
302 public $flagdelsessionsbefore;
310 public $ippreviouslogin;
314 public $datestartvalidity;
318 public $dateendvalidity;
338 public $all_permissions_are_loaded;
348 public $user_group_list;
353 private $_tab_loaded = array();
363 public $default_values;
368 public $lastsearch_values_tmp;
372 public $lastsearch_values;
377 public $users = array();
385 private $cache_childids;
391 public $accountancy_code_user_general;
396 public $accountancy_code;
428 public $dateemployment;
432 public $dateemploymentend;
437 public $default_c_exp_tax_cat;
442 public $ref_employee;
447 public $national_registration_number;
452 public $default_range;
457 public $fk_warehouse;
462 public $fk_establishment;
467 public $label_establishment;
473 public $usergroup_entity;
475 public $fields = array(
476 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
477 'lastname' => array(
'type' =>
'varchar(50)',
'label' =>
'Lastname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 20,
'searchall' => 1),
478 'firstname' => array(
'type' =>
'varchar(50)',
'label' =>
'Firstname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 10,
'searchall' => 1),
479 'ref_employee' => array(
'type' =>
'varchar(50)',
'label' =>
'RefEmployee',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 30,
'searchall' => 1),
480 'national_registration_number' => array(
'type' =>
'varchar(50)',
'label' =>
'NationalRegistrationNumber',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 40,
'searchall' => 1)
483 const STATUS_DISABLED = 0;
484 const STATUS_ENABLED = 1;
495 $this->ismultientitymanaged = 1;
496 $this->isextrafieldmanaged = 1;
498 $this->clicktodial_loaded = 0;
501 $this->all_permissions_are_loaded = 0;
502 $this->nb_rights = 0;
510 $this->rights->user =
new stdClass();
511 $this->rights->user->user =
new stdClass();
512 $this->rights->user->self =
new stdClass();
513 $this->rights->user->user_advance =
new stdClass();
514 $this->rights->user->self_advance =
new stdClass();
515 $this->rights->user->group_advance =
new stdClass();
532 public function fetch($id = 0, $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'', $fk_socpeople = 0, $use_email_oauth2 = 0)
537 $login = trim($login);
540 $sql =
"SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.civility as civility_code, u.birth, u.job,";
541 $sql .=
" u.email, u.email_oauth2, u.personal_email,";
542 $sql .=
" u.socialnetworks,";
543 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
544 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
545 $sql .=
" u.admin, u.login, u.note_private, u.note_public,";
546 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.api_key,";
547 $sql .=
" u.fk_soc, u.fk_socpeople, u.fk_member, u.fk_user, u.ldap_sid, u.fk_user_expense_validator, u.fk_user_holiday_validator,";
548 $sql .=
" fk_user_creat as user_creation_id, fk_user_modif as user_modification_id,";
549 $sql .=
" u.statut as status, u.lang, u.entity,";
550 $sql .=
" u.datec as datec,";
551 $sql .=
" GREATEST(u.tms, COALESCE(uef.tms, u.tms)) as datem,";
552 $sql .=
" u.datelastlogin as datel,";
553 $sql .=
" u.datepreviouslogin as datep,";
554 $sql .=
" u.flagdelsessionsbefore,";
555 $sql .=
" u.iplastlogin,";
556 $sql .=
" u.ippreviouslogin,";
557 $sql .=
" u.datelastpassvalidation,";
558 $sql .=
" u.datestartvalidity,";
559 $sql .=
" u.dateendvalidity,";
560 $sql .=
" u.photo as photo,";
561 $sql .=
" u.openid as openid,";
562 $sql .=
" u.accountancy_code_user_general,";
563 $sql .=
" u.accountancy_code,";
566 $sql .=
" u.salary,";
567 $sql .=
" u.salaryextra,";
568 $sql .=
" u.weeklyhours,";
570 $sql .=
" u.dateemployment, u.dateemploymentend,";
571 $sql .=
" u.fk_warehouse,";
572 $sql .=
" u.ref_ext,";
573 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
574 $sql .=
" u.national_registration_number,";
575 $sql .=
" u.ref_employee,";
576 $sql .=
" c.code as country_code, c.label as country,";
577 $sql .=
" d.code_departement as state_code, d.nom as state,";
578 $sql .=
" s.label as label_establishment, u.fk_establishment";
579 $sql .=
" FROM ".$this->db->prefix().
"user as u";
580 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user_extrafields as uef ON uef.fk_object = u.rowid";
581 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as c ON u.fk_country = c.rowid";
582 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_departements as d ON u.fk_state = d.rowid";
583 $sql .=
" LEFT JOIN ".$this->db->prefix().
"establishment as s ON u.fk_establishment = s.rowid";
586 $sql .=
" WHERE u.rowid = ".((int) $id);
590 $sql .=
" WHERE u.entity IN (0, " . ((int) $conf->entity) .
")";
592 $sql .=
" WHERE u.entity IS NOT NULL";
597 $sql .=
" WHERE u.entity IS NOT NULL";
599 if ($entity !=
'' && $entity == 0) {
600 $sql .=
" WHERE u.entity = 0";
602 $sql .=
" WHERE u.entity IN (0, " . ((int) ($entity > 0 ? $entity : $conf->entity)) .
")";
610 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->db->escape($login).
"')";
612 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
614 $sql .=
" AND (u.email = '".$this->db->escape($email).
"'";
615 if ($use_email_oauth2) {
616 $sql .=
" OR u.email_oauth2 = '".$this->db->escape($email).
"'";
619 } elseif ($fk_socpeople > 0) {
620 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
623 $sql .=
" ORDER BY u.entity ASC";
627 $sql .=
' '.$this->db->plimit(1);
630 $resql = $this->db->query($sql);
632 $num = $this->db->num_rows($resql);
634 $this->
error =
"USERDUPLICATEFOUND";
635 dol_syslog(get_class($this).
"::fetch more than 1 user found", LOG_WARNING);
637 $this->db->free($resql);
641 $obj = $this->db->fetch_object($resql);
643 $this->
id = $obj->rowid;
644 $this->
ref = $obj->rowid;
646 $this->ref_ext = $obj->ref_ext;
648 $this->ldap_sid = $obj->ldap_sid;
649 $this->civility_code = $obj->civility_code;
650 $this->lastname = $obj->lastname;
651 $this->firstname = $obj->firstname;
652 $this->ref_employee = $obj->ref_employee;
653 $this->national_registration_number = $obj->national_registration_number;
655 $this->employee = $obj->employee;
657 $this->login = $obj->login;
658 $this->gender = $obj->gender;
659 $this->birth = $this->db->jdate($obj->birth);
660 $this->pass_indatabase = $obj->pass;
661 $this->pass_indatabase_crypted = $obj->pass_crypted;
662 $this->pass = $obj->pass;
663 $this->pass_temp = $obj->pass_temp;
664 $this->datelastpassvalidation = $this->db->jdate($obj->datelastpassvalidation);
667 $this->
address = $obj->address;
668 $this->zip = $obj->zip;
669 $this->town = $obj->town;
671 $this->country_id = $obj->country_id;
672 $this->country_code = $obj->country_id ? $obj->country_code :
'';
675 $this->state_id = $obj->state_id;
676 $this->state_code = $obj->state_code;
677 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
679 $this->office_phone = $obj->office_phone;
680 $this->office_fax = $obj->office_fax;
681 $this->user_mobile = $obj->user_mobile;
682 $this->personal_mobile = $obj->personal_mobile;
683 $this->
email = $obj->email;
684 $this->email_oauth2 = $obj->email_oauth2;
685 $this->personal_email = $obj->personal_email;
686 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
687 $this->user_creation_id = $obj->user_creation_id;
688 $this->user_modification_id = $obj->user_modification_id;
690 $this->job = $obj->job;
691 $this->signature = $obj->signature;
692 $this->admin = $obj->admin;
693 $this->note_public = $obj->note_public;
694 $this->note_private = $obj->note_private;
696 $this->statut = $obj->status;
697 $this->
status = $obj->status;
699 $this->photo = $obj->photo;
700 $this->openid = $obj->openid;
701 $this->lang = $obj->lang;
702 $this->entity = $obj->entity;
704 $this->accountancy_code_user_general = $obj->accountancy_code_user_general;
705 $this->accountancy_code = $obj->accountancy_code;
707 $this->thm = $obj->thm;
708 $this->tjm = $obj->tjm;
709 $this->salary = $obj->salary;
710 $this->salaryextra = $obj->salaryextra;
711 $this->weeklyhours = $obj->weeklyhours;
712 $this->color = $obj->color;
713 $this->dateemployment = $this->db->jdate($obj->dateemployment);
714 $this->dateemploymentend = $this->db->jdate($obj->dateemploymentend);
716 $this->datec = $this->db->jdate($obj->datec);
717 $this->datem = $this->db->jdate($obj->datem);
718 $this->datelastlogin = $this->db->jdate($obj->datel);
719 $this->datepreviouslogin = $this->db->jdate($obj->datep);
720 $this->flagdelsessionsbefore = $this->db->jdate($obj->flagdelsessionsbefore,
'gmt');
721 $this->iplastlogin = $obj->iplastlogin;
722 $this->ippreviouslogin = $obj->ippreviouslogin;
723 $this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
724 $this->dateendvalidity = $this->db->jdate($obj->dateendvalidity);
726 $this->socid = $obj->fk_soc;
727 $this->contact_id = $obj->fk_socpeople;
728 $this->fk_member = $obj->fk_member;
729 $this->fk_user = $obj->fk_user;
730 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
731 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
733 $this->default_range = $obj->default_range;
734 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
735 $this->fk_warehouse = $obj->fk_warehouse;
736 $this->fk_establishment = $obj->fk_establishment;
737 $this->label_establishment = $obj->label_establishment;
741 if (!
isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
749 $this->db->free($resql);
751 $this->
error =
"USERNOTFOUND";
752 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
754 $this->db->free($resql);
758 $this->
error = $this->db->lasterror();
763 if ($loadpersonalconf) {
769 $this->
error = $this->db->lasterror();
776 if (
GETPOSTINT(
'forceexternaluser') && $this->admin && empty($this->socid)) {
777 $this->socid =
GETPOSTINT(
'forceexternaluser');
795 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
796 $sql .=
" WHERE fk_user = ".((int) $this->
id);
798 $sql .=
" AND entity IN (0, ".((int) $conf->entity).
")";
800 $sql .=
" AND entity = ".((int) $entity);
804 $resql = $this->db->query($sql);
806 $num = $this->db->num_rows($resql);
809 $obj = $this->db->fetch_object($resql);
810 $p = (!empty($obj->param) ? $obj->param :
'');
812 $this->
conf->$p = $obj->value;
816 $this->db->free($resql);
820 $this->
error = $this->db->lasterror();
837 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
840 $result = $defaultValues->fetchAll(
'',
'', 0, 0,
'(t.user_id:in:0,'.$this->
id.
') AND (entity:in:'.(isset($this->entity) ? $this->entity : $conf->entity).
','.$conf->entity.
')');
843 if (!is_array($result) && $result < 0) {
847 } elseif (count($result) > 0) {
848 foreach ($result as $defval) {
849 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
850 $pagewithoutquerystring = $defval->page;
853 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
854 $pagewithoutquerystring = $reg[1];
855 $pagequeries = $reg[2];
857 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
861 if (!empty($this->default_values)) {
862 foreach ($this->default_values as $a => $b) {
863 foreach ($b as
$c => $d) {
864 krsort($this->default_values[$a][
$c]);
895 public function hasRight($module, $permlevel1, $permlevel2 =
'')
898 $moduletomoduletouse = array(
899 'category' =>
'categorie',
900 'compta' =>
'comptabilite',
901 'contract' =>
'contrat',
902 'member' =>
'adherent',
904 'order' =>
'commande',
905 'produit' =>
'product',
906 'productlot' =>
'product',
907 'project' =>
'projet',
908 'propale' =>
'propal',
909 'shipping' =>
'expedition',
910 'task' =>
'task@projet',
911 'fichinter' =>
'ficheinter',
912 'inventory' =>
'stock',
913 'invoice' =>
'facture',
914 'invoice_supplier' =>
'fournisseur',
915 'order_supplier' =>
'fournisseur',
916 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
917 'skill@hrm' =>
'all@hrm',
918 'job@hrm' =>
'all@hrm',
919 'position@hrm' =>
'all@hrm',
920 'facturerec' =>
'facture',
921 'margins' =>
'margin',
924 if (!empty($moduletomoduletouse[$module])) {
925 $module = $moduletomoduletouse[$module];
928 $moduleRightsMapping = array(
929 'product' =>
'produit',
930 'margin' =>
'margins',
931 'comptabilite' =>
'compta'
934 $rightsPath = $module;
935 if (!empty($moduleRightsMapping[$rightsPath])) {
936 $rightsPath = $moduleRightsMapping[$rightsPath];
940 $tmp = explode(
'@', $rightsPath, 2);
941 if (!empty($tmp[1])) {
942 if (strpos($module,
'@') !==
false) {
945 if ($tmp[0] != $tmp[1]) {
947 $rightsPath = $tmp[1];
948 $permlevel2 = $permlevel1;
949 $permlevel1 = $tmp[0];
952 $rightsPath = $tmp[1];
967 if (!empty($this->socid)) {
968 if ($module ==
'societe' && ($permlevel1 ==
'creer' || $permlevel1 ==
'write')) {
971 if ($module ==
'societe' && $permlevel1 ==
'client' && $permlevel2 ==
'voir') {
974 if ($module ==
'societe' && $permlevel1 ==
'export') {
977 if ($module ==
'societe' && ($permlevel1 ==
'supprimer' || $permlevel1 ==
'delete')) {
983 if ($permlevel1 ==
'propale') {
984 $permlevel1 =
'propal';
986 if ($permlevel1 ==
'member') {
987 $permlevel1 =
'adherent';
989 if ($permlevel1 ==
'recruitmentcandidature') {
990 $permlevel1 =
'recruitmentjobposition';
995 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
1000 if (!empty($this->rights->$rightsPath->$permlevel1)) {
1001 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
1002 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
1006 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
1007 return $this->rights->$rightsPath->$permlevel1->lire;
1009 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
1010 return $this->rights->$rightsPath->$permlevel1->creer;
1012 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
1013 return $this->rights->$rightsPath->$permlevel1->create;
1015 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
1016 return $this->rights->$rightsPath->$permlevel1->supprimer;
1020 if (!empty($this->rights->$rightsPath->$permlevel1)) {
1021 return $this->rights->$rightsPath->$permlevel1;
1025 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
1026 return $this->rights->$rightsPath->lire;
1028 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
1029 return $this->rights->$rightsPath->creer;
1031 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
1032 return $this->rights->$rightsPath->create;
1034 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
1035 return $this->rights->$rightsPath->supprimer;
1053 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1055 global $conf, $user, $langs;
1057 $entity = (empty($entity) ? $conf->entity : $entity);
1059 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
1061 if (empty($this->
id)) {
1062 $this->
error =
'Try to call addrights on an object user with an empty id';
1072 $module = $perms = $subperms =
'';
1075 $sql =
"SELECT module, perms, subperms";
1076 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1077 $sql .=
" WHERE id = ".((int) $rid);
1078 $sql .=
" AND entity = ".((int) $entity);
1080 $result = $this->db->query($sql);
1082 $obj = $this->db->fetch_object($result);
1085 $module = $obj->module;
1086 $perms = $obj->perms;
1087 $subperms = $obj->subperms;
1095 $whereforadd =
"id=".((int) $rid);
1097 if (!empty($subperms)) {
1098 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
1099 } elseif (!empty($perms)) {
1100 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND (subperms IS NULL or subperms = ''))";
1106 if (!empty($allmodule)) {
1107 if ($allmodule ==
'allmodules') {
1108 $whereforadd =
'allmodules';
1110 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
1111 if (!empty($allperms)) {
1112 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
1120 if (!empty($whereforadd)) {
1123 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1124 $sql .=
" WHERE entity = ".((int) $entity);
1125 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
1126 $sql .=
" AND (".$whereforadd.
")";
1129 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1130 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1132 $sqldelete .=
") AND entity = ".((int) $entity);
1133 if (!$this->db->query($sqldelete)) {
1138 $resql = $this->db->query($sql);
1140 $num = $this->db->num_rows($resql);
1143 $obj = $this->db->fetch_object($resql);
1148 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
1149 if (!$this->db->query($sql)) {
1163 if (!$error && !$notrigger) {
1164 $langs->load(
"other");
1165 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
1168 $result = $this->call_trigger(
'USER_MODIFY', $user);
1176 $this->db->rollback();
1179 $this->db->commit();
1196 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1198 global $conf, $user, $langs;
1202 $entity = (!empty($entity) ? $entity : $conf->entity);
1207 $module = $perms = $subperms =
'';
1211 $sql =
"SELECT module, perms, subperms";
1212 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1213 $sql .=
" WHERE id = '".((int) $rid).
"'";
1214 $sql .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1216 $result = $this->db->query($sql);
1218 $obj = $this->db->fetch_object($result);
1221 $module = $obj->module;
1222 $perms = $obj->perms;
1223 $subperms = $obj->subperms;
1231 $wherefordel =
"id=".((int) $rid);
1233 if ($subperms ==
'lire' || $subperms ==
'read') {
1234 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1236 if ($perms ==
'lire' || $perms ==
'read') {
1237 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1243 if (!empty($allmodule)) {
1244 if ($allmodule ==
'allmodules') {
1245 $wherefordel =
'allmodules';
1247 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1248 if (!empty($allperms)) {
1249 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1256 if (!empty($wherefordel)) {
1259 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1260 $sql .=
" WHERE entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1261 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1262 $sql .=
" AND (".$wherefordel.
")";
1266 if ($this->admin == 1) {
1267 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1268 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1269 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1270 $sql .=
" AND id NOT IN (358)";
1273 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1274 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1277 $sqldelete .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1279 $resql = $this->db->query($sqldelete);
1286 if (!$error && !$notrigger) {
1287 $langs->load(
"other");
1288 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1291 $result = $this->call_trigger(
'USER_MODIFY', $user);
1299 $this->db->rollback();
1302 $this->db->commit();
1316 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1318 $this->nb_rights = 0;
1319 $this->all_permissions_are_loaded = 0;
1320 $this->_tab_loaded = array();
1336 $alreadyloaded =
false;
1338 if (empty($forcereload)) {
1339 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1341 $alreadyloaded =
true;
1344 if (!empty($this->all_permissions_are_loaded)) {
1346 $alreadyloaded =
true;
1351 if (!isset($this->rights) || !is_object($this->rights)) {
1354 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1355 $this->rights->user =
new stdClass();
1360 if (!$alreadyloaded) {
1362 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1363 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1364 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1365 $sql .=
" WHERE r.id = ur.fk_id";
1371 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') ?
"1," :
"").$conf->entity.
")";
1375 $sql .=
" AND r.entity = ".((int) $conf->entity).
" AND ur.entity = ".((int) $conf->entity);
1377 $sql .=
" AND ur.fk_user = ".((int) $this->
id);
1378 $sql .=
" AND r.perms IS NOT NULL";
1380 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1383 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1386 $resql = $this->db->query($sql);
1388 $num = $this->db->num_rows($resql);
1391 $obj = $this->db->fetch_object($resql);
1394 $module = $obj->module;
1395 $perms = $obj->perms;
1396 $subperms = $obj->subperms;
1398 if (!empty($perms)) {
1399 if (!empty($module)) {
1400 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1401 $this->rights->$module =
new stdClass();
1403 if (!empty($subperms)) {
1404 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1405 $this->rights->$module->$perms =
new stdClass();
1407 if (empty($this->rights->$module->$perms->$subperms)) {
1410 $this->rights->$module->$perms->$subperms = 1;
1412 if (empty($this->rights->$module->$perms)) {
1415 $this->rights->$module->$perms = 1;
1422 $this->db->free($resql);
1426 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms, r.entity";
1427 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1428 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1429 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1430 $sql .=
" WHERE r.id = gr.fk_id";
1436 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1438 $sql .=
" AND r.entity = ".((int) $conf->entity);
1441 $sql .=
" AND gr.entity = ".((int) $conf->entity);
1445 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1446 $sql .=
" AND r.entity = ".((int) $conf->entity);
1449 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1450 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1451 $sql .=
" AND r.perms IS NOT NULL";
1453 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1456 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1459 $resql = $this->db->query($sql);
1461 $num = $this->db->num_rows($resql);
1464 $obj = $this->db->fetch_object($resql);
1467 $module = $obj->module;
1468 $perms = $obj->perms;
1469 $subperms = $obj->subperms;
1471 if (!empty($perms)) {
1472 if (!empty($module)) {
1473 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1474 $this->rights->$module =
new stdClass();
1476 if (!empty($subperms)) {
1477 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1478 $this->rights->$module->$perms =
new stdClass();
1480 if (empty($this->rights->$module->$perms->$subperms)) {
1483 $this->rights->$module->$perms->$subperms = 1;
1486 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1487 if (empty($this->rights->$module->$perms)) {
1490 $this->rights->$module->$perms = 1;
1498 $this->db->free($resql);
1502 if (!empty($this->admin)) {
1503 if (empty($this->rights->user->user)) {
1504 $this->rights->user->user =
new stdClass();
1506 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1507 foreach ($listofpermtotest as $permtotest) {
1508 if (empty($this->rights->user->user->$permtotest)) {
1509 $this->rights->user->user->$permtotest = 1;
1513 if (empty($this->rights->user->self)) {
1514 $this->rights->user->self =
new stdClass();
1516 $listofpermtotest = array(
'creer',
'password');
1517 foreach ($listofpermtotest as $permtotest) {
1518 if (empty($this->rights->user->self->$permtotest)) {
1519 $this->rights->user->self->$permtotest = 1;
1525 if (empty($this->rights->user->user_advance)) {
1526 $this->rights->user->user_advance =
new stdClass();
1528 $listofpermtotest = array(
'readperms',
'write');
1529 foreach ($listofpermtotest as $permtotest) {
1530 if (empty($this->rights->user->user_advance->$permtotest)) {
1531 $this->rights->user->user_advance->$permtotest = 1;
1535 if (empty($this->rights->user->self_advance)) {
1536 $this->rights->user->self_advance =
new stdClass();
1538 $listofpermtotest = array(
'readperms',
'writeperms');
1539 foreach ($listofpermtotest as $permtotest) {
1540 if (empty($this->rights->user->self_advance->$permtotest)) {
1541 $this->rights->user->self_advance->$permtotest = 1;
1545 if (empty($this->rights->user->group_advance)) {
1546 $this->rights->user->group_advance =
new stdClass();
1548 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1549 foreach ($listofpermtotest as $permtotest) {
1550 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1551 $this->rights->user->group_advance->$permtotest = 1;
1559 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1560 $this->rights->propal = $this->rights->propale;
1562 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1563 $this->rights->propale = $this->rights->propal;
1570 $this->all_permissions_are_loaded = 1;
1573 $this->_tab_loaded[$moduletag] = 1;
1590 public function getrights($moduletag =
'', $forcereload = 0)
1603 global $conf, $langs, $user;
1608 if (isset($this->statut)) {
1609 if ($this->statut == $status) {
1612 } elseif (isset($this->
status) && $this->
status == $status) {
1619 $sql =
"UPDATE ".$this->db->prefix().
"user";
1620 $sql .=
" SET statut = ".((int) $status);
1621 $sql .=
" WHERE rowid = ".((int) $this->
id);
1622 $result = $this->db->query($sql);
1624 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1627 $this->context[
'actionmsg'] =
'User '.$this->login.
' disabled';
1629 $this->context[
'actionmsg'] =
'User '.$this->login.
' enabled';
1632 $result = $this->call_trigger(
'USER_ENABLEDISABLE', $user);
1640 $this->db->rollback();
1644 $this->statut = $status;
1645 $this->db->commit();
1662 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1663 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1678 $this->
fetch($this->
id);
1680 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1687 'hrm_evaluation' => array(
'label' =>
'EvaluationCard',
'filter' =>
"fk_user = ".((
int) $this->
id)),
1688 'hrm_job_user' => array(
'label' =>
'EmployeePosition',
'filter' =>
"fk_user = ".((
int) $this->
id)),
1689 'hrm_skillrank' => array(
'label' =>
'Skill',
'filter' =>
"objecttype = 'user' AND fk_object = ".((
int) $this->
id)),
1691 foreach ($hrmtables as $hrmtable => $hrminfo) {
1692 $sanitizedfilter = $hrminfo[
'filter'];
1693 $sql =
"SELECT COUNT(rowid) as nb FROM ".$this->db->prefix().$this->db->sanitize($hrmtable).
" WHERE ".$sanitizedfilter;
1694 $resql = $this->db->query($sql);
1696 $obj = $this->db->fetch_object($resql);
1697 if ($obj && $obj->nb > 0) {
1698 $langs->loadLangs(array(
'errors',
'hrm'));
1699 $this->
error = $langs->trans(
"ErrorRecordHasAtLeastOneChildOfType", $this->login, $langs->transnoentitiesnoconv($hrminfo[
'label']));
1700 $this->errors[] = $this->error;
1701 $this->db->rollback();
1709 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1711 if (!$error && !$this->db->query($sql)) {
1713 $this->
error = $this->db->lasterror();
1717 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1718 if (!$error && !$this->db->query($sql)) {
1720 $this->
error = $this->db->lasterror();
1724 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1725 if (!$error && !$this->db->query($sql)) {
1727 $this->
error = $this->db->lasterror();
1731 $sql =
"DELETE FROM ".$this->db->prefix().
"bookmark WHERE fk_user = ".((int) $this->
id);
1732 if (!$error && !$this->db->query($sql)) {
1734 $this->
error = $this->db->lasterror();
1738 if ($this->contact_id > 0) {
1739 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1740 if (!$error && !$this->db->query($sql)) {
1742 $this->
error = $this->db->lasterror();
1751 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1757 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1758 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1759 if (!$this->db->query($sql)) {
1761 $this->
error = $this->db->lasterror();
1767 $result = $this->call_trigger(
'USER_DELETE', $user);
1770 $this->db->rollback();
1775 $this->db->commit();
1778 $this->db->rollback();
1790 public function create($user, $notrigger = 0)
1792 global $conf, $langs;
1798 $this->civility_code = trim((
string) $this->civility_code);
1799 $this->login = trim((
string) $this->login);
1800 $this->user_creation_id = (int) $user->id;
1801 if (!isset($this->entity)) {
1802 $this->entity = $conf->entity;
1804 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1806 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1810 $langs->load(
"errors");
1811 $this->
error = $langs->trans(
"ErrorBadEMail", $this->
email);
1814 if (empty($this->login)) {
1815 $langs->load(
"errors");
1816 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1818 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1819 $langs->load(
"errors");
1820 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1831 $sqltochecklogin =
"SELECT COUNT(*) as nb FROM ".$this->db->prefix().
"user WHERE entity IN (".$this->db->sanitize(((
int) $this->entity).
", 0").
") AND login = '".$this->db->escape($this->login).
"'";
1832 $resqltochecklogin = $this->db->query($sqltochecklogin);
1833 if ($resqltochecklogin) {
1834 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1835 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1836 $langs->load(
"errors");
1837 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1839 $this->db->rollback();
1842 $this->db->free($resqltochecklogin);
1845 if (!empty($this->
email)) {
1846 $sqltochecklogin =
"SELECT COUNT(*) as nb FROM ".$this->db->prefix().
"user WHERE entity IN (".$this->db->sanitize(((
int) $this->entity).
", 0").
") AND email = '".$this->db->escape($this->
email).
"'";
1847 $resqltochecklogin = $this->db->query($sqltochecklogin);
1848 if ($resqltochecklogin) {
1849 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1850 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1851 $langs->load(
"errors");
1852 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->
email);
1854 $this->db->rollback();
1857 $this->db->free($resqltochecklogin);
1862 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, fk_user_creat, entity)";
1863 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->db->escape($this->login).
"', '".$this->db->escape($this->ldap_sid).
"', ".(int) $this->user_creation_id.
", ".((
int) $this->entity).
")";
1864 $result = $this->db->query($sql);
1866 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1868 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1872 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1873 $this->db->rollback();
1878 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1879 $langs->load(
"stocks");
1881 $entrepot =
new Entrepot($this->db);
1882 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1883 $entrepot->libelle = $entrepot->label;
1884 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1885 $entrepot->statut = 1;
1886 $entrepot->country_id =
$mysoc->country_id;
1888 $warehouseid = $entrepot->create($user);
1890 $this->fk_warehouse = $warehouseid;
1894 $result = $this->
update($user, 1, 1);
1896 $this->db->rollback();
1902 $result = $this->call_trigger(
'USER_CREATE', $user);
1910 $this->db->commit();
1915 $this->db->rollback();
1919 $this->
error = $this->db->lasterror();
1920 $this->db->rollback();
1944 $this->civility_code = $contact->civility_code;
1945 $this->lastname = $contact->lastname;
1946 $this->firstname = $contact->firstname;
1948 $this->
email = $contact->email;
1949 $this->socialnetworks = $contact->socialnetworks;
1950 $this->office_phone = $contact->phone_pro;
1951 $this->office_fax = $contact->fax;
1952 $this->user_mobile = $contact->phone_mobile;
1953 $this->
address = $contact->address;
1954 $this->zip = $contact->zip;
1955 $this->town = $contact->town;
1957 $this->state_id = $contact->state_id;
1958 $this->country_id = $contact->country_id;
1959 $this->employee = 0;
1961 if (empty($login)) {
1962 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1963 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1965 $this->login = $login;
1970 $result = $this->
create($user, 1);
1972 $sql =
"UPDATE ".$this->db->prefix().
"user";
1973 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1974 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1975 if ($contact->socid > 0) {
1976 $sql .=
", fk_soc=".((int) $contact->socid);
1978 $sql .=
" WHERE rowid=".((int) $this->
id);
1980 $resql = $this->db->query($sql);
1982 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1984 $this->context[
'createfromcontact'] =
'createfromcontact';
1987 $result = $this->call_trigger(
'USER_CREATE', $user);
1990 $this->db->rollback();
1995 $this->db->commit();
1998 $this->
error = $this->db->error();
2000 $this->db->rollback();
2005 dol_syslog(get_class($this).
"::create_from_contact - 0");
2007 $this->db->rollback();
2028 $this->civility_code = $member->civility_code;
2029 $this->lastname = $member->lastname;
2030 $this->firstname = $member->firstname;
2031 $this->gender = $member->gender;
2032 $this->
email = $member->email;
2033 $this->fk_member = $member->id;
2034 $this->
address = $member->address;
2035 $this->zip = $member->zip;
2036 $this->town = $member->town;
2038 $this->state_id = $member->state_id;
2039 $this->country_id = $member->country_id;
2040 $this->socialnetworks = $member->socialnetworks;
2042 $this->pass = $member->pass;
2043 $this->pass_crypted = $member->pass_indatabase_crypted;
2045 if (empty($login)) {
2046 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
2049 $this->login = $login;
2054 $result = $this->
create($user);
2056 if (!empty($this->pass)) {
2057 $newpass = $this->
setPassword($user, $this->pass);
2058 if (is_int($newpass) && $newpass < 0) {
2061 } elseif (!empty($this->pass_crypted)) {
2062 $sql =
"UPDATE ".$this->db->prefix().
"user";
2063 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
2064 $sql .=
" WHERE rowid=".((int) $this->
id);
2066 $resql = $this->db->query($sql);
2072 if ($result > 0 && $member->socid) {
2073 $sql =
"UPDATE ".$this->db->prefix().
"user";
2074 $sql .=
" SET fk_soc=".((int) $member->socid);
2075 $sql .=
" WHERE rowid=".((int) $this->
id);
2077 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
2078 $resql = $this->db->query($sql);
2080 $this->db->commit();
2083 $this->
error = $this->db->lasterror();
2085 $this->db->rollback();
2092 $this->db->commit();
2096 $this->db->rollback();
2114 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
2115 $sql .=
" WHERE bydefault = 1";
2116 $sql .=
" AND entity = ".((int) $conf->entity);
2118 $resql = $this->db->query($sql);
2120 $num = $this->db->num_rows($resql);
2123 $row = $this->db->fetch_row($resql);
2127 $this->db->free($resql);
2131 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
2132 $result = $this->db->query($sql);
2134 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
2135 $result = $this->db->query($sql);
2155 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
2159 if (empty($this->country_id) && !empty($this->country_code)) {
2160 $country_id =
getCountry($this->country_code,
'3');
2161 $this->country_id = is_int($country_id) ? $country_id : 0;
2164 $nbrowsaffected = 0;
2167 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
2170 $this->civility_code = trim((
string) $this->civility_code);
2171 $this->lastname = trim((
string) $this->lastname);
2172 $this->firstname = trim((
string) $this->firstname);
2173 $this->ref_employee = trim((
string) $this->ref_employee);
2174 $this->national_registration_number = trim((
string) $this->national_registration_number);
2175 $this->employee = ($this->employee > 0 ? $this->employee : 0);
2176 $this->login = trim((
string) $this->login);
2177 $this->gender = trim((
string) $this->gender);
2179 $this->pass = trim((
string) $this->pass);
2180 $this->api_key = trim((
string) $this->api_key);
2181 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
2182 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
2185 $this->zip = trim((
string) $this->zip);
2186 $this->town = trim((
string) $this->town);
2188 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
2189 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
2190 $this->office_phone = trim((
string) $this->office_phone);
2191 $this->office_fax = trim((
string) $this->office_fax);
2192 $this->user_mobile = trim((
string) $this->user_mobile);
2193 $this->personal_mobile = trim((
string) $this->personal_mobile);
2195 $this->personal_email = trim((
string) $this->personal_email);
2197 $this->job = trim((
string) $this->job);
2198 $this->signature = trim((
string) $this->signature);
2199 $this->note_public = trim((
string) $this->note_public);
2200 $this->note_private = trim((
string) $this->note_private);
2201 $this->openid = trim((
string) $this->openid);
2202 $this->admin = ($this->admin > 0 ? $this->admin : 0);
2203 $this->user_modification_id = $user->id;
2205 $this->accountancy_code_user_general = trim((
string) $this->accountancy_code_user_general);
2206 $this->accountancy_code = trim((
string) $this->accountancy_code);
2207 $this->color = trim(str_replace(
'#',
'', (
string) $this->color));
2208 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
2209 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
2211 $this->birth = empty($this->birth) ?
'' : $this->birth;
2212 $this->fk_warehouse = (int) $this->fk_warehouse;
2213 $this->fk_establishment = (int) $this->fk_establishment;
2218 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
2221 $langs->load(
"errors");
2222 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
2225 if (empty($this->login)) {
2226 $langs->load(
"errors");
2227 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
2229 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
2230 $langs->load(
"errors");
2231 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
2238 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->oldcopy->login != $this->login) {
2239 $sqltochecklogin =
"SELECT COUNT(*) as nb FROM ".$this->db->prefix().
"user WHERE entity IN (".$this->db->sanitize(((
int) $this->entity).
", 0").
") AND login = '".$this->db->escape($this->login).
"'";
2240 $resqltochecklogin = $this->db->query($sqltochecklogin);
2241 if ($resqltochecklogin) {
2242 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2243 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2244 $langs->load(
"errors");
2245 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
2247 $this->db->rollback();
2252 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && !empty($this->email) && $this->oldcopy->email != $this->email) {
2253 $sqltochecklogin =
"SELECT COUNT(*) as nb FROM ".$this->db->prefix().
"user WHERE entity IN (".$this->db->sanitize(((
int) $this->entity).
", 0").
") AND email = '".$this->db->escape($this->email).
"'";
2254 $resqltochecklogin = $this->db->query($sqltochecklogin);
2255 if ($resqltochecklogin) {
2256 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2257 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2258 $langs->load(
"errors");
2259 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
2261 $this->db->rollback();
2268 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2269 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
2270 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
2271 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
2272 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
2273 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
2274 $sql .=
", employee = ".(int) $this->employee;
2275 $sql .=
", login = '".$this->db->escape($this->login).
"'";
2276 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
2277 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
2278 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
2279 if (!empty($user->admin)) {
2280 $sql .=
", admin = ".(int) $this->admin;
2282 $sql .=
", address = '".$this->db->escape($this->address).
"'";
2283 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
2284 $sql .=
", town = '".$this->db->escape($this->town).
"'";
2285 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".((
int) $this->state_id).
"'" :
"null");
2286 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".((
int) $this->country_id).
"'" :
"null");
2287 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
2288 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
2289 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
2290 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
2291 $sql .=
", email = '".$this->db->escape($this->email).
"'";
2292 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
2293 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
2294 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2295 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2296 $sql .=
", accountancy_code_user_general = '".$this->db->escape($this->accountancy_code_user_general).
"'";
2297 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2298 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2299 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2300 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2301 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2302 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2303 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2304 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2305 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2306 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2307 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".((int) $this->fk_user).
"'" :
"null");
2308 $sql .=
", fk_user_modif = ".($this->user_modification_id > 0 ?
"'".((int) $this->user_modification_id).
"'" :
"null");
2309 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".((int) $this->fk_user_expense_validator).
"'" :
"null");
2310 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".((int) $this->fk_user_holiday_validator).
"'" :
"null");
2311 if (isset($this->thm) || $this->thm !=
'') {
2312 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2314 if (isset($this->tjm) || $this->tjm !=
'') {
2315 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2317 if (isset($this->salary) || $this->salary !=
'') {
2318 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2320 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2321 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2323 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2324 if (
isModEnabled(
'multicompany') && !empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2329 $sql .=
", entity = ".((int) $this->entity);
2331 $sql .=
", default_range = ".($this->default_range > 0 ? (int) $this->default_range :
'null');
2332 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? (int) $this->default_c_exp_tax_cat :
'null');
2333 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? (int) $this->fk_warehouse :
"null");
2334 $sql .=
", fk_establishment = ".($this->fk_establishment > 0 ? (int) $this->fk_establishment :
"null");
2335 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2336 $sql .=
" WHERE rowid = ".((int) $this->
id);
2338 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2339 $resql = $this->db->query($sql);
2341 $nbrowsaffected += $this->db->affected_rows($resql);
2344 if (!empty($this->pass)) {
2345 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2347 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2348 if (is_int($result) && $result < 0) {
2355 if ($this->fk_member > 0) {
2356 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2357 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2358 $resql = $this->db->query($sql);
2360 $this->
error = $this->db->error();
2361 $this->db->rollback();
2366 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2367 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2368 $resql = $this->db->query($sql);
2370 $this->
error = $this->db->error();
2371 $this->db->rollback();
2375 if ($nbrowsaffected) {
2376 if ($this->fk_member > 0 && !$nosyncmember) {
2377 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2379 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2384 $result = $adh->fetch($this->fk_member);
2387 $adh->civility_code = $this->civility_code;
2388 $adh->firstname = $this->firstname;
2389 $adh->lastname = $this->lastname;
2390 $adh->login = $this->login;
2391 $adh->gender = $this->gender;
2392 $adh->birth = $this->birth;
2394 $adh->pass = $this->pass;
2396 $adh->address = $this->address;
2397 $adh->town = $this->town;
2398 $adh->zip = $this->zip;
2399 $adh->state_id = $this->state_id;
2400 $adh->country_id = $this->country_id;
2402 $adh->email = $this->email;
2404 $adh->socialnetworks = $this->socialnetworks;
2406 $adh->phone = $this->office_phone;
2407 $adh->phone_mobile = $this->user_mobile;
2409 $adh->default_lang = $this->lang;
2411 $adh->user_id = $this->id;
2412 $adh->user_login = $this->login;
2414 $result = $adh->update($user, 0, 1, 0);
2416 $this->
error = $adh->error;
2417 $this->errors = $adh->errors;
2418 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2421 } elseif ($result < 0) {
2422 $this->
error = $adh->error;
2423 $this->errors = $adh->errors;
2428 if ($this->contact_id > 0 && !$nosynccontact) {
2429 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2431 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2434 $tmpobj =
new Contact($this->db);
2435 $result = $tmpobj->fetch($this->contact_id);
2438 $tmpobj->civility_code = $this->civility_code;
2439 $tmpobj->firstname = $this->firstname;
2440 $tmpobj->lastname = $this->lastname;
2441 $tmpobj->login = $this->login;
2442 $tmpobj->gender = $this->gender;
2443 $tmpobj->birth = $this->birth;
2447 $tmpobj->email = $this->email;
2449 $tmpobj->socialnetworks = $this->socialnetworks;
2451 $tmpobj->phone_pro = $this->office_phone;
2452 $tmpobj->phone_mobile = $this->user_mobile;
2453 $tmpobj->fax = $this->office_fax;
2455 $tmpobj->default_lang = $this->lang;
2457 $tmpobj->address = $this->address;
2458 $tmpobj->town = $this->town;
2459 $tmpobj->zip = $this->zip;
2460 $tmpobj->state_id = $this->state_id;
2461 $tmpobj->country_id = $this->country_id;
2463 $tmpobj->user_id = $this->id;
2464 $tmpobj->user_login = $this->login;
2466 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2468 $this->
error = $tmpobj->error;
2469 $this->errors = $tmpobj->errors;
2470 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2474 $this->
error = $tmpobj->error;
2475 $this->errors = $tmpobj->errors;
2491 if (!$error && !$notrigger) {
2493 $result = $this->call_trigger(
'USER_MODIFY', $user);
2501 $this->db->commit();
2502 return $nbrowsaffected;
2505 $this->db->rollback();
2509 $this->
error = $this->db->lasterror();
2510 $this->db->rollback();
2529 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2530 $sql .=
" datepreviouslogin = datelastlogin,";
2531 $sql .=
" ippreviouslogin = iplastlogin,";
2532 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2533 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2534 $sql .=
" tms = tms";
2535 $sql .=
" WHERE rowid = ".((int) $this->
id);
2537 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2538 $resql = $this->db->query($sql);
2540 $this->datepreviouslogin = $this->datelastlogin;
2541 $this->datelastlogin = $now;
2542 $this->ippreviouslogin = $this->iplastlogin;
2543 $this->iplastlogin = $userremoteip;
2546 $this->
error = $this->db->lasterror().
' sql='.$sql;
2564 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2566 global $conf, $langs;
2567 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2571 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2578 $password_crypted =
null;
2580 if (empty($passwordalreadycrypted)) {
2583 $modGeneratePassClass =
'modGeneratePass'.ucfirst(
getDolGlobalString(
'USER_PASSWORD_GENERATED'));
2585 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2586 if (class_exists($modGeneratePassClass)) {
2587 $modGeneratePass =
new $modGeneratePassClass($this->db, $conf, $langs, $user);
2588 '@phan-var-force ModeleGenPassword $modGeneratePass';
2591 $modGeneratePass->WithoutAmbi = 0;
2594 $testpassword = $modGeneratePass->validatePassword($password);
2595 if (!$testpassword) {
2596 $this->
error = $modGeneratePass->error;
2604 $password_crypted =
dol_hash($password);
2608 if (!$changelater) {
2609 if (!is_object($this->oldcopy)) {
2610 $this->oldcopy = clone $this;
2617 $sql =
"UPDATE ".$this->db->prefix().
"user";
2618 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2619 $sql .=
" datelastpassvalidation = '".$this->db->idate(
dol_now()).
"',";
2620 $sql .=
" pass_temp = null";
2621 if (!empty($flagdelsessionsbefore)) {
2622 $sql .=
", flagdelsessionsbefore = '".$this->db->idate($now - 5,
'gmt').
"'";
2625 $sql .=
", pass = null";
2627 $sql .=
", pass = '".$this->db->escape($password).
"'";
2629 $sql .=
" WHERE rowid = ".((int) $this->
id);
2631 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2633 $result = $this->db->query($sql);
2635 if ($this->db->affected_rows($result)) {
2636 $this->pass = $password;
2637 $this->pass_indatabase = $password;
2638 $this->pass_indatabase_crypted = (string) $password_crypted;
2640 if ($this->fk_member && !$nosyncmember) {
2641 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2646 $result = $adh->fetch($this->fk_member);
2649 $result = $adh->setPassword($user, $this->pass, (!
getDolGlobalString(
'DATABASE_PWD_ENCRYPTED') ? 0 : 1), 1);
2650 if (is_int($result) && $result < 0) {
2651 $this->
error = $adh->error;
2656 $this->
error = $adh->error;
2661 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2664 $user->context[
'audit'] =
'login='.$user->login;
2665 if (!empty($flagdelsessionsbefore)) {
2666 $user->context[
'audit'] .=
" - flagdelsessionsbefore set to '".$this->db->idate($now - 5,
'gmt').
"'";
2669 if (!$error && !$notrigger) {
2671 $result = $this->call_trigger(
'USER_NEW_PASSWORD', $user);
2674 $this->db->rollback();
2680 $this->db->commit();
2683 $this->db->rollback();
2687 $this->db->rollback();
2694 $sql =
"UPDATE ".$this->db->prefix().
"user";
2695 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2696 $sql .=
" WHERE rowid = ".((int) $this->
id);
2698 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2699 $result = $this->db->query($sql);
2721 global $conf, $langs;
2724 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2731 $outputlangs =
new Translate(
"", $conf);
2736 $outputlangs = $langs;
2740 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2742 $appli =
getDolGlobalString(
'MAIN_APPLICATION_TITLE', constant(
'DOL_APPLICATION_TITLE'));
2744 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2747 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
2748 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2750 if (!$changelater) {
2751 $url = $urlwithroot.
'/';
2756 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2758 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2759 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2760 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2761 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2764 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2766 $mesg .= $user->getFullName($outputlangs);
2769 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2770 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.$conf->file->instance_unique_id));
2772 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2775 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2779 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2780 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2781 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2782 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2784 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2785 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2786 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2789 $trackid =
'use'.$this->id;
2790 $sendcontext =
'passwordreset';
2811 if ($mailfile->sendfile()) {
2814 $langs->trans(
"errors");
2815 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2827 return $this->error;
2840 $sql =
"SELECT url, login, pass, poste ";
2841 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2842 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2844 $resql = $this->db->query($sql);
2846 if ($this->db->num_rows($resql)) {
2847 $obj = $this->db->fetch_object($resql);
2849 $this->clicktodial_url = $obj->url;
2850 $this->clicktodial_login = $obj->login;
2851 $this->clicktodial_password = $obj->pass;
2852 $this->clicktodial_poste = $obj->poste;
2855 $this->clicktodial_loaded = 1;
2857 $this->db->free($resql);
2860 $this->
error = $this->db->error();
2876 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2877 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2879 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2881 $result = $this->db->query($sql);
2883 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2884 $sql .=
" (fk_user,url,login,pass,poste)";
2885 $sql .=
" VALUES (".$this->id;
2886 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2887 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2888 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2889 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2891 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2893 $result = $this->db->query($sql);
2895 $this->db->commit();
2898 $this->db->rollback();
2899 $this->
error = $this->db->lasterror();
2917 global $langs, $user;
2923 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2924 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2925 $sql .=
" AND fk_usergroup = ".((int) $group);
2926 $sql .=
" AND entity = ".((int) $entity);
2928 $result = $this->db->query($sql);
2930 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2931 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2933 $result = $this->db->query($sql);
2935 if (!$error && !$notrigger) {
2936 $this->context = array(
'audit' => $langs->trans(
"UserSetInGroup"),
'newgroupid' => $group);
2939 $result = $this->call_trigger(
'USER_MODIFY', $user);
2947 $this->db->commit();
2951 $this->db->rollback();
2955 $this->
error = $this->db->lasterror();
2956 $this->db->rollback();
2973 global $langs, $user;
2979 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2980 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2981 $sql .=
" AND fk_usergroup = ".((int) $group);
2982 if (empty($entity)) {
2983 $sql .=
" AND entity IN (0, 1)";
2985 $sql .=
" AND entity = ".((int) $entity);
2988 $result = $this->db->query($sql);
2990 if (!$error && !$notrigger) {
2991 $this->context = array(
'audit' => $langs->trans(
"UserRemovedFromGroup"),
'oldgroupid' => $group);
2994 $result = $this->call_trigger(
'USER_MODIFY', $user);
3002 $this->db->commit();
3005 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
3006 $this->db->rollback();
3010 $this->
error = $this->db->lasterror();
3011 $this->db->rollback();
3025 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
3032 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
3055 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
3057 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3058 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
3072 global $conf, $langs, $menumanager;
3073 global $dolibarr_main_demo;
3075 $infologin = $params[
'infologin'] ?? 0;
3076 $option = $params[
'option'] ??
'';
3079 if (!empty($this->photo)) {
3080 $photo =
'<div class="photointooltip floatright">';
3081 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
3083 $data[
'photo'] = $photo;
3088 $data[
'opendiv'] =
'<div class="centpercent divtooltip">';
3089 $data[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
3091 if (!empty($this->login)) {
3094 if (!empty($this->job)) {
3098 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
3099 $phonelist = array();
3100 if ($this->office_phone) {
3101 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
3103 if ($this->office_fax) {
3104 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
3106 if ($this->user_mobile) {
3107 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
3109 $data[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
3111 if (!empty($this->admin)) {
3112 $data[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
3114 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
3115 $langs->load(
"companies");
3116 $data[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
3119 if (!empty($this->socid)) {
3120 $thirdpartystatic =
new Societe($this->db);
3121 $thirdpartystatic->fetch($this->socid);
3123 if (empty($params[
'hidethirdpartylogo'])) {
3124 $companyimg =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3126 $company =
' ('.$langs->trans(
"Company").
': '.($companyimg ? $companyimg :
img_picto(
'',
'company')).
' '.
dol_string_nohtmltag($thirdpartystatic->name).
')';
3128 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
3129 $data[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
3130 $data[
'closediv'] =
'</div>';
3132 if ($infologin > 0) {
3133 $data[
'newlinelogin'] =
'<br>';
3134 $data[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
3137 $data[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.$conf->entity.
' (User entity '.$this->entity.
')';
3139 $data[
'authentication'] =
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
3140 $data[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
3141 $data[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
3142 $data[
'currenttheme'] =
'<br><b>'.$langs->trans(
"CurrentTheme").
':</b> '.
dol_string_nohtmltag($conf->theme);
3144 $data[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
3146 $data[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
3147 $data[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag($conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
3148 $data[
'layout'] =
'<br><b>'.$langs->trans(
"Layout").
':</b> '.
dol_string_nohtmltag($conf->browser->layout);
3149 $data[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
3150 if ($conf->browser->layout ==
'phone') {
3151 $data[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
3153 if (!empty($_SESSION[
"disablemodules"])) {
3154 $data[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(implode(
', ', explode(
',', $_SESSION[
"disablemodules"])));
3176 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
3178 global $langs, $hookmanager, $user;
3180 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
3191 'objecttype' => $this->element,
3192 'infologin' => $infologin,
3193 'option' => $option,
3194 'hidethirdpartylogo' => $hidethirdpartylogo,
3196 $classfortooltip =
'classfortooltip';
3199 $classfortooltip =
'classforajaxtooltip';
3200 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3207 if (!empty($this->socid)) {
3208 $thirdpartystatic =
new Societe($this->db);
3209 $thirdpartystatic->fetch($this->socid);
3210 if (empty($hidethirdpartylogo)) {
3211 $companylink =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3215 if ($infologin < 0) {
3219 $baseurl = DOL_URL_ROOT .
'/user/card.php';
3220 if ($option ==
'leave') {
3221 $baseurl = DOL_URL_ROOT .
'/holiday/list.php';
3223 $query = [
'id' => $this->id];
3224 if ($option !=
'nolink') {
3226 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3227 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3228 $add_save_lastsearch_values = 1;
3230 if ($add_save_lastsearch_values) {
3231 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
3236 $linkstart =
'<a href="'.$url.
'"';
3238 if (empty($notooltip)) {
3240 $langs->load(
"users");
3241 $label = $langs->trans(
"ShowUser");
3242 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
3244 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
3245 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
3247 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
3250 $linkstart .= $linkclose.
'>';
3254 $result .= (($option ==
'nolink') ?
'' : $linkstart);
3255 if ($withpictoimg) {
3256 $paddafterimage =
'';
3257 if (abs((
int) $withpictoimg) == 1 || abs((
int) $withpictoimg) == 4) {
3258 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3261 if ($withpictoimg > 0) {
3262 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'"><div class="valignmiddle userphoto inline-block center marginrightonlyshort"'.($paddafterimage ?
' '.$paddafterimage :
'').
'>'.
img_object(
'',
'user',
'class=""', 0, 0, $notooltip ? 0 : 1).
'</div></span>';
3265 $picto =
'<!-- picto photo user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'"'.($paddafterimage ?
' '.$paddafterimage :
'').
'>'.
Form::showphoto(
'userphoto', $this, 0, 0, 0,
'userphoto'.(($withpictoimg == -3 || $withpictoimg == -4) ?
'small' :
''),
'mini', 0, 1).
'</span>';
3269 if ($withpictoimg == -4 || ($withpictoimg > -2 && $withpictoimg != 2)) {
3271 $result .=
'<span class="nopadding usertext'.((!isset($this->
status) || $this->status) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
3273 if ($mode ==
'login') {
3279 $result .=
'</span>';
3282 $result .= (($option ==
'nolink') ?
'' : $linkend);
3285 $result .= $companylink;
3288 $hookmanager->initHooks(array(
'userdao'));
3289 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
3290 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3292 $result = $hookmanager->resPrint;
3294 $result .= $hookmanager->resPrint;
3309 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
3311 global $langs, $user;
3315 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3319 if ((!$user->hasRight(
'user',
'user',
'lire') && $this->id != $user->id)) {
3323 if ($option ==
'xxx') {
3324 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3328 if ($option ==
'nolink') {
3333 $result .= $linkstart;
3334 if ($withpictoimg) {
3335 $paddafterimage =
'';
3336 if (abs($withpictoimg) == 1) {
3337 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3340 if ($withpictoimg > 0) {
3341 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3344 $picto =
'<!-- picto photo user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'"'.($paddafterimage ?
' '.$paddafterimage :
'').
'>'.
Form::showphoto(
'userphoto', $this, 0, 0, 0,
'userphoto'.($withpictoimg == -3 ?
'small' :
''),
'mini', 0, 1).
'</span>';
3348 $result .= $this->login;
3349 $result .= $linkend;
3362 return $this->
LibStatut(isset($this->statut) ? (
int) $this->statut : (int) $this->
status, $mode);
3378 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3381 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3382 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3383 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3384 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3387 $statusType =
'status5';
3388 if ($status == self::STATUS_ENABLED) {
3389 $statusType =
'status4';
3392 $label = $this->labelStatus[$status];
3393 $labelshort = $this->labelStatusShort[$status];
3396 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3397 $statusType =
'status3';
3398 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3400 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3401 $statusType =
'status2';
3402 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3405 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3420 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3422 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3423 $return .=
'<div class="info-box info-box-sm">';
3424 $return .=
'<span class="info-box-icon bg-infobox-action">';
3427 if (!empty($this->photo)) {
3429 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3438 $return .=
'</span>';
3439 $return .=
'<div class="info-box-content">';
3440 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3441 if (
isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3442 $return .=
img_picto($langs->trans(
"SuperAdministratorDesc"),
'superadmin',
'class="valignmiddle paddingright paddingleft"');
3443 } elseif ($this->admin) {
3444 $return .=
img_picto($langs->trans(
"AdministratorDesc"),
'admin',
'class="valignmiddle paddingright paddingleft"');
3446 $return .=
'</span>';
3447 if ($selected >= 0) {
3448 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3450 if (property_exists($this,
'label')) {
3451 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3454 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->
email.
'</span>';
3456 if (method_exists($this,
'getLibStatut')) {
3457 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3459 $return .=
'</div>';
3460 $return .=
'</div>';
3461 $return .=
'</div>';
3485 } elseif ($mode == 1) {
3487 } elseif ($mode == 2) {
3503 global $conf, $langs;
3509 $keymodified =
false;
3518 'LDAP_FIELD_FULLNAME' =>
'fullname',
3519 'LDAP_FIELD_NAME' =>
'lastname',
3520 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3521 'LDAP_FIELD_LOGIN' =>
'login',
3522 'LDAP_FIELD_LOGIN_SAMBA' =>
'login',
3523 'LDAP_FIELD_PHONE' =>
'office_phone',
3524 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3525 'LDAP_FIELD_FAX' =>
'office_fax',
3526 'LDAP_FIELD_MAIL' =>
'email',
3527 'LDAP_FIELD_SID' =>
'ldap_sid',
3531 foreach ($ldapkey as $constname => $varname) {
3537 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->$varname != $this->oldcopy->$varname) {
3538 $keymodified =
true;
3543 foreach ($socialnetworks as $key => $value) {
3544 if (!empty($this->socialnetworks[$value[
'label']]) &&
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))) {
3545 $info[
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))] = $this->socialnetworks[$value[
'label']];
3561 $soc =
new Societe($this->db);
3562 $soc->fetch($this->socid);
3565 if ($soc->client == 1) {
3566 $info[
"businessCategory"] =
"Customers";
3568 if ($soc->client == 2) {
3569 $info[
"businessCategory"] =
"Prospects";
3571 if ($soc->fournisseur == 1) {
3572 $info[
"businessCategory"] =
"Suppliers";
3577 if (!empty($this->pass)) {
3590 if ($this->pass_indatabase_crypted &&
getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED')) {
3594 } elseif (!empty($this->pass_indatabase)) {
3606 $info[
"objectclass"][4] =
"phpgwContact";
3608 $info[
'uidnumber'] = $this->id;
3610 $info[
'phpgwTz'] = 0;
3611 $info[
'phpgwMailType'] =
'INTERNET';
3612 $info[
'phpgwMailHomeType'] =
'INTERNET';
3614 $info[
"phpgwContactTypeId"] =
'n';
3615 $info[
"phpgwContactCatId"] = 0;
3616 $info[
"phpgwContactAccess"] =
"public";
3618 $info[
"phpgwContactOwner"] = 1;
3621 $info[
"rfc822Mailbox"] = $this->email;
3623 if ($this->user_mobile) {
3624 $info[
"phpgwCellTelephoneNumber"] = $this->user_mobile;
3633 $groupslist = $usergroup->listGroupsForUser($this->
id);
3635 if (!empty($groupslist)) {
3636 foreach ($groupslist as $groupforuser) {
3665 $this->
ref =
'SPECIMEN';
3666 $this->specimen = 1;
3667 $this->user_creation_id = $user->id;
3669 $this->lastname =
'DOLIBARR';
3670 $this->firstname =
'SPECIMEN';
3671 $this->gender =
'man';
3672 $this->note_public =
'This is a note public';
3673 $this->note_private =
'This is a note private';
3674 $this->
email =
'email@specimen.com';
3675 $this->personal_email =
'personalemail@specimen.com';
3676 $this->socialnetworks = array(
3677 'skype' =>
'skypepseudo',
3678 'twitter' =>
'twitterpseudo',
3679 'facebook' =>
'facebookpseudo',
3680 'linkedin' =>
'linkedinpseudo',
3682 $this->office_phone =
'0999999999';
3683 $this->office_fax =
'0999999998';
3684 $this->user_mobile =
'0999999997';
3685 $this->personal_mobile =
'0999999996';
3687 $this->login =
'dolibspec';
3688 $this->pass =
'dolibSpec+@123';
3691 $this->datec = $now;
3692 $this->datem = $now;
3694 $this->datelastlogin = $now;
3695 $this->iplastlogin =
'127.0.0.1';
3696 $this->datepreviouslogin = $now;
3697 $this->ippreviouslogin =
'127.0.0.1';
3713 $sql =
"SELECT u.rowid, u.login as ref, u.datec, fk_user_creat as user_creation_id, fk_user_modif as user_modification_id,";
3714 $sql .=
" GREATEST(u.tms, COALESCE(uef.tms, u.tms)) as date_modification, u.entity";
3715 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3716 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user_extrafields as uef ON uef.fk_object = u.rowid";
3717 $sql .=
" WHERE u.rowid = ".((int) $id);
3719 $result = $this->db->query($sql);
3721 if ($this->db->num_rows($result)) {
3722 $obj = $this->db->fetch_object($result);
3724 $this->
id = $obj->rowid;
3726 $this->user_creation_id = $obj->user_creation_id;
3727 $this->user_modification_id = $obj->user_modification_id;
3729 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3730 $this->date_creation = $this->db->jdate($obj->datec);
3731 $this->date_modification = $this->db->jdate($obj->date_modification);
3732 $this->entity = $obj->entity;
3735 $this->db->free($result);
3749 $sql =
"SELECT count(mc.email) as nb";
3750 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3751 $sql .=
" WHERE mc.email = '".$this->db->escape($this->
email).
"'";
3752 $sql .=
" AND mc.statut NOT IN (-1,0)";
3754 $resql = $this->db->query($sql);
3756 $obj = $this->db->fetch_object($resql);
3757 $nb = (int) $obj->nb;
3759 $this->db->free($resql);
3762 $this->
error = $this->db->error();
3777 $sql =
"SELECT count(rowid) as nb";
3778 $sql .=
" FROM ".$this->db->prefix().
"user";
3779 if ($option ==
'superadmin') {
3780 $sql .=
" WHERE entity = 0";
3782 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3783 if ($limitTo ==
'active') {
3784 $sql .=
" AND statut = 1";
3788 $sql .=
" AND admin = ".(int) $admin;
3791 $resql = $this->db->query($sql);
3793 $obj = $this->db->fetch_object($resql);
3794 $nb = (int) $obj->nb;
3796 $this->db->free($resql);
3799 $this->
error = $this->db->lasterror();
3820 $this->firstname = $ldapuser->$tmpvar;
3822 $this->lastname = $ldapuser->$tmpvar;
3824 $this->login = $ldapuser->$tmpvar;
3826 $this->pass = $ldapuser->$tmpvar;
3828 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3831 $this->office_phone = $ldapuser->$tmpvar;
3833 $this->user_mobile = $ldapuser->$tmpvar;
3835 $this->office_fax = $ldapuser->$tmpvar;
3837 $this->
email = $ldapuser->$tmpvar;
3838 foreach ($socialnetworks as $key => $value) {
3840 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3843 $this->ldap_sid = $ldapuser->$tmpvar;
3846 $this->job = $ldapuser->$tmpvar;
3848 $this->note_public = $ldapuser->$tmpvar;
3850 $result = $this->
update($user);
3852 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3868 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3869 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3871 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3872 $res = $this->db->query($sql);
3875 while ($rec = $this->db->fetch_array($res)) {
3876 $user =
new User($this->db);
3877 $user->fetch($rec[
'rowid']);
3895 $this->parentof = array();
3898 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3899 $sql .=
" FROM ".$this->db->prefix().
"user";
3900 $sql .=
" WHERE fk_user <> 0";
3901 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3903 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3904 $resql = $this->db->query($sql);
3906 while ($obj = $this->db->fetch_object($resql)) {
3907 $this->parentof[$obj->id_son] = $obj->id_parent;
3933 global $hookmanager;
3936 $hookmanager->initHooks(array(
'userdao'));
3938 $this->users = array();
3944 $sql =
"SELECT DISTINCT u.rowid, u.firstname, u.lastname, u.fk_user, u.fk_soc, u.login, u.email, u.gender, u.admin, u.statut, u.photo, u.entity";
3945 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3947 $parameters = array();
3948 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3950 $sql .= $hookmanager->resPrint;
3952 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3955 $sql .=
" AND ".$filter;
3958 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3959 $resql = $this->db->query($sql);
3962 while ($obj = $this->db->fetch_object($resql)) {
3963 $this->users[(int) $obj->rowid]
3965 'rowid' => (
int) $obj->rowid,
3966 'id' => (int) $obj->rowid,
3967 'fk_user' => (
int) $obj->fk_user,
3968 'fk_soc' => (int) $obj->fk_soc,
3969 'firstname' => (
string) $obj->firstname,
3970 'lastname' => (string) $obj->lastname,
3971 'login' => (
string) $obj->login,
3972 'statut' => (int) $obj->statut,
3973 'entity' => (
int) $obj->entity,
3974 'email' => (string) $obj->email,
3975 'gender' => (
string) $obj->gender,
3976 'admin' => (int) $obj->admin,
3977 'photo' => (
string) $obj->photo,
3991 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3992 foreach ($this->users as $key => $val) {
3995 $this->
error =
'ErrorLoopInHierarchy';
4001 if ($deleteafterid) {
4003 $keyfilter1 =
'^'.$deleteafterid.
'$';
4004 $keyfilter2 =
'_'.$deleteafterid.
'$';
4005 $keyfilter3 =
'^'.$deleteafterid.
'_';
4006 $keyfilter4 =
'_'.$deleteafterid.
'_';
4007 foreach (array_keys($this->users) as $key) {
4008 $fullpath = (string) $this->users[$key][
'fullpath'];
4009 if (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
4010 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath)) {
4011 unset($this->users[$key]);
4016 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
4017 $this->users =
dol_sort_array($this->users,
'fullname',
'asc', 1, 0, 1);
4021 return $this->users;
4034 $childids = array();
4036 if (isset($this->cache_childids[$this->
id])) {
4037 $childids = $this->cache_childids[$this->id];
4042 $idtoscan = $this->id;
4044 dol_syslog(
"Build childid for id = ".$idtoscan);
4045 foreach ($this->users as $id => $val) {
4047 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
4048 $childids[$val[
'id']] = $val[
'id'];
4055 if ($treeresult < 0) {
4056 dol_syslog(get_class($this).
"::getAllChildIds got a truncated tree: ".$this->
error, LOG_WARNING);
4057 return $addcurrentuser ? array($this->
id => $this->
id) : $childids;
4060 $this->cache_childids[$this->id] = $childids;
4062 if ($addcurrentuser) {
4063 $childids[$this->id] = $this->id;
4083 if (!empty($this->users[$id_user][
'fullpath'])) {
4085 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
4090 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
4091 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
4093 $cursor_user = $id_user;
4095 $useridfound = array($id_user);
4096 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
4097 if (in_array($this->parentof[$cursor_user], $useridfound)) {
4098 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
4101 $useridfound[] = $this->parentof[$cursor_user];
4102 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
4103 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
4105 $cursor_user = $this->parentof[$cursor_user];
4109 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
4139 $this->nb = array();
4141 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
4142 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4144 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
4145 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
4146 $sql .=
" AND ug.fk_user = u.rowid";
4148 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4150 $sql .=
" AND u.statut > 0";
4153 $resql = $this->db->query($sql);
4155 while ($obj = $this->db->fetch_object($resql)) {
4156 $this->nb[
"users"] = $obj->nb;
4158 $this->db->free($resql);
4162 $this->
error = $this->db->error();
4178 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4182 $langs->load(
"user");
4189 $modele =
'bluesky';
4193 $modelpath =
"core/modules/user/doc/";
4195 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4209 $user_property =
'';
4211 if (empty($rowid)) {
4215 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
4216 $sql .=
" FROM ".$this->db->prefix().
"user";
4217 $sql .=
" WHERE rowid = ".((int) $rowid);
4219 $resql = $this->db->query($sql);
4221 $nump = $this->db->num_rows($resql);
4224 $obj = $this->db->fetch_object($resql);
4226 if ($mode ==
'email') {
4227 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
4228 } elseif ($mode ==
'mobile') {
4229 $user_property = $obj->user_mobile;
4230 } elseif ($mode ==
'name') {
4234 return $user_property;
4254 $instanceuniqueid = empty($conf->file->instance_unique_id) ?
'' : $conf->file->instance_unique_id;
4255 $encodedsecurekey =
dol_hash($instanceuniqueid.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
4257 $entity_qr =
'&entity='.((int) $conf->entity);
4262 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
4263 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
4266 if ($typeofurl ==
'internal') {
4267 $urlwithroot = DOL_URL_ROOT;
4270 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
4286 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $entityfilter =
false)
4288 global $conf, $user;
4290 $sql =
"SELECT t.rowid";
4291 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
4293 if ($entityfilter) {
4295 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
4296 $sql .=
" WHERE t.entity IS NOT NULL";
4298 $sql .=
" WHERE t.entity = 0 OR EXISTS (";
4299 $sql .=
" SELECT ug.rowid FROM " . $this->db->prefix() .
"usergroup_user as ug";
4300 $sql .=
" WHERE ug.fk_user = t.rowid AND ug.entity IN (" .
getEntity(
'usergroup') .
"))";
4303 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
4306 $sql .=
" WHERE 1 = 1";
4312 if ($errormessage) {
4313 $this->errors[] = $errormessage;
4314 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
4318 $sql .= $this->db->order($sortfield, $sortorder);
4320 $sql .= $this->db->plimit($limit + 1, $offset);
4325 $resql = $this->db->query($sql);
4327 $this->users = array();
4328 $num = $this->db->num_rows($resql);
4330 while ($obj = $this->db->fetch_object($resql)) {
4331 $line =
new self($this->db);
4332 $result = $line->fetch($obj->rowid);
4333 if ($result > 0 && !empty($line->id)) {
4334 $this->users[$obj->rowid] = clone $line;
4337 $this->db->free($resql);
4341 $this->errors[] = $this->db->lasterror();
4353 private $findUserIdByEmailCache;
4367 if (isset($this->findUserIdByEmailCache[$email])) {
4368 return $this->findUserIdByEmailCache[$email];
4371 $this->findUserIdByEmailCache[$email] = -1;
4373 $sql =
'SELECT rowid';
4374 $sql .=
' FROM '.$this->db->prefix().
'user';
4375 if (
getDolGlobalString(
'AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR')) {
4376 $sql .=
" WHERE email LIKE '%".$this->db->escape($this->db->escapeforlike($email)).
"%'";
4378 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4382 $resql = $this->db->query($sql);
4387 $obj = $this->db->fetch_object($resql);
4392 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4394 return $this->findUserIdByEmailCache[$email];
4405 if (empty($fromId) || empty($toId)) {
4412 $sqlDelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
4413 $sqlDelete .=
" WHERE fk_user = ".((int) $toId);
4415 dol_syslog(get_class($this).
"::clone_rights (delete default permissions)", LOG_DEBUG);
4417 if (!$this->db->query($sqlDelete)) {
4418 $this->db->rollback();
4423 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id)";
4424 $sql .=
" SELECT entity, ".((int) $toId).
", fk_id";
4425 $sql .=
" FROM ".$this->db->prefix().
"user_rights src";
4426 $sql .=
" WHERE fk_user = ".((int) $fromId);
4427 $sql .=
" AND NOT EXISTS (";
4428 $sql .=
" SELECT 1";
4429 $sql .=
" FROM ".$this->db->prefix().
"user_rights dest";
4430 $sql .=
" WHERE dest.entity = src.entity";
4431 $sql .=
" AND dest.fk_user = ".((int) $toId);
4432 $sql .=
" AND dest.fk_id = src.fk_id";
4435 dol_syslog(get_class($this).
"::clone_rights", LOG_DEBUG);
4438 if (!$this->db->query($sql)) {
4439 $this->db->rollback();
4443 $this->db->commit();
4460 $type = $this->table_element;
4463 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4464 $categorystatic =
new Categorie($this->db);
4466 $sql =
"INSERT INTO ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]).
" (fk_categorie, fk_user)";
4467 $sql .=
" SELECT fk_categorie, ".((int) $toId).
" FROM ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]);
4468 $sql .=
" WHERE fk_user = ".((int) $fromId);
4470 if (!$this->db->query($sql)) {
4471 $this->
error = $this->db->lasterror();
4472 $this->db->rollback();
4476 $this->db->commit();
global $dolibarr_main_url_root
Class to manage members of a foundation.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage categories.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class to manage Dolibarr database access.
Class to manage warehouses.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage user groups.
Class to manage Dolibarr users.
fetch($id=0, $login='', $sid='', $loadpersonalconf=0, $entity=-1, $email='', $fk_socpeople=0, $use_email_oauth2=0)
Load a user from database with its id or ref (login).
SetInGroup($group, $entity, $notrigger=0)
Add user into a group.
LibStatut($status, $mode=0)
Return the label of a status of user (active, inactive)
loadRights($moduletag='', $forcereload=0)
Load permissions granted to a user->id into object user->rights.
get_children()
Return and array with all instantiated first level children users of current user.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
loadStateBoard()
Load metrics this->nb for dashboard.
hasRight($module, $permlevel1, $permlevel2='')
Return if a user has a permission.
info($id)
Load info of user object.
create_from_contact($contact, $login='', $password='')
Create a user from a contact object.
setstatus($status)
Change status of a user.
get_full_tree($deleteafterid=0, $filter='')
Build the hierarchy/tree of users into an array.
_load_ldap_info()
Initialize the info array (array of LDAP values) that will be used to call LDAP functions.
delrights($rid, $allmodule='', $allperms='', $entity=0, $notrigger=0)
Remove a right to the user.
update_last_login_date()
Update the user's last login date in the database.
__construct($db)
Constructor of the class.
RemoveFromGroup($group, $entity, $notrigger=0)
Remove a user from a group.
isNotIntoValidityDateRange()
Return a link with photo Use this->id,this->photo.
getNbOfUsers($limitTo, $option='', $admin=-1)
Return number of existing users.
set_default_rights()
Assign rights by default.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND', $entityfilter=false)
Load all objects into $this->users.
getOnlineVirtualCardUrl($mode='', $typeofurl='external')
Return string with full Url to virtual card.
update($user, $notrigger=0, $nosyncmember=0, $nosyncmemberpass=0, $nosynccontact=0)
Update a user into database (and also password if this->pass is defined)
getLoginUrl($withpictoimg=0, $option='', $notooltip=0, $morecss='')
Return clickable link of login (optionally with picto)
setCategories($categories)
Sets object to supplied categories.
loadParentOf()
Load this->parentof that is array(id_son=>id_parent, ...)
fetch_clicktodial()
Read clicktodial information for user.
build_path_from_id_user($id_user, $protection=0)
For user id_user and its children available in this->users, define property fullpath and fullname.
error()
Renvoie la derniere erreur fonctionnelle de manipulation de l'objet.
cloneCategories($fromId, $toId, $type='user')
Copy related categories to another object.
getAllChildIds($addcurrentuser=0)
Return list of all child user ids in hierarchy (all sublevels).
initAsSpecimen()
Initialise an instance with random values.
setPassword($user, $password='', $changelater=0, $notrigger=0, $nosyncmember=0, $passwordalreadycrypted=0, $flagdelsessionsbefore=1)
Change password of a user.
getNomUrl($withpictoimg=0, $option='', $infologin=0, $notooltip=0, $maxlen=24, $hidethirdpartylogo=0, $mode='', $morecss='', $save_lastsearch_value=-1)
Return a HTML link to the user card (with optionally the picto) Use this->id,this->lastname,...
clearrights()
Clear all permissions array of user.
update_clicktodial()
Update clicktodial info.
cloneRights($fromId, $toId)
Clone permissions of user.
getLibStatut($mode=0)
Return the label of the status of user (active, inactive)
create_from_member($member, $login='')
Create a user into database from a member object.
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
loadDefaultValues()
Load default values from database table into property ->default_values.
getPhotoUrl($width, $height, $cssclass='', $imagesize='')
Return a link with photo Use this->id,this->photo.
isAdmin()
Return if a user is an admin user It replaces old syntax: if ($user->admin)
update_ldap2dolibarr(&$ldapuser)
Update user using data from the LDAP.
getrights($moduletag='', $forcereload=0)
Load permissions granted to a user->id into object user->rights TODO Remove this method.
user_get_property($rowid, $mode)
Return property of user from its id.
send_password($user, $password='', $changelater=0)
Send a new password (or instructions to reset it) by email.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (optionally with picto)
getNbOfEMailings()
Return number of mass Emailing received by this contacts with its email.
addrights($rid, $allmodule='', $allperms='', $entity=0, $notrigger=0)
Add a right to the user.
create($user, $notrigger=0)
Create a user into database.
loadPersonalConf($entity=-1)
Load const values from database table user_param and set it into user->conf->XXX.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
findUserIdByEmail($email)
Find a user by the given e-mail and return it's user id when found.
getTooltipContentArray($params)
getTooltipContentArray
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
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").
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolBuildUrl($url, $params=[], $addtoken=false)
Return path of url.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
getArrayOfSocialNetworks()
Get array of social network dictionary.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
div refaddress div address
conf($dolibarr_main_document_root)
Load conf file (file must exists)
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
dol_verifyHash($chain, $hash, $type='0')
Compute a hash and compare it to the given one For backward compatibility reasons,...
dolEncrypt($chain, $key='', $ciphering='', $forceseed='')
Encode a string with a symmetric encryption.
dolGetLdapPasswordHash($password, $type='md5')
Returns a specific ldap hash of a password.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.