38require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/commonpeople.class.php';
54 public $element =
'user';
59 public $table_element =
'user';
64 public $fk_element =
'fk_user';
70 public $ismultientitymanaged = 1;
75 public $isextrafieldmanaged = 1;
80 public $picto =
'user';
87 public $civility_code;
109 public $personal_email;
114 public $socialnetworks;
129 public $office_phone;
144 public $personal_mobile;
174 public $pass_indatabase;
179 public $pass_indatabase_crypted;
223 public $fk_user_expense_validator;
228 public $fk_user_holiday_validator;
238 public $clicktodial_login;
243 public $clicktodial_password;
248 public $clicktodial_poste;
253 public $clicktodial_loaded;
256 public $datelastlogin;
257 public $datepreviouslogin;
258 public $flagdelsessionsbefore;
260 public $ippreviouslogin;
261 public $datestartvalidity;
262 public $dateendvalidity;
278 public $all_permissions_are_loaded;
288 public $user_group_list;
293 private $_tab_loaded = array();
300 public $default_values;
302 public $lastsearch_values_tmp;
303 public $lastsearch_values;
305 public $users = array();
307 private $cache_childids;
309 public $accountancy_code;
323 public $dateemployment;
324 public $dateemploymentend;
326 public $default_c_exp_tax_cat;
331 public $ref_employee;
336 public $national_registration_number;
338 public $default_range;
343 public $fk_warehouse;
346 public $fields = array(
347 'rowid'=>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'index'=>1,
'position'=>1,
'comment'=>
'Id'),
348 'lastname'=>array(
'type'=>
'varchar(50)',
'label'=>
'LastName',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>20,
'searchall'=>1),
349 'firstname'=>array(
'type'=>
'varchar(50)',
'label'=>
'FirstName',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>10,
'searchall'=>1),
350 'ref_employee'=>array(
'type'=>
'varchar(50)',
'label'=>
'RefEmployee',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>30,
'searchall'=>1),
351 'national_registration_number'=>array(
'type'=>
'varchar(50)',
'label'=>
'NationalRegistrationNumber',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>40,
'searchall'=>1)
355 const STATUS_DISABLED = 0;
356 const STATUS_ENABLED = 1;
370 $this->clicktodial_loaded = 0;
373 $this->all_permissions_are_loaded = 0;
374 $this->nb_rights = 0;
380 $this->
conf =
new stdClass();
381 $this->rights =
new stdClass();
382 $this->rights->user =
new stdClass();
383 $this->rights->user->user =
new stdClass();
384 $this->rights->user->self =
new stdClass();
385 $this->rights->user->user_advance =
new stdClass();
386 $this->rights->user->self_advance =
new stdClass();
387 $this->rights->user->group_advance =
new stdClass();
403 public function fetch($id =
'', $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'', $fk_socpeople = 0)
408 $login = trim($login);
411 $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,";
412 $sql .=
" u.socialnetworks,";
413 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
414 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
415 $sql .=
" u.admin, u.login, u.note_private, u.note_public,";
416 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.api_key,";
417 $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,";
418 $sql .=
" u.statut as status, u.lang, u.entity,";
419 $sql .=
" u.datec as datec,";
420 $sql .=
" u.tms as datem,";
421 $sql .=
" u.datelastlogin as datel,";
422 $sql .=
" u.datepreviouslogin as datep,";
423 $sql .=
" u.flagdelsessionsbefore,";
424 $sql .=
" u.iplastlogin,";
425 $sql .=
" u.ippreviouslogin,";
426 $sql .=
" u.datelastpassvalidation,";
427 $sql .=
" u.datestartvalidity,";
428 $sql .=
" u.dateendvalidity,";
429 $sql .=
" u.photo as photo,";
430 $sql .=
" u.openid as openid,";
431 $sql .=
" u.accountancy_code,";
434 $sql .=
" u.salary,";
435 $sql .=
" u.salaryextra,";
436 $sql .=
" u.weeklyhours,";
438 $sql .=
" u.dateemployment, u.dateemploymentend,";
439 $sql .=
" u.fk_warehouse,";
440 $sql .=
" u.ref_ext,";
441 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
442 $sql .=
" u.national_registration_number,";
443 $sql .=
" u.ref_employee,";
444 $sql .=
" c.code as country_code, c.label as country,";
445 $sql .=
" d.code_departement as state_code, d.nom as state";
446 $sql .=
" FROM ".$this->db->prefix().
"user as u";
447 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as c ON u.fk_country = c.rowid";
448 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_departements as d ON u.fk_state = d.rowid";
451 if ((!isModEnabled(
'multicompany') || empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) && (!empty($user->entity))) {
452 $sql .=
" WHERE u.entity IN (0, ".((int) $conf->entity).
")";
454 $sql .=
" WHERE u.entity IS NOT NULL";
458 if (isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
459 $sql .=
" WHERE u.entity IS NOT NULL";
461 $sql .=
" WHERE u.entity IN (0, ".((int) (($entity !=
'' && $entity >= 0) ? $entity : $conf->entity)).
")";
467 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->db->escape($login).
"')";
469 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
471 $sql .=
" AND u.email = '".$this->db->escape($email).
"'";
472 } elseif ($fk_socpeople > 0) {
473 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
475 $sql .=
" AND u.rowid = ".((int) $id);
477 $sql .=
" ORDER BY u.entity ASC";
481 $sql .=
' '.$this->db->plimit(1);
484 $result = $this->db->query($sql);
486 $obj = $this->db->fetch_object($result);
488 $this->
id = $obj->rowid;
489 $this->
ref = $obj->rowid;
491 $this->ref_ext = $obj->ref_ext;
493 $this->ldap_sid = $obj->ldap_sid;
494 $this->civility_code = $obj->civility_code;
495 $this->lastname = $obj->lastname;
496 $this->firstname = $obj->firstname;
497 $this->ref_employee = $obj->ref_employee;
498 $this->national_registration_number = $obj->national_registration_number;
500 $this->employee = $obj->employee;
502 $this->login = $obj->login;
503 $this->gender = $obj->gender;
504 $this->birth = $this->db->jdate($obj->birth);
505 $this->pass_indatabase = $obj->pass;
506 $this->pass_indatabase_crypted = $obj->pass_crypted;
507 $this->pass = $obj->pass;
508 $this->pass_temp = $obj->pass_temp;
511 $this->address = $obj->address;
512 $this->zip = $obj->zip;
513 $this->town = $obj->town;
515 $this->country_id = $obj->country_id;
516 $this->country_code = $obj->country_id ? $obj->country_code :
'';
519 $this->state_id = $obj->state_id;
520 $this->state_code = $obj->state_code;
521 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
523 $this->office_phone = $obj->office_phone;
524 $this->office_fax = $obj->office_fax;
525 $this->user_mobile = $obj->user_mobile;
526 $this->personal_mobile = $obj->personal_mobile;
527 $this->email = $obj->email;
528 $this->personal_email = $obj->personal_email;
529 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
530 $this->job = $obj->job;
531 $this->signature = $obj->signature;
532 $this->admin = $obj->admin;
533 $this->note_public = $obj->note_public;
534 $this->note_private = $obj->note_private;
535 $this->note = $obj->note_private;
537 $this->
statut = $obj->status;
538 $this->status = $obj->status;
540 $this->photo = $obj->photo;
541 $this->openid = $obj->openid;
542 $this->lang = $obj->lang;
543 $this->entity = $obj->entity;
544 $this->accountancy_code = $obj->accountancy_code;
545 $this->thm = $obj->thm;
546 $this->tjm = $obj->tjm;
547 $this->salary = $obj->salary;
548 $this->salaryextra = $obj->salaryextra;
549 $this->weeklyhours = $obj->weeklyhours;
550 $this->color = $obj->color;
551 $this->dateemployment = $this->db->jdate($obj->dateemployment);
552 $this->dateemploymentend = $this->db->jdate($obj->dateemploymentend);
554 $this->datec = $this->db->jdate($obj->datec);
555 $this->datem = $this->db->jdate($obj->datem);
556 $this->datelastlogin = $this->db->jdate($obj->datel);
557 $this->datepreviouslogin = $this->db->jdate($obj->datep);
558 $this->flagdelsessionsbefore = $this->db->jdate($obj->flagdelsessionsbefore,
'gmt');
559 $this->iplastlogin = $obj->iplastlogin;
560 $this->ippreviouslogin = $obj->ippreviouslogin;
561 $this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
562 $this->dateendvalidity = $this->db->jdate($obj->dateendvalidity);
564 $this->socid = $obj->fk_soc;
565 $this->contact_id = $obj->fk_socpeople;
566 $this->fk_member = $obj->fk_member;
567 $this->fk_user = $obj->fk_user;
568 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
569 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
571 $this->default_range = $obj->default_range;
572 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
573 $this->fk_warehouse = $obj->fk_warehouse;
577 if (!isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
585 $this->db->free($result);
587 $this->
error =
"USERNOTFOUND";
588 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
590 $this->db->free($result);
594 $this->
error = $this->db->lasterror();
599 if ($loadpersonalconf) {
601 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
602 $sql .=
" WHERE fk_user = ".((int) $this->
id);
603 $sql .=
" AND entity = ".((int) $conf->entity);
605 $resql = $this->db->query($sql);
607 $num = $this->db->num_rows($resql);
610 $obj = $this->db->fetch_object($resql);
611 $p = (!empty($obj->param) ? $obj->param :
'');
613 $this->
conf->$p = $obj->value;
617 $this->db->free($resql);
619 $this->
error = $this->db->lasterror();
626 $this->
error = $this->db->lasterror();
642 if (!empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) {
644 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
647 $result = $defaultValues->fetchAll(
'',
'', 0, 0, array(
't.user_id'=>array(0, $this->
id),
'entity'=>array((isset($this->entity) ? $this->entity : $conf->entity), $conf->entity)));
649 if (!is_array($result) && $result < 0) {
653 } elseif (count($result) > 0) {
654 foreach ($result as $defval) {
655 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
656 $pagewithoutquerystring = $defval->page;
659 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
660 $pagewithoutquerystring = $reg[1];
661 $pagequeries = $reg[2];
663 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
667 if (!empty($this->default_values)) {
668 foreach ($this->default_values as $a => $b) {
669 foreach ($b as $c => $d) {
670 krsort($this->default_values[$a][$c]);
689 public function hasRight($module, $permlevel1, $permlevel2 =
'')
693 $moduletomoduletouse = array(
694 'compta' =>
'comptabilite',
695 'contract' =>
'contrat',
696 'member' =>
'adherent',
698 'order' =>
'commande',
699 'produit' =>
'product',
700 'productlot' =>
'produit',
701 'project' =>
'projet',
702 'propale' =>
'propal',
703 'shipping' =>
'expedition',
704 'task' =>
'task@projet',
705 'fichinter' =>
'ficheinter',
706 'inventory' =>
'stock',
707 'invoice' =>
'facture',
708 'invoice_supplier' =>
'fournisseur',
709 'order_supplier' =>
'fournisseur',
710 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
711 'skill@hrm' =>
'all@hrm',
712 'job@hrm' =>
'all@hrm',
713 'position@hrm' =>
'all@hrm',
714 'facturerec' =>
'facture',
715 'margins' =>
'margin',
718 if (!empty($moduletomoduletouse[$module])) {
719 $module = $moduletomoduletouse[$module];
722 $moduleRightsMapping = array(
723 'product' =>
'produit',
724 'margin' =>
'margins',
725 'comptabilite' =>
'compta'
728 $rightsPath = $module;
729 if (!empty($moduleRightsMapping[$rightsPath])) {
730 $rightsPath = $moduleRightsMapping[$rightsPath];
734 $tmp = explode(
'@', $rightsPath, 2);
735 if (!empty($tmp[1])) {
736 if (strpos($module,
'@') !==
false) {
739 $rightsPath = $tmp[1];
740 $permlevel2 = $permlevel1;
741 $permlevel1 = $tmp[0];
751 if (!isModEnabled($module)) {
756 if ($permlevel1 ==
'propale') {
757 $permlevel1 =
'propal';
759 if ($permlevel1 ==
'member') {
760 $permlevel1 =
'adherent';
762 if ($permlevel1 ==
'recruitmentcandidature') {
763 $permlevel1 =
'recruitmentjobposition';
768 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
773 if (!empty($this->rights->$rightsPath->$permlevel1)) {
774 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
775 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
779 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
780 return $this->rights->$rightsPath->$permlevel1->lire;
782 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
783 return $this->rights->$rightsPath->$permlevel1->creer;
785 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
786 return $this->rights->$rightsPath->$permlevel1->create;
788 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
789 return $this->rights->$rightsPath->$permlevel1->supprimer;
793 if (!empty($this->rights->$rightsPath->$permlevel1)) {
794 return $this->rights->$rightsPath->$permlevel1;
798 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
799 return $this->rights->$rightsPath->lire;
801 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
802 return $this->rights->$rightsPath->creer;
804 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
805 return $this->rights->$rightsPath->create;
807 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
808 return $this->rights->$rightsPath->supprimer;
826 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
828 global $conf, $user, $langs;
830 $entity = (empty($entity) ? $conf->entity : $entity);
832 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
834 if (empty($this->
id)) {
836 $this->
error =
'Try to call addrights on an object user with an empty id';
846 $module = $perms = $subperms =
'';
849 $sql =
"SELECT module, perms, subperms";
850 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
851 $sql .=
" WHERE id = ".((int) $rid);
852 $sql .=
" AND entity = ".((int) $entity);
854 $result = $this->db->query($sql);
856 $obj = $this->db->fetch_object($result);
859 $module = $obj->module;
860 $perms = $obj->perms;
861 $subperms = $obj->subperms;
869 $whereforadd =
"id=".((int) $rid);
871 if (!empty($subperms)) {
872 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
873 } elseif (!empty($perms)) {
874 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
880 if (!empty($allmodule)) {
881 if ($allmodule ==
'allmodules') {
882 $whereforadd =
'allmodules';
884 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
885 if (!empty($allperms)) {
886 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
894 if (!empty($whereforadd)) {
897 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
898 $sql .=
" WHERE entity = ".((int) $entity);
899 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
900 $sql .=
" AND (".$whereforadd.
")";
903 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
904 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
906 $sqldelete .=
") AND entity = ".((int) $entity);
907 if (!$this->db->query($sqldelete)) {
912 $resql = $this->db->query($sql);
914 $num = $this->db->num_rows($resql);
917 $obj = $this->db->fetch_object($resql);
922 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
923 if (!$this->db->query($sql)) {
937 if (!$error && !$notrigger) {
938 $langs->load(
"other");
939 $this->context = array(
'audit'=>$langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
950 $this->db->rollback();
970 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
972 global $conf, $user, $langs;
976 $entity = (!empty($entity) ? $entity : $conf->entity);
981 $module = $perms = $subperms =
'';
985 $sql =
"SELECT module, perms, subperms";
986 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
987 $sql .=
" WHERE id = '".$this->db->escape($rid).
"'";
988 $sql .=
" AND entity = ".((int) $entity);
990 $result = $this->db->query($sql);
992 $obj = $this->db->fetch_object($result);
995 $module = $obj->module;
996 $perms = $obj->perms;
997 $subperms = $obj->subperms;
1005 $wherefordel =
"id=".((int) $rid);
1007 if ($subperms ==
'lire' || $subperms ==
'read') {
1008 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1010 if ($perms ==
'lire' || $perms ==
'read') {
1011 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1016 if (!empty($allmodule)) {
1017 if ($allmodule ==
'allmodules') {
1018 $wherefordel =
'allmodules';
1020 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1021 if (!empty($allperms)) {
1022 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1029 if (!empty($wherefordel)) {
1032 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1033 $sql .=
" WHERE entity = ".((int) $entity);
1034 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1035 $sql .=
" AND (".$wherefordel.
")";
1039 if ($this->admin == 1) {
1040 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1041 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1042 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1043 $sql .=
" AND id NOT IN (358)";
1046 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1047 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1050 $sqldelete .=
" AND entity = ".((int) $entity);
1052 $resql = $this->db->query($sqldelete);
1059 if (!$error && !$notrigger) {
1060 $langs->load(
"other");
1061 $this->context = array(
'audit'=>$langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1072 $this->db->rollback();
1075 $this->db->commit();
1089 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1090 $this->rights =
null;
1091 $this->nb_rights = 0;
1092 $this->all_permissions_are_loaded = 0;
1093 $this->_tab_loaded = array();
1105 public function getrights($moduletag =
'', $forcereload = 0)
1109 if (empty($forcereload)) {
1110 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1115 if (!empty($this->all_permissions_are_loaded)) {
1122 if (!isset($this->rights) || !is_object($this->rights)) {
1123 $this->rights =
new stdClass();
1125 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1126 $this->rights->user =
new stdClass();
1132 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1133 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1134 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1135 $sql .=
" WHERE r.id = ur.fk_id";
1136 if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
1138 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ?
"1," :
"").$conf->entity.
")";
1142 $sql .=
" AND r.entity = ".((int) $conf->entity).
" AND ur.entity = ".((int) $conf->entity);
1144 $sql .=
" AND ur.fk_user= ".((int) $this->
id);
1145 $sql .=
" AND r.perms IS NOT NULL";
1147 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1150 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1153 $resql = $this->db->query($sql);
1155 $num = $this->db->num_rows($resql);
1158 $obj = $this->db->fetch_object($resql);
1161 $module = $obj->module;
1162 $perms = $obj->perms;
1163 $subperms = $obj->subperms;
1165 if (!empty($perms)) {
1166 if (!empty($module)) {
1167 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1168 $this->rights->$module =
new stdClass();
1170 if (!empty($subperms)) {
1171 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1172 $this->rights->$module->$perms =
new stdClass();
1174 if (empty($this->rights->$module->$perms->$subperms)) {
1177 $this->rights->$module->$perms->$subperms = 1;
1179 if (empty($this->rights->$module->$perms)) {
1182 $this->rights->$module->$perms = 1;
1189 $this->db->free($resql);
1193 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1194 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1195 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1196 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1197 $sql .=
" WHERE r.id = gr.fk_id";
1199 if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
1200 if (isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1201 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1203 $sql .=
" AND r.entity = ".((int) $conf->entity);
1206 $sql .=
" AND gr.entity = ".((int) $conf->entity);
1210 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1211 $sql .=
" AND r.entity = ".((int) $conf->entity);
1214 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1215 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1216 $sql .=
" AND r.perms IS NOT NULL";
1218 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1221 $resql = $this->db->query($sql);
1223 $num = $this->db->num_rows($resql);
1226 $obj = $this->db->fetch_object($resql);
1229 $module = $obj->module;
1230 $perms = $obj->perms;
1231 $subperms = $obj->subperms;
1233 if (!empty($perms)) {
1234 if (!empty($module)) {
1235 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1236 $this->rights->$module =
new stdClass();
1238 if (!empty($subperms)) {
1239 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1240 $this->rights->$module->$perms =
new stdClass();
1242 if (empty($this->rights->$module->$perms->$subperms)) {
1245 $this->rights->$module->$perms->$subperms = 1;
1247 if (empty($this->rights->$module->$perms)) {
1251 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1252 $this->rights->$module->$perms = 1;
1260 $this->db->free($resql);
1264 if (!empty($this->admin)) {
1265 if (empty($this->rights->user->user)) {
1266 $this->rights->user->user =
new stdClass();
1268 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1269 foreach ($listofpermtotest as $permtotest) {
1270 if (empty($this->rights->user->user->$permtotest)) {
1271 $this->rights->user->user->$permtotest = 1;
1275 if (empty($this->rights->user->self)) {
1276 $this->rights->user->self =
new stdClass();
1278 $listofpermtotest = array(
'creer',
'password');
1279 foreach ($listofpermtotest as $permtotest) {
1280 if (empty($this->rights->user->self->$permtotest)) {
1281 $this->rights->user->self->$permtotest = 1;
1286 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
1287 if (empty($this->rights->user->user_advance)) {
1288 $this->rights->user->user_advance =
new stdClass();
1290 $listofpermtotest = array(
'readperms',
'write');
1291 foreach ($listofpermtotest as $permtotest) {
1292 if (empty($this->rights->user->user_advance->$permtotest)) {
1293 $this->rights->user->user_advance->$permtotest = 1;
1297 if (empty($this->rights->user->self_advance)) {
1298 $this->rights->user->self_advance =
new stdClass();
1300 $listofpermtotest = array(
'readperms',
'writeperms');
1301 foreach ($listofpermtotest as $permtotest) {
1302 if (empty($this->rights->user->self_advance->$permtotest)) {
1303 $this->rights->user->self_advance->$permtotest = 1;
1307 if (empty($this->rights->user->group_advance)) {
1308 $this->rights->user->group_advance =
new stdClass();
1310 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1311 foreach ($listofpermtotest as $permtotest) {
1312 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1313 $this->rights->user->group_advance->$permtotest = 1;
1321 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1322 $this->rights->propal = $this->rights->propale;
1324 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1325 $this->rights->propale = $this->rights->propal;
1331 $this->all_permissions_are_loaded = 1;
1334 $this->_tab_loaded[$moduletag] = 1;
1346 global $conf, $langs, $user;
1351 if (isset($this->
statut)) {
1352 if ($this->
statut == $status) {
1355 } elseif (isset($this->status) && $this->status == $status) {
1362 $sql =
"UPDATE ".$this->db->prefix().
"user";
1363 $sql .=
" SET statut = ".((int) $status);
1364 $sql .=
" WHERE rowid = ".((int) $this->
id);
1365 $result = $this->db->query($sql);
1367 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1370 $this->context[
'actionmsg'] =
'User '.$this->login.
' disabled';
1372 $this->context[
'actionmsg'] =
'User '.$this->login.
' enabled';
1375 $result = $this->
call_trigger(
'USER_ENABLEDISABLE', $user);
1383 $this->db->rollback();
1386 $this->status = $status;
1388 $this->db->commit();
1405 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1406 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1417 global $conf, $langs;
1423 $this->
fetch($this->
id);
1425 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1428 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1430 if (!$error && !$this->db->query($sql)) {
1432 $this->
error = $this->db->lasterror();
1436 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1437 if (!$error && !$this->db->query($sql)) {
1439 $this->
error = $this->db->lasterror();
1443 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1444 if (!$error && !$this->db->query($sql)) {
1446 $this->
error = $this->db->lasterror();
1450 if ($this->contact_id > 0) {
1451 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1452 if (!$error && !$this->db->query($sql)) {
1454 $this->
error = $this->db->lasterror();
1463 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1469 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1470 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1471 if (!$this->db->query($sql)) {
1473 $this->
error = $this->db->lasterror();
1482 $this->db->rollback();
1487 $this->db->commit();
1490 $this->db->rollback();
1502 public function create($user, $notrigger = 0)
1504 global $conf, $langs;
1510 $this->civility_code = trim((
string) $this->civility_code);
1511 $this->login = trim((
string) $this->login);
1512 if (!isset($this->entity)) {
1513 $this->entity = $conf->entity;
1516 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1518 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1521 if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1522 $langs->load(
"errors");
1523 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1526 if (empty($this->login)) {
1527 $langs->load(
"errors");
1528 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1530 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1531 $langs->load(
"errors");
1532 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1543 $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).
"'";
1544 $resqltochecklogin = $this->db->query($sqltochecklogin);
1545 if ($resqltochecklogin) {
1546 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1547 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1548 $langs->load(
"errors");
1549 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1551 $this->db->rollback();
1554 $this->db->free($resqltochecklogin);
1557 if (!empty($this->email)) {
1558 $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).
"'";
1559 $resqltochecklogin = $this->db->query($sqltochecklogin);
1560 if ($resqltochecklogin) {
1561 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1562 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1563 $langs->load(
"errors");
1564 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
1566 $this->db->rollback();
1569 $this->db->free($resqltochecklogin);
1574 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, entity)";
1575 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->db->escape($this->login).
"', '".$this->db->escape($this->ldap_sid).
"', ".((int) $this->entity).
")";
1576 $result = $this->db->query($sql);
1578 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1580 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1584 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1585 $this->db->rollback();
1589 if (!empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER) && !empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) {
1590 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1591 $langs->load(
"stocks");
1592 $entrepot =
new Entrepot($this->db);
1593 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1594 $entrepot->libelle = $entrepot->label;
1595 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1596 $entrepot->statut = 1;
1597 $entrepot->country_id = $mysoc->country_id;
1598 $warehouseid = $entrepot->create($user);
1600 $this->fk_warehouse = $warehouseid;
1604 $result = $this->
update($user, 1, 1);
1606 $this->db->rollback();
1620 $this->db->commit();
1625 $this->db->rollback();
1629 $this->
error = $this->db->lasterror();
1630 $this->db->rollback();
1648 global $conf, $user, $langs;
1654 $this->civility_code = $contact->civility_code;
1655 $this->lastname = $contact->lastname;
1656 $this->firstname = $contact->firstname;
1658 $this->email = $contact->email;
1659 $this->socialnetworks = $contact->socialnetworks;
1660 $this->office_phone = $contact->phone_pro;
1661 $this->office_fax = $contact->fax;
1662 $this->user_mobile = $contact->phone_mobile;
1663 $this->address = $contact->address;
1664 $this->zip = $contact->zip;
1665 $this->town = $contact->town;
1667 $this->state_id = $contact->state_id;
1668 $this->country_id = $contact->country_id;
1669 $this->employee = 0;
1671 if (empty($login)) {
1672 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1673 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1675 $this->login = $login;
1680 $result = $this->
create($user, 1);
1682 $sql =
"UPDATE ".$this->db->prefix().
"user";
1683 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1684 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1685 if ($contact->socid > 0) {
1686 $sql .=
", fk_soc=".((int) $contact->socid);
1688 $sql .=
" WHERE rowid=".((int) $this->
id);
1690 $resql = $this->db->query($sql);
1692 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1694 $this->context[
'createfromcontact'] =
'createfromcontact';
1699 $error++; $this->db->rollback();
return -1;
1703 $this->db->commit();
1706 $this->
error = $this->db->error();
1708 $this->db->rollback();
1713 dol_syslog(get_class($this).
"::create_from_contact - 0");
1715 $this->db->rollback();
1732 global $conf, $user, $langs;
1736 $this->civility_code = $member->civility_id;
1737 $this->lastname = $member->lastname;
1738 $this->firstname = $member->firstname;
1739 $this->gender = $member->gender;
1740 $this->email = $member->email;
1741 $this->fk_member = $member->id;
1742 $this->address = $member->address;
1743 $this->zip = $member->zip;
1744 $this->town = $member->town;
1746 $this->state_id = $member->state_id;
1747 $this->country_id = $member->country_id;
1748 $this->socialnetworks = $member->socialnetworks;
1750 $this->pass = $member->pass;
1751 $this->pass_crypted = $member->pass_indatabase_crypted;
1753 if (empty($login)) {
1754 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1757 $this->login = $login;
1762 $result = $this->
create($user);
1764 if (!empty($this->pass)) {
1765 $newpass = $this->
setPassword($user, $this->pass);
1766 if (is_int($newpass) && $newpass < 0) {
1769 } elseif (!empty($this->pass_crypted)) {
1770 $sql =
"UPDATE ".$this->db->prefix().
"user";
1771 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
1772 $sql .=
" WHERE rowid=".((int) $this->
id);
1774 $resql = $this->db->query($sql);
1780 if ($result > 0 && $member->socid) {
1781 $sql =
"UPDATE ".$this->db->prefix().
"user";
1782 $sql .=
" SET fk_soc=".((int) $member->socid);
1783 $sql .=
" WHERE rowid=".((int) $this->
id);
1785 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
1786 $resql = $this->db->query($sql);
1788 $this->db->commit();
1791 $this->
error = $this->db->lasterror();
1793 $this->db->rollback();
1800 $this->db->commit();
1804 $this->db->rollback();
1822 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
1823 $sql .=
" WHERE bydefault = 1";
1824 $sql .=
" AND entity = ".((int) $conf->entity);
1826 $resql = $this->db->query($sql);
1828 $num = $this->db->num_rows($resql);
1831 $row = $this->db->fetch_row($resql);
1835 $this->db->free($resql);
1839 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
1840 $result = $this->db->query($sql);
1842 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
1843 $result = $this->db->query($sql);
1863 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
1865 global $conf, $langs;
1867 $nbrowsaffected = 0;
1870 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
1873 $this->civility_code = trim((
string) $this->civility_code);
1874 $this->lastname = trim((
string) $this->lastname);
1875 $this->firstname = trim((
string) $this->firstname);
1876 $this->ref_employee = trim((
string) $this->ref_employee);
1877 $this->national_registration_number = trim((
string) $this->national_registration_number);
1878 $this->employee = ($this->employee > 0 ? $this->employee : 0);
1879 $this->login = trim((
string) $this->login);
1880 $this->gender = trim((
string) $this->gender);
1882 $this->pass = trim((
string) $this->pass);
1883 $this->api_key = trim((
string) $this->api_key);
1884 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
1885 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
1887 $this->address = trim((
string) $this->address);
1888 $this->zip = trim((
string) $this->zip);
1889 $this->town = trim((
string) $this->town);
1891 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
1892 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
1893 $this->office_phone = trim((
string) $this->office_phone);
1894 $this->office_fax = trim((
string) $this->office_fax);
1895 $this->user_mobile = trim((
string) $this->user_mobile);
1896 $this->personal_mobile = trim((
string) $this->personal_mobile);
1897 $this->email = trim((
string) $this->email);
1898 $this->personal_email = trim((
string) $this->personal_email);
1900 $this->job = trim((
string) $this->job);
1901 $this->signature = trim((
string) $this->signature);
1902 $this->note_public = trim((
string) $this->note_public);
1903 $this->note_private = trim((
string) $this->note_private);
1904 $this->openid = trim((
string) $this->openid);
1905 $this->admin = ($this->admin > 0 ? $this->admin : 0);
1907 $this->accountancy_code = trim((
string) $this->accountancy_code);
1908 $this->color = trim((
string) $this->color);
1909 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
1910 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
1912 $this->birth = empty($this->birth) ?
'' : $this->birth;
1913 $this->fk_warehouse = (int) $this->fk_warehouse;
1918 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1920 if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1921 $langs->load(
"errors");
1922 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1925 if (empty($this->login)) {
1926 $langs->load(
"errors");
1927 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
1929 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1930 $langs->load(
"errors");
1931 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1938 if (!empty($this->oldcopy) && $this->oldcopy->login != $this->login) {
1939 $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).
"'";
1940 $resqltochecklogin = $this->db->query($sqltochecklogin);
1941 if ($resqltochecklogin) {
1942 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1943 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1944 $langs->load(
"errors");
1945 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1947 $this->db->rollback();
1952 if (!empty($this->oldcopy) && !empty($this->email) && $this->oldcopy->email != $this->email) {
1953 $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).
"'";
1954 $resqltochecklogin = $this->db->query($sqltochecklogin);
1955 if ($resqltochecklogin) {
1956 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1957 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1958 $langs->load(
"errors");
1959 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
1961 $this->db->rollback();
1968 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
1969 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
1970 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
1971 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
1972 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
1973 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
1974 $sql .=
", employee = ".(int) $this->employee;
1975 $sql .=
", login = '".$this->db->escape($this->login).
"'";
1976 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
1977 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
1978 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
1979 if (!empty($user->admin)) {
1980 $sql .=
", admin = ".(int) $this->admin;
1982 $sql .=
", address = '".$this->db->escape($this->address).
"'";
1983 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
1984 $sql .=
", town = '".$this->db->escape($this->town).
"'";
1985 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".$this->db->escape($this->state_id).
"'" :
"null");
1986 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".$this->db->escape($this->country_id).
"'" :
"null");
1987 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
1988 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
1989 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
1990 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
1991 $sql .=
", email = '".$this->db->escape($this->email).
"'";
1992 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
1993 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1994 $sql .=
", job = '".$this->db->escape($this->job).
"'";
1995 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
1996 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
1997 $sql .=
", color = '".$this->db->escape($this->color).
"'";
1998 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
1999 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2000 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2001 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2002 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2003 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2004 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2005 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2006 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".$this->db->escape($this->fk_user).
"'" :
"null");
2007 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".$this->db->escape($this->fk_user_expense_validator).
"'" :
"null");
2008 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".$this->db->escape($this->fk_user_holiday_validator).
"'" :
"null");
2009 if (isset($this->thm) || $this->thm !=
'') {
2010 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2012 if (isset($this->tjm) || $this->tjm !=
'') {
2013 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2015 if (isset($this->salary) || $this->salary !=
'') {
2016 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2018 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2019 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2021 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2022 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2023 $sql .=
", entity = ".((int) $this->entity);
2025 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2026 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2027 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2028 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2029 $sql .=
" WHERE rowid = ".((int) $this->
id);
2031 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2032 $resql = $this->db->query($sql);
2034 $nbrowsaffected += $this->db->affected_rows($resql);
2037 if (!empty($this->pass)) {
2038 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2040 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2041 if (is_int($result) && $result < 0) {
2048 if ($this->fk_member > 0) {
2049 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2050 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2051 $resql = $this->db->query($sql);
2053 $this->
error = $this->db->error(); $this->db->rollback();
return -5;
2057 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2058 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2059 $resql = $this->db->query($sql);
2061 $this->
error = $this->db->error(); $this->db->rollback();
return -5;
2064 if ($nbrowsaffected) {
2065 if ($this->fk_member > 0 && !$nosyncmember) {
2066 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2068 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2073 $result = $adh->fetch($this->fk_member);
2076 $adh->civility_code = $this->civility_code;
2077 $adh->firstname = $this->firstname;
2078 $adh->lastname = $this->lastname;
2079 $adh->login = $this->login;
2080 $adh->gender = $this->gender;
2081 $adh->birth = $this->birth;
2083 $adh->pass = $this->pass;
2085 $adh->address = $this->address;
2086 $adh->town = $this->town;
2087 $adh->zip = $this->zip;
2088 $adh->state_id = $this->state_id;
2089 $adh->country_id = $this->country_id;
2091 $adh->email = $this->email;
2093 $adh->socialnetworks = $this->socialnetworks;
2095 $adh->phone = $this->office_phone;
2096 $adh->phone_mobile = $this->user_mobile;
2098 $adh->default_lang = $this->lang;
2100 $adh->user_id = $this->id;
2101 $adh->user_login = $this->login;
2103 $result = $adh->update($user, 0, 1, 0);
2105 $this->
error = $adh->error;
2106 $this->errors = $adh->errors;
2107 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2110 } elseif ($result < 0) {
2111 $this->
error = $adh->error;
2112 $this->errors = $adh->errors;
2117 if ($this->contact_id > 0 && !$nosynccontact) {
2118 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2120 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2123 $tmpobj =
new Contact($this->db);
2124 $result = $tmpobj->fetch($this->contact_id);
2127 $tmpobj->civility_code = $this->civility_code;
2128 $tmpobj->firstname = $this->firstname;
2129 $tmpobj->lastname = $this->lastname;
2130 $tmpobj->login = $this->login;
2131 $tmpobj->gender = $this->gender;
2132 $tmpobj->birth = $this->birth;
2136 $tmpobj->email = $this->email;
2138 $tmpobj->socialnetworks = $this->socialnetworks;
2140 $tmpobj->phone_pro = $this->office_phone;
2141 $tmpobj->phone_mobile = $this->user_mobile;
2142 $tmpobj->fax = $this->office_fax;
2144 $tmpobj->default_lang = $this->lang;
2146 $tmpobj->address = $this->address;
2147 $tmpobj->town = $this->town;
2148 $tmpobj->zip = $this->zip;
2149 $tmpobj->state_id = $this->state_id;
2150 $tmpobj->country_id = $this->country_id;
2152 $tmpobj->user_id = $this->id;
2153 $tmpobj->user_login = $this->login;
2155 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2157 $this->
error = $tmpobj->error;
2158 $this->errors = $tmpobj->errors;
2159 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2163 $this->
error = $tmpobj->error;
2164 $this->errors = $tmpobj->errors;
2180 if (!$error && !$notrigger) {
2190 $this->db->commit();
2191 return $nbrowsaffected;
2194 $this->db->rollback();
2198 $this->
error = $this->db->lasterror();
2199 $this->db->rollback();
2218 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2219 $sql .=
" datepreviouslogin = datelastlogin,";
2220 $sql .=
" ippreviouslogin = iplastlogin,";
2221 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2222 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2223 $sql .=
" tms = tms";
2224 $sql .=
" WHERE rowid = ".((int) $this->
id);
2226 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2227 $resql = $this->db->query($sql);
2229 $this->datepreviouslogin = $this->datelastlogin;
2230 $this->datelastlogin = $now;
2231 $this->ippreviouslogin = $this->iplastlogin;
2232 $this->iplastlogin = $userremoteip;
2235 $this->
error = $this->db->lasterror().
' sql='.$sql;
2253 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2255 global $conf, $langs;
2256 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2260 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2268 if (empty($passwordalreadycrypted)) {
2269 if (!empty($conf->global->USER_PASSWORD_GENERATED)) {
2271 $modGeneratePassClass =
'modGeneratePass'.ucfirst($conf->global->USER_PASSWORD_GENERATED);
2273 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2274 if (class_exists($modGeneratePassClass)) {
2275 $modGeneratePass =
new $modGeneratePassClass($this->db, $conf, $langs, $user);
2278 $modGeneratePass->WithoutAmbi = 0;
2281 $testpassword = $modGeneratePass->validatePassword($password);
2282 if (!$testpassword) {
2283 $this->
error = $modGeneratePass->error;
2291 $password_crypted =
dol_hash($password);
2295 if (!$changelater) {
2296 if (!is_object($this->oldcopy)) {
2297 $this->oldcopy = clone $this;
2302 $sql =
"UPDATE ".$this->db->prefix().
"user";
2303 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2304 $sql .=
" pass_temp = null";
2305 if (!empty($flagdelsessionsbefore)) {
2306 $sql .=
", flagdelsessionsbefore = '".$this->db->idate(
dol_now() - 5,
'gmt').
"'";
2308 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
2309 $sql .=
", pass = null";
2311 $sql .=
", pass = '".$this->db->escape($password).
"'";
2313 $sql .=
" WHERE rowid = ".((int) $this->
id);
2315 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2316 $result = $this->db->query($sql);
2318 if ($this->db->affected_rows($result)) {
2319 $this->pass = $password;
2320 $this->pass_indatabase = $password;
2321 $this->pass_indatabase_crypted = $password_crypted;
2323 if ($this->fk_member && !$nosyncmember) {
2324 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2329 $result = $adh->fetch($this->fk_member);
2332 $result = $adh->setPassword($user, $this->pass, (empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1), 1);
2333 if (is_int($result) && $result < 0) {
2334 $this->
error = $adh->error;
2339 $this->
error = $adh->error;
2344 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2346 if (!$error && !$notrigger) {
2348 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2350 $error++; $this->db->rollback();
return -1;
2355 $this->db->commit();
2358 $this->db->rollback();
2362 $this->db->rollback();
2369 $sql =
"UPDATE ".$this->db->prefix().
"user";
2370 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2371 $sql .=
" WHERE rowid = ".((int) $this->
id);
2373 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2374 $result = $this->db->query($sql);
2396 global $conf, $langs, $mysoc;
2397 global $dolibarr_main_url_root;
2399 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2406 $outputlangs =
new Translate(
"", $conf);
2408 if (isset($this->
conf->MAIN_LANG_DEFAULT)
2409 && $this->conf->MAIN_LANG_DEFAULT !=
'auto') {
2410 $outputlangs->getDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2413 if ($this->
conf->MAIN_LANG_DEFAULT) {
2414 $outputlangs->setDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2416 $outputlangs = $langs;
2420 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2422 $appli = constant(
'DOL_APPLICATION_TITLE');
2423 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
2424 $appli = $conf->global->MAIN_APPLICATION_TITLE;
2427 $subject =
'['.$mysoc->name.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2430 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2431 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2433 if (!$changelater) {
2434 $url = $urlwithroot.
'/';
2435 if (!empty($conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD)) {
2436 $url = $conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD;
2439 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2441 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2442 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2443 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2444 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2447 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2449 $mesg .= $user->getFullName($outputlangs);
2452 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2453 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.$conf->file->instance_unique_id));
2454 if (isModEnabled(
'multicompany')) {
2455 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2458 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2462 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2463 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2464 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2465 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2467 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2468 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2469 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2472 $trackid =
'use'.$this->id;
2473 $sendcontext =
'password';
2478 $conf->global->MAIN_MAIL_EMAIL_FROM,
2494 if ($mailfile->sendfile()) {
2497 $langs->trans(
"errors");
2498 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2510 return $this->error;
2523 $sql =
"SELECT url, login, pass, poste ";
2524 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2525 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2527 $resql = $this->db->query($sql);
2529 if ($this->db->num_rows($resql)) {
2530 $obj = $this->db->fetch_object($resql);
2532 $this->clicktodial_url = $obj->url;
2533 $this->clicktodial_login = $obj->login;
2534 $this->clicktodial_password = $obj->pass;
2535 $this->clicktodial_poste = $obj->poste;
2538 $this->clicktodial_loaded = 1;
2540 $this->db->free($resql);
2543 $this->
error = $this->db->error();
2559 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2560 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2562 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2563 $result = $this->db->query($sql);
2565 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2566 $sql .=
" (fk_user,url,login,pass,poste)";
2567 $sql .=
" VALUES (".$this->id;
2568 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2569 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2570 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2571 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2573 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2574 $result = $this->db->query($sql);
2576 $this->db->commit();
2579 $this->db->rollback();
2580 $this->
error = $this->db->lasterror();
2598 global $conf, $langs, $user;
2604 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2605 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2606 $sql .=
" AND fk_usergroup = ".((int) $group);
2607 $sql .=
" AND entity = ".((int) $entity);
2609 $result = $this->db->query($sql);
2611 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2612 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2614 $result = $this->db->query($sql);
2616 if (!$error && !$notrigger) {
2617 $this->newgroupid = $group;
2618 $this->context = array(
'audit'=>$langs->trans(
"UserSetInGroup"),
'newgroupid'=>$group);
2629 $this->db->commit();
2633 $this->db->rollback();
2637 $this->
error = $this->db->lasterror();
2638 $this->db->rollback();
2655 global $conf, $langs, $user;
2661 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2662 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2663 $sql .=
" AND fk_usergroup = ".((int) $group);
2664 if (empty($entity)) {
2665 $sql .=
" AND entity IN (0, 1)";
2667 $sql .=
" AND entity = ".((int) $entity);
2670 $result = $this->db->query($sql);
2672 if (!$error && !$notrigger) {
2673 $this->oldgroupid = $group;
2674 $this->context = array(
'audit'=>$langs->trans(
"UserRemovedFromGroup"),
'oldgroupid'=>$group);
2685 $this->db->commit();
2688 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2689 $this->db->rollback();
2693 $this->
error = $this->db->lasterror();
2694 $this->db->rollback();
2708 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2715 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
2737 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
2739 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2740 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
2755 global $conf, $langs, $menumanager;
2757 $infologin = $params[
'infologin'] ?? 0;
2758 $option = $params[
'option'] ??
'';
2761 if (!empty($this->photo)) {
2762 $photo =
'<div class="photointooltip floatright">';
2763 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
2765 $datas[
'photo'] = $photo;
2770 $datas[
'opendiv'] =
'<div class="centpercent">';
2771 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
2773 if (!empty($this->login)) {
2774 $datas[
'login'] =
'<br><b>'.$langs->trans(
'Login').
':</b> '.
dol_string_nohtmltag($this->login);
2776 if (!empty($this->job)) {
2779 $datas[
'email'] =
'<br><b>'.$langs->trans(
"Email").
':</b> '.
dol_string_nohtmltag($this->email);
2780 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
2781 $phonelist = array();
2782 if ($this->office_phone) {
2783 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2785 if ($this->office_fax) {
2786 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2788 if ($this->user_mobile) {
2789 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
2791 $datas[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
2793 if (!empty($this->admin)) {
2794 $datas[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
2796 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
2797 $datas[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
2800 if (!empty($this->socid)) {
2801 $thirdpartystatic =
new Societe($this->db);
2802 $thirdpartystatic->fetch($this->socid);
2803 if (empty($hidethirdpartylogo)) {
2804 $companylink =
' '.$thirdpartystatic->getNomUrl(2, (($option ==
'nolink') ?
'nolink' :
''));
2808 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
2809 $datas[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
2810 $datas[
'closediv'] =
'</div>';
2812 if ($infologin > 0) {
2813 $datas[
'newlinelogin'] =
'<br>';
2814 $datas[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
2816 if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) {
2817 $datas[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.$conf->entity.
' (User entity '.$this->entity.
')';
2819 $datas[
'authentication'] =
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
2820 $datas[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
2821 $datas[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
2822 $datas[
'currenttheme'] =
'<br><b>'.$langs->trans(
"CurrentTheme").
':</b> '.
dol_string_nohtmltag($conf->theme);
2823 $datas[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
2825 $datas[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
2826 $datas[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag($conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
2827 $datas[
'layout'] =
'<br><b>'.$langs->trans(
"Layout").
':</b> '.
dol_string_nohtmltag($conf->browser->layout);
2828 $datas[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
2829 if ($conf->browser->layout ==
'phone') {
2830 $datas[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
2832 if (!empty($_SESSION[
"disablemodules"])) {
2833 $datas[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(join(
', ', explode(
',', $_SESSION[
"disablemodules"])));
2855 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
2857 global $langs, $conf, $db, $hookmanager, $user;
2858 global $dolibarr_main_authentication, $dolibarr_main_demo;
2859 global $menumanager;
2861 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
2865 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) {
2872 'objecttype' => $this->element,
2873 'infologin' => $infologin,
2874 'option' => $option,
2876 $classfortooltip =
'classfortooltip';
2879 $classfortooltip =
'classforajaxtooltip';
2880 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
2887 if (!empty($this->socid)) {
2888 $thirdpartystatic =
new Societe($this->db);
2889 $thirdpartystatic->fetch($this->socid);
2890 if (empty($hidethirdpartylogo)) {
2891 $companylink =
' '.$thirdpartystatic->getNomUrl(2, (($option ==
'nolink') ?
'nolink' :
''));
2895 if ($infologin < 0) {
2899 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
2900 if ($option ==
'leave') {
2901 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
2904 if ($option !=
'nolink') {
2906 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2907 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2908 $add_save_lastsearch_values = 1;
2910 if ($add_save_lastsearch_values) {
2911 $url .=
'&save_lastsearch_values=1';
2915 $linkstart =
'<a href="'.$url.
'"';
2917 if (empty($notooltip)) {
2918 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2919 $langs->load(
"users");
2920 $label = $langs->trans(
"ShowUser");
2921 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2923 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
2924 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
2926 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
2929 $linkstart .= $linkclose.
'>';
2933 $result .= (($option ==
'nolink') ?
'' : $linkstart);
2934 if ($withpictoimg) {
2935 $paddafterimage =
'';
2936 if (abs((
int) $withpictoimg) == 1) {
2937 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
2940 if ($withpictoimg > 0) {
2941 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' class="paddingright")', 0, 0, $notooltip ? 0 : 1).
'</span>';
2944 $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>';
2948 if ($withpictoimg > -2 && $withpictoimg != 2) {
2949 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2950 $result .=
'<span class="nopadding usertext'.((!isset($this->
statut) || $this->statut) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
2952 if ($mode ==
'login') {
2957 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2958 $result .=
'</span>';
2961 $result .= (($option ==
'nolink') ?
'' : $linkend);
2964 $result .= $companylink;
2967 $hookmanager->initHooks(array(
'userdao'));
2968 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
2969 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2971 $result = $hookmanager->resPrint;
2973 $result .= $hookmanager->resPrint;
2988 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
2990 global $langs, $user;
2994 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2998 if ((!$user->rights->user->user->lire && $this->id != $user->id)) {
3002 if ($option ==
'xxx') {
3003 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3007 if ($option ==
'nolink') {
3012 $result .= $linkstart;
3013 if ($withpictoimg) {
3014 $paddafterimage =
'';
3015 if (abs($withpictoimg) == 1) {
3016 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3019 if ($withpictoimg > 0) {
3020 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3023 $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>';
3027 $result .= $this->login;
3028 $result .= $linkend;
3057 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3060 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3061 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3062 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3063 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3066 $statusType =
'status5';
3067 if ($status == self::STATUS_ENABLED) {
3068 $statusType =
'status4';
3071 $label = $this->labelStatus[$status];
3072 $labelshort = $this->labelStatusShort[$status];
3075 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3076 $statusType =
'status3';
3077 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3079 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3080 $statusType =
'status2';
3081 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3084 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3099 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3101 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3102 $return .=
'<div class="info-box info-box-sm">';
3103 $return .=
'<span class="info-box-icon bg-infobox-action">';
3106 if (!empty($this->photo)) {
3108 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3117 $return .=
'</span>';
3118 $return .=
'<div class="info-box-content">';
3119 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3120 if (isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3121 $return .=
img_picto($langs->trans(
"SuperAdministrator"),
'redstar',
'class="valignmiddle paddingright paddingleft"');
3122 } elseif ($this->admin) {
3123 $return .=
img_picto($langs->trans(
"Administrator"),
'star',
'class="valignmiddle paddingright paddingleft"');
3125 $return .=
'</span>';
3126 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3127 if (property_exists($this,
'label')) {
3128 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3131 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->email.
'</span>';
3133 if (method_exists($this,
'getLibStatut')) {
3134 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
3136 $return .=
'</div>';
3137 $return .=
'</div>';
3138 $return .=
'</div>';
3161 $dn = $conf->global->LDAP_KEY_USERS.
"=".$info[$conf->global->LDAP_KEY_USERS].
",".$conf->global->LDAP_USER_DN;
3162 } elseif ($mode == 1) {
3163 $dn = $conf->global->LDAP_USER_DN;
3164 } elseif ($mode == 2) {
3165 $dn = $conf->global->LDAP_KEY_USERS.
"=".$info[$conf->global->LDAP_KEY_USERS];
3180 global $conf, $langs;
3186 $keymodified =
false;
3189 $info[
"objectclass"] = explode(
',', $conf->global->LDAP_USER_OBJECT_CLASS);
3195 'LDAP_FIELD_FULLNAME' =>
'fullname',
3196 'LDAP_FIELD_NAME' =>
'lastname',
3197 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3198 'LDAP_FIELD_LOGIN' =>
'login',
3199 'LDAP_FIELD_LOGIN_SAMBA'=>
'login',
3200 'LDAP_FIELD_PHONE' =>
'office_phone',
3201 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3202 'LDAP_FIELD_FAX' =>
'office_fax',
3203 'LDAP_FIELD_MAIL' =>
'email',
3204 'LDAP_FIELD_SID' =>
'ldap_sid',
3208 foreach ($ldapkey as $constname => $varname) {
3209 if (!empty($this->$varname) && !empty($conf->global->$constname)) {
3210 $info[$conf->global->$constname] = $this->$varname;
3213 if (!empty($conf->global->LDAP_KEY_USERS) && $conf->global->LDAP_KEY_USERS == $conf->global->$constname) {
3214 if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
3215 $keymodified =
true;
3220 foreach ($socialnetworks as $key => $value) {
3221 if (!empty($this->socialnetworks[$value[
'label']]) && !empty($conf->global->{
'LDAP_FIELD_'.strtoupper($value[
'label'])})) {
3222 $info[$conf->global->{
'LDAP_FIELD_'.strtoupper($value[
'label'])}] = $this->socialnetworks[$value[
'label']];
3225 if ($this->address && !empty($conf->global->LDAP_FIELD_ADDRESS)) {
3226 $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->address;
3228 if ($this->zip && !empty($conf->global->LDAP_FIELD_ZIP)) {
3229 $info[$conf->global->LDAP_FIELD_ZIP] = $this->zip;
3231 if ($this->town && !empty($conf->global->LDAP_FIELD_TOWN)) {
3232 $info[$conf->global->LDAP_FIELD_TOWN] = $this->town;
3234 if ($this->note_public && !empty($conf->global->LDAP_FIELD_DESCRIPTION)) {
3237 if ($this->socid > 0) {
3238 $soc =
new Societe($this->db);
3239 $soc->fetch($this->socid);
3241 $info[$conf->global->LDAP_FIELD_COMPANY] = $soc->name;
3242 if ($soc->client == 1) {
3243 $info[
"businessCategory"] =
"Customers";
3245 if ($soc->client == 2) {
3246 $info[
"businessCategory"] =
"Prospects";
3248 if ($soc->fournisseur == 1) {
3249 $info[
"businessCategory"] =
"Suppliers";
3254 if (!empty($this->pass)) {
3255 if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
3256 $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass;
3258 if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3259 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass,
'openldap');
3261 } elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !==
'3') {
3264 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
3266 if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) {
3267 if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3268 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dolGetLdapPasswordHash($this->pass_indatabase_crypted,
'md5frommd5');
3271 } elseif (!empty($this->pass_indatabase)) {
3273 if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
3274 $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass_indatabase;
3276 if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3277 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass_indatabase,
'openldap');
3282 if ($conf->global->LDAP_SERVER_TYPE ==
'egroupware') {
3283 $info[
"objectclass"][4] =
"phpgwContact";
3285 $info[
'uidnumber'] = $this->id;
3287 $info[
'phpgwTz'] = 0;
3288 $info[
'phpgwMailType'] =
'INTERNET';
3289 $info[
'phpgwMailHomeType'] =
'INTERNET';
3291 $info[
"phpgwContactTypeId"] =
'n';
3292 $info[
"phpgwContactCatId"] = 0;
3293 $info[
"phpgwContactAccess"] =
"public";
3296 $this->egroupware_id = 1;
3299 $info[
"phpgwContactOwner"] = $this->egroupware_id;
3302 $info[
"rfc822Mailbox"] = $this->email;
3304 if ($this->phone_mobile) {
3305 $info[
"phpgwCellTelephoneNumber"] = $this->phone_mobile;
3309 if (!empty($conf->global->LDAP_FIELD_USERID)) {
3310 $info[$conf->global->LDAP_FIELD_USERID] = $this->id;
3312 if (!empty($conf->global->LDAP_FIELD_GROUPID)) {
3314 $groupslist = $usergroup->listGroupsForUser($this->
id);
3315 $info[$conf->global->LDAP_FIELD_GROUPID] =
'65534';
3316 if (!empty($groupslist)) {
3317 foreach ($groupslist as $groupforuser) {
3318 $info[$conf->global->LDAP_FIELD_GROUPID] = $groupforuser->id;
3323 if (!empty($conf->global->LDAP_FIELD_HOMEDIRECTORY) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX)) {
3324 $info[$conf->global->LDAP_FIELD_HOMEDIRECTORY] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->login";
3340 global $user, $langs;
3346 $this->
ref =
'SPECIMEN';
3347 $this->specimen = 1;
3349 $this->lastname =
'DOLIBARR';
3350 $this->firstname =
'SPECIMEN';
3351 $this->gender =
'man';
3352 $this->note_public =
'This is a note public';
3353 $this->note_private =
'This is a note private';
3354 $this->email =
'email@specimen.com';
3355 $this->personal_email =
'personalemail@specimen.com';
3356 $this->socialnetworks = array(
3357 'skype' =>
'skypepseudo',
3358 'twitter' =>
'twitterpseudo',
3359 'facebook' =>
'facebookpseudo',
3360 'linkedin' =>
'linkedinpseudo',
3362 $this->office_phone =
'0999999999';
3363 $this->office_fax =
'0999999998';
3364 $this->user_mobile =
'0999999997';
3365 $this->personal_mobile =
'0999999996';
3367 $this->login =
'dolibspec';
3368 $this->pass =
'dolibSpec+@123';
3371 $this->datec = $now;
3372 $this->datem = $now;
3374 $this->datelastlogin = $now;
3375 $this->iplastlogin =
'127.0.0.1';
3376 $this->datepreviouslogin = $now;
3377 $this->ippreviouslogin =
'127.0.0.1';
3393 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
3394 $sql .=
" u.tms as date_modification, u.entity";
3395 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3396 $sql .=
" WHERE u.rowid = ".((int) $id);
3398 $result = $this->db->query($sql);
3400 if ($this->db->num_rows($result)) {
3401 $obj = $this->db->fetch_object($result);
3403 $this->
id = $obj->rowid;
3405 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3406 $this->date_creation = $this->db->jdate($obj->datec);
3407 $this->date_modification = $this->db->jdate($obj->date_modification);
3408 $this->entity = $obj->entity;
3411 $this->db->free($result);
3425 $sql =
"SELECT count(mc.email) as nb";
3426 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3427 $sql .=
" WHERE mc.email = '".$this->db->escape($this->email).
"'";
3428 $sql .=
" AND mc.statut NOT IN (-1,0)";
3430 $resql = $this->db->query($sql);
3432 $obj = $this->db->fetch_object($resql);
3435 $this->db->free($resql);
3438 $this->error = $this->db->error();
3455 $sql =
"SELECT count(rowid) as nb";
3456 $sql .=
" FROM ".$this->db->prefix().
"user";
3457 if ($option ==
'superadmin') {
3458 $sql .=
" WHERE entity = 0";
3460 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3461 if ($limitTo ==
'active') {
3462 $sql .=
" AND statut = 1";
3466 $sql .=
" AND admin = ".(int) $admin;
3469 $resql = $this->db->query($sql);
3471 $obj = $this->db->fetch_object($resql);
3472 $nb = (int) $obj->nb;
3474 $this->db->free($resql);
3477 $this->error = $this->db->lasterror();
3493 global $user, $conf;
3498 $this->firstname = $ldapuser->$tmpvar;
3500 $this->lastname = $ldapuser->$tmpvar;
3502 $this->login = $ldapuser->$tmpvar;
3504 $this->pass = $ldapuser->$tmpvar;
3506 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3509 $this->office_phone = $ldapuser->$tmpvar;
3511 $this->user_mobile = $ldapuser->$tmpvar;
3513 $this->office_fax = $ldapuser->$tmpvar;
3515 $this->email = $ldapuser->$tmpvar;
3516 foreach ($socialnetworks as $key => $value) {
3518 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3521 $this->ldap_sid = $ldapuser->$tmpvar;
3524 $this->job = $ldapuser->$tmpvar;
3526 $this->note_public = $ldapuser->$tmpvar;
3528 $result = $this->update($user);
3530 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3546 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3547 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3549 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3550 $res = $this->db->query($sql);
3553 while ($rec = $this->db->fetch_array($res)) {
3554 $user =
new User($this->db);
3555 $user->fetch($rec[
'rowid']);
3575 $this->parentof = array();
3578 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3579 $sql .=
" FROM ".$this->db->prefix().
"user";
3580 $sql .=
" WHERE fk_user <> 0";
3581 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3583 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3584 $resql = $this->db->query($sql);
3586 while ($obj = $this->db->fetch_object($resql)) {
3587 $this->parentof[$obj->id_son] = $obj->id_parent;
3613 global $conf, $user;
3614 global $hookmanager;
3617 $hookmanager->initHooks(array(
'userdao'));
3619 $this->users = array();
3622 $this->loadParentOf();
3625 $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";
3626 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3628 $parameters = array();
3629 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3631 $sql .= $hookmanager->resPrint;
3633 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3636 $sql .=
" AND ".$filter;
3639 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3640 $resql = $this->db->query($sql);
3643 while ($obj = $this->db->fetch_object($resql)) {
3644 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3645 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3646 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3647 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3648 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3649 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3650 $this->users[$obj->rowid][
'login'] = $obj->login;
3651 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3652 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3653 $this->users[$obj->rowid][
'email'] = $obj->email;
3654 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3655 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3656 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3665 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3666 foreach ($this->users as $key => $val) {
3667 $result = $this->build_path_from_id_user($key, 0);
3669 $this->error =
'ErrorLoopInHierarchy';
3675 if ($deleteafterid) {
3677 $keyfilter1 =
'^'.$deleteafterid.
'$';
3678 $keyfilter2 =
'_'.$deleteafterid.
'$';
3679 $keyfilter3 =
'^'.$deleteafterid.
'_';
3680 $keyfilter4 =
'_'.$deleteafterid.
'_';
3681 foreach ($this->users as $key => $val) {
3682 if (preg_match(
'/'.$keyfilter1.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter2.
'/', $val[
'fullpath'])
3683 || preg_match(
'/'.$keyfilter3.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter4.
'/', $val[
'fullpath'])) {
3684 unset($this->users[$key]);
3689 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
3690 $this->users =
dol_sort_array($this->users,
'fullname',
'asc',
true,
false, 1);
3694 return $this->users;
3707 $childids = array();
3709 if (isset($this->cache_childids[$this->
id])) {
3710 $childids = $this->cache_childids[$this->id];
3713 $this->get_full_tree();
3715 $idtoscan = $this->id;
3717 dol_syslog(
"Build childid for id = ".$idtoscan);
3718 foreach ($this->users as $id => $val) {
3720 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
3721 $childids[$val[
'id']] = $val[
'id'];
3725 $this->cache_childids[$this->id] = $childids;
3727 if ($addcurrentuser) {
3728 $childids[$this->id] = $this->id;
3748 if (!empty($this->users[$id_user][
'fullpath'])) {
3750 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
3755 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
3756 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
3757 $i = 0; $cursor_user = $id_user;
3759 $useridfound = array($id_user);
3760 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
3761 if (in_array($this->parentof[$cursor_user], $useridfound)) {
3762 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
3765 $useridfound[] = $this->parentof[$cursor_user];
3766 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
3767 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
3768 $i++; $cursor_user = $this->parentof[$cursor_user];
3772 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
3806 $this->nb = array();
3808 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
3809 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3810 if (isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
3811 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
3812 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
3813 $sql .=
" AND ug.fk_user = u.rowid";
3815 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3817 $sql .=
" AND u.statut > 0";
3820 $resql = $this->db->query($sql);
3822 while ($obj = $this->db->fetch_object($resql)) {
3823 $this->nb[
"users"] = $obj->nb;
3825 $this->db->free($resql);
3829 $this->error = $this->db->error();
3845 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3847 global $conf, $user, $langs;
3849 $langs->load(
"user");
3853 if (!empty($conf->global->USER_ADDON_PDF)) {
3854 $modele = $conf->global->USER_ADDON_PDF;
3856 $modele =
'bluesky';
3860 $modelpath =
"core/modules/user/doc/";
3862 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3876 $user_property =
'';
3878 if (empty($rowid)) {
3882 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
3883 $sql .=
" FROM ".$this->db->prefix().
"user";
3884 $sql .=
" WHERE rowid = ".((int) $rowid);
3886 $resql = $this->db->query($sql);
3888 $nump = $this->db->num_rows($resql);
3891 $obj = $this->db->fetch_object($resql);
3893 if ($mode ==
'email') {
3894 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
3895 } elseif ($mode ==
'mobile') {
3896 $user_property = $obj->user_mobile;
3899 return $user_property;
3916 global $dolibarr_main_url_root;
3919 $encodedsecurekey =
dol_hash($conf->file->instance_unique_id.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
3920 if (isModEnabled(
'multicompany')) {
3921 $entity_qr =
'&entity='.((int) $conf->entity);
3926 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
3927 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
3930 if ($typeofurl ==
'internal') {
3931 $urlwithroot = DOL_URL_ROOT;
3934 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
3949 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter = array(), $filtermode =
'AND', $entityfilter =
false)
3951 global $conf, $user;
3953 $sql =
"SELECT t.rowid";
3954 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
3956 if ($entityfilter) {
3957 if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
3958 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
3959 $sql .=
" WHERE t.entity IS NOT NULL";
3961 $sql .=
" WHERE t.entity = 0 OR EXISTS (";
3962 $sql .=
" SELECT ug.rowid FROM " . $this->db->prefix() .
"usergroup_user as ug";
3963 $sql .=
" WHERE ug.fk_user = t.rowid AND ug.entity IN (" .
getEntity(
'usergroup') .
"))";
3966 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
3969 $sql .=
" WHERE 1 = 1";
3973 $sqlwhere = array();
3974 if (!empty($filter)) {
3975 foreach ($filter as $key => $value) {
3976 if ($key ==
't.rowid') {
3977 $sqlwhere[] = $key.
" = ".((int) $value);
3978 } elseif (isset($this->fields[$key][
'type']) && in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
3979 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
3980 } elseif ($key ==
'customsql') {
3981 $sqlwhere[] = $value;
3983 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
3987 if (count($sqlwhere) > 0) {
3988 $sql .=
' AND ('.implode(
' '.$this->db->escape($filtermode).
' ', $sqlwhere).
')';
3990 $sql .= $this->db->order($sortfield, $sortorder);
3992 $sql .= $this->db->plimit($limit + 1, $offset);
3997 $resql = $this->db->query($sql);
3999 $this->users = array();
4000 $num = $this->db->num_rows($resql);
4002 while ($obj = $this->db->fetch_object($resql)) {
4003 $line =
new self($this->db);
4004 $result = $line->fetch($obj->rowid);
4005 if ($result > 0 && !empty($line->id)) {
4006 $this->users[$obj->rowid] = clone $line;
4009 $this->db->free($resql);
4013 $this->errors[] = $this->db->lasterror();
4025 private $findUserIdByEmailCache;
4039 if (isset($this->findUserIdByEmailCache[$email])) {
4040 return $this->findUserIdByEmailCache[$email];
4043 $this->findUserIdByEmailCache[$email] = -1;
4047 $sql =
'SELECT rowid';
4048 $sql .=
' FROM '.$this->db->prefix().
'user';
4049 if (!empty($conf->global->AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR)) {
4050 $sql .=
" WHERE email LIKE '%".$this->db->escape($email).
"%'";
4052 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4056 $resql = $this->db->query($sql);
4061 $obj = $this->db->fetch_object($resql);
4066 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4068 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...
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.
print $langs trans("Ref").' m m m statut
trait CommonPeople
Superclass for thirdparties, contacts, members or users.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
getArrayOfSocialNetworks()
Get array of social network dictionary.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getUserRemoteIP()
Return the IP of remote user.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
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.