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 'project' =>
'projet',
772 'propale' =>
'propal',
773 'shipping' =>
'expedition',
774 'task' =>
'task@projet',
775 'fichinter' =>
'ficheinter',
776 'inventory' =>
'stock',
777 'invoice' =>
'facture',
778 'invoice_supplier' =>
'fournisseur',
779 'order_supplier' =>
'fournisseur',
780 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
781 'skill@hrm' =>
'all@hrm',
782 'job@hrm' =>
'all@hrm',
783 'position@hrm' =>
'all@hrm',
784 'facturerec' =>
'facture',
785 'margins' =>
'margin',
788 if (!empty($moduletomoduletouse[$module])) {
789 $module = $moduletomoduletouse[$module];
792 $moduleRightsMapping = array(
793 'product' =>
'produit',
794 'margin' =>
'margins',
795 'comptabilite' =>
'compta'
798 $rightsPath = $module;
799 if (!empty($moduleRightsMapping[$rightsPath])) {
800 $rightsPath = $moduleRightsMapping[$rightsPath];
804 $tmp = explode(
'@', $rightsPath, 2);
805 if (!empty($tmp[1])) {
806 if (strpos($module,
'@') !==
false) {
809 $rightsPath = $tmp[1];
810 $permlevel2 = $permlevel1;
811 $permlevel1 = $tmp[0];
821 if (!isModEnabled($module)) {
826 if ($permlevel1 ==
'propale') {
827 $permlevel1 =
'propal';
829 if ($permlevel1 ==
'member') {
830 $permlevel1 =
'adherent';
832 if ($permlevel1 ==
'recruitmentcandidature') {
833 $permlevel1 =
'recruitmentjobposition';
838 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
843 if (!empty($this->rights->$rightsPath->$permlevel1)) {
844 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
845 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
849 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
850 return $this->rights->$rightsPath->$permlevel1->lire;
852 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
853 return $this->rights->$rightsPath->$permlevel1->creer;
855 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
856 return $this->rights->$rightsPath->$permlevel1->create;
858 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
859 return $this->rights->$rightsPath->$permlevel1->supprimer;
863 if (!empty($this->rights->$rightsPath->$permlevel1)) {
864 return $this->rights->$rightsPath->$permlevel1;
868 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
869 return $this->rights->$rightsPath->lire;
871 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
872 return $this->rights->$rightsPath->creer;
874 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
875 return $this->rights->$rightsPath->create;
877 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
878 return $this->rights->$rightsPath->supprimer;
896 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
898 global $conf, $user, $langs;
900 $entity = (empty($entity) ? $conf->entity : $entity);
902 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
904 if (empty($this->
id)) {
905 $this->
error =
'Try to call addrights on an object user with an empty id';
915 $module = $perms = $subperms =
'';
918 $sql =
"SELECT module, perms, subperms";
919 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
920 $sql .=
" WHERE id = ".((int) $rid);
921 $sql .=
" AND entity = ".((int) $entity);
923 $result = $this->db->query($sql);
925 $obj = $this->db->fetch_object($result);
928 $module = $obj->module;
929 $perms = $obj->perms;
930 $subperms = $obj->subperms;
938 $whereforadd =
"id=".((int) $rid);
940 if (!empty($subperms)) {
941 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
942 } elseif (!empty($perms)) {
943 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
949 if (!empty($allmodule)) {
950 if ($allmodule ==
'allmodules') {
951 $whereforadd =
'allmodules';
953 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
954 if (!empty($allperms)) {
955 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
963 if (!empty($whereforadd)) {
966 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
967 $sql .=
" WHERE entity = ".((int) $entity);
968 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
969 $sql .=
" AND (".$whereforadd.
")";
972 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
973 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
975 $sqldelete .=
") AND entity = ".((int) $entity);
976 if (!$this->db->query($sqldelete)) {
981 $resql = $this->db->query($sql);
983 $num = $this->db->num_rows($resql);
986 $obj = $this->db->fetch_object($resql);
991 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
992 if (!$this->db->query($sql)) {
1006 if (!$error && !$notrigger) {
1007 $langs->load(
"other");
1008 $this->context = array(
'audit'=>$langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
1019 $this->db->rollback();
1022 $this->db->commit();
1039 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1041 global $conf, $user, $langs;
1045 $entity = (!empty($entity) ? $entity : $conf->entity);
1050 $module = $perms = $subperms =
'';
1054 $sql =
"SELECT module, perms, subperms";
1055 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1056 $sql .=
" WHERE id = '".$this->db->escape($rid).
"'";
1057 $sql .=
" AND entity = ".((int) $entity);
1059 $result = $this->db->query($sql);
1061 $obj = $this->db->fetch_object($result);
1064 $module = $obj->module;
1065 $perms = $obj->perms;
1066 $subperms = $obj->subperms;
1074 $wherefordel =
"id=".((int) $rid);
1076 if ($subperms ==
'lire' || $subperms ==
'read') {
1077 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1079 if ($perms ==
'lire' || $perms ==
'read') {
1080 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1085 if (!empty($allmodule)) {
1086 if ($allmodule ==
'allmodules') {
1087 $wherefordel =
'allmodules';
1089 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1090 if (!empty($allperms)) {
1091 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1098 if (!empty($wherefordel)) {
1101 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1102 $sql .=
" WHERE entity = ".((int) $entity);
1103 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1104 $sql .=
" AND (".$wherefordel.
")";
1108 if ($this->admin == 1) {
1109 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1110 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1111 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1112 $sql .=
" AND id NOT IN (358)";
1115 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1116 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1119 $sqldelete .=
" AND entity = ".((int) $entity);
1121 $resql = $this->db->query($sqldelete);
1128 if (!$error && !$notrigger) {
1129 $langs->load(
"other");
1130 $this->context = array(
'audit'=>$langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1141 $this->db->rollback();
1144 $this->db->commit();
1158 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1159 $this->rights =
null;
1160 $this->nb_rights = 0;
1161 $this->all_permissions_are_loaded = 0;
1162 $this->_tab_loaded = array();
1174 public function getrights($moduletag =
'', $forcereload = 0)
1178 if (empty($forcereload)) {
1179 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1184 if (!empty($this->all_permissions_are_loaded)) {
1191 if (!isset($this->rights) || !is_object($this->rights)) {
1194 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1195 $this->rights->user =
new stdClass();
1201 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1202 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1203 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1204 $sql .=
" WHERE r.id = ur.fk_id";
1207 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') ?
"1," :
"").$conf->entity.
")";
1211 $sql .=
" AND r.entity = ".((int) $conf->entity).
" AND ur.entity = ".((int) $conf->entity);
1213 $sql .=
" AND ur.fk_user= ".((int) $this->
id);
1214 $sql .=
" AND r.perms IS NOT NULL";
1216 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1219 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1222 $resql = $this->db->query($sql);
1224 $num = $this->db->num_rows($resql);
1227 $obj = $this->db->fetch_object($resql);
1230 $module = $obj->module;
1231 $perms = $obj->perms;
1232 $subperms = $obj->subperms;
1234 if (!empty($perms)) {
1235 if (!empty($module)) {
1236 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1237 $this->rights->$module =
new stdClass();
1239 if (!empty($subperms)) {
1240 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1241 $this->rights->$module->$perms =
new stdClass();
1243 if (empty($this->rights->$module->$perms->$subperms)) {
1246 $this->rights->$module->$perms->$subperms = 1;
1248 if (empty($this->rights->$module->$perms)) {
1251 $this->rights->$module->$perms = 1;
1258 $this->db->free($resql);
1262 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1263 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1264 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1265 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1266 $sql .=
" WHERE r.id = gr.fk_id";
1269 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
1270 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1272 $sql .=
" AND r.entity = ".((int) $conf->entity);
1275 $sql .=
" AND gr.entity = ".((int) $conf->entity);
1279 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1280 $sql .=
" AND r.entity = ".((int) $conf->entity);
1283 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1284 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1285 $sql .=
" AND r.perms IS NOT NULL";
1287 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1290 $resql = $this->db->query($sql);
1292 $num = $this->db->num_rows($resql);
1295 $obj = $this->db->fetch_object($resql);
1298 $module = $obj->module;
1299 $perms = $obj->perms;
1300 $subperms = $obj->subperms;
1302 if (!empty($perms)) {
1303 if (!empty($module)) {
1304 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1305 $this->rights->$module =
new stdClass();
1307 if (!empty($subperms)) {
1308 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1309 $this->rights->$module->$perms =
new stdClass();
1311 if (empty($this->rights->$module->$perms->$subperms)) {
1314 $this->rights->$module->$perms->$subperms = 1;
1316 if (empty($this->rights->$module->$perms)) {
1320 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1321 $this->rights->$module->$perms = 1;
1329 $this->db->free($resql);
1333 if (!empty($this->admin)) {
1334 if (empty($this->rights->user->user)) {
1335 $this->rights->user->user =
new stdClass();
1337 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1338 foreach ($listofpermtotest as $permtotest) {
1339 if (empty($this->rights->user->user->$permtotest)) {
1340 $this->rights->user->user->$permtotest = 1;
1344 if (empty($this->rights->user->self)) {
1345 $this->rights->user->self =
new stdClass();
1347 $listofpermtotest = array(
'creer',
'password');
1348 foreach ($listofpermtotest as $permtotest) {
1349 if (empty($this->rights->user->self->$permtotest)) {
1350 $this->rights->user->self->$permtotest = 1;
1356 if (empty($this->rights->user->user_advance)) {
1357 $this->rights->user->user_advance =
new stdClass();
1359 $listofpermtotest = array(
'readperms',
'write');
1360 foreach ($listofpermtotest as $permtotest) {
1361 if (empty($this->rights->user->user_advance->$permtotest)) {
1362 $this->rights->user->user_advance->$permtotest = 1;
1366 if (empty($this->rights->user->self_advance)) {
1367 $this->rights->user->self_advance =
new stdClass();
1369 $listofpermtotest = array(
'readperms',
'writeperms');
1370 foreach ($listofpermtotest as $permtotest) {
1371 if (empty($this->rights->user->self_advance->$permtotest)) {
1372 $this->rights->user->self_advance->$permtotest = 1;
1376 if (empty($this->rights->user->group_advance)) {
1377 $this->rights->user->group_advance =
new stdClass();
1379 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1380 foreach ($listofpermtotest as $permtotest) {
1381 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1382 $this->rights->user->group_advance->$permtotest = 1;
1390 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1391 $this->rights->propal = $this->rights->propale;
1393 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1394 $this->rights->propale = $this->rights->propal;
1400 $this->all_permissions_are_loaded = 1;
1403 $this->_tab_loaded[$moduletag] = 1;
1415 global $conf, $langs, $user;
1420 if (isset($this->
statut)) {
1421 if ($this->
statut == $status) {
1424 } elseif (isset($this->
status) && $this->
status == $status) {
1431 $sql =
"UPDATE ".$this->db->prefix().
"user";
1432 $sql .=
" SET statut = ".((int) $status);
1433 $sql .=
" WHERE rowid = ".((int) $this->
id);
1434 $result = $this->db->query($sql);
1436 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1439 $this->context[
'actionmsg'] =
'User '.$this->login.
' disabled';
1441 $this->context[
'actionmsg'] =
'User '.$this->login.
' enabled';
1444 $result = $this->
call_trigger(
'USER_ENABLEDISABLE', $user);
1452 $this->db->rollback();
1457 $this->db->commit();
1474 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1475 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1486 global $conf, $langs;
1492 $this->
fetch($this->
id);
1494 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1497 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1499 if (!$error && !$this->db->query($sql)) {
1501 $this->
error = $this->db->lasterror();
1505 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1506 if (!$error && !$this->db->query($sql)) {
1508 $this->
error = $this->db->lasterror();
1512 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1513 if (!$error && !$this->db->query($sql)) {
1515 $this->
error = $this->db->lasterror();
1519 if ($this->contact_id > 0) {
1520 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1521 if (!$error && !$this->db->query($sql)) {
1523 $this->
error = $this->db->lasterror();
1532 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1538 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1539 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1540 if (!$this->db->query($sql)) {
1542 $this->
error = $this->db->lasterror();
1551 $this->db->rollback();
1556 $this->db->commit();
1559 $this->db->rollback();
1571 public function create($user, $notrigger = 0)
1573 global $conf, $langs;
1579 $this->civility_code = trim((
string) $this->civility_code);
1580 $this->login = trim((
string) $this->login);
1581 if (!isset($this->entity)) {
1582 $this->entity = $conf->entity;
1585 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1587 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1591 $langs->load(
"errors");
1592 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1595 if (empty($this->login)) {
1596 $langs->load(
"errors");
1597 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1599 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1600 $langs->load(
"errors");
1601 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1612 $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).
"'";
1613 $resqltochecklogin = $this->db->query($sqltochecklogin);
1614 if ($resqltochecklogin) {
1615 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1616 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1617 $langs->load(
"errors");
1618 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1620 $this->db->rollback();
1623 $this->db->free($resqltochecklogin);
1626 if (!empty($this->email)) {
1627 $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).
"'";
1628 $resqltochecklogin = $this->db->query($sqltochecklogin);
1629 if ($resqltochecklogin) {
1630 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1631 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1632 $langs->load(
"errors");
1633 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
1635 $this->db->rollback();
1638 $this->db->free($resqltochecklogin);
1643 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, entity)";
1644 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->db->escape($this->login).
"', '".$this->db->escape($this->ldap_sid).
"', ".((int) $this->entity).
")";
1645 $result = $this->db->query($sql);
1647 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1649 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1653 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1654 $this->db->rollback();
1659 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1660 $langs->load(
"stocks");
1662 $entrepot =
new Entrepot($this->db);
1663 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1664 $entrepot->libelle = $entrepot->label;
1665 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1666 $entrepot->statut = 1;
1667 $entrepot->country_id = $mysoc->country_id;
1669 $warehouseid = $entrepot->create($user);
1671 $this->fk_warehouse = $warehouseid;
1675 $result = $this->
update($user, 1, 1);
1677 $this->db->rollback();
1691 $this->db->commit();
1696 $this->db->rollback();
1700 $this->
error = $this->db->lasterror();
1701 $this->db->rollback();
1719 global $conf, $user, $langs;
1725 $this->civility_code = $contact->civility_code;
1726 $this->lastname = $contact->lastname;
1727 $this->firstname = $contact->firstname;
1729 $this->email = $contact->email;
1730 $this->socialnetworks = $contact->socialnetworks;
1731 $this->office_phone = $contact->phone_pro;
1732 $this->office_fax = $contact->fax;
1733 $this->user_mobile = $contact->phone_mobile;
1734 $this->address = $contact->address;
1735 $this->zip = $contact->zip;
1736 $this->town = $contact->town;
1738 $this->state_id = $contact->state_id;
1739 $this->country_id = $contact->country_id;
1740 $this->employee = 0;
1742 if (empty($login)) {
1743 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1744 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1746 $this->login = $login;
1751 $result = $this->
create($user, 1);
1753 $sql =
"UPDATE ".$this->db->prefix().
"user";
1754 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1755 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1756 if ($contact->socid > 0) {
1757 $sql .=
", fk_soc=".((int) $contact->socid);
1759 $sql .=
" WHERE rowid=".((int) $this->
id);
1761 $resql = $this->db->query($sql);
1763 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1765 $this->context[
'createfromcontact'] =
'createfromcontact';
1771 $this->db->rollback();
1776 $this->db->commit();
1779 $this->
error = $this->db->error();
1781 $this->db->rollback();
1786 dol_syslog(get_class($this).
"::create_from_contact - 0");
1788 $this->db->rollback();
1805 global $conf, $user, $langs;
1809 $this->civility_code = $member->civility_id;
1810 $this->lastname = $member->lastname;
1811 $this->firstname = $member->firstname;
1812 $this->gender = $member->gender;
1813 $this->email = $member->email;
1814 $this->fk_member = $member->id;
1815 $this->address = $member->address;
1816 $this->zip = $member->zip;
1817 $this->town = $member->town;
1819 $this->state_id = $member->state_id;
1820 $this->country_id = $member->country_id;
1821 $this->socialnetworks = $member->socialnetworks;
1823 $this->pass = $member->pass;
1824 $this->pass_crypted = $member->pass_indatabase_crypted;
1826 if (empty($login)) {
1827 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1830 $this->login = $login;
1835 $result = $this->
create($user);
1837 if (!empty($this->pass)) {
1838 $newpass = $this->
setPassword($user, $this->pass);
1839 if (is_int($newpass) && $newpass < 0) {
1842 } elseif (!empty($this->pass_crypted)) {
1843 $sql =
"UPDATE ".$this->db->prefix().
"user";
1844 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
1845 $sql .=
" WHERE rowid=".((int) $this->
id);
1847 $resql = $this->db->query($sql);
1853 if ($result > 0 && $member->socid) {
1854 $sql =
"UPDATE ".$this->db->prefix().
"user";
1855 $sql .=
" SET fk_soc=".((int) $member->socid);
1856 $sql .=
" WHERE rowid=".((int) $this->
id);
1858 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
1859 $resql = $this->db->query($sql);
1861 $this->db->commit();
1864 $this->
error = $this->db->lasterror();
1866 $this->db->rollback();
1873 $this->db->commit();
1877 $this->db->rollback();
1895 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
1896 $sql .=
" WHERE bydefault = 1";
1897 $sql .=
" AND entity = ".((int) $conf->entity);
1899 $resql = $this->db->query($sql);
1901 $num = $this->db->num_rows($resql);
1904 $row = $this->db->fetch_row($resql);
1908 $this->db->free($resql);
1912 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
1913 $result = $this->db->query($sql);
1915 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
1916 $result = $this->db->query($sql);
1936 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
1938 global $conf, $langs;
1940 $nbrowsaffected = 0;
1943 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
1946 $this->civility_code = trim((
string) $this->civility_code);
1947 $this->lastname = trim((
string) $this->lastname);
1948 $this->firstname = trim((
string) $this->firstname);
1949 $this->ref_employee = trim((
string) $this->ref_employee);
1950 $this->national_registration_number = trim((
string) $this->national_registration_number);
1951 $this->employee = ($this->employee > 0 ? $this->employee : 0);
1952 $this->login = trim((
string) $this->login);
1953 $this->gender = trim((
string) $this->gender);
1955 $this->pass = trim((
string) $this->pass);
1956 $this->api_key = trim((
string) $this->api_key);
1957 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
1958 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
1960 $this->address = trim((
string) $this->address);
1961 $this->zip = trim((
string) $this->zip);
1962 $this->town = trim((
string) $this->town);
1964 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
1965 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
1966 $this->office_phone = trim((
string) $this->office_phone);
1967 $this->office_fax = trim((
string) $this->office_fax);
1968 $this->user_mobile = trim((
string) $this->user_mobile);
1969 $this->personal_mobile = trim((
string) $this->personal_mobile);
1970 $this->email = trim((
string) $this->email);
1971 $this->personal_email = trim((
string) $this->personal_email);
1973 $this->job = trim((
string) $this->job);
1974 $this->signature = trim((
string) $this->signature);
1975 $this->note_public = trim((
string) $this->note_public);
1976 $this->note_private = trim((
string) $this->note_private);
1977 $this->openid = trim((
string) $this->openid);
1978 $this->admin = ($this->admin > 0 ? $this->admin : 0);
1980 $this->accountancy_code = trim((
string) $this->accountancy_code);
1981 $this->color = trim((
string) $this->color);
1982 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
1983 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
1985 $this->birth = empty($this->birth) ?
'' : $this->birth;
1986 $this->fk_warehouse = (int) $this->fk_warehouse;
1991 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1994 $langs->load(
"errors");
1995 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1998 if (empty($this->login)) {
1999 $langs->load(
"errors");
2000 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
2002 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
2003 $langs->load(
"errors");
2004 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
2011 if (!empty($this->oldcopy) && $this->oldcopy->login != $this->login) {
2012 $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).
"'";
2013 $resqltochecklogin = $this->db->query($sqltochecklogin);
2014 if ($resqltochecklogin) {
2015 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2016 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2017 $langs->load(
"errors");
2018 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
2020 $this->db->rollback();
2025 if (!empty($this->oldcopy) && !empty($this->email) && $this->oldcopy->email != $this->email) {
2026 $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).
"'";
2027 $resqltochecklogin = $this->db->query($sqltochecklogin);
2028 if ($resqltochecklogin) {
2029 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2030 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2031 $langs->load(
"errors");
2032 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
2034 $this->db->rollback();
2041 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2042 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
2043 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
2044 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
2045 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
2046 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
2047 $sql .=
", employee = ".(int) $this->employee;
2048 $sql .=
", login = '".$this->db->escape($this->login).
"'";
2049 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
2050 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
2051 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
2052 if (!empty($user->admin)) {
2053 $sql .=
", admin = ".(int) $this->admin;
2055 $sql .=
", address = '".$this->db->escape($this->address).
"'";
2056 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
2057 $sql .=
", town = '".$this->db->escape($this->town).
"'";
2058 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".$this->db->escape($this->state_id).
"'" :
"null");
2059 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".$this->db->escape($this->country_id).
"'" :
"null");
2060 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
2061 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
2062 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
2063 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
2064 $sql .=
", email = '".$this->db->escape($this->email).
"'";
2065 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
2066 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
2067 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2068 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2069 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2070 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2071 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2072 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2073 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2074 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2075 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2076 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2077 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2078 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2079 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".$this->db->escape($this->fk_user).
"'" :
"null");
2080 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".$this->db->escape($this->fk_user_expense_validator).
"'" :
"null");
2081 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".$this->db->escape($this->fk_user_holiday_validator).
"'" :
"null");
2082 if (isset($this->thm) || $this->thm !=
'') {
2083 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2085 if (isset($this->tjm) || $this->tjm !=
'') {
2086 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2088 if (isset($this->salary) || $this->salary !=
'') {
2089 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2091 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2092 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2094 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2095 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2096 $sql .=
", entity = ".((int) $this->entity);
2098 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2099 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2100 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2101 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2102 $sql .=
" WHERE rowid = ".((int) $this->
id);
2104 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2105 $resql = $this->db->query($sql);
2107 $nbrowsaffected += $this->db->affected_rows($resql);
2110 if (!empty($this->pass)) {
2111 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2113 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2114 if (is_int($result) && $result < 0) {
2121 if ($this->fk_member > 0) {
2122 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2123 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2124 $resql = $this->db->query($sql);
2126 $this->
error = $this->db->error();
2127 $this->db->rollback();
2132 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2133 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2134 $resql = $this->db->query($sql);
2136 $this->
error = $this->db->error();
2137 $this->db->rollback();
2141 if ($nbrowsaffected) {
2142 if ($this->fk_member > 0 && !$nosyncmember) {
2143 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2145 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2150 $result = $adh->fetch($this->fk_member);
2153 $adh->civility_code = $this->civility_code;
2154 $adh->firstname = $this->firstname;
2155 $adh->lastname = $this->lastname;
2156 $adh->login = $this->login;
2157 $adh->gender = $this->gender;
2158 $adh->birth = $this->birth;
2160 $adh->pass = $this->pass;
2162 $adh->address = $this->address;
2163 $adh->town = $this->town;
2164 $adh->zip = $this->zip;
2165 $adh->state_id = $this->state_id;
2166 $adh->country_id = $this->country_id;
2168 $adh->email = $this->email;
2170 $adh->socialnetworks = $this->socialnetworks;
2172 $adh->phone = $this->office_phone;
2173 $adh->phone_mobile = $this->user_mobile;
2175 $adh->default_lang = $this->lang;
2177 $adh->user_id = $this->id;
2178 $adh->user_login = $this->login;
2180 $result = $adh->update($user, 0, 1, 0);
2182 $this->
error = $adh->error;
2183 $this->errors = $adh->errors;
2184 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2187 } elseif ($result < 0) {
2188 $this->
error = $adh->error;
2189 $this->errors = $adh->errors;
2194 if ($this->contact_id > 0 && !$nosynccontact) {
2195 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2197 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2200 $tmpobj =
new Contact($this->db);
2201 $result = $tmpobj->fetch($this->contact_id);
2204 $tmpobj->civility_code = $this->civility_code;
2205 $tmpobj->firstname = $this->firstname;
2206 $tmpobj->lastname = $this->lastname;
2207 $tmpobj->login = $this->login;
2208 $tmpobj->gender = $this->gender;
2209 $tmpobj->birth = $this->birth;
2213 $tmpobj->email = $this->email;
2215 $tmpobj->socialnetworks = $this->socialnetworks;
2217 $tmpobj->phone_pro = $this->office_phone;
2218 $tmpobj->phone_mobile = $this->user_mobile;
2219 $tmpobj->fax = $this->office_fax;
2221 $tmpobj->default_lang = $this->lang;
2223 $tmpobj->address = $this->address;
2224 $tmpobj->town = $this->town;
2225 $tmpobj->zip = $this->zip;
2226 $tmpobj->state_id = $this->state_id;
2227 $tmpobj->country_id = $this->country_id;
2229 $tmpobj->user_id = $this->id;
2230 $tmpobj->user_login = $this->login;
2232 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2234 $this->
error = $tmpobj->error;
2235 $this->errors = $tmpobj->errors;
2236 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2240 $this->
error = $tmpobj->error;
2241 $this->errors = $tmpobj->errors;
2257 if (!$error && !$notrigger) {
2267 $this->db->commit();
2268 return $nbrowsaffected;
2271 $this->db->rollback();
2275 $this->
error = $this->db->lasterror();
2276 $this->db->rollback();
2295 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2296 $sql .=
" datepreviouslogin = datelastlogin,";
2297 $sql .=
" ippreviouslogin = iplastlogin,";
2298 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2299 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2300 $sql .=
" tms = tms";
2301 $sql .=
" WHERE rowid = ".((int) $this->
id);
2303 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2304 $resql = $this->db->query($sql);
2306 $this->datepreviouslogin = $this->datelastlogin;
2307 $this->datelastlogin = $now;
2308 $this->ippreviouslogin = $this->iplastlogin;
2309 $this->iplastlogin = $userremoteip;
2312 $this->
error = $this->db->lasterror().
' sql='.$sql;
2330 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2332 global $conf, $langs;
2333 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2337 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2345 if (empty($passwordalreadycrypted)) {
2348 $modGeneratePassClass =
'modGeneratePass'.ucfirst($conf->global->USER_PASSWORD_GENERATED);
2350 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2351 if (class_exists($modGeneratePassClass)) {
2352 $modGeneratePass =
new $modGeneratePassClass($this->db, $conf, $langs, $user);
2355 $modGeneratePass->WithoutAmbi = 0;
2358 $testpassword = $modGeneratePass->validatePassword($password);
2359 if (!$testpassword) {
2360 $this->
error = $modGeneratePass->error;
2368 $password_crypted =
dol_hash($password);
2372 if (!$changelater) {
2373 if (!is_object($this->oldcopy)) {
2374 $this->oldcopy = clone $this;
2379 $sql =
"UPDATE ".$this->db->prefix().
"user";
2380 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2381 $sql .=
" pass_temp = null";
2382 if (!empty($flagdelsessionsbefore)) {
2383 $sql .=
", flagdelsessionsbefore = '".$this->db->idate(
dol_now() - 5,
'gmt').
"'";
2386 $sql .=
", pass = null";
2388 $sql .=
", pass = '".$this->db->escape($password).
"'";
2390 $sql .=
" WHERE rowid = ".((int) $this->
id);
2392 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2393 $result = $this->db->query($sql);
2395 if ($this->db->affected_rows($result)) {
2396 $this->pass = $password;
2397 $this->pass_indatabase = $password;
2398 $this->pass_indatabase_crypted = $password_crypted;
2400 if ($this->fk_member && !$nosyncmember) {
2401 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2406 $result = $adh->fetch($this->fk_member);
2409 $result = $adh->setPassword($user, $this->pass, (!
getDolGlobalString(
'DATABASE_PWD_ENCRYPTED') ? 0 : 1), 1);
2410 if (is_int($result) && $result < 0) {
2411 $this->
error = $adh->error;
2416 $this->
error = $adh->error;
2421 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2423 if (!$error && !$notrigger) {
2425 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2428 $this->db->rollback();
2434 $this->db->commit();
2437 $this->db->rollback();
2441 $this->db->rollback();
2448 $sql =
"UPDATE ".$this->db->prefix().
"user";
2449 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2450 $sql .=
" WHERE rowid = ".((int) $this->
id);
2452 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2453 $result = $this->db->query($sql);
2475 global $conf, $langs, $mysoc;
2476 global $dolibarr_main_url_root;
2478 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2485 $outputlangs =
new Translate(
"", $conf);
2487 if (isset($this->
conf->MAIN_LANG_DEFAULT)
2488 && $this->conf->MAIN_LANG_DEFAULT !=
'auto') {
2489 $outputlangs->getDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2492 if ($this->
conf->MAIN_LANG_DEFAULT) {
2493 $outputlangs->setDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2495 $outputlangs = $langs;
2499 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2501 $appli =
getDolGlobalString(
'MAIN_APPLICATION_TITLE', constant(
'DOL_APPLICATION_TITLE'));
2503 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2506 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2507 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2509 if (!$changelater) {
2510 $url = $urlwithroot.
'/';
2512 $url = $conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD;
2515 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2517 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2518 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2519 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2520 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2523 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2525 $mesg .= $user->getFullName($outputlangs);
2528 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2529 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.$conf->file->instance_unique_id));
2530 if (isModEnabled(
'multicompany')) {
2531 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2534 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2538 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2539 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2540 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2541 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2543 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2544 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2545 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2548 $trackid =
'use'.$this->id;
2549 $sendcontext =
'password';
2554 $conf->global->MAIN_MAIL_EMAIL_FROM,
2570 if ($mailfile->sendfile()) {
2573 $langs->trans(
"errors");
2574 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2586 return $this->error;
2599 $sql =
"SELECT url, login, pass, poste ";
2600 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2601 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2603 $resql = $this->db->query($sql);
2605 if ($this->db->num_rows($resql)) {
2606 $obj = $this->db->fetch_object($resql);
2608 $this->clicktodial_url = $obj->url;
2609 $this->clicktodial_login = $obj->login;
2610 $this->clicktodial_password = $obj->pass;
2611 $this->clicktodial_poste = $obj->poste;
2614 $this->clicktodial_loaded = 1;
2616 $this->db->free($resql);
2619 $this->
error = $this->db->error();
2635 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2636 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2638 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2639 $result = $this->db->query($sql);
2641 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2642 $sql .=
" (fk_user,url,login,pass,poste)";
2643 $sql .=
" VALUES (".$this->id;
2644 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2645 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2646 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2647 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2649 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2650 $result = $this->db->query($sql);
2652 $this->db->commit();
2655 $this->db->rollback();
2656 $this->
error = $this->db->lasterror();
2674 global $conf, $langs, $user;
2680 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2681 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2682 $sql .=
" AND fk_usergroup = ".((int) $group);
2683 $sql .=
" AND entity = ".((int) $entity);
2685 $result = $this->db->query($sql);
2687 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2688 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2690 $result = $this->db->query($sql);
2692 if (!$error && !$notrigger) {
2693 $this->context = array(
'audit'=>$langs->trans(
"UserSetInGroup"),
'newgroupid'=>$group);
2704 $this->db->commit();
2708 $this->db->rollback();
2712 $this->
error = $this->db->lasterror();
2713 $this->db->rollback();
2730 global $conf, $langs, $user;
2736 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2737 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2738 $sql .=
" AND fk_usergroup = ".((int) $group);
2739 if (empty($entity)) {
2740 $sql .=
" AND entity IN (0, 1)";
2742 $sql .=
" AND entity = ".((int) $entity);
2745 $result = $this->db->query($sql);
2747 if (!$error && !$notrigger) {
2748 $this->context = array(
'audit'=>$langs->trans(
"UserRemovedFromGroup"),
'oldgroupid'=>$group);
2759 $this->db->commit();
2762 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2763 $this->db->rollback();
2767 $this->
error = $this->db->lasterror();
2768 $this->db->rollback();
2782 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2789 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
2811 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
2813 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2814 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
2829 global $conf, $langs, $menumanager;
2830 global $dolibarr_main_demo;
2832 $infologin = $params[
'infologin'] ?? 0;
2833 $option = $params[
'option'] ??
'';
2836 if (!empty($this->photo)) {
2837 $photo =
'<div class="photointooltip floatright">';
2838 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
2840 $datas[
'photo'] = $photo;
2845 $datas[
'opendiv'] =
'<div class="centpercent divtooltip">';
2846 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
2848 if (!empty($this->login)) {
2849 $datas[
'login'] =
'<br><b>'.$langs->trans(
'Login').
':</b> '.
dol_string_nohtmltag($this->login);
2851 if (!empty($this->job)) {
2854 $datas[
'email'] =
'<br><b>'.$langs->trans(
"Email").
':</b> '.
dol_string_nohtmltag($this->email);
2855 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
2856 $phonelist = array();
2857 if ($this->office_phone) {
2858 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2860 if ($this->office_fax) {
2861 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2863 if ($this->user_mobile) {
2864 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
2866 $datas[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
2868 if (!empty($this->admin)) {
2869 $datas[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
2871 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
2872 $langs->load(
"companies");
2873 $datas[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
2876 if (!empty($this->socid)) {
2877 $thirdpartystatic =
new Societe($this->db);
2878 $thirdpartystatic->fetch($this->socid);
2880 if (empty($params[
'hidethirdpartylogo'])) {
2881 $companyimg =
' '.$thirdpartystatic->getNomUrl(2, (($option ==
'nolink') ?
'nolink' :
''));
2883 $company =
' ('.$langs->trans(
"Company").
': '.($companyimg ? $companyimg :
img_picto(
'',
'company')).
' '.
dol_string_nohtmltag($thirdpartystatic->name).
')';
2885 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
2886 $datas[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
2887 $datas[
'closediv'] =
'</div>';
2889 if ($infologin > 0) {
2890 $datas[
'newlinelogin'] =
'<br>';
2891 $datas[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
2894 $datas[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.$conf->entity.
' (User entity '.$this->entity.
')';
2896 $datas[
'authentication'] =
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
2897 $datas[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
2898 $datas[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
2899 $datas[
'currenttheme'] =
'<br><b>'.$langs->trans(
"CurrentTheme").
':</b> '.
dol_string_nohtmltag($conf->theme);
2900 $datas[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
2902 $datas[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
2903 $datas[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag($conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
2904 $datas[
'layout'] =
'<br><b>'.$langs->trans(
"Layout").
':</b> '.
dol_string_nohtmltag($conf->browser->layout);
2905 $datas[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
2906 if ($conf->browser->layout ==
'phone') {
2907 $datas[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
2909 if (!empty($_SESSION[
"disablemodules"])) {
2910 $datas[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(join(
', ', explode(
',', $_SESSION[
"disablemodules"])));
2932 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
2934 global $langs, $conf, $db, $hookmanager, $user;
2935 global $dolibarr_main_authentication, $dolibarr_main_demo;
2937 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
2948 'objecttype' => $this->element,
2949 'infologin' => $infologin,
2950 'option' => $option,
2952 $classfortooltip =
'classfortooltip';
2955 $classfortooltip =
'classforajaxtooltip';
2956 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
2963 if (!empty($this->socid)) {
2964 $thirdpartystatic =
new Societe($this->db);
2965 $thirdpartystatic->fetch($this->socid);
2966 if (empty($hidethirdpartylogo)) {
2967 $companylink =
' '.$thirdpartystatic->getNomUrl(2, (($option ==
'nolink') ?
'nolink' :
''));
2971 if ($infologin < 0) {
2975 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
2976 if ($option ==
'leave') {
2977 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
2980 if ($option !=
'nolink') {
2982 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2983 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2984 $add_save_lastsearch_values = 1;
2986 if ($add_save_lastsearch_values) {
2987 $url .=
'&save_lastsearch_values=1';
2991 $linkstart =
'<a href="'.$url.
'"';
2993 if (empty($notooltip)) {
2995 $langs->load(
"users");
2996 $label = $langs->trans(
"ShowUser");
2997 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2999 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
3000 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
3002 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
3005 $linkstart .= $linkclose.
'>';
3009 $result .= (($option ==
'nolink') ?
'' : $linkstart);
3010 if ($withpictoimg) {
3011 $paddafterimage =
'';
3012 if (abs((
int) $withpictoimg) == 1) {
3013 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3016 if ($withpictoimg > 0) {
3017 $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>';
3020 $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>';
3024 if ($withpictoimg > -2 && $withpictoimg != 2) {
3026 $result .=
'<span class="nopadding usertext'.((!isset($this->
status) || $this->status) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
3028 if ($mode ==
'login') {
3034 $result .=
'</span>';
3037 $result .= (($option ==
'nolink') ?
'' : $linkend);
3040 $result .= $companylink;
3043 $hookmanager->initHooks(array(
'userdao'));
3044 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
3045 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3047 $result = $hookmanager->resPrint;
3049 $result .= $hookmanager->resPrint;
3064 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
3066 global $langs, $user;
3070 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3074 if ((!$user->hasRight(
'user',
'user',
'lire') && $this->id != $user->id)) {
3078 if ($option ==
'xxx') {
3079 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3083 if ($option ==
'nolink') {
3088 $result .= $linkstart;
3089 if ($withpictoimg) {
3090 $paddafterimage =
'';
3091 if (abs($withpictoimg) == 1) {
3092 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3095 if ($withpictoimg > 0) {
3096 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3099 $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>';
3103 $result .= $this->login;
3104 $result .= $linkend;
3133 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3136 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3137 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3138 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3139 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3142 $statusType =
'status5';
3143 if ($status == self::STATUS_ENABLED) {
3144 $statusType =
'status4';
3147 $label = $this->labelStatus[$status];
3148 $labelshort = $this->labelStatusShort[$status];
3151 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3152 $statusType =
'status3';
3153 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3155 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3156 $statusType =
'status2';
3157 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3160 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3175 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3177 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3178 $return .=
'<div class="info-box info-box-sm">';
3179 $return .=
'<span class="info-box-icon bg-infobox-action">';
3182 if (!empty($this->photo)) {
3184 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3193 $return .=
'</span>';
3194 $return .=
'<div class="info-box-content">';
3195 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3196 if (isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3197 $return .=
img_picto($langs->trans(
"SuperAdministratorDesc"),
'redstar',
'class="valignmiddle paddingright paddingleft"');
3198 } elseif ($this->admin) {
3199 $return .=
img_picto($langs->trans(
"AdministratorDesc"),
'star',
'class="valignmiddle paddingright paddingleft"');
3201 $return .=
'</span>';
3202 if ($selected >= 0) {
3203 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3205 if (property_exists($this,
'label')) {
3206 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3209 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->email.
'</span>';
3211 if (method_exists($this,
'getLibStatut')) {
3212 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3214 $return .=
'</div>';
3215 $return .=
'</div>';
3216 $return .=
'</div>';
3240 } elseif ($mode == 1) {
3241 $dn = $conf->global->LDAP_USER_DN;
3242 } elseif ($mode == 2) {
3258 global $conf, $langs;
3264 $keymodified =
false;
3273 'LDAP_FIELD_FULLNAME' =>
'fullname',
3274 'LDAP_FIELD_NAME' =>
'lastname',
3275 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3276 'LDAP_FIELD_LOGIN' =>
'login',
3277 'LDAP_FIELD_LOGIN_SAMBA'=>
'login',
3278 'LDAP_FIELD_PHONE' =>
'office_phone',
3279 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3280 'LDAP_FIELD_FAX' =>
'office_fax',
3281 'LDAP_FIELD_MAIL' =>
'email',
3282 'LDAP_FIELD_SID' =>
'ldap_sid',
3286 foreach ($ldapkey as $constname => $varname) {
3292 if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
3293 $keymodified =
true;
3298 foreach ($socialnetworks as $key => $value) {
3299 if (!empty($this->socialnetworks[$value[
'label']]) &&
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))) {
3300 $info[
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))] = $this->socialnetworks[$value[
'label']];
3315 if ($this->socid > 0) {
3316 $soc =
new Societe($this->db);
3317 $soc->fetch($this->socid);
3320 if ($soc->client == 1) {
3321 $info[
"businessCategory"] =
"Customers";
3323 if ($soc->client == 2) {
3324 $info[
"businessCategory"] =
"Prospects";
3326 if ($soc->fournisseur == 1) {
3327 $info[
"businessCategory"] =
"Suppliers";
3332 if (!empty($this->pass)) {
3345 if ($this->pass_indatabase_crypted &&
getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED')) {
3349 } elseif (!empty($this->pass_indatabase)) {
3361 $info[
"objectclass"][4] =
"phpgwContact";
3363 $info[
'uidnumber'] = $this->id;
3365 $info[
'phpgwTz'] = 0;
3366 $info[
'phpgwMailType'] =
'INTERNET';
3367 $info[
'phpgwMailHomeType'] =
'INTERNET';
3369 $info[
"phpgwContactTypeId"] =
'n';
3370 $info[
"phpgwContactCatId"] = 0;
3371 $info[
"phpgwContactAccess"] =
"public";
3374 $this->egroupware_id = 1;
3377 $info[
"phpgwContactOwner"] = $this->egroupware_id;
3380 $info[
"rfc822Mailbox"] = $this->email;
3382 if ($this->user_mobile) {
3383 $info[
"phpgwCellTelephoneNumber"] = $this->user_mobile;
3392 $groupslist = $usergroup->listGroupsForUser($this->
id);
3394 if (!empty($groupslist)) {
3395 foreach ($groupslist as $groupforuser) {
3402 $info[
getDolGlobalString(
'LDAP_FIELD_HOMEDIRECTORY')] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->login";
3418 global $user, $langs;
3424 $this->
ref =
'SPECIMEN';
3425 $this->specimen = 1;
3427 $this->lastname =
'DOLIBARR';
3428 $this->firstname =
'SPECIMEN';
3429 $this->gender =
'man';
3430 $this->note_public =
'This is a note public';
3431 $this->note_private =
'This is a note private';
3432 $this->email =
'email@specimen.com';
3433 $this->personal_email =
'personalemail@specimen.com';
3434 $this->socialnetworks = array(
3435 'skype' =>
'skypepseudo',
3436 'twitter' =>
'twitterpseudo',
3437 'facebook' =>
'facebookpseudo',
3438 'linkedin' =>
'linkedinpseudo',
3440 $this->office_phone =
'0999999999';
3441 $this->office_fax =
'0999999998';
3442 $this->user_mobile =
'0999999997';
3443 $this->personal_mobile =
'0999999996';
3445 $this->login =
'dolibspec';
3446 $this->pass =
'dolibSpec+@123';
3449 $this->datec = $now;
3450 $this->datem = $now;
3452 $this->datelastlogin = $now;
3453 $this->iplastlogin =
'127.0.0.1';
3454 $this->datepreviouslogin = $now;
3455 $this->ippreviouslogin =
'127.0.0.1';
3471 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
3472 $sql .=
" u.tms as date_modification, u.entity";
3473 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3474 $sql .=
" WHERE u.rowid = ".((int) $id);
3476 $result = $this->db->query($sql);
3478 if ($this->db->num_rows($result)) {
3479 $obj = $this->db->fetch_object($result);
3481 $this->
id = $obj->rowid;
3483 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3484 $this->date_creation = $this->db->jdate($obj->datec);
3485 $this->date_modification = $this->db->jdate($obj->date_modification);
3486 $this->entity = $obj->entity;
3489 $this->db->free($result);
3503 $sql =
"SELECT count(mc.email) as nb";
3504 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3505 $sql .=
" WHERE mc.email = '".$this->db->escape($this->email).
"'";
3506 $sql .=
" AND mc.statut NOT IN (-1,0)";
3508 $resql = $this->db->query($sql);
3510 $obj = $this->db->fetch_object($resql);
3513 $this->db->free($resql);
3516 $this->
error = $this->db->error();
3533 $sql =
"SELECT count(rowid) as nb";
3534 $sql .=
" FROM ".$this->db->prefix().
"user";
3535 if ($option ==
'superadmin') {
3536 $sql .=
" WHERE entity = 0";
3538 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3539 if ($limitTo ==
'active') {
3540 $sql .=
" AND statut = 1";
3544 $sql .=
" AND admin = ".(int) $admin;
3547 $resql = $this->db->query($sql);
3549 $obj = $this->db->fetch_object($resql);
3550 $nb = (int) $obj->nb;
3552 $this->db->free($resql);
3555 $this->
error = $this->db->lasterror();
3571 global $user, $conf;
3576 $this->firstname = $ldapuser->$tmpvar;
3578 $this->lastname = $ldapuser->$tmpvar;
3580 $this->login = $ldapuser->$tmpvar;
3582 $this->pass = $ldapuser->$tmpvar;
3584 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3587 $this->office_phone = $ldapuser->$tmpvar;
3589 $this->user_mobile = $ldapuser->$tmpvar;
3591 $this->office_fax = $ldapuser->$tmpvar;
3593 $this->email = $ldapuser->$tmpvar;
3594 foreach ($socialnetworks as $key => $value) {
3596 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3599 $this->ldap_sid = $ldapuser->$tmpvar;
3602 $this->job = $ldapuser->$tmpvar;
3604 $this->note_public = $ldapuser->$tmpvar;
3606 $result = $this->
update($user);
3608 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3624 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3625 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3627 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3628 $res = $this->db->query($sql);
3631 while ($rec = $this->db->fetch_array($res)) {
3632 $user =
new User($this->db);
3633 $user->fetch($rec[
'rowid']);
3653 $this->parentof = array();
3656 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3657 $sql .=
" FROM ".$this->db->prefix().
"user";
3658 $sql .=
" WHERE fk_user <> 0";
3659 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3661 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3662 $resql = $this->db->query($sql);
3664 while ($obj = $this->db->fetch_object($resql)) {
3665 $this->parentof[$obj->id_son] = $obj->id_parent;
3691 global $conf, $user;
3692 global $hookmanager;
3695 $hookmanager->initHooks(array(
'userdao'));
3697 $this->users = array();
3703 $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";
3704 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3706 $parameters = array();
3707 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3709 $sql .= $hookmanager->resPrint;
3711 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3714 $sql .=
" AND ".$filter;
3717 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3718 $resql = $this->db->query($sql);
3721 while ($obj = $this->db->fetch_object($resql)) {
3722 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3723 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3724 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3725 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3726 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3727 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3728 $this->users[$obj->rowid][
'login'] = $obj->login;
3729 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3730 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3731 $this->users[$obj->rowid][
'email'] = $obj->email;
3732 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3733 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3734 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3743 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3744 foreach ($this->users as $key => $val) {
3747 $this->
error =
'ErrorLoopInHierarchy';
3753 if ($deleteafterid) {
3755 $keyfilter1 =
'^'.$deleteafterid.
'$';
3756 $keyfilter2 =
'_'.$deleteafterid.
'$';
3757 $keyfilter3 =
'^'.$deleteafterid.
'_';
3758 $keyfilter4 =
'_'.$deleteafterid.
'_';
3759 foreach ($this->users as $key => $val) {
3760 if (preg_match(
'/'.$keyfilter1.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter2.
'/', $val[
'fullpath'])
3761 || preg_match(
'/'.$keyfilter3.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter4.
'/', $val[
'fullpath'])) {
3762 unset($this->users[$key]);
3767 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
3768 $this->users =
dol_sort_array($this->users,
'fullname',
'asc',
true,
false, 1);
3772 return $this->users;
3785 $childids = array();
3787 if (isset($this->cache_childids[$this->
id])) {
3788 $childids = $this->cache_childids[$this->id];
3793 $idtoscan = $this->id;
3795 dol_syslog(
"Build childid for id = ".$idtoscan);
3796 foreach ($this->users as $id => $val) {
3798 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
3799 $childids[$val[
'id']] = $val[
'id'];
3803 $this->cache_childids[$this->id] = $childids;
3805 if ($addcurrentuser) {
3806 $childids[$this->id] = $this->id;
3826 if (!empty($this->users[$id_user][
'fullpath'])) {
3828 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
3833 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
3834 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
3836 $cursor_user = $id_user;
3838 $useridfound = array($id_user);
3839 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
3840 if (in_array($this->parentof[$cursor_user], $useridfound)) {
3841 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
3844 $useridfound[] = $this->parentof[$cursor_user];
3845 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
3846 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
3848 $cursor_user = $this->parentof[$cursor_user];
3852 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
3886 $this->nb = array();
3888 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
3889 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3890 if (isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE')) {
3891 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
3892 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
3893 $sql .=
" AND ug.fk_user = u.rowid";
3895 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3897 $sql .=
" AND u.statut > 0";
3900 $resql = $this->db->query($sql);
3902 while ($obj = $this->db->fetch_object($resql)) {
3903 $this->nb[
"users"] = $obj->nb;
3905 $this->db->free($resql);
3909 $this->
error = $this->db->error();
3925 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3927 global $conf, $user, $langs;
3929 $langs->load(
"user");
3934 $modele = $conf->global->USER_ADDON_PDF;
3936 $modele =
'bluesky';
3940 $modelpath =
"core/modules/user/doc/";
3942 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3956 $user_property =
'';
3958 if (empty($rowid)) {
3962 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
3963 $sql .=
" FROM ".$this->db->prefix().
"user";
3964 $sql .=
" WHERE rowid = ".((int) $rowid);
3966 $resql = $this->db->query($sql);
3968 $nump = $this->db->num_rows($resql);
3971 $obj = $this->db->fetch_object($resql);
3973 if ($mode ==
'email') {
3974 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
3975 } elseif ($mode ==
'mobile') {
3976 $user_property = $obj->user_mobile;
3977 } elseif ($mode ==
'name') {
3981 return $user_property;
3998 global $dolibarr_main_url_root;
4001 $encodedsecurekey =
dol_hash($conf->file->instance_unique_id.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
4002 if (isModEnabled(
'multicompany')) {
4003 $entity_qr =
'&entity='.((int) $conf->entity);
4008 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
4009 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
4012 if ($typeofurl ==
'internal') {
4013 $urlwithroot = DOL_URL_ROOT;
4016 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
4031 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter = array(), $filtermode =
'AND', $entityfilter =
false)
4033 global $conf, $user;
4035 $sql =
"SELECT t.rowid";
4036 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
4038 if ($entityfilter) {
4040 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
4041 $sql .=
" WHERE t.entity IS NOT NULL";
4043 $sql .=
",".$this->db->prefix().
"usergroup_user as ug";
4044 $sql .=
" WHERE ((ug.fk_user = t.rowid";
4045 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
4046 $sql .=
" OR t.entity = 0)";
4049 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
4052 $sql .=
" WHERE 1 = 1";
4056 $sqlwhere = array();
4057 if (!empty($filter)) {
4058 foreach ($filter as $key => $value) {
4059 if ($key ==
't.rowid') {
4060 $sqlwhere[] = $key.
" = ".((int) $value);
4061 } elseif (array_key_exists($key, $this->fields) && isset($this->fields[$key][
'type']) && in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
4062 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
4063 } elseif ($key ==
'customsql') {
4064 $sqlwhere[] = $value;
4066 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
4070 if (count($sqlwhere) > 0) {
4071 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
4073 $sql .= $this->db->order($sortfield, $sortorder);
4075 $sql .= $this->db->plimit($limit + 1, $offset);
4080 $resql = $this->db->query($sql);
4082 $this->users = array();
4083 $num = $this->db->num_rows($resql);
4085 while ($obj = $this->db->fetch_object($resql)) {
4086 $line =
new self($this->db);
4087 $result = $line->fetch($obj->rowid);
4088 if ($result > 0 && !empty($line->id)) {
4089 $this->users[$obj->rowid] = clone $line;
4092 $this->db->free($resql);
4096 $this->errors[] = $this->db->lasterror();
4108 private $findUserIdByEmailCache;
4122 if (isset($this->findUserIdByEmailCache[$email])) {
4123 return $this->findUserIdByEmailCache[$email];
4126 $this->findUserIdByEmailCache[$email] = -1;
4130 $sql =
'SELECT rowid';
4131 $sql .=
' FROM '.$this->db->prefix().
'user';
4132 if (
getDolGlobalString(
'AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR')) {
4133 $sql .=
" WHERE email LIKE '%".$this->db->escape($email).
"%'";
4135 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4139 $resql = $this->db->query($sql);
4144 $obj = $this->db->fetch_object($resql);
4149 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4151 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.