38require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/commonpeople.class.php';
54 public $element =
'user';
59 public $table_element =
'user';
64 public $fk_element =
'fk_user';
70 public $ismultientitymanaged = 1;
75 public $isextrafieldmanaged = 1;
80 public $picto =
'user';
106 public $civility_code;
128 public $email_oauth2;
133 public $personal_email;
138 public $socialnetworks;
153 public $office_phone;
168 public $personal_mobile;
198 public $pass_crypted;
203 public $pass_indatabase;
208 public $pass_indatabase_crypted;
252 public $fk_user_expense_validator;
257 public $fk_user_holiday_validator;
267 public $clicktodial_login;
272 public $clicktodial_password;
277 public $clicktodial_poste;
282 public $clicktodial_loaded;
285 public $datelastlogin;
286 public $datepreviouslogin;
287 public $flagdelsessionsbefore;
289 public $ippreviouslogin;
290 public $datestartvalidity;
291 public $dateendvalidity;
307 public $all_permissions_are_loaded;
317 public $user_group_list;
322 private $_tab_loaded = array();
329 public $default_values;
331 public $lastsearch_values_tmp;
332 public $lastsearch_values;
334 public $users = array();
336 private $cache_childids;
338 public $accountancy_code;
352 public $dateemployment;
353 public $dateemploymentend;
355 public $default_c_exp_tax_cat;
360 public $ref_employee;
365 public $national_registration_number;
367 public $default_range;
372 public $fk_warehouse;
377 public $egroupware_id;
383 public $usergroup_entity;
385 public $fields = array(
386 'rowid'=>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'index'=>1,
'position'=>1,
'comment'=>
'Id'),
387 'lastname'=>array(
'type'=>
'varchar(50)',
'label'=>
'LastName',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>20,
'searchall'=>1),
388 'firstname'=>array(
'type'=>
'varchar(50)',
'label'=>
'FirstName',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>10,
'searchall'=>1),
389 'ref_employee'=>array(
'type'=>
'varchar(50)',
'label'=>
'RefEmployee',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>30,
'searchall'=>1),
390 'national_registration_number'=>array(
'type'=>
'varchar(50)',
'label'=>
'NationalRegistrationNumber',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>40,
'searchall'=>1)
394 const STATUS_DISABLED = 0;
395 const STATUS_ENABLED = 1;
409 $this->clicktodial_loaded = 0;
412 $this->all_permissions_are_loaded = 0;
413 $this->nb_rights = 0;
421 $this->rights->user =
new stdClass();
422 $this->rights->user->user =
new stdClass();
423 $this->rights->user->self =
new stdClass();
424 $this->rights->user->user_advance =
new stdClass();
425 $this->rights->user->self_advance =
new stdClass();
426 $this->rights->user->group_advance =
new stdClass();
443 public function fetch($id = 0, $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'', $fk_socpeople = 0, $use_email_oauth2 = 0)
448 $login = trim($login);
451 $sql =
"SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.civility as civility_code, u.birth, u.job,";
452 $sql .=
" u.email, u.email_oauth2, u.personal_email,";
453 $sql .=
" u.socialnetworks,";
454 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
455 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
456 $sql .=
" u.admin, u.login, u.note_private, u.note_public,";
457 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.api_key,";
458 $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,";
459 $sql .=
" u.statut as status, u.lang, u.entity,";
460 $sql .=
" u.datec as datec,";
461 $sql .=
" u.tms as datem,";
462 $sql .=
" u.datelastlogin as datel,";
463 $sql .=
" u.datepreviouslogin as datep,";
464 $sql .=
" u.flagdelsessionsbefore,";
465 $sql .=
" u.iplastlogin,";
466 $sql .=
" u.ippreviouslogin,";
467 $sql .=
" u.datelastpassvalidation,";
468 $sql .=
" u.datestartvalidity,";
469 $sql .=
" u.dateendvalidity,";
470 $sql .=
" u.photo as photo,";
471 $sql .=
" u.openid as openid,";
472 $sql .=
" u.accountancy_code,";
475 $sql .=
" u.salary,";
476 $sql .=
" u.salaryextra,";
477 $sql .=
" u.weeklyhours,";
479 $sql .=
" u.dateemployment, u.dateemploymentend,";
480 $sql .=
" u.fk_warehouse,";
481 $sql .=
" u.ref_ext,";
482 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
483 $sql .=
" u.national_registration_number,";
484 $sql .=
" u.ref_employee,";
485 $sql .=
" c.code as country_code, c.label as country,";
486 $sql .=
" d.code_departement as state_code, d.nom as state";
487 $sql .=
" FROM ".$this->db->prefix().
"user as u";
488 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as c ON u.fk_country = c.rowid";
489 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_departements as d ON u.fk_state = d.rowid";
492 if ((!isModEnabled(
'multicompany') || !
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) && (!empty($user->entity))) {
493 $sql .=
" WHERE u.entity IN (0, ".((int) $conf->entity).
")";
495 $sql .=
" WHERE u.entity IS NOT NULL";
499 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
500 $sql .=
" WHERE u.entity IS NOT NULL";
502 $sql .=
" WHERE u.entity IN (0, ".((int) (($entity !=
'' && $entity >= 0) ? $entity : $conf->entity)).
")";
508 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->db->escape($login).
"')";
510 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
512 $sql .=
" AND (u.email = '".$this->db->escape($email).
"'";
513 if ($use_email_oauth2) {
514 $sql .=
" OR u.email_oauth2 = '".$this->db->escape($email).
"'";
517 } elseif ($fk_socpeople > 0) {
518 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
520 $sql .=
" AND u.rowid = ".((int) $id);
522 $sql .=
" ORDER BY u.entity ASC";
526 $sql .=
' '.$this->db->plimit(1);
529 $resql = $this->db->query($sql);
531 $num = $this->db->num_rows($resql);
533 $this->
error =
"USERDUPLICATEFOUND";
534 dol_syslog(get_class($this).
"::fetch more than 1 user found", LOG_WARNING);
536 $this->db->free($resql);
540 $obj = $this->db->fetch_object($resql);
542 $this->
id = $obj->rowid;
543 $this->
ref = $obj->rowid;
545 $this->ref_ext = $obj->ref_ext;
547 $this->ldap_sid = $obj->ldap_sid;
548 $this->civility_code = $obj->civility_code;
549 $this->lastname = $obj->lastname;
550 $this->firstname = $obj->firstname;
551 $this->ref_employee = $obj->ref_employee;
552 $this->national_registration_number = $obj->national_registration_number;
554 $this->employee = $obj->employee;
556 $this->login = $obj->login;
557 $this->gender = $obj->gender;
558 $this->birth = $this->db->jdate($obj->birth);
559 $this->pass_indatabase = $obj->pass;
560 $this->pass_indatabase_crypted = $obj->pass_crypted;
561 $this->pass = $obj->pass;
562 $this->pass_temp = $obj->pass_temp;
565 $this->address = $obj->address;
566 $this->zip = $obj->zip;
567 $this->town = $obj->town;
569 $this->country_id = $obj->country_id;
570 $this->country_code = $obj->country_id ? $obj->country_code :
'';
573 $this->state_id = $obj->state_id;
574 $this->state_code = $obj->state_code;
575 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
577 $this->office_phone = $obj->office_phone;
578 $this->office_fax = $obj->office_fax;
579 $this->user_mobile = $obj->user_mobile;
580 $this->personal_mobile = $obj->personal_mobile;
581 $this->email = $obj->email;
582 $this->email_oauth2 = $obj->email_oauth2;
583 $this->personal_email = $obj->personal_email;
584 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
585 $this->job = $obj->job;
586 $this->signature = $obj->signature;
587 $this->admin = $obj->admin;
588 $this->note_public = $obj->note_public;
589 $this->note_private = $obj->note_private;
590 $this->note = $obj->note_private;
592 $this->
statut = $obj->status;
593 $this->
status = $obj->status;
595 $this->photo = $obj->photo;
596 $this->openid = $obj->openid;
597 $this->lang = $obj->lang;
598 $this->entity = $obj->entity;
599 $this->accountancy_code = $obj->accountancy_code;
600 $this->thm = $obj->thm;
601 $this->tjm = $obj->tjm;
602 $this->salary = $obj->salary;
603 $this->salaryextra = $obj->salaryextra;
604 $this->weeklyhours = $obj->weeklyhours;
605 $this->color = $obj->color;
606 $this->dateemployment = $this->db->jdate($obj->dateemployment);
607 $this->dateemploymentend = $this->db->jdate($obj->dateemploymentend);
609 $this->datec = $this->db->jdate($obj->datec);
610 $this->datem = $this->db->jdate($obj->datem);
611 $this->datelastlogin = $this->db->jdate($obj->datel);
612 $this->datepreviouslogin = $this->db->jdate($obj->datep);
613 $this->flagdelsessionsbefore = $this->db->jdate($obj->flagdelsessionsbefore,
'gmt');
614 $this->iplastlogin = $obj->iplastlogin;
615 $this->ippreviouslogin = $obj->ippreviouslogin;
616 $this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
617 $this->dateendvalidity = $this->db->jdate($obj->dateendvalidity);
619 $this->socid = $obj->fk_soc;
620 $this->contact_id = $obj->fk_socpeople;
621 $this->fk_member = $obj->fk_member;
622 $this->fk_user = $obj->fk_user;
623 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
624 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
626 $this->default_range = $obj->default_range;
627 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
628 $this->fk_warehouse = $obj->fk_warehouse;
632 if (!isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
640 $this->db->free($resql);
642 $this->
error =
"USERNOTFOUND";
643 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
645 $this->db->free($resql);
649 $this->
error = $this->db->lasterror();
654 if ($loadpersonalconf) {
660 $this->
error = $this->db->lasterror();
679 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
680 $sql .=
" WHERE fk_user = ".((int) $this->
id);
681 $sql .=
" AND entity = ".((int) $conf->entity);
683 $resql = $this->db->query($sql);
685 $num = $this->db->num_rows($resql);
688 $obj = $this->db->fetch_object($resql);
689 $p = (!empty($obj->param) ? $obj->param :
'');
691 $this->
conf->$p = $obj->value;
695 $this->db->free($resql);
699 $this->
error = $this->db->lasterror();
716 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
719 $result = $defaultValues->fetchAll(
'',
'', 0, 0, array(
't.user_id'=>array(0, $this->
id),
'entity'=>array((isset($this->entity) ? $this->entity : $conf->entity), $conf->entity)));
721 if (!is_array($result) && $result < 0) {
725 } elseif (count($result) > 0) {
726 foreach ($result as $defval) {
727 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
728 $pagewithoutquerystring = $defval->page;
731 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
732 $pagewithoutquerystring = $reg[1];
733 $pagequeries = $reg[2];
735 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
739 if (!empty($this->default_values)) {
740 foreach ($this->default_values as $a => $b) {
741 foreach ($b as $c => $d) {
742 krsort($this->default_values[$a][$c]);
761 public function hasRight($module, $permlevel1, $permlevel2 =
'')
764 $moduletomoduletouse = array(
765 'compta' =>
'comptabilite',
766 'contract' =>
'contrat',
767 'member' =>
'adherent',
769 'order' =>
'commande',
770 'produit' =>
'product',
771 'productlot' =>
'produit',
772 'project' =>
'projet',
773 'propale' =>
'propal',
774 'shipping' =>
'expedition',
775 'task' =>
'task@projet',
776 'fichinter' =>
'ficheinter',
777 'inventory' =>
'stock',
778 'invoice' =>
'facture',
779 'invoice_supplier' =>
'fournisseur',
780 'order_supplier' =>
'fournisseur',
781 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
782 'skill@hrm' =>
'all@hrm',
783 'job@hrm' =>
'all@hrm',
784 'position@hrm' =>
'all@hrm',
785 'facturerec' =>
'facture',
786 'margins' =>
'margin',
789 if (!empty($moduletomoduletouse[$module])) {
790 $module = $moduletomoduletouse[$module];
793 $moduleRightsMapping = array(
794 'product' =>
'produit',
795 'margin' =>
'margins',
796 'comptabilite' =>
'compta'
799 $rightsPath = $module;
800 if (!empty($moduleRightsMapping[$rightsPath])) {
801 $rightsPath = $moduleRightsMapping[$rightsPath];
805 $tmp = explode(
'@', $rightsPath, 2);
806 if (!empty($tmp[1])) {
807 if (strpos($module,
'@') !==
false) {
810 $rightsPath = $tmp[1];
811 $permlevel2 = $permlevel1;
812 $permlevel1 = $tmp[0];
822 if (!isModEnabled($module)) {
827 if ($permlevel1 ==
'propale') {
828 $permlevel1 =
'propal';
830 if ($permlevel1 ==
'member') {
831 $permlevel1 =
'adherent';
833 if ($permlevel1 ==
'recruitmentcandidature') {
834 $permlevel1 =
'recruitmentjobposition';
839 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
844 if (!empty($this->rights->$rightsPath->$permlevel1)) {
845 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
846 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
850 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
851 return $this->rights->$rightsPath->$permlevel1->lire;
853 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
854 return $this->rights->$rightsPath->$permlevel1->creer;
856 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
857 return $this->rights->$rightsPath->$permlevel1->create;
859 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
860 return $this->rights->$rightsPath->$permlevel1->supprimer;
864 if (!empty($this->rights->$rightsPath->$permlevel1)) {
865 return $this->rights->$rightsPath->$permlevel1;
869 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
870 return $this->rights->$rightsPath->lire;
872 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
873 return $this->rights->$rightsPath->creer;
875 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
876 return $this->rights->$rightsPath->create;
878 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
879 return $this->rights->$rightsPath->supprimer;
897 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
899 global $conf, $user, $langs;
901 $entity = (empty($entity) ? $conf->entity : $entity);
903 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
905 if (empty($this->
id)) {
906 $this->
error =
'Try to call addrights on an object user with an empty id';
916 $module = $perms = $subperms =
'';
919 $sql =
"SELECT module, perms, subperms";
920 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
921 $sql .=
" WHERE id = ".((int) $rid);
922 $sql .=
" AND entity = ".((int) $entity);
924 $result = $this->db->query($sql);
926 $obj = $this->db->fetch_object($result);
929 $module = $obj->module;
930 $perms = $obj->perms;
931 $subperms = $obj->subperms;
939 $whereforadd =
"id=".((int) $rid);
941 if (!empty($subperms)) {
942 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
943 } elseif (!empty($perms)) {
944 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
950 if (!empty($allmodule)) {
951 if ($allmodule ==
'allmodules') {
952 $whereforadd =
'allmodules';
954 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
955 if (!empty($allperms)) {
956 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
964 if (!empty($whereforadd)) {
967 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
968 $sql .=
" WHERE entity = ".((int) $entity);
969 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
970 $sql .=
" AND (".$whereforadd.
")";
973 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
974 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
976 $sqldelete .=
") AND entity = ".((int) $entity);
977 if (!$this->db->query($sqldelete)) {
982 $resql = $this->db->query($sql);
984 $num = $this->db->num_rows($resql);
987 $obj = $this->db->fetch_object($resql);
992 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
993 if (!$this->db->query($sql)) {
1007 if (!$error && !$notrigger) {
1008 $langs->load(
"other");
1009 $this->context = array(
'audit'=>$langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
1020 $this->db->rollback();
1023 $this->db->commit();
1040 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1042 global $conf, $user, $langs;
1046 $entity = (!empty($entity) ? $entity : $conf->entity);
1051 $module = $perms = $subperms =
'';
1055 $sql =
"SELECT module, perms, subperms";
1056 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1057 $sql .=
" WHERE id = '".$this->db->escape($rid).
"'";
1058 $sql .=
" AND entity = ".((int) $entity);
1060 $result = $this->db->query($sql);
1062 $obj = $this->db->fetch_object($result);
1065 $module = $obj->module;
1066 $perms = $obj->perms;
1067 $subperms = $obj->subperms;
1075 $wherefordel =
"id=".((int) $rid);
1077 if ($subperms ==
'lire' || $subperms ==
'read') {
1078 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1080 if ($perms ==
'lire' || $perms ==
'read') {
1081 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1086 if (!empty($allmodule)) {
1087 if ($allmodule ==
'allmodules') {
1088 $wherefordel =
'allmodules';
1090 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1091 if (!empty($allperms)) {
1092 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1099 if (!empty($wherefordel)) {
1102 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1103 $sql .=
" WHERE entity = ".((int) $entity);
1104 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1105 $sql .=
" AND (".$wherefordel.
")";
1109 if ($this->admin == 1) {
1110 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1111 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1112 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1113 $sql .=
" AND id NOT IN (358)";
1116 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1117 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1120 $sqldelete .=
" AND entity = ".((int) $entity);
1122 $resql = $this->db->query($sqldelete);
1129 if (!$error && !$notrigger) {
1130 $langs->load(
"other");
1131 $this->context = array(
'audit'=>$langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1142 $this->db->rollback();
1145 $this->db->commit();
1159 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1160 $this->rights =
null;
1161 $this->nb_rights = 0;
1162 $this->all_permissions_are_loaded = 0;
1163 $this->_tab_loaded = array();
1175 public function getrights($moduletag =
'', $forcereload = 0)
1179 if (empty($forcereload)) {
1180 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1185 if (!empty($this->all_permissions_are_loaded)) {
1192 if (!isset($this->rights) || !is_object($this->rights)) {
1195 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1196 $this->rights->user =
new stdClass();
1202 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1203 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1204 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1205 $sql .=
" WHERE r.id = ur.fk_id";
1208 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') ?
"1," :
"").$conf->entity.
")";
1212 $sql .=
" AND r.entity = ".((int) $conf->entity).
" AND ur.entity = ".((int) $conf->entity);
1214 $sql .=
" AND ur.fk_user= ".((int) $this->
id);
1215 $sql .=
" AND r.perms IS NOT NULL";
1217 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1220 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1223 $resql = $this->db->query($sql);
1225 $num = $this->db->num_rows($resql);
1228 $obj = $this->db->fetch_object($resql);
1231 $module = $obj->module;
1232 $perms = $obj->perms;
1233 $subperms = $obj->subperms;
1235 if (!empty($perms)) {
1236 if (!empty($module)) {
1237 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1238 $this->rights->$module =
new stdClass();
1240 if (!empty($subperms)) {
1241 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1242 $this->rights->$module->$perms =
new stdClass();
1244 if (empty($this->rights->$module->$perms->$subperms)) {
1247 $this->rights->$module->$perms->$subperms = 1;
1249 if (empty($this->rights->$module->$perms)) {
1252 $this->rights->$module->$perms = 1;
1259 $this->db->free($resql);
1263 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1264 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1265 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1266 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1267 $sql .=
" WHERE r.id = gr.fk_id";
1270 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1271 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1273 $sql .=
" AND r.entity = ".((int) $conf->entity);
1276 $sql .=
" AND gr.entity = ".((int) $conf->entity);
1280 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1281 $sql .=
" AND r.entity = ".((int) $conf->entity);
1284 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1285 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1286 $sql .=
" AND r.perms IS NOT NULL";
1288 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1291 $resql = $this->db->query($sql);
1293 $num = $this->db->num_rows($resql);
1296 $obj = $this->db->fetch_object($resql);
1299 $module = $obj->module;
1300 $perms = $obj->perms;
1301 $subperms = $obj->subperms;
1303 if (!empty($perms)) {
1304 if (!empty($module)) {
1305 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1306 $this->rights->$module =
new stdClass();
1308 if (!empty($subperms)) {
1309 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1310 $this->rights->$module->$perms =
new stdClass();
1312 if (empty($this->rights->$module->$perms->$subperms)) {
1315 $this->rights->$module->$perms->$subperms = 1;
1317 if (empty($this->rights->$module->$perms)) {
1321 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1322 $this->rights->$module->$perms = 1;
1330 $this->db->free($resql);
1334 if (!empty($this->admin)) {
1335 if (empty($this->rights->user->user)) {
1336 $this->rights->user->user =
new stdClass();
1338 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1339 foreach ($listofpermtotest as $permtotest) {
1340 if (empty($this->rights->user->user->$permtotest)) {
1341 $this->rights->user->user->$permtotest = 1;
1345 if (empty($this->rights->user->self)) {
1346 $this->rights->user->self =
new stdClass();
1348 $listofpermtotest = array(
'creer',
'password');
1349 foreach ($listofpermtotest as $permtotest) {
1350 if (empty($this->rights->user->self->$permtotest)) {
1351 $this->rights->user->self->$permtotest = 1;
1357 if (empty($this->rights->user->user_advance)) {
1358 $this->rights->user->user_advance =
new stdClass();
1360 $listofpermtotest = array(
'readperms',
'write');
1361 foreach ($listofpermtotest as $permtotest) {
1362 if (empty($this->rights->user->user_advance->$permtotest)) {
1363 $this->rights->user->user_advance->$permtotest = 1;
1367 if (empty($this->rights->user->self_advance)) {
1368 $this->rights->user->self_advance =
new stdClass();
1370 $listofpermtotest = array(
'readperms',
'writeperms');
1371 foreach ($listofpermtotest as $permtotest) {
1372 if (empty($this->rights->user->self_advance->$permtotest)) {
1373 $this->rights->user->self_advance->$permtotest = 1;
1377 if (empty($this->rights->user->group_advance)) {
1378 $this->rights->user->group_advance =
new stdClass();
1380 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1381 foreach ($listofpermtotest as $permtotest) {
1382 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1383 $this->rights->user->group_advance->$permtotest = 1;
1391 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1392 $this->rights->propal = $this->rights->propale;
1394 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1395 $this->rights->propale = $this->rights->propal;
1401 $this->all_permissions_are_loaded = 1;
1404 $this->_tab_loaded[$moduletag] = 1;
1416 global $conf, $langs, $user;
1421 if (isset($this->
statut)) {
1422 if ($this->
statut == $status) {
1425 } elseif (isset($this->
status) && $this->
status == $status) {
1432 $sql =
"UPDATE ".$this->db->prefix().
"user";
1433 $sql .=
" SET statut = ".((int) $status);
1434 $sql .=
" WHERE rowid = ".((int) $this->
id);
1435 $result = $this->db->query($sql);
1437 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1440 $this->context[
'actionmsg'] =
'User '.$this->login.
' disabled';
1442 $this->context[
'actionmsg'] =
'User '.$this->login.
' enabled';
1445 $result = $this->
call_trigger(
'USER_ENABLEDISABLE', $user);
1453 $this->db->rollback();
1458 $this->db->commit();
1475 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1476 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1487 global $conf, $langs;
1493 $this->
fetch($this->
id);
1495 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1498 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1500 if (!$error && !$this->db->query($sql)) {
1502 $this->
error = $this->db->lasterror();
1506 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1507 if (!$error && !$this->db->query($sql)) {
1509 $this->
error = $this->db->lasterror();
1513 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1514 if (!$error && !$this->db->query($sql)) {
1516 $this->
error = $this->db->lasterror();
1520 if ($this->contact_id > 0) {
1521 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1522 if (!$error && !$this->db->query($sql)) {
1524 $this->
error = $this->db->lasterror();
1533 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1539 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1540 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1541 if (!$this->db->query($sql)) {
1543 $this->
error = $this->db->lasterror();
1552 $this->db->rollback();
1557 $this->db->commit();
1560 $this->db->rollback();
1572 public function create($user, $notrigger = 0)
1574 global $conf, $langs;
1580 $this->civility_code = trim((
string) $this->civility_code);
1581 $this->login = trim((
string) $this->login);
1582 if (!isset($this->entity)) {
1583 $this->entity = $conf->entity;
1586 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1588 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1592 $langs->load(
"errors");
1593 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1596 if (empty($this->login)) {
1597 $langs->load(
"errors");
1598 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1600 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1601 $langs->load(
"errors");
1602 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1613 $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).
"'";
1614 $resqltochecklogin = $this->db->query($sqltochecklogin);
1615 if ($resqltochecklogin) {
1616 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1617 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1618 $langs->load(
"errors");
1619 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1621 $this->db->rollback();
1624 $this->db->free($resqltochecklogin);
1627 if (!empty($this->email)) {
1628 $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).
"'";
1629 $resqltochecklogin = $this->db->query($sqltochecklogin);
1630 if ($resqltochecklogin) {
1631 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1632 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1633 $langs->load(
"errors");
1634 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
1636 $this->db->rollback();
1639 $this->db->free($resqltochecklogin);
1644 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, entity)";
1645 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->db->escape($this->login).
"', '".$this->db->escape($this->ldap_sid).
"', ".((int) $this->entity).
")";
1646 $result = $this->db->query($sql);
1648 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1650 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1654 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1655 $this->db->rollback();
1660 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1661 $langs->load(
"stocks");
1663 $entrepot =
new Entrepot($this->db);
1664 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1665 $entrepot->libelle = $entrepot->label;
1666 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1667 $entrepot->statut = 1;
1668 $entrepot->country_id = $mysoc->country_id;
1670 $warehouseid = $entrepot->create($user);
1672 $this->fk_warehouse = $warehouseid;
1676 $result = $this->
update($user, 1, 1);
1678 $this->db->rollback();
1692 $this->db->commit();
1697 $this->db->rollback();
1701 $this->
error = $this->db->lasterror();
1702 $this->db->rollback();
1720 global $conf, $user, $langs;
1726 $this->civility_code = $contact->civility_code;
1727 $this->lastname = $contact->lastname;
1728 $this->firstname = $contact->firstname;
1730 $this->email = $contact->email;
1731 $this->socialnetworks = $contact->socialnetworks;
1732 $this->office_phone = $contact->phone_pro;
1733 $this->office_fax = $contact->fax;
1734 $this->user_mobile = $contact->phone_mobile;
1735 $this->address = $contact->address;
1736 $this->zip = $contact->zip;
1737 $this->town = $contact->town;
1739 $this->state_id = $contact->state_id;
1740 $this->country_id = $contact->country_id;
1741 $this->employee = 0;
1743 if (empty($login)) {
1744 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1745 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1747 $this->login = $login;
1752 $result = $this->
create($user, 1);
1754 $sql =
"UPDATE ".$this->db->prefix().
"user";
1755 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1756 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1757 if ($contact->socid > 0) {
1758 $sql .=
", fk_soc=".((int) $contact->socid);
1760 $sql .=
" WHERE rowid=".((int) $this->
id);
1762 $resql = $this->db->query($sql);
1764 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1766 $this->context[
'createfromcontact'] =
'createfromcontact';
1772 $this->db->rollback();
1777 $this->db->commit();
1780 $this->
error = $this->db->error();
1782 $this->db->rollback();
1787 dol_syslog(get_class($this).
"::create_from_contact - 0");
1789 $this->db->rollback();
1806 global $conf, $user, $langs;
1810 $this->civility_code = $member->civility_id;
1811 $this->lastname = $member->lastname;
1812 $this->firstname = $member->firstname;
1813 $this->gender = $member->gender;
1814 $this->email = $member->email;
1815 $this->fk_member = $member->id;
1816 $this->address = $member->address;
1817 $this->zip = $member->zip;
1818 $this->town = $member->town;
1820 $this->state_id = $member->state_id;
1821 $this->country_id = $member->country_id;
1822 $this->socialnetworks = $member->socialnetworks;
1824 $this->pass = $member->pass;
1825 $this->pass_crypted = $member->pass_indatabase_crypted;
1827 if (empty($login)) {
1828 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1831 $this->login = $login;
1836 $result = $this->
create($user);
1838 if (!empty($this->pass)) {
1839 $newpass = $this->
setPassword($user, $this->pass);
1840 if (is_int($newpass) && $newpass < 0) {
1843 } elseif (!empty($this->pass_crypted)) {
1844 $sql =
"UPDATE ".$this->db->prefix().
"user";
1845 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
1846 $sql .=
" WHERE rowid=".((int) $this->
id);
1848 $resql = $this->db->query($sql);
1854 if ($result > 0 && $member->socid) {
1855 $sql =
"UPDATE ".$this->db->prefix().
"user";
1856 $sql .=
" SET fk_soc=".((int) $member->socid);
1857 $sql .=
" WHERE rowid=".((int) $this->
id);
1859 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
1860 $resql = $this->db->query($sql);
1862 $this->db->commit();
1865 $this->
error = $this->db->lasterror();
1867 $this->db->rollback();
1874 $this->db->commit();
1878 $this->db->rollback();
1896 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
1897 $sql .=
" WHERE bydefault = 1";
1898 $sql .=
" AND entity = ".((int) $conf->entity);
1900 $resql = $this->db->query($sql);
1902 $num = $this->db->num_rows($resql);
1905 $row = $this->db->fetch_row($resql);
1909 $this->db->free($resql);
1913 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
1914 $result = $this->db->query($sql);
1916 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
1917 $result = $this->db->query($sql);
1937 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
1939 global $conf, $langs;
1941 $nbrowsaffected = 0;
1944 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
1947 $this->civility_code = trim((
string) $this->civility_code);
1948 $this->lastname = trim((
string) $this->lastname);
1949 $this->firstname = trim((
string) $this->firstname);
1950 $this->ref_employee = trim((
string) $this->ref_employee);
1951 $this->national_registration_number = trim((
string) $this->national_registration_number);
1952 $this->employee = ($this->employee > 0 ? $this->employee : 0);
1953 $this->login = trim((
string) $this->login);
1954 $this->gender = trim((
string) $this->gender);
1956 $this->pass = trim((
string) $this->pass);
1957 $this->api_key = trim((
string) $this->api_key);
1958 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
1959 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
1961 $this->address = trim((
string) $this->address);
1962 $this->zip = trim((
string) $this->zip);
1963 $this->town = trim((
string) $this->town);
1965 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
1966 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
1967 $this->office_phone = trim((
string) $this->office_phone);
1968 $this->office_fax = trim((
string) $this->office_fax);
1969 $this->user_mobile = trim((
string) $this->user_mobile);
1970 $this->personal_mobile = trim((
string) $this->personal_mobile);
1971 $this->email = trim((
string) $this->email);
1972 $this->personal_email = trim((
string) $this->personal_email);
1974 $this->job = trim((
string) $this->job);
1975 $this->signature = trim((
string) $this->signature);
1976 $this->note_public = trim((
string) $this->note_public);
1977 $this->note_private = trim((
string) $this->note_private);
1978 $this->openid = trim((
string) $this->openid);
1979 $this->admin = ($this->admin > 0 ? $this->admin : 0);
1981 $this->accountancy_code = trim((
string) $this->accountancy_code);
1982 $this->color = trim((
string) $this->color);
1983 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
1984 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
1986 $this->birth = empty($this->birth) ?
'' : $this->birth;
1987 $this->fk_warehouse = (int) $this->fk_warehouse;
1992 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1995 $langs->load(
"errors");
1996 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1999 if (empty($this->login)) {
2000 $langs->load(
"errors");
2001 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
2003 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
2004 $langs->load(
"errors");
2005 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
2012 if (!empty($this->oldcopy) && $this->oldcopy->login != $this->login) {
2013 $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).
"'";
2014 $resqltochecklogin = $this->db->query($sqltochecklogin);
2015 if ($resqltochecklogin) {
2016 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2017 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2018 $langs->load(
"errors");
2019 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
2021 $this->db->rollback();
2026 if (!empty($this->oldcopy) && !empty($this->email) && $this->oldcopy->email != $this->email) {
2027 $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).
"'";
2028 $resqltochecklogin = $this->db->query($sqltochecklogin);
2029 if ($resqltochecklogin) {
2030 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2031 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2032 $langs->load(
"errors");
2033 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
2035 $this->db->rollback();
2042 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2043 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
2044 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
2045 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
2046 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
2047 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
2048 $sql .=
", employee = ".(int) $this->employee;
2049 $sql .=
", login = '".$this->db->escape($this->login).
"'";
2050 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
2051 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
2052 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
2053 if (!empty($user->admin)) {
2054 $sql .=
", admin = ".(int) $this->admin;
2056 $sql .=
", address = '".$this->db->escape($this->address).
"'";
2057 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
2058 $sql .=
", town = '".$this->db->escape($this->town).
"'";
2059 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".$this->db->escape($this->state_id).
"'" :
"null");
2060 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".$this->db->escape($this->country_id).
"'" :
"null");
2061 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
2062 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
2063 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
2064 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
2065 $sql .=
", email = '".$this->db->escape($this->email).
"'";
2066 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
2067 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
2068 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2069 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2070 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2071 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2072 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2073 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2074 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2075 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2076 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2077 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2078 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2079 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2080 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".$this->db->escape($this->fk_user).
"'" :
"null");
2081 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".$this->db->escape($this->fk_user_expense_validator).
"'" :
"null");
2082 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".$this->db->escape($this->fk_user_holiday_validator).
"'" :
"null");
2083 if (isset($this->thm) || $this->thm !=
'') {
2084 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2086 if (isset($this->tjm) || $this->tjm !=
'') {
2087 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2089 if (isset($this->salary) || $this->salary !=
'') {
2090 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2092 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2093 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2095 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2096 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2097 $sql .=
", entity = ".((int) $this->entity);
2099 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2100 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2101 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2102 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2103 $sql .=
" WHERE rowid = ".((int) $this->
id);
2105 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2106 $resql = $this->db->query($sql);
2108 $nbrowsaffected += $this->db->affected_rows($resql);
2111 if (!empty($this->pass)) {
2112 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2114 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2115 if (is_int($result) && $result < 0) {
2122 if ($this->fk_member > 0) {
2123 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2124 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2125 $resql = $this->db->query($sql);
2127 $this->
error = $this->db->error();
2128 $this->db->rollback();
2133 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2134 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2135 $resql = $this->db->query($sql);
2137 $this->
error = $this->db->error();
2138 $this->db->rollback();
2142 if ($nbrowsaffected) {
2143 if ($this->fk_member > 0 && !$nosyncmember) {
2144 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2146 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2151 $result = $adh->fetch($this->fk_member);
2154 $adh->civility_code = $this->civility_code;
2155 $adh->firstname = $this->firstname;
2156 $adh->lastname = $this->lastname;
2157 $adh->login = $this->login;
2158 $adh->gender = $this->gender;
2159 $adh->birth = $this->birth;
2161 $adh->pass = $this->pass;
2163 $adh->address = $this->address;
2164 $adh->town = $this->town;
2165 $adh->zip = $this->zip;
2166 $adh->state_id = $this->state_id;
2167 $adh->country_id = $this->country_id;
2169 $adh->email = $this->email;
2171 $adh->socialnetworks = $this->socialnetworks;
2173 $adh->phone = $this->office_phone;
2174 $adh->phone_mobile = $this->user_mobile;
2176 $adh->default_lang = $this->lang;
2178 $adh->user_id = $this->id;
2179 $adh->user_login = $this->login;
2181 $result = $adh->update($user, 0, 1, 0);
2183 $this->
error = $adh->error;
2184 $this->errors = $adh->errors;
2185 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2188 } elseif ($result < 0) {
2189 $this->
error = $adh->error;
2190 $this->errors = $adh->errors;
2195 if ($this->contact_id > 0 && !$nosynccontact) {
2196 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2198 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2201 $tmpobj =
new Contact($this->db);
2202 $result = $tmpobj->fetch($this->contact_id);
2205 $tmpobj->civility_code = $this->civility_code;
2206 $tmpobj->firstname = $this->firstname;
2207 $tmpobj->lastname = $this->lastname;
2208 $tmpobj->login = $this->login;
2209 $tmpobj->gender = $this->gender;
2210 $tmpobj->birth = $this->birth;
2214 $tmpobj->email = $this->email;
2216 $tmpobj->socialnetworks = $this->socialnetworks;
2218 $tmpobj->phone_pro = $this->office_phone;
2219 $tmpobj->phone_mobile = $this->user_mobile;
2220 $tmpobj->fax = $this->office_fax;
2222 $tmpobj->default_lang = $this->lang;
2224 $tmpobj->address = $this->address;
2225 $tmpobj->town = $this->town;
2226 $tmpobj->zip = $this->zip;
2227 $tmpobj->state_id = $this->state_id;
2228 $tmpobj->country_id = $this->country_id;
2230 $tmpobj->user_id = $this->id;
2231 $tmpobj->user_login = $this->login;
2233 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2235 $this->
error = $tmpobj->error;
2236 $this->errors = $tmpobj->errors;
2237 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2241 $this->
error = $tmpobj->error;
2242 $this->errors = $tmpobj->errors;
2258 if (!$error && !$notrigger) {
2268 $this->db->commit();
2269 return $nbrowsaffected;
2272 $this->db->rollback();
2276 $this->
error = $this->db->lasterror();
2277 $this->db->rollback();
2296 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2297 $sql .=
" datepreviouslogin = datelastlogin,";
2298 $sql .=
" ippreviouslogin = iplastlogin,";
2299 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2300 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2301 $sql .=
" tms = tms";
2302 $sql .=
" WHERE rowid = ".((int) $this->
id);
2304 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2305 $resql = $this->db->query($sql);
2307 $this->datepreviouslogin = $this->datelastlogin;
2308 $this->datelastlogin = $now;
2309 $this->ippreviouslogin = $this->iplastlogin;
2310 $this->iplastlogin = $userremoteip;
2313 $this->
error = $this->db->lasterror().
' sql='.$sql;
2331 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2333 global $conf, $langs;
2334 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2338 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2346 if (empty($passwordalreadycrypted)) {
2349 $modGeneratePassClass =
'modGeneratePass'.ucfirst($conf->global->USER_PASSWORD_GENERATED);
2351 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2352 if (class_exists($modGeneratePassClass)) {
2353 $modGeneratePass =
new $modGeneratePassClass($this->db, $conf, $langs, $user);
2356 $modGeneratePass->WithoutAmbi = 0;
2359 $testpassword = $modGeneratePass->validatePassword($password);
2360 if (!$testpassword) {
2361 $this->
error = $modGeneratePass->error;
2369 $password_crypted =
dol_hash($password);
2373 if (!$changelater) {
2374 if (!is_object($this->oldcopy)) {
2375 $this->oldcopy = clone $this;
2380 $sql =
"UPDATE ".$this->db->prefix().
"user";
2381 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2382 $sql .=
" pass_temp = null";
2383 if (!empty($flagdelsessionsbefore)) {
2384 $sql .=
", flagdelsessionsbefore = '".$this->db->idate(
dol_now() - 5,
'gmt').
"'";
2387 $sql .=
", pass = null";
2389 $sql .=
", pass = '".$this->db->escape($password).
"'";
2391 $sql .=
" WHERE rowid = ".((int) $this->
id);
2393 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2394 $result = $this->db->query($sql);
2396 if ($this->db->affected_rows($result)) {
2397 $this->pass = $password;
2398 $this->pass_indatabase = $password;
2399 $this->pass_indatabase_crypted = $password_crypted;
2401 if ($this->fk_member && !$nosyncmember) {
2402 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2407 $result = $adh->fetch($this->fk_member);
2410 $result = $adh->setPassword($user, $this->pass, (!
getDolGlobalString(
'DATABASE_PWD_ENCRYPTED') ? 0 : 1), 1);
2411 if (is_int($result) && $result < 0) {
2412 $this->
error = $adh->error;
2417 $this->
error = $adh->error;
2422 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2424 if (!$error && !$notrigger) {
2426 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2429 $this->db->rollback();
2435 $this->db->commit();
2438 $this->db->rollback();
2442 $this->db->rollback();
2449 $sql =
"UPDATE ".$this->db->prefix().
"user";
2450 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2451 $sql .=
" WHERE rowid = ".((int) $this->
id);
2453 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2454 $result = $this->db->query($sql);
2476 global $conf, $langs, $mysoc;
2477 global $dolibarr_main_url_root;
2479 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2486 $outputlangs =
new Translate(
"", $conf);
2488 if (isset($this->
conf->MAIN_LANG_DEFAULT)
2489 && $this->conf->MAIN_LANG_DEFAULT !=
'auto') {
2490 $outputlangs->getDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2493 if ($this->
conf->MAIN_LANG_DEFAULT) {
2494 $outputlangs->setDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2496 $outputlangs = $langs;
2500 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2502 $appli =
getDolGlobalString(
'MAIN_APPLICATION_TITLE', constant(
'DOL_APPLICATION_TITLE'));
2504 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2507 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2508 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2510 if (!$changelater) {
2511 $url = $urlwithroot.
'/';
2513 $url = $conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD;
2516 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2518 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2519 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2520 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2521 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2524 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2526 $mesg .= $user->getFullName($outputlangs);
2529 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2530 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.$conf->file->instance_unique_id));
2531 if (isModEnabled(
'multicompany')) {
2532 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2535 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2539 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2540 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2541 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2542 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2544 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2545 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2546 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2549 $trackid =
'use'.$this->id;
2550 $sendcontext =
'password';
2555 $conf->global->MAIN_MAIL_EMAIL_FROM,
2571 if ($mailfile->sendfile()) {
2574 $langs->trans(
"errors");
2575 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2587 return $this->error;
2600 $sql =
"SELECT url, login, pass, poste ";
2601 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2602 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2604 $resql = $this->db->query($sql);
2606 if ($this->db->num_rows($resql)) {
2607 $obj = $this->db->fetch_object($resql);
2609 $this->clicktodial_url = $obj->url;
2610 $this->clicktodial_login = $obj->login;
2611 $this->clicktodial_password = $obj->pass;
2612 $this->clicktodial_poste = $obj->poste;
2615 $this->clicktodial_loaded = 1;
2617 $this->db->free($resql);
2620 $this->
error = $this->db->error();
2636 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2637 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2639 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2640 $result = $this->db->query($sql);
2642 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2643 $sql .=
" (fk_user,url,login,pass,poste)";
2644 $sql .=
" VALUES (".$this->id;
2645 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2646 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2647 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2648 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2650 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2651 $result = $this->db->query($sql);
2653 $this->db->commit();
2656 $this->db->rollback();
2657 $this->
error = $this->db->lasterror();
2675 global $conf, $langs, $user;
2681 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2682 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2683 $sql .=
" AND fk_usergroup = ".((int) $group);
2684 $sql .=
" AND entity = ".((int) $entity);
2686 $result = $this->db->query($sql);
2688 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2689 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2691 $result = $this->db->query($sql);
2693 if (!$error && !$notrigger) {
2694 $this->context = array(
'audit'=>$langs->trans(
"UserSetInGroup"),
'newgroupid'=>$group);
2705 $this->db->commit();
2709 $this->db->rollback();
2713 $this->
error = $this->db->lasterror();
2714 $this->db->rollback();
2731 global $conf, $langs, $user;
2737 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2738 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2739 $sql .=
" AND fk_usergroup = ".((int) $group);
2740 if (empty($entity)) {
2741 $sql .=
" AND entity IN (0, 1)";
2743 $sql .=
" AND entity = ".((int) $entity);
2746 $result = $this->db->query($sql);
2748 if (!$error && !$notrigger) {
2749 $this->context = array(
'audit'=>$langs->trans(
"UserRemovedFromGroup"),
'oldgroupid'=>$group);
2760 $this->db->commit();
2763 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2764 $this->db->rollback();
2768 $this->
error = $this->db->lasterror();
2769 $this->db->rollback();
2783 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2790 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
2812 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
2814 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2815 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
2830 global $conf, $langs, $menumanager;
2831 global $dolibarr_main_demo;
2833 $infologin = $params[
'infologin'] ?? 0;
2834 $option = $params[
'option'] ??
'';
2837 if (!empty($this->photo)) {
2838 $photo =
'<div class="photointooltip floatright">';
2839 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
2841 $datas[
'photo'] = $photo;
2846 $datas[
'opendiv'] =
'<div class="centpercent divtooltip">';
2847 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
2849 if (!empty($this->login)) {
2850 $datas[
'login'] =
'<br><b>'.$langs->trans(
'Login').
':</b> '.
dol_string_nohtmltag($this->login);
2852 if (!empty($this->job)) {
2855 $datas[
'email'] =
'<br><b>'.$langs->trans(
"Email").
':</b> '.
dol_string_nohtmltag($this->email);
2856 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
2857 $phonelist = array();
2858 if ($this->office_phone) {
2859 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2861 if ($this->office_fax) {
2862 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2864 if ($this->user_mobile) {
2865 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
2867 $datas[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
2869 if (!empty($this->admin)) {
2870 $datas[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
2872 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
2873 $langs->load(
"companies");
2874 $datas[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
2877 if (!empty($this->socid)) {
2878 $thirdpartystatic =
new Societe($this->db);
2879 $thirdpartystatic->fetch($this->socid);
2881 if (empty($params[
'hidethirdpartylogo'])) {
2882 $companyimg =
' '.$thirdpartystatic->getNomUrl(2, (($option ==
'nolink') ?
'nolink' :
''));
2884 $company =
' ('.$langs->trans(
"Company").
': '.($companyimg ? $companyimg :
img_picto(
'',
'company')).
' '.
dol_string_nohtmltag($thirdpartystatic->name).
')';
2886 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
2887 $datas[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
2888 $datas[
'closediv'] =
'</div>';
2890 if ($infologin > 0) {
2891 $datas[
'newlinelogin'] =
'<br>';
2892 $datas[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
2895 $datas[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.$conf->entity.
' (User entity '.$this->entity.
')';
2897 $datas[
'authentication'] =
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
2898 $datas[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
2899 $datas[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
2900 $datas[
'currenttheme'] =
'<br><b>'.$langs->trans(
"CurrentTheme").
':</b> '.
dol_string_nohtmltag($conf->theme);
2901 $datas[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
2903 $datas[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
2904 $datas[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag($conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
2905 $datas[
'layout'] =
'<br><b>'.$langs->trans(
"Layout").
':</b> '.
dol_string_nohtmltag($conf->browser->layout);
2906 $datas[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
2907 if ($conf->browser->layout ==
'phone') {
2908 $datas[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
2910 if (!empty($_SESSION[
"disablemodules"])) {
2911 $datas[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(join(
', ', explode(
',', $_SESSION[
"disablemodules"])));
2933 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
2935 global $langs, $conf, $db, $hookmanager, $user;
2936 global $dolibarr_main_authentication, $dolibarr_main_demo;
2938 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
2949 'objecttype' => $this->element,
2950 'infologin' => $infologin,
2951 'option' => $option,
2953 $classfortooltip =
'classfortooltip';
2956 $classfortooltip =
'classforajaxtooltip';
2957 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
2964 if (!empty($this->socid)) {
2965 $thirdpartystatic =
new Societe($this->db);
2966 $thirdpartystatic->fetch($this->socid);
2967 if (empty($hidethirdpartylogo)) {
2968 $companylink =
' '.$thirdpartystatic->getNomUrl(2, (($option ==
'nolink') ?
'nolink' :
''));
2972 if ($infologin < 0) {
2976 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
2977 if ($option ==
'leave') {
2978 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
2981 if ($option !=
'nolink') {
2983 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2984 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2985 $add_save_lastsearch_values = 1;
2987 if ($add_save_lastsearch_values) {
2988 $url .=
'&save_lastsearch_values=1';
2992 $linkstart =
'<a href="'.$url.
'"';
2994 if (empty($notooltip)) {
2996 $langs->load(
"users");
2997 $label = $langs->trans(
"ShowUser");
2998 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
3000 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
3001 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
3003 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
3006 $linkstart .= $linkclose.
'>';
3010 $result .= (($option ==
'nolink') ?
'' : $linkstart);
3011 if ($withpictoimg) {
3012 $paddafterimage =
'';
3013 if (abs((
int) $withpictoimg) == 1) {
3014 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3017 if ($withpictoimg > 0) {
3018 $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>';
3021 $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>';
3025 if ($withpictoimg > -2 && $withpictoimg != 2) {
3027 $result .=
'<span class="nopadding usertext'.((!isset($this->
status) || $this->status) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
3029 if ($mode ==
'login') {
3035 $result .=
'</span>';
3038 $result .= (($option ==
'nolink') ?
'' : $linkend);
3041 $result .= $companylink;
3044 $hookmanager->initHooks(array(
'userdao'));
3045 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
3046 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3048 $result = $hookmanager->resPrint;
3050 $result .= $hookmanager->resPrint;
3065 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
3067 global $langs, $user;
3071 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3075 if ((!$user->hasRight(
'user',
'user',
'lire') && $this->id != $user->id)) {
3079 if ($option ==
'xxx') {
3080 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3084 if ($option ==
'nolink') {
3089 $result .= $linkstart;
3090 if ($withpictoimg) {
3091 $paddafterimage =
'';
3092 if (abs($withpictoimg) == 1) {
3093 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3096 if ($withpictoimg > 0) {
3097 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3100 $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>';
3104 $result .= $this->login;
3105 $result .= $linkend;
3134 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3137 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3138 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3139 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3140 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3143 $statusType =
'status5';
3144 if ($status == self::STATUS_ENABLED) {
3145 $statusType =
'status4';
3148 $label = $this->labelStatus[$status];
3149 $labelshort = $this->labelStatusShort[$status];
3152 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3153 $statusType =
'status3';
3154 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3156 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3157 $statusType =
'status2';
3158 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3161 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3176 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3178 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3179 $return .=
'<div class="info-box info-box-sm">';
3180 $return .=
'<span class="info-box-icon bg-infobox-action">';
3183 if (!empty($this->photo)) {
3185 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3194 $return .=
'</span>';
3195 $return .=
'<div class="info-box-content">';
3196 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3197 if (isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3198 $return .=
img_picto($langs->trans(
"SuperAdministratorDesc"),
'redstar',
'class="valignmiddle paddingright paddingleft"');
3199 } elseif ($this->admin) {
3200 $return .=
img_picto($langs->trans(
"AdministratorDesc"),
'star',
'class="valignmiddle paddingright paddingleft"');
3202 $return .=
'</span>';
3203 if ($selected >= 0) {
3204 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3206 if (property_exists($this,
'label')) {
3207 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3210 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->email.
'</span>';
3212 if (method_exists($this,
'getLibStatut')) {
3213 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3215 $return .=
'</div>';
3216 $return .=
'</div>';
3217 $return .=
'</div>';
3241 } elseif ($mode == 1) {
3242 $dn = $conf->global->LDAP_USER_DN;
3243 } elseif ($mode == 2) {
3259 global $conf, $langs;
3265 $keymodified =
false;
3274 'LDAP_FIELD_FULLNAME' =>
'fullname',
3275 'LDAP_FIELD_NAME' =>
'lastname',
3276 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3277 'LDAP_FIELD_LOGIN' =>
'login',
3278 'LDAP_FIELD_LOGIN_SAMBA'=>
'login',
3279 'LDAP_FIELD_PHONE' =>
'office_phone',
3280 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3281 'LDAP_FIELD_FAX' =>
'office_fax',
3282 'LDAP_FIELD_MAIL' =>
'email',
3283 'LDAP_FIELD_SID' =>
'ldap_sid',
3287 foreach ($ldapkey as $constname => $varname) {
3293 if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
3294 $keymodified =
true;
3299 foreach ($socialnetworks as $key => $value) {
3300 if (!empty($this->socialnetworks[$value[
'label']]) &&
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))) {
3301 $info[
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))] = $this->socialnetworks[$value[
'label']];
3316 if ($this->socid > 0) {
3317 $soc =
new Societe($this->db);
3318 $soc->fetch($this->socid);
3321 if ($soc->client == 1) {
3322 $info[
"businessCategory"] =
"Customers";
3324 if ($soc->client == 2) {
3325 $info[
"businessCategory"] =
"Prospects";
3327 if ($soc->fournisseur == 1) {
3328 $info[
"businessCategory"] =
"Suppliers";
3333 if (!empty($this->pass)) {
3346 if ($this->pass_indatabase_crypted &&
getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED')) {
3350 } elseif (!empty($this->pass_indatabase)) {
3362 $info[
"objectclass"][4] =
"phpgwContact";
3364 $info[
'uidnumber'] = $this->id;
3366 $info[
'phpgwTz'] = 0;
3367 $info[
'phpgwMailType'] =
'INTERNET';
3368 $info[
'phpgwMailHomeType'] =
'INTERNET';
3370 $info[
"phpgwContactTypeId"] =
'n';
3371 $info[
"phpgwContactCatId"] = 0;
3372 $info[
"phpgwContactAccess"] =
"public";
3375 $this->egroupware_id = 1;
3378 $info[
"phpgwContactOwner"] = $this->egroupware_id;
3381 $info[
"rfc822Mailbox"] = $this->email;
3383 if ($this->user_mobile) {
3384 $info[
"phpgwCellTelephoneNumber"] = $this->user_mobile;
3393 $groupslist = $usergroup->listGroupsForUser($this->
id);
3395 if (!empty($groupslist)) {
3396 foreach ($groupslist as $groupforuser) {
3403 $info[
getDolGlobalString(
'LDAP_FIELD_HOMEDIRECTORY')] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->login";
3419 global $user, $langs;
3425 $this->
ref =
'SPECIMEN';
3426 $this->specimen = 1;
3428 $this->lastname =
'DOLIBARR';
3429 $this->firstname =
'SPECIMEN';
3430 $this->gender =
'man';
3431 $this->note_public =
'This is a note public';
3432 $this->note_private =
'This is a note private';
3433 $this->email =
'email@specimen.com';
3434 $this->personal_email =
'personalemail@specimen.com';
3435 $this->socialnetworks = array(
3436 'skype' =>
'skypepseudo',
3437 'twitter' =>
'twitterpseudo',
3438 'facebook' =>
'facebookpseudo',
3439 'linkedin' =>
'linkedinpseudo',
3441 $this->office_phone =
'0999999999';
3442 $this->office_fax =
'0999999998';
3443 $this->user_mobile =
'0999999997';
3444 $this->personal_mobile =
'0999999996';
3446 $this->login =
'dolibspec';
3447 $this->pass =
'dolibSpec+@123';
3450 $this->datec = $now;
3451 $this->datem = $now;
3453 $this->datelastlogin = $now;
3454 $this->iplastlogin =
'127.0.0.1';
3455 $this->datepreviouslogin = $now;
3456 $this->ippreviouslogin =
'127.0.0.1';
3472 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
3473 $sql .=
" u.tms as date_modification, u.entity";
3474 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3475 $sql .=
" WHERE u.rowid = ".((int) $id);
3477 $result = $this->db->query($sql);
3479 if ($this->db->num_rows($result)) {
3480 $obj = $this->db->fetch_object($result);
3482 $this->
id = $obj->rowid;
3484 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3485 $this->date_creation = $this->db->jdate($obj->datec);
3486 $this->date_modification = $this->db->jdate($obj->date_modification);
3487 $this->entity = $obj->entity;
3490 $this->db->free($result);
3504 $sql =
"SELECT count(mc.email) as nb";
3505 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3506 $sql .=
" WHERE mc.email = '".$this->db->escape($this->email).
"'";
3507 $sql .=
" AND mc.statut NOT IN (-1,0)";
3509 $resql = $this->db->query($sql);
3511 $obj = $this->db->fetch_object($resql);
3514 $this->db->free($resql);
3517 $this->
error = $this->db->error();
3534 $sql =
"SELECT count(rowid) as nb";
3535 $sql .=
" FROM ".$this->db->prefix().
"user";
3536 if ($option ==
'superadmin') {
3537 $sql .=
" WHERE entity = 0";
3539 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3540 if ($limitTo ==
'active') {
3541 $sql .=
" AND statut = 1";
3545 $sql .=
" AND admin = ".(int) $admin;
3548 $resql = $this->db->query($sql);
3550 $obj = $this->db->fetch_object($resql);
3551 $nb = (int) $obj->nb;
3553 $this->db->free($resql);
3556 $this->
error = $this->db->lasterror();
3572 global $user, $conf;
3577 $this->firstname = $ldapuser->$tmpvar;
3579 $this->lastname = $ldapuser->$tmpvar;
3581 $this->login = $ldapuser->$tmpvar;
3583 $this->pass = $ldapuser->$tmpvar;
3585 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3588 $this->office_phone = $ldapuser->$tmpvar;
3590 $this->user_mobile = $ldapuser->$tmpvar;
3592 $this->office_fax = $ldapuser->$tmpvar;
3594 $this->email = $ldapuser->$tmpvar;
3595 foreach ($socialnetworks as $key => $value) {
3597 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3600 $this->ldap_sid = $ldapuser->$tmpvar;
3603 $this->job = $ldapuser->$tmpvar;
3605 $this->note_public = $ldapuser->$tmpvar;
3607 $result = $this->
update($user);
3609 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3625 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3626 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3628 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3629 $res = $this->db->query($sql);
3632 while ($rec = $this->db->fetch_array($res)) {
3633 $user =
new User($this->db);
3634 $user->fetch($rec[
'rowid']);
3654 $this->parentof = array();
3657 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3658 $sql .=
" FROM ".$this->db->prefix().
"user";
3659 $sql .=
" WHERE fk_user <> 0";
3660 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3662 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3663 $resql = $this->db->query($sql);
3665 while ($obj = $this->db->fetch_object($resql)) {
3666 $this->parentof[$obj->id_son] = $obj->id_parent;
3692 global $conf, $user;
3693 global $hookmanager;
3696 $hookmanager->initHooks(array(
'userdao'));
3698 $this->users = array();
3704 $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";
3705 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3707 $parameters = array();
3708 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3710 $sql .= $hookmanager->resPrint;
3712 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3715 $sql .=
" AND ".$filter;
3718 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3719 $resql = $this->db->query($sql);
3722 while ($obj = $this->db->fetch_object($resql)) {
3723 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3724 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3725 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3726 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3727 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3728 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3729 $this->users[$obj->rowid][
'login'] = $obj->login;
3730 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3731 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3732 $this->users[$obj->rowid][
'email'] = $obj->email;
3733 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3734 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3735 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3744 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3745 foreach ($this->users as $key => $val) {
3748 $this->
error =
'ErrorLoopInHierarchy';
3754 if ($deleteafterid) {
3756 $keyfilter1 =
'^'.$deleteafterid.
'$';
3757 $keyfilter2 =
'_'.$deleteafterid.
'$';
3758 $keyfilter3 =
'^'.$deleteafterid.
'_';
3759 $keyfilter4 =
'_'.$deleteafterid.
'_';
3760 foreach ($this->users as $key => $val) {
3761 if (preg_match(
'/'.$keyfilter1.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter2.
'/', $val[
'fullpath'])
3762 || preg_match(
'/'.$keyfilter3.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter4.
'/', $val[
'fullpath'])) {
3763 unset($this->users[$key]);
3768 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
3769 $this->users =
dol_sort_array($this->users,
'fullname',
'asc',
true,
false, 1);
3773 return $this->users;
3786 $childids = array();
3788 if (isset($this->cache_childids[$this->
id])) {
3789 $childids = $this->cache_childids[$this->id];
3794 $idtoscan = $this->id;
3796 dol_syslog(
"Build childid for id = ".$idtoscan);
3797 foreach ($this->users as $id => $val) {
3799 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
3800 $childids[$val[
'id']] = $val[
'id'];
3804 $this->cache_childids[$this->id] = $childids;
3806 if ($addcurrentuser) {
3807 $childids[$this->id] = $this->id;
3827 if (!empty($this->users[$id_user][
'fullpath'])) {
3829 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
3834 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
3835 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
3837 $cursor_user = $id_user;
3839 $useridfound = array($id_user);
3840 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
3841 if (in_array($this->parentof[$cursor_user], $useridfound)) {
3842 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
3845 $useridfound[] = $this->parentof[$cursor_user];
3846 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
3847 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
3849 $cursor_user = $this->parentof[$cursor_user];
3853 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
3887 $this->nb = array();
3889 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
3890 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3891 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
3892 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
3893 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
3894 $sql .=
" AND ug.fk_user = u.rowid";
3896 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3898 $sql .=
" AND u.statut > 0";
3901 $resql = $this->db->query($sql);
3903 while ($obj = $this->db->fetch_object($resql)) {
3904 $this->nb[
"users"] = $obj->nb;
3906 $this->db->free($resql);
3910 $this->
error = $this->db->error();
3926 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3928 global $conf, $user, $langs;
3930 $langs->load(
"user");
3935 $modele = $conf->global->USER_ADDON_PDF;
3937 $modele =
'bluesky';
3941 $modelpath =
"core/modules/user/doc/";
3943 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3957 $user_property =
'';
3959 if (empty($rowid)) {
3963 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
3964 $sql .=
" FROM ".$this->db->prefix().
"user";
3965 $sql .=
" WHERE rowid = ".((int) $rowid);
3967 $resql = $this->db->query($sql);
3969 $nump = $this->db->num_rows($resql);
3972 $obj = $this->db->fetch_object($resql);
3974 if ($mode ==
'email') {
3975 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
3976 } elseif ($mode ==
'mobile') {
3977 $user_property = $obj->user_mobile;
3978 } elseif ($mode ==
'name') {
3982 return $user_property;
3999 global $dolibarr_main_url_root;
4002 $encodedsecurekey =
dol_hash($conf->file->instance_unique_id.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
4003 if (isModEnabled(
'multicompany')) {
4004 $entity_qr =
'&entity='.((int) $conf->entity);
4009 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
4010 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
4013 if ($typeofurl ==
'internal') {
4014 $urlwithroot = DOL_URL_ROOT;
4017 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
4032 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter = array(), $filtermode =
'AND', $entityfilter =
false)
4034 global $conf, $user;
4036 $sql =
"SELECT t.rowid";
4037 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
4039 if ($entityfilter) {
4041 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
4042 $sql .=
" WHERE t.entity IS NOT NULL";
4044 $sql .=
",".$this->db->prefix().
"usergroup_user as ug";
4045 $sql .=
" WHERE ((ug.fk_user = t.rowid";
4046 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
4047 $sql .=
" OR t.entity = 0)";
4050 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
4053 $sql .=
" WHERE 1 = 1";
4057 $sqlwhere = array();
4058 if (!empty($filter)) {
4059 foreach ($filter as $key => $value) {
4060 if ($key ==
't.rowid') {
4061 $sqlwhere[] = $key.
" = ".((int) $value);
4062 } elseif (array_key_exists($key, $this->fields) && isset($this->fields[$key][
'type']) && in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
4063 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
4064 } elseif ($key ==
'customsql') {
4065 $sqlwhere[] = $value;
4067 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
4071 if (count($sqlwhere) > 0) {
4072 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
4074 $sql .= $this->db->order($sortfield, $sortorder);
4076 $sql .= $this->db->plimit($limit + 1, $offset);
4081 $resql = $this->db->query($sql);
4083 $this->users = array();
4084 $num = $this->db->num_rows($resql);
4086 while ($obj = $this->db->fetch_object($resql)) {
4087 $line =
new self($this->db);
4088 $result = $line->fetch($obj->rowid);
4089 if ($result > 0 && !empty($line->id)) {
4090 $this->users[$obj->rowid] = clone $line;
4093 $this->db->free($resql);
4097 $this->errors[] = $this->db->lasterror();
4109 private $findUserIdByEmailCache;
4123 if (isset($this->findUserIdByEmailCache[$email])) {
4124 return $this->findUserIdByEmailCache[$email];
4127 $this->findUserIdByEmailCache[$email] = -1;
4131 $sql =
'SELECT rowid';
4132 $sql .=
' FROM '.$this->db->prefix().
'user';
4133 if (
getDolGlobalString(
'AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR')) {
4134 $sql .=
" WHERE email LIKE '%".$this->db->escape($email).
"%'";
4136 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4140 $resql = $this->db->query($sql);
4145 $obj = $this->db->fetch_object($resql);
4150 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4152 return $this->findUserIdByEmailCache[$email];
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
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)
get_children()
Return and array with all instanciated 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.
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()
Mise a jour en base de la date de derniere connexion d'un utilisateur Fonction appelee lors d'une nou...
__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.
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 (eventualy 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 childs 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 users id in herarchy (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 optionaly the picto) Use this->id,this->lastname,...
clearrights()
Clear all permissions array of user.
load_state_board()
Load metrics this->nb for dashboard.
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 user into object user.
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 clicable link of object (with eventually 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.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter=array(), $filtermode='AND', $entityfilter=false)
Load all objects into $this->users.
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.
trait CommonPeople
Superclass for thirdparties, contacts, members or users.
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...
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
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_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.
getDolGlobalString($key, $default='')
Return 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)
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut
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 symetric 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 symetric encryption.
dol_hash($chain, $type='0', $nosalt=0)
Returns a hash (non reversible encryption) of a string.