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 'project' =>
'projet',
701 'propale' =>
'propal',
702 'shipping' =>
'expedition',
703 'task' =>
'task@projet',
704 'fichinter' =>
'ficheinter',
705 'inventory' =>
'stock',
706 'invoice' =>
'facture',
707 'invoice_supplier' =>
'fournisseur',
708 'order_supplier' =>
'fournisseur',
709 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
710 'skill@hrm' =>
'all@hrm',
711 'job@hrm' =>
'all@hrm',
712 'position@hrm' =>
'all@hrm',
713 'facturerec' =>
'facture',
714 'margins' =>
'margin',
717 if (!empty($moduletomoduletouse[$module])) {
718 $module = $moduletomoduletouse[$module];
721 $moduleRightsMapping = array(
722 'product' =>
'produit',
723 'margin' =>
'margins',
724 'comptabilite' =>
'compta'
727 $rightsPath = $module;
728 if (!empty($moduleRightsMapping[$rightsPath])) {
729 $rightsPath = $moduleRightsMapping[$rightsPath];
733 $tmp = explode(
'@', $rightsPath, 2);
734 if (!empty($tmp[1])) {
735 if (strpos($module,
'@') !==
false) {
738 $rightsPath = $tmp[1];
739 $permlevel2 = $permlevel1;
740 $permlevel1 = $tmp[0];
750 if (!isModEnabled($module)) {
755 if ($permlevel1 ==
'propale') {
756 $permlevel1 =
'propal';
758 if ($permlevel1 ==
'member') {
759 $permlevel1 =
'adherent';
761 if ($permlevel1 ==
'recruitmentcandidature') {
762 $permlevel1 =
'recruitmentjobposition';
767 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
772 if (!empty($this->rights->$rightsPath->$permlevel1)) {
773 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
774 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
778 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
779 return $this->rights->$rightsPath->$permlevel1->lire;
781 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
782 return $this->rights->$rightsPath->$permlevel1->creer;
784 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
785 return $this->rights->$rightsPath->$permlevel1->create;
787 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
788 return $this->rights->$rightsPath->$permlevel1->supprimer;
792 if (!empty($this->rights->$rightsPath->$permlevel1)) {
793 return $this->rights->$rightsPath->$permlevel1;
797 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
798 return $this->rights->$rightsPath->lire;
800 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
801 return $this->rights->$rightsPath->creer;
803 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
804 return $this->rights->$rightsPath->create;
806 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
807 return $this->rights->$rightsPath->supprimer;
825 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
827 global $conf, $user, $langs;
829 $entity = (empty($entity) ? $conf->entity : $entity);
831 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
833 if (empty($this->
id)) {
835 $this->
error =
'Try to call addrights on an object user with an empty id';
845 $module = $perms = $subperms =
'';
848 $sql =
"SELECT module, perms, subperms";
849 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
850 $sql .=
" WHERE id = ".((int) $rid);
851 $sql .=
" AND entity = ".((int) $entity);
853 $result = $this->db->query($sql);
855 $obj = $this->db->fetch_object($result);
858 $module = $obj->module;
859 $perms = $obj->perms;
860 $subperms = $obj->subperms;
868 $whereforadd =
"id=".((int) $rid);
870 if (!empty($subperms)) {
871 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
872 } elseif (!empty($perms)) {
873 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
879 if (!empty($allmodule)) {
880 if ($allmodule ==
'allmodules') {
881 $whereforadd =
'allmodules';
883 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
884 if (!empty($allperms)) {
885 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
893 if (!empty($whereforadd)) {
896 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
897 $sql .=
" WHERE entity = ".((int) $entity);
898 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
899 $sql .=
" AND (".$whereforadd.
")";
902 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
903 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
905 $sqldelete .=
") AND entity = ".((int) $entity);
906 if (!$this->db->query($sqldelete)) {
911 $resql = $this->db->query($sql);
913 $num = $this->db->num_rows($resql);
916 $obj = $this->db->fetch_object($resql);
921 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
922 if (!$this->db->query($sql)) {
936 if (!$error && !$notrigger) {
937 $langs->load(
"other");
938 $this->context = array(
'audit'=>$langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
949 $this->db->rollback();
969 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
971 global $conf, $user, $langs;
975 $entity = (!empty($entity) ? $entity : $conf->entity);
980 $module = $perms = $subperms =
'';
984 $sql =
"SELECT module, perms, subperms";
985 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
986 $sql .=
" WHERE id = '".$this->db->escape($rid).
"'";
987 $sql .=
" AND entity = ".((int) $entity);
989 $result = $this->db->query($sql);
991 $obj = $this->db->fetch_object($result);
994 $module = $obj->module;
995 $perms = $obj->perms;
996 $subperms = $obj->subperms;
1004 $wherefordel =
"id=".((int) $rid);
1006 if ($subperms ==
'lire' || $subperms ==
'read') {
1007 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1009 if ($perms ==
'lire' || $perms ==
'read') {
1010 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1015 if (!empty($allmodule)) {
1016 if ($allmodule ==
'allmodules') {
1017 $wherefordel =
'allmodules';
1019 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1020 if (!empty($allperms)) {
1021 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1028 if (!empty($wherefordel)) {
1031 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1032 $sql .=
" WHERE entity = ".((int) $entity);
1033 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1034 $sql .=
" AND (".$wherefordel.
")";
1038 if ($this->admin == 1) {
1039 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1040 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1041 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1042 $sql .=
" AND id NOT IN (358)";
1045 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1046 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1049 $sqldelete .=
" AND entity = ".((int) $entity);
1051 $resql = $this->db->query($sqldelete);
1058 if (!$error && !$notrigger) {
1059 $langs->load(
"other");
1060 $this->context = array(
'audit'=>$langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1071 $this->db->rollback();
1074 $this->db->commit();
1088 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1089 $this->rights =
null;
1090 $this->nb_rights = 0;
1091 $this->all_permissions_are_loaded = 0;
1092 $this->_tab_loaded = array();
1104 public function getrights($moduletag =
'', $forcereload = 0)
1108 if (empty($forcereload)) {
1109 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1114 if (!empty($this->all_permissions_are_loaded)) {
1121 if (!isset($this->rights) || !is_object($this->rights)) {
1122 $this->rights =
new stdClass();
1124 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1125 $this->rights->user =
new stdClass();
1131 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1132 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1133 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1134 $sql .=
" WHERE r.id = ur.fk_id";
1135 if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
1137 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ?
"1," :
"").$conf->entity.
")";
1141 $sql .=
" AND r.entity = ".((int) $conf->entity).
" AND ur.entity = ".((int) $conf->entity);
1143 $sql .=
" AND ur.fk_user= ".((int) $this->
id);
1144 $sql .=
" AND r.perms IS NOT NULL";
1146 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1149 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1152 $resql = $this->db->query($sql);
1154 $num = $this->db->num_rows($resql);
1157 $obj = $this->db->fetch_object($resql);
1160 $module = $obj->module;
1161 $perms = $obj->perms;
1162 $subperms = $obj->subperms;
1164 if (!empty($perms)) {
1165 if (!empty($module)) {
1166 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1167 $this->rights->$module =
new stdClass();
1169 if (!empty($subperms)) {
1170 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1171 $this->rights->$module->$perms =
new stdClass();
1173 if (empty($this->rights->$module->$perms->$subperms)) {
1176 $this->rights->$module->$perms->$subperms = 1;
1178 if (empty($this->rights->$module->$perms)) {
1181 $this->rights->$module->$perms = 1;
1188 $this->db->free($resql);
1192 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1193 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1194 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1195 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1196 $sql .=
" WHERE r.id = gr.fk_id";
1198 if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
1199 if (isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1200 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1202 $sql .=
" AND r.entity = ".((int) $conf->entity);
1205 $sql .=
" AND gr.entity = ".((int) $conf->entity);
1209 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1210 $sql .=
" AND r.entity = ".((int) $conf->entity);
1213 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1214 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1215 $sql .=
" AND r.perms IS NOT NULL";
1217 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1220 $resql = $this->db->query($sql);
1222 $num = $this->db->num_rows($resql);
1225 $obj = $this->db->fetch_object($resql);
1228 $module = $obj->module;
1229 $perms = $obj->perms;
1230 $subperms = $obj->subperms;
1232 if (!empty($perms)) {
1233 if (!empty($module)) {
1234 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1235 $this->rights->$module =
new stdClass();
1237 if (!empty($subperms)) {
1238 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1239 $this->rights->$module->$perms =
new stdClass();
1241 if (empty($this->rights->$module->$perms->$subperms)) {
1244 $this->rights->$module->$perms->$subperms = 1;
1246 if (empty($this->rights->$module->$perms)) {
1250 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1251 $this->rights->$module->$perms = 1;
1259 $this->db->free($resql);
1263 if (!empty($this->admin)) {
1264 if (empty($this->rights->user->user)) {
1265 $this->rights->user->user =
new stdClass();
1267 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1268 foreach ($listofpermtotest as $permtotest) {
1269 if (empty($this->rights->user->user->$permtotest)) {
1270 $this->rights->user->user->$permtotest = 1;
1274 if (empty($this->rights->user->self)) {
1275 $this->rights->user->self =
new stdClass();
1277 $listofpermtotest = array(
'creer',
'password');
1278 foreach ($listofpermtotest as $permtotest) {
1279 if (empty($this->rights->user->self->$permtotest)) {
1280 $this->rights->user->self->$permtotest = 1;
1285 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
1286 if (empty($this->rights->user->user_advance)) {
1287 $this->rights->user->user_advance =
new stdClass();
1289 $listofpermtotest = array(
'readperms',
'write');
1290 foreach ($listofpermtotest as $permtotest) {
1291 if (empty($this->rights->user->user_advance->$permtotest)) {
1292 $this->rights->user->user_advance->$permtotest = 1;
1296 if (empty($this->rights->user->self_advance)) {
1297 $this->rights->user->self_advance =
new stdClass();
1299 $listofpermtotest = array(
'readperms',
'writeperms');
1300 foreach ($listofpermtotest as $permtotest) {
1301 if (empty($this->rights->user->self_advance->$permtotest)) {
1302 $this->rights->user->self_advance->$permtotest = 1;
1306 if (empty($this->rights->user->group_advance)) {
1307 $this->rights->user->group_advance =
new stdClass();
1309 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1310 foreach ($listofpermtotest as $permtotest) {
1311 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1312 $this->rights->user->group_advance->$permtotest = 1;
1320 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1321 $this->rights->propal = $this->rights->propale;
1323 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1324 $this->rights->propale = $this->rights->propal;
1330 $this->all_permissions_are_loaded = 1;
1333 $this->_tab_loaded[$moduletag] = 1;
1345 global $conf, $langs, $user;
1350 if (isset($this->
statut)) {
1351 if ($this->
statut == $status) {
1354 } elseif (isset($this->status) && $this->status == $status) {
1361 $sql =
"UPDATE ".$this->db->prefix().
"user";
1362 $sql .=
" SET statut = ".((int) $status);
1363 $sql .=
" WHERE rowid = ".((int) $this->
id);
1364 $result = $this->db->query($sql);
1366 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1369 $this->context[
'actionmsg'] =
'User '.$this->login.
' disabled';
1371 $this->context[
'actionmsg'] =
'User '.$this->login.
' enabled';
1374 $result = $this->
call_trigger(
'USER_ENABLEDISABLE', $user);
1382 $this->db->rollback();
1385 $this->status = $status;
1387 $this->db->commit();
1404 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1405 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1416 global $conf, $langs;
1422 $this->
fetch($this->
id);
1424 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1427 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1429 if (!$error && !$this->db->query($sql)) {
1431 $this->
error = $this->db->lasterror();
1435 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1436 if (!$error && !$this->db->query($sql)) {
1438 $this->
error = $this->db->lasterror();
1442 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1443 if (!$error && !$this->db->query($sql)) {
1445 $this->
error = $this->db->lasterror();
1449 if ($this->contact_id > 0) {
1450 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1451 if (!$error && !$this->db->query($sql)) {
1453 $this->
error = $this->db->lasterror();
1462 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1468 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1469 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1470 if (!$this->db->query($sql)) {
1472 $this->
error = $this->db->lasterror();
1481 $this->db->rollback();
1486 $this->db->commit();
1489 $this->db->rollback();
1501 public function create($user, $notrigger = 0)
1503 global $conf, $langs;
1509 $this->civility_code = trim((
string) $this->civility_code);
1510 $this->login = trim((
string) $this->login);
1511 if (!isset($this->entity)) {
1512 $this->entity = $conf->entity;
1515 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1517 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1520 if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1521 $langs->load(
"errors");
1522 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1525 if (empty($this->login)) {
1526 $langs->load(
"errors");
1527 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1529 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1530 $langs->load(
"errors");
1531 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1542 $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).
"'";
1543 $resqltochecklogin = $this->db->query($sqltochecklogin);
1544 if ($resqltochecklogin) {
1545 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1546 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1547 $langs->load(
"errors");
1548 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1550 $this->db->rollback();
1553 $this->db->free($resqltochecklogin);
1556 if (!empty($this->email)) {
1557 $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).
"'";
1558 $resqltochecklogin = $this->db->query($sqltochecklogin);
1559 if ($resqltochecklogin) {
1560 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1561 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1562 $langs->load(
"errors");
1563 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
1565 $this->db->rollback();
1568 $this->db->free($resqltochecklogin);
1573 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, entity)";
1574 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->db->escape($this->login).
"', '".$this->db->escape($this->ldap_sid).
"', ".((int) $this->entity).
")";
1575 $result = $this->db->query($sql);
1577 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1579 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1583 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1584 $this->db->rollback();
1588 if (!empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER) && !empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) {
1589 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1590 $langs->load(
"stocks");
1591 $entrepot =
new Entrepot($this->db);
1592 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1593 $entrepot->libelle = $entrepot->label;
1594 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1595 $entrepot->statut = 1;
1596 $entrepot->country_id = $mysoc->country_id;
1597 $warehouseid = $entrepot->create($user);
1599 $this->fk_warehouse = $warehouseid;
1603 $result = $this->
update($user, 1, 1);
1605 $this->db->rollback();
1619 $this->db->commit();
1624 $this->db->rollback();
1628 $this->
error = $this->db->lasterror();
1629 $this->db->rollback();
1647 global $conf, $user, $langs;
1653 $this->civility_code = $contact->civility_code;
1654 $this->lastname = $contact->lastname;
1655 $this->firstname = $contact->firstname;
1657 $this->email = $contact->email;
1658 $this->socialnetworks = $contact->socialnetworks;
1659 $this->office_phone = $contact->phone_pro;
1660 $this->office_fax = $contact->fax;
1661 $this->user_mobile = $contact->phone_mobile;
1662 $this->address = $contact->address;
1663 $this->zip = $contact->zip;
1664 $this->town = $contact->town;
1666 $this->state_id = $contact->state_id;
1667 $this->country_id = $contact->country_id;
1668 $this->employee = 0;
1670 if (empty($login)) {
1671 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1672 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1674 $this->login = $login;
1679 $result = $this->
create($user, 1);
1681 $sql =
"UPDATE ".$this->db->prefix().
"user";
1682 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1683 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1684 if ($contact->socid > 0) {
1685 $sql .=
", fk_soc=".((int) $contact->socid);
1687 $sql .=
" WHERE rowid=".((int) $this->
id);
1689 $resql = $this->db->query($sql);
1691 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1693 $this->context[
'createfromcontact'] =
'createfromcontact';
1698 $error++; $this->db->rollback();
return -1;
1702 $this->db->commit();
1705 $this->
error = $this->db->error();
1707 $this->db->rollback();
1712 dol_syslog(get_class($this).
"::create_from_contact - 0");
1714 $this->db->rollback();
1731 global $conf, $user, $langs;
1735 $this->civility_code = $member->civility_id;
1736 $this->lastname = $member->lastname;
1737 $this->firstname = $member->firstname;
1738 $this->gender = $member->gender;
1739 $this->email = $member->email;
1740 $this->fk_member = $member->id;
1741 $this->address = $member->address;
1742 $this->zip = $member->zip;
1743 $this->town = $member->town;
1745 $this->state_id = $member->state_id;
1746 $this->country_id = $member->country_id;
1747 $this->socialnetworks = $member->socialnetworks;
1749 $this->pass = $member->pass;
1750 $this->pass_crypted = $member->pass_indatabase_crypted;
1752 if (empty($login)) {
1753 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1756 $this->login = $login;
1761 $result = $this->
create($user);
1763 if (!empty($this->pass)) {
1764 $newpass = $this->
setPassword($user, $this->pass);
1765 if (is_int($newpass) && $newpass < 0) {
1768 } elseif (!empty($this->pass_crypted)) {
1769 $sql =
"UPDATE ".$this->db->prefix().
"user";
1770 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
1771 $sql .=
" WHERE rowid=".((int) $this->
id);
1773 $resql = $this->db->query($sql);
1779 if ($result > 0 && $member->socid) {
1780 $sql =
"UPDATE ".$this->db->prefix().
"user";
1781 $sql .=
" SET fk_soc=".((int) $member->socid);
1782 $sql .=
" WHERE rowid=".((int) $this->
id);
1784 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
1785 $resql = $this->db->query($sql);
1787 $this->db->commit();
1790 $this->
error = $this->db->lasterror();
1792 $this->db->rollback();
1799 $this->db->commit();
1803 $this->db->rollback();
1821 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
1822 $sql .=
" WHERE bydefault = 1";
1823 $sql .=
" AND entity = ".((int) $conf->entity);
1825 $resql = $this->db->query($sql);
1827 $num = $this->db->num_rows($resql);
1830 $row = $this->db->fetch_row($resql);
1834 $this->db->free($resql);
1838 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
1839 $result = $this->db->query($sql);
1841 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
1842 $result = $this->db->query($sql);
1862 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
1864 global $conf, $langs;
1866 $nbrowsaffected = 0;
1869 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
1872 $this->civility_code = trim((
string) $this->civility_code);
1873 $this->lastname = trim((
string) $this->lastname);
1874 $this->firstname = trim((
string) $this->firstname);
1875 $this->ref_employee = trim((
string) $this->ref_employee);
1876 $this->national_registration_number = trim((
string) $this->national_registration_number);
1877 $this->employee = ($this->employee > 0 ? $this->employee : 0);
1878 $this->login = trim((
string) $this->login);
1879 $this->gender = trim((
string) $this->gender);
1881 $this->pass = trim((
string) $this->pass);
1882 $this->api_key = trim((
string) $this->api_key);
1883 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
1884 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
1886 $this->address = trim((
string) $this->address);
1887 $this->zip = trim((
string) $this->zip);
1888 $this->town = trim((
string) $this->town);
1890 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
1891 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
1892 $this->office_phone = trim((
string) $this->office_phone);
1893 $this->office_fax = trim((
string) $this->office_fax);
1894 $this->user_mobile = trim((
string) $this->user_mobile);
1895 $this->personal_mobile = trim((
string) $this->personal_mobile);
1896 $this->email = trim((
string) $this->email);
1897 $this->personal_email = trim((
string) $this->personal_email);
1899 $this->job = trim((
string) $this->job);
1900 $this->signature = trim((
string) $this->signature);
1901 $this->note_public = trim((
string) $this->note_public);
1902 $this->note_private = trim((
string) $this->note_private);
1903 $this->openid = trim((
string) $this->openid);
1904 $this->admin = ($this->admin > 0 ? $this->admin : 0);
1906 $this->accountancy_code = trim((
string) $this->accountancy_code);
1907 $this->color = trim((
string) $this->color);
1908 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
1909 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
1911 $this->birth = empty($this->birth) ?
'' : $this->birth;
1912 $this->fk_warehouse = (int) $this->fk_warehouse;
1917 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1919 if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1920 $langs->load(
"errors");
1921 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1924 if (empty($this->login)) {
1925 $langs->load(
"errors");
1926 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
1928 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1929 $langs->load(
"errors");
1930 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1937 if (!empty($this->oldcopy) && $this->oldcopy->login != $this->login) {
1938 $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).
"'";
1939 $resqltochecklogin = $this->db->query($sqltochecklogin);
1940 if ($resqltochecklogin) {
1941 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1942 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1943 $langs->load(
"errors");
1944 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1946 $this->db->rollback();
1951 if (!empty($this->oldcopy) && !empty($this->email) && $this->oldcopy->email != $this->email) {
1952 $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).
"'";
1953 $resqltochecklogin = $this->db->query($sqltochecklogin);
1954 if ($resqltochecklogin) {
1955 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1956 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1957 $langs->load(
"errors");
1958 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
1960 $this->db->rollback();
1967 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
1968 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
1969 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
1970 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
1971 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
1972 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
1973 $sql .=
", employee = ".(int) $this->employee;
1974 $sql .=
", login = '".$this->db->escape($this->login).
"'";
1975 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
1976 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
1977 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
1978 if (!empty($user->admin)) {
1979 $sql .=
", admin = ".(int) $this->admin;
1981 $sql .=
", address = '".$this->db->escape($this->address).
"'";
1982 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
1983 $sql .=
", town = '".$this->db->escape($this->town).
"'";
1984 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".$this->db->escape($this->state_id).
"'" :
"null");
1985 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".$this->db->escape($this->country_id).
"'" :
"null");
1986 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
1987 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
1988 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
1989 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
1990 $sql .=
", email = '".$this->db->escape($this->email).
"'";
1991 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
1992 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1993 $sql .=
", job = '".$this->db->escape($this->job).
"'";
1994 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
1995 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
1996 $sql .=
", color = '".$this->db->escape($this->color).
"'";
1997 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
1998 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
1999 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2000 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2001 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2002 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2003 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2004 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2005 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".$this->db->escape($this->fk_user).
"'" :
"null");
2006 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".$this->db->escape($this->fk_user_expense_validator).
"'" :
"null");
2007 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".$this->db->escape($this->fk_user_holiday_validator).
"'" :
"null");
2008 if (isset($this->thm) || $this->thm !=
'') {
2009 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2011 if (isset($this->tjm) || $this->tjm !=
'') {
2012 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2014 if (isset($this->salary) || $this->salary !=
'') {
2015 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2017 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2018 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2020 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2021 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2022 $sql .=
", entity = ".((int) $this->entity);
2024 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2025 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2026 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2027 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2028 $sql .=
" WHERE rowid = ".((int) $this->
id);
2030 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2031 $resql = $this->db->query($sql);
2033 $nbrowsaffected += $this->db->affected_rows($resql);
2036 if (!empty($this->pass)) {
2037 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2039 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2040 if (is_int($result) && $result < 0) {
2047 if ($this->fk_member > 0) {
2048 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2049 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2050 $resql = $this->db->query($sql);
2052 $this->
error = $this->db->error(); $this->db->rollback();
return -5;
2056 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2057 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2058 $resql = $this->db->query($sql);
2060 $this->
error = $this->db->error(); $this->db->rollback();
return -5;
2063 if ($nbrowsaffected) {
2064 if ($this->fk_member > 0 && !$nosyncmember) {
2065 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2067 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2072 $result = $adh->fetch($this->fk_member);
2075 $adh->civility_code = $this->civility_code;
2076 $adh->firstname = $this->firstname;
2077 $adh->lastname = $this->lastname;
2078 $adh->login = $this->login;
2079 $adh->gender = $this->gender;
2080 $adh->birth = $this->birth;
2082 $adh->pass = $this->pass;
2084 $adh->address = $this->address;
2085 $adh->town = $this->town;
2086 $adh->zip = $this->zip;
2087 $adh->state_id = $this->state_id;
2088 $adh->country_id = $this->country_id;
2090 $adh->email = $this->email;
2092 $adh->socialnetworks = $this->socialnetworks;
2094 $adh->phone = $this->office_phone;
2095 $adh->phone_mobile = $this->user_mobile;
2097 $adh->default_lang = $this->lang;
2099 $adh->user_id = $this->id;
2100 $adh->user_login = $this->login;
2102 $result = $adh->update($user, 0, 1, 0);
2104 $this->
error = $adh->error;
2105 $this->errors = $adh->errors;
2106 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2109 } elseif ($result < 0) {
2110 $this->
error = $adh->error;
2111 $this->errors = $adh->errors;
2116 if ($this->contact_id > 0 && !$nosynccontact) {
2117 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2119 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2122 $tmpobj =
new Contact($this->db);
2123 $result = $tmpobj->fetch($this->contact_id);
2126 $tmpobj->civility_code = $this->civility_code;
2127 $tmpobj->firstname = $this->firstname;
2128 $tmpobj->lastname = $this->lastname;
2129 $tmpobj->login = $this->login;
2130 $tmpobj->gender = $this->gender;
2131 $tmpobj->birth = $this->birth;
2135 $tmpobj->email = $this->email;
2137 $tmpobj->socialnetworks = $this->socialnetworks;
2139 $tmpobj->phone_pro = $this->office_phone;
2140 $tmpobj->phone_mobile = $this->user_mobile;
2141 $tmpobj->fax = $this->office_fax;
2143 $tmpobj->default_lang = $this->lang;
2145 $tmpobj->address = $this->address;
2146 $tmpobj->town = $this->town;
2147 $tmpobj->zip = $this->zip;
2148 $tmpobj->state_id = $this->state_id;
2149 $tmpobj->country_id = $this->country_id;
2151 $tmpobj->user_id = $this->id;
2152 $tmpobj->user_login = $this->login;
2154 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2156 $this->
error = $tmpobj->error;
2157 $this->errors = $tmpobj->errors;
2158 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2162 $this->
error = $tmpobj->error;
2163 $this->errors = $tmpobj->errors;
2179 if (!$error && !$notrigger) {
2189 $this->db->commit();
2190 return $nbrowsaffected;
2193 $this->db->rollback();
2197 $this->
error = $this->db->lasterror();
2198 $this->db->rollback();
2217 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2218 $sql .=
" datepreviouslogin = datelastlogin,";
2219 $sql .=
" ippreviouslogin = iplastlogin,";
2220 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2221 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2222 $sql .=
" tms = tms";
2223 $sql .=
" WHERE rowid = ".((int) $this->
id);
2225 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2226 $resql = $this->db->query($sql);
2228 $this->datepreviouslogin = $this->datelastlogin;
2229 $this->datelastlogin = $now;
2230 $this->ippreviouslogin = $this->iplastlogin;
2231 $this->iplastlogin = $userremoteip;
2234 $this->
error = $this->db->lasterror().
' sql='.$sql;
2252 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2254 global $conf, $langs;
2255 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2259 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2267 if (empty($passwordalreadycrypted)) {
2268 if (!empty($conf->global->USER_PASSWORD_GENERATED)) {
2270 $modGeneratePassClass =
'modGeneratePass'.ucfirst($conf->global->USER_PASSWORD_GENERATED);
2272 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2273 if (class_exists($modGeneratePassClass)) {
2274 $modGeneratePass =
new $modGeneratePassClass($this->db, $conf, $langs, $user);
2277 $modGeneratePass->WithoutAmbi = 0;
2280 $testpassword = $modGeneratePass->validatePassword($password);
2281 if (!$testpassword) {
2282 $this->
error = $modGeneratePass->error;
2290 $password_crypted =
dol_hash($password);
2294 if (!$changelater) {
2295 if (!is_object($this->oldcopy)) {
2296 $this->oldcopy = clone $this;
2301 $sql =
"UPDATE ".$this->db->prefix().
"user";
2302 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2303 $sql .=
" pass_temp = null";
2304 if (!empty($flagdelsessionsbefore)) {
2305 $sql .=
", flagdelsessionsbefore = '".$this->db->idate(
dol_now() - 5,
'gmt').
"'";
2307 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
2308 $sql .=
", pass = null";
2310 $sql .=
", pass = '".$this->db->escape($password).
"'";
2312 $sql .=
" WHERE rowid = ".((int) $this->
id);
2314 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2315 $result = $this->db->query($sql);
2317 if ($this->db->affected_rows($result)) {
2318 $this->pass = $password;
2319 $this->pass_indatabase = $password;
2320 $this->pass_indatabase_crypted = $password_crypted;
2322 if ($this->fk_member && !$nosyncmember) {
2323 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2328 $result = $adh->fetch($this->fk_member);
2331 $result = $adh->setPassword($user, $this->pass, (empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1), 1);
2332 if (is_int($result) && $result < 0) {
2333 $this->
error = $adh->error;
2338 $this->
error = $adh->error;
2343 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2345 if (!$error && !$notrigger) {
2347 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2349 $error++; $this->db->rollback();
return -1;
2354 $this->db->commit();
2357 $this->db->rollback();
2361 $this->db->rollback();
2368 $sql =
"UPDATE ".$this->db->prefix().
"user";
2369 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2370 $sql .=
" WHERE rowid = ".((int) $this->
id);
2372 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2373 $result = $this->db->query($sql);
2395 global $conf, $langs, $mysoc;
2396 global $dolibarr_main_url_root;
2398 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2405 $outputlangs =
new Translate(
"", $conf);
2407 if (isset($this->
conf->MAIN_LANG_DEFAULT)
2408 && $this->conf->MAIN_LANG_DEFAULT !=
'auto') {
2409 $outputlangs->getDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2412 if ($this->
conf->MAIN_LANG_DEFAULT) {
2413 $outputlangs->setDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2415 $outputlangs = $langs;
2419 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2421 $appli = constant(
'DOL_APPLICATION_TITLE');
2422 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
2423 $appli = $conf->global->MAIN_APPLICATION_TITLE;
2426 $subject =
'['.$mysoc->name.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2429 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2430 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2432 if (!$changelater) {
2433 $url = $urlwithroot.
'/';
2434 if (!empty($conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD)) {
2435 $url = $conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD;
2438 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2440 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2441 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2442 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2443 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2446 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2448 $mesg .= $user->getFullName($outputlangs);
2451 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2452 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.$conf->file->instance_unique_id));
2453 if (isModEnabled(
'multicompany')) {
2454 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2457 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2461 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2462 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2463 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2464 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2466 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2467 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2468 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2471 $trackid =
'use'.$this->id;
2472 $sendcontext =
'password';
2477 $conf->global->MAIN_MAIL_EMAIL_FROM,
2493 if ($mailfile->sendfile()) {
2496 $langs->trans(
"errors");
2497 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2509 return $this->error;
2522 $sql =
"SELECT url, login, pass, poste ";
2523 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2524 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2526 $resql = $this->db->query($sql);
2528 if ($this->db->num_rows($resql)) {
2529 $obj = $this->db->fetch_object($resql);
2531 $this->clicktodial_url = $obj->url;
2532 $this->clicktodial_login = $obj->login;
2533 $this->clicktodial_password = $obj->pass;
2534 $this->clicktodial_poste = $obj->poste;
2537 $this->clicktodial_loaded = 1;
2539 $this->db->free($resql);
2542 $this->
error = $this->db->error();
2558 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2559 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2561 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2562 $result = $this->db->query($sql);
2564 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2565 $sql .=
" (fk_user,url,login,pass,poste)";
2566 $sql .=
" VALUES (".$this->id;
2567 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2568 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2569 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2570 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2572 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2573 $result = $this->db->query($sql);
2575 $this->db->commit();
2578 $this->db->rollback();
2579 $this->
error = $this->db->lasterror();
2597 global $conf, $langs, $user;
2603 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2604 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2605 $sql .=
" AND fk_usergroup = ".((int) $group);
2606 $sql .=
" AND entity = ".((int) $entity);
2608 $result = $this->db->query($sql);
2610 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2611 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2613 $result = $this->db->query($sql);
2615 if (!$error && !$notrigger) {
2616 $this->newgroupid = $group;
2617 $this->context = array(
'audit'=>$langs->trans(
"UserSetInGroup"),
'newgroupid'=>$group);
2628 $this->db->commit();
2632 $this->db->rollback();
2636 $this->
error = $this->db->lasterror();
2637 $this->db->rollback();
2654 global $conf, $langs, $user;
2660 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2661 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2662 $sql .=
" AND fk_usergroup = ".((int) $group);
2663 if (empty($entity)) {
2664 $sql .=
" AND entity IN (0, 1)";
2666 $sql .=
" AND entity = ".((int) $entity);
2669 $result = $this->db->query($sql);
2671 if (!$error && !$notrigger) {
2672 $this->oldgroupid = $group;
2673 $this->context = array(
'audit'=>$langs->trans(
"UserRemovedFromGroup"),
'oldgroupid'=>$group);
2684 $this->db->commit();
2687 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2688 $this->db->rollback();
2692 $this->
error = $this->db->lasterror();
2693 $this->db->rollback();
2707 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
2714 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
2736 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
2738 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2739 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
2754 global $conf, $langs, $menumanager;
2756 $infologin = $params[
'infologin'] ?? 0;
2757 $option = $params[
'option'] ??
'';
2760 if (!empty($this->photo)) {
2761 $photo =
'<div class="photointooltip floatright">';
2762 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
2764 $datas[
'photo'] = $photo;
2769 $datas[
'opendiv'] =
'<div class="centpercent">';
2770 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
2772 if (!empty($this->login)) {
2773 $datas[
'login'] =
'<br><b>'.$langs->trans(
'Login').
':</b> '.
dol_string_nohtmltag($this->login);
2775 if (!empty($this->job)) {
2778 $datas[
'email'] =
'<br><b>'.$langs->trans(
"Email").
':</b> '.
dol_string_nohtmltag($this->email);
2779 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
2780 $phonelist = array();
2781 if ($this->office_phone) {
2782 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2784 if ($this->office_fax) {
2785 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2787 if ($this->user_mobile) {
2788 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
2790 $datas[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
2792 if (!empty($this->admin)) {
2793 $datas[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
2795 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
2796 $datas[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
2799 if (!empty($this->socid)) {
2800 $thirdpartystatic =
new Societe($this->db);
2801 $thirdpartystatic->fetch($this->socid);
2802 if (empty($hidethirdpartylogo)) {
2803 $companylink =
' '.$thirdpartystatic->getNomUrl(2, (($option ==
'nolink') ?
'nolink' :
''));
2807 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
2808 $datas[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
2809 $datas[
'closediv'] =
'</div>';
2811 if ($infologin > 0) {
2812 $datas[
'newlinelogin'] =
'<br>';
2813 $datas[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
2815 if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) {
2816 $datas[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.$conf->entity.
' (User entity '.$this->entity.
')';
2818 $datas[
'authentication'] =
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
2819 $datas[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
2820 $datas[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
2821 $datas[
'currenttheme'] =
'<br><b>'.$langs->trans(
"CurrentTheme").
':</b> '.
dol_string_nohtmltag($conf->theme);
2822 $datas[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
2824 $datas[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
2825 $datas[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag($conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
2826 $datas[
'layout'] =
'<br><b>'.$langs->trans(
"Layout").
':</b> '.
dol_string_nohtmltag($conf->browser->layout);
2827 $datas[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
2828 if ($conf->browser->layout ==
'phone') {
2829 $datas[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
2831 if (!empty($_SESSION[
"disablemodules"])) {
2832 $datas[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(join(
', ', explode(
',', $_SESSION[
"disablemodules"])));
2854 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
2856 global $langs, $conf, $db, $hookmanager, $user;
2857 global $dolibarr_main_authentication, $dolibarr_main_demo;
2858 global $menumanager;
2860 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
2864 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) {
2871 'objecttype' => $this->element,
2872 'infologin' => $infologin,
2873 'option' => $option,
2875 $classfortooltip =
'classfortooltip';
2878 $classfortooltip =
'classforajaxtooltip';
2879 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
2886 if (!empty($this->socid)) {
2887 $thirdpartystatic =
new Societe($this->db);
2888 $thirdpartystatic->fetch($this->socid);
2889 if (empty($hidethirdpartylogo)) {
2890 $companylink =
' '.$thirdpartystatic->getNomUrl(2, (($option ==
'nolink') ?
'nolink' :
''));
2894 if ($infologin < 0) {
2898 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
2899 if ($option ==
'leave') {
2900 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
2903 if ($option !=
'nolink') {
2905 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2906 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2907 $add_save_lastsearch_values = 1;
2909 if ($add_save_lastsearch_values) {
2910 $url .=
'&save_lastsearch_values=1';
2914 $linkstart =
'<a href="'.$url.
'"';
2916 if (empty($notooltip)) {
2917 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2918 $langs->load(
"users");
2919 $label = $langs->trans(
"ShowUser");
2920 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2922 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
2923 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
2925 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
2928 $linkstart .= $linkclose.
'>';
2932 $result .= (($option ==
'nolink') ?
'' : $linkstart);
2933 if ($withpictoimg) {
2934 $paddafterimage =
'';
2935 if (abs((
int) $withpictoimg) == 1) {
2936 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
2939 if ($withpictoimg > 0) {
2940 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' class="paddingright")', 0, 0, $notooltip ? 0 : 1).
'</span>';
2943 $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>';
2947 if ($withpictoimg > -2 && $withpictoimg != 2) {
2948 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2949 $result .=
'<span class="nopadding usertext'.((!isset($this->
statut) || $this->statut) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
2951 if ($mode ==
'login') {
2956 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2957 $result .=
'</span>';
2960 $result .= (($option ==
'nolink') ?
'' : $linkend);
2963 $result .= $companylink;
2966 $hookmanager->initHooks(array(
'userdao'));
2967 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
2968 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2970 $result = $hookmanager->resPrint;
2972 $result .= $hookmanager->resPrint;
2987 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
2989 global $langs, $user;
2993 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2997 if ((!$user->rights->user->user->lire && $this->id != $user->id)) {
3001 if ($option ==
'xxx') {
3002 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3006 if ($option ==
'nolink') {
3011 $result .= $linkstart;
3012 if ($withpictoimg) {
3013 $paddafterimage =
'';
3014 if (abs($withpictoimg) == 1) {
3015 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3018 if ($withpictoimg > 0) {
3019 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3022 $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>';
3026 $result .= $this->login;
3027 $result .= $linkend;
3056 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3059 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3060 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3061 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3062 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3065 $statusType =
'status5';
3066 if ($status == self::STATUS_ENABLED) {
3067 $statusType =
'status4';
3070 $label = $this->labelStatus[$status];
3071 $labelshort = $this->labelStatusShort[$status];
3074 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3075 $statusType =
'status3';
3076 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3078 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3079 $statusType =
'status2';
3080 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3083 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3098 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3100 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3101 $return .=
'<div class="info-box info-box-sm">';
3102 $return .=
'<span class="info-box-icon bg-infobox-action">';
3105 if (!empty($this->photo)) {
3107 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3116 $return .=
'</span>';
3117 $return .=
'<div class="info-box-content">';
3118 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3119 if (isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3120 $return .=
img_picto($langs->trans(
"SuperAdministrator"),
'redstar',
'class="valignmiddle paddingright paddingleft"');
3121 } elseif ($this->admin) {
3122 $return .=
img_picto($langs->trans(
"Administrator"),
'star',
'class="valignmiddle paddingright paddingleft"');
3124 $return .=
'</span>';
3125 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3126 if (property_exists($this,
'label')) {
3127 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3130 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->email.
'</span>';
3132 if (method_exists($this,
'getLibStatut')) {
3133 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
3135 $return .=
'</div>';
3136 $return .=
'</div>';
3137 $return .=
'</div>';
3160 $dn = $conf->global->LDAP_KEY_USERS.
"=".$info[$conf->global->LDAP_KEY_USERS].
",".$conf->global->LDAP_USER_DN;
3161 } elseif ($mode == 1) {
3162 $dn = $conf->global->LDAP_USER_DN;
3163 } elseif ($mode == 2) {
3164 $dn = $conf->global->LDAP_KEY_USERS.
"=".$info[$conf->global->LDAP_KEY_USERS];
3179 global $conf, $langs;
3185 $keymodified =
false;
3188 $info[
"objectclass"] = explode(
',', $conf->global->LDAP_USER_OBJECT_CLASS);
3194 'LDAP_FIELD_FULLNAME' =>
'fullname',
3195 'LDAP_FIELD_NAME' =>
'lastname',
3196 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3197 'LDAP_FIELD_LOGIN' =>
'login',
3198 'LDAP_FIELD_LOGIN_SAMBA'=>
'login',
3199 'LDAP_FIELD_PHONE' =>
'office_phone',
3200 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3201 'LDAP_FIELD_FAX' =>
'office_fax',
3202 'LDAP_FIELD_MAIL' =>
'email',
3203 'LDAP_FIELD_SID' =>
'ldap_sid',
3207 foreach ($ldapkey as $constname => $varname) {
3208 if (!empty($this->$varname) && !empty($conf->global->$constname)) {
3209 $info[$conf->global->$constname] = $this->$varname;
3212 if (!empty($conf->global->LDAP_KEY_USERS) && $conf->global->LDAP_KEY_USERS == $conf->global->$constname) {
3213 if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
3214 $keymodified =
true;
3219 foreach ($socialnetworks as $key => $value) {
3220 if (!empty($this->socialnetworks[$value[
'label']]) && !empty($conf->global->{
'LDAP_FIELD_'.strtoupper($value[
'label'])})) {
3221 $info[$conf->global->{
'LDAP_FIELD_'.strtoupper($value[
'label'])}] = $this->socialnetworks[$value[
'label']];
3224 if ($this->address && !empty($conf->global->LDAP_FIELD_ADDRESS)) {
3225 $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->address;
3227 if ($this->zip && !empty($conf->global->LDAP_FIELD_ZIP)) {
3228 $info[$conf->global->LDAP_FIELD_ZIP] = $this->zip;
3230 if ($this->town && !empty($conf->global->LDAP_FIELD_TOWN)) {
3231 $info[$conf->global->LDAP_FIELD_TOWN] = $this->town;
3233 if ($this->note_public && !empty($conf->global->LDAP_FIELD_DESCRIPTION)) {
3236 if ($this->socid > 0) {
3237 $soc =
new Societe($this->db);
3238 $soc->fetch($this->socid);
3240 $info[$conf->global->LDAP_FIELD_COMPANY] = $soc->name;
3241 if ($soc->client == 1) {
3242 $info[
"businessCategory"] =
"Customers";
3244 if ($soc->client == 2) {
3245 $info[
"businessCategory"] =
"Prospects";
3247 if ($soc->fournisseur == 1) {
3248 $info[
"businessCategory"] =
"Suppliers";
3253 if (!empty($this->pass)) {
3254 if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
3255 $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass;
3257 if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3258 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass,
'openldap');
3260 } elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !==
'3') {
3263 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
3265 if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) {
3266 if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3267 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dolGetLdapPasswordHash($this->pass_indatabase_crypted,
'md5frommd5');
3270 } elseif (!empty($this->pass_indatabase)) {
3272 if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
3273 $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass_indatabase;
3275 if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3276 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass_indatabase,
'openldap');
3281 if ($conf->global->LDAP_SERVER_TYPE ==
'egroupware') {
3282 $info[
"objectclass"][4] =
"phpgwContact";
3284 $info[
'uidnumber'] = $this->id;
3286 $info[
'phpgwTz'] = 0;
3287 $info[
'phpgwMailType'] =
'INTERNET';
3288 $info[
'phpgwMailHomeType'] =
'INTERNET';
3290 $info[
"phpgwContactTypeId"] =
'n';
3291 $info[
"phpgwContactCatId"] = 0;
3292 $info[
"phpgwContactAccess"] =
"public";
3295 $this->egroupware_id = 1;
3298 $info[
"phpgwContactOwner"] = $this->egroupware_id;
3301 $info[
"rfc822Mailbox"] = $this->email;
3303 if ($this->phone_mobile) {
3304 $info[
"phpgwCellTelephoneNumber"] = $this->phone_mobile;
3308 if (!empty($conf->global->LDAP_FIELD_USERID)) {
3309 $info[$conf->global->LDAP_FIELD_USERID] = $this->id;
3311 if (!empty($conf->global->LDAP_FIELD_GROUPID)) {
3313 $groupslist = $usergroup->listGroupsForUser($this->
id);
3314 $info[$conf->global->LDAP_FIELD_GROUPID] =
'65534';
3315 if (!empty($groupslist)) {
3316 foreach ($groupslist as $groupforuser) {
3317 $info[$conf->global->LDAP_FIELD_GROUPID] = $groupforuser->id;
3322 if (!empty($conf->global->LDAP_FIELD_HOMEDIRECTORY) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX)) {
3323 $info[$conf->global->LDAP_FIELD_HOMEDIRECTORY] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->login";
3339 global $user, $langs;
3345 $this->
ref =
'SPECIMEN';
3346 $this->specimen = 1;
3348 $this->lastname =
'DOLIBARR';
3349 $this->firstname =
'SPECIMEN';
3350 $this->gender =
'man';
3351 $this->note_public =
'This is a note public';
3352 $this->note_private =
'This is a note private';
3353 $this->email =
'email@specimen.com';
3354 $this->personal_email =
'personalemail@specimen.com';
3355 $this->socialnetworks = array(
3356 'skype' =>
'skypepseudo',
3357 'twitter' =>
'twitterpseudo',
3358 'facebook' =>
'facebookpseudo',
3359 'linkedin' =>
'linkedinpseudo',
3361 $this->office_phone =
'0999999999';
3362 $this->office_fax =
'0999999998';
3363 $this->user_mobile =
'0999999997';
3364 $this->personal_mobile =
'0999999996';
3366 $this->login =
'dolibspec';
3367 $this->pass =
'dolibSpec+@123';
3370 $this->datec = $now;
3371 $this->datem = $now;
3373 $this->datelastlogin = $now;
3374 $this->iplastlogin =
'127.0.0.1';
3375 $this->datepreviouslogin = $now;
3376 $this->ippreviouslogin =
'127.0.0.1';
3392 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
3393 $sql .=
" u.tms as date_modification, u.entity";
3394 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3395 $sql .=
" WHERE u.rowid = ".((int) $id);
3397 $result = $this->db->query($sql);
3399 if ($this->db->num_rows($result)) {
3400 $obj = $this->db->fetch_object($result);
3402 $this->
id = $obj->rowid;
3404 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3405 $this->date_creation = $this->db->jdate($obj->datec);
3406 $this->date_modification = $this->db->jdate($obj->date_modification);
3407 $this->entity = $obj->entity;
3410 $this->db->free($result);
3424 $sql =
"SELECT count(mc.email) as nb";
3425 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3426 $sql .=
" WHERE mc.email = '".$this->db->escape($this->email).
"'";
3427 $sql .=
" AND mc.statut NOT IN (-1,0)";
3429 $resql = $this->db->query($sql);
3431 $obj = $this->db->fetch_object($resql);
3434 $this->db->free($resql);
3437 $this->error = $this->db->error();
3454 $sql =
"SELECT count(rowid) as nb";
3455 $sql .=
" FROM ".$this->db->prefix().
"user";
3456 if ($option ==
'superadmin') {
3457 $sql .=
" WHERE entity = 0";
3459 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3460 if ($limitTo ==
'active') {
3461 $sql .=
" AND statut = 1";
3465 $sql .=
" AND admin = ".(int) $admin;
3468 $resql = $this->db->query($sql);
3470 $obj = $this->db->fetch_object($resql);
3471 $nb = (int) $obj->nb;
3473 $this->db->free($resql);
3476 $this->error = $this->db->lasterror();
3492 global $user, $conf;
3497 $this->firstname = $ldapuser->$tmpvar;
3499 $this->lastname = $ldapuser->$tmpvar;
3501 $this->login = $ldapuser->$tmpvar;
3503 $this->pass = $ldapuser->$tmpvar;
3505 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3508 $this->office_phone = $ldapuser->$tmpvar;
3510 $this->user_mobile = $ldapuser->$tmpvar;
3512 $this->office_fax = $ldapuser->$tmpvar;
3514 $this->email = $ldapuser->$tmpvar;
3515 foreach ($socialnetworks as $key => $value) {
3517 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3520 $this->ldap_sid = $ldapuser->$tmpvar;
3523 $this->job = $ldapuser->$tmpvar;
3525 $this->note_public = $ldapuser->$tmpvar;
3527 $result = $this->update($user);
3529 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3545 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3546 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3548 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3549 $res = $this->db->query($sql);
3552 while ($rec = $this->db->fetch_array($res)) {
3553 $user =
new User($this->db);
3554 $user->fetch($rec[
'rowid']);
3574 $this->parentof = array();
3577 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3578 $sql .=
" FROM ".$this->db->prefix().
"user";
3579 $sql .=
" WHERE fk_user <> 0";
3580 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3582 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3583 $resql = $this->db->query($sql);
3585 while ($obj = $this->db->fetch_object($resql)) {
3586 $this->parentof[$obj->id_son] = $obj->id_parent;
3612 global $conf, $user;
3613 global $hookmanager;
3616 $hookmanager->initHooks(array(
'userdao'));
3618 $this->users = array();
3621 $this->loadParentOf();
3624 $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";
3625 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3627 $parameters = array();
3628 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3630 $sql .= $hookmanager->resPrint;
3632 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3635 $sql .=
" AND ".$filter;
3638 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3639 $resql = $this->db->query($sql);
3642 while ($obj = $this->db->fetch_object($resql)) {
3643 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3644 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3645 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3646 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3647 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3648 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3649 $this->users[$obj->rowid][
'login'] = $obj->login;
3650 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3651 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3652 $this->users[$obj->rowid][
'email'] = $obj->email;
3653 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3654 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3655 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3664 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3665 foreach ($this->users as $key => $val) {
3666 $result = $this->build_path_from_id_user($key, 0);
3668 $this->error =
'ErrorLoopInHierarchy';
3674 if ($deleteafterid) {
3676 $keyfilter1 =
'^'.$deleteafterid.
'$';
3677 $keyfilter2 =
'_'.$deleteafterid.
'$';
3678 $keyfilter3 =
'^'.$deleteafterid.
'_';
3679 $keyfilter4 =
'_'.$deleteafterid.
'_';
3680 foreach ($this->users as $key => $val) {
3681 if (preg_match(
'/'.$keyfilter1.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter2.
'/', $val[
'fullpath'])
3682 || preg_match(
'/'.$keyfilter3.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter4.
'/', $val[
'fullpath'])) {
3683 unset($this->users[$key]);
3688 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
3689 $this->users =
dol_sort_array($this->users,
'fullname',
'asc',
true,
false, 1);
3693 return $this->users;
3706 $childids = array();
3708 if (isset($this->cache_childids[$this->
id])) {
3709 $childids = $this->cache_childids[$this->id];
3712 $this->get_full_tree();
3714 $idtoscan = $this->id;
3716 dol_syslog(
"Build childid for id = ".$idtoscan);
3717 foreach ($this->users as $id => $val) {
3719 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
3720 $childids[$val[
'id']] = $val[
'id'];
3724 $this->cache_childids[$this->id] = $childids;
3726 if ($addcurrentuser) {
3727 $childids[$this->id] = $this->id;
3747 if (!empty($this->users[$id_user][
'fullpath'])) {
3749 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
3754 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
3755 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
3756 $i = 0; $cursor_user = $id_user;
3758 $useridfound = array($id_user);
3759 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
3760 if (in_array($this->parentof[$cursor_user], $useridfound)) {
3761 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
3764 $useridfound[] = $this->parentof[$cursor_user];
3765 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
3766 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
3767 $i++; $cursor_user = $this->parentof[$cursor_user];
3771 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
3805 $this->nb = array();
3807 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
3808 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3809 if (isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
3810 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
3811 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
3812 $sql .=
" AND ug.fk_user = u.rowid";
3814 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3816 $sql .=
" AND u.statut > 0";
3819 $resql = $this->db->query($sql);
3821 while ($obj = $this->db->fetch_object($resql)) {
3822 $this->nb[
"users"] = $obj->nb;
3824 $this->db->free($resql);
3828 $this->error = $this->db->error();
3844 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3846 global $conf, $user, $langs;
3848 $langs->load(
"user");
3852 if (!empty($conf->global->USER_ADDON_PDF)) {
3853 $modele = $conf->global->USER_ADDON_PDF;
3855 $modele =
'bluesky';
3859 $modelpath =
"core/modules/user/doc/";
3861 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3875 $user_property =
'';
3877 if (empty($rowid)) {
3881 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
3882 $sql .=
" FROM ".$this->db->prefix().
"user";
3883 $sql .=
" WHERE rowid = ".((int) $rowid);
3885 $resql = $this->db->query($sql);
3887 $nump = $this->db->num_rows($resql);
3890 $obj = $this->db->fetch_object($resql);
3892 if ($mode ==
'email') {
3893 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
3894 } elseif ($mode ==
'mobile') {
3895 $user_property = $obj->user_mobile;
3898 return $user_property;
3915 global $dolibarr_main_url_root;
3918 $encodedsecurekey =
dol_hash($conf->file->instance_unique_id.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
3919 if (isModEnabled(
'multicompany')) {
3920 $entity_qr =
'&entity='.((int) $conf->entity);
3925 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
3926 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
3929 if ($typeofurl ==
'internal') {
3930 $urlwithroot = DOL_URL_ROOT;
3933 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
3948 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter = array(), $filtermode =
'AND', $entityfilter =
false)
3950 global $conf, $user;
3952 $sql =
"SELECT t.rowid";
3953 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
3955 if ($entityfilter) {
3956 if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
3957 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
3958 $sql .=
" WHERE t.entity IS NOT NULL";
3960 $sql .=
",".$this->db->prefix().
"usergroup_user as ug";
3961 $sql .=
" WHERE ((ug.fk_user = t.rowid";
3962 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
3963 $sql .=
" OR t.entity = 0)";
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.
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.