40require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/commonpeople.class.php';
56 public $element =
'user';
61 public $table_element =
'user';
66 public $fk_element =
'fk_user';
71 public $picto =
'user';
110 public $civility_code;
135 public $email_oauth2;
140 public $personal_email;
145 public $socialnetworks;
160 public $office_phone;
175 public $personal_mobile;
205 public $pass_crypted;
210 public $pass_indatabase;
215 public $pass_indatabase_crypted;
259 public $fk_user_expense_validator;
264 public $fk_user_holiday_validator;
269 public $clicktodial_url;
274 public $clicktodial_login;
279 public $clicktodial_password;
284 public $clicktodial_poste;
289 public $clicktodial_loaded;
295 public $datelastlogin;
299 public $datepreviouslogin;
303 public $flagdelsessionsbefore;
311 public $ippreviouslogin;
315 public $datestartvalidity;
319 public $dateendvalidity;
339 public $all_permissions_are_loaded;
349 public $user_group_list;
354 private $_tab_loaded = array();
364 public $default_values;
369 public $lastsearch_values_tmp;
373 public $lastsearch_values;
378 public $users = array();
386 private $cache_childids;
392 public $accountancy_code_user_general;
397 public $accountancy_code;
429 public $dateemployment;
433 public $dateemploymentend;
438 public $default_c_exp_tax_cat;
443 public $ref_employee;
448 public $national_registration_number;
453 public $default_range;
458 public $fk_warehouse;
463 public $fk_establishment;
468 public $label_establishment;
479 public $usergroup_entity;
481 public $fields = array(
482 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
483 'lastname' => array(
'type' =>
'varchar(50)',
'label' =>
'Lastname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 20,
'searchall' => 1),
484 'firstname' => array(
'type' =>
'varchar(50)',
'label' =>
'Firstname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 10,
'searchall' => 1),
485 'ref_employee' => array(
'type' =>
'varchar(50)',
'label' =>
'RefEmployee',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 30,
'searchall' => 1),
486 'national_registration_number' => array(
'type' =>
'varchar(50)',
'label' =>
'NationalRegistrationNumber',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 40,
'searchall' => 1)
489 const STATUS_DISABLED = 0;
490 const STATUS_ENABLED = 1;
501 $this->ismultientitymanaged = 1;
502 $this->isextrafieldmanaged = 1;
504 $this->clicktodial_loaded = 0;
507 $this->all_permissions_are_loaded = 0;
508 $this->nb_rights = 0;
516 $this->rights->user =
new stdClass();
517 $this->rights->user->user =
new stdClass();
518 $this->rights->user->self =
new stdClass();
519 $this->rights->user->user_advance =
new stdClass();
520 $this->rights->user->self_advance =
new stdClass();
521 $this->rights->user->group_advance =
new stdClass();
538 public function fetch($id = 0, $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'', $fk_socpeople = 0, $use_email_oauth2 = 0)
543 $login = trim($login);
546 $sql =
"SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.civility as civility_code, u.birth, u.job,";
547 $sql .=
" u.email, u.email_oauth2, u.personal_email,";
548 $sql .=
" u.socialnetworks,";
549 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
550 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
551 $sql .=
" u.admin, u.login, u.note_private, u.note_public,";
552 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.api_key,";
553 $sql .=
" u.fk_soc, u.fk_socpeople, u.fk_member, u.fk_user, u.ldap_sid, u.fk_user_expense_validator, u.fk_user_holiday_validator,";
554 $sql .=
" u.statut as status, u.lang, u.entity,";
555 $sql .=
" u.datec as datec,";
556 $sql .=
" u.tms as datem,";
557 $sql .=
" u.datelastlogin as datel,";
558 $sql .=
" u.datepreviouslogin as datep,";
559 $sql .=
" u.flagdelsessionsbefore,";
560 $sql .=
" u.iplastlogin,";
561 $sql .=
" u.ippreviouslogin,";
562 $sql .=
" u.datelastpassvalidation,";
563 $sql .=
" u.datestartvalidity,";
564 $sql .=
" u.dateendvalidity,";
565 $sql .=
" u.photo as photo,";
566 $sql .=
" u.openid as openid,";
567 $sql .=
" u.accountancy_code_user_general,";
568 $sql .=
" u.accountancy_code,";
571 $sql .=
" u.salary,";
572 $sql .=
" u.salaryextra,";
573 $sql .=
" u.weeklyhours,";
575 $sql .=
" u.dateemployment, u.dateemploymentend,";
576 $sql .=
" u.fk_warehouse,";
577 $sql .=
" u.ref_ext,";
578 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
579 $sql .=
" u.national_registration_number,";
580 $sql .=
" u.ref_employee,";
581 $sql .=
" c.code as country_code, c.label as country,";
582 $sql .=
" d.code_departement as state_code, d.nom as state,";
583 $sql .=
" s.label as label_establishment, u.fk_establishment";
584 $sql .=
" FROM ".$this->db->prefix().
"user as u";
585 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as c ON u.fk_country = c.rowid";
586 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_departements as d ON u.fk_state = d.rowid";
587 $sql .=
" LEFT JOIN ".$this->db->prefix().
"establishment as s ON u.fk_establishment = s.rowid";
590 if ((!isModEnabled(
'multicompany') || !
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) && (!empty($user->entity))) {
591 $sql .=
" WHERE u.entity IN (0, ".((int)
$conf->entity).
")";
593 $sql .=
" WHERE u.entity IS NOT NULL";
597 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
598 $sql .=
" WHERE u.entity IS NOT NULL";
600 if ($entity !=
'' && $entity == 0) {
601 $sql .=
" WHERE u.entity = 0";
603 $sql .=
" WHERE u.entity IN (0, ".((int) ($entity > 0 ? $entity :
$conf->entity)).
")";
610 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->db->escape($login).
"')";
612 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
614 $sql .=
" AND (u.email = '".$this->db->escape($email).
"'";
615 if ($use_email_oauth2) {
616 $sql .=
" OR u.email_oauth2 = '".$this->db->escape($email).
"'";
619 } elseif ($fk_socpeople > 0) {
620 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
622 $sql .=
" AND u.rowid = ".((int) $id);
624 $sql .=
" ORDER BY u.entity ASC";
628 $sql .=
' '.$this->db->plimit(1);
631 $resql = $this->db->query($sql);
633 $num = $this->db->num_rows($resql);
635 $this->
error =
"USERDUPLICATEFOUND";
636 dol_syslog(get_class($this).
"::fetch more than 1 user found", LOG_WARNING);
638 $this->db->free($resql);
642 $obj = $this->db->fetch_object($resql);
644 $this->
id = $obj->rowid;
645 $this->
ref = $obj->rowid;
647 $this->ref_ext = $obj->ref_ext;
649 $this->ldap_sid = $obj->ldap_sid;
650 $this->civility_code = $obj->civility_code;
651 $this->lastname = $obj->lastname;
652 $this->firstname = $obj->firstname;
653 $this->ref_employee = $obj->ref_employee;
654 $this->national_registration_number = $obj->national_registration_number;
656 $this->employee = $obj->employee;
658 $this->login = $obj->login;
659 $this->gender = $obj->gender;
660 $this->birth = $this->db->jdate($obj->birth);
661 $this->pass_indatabase = $obj->pass;
662 $this->pass_indatabase_crypted = $obj->pass_crypted;
663 $this->pass = $obj->pass;
664 $this->pass_temp = $obj->pass_temp;
667 $this->
address = $obj->address;
668 $this->zip = $obj->zip;
669 $this->town = $obj->town;
671 $this->country_id = $obj->country_id;
672 $this->country_code = $obj->country_id ? $obj->country_code :
'';
675 $this->state_id = $obj->state_id;
676 $this->state_code = $obj->state_code;
677 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
679 $this->office_phone = $obj->office_phone;
680 $this->office_fax = $obj->office_fax;
681 $this->user_mobile = $obj->user_mobile;
682 $this->personal_mobile = $obj->personal_mobile;
683 $this->
email = $obj->email;
684 $this->email_oauth2 = $obj->email_oauth2;
685 $this->personal_email = $obj->personal_email;
686 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
688 $this->job = $obj->job;
689 $this->signature = $obj->signature;
690 $this->admin = $obj->admin;
691 $this->note_public = $obj->note_public;
692 $this->note_private = $obj->note_private;
694 $this->statut = $obj->status;
695 $this->
status = $obj->status;
697 $this->photo = $obj->photo;
698 $this->openid = $obj->openid;
699 $this->lang = $obj->lang;
700 $this->entity = $obj->entity;
702 $this->accountancy_code_user_general = $obj->accountancy_code_user_general;
703 $this->accountancy_code = $obj->accountancy_code;
705 $this->thm = $obj->thm;
706 $this->tjm = $obj->tjm;
707 $this->salary = $obj->salary;
708 $this->salaryextra = $obj->salaryextra;
709 $this->weeklyhours = $obj->weeklyhours;
710 $this->color = $obj->color;
711 $this->dateemployment = $this->db->jdate($obj->dateemployment);
712 $this->dateemploymentend = $this->db->jdate($obj->dateemploymentend);
714 $this->datec = $this->db->jdate($obj->datec);
715 $this->datem = $this->db->jdate($obj->datem);
716 $this->datelastlogin = $this->db->jdate($obj->datel);
717 $this->datepreviouslogin = $this->db->jdate($obj->datep);
718 $this->flagdelsessionsbefore = $this->db->jdate($obj->flagdelsessionsbefore,
'gmt');
719 $this->iplastlogin = $obj->iplastlogin;
720 $this->ippreviouslogin = $obj->ippreviouslogin;
721 $this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
722 $this->dateendvalidity = $this->db->jdate($obj->dateendvalidity);
724 $this->socid = $obj->fk_soc;
725 $this->contact_id = $obj->fk_socpeople;
726 $this->fk_member = $obj->fk_member;
727 $this->fk_user = $obj->fk_user;
728 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
729 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
731 $this->default_range = $obj->default_range;
732 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
733 $this->fk_warehouse = $obj->fk_warehouse;
734 $this->fk_establishment = $obj->fk_establishment;
735 $this->label_establishment = $obj->label_establishment;
739 if (!isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
747 $this->db->free($resql);
749 $this->
error =
"USERNOTFOUND";
750 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
752 $this->db->free($resql);
756 $this->
error = $this->db->lasterror();
761 if ($loadpersonalconf) {
767 $this->
error = $this->db->lasterror();
786 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
787 $sql .=
" WHERE fk_user = ".((int) $this->
id);
788 $sql .=
" AND entity = ".((int)
$conf->entity);
790 $resql = $this->db->query($sql);
792 $num = $this->db->num_rows($resql);
795 $obj = $this->db->fetch_object($resql);
796 $p = (!empty($obj->param) ? $obj->param :
'');
798 $this->
conf->$p = $obj->value;
802 $this->db->free($resql);
806 $this->
error = $this->db->lasterror();
823 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
826 $result = $defaultValues->fetchAll(
'',
'', 0, 0,
'(t.user_id:in:0,'.$this->
id.
') AND (entity:in:'.(isset($this->entity) ? $this->entity :
$conf->entity).
','.
$conf->entity.
')');
829 if (!is_array($result) && $result < 0) {
833 } elseif (count($result) > 0) {
834 foreach ($result as $defval) {
835 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
836 $pagewithoutquerystring = $defval->page;
839 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
840 $pagewithoutquerystring = $reg[1];
841 $pagequeries = $reg[2];
843 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
847 if (!empty($this->default_values)) {
848 foreach ($this->default_values as $a => $b) {
849 foreach ($b as
$c => $d) {
850 krsort($this->default_values[$a][
$c]);
869 public function hasRight($module, $permlevel1, $permlevel2 =
'')
872 $moduletomoduletouse = array(
873 'compta' =>
'comptabilite',
874 'contract' =>
'contrat',
875 'member' =>
'adherent',
877 'order' =>
'commande',
878 'produit' =>
'product',
879 'productlot' =>
'product',
880 'project' =>
'projet',
881 'propale' =>
'propal',
882 'shipping' =>
'expedition',
883 'task' =>
'task@projet',
884 'fichinter' =>
'ficheinter',
885 'inventory' =>
'stock',
886 'invoice' =>
'facture',
887 'invoice_supplier' =>
'fournisseur',
888 'order_supplier' =>
'fournisseur',
889 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
890 'skill@hrm' =>
'all@hrm',
891 'job@hrm' =>
'all@hrm',
892 'position@hrm' =>
'all@hrm',
893 'facturerec' =>
'facture',
894 'margins' =>
'margin',
897 if (!empty($moduletomoduletouse[$module])) {
898 $module = $moduletomoduletouse[$module];
901 $moduleRightsMapping = array(
902 'product' =>
'produit',
903 'margin' =>
'margins',
904 'comptabilite' =>
'compta'
907 $rightsPath = $module;
908 if (!empty($moduleRightsMapping[$rightsPath])) {
909 $rightsPath = $moduleRightsMapping[$rightsPath];
913 $tmp = explode(
'@', $rightsPath, 2);
914 if (!empty($tmp[1])) {
915 if (strpos($module,
'@') !==
false) {
918 if ($tmp[0] != $tmp[1]) {
920 $rightsPath = $tmp[1];
921 $permlevel2 = $permlevel1;
922 $permlevel1 = $tmp[0];
925 $rightsPath = $tmp[1];
935 if (!isModEnabled($module)) {
940 if (!empty($this->socid)) {
941 if ($module ==
'societe' && ($permlevel1 ==
'creer' || $permlevel1 ==
'write')) {
944 if ($module ==
'societe' && $permlevel1 ==
'client' && $permlevel2 ==
'voir') {
947 if ($module ==
'societe' && $permlevel1 ==
'export') {
950 if ($module ==
'societe' && ($permlevel1 ==
'supprimer' || $permlevel1 ==
'delete')) {
956 if ($permlevel1 ==
'propale') {
957 $permlevel1 =
'propal';
959 if ($permlevel1 ==
'member') {
960 $permlevel1 =
'adherent';
962 if ($permlevel1 ==
'recruitmentcandidature') {
963 $permlevel1 =
'recruitmentjobposition';
968 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
973 if (!empty($this->rights->$rightsPath->$permlevel1)) {
974 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
975 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
979 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
980 return $this->rights->$rightsPath->$permlevel1->lire;
982 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
983 return $this->rights->$rightsPath->$permlevel1->creer;
985 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
986 return $this->rights->$rightsPath->$permlevel1->create;
988 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
989 return $this->rights->$rightsPath->$permlevel1->supprimer;
993 if (!empty($this->rights->$rightsPath->$permlevel1)) {
994 return $this->rights->$rightsPath->$permlevel1;
998 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
999 return $this->rights->$rightsPath->lire;
1001 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
1002 return $this->rights->$rightsPath->creer;
1004 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
1005 return $this->rights->$rightsPath->create;
1007 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
1008 return $this->rights->$rightsPath->supprimer;
1026 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1028 global $conf, $user, $langs;
1030 $entity = (empty($entity) ?
$conf->entity : $entity);
1032 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
1034 if (empty($this->
id)) {
1035 $this->
error =
'Try to call addrights on an object user with an empty id';
1045 $module = $perms = $subperms =
'';
1048 $sql =
"SELECT module, perms, subperms";
1049 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1050 $sql .=
" WHERE id = ".((int) $rid);
1051 $sql .=
" AND entity = ".((int) $entity);
1053 $result = $this->db->query($sql);
1055 $obj = $this->db->fetch_object($result);
1058 $module = $obj->module;
1059 $perms = $obj->perms;
1060 $subperms = $obj->subperms;
1068 $whereforadd =
"id=".((int) $rid);
1070 if (!empty($subperms)) {
1071 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
1072 } elseif (!empty($perms)) {
1073 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND (subperms IS NULL or subperms = ''))";
1079 if (!empty($allmodule)) {
1080 if ($allmodule ==
'allmodules') {
1081 $whereforadd =
'allmodules';
1083 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
1084 if (!empty($allperms)) {
1085 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
1093 if (!empty($whereforadd)) {
1096 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1097 $sql .=
" WHERE entity = ".((int) $entity);
1098 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
1099 $sql .=
" AND (".$whereforadd.
")";
1102 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1103 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1105 $sqldelete .=
") AND entity = ".((int) $entity);
1106 if (!$this->db->query($sqldelete)) {
1111 $resql = $this->db->query($sql);
1113 $num = $this->db->num_rows($resql);
1116 $obj = $this->db->fetch_object($resql);
1121 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
1122 if (!$this->db->query($sql)) {
1136 if (!$error && !$notrigger) {
1137 $langs->load(
"other");
1138 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
1149 $this->db->rollback();
1152 $this->db->commit();
1169 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1171 global $conf, $user, $langs;
1175 $entity = (!empty($entity) ? $entity :
$conf->entity);
1180 $module = $perms = $subperms =
'';
1184 $sql =
"SELECT module, perms, subperms";
1185 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1186 $sql .=
" WHERE id = '".$this->db->escape($rid).
"'";
1187 $sql .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1189 $result = $this->db->query($sql);
1191 $obj = $this->db->fetch_object($result);
1194 $module = $obj->module;
1195 $perms = $obj->perms;
1196 $subperms = $obj->subperms;
1204 $wherefordel =
"id=".((int) $rid);
1206 if ($subperms ==
'lire' || $subperms ==
'read') {
1207 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1209 if ($perms ==
'lire' || $perms ==
'read') {
1210 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1216 if (!empty($allmodule)) {
1217 if ($allmodule ==
'allmodules') {
1218 $wherefordel =
'allmodules';
1220 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1221 if (!empty($allperms)) {
1222 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1229 if (!empty($wherefordel)) {
1232 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1233 $sql .=
" WHERE entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1234 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1235 $sql .=
" AND (".$wherefordel.
")";
1239 if ($this->admin == 1) {
1240 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1241 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1242 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1243 $sql .=
" AND id NOT IN (358)";
1246 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1247 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1250 $sqldelete .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1252 $resql = $this->db->query($sqldelete);
1259 if (!$error && !$notrigger) {
1260 $langs->load(
"other");
1261 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1272 $this->db->rollback();
1275 $this->db->commit();
1289 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1291 $this->nb_rights = 0;
1292 $this->all_permissions_are_loaded = 0;
1293 $this->_tab_loaded = array();
1309 $alreadyloaded =
false;
1311 if (empty($forcereload)) {
1312 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1314 $alreadyloaded =
true;
1317 if (!empty($this->all_permissions_are_loaded)) {
1319 $alreadyloaded =
true;
1324 if (!isset($this->rights) || !is_object($this->rights)) {
1327 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1328 $this->rights->user =
new stdClass();
1333 if (!$alreadyloaded) {
1335 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1336 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1337 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1338 $sql .=
" WHERE r.id = ur.fk_id";
1344 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') ?
"1," :
"").
$conf->entity.
")";
1348 $sql .=
" AND r.entity = ".((int)
$conf->entity).
" AND ur.entity = ".((int)
$conf->entity);
1350 $sql .=
" AND ur.fk_user = ".((int) $this->
id);
1351 $sql .=
" AND r.perms IS NOT NULL";
1353 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1356 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1359 $resql = $this->db->query($sql);
1361 $num = $this->db->num_rows($resql);
1364 $obj = $this->db->fetch_object($resql);
1367 $module = $obj->module;
1368 $perms = $obj->perms;
1369 $subperms = $obj->subperms;
1371 if (!empty($perms)) {
1372 if (!empty($module)) {
1373 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1374 $this->rights->$module =
new stdClass();
1376 if (!empty($subperms)) {
1377 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1378 $this->rights->$module->$perms =
new stdClass();
1380 if (empty($this->rights->$module->$perms->$subperms)) {
1383 $this->rights->$module->$perms->$subperms = 1;
1385 if (empty($this->rights->$module->$perms)) {
1388 $this->rights->$module->$perms = 1;
1395 $this->db->free($resql);
1399 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms, r.entity";
1400 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1401 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1402 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1403 $sql .=
" WHERE r.id = gr.fk_id";
1408 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1409 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1411 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1414 $sql .=
" AND gr.entity = ".((int)
$conf->entity);
1418 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1419 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1422 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1423 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1424 $sql .=
" AND r.perms IS NOT NULL";
1426 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1429 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1432 $resql = $this->db->query($sql);
1434 $num = $this->db->num_rows($resql);
1437 $obj = $this->db->fetch_object($resql);
1440 $module = $obj->module;
1441 $perms = $obj->perms;
1442 $subperms = $obj->subperms;
1444 if (!empty($perms)) {
1445 if (!empty($module)) {
1446 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1447 $this->rights->$module =
new stdClass();
1449 if (!empty($subperms)) {
1450 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1451 $this->rights->$module->$perms =
new stdClass();
1453 if (empty($this->rights->$module->$perms->$subperms)) {
1456 $this->rights->$module->$perms->$subperms = 1;
1459 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1460 if (empty($this->rights->$module->$perms)) {
1463 $this->rights->$module->$perms = 1;
1471 $this->db->free($resql);
1475 if (!empty($this->admin)) {
1476 if (empty($this->rights->user->user)) {
1477 $this->rights->user->user =
new stdClass();
1479 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1480 foreach ($listofpermtotest as $permtotest) {
1481 if (empty($this->rights->user->user->$permtotest)) {
1482 $this->rights->user->user->$permtotest = 1;
1486 if (empty($this->rights->user->self)) {
1487 $this->rights->user->self =
new stdClass();
1489 $listofpermtotest = array(
'creer',
'password');
1490 foreach ($listofpermtotest as $permtotest) {
1491 if (empty($this->rights->user->self->$permtotest)) {
1492 $this->rights->user->self->$permtotest = 1;
1498 if (empty($this->rights->user->user_advance)) {
1499 $this->rights->user->user_advance =
new stdClass();
1501 $listofpermtotest = array(
'readperms',
'write');
1502 foreach ($listofpermtotest as $permtotest) {
1503 if (empty($this->rights->user->user_advance->$permtotest)) {
1504 $this->rights->user->user_advance->$permtotest = 1;
1508 if (empty($this->rights->user->self_advance)) {
1509 $this->rights->user->self_advance =
new stdClass();
1511 $listofpermtotest = array(
'readperms',
'writeperms');
1512 foreach ($listofpermtotest as $permtotest) {
1513 if (empty($this->rights->user->self_advance->$permtotest)) {
1514 $this->rights->user->self_advance->$permtotest = 1;
1518 if (empty($this->rights->user->group_advance)) {
1519 $this->rights->user->group_advance =
new stdClass();
1521 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1522 foreach ($listofpermtotest as $permtotest) {
1523 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1524 $this->rights->user->group_advance->$permtotest = 1;
1532 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1533 $this->rights->propal = $this->rights->propale;
1535 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1536 $this->rights->propale = $this->rights->propal;
1543 $this->all_permissions_are_loaded = 1;
1546 $this->_tab_loaded[$moduletag] = 1;
1563 public function getrights($moduletag =
'', $forcereload = 0)
1576 global $conf, $langs, $user;
1581 if (isset($this->statut)) {
1582 if ($this->statut == $status) {
1585 } elseif (isset($this->
status) && $this->
status == $status) {
1592 $sql =
"UPDATE ".$this->db->prefix().
"user";
1593 $sql .=
" SET statut = ".((int) $status);
1594 $sql .=
" WHERE rowid = ".((int) $this->
id);
1595 $result = $this->db->query($sql);
1597 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1600 $this->context[
'actionmsg'] =
'User '.$this->login.
' disabled';
1602 $this->context[
'actionmsg'] =
'User '.$this->login.
' enabled';
1605 $result = $this->
call_trigger(
'USER_ENABLEDISABLE', $user);
1613 $this->db->rollback();
1617 $this->statut = $status;
1618 $this->db->commit();
1635 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1636 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1647 global $conf, $langs;
1653 $this->
fetch($this->
id);
1655 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1658 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1660 if (!$error && !$this->db->query($sql)) {
1662 $this->
error = $this->db->lasterror();
1666 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1667 if (!$error && !$this->db->query($sql)) {
1669 $this->
error = $this->db->lasterror();
1673 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1674 if (!$error && !$this->db->query($sql)) {
1676 $this->
error = $this->db->lasterror();
1680 if ($this->contact_id > 0) {
1681 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1682 if (!$error && !$this->db->query($sql)) {
1684 $this->
error = $this->db->lasterror();
1693 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1699 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1700 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1701 if (!$this->db->query($sql)) {
1703 $this->
error = $this->db->lasterror();
1712 $this->db->rollback();
1717 $this->db->commit();
1720 $this->db->rollback();
1732 public function create($user, $notrigger = 0)
1734 global $conf, $langs;
1740 $this->civility_code = trim((
string) $this->civility_code);
1741 $this->login = trim((
string) $this->login);
1742 if (!isset($this->entity)) {
1743 $this->entity =
$conf->entity;
1745 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1747 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1751 $langs->load(
"errors");
1752 $this->
error = $langs->trans(
"ErrorBadEMail", $this->
email);
1755 if (empty($this->login)) {
1756 $langs->load(
"errors");
1757 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1759 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1760 $langs->load(
"errors");
1761 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1772 $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).
"'";
1773 $resqltochecklogin = $this->db->query($sqltochecklogin);
1774 if ($resqltochecklogin) {
1775 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1776 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1777 $langs->load(
"errors");
1778 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1780 $this->db->rollback();
1783 $this->db->free($resqltochecklogin);
1786 if (!empty($this->
email)) {
1787 $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).
"'";
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(
"ErrorEmailAlreadyExists", $this->
email);
1795 $this->db->rollback();
1798 $this->db->free($resqltochecklogin);
1803 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, entity)";
1804 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->db->escape($this->login).
"', '".$this->db->escape($this->ldap_sid).
"', ".((int) $this->entity).
")";
1805 $result = $this->db->query($sql);
1807 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1809 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1813 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1814 $this->db->rollback();
1819 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1820 $langs->load(
"stocks");
1822 $entrepot =
new Entrepot($this->db);
1823 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1824 $entrepot->libelle = $entrepot->label;
1825 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1826 $entrepot->statut = 1;
1827 $entrepot->country_id = $mysoc->country_id;
1829 $warehouseid = $entrepot->create($user);
1831 $this->fk_warehouse = $warehouseid;
1835 $result = $this->
update($user, 1, 1);
1837 $this->db->rollback();
1851 $this->db->commit();
1856 $this->db->rollback();
1860 $this->
error = $this->db->lasterror();
1861 $this->db->rollback();
1879 global $conf, $user, $langs;
1885 $this->civility_code = $contact->civility_code;
1886 $this->lastname = $contact->lastname;
1887 $this->firstname = $contact->firstname;
1889 $this->
email = $contact->email;
1890 $this->socialnetworks = $contact->socialnetworks;
1891 $this->office_phone = $contact->phone_pro;
1892 $this->office_fax = $contact->fax;
1893 $this->user_mobile = $contact->phone_mobile;
1894 $this->
address = $contact->address;
1895 $this->zip = $contact->zip;
1896 $this->town = $contact->town;
1898 $this->state_id = $contact->state_id;
1899 $this->country_id = $contact->country_id;
1900 $this->employee = 0;
1902 if (empty($login)) {
1903 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1904 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1906 $this->login = $login;
1911 $result = $this->
create($user, 1);
1913 $sql =
"UPDATE ".$this->db->prefix().
"user";
1914 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1915 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1916 if ($contact->socid > 0) {
1917 $sql .=
", fk_soc=".((int) $contact->socid);
1919 $sql .=
" WHERE rowid=".((int) $this->
id);
1921 $resql = $this->db->query($sql);
1923 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1925 $this->context[
'createfromcontact'] =
'createfromcontact';
1931 $this->db->rollback();
1936 $this->db->commit();
1939 $this->
error = $this->db->error();
1941 $this->db->rollback();
1946 dol_syslog(get_class($this).
"::create_from_contact - 0");
1948 $this->db->rollback();
1969 $this->civility_code = $member->civility_code;
1970 $this->lastname = $member->lastname;
1971 $this->firstname = $member->firstname;
1972 $this->gender = $member->gender;
1973 $this->
email = $member->email;
1974 $this->fk_member = $member->id;
1975 $this->
address = $member->address;
1976 $this->zip = $member->zip;
1977 $this->town = $member->town;
1979 $this->state_id = $member->state_id;
1980 $this->country_id = $member->country_id;
1981 $this->socialnetworks = $member->socialnetworks;
1983 $this->pass = $member->pass;
1984 $this->pass_crypted = $member->pass_indatabase_crypted;
1986 if (empty($login)) {
1987 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1990 $this->login = $login;
1995 $result = $this->
create($user);
1997 if (!empty($this->pass)) {
1998 $newpass = $this->
setPassword($user, $this->pass);
1999 if (is_int($newpass) && $newpass < 0) {
2002 } elseif (!empty($this->pass_crypted)) {
2003 $sql =
"UPDATE ".$this->db->prefix().
"user";
2004 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
2005 $sql .=
" WHERE rowid=".((int) $this->
id);
2007 $resql = $this->db->query($sql);
2013 if ($result > 0 && $member->socid) {
2014 $sql =
"UPDATE ".$this->db->prefix().
"user";
2015 $sql .=
" SET fk_soc=".((int) $member->socid);
2016 $sql .=
" WHERE rowid=".((int) $this->
id);
2018 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
2019 $resql = $this->db->query($sql);
2021 $this->db->commit();
2024 $this->
error = $this->db->lasterror();
2026 $this->db->rollback();
2033 $this->db->commit();
2037 $this->db->rollback();
2055 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
2056 $sql .=
" WHERE bydefault = 1";
2057 $sql .=
" AND entity = ".((int)
$conf->entity);
2059 $resql = $this->db->query($sql);
2061 $num = $this->db->num_rows($resql);
2064 $row = $this->db->fetch_row($resql);
2068 $this->db->free($resql);
2072 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
2073 $result = $this->db->query($sql);
2075 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
2076 $result = $this->db->query($sql);
2096 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
2098 global $conf, $langs;
2100 $nbrowsaffected = 0;
2103 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
2106 $this->civility_code = trim((
string) $this->civility_code);
2107 $this->lastname = trim((
string) $this->lastname);
2108 $this->firstname = trim((
string) $this->firstname);
2109 $this->ref_employee = trim((
string) $this->ref_employee);
2110 $this->national_registration_number = trim((
string) $this->national_registration_number);
2111 $this->employee = ($this->employee > 0 ? $this->employee : 0);
2112 $this->login = trim((
string) $this->login);
2113 $this->gender = trim((
string) $this->gender);
2115 $this->pass = trim((
string) $this->pass);
2116 $this->api_key = trim((
string) $this->api_key);
2117 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
2118 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
2121 $this->zip = trim((
string) $this->zip);
2122 $this->town = trim((
string) $this->town);
2124 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
2125 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
2126 $this->office_phone = trim((
string) $this->office_phone);
2127 $this->office_fax = trim((
string) $this->office_fax);
2128 $this->user_mobile = trim((
string) $this->user_mobile);
2129 $this->personal_mobile = trim((
string) $this->personal_mobile);
2131 $this->personal_email = trim((
string) $this->personal_email);
2133 $this->job = trim((
string) $this->job);
2134 $this->signature = trim((
string) $this->signature);
2135 $this->note_public = trim((
string) $this->note_public);
2136 $this->note_private = trim((
string) $this->note_private);
2137 $this->openid = trim((
string) $this->openid);
2138 $this->admin = ($this->admin > 0 ? $this->admin : 0);
2140 $this->accountancy_code_user_general = trim((
string) $this->accountancy_code_user_general);
2141 $this->accountancy_code = trim((
string) $this->accountancy_code);
2142 $this->color = trim((
string) $this->color);
2143 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
2144 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
2146 $this->birth = empty($this->birth) ?
'' : $this->birth;
2147 $this->fk_warehouse = (int) $this->fk_warehouse;
2148 $this->fk_establishment = (int) $this->fk_establishment;
2153 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
2156 $langs->load(
"errors");
2157 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
2160 if (empty($this->login)) {
2161 $langs->load(
"errors");
2162 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
2164 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
2165 $langs->load(
"errors");
2166 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
2173 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->oldcopy->login != $this->login) {
2174 $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).
"'";
2175 $resqltochecklogin = $this->db->query($sqltochecklogin);
2176 if ($resqltochecklogin) {
2177 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2178 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2179 $langs->load(
"errors");
2180 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
2182 $this->db->rollback();
2187 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && !empty($this->email) && $this->oldcopy->email != $this->email) {
2188 $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).
"'";
2189 $resqltochecklogin = $this->db->query($sqltochecklogin);
2190 if ($resqltochecklogin) {
2191 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2192 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2193 $langs->load(
"errors");
2194 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
2196 $this->db->rollback();
2203 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2204 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
2205 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
2206 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
2207 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
2208 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
2209 $sql .=
", employee = ".(int) $this->employee;
2210 $sql .=
", login = '".$this->db->escape($this->login).
"'";
2211 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
2212 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
2213 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
2214 if (!empty($user->admin)) {
2215 $sql .=
", admin = ".(int) $this->admin;
2217 $sql .=
", address = '".$this->db->escape($this->address).
"'";
2218 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
2219 $sql .=
", town = '".$this->db->escape($this->town).
"'";
2220 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".$this->db->escape($this->state_id).
"'" :
"null");
2221 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".$this->db->escape($this->country_id).
"'" :
"null");
2222 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
2223 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
2224 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
2225 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
2226 $sql .=
", email = '".$this->db->escape($this->email).
"'";
2227 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
2228 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
2229 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2230 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2231 $sql .=
", accountancy_code_user_general = '".$this->db->escape($this->accountancy_code_user_general).
"'";
2232 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2233 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2234 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2235 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2236 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2237 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2238 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2239 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2240 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2241 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2242 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".$this->db->escape($this->fk_user).
"'" :
"null");
2243 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".$this->db->escape($this->fk_user_expense_validator).
"'" :
"null");
2244 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".$this->db->escape($this->fk_user_holiday_validator).
"'" :
"null");
2245 if (isset($this->thm) || $this->thm !=
'') {
2246 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2248 if (isset($this->tjm) || $this->tjm !=
'') {
2249 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2251 if (isset($this->salary) || $this->salary !=
'') {
2252 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2254 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2255 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2257 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2258 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2259 $sql .=
", entity = ".((int) $this->entity);
2261 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2262 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2263 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2264 $sql .=
", fk_establishment = ".($this->fk_establishment > 0 ? $this->fk_establishment :
"null");
2265 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2266 $sql .=
" WHERE rowid = ".((int) $this->
id);
2268 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2269 $resql = $this->db->query($sql);
2271 $nbrowsaffected += $this->db->affected_rows($resql);
2274 if (!empty($this->pass)) {
2275 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2277 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2278 if (is_int($result) && $result < 0) {
2285 if ($this->fk_member > 0) {
2286 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2287 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2288 $resql = $this->db->query($sql);
2290 $this->
error = $this->db->error();
2291 $this->db->rollback();
2296 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2297 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2298 $resql = $this->db->query($sql);
2300 $this->
error = $this->db->error();
2301 $this->db->rollback();
2305 if ($nbrowsaffected) {
2306 if ($this->fk_member > 0 && !$nosyncmember) {
2307 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2309 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2314 $result = $adh->fetch($this->fk_member);
2317 $adh->civility_code = $this->civility_code;
2318 $adh->firstname = $this->firstname;
2319 $adh->lastname = $this->lastname;
2320 $adh->login = $this->login;
2321 $adh->gender = $this->gender;
2322 $adh->birth = $this->birth;
2324 $adh->pass = $this->pass;
2326 $adh->address = $this->address;
2327 $adh->town = $this->town;
2328 $adh->zip = $this->zip;
2329 $adh->state_id = $this->state_id;
2330 $adh->country_id = $this->country_id;
2332 $adh->email = $this->email;
2334 $adh->socialnetworks = $this->socialnetworks;
2336 $adh->phone = $this->office_phone;
2337 $adh->phone_mobile = $this->user_mobile;
2339 $adh->default_lang = $this->lang;
2341 $adh->user_id = $this->id;
2342 $adh->user_login = $this->login;
2344 $result = $adh->update($user, 0, 1, 0);
2346 $this->
error = $adh->error;
2347 $this->errors = $adh->errors;
2348 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2351 } elseif ($result < 0) {
2352 $this->
error = $adh->error;
2353 $this->errors = $adh->errors;
2358 if ($this->contact_id > 0 && !$nosynccontact) {
2359 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2361 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2364 $tmpobj =
new Contact($this->db);
2365 $result = $tmpobj->fetch($this->contact_id);
2368 $tmpobj->civility_code = $this->civility_code;
2369 $tmpobj->firstname = $this->firstname;
2370 $tmpobj->lastname = $this->lastname;
2371 $tmpobj->login = $this->login;
2372 $tmpobj->gender = $this->gender;
2373 $tmpobj->birth = $this->birth;
2377 $tmpobj->email = $this->email;
2379 $tmpobj->socialnetworks = $this->socialnetworks;
2381 $tmpobj->phone_pro = $this->office_phone;
2382 $tmpobj->phone_mobile = $this->user_mobile;
2383 $tmpobj->fax = $this->office_fax;
2385 $tmpobj->default_lang = $this->lang;
2387 $tmpobj->address = $this->address;
2388 $tmpobj->town = $this->town;
2389 $tmpobj->zip = $this->zip;
2390 $tmpobj->state_id = $this->state_id;
2391 $tmpobj->country_id = $this->country_id;
2393 $tmpobj->user_id = $this->id;
2394 $tmpobj->user_login = $this->login;
2396 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2398 $this->
error = $tmpobj->error;
2399 $this->errors = $tmpobj->errors;
2400 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2404 $this->
error = $tmpobj->error;
2405 $this->errors = $tmpobj->errors;
2421 if (!$error && !$notrigger) {
2431 $this->db->commit();
2432 return $nbrowsaffected;
2435 $this->db->rollback();
2439 $this->
error = $this->db->lasterror();
2440 $this->db->rollback();
2459 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2460 $sql .=
" datepreviouslogin = datelastlogin,";
2461 $sql .=
" ippreviouslogin = iplastlogin,";
2462 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2463 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2464 $sql .=
" tms = tms";
2465 $sql .=
" WHERE rowid = ".((int) $this->
id);
2467 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2468 $resql = $this->db->query($sql);
2470 $this->datepreviouslogin = $this->datelastlogin;
2471 $this->datelastlogin = $now;
2472 $this->ippreviouslogin = $this->iplastlogin;
2473 $this->iplastlogin = $userremoteip;
2476 $this->
error = $this->db->lasterror().
' sql='.$sql;
2494 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2496 global $conf, $langs;
2497 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2501 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2508 $password_crypted =
null;
2510 if (empty($passwordalreadycrypted)) {
2513 $modGeneratePassClass =
'modGeneratePass'.ucfirst(
$conf->global->USER_PASSWORD_GENERATED);
2515 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2516 if (class_exists($modGeneratePassClass)) {
2517 $modGeneratePass =
new $modGeneratePassClass($this->db,
$conf, $langs, $user);
2518 '@phan-var-force ModeleGenPassword $modGeneratePass';
2521 $modGeneratePass->WithoutAmbi = 0;
2524 $testpassword = $modGeneratePass->validatePassword($password);
2525 if (!$testpassword) {
2526 $this->
error = $modGeneratePass->error;
2534 $password_crypted =
dol_hash($password);
2538 if (!$changelater) {
2539 if (!is_object($this->oldcopy)) {
2540 $this->oldcopy = clone $this;
2547 $sql =
"UPDATE ".$this->db->prefix().
"user";
2548 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2549 $sql .=
" pass_temp = null";
2550 if (!empty($flagdelsessionsbefore)) {
2551 $sql .=
", flagdelsessionsbefore = '".$this->db->idate($now - 5,
'gmt').
"'";
2554 $sql .=
", pass = null";
2556 $sql .=
", pass = '".$this->db->escape($password).
"'";
2558 $sql .=
" WHERE rowid = ".((int) $this->
id);
2560 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2561 $result = $this->db->query($sql);
2563 if ($this->db->affected_rows($result)) {
2564 $this->pass = $password;
2565 $this->pass_indatabase = $password;
2566 $this->pass_indatabase_crypted = (string) $password_crypted;
2568 if ($this->fk_member && !$nosyncmember) {
2569 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2574 $result = $adh->fetch($this->fk_member);
2577 $result = $adh->setPassword($user, $this->pass, (!
getDolGlobalString(
'DATABASE_PWD_ENCRYPTED') ? 0 : 1), 1);
2578 if (is_int($result) && $result < 0) {
2579 $this->
error = $adh->error;
2584 $this->
error = $adh->error;
2589 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2592 $user->context[
'audit'] =
'login='.$user->login;
2593 if (!empty($flagdelsessionsbefore)) {
2594 $user->context[
'audit'] .=
" - flagdelsessionsbefore set to '".$this->db->idate($now - 5,
'gmt').
"'";
2597 if (!$error && !$notrigger) {
2599 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2602 $this->db->rollback();
2608 $this->db->commit();
2611 $this->db->rollback();
2615 $this->db->rollback();
2622 $sql =
"UPDATE ".$this->db->prefix().
"user";
2623 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2624 $sql .=
" WHERE rowid = ".((int) $this->
id);
2626 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2627 $result = $this->db->query($sql);
2649 global $conf, $langs, $mysoc;
2650 global $dolibarr_main_url_root;
2652 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2661 if (isset($this->
conf->MAIN_LANG_DEFAULT)
2662 && $this->conf->MAIN_LANG_DEFAULT !=
'auto') {
2663 $outputlangs->getDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2666 if ($this->
conf->MAIN_LANG_DEFAULT) {
2667 $outputlangs->setDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2669 $outputlangs = $langs;
2673 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2675 $appli =
getDolGlobalString(
'MAIN_APPLICATION_TITLE', constant(
'DOL_APPLICATION_TITLE'));
2677 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2680 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2681 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2683 if (!$changelater) {
2684 $url = $urlwithroot.
'/';
2689 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2691 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2692 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2693 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2694 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2697 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2699 $mesg .= $user->getFullName($outputlangs);
2702 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2703 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.
$conf->file->instance_unique_id));
2704 if (isModEnabled(
'multicompany')) {
2705 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2708 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2712 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2713 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2714 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2715 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2717 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2718 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2719 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2722 $trackid =
'use'.$this->id;
2723 $sendcontext =
'passwordreset';
2728 $conf->global->MAIN_MAIL_EMAIL_FROM,
2744 if ($mailfile->sendfile()) {
2747 $langs->trans(
"errors");
2748 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2760 return $this->error;
2773 $sql =
"SELECT url, login, pass, poste ";
2774 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2775 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2777 $resql = $this->db->query($sql);
2779 if ($this->db->num_rows($resql)) {
2780 $obj = $this->db->fetch_object($resql);
2782 $this->clicktodial_url = $obj->url;
2783 $this->clicktodial_login = $obj->login;
2784 $this->clicktodial_password = $obj->pass;
2785 $this->clicktodial_poste = $obj->poste;
2788 $this->clicktodial_loaded = 1;
2790 $this->db->free($resql);
2793 $this->
error = $this->db->error();
2809 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2810 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2812 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2814 $result = $this->db->query($sql);
2816 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2817 $sql .=
" (fk_user,url,login,pass,poste)";
2818 $sql .=
" VALUES (".$this->id;
2819 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2820 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2821 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2822 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2824 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2826 $result = $this->db->query($sql);
2828 $this->db->commit();
2831 $this->db->rollback();
2832 $this->
error = $this->db->lasterror();
2850 global $conf, $langs, $user;
2856 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2857 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2858 $sql .=
" AND fk_usergroup = ".((int) $group);
2859 $sql .=
" AND entity = ".((int) $entity);
2861 $result = $this->db->query($sql);
2863 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2864 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2866 $result = $this->db->query($sql);
2868 if (!$error && !$notrigger) {
2869 $this->context = array(
'audit' => $langs->trans(
"UserSetInGroup"),
'newgroupid' => $group);
2880 $this->db->commit();
2884 $this->db->rollback();
2888 $this->
error = $this->db->lasterror();
2889 $this->db->rollback();
2906 global $conf, $langs, $user;
2912 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2913 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2914 $sql .=
" AND fk_usergroup = ".((int) $group);
2915 if (empty($entity)) {
2916 $sql .=
" AND entity IN (0, 1)";
2918 $sql .=
" AND entity = ".((int) $entity);
2921 $result = $this->db->query($sql);
2923 if (!$error && !$notrigger) {
2924 $this->context = array(
'audit' => $langs->trans(
"UserRemovedFromGroup"),
'oldgroupid' => $group);
2935 $this->db->commit();
2938 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2939 $this->db->rollback();
2943 $this->
error = $this->db->lasterror();
2944 $this->db->rollback();
2958 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2965 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
2988 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
2990 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2991 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
3005 global $conf, $langs, $menumanager;
3006 global $dolibarr_main_demo;
3008 $infologin = $params[
'infologin'] ?? 0;
3009 $option = $params[
'option'] ??
'';
3012 if (!empty($this->photo)) {
3013 $photo =
'<div class="photointooltip floatright">';
3014 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
3016 $data[
'photo'] = $photo;
3021 $data[
'opendiv'] =
'<div class="centpercent divtooltip">';
3022 $data[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
3024 if (!empty($this->login)) {
3027 if (!empty($this->job)) {
3031 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
3032 $phonelist = array();
3033 if ($this->office_phone) {
3034 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
3036 if ($this->office_fax) {
3037 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
3039 if ($this->user_mobile) {
3040 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
3042 $data[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
3044 if (!empty($this->admin)) {
3045 $data[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
3047 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
3048 $langs->load(
"companies");
3049 $data[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
3052 if (!empty($this->socid)) {
3053 $thirdpartystatic =
new Societe($this->db);
3054 $thirdpartystatic->fetch($this->socid);
3056 if (empty($params[
'hidethirdpartylogo'])) {
3057 $companyimg =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3059 $company =
' ('.$langs->trans(
"Company").
': '.($companyimg ? $companyimg :
img_picto(
'',
'company')).
' '.
dol_string_nohtmltag($thirdpartystatic->name).
')';
3061 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
3062 $data[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
3063 $data[
'closediv'] =
'</div>';
3065 if ($infologin > 0) {
3066 $data[
'newlinelogin'] =
'<br>';
3067 $data[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
3070 $data[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.
$conf->entity.
' (User entity '.$this->entity.
')';
3072 $data[
'authentication'] =
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
3073 $data[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
3074 $data[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
3077 $data[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
3079 $data[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
3080 $data[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag(
$conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
3082 $data[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
3083 if (
$conf->browser->layout ==
'phone') {
3084 $data[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
3086 if (!empty($_SESSION[
"disablemodules"])) {
3087 $data[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(implode(
', ', explode(
',', $_SESSION[
"disablemodules"])));
3109 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
3111 global $langs, $hookmanager, $user;
3113 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
3124 'objecttype' => $this->element,
3125 'infologin' => $infologin,
3126 'option' => $option,
3127 'hidethirdpartylogo' => $hidethirdpartylogo,
3129 $classfortooltip =
'classfortooltip';
3132 $classfortooltip =
'classforajaxtooltip';
3133 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3140 if (!empty($this->socid)) {
3141 $thirdpartystatic =
new Societe($this->db);
3142 $thirdpartystatic->fetch($this->socid);
3143 if (empty($hidethirdpartylogo)) {
3144 $companylink =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3148 if ($infologin < 0) {
3152 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
3153 if ($option ==
'leave') {
3154 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
3157 if ($option !=
'nolink') {
3159 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3160 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3161 $add_save_lastsearch_values = 1;
3163 if ($add_save_lastsearch_values) {
3164 $url .=
'&save_lastsearch_values=1';
3168 $linkstart =
'<a href="'.$url.
'"';
3170 if (empty($notooltip)) {
3172 $langs->load(
"users");
3173 $label = $langs->trans(
"ShowUser");
3174 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
3176 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
3177 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
3179 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
3182 $linkstart .= $linkclose.
'>';
3186 $result .= (($option ==
'nolink') ?
'' : $linkstart);
3187 if ($withpictoimg) {
3188 $paddafterimage =
'';
3189 if (abs((
int) $withpictoimg) == 1) {
3190 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3193 if ($withpictoimg > 0) {
3194 $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>';
3197 $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>';
3201 if ($withpictoimg > -2 && $withpictoimg != 2) {
3203 $result .=
'<span class="nopadding usertext'.((!isset($this->
status) || $this->status) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
3205 if ($mode ==
'login') {
3211 $result .=
'</span>';
3214 $result .= (($option ==
'nolink') ?
'' : $linkend);
3217 $result .= $companylink;
3220 $hookmanager->initHooks(array(
'userdao'));
3221 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
3222 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3224 $result = $hookmanager->resPrint;
3226 $result .= $hookmanager->resPrint;
3241 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
3243 global $langs, $user;
3247 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3251 if ((!$user->hasRight(
'user',
'user',
'lire') && $this->id != $user->id)) {
3255 if ($option ==
'xxx') {
3256 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3260 if ($option ==
'nolink') {
3265 $result .= $linkstart;
3266 if ($withpictoimg) {
3267 $paddafterimage =
'';
3268 if (abs($withpictoimg) == 1) {
3269 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3272 if ($withpictoimg > 0) {
3273 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3276 $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>';
3280 $result .= $this->login;
3281 $result .= $linkend;
3294 return $this->
LibStatut(isset($this->statut) ? (
int) $this->statut : (int) $this->
status, $mode);
3310 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3313 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3314 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3315 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3316 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3319 $statusType =
'status5';
3320 if ($status == self::STATUS_ENABLED) {
3321 $statusType =
'status4';
3324 $label = $this->labelStatus[$status];
3325 $labelshort = $this->labelStatusShort[$status];
3328 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3329 $statusType =
'status3';
3330 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3332 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3333 $statusType =
'status2';
3334 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3337 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3352 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3354 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3355 $return .=
'<div class="info-box info-box-sm">';
3356 $return .=
'<span class="info-box-icon bg-infobox-action">';
3359 if (!empty($this->photo)) {
3361 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3370 $return .=
'</span>';
3371 $return .=
'<div class="info-box-content">';
3372 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3373 if (isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3374 $return .=
img_picto($langs->trans(
"SuperAdministratorDesc"),
'redstar',
'class="valignmiddle paddingright paddingleft"');
3375 } elseif ($this->admin) {
3376 $return .=
img_picto($langs->trans(
"AdministratorDesc"),
'star',
'class="valignmiddle paddingright paddingleft"');
3378 $return .=
'</span>';
3379 if ($selected >= 0) {
3380 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3382 if (property_exists($this,
'label')) {
3383 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3386 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->
email.
'</span>';
3388 if (method_exists($this,
'getLibStatut')) {
3389 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3391 $return .=
'</div>';
3392 $return .=
'</div>';
3393 $return .=
'</div>';
3417 } elseif ($mode == 1) {
3419 } elseif ($mode == 2) {
3435 global $conf, $langs;
3441 $keymodified =
false;
3450 'LDAP_FIELD_FULLNAME' =>
'fullname',
3451 'LDAP_FIELD_NAME' =>
'lastname',
3452 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3453 'LDAP_FIELD_LOGIN' =>
'login',
3454 'LDAP_FIELD_LOGIN_SAMBA' =>
'login',
3455 'LDAP_FIELD_PHONE' =>
'office_phone',
3456 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3457 'LDAP_FIELD_FAX' =>
'office_fax',
3458 'LDAP_FIELD_MAIL' =>
'email',
3459 'LDAP_FIELD_SID' =>
'ldap_sid',
3463 foreach ($ldapkey as $constname => $varname) {
3469 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->$varname != $this->oldcopy->$varname) {
3470 $keymodified =
true;
3475 foreach ($socialnetworks as $key => $value) {
3476 if (!empty($this->socialnetworks[$value[
'label']]) &&
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))) {
3477 $info[
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))] = $this->socialnetworks[$value[
'label']];
3492 if ($this->socid > 0) {
3493 $soc =
new Societe($this->db);
3494 $soc->fetch($this->socid);
3497 if ($soc->client == 1) {
3498 $info[
"businessCategory"] =
"Customers";
3500 if ($soc->client == 2) {
3501 $info[
"businessCategory"] =
"Prospects";
3503 if ($soc->fournisseur == 1) {
3504 $info[
"businessCategory"] =
"Suppliers";
3509 if (!empty($this->pass)) {
3522 if ($this->pass_indatabase_crypted &&
getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED')) {
3526 } elseif (!empty($this->pass_indatabase)) {
3538 $info[
"objectclass"][4] =
"phpgwContact";
3540 $info[
'uidnumber'] = $this->id;
3542 $info[
'phpgwTz'] = 0;
3543 $info[
'phpgwMailType'] =
'INTERNET';
3544 $info[
'phpgwMailHomeType'] =
'INTERNET';
3546 $info[
"phpgwContactTypeId"] =
'n';
3547 $info[
"phpgwContactCatId"] = 0;
3548 $info[
"phpgwContactAccess"] =
"public";
3556 $info[
"phpgwContactOwner"] = 1;
3559 $info[
"rfc822Mailbox"] = $this->email;
3561 if ($this->user_mobile) {
3562 $info[
"phpgwCellTelephoneNumber"] = $this->user_mobile;
3571 $groupslist = $usergroup->listGroupsForUser($this->
id);
3573 if (!empty($groupslist)) {
3574 foreach ($groupslist as $groupforuser) {
3581 $info[
getDolGlobalString(
'LDAP_FIELD_HOMEDIRECTORY')] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->login";
3597 global $user, $langs;
3603 $this->
ref =
'SPECIMEN';
3604 $this->specimen = 1;
3606 $this->lastname =
'DOLIBARR';
3607 $this->firstname =
'SPECIMEN';
3608 $this->gender =
'man';
3609 $this->note_public =
'This is a note public';
3610 $this->note_private =
'This is a note private';
3611 $this->
email =
'email@specimen.com';
3612 $this->personal_email =
'personalemail@specimen.com';
3613 $this->socialnetworks = array(
3614 'skype' =>
'skypepseudo',
3615 'twitter' =>
'twitterpseudo',
3616 'facebook' =>
'facebookpseudo',
3617 'linkedin' =>
'linkedinpseudo',
3619 $this->office_phone =
'0999999999';
3620 $this->office_fax =
'0999999998';
3621 $this->user_mobile =
'0999999997';
3622 $this->personal_mobile =
'0999999996';
3624 $this->login =
'dolibspec';
3625 $this->pass =
'dolibSpec+@123';
3628 $this->datec = $now;
3629 $this->datem = $now;
3631 $this->datelastlogin = $now;
3632 $this->iplastlogin =
'127.0.0.1';
3633 $this->datepreviouslogin = $now;
3634 $this->ippreviouslogin =
'127.0.0.1';
3651 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
3652 $sql .=
" u.tms as date_modification, u.entity";
3653 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3654 $sql .=
" WHERE u.rowid = ".((int) $id);
3656 $result = $this->db->query($sql);
3658 if ($this->db->num_rows($result)) {
3659 $obj = $this->db->fetch_object($result);
3661 $this->
id = $obj->rowid;
3663 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3664 $this->date_creation = $this->db->jdate($obj->datec);
3665 $this->date_modification = $this->db->jdate($obj->date_modification);
3666 $this->entity = $obj->entity;
3669 $this->db->free($result);
3683 $sql =
"SELECT count(mc.email) as nb";
3684 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3685 $sql .=
" WHERE mc.email = '".$this->db->escape($this->
email).
"'";
3686 $sql .=
" AND mc.statut NOT IN (-1,0)";
3688 $resql = $this->db->query($sql);
3690 $obj = $this->db->fetch_object($resql);
3693 $this->db->free($resql);
3696 $this->
error = $this->db->error();
3713 $sql =
"SELECT count(rowid) as nb";
3714 $sql .=
" FROM ".$this->db->prefix().
"user";
3715 if ($option ==
'superadmin') {
3716 $sql .=
" WHERE entity = 0";
3718 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3719 if ($limitTo ==
'active') {
3720 $sql .=
" AND statut = 1";
3724 $sql .=
" AND admin = ".(int) $admin;
3727 $resql = $this->db->query($sql);
3729 $obj = $this->db->fetch_object($resql);
3730 $nb = (int) $obj->nb;
3732 $this->db->free($resql);
3735 $this->
error = $this->db->lasterror();
3751 global $user, $conf;
3756 $this->firstname = $ldapuser->$tmpvar;
3758 $this->lastname = $ldapuser->$tmpvar;
3760 $this->login = $ldapuser->$tmpvar;
3762 $this->pass = $ldapuser->$tmpvar;
3764 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3767 $this->office_phone = $ldapuser->$tmpvar;
3769 $this->user_mobile = $ldapuser->$tmpvar;
3771 $this->office_fax = $ldapuser->$tmpvar;
3773 $this->
email = $ldapuser->$tmpvar;
3774 foreach ($socialnetworks as $key => $value) {
3776 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3779 $this->ldap_sid = $ldapuser->$tmpvar;
3782 $this->job = $ldapuser->$tmpvar;
3784 $this->note_public = $ldapuser->$tmpvar;
3786 $result = $this->
update($user);
3788 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3804 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3805 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3807 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3808 $res = $this->db->query($sql);
3811 while ($rec = $this->db->fetch_array($res)) {
3812 $user =
new User($this->db);
3813 $user->fetch($rec[
'rowid']);
3833 $this->parentof = array();
3836 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3837 $sql .=
" FROM ".$this->db->prefix().
"user";
3838 $sql .=
" WHERE fk_user <> 0";
3839 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3841 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3842 $resql = $this->db->query($sql);
3844 while ($obj = $this->db->fetch_object($resql)) {
3845 $this->parentof[$obj->id_son] = $obj->id_parent;
3871 global $conf, $user;
3872 global $hookmanager;
3875 $hookmanager->initHooks(array(
'userdao'));
3877 $this->users = array();
3883 $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";
3884 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3886 $parameters = array();
3887 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3889 $sql .= $hookmanager->resPrint;
3891 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3894 $sql .=
" AND ".$filter;
3897 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3898 $resql = $this->db->query($sql);
3901 while ($obj = $this->db->fetch_object($resql)) {
3902 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3903 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3904 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3905 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3906 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3907 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3908 $this->users[$obj->rowid][
'login'] = $obj->login;
3909 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3910 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3911 $this->users[$obj->rowid][
'email'] = $obj->email;
3912 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3913 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3914 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3916 $this->users[$obj->rowid][
'fullpath'] =
'';
3917 $this->users[$obj->rowid][
'fullname'] =
'';
3918 $this->users[$obj->rowid][
'level'] = 0;
3927 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3928 foreach ($this->users as $key => $val) {
3931 $this->
error =
'ErrorLoopInHierarchy';
3937 if ($deleteafterid) {
3939 $keyfilter1 =
'^'.$deleteafterid.
'$';
3940 $keyfilter2 =
'_'.$deleteafterid.
'$';
3941 $keyfilter3 =
'^'.$deleteafterid.
'_';
3942 $keyfilter4 =
'_'.$deleteafterid.
'_';
3943 foreach (array_keys($this->users) as $key) {
3944 $fullpath = (string) $this->users[$key][
'fullpath'];
3945 if (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
3946 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath)) {
3947 unset($this->users[$key]);
3952 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
3953 $this->users =
dol_sort_array($this->users,
'fullname',
'asc', 1, 0, 1);
3957 return $this->users;
3970 $childids = array();
3972 if (isset($this->cache_childids[$this->
id])) {
3973 $childids = $this->cache_childids[$this->id];
3978 $idtoscan = $this->id;
3980 dol_syslog(
"Build childid for id = ".$idtoscan);
3981 foreach ($this->users as $id => $val) {
3983 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
3984 $childids[$val[
'id']] = $val[
'id'];
3988 $this->cache_childids[$this->id] = $childids;
3990 if ($addcurrentuser) {
3991 $childids[$this->id] = $this->id;
4011 if (!empty($this->users[$id_user][
'fullpath'])) {
4013 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
4018 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
4019 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
4021 $cursor_user = $id_user;
4023 $useridfound = array($id_user);
4024 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
4025 if (in_array($this->parentof[$cursor_user], $useridfound)) {
4026 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
4029 $useridfound[] = $this->parentof[$cursor_user];
4030 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
4031 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
4033 $cursor_user = $this->parentof[$cursor_user];
4037 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
4069 $this->nb = array();
4071 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
4072 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4073 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
4074 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
4075 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
4076 $sql .=
" AND ug.fk_user = u.rowid";
4078 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4080 $sql .=
" AND u.statut > 0";
4083 $resql = $this->db->query($sql);
4085 while ($obj = $this->db->fetch_object($resql)) {
4086 $this->nb[
"users"] = $obj->nb;
4088 $this->db->free($resql);
4092 $this->
error = $this->db->error();
4108 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4110 global $conf, $user, $langs;
4112 $langs->load(
"user");
4119 $modele =
'bluesky';
4123 $modelpath =
"core/modules/user/doc/";
4125 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4139 $user_property =
'';
4141 if (empty($rowid)) {
4145 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
4146 $sql .=
" FROM ".$this->db->prefix().
"user";
4147 $sql .=
" WHERE rowid = ".((int) $rowid);
4149 $resql = $this->db->query($sql);
4151 $nump = $this->db->num_rows($resql);
4154 $obj = $this->db->fetch_object($resql);
4156 if ($mode ==
'email') {
4157 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
4158 } elseif ($mode ==
'mobile') {
4159 $user_property = $obj->user_mobile;
4160 } elseif ($mode ==
'name') {
4164 return $user_property;
4181 global $dolibarr_main_url_root;
4184 $encodedsecurekey =
dol_hash(
$conf->file->instance_unique_id.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
4185 if (isModEnabled(
'multicompany')) {
4186 $entity_qr =
'&entity='.((int)
$conf->entity);
4191 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
4192 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
4195 if ($typeofurl ==
'internal') {
4196 $urlwithroot = DOL_URL_ROOT;
4199 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
4215 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $entityfilter =
false)
4217 global $conf, $user;
4219 $sql =
"SELECT t.rowid";
4220 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
4222 if ($entityfilter) {
4224 if (!empty($user->admin) && empty($user->entity) &&
$conf->entity == 1) {
4225 $sql .=
" WHERE t.entity IS NOT NULL";
4227 $sql .=
" WHERE t.entity = 0 OR EXISTS (";
4228 $sql .=
" SELECT ug.rowid FROM " . $this->db->prefix() .
"usergroup_user as ug";
4229 $sql .=
" WHERE ug.fk_user = t.rowid AND ug.entity IN (" .
getEntity(
'usergroup') .
"))";
4232 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
4235 $sql .=
" WHERE 1 = 1";
4241 if ($errormessage) {
4242 $this->errors[] = $errormessage;
4243 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
4247 $sql .= $this->db->order($sortfield, $sortorder);
4249 $sql .= $this->db->plimit($limit + 1, $offset);
4254 $resql = $this->db->query($sql);
4256 $this->users = array();
4257 $num = $this->db->num_rows($resql);
4259 while ($obj = $this->db->fetch_object($resql)) {
4260 $line =
new self($this->db);
4261 $result = $line->fetch($obj->rowid);
4262 if ($result > 0 && !empty($line->id)) {
4263 $this->users[$obj->rowid] = clone $line;
4266 $this->db->free($resql);
4270 $this->errors[] = $this->db->lasterror();
4282 private $findUserIdByEmailCache;
4296 if (isset($this->findUserIdByEmailCache[$email])) {
4297 return $this->findUserIdByEmailCache[$email];
4300 $this->findUserIdByEmailCache[$email] = -1;
4302 $sql =
'SELECT rowid';
4303 $sql .=
' FROM '.$this->db->prefix().
'user';
4304 if (
getDolGlobalString(
'AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR')) {
4305 $sql .=
" WHERE email LIKE '%".$this->db->escape($this->db->escapeforlike($email)).
"%'";
4307 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4311 $resql = $this->db->query($sql);
4316 $obj = $this->db->fetch_object($resql);
4321 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4323 return $this->findUserIdByEmailCache[$email];
4334 if (empty($fromId) || empty($toId)) {
4341 $sqlDelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
4342 $sqlDelete .=
" WHERE fk_user = ".((int) $toId);
4344 dol_syslog(get_class($this).
"::clone_rights (delete default permissions)", LOG_DEBUG);
4346 if (!$this->db->query($sqlDelete)) {
4347 $this->db->rollback();
4352 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id)";
4353 $sql .=
" SELECT entity, ".((int) $toId).
", fk_id";
4354 $sql .=
" FROM ".$this->db->prefix().
"user_rights src";
4355 $sql .=
" WHERE fk_user = ".((int) $fromId);
4356 $sql .=
" AND NOT EXISTS (";
4357 $sql .=
" SELECT 1";
4358 $sql .=
" FROM ".$this->db->prefix().
"user_rights dest";
4359 $sql .=
" WHERE dest.entity = src.entity";
4360 $sql .=
" AND dest.fk_user = ".((int) $toId);
4361 $sql .=
" AND dest.fk_id = src.fk_id";
4364 dol_syslog(get_class($this).
"::clone_rights", LOG_DEBUG);
4367 if (!$this->db->query($sql)) {
4368 $this->db->rollback();
4372 $this->db->commit();
4389 $type = $this->table_element;
4392 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4393 $categorystatic =
new Categorie($this->db);
4395 $sql =
"INSERT INTO ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]).
" (fk_categorie, fk_user)";
4396 $sql .=
" SELECT fk_categorie, ".((int) $toId).
" FROM ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]);
4397 $sql .=
" WHERE fk_user = ".((int) $fromId);
4399 if (!$this->db->query($sql)) {
4400 $this->
error = $this->db->lasterror();
4401 $this->db->rollback();
4405 $this->db->commit();
Class to manage members of a foundation.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage categories.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage warehouses.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage user groups.
Class to manage Dolibarr users.
fetch($id=0, $login='', $sid='', $loadpersonalconf=0, $entity=-1, $email='', $fk_socpeople=0, $use_email_oauth2=0)
Load a user from database with its id or ref (login).
SetInGroup($group, $entity, $notrigger=0)
Add user into a group.
LibStatut($status, $mode=0)
Return the label of a status of user (active, inactive)
loadRights($moduletag='', $forcereload=0)
Load permissions granted to a user->id into object user->rights.
get_children()
Return and array with all instantiated first level children users of current user.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
loadStateBoard()
Load metrics this->nb for dashboard.
hasRight($module, $permlevel1, $permlevel2='')
Return if a user has a permission.
info($id)
Load info of user object.
create_from_contact($contact, $login='', $password='')
Create a user from a contact object.
setstatus($status)
Change status of a user.
get_full_tree($deleteafterid=0, $filter='')
Build the hierarchy/tree of users into an array.
_load_ldap_info()
Initialize the info array (array of LDAP values) that will be used to call LDAP functions.
delrights($rid, $allmodule='', $allperms='', $entity=0, $notrigger=0)
Remove a right to the user.
update_last_login_date()
Update the user's last login date in the database.
__construct($db)
Constructor of the class.
RemoveFromGroup($group, $entity, $notrigger=0)
Remove a user from a group.
isNotIntoValidityDateRange()
Return a link with photo Use this->id,this->photo.
getNbOfUsers($limitTo, $option='', $admin=-1)
Return number of existing users.
set_default_rights()
Assign rights by default.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND', $entityfilter=false)
Load all objects into $this->users.
getOnlineVirtualCardUrl($mode='', $typeofurl='external')
Return string with full Url to virtual card.
update($user, $notrigger=0, $nosyncmember=0, $nosyncmemberpass=0, $nosynccontact=0)
Update a user into database (and also password if this->pass is defined)
getLoginUrl($withpictoimg=0, $option='', $notooltip=0, $morecss='')
Return clickable link of login (optionally with picto)
setCategories($categories)
Sets object to supplied categories.
loadParentOf()
Load this->parentof that is array(id_son=>id_parent, ...)
fetch_clicktodial()
Read clicktodial information for user.
build_path_from_id_user($id_user, $protection=0)
For user id_user and its children available in this->users, define property fullpath and fullname.
error()
Renvoie la derniere erreur fonctionnelle de manipulation de l'objet.
cloneCategories($fromId, $toId, $type='user')
Copy related categories to another object.
getAllChildIds($addcurrentuser=0)
Return list of all child user ids in hierarchy (all sublevels).
initAsSpecimen()
Initialise an instance with random values.
setPassword($user, $password='', $changelater=0, $notrigger=0, $nosyncmember=0, $passwordalreadycrypted=0, $flagdelsessionsbefore=1)
Change password of a user.
getNomUrl($withpictoimg=0, $option='', $infologin=0, $notooltip=0, $maxlen=24, $hidethirdpartylogo=0, $mode='', $morecss='', $save_lastsearch_value=-1)
Return a HTML link to the user card (with optionally the picto) Use this->id,this->lastname,...
clearrights()
Clear all permissions array of user.
update_clicktodial()
Update clicktodial info.
cloneRights($fromId, $toId)
Clone permissions of user.
getLibStatut($mode=0)
Return the label of the status of user (active, inactive)
create_from_member($member, $login='')
Create a user into database from a member object.
loadPersonalConf()
Load const values from database table user_param and set it into user->conf->XXX.
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
loadDefaultValues()
Load default values from database table into property ->default_values.
getPhotoUrl($width, $height, $cssclass='', $imagesize='')
Return a link with photo Use this->id,this->photo.
update_ldap2dolibarr(&$ldapuser)
Update user using data from the LDAP.
getrights($moduletag='', $forcereload=0)
Load permissions granted to a user->id into object user->rights TODO Remove this method.
user_get_property($rowid, $mode)
Return property of user from its id.
send_password($user, $password='', $changelater=0)
Send a new password (or instructions to reset it) by email.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (optionally with picto)
getNbOfEMailings()
Return number of mass Emailing received by this contacts with its email.
addrights($rid, $allmodule='', $allperms='', $entity=0, $notrigger=0)
Add a right to the user.
create($user, $notrigger=0)
Create a user into database.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
findUserIdByEmail($email)
Find a user by the given e-mail and return it's user id when found.
getTooltipContentArray($params)
getTooltipContentArray
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
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)
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...
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.