38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
51 public $element =
'user';
56 public $table_element =
'user';
61 public $fk_element =
'fk_user';
67 public $ismultientitymanaged = 1;
72 public $picto =
'user';
79 public $civility_code;
96 public $personal_email;
101 public $socialnetworks;
158 public $office_phone;
173 public $personal_mobile;
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;
279 public $datelastlogin;
280 public $datepreviouslogin;
282 public $ippreviouslogin;
283 public $datestartvalidity;
284 public $dateendvalidity;
300 public $all_permissions_are_loaded;
310 public $user_group_list;
315 private $_tab_loaded = array();
322 public $default_values;
324 public $lastsearch_values_tmp;
325 public $lastsearch_values;
327 public $users = array();
329 private $cache_childids;
331 public $accountancy_code;
345 public $dateemployment;
346 public $dateemploymentend;
348 public $default_c_exp_tax_cat;
353 public $ref_employee;
358 public $national_registration_number;
360 public $default_range;
365 public $fk_warehouse;
368 public $fields = array(
369 'rowid'=>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'index'=>1,
'position'=>1,
'comment'=>
'Id'),
370 'lastname'=>array(
'type'=>
'varchar(50)',
'label'=>
'LastName',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>20,
'searchall'=>1),
371 'firstname'=>array(
'type'=>
'varchar(50)',
'label'=>
'FirstName',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>10,
'searchall'=>1),
372 'ref_employee'=>array(
'type'=>
'varchar(50)',
'label'=>
'RefEmployee',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>30,
'searchall'=>1),
373 'national_registration_number'=>array(
'type'=>
'varchar(50)',
'label'=>
'NationalRegistrationNumber',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>40,
'searchall'=>1)
377 const STATUS_DISABLED = 0;
378 const STATUS_ENABLED = 1;
392 $this->liste_limit = 0;
393 $this->clicktodial_loaded = 0;
396 $this->all_permissions_are_loaded = 0;
397 $this->nb_rights = 0;
403 $this->
conf =
new stdClass();
404 $this->rights =
new stdClass();
405 $this->rights->user =
new stdClass();
406 $this->rights->user->user =
new stdClass();
407 $this->rights->user->self =
new stdClass();
408 $this->rights->user->user_advance =
new stdClass();
409 $this->rights->user->self_advance =
new stdClass();
410 $this->rights->user->group_advance =
new stdClass();
426 public function fetch($id =
'', $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'', $fk_socpeople = 0)
431 $login = trim($login);
434 $sql =
"SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.civility as civility_code, u.birth, u.email, u.personal_email, u.job,";
435 $sql .=
" u.socialnetworks,";
436 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
437 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
438 $sql .=
" u.admin, u.login, u.note_private, u.note_public,";
439 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.api_key,";
440 $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,";
441 $sql .=
" u.statut as status, u.lang, u.entity,";
442 $sql .=
" u.datec as datec,";
443 $sql .=
" u.tms as datem,";
444 $sql .=
" u.datelastlogin as datel,";
445 $sql .=
" u.datepreviouslogin as datep,";
446 $sql .=
" u.iplastlogin,";
447 $sql .=
" u.ippreviouslogin,";
448 $sql .=
" u.datelastpassvalidation,";
449 $sql .=
" u.datestartvalidity,";
450 $sql .=
" u.dateendvalidity,";
451 $sql .=
" u.photo as photo,";
452 $sql .=
" u.openid as openid,";
453 $sql .=
" u.accountancy_code,";
456 $sql .=
" u.salary,";
457 $sql .=
" u.salaryextra,";
458 $sql .=
" u.weeklyhours,";
460 $sql .=
" u.dateemployment, u.dateemploymentend,";
461 $sql .=
" u.fk_warehouse,";
462 $sql .=
" u.ref_ext,";
463 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
464 $sql .=
" u.national_registration_number,";
465 $sql .=
" u.ref_employee,";
466 $sql .=
" c.code as country_code, c.label as country,";
467 $sql .=
" d.code_departement as state_code, d.nom as state";
468 $sql .=
" FROM ".$this->db->prefix().
"user as u";
469 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as c ON u.fk_country = c.rowid";
470 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_departements as d ON u.fk_state = d.rowid";
473 if ((!
isModEnabled(
'multicompany') || empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) && (!empty($user->entity))) {
474 $sql .=
" WHERE u.entity IN (0, ".((int) $conf->entity).
")";
476 $sql .=
" WHERE u.entity IS NOT NULL";
480 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
481 $sql .=
" WHERE u.entity IS NOT NULL";
483 $sql .=
" WHERE u.entity IN (0, ".((int) (($entity !=
'' && $entity >= 0) ? $entity : $conf->entity)).
")";
489 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->
db->escape($login).
"')";
491 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
493 $sql .=
" AND u.email = '".$this->db->escape($email).
"'";
494 } elseif ($fk_socpeople > 0) {
495 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
497 $sql .=
" AND u.rowid = ".((int) $id);
499 $sql .=
" ORDER BY u.entity ASC";
503 $sql .=
' '.$this->db->plimit(1);
506 $result = $this->
db->query($sql);
508 $obj = $this->
db->fetch_object($result);
510 $this->
id = $obj->rowid;
511 $this->
ref = $obj->rowid;
513 $this->ref_ext = $obj->ref_ext;
515 $this->ldap_sid = $obj->ldap_sid;
516 $this->civility_code = $obj->civility_code;
517 $this->lastname = $obj->lastname;
518 $this->firstname = $obj->firstname;
519 $this->ref_employee = $obj->ref_employee;
520 $this->national_registration_number = $obj->national_registration_number;
522 $this->employee = $obj->employee;
524 $this->login = $obj->login;
525 $this->gender = $obj->gender;
526 $this->birth = $this->
db->jdate($obj->birth);
527 $this->pass_indatabase = $obj->pass;
528 $this->pass_indatabase_crypted = $obj->pass_crypted;
529 $this->pass = $obj->pass;
530 $this->pass_temp = $obj->pass_temp;
533 $this->address = $obj->address;
534 $this->zip = $obj->zip;
535 $this->town = $obj->town;
537 $this->country_id = $obj->country_id;
538 $this->country_code = $obj->country_id ? $obj->country_code :
'';
541 $this->state_id = $obj->state_id;
542 $this->state_code = $obj->state_code;
543 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
545 $this->office_phone = $obj->office_phone;
546 $this->office_fax = $obj->office_fax;
547 $this->user_mobile = $obj->user_mobile;
548 $this->personal_mobile = $obj->personal_mobile;
549 $this->email = $obj->email;
550 $this->personal_email = $obj->personal_email;
551 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
552 $this->job = $obj->job;
553 $this->signature = $obj->signature;
554 $this->admin = $obj->admin;
555 $this->note_public = $obj->note_public;
556 $this->note_private = $obj->note_private;
557 $this->note = $obj->note_private;
559 $this->statut = $obj->status;
560 $this->status = $obj->status;
562 $this->photo = $obj->photo;
563 $this->openid = $obj->openid;
564 $this->lang = $obj->lang;
565 $this->entity = $obj->entity;
566 $this->accountancy_code = $obj->accountancy_code;
567 $this->thm = $obj->thm;
568 $this->tjm = $obj->tjm;
569 $this->salary = $obj->salary;
570 $this->salaryextra = $obj->salaryextra;
571 $this->weeklyhours = $obj->weeklyhours;
572 $this->color = $obj->color;
573 $this->dateemployment = $this->
db->jdate($obj->dateemployment);
574 $this->dateemploymentend = $this->
db->jdate($obj->dateemploymentend);
576 $this->datec = $this->
db->jdate($obj->datec);
577 $this->datem = $this->
db->jdate($obj->datem);
578 $this->datelastlogin = $this->
db->jdate($obj->datel);
579 $this->datepreviouslogin = $this->
db->jdate($obj->datep);
580 $this->iplastlogin = $obj->iplastlogin;
581 $this->ippreviouslogin = $obj->ippreviouslogin;
582 $this->datestartvalidity = $this->
db->jdate($obj->datestartvalidity);
583 $this->dateendvalidity = $this->
db->jdate($obj->dateendvalidity);
585 $this->socid = $obj->fk_soc;
586 $this->contact_id = $obj->fk_socpeople;
587 $this->fk_member = $obj->fk_member;
588 $this->fk_user = $obj->fk_user;
589 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
590 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
592 $this->default_range = $obj->default_range;
593 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
594 $this->fk_warehouse = $obj->fk_warehouse;
598 if (!
isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
606 $this->
db->free($result);
608 $this->
error =
"USERNOTFOUND";
609 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
611 $this->
db->free($result);
615 $this->
error = $this->
db->lasterror();
620 if ($loadpersonalconf) {
622 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
623 $sql .=
" WHERE fk_user = ".((int) $this->
id);
624 $sql .=
" AND entity = ".((int) $conf->entity);
631 $obj = $this->
db->fetch_object(
$resql);
632 $p = (!empty($obj->param) ? $obj->param :
'');
634 $this->
conf->$p = $obj->value;
640 $this->
error = $this->
db->lasterror();
647 $this->
error = $this->
db->lasterror();
663 if (!empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) {
665 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
668 $result = $defaultValues->fetchAll(
'',
'', 0, 0, array(
't.user_id'=>array(0, $this->
id),
'entity'=>array((isset($this->entity) ? $this->entity : $conf->entity), $conf->entity)));
670 if (!is_array($result) && $result < 0) {
674 } elseif (count($result) > 0) {
675 foreach ($result as $defval) {
676 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
677 $pagewithoutquerystring = $defval->page;
680 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
681 $pagewithoutquerystring = $reg[1];
682 $pagequeries = $reg[2];
684 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
688 if (!empty($this->default_values)) {
689 foreach ($this->default_values as $a => $b) {
690 foreach ($b as $c => $d) {
691 krsort($this->default_values[$a][$c]);
710 public function hasRight($module, $permlevel1, $permlevel2 =
'')
714 $moduletomoduletouse = array(
715 'compta' =>
'comptabilite',
716 'contract' =>
'contrat',
717 'member' =>
'adherent',
719 'order' =>
'commande',
720 'produit' =>
'product',
721 'project' =>
'projet',
722 'propale' =>
'propal',
723 'shipping' =>
'expedition',
724 'task' =>
'task@projet',
725 'fichinter' =>
'ficheinter',
726 'propale' =>
'propal',
727 'inventory' =>
'stock',
728 'invoice' =>
'facture',
729 'invoice_supplier' =>
'fournisseur',
730 'order_supplier' =>
'fournisseur',
731 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
732 'skill@hrm' =>
'all@hrm',
733 'job@hrm' =>
'all@hrm',
734 'position@hrm' =>
'all@hrm',
735 'facturerec' =>
'facture',
736 'margins' =>
'margin',
739 if (!empty($moduletomoduletouse[$module])) {
740 $module = $moduletomoduletouse[$module];
743 $moduleRightsMapping = array(
744 'product' =>
'produit',
745 'margin' =>
'margins',
746 'comptabilite' =>
'compta'
749 $rightsPath = $module;
750 if (!empty($moduleRightsMapping[$rightsPath])) {
751 $rightsPath = $moduleRightsMapping[$rightsPath];
755 $tmp = explode(
'@', $rightsPath, 2);
756 if (!empty($tmp[1])) {
757 if (strpos($module,
'@') !==
false) {
760 $rightsPath = $tmp[1];
761 $permlevel2 = $permlevel1;
762 $permlevel1 = $tmp[0];
777 if ($permlevel1 ==
'propale') {
778 $permlevel1 =
'propal';
780 if ($permlevel1 ==
'member') {
781 $permlevel1 =
'adherent';
783 if ($permlevel1 ==
'recruitmentcandidature') {
784 $permlevel1 =
'recruitmentjobposition';
789 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
794 if (!empty($this->rights->$rightsPath->$permlevel1)) {
795 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
796 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
800 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
801 return $this->rights->$rightsPath->$permlevel1->lire;
803 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
804 return $this->rights->$rightsPath->$permlevel1->creer;
806 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
807 return $this->rights->$rightsPath->$permlevel1->create;
809 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
810 return $this->rights->$rightsPath->$permlevel1->supprimer;
814 if (!empty($this->rights->$rightsPath->$permlevel1)) {
815 return $this->rights->$rightsPath->$permlevel1;
819 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
820 return $this->rights->$rightsPath->lire;
822 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
823 return $this->rights->$rightsPath->creer;
825 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
826 return $this->rights->$rightsPath->create;
828 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
829 return $this->rights->$rightsPath->supprimer;
847 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
849 global $conf, $user, $langs;
851 $entity = (empty($entity) ? $conf->entity : $entity);
853 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
861 $module = $perms = $subperms =
'';
864 $sql =
"SELECT module, perms, subperms";
865 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
866 $sql .=
" WHERE id = ".((int) $rid);
867 $sql .=
" AND entity = ".((int) $entity);
869 $result = $this->
db->query($sql);
871 $obj = $this->
db->fetch_object($result);
874 $module = $obj->module;
875 $perms = $obj->perms;
876 $subperms = $obj->subperms;
884 $whereforadd =
"id=".((int) $rid);
886 if (!empty($subperms)) {
887 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->
db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
888 } elseif (!empty($perms)) {
889 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
895 if (!empty($allmodule)) {
896 if ($allmodule ==
'allmodules') {
897 $whereforadd =
'allmodules';
899 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
900 if (!empty($allperms)) {
901 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
908 if (!empty($whereforadd)) {
911 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
912 $sql .=
" WHERE entity = ".((int) $entity);
913 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
914 $sql .=
" AND (".$whereforadd.
")";
917 $result = $this->
db->query($sql);
919 $num = $this->
db->num_rows($result);
922 $obj = $this->
db->fetch_object($result);
927 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id).
" AND fk_id = ".((int) $nid).
" AND entity = ".((int) $entity);
928 if (!$this->
db->query($sql)) {
931 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
932 if (!$this->
db->query($sql)) {
945 if (!$error && !$notrigger) {
946 $langs->load(
"other");
947 $this->context = array(
'audit'=>$langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
958 $this->
db->rollback();
978 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
980 global $conf, $user, $langs;
984 $entity = (!empty($entity) ? $entity : $conf->entity);
989 $module = $perms = $subperms =
'';
993 $sql =
"SELECT module, perms, subperms";
994 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
995 $sql .=
" WHERE id = '".$this->db->escape($rid).
"'";
996 $sql .=
" AND entity = ".((int) $entity);
998 $result = $this->
db->query($sql);
1000 $obj = $this->
db->fetch_object($result);
1003 $module = $obj->module;
1004 $perms = $obj->perms;
1005 $subperms = $obj->subperms;
1013 $wherefordel =
"id=".((int) $rid);
1015 if ($subperms ==
'lire' || $subperms ==
'read') {
1016 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->
db->escape($perms).
"' AND subperms IS NOT NULL)";
1018 if ($perms ==
'lire' || $perms ==
'read') {
1019 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1024 if (!empty($allmodule)) {
1025 if ($allmodule ==
'allmodules') {
1026 $wherefordel =
'allmodules';
1028 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1029 if (!empty($allperms)) {
1030 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1037 if (!empty($wherefordel)) {
1040 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1041 $sql .=
" WHERE entity = ".((int) $entity);
1042 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1043 $sql .=
" AND (".$wherefordel.
")";
1047 if ($this->admin == 1) {
1048 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1049 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1050 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1051 $sql .=
" AND id NOT IN (358)";
1054 $result = $this->
db->query($sql);
1056 $num = $this->
db->num_rows($result);
1059 $obj = $this->
db->fetch_object($result);
1062 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1063 $sql .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id = ".((int) $nid);
1064 $sql .=
" AND entity = ".((int) $entity);
1065 if (!$this->
db->query($sql)) {
1077 if (!$error && !$notrigger) {
1078 $langs->load(
"other");
1079 $this->context = array(
'audit'=>$langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1090 $this->
db->rollback();
1093 $this->
db->commit();
1107 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1108 $this->rights =
null;
1109 $this->nb_rights = 0;
1110 $this->all_permissions_are_loaded = 0;
1111 $this->_tab_loaded = array();
1123 public function getrights($moduletag =
'', $forcereload = 0)
1127 if (empty($forcereload)) {
1128 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1133 if (!empty($this->all_permissions_are_loaded)) {
1140 if (!isset($this->rights) || !is_object($this->rights)) {
1141 $this->rights =
new stdClass();
1143 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1144 $this->rights->user =
new stdClass();
1150 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1151 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1152 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1153 $sql .=
" WHERE r.id = ur.fk_id";
1154 if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
1156 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ?
"1," :
"").$conf->entity.
")";
1160 $sql .=
" AND r.entity = ".((int) $conf->entity).
" AND ur.entity = ".((int) $conf->entity);
1162 $sql .=
" AND ur.fk_user= ".((int) $this->
id);
1163 $sql .=
" AND r.perms IS NOT NULL";
1165 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1170 $num = $this->
db->num_rows(
$resql);
1173 $obj = $this->
db->fetch_object(
$resql);
1176 $module = $obj->module;
1177 $perms = $obj->perms;
1178 $subperms = $obj->subperms;
1180 if (!empty($perms)) {
1181 if (!empty($module)) {
1182 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1183 $this->rights->$module =
new stdClass();
1185 if (!empty($subperms)) {
1186 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1187 $this->rights->$module->$perms =
new stdClass();
1189 if (empty($this->rights->$module->$perms->$subperms)) {
1192 $this->rights->$module->$perms->$subperms = 1;
1194 if (empty($this->rights->$module->$perms)) {
1197 $this->rights->$module->$perms = 1;
1208 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1209 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1210 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1211 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1212 $sql .=
" WHERE r.id = gr.fk_id";
1214 if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
1215 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1216 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1218 $sql .=
" AND r.entity = ".((int) $conf->entity);
1221 $sql .=
" AND gr.entity = ".((int) $conf->entity);
1225 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1226 $sql .=
" AND r.entity = ".((int) $conf->entity);
1229 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1230 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1231 $sql .=
" AND r.perms IS NOT NULL";
1233 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1238 $num = $this->
db->num_rows(
$resql);
1241 $obj = $this->
db->fetch_object(
$resql);
1244 $module = $obj->module;
1245 $perms = $obj->perms;
1246 $subperms = $obj->subperms;
1248 if (!empty($perms)) {
1249 if (!empty($module)) {
1250 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1251 $this->rights->$module =
new stdClass();
1253 if (!empty($subperms)) {
1254 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1255 $this->rights->$module->$perms =
new stdClass();
1257 if (empty($this->rights->$module->$perms->$subperms)) {
1260 $this->rights->$module->$perms->$subperms = 1;
1262 if (empty($this->rights->$module->$perms)) {
1266 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1267 $this->rights->$module->$perms = 1;
1279 if (!empty($this->admin)) {
1280 if (empty($this->rights->user->user)) {
1281 $this->rights->user->user =
new stdClass();
1283 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1284 foreach ($listofpermtotest as $permtotest) {
1285 if (empty($this->rights->user->user->$permtotest)) {
1286 $this->rights->user->user->$permtotest = 1;
1290 if (empty($this->rights->user->self)) {
1291 $this->rights->user->self =
new stdClass();
1293 $listofpermtotest = array(
'creer',
'password');
1294 foreach ($listofpermtotest as $permtotest) {
1295 if (empty($this->rights->user->self->$permtotest)) {
1296 $this->rights->user->self->$permtotest = 1;
1301 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
1302 if (empty($this->rights->user->user_advance)) {
1303 $this->rights->user->user_advance =
new stdClass();
1305 $listofpermtotest = array(
'readperms',
'write');
1306 foreach ($listofpermtotest as $permtotest) {
1307 if (empty($this->rights->user->user_advance->$permtotest)) {
1308 $this->rights->user->user_advance->$permtotest = 1;
1312 if (empty($this->rights->user->self_advance)) {
1313 $this->rights->user->self_advance =
new stdClass();
1315 $listofpermtotest = array(
'readperms',
'writeperms');
1316 foreach ($listofpermtotest as $permtotest) {
1317 if (empty($this->rights->user->self_advance->$permtotest)) {
1318 $this->rights->user->self_advance->$permtotest = 1;
1322 if (empty($this->rights->user->group_advance)) {
1323 $this->rights->user->group_advance =
new stdClass();
1325 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1326 foreach ($listofpermtotest as $permtotest) {
1327 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1328 $this->rights->user->group_advance->$permtotest = 1;
1336 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1337 $this->rights->propal = $this->rights->propale;
1339 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1340 $this->rights->propale = $this->rights->propal;
1346 $this->all_permissions_are_loaded = 1;
1349 $this->_tab_loaded[$moduletag] = 1;
1361 global $conf, $langs, $user;
1366 if (isset($this->statut)) {
1367 if ($this->statut == $status) {
1370 } elseif (isset($this->status) && $this->status == $status) {
1377 $sql =
"UPDATE ".$this->db->prefix().
"user";
1378 $sql .=
" SET statut = ".((int) $status);
1379 $sql .=
" WHERE rowid = ".((int) $this->
id);
1380 $result = $this->
db->query($sql);
1382 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1385 $result = $this->
call_trigger(
'USER_ENABLEDISABLE', $user);
1393 $this->
db->rollback();
1396 $this->status = $status;
1397 $this->statut = $status;
1398 $this->
db->commit();
1415 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1416 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1427 global $conf, $langs;
1433 $this->
fetch($this->
id);
1435 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1438 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1440 if (!$error && !$this->
db->query($sql)) {
1442 $this->
error = $this->
db->lasterror();
1446 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1447 if (!$error && !$this->
db->query($sql)) {
1449 $this->
error = $this->
db->lasterror();
1453 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1454 if (!$error && !$this->
db->query($sql)) {
1456 $this->
error = $this->
db->lasterror();
1460 if ($this->contact_id > 0) {
1461 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1462 if (!$error && !$this->
db->query($sql)) {
1464 $this->
error = $this->
db->lasterror();
1473 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1479 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1480 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1481 if (!$this->
db->query($sql)) {
1483 $this->
error = $this->
db->lasterror();
1492 $this->
db->rollback();
1497 $this->
db->commit();
1500 $this->
db->rollback();
1512 public function create($user, $notrigger = 0)
1514 global $conf, $langs;
1520 $this->civility_code = trim((
string) $this->civility_code);
1521 $this->login = trim((
string) $this->login);
1522 if (!isset($this->entity)) {
1523 $this->entity = $conf->entity;
1526 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1528 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1531 if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1532 $langs->load(
"errors");
1533 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1536 if (empty($this->login)) {
1537 $langs->load(
"errors");
1538 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1540 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1541 $langs->load(
"errors");
1542 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1553 $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).
"'";
1554 $resqltochecklogin = $this->
db->query($sqltochecklogin);
1555 if ($resqltochecklogin) {
1556 $objtochecklogin = $this->
db->fetch_object($resqltochecklogin);
1557 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1558 $langs->load(
"errors");
1559 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1561 $this->
db->rollback();
1564 $this->
db->free($resqltochecklogin);
1567 if (!empty($this->email)) {
1568 $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).
"'";
1569 $resqltochecklogin = $this->
db->query($sqltochecklogin);
1570 if ($resqltochecklogin) {
1571 $objtochecklogin = $this->
db->fetch_object($resqltochecklogin);
1572 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1573 $langs->load(
"errors");
1574 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
1576 $this->
db->rollback();
1579 $this->
db->free($resqltochecklogin);
1584 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, entity)";
1585 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->
db->escape($this->login).
"', '".$this->
db->escape($this->ldap_sid).
"', ".((int) $this->entity).
")";
1586 $result = $this->
db->query($sql);
1588 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1590 $this->
id = $this->
db->last_insert_id($this->
db->prefix().
"user");
1594 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1595 $this->
db->rollback();
1599 if (!empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER) && !empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) {
1600 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1601 $langs->load(
"stocks");
1603 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1604 $entrepot->libelle = $entrepot->label;
1605 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1606 $entrepot->statut = 1;
1607 $entrepot->country_id = $mysoc->country_id;
1608 $warehouseid = $entrepot->create($user);
1610 $this->fk_warehouse = $warehouseid;
1614 $result = $this->
update($user, 1, 1);
1616 $this->
db->rollback();
1630 $this->
db->commit();
1635 $this->
db->rollback();
1639 $this->
error = $this->
db->lasterror();
1640 $this->
db->rollback();
1658 global $conf, $user, $langs;
1664 $this->civility_code = $contact->civility_code;
1665 $this->lastname = $contact->lastname;
1666 $this->firstname = $contact->firstname;
1667 $this->gender = $contact->gender;
1668 $this->email = $contact->email;
1669 $this->socialnetworks = $contact->socialnetworks;
1670 $this->office_phone = $contact->phone_pro;
1671 $this->office_fax = $contact->fax;
1672 $this->user_mobile = $contact->phone_mobile;
1673 $this->address = $contact->address;
1674 $this->zip = $contact->zip;
1675 $this->town = $contact->town;
1677 $this->state_id = $contact->state_id;
1678 $this->country_id = $contact->country_id;
1679 $this->employee = 0;
1681 if (empty($login)) {
1682 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1683 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1685 $this->login = $login;
1690 $result = $this->
create($user, 1);
1692 $sql =
"UPDATE ".$this->db->prefix().
"user";
1693 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1694 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1695 if ($contact->socid > 0) {
1696 $sql .=
", fk_soc=".((int) $contact->socid);
1698 $sql .=
" WHERE rowid=".((int) $this->
id);
1702 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1704 $this->context[
'createfromcontact'] =
'createfromcontact';
1709 $error++; $this->
db->rollback();
return -1;
1713 $this->
db->commit();
1716 $this->
error = $this->
db->error();
1718 $this->
db->rollback();
1723 dol_syslog(get_class($this).
"::create_from_contact - 0");
1725 $this->
db->rollback();
1742 global $conf, $user, $langs;
1746 $this->civility_code = $member->civility_id;
1747 $this->lastname = $member->lastname;
1748 $this->firstname = $member->firstname;
1749 $this->gender = $member->gender;
1750 $this->email = $member->email;
1751 $this->fk_member = $member->id;
1752 $this->address = $member->address;
1753 $this->zip = $member->zip;
1754 $this->town = $member->town;
1756 $this->state_id = $member->state_id;
1757 $this->country_id = $member->country_id;
1758 $this->socialnetworks = $member->socialnetworks;
1760 $this->pass = $member->pass;
1761 $this->pass_crypted = $member->pass_indatabase_crypted;
1763 if (empty($login)) {
1764 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1767 $this->login = $login;
1772 $result = $this->
create($user);
1774 if (!empty($this->pass)) {
1775 $newpass = $this->
setPassword($user, $this->pass);
1776 if (is_numeric($newpass) && $newpass < 0) {
1779 } elseif (!empty($this->pass_crypted)) {
1780 $sql =
"UPDATE ".$this->db->prefix().
"user";
1781 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
1782 $sql .=
" WHERE rowid=".((int) $this->
id);
1790 if ($result > 0 && $member->fk_soc) {
1791 $sql =
"UPDATE ".$this->db->prefix().
"user";
1792 $sql .=
" SET fk_soc=".((int) $member->fk_soc);
1793 $sql .=
" WHERE rowid=".((int) $this->
id);
1795 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
1798 $this->
db->commit();
1801 $this->
error = $this->
db->lasterror();
1803 $this->
db->rollback();
1810 $this->
db->commit();
1814 $this->
db->rollback();
1832 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
1833 $sql .=
" WHERE bydefault = 1";
1834 $sql .=
" AND entity = ".((int) $conf->entity);
1838 $num = $this->
db->num_rows(
$resql);
1841 $row = $this->
db->fetch_row(
$resql);
1849 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
1850 $result = $this->
db->query($sql);
1852 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
1853 $result = $this->
db->query($sql);
1873 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
1875 global $conf, $langs;
1877 $nbrowsaffected = 0;
1880 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
1883 $this->civility_code = trim((
string) $this->civility_code);
1884 $this->lastname = trim((
string) $this->lastname);
1885 $this->firstname = trim((
string) $this->firstname);
1886 $this->ref_employee = trim((
string) $this->ref_employee);
1887 $this->national_registration_number = trim((
string) $this->national_registration_number);
1888 $this->employee = ($this->employee > 0 ? $this->employee : 0);
1889 $this->login = trim((
string) $this->login);
1890 $this->gender = trim((
string) $this->gender);
1891 $this->pass = trim((
string) $this->pass);
1892 $this->api_key = trim((
string) $this->api_key);
1893 $this->address = trim((
string) $this->address);
1894 $this->zip = trim((
string) $this->zip);
1895 $this->town = trim((
string) $this->town);
1897 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
1898 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
1899 $this->office_phone = trim((
string) $this->office_phone);
1900 $this->office_fax = trim((
string) $this->office_fax);
1901 $this->user_mobile = trim((
string) $this->user_mobile);
1902 $this->personal_mobile = trim((
string) $this->personal_mobile);
1903 $this->email = trim((
string) $this->email);
1904 $this->personal_email = trim((
string) $this->personal_email);
1906 $this->job = trim((
string) $this->job);
1907 $this->signature = trim((
string) $this->signature);
1908 $this->note_public = trim((
string) $this->note_public);
1909 $this->note_private = trim((
string) $this->note_private);
1910 $this->openid = trim((
string) $this->openid);
1911 $this->admin = ($this->admin > 0 ? $this->admin : 0);
1913 $this->accountancy_code = trim((
string) $this->accountancy_code);
1914 $this->color = trim((
string) $this->color);
1915 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
1916 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
1917 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
1918 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
1919 $this->birth = empty($this->birth) ?
'' : $this->birth;
1920 $this->fk_warehouse = (int) $this->fk_warehouse;
1925 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1927 if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1928 $langs->load(
"errors");
1929 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1932 if (empty($this->login)) {
1933 $langs->load(
"errors");
1934 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
1936 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1937 $langs->load(
"errors");
1938 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1945 if (!empty($this->oldcopy) && $this->oldcopy->login != $this->login) {
1946 $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).
"'";
1947 $resqltochecklogin = $this->
db->query($sqltochecklogin);
1948 if ($resqltochecklogin) {
1949 $objtochecklogin = $this->
db->fetch_object($resqltochecklogin);
1950 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1951 $langs->load(
"errors");
1952 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1954 $this->
db->rollback();
1959 if (!empty($this->oldcopy) && !empty($this->email) && $this->oldcopy->email != $this->email) {
1960 $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).
"'";
1961 $resqltochecklogin = $this->
db->query($sqltochecklogin);
1962 if ($resqltochecklogin) {
1963 $objtochecklogin = $this->
db->fetch_object($resqltochecklogin);
1964 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1965 $langs->load(
"errors");
1966 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
1968 $this->
db->rollback();
1975 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
1976 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
1977 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
1978 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
1979 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
1980 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
1981 $sql .=
", employee = ".(int) $this->employee;
1982 $sql .=
", login = '".$this->db->escape($this->login).
"'";
1983 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
1984 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
1985 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
1986 if (!empty($user->admin)) {
1987 $sql .=
", admin = ".(int) $this->admin;
1989 $sql .=
", address = '".$this->db->escape($this->address).
"'";
1990 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
1991 $sql .=
", town = '".$this->db->escape($this->town).
"'";
1992 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".$this->
db->escape($this->state_id).
"'" :
"null");
1993 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".$this->
db->escape($this->country_id).
"'" :
"null");
1994 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
1995 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
1996 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
1997 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
1998 $sql .=
", email = '".$this->db->escape($this->email).
"'";
1999 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
2000 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
2001 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2002 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2003 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2004 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2005 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2006 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2007 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2008 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2009 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2010 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2011 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2012 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2013 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".$this->db->escape($this->fk_user).
"'" :
"null");
2014 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".$this->db->escape($this->fk_user_expense_validator).
"'" :
"null");
2015 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".$this->db->escape($this->fk_user_holiday_validator).
"'" :
"null");
2016 if (isset($this->thm) || $this->thm !=
'') {
2017 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2019 if (isset($this->tjm) || $this->tjm !=
'') {
2020 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2022 if (isset($this->salary) || $this->salary !=
'') {
2023 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2025 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2026 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2028 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2029 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2030 $sql .=
", entity = ".((int) $this->entity);
2032 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2033 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2034 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2035 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2036 $sql .=
" WHERE rowid = ".((int) $this->
id);
2038 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2041 $nbrowsaffected += $this->
db->affected_rows(
$resql);
2044 if (!empty($this->pass)) {
2045 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2047 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2048 if (is_numeric($result) && $result < 0) {
2055 if ($this->fk_member > 0) {
2056 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2057 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2060 $this->
error = $this->
db->error(); $this->
db->rollback();
return -5;
2064 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2065 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2068 $this->
error = $this->
db->error(); $this->
db->rollback();
return -5;
2071 if ($nbrowsaffected) {
2072 if ($this->fk_member > 0 && !$nosyncmember) {
2073 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2075 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2080 $result = $adh->fetch($this->fk_member);
2083 $adh->civility_code = $this->civility_code;
2084 $adh->firstname = $this->firstname;
2085 $adh->lastname = $this->lastname;
2086 $adh->login = $this->login;
2087 $adh->gender = $this->gender;
2088 $adh->birth = $this->birth;
2090 $adh->pass = $this->pass;
2092 $adh->address = $this->address;
2093 $adh->town = $this->town;
2094 $adh->zip = $this->zip;
2095 $adh->state_id = $this->state_id;
2096 $adh->country_id = $this->country_id;
2098 $adh->email = $this->email;
2100 $adh->socialnetworks = $this->socialnetworks;
2102 $adh->phone = $this->office_phone;
2103 $adh->phone_mobile = $this->user_mobile;
2105 $adh->default_lang = $this->lang;
2107 $adh->user_id = $this->id;
2108 $adh->user_login = $this->login;
2110 $result = $adh->update($user, 0, 1, 0);
2112 $this->
error = $adh->error;
2113 $this->errors = $adh->errors;
2114 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2117 } elseif ($result < 0) {
2118 $this->
error = $adh->error;
2119 $this->errors = $adh->errors;
2124 if ($this->contact_id > 0 && !$nosynccontact) {
2125 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2127 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2131 $result = $tmpobj->fetch($this->contact_id);
2134 $tmpobj->civility_code = $this->civility_code;
2135 $tmpobj->firstname = $this->firstname;
2136 $tmpobj->lastname = $this->lastname;
2137 $tmpobj->login = $this->login;
2138 $tmpobj->gender = $this->gender;
2139 $tmpobj->birth = $this->birth;
2143 $tmpobj->email = $this->email;
2145 $tmpobj->socialnetworks = $this->socialnetworks;
2147 $tmpobj->phone_pro = $this->office_phone;
2148 $tmpobj->phone_mobile = $this->user_mobile;
2149 $tmpobj->fax = $this->office_fax;
2151 $tmpobj->default_lang = $this->lang;
2153 $tmpobj->address = $this->address;
2154 $tmpobj->town = $this->town;
2155 $tmpobj->zip = $this->zip;
2156 $tmpobj->state_id = $this->state_id;
2157 $tmpobj->country_id = $this->country_id;
2159 $tmpobj->user_id = $this->id;
2160 $tmpobj->user_login = $this->login;
2162 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2164 $this->
error = $tmpobj->error;
2165 $this->errors = $tmpobj->errors;
2166 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2170 $this->
error = $tmpobj->error;
2171 $this->errors = $tmpobj->errors;
2187 if (!$error && !$notrigger) {
2197 $this->
db->commit();
2198 return $nbrowsaffected;
2201 $this->
db->rollback();
2205 $this->
error = $this->
db->lasterror();
2206 $this->
db->rollback();
2225 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2226 $sql .=
" datepreviouslogin = datelastlogin,";
2227 $sql .=
" ippreviouslogin = iplastlogin,";
2228 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2229 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2230 $sql .=
" tms = tms";
2231 $sql .=
" WHERE rowid = ".((int) $this->
id);
2233 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2236 $this->datepreviouslogin = $this->datelastlogin;
2237 $this->datelastlogin = $now;
2238 $this->ippreviouslogin = $this->iplastlogin;
2239 $this->iplastlogin = $userremoteip;
2242 $this->
error = $this->
db->lasterror().
' sql='.$sql;
2259 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0)
2261 global $conf, $langs;
2262 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2266 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2274 if (empty($passwordalreadycrypted)) {
2275 if (!empty($conf->global->USER_PASSWORD_GENERATED)) {
2277 $modGeneratePassClass =
'modGeneratePass'.ucfirst($conf->global->USER_PASSWORD_GENERATED);
2279 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2280 if (class_exists($modGeneratePassClass)) {
2281 $modGeneratePass =
new $modGeneratePassClass($this->
db, $conf, $langs, $user);
2284 $modGeneratePass->WithoutAmbi = 0;
2287 $testpassword = $modGeneratePass->validatePassword($password);
2288 if (!$testpassword) {
2289 $this->
error = $modGeneratePass->error;
2297 $password_crypted =
dol_hash($password);
2301 if (!$changelater) {
2302 if (!is_object($this->oldcopy)) {
2303 $this->oldcopy = clone $this;
2308 $sql =
"UPDATE ".$this->db->prefix().
"user";
2309 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2310 $sql .=
" pass_temp = null";
2311 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
2312 $sql .=
", pass = null";
2314 $sql .=
", pass = '".$this->db->escape($password).
"'";
2316 $sql .=
" WHERE rowid = ".((int) $this->
id);
2318 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2319 $result = $this->
db->query($sql);
2321 if ($this->
db->affected_rows($result)) {
2322 $this->pass = $password;
2323 $this->pass_indatabase = $password;
2324 $this->pass_indatabase_crypted = $password_crypted;
2326 if ($this->fk_member && !$nosyncmember) {
2327 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2332 $result = $adh->fetch($this->fk_member);
2335 $result = $adh->setPassword($user, $this->pass, (empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1), 1);
2336 if (is_numeric($result) && $result < 0) {
2337 $this->
error = $adh->error;
2342 $this->
error = $adh->error;
2347 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2349 if (!$error && !$notrigger) {
2351 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2353 $error++; $this->
db->rollback();
return -1;
2358 $this->
db->commit();
2361 $this->
db->rollback();
2365 $this->
db->rollback();
2372 $sql =
"UPDATE ".$this->db->prefix().
"user";
2373 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2374 $sql .=
" WHERE rowid = ".((int) $this->
id);
2376 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2377 $result = $this->
db->query($sql);
2399 global $conf, $langs, $mysoc;
2400 global $dolibarr_main_url_root;
2402 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2409 $outputlangs =
new Translate(
"", $conf);
2411 if (isset($this->
conf->MAIN_LANG_DEFAULT)
2412 && $this->conf->MAIN_LANG_DEFAULT !=
'auto') {
2413 $outputlangs->getDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2416 if ($this->
conf->MAIN_LANG_DEFAULT) {
2417 $outputlangs->setDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2419 $outputlangs = $langs;
2423 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2425 $appli = constant(
'DOL_APPLICATION_TITLE');
2426 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
2427 $appli = $conf->global->MAIN_APPLICATION_TITLE;
2430 $subject =
'['.$mysoc->name.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2433 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2434 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2436 if (!$changelater) {
2437 $url = $urlwithroot.
'/';
2438 if (!empty($conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD))
2439 $url = $conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD;
2440 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2441 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2442 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2443 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2446 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2448 $mesg .= $user->getFullName($outputlangs);
2450 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2452 global $dolibarr_main_instance_unique_id;
2455 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2456 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.$dolibarr_main_instance_unique_id));
2457 if (!empty($conf->multicompany->enabled)) {
2458 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2463 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2464 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2465 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2466 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2468 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2469 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2470 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2472 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2475 $trackid =
'use'.$this->id;
2480 $conf->global->MAIN_MAIL_EMAIL_FROM,
2494 if ($mailfile->sendfile()) {
2497 $langs->trans(
"errors");
2498 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2510 return $this->error;
2523 $sql =
"SELECT url, login, pass, poste ";
2524 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2525 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2530 $obj = $this->
db->fetch_object(
$resql);
2532 $this->clicktodial_url = $obj->url;
2533 $this->clicktodial_login = $obj->login;
2534 $this->clicktodial_password = $obj->pass;
2535 $this->clicktodial_poste = $obj->poste;
2538 $this->clicktodial_loaded = 1;
2543 $this->
error = $this->
db->error();
2559 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2560 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2562 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2563 $result = $this->
db->query($sql);
2565 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2566 $sql .=
" (fk_user,url,login,pass,poste)";
2567 $sql .=
" VALUES (".$this->id;
2568 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2569 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2570 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2571 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2573 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2574 $result = $this->
db->query($sql);
2576 $this->
db->commit();
2579 $this->
db->rollback();
2580 $this->
error = $this->
db->lasterror();
2598 global $conf, $langs, $user;
2604 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2605 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2606 $sql .=
" AND fk_usergroup = ".((int) $group);
2607 $sql .=
" AND entity = ".((int) $entity);
2609 $result = $this->
db->query($sql);
2611 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2612 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2614 $result = $this->
db->query($sql);
2616 if (!$error && !$notrigger) {
2617 $this->newgroupid = $group;
2618 $this->context = array(
'audit'=>$langs->trans(
"UserSetInGroup"),
'newgroupid'=>$group);
2629 $this->
db->commit();
2633 $this->
db->rollback();
2637 $this->
error = $this->
db->lasterror();
2638 $this->
db->rollback();
2655 global $conf, $langs, $user;
2661 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2662 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2663 $sql .=
" AND fk_usergroup = ".((int) $group);
2664 if (empty($entity)) {
2665 $sql .=
" AND entity IN (0, 1)";
2667 $sql .=
" AND entity = ".((int) $entity);
2670 $result = $this->
db->query($sql);
2672 if (!$error && !$notrigger) {
2673 $this->oldgroupid = $group;
2674 $this->context = array(
'audit'=>$langs->trans(
"UserRemovedFromGroup"),
'oldgroupid'=>$group);
2685 $this->
db->commit();
2688 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2689 $this->
db->rollback();
2693 $this->
error = $this->
db->lasterror();
2694 $this->
db->rollback();
2710 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
2712 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2713 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
2734 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
2736 global $langs, $conf, $db, $hookmanager, $user;
2737 global $dolibarr_main_authentication, $dolibarr_main_demo;
2738 global $menumanager;
2740 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
2744 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) {
2748 $result =
''; $label =
''; $companylink =
'';
2750 if (!empty($this->photo)) {
2751 $label .=
'<div class="photointooltip floatright">';
2752 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
2758 $label .=
'<div class="centpercent">';
2759 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u>';
2760 $label .=
' '.$this->getLibStatut(4);
2762 if (!empty($this->login)) {
2765 if (!empty($this->job)) {
2769 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
2770 $phonelist = array();
2771 if ($this->office_phone) {
2772 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2774 if ($this->office_fax) {
2775 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2777 if ($this->user_mobile) {
2778 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
2780 $label .=
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
2782 if (!empty($this->admin)) {
2783 $label .=
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
2785 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
2786 $label .=
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
2789 if (!empty($this->socid)) {
2790 $thirdpartystatic =
new Societe($db);
2791 $thirdpartystatic->fetch($this->socid);
2792 if (empty($hidethirdpartylogo)) {
2793 $companylink =
' '.$thirdpartystatic->getNomUrl(2, (($option ==
'nolink') ?
'nolink' :
''));
2797 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
2798 $label .=
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
2800 if ($infologin > 0) {
2802 $label .=
'<br><u>'.$langs->trans(
"Session").
'</u>';
2804 if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) {
2805 $label .=
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.$conf->entity.
' (User entity '.$this->entity.
')';
2807 $label .=
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
2808 $label .=
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
2809 $label .=
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
2811 $label .=
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
2813 $label .=
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
2814 $label .=
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag($conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
2815 $label .=
'<br><b>'.$langs->trans(
"Layout").
':</b> '.
dol_string_nohtmltag($conf->browser->layout);
2816 $label .=
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
2817 if ($conf->browser->layout ==
'phone') {
2818 $label .=
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
2820 if (!empty($_SESSION[
"disablemodules"])) {
2821 $label .=
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(join(
', ', explode(
',', $_SESSION[
"disablemodules"])));
2824 if ($infologin < 0) {
2828 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
2829 if ($option ==
'leave') {
2830 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
2833 if ($option !=
'nolink') {
2835 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2836 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2837 $add_save_lastsearch_values = 1;
2839 if ($add_save_lastsearch_values) {
2840 $url .=
'&save_lastsearch_values=1';
2844 $linkstart =
'<a href="'.$url.
'"';
2846 if (empty($notooltip)) {
2847 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2848 $langs->load(
"users");
2849 $label = $langs->trans(
"ShowUser");
2850 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2852 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
2853 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
2856 $linkstart .= $linkclose.
'>';
2860 $result .= (($option ==
'nolink') ?
'' : $linkstart);
2861 if ($withpictoimg) {
2862 $paddafterimage =
'';
2863 if (abs((
int) $withpictoimg) == 1) {
2864 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
2867 if ($withpictoimg > 0) {
2868 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
2871 $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>';
2875 if ($withpictoimg > -2 && $withpictoimg != 2) {
2876 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2877 $result .=
'<span class="nopadding usertext'.((!isset($this->statut) || $this->statut) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
2879 if ($mode ==
'login') {
2884 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2885 $result .=
'</span>';
2888 $result .= (($option ==
'nolink') ?
'' : $linkend);
2891 $result .= $companylink;
2894 $hookmanager->initHooks(array(
'userdao'));
2895 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
2896 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2898 $result = $hookmanager->resPrint;
2900 $result .= $hookmanager->resPrint;
2915 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
2917 global $langs, $user;
2921 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2925 if ((!$user->rights->user->user->lire && $this->id != $user->id)) {
2929 if ($option ==
'xxx') {
2930 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2934 if ($option ==
'nolink') {
2939 $result .= $linkstart;
2940 if ($withpictoimg) {
2941 $paddafterimage =
'';
2942 if (abs($withpictoimg) == 1) {
2943 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
2946 if ($withpictoimg > 0) {
2947 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
2950 $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>';
2954 $result .= $this->login;
2955 $result .= $linkend;
2968 return $this->
LibStatut(isset($this->statut) ? (
int) $this->statut : (
int) $this->status, $mode);
2984 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2987 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
2988 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
2989 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
2990 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
2993 $statusType =
'status5';
2994 if ($status == self::STATUS_ENABLED) {
2995 $statusType =
'status4';
2998 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
3010 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3011 $return .=
'<div class="info-box info-box-sm">';
3012 $return .=
'<span class="info-box-icon bg-infobox-action">';
3015 if (!empty($this->photo)) {
3017 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3026 $return .=
'</span>';
3027 $return .=
'<div class="info-box-content">';
3028 $return .=
'<span class="info-box-ref">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3029 if (property_exists($this,
'label')) {
3030 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3033 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->email.
'</span>';
3035 if (method_exists($this,
'getLibStatut')) {
3036 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(5).
'</div>';
3038 $return .=
'</div>';
3039 $return .=
'</div>';
3040 $return .=
'</div>';
3063 $dn = $conf->global->LDAP_KEY_USERS.
"=".$info[$conf->global->LDAP_KEY_USERS].
",".$conf->global->LDAP_USER_DN;
3064 } elseif ($mode == 1) {
3065 $dn = $conf->global->LDAP_USER_DN;
3066 } elseif ($mode == 2) {
3067 $dn = $conf->global->LDAP_KEY_USERS.
"=".$info[$conf->global->LDAP_KEY_USERS];
3082 global $conf, $langs;
3088 $keymodified =
false;
3091 $info[
"objectclass"] = explode(
',', $conf->global->LDAP_USER_OBJECT_CLASS);
3097 'LDAP_FIELD_FULLNAME' =>
'fullname',
3098 'LDAP_FIELD_NAME' =>
'lastname',
3099 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3100 'LDAP_FIELD_LOGIN' =>
'login',
3101 'LDAP_FIELD_LOGIN_SAMBA'=>
'login',
3102 'LDAP_FIELD_PHONE' =>
'office_phone',
3103 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3104 'LDAP_FIELD_FAX' =>
'office_fax',
3105 'LDAP_FIELD_MAIL' =>
'email',
3106 'LDAP_FIELD_SID' =>
'ldap_sid',
3110 foreach ($ldapkey as $constname => $varname) {
3111 if (!empty($this->$varname) && !empty($conf->global->$constname)) {
3112 $info[$conf->global->$constname] = $this->$varname;
3115 if (!empty($conf->global->LDAP_KEY_USERS) && $conf->global->LDAP_KEY_USERS == $conf->global->$constname) {
3116 if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
3117 $keymodified =
true;
3122 foreach ($socialnetworks as $key => $value) {
3123 if (!empty($this->socialnetworks[$value[
'label']]) && !empty($conf->global->{
'LDAP_FIELD_'.strtoupper($value[
'label'])})) {
3124 $info[$conf->global->{
'LDAP_FIELD_'.strtoupper($value[
'label'])}] = $this->socialnetworks[$value[
'label']];
3127 if ($this->address && !empty($conf->global->LDAP_FIELD_ADDRESS)) {
3128 $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->address;
3130 if ($this->zip && !empty($conf->global->LDAP_FIELD_ZIP)) {
3131 $info[$conf->global->LDAP_FIELD_ZIP] = $this->zip;
3133 if ($this->town && !empty($conf->global->LDAP_FIELD_TOWN)) {
3134 $info[$conf->global->LDAP_FIELD_TOWN] = $this->town;
3136 if ($this->note_public && !empty($conf->global->LDAP_FIELD_DESCRIPTION)) {
3139 if ($this->socid > 0) {
3141 $soc->fetch($this->socid);
3143 $info[$conf->global->LDAP_FIELD_COMPANY] = $soc->name;
3144 if ($soc->client == 1) {
3145 $info[
"businessCategory"] =
"Customers";
3147 if ($soc->client == 2) {
3148 $info[
"businessCategory"] =
"Prospects";
3150 if ($soc->fournisseur == 1) {
3151 $info[
"businessCategory"] =
"Suppliers";
3156 if (!empty($this->pass)) {
3157 if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
3158 $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass;
3160 if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3161 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass,
'openldap');
3163 } elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !==
'3') {
3166 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
3168 if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) {
3169 if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3170 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dolGetLdapPasswordHash($this->pass_indatabase_crypted,
'md5frommd5');
3173 } elseif (!empty($this->pass_indatabase)) {
3175 if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
3176 $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass_indatabase;
3178 if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3179 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass_indatabase,
'openldap');
3184 if ($conf->global->LDAP_SERVER_TYPE ==
'egroupware') {
3185 $info[
"objectclass"][4] =
"phpgwContact";
3187 $info[
'uidnumber'] = $this->id;
3189 $info[
'phpgwTz'] = 0;
3190 $info[
'phpgwMailType'] =
'INTERNET';
3191 $info[
'phpgwMailHomeType'] =
'INTERNET';
3193 $info[
"phpgwContactTypeId"] =
'n';
3194 $info[
"phpgwContactCatId"] = 0;
3195 $info[
"phpgwContactAccess"] =
"public";
3198 $this->egroupware_id = 1;
3201 $info[
"phpgwContactOwner"] = $this->egroupware_id;
3204 $info[
"rfc822Mailbox"] = $this->email;
3206 if ($this->phone_mobile) {
3207 $info[
"phpgwCellTelephoneNumber"] = $this->phone_mobile;
3211 if (!empty($conf->global->LDAP_FIELD_USERID)) {
3212 $info[$conf->global->LDAP_FIELD_USERID] = $this->id;
3214 if (!empty($conf->global->LDAP_FIELD_GROUPID)) {
3216 $groupslist = $usergroup->listGroupsForUser($this->
id);
3217 $info[$conf->global->LDAP_FIELD_GROUPID] =
'65534';
3218 if (!empty($groupslist)) {
3219 foreach ($groupslist as $groupforuser) {
3220 $info[$conf->global->LDAP_FIELD_GROUPID] = $groupforuser->id;
3225 if (!empty($conf->global->LDAP_FIELD_HOMEDIRECTORY) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX)) {
3226 $info[$conf->global->LDAP_FIELD_HOMEDIRECTORY] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->login";
3242 global $user, $langs;
3248 $this->
ref =
'SPECIMEN';
3249 $this->specimen = 1;
3251 $this->lastname =
'DOLIBARR';
3252 $this->firstname =
'SPECIMEN';
3253 $this->gender =
'man';
3254 $this->note_public =
'This is a note public';
3255 $this->note_private =
'This is a note private';
3256 $this->email =
'email@specimen.com';
3257 $this->personal_email =
'personalemail@specimen.com';
3258 $this->socialnetworks = array(
3259 'skype' =>
'skypepseudo',
3260 'twitter' =>
'twitterpseudo',
3261 'facebook' =>
'facebookpseudo',
3262 'linkedin' =>
'linkedinpseudo',
3264 $this->office_phone =
'0999999999';
3265 $this->office_fax =
'0999999998';
3266 $this->user_mobile =
'0999999997';
3267 $this->personal_mobile =
'0999999996';
3269 $this->login =
'dolibspec';
3270 $this->pass =
'dolibSpec+@123';
3273 $this->datec = $now;
3274 $this->datem = $now;
3276 $this->datelastlogin = $now;
3277 $this->iplastlogin =
'127.0.0.1';
3278 $this->datepreviouslogin = $now;
3279 $this->ippreviouslogin =
'127.0.0.1';
3295 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
3296 $sql .=
" u.tms as date_modification, u.entity";
3297 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3298 $sql .=
" WHERE u.rowid = ".((int) $id);
3300 $result = $this->
db->query($sql);
3302 if ($this->
db->num_rows($result)) {
3303 $obj = $this->
db->fetch_object($result);
3305 $this->
id = $obj->rowid;
3307 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3308 $this->date_creation = $this->db->jdate($obj->datec);
3309 $this->date_modification = $this->
db->jdate($obj->date_modification);
3310 $this->entity = $obj->entity;
3313 $this->
db->free($result);
3327 $sql =
"SELECT count(mc.email) as nb";
3328 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3329 $sql .=
" WHERE mc.email = '".$this->db->escape($this->email).
"'";
3330 $sql .=
" AND mc.statut NOT IN (-1,0)";
3334 $obj = $this->
db->fetch_object(
$resql);
3340 $this->error = $this->
db->error();
3357 $sql =
"SELECT count(rowid) as nb";
3358 $sql .=
" FROM ".$this->db->prefix().
"user";
3359 if ($option ==
'superadmin') {
3360 $sql .=
" WHERE entity = 0";
3362 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3363 if ($limitTo ==
'active') {
3364 $sql .=
" AND statut = 1";
3368 $sql .=
" AND admin = ".(int) $admin;
3373 $obj = $this->
db->fetch_object(
$resql);
3374 $nb = (int) $obj->nb;
3379 $this->error = $this->
db->lasterror();
3395 global $user, $conf;
3399 $this->firstname = $ldapuser->{$conf->global->LDAP_FIELD_FIRSTNAME};
3400 $this->lastname = $ldapuser->{$conf->global->LDAP_FIELD_NAME};
3401 $this->login = $ldapuser->{$conf->global->LDAP_FIELD_LOGIN};
3402 $this->pass = $ldapuser->{$conf->global->LDAP_FIELD_PASSWORD};
3403 $this->pass_indatabase_crypted = $ldapuser->{$conf->global->LDAP_FIELD_PASSWORD_CRYPTED};
3405 $this->office_phone = $ldapuser->{$conf->global->LDAP_FIELD_PHONE};
3406 $this->user_mobile = $ldapuser->{$conf->global->LDAP_FIELD_MOBILE};
3407 $this->office_fax = $ldapuser->{$conf->global->LDAP_FIELD_FAX};
3408 $this->email = $ldapuser->{$conf->global->LDAP_FIELD_MAIL};
3409 foreach ($socialnetworks as $key => $value) {
3410 $tmpkey =
'LDAP_FIELD_'.strtoupper($value[
'label']);
3411 $this->socialnetworks[$value[
'label']] = $ldapuser->{$conf->global->$tmpkey};
3413 $this->ldap_sid = $ldapuser->{$conf->global->LDAP_FIELD_SID};
3415 $this->job = $ldapuser->{$conf->global->LDAP_FIELD_TITLE};
3416 $this->note_public = $ldapuser->{$conf->global->LDAP_FIELD_DESCRIPTION};
3418 $result = $this->update($user);
3420 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3436 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3437 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3439 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3440 $res = $this->
db->query($sql);
3443 while ($rec = $this->
db->fetch_array($res)) {
3444 $user =
new User($this->
db);
3445 $user->fetch($rec[
'rowid']);
3465 $this->parentof = array();
3468 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3469 $sql .=
" FROM ".$this->db->prefix().
"user";
3470 $sql .=
" WHERE fk_user <> 0";
3471 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3473 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3476 while ($obj = $this->
db->fetch_object(
$resql)) {
3477 $this->parentof[$obj->id_son] = $obj->id_parent;
3503 global $conf, $user;
3504 global $hookmanager;
3507 $hookmanager->initHooks(array(
'userdao'));
3509 $this->users = array();
3512 $this->loadParentOf();
3515 $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";
3516 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3518 $parameters = array();
3519 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3521 $sql .= $hookmanager->resPrint;
3523 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3526 $sql .=
" AND ".$filter;
3529 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3533 while ($obj = $this->
db->fetch_object(
$resql)) {
3534 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3535 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3536 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3537 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3538 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3539 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3540 $this->users[$obj->rowid][
'login'] = $obj->login;
3541 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3542 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3543 $this->users[$obj->rowid][
'email'] = $obj->email;
3544 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3545 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3546 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3555 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3556 foreach ($this->users as $key => $val) {
3557 $result = $this->build_path_from_id_user($key, 0);
3559 $this->error =
'ErrorLoopInHierarchy';
3565 if ($deleteafterid) {
3567 $keyfilter1 =
'^'.$deleteafterid.
'$';
3568 $keyfilter2 =
'_'.$deleteafterid.
'$';
3569 $keyfilter3 =
'^'.$deleteafterid.
'_';
3570 $keyfilter4 =
'_'.$deleteafterid.
'_';
3571 foreach ($this->users as $key => $val) {
3572 if (preg_match(
'/'.$keyfilter1.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter2.
'/', $val[
'fullpath'])
3573 || preg_match(
'/'.$keyfilter3.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter4.
'/', $val[
'fullpath'])) {
3574 unset($this->users[$key]);
3579 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
3580 $this->users =
dol_sort_array($this->users,
'fullname',
'asc',
true,
false);
3584 return $this->users;
3597 $childids = array();
3599 if (isset($this->cache_childids[$this->
id])) {
3600 $childids = $this->cache_childids[$this->id];
3603 $this->get_full_tree();
3605 $idtoscan = $this->id;
3607 dol_syslog(
"Build childid for id = ".$idtoscan);
3608 foreach ($this->users as $id => $val) {
3610 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
3611 $childids[$val[
'id']] = $val[
'id'];
3615 $this->cache_childids[$this->id] = $childids;
3617 if ($addcurrentuser) {
3618 $childids[$this->id] = $this->id;
3638 if (!empty($this->users[$id_user][
'fullpath'])) {
3640 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
3645 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
3646 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
3647 $i = 0; $cursor_user = $id_user;
3649 $useridfound = array($id_user);
3650 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
3651 if (in_array($this->parentof[$cursor_user], $useridfound)) {
3652 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
3655 $useridfound[] = $this->parentof[$cursor_user];
3656 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
3657 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
3658 $i++; $cursor_user = $this->parentof[$cursor_user];
3662 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
3696 $this->nb = array();
3698 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
3699 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3700 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
3701 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
3702 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
3703 $sql .=
" AND ug.fk_user = u.rowid";
3705 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3707 $sql .=
" AND u.statut > 0";
3712 while ($obj = $this->
db->fetch_object(
$resql)) {
3713 $this->nb[
"users"] = $obj->nb;
3719 $this->error = $this->
db->error();
3735 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3737 global $conf, $user, $langs;
3739 $langs->load(
"user");
3743 if (!empty($conf->global->USER_ADDON_PDF)) {
3744 $modele = $conf->global->USER_ADDON_PDF;
3746 $modele =
'bluesky';
3750 $modelpath =
"core/modules/user/doc/";
3752 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3766 $user_property =
'';
3768 if (empty($rowid)) {
3772 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
3773 $sql .=
" FROM ".$this->db->prefix().
"user";
3774 $sql .=
" WHERE rowid = ".((int) $rowid);
3778 $nump = $this->
db->num_rows(
$resql);
3781 $obj = $this->
db->fetch_object(
$resql);
3783 if ($mode ==
'email') {
3784 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
3785 } elseif ($mode ==
'mobile') {
3786 $user_property = $obj->user_mobile;
3789 return $user_property;
3807 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter = array(), $filtermode =
'AND', $entityfilter =
false)
3809 global $conf, $user;
3811 $sql =
"SELECT t.rowid";
3812 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
3814 if ($entityfilter) {
3815 if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
3816 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
3817 $sql .=
" WHERE t.entity IS NOT NULL";
3819 $sql .=
",".$this->db->prefix().
"usergroup_user as ug";
3820 $sql .=
" WHERE ((ug.fk_user = t.rowid";
3821 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
3822 $sql .=
" OR t.entity = 0)";
3825 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
3828 $sql .=
" WHERE 1 = 1";
3832 $sqlwhere = array();
3833 if (!empty($filter)) {
3834 foreach ($filter as $key => $value) {
3835 if ($key ==
't.rowid') {
3836 $sqlwhere[] = $key.
" = ".((int) $value);
3837 } elseif (isset($this->fields[$key][
'type']) && in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
3838 $sqlwhere[] = $key.
" = '".$this->
db->idate($value).
"'";
3839 } elseif ($key ==
'customsql') {
3840 $sqlwhere[] = $value;
3842 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
3846 if (count($sqlwhere) > 0) {
3847 $sql .=
' AND ('.implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere).
')';
3849 $sql .= $this->
db->order($sortfield, $sortorder);
3851 $sql .= $this->
db->plimit($limit + 1, $offset);
3858 $this->users = array();
3859 $num = $this->
db->num_rows(
$resql);
3861 while ($obj = $this->
db->fetch_object(
$resql)) {
3862 $line =
new self($this->db);
3863 $result = $line->fetch($obj->rowid);
3864 if ($result > 0 && !empty($line->id)) {
3865 $this->users[$obj->rowid] = clone $line;
3872 $this->errors[] = $this->
db->lasterror();
3884 private $findUserIdByEmailCache;
3898 if (isset($this->findUserIdByEmailCache[$email])) {
3899 return $this->findUserIdByEmailCache[$email];
3902 $this->findUserIdByEmailCache[$email] = -1;
3906 $sql =
'SELECT rowid';
3907 $sql .=
' FROM '.$this->db->prefix().
'user';
3908 if (!empty($conf->global->AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR)) {
3909 $sql .=
" WHERE email LIKE '%".$this->db->escape($email).
"%'";
3911 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
3920 $obj = $this->
db->fetch_object(
$resql);
3925 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
3927 return $this->findUserIdByEmailCache[$email];
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...
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $db, $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.
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.
hasRight($module, $permlevel1, $permlevel2='')
Return if a user has a permission.
getKanbanView($option='')
Return clicable link of object (with eventually picto)
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.
getNbOfUsers($limitTo, $option='', $admin=-1)
Return number of existing users.
fetch($id='', $login='', $sid='', $loadpersonalconf=0, $entity=-1, $email='', $fk_socpeople=0)
Load a user from database with its id or ref (login).
set_default_rights()
Assign rights by default.
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.
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
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.
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.
_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 new password by email.
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.
setPassword($user, $password='', $changelater=0, $notrigger=0, $nosyncmember=0, $passwordalreadycrypted=0)
Change password of a user.
findUserIdByEmail($email)
Find a user by the given e-mail and return it's user id when found.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
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)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
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.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
getArrayOfSocialNetworks()
Get array of social network dictionary.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.
getUserRemoteIP()
Return the IP of remote user.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dolEncrypt($chain, $key='', $ciphering='AES-256-CTR', $forceseed='')
Encode a string with a 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')
Returns a hash (non reversible encryption) of a string.
$conf db
API class for accounts.