40require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/commonpeople.class.php';
56 public $element =
'user';
61 public $table_element =
'user';
66 public $fk_element =
'fk_user';
71 public $picto =
'user';
110 public $civility_code;
135 public $email_oauth2;
140 public $personal_email;
145 public $socialnetworks;
160 public $office_phone;
175 public $personal_mobile;
200 public $pass_crypted;
205 public $pass_indatabase;
210 public $pass_indatabase_crypted;
220 public $force_pass_change = 0;
259 public $fk_user_expense_validator;
264 public $fk_user_holiday_validator;
269 public $clicktodial_url;
274 public $clicktodial_login;
279 public $clicktodial_password;
284 public $clicktodial_poste;
289 public $clicktodial_loaded;
295 public $datelastpassvalidation;
299 public $datelastlogin;
303 public $datepreviouslogin;
307 public $flagdelsessionsbefore;
315 public $ippreviouslogin;
319 public $datestartvalidity;
323 public $dateendvalidity;
343 public $all_permissions_are_loaded;
353 public $user_group_list;
358 private $_tab_loaded = array();
368 public $default_values;
373 public $lastsearch_values_tmp;
377 public $lastsearch_values;
382 public $users = array();
390 private $cache_childids;
396 public $accountancy_code_user_general;
401 public $accountancy_code;
433 public $dateemployment;
437 public $dateemploymentend;
442 public $default_c_exp_tax_cat;
447 public $ref_employee;
452 public $national_registration_number;
457 public $default_range;
462 public $fk_warehouse;
467 public $fk_establishment;
472 public $label_establishment;
478 public $usergroup_entity;
480 public $fields = array(
481 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
482 'lastname' => array(
'type' =>
'varchar(50)',
'label' =>
'Lastname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 20,
'searchall' => 1),
483 'firstname' => array(
'type' =>
'varchar(50)',
'label' =>
'Firstname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 10,
'searchall' => 1),
484 'ref_employee' => array(
'type' =>
'varchar(50)',
'label' =>
'RefEmployee',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 30,
'searchall' => 1),
485 'national_registration_number' => array(
'type' =>
'varchar(50)',
'label' =>
'NationalRegistrationNumber',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 40,
'searchall' => 1)
488 const STATUS_DISABLED = 0;
489 const STATUS_ENABLED = 1;
500 $this->ismultientitymanaged = 1;
501 $this->isextrafieldmanaged = 1;
503 $this->clicktodial_loaded = 0;
506 $this->all_permissions_are_loaded = 0;
507 $this->nb_rights = 0;
515 $this->rights->user =
new stdClass();
516 $this->rights->user->user =
new stdClass();
517 $this->rights->user->self =
new stdClass();
518 $this->rights->user->user_advance =
new stdClass();
519 $this->rights->user->self_advance =
new stdClass();
520 $this->rights->user->group_advance =
new stdClass();
537 public function fetch($id = 0, $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'', $fk_socpeople = 0, $use_email_oauth2 = 0)
542 $login = trim($login);
545 $sql =
"SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.civility as civility_code, u.birth, u.job,";
546 $sql .=
" u.email, u.email_oauth2, u.personal_email,";
547 $sql .=
" u.socialnetworks,";
548 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
549 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
550 $sql .=
" u.admin, u.login, u.note_private, u.note_public,";
551 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.force_pass_change, u.api_key,";
552 $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,";
553 $sql .=
" fk_user_creat as user_creation_id, fk_user_modif as user_modification_id,";
554 $sql .=
" u.statut as status, u.lang, u.entity,";
555 $sql .=
" u.datec as datec,";
556 $sql .=
" GREATEST(u.tms, uef.tms) as datem,";
557 $sql .=
" u.datelastlogin as datel,";
558 $sql .=
" u.datepreviouslogin as datep,";
559 $sql .=
" u.flagdelsessionsbefore,";
560 $sql .=
" u.iplastlogin,";
561 $sql .=
" u.ippreviouslogin,";
562 $sql .=
" u.datelastpassvalidation,";
563 $sql .=
" u.datestartvalidity,";
564 $sql .=
" u.dateendvalidity,";
565 $sql .=
" u.photo as photo,";
566 $sql .=
" u.openid as openid,";
567 $sql .=
" u.accountancy_code_user_general,";
568 $sql .=
" u.accountancy_code,";
571 $sql .=
" u.salary,";
572 $sql .=
" u.salaryextra,";
573 $sql .=
" u.weeklyhours,";
575 $sql .=
" u.dateemployment, u.dateemploymentend,";
576 $sql .=
" u.fk_warehouse,";
577 $sql .=
" u.ref_ext,";
578 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
579 $sql .=
" u.national_registration_number,";
580 $sql .=
" u.ref_employee,";
581 $sql .=
" c.code as country_code, c.label as country,";
582 $sql .=
" d.code_departement as state_code, d.nom as state,";
583 $sql .=
" s.label as label_establishment, u.fk_establishment";
584 $sql .=
" FROM ".$this->db->prefix().
"user as u";
585 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user_extrafields as uef ON uef.fk_object = u.rowid";
586 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as c ON u.fk_country = c.rowid";
587 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_departements as d ON u.fk_state = d.rowid";
588 $sql .=
" LEFT JOIN ".$this->db->prefix().
"establishment as s ON u.fk_establishment = s.rowid";
591 $sql .=
" WHERE u.rowid = ".((int) $id);
595 $sql .=
" WHERE u.entity IN (0, " . ((int)
$conf->entity) .
")";
597 $sql .=
" WHERE u.entity IS NOT NULL";
602 $sql .=
" WHERE u.entity IS NOT NULL";
604 if ($entity !=
'' && $entity == 0) {
605 $sql .=
" WHERE u.entity = 0";
607 $sql .=
" WHERE u.entity IN (0, " . ((int) ($entity > 0 ? $entity :
$conf->entity)) .
")";
615 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->db->escape($login).
"')";
617 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
619 $sql .=
" AND (u.email = '".$this->db->escape($email).
"'";
620 if ($use_email_oauth2) {
621 $sql .=
" OR u.email_oauth2 = '".$this->db->escape($email).
"'";
624 } elseif ($fk_socpeople > 0) {
625 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
628 $sql .=
" ORDER BY u.entity ASC";
632 $sql .=
' '.$this->db->plimit(1);
635 $resql = $this->db->query($sql);
637 $num = $this->db->num_rows($resql);
639 $this->
error =
"USERDUPLICATEFOUND";
640 dol_syslog(get_class($this).
"::fetch more than 1 user found", LOG_WARNING);
642 $this->db->free($resql);
646 $obj = $this->db->fetch_object($resql);
648 $this->
id = $obj->rowid;
649 $this->
ref = $obj->rowid;
651 $this->ref_ext = $obj->ref_ext;
653 $this->ldap_sid = $obj->ldap_sid;
654 $this->civility_code = $obj->civility_code;
655 $this->lastname = $obj->lastname;
656 $this->firstname = $obj->firstname;
657 $this->ref_employee = $obj->ref_employee;
658 $this->national_registration_number = $obj->national_registration_number;
660 $this->employee = $obj->employee;
662 $this->login = $obj->login;
663 $this->gender = $obj->gender;
664 $this->birth = $this->db->jdate($obj->birth);
665 $this->pass_indatabase = $obj->pass;
666 $this->pass_indatabase_crypted = $obj->pass_crypted;
667 $this->pass = $obj->pass;
668 $this->pass_temp = $obj->pass_temp;
669 $this->force_pass_change = $obj->force_pass_change;
670 $this->datelastpassvalidation = $obj->datelastpassvalidation;
673 $this->
address = $obj->address;
674 $this->zip = $obj->zip;
675 $this->town = $obj->town;
677 $this->country_id = $obj->country_id;
678 $this->country_code = $obj->country_id ? $obj->country_code :
'';
681 $this->state_id = $obj->state_id;
682 $this->state_code = $obj->state_code;
683 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
685 $this->office_phone = $obj->office_phone;
686 $this->office_fax = $obj->office_fax;
687 $this->user_mobile = $obj->user_mobile;
688 $this->personal_mobile = $obj->personal_mobile;
689 $this->
email = $obj->email;
690 $this->email_oauth2 = $obj->email_oauth2;
691 $this->personal_email = $obj->personal_email;
692 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
693 $this->user_creation_id = $obj->user_creation_id;
694 $this->user_modification_id = $obj->user_modification_id;
696 $this->job = $obj->job;
697 $this->signature = $obj->signature;
698 $this->admin = $obj->admin;
699 $this->note_public = $obj->note_public;
700 $this->note_private = $obj->note_private;
702 $this->statut = $obj->status;
703 $this->
status = $obj->status;
705 $this->photo = $obj->photo;
706 $this->openid = $obj->openid;
707 $this->lang = $obj->lang;
708 $this->entity = $obj->entity;
710 $this->accountancy_code_user_general = $obj->accountancy_code_user_general;
711 $this->accountancy_code = $obj->accountancy_code;
713 $this->thm = $obj->thm;
714 $this->tjm = $obj->tjm;
715 $this->salary = $obj->salary;
716 $this->salaryextra = $obj->salaryextra;
717 $this->weeklyhours = $obj->weeklyhours;
718 $this->color = $obj->color;
719 $this->dateemployment = $this->db->jdate($obj->dateemployment);
720 $this->dateemploymentend = $this->db->jdate($obj->dateemploymentend);
722 $this->datec = $this->db->jdate($obj->datec);
723 $this->datem = $this->db->jdate($obj->datem);
724 $this->datelastlogin = $this->db->jdate($obj->datel);
725 $this->datepreviouslogin = $this->db->jdate($obj->datep);
726 $this->flagdelsessionsbefore = $this->db->jdate($obj->flagdelsessionsbefore,
'gmt');
727 $this->iplastlogin = $obj->iplastlogin;
728 $this->ippreviouslogin = $obj->ippreviouslogin;
729 $this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
730 $this->dateendvalidity = $this->db->jdate($obj->dateendvalidity);
732 $this->socid = $obj->fk_soc;
733 $this->contact_id = $obj->fk_socpeople;
734 $this->fk_member = $obj->fk_member;
735 $this->fk_user = $obj->fk_user;
736 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
737 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
739 $this->default_range = $obj->default_range;
740 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
741 $this->fk_warehouse = $obj->fk_warehouse;
742 $this->fk_establishment = $obj->fk_establishment;
743 $this->label_establishment = $obj->label_establishment;
747 if (!
isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
755 $this->db->free($resql);
757 $this->
error =
"USERNOTFOUND";
758 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
760 $this->db->free($resql);
764 $this->
error = $this->db->lasterror();
769 if ($loadpersonalconf) {
775 $this->
error = $this->db->lasterror();
782 if (
GETPOSTINT(
'forceexternaluser') && $this->admin && empty($this->socid)) {
783 $this->socid =
GETPOSTINT(
'forceexternaluser');
801 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
802 $sql .=
" WHERE fk_user = ".((int) $this->
id);
804 $sql .=
" AND entity IN (0, ".((int)
$conf->entity).
")";
806 $sql .=
" AND entity = ".((int) $entity);
810 $resql = $this->db->query($sql);
812 $num = $this->db->num_rows($resql);
815 $obj = $this->db->fetch_object($resql);
816 $p = (!empty($obj->param) ? $obj->param :
'');
818 $this->
conf->$p = $obj->value;
822 $this->db->free($resql);
826 $this->
error = $this->db->lasterror();
843 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
846 $result = $defaultValues->fetchAll(
'',
'', 0, 0,
'(t.user_id:in:0,'.$this->
id.
') AND (entity:in:'.(isset($this->entity) ? $this->entity :
$conf->entity).
','.
$conf->entity.
')');
849 if (!is_array($result) && $result < 0) {
853 } elseif (count($result) > 0) {
854 foreach ($result as $defval) {
855 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
856 $pagewithoutquerystring = $defval->page;
859 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
860 $pagewithoutquerystring = $reg[1];
861 $pagequeries = $reg[2];
863 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
867 if (!empty($this->default_values)) {
868 foreach ($this->default_values as $a => $b) {
869 foreach ($b as
$c => $d) {
870 krsort($this->default_values[$a][
$c]);
911 public function hasRight($module, $permlevel1, $permlevel2 =
'')
914 $moduletomoduletouse = array(
915 'category' =>
'categorie',
916 'compta' =>
'comptabilite',
917 'contract' =>
'contrat',
918 'member' =>
'adherent',
920 'order' =>
'commande',
921 'produit' =>
'product',
922 'productlot' =>
'product',
923 'project' =>
'projet',
924 'propale' =>
'propal',
925 'shipping' =>
'expedition',
926 'task' =>
'task@projet',
927 'fichinter' =>
'ficheinter',
928 'intervention' =>
'ficheinter',
929 'inventory' =>
'stock',
930 'invoice' =>
'facture',
931 'invoice_supplier' =>
'facture@fournisseur',
932 'order_supplier' =>
'fournisseur',
933 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
934 'skill@hrm' =>
'all@hrm',
935 'job@hrm' =>
'all@hrm',
936 'position@hrm' =>
'all@hrm',
937 'facturerec' =>
'facture',
938 'margins' =>
'margin',
941 if (!empty($moduletomoduletouse[$module])) {
942 $module = $moduletomoduletouse[$module];
953 $supplierNewToLegacy = array(
954 'supplier_order' => array(
'fournisseur',
'commande'),
955 'supplier_invoice' => array(
'fournisseur',
'facture'),
958 if (isset($supplierNewToLegacy[$module])) {
961 $permlevel2 = $permlevel1;
962 $permlevel1 = $supplierNewToLegacy[$module][1];
963 $module = $supplierNewToLegacy[$module][0];
968 $supplierLegacyCompat = array(
969 'supplier_order' =>
'fournisseur',
970 'supplier_invoice' =>
'fournisseur',
973 if (isset($supplierLegacyCompat[$module])) {
975 $module = $supplierLegacyCompat[$module];
979 $moduleRightsMapping = array(
980 'product' =>
'produit',
981 'margin' =>
'margins',
982 'comptabilite' =>
'compta'
985 $rightsPath = $module;
986 if (!empty($moduleRightsMapping[$rightsPath])) {
987 $rightsPath = $moduleRightsMapping[$rightsPath];
991 $tmp = explode(
'@', $rightsPath, 2);
992 if (!empty($tmp[1])) {
993 if (strpos($module,
'@') !==
false) {
996 if ($tmp[0] != $tmp[1]) {
998 $rightsPath = $tmp[1];
999 $permlevel2 = $permlevel1;
1000 $permlevel1 = $tmp[0];
1003 $rightsPath = $tmp[1];
1018 if (!empty($this->socid)) {
1019 if ($module ==
'societe' && ($permlevel1 ==
'creer' || $permlevel1 ==
'write')) {
1022 if ($module ==
'societe' && $permlevel1 ==
'client' && $permlevel2 ==
'voir') {
1025 if ($module ==
'societe' && $permlevel1 ==
'export') {
1028 if ($module ==
'societe' && ($permlevel1 ==
'supprimer' || $permlevel1 ==
'delete')) {
1034 if ($permlevel1 ==
'propale') {
1035 $permlevel1 =
'propal';
1037 if ($permlevel1 ==
'member') {
1038 $permlevel1 =
'adherent';
1040 if ($permlevel1 ==
'recruitmentcandidature') {
1041 $permlevel1 =
'recruitmentjobposition';
1046 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
1051 if (!empty($this->rights->$rightsPath->$permlevel1)) {
1052 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
1053 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
1057 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
1058 return $this->rights->$rightsPath->$permlevel1->lire;
1060 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
1061 return $this->rights->$rightsPath->$permlevel1->creer;
1063 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
1064 return $this->rights->$rightsPath->$permlevel1->create;
1066 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
1067 return $this->rights->$rightsPath->$permlevel1->supprimer;
1071 if (!empty($this->rights->$rightsPath->$permlevel1)) {
1072 return $this->rights->$rightsPath->$permlevel1;
1076 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
1077 return $this->rights->$rightsPath->lire;
1079 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
1080 return $this->rights->$rightsPath->creer;
1082 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
1083 return $this->rights->$rightsPath->create;
1085 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
1086 return $this->rights->$rightsPath->supprimer;
1104 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1106 global $conf, $user, $langs;
1108 $entity = (empty($entity) ?
$conf->entity : $entity);
1110 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
1112 if (empty($this->
id)) {
1113 $this->
error =
'Try to call addrights on an object user with an empty id';
1123 $module = $perms = $subperms =
'';
1126 $sql =
"SELECT module, perms, subperms";
1127 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1128 $sql .=
" WHERE id = ".((int) $rid);
1129 $sql .=
" AND entity = ".((int) $entity);
1131 $result = $this->db->query($sql);
1133 $obj = $this->db->fetch_object($result);
1136 $module = $obj->module;
1137 $perms = $obj->perms;
1138 $subperms = $obj->subperms;
1146 $whereforadd =
"id=".((int) $rid);
1148 if (!empty($subperms)) {
1149 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
1150 } elseif (!empty($perms)) {
1151 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND (subperms IS NULL or subperms = ''))";
1157 if (!empty($allmodule)) {
1158 if ($allmodule ==
'allmodules') {
1159 $whereforadd =
'allmodules';
1161 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
1162 if (!empty($allperms)) {
1163 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
1171 if (!empty($whereforadd)) {
1174 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1175 $sql .=
" WHERE entity = ".((int) $entity);
1176 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
1177 $sql .=
" AND (".$whereforadd.
")";
1180 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1181 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1183 $sqldelete .=
") AND entity = ".((int) $entity);
1184 if (!$this->db->query($sqldelete)) {
1189 $resql = $this->db->query($sql);
1191 $num = $this->db->num_rows($resql);
1194 $obj = $this->db->fetch_object($resql);
1199 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
1200 if (!$this->db->query($sql)) {
1214 if (!$error && !$notrigger) {
1215 $langs->load(
"other");
1216 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
1219 $result = $this->call_trigger(
'USER_MODIFY', $user);
1227 $this->db->rollback();
1230 $this->db->commit();
1247 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1249 global $conf, $user, $langs;
1253 $entity = (!empty($entity) ? $entity :
$conf->entity);
1258 $module = $perms = $subperms =
'';
1262 $sql =
"SELECT module, perms, subperms";
1263 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1264 $sql .=
" WHERE id = '".((int) $rid).
"'";
1265 $sql .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1267 $result = $this->db->query($sql);
1269 $obj = $this->db->fetch_object($result);
1272 $module = $obj->module;
1273 $perms = $obj->perms;
1274 $subperms = $obj->subperms;
1282 $wherefordel =
"id=".((int) $rid);
1284 if ($subperms ==
'lire' || $subperms ==
'read') {
1285 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1287 if ($perms ==
'lire' || $perms ==
'read') {
1288 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1294 if (!empty($allmodule)) {
1295 if ($allmodule ==
'allmodules') {
1296 $wherefordel =
'allmodules';
1298 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1299 if (!empty($allperms)) {
1300 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1307 if (!empty($wherefordel)) {
1310 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1311 $sql .=
" WHERE entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1312 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1313 $sql .=
" AND (".$wherefordel.
")";
1317 if ($this->admin == 1) {
1318 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1319 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1320 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1321 $sql .=
" AND id NOT IN (358)";
1324 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1325 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1328 $sqldelete .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1330 $resql = $this->db->query($sqldelete);
1337 if (!$error && !$notrigger) {
1338 $langs->load(
"other");
1339 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1342 $result = $this->call_trigger(
'USER_MODIFY', $user);
1350 $this->db->rollback();
1353 $this->db->commit();
1367 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1369 $this->nb_rights = 0;
1370 $this->all_permissions_are_loaded = 0;
1371 $this->_tab_loaded = array();
1387 $alreadyloaded =
false;
1389 if (empty($forcereload)) {
1390 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1392 $alreadyloaded =
true;
1395 if (!empty($this->all_permissions_are_loaded)) {
1397 $alreadyloaded =
true;
1402 if (!isset($this->rights) || !is_object($this->rights)) {
1405 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1406 $this->rights->user =
new stdClass();
1411 if (!$alreadyloaded) {
1413 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1414 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1415 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1416 $sql .=
" WHERE r.id = ur.fk_id";
1422 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') ?
"1," :
"").
$conf->entity.
")";
1426 $sql .=
" AND r.entity = ".((int)
$conf->entity).
" AND ur.entity = ".((int)
$conf->entity);
1428 $sql .=
" AND ur.fk_user = ".((int) $this->
id);
1429 $sql .=
" AND r.perms IS NOT NULL";
1431 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1434 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1437 $resql = $this->db->query($sql);
1439 $num = $this->db->num_rows($resql);
1442 $obj = $this->db->fetch_object($resql);
1445 $module = $obj->module;
1446 $perms = $obj->perms;
1447 $subperms = $obj->subperms;
1449 if (!empty($perms)) {
1450 if (!empty($module)) {
1451 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1452 $this->rights->$module =
new stdClass();
1454 if (!empty($subperms)) {
1455 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1456 $this->rights->$module->$perms =
new stdClass();
1458 if (empty($this->rights->$module->$perms->$subperms)) {
1461 $this->rights->$module->$perms->$subperms = 1;
1463 if (empty($this->rights->$module->$perms)) {
1466 $this->rights->$module->$perms = 1;
1473 $this->db->free($resql);
1477 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms, r.entity";
1478 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1479 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1480 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1481 $sql .=
" WHERE r.id = gr.fk_id";
1487 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1489 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1492 $sql .=
" AND gr.entity = ".((int)
$conf->entity);
1496 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1497 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1500 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1501 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1502 $sql .=
" AND r.perms IS NOT NULL";
1504 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1507 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1510 $resql = $this->db->query($sql);
1512 $num = $this->db->num_rows($resql);
1515 $obj = $this->db->fetch_object($resql);
1518 $module = $obj->module;
1519 $perms = $obj->perms;
1520 $subperms = $obj->subperms;
1522 if (!empty($perms)) {
1523 if (!empty($module)) {
1524 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1525 $this->rights->$module =
new stdClass();
1527 if (!empty($subperms)) {
1528 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1529 $this->rights->$module->$perms =
new stdClass();
1531 if (empty($this->rights->$module->$perms->$subperms)) {
1534 $this->rights->$module->$perms->$subperms = 1;
1537 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1538 if (empty($this->rights->$module->$perms)) {
1541 $this->rights->$module->$perms = 1;
1549 $this->db->free($resql);
1553 if (!empty($this->admin)) {
1554 if (empty($this->rights->user->user)) {
1555 $this->rights->user->user =
new stdClass();
1557 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1558 foreach ($listofpermtotest as $permtotest) {
1559 if (empty($this->rights->user->user->$permtotest)) {
1560 $this->rights->user->user->$permtotest = 1;
1564 if (empty($this->rights->user->self)) {
1565 $this->rights->user->self =
new stdClass();
1567 $listofpermtotest = array(
'creer',
'password');
1568 foreach ($listofpermtotest as $permtotest) {
1569 if (empty($this->rights->user->self->$permtotest)) {
1570 $this->rights->user->self->$permtotest = 1;
1576 if (empty($this->rights->user->user_advance)) {
1577 $this->rights->user->user_advance =
new stdClass();
1579 $listofpermtotest = array(
'readperms',
'write');
1580 foreach ($listofpermtotest as $permtotest) {
1581 if (empty($this->rights->user->user_advance->$permtotest)) {
1582 $this->rights->user->user_advance->$permtotest = 1;
1586 if (empty($this->rights->user->self_advance)) {
1587 $this->rights->user->self_advance =
new stdClass();
1589 $listofpermtotest = array(
'readperms',
'writeperms');
1590 foreach ($listofpermtotest as $permtotest) {
1591 if (empty($this->rights->user->self_advance->$permtotest)) {
1592 $this->rights->user->self_advance->$permtotest = 1;
1596 if (empty($this->rights->user->group_advance)) {
1597 $this->rights->user->group_advance =
new stdClass();
1599 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1600 foreach ($listofpermtotest as $permtotest) {
1601 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1602 $this->rights->user->group_advance->$permtotest = 1;
1610 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1611 $this->rights->propal = $this->rights->propale;
1613 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1614 $this->rights->propale = $this->rights->propal;
1621 $this->all_permissions_are_loaded = 1;
1624 $this->_tab_loaded[$moduletag] = 1;
1641 public function getrights($moduletag =
'', $forcereload = 0)
1654 global $conf, $langs, $user;
1659 if (isset($this->statut)) {
1660 if ($this->statut == $status) {
1663 } elseif (isset($this->
status) && $this->
status == $status) {
1670 $sql =
"UPDATE ".$this->db->prefix().
"user";
1671 $sql .=
" SET statut = ".((int) $status);
1672 $sql .=
" WHERE rowid = ".((int) $this->
id);
1673 $result = $this->db->query($sql);
1675 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1678 $this->context[
'actionmsg'] =
'User '.$this->login.
' disabled';
1680 $this->context[
'actionmsg'] =
'User '.$this->login.
' enabled';
1683 $result = $this->call_trigger(
'USER_ENABLEDISABLE', $user);
1691 $this->db->rollback();
1695 $this->statut = $status;
1696 $this->db->commit();
1712 $value = (int) $value;
1715 if ($this->force_pass_change == $value) {
1722 $sql =
"UPDATE ".$this->db->prefix().
"user";
1723 $sql .=
" SET force_pass_change = ".((int) $value);
1724 $sql .=
" WHERE rowid = ".((int) $this->
id);
1725 $result = $this->db->query($sql);
1727 dol_syslog(get_class($this).
"::setForcePasswordChange", LOG_DEBUG);
1729 $this->force_pass_change = $value;
1731 $result = $this->call_trigger(
'USER_MODIFY', $user);
1738 $this->
error = $this->db->lasterror();
1742 $this->db->rollback();
1745 $this->db->commit();
1762 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1763 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1778 $this->
fetch($this->
id);
1780 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1783 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1785 if (!$error && !$this->db->query($sql)) {
1787 $this->
error = $this->db->lasterror();
1791 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1792 if (!$error && !$this->db->query($sql)) {
1794 $this->
error = $this->db->lasterror();
1798 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1799 if (!$error && !$this->db->query($sql)) {
1801 $this->
error = $this->db->lasterror();
1805 if ($this->contact_id > 0) {
1806 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1807 if (!$error && !$this->db->query($sql)) {
1809 $this->
error = $this->db->lasterror();
1818 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1824 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1825 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1826 if (!$this->db->query($sql)) {
1828 $this->
error = $this->db->lasterror();
1834 $result = $this->call_trigger(
'USER_DELETE', $user);
1837 $this->db->rollback();
1842 $this->db->commit();
1845 $this->db->rollback();
1857 public function create($user, $notrigger = 0)
1859 global $conf, $langs;
1865 $this->civility_code = trim((
string) $this->civility_code);
1866 $this->login = trim((
string) $this->login);
1867 $this->user_creation_id = (int) $user->id;
1868 if (!isset($this->entity)) {
1869 $this->entity =
$conf->entity;
1871 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1877 $langs->load(
"errors");
1878 $this->
error = $langs->trans(
"ErrorBadEMail", $this->
email);
1881 if (empty($this->login)) {
1882 $langs->load(
"errors");
1883 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1885 } elseif ($badCharUnauthorizedIntoLoginName !==
'' && preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1886 $langs->load(
"errors");
1887 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1898 $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).
"'";
1899 $resqltochecklogin = $this->db->query($sqltochecklogin);
1900 if ($resqltochecklogin) {
1901 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1902 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1903 $langs->load(
"errors");
1904 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1906 $this->db->rollback();
1909 $this->db->free($resqltochecklogin);
1912 if (!empty($this->
email)) {
1913 $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).
"'";
1914 $resqltochecklogin = $this->db->query($sqltochecklogin);
1915 if ($resqltochecklogin) {
1916 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1917 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1918 $langs->load(
"errors");
1919 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->
email);
1921 $this->db->rollback();
1924 $this->db->free($resqltochecklogin);
1929 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, fk_user_creat, entity)";
1930 $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).
")";
1931 $result = $this->db->query($sql);
1933 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1935 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1939 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1940 $this->db->rollback();
1945 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1946 $langs->load(
"stocks");
1948 $entrepot =
new Entrepot($this->db);
1949 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1950 $entrepot->libelle = $entrepot->label;
1951 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1952 $entrepot->statut = 1;
1953 $entrepot->country_id =
$mysoc->country_id;
1955 $warehouseid = $entrepot->create($user);
1957 $this->fk_warehouse = $warehouseid;
1961 $result = $this->
update($user, 1, 1);
1963 $this->db->rollback();
1969 $result = $this->call_trigger(
'USER_CREATE', $user);
1977 $this->db->commit();
1982 $this->db->rollback();
1986 $this->
error = $this->db->lasterror();
1987 $this->db->rollback();
2011 $this->civility_code = $contact->civility_code;
2012 $this->lastname = $contact->lastname;
2013 $this->firstname = $contact->firstname;
2015 $this->
email = $contact->email;
2016 $this->socialnetworks = $contact->socialnetworks;
2017 $this->office_phone = $contact->phone_pro;
2018 $this->office_fax = $contact->fax;
2019 $this->user_mobile = $contact->phone_mobile;
2020 $this->
address = $contact->address;
2021 $this->zip = $contact->zip;
2022 $this->town = $contact->town;
2024 $this->state_id = $contact->state_id;
2025 $this->country_id = $contact->country_id;
2026 $this->employee = 0;
2028 if (empty($login)) {
2029 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
2030 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
2032 $this->login = $login;
2037 $result = $this->
create($user, 1);
2039 $sql =
"UPDATE ".$this->db->prefix().
"user";
2040 $sql .=
" SET fk_socpeople=".((int) $contact->id);
2041 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
2042 if ($contact->socid > 0) {
2043 $sql .=
", fk_soc=".((int) $contact->socid);
2045 $sql .=
" WHERE rowid=".((int) $this->
id);
2047 $resql = $this->db->query($sql);
2049 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
2051 $this->context[
'createfromcontact'] =
'createfromcontact';
2054 $result = $this->call_trigger(
'USER_CREATE', $user);
2057 $this->db->rollback();
2062 $this->db->commit();
2065 $this->
error = $this->db->error();
2067 $this->db->rollback();
2072 dol_syslog(get_class($this).
"::create_from_contact - 0");
2074 $this->db->rollback();
2095 $this->civility_code = $member->civility_code;
2096 $this->lastname = $member->lastname;
2097 $this->firstname = $member->firstname;
2098 $this->gender = $member->gender;
2099 $this->
email = $member->email;
2100 $this->fk_member = $member->id;
2101 $this->
address = $member->address;
2102 $this->zip = $member->zip;
2103 $this->town = $member->town;
2105 $this->state_id = $member->state_id;
2106 $this->country_id = $member->country_id;
2107 $this->socialnetworks = $member->socialnetworks;
2109 $this->pass = $member->pass;
2110 $this->pass_crypted = $member->pass_indatabase_crypted;
2112 if (empty($login)) {
2113 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
2116 $this->login = $login;
2121 $result = $this->
create($user);
2123 if (!empty($this->pass)) {
2124 $newpass = $this->
setPassword($user, $this->pass);
2125 if (is_int($newpass) && $newpass < 0) {
2128 } elseif (!empty($this->pass_crypted)) {
2129 $sql =
"UPDATE ".$this->db->prefix().
"user";
2130 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
2131 $sql .=
" WHERE rowid=".((int) $this->
id);
2133 $resql = $this->db->query($sql);
2139 if ($result > 0 && $member->socid) {
2140 $sql =
"UPDATE ".$this->db->prefix().
"user";
2141 $sql .=
" SET fk_soc=".((int) $member->socid);
2142 $sql .=
" WHERE rowid=".((int) $this->
id);
2144 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
2145 $resql = $this->db->query($sql);
2147 $this->db->commit();
2150 $this->
error = $this->db->lasterror();
2152 $this->db->rollback();
2159 $this->db->commit();
2163 $this->db->rollback();
2181 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
2182 $sql .=
" WHERE bydefault = 1";
2183 $sql .=
" AND entity = ".((int)
$conf->entity);
2185 $resql = $this->db->query($sql);
2187 $num = $this->db->num_rows($resql);
2190 $row = $this->db->fetch_row($resql);
2194 $this->db->free($resql);
2198 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
2199 $result = $this->db->query($sql);
2201 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
2202 $result = $this->db->query($sql);
2222 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
2226 if (empty($this->country_id) && !empty($this->country_code)) {
2227 $country_id =
getCountry($this->country_code,
'3');
2228 $this->country_id = is_int($country_id) ? $country_id : 0;
2231 $nbrowsaffected = 0;
2234 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
2237 $this->civility_code = trim((
string) $this->civility_code);
2238 $this->lastname = trim((
string) $this->lastname);
2239 $this->firstname = trim((
string) $this->firstname);
2240 $this->ref_employee = trim((
string) $this->ref_employee);
2241 $this->national_registration_number = trim((
string) $this->national_registration_number);
2242 $this->employee = ($this->employee > 0 ? $this->employee : 0);
2243 $this->login = trim((
string) $this->login);
2244 $this->gender = trim((
string) $this->gender);
2246 $this->pass = trim((
string) $this->pass);
2247 $this->api_key = trim((
string) $this->api_key);
2248 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
2249 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
2252 $this->zip = trim((
string) $this->zip);
2253 $this->town = trim((
string) $this->town);
2255 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
2256 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
2257 $this->office_phone = trim((
string) $this->office_phone);
2258 $this->office_fax = trim((
string) $this->office_fax);
2259 $this->user_mobile = trim((
string) $this->user_mobile);
2260 $this->personal_mobile = trim((
string) $this->personal_mobile);
2262 $this->personal_email = trim((
string) $this->personal_email);
2264 $this->job = trim((
string) $this->job);
2265 $this->signature = trim((
string) $this->signature);
2266 $this->note_public = trim((
string) $this->note_public);
2267 $this->note_private = trim((
string) $this->note_private);
2268 $this->openid = trim((
string) $this->openid);
2269 $this->admin = ($this->admin > 0 ? $this->admin : 0);
2270 $this->user_modification_id = $user->id;
2272 $this->accountancy_code_user_general = trim((
string) $this->accountancy_code_user_general);
2273 $this->accountancy_code = trim((
string) $this->accountancy_code);
2274 $this->color = trim(str_replace(
'#',
'', (
string) $this->color));
2275 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
2276 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
2278 $this->birth = empty($this->birth) ?
'' : $this->birth;
2279 $this->fk_warehouse = (int) $this->fk_warehouse;
2280 $this->fk_establishment = (int) $this->fk_establishment;
2288 $langs->load(
"errors");
2289 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
2292 if (empty($this->login)) {
2293 $langs->load(
"errors");
2294 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
2296 } elseif ($badCharUnauthorizedIntoLoginName !==
'' && preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
2297 $langs->load(
"errors");
2298 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
2305 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->oldcopy->login != $this->login) {
2306 $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).
"'";
2307 $resqltochecklogin = $this->db->query($sqltochecklogin);
2308 if ($resqltochecklogin) {
2309 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2310 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2311 $langs->load(
"errors");
2312 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
2314 $this->db->rollback();
2319 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && !empty($this->email) && $this->oldcopy->email != $this->email) {
2320 $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).
"'";
2321 $resqltochecklogin = $this->db->query($sqltochecklogin);
2322 if ($resqltochecklogin) {
2323 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2324 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2325 $langs->load(
"errors");
2326 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
2328 $this->db->rollback();
2335 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2336 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
2337 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
2338 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
2339 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
2340 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
2341 $sql .=
", employee = ".(int) $this->employee;
2342 $sql .=
", login = '".$this->db->escape($this->login).
"'";
2343 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
2344 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
2345 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
2346 if (!empty($user->admin)) {
2347 $sql .=
", admin = ".(int) $this->admin;
2349 $sql .=
", address = '".$this->db->escape($this->address).
"'";
2350 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
2351 $sql .=
", town = '".$this->db->escape($this->town).
"'";
2352 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".((
int) $this->state_id).
"'" :
"null");
2353 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".((
int) $this->country_id).
"'" :
"null");
2354 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
2355 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
2356 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
2357 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
2358 $sql .=
", email = '".$this->db->escape($this->email).
"'";
2359 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
2360 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
2361 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2362 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2363 $sql .=
", accountancy_code_user_general = '".$this->db->escape($this->accountancy_code_user_general).
"'";
2364 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2365 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2366 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2367 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2368 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2369 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2370 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2371 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2372 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2373 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2374 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".((int) $this->fk_user).
"'" :
"null");
2375 $sql .=
", fk_user_modif = ".($this->user_modification_id > 0 ?
"'".((int) $this->user_modification_id).
"'" :
"null");
2376 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".((int) $this->fk_user_expense_validator).
"'" :
"null");
2377 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".((int) $this->fk_user_holiday_validator).
"'" :
"null");
2378 if (isset($this->thm) || $this->thm !=
'') {
2379 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2381 if (isset($this->tjm) || $this->tjm !=
'') {
2382 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2384 if (isset($this->salary) || $this->salary !=
'') {
2385 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2387 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2388 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2390 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2391 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2392 $sql .=
", entity = ".((int) $this->entity);
2394 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2395 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2396 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2397 $sql .=
", fk_establishment = ".($this->fk_establishment > 0 ? $this->fk_establishment :
"null");
2398 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2399 $sql .=
", force_pass_change = ".($this->force_pass_change ? ((int) $this->force_pass_change) :
"0");
2400 $sql .=
" WHERE rowid = ".((int) $this->
id);
2402 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2403 $resql = $this->db->query($sql);
2405 $nbrowsaffected += $this->db->affected_rows($resql);
2408 if (!empty($this->pass)) {
2409 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2411 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2412 if (is_int($result) && $result < 0) {
2419 if ($this->fk_member > 0) {
2420 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2421 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2422 $resql = $this->db->query($sql);
2424 $this->
error = $this->db->error();
2425 $this->db->rollback();
2430 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2431 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2432 $resql = $this->db->query($sql);
2434 $this->
error = $this->db->error();
2435 $this->db->rollback();
2439 if ($nbrowsaffected) {
2440 if ($this->fk_member > 0 && !$nosyncmember) {
2441 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2443 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2448 $result = $adh->fetch($this->fk_member);
2451 $adh->civility_code = $this->civility_code;
2452 $adh->firstname = $this->firstname;
2453 $adh->lastname = $this->lastname;
2454 $adh->login = $this->login;
2455 $adh->gender = $this->gender;
2456 $adh->birth = $this->birth;
2458 $adh->pass = $this->pass;
2460 $adh->address = $this->address;
2461 $adh->town = $this->town;
2462 $adh->zip = $this->zip;
2463 $adh->state_id = $this->state_id;
2464 $adh->country_id = $this->country_id;
2466 $adh->email = $this->email;
2468 $adh->socialnetworks = $this->socialnetworks;
2470 $adh->phone = $this->office_phone;
2471 $adh->phone_mobile = $this->user_mobile;
2473 $adh->default_lang = $this->lang;
2475 $adh->user_id = $this->id;
2476 $adh->user_login = $this->login;
2478 $result = $adh->update($user, 0, 1, 0);
2480 $this->
error = $adh->error;
2481 $this->errors = $adh->errors;
2482 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2485 } elseif ($result < 0) {
2486 $this->
error = $adh->error;
2487 $this->errors = $adh->errors;
2492 if ($this->contact_id > 0 && !$nosynccontact) {
2493 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2495 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2498 $tmpobj =
new Contact($this->db);
2499 $result = $tmpobj->fetch($this->contact_id);
2502 $tmpobj->civility_code = $this->civility_code;
2503 $tmpobj->firstname = $this->firstname;
2504 $tmpobj->lastname = $this->lastname;
2505 $tmpobj->login = $this->login;
2506 $tmpobj->gender = $this->gender;
2507 $tmpobj->birth = $this->birth;
2511 $tmpobj->email = $this->email;
2513 $tmpobj->socialnetworks = $this->socialnetworks;
2515 $tmpobj->phone_pro = $this->office_phone;
2516 $tmpobj->phone_mobile = $this->user_mobile;
2517 $tmpobj->fax = $this->office_fax;
2519 $tmpobj->default_lang = $this->lang;
2521 $tmpobj->address = $this->address;
2522 $tmpobj->town = $this->town;
2523 $tmpobj->zip = $this->zip;
2524 $tmpobj->state_id = $this->state_id;
2525 $tmpobj->country_id = $this->country_id;
2527 $tmpobj->user_id = $this->id;
2528 $tmpobj->user_login = $this->login;
2530 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2532 $this->
error = $tmpobj->error;
2533 $this->errors = $tmpobj->errors;
2534 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2538 $this->
error = $tmpobj->error;
2539 $this->errors = $tmpobj->errors;
2555 if (!$error && !$notrigger) {
2557 $result = $this->call_trigger(
'USER_MODIFY', $user);
2565 $this->db->commit();
2566 return $nbrowsaffected;
2569 $this->db->rollback();
2573 $this->
error = $this->db->lasterror();
2574 $this->db->rollback();
2593 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2594 $sql .=
" datepreviouslogin = datelastlogin,";
2595 $sql .=
" ippreviouslogin = iplastlogin,";
2596 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2597 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2598 $sql .=
" tms = tms";
2599 $sql .=
" WHERE rowid = ".((int) $this->
id);
2601 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2602 $resql = $this->db->query($sql);
2604 $this->datepreviouslogin = $this->datelastlogin;
2605 $this->datelastlogin = $now;
2606 $this->ippreviouslogin = $this->iplastlogin;
2607 $this->iplastlogin = $userremoteip;
2610 $this->
error = $this->db->lasterror().
' sql='.$sql;
2628 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2630 global $conf, $langs;
2631 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2635 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2640 $passwordalreadycrypted = 0;
2644 if (!empty($passwordalreadycrypted)) {
2645 $password_crypted = $password;
2649 $modGeneratePassClass =
'modGeneratePass'.ucfirst(
getDolGlobalString(
'USER_PASSWORD_GENERATED'));
2651 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2652 if (class_exists($modGeneratePassClass)) {
2653 $modGeneratePass =
new $modGeneratePassClass($this->db,
$conf, $langs, $user);
2654 '@phan-var-force ModeleGenPassword $modGeneratePass';
2657 $modGeneratePass->WithoutAmbi = 0;
2660 $testpassword = $modGeneratePass->validatePassword($password);
2661 if (!$testpassword) {
2662 $this->
error = $modGeneratePass->error;
2674 if (!$changelater) {
2675 if (!is_object($this->oldcopy)) {
2676 $this->oldcopy = clone $this;
2683 $sql =
"UPDATE ".$this->db->prefix().
"user";
2684 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2685 $sql .=
" datelastpassvalidation = '".$this->db->idate(
dol_now()).
"',";
2686 $sql .=
" pass_temp = null,";
2687 $sql .=
" force_pass_change = 0";
2688 if (!empty($flagdelsessionsbefore)) {
2689 $sql .=
", flagdelsessionsbefore = '".$this->db->idate($now - 5,
'gmt').
"'";
2692 $sql .=
", pass = null";
2694 $sql .=
", pass = '".$this->db->escape($password).
"'";
2696 $sql .=
" WHERE rowid = ".((int) $this->
id);
2698 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2700 $result = $this->db->query($sql);
2702 if ($this->db->affected_rows($result)) {
2703 $this->pass = $password;
2704 $this->pass_indatabase = $password;
2705 $this->pass_indatabase_crypted = (
string) $password_crypted;
2706 $this->force_pass_change = 0;
2708 if ($this->fk_member && !$nosyncmember) {
2709 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2714 $result = $adh->fetch($this->fk_member);
2717 $result = $adh->setPassword($user, $this->pass, (!
getDolGlobalString(
'DATABASE_PWD_ENCRYPTED') ? 0 : 1), 1);
2718 if (is_int($result) && $result < 0) {
2719 $this->
error = $adh->error;
2724 $this->
error = $adh->error;
2729 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2732 $user->context[
'audit'] =
'login='.$user->login;
2733 if (!empty($flagdelsessionsbefore)) {
2734 $user->context[
'audit'] .=
" - flagdelsessionsbefore set to '".$this->db->idate($now - 5,
'gmt').
"'";
2737 if (!$error && !$notrigger) {
2739 $result = $this->call_trigger(
'USER_NEW_PASSWORD', $user);
2742 $this->db->rollback();
2748 $this->db->commit();
2751 $this->db->rollback();
2755 $this->db->rollback();
2762 $sql =
"UPDATE ".$this->db->prefix().
"user";
2763 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2764 $sql .=
" WHERE rowid = ".((int) $this->
id);
2766 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2767 $result = $this->db->query($sql);
2789 global $conf, $langs;
2792 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2804 $outputlangs = $langs;
2808 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2810 $appli =
getDolGlobalString(
'MAIN_APPLICATION_TITLE', constant(
'DOL_APPLICATION_TITLE'));
2812 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2815 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
2816 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2818 if (!$changelater) {
2819 $url = $urlwithroot.
'/';
2824 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2826 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"\n";
2827 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2828 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2829 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2832 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2834 $mesg .= $user->getFullName($outputlangs);
2837 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2838 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.
$conf->file->instance_unique_id));
2840 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2843 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2847 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2848 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2849 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2850 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2852 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2853 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2854 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2857 $trackid =
'use'.$this->id;
2858 $sendcontext =
'passwordreset';
2879 if ($mailfile->sendfile()) {
2882 $langs->trans(
"errors");
2883 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2895 return $this->error;
2908 $sql =
"SELECT url, login, pass, poste ";
2909 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2910 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2912 $resql = $this->db->query($sql);
2914 if ($this->db->num_rows($resql)) {
2915 $obj = $this->db->fetch_object($resql);
2917 $this->clicktodial_url = $obj->url;
2918 $this->clicktodial_login = $obj->login;
2919 $this->clicktodial_password = $obj->pass;
2920 $this->clicktodial_poste = $obj->poste;
2923 $this->clicktodial_loaded = 1;
2925 $this->db->free($resql);
2928 $this->
error = $this->db->error();
2944 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2945 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2947 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2949 $result = $this->db->query($sql);
2951 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2952 $sql .=
" (fk_user,url,login,pass,poste)";
2953 $sql .=
" VALUES (".$this->id;
2954 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2955 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2956 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2957 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2959 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2961 $result = $this->db->query($sql);
2963 $this->db->commit();
2966 $this->db->rollback();
2967 $this->
error = $this->db->lasterror();
2985 global $langs, $user;
2991 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2992 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2993 $sql .=
" AND fk_usergroup = ".((int) $group);
2994 $sql .=
" AND entity = ".((int) $entity);
2996 $result = $this->db->query($sql);
2998 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2999 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
3001 $result = $this->db->query($sql);
3003 if (!$error && !$notrigger) {
3004 $this->context = array(
'audit' => $langs->trans(
"UserSetInGroup"),
'newgroupid' => $group);
3007 $result = $this->call_trigger(
'USER_MODIFY', $user);
3015 $this->db->commit();
3019 $this->db->rollback();
3023 $this->
error = $this->db->lasterror();
3024 $this->db->rollback();
3041 global $langs, $user;
3047 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
3048 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3049 $sql .=
" AND fk_usergroup = ".((int) $group);
3050 if (empty($entity)) {
3051 $sql .=
" AND entity IN (0, 1)";
3053 $sql .=
" AND entity = ".((int) $entity);
3056 $result = $this->db->query($sql);
3058 if (!$error && !$notrigger) {
3059 $this->context = array(
'audit' => $langs->trans(
"UserRemovedFromGroup"),
'oldgroupid' => $group);
3062 $result = $this->call_trigger(
'USER_MODIFY', $user);
3070 $this->db->commit();
3073 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
3074 $this->db->rollback();
3078 $this->
error = $this->db->lasterror();
3079 $this->db->rollback();
3093 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
3100 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
3123 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
3125 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3126 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
3140 global $conf, $langs, $menumanager;
3141 global $dolibarr_main_demo;
3143 $infologin = $params[
'infologin'] ?? 0;
3144 $option = $params[
'option'] ??
'';
3147 if (!empty($this->photo)) {
3148 $photo =
'<div class="photointooltip floatright">';
3149 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
3151 $data[
'photo'] = $photo;
3156 $data[
'opendiv'] =
'<div class="centpercent divtooltip">';
3157 $data[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
3159 if (!empty($this->login)) {
3162 if (!empty($this->job)) {
3166 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
3167 $phonelist = array();
3168 if ($this->office_phone) {
3169 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
3171 if ($this->office_fax) {
3172 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
3174 if ($this->user_mobile) {
3175 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
3177 $data[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
3179 if (!empty($this->admin)) {
3180 $data[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
3182 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
3183 $langs->load(
"companies");
3184 $data[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
3187 if (!empty($this->socid)) {
3188 $thirdpartystatic =
new Societe($this->db);
3189 $thirdpartystatic->fetch($this->socid);
3191 if (empty($params[
'hidethirdpartylogo'])) {
3192 $companyimg =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3194 $company =
' ('.$langs->trans(
"Company").
': '.($companyimg ? $companyimg :
img_picto(
'',
'company')).
' '.
dol_string_nohtmltag($thirdpartystatic->name).
')';
3196 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
3197 $data[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
3198 $data[
'closediv'] =
'</div>';
3200 if ($infologin > 0) {
3201 $data[
'newlinelogin'] =
'<br>';
3202 $data[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
3205 $data[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.
$conf->entity.
' (User entity '.$this->entity.
')';
3207 $data[
'authentication'] =
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
3208 $data[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
3209 $data[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
3212 $data[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
3214 $data[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
3215 $data[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag(
$conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
3217 $data[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
3218 if (
$conf->browser->layout ==
'phone') {
3219 $data[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
3221 if (!empty($_SESSION[
"disablemodules"])) {
3222 $data[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(implode(
', ', explode(
',', $_SESSION[
"disablemodules"])));
3244 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
3246 global $langs, $hookmanager, $user;
3248 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
3259 'objecttype' => $this->element,
3260 'infologin' => $infologin,
3261 'option' => $option,
3262 'hidethirdpartylogo' => $hidethirdpartylogo,
3264 $classfortooltip =
'classfortooltip';
3267 $classfortooltip =
'classforajaxtooltip';
3268 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3275 if (!empty($this->socid)) {
3276 $thirdpartystatic =
new Societe($this->db);
3277 $thirdpartystatic->fetch($this->socid);
3278 if (empty($hidethirdpartylogo)) {
3279 $companylink =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3283 if ($infologin < 0) {
3287 $baseurl = DOL_URL_ROOT .
'/user/card.php';
3288 if ($option ==
'leave') {
3289 $baseurl = DOL_URL_ROOT .
'/holiday/list.php';
3291 $query = [
'id' => $this->id];
3292 if ($option !=
'nolink') {
3294 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3295 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3296 $add_save_lastsearch_values = 1;
3298 if ($add_save_lastsearch_values) {
3299 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
3304 $linkstart =
'<a href="'.$url.
'"';
3306 if (empty($notooltip)) {
3308 $langs->load(
"users");
3309 $label = $langs->trans(
"ShowUser");
3310 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
3312 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
3313 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
3315 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
3318 $linkstart .= $linkclose.
'>';
3322 $result .= (($option ==
'nolink') ?
'' : $linkstart);
3323 if ($withpictoimg) {
3324 $paddafterimage =
'';
3325 if (abs((
int) $withpictoimg) == 1 || abs((
int) $withpictoimg) == 4) {
3326 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3329 if ($withpictoimg > 0) {
3330 $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>';
3333 $picto =
'<!-- picto photo user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'"'.($paddafterimage ?
' '.$paddafterimage :
'').
'>';
3334 $picto .=
Form::showphoto(
'userphoto', $this, 0, 0, 0,
'userphoto'.(($withpictoimg == -3 || $withpictoimg == -4) ?
'small' :
''),
'mini', 0, 1);
3335 $picto .=
'</span>';
3340 if ($withpictoimg == -4 || ($withpictoimg > -2 && $withpictoimg != 2)) {
3342 $result .=
'<span class="nopadding usertext'.((!isset($this->
status) || $this->status) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
3344 if ($mode ==
'login') {
3350 $result .=
'</span>';
3353 $result .= (($option ==
'nolink') ?
'' : $linkend);
3356 $result .= $companylink;
3359 $hookmanager->initHooks(array(
'userdao'));
3360 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
3361 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3363 $result = $hookmanager->resPrint;
3365 $result .= $hookmanager->resPrint;
3380 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
3382 global $langs, $user;
3386 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3390 if ((!$user->hasRight(
'user',
'user',
'lire') && $this->id != $user->id)) {
3394 if ($option ==
'xxx') {
3395 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3399 if ($option ==
'nolink') {
3404 $result .= $linkstart;
3405 if ($withpictoimg) {
3406 $paddafterimage =
'';
3407 if (abs($withpictoimg) == 1) {
3408 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3411 if ($withpictoimg > 0) {
3412 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3415 $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>';
3419 $result .= $this->login;
3420 $result .= $linkend;
3433 return $this->
LibStatut(isset($this->statut) ? (
int) $this->statut : (int) $this->
status, $mode);
3449 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3452 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3453 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3454 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3455 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3458 $statusType =
'status5';
3459 if ($status == self::STATUS_ENABLED) {
3460 $statusType =
'status4';
3463 $label = $this->labelStatus[$status];
3464 $labelshort = $this->labelStatusShort[$status];
3467 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3468 $statusType =
'status3';
3469 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3471 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3472 $statusType =
'status2';
3473 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3476 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3491 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3493 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3494 $return .=
'<div class="info-box info-box-sm">';
3495 $return .=
'<span class="info-box-icon bg-infobox-action">';
3498 if (!empty($this->photo)) {
3500 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3509 $return .=
'</span>';
3510 $return .=
'<div class="info-box-content">';
3511 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3512 if (
isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3513 $return .=
img_picto($langs->trans(
"SuperAdministratorDesc"),
'superadmin',
'class="valignmiddle paddingright paddingleft"');
3514 } elseif ($this->admin) {
3515 $return .=
img_picto($langs->trans(
"AdministratorDesc"),
'admin',
'class="valignmiddle paddingright paddingleft"');
3517 $return .=
'</span>';
3518 if ($selected >= 0) {
3519 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3521 if (property_exists($this,
'label')) {
3522 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3525 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->
email.
'</span>';
3527 if (method_exists($this,
'getLibStatut')) {
3528 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3530 $return .=
'</div>';
3531 $return .=
'</div>';
3532 $return .=
'</div>';
3556 } elseif ($mode == 1) {
3558 } elseif ($mode == 2) {
3574 global $conf, $langs;
3580 $keymodified =
false;
3589 'LDAP_FIELD_FULLNAME' =>
'fullname',
3590 'LDAP_FIELD_NAME' =>
'lastname',
3591 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3592 'LDAP_FIELD_LOGIN' =>
'login',
3593 'LDAP_FIELD_LOGIN_SAMBA' =>
'login',
3594 'LDAP_FIELD_PHONE' =>
'office_phone',
3595 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3596 'LDAP_FIELD_FAX' =>
'office_fax',
3597 'LDAP_FIELD_MAIL' =>
'email',
3598 'LDAP_FIELD_SID' =>
'ldap_sid',
3602 foreach ($ldapkey as $constname => $varname) {
3608 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->$varname != $this->oldcopy->$varname) {
3609 $keymodified =
true;
3614 foreach ($socialnetworks as $key => $value) {
3615 if (!empty($this->socialnetworks[$value[
'label']]) &&
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))) {
3616 $info[
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))] = $this->socialnetworks[$value[
'label']];
3632 $soc =
new Societe($this->db);
3633 $soc->fetch($this->socid);
3636 if ($soc->client == 1) {
3637 $info[
"businessCategory"] =
"Customers";
3639 if ($soc->client == 2) {
3640 $info[
"businessCategory"] =
"Prospects";
3642 if ($soc->fournisseur == 1) {
3643 $info[
"businessCategory"] =
"Suppliers";
3648 if (!empty($this->pass)) {
3661 if ($this->pass_indatabase_crypted &&
getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED')) {
3665 } elseif (!empty($this->pass_indatabase)) {
3677 $info[
"objectclass"][4] =
"phpgwContact";
3679 $info[
'uidnumber'] = $this->id;
3681 $info[
'phpgwTz'] = 0;
3682 $info[
'phpgwMailType'] =
'INTERNET';
3683 $info[
'phpgwMailHomeType'] =
'INTERNET';
3685 $info[
"phpgwContactTypeId"] =
'n';
3686 $info[
"phpgwContactCatId"] = 0;
3687 $info[
"phpgwContactAccess"] =
"public";
3689 $info[
"phpgwContactOwner"] = 1;
3692 $info[
"rfc822Mailbox"] = $this->email;
3694 if ($this->user_mobile) {
3695 $info[
"phpgwCellTelephoneNumber"] = $this->user_mobile;
3704 $groupslist = $usergroup->listGroupsForUser($this->
id);
3706 if (!empty($groupslist)) {
3707 foreach ($groupslist as $groupforuser) {
3736 $this->
ref =
'SPECIMEN';
3737 $this->specimen = 1;
3738 $this->user_creation_id = $user->id;
3740 $this->lastname =
'DOLIBARR';
3741 $this->firstname =
'SPECIMEN';
3742 $this->gender =
'man';
3743 $this->note_public =
'This is a note public';
3744 $this->note_private =
'This is a note private';
3745 $this->
email =
'email@specimen.com';
3746 $this->personal_email =
'personalemail@specimen.com';
3747 $this->socialnetworks = array(
3748 'skype' =>
'skypepseudo',
3749 'twitter' =>
'twitterpseudo',
3750 'facebook' =>
'facebookpseudo',
3751 'linkedin' =>
'linkedinpseudo',
3753 $this->office_phone =
'0999999999';
3754 $this->office_fax =
'0999999998';
3755 $this->user_mobile =
'0999999997';
3756 $this->personal_mobile =
'0999999996';
3758 $this->login =
'dolibspec';
3759 $this->pass =
'dolibSpec+@123';
3762 $this->datec = $now;
3763 $this->datem = $now;
3765 $this->datelastlogin = $now;
3766 $this->iplastlogin =
'127.0.0.1';
3767 $this->datepreviouslogin = $now;
3768 $this->ippreviouslogin =
'127.0.0.1';
3784 $sql =
"SELECT u.rowid, u.login as ref, u.datec, fk_user_creat as user_creation_id, fk_user_modif as user_modification_id,";
3785 $sql .=
" GREATEST(u.tms, uef.tms) as date_modification, u.entity";
3786 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3787 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user_extrafields as uef ON uef.fk_object = u.rowid";
3788 $sql .=
" WHERE u.rowid = ".((int) $id);
3790 $result = $this->db->query($sql);
3792 if ($this->db->num_rows($result)) {
3793 $obj = $this->db->fetch_object($result);
3795 $this->
id = $obj->rowid;
3797 $this->user_creation_id = $obj->user_creation_id;
3798 $this->user_modification_id = $obj->user_modification_id;
3800 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3801 $this->date_creation = $this->db->jdate($obj->datec);
3802 $this->date_modification = $this->db->jdate($obj->date_modification);
3803 $this->entity = $obj->entity;
3806 $this->db->free($result);
3820 $sql =
"SELECT count(mc.email) as nb";
3821 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3822 $sql .=
" WHERE mc.email = '".$this->db->escape($this->
email).
"'";
3823 $sql .=
" AND mc.statut NOT IN (-1,0)";
3825 $resql = $this->db->query($sql);
3827 $obj = $this->db->fetch_object($resql);
3828 $nb = (int) $obj->nb;
3830 $this->db->free($resql);
3833 $this->
error = $this->db->error();
3848 $sql =
"SELECT count(rowid) as nb";
3849 $sql .=
" FROM ".$this->db->prefix().
"user";
3850 if ($option ==
'superadmin') {
3851 $sql .=
" WHERE entity = 0";
3853 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3854 if ($limitTo ==
'active') {
3855 $sql .=
" AND statut = 1";
3859 $sql .=
" AND admin = ".(int) $admin;
3862 $resql = $this->db->query($sql);
3864 $obj = $this->db->fetch_object($resql);
3865 $nb = (int) $obj->nb;
3867 $this->db->free($resql);
3870 $this->
error = $this->db->lasterror();
3891 $this->firstname = $ldapuser->$tmpvar;
3893 $this->lastname = $ldapuser->$tmpvar;
3895 $this->login = $ldapuser->$tmpvar;
3897 $this->pass = $ldapuser->$tmpvar;
3899 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3902 $this->office_phone = $ldapuser->$tmpvar;
3904 $this->user_mobile = $ldapuser->$tmpvar;
3906 $this->office_fax = $ldapuser->$tmpvar;
3908 $this->
email = $ldapuser->$tmpvar;
3909 foreach ($socialnetworks as $key => $value) {
3911 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3914 $this->ldap_sid = $ldapuser->$tmpvar;
3917 $this->job = $ldapuser->$tmpvar;
3919 $this->note_public = $ldapuser->$tmpvar;
3921 $result = $this->
update($user);
3923 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3939 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3940 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3942 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3943 $res = $this->db->query($sql);
3946 while ($rec = $this->db->fetch_array($res)) {
3947 $user =
new User($this->db);
3948 $user->fetch($rec[
'rowid']);
3966 $this->parentof = array();
3969 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3970 $sql .=
" FROM ".$this->db->prefix().
"user";
3971 $sql .=
" WHERE fk_user <> 0";
3972 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3974 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3975 $resql = $this->db->query($sql);
3977 while ($obj = $this->db->fetch_object($resql)) {
3978 $this->parentof[$obj->id_son] = $obj->id_parent;
4004 global $hookmanager;
4007 $hookmanager->initHooks(array(
'userdao'));
4009 $this->users = array();
4015 $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";
4016 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4018 $parameters = array();
4019 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
4021 $sql .= $hookmanager->resPrint;
4023 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4026 $sql .= forgeSQLFromUniversalSearchCriteria($filter);
4029 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
4030 $resql = $this->db->query($sql);
4033 while ($obj = $this->db->fetch_object($resql)) {
4034 $this->users[(int) $obj->rowid]
4036 'rowid' => (
int) $obj->rowid,
4037 'id' => (int) $obj->rowid,
4038 'fk_user' => (
int) $obj->fk_user,
4039 'fk_soc' => (int) $obj->fk_soc,
4040 'firstname' => (
string) $obj->firstname,
4041 'lastname' => (
string) $obj->lastname,
4042 'login' => (
string) $obj->login,
4043 'statut' => (int) $obj->statut,
4044 'entity' => (
int) $obj->entity,
4045 'email' => (
string) $obj->email,
4046 'gender' => (
string) $obj->gender,
4047 'admin' => (int) $obj->admin,
4048 'photo' => (
string) $obj->photo,
4062 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
4063 foreach ($this->users as $key => $val) {
4066 $this->
error =
'ErrorLoopInHierarchy';
4072 if ($deleteafterid) {
4074 $keyfilter1 =
'^'.$deleteafterid.
'$';
4075 $keyfilter2 =
'_'.$deleteafterid.
'$';
4076 $keyfilter3 =
'^'.$deleteafterid.
'_';
4077 $keyfilter4 =
'_'.$deleteafterid.
'_';
4078 foreach (array_keys($this->users) as $key) {
4079 $fullpath = (
string) $this->users[$key][
'fullpath'];
4080 if (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
4081 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath)) {
4082 unset($this->users[$key]);
4087 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
4088 $this->users =
dol_sort_array($this->users,
'fullname',
'asc', 1, 0, 1);
4090 return $this->users;
4103 $childids = array();
4105 if (isset($this->cache_childids[$this->
id])) {
4106 $childids = $this->cache_childids[$this->id];
4111 $idtoscan = $this->id;
4113 dol_syslog(
"Build childid for id = ".$idtoscan);
4114 foreach ($this->users as $id => $val) {
4115 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
4116 $childids[$val[
'id']] = $val[
'id'];
4120 $this->cache_childids[$this->id] = $childids;
4122 if ($addcurrentuser) {
4123 $childids[$this->id] = $this->id;
4143 if (!empty($this->users[$id_user][
'fullpath'])) {
4145 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
4150 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
4151 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
4153 $cursor_user = $id_user;
4155 $useridfound = array($id_user);
4156 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
4157 if (in_array($this->parentof[$cursor_user], $useridfound)) {
4158 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
4161 $useridfound[] = $this->parentof[$cursor_user];
4162 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
4163 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
4165 $cursor_user = $this->parentof[$cursor_user];
4169 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
4199 $this->nb = array();
4201 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
4202 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4204 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
4205 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
4206 $sql .=
" AND ug.fk_user = u.rowid";
4208 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4210 $sql .=
" AND u.statut > 0";
4213 $resql = $this->db->query($sql);
4215 while ($obj = $this->db->fetch_object($resql)) {
4216 $this->nb[
"users"] = $obj->nb;
4218 $this->db->free($resql);
4222 $this->
error = $this->db->error();
4238 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4242 $langs->load(
"user");
4249 $modele =
'bluesky';
4253 $modelpath =
"core/modules/user/doc/";
4255 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4269 $user_property =
'';
4271 if (empty($rowid)) {
4275 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
4276 $sql .=
" FROM ".$this->db->prefix().
"user";
4277 $sql .=
" WHERE rowid = ".((int) $rowid);
4279 $resql = $this->db->query($sql);
4281 $nump = $this->db->num_rows($resql);
4284 $obj = $this->db->fetch_object($resql);
4286 if ($mode ==
'email') {
4287 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
4288 } elseif ($mode ==
'mobile') {
4289 $user_property = $obj->user_mobile;
4290 } elseif ($mode ==
'name') {
4294 return $user_property;
4314 $encodedsecurekey =
dol_hash(
$conf->file->instance_unique_id.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
4316 $entity_qr =
'&entity='.((int)
$conf->entity);
4321 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
4322 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
4325 if ($typeofurl ==
'internal') {
4326 $urlwithroot = DOL_URL_ROOT;
4329 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
4345 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $entityfilter =
false)
4347 global $conf, $user;
4349 $sql =
"SELECT t.rowid";
4350 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
4352 if ($entityfilter) {
4354 if (!empty($user->admin) && empty($user->entity) &&
$conf->entity == 1) {
4355 $sql .=
" WHERE t.entity IS NOT NULL";
4357 $sql .=
" WHERE t.entity = 0 OR EXISTS (";
4358 $sql .=
" SELECT ug.rowid FROM " . $this->db->prefix() .
"usergroup_user as ug";
4359 $sql .=
" WHERE ug.fk_user = t.rowid AND ug.entity IN (" .
getEntity(
'usergroup') .
"))";
4362 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
4365 $sql .=
" WHERE 1 = 1";
4370 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
4371 if ($errormessage) {
4372 $this->errors[] = $errormessage;
4373 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
4377 $sql .= $this->db->order($sortfield, $sortorder);
4379 $sql .= $this->db->plimit($limit + 1, $offset);
4384 $resql = $this->db->query($sql);
4386 $this->users = array();
4387 $num = $this->db->num_rows($resql);
4389 while ($obj = $this->db->fetch_object($resql)) {
4390 $line =
new self($this->db);
4391 $result = $line->fetch($obj->rowid);
4392 if ($result > 0 && !empty($line->id)) {
4393 $this->users[$obj->rowid] = clone $line;
4396 $this->db->free($resql);
4400 $this->errors[] = $this->db->lasterror();
4412 private $findUserIdByEmailCache;
4426 if (isset($this->findUserIdByEmailCache[$email])) {
4427 return $this->findUserIdByEmailCache[$email];
4430 $this->findUserIdByEmailCache[$email] = -1;
4432 $sql =
'SELECT rowid';
4433 $sql .=
' FROM '.$this->db->prefix().
'user';
4434 if (
getDolGlobalString(
'AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR')) {
4435 $sql .=
" WHERE email LIKE '%".$this->db->escape($this->db->escapeforlike($email)).
"%'";
4437 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4441 $resql = $this->db->query($sql);
4446 $obj = $this->db->fetch_object($resql);
4451 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4453 return $this->findUserIdByEmailCache[$email];
4464 if (empty($fromId) || empty($toId)) {
4471 $sqlDelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
4472 $sqlDelete .=
" WHERE fk_user = ".((int) $toId);
4474 dol_syslog(get_class($this).
"::clone_rights (delete default permissions)", LOG_DEBUG);
4476 if (!$this->db->query($sqlDelete)) {
4477 $this->db->rollback();
4482 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id)";
4483 $sql .=
" SELECT entity, ".((int) $toId).
", fk_id";
4484 $sql .=
" FROM ".$this->db->prefix().
"user_rights src";
4485 $sql .=
" WHERE fk_user = ".((int) $fromId);
4486 $sql .=
" AND NOT EXISTS (";
4487 $sql .=
" SELECT 1";
4488 $sql .=
" FROM ".$this->db->prefix().
"user_rights dest";
4489 $sql .=
" WHERE dest.entity = src.entity";
4490 $sql .=
" AND dest.fk_user = ".((int) $toId);
4491 $sql .=
" AND dest.fk_id = src.fk_id";
4494 dol_syslog(get_class($this).
"::clone_rights", LOG_DEBUG);
4497 if (!$this->db->query($sql)) {
4498 $this->db->rollback();
4502 $this->db->commit();
4519 $type = $this->table_element;
4522 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4523 $categorystatic =
new Categorie($this->db);
4525 $sql =
"INSERT INTO ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]).
" (fk_categorie, fk_user)";
4526 $sql .=
" SELECT fk_categorie, ".((int) $toId).
" FROM ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]);
4527 $sql .=
" WHERE fk_user = ".((int) $fromId);
4529 if (!$this->db->query($sql)) {
4530 $this->
error = $this->db->lasterror();
4531 $this->db->rollback();
4535 $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.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class to manage Dolibarr database access.
Class to manage warehouses.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage user groups.
Class to manage Dolibarr users.
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
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...
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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.
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
getArrayOfSocialNetworks()
Get array of social network dictionary.
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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
conf($dolibarr_main_document_root)
Load conf file (file must exists)
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
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.