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 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1675 if (!$error && !$this->db->query($sql)) {
1677 $this->
error = $this->db->lasterror();
1681 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1682 if (!$error && !$this->db->query($sql)) {
1684 $this->
error = $this->db->lasterror();
1688 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1689 if (!$error && !$this->db->query($sql)) {
1691 $this->
error = $this->db->lasterror();
1695 if ($this->contact_id > 0) {
1696 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1697 if (!$error && !$this->db->query($sql)) {
1699 $this->
error = $this->db->lasterror();
1708 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1714 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1715 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1716 if (!$this->db->query($sql)) {
1718 $this->
error = $this->db->lasterror();
1727 $this->db->rollback();
1732 $this->db->commit();
1735 $this->db->rollback();
1747 public function create($user, $notrigger = 0)
1749 global $conf, $langs;
1755 $this->civility_code = trim((
string) $this->civility_code);
1756 $this->login = trim((
string) $this->login);
1757 if (!isset($this->entity)) {
1758 $this->entity =
$conf->entity;
1760 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1762 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1766 $langs->load(
"errors");
1767 $this->
error = $langs->trans(
"ErrorBadEMail", $this->
email);
1770 if (empty($this->login)) {
1771 $langs->load(
"errors");
1772 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1774 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1775 $langs->load(
"errors");
1776 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1787 $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).
"'";
1788 $resqltochecklogin = $this->db->query($sqltochecklogin);
1789 if ($resqltochecklogin) {
1790 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1791 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1792 $langs->load(
"errors");
1793 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1795 $this->db->rollback();
1798 $this->db->free($resqltochecklogin);
1801 if (!empty($this->
email)) {
1802 $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).
"'";
1803 $resqltochecklogin = $this->db->query($sqltochecklogin);
1804 if ($resqltochecklogin) {
1805 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1806 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1807 $langs->load(
"errors");
1808 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->
email);
1810 $this->db->rollback();
1813 $this->db->free($resqltochecklogin);
1818 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, entity)";
1819 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->db->escape($this->login).
"', '".$this->db->escape($this->ldap_sid).
"', ".((int) $this->entity).
")";
1820 $result = $this->db->query($sql);
1822 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1824 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1828 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1829 $this->db->rollback();
1834 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1835 $langs->load(
"stocks");
1837 $entrepot =
new Entrepot($this->db);
1838 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1839 $entrepot->libelle = $entrepot->label;
1840 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1841 $entrepot->statut = 1;
1842 $entrepot->country_id = $mysoc->country_id;
1844 $warehouseid = $entrepot->create($user);
1846 $this->fk_warehouse = $warehouseid;
1850 $result = $this->
update($user, 1, 1);
1852 $this->db->rollback();
1866 $this->db->commit();
1871 $this->db->rollback();
1875 $this->
error = $this->db->lasterror();
1876 $this->db->rollback();
1894 global $conf, $user, $langs;
1900 $this->civility_code = $contact->civility_code;
1901 $this->lastname = $contact->lastname;
1902 $this->firstname = $contact->firstname;
1904 $this->
email = $contact->email;
1905 $this->socialnetworks = $contact->socialnetworks;
1906 $this->office_phone = $contact->phone_pro;
1907 $this->office_fax = $contact->fax;
1908 $this->user_mobile = $contact->phone_mobile;
1909 $this->
address = $contact->address;
1910 $this->zip = $contact->zip;
1911 $this->town = $contact->town;
1913 $this->state_id = $contact->state_id;
1914 $this->country_id = $contact->country_id;
1915 $this->employee = 0;
1917 if (empty($login)) {
1918 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1919 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1921 $this->login = $login;
1926 $result = $this->
create($user, 1);
1928 $sql =
"UPDATE ".$this->db->prefix().
"user";
1929 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1930 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1931 if ($contact->socid > 0) {
1932 $sql .=
", fk_soc=".((int) $contact->socid);
1934 $sql .=
" WHERE rowid=".((int) $this->
id);
1936 $resql = $this->db->query($sql);
1938 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1940 $this->context[
'createfromcontact'] =
'createfromcontact';
1946 $this->db->rollback();
1951 $this->db->commit();
1954 $this->
error = $this->db->error();
1956 $this->db->rollback();
1961 dol_syslog(get_class($this).
"::create_from_contact - 0");
1963 $this->db->rollback();
1984 $this->civility_code = $member->civility_code;
1985 $this->lastname = $member->lastname;
1986 $this->firstname = $member->firstname;
1987 $this->gender = $member->gender;
1988 $this->
email = $member->email;
1989 $this->fk_member = $member->id;
1990 $this->
address = $member->address;
1991 $this->zip = $member->zip;
1992 $this->town = $member->town;
1994 $this->state_id = $member->state_id;
1995 $this->country_id = $member->country_id;
1996 $this->socialnetworks = $member->socialnetworks;
1998 $this->pass = $member->pass;
1999 $this->pass_crypted = $member->pass_indatabase_crypted;
2001 if (empty($login)) {
2002 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
2005 $this->login = $login;
2010 $result = $this->
create($user);
2012 if (!empty($this->pass)) {
2013 $newpass = $this->
setPassword($user, $this->pass);
2014 if (is_int($newpass) && $newpass < 0) {
2017 } elseif (!empty($this->pass_crypted)) {
2018 $sql =
"UPDATE ".$this->db->prefix().
"user";
2019 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
2020 $sql .=
" WHERE rowid=".((int) $this->
id);
2022 $resql = $this->db->query($sql);
2028 if ($result > 0 && $member->socid) {
2029 $sql =
"UPDATE ".$this->db->prefix().
"user";
2030 $sql .=
" SET fk_soc=".((int) $member->socid);
2031 $sql .=
" WHERE rowid=".((int) $this->
id);
2033 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
2034 $resql = $this->db->query($sql);
2036 $this->db->commit();
2039 $this->
error = $this->db->lasterror();
2041 $this->db->rollback();
2048 $this->db->commit();
2052 $this->db->rollback();
2070 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
2071 $sql .=
" WHERE bydefault = 1";
2072 $sql .=
" AND entity = ".((int)
$conf->entity);
2074 $resql = $this->db->query($sql);
2076 $num = $this->db->num_rows($resql);
2079 $row = $this->db->fetch_row($resql);
2083 $this->db->free($resql);
2087 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
2088 $result = $this->db->query($sql);
2090 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
2091 $result = $this->db->query($sql);
2111 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
2113 global $conf, $langs;
2115 if (empty($this->country_id) && !empty($this->country_code)) {
2116 $country_id =
getCountry($this->country_code,
'3');
2117 $this->country_id = is_int($country_id) ? $country_id : 0;
2120 $nbrowsaffected = 0;
2123 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
2126 $this->civility_code = trim((
string) $this->civility_code);
2127 $this->lastname = trim((
string) $this->lastname);
2128 $this->firstname = trim((
string) $this->firstname);
2129 $this->ref_employee = trim((
string) $this->ref_employee);
2130 $this->national_registration_number = trim((
string) $this->national_registration_number);
2131 $this->employee = ($this->employee > 0 ? $this->employee : 0);
2132 $this->login = trim((
string) $this->login);
2133 $this->gender = trim((
string) $this->gender);
2135 $this->pass = trim((
string) $this->pass);
2136 $this->api_key = trim((
string) $this->api_key);
2137 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
2138 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
2141 $this->zip = trim((
string) $this->zip);
2142 $this->town = trim((
string) $this->town);
2144 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
2145 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
2146 $this->office_phone = trim((
string) $this->office_phone);
2147 $this->office_fax = trim((
string) $this->office_fax);
2148 $this->user_mobile = trim((
string) $this->user_mobile);
2149 $this->personal_mobile = trim((
string) $this->personal_mobile);
2151 $this->personal_email = trim((
string) $this->personal_email);
2153 $this->job = trim((
string) $this->job);
2154 $this->signature = trim((
string) $this->signature);
2155 $this->note_public = trim((
string) $this->note_public);
2156 $this->note_private = trim((
string) $this->note_private);
2157 $this->openid = trim((
string) $this->openid);
2158 $this->admin = ($this->admin > 0 ? $this->admin : 0);
2160 $this->accountancy_code_user_general = trim((
string) $this->accountancy_code_user_general);
2161 $this->accountancy_code = trim((
string) $this->accountancy_code);
2162 $this->color = trim(str_replace(
'#',
'', (
string) $this->color));
2163 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
2164 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
2166 $this->birth = empty($this->birth) ?
'' : $this->birth;
2167 $this->fk_warehouse = (int) $this->fk_warehouse;
2168 $this->fk_establishment = (int) $this->fk_establishment;
2173 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
2176 $langs->load(
"errors");
2177 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
2180 if (empty($this->login)) {
2181 $langs->load(
"errors");
2182 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
2184 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
2185 $langs->load(
"errors");
2186 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
2193 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->oldcopy->login != $this->login) {
2194 $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).
"'";
2195 $resqltochecklogin = $this->db->query($sqltochecklogin);
2196 if ($resqltochecklogin) {
2197 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2198 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2199 $langs->load(
"errors");
2200 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
2202 $this->db->rollback();
2207 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && !empty($this->email) && $this->oldcopy->email != $this->email) {
2208 $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).
"'";
2209 $resqltochecklogin = $this->db->query($sqltochecklogin);
2210 if ($resqltochecklogin) {
2211 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2212 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2213 $langs->load(
"errors");
2214 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
2216 $this->db->rollback();
2223 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2224 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
2225 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
2226 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
2227 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
2228 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
2229 $sql .=
", employee = ".(int) $this->employee;
2230 $sql .=
", login = '".$this->db->escape($this->login).
"'";
2231 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
2232 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
2233 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
2234 if (!empty($user->admin)) {
2235 $sql .=
", admin = ".(int) $this->admin;
2237 $sql .=
", address = '".$this->db->escape($this->address).
"'";
2238 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
2239 $sql .=
", town = '".$this->db->escape($this->town).
"'";
2240 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".((
int) $this->state_id).
"'" :
"null");
2241 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".((
int) $this->country_id).
"'" :
"null");
2242 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
2243 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
2244 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
2245 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
2246 $sql .=
", email = '".$this->db->escape($this->email).
"'";
2247 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
2248 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
2249 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2250 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2251 $sql .=
", accountancy_code_user_general = '".$this->db->escape($this->accountancy_code_user_general).
"'";
2252 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2253 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2254 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2255 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2256 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2257 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2258 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2259 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2260 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2261 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2262 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".((int) $this->fk_user).
"'" :
"null");
2263 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".((int) $this->fk_user_expense_validator).
"'" :
"null");
2264 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".((int) $this->fk_user_holiday_validator).
"'" :
"null");
2265 if (isset($this->thm) || $this->thm !=
'') {
2266 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2268 if (isset($this->tjm) || $this->tjm !=
'') {
2269 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2271 if (isset($this->salary) || $this->salary !=
'') {
2272 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2274 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2275 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2277 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2278 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2279 $sql .=
", entity = ".((int) $this->entity);
2281 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2282 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2283 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2284 $sql .=
", fk_establishment = ".($this->fk_establishment > 0 ? $this->fk_establishment :
"null");
2285 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2286 $sql .=
" WHERE rowid = ".((int) $this->
id);
2288 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2289 $resql = $this->db->query($sql);
2291 $nbrowsaffected += $this->db->affected_rows($resql);
2294 if (!empty($this->pass)) {
2295 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2297 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2298 if (is_int($result) && $result < 0) {
2305 if ($this->fk_member > 0) {
2306 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2307 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2308 $resql = $this->db->query($sql);
2310 $this->
error = $this->db->error();
2311 $this->db->rollback();
2316 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2317 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2318 $resql = $this->db->query($sql);
2320 $this->
error = $this->db->error();
2321 $this->db->rollback();
2325 if ($nbrowsaffected) {
2326 if ($this->fk_member > 0 && !$nosyncmember) {
2327 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2329 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2334 $result = $adh->fetch($this->fk_member);
2337 $adh->civility_code = $this->civility_code;
2338 $adh->firstname = $this->firstname;
2339 $adh->lastname = $this->lastname;
2340 $adh->login = $this->login;
2341 $adh->gender = $this->gender;
2342 $adh->birth = $this->birth;
2344 $adh->pass = $this->pass;
2346 $adh->address = $this->address;
2347 $adh->town = $this->town;
2348 $adh->zip = $this->zip;
2349 $adh->state_id = $this->state_id;
2350 $adh->country_id = $this->country_id;
2352 $adh->email = $this->email;
2354 $adh->socialnetworks = $this->socialnetworks;
2356 $adh->phone = $this->office_phone;
2357 $adh->phone_mobile = $this->user_mobile;
2359 $adh->default_lang = $this->lang;
2361 $adh->user_id = $this->id;
2362 $adh->user_login = $this->login;
2364 $result = $adh->update($user, 0, 1, 0);
2366 $this->
error = $adh->error;
2367 $this->errors = $adh->errors;
2368 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2371 } elseif ($result < 0) {
2372 $this->
error = $adh->error;
2373 $this->errors = $adh->errors;
2378 if ($this->contact_id > 0 && !$nosynccontact) {
2379 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2381 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2384 $tmpobj =
new Contact($this->db);
2385 $result = $tmpobj->fetch($this->contact_id);
2388 $tmpobj->civility_code = $this->civility_code;
2389 $tmpobj->firstname = $this->firstname;
2390 $tmpobj->lastname = $this->lastname;
2391 $tmpobj->login = $this->login;
2392 $tmpobj->gender = $this->gender;
2393 $tmpobj->birth = $this->birth;
2397 $tmpobj->email = $this->email;
2399 $tmpobj->socialnetworks = $this->socialnetworks;
2401 $tmpobj->phone_pro = $this->office_phone;
2402 $tmpobj->phone_mobile = $this->user_mobile;
2403 $tmpobj->fax = $this->office_fax;
2405 $tmpobj->default_lang = $this->lang;
2407 $tmpobj->address = $this->address;
2408 $tmpobj->town = $this->town;
2409 $tmpobj->zip = $this->zip;
2410 $tmpobj->state_id = $this->state_id;
2411 $tmpobj->country_id = $this->country_id;
2413 $tmpobj->user_id = $this->id;
2414 $tmpobj->user_login = $this->login;
2416 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2418 $this->
error = $tmpobj->error;
2419 $this->errors = $tmpobj->errors;
2420 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2424 $this->
error = $tmpobj->error;
2425 $this->errors = $tmpobj->errors;
2441 if (!$error && !$notrigger) {
2451 $this->db->commit();
2452 return $nbrowsaffected;
2455 $this->db->rollback();
2459 $this->
error = $this->db->lasterror();
2460 $this->db->rollback();
2479 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2480 $sql .=
" datepreviouslogin = datelastlogin,";
2481 $sql .=
" ippreviouslogin = iplastlogin,";
2482 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2483 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2484 $sql .=
" tms = tms";
2485 $sql .=
" WHERE rowid = ".((int) $this->
id);
2487 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2488 $resql = $this->db->query($sql);
2490 $this->datepreviouslogin = $this->datelastlogin;
2491 $this->datelastlogin = $now;
2492 $this->ippreviouslogin = $this->iplastlogin;
2493 $this->iplastlogin = $userremoteip;
2496 $this->
error = $this->db->lasterror().
' sql='.$sql;
2514 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2516 global $conf, $langs;
2517 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2521 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2528 $password_crypted =
null;
2530 if (empty($passwordalreadycrypted)) {
2533 $modGeneratePassClass =
'modGeneratePass'.ucfirst(
$conf->global->USER_PASSWORD_GENERATED);
2535 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2536 if (class_exists($modGeneratePassClass)) {
2537 $modGeneratePass =
new $modGeneratePassClass($this->db,
$conf, $langs, $user);
2538 '@phan-var-force ModeleGenPassword $modGeneratePass';
2541 $modGeneratePass->WithoutAmbi = 0;
2544 $testpassword = $modGeneratePass->validatePassword($password);
2545 if (!$testpassword) {
2546 $this->
error = $modGeneratePass->error;
2554 $password_crypted =
dol_hash($password);
2558 if (!$changelater) {
2559 if (!is_object($this->oldcopy)) {
2560 $this->oldcopy = clone $this;
2567 $sql =
"UPDATE ".$this->db->prefix().
"user";
2568 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2569 $sql .=
" datelastpassvalidation = '".$this->db->idate(
dol_now()).
"',";
2570 $sql .=
" pass_temp = null";
2571 if (!empty($flagdelsessionsbefore)) {
2572 $sql .=
", flagdelsessionsbefore = '".$this->db->idate($now - 5,
'gmt').
"'";
2575 $sql .=
", pass = null";
2577 $sql .=
", pass = '".$this->db->escape($password).
"'";
2579 $sql .=
" WHERE rowid = ".((int) $this->
id);
2581 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2583 $result = $this->db->query($sql);
2585 if ($this->db->affected_rows($result)) {
2586 $this->pass = $password;
2587 $this->pass_indatabase = $password;
2588 $this->pass_indatabase_crypted = (string) $password_crypted;
2590 if ($this->fk_member && !$nosyncmember) {
2591 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2596 $result = $adh->fetch($this->fk_member);
2599 $result = $adh->setPassword($user, $this->pass, (!
getDolGlobalString(
'DATABASE_PWD_ENCRYPTED') ? 0 : 1), 1);
2600 if (is_int($result) && $result < 0) {
2601 $this->
error = $adh->error;
2606 $this->
error = $adh->error;
2611 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2614 $user->context[
'audit'] =
'login='.$user->login;
2615 if (!empty($flagdelsessionsbefore)) {
2616 $user->context[
'audit'] .=
" - flagdelsessionsbefore set to '".$this->db->idate($now - 5,
'gmt').
"'";
2619 if (!$error && !$notrigger) {
2621 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2624 $this->db->rollback();
2630 $this->db->commit();
2633 $this->db->rollback();
2637 $this->db->rollback();
2644 $sql =
"UPDATE ".$this->db->prefix().
"user";
2645 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2646 $sql .=
" WHERE rowid = ".((int) $this->
id);
2648 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2649 $result = $this->db->query($sql);
2671 global $conf, $langs;
2674 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2686 $outputlangs = $langs;
2690 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2692 $appli =
getDolGlobalString(
'MAIN_APPLICATION_TITLE', constant(
'DOL_APPLICATION_TITLE'));
2694 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2697 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
2698 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2700 if (!$changelater) {
2701 $url = $urlwithroot.
'/';
2706 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2708 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2709 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2710 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2711 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2714 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2716 $mesg .= $user->getFullName($outputlangs);
2719 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2720 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.
$conf->file->instance_unique_id));
2721 if (isModEnabled(
'multicompany')) {
2722 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2725 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2729 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2730 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2731 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2732 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2734 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2735 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2736 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2739 $trackid =
'use'.$this->id;
2740 $sendcontext =
'passwordreset';
2761 if ($mailfile->sendfile()) {
2764 $langs->trans(
"errors");
2765 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2777 return $this->error;
2790 $sql =
"SELECT url, login, pass, poste ";
2791 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2792 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2794 $resql = $this->db->query($sql);
2796 if ($this->db->num_rows($resql)) {
2797 $obj = $this->db->fetch_object($resql);
2799 $this->clicktodial_url = $obj->url;
2800 $this->clicktodial_login = $obj->login;
2801 $this->clicktodial_password = $obj->pass;
2802 $this->clicktodial_poste = $obj->poste;
2805 $this->clicktodial_loaded = 1;
2807 $this->db->free($resql);
2810 $this->
error = $this->db->error();
2826 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2827 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2829 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2831 $result = $this->db->query($sql);
2833 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2834 $sql .=
" (fk_user,url,login,pass,poste)";
2835 $sql .=
" VALUES (".$this->id;
2836 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2837 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2838 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2839 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2841 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2843 $result = $this->db->query($sql);
2845 $this->db->commit();
2848 $this->db->rollback();
2849 $this->
error = $this->db->lasterror();
2867 global $conf, $langs, $user;
2873 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2874 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2875 $sql .=
" AND fk_usergroup = ".((int) $group);
2876 $sql .=
" AND entity = ".((int) $entity);
2878 $result = $this->db->query($sql);
2880 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2881 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2883 $result = $this->db->query($sql);
2885 if (!$error && !$notrigger) {
2886 $this->context = array(
'audit' => $langs->trans(
"UserSetInGroup"),
'newgroupid' => $group);
2897 $this->db->commit();
2901 $this->db->rollback();
2905 $this->
error = $this->db->lasterror();
2906 $this->db->rollback();
2923 global $conf, $langs, $user;
2929 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2930 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2931 $sql .=
" AND fk_usergroup = ".((int) $group);
2932 if (empty($entity)) {
2933 $sql .=
" AND entity IN (0, 1)";
2935 $sql .=
" AND entity = ".((int) $entity);
2938 $result = $this->db->query($sql);
2940 if (!$error && !$notrigger) {
2941 $this->context = array(
'audit' => $langs->trans(
"UserRemovedFromGroup"),
'oldgroupid' => $group);
2952 $this->db->commit();
2955 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2956 $this->db->rollback();
2960 $this->
error = $this->db->lasterror();
2961 $this->db->rollback();
2975 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2982 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
3005 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
3007 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3008 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
3022 global $conf, $langs, $menumanager;
3025 $infologin = $params[
'infologin'] ?? 0;
3026 $option = $params[
'option'] ??
'';
3029 if (!empty($this->photo)) {
3030 $photo =
'<div class="photointooltip floatright">';
3031 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
3033 $data[
'photo'] = $photo;
3038 $data[
'opendiv'] =
'<div class="centpercent divtooltip">';
3039 $data[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
3041 if (!empty($this->login)) {
3044 if (!empty($this->job)) {
3048 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
3049 $phonelist = array();
3050 if ($this->office_phone) {
3051 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
3053 if ($this->office_fax) {
3054 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
3056 if ($this->user_mobile) {
3057 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
3059 $data[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
3061 if (!empty($this->admin)) {
3062 $data[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
3064 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
3065 $langs->load(
"companies");
3066 $data[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
3069 if (!empty($this->socid)) {
3070 $thirdpartystatic =
new Societe($this->db);
3071 $thirdpartystatic->fetch($this->socid);
3073 if (empty($params[
'hidethirdpartylogo'])) {
3074 $companyimg =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3076 $company =
' ('.$langs->trans(
"Company").
': '.($companyimg ? $companyimg :
img_picto(
'',
'company')).
' '.
dol_string_nohtmltag($thirdpartystatic->name).
')';
3078 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
3079 $data[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
3080 $data[
'closediv'] =
'</div>';
3082 if ($infologin > 0) {
3083 $data[
'newlinelogin'] =
'<br>';
3084 $data[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
3087 $data[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.
$conf->entity.
' (User entity '.$this->entity.
')';
3090 $data[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
3091 $data[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
3094 $data[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
3096 $data[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
3097 $data[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag(
$conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
3099 $data[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
3100 if (
$conf->browser->layout ==
'phone') {
3101 $data[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
3103 if (!empty($_SESSION[
"disablemodules"])) {
3104 $data[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(implode(
', ', explode(
',', $_SESSION[
"disablemodules"])));
3126 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'valignmiddle', $save_lastsearch_value = -1)
3128 global $langs, $hookmanager, $user;
3130 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
3141 'objecttype' => $this->element,
3142 'infologin' => $infologin,
3143 'option' => $option,
3144 'hidethirdpartylogo' => $hidethirdpartylogo,
3146 $classfortooltip =
'classfortooltip';
3149 $classfortooltip =
'classforajaxtooltip';
3150 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3157 if (!empty($this->socid)) {
3158 $thirdpartystatic =
new Societe($this->db);
3159 $thirdpartystatic->fetch($this->socid);
3160 if (empty($hidethirdpartylogo)) {
3161 $companylink =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3165 if ($infologin < 0) {
3169 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
3170 if ($option ==
'leave') {
3171 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
3174 if ($option !=
'nolink') {
3176 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3177 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3178 $add_save_lastsearch_values = 1;
3180 if ($add_save_lastsearch_values) {
3181 $url .=
'&save_lastsearch_values=1';
3185 $linkstart =
'<a href="'.$url.
'"';
3187 if (empty($notooltip)) {
3189 $langs->load(
"users");
3190 $label = $langs->trans(
"ShowUser");
3191 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
3193 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
3194 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
3196 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
3199 $linkstart .= $linkclose.
'>';
3203 $result .= (($option ==
'nolink') ?
'' : $linkstart);
3204 if ($withpictoimg) {
3205 $paddafterimage =
'';
3206 if (abs((
int) $withpictoimg) == 1) {
3207 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3210 if ($withpictoimg > 0) {
3211 $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>';
3214 $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>';
3218 if ($withpictoimg > -2 && $withpictoimg != 2) {
3220 $result .=
'<span class="nopadding usertext'.((!isset($this->
status) || $this->status) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
3222 if ($mode ==
'login') {
3228 $result .=
'</span>';
3231 $result .= (($option ==
'nolink') ?
'' : $linkend);
3234 $result .= $companylink;
3237 $hookmanager->initHooks(array(
'userdao'));
3238 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
3239 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3241 $result = $hookmanager->resPrint;
3243 $result .= $hookmanager->resPrint;
3258 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
3260 global $langs, $user;
3264 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3268 if ((!$user->hasRight(
'user',
'user',
'lire') && $this->id != $user->id)) {
3272 if ($option ==
'xxx') {
3273 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3277 if ($option ==
'nolink') {
3282 $result .= $linkstart;
3283 if ($withpictoimg) {
3284 $paddafterimage =
'';
3285 if (abs($withpictoimg) == 1) {
3286 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3289 if ($withpictoimg > 0) {
3290 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3293 $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>';
3297 $result .= $this->login;
3298 $result .= $linkend;
3311 return $this->
LibStatut(isset($this->statut) ? (
int) $this->statut : (int) $this->
status, $mode);
3327 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3330 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3331 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3332 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3333 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3336 $statusType =
'status5';
3337 if ($status == self::STATUS_ENABLED) {
3338 $statusType =
'status4';
3341 $label = $this->labelStatus[$status];
3342 $labelshort = $this->labelStatusShort[$status];
3345 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3346 $statusType =
'status3';
3347 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3349 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3350 $statusType =
'status2';
3351 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3354 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3369 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3371 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3372 $return .=
'<div class="info-box info-box-sm">';
3373 $return .=
'<span class="info-box-icon bg-infobox-action">';
3376 if (!empty($this->photo)) {
3378 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3387 $return .=
'</span>';
3388 $return .=
'<div class="info-box-content">';
3389 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3390 if (isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3391 $return .=
img_picto($langs->trans(
"SuperAdministratorDesc"),
'redstar',
'class="valignmiddle paddingright paddingleft"');
3392 } elseif ($this->admin) {
3393 $return .=
img_picto($langs->trans(
"AdministratorDesc"),
'star',
'class="valignmiddle paddingright paddingleft"');
3395 $return .=
'</span>';
3396 if ($selected >= 0) {
3397 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3399 if (property_exists($this,
'label')) {
3400 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3403 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->
email.
'</span>';
3405 if (method_exists($this,
'getLibStatut')) {
3406 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3408 $return .=
'</div>';
3409 $return .=
'</div>';
3410 $return .=
'</div>';
3434 } elseif ($mode == 1) {
3436 } elseif ($mode == 2) {
3452 global $conf, $langs;
3458 $keymodified =
false;
3467 'LDAP_FIELD_FULLNAME' =>
'fullname',
3468 'LDAP_FIELD_NAME' =>
'lastname',
3469 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3470 'LDAP_FIELD_LOGIN' =>
'login',
3471 'LDAP_FIELD_LOGIN_SAMBA' =>
'login',
3472 'LDAP_FIELD_PHONE' =>
'office_phone',
3473 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3474 'LDAP_FIELD_FAX' =>
'office_fax',
3475 'LDAP_FIELD_MAIL' =>
'email',
3476 'LDAP_FIELD_SID' =>
'ldap_sid',
3480 foreach ($ldapkey as $constname => $varname) {
3486 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->$varname != $this->oldcopy->$varname) {
3487 $keymodified =
true;
3492 foreach ($socialnetworks as $key => $value) {
3493 if (!empty($this->socialnetworks[$value[
'label']]) &&
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))) {
3494 $info[
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))] = $this->socialnetworks[$value[
'label']];
3510 $soc =
new Societe($this->db);
3511 $soc->fetch($this->socid);
3514 if ($soc->client == 1) {
3515 $info[
"businessCategory"] =
"Customers";
3517 if ($soc->client == 2) {
3518 $info[
"businessCategory"] =
"Prospects";
3520 if ($soc->fournisseur == 1) {
3521 $info[
"businessCategory"] =
"Suppliers";
3526 if (!empty($this->pass)) {
3539 if ($this->pass_indatabase_crypted &&
getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED')) {
3543 } elseif (!empty($this->pass_indatabase)) {
3555 $info[
"objectclass"][4] =
"phpgwContact";
3557 $info[
'uidnumber'] = $this->id;
3559 $info[
'phpgwTz'] = 0;
3560 $info[
'phpgwMailType'] =
'INTERNET';
3561 $info[
'phpgwMailHomeType'] =
'INTERNET';
3563 $info[
"phpgwContactTypeId"] =
'n';
3564 $info[
"phpgwContactCatId"] = 0;
3565 $info[
"phpgwContactAccess"] =
"public";
3573 $info[
"phpgwContactOwner"] = 1;
3576 $info[
"rfc822Mailbox"] = $this->email;
3578 if ($this->user_mobile) {
3579 $info[
"phpgwCellTelephoneNumber"] = $this->user_mobile;
3588 $groupslist = $usergroup->listGroupsForUser($this->
id);
3590 if (!empty($groupslist)) {
3591 foreach ($groupslist as $groupforuser) {
3598 $info[
getDolGlobalString(
'LDAP_FIELD_HOMEDIRECTORY')] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->login";
3614 global $user, $langs;
3620 $this->
ref =
'SPECIMEN';
3621 $this->specimen = 1;
3623 $this->lastname =
'DOLIBARR';
3624 $this->firstname =
'SPECIMEN';
3625 $this->gender =
'man';
3626 $this->note_public =
'This is a note public';
3627 $this->note_private =
'This is a note private';
3628 $this->
email =
'email@specimen.com';
3629 $this->personal_email =
'personalemail@specimen.com';
3630 $this->socialnetworks = array(
3631 'skype' =>
'skypepseudo',
3632 'twitter' =>
'twitterpseudo',
3633 'facebook' =>
'facebookpseudo',
3634 'linkedin' =>
'linkedinpseudo',
3636 $this->office_phone =
'0999999999';
3637 $this->office_fax =
'0999999998';
3638 $this->user_mobile =
'0999999997';
3639 $this->personal_mobile =
'0999999996';
3641 $this->login =
'dolibspec';
3642 $this->pass =
'dolibSpec+@123';
3645 $this->datec = $now;
3646 $this->datem = $now;
3648 $this->datelastlogin = $now;
3649 $this->iplastlogin =
'127.0.0.1';
3650 $this->datepreviouslogin = $now;
3651 $this->ippreviouslogin =
'127.0.0.1';
3668 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
3669 $sql .=
" u.tms as date_modification, u.entity";
3670 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3671 $sql .=
" WHERE u.rowid = ".((int) $id);
3673 $result = $this->db->query($sql);
3675 if ($this->db->num_rows($result)) {
3676 $obj = $this->db->fetch_object($result);
3678 $this->
id = $obj->rowid;
3680 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3681 $this->date_creation = $this->db->jdate($obj->datec);
3682 $this->date_modification = $this->db->jdate($obj->date_modification);
3683 $this->entity = $obj->entity;
3686 $this->db->free($result);
3700 $sql =
"SELECT count(mc.email) as nb";
3701 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3702 $sql .=
" WHERE mc.email = '".$this->db->escape($this->
email).
"'";
3703 $sql .=
" AND mc.statut NOT IN (-1,0)";
3705 $resql = $this->db->query($sql);
3707 $obj = $this->db->fetch_object($resql);
3710 $this->db->free($resql);
3713 $this->
error = $this->db->error();
3730 $sql =
"SELECT count(rowid) as nb";
3731 $sql .=
" FROM ".$this->db->prefix().
"user";
3732 if ($option ==
'superadmin') {
3733 $sql .=
" WHERE entity = 0";
3735 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3736 if ($limitTo ==
'active') {
3737 $sql .=
" AND statut = 1";
3741 $sql .=
" AND admin = ".(int) $admin;
3744 $resql = $this->db->query($sql);
3746 $obj = $this->db->fetch_object($resql);
3747 $nb = (int) $obj->nb;
3749 $this->db->free($resql);
3752 $this->
error = $this->db->lasterror();
3768 global $user, $conf;
3773 $this->firstname = $ldapuser->$tmpvar;
3775 $this->lastname = $ldapuser->$tmpvar;
3777 $this->login = $ldapuser->$tmpvar;
3779 $this->pass = $ldapuser->$tmpvar;
3781 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3784 $this->office_phone = $ldapuser->$tmpvar;
3786 $this->user_mobile = $ldapuser->$tmpvar;
3788 $this->office_fax = $ldapuser->$tmpvar;
3790 $this->
email = $ldapuser->$tmpvar;
3791 foreach ($socialnetworks as $key => $value) {
3793 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3796 $this->ldap_sid = $ldapuser->$tmpvar;
3799 $this->job = $ldapuser->$tmpvar;
3801 $this->note_public = $ldapuser->$tmpvar;
3803 $result = $this->
update($user);
3805 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3821 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3822 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3824 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3825 $res = $this->db->query($sql);
3828 while ($rec = $this->db->fetch_array($res)) {
3829 $user =
new User($this->db);
3830 $user->fetch($rec[
'rowid']);
3850 $this->parentof = array();
3853 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3854 $sql .=
" FROM ".$this->db->prefix().
"user";
3855 $sql .=
" WHERE fk_user <> 0";
3856 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3858 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3859 $resql = $this->db->query($sql);
3861 while ($obj = $this->db->fetch_object($resql)) {
3862 $this->parentof[$obj->id_son] = $obj->id_parent;
3888 global $hookmanager;
3891 $hookmanager->initHooks(array(
'userdao'));
3893 $this->users = array();
3899 $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";
3900 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3902 $parameters = array();
3903 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3905 $sql .= $hookmanager->resPrint;
3907 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3910 $sql .=
" AND ".$filter;
3913 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3914 $resql = $this->db->query($sql);
3917 while ($obj = $this->db->fetch_object($resql)) {
3918 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3919 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3920 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3921 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3922 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3923 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3924 $this->users[$obj->rowid][
'login'] = $obj->login;
3925 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3926 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3927 $this->users[$obj->rowid][
'email'] = $obj->email;
3928 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3929 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3930 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3932 $this->users[$obj->rowid][
'fullpath'] =
'';
3933 $this->users[$obj->rowid][
'fullname'] =
'';
3934 $this->users[$obj->rowid][
'level'] = 0;
3943 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3944 foreach ($this->users as $key => $val) {
3947 $this->
error =
'ErrorLoopInHierarchy';
3953 if ($deleteafterid) {
3955 $keyfilter1 =
'^'.$deleteafterid.
'$';
3956 $keyfilter2 =
'_'.$deleteafterid.
'$';
3957 $keyfilter3 =
'^'.$deleteafterid.
'_';
3958 $keyfilter4 =
'_'.$deleteafterid.
'_';
3959 foreach (array_keys($this->users) as $key) {
3960 $fullpath = (string) $this->users[$key][
'fullpath'];
3961 if (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
3962 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath)) {
3963 unset($this->users[$key]);
3968 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
3969 $this->users =
dol_sort_array($this->users,
'fullname',
'asc', 1, 0, 1);
3973 return $this->users;
3986 $childids = array();
3988 if (isset($this->cache_childids[$this->
id])) {
3989 $childids = $this->cache_childids[$this->id];
3994 $idtoscan = $this->id;
3996 dol_syslog(
"Build childid for id = ".$idtoscan);
3997 foreach ($this->users as $id => $val) {
3999 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
4000 $childids[$val[
'id']] = $val[
'id'];
4004 $this->cache_childids[$this->id] = $childids;
4006 if ($addcurrentuser) {
4007 $childids[$this->id] = $this->id;
4027 if (!empty($this->users[$id_user][
'fullpath'])) {
4029 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
4034 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
4035 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
4037 $cursor_user = $id_user;
4039 $useridfound = array($id_user);
4040 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
4041 if (in_array($this->parentof[$cursor_user], $useridfound)) {
4042 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
4045 $useridfound[] = $this->parentof[$cursor_user];
4046 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
4047 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
4049 $cursor_user = $this->parentof[$cursor_user];
4053 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
4085 $this->nb = array();
4087 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
4088 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4089 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
4090 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
4091 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
4092 $sql .=
" AND ug.fk_user = u.rowid";
4094 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4096 $sql .=
" AND u.statut > 0";
4099 $resql = $this->db->query($sql);
4101 while ($obj = $this->db->fetch_object($resql)) {
4102 $this->nb[
"users"] = $obj->nb;
4104 $this->db->free($resql);
4108 $this->
error = $this->db->error();
4124 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4126 global $conf, $user, $langs;
4128 $langs->load(
"user");
4135 $modele =
'bluesky';
4139 $modelpath =
"core/modules/user/doc/";
4141 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4155 $user_property =
'';
4157 if (empty($rowid)) {
4161 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
4162 $sql .=
" FROM ".$this->db->prefix().
"user";
4163 $sql .=
" WHERE rowid = ".((int) $rowid);
4165 $resql = $this->db->query($sql);
4167 $nump = $this->db->num_rows($resql);
4170 $obj = $this->db->fetch_object($resql);
4172 if ($mode ==
'email') {
4173 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
4174 } elseif ($mode ==
'mobile') {
4175 $user_property = $obj->user_mobile;
4176 } elseif ($mode ==
'name') {
4180 return $user_property;
4200 $encodedsecurekey =
dol_hash(
$conf->file->instance_unique_id.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
4201 if (isModEnabled(
'multicompany')) {
4202 $entity_qr =
'&entity='.((int)
$conf->entity);
4207 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
4208 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
4211 if ($typeofurl ==
'internal') {
4212 $urlwithroot = DOL_URL_ROOT;
4215 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
4231 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $entityfilter =
false)
4233 global $conf, $user;
4235 $sql =
"SELECT t.rowid";
4236 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
4238 if ($entityfilter) {
4240 if (!empty($user->admin) && empty($user->entity) &&
$conf->entity == 1) {
4241 $sql .=
" WHERE t.entity IS NOT NULL";
4243 $sql .=
" WHERE t.entity = 0 OR EXISTS (";
4244 $sql .=
" SELECT ug.rowid FROM " . $this->db->prefix() .
"usergroup_user as ug";
4245 $sql .=
" WHERE ug.fk_user = t.rowid AND ug.entity IN (" .
getEntity(
'usergroup') .
"))";
4248 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
4251 $sql .=
" WHERE 1 = 1";
4257 if ($errormessage) {
4258 $this->errors[] = $errormessage;
4259 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
4263 $sql .= $this->db->order($sortfield, $sortorder);
4265 $sql .= $this->db->plimit($limit + 1, $offset);
4270 $resql = $this->db->query($sql);
4272 $this->users = array();
4273 $num = $this->db->num_rows($resql);
4275 while ($obj = $this->db->fetch_object($resql)) {
4276 $line =
new self($this->db);
4277 $result = $line->fetch($obj->rowid);
4278 if ($result > 0 && !empty($line->id)) {
4279 $this->users[$obj->rowid] = clone $line;
4282 $this->db->free($resql);
4286 $this->errors[] = $this->db->lasterror();
4298 private $findUserIdByEmailCache;
4312 if (isset($this->findUserIdByEmailCache[$email])) {
4313 return $this->findUserIdByEmailCache[$email];
4316 $this->findUserIdByEmailCache[$email] = -1;
4318 $sql =
'SELECT rowid';
4319 $sql .=
' FROM '.$this->db->prefix().
'user';
4320 if (
getDolGlobalString(
'AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR')) {
4321 $sql .=
" WHERE email LIKE '%".$this->db->escape($this->db->escapeforlike($email)).
"%'";
4323 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4327 $resql = $this->db->query($sql);
4332 $obj = $this->db->fetch_object($resql);
4337 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4339 return $this->findUserIdByEmailCache[$email];
4350 if (empty($fromId) || empty($toId)) {
4357 $sqlDelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
4358 $sqlDelete .=
" WHERE fk_user = ".((int) $toId);
4360 dol_syslog(get_class($this).
"::clone_rights (delete default permissions)", LOG_DEBUG);
4362 if (!$this->db->query($sqlDelete)) {
4363 $this->db->rollback();
4368 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id)";
4369 $sql .=
" SELECT entity, ".((int) $toId).
", fk_id";
4370 $sql .=
" FROM ".$this->db->prefix().
"user_rights src";
4371 $sql .=
" WHERE fk_user = ".((int) $fromId);
4372 $sql .=
" AND NOT EXISTS (";
4373 $sql .=
" SELECT 1";
4374 $sql .=
" FROM ".$this->db->prefix().
"user_rights dest";
4375 $sql .=
" WHERE dest.entity = src.entity";
4376 $sql .=
" AND dest.fk_user = ".((int) $toId);
4377 $sql .=
" AND dest.fk_id = src.fk_id";
4380 dol_syslog(get_class($this).
"::clone_rights", LOG_DEBUG);
4383 if (!$this->db->query($sql)) {
4384 $this->db->rollback();
4388 $this->db->commit();
4405 $type = $this->table_element;
4408 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4409 $categorystatic =
new Categorie($this->db);
4411 $sql =
"INSERT INTO ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]).
" (fk_categorie, fk_user)";
4412 $sql .=
" SELECT fk_categorie, ".((int) $toId).
" FROM ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]);
4413 $sql .=
" WHERE fk_user = ".((int) $fromId);
4415 if (!$this->db->query($sql)) {
4416 $this->
error = $this->db->lasterror();
4417 $this->db->rollback();
4421 $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.