40require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/class/commonpeople.class.php';
56 public $element =
'user';
61 public $table_element =
'user';
66 public $fk_element =
'fk_user';
71 public $picto =
'user';
110 public $civility_code;
135 public $email_oauth2;
140 public $personal_email;
145 public $socialnetworks;
160 public $office_phone;
175 public $personal_mobile;
200 public $pass_crypted;
205 public $pass_indatabase;
210 public $pass_indatabase_crypted;
220 public $force_pass_change = 0;
259 public $fk_user_expense_validator;
264 public $fk_user_holiday_validator;
269 public $clicktodial_url;
274 public $clicktodial_login;
279 public $clicktodial_password;
284 public $clicktodial_poste;
289 public $clicktodial_loaded;
295 public $datelastpassvalidation;
299 public $datelastlogin;
303 public $datepreviouslogin;
307 public $flagdelsessionsbefore;
315 public $ippreviouslogin;
319 public $datestartvalidity;
323 public $dateendvalidity;
343 public $all_permissions_are_loaded;
353 public $user_group_list;
358 private $_tab_loaded = array();
368 public $default_values;
373 public $lastsearch_values_tmp;
377 public $lastsearch_values;
382 public $users = array();
390 private $cache_childids;
396 public $accountancy_code_user_general;
401 public $accountancy_code;
433 public $dateemployment;
437 public $dateemploymentend;
442 public $default_c_exp_tax_cat;
447 public $ref_employee;
452 public $national_registration_number;
457 public $default_range;
462 public $fk_warehouse;
467 public $fk_establishment;
472 public $label_establishment;
478 public $usergroup_entity;
480 public $fields = array(
481 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
482 'lastname' => array(
'type' =>
'varchar(50)',
'label' =>
'Lastname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 20,
'searchall' => 1),
483 'firstname' => array(
'type' =>
'varchar(50)',
'label' =>
'Firstname',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 10,
'searchall' => 1),
484 'ref_employee' => array(
'type' =>
'varchar(50)',
'label' =>
'RefEmployee',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 30,
'searchall' => 1),
485 'national_registration_number' => array(
'type' =>
'varchar(50)',
'label' =>
'NationalRegistrationNumber',
'enabled' => 1,
'visible' => 1,
'notnull' => 1,
'showoncombobox' => 1,
'index' => 1,
'position' => 40,
'searchall' => 1)
488 const STATUS_DISABLED = 0;
489 const STATUS_ENABLED = 1;
500 $this->ismultientitymanaged = 1;
501 $this->isextrafieldmanaged = 1;
503 $this->clicktodial_loaded = 0;
506 $this->all_permissions_are_loaded = 0;
507 $this->nb_rights = 0;
515 $this->rights->user =
new stdClass();
516 $this->rights->user->user =
new stdClass();
517 $this->rights->user->self =
new stdClass();
518 $this->rights->user->user_advance =
new stdClass();
519 $this->rights->user->self_advance =
new stdClass();
520 $this->rights->user->group_advance =
new stdClass();
537 public function fetch($id = 0, $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'', $fk_socpeople = 0, $use_email_oauth2 = 0)
542 $login = trim($login);
545 $sql =
"SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.civility as civility_code, u.birth, u.job,";
546 $sql .=
" u.email, u.email_oauth2, u.personal_email,";
547 $sql .=
" u.socialnetworks,";
548 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
549 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
550 $sql .=
" u.admin, u.login, u.note_private, u.note_public,";
551 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.force_pass_change, u.api_key,";
552 $sql .=
" u.fk_soc, u.fk_socpeople, u.fk_member, u.fk_user, u.ldap_sid, u.fk_user_expense_validator, u.fk_user_holiday_validator,";
553 $sql .=
" fk_user_creat as user_creation_id, fk_user_modif as user_modification_id,";
554 $sql .=
" u.statut as status, u.lang, u.entity,";
555 $sql .=
" u.datec as datec,";
556 $sql .=
" GREATEST(u.tms, COALESCE(uef.tms, u.tms)) as datem,";
557 $sql .=
" u.datelastlogin as datel,";
558 $sql .=
" u.datepreviouslogin as datep,";
559 $sql .=
" u.flagdelsessionsbefore,";
560 $sql .=
" u.iplastlogin,";
561 $sql .=
" u.ippreviouslogin,";
562 $sql .=
" u.datelastpassvalidation,";
563 $sql .=
" u.datestartvalidity,";
564 $sql .=
" u.dateendvalidity,";
565 $sql .=
" u.photo as photo,";
566 $sql .=
" u.openid as openid,";
567 $sql .=
" u.accountancy_code_user_general,";
568 $sql .=
" u.accountancy_code,";
571 $sql .=
" u.salary,";
572 $sql .=
" u.salaryextra,";
573 $sql .=
" u.weeklyhours,";
575 $sql .=
" u.dateemployment, u.dateemploymentend,";
576 $sql .=
" u.fk_warehouse,";
577 $sql .=
" u.ref_ext,";
578 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
579 $sql .=
" u.national_registration_number,";
580 $sql .=
" u.ref_employee,";
581 $sql .=
" c.code as country_code, c.label as country,";
582 $sql .=
" d.code_departement as state_code, d.nom as state,";
583 $sql .=
" s.label as label_establishment, u.fk_establishment";
584 $sql .=
" FROM ".$this->db->prefix().
"user as u";
585 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user_extrafields as uef ON uef.fk_object = u.rowid";
586 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as c ON u.fk_country = c.rowid";
587 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_departements as d ON u.fk_state = d.rowid";
588 $sql .=
" LEFT JOIN ".$this->db->prefix().
"establishment as s ON u.fk_establishment = s.rowid";
591 $sql .=
" WHERE u.rowid = ".((int) $id);
595 $sql .=
" WHERE u.entity IN (0, " . ((int)
$conf->entity) .
")";
597 $sql .=
" WHERE u.entity IS NOT NULL";
602 $sql .=
" WHERE u.entity IS NOT NULL";
604 if ($entity !=
'' && $entity == 0) {
605 $sql .=
" WHERE u.entity = 0";
607 $sql .=
" WHERE u.entity IN (0, " . ((int) ($entity > 0 ? ((
int) $entity) : ((int)
$conf->entity))) .
")";
615 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->db->escape($login).
"')";
617 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
619 $sql .=
" AND (u.email = '".$this->db->escape($email).
"'";
620 if ($use_email_oauth2) {
621 $sql .=
" OR u.email_oauth2 = '".$this->db->escape($email).
"'";
624 } elseif ($fk_socpeople > 0) {
625 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
628 $sql .=
" ORDER BY u.entity ASC";
632 $sql .=
' '.$this->db->plimit(1);
635 $resql = $this->db->query($sql);
637 $num = $this->db->num_rows($resql);
639 $this->
error =
"USERDUPLICATEFOUND";
640 dol_syslog(get_class($this).
"::fetch more than 1 user found", LOG_WARNING);
642 $this->db->free($resql);
646 $obj = $this->db->fetch_object($resql);
648 $this->
id = $obj->rowid;
649 $this->
ref = $obj->rowid;
651 $this->ref_ext = $obj->ref_ext;
653 $this->ldap_sid = $obj->ldap_sid;
654 $this->civility_code = $obj->civility_code;
655 $this->lastname = $obj->lastname;
656 $this->firstname = $obj->firstname;
657 $this->ref_employee = $obj->ref_employee;
658 $this->national_registration_number = $obj->national_registration_number;
660 $this->employee = $obj->employee;
662 $this->login = $obj->login;
663 $this->gender = $obj->gender;
664 $this->birth = $this->db->jdate($obj->birth);
665 $this->pass_indatabase = $obj->pass;
666 $this->pass_indatabase_crypted = $obj->pass_crypted;
667 $this->pass = $obj->pass;
668 $this->pass_temp = $obj->pass_temp;
670 $this->force_pass_change = $obj->force_pass_change;
671 $this->datelastpassvalidation = $this->db->jdate($obj->datelastpassvalidation);
675 $this->
address = $obj->address;
676 $this->zip = $obj->zip;
677 $this->town = $obj->town;
679 $this->country_id = $obj->country_id;
680 $this->country_code = $obj->country_id ? $obj->country_code :
'';
683 $this->state_id = $obj->state_id;
684 $this->state_code = $obj->state_code;
685 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
687 $this->office_phone = $obj->office_phone;
688 $this->office_fax = $obj->office_fax;
689 $this->user_mobile = $obj->user_mobile;
690 $this->personal_mobile = $obj->personal_mobile;
691 $this->
email = $obj->email;
692 $this->email_oauth2 = $obj->email_oauth2;
693 $this->personal_email = $obj->personal_email;
694 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
695 $this->user_creation_id = $obj->user_creation_id;
696 $this->user_modification_id = $obj->user_modification_id;
698 $this->job = $obj->job;
699 $this->signature = $obj->signature;
700 $this->admin = $obj->admin;
701 $this->note_public = $obj->note_public;
702 $this->note_private = $obj->note_private;
704 $this->statut = $obj->status;
705 $this->
status = $obj->status;
707 $this->photo = $obj->photo;
708 $this->openid = $obj->openid;
709 $this->lang = $obj->lang;
710 $this->entity = $obj->entity;
712 $this->accountancy_code_user_general = $obj->accountancy_code_user_general;
713 $this->accountancy_code = $obj->accountancy_code;
715 $this->thm = $obj->thm;
716 $this->tjm = $obj->tjm;
717 $this->salary = $obj->salary;
718 $this->salaryextra = $obj->salaryextra;
719 $this->weeklyhours = $obj->weeklyhours;
720 $this->color = $obj->color;
721 $this->dateemployment = $this->db->jdate($obj->dateemployment);
722 $this->dateemploymentend = $this->db->jdate($obj->dateemploymentend);
724 $this->datec = $this->db->jdate($obj->datec);
725 $this->datem = $this->db->jdate($obj->datem);
726 $this->datelastlogin = $this->db->jdate($obj->datel);
727 $this->datepreviouslogin = $this->db->jdate($obj->datep);
728 $this->flagdelsessionsbefore = $this->db->jdate($obj->flagdelsessionsbefore,
'gmt');
729 $this->iplastlogin = $obj->iplastlogin;
730 $this->ippreviouslogin = $obj->ippreviouslogin;
731 $this->datestartvalidity = $this->db->jdate($obj->datestartvalidity);
732 $this->dateendvalidity = $this->db->jdate($obj->dateendvalidity);
734 $this->socid = $obj->fk_soc;
735 $this->contact_id = $obj->fk_socpeople;
736 $this->fk_member = $obj->fk_member;
737 $this->fk_user = $obj->fk_user;
738 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
739 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
741 $this->default_range = $obj->default_range;
742 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
743 $this->fk_warehouse = $obj->fk_warehouse;
744 $this->fk_establishment = $obj->fk_establishment;
745 $this->label_establishment = $obj->label_establishment;
749 if (!
isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
757 $this->db->free($resql);
759 $this->
error =
"USERNOTFOUND";
760 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
762 $this->db->free($resql);
766 $this->
error = $this->db->lasterror();
771 if ($loadpersonalconf) {
777 $this->
error = $this->db->lasterror();
784 if (
GETPOSTINT(
'forceexternaluser') && $this->admin && empty($this->socid)) {
785 $this->socid =
GETPOSTINT(
'forceexternaluser');
803 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
804 $sql .=
" WHERE fk_user = ".((int) $this->
id);
806 $sql .=
" AND entity IN (0, ".((int)
$conf->entity).
")";
808 $sql .=
" AND entity = ".((int) $entity);
812 $resql = $this->db->query($sql);
814 $num = $this->db->num_rows($resql);
817 $obj = $this->db->fetch_object($resql);
818 $p = (!empty($obj->param) ? $obj->param :
'');
820 $this->
conf->$p = $obj->value;
824 $this->db->free($resql);
828 $this->
error = $this->db->lasterror();
845 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
848 $result = $defaultValues->fetchAll(
'',
'', 0, 0,
'(t.user_id:in:0,'.$this->
id.
') AND (entity:in:'.(isset($this->entity) ? $this->entity :
$conf->entity).
','.
$conf->entity.
')');
851 if (!is_array($result) && $result < 0) {
855 } elseif (count($result) > 0) {
856 foreach ($result as $defval) {
857 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
858 $pagewithoutquerystring = $defval->page;
861 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
862 $pagewithoutquerystring = $reg[1];
863 $pagequeries = $reg[2];
865 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
869 if (!empty($this->default_values)) {
870 foreach ($this->default_values as $a => $b) {
871 foreach ($b as
$c => $d) {
872 krsort($this->default_values[$a][
$c]);
913 public function hasRight($module, $permlevel1, $permlevel2 =
'')
916 $moduletomoduletouse = array(
917 'category' =>
'categorie',
918 'compta' =>
'comptabilite',
919 'contract' =>
'contrat',
920 'member' =>
'adherent',
922 'order' =>
'commande',
923 'produit' =>
'product',
924 'productlot' =>
'product',
925 'project' =>
'projet',
926 'propale' =>
'propal',
927 'shipping' =>
'expedition',
928 'task' =>
'task@projet',
929 'fichinter' =>
'ficheinter',
930 'intervention' =>
'ficheinter',
931 'inventory' =>
'stock',
932 'invoice' =>
'facture',
933 'invoice_supplier' =>
'facture@fournisseur',
934 'order_supplier' =>
'fournisseur',
935 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
936 'skill@hrm' =>
'all@hrm',
937 'job@hrm' =>
'all@hrm',
938 'position@hrm' =>
'all@hrm',
939 'facturerec' =>
'facture',
940 'margins' =>
'margin',
943 if (!empty($moduletomoduletouse[$module])) {
944 $module = $moduletomoduletouse[$module];
955 $supplierNewToLegacy = array(
956 'supplier_order' => array(
'fournisseur',
'commande'),
957 'supplier_invoice' => array(
'fournisseur',
'facture'),
960 if (isset($supplierNewToLegacy[$module])) {
963 $permlevel2 = $permlevel1;
964 $permlevel1 = $supplierNewToLegacy[$module][1];
965 $module = $supplierNewToLegacy[$module][0];
970 $supplierLegacyCompat = array(
971 'supplier_order' =>
'fournisseur',
972 'supplier_invoice' =>
'fournisseur',
975 if (isset($supplierLegacyCompat[$module])) {
977 $module = $supplierLegacyCompat[$module];
981 $moduleRightsMapping = array(
982 'product' =>
'produit',
983 'margin' =>
'margins',
984 'comptabilite' =>
'compta'
987 $rightsPath = $module;
988 if (!empty($moduleRightsMapping[$rightsPath])) {
989 $rightsPath = $moduleRightsMapping[$rightsPath];
993 $tmp = explode(
'@', $rightsPath, 2);
994 if (!empty($tmp[1])) {
995 if (strpos($module,
'@') !==
false) {
998 if ($tmp[0] != $tmp[1]) {
1000 $rightsPath = $tmp[1];
1001 $permlevel2 = $permlevel1;
1002 $permlevel1 = $tmp[0];
1005 $rightsPath = $tmp[1];
1020 if (!empty($this->socid)) {
1021 if ($module ==
'societe' && ($permlevel1 ==
'creer' || $permlevel1 ==
'write')) {
1024 if ($module ==
'societe' && $permlevel1 ==
'client' && $permlevel2 ==
'voir') {
1027 if ($module ==
'societe' && $permlevel1 ==
'export') {
1030 if ($module ==
'societe' && ($permlevel1 ==
'supprimer' || $permlevel1 ==
'delete')) {
1036 if ($permlevel1 ==
'propale') {
1037 $permlevel1 =
'propal';
1039 if ($permlevel1 ==
'member') {
1040 $permlevel1 =
'adherent';
1042 if ($permlevel1 ==
'recruitmentcandidature') {
1043 $permlevel1 =
'recruitmentjobposition';
1048 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
1053 if (!empty($this->rights->$rightsPath->$permlevel1)) {
1054 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
1055 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
1059 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
1060 return $this->rights->$rightsPath->$permlevel1->lire;
1062 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
1063 return $this->rights->$rightsPath->$permlevel1->creer;
1065 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
1066 return $this->rights->$rightsPath->$permlevel1->create;
1068 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
1069 return $this->rights->$rightsPath->$permlevel1->supprimer;
1073 if (!empty($this->rights->$rightsPath->$permlevel1)) {
1074 return $this->rights->$rightsPath->$permlevel1;
1078 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
1079 return $this->rights->$rightsPath->lire;
1081 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
1082 return $this->rights->$rightsPath->creer;
1084 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
1085 return $this->rights->$rightsPath->create;
1087 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
1088 return $this->rights->$rightsPath->supprimer;
1106 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1108 global $conf, $user, $langs;
1110 $entity = (empty($entity) ?
$conf->entity : $entity);
1112 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
1114 if (empty($this->
id)) {
1115 $this->
error =
'Try to call addrights on an object user with an empty id';
1125 $module = $perms = $subperms =
'';
1128 $sql =
"SELECT module, perms, subperms";
1129 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1130 $sql .=
" WHERE id = ".((int) $rid);
1131 $sql .=
" AND entity = ".((int) $entity);
1133 $result = $this->db->query($sql);
1135 $obj = $this->db->fetch_object($result);
1138 $module = $obj->module;
1139 $perms = $obj->perms;
1140 $subperms = $obj->subperms;
1148 $whereforadd =
"id=".((int) $rid);
1150 if (!empty($subperms)) {
1151 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
1152 } elseif (!empty($perms)) {
1153 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND (subperms IS NULL or subperms = ''))";
1159 if (!empty($allmodule)) {
1160 if ($allmodule ==
'allmodules') {
1161 $whereforadd =
'allmodules';
1163 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
1164 if (!empty($allperms)) {
1165 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
1173 if (!empty($whereforadd)) {
1176 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1177 $sql .=
" WHERE entity = ".((int) $entity);
1178 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
1179 $sql .=
" AND (".$whereforadd.
")";
1182 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1183 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1185 $sqldelete .=
") AND entity = ".((int) $entity);
1186 if (!$this->db->query($sqldelete)) {
1191 $resql = $this->db->query($sql);
1193 $num = $this->db->num_rows($resql);
1196 $obj = $this->db->fetch_object($resql);
1201 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
1202 if (!$this->db->query($sql)) {
1216 if (!$error && !$notrigger) {
1217 $langs->load(
"other");
1218 $this->context = array(
'audit' => $langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
1221 $result = $this->call_trigger(
'USER_MODIFY', $user);
1229 $this->db->rollback();
1232 $this->db->commit();
1249 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
1251 global $conf, $user, $langs;
1255 $entity = (!empty($entity) ? $entity :
$conf->entity);
1260 $module = $perms = $subperms =
'';
1264 $sql =
"SELECT module, perms, subperms";
1265 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1266 $sql .=
" WHERE id = ".((int) $rid);
1267 $sql .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1269 $result = $this->db->query($sql);
1271 $obj = $this->db->fetch_object($result);
1274 $module = $obj->module;
1275 $perms = $obj->perms;
1276 $subperms = $obj->subperms;
1284 $wherefordel =
"id=".((int) $rid);
1286 if ($subperms ==
'lire' || $subperms ==
'read') {
1287 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->db->escape($perms).
"' AND subperms IS NOT NULL)";
1289 if ($perms ==
'lire' || $perms ==
'read') {
1290 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1296 if (!empty($allmodule)) {
1297 if ($allmodule ==
'allmodules') {
1298 $wherefordel =
'allmodules';
1300 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1301 if (!empty($allperms)) {
1302 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1309 if (!empty($wherefordel)) {
1312 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1313 $sql .=
" WHERE entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1314 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1315 $sql .=
" AND (".$wherefordel.
")";
1319 if ($this->admin == 1) {
1320 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1321 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1322 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1323 $sql .=
" AND id NOT IN (358)";
1326 $sqldelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1327 $sqldelete .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id IN (";
1330 $sqldelete .=
" AND entity IN (".$this->db->sanitize($entity, 0, 0, 0, 0).
")";
1332 $resql = $this->db->query($sqldelete);
1339 if (!$error && !$notrigger) {
1340 $langs->load(
"other");
1341 $this->context = array(
'audit' => $langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1344 $result = $this->call_trigger(
'USER_MODIFY', $user);
1352 $this->db->rollback();
1355 $this->db->commit();
1369 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1371 $this->nb_rights = 0;
1372 $this->all_permissions_are_loaded = 0;
1373 $this->_tab_loaded = array();
1389 $alreadyloaded =
false;
1391 if (empty($forcereload)) {
1392 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1394 $alreadyloaded =
true;
1397 if (!empty($this->all_permissions_are_loaded)) {
1399 $alreadyloaded =
true;
1404 if (!isset($this->rights) || !is_object($this->rights)) {
1407 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1408 $this->rights->user =
new stdClass();
1413 if (!$alreadyloaded) {
1415 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1416 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1417 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1418 $sql .=
" WHERE r.id = ur.fk_id";
1424 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') &&
getDolGlobalString(
'MULTICOMPANY_TRANSVERSE_MODE') ?
"1," :
"").((
int)
$conf->entity).
")";
1428 $sql .=
" AND r.entity = ".((int)
$conf->entity).
" AND ur.entity = ".((int)
$conf->entity);
1430 $sql .=
" AND ur.fk_user = ".((int) $this->
id);
1431 $sql .=
" AND r.perms IS NOT NULL";
1433 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1436 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1439 $resql = $this->db->query($sql);
1441 $num = $this->db->num_rows($resql);
1444 $obj = $this->db->fetch_object($resql);
1447 $module = $obj->module;
1448 $perms = $obj->perms;
1449 $subperms = $obj->subperms;
1451 if (!empty($perms)) {
1452 if (!empty($module)) {
1453 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1454 $this->rights->$module =
new stdClass();
1456 if (!empty($subperms)) {
1457 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1458 $this->rights->$module->$perms =
new stdClass();
1460 if (empty($this->rights->$module->$perms->$subperms)) {
1463 $this->rights->$module->$perms->$subperms = 1;
1465 if (empty($this->rights->$module->$perms)) {
1468 $this->rights->$module->$perms = 1;
1475 $this->db->free($resql);
1479 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms, r.entity";
1480 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1481 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1482 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1483 $sql .=
" WHERE r.id = gr.fk_id";
1489 $sql .=
" AND gu.entity IN (0,".((int)
$conf->entity).
")";
1491 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1494 $sql .=
" AND gr.entity = ".((int)
$conf->entity);
1498 $sql .=
" AND gu.entity IN (0,".((int)
$conf->entity).
")";
1499 $sql .=
" AND r.entity = ".((int)
$conf->entity);
1502 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1503 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1504 $sql .=
" AND r.perms IS NOT NULL";
1506 $sql .=
" AND r.perms NOT LIKE '%_advance'";
1509 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1512 $resql = $this->db->query($sql);
1514 $num = $this->db->num_rows($resql);
1517 $obj = $this->db->fetch_object($resql);
1520 $module = $obj->module;
1521 $perms = $obj->perms;
1522 $subperms = $obj->subperms;
1524 if (!empty($perms)) {
1525 if (!empty($module)) {
1526 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1527 $this->rights->$module =
new stdClass();
1529 if (!empty($subperms)) {
1530 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1531 $this->rights->$module->$perms =
new stdClass();
1533 if (empty($this->rights->$module->$perms->$subperms)) {
1536 $this->rights->$module->$perms->$subperms = 1;
1539 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1540 if (empty($this->rights->$module->$perms)) {
1543 $this->rights->$module->$perms = 1;
1551 $this->db->free($resql);
1555 if (!empty($this->admin)) {
1556 if (empty($this->rights->user->user)) {
1557 $this->rights->user->user =
new stdClass();
1559 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1560 foreach ($listofpermtotest as $permtotest) {
1561 if (empty($this->rights->user->user->$permtotest)) {
1562 $this->rights->user->user->$permtotest = 1;
1566 if (empty($this->rights->user->self)) {
1567 $this->rights->user->self =
new stdClass();
1569 $listofpermtotest = array(
'creer',
'password');
1570 foreach ($listofpermtotest as $permtotest) {
1571 if (empty($this->rights->user->self->$permtotest)) {
1572 $this->rights->user->self->$permtotest = 1;
1578 if (empty($this->rights->user->user_advance)) {
1579 $this->rights->user->user_advance =
new stdClass();
1581 $listofpermtotest = array(
'readperms',
'write');
1582 foreach ($listofpermtotest as $permtotest) {
1583 if (empty($this->rights->user->user_advance->$permtotest)) {
1584 $this->rights->user->user_advance->$permtotest = 1;
1588 if (empty($this->rights->user->self_advance)) {
1589 $this->rights->user->self_advance =
new stdClass();
1591 $listofpermtotest = array(
'readperms',
'writeperms');
1592 foreach ($listofpermtotest as $permtotest) {
1593 if (empty($this->rights->user->self_advance->$permtotest)) {
1594 $this->rights->user->self_advance->$permtotest = 1;
1598 if (empty($this->rights->user->group_advance)) {
1599 $this->rights->user->group_advance =
new stdClass();
1601 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1602 foreach ($listofpermtotest as $permtotest) {
1603 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1604 $this->rights->user->group_advance->$permtotest = 1;
1612 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1613 $this->rights->propal = $this->rights->propale;
1615 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1616 $this->rights->propale = $this->rights->propal;
1623 $this->all_permissions_are_loaded = 1;
1626 $this->_tab_loaded[$moduletag] = 1;
1643 public function getrights($moduletag =
'', $forcereload = 0)
1656 global $conf, $langs, $user;
1661 if (isset($this->statut)) {
1662 if ($this->statut == $status) {
1665 } elseif (isset($this->
status) && $this->
status == $status) {
1672 $sql =
"UPDATE ".$this->db->prefix().
"user";
1673 $sql .=
" SET statut = ".((int) $status);
1674 $sql .=
" WHERE rowid = ".((int) $this->
id);
1675 $result = $this->db->query($sql);
1677 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1680 $this->context[
'actionmsg'] =
'User '.$this->login.
' disabled';
1682 $this->context[
'actionmsg'] =
'User '.$this->login.
' enabled';
1685 $result = $this->call_trigger(
'USER_ENABLEDISABLE', $user);
1693 $this->db->rollback();
1697 $this->statut = $status;
1698 $this->db->commit();
1714 $value = (int) $value;
1717 if ($this->force_pass_change == $value) {
1724 $sql =
"UPDATE ".$this->db->prefix().
"user";
1725 $sql .=
" SET force_pass_change = ".((int) $value);
1726 $sql .=
" WHERE rowid = ".((int) $this->
id);
1727 $result = $this->db->query($sql);
1729 dol_syslog(get_class($this).
"::setForcePasswordChange", LOG_DEBUG);
1731 $this->force_pass_change = $value;
1733 $result = $this->call_trigger(
'USER_MODIFY', $user);
1740 $this->
error = $this->db->lasterror();
1744 $this->db->rollback();
1747 $this->db->commit();
1764 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1765 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1780 $this->
fetch($this->
id);
1782 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1789 'hrm_evaluation' => array(
'label' =>
'EvaluationCard',
'filter' =>
"fk_user = ".((
int) $this->
id)),
1790 'hrm_job_user' => array(
'label' =>
'EmployeePosition',
'filter' =>
"fk_user = ".((
int) $this->
id)),
1791 'hrm_skillrank' => array(
'label' =>
'Skill',
'filter' =>
"objecttype = 'user' AND fk_object = ".((
int) $this->
id)),
1793 foreach ($hrmtables as $hrmtable => $sanitizedhrminfo) {
1794 $sanitizedfilter = $sanitizedhrminfo[
'filter'];
1795 $sql =
"SELECT COUNT(rowid) as nb FROM ".$this->db->prefix().$this->db->sanitize($hrmtable).
" WHERE ".$sanitizedfilter;
1796 $resql = $this->db->query($sql);
1798 $obj = $this->db->fetch_object($resql);
1799 if ($obj && $obj->nb > 0) {
1800 $langs->loadLangs(array(
'errors',
'hrm'));
1801 $this->
error = $langs->trans(
"ErrorRecordHasAtLeastOneChildOfType", $this->login, $langs->transnoentitiesnoconv($sanitizedhrminfo[
'label']));
1802 $this->errors[] = $this->error;
1803 $this->db->rollback();
1811 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1813 if (!$error && !$this->db->query($sql)) {
1815 $this->
error = $this->db->lasterror();
1819 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1820 if (!$error && !$this->db->query($sql)) {
1822 $this->
error = $this->db->lasterror();
1826 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1827 if (!$error && !$this->db->query($sql)) {
1829 $this->
error = $this->db->lasterror();
1833 $sql =
"DELETE FROM ".$this->db->prefix().
"bookmark WHERE fk_user = ".((int) $this->
id);
1834 if (!$error && !$this->db->query($sql)) {
1836 $this->
error = $this->db->lasterror();
1840 if ($this->contact_id > 0) {
1841 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1842 if (!$error && !$this->db->query($sql)) {
1844 $this->
error = $this->db->lasterror();
1853 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1859 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1860 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1861 if (!$this->db->query($sql)) {
1863 $this->
error = $this->db->lasterror();
1869 $result = $this->call_trigger(
'USER_DELETE', $user);
1872 $this->db->rollback();
1877 $this->db->commit();
1880 $this->db->rollback();
1892 public function create($user, $notrigger = 0)
1894 global $conf, $langs;
1900 $this->civility_code = trim((
string) $this->civility_code);
1901 $this->login = trim((
string) $this->login);
1902 $this->user_creation_id = (int) $user->id;
1903 if (!isset($this->entity)) {
1904 $this->entity =
$conf->entity;
1906 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1912 $langs->load(
"errors");
1913 $this->
error = $langs->trans(
"ErrorBadEMail", $this->
email);
1916 if (empty($this->login)) {
1917 $langs->load(
"errors");
1918 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1920 } elseif ($badCharUnauthorizedIntoLoginName !==
'' && preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1921 $langs->load(
"errors");
1922 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1933 $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).
"'";
1934 $resqltochecklogin = $this->db->query($sqltochecklogin);
1935 if ($resqltochecklogin) {
1936 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1937 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1938 $langs->load(
"errors");
1939 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1941 $this->db->rollback();
1944 $this->db->free($resqltochecklogin);
1947 if (!empty($this->
email)) {
1948 $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).
"'";
1949 $resqltochecklogin = $this->db->query($sqltochecklogin);
1950 if ($resqltochecklogin) {
1951 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
1952 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1953 $langs->load(
"errors");
1954 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->
email);
1956 $this->db->rollback();
1959 $this->db->free($resqltochecklogin);
1964 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, fk_user_creat, entity)";
1965 $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).
")";
1966 $result = $this->db->query($sql);
1968 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1970 $this->
id = $this->db->last_insert_id($this->db->prefix().
"user");
1974 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1975 $this->db->rollback();
1980 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1981 $langs->load(
"stocks");
1983 $entrepot =
new Entrepot($this->db);
1984 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1985 $entrepot->libelle = $entrepot->label;
1986 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1987 $entrepot->statut = 1;
1988 $entrepot->country_id =
$mysoc->country_id;
1990 $warehouseid = $entrepot->create($user);
1992 $this->fk_warehouse = $warehouseid;
1996 $result = $this->
update($user, 1, 1);
1998 $this->db->rollback();
2004 $result = $this->call_trigger(
'USER_CREATE', $user);
2012 $this->db->commit();
2017 $this->db->rollback();
2021 $this->
error = $this->db->lasterror();
2022 $this->db->rollback();
2046 $this->civility_code = $contact->civility_code;
2047 $this->lastname = $contact->lastname;
2048 $this->firstname = $contact->firstname;
2050 $this->
email = $contact->email;
2051 $this->socialnetworks = $contact->socialnetworks;
2052 $this->office_phone = $contact->phone_pro;
2053 $this->office_fax = $contact->fax;
2054 $this->user_mobile = $contact->phone_mobile;
2055 $this->
address = $contact->address;
2056 $this->zip = $contact->zip;
2057 $this->town = $contact->town;
2059 $this->state_id = $contact->state_id;
2060 $this->country_id = $contact->country_id;
2061 $this->employee = 0;
2063 if (empty($login)) {
2064 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
2065 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
2067 $this->login = $login;
2072 $result = $this->
create($user, 1);
2074 $sql =
"UPDATE ".$this->db->prefix().
"user";
2075 $sql .=
" SET fk_socpeople=".((int) $contact->id);
2076 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
2077 if ($contact->socid > 0) {
2078 $sql .=
", fk_soc=".((int) $contact->socid);
2080 $sql .=
" WHERE rowid=".((int) $this->
id);
2082 $resql = $this->db->query($sql);
2084 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
2086 $this->context[
'createfromcontact'] =
'createfromcontact';
2089 $result = $this->call_trigger(
'USER_CREATE', $user);
2092 $this->db->rollback();
2097 $this->db->commit();
2100 $this->
error = $this->db->error();
2102 $this->db->rollback();
2107 dol_syslog(get_class($this).
"::create_from_contact - 0");
2109 $this->db->rollback();
2130 $this->civility_code = $member->civility_code;
2133 if ($member->morphy ==
'mor' && empty($member->lastname) && !empty($member->company)) {
2134 $this->lastname = $member->company;
2135 $this->firstname =
'';
2137 $this->lastname = $member->lastname;
2138 $this->firstname = $member->firstname;
2140 $this->gender = $member->gender;
2141 $this->
email = $member->email;
2142 $this->fk_member = $member->id;
2143 $this->
address = $member->address;
2144 $this->zip = $member->zip;
2145 $this->town = $member->town;
2147 $this->state_id = $member->state_id;
2148 $this->country_id = $member->country_id;
2149 $this->socialnetworks = $member->socialnetworks;
2151 $this->pass = $member->pass;
2152 $this->pass_crypted = $member->pass_indatabase_crypted;
2154 if (empty($login)) {
2155 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
2159 $this->login = $login;
2164 $result = $this->
create($user);
2166 if (!empty($this->pass)) {
2167 $newpass = $this->
setPassword($user, $this->pass);
2168 if (is_int($newpass) && $newpass < 0) {
2171 } elseif (!empty($this->pass_crypted)) {
2172 $sql =
"UPDATE ".$this->db->prefix().
"user";
2173 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
2174 $sql .=
" WHERE rowid=".((int) $this->
id);
2176 $resql = $this->db->query($sql);
2182 if ($result > 0 && $member->socid) {
2183 $sql =
"UPDATE ".$this->db->prefix().
"user";
2184 $sql .=
" SET fk_soc=".((int) $member->socid);
2185 $sql .=
" WHERE rowid=".((int) $this->
id);
2187 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
2188 $resql = $this->db->query($sql);
2190 $this->db->commit();
2193 $this->
error = $this->db->lasterror();
2195 $this->db->rollback();
2202 $this->db->commit();
2206 $this->db->rollback();
2224 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
2225 $sql .=
" WHERE bydefault = 1";
2226 $sql .=
" AND entity = ".((int)
$conf->entity);
2228 $resql = $this->db->query($sql);
2230 $num = $this->db->num_rows($resql);
2233 $row = $this->db->fetch_row($resql);
2237 $this->db->free($resql);
2241 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id).
" AND fk_id=".((int) $rd[$i]);
2242 $result = $this->db->query($sql);
2244 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES (".((int) $this->
id).
", ".((int) $rd[$i]).
")";
2245 $result = $this->db->query($sql);
2265 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
2269 if (empty($this->country_id) && !empty($this->country_code)) {
2270 $country_id =
getCountry($this->country_code,
'3');
2271 $this->country_id = is_int($country_id) ? $country_id : 0;
2274 $nbrowsaffected = 0;
2277 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
2280 $this->civility_code = trim((
string) $this->civility_code);
2281 $this->lastname = trim((
string) $this->lastname);
2282 $this->firstname = trim((
string) $this->firstname);
2283 $this->ref_employee = trim((
string) $this->ref_employee);
2284 $this->national_registration_number = trim((
string) $this->national_registration_number);
2285 $this->employee = ($this->employee > 0 ? $this->employee : 0);
2286 $this->login = trim((
string) $this->login);
2287 $this->gender = trim((
string) $this->gender);
2289 $this->pass = trim((
string) $this->pass);
2290 $this->api_key = trim((
string) $this->api_key);
2291 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
2292 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
2295 $this->zip = trim((
string) $this->zip);
2296 $this->town = trim((
string) $this->town);
2298 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
2299 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
2300 $this->office_phone = trim((
string) $this->office_phone);
2301 $this->office_fax = trim((
string) $this->office_fax);
2302 $this->user_mobile = trim((
string) $this->user_mobile);
2303 $this->personal_mobile = trim((
string) $this->personal_mobile);
2305 $this->personal_email = trim((
string) $this->personal_email);
2307 $this->job = trim((
string) $this->job);
2308 $this->signature = trim((
string) $this->signature);
2309 $this->note_public = trim((
string) $this->note_public);
2310 $this->note_private = trim((
string) $this->note_private);
2311 $this->openid = trim((
string) $this->openid);
2312 $this->admin = ($this->admin > 0 ? $this->admin : 0);
2313 $this->user_modification_id = $user->id;
2315 $this->accountancy_code_user_general = trim((
string) $this->accountancy_code_user_general);
2316 $this->accountancy_code = trim((
string) $this->accountancy_code);
2317 $this->color = trim(str_replace(
'#',
'', (
string) $this->color));
2318 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
2319 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
2321 $this->birth = empty($this->birth) ?
'' : $this->birth;
2322 $this->fk_warehouse = (int) $this->fk_warehouse;
2323 $this->fk_establishment = (int) $this->fk_establishment;
2331 $langs->load(
"errors");
2332 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
2335 if (empty($this->login)) {
2336 $langs->load(
"errors");
2337 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
2339 } elseif ($badCharUnauthorizedIntoLoginName !==
'' && preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
2340 $langs->load(
"errors");
2341 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
2348 if (is_object($this->oldcopy) && !empty($this->oldcopy->id) && $this->oldcopy->login != $this->login) {
2349 $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).
"'";
2350 $resqltochecklogin = $this->db->query($sqltochecklogin);
2351 if ($resqltochecklogin) {
2352 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2353 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2354 $langs->load(
"errors");
2355 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
2357 $this->db->rollback();
2362 if (is_object($this->oldcopy) && !empty($this->oldcopy->id) && !empty($this->email) && $this->oldcopy->email != $this->email) {
2363 $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).
"'";
2364 $resqltochecklogin = $this->db->query($sqltochecklogin);
2365 if ($resqltochecklogin) {
2366 $objtochecklogin = $this->db->fetch_object($resqltochecklogin);
2367 if ($objtochecklogin && $objtochecklogin->nb > 0) {
2368 $langs->load(
"errors");
2369 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
2371 $this->db->rollback();
2378 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2379 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
2380 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
2381 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
2382 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
2383 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
2384 $sql .=
", employee = ".(int) $this->employee;
2385 $sql .=
", login = '".$this->db->escape($this->login).
"'";
2386 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape(
dolEncrypt($this->api_key,
'',
'',
'dolibarr')).
"'" :
"null");
2387 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
2388 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
2389 if (!empty($user->admin)) {
2390 $sql .=
", admin = ".(int) $this->admin;
2392 $sql .=
", address = '".$this->db->escape($this->address).
"'";
2393 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
2394 $sql .=
", town = '".$this->db->escape($this->town).
"'";
2395 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ? ((
int) $this->state_id) :
"null");
2396 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ? ((
int) $this->country_id) :
"null");
2397 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
2398 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
2399 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
2400 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
2401 $sql .=
", email = '".$this->db->escape($this->email).
"'";
2402 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
2403 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
2404 $sql .=
", job = '".$this->db->escape($this->job).
"'";
2405 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
2406 $sql .=
", accountancy_code_user_general = '".$this->db->escape($this->accountancy_code_user_general).
"'";
2407 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
2408 $sql .=
", color = '".$this->db->escape($this->color).
"'";
2409 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
2410 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
2411 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
2412 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
2413 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
2414 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2415 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2416 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2417 $sql .=
", fk_user = ".($this->fk_user > 0 ? ((int) $this->fk_user) :
"null");
2418 $sql .=
", fk_user_modif = ".($this->user_modification_id > 0 ? ((int) $this->user_modification_id) :
"null");
2419 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ? ((int) $this->fk_user_expense_validator) :
"null");
2420 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ? ((int) $this->fk_user_holiday_validator) :
"null");
2421 if (isset($this->thm) || $this->thm !=
'') {
2422 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2424 if (isset($this->tjm) || $this->tjm !=
'') {
2425 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2427 if (isset($this->salary) || $this->salary !=
'') {
2428 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2430 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2431 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2433 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2434 if (
isModEnabled(
'multicompany') && !empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2439 $sql .=
", entity = ".((int) $this->entity);
2442 $sql .=
", default_range = ".($this->default_range > 0 ? ((int) $this->default_range) :
'null');
2443 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? ((int) $this->default_c_exp_tax_cat) :
'null');
2444 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? ((int) $this->fk_warehouse) :
"null");
2445 $sql .=
", fk_establishment = ".($this->fk_establishment > 0 ? ((int) $this->fk_establishment) :
"null");
2446 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2447 $sql .=
", force_pass_change = ".($this->force_pass_change ? ((int) $this->force_pass_change) :
"0");
2448 $sql .=
" WHERE rowid = ".((int) $this->
id);
2450 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2451 $resql = $this->db->query($sql);
2453 $nbrowsaffected += $this->db->affected_rows($resql);
2456 if (!empty($this->pass)) {
2457 if ($this->pass != $this->pass_indatabase && !
dol_verifyHash($this->pass, $this->pass_indatabase_crypted)) {
2459 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass, 0, 1);
2460 if (is_int($result) && $result < 0) {
2467 if ($this->fk_member > 0) {
2468 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2469 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2470 $resql = $this->db->query($sql);
2472 $this->
error = $this->db->error();
2473 $this->db->rollback();
2478 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2479 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2480 $resql = $this->db->query($sql);
2482 $this->
error = $this->db->error();
2483 $this->db->rollback();
2487 if ($nbrowsaffected) {
2488 if ($this->fk_member > 0 && !$nosyncmember) {
2489 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2491 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2496 $result = $adh->fetch($this->fk_member);
2499 $adh->civility_code = $this->civility_code;
2500 $adh->firstname = $this->firstname;
2501 $adh->lastname = $this->lastname;
2502 $adh->login = $this->login;
2503 $adh->gender = $this->gender;
2504 $adh->birth = $this->birth;
2506 $adh->pass = $this->pass;
2508 $adh->address = $this->address;
2509 $adh->town = $this->town;
2510 $adh->zip = $this->zip;
2511 $adh->state_id = $this->state_id;
2512 $adh->country_id = $this->country_id;
2514 $adh->email = $this->email;
2516 $adh->socialnetworks = $this->socialnetworks;
2518 $adh->phone = $this->office_phone;
2519 $adh->phone_mobile = $this->user_mobile;
2521 $adh->default_lang = $this->lang;
2523 $adh->user_id = $this->id;
2524 $adh->user_login = $this->login;
2526 $result = $adh->update($user, 0, 1, 0);
2528 $this->
error = $adh->error;
2529 $this->errors = $adh->errors;
2530 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2533 } elseif ($result < 0) {
2534 $this->
error = $adh->error;
2535 $this->errors = $adh->errors;
2540 if ($this->contact_id > 0 && !$nosynccontact) {
2541 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2543 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2546 $tmpobj =
new Contact($this->db);
2547 $result = $tmpobj->fetch($this->contact_id);
2550 $tmpobj->civility_code = $this->civility_code;
2551 $tmpobj->firstname = $this->firstname;
2552 $tmpobj->lastname = $this->lastname;
2553 $tmpobj->login = $this->login;
2554 $tmpobj->gender = $this->gender;
2555 $tmpobj->birth = $this->birth;
2559 $tmpobj->email = $this->email;
2561 $tmpobj->socialnetworks = $this->socialnetworks;
2563 $tmpobj->phone_pro = $this->office_phone;
2564 $tmpobj->phone_mobile = $this->user_mobile;
2565 $tmpobj->fax = $this->office_fax;
2567 $tmpobj->default_lang = $this->lang;
2569 $tmpobj->address = $this->address;
2570 $tmpobj->town = $this->town;
2571 $tmpobj->zip = $this->zip;
2572 $tmpobj->state_id = $this->state_id;
2573 $tmpobj->country_id = $this->country_id;
2575 $tmpobj->user_id = $this->id;
2576 $tmpobj->user_login = $this->login;
2578 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2580 $this->
error = $tmpobj->error;
2581 $this->errors = $tmpobj->errors;
2582 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2586 $this->
error = $tmpobj->error;
2587 $this->errors = $tmpobj->errors;
2603 if (!$error && !$notrigger) {
2605 $result = $this->call_trigger(
'USER_MODIFY', $user);
2613 $this->db->commit();
2614 return $nbrowsaffected;
2617 $this->db->rollback();
2621 $this->
error = $this->db->lasterror();
2622 $this->db->rollback();
2641 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2642 $sql .=
" datepreviouslogin = datelastlogin,";
2643 $sql .=
" ippreviouslogin = iplastlogin,";
2644 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2645 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2646 $sql .=
" tms = tms";
2647 $sql .=
" WHERE rowid = ".((int) $this->
id);
2649 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2650 $resql = $this->db->query($sql);
2652 $this->datepreviouslogin = $this->datelastlogin;
2653 $this->datelastlogin = $now;
2654 $this->ippreviouslogin = $this->iplastlogin;
2655 $this->iplastlogin = $userremoteip;
2658 $this->
error = $this->db->lasterror().
' sql='.$sql;
2676 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0, $flagdelsessionsbefore = 1)
2678 global $conf, $langs;
2679 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2683 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2688 $passwordalreadycrypted = 0;
2692 if (!empty($passwordalreadycrypted)) {
2693 $password_crypted = $password;
2697 $modGeneratePassClass =
'modGeneratePass'.ucfirst(
getDolGlobalString(
'USER_PASSWORD_GENERATED'));
2699 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2700 if (class_exists($modGeneratePassClass)) {
2701 $modGeneratePass =
new $modGeneratePassClass($this->db,
$conf, $langs, $user);
2702 '@phan-var-force ModeleGenPassword $modGeneratePass';
2705 $modGeneratePass->WithoutAmbi = 0;
2708 $testpassword = $modGeneratePass->validatePassword($password);
2709 if (!$testpassword) {
2710 $this->
error = $modGeneratePass->error;
2722 if (!$changelater) {
2723 if (!is_object($this->oldcopy)) {
2724 $this->oldcopy = clone $this;
2731 $sql =
"UPDATE ".$this->db->prefix().
"user";
2732 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2733 $sql .=
" datelastpassvalidation = '".$this->db->idate(
dol_now()).
"',";
2734 $sql .=
" pass_temp = null,";
2735 $sql .=
" force_pass_change = 0";
2736 if (!empty($flagdelsessionsbefore)) {
2737 $sql .=
", flagdelsessionsbefore = '".$this->db->idate($now - 5,
'gmt').
"'";
2740 $sql .=
", pass = null";
2742 $sql .=
", pass = '".$this->db->escape($password).
"'";
2744 $sql .=
" WHERE rowid = ".((int) $this->
id);
2746 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2748 $result = $this->db->query($sql);
2750 if ($this->db->affected_rows($result)) {
2751 $this->pass = $password;
2752 $this->pass_indatabase = $password;
2753 $this->pass_indatabase_crypted = (
string) $password_crypted;
2754 $this->force_pass_change = 0;
2756 if ($this->fk_member && !$nosyncmember) {
2757 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2762 $result = $adh->fetch($this->fk_member);
2765 $result = $adh->setPassword($user, $this->pass, (!
getDolGlobalString(
'DATABASE_PWD_ENCRYPTED') ? 0 : 1), 1);
2766 if (is_int($result) && $result < 0) {
2767 $this->
error = $adh->error;
2772 $this->
error = $adh->error;
2777 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2780 $user->context[
'audit'] =
'login='.$user->login;
2781 if (!empty($flagdelsessionsbefore)) {
2782 $user->context[
'audit'] .=
" - flagdelsessionsbefore set to '".$this->db->idate($now - 5,
'gmt').
"'";
2785 if (!$error && !$notrigger) {
2787 $result = $this->call_trigger(
'USER_NEW_PASSWORD', $user);
2790 $this->db->rollback();
2796 $this->db->commit();
2799 $this->db->rollback();
2803 $this->db->rollback();
2810 $sql =
"UPDATE ".$this->db->prefix().
"user";
2811 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2812 $sql .=
" WHERE rowid = ".((int) $this->
id);
2814 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2815 $result = $this->db->query($sql);
2837 global $conf, $langs;
2840 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2852 $outputlangs = $langs;
2856 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2858 $appli =
getDolGlobalString(
'MAIN_APPLICATION_TITLE', constant(
'DOL_APPLICATION_TITLE'));
2860 $subject =
'['.$appli.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2863 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
2864 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2866 if (!$changelater) {
2867 $url = $urlwithroot.
'/';
2872 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2874 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"\n";
2875 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2876 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2877 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2880 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2882 $mesg .= $user->getFullName($outputlangs);
2885 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2886 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.
$conf->file->instance_unique_id));
2888 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2891 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2895 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2896 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2897 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2898 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2900 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2901 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2902 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2905 $trackid =
'use'.$this->id;
2906 $sendcontext =
'passwordreset';
2927 if ($mailfile->sendfile()) {
2930 $langs->trans(
"errors");
2931 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2943 return $this->error;
2956 $sql =
"SELECT url, login, pass, poste ";
2957 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2958 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2960 $resql = $this->db->query($sql);
2962 if ($this->db->num_rows($resql)) {
2963 $obj = $this->db->fetch_object($resql);
2965 $this->clicktodial_url = $obj->url;
2966 $this->clicktodial_login = $obj->login;
2967 $this->clicktodial_password = $obj->pass;
2968 $this->clicktodial_poste = $obj->poste;
2971 $this->clicktodial_loaded = 1;
2973 $this->db->free($resql);
2976 $this->
error = $this->db->error();
2992 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2993 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2995 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2997 $result = $this->db->query($sql);
2999 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
3000 $sql .=
" (fk_user,url,login,pass,poste)";
3001 $sql .=
" VALUES (".((int) $this->
id);
3002 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
3003 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
3004 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
3005 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
3007 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
3009 $result = $this->db->query($sql);
3011 $this->db->commit();
3014 $this->db->rollback();
3015 $this->
error = $this->db->lasterror();
3033 global $langs, $user;
3039 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
3040 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3041 $sql .=
" AND fk_usergroup = ".((int) $group);
3042 $sql .=
" AND entity = ".((int) $entity);
3044 $result = $this->db->query($sql);
3046 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
3047 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
3049 $result = $this->db->query($sql);
3051 if (!$error && !$notrigger) {
3052 $this->context = array(
'audit' => $langs->trans(
"UserSetInGroup"),
'newgroupid' => $group);
3055 $result = $this->call_trigger(
'USER_MODIFY', $user);
3063 $this->db->commit();
3067 $this->db->rollback();
3071 $this->
error = $this->db->lasterror();
3072 $this->db->rollback();
3089 global $langs, $user;
3095 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
3096 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3097 $sql .=
" AND fk_usergroup = ".((int) $group);
3098 if (empty($entity)) {
3099 $sql .=
" AND entity IN (0, 1)";
3101 $sql .=
" AND entity = ".((int) $entity);
3104 $result = $this->db->query($sql);
3106 if (!$error && !$notrigger) {
3107 $this->context = array(
'audit' => $langs->trans(
"UserRemovedFromGroup"),
'oldgroupid' => $group);
3110 $result = $this->call_trigger(
'USER_MODIFY', $user);
3118 $this->db->commit();
3121 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
3122 $this->db->rollback();
3126 $this->
error = $this->db->lasterror();
3127 $this->db->rollback();
3141 include_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
3148 if ($this->datestartvalidity && $this->datestartvalidity >
dol_get_last_hour($now)) {
3171 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
3173 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3174 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
3188 global $conf, $langs, $menumanager;
3189 global $dolibarr_main_demo;
3191 $infologin = $params[
'infologin'] ?? 0;
3192 $option = $params[
'option'] ??
'';
3195 if (!empty($this->photo)) {
3196 $photo =
'<div class="photointooltip floatright">';
3197 $photo .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
3199 $data[
'photo'] = $photo;
3204 $data[
'opendiv'] =
'<div class="centpercent divtooltip">';
3205 $data[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u> '.$this->
getLibStatut(4);
3207 if (!empty($this->login)) {
3210 if (!empty($this->job)) {
3214 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
3215 $phonelist = array();
3216 if ($this->office_phone) {
3217 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
3219 if ($this->office_fax) {
3220 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
3222 if ($this->user_mobile) {
3223 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
3225 $data[
'phones'] =
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
3227 if (!empty($this->admin)) {
3228 $data[
'administrator'] =
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
3230 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
3231 $langs->load(
"companies");
3232 $data[
'accountancycode'] =
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
3235 if (!empty($this->socid)) {
3236 $thirdpartystatic =
new Societe($this->db);
3237 $thirdpartystatic->fetch($this->socid);
3239 if (empty($params[
'hidethirdpartylogo'])) {
3240 $companyimg =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3242 $company =
' ('.$langs->trans(
"Company").
': '.($companyimg ? $companyimg :
img_picto(
'',
'company')).
' '.
dol_string_nohtmltag($thirdpartystatic->name).
')';
3244 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
3245 $data[
'type'] =
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
3246 $data[
'closediv'] =
'</div>';
3248 if ($infologin > 0) {
3249 $data[
'newlinelogin'] =
'<br>';
3250 $data[
'session'] =
'<br><u>'.$langs->trans(
"Session").
'</u>';
3253 $data[
'multicompany'] =
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.
$conf->entity.
' (User entity '.$this->entity.
')';
3255 $data[
'authentication'] =
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
3256 $data[
'connectedsince'] =
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
3257 $data[
'previousconnexion'] =
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
3260 $data[
'currentmenumanager'] =
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
3262 $data[
'currentuserlang'] =
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
3263 $data[
'browser'] =
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag(
$conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
3265 $data[
'screen'] =
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
3266 if (
$conf->browser->layout ==
'phone') {
3267 $data[
'phone'] =
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
3269 if (!empty($_SESSION[
"disablemodules"])) {
3270 $data[
'disabledmodules'] =
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(implode(
', ', explode(
',', $_SESSION[
"disablemodules"])));
3292 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
3294 global $langs, $hookmanager, $user;
3296 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
3307 'objecttype' => $this->element,
3308 'infologin' => $infologin,
3309 'option' => $option,
3310 'hidethirdpartylogo' => $hidethirdpartylogo,
3312 $classfortooltip =
'classfortooltip';
3315 $classfortooltip =
'classforajaxtooltip';
3316 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
3323 if (!empty($this->socid)) {
3324 $thirdpartystatic =
new Societe($this->db);
3325 $thirdpartystatic->fetch($this->socid);
3326 if (empty($hidethirdpartylogo)) {
3327 $companylink =
' '.$thirdpartystatic->getNomUrl(2,
'nolink', 0, 1);
3331 if ($infologin < 0) {
3335 $baseurl = DOL_URL_ROOT .
'/user/card.php';
3336 if ($option ==
'leave') {
3337 $baseurl = DOL_URL_ROOT .
'/holiday/list.php';
3339 $query = [
'id' => $this->id];
3340 if ($option !=
'nolink') {
3342 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3343 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3344 $add_save_lastsearch_values = 1;
3346 if ($add_save_lastsearch_values) {
3347 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
3352 $linkstart =
'<a href="'.$url.
'"';
3354 if (empty($notooltip)) {
3356 $langs->load(
"users");
3357 $label = $langs->trans(
"ShowUser");
3358 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
3360 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
3361 $linkclose .= $dataparams .
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
3363 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
3366 $linkstart .= $linkclose.
'>';
3370 $result .= (($option ==
'nolink') ?
'' : $linkstart);
3371 if ($withpictoimg) {
3372 $paddafterimage =
'';
3373 if (abs((
int) $withpictoimg) == 1 || abs((
int) $withpictoimg) == 4) {
3374 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3377 if ($withpictoimg > 0) {
3378 $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>';
3381 $picto =
'<!-- picto photo user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'"'.($paddafterimage ?
' '.$paddafterimage :
'').
'>';
3382 $picto .=
Form::showphoto(
'userphoto', $this, 0, 0, 0,
'userphoto'.(($withpictoimg == -3 || $withpictoimg == -4) ?
'small' :
''),
'mini', 0, 1);
3383 $picto .=
'</span>';
3388 if ($withpictoimg == -4 || ($withpictoimg > -2 && $withpictoimg != 2)) {
3390 $result .=
'<span class="nopadding usertext'.((!isset($this->
status) || $this->status) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
3392 if ($mode ==
'login') {
3398 $result .=
'</span>';
3401 $result .= (($option ==
'nolink') ?
'' : $linkend);
3404 $result .= $companylink;
3407 $hookmanager->initHooks(array(
'userdao'));
3408 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
3409 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
3411 $result = $hookmanager->resPrint;
3413 $result .= $hookmanager->resPrint;
3428 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
3430 global $langs, $user;
3434 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3438 if ((!$user->hasRight(
'user',
'user',
'lire') && $this->id != $user->id)) {
3442 if ($option ==
'xxx') {
3443 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
3447 if ($option ==
'nolink') {
3452 $result .= $linkstart;
3453 if ($withpictoimg) {
3454 $paddafterimage =
'';
3455 if (abs($withpictoimg) == 1) {
3456 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
3459 if ($withpictoimg > 0) {
3460 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
3463 $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>';
3467 $result .= $this->login;
3468 $result .= $linkend;
3481 return $this->
LibStatut(isset($this->statut) ? (
int) $this->statut : (int) $this->
status, $mode);
3497 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
3500 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3501 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3502 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
3503 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
3506 $statusType =
'status5';
3507 if ($status == self::STATUS_ENABLED) {
3508 $statusType =
'status4';
3511 $label = $this->labelStatus[$status];
3512 $labelshort = $this->labelStatusShort[$status];
3515 if (!empty($this->datestartvalidity) && $now < $this->datestartvalidity) {
3516 $statusType =
'status3';
3517 $label .=
' ('.$langs->trans(
"UserNotYetValid").
')';
3519 if (!empty($this->dateendvalidity) && $now > ($this->dateendvalidity + 24 * 3600 - 1)) {
3520 $statusType =
'status2';
3521 $label .=
' ('.$langs->trans(
"UserExpired").
')';
3524 return dolGetStatus($label, $labelshort,
'', $statusType, $mode);
3539 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3541 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3542 $return .=
'<div class="info-box info-box-sm">';
3543 $return .=
'<span class="info-box-icon bg-infobox-action">';
3546 if (!empty($this->photo)) {
3548 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3557 $return .=
'</span>';
3558 $return .=
'<div class="info-box-content">';
3559 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(0,
'', 0, 0, 24, 0,
'',
'valignmiddle') : $this->ref);
3560 if (
isModEnabled(
'multicompany') && $this->admin && !$this->entity) {
3561 $return .=
img_picto($langs->trans(
"SuperAdministratorDesc"),
'superadmin',
'class="valignmiddle paddingright paddingleft"');
3562 } elseif ($this->admin) {
3563 $return .=
img_picto($langs->trans(
"AdministratorDesc"),
'admin',
'class="valignmiddle paddingright paddingleft"');
3565 $return .=
'</span>';
3566 if ($selected >= 0) {
3567 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3569 if (property_exists($this,
'label')) {
3570 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3573 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->
email.
'</span>';
3575 if (method_exists($this,
'getLibStatut')) {
3576 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3578 $return .=
'</div>';
3579 $return .=
'</div>';
3580 $return .=
'</div>';
3604 } elseif ($mode == 1) {
3606 } elseif ($mode == 2) {
3622 global $conf, $langs;
3628 $keymodified =
false;
3637 'LDAP_FIELD_FULLNAME' =>
'fullname',
3638 'LDAP_FIELD_NAME' =>
'lastname',
3639 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3640 'LDAP_FIELD_LOGIN' =>
'login',
3641 'LDAP_FIELD_LOGIN_SAMBA' =>
'login',
3642 'LDAP_FIELD_PHONE' =>
'office_phone',
3643 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3644 'LDAP_FIELD_FAX' =>
'office_fax',
3645 'LDAP_FIELD_MAIL' =>
'email',
3646 'LDAP_FIELD_SID' =>
'ldap_sid',
3650 foreach ($ldapkey as $constname => $varname) {
3656 if (is_object($this->oldcopy) && !empty($this->oldcopy->id) && $this->$varname != $this->oldcopy->$varname) {
3657 $keymodified =
true;
3662 foreach ($socialnetworks as $key => $value) {
3663 if (!empty($this->socialnetworks[$value[
'label']]) &&
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))) {
3664 $info[
getDolGlobalString(
'LDAP_FIELD_'.strtoupper($value[
'label']))] = $this->socialnetworks[$value[
'label']];
3680 $soc =
new Societe($this->db);
3681 $soc->fetch($this->socid);
3684 if ($soc->client == 1) {
3685 $info[
"businessCategory"] =
"Customers";
3687 if ($soc->client == 2) {
3688 $info[
"businessCategory"] =
"Prospects";
3690 if ($soc->fournisseur == 1) {
3691 $info[
"businessCategory"] =
"Suppliers";
3696 if (!empty($this->pass)) {
3709 if ($this->pass_indatabase_crypted &&
getDolGlobalString(
'LDAP_FIELD_PASSWORD_CRYPTED')) {
3713 } elseif (!empty($this->pass_indatabase)) {
3725 $info[
"objectclass"][4] =
"phpgwContact";
3727 $info[
'uidnumber'] = $this->id;
3729 $info[
'phpgwTz'] = 0;
3730 $info[
'phpgwMailType'] =
'INTERNET';
3731 $info[
'phpgwMailHomeType'] =
'INTERNET';
3733 $info[
"phpgwContactTypeId"] =
'n';
3734 $info[
"phpgwContactCatId"] = 0;
3735 $info[
"phpgwContactAccess"] =
"public";
3737 $info[
"phpgwContactOwner"] = 1;
3740 $info[
"rfc822Mailbox"] = $this->email;
3742 if ($this->user_mobile) {
3743 $info[
"phpgwCellTelephoneNumber"] = $this->user_mobile;
3752 $groupslist = $usergroup->listGroupsForUser($this->
id);
3754 if (!empty($groupslist)) {
3755 foreach ($groupslist as $groupforuser) {
3784 $this->
ref =
'SPECIMEN';
3785 $this->specimen = 1;
3786 $this->user_creation_id = $user->id;
3788 $this->lastname =
'DOLIBARR';
3789 $this->firstname =
'SPECIMEN';
3790 $this->gender =
'man';
3791 $this->note_public =
'This is a note public';
3792 $this->note_private =
'This is a note private';
3793 $this->
email =
'email@specimen.com';
3794 $this->personal_email =
'personalemail@specimen.com';
3795 $this->socialnetworks = array(
3796 'skype' =>
'skypepseudo',
3797 'twitter' =>
'twitterpseudo',
3798 'facebook' =>
'facebookpseudo',
3799 'linkedin' =>
'linkedinpseudo',
3801 $this->office_phone =
'0999999999';
3802 $this->office_fax =
'0999999998';
3803 $this->user_mobile =
'0999999997';
3804 $this->personal_mobile =
'0999999996';
3806 $this->login =
'dolibspec';
3807 $this->pass =
'dolibSpec+@123';
3810 $this->datec = $now;
3811 $this->datem = $now;
3813 $this->datelastlogin = $now;
3814 $this->iplastlogin =
'127.0.0.1';
3815 $this->datepreviouslogin = $now;
3816 $this->ippreviouslogin =
'127.0.0.1';
3832 $sql =
"SELECT u.rowid, u.login as ref, u.datec, fk_user_creat as user_creation_id, fk_user_modif as user_modification_id,";
3833 $sql .=
" GREATEST(u.tms, COALESCE(uef.tms, u.tms)) as date_modification, u.entity";
3834 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3835 $sql .=
" LEFT JOIN ".$this->db->prefix().
"user_extrafields as uef ON uef.fk_object = u.rowid";
3836 $sql .=
" WHERE u.rowid = ".((int) $id);
3838 $result = $this->db->query($sql);
3840 if ($this->db->num_rows($result)) {
3841 $obj = $this->db->fetch_object($result);
3843 $this->
id = $obj->rowid;
3845 $this->user_creation_id = $obj->user_creation_id;
3846 $this->user_modification_id = $obj->user_modification_id;
3848 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3849 $this->date_creation = $this->db->jdate($obj->datec);
3850 $this->date_modification = $this->db->jdate($obj->date_modification);
3851 $this->entity = $obj->entity;
3854 $this->db->free($result);
3868 $sql =
"SELECT count(mc.email) as nb";
3869 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3870 $sql .=
" WHERE mc.email = '".$this->db->escape($this->
email).
"'";
3871 $sql .=
" AND mc.statut NOT IN (-1,0)";
3873 $resql = $this->db->query($sql);
3875 $obj = $this->db->fetch_object($resql);
3876 $nb = (int) $obj->nb;
3878 $this->db->free($resql);
3881 $this->
error = $this->db->error();
3896 $sql =
"SELECT count(rowid) as nb";
3897 $sql .=
" FROM ".$this->db->prefix().
"user";
3898 if ($option ==
'superadmin') {
3899 $sql .=
" WHERE entity = 0";
3901 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3902 if ($limitTo ==
'active') {
3903 $sql .=
" AND statut = 1";
3907 $sql .=
" AND admin = ".(int) $admin;
3910 $resql = $this->db->query($sql);
3912 $obj = $this->db->fetch_object($resql);
3913 $nb = (int) $obj->nb;
3915 $this->db->free($resql);
3918 $this->
error = $this->db->lasterror();
3939 $this->firstname = $ldapuser->$tmpvar;
3941 $this->lastname = $ldapuser->$tmpvar;
3943 $this->login = $ldapuser->$tmpvar;
3945 $this->pass = $ldapuser->$tmpvar;
3947 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3950 $this->office_phone = $ldapuser->$tmpvar;
3952 $this->user_mobile = $ldapuser->$tmpvar;
3954 $this->office_fax = $ldapuser->$tmpvar;
3956 $this->
email = $ldapuser->$tmpvar;
3957 foreach ($socialnetworks as $key => $value) {
3959 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3962 $this->ldap_sid = $ldapuser->$tmpvar;
3965 $this->job = $ldapuser->$tmpvar;
3967 $this->note_public = $ldapuser->$tmpvar;
3969 $result = $this->
update($user);
3971 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3987 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3988 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3990 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3991 $res = $this->db->query($sql);
3994 while ($rec = $this->db->fetch_array($res)) {
3995 $user =
new User($this->db);
3996 $user->fetch($rec[
'rowid']);
4014 $this->parentof = array();
4017 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
4018 $sql .=
" FROM ".$this->db->prefix().
"user";
4019 $sql .=
" WHERE fk_user <> 0";
4020 $sql .=
" AND entity IN (".getEntity(
'user').
")";
4022 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
4023 $resql = $this->db->query($sql);
4025 while ($obj = $this->db->fetch_object($resql)) {
4026 $this->parentof[$obj->id_son] = $obj->id_parent;
4052 global $hookmanager;
4055 $hookmanager->initHooks(array(
'userdao'));
4057 $this->users = array();
4063 $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";
4064 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4066 $parameters = array();
4067 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
4069 $sql .= $hookmanager->resPrint;
4071 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4077 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
4078 $resql = $this->db->query($sql);
4081 while ($obj = $this->db->fetch_object($resql)) {
4082 $this->users[(int) $obj->rowid]
4084 'rowid' => (
int) $obj->rowid,
4085 'id' => (int) $obj->rowid,
4086 'fk_user' => (
int) $obj->fk_user,
4087 'fk_soc' => (int) $obj->fk_soc,
4088 'firstname' => (
string) $obj->firstname,
4089 'lastname' => (
string) $obj->lastname,
4090 'login' => (
string) $obj->login,
4091 'statut' => (int) $obj->statut,
4092 'entity' => (
int) $obj->entity,
4093 'email' => (
string) $obj->email,
4094 'gender' => (
string) $obj->gender,
4095 'admin' => (int) $obj->admin,
4096 'photo' => (
string) $obj->photo,
4110 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
4111 foreach ($this->users as $key => $val) {
4114 $this->
error =
'ErrorLoopInHierarchy';
4120 if ($deleteafterid) {
4122 $keyfilter1 =
'^'.$deleteafterid.
'$';
4123 $keyfilter2 =
'_'.$deleteafterid.
'$';
4124 $keyfilter3 =
'^'.$deleteafterid.
'_';
4125 $keyfilter4 =
'_'.$deleteafterid.
'_';
4126 foreach (array_keys($this->users) as $key) {
4127 $fullpath = (
string) $this->users[$key][
'fullpath'];
4128 if (preg_match(
'/'.$keyfilter1.
'/', $fullpath) || preg_match(
'/'.$keyfilter2.
'/', $fullpath)
4129 || preg_match(
'/'.$keyfilter3.
'/', $fullpath) || preg_match(
'/'.$keyfilter4.
'/', $fullpath)) {
4130 unset($this->users[$key]);
4135 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
4136 $this->users =
dol_sort_array($this->users,
'fullname',
'asc', 1, 0, 1);
4138 return $this->users;
4151 $childids = array();
4153 if (isset($this->cache_childids[$this->
id])) {
4154 $childids = $this->cache_childids[$this->id];
4159 $idtoscan = $this->id;
4161 dol_syslog(
"Build childid for id = ".$idtoscan);
4162 foreach ($this->users as $id => $val) {
4163 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
4164 $childids[$val[
'id']] = $val[
'id'];
4171 if ($treeresult < 0) {
4172 dol_syslog(get_class($this).
"::getAllChildIds got a truncated tree: ".$this->
error, LOG_WARNING);
4173 return $addcurrentuser ? array($this->
id => $this->
id) : $childids;
4176 $this->cache_childids[$this->id] = $childids;
4178 if ($addcurrentuser) {
4179 $childids[$this->id] = $this->id;
4199 if (!empty($this->users[$id_user][
'fullpath'])) {
4201 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
4206 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
4207 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
4209 $cursor_user = $id_user;
4211 $useridfound = array($id_user);
4212 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
4213 if (in_array($this->parentof[$cursor_user], $useridfound)) {
4214 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
4217 $useridfound[] = $this->parentof[$cursor_user];
4218 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
4219 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
4221 $cursor_user = $this->parentof[$cursor_user];
4225 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
4255 $this->nb = array();
4257 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
4258 $sql .=
" FROM ".$this->db->prefix().
"user as u";
4260 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
4261 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
4262 $sql .=
" AND ug.fk_user = u.rowid";
4264 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
4266 $sql .=
" AND u.statut > 0";
4269 $resql = $this->db->query($sql);
4271 while ($obj = $this->db->fetch_object($resql)) {
4272 $this->nb[
"users"] = $obj->nb;
4274 $this->db->free($resql);
4278 $this->
error = $this->db->error();
4294 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4298 $langs->load(
"user");
4305 $modele =
'bluesky';
4309 $modelpath =
"core/modules/user/doc/";
4311 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4325 $user_property =
'';
4327 if (empty($rowid)) {
4331 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
4332 $sql .=
" FROM ".$this->db->prefix().
"user";
4333 $sql .=
" WHERE rowid = ".((int) $rowid);
4335 $resql = $this->db->query($sql);
4337 $nump = $this->db->num_rows($resql);
4340 $obj = $this->db->fetch_object($resql);
4342 if ($mode ==
'email') {
4343 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
4344 } elseif ($mode ==
'mobile') {
4345 $user_property = $obj->user_mobile;
4346 } elseif ($mode ==
'name') {
4350 return $user_property;
4370 $instanceuniqueid = empty(
$conf->file->instance_unique_id) ?
'' :
$conf->file->instance_unique_id;
4371 $encodedsecurekey =
dol_hash($instanceuniqueid.
'uservirtualcard'.$this->id.
'-'.$this->login,
'md5');
4373 $entity_qr =
'&entity='.((int)
$conf->entity);
4378 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim(
$dolibarr_main_url_root));
4379 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
4382 if ($typeofurl ==
'internal') {
4383 $urlwithroot = DOL_URL_ROOT;
4386 return $urlwithroot.
'/public/users/view.php?id='.$this->
id.
'&securekey='.$encodedsecurekey.$entity_qr.($mode ?
'&mode='.urlencode($mode) :
'');
4402 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter =
'', $filtermode =
'AND', $entityfilter =
false)
4404 global $conf, $user;
4406 $sql =
"SELECT t.rowid";
4407 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
4409 if ($entityfilter) {
4411 if (!empty($user->admin) && empty($user->entity) &&
$conf->entity == 1) {
4412 $sql .=
" WHERE t.entity IS NOT NULL";
4414 $sql .=
" WHERE t.entity = 0 OR EXISTS (";
4415 $sql .=
" SELECT ug.rowid FROM " . $this->db->prefix() .
"usergroup_user as ug";
4416 $sql .=
" WHERE ug.fk_user = t.rowid AND ug.entity IN (" .
getEntity(
'usergroup') .
"))";
4419 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
4422 $sql .=
" WHERE 1 = 1";
4428 if ($errormessage) {
4429 $this->errors[] = $errormessage;
4430 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
4434 $sql .= $this->db->order($sortfield, $sortorder);
4436 $sql .= $this->db->plimit($limit + 1, $offset);
4441 $resql = $this->db->query($sql);
4443 $this->users = array();
4444 $num = $this->db->num_rows($resql);
4446 while ($obj = $this->db->fetch_object($resql)) {
4447 $line =
new self($this->db);
4448 $result = $line->fetch($obj->rowid);
4449 if ($result > 0 && !empty($line->id)) {
4450 $this->users[$obj->rowid] = clone $line;
4453 $this->db->free($resql);
4457 $this->errors[] = $this->db->lasterror();
4469 private $findUserIdByEmailCache;
4483 if (isset($this->findUserIdByEmailCache[$email])) {
4484 return $this->findUserIdByEmailCache[$email];
4487 $this->findUserIdByEmailCache[$email] = -1;
4489 $sql =
'SELECT rowid';
4490 $sql .=
' FROM '.$this->db->prefix().
'user';
4491 if (
getDolGlobalString(
'AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR')) {
4492 $sql .=
" WHERE email LIKE '%".$this->db->escape($this->db->escapeforlike($email)).
"%'";
4494 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
4498 $resql = $this->db->query($sql);
4503 $obj = $this->db->fetch_object($resql);
4508 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
4510 return $this->findUserIdByEmailCache[$email];
4521 if (empty($fromId) || empty($toId)) {
4528 $sqlDelete =
"DELETE FROM ".$this->db->prefix().
"user_rights";
4529 $sqlDelete .=
" WHERE fk_user = ".((int) $toId);
4531 dol_syslog(get_class($this).
"::clone_rights (delete default permissions)", LOG_DEBUG);
4533 if (!$this->db->query($sqlDelete)) {
4534 $this->db->rollback();
4539 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id)";
4540 $sql .=
" SELECT entity, ".((int) $toId).
", fk_id";
4541 $sql .=
" FROM ".$this->db->prefix().
"user_rights src";
4542 $sql .=
" WHERE fk_user = ".((int) $fromId);
4543 $sql .=
" AND NOT EXISTS (";
4544 $sql .=
" SELECT 1";
4545 $sql .=
" FROM ".$this->db->prefix().
"user_rights dest";
4546 $sql .=
" WHERE dest.entity = src.entity";
4547 $sql .=
" AND dest.fk_user = ".((int) $toId);
4548 $sql .=
" AND dest.fk_id = src.fk_id";
4551 dol_syslog(get_class($this).
"::clone_rights", LOG_DEBUG);
4554 if (!$this->db->query($sql)) {
4555 $this->db->rollback();
4559 $this->db->commit();
4576 $type = $this->table_element;
4579 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
4580 $categorystatic =
new Categorie($this->db);
4582 $sql =
"INSERT INTO ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]).
" (fk_categorie, fk_user)";
4583 $sql .=
" SELECT fk_categorie, ".((int) $toId).
" FROM ".$this->db->prefix().
"categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]);
4584 $sql .=
" WHERE fk_user = ".((int) $fromId);
4586 if (!$this->db->query($sql)) {
4587 $this->
error = $this->db->lasterror();
4588 $this->db->rollback();
4592 $this->db->commit();
global $dolibarr_main_url_root
Class to manage members of a foundation.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage categories.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Class to manage Dolibarr database access.
Class to manage warehouses.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage user groups.
Class to manage Dolibarr users.
fetch($id=0, $login='', $sid='', $loadpersonalconf=0, $entity=-1, $email='', $fk_socpeople=0, $use_email_oauth2=0)
Load a user from database with its id or ref (login).
SetInGroup($group, $entity, $notrigger=0)
Add user into a group.
LibStatut($status, $mode=0)
Return the label of a status of user (active, inactive)
loadRights($moduletag='', $forcereload=0)
Load permissions granted to a user->id into object user->rights.
get_children()
Return and array with all instantiated first level children users of current user.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
loadStateBoard()
Load metrics this->nb for dashboard.
hasRight($module, $permlevel1, $permlevel2='')
Return if a user has a permission.
info($id)
Load info of user object.
create_from_contact($contact, $login='', $password='')
Create a user from a contact object.
setstatus($status)
Change status of a user.
get_full_tree($deleteafterid=0, $filter='')
Build the hierarchy/tree of users into an array.
_load_ldap_info()
Initialize the info array (array of LDAP values) that will be used to call LDAP functions.
delrights($rid, $allmodule='', $allperms='', $entity=0, $notrigger=0)
Remove a right to the user.
update_last_login_date()
Update the user's last login date in the database.
__construct($db)
Constructor of the class.
RemoveFromGroup($group, $entity, $notrigger=0)
Remove a user from a group.
isNotIntoValidityDateRange()
Return a link with photo Use this->id,this->photo.
getNbOfUsers($limitTo, $option='', $admin=-1)
Return number of existing users.
set_default_rights()
Assign rights by default.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND', $entityfilter=false)
Load all objects into $this->users.
getOnlineVirtualCardUrl($mode='', $typeofurl='external')
Return string with full Url to virtual card.
update($user, $notrigger=0, $nosyncmember=0, $nosyncmemberpass=0, $nosynccontact=0)
Update a user into database (and also password if this->pass is defined)
getLoginUrl($withpictoimg=0, $option='', $notooltip=0, $morecss='')
Return clickable link of login (optionally with picto)
setCategories($categories)
Sets object to supplied categories.
loadParentOf()
Load this->parentof that is array(id_son=>id_parent, ...)
setForcePasswordChange($user, $value)
Set force password change flag.
fetch_clicktodial()
Read clicktodial information for user.
build_path_from_id_user($id_user, $protection=0)
For user id_user and its children available in this->users, define property fullpath and fullname.
error()
Returns the last functional error when manipulating the object.
cloneCategories($fromId, $toId, $type='user')
Copy related categories to another object.
getAllChildIds($addcurrentuser=0)
Return list of all child user ids in hierarchy (all sublevels).
initAsSpecimen()
Initialise an instance with random values.
setPassword($user, $password='', $changelater=0, $notrigger=0, $nosyncmember=0, $passwordalreadycrypted=0, $flagdelsessionsbefore=1)
Change password of a user.
getNomUrl($withpictoimg=0, $option='', $infologin=0, $notooltip=0, $maxlen=24, $hidethirdpartylogo=0, $mode='', $morecss='', $save_lastsearch_value=-1)
Return a HTML link to the user card (with optionally the picto) Use this->id,this->lastname,...
clearrights()
Clear all permissions array of user.
update_clicktodial()
Update clicktodial info.
cloneRights($fromId, $toId)
Clone permissions of user.
isExternalUser()
Return if a user is an external user It replaces old syntax: if ($user->socid)
getLibStatut($mode=0)
Return the label of the status of user (active, inactive)
create_from_member($member, $login='')
Create a user into database from a member object.
_load_ldap_dn($info, $mode=0)
Returns the complete DN (Distinguished Name) string in the LDAP directory for the object.
loadDefaultValues()
Load default values from database table into property ->default_values.
getPhotoUrl($width, $height, $cssclass='', $imagesize='')
Return a link with photo Use this->id,this->photo.
isAdmin()
Return if a user is an admin user It replaces old syntax: if ($user->admin)
update_ldap2dolibarr(&$ldapuser)
Update user using data from the LDAP.
getrights($moduletag='', $forcereload=0)
Load permissions granted to a user->id into object user->rights TODO Remove this method.
user_get_property($rowid, $mode)
Return property of user from its id.
send_password($user, $password='', $changelater=0)
Send a new password (or instructions to reset it) by email.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (optionally with picto)
getNbOfEMailings()
Return number of mass Emailing received by this contacts with its email.
addrights($rid, $allmodule='', $allperms='', $entity=0, $notrigger=0)
Add a right to the user.
create($user, $notrigger=0)
Create a user into database.
loadPersonalConf($entity=-1)
Load const values from database table user_param and set it into user->conf->XXX.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
findUserIdByEmail($email)
Find a user by the given e-mail and return it's user id when found.
getTooltipContentArray($params)
getTooltipContentArray
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as p label as s rowid as s nom as s email
Sender: Who sends the email ("Sender" has sent emails on behalf of "From").
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
dol_now($mode='gmt')
Return date for now.
getDolGlobalLoginBadCharUnauthorized()
Return the list of unauthorized characters in user logins.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
dol_print_phone($phone, $countrycode='', $contactid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0, $morecss='paddingright')
Format phone numbers according to country.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
div refaddress div address
conf($dolibarr_main_document_root, $realpathconf=null)
Load conf file (file must exists)
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dolGetLdapPasswordHash($password, $type='md5')
Returns a specific ldap hash of a password.
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.
dolDecrypt($chain, $key='', $patterntotest='')
Decode a string with a symmetric encryption.
dol_verifyHash($chain, $hash, $type='0')
Compute a hash and compare it to the given one For backward compatibility reasons,...
dolEncrypt($chain, $key='', $ciphering='', $forceseed='', $obfuscationmode='dolcrypt')
Encode a string with a symmetric encryption.