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 public $usergroup_entity;
364 private $_tab_loaded = array();
374 public $default_values;
379 public $lastsearch_values_tmp;
383 public $lastsearch_values;
388 public $users = array();
396 private $cache_childids;
402 public $accountancy_code_user_general;
407 public $accountancy_code;
439 public $dateemployment;
443 public $dateemploymentend;
448 public $default_c_exp_tax_cat;
453 public $ref_employee;
458 public $national_registration_number;
463 public $default_range;
469 public $fk_warehouse;
474 public $fk_establishment;
479 public $label_establishment;
486 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
487 'lastname' => array(
'type' =>
'varchar(50)',
'label' =>
'Lastname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 20,
'searchall' => 1),
488 'firstname' => array(
'type' =>
'varchar(50)',
'label' =>
'Firstname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 10,
'searchall' => 1),
489 '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,
'bi' => 0),
490 'ref_employee' => array(
'type' =>
'varchar(50)',
'label' =>
'RefEmployee',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 30,
'searchall' => 1),
491 'national_registration_number' => array(
'type' =>
'varchar(50)',
'label' =>
'NationalRegistrationNumber',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 40,
'searchall' => 1)
494 const STATUS_DISABLED = 0;
495 const STATUS_ENABLED = 1;
506 $this->ismultientitymanaged = 1;
507 $this->isextrafieldmanaged = 1;
509 $this->clicktodial_loaded = 0;
512 $this->all_permissions_are_loaded = 0;
513 $this->nb_rights = 0;
521 $this->rights->user =
new stdClass();
522 $this->rights->user->user =
new stdClass();
523 $this->rights->user->self =
new stdClass();
524 $this->rights->user->user_advance =
new stdClass();
525 $this->rights->user->self_advance =
new stdClass();
526 $this->rights->user->group_advance =
new stdClass();
543 public function fetch($id = 0, $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'', $fk_socpeople = 0, $use_email_oauth2 = 0)
548 $login = trim($login);
551 $sql =
"SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.civility as civility_code, u.birth, u.job,";
552 $sql .=
" u.email, u.email_oauth2, u.personal_email,";
553 $sql .=
" u.socialnetworks,";
554 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
555 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
556 $sql .=
" u.admin, u.login, u.note_private, u.note_public,";
557 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.force_pass_change, u.api_key,";
558 $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,";
559 $sql .=
" fk_user_creat as user_creation_id, fk_user_modif as user_modification_id,";
560 $sql .=
" u.statut as status, u.lang, u.entity,";
561 $sql .=
" u.datec as datec,";
562 $sql .=
" GREATEST(u.tms, COALESCE(uef.tms, u.tms)) as datem,";
563 $sql .=
" u.datelastlogin as datel,";
564 $sql .=
" u.datepreviouslogin as datep,";
565 $sql .=
" u.flagdelsessionsbefore,";
566 $sql .=
" u.iplastlogin,";
567 $sql .=
" u.ippreviouslogin,";
568 $sql .=
" u.datelastpassvalidation,";
569 $sql .=
" u.datestartvalidity,";
570 $sql .=
" u.dateendvalidity,";
571 $sql .=
" u.photo as photo,";
572 $sql .=
" u.openid as openid,";
573 $sql .=
" u.accountancy_code_user_general,";
574 $sql .=
" u.accountancy_code,";
577 $sql .=
" u.salary,";
578 $sql .=
" u.salaryextra,";
579 $sql .=
" u.weeklyhours,";
581 $sql .=
" u.dateemployment, u.dateemploymentend,";
582 $sql .=
" u.fk_warehouse,";
583 $sql .=
" u.ref_ext,";
584 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
585 $sql .=
" u.national_registration_number,";
586 $sql .=
" u.ref_employee,";
587 $sql .=
" c.code as country_code, c.label as country,";
588 $sql .=
" d.code_departement as state_code, d.nom as state,";
589 $sql .=
" s.label as label_establishment, u.fk_establishment";
590 $sql .=
" FROM ".$this->db->prefix().
"user as u";
591 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user_extrafields as uef ON uef.fk_object = u.rowid";
592 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as c ON u.fk_country = c.rowid";
593 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_departements as d ON u.fk_state = d.rowid";
594 $sql .=
" LEFT JOIN ".$this->db->prefix().
"establishment as s ON u.fk_establishment = s.rowid";
597 $sql .=
" WHERE u.rowid = ".((int) $id);
601 $sql .=
" WHERE u.entity IN (0, " . ((int)
$conf->entity) .
")";
603 $sql .=
" WHERE u.entity IS NOT NULL";
608 $sql .=
" WHERE u.entity IS NOT NULL";
610 if ($entity !=
'' && $entity == 0) {
611 $sql .=
" WHERE u.entity = 0";
613 $sql .=
" WHERE u.entity IN (0, " . ((int) ($entity > 0 ? ((
int) $entity) : ((int)
$conf->entity))) .
")";
621 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->db->escape($login).
"')";
623 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
625 $sql .=
" AND (u.email = '".$this->db->escape($email).
"'";
626 if ($use_email_oauth2) {
627 $sql .=
" OR u.email_oauth2 = '".$this->db->escape($email).
"'";
630 } elseif ($fk_socpeople > 0) {
631 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
634 $sql .=
" ORDER BY u.entity ASC";
638 $sql .=
' '.$this->db->plimit(1);
641 $resql = $this->db->query($sql);
643 $num = $this->db->num_rows($resql);
645 $this->
error =
"USERDUPLICATEFOUND";
646 dol_syslog(get_class($this).
"::fetch more than 1 user found", LOG_WARNING);
648 $this->db->free($resql);
652 $obj = $this->db->fetch_object($resql);
654 $this->
id = $obj->rowid;
655 $this->
ref = $obj->rowid;
657 $this->ref_ext = $obj->ref_ext;
659 $this->ldap_sid = $obj->ldap_sid;
660 $this->civility_code = $obj->civility_code;
661 $this->lastname = $obj->lastname;
662 $this->firstname = $obj->firstname;
663 $this->ref_employee = $obj->ref_employee;
664 $this->national_registration_number = $obj->national_registration_number;
666 $this->employee = $obj->employee;
668 $this->login = $obj->login;
669 $this->gender = $obj->gender;
670 $this->birth = $this->db->jdate($obj->birth);
671 $this->pass_indatabase = $obj->pass;
672 $this->pass_indatabase_crypted = $obj->pass_crypted;
673 $this->pass = $obj->pass;
674 $this->pass_temp = $obj->pass_temp;
676 $this->force_pass_change = $obj->force_pass_change;
677 $this->datelastpassvalidation = $this->db->jdate($obj->datelastpassvalidation);
681 $this->
address = $obj->address;
682 $this->zip = $obj->zip;
683 $this->town = $obj->town;
685 $this->country_id = $obj->country_id;
686 $this->country_code = $obj->country_id ? $obj->country_code :
'';
689 $this->state_id = $obj->state_id;
690 $this->state_code = $obj->state_code;
691 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
693 $this->office_phone = $obj->office_phone;
694 $this->office_fax = $obj->office_fax;
695 $this->user_mobile = $obj->user_mobile;
696 $this->personal_mobile = $obj->personal_mobile;
697 $this->
email = $obj->email;
698 $this->email_oauth2 = $obj->email_oauth2;
699 $this->personal_email = $obj->personal_email;
700 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
701 $this->user_creation_id = $obj->user_creation_id;
702 $this->user_modification_id = $obj->user_modification_id;
704 $this->job = $obj->job;
705 $this->signature = $obj->signature;
706 $this->admin = $obj->admin;
707 $this->note_public = $obj->note_public;
708 $this->note_private = $obj->note_private;
710 $this->statut = $obj->status;
711 $this->
status = $obj->status;
713 $this->photo = $obj->photo;
714 $this->openid = $obj->openid;
715 $this->lang = $obj->lang;
716 $this->entity = $obj->entity;
718 $this->accountancy_code_user_general = $obj->accountancy_code_user_general;
719 $this->accountancy_code = $obj->accountancy_code;
721 $this->thm = $obj->thm;
722 $this->tjm = $obj->tjm;
723 $this->salary = $obj->salary;
724 $this->salaryextra = $obj->salaryextra;
725 $this->weeklyhours = $obj->weeklyhours;
726 $this->color = $obj->color;
727 $this->dateemployment = $this->db->jdate($obj->dateemployment);
728 $this->dateemploymentend = $this->db->jdate($obj->dateemploymentend);
730 $this->datec = $this->db->jdate($obj->datec);
731 $this->datem = $this->db->jdate($obj->datem);
732 $this->datelastlogin = $this->db->jdate($obj->datel);
733 $this->datepreviouslogin = $this->db->jdate($obj->datep);
734 $this->flagdelsessionsbefore = $this->db->jdate($obj->flagdelsessionsbefore,
'gmt');
735 $this->iplastlogin = $obj->iplastlogin;
736 $this->ippreviouslogin = $obj->ippreviouslogin;
737 $this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
738 $this->dateendvalidity = $this->db->jdate($obj->dateendvalidity);
740 $this->socid = $obj->fk_soc;
741 $this->contact_id = $obj->fk_socpeople;
742 $this->fk_member = $obj->fk_member;
743 $this->fk_user = $obj->fk_user;
744 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
745 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
747 $this->default_range = $obj->default_range;
748 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
749 $this->fk_warehouse = $obj->fk_warehouse;
750 $this->warehouse_id = $obj->fk_warehouse;
751 $this->warehouse =
null;
752 $this->fk_establishment = $obj->fk_establishment;
753 $this->label_establishment = $obj->label_establishment;
757 if (!
isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
769 $this->db->free($resql);
771 $this->
error =
"USERNOTFOUND";
772 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
774 $this->db->free($resql);
778 $this->
error = $this->db->lasterror();
783 if ($loadpersonalconf) {
789 $this->
error = $this->db->lasterror();
796 if (
GETPOSTINT(
'forceexternaluser') && $this->admin && empty($this->socid)) {
797 $this->socid =
GETPOSTINT(
'forceexternaluser');
815 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
816 $sql .=
" WHERE fk_user = ".((int) $this->
id);
818 $sql .=
" AND entity IN (0, ".((int)
$conf->entity).
")";
820 $sql .=
" AND entity = ".((int) $entity);
824 $resql = $this->db->query($sql);
826 $num = $this->db->num_rows($resql);
829 $obj = $this->db->fetch_object($resql);
830 $p = (!empty($obj->param) ? $obj->param :
'');
832 $this->
conf->$p = $obj->value;
836 $this->db->free($resql);
840 $this->
error = $this->db->lasterror();
857 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
860 $result = $defaultValues->fetchAll(
'',
'', 0, 0,
'(t.user_id:in:0,'.$this->
id.
') AND (entity:in:'.(isset($this->entity) ? $this->entity :
$conf->entity).
','.
$conf->entity.
')');
863 if (!is_array($result) && $result < 0) {
864 $this->
error = $defaultValues->error;
865 $this->errors = $defaultValues->errors;
866 dol_print_error($this->db);
868 } elseif (count($result) > 0) {
869 foreach ($result as $defval) {
870 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
871 $pagewithoutquerystring = $defval->page;
874 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
875 $pagewithoutquerystring = $reg[1];
876 $pagequeries = $reg[2];
878 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
882 if (!empty($this->default_values)) {
883 foreach ($this->default_values as $a => $b) {
884 foreach ($b as
$c => $d) {
885 krsort($this->default_values[$a][
$c]);
926 public function hasRight($module, $permlevel1, $permlevel2 =
'')
929 $moduletomoduletouse = array(
930 'category' =>
'categorie',
931 'compta' =>
'comptabilite',
932 'contract' =>
'contrat',
933 'member' =>
'adherent',
935 'order' =>
'commande',
936 'produit' =>
'product',
937 'productlot' =>
'product',
938 'project' =>
'projet',
939 'propale' =>
'propal',
940 'shipping' =>
'expedition',
941 'task' =>
'task@projet',
942 'fichinter' =>
'ficheinter',
943 'intervention' =>
'ficheinter',
944 'inventory' =>
'stock',
945 'invoice' =>
'facture',
946 'invoice_supplier' =>
'facture@fournisseur',
947 'order_supplier' =>
'fournisseur',
948 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
949 'skill@hrm' =>
'all@hrm',
950 'job@hrm' =>
'all@hrm',
951 'position@hrm' =>
'all@hrm',
952 'facturerec' =>
'facture',
953 'margins' =>
'margin',
956 if (!empty($moduletomoduletouse[$module])) {
968 $supplierNewToLegacy = array(
969 'supplier_order' => array(
'fournisseur',
'commande'),
970 'supplier_invoice' => array(
'fournisseur',
'facture'),
973 if (isset($supplierNewToLegacy[
$module])) {
976 $permlevel2 = $permlevel1;
977 $permlevel1 = $supplierNewToLegacy[
$module][1];
983 $supplierLegacyCompat = array(
984 'supplier_order' =>
'fournisseur',
985 'supplier_invoice' =>
'fournisseur',
988 if (isset($supplierLegacyCompat[
$module])) {
994 $moduleRightsMapping = array(
995 'product' =>
'produit',
996 'margin' =>
'margins',
997 'comptabilite' =>
'compta'
1001 if (!empty($moduleRightsMapping[$rightsPath])) {
1002 $rightsPath = $moduleRightsMapping[$rightsPath];
1006 $tmp = explode(
'@', $rightsPath, 2);
1007 if (!empty($tmp[1])) {
1008 if (strpos(
$module,
'@') !==
false) {
1011 if ($tmp[0] != $tmp[1]) {
1013 $rightsPath = $tmp[1];
1014 $permlevel2 = $permlevel1;
1015 $permlevel1 = $tmp[0];
1018 $rightsPath = $tmp[1];
1030 if (!empty($this->socid)) {
1031 if (
$module ==
'societe' && ($permlevel1 ==
'creer' || $permlevel1 ==
'write')) {
1034 if (
$module ==
'societe' && $permlevel1 ==
'client' && $permlevel2 ==
'voir') {
1037 if (
$module ==
'societe' && $permlevel1 ==
'export') {
1040 if (
$module ==
'societe' && ($permlevel1 ==
'supprimer' || $permlevel1 ==
'delete')) {
1046 if ($permlevel1 ==
'propale') {
1047 $permlevel1 =
'propal';
1049 if ($permlevel1 ==
'member') {
1050 $permlevel1 =
'adherent';
1052 if ($permlevel1 ==
'recruitmentcandidature') {
1053 $permlevel1 =
'recruitmentjobposition';
1056 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
1061 if (!empty($this->rights->$rightsPath->$permlevel1)) {
1062 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
1063 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
1067 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
1068 return $this->rights->$rightsPath->$permlevel1->lire;
1070 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
1071 return $this->rights->$rightsPath->$permlevel1->creer;
1073 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
1074 return $this->rights->$rightsPath->$permlevel1->create;
1076 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
1077 return $this->rights->$rightsPath->$permlevel1->supprimer;
1081 if (!empty($this->rights->$rightsPath->$permlevel1)) {
1082 return $this->rights->$rightsPath->$permlevel1;
1086 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
1087 return $this->rights->$rightsPath->lire;
1089 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
1090 return $this->rights->$rightsPath->creer;
1092 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
1093 return $this->rights->$rightsPath->create;
1095 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
1096 return $this->rights->$rightsPath->supprimer;
1114 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1116 global $conf, $user, $langs;
1118 $entity = (empty($entity) ?
$conf->entity : $entity);
1120 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
1122 if (empty($this->
id)) {
1123 $this->
error =
'Try to call addrights on an object user with an empty id';
1133 $module = $perms = $subperms =
'';
1136 $sql =
"SELECT module, perms, subperms";
1137 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1138 $sql .=
" WHERE id = ".((int) $rid);
1139 $sql .=
" AND entity = ".((int) $entity);
1141 $result = $this->db->query($sql);
1143 $obj = $this->db->fetch_object($result);
1146 $module = $obj->module;
1147 $perms = $obj->perms;
1148 $subperms = $obj->subperms;
1152 dol_print_error($this->db);
1156 $whereforadd =
"id=".((int) $rid);
1158 if (!empty($subperms)) {
1159 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
1160 } elseif (!empty($perms)) {
1161 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND (subperms IS NULL or subperms = ''))";
1167 if (!empty($allmodule)) {
1168 if ($allmodule ==
'allmodules') {
1169 $whereforadd =
'allmodules';
1171 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
1172 if (!empty($allperms)) {
1173 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
1181 if (!empty($whereforadd)) {
1184 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1185 $sql .=
" WHERE entity = ".((int) $entity);
1186 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
1187 $sql .=
" AND (".$whereforadd.
")";
1190 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1191 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1193 $sqldelete .=
") AND entity = ".((int) $entity);
1194 if (!$this->db->query($sqldelete)) {
1199 $resql = $this->db->query($sql);
1201 $num = $this->db->num_rows($resql);
1204 $obj = $this->db->fetch_object($resql);
1209 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
1210 if (!$this->db->query($sql)) {
1219 dol_print_error($this->db);
1224 if (!$error && !$notrigger) {
1225 $langs->load(
"other");
1226 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
1229 $result = $this->call_trigger(
'USER_MODIFY', $user);
1237 $this->db->rollback();
1240 $this->db->commit();
1257 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1259 global $conf, $user, $langs;
1263 $entity = (!empty($entity) ? $entity :
$conf->entity);
1268 $module = $perms = $subperms =
'';
1272 $sql =
"SELECT module, perms, subperms";
1273 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1274 $sql .=
" WHERE id = ".((int) $rid);
1275 $sql .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1277 $result = $this->db->query($sql);
1279 $obj = $this->db->fetch_object($result);
1282 $module = $obj->module;
1283 $perms = $obj->perms;
1284 $subperms = $obj->subperms;
1288 dol_print_error($this->db);
1292 $wherefordel =
"id=".((int) $rid);
1294 if ($subperms ==
'lire' || $subperms ==
'read') {
1295 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1297 if ($perms ==
'lire' || $perms ==
'read') {
1298 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1304 if (!empty($allmodule)) {
1305 if ($allmodule ==
'allmodules') {
1306 $wherefordel =
'allmodules';
1308 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1309 if (!empty($allperms)) {
1310 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1317 if (!empty($wherefordel)) {
1320 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1321 $sql .=
" WHERE entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1322 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1323 $sql .=
" AND (".$wherefordel.
")";
1327 if ($this->admin == 1) {
1328 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1329 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1330 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1331 $sql .=
" AND id NOT IN (358)";
1334 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1335 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1338 $sqldelete .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1340 $resql = $this->db->query($sqldelete);
1343 dol_print_error($this->db);
1347 if (!$error && !$notrigger) {
1348 $langs->load(
"other");
1349 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1352 $result = $this->call_trigger(
'USER_MODIFY', $user);
1360 $this->db->rollback();
1363 $this->db->commit();
1377 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1379 $this->nb_rights = 0;
1380 $this->all_permissions_are_loaded = 0;
1381 $this->_tab_loaded = array();
1397 $alreadyloaded =
false;
1399 if (empty($forcereload)) {
1400 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1402 $alreadyloaded =
true;
1405 if (!empty($this->all_permissions_are_loaded)) {
1407 $alreadyloaded =
true;
1412 if (!isset($this->rights) || !is_object($this->rights)) {
1415 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1416 $this->rights->user =
new stdClass();
1421 if (!$alreadyloaded) {
1423 $sql =
"SELECT DISTINCT r.module, r.module_origin, r.perms, r.subperms";
1424 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1425 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1426 $sql .=
" WHERE r.id = ur.fk_id";
1432 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') ?
"1," :
"").((
int)
$conf->entity).
")";
1436 $sql .=
" AND r.entity = ".((int)
$conf->entity).
" AND ur.entity = ".((int)
$conf->entity);
1438 $sql .=
" AND ur.fk_user = ".((int) $this->
id);
1439 $sql .=
" AND r.perms IS NOT NULL";
1441 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1444 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1447 $resql = $this->db->query($sql);
1449 $num = $this->db->num_rows($resql);
1452 $obj = $this->db->fetch_object($resql);
1460 $module = (!empty($obj->module_origin) ? $obj->module_origin : $obj->module);
1461 $perms = $obj->perms;
1462 $subperms = $obj->subperms;
1464 if (!empty($perms)) {
1465 if (!empty($module)) {
1466 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1467 $this->rights->$module =
new stdClass();
1469 if (!empty($subperms)) {
1470 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1471 $this->rights->$module->$perms =
new stdClass();
1473 if (empty($this->rights->$module->$perms->$subperms)) {
1476 $this->rights->$module->$perms->$subperms = 1;
1478 if (empty($this->rights->$module->$perms)) {
1481 $this->rights->$module->$perms = 1;
1488 $this->db->free($resql);
1492 $sql =
"SELECT DISTINCT r.module, r.module_origin, r.perms, r.subperms, r.entity";
1493 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1494 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1495 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1496 $sql .=
" WHERE r.id = gr.fk_id";
1502 $sql .=
" AND gu.entity IN (0,".((int)
$conf->entity).
")";
1504 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1507 $sql .=
" AND gr.entity = ".((int)
$conf->entity);
1511 $sql .=
" AND gu.entity IN (0,".((int)
$conf->entity).
")";
1512 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1515 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1516 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1517 $sql .=
" AND r.perms IS NOT NULL";
1519 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1522 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1525 $resql = $this->db->query($sql);
1527 $num = $this->db->num_rows($resql);
1530 $obj = $this->db->fetch_object($resql);
1538 $module = (!empty($obj->module_origin) ? $obj->module_origin : $obj->module);
1539 $perms = $obj->perms;
1540 $subperms = $obj->subperms;
1542 if (!empty($perms)) {
1543 if (!empty($module)) {
1544 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1545 $this->rights->$module =
new stdClass();
1547 if (!empty($subperms)) {
1548 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1549 $this->rights->$module->$perms =
new stdClass();
1551 if (empty($this->rights->$module->$perms->$subperms)) {
1554 $this->rights->$module->$perms->$subperms = 1;
1557 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1558 if (empty($this->rights->$module->$perms)) {
1561 $this->rights->$module->$perms = 1;
1569 $this->db->free($resql);
1573 if (!empty($this->admin)) {
1574 if (empty($this->rights->user->user)) {
1575 $this->rights->user->user =
new stdClass();
1577 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1578 foreach ($listofpermtotest as $permtotest) {
1579 if (empty($this->rights->user->user->$permtotest)) {
1580 $this->rights->user->user->$permtotest = 1;
1584 if (empty($this->rights->user->self)) {
1585 $this->rights->user->self =
new stdClass();
1587 $listofpermtotest = array(
'creer',
'password');
1588 foreach ($listofpermtotest as $permtotest) {
1589 if (empty($this->rights->user->self->$permtotest)) {
1590 $this->rights->user->self->$permtotest = 1;
1596 if (empty($this->rights->user->user_advance)) {
1597 $this->rights->user->user_advance =
new stdClass();
1599 $listofpermtotest = array(
'readperms',
'write');
1600 foreach ($listofpermtotest as $permtotest) {
1601 if (empty($this->rights->user->user_advance->$permtotest)) {
1602 $this->rights->user->user_advance->$permtotest = 1;
1606 if (empty($this->rights->user->self_advance)) {
1607 $this->rights->user->self_advance =
new stdClass();
1609 $listofpermtotest = array(
'readperms',
'writeperms');
1610 foreach ($listofpermtotest as $permtotest) {
1611 if (empty($this->rights->user->self_advance->$permtotest)) {
1612 $this->rights->user->self_advance->$permtotest = 1;
1616 if (empty($this->rights->user->group_advance)) {
1617 $this->rights->user->group_advance =
new stdClass();
1619 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1620 foreach ($listofpermtotest as $permtotest) {
1621 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1622 $this->rights->user->group_advance->$permtotest = 1;
1630 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1631 $this->rights->propal = $this->rights->propale;
1633 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1634 $this->rights->propale = $this->rights->propal;
1641 $this->all_permissions_are_loaded = 1;
1644 $this->_tab_loaded[$moduletag] = 1;
1661 public function getrights($moduletag =
'', $forcereload = 0)
1674 global $conf, $langs, $user;
1679 if (isset($this->
status)) {
1680 if ($this->
status == $status) {
1683 } elseif (isset($this->statut) && $this->statut == $status) {
1690 $sql =
"UPDATE ".$this->db->prefix().
"user";
1691 $sql .=
" SET statut = ".((int) $status);
1692 $sql .=
" WHERE rowid = ".((int) $this->
id);
1693 $result = $this->db->query($sql);
1695 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1698 $this->context[
'actionmsg'] =
'User '.$this->login.
' disabled';
1700 $this->context[
'actionmsg'] =
'User '.$this->login.
' enabled';
1703 $result = $this->call_trigger(
'USER_ENABLEDISABLE', $user);
1711 $this->db->rollback();
1715 $this->statut = $status;
1716 $this->db->commit();
1732 $value = (int) $value;
1735 if ($this->force_pass_change == $value) {
1742 $sql =
"UPDATE ".$this->db->prefix().
"user";
1743 $sql .=
" SET force_pass_change = ".((int) $value);
1744 $sql .=
" WHERE rowid = ".((int) $this->
id);
1745 $result = $this->db->query($sql);
1747 dol_syslog(get_class($this).
"::setForcePasswordChange", LOG_DEBUG);
1749 $this->force_pass_change = $value;
1751 $result = $this->call_trigger(
'USER_MODIFY', $user);
1758 $this->
error = $this->db->lasterror();
1762 $this->db->rollback();
1765 $this->db->commit();
1782 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1783 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1798 $this->
fetch($this->
id);
1800 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1807 'hrm_evaluation' => array(
'label' =>
'EvaluationCard',
'filter' =>
"fk_user = ".((
int) $this->
id)),
1808 'hrm_job_user' => array(
'label' =>
'EmployeePosition',
'filter' =>
"fk_user = ".((
int) $this->
id)),
1809 'hrm_skillrank' => array(
'label' =>
'Skill',
'filter' =>
"objecttype = 'user' AND fk_object = ".((
int) $this->
id)),
1811 foreach ($hrmtables as $hrmtable => $sanitizedhrminfo) {
1812 $sanitizedfilter = $sanitizedhrminfo[
'filter'];
1813 $sql =
"SELECT COUNT(rowid) as nb FROM ".$this->db->prefix().$this->db->sanitize($hrmtable).
" WHERE ".$sanitizedfilter;
1814 $resql = $this->db->query($sql);
1816 $obj = $this->db->fetch_object($resql);
1817 if ($obj && $obj->nb > 0) {
1818 $langs->loadLangs(array(
'errors',
'hrm'));
1819 $this->
error = $langs->trans(
"ErrorRecordHasAtLeastOneChildOfType", $this->login, $langs->transnoentitiesnoconv($sanitizedhrminfo[
'label']));
1820 $this->errors[] = $this->error;
1821 $this->db->rollback();
1829 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1831 if (!$error && !$this->db->query($sql)) {
1833 $this->
error = $this->db->lasterror();
1837 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1838 if (!$error && !$this->db->query($sql)) {
1840 $this->
error = $this->db->lasterror();
1844 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1845 if (!$error && !$this->db->query($sql)) {
1847 $this->
error = $this->db->lasterror();
1851 $sql =
"DELETE FROM ".$this->db->prefix().
"bookmark WHERE fk_user = ".((int) $this->
id);
1852 if (!$error && !$this->db->query($sql)) {
1854 $this->
error = $this->db->lasterror();
1858 if ($this->contact_id > 0) {
1859 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1860 if (!$error && !$this->db->query($sql)) {
1862 $this->
error = $this->db->lasterror();
1871 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1877 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1878 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1879 if (!$this->db->query($sql)) {
1881 $this->
error = $this->db->lasterror();
1887 $result = $this->call_trigger(
'USER_DELETE', $user);
1890 $this->db->rollback();
1895 $this->db->commit();
1898 $this->db->rollback();
1910 public function create($user, $notrigger = 0)
1912 global $conf, $langs;
1918 $this->civility_code = trim((
string) $this->civility_code);
1919 $this->login = trim((
string) $this->login);
1920 $this->user_creation_id = (int) $user->id;
1921 if (!isset($this->entity)) {
1922 $this->entity =
$conf->entity;
1924 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1930 $langs->load(
"errors");
1931 $this->
error = $langs->trans(
"ErrorBadEMail", $this->
email);
1934 if (empty($this->login)) {
1935 $langs->load(
"errors");
1936 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1938 } elseif ($badCharUnauthorizedIntoLoginName !==
'' && preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1939 $langs->load(
"errors");
1940 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1951 $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).
"'";
1952 $resqltochecklogin = $this->db->query($sqltochecklogin);
1953 if ($resqltochecklogin) {
1954 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1955 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1956 $langs->load(
"errors");
1957 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1959 $this->db->rollback();
1962 $this->db->free($resqltochecklogin);
1965 if (!empty($this->
email)) {
1966 $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).
"'";
1967 $resqltochecklogin = $this->db->query($sqltochecklogin);
1968 if ($resqltochecklogin) {
1969 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1970 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1971 $langs->load(
"errors");
1972 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->
email);
1974 $this->db->rollback();
1977 $this->db->free($resqltochecklogin);
1982 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, fk_user_creat, entity)";
1983 $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).
")";
1984 $result = $this->db->query($sql);
1986 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1988 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1992 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1993 $this->db->rollback();
1998 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1999 $langs->load(
"stocks");
2001 $entrepot =
new Entrepot($this->db);
2002 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
2003 $entrepot->libelle = $entrepot->label;
2004 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
2005 $entrepot->statut = 1;
2006 $entrepot->country_id =
$mysoc->country_id;
2008 $warehouseid = $entrepot->create($user);
2010 $this->fk_warehouse = $warehouseid;
2014 $result = $this->
update($user, 1, 1);
2016 $this->db->rollback();
2022 $result = $this->call_trigger(
'USER_CREATE', $user);
2030 $this->db->commit();
2035 $this->db->rollback();
2039 $this->
error = $this->db->lasterror();
2040 $this->db->rollback();
2064 $this->civility_code = $contact->civility_code;
2065 $this->lastname = $contact->lastname;
2066 $this->firstname = $contact->firstname;
2068 $this->
email = $contact->email;
2069 $this->socialnetworks = $contact->socialnetworks;
2070 $this->office_phone = $contact->phone_pro;
2071 $this->office_fax = $contact->fax;
2072 $this->user_mobile = $contact->phone_mobile;
2073 $this->
address = $contact->address;
2074 $this->zip = $contact->zip;
2075 $this->town = $contact->town;
2077 $this->state_id = $contact->state_id;
2078 $this->country_id = $contact->country_id;
2079 $this->employee = 0;
2081 if (empty($login)) {
2082 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
2083 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
2085 $this->login = $login;
2090 $result = $this->
create($user, 1);
2092 $sql =
"UPDATE ".$this->db->prefix().
"user";
2093 $sql .=
" SET fk_socpeople=".((int) $contact->id);
2094 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
2095 if ($contact->socid > 0) {
2096 $sql .=
", fk_soc=".((int) $contact->socid);
2098 $sql .=
" WHERE rowid=".((int) $this->
id);
2100 $resql = $this->db->query($sql);
2102 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
2104 $this->context[
'createfromcontact'] =
'createfromcontact';
2107 $result = $this->call_trigger(
'USER_CREATE', $user);
2110 $this->db->rollback();
2115 $this->db->commit();
2118 $this->
error = $this->db->error();
2120 $this->db->rollback();
2125 dol_syslog(get_class($this).
"::create_from_contact - 0");
2127 $this->db->rollback();
2148 $this->civility_code = $member->civility_code;
2151 if ($member->morphy ==
'mor' && empty($member->lastname) && !empty($member->company)) {
2152 $this->lastname = $member->company;
2153 $this->firstname =
'';
2155 $this->lastname = $member->lastname;
2156 $this->firstname = $member->firstname;
2158 $this->gender = $member->gender;
2159 $this->
email = $member->email;
2160 $this->fk_member = $member->id;
2161 $this->
address = $member->address;
2162 $this->zip = $member->zip;
2163 $this->town = $member->town;
2165 $this->state_id = $member->state_id;
2166 $this->country_id = $member->country_id;
2167 $this->socialnetworks = $member->socialnetworks;
2169 $this->pass = $member->pass;
2170 $this->pass_crypted = $member->pass_indatabase_crypted;
2172 if (empty($login)) {
2173 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
2177 $this->login = $login;
2182 $result = $this->
create($user);
2184 if (!empty($this->pass)) {
2185 $newpass = $this->
setPassword($user, $this->pass);
2186 if (is_int($newpass) && $newpass < 0) {
2189 } elseif (!empty($this->pass_crypted)) {
2190 $sql =
"UPDATE ".$this->db->prefix().
"user";
2191 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
2192 $sql .=
" WHERE rowid=".((int) $this->
id);
2194 $resql = $this->db->query($sql);
2200 if ($result > 0 && $member->socid) {
2201 $sql =
"UPDATE ".$this->db->prefix().
"user";
2202 $sql .=
" SET fk_soc=".((int) $member->socid);
2203 $sql .=
" WHERE rowid=".((int) $this->
id);
2205 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
2206 $resql = $this->db->query($sql);
2208 $this->db->commit();
2211 $this->
error = $this->db->lasterror();
2213 $this->db->rollback();
2220 $this->db->commit();
2224 $this->db->rollback();
2242 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
2243 $sql .=
" WHERE bydefault = 1";
2244 $sql .=
" AND entity = ".((int)
$conf->entity);
2246 $resql = $this->db->query($sql);
2248 $num = $this->db->num_rows($resql);
2251 $row = $this->db->fetch_row($resql);
2255 $this->db->free($resql);
2259 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id).
" AND fk_id=".((int) $rd[$i]);
2260 $result = $this->db->query($sql);
2262 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES (".((int) $this->
id).
", ".((int) $rd[$i]).
")";
2263 $result = $this->db->query($sql);
2283 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
2287 if (empty($this->country_id) && !empty($this->country_code)) {
2288 $country_id =
getCountry($this->country_code,
'3');
2289 $this->country_id = is_int($country_id) ? $country_id : 0;
2292 $nbrowsaffected = 0;
2295 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
2298 $this->civility_code = trim((
string) $this->civility_code);
2299 $this->lastname = trim((
string) $this->lastname);
2300 $this->firstname = trim((
string) $this->firstname);
2301 $this->ref_employee = trim((
string) $this->ref_employee);
2302 $this->national_registration_number = trim((
string) $this->national_registration_number);
2303 $this->employee = ($this->employee > 0 ? $this->employee : 0);
2304 $this->login = trim((
string) $this->login);
2305 $this->gender = trim((
string) $this->gender);
2307 $this->pass = trim((
string) $this->pass);
2308 $this->api_key = trim((
string) $this->api_key);
2309 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
2310 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
2313 $this->zip = trim((
string) $this->zip);
2314 $this->town = trim((
string) $this->town);
2316 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
2317 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
2318 $this->office_phone = trim((
string) $this->office_phone);
2319 $this->office_fax = trim((
string) $this->office_fax);
2320 $this->user_mobile = trim((
string) $this->user_mobile);
2321 $this->personal_mobile = trim((
string) $this->personal_mobile);
2323 $this->personal_email = trim((
string) $this->personal_email);
2325 $this->job = trim((
string) $this->job);
2326 $this->signature = trim((
string) $this->signature);
2327 $this->note_public = trim((
string) $this->note_public);
2328 $this->note_private = trim((
string) $this->note_private);
2329 $this->openid = trim((
string) $this->openid);
2330 $this->admin = ($this->admin > 0 ? $this->admin : 0);
2331 $this->user_modification_id = $user->id;
2333 $this->accountancy_code_user_general = trim((
string) $this->accountancy_code_user_general);
2334 $this->accountancy_code = trim((
string) $this->accountancy_code);
2335 $this->color = trim(str_replace(
'#',
'', (
string) $this->color));
2336 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
2337 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
2339 $this->birth = empty($this->birth) ?
'' : $this->birth;
2340 $this->fk_warehouse = (int) $this->fk_warehouse;
2341 $this->fk_establishment = (int) $this->fk_establishment;
2349 $langs->load(
"errors");
2350 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
2353 if (empty($this->login)) {
2354 $langs->load(
"errors");
2355 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
2357 } elseif ($badCharUnauthorizedIntoLoginName !==
'' && preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
2358 $langs->load(
"errors");
2359 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
2366 if (is_object($this->oldcopy) && !empty($this->oldcopy->id) && $this->oldcopy->login != $this->login) {
2367 $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).
"'";
2368 $resqltochecklogin = $this->db->query($sqltochecklogin);
2369 if ($resqltochecklogin) {
2370 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2371 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2372 $langs->load(
"errors");
2373 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
2375 $this->db->rollback();
2380 if (is_object($this->oldcopy) && !empty($this->oldcopy->id) && !empty($this->email) && $this->oldcopy->email != $this->email) {
2381 $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).
"'";
2382 $resqltochecklogin = $this->db->query($sqltochecklogin);
2383 if ($resqltochecklogin) {
2384 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2385 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2386 $langs->load(
"errors");
2387 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
2389 $this->db->rollback();
2396 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2397 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
2398 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
2399 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
2400 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
2401 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
2402 $sql .=
", employee = ".(int) $this->employee;
2403 $sql .=
", login = '".$this->db->escape($this->login).
"'";
2404 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
2405 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
2406 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
2407 if (!empty($user->admin)) {
2408 $sql .=
", admin = ".(int) $this->admin;
2410 $sql .=
", address = '".$this->db->escape($this->address).
"'";
2411 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
2412 $sql .=
", town = '".$this->db->escape($this->town).
"'";
2413 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ? ((
int) $this->state_id) :
"null");
2414 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ? ((
int) $this->country_id) :
"null");
2415 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
2416 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
2417 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
2418 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
2419 $sql .=
", email = '".$this->db->escape($this->email).
"'";
2420 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
2421 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
2422 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2423 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2424 $sql .=
", accountancy_code_user_general = '".$this->db->escape($this->accountancy_code_user_general).
"'";
2425 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2426 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2427 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2428 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2429 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2430 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2431 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2432 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2433 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2434 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2435 $sql .=
", fk_user = ".($this->fk_user > 0 ? ((int) $this->fk_user) :
"null");
2436 $sql .=
", fk_user_modif = ".($this->user_modification_id > 0 ? ((int) $this->user_modification_id) :
"null");
2437 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ? ((int) $this->fk_user_expense_validator) :
"null");
2438 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ? ((int) $this->fk_user_holiday_validator) :
"null");
2439 if (isset($this->thm) || $this->thm !=
'') {
2440 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2442 if (isset($this->tjm) || $this->tjm !=
'') {
2443 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2445 if (isset($this->salary) || $this->salary !=
'') {
2446 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2448 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2449 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2451 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2452 if (
isModEnabled(
'multicompany') && !empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2457 $sql .=
", entity = ".((int) $this->entity);
2460 $sql .=
", default_range = ".($this->default_range > 0 ? ((int) $this->default_range) :
'null');
2461 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? ((int) $this->default_c_exp_tax_cat) :
'null');
2462 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? ((int) $this->fk_warehouse) :
"null");
2463 $sql .=
", fk_establishment = ".($this->fk_establishment > 0 ? ((int) $this->fk_establishment) :
"null");
2464 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2465 $sql .=
", force_pass_change = ".($this->force_pass_change ? ((int) $this->force_pass_change) :
"0");
2466 $sql .=
" WHERE rowid = ".((int) $this->
id);
2468 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2469 $resql = $this->db->query($sql);
2471 $nbrowsaffected += $this->db->affected_rows($resql);
2474 if (!empty($this->pass)) {
2475 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2477 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2478 if (is_int($result) && $result < 0) {
2485 if ($this->fk_member > 0) {
2486 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2487 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2488 $resql = $this->db->query($sql);
2490 $this->
error = $this->db->error();
2491 $this->db->rollback();
2496 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2497 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2498 $resql = $this->db->query($sql);
2500 $this->
error = $this->db->error();
2501 $this->db->rollback();
2505 if ($nbrowsaffected) {
2506 if ($this->fk_member > 0 && !$nosyncmember) {
2507 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2509 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2514 $result = $adh->fetch($this->fk_member);
2517 $adh->civility_code = $this->civility_code;
2518 $adh->firstname = $this->firstname;
2519 $adh->lastname = $this->lastname;
2520 $adh->login = $this->login;
2521 $adh->gender = $this->gender;
2522 $adh->birth = $this->birth;
2524 $adh->pass = $this->pass;
2526 $adh->address = $this->address;
2527 $adh->town = $this->town;
2528 $adh->zip = $this->zip;
2529 $adh->state_id = $this->state_id;
2530 $adh->country_id = $this->country_id;
2532 $adh->email = $this->email;
2534 $adh->socialnetworks = $this->socialnetworks;
2536 $adh->phone = $this->office_phone;
2537 $adh->phone_mobile = $this->user_mobile;
2539 $adh->default_lang = $this->lang;
2541 $adh->user_id = $this->id;
2542 $adh->user_login = $this->login;
2544 $result = $adh->update($user, 0, 1, 0);
2546 $this->
error = $adh->error;
2547 $this->errors = $adh->errors;
2548 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2551 } elseif ($result < 0) {
2552 $this->
error = $adh->error;
2553 $this->errors = $adh->errors;
2558 if ($this->contact_id > 0 && !$nosynccontact) {
2559 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2561 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2564 $tmpobj =
new Contact($this->db);
2565 $result = $tmpobj->fetch($this->contact_id);
2568 $tmpobj->civility_code = $this->civility_code;
2569 $tmpobj->firstname = $this->firstname;
2570 $tmpobj->lastname = $this->lastname;
2571 $tmpobj->login = $this->login;
2572 $tmpobj->gender = $this->gender;
2573 $tmpobj->birth = $this->birth;
2577 $tmpobj->email = $this->email;
2579 $tmpobj->socialnetworks = $this->socialnetworks;
2581 $tmpobj->phone_pro = $this->office_phone;
2582 $tmpobj->phone_mobile = $this->user_mobile;
2583 $tmpobj->fax = $this->office_fax;
2585 $tmpobj->default_lang = $this->lang;
2587 $tmpobj->address = $this->address;
2588 $tmpobj->town = $this->town;
2589 $tmpobj->zip = $this->zip;
2590 $tmpobj->state_id = $this->state_id;
2591 $tmpobj->country_id = $this->country_id;
2593 $tmpobj->user_id = $this->id;
2594 $tmpobj->user_login = $this->login;
2596 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2598 $this->
error = $tmpobj->error;
2599 $this->errors = $tmpobj->errors;
2600 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2604 $this->
error = $tmpobj->error;
2605 $this->errors = $tmpobj->errors;
2621 if (!$error && !$notrigger) {
2623 $result = $this->call_trigger(
'USER_MODIFY', $user);
2631 $this->db->commit();
2632 return $nbrowsaffected;
2635 $this->db->rollback();
2639 $this->
error = $this->db->lasterror();
2640 $this->db->rollback();
2659 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2660 $sql .=
" datepreviouslogin = datelastlogin,";
2661 $sql .=
" ippreviouslogin = iplastlogin,";
2662 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2663 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2664 $sql .=
" tms = tms";
2665 $sql .=
" WHERE rowid = ".((int) $this->
id);
2667 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2668 $resql = $this->db->query($sql);
2670 $this->datepreviouslogin = $this->datelastlogin;
2671 $this->datelastlogin = $now;
2672 $this->ippreviouslogin = $this->iplastlogin;
2673 $this->iplastlogin = $userremoteip;
2676 $this->
error = $this->db->lasterror().
' sql='.$sql;
2694 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2696 global $conf, $langs;
2697 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2701 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2706 $passwordalreadycrypted = 0;
2710 if (!empty($passwordalreadycrypted)) {
2711 $password_crypted = $password;
2715 require_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/modules_genpassword.php';
2717 if ($modGeneratePass) {
2718 '@phan-var-force ModeleGenPassword $modGeneratePass';
2721 $modGeneratePass->WithoutAmbi = 0;
2724 $testpassword = $modGeneratePass->validatePassword($password);
2725 if (!$testpassword) {
2726 $this->
error = $modGeneratePass->error;
2734 $password_crypted = (string)
dol_hash($password);
2738 if (!$changelater) {
2739 if (!is_object($this->oldcopy)) {
2740 $this->oldcopy = clone $this;
2747 $sql =
"UPDATE ".$this->db->prefix().
"user";
2748 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2749 $sql .=
" datelastpassvalidation = '".$this->db->idate(
dol_now()).
"',";
2750 $sql .=
" pass_temp = null,";
2751 $sql .=
" force_pass_change = 0";
2752 if (!empty($flagdelsessionsbefore)) {
2753 $sql .=
", flagdelsessionsbefore = '".$this->db->idate($now - 5,
'gmt').
"'";
2756 $sql .=
", pass = null";
2758 $sql .=
", pass = '".$this->db->escape($password).
"'";
2760 $sql .=
" WHERE rowid = ".((int) $this->
id);
2762 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2764 $result = $this->db->query($sql);
2766 if ($this->db->affected_rows($result)) {
2767 $this->pass = $password;
2768 $this->pass_indatabase = $password;
2769 $this->pass_indatabase_crypted = (string) $password_crypted;
2770 $this->force_pass_change = 0;
2772 if ($this->fk_member && !$nosyncmember) {
2773 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2778 $result = $adh->fetch($this->fk_member);
2781 $result = $adh->setPassword($user, $this->pass, (!
getDolGlobalString(
'DATABASE_PWD_ENCRYPTED') ? 0 : 1), 1);
2782 if (is_int($result) && $result < 0) {
2783 $this->
error = $adh->error;
2788 $this->
error = $adh->error;
2793 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2796 $user->context[
'audit'] =
'login='.$user->login;
2797 if (!empty($flagdelsessionsbefore)) {
2798 $user->context[
'audit'] .=
" - flagdelsessionsbefore set to '".$this->db->idate($now - 5,
'gmt').
"'";
2801 if (!$error && !$notrigger) {
2803 $result = $this->call_trigger(
'USER_NEW_PASSWORD', $user);
2806 $this->db->rollback();
2812 $this->db->commit();
2815 $this->db->rollback();
2819 $this->db->rollback();
2820 dol_print_error($this->db);
2826 $sql =
"UPDATE ".$this->db->prefix().
"user";
2827 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2828 $sql .=
" WHERE rowid = ".((int) $this->
id);
2830 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2831 $result = $this->db->query($sql);
2835 dol_print_error($this->db);
2853 global $conf, $langs;
2856 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2868 $outputlangs = $langs;
2872 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2874 $appli =
getDolGlobalString(
'MAIN_APPLICATION_TITLE', constant(
'DOL_APPLICATION_TITLE'));
2876 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2879 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
2880 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2882 if (!$changelater) {
2883 $url = $urlwithroot.
'/';
2888 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2890 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"\n";
2891 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2892 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2893 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2896 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2898 $mesg .= $user->getFullName($outputlangs);
2901 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2902 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.
$conf->file->instance_unique_id));
2904 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2907 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2911 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2912 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2913 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2914 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2916 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2917 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2918 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2921 $trackid =
'use'.$this->id;
2922 $sendcontext =
'passwordreset';
2943 if ($mailfile->sendfile()) {
2946 $langs->load(
"errors");
2947 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2959 return $this->error;
2972 $sql =
"SELECT url, login, pass, poste ";
2973 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2974 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2976 $resql = $this->db->query($sql);
2978 if ($this->db->num_rows($resql)) {
2979 $obj = $this->db->fetch_object($resql);
2981 $this->clicktodial_url = $obj->url;
2982 $this->clicktodial_login = $obj->login;
2983 $this->clicktodial_password = $obj->pass;
2984 $this->clicktodial_poste = $obj->poste;
2987 $this->clicktodial_loaded = 1;
2989 $this->db->free($resql);
2992 $this->
error = $this->db->error();
3008 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
3009 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3011 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
3013 $result = $this->db->query($sql);
3015 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
3016 $sql .=
" (fk_user,url,login,pass,poste)";
3017 $sql .=
" VALUES (".((int) $this->
id);
3018 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
3019 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
3020 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
3021 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
3023 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
3025 $result = $this->db->query($sql);
3027 $this->db->commit();
3030 $this->db->rollback();
3031 $this->
error = $this->db->lasterror();
3047 global $langs, $user;
3053 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
3054 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3055 $sql .=
" AND fk_usergroup = ".((int) $group);
3056 $sql .=
" AND entity = ".((int) $entity);
3058 $result = $this->db->query($sql);
3060 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
3061 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
3063 $result = $this->db->query($sql);
3065 if (!$error && !$notrigger) {
3066 $this->context = array(
'audit' => $langs->trans(
"UserSetInGroup"),
'newgroupid' => $group);
3069 $result = $this->call_trigger(
'USER_MODIFY', $user);
3077 $this->db->commit();
3081 $this->db->rollback();
3085 $this->
error = $this->db->lasterror();
3086 $this->db->rollback();
3101 global $langs, $user;
3107 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
3108 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3109 $sql .=
" AND fk_usergroup = ".((int) $group);
3110 if (empty($entity)) {
3111 $sql .=
" AND entity IN (0, 1)";
3113 $sql .=
" AND entity = ".((int) $entity);
3116 $result = $this->db->query($sql);
3118 if (!$error && !$notrigger) {
3119 $this->context = array(
'audit' => $langs->trans(
"UserRemovedFromGroup"),
'oldgroupid' => $group);
3122 $result = $this->call_trigger(
'USER_MODIFY', $user);
3130 $this->db->commit();
3133 dol_syslog(get_class($this).
"::removeFromGroup ".$this->
error, LOG_ERR);
3134 $this->db->rollback();
3138 $this->
error = $this->db->lasterror();
3139 $this->db->rollback();
3153 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
3160 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
3183 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
3185 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3186 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
3200 global $conf, $langs, $menumanager;
3201 global $dolibarr_main_demo;
3203 $infologin = $params[
'infologin'] ?? 0;
3204 $option = $params[
'option'] ??
'';
3207 if (!empty($this->photo)) {
3208 $photo =
'<div class="photointooltip floatright">';
3209 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
3211 $data[
'photo'] = $photo;
3216 $data[
'opendiv'] =
'<div class="centpercent divtooltip">';
3217 $data[
'picto'] = img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
3219 if (!empty($this->login)) {
3222 if (!empty($this->job)) {
3226 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
3227 $phonelist = array();
3228 if ($this->office_phone) {
3229 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
3231 if ($this->office_fax) {
3232 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
3234 if ($this->user_mobile) {
3235 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
3237 $data[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
3239 if (!empty($this->admin)) {
3240 $data[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.yn($this->admin);
3242 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
3243 $langs->load(
"companies");
3244 $data[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
3247 if (!empty($this->socid)) {
3248 $thirdpartystatic =
new Societe($this->db);
3249 $thirdpartystatic->fetch($this->socid);
3251 if (empty($params[
'hidethirdpartylogo'])) {
3252 $companyimg =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3254 $company =
' ('.$langs->trans(
"Company").
': '.($companyimg ? $companyimg : img_picto(
'',
'company')).
' '.
dol_string_nohtmltag($thirdpartystatic->name).
')';
3256 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
3257 $data[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
3258 $data[
'closediv'] =
'</div>';
3260 if ($infologin > 0) {
3261 $data[
'newlinelogin'] =
'<br>';
3262 $data[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
3265 $data[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.
$conf->entity.
' (User entity '.$this->entity.
')';
3267 $data[
'authentication'] =
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
3268 $data[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
3269 $data[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
3272 $data[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
3274 $data[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
3275 $data[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag(
$conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.($_SERVER[
'HTTP_USER_AGENT'] ??
'').
')');
3277 $data[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
3278 if (
$conf->browser->layout ==
'phone') {
3279 $data[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
3281 if (!empty($_SESSION[
"disablemodules"])) {
3282 $data[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(implode(
', ', explode(
',', $_SESSION[
"disablemodules"])));
3304 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
3306 global $langs, $hookmanager, $user;
3308 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
3319 'objecttype' => $this->element,
3320 'infologin' => $infologin,
3321 'option' => $option,
3322 'hidethirdpartylogo' => $hidethirdpartylogo,
3324 $classfortooltip =
'classfortooltip';
3327 $classfortooltip =
'classforajaxtooltip';
3328 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3335 if (!empty($this->socid)) {
3336 $thirdpartystatic =
new Societe($this->db);
3337 $thirdpartystatic->fetch($this->socid);
3338 if (empty($hidethirdpartylogo)) {
3339 $companylink =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3343 if ($infologin < 0) {
3347 $baseurl = DOL_URL_ROOT .
'/user/card.php';
3348 if ($option ==
'leave') {
3349 $baseurl = DOL_URL_ROOT .
'/holiday/list.php';
3351 $query = [
'id' => $this->id];
3352 if ($option !=
'nolink') {
3354 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3355 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3356 $add_save_lastsearch_values = 1;
3358 if ($add_save_lastsearch_values) {
3359 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
3364 $linkstart =
'<a href="'.$url.
'"';
3366 if (empty($notooltip)) {
3368 $langs->load(
"users");
3369 $label = $langs->trans(
"ShowUser");
3370 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
3372 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
3373 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
3375 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
3378 $linkstart .= $linkclose.
'>';
3382 $result .= (($option ==
'nolink') ?
'' : $linkstart);
3383 if ($withpictoimg) {
3384 $paddafterimage =
'';
3385 if (abs((
int) $withpictoimg) == 1 || abs((
int) $withpictoimg) == 4) {
3386 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3389 if ($withpictoimg > 0) {
3390 $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>';
3393 $picto =
'<!-- picto photo user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'"'.($paddafterimage ?
' '.$paddafterimage :
'').
'>';
3394 $picto .=
Form::showphoto(
'userphoto', $this, 0, 0, 0,
'userphoto'.(($withpictoimg == -3 || $withpictoimg == -4) ?
'small' :
''),
'mini', 0, 1);
3395 $picto .=
'</span>';
3400 if ($withpictoimg == -4 || ($withpictoimg > -2 && $withpictoimg != 2)) {
3402 $result .=
'<span class="nopadding usertext'.((!isset($this->
status) || $this->status) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
3404 if ($mode ==
'login') {
3410 $result .=
'</span>';
3413 $result .= (($option ==
'nolink') ?
'' : $linkend);
3416 $result .= $companylink;
3419 $hookmanager->initHooks(array(
'userdao'));
3420 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
3421 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3423 $result = $hookmanager->resPrint;
3425 $result .= $hookmanager->resPrint;
3440 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
3442 global $langs, $user;
3446 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3450 if ((!$user->hasRight(
'user',
'user',
'lire') && $this->id != $user->id)) {
3454 if ($option ==
'xxx') {
3455 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3459 if ($option ==
'nolink') {
3464 $result .= $linkstart;
3465 if ($withpictoimg) {
3466 $paddafterimage =
'';
3467 if (abs($withpictoimg) == 1) {
3468 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3471 if ($withpictoimg > 0) {
3472 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3475 $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>';
3479 $result .= $this->login;
3480 $result .= $linkend;
3509 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3512 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3513 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3514 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3515 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3518 $statusType =
'status5';
3519 if ($status == self::STATUS_ENABLED) {
3520 $statusType =
'status4';
3523 $label = $this->labelStatus[$status];
3524 $labelshort = $this->labelStatusShort[$status];
3527 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3528 $statusType =
'status3';
3529 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3531 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3532 $statusType =
'status2';
3533 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3536 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3551 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3553 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3554 $return .=
'<div class="info-box info-box-sm">';
3555 $return .=
'<span class="info-box-icon bg-infobox-action">';
3558 if (!empty($this->photo)) {
3560 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3565 $return .= img_picto(
'', $this->picto);
3569 $return .=
'</span>';
3570 $return .=
'<div class="info-box-content">';
3571 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3572 if (
isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3573 $return .= img_picto($langs->trans(
"SuperAdministratorDesc"),
'superadmin',
'class="valignmiddle paddingright paddingleft"');
3574 } elseif ($this->admin) {
3575 $return .= img_picto($langs->trans(
"AdministratorDesc"),
'admin',
'class="valignmiddle paddingright paddingleft"');
3577 $return .=
'</span>';
3578 if ($selected >= 0) {
3579 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3582 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->
email.
'</span>';
3584 if (method_exists($this,
'getLibStatut')) {
3585 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3587 $return .=
'</div>';
3588 $return .=
'</div>';
3589 $return .=
'</div>';
3613 } elseif ($mode == 1) {
3615 } elseif ($mode == 2) {
3631 global $conf, $langs;
3637 $keymodified =
false;
3646 'LDAP_FIELD_FULLNAME' =>
'fullname',
3647 'LDAP_FIELD_NAME' =>
'lastname',
3648 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3649 'LDAP_FIELD_LOGIN' =>
'login',
3650 'LDAP_FIELD_LOGIN_SAMBA' =>
'login',
3651 'LDAP_FIELD_PHONE' =>
'office_phone',
3652 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3653 'LDAP_FIELD_FAX' =>
'office_fax',
3654 'LDAP_FIELD_MAIL' =>
'email',
3655 'LDAP_FIELD_SID' =>
'ldap_sid',
3659 foreach ($ldapkey as $constname => $varname) {
3665 if (is_object($this->oldcopy) && !empty($this->oldcopy->id) && $this->$varname != $this->oldcopy->$varname) {
3666 $keymodified =
true;
3671 foreach ($socialnetworks as $key => $value) {
3672 if (!empty($this->socialnetworks[$value[
'label']]) &&
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))) {
3673 $info[
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))] = $this->socialnetworks[$value[
'label']];
3689 $soc =
new Societe($this->db);
3690 $soc->fetch($this->socid);
3693 if ($soc->client == 1) {
3694 $info[
"businessCategory"] =
"Customers";
3696 if ($soc->client == 2) {
3697 $info[
"businessCategory"] =
"Prospects";
3699 if ($soc->fournisseur == 1) {
3700 $info[
"businessCategory"] =
"Suppliers";
3705 if (!empty($this->pass)) {
3718 if ($this->pass_indatabase_crypted &&
getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED')) {
3722 } elseif (!empty($this->pass_indatabase)) {
3734 $info[
"objectclass"][4] =
"phpgwContact";
3736 $info[
'uidnumber'] = $this->id;
3738 $info[
'phpgwTz'] = 0;
3739 $info[
'phpgwMailType'] =
'INTERNET';
3740 $info[
'phpgwMailHomeType'] =
'INTERNET';
3742 $info[
"phpgwContactTypeId"] =
'n';
3743 $info[
"phpgwContactCatId"] = 0;
3744 $info[
"phpgwContactAccess"] =
"public";
3746 $info[
"phpgwContactOwner"] = 1;
3749 $info[
"rfc822Mailbox"] = $this->email;
3751 if ($this->user_mobile) {
3752 $info[
"phpgwCellTelephoneNumber"] = $this->user_mobile;
3761 $groupslist = $usergroup->listGroupsForUser($this->
id);
3763 if (!empty($groupslist)) {
3764 foreach ($groupslist as $groupforuser) {
3793 $this->
ref =
'SPECIMEN';
3794 $this->specimen = 1;
3795 $this->user_creation_id = $user->id;
3797 $this->lastname =
'DOLIBARR';
3798 $this->firstname =
'SPECIMEN';
3799 $this->gender =
'man';
3800 $this->note_public =
'This is a note public';
3801 $this->note_private =
'This is a note private';
3802 $this->
email =
'email@specimen.com';
3803 $this->personal_email =
'personalemail@specimen.com';
3804 $this->socialnetworks = array(
3805 'skype' =>
'skypepseudo',
3806 'twitter' =>
'twitterpseudo',
3807 'facebook' =>
'facebookpseudo',
3808 'linkedin' =>
'linkedinpseudo',
3810 $this->office_phone =
'0999999999';
3811 $this->office_fax =
'0999999998';
3812 $this->user_mobile =
'0999999997';
3813 $this->personal_mobile =
'0999999996';
3815 $this->login =
'dolibspec';
3816 $this->pass =
'dolibSpec+@123';
3819 $this->datec = $now;
3820 $this->datem = $now;
3822 $this->datelastlogin = $now;
3823 $this->iplastlogin =
'127.0.0.1';
3824 $this->datepreviouslogin = $now;
3825 $this->ippreviouslogin =
'127.0.0.1';
3841 $sql =
"SELECT u.rowid, u.login as ref, u.datec, fk_user_creat as user_creation_id, fk_user_modif as user_modification_id,";
3842 $sql .=
" GREATEST(u.tms, COALESCE(uef.tms, u.tms)) as date_modification, u.entity";
3843 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3844 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user_extrafields as uef ON uef.fk_object = u.rowid";
3845 $sql .=
" WHERE u.rowid = ".((int) $id);
3847 $result = $this->db->query($sql);
3849 if ($this->db->num_rows($result)) {
3850 $obj = $this->db->fetch_object($result);
3852 $this->
id = $obj->rowid;
3854 $this->user_creation_id = $obj->user_creation_id;
3855 $this->user_modification_id = $obj->user_modification_id;
3857 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3858 $this->date_creation = $this->db->jdate($obj->datec);
3859 $this->date_modification = $this->db->jdate($obj->date_modification);
3860 $this->entity = $obj->entity;
3863 $this->db->free($result);
3865 dol_print_error($this->db);
3877 $sql =
"SELECT count(mc.email) as nb";
3878 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3879 $sql .=
" WHERE mc.email = '".$this->db->escape($this->
email).
"'";
3880 $sql .=
" AND mc.statut NOT IN (-1,0)";
3882 $resql = $this->db->query($sql);
3884 $obj = $this->db->fetch_object($resql);
3885 $nb = (int) $obj->nb;
3887 $this->db->free($resql);
3890 $this->
error = $this->db->error();
3905 $sql =
"SELECT count(rowid) as nb";
3906 $sql .=
" FROM ".$this->db->prefix().
"user";
3907 if ($option ==
'superadmin') {
3908 $sql .=
" WHERE entity = 0";
3910 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3911 if ($limitTo ==
'active') {
3912 $sql .=
" AND statut = 1";
3916 $sql .=
" AND admin = ".(int) $admin;
3919 $resql = $this->db->query($sql);
3921 $obj = $this->db->fetch_object($resql);
3922 $nb = (int) $obj->nb;
3924 $this->db->free($resql);
3927 $this->
error = $this->db->lasterror();
3948 $this->firstname = $ldapuser->$tmpvar;
3950 $this->lastname = $ldapuser->$tmpvar;
3952 $this->login = $ldapuser->$tmpvar;
3954 $this->pass = $ldapuser->$tmpvar;
3956 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3959 $this->office_phone = $ldapuser->$tmpvar;
3961 $this->user_mobile = $ldapuser->$tmpvar;
3963 $this->office_fax = $ldapuser->$tmpvar;
3965 $this->
email = $ldapuser->$tmpvar;
3966 foreach ($socialnetworks as $key => $value) {
3968 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3971 $this->ldap_sid = $ldapuser->$tmpvar;
3974 $this->job = $ldapuser->$tmpvar;
3976 $this->note_public = $ldapuser->$tmpvar;
3978 $result = $this->
update($user);
3980 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3996 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3997 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3999 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
4000 $res = $this->db->query($sql);
4003 while ($rec = $this->db->fetch_array($res)) {
4004 $user =
new User($this->db);
4005 $user->fetch($rec[
'rowid']);
4010 dol_print_error($this->db);
4023 $this->parentof = array();
4026 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
4027 $sql .=
" FROM ".$this->db->prefix().
"user";
4028 $sql .=
" WHERE fk_user <> 0";
4029 $sql .=
" AND entity IN (".getEntity(
'user').
")";
4031 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
4032 $resql = $this->db->query($sql);
4034 while ($obj = $this->db->fetch_object($resql)) {
4035 $this->parentof[$obj->id_son] = $obj->id_parent;
4039 dol_print_error($this->db);
4061 global $hookmanager;
4064 $hookmanager->initHooks(array(
'userdao'));
4066 $this->users = array();
4072 $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";
4073 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4075 $parameters = array();
4076 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
4078 $sql .= $hookmanager->resPrint;
4080 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4086 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
4087 $resql = $this->db->query($sql);
4090 while ($obj = $this->db->fetch_object($resql)) {
4091 $this->users[(int) $obj->rowid]
4093 'rowid' => (
int) $obj->rowid,
4094 'id' => (int) $obj->rowid,
4095 'fk_user' => (
int) $obj->fk_user,
4096 'fk_soc' => (int) $obj->fk_soc,
4097 'firstname' => (
string) $obj->firstname,
4098 'lastname' => (string) $obj->lastname,
4099 'login' => (
string) $obj->login,
4100 'statut' => (int) $obj->statut,
4101 'entity' => (
int) $obj->entity,
4102 'email' => (string) $obj->email,
4103 'gender' => (
string) $obj->gender,
4104 'admin' => (int) $obj->admin,
4105 'photo' => (
string) $obj->photo,
4114 dol_print_error($this->db);
4119 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
4120 foreach ($this->users as $key => $val) {
4123 $this->
error =
'ErrorLoopInHierarchy';
4129 if ($deleteafterid) {
4131 $keyfilter1 =
'^'.$deleteafterid.
'$';
4132 $keyfilter2 =
'_'.$deleteafterid.
'$';
4133 $keyfilter3 =
'^'.$deleteafterid.
'_';
4134 $keyfilter4 =
'_'.$deleteafterid.
'_';
4135 foreach (array_keys($this->users) as $key) {
4136 $fullpath = (string) $this->users[$key][
'fullpath'];
4137 if (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
4138 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath)) {
4139 unset($this->users[$key]);
4144 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
4145 $this->users =
dol_sort_array($this->users,
'fullname',
'asc', 1, 0, 1);
4147 return $this->users;
4160 $childids = array();
4162 if (isset($this->cache_childids[$this->
id])) {
4163 $childids = $this->cache_childids[$this->id];
4168 $idtoscan = $this->id;
4170 dol_syslog(
"Build childid for id = ".$idtoscan);
4171 foreach ($this->users as $id => $val) {
4172 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
4173 $childids[$val[
'id']] = $val[
'id'];
4180 if ($treeresult < 0) {
4181 dol_syslog(get_class($this).
"::getAllChildIds got a truncated tree: ".$this->
error, LOG_WARNING);
4182 return $addcurrentuser ? array($this->
id => $this->
id) : $childids;
4185 $this->cache_childids[$this->id] = $childids;
4187 if ($addcurrentuser) {
4188 $childids[$this->id] = $this->id;
4208 if (!empty($this->users[$id_user][
'fullpath'])) {
4210 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
4215 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
4216 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
4218 $cursor_user = $id_user;
4220 $useridfound = array($id_user);
4221 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
4222 if (in_array($this->parentof[$cursor_user], $useridfound)) {
4223 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
4226 $useridfound[] = $this->parentof[$cursor_user];
4227 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
4228 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
4230 $cursor_user = $this->parentof[$cursor_user];
4234 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
4283 $this->nb = array();
4285 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
4286 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4288 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
4289 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
4290 $sql .=
" AND ug.fk_user = u.rowid";
4292 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4294 $sql .=
" AND u.statut > 0";
4297 $resql = $this->db->query($sql);
4299 while ($obj = $this->db->fetch_object($resql)) {
4300 $this->nb[
"users"] = $obj->nb;
4302 $this->db->free($resql);
4305 dol_print_error($this->db);
4306 $this->
error = $this->db->error();
4322 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4326 $langs->load(
"user");
4333 $modele =
'bluesky';
4337 $modelpath =
"core/modules/user/doc/";
4339 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4353 $user_property =
'';
4355 if (empty($rowid)) {
4359 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
4360 $sql .=
" FROM ".$this->db->prefix().
"user";
4361 $sql .=
" WHERE rowid = ".((int) $rowid);
4363 $resql = $this->db->query($sql);
4365 $nump = $this->db->num_rows($resql);
4368 $obj = $this->db->fetch_object($resql);
4370 if ($mode ==
'email') {
4371 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
4372 } elseif ($mode ==
'mobile') {
4373 $user_property = $obj->user_mobile;
4374 } elseif ($mode ==
'name') {
4378 return $user_property;
4380 dol_print_error($this->db);
4398 $instanceuniqueid = empty(
$conf->file->instance_unique_id) ?
'' :
$conf->file->instance_unique_id;
4399 $encodedsecurekey =
dol_hash($instanceuniqueid.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
4401 $entity_qr =
'&entity='.((int)
$conf->entity);
4406 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
4407 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
4410 if ($typeofurl ==
'internal') {
4411 $urlwithroot = DOL_URL_ROOT;
4414 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
4430 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $entityfilter =
false)
4432 global $conf, $user;
4434 $sql =
"SELECT t.rowid";
4435 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
4437 if ($entityfilter) {
4439 if (!empty($user->admin) && empty($user->entity) &&
$conf->entity == 1) {
4440 $sql .=
" WHERE t.entity IS NOT NULL";
4442 $sql .=
" WHERE t.entity = 0 OR EXISTS (";
4443 $sql .=
" SELECT ug.rowid FROM " . $this->db->prefix() .
"usergroup_user as ug";
4444 $sql .=
" WHERE ug.fk_user = t.rowid AND ug.entity IN (" .
getEntity(
'usergroup') .
"))";
4447 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
4450 $sql .=
" WHERE 1 = 1";
4456 if ($errormessage) {
4457 $this->errors[] = $errormessage;
4458 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
4462 $sql .= $this->db->order($sortfield, $sortorder);
4464 $sql .= $this->db->plimit($limit + 1, $offset);
4469 $resql = $this->db->query($sql);
4471 $this->users = array();
4472 $num = $this->db->num_rows($resql);
4474 while ($obj = $this->db->fetch_object($resql)) {
4475 $line =
new self($this->db);
4476 $result = $line->fetch($obj->rowid);
4477 if ($result > 0 && !empty($line->id)) {
4478 $this->users[$obj->rowid] = clone $line;
4481 $this->db->free($resql);
4485 $this->errors[] = $this->db->lasterror();
4497 private $findUserIdByEmailCache;
4511 if (isset($this->findUserIdByEmailCache[$email])) {
4512 return $this->findUserIdByEmailCache[$email];
4515 $this->findUserIdByEmailCache[$email] = -1;
4517 $sql =
'SELECT rowid';
4518 $sql .=
' FROM '.$this->db->prefix().
'user';
4519 if (
getDolGlobalString(
'AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR')) {
4520 $sql .=
" WHERE email LIKE '%".$this->db->escape($this->db->escapeforlike($email)).
"%'";
4522 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4526 $resql = $this->db->query($sql);
4531 $obj = $this->db->fetch_object($resql);
4536 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4538 return $this->findUserIdByEmailCache[$email];
4549 if (empty($fromId) || empty($toId)) {
4556 $sqlDelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
4557 $sqlDelete .=
" WHERE fk_user = ".((int) $toId);
4559 dol_syslog(get_class($this).
"::clone_rights (delete default permissions)", LOG_DEBUG);
4561 if (!$this->db->query($sqlDelete)) {
4562 $this->db->rollback();
4567 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id)";
4568 $sql .=
" SELECT entity, ".((int) $toId).
", fk_id";
4569 $sql .=
" FROM ".$this->db->prefix().
"user_rights src";
4570 $sql .=
" WHERE fk_user = ".((int) $fromId);
4571 $sql .=
" AND NOT EXISTS (";
4572 $sql .=
" SELECT 1";
4573 $sql .=
" FROM ".$this->db->prefix().
"user_rights dest";
4574 $sql .=
" WHERE dest.entity = src.entity";
4575 $sql .=
" AND dest.fk_user = ".((int) $toId);
4576 $sql .=
" AND dest.fk_id = src.fk_id";
4579 dol_syslog(get_class($this).
"::clone_rights", LOG_DEBUG);
4582 if (!$this->db->query($sql)) {
4583 $this->db->rollback();
4587 $this->db->commit();
4604 $type = $this->table_element;
4607 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4608 $categorystatic =
new Categorie($this->db);
4610 $sql =
"INSERT INTO ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]).
" (fk_categorie, fk_user)";
4611 $sql .=
" SELECT fk_categorie, ".((int) $toId).
" FROM ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]);
4612 $sql .=
" WHERE fk_user = ".((int) $fromId);
4614 if (!$this->db->query($sql)) {
4615 $this->
error = $this->db->lasterror();
4616 $this->db->rollback();
4620 $this->db->commit();
global $dolibarr_main_url_root
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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).
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.
isNotIntoValidityDateRange()
Return a link with photo Use this->id,this->photo.
getNbOfUsers($limitTo, $option='', $admin=-1)
Return number of existing users.
removeFromGroup($group, $entity, $notrigger=0)
Remove a user from a group.
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)
$fields
Array with all fields and their property.
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.
setInGroup($group, $entity, $notrigger=0)
Add user into a group.
create($user, $notrigger=0)
Create a user into database.
loadPersonalConf($entity=-1)
Load const values from database table user_param and set it into user->conf->XXX.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
findUserIdByEmail($email)
Find a user by the given e-mail and return it's user id when found.
getTooltipContentArray($params)
getTooltipContentArray
static replaceContact(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a contact id with another one when merging two contacts.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
if(! $sortfield) if(! $sortorder) $module
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
dol_now($mode='gmt')
Return date for now.
getDolGlobalLoginBadCharUnauthorized()
Return the list of unauthorized characters in user logins.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
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.
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.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
conf($dolibarr_main_document_root, $realpathconf=null)
Load conf file (file must exists)
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dolGetLdapPasswordHash($password, $type='md5')
Returns a specific ldap hash of a password.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.
dol_verifyHash($chain, $hash, $type='0')
Compute a hash and compare it to the given one For backward compatibility reasons,...
dolEncrypt($chain, $key='', $ciphering='', $forceseed='', $obfuscationmode='dolcrypt')
Encode a string with a symmetric encryption.
div refaddress div address