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';
97 public $civility_code;
119 public $email_oauth2;
124 public $personal_email;
129 public $socialnetworks;
144 public $office_phone;
159 public $personal_mobile;
189 public $pass_crypted;
194 public $pass_indatabase;
199 public $pass_indatabase_crypted;
243 public $fk_user_expense_validator;
248 public $fk_user_holiday_validator;
258 public $clicktodial_login;
263 public $clicktodial_password;
268 public $clicktodial_poste;
273 public $clicktodial_loaded;
276 public $datelastlogin;
277 public $datepreviouslogin;
278 public $flagdelsessionsbefore;
280 public $ippreviouslogin;
281 public $datestartvalidity;
282 public $dateendvalidity;
302 public $all_permissions_are_loaded;
312 public $user_group_list;
317 private $_tab_loaded = array();
324 public $default_values;
326 public $lastsearch_values_tmp;
327 public $lastsearch_values;
332 public $users = array();
334 private $cache_childids;
336 public $accountancy_code;
350 public $dateemployment;
351 public $dateemploymentend;
353 public $default_c_exp_tax_cat;
358 public $ref_employee;
363 public $national_registration_number;
365 public $default_range;
370 public $fk_warehouse;
375 public $fk_establishment;
380 public $label_establishment;
391 public $usergroup_entity;
393 public $fields = array(
394 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
395 'lastname' => array(
'type' =>
'varchar(50)',
'label' =>
'Lastname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 20,
'searchall' => 1),
396 'firstname' => array(
'type' =>
'varchar(50)',
'label' =>
'Firstname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 10,
'searchall' => 1),
397 'ref_employee' => array(
'type' =>
'varchar(50)',
'label' =>
'RefEmployee',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 30,
'searchall' => 1),
398 'national_registration_number' => array(
'type' =>
'varchar(50)',
'label' =>
'NationalRegistrationNumber',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 40,
'searchall' => 1)
401 const STATUS_DISABLED = 0;
402 const STATUS_ENABLED = 1;
413 $this->ismultientitymanaged = 1;
414 $this->isextrafieldmanaged = 1;
416 $this->clicktodial_loaded = 0;
419 $this->all_permissions_are_loaded = 0;
420 $this->nb_rights = 0;
428 $this->rights->user =
new stdClass();
429 $this->rights->user->user =
new stdClass();
430 $this->rights->user->self =
new stdClass();
431 $this->rights->user->user_advance =
new stdClass();
432 $this->rights->user->self_advance =
new stdClass();
433 $this->rights->user->group_advance =
new stdClass();
450 public function fetch($id = 0, $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'', $fk_socpeople = 0, $use_email_oauth2 = 0)
455 $login = trim($login);
458 $sql =
"SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.civility as civility_code, u.birth, u.job,";
459 $sql .=
" u.email, u.email_oauth2, u.personal_email,";
460 $sql .=
" u.socialnetworks,";
461 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
462 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
463 $sql .=
" u.admin, u.login, u.note_private, u.note_public,";
464 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.api_key,";
465 $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,";
466 $sql .=
" u.statut as status, u.lang, u.entity,";
467 $sql .=
" u.datec as datec,";
468 $sql .=
" u.tms as datem,";
469 $sql .=
" u.datelastlogin as datel,";
470 $sql .=
" u.datepreviouslogin as datep,";
471 $sql .=
" u.flagdelsessionsbefore,";
472 $sql .=
" u.iplastlogin,";
473 $sql .=
" u.ippreviouslogin,";
474 $sql .=
" u.datelastpassvalidation,";
475 $sql .=
" u.datestartvalidity,";
476 $sql .=
" u.dateendvalidity,";
477 $sql .=
" u.photo as photo,";
478 $sql .=
" u.openid as openid,";
479 $sql .=
" u.accountancy_code,";
482 $sql .=
" u.salary,";
483 $sql .=
" u.salaryextra,";
484 $sql .=
" u.weeklyhours,";
486 $sql .=
" u.dateemployment, u.dateemploymentend,";
487 $sql .=
" u.fk_warehouse,";
488 $sql .=
" u.ref_ext,";
489 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
490 $sql .=
" u.national_registration_number,";
491 $sql .=
" u.ref_employee,";
492 $sql .=
" c.code as country_code, c.label as country,";
493 $sql .=
" d.code_departement as state_code, d.nom as state,";
494 $sql .=
" s.label as label_establishment, u.fk_establishment";
495 $sql .=
" FROM ".$this->db->prefix().
"user as u";
496 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as c ON u.fk_country = c.rowid";
497 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_departements as d ON u.fk_state = d.rowid";
498 $sql .=
" LEFT JOIN ".$this->db->prefix().
"establishment as s ON u.fk_establishment = s.rowid";
501 if ((!isModEnabled(
'multicompany') || !
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) && (!empty($user->entity))) {
502 $sql .=
" WHERE u.entity IN (0, ".((int) $conf->entity).
")";
504 $sql .=
" WHERE u.entity IS NOT NULL";
508 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
509 $sql .=
" WHERE u.entity IS NOT NULL";
511 $sql .=
" WHERE u.entity IN (0, ".((int) (($entity !=
'' && $entity >= 0) ? $entity : $conf->entity)).
")";
517 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->db->escape($login).
"')";
519 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
521 $sql .=
" AND (u.email = '".$this->db->escape($email).
"'";
522 if ($use_email_oauth2) {
523 $sql .=
" OR u.email_oauth2 = '".$this->db->escape($email).
"'";
526 } elseif ($fk_socpeople > 0) {
527 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
529 $sql .=
" AND u.rowid = ".((int) $id);
531 $sql .=
" ORDER BY u.entity ASC";
535 $sql .=
' '.$this->db->plimit(1);
538 $resql = $this->db->query($sql);
540 $num = $this->db->num_rows($resql);
542 $this->
error =
"USERDUPLICATEFOUND";
543 dol_syslog(get_class($this).
"::fetch more than 1 user found", LOG_WARNING);
545 $this->db->free($resql);
549 $obj = $this->db->fetch_object($resql);
551 $this->
id = $obj->rowid;
552 $this->
ref = $obj->rowid;
554 $this->ref_ext = $obj->ref_ext;
556 $this->ldap_sid = $obj->ldap_sid;
557 $this->civility_code = $obj->civility_code;
558 $this->lastname = $obj->lastname;
559 $this->firstname = $obj->firstname;
560 $this->ref_employee = $obj->ref_employee;
561 $this->national_registration_number = $obj->national_registration_number;
563 $this->employee = $obj->employee;
565 $this->login = $obj->login;
566 $this->gender = $obj->gender;
567 $this->birth = $this->db->jdate($obj->birth);
568 $this->pass_indatabase = $obj->pass;
569 $this->pass_indatabase_crypted = $obj->pass_crypted;
570 $this->pass = $obj->pass;
571 $this->pass_temp = $obj->pass_temp;
574 $this->address = $obj->address;
575 $this->zip = $obj->zip;
576 $this->town = $obj->town;
578 $this->country_id = $obj->country_id;
579 $this->country_code = $obj->country_id ? $obj->country_code :
'';
582 $this->state_id = $obj->state_id;
583 $this->state_code = $obj->state_code;
584 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
586 $this->office_phone = $obj->office_phone;
587 $this->office_fax = $obj->office_fax;
588 $this->user_mobile = $obj->user_mobile;
589 $this->personal_mobile = $obj->personal_mobile;
590 $this->
email = $obj->email;
591 $this->email_oauth2 = $obj->email_oauth2;
592 $this->personal_email = $obj->personal_email;
593 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
594 $this->job = $obj->job;
595 $this->signature = $obj->signature;
596 $this->admin = $obj->admin;
597 $this->note_public = $obj->note_public;
598 $this->note_private = $obj->note_private;
600 $this->statut = $obj->status;
601 $this->
status = $obj->status;
603 $this->photo = $obj->photo;
604 $this->openid = $obj->openid;
605 $this->lang = $obj->lang;
606 $this->entity = $obj->entity;
607 $this->accountancy_code = $obj->accountancy_code;
608 $this->thm = $obj->thm;
609 $this->tjm = $obj->tjm;
610 $this->salary = $obj->salary;
611 $this->salaryextra = $obj->salaryextra;
612 $this->weeklyhours = $obj->weeklyhours;
613 $this->color = $obj->color;
614 $this->dateemployment = $this->db->jdate($obj->dateemployment);
615 $this->dateemploymentend = $this->db->jdate($obj->dateemploymentend);
617 $this->datec = $this->db->jdate($obj->datec);
618 $this->datem = $this->db->jdate($obj->datem);
619 $this->datelastlogin = $this->db->jdate($obj->datel);
620 $this->datepreviouslogin = $this->db->jdate($obj->datep);
621 $this->flagdelsessionsbefore = $this->db->jdate($obj->flagdelsessionsbefore,
'gmt');
622 $this->iplastlogin = $obj->iplastlogin;
623 $this->ippreviouslogin = $obj->ippreviouslogin;
624 $this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
625 $this->dateendvalidity = $this->db->jdate($obj->dateendvalidity);
627 $this->socid = $obj->fk_soc;
628 $this->contact_id = $obj->fk_socpeople;
629 $this->fk_member = $obj->fk_member;
630 $this->fk_user = $obj->fk_user;
631 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
632 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
634 $this->default_range = $obj->default_range;
635 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
636 $this->fk_warehouse = $obj->fk_warehouse;
637 $this->fk_establishment = $obj->fk_establishment;
638 $this->label_establishment = $obj->label_establishment;
642 if (!isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
650 $this->db->free($resql);
652 $this->
error =
"USERNOTFOUND";
653 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
655 $this->db->free($resql);
659 $this->
error = $this->db->lasterror();
664 if ($loadpersonalconf) {
670 $this->
error = $this->db->lasterror();
689 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
690 $sql .=
" WHERE fk_user = ".((int) $this->
id);
691 $sql .=
" AND entity = ".((int) $conf->entity);
693 $resql = $this->db->query($sql);
695 $num = $this->db->num_rows($resql);
698 $obj = $this->db->fetch_object($resql);
699 $p = (!empty($obj->param) ? $obj->param :
'');
701 $this->
conf->$p = $obj->value;
705 $this->db->free($resql);
709 $this->
error = $this->db->lasterror();
726 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
729 $result = $defaultValues->fetchAll(
'',
'', 0, 0,
'(t.user_id:in:0,'.$this->
id.
') AND (entity:in:'.(isset($this->entity) ? $this->entity : $conf->entity).
','.$conf->entity.
')');
732 if (!is_array($result) && $result < 0) {
736 } elseif (count($result) > 0) {
737 foreach ($result as $defval) {
738 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
739 $pagewithoutquerystring = $defval->page;
742 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
743 $pagewithoutquerystring = $reg[1];
744 $pagequeries = $reg[2];
746 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
750 if (!empty($this->default_values)) {
751 foreach ($this->default_values as $a => $b) {
752 foreach ($b as $c => $d) {
753 krsort($this->default_values[$a][$c]);
772 public function hasRight($module, $permlevel1, $permlevel2 =
'')
775 $moduletomoduletouse = array(
776 'compta' =>
'comptabilite',
777 'contract' =>
'contrat',
778 'member' =>
'adherent',
780 'order' =>
'commande',
781 'produit' =>
'product',
782 'project' =>
'projet',
783 'propale' =>
'propal',
784 'shipping' =>
'expedition',
785 'task' =>
'task@projet',
786 'fichinter' =>
'ficheinter',
787 'inventory' =>
'stock',
788 'invoice' =>
'facture',
789 'invoice_supplier' =>
'fournisseur',
790 'order_supplier' =>
'fournisseur',
791 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
792 'skill@hrm' =>
'all@hrm',
793 'job@hrm' =>
'all@hrm',
794 'position@hrm' =>
'all@hrm',
795 'facturerec' =>
'facture',
796 'margins' =>
'margin',
799 if (!empty($moduletomoduletouse[$module])) {
800 $module = $moduletomoduletouse[$module];
803 $moduleRightsMapping = array(
804 'product' =>
'produit',
805 'margin' =>
'margins',
806 'comptabilite' =>
'compta'
809 $rightsPath = $module;
810 if (!empty($moduleRightsMapping[$rightsPath])) {
811 $rightsPath = $moduleRightsMapping[$rightsPath];
815 $tmp = explode(
'@', $rightsPath, 2);
816 if (!empty($tmp[1])) {
817 if (strpos($module,
'@') !==
false) {
820 if ($tmp[0] != $tmp[1]) {
822 $rightsPath = $tmp[1];
823 $permlevel2 = $permlevel1;
824 $permlevel1 = $tmp[0];
827 $rightsPath = $tmp[1];
836 if (!isModEnabled($module)) {
841 if (!empty($this->socid)) {
842 if ($module ==
'societe' && ($permlevel1 ==
'creer' || $permlevel1 ==
'write')) {
845 if ($module ==
'societe' && $permlevel1 ==
'client' && $permlevel2 ==
'voir') {
848 if ($module ==
'societe' && $permlevel1 ==
'export') {
851 if ($module ==
'societe' && ($permlevel1 ==
'supprimer' || $permlevel1 ==
'delete')) {
857 if ($permlevel1 ==
'propale') {
858 $permlevel1 =
'propal';
860 if ($permlevel1 ==
'member') {
861 $permlevel1 =
'adherent';
863 if ($permlevel1 ==
'recruitmentcandidature') {
864 $permlevel1 =
'recruitmentjobposition';
869 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
874 if (!empty($this->rights->$rightsPath->$permlevel1)) {
875 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
876 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
880 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
881 return $this->rights->$rightsPath->$permlevel1->lire;
883 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
884 return $this->rights->$rightsPath->$permlevel1->creer;
886 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
887 return $this->rights->$rightsPath->$permlevel1->create;
889 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
890 return $this->rights->$rightsPath->$permlevel1->supprimer;
894 if (!empty($this->rights->$rightsPath->$permlevel1)) {
895 return $this->rights->$rightsPath->$permlevel1;
899 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
900 return $this->rights->$rightsPath->lire;
902 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
903 return $this->rights->$rightsPath->creer;
905 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
906 return $this->rights->$rightsPath->create;
908 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
909 return $this->rights->$rightsPath->supprimer;
927 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
929 global $conf, $user, $langs;
931 $entity = (empty($entity) ? $conf->entity : $entity);
933 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
935 if (empty($this->
id)) {
936 $this->
error =
'Try to call addrights on an object user with an empty id';
946 $module = $perms = $subperms =
'';
949 $sql =
"SELECT module, perms, subperms";
950 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
951 $sql .=
" WHERE id = ".((int) $rid);
952 $sql .=
" AND entity = ".((int) $entity);
954 $result = $this->db->query($sql);
956 $obj = $this->db->fetch_object($result);
959 $module = $obj->module;
960 $perms = $obj->perms;
961 $subperms = $obj->subperms;
969 $whereforadd =
"id=".((int) $rid);
971 if (!empty($subperms)) {
972 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
973 } elseif (!empty($perms)) {
974 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND (subperms IS NULL or subperms = ''))";
980 if (!empty($allmodule)) {
981 if ($allmodule ==
'allmodules') {
982 $whereforadd =
'allmodules';
984 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
985 if (!empty($allperms)) {
986 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
994 if (!empty($whereforadd)) {
997 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
998 $sql .=
" WHERE entity = ".((int) $entity);
999 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
1000 $sql .=
" AND (".$whereforadd.
")";
1003 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1004 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1006 $sqldelete .=
") AND entity = ".((int) $entity);
1007 if (!$this->db->query($sqldelete)) {
1012 $resql = $this->db->query($sql);
1014 $num = $this->db->num_rows($resql);
1017 $obj = $this->db->fetch_object($resql);
1022 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
1023 if (!$this->db->query($sql)) {
1037 if (!$error && !$notrigger) {
1038 $langs->load(
"other");
1039 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
1050 $this->db->rollback();
1053 $this->db->commit();
1070 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1072 global $conf, $user, $langs;
1076 $entity = (!empty($entity) ? $entity : $conf->entity);
1081 $module = $perms = $subperms =
'';
1085 $sql =
"SELECT module, perms, subperms";
1086 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1087 $sql .=
" WHERE id = '".$this->db->escape($rid).
"'";
1088 $sql .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1090 $result = $this->db->query($sql);
1092 $obj = $this->db->fetch_object($result);
1095 $module = $obj->module;
1096 $perms = $obj->perms;
1097 $subperms = $obj->subperms;
1105 $wherefordel =
"id=".((int) $rid);
1107 if ($subperms ==
'lire' || $subperms ==
'read') {
1108 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1110 if ($perms ==
'lire' || $perms ==
'read') {
1111 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1117 if (!empty($allmodule)) {
1118 if ($allmodule ==
'allmodules') {
1119 $wherefordel =
'allmodules';
1121 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1122 if (!empty($allperms)) {
1123 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1130 if (!empty($wherefordel)) {
1133 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1134 $sql .=
" WHERE entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1135 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1136 $sql .=
" AND (".$wherefordel.
")";
1140 if ($this->admin == 1) {
1141 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1142 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1143 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1144 $sql .=
" AND id NOT IN (358)";
1147 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1148 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1151 $sqldelete .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1153 $resql = $this->db->query($sqldelete);
1160 if (!$error && !$notrigger) {
1161 $langs->load(
"other");
1162 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1173 $this->db->rollback();
1176 $this->db->commit();
1190 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1192 $this->nb_rights = 0;
1193 $this->all_permissions_are_loaded = 0;
1194 $this->_tab_loaded = array();
1210 $alreadyloaded =
false;
1212 if (empty($forcereload)) {
1213 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1215 $alreadyloaded =
true;
1218 if (!empty($this->all_permissions_are_loaded)) {
1220 $alreadyloaded =
true;
1225 if (!isset($this->rights) || !is_object($this->rights)) {
1228 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1229 $this->rights->user =
new stdClass();
1234 if (!$alreadyloaded) {
1236 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1237 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1238 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1239 $sql .=
" WHERE r.id = ur.fk_id";
1245 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') ?
"1," :
"").$conf->entity.
")";
1249 $sql .=
" AND r.entity = ".((int) $conf->entity).
" AND ur.entity = ".((int) $conf->entity);
1251 $sql .=
" AND ur.fk_user = ".((int) $this->
id);
1252 $sql .=
" AND r.perms IS NOT NULL";
1254 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1257 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1260 $resql = $this->db->query($sql);
1262 $num = $this->db->num_rows($resql);
1265 $obj = $this->db->fetch_object($resql);
1268 $module = $obj->module;
1269 $perms = $obj->perms;
1270 $subperms = $obj->subperms;
1272 if (!empty($perms)) {
1273 if (!empty($module)) {
1274 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1275 $this->rights->$module =
new stdClass();
1277 if (!empty($subperms)) {
1278 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1279 $this->rights->$module->$perms =
new stdClass();
1281 if (empty($this->rights->$module->$perms->$subperms)) {
1284 $this->rights->$module->$perms->$subperms = 1;
1286 if (empty($this->rights->$module->$perms)) {
1289 $this->rights->$module->$perms = 1;
1296 $this->db->free($resql);
1300 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms, r.entity";
1301 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1302 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1303 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1304 $sql .=
" WHERE r.id = gr.fk_id";
1309 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1310 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1312 $sql .=
" AND r.entity = ".((int) $conf->entity);
1315 $sql .=
" AND gr.entity = ".((int) $conf->entity);
1319 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1320 $sql .=
" AND r.entity = ".((int) $conf->entity);
1323 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1324 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1325 $sql .=
" AND r.perms IS NOT NULL";
1327 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1330 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1333 $resql = $this->db->query($sql);
1335 $num = $this->db->num_rows($resql);
1338 $obj = $this->db->fetch_object($resql);
1341 $module = $obj->module;
1342 $perms = $obj->perms;
1343 $subperms = $obj->subperms;
1345 if (!empty($perms)) {
1346 if (!empty($module)) {
1347 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1348 $this->rights->$module =
new stdClass();
1350 if (!empty($subperms)) {
1351 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1352 $this->rights->$module->$perms =
new stdClass();
1354 if (empty($this->rights->$module->$perms->$subperms)) {
1357 $this->rights->$module->$perms->$subperms = 1;
1360 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1361 if (empty($this->rights->$module->$perms)) {
1364 $this->rights->$module->$perms = 1;
1372 $this->db->free($resql);
1376 if (!empty($this->admin)) {
1377 if (empty($this->rights->user->user)) {
1378 $this->rights->user->user =
new stdClass();
1380 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1381 foreach ($listofpermtotest as $permtotest) {
1382 if (empty($this->rights->user->user->$permtotest)) {
1383 $this->rights->user->user->$permtotest = 1;
1387 if (empty($this->rights->user->self)) {
1388 $this->rights->user->self =
new stdClass();
1390 $listofpermtotest = array(
'creer',
'password');
1391 foreach ($listofpermtotest as $permtotest) {
1392 if (empty($this->rights->user->self->$permtotest)) {
1393 $this->rights->user->self->$permtotest = 1;
1399 if (empty($this->rights->user->user_advance)) {
1400 $this->rights->user->user_advance =
new stdClass();
1402 $listofpermtotest = array(
'readperms',
'write');
1403 foreach ($listofpermtotest as $permtotest) {
1404 if (empty($this->rights->user->user_advance->$permtotest)) {
1405 $this->rights->user->user_advance->$permtotest = 1;
1409 if (empty($this->rights->user->self_advance)) {
1410 $this->rights->user->self_advance =
new stdClass();
1412 $listofpermtotest = array(
'readperms',
'writeperms');
1413 foreach ($listofpermtotest as $permtotest) {
1414 if (empty($this->rights->user->self_advance->$permtotest)) {
1415 $this->rights->user->self_advance->$permtotest = 1;
1419 if (empty($this->rights->user->group_advance)) {
1420 $this->rights->user->group_advance =
new stdClass();
1422 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1423 foreach ($listofpermtotest as $permtotest) {
1424 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1425 $this->rights->user->group_advance->$permtotest = 1;
1433 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1434 $this->rights->propal = $this->rights->propale;
1436 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1437 $this->rights->propale = $this->rights->propal;
1444 $this->all_permissions_are_loaded = 1;
1447 $this->_tab_loaded[$moduletag] = 1;
1464 public function getrights($moduletag =
'', $forcereload = 0)
1477 global $conf, $langs, $user;
1482 if (isset($this->statut)) {
1483 if ($this->statut == $status) {
1486 } elseif (isset($this->
status) && $this->
status == $status) {
1493 $sql =
"UPDATE ".$this->db->prefix().
"user";
1494 $sql .=
" SET statut = ".((int) $status);
1495 $sql .=
" WHERE rowid = ".((int) $this->
id);
1496 $result = $this->db->query($sql);
1498 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1501 $this->context[
'actionmsg'] =
'User '.$this->login.
' disabled';
1503 $this->context[
'actionmsg'] =
'User '.$this->login.
' enabled';
1506 $result = $this->
call_trigger(
'USER_ENABLEDISABLE', $user);
1514 $this->db->rollback();
1518 $this->statut = $status;
1519 $this->db->commit();
1536 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1537 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1548 global $conf, $langs;
1554 $this->
fetch($this->
id);
1556 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1559 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1561 if (!$error && !$this->db->query($sql)) {
1563 $this->
error = $this->db->lasterror();
1567 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1568 if (!$error && !$this->db->query($sql)) {
1570 $this->
error = $this->db->lasterror();
1574 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1575 if (!$error && !$this->db->query($sql)) {
1577 $this->
error = $this->db->lasterror();
1581 if ($this->contact_id > 0) {
1582 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1583 if (!$error && !$this->db->query($sql)) {
1585 $this->
error = $this->db->lasterror();
1594 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1600 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1601 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1602 if (!$this->db->query($sql)) {
1604 $this->
error = $this->db->lasterror();
1613 $this->db->rollback();
1618 $this->db->commit();
1621 $this->db->rollback();
1633 public function create($user, $notrigger = 0)
1635 global $conf, $langs;
1641 $this->civility_code = trim((
string) $this->civility_code);
1642 $this->login = trim((
string) $this->login);
1643 if (!isset($this->entity)) {
1644 $this->entity = $conf->entity;
1647 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1649 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1653 $langs->load(
"errors");
1654 $this->
error = $langs->trans(
"ErrorBadEMail", $this->
email);
1657 if (empty($this->login)) {
1658 $langs->load(
"errors");
1659 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1661 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1662 $langs->load(
"errors");
1663 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1674 $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).
"'";
1675 $resqltochecklogin = $this->db->query($sqltochecklogin);
1676 if ($resqltochecklogin) {
1677 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1678 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1679 $langs->load(
"errors");
1680 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1682 $this->db->rollback();
1685 $this->db->free($resqltochecklogin);
1688 if (!empty($this->
email)) {
1689 $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).
"'";
1690 $resqltochecklogin = $this->db->query($sqltochecklogin);
1691 if ($resqltochecklogin) {
1692 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1693 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1694 $langs->load(
"errors");
1695 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->
email);
1697 $this->db->rollback();
1700 $this->db->free($resqltochecklogin);
1705 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, entity)";
1706 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->db->escape($this->login).
"', '".$this->db->escape($this->ldap_sid).
"', ".((int) $this->entity).
")";
1707 $result = $this->db->query($sql);
1709 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1711 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1715 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1716 $this->db->rollback();
1721 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1722 $langs->load(
"stocks");
1724 $entrepot =
new Entrepot($this->db);
1725 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1726 $entrepot->libelle = $entrepot->label;
1727 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1728 $entrepot->statut = 1;
1729 $entrepot->country_id = $mysoc->country_id;
1731 $warehouseid = $entrepot->create($user);
1733 $this->fk_warehouse = $warehouseid;
1737 $result = $this->
update($user, 1, 1);
1739 $this->db->rollback();
1753 $this->db->commit();
1758 $this->db->rollback();
1762 $this->
error = $this->db->lasterror();
1763 $this->db->rollback();
1781 global $conf, $user, $langs;
1787 $this->civility_code = $contact->civility_code;
1788 $this->lastname = $contact->lastname;
1789 $this->firstname = $contact->firstname;
1791 $this->
email = $contact->email;
1792 $this->socialnetworks = $contact->socialnetworks;
1793 $this->office_phone = $contact->phone_pro;
1794 $this->office_fax = $contact->fax;
1795 $this->user_mobile = $contact->phone_mobile;
1796 $this->address = $contact->address;
1797 $this->zip = $contact->zip;
1798 $this->town = $contact->town;
1800 $this->state_id = $contact->state_id;
1801 $this->country_id = $contact->country_id;
1802 $this->employee = 0;
1804 if (empty($login)) {
1805 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1806 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1808 $this->login = $login;
1813 $result = $this->
create($user, 1);
1815 $sql =
"UPDATE ".$this->db->prefix().
"user";
1816 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1817 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1818 if ($contact->socid > 0) {
1819 $sql .=
", fk_soc=".((int) $contact->socid);
1821 $sql .=
" WHERE rowid=".((int) $this->
id);
1823 $resql = $this->db->query($sql);
1825 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1827 $this->context[
'createfromcontact'] =
'createfromcontact';
1833 $this->db->rollback();
1838 $this->db->commit();
1841 $this->
error = $this->db->error();
1843 $this->db->rollback();
1848 dol_syslog(get_class($this).
"::create_from_contact - 0");
1850 $this->db->rollback();
1871 $this->civility_code = $member->civility_code;
1872 $this->lastname = $member->lastname;
1873 $this->firstname = $member->firstname;
1874 $this->gender = $member->gender;
1875 $this->
email = $member->email;
1876 $this->fk_member = $member->id;
1877 $this->address = $member->address;
1878 $this->zip = $member->zip;
1879 $this->town = $member->town;
1881 $this->state_id = $member->state_id;
1882 $this->country_id = $member->country_id;
1883 $this->socialnetworks = $member->socialnetworks;
1885 $this->pass = $member->pass;
1886 $this->pass_crypted = $member->pass_indatabase_crypted;
1888 if (empty($login)) {
1889 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1892 $this->login = $login;
1897 $result = $this->
create($user);
1899 if (!empty($this->pass)) {
1900 $newpass = $this->
setPassword($user, $this->pass);
1901 if (is_int($newpass) && $newpass < 0) {
1904 } elseif (!empty($this->pass_crypted)) {
1905 $sql =
"UPDATE ".$this->db->prefix().
"user";
1906 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
1907 $sql .=
" WHERE rowid=".((int) $this->
id);
1909 $resql = $this->db->query($sql);
1915 if ($result > 0 && $member->socid) {
1916 $sql =
"UPDATE ".$this->db->prefix().
"user";
1917 $sql .=
" SET fk_soc=".((int) $member->socid);
1918 $sql .=
" WHERE rowid=".((int) $this->
id);
1920 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
1921 $resql = $this->db->query($sql);
1923 $this->db->commit();
1926 $this->
error = $this->db->lasterror();
1928 $this->db->rollback();
1935 $this->db->commit();
1939 $this->db->rollback();
1957 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
1958 $sql .=
" WHERE bydefault = 1";
1959 $sql .=
" AND entity = ".((int) $conf->entity);
1961 $resql = $this->db->query($sql);
1963 $num = $this->db->num_rows($resql);
1966 $row = $this->db->fetch_row($resql);
1970 $this->db->free($resql);
1974 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
1975 $result = $this->db->query($sql);
1977 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
1978 $result = $this->db->query($sql);
1998 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
2000 global $conf, $langs;
2002 $nbrowsaffected = 0;
2005 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
2008 $this->civility_code = trim((
string) $this->civility_code);
2009 $this->lastname = trim((
string) $this->lastname);
2010 $this->firstname = trim((
string) $this->firstname);
2011 $this->ref_employee = trim((
string) $this->ref_employee);
2012 $this->national_registration_number = trim((
string) $this->national_registration_number);
2013 $this->employee = ($this->employee > 0 ? $this->employee : 0);
2014 $this->login = trim((
string) $this->login);
2015 $this->gender = trim((
string) $this->gender);
2017 $this->pass = trim((
string) $this->pass);
2018 $this->api_key = trim((
string) $this->api_key);
2019 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
2020 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
2022 $this->address = trim((
string) $this->address);
2023 $this->zip = trim((
string) $this->zip);
2024 $this->town = trim((
string) $this->town);
2026 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
2027 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
2028 $this->office_phone = trim((
string) $this->office_phone);
2029 $this->office_fax = trim((
string) $this->office_fax);
2030 $this->user_mobile = trim((
string) $this->user_mobile);
2031 $this->personal_mobile = trim((
string) $this->personal_mobile);
2033 $this->personal_email = trim((
string) $this->personal_email);
2035 $this->job = trim((
string) $this->job);
2036 $this->signature = trim((
string) $this->signature);
2037 $this->note_public = trim((
string) $this->note_public);
2038 $this->note_private = trim((
string) $this->note_private);
2039 $this->openid = trim((
string) $this->openid);
2040 $this->admin = ($this->admin > 0 ? $this->admin : 0);
2042 $this->accountancy_code = trim((
string) $this->accountancy_code);
2043 $this->color = trim((
string) $this->color);
2044 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
2045 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
2047 $this->birth = empty($this->birth) ?
'' : $this->birth;
2048 $this->fk_warehouse = (int) $this->fk_warehouse;
2049 $this->fk_establishment = (int) $this->fk_establishment;
2054 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
2057 $langs->load(
"errors");
2058 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
2061 if (empty($this->login)) {
2062 $langs->load(
"errors");
2063 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
2065 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
2066 $langs->load(
"errors");
2067 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
2074 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->oldcopy->login != $this->login) {
2075 $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).
"'";
2076 $resqltochecklogin = $this->db->query($sqltochecklogin);
2077 if ($resqltochecklogin) {
2078 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2079 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2080 $langs->load(
"errors");
2081 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
2083 $this->db->rollback();
2088 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && !empty($this->email) && $this->oldcopy->email != $this->email) {
2089 $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).
"'";
2090 $resqltochecklogin = $this->db->query($sqltochecklogin);
2091 if ($resqltochecklogin) {
2092 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2093 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2094 $langs->load(
"errors");
2095 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
2097 $this->db->rollback();
2104 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2105 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
2106 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
2107 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
2108 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
2109 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
2110 $sql .=
", employee = ".(int) $this->employee;
2111 $sql .=
", login = '".$this->db->escape($this->login).
"'";
2112 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
2113 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
2114 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
2115 if (!empty($user->admin)) {
2116 $sql .=
", admin = ".(int) $this->admin;
2118 $sql .=
", address = '".$this->db->escape($this->address).
"'";
2119 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
2120 $sql .=
", town = '".$this->db->escape($this->town).
"'";
2121 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".$this->db->escape($this->state_id).
"'" :
"null");
2122 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".$this->db->escape($this->country_id).
"'" :
"null");
2123 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
2124 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
2125 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
2126 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
2127 $sql .=
", email = '".$this->db->escape($this->email).
"'";
2128 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
2129 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
2130 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2131 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2132 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2133 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2134 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2135 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2136 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2137 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2138 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2139 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2140 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2141 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2142 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".$this->db->escape($this->fk_user).
"'" :
"null");
2143 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".$this->db->escape($this->fk_user_expense_validator).
"'" :
"null");
2144 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".$this->db->escape($this->fk_user_holiday_validator).
"'" :
"null");
2145 if (isset($this->thm) || $this->thm !=
'') {
2146 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2148 if (isset($this->tjm) || $this->tjm !=
'') {
2149 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2151 if (isset($this->salary) || $this->salary !=
'') {
2152 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2154 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2155 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2157 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2158 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2159 $sql .=
", entity = ".((int) $this->entity);
2161 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2162 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2163 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2164 $sql .=
", fk_establishment = ".($this->fk_establishment > 0 ? $this->fk_establishment :
"null");
2165 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2166 $sql .=
" WHERE rowid = ".((int) $this->
id);
2168 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2169 $resql = $this->db->query($sql);
2171 $nbrowsaffected += $this->db->affected_rows($resql);
2174 if (!empty($this->pass)) {
2175 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2177 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2178 if (is_int($result) && $result < 0) {
2185 if ($this->fk_member > 0) {
2186 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2187 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2188 $resql = $this->db->query($sql);
2190 $this->
error = $this->db->error();
2191 $this->db->rollback();
2196 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2197 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2198 $resql = $this->db->query($sql);
2200 $this->
error = $this->db->error();
2201 $this->db->rollback();
2205 if ($nbrowsaffected) {
2206 if ($this->fk_member > 0 && !$nosyncmember) {
2207 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2209 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2214 $result = $adh->fetch($this->fk_member);
2217 $adh->civility_code = $this->civility_code;
2218 $adh->firstname = $this->firstname;
2219 $adh->lastname = $this->lastname;
2220 $adh->login = $this->login;
2221 $adh->gender = $this->gender;
2222 $adh->birth = $this->birth;
2224 $adh->pass = $this->pass;
2226 $adh->address = $this->address;
2227 $adh->town = $this->town;
2228 $adh->zip = $this->zip;
2229 $adh->state_id = $this->state_id;
2230 $adh->country_id = $this->country_id;
2232 $adh->email = $this->email;
2234 $adh->socialnetworks = $this->socialnetworks;
2236 $adh->phone = $this->office_phone;
2237 $adh->phone_mobile = $this->user_mobile;
2239 $adh->default_lang = $this->lang;
2241 $adh->user_id = $this->id;
2242 $adh->user_login = $this->login;
2244 $result = $adh->update($user, 0, 1, 0);
2246 $this->
error = $adh->error;
2247 $this->errors = $adh->errors;
2248 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2251 } elseif ($result < 0) {
2252 $this->
error = $adh->error;
2253 $this->errors = $adh->errors;
2258 if ($this->contact_id > 0 && !$nosynccontact) {
2259 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2261 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2264 $tmpobj =
new Contact($this->db);
2265 $result = $tmpobj->fetch($this->contact_id);
2268 $tmpobj->civility_code = $this->civility_code;
2269 $tmpobj->firstname = $this->firstname;
2270 $tmpobj->lastname = $this->lastname;
2271 $tmpobj->login = $this->login;
2272 $tmpobj->gender = $this->gender;
2273 $tmpobj->birth = $this->birth;
2277 $tmpobj->email = $this->email;
2279 $tmpobj->socialnetworks = $this->socialnetworks;
2281 $tmpobj->phone_pro = $this->office_phone;
2282 $tmpobj->phone_mobile = $this->user_mobile;
2283 $tmpobj->fax = $this->office_fax;
2285 $tmpobj->default_lang = $this->lang;
2287 $tmpobj->address = $this->address;
2288 $tmpobj->town = $this->town;
2289 $tmpobj->zip = $this->zip;
2290 $tmpobj->state_id = $this->state_id;
2291 $tmpobj->country_id = $this->country_id;
2293 $tmpobj->user_id = $this->id;
2294 $tmpobj->user_login = $this->login;
2296 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2298 $this->
error = $tmpobj->error;
2299 $this->errors = $tmpobj->errors;
2300 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2304 $this->
error = $tmpobj->error;
2305 $this->errors = $tmpobj->errors;
2321 if (!$error && !$notrigger) {
2331 $this->db->commit();
2332 return $nbrowsaffected;
2335 $this->db->rollback();
2339 $this->
error = $this->db->lasterror();
2340 $this->db->rollback();
2359 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2360 $sql .=
" datepreviouslogin = datelastlogin,";
2361 $sql .=
" ippreviouslogin = iplastlogin,";
2362 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2363 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2364 $sql .=
" tms = tms";
2365 $sql .=
" WHERE rowid = ".((int) $this->
id);
2367 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2368 $resql = $this->db->query($sql);
2370 $this->datepreviouslogin = $this->datelastlogin;
2371 $this->datelastlogin = $now;
2372 $this->ippreviouslogin = $this->iplastlogin;
2373 $this->iplastlogin = $userremoteip;
2376 $this->
error = $this->db->lasterror().
' sql='.$sql;
2394 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2396 global $conf, $langs;
2397 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2401 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2409 if (empty($passwordalreadycrypted)) {
2412 $modGeneratePassClass =
'modGeneratePass'.ucfirst($conf->global->USER_PASSWORD_GENERATED);
2414 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2415 if (class_exists($modGeneratePassClass)) {
2416 $modGeneratePass =
new $modGeneratePassClass($this->db, $conf, $langs, $user);
2419 $modGeneratePass->WithoutAmbi = 0;
2422 $testpassword = $modGeneratePass->validatePassword($password);
2423 if (!$testpassword) {
2424 $this->
error = $modGeneratePass->error;
2432 $password_crypted =
dol_hash($password);
2436 if (!$changelater) {
2437 if (!is_object($this->oldcopy)) {
2438 $this->oldcopy = clone $this;
2443 $sql =
"UPDATE ".$this->db->prefix().
"user";
2444 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2445 $sql .=
" pass_temp = null";
2446 if (!empty($flagdelsessionsbefore)) {
2447 $sql .=
", flagdelsessionsbefore = '".$this->db->idate(
dol_now() - 5,
'gmt').
"'";
2450 $sql .=
", pass = null";
2452 $sql .=
", pass = '".$this->db->escape($password).
"'";
2454 $sql .=
" WHERE rowid = ".((int) $this->
id);
2456 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2457 $result = $this->db->query($sql);
2459 if ($this->db->affected_rows($result)) {
2460 $this->pass = $password;
2461 $this->pass_indatabase = $password;
2462 $this->pass_indatabase_crypted = $password_crypted;
2464 if ($this->fk_member && !$nosyncmember) {
2465 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2470 $result = $adh->fetch($this->fk_member);
2473 $result = $adh->setPassword($user, $this->pass, (!
getDolGlobalString(
'DATABASE_PWD_ENCRYPTED') ? 0 : 1), 1);
2474 if (is_int($result) && $result < 0) {
2475 $this->
error = $adh->error;
2480 $this->
error = $adh->error;
2485 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2487 if (!$error && !$notrigger) {
2489 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2492 $this->db->rollback();
2498 $this->db->commit();
2501 $this->db->rollback();
2505 $this->db->rollback();
2512 $sql =
"UPDATE ".$this->db->prefix().
"user";
2513 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2514 $sql .=
" WHERE rowid = ".((int) $this->
id);
2516 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2517 $result = $this->db->query($sql);
2539 global $conf, $langs, $mysoc;
2540 global $dolibarr_main_url_root;
2542 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2549 $outputlangs =
new Translate(
"", $conf);
2551 if (isset($this->
conf->MAIN_LANG_DEFAULT)
2552 && $this->conf->MAIN_LANG_DEFAULT !=
'auto') {
2553 $outputlangs->getDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2556 if ($this->
conf->MAIN_LANG_DEFAULT) {
2557 $outputlangs->setDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2559 $outputlangs = $langs;
2563 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2565 $appli =
getDolGlobalString(
'MAIN_APPLICATION_TITLE', constant(
'DOL_APPLICATION_TITLE'));
2567 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2570 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2571 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2573 if (!$changelater) {
2574 $url = $urlwithroot.
'/';
2579 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2581 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2582 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2583 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2584 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2587 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2589 $mesg .= $user->getFullName($outputlangs);
2592 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2593 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.$conf->file->instance_unique_id));
2594 if (isModEnabled(
'multicompany')) {
2595 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2598 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2602 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2603 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2604 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2605 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2607 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2608 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2609 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2612 $trackid =
'use'.$this->id;
2613 $sendcontext =
'passwordreset';
2618 $conf->global->MAIN_MAIL_EMAIL_FROM,
2634 if ($mailfile->sendfile()) {
2637 $langs->trans(
"errors");
2638 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2650 return $this->error;
2663 $sql =
"SELECT url, login, pass, poste ";
2664 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2665 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2667 $resql = $this->db->query($sql);
2669 if ($this->db->num_rows($resql)) {
2670 $obj = $this->db->fetch_object($resql);
2672 $this->clicktodial_url = $obj->url;
2673 $this->clicktodial_login = $obj->login;
2674 $this->clicktodial_password = $obj->pass;
2675 $this->clicktodial_poste = $obj->poste;
2678 $this->clicktodial_loaded = 1;
2680 $this->db->free($resql);
2683 $this->
error = $this->db->error();
2699 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2700 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2702 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2703 $result = $this->db->query($sql);
2705 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2706 $sql .=
" (fk_user,url,login,pass,poste)";
2707 $sql .=
" VALUES (".$this->id;
2708 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2709 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2710 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2711 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2713 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2714 $result = $this->db->query($sql);
2716 $this->db->commit();
2719 $this->db->rollback();
2720 $this->
error = $this->db->lasterror();
2738 global $conf, $langs, $user;
2744 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2745 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2746 $sql .=
" AND fk_usergroup = ".((int) $group);
2747 $sql .=
" AND entity = ".((int) $entity);
2749 $result = $this->db->query($sql);
2751 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2752 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2754 $result = $this->db->query($sql);
2756 if (!$error && !$notrigger) {
2757 $this->context = array(
'audit' => $langs->trans(
"UserSetInGroup"),
'newgroupid' => $group);
2768 $this->db->commit();
2772 $this->db->rollback();
2776 $this->
error = $this->db->lasterror();
2777 $this->db->rollback();
2794 global $conf, $langs, $user;
2800 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2801 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2802 $sql .=
" AND fk_usergroup = ".((int) $group);
2803 if (empty($entity)) {
2804 $sql .=
" AND entity IN (0, 1)";
2806 $sql .=
" AND entity = ".((int) $entity);
2809 $result = $this->db->query($sql);
2811 if (!$error && !$notrigger) {
2812 $this->context = array(
'audit' => $langs->trans(
"UserRemovedFromGroup"),
'oldgroupid' => $group);
2823 $this->db->commit();
2826 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2827 $this->db->rollback();
2831 $this->
error = $this->db->lasterror();
2832 $this->db->rollback();
2846 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2853 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
2876 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
2878 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2879 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
2894 global $conf, $langs, $menumanager;
2895 global $dolibarr_main_demo;
2897 $infologin = $params[
'infologin'] ?? 0;
2898 $option = $params[
'option'] ??
'';
2901 if (!empty($this->photo)) {
2902 $photo =
'<div class="photointooltip floatright">';
2903 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
2905 $data[
'photo'] = $photo;
2910 $data[
'opendiv'] =
'<div class="centpercent divtooltip">';
2911 $data[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
2913 if (!empty($this->login)) {
2916 if (!empty($this->job)) {
2920 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
2921 $phonelist = array();
2922 if ($this->office_phone) {
2923 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2925 if ($this->office_fax) {
2926 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2928 if ($this->user_mobile) {
2929 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
2931 $data[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
2933 if (!empty($this->admin)) {
2934 $data[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
2936 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
2937 $langs->load(
"companies");
2938 $data[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
2941 if (!empty($this->socid)) {
2942 $thirdpartystatic =
new Societe($this->db);
2943 $thirdpartystatic->fetch($this->socid);
2945 if (empty($params[
'hidethirdpartylogo'])) {
2946 $companyimg =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
2948 $company =
' ('.$langs->trans(
"Company").
': '.($companyimg ? $companyimg :
img_picto(
'',
'company')).
' '.
dol_string_nohtmltag($thirdpartystatic->name).
')';
2950 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
2951 $data[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
2952 $data[
'closediv'] =
'</div>';
2954 if ($infologin > 0) {
2955 $data[
'newlinelogin'] =
'<br>';
2956 $data[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
2959 $data[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.$conf->entity.
' (User entity '.$this->entity.
')';
2961 $data[
'authentication'] =
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
2962 $data[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
2963 $data[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
2964 $data[
'currenttheme'] =
'<br><b>'.$langs->trans(
"CurrentTheme").
':</b> '.
dol_string_nohtmltag($conf->theme);
2966 $data[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
2968 $data[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
2969 $data[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag($conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
2970 $data[
'layout'] =
'<br><b>'.$langs->trans(
"Layout").
':</b> '.
dol_string_nohtmltag($conf->browser->layout);
2971 $data[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
2972 if ($conf->browser->layout ==
'phone') {
2973 $data[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
2975 if (!empty($_SESSION[
"disablemodules"])) {
2976 $data[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(implode(
', ', explode(
',', $_SESSION[
"disablemodules"])));
2998 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
3000 global $langs, $hookmanager, $user;
3002 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
3013 'objecttype' => $this->element,
3014 'infologin' => $infologin,
3015 'option' => $option,
3016 'hidethirdpartylogo' => $hidethirdpartylogo,
3018 $classfortooltip =
'classfortooltip';
3021 $classfortooltip =
'classforajaxtooltip';
3022 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3029 if (!empty($this->socid)) {
3030 $thirdpartystatic =
new Societe($this->db);
3031 $thirdpartystatic->fetch($this->socid);
3032 if (empty($hidethirdpartylogo)) {
3033 $companylink =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3037 if ($infologin < 0) {
3041 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
3042 if ($option ==
'leave') {
3043 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
3046 if ($option !=
'nolink') {
3048 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3049 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3050 $add_save_lastsearch_values = 1;
3052 if ($add_save_lastsearch_values) {
3053 $url .=
'&save_lastsearch_values=1';
3057 $linkstart =
'<a href="'.$url.
'"';
3059 if (empty($notooltip)) {
3061 $langs->load(
"users");
3062 $label = $langs->trans(
"ShowUser");
3063 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
3065 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
3066 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
3068 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
3071 $linkstart .= $linkclose.
'>';
3075 $result .= (($option ==
'nolink') ?
'' : $linkstart);
3076 if ($withpictoimg) {
3077 $paddafterimage =
'';
3078 if (abs((
int) $withpictoimg) == 1) {
3079 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3082 if ($withpictoimg > 0) {
3083 $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>';
3086 $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>';
3090 if ($withpictoimg > -2 && $withpictoimg != 2) {
3092 $result .=
'<span class="nopadding usertext'.((!isset($this->
status) || $this->status) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
3094 if ($mode ==
'login') {
3100 $result .=
'</span>';
3103 $result .= (($option ==
'nolink') ?
'' : $linkend);
3106 $result .= $companylink;
3109 $hookmanager->initHooks(array(
'userdao'));
3110 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
3111 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3113 $result = $hookmanager->resPrint;
3115 $result .= $hookmanager->resPrint;
3130 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
3132 global $langs, $user;
3136 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3140 if ((!$user->hasRight(
'user',
'user',
'lire') && $this->id != $user->id)) {
3144 if ($option ==
'xxx') {
3145 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3149 if ($option ==
'nolink') {
3154 $result .= $linkstart;
3155 if ($withpictoimg) {
3156 $paddafterimage =
'';
3157 if (abs($withpictoimg) == 1) {
3158 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3161 if ($withpictoimg > 0) {
3162 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3165 $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>';
3169 $result .= $this->login;
3170 $result .= $linkend;
3183 return $this->
LibStatut(isset($this->statut) ? (
int) $this->statut : (int) $this->
status, $mode);
3199 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3202 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3203 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3204 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3205 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3208 $statusType =
'status5';
3209 if ($status == self::STATUS_ENABLED) {
3210 $statusType =
'status4';
3213 $label = $this->labelStatus[$status];
3214 $labelshort = $this->labelStatusShort[$status];
3217 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3218 $statusType =
'status3';
3219 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3221 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3222 $statusType =
'status2';
3223 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3226 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3241 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3243 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3244 $return .=
'<div class="info-box info-box-sm">';
3245 $return .=
'<span class="info-box-icon bg-infobox-action">';
3248 if (!empty($this->photo)) {
3250 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3259 $return .=
'</span>';
3260 $return .=
'<div class="info-box-content">';
3261 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3262 if (isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3263 $return .=
img_picto($langs->trans(
"SuperAdministratorDesc"),
'redstar',
'class="valignmiddle paddingright paddingleft"');
3264 } elseif ($this->admin) {
3265 $return .=
img_picto($langs->trans(
"AdministratorDesc"),
'star',
'class="valignmiddle paddingright paddingleft"');
3267 $return .=
'</span>';
3268 if ($selected >= 0) {
3269 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3271 if (property_exists($this,
'label')) {
3272 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3275 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->
email.
'</span>';
3277 if (method_exists($this,
'getLibStatut')) {
3278 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3280 $return .=
'</div>';
3281 $return .=
'</div>';
3282 $return .=
'</div>';
3306 } elseif ($mode == 1) {
3308 } elseif ($mode == 2) {
3324 global $conf, $langs;
3330 $keymodified =
false;
3339 'LDAP_FIELD_FULLNAME' =>
'fullname',
3340 'LDAP_FIELD_NAME' =>
'lastname',
3341 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3342 'LDAP_FIELD_LOGIN' =>
'login',
3343 'LDAP_FIELD_LOGIN_SAMBA' =>
'login',
3344 'LDAP_FIELD_PHONE' =>
'office_phone',
3345 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3346 'LDAP_FIELD_FAX' =>
'office_fax',
3347 'LDAP_FIELD_MAIL' =>
'email',
3348 'LDAP_FIELD_SID' =>
'ldap_sid',
3352 foreach ($ldapkey as $constname => $varname) {
3358 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->$varname != $this->oldcopy->$varname) {
3359 $keymodified =
true;
3364 foreach ($socialnetworks as $key => $value) {
3365 if (!empty($this->socialnetworks[$value[
'label']]) &&
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))) {
3366 $info[
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))] = $this->socialnetworks[$value[
'label']];
3381 if ($this->socid > 0) {
3382 $soc =
new Societe($this->db);
3383 $soc->fetch($this->socid);
3386 if ($soc->client == 1) {
3387 $info[
"businessCategory"] =
"Customers";
3389 if ($soc->client == 2) {
3390 $info[
"businessCategory"] =
"Prospects";
3392 if ($soc->fournisseur == 1) {
3393 $info[
"businessCategory"] =
"Suppliers";
3398 if (!empty($this->pass)) {
3411 if ($this->pass_indatabase_crypted &&
getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED')) {
3415 } elseif (!empty($this->pass_indatabase)) {
3427 $info[
"objectclass"][4] =
"phpgwContact";
3429 $info[
'uidnumber'] = $this->id;
3431 $info[
'phpgwTz'] = 0;
3432 $info[
'phpgwMailType'] =
'INTERNET';
3433 $info[
'phpgwMailHomeType'] =
'INTERNET';
3435 $info[
"phpgwContactTypeId"] =
'n';
3436 $info[
"phpgwContactCatId"] = 0;
3437 $info[
"phpgwContactAccess"] =
"public";
3445 $info[
"phpgwContactOwner"] = 1;
3448 $info[
"rfc822Mailbox"] = $this->email;
3450 if ($this->user_mobile) {
3451 $info[
"phpgwCellTelephoneNumber"] = $this->user_mobile;
3460 $groupslist = $usergroup->listGroupsForUser($this->
id);
3462 if (!empty($groupslist)) {
3463 foreach ($groupslist as $groupforuser) {
3470 $info[
getDolGlobalString(
'LDAP_FIELD_HOMEDIRECTORY')] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->login";
3486 global $user, $langs;
3492 $this->
ref =
'SPECIMEN';
3493 $this->specimen = 1;
3495 $this->lastname =
'DOLIBARR';
3496 $this->firstname =
'SPECIMEN';
3497 $this->gender =
'man';
3498 $this->note_public =
'This is a note public';
3499 $this->note_private =
'This is a note private';
3500 $this->
email =
'email@specimen.com';
3501 $this->personal_email =
'personalemail@specimen.com';
3502 $this->socialnetworks = array(
3503 'skype' =>
'skypepseudo',
3504 'twitter' =>
'twitterpseudo',
3505 'facebook' =>
'facebookpseudo',
3506 'linkedin' =>
'linkedinpseudo',
3508 $this->office_phone =
'0999999999';
3509 $this->office_fax =
'0999999998';
3510 $this->user_mobile =
'0999999997';
3511 $this->personal_mobile =
'0999999996';
3513 $this->login =
'dolibspec';
3514 $this->pass =
'dolibSpec+@123';
3517 $this->datec = $now;
3518 $this->datem = $now;
3520 $this->datelastlogin = $now;
3521 $this->iplastlogin =
'127.0.0.1';
3522 $this->datepreviouslogin = $now;
3523 $this->ippreviouslogin =
'127.0.0.1';
3540 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
3541 $sql .=
" u.tms as date_modification, u.entity";
3542 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3543 $sql .=
" WHERE u.rowid = ".((int) $id);
3545 $result = $this->db->query($sql);
3547 if ($this->db->num_rows($result)) {
3548 $obj = $this->db->fetch_object($result);
3550 $this->
id = $obj->rowid;
3552 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3553 $this->date_creation = $this->db->jdate($obj->datec);
3554 $this->date_modification = $this->db->jdate($obj->date_modification);
3555 $this->entity = $obj->entity;
3558 $this->db->free($result);
3572 $sql =
"SELECT count(mc.email) as nb";
3573 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3574 $sql .=
" WHERE mc.email = '".$this->db->escape($this->
email).
"'";
3575 $sql .=
" AND mc.statut NOT IN (-1,0)";
3577 $resql = $this->db->query($sql);
3579 $obj = $this->db->fetch_object($resql);
3582 $this->db->free($resql);
3585 $this->
error = $this->db->error();
3602 $sql =
"SELECT count(rowid) as nb";
3603 $sql .=
" FROM ".$this->db->prefix().
"user";
3604 if ($option ==
'superadmin') {
3605 $sql .=
" WHERE entity = 0";
3607 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3608 if ($limitTo ==
'active') {
3609 $sql .=
" AND statut = 1";
3613 $sql .=
" AND admin = ".(int) $admin;
3616 $resql = $this->db->query($sql);
3618 $obj = $this->db->fetch_object($resql);
3619 $nb = (int) $obj->nb;
3621 $this->db->free($resql);
3624 $this->
error = $this->db->lasterror();
3640 global $user, $conf;
3645 $this->firstname = $ldapuser->$tmpvar;
3647 $this->lastname = $ldapuser->$tmpvar;
3649 $this->login = $ldapuser->$tmpvar;
3651 $this->pass = $ldapuser->$tmpvar;
3653 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3656 $this->office_phone = $ldapuser->$tmpvar;
3658 $this->user_mobile = $ldapuser->$tmpvar;
3660 $this->office_fax = $ldapuser->$tmpvar;
3662 $this->
email = $ldapuser->$tmpvar;
3663 foreach ($socialnetworks as $key => $value) {
3665 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3668 $this->ldap_sid = $ldapuser->$tmpvar;
3671 $this->job = $ldapuser->$tmpvar;
3673 $this->note_public = $ldapuser->$tmpvar;
3675 $result = $this->
update($user);
3677 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3693 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3694 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3696 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3697 $res = $this->db->query($sql);
3700 while ($rec = $this->db->fetch_array($res)) {
3701 $user =
new User($this->db);
3702 $user->fetch($rec[
'rowid']);
3722 $this->parentof = array();
3725 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3726 $sql .=
" FROM ".$this->db->prefix().
"user";
3727 $sql .=
" WHERE fk_user <> 0";
3728 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3730 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3731 $resql = $this->db->query($sql);
3733 while ($obj = $this->db->fetch_object($resql)) {
3734 $this->parentof[$obj->id_son] = $obj->id_parent;
3760 global $conf, $user;
3761 global $hookmanager;
3764 $hookmanager->initHooks(array(
'userdao'));
3766 $this->users = array();
3772 $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";
3773 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3775 $parameters = array();
3776 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3778 $sql .= $hookmanager->resPrint;
3780 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3783 $sql .=
" AND ".$filter;
3786 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3787 $resql = $this->db->query($sql);
3790 while ($obj = $this->db->fetch_object($resql)) {
3791 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3792 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3793 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3794 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3795 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3796 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3797 $this->users[$obj->rowid][
'login'] = $obj->login;
3798 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3799 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3800 $this->users[$obj->rowid][
'email'] = $obj->email;
3801 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3802 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3803 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3805 $this->users[$obj->rowid][
'fullpath'] =
'';
3806 $this->users[$obj->rowid][
'fullname'] =
'';
3807 $this->users[$obj->rowid][
'level'] = 0;
3816 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3817 foreach ($this->users as $key => $val) {
3820 $this->
error =
'ErrorLoopInHierarchy';
3826 if ($deleteafterid) {
3828 $keyfilter1 =
'^'.$deleteafterid.
'$';
3829 $keyfilter2 =
'_'.$deleteafterid.
'$';
3830 $keyfilter3 =
'^'.$deleteafterid.
'_';
3831 $keyfilter4 =
'_'.$deleteafterid.
'_';
3832 foreach (array_keys($this->users) as $key) {
3833 $fullpath = (string) $this->users[$key][
'fullpath'];
3834 if (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
3835 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath)) {
3836 unset($this->users[$key]);
3841 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
3842 $this->users =
dol_sort_array($this->users,
'fullname',
'asc', 1, 0, 1);
3846 return $this->users;
3859 $childids = array();
3861 if (isset($this->cache_childids[$this->
id])) {
3862 $childids = $this->cache_childids[$this->id];
3867 $idtoscan = $this->id;
3869 dol_syslog(
"Build childid for id = ".$idtoscan);
3870 foreach ($this->users as $id => $val) {
3872 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
3873 $childids[$val[
'id']] = $val[
'id'];
3877 $this->cache_childids[$this->id] = $childids;
3879 if ($addcurrentuser) {
3880 $childids[$this->id] = $this->id;
3900 if (!empty($this->users[$id_user][
'fullpath'])) {
3902 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
3907 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
3908 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
3910 $cursor_user = $id_user;
3912 $useridfound = array($id_user);
3913 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
3914 if (in_array($this->parentof[$cursor_user], $useridfound)) {
3915 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
3918 $useridfound[] = $this->parentof[$cursor_user];
3919 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
3920 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
3922 $cursor_user = $this->parentof[$cursor_user];
3926 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
3958 $this->nb = array();
3960 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
3961 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3962 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
3963 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
3964 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
3965 $sql .=
" AND ug.fk_user = u.rowid";
3967 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3969 $sql .=
" AND u.statut > 0";
3972 $resql = $this->db->query($sql);
3974 while ($obj = $this->db->fetch_object($resql)) {
3975 $this->nb[
"users"] = $obj->nb;
3977 $this->db->free($resql);
3981 $this->
error = $this->db->error();
3997 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3999 global $conf, $user, $langs;
4001 $langs->load(
"user");
4008 $modele =
'bluesky';
4012 $modelpath =
"core/modules/user/doc/";
4014 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4028 $user_property =
'';
4030 if (empty($rowid)) {
4034 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
4035 $sql .=
" FROM ".$this->db->prefix().
"user";
4036 $sql .=
" WHERE rowid = ".((int) $rowid);
4038 $resql = $this->db->query($sql);
4040 $nump = $this->db->num_rows($resql);
4043 $obj = $this->db->fetch_object($resql);
4045 if ($mode ==
'email') {
4046 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
4047 } elseif ($mode ==
'mobile') {
4048 $user_property = $obj->user_mobile;
4049 } elseif ($mode ==
'name') {
4053 return $user_property;
4070 global $dolibarr_main_url_root;
4073 $encodedsecurekey =
dol_hash($conf->file->instance_unique_id.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
4074 if (isModEnabled(
'multicompany')) {
4075 $entity_qr =
'&entity='.((int) $conf->entity);
4080 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
4081 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
4084 if ($typeofurl ==
'internal') {
4085 $urlwithroot = DOL_URL_ROOT;
4088 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
4104 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $entityfilter =
false)
4106 global $conf, $user;
4108 $sql =
"SELECT t.rowid";
4109 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
4111 if ($entityfilter) {
4113 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
4114 $sql .=
" WHERE t.entity IS NOT NULL";
4116 $sql .=
",".$this->db->prefix().
"usergroup_user as ug";
4117 $sql .=
" WHERE ((ug.fk_user = t.rowid";
4118 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
4119 $sql .=
" OR t.entity = 0)";
4122 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
4125 $sql .=
" WHERE 1 = 1";
4131 if ($errormessage) {
4132 $this->errors[] = $errormessage;
4133 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
4137 $sql .= $this->db->order($sortfield, $sortorder);
4139 $sql .= $this->db->plimit($limit + 1, $offset);
4144 $resql = $this->db->query($sql);
4146 $this->users = array();
4147 $num = $this->db->num_rows($resql);
4149 while ($obj = $this->db->fetch_object($resql)) {
4150 $line =
new self($this->db);
4151 $result = $line->fetch($obj->rowid);
4152 if ($result > 0 && !empty($line->id)) {
4153 $this->users[$obj->rowid] = clone $line;
4156 $this->db->free($resql);
4160 $this->errors[] = $this->db->lasterror();
4172 private $findUserIdByEmailCache;
4186 if (isset($this->findUserIdByEmailCache[$email])) {
4187 return $this->findUserIdByEmailCache[$email];
4190 $this->findUserIdByEmailCache[$email] = -1;
4192 $sql =
'SELECT rowid';
4193 $sql .=
' FROM '.$this->db->prefix().
'user';
4194 if (
getDolGlobalString(
'AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR')) {
4195 $sql .=
" WHERE email LIKE '%".$this->db->escape($this->db->escapeforlike($email)).
"%'";
4197 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4201 $resql = $this->db->query($sql);
4206 $obj = $this->db->fetch_object($resql);
4211 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4213 return $this->findUserIdByEmailCache[$email];
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Class to manage members of a foundation.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
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.
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.
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.
$clicktodial_url
@string clicktodial url
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)
Return array of data to show into tooltips.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
getArrayOfSocialNetworks()
Get array of social network dictionary.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
getUserRemoteIP()
Return the IP of remote user.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dolEncrypt($chain, $key='', $ciphering='AES-256-CTR', $forceseed='')
Encode a string with a symmetric encryption.
dol_verifyHash($chain, $hash, $type='0')
Compute a hash and compare it to the given one For backward compatibility reasons,...
dolGetLdapPasswordHash($password, $type='md5')
Returns a specific ldap hash of a password.
dolDecrypt($chain, $key='')
Decode a string with a symmetric encryption.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.