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';
41 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonpeople.class.php';
54 public $element =
'user';
59 public $table_element =
'user';
64 public $fk_element =
'fk_user';
70 public $ismultientitymanaged = 1;
75 public $isextrafieldmanaged = 1;
80 public $picto =
'user';
94 public $civility_code;
116 public $personal_email;
121 public $socialnetworks;
136 public $office_phone;
151 public $personal_mobile;
181 public $pass_crypted;
186 public $pass_indatabase;
191 public $pass_indatabase_crypted;
235 public $fk_user_expense_validator;
240 public $fk_user_holiday_validator;
250 public $clicktodial_login;
255 public $clicktodial_password;
260 public $clicktodial_poste;
265 public $clicktodial_loaded;
268 public $datelastlogin;
269 public $datepreviouslogin;
270 public $flagdelsessionsbefore;
272 public $ippreviouslogin;
273 public $datestartvalidity;
274 public $dateendvalidity;
290 public $all_permissions_are_loaded;
300 public $user_group_list;
305 private $_tab_loaded = array();
312 public $default_values;
314 public $lastsearch_values_tmp;
315 public $lastsearch_values;
317 public $users = array();
319 private $cache_childids;
321 public $accountancy_code;
335 public $dateemployment;
336 public $dateemploymentend;
338 public $default_c_exp_tax_cat;
343 public $ref_employee;
348 public $national_registration_number;
350 public $default_range;
355 public $fk_warehouse;
360 public $egroupware_id;
362 public $fields = array(
363 'rowid'=>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'index'=>1,
'position'=>1,
'comment'=>
'Id'),
364 'lastname'=>array(
'type'=>
'varchar(50)',
'label'=>
'LastName',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>20,
'searchall'=>1),
365 'firstname'=>array(
'type'=>
'varchar(50)',
'label'=>
'FirstName',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>10,
'searchall'=>1),
366 'ref_employee'=>array(
'type'=>
'varchar(50)',
'label'=>
'RefEmployee',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>30,
'searchall'=>1),
367 'national_registration_number'=>array(
'type'=>
'varchar(50)',
'label'=>
'NationalRegistrationNumber',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>40,
'searchall'=>1)
371 const STATUS_DISABLED = 0;
372 const STATUS_ENABLED = 1;
386 $this->clicktodial_loaded = 0;
389 $this->all_permissions_are_loaded = 0;
390 $this->nb_rights = 0;
396 $this->
conf =
new stdClass();
397 $this->rights =
new stdClass();
398 $this->rights->user =
new stdClass();
399 $this->rights->user->user =
new stdClass();
400 $this->rights->user->self =
new stdClass();
401 $this->rights->user->user_advance =
new stdClass();
402 $this->rights->user->self_advance =
new stdClass();
403 $this->rights->user->group_advance =
new stdClass();
419 public function fetch($id =
'', $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'', $fk_socpeople = 0)
424 $login = trim($login);
427 $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,";
428 $sql .=
" u.socialnetworks,";
429 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
430 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
431 $sql .=
" u.admin, u.login, u.note_private, u.note_public,";
432 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.api_key,";
433 $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,";
434 $sql .=
" u.statut as status, u.lang, u.entity,";
435 $sql .=
" u.datec as datec,";
436 $sql .=
" u.tms as datem,";
437 $sql .=
" u.datelastlogin as datel,";
438 $sql .=
" u.datepreviouslogin as datep,";
439 $sql .=
" u.flagdelsessionsbefore,";
440 $sql .=
" u.iplastlogin,";
441 $sql .=
" u.ippreviouslogin,";
442 $sql .=
" u.datelastpassvalidation,";
443 $sql .=
" u.datestartvalidity,";
444 $sql .=
" u.dateendvalidity,";
445 $sql .=
" u.photo as photo,";
446 $sql .=
" u.openid as openid,";
447 $sql .=
" u.accountancy_code,";
450 $sql .=
" u.salary,";
451 $sql .=
" u.salaryextra,";
452 $sql .=
" u.weeklyhours,";
454 $sql .=
" u.dateemployment, u.dateemploymentend,";
455 $sql .=
" u.fk_warehouse,";
456 $sql .=
" u.ref_ext,";
457 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
458 $sql .=
" u.national_registration_number,";
459 $sql .=
" u.ref_employee,";
460 $sql .=
" c.code as country_code, c.label as country,";
461 $sql .=
" d.code_departement as state_code, d.nom as state";
462 $sql .=
" FROM ".$this->db->prefix().
"user as u";
463 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as c ON u.fk_country = c.rowid";
464 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_departements as d ON u.fk_state = d.rowid";
467 if ((!
isModEnabled(
'multicompany') || empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) && (!empty($user->entity))) {
468 $sql .=
" WHERE u.entity IN (0, ".((int) $conf->entity).
")";
470 $sql .=
" WHERE u.entity IS NOT NULL";
474 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
475 $sql .=
" WHERE u.entity IS NOT NULL";
477 $sql .=
" WHERE u.entity IN (0, ".((int) (($entity !=
'' && $entity >= 0) ? $entity : $conf->entity)).
")";
483 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->db->escape($login).
"')";
485 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
487 $sql .=
" AND u.email = '".$this->db->escape($email).
"'";
488 } elseif ($fk_socpeople > 0) {
489 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
491 $sql .=
" AND u.rowid = ".((int) $id);
493 $sql .=
" ORDER BY u.entity ASC";
497 $sql .=
' '.$this->db->plimit(1);
500 $result = $this->db->query(
$sql);
502 $obj = $this->db->fetch_object($result);
504 $this->
id = $obj->rowid;
505 $this->
ref = $obj->rowid;
507 $this->ref_ext = $obj->ref_ext;
509 $this->ldap_sid = $obj->ldap_sid;
510 $this->civility_code = $obj->civility_code;
511 $this->lastname = $obj->lastname;
512 $this->firstname = $obj->firstname;
513 $this->ref_employee = $obj->ref_employee;
514 $this->national_registration_number = $obj->national_registration_number;
516 $this->employee = $obj->employee;
518 $this->login = $obj->login;
519 $this->gender = $obj->gender;
520 $this->birth = $this->db->jdate($obj->birth);
521 $this->pass_indatabase = $obj->pass;
522 $this->pass_indatabase_crypted = $obj->pass_crypted;
523 $this->pass = $obj->pass;
524 $this->pass_temp = $obj->pass_temp;
527 $this->address = $obj->address;
528 $this->zip = $obj->zip;
529 $this->town = $obj->town;
531 $this->country_id = $obj->country_id;
532 $this->country_code = $obj->country_id ? $obj->country_code :
'';
535 $this->state_id = $obj->state_id;
536 $this->state_code = $obj->state_code;
537 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
539 $this->office_phone = $obj->office_phone;
540 $this->office_fax = $obj->office_fax;
541 $this->user_mobile = $obj->user_mobile;
542 $this->personal_mobile = $obj->personal_mobile;
543 $this->email = $obj->email;
544 $this->personal_email = $obj->personal_email;
545 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
546 $this->job = $obj->job;
547 $this->signature = $obj->signature;
548 $this->admin = $obj->admin;
549 $this->note_public = $obj->note_public;
550 $this->note_private = $obj->note_private;
551 $this->note = $obj->note_private;
553 $this->statut = $obj->status;
554 $this->status = $obj->status;
556 $this->photo = $obj->photo;
557 $this->openid = $obj->openid;
558 $this->lang = $obj->lang;
559 $this->entity = $obj->entity;
560 $this->accountancy_code = $obj->accountancy_code;
561 $this->thm = $obj->thm;
562 $this->tjm = $obj->tjm;
563 $this->salary = $obj->salary;
564 $this->salaryextra = $obj->salaryextra;
565 $this->weeklyhours = $obj->weeklyhours;
566 $this->color = $obj->color;
567 $this->dateemployment = $this->db->jdate($obj->dateemployment);
568 $this->dateemploymentend = $this->db->jdate($obj->dateemploymentend);
570 $this->datec = $this->db->jdate($obj->datec);
571 $this->datem = $this->db->jdate($obj->datem);
572 $this->datelastlogin = $this->db->jdate($obj->datel);
573 $this->datepreviouslogin = $this->db->jdate($obj->datep);
574 $this->flagdelsessionsbefore = $this->db->jdate($obj->flagdelsessionsbefore,
'gmt');
575 $this->iplastlogin = $obj->iplastlogin;
576 $this->ippreviouslogin = $obj->ippreviouslogin;
577 $this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
578 $this->dateendvalidity = $this->db->jdate($obj->dateendvalidity);
580 $this->socid = $obj->fk_soc;
581 $this->contact_id = $obj->fk_socpeople;
582 $this->fk_member = $obj->fk_member;
583 $this->fk_user = $obj->fk_user;
584 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
585 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
587 $this->default_range = $obj->default_range;
588 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
589 $this->fk_warehouse = $obj->fk_warehouse;
593 if (!
isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
601 $this->db->free($result);
603 $this->
error =
"USERNOTFOUND";
604 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
606 $this->db->free($result);
610 $this->
error = $this->db->lasterror();
615 if ($loadpersonalconf) {
617 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
618 $sql .=
" WHERE fk_user = ".((int) $this->
id);
619 $sql .=
" AND entity = ".((int) $conf->entity);
621 $resql = $this->db->query(
$sql);
623 $num = $this->db->num_rows($resql);
626 $obj = $this->db->fetch_object($resql);
627 $p = (!empty($obj->param) ? $obj->param :
'');
629 $this->
conf->$p = $obj->value;
633 $this->db->free($resql);
635 $this->
error = $this->db->lasterror();
642 $this->
error = $this->db->lasterror();
658 if (!empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) {
660 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
663 $result = $defaultValues->fetchAll(
'',
'', 0, 0, array(
't.user_id'=>array(0, $this->
id),
'entity'=>array((isset($this->entity) ? $this->entity : $conf->entity), $conf->entity)));
665 if (!is_array($result) && $result < 0) {
669 } elseif (count($result) > 0) {
670 foreach ($result as $defval) {
671 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
672 $pagewithoutquerystring = $defval->page;
675 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
676 $pagewithoutquerystring = $reg[1];
677 $pagequeries = $reg[2];
679 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
683 if (!empty($this->default_values)) {
684 foreach ($this->default_values as $a => $b) {
685 foreach ($b as $c => $d) {
686 krsort($this->default_values[$a][$c]);
705 public function hasRight($module, $permlevel1, $permlevel2 =
'')
708 $moduletomoduletouse = array(
709 'compta' =>
'comptabilite',
710 'contract' =>
'contrat',
711 'member' =>
'adherent',
713 'order' =>
'commande',
714 'produit' =>
'product',
715 'project' =>
'projet',
716 'propale' =>
'propal',
717 'shipping' =>
'expedition',
718 'task' =>
'task@projet',
719 'fichinter' =>
'ficheinter',
720 'inventory' =>
'stock',
721 'invoice' =>
'facture',
722 'invoice_supplier' =>
'fournisseur',
723 'order_supplier' =>
'fournisseur',
724 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
725 'skill@hrm' =>
'all@hrm',
726 'job@hrm' =>
'all@hrm',
727 'position@hrm' =>
'all@hrm',
728 'facturerec' =>
'facture',
729 'margins' =>
'margin',
732 if (!empty($moduletomoduletouse[$module])) {
733 $module = $moduletomoduletouse[$module];
736 $moduleRightsMapping = array(
737 'product' =>
'produit',
738 'margin' =>
'margins',
739 'comptabilite' =>
'compta'
742 $rightsPath = $module;
743 if (!empty($moduleRightsMapping[$rightsPath])) {
744 $rightsPath = $moduleRightsMapping[$rightsPath];
748 $tmp = explode(
'@', $rightsPath, 2);
749 if (!empty($tmp[1])) {
750 if (strpos($module,
'@') !==
false) {
753 $rightsPath = $tmp[1];
754 $permlevel2 = $permlevel1;
755 $permlevel1 = $tmp[0];
770 if ($permlevel1 ==
'propale') {
771 $permlevel1 =
'propal';
773 if ($permlevel1 ==
'member') {
774 $permlevel1 =
'adherent';
776 if ($permlevel1 ==
'recruitmentcandidature') {
777 $permlevel1 =
'recruitmentjobposition';
782 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
787 if (!empty($this->rights->$rightsPath->$permlevel1)) {
788 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
789 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
793 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
794 return $this->rights->$rightsPath->$permlevel1->lire;
796 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
797 return $this->rights->$rightsPath->$permlevel1->creer;
799 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
800 return $this->rights->$rightsPath->$permlevel1->create;
802 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
803 return $this->rights->$rightsPath->$permlevel1->supprimer;
807 if (!empty($this->rights->$rightsPath->$permlevel1)) {
808 return $this->rights->$rightsPath->$permlevel1;
812 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
813 return $this->rights->$rightsPath->lire;
815 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
816 return $this->rights->$rightsPath->creer;
818 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
819 return $this->rights->$rightsPath->create;
821 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
822 return $this->rights->$rightsPath->supprimer;
840 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
842 global $conf, $user, $langs;
844 $entity = (empty($entity) ? $conf->entity : $entity);
846 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
848 if (empty($this->
id)) {
849 $this->
error =
'Try to call addrights on an object user with an empty id';
859 $module = $perms = $subperms =
'';
862 $sql =
"SELECT module, perms, subperms";
863 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
864 $sql .=
" WHERE id = ".((int) $rid);
865 $sql .=
" AND entity = ".((int) $entity);
867 $result = $this->db->query(
$sql);
869 $obj = $this->db->fetch_object($result);
872 $module = $obj->module;
873 $perms = $obj->perms;
874 $subperms = $obj->subperms;
882 $whereforadd =
"id=".((int) $rid);
884 if (!empty($subperms)) {
885 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
886 } elseif (!empty($perms)) {
887 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
893 if (!empty($allmodule)) {
894 if ($allmodule ==
'allmodules') {
895 $whereforadd =
'allmodules';
897 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
898 if (!empty($allperms)) {
899 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
907 if (!empty($whereforadd)) {
910 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
911 $sql .=
" WHERE entity = ".((int) $entity);
912 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
913 $sql .=
" AND (".$whereforadd.
")";
916 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
917 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
919 $sqldelete .=
") AND entity = ".((int) $entity);
920 if (!$this->db->query($sqldelete)) {
925 $resql = $this->db->query(
$sql);
927 $num = $this->db->num_rows($resql);
930 $obj = $this->db->fetch_object($resql);
935 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
936 if (!$this->db->query(
$sql)) {
950 if (!$error && !$notrigger) {
951 $langs->load(
"other");
952 $this->context = array(
'audit'=>$langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
963 $this->db->rollback();
983 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
985 global $conf, $user, $langs;
989 $entity = (!empty($entity) ? $entity : $conf->entity);
994 $module = $perms = $subperms =
'';
998 $sql =
"SELECT module, perms, subperms";
999 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1000 $sql .=
" WHERE id = '".$this->db->escape($rid).
"'";
1001 $sql .=
" AND entity = ".((int) $entity);
1003 $result = $this->db->query(
$sql);
1005 $obj = $this->db->fetch_object($result);
1008 $module = $obj->module;
1009 $perms = $obj->perms;
1010 $subperms = $obj->subperms;
1018 $wherefordel =
"id=".((int) $rid);
1020 if ($subperms ==
'lire' || $subperms ==
'read') {
1021 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1023 if ($perms ==
'lire' || $perms ==
'read') {
1024 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1029 if (!empty($allmodule)) {
1030 if ($allmodule ==
'allmodules') {
1031 $wherefordel =
'allmodules';
1033 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1034 if (!empty($allperms)) {
1035 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1042 if (!empty($wherefordel)) {
1045 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1046 $sql .=
" WHERE entity = ".((int) $entity);
1047 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1048 $sql .=
" AND (".$wherefordel.
")";
1052 if ($this->admin == 1) {
1053 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1054 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1055 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1056 $sql .=
" AND id NOT IN (358)";
1059 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1060 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1063 $sqldelete .=
" AND entity = ".((int) $entity);
1065 $resql = $this->db->query($sqldelete);
1072 if (!$error && !$notrigger) {
1073 $langs->load(
"other");
1074 $this->context = array(
'audit'=>$langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1085 $this->db->rollback();
1088 $this->db->commit();
1102 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1103 $this->rights =
null;
1104 $this->nb_rights = 0;
1105 $this->all_permissions_are_loaded = 0;
1106 $this->_tab_loaded = array();
1118 public function getrights($moduletag =
'', $forcereload = 0)
1122 if (empty($forcereload)) {
1123 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1128 if (!empty($this->all_permissions_are_loaded)) {
1135 if (!isset($this->rights) || !is_object($this->rights)) {
1136 $this->rights =
new stdClass();
1138 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1139 $this->rights->user =
new stdClass();
1145 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1146 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1147 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1148 $sql .=
" WHERE r.id = ur.fk_id";
1149 if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
1151 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ?
"1," :
"").$conf->entity.
")";
1155 $sql .=
" AND r.entity = ".((int) $conf->entity).
" AND ur.entity = ".((int) $conf->entity);
1157 $sql .=
" AND ur.fk_user= ".((int) $this->
id);
1158 $sql .=
" AND r.perms IS NOT NULL";
1160 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1163 $resql = $this->db->query(
$sql);
1165 $num = $this->db->num_rows($resql);
1168 $obj = $this->db->fetch_object($resql);
1171 $module = $obj->module;
1172 $perms = $obj->perms;
1173 $subperms = $obj->subperms;
1175 if (!empty($perms)) {
1176 if (!empty($module)) {
1177 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1178 $this->rights->$module =
new stdClass();
1180 if (!empty($subperms)) {
1181 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1182 $this->rights->$module->$perms =
new stdClass();
1184 if (empty($this->rights->$module->$perms->$subperms)) {
1187 $this->rights->$module->$perms->$subperms = 1;
1189 if (empty($this->rights->$module->$perms)) {
1192 $this->rights->$module->$perms = 1;
1199 $this->db->free($resql);
1203 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1204 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1205 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1206 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1207 $sql .=
" WHERE r.id = gr.fk_id";
1209 if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
1210 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1211 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1213 $sql .=
" AND r.entity = ".((int) $conf->entity);
1216 $sql .=
" AND gr.entity = ".((int) $conf->entity);
1220 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1221 $sql .=
" AND r.entity = ".((int) $conf->entity);
1224 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1225 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1226 $sql .=
" AND r.perms IS NOT NULL";
1228 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1231 $resql = $this->db->query(
$sql);
1233 $num = $this->db->num_rows($resql);
1236 $obj = $this->db->fetch_object($resql);
1239 $module = $obj->module;
1240 $perms = $obj->perms;
1241 $subperms = $obj->subperms;
1243 if (!empty($perms)) {
1244 if (!empty($module)) {
1245 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1246 $this->rights->$module =
new stdClass();
1248 if (!empty($subperms)) {
1249 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1250 $this->rights->$module->$perms =
new stdClass();
1252 if (empty($this->rights->$module->$perms->$subperms)) {
1255 $this->rights->$module->$perms->$subperms = 1;
1257 if (empty($this->rights->$module->$perms)) {
1261 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1262 $this->rights->$module->$perms = 1;
1270 $this->db->free($resql);
1274 if (!empty($this->admin)) {
1275 if (empty($this->rights->user->user)) {
1276 $this->rights->user->user =
new stdClass();
1278 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1279 foreach ($listofpermtotest as $permtotest) {
1280 if (empty($this->rights->user->user->$permtotest)) {
1281 $this->rights->user->user->$permtotest = 1;
1285 if (empty($this->rights->user->self)) {
1286 $this->rights->user->self =
new stdClass();
1288 $listofpermtotest = array(
'creer',
'password');
1289 foreach ($listofpermtotest as $permtotest) {
1290 if (empty($this->rights->user->self->$permtotest)) {
1291 $this->rights->user->self->$permtotest = 1;
1296 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
1297 if (empty($this->rights->user->user_advance)) {
1298 $this->rights->user->user_advance =
new stdClass();
1300 $listofpermtotest = array(
'readperms',
'write');
1301 foreach ($listofpermtotest as $permtotest) {
1302 if (empty($this->rights->user->user_advance->$permtotest)) {
1303 $this->rights->user->user_advance->$permtotest = 1;
1307 if (empty($this->rights->user->self_advance)) {
1308 $this->rights->user->self_advance =
new stdClass();
1310 $listofpermtotest = array(
'readperms',
'writeperms');
1311 foreach ($listofpermtotest as $permtotest) {
1312 if (empty($this->rights->user->self_advance->$permtotest)) {
1313 $this->rights->user->self_advance->$permtotest = 1;
1317 if (empty($this->rights->user->group_advance)) {
1318 $this->rights->user->group_advance =
new stdClass();
1320 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1321 foreach ($listofpermtotest as $permtotest) {
1322 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1323 $this->rights->user->group_advance->$permtotest = 1;
1331 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1332 $this->rights->propal = $this->rights->propale;
1334 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1335 $this->rights->propale = $this->rights->propal;
1341 $this->all_permissions_are_loaded = 1;
1344 $this->_tab_loaded[$moduletag] = 1;
1356 global $conf, $langs, $user;
1361 if (isset($this->statut)) {
1362 if ($this->statut == $status) {
1365 } elseif (isset($this->status) && $this->status == $status) {
1372 $sql =
"UPDATE ".$this->db->prefix().
"user";
1373 $sql .=
" SET statut = ".((int) $status);
1374 $sql .=
" WHERE rowid = ".((int) $this->
id);
1375 $result = $this->db->query(
$sql);
1377 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1380 $result = $this->
call_trigger(
'USER_ENABLEDISABLE', $user);
1388 $this->db->rollback();
1391 $this->status = $status;
1392 $this->statut = $status;
1393 $this->db->commit();
1410 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1411 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1422 global $conf, $langs;
1428 $this->
fetch($this->
id);
1430 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1433 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1435 if (!$error && !$this->db->query(
$sql)) {
1437 $this->
error = $this->db->lasterror();
1441 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1442 if (!$error && !$this->db->query(
$sql)) {
1444 $this->
error = $this->db->lasterror();
1448 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1449 if (!$error && !$this->db->query(
$sql)) {
1451 $this->
error = $this->db->lasterror();
1455 if ($this->contact_id > 0) {
1456 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1457 if (!$error && !$this->db->query(
$sql)) {
1459 $this->
error = $this->db->lasterror();
1468 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1474 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1475 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1476 if (!$this->db->query(
$sql)) {
1478 $this->
error = $this->db->lasterror();
1487 $this->db->rollback();
1492 $this->db->commit();
1495 $this->db->rollback();
1507 public function create($user, $notrigger = 0)
1509 global $conf, $langs;
1515 $this->civility_code = trim((
string) $this->civility_code);
1516 $this->login = trim((
string) $this->login);
1517 if (!isset($this->entity)) {
1518 $this->entity = $conf->entity;
1521 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1523 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1526 if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1527 $langs->load(
"errors");
1528 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1531 if (empty($this->login)) {
1532 $langs->load(
"errors");
1533 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1535 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1536 $langs->load(
"errors");
1537 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1548 $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).
"'";
1549 $resqltochecklogin = $this->db->query($sqltochecklogin);
1550 if ($resqltochecklogin) {
1551 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1552 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1553 $langs->load(
"errors");
1554 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1556 $this->db->rollback();
1559 $this->db->free($resqltochecklogin);
1562 if (!empty($this->email)) {
1563 $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).
"'";
1564 $resqltochecklogin = $this->db->query($sqltochecklogin);
1565 if ($resqltochecklogin) {
1566 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1567 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1568 $langs->load(
"errors");
1569 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
1571 $this->db->rollback();
1574 $this->db->free($resqltochecklogin);
1579 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, entity)";
1580 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->db->escape($this->login).
"', '".$this->db->escape($this->ldap_sid).
"', ".((int) $this->entity).
")";
1581 $result = $this->db->query(
$sql);
1583 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1585 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1589 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1590 $this->db->rollback();
1594 if (!empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER) && !empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) {
1595 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1596 $langs->load(
"stocks");
1597 $entrepot =
new Entrepot($this->db);
1598 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1599 $entrepot->libelle = $entrepot->label;
1600 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1601 $entrepot->statut = 1;
1602 $entrepot->country_id = $mysoc->country_id;
1603 $warehouseid = $entrepot->create($user);
1605 $this->fk_warehouse = $warehouseid;
1609 $result = $this->
update($user, 1, 1);
1611 $this->db->rollback();
1625 $this->db->commit();
1630 $this->db->rollback();
1634 $this->
error = $this->db->lasterror();
1635 $this->db->rollback();
1653 global $conf, $user, $langs;
1659 $this->civility_code = $contact->civility_code;
1660 $this->lastname = $contact->lastname;
1661 $this->firstname = $contact->firstname;
1662 $this->gender = $contact->gender;
1663 $this->email = $contact->email;
1664 $this->socialnetworks = $contact->socialnetworks;
1665 $this->office_phone = $contact->phone_pro;
1666 $this->office_fax = $contact->fax;
1667 $this->user_mobile = $contact->phone_mobile;
1668 $this->address = $contact->address;
1669 $this->zip = $contact->zip;
1670 $this->town = $contact->town;
1672 $this->state_id = $contact->state_id;
1673 $this->country_id = $contact->country_id;
1674 $this->employee = 0;
1676 if (empty($login)) {
1677 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1678 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1680 $this->login = $login;
1685 $result = $this->
create($user, 1);
1687 $sql =
"UPDATE ".$this->db->prefix().
"user";
1688 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1689 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1690 if ($contact->socid > 0) {
1691 $sql .=
", fk_soc=".((int) $contact->socid);
1693 $sql .=
" WHERE rowid=".((int) $this->
id);
1695 $resql = $this->db->query(
$sql);
1697 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1699 $this->context[
'createfromcontact'] =
'createfromcontact';
1704 $error++; $this->db->rollback();
return -1;
1708 $this->db->commit();
1711 $this->
error = $this->db->error();
1713 $this->db->rollback();
1718 dol_syslog(get_class($this).
"::create_from_contact - 0");
1720 $this->db->rollback();
1737 global $conf, $user, $langs;
1741 $this->civility_code = $member->civility_id;
1742 $this->lastname = $member->lastname;
1743 $this->firstname = $member->firstname;
1744 $this->gender = $member->gender;
1745 $this->email = $member->email;
1746 $this->fk_member = $member->id;
1747 $this->address = $member->address;
1748 $this->zip = $member->zip;
1749 $this->town = $member->town;
1751 $this->state_id = $member->state_id;
1752 $this->country_id = $member->country_id;
1753 $this->socialnetworks = $member->socialnetworks;
1755 $this->pass = $member->pass;
1756 $this->pass_crypted = $member->pass_indatabase_crypted;
1758 if (empty($login)) {
1759 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1762 $this->login = $login;
1767 $result = $this->
create($user);
1769 if (!empty($this->pass)) {
1770 $newpass = $this->
setPassword($user, $this->pass);
1771 if (is_numeric($newpass) && $newpass < 0) {
1774 } elseif (!empty($this->pass_crypted)) {
1775 $sql =
"UPDATE ".$this->db->prefix().
"user";
1776 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
1777 $sql .=
" WHERE rowid=".((int) $this->
id);
1779 $resql = $this->db->query(
$sql);
1785 if ($result > 0 && $member->socid) {
1786 $sql =
"UPDATE ".$this->db->prefix().
"user";
1787 $sql .=
" SET fk_soc=".((int) $member->socid);
1788 $sql .=
" WHERE rowid=".((int) $this->
id);
1790 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
1791 $resql = $this->db->query(
$sql);
1793 $this->db->commit();
1796 $this->
error = $this->db->lasterror();
1798 $this->db->rollback();
1805 $this->db->commit();
1809 $this->db->rollback();
1827 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
1828 $sql .=
" WHERE bydefault = 1";
1829 $sql .=
" AND entity = ".((int) $conf->entity);
1831 $resql = $this->db->query(
$sql);
1833 $num = $this->db->num_rows($resql);
1836 $row = $this->db->fetch_row($resql);
1840 $this->db->free($resql);
1844 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
1845 $result = $this->db->query(
$sql);
1847 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
1848 $result = $this->db->query(
$sql);
1868 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
1870 global $conf, $langs;
1872 $nbrowsaffected = 0;
1875 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
1878 $this->civility_code = trim((
string) $this->civility_code);
1879 $this->lastname = trim((
string) $this->lastname);
1880 $this->firstname = trim((
string) $this->firstname);
1881 $this->ref_employee = trim((
string) $this->ref_employee);
1882 $this->national_registration_number = trim((
string) $this->national_registration_number);
1883 $this->employee = ($this->employee > 0 ? $this->employee : 0);
1884 $this->login = trim((
string) $this->login);
1885 $this->gender = trim((
string) $this->gender);
1887 $this->pass = trim((
string) $this->pass);
1888 $this->api_key = trim((
string) $this->api_key);
1889 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
1890 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
1892 $this->address = trim((
string) $this->address);
1893 $this->zip = trim((
string) $this->zip);
1894 $this->town = trim((
string) $this->town);
1896 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
1897 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
1898 $this->office_phone = trim((
string) $this->office_phone);
1899 $this->office_fax = trim((
string) $this->office_fax);
1900 $this->user_mobile = trim((
string) $this->user_mobile);
1901 $this->personal_mobile = trim((
string) $this->personal_mobile);
1902 $this->email = trim((
string) $this->email);
1903 $this->personal_email = trim((
string) $this->personal_email);
1905 $this->job = trim((
string) $this->job);
1906 $this->signature = trim((
string) $this->signature);
1907 $this->note_public = trim((
string) $this->note_public);
1908 $this->note_private = trim((
string) $this->note_private);
1909 $this->openid = trim((
string) $this->openid);
1910 $this->admin = ($this->admin > 0 ? $this->admin : 0);
1912 $this->accountancy_code = trim((
string) $this->accountancy_code);
1913 $this->color = trim((
string) $this->color);
1914 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
1915 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
1917 $this->birth = empty($this->birth) ?
'' : $this->birth;
1918 $this->fk_warehouse = (int) $this->fk_warehouse;
1923 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1925 if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1926 $langs->load(
"errors");
1927 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1930 if (empty($this->login)) {
1931 $langs->load(
"errors");
1932 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
1934 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1935 $langs->load(
"errors");
1936 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1943 if (!empty($this->oldcopy) && $this->oldcopy->login != $this->login) {
1944 $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).
"'";
1945 $resqltochecklogin = $this->db->query($sqltochecklogin);
1946 if ($resqltochecklogin) {
1947 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1948 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1949 $langs->load(
"errors");
1950 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1952 $this->db->rollback();
1957 if (!empty($this->oldcopy) && !empty($this->email) && $this->oldcopy->email != $this->email) {
1958 $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).
"'";
1959 $resqltochecklogin = $this->db->query($sqltochecklogin);
1960 if ($resqltochecklogin) {
1961 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1962 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1963 $langs->load(
"errors");
1964 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
1966 $this->db->rollback();
1973 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
1974 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
1975 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
1976 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
1977 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
1978 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
1979 $sql .=
", employee = ".(int) $this->employee;
1980 $sql .=
", login = '".$this->db->escape($this->login).
"'";
1981 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
1982 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
1983 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
1984 if (!empty($user->admin)) {
1985 $sql .=
", admin = ".(int) $this->admin;
1987 $sql .=
", address = '".$this->db->escape($this->address).
"'";
1988 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
1989 $sql .=
", town = '".$this->db->escape($this->town).
"'";
1990 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".$this->db->escape($this->state_id).
"'" :
"null");
1991 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".$this->db->escape($this->country_id).
"'" :
"null");
1992 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
1993 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
1994 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
1995 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
1996 $sql .=
", email = '".$this->db->escape($this->email).
"'";
1997 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
1998 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1999 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2000 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2001 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2002 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2003 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2004 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2005 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2006 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2007 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2008 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2009 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2010 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2011 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".$this->db->escape($this->fk_user).
"'" :
"null");
2012 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".$this->db->escape($this->fk_user_expense_validator).
"'" :
"null");
2013 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".$this->db->escape($this->fk_user_holiday_validator).
"'" :
"null");
2014 if (isset($this->thm) || $this->thm !=
'') {
2015 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2017 if (isset($this->tjm) || $this->tjm !=
'') {
2018 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2020 if (isset($this->salary) || $this->salary !=
'') {
2021 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2023 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2024 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2026 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2027 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2028 $sql .=
", entity = ".((int) $this->entity);
2030 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2031 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2032 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2033 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2034 $sql .=
" WHERE rowid = ".((int) $this->
id);
2036 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2037 $resql = $this->db->query(
$sql);
2039 $nbrowsaffected += $this->db->affected_rows($resql);
2042 if (!empty($this->pass)) {
2043 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2045 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2046 if (is_numeric($result) && $result < 0) {
2053 if ($this->fk_member > 0) {
2054 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2055 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2056 $resql = $this->db->query(
$sql);
2058 $this->
error = $this->db->error(); $this->db->rollback();
return -5;
2062 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2063 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2064 $resql = $this->db->query(
$sql);
2066 $this->
error = $this->db->error(); $this->db->rollback();
return -5;
2069 if ($nbrowsaffected) {
2070 if ($this->fk_member > 0 && !$nosyncmember) {
2071 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2073 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2078 $result = $adh->fetch($this->fk_member);
2081 $adh->civility_code = $this->civility_code;
2082 $adh->firstname = $this->firstname;
2083 $adh->lastname = $this->lastname;
2084 $adh->login = $this->login;
2085 $adh->gender = $this->gender;
2086 $adh->birth = $this->birth;
2088 $adh->pass = $this->pass;
2090 $adh->address = $this->address;
2091 $adh->town = $this->town;
2092 $adh->zip = $this->zip;
2093 $adh->state_id = $this->state_id;
2094 $adh->country_id = $this->country_id;
2096 $adh->email = $this->email;
2098 $adh->socialnetworks = $this->socialnetworks;
2100 $adh->phone = $this->office_phone;
2101 $adh->phone_mobile = $this->user_mobile;
2103 $adh->default_lang = $this->lang;
2105 $adh->user_id = $this->id;
2106 $adh->user_login = $this->login;
2108 $result = $adh->update($user, 0, 1, 0);
2110 $this->
error = $adh->error;
2111 $this->errors = $adh->errors;
2112 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2115 } elseif ($result < 0) {
2116 $this->
error = $adh->error;
2117 $this->errors = $adh->errors;
2122 if ($this->contact_id > 0 && !$nosynccontact) {
2123 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2125 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2128 $tmpobj =
new Contact($this->db);
2129 $result = $tmpobj->fetch($this->contact_id);
2132 $tmpobj->civility_code = $this->civility_code;
2133 $tmpobj->firstname = $this->firstname;
2134 $tmpobj->lastname = $this->lastname;
2135 $tmpobj->login = $this->login;
2136 $tmpobj->gender = $this->gender;
2137 $tmpobj->birth = $this->birth;
2141 $tmpobj->email = $this->email;
2143 $tmpobj->socialnetworks = $this->socialnetworks;
2145 $tmpobj->phone_pro = $this->office_phone;
2146 $tmpobj->phone_mobile = $this->user_mobile;
2147 $tmpobj->fax = $this->office_fax;
2149 $tmpobj->default_lang = $this->lang;
2151 $tmpobj->address = $this->address;
2152 $tmpobj->town = $this->town;
2153 $tmpobj->zip = $this->zip;
2154 $tmpobj->state_id = $this->state_id;
2155 $tmpobj->country_id = $this->country_id;
2157 $tmpobj->user_id = $this->id;
2158 $tmpobj->user_login = $this->login;
2160 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2162 $this->
error = $tmpobj->error;
2163 $this->errors = $tmpobj->errors;
2164 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2168 $this->
error = $tmpobj->error;
2169 $this->errors = $tmpobj->errors;
2185 if (!$error && !$notrigger) {
2195 $this->db->commit();
2196 return $nbrowsaffected;
2199 $this->db->rollback();
2203 $this->
error = $this->db->lasterror();
2204 $this->db->rollback();
2223 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2224 $sql .=
" datepreviouslogin = datelastlogin,";
2225 $sql .=
" ippreviouslogin = iplastlogin,";
2226 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2227 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2228 $sql .=
" tms = tms";
2229 $sql .=
" WHERE rowid = ".((int) $this->
id);
2231 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".
$sql, LOG_DEBUG);
2232 $resql = $this->db->query(
$sql);
2234 $this->datepreviouslogin = $this->datelastlogin;
2235 $this->datelastlogin = $now;
2236 $this->ippreviouslogin = $this->iplastlogin;
2237 $this->iplastlogin = $userremoteip;
2240 $this->
error = $this->db->lasterror().
' sql='.
$sql;
2258 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2260 global $conf, $langs;
2261 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2265 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2273 if (empty($passwordalreadycrypted)) {
2274 if (!empty($conf->global->USER_PASSWORD_GENERATED)) {
2276 $modGeneratePassClass =
'modGeneratePass'.ucfirst($conf->global->USER_PASSWORD_GENERATED);
2278 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2279 if (class_exists($modGeneratePassClass)) {
2280 $modGeneratePass =
new $modGeneratePassClass($this->db, $conf, $langs, $user);
2283 $modGeneratePass->WithoutAmbi = 0;
2286 $testpassword = $modGeneratePass->validatePassword($password);
2287 if (!$testpassword) {
2288 $this->
error = $modGeneratePass->error;
2296 $password_crypted =
dol_hash($password);
2300 if (!$changelater) {
2301 if (!is_object($this->oldcopy)) {
2302 $this->oldcopy = clone $this;
2307 $sql =
"UPDATE ".$this->db->prefix().
"user";
2308 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2309 $sql .=
" pass_temp = null";
2310 if (!empty($flagdelsessionsbefore)) {
2311 $sql .=
", flagdelsessionsbefore = '".$this->db->idate(
dol_now() - 5,
'gmt').
"'";
2313 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
2314 $sql .=
", pass = null";
2316 $sql .=
", pass = '".$this->db->escape($password).
"'";
2318 $sql .=
" WHERE rowid = ".((int) $this->
id);
2320 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2321 $result = $this->db->query(
$sql);
2323 if ($this->db->affected_rows($result)) {
2324 $this->pass = $password;
2325 $this->pass_indatabase = $password;
2326 $this->pass_indatabase_crypted = $password_crypted;
2328 if ($this->fk_member && !$nosyncmember) {
2329 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2334 $result = $adh->fetch($this->fk_member);
2337 $result = $adh->setPassword($user, $this->pass, (empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1), 1);
2338 if (is_numeric($result) && $result < 0) {
2339 $this->
error = $adh->error;
2344 $this->
error = $adh->error;
2349 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2351 if (!$error && !$notrigger) {
2353 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2355 $error++; $this->db->rollback();
return -1;
2360 $this->db->commit();
2363 $this->db->rollback();
2367 $this->db->rollback();
2374 $sql =
"UPDATE ".$this->db->prefix().
"user";
2375 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2376 $sql .=
" WHERE rowid = ".((int) $this->
id);
2378 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2379 $result = $this->db->query(
$sql);
2401 global $conf, $langs, $mysoc;
2402 global $dolibarr_main_url_root;
2404 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2411 $outputlangs =
new Translate(
"", $conf);
2413 if (isset($this->
conf->MAIN_LANG_DEFAULT)
2414 && $this->conf->MAIN_LANG_DEFAULT !=
'auto') {
2415 $outputlangs->getDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2418 if ($this->
conf->MAIN_LANG_DEFAULT) {
2419 $outputlangs->setDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2421 $outputlangs = $langs;
2425 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2427 $appli = constant(
'DOL_APPLICATION_TITLE');
2428 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
2429 $appli = $conf->global->MAIN_APPLICATION_TITLE;
2432 $subject =
'['.$mysoc->name.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2435 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2436 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2438 if (!$changelater) {
2439 $url = $urlwithroot.
'/';
2440 if (!empty($conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD)) {
2441 $url = $conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD;
2444 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2446 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2447 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2448 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2449 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2452 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2454 $mesg .= $user->getFullName($outputlangs);
2457 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2458 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.$conf->file->instance_unique_id));
2460 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2463 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2467 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2468 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2469 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2470 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2472 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2473 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2474 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2477 $trackid =
'use'.$this->id;
2478 $sendcontext =
'password';
2483 $conf->global->MAIN_MAIL_EMAIL_FROM,
2499 if ($mailfile->sendfile()) {
2502 $langs->trans(
"errors");
2503 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2515 return $this->error;
2528 $sql =
"SELECT url, login, pass, poste ";
2529 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2530 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2532 $resql = $this->db->query(
$sql);
2534 if ($this->db->num_rows($resql)) {
2535 $obj = $this->db->fetch_object($resql);
2537 $this->clicktodial_url = $obj->url;
2538 $this->clicktodial_login = $obj->login;
2539 $this->clicktodial_password = $obj->pass;
2540 $this->clicktodial_poste = $obj->poste;
2543 $this->clicktodial_loaded = 1;
2545 $this->db->free($resql);
2548 $this->
error = $this->db->error();
2564 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2565 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2567 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2568 $result = $this->db->query(
$sql);
2570 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2571 $sql .=
" (fk_user,url,login,pass,poste)";
2572 $sql .=
" VALUES (".$this->id;
2573 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2574 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2575 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2576 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2578 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2579 $result = $this->db->query(
$sql);
2581 $this->db->commit();
2584 $this->db->rollback();
2585 $this->
error = $this->db->lasterror();
2603 global $conf, $langs, $user;
2609 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2610 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2611 $sql .=
" AND fk_usergroup = ".((int) $group);
2612 $sql .=
" AND entity = ".((int) $entity);
2614 $result = $this->db->query(
$sql);
2616 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2617 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2619 $result = $this->db->query(
$sql);
2621 if (!$error && !$notrigger) {
2622 $this->context = array(
'audit'=>$langs->trans(
"UserSetInGroup"),
'newgroupid'=>$group);
2633 $this->db->commit();
2637 $this->db->rollback();
2641 $this->
error = $this->db->lasterror();
2642 $this->db->rollback();
2659 global $conf, $langs, $user;
2665 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2666 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2667 $sql .=
" AND fk_usergroup = ".((int) $group);
2668 if (empty($entity)) {
2669 $sql .=
" AND entity IN (0, 1)";
2671 $sql .=
" AND entity = ".((int) $entity);
2674 $result = $this->db->query(
$sql);
2676 if (!$error && !$notrigger) {
2677 $this->context = array(
'audit'=>$langs->trans(
"UserRemovedFromGroup"),
'oldgroupid'=>$group);
2688 $this->db->commit();
2691 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2692 $this->db->rollback();
2696 $this->
error = $this->db->lasterror();
2697 $this->db->rollback();
2711 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2718 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
2740 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
2742 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2743 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
2758 global $conf, $langs, $menumanager;
2760 $infologin = $params[
'infologin'] ?? 0;
2761 $option = $params[
'option'] ??
'';
2764 if (!empty($this->photo)) {
2765 $photo =
'<div class="photointooltip floatright">';
2766 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
2768 $datas[
'photo'] = $photo;
2773 $datas[
'opendiv'] =
'<div class="centpercent">';
2774 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
2776 if (!empty($this->login)) {
2777 $datas[
'login'] =
'<br><b>'.$langs->trans(
'Login').
':</b> '.
dol_string_nohtmltag($this->login);
2779 if (!empty($this->job)) {
2782 $datas[
'email'] =
'<br><b>'.$langs->trans(
"Email").
':</b> '.
dol_string_nohtmltag($this->email);
2783 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
2784 $phonelist = array();
2785 if ($this->office_phone) {
2786 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2788 if ($this->office_fax) {
2789 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2791 if ($this->user_mobile) {
2792 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
2794 $datas[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
2796 if (!empty($this->admin)) {
2797 $datas[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
2799 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
2800 $datas[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
2803 if (!empty($this->socid)) {
2804 $thirdpartystatic =
new Societe($this->db);
2805 $thirdpartystatic->fetch($this->socid);
2806 if (empty($hidethirdpartylogo)) {
2807 $companylink =
' '.$thirdpartystatic->getNomUrl(2, (($option ==
'nolink') ?
'nolink' :
''));
2811 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
2812 $datas[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
2813 $datas[
'closediv'] =
'</div>';
2815 if ($infologin > 0) {
2816 $datas[
'newlinelogin'] =
'<br>';
2817 $datas[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
2819 if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) {
2820 $datas[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.$conf->entity.
' (User entity '.$this->entity.
')';
2822 $datas[
'authentication'] =
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
2823 $datas[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
2824 $datas[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
2825 $datas[
'currenttheme'] =
'<br><b>'.$langs->trans(
"CurrentTheme").
':</b> '.
dol_string_nohtmltag($conf->theme);
2826 $datas[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
2828 $datas[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
2829 $datas[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag($conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
2830 $datas[
'layout'] =
'<br><b>'.$langs->trans(
"Layout").
':</b> '.
dol_string_nohtmltag($conf->browser->layout);
2831 $datas[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
2832 if ($conf->browser->layout ==
'phone') {
2833 $datas[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
2835 if (!empty($_SESSION[
"disablemodules"])) {
2836 $datas[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(join(
', ', explode(
',', $_SESSION[
"disablemodules"])));
2858 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
2860 global $langs, $conf, $db, $hookmanager, $user;
2861 global $dolibarr_main_authentication, $dolibarr_main_demo;
2862 global $menumanager;
2864 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
2868 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) {
2875 'objecttype' => $this->element,
2876 'infologin' => $infologin,
2877 'option' => $option,
2879 $classfortooltip =
'classfortooltip';
2882 $classfortooltip =
'classforajaxtooltip';
2883 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
2890 if (!empty($this->socid)) {
2891 $thirdpartystatic =
new Societe($this->db);
2892 $thirdpartystatic->fetch($this->socid);
2893 if (empty($hidethirdpartylogo)) {
2894 $companylink =
' '.$thirdpartystatic->getNomUrl(2, (($option ==
'nolink') ?
'nolink' :
''));
2898 if ($infologin < 0) {
2902 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
2903 if ($option ==
'leave') {
2904 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
2907 if ($option !=
'nolink') {
2909 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2910 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2911 $add_save_lastsearch_values = 1;
2913 if ($add_save_lastsearch_values) {
2914 $url .=
'&save_lastsearch_values=1';
2918 $linkstart =
'<a href="'.$url.
'"';
2920 if (empty($notooltip)) {
2921 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2922 $langs->load(
"users");
2923 $label = $langs->trans(
"ShowUser");
2924 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2926 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
2927 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
2929 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
2932 $linkstart .= $linkclose.
'>';
2936 $result .= (($option ==
'nolink') ?
'' : $linkstart);
2937 if ($withpictoimg) {
2938 $paddafterimage =
'';
2939 if (abs((
int) $withpictoimg) == 1) {
2940 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
2943 if ($withpictoimg > 0) {
2944 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' class="paddingright")', 0, 0, $notooltip ? 0 : 1).
'</span>';
2947 $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>';
2951 if ($withpictoimg > -2 && $withpictoimg != 2) {
2952 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2953 $result .=
'<span class="nopadding usertext'.((!isset($this->status) || $this->status) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
2955 if ($mode ==
'login') {
2960 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2961 $result .=
'</span>';
2964 $result .= (($option ==
'nolink') ?
'' : $linkend);
2967 $result .= $companylink;
2970 $hookmanager->initHooks(array(
'userdao'));
2971 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
2972 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2974 $result = $hookmanager->resPrint;
2976 $result .= $hookmanager->resPrint;
2991 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
2993 global $langs, $user;
2997 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3001 if ((!$user->rights->user->user->lire && $this->id != $user->id)) {
3005 if ($option ==
'xxx') {
3006 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3010 if ($option ==
'nolink') {
3015 $result .= $linkstart;
3016 if ($withpictoimg) {
3017 $paddafterimage =
'';
3018 if (abs($withpictoimg) == 1) {
3019 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3022 if ($withpictoimg > 0) {
3023 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3026 $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>';
3030 $result .= $this->login;
3031 $result .= $linkend;
3044 return $this->
LibStatut(isset($this->statut) ? (
int) $this->statut : (
int) $this->status, $mode);
3060 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3063 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3064 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3065 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3066 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3069 $statusType =
'status5';
3070 if ($status == self::STATUS_ENABLED) {
3071 $statusType =
'status4';
3074 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
3089 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3091 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3092 $return .=
'<div class="info-box info-box-sm">';
3093 $return .=
'<span class="info-box-icon bg-infobox-action">';
3096 if (!empty($this->photo)) {
3098 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3107 $return .=
'</span>';
3108 $return .=
'<div class="info-box-content">';
3109 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3110 if (
isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3111 $return .=
img_picto($langs->trans(
"SuperAdministrator"),
'redstar',
'class="valignmiddle paddingright paddingleft"');
3112 } elseif ($this->admin) {
3113 $return .=
img_picto($langs->trans(
"Administrator"),
'star',
'class="valignmiddle paddingright paddingleft"');
3115 $return .=
'</span>';
3116 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3117 if (property_exists($this,
'label')) {
3118 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3121 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->email.
'</span>';
3123 if (method_exists($this,
'getLibStatut')) {
3124 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
3126 $return .=
'</div>';
3127 $return .=
'</div>';
3128 $return .=
'</div>';
3151 $dn = $conf->global->LDAP_KEY_USERS.
"=".$info[$conf->global->LDAP_KEY_USERS].
",".$conf->global->LDAP_USER_DN;
3152 } elseif ($mode == 1) {
3153 $dn = $conf->global->LDAP_USER_DN;
3154 } elseif ($mode == 2) {
3155 $dn = $conf->global->LDAP_KEY_USERS.
"=".$info[$conf->global->LDAP_KEY_USERS];
3170 global $conf, $langs;
3176 $keymodified =
false;
3179 $info[
"objectclass"] = explode(
',', $conf->global->LDAP_USER_OBJECT_CLASS);
3185 'LDAP_FIELD_FULLNAME' =>
'fullname',
3186 'LDAP_FIELD_NAME' =>
'lastname',
3187 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3188 'LDAP_FIELD_LOGIN' =>
'login',
3189 'LDAP_FIELD_LOGIN_SAMBA'=>
'login',
3190 'LDAP_FIELD_PHONE' =>
'office_phone',
3191 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3192 'LDAP_FIELD_FAX' =>
'office_fax',
3193 'LDAP_FIELD_MAIL' =>
'email',
3194 'LDAP_FIELD_SID' =>
'ldap_sid',
3198 foreach ($ldapkey as $constname => $varname) {
3203 if (!empty($conf->global->LDAP_KEY_USERS) && $conf->global->LDAP_KEY_USERS ==
getDolGlobalString($constname)) {
3204 if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
3205 $keymodified =
true;
3210 foreach ($socialnetworks as $key => $value) {
3211 if (!empty($this->socialnetworks[$value[
'label']]) &&
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))) {
3212 $info[
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))] = $this->socialnetworks[$value[
'label']];
3215 if ($this->address && !empty($conf->global->LDAP_FIELD_ADDRESS)) {
3216 $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->address;
3218 if ($this->zip && !empty($conf->global->LDAP_FIELD_ZIP)) {
3219 $info[$conf->global->LDAP_FIELD_ZIP] = $this->zip;
3221 if ($this->town && !empty($conf->global->LDAP_FIELD_TOWN)) {
3222 $info[$conf->global->LDAP_FIELD_TOWN] = $this->town;
3224 if ($this->note_public && !empty($conf->global->LDAP_FIELD_DESCRIPTION)) {
3227 if ($this->socid > 0) {
3228 $soc =
new Societe($this->db);
3229 $soc->fetch($this->socid);
3231 $info[$conf->global->LDAP_FIELD_COMPANY] = $soc->name;
3232 if ($soc->client == 1) {
3233 $info[
"businessCategory"] =
"Customers";
3235 if ($soc->client == 2) {
3236 $info[
"businessCategory"] =
"Prospects";
3238 if ($soc->fournisseur == 1) {
3239 $info[
"businessCategory"] =
"Suppliers";
3244 if (!empty($this->pass)) {
3245 if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
3246 $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass;
3248 if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3249 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass,
'openldap');
3251 } elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !==
'3') {
3254 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
3256 if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) {
3257 if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3258 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dolGetLdapPasswordHash($this->pass_indatabase_crypted,
'md5frommd5');
3261 } elseif (!empty($this->pass_indatabase)) {
3263 if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
3264 $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass_indatabase;
3266 if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3267 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass_indatabase,
'openldap');
3273 $info[
"objectclass"][4] =
"phpgwContact";
3275 $info[
'uidnumber'] = $this->id;
3277 $info[
'phpgwTz'] = 0;
3278 $info[
'phpgwMailType'] =
'INTERNET';
3279 $info[
'phpgwMailHomeType'] =
'INTERNET';
3281 $info[
"phpgwContactTypeId"] =
'n';
3282 $info[
"phpgwContactCatId"] = 0;
3283 $info[
"phpgwContactAccess"] =
"public";
3286 $this->egroupware_id = 1;
3289 $info[
"phpgwContactOwner"] = $this->egroupware_id;
3292 $info[
"rfc822Mailbox"] = $this->email;
3294 if ($this->user_mobile) {
3295 $info[
"phpgwCellTelephoneNumber"] = $this->user_mobile;
3299 if (!empty($conf->global->LDAP_FIELD_USERID)) {
3300 $info[$conf->global->LDAP_FIELD_USERID] = $this->id;
3302 if (!empty($conf->global->LDAP_FIELD_GROUPID)) {
3304 $groupslist = $usergroup->listGroupsForUser($this->
id);
3305 $info[$conf->global->LDAP_FIELD_GROUPID] =
'65534';
3306 if (!empty($groupslist)) {
3307 foreach ($groupslist as $groupforuser) {
3308 $info[$conf->global->LDAP_FIELD_GROUPID] = $groupforuser->id;
3313 if (!empty($conf->global->LDAP_FIELD_HOMEDIRECTORY) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX)) {
3314 $info[$conf->global->LDAP_FIELD_HOMEDIRECTORY] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->login";
3330 global $user, $langs;
3336 $this->
ref =
'SPECIMEN';
3337 $this->specimen = 1;
3339 $this->lastname =
'DOLIBARR';
3340 $this->firstname =
'SPECIMEN';
3341 $this->gender =
'man';
3342 $this->note_public =
'This is a note public';
3343 $this->note_private =
'This is a note private';
3344 $this->email =
'email@specimen.com';
3345 $this->personal_email =
'personalemail@specimen.com';
3346 $this->socialnetworks = array(
3347 'skype' =>
'skypepseudo',
3348 'twitter' =>
'twitterpseudo',
3349 'facebook' =>
'facebookpseudo',
3350 'linkedin' =>
'linkedinpseudo',
3352 $this->office_phone =
'0999999999';
3353 $this->office_fax =
'0999999998';
3354 $this->user_mobile =
'0999999997';
3355 $this->personal_mobile =
'0999999996';
3357 $this->login =
'dolibspec';
3358 $this->pass =
'dolibSpec+@123';
3361 $this->datec = $now;
3362 $this->datem = $now;
3364 $this->datelastlogin = $now;
3365 $this->iplastlogin =
'127.0.0.1';
3366 $this->datepreviouslogin = $now;
3367 $this->ippreviouslogin =
'127.0.0.1';
3383 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
3384 $sql .=
" u.tms as date_modification, u.entity";
3385 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3386 $sql .=
" WHERE u.rowid = ".((int) $id);
3388 $result = $this->db->query(
$sql);
3390 if ($this->db->num_rows($result)) {
3391 $obj = $this->db->fetch_object($result);
3393 $this->
id = $obj->rowid;
3395 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3396 $this->date_creation = $this->db->jdate($obj->datec);
3397 $this->date_modification = $this->db->jdate($obj->date_modification);
3398 $this->entity = $obj->entity;
3401 $this->db->free($result);
3415 $sql =
"SELECT count(mc.email) as nb";
3416 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3417 $sql .=
" WHERE mc.email = '".$this->db->escape($this->email).
"'";
3418 $sql .=
" AND mc.statut NOT IN (-1,0)";
3420 $resql = $this->db->query(
$sql);
3422 $obj = $this->db->fetch_object($resql);
3425 $this->db->free($resql);
3428 $this->
error = $this->db->error();
3445 $sql =
"SELECT count(rowid) as nb";
3446 $sql .=
" FROM ".$this->db->prefix().
"user";
3447 if ($option ==
'superadmin') {
3448 $sql .=
" WHERE entity = 0";
3450 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3451 if ($limitTo ==
'active') {
3452 $sql .=
" AND statut = 1";
3456 $sql .=
" AND admin = ".(int) $admin;
3459 $resql = $this->db->query(
$sql);
3461 $obj = $this->db->fetch_object($resql);
3462 $nb = (int) $obj->nb;
3464 $this->db->free($resql);
3467 $this->
error = $this->db->lasterror();
3483 global $user, $conf;
3488 $this->firstname = $ldapuser->$tmpvar;
3490 $this->lastname = $ldapuser->$tmpvar;
3492 $this->login = $ldapuser->$tmpvar;
3494 $this->pass = $ldapuser->$tmpvar;
3496 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3499 $this->office_phone = $ldapuser->$tmpvar;
3501 $this->user_mobile = $ldapuser->$tmpvar;
3503 $this->office_fax = $ldapuser->$tmpvar;
3505 $this->email = $ldapuser->$tmpvar;
3506 foreach ($socialnetworks as $key => $value) {
3508 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3511 $this->ldap_sid = $ldapuser->$tmpvar;
3514 $this->job = $ldapuser->$tmpvar;
3516 $this->note_public = $ldapuser->$tmpvar;
3518 $result = $this->
update($user);
3520 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3536 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3537 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3539 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3540 $res = $this->db->query(
$sql);
3543 while ($rec = $this->db->fetch_array($res)) {
3544 $user =
new User($this->db);
3545 $user->fetch($rec[
'rowid']);
3565 $this->parentof = array();
3568 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3569 $sql .=
" FROM ".$this->db->prefix().
"user";
3570 $sql .=
" WHERE fk_user <> 0";
3571 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3573 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3574 $resql = $this->db->query(
$sql);
3576 while ($obj = $this->db->fetch_object($resql)) {
3577 $this->parentof[$obj->id_son] = $obj->id_parent;
3603 global $conf, $user;
3604 global $hookmanager;
3607 $hookmanager->initHooks(array(
'userdao'));
3609 $this->users = array();
3615 $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";
3616 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3618 $parameters = array();
3619 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3621 $sql .= $hookmanager->resPrint;
3623 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3626 $sql .=
" AND ".$filter;
3629 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3630 $resql = $this->db->query(
$sql);
3633 while ($obj = $this->db->fetch_object($resql)) {
3634 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3635 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3636 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3637 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3638 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3639 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3640 $this->users[$obj->rowid][
'login'] = $obj->login;
3641 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3642 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3643 $this->users[$obj->rowid][
'email'] = $obj->email;
3644 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3645 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3646 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3655 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3656 foreach ($this->users as $key => $val) {
3659 $this->
error =
'ErrorLoopInHierarchy';
3665 if ($deleteafterid) {
3667 $keyfilter1 =
'^'.$deleteafterid.
'$';
3668 $keyfilter2 =
'_'.$deleteafterid.
'$';
3669 $keyfilter3 =
'^'.$deleteafterid.
'_';
3670 $keyfilter4 =
'_'.$deleteafterid.
'_';
3671 foreach ($this->users as $key => $val) {
3672 if (preg_match(
'/'.$keyfilter1.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter2.
'/', $val[
'fullpath'])
3673 || preg_match(
'/'.$keyfilter3.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter4.
'/', $val[
'fullpath'])) {
3674 unset($this->users[$key]);
3679 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
3680 $this->users =
dol_sort_array($this->users,
'fullname',
'asc',
true,
false);
3684 return $this->users;
3697 $childids = array();
3699 if (isset($this->cache_childids[$this->
id])) {
3700 $childids = $this->cache_childids[$this->id];
3705 $idtoscan = $this->id;
3707 dol_syslog(
"Build childid for id = ".$idtoscan);
3708 foreach ($this->users as $id => $val) {
3710 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
3711 $childids[$val[
'id']] = $val[
'id'];
3715 $this->cache_childids[$this->id] = $childids;
3717 if ($addcurrentuser) {
3718 $childids[$this->id] = $this->id;
3738 if (!empty($this->users[$id_user][
'fullpath'])) {
3740 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
3745 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
3746 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
3747 $i = 0; $cursor_user = $id_user;
3749 $useridfound = array($id_user);
3750 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
3751 if (in_array($this->parentof[$cursor_user], $useridfound)) {
3752 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
3755 $useridfound[] = $this->parentof[$cursor_user];
3756 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
3757 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
3758 $i++; $cursor_user = $this->parentof[$cursor_user];
3762 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
3796 $this->nb = array();
3798 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
3799 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3800 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
3801 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
3802 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
3803 $sql .=
" AND ug.fk_user = u.rowid";
3805 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3807 $sql .=
" AND u.statut > 0";
3810 $resql = $this->db->query(
$sql);
3812 while ($obj = $this->db->fetch_object($resql)) {
3813 $this->nb[
"users"] = $obj->nb;
3815 $this->db->free($resql);
3819 $this->
error = $this->db->error();
3835 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3837 global $conf, $user, $langs;
3839 $langs->load(
"user");
3843 if (!empty($conf->global->USER_ADDON_PDF)) {
3844 $modele = $conf->global->USER_ADDON_PDF;
3846 $modele =
'bluesky';
3850 $modelpath =
"core/modules/user/doc/";
3852 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3866 $user_property =
'';
3868 if (empty($rowid)) {
3872 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
3873 $sql .=
" FROM ".$this->db->prefix().
"user";
3874 $sql .=
" WHERE rowid = ".((int) $rowid);
3876 $resql = $this->db->query(
$sql);
3878 $nump = $this->db->num_rows($resql);
3881 $obj = $this->db->fetch_object($resql);
3883 if ($mode ==
'email') {
3884 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
3885 } elseif ($mode ==
'mobile') {
3886 $user_property = $obj->user_mobile;
3887 } elseif ($mode ==
'name') {
3891 return $user_property;
3908 global $dolibarr_main_url_root;
3911 $encodedsecurekey =
dol_hash($conf->file->instance_unique_id.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
3913 $entity_qr =
'&entity='.((int) $conf->entity);
3918 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
3919 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
3922 if ($typeofurl ==
'internal') {
3923 $urlwithroot = DOL_URL_ROOT;
3926 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
3941 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter = array(), $filtermode =
'AND', $entityfilter =
false)
3943 global $conf, $user;
3945 $sql =
"SELECT t.rowid";
3946 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
3948 if ($entityfilter) {
3949 if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
3950 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
3951 $sql .=
" WHERE t.entity IS NOT NULL";
3953 $sql .=
",".$this->db->prefix().
"usergroup_user as ug";
3954 $sql .=
" WHERE ((ug.fk_user = t.rowid";
3955 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
3956 $sql .=
" OR t.entity = 0)";
3959 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
3962 $sql .=
" WHERE 1 = 1";
3966 $sqlwhere = array();
3967 if (!empty($filter)) {
3968 foreach ($filter as $key => $value) {
3969 if ($key ==
't.rowid') {
3970 $sqlwhere[] = $key.
" = ".((int) $value);
3971 } elseif (isset($this->fields[$key][
'type']) && in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
3972 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
3973 } elseif ($key ==
'customsql') {
3974 $sqlwhere[] = $value;
3976 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
3980 if (count($sqlwhere) > 0) {
3981 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
3983 $sql .= $this->db->order($sortfield, $sortorder);
3985 $sql .= $this->db->plimit($limit + 1, $offset);
3990 $resql = $this->db->query(
$sql);
3992 $this->users = array();
3993 $num = $this->db->num_rows($resql);
3995 while ($obj = $this->db->fetch_object($resql)) {
3996 $line =
new self($this->db);
3997 $result = $line->fetch($obj->rowid);
3998 if ($result > 0 && !empty($line->id)) {
3999 $this->users[$obj->rowid] = clone $line;
4002 $this->db->free($resql);
4006 $this->errors[] = $this->db->lasterror();
4018 private $findUserIdByEmailCache;
4032 if (isset($this->findUserIdByEmailCache[$email])) {
4033 return $this->findUserIdByEmailCache[$email];
4036 $this->findUserIdByEmailCache[$email] = -1;
4040 $sql =
'SELECT rowid';
4041 $sql .=
' FROM '.$this->db->prefix().
'user';
4042 if (!empty($conf->global->AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR)) {
4043 $sql .=
" WHERE email LIKE '%".$this->db->escape($email).
"%'";
4045 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4049 $resql = $this->db->query(
$sql);
4054 $obj = $this->db->fetch_object($resql);
4059 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4061 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...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage warehouses.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage user groups.
Class to manage Dolibarr users.
SetInGroup($group, $entity, $notrigger=0)
Add user into a group.
LibStatut($status, $mode=0)
Return the label of a status of user (active, inactive)
get_children()
Return and array with all instanciated first level children users of current user.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
hasRight($module, $permlevel1, $permlevel2='')
Return if a user has a permission.
info($id)
Load info of user object.
create_from_contact($contact, $login='', $password='')
Create a user from a contact object.
setstatus($status)
Change status of a user.
get_full_tree($deleteafterid=0, $filter='')
Build the hierarchy/tree of users into an array.
_load_ldap_info()
Initialize the info array (array of LDAP values) that will be used to call LDAP functions.
delrights($rid, $allmodule='', $allperms='', $entity=0, $notrigger=0)
Remove a right to the user.
update_last_login_date()
Mise a jour en base de la date de derniere connexion d'un utilisateur Fonction appelee lors d'une nou...
__construct($db)
Constructor of the class.
RemoveFromGroup($group, $entity, $notrigger=0)
Remove a user from a group.
isNotIntoValidityDateRange()
Return a link with photo Use this->id,this->photo.
getNbOfUsers($limitTo, $option='', $admin=-1)
Return number of existing users.
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.
getOnlineVirtualCardUrl($mode='', $typeofurl='external')
Return string with full Url to virtual card.
update($user, $notrigger=0, $nosyncmember=0, $nosyncmemberpass=0, $nosynccontact=0)
Update a user into database (and also password if this->pass is defined)
getLoginUrl($withpictoimg=0, $option='', $notooltip=0, $morecss='')
Return clickable link of login (eventualy with picto)
setCategories($categories)
Sets object to supplied categories.
loadParentOf()
Load this->parentof that is array(id_son=>id_parent, ...)
fetch_clicktodial()
Read clicktodial information for user.
build_path_from_id_user($id_user, $protection=0)
For user id_user and its childs available in this->users, define property fullpath and fullname.
error()
Renvoie la derniere erreur fonctionnelle de manipulation de l'objet.
getAllChildIds($addcurrentuser=0)
Return list of all child users id in herarchy (all sublevels).
initAsSpecimen()
Initialise an instance with random values.
setPassword($user, $password='', $changelater=0, $notrigger=0, $nosyncmember=0, $passwordalreadycrypted=0, $flagdelsessionsbefore=1)
Change password of a user.
getNomUrl($withpictoimg=0, $option='', $infologin=0, $notooltip=0, $maxlen=24, $hidethirdpartylogo=0, $mode='', $morecss='', $save_lastsearch_value=-1)
Return a HTML link to the user card (with optionaly the picto) Use this->id,this->lastname,...
clearrights()
Clear all permissions array of user.
load_state_board()
Load metrics this->nb for dashboard.
update_clicktodial()
Update clicktodial info.
getLibStatut($mode=0)
Return the label of the status of user (active, inactive)
create_from_member($member, $login='')
Create a user into database from a member object.
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
$clicktodial_url
@string clicktodial url
loadDefaultValues()
Load default values from database table into property ->default_values.
getPhotoUrl($width, $height, $cssclass='', $imagesize='')
Return a link with photo Use this->id,this->photo.
update_ldap2dolibarr(&$ldapuser)
Update user using data from the LDAP.
getrights($moduletag='', $forcereload=0)
Load permissions granted to user into object user.
user_get_property($rowid, $mode)
Return property of user from its id.
send_password($user, $password='', $changelater=0)
Send a new password (or instructions to reset it) by email.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
getNbOfEMailings()
Return number of mass Emailing received by this contacts with its email.
addrights($rid, $allmodule='', $allperms='', $entity=0, $notrigger=0)
Add a right to the user.
create($user, $notrigger=0)
Create a user into database.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter=array(), $filtermode='AND', $entityfilter=false)
Load all objects into $this->users.
findUserIdByEmail($email)
Find a user by the given e-mail and return it's user id when found.
getTooltipContentArray($params)
Return array of data to show into tooltips.
trait CommonPeople
Superclass for thirdparties, contacts, members or users.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
getArrayOfSocialNetworks()
Get array of social network dictionary.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getUserRemoteIP()
Return the IP of remote user.
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.