41require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/class/commonpeople.class.php';
57 public $element =
'user';
62 public $table_element =
'user';
67 public $fk_element =
'fk_user';
72 public $picto =
'user';
111 public $civility_code;
136 public $email_oauth2;
141 public $personal_email;
146 public $socialnetworks;
161 public $office_phone;
176 public $personal_mobile;
201 public $pass_crypted;
206 public $pass_indatabase;
211 public $pass_indatabase_crypted;
221 public $force_pass_change = 0;
260 public $fk_user_expense_validator;
265 public $fk_user_holiday_validator;
270 public $clicktodial_url;
275 public $clicktodial_login;
280 public $clicktodial_password;
285 public $clicktodial_poste;
290 public $clicktodial_loaded;
296 public $datelastpassvalidation;
300 public $datelastlogin;
304 public $datepreviouslogin;
308 public $flagdelsessionsbefore;
316 public $ippreviouslogin;
320 public $datestartvalidity;
324 public $dateendvalidity;
344 public $all_permissions_are_loaded;
354 public $user_group_list;
359 private $_tab_loaded = array();
369 public $default_values;
374 public $lastsearch_values_tmp;
378 public $lastsearch_values;
383 public $users = array();
391 private $cache_childids;
397 public $accountancy_code_user_general;
402 public $accountancy_code;
434 public $dateemployment;
438 public $dateemploymentend;
443 public $default_c_exp_tax_cat;
448 public $ref_employee;
453 public $national_registration_number;
458 public $default_range;
464 public $fk_warehouse;
469 public $fk_establishment;
474 public $label_establishment;
480 public $usergroup_entity;
482 public $fields = array(
483 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
484 'lastname' => array(
'type' =>
'varchar(50)',
'label' =>
'Lastname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 20,
'searchall' => 1),
485 'firstname' => array(
'type' =>
'varchar(50)',
'label' =>
'Firstname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 10,
'searchall' => 1),
486 'fk_warehouse' => array(
'type' =>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label' =>
'Warehouse',
'enabled' =>
"isModEnabled('stock')",
'visible' => 1,
'notnull' => 0,
'showoncombobox' => 1,
'index' => 1,
'position' => 50,
'searchall' => 1),
487 'ref_employee' => array(
'type' =>
'varchar(50)',
'label' =>
'RefEmployee',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 30,
'searchall' => 1),
488 'national_registration_number' => array(
'type' =>
'varchar(50)',
'label' =>
'NationalRegistrationNumber',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 40,
'searchall' => 1)
491 const STATUS_DISABLED = 0;
492 const STATUS_ENABLED = 1;
503 $this->ismultientitymanaged = 1;
504 $this->isextrafieldmanaged = 1;
506 $this->clicktodial_loaded = 0;
509 $this->all_permissions_are_loaded = 0;
510 $this->nb_rights = 0;
518 $this->rights->user =
new stdClass();
519 $this->rights->user->user =
new stdClass();
520 $this->rights->user->self =
new stdClass();
521 $this->rights->user->user_advance =
new stdClass();
522 $this->rights->user->self_advance =
new stdClass();
523 $this->rights->user->group_advance =
new stdClass();
540 public function fetch($id = 0, $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'', $fk_socpeople = 0, $use_email_oauth2 = 0)
545 $login = trim($login);
548 $sql =
"SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.civility as civility_code, u.birth, u.job,";
549 $sql .=
" u.email, u.email_oauth2, u.personal_email,";
550 $sql .=
" u.socialnetworks,";
551 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
552 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
553 $sql .=
" u.admin, u.login, u.note_private, u.note_public,";
554 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.force_pass_change, u.api_key,";
555 $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,";
556 $sql .=
" fk_user_creat as user_creation_id, fk_user_modif as user_modification_id,";
557 $sql .=
" u.statut as status, u.lang, u.entity,";
558 $sql .=
" u.datec as datec,";
559 $sql .=
" GREATEST(u.tms, uef.tms) as datem,";
560 $sql .=
" u.datelastlogin as datel,";
561 $sql .=
" u.datepreviouslogin as datep,";
562 $sql .=
" u.flagdelsessionsbefore,";
563 $sql .=
" u.iplastlogin,";
564 $sql .=
" u.ippreviouslogin,";
565 $sql .=
" u.datelastpassvalidation,";
566 $sql .=
" u.datestartvalidity,";
567 $sql .=
" u.dateendvalidity,";
568 $sql .=
" u.photo as photo,";
569 $sql .=
" u.openid as openid,";
570 $sql .=
" u.accountancy_code_user_general,";
571 $sql .=
" u.accountancy_code,";
574 $sql .=
" u.salary,";
575 $sql .=
" u.salaryextra,";
576 $sql .=
" u.weeklyhours,";
578 $sql .=
" u.dateemployment, u.dateemploymentend,";
579 $sql .=
" u.fk_warehouse,";
580 $sql .=
" u.ref_ext,";
581 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
582 $sql .=
" u.national_registration_number,";
583 $sql .=
" u.ref_employee,";
584 $sql .=
" c.code as country_code, c.label as country,";
585 $sql .=
" d.code_departement as state_code, d.nom as state,";
586 $sql .=
" s.label as label_establishment, u.fk_establishment";
587 $sql .=
" FROM ".$this->db->prefix().
"user as u";
588 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user_extrafields as uef ON uef.fk_object = u.rowid";
589 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as c ON u.fk_country = c.rowid";
590 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_departements as d ON u.fk_state = d.rowid";
591 $sql .=
" LEFT JOIN ".$this->db->prefix().
"establishment as s ON u.fk_establishment = s.rowid";
594 $sql .=
" WHERE u.rowid = ".((int) $id);
598 $sql .=
" WHERE u.entity IN (0, " . ((int)
$conf->entity) .
")";
600 $sql .=
" WHERE u.entity IS NOT NULL";
605 $sql .=
" WHERE u.entity IS NOT NULL";
607 if ($entity !=
'' && $entity == 0) {
608 $sql .=
" WHERE u.entity = 0";
610 $sql .=
" WHERE u.entity IN (0, " . ((int) ($entity > 0 ? ((
int) $entity) : ((int)
$conf->entity))) .
")";
618 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->db->escape($login).
"')";
620 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
622 $sql .=
" AND (u.email = '".$this->db->escape($email).
"'";
623 if ($use_email_oauth2) {
624 $sql .=
" OR u.email_oauth2 = '".$this->db->escape($email).
"'";
627 } elseif ($fk_socpeople > 0) {
628 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
631 $sql .=
" ORDER BY u.entity ASC";
635 $sql .=
' '.$this->db->plimit(1);
638 $resql = $this->db->query($sql);
640 $num = $this->db->num_rows($resql);
642 $this->
error =
"USERDUPLICATEFOUND";
643 dol_syslog(get_class($this).
"::fetch more than 1 user found", LOG_WARNING);
645 $this->db->free($resql);
649 $obj = $this->db->fetch_object($resql);
651 $this->
id = $obj->rowid;
652 $this->
ref = $obj->rowid;
654 $this->ref_ext = $obj->ref_ext;
656 $this->ldap_sid = $obj->ldap_sid;
657 $this->civility_code = $obj->civility_code;
658 $this->lastname = $obj->lastname;
659 $this->firstname = $obj->firstname;
660 $this->ref_employee = $obj->ref_employee;
661 $this->national_registration_number = $obj->national_registration_number;
663 $this->employee = $obj->employee;
665 $this->login = $obj->login;
666 $this->gender = $obj->gender;
667 $this->birth = $this->db->jdate($obj->birth);
668 $this->pass_indatabase = $obj->pass;
669 $this->pass_indatabase_crypted = $obj->pass_crypted;
670 $this->pass = $obj->pass;
671 $this->pass_temp = $obj->pass_temp;
673 $this->force_pass_change = $obj->force_pass_change;
674 $this->datelastpassvalidation = $this->db->jdate($obj->datelastpassvalidation);
678 $this->
address = $obj->address;
679 $this->zip = $obj->zip;
680 $this->town = $obj->town;
682 $this->country_id = $obj->country_id;
683 $this->country_code = $obj->country_id ? $obj->country_code :
'';
686 $this->state_id = $obj->state_id;
687 $this->state_code = $obj->state_code;
688 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
690 $this->office_phone = $obj->office_phone;
691 $this->office_fax = $obj->office_fax;
692 $this->user_mobile = $obj->user_mobile;
693 $this->personal_mobile = $obj->personal_mobile;
694 $this->
email = $obj->email;
695 $this->email_oauth2 = $obj->email_oauth2;
696 $this->personal_email = $obj->personal_email;
697 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
698 $this->user_creation_id = $obj->user_creation_id;
699 $this->user_modification_id = $obj->user_modification_id;
701 $this->job = $obj->job;
702 $this->signature = $obj->signature;
703 $this->admin = $obj->admin;
704 $this->note_public = $obj->note_public;
705 $this->note_private = $obj->note_private;
707 $this->statut = $obj->status;
708 $this->
status = $obj->status;
710 $this->photo = $obj->photo;
711 $this->openid = $obj->openid;
712 $this->lang = $obj->lang;
713 $this->entity = $obj->entity;
715 $this->accountancy_code_user_general = $obj->accountancy_code_user_general;
716 $this->accountancy_code = $obj->accountancy_code;
718 $this->thm = $obj->thm;
719 $this->tjm = $obj->tjm;
720 $this->salary = $obj->salary;
721 $this->salaryextra = $obj->salaryextra;
722 $this->weeklyhours = $obj->weeklyhours;
723 $this->color = $obj->color;
724 $this->dateemployment = $this->db->jdate($obj->dateemployment);
725 $this->dateemploymentend = $this->db->jdate($obj->dateemploymentend);
727 $this->datec = $this->db->jdate($obj->datec);
728 $this->datem = $this->db->jdate($obj->datem);
729 $this->datelastlogin = $this->db->jdate($obj->datel);
730 $this->datepreviouslogin = $this->db->jdate($obj->datep);
731 $this->flagdelsessionsbefore = $this->db->jdate($obj->flagdelsessionsbefore,
'gmt');
732 $this->iplastlogin = $obj->iplastlogin;
733 $this->ippreviouslogin = $obj->ippreviouslogin;
734 $this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
735 $this->dateendvalidity = $this->db->jdate($obj->dateendvalidity);
737 $this->socid = $obj->fk_soc;
738 $this->contact_id = $obj->fk_socpeople;
739 $this->fk_member = $obj->fk_member;
740 $this->fk_user = $obj->fk_user;
741 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
742 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
744 $this->default_range = $obj->default_range;
745 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
746 $this->fk_warehouse = $obj->fk_warehouse;
747 $this->warehouse_id = $obj->fk_warehouse;
748 $this->warehouse =
null;
749 $this->fk_establishment = $obj->fk_establishment;
750 $this->label_establishment = $obj->label_establishment;
754 if (!
isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
766 $this->db->free($resql);
768 $this->
error =
"USERNOTFOUND";
769 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
771 $this->db->free($resql);
775 $this->
error = $this->db->lasterror();
780 if ($loadpersonalconf) {
786 $this->
error = $this->db->lasterror();
793 if (
GETPOSTINT(
'forceexternaluser') && $this->admin && empty($this->socid)) {
794 $this->socid =
GETPOSTINT(
'forceexternaluser');
812 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
813 $sql .=
" WHERE fk_user = ".((int) $this->
id);
815 $sql .=
" AND entity IN (0, ".((int)
$conf->entity).
")";
817 $sql .=
" AND entity = ".((int) $entity);
821 $resql = $this->db->query($sql);
823 $num = $this->db->num_rows($resql);
826 $obj = $this->db->fetch_object($resql);
827 $p = (!empty($obj->param) ? $obj->param :
'');
829 $this->
conf->$p = $obj->value;
833 $this->db->free($resql);
837 $this->
error = $this->db->lasterror();
854 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
857 $result = $defaultValues->fetchAll(
'',
'', 0, 0,
'(t.user_id:in:0,'.$this->
id.
') AND (entity:in:'.(isset($this->entity) ? $this->entity :
$conf->entity).
','.
$conf->entity.
')');
860 if (!is_array($result) && $result < 0) {
861 $this->
error = $defaultValues->error;
862 $this->errors = $defaultValues->errors;
863 dol_print_error($this->db);
865 } elseif (count($result) > 0) {
866 foreach ($result as $defval) {
867 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
868 $pagewithoutquerystring = $defval->page;
871 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
872 $pagewithoutquerystring = $reg[1];
873 $pagequeries = $reg[2];
875 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
879 if (!empty($this->default_values)) {
880 foreach ($this->default_values as $a => $b) {
881 foreach ($b as
$c => $d) {
882 krsort($this->default_values[$a][
$c]);
923 public function hasRight($module, $permlevel1, $permlevel2 =
'')
926 $moduletomoduletouse = array(
927 'category' =>
'categorie',
928 'compta' =>
'comptabilite',
929 'contract' =>
'contrat',
930 'member' =>
'adherent',
932 'order' =>
'commande',
933 'produit' =>
'product',
934 'productlot' =>
'product',
935 'project' =>
'projet',
936 'propale' =>
'propal',
937 'shipping' =>
'expedition',
938 'task' =>
'task@projet',
939 'fichinter' =>
'ficheinter',
940 'intervention' =>
'ficheinter',
941 'inventory' =>
'stock',
942 'invoice' =>
'facture',
943 'invoice_supplier' =>
'facture@fournisseur',
944 'order_supplier' =>
'fournisseur',
945 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
946 'skill@hrm' =>
'all@hrm',
947 'job@hrm' =>
'all@hrm',
948 'position@hrm' =>
'all@hrm',
949 'facturerec' =>
'facture',
950 'margins' =>
'margin',
953 if (!empty($moduletomoduletouse[$module])) {
965 $supplierNewToLegacy = array(
966 'supplier_order' => array(
'fournisseur',
'commande'),
967 'supplier_invoice' => array(
'fournisseur',
'facture'),
970 if (isset($supplierNewToLegacy[
$module])) {
973 $permlevel2 = $permlevel1;
974 $permlevel1 = $supplierNewToLegacy[
$module][1];
980 $supplierLegacyCompat = array(
981 'supplier_order' =>
'fournisseur',
982 'supplier_invoice' =>
'fournisseur',
985 if (isset($supplierLegacyCompat[
$module])) {
991 $moduleRightsMapping = array(
992 'product' =>
'produit',
993 'margin' =>
'margins',
994 'comptabilite' =>
'compta'
998 if (!empty($moduleRightsMapping[$rightsPath])) {
999 $rightsPath = $moduleRightsMapping[$rightsPath];
1003 $tmp = explode(
'@', $rightsPath, 2);
1004 if (!empty($tmp[1])) {
1005 if (strpos(
$module,
'@') !==
false) {
1008 if ($tmp[0] != $tmp[1]) {
1010 $rightsPath = $tmp[1];
1011 $permlevel2 = $permlevel1;
1012 $permlevel1 = $tmp[0];
1015 $rightsPath = $tmp[1];
1027 if (!empty($this->socid)) {
1028 if (
$module ==
'societe' && ($permlevel1 ==
'creer' || $permlevel1 ==
'write')) {
1031 if (
$module ==
'societe' && $permlevel1 ==
'client' && $permlevel2 ==
'voir') {
1034 if (
$module ==
'societe' && $permlevel1 ==
'export') {
1037 if (
$module ==
'societe' && ($permlevel1 ==
'supprimer' || $permlevel1 ==
'delete')) {
1043 if ($permlevel1 ==
'propale') {
1044 $permlevel1 =
'propal';
1046 if ($permlevel1 ==
'member') {
1047 $permlevel1 =
'adherent';
1049 if ($permlevel1 ==
'recruitmentcandidature') {
1050 $permlevel1 =
'recruitmentjobposition';
1053 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
1058 if (!empty($this->rights->$rightsPath->$permlevel1)) {
1059 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
1060 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
1064 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
1065 return $this->rights->$rightsPath->$permlevel1->lire;
1067 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
1068 return $this->rights->$rightsPath->$permlevel1->creer;
1070 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
1071 return $this->rights->$rightsPath->$permlevel1->create;
1073 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
1074 return $this->rights->$rightsPath->$permlevel1->supprimer;
1078 if (!empty($this->rights->$rightsPath->$permlevel1)) {
1079 return $this->rights->$rightsPath->$permlevel1;
1083 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
1084 return $this->rights->$rightsPath->lire;
1086 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
1087 return $this->rights->$rightsPath->creer;
1089 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
1090 return $this->rights->$rightsPath->create;
1092 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
1093 return $this->rights->$rightsPath->supprimer;
1111 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1113 global $conf, $user, $langs;
1115 $entity = (empty($entity) ?
$conf->entity : $entity);
1117 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
1119 if (empty($this->
id)) {
1120 $this->
error =
'Try to call addrights on an object user with an empty id';
1130 $module = $perms = $subperms =
'';
1133 $sql =
"SELECT module, perms, subperms";
1134 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1135 $sql .=
" WHERE id = ".((int) $rid);
1136 $sql .=
" AND entity = ".((int) $entity);
1138 $result = $this->db->query($sql);
1140 $obj = $this->db->fetch_object($result);
1143 $module = $obj->module;
1144 $perms = $obj->perms;
1145 $subperms = $obj->subperms;
1149 dol_print_error($this->db);
1153 $whereforadd =
"id=".((int) $rid);
1155 if (!empty($subperms)) {
1156 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
1157 } elseif (!empty($perms)) {
1158 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND (subperms IS NULL or subperms = ''))";
1164 if (!empty($allmodule)) {
1165 if ($allmodule ==
'allmodules') {
1166 $whereforadd =
'allmodules';
1168 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
1169 if (!empty($allperms)) {
1170 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
1178 if (!empty($whereforadd)) {
1181 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1182 $sql .=
" WHERE entity = ".((int) $entity);
1183 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
1184 $sql .=
" AND (".$whereforadd.
")";
1187 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1188 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1190 $sqldelete .=
") AND entity = ".((int) $entity);
1191 if (!$this->db->query($sqldelete)) {
1196 $resql = $this->db->query($sql);
1198 $num = $this->db->num_rows($resql);
1201 $obj = $this->db->fetch_object($resql);
1206 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
1207 if (!$this->db->query($sql)) {
1216 dol_print_error($this->db);
1221 if (!$error && !$notrigger) {
1222 $langs->load(
"other");
1223 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
1226 $result = $this->call_trigger(
'USER_MODIFY', $user);
1234 $this->db->rollback();
1237 $this->db->commit();
1254 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1256 global $conf, $user, $langs;
1260 $entity = (!empty($entity) ? $entity :
$conf->entity);
1265 $module = $perms = $subperms =
'';
1269 $sql =
"SELECT module, perms, subperms";
1270 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1271 $sql .=
" WHERE id = ".((int) $rid);
1272 $sql .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1274 $result = $this->db->query($sql);
1276 $obj = $this->db->fetch_object($result);
1279 $module = $obj->module;
1280 $perms = $obj->perms;
1281 $subperms = $obj->subperms;
1285 dol_print_error($this->db);
1289 $wherefordel =
"id=".((int) $rid);
1291 if ($subperms ==
'lire' || $subperms ==
'read') {
1292 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1294 if ($perms ==
'lire' || $perms ==
'read') {
1295 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1301 if (!empty($allmodule)) {
1302 if ($allmodule ==
'allmodules') {
1303 $wherefordel =
'allmodules';
1305 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1306 if (!empty($allperms)) {
1307 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1314 if (!empty($wherefordel)) {
1317 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1318 $sql .=
" WHERE entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1319 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1320 $sql .=
" AND (".$wherefordel.
")";
1324 if ($this->admin == 1) {
1325 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1326 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1327 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1328 $sql .=
" AND id NOT IN (358)";
1331 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1332 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1335 $sqldelete .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1337 $resql = $this->db->query($sqldelete);
1340 dol_print_error($this->db);
1344 if (!$error && !$notrigger) {
1345 $langs->load(
"other");
1346 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1349 $result = $this->call_trigger(
'USER_MODIFY', $user);
1357 $this->db->rollback();
1360 $this->db->commit();
1374 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1376 $this->nb_rights = 0;
1377 $this->all_permissions_are_loaded = 0;
1378 $this->_tab_loaded = array();
1394 $alreadyloaded =
false;
1396 if (empty($forcereload)) {
1397 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1399 $alreadyloaded =
true;
1402 if (!empty($this->all_permissions_are_loaded)) {
1404 $alreadyloaded =
true;
1409 if (!isset($this->rights) || !is_object($this->rights)) {
1412 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1413 $this->rights->user =
new stdClass();
1418 if (!$alreadyloaded) {
1420 $sql =
"SELECT DISTINCT r.module, r.module_origin, r.perms, r.subperms";
1421 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1422 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1423 $sql .=
" WHERE r.id = ur.fk_id";
1429 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') ?
"1," :
"").((
int)
$conf->entity).
")";
1433 $sql .=
" AND r.entity = ".((int)
$conf->entity).
" AND ur.entity = ".((int)
$conf->entity);
1435 $sql .=
" AND ur.fk_user = ".((int) $this->
id);
1436 $sql .=
" AND r.perms IS NOT NULL";
1438 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1441 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1444 $resql = $this->db->query($sql);
1446 $num = $this->db->num_rows($resql);
1449 $obj = $this->db->fetch_object($resql);
1457 $module = (!empty($obj->module_origin) ? $obj->module_origin : $obj->module);
1458 $perms = $obj->perms;
1459 $subperms = $obj->subperms;
1461 if (!empty($perms)) {
1462 if (!empty($module)) {
1463 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1464 $this->rights->$module =
new stdClass();
1466 if (!empty($subperms)) {
1467 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1468 $this->rights->$module->$perms =
new stdClass();
1470 if (empty($this->rights->$module->$perms->$subperms)) {
1473 $this->rights->$module->$perms->$subperms = 1;
1475 if (empty($this->rights->$module->$perms)) {
1478 $this->rights->$module->$perms = 1;
1485 $this->db->free($resql);
1489 $sql =
"SELECT DISTINCT r.module, r.module_origin, r.perms, r.subperms, r.entity";
1490 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1491 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1492 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1493 $sql .=
" WHERE r.id = gr.fk_id";
1499 $sql .=
" AND gu.entity IN (0,".((int)
$conf->entity).
")";
1501 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1504 $sql .=
" AND gr.entity = ".((int)
$conf->entity);
1508 $sql .=
" AND gu.entity IN (0,".((int)
$conf->entity).
")";
1509 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1512 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1513 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1514 $sql .=
" AND r.perms IS NOT NULL";
1516 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1519 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1522 $resql = $this->db->query($sql);
1524 $num = $this->db->num_rows($resql);
1527 $obj = $this->db->fetch_object($resql);
1535 $module = (!empty($obj->module_origin) ? $obj->module_origin : $obj->module);
1536 $perms = $obj->perms;
1537 $subperms = $obj->subperms;
1539 if (!empty($perms)) {
1540 if (!empty($module)) {
1541 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1542 $this->rights->$module =
new stdClass();
1544 if (!empty($subperms)) {
1545 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1546 $this->rights->$module->$perms =
new stdClass();
1548 if (empty($this->rights->$module->$perms->$subperms)) {
1551 $this->rights->$module->$perms->$subperms = 1;
1554 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1555 if (empty($this->rights->$module->$perms)) {
1558 $this->rights->$module->$perms = 1;
1566 $this->db->free($resql);
1570 if (!empty($this->admin)) {
1571 if (empty($this->rights->user->user)) {
1572 $this->rights->user->user =
new stdClass();
1574 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1575 foreach ($listofpermtotest as $permtotest) {
1576 if (empty($this->rights->user->user->$permtotest)) {
1577 $this->rights->user->user->$permtotest = 1;
1581 if (empty($this->rights->user->self)) {
1582 $this->rights->user->self =
new stdClass();
1584 $listofpermtotest = array(
'creer',
'password');
1585 foreach ($listofpermtotest as $permtotest) {
1586 if (empty($this->rights->user->self->$permtotest)) {
1587 $this->rights->user->self->$permtotest = 1;
1593 if (empty($this->rights->user->user_advance)) {
1594 $this->rights->user->user_advance =
new stdClass();
1596 $listofpermtotest = array(
'readperms',
'write');
1597 foreach ($listofpermtotest as $permtotest) {
1598 if (empty($this->rights->user->user_advance->$permtotest)) {
1599 $this->rights->user->user_advance->$permtotest = 1;
1603 if (empty($this->rights->user->self_advance)) {
1604 $this->rights->user->self_advance =
new stdClass();
1606 $listofpermtotest = array(
'readperms',
'writeperms');
1607 foreach ($listofpermtotest as $permtotest) {
1608 if (empty($this->rights->user->self_advance->$permtotest)) {
1609 $this->rights->user->self_advance->$permtotest = 1;
1613 if (empty($this->rights->user->group_advance)) {
1614 $this->rights->user->group_advance =
new stdClass();
1616 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1617 foreach ($listofpermtotest as $permtotest) {
1618 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1619 $this->rights->user->group_advance->$permtotest = 1;
1627 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1628 $this->rights->propal = $this->rights->propale;
1630 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1631 $this->rights->propale = $this->rights->propal;
1638 $this->all_permissions_are_loaded = 1;
1641 $this->_tab_loaded[$moduletag] = 1;
1658 public function getrights($moduletag =
'', $forcereload = 0)
1671 global $conf, $langs, $user;
1676 if (isset($this->
status)) {
1677 if ($this->
status == $status) {
1680 } elseif (isset($this->statut) && $this->statut == $status) {
1687 $sql =
"UPDATE ".$this->db->prefix().
"user";
1688 $sql .=
" SET statut = ".((int) $status);
1689 $sql .=
" WHERE rowid = ".((int) $this->
id);
1690 $result = $this->db->query($sql);
1692 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1695 $this->context[
'actionmsg'] =
'User '.$this->login.
' disabled';
1697 $this->context[
'actionmsg'] =
'User '.$this->login.
' enabled';
1700 $result = $this->call_trigger(
'USER_ENABLEDISABLE', $user);
1708 $this->db->rollback();
1712 $this->statut = $status;
1713 $this->db->commit();
1729 $value = (int) $value;
1732 if ($this->force_pass_change == $value) {
1739 $sql =
"UPDATE ".$this->db->prefix().
"user";
1740 $sql .=
" SET force_pass_change = ".((int) $value);
1741 $sql .=
" WHERE rowid = ".((int) $this->
id);
1742 $result = $this->db->query($sql);
1744 dol_syslog(get_class($this).
"::setForcePasswordChange", LOG_DEBUG);
1746 $this->force_pass_change = $value;
1748 $result = $this->call_trigger(
'USER_MODIFY', $user);
1755 $this->
error = $this->db->lasterror();
1759 $this->db->rollback();
1762 $this->db->commit();
1779 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1780 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1795 $this->
fetch($this->
id);
1797 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1800 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1802 if (!$error && !$this->db->query($sql)) {
1804 $this->
error = $this->db->lasterror();
1808 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1809 if (!$error && !$this->db->query($sql)) {
1811 $this->
error = $this->db->lasterror();
1815 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1816 if (!$error && !$this->db->query($sql)) {
1818 $this->
error = $this->db->lasterror();
1822 if ($this->contact_id > 0) {
1823 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1824 if (!$error && !$this->db->query($sql)) {
1826 $this->
error = $this->db->lasterror();
1835 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1841 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1842 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1843 if (!$this->db->query($sql)) {
1845 $this->
error = $this->db->lasterror();
1851 $result = $this->call_trigger(
'USER_DELETE', $user);
1854 $this->db->rollback();
1859 $this->db->commit();
1862 $this->db->rollback();
1874 public function create($user, $notrigger = 0)
1876 global $conf, $langs;
1882 $this->civility_code = trim((
string) $this->civility_code);
1883 $this->login = trim((
string) $this->login);
1884 $this->user_creation_id = (int) $user->id;
1885 if (!isset($this->entity)) {
1886 $this->entity =
$conf->entity;
1888 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1894 $langs->load(
"errors");
1895 $this->
error = $langs->trans(
"ErrorBadEMail", $this->
email);
1898 if (empty($this->login)) {
1899 $langs->load(
"errors");
1900 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1902 } elseif ($badCharUnauthorizedIntoLoginName !==
'' && preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1903 $langs->load(
"errors");
1904 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1915 $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).
"'";
1916 $resqltochecklogin = $this->db->query($sqltochecklogin);
1917 if ($resqltochecklogin) {
1918 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1919 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1920 $langs->load(
"errors");
1921 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1923 $this->db->rollback();
1926 $this->db->free($resqltochecklogin);
1929 if (!empty($this->
email)) {
1930 $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).
"'";
1931 $resqltochecklogin = $this->db->query($sqltochecklogin);
1932 if ($resqltochecklogin) {
1933 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1934 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1935 $langs->load(
"errors");
1936 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->
email);
1938 $this->db->rollback();
1941 $this->db->free($resqltochecklogin);
1946 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, fk_user_creat, entity)";
1947 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->db->escape($this->login).
"', '".$this->db->escape($this->ldap_sid).
"', ".(int) $this->user_creation_id.
", ".((
int) $this->entity).
")";
1948 $result = $this->db->query($sql);
1950 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1952 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1956 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1957 $this->db->rollback();
1962 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1963 $langs->load(
"stocks");
1965 $entrepot =
new Entrepot($this->db);
1966 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1967 $entrepot->libelle = $entrepot->label;
1968 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1969 $entrepot->statut = 1;
1970 $entrepot->country_id =
$mysoc->country_id;
1972 $warehouseid = $entrepot->create($user);
1974 $this->fk_warehouse = $warehouseid;
1978 $result = $this->
update($user, 1, 1);
1980 $this->db->rollback();
1986 $result = $this->call_trigger(
'USER_CREATE', $user);
1994 $this->db->commit();
1999 $this->db->rollback();
2003 $this->
error = $this->db->lasterror();
2004 $this->db->rollback();
2028 $this->civility_code = $contact->civility_code;
2029 $this->lastname = $contact->lastname;
2030 $this->firstname = $contact->firstname;
2032 $this->
email = $contact->email;
2033 $this->socialnetworks = $contact->socialnetworks;
2034 $this->office_phone = $contact->phone_pro;
2035 $this->office_fax = $contact->fax;
2036 $this->user_mobile = $contact->phone_mobile;
2037 $this->
address = $contact->address;
2038 $this->zip = $contact->zip;
2039 $this->town = $contact->town;
2041 $this->state_id = $contact->state_id;
2042 $this->country_id = $contact->country_id;
2043 $this->employee = 0;
2045 if (empty($login)) {
2046 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
2047 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
2049 $this->login = $login;
2054 $result = $this->
create($user, 1);
2056 $sql =
"UPDATE ".$this->db->prefix().
"user";
2057 $sql .=
" SET fk_socpeople=".((int) $contact->id);
2058 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
2059 if ($contact->socid > 0) {
2060 $sql .=
", fk_soc=".((int) $contact->socid);
2062 $sql .=
" WHERE rowid=".((int) $this->
id);
2064 $resql = $this->db->query($sql);
2066 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
2068 $this->context[
'createfromcontact'] =
'createfromcontact';
2071 $result = $this->call_trigger(
'USER_CREATE', $user);
2074 $this->db->rollback();
2079 $this->db->commit();
2082 $this->
error = $this->db->error();
2084 $this->db->rollback();
2089 dol_syslog(get_class($this).
"::create_from_contact - 0");
2091 $this->db->rollback();
2112 $this->civility_code = $member->civility_code;
2113 $this->lastname = $member->lastname;
2114 $this->firstname = $member->firstname;
2115 $this->gender = $member->gender;
2116 $this->
email = $member->email;
2117 $this->fk_member = $member->id;
2118 $this->
address = $member->address;
2119 $this->zip = $member->zip;
2120 $this->town = $member->town;
2122 $this->state_id = $member->state_id;
2123 $this->country_id = $member->country_id;
2124 $this->socialnetworks = $member->socialnetworks;
2126 $this->pass = $member->pass;
2127 $this->pass_crypted = $member->pass_indatabase_crypted;
2129 if (empty($login)) {
2130 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
2133 $this->login = $login;
2138 $result = $this->
create($user);
2140 if (!empty($this->pass)) {
2141 $newpass = $this->
setPassword($user, $this->pass);
2142 if (is_int($newpass) && $newpass < 0) {
2145 } elseif (!empty($this->pass_crypted)) {
2146 $sql =
"UPDATE ".$this->db->prefix().
"user";
2147 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
2148 $sql .=
" WHERE rowid=".((int) $this->
id);
2150 $resql = $this->db->query($sql);
2156 if ($result > 0 && $member->socid) {
2157 $sql =
"UPDATE ".$this->db->prefix().
"user";
2158 $sql .=
" SET fk_soc=".((int) $member->socid);
2159 $sql .=
" WHERE rowid=".((int) $this->
id);
2161 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
2162 $resql = $this->db->query($sql);
2164 $this->db->commit();
2167 $this->
error = $this->db->lasterror();
2169 $this->db->rollback();
2176 $this->db->commit();
2180 $this->db->rollback();
2198 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
2199 $sql .=
" WHERE bydefault = 1";
2200 $sql .=
" AND entity = ".((int)
$conf->entity);
2202 $resql = $this->db->query($sql);
2204 $num = $this->db->num_rows($resql);
2207 $row = $this->db->fetch_row($resql);
2211 $this->db->free($resql);
2215 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id).
" AND fk_id=".((int) $rd[$i]);
2216 $result = $this->db->query($sql);
2218 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES (".((int) $this->
id).
", ".((int) $rd[$i]).
")";
2219 $result = $this->db->query($sql);
2239 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
2243 if (empty($this->country_id) && !empty($this->country_code)) {
2244 $country_id =
getCountry($this->country_code,
'3');
2245 $this->country_id = is_int($country_id) ? $country_id : 0;
2248 $nbrowsaffected = 0;
2251 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
2254 $this->civility_code = trim((
string) $this->civility_code);
2255 $this->lastname = trim((
string) $this->lastname);
2256 $this->firstname = trim((
string) $this->firstname);
2257 $this->ref_employee = trim((
string) $this->ref_employee);
2258 $this->national_registration_number = trim((
string) $this->national_registration_number);
2259 $this->employee = ($this->employee > 0 ? $this->employee : 0);
2260 $this->login = trim((
string) $this->login);
2261 $this->gender = trim((
string) $this->gender);
2263 $this->pass = trim((
string) $this->pass);
2264 $this->api_key = trim((
string) $this->api_key);
2265 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
2266 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
2269 $this->zip = trim((
string) $this->zip);
2270 $this->town = trim((
string) $this->town);
2272 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
2273 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
2274 $this->office_phone = trim((
string) $this->office_phone);
2275 $this->office_fax = trim((
string) $this->office_fax);
2276 $this->user_mobile = trim((
string) $this->user_mobile);
2277 $this->personal_mobile = trim((
string) $this->personal_mobile);
2279 $this->personal_email = trim((
string) $this->personal_email);
2281 $this->job = trim((
string) $this->job);
2282 $this->signature = trim((
string) $this->signature);
2283 $this->note_public = trim((
string) $this->note_public);
2284 $this->note_private = trim((
string) $this->note_private);
2285 $this->openid = trim((
string) $this->openid);
2286 $this->admin = ($this->admin > 0 ? $this->admin : 0);
2287 $this->user_modification_id = $user->id;
2289 $this->accountancy_code_user_general = trim((
string) $this->accountancy_code_user_general);
2290 $this->accountancy_code = trim((
string) $this->accountancy_code);
2291 $this->color = trim(str_replace(
'#',
'', (
string) $this->color));
2292 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
2293 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
2295 $this->birth = empty($this->birth) ?
'' : $this->birth;
2296 $this->fk_warehouse = (int) $this->fk_warehouse;
2297 $this->fk_establishment = (int) $this->fk_establishment;
2305 $langs->load(
"errors");
2306 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
2309 if (empty($this->login)) {
2310 $langs->load(
"errors");
2311 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
2313 } elseif ($badCharUnauthorizedIntoLoginName !==
'' && preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
2314 $langs->load(
"errors");
2315 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
2322 if (is_object($this->oldcopy) && !empty($this->oldcopy->id) && $this->oldcopy->login != $this->login) {
2323 $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).
"'";
2324 $resqltochecklogin = $this->db->query($sqltochecklogin);
2325 if ($resqltochecklogin) {
2326 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2327 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2328 $langs->load(
"errors");
2329 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
2331 $this->db->rollback();
2336 if (is_object($this->oldcopy) && !empty($this->oldcopy->id) && !empty($this->email) && $this->oldcopy->email != $this->email) {
2337 $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).
"'";
2338 $resqltochecklogin = $this->db->query($sqltochecklogin);
2339 if ($resqltochecklogin) {
2340 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2341 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2342 $langs->load(
"errors");
2343 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
2345 $this->db->rollback();
2352 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2353 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
2354 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
2355 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
2356 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
2357 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
2358 $sql .=
", employee = ".(int) $this->employee;
2359 $sql .=
", login = '".$this->db->escape($this->login).
"'";
2360 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
2361 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
2362 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
2363 if (!empty($user->admin)) {
2364 $sql .=
", admin = ".(int) $this->admin;
2366 $sql .=
", address = '".$this->db->escape($this->address).
"'";
2367 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
2368 $sql .=
", town = '".$this->db->escape($this->town).
"'";
2369 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ? ((
int) $this->state_id) :
"null");
2370 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ? ((
int) $this->country_id) :
"null");
2371 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
2372 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
2373 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
2374 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
2375 $sql .=
", email = '".$this->db->escape($this->email).
"'";
2376 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
2377 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
2378 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2379 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2380 $sql .=
", accountancy_code_user_general = '".$this->db->escape($this->accountancy_code_user_general).
"'";
2381 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2382 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2383 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2384 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2385 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2386 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2387 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2388 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2389 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2390 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2391 $sql .=
", fk_user = ".($this->fk_user > 0 ? ((int) $this->fk_user) :
"null");
2392 $sql .=
", fk_user_modif = ".($this->user_modification_id > 0 ? ((int) $this->user_modification_id) :
"null");
2393 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ? ((int) $this->fk_user_expense_validator) :
"null");
2394 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ? ((int) $this->fk_user_holiday_validator) :
"null");
2395 if (isset($this->thm) || $this->thm !=
'') {
2396 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2398 if (isset($this->tjm) || $this->tjm !=
'') {
2399 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2401 if (isset($this->salary) || $this->salary !=
'') {
2402 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2404 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2405 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2407 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2408 if (
isModEnabled(
'multicompany') && !empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2413 $sql .=
", entity = ".((int) $this->entity);
2416 $sql .=
", default_range = ".($this->default_range > 0 ? ((int) $this->default_range) :
'null');
2417 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? ((int) $this->default_c_exp_tax_cat) :
'null');
2418 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? ((int) $this->fk_warehouse) :
"null");
2419 $sql .=
", fk_establishment = ".($this->fk_establishment > 0 ? ((int) $this->fk_establishment) :
"null");
2420 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2421 $sql .=
", force_pass_change = ".($this->force_pass_change ? ((int) $this->force_pass_change) :
"0");
2422 $sql .=
" WHERE rowid = ".((int) $this->
id);
2424 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2425 $resql = $this->db->query($sql);
2427 $nbrowsaffected += $this->db->affected_rows($resql);
2430 if (!empty($this->pass)) {
2431 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2433 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2434 if (is_int($result) && $result < 0) {
2441 if ($this->fk_member > 0) {
2442 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2443 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2444 $resql = $this->db->query($sql);
2446 $this->
error = $this->db->error();
2447 $this->db->rollback();
2452 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2453 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2454 $resql = $this->db->query($sql);
2456 $this->
error = $this->db->error();
2457 $this->db->rollback();
2461 if ($nbrowsaffected) {
2462 if ($this->fk_member > 0 && !$nosyncmember) {
2463 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2465 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2470 $result = $adh->fetch($this->fk_member);
2473 $adh->civility_code = $this->civility_code;
2474 $adh->firstname = $this->firstname;
2475 $adh->lastname = $this->lastname;
2476 $adh->login = $this->login;
2477 $adh->gender = $this->gender;
2478 $adh->birth = $this->birth;
2480 $adh->pass = $this->pass;
2482 $adh->address = $this->address;
2483 $adh->town = $this->town;
2484 $adh->zip = $this->zip;
2485 $adh->state_id = $this->state_id;
2486 $adh->country_id = $this->country_id;
2488 $adh->email = $this->email;
2490 $adh->socialnetworks = $this->socialnetworks;
2492 $adh->phone = $this->office_phone;
2493 $adh->phone_mobile = $this->user_mobile;
2495 $adh->default_lang = $this->lang;
2497 $adh->user_id = $this->id;
2498 $adh->user_login = $this->login;
2500 $result = $adh->update($user, 0, 1, 0);
2502 $this->
error = $adh->error;
2503 $this->errors = $adh->errors;
2504 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2507 } elseif ($result < 0) {
2508 $this->
error = $adh->error;
2509 $this->errors = $adh->errors;
2514 if ($this->contact_id > 0 && !$nosynccontact) {
2515 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2517 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2520 $tmpobj =
new Contact($this->db);
2521 $result = $tmpobj->fetch($this->contact_id);
2524 $tmpobj->civility_code = $this->civility_code;
2525 $tmpobj->firstname = $this->firstname;
2526 $tmpobj->lastname = $this->lastname;
2527 $tmpobj->login = $this->login;
2528 $tmpobj->gender = $this->gender;
2529 $tmpobj->birth = $this->birth;
2533 $tmpobj->email = $this->email;
2535 $tmpobj->socialnetworks = $this->socialnetworks;
2537 $tmpobj->phone_pro = $this->office_phone;
2538 $tmpobj->phone_mobile = $this->user_mobile;
2539 $tmpobj->fax = $this->office_fax;
2541 $tmpobj->default_lang = $this->lang;
2543 $tmpobj->address = $this->address;
2544 $tmpobj->town = $this->town;
2545 $tmpobj->zip = $this->zip;
2546 $tmpobj->state_id = $this->state_id;
2547 $tmpobj->country_id = $this->country_id;
2549 $tmpobj->user_id = $this->id;
2550 $tmpobj->user_login = $this->login;
2552 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2554 $this->
error = $tmpobj->error;
2555 $this->errors = $tmpobj->errors;
2556 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2560 $this->
error = $tmpobj->error;
2561 $this->errors = $tmpobj->errors;
2577 if (!$error && !$notrigger) {
2579 $result = $this->call_trigger(
'USER_MODIFY', $user);
2587 $this->db->commit();
2588 return $nbrowsaffected;
2591 $this->db->rollback();
2595 $this->
error = $this->db->lasterror();
2596 $this->db->rollback();
2615 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2616 $sql .=
" datepreviouslogin = datelastlogin,";
2617 $sql .=
" ippreviouslogin = iplastlogin,";
2618 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2619 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2620 $sql .=
" tms = tms";
2621 $sql .=
" WHERE rowid = ".((int) $this->
id);
2623 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2624 $resql = $this->db->query($sql);
2626 $this->datepreviouslogin = $this->datelastlogin;
2627 $this->datelastlogin = $now;
2628 $this->ippreviouslogin = $this->iplastlogin;
2629 $this->iplastlogin = $userremoteip;
2632 $this->
error = $this->db->lasterror().
' sql='.$sql;
2650 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2652 global $conf, $langs;
2653 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2657 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2662 $passwordalreadycrypted = 0;
2666 if (!empty($passwordalreadycrypted)) {
2667 $password_crypted = $password;
2671 require_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/modules_genpassword.php';
2673 if ($modGeneratePass) {
2674 '@phan-var-force ModeleGenPassword $modGeneratePass';
2677 $modGeneratePass->WithoutAmbi = 0;
2680 $testpassword = $modGeneratePass->validatePassword($password);
2681 if (!$testpassword) {
2682 $this->
error = $modGeneratePass->error;
2690 $password_crypted = (string)
dol_hash($password);
2694 if (!$changelater) {
2695 if (!is_object($this->oldcopy)) {
2696 $this->oldcopy = clone $this;
2703 $sql =
"UPDATE ".$this->db->prefix().
"user";
2704 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2705 $sql .=
" datelastpassvalidation = '".$this->db->idate(
dol_now()).
"',";
2706 $sql .=
" pass_temp = null,";
2707 $sql .=
" force_pass_change = 0";
2708 if (!empty($flagdelsessionsbefore)) {
2709 $sql .=
", flagdelsessionsbefore = '".$this->db->idate($now - 5,
'gmt').
"'";
2712 $sql .=
", pass = null";
2714 $sql .=
", pass = '".$this->db->escape($password).
"'";
2716 $sql .=
" WHERE rowid = ".((int) $this->
id);
2718 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2720 $result = $this->db->query($sql);
2722 if ($this->db->affected_rows($result)) {
2723 $this->pass = $password;
2724 $this->pass_indatabase = $password;
2725 $this->pass_indatabase_crypted = (string) $password_crypted;
2726 $this->force_pass_change = 0;
2728 if ($this->fk_member && !$nosyncmember) {
2729 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2734 $result = $adh->fetch($this->fk_member);
2737 $result = $adh->setPassword($user, $this->pass, (!
getDolGlobalString(
'DATABASE_PWD_ENCRYPTED') ? 0 : 1), 1);
2738 if (is_int($result) && $result < 0) {
2739 $this->
error = $adh->error;
2744 $this->
error = $adh->error;
2749 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2752 $user->context[
'audit'] =
'login='.$user->login;
2753 if (!empty($flagdelsessionsbefore)) {
2754 $user->context[
'audit'] .=
" - flagdelsessionsbefore set to '".$this->db->idate($now - 5,
'gmt').
"'";
2757 if (!$error && !$notrigger) {
2759 $result = $this->call_trigger(
'USER_NEW_PASSWORD', $user);
2762 $this->db->rollback();
2768 $this->db->commit();
2771 $this->db->rollback();
2775 $this->db->rollback();
2776 dol_print_error($this->db);
2782 $sql =
"UPDATE ".$this->db->prefix().
"user";
2783 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2784 $sql .=
" WHERE rowid = ".((int) $this->
id);
2786 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2787 $result = $this->db->query($sql);
2791 dol_print_error($this->db);
2809 global $conf, $langs;
2812 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2824 $outputlangs = $langs;
2828 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2830 $appli =
getDolGlobalString(
'MAIN_APPLICATION_TITLE', constant(
'DOL_APPLICATION_TITLE'));
2832 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2835 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
2836 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2838 if (!$changelater) {
2839 $url = $urlwithroot.
'/';
2844 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2846 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"\n";
2847 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2848 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2849 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2852 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2854 $mesg .= $user->getFullName($outputlangs);
2857 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2858 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.
$conf->file->instance_unique_id));
2860 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2863 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2867 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2868 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2869 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2870 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2872 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2873 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2874 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2877 $trackid =
'use'.$this->id;
2878 $sendcontext =
'passwordreset';
2899 if ($mailfile->sendfile()) {
2902 $langs->trans(
"errors");
2903 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2915 return $this->error;
2928 $sql =
"SELECT url, login, pass, poste ";
2929 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2930 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2932 $resql = $this->db->query($sql);
2934 if ($this->db->num_rows($resql)) {
2935 $obj = $this->db->fetch_object($resql);
2937 $this->clicktodial_url = $obj->url;
2938 $this->clicktodial_login = $obj->login;
2939 $this->clicktodial_password = $obj->pass;
2940 $this->clicktodial_poste = $obj->poste;
2943 $this->clicktodial_loaded = 1;
2945 $this->db->free($resql);
2948 $this->
error = $this->db->error();
2964 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2965 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2967 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2969 $result = $this->db->query($sql);
2971 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2972 $sql .=
" (fk_user,url,login,pass,poste)";
2973 $sql .=
" VALUES (".((int) $this->
id);
2974 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2975 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2976 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2977 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2979 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2981 $result = $this->db->query($sql);
2983 $this->db->commit();
2986 $this->db->rollback();
2987 $this->
error = $this->db->lasterror();
3005 global $langs, $user;
3011 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
3012 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3013 $sql .=
" AND fk_usergroup = ".((int) $group);
3014 $sql .=
" AND entity = ".((int) $entity);
3016 $result = $this->db->query($sql);
3018 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
3019 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
3021 $result = $this->db->query($sql);
3023 if (!$error && !$notrigger) {
3024 $this->context = array(
'audit' => $langs->trans(
"UserSetInGroup"),
'newgroupid' => $group);
3027 $result = $this->call_trigger(
'USER_MODIFY', $user);
3035 $this->db->commit();
3039 $this->db->rollback();
3043 $this->
error = $this->db->lasterror();
3044 $this->db->rollback();
3061 global $langs, $user;
3067 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
3068 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3069 $sql .=
" AND fk_usergroup = ".((int) $group);
3070 if (empty($entity)) {
3071 $sql .=
" AND entity IN (0, 1)";
3073 $sql .=
" AND entity = ".((int) $entity);
3076 $result = $this->db->query($sql);
3078 if (!$error && !$notrigger) {
3079 $this->context = array(
'audit' => $langs->trans(
"UserRemovedFromGroup"),
'oldgroupid' => $group);
3082 $result = $this->call_trigger(
'USER_MODIFY', $user);
3090 $this->db->commit();
3093 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
3094 $this->db->rollback();
3098 $this->
error = $this->db->lasterror();
3099 $this->db->rollback();
3113 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
3120 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
3143 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
3145 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3146 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
3160 global $conf, $langs, $menumanager;
3161 global $dolibarr_main_demo;
3163 $infologin = $params[
'infologin'] ?? 0;
3164 $option = $params[
'option'] ??
'';
3167 if (!empty($this->photo)) {
3168 $photo =
'<div class="photointooltip floatright">';
3169 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
3171 $data[
'photo'] = $photo;
3176 $data[
'opendiv'] =
'<div class="centpercent divtooltip">';
3177 $data[
'picto'] = img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
3179 if (!empty($this->login)) {
3182 if (!empty($this->job)) {
3186 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
3187 $phonelist = array();
3188 if ($this->office_phone) {
3189 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
3191 if ($this->office_fax) {
3192 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
3194 if ($this->user_mobile) {
3195 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
3197 $data[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
3199 if (!empty($this->admin)) {
3200 $data[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.yn($this->admin);
3202 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
3203 $langs->load(
"companies");
3204 $data[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
3207 if (!empty($this->socid)) {
3208 $thirdpartystatic =
new Societe($this->db);
3209 $thirdpartystatic->fetch($this->socid);
3211 if (empty($params[
'hidethirdpartylogo'])) {
3212 $companyimg =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3214 $company =
' ('.$langs->trans(
"Company").
': '.($companyimg ? $companyimg : img_picto(
'',
'company')).
' '.
dol_string_nohtmltag($thirdpartystatic->name).
')';
3216 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
3217 $data[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
3218 $data[
'closediv'] =
'</div>';
3220 if ($infologin > 0) {
3221 $data[
'newlinelogin'] =
'<br>';
3222 $data[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
3225 $data[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.
$conf->entity.
' (User entity '.$this->entity.
')';
3227 $data[
'authentication'] =
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
3228 $data[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
3229 $data[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
3232 $data[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
3234 $data[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
3235 $data[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag(
$conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.($_SERVER[
'HTTP_USER_AGENT'] ??
'').
')');
3237 $data[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
3238 if (
$conf->browser->layout ==
'phone') {
3239 $data[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
3241 if (!empty($_SESSION[
"disablemodules"])) {
3242 $data[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(implode(
', ', explode(
',', $_SESSION[
"disablemodules"])));
3264 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
3266 global $langs, $hookmanager, $user;
3268 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
3279 'objecttype' => $this->element,
3280 'infologin' => $infologin,
3281 'option' => $option,
3282 'hidethirdpartylogo' => $hidethirdpartylogo,
3284 $classfortooltip =
'classfortooltip';
3287 $classfortooltip =
'classforajaxtooltip';
3288 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3295 if (!empty($this->socid)) {
3296 $thirdpartystatic =
new Societe($this->db);
3297 $thirdpartystatic->fetch($this->socid);
3298 if (empty($hidethirdpartylogo)) {
3299 $companylink =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3303 if ($infologin < 0) {
3307 $baseurl = DOL_URL_ROOT .
'/user/card.php';
3308 if ($option ==
'leave') {
3309 $baseurl = DOL_URL_ROOT .
'/holiday/list.php';
3311 $query = [
'id' => $this->id];
3312 if ($option !=
'nolink') {
3314 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3315 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3316 $add_save_lastsearch_values = 1;
3318 if ($add_save_lastsearch_values) {
3319 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
3324 $linkstart =
'<a href="'.$url.
'"';
3326 if (empty($notooltip)) {
3328 $langs->load(
"users");
3329 $label = $langs->trans(
"ShowUser");
3330 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
3332 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
3333 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
3335 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
3338 $linkstart .= $linkclose.
'>';
3342 $result .= (($option ==
'nolink') ?
'' : $linkstart);
3343 if ($withpictoimg) {
3344 $paddafterimage =
'';
3345 if (abs((
int) $withpictoimg) == 1 || abs((
int) $withpictoimg) == 4) {
3346 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3349 if ($withpictoimg > 0) {
3350 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'"><div class="valignmiddle userphoto inline-block center marginrightonlyshort"'.($paddafterimage ?
' '.$paddafterimage :
'').
'>'.img_object(
'',
'user',
'class=""', 0, 0, $notooltip ? 0 : 1).
'</div></span>';
3353 $picto =
'<!-- picto photo user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'"'.($paddafterimage ?
' '.$paddafterimage :
'').
'>';
3354 $picto .=
Form::showphoto(
'userphoto', $this, 0, 0, 0,
'userphoto'.(($withpictoimg == -3 || $withpictoimg == -4) ?
'small' :
''),
'mini', 0, 1);
3355 $picto .=
'</span>';
3360 if ($withpictoimg == -4 || ($withpictoimg > -2 && $withpictoimg != 2)) {
3362 $result .=
'<span class="nopadding usertext'.((!isset($this->
status) || $this->status) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
3364 if ($mode ==
'login') {
3370 $result .=
'</span>';
3373 $result .= (($option ==
'nolink') ?
'' : $linkend);
3376 $result .= $companylink;
3379 $hookmanager->initHooks(array(
'userdao'));
3380 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
3381 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3383 $result = $hookmanager->resPrint;
3385 $result .= $hookmanager->resPrint;
3400 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
3402 global $langs, $user;
3406 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3410 if ((!$user->hasRight(
'user',
'user',
'lire') && $this->id != $user->id)) {
3414 if ($option ==
'xxx') {
3415 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3419 if ($option ==
'nolink') {
3424 $result .= $linkstart;
3425 if ($withpictoimg) {
3426 $paddafterimage =
'';
3427 if (abs($withpictoimg) == 1) {
3428 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3431 if ($withpictoimg > 0) {
3432 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3435 $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>';
3439 $result .= $this->login;
3440 $result .= $linkend;
3469 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3472 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3473 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3474 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3475 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3478 $statusType =
'status5';
3479 if ($status == self::STATUS_ENABLED) {
3480 $statusType =
'status4';
3483 $label = $this->labelStatus[$status];
3484 $labelshort = $this->labelStatusShort[$status];
3487 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3488 $statusType =
'status3';
3489 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3491 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3492 $statusType =
'status2';
3493 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3496 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3511 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3513 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3514 $return .=
'<div class="info-box info-box-sm">';
3515 $return .=
'<span class="info-box-icon bg-infobox-action">';
3518 if (!empty($this->photo)) {
3520 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3525 $return .= img_picto(
'', $this->picto);
3529 $return .=
'</span>';
3530 $return .=
'<div class="info-box-content">';
3531 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3532 if (
isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3533 $return .= img_picto($langs->trans(
"SuperAdministratorDesc"),
'superadmin',
'class="valignmiddle paddingright paddingleft"');
3534 } elseif ($this->admin) {
3535 $return .= img_picto($langs->trans(
"AdministratorDesc"),
'admin',
'class="valignmiddle paddingright paddingleft"');
3537 $return .=
'</span>';
3538 if ($selected >= 0) {
3539 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3541 if (property_exists($this,
'label')) {
3542 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3545 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->
email.
'</span>';
3547 if (method_exists($this,
'getLibStatut')) {
3548 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3550 $return .=
'</div>';
3551 $return .=
'</div>';
3552 $return .=
'</div>';
3576 } elseif ($mode == 1) {
3578 } elseif ($mode == 2) {
3594 global $conf, $langs;
3600 $keymodified =
false;
3609 'LDAP_FIELD_FULLNAME' =>
'fullname',
3610 'LDAP_FIELD_NAME' =>
'lastname',
3611 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3612 'LDAP_FIELD_LOGIN' =>
'login',
3613 'LDAP_FIELD_LOGIN_SAMBA' =>
'login',
3614 'LDAP_FIELD_PHONE' =>
'office_phone',
3615 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3616 'LDAP_FIELD_FAX' =>
'office_fax',
3617 'LDAP_FIELD_MAIL' =>
'email',
3618 'LDAP_FIELD_SID' =>
'ldap_sid',
3622 foreach ($ldapkey as $constname => $varname) {
3628 if (is_object($this->oldcopy) && !empty($this->oldcopy->id) && $this->$varname != $this->oldcopy->$varname) {
3629 $keymodified =
true;
3634 foreach ($socialnetworks as $key => $value) {
3635 if (!empty($this->socialnetworks[$value[
'label']]) &&
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))) {
3636 $info[
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))] = $this->socialnetworks[$value[
'label']];
3652 $soc =
new Societe($this->db);
3653 $soc->fetch($this->socid);
3656 if ($soc->client == 1) {
3657 $info[
"businessCategory"] =
"Customers";
3659 if ($soc->client == 2) {
3660 $info[
"businessCategory"] =
"Prospects";
3662 if ($soc->fournisseur == 1) {
3663 $info[
"businessCategory"] =
"Suppliers";
3668 if (!empty($this->pass)) {
3681 if ($this->pass_indatabase_crypted &&
getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED')) {
3685 } elseif (!empty($this->pass_indatabase)) {
3697 $info[
"objectclass"][4] =
"phpgwContact";
3699 $info[
'uidnumber'] = $this->id;
3701 $info[
'phpgwTz'] = 0;
3702 $info[
'phpgwMailType'] =
'INTERNET';
3703 $info[
'phpgwMailHomeType'] =
'INTERNET';
3705 $info[
"phpgwContactTypeId"] =
'n';
3706 $info[
"phpgwContactCatId"] = 0;
3707 $info[
"phpgwContactAccess"] =
"public";
3709 $info[
"phpgwContactOwner"] = 1;
3712 $info[
"rfc822Mailbox"] = $this->email;
3714 if ($this->user_mobile) {
3715 $info[
"phpgwCellTelephoneNumber"] = $this->user_mobile;
3724 $groupslist = $usergroup->listGroupsForUser($this->
id);
3726 if (!empty($groupslist)) {
3727 foreach ($groupslist as $groupforuser) {
3756 $this->
ref =
'SPECIMEN';
3757 $this->specimen = 1;
3758 $this->user_creation_id = $user->id;
3760 $this->lastname =
'DOLIBARR';
3761 $this->firstname =
'SPECIMEN';
3762 $this->gender =
'man';
3763 $this->note_public =
'This is a note public';
3764 $this->note_private =
'This is a note private';
3765 $this->
email =
'email@specimen.com';
3766 $this->personal_email =
'personalemail@specimen.com';
3767 $this->socialnetworks = array(
3768 'skype' =>
'skypepseudo',
3769 'twitter' =>
'twitterpseudo',
3770 'facebook' =>
'facebookpseudo',
3771 'linkedin' =>
'linkedinpseudo',
3773 $this->office_phone =
'0999999999';
3774 $this->office_fax =
'0999999998';
3775 $this->user_mobile =
'0999999997';
3776 $this->personal_mobile =
'0999999996';
3778 $this->login =
'dolibspec';
3779 $this->pass =
'dolibSpec+@123';
3782 $this->datec = $now;
3783 $this->datem = $now;
3785 $this->datelastlogin = $now;
3786 $this->iplastlogin =
'127.0.0.1';
3787 $this->datepreviouslogin = $now;
3788 $this->ippreviouslogin =
'127.0.0.1';
3804 $sql =
"SELECT u.rowid, u.login as ref, u.datec, fk_user_creat as user_creation_id, fk_user_modif as user_modification_id,";
3805 $sql .=
" GREATEST(u.tms, uef.tms) as date_modification, u.entity";
3806 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3807 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user_extrafields as uef ON uef.fk_object = u.rowid";
3808 $sql .=
" WHERE u.rowid = ".((int) $id);
3810 $result = $this->db->query($sql);
3812 if ($this->db->num_rows($result)) {
3813 $obj = $this->db->fetch_object($result);
3815 $this->
id = $obj->rowid;
3817 $this->user_creation_id = $obj->user_creation_id;
3818 $this->user_modification_id = $obj->user_modification_id;
3820 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3821 $this->date_creation = $this->db->jdate($obj->datec);
3822 $this->date_modification = $this->db->jdate($obj->date_modification);
3823 $this->entity = $obj->entity;
3826 $this->db->free($result);
3828 dol_print_error($this->db);
3840 $sql =
"SELECT count(mc.email) as nb";
3841 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3842 $sql .=
" WHERE mc.email = '".$this->db->escape($this->
email).
"'";
3843 $sql .=
" AND mc.statut NOT IN (-1,0)";
3845 $resql = $this->db->query($sql);
3847 $obj = $this->db->fetch_object($resql);
3848 $nb = (int) $obj->nb;
3850 $this->db->free($resql);
3853 $this->
error = $this->db->error();
3868 $sql =
"SELECT count(rowid) as nb";
3869 $sql .=
" FROM ".$this->db->prefix().
"user";
3870 if ($option ==
'superadmin') {
3871 $sql .=
" WHERE entity = 0";
3873 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3874 if ($limitTo ==
'active') {
3875 $sql .=
" AND statut = 1";
3879 $sql .=
" AND admin = ".(int) $admin;
3882 $resql = $this->db->query($sql);
3884 $obj = $this->db->fetch_object($resql);
3885 $nb = (int) $obj->nb;
3887 $this->db->free($resql);
3890 $this->
error = $this->db->lasterror();
3911 $this->firstname = $ldapuser->$tmpvar;
3913 $this->lastname = $ldapuser->$tmpvar;
3915 $this->login = $ldapuser->$tmpvar;
3917 $this->pass = $ldapuser->$tmpvar;
3919 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3922 $this->office_phone = $ldapuser->$tmpvar;
3924 $this->user_mobile = $ldapuser->$tmpvar;
3926 $this->office_fax = $ldapuser->$tmpvar;
3928 $this->
email = $ldapuser->$tmpvar;
3929 foreach ($socialnetworks as $key => $value) {
3931 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3934 $this->ldap_sid = $ldapuser->$tmpvar;
3937 $this->job = $ldapuser->$tmpvar;
3939 $this->note_public = $ldapuser->$tmpvar;
3941 $result = $this->
update($user);
3943 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3959 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3960 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3962 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3963 $res = $this->db->query($sql);
3966 while ($rec = $this->db->fetch_array($res)) {
3967 $user =
new User($this->db);
3968 $user->fetch($rec[
'rowid']);
3973 dol_print_error($this->db);
3986 $this->parentof = array();
3989 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3990 $sql .=
" FROM ".$this->db->prefix().
"user";
3991 $sql .=
" WHERE fk_user <> 0";
3992 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3994 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3995 $resql = $this->db->query($sql);
3997 while ($obj = $this->db->fetch_object($resql)) {
3998 $this->parentof[$obj->id_son] = $obj->id_parent;
4002 dol_print_error($this->db);
4024 global $hookmanager;
4027 $hookmanager->initHooks(array(
'userdao'));
4029 $this->users = array();
4035 $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";
4036 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4038 $parameters = array();
4039 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
4041 $sql .= $hookmanager->resPrint;
4043 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4049 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
4050 $resql = $this->db->query($sql);
4053 while ($obj = $this->db->fetch_object($resql)) {
4054 $this->users[(int) $obj->rowid]
4056 'rowid' => (
int) $obj->rowid,
4057 'id' => (int) $obj->rowid,
4058 'fk_user' => (
int) $obj->fk_user,
4059 'fk_soc' => (int) $obj->fk_soc,
4060 'firstname' => (
string) $obj->firstname,
4061 'lastname' => (string) $obj->lastname,
4062 'login' => (
string) $obj->login,
4063 'statut' => (int) $obj->statut,
4064 'entity' => (
int) $obj->entity,
4065 'email' => (string) $obj->email,
4066 'gender' => (
string) $obj->gender,
4067 'admin' => (int) $obj->admin,
4068 'photo' => (
string) $obj->photo,
4077 dol_print_error($this->db);
4082 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
4083 foreach ($this->users as $key => $val) {
4086 $this->
error =
'ErrorLoopInHierarchy';
4092 if ($deleteafterid) {
4094 $keyfilter1 =
'^'.$deleteafterid.
'$';
4095 $keyfilter2 =
'_'.$deleteafterid.
'$';
4096 $keyfilter3 =
'^'.$deleteafterid.
'_';
4097 $keyfilter4 =
'_'.$deleteafterid.
'_';
4098 foreach (array_keys($this->users) as $key) {
4099 $fullpath = (string) $this->users[$key][
'fullpath'];
4100 if (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
4101 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath)) {
4102 unset($this->users[$key]);
4107 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
4108 $this->users =
dol_sort_array($this->users,
'fullname',
'asc', 1, 0, 1);
4110 return $this->users;
4123 $childids = array();
4125 if (isset($this->cache_childids[$this->
id])) {
4126 $childids = $this->cache_childids[$this->id];
4131 $idtoscan = $this->id;
4133 dol_syslog(
"Build childid for id = ".$idtoscan);
4134 foreach ($this->users as $id => $val) {
4135 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
4136 $childids[$val[
'id']] = $val[
'id'];
4143 if ($treeresult < 0) {
4144 dol_syslog(get_class($this).
"::getAllChildIds got a truncated tree: ".$this->
error, LOG_WARNING);
4145 return $addcurrentuser ? array($this->
id => $this->
id) : $childids;
4148 $this->cache_childids[$this->id] = $childids;
4150 if ($addcurrentuser) {
4151 $childids[$this->id] = $this->id;
4171 if (!empty($this->users[$id_user][
'fullpath'])) {
4173 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
4178 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
4179 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
4181 $cursor_user = $id_user;
4183 $useridfound = array($id_user);
4184 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
4185 if (in_array($this->parentof[$cursor_user], $useridfound)) {
4186 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
4189 $useridfound[] = $this->parentof[$cursor_user];
4190 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
4191 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
4193 $cursor_user = $this->parentof[$cursor_user];
4197 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
4246 $this->nb = array();
4248 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
4249 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4251 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
4252 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
4253 $sql .=
" AND ug.fk_user = u.rowid";
4255 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4257 $sql .=
" AND u.statut > 0";
4260 $resql = $this->db->query($sql);
4262 while ($obj = $this->db->fetch_object($resql)) {
4263 $this->nb[
"users"] = $obj->nb;
4265 $this->db->free($resql);
4268 dol_print_error($this->db);
4269 $this->
error = $this->db->error();
4285 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4289 $langs->load(
"user");
4296 $modele =
'bluesky';
4300 $modelpath =
"core/modules/user/doc/";
4302 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4316 $user_property =
'';
4318 if (empty($rowid)) {
4322 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
4323 $sql .=
" FROM ".$this->db->prefix().
"user";
4324 $sql .=
" WHERE rowid = ".((int) $rowid);
4326 $resql = $this->db->query($sql);
4328 $nump = $this->db->num_rows($resql);
4331 $obj = $this->db->fetch_object($resql);
4333 if ($mode ==
'email') {
4334 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
4335 } elseif ($mode ==
'mobile') {
4336 $user_property = $obj->user_mobile;
4337 } elseif ($mode ==
'name') {
4341 return $user_property;
4343 dol_print_error($this->db);
4361 $instanceuniqueid = empty(
$conf->file->instance_unique_id) ?
'' :
$conf->file->instance_unique_id;
4362 $encodedsecurekey =
dol_hash($instanceuniqueid.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
4364 $entity_qr =
'&entity='.((int)
$conf->entity);
4369 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
4370 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
4373 if ($typeofurl ==
'internal') {
4374 $urlwithroot = DOL_URL_ROOT;
4377 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
4393 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $entityfilter =
false)
4395 global $conf, $user;
4397 $sql =
"SELECT t.rowid";
4398 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
4400 if ($entityfilter) {
4402 if (!empty($user->admin) && empty($user->entity) &&
$conf->entity == 1) {
4403 $sql .=
" WHERE t.entity IS NOT NULL";
4405 $sql .=
" WHERE t.entity = 0 OR EXISTS (";
4406 $sql .=
" SELECT ug.rowid FROM " . $this->db->prefix() .
"usergroup_user as ug";
4407 $sql .=
" WHERE ug.fk_user = t.rowid AND ug.entity IN (" .
getEntity(
'usergroup') .
"))";
4410 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
4413 $sql .=
" WHERE 1 = 1";
4419 if ($errormessage) {
4420 $this->errors[] = $errormessage;
4421 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
4425 $sql .= $this->db->order($sortfield, $sortorder);
4427 $sql .= $this->db->plimit($limit + 1, $offset);
4432 $resql = $this->db->query($sql);
4434 $this->users = array();
4435 $num = $this->db->num_rows($resql);
4437 while ($obj = $this->db->fetch_object($resql)) {
4438 $line =
new self($this->db);
4439 $result = $line->fetch($obj->rowid);
4440 if ($result > 0 && !empty($line->id)) {
4441 $this->users[$obj->rowid] = clone $line;
4444 $this->db->free($resql);
4448 $this->errors[] = $this->db->lasterror();
4460 private $findUserIdByEmailCache;
4474 if (isset($this->findUserIdByEmailCache[$email])) {
4475 return $this->findUserIdByEmailCache[$email];
4478 $this->findUserIdByEmailCache[$email] = -1;
4480 $sql =
'SELECT rowid';
4481 $sql .=
' FROM '.$this->db->prefix().
'user';
4482 if (
getDolGlobalString(
'AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR')) {
4483 $sql .=
" WHERE email LIKE '%".$this->db->escape($this->db->escapeforlike($email)).
"%'";
4485 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4489 $resql = $this->db->query($sql);
4494 $obj = $this->db->fetch_object($resql);
4499 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4501 return $this->findUserIdByEmailCache[$email];
4512 if (empty($fromId) || empty($toId)) {
4519 $sqlDelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
4520 $sqlDelete .=
" WHERE fk_user = ".((int) $toId);
4522 dol_syslog(get_class($this).
"::clone_rights (delete default permissions)", LOG_DEBUG);
4524 if (!$this->db->query($sqlDelete)) {
4525 $this->db->rollback();
4530 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id)";
4531 $sql .=
" SELECT entity, ".((int) $toId).
", fk_id";
4532 $sql .=
" FROM ".$this->db->prefix().
"user_rights src";
4533 $sql .=
" WHERE fk_user = ".((int) $fromId);
4534 $sql .=
" AND NOT EXISTS (";
4535 $sql .=
" SELECT 1";
4536 $sql .=
" FROM ".$this->db->prefix().
"user_rights dest";
4537 $sql .=
" WHERE dest.entity = src.entity";
4538 $sql .=
" AND dest.fk_user = ".((int) $toId);
4539 $sql .=
" AND dest.fk_id = src.fk_id";
4542 dol_syslog(get_class($this).
"::clone_rights", LOG_DEBUG);
4545 if (!$this->db->query($sql)) {
4546 $this->db->rollback();
4550 $this->db->commit();
4567 $type = $this->table_element;
4570 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4571 $categorystatic =
new Categorie($this->db);
4573 $sql =
"INSERT INTO ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]).
" (fk_categorie, fk_user)";
4574 $sql .=
" SELECT fk_categorie, ".((int) $toId).
" FROM ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]);
4575 $sql .=
" WHERE fk_user = ".((int) $fromId);
4577 if (!$this->db->query($sql)) {
4578 $this->
error = $this->db->lasterror();
4579 $this->db->rollback();
4583 $this->db->commit();
global $dolibarr_main_url_root
Class to manage members of a foundation.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage categories.
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...
fetchWarehouse($force_warehouse_id=0)
Load the warehouse of object, from id $this->warehouse_id or $this->fk_warehouse, into this->warehous...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
static commonReplaceContact(DoliDB $dbs, $origin_id, $dest_id, array $tables, $fieldname='fk_socpeople', $ignoreerrors=0)
Function used to replace a contact id with another one.
Class to manage Dolibarr database access.
Class to manage warehouses.
static loadAndInstantiate($id, $db, $conf, $langs, $user)
Locate, load and instantiate a password generator/validator model by its id (the value stored in USER...
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage user groups.
Class to manage Dolibarr users.
fetch($id=0, $login='', $sid='', $loadpersonalconf=0, $entity=-1, $email='', $fk_socpeople=0, $use_email_oauth2=0)
Load a user from database with its id or ref (login).
SetInGroup($group, $entity, $notrigger=0)
Add user into a group.
LibStatut($status, $mode=0)
Return the label of a status of user (active, inactive)
loadRights($moduletag='', $forcereload=0)
Load permissions granted to a user->id into object user->rights.
get_children()
Return and array with all instantiated 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.
loadStateBoard()
Load metrics this->nb for dashboard.
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()
Update the user's last login date in the database.
__construct($db)
Constructor of the class.
RemoveFromGroup($group, $entity, $notrigger=0)
Remove a user from a group.
isNotIntoValidityDateRange()
Return a link with photo Use this->id,this->photo.
getNbOfUsers($limitTo, $option='', $admin=-1)
Return number of existing users.
set_default_rights()
Assign rights by default.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND', $entityfilter=false)
Load all objects into $this->users.
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 (optionally with picto)
setCategories($categories)
Sets object to supplied categories.
loadParentOf()
Load this->parentof that is array(id_son=>id_parent, ...)
setForcePasswordChange($user, $value)
Set force password change flag.
fetch_clicktodial()
Read clicktodial information for user.
build_path_from_id_user($id_user, $protection=0)
For user id_user and its children available in this->users, define property fullpath and fullname.
error()
Returns the last functional error when manipulating the object.
cloneCategories($fromId, $toId, $type='user')
Copy related categories to another object.
getAllChildIds($addcurrentuser=0)
Return list of all child user ids in hierarchy (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 optionally the picto) Use this->id,this->lastname,...
clearrights()
Clear all permissions array of user.
update_clicktodial()
Update clicktodial info.
cloneRights($fromId, $toId)
Clone permissions of user.
isExternalUser()
Return if a user is an external user It replaces old syntax: if ($user->socid)
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)
Returns the complete DN (Distinguished Name) string in the LDAP directory for the object.
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.
isAdmin()
Return if a user is an admin user It replaces old syntax: if ($user->admin)
update_ldap2dolibarr(&$ldapuser)
Update user using data from the LDAP.
getrights($moduletag='', $forcereload=0)
Load permissions granted to a user->id into object user->rights TODO Remove this method.
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 clickable link of object (optionally with 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.
loadPersonalConf($entity=-1)
Load const values from database table user_param and set it into user->conf->XXX.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
findUserIdByEmail($email)
Find a user by the given e-mail and return it's user id when found.
getTooltipContentArray($params)
getTooltipContentArray
static replaceContact(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a contact id with another one when merging two contacts.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
if(! $sortfield) if(! $sortorder) $module
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
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...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
dol_now($mode='gmt')
Return date for now.
getDolGlobalLoginBadCharUnauthorized()
Return the list of unauthorized characters in user logins.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
getArrayOfSocialNetworks()
Get array of social network dictionary.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
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.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
div refaddress div address
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
conf($dolibarr_main_document_root, $realpathconf=null)
Load conf file (file must exists)
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dolGetLdapPasswordHash($password, $type='md5')
Returns a specific ldap hash of a password.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.
dol_verifyHash($chain, $hash, $type='0')
Compute a hash and compare it to the given one For backward compatibility reasons,...
dolEncrypt($chain, $key='', $ciphering='', $forceseed='', $obfuscationmode='dolcrypt')
Encode a string with a symmetric encryption.