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 $datelastpassvalidation;
299 public $datelastlogin;
303 public $datepreviouslogin;
307 public $flagdelsessionsbefore;
315 public $ippreviouslogin;
319 public $datestartvalidity;
323 public $dateendvalidity;
343 public $all_permissions_are_loaded;
353 public $user_group_list;
358 private $_tab_loaded = array();
368 public $default_values;
373 public $lastsearch_values_tmp;
377 public $lastsearch_values;
382 public $users = array();
390 private $cache_childids;
396 public $accountancy_code_user_general;
401 public $accountancy_code;
433 public $dateemployment;
437 public $dateemploymentend;
442 public $default_c_exp_tax_cat;
447 public $ref_employee;
452 public $national_registration_number;
457 public $default_range;
462 public $fk_warehouse;
467 public $fk_establishment;
472 public $label_establishment;
483 public $usergroup_entity;
485 public $fields = array(
486 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
487 'lastname' => array(
'type' =>
'varchar(50)',
'label' =>
'Lastname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 20,
'searchall' => 1),
488 'firstname' => array(
'type' =>
'varchar(50)',
'label' =>
'Firstname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 10,
'searchall' => 1),
489 'ref_employee' => array(
'type' =>
'varchar(50)',
'label' =>
'RefEmployee',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 30,
'searchall' => 1),
490 'national_registration_number' => array(
'type' =>
'varchar(50)',
'label' =>
'NationalRegistrationNumber',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 40,
'searchall' => 1)
493 const STATUS_DISABLED = 0;
494 const STATUS_ENABLED = 1;
505 $this->ismultientitymanaged = 1;
506 $this->isextrafieldmanaged = 1;
508 $this->clicktodial_loaded = 0;
511 $this->all_permissions_are_loaded = 0;
512 $this->nb_rights = 0;
520 $this->rights->user =
new stdClass();
521 $this->rights->user->user =
new stdClass();
522 $this->rights->user->self =
new stdClass();
523 $this->rights->user->user_advance =
new stdClass();
524 $this->rights->user->self_advance =
new stdClass();
525 $this->rights->user->group_advance =
new stdClass();
542 public function fetch($id = 0, $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'', $fk_socpeople = 0, $use_email_oauth2 = 0)
547 $login = trim($login);
550 $sql =
"SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.civility as civility_code, u.birth, u.job,";
551 $sql .=
" u.email, u.email_oauth2, u.personal_email,";
552 $sql .=
" u.socialnetworks,";
553 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
554 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
555 $sql .=
" u.admin, u.login, u.note_private, u.note_public,";
556 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.api_key,";
557 $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,";
558 $sql .=
" u.statut as status, u.lang, u.entity,";
559 $sql .=
" u.datec as datec,";
560 $sql .=
" u.tms as datem,";
561 $sql .=
" u.datelastlogin as datel,";
562 $sql .=
" u.datepreviouslogin as datep,";
563 $sql .=
" u.flagdelsessionsbefore,";
564 $sql .=
" u.iplastlogin,";
565 $sql .=
" u.ippreviouslogin,";
566 $sql .=
" u.datelastpassvalidation,";
567 $sql .=
" u.datestartvalidity,";
568 $sql .=
" u.dateendvalidity,";
569 $sql .=
" u.photo as photo,";
570 $sql .=
" u.openid as openid,";
571 $sql .=
" u.accountancy_code_user_general,";
572 $sql .=
" u.accountancy_code,";
575 $sql .=
" u.salary,";
576 $sql .=
" u.salaryextra,";
577 $sql .=
" u.weeklyhours,";
579 $sql .=
" u.dateemployment, u.dateemploymentend,";
580 $sql .=
" u.fk_warehouse,";
581 $sql .=
" u.ref_ext,";
582 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
583 $sql .=
" u.national_registration_number,";
584 $sql .=
" u.ref_employee,";
585 $sql .=
" c.code as country_code, c.label as country,";
586 $sql .=
" d.code_departement as state_code, d.nom as state,";
587 $sql .=
" s.label as label_establishment, u.fk_establishment";
588 $sql .=
" FROM ".$this->db->prefix().
"user as u";
589 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as c ON u.fk_country = c.rowid";
590 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_departements as d ON u.fk_state = d.rowid";
591 $sql .=
" LEFT JOIN ".$this->db->prefix().
"establishment as s ON u.fk_establishment = s.rowid";
594 $sql .=
" WHERE u.rowid = ".((int) $id);
597 if ((! isModEnabled(
'multicompany') || !
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) && (! empty($user->entity))) {
598 $sql .=
" WHERE u.entity IN (0, " . ((int)
$conf->entity) .
")";
600 $sql .=
" WHERE u.entity IS NOT NULL";
604 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
605 $sql .=
" WHERE u.entity IS NOT NULL";
607 if ($entity !=
'' && $entity == 0) {
608 $sql .=
" WHERE u.entity = 0";
610 $sql .=
" WHERE u.entity IN (0, " . ((int) ($entity > 0 ? $entity :
$conf->entity)) .
")";
618 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->db->escape($login).
"')";
620 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
622 $sql .=
" AND (u.email = '".$this->db->escape($email).
"'";
623 if ($use_email_oauth2) {
624 $sql .=
" OR u.email_oauth2 = '".$this->db->escape($email).
"'";
627 } elseif ($fk_socpeople > 0) {
628 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
631 $sql .=
" ORDER BY u.entity ASC";
635 $sql .=
' '.$this->db->plimit(1);
638 $resql = $this->db->query($sql);
640 $num = $this->db->num_rows($resql);
642 $this->
error =
"USERDUPLICATEFOUND";
643 dol_syslog(get_class($this).
"::fetch more than 1 user found", LOG_WARNING);
645 $this->db->free($resql);
649 $obj = $this->db->fetch_object($resql);
651 $this->
id = $obj->rowid;
652 $this->
ref = $obj->rowid;
654 $this->ref_ext = $obj->ref_ext;
656 $this->ldap_sid = $obj->ldap_sid;
657 $this->civility_code = $obj->civility_code;
658 $this->lastname = $obj->lastname;
659 $this->firstname = $obj->firstname;
660 $this->ref_employee = $obj->ref_employee;
661 $this->national_registration_number = $obj->national_registration_number;
663 $this->employee = $obj->employee;
665 $this->login = $obj->login;
666 $this->gender = $obj->gender;
667 $this->birth = $this->db->jdate($obj->birth);
668 $this->pass_indatabase = $obj->pass;
669 $this->pass_indatabase_crypted = $obj->pass_crypted;
670 $this->pass = $obj->pass;
671 $this->pass_temp = $obj->pass_temp;
672 $this->datelastpassvalidation = $obj->datelastpassvalidation;
675 $this->
address = $obj->address;
676 $this->zip = $obj->zip;
677 $this->town = $obj->town;
679 $this->country_id = $obj->country_id;
680 $this->country_code = $obj->country_id ? $obj->country_code :
'';
683 $this->state_id = $obj->state_id;
684 $this->state_code = $obj->state_code;
685 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
687 $this->office_phone = $obj->office_phone;
688 $this->office_fax = $obj->office_fax;
689 $this->user_mobile = $obj->user_mobile;
690 $this->personal_mobile = $obj->personal_mobile;
691 $this->
email = $obj->email;
692 $this->email_oauth2 = $obj->email_oauth2;
693 $this->personal_email = $obj->personal_email;
694 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
696 $this->job = $obj->job;
697 $this->signature = $obj->signature;
698 $this->admin = $obj->admin;
699 $this->note_public = $obj->note_public;
700 $this->note_private = $obj->note_private;
702 $this->statut = $obj->status;
703 $this->
status = $obj->status;
705 $this->photo = $obj->photo;
706 $this->openid = $obj->openid;
707 $this->lang = $obj->lang;
708 $this->entity = $obj->entity;
710 $this->accountancy_code_user_general = $obj->accountancy_code_user_general;
711 $this->accountancy_code = $obj->accountancy_code;
713 $this->thm = $obj->thm;
714 $this->tjm = $obj->tjm;
715 $this->salary = $obj->salary;
716 $this->salaryextra = $obj->salaryextra;
717 $this->weeklyhours = $obj->weeklyhours;
718 $this->color = $obj->color;
719 $this->dateemployment = $this->db->jdate($obj->dateemployment);
720 $this->dateemploymentend = $this->db->jdate($obj->dateemploymentend);
722 $this->datec = $this->db->jdate($obj->datec);
723 $this->datem = $this->db->jdate($obj->datem);
724 $this->datelastlogin = $this->db->jdate($obj->datel);
725 $this->datepreviouslogin = $this->db->jdate($obj->datep);
726 $this->flagdelsessionsbefore = $this->db->jdate($obj->flagdelsessionsbefore,
'gmt');
727 $this->iplastlogin = $obj->iplastlogin;
728 $this->ippreviouslogin = $obj->ippreviouslogin;
729 $this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
730 $this->dateendvalidity = $this->db->jdate($obj->dateendvalidity);
732 $this->socid = $obj->fk_soc;
733 $this->contact_id = $obj->fk_socpeople;
734 $this->fk_member = $obj->fk_member;
735 $this->fk_user = $obj->fk_user;
736 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
737 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
739 $this->default_range = $obj->default_range;
740 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
741 $this->fk_warehouse = $obj->fk_warehouse;
742 $this->fk_establishment = $obj->fk_establishment;
743 $this->label_establishment = $obj->label_establishment;
747 if (!isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
755 $this->db->free($resql);
757 $this->
error =
"USERNOTFOUND";
758 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
760 $this->db->free($resql);
764 $this->
error = $this->db->lasterror();
769 if ($loadpersonalconf) {
775 $this->
error = $this->db->lasterror();
782 if (
GETPOSTINT(
'forceexternaluser') && $this->admin && empty($this->socid)) {
783 $this->socid =
GETPOSTINT(
'forceexternaluser');
800 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
801 $sql .=
" WHERE fk_user = ".((int) $this->
id);
802 $sql .=
" AND entity = ".((int)
$conf->entity);
804 $resql = $this->db->query($sql);
806 $num = $this->db->num_rows($resql);
809 $obj = $this->db->fetch_object($resql);
810 $p = (!empty($obj->param) ? $obj->param :
'');
812 $this->
conf->$p = $obj->value;
816 $this->db->free($resql);
820 $this->
error = $this->db->lasterror();
837 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
840 $result = $defaultValues->fetchAll(
'',
'', 0, 0,
'(t.user_id:in:0,'.$this->
id.
') AND (entity:in:'.(isset($this->entity) ? $this->entity :
$conf->entity).
','.
$conf->entity.
')');
843 if (!is_array($result) && $result < 0) {
847 } elseif (count($result) > 0) {
848 foreach ($result as $defval) {
849 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
850 $pagewithoutquerystring = $defval->page;
853 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
854 $pagewithoutquerystring = $reg[1];
855 $pagequeries = $reg[2];
857 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
861 if (!empty($this->default_values)) {
862 foreach ($this->default_values as $a => $b) {
863 foreach ($b as
$c => $d) {
864 krsort($this->default_values[$a][
$c]);
883 public function hasRight($module, $permlevel1, $permlevel2 =
'')
886 $moduletomoduletouse = array(
887 'category' =>
'categorie',
888 'compta' =>
'comptabilite',
889 'contract' =>
'contrat',
890 'member' =>
'adherent',
892 'order' =>
'commande',
893 'produit' =>
'product',
894 'productlot' =>
'product',
895 'project' =>
'projet',
896 'propale' =>
'propal',
897 'shipping' =>
'expedition',
898 'task' =>
'task@projet',
899 'fichinter' =>
'ficheinter',
900 'inventory' =>
'stock',
901 'invoice' =>
'facture',
902 'invoice_supplier' =>
'fournisseur',
903 'order_supplier' =>
'fournisseur',
904 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
905 'skill@hrm' =>
'all@hrm',
906 'job@hrm' =>
'all@hrm',
907 'position@hrm' =>
'all@hrm',
908 'facturerec' =>
'facture',
909 'margins' =>
'margin',
912 if (!empty($moduletomoduletouse[$module])) {
913 $module = $moduletomoduletouse[$module];
916 $moduleRightsMapping = array(
917 'product' =>
'produit',
918 'margin' =>
'margins',
919 'comptabilite' =>
'compta'
922 $rightsPath = $module;
923 if (!empty($moduleRightsMapping[$rightsPath])) {
924 $rightsPath = $moduleRightsMapping[$rightsPath];
928 $tmp = explode(
'@', $rightsPath, 2);
929 if (!empty($tmp[1])) {
930 if (strpos($module,
'@') !==
false) {
933 if ($tmp[0] != $tmp[1]) {
935 $rightsPath = $tmp[1];
936 $permlevel2 = $permlevel1;
937 $permlevel1 = $tmp[0];
940 $rightsPath = $tmp[1];
950 if (!isModEnabled($module)) {
955 if (!empty($this->socid)) {
956 if ($module ==
'societe' && ($permlevel1 ==
'creer' || $permlevel1 ==
'write')) {
959 if ($module ==
'societe' && $permlevel1 ==
'client' && $permlevel2 ==
'voir') {
962 if ($module ==
'societe' && $permlevel1 ==
'export') {
965 if ($module ==
'societe' && ($permlevel1 ==
'supprimer' || $permlevel1 ==
'delete')) {
971 if ($permlevel1 ==
'propale') {
972 $permlevel1 =
'propal';
974 if ($permlevel1 ==
'member') {
975 $permlevel1 =
'adherent';
977 if ($permlevel1 ==
'recruitmentcandidature') {
978 $permlevel1 =
'recruitmentjobposition';
983 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
988 if (!empty($this->rights->$rightsPath->$permlevel1)) {
989 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
990 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
994 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
995 return $this->rights->$rightsPath->$permlevel1->lire;
997 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
998 return $this->rights->$rightsPath->$permlevel1->creer;
1000 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
1001 return $this->rights->$rightsPath->$permlevel1->create;
1003 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
1004 return $this->rights->$rightsPath->$permlevel1->supprimer;
1008 if (!empty($this->rights->$rightsPath->$permlevel1)) {
1009 return $this->rights->$rightsPath->$permlevel1;
1013 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
1014 return $this->rights->$rightsPath->lire;
1016 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
1017 return $this->rights->$rightsPath->creer;
1019 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
1020 return $this->rights->$rightsPath->create;
1022 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
1023 return $this->rights->$rightsPath->supprimer;
1041 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1043 global $conf, $user, $langs;
1045 $entity = (empty($entity) ?
$conf->entity : $entity);
1047 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
1049 if (empty($this->
id)) {
1050 $this->
error =
'Try to call addrights on an object user with an empty id';
1060 $module = $perms = $subperms =
'';
1063 $sql =
"SELECT module, perms, subperms";
1064 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1065 $sql .=
" WHERE id = ".((int) $rid);
1066 $sql .=
" AND entity = ".((int) $entity);
1068 $result = $this->db->query($sql);
1070 $obj = $this->db->fetch_object($result);
1073 $module = $obj->module;
1074 $perms = $obj->perms;
1075 $subperms = $obj->subperms;
1083 $whereforadd =
"id=".((int) $rid);
1085 if (!empty($subperms)) {
1086 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
1087 } elseif (!empty($perms)) {
1088 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND (subperms IS NULL or subperms = ''))";
1094 if (!empty($allmodule)) {
1095 if ($allmodule ==
'allmodules') {
1096 $whereforadd =
'allmodules';
1098 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
1099 if (!empty($allperms)) {
1100 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
1108 if (!empty($whereforadd)) {
1111 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1112 $sql .=
" WHERE entity = ".((int) $entity);
1113 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
1114 $sql .=
" AND (".$whereforadd.
")";
1117 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1118 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1120 $sqldelete .=
") AND entity = ".((int) $entity);
1121 if (!$this->db->query($sqldelete)) {
1126 $resql = $this->db->query($sql);
1128 $num = $this->db->num_rows($resql);
1131 $obj = $this->db->fetch_object($resql);
1136 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
1137 if (!$this->db->query($sql)) {
1151 if (!$error && !$notrigger) {
1152 $langs->load(
"other");
1153 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
1164 $this->db->rollback();
1167 $this->db->commit();
1184 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1186 global $conf, $user, $langs;
1190 $entity = (!empty($entity) ? $entity :
$conf->entity);
1195 $module = $perms = $subperms =
'';
1199 $sql =
"SELECT module, perms, subperms";
1200 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1201 $sql .=
" WHERE id = '".((int) $rid).
"'";
1202 $sql .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1204 $result = $this->db->query($sql);
1206 $obj = $this->db->fetch_object($result);
1209 $module = $obj->module;
1210 $perms = $obj->perms;
1211 $subperms = $obj->subperms;
1219 $wherefordel =
"id=".((int) $rid);
1221 if ($subperms ==
'lire' || $subperms ==
'read') {
1222 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1224 if ($perms ==
'lire' || $perms ==
'read') {
1225 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1231 if (!empty($allmodule)) {
1232 if ($allmodule ==
'allmodules') {
1233 $wherefordel =
'allmodules';
1235 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1236 if (!empty($allperms)) {
1237 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1244 if (!empty($wherefordel)) {
1247 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1248 $sql .=
" WHERE entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1249 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1250 $sql .=
" AND (".$wherefordel.
")";
1254 if ($this->admin == 1) {
1255 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1256 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1257 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1258 $sql .=
" AND id NOT IN (358)";
1261 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1262 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1265 $sqldelete .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1267 $resql = $this->db->query($sqldelete);
1274 if (!$error && !$notrigger) {
1275 $langs->load(
"other");
1276 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1287 $this->db->rollback();
1290 $this->db->commit();
1304 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1306 $this->nb_rights = 0;
1307 $this->all_permissions_are_loaded = 0;
1308 $this->_tab_loaded = array();
1324 $alreadyloaded =
false;
1326 if (empty($forcereload)) {
1327 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1329 $alreadyloaded =
true;
1332 if (!empty($this->all_permissions_are_loaded)) {
1334 $alreadyloaded =
true;
1339 if (!isset($this->rights) || !is_object($this->rights)) {
1342 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1343 $this->rights->user =
new stdClass();
1348 if (!$alreadyloaded) {
1350 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1351 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1352 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1353 $sql .=
" WHERE r.id = ur.fk_id";
1359 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') ?
"1," :
"").
$conf->entity.
")";
1363 $sql .=
" AND r.entity = ".((int)
$conf->entity).
" AND ur.entity = ".((int)
$conf->entity);
1365 $sql .=
" AND ur.fk_user = ".((int) $this->
id);
1366 $sql .=
" AND r.perms IS NOT NULL";
1368 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1371 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1374 $resql = $this->db->query($sql);
1376 $num = $this->db->num_rows($resql);
1379 $obj = $this->db->fetch_object($resql);
1382 $module = $obj->module;
1383 $perms = $obj->perms;
1384 $subperms = $obj->subperms;
1386 if (!empty($perms)) {
1387 if (!empty($module)) {
1388 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1389 $this->rights->$module =
new stdClass();
1391 if (!empty($subperms)) {
1392 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1393 $this->rights->$module->$perms =
new stdClass();
1395 if (empty($this->rights->$module->$perms->$subperms)) {
1398 $this->rights->$module->$perms->$subperms = 1;
1400 if (empty($this->rights->$module->$perms)) {
1403 $this->rights->$module->$perms = 1;
1410 $this->db->free($resql);
1414 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms, r.entity";
1415 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1416 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1417 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1418 $sql .=
" WHERE r.id = gr.fk_id";
1423 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1424 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1426 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1429 $sql .=
" AND gr.entity = ".((int)
$conf->entity);
1433 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1434 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1437 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1438 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1439 $sql .=
" AND r.perms IS NOT NULL";
1441 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1444 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1447 $resql = $this->db->query($sql);
1449 $num = $this->db->num_rows($resql);
1452 $obj = $this->db->fetch_object($resql);
1455 $module = $obj->module;
1456 $perms = $obj->perms;
1457 $subperms = $obj->subperms;
1459 if (!empty($perms)) {
1460 if (!empty($module)) {
1461 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1462 $this->rights->$module =
new stdClass();
1464 if (!empty($subperms)) {
1465 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1466 $this->rights->$module->$perms =
new stdClass();
1468 if (empty($this->rights->$module->$perms->$subperms)) {
1471 $this->rights->$module->$perms->$subperms = 1;
1474 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1475 if (empty($this->rights->$module->$perms)) {
1478 $this->rights->$module->$perms = 1;
1486 $this->db->free($resql);
1490 if (!empty($this->admin)) {
1491 if (empty($this->rights->user->user)) {
1492 $this->rights->user->user =
new stdClass();
1494 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1495 foreach ($listofpermtotest as $permtotest) {
1496 if (empty($this->rights->user->user->$permtotest)) {
1497 $this->rights->user->user->$permtotest = 1;
1501 if (empty($this->rights->user->self)) {
1502 $this->rights->user->self =
new stdClass();
1504 $listofpermtotest = array(
'creer',
'password');
1505 foreach ($listofpermtotest as $permtotest) {
1506 if (empty($this->rights->user->self->$permtotest)) {
1507 $this->rights->user->self->$permtotest = 1;
1513 if (empty($this->rights->user->user_advance)) {
1514 $this->rights->user->user_advance =
new stdClass();
1516 $listofpermtotest = array(
'readperms',
'write');
1517 foreach ($listofpermtotest as $permtotest) {
1518 if (empty($this->rights->user->user_advance->$permtotest)) {
1519 $this->rights->user->user_advance->$permtotest = 1;
1523 if (empty($this->rights->user->self_advance)) {
1524 $this->rights->user->self_advance =
new stdClass();
1526 $listofpermtotest = array(
'readperms',
'writeperms');
1527 foreach ($listofpermtotest as $permtotest) {
1528 if (empty($this->rights->user->self_advance->$permtotest)) {
1529 $this->rights->user->self_advance->$permtotest = 1;
1533 if (empty($this->rights->user->group_advance)) {
1534 $this->rights->user->group_advance =
new stdClass();
1536 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1537 foreach ($listofpermtotest as $permtotest) {
1538 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1539 $this->rights->user->group_advance->$permtotest = 1;
1547 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1548 $this->rights->propal = $this->rights->propale;
1550 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1551 $this->rights->propale = $this->rights->propal;
1558 $this->all_permissions_are_loaded = 1;
1561 $this->_tab_loaded[$moduletag] = 1;
1578 public function getrights($moduletag =
'', $forcereload = 0)
1591 global $conf, $langs, $user;
1596 if (isset($this->statut)) {
1597 if ($this->statut == $status) {
1600 } elseif (isset($this->
status) && $this->
status == $status) {
1607 $sql =
"UPDATE ".$this->db->prefix().
"user";
1608 $sql .=
" SET statut = ".((int) $status);
1609 $sql .=
" WHERE rowid = ".((int) $this->
id);
1610 $result = $this->db->query($sql);
1612 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1615 $this->context[
'actionmsg'] =
'User '.$this->login.
' disabled';
1617 $this->context[
'actionmsg'] =
'User '.$this->login.
' enabled';
1620 $result = $this->
call_trigger(
'USER_ENABLEDISABLE', $user);
1628 $this->db->rollback();
1632 $this->statut = $status;
1633 $this->db->commit();
1650 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1651 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1662 global $conf, $langs;
1668 $this->
fetch($this->
id);
1670 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1673 if (isModEnabled(
'hrm')) {
1677 'hrm_evaluation' => array(
'label' =>
'EvaluationCard',
'filter' =>
"fk_user = ".((
int) $this->
id)),
1678 'hrm_job_user' => array(
'label' =>
'EmployeePosition',
'filter' =>
"fk_user = ".((
int) $this->
id)),
1679 'hrm_skillrank' => array(
'label' =>
'Skill',
'filter' =>
"objecttype = 'user' AND fk_object = ".((
int) $this->
id)),
1681 foreach ($hrmtables as $hrmtable => $hrminfo) {
1682 $sanitizedfilter = $hrminfo[
'filter'];
1683 $sql =
"SELECT COUNT(rowid) as nb FROM ".$this->db->prefix().$this->db->sanitize($hrmtable).
" WHERE ".$sanitizedfilter;
1684 $resql = $this->db->query($sql);
1686 $obj = $this->db->fetch_object($resql);
1687 if ($obj && $obj->nb > 0) {
1688 $langs->loadLangs(array(
'errors',
'hrm'));
1689 $this->
error = $langs->trans(
"ErrorRecordHasAtLeastOneChildOfType", $this->login, $langs->transnoentitiesnoconv($hrminfo[
'label']));
1690 $this->errors[] = $this->error;
1691 $this->db->rollback();
1699 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1701 if (!$error && !$this->db->query($sql)) {
1703 $this->
error = $this->db->lasterror();
1707 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1708 if (!$error && !$this->db->query($sql)) {
1710 $this->
error = $this->db->lasterror();
1714 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1715 if (!$error && !$this->db->query($sql)) {
1717 $this->
error = $this->db->lasterror();
1721 $sql =
"DELETE FROM ".$this->db->prefix().
"bookmark WHERE fk_user = ".((int) $this->
id);
1722 if (!$error && !$this->db->query($sql)) {
1724 $this->
error = $this->db->lasterror();
1728 if ($this->contact_id > 0) {
1729 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1730 if (!$error && !$this->db->query($sql)) {
1732 $this->
error = $this->db->lasterror();
1741 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1747 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1748 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1749 if (!$this->db->query($sql)) {
1751 $this->
error = $this->db->lasterror();
1760 $this->db->rollback();
1765 $this->db->commit();
1768 $this->db->rollback();
1780 public function create($user, $notrigger = 0)
1782 global $conf, $langs;
1788 $this->civility_code = trim((
string) $this->civility_code);
1789 $this->login = trim((
string) $this->login);
1790 if (!isset($this->entity)) {
1791 $this->entity =
$conf->entity;
1793 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1795 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1799 $langs->load(
"errors");
1800 $this->
error = $langs->trans(
"ErrorBadEMail", $this->
email);
1803 if (empty($this->login)) {
1804 $langs->load(
"errors");
1805 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1807 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1808 $langs->load(
"errors");
1809 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1820 $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).
"'";
1821 $resqltochecklogin = $this->db->query($sqltochecklogin);
1822 if ($resqltochecklogin) {
1823 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1824 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1825 $langs->load(
"errors");
1826 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1828 $this->db->rollback();
1831 $this->db->free($resqltochecklogin);
1834 if (!empty($this->
email)) {
1835 $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).
"'";
1836 $resqltochecklogin = $this->db->query($sqltochecklogin);
1837 if ($resqltochecklogin) {
1838 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1839 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1840 $langs->load(
"errors");
1841 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->
email);
1843 $this->db->rollback();
1846 $this->db->free($resqltochecklogin);
1851 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, entity)";
1852 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->db->escape($this->login).
"', '".$this->db->escape($this->ldap_sid).
"', ".((int) $this->entity).
")";
1853 $result = $this->db->query($sql);
1855 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1857 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1861 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1862 $this->db->rollback();
1867 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1868 $langs->load(
"stocks");
1870 $entrepot =
new Entrepot($this->db);
1871 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1872 $entrepot->libelle = $entrepot->label;
1873 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1874 $entrepot->statut = 1;
1875 $entrepot->country_id = $mysoc->country_id;
1877 $warehouseid = $entrepot->create($user);
1879 $this->fk_warehouse = $warehouseid;
1883 $result = $this->
update($user, 1, 1);
1885 $this->db->rollback();
1899 $this->db->commit();
1904 $this->db->rollback();
1908 $this->
error = $this->db->lasterror();
1909 $this->db->rollback();
1927 global $conf, $user, $langs;
1933 $this->civility_code = $contact->civility_code;
1934 $this->lastname = $contact->lastname;
1935 $this->firstname = $contact->firstname;
1937 $this->
email = $contact->email;
1938 $this->socialnetworks = $contact->socialnetworks;
1939 $this->office_phone = $contact->phone_pro;
1940 $this->office_fax = $contact->fax;
1941 $this->user_mobile = $contact->phone_mobile;
1942 $this->
address = $contact->address;
1943 $this->zip = $contact->zip;
1944 $this->town = $contact->town;
1946 $this->state_id = $contact->state_id;
1947 $this->country_id = $contact->country_id;
1948 $this->employee = 0;
1950 if (empty($login)) {
1951 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1952 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1954 $this->login = $login;
1959 $result = $this->
create($user, 1);
1961 $sql =
"UPDATE ".$this->db->prefix().
"user";
1962 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1963 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1964 if ($contact->socid > 0) {
1965 $sql .=
", fk_soc=".((int) $contact->socid);
1967 $sql .=
" WHERE rowid=".((int) $this->
id);
1969 $resql = $this->db->query($sql);
1971 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1973 $this->context[
'createfromcontact'] =
'createfromcontact';
1979 $this->db->rollback();
1984 $this->db->commit();
1987 $this->
error = $this->db->error();
1989 $this->db->rollback();
1994 dol_syslog(get_class($this).
"::create_from_contact - 0");
1996 $this->db->rollback();
2017 $this->civility_code = $member->civility_code;
2018 $this->lastname = $member->lastname;
2019 $this->firstname = $member->firstname;
2020 $this->gender = $member->gender;
2021 $this->
email = $member->email;
2022 $this->fk_member = $member->id;
2023 $this->
address = $member->address;
2024 $this->zip = $member->zip;
2025 $this->town = $member->town;
2027 $this->state_id = $member->state_id;
2028 $this->country_id = $member->country_id;
2029 $this->socialnetworks = $member->socialnetworks;
2031 $this->pass = $member->pass;
2032 $this->pass_crypted = $member->pass_indatabase_crypted;
2034 if (empty($login)) {
2035 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
2038 $this->login = $login;
2043 $result = $this->
create($user);
2045 if (!empty($this->pass)) {
2046 $newpass = $this->
setPassword($user, $this->pass);
2047 if (is_int($newpass) && $newpass < 0) {
2050 } elseif (!empty($this->pass_crypted)) {
2051 $sql =
"UPDATE ".$this->db->prefix().
"user";
2052 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
2053 $sql .=
" WHERE rowid=".((int) $this->
id);
2055 $resql = $this->db->query($sql);
2061 if ($result > 0 && $member->socid) {
2062 $sql =
"UPDATE ".$this->db->prefix().
"user";
2063 $sql .=
" SET fk_soc=".((int) $member->socid);
2064 $sql .=
" WHERE rowid=".((int) $this->
id);
2066 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
2067 $resql = $this->db->query($sql);
2069 $this->db->commit();
2072 $this->
error = $this->db->lasterror();
2074 $this->db->rollback();
2081 $this->db->commit();
2085 $this->db->rollback();
2103 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
2104 $sql .=
" WHERE bydefault = 1";
2105 $sql .=
" AND entity = ".((int)
$conf->entity);
2107 $resql = $this->db->query($sql);
2109 $num = $this->db->num_rows($resql);
2112 $row = $this->db->fetch_row($resql);
2116 $this->db->free($resql);
2120 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
2121 $result = $this->db->query($sql);
2123 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
2124 $result = $this->db->query($sql);
2144 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
2146 global $conf, $langs;
2148 if (empty($this->country_id) && !empty($this->country_code)) {
2149 $country_id =
getCountry($this->country_code,
'3');
2150 $this->country_id = is_int($country_id) ? $country_id : 0;
2153 $nbrowsaffected = 0;
2156 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
2159 $this->civility_code = trim((
string) $this->civility_code);
2160 $this->lastname = trim((
string) $this->lastname);
2161 $this->firstname = trim((
string) $this->firstname);
2162 $this->ref_employee = trim((
string) $this->ref_employee);
2163 $this->national_registration_number = trim((
string) $this->national_registration_number);
2164 $this->employee = ($this->employee > 0 ? $this->employee : 0);
2165 $this->login = trim((
string) $this->login);
2166 $this->gender = trim((
string) $this->gender);
2168 $this->pass = trim((
string) $this->pass);
2169 $this->api_key = trim((
string) $this->api_key);
2170 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
2171 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
2174 $this->zip = trim((
string) $this->zip);
2175 $this->town = trim((
string) $this->town);
2177 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
2178 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
2179 $this->office_phone = trim((
string) $this->office_phone);
2180 $this->office_fax = trim((
string) $this->office_fax);
2181 $this->user_mobile = trim((
string) $this->user_mobile);
2182 $this->personal_mobile = trim((
string) $this->personal_mobile);
2184 $this->personal_email = trim((
string) $this->personal_email);
2186 $this->job = trim((
string) $this->job);
2187 $this->signature = trim((
string) $this->signature);
2188 $this->note_public = trim((
string) $this->note_public);
2189 $this->note_private = trim((
string) $this->note_private);
2190 $this->openid = trim((
string) $this->openid);
2191 $this->admin = ($this->admin > 0 ? $this->admin : 0);
2193 $this->accountancy_code_user_general = trim((
string) $this->accountancy_code_user_general);
2194 $this->accountancy_code = trim((
string) $this->accountancy_code);
2195 $this->color = trim(str_replace(
'#',
'', (
string) $this->color));
2196 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
2197 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
2199 $this->birth = empty($this->birth) ?
'' : $this->birth;
2200 $this->fk_warehouse = (int) $this->fk_warehouse;
2201 $this->fk_establishment = (int) $this->fk_establishment;
2206 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
2209 $langs->load(
"errors");
2210 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
2213 if (empty($this->login)) {
2214 $langs->load(
"errors");
2215 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
2217 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
2218 $langs->load(
"errors");
2219 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
2226 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->oldcopy->login != $this->login) {
2227 $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).
"'";
2228 $resqltochecklogin = $this->db->query($sqltochecklogin);
2229 if ($resqltochecklogin) {
2230 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2231 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2232 $langs->load(
"errors");
2233 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
2235 $this->db->rollback();
2240 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && !empty($this->email) && $this->oldcopy->email != $this->email) {
2241 $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).
"'";
2242 $resqltochecklogin = $this->db->query($sqltochecklogin);
2243 if ($resqltochecklogin) {
2244 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2245 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2246 $langs->load(
"errors");
2247 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
2249 $this->db->rollback();
2256 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2257 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
2258 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
2259 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
2260 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
2261 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
2262 $sql .=
", employee = ".(int) $this->employee;
2263 $sql .=
", login = '".$this->db->escape($this->login).
"'";
2264 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
2265 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
2266 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
2267 if (!empty($user->admin)) {
2268 $sql .=
", admin = ".(int) $this->admin;
2270 $sql .=
", address = '".$this->db->escape($this->address).
"'";
2271 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
2272 $sql .=
", town = '".$this->db->escape($this->town).
"'";
2273 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".((
int) $this->state_id).
"'" :
"null");
2274 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".((
int) $this->country_id).
"'" :
"null");
2275 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
2276 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
2277 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
2278 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
2279 $sql .=
", email = '".$this->db->escape($this->email).
"'";
2280 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
2281 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
2282 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2283 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2284 $sql .=
", accountancy_code_user_general = '".$this->db->escape($this->accountancy_code_user_general).
"'";
2285 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2286 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2287 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2288 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2289 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2290 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2291 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2292 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2293 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2294 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2295 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".((int) $this->fk_user).
"'" :
"null");
2296 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".((int) $this->fk_user_expense_validator).
"'" :
"null");
2297 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".((int) $this->fk_user_holiday_validator).
"'" :
"null");
2298 if (isset($this->thm) || $this->thm !=
'') {
2299 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2301 if (isset($this->tjm) || $this->tjm !=
'') {
2302 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2304 if (isset($this->salary) || $this->salary !=
'') {
2305 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2307 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2308 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2310 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2311 if (isModEnabled(
'multicompany') && !empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2316 $sql .=
", entity = ".((int) $this->entity);
2318 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2319 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2320 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2321 $sql .=
", fk_establishment = ".($this->fk_establishment > 0 ? $this->fk_establishment :
"null");
2322 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2323 $sql .=
" WHERE rowid = ".((int) $this->
id);
2325 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2326 $resql = $this->db->query($sql);
2328 $nbrowsaffected += $this->db->affected_rows($resql);
2331 if (!empty($this->pass)) {
2332 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2334 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2335 if (is_int($result) && $result < 0) {
2342 if ($this->fk_member > 0) {
2343 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2344 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2345 $resql = $this->db->query($sql);
2347 $this->
error = $this->db->error();
2348 $this->db->rollback();
2353 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2354 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2355 $resql = $this->db->query($sql);
2357 $this->
error = $this->db->error();
2358 $this->db->rollback();
2362 if ($nbrowsaffected) {
2363 if ($this->fk_member > 0 && !$nosyncmember) {
2364 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2366 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2371 $result = $adh->fetch($this->fk_member);
2374 $adh->civility_code = $this->civility_code;
2375 $adh->firstname = $this->firstname;
2376 $adh->lastname = $this->lastname;
2377 $adh->login = $this->login;
2378 $adh->gender = $this->gender;
2379 $adh->birth = $this->birth;
2381 $adh->pass = $this->pass;
2383 $adh->address = $this->address;
2384 $adh->town = $this->town;
2385 $adh->zip = $this->zip;
2386 $adh->state_id = $this->state_id;
2387 $adh->country_id = $this->country_id;
2389 $adh->email = $this->email;
2391 $adh->socialnetworks = $this->socialnetworks;
2393 $adh->phone = $this->office_phone;
2394 $adh->phone_mobile = $this->user_mobile;
2396 $adh->default_lang = $this->lang;
2398 $adh->user_id = $this->id;
2399 $adh->user_login = $this->login;
2401 $result = $adh->update($user, 0, 1, 0);
2403 $this->
error = $adh->error;
2404 $this->errors = $adh->errors;
2405 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2408 } elseif ($result < 0) {
2409 $this->
error = $adh->error;
2410 $this->errors = $adh->errors;
2415 if ($this->contact_id > 0 && !$nosynccontact) {
2416 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2418 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2421 $tmpobj =
new Contact($this->db);
2422 $result = $tmpobj->fetch($this->contact_id);
2425 $tmpobj->civility_code = $this->civility_code;
2426 $tmpobj->firstname = $this->firstname;
2427 $tmpobj->lastname = $this->lastname;
2428 $tmpobj->login = $this->login;
2429 $tmpobj->gender = $this->gender;
2430 $tmpobj->birth = $this->birth;
2434 $tmpobj->email = $this->email;
2436 $tmpobj->socialnetworks = $this->socialnetworks;
2438 $tmpobj->phone_pro = $this->office_phone;
2439 $tmpobj->phone_mobile = $this->user_mobile;
2440 $tmpobj->fax = $this->office_fax;
2442 $tmpobj->default_lang = $this->lang;
2444 $tmpobj->address = $this->address;
2445 $tmpobj->town = $this->town;
2446 $tmpobj->zip = $this->zip;
2447 $tmpobj->state_id = $this->state_id;
2448 $tmpobj->country_id = $this->country_id;
2450 $tmpobj->user_id = $this->id;
2451 $tmpobj->user_login = $this->login;
2453 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2455 $this->
error = $tmpobj->error;
2456 $this->errors = $tmpobj->errors;
2457 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2461 $this->
error = $tmpobj->error;
2462 $this->errors = $tmpobj->errors;
2478 if (!$error && !$notrigger) {
2488 $this->db->commit();
2489 return $nbrowsaffected;
2492 $this->db->rollback();
2496 $this->
error = $this->db->lasterror();
2497 $this->db->rollback();
2516 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2517 $sql .=
" datepreviouslogin = datelastlogin,";
2518 $sql .=
" ippreviouslogin = iplastlogin,";
2519 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2520 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2521 $sql .=
" tms = tms";
2522 $sql .=
" WHERE rowid = ".((int) $this->
id);
2524 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2525 $resql = $this->db->query($sql);
2527 $this->datepreviouslogin = $this->datelastlogin;
2528 $this->datelastlogin = $now;
2529 $this->ippreviouslogin = $this->iplastlogin;
2530 $this->iplastlogin = $userremoteip;
2533 $this->
error = $this->db->lasterror().
' sql='.$sql;
2551 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2553 global $conf, $langs;
2554 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2558 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2565 $password_crypted =
null;
2567 if (empty($passwordalreadycrypted)) {
2570 $modGeneratePassClass =
'modGeneratePass'.ucfirst(
$conf->global->USER_PASSWORD_GENERATED);
2572 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2573 if (class_exists($modGeneratePassClass)) {
2574 $modGeneratePass =
new $modGeneratePassClass($this->db,
$conf, $langs, $user);
2575 '@phan-var-force ModeleGenPassword $modGeneratePass';
2578 $modGeneratePass->WithoutAmbi = 0;
2581 $testpassword = $modGeneratePass->validatePassword($password);
2582 if (!$testpassword) {
2583 $this->
error = $modGeneratePass->error;
2591 $password_crypted =
dol_hash($password);
2595 if (!$changelater) {
2596 if (!is_object($this->oldcopy)) {
2597 $this->oldcopy = clone $this;
2604 $sql =
"UPDATE ".$this->db->prefix().
"user";
2605 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2606 $sql .=
" datelastpassvalidation = '".$this->db->idate(
dol_now()).
"',";
2607 $sql .=
" pass_temp = null";
2608 if (!empty($flagdelsessionsbefore)) {
2609 $sql .=
", flagdelsessionsbefore = '".$this->db->idate($now - 5,
'gmt').
"'";
2612 $sql .=
", pass = null";
2614 $sql .=
", pass = '".$this->db->escape($password).
"'";
2616 $sql .=
" WHERE rowid = ".((int) $this->
id);
2618 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2620 $result = $this->db->query($sql);
2622 if ($this->db->affected_rows($result)) {
2623 $this->pass = $password;
2624 $this->pass_indatabase = $password;
2625 $this->pass_indatabase_crypted = (string) $password_crypted;
2627 if ($this->fk_member && !$nosyncmember) {
2628 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2633 $result = $adh->fetch($this->fk_member);
2636 $result = $adh->setPassword($user, $this->pass, (!
getDolGlobalString(
'DATABASE_PWD_ENCRYPTED') ? 0 : 1), 1);
2637 if (is_int($result) && $result < 0) {
2638 $this->
error = $adh->error;
2643 $this->
error = $adh->error;
2648 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2651 $user->context[
'audit'] =
'login='.$user->login;
2652 if (!empty($flagdelsessionsbefore)) {
2653 $user->context[
'audit'] .=
" - flagdelsessionsbefore set to '".$this->db->idate($now - 5,
'gmt').
"'";
2656 if (!$error && !$notrigger) {
2658 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2661 $this->db->rollback();
2667 $this->db->commit();
2670 $this->db->rollback();
2674 $this->db->rollback();
2681 $sql =
"UPDATE ".$this->db->prefix().
"user";
2682 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2683 $sql .=
" WHERE rowid = ".((int) $this->
id);
2685 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2686 $result = $this->db->query($sql);
2708 global $conf, $langs;
2711 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2723 $outputlangs = $langs;
2727 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2729 $appli =
getDolGlobalString(
'MAIN_APPLICATION_TITLE', constant(
'DOL_APPLICATION_TITLE'));
2731 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2734 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
2735 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2737 if (!$changelater) {
2738 $url = $urlwithroot.
'/';
2743 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2745 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2746 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2747 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2748 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2751 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2753 $mesg .= $user->getFullName($outputlangs);
2756 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2757 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.
$conf->file->instance_unique_id));
2758 if (isModEnabled(
'multicompany')) {
2759 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2762 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2766 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2767 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2768 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2769 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2771 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2772 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2773 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2776 $trackid =
'use'.$this->id;
2777 $sendcontext =
'passwordreset';
2798 if ($mailfile->sendfile()) {
2801 $langs->trans(
"errors");
2802 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2814 return $this->error;
2827 $sql =
"SELECT url, login, pass, poste ";
2828 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2829 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2831 $resql = $this->db->query($sql);
2833 if ($this->db->num_rows($resql)) {
2834 $obj = $this->db->fetch_object($resql);
2836 $this->clicktodial_url = $obj->url;
2837 $this->clicktodial_login = $obj->login;
2838 $this->clicktodial_password = $obj->pass;
2839 $this->clicktodial_poste = $obj->poste;
2842 $this->clicktodial_loaded = 1;
2844 $this->db->free($resql);
2847 $this->
error = $this->db->error();
2863 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2864 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2866 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2868 $result = $this->db->query($sql);
2870 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2871 $sql .=
" (fk_user,url,login,pass,poste)";
2872 $sql .=
" VALUES (".$this->id;
2873 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2874 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2875 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2876 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2878 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2880 $result = $this->db->query($sql);
2882 $this->db->commit();
2885 $this->db->rollback();
2886 $this->
error = $this->db->lasterror();
2904 global $conf, $langs, $user;
2910 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2911 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2912 $sql .=
" AND fk_usergroup = ".((int) $group);
2913 $sql .=
" AND entity = ".((int) $entity);
2915 $result = $this->db->query($sql);
2917 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2918 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2920 $result = $this->db->query($sql);
2922 if (!$error && !$notrigger) {
2923 $this->context = array(
'audit' => $langs->trans(
"UserSetInGroup"),
'newgroupid' => $group);
2934 $this->db->commit();
2938 $this->db->rollback();
2942 $this->
error = $this->db->lasterror();
2943 $this->db->rollback();
2960 global $conf, $langs, $user;
2966 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2967 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2968 $sql .=
" AND fk_usergroup = ".((int) $group);
2969 if (empty($entity)) {
2970 $sql .=
" AND entity IN (0, 1)";
2972 $sql .=
" AND entity = ".((int) $entity);
2975 $result = $this->db->query($sql);
2977 if (!$error && !$notrigger) {
2978 $this->context = array(
'audit' => $langs->trans(
"UserRemovedFromGroup"),
'oldgroupid' => $group);
2989 $this->db->commit();
2992 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2993 $this->db->rollback();
2997 $this->
error = $this->db->lasterror();
2998 $this->db->rollback();
3012 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
3019 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
3042 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
3044 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3045 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
3059 global $conf, $langs, $menumanager;
3062 $infologin = $params[
'infologin'] ?? 0;
3063 $option = $params[
'option'] ??
'';
3066 if (!empty($this->photo)) {
3067 $photo =
'<div class="photointooltip floatright">';
3068 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
3070 $data[
'photo'] = $photo;
3075 $data[
'opendiv'] =
'<div class="centpercent divtooltip">';
3076 $data[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
3078 if (!empty($this->login)) {
3081 if (!empty($this->job)) {
3085 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
3086 $phonelist = array();
3087 if ($this->office_phone) {
3088 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
3090 if ($this->office_fax) {
3091 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
3093 if ($this->user_mobile) {
3094 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
3096 $data[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
3098 if (!empty($this->admin)) {
3099 $data[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
3101 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
3102 $langs->load(
"companies");
3103 $data[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
3106 if (!empty($this->socid)) {
3107 $thirdpartystatic =
new Societe($this->db);
3108 $thirdpartystatic->fetch($this->socid);
3110 if (empty($params[
'hidethirdpartylogo'])) {
3111 $companyimg =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3113 $company =
' ('.$langs->trans(
"Company").
': '.($companyimg ? $companyimg :
img_picto(
'',
'company')).
' '.
dol_string_nohtmltag($thirdpartystatic->name).
')';
3115 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
3116 $data[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
3117 $data[
'closediv'] =
'</div>';
3119 if ($infologin > 0) {
3120 $data[
'newlinelogin'] =
'<br>';
3121 $data[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
3124 $data[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.
$conf->entity.
' (User entity '.$this->entity.
')';
3127 $data[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
3128 $data[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
3131 $data[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
3133 $data[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
3134 $data[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag(
$conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
3136 $data[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
3137 if (
$conf->browser->layout ==
'phone') {
3138 $data[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
3140 if (!empty($_SESSION[
"disablemodules"])) {
3141 $data[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(implode(
', ', explode(
',', $_SESSION[
"disablemodules"])));
3163 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'valignmiddle', $save_lastsearch_value = -1)
3165 global $langs, $hookmanager, $user;
3167 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
3178 'objecttype' => $this->element,
3179 'infologin' => $infologin,
3180 'option' => $option,
3181 'hidethirdpartylogo' => $hidethirdpartylogo,
3183 $classfortooltip =
'classfortooltip';
3186 $classfortooltip =
'classforajaxtooltip';
3187 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3194 if (!empty($this->socid)) {
3195 $thirdpartystatic =
new Societe($this->db);
3196 $thirdpartystatic->fetch($this->socid);
3197 if (empty($hidethirdpartylogo)) {
3198 $companylink =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3202 if ($infologin < 0) {
3206 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
3207 if ($option ==
'leave') {
3208 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
3211 if ($option !=
'nolink') {
3213 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3214 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3215 $add_save_lastsearch_values = 1;
3217 if ($add_save_lastsearch_values) {
3218 $url .=
'&save_lastsearch_values=1';
3222 $linkstart =
'<a href="'.$url.
'"';
3224 if (empty($notooltip)) {
3226 $langs->load(
"users");
3227 $label = $langs->trans(
"ShowUser");
3228 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
3230 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
3231 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
3233 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
3236 $linkstart .= $linkclose.
'>';
3240 $result .= (($option ==
'nolink') ?
'' : $linkstart);
3241 if ($withpictoimg) {
3242 $paddafterimage =
'';
3243 if (abs((
int) $withpictoimg) == 1) {
3244 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3247 if ($withpictoimg > 0) {
3248 $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>';
3251 $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>';
3255 if ($withpictoimg > -2 && $withpictoimg != 2) {
3257 $result .=
'<span class="nopadding usertext'.((!isset($this->
status) || $this->status) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
3259 if ($mode ==
'login') {
3265 $result .=
'</span>';
3268 $result .= (($option ==
'nolink') ?
'' : $linkend);
3271 $result .= $companylink;
3274 $hookmanager->initHooks(array(
'userdao'));
3275 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
3276 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3278 $result = $hookmanager->resPrint;
3280 $result .= $hookmanager->resPrint;
3295 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
3297 global $langs, $user;
3301 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3305 if ((!$user->hasRight(
'user',
'user',
'lire') && $this->id != $user->id)) {
3309 if ($option ==
'xxx') {
3310 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3314 if ($option ==
'nolink') {
3319 $result .= $linkstart;
3320 if ($withpictoimg) {
3321 $paddafterimage =
'';
3322 if (abs($withpictoimg) == 1) {
3323 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3326 if ($withpictoimg > 0) {
3327 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3330 $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>';
3334 $result .= $this->login;
3335 $result .= $linkend;
3348 return $this->
LibStatut(isset($this->statut) ? (
int) $this->statut : (int) $this->
status, $mode);
3364 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3367 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3368 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3369 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3370 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3373 $statusType =
'status5';
3374 if ($status == self::STATUS_ENABLED) {
3375 $statusType =
'status4';
3378 $label = $this->labelStatus[$status];
3379 $labelshort = $this->labelStatusShort[$status];
3382 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3383 $statusType =
'status3';
3384 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3386 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3387 $statusType =
'status2';
3388 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3391 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3406 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3408 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3409 $return .=
'<div class="info-box info-box-sm">';
3410 $return .=
'<span class="info-box-icon bg-infobox-action">';
3413 if (!empty($this->photo)) {
3415 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3424 $return .=
'</span>';
3425 $return .=
'<div class="info-box-content">';
3426 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3427 if (isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3428 $return .=
img_picto($langs->trans(
"SuperAdministratorDesc"),
'redstar',
'class="valignmiddle paddingright paddingleft"');
3429 } elseif ($this->admin) {
3430 $return .=
img_picto($langs->trans(
"AdministratorDesc"),
'star',
'class="valignmiddle paddingright paddingleft"');
3432 $return .=
'</span>';
3433 if ($selected >= 0) {
3434 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3436 if (property_exists($this,
'label')) {
3437 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3440 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->
email.
'</span>';
3442 if (method_exists($this,
'getLibStatut')) {
3443 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3445 $return .=
'</div>';
3446 $return .=
'</div>';
3447 $return .=
'</div>';
3471 } elseif ($mode == 1) {
3473 } elseif ($mode == 2) {
3489 global $conf, $langs;
3495 $keymodified =
false;
3504 'LDAP_FIELD_FULLNAME' =>
'fullname',
3505 'LDAP_FIELD_NAME' =>
'lastname',
3506 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3507 'LDAP_FIELD_LOGIN' =>
'login',
3508 'LDAP_FIELD_LOGIN_SAMBA' =>
'login',
3509 'LDAP_FIELD_PHONE' =>
'office_phone',
3510 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3511 'LDAP_FIELD_FAX' =>
'office_fax',
3512 'LDAP_FIELD_MAIL' =>
'email',
3513 'LDAP_FIELD_SID' =>
'ldap_sid',
3517 foreach ($ldapkey as $constname => $varname) {
3523 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->$varname != $this->oldcopy->$varname) {
3524 $keymodified =
true;
3529 foreach ($socialnetworks as $key => $value) {
3530 if (!empty($this->socialnetworks[$value[
'label']]) &&
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))) {
3531 $info[
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))] = $this->socialnetworks[$value[
'label']];
3547 $soc =
new Societe($this->db);
3548 $soc->fetch($this->socid);
3551 if ($soc->client == 1) {
3552 $info[
"businessCategory"] =
"Customers";
3554 if ($soc->client == 2) {
3555 $info[
"businessCategory"] =
"Prospects";
3557 if ($soc->fournisseur == 1) {
3558 $info[
"businessCategory"] =
"Suppliers";
3563 if (!empty($this->pass)) {
3576 if ($this->pass_indatabase_crypted &&
getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED')) {
3580 } elseif (!empty($this->pass_indatabase)) {
3592 $info[
"objectclass"][4] =
"phpgwContact";
3594 $info[
'uidnumber'] = $this->id;
3596 $info[
'phpgwTz'] = 0;
3597 $info[
'phpgwMailType'] =
'INTERNET';
3598 $info[
'phpgwMailHomeType'] =
'INTERNET';
3600 $info[
"phpgwContactTypeId"] =
'n';
3601 $info[
"phpgwContactCatId"] = 0;
3602 $info[
"phpgwContactAccess"] =
"public";
3610 $info[
"phpgwContactOwner"] = 1;
3613 $info[
"rfc822Mailbox"] = $this->email;
3615 if ($this->user_mobile) {
3616 $info[
"phpgwCellTelephoneNumber"] = $this->user_mobile;
3625 $groupslist = $usergroup->listGroupsForUser($this->
id);
3627 if (!empty($groupslist)) {
3628 foreach ($groupslist as $groupforuser) {
3635 $info[
getDolGlobalString(
'LDAP_FIELD_HOMEDIRECTORY')] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->login";
3651 global $user, $langs;
3657 $this->
ref =
'SPECIMEN';
3658 $this->specimen = 1;
3660 $this->lastname =
'DOLIBARR';
3661 $this->firstname =
'SPECIMEN';
3662 $this->gender =
'man';
3663 $this->note_public =
'This is a note public';
3664 $this->note_private =
'This is a note private';
3665 $this->
email =
'email@specimen.com';
3666 $this->personal_email =
'personalemail@specimen.com';
3667 $this->socialnetworks = array(
3668 'skype' =>
'skypepseudo',
3669 'twitter' =>
'twitterpseudo',
3670 'facebook' =>
'facebookpseudo',
3671 'linkedin' =>
'linkedinpseudo',
3673 $this->office_phone =
'0999999999';
3674 $this->office_fax =
'0999999998';
3675 $this->user_mobile =
'0999999997';
3676 $this->personal_mobile =
'0999999996';
3678 $this->login =
'dolibspec';
3679 $this->pass =
'dolibSpec+@123';
3682 $this->datec = $now;
3683 $this->datem = $now;
3685 $this->datelastlogin = $now;
3686 $this->iplastlogin =
'127.0.0.1';
3687 $this->datepreviouslogin = $now;
3688 $this->ippreviouslogin =
'127.0.0.1';
3705 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
3706 $sql .=
" u.tms as date_modification, u.entity";
3707 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3708 $sql .=
" WHERE u.rowid = ".((int) $id);
3710 $result = $this->db->query($sql);
3712 if ($this->db->num_rows($result)) {
3713 $obj = $this->db->fetch_object($result);
3715 $this->
id = $obj->rowid;
3717 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3718 $this->date_creation = $this->db->jdate($obj->datec);
3719 $this->date_modification = $this->db->jdate($obj->date_modification);
3720 $this->entity = $obj->entity;
3723 $this->db->free($result);
3737 $sql =
"SELECT count(mc.email) as nb";
3738 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3739 $sql .=
" WHERE mc.email = '".$this->db->escape($this->
email).
"'";
3740 $sql .=
" AND mc.statut NOT IN (-1,0)";
3742 $resql = $this->db->query($sql);
3744 $obj = $this->db->fetch_object($resql);
3747 $this->db->free($resql);
3750 $this->
error = $this->db->error();
3767 $sql =
"SELECT count(rowid) as nb";
3768 $sql .=
" FROM ".$this->db->prefix().
"user";
3769 if ($option ==
'superadmin') {
3770 $sql .=
" WHERE entity = 0";
3772 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3773 if ($limitTo ==
'active') {
3774 $sql .=
" AND statut = 1";
3778 $sql .=
" AND admin = ".(int) $admin;
3781 $resql = $this->db->query($sql);
3783 $obj = $this->db->fetch_object($resql);
3784 $nb = (int) $obj->nb;
3786 $this->db->free($resql);
3789 $this->
error = $this->db->lasterror();
3805 global $user, $conf;
3810 $this->firstname = $ldapuser->$tmpvar;
3812 $this->lastname = $ldapuser->$tmpvar;
3814 $this->login = $ldapuser->$tmpvar;
3816 $this->pass = $ldapuser->$tmpvar;
3818 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3821 $this->office_phone = $ldapuser->$tmpvar;
3823 $this->user_mobile = $ldapuser->$tmpvar;
3825 $this->office_fax = $ldapuser->$tmpvar;
3827 $this->
email = $ldapuser->$tmpvar;
3828 foreach ($socialnetworks as $key => $value) {
3830 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3833 $this->ldap_sid = $ldapuser->$tmpvar;
3836 $this->job = $ldapuser->$tmpvar;
3838 $this->note_public = $ldapuser->$tmpvar;
3840 $result = $this->
update($user);
3842 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3858 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3859 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3861 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3862 $res = $this->db->query($sql);
3865 while ($rec = $this->db->fetch_array($res)) {
3866 $user =
new User($this->db);
3867 $user->fetch($rec[
'rowid']);
3887 $this->parentof = array();
3890 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3891 $sql .=
" FROM ".$this->db->prefix().
"user";
3892 $sql .=
" WHERE fk_user <> 0";
3893 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3895 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3896 $resql = $this->db->query($sql);
3898 while ($obj = $this->db->fetch_object($resql)) {
3899 $this->parentof[$obj->id_son] = $obj->id_parent;
3925 global $hookmanager;
3928 $hookmanager->initHooks(array(
'userdao'));
3930 $this->users = array();
3936 $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";
3937 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3939 $parameters = array();
3940 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3942 $sql .= $hookmanager->resPrint;
3944 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3947 $sql .=
" AND ".$filter;
3950 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3951 $resql = $this->db->query($sql);
3954 while ($obj = $this->db->fetch_object($resql)) {
3955 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3956 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3957 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3958 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3959 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3960 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3961 $this->users[$obj->rowid][
'login'] = $obj->login;
3962 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3963 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3964 $this->users[$obj->rowid][
'email'] = $obj->email;
3965 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3966 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3967 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3969 $this->users[$obj->rowid][
'fullpath'] =
'';
3970 $this->users[$obj->rowid][
'fullname'] =
'';
3971 $this->users[$obj->rowid][
'level'] = 0;
3980 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3981 foreach ($this->users as $key => $val) {
3984 $this->
error =
'ErrorLoopInHierarchy';
3990 if ($deleteafterid) {
3992 $keyfilter1 =
'^'.$deleteafterid.
'$';
3993 $keyfilter2 =
'_'.$deleteafterid.
'$';
3994 $keyfilter3 =
'^'.$deleteafterid.
'_';
3995 $keyfilter4 =
'_'.$deleteafterid.
'_';
3996 foreach (array_keys($this->users) as $key) {
3997 $fullpath = (string) $this->users[$key][
'fullpath'];
3998 if (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
3999 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath)) {
4000 unset($this->users[$key]);
4005 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
4006 $this->users =
dol_sort_array($this->users,
'fullname',
'asc', 1, 0, 1);
4010 return $this->users;
4023 $childids = array();
4025 if (isset($this->cache_childids[$this->
id])) {
4026 $childids = $this->cache_childids[$this->id];
4031 $idtoscan = $this->id;
4033 dol_syslog(
"Build childid for id = ".$idtoscan);
4034 foreach ($this->users as $id => $val) {
4036 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
4037 $childids[$val[
'id']] = $val[
'id'];
4044 if ($treeresult < 0) {
4045 dol_syslog(get_class($this).
"::getAllChildIds got a truncated tree: ".$this->
error, LOG_WARNING);
4046 return $addcurrentuser ? array($this->
id => $this->
id) : $childids;
4049 $this->cache_childids[$this->id] = $childids;
4051 if ($addcurrentuser) {
4052 $childids[$this->id] = $this->id;
4072 if (!empty($this->users[$id_user][
'fullpath'])) {
4074 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
4079 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
4080 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
4082 $cursor_user = $id_user;
4084 $useridfound = array($id_user);
4085 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
4086 if (in_array($this->parentof[$cursor_user], $useridfound)) {
4087 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
4090 $useridfound[] = $this->parentof[$cursor_user];
4091 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
4092 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
4094 $cursor_user = $this->parentof[$cursor_user];
4098 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
4130 $this->nb = array();
4132 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
4133 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4134 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
4135 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
4136 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
4137 $sql .=
" AND ug.fk_user = u.rowid";
4139 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4141 $sql .=
" AND u.statut > 0";
4144 $resql = $this->db->query($sql);
4146 while ($obj = $this->db->fetch_object($resql)) {
4147 $this->nb[
"users"] = $obj->nb;
4149 $this->db->free($resql);
4153 $this->
error = $this->db->error();
4169 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4171 global $conf, $user, $langs;
4173 $langs->load(
"user");
4180 $modele =
'bluesky';
4184 $modelpath =
"core/modules/user/doc/";
4186 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4200 $user_property =
'';
4202 if (empty($rowid)) {
4206 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
4207 $sql .=
" FROM ".$this->db->prefix().
"user";
4208 $sql .=
" WHERE rowid = ".((int) $rowid);
4210 $resql = $this->db->query($sql);
4212 $nump = $this->db->num_rows($resql);
4215 $obj = $this->db->fetch_object($resql);
4217 if ($mode ==
'email') {
4218 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
4219 } elseif ($mode ==
'mobile') {
4220 $user_property = $obj->user_mobile;
4221 } elseif ($mode ==
'name') {
4225 return $user_property;
4245 $encodedsecurekey =
dol_hash(
$conf->file->instance_unique_id.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
4246 if (isModEnabled(
'multicompany')) {
4247 $entity_qr =
'&entity='.((int)
$conf->entity);
4252 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
4253 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
4256 if ($typeofurl ==
'internal') {
4257 $urlwithroot = DOL_URL_ROOT;
4260 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
4276 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $entityfilter =
false)
4278 global $conf, $user;
4280 $sql =
"SELECT t.rowid";
4281 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
4283 if ($entityfilter) {
4285 if (!empty($user->admin) && empty($user->entity) &&
$conf->entity == 1) {
4286 $sql .=
" WHERE t.entity IS NOT NULL";
4288 $sql .=
" WHERE t.entity = 0 OR EXISTS (";
4289 $sql .=
" SELECT ug.rowid FROM " . $this->db->prefix() .
"usergroup_user as ug";
4290 $sql .=
" WHERE ug.fk_user = t.rowid AND ug.entity IN (" .
getEntity(
'usergroup') .
"))";
4293 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
4296 $sql .=
" WHERE 1 = 1";
4302 if ($errormessage) {
4303 $this->errors[] = $errormessage;
4304 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
4308 $sql .= $this->db->order($sortfield, $sortorder);
4310 $sql .= $this->db->plimit($limit + 1, $offset);
4315 $resql = $this->db->query($sql);
4317 $this->users = array();
4318 $num = $this->db->num_rows($resql);
4320 while ($obj = $this->db->fetch_object($resql)) {
4321 $line =
new self($this->db);
4322 $result = $line->fetch($obj->rowid);
4323 if ($result > 0 && !empty($line->id)) {
4324 $this->users[$obj->rowid] = clone $line;
4327 $this->db->free($resql);
4331 $this->errors[] = $this->db->lasterror();
4343 private $findUserIdByEmailCache;
4357 if (isset($this->findUserIdByEmailCache[$email])) {
4358 return $this->findUserIdByEmailCache[$email];
4361 $this->findUserIdByEmailCache[$email] = -1;
4363 $sql =
'SELECT rowid';
4364 $sql .=
' FROM '.$this->db->prefix().
'user';
4365 if (
getDolGlobalString(
'AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR')) {
4366 $sql .=
" WHERE email LIKE '%".$this->db->escape($this->db->escapeforlike($email)).
"%'";
4368 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4372 $resql = $this->db->query($sql);
4377 $obj = $this->db->fetch_object($resql);
4382 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4384 return $this->findUserIdByEmailCache[$email];
4395 if (empty($fromId) || empty($toId)) {
4402 $sqlDelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
4403 $sqlDelete .=
" WHERE fk_user = ".((int) $toId);
4405 dol_syslog(get_class($this).
"::clone_rights (delete default permissions)", LOG_DEBUG);
4407 if (!$this->db->query($sqlDelete)) {
4408 $this->db->rollback();
4413 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id)";
4414 $sql .=
" SELECT entity, ".((int) $toId).
", fk_id";
4415 $sql .=
" FROM ".$this->db->prefix().
"user_rights src";
4416 $sql .=
" WHERE fk_user = ".((int) $fromId);
4417 $sql .=
" AND NOT EXISTS (";
4418 $sql .=
" SELECT 1";
4419 $sql .=
" FROM ".$this->db->prefix().
"user_rights dest";
4420 $sql .=
" WHERE dest.entity = src.entity";
4421 $sql .=
" AND dest.fk_user = ".((int) $toId);
4422 $sql .=
" AND dest.fk_id = src.fk_id";
4425 dol_syslog(get_class($this).
"::clone_rights", LOG_DEBUG);
4428 if (!$this->db->query($sql)) {
4429 $this->db->rollback();
4433 $this->db->commit();
4450 $type = $this->table_element;
4453 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4454 $categorystatic =
new Categorie($this->db);
4456 $sql =
"INSERT INTO ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]).
" (fk_categorie, fk_user)";
4457 $sql .=
" SELECT fk_categorie, ".((int) $toId).
" FROM ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]);
4458 $sql .=
" WHERE fk_user = ".((int) $fromId);
4460 if (!$this->db->query($sql)) {
4461 $this->
error = $this->db->lasterror();
4462 $this->db->rollback();
4466 $this->db->commit();
global $dolibarr_main_url_root
Class to manage members of a foundation.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage categories.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
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.
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)
getNomUrl($withpictoimg=0, $option='', $infologin=0, $notooltip=0, $maxlen=24, $hidethirdpartylogo=0, $mode='', $morecss='valignmiddle', $save_lastsearch_value=-1)
Return a HTML link to the user card (with optionally the picto) Use this->id,this->lastname,...
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.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
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, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
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.
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
div refaddress div address
conf($dolibarr_main_document_root)
Load conf file (file must exists)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
global $dolibarr_main_demo
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
dol_verifyHash($chain, $hash, $type='0')
Compute a hash and compare it to the given one For backward compatibility reasons,...
dolEncrypt($chain, $key='', $ciphering='', $forceseed='')
Encode a string with a symmetric encryption.
dolGetLdapPasswordHash($password, $type='md5')
Returns a specific ldap hash of a password.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.