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';
115 public $civility_code;
140 public $email_oauth2;
145 public $personal_email;
150 public $socialnetworks;
165 public $office_phone;
180 public $personal_mobile;
210 public $pass_crypted;
215 public $pass_indatabase;
220 public $pass_indatabase_crypted;
264 public $fk_user_expense_validator;
269 public $fk_user_holiday_validator;
274 public $clicktodial_url;
279 public $clicktodial_login;
284 public $clicktodial_password;
289 public $clicktodial_poste;
294 public $clicktodial_loaded;
300 public $datelastlogin;
304 public $datepreviouslogin;
308 public $flagdelsessionsbefore;
316 public $ippreviouslogin;
320 public $datestartvalidity;
324 public $dateendvalidity;
344 public $all_permissions_are_loaded;
354 public $user_group_list;
359 private $_tab_loaded = array();
369 public $default_values;
374 public $lastsearch_values_tmp;
378 public $lastsearch_values;
383 public $users = array();
391 private $cache_childids;
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;
478 public $usergroup_entity;
480 public $fields = array(
481 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
482 'lastname' => array(
'type' =>
'varchar(50)',
'label' =>
'Lastname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 20,
'searchall' => 1),
483 'firstname' => array(
'type' =>
'varchar(50)',
'label' =>
'Firstname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 10,
'searchall' => 1),
484 'ref_employee' => array(
'type' =>
'varchar(50)',
'label' =>
'RefEmployee',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 30,
'searchall' => 1),
485 'national_registration_number' => array(
'type' =>
'varchar(50)',
'label' =>
'NationalRegistrationNumber',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 40,
'searchall' => 1)
488 const STATUS_DISABLED = 0;
489 const STATUS_ENABLED = 1;
500 $this->ismultientitymanaged = 1;
501 $this->isextrafieldmanaged = 1;
503 $this->clicktodial_loaded = 0;
506 $this->all_permissions_are_loaded = 0;
507 $this->nb_rights = 0;
515 $this->rights->user =
new stdClass();
516 $this->rights->user->user =
new stdClass();
517 $this->rights->user->self =
new stdClass();
518 $this->rights->user->user_advance =
new stdClass();
519 $this->rights->user->self_advance =
new stdClass();
520 $this->rights->user->group_advance =
new stdClass();
537 public function fetch($id = 0, $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'', $fk_socpeople = 0, $use_email_oauth2 = 0)
542 $login = trim($login);
545 $sql =
"SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.civility as civility_code, u.birth, u.job,";
546 $sql .=
" u.email, u.email_oauth2, u.personal_email,";
547 $sql .=
" u.socialnetworks,";
548 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
549 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
550 $sql .=
" u.admin, u.login, u.note_private, u.note_public,";
551 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.api_key,";
552 $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,";
553 $sql .=
" u.statut as status, u.lang, u.entity,";
554 $sql .=
" u.datec as datec,";
555 $sql .=
" u.tms as datem,";
556 $sql .=
" u.datelastlogin as datel,";
557 $sql .=
" u.datepreviouslogin as datep,";
558 $sql .=
" u.flagdelsessionsbefore,";
559 $sql .=
" u.iplastlogin,";
560 $sql .=
" u.ippreviouslogin,";
561 $sql .=
" u.datelastpassvalidation,";
562 $sql .=
" u.datestartvalidity,";
563 $sql .=
" u.dateendvalidity,";
564 $sql .=
" u.photo as photo,";
565 $sql .=
" u.openid as openid,";
566 $sql .=
" u.accountancy_code,";
569 $sql .=
" u.salary,";
570 $sql .=
" u.salaryextra,";
571 $sql .=
" u.weeklyhours,";
573 $sql .=
" u.dateemployment, u.dateemploymentend,";
574 $sql .=
" u.fk_warehouse,";
575 $sql .=
" u.ref_ext,";
576 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
577 $sql .=
" u.national_registration_number,";
578 $sql .=
" u.ref_employee,";
579 $sql .=
" c.code as country_code, c.label as country,";
580 $sql .=
" d.code_departement as state_code, d.nom as state,";
581 $sql .=
" s.label as label_establishment, u.fk_establishment";
582 $sql .=
" FROM ".$this->db->prefix().
"user as u";
583 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as c ON u.fk_country = c.rowid";
584 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_departements as d ON u.fk_state = d.rowid";
585 $sql .=
" LEFT JOIN ".$this->db->prefix().
"establishment as s ON u.fk_establishment = s.rowid";
588 if ((!isModEnabled(
'multicompany') || !
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) && (!empty($user->entity))) {
589 $sql .=
" WHERE u.entity IN (0, ".((int) $conf->entity).
")";
591 $sql .=
" WHERE u.entity IS NOT NULL";
595 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
596 $sql .=
" WHERE u.entity IS NOT NULL";
598 $sql .=
" WHERE u.entity IN (0, ".((int) (($entity !=
'' && $entity >= 0) ? $entity : $conf->entity)).
")";
604 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->db->escape($login).
"')";
606 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
608 $sql .=
" AND (u.email = '".$this->db->escape($email).
"'";
609 if ($use_email_oauth2) {
610 $sql .=
" OR u.email_oauth2 = '".$this->db->escape($email).
"'";
613 } elseif ($fk_socpeople > 0) {
614 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
616 $sql .=
" AND u.rowid = ".((int) $id);
618 $sql .=
" ORDER BY u.entity ASC";
622 $sql .=
' '.$this->db->plimit(1);
625 $resql = $this->db->query($sql);
627 $num = $this->db->num_rows($resql);
629 $this->
error =
"USERDUPLICATEFOUND";
630 dol_syslog(get_class($this).
"::fetch more than 1 user found", LOG_WARNING);
632 $this->db->free($resql);
636 $obj = $this->db->fetch_object($resql);
638 $this->
id = $obj->rowid;
639 $this->
ref = $obj->rowid;
641 $this->ref_ext = $obj->ref_ext;
643 $this->ldap_sid = $obj->ldap_sid;
644 $this->civility_code = $obj->civility_code;
645 $this->lastname = $obj->lastname;
646 $this->firstname = $obj->firstname;
647 $this->ref_employee = $obj->ref_employee;
648 $this->national_registration_number = $obj->national_registration_number;
650 $this->employee = $obj->employee;
652 $this->login = $obj->login;
653 $this->gender = $obj->gender;
654 $this->birth = $this->db->jdate($obj->birth);
655 $this->pass_indatabase = $obj->pass;
656 $this->pass_indatabase_crypted = $obj->pass_crypted;
657 $this->pass = $obj->pass;
658 $this->pass_temp = $obj->pass_temp;
661 $this->
address = $obj->address;
662 $this->zip = $obj->zip;
663 $this->town = $obj->town;
665 $this->country_id = $obj->country_id;
666 $this->country_code = $obj->country_id ? $obj->country_code :
'';
669 $this->state_id = $obj->state_id;
670 $this->state_code = $obj->state_code;
671 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
673 $this->office_phone = $obj->office_phone;
674 $this->office_fax = $obj->office_fax;
675 $this->user_mobile = $obj->user_mobile;
676 $this->personal_mobile = $obj->personal_mobile;
677 $this->
email = $obj->email;
678 $this->email_oauth2 = $obj->email_oauth2;
679 $this->personal_email = $obj->personal_email;
680 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
682 $this->job = $obj->job;
683 $this->signature = $obj->signature;
684 $this->admin = $obj->admin;
685 $this->note_public = $obj->note_public;
686 $this->note_private = $obj->note_private;
688 $this->statut = $obj->status;
689 $this->
status = $obj->status;
691 $this->photo = $obj->photo;
692 $this->openid = $obj->openid;
693 $this->lang = $obj->lang;
694 $this->entity = $obj->entity;
695 $this->accountancy_code = $obj->accountancy_code;
696 $this->thm = $obj->thm;
697 $this->tjm = $obj->tjm;
698 $this->salary = $obj->salary;
699 $this->salaryextra = $obj->salaryextra;
700 $this->weeklyhours = $obj->weeklyhours;
701 $this->color = $obj->color;
702 $this->dateemployment = $this->db->jdate($obj->dateemployment);
703 $this->dateemploymentend = $this->db->jdate($obj->dateemploymentend);
705 $this->datec = $this->db->jdate($obj->datec);
706 $this->datem = $this->db->jdate($obj->datem);
707 $this->datelastlogin = $this->db->jdate($obj->datel);
708 $this->datepreviouslogin = $this->db->jdate($obj->datep);
709 $this->flagdelsessionsbefore = $this->db->jdate($obj->flagdelsessionsbefore,
'gmt');
710 $this->iplastlogin = $obj->iplastlogin;
711 $this->ippreviouslogin = $obj->ippreviouslogin;
712 $this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
713 $this->dateendvalidity = $this->db->jdate($obj->dateendvalidity);
715 $this->socid = $obj->fk_soc;
716 $this->contact_id = $obj->fk_socpeople;
717 $this->fk_member = $obj->fk_member;
718 $this->fk_user = $obj->fk_user;
719 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
720 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
722 $this->default_range = $obj->default_range;
723 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
724 $this->fk_warehouse = $obj->fk_warehouse;
725 $this->fk_establishment = $obj->fk_establishment;
726 $this->label_establishment = $obj->label_establishment;
730 if (!isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
738 $this->db->free($resql);
740 $this->
error =
"USERNOTFOUND";
741 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
743 $this->db->free($resql);
747 $this->
error = $this->db->lasterror();
752 if ($loadpersonalconf) {
758 $this->
error = $this->db->lasterror();
777 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
778 $sql .=
" WHERE fk_user = ".((int) $this->
id);
779 $sql .=
" AND entity = ".((int) $conf->entity);
781 $resql = $this->db->query($sql);
783 $num = $this->db->num_rows($resql);
786 $obj = $this->db->fetch_object($resql);
787 $p = (!empty($obj->param) ? $obj->param :
'');
789 $this->
conf->$p = $obj->value;
793 $this->db->free($resql);
797 $this->
error = $this->db->lasterror();
814 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
817 $result = $defaultValues->fetchAll(
'',
'', 0, 0,
'(t.user_id:in:0,'.$this->
id.
') AND (entity:in:'.(isset($this->entity) ? $this->entity : $conf->entity).
','.$conf->entity.
')');
820 if (!is_array($result) && $result < 0) {
824 } elseif (count($result) > 0) {
825 foreach ($result as $defval) {
826 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
827 $pagewithoutquerystring = $defval->page;
830 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
831 $pagewithoutquerystring = $reg[1];
832 $pagequeries = $reg[2];
834 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
838 if (!empty($this->default_values)) {
839 foreach ($this->default_values as $a => $b) {
840 foreach ($b as $c => $d) {
841 krsort($this->default_values[$a][$c]);
860 public function hasRight($module, $permlevel1, $permlevel2 =
'')
863 $moduletomoduletouse = array(
864 'compta' =>
'comptabilite',
865 'contract' =>
'contrat',
866 'member' =>
'adherent',
868 'order' =>
'commande',
869 'produit' =>
'product',
870 'project' =>
'projet',
871 'propale' =>
'propal',
872 'shipping' =>
'expedition',
873 'task' =>
'task@projet',
874 'fichinter' =>
'ficheinter',
875 'inventory' =>
'stock',
876 'invoice' =>
'facture',
877 'invoice_supplier' =>
'fournisseur',
878 'order_supplier' =>
'fournisseur',
879 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
880 'skill@hrm' =>
'all@hrm',
881 'job@hrm' =>
'all@hrm',
882 'position@hrm' =>
'all@hrm',
883 'facturerec' =>
'facture',
884 'margins' =>
'margin',
887 if (!empty($moduletomoduletouse[$module])) {
888 $module = $moduletomoduletouse[$module];
891 $moduleRightsMapping = array(
892 'product' =>
'produit',
893 'margin' =>
'margins',
894 'comptabilite' =>
'compta'
897 $rightsPath = $module;
898 if (!empty($moduleRightsMapping[$rightsPath])) {
899 $rightsPath = $moduleRightsMapping[$rightsPath];
903 $tmp = explode(
'@', $rightsPath, 2);
904 if (!empty($tmp[1])) {
905 if (strpos($module,
'@') !==
false) {
908 if ($tmp[0] != $tmp[1]) {
910 $rightsPath = $tmp[1];
911 $permlevel2 = $permlevel1;
912 $permlevel1 = $tmp[0];
915 $rightsPath = $tmp[1];
924 if (!isModEnabled($module)) {
929 if (!empty($this->socid)) {
930 if ($module ==
'societe' && ($permlevel1 ==
'creer' || $permlevel1 ==
'write')) {
933 if ($module ==
'societe' && $permlevel1 ==
'client' && $permlevel2 ==
'voir') {
936 if ($module ==
'societe' && $permlevel1 ==
'export') {
939 if ($module ==
'societe' && ($permlevel1 ==
'supprimer' || $permlevel1 ==
'delete')) {
945 if ($permlevel1 ==
'propale') {
946 $permlevel1 =
'propal';
948 if ($permlevel1 ==
'member') {
949 $permlevel1 =
'adherent';
951 if ($permlevel1 ==
'recruitmentcandidature') {
952 $permlevel1 =
'recruitmentjobposition';
957 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
962 if (!empty($this->rights->$rightsPath->$permlevel1)) {
963 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
964 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
968 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
969 return $this->rights->$rightsPath->$permlevel1->lire;
971 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
972 return $this->rights->$rightsPath->$permlevel1->creer;
974 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
975 return $this->rights->$rightsPath->$permlevel1->create;
977 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
978 return $this->rights->$rightsPath->$permlevel1->supprimer;
982 if (!empty($this->rights->$rightsPath->$permlevel1)) {
983 return $this->rights->$rightsPath->$permlevel1;
987 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
988 return $this->rights->$rightsPath->lire;
990 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
991 return $this->rights->$rightsPath->creer;
993 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
994 return $this->rights->$rightsPath->create;
996 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
997 return $this->rights->$rightsPath->supprimer;
1015 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1017 global $conf, $user, $langs;
1019 $entity = (empty($entity) ? $conf->entity : $entity);
1021 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
1023 if (empty($this->
id)) {
1024 $this->
error =
'Try to call addrights on an object user with an empty id';
1034 $module = $perms = $subperms =
'';
1037 $sql =
"SELECT module, perms, subperms";
1038 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1039 $sql .=
" WHERE id = ".((int) $rid);
1040 $sql .=
" AND entity = ".((int) $entity);
1042 $result = $this->db->query($sql);
1044 $obj = $this->db->fetch_object($result);
1047 $module = $obj->module;
1048 $perms = $obj->perms;
1049 $subperms = $obj->subperms;
1057 $whereforadd =
"id=".((int) $rid);
1059 if (!empty($subperms)) {
1060 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
1061 } elseif (!empty($perms)) {
1062 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND (subperms IS NULL or subperms = ''))";
1068 if (!empty($allmodule)) {
1069 if ($allmodule ==
'allmodules') {
1070 $whereforadd =
'allmodules';
1072 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
1073 if (!empty($allperms)) {
1074 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
1082 if (!empty($whereforadd)) {
1085 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1086 $sql .=
" WHERE entity = ".((int) $entity);
1087 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
1088 $sql .=
" AND (".$whereforadd.
")";
1091 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1092 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1094 $sqldelete .=
") AND entity = ".((int) $entity);
1095 if (!$this->db->query($sqldelete)) {
1100 $resql = $this->db->query($sql);
1102 $num = $this->db->num_rows($resql);
1105 $obj = $this->db->fetch_object($resql);
1110 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
1111 if (!$this->db->query($sql)) {
1125 if (!$error && !$notrigger) {
1126 $langs->load(
"other");
1127 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
1138 $this->db->rollback();
1141 $this->db->commit();
1158 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1160 global $conf, $user, $langs;
1164 $entity = (!empty($entity) ? $entity : $conf->entity);
1169 $module = $perms = $subperms =
'';
1173 $sql =
"SELECT module, perms, subperms";
1174 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1175 $sql .=
" WHERE id = '".$this->db->escape($rid).
"'";
1176 $sql .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1178 $result = $this->db->query($sql);
1180 $obj = $this->db->fetch_object($result);
1183 $module = $obj->module;
1184 $perms = $obj->perms;
1185 $subperms = $obj->subperms;
1193 $wherefordel =
"id=".((int) $rid);
1195 if ($subperms ==
'lire' || $subperms ==
'read') {
1196 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1198 if ($perms ==
'lire' || $perms ==
'read') {
1199 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1205 if (!empty($allmodule)) {
1206 if ($allmodule ==
'allmodules') {
1207 $wherefordel =
'allmodules';
1209 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1210 if (!empty($allperms)) {
1211 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1218 if (!empty($wherefordel)) {
1221 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1222 $sql .=
" WHERE entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1223 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1224 $sql .=
" AND (".$wherefordel.
")";
1228 if ($this->admin == 1) {
1229 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1230 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1231 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1232 $sql .=
" AND id NOT IN (358)";
1235 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1236 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1239 $sqldelete .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1241 $resql = $this->db->query($sqldelete);
1248 if (!$error && !$notrigger) {
1249 $langs->load(
"other");
1250 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1261 $this->db->rollback();
1264 $this->db->commit();
1278 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1280 $this->nb_rights = 0;
1281 $this->all_permissions_are_loaded = 0;
1282 $this->_tab_loaded = array();
1298 $alreadyloaded =
false;
1300 if (empty($forcereload)) {
1301 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1303 $alreadyloaded =
true;
1306 if (!empty($this->all_permissions_are_loaded)) {
1308 $alreadyloaded =
true;
1313 if (!isset($this->rights) || !is_object($this->rights)) {
1316 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1317 $this->rights->user =
new stdClass();
1322 if (!$alreadyloaded) {
1324 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1325 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1326 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1327 $sql .=
" WHERE r.id = ur.fk_id";
1333 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') ?
"1," :
"").$conf->entity.
")";
1337 $sql .=
" AND r.entity = ".((int) $conf->entity).
" AND ur.entity = ".((int) $conf->entity);
1339 $sql .=
" AND ur.fk_user = ".((int) $this->
id);
1340 $sql .=
" AND r.perms IS NOT NULL";
1342 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1345 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1348 $resql = $this->db->query($sql);
1350 $num = $this->db->num_rows($resql);
1353 $obj = $this->db->fetch_object($resql);
1356 $module = $obj->module;
1357 $perms = $obj->perms;
1358 $subperms = $obj->subperms;
1360 if (!empty($perms)) {
1361 if (!empty($module)) {
1362 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1363 $this->rights->$module =
new stdClass();
1365 if (!empty($subperms)) {
1366 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1367 $this->rights->$module->$perms =
new stdClass();
1369 if (empty($this->rights->$module->$perms->$subperms)) {
1372 $this->rights->$module->$perms->$subperms = 1;
1374 if (empty($this->rights->$module->$perms)) {
1377 $this->rights->$module->$perms = 1;
1384 $this->db->free($resql);
1388 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms, r.entity";
1389 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1390 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1391 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1392 $sql .=
" WHERE r.id = gr.fk_id";
1397 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1398 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1400 $sql .=
" AND r.entity = ".((int) $conf->entity);
1403 $sql .=
" AND gr.entity = ".((int) $conf->entity);
1407 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1408 $sql .=
" AND r.entity = ".((int) $conf->entity);
1411 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1412 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1413 $sql .=
" AND r.perms IS NOT NULL";
1415 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1418 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1421 $resql = $this->db->query($sql);
1423 $num = $this->db->num_rows($resql);
1426 $obj = $this->db->fetch_object($resql);
1429 $module = $obj->module;
1430 $perms = $obj->perms;
1431 $subperms = $obj->subperms;
1433 if (!empty($perms)) {
1434 if (!empty($module)) {
1435 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1436 $this->rights->$module =
new stdClass();
1438 if (!empty($subperms)) {
1439 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1440 $this->rights->$module->$perms =
new stdClass();
1442 if (empty($this->rights->$module->$perms->$subperms)) {
1445 $this->rights->$module->$perms->$subperms = 1;
1448 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1449 if (empty($this->rights->$module->$perms)) {
1452 $this->rights->$module->$perms = 1;
1460 $this->db->free($resql);
1464 if (!empty($this->admin)) {
1465 if (empty($this->rights->user->user)) {
1466 $this->rights->user->user =
new stdClass();
1468 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1469 foreach ($listofpermtotest as $permtotest) {
1470 if (empty($this->rights->user->user->$permtotest)) {
1471 $this->rights->user->user->$permtotest = 1;
1475 if (empty($this->rights->user->self)) {
1476 $this->rights->user->self =
new stdClass();
1478 $listofpermtotest = array(
'creer',
'password');
1479 foreach ($listofpermtotest as $permtotest) {
1480 if (empty($this->rights->user->self->$permtotest)) {
1481 $this->rights->user->self->$permtotest = 1;
1487 if (empty($this->rights->user->user_advance)) {
1488 $this->rights->user->user_advance =
new stdClass();
1490 $listofpermtotest = array(
'readperms',
'write');
1491 foreach ($listofpermtotest as $permtotest) {
1492 if (empty($this->rights->user->user_advance->$permtotest)) {
1493 $this->rights->user->user_advance->$permtotest = 1;
1497 if (empty($this->rights->user->self_advance)) {
1498 $this->rights->user->self_advance =
new stdClass();
1500 $listofpermtotest = array(
'readperms',
'writeperms');
1501 foreach ($listofpermtotest as $permtotest) {
1502 if (empty($this->rights->user->self_advance->$permtotest)) {
1503 $this->rights->user->self_advance->$permtotest = 1;
1507 if (empty($this->rights->user->group_advance)) {
1508 $this->rights->user->group_advance =
new stdClass();
1510 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1511 foreach ($listofpermtotest as $permtotest) {
1512 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1513 $this->rights->user->group_advance->$permtotest = 1;
1521 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1522 $this->rights->propal = $this->rights->propale;
1524 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1525 $this->rights->propale = $this->rights->propal;
1532 $this->all_permissions_are_loaded = 1;
1535 $this->_tab_loaded[$moduletag] = 1;
1552 public function getrights($moduletag =
'', $forcereload = 0)
1565 global $conf, $langs, $user;
1570 if (isset($this->statut)) {
1571 if ($this->statut == $status) {
1574 } elseif (isset($this->
status) && $this->
status == $status) {
1581 $sql =
"UPDATE ".$this->db->prefix().
"user";
1582 $sql .=
" SET statut = ".((int) $status);
1583 $sql .=
" WHERE rowid = ".((int) $this->
id);
1584 $result = $this->db->query($sql);
1586 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1589 $this->context[
'actionmsg'] =
'User '.$this->login.
' disabled';
1591 $this->context[
'actionmsg'] =
'User '.$this->login.
' enabled';
1594 $result = $this->
call_trigger(
'USER_ENABLEDISABLE', $user);
1602 $this->db->rollback();
1606 $this->statut = $status;
1607 $this->db->commit();
1624 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1625 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1636 global $conf, $langs;
1642 $this->
fetch($this->
id);
1644 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1647 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1649 if (!$error && !$this->db->query($sql)) {
1651 $this->
error = $this->db->lasterror();
1655 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1656 if (!$error && !$this->db->query($sql)) {
1658 $this->
error = $this->db->lasterror();
1662 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1663 if (!$error && !$this->db->query($sql)) {
1665 $this->
error = $this->db->lasterror();
1669 if ($this->contact_id > 0) {
1670 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1671 if (!$error && !$this->db->query($sql)) {
1673 $this->
error = $this->db->lasterror();
1682 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1688 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1689 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1690 if (!$this->db->query($sql)) {
1692 $this->
error = $this->db->lasterror();
1701 $this->db->rollback();
1706 $this->db->commit();
1709 $this->db->rollback();
1721 public function create($user, $notrigger = 0)
1723 global $conf, $langs;
1729 $this->civility_code = trim((
string) $this->civility_code);
1730 $this->login = trim((
string) $this->login);
1731 if (!isset($this->entity)) {
1732 $this->entity = $conf->entity;
1735 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1737 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1741 $langs->load(
"errors");
1742 $this->
error = $langs->trans(
"ErrorBadEMail", $this->
email);
1745 if (empty($this->login)) {
1746 $langs->load(
"errors");
1747 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1749 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1750 $langs->load(
"errors");
1751 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1762 $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).
"'";
1763 $resqltochecklogin = $this->db->query($sqltochecklogin);
1764 if ($resqltochecklogin) {
1765 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1766 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1767 $langs->load(
"errors");
1768 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1770 $this->db->rollback();
1773 $this->db->free($resqltochecklogin);
1776 if (!empty($this->
email)) {
1777 $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).
"'";
1778 $resqltochecklogin = $this->db->query($sqltochecklogin);
1779 if ($resqltochecklogin) {
1780 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1781 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1782 $langs->load(
"errors");
1783 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->
email);
1785 $this->db->rollback();
1788 $this->db->free($resqltochecklogin);
1793 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, entity)";
1794 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->db->escape($this->login).
"', '".$this->db->escape($this->ldap_sid).
"', ".((int) $this->entity).
")";
1795 $result = $this->db->query($sql);
1797 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1799 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1803 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1804 $this->db->rollback();
1809 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1810 $langs->load(
"stocks");
1812 $entrepot =
new Entrepot($this->db);
1813 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1814 $entrepot->libelle = $entrepot->label;
1815 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1816 $entrepot->statut = 1;
1817 $entrepot->country_id = $mysoc->country_id;
1819 $warehouseid = $entrepot->create($user);
1821 $this->fk_warehouse = $warehouseid;
1825 $result = $this->
update($user, 1, 1);
1827 $this->db->rollback();
1841 $this->db->commit();
1846 $this->db->rollback();
1850 $this->
error = $this->db->lasterror();
1851 $this->db->rollback();
1869 global $conf, $user, $langs;
1875 $this->civility_code = $contact->civility_code;
1876 $this->lastname = $contact->lastname;
1877 $this->firstname = $contact->firstname;
1879 $this->
email = $contact->email;
1880 $this->socialnetworks = $contact->socialnetworks;
1881 $this->office_phone = $contact->phone_pro;
1882 $this->office_fax = $contact->fax;
1883 $this->user_mobile = $contact->phone_mobile;
1884 $this->
address = $contact->address;
1885 $this->zip = $contact->zip;
1886 $this->town = $contact->town;
1888 $this->state_id = $contact->state_id;
1889 $this->country_id = $contact->country_id;
1890 $this->employee = 0;
1892 if (empty($login)) {
1893 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1894 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1896 $this->login = $login;
1901 $result = $this->
create($user, 1);
1903 $sql =
"UPDATE ".$this->db->prefix().
"user";
1904 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1905 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1906 if ($contact->socid > 0) {
1907 $sql .=
", fk_soc=".((int) $contact->socid);
1909 $sql .=
" WHERE rowid=".((int) $this->
id);
1911 $resql = $this->db->query($sql);
1913 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1915 $this->context[
'createfromcontact'] =
'createfromcontact';
1921 $this->db->rollback();
1926 $this->db->commit();
1929 $this->
error = $this->db->error();
1931 $this->db->rollback();
1936 dol_syslog(get_class($this).
"::create_from_contact - 0");
1938 $this->db->rollback();
1959 $this->civility_code = $member->civility_code;
1960 $this->lastname = $member->lastname;
1961 $this->firstname = $member->firstname;
1962 $this->gender = $member->gender;
1963 $this->
email = $member->email;
1964 $this->fk_member = $member->id;
1965 $this->
address = $member->address;
1966 $this->zip = $member->zip;
1967 $this->town = $member->town;
1969 $this->state_id = $member->state_id;
1970 $this->country_id = $member->country_id;
1971 $this->socialnetworks = $member->socialnetworks;
1973 $this->pass = $member->pass;
1974 $this->pass_crypted = $member->pass_indatabase_crypted;
1976 if (empty($login)) {
1977 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1980 $this->login = $login;
1985 $result = $this->
create($user);
1987 if (!empty($this->pass)) {
1988 $newpass = $this->
setPassword($user, $this->pass);
1989 if (is_int($newpass) && $newpass < 0) {
1992 } elseif (!empty($this->pass_crypted)) {
1993 $sql =
"UPDATE ".$this->db->prefix().
"user";
1994 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
1995 $sql .=
" WHERE rowid=".((int) $this->
id);
1997 $resql = $this->db->query($sql);
2003 if ($result > 0 && $member->socid) {
2004 $sql =
"UPDATE ".$this->db->prefix().
"user";
2005 $sql .=
" SET fk_soc=".((int) $member->socid);
2006 $sql .=
" WHERE rowid=".((int) $this->
id);
2008 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
2009 $resql = $this->db->query($sql);
2011 $this->db->commit();
2014 $this->
error = $this->db->lasterror();
2016 $this->db->rollback();
2023 $this->db->commit();
2027 $this->db->rollback();
2045 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
2046 $sql .=
" WHERE bydefault = 1";
2047 $sql .=
" AND entity = ".((int) $conf->entity);
2049 $resql = $this->db->query($sql);
2051 $num = $this->db->num_rows($resql);
2054 $row = $this->db->fetch_row($resql);
2058 $this->db->free($resql);
2062 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
2063 $result = $this->db->query($sql);
2065 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
2066 $result = $this->db->query($sql);
2086 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
2088 global $conf, $langs;
2090 $nbrowsaffected = 0;
2093 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
2096 $this->civility_code = trim((
string) $this->civility_code);
2097 $this->lastname = trim((
string) $this->lastname);
2098 $this->firstname = trim((
string) $this->firstname);
2099 $this->ref_employee = trim((
string) $this->ref_employee);
2100 $this->national_registration_number = trim((
string) $this->national_registration_number);
2101 $this->employee = ($this->employee > 0 ? $this->employee : 0);
2102 $this->login = trim((
string) $this->login);
2103 $this->gender = trim((
string) $this->gender);
2105 $this->pass = trim((
string) $this->pass);
2106 $this->api_key = trim((
string) $this->api_key);
2107 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
2108 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
2111 $this->zip = trim((
string) $this->zip);
2112 $this->town = trim((
string) $this->town);
2114 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
2115 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
2116 $this->office_phone = trim((
string) $this->office_phone);
2117 $this->office_fax = trim((
string) $this->office_fax);
2118 $this->user_mobile = trim((
string) $this->user_mobile);
2119 $this->personal_mobile = trim((
string) $this->personal_mobile);
2121 $this->personal_email = trim((
string) $this->personal_email);
2123 $this->job = trim((
string) $this->job);
2124 $this->signature = trim((
string) $this->signature);
2125 $this->note_public = trim((
string) $this->note_public);
2126 $this->note_private = trim((
string) $this->note_private);
2127 $this->openid = trim((
string) $this->openid);
2128 $this->admin = ($this->admin > 0 ? $this->admin : 0);
2130 $this->accountancy_code = trim((
string) $this->accountancy_code);
2131 $this->color = trim((
string) $this->color);
2132 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
2133 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
2135 $this->birth = empty($this->birth) ?
'' : $this->birth;
2136 $this->fk_warehouse = (int) $this->fk_warehouse;
2137 $this->fk_establishment = (int) $this->fk_establishment;
2142 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
2145 $langs->load(
"errors");
2146 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
2149 if (empty($this->login)) {
2150 $langs->load(
"errors");
2151 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
2153 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
2154 $langs->load(
"errors");
2155 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
2162 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->oldcopy->login != $this->login) {
2163 $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).
"'";
2164 $resqltochecklogin = $this->db->query($sqltochecklogin);
2165 if ($resqltochecklogin) {
2166 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2167 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2168 $langs->load(
"errors");
2169 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
2171 $this->db->rollback();
2176 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && !empty($this->email) && $this->oldcopy->email != $this->email) {
2177 $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).
"'";
2178 $resqltochecklogin = $this->db->query($sqltochecklogin);
2179 if ($resqltochecklogin) {
2180 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2181 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2182 $langs->load(
"errors");
2183 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
2185 $this->db->rollback();
2192 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2193 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
2194 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
2195 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
2196 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
2197 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
2198 $sql .=
", employee = ".(int) $this->employee;
2199 $sql .=
", login = '".$this->db->escape($this->login).
"'";
2200 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
2201 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
2202 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
2203 if (!empty($user->admin)) {
2204 $sql .=
", admin = ".(int) $this->admin;
2206 $sql .=
", address = '".$this->db->escape($this->address).
"'";
2207 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
2208 $sql .=
", town = '".$this->db->escape($this->town).
"'";
2209 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".$this->db->escape($this->state_id).
"'" :
"null");
2210 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".$this->db->escape($this->country_id).
"'" :
"null");
2211 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
2212 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
2213 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
2214 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
2215 $sql .=
", email = '".$this->db->escape($this->email).
"'";
2216 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
2217 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
2218 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2219 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2220 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2221 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2222 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2223 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2224 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2225 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2226 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2227 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2228 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2229 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2230 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".$this->db->escape($this->fk_user).
"'" :
"null");
2231 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".$this->db->escape($this->fk_user_expense_validator).
"'" :
"null");
2232 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".$this->db->escape($this->fk_user_holiday_validator).
"'" :
"null");
2233 if (isset($this->thm) || $this->thm !=
'') {
2234 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2236 if (isset($this->tjm) || $this->tjm !=
'') {
2237 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2239 if (isset($this->salary) || $this->salary !=
'') {
2240 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2242 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2243 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2245 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2246 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2247 $sql .=
", entity = ".((int) $this->entity);
2249 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2250 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2251 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2252 $sql .=
", fk_establishment = ".($this->fk_establishment > 0 ? $this->fk_establishment :
"null");
2253 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2254 $sql .=
" WHERE rowid = ".((int) $this->
id);
2256 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2257 $resql = $this->db->query($sql);
2259 $nbrowsaffected += $this->db->affected_rows($resql);
2262 if (!empty($this->pass)) {
2263 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2265 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2266 if (is_int($result) && $result < 0) {
2273 if ($this->fk_member > 0) {
2274 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2275 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2276 $resql = $this->db->query($sql);
2278 $this->
error = $this->db->error();
2279 $this->db->rollback();
2284 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2285 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2286 $resql = $this->db->query($sql);
2288 $this->
error = $this->db->error();
2289 $this->db->rollback();
2293 if ($nbrowsaffected) {
2294 if ($this->fk_member > 0 && !$nosyncmember) {
2295 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2297 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2302 $result = $adh->fetch($this->fk_member);
2305 $adh->civility_code = $this->civility_code;
2306 $adh->firstname = $this->firstname;
2307 $adh->lastname = $this->lastname;
2308 $adh->login = $this->login;
2309 $adh->gender = $this->gender;
2310 $adh->birth = $this->birth;
2312 $adh->pass = $this->pass;
2314 $adh->address = $this->address;
2315 $adh->town = $this->town;
2316 $adh->zip = $this->zip;
2317 $adh->state_id = $this->state_id;
2318 $adh->country_id = $this->country_id;
2320 $adh->email = $this->email;
2322 $adh->socialnetworks = $this->socialnetworks;
2324 $adh->phone = $this->office_phone;
2325 $adh->phone_mobile = $this->user_mobile;
2327 $adh->default_lang = $this->lang;
2329 $adh->user_id = $this->id;
2330 $adh->user_login = $this->login;
2332 $result = $adh->update($user, 0, 1, 0);
2334 $this->
error = $adh->error;
2335 $this->errors = $adh->errors;
2336 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2339 } elseif ($result < 0) {
2340 $this->
error = $adh->error;
2341 $this->errors = $adh->errors;
2346 if ($this->contact_id > 0 && !$nosynccontact) {
2347 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2349 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2352 $tmpobj =
new Contact($this->db);
2353 $result = $tmpobj->fetch($this->contact_id);
2356 $tmpobj->civility_code = $this->civility_code;
2357 $tmpobj->firstname = $this->firstname;
2358 $tmpobj->lastname = $this->lastname;
2359 $tmpobj->login = $this->login;
2360 $tmpobj->gender = $this->gender;
2361 $tmpobj->birth = $this->birth;
2365 $tmpobj->email = $this->email;
2367 $tmpobj->socialnetworks = $this->socialnetworks;
2369 $tmpobj->phone_pro = $this->office_phone;
2370 $tmpobj->phone_mobile = $this->user_mobile;
2371 $tmpobj->fax = $this->office_fax;
2373 $tmpobj->default_lang = $this->lang;
2375 $tmpobj->address = $this->address;
2376 $tmpobj->town = $this->town;
2377 $tmpobj->zip = $this->zip;
2378 $tmpobj->state_id = $this->state_id;
2379 $tmpobj->country_id = $this->country_id;
2381 $tmpobj->user_id = $this->id;
2382 $tmpobj->user_login = $this->login;
2384 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2386 $this->
error = $tmpobj->error;
2387 $this->errors = $tmpobj->errors;
2388 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2392 $this->
error = $tmpobj->error;
2393 $this->errors = $tmpobj->errors;
2409 if (!$error && !$notrigger) {
2419 $this->db->commit();
2420 return $nbrowsaffected;
2423 $this->db->rollback();
2427 $this->
error = $this->db->lasterror();
2428 $this->db->rollback();
2447 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2448 $sql .=
" datepreviouslogin = datelastlogin,";
2449 $sql .=
" ippreviouslogin = iplastlogin,";
2450 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2451 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2452 $sql .=
" tms = tms";
2453 $sql .=
" WHERE rowid = ".((int) $this->
id);
2455 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2456 $resql = $this->db->query($sql);
2458 $this->datepreviouslogin = $this->datelastlogin;
2459 $this->datelastlogin = $now;
2460 $this->ippreviouslogin = $this->iplastlogin;
2461 $this->iplastlogin = $userremoteip;
2464 $this->
error = $this->db->lasterror().
' sql='.$sql;
2482 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2484 global $conf, $langs;
2485 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2489 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2496 $password_crypted =
null;
2498 if (empty($passwordalreadycrypted)) {
2501 $modGeneratePassClass =
'modGeneratePass'.ucfirst($conf->global->USER_PASSWORD_GENERATED);
2503 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2504 if (class_exists($modGeneratePassClass)) {
2505 $modGeneratePass =
new $modGeneratePassClass($this->db, $conf, $langs, $user);
2506 '@phan-var-force ModeleGenPassword $modGeneratePass';
2509 $modGeneratePass->WithoutAmbi = 0;
2512 $testpassword = $modGeneratePass->validatePassword($password);
2513 if (!$testpassword) {
2514 $this->
error = $modGeneratePass->error;
2522 $password_crypted =
dol_hash($password);
2526 if (!$changelater) {
2527 if (!is_object($this->oldcopy)) {
2528 $this->oldcopy = clone $this;
2533 $sql =
"UPDATE ".$this->db->prefix().
"user";
2534 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2535 $sql .=
" pass_temp = null";
2536 if (!empty($flagdelsessionsbefore)) {
2537 $sql .=
", flagdelsessionsbefore = '".$this->db->idate(
dol_now() - 5,
'gmt').
"'";
2540 $sql .=
", pass = null";
2542 $sql .=
", pass = '".$this->db->escape($password).
"'";
2544 $sql .=
" WHERE rowid = ".((int) $this->
id);
2546 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2547 $result = $this->db->query($sql);
2549 if ($this->db->affected_rows($result)) {
2550 $this->pass = $password;
2551 $this->pass_indatabase = $password;
2552 $this->pass_indatabase_crypted = (string) $password_crypted;
2554 if ($this->fk_member && !$nosyncmember) {
2555 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2560 $result = $adh->fetch($this->fk_member);
2563 $result = $adh->setPassword($user, $this->pass, (!
getDolGlobalString(
'DATABASE_PWD_ENCRYPTED') ? 0 : 1), 1);
2564 if (is_int($result) && $result < 0) {
2565 $this->
error = $adh->error;
2570 $this->
error = $adh->error;
2575 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2577 if (!$error && !$notrigger) {
2579 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2582 $this->db->rollback();
2588 $this->db->commit();
2591 $this->db->rollback();
2595 $this->db->rollback();
2602 $sql =
"UPDATE ".$this->db->prefix().
"user";
2603 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2604 $sql .=
" WHERE rowid = ".((int) $this->
id);
2606 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2607 $result = $this->db->query($sql);
2629 global $conf, $langs, $mysoc;
2630 global $dolibarr_main_url_root;
2632 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2639 $outputlangs =
new Translate(
"", $conf);
2641 if (isset($this->
conf->MAIN_LANG_DEFAULT)
2642 && $this->conf->MAIN_LANG_DEFAULT !=
'auto') {
2643 $outputlangs->getDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2646 if ($this->
conf->MAIN_LANG_DEFAULT) {
2647 $outputlangs->setDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2649 $outputlangs = $langs;
2653 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2655 $appli =
getDolGlobalString(
'MAIN_APPLICATION_TITLE', constant(
'DOL_APPLICATION_TITLE'));
2657 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2660 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2661 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2663 if (!$changelater) {
2664 $url = $urlwithroot.
'/';
2669 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2671 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2672 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2673 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2674 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2677 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2679 $mesg .= $user->getFullName($outputlangs);
2682 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2683 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.$conf->file->instance_unique_id));
2684 if (isModEnabled(
'multicompany')) {
2685 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2688 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2692 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2693 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2694 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2695 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2697 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2698 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2699 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2702 $trackid =
'use'.$this->id;
2703 $sendcontext =
'passwordreset';
2708 $conf->global->MAIN_MAIL_EMAIL_FROM,
2724 if ($mailfile->sendfile()) {
2727 $langs->trans(
"errors");
2728 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2740 return $this->error;
2753 $sql =
"SELECT url, login, pass, poste ";
2754 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2755 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2757 $resql = $this->db->query($sql);
2759 if ($this->db->num_rows($resql)) {
2760 $obj = $this->db->fetch_object($resql);
2762 $this->clicktodial_url = $obj->url;
2763 $this->clicktodial_login = $obj->login;
2764 $this->clicktodial_password = $obj->pass;
2765 $this->clicktodial_poste = $obj->poste;
2768 $this->clicktodial_loaded = 1;
2770 $this->db->free($resql);
2773 $this->
error = $this->db->error();
2789 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2790 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2792 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2794 $result = $this->db->query($sql);
2796 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2797 $sql .=
" (fk_user,url,login,pass,poste)";
2798 $sql .=
" VALUES (".$this->id;
2799 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2800 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2801 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2802 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2804 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2806 $result = $this->db->query($sql);
2808 $this->db->commit();
2811 $this->db->rollback();
2812 $this->
error = $this->db->lasterror();
2830 global $conf, $langs, $user;
2836 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2837 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2838 $sql .=
" AND fk_usergroup = ".((int) $group);
2839 $sql .=
" AND entity = ".((int) $entity);
2841 $result = $this->db->query($sql);
2843 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2844 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2846 $result = $this->db->query($sql);
2848 if (!$error && !$notrigger) {
2849 $this->context = array(
'audit' => $langs->trans(
"UserSetInGroup"),
'newgroupid' => $group);
2860 $this->db->commit();
2864 $this->db->rollback();
2868 $this->
error = $this->db->lasterror();
2869 $this->db->rollback();
2886 global $conf, $langs, $user;
2892 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2893 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2894 $sql .=
" AND fk_usergroup = ".((int) $group);
2895 if (empty($entity)) {
2896 $sql .=
" AND entity IN (0, 1)";
2898 $sql .=
" AND entity = ".((int) $entity);
2901 $result = $this->db->query($sql);
2903 if (!$error && !$notrigger) {
2904 $this->context = array(
'audit' => $langs->trans(
"UserRemovedFromGroup"),
'oldgroupid' => $group);
2915 $this->db->commit();
2918 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2919 $this->db->rollback();
2923 $this->
error = $this->db->lasterror();
2924 $this->db->rollback();
2938 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2945 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
2968 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
2970 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2971 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
2985 global $conf, $langs, $menumanager;
2986 global $dolibarr_main_demo;
2988 $infologin = $params[
'infologin'] ?? 0;
2989 $option = $params[
'option'] ??
'';
2992 if (!empty($this->photo)) {
2993 $photo =
'<div class="photointooltip floatright">';
2994 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
2996 $data[
'photo'] = $photo;
3001 $data[
'opendiv'] =
'<div class="centpercent divtooltip">';
3002 $data[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
3004 if (!empty($this->login)) {
3007 if (!empty($this->job)) {
3011 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
3012 $phonelist = array();
3013 if ($this->office_phone) {
3014 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
3016 if ($this->office_fax) {
3017 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
3019 if ($this->user_mobile) {
3020 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
3022 $data[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
3024 if (!empty($this->admin)) {
3025 $data[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
3027 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
3028 $langs->load(
"companies");
3029 $data[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
3032 if (!empty($this->socid)) {
3033 $thirdpartystatic =
new Societe($this->db);
3034 $thirdpartystatic->fetch($this->socid);
3036 if (empty($params[
'hidethirdpartylogo'])) {
3037 $companyimg =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3039 $company =
' ('.$langs->trans(
"Company").
': '.($companyimg ? $companyimg :
img_picto(
'',
'company')).
' '.
dol_string_nohtmltag($thirdpartystatic->name).
')';
3041 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
3042 $data[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
3043 $data[
'closediv'] =
'</div>';
3045 if ($infologin > 0) {
3046 $data[
'newlinelogin'] =
'<br>';
3047 $data[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
3050 $data[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.$conf->entity.
' (User entity '.$this->entity.
')';
3052 $data[
'authentication'] =
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
3053 $data[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
3054 $data[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
3055 $data[
'currenttheme'] =
'<br><b>'.$langs->trans(
"CurrentTheme").
':</b> '.
dol_string_nohtmltag($conf->theme);
3057 $data[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
3059 $data[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
3060 $data[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag($conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
3061 $data[
'layout'] =
'<br><b>'.$langs->trans(
"Layout").
':</b> '.
dol_string_nohtmltag($conf->browser->layout);
3062 $data[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
3063 if ($conf->browser->layout ==
'phone') {
3064 $data[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
3066 if (!empty($_SESSION[
"disablemodules"])) {
3067 $data[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(implode(
', ', explode(
',', $_SESSION[
"disablemodules"])));
3089 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
3091 global $langs, $hookmanager, $user;
3093 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
3104 'objecttype' => $this->element,
3105 'infologin' => $infologin,
3106 'option' => $option,
3107 'hidethirdpartylogo' => $hidethirdpartylogo,
3109 $classfortooltip =
'classfortooltip';
3112 $classfortooltip =
'classforajaxtooltip';
3113 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3120 if (!empty($this->socid)) {
3121 $thirdpartystatic =
new Societe($this->db);
3122 $thirdpartystatic->fetch($this->socid);
3123 if (empty($hidethirdpartylogo)) {
3124 $companylink =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3128 if ($infologin < 0) {
3132 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
3133 if ($option ==
'leave') {
3134 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
3137 if ($option !=
'nolink') {
3139 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3140 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3141 $add_save_lastsearch_values = 1;
3143 if ($add_save_lastsearch_values) {
3144 $url .=
'&save_lastsearch_values=1';
3148 $linkstart =
'<a href="'.$url.
'"';
3150 if (empty($notooltip)) {
3152 $langs->load(
"users");
3153 $label = $langs->trans(
"ShowUser");
3154 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
3156 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
3157 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
3159 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
3162 $linkstart .= $linkclose.
'>';
3166 $result .= (($option ==
'nolink') ?
'' : $linkstart);
3167 if ($withpictoimg) {
3168 $paddafterimage =
'';
3169 if (abs((
int) $withpictoimg) == 1) {
3170 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3173 if ($withpictoimg > 0) {
3174 $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>';
3177 $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>';
3181 if ($withpictoimg > -2 && $withpictoimg != 2) {
3183 $result .=
'<span class="nopadding usertext'.((!isset($this->
status) || $this->status) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
3185 if ($mode ==
'login') {
3191 $result .=
'</span>';
3194 $result .= (($option ==
'nolink') ?
'' : $linkend);
3197 $result .= $companylink;
3200 $hookmanager->initHooks(array(
'userdao'));
3201 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
3202 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3204 $result = $hookmanager->resPrint;
3206 $result .= $hookmanager->resPrint;
3221 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
3223 global $langs, $user;
3227 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3231 if ((!$user->hasRight(
'user',
'user',
'lire') && $this->id != $user->id)) {
3235 if ($option ==
'xxx') {
3236 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3240 if ($option ==
'nolink') {
3245 $result .= $linkstart;
3246 if ($withpictoimg) {
3247 $paddafterimage =
'';
3248 if (abs($withpictoimg) == 1) {
3249 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3252 if ($withpictoimg > 0) {
3253 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3256 $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>';
3260 $result .= $this->login;
3261 $result .= $linkend;
3274 return $this->
LibStatut(isset($this->statut) ? (
int) $this->statut : (int) $this->
status, $mode);
3290 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3293 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3294 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3295 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3296 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3299 $statusType =
'status5';
3300 if ($status == self::STATUS_ENABLED) {
3301 $statusType =
'status4';
3304 $label = $this->labelStatus[$status];
3305 $labelshort = $this->labelStatusShort[$status];
3308 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3309 $statusType =
'status3';
3310 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3312 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3313 $statusType =
'status2';
3314 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3317 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3332 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3334 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3335 $return .=
'<div class="info-box info-box-sm">';
3336 $return .=
'<span class="info-box-icon bg-infobox-action">';
3339 if (!empty($this->photo)) {
3341 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3350 $return .=
'</span>';
3351 $return .=
'<div class="info-box-content">';
3352 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3353 if (isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3354 $return .=
img_picto($langs->trans(
"SuperAdministratorDesc"),
'redstar',
'class="valignmiddle paddingright paddingleft"');
3355 } elseif ($this->admin) {
3356 $return .=
img_picto($langs->trans(
"AdministratorDesc"),
'star',
'class="valignmiddle paddingright paddingleft"');
3358 $return .=
'</span>';
3359 if ($selected >= 0) {
3360 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3362 if (property_exists($this,
'label')) {
3363 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3366 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->
email.
'</span>';
3368 if (method_exists($this,
'getLibStatut')) {
3369 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3371 $return .=
'</div>';
3372 $return .=
'</div>';
3373 $return .=
'</div>';
3397 } elseif ($mode == 1) {
3399 } elseif ($mode == 2) {
3415 global $conf, $langs;
3421 $keymodified =
false;
3430 'LDAP_FIELD_FULLNAME' =>
'fullname',
3431 'LDAP_FIELD_NAME' =>
'lastname',
3432 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3433 'LDAP_FIELD_LOGIN' =>
'login',
3434 'LDAP_FIELD_LOGIN_SAMBA' =>
'login',
3435 'LDAP_FIELD_PHONE' =>
'office_phone',
3436 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3437 'LDAP_FIELD_FAX' =>
'office_fax',
3438 'LDAP_FIELD_MAIL' =>
'email',
3439 'LDAP_FIELD_SID' =>
'ldap_sid',
3443 foreach ($ldapkey as $constname => $varname) {
3449 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->$varname != $this->oldcopy->$varname) {
3450 $keymodified =
true;
3455 foreach ($socialnetworks as $key => $value) {
3456 if (!empty($this->socialnetworks[$value[
'label']]) &&
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))) {
3457 $info[
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))] = $this->socialnetworks[$value[
'label']];
3472 if ($this->socid > 0) {
3473 $soc =
new Societe($this->db);
3474 $soc->fetch($this->socid);
3477 if ($soc->client == 1) {
3478 $info[
"businessCategory"] =
"Customers";
3480 if ($soc->client == 2) {
3481 $info[
"businessCategory"] =
"Prospects";
3483 if ($soc->fournisseur == 1) {
3484 $info[
"businessCategory"] =
"Suppliers";
3489 if (!empty($this->pass)) {
3502 if ($this->pass_indatabase_crypted &&
getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED')) {
3506 } elseif (!empty($this->pass_indatabase)) {
3518 $info[
"objectclass"][4] =
"phpgwContact";
3520 $info[
'uidnumber'] = $this->id;
3522 $info[
'phpgwTz'] = 0;
3523 $info[
'phpgwMailType'] =
'INTERNET';
3524 $info[
'phpgwMailHomeType'] =
'INTERNET';
3526 $info[
"phpgwContactTypeId"] =
'n';
3527 $info[
"phpgwContactCatId"] = 0;
3528 $info[
"phpgwContactAccess"] =
"public";
3536 $info[
"phpgwContactOwner"] = 1;
3539 $info[
"rfc822Mailbox"] = $this->email;
3541 if ($this->user_mobile) {
3542 $info[
"phpgwCellTelephoneNumber"] = $this->user_mobile;
3551 $groupslist = $usergroup->listGroupsForUser($this->
id);
3553 if (!empty($groupslist)) {
3554 foreach ($groupslist as $groupforuser) {
3561 $info[
getDolGlobalString(
'LDAP_FIELD_HOMEDIRECTORY')] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->login";
3577 global $user, $langs;
3583 $this->
ref =
'SPECIMEN';
3584 $this->specimen = 1;
3586 $this->lastname =
'DOLIBARR';
3587 $this->firstname =
'SPECIMEN';
3588 $this->gender =
'man';
3589 $this->note_public =
'This is a note public';
3590 $this->note_private =
'This is a note private';
3591 $this->
email =
'email@specimen.com';
3592 $this->personal_email =
'personalemail@specimen.com';
3593 $this->socialnetworks = array(
3594 'skype' =>
'skypepseudo',
3595 'twitter' =>
'twitterpseudo',
3596 'facebook' =>
'facebookpseudo',
3597 'linkedin' =>
'linkedinpseudo',
3599 $this->office_phone =
'0999999999';
3600 $this->office_fax =
'0999999998';
3601 $this->user_mobile =
'0999999997';
3602 $this->personal_mobile =
'0999999996';
3604 $this->login =
'dolibspec';
3605 $this->pass =
'dolibSpec+@123';
3608 $this->datec = $now;
3609 $this->datem = $now;
3611 $this->datelastlogin = $now;
3612 $this->iplastlogin =
'127.0.0.1';
3613 $this->datepreviouslogin = $now;
3614 $this->ippreviouslogin =
'127.0.0.1';
3631 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
3632 $sql .=
" u.tms as date_modification, u.entity";
3633 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3634 $sql .=
" WHERE u.rowid = ".((int) $id);
3636 $result = $this->db->query($sql);
3638 if ($this->db->num_rows($result)) {
3639 $obj = $this->db->fetch_object($result);
3641 $this->
id = $obj->rowid;
3643 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3644 $this->date_creation = $this->db->jdate($obj->datec);
3645 $this->date_modification = $this->db->jdate($obj->date_modification);
3646 $this->entity = $obj->entity;
3649 $this->db->free($result);
3663 $sql =
"SELECT count(mc.email) as nb";
3664 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3665 $sql .=
" WHERE mc.email = '".$this->db->escape($this->
email).
"'";
3666 $sql .=
" AND mc.statut NOT IN (-1,0)";
3668 $resql = $this->db->query($sql);
3670 $obj = $this->db->fetch_object($resql);
3673 $this->db->free($resql);
3676 $this->
error = $this->db->error();
3693 $sql =
"SELECT count(rowid) as nb";
3694 $sql .=
" FROM ".$this->db->prefix().
"user";
3695 if ($option ==
'superadmin') {
3696 $sql .=
" WHERE entity = 0";
3698 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3699 if ($limitTo ==
'active') {
3700 $sql .=
" AND statut = 1";
3704 $sql .=
" AND admin = ".(int) $admin;
3707 $resql = $this->db->query($sql);
3709 $obj = $this->db->fetch_object($resql);
3710 $nb = (int) $obj->nb;
3712 $this->db->free($resql);
3715 $this->
error = $this->db->lasterror();
3731 global $user, $conf;
3736 $this->firstname = $ldapuser->$tmpvar;
3738 $this->lastname = $ldapuser->$tmpvar;
3740 $this->login = $ldapuser->$tmpvar;
3742 $this->pass = $ldapuser->$tmpvar;
3744 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3747 $this->office_phone = $ldapuser->$tmpvar;
3749 $this->user_mobile = $ldapuser->$tmpvar;
3751 $this->office_fax = $ldapuser->$tmpvar;
3753 $this->
email = $ldapuser->$tmpvar;
3754 foreach ($socialnetworks as $key => $value) {
3756 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3759 $this->ldap_sid = $ldapuser->$tmpvar;
3762 $this->job = $ldapuser->$tmpvar;
3764 $this->note_public = $ldapuser->$tmpvar;
3766 $result = $this->
update($user);
3768 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3784 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3785 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3787 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3788 $res = $this->db->query($sql);
3791 while ($rec = $this->db->fetch_array($res)) {
3792 $user =
new User($this->db);
3793 $user->fetch($rec[
'rowid']);
3813 $this->parentof = array();
3816 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3817 $sql .=
" FROM ".$this->db->prefix().
"user";
3818 $sql .=
" WHERE fk_user <> 0";
3819 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3821 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3822 $resql = $this->db->query($sql);
3824 while ($obj = $this->db->fetch_object($resql)) {
3825 $this->parentof[$obj->id_son] = $obj->id_parent;
3851 global $conf, $user;
3852 global $hookmanager;
3855 $hookmanager->initHooks(array(
'userdao'));
3857 $this->users = array();
3863 $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";
3864 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3866 $parameters = array();
3867 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3869 $sql .= $hookmanager->resPrint;
3871 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3874 $sql .=
" AND ".$filter;
3877 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3878 $resql = $this->db->query($sql);
3881 while ($obj = $this->db->fetch_object($resql)) {
3882 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3883 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3884 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3885 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3886 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3887 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3888 $this->users[$obj->rowid][
'login'] = $obj->login;
3889 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3890 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3891 $this->users[$obj->rowid][
'email'] = $obj->email;
3892 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3893 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3894 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3896 $this->users[$obj->rowid][
'fullpath'] =
'';
3897 $this->users[$obj->rowid][
'fullname'] =
'';
3898 $this->users[$obj->rowid][
'level'] = 0;
3907 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3908 foreach ($this->users as $key => $val) {
3911 $this->
error =
'ErrorLoopInHierarchy';
3917 if ($deleteafterid) {
3919 $keyfilter1 =
'^'.$deleteafterid.
'$';
3920 $keyfilter2 =
'_'.$deleteafterid.
'$';
3921 $keyfilter3 =
'^'.$deleteafterid.
'_';
3922 $keyfilter4 =
'_'.$deleteafterid.
'_';
3923 foreach (array_keys($this->users) as $key) {
3924 $fullpath = (string) $this->users[$key][
'fullpath'];
3925 if (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
3926 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath)) {
3927 unset($this->users[$key]);
3932 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
3933 $this->users =
dol_sort_array($this->users,
'fullname',
'asc', 1, 0, 1);
3937 return $this->users;
3950 $childids = array();
3952 if (isset($this->cache_childids[$this->
id])) {
3953 $childids = $this->cache_childids[$this->id];
3958 $idtoscan = $this->id;
3960 dol_syslog(
"Build childid for id = ".$idtoscan);
3961 foreach ($this->users as $id => $val) {
3963 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
3964 $childids[$val[
'id']] = $val[
'id'];
3968 $this->cache_childids[$this->id] = $childids;
3970 if ($addcurrentuser) {
3971 $childids[$this->id] = $this->id;
3991 if (!empty($this->users[$id_user][
'fullpath'])) {
3993 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
3998 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
3999 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
4001 $cursor_user = $id_user;
4003 $useridfound = array($id_user);
4004 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
4005 if (in_array($this->parentof[$cursor_user], $useridfound)) {
4006 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
4009 $useridfound[] = $this->parentof[$cursor_user];
4010 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
4011 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
4013 $cursor_user = $this->parentof[$cursor_user];
4017 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
4049 $this->nb = array();
4051 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
4052 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4053 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
4054 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
4055 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
4056 $sql .=
" AND ug.fk_user = u.rowid";
4058 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4060 $sql .=
" AND u.statut > 0";
4063 $resql = $this->db->query($sql);
4065 while ($obj = $this->db->fetch_object($resql)) {
4066 $this->nb[
"users"] = $obj->nb;
4068 $this->db->free($resql);
4072 $this->
error = $this->db->error();
4088 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4090 global $conf, $user, $langs;
4092 $langs->load(
"user");
4099 $modele =
'bluesky';
4103 $modelpath =
"core/modules/user/doc/";
4105 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4119 $user_property =
'';
4121 if (empty($rowid)) {
4125 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
4126 $sql .=
" FROM ".$this->db->prefix().
"user";
4127 $sql .=
" WHERE rowid = ".((int) $rowid);
4129 $resql = $this->db->query($sql);
4131 $nump = $this->db->num_rows($resql);
4134 $obj = $this->db->fetch_object($resql);
4136 if ($mode ==
'email') {
4137 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
4138 } elseif ($mode ==
'mobile') {
4139 $user_property = $obj->user_mobile;
4140 } elseif ($mode ==
'name') {
4144 return $user_property;
4161 global $dolibarr_main_url_root;
4164 $encodedsecurekey =
dol_hash($conf->file->instance_unique_id.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
4165 if (isModEnabled(
'multicompany')) {
4166 $entity_qr =
'&entity='.((int) $conf->entity);
4171 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
4172 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
4175 if ($typeofurl ==
'internal') {
4176 $urlwithroot = DOL_URL_ROOT;
4179 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
4195 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $entityfilter =
false)
4197 global $conf, $user;
4199 $sql =
"SELECT t.rowid";
4200 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
4202 if ($entityfilter) {
4204 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
4205 $sql .=
" WHERE t.entity IS NOT NULL";
4207 $sql .=
",".$this->db->prefix().
"usergroup_user as ug";
4208 $sql .=
" WHERE ((ug.fk_user = t.rowid";
4209 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
4210 $sql .=
" OR t.entity = 0)";
4213 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
4216 $sql .=
" WHERE 1 = 1";
4222 if ($errormessage) {
4223 $this->errors[] = $errormessage;
4224 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
4228 $sql .= $this->db->order($sortfield, $sortorder);
4230 $sql .= $this->db->plimit($limit + 1, $offset);
4235 $resql = $this->db->query($sql);
4237 $this->users = array();
4238 $num = $this->db->num_rows($resql);
4240 while ($obj = $this->db->fetch_object($resql)) {
4241 $line =
new self($this->db);
4242 $result = $line->fetch($obj->rowid);
4243 if ($result > 0 && !empty($line->id)) {
4244 $this->users[$obj->rowid] = clone $line;
4247 $this->db->free($resql);
4251 $this->errors[] = $this->db->lasterror();
4263 private $findUserIdByEmailCache;
4277 if (isset($this->findUserIdByEmailCache[$email])) {
4278 return $this->findUserIdByEmailCache[$email];
4281 $this->findUserIdByEmailCache[$email] = -1;
4283 $sql =
'SELECT rowid';
4284 $sql .=
' FROM '.$this->db->prefix().
'user';
4285 if (
getDolGlobalString(
'AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR')) {
4286 $sql .=
" WHERE email LIKE '%".$this->db->escape($this->db->escapeforlike($email)).
"%'";
4288 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4292 $resql = $this->db->query($sql);
4297 $obj = $this->db->fetch_object($resql);
4302 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4304 return $this->findUserIdByEmailCache[$email];
Class to manage members of a foundation.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
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.
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.
loadPersonalConf()
Load const values from database table user_param and set it into user->conf->XXX.
_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.
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.
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.
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
getArrayOfSocialNetworks()
Get array of social network dictionary.
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.
getUserRemoteIP()
Return the IP of remote user.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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_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.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.