41require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/class/commonpeople.class.php';
57 public $element =
'user';
62 public $table_element =
'user';
67 public $fk_element =
'fk_user';
72 public $picto =
'user';
111 public $civility_code;
136 public $email_oauth2;
141 public $personal_email;
146 public $socialnetworks;
161 public $office_phone;
176 public $personal_mobile;
201 public $pass_crypted;
206 public $pass_indatabase;
211 public $pass_indatabase_crypted;
221 public $force_pass_change = 0;
260 public $fk_user_expense_validator;
265 public $fk_user_holiday_validator;
270 public $clicktodial_url;
275 public $clicktodial_login;
280 public $clicktodial_password;
285 public $clicktodial_poste;
290 public $clicktodial_loaded;
296 public $datelastpassvalidation;
300 public $datelastlogin;
304 public $datepreviouslogin;
308 public $flagdelsessionsbefore;
316 public $ippreviouslogin;
320 public $datestartvalidity;
324 public $dateendvalidity;
344 public $all_permissions_are_loaded;
354 public $user_group_list;
359 private $_tab_loaded = array();
369 public $default_values;
374 public $lastsearch_values_tmp;
378 public $lastsearch_values;
383 public $users = array();
391 private $cache_childids;
397 public $accountancy_code_user_general;
402 public $accountancy_code;
434 public $dateemployment;
438 public $dateemploymentend;
443 public $default_c_exp_tax_cat;
448 public $ref_employee;
453 public $national_registration_number;
458 public $default_range;
464 public $fk_warehouse;
469 public $fk_establishment;
474 public $label_establishment;
480 public $usergroup_entity;
482 public $fields = array(
483 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
484 'lastname' => array(
'type' =>
'varchar(50)',
'label' =>
'Lastname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 20,
'searchall' => 1),
485 'firstname' => array(
'type' =>
'varchar(50)',
'label' =>
'Firstname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 10,
'searchall' => 1),
486 'fk_warehouse' => array(
'type' =>
'integer:Entrepot:product\stock\class\entrepot.class.php',
'label' =>
'Warehouse',
'enabled' =>
"isModEnabled('stock')",
'visible' => 1,
'notnull' => 0,
'showoncombobox' => 1,
'index' => 1,
'position' => 50,
'searchall' => 1),
487 'ref_employee' => array(
'type' =>
'varchar(50)',
'label' =>
'RefEmployee',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 30,
'searchall' => 1),
488 'national_registration_number' => array(
'type' =>
'varchar(50)',
'label' =>
'NationalRegistrationNumber',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 40,
'searchall' => 1)
491 const STATUS_DISABLED = 0;
492 const STATUS_ENABLED = 1;
503 $this->ismultientitymanaged = 1;
504 $this->isextrafieldmanaged = 1;
506 $this->clicktodial_loaded = 0;
509 $this->all_permissions_are_loaded = 0;
510 $this->nb_rights = 0;
518 $this->rights->user =
new stdClass();
519 $this->rights->user->user =
new stdClass();
520 $this->rights->user->self =
new stdClass();
521 $this->rights->user->user_advance =
new stdClass();
522 $this->rights->user->self_advance =
new stdClass();
523 $this->rights->user->group_advance =
new stdClass();
540 public function fetch($id = 0, $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'', $fk_socpeople = 0, $use_email_oauth2 = 0)
545 $login = trim($login);
548 $sql =
"SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.civility as civility_code, u.birth, u.job,";
549 $sql .=
" u.email, u.email_oauth2, u.personal_email,";
550 $sql .=
" u.socialnetworks,";
551 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
552 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
553 $sql .=
" u.admin, u.login, u.note_private, u.note_public,";
554 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.force_pass_change, u.api_key,";
555 $sql .=
" u.fk_soc, u.fk_socpeople, u.fk_member, u.fk_user, u.ldap_sid, u.fk_user_expense_validator, u.fk_user_holiday_validator,";
556 $sql .=
" fk_user_creat as user_creation_id, fk_user_modif as user_modification_id,";
557 $sql .=
" u.statut as status, u.lang, u.entity,";
558 $sql .=
" u.datec as datec,";
559 $sql .=
" GREATEST(u.tms, uef.tms) as datem,";
560 $sql .=
" u.datelastlogin as datel,";
561 $sql .=
" u.datepreviouslogin as datep,";
562 $sql .=
" u.flagdelsessionsbefore,";
563 $sql .=
" u.iplastlogin,";
564 $sql .=
" u.ippreviouslogin,";
565 $sql .=
" u.datelastpassvalidation,";
566 $sql .=
" u.datestartvalidity,";
567 $sql .=
" u.dateendvalidity,";
568 $sql .=
" u.photo as photo,";
569 $sql .=
" u.openid as openid,";
570 $sql .=
" u.accountancy_code_user_general,";
571 $sql .=
" u.accountancy_code,";
574 $sql .=
" u.salary,";
575 $sql .=
" u.salaryextra,";
576 $sql .=
" u.weeklyhours,";
578 $sql .=
" u.dateemployment, u.dateemploymentend,";
579 $sql .=
" u.fk_warehouse,";
580 $sql .=
" u.ref_ext,";
581 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
582 $sql .=
" u.national_registration_number,";
583 $sql .=
" u.ref_employee,";
584 $sql .=
" c.code as country_code, c.label as country,";
585 $sql .=
" d.code_departement as state_code, d.nom as state,";
586 $sql .=
" s.label as label_establishment, u.fk_establishment";
587 $sql .=
" FROM ".$this->db->prefix().
"user as u";
588 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user_extrafields as uef ON uef.fk_object = u.rowid";
589 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as c ON u.fk_country = c.rowid";
590 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_departements as d ON u.fk_state = d.rowid";
591 $sql .=
" LEFT JOIN ".$this->db->prefix().
"establishment as s ON u.fk_establishment = s.rowid";
594 $sql .=
" WHERE u.rowid = ".((int) $id);
598 $sql .=
" WHERE u.entity IN (0, " . ((int)
$conf->entity) .
")";
600 $sql .=
" WHERE u.entity IS NOT NULL";
605 $sql .=
" WHERE u.entity IS NOT NULL";
607 if ($entity !=
'' && $entity == 0) {
608 $sql .=
" WHERE u.entity = 0";
610 $sql .=
" WHERE u.entity IN (0, " . ((int) ($entity > 0 ? ((
int) $entity) : ((int)
$conf->entity))) .
")";
618 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->db->escape($login).
"')";
620 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
622 $sql .=
" AND (u.email = '".$this->db->escape($email).
"'";
623 if ($use_email_oauth2) {
624 $sql .=
" OR u.email_oauth2 = '".$this->db->escape($email).
"'";
627 } elseif ($fk_socpeople > 0) {
628 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
631 $sql .=
" ORDER BY u.entity ASC";
635 $sql .=
' '.$this->db->plimit(1);
638 $resql = $this->db->query($sql);
640 $num = $this->db->num_rows($resql);
642 $this->
error =
"USERDUPLICATEFOUND";
643 dol_syslog(get_class($this).
"::fetch more than 1 user found", LOG_WARNING);
645 $this->db->free($resql);
649 $obj = $this->db->fetch_object($resql);
651 $this->
id = $obj->rowid;
652 $this->
ref = $obj->rowid;
654 $this->ref_ext = $obj->ref_ext;
656 $this->ldap_sid = $obj->ldap_sid;
657 $this->civility_code = $obj->civility_code;
658 $this->lastname = $obj->lastname;
659 $this->firstname = $obj->firstname;
660 $this->ref_employee = $obj->ref_employee;
661 $this->national_registration_number = $obj->national_registration_number;
663 $this->employee = $obj->employee;
665 $this->login = $obj->login;
666 $this->gender = $obj->gender;
667 $this->birth = $this->db->jdate($obj->birth);
668 $this->pass_indatabase = $obj->pass;
669 $this->pass_indatabase_crypted = $obj->pass_crypted;
670 $this->pass = $obj->pass;
671 $this->pass_temp = $obj->pass_temp;
672 $this->force_pass_change = $obj->force_pass_change;
673 $this->datelastpassvalidation = $obj->datelastpassvalidation;
676 $this->
address = $obj->address;
677 $this->zip = $obj->zip;
678 $this->town = $obj->town;
680 $this->country_id = $obj->country_id;
681 $this->country_code = $obj->country_id ? $obj->country_code :
'';
684 $this->state_id = $obj->state_id;
685 $this->state_code = $obj->state_code;
686 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
688 $this->office_phone = $obj->office_phone;
689 $this->office_fax = $obj->office_fax;
690 $this->user_mobile = $obj->user_mobile;
691 $this->personal_mobile = $obj->personal_mobile;
692 $this->
email = $obj->email;
693 $this->email_oauth2 = $obj->email_oauth2;
694 $this->personal_email = $obj->personal_email;
695 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
696 $this->user_creation_id = $obj->user_creation_id;
697 $this->user_modification_id = $obj->user_modification_id;
699 $this->job = $obj->job;
700 $this->signature = $obj->signature;
701 $this->admin = $obj->admin;
702 $this->note_public = $obj->note_public;
703 $this->note_private = $obj->note_private;
705 $this->statut = $obj->status;
706 $this->
status = $obj->status;
708 $this->photo = $obj->photo;
709 $this->openid = $obj->openid;
710 $this->lang = $obj->lang;
711 $this->entity = $obj->entity;
713 $this->accountancy_code_user_general = $obj->accountancy_code_user_general;
714 $this->accountancy_code = $obj->accountancy_code;
716 $this->thm = $obj->thm;
717 $this->tjm = $obj->tjm;
718 $this->salary = $obj->salary;
719 $this->salaryextra = $obj->salaryextra;
720 $this->weeklyhours = $obj->weeklyhours;
721 $this->color = $obj->color;
722 $this->dateemployment = $this->db->jdate($obj->dateemployment);
723 $this->dateemploymentend = $this->db->jdate($obj->dateemploymentend);
725 $this->datec = $this->db->jdate($obj->datec);
726 $this->datem = $this->db->jdate($obj->datem);
727 $this->datelastlogin = $this->db->jdate($obj->datel);
728 $this->datepreviouslogin = $this->db->jdate($obj->datep);
729 $this->flagdelsessionsbefore = $this->db->jdate($obj->flagdelsessionsbefore,
'gmt');
730 $this->iplastlogin = $obj->iplastlogin;
731 $this->ippreviouslogin = $obj->ippreviouslogin;
732 $this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
733 $this->dateendvalidity = $this->db->jdate($obj->dateendvalidity);
735 $this->socid = $obj->fk_soc;
736 $this->contact_id = $obj->fk_socpeople;
737 $this->fk_member = $obj->fk_member;
738 $this->fk_user = $obj->fk_user;
739 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
740 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
742 $this->default_range = $obj->default_range;
743 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
744 $this->fk_warehouse = $obj->fk_warehouse;
745 $this->warehouse_id = $obj->fk_warehouse;
746 $this->warehouse =
null;
747 $this->fk_establishment = $obj->fk_establishment;
748 $this->label_establishment = $obj->label_establishment;
752 if (!
isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
764 $this->db->free($resql);
766 $this->
error =
"USERNOTFOUND";
767 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
769 $this->db->free($resql);
773 $this->
error = $this->db->lasterror();
778 if ($loadpersonalconf) {
784 $this->
error = $this->db->lasterror();
791 if (
GETPOSTINT(
'forceexternaluser') && $this->admin && empty($this->socid)) {
792 $this->socid =
GETPOSTINT(
'forceexternaluser');
810 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
811 $sql .=
" WHERE fk_user = ".((int) $this->
id);
813 $sql .=
" AND entity IN (0, ".((int)
$conf->entity).
")";
815 $sql .=
" AND entity = ".((int) $entity);
819 $resql = $this->db->query($sql);
821 $num = $this->db->num_rows($resql);
824 $obj = $this->db->fetch_object($resql);
825 $p = (!empty($obj->param) ? $obj->param :
'');
827 $this->
conf->$p = $obj->value;
831 $this->db->free($resql);
835 $this->
error = $this->db->lasterror();
852 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
855 $result = $defaultValues->fetchAll(
'',
'', 0, 0,
'(t.user_id:in:0,'.$this->
id.
') AND (entity:in:'.(isset($this->entity) ? $this->entity :
$conf->entity).
','.
$conf->entity.
')');
858 if (!is_array($result) && $result < 0) {
862 } elseif (count($result) > 0) {
863 foreach ($result as $defval) {
864 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
865 $pagewithoutquerystring = $defval->page;
868 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
869 $pagewithoutquerystring = $reg[1];
870 $pagequeries = $reg[2];
872 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
876 if (!empty($this->default_values)) {
877 foreach ($this->default_values as $a => $b) {
878 foreach ($b as
$c => $d) {
879 krsort($this->default_values[$a][
$c]);
920 public function hasRight($module, $permlevel1, $permlevel2 =
'')
923 $moduletomoduletouse = array(
924 'category' =>
'categorie',
925 'compta' =>
'comptabilite',
926 'contract' =>
'contrat',
927 'member' =>
'adherent',
929 'order' =>
'commande',
930 'produit' =>
'product',
931 'productlot' =>
'product',
932 'project' =>
'projet',
933 'propale' =>
'propal',
934 'shipping' =>
'expedition',
935 'task' =>
'task@projet',
936 'fichinter' =>
'ficheinter',
937 'intervention' =>
'ficheinter',
938 'inventory' =>
'stock',
939 'invoice' =>
'facture',
940 'invoice_supplier' =>
'facture@fournisseur',
941 'order_supplier' =>
'fournisseur',
942 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
943 'skill@hrm' =>
'all@hrm',
944 'job@hrm' =>
'all@hrm',
945 'position@hrm' =>
'all@hrm',
946 'facturerec' =>
'facture',
947 'margins' =>
'margin',
950 if (!empty($moduletomoduletouse[$module])) {
951 $module = $moduletomoduletouse[$module];
962 $supplierNewToLegacy = array(
963 'supplier_order' => array(
'fournisseur',
'commande'),
964 'supplier_invoice' => array(
'fournisseur',
'facture'),
967 if (isset($supplierNewToLegacy[$module])) {
970 $permlevel2 = $permlevel1;
971 $permlevel1 = $supplierNewToLegacy[$module][1];
972 $module = $supplierNewToLegacy[$module][0];
977 $supplierLegacyCompat = array(
978 'supplier_order' =>
'fournisseur',
979 'supplier_invoice' =>
'fournisseur',
982 if (isset($supplierLegacyCompat[$module])) {
984 $module = $supplierLegacyCompat[$module];
988 $moduleRightsMapping = array(
989 'product' =>
'produit',
990 'margin' =>
'margins',
991 'comptabilite' =>
'compta'
994 $rightsPath = $module;
995 if (!empty($moduleRightsMapping[$rightsPath])) {
996 $rightsPath = $moduleRightsMapping[$rightsPath];
1000 $tmp = explode(
'@', $rightsPath, 2);
1001 if (!empty($tmp[1])) {
1002 if (strpos($module,
'@') !==
false) {
1005 if ($tmp[0] != $tmp[1]) {
1007 $rightsPath = $tmp[1];
1008 $permlevel2 = $permlevel1;
1009 $permlevel1 = $tmp[0];
1012 $rightsPath = $tmp[1];
1024 if (!empty($this->socid)) {
1025 if ($module ==
'societe' && ($permlevel1 ==
'creer' || $permlevel1 ==
'write')) {
1028 if ($module ==
'societe' && $permlevel1 ==
'client' && $permlevel2 ==
'voir') {
1031 if ($module ==
'societe' && $permlevel1 ==
'export') {
1034 if ($module ==
'societe' && ($permlevel1 ==
'supprimer' || $permlevel1 ==
'delete')) {
1040 if ($permlevel1 ==
'propale') {
1041 $permlevel1 =
'propal';
1043 if ($permlevel1 ==
'member') {
1044 $permlevel1 =
'adherent';
1046 if ($permlevel1 ==
'recruitmentcandidature') {
1047 $permlevel1 =
'recruitmentjobposition';
1050 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
1055 if (!empty($this->rights->$rightsPath->$permlevel1)) {
1056 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
1057 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
1061 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
1062 return $this->rights->$rightsPath->$permlevel1->lire;
1064 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
1065 return $this->rights->$rightsPath->$permlevel1->creer;
1067 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
1068 return $this->rights->$rightsPath->$permlevel1->create;
1070 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
1071 return $this->rights->$rightsPath->$permlevel1->supprimer;
1075 if (!empty($this->rights->$rightsPath->$permlevel1)) {
1076 return $this->rights->$rightsPath->$permlevel1;
1080 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
1081 return $this->rights->$rightsPath->lire;
1083 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
1084 return $this->rights->$rightsPath->creer;
1086 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
1087 return $this->rights->$rightsPath->create;
1089 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
1090 return $this->rights->$rightsPath->supprimer;
1108 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1110 global $conf, $user, $langs;
1112 $entity = (empty($entity) ?
$conf->entity : $entity);
1114 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
1116 if (empty($this->
id)) {
1117 $this->
error =
'Try to call addrights on an object user with an empty id';
1127 $module = $perms = $subperms =
'';
1130 $sql =
"SELECT module, perms, subperms";
1131 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1132 $sql .=
" WHERE id = ".((int) $rid);
1133 $sql .=
" AND entity = ".((int) $entity);
1135 $result = $this->db->query($sql);
1137 $obj = $this->db->fetch_object($result);
1140 $module = $obj->module;
1141 $perms = $obj->perms;
1142 $subperms = $obj->subperms;
1150 $whereforadd =
"id=".((int) $rid);
1152 if (!empty($subperms)) {
1153 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
1154 } elseif (!empty($perms)) {
1155 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND (subperms IS NULL or subperms = ''))";
1161 if (!empty($allmodule)) {
1162 if ($allmodule ==
'allmodules') {
1163 $whereforadd =
'allmodules';
1165 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
1166 if (!empty($allperms)) {
1167 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
1175 if (!empty($whereforadd)) {
1178 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1179 $sql .=
" WHERE entity = ".((int) $entity);
1180 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
1181 $sql .=
" AND (".$whereforadd.
")";
1184 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1185 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1187 $sqldelete .=
") AND entity = ".((int) $entity);
1188 if (!$this->db->query($sqldelete)) {
1193 $resql = $this->db->query($sql);
1195 $num = $this->db->num_rows($resql);
1198 $obj = $this->db->fetch_object($resql);
1203 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
1204 if (!$this->db->query($sql)) {
1218 if (!$error && !$notrigger) {
1219 $langs->load(
"other");
1220 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
1223 $result = $this->call_trigger(
'USER_MODIFY', $user);
1231 $this->db->rollback();
1234 $this->db->commit();
1251 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1253 global $conf, $user, $langs;
1257 $entity = (!empty($entity) ? $entity :
$conf->entity);
1262 $module = $perms = $subperms =
'';
1266 $sql =
"SELECT module, perms, subperms";
1267 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1268 $sql .=
" WHERE id = ".((int) $rid);
1269 $sql .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1271 $result = $this->db->query($sql);
1273 $obj = $this->db->fetch_object($result);
1276 $module = $obj->module;
1277 $perms = $obj->perms;
1278 $subperms = $obj->subperms;
1286 $wherefordel =
"id=".((int) $rid);
1288 if ($subperms ==
'lire' || $subperms ==
'read') {
1289 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1291 if ($perms ==
'lire' || $perms ==
'read') {
1292 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1298 if (!empty($allmodule)) {
1299 if ($allmodule ==
'allmodules') {
1300 $wherefordel =
'allmodules';
1302 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1303 if (!empty($allperms)) {
1304 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1311 if (!empty($wherefordel)) {
1314 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1315 $sql .=
" WHERE entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1316 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1317 $sql .=
" AND (".$wherefordel.
")";
1321 if ($this->admin == 1) {
1322 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1323 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1324 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1325 $sql .=
" AND id NOT IN (358)";
1328 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1329 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1332 $sqldelete .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1334 $resql = $this->db->query($sqldelete);
1341 if (!$error && !$notrigger) {
1342 $langs->load(
"other");
1343 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1346 $result = $this->call_trigger(
'USER_MODIFY', $user);
1354 $this->db->rollback();
1357 $this->db->commit();
1371 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1373 $this->nb_rights = 0;
1374 $this->all_permissions_are_loaded = 0;
1375 $this->_tab_loaded = array();
1391 $alreadyloaded =
false;
1393 if (empty($forcereload)) {
1394 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1396 $alreadyloaded =
true;
1399 if (!empty($this->all_permissions_are_loaded)) {
1401 $alreadyloaded =
true;
1406 if (!isset($this->rights) || !is_object($this->rights)) {
1409 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1410 $this->rights->user =
new stdClass();
1415 if (!$alreadyloaded) {
1417 $sql =
"SELECT DISTINCT r.module, r.module_origin, r.perms, r.subperms";
1418 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1419 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1420 $sql .=
" WHERE r.id = ur.fk_id";
1426 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') ?
"1," :
"").((
int)
$conf->entity).
")";
1430 $sql .=
" AND r.entity = ".((int)
$conf->entity).
" AND ur.entity = ".((int)
$conf->entity);
1432 $sql .=
" AND ur.fk_user = ".((int) $this->
id);
1433 $sql .=
" AND r.perms IS NOT NULL";
1435 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1438 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1441 $resql = $this->db->query($sql);
1443 $num = $this->db->num_rows($resql);
1446 $obj = $this->db->fetch_object($resql);
1454 $module = (!empty($obj->module_origin) ? $obj->module_origin : $obj->module);
1455 $perms = $obj->perms;
1456 $subperms = $obj->subperms;
1458 if (!empty($perms)) {
1459 if (!empty($module)) {
1460 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1461 $this->rights->$module =
new stdClass();
1463 if (!empty($subperms)) {
1464 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1465 $this->rights->$module->$perms =
new stdClass();
1467 if (empty($this->rights->$module->$perms->$subperms)) {
1470 $this->rights->$module->$perms->$subperms = 1;
1472 if (empty($this->rights->$module->$perms)) {
1475 $this->rights->$module->$perms = 1;
1482 $this->db->free($resql);
1486 $sql =
"SELECT DISTINCT r.module, r.module_origin, r.perms, r.subperms, r.entity";
1487 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1488 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1489 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1490 $sql .=
" WHERE r.id = gr.fk_id";
1496 $sql .=
" AND gu.entity IN (0,".((int)
$conf->entity).
")";
1498 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1501 $sql .=
" AND gr.entity = ".((int)
$conf->entity);
1505 $sql .=
" AND gu.entity IN (0,".((int)
$conf->entity).
")";
1506 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1509 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1510 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1511 $sql .=
" AND r.perms IS NOT NULL";
1513 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1516 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1519 $resql = $this->db->query($sql);
1521 $num = $this->db->num_rows($resql);
1524 $obj = $this->db->fetch_object($resql);
1532 $module = (!empty($obj->module_origin) ? $obj->module_origin : $obj->module);
1533 $perms = $obj->perms;
1534 $subperms = $obj->subperms;
1536 if (!empty($perms)) {
1537 if (!empty($module)) {
1538 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1539 $this->rights->$module =
new stdClass();
1541 if (!empty($subperms)) {
1542 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1543 $this->rights->$module->$perms =
new stdClass();
1545 if (empty($this->rights->$module->$perms->$subperms)) {
1548 $this->rights->$module->$perms->$subperms = 1;
1551 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1552 if (empty($this->rights->$module->$perms)) {
1555 $this->rights->$module->$perms = 1;
1563 $this->db->free($resql);
1567 if (!empty($this->admin)) {
1568 if (empty($this->rights->user->user)) {
1569 $this->rights->user->user =
new stdClass();
1571 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1572 foreach ($listofpermtotest as $permtotest) {
1573 if (empty($this->rights->user->user->$permtotest)) {
1574 $this->rights->user->user->$permtotest = 1;
1578 if (empty($this->rights->user->self)) {
1579 $this->rights->user->self =
new stdClass();
1581 $listofpermtotest = array(
'creer',
'password');
1582 foreach ($listofpermtotest as $permtotest) {
1583 if (empty($this->rights->user->self->$permtotest)) {
1584 $this->rights->user->self->$permtotest = 1;
1590 if (empty($this->rights->user->user_advance)) {
1591 $this->rights->user->user_advance =
new stdClass();
1593 $listofpermtotest = array(
'readperms',
'write');
1594 foreach ($listofpermtotest as $permtotest) {
1595 if (empty($this->rights->user->user_advance->$permtotest)) {
1596 $this->rights->user->user_advance->$permtotest = 1;
1600 if (empty($this->rights->user->self_advance)) {
1601 $this->rights->user->self_advance =
new stdClass();
1603 $listofpermtotest = array(
'readperms',
'writeperms');
1604 foreach ($listofpermtotest as $permtotest) {
1605 if (empty($this->rights->user->self_advance->$permtotest)) {
1606 $this->rights->user->self_advance->$permtotest = 1;
1610 if (empty($this->rights->user->group_advance)) {
1611 $this->rights->user->group_advance =
new stdClass();
1613 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1614 foreach ($listofpermtotest as $permtotest) {
1615 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1616 $this->rights->user->group_advance->$permtotest = 1;
1624 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1625 $this->rights->propal = $this->rights->propale;
1627 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1628 $this->rights->propale = $this->rights->propal;
1635 $this->all_permissions_are_loaded = 1;
1638 $this->_tab_loaded[$moduletag] = 1;
1655 public function getrights($moduletag =
'', $forcereload = 0)
1668 global $conf, $langs, $user;
1673 if (isset($this->statut)) {
1674 if ($this->statut == $status) {
1677 } elseif (isset($this->
status) && $this->
status == $status) {
1684 $sql =
"UPDATE ".$this->db->prefix().
"user";
1685 $sql .=
" SET statut = ".((int) $status);
1686 $sql .=
" WHERE rowid = ".((int) $this->
id);
1687 $result = $this->db->query($sql);
1689 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1692 $this->context[
'actionmsg'] =
'User '.$this->login.
' disabled';
1694 $this->context[
'actionmsg'] =
'User '.$this->login.
' enabled';
1697 $result = $this->call_trigger(
'USER_ENABLEDISABLE', $user);
1705 $this->db->rollback();
1709 $this->statut = $status;
1710 $this->db->commit();
1726 $value = (int) $value;
1729 if ($this->force_pass_change == $value) {
1736 $sql =
"UPDATE ".$this->db->prefix().
"user";
1737 $sql .=
" SET force_pass_change = ".((int) $value);
1738 $sql .=
" WHERE rowid = ".((int) $this->
id);
1739 $result = $this->db->query($sql);
1741 dol_syslog(get_class($this).
"::setForcePasswordChange", LOG_DEBUG);
1743 $this->force_pass_change = $value;
1745 $result = $this->call_trigger(
'USER_MODIFY', $user);
1752 $this->
error = $this->db->lasterror();
1756 $this->db->rollback();
1759 $this->db->commit();
1776 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1777 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1792 $this->
fetch($this->
id);
1794 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1797 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1799 if (!$error && !$this->db->query($sql)) {
1801 $this->
error = $this->db->lasterror();
1805 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1806 if (!$error && !$this->db->query($sql)) {
1808 $this->
error = $this->db->lasterror();
1812 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1813 if (!$error && !$this->db->query($sql)) {
1815 $this->
error = $this->db->lasterror();
1819 if ($this->contact_id > 0) {
1820 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1821 if (!$error && !$this->db->query($sql)) {
1823 $this->
error = $this->db->lasterror();
1832 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1838 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1839 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1840 if (!$this->db->query($sql)) {
1842 $this->
error = $this->db->lasterror();
1848 $result = $this->call_trigger(
'USER_DELETE', $user);
1851 $this->db->rollback();
1856 $this->db->commit();
1859 $this->db->rollback();
1871 public function create($user, $notrigger = 0)
1873 global $conf, $langs;
1879 $this->civility_code = trim((
string) $this->civility_code);
1880 $this->login = trim((
string) $this->login);
1881 $this->user_creation_id = (int) $user->id;
1882 if (!isset($this->entity)) {
1883 $this->entity =
$conf->entity;
1885 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1891 $langs->load(
"errors");
1892 $this->
error = $langs->trans(
"ErrorBadEMail", $this->
email);
1895 if (empty($this->login)) {
1896 $langs->load(
"errors");
1897 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1899 } elseif ($badCharUnauthorizedIntoLoginName !==
'' && preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1900 $langs->load(
"errors");
1901 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1912 $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).
"'";
1913 $resqltochecklogin = $this->db->query($sqltochecklogin);
1914 if ($resqltochecklogin) {
1915 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1916 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1917 $langs->load(
"errors");
1918 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1920 $this->db->rollback();
1923 $this->db->free($resqltochecklogin);
1926 if (!empty($this->
email)) {
1927 $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).
"'";
1928 $resqltochecklogin = $this->db->query($sqltochecklogin);
1929 if ($resqltochecklogin) {
1930 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1931 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1932 $langs->load(
"errors");
1933 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->
email);
1935 $this->db->rollback();
1938 $this->db->free($resqltochecklogin);
1943 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, fk_user_creat, entity)";
1944 $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).
")";
1945 $result = $this->db->query($sql);
1947 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1949 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1953 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1954 $this->db->rollback();
1959 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1960 $langs->load(
"stocks");
1962 $entrepot =
new Entrepot($this->db);
1963 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1964 $entrepot->libelle = $entrepot->label;
1965 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1966 $entrepot->statut = 1;
1967 $entrepot->country_id =
$mysoc->country_id;
1969 $warehouseid = $entrepot->create($user);
1971 $this->fk_warehouse = $warehouseid;
1975 $result = $this->
update($user, 1, 1);
1977 $this->db->rollback();
1983 $result = $this->call_trigger(
'USER_CREATE', $user);
1991 $this->db->commit();
1996 $this->db->rollback();
2000 $this->
error = $this->db->lasterror();
2001 $this->db->rollback();
2025 $this->civility_code = $contact->civility_code;
2026 $this->lastname = $contact->lastname;
2027 $this->firstname = $contact->firstname;
2029 $this->
email = $contact->email;
2030 $this->socialnetworks = $contact->socialnetworks;
2031 $this->office_phone = $contact->phone_pro;
2032 $this->office_fax = $contact->fax;
2033 $this->user_mobile = $contact->phone_mobile;
2034 $this->
address = $contact->address;
2035 $this->zip = $contact->zip;
2036 $this->town = $contact->town;
2038 $this->state_id = $contact->state_id;
2039 $this->country_id = $contact->country_id;
2040 $this->employee = 0;
2042 if (empty($login)) {
2043 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
2044 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
2046 $this->login = $login;
2051 $result = $this->
create($user, 1);
2053 $sql =
"UPDATE ".$this->db->prefix().
"user";
2054 $sql .=
" SET fk_socpeople=".((int) $contact->id);
2055 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
2056 if ($contact->socid > 0) {
2057 $sql .=
", fk_soc=".((int) $contact->socid);
2059 $sql .=
" WHERE rowid=".((int) $this->
id);
2061 $resql = $this->db->query($sql);
2063 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
2065 $this->context[
'createfromcontact'] =
'createfromcontact';
2068 $result = $this->call_trigger(
'USER_CREATE', $user);
2071 $this->db->rollback();
2076 $this->db->commit();
2079 $this->
error = $this->db->error();
2081 $this->db->rollback();
2086 dol_syslog(get_class($this).
"::create_from_contact - 0");
2088 $this->db->rollback();
2109 $this->civility_code = $member->civility_code;
2110 $this->lastname = $member->lastname;
2111 $this->firstname = $member->firstname;
2112 $this->gender = $member->gender;
2113 $this->
email = $member->email;
2114 $this->fk_member = $member->id;
2115 $this->
address = $member->address;
2116 $this->zip = $member->zip;
2117 $this->town = $member->town;
2119 $this->state_id = $member->state_id;
2120 $this->country_id = $member->country_id;
2121 $this->socialnetworks = $member->socialnetworks;
2123 $this->pass = $member->pass;
2124 $this->pass_crypted = $member->pass_indatabase_crypted;
2126 if (empty($login)) {
2127 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
2130 $this->login = $login;
2135 $result = $this->
create($user);
2137 if (!empty($this->pass)) {
2138 $newpass = $this->
setPassword($user, $this->pass);
2139 if (is_int($newpass) && $newpass < 0) {
2142 } elseif (!empty($this->pass_crypted)) {
2143 $sql =
"UPDATE ".$this->db->prefix().
"user";
2144 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
2145 $sql .=
" WHERE rowid=".((int) $this->
id);
2147 $resql = $this->db->query($sql);
2153 if ($result > 0 && $member->socid) {
2154 $sql =
"UPDATE ".$this->db->prefix().
"user";
2155 $sql .=
" SET fk_soc=".((int) $member->socid);
2156 $sql .=
" WHERE rowid=".((int) $this->
id);
2158 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
2159 $resql = $this->db->query($sql);
2161 $this->db->commit();
2164 $this->
error = $this->db->lasterror();
2166 $this->db->rollback();
2173 $this->db->commit();
2177 $this->db->rollback();
2195 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
2196 $sql .=
" WHERE bydefault = 1";
2197 $sql .=
" AND entity = ".((int)
$conf->entity);
2199 $resql = $this->db->query($sql);
2201 $num = $this->db->num_rows($resql);
2204 $row = $this->db->fetch_row($resql);
2208 $this->db->free($resql);
2212 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id).
" AND fk_id=".((int) $rd[$i]);
2213 $result = $this->db->query($sql);
2215 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES (".((int) $this->
id).
", ".((int) $rd[$i]).
")";
2216 $result = $this->db->query($sql);
2236 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
2240 if (empty($this->country_id) && !empty($this->country_code)) {
2241 $country_id =
getCountry($this->country_code,
'3');
2242 $this->country_id = is_int($country_id) ? $country_id : 0;
2245 $nbrowsaffected = 0;
2248 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
2251 $this->civility_code = trim((
string) $this->civility_code);
2252 $this->lastname = trim((
string) $this->lastname);
2253 $this->firstname = trim((
string) $this->firstname);
2254 $this->ref_employee = trim((
string) $this->ref_employee);
2255 $this->national_registration_number = trim((
string) $this->national_registration_number);
2256 $this->employee = ($this->employee > 0 ? $this->employee : 0);
2257 $this->login = trim((
string) $this->login);
2258 $this->gender = trim((
string) $this->gender);
2260 $this->pass = trim((
string) $this->pass);
2261 $this->api_key = trim((
string) $this->api_key);
2262 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
2263 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
2266 $this->zip = trim((
string) $this->zip);
2267 $this->town = trim((
string) $this->town);
2269 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
2270 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
2271 $this->office_phone = trim((
string) $this->office_phone);
2272 $this->office_fax = trim((
string) $this->office_fax);
2273 $this->user_mobile = trim((
string) $this->user_mobile);
2274 $this->personal_mobile = trim((
string) $this->personal_mobile);
2276 $this->personal_email = trim((
string) $this->personal_email);
2278 $this->job = trim((
string) $this->job);
2279 $this->signature = trim((
string) $this->signature);
2280 $this->note_public = trim((
string) $this->note_public);
2281 $this->note_private = trim((
string) $this->note_private);
2282 $this->openid = trim((
string) $this->openid);
2283 $this->admin = ($this->admin > 0 ? $this->admin : 0);
2284 $this->user_modification_id = $user->id;
2286 $this->accountancy_code_user_general = trim((
string) $this->accountancy_code_user_general);
2287 $this->accountancy_code = trim((
string) $this->accountancy_code);
2288 $this->color = trim(str_replace(
'#',
'', (
string) $this->color));
2289 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
2290 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
2292 $this->birth = empty($this->birth) ?
'' : $this->birth;
2293 $this->fk_warehouse = (int) $this->fk_warehouse;
2294 $this->fk_establishment = (int) $this->fk_establishment;
2302 $langs->load(
"errors");
2303 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
2306 if (empty($this->login)) {
2307 $langs->load(
"errors");
2308 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
2310 } elseif ($badCharUnauthorizedIntoLoginName !==
'' && preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
2311 $langs->load(
"errors");
2312 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
2319 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->oldcopy->login != $this->login) {
2320 $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).
"'";
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(
"ErrorLoginAlreadyExists", $this->login);
2328 $this->db->rollback();
2333 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && !empty($this->email) && $this->oldcopy->email != $this->email) {
2334 $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).
"'";
2335 $resqltochecklogin = $this->db->query($sqltochecklogin);
2336 if ($resqltochecklogin) {
2337 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2338 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2339 $langs->load(
"errors");
2340 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
2342 $this->db->rollback();
2349 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2350 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
2351 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
2352 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
2353 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
2354 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
2355 $sql .=
", employee = ".(int) $this->employee;
2356 $sql .=
", login = '".$this->db->escape($this->login).
"'";
2357 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
2358 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
2359 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
2360 if (!empty($user->admin)) {
2361 $sql .=
", admin = ".(int) $this->admin;
2363 $sql .=
", address = '".$this->db->escape($this->address).
"'";
2364 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
2365 $sql .=
", town = '".$this->db->escape($this->town).
"'";
2366 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ? ((
int) $this->state_id) :
"null");
2367 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ? ((
int) $this->country_id) :
"null");
2368 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
2369 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
2370 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
2371 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
2372 $sql .=
", email = '".$this->db->escape($this->email).
"'";
2373 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
2374 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
2375 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2376 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2377 $sql .=
", accountancy_code_user_general = '".$this->db->escape($this->accountancy_code_user_general).
"'";
2378 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2379 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2380 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2381 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2382 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2383 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2384 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2385 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2386 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2387 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2388 $sql .=
", fk_user = ".($this->fk_user > 0 ? ((int) $this->fk_user) :
"null");
2389 $sql .=
", fk_user_modif = ".($this->user_modification_id > 0 ? ((int) $this->user_modification_id) :
"null");
2390 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ? ((int) $this->fk_user_expense_validator) :
"null");
2391 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ? ((int) $this->fk_user_holiday_validator) :
"null");
2392 if (isset($this->thm) || $this->thm !=
'') {
2393 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2395 if (isset($this->tjm) || $this->tjm !=
'') {
2396 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2398 if (isset($this->salary) || $this->salary !=
'') {
2399 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2401 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2402 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2404 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2405 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2406 $sql .=
", entity = ".((int) $this->entity);
2409 $sql .=
", default_range = ".($this->default_range > 0 ? ((int) $this->default_range) :
'null');
2410 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? ((int) $this->default_c_exp_tax_cat) :
'null');
2411 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? ((int) $this->fk_warehouse) :
"null");
2412 $sql .=
", fk_establishment = ".($this->fk_establishment > 0 ? ((int) $this->fk_establishment) :
"null");
2413 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2414 $sql .=
", force_pass_change = ".($this->force_pass_change ? ((int) $this->force_pass_change) :
"0");
2415 $sql .=
" WHERE rowid = ".((int) $this->
id);
2417 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2418 $resql = $this->db->query($sql);
2420 $nbrowsaffected += $this->db->affected_rows($resql);
2423 if (!empty($this->pass)) {
2424 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2426 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2427 if (is_int($result) && $result < 0) {
2434 if ($this->fk_member > 0) {
2435 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2436 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2437 $resql = $this->db->query($sql);
2439 $this->
error = $this->db->error();
2440 $this->db->rollback();
2445 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2446 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2447 $resql = $this->db->query($sql);
2449 $this->
error = $this->db->error();
2450 $this->db->rollback();
2454 if ($nbrowsaffected) {
2455 if ($this->fk_member > 0 && !$nosyncmember) {
2456 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2458 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2463 $result = $adh->fetch($this->fk_member);
2466 $adh->civility_code = $this->civility_code;
2467 $adh->firstname = $this->firstname;
2468 $adh->lastname = $this->lastname;
2469 $adh->login = $this->login;
2470 $adh->gender = $this->gender;
2471 $adh->birth = $this->birth;
2473 $adh->pass = $this->pass;
2475 $adh->address = $this->address;
2476 $adh->town = $this->town;
2477 $adh->zip = $this->zip;
2478 $adh->state_id = $this->state_id;
2479 $adh->country_id = $this->country_id;
2481 $adh->email = $this->email;
2483 $adh->socialnetworks = $this->socialnetworks;
2485 $adh->phone = $this->office_phone;
2486 $adh->phone_mobile = $this->user_mobile;
2488 $adh->default_lang = $this->lang;
2490 $adh->user_id = $this->id;
2491 $adh->user_login = $this->login;
2493 $result = $adh->update($user, 0, 1, 0);
2495 $this->
error = $adh->error;
2496 $this->errors = $adh->errors;
2497 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2500 } elseif ($result < 0) {
2501 $this->
error = $adh->error;
2502 $this->errors = $adh->errors;
2507 if ($this->contact_id > 0 && !$nosynccontact) {
2508 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2510 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2513 $tmpobj =
new Contact($this->db);
2514 $result = $tmpobj->fetch($this->contact_id);
2517 $tmpobj->civility_code = $this->civility_code;
2518 $tmpobj->firstname = $this->firstname;
2519 $tmpobj->lastname = $this->lastname;
2520 $tmpobj->login = $this->login;
2521 $tmpobj->gender = $this->gender;
2522 $tmpobj->birth = $this->birth;
2526 $tmpobj->email = $this->email;
2528 $tmpobj->socialnetworks = $this->socialnetworks;
2530 $tmpobj->phone_pro = $this->office_phone;
2531 $tmpobj->phone_mobile = $this->user_mobile;
2532 $tmpobj->fax = $this->office_fax;
2534 $tmpobj->default_lang = $this->lang;
2536 $tmpobj->address = $this->address;
2537 $tmpobj->town = $this->town;
2538 $tmpobj->zip = $this->zip;
2539 $tmpobj->state_id = $this->state_id;
2540 $tmpobj->country_id = $this->country_id;
2542 $tmpobj->user_id = $this->id;
2543 $tmpobj->user_login = $this->login;
2545 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2547 $this->
error = $tmpobj->error;
2548 $this->errors = $tmpobj->errors;
2549 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2553 $this->
error = $tmpobj->error;
2554 $this->errors = $tmpobj->errors;
2570 if (!$error && !$notrigger) {
2572 $result = $this->call_trigger(
'USER_MODIFY', $user);
2580 $this->db->commit();
2581 return $nbrowsaffected;
2584 $this->db->rollback();
2588 $this->
error = $this->db->lasterror();
2589 $this->db->rollback();
2608 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2609 $sql .=
" datepreviouslogin = datelastlogin,";
2610 $sql .=
" ippreviouslogin = iplastlogin,";
2611 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2612 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2613 $sql .=
" tms = tms";
2614 $sql .=
" WHERE rowid = ".((int) $this->
id);
2616 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2617 $resql = $this->db->query($sql);
2619 $this->datepreviouslogin = $this->datelastlogin;
2620 $this->datelastlogin = $now;
2621 $this->ippreviouslogin = $this->iplastlogin;
2622 $this->iplastlogin = $userremoteip;
2625 $this->
error = $this->db->lasterror().
' sql='.$sql;
2643 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2645 global $conf, $langs;
2646 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2650 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2655 $passwordalreadycrypted = 0;
2659 if (!empty($passwordalreadycrypted)) {
2660 $password_crypted = $password;
2664 require_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/modules_genpassword.php';
2666 if ($modGeneratePass) {
2667 '@phan-var-force ModeleGenPassword $modGeneratePass';
2670 $modGeneratePass->WithoutAmbi = 0;
2673 $testpassword = $modGeneratePass->validatePassword($password);
2674 if (!$testpassword) {
2675 $this->
error = $modGeneratePass->error;
2687 if (!$changelater) {
2688 if (!is_object($this->oldcopy)) {
2689 $this->oldcopy = clone $this;
2696 $sql =
"UPDATE ".$this->db->prefix().
"user";
2697 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2698 $sql .=
" datelastpassvalidation = '".$this->db->idate(
dol_now()).
"',";
2699 $sql .=
" pass_temp = null,";
2700 $sql .=
" force_pass_change = 0";
2701 if (!empty($flagdelsessionsbefore)) {
2702 $sql .=
", flagdelsessionsbefore = '".$this->db->idate($now - 5,
'gmt').
"'";
2705 $sql .=
", pass = null";
2707 $sql .=
", pass = '".$this->db->escape($password).
"'";
2709 $sql .=
" WHERE rowid = ".((int) $this->
id);
2711 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2713 $result = $this->db->query($sql);
2715 if ($this->db->affected_rows($result)) {
2716 $this->pass = $password;
2717 $this->pass_indatabase = $password;
2718 $this->pass_indatabase_crypted = (
string) $password_crypted;
2719 $this->force_pass_change = 0;
2721 if ($this->fk_member && !$nosyncmember) {
2722 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2727 $result = $adh->fetch($this->fk_member);
2730 $result = $adh->setPassword($user, $this->pass, (!
getDolGlobalString(
'DATABASE_PWD_ENCRYPTED') ? 0 : 1), 1);
2731 if (is_int($result) && $result < 0) {
2732 $this->
error = $adh->error;
2737 $this->
error = $adh->error;
2742 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2745 $user->context[
'audit'] =
'login='.$user->login;
2746 if (!empty($flagdelsessionsbefore)) {
2747 $user->context[
'audit'] .=
" - flagdelsessionsbefore set to '".$this->db->idate($now - 5,
'gmt').
"'";
2750 if (!$error && !$notrigger) {
2752 $result = $this->call_trigger(
'USER_NEW_PASSWORD', $user);
2755 $this->db->rollback();
2761 $this->db->commit();
2764 $this->db->rollback();
2768 $this->db->rollback();
2775 $sql =
"UPDATE ".$this->db->prefix().
"user";
2776 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2777 $sql .=
" WHERE rowid = ".((int) $this->
id);
2779 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2780 $result = $this->db->query($sql);
2802 global $conf, $langs;
2805 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2817 $outputlangs = $langs;
2821 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2823 $appli =
getDolGlobalString(
'MAIN_APPLICATION_TITLE', constant(
'DOL_APPLICATION_TITLE'));
2825 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2828 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
2829 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2831 if (!$changelater) {
2832 $url = $urlwithroot.
'/';
2837 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2839 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"\n";
2840 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2841 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2842 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2845 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2847 $mesg .= $user->getFullName($outputlangs);
2850 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2851 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.
$conf->file->instance_unique_id));
2853 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2856 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2860 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2861 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2862 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2863 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2865 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2866 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2867 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2870 $trackid =
'use'.$this->id;
2871 $sendcontext =
'passwordreset';
2892 if ($mailfile->sendfile()) {
2895 $langs->trans(
"errors");
2896 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2908 return $this->error;
2921 $sql =
"SELECT url, login, pass, poste ";
2922 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2923 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2925 $resql = $this->db->query($sql);
2927 if ($this->db->num_rows($resql)) {
2928 $obj = $this->db->fetch_object($resql);
2930 $this->clicktodial_url = $obj->url;
2931 $this->clicktodial_login = $obj->login;
2932 $this->clicktodial_password = $obj->pass;
2933 $this->clicktodial_poste = $obj->poste;
2936 $this->clicktodial_loaded = 1;
2938 $this->db->free($resql);
2941 $this->
error = $this->db->error();
2957 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2958 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2960 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2962 $result = $this->db->query($sql);
2964 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2965 $sql .=
" (fk_user,url,login,pass,poste)";
2966 $sql .=
" VALUES (".((int) $this->
id);
2967 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2968 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2969 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2970 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2972 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2974 $result = $this->db->query($sql);
2976 $this->db->commit();
2979 $this->db->rollback();
2980 $this->
error = $this->db->lasterror();
2998 global $langs, $user;
3004 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
3005 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3006 $sql .=
" AND fk_usergroup = ".((int) $group);
3007 $sql .=
" AND entity = ".((int) $entity);
3009 $result = $this->db->query($sql);
3011 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
3012 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
3014 $result = $this->db->query($sql);
3016 if (!$error && !$notrigger) {
3017 $this->context = array(
'audit' => $langs->trans(
"UserSetInGroup"),
'newgroupid' => $group);
3020 $result = $this->call_trigger(
'USER_MODIFY', $user);
3028 $this->db->commit();
3032 $this->db->rollback();
3036 $this->
error = $this->db->lasterror();
3037 $this->db->rollback();
3054 global $langs, $user;
3060 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
3061 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3062 $sql .=
" AND fk_usergroup = ".((int) $group);
3063 if (empty($entity)) {
3064 $sql .=
" AND entity IN (0, 1)";
3066 $sql .=
" AND entity = ".((int) $entity);
3069 $result = $this->db->query($sql);
3071 if (!$error && !$notrigger) {
3072 $this->context = array(
'audit' => $langs->trans(
"UserRemovedFromGroup"),
'oldgroupid' => $group);
3075 $result = $this->call_trigger(
'USER_MODIFY', $user);
3083 $this->db->commit();
3086 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
3087 $this->db->rollback();
3091 $this->
error = $this->db->lasterror();
3092 $this->db->rollback();
3106 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
3113 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
3136 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
3138 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3139 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
3153 global $conf, $langs, $menumanager;
3154 global $dolibarr_main_demo;
3156 $infologin = $params[
'infologin'] ?? 0;
3157 $option = $params[
'option'] ??
'';
3160 if (!empty($this->photo)) {
3161 $photo =
'<div class="photointooltip floatright">';
3162 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
3164 $data[
'photo'] = $photo;
3169 $data[
'opendiv'] =
'<div class="centpercent divtooltip">';
3170 $data[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
3172 if (!empty($this->login)) {
3175 if (!empty($this->job)) {
3179 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
3180 $phonelist = array();
3181 if ($this->office_phone) {
3182 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
3184 if ($this->office_fax) {
3185 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
3187 if ($this->user_mobile) {
3188 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
3190 $data[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
3192 if (!empty($this->admin)) {
3193 $data[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
3195 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
3196 $langs->load(
"companies");
3197 $data[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
3200 if (!empty($this->socid)) {
3201 $thirdpartystatic =
new Societe($this->db);
3202 $thirdpartystatic->fetch($this->socid);
3204 if (empty($params[
'hidethirdpartylogo'])) {
3205 $companyimg =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3207 $company =
' ('.$langs->trans(
"Company").
': '.($companyimg ? $companyimg :
img_picto(
'',
'company')).
' '.
dol_string_nohtmltag($thirdpartystatic->name).
')';
3209 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
3210 $data[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
3211 $data[
'closediv'] =
'</div>';
3213 if ($infologin > 0) {
3214 $data[
'newlinelogin'] =
'<br>';
3215 $data[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
3218 $data[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.
$conf->entity.
' (User entity '.$this->entity.
')';
3220 $data[
'authentication'] =
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
3221 $data[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
3222 $data[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
3225 $data[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
3227 $data[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
3228 $data[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag(
$conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
3230 $data[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
3231 if (
$conf->browser->layout ==
'phone') {
3232 $data[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
3234 if (!empty($_SESSION[
"disablemodules"])) {
3235 $data[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(implode(
', ', explode(
',', $_SESSION[
"disablemodules"])));
3257 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
3259 global $langs, $hookmanager, $user;
3261 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
3272 'objecttype' => $this->element,
3273 'infologin' => $infologin,
3274 'option' => $option,
3275 'hidethirdpartylogo' => $hidethirdpartylogo,
3277 $classfortooltip =
'classfortooltip';
3280 $classfortooltip =
'classforajaxtooltip';
3281 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3288 if (!empty($this->socid)) {
3289 $thirdpartystatic =
new Societe($this->db);
3290 $thirdpartystatic->fetch($this->socid);
3291 if (empty($hidethirdpartylogo)) {
3292 $companylink =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3296 if ($infologin < 0) {
3300 $baseurl = DOL_URL_ROOT .
'/user/card.php';
3301 if ($option ==
'leave') {
3302 $baseurl = DOL_URL_ROOT .
'/holiday/list.php';
3304 $query = [
'id' => $this->id];
3305 if ($option !=
'nolink') {
3307 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3308 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3309 $add_save_lastsearch_values = 1;
3311 if ($add_save_lastsearch_values) {
3312 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
3317 $linkstart =
'<a href="'.$url.
'"';
3319 if (empty($notooltip)) {
3321 $langs->load(
"users");
3322 $label = $langs->trans(
"ShowUser");
3323 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
3325 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
3326 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
3328 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
3331 $linkstart .= $linkclose.
'>';
3335 $result .= (($option ==
'nolink') ?
'' : $linkstart);
3336 if ($withpictoimg) {
3337 $paddafterimage =
'';
3338 if (abs((
int) $withpictoimg) == 1 || abs((
int) $withpictoimg) == 4) {
3339 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3342 if ($withpictoimg > 0) {
3343 $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>';
3346 $picto =
'<!-- picto photo user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'"'.($paddafterimage ?
' '.$paddafterimage :
'').
'>';
3347 $picto .=
Form::showphoto(
'userphoto', $this, 0, 0, 0,
'userphoto'.(($withpictoimg == -3 || $withpictoimg == -4) ?
'small' :
''),
'mini', 0, 1);
3348 $picto .=
'</span>';
3353 if ($withpictoimg == -4 || ($withpictoimg > -2 && $withpictoimg != 2)) {
3355 $result .=
'<span class="nopadding usertext'.((!isset($this->
status) || $this->status) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
3357 if ($mode ==
'login') {
3363 $result .=
'</span>';
3366 $result .= (($option ==
'nolink') ?
'' : $linkend);
3369 $result .= $companylink;
3372 $hookmanager->initHooks(array(
'userdao'));
3373 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
3374 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3376 $result = $hookmanager->resPrint;
3378 $result .= $hookmanager->resPrint;
3393 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
3395 global $langs, $user;
3399 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3403 if ((!$user->hasRight(
'user',
'user',
'lire') && $this->id != $user->id)) {
3407 if ($option ==
'xxx') {
3408 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3412 if ($option ==
'nolink') {
3417 $result .= $linkstart;
3418 if ($withpictoimg) {
3419 $paddafterimage =
'';
3420 if (abs($withpictoimg) == 1) {
3421 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3424 if ($withpictoimg > 0) {
3425 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3428 $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>';
3432 $result .= $this->login;
3433 $result .= $linkend;
3446 return $this->
LibStatut(isset($this->statut) ? (
int) $this->statut : (int) $this->
status, $mode);
3462 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3465 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3466 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3467 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3468 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3471 $statusType =
'status5';
3472 if ($status == self::STATUS_ENABLED) {
3473 $statusType =
'status4';
3476 $label = $this->labelStatus[$status];
3477 $labelshort = $this->labelStatusShort[$status];
3480 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3481 $statusType =
'status3';
3482 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3484 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3485 $statusType =
'status2';
3486 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3489 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3504 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3506 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3507 $return .=
'<div class="info-box info-box-sm">';
3508 $return .=
'<span class="info-box-icon bg-infobox-action">';
3511 if (!empty($this->photo)) {
3513 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3522 $return .=
'</span>';
3523 $return .=
'<div class="info-box-content">';
3524 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3525 if (
isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3526 $return .=
img_picto($langs->trans(
"SuperAdministratorDesc"),
'superadmin',
'class="valignmiddle paddingright paddingleft"');
3527 } elseif ($this->admin) {
3528 $return .=
img_picto($langs->trans(
"AdministratorDesc"),
'admin',
'class="valignmiddle paddingright paddingleft"');
3530 $return .=
'</span>';
3531 if ($selected >= 0) {
3532 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3534 if (property_exists($this,
'label')) {
3535 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3538 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->
email.
'</span>';
3540 if (method_exists($this,
'getLibStatut')) {
3541 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3543 $return .=
'</div>';
3544 $return .=
'</div>';
3545 $return .=
'</div>';
3569 } elseif ($mode == 1) {
3571 } elseif ($mode == 2) {
3587 global $conf, $langs;
3593 $keymodified =
false;
3602 'LDAP_FIELD_FULLNAME' =>
'fullname',
3603 'LDAP_FIELD_NAME' =>
'lastname',
3604 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3605 'LDAP_FIELD_LOGIN' =>
'login',
3606 'LDAP_FIELD_LOGIN_SAMBA' =>
'login',
3607 'LDAP_FIELD_PHONE' =>
'office_phone',
3608 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3609 'LDAP_FIELD_FAX' =>
'office_fax',
3610 'LDAP_FIELD_MAIL' =>
'email',
3611 'LDAP_FIELD_SID' =>
'ldap_sid',
3615 foreach ($ldapkey as $constname => $varname) {
3621 if (is_object($this->oldcopy) && !$this->oldcopy->isEmpty() && $this->$varname != $this->oldcopy->$varname) {
3622 $keymodified =
true;
3627 foreach ($socialnetworks as $key => $value) {
3628 if (!empty($this->socialnetworks[$value[
'label']]) &&
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))) {
3629 $info[
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))] = $this->socialnetworks[$value[
'label']];
3645 $soc =
new Societe($this->db);
3646 $soc->fetch($this->socid);
3649 if ($soc->client == 1) {
3650 $info[
"businessCategory"] =
"Customers";
3652 if ($soc->client == 2) {
3653 $info[
"businessCategory"] =
"Prospects";
3655 if ($soc->fournisseur == 1) {
3656 $info[
"businessCategory"] =
"Suppliers";
3661 if (!empty($this->pass)) {
3674 if ($this->pass_indatabase_crypted &&
getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED')) {
3678 } elseif (!empty($this->pass_indatabase)) {
3690 $info[
"objectclass"][4] =
"phpgwContact";
3692 $info[
'uidnumber'] = $this->id;
3694 $info[
'phpgwTz'] = 0;
3695 $info[
'phpgwMailType'] =
'INTERNET';
3696 $info[
'phpgwMailHomeType'] =
'INTERNET';
3698 $info[
"phpgwContactTypeId"] =
'n';
3699 $info[
"phpgwContactCatId"] = 0;
3700 $info[
"phpgwContactAccess"] =
"public";
3702 $info[
"phpgwContactOwner"] = 1;
3705 $info[
"rfc822Mailbox"] = $this->email;
3707 if ($this->user_mobile) {
3708 $info[
"phpgwCellTelephoneNumber"] = $this->user_mobile;
3717 $groupslist = $usergroup->listGroupsForUser($this->
id);
3719 if (!empty($groupslist)) {
3720 foreach ($groupslist as $groupforuser) {
3749 $this->
ref =
'SPECIMEN';
3750 $this->specimen = 1;
3751 $this->user_creation_id = $user->id;
3753 $this->lastname =
'DOLIBARR';
3754 $this->firstname =
'SPECIMEN';
3755 $this->gender =
'man';
3756 $this->note_public =
'This is a note public';
3757 $this->note_private =
'This is a note private';
3758 $this->
email =
'email@specimen.com';
3759 $this->personal_email =
'personalemail@specimen.com';
3760 $this->socialnetworks = array(
3761 'skype' =>
'skypepseudo',
3762 'twitter' =>
'twitterpseudo',
3763 'facebook' =>
'facebookpseudo',
3764 'linkedin' =>
'linkedinpseudo',
3766 $this->office_phone =
'0999999999';
3767 $this->office_fax =
'0999999998';
3768 $this->user_mobile =
'0999999997';
3769 $this->personal_mobile =
'0999999996';
3771 $this->login =
'dolibspec';
3772 $this->pass =
'dolibSpec+@123';
3775 $this->datec = $now;
3776 $this->datem = $now;
3778 $this->datelastlogin = $now;
3779 $this->iplastlogin =
'127.0.0.1';
3780 $this->datepreviouslogin = $now;
3781 $this->ippreviouslogin =
'127.0.0.1';
3797 $sql =
"SELECT u.rowid, u.login as ref, u.datec, fk_user_creat as user_creation_id, fk_user_modif as user_modification_id,";
3798 $sql .=
" GREATEST(u.tms, uef.tms) as date_modification, u.entity";
3799 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3800 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user_extrafields as uef ON uef.fk_object = u.rowid";
3801 $sql .=
" WHERE u.rowid = ".((int) $id);
3803 $result = $this->db->query($sql);
3805 if ($this->db->num_rows($result)) {
3806 $obj = $this->db->fetch_object($result);
3808 $this->
id = $obj->rowid;
3810 $this->user_creation_id = $obj->user_creation_id;
3811 $this->user_modification_id = $obj->user_modification_id;
3813 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3814 $this->date_creation = $this->db->jdate($obj->datec);
3815 $this->date_modification = $this->db->jdate($obj->date_modification);
3816 $this->entity = $obj->entity;
3819 $this->db->free($result);
3833 $sql =
"SELECT count(mc.email) as nb";
3834 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3835 $sql .=
" WHERE mc.email = '".$this->db->escape($this->
email).
"'";
3836 $sql .=
" AND mc.statut NOT IN (-1,0)";
3838 $resql = $this->db->query($sql);
3840 $obj = $this->db->fetch_object($resql);
3841 $nb = (int) $obj->nb;
3843 $this->db->free($resql);
3846 $this->
error = $this->db->error();
3861 $sql =
"SELECT count(rowid) as nb";
3862 $sql .=
" FROM ".$this->db->prefix().
"user";
3863 if ($option ==
'superadmin') {
3864 $sql .=
" WHERE entity = 0";
3866 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3867 if ($limitTo ==
'active') {
3868 $sql .=
" AND statut = 1";
3872 $sql .=
" AND admin = ".(int) $admin;
3875 $resql = $this->db->query($sql);
3877 $obj = $this->db->fetch_object($resql);
3878 $nb = (int) $obj->nb;
3880 $this->db->free($resql);
3883 $this->
error = $this->db->lasterror();
3904 $this->firstname = $ldapuser->$tmpvar;
3906 $this->lastname = $ldapuser->$tmpvar;
3908 $this->login = $ldapuser->$tmpvar;
3910 $this->pass = $ldapuser->$tmpvar;
3912 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3915 $this->office_phone = $ldapuser->$tmpvar;
3917 $this->user_mobile = $ldapuser->$tmpvar;
3919 $this->office_fax = $ldapuser->$tmpvar;
3921 $this->
email = $ldapuser->$tmpvar;
3922 foreach ($socialnetworks as $key => $value) {
3924 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3927 $this->ldap_sid = $ldapuser->$tmpvar;
3930 $this->job = $ldapuser->$tmpvar;
3932 $this->note_public = $ldapuser->$tmpvar;
3934 $result = $this->
update($user);
3936 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3952 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3953 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3955 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3956 $res = $this->db->query($sql);
3959 while ($rec = $this->db->fetch_array($res)) {
3960 $user =
new User($this->db);
3961 $user->fetch($rec[
'rowid']);
3979 $this->parentof = array();
3982 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3983 $sql .=
" FROM ".$this->db->prefix().
"user";
3984 $sql .=
" WHERE fk_user <> 0";
3985 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3987 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3988 $resql = $this->db->query($sql);
3990 while ($obj = $this->db->fetch_object($resql)) {
3991 $this->parentof[$obj->id_son] = $obj->id_parent;
4017 global $hookmanager;
4020 $hookmanager->initHooks(array(
'userdao'));
4022 $this->users = array();
4028 $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";
4029 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4031 $parameters = array();
4032 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
4034 $sql .= $hookmanager->resPrint;
4036 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4042 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
4043 $resql = $this->db->query($sql);
4046 while ($obj = $this->db->fetch_object($resql)) {
4047 $this->users[(int) $obj->rowid]
4049 'rowid' => (
int) $obj->rowid,
4050 'id' => (int) $obj->rowid,
4051 'fk_user' => (
int) $obj->fk_user,
4052 'fk_soc' => (int) $obj->fk_soc,
4053 'firstname' => (
string) $obj->firstname,
4054 'lastname' => (
string) $obj->lastname,
4055 'login' => (
string) $obj->login,
4056 'statut' => (int) $obj->statut,
4057 'entity' => (
int) $obj->entity,
4058 'email' => (
string) $obj->email,
4059 'gender' => (
string) $obj->gender,
4060 'admin' => (int) $obj->admin,
4061 'photo' => (
string) $obj->photo,
4075 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
4076 foreach ($this->users as $key => $val) {
4079 $this->
error =
'ErrorLoopInHierarchy';
4085 if ($deleteafterid) {
4087 $keyfilter1 =
'^'.$deleteafterid.
'$';
4088 $keyfilter2 =
'_'.$deleteafterid.
'$';
4089 $keyfilter3 =
'^'.$deleteafterid.
'_';
4090 $keyfilter4 =
'_'.$deleteafterid.
'_';
4091 foreach (array_keys($this->users) as $key) {
4092 $fullpath = (
string) $this->users[$key][
'fullpath'];
4093 if (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
4094 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath)) {
4095 unset($this->users[$key]);
4100 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
4101 $this->users =
dol_sort_array($this->users,
'fullname',
'asc', 1, 0, 1);
4103 return $this->users;
4116 $childids = array();
4118 if (isset($this->cache_childids[$this->
id])) {
4119 $childids = $this->cache_childids[$this->id];
4124 $idtoscan = $this->id;
4126 dol_syslog(
"Build childid for id = ".$idtoscan);
4127 foreach ($this->users as $id => $val) {
4128 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
4129 $childids[$val[
'id']] = $val[
'id'];
4133 $this->cache_childids[$this->id] = $childids;
4135 if ($addcurrentuser) {
4136 $childids[$this->id] = $this->id;
4156 if (!empty($this->users[$id_user][
'fullpath'])) {
4158 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
4163 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
4164 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
4166 $cursor_user = $id_user;
4168 $useridfound = array($id_user);
4169 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
4170 if (in_array($this->parentof[$cursor_user], $useridfound)) {
4171 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
4174 $useridfound[] = $this->parentof[$cursor_user];
4175 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
4176 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
4178 $cursor_user = $this->parentof[$cursor_user];
4182 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
4231 $this->nb = array();
4233 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
4234 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4236 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
4237 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
4238 $sql .=
" AND ug.fk_user = u.rowid";
4240 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4242 $sql .=
" AND u.statut > 0";
4245 $resql = $this->db->query($sql);
4247 while ($obj = $this->db->fetch_object($resql)) {
4248 $this->nb[
"users"] = $obj->nb;
4250 $this->db->free($resql);
4254 $this->
error = $this->db->error();
4270 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4274 $langs->load(
"user");
4281 $modele =
'bluesky';
4285 $modelpath =
"core/modules/user/doc/";
4287 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4301 $user_property =
'';
4303 if (empty($rowid)) {
4307 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
4308 $sql .=
" FROM ".$this->db->prefix().
"user";
4309 $sql .=
" WHERE rowid = ".((int) $rowid);
4311 $resql = $this->db->query($sql);
4313 $nump = $this->db->num_rows($resql);
4316 $obj = $this->db->fetch_object($resql);
4318 if ($mode ==
'email') {
4319 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
4320 } elseif ($mode ==
'mobile') {
4321 $user_property = $obj->user_mobile;
4322 } elseif ($mode ==
'name') {
4326 return $user_property;
4346 $instanceuniqueid = empty(
$conf->file->instance_unique_id) ?
'' :
$conf->file->instance_unique_id;
4347 $encodedsecurekey =
dol_hash($instanceuniqueid.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
4349 $entity_qr =
'&entity='.((int)
$conf->entity);
4354 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
4355 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
4358 if ($typeofurl ==
'internal') {
4359 $urlwithroot = DOL_URL_ROOT;
4362 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
4378 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $entityfilter =
false)
4380 global $conf, $user;
4382 $sql =
"SELECT t.rowid";
4383 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
4385 if ($entityfilter) {
4387 if (!empty($user->admin) && empty($user->entity) &&
$conf->entity == 1) {
4388 $sql .=
" WHERE t.entity IS NOT NULL";
4390 $sql .=
" WHERE t.entity = 0 OR EXISTS (";
4391 $sql .=
" SELECT ug.rowid FROM " . $this->db->prefix() .
"usergroup_user as ug";
4392 $sql .=
" WHERE ug.fk_user = t.rowid AND ug.entity IN (" .
getEntity(
'usergroup') .
"))";
4395 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
4398 $sql .=
" WHERE 1 = 1";
4404 if ($errormessage) {
4405 $this->errors[] = $errormessage;
4406 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
4410 $sql .= $this->db->order($sortfield, $sortorder);
4412 $sql .= $this->db->plimit($limit + 1, $offset);
4417 $resql = $this->db->query($sql);
4419 $this->users = array();
4420 $num = $this->db->num_rows($resql);
4422 while ($obj = $this->db->fetch_object($resql)) {
4423 $line =
new self($this->db);
4424 $result = $line->fetch($obj->rowid);
4425 if ($result > 0 && !empty($line->id)) {
4426 $this->users[$obj->rowid] = clone $line;
4429 $this->db->free($resql);
4433 $this->errors[] = $this->db->lasterror();
4445 private $findUserIdByEmailCache;
4459 if (isset($this->findUserIdByEmailCache[$email])) {
4460 return $this->findUserIdByEmailCache[$email];
4463 $this->findUserIdByEmailCache[$email] = -1;
4465 $sql =
'SELECT rowid';
4466 $sql .=
' FROM '.$this->db->prefix().
'user';
4467 if (
getDolGlobalString(
'AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR')) {
4468 $sql .=
" WHERE email LIKE '%".$this->db->escape($this->db->escapeforlike($email)).
"%'";
4470 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4474 $resql = $this->db->query($sql);
4479 $obj = $this->db->fetch_object($resql);
4484 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4486 return $this->findUserIdByEmailCache[$email];
4497 if (empty($fromId) || empty($toId)) {
4504 $sqlDelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
4505 $sqlDelete .=
" WHERE fk_user = ".((int) $toId);
4507 dol_syslog(get_class($this).
"::clone_rights (delete default permissions)", LOG_DEBUG);
4509 if (!$this->db->query($sqlDelete)) {
4510 $this->db->rollback();
4515 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id)";
4516 $sql .=
" SELECT entity, ".((int) $toId).
", fk_id";
4517 $sql .=
" FROM ".$this->db->prefix().
"user_rights src";
4518 $sql .=
" WHERE fk_user = ".((int) $fromId);
4519 $sql .=
" AND NOT EXISTS (";
4520 $sql .=
" SELECT 1";
4521 $sql .=
" FROM ".$this->db->prefix().
"user_rights dest";
4522 $sql .=
" WHERE dest.entity = src.entity";
4523 $sql .=
" AND dest.fk_user = ".((int) $toId);
4524 $sql .=
" AND dest.fk_id = src.fk_id";
4527 dol_syslog(get_class($this).
"::clone_rights", LOG_DEBUG);
4530 if (!$this->db->query($sql)) {
4531 $this->db->rollback();
4535 $this->db->commit();
4552 $type = $this->table_element;
4555 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4556 $categorystatic =
new Categorie($this->db);
4558 $sql =
"INSERT INTO ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]).
" (fk_categorie, fk_user)";
4559 $sql .=
" SELECT fk_categorie, ".((int) $toId).
" FROM ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]);
4560 $sql .=
" WHERE fk_user = ".((int) $fromId);
4562 if (!$this->db->query($sql)) {
4563 $this->
error = $this->db->lasterror();
4564 $this->db->rollback();
4568 $this->db->commit();
global $dolibarr_main_url_root
Class to manage members of a foundation.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage categories.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
fetchWarehouse($force_warehouse_id=0)
Load the warehouse of object, from id $this->warehouse_id or $this->fk_warehouse, into this->warehous...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
static commonReplaceContact(DoliDB $dbs, $origin_id, $dest_id, array $tables, $fieldname='fk_socpeople', $ignoreerrors=0)
Function used to replace a contact id with another one.
Class to manage Dolibarr database access.
Class to manage warehouses.
static loadAndInstantiate($id, $db, $conf, $langs, $user)
Locate, load and instantiate a password generator/validator model by its id (the value stored in USER...
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage user groups.
Class to manage Dolibarr users.
fetch($id=0, $login='', $sid='', $loadpersonalconf=0, $entity=-1, $email='', $fk_socpeople=0, $use_email_oauth2=0)
Load a user from database with its id or ref (login).
SetInGroup($group, $entity, $notrigger=0)
Add user into a group.
LibStatut($status, $mode=0)
Return the label of a status of user (active, inactive)
loadRights($moduletag='', $forcereload=0)
Load permissions granted to a user->id into object user->rights.
get_children()
Return and array with all instantiated first level children users of current user.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
loadStateBoard()
Load metrics this->nb for dashboard.
hasRight($module, $permlevel1, $permlevel2='')
Return if a user has a permission.
info($id)
Load info of user object.
create_from_contact($contact, $login='', $password='')
Create a user from a contact object.
setstatus($status)
Change status of a user.
get_full_tree($deleteafterid=0, $filter='')
Build the hierarchy/tree of users into an array.
_load_ldap_info()
Initialize the info array (array of LDAP values) that will be used to call LDAP functions.
delrights($rid, $allmodule='', $allperms='', $entity=0, $notrigger=0)
Remove a right to the user.
update_last_login_date()
Update the user's last login date in the database.
__construct($db)
Constructor of the class.
RemoveFromGroup($group, $entity, $notrigger=0)
Remove a user from a group.
isNotIntoValidityDateRange()
Return a link with photo Use this->id,this->photo.
getNbOfUsers($limitTo, $option='', $admin=-1)
Return number of existing users.
set_default_rights()
Assign rights by default.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND', $entityfilter=false)
Load all objects into $this->users.
getOnlineVirtualCardUrl($mode='', $typeofurl='external')
Return string with full Url to virtual card.
update($user, $notrigger=0, $nosyncmember=0, $nosyncmemberpass=0, $nosynccontact=0)
Update a user into database (and also password if this->pass is defined)
getLoginUrl($withpictoimg=0, $option='', $notooltip=0, $morecss='')
Return clickable link of login (optionally with picto)
setCategories($categories)
Sets object to supplied categories.
loadParentOf()
Load this->parentof that is array(id_son=>id_parent, ...)
setForcePasswordChange($user, $value)
Set force password change flag.
fetch_clicktodial()
Read clicktodial information for user.
build_path_from_id_user($id_user, $protection=0)
For user id_user and its children available in this->users, define property fullpath and fullname.
error()
Returns the last functional error when manipulating the object.
cloneCategories($fromId, $toId, $type='user')
Copy related categories to another object.
getAllChildIds($addcurrentuser=0)
Return list of all child user ids in hierarchy (all sublevels).
initAsSpecimen()
Initialise an instance with random values.
setPassword($user, $password='', $changelater=0, $notrigger=0, $nosyncmember=0, $passwordalreadycrypted=0, $flagdelsessionsbefore=1)
Change password of a user.
getNomUrl($withpictoimg=0, $option='', $infologin=0, $notooltip=0, $maxlen=24, $hidethirdpartylogo=0, $mode='', $morecss='', $save_lastsearch_value=-1)
Return a HTML link to the user card (with optionally the picto) Use this->id,this->lastname,...
clearrights()
Clear all permissions array of user.
update_clicktodial()
Update clicktodial info.
cloneRights($fromId, $toId)
Clone permissions of user.
isExternalUser()
Return if a user is an external user It replaces old syntax: if ($user->socid)
getLibStatut($mode=0)
Return the label of the status of user (active, inactive)
create_from_member($member, $login='')
Create a user into database from a member object.
_load_ldap_dn($info, $mode=0)
Returns the complete DN (Distinguished Name) string in the LDAP directory for the object.
loadDefaultValues()
Load default values from database table into property ->default_values.
getPhotoUrl($width, $height, $cssclass='', $imagesize='')
Return a link with photo Use this->id,this->photo.
isAdmin()
Return if a user is an admin user It replaces old syntax: if ($user->admin)
update_ldap2dolibarr(&$ldapuser)
Update user using data from the LDAP.
getrights($moduletag='', $forcereload=0)
Load permissions granted to a user->id into object user->rights TODO Remove this method.
user_get_property($rowid, $mode)
Return property of user from its id.
send_password($user, $password='', $changelater=0)
Send a new password (or instructions to reset it) by email.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (optionally with picto)
getNbOfEMailings()
Return number of mass Emailing received by this contacts with its email.
addrights($rid, $allmodule='', $allperms='', $entity=0, $notrigger=0)
Add a right to the user.
create($user, $notrigger=0)
Create a user into database.
loadPersonalConf($entity=-1)
Load const values from database table user_param and set it into user->conf->XXX.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
findUserIdByEmail($email)
Find a user by the given e-mail and return it's user id when found.
getTooltipContentArray($params)
getTooltipContentArray
static replaceContact(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a contact id with another one when merging two contacts.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
dol_now($mode='gmt')
Return date for now.
getDolGlobalLoginBadCharUnauthorized()
Return the list of unauthorized characters in user logins.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
getArrayOfSocialNetworks()
Get array of social network dictionary.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
div refaddress div address
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.
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)
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
conf($dolibarr_main_document_root, $realpathconf=null)
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
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.