40require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/commonpeople.class.php';
56 public $element =
'user';
61 public $table_element =
'user';
66 public $fk_element =
'fk_user';
71 public $picto =
'user';
110 public $civility_code;
135 public $email_oauth2;
140 public $personal_email;
145 public $socialnetworks;
160 public $office_phone;
175 public $personal_mobile;
205 public $pass_crypted;
210 public $pass_indatabase;
215 public $pass_indatabase_crypted;
259 public $fk_user_expense_validator;
264 public $fk_user_holiday_validator;
269 public $clicktodial_url;
274 public $clicktodial_login;
279 public $clicktodial_password;
284 public $clicktodial_poste;
289 public $clicktodial_loaded;
295 public $datelastlogin;
299 public $datepreviouslogin;
303 public $flagdelsessionsbefore;
311 public $ippreviouslogin;
315 public $datestartvalidity;
319 public $dateendvalidity;
339 public $all_permissions_are_loaded;
349 public $user_group_list;
354 private $_tab_loaded = array();
364 public $default_values;
369 public $lastsearch_values_tmp;
373 public $lastsearch_values;
378 public $users = array();
386 private $cache_childids;
392 public $accountancy_code_user_general;
397 public $accountancy_code;
429 public $dateemployment;
433 public $dateemploymentend;
438 public $default_c_exp_tax_cat;
443 public $ref_employee;
448 public $national_registration_number;
453 public $default_range;
458 public $fk_warehouse;
463 public $fk_establishment;
468 public $label_establishment;
479 public $usergroup_entity;
481 public $fields = array(
482 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
483 'lastname' => array(
'type' =>
'varchar(50)',
'label' =>
'Lastname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 20,
'searchall' => 1),
484 'firstname' => array(
'type' =>
'varchar(50)',
'label' =>
'Firstname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 10,
'searchall' => 1),
485 'ref_employee' => array(
'type' =>
'varchar(50)',
'label' =>
'RefEmployee',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 30,
'searchall' => 1),
486 'national_registration_number' => array(
'type' =>
'varchar(50)',
'label' =>
'NationalRegistrationNumber',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 40,
'searchall' => 1)
489 const STATUS_DISABLED = 0;
490 const STATUS_ENABLED = 1;
501 $this->ismultientitymanaged = 1;
502 $this->isextrafieldmanaged = 1;
504 $this->clicktodial_loaded = 0;
507 $this->all_permissions_are_loaded = 0;
508 $this->nb_rights = 0;
516 $this->rights->user =
new stdClass();
517 $this->rights->user->user =
new stdClass();
518 $this->rights->user->self =
new stdClass();
519 $this->rights->user->user_advance =
new stdClass();
520 $this->rights->user->self_advance =
new stdClass();
521 $this->rights->user->group_advance =
new stdClass();
538 public function fetch($id = 0, $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'', $fk_socpeople = 0, $use_email_oauth2 = 0)
543 $login = trim($login);
546 $sql =
"SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.civility as civility_code, u.birth, u.job,";
547 $sql .=
" u.email, u.email_oauth2, u.personal_email,";
548 $sql .=
" u.socialnetworks,";
549 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
550 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
551 $sql .=
" u.admin, u.login, u.note_private, u.note_public,";
552 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.api_key,";
553 $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,";
554 $sql .=
" u.statut as status, u.lang, u.entity,";
555 $sql .=
" u.datec as datec,";
556 $sql .=
" u.tms as datem,";
557 $sql .=
" u.datelastlogin as datel,";
558 $sql .=
" u.datepreviouslogin as datep,";
559 $sql .=
" u.flagdelsessionsbefore,";
560 $sql .=
" u.iplastlogin,";
561 $sql .=
" u.ippreviouslogin,";
562 $sql .=
" u.datelastpassvalidation,";
563 $sql .=
" u.datestartvalidity,";
564 $sql .=
" u.dateendvalidity,";
565 $sql .=
" u.photo as photo,";
566 $sql .=
" u.openid as openid,";
567 $sql .=
" u.accountancy_code_user_general,";
568 $sql .=
" u.accountancy_code,";
571 $sql .=
" u.salary,";
572 $sql .=
" u.salaryextra,";
573 $sql .=
" u.weeklyhours,";
575 $sql .=
" u.dateemployment, u.dateemploymentend,";
576 $sql .=
" u.fk_warehouse,";
577 $sql .=
" u.ref_ext,";
578 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
579 $sql .=
" u.national_registration_number,";
580 $sql .=
" u.ref_employee,";
581 $sql .=
" c.code as country_code, c.label as country,";
582 $sql .=
" d.code_departement as state_code, d.nom as state,";
583 $sql .=
" s.label as label_establishment, u.fk_establishment";
584 $sql .=
" FROM ".$this->db->prefix().
"user as u";
585 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as c ON u.fk_country = c.rowid";
586 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_departements as d ON u.fk_state = d.rowid";
587 $sql .=
" LEFT JOIN ".$this->db->prefix().
"establishment as s ON u.fk_establishment = s.rowid";
590 if ((!isModEnabled(
'multicompany') || !
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) && (!empty($user->entity))) {
591 $sql .=
" WHERE u.entity IN (0, ".((int)
$conf->entity).
")";
593 $sql .=
" WHERE u.entity IS NOT NULL";
597 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
598 $sql .=
" WHERE u.entity IS NOT NULL";
600 $sql .=
" WHERE u.entity IN (0, ".((int) (($entity !=
'' && $entity >= 0) ? $entity :
$conf->entity)).
")";
606 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->db->escape($login).
"')";
608 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
610 $sql .=
" AND (u.email = '".$this->db->escape($email).
"'";
611 if ($use_email_oauth2) {
612 $sql .=
" OR u.email_oauth2 = '".$this->db->escape($email).
"'";
615 } elseif ($fk_socpeople > 0) {
616 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
618 $sql .=
" AND u.rowid = ".((int) $id);
620 $sql .=
" ORDER BY u.entity ASC";
624 $sql .=
' '.$this->db->plimit(1);
627 $resql = $this->db->query($sql);
629 $num = $this->db->num_rows($resql);
631 $this->
error =
"USERDUPLICATEFOUND";
632 dol_syslog(get_class($this).
"::fetch more than 1 user found", LOG_WARNING);
634 $this->db->free($resql);
638 $obj = $this->db->fetch_object($resql);
640 $this->
id = $obj->rowid;
641 $this->
ref = $obj->rowid;
643 $this->ref_ext = $obj->ref_ext;
645 $this->ldap_sid = $obj->ldap_sid;
646 $this->civility_code = $obj->civility_code;
647 $this->lastname = $obj->lastname;
648 $this->firstname = $obj->firstname;
649 $this->ref_employee = $obj->ref_employee;
650 $this->national_registration_number = $obj->national_registration_number;
652 $this->employee = $obj->employee;
654 $this->login = $obj->login;
655 $this->gender = $obj->gender;
656 $this->birth = $this->db->jdate($obj->birth);
657 $this->pass_indatabase = $obj->pass;
658 $this->pass_indatabase_crypted = $obj->pass_crypted;
659 $this->pass = $obj->pass;
660 $this->pass_temp = $obj->pass_temp;
663 $this->
address = $obj->address;
664 $this->zip = $obj->zip;
665 $this->town = $obj->town;
667 $this->country_id = $obj->country_id;
668 $this->country_code = $obj->country_id ? $obj->country_code :
'';
671 $this->state_id = $obj->state_id;
672 $this->state_code = $obj->state_code;
673 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
675 $this->office_phone = $obj->office_phone;
676 $this->office_fax = $obj->office_fax;
677 $this->user_mobile = $obj->user_mobile;
678 $this->personal_mobile = $obj->personal_mobile;
679 $this->
email = $obj->email;
680 $this->email_oauth2 = $obj->email_oauth2;
681 $this->personal_email = $obj->personal_email;
682 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
684 $this->job = $obj->job;
685 $this->signature = $obj->signature;
686 $this->admin = $obj->admin;
687 $this->note_public = $obj->note_public;
688 $this->note_private = $obj->note_private;
690 $this->statut = $obj->status;
691 $this->
status = $obj->status;
693 $this->photo = $obj->photo;
694 $this->openid = $obj->openid;
695 $this->lang = $obj->lang;
696 $this->entity = $obj->entity;
698 $this->accountancy_code_user_general = $obj->accountancy_code_user_general;
699 $this->accountancy_code = $obj->accountancy_code;
701 $this->thm = $obj->thm;
702 $this->tjm = $obj->tjm;
703 $this->salary = $obj->salary;
704 $this->salaryextra = $obj->salaryextra;
705 $this->weeklyhours = $obj->weeklyhours;
706 $this->color = $obj->color;
707 $this->dateemployment = $this->db->jdate($obj->dateemployment);
708 $this->dateemploymentend = $this->db->jdate($obj->dateemploymentend);
710 $this->datec = $this->db->jdate($obj->datec);
711 $this->datem = $this->db->jdate($obj->datem);
712 $this->datelastlogin = $this->db->jdate($obj->datel);
713 $this->datepreviouslogin = $this->db->jdate($obj->datep);
714 $this->flagdelsessionsbefore = $this->db->jdate($obj->flagdelsessionsbefore,
'gmt');
715 $this->iplastlogin = $obj->iplastlogin;
716 $this->ippreviouslogin = $obj->ippreviouslogin;
717 $this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
718 $this->dateendvalidity = $this->db->jdate($obj->dateendvalidity);
720 $this->socid = $obj->fk_soc;
721 $this->contact_id = $obj->fk_socpeople;
722 $this->fk_member = $obj->fk_member;
723 $this->fk_user = $obj->fk_user;
724 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
725 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
727 $this->default_range = $obj->default_range;
728 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
729 $this->fk_warehouse = $obj->fk_warehouse;
730 $this->fk_establishment = $obj->fk_establishment;
731 $this->label_establishment = $obj->label_establishment;
735 if (!isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
743 $this->db->free($resql);
745 $this->
error =
"USERNOTFOUND";
746 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
748 $this->db->free($resql);
752 $this->
error = $this->db->lasterror();
757 if ($loadpersonalconf) {
763 $this->
error = $this->db->lasterror();
782 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
783 $sql .=
" WHERE fk_user = ".((int) $this->
id);
784 $sql .=
" AND entity = ".((int)
$conf->entity);
786 $resql = $this->db->query($sql);
788 $num = $this->db->num_rows($resql);
791 $obj = $this->db->fetch_object($resql);
792 $p = (!empty($obj->param) ? $obj->param :
'');
794 $this->
conf->$p = $obj->value;
798 $this->db->free($resql);
802 $this->
error = $this->db->lasterror();
819 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
822 $result = $defaultValues->fetchAll(
'',
'', 0, 0,
'(t.user_id:in:0,'.$this->
id.
') AND (entity:in:'.(isset($this->entity) ? $this->entity :
$conf->entity).
','.
$conf->entity.
')');
825 if (!is_array($result) && $result < 0) {
829 } elseif (count($result) > 0) {
830 foreach ($result as $defval) {
831 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
832 $pagewithoutquerystring = $defval->page;
835 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
836 $pagewithoutquerystring = $reg[1];
837 $pagequeries = $reg[2];
839 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
843 if (!empty($this->default_values)) {
844 foreach ($this->default_values as $a => $b) {
845 foreach ($b as $c => $d) {
846 krsort($this->default_values[$a][$c]);
865 public function hasRight($module, $permlevel1, $permlevel2 =
'')
868 $moduletomoduletouse = array(
869 'compta' =>
'comptabilite',
870 'contract' =>
'contrat',
871 'member' =>
'adherent',
873 'order' =>
'commande',
874 'produit' =>
'product',
875 'project' =>
'projet',
876 'propale' =>
'propal',
877 'shipping' =>
'expedition',
878 'task' =>
'task@projet',
879 'fichinter' =>
'ficheinter',
880 'inventory' =>
'stock',
881 'invoice' =>
'facture',
882 'invoice_supplier' =>
'fournisseur',
883 'order_supplier' =>
'fournisseur',
884 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
885 'skill@hrm' =>
'all@hrm',
886 'job@hrm' =>
'all@hrm',
887 'position@hrm' =>
'all@hrm',
888 'facturerec' =>
'facture',
889 'margins' =>
'margin',
892 if (!empty($moduletomoduletouse[$module])) {
893 $module = $moduletomoduletouse[$module];
896 $moduleRightsMapping = array(
897 'product' =>
'produit',
898 'margin' =>
'margins',
899 'comptabilite' =>
'compta'
902 $rightsPath = $module;
903 if (!empty($moduleRightsMapping[$rightsPath])) {
904 $rightsPath = $moduleRightsMapping[$rightsPath];
908 $tmp = explode(
'@', $rightsPath, 2);
909 if (!empty($tmp[1])) {
910 if (strpos($module,
'@') !==
false) {
913 if ($tmp[0] != $tmp[1]) {
915 $rightsPath = $tmp[1];
916 $permlevel2 = $permlevel1;
917 $permlevel1 = $tmp[0];
920 $rightsPath = $tmp[1];
930 if (!isModEnabled($module)) {
935 if (!empty($this->socid)) {
936 if ($module ==
'societe' && ($permlevel1 ==
'creer' || $permlevel1 ==
'write')) {
939 if ($module ==
'societe' && $permlevel1 ==
'client' && $permlevel2 ==
'voir') {
942 if ($module ==
'societe' && $permlevel1 ==
'export') {
945 if ($module ==
'societe' && ($permlevel1 ==
'supprimer' || $permlevel1 ==
'delete')) {
951 if ($permlevel1 ==
'propale') {
952 $permlevel1 =
'propal';
954 if ($permlevel1 ==
'member') {
955 $permlevel1 =
'adherent';
957 if ($permlevel1 ==
'recruitmentcandidature') {
958 $permlevel1 =
'recruitmentjobposition';
963 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
968 if (!empty($this->rights->$rightsPath->$permlevel1)) {
969 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
970 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
974 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
975 return $this->rights->$rightsPath->$permlevel1->lire;
977 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
978 return $this->rights->$rightsPath->$permlevel1->creer;
980 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
981 return $this->rights->$rightsPath->$permlevel1->create;
983 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
984 return $this->rights->$rightsPath->$permlevel1->supprimer;
988 if (!empty($this->rights->$rightsPath->$permlevel1)) {
989 return $this->rights->$rightsPath->$permlevel1;
993 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
994 return $this->rights->$rightsPath->lire;
996 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
997 return $this->rights->$rightsPath->creer;
999 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
1000 return $this->rights->$rightsPath->create;
1002 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
1003 return $this->rights->$rightsPath->supprimer;
1021 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1023 global $conf, $user, $langs;
1025 $entity = (empty($entity) ?
$conf->entity : $entity);
1027 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
1029 if (empty($this->
id)) {
1030 $this->
error =
'Try to call addrights on an object user with an empty id';
1040 $module = $perms = $subperms =
'';
1043 $sql =
"SELECT module, perms, subperms";
1044 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1045 $sql .=
" WHERE id = ".((int) $rid);
1046 $sql .=
" AND entity = ".((int) $entity);
1048 $result = $this->db->query($sql);
1050 $obj = $this->db->fetch_object($result);
1053 $module = $obj->module;
1054 $perms = $obj->perms;
1055 $subperms = $obj->subperms;
1063 $whereforadd =
"id=".((int) $rid);
1065 if (!empty($subperms)) {
1066 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
1067 } elseif (!empty($perms)) {
1068 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND (subperms IS NULL or subperms = ''))";
1074 if (!empty($allmodule)) {
1075 if ($allmodule ==
'allmodules') {
1076 $whereforadd =
'allmodules';
1078 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
1079 if (!empty($allperms)) {
1080 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
1088 if (!empty($whereforadd)) {
1091 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1092 $sql .=
" WHERE entity = ".((int) $entity);
1093 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
1094 $sql .=
" AND (".$whereforadd.
")";
1097 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1098 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1100 $sqldelete .=
") AND entity = ".((int) $entity);
1101 if (!$this->db->query($sqldelete)) {
1106 $resql = $this->db->query($sql);
1108 $num = $this->db->num_rows($resql);
1111 $obj = $this->db->fetch_object($resql);
1116 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
1117 if (!$this->db->query($sql)) {
1131 if (!$error && !$notrigger) {
1132 $langs->load(
"other");
1133 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
1144 $this->db->rollback();
1147 $this->db->commit();
1164 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1166 global $conf, $user, $langs;
1170 $entity = (!empty($entity) ? $entity :
$conf->entity);
1175 $module = $perms = $subperms =
'';
1179 $sql =
"SELECT module, perms, subperms";
1180 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1181 $sql .=
" WHERE id = '".$this->db->escape($rid).
"'";
1182 $sql .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1184 $result = $this->db->query($sql);
1186 $obj = $this->db->fetch_object($result);
1189 $module = $obj->module;
1190 $perms = $obj->perms;
1191 $subperms = $obj->subperms;
1199 $wherefordel =
"id=".((int) $rid);
1201 if ($subperms ==
'lire' || $subperms ==
'read') {
1202 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1204 if ($perms ==
'lire' || $perms ==
'read') {
1205 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1211 if (!empty($allmodule)) {
1212 if ($allmodule ==
'allmodules') {
1213 $wherefordel =
'allmodules';
1215 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1216 if (!empty($allperms)) {
1217 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1224 if (!empty($wherefordel)) {
1227 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1228 $sql .=
" WHERE entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1229 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1230 $sql .=
" AND (".$wherefordel.
")";
1234 if ($this->admin == 1) {
1235 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1236 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1237 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1238 $sql .=
" AND id NOT IN (358)";
1241 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1242 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1245 $sqldelete .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1247 $resql = $this->db->query($sqldelete);
1254 if (!$error && !$notrigger) {
1255 $langs->load(
"other");
1256 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1267 $this->db->rollback();
1270 $this->db->commit();
1284 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1286 $this->nb_rights = 0;
1287 $this->all_permissions_are_loaded = 0;
1288 $this->_tab_loaded = array();
1304 $alreadyloaded =
false;
1306 if (empty($forcereload)) {
1307 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1309 $alreadyloaded =
true;
1312 if (!empty($this->all_permissions_are_loaded)) {
1314 $alreadyloaded =
true;
1319 if (!isset($this->rights) || !is_object($this->rights)) {
1322 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1323 $this->rights->user =
new stdClass();
1328 if (!$alreadyloaded) {
1330 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1331 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1332 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1333 $sql .=
" WHERE r.id = ur.fk_id";
1339 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') ?
"1," :
"").
$conf->entity.
")";
1343 $sql .=
" AND r.entity = ".((int)
$conf->entity).
" AND ur.entity = ".((int)
$conf->entity);
1345 $sql .=
" AND ur.fk_user = ".((int) $this->
id);
1346 $sql .=
" AND r.perms IS NOT NULL";
1348 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1351 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1354 $resql = $this->db->query($sql);
1356 $num = $this->db->num_rows($resql);
1359 $obj = $this->db->fetch_object($resql);
1362 $module = $obj->module;
1363 $perms = $obj->perms;
1364 $subperms = $obj->subperms;
1366 if (!empty($perms)) {
1367 if (!empty($module)) {
1368 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1369 $this->rights->$module =
new stdClass();
1371 if (!empty($subperms)) {
1372 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1373 $this->rights->$module->$perms =
new stdClass();
1375 if (empty($this->rights->$module->$perms->$subperms)) {
1378 $this->rights->$module->$perms->$subperms = 1;
1380 if (empty($this->rights->$module->$perms)) {
1383 $this->rights->$module->$perms = 1;
1390 $this->db->free($resql);
1394 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms, r.entity";
1395 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1396 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1397 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1398 $sql .=
" WHERE r.id = gr.fk_id";
1403 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1404 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1406 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1409 $sql .=
" AND gr.entity = ".((int)
$conf->entity);
1413 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1414 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1417 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1418 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1419 $sql .=
" AND r.perms IS NOT NULL";
1421 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1424 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1427 $resql = $this->db->query($sql);
1429 $num = $this->db->num_rows($resql);
1432 $obj = $this->db->fetch_object($resql);
1435 $module = $obj->module;
1436 $perms = $obj->perms;
1437 $subperms = $obj->subperms;
1439 if (!empty($perms)) {
1440 if (!empty($module)) {
1441 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1442 $this->rights->$module =
new stdClass();
1444 if (!empty($subperms)) {
1445 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1446 $this->rights->$module->$perms =
new stdClass();
1448 if (empty($this->rights->$module->$perms->$subperms)) {
1451 $this->rights->$module->$perms->$subperms = 1;
1454 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1455 if (empty($this->rights->$module->$perms)) {
1458 $this->rights->$module->$perms = 1;
1466 $this->db->free($resql);
1470 if (!empty($this->admin)) {
1471 if (empty($this->rights->user->user)) {
1472 $this->rights->user->user =
new stdClass();
1474 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1475 foreach ($listofpermtotest as $permtotest) {
1476 if (empty($this->rights->user->user->$permtotest)) {
1477 $this->rights->user->user->$permtotest = 1;
1481 if (empty($this->rights->user->self)) {
1482 $this->rights->user->self =
new stdClass();
1484 $listofpermtotest = array(
'creer',
'password');
1485 foreach ($listofpermtotest as $permtotest) {
1486 if (empty($this->rights->user->self->$permtotest)) {
1487 $this->rights->user->self->$permtotest = 1;
1493 if (empty($this->rights->user->user_advance)) {
1494 $this->rights->user->user_advance =
new stdClass();
1496 $listofpermtotest = array(
'readperms',
'write');
1497 foreach ($listofpermtotest as $permtotest) {
1498 if (empty($this->rights->user->user_advance->$permtotest)) {
1499 $this->rights->user->user_advance->$permtotest = 1;
1503 if (empty($this->rights->user->self_advance)) {
1504 $this->rights->user->self_advance =
new stdClass();
1506 $listofpermtotest = array(
'readperms',
'writeperms');
1507 foreach ($listofpermtotest as $permtotest) {
1508 if (empty($this->rights->user->self_advance->$permtotest)) {
1509 $this->rights->user->self_advance->$permtotest = 1;
1513 if (empty($this->rights->user->group_advance)) {
1514 $this->rights->user->group_advance =
new stdClass();
1516 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1517 foreach ($listofpermtotest as $permtotest) {
1518 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1519 $this->rights->user->group_advance->$permtotest = 1;
1527 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1528 $this->rights->propal = $this->rights->propale;
1530 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1531 $this->rights->propale = $this->rights->propal;
1538 $this->all_permissions_are_loaded = 1;
1541 $this->_tab_loaded[$moduletag] = 1;
1558 public function getrights($moduletag =
'', $forcereload = 0)
1571 global $conf, $langs, $user;
1576 if (isset($this->statut)) {
1577 if ($this->statut == $status) {
1580 } elseif (isset($this->
status) && $this->
status == $status) {
1587 $sql =
"UPDATE ".$this->db->prefix().
"user";
1588 $sql .=
" SET statut = ".((int) $status);
1589 $sql .=
" WHERE rowid = ".((int) $this->
id);
1590 $result = $this->db->query($sql);
1592 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1595 $this->context[
'actionmsg'] =
'User '.$this->login.
' disabled';
1597 $this->context[
'actionmsg'] =
'User '.$this->login.
' enabled';
1600 $result = $this->
call_trigger(
'USER_ENABLEDISABLE', $user);
1608 $this->db->rollback();
1612 $this->statut = $status;
1613 $this->db->commit();
1630 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1631 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1642 global $conf, $langs;
1648 $this->
fetch($this->
id);
1650 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1653 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1655 if (!$error && !$this->db->query($sql)) {
1657 $this->
error = $this->db->lasterror();
1661 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1662 if (!$error && !$this->db->query($sql)) {
1664 $this->
error = $this->db->lasterror();
1668 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1669 if (!$error && !$this->db->query($sql)) {
1671 $this->
error = $this->db->lasterror();
1675 if ($this->contact_id > 0) {
1676 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1677 if (!$error && !$this->db->query($sql)) {
1679 $this->
error = $this->db->lasterror();
1688 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1694 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1695 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1696 if (!$this->db->query($sql)) {
1698 $this->
error = $this->db->lasterror();
1707 $this->db->rollback();
1712 $this->db->commit();
1715 $this->db->rollback();
1727 public function create($user, $notrigger = 0)
1729 global $conf, $langs;
1735 $this->civility_code = trim((
string) $this->civility_code);
1736 $this->login = trim((
string) $this->login);
1737 if (!isset($this->entity)) {
1738 $this->entity =
$conf->entity;
1740 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1742 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1746 $langs->load(
"errors");
1747 $this->
error = $langs->trans(
"ErrorBadEMail", $this->
email);
1750 if (empty($this->login)) {
1751 $langs->load(
"errors");
1752 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1754 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1755 $langs->load(
"errors");
1756 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1767 $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).
"'";
1768 $resqltochecklogin = $this->db->query($sqltochecklogin);
1769 if ($resqltochecklogin) {
1770 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1771 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1772 $langs->load(
"errors");
1773 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1775 $this->db->rollback();
1778 $this->db->free($resqltochecklogin);
1781 if (!empty($this->
email)) {
1782 $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).
"'";
1783 $resqltochecklogin = $this->db->query($sqltochecklogin);
1784 if ($resqltochecklogin) {
1785 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1786 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1787 $langs->load(
"errors");
1788 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->
email);
1790 $this->db->rollback();
1793 $this->db->free($resqltochecklogin);
1798 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, entity)";
1799 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->db->escape($this->login).
"', '".$this->db->escape($this->ldap_sid).
"', ".((int) $this->entity).
")";
1800 $result = $this->db->query($sql);
1802 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1804 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1808 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1809 $this->db->rollback();
1814 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1815 $langs->load(
"stocks");
1817 $entrepot =
new Entrepot($this->db);
1818 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1819 $entrepot->libelle = $entrepot->label;
1820 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1821 $entrepot->statut = 1;
1822 $entrepot->country_id = $mysoc->country_id;
1824 $warehouseid = $entrepot->create($user);
1826 $this->fk_warehouse = $warehouseid;
1830 $result = $this->
update($user, 1, 1);
1832 $this->db->rollback();
1846 $this->db->commit();
1851 $this->db->rollback();
1855 $this->
error = $this->db->lasterror();
1856 $this->db->rollback();
1874 global $conf, $user, $langs;
1880 $this->civility_code = $contact->civility_code;
1881 $this->lastname = $contact->lastname;
1882 $this->firstname = $contact->firstname;
1884 $this->
email = $contact->email;
1885 $this->socialnetworks = $contact->socialnetworks;
1886 $this->office_phone = $contact->phone_pro;
1887 $this->office_fax = $contact->fax;
1888 $this->user_mobile = $contact->phone_mobile;
1889 $this->
address = $contact->address;
1890 $this->zip = $contact->zip;
1891 $this->town = $contact->town;
1893 $this->state_id = $contact->state_id;
1894 $this->country_id = $contact->country_id;
1895 $this->employee = 0;
1897 if (empty($login)) {
1898 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1899 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1901 $this->login = $login;
1906 $result = $this->
create($user, 1);
1908 $sql =
"UPDATE ".$this->db->prefix().
"user";
1909 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1910 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1911 if ($contact->socid > 0) {
1912 $sql .=
", fk_soc=".((int) $contact->socid);
1914 $sql .=
" WHERE rowid=".((int) $this->
id);
1916 $resql = $this->db->query($sql);
1918 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1920 $this->context[
'createfromcontact'] =
'createfromcontact';
1926 $this->db->rollback();
1931 $this->db->commit();
1934 $this->
error = $this->db->error();
1936 $this->db->rollback();
1941 dol_syslog(get_class($this).
"::create_from_contact - 0");
1943 $this->db->rollback();
1964 $this->civility_code = $member->civility_code;
1965 $this->lastname = $member->lastname;
1966 $this->firstname = $member->firstname;
1967 $this->gender = $member->gender;
1968 $this->
email = $member->email;
1969 $this->fk_member = $member->id;
1970 $this->
address = $member->address;
1971 $this->zip = $member->zip;
1972 $this->town = $member->town;
1974 $this->state_id = $member->state_id;
1975 $this->country_id = $member->country_id;
1976 $this->socialnetworks = $member->socialnetworks;
1978 $this->pass = $member->pass;
1979 $this->pass_crypted = $member->pass_indatabase_crypted;
1981 if (empty($login)) {
1982 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1985 $this->login = $login;
1990 $result = $this->
create($user);
1992 if (!empty($this->pass)) {
1993 $newpass = $this->
setPassword($user, $this->pass);
1994 if (is_int($newpass) && $newpass < 0) {
1997 } elseif (!empty($this->pass_crypted)) {
1998 $sql =
"UPDATE ".$this->db->prefix().
"user";
1999 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
2000 $sql .=
" WHERE rowid=".((int) $this->
id);
2002 $resql = $this->db->query($sql);
2008 if ($result > 0 && $member->socid) {
2009 $sql =
"UPDATE ".$this->db->prefix().
"user";
2010 $sql .=
" SET fk_soc=".((int) $member->socid);
2011 $sql .=
" WHERE rowid=".((int) $this->
id);
2013 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
2014 $resql = $this->db->query($sql);
2016 $this->db->commit();
2019 $this->
error = $this->db->lasterror();
2021 $this->db->rollback();
2028 $this->db->commit();
2032 $this->db->rollback();
2050 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
2051 $sql .=
" WHERE bydefault = 1";
2052 $sql .=
" AND entity = ".((int)
$conf->entity);
2054 $resql = $this->db->query($sql);
2056 $num = $this->db->num_rows($resql);
2059 $row = $this->db->fetch_row($resql);
2063 $this->db->free($resql);
2067 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
2068 $result = $this->db->query($sql);
2070 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
2071 $result = $this->db->query($sql);
2091 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
2093 global $conf, $langs;
2095 $nbrowsaffected = 0;
2098 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
2101 $this->civility_code = trim((
string) $this->civility_code);
2102 $this->lastname = trim((
string) $this->lastname);
2103 $this->firstname = trim((
string) $this->firstname);
2104 $this->ref_employee = trim((
string) $this->ref_employee);
2105 $this->national_registration_number = trim((
string) $this->national_registration_number);
2106 $this->employee = ($this->employee > 0 ? $this->employee : 0);
2107 $this->login = trim((
string) $this->login);
2108 $this->gender = trim((
string) $this->gender);
2110 $this->pass = trim((
string) $this->pass);
2111 $this->api_key = trim((
string) $this->api_key);
2112 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
2113 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
2116 $this->zip = trim((
string) $this->zip);
2117 $this->town = trim((
string) $this->town);
2119 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
2120 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
2121 $this->office_phone = trim((
string) $this->office_phone);
2122 $this->office_fax = trim((
string) $this->office_fax);
2123 $this->user_mobile = trim((
string) $this->user_mobile);
2124 $this->personal_mobile = trim((
string) $this->personal_mobile);
2126 $this->personal_email = trim((
string) $this->personal_email);
2128 $this->job = trim((
string) $this->job);
2129 $this->signature = trim((
string) $this->signature);
2130 $this->note_public = trim((
string) $this->note_public);
2131 $this->note_private = trim((
string) $this->note_private);
2132 $this->openid = trim((
string) $this->openid);
2133 $this->admin = ($this->admin > 0 ? $this->admin : 0);
2135 $this->accountancy_code_user_general = trim((
string) $this->accountancy_code_user_general);
2136 $this->accountancy_code = trim((
string) $this->accountancy_code);
2137 $this->color = trim((
string) $this->color);
2138 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
2139 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
2141 $this->birth = empty($this->birth) ?
'' : $this->birth;
2142 $this->fk_warehouse = (int) $this->fk_warehouse;
2143 $this->fk_establishment = (int) $this->fk_establishment;
2148 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
2151 $langs->load(
"errors");
2152 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
2155 if (empty($this->login)) {
2156 $langs->load(
"errors");
2157 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
2159 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
2160 $langs->load(
"errors");
2161 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
2168 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->oldcopy->login != $this->login) {
2169 $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).
"'";
2170 $resqltochecklogin = $this->db->query($sqltochecklogin);
2171 if ($resqltochecklogin) {
2172 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2173 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2174 $langs->load(
"errors");
2175 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
2177 $this->db->rollback();
2182 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && !empty($this->email) && $this->oldcopy->email != $this->email) {
2183 $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).
"'";
2184 $resqltochecklogin = $this->db->query($sqltochecklogin);
2185 if ($resqltochecklogin) {
2186 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2187 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2188 $langs->load(
"errors");
2189 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
2191 $this->db->rollback();
2198 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2199 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
2200 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
2201 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
2202 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
2203 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
2204 $sql .=
", employee = ".(int) $this->employee;
2205 $sql .=
", login = '".$this->db->escape($this->login).
"'";
2206 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
2207 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
2208 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
2209 if (!empty($user->admin)) {
2210 $sql .=
", admin = ".(int) $this->admin;
2212 $sql .=
", address = '".$this->db->escape($this->address).
"'";
2213 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
2214 $sql .=
", town = '".$this->db->escape($this->town).
"'";
2215 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".$this->db->escape($this->state_id).
"'" :
"null");
2216 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".$this->db->escape($this->country_id).
"'" :
"null");
2217 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
2218 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
2219 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
2220 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
2221 $sql .=
", email = '".$this->db->escape($this->email).
"'";
2222 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
2223 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
2224 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2225 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2226 $sql .=
", accountancy_code_user_general = '".$this->db->escape($this->accountancy_code_user_general).
"'";
2227 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2228 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2229 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2230 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2231 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2232 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2233 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2234 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2235 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2236 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2237 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".$this->db->escape($this->fk_user).
"'" :
"null");
2238 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".$this->db->escape($this->fk_user_expense_validator).
"'" :
"null");
2239 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".$this->db->escape($this->fk_user_holiday_validator).
"'" :
"null");
2240 if (isset($this->thm) || $this->thm !=
'') {
2241 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2243 if (isset($this->tjm) || $this->tjm !=
'') {
2244 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2246 if (isset($this->salary) || $this->salary !=
'') {
2247 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2249 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2250 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2252 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2253 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2254 $sql .=
", entity = ".((int) $this->entity);
2256 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2257 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2258 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2259 $sql .=
", fk_establishment = ".($this->fk_establishment > 0 ? $this->fk_establishment :
"null");
2260 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2261 $sql .=
" WHERE rowid = ".((int) $this->
id);
2263 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2264 $resql = $this->db->query($sql);
2266 $nbrowsaffected += $this->db->affected_rows($resql);
2269 if (!empty($this->pass)) {
2270 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2272 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2273 if (is_int($result) && $result < 0) {
2280 if ($this->fk_member > 0) {
2281 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2282 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2283 $resql = $this->db->query($sql);
2285 $this->
error = $this->db->error();
2286 $this->db->rollback();
2291 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2292 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2293 $resql = $this->db->query($sql);
2295 $this->
error = $this->db->error();
2296 $this->db->rollback();
2300 if ($nbrowsaffected) {
2301 if ($this->fk_member > 0 && !$nosyncmember) {
2302 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2304 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2309 $result = $adh->fetch($this->fk_member);
2312 $adh->civility_code = $this->civility_code;
2313 $adh->firstname = $this->firstname;
2314 $adh->lastname = $this->lastname;
2315 $adh->login = $this->login;
2316 $adh->gender = $this->gender;
2317 $adh->birth = $this->birth;
2319 $adh->pass = $this->pass;
2321 $adh->address = $this->address;
2322 $adh->town = $this->town;
2323 $adh->zip = $this->zip;
2324 $adh->state_id = $this->state_id;
2325 $adh->country_id = $this->country_id;
2327 $adh->email = $this->email;
2329 $adh->socialnetworks = $this->socialnetworks;
2331 $adh->phone = $this->office_phone;
2332 $adh->phone_mobile = $this->user_mobile;
2334 $adh->default_lang = $this->lang;
2336 $adh->user_id = $this->id;
2337 $adh->user_login = $this->login;
2339 $result = $adh->update($user, 0, 1, 0);
2341 $this->
error = $adh->error;
2342 $this->errors = $adh->errors;
2343 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2346 } elseif ($result < 0) {
2347 $this->
error = $adh->error;
2348 $this->errors = $adh->errors;
2353 if ($this->contact_id > 0 && !$nosynccontact) {
2354 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2356 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2359 $tmpobj =
new Contact($this->db);
2360 $result = $tmpobj->fetch($this->contact_id);
2363 $tmpobj->civility_code = $this->civility_code;
2364 $tmpobj->firstname = $this->firstname;
2365 $tmpobj->lastname = $this->lastname;
2366 $tmpobj->login = $this->login;
2367 $tmpobj->gender = $this->gender;
2368 $tmpobj->birth = $this->birth;
2372 $tmpobj->email = $this->email;
2374 $tmpobj->socialnetworks = $this->socialnetworks;
2376 $tmpobj->phone_pro = $this->office_phone;
2377 $tmpobj->phone_mobile = $this->user_mobile;
2378 $tmpobj->fax = $this->office_fax;
2380 $tmpobj->default_lang = $this->lang;
2382 $tmpobj->address = $this->address;
2383 $tmpobj->town = $this->town;
2384 $tmpobj->zip = $this->zip;
2385 $tmpobj->state_id = $this->state_id;
2386 $tmpobj->country_id = $this->country_id;
2388 $tmpobj->user_id = $this->id;
2389 $tmpobj->user_login = $this->login;
2391 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2393 $this->
error = $tmpobj->error;
2394 $this->errors = $tmpobj->errors;
2395 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2399 $this->
error = $tmpobj->error;
2400 $this->errors = $tmpobj->errors;
2416 if (!$error && !$notrigger) {
2426 $this->db->commit();
2427 return $nbrowsaffected;
2430 $this->db->rollback();
2434 $this->
error = $this->db->lasterror();
2435 $this->db->rollback();
2454 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2455 $sql .=
" datepreviouslogin = datelastlogin,";
2456 $sql .=
" ippreviouslogin = iplastlogin,";
2457 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2458 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2459 $sql .=
" tms = tms";
2460 $sql .=
" WHERE rowid = ".((int) $this->
id);
2462 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2463 $resql = $this->db->query($sql);
2465 $this->datepreviouslogin = $this->datelastlogin;
2466 $this->datelastlogin = $now;
2467 $this->ippreviouslogin = $this->iplastlogin;
2468 $this->iplastlogin = $userremoteip;
2471 $this->
error = $this->db->lasterror().
' sql='.$sql;
2489 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2491 global $conf, $langs;
2492 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2496 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2503 $password_crypted =
null;
2505 if (empty($passwordalreadycrypted)) {
2508 $modGeneratePassClass =
'modGeneratePass'.ucfirst(
$conf->global->USER_PASSWORD_GENERATED);
2510 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2511 if (class_exists($modGeneratePassClass)) {
2512 $modGeneratePass =
new $modGeneratePassClass($this->db,
$conf, $langs, $user);
2513 '@phan-var-force ModeleGenPassword $modGeneratePass';
2516 $modGeneratePass->WithoutAmbi = 0;
2519 $testpassword = $modGeneratePass->validatePassword($password);
2520 if (!$testpassword) {
2521 $this->
error = $modGeneratePass->error;
2529 $password_crypted =
dol_hash($password);
2533 if (!$changelater) {
2534 if (!is_object($this->oldcopy)) {
2535 $this->oldcopy = clone $this;
2542 $sql =
"UPDATE ".$this->db->prefix().
"user";
2543 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2544 $sql .=
" pass_temp = null";
2545 if (!empty($flagdelsessionsbefore)) {
2546 $sql .=
", flagdelsessionsbefore = '".$this->db->idate($now - 5,
'gmt').
"'";
2549 $sql .=
", pass = null";
2551 $sql .=
", pass = '".$this->db->escape($password).
"'";
2553 $sql .=
" WHERE rowid = ".((int) $this->
id);
2555 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2556 $result = $this->db->query($sql);
2558 if ($this->db->affected_rows($result)) {
2559 $this->pass = $password;
2560 $this->pass_indatabase = $password;
2561 $this->pass_indatabase_crypted = (string) $password_crypted;
2563 if ($this->fk_member && !$nosyncmember) {
2564 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2569 $result = $adh->fetch($this->fk_member);
2572 $result = $adh->setPassword($user, $this->pass, (!
getDolGlobalString(
'DATABASE_PWD_ENCRYPTED') ? 0 : 1), 1);
2573 if (is_int($result) && $result < 0) {
2574 $this->
error = $adh->error;
2579 $this->
error = $adh->error;
2584 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2587 $user->context[
'audit'] =
'login='.$user->login;
2588 if (!empty($flagdelsessionsbefore)) {
2589 $user->context[
'audit'] .=
" - flagdelsessionsbefore set to '".$this->db->idate($now - 5,
'gmt').
"'";
2592 if (!$error && !$notrigger) {
2594 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2597 $this->db->rollback();
2603 $this->db->commit();
2606 $this->db->rollback();
2610 $this->db->rollback();
2617 $sql =
"UPDATE ".$this->db->prefix().
"user";
2618 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2619 $sql .=
" WHERE rowid = ".((int) $this->
id);
2621 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2622 $result = $this->db->query($sql);
2644 global $conf, $langs, $mysoc;
2645 global $dolibarr_main_url_root;
2647 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2656 if (isset($this->
conf->MAIN_LANG_DEFAULT)
2657 && $this->conf->MAIN_LANG_DEFAULT !=
'auto') {
2658 $outputlangs->getDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2661 if ($this->
conf->MAIN_LANG_DEFAULT) {
2662 $outputlangs->setDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2664 $outputlangs = $langs;
2668 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2670 $appli =
getDolGlobalString(
'MAIN_APPLICATION_TITLE', constant(
'DOL_APPLICATION_TITLE'));
2672 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2675 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2676 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2678 if (!$changelater) {
2679 $url = $urlwithroot.
'/';
2684 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2686 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2687 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2688 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2689 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2692 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2694 $mesg .= $user->getFullName($outputlangs);
2697 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2698 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.
$conf->file->instance_unique_id));
2699 if (isModEnabled(
'multicompany')) {
2700 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2703 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2707 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2708 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2709 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2710 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2712 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2713 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2714 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2717 $trackid =
'use'.$this->id;
2718 $sendcontext =
'passwordreset';
2723 $conf->global->MAIN_MAIL_EMAIL_FROM,
2739 if ($mailfile->sendfile()) {
2742 $langs->trans(
"errors");
2743 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2755 return $this->error;
2768 $sql =
"SELECT url, login, pass, poste ";
2769 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2770 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2772 $resql = $this->db->query($sql);
2774 if ($this->db->num_rows($resql)) {
2775 $obj = $this->db->fetch_object($resql);
2777 $this->clicktodial_url = $obj->url;
2778 $this->clicktodial_login = $obj->login;
2779 $this->clicktodial_password = $obj->pass;
2780 $this->clicktodial_poste = $obj->poste;
2783 $this->clicktodial_loaded = 1;
2785 $this->db->free($resql);
2788 $this->
error = $this->db->error();
2804 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2805 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2807 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2809 $result = $this->db->query($sql);
2811 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2812 $sql .=
" (fk_user,url,login,pass,poste)";
2813 $sql .=
" VALUES (".$this->id;
2814 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2815 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2816 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2817 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2819 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2821 $result = $this->db->query($sql);
2823 $this->db->commit();
2826 $this->db->rollback();
2827 $this->
error = $this->db->lasterror();
2845 global $conf, $langs, $user;
2851 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2852 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2853 $sql .=
" AND fk_usergroup = ".((int) $group);
2854 $sql .=
" AND entity = ".((int) $entity);
2856 $result = $this->db->query($sql);
2858 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2859 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2861 $result = $this->db->query($sql);
2863 if (!$error && !$notrigger) {
2864 $this->context = array(
'audit' => $langs->trans(
"UserSetInGroup"),
'newgroupid' => $group);
2875 $this->db->commit();
2879 $this->db->rollback();
2883 $this->
error = $this->db->lasterror();
2884 $this->db->rollback();
2901 global $conf, $langs, $user;
2907 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2908 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2909 $sql .=
" AND fk_usergroup = ".((int) $group);
2910 if (empty($entity)) {
2911 $sql .=
" AND entity IN (0, 1)";
2913 $sql .=
" AND entity = ".((int) $entity);
2916 $result = $this->db->query($sql);
2918 if (!$error && !$notrigger) {
2919 $this->context = array(
'audit' => $langs->trans(
"UserRemovedFromGroup"),
'oldgroupid' => $group);
2930 $this->db->commit();
2933 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2934 $this->db->rollback();
2938 $this->
error = $this->db->lasterror();
2939 $this->db->rollback();
2953 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2960 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
2983 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
2985 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2986 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
3000 global $conf, $langs, $menumanager;
3001 global $dolibarr_main_demo;
3003 $infologin = $params[
'infologin'] ?? 0;
3004 $option = $params[
'option'] ??
'';
3007 if (!empty($this->photo)) {
3008 $photo =
'<div class="photointooltip floatright">';
3009 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
3011 $data[
'photo'] = $photo;
3016 $data[
'opendiv'] =
'<div class="centpercent divtooltip">';
3017 $data[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
3019 if (!empty($this->login)) {
3022 if (!empty($this->job)) {
3026 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
3027 $phonelist = array();
3028 if ($this->office_phone) {
3029 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
3031 if ($this->office_fax) {
3032 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
3034 if ($this->user_mobile) {
3035 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
3037 $data[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
3039 if (!empty($this->admin)) {
3040 $data[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
3042 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
3043 $langs->load(
"companies");
3044 $data[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
3047 if (!empty($this->socid)) {
3048 $thirdpartystatic =
new Societe($this->db);
3049 $thirdpartystatic->fetch($this->socid);
3051 if (empty($params[
'hidethirdpartylogo'])) {
3052 $companyimg =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3054 $company =
' ('.$langs->trans(
"Company").
': '.($companyimg ? $companyimg :
img_picto(
'',
'company')).
' '.
dol_string_nohtmltag($thirdpartystatic->name).
')';
3056 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
3057 $data[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
3058 $data[
'closediv'] =
'</div>';
3060 if ($infologin > 0) {
3061 $data[
'newlinelogin'] =
'<br>';
3062 $data[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
3065 $data[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.
$conf->entity.
' (User entity '.$this->entity.
')';
3067 $data[
'authentication'] =
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
3068 $data[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
3069 $data[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
3072 $data[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
3074 $data[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
3075 $data[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag(
$conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
3077 $data[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
3078 if (
$conf->browser->layout ==
'phone') {
3079 $data[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
3081 if (!empty($_SESSION[
"disablemodules"])) {
3082 $data[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(implode(
', ', explode(
',', $_SESSION[
"disablemodules"])));
3104 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
3106 global $langs, $hookmanager, $user;
3108 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
3119 'objecttype' => $this->element,
3120 'infologin' => $infologin,
3121 'option' => $option,
3122 'hidethirdpartylogo' => $hidethirdpartylogo,
3124 $classfortooltip =
'classfortooltip';
3127 $classfortooltip =
'classforajaxtooltip';
3128 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3135 if (!empty($this->socid)) {
3136 $thirdpartystatic =
new Societe($this->db);
3137 $thirdpartystatic->fetch($this->socid);
3138 if (empty($hidethirdpartylogo)) {
3139 $companylink =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3143 if ($infologin < 0) {
3147 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
3148 if ($option ==
'leave') {
3149 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
3152 if ($option !=
'nolink') {
3154 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3155 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3156 $add_save_lastsearch_values = 1;
3158 if ($add_save_lastsearch_values) {
3159 $url .=
'&save_lastsearch_values=1';
3163 $linkstart =
'<a href="'.$url.
'"';
3165 if (empty($notooltip)) {
3167 $langs->load(
"users");
3168 $label = $langs->trans(
"ShowUser");
3169 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
3171 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
3172 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
3174 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
3177 $linkstart .= $linkclose.
'>';
3181 $result .= (($option ==
'nolink') ?
'' : $linkstart);
3182 if ($withpictoimg) {
3183 $paddafterimage =
'';
3184 if (abs((
int) $withpictoimg) == 1) {
3185 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3188 if ($withpictoimg > 0) {
3189 $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>';
3192 $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>';
3196 if ($withpictoimg > -2 && $withpictoimg != 2) {
3198 $result .=
'<span class="nopadding usertext'.((!isset($this->
status) || $this->status) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
3200 if ($mode ==
'login') {
3206 $result .=
'</span>';
3209 $result .= (($option ==
'nolink') ?
'' : $linkend);
3212 $result .= $companylink;
3215 $hookmanager->initHooks(array(
'userdao'));
3216 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
3217 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3219 $result = $hookmanager->resPrint;
3221 $result .= $hookmanager->resPrint;
3236 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
3238 global $langs, $user;
3242 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3246 if ((!$user->hasRight(
'user',
'user',
'lire') && $this->id != $user->id)) {
3250 if ($option ==
'xxx') {
3251 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3255 if ($option ==
'nolink') {
3260 $result .= $linkstart;
3261 if ($withpictoimg) {
3262 $paddafterimage =
'';
3263 if (abs($withpictoimg) == 1) {
3264 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3267 if ($withpictoimg > 0) {
3268 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3271 $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>';
3275 $result .= $this->login;
3276 $result .= $linkend;
3289 return $this->
LibStatut(isset($this->statut) ? (
int) $this->statut : (int) $this->
status, $mode);
3305 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3308 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3309 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3310 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3311 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3314 $statusType =
'status5';
3315 if ($status == self::STATUS_ENABLED) {
3316 $statusType =
'status4';
3319 $label = $this->labelStatus[$status];
3320 $labelshort = $this->labelStatusShort[$status];
3323 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3324 $statusType =
'status3';
3325 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3327 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3328 $statusType =
'status2';
3329 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3332 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3347 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3349 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3350 $return .=
'<div class="info-box info-box-sm">';
3351 $return .=
'<span class="info-box-icon bg-infobox-action">';
3354 if (!empty($this->photo)) {
3356 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3365 $return .=
'</span>';
3366 $return .=
'<div class="info-box-content">';
3367 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3368 if (isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3369 $return .=
img_picto($langs->trans(
"SuperAdministratorDesc"),
'redstar',
'class="valignmiddle paddingright paddingleft"');
3370 } elseif ($this->admin) {
3371 $return .=
img_picto($langs->trans(
"AdministratorDesc"),
'star',
'class="valignmiddle paddingright paddingleft"');
3373 $return .=
'</span>';
3374 if ($selected >= 0) {
3375 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3377 if (property_exists($this,
'label')) {
3378 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3381 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->
email.
'</span>';
3383 if (method_exists($this,
'getLibStatut')) {
3384 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3386 $return .=
'</div>';
3387 $return .=
'</div>';
3388 $return .=
'</div>';
3412 } elseif ($mode == 1) {
3414 } elseif ($mode == 2) {
3430 global $conf, $langs;
3436 $keymodified =
false;
3445 'LDAP_FIELD_FULLNAME' =>
'fullname',
3446 'LDAP_FIELD_NAME' =>
'lastname',
3447 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3448 'LDAP_FIELD_LOGIN' =>
'login',
3449 'LDAP_FIELD_LOGIN_SAMBA' =>
'login',
3450 'LDAP_FIELD_PHONE' =>
'office_phone',
3451 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3452 'LDAP_FIELD_FAX' =>
'office_fax',
3453 'LDAP_FIELD_MAIL' =>
'email',
3454 'LDAP_FIELD_SID' =>
'ldap_sid',
3458 foreach ($ldapkey as $constname => $varname) {
3464 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->$varname != $this->oldcopy->$varname) {
3465 $keymodified =
true;
3470 foreach ($socialnetworks as $key => $value) {
3471 if (!empty($this->socialnetworks[$value[
'label']]) &&
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))) {
3472 $info[
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))] = $this->socialnetworks[$value[
'label']];
3487 if ($this->socid > 0) {
3488 $soc =
new Societe($this->db);
3489 $soc->fetch($this->socid);
3492 if ($soc->client == 1) {
3493 $info[
"businessCategory"] =
"Customers";
3495 if ($soc->client == 2) {
3496 $info[
"businessCategory"] =
"Prospects";
3498 if ($soc->fournisseur == 1) {
3499 $info[
"businessCategory"] =
"Suppliers";
3504 if (!empty($this->pass)) {
3517 if ($this->pass_indatabase_crypted &&
getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED')) {
3521 } elseif (!empty($this->pass_indatabase)) {
3533 $info[
"objectclass"][4] =
"phpgwContact";
3535 $info[
'uidnumber'] = $this->id;
3537 $info[
'phpgwTz'] = 0;
3538 $info[
'phpgwMailType'] =
'INTERNET';
3539 $info[
'phpgwMailHomeType'] =
'INTERNET';
3541 $info[
"phpgwContactTypeId"] =
'n';
3542 $info[
"phpgwContactCatId"] = 0;
3543 $info[
"phpgwContactAccess"] =
"public";
3551 $info[
"phpgwContactOwner"] = 1;
3554 $info[
"rfc822Mailbox"] = $this->email;
3556 if ($this->user_mobile) {
3557 $info[
"phpgwCellTelephoneNumber"] = $this->user_mobile;
3566 $groupslist = $usergroup->listGroupsForUser($this->
id);
3568 if (!empty($groupslist)) {
3569 foreach ($groupslist as $groupforuser) {
3576 $info[
getDolGlobalString(
'LDAP_FIELD_HOMEDIRECTORY')] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->login";
3592 global $user, $langs;
3598 $this->
ref =
'SPECIMEN';
3599 $this->specimen = 1;
3601 $this->lastname =
'DOLIBARR';
3602 $this->firstname =
'SPECIMEN';
3603 $this->gender =
'man';
3604 $this->note_public =
'This is a note public';
3605 $this->note_private =
'This is a note private';
3606 $this->
email =
'email@specimen.com';
3607 $this->personal_email =
'personalemail@specimen.com';
3608 $this->socialnetworks = array(
3609 'skype' =>
'skypepseudo',
3610 'twitter' =>
'twitterpseudo',
3611 'facebook' =>
'facebookpseudo',
3612 'linkedin' =>
'linkedinpseudo',
3614 $this->office_phone =
'0999999999';
3615 $this->office_fax =
'0999999998';
3616 $this->user_mobile =
'0999999997';
3617 $this->personal_mobile =
'0999999996';
3619 $this->login =
'dolibspec';
3620 $this->pass =
'dolibSpec+@123';
3623 $this->datec = $now;
3624 $this->datem = $now;
3626 $this->datelastlogin = $now;
3627 $this->iplastlogin =
'127.0.0.1';
3628 $this->datepreviouslogin = $now;
3629 $this->ippreviouslogin =
'127.0.0.1';
3646 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
3647 $sql .=
" u.tms as date_modification, u.entity";
3648 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3649 $sql .=
" WHERE u.rowid = ".((int) $id);
3651 $result = $this->db->query($sql);
3653 if ($this->db->num_rows($result)) {
3654 $obj = $this->db->fetch_object($result);
3656 $this->
id = $obj->rowid;
3658 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3659 $this->date_creation = $this->db->jdate($obj->datec);
3660 $this->date_modification = $this->db->jdate($obj->date_modification);
3661 $this->entity = $obj->entity;
3664 $this->db->free($result);
3678 $sql =
"SELECT count(mc.email) as nb";
3679 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3680 $sql .=
" WHERE mc.email = '".$this->db->escape($this->
email).
"'";
3681 $sql .=
" AND mc.statut NOT IN (-1,0)";
3683 $resql = $this->db->query($sql);
3685 $obj = $this->db->fetch_object($resql);
3688 $this->db->free($resql);
3691 $this->
error = $this->db->error();
3708 $sql =
"SELECT count(rowid) as nb";
3709 $sql .=
" FROM ".$this->db->prefix().
"user";
3710 if ($option ==
'superadmin') {
3711 $sql .=
" WHERE entity = 0";
3713 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3714 if ($limitTo ==
'active') {
3715 $sql .=
" AND statut = 1";
3719 $sql .=
" AND admin = ".(int) $admin;
3722 $resql = $this->db->query($sql);
3724 $obj = $this->db->fetch_object($resql);
3725 $nb = (int) $obj->nb;
3727 $this->db->free($resql);
3730 $this->
error = $this->db->lasterror();
3746 global $user, $conf;
3751 $this->firstname = $ldapuser->$tmpvar;
3753 $this->lastname = $ldapuser->$tmpvar;
3755 $this->login = $ldapuser->$tmpvar;
3757 $this->pass = $ldapuser->$tmpvar;
3759 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3762 $this->office_phone = $ldapuser->$tmpvar;
3764 $this->user_mobile = $ldapuser->$tmpvar;
3766 $this->office_fax = $ldapuser->$tmpvar;
3768 $this->
email = $ldapuser->$tmpvar;
3769 foreach ($socialnetworks as $key => $value) {
3771 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3774 $this->ldap_sid = $ldapuser->$tmpvar;
3777 $this->job = $ldapuser->$tmpvar;
3779 $this->note_public = $ldapuser->$tmpvar;
3781 $result = $this->
update($user);
3783 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3799 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3800 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3802 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3803 $res = $this->db->query($sql);
3806 while ($rec = $this->db->fetch_array($res)) {
3807 $user =
new User($this->db);
3808 $user->fetch($rec[
'rowid']);
3828 $this->parentof = array();
3831 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3832 $sql .=
" FROM ".$this->db->prefix().
"user";
3833 $sql .=
" WHERE fk_user <> 0";
3834 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3836 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3837 $resql = $this->db->query($sql);
3839 while ($obj = $this->db->fetch_object($resql)) {
3840 $this->parentof[$obj->id_son] = $obj->id_parent;
3866 global $conf, $user;
3867 global $hookmanager;
3870 $hookmanager->initHooks(array(
'userdao'));
3872 $this->users = array();
3878 $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";
3879 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3881 $parameters = array();
3882 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3884 $sql .= $hookmanager->resPrint;
3886 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3889 $sql .=
" AND ".$filter;
3892 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3893 $resql = $this->db->query($sql);
3896 while ($obj = $this->db->fetch_object($resql)) {
3897 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3898 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3899 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3900 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3901 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3902 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3903 $this->users[$obj->rowid][
'login'] = $obj->login;
3904 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3905 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3906 $this->users[$obj->rowid][
'email'] = $obj->email;
3907 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3908 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3909 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3911 $this->users[$obj->rowid][
'fullpath'] =
'';
3912 $this->users[$obj->rowid][
'fullname'] =
'';
3913 $this->users[$obj->rowid][
'level'] = 0;
3922 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3923 foreach ($this->users as $key => $val) {
3926 $this->
error =
'ErrorLoopInHierarchy';
3932 if ($deleteafterid) {
3934 $keyfilter1 =
'^'.$deleteafterid.
'$';
3935 $keyfilter2 =
'_'.$deleteafterid.
'$';
3936 $keyfilter3 =
'^'.$deleteafterid.
'_';
3937 $keyfilter4 =
'_'.$deleteafterid.
'_';
3938 foreach (array_keys($this->users) as $key) {
3939 $fullpath = (string) $this->users[$key][
'fullpath'];
3940 if (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
3941 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath)) {
3942 unset($this->users[$key]);
3947 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
3948 $this->users =
dol_sort_array($this->users,
'fullname',
'asc', 1, 0, 1);
3952 return $this->users;
3965 $childids = array();
3967 if (isset($this->cache_childids[$this->
id])) {
3968 $childids = $this->cache_childids[$this->id];
3973 $idtoscan = $this->id;
3975 dol_syslog(
"Build childid for id = ".$idtoscan);
3976 foreach ($this->users as $id => $val) {
3978 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
3979 $childids[$val[
'id']] = $val[
'id'];
3983 $this->cache_childids[$this->id] = $childids;
3985 if ($addcurrentuser) {
3986 $childids[$this->id] = $this->id;
4006 if (!empty($this->users[$id_user][
'fullpath'])) {
4008 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
4013 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
4014 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
4016 $cursor_user = $id_user;
4018 $useridfound = array($id_user);
4019 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
4020 if (in_array($this->parentof[$cursor_user], $useridfound)) {
4021 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
4024 $useridfound[] = $this->parentof[$cursor_user];
4025 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
4026 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
4028 $cursor_user = $this->parentof[$cursor_user];
4032 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
4064 $this->nb = array();
4066 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
4067 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4068 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
4069 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
4070 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
4071 $sql .=
" AND ug.fk_user = u.rowid";
4073 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4075 $sql .=
" AND u.statut > 0";
4078 $resql = $this->db->query($sql);
4080 while ($obj = $this->db->fetch_object($resql)) {
4081 $this->nb[
"users"] = $obj->nb;
4083 $this->db->free($resql);
4087 $this->
error = $this->db->error();
4103 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4105 global $conf, $user, $langs;
4107 $langs->load(
"user");
4114 $modele =
'bluesky';
4118 $modelpath =
"core/modules/user/doc/";
4120 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4134 $user_property =
'';
4136 if (empty($rowid)) {
4140 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
4141 $sql .=
" FROM ".$this->db->prefix().
"user";
4142 $sql .=
" WHERE rowid = ".((int) $rowid);
4144 $resql = $this->db->query($sql);
4146 $nump = $this->db->num_rows($resql);
4149 $obj = $this->db->fetch_object($resql);
4151 if ($mode ==
'email') {
4152 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
4153 } elseif ($mode ==
'mobile') {
4154 $user_property = $obj->user_mobile;
4155 } elseif ($mode ==
'name') {
4159 return $user_property;
4176 global $dolibarr_main_url_root;
4179 $encodedsecurekey =
dol_hash(
$conf->file->instance_unique_id.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
4180 if (isModEnabled(
'multicompany')) {
4181 $entity_qr =
'&entity='.((int)
$conf->entity);
4186 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
4187 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
4190 if ($typeofurl ==
'internal') {
4191 $urlwithroot = DOL_URL_ROOT;
4194 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
4210 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $entityfilter =
false)
4212 global $conf, $user;
4214 $sql =
"SELECT t.rowid";
4215 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
4217 if ($entityfilter) {
4219 if (!empty($user->admin) && empty($user->entity) &&
$conf->entity == 1) {
4220 $sql .=
" WHERE t.entity IS NOT NULL";
4222 $sql .=
",".$this->db->prefix().
"usergroup_user as ug";
4223 $sql .=
" WHERE ((ug.fk_user = t.rowid";
4224 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
4225 $sql .=
" OR t.entity = 0)";
4228 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
4231 $sql .=
" WHERE 1 = 1";
4237 if ($errormessage) {
4238 $this->errors[] = $errormessage;
4239 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
4243 $sql .= $this->db->order($sortfield, $sortorder);
4245 $sql .= $this->db->plimit($limit + 1, $offset);
4250 $resql = $this->db->query($sql);
4252 $this->users = array();
4253 $num = $this->db->num_rows($resql);
4255 while ($obj = $this->db->fetch_object($resql)) {
4256 $line =
new self($this->db);
4257 $result = $line->fetch($obj->rowid);
4258 if ($result > 0 && !empty($line->id)) {
4259 $this->users[$obj->rowid] = clone $line;
4262 $this->db->free($resql);
4266 $this->errors[] = $this->db->lasterror();
4278 private $findUserIdByEmailCache;
4292 if (isset($this->findUserIdByEmailCache[$email])) {
4293 return $this->findUserIdByEmailCache[$email];
4296 $this->findUserIdByEmailCache[$email] = -1;
4298 $sql =
'SELECT rowid';
4299 $sql .=
' FROM '.$this->db->prefix().
'user';
4300 if (
getDolGlobalString(
'AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR')) {
4301 $sql .=
" WHERE email LIKE '%".$this->db->escape($this->db->escapeforlike($email)).
"%'";
4303 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4307 $resql = $this->db->query($sql);
4312 $obj = $this->db->fetch_object($resql);
4317 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4319 return $this->findUserIdByEmailCache[$email];
4330 if (empty($fromId) || empty($toId)) {
4337 $sqlDelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
4338 $sqlDelete .=
" WHERE fk_user = ".((int) $toId);
4340 dol_syslog(get_class($this).
"::clone_rights (delete default permissions)", LOG_DEBUG);
4342 if (!$this->db->query($sqlDelete)) {
4343 $this->db->rollback();
4348 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id)";
4349 $sql .=
" SELECT entity, ".((int) $toId).
", fk_id";
4350 $sql .=
" FROM ".$this->db->prefix().
"user_rights src";
4351 $sql .=
" WHERE fk_user = ".((int) $fromId);
4352 $sql .=
" AND NOT EXISTS (";
4353 $sql .=
" SELECT 1";
4354 $sql .=
" FROM ".$this->db->prefix().
"user_rights dest";
4355 $sql .=
" WHERE dest.entity = src.entity";
4356 $sql .=
" AND dest.fk_user = ".((int) $toId);
4357 $sql .=
" AND dest.fk_id = src.fk_id";
4360 dol_syslog(get_class($this).
"::clone_rights", LOG_DEBUG);
4363 if (!$this->db->query($sql)) {
4364 $this->db->rollback();
4368 $this->db->commit();
4385 $type = $this->table_element;
4388 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4389 $categorystatic =
new Categorie($this->db);
4391 $sql =
"INSERT INTO ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]).
" (fk_categorie, fk_user)";
4392 $sql .=
" SELECT fk_categorie, ".((int) $toId).
" FROM ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]);
4393 $sql .=
" WHERE fk_user = ".((int) $fromId);
4395 if (!$this->db->query($sql)) {
4396 $this->
error = $this->db->lasterror();
4397 $this->db->rollback();
4401 $this->db->commit();
Class to manage members of a foundation.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage categories.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
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.
cloneCategories($fromId, $toId, $type='user')
Copy related categories to another object.
getAllChildIds($addcurrentuser=0)
Return list of all child user ids in hierarchy (all sublevels).
initAsSpecimen()
Initialise an instance with random values.
setPassword($user, $password='', $changelater=0, $notrigger=0, $nosyncmember=0, $passwordalreadycrypted=0, $flagdelsessionsbefore=1)
Change password of a user.
getNomUrl($withpictoimg=0, $option='', $infologin=0, $notooltip=0, $maxlen=24, $hidethirdpartylogo=0, $mode='', $morecss='', $save_lastsearch_value=-1)
Return a HTML link to the user card (with optionally the picto) Use this->id,this->lastname,...
clearrights()
Clear all permissions array of user.
update_clicktodial()
Update clicktodial info.
cloneRights($fromId, $toId)
Clone permissions of user.
getLibStatut($mode=0)
Return the label of the status of user (active, inactive)
create_from_member($member, $login='')
Create a user into database from a member object.
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.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
getArrayOfSocialNetworks()
Get array of social network dictionary.
dol_print_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)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.