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 if ($entity !=
'' && $entity == 0) {
601 $sql .=
" WHERE u.entity = 0";
603 $sql .=
" WHERE u.entity IN (0, ".((int) ($entity > 0 ? $entity :
$conf->entity)).
")";
610 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->db->escape($login).
"')";
612 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
614 $sql .=
" AND (u.email = '".$this->db->escape($email).
"'";
615 if ($use_email_oauth2) {
616 $sql .=
" OR u.email_oauth2 = '".$this->db->escape($email).
"'";
619 } elseif ($fk_socpeople > 0) {
620 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
622 $sql .=
" AND u.rowid = ".((int) $id);
624 $sql .=
" ORDER BY u.entity ASC";
628 $sql .=
' '.$this->db->plimit(1);
631 $resql = $this->db->query($sql);
633 $num = $this->db->num_rows($resql);
635 $this->
error =
"USERDUPLICATEFOUND";
636 dol_syslog(get_class($this).
"::fetch more than 1 user found", LOG_WARNING);
638 $this->db->free($resql);
642 $obj = $this->db->fetch_object($resql);
644 $this->
id = $obj->rowid;
645 $this->
ref = $obj->rowid;
647 $this->ref_ext = $obj->ref_ext;
649 $this->ldap_sid = $obj->ldap_sid;
650 $this->civility_code = $obj->civility_code;
651 $this->lastname = $obj->lastname;
652 $this->firstname = $obj->firstname;
653 $this->ref_employee = $obj->ref_employee;
654 $this->national_registration_number = $obj->national_registration_number;
656 $this->employee = $obj->employee;
658 $this->login = $obj->login;
659 $this->gender = $obj->gender;
660 $this->birth = $this->db->jdate($obj->birth);
661 $this->pass_indatabase = $obj->pass;
662 $this->pass_indatabase_crypted = $obj->pass_crypted;
663 $this->pass = $obj->pass;
664 $this->pass_temp = $obj->pass_temp;
667 $this->
address = $obj->address;
668 $this->zip = $obj->zip;
669 $this->town = $obj->town;
671 $this->country_id = $obj->country_id;
672 $this->country_code = $obj->country_id ? $obj->country_code :
'';
675 $this->state_id = $obj->state_id;
676 $this->state_code = $obj->state_code;
677 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
679 $this->office_phone = $obj->office_phone;
680 $this->office_fax = $obj->office_fax;
681 $this->user_mobile = $obj->user_mobile;
682 $this->personal_mobile = $obj->personal_mobile;
683 $this->
email = $obj->email;
684 $this->email_oauth2 = $obj->email_oauth2;
685 $this->personal_email = $obj->personal_email;
686 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
688 $this->job = $obj->job;
689 $this->signature = $obj->signature;
690 $this->admin = $obj->admin;
691 $this->note_public = $obj->note_public;
692 $this->note_private = $obj->note_private;
694 $this->statut = $obj->status;
695 $this->
status = $obj->status;
697 $this->photo = $obj->photo;
698 $this->openid = $obj->openid;
699 $this->lang = $obj->lang;
700 $this->entity = $obj->entity;
702 $this->accountancy_code_user_general = $obj->accountancy_code_user_general;
703 $this->accountancy_code = $obj->accountancy_code;
705 $this->thm = $obj->thm;
706 $this->tjm = $obj->tjm;
707 $this->salary = $obj->salary;
708 $this->salaryextra = $obj->salaryextra;
709 $this->weeklyhours = $obj->weeklyhours;
710 $this->color = $obj->color;
711 $this->dateemployment = $this->db->jdate($obj->dateemployment);
712 $this->dateemploymentend = $this->db->jdate($obj->dateemploymentend);
714 $this->datec = $this->db->jdate($obj->datec);
715 $this->datem = $this->db->jdate($obj->datem);
716 $this->datelastlogin = $this->db->jdate($obj->datel);
717 $this->datepreviouslogin = $this->db->jdate($obj->datep);
718 $this->flagdelsessionsbefore = $this->db->jdate($obj->flagdelsessionsbefore,
'gmt');
719 $this->iplastlogin = $obj->iplastlogin;
720 $this->ippreviouslogin = $obj->ippreviouslogin;
721 $this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
722 $this->dateendvalidity = $this->db->jdate($obj->dateendvalidity);
724 $this->socid = $obj->fk_soc;
725 $this->contact_id = $obj->fk_socpeople;
726 $this->fk_member = $obj->fk_member;
727 $this->fk_user = $obj->fk_user;
728 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
729 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
731 $this->default_range = $obj->default_range;
732 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
733 $this->fk_warehouse = $obj->fk_warehouse;
734 $this->fk_establishment = $obj->fk_establishment;
735 $this->label_establishment = $obj->label_establishment;
739 if (!isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
747 $this->db->free($resql);
749 $this->
error =
"USERNOTFOUND";
750 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
752 $this->db->free($resql);
756 $this->
error = $this->db->lasterror();
761 if ($loadpersonalconf) {
767 $this->
error = $this->db->lasterror();
786 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
787 $sql .=
" WHERE fk_user = ".((int) $this->
id);
788 $sql .=
" AND entity = ".((int)
$conf->entity);
790 $resql = $this->db->query($sql);
792 $num = $this->db->num_rows($resql);
795 $obj = $this->db->fetch_object($resql);
796 $p = (!empty($obj->param) ? $obj->param :
'');
798 $this->
conf->$p = $obj->value;
802 $this->db->free($resql);
806 $this->
error = $this->db->lasterror();
823 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
826 $result = $defaultValues->fetchAll(
'',
'', 0, 0,
'(t.user_id:in:0,'.$this->
id.
') AND (entity:in:'.(isset($this->entity) ? $this->entity :
$conf->entity).
','.
$conf->entity.
')');
829 if (!is_array($result) && $result < 0) {
833 } elseif (count($result) > 0) {
834 foreach ($result as $defval) {
835 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
836 $pagewithoutquerystring = $defval->page;
839 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
840 $pagewithoutquerystring = $reg[1];
841 $pagequeries = $reg[2];
843 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
847 if (!empty($this->default_values)) {
848 foreach ($this->default_values as $a => $b) {
849 foreach ($b as $c => $d) {
850 krsort($this->default_values[$a][$c]);
869 public function hasRight($module, $permlevel1, $permlevel2 =
'')
872 $moduletomoduletouse = array(
873 'compta' =>
'comptabilite',
874 'contract' =>
'contrat',
875 'member' =>
'adherent',
877 'order' =>
'commande',
878 'produit' =>
'product',
879 'project' =>
'projet',
880 'propale' =>
'propal',
881 'shipping' =>
'expedition',
882 'task' =>
'task@projet',
883 'fichinter' =>
'ficheinter',
884 'inventory' =>
'stock',
885 'invoice' =>
'facture',
886 'invoice_supplier' =>
'fournisseur',
887 'order_supplier' =>
'fournisseur',
888 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
889 'skill@hrm' =>
'all@hrm',
890 'job@hrm' =>
'all@hrm',
891 'position@hrm' =>
'all@hrm',
892 'facturerec' =>
'facture',
893 'margins' =>
'margin',
896 if (!empty($moduletomoduletouse[$module])) {
897 $module = $moduletomoduletouse[$module];
900 $moduleRightsMapping = array(
901 'product' =>
'produit',
902 'margin' =>
'margins',
903 'comptabilite' =>
'compta'
906 $rightsPath = $module;
907 if (!empty($moduleRightsMapping[$rightsPath])) {
908 $rightsPath = $moduleRightsMapping[$rightsPath];
912 $tmp = explode(
'@', $rightsPath, 2);
913 if (!empty($tmp[1])) {
914 if (strpos($module,
'@') !==
false) {
917 if ($tmp[0] != $tmp[1]) {
919 $rightsPath = $tmp[1];
920 $permlevel2 = $permlevel1;
921 $permlevel1 = $tmp[0];
924 $rightsPath = $tmp[1];
934 if (!isModEnabled($module)) {
939 if (!empty($this->socid)) {
940 if ($module ==
'societe' && ($permlevel1 ==
'creer' || $permlevel1 ==
'write')) {
943 if ($module ==
'societe' && $permlevel1 ==
'client' && $permlevel2 ==
'voir') {
946 if ($module ==
'societe' && $permlevel1 ==
'export') {
949 if ($module ==
'societe' && ($permlevel1 ==
'supprimer' || $permlevel1 ==
'delete')) {
955 if ($permlevel1 ==
'propale') {
956 $permlevel1 =
'propal';
958 if ($permlevel1 ==
'member') {
959 $permlevel1 =
'adherent';
961 if ($permlevel1 ==
'recruitmentcandidature') {
962 $permlevel1 =
'recruitmentjobposition';
967 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
972 if (!empty($this->rights->$rightsPath->$permlevel1)) {
973 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
974 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
978 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
979 return $this->rights->$rightsPath->$permlevel1->lire;
981 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
982 return $this->rights->$rightsPath->$permlevel1->creer;
984 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
985 return $this->rights->$rightsPath->$permlevel1->create;
987 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
988 return $this->rights->$rightsPath->$permlevel1->supprimer;
992 if (!empty($this->rights->$rightsPath->$permlevel1)) {
993 return $this->rights->$rightsPath->$permlevel1;
997 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
998 return $this->rights->$rightsPath->lire;
1000 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
1001 return $this->rights->$rightsPath->creer;
1003 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
1004 return $this->rights->$rightsPath->create;
1006 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
1007 return $this->rights->$rightsPath->supprimer;
1025 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1027 global $conf, $user, $langs;
1029 $entity = (empty($entity) ?
$conf->entity : $entity);
1031 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
1033 if (empty($this->
id)) {
1034 $this->
error =
'Try to call addrights on an object user with an empty id';
1044 $module = $perms = $subperms =
'';
1047 $sql =
"SELECT module, perms, subperms";
1048 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1049 $sql .=
" WHERE id = ".((int) $rid);
1050 $sql .=
" AND entity = ".((int) $entity);
1052 $result = $this->db->query($sql);
1054 $obj = $this->db->fetch_object($result);
1057 $module = $obj->module;
1058 $perms = $obj->perms;
1059 $subperms = $obj->subperms;
1067 $whereforadd =
"id=".((int) $rid);
1069 if (!empty($subperms)) {
1070 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
1071 } elseif (!empty($perms)) {
1072 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND (subperms IS NULL or subperms = ''))";
1078 if (!empty($allmodule)) {
1079 if ($allmodule ==
'allmodules') {
1080 $whereforadd =
'allmodules';
1082 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
1083 if (!empty($allperms)) {
1084 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
1092 if (!empty($whereforadd)) {
1095 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1096 $sql .=
" WHERE entity = ".((int) $entity);
1097 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
1098 $sql .=
" AND (".$whereforadd.
")";
1101 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1102 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1104 $sqldelete .=
") AND entity = ".((int) $entity);
1105 if (!$this->db->query($sqldelete)) {
1110 $resql = $this->db->query($sql);
1112 $num = $this->db->num_rows($resql);
1115 $obj = $this->db->fetch_object($resql);
1120 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
1121 if (!$this->db->query($sql)) {
1135 if (!$error && !$notrigger) {
1136 $langs->load(
"other");
1137 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
1148 $this->db->rollback();
1151 $this->db->commit();
1168 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1170 global $conf, $user, $langs;
1174 $entity = (!empty($entity) ? $entity :
$conf->entity);
1179 $module = $perms = $subperms =
'';
1183 $sql =
"SELECT module, perms, subperms";
1184 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1185 $sql .=
" WHERE id = '".$this->db->escape($rid).
"'";
1186 $sql .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1188 $result = $this->db->query($sql);
1190 $obj = $this->db->fetch_object($result);
1193 $module = $obj->module;
1194 $perms = $obj->perms;
1195 $subperms = $obj->subperms;
1203 $wherefordel =
"id=".((int) $rid);
1205 if ($subperms ==
'lire' || $subperms ==
'read') {
1206 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1208 if ($perms ==
'lire' || $perms ==
'read') {
1209 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1215 if (!empty($allmodule)) {
1216 if ($allmodule ==
'allmodules') {
1217 $wherefordel =
'allmodules';
1219 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1220 if (!empty($allperms)) {
1221 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1228 if (!empty($wherefordel)) {
1231 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1232 $sql .=
" WHERE entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1233 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1234 $sql .=
" AND (".$wherefordel.
")";
1238 if ($this->admin == 1) {
1239 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1240 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1241 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1242 $sql .=
" AND id NOT IN (358)";
1245 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1246 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1249 $sqldelete .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1251 $resql = $this->db->query($sqldelete);
1258 if (!$error && !$notrigger) {
1259 $langs->load(
"other");
1260 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1271 $this->db->rollback();
1274 $this->db->commit();
1288 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1290 $this->nb_rights = 0;
1291 $this->all_permissions_are_loaded = 0;
1292 $this->_tab_loaded = array();
1308 $alreadyloaded =
false;
1310 if (empty($forcereload)) {
1311 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1313 $alreadyloaded =
true;
1316 if (!empty($this->all_permissions_are_loaded)) {
1318 $alreadyloaded =
true;
1323 if (!isset($this->rights) || !is_object($this->rights)) {
1326 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1327 $this->rights->user =
new stdClass();
1332 if (!$alreadyloaded) {
1334 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1335 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1336 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1337 $sql .=
" WHERE r.id = ur.fk_id";
1343 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') ?
"1," :
"").
$conf->entity.
")";
1347 $sql .=
" AND r.entity = ".((int)
$conf->entity).
" AND ur.entity = ".((int)
$conf->entity);
1349 $sql .=
" AND ur.fk_user = ".((int) $this->
id);
1350 $sql .=
" AND r.perms IS NOT NULL";
1352 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1355 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1358 $resql = $this->db->query($sql);
1360 $num = $this->db->num_rows($resql);
1363 $obj = $this->db->fetch_object($resql);
1366 $module = $obj->module;
1367 $perms = $obj->perms;
1368 $subperms = $obj->subperms;
1370 if (!empty($perms)) {
1371 if (!empty($module)) {
1372 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1373 $this->rights->$module =
new stdClass();
1375 if (!empty($subperms)) {
1376 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1377 $this->rights->$module->$perms =
new stdClass();
1379 if (empty($this->rights->$module->$perms->$subperms)) {
1382 $this->rights->$module->$perms->$subperms = 1;
1384 if (empty($this->rights->$module->$perms)) {
1387 $this->rights->$module->$perms = 1;
1394 $this->db->free($resql);
1398 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms, r.entity";
1399 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1400 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1401 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1402 $sql .=
" WHERE r.id = gr.fk_id";
1407 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1408 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1410 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1413 $sql .=
" AND gr.entity = ".((int)
$conf->entity);
1417 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1418 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1421 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1422 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1423 $sql .=
" AND r.perms IS NOT NULL";
1425 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1428 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1431 $resql = $this->db->query($sql);
1433 $num = $this->db->num_rows($resql);
1436 $obj = $this->db->fetch_object($resql);
1439 $module = $obj->module;
1440 $perms = $obj->perms;
1441 $subperms = $obj->subperms;
1443 if (!empty($perms)) {
1444 if (!empty($module)) {
1445 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1446 $this->rights->$module =
new stdClass();
1448 if (!empty($subperms)) {
1449 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1450 $this->rights->$module->$perms =
new stdClass();
1452 if (empty($this->rights->$module->$perms->$subperms)) {
1455 $this->rights->$module->$perms->$subperms = 1;
1458 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1459 if (empty($this->rights->$module->$perms)) {
1462 $this->rights->$module->$perms = 1;
1470 $this->db->free($resql);
1474 if (!empty($this->admin)) {
1475 if (empty($this->rights->user->user)) {
1476 $this->rights->user->user =
new stdClass();
1478 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1479 foreach ($listofpermtotest as $permtotest) {
1480 if (empty($this->rights->user->user->$permtotest)) {
1481 $this->rights->user->user->$permtotest = 1;
1485 if (empty($this->rights->user->self)) {
1486 $this->rights->user->self =
new stdClass();
1488 $listofpermtotest = array(
'creer',
'password');
1489 foreach ($listofpermtotest as $permtotest) {
1490 if (empty($this->rights->user->self->$permtotest)) {
1491 $this->rights->user->self->$permtotest = 1;
1497 if (empty($this->rights->user->user_advance)) {
1498 $this->rights->user->user_advance =
new stdClass();
1500 $listofpermtotest = array(
'readperms',
'write');
1501 foreach ($listofpermtotest as $permtotest) {
1502 if (empty($this->rights->user->user_advance->$permtotest)) {
1503 $this->rights->user->user_advance->$permtotest = 1;
1507 if (empty($this->rights->user->self_advance)) {
1508 $this->rights->user->self_advance =
new stdClass();
1510 $listofpermtotest = array(
'readperms',
'writeperms');
1511 foreach ($listofpermtotest as $permtotest) {
1512 if (empty($this->rights->user->self_advance->$permtotest)) {
1513 $this->rights->user->self_advance->$permtotest = 1;
1517 if (empty($this->rights->user->group_advance)) {
1518 $this->rights->user->group_advance =
new stdClass();
1520 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1521 foreach ($listofpermtotest as $permtotest) {
1522 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1523 $this->rights->user->group_advance->$permtotest = 1;
1531 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1532 $this->rights->propal = $this->rights->propale;
1534 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1535 $this->rights->propale = $this->rights->propal;
1542 $this->all_permissions_are_loaded = 1;
1545 $this->_tab_loaded[$moduletag] = 1;
1562 public function getrights($moduletag =
'', $forcereload = 0)
1575 global $conf, $langs, $user;
1580 if (isset($this->statut)) {
1581 if ($this->statut == $status) {
1584 } elseif (isset($this->
status) && $this->
status == $status) {
1591 $sql =
"UPDATE ".$this->db->prefix().
"user";
1592 $sql .=
" SET statut = ".((int) $status);
1593 $sql .=
" WHERE rowid = ".((int) $this->
id);
1594 $result = $this->db->query($sql);
1596 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1599 $this->context[
'actionmsg'] =
'User '.$this->login.
' disabled';
1601 $this->context[
'actionmsg'] =
'User '.$this->login.
' enabled';
1604 $result = $this->
call_trigger(
'USER_ENABLEDISABLE', $user);
1612 $this->db->rollback();
1616 $this->statut = $status;
1617 $this->db->commit();
1634 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1635 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1646 global $conf, $langs;
1652 $this->
fetch($this->
id);
1654 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1657 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1659 if (!$error && !$this->db->query($sql)) {
1661 $this->
error = $this->db->lasterror();
1665 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1666 if (!$error && !$this->db->query($sql)) {
1668 $this->
error = $this->db->lasterror();
1672 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1673 if (!$error && !$this->db->query($sql)) {
1675 $this->
error = $this->db->lasterror();
1679 if ($this->contact_id > 0) {
1680 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1681 if (!$error && !$this->db->query($sql)) {
1683 $this->
error = $this->db->lasterror();
1692 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1698 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1699 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1700 if (!$this->db->query($sql)) {
1702 $this->
error = $this->db->lasterror();
1711 $this->db->rollback();
1716 $this->db->commit();
1719 $this->db->rollback();
1731 public function create($user, $notrigger = 0)
1733 global $conf, $langs;
1739 $this->civility_code = trim((
string) $this->civility_code);
1740 $this->login = trim((
string) $this->login);
1741 if (!isset($this->entity)) {
1742 $this->entity =
$conf->entity;
1744 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1746 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1750 $langs->load(
"errors");
1751 $this->
error = $langs->trans(
"ErrorBadEMail", $this->
email);
1754 if (empty($this->login)) {
1755 $langs->load(
"errors");
1756 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1758 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1759 $langs->load(
"errors");
1760 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1771 $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).
"'";
1772 $resqltochecklogin = $this->db->query($sqltochecklogin);
1773 if ($resqltochecklogin) {
1774 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1775 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1776 $langs->load(
"errors");
1777 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1779 $this->db->rollback();
1782 $this->db->free($resqltochecklogin);
1785 if (!empty($this->
email)) {
1786 $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).
"'";
1787 $resqltochecklogin = $this->db->query($sqltochecklogin);
1788 if ($resqltochecklogin) {
1789 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1790 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1791 $langs->load(
"errors");
1792 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->
email);
1794 $this->db->rollback();
1797 $this->db->free($resqltochecklogin);
1802 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, entity)";
1803 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->db->escape($this->login).
"', '".$this->db->escape($this->ldap_sid).
"', ".((int) $this->entity).
")";
1804 $result = $this->db->query($sql);
1806 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1808 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1812 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1813 $this->db->rollback();
1818 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1819 $langs->load(
"stocks");
1821 $entrepot =
new Entrepot($this->db);
1822 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1823 $entrepot->libelle = $entrepot->label;
1824 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1825 $entrepot->statut = 1;
1826 $entrepot->country_id = $mysoc->country_id;
1828 $warehouseid = $entrepot->create($user);
1830 $this->fk_warehouse = $warehouseid;
1834 $result = $this->
update($user, 1, 1);
1836 $this->db->rollback();
1850 $this->db->commit();
1855 $this->db->rollback();
1859 $this->
error = $this->db->lasterror();
1860 $this->db->rollback();
1878 global $conf, $user, $langs;
1884 $this->civility_code = $contact->civility_code;
1885 $this->lastname = $contact->lastname;
1886 $this->firstname = $contact->firstname;
1888 $this->
email = $contact->email;
1889 $this->socialnetworks = $contact->socialnetworks;
1890 $this->office_phone = $contact->phone_pro;
1891 $this->office_fax = $contact->fax;
1892 $this->user_mobile = $contact->phone_mobile;
1893 $this->
address = $contact->address;
1894 $this->zip = $contact->zip;
1895 $this->town = $contact->town;
1897 $this->state_id = $contact->state_id;
1898 $this->country_id = $contact->country_id;
1899 $this->employee = 0;
1901 if (empty($login)) {
1902 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1903 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1905 $this->login = $login;
1910 $result = $this->
create($user, 1);
1912 $sql =
"UPDATE ".$this->db->prefix().
"user";
1913 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1914 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1915 if ($contact->socid > 0) {
1916 $sql .=
", fk_soc=".((int) $contact->socid);
1918 $sql .=
" WHERE rowid=".((int) $this->
id);
1920 $resql = $this->db->query($sql);
1922 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1924 $this->context[
'createfromcontact'] =
'createfromcontact';
1930 $this->db->rollback();
1935 $this->db->commit();
1938 $this->
error = $this->db->error();
1940 $this->db->rollback();
1945 dol_syslog(get_class($this).
"::create_from_contact - 0");
1947 $this->db->rollback();
1968 $this->civility_code = $member->civility_code;
1969 $this->lastname = $member->lastname;
1970 $this->firstname = $member->firstname;
1971 $this->gender = $member->gender;
1972 $this->
email = $member->email;
1973 $this->fk_member = $member->id;
1974 $this->
address = $member->address;
1975 $this->zip = $member->zip;
1976 $this->town = $member->town;
1978 $this->state_id = $member->state_id;
1979 $this->country_id = $member->country_id;
1980 $this->socialnetworks = $member->socialnetworks;
1982 $this->pass = $member->pass;
1983 $this->pass_crypted = $member->pass_indatabase_crypted;
1985 if (empty($login)) {
1986 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1989 $this->login = $login;
1994 $result = $this->
create($user);
1996 if (!empty($this->pass)) {
1997 $newpass = $this->
setPassword($user, $this->pass);
1998 if (is_int($newpass) && $newpass < 0) {
2001 } elseif (!empty($this->pass_crypted)) {
2002 $sql =
"UPDATE ".$this->db->prefix().
"user";
2003 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
2004 $sql .=
" WHERE rowid=".((int) $this->
id);
2006 $resql = $this->db->query($sql);
2012 if ($result > 0 && $member->socid) {
2013 $sql =
"UPDATE ".$this->db->prefix().
"user";
2014 $sql .=
" SET fk_soc=".((int) $member->socid);
2015 $sql .=
" WHERE rowid=".((int) $this->
id);
2017 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
2018 $resql = $this->db->query($sql);
2020 $this->db->commit();
2023 $this->
error = $this->db->lasterror();
2025 $this->db->rollback();
2032 $this->db->commit();
2036 $this->db->rollback();
2054 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
2055 $sql .=
" WHERE bydefault = 1";
2056 $sql .=
" AND entity = ".((int)
$conf->entity);
2058 $resql = $this->db->query($sql);
2060 $num = $this->db->num_rows($resql);
2063 $row = $this->db->fetch_row($resql);
2067 $this->db->free($resql);
2071 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
2072 $result = $this->db->query($sql);
2074 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
2075 $result = $this->db->query($sql);
2095 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
2097 global $conf, $langs;
2099 $nbrowsaffected = 0;
2102 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
2105 $this->civility_code = trim((
string) $this->civility_code);
2106 $this->lastname = trim((
string) $this->lastname);
2107 $this->firstname = trim((
string) $this->firstname);
2108 $this->ref_employee = trim((
string) $this->ref_employee);
2109 $this->national_registration_number = trim((
string) $this->national_registration_number);
2110 $this->employee = ($this->employee > 0 ? $this->employee : 0);
2111 $this->login = trim((
string) $this->login);
2112 $this->gender = trim((
string) $this->gender);
2114 $this->pass = trim((
string) $this->pass);
2115 $this->api_key = trim((
string) $this->api_key);
2116 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
2117 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
2120 $this->zip = trim((
string) $this->zip);
2121 $this->town = trim((
string) $this->town);
2123 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
2124 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
2125 $this->office_phone = trim((
string) $this->office_phone);
2126 $this->office_fax = trim((
string) $this->office_fax);
2127 $this->user_mobile = trim((
string) $this->user_mobile);
2128 $this->personal_mobile = trim((
string) $this->personal_mobile);
2130 $this->personal_email = trim((
string) $this->personal_email);
2132 $this->job = trim((
string) $this->job);
2133 $this->signature = trim((
string) $this->signature);
2134 $this->note_public = trim((
string) $this->note_public);
2135 $this->note_private = trim((
string) $this->note_private);
2136 $this->openid = trim((
string) $this->openid);
2137 $this->admin = ($this->admin > 0 ? $this->admin : 0);
2139 $this->accountancy_code_user_general = trim((
string) $this->accountancy_code_user_general);
2140 $this->accountancy_code = trim((
string) $this->accountancy_code);
2141 $this->color = trim((
string) $this->color);
2142 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
2143 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
2145 $this->birth = empty($this->birth) ?
'' : $this->birth;
2146 $this->fk_warehouse = (int) $this->fk_warehouse;
2147 $this->fk_establishment = (int) $this->fk_establishment;
2152 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
2155 $langs->load(
"errors");
2156 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
2159 if (empty($this->login)) {
2160 $langs->load(
"errors");
2161 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
2163 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
2164 $langs->load(
"errors");
2165 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
2172 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->oldcopy->login != $this->login) {
2173 $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).
"'";
2174 $resqltochecklogin = $this->db->query($sqltochecklogin);
2175 if ($resqltochecklogin) {
2176 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2177 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2178 $langs->load(
"errors");
2179 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
2181 $this->db->rollback();
2186 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && !empty($this->email) && $this->oldcopy->email != $this->email) {
2187 $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).
"'";
2188 $resqltochecklogin = $this->db->query($sqltochecklogin);
2189 if ($resqltochecklogin) {
2190 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2191 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2192 $langs->load(
"errors");
2193 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
2195 $this->db->rollback();
2202 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2203 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
2204 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
2205 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
2206 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
2207 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
2208 $sql .=
", employee = ".(int) $this->employee;
2209 $sql .=
", login = '".$this->db->escape($this->login).
"'";
2210 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
2211 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
2212 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
2213 if (!empty($user->admin)) {
2214 $sql .=
", admin = ".(int) $this->admin;
2216 $sql .=
", address = '".$this->db->escape($this->address).
"'";
2217 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
2218 $sql .=
", town = '".$this->db->escape($this->town).
"'";
2219 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".$this->db->escape($this->state_id).
"'" :
"null");
2220 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".$this->db->escape($this->country_id).
"'" :
"null");
2221 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
2222 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
2223 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
2224 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
2225 $sql .=
", email = '".$this->db->escape($this->email).
"'";
2226 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
2227 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
2228 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2229 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2230 $sql .=
", accountancy_code_user_general = '".$this->db->escape($this->accountancy_code_user_general).
"'";
2231 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2232 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2233 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2234 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2235 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2236 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2237 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2238 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2239 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2240 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2241 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".$this->db->escape($this->fk_user).
"'" :
"null");
2242 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".$this->db->escape($this->fk_user_expense_validator).
"'" :
"null");
2243 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".$this->db->escape($this->fk_user_holiday_validator).
"'" :
"null");
2244 if (isset($this->thm) || $this->thm !=
'') {
2245 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2247 if (isset($this->tjm) || $this->tjm !=
'') {
2248 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2250 if (isset($this->salary) || $this->salary !=
'') {
2251 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2253 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2254 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2256 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2257 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2258 $sql .=
", entity = ".((int) $this->entity);
2260 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2261 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2262 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2263 $sql .=
", fk_establishment = ".($this->fk_establishment > 0 ? $this->fk_establishment :
"null");
2264 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2265 $sql .=
" WHERE rowid = ".((int) $this->
id);
2267 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2268 $resql = $this->db->query($sql);
2270 $nbrowsaffected += $this->db->affected_rows($resql);
2273 if (!empty($this->pass)) {
2274 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2276 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2277 if (is_int($result) && $result < 0) {
2284 if ($this->fk_member > 0) {
2285 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2286 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2287 $resql = $this->db->query($sql);
2289 $this->
error = $this->db->error();
2290 $this->db->rollback();
2295 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2296 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2297 $resql = $this->db->query($sql);
2299 $this->
error = $this->db->error();
2300 $this->db->rollback();
2304 if ($nbrowsaffected) {
2305 if ($this->fk_member > 0 && !$nosyncmember) {
2306 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2308 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2313 $result = $adh->fetch($this->fk_member);
2316 $adh->civility_code = $this->civility_code;
2317 $adh->firstname = $this->firstname;
2318 $adh->lastname = $this->lastname;
2319 $adh->login = $this->login;
2320 $adh->gender = $this->gender;
2321 $adh->birth = $this->birth;
2323 $adh->pass = $this->pass;
2325 $adh->address = $this->address;
2326 $adh->town = $this->town;
2327 $adh->zip = $this->zip;
2328 $adh->state_id = $this->state_id;
2329 $adh->country_id = $this->country_id;
2331 $adh->email = $this->email;
2333 $adh->socialnetworks = $this->socialnetworks;
2335 $adh->phone = $this->office_phone;
2336 $adh->phone_mobile = $this->user_mobile;
2338 $adh->default_lang = $this->lang;
2340 $adh->user_id = $this->id;
2341 $adh->user_login = $this->login;
2343 $result = $adh->update($user, 0, 1, 0);
2345 $this->
error = $adh->error;
2346 $this->errors = $adh->errors;
2347 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2350 } elseif ($result < 0) {
2351 $this->
error = $adh->error;
2352 $this->errors = $adh->errors;
2357 if ($this->contact_id > 0 && !$nosynccontact) {
2358 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2360 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2363 $tmpobj =
new Contact($this->db);
2364 $result = $tmpobj->fetch($this->contact_id);
2367 $tmpobj->civility_code = $this->civility_code;
2368 $tmpobj->firstname = $this->firstname;
2369 $tmpobj->lastname = $this->lastname;
2370 $tmpobj->login = $this->login;
2371 $tmpobj->gender = $this->gender;
2372 $tmpobj->birth = $this->birth;
2376 $tmpobj->email = $this->email;
2378 $tmpobj->socialnetworks = $this->socialnetworks;
2380 $tmpobj->phone_pro = $this->office_phone;
2381 $tmpobj->phone_mobile = $this->user_mobile;
2382 $tmpobj->fax = $this->office_fax;
2384 $tmpobj->default_lang = $this->lang;
2386 $tmpobj->address = $this->address;
2387 $tmpobj->town = $this->town;
2388 $tmpobj->zip = $this->zip;
2389 $tmpobj->state_id = $this->state_id;
2390 $tmpobj->country_id = $this->country_id;
2392 $tmpobj->user_id = $this->id;
2393 $tmpobj->user_login = $this->login;
2395 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2397 $this->
error = $tmpobj->error;
2398 $this->errors = $tmpobj->errors;
2399 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2403 $this->
error = $tmpobj->error;
2404 $this->errors = $tmpobj->errors;
2420 if (!$error && !$notrigger) {
2430 $this->db->commit();
2431 return $nbrowsaffected;
2434 $this->db->rollback();
2438 $this->
error = $this->db->lasterror();
2439 $this->db->rollback();
2458 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2459 $sql .=
" datepreviouslogin = datelastlogin,";
2460 $sql .=
" ippreviouslogin = iplastlogin,";
2461 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2462 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2463 $sql .=
" tms = tms";
2464 $sql .=
" WHERE rowid = ".((int) $this->
id);
2466 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2467 $resql = $this->db->query($sql);
2469 $this->datepreviouslogin = $this->datelastlogin;
2470 $this->datelastlogin = $now;
2471 $this->ippreviouslogin = $this->iplastlogin;
2472 $this->iplastlogin = $userremoteip;
2475 $this->
error = $this->db->lasterror().
' sql='.$sql;
2493 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2495 global $conf, $langs;
2496 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2500 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2507 $password_crypted =
null;
2509 if (empty($passwordalreadycrypted)) {
2512 $modGeneratePassClass =
'modGeneratePass'.ucfirst(
$conf->global->USER_PASSWORD_GENERATED);
2514 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2515 if (class_exists($modGeneratePassClass)) {
2516 $modGeneratePass =
new $modGeneratePassClass($this->db,
$conf, $langs, $user);
2517 '@phan-var-force ModeleGenPassword $modGeneratePass';
2520 $modGeneratePass->WithoutAmbi = 0;
2523 $testpassword = $modGeneratePass->validatePassword($password);
2524 if (!$testpassword) {
2525 $this->
error = $modGeneratePass->error;
2533 $password_crypted =
dol_hash($password);
2537 if (!$changelater) {
2538 if (!is_object($this->oldcopy)) {
2539 $this->oldcopy = clone $this;
2546 $sql =
"UPDATE ".$this->db->prefix().
"user";
2547 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2548 $sql .=
" pass_temp = null";
2549 if (!empty($flagdelsessionsbefore)) {
2550 $sql .=
", flagdelsessionsbefore = '".$this->db->idate($now - 5,
'gmt').
"'";
2553 $sql .=
", pass = null";
2555 $sql .=
", pass = '".$this->db->escape($password).
"'";
2557 $sql .=
" WHERE rowid = ".((int) $this->
id);
2559 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2560 $result = $this->db->query($sql);
2562 if ($this->db->affected_rows($result)) {
2563 $this->pass = $password;
2564 $this->pass_indatabase = $password;
2565 $this->pass_indatabase_crypted = (string) $password_crypted;
2567 if ($this->fk_member && !$nosyncmember) {
2568 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2573 $result = $adh->fetch($this->fk_member);
2576 $result = $adh->setPassword($user, $this->pass, (!
getDolGlobalString(
'DATABASE_PWD_ENCRYPTED') ? 0 : 1), 1);
2577 if (is_int($result) && $result < 0) {
2578 $this->
error = $adh->error;
2583 $this->
error = $adh->error;
2588 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2591 $user->context[
'audit'] =
'login='.$user->login;
2592 if (!empty($flagdelsessionsbefore)) {
2593 $user->context[
'audit'] .=
" - flagdelsessionsbefore set to '".$this->db->idate($now - 5,
'gmt').
"'";
2596 if (!$error && !$notrigger) {
2598 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2601 $this->db->rollback();
2607 $this->db->commit();
2610 $this->db->rollback();
2614 $this->db->rollback();
2621 $sql =
"UPDATE ".$this->db->prefix().
"user";
2622 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2623 $sql .=
" WHERE rowid = ".((int) $this->
id);
2625 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2626 $result = $this->db->query($sql);
2648 global $conf, $langs, $mysoc;
2649 global $dolibarr_main_url_root;
2651 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2660 if (isset($this->
conf->MAIN_LANG_DEFAULT)
2661 && $this->conf->MAIN_LANG_DEFAULT !=
'auto') {
2662 $outputlangs->getDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2665 if ($this->
conf->MAIN_LANG_DEFAULT) {
2666 $outputlangs->setDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2668 $outputlangs = $langs;
2672 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2674 $appli =
getDolGlobalString(
'MAIN_APPLICATION_TITLE', constant(
'DOL_APPLICATION_TITLE'));
2676 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2679 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2680 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2682 if (!$changelater) {
2683 $url = $urlwithroot.
'/';
2688 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2690 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2691 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2692 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2693 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2696 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2698 $mesg .= $user->getFullName($outputlangs);
2701 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2702 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.
$conf->file->instance_unique_id));
2703 if (isModEnabled(
'multicompany')) {
2704 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2707 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2711 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2712 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2713 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2714 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2716 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2717 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2718 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2721 $trackid =
'use'.$this->id;
2722 $sendcontext =
'passwordreset';
2727 $conf->global->MAIN_MAIL_EMAIL_FROM,
2743 if ($mailfile->sendfile()) {
2746 $langs->trans(
"errors");
2747 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2759 return $this->error;
2772 $sql =
"SELECT url, login, pass, poste ";
2773 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2774 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2776 $resql = $this->db->query($sql);
2778 if ($this->db->num_rows($resql)) {
2779 $obj = $this->db->fetch_object($resql);
2781 $this->clicktodial_url = $obj->url;
2782 $this->clicktodial_login = $obj->login;
2783 $this->clicktodial_password = $obj->pass;
2784 $this->clicktodial_poste = $obj->poste;
2787 $this->clicktodial_loaded = 1;
2789 $this->db->free($resql);
2792 $this->
error = $this->db->error();
2808 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2809 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2811 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2813 $result = $this->db->query($sql);
2815 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2816 $sql .=
" (fk_user,url,login,pass,poste)";
2817 $sql .=
" VALUES (".$this->id;
2818 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2819 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2820 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2821 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2823 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2825 $result = $this->db->query($sql);
2827 $this->db->commit();
2830 $this->db->rollback();
2831 $this->
error = $this->db->lasterror();
2849 global $conf, $langs, $user;
2855 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2856 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2857 $sql .=
" AND fk_usergroup = ".((int) $group);
2858 $sql .=
" AND entity = ".((int) $entity);
2860 $result = $this->db->query($sql);
2862 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2863 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2865 $result = $this->db->query($sql);
2867 if (!$error && !$notrigger) {
2868 $this->context = array(
'audit' => $langs->trans(
"UserSetInGroup"),
'newgroupid' => $group);
2879 $this->db->commit();
2883 $this->db->rollback();
2887 $this->
error = $this->db->lasterror();
2888 $this->db->rollback();
2905 global $conf, $langs, $user;
2911 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2912 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2913 $sql .=
" AND fk_usergroup = ".((int) $group);
2914 if (empty($entity)) {
2915 $sql .=
" AND entity IN (0, 1)";
2917 $sql .=
" AND entity = ".((int) $entity);
2920 $result = $this->db->query($sql);
2922 if (!$error && !$notrigger) {
2923 $this->context = array(
'audit' => $langs->trans(
"UserRemovedFromGroup"),
'oldgroupid' => $group);
2934 $this->db->commit();
2937 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2938 $this->db->rollback();
2942 $this->
error = $this->db->lasterror();
2943 $this->db->rollback();
2957 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2964 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
2987 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
2989 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2990 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
3004 global $conf, $langs, $menumanager;
3005 global $dolibarr_main_demo;
3007 $infologin = $params[
'infologin'] ?? 0;
3008 $option = $params[
'option'] ??
'';
3011 if (!empty($this->photo)) {
3012 $photo =
'<div class="photointooltip floatright">';
3013 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
3015 $data[
'photo'] = $photo;
3020 $data[
'opendiv'] =
'<div class="centpercent divtooltip">';
3021 $data[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
3023 if (!empty($this->login)) {
3026 if (!empty($this->job)) {
3030 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
3031 $phonelist = array();
3032 if ($this->office_phone) {
3033 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
3035 if ($this->office_fax) {
3036 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
3038 if ($this->user_mobile) {
3039 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
3041 $data[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
3043 if (!empty($this->admin)) {
3044 $data[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
3046 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
3047 $langs->load(
"companies");
3048 $data[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
3051 if (!empty($this->socid)) {
3052 $thirdpartystatic =
new Societe($this->db);
3053 $thirdpartystatic->fetch($this->socid);
3055 if (empty($params[
'hidethirdpartylogo'])) {
3056 $companyimg =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3058 $company =
' ('.$langs->trans(
"Company").
': '.($companyimg ? $companyimg :
img_picto(
'',
'company')).
' '.
dol_string_nohtmltag($thirdpartystatic->name).
')';
3060 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
3061 $data[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
3062 $data[
'closediv'] =
'</div>';
3064 if ($infologin > 0) {
3065 $data[
'newlinelogin'] =
'<br>';
3066 $data[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
3069 $data[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.
$conf->entity.
' (User entity '.$this->entity.
')';
3071 $data[
'authentication'] =
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
3072 $data[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
3073 $data[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
3076 $data[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
3078 $data[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
3079 $data[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag(
$conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
3081 $data[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
3082 if (
$conf->browser->layout ==
'phone') {
3083 $data[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
3085 if (!empty($_SESSION[
"disablemodules"])) {
3086 $data[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(implode(
', ', explode(
',', $_SESSION[
"disablemodules"])));
3108 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
3110 global $langs, $hookmanager, $user;
3112 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
3123 'objecttype' => $this->element,
3124 'infologin' => $infologin,
3125 'option' => $option,
3126 'hidethirdpartylogo' => $hidethirdpartylogo,
3128 $classfortooltip =
'classfortooltip';
3131 $classfortooltip =
'classforajaxtooltip';
3132 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3139 if (!empty($this->socid)) {
3140 $thirdpartystatic =
new Societe($this->db);
3141 $thirdpartystatic->fetch($this->socid);
3142 if (empty($hidethirdpartylogo)) {
3143 $companylink =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3147 if ($infologin < 0) {
3151 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
3152 if ($option ==
'leave') {
3153 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
3156 if ($option !=
'nolink') {
3158 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3159 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3160 $add_save_lastsearch_values = 1;
3162 if ($add_save_lastsearch_values) {
3163 $url .=
'&save_lastsearch_values=1';
3167 $linkstart =
'<a href="'.$url.
'"';
3169 if (empty($notooltip)) {
3171 $langs->load(
"users");
3172 $label = $langs->trans(
"ShowUser");
3173 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
3175 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
3176 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
3178 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
3181 $linkstart .= $linkclose.
'>';
3185 $result .= (($option ==
'nolink') ?
'' : $linkstart);
3186 if ($withpictoimg) {
3187 $paddafterimage =
'';
3188 if (abs((
int) $withpictoimg) == 1) {
3189 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3192 if ($withpictoimg > 0) {
3193 $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>';
3196 $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>';
3200 if ($withpictoimg > -2 && $withpictoimg != 2) {
3202 $result .=
'<span class="nopadding usertext'.((!isset($this->
status) || $this->status) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
3204 if ($mode ==
'login') {
3210 $result .=
'</span>';
3213 $result .= (($option ==
'nolink') ?
'' : $linkend);
3216 $result .= $companylink;
3219 $hookmanager->initHooks(array(
'userdao'));
3220 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
3221 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3223 $result = $hookmanager->resPrint;
3225 $result .= $hookmanager->resPrint;
3240 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
3242 global $langs, $user;
3246 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3250 if ((!$user->hasRight(
'user',
'user',
'lire') && $this->id != $user->id)) {
3254 if ($option ==
'xxx') {
3255 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3259 if ($option ==
'nolink') {
3264 $result .= $linkstart;
3265 if ($withpictoimg) {
3266 $paddafterimage =
'';
3267 if (abs($withpictoimg) == 1) {
3268 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3271 if ($withpictoimg > 0) {
3272 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3275 $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>';
3279 $result .= $this->login;
3280 $result .= $linkend;
3293 return $this->
LibStatut(isset($this->statut) ? (
int) $this->statut : (int) $this->
status, $mode);
3309 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3312 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3313 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3314 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3315 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3318 $statusType =
'status5';
3319 if ($status == self::STATUS_ENABLED) {
3320 $statusType =
'status4';
3323 $label = $this->labelStatus[$status];
3324 $labelshort = $this->labelStatusShort[$status];
3327 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3328 $statusType =
'status3';
3329 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3331 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3332 $statusType =
'status2';
3333 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3336 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3351 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3353 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3354 $return .=
'<div class="info-box info-box-sm">';
3355 $return .=
'<span class="info-box-icon bg-infobox-action">';
3358 if (!empty($this->photo)) {
3360 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3369 $return .=
'</span>';
3370 $return .=
'<div class="info-box-content">';
3371 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3372 if (isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3373 $return .=
img_picto($langs->trans(
"SuperAdministratorDesc"),
'redstar',
'class="valignmiddle paddingright paddingleft"');
3374 } elseif ($this->admin) {
3375 $return .=
img_picto($langs->trans(
"AdministratorDesc"),
'star',
'class="valignmiddle paddingright paddingleft"');
3377 $return .=
'</span>';
3378 if ($selected >= 0) {
3379 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3381 if (property_exists($this,
'label')) {
3382 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3385 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->
email.
'</span>';
3387 if (method_exists($this,
'getLibStatut')) {
3388 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3390 $return .=
'</div>';
3391 $return .=
'</div>';
3392 $return .=
'</div>';
3416 } elseif ($mode == 1) {
3418 } elseif ($mode == 2) {
3434 global $conf, $langs;
3440 $keymodified =
false;
3449 'LDAP_FIELD_FULLNAME' =>
'fullname',
3450 'LDAP_FIELD_NAME' =>
'lastname',
3451 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3452 'LDAP_FIELD_LOGIN' =>
'login',
3453 'LDAP_FIELD_LOGIN_SAMBA' =>
'login',
3454 'LDAP_FIELD_PHONE' =>
'office_phone',
3455 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3456 'LDAP_FIELD_FAX' =>
'office_fax',
3457 'LDAP_FIELD_MAIL' =>
'email',
3458 'LDAP_FIELD_SID' =>
'ldap_sid',
3462 foreach ($ldapkey as $constname => $varname) {
3468 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->$varname != $this->oldcopy->$varname) {
3469 $keymodified =
true;
3474 foreach ($socialnetworks as $key => $value) {
3475 if (!empty($this->socialnetworks[$value[
'label']]) &&
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))) {
3476 $info[
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))] = $this->socialnetworks[$value[
'label']];
3491 if ($this->socid > 0) {
3492 $soc =
new Societe($this->db);
3493 $soc->fetch($this->socid);
3496 if ($soc->client == 1) {
3497 $info[
"businessCategory"] =
"Customers";
3499 if ($soc->client == 2) {
3500 $info[
"businessCategory"] =
"Prospects";
3502 if ($soc->fournisseur == 1) {
3503 $info[
"businessCategory"] =
"Suppliers";
3508 if (!empty($this->pass)) {
3521 if ($this->pass_indatabase_crypted &&
getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED')) {
3525 } elseif (!empty($this->pass_indatabase)) {
3537 $info[
"objectclass"][4] =
"phpgwContact";
3539 $info[
'uidnumber'] = $this->id;
3541 $info[
'phpgwTz'] = 0;
3542 $info[
'phpgwMailType'] =
'INTERNET';
3543 $info[
'phpgwMailHomeType'] =
'INTERNET';
3545 $info[
"phpgwContactTypeId"] =
'n';
3546 $info[
"phpgwContactCatId"] = 0;
3547 $info[
"phpgwContactAccess"] =
"public";
3555 $info[
"phpgwContactOwner"] = 1;
3558 $info[
"rfc822Mailbox"] = $this->email;
3560 if ($this->user_mobile) {
3561 $info[
"phpgwCellTelephoneNumber"] = $this->user_mobile;
3570 $groupslist = $usergroup->listGroupsForUser($this->
id);
3572 if (!empty($groupslist)) {
3573 foreach ($groupslist as $groupforuser) {
3580 $info[
getDolGlobalString(
'LDAP_FIELD_HOMEDIRECTORY')] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->login";
3596 global $user, $langs;
3602 $this->
ref =
'SPECIMEN';
3603 $this->specimen = 1;
3605 $this->lastname =
'DOLIBARR';
3606 $this->firstname =
'SPECIMEN';
3607 $this->gender =
'man';
3608 $this->note_public =
'This is a note public';
3609 $this->note_private =
'This is a note private';
3610 $this->
email =
'email@specimen.com';
3611 $this->personal_email =
'personalemail@specimen.com';
3612 $this->socialnetworks = array(
3613 'skype' =>
'skypepseudo',
3614 'twitter' =>
'twitterpseudo',
3615 'facebook' =>
'facebookpseudo',
3616 'linkedin' =>
'linkedinpseudo',
3618 $this->office_phone =
'0999999999';
3619 $this->office_fax =
'0999999998';
3620 $this->user_mobile =
'0999999997';
3621 $this->personal_mobile =
'0999999996';
3623 $this->login =
'dolibspec';
3624 $this->pass =
'dolibSpec+@123';
3627 $this->datec = $now;
3628 $this->datem = $now;
3630 $this->datelastlogin = $now;
3631 $this->iplastlogin =
'127.0.0.1';
3632 $this->datepreviouslogin = $now;
3633 $this->ippreviouslogin =
'127.0.0.1';
3650 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
3651 $sql .=
" u.tms as date_modification, u.entity";
3652 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3653 $sql .=
" WHERE u.rowid = ".((int) $id);
3655 $result = $this->db->query($sql);
3657 if ($this->db->num_rows($result)) {
3658 $obj = $this->db->fetch_object($result);
3660 $this->
id = $obj->rowid;
3662 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3663 $this->date_creation = $this->db->jdate($obj->datec);
3664 $this->date_modification = $this->db->jdate($obj->date_modification);
3665 $this->entity = $obj->entity;
3668 $this->db->free($result);
3682 $sql =
"SELECT count(mc.email) as nb";
3683 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3684 $sql .=
" WHERE mc.email = '".$this->db->escape($this->
email).
"'";
3685 $sql .=
" AND mc.statut NOT IN (-1,0)";
3687 $resql = $this->db->query($sql);
3689 $obj = $this->db->fetch_object($resql);
3692 $this->db->free($resql);
3695 $this->
error = $this->db->error();
3712 $sql =
"SELECT count(rowid) as nb";
3713 $sql .=
" FROM ".$this->db->prefix().
"user";
3714 if ($option ==
'superadmin') {
3715 $sql .=
" WHERE entity = 0";
3717 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3718 if ($limitTo ==
'active') {
3719 $sql .=
" AND statut = 1";
3723 $sql .=
" AND admin = ".(int) $admin;
3726 $resql = $this->db->query($sql);
3728 $obj = $this->db->fetch_object($resql);
3729 $nb = (int) $obj->nb;
3731 $this->db->free($resql);
3734 $this->
error = $this->db->lasterror();
3750 global $user, $conf;
3755 $this->firstname = $ldapuser->$tmpvar;
3757 $this->lastname = $ldapuser->$tmpvar;
3759 $this->login = $ldapuser->$tmpvar;
3761 $this->pass = $ldapuser->$tmpvar;
3763 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3766 $this->office_phone = $ldapuser->$tmpvar;
3768 $this->user_mobile = $ldapuser->$tmpvar;
3770 $this->office_fax = $ldapuser->$tmpvar;
3772 $this->
email = $ldapuser->$tmpvar;
3773 foreach ($socialnetworks as $key => $value) {
3775 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3778 $this->ldap_sid = $ldapuser->$tmpvar;
3781 $this->job = $ldapuser->$tmpvar;
3783 $this->note_public = $ldapuser->$tmpvar;
3785 $result = $this->
update($user);
3787 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3803 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3804 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3806 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3807 $res = $this->db->query($sql);
3810 while ($rec = $this->db->fetch_array($res)) {
3811 $user =
new User($this->db);
3812 $user->fetch($rec[
'rowid']);
3832 $this->parentof = array();
3835 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3836 $sql .=
" FROM ".$this->db->prefix().
"user";
3837 $sql .=
" WHERE fk_user <> 0";
3838 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3840 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3841 $resql = $this->db->query($sql);
3843 while ($obj = $this->db->fetch_object($resql)) {
3844 $this->parentof[$obj->id_son] = $obj->id_parent;
3870 global $conf, $user;
3871 global $hookmanager;
3874 $hookmanager->initHooks(array(
'userdao'));
3876 $this->users = array();
3882 $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";
3883 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3885 $parameters = array();
3886 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3888 $sql .= $hookmanager->resPrint;
3890 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3893 $sql .=
" AND ".$filter;
3896 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3897 $resql = $this->db->query($sql);
3900 while ($obj = $this->db->fetch_object($resql)) {
3901 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3902 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3903 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3904 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3905 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3906 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3907 $this->users[$obj->rowid][
'login'] = $obj->login;
3908 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3909 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3910 $this->users[$obj->rowid][
'email'] = $obj->email;
3911 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3912 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3913 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3915 $this->users[$obj->rowid][
'fullpath'] =
'';
3916 $this->users[$obj->rowid][
'fullname'] =
'';
3917 $this->users[$obj->rowid][
'level'] = 0;
3926 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3927 foreach ($this->users as $key => $val) {
3930 $this->
error =
'ErrorLoopInHierarchy';
3936 if ($deleteafterid) {
3938 $keyfilter1 =
'^'.$deleteafterid.
'$';
3939 $keyfilter2 =
'_'.$deleteafterid.
'$';
3940 $keyfilter3 =
'^'.$deleteafterid.
'_';
3941 $keyfilter4 =
'_'.$deleteafterid.
'_';
3942 foreach (array_keys($this->users) as $key) {
3943 $fullpath = (string) $this->users[$key][
'fullpath'];
3944 if (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
3945 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath)) {
3946 unset($this->users[$key]);
3951 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
3952 $this->users =
dol_sort_array($this->users,
'fullname',
'asc', 1, 0, 1);
3956 return $this->users;
3969 $childids = array();
3971 if (isset($this->cache_childids[$this->
id])) {
3972 $childids = $this->cache_childids[$this->id];
3977 $idtoscan = $this->id;
3979 dol_syslog(
"Build childid for id = ".$idtoscan);
3980 foreach ($this->users as $id => $val) {
3982 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
3983 $childids[$val[
'id']] = $val[
'id'];
3987 $this->cache_childids[$this->id] = $childids;
3989 if ($addcurrentuser) {
3990 $childids[$this->id] = $this->id;
4010 if (!empty($this->users[$id_user][
'fullpath'])) {
4012 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
4017 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
4018 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
4020 $cursor_user = $id_user;
4022 $useridfound = array($id_user);
4023 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
4024 if (in_array($this->parentof[$cursor_user], $useridfound)) {
4025 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
4028 $useridfound[] = $this->parentof[$cursor_user];
4029 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
4030 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
4032 $cursor_user = $this->parentof[$cursor_user];
4036 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
4068 $this->nb = array();
4070 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
4071 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4072 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
4073 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
4074 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
4075 $sql .=
" AND ug.fk_user = u.rowid";
4077 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4079 $sql .=
" AND u.statut > 0";
4082 $resql = $this->db->query($sql);
4084 while ($obj = $this->db->fetch_object($resql)) {
4085 $this->nb[
"users"] = $obj->nb;
4087 $this->db->free($resql);
4091 $this->
error = $this->db->error();
4107 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4109 global $conf, $user, $langs;
4111 $langs->load(
"user");
4118 $modele =
'bluesky';
4122 $modelpath =
"core/modules/user/doc/";
4124 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4138 $user_property =
'';
4140 if (empty($rowid)) {
4144 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
4145 $sql .=
" FROM ".$this->db->prefix().
"user";
4146 $sql .=
" WHERE rowid = ".((int) $rowid);
4148 $resql = $this->db->query($sql);
4150 $nump = $this->db->num_rows($resql);
4153 $obj = $this->db->fetch_object($resql);
4155 if ($mode ==
'email') {
4156 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
4157 } elseif ($mode ==
'mobile') {
4158 $user_property = $obj->user_mobile;
4159 } elseif ($mode ==
'name') {
4163 return $user_property;
4180 global $dolibarr_main_url_root;
4183 $encodedsecurekey =
dol_hash(
$conf->file->instance_unique_id.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
4184 if (isModEnabled(
'multicompany')) {
4185 $entity_qr =
'&entity='.((int)
$conf->entity);
4190 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
4191 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
4194 if ($typeofurl ==
'internal') {
4195 $urlwithroot = DOL_URL_ROOT;
4198 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
4214 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $entityfilter =
false)
4216 global $conf, $user;
4218 $sql =
"SELECT t.rowid";
4219 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
4221 if ($entityfilter) {
4223 if (!empty($user->admin) && empty($user->entity) &&
$conf->entity == 1) {
4224 $sql .=
" WHERE t.entity IS NOT NULL";
4226 $sql .=
",".$this->db->prefix().
"usergroup_user as ug";
4227 $sql .=
" WHERE ((ug.fk_user = t.rowid";
4228 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
4229 $sql .=
" OR t.entity = 0)";
4232 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
4235 $sql .=
" WHERE 1 = 1";
4241 if ($errormessage) {
4242 $this->errors[] = $errormessage;
4243 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
4247 $sql .= $this->db->order($sortfield, $sortorder);
4249 $sql .= $this->db->plimit($limit + 1, $offset);
4254 $resql = $this->db->query($sql);
4256 $this->users = array();
4257 $num = $this->db->num_rows($resql);
4259 while ($obj = $this->db->fetch_object($resql)) {
4260 $line =
new self($this->db);
4261 $result = $line->fetch($obj->rowid);
4262 if ($result > 0 && !empty($line->id)) {
4263 $this->users[$obj->rowid] = clone $line;
4266 $this->db->free($resql);
4270 $this->errors[] = $this->db->lasterror();
4282 private $findUserIdByEmailCache;
4296 if (isset($this->findUserIdByEmailCache[$email])) {
4297 return $this->findUserIdByEmailCache[$email];
4300 $this->findUserIdByEmailCache[$email] = -1;
4302 $sql =
'SELECT rowid';
4303 $sql .=
' FROM '.$this->db->prefix().
'user';
4304 if (
getDolGlobalString(
'AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR')) {
4305 $sql .=
" WHERE email LIKE '%".$this->db->escape($this->db->escapeforlike($email)).
"%'";
4307 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4311 $resql = $this->db->query($sql);
4316 $obj = $this->db->fetch_object($resql);
4321 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4323 return $this->findUserIdByEmailCache[$email];
4334 if (empty($fromId) || empty($toId)) {
4341 $sqlDelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
4342 $sqlDelete .=
" WHERE fk_user = ".((int) $toId);
4344 dol_syslog(get_class($this).
"::clone_rights (delete default permissions)", LOG_DEBUG);
4346 if (!$this->db->query($sqlDelete)) {
4347 $this->db->rollback();
4352 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id)";
4353 $sql .=
" SELECT entity, ".((int) $toId).
", fk_id";
4354 $sql .=
" FROM ".$this->db->prefix().
"user_rights src";
4355 $sql .=
" WHERE fk_user = ".((int) $fromId);
4356 $sql .=
" AND NOT EXISTS (";
4357 $sql .=
" SELECT 1";
4358 $sql .=
" FROM ".$this->db->prefix().
"user_rights dest";
4359 $sql .=
" WHERE dest.entity = src.entity";
4360 $sql .=
" AND dest.fk_user = ".((int) $toId);
4361 $sql .=
" AND dest.fk_id = src.fk_id";
4364 dol_syslog(get_class($this).
"::clone_rights", LOG_DEBUG);
4367 if (!$this->db->query($sql)) {
4368 $this->db->rollback();
4372 $this->db->commit();
4389 $type = $this->table_element;
4392 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4393 $categorystatic =
new Categorie($this->db);
4395 $sql =
"INSERT INTO ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]).
" (fk_categorie, fk_user)";
4396 $sql .=
" SELECT fk_categorie, ".((int) $toId).
" FROM ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]);
4397 $sql .=
" WHERE fk_user = ".((int) $fromId);
4399 if (!$this->db->query($sql)) {
4400 $this->
error = $this->db->lasterror();
4401 $this->db->rollback();
4405 $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.