38 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
49 public $element =
'user';
54 public $table_element =
'user';
59 public $fk_element =
'fk_user';
65 public $ismultientitymanaged = 1;
70 public $picto =
'user';
77 public $civility_code;
94 public $personal_email;
99 public $socialnetworks;
156 public $office_phone;
171 public $personal_mobile;
201 public $pass_indatabase;
206 public $pass_indatabase_crypted;
250 public $fk_user_expense_validator;
255 public $fk_user_holiday_validator;
265 public $clicktodial_login;
270 public $clicktodial_password;
275 public $clicktodial_poste;
277 public $datelastlogin;
278 public $datepreviouslogin;
280 public $ippreviouslogin;
281 public $datestartvalidity;
282 public $dateendvalidity;
298 public $all_permissions_are_loaded;
308 public $user_group_list;
313 private $_tab_loaded = array();
320 public $default_values;
322 public $lastsearch_values_tmp;
323 public $lastsearch_values;
325 public $users = array();
327 private $cache_childids;
329 public $accountancy_code;
343 public $dateemployment;
344 public $dateemploymentend;
346 public $default_c_exp_tax_cat;
351 public $ref_employee;
356 public $national_registration_number;
358 public $default_range;
363 public $fk_warehouse;
366 public $fields = array(
367 'rowid'=>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'index'=>1,
'position'=>1,
'comment'=>
'Id'),
368 'lastname'=>array(
'type'=>
'varchar(50)',
'label'=>
'LastName',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>20,
'searchall'=>1),
369 'firstname'=>array(
'type'=>
'varchar(50)',
'label'=>
'FirstName',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>10,
'searchall'=>1),
370 'ref_employee'=>array(
'type'=>
'varchar(50)',
'label'=>
'RefEmployee',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>30,
'searchall'=>1),
371 'national_registration_number'=>array(
'type'=>
'varchar(50)',
'label'=>
'NationalRegistrationNumber',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>40,
'searchall'=>1)
375 const STATUS_DISABLED = 0;
376 const STATUS_ENABLED = 1;
390 $this->liste_limit = 0;
391 $this->clicktodial_loaded = 0;
394 $this->all_permissions_are_loaded = 0;
395 $this->nb_rights = 0;
401 $this->
conf =
new stdClass();
402 $this->rights =
new stdClass();
403 $this->rights->user =
new stdClass();
404 $this->rights->user->user =
new stdClass();
405 $this->rights->user->self =
new stdClass();
406 $this->rights->user->user_advance =
new stdClass();
407 $this->rights->user->self_advance =
new stdClass();
408 $this->rights->user->group_advance =
new stdClass();
424 public function fetch($id =
'', $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'', $fk_socpeople = 0)
429 $login = trim($login);
432 $sql =
"SELECT u.rowid, u.lastname, u.firstname, u.employee, u.gender, u.civility as civility_code, u.birth, u.email, u.personal_email, u.job,";
433 $sql .=
" u.socialnetworks,";
434 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
435 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
436 $sql .=
" u.admin, u.login, u.note_private, u.note_public,";
437 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.api_key,";
438 $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,";
439 $sql .=
" u.statut as status, u.lang, u.entity,";
440 $sql .=
" u.datec as datec,";
441 $sql .=
" u.tms as datem,";
442 $sql .=
" u.datelastlogin as datel,";
443 $sql .=
" u.datepreviouslogin as datep,";
444 $sql .=
" u.iplastlogin,";
445 $sql .=
" u.ippreviouslogin,";
446 $sql .=
" u.datelastpassvalidation,";
447 $sql .=
" u.datestartvalidity,";
448 $sql .=
" u.dateendvalidity,";
449 $sql .=
" u.photo as photo,";
450 $sql .=
" u.openid as openid,";
451 $sql .=
" u.accountancy_code,";
454 $sql .=
" u.salary,";
455 $sql .=
" u.salaryextra,";
456 $sql .=
" u.weeklyhours,";
458 $sql .=
" u.dateemployment, u.dateemploymentend,";
459 $sql .=
" u.fk_warehouse,";
460 $sql .=
" u.ref_ext,";
461 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
462 $sql .=
" u.national_registration_number,";
463 $sql .=
" u.ref_employee,";
464 $sql .=
" c.code as country_code, c.label as country,";
465 $sql .=
" d.code_departement as state_code, d.nom as state";
466 $sql .=
" FROM ".$this->db->prefix().
"user as u";
467 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_country as c ON u.fk_country = c.rowid";
468 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_departements as d ON u.fk_state = d.rowid";
471 if ((!
isModEnabled(
'multicompany') || empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) && (!empty($user->entity))) {
472 $sql .=
" WHERE u.entity IN (0, ".((int) $conf->entity).
")";
474 $sql .=
" WHERE u.entity IS NOT NULL";
478 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
479 $sql .=
" WHERE u.entity IS NOT NULL";
481 $sql .=
" WHERE u.entity IN (0, ".((int) (($entity !=
'' && $entity >= 0) ? $entity : $conf->entity)).
")";
487 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->
db->escape($login).
"')";
489 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
491 $sql .=
" AND u.email = '".$this->db->escape($email).
"'";
492 } elseif ($fk_socpeople > 0) {
493 $sql .=
" AND u.fk_socpeople = ".((int) $fk_socpeople);
495 $sql .=
" AND u.rowid = ".((int) $id);
497 $sql .=
" ORDER BY u.entity ASC";
501 $sql .=
' '.$this->db->plimit(1);
504 $result = $this->
db->query($sql);
506 $obj = $this->
db->fetch_object($result);
508 $this->
id = $obj->rowid;
509 $this->
ref = $obj->rowid;
511 $this->ref_ext = $obj->ref_ext;
513 $this->ldap_sid = $obj->ldap_sid;
514 $this->civility_code = $obj->civility_code;
515 $this->lastname = $obj->lastname;
516 $this->firstname = $obj->firstname;
517 $this->ref_employee = $obj->ref_employee;
518 $this->national_registration_number = $obj->national_registration_number;
520 $this->employee = $obj->employee;
522 $this->login = $obj->login;
523 $this->gender = $obj->gender;
524 $this->birth = $this->
db->jdate($obj->birth);
525 $this->pass_indatabase = $obj->pass;
526 $this->pass_indatabase_crypted = $obj->pass_crypted;
527 $this->pass = $obj->pass;
528 $this->pass_temp = $obj->pass_temp;
529 $this->api_key = $obj->api_key;
531 $this->address = $obj->address;
532 $this->zip = $obj->zip;
533 $this->town = $obj->town;
535 $this->country_id = $obj->country_id;
536 $this->country_code = $obj->country_id ? $obj->country_code :
'';
539 $this->state_id = $obj->state_id;
540 $this->state_code = $obj->state_code;
541 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
543 $this->office_phone = $obj->office_phone;
544 $this->office_fax = $obj->office_fax;
545 $this->user_mobile = $obj->user_mobile;
546 $this->personal_mobile = $obj->personal_mobile;
547 $this->email = $obj->email;
548 $this->personal_email = $obj->personal_email;
549 $this->socialnetworks = ($obj->socialnetworks ? (array) json_decode($obj->socialnetworks,
true) : array());
550 $this->job = $obj->job;
551 $this->signature = $obj->signature;
552 $this->admin = $obj->admin;
553 $this->note_public = $obj->note_public;
554 $this->note_private = $obj->note_private;
555 $this->note = $obj->note_private;
557 $this->statut = $obj->status;
558 $this->status = $obj->status;
560 $this->photo = $obj->photo;
561 $this->openid = $obj->openid;
562 $this->lang = $obj->lang;
563 $this->entity = $obj->entity;
564 $this->accountancy_code = $obj->accountancy_code;
565 $this->thm = $obj->thm;
566 $this->tjm = $obj->tjm;
567 $this->salary = $obj->salary;
568 $this->salaryextra = $obj->salaryextra;
569 $this->weeklyhours = $obj->weeklyhours;
570 $this->color = $obj->color;
571 $this->dateemployment = $this->
db->jdate($obj->dateemployment);
572 $this->dateemploymentend = $this->
db->jdate($obj->dateemploymentend);
574 $this->datec = $this->
db->jdate($obj->datec);
575 $this->datem = $this->
db->jdate($obj->datem);
576 $this->datelastlogin = $this->
db->jdate($obj->datel);
577 $this->datepreviouslogin = $this->
db->jdate($obj->datep);
578 $this->iplastlogin = $obj->iplastlogin;
579 $this->ippreviouslogin = $obj->ippreviouslogin;
580 $this->datestartvalidity = $this->
db->jdate($obj->datestartvalidity);
581 $this->dateendvalidity = $this->
db->jdate($obj->dateendvalidity);
583 $this->socid = $obj->fk_soc;
584 $this->contact_id = $obj->fk_socpeople;
585 $this->fk_member = $obj->fk_member;
586 $this->fk_user = $obj->fk_user;
587 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
588 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
590 $this->default_range = $obj->default_range;
591 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
592 $this->fk_warehouse = $obj->fk_warehouse;
596 if (!
isModEnabled(
'multicompany') && $this->admin && $this->entity == 1) {
604 $this->
db->free($result);
606 $this->
error =
"USERNOTFOUND";
607 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
609 $this->
db->free($result);
613 $this->
error = $this->
db->lasterror();
618 if ($loadpersonalconf) {
620 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
621 $sql .=
" WHERE fk_user = ".((int) $this->
id);
622 $sql .=
" AND entity = ".((int) $conf->entity);
629 $obj = $this->
db->fetch_object(
$resql);
630 $p = (!empty($obj->param) ? $obj->param :
'');
632 $this->
conf->$p = $obj->value;
638 $this->
error = $this->
db->lasterror();
645 $this->
error = $this->
db->lasterror();
661 if (!empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) {
663 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
666 $result = $defaultValues->fetchAll(
'',
'', 0, 0, array(
't.user_id'=>array(0, $this->
id),
'entity'=>array((isset($this->entity) ? $this->entity : $conf->entity), $conf->entity)));
668 if (!is_array($result) && $result < 0) {
672 } elseif (count($result) > 0) {
673 foreach ($result as $defval) {
674 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
675 $pagewithoutquerystring = $defval->page;
678 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
679 $pagewithoutquerystring = $reg[1];
680 $pagequeries = $reg[2];
682 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
686 if (!empty($this->default_values)) {
687 foreach ($this->default_values as $a => $b) {
688 foreach ($b as $c => $d) {
689 krsort($this->default_values[$a][$c]);
708 public function hasRight($module, $permlevel1, $permlevel2 =
'')
712 $moduletomoduletouse = array(
713 'contract' =>
'contrat',
714 'member' =>
'adherent',
716 'order' =>
'commande',
717 'produit' =>
'product',
718 'project' =>
'projet',
719 'propale' =>
'propal',
720 'shipping' =>
'expedition',
721 'task' =>
'task@projet',
722 'fichinter' =>
'ficheinter',
723 'inventory' =>
'stock',
724 'invoice' =>
'facture',
725 'invoice_supplier' =>
'fournisseur',
726 'order_supplier' =>
'fournisseur',
727 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
728 'skill@hrm' =>
'all@hrm',
729 'job@hrm' =>
'all@hrm',
730 'position@hrm' =>
'all@hrm',
731 'facturerec' =>
'facture'
734 if (!empty($moduletomoduletouse[$module])) {
735 $module = $moduletomoduletouse[$module];
738 $moduleRightsMapping = array(
739 'product' =>
'produit',
740 'margin' =>
'margins'
743 $rightsPath = $module;
744 if (!empty($moduleRightsMapping[$rightsPath])) {
745 $rightsPath = $moduleRightsMapping[$rightsPath];
749 $tmp = explode(
'@', $rightsPath, 2);
750 if (!empty($tmp[1])) {
751 if (strpos($module,
'@') !==
false) {
754 $rightsPath = $tmp[1];
755 $permlevel2 = $permlevel1;
756 $permlevel1 = $tmp[0];
769 if ($permlevel1 ==
'propale') {
770 $permlevel1 =
'propal';
772 if ($permlevel1 ==
'member') {
773 $permlevel1 =
'adherent';
775 if ($permlevel1 ==
'recruitmentcandidature') {
776 $permlevel1 =
'recruitmentjobposition';
780 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
785 if (!empty($this->rights->$rightsPath->$permlevel1)) {
786 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
787 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
791 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
792 return $this->rights->$rightsPath->$permlevel1->lire;
794 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
795 return $this->rights->$rightsPath->$permlevel1->creer;
797 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
798 return $this->rights->$rightsPath->$permlevel1->create;
800 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
801 return $this->rights->$rightsPath->$permlevel1->supprimer;
805 if (!empty($this->rights->$rightsPath->$permlevel1)) {
806 return $this->rights->$rightsPath->$permlevel1;
810 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
811 return $this->rights->$rightsPath->lire;
813 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
814 return $this->rights->$rightsPath->creer;
816 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
817 return $this->rights->$rightsPath->create;
819 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
820 return $this->rights->$rightsPath->supprimer;
838 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
840 global $conf, $user, $langs;
842 $entity = (empty($entity) ? $conf->entity : $entity);
844 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
852 $module = $perms = $subperms =
'';
855 $sql =
"SELECT module, perms, subperms";
856 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
857 $sql .=
" WHERE id = ".((int) $rid);
858 $sql .=
" AND entity = ".((int) $entity);
860 $result = $this->
db->query($sql);
862 $obj = $this->
db->fetch_object($result);
865 $module = $obj->module;
866 $perms = $obj->perms;
867 $subperms = $obj->subperms;
875 $whereforadd =
"id=".((int) $rid);
877 if (!empty($subperms)) {
878 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->
db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
879 } elseif (!empty($perms)) {
880 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
886 if (!empty($allmodule)) {
887 if ($allmodule ==
'allmodules') {
888 $whereforadd =
'allmodules';
890 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
891 if (!empty($allperms)) {
892 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
899 if (!empty($whereforadd)) {
902 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
903 $sql .=
" WHERE entity = ".((int) $entity);
904 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
905 $sql .=
" AND (".$whereforadd.
")";
908 $result = $this->
db->query($sql);
910 $num = $this->
db->num_rows($result);
913 $obj = $this->
db->fetch_object($result);
918 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id).
" AND fk_id = ".((int) $nid).
" AND entity = ".((int) $entity);
919 if (!$this->
db->query($sql)) {
922 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
923 if (!$this->
db->query($sql)) {
936 if (!$error && !$notrigger) {
937 $langs->load(
"other");
938 $this->context = array(
'audit'=>$langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
949 $this->
db->rollback();
969 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
971 global $conf, $user, $langs;
975 $entity = (!empty($entity) ? $entity : $conf->entity);
980 $module = $perms = $subperms =
'';
984 $sql =
"SELECT module, perms, subperms";
985 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
986 $sql .=
" WHERE id = '".$this->db->escape($rid).
"'";
987 $sql .=
" AND entity = ".((int) $entity);
989 $result = $this->
db->query($sql);
991 $obj = $this->
db->fetch_object($result);
994 $module = $obj->module;
995 $perms = $obj->perms;
996 $subperms = $obj->subperms;
1004 $wherefordel =
"id=".((int) $rid);
1006 if ($subperms ==
'lire' || $subperms ==
'read') {
1007 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->
db->escape($perms).
"' AND subperms IS NOT NULL)";
1009 if ($perms ==
'lire' || $perms ==
'read') {
1010 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1015 if (!empty($allmodule)) {
1016 if ($allmodule ==
'allmodules') {
1017 $wherefordel =
'allmodules';
1019 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1020 if (!empty($allperms)) {
1021 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1028 if (!empty($wherefordel)) {
1031 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1032 $sql .=
" WHERE entity = ".((int) $entity);
1033 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1034 $sql .=
" AND (".$wherefordel.
")";
1038 if ($this->admin == 1) {
1039 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1040 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1041 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1042 $sql .=
" AND id NOT IN (358)";
1045 $result = $this->
db->query($sql);
1047 $num = $this->
db->num_rows($result);
1050 $obj = $this->
db->fetch_object($result);
1053 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1054 $sql .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id = ".((int) $nid);
1055 $sql .=
" AND entity = ".((int) $entity);
1056 if (!$this->
db->query($sql)) {
1068 if (!$error && !$notrigger) {
1069 $langs->load(
"other");
1070 $this->context = array(
'audit'=>$langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1081 $this->
db->rollback();
1084 $this->
db->commit();
1098 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1099 $this->rights =
null;
1100 $this->nb_rights = 0;
1101 $this->all_permissions_are_loaded = 0;
1102 $this->_tab_loaded = array();
1114 public function getrights($moduletag =
'', $forcereload = 0)
1118 if (empty($forcereload)) {
1119 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1124 if (!empty($this->all_permissions_are_loaded)) {
1131 if (!isset($this->rights) || !is_object($this->rights)) {
1132 $this->rights =
new stdClass();
1134 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1135 $this->rights->user =
new stdClass();
1141 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1142 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1143 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1144 $sql .=
" WHERE r.id = ur.fk_id";
1145 if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
1147 $sql .=
" AND r.entity IN (0,".(isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ?
"1," :
"").$conf->entity.
")";
1151 $sql .=
" AND r.entity = ".((int) $conf->entity).
" AND ur.entity = ".((int) $conf->entity);
1153 $sql .=
" AND ur.fk_user= ".((int) $this->
id);
1154 $sql .=
" AND r.perms IS NOT NULL";
1156 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1161 $num = $this->
db->num_rows(
$resql);
1164 $obj = $this->
db->fetch_object(
$resql);
1167 $module = $obj->module;
1168 $perms = $obj->perms;
1169 $subperms = $obj->subperms;
1171 if (!empty($perms)) {
1172 if (!empty($module)) {
1173 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1174 $this->rights->$module =
new stdClass();
1176 if (!empty($subperms)) {
1177 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1178 $this->rights->$module->$perms =
new stdClass();
1180 if (empty($this->rights->$module->$perms->$subperms)) {
1183 $this->rights->$module->$perms->$subperms = 1;
1185 if (empty($this->rights->$module->$perms)) {
1188 $this->rights->$module->$perms = 1;
1199 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1200 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1201 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1202 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1203 $sql .=
" WHERE r.id = gr.fk_id";
1204 if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
1205 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1206 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1208 $sql .=
" AND r.entity = ".((int) $conf->entity);
1211 $sql .=
" AND gr.entity = ".((int) $conf->entity);
1215 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1216 $sql .=
" AND r.entity = ".((int) $conf->entity);
1218 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1219 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1220 $sql .=
" AND r.perms IS NOT NULL";
1222 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1227 $num = $this->
db->num_rows(
$resql);
1230 $obj = $this->
db->fetch_object(
$resql);
1233 $module = $obj->module;
1234 $perms = $obj->perms;
1235 $subperms = $obj->subperms;
1237 if (!empty($perms)) {
1238 if (!empty($module)) {
1239 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1240 $this->rights->$module =
new stdClass();
1242 if (!empty($subperms)) {
1243 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1244 $this->rights->$module->$perms =
new stdClass();
1246 if (empty($this->rights->$module->$perms->$subperms)) {
1249 $this->rights->$module->$perms->$subperms = 1;
1251 if (empty($this->rights->$module->$perms)) {
1255 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1256 $this->rights->$module->$perms = 1;
1268 if (!empty($this->admin)) {
1269 if (empty($this->rights->user->user)) {
1270 $this->rights->user->user =
new stdClass();
1272 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1273 foreach ($listofpermtotest as $permtotest) {
1274 if (empty($this->rights->user->user->$permtotest)) {
1275 $this->rights->user->user->$permtotest = 1;
1279 if (empty($this->rights->user->self)) {
1280 $this->rights->user->self =
new stdClass();
1282 $listofpermtotest = array(
'creer',
'password');
1283 foreach ($listofpermtotest as $permtotest) {
1284 if (empty($this->rights->user->self->$permtotest)) {
1285 $this->rights->user->self->$permtotest = 1;
1290 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
1291 if (empty($this->rights->user->user_advance)) {
1292 $this->rights->user->user_advance =
new stdClass();
1294 $listofpermtotest = array(
'readperms',
'write');
1295 foreach ($listofpermtotest as $permtotest) {
1296 if (empty($this->rights->user->user_advance->$permtotest)) {
1297 $this->rights->user->user_advance->$permtotest = 1;
1301 if (empty($this->rights->user->self_advance)) {
1302 $this->rights->user->self_advance =
new stdClass();
1304 $listofpermtotest = array(
'readperms',
'writeperms');
1305 foreach ($listofpermtotest as $permtotest) {
1306 if (empty($this->rights->user->self_advance->$permtotest)) {
1307 $this->rights->user->self_advance->$permtotest = 1;
1311 if (empty($this->rights->user->group_advance)) {
1312 $this->rights->user->group_advance =
new stdClass();
1314 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1315 foreach ($listofpermtotest as $permtotest) {
1316 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1317 $this->rights->user->group_advance->$permtotest = 1;
1325 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1326 $this->rights->propal = $this->rights->propale;
1328 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1329 $this->rights->propale = $this->rights->propal;
1335 $this->all_permissions_are_loaded = 1;
1338 $this->_tab_loaded[$moduletag] = 1;
1350 global $conf, $langs, $user;
1355 if (isset($this->statut)) {
1356 if ($this->statut == $status) {
1359 } elseif (isset($this->status) && $this->status == $status) {
1366 $sql =
"UPDATE ".$this->db->prefix().
"user";
1367 $sql .=
" SET statut = ".((int) $status);
1368 $sql .=
" WHERE rowid = ".((int) $this->
id);
1369 $result = $this->
db->query($sql);
1371 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1374 $result = $this->
call_trigger(
'USER_ENABLEDISABLE', $user);
1382 $this->
db->rollback();
1385 $this->status = $status;
1386 $this->statut = $status;
1387 $this->
db->commit();
1404 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1405 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1416 global $conf, $langs;
1422 $this->
fetch($this->
id);
1424 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1427 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1429 if (!$error && !$this->
db->query($sql)) {
1431 $this->
error = $this->
db->lasterror();
1435 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1436 if (!$error && !$this->
db->query($sql)) {
1438 $this->
error = $this->
db->lasterror();
1442 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1443 if (!$error && !$this->
db->query($sql)) {
1445 $this->
error = $this->
db->lasterror();
1449 if ($this->contact_id > 0) {
1450 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1451 if (!$error && !$this->
db->query($sql)) {
1453 $this->
error = $this->
db->lasterror();
1462 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1468 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1469 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1470 if (!$this->
db->query($sql)) {
1472 $this->
error = $this->
db->lasterror();
1481 $this->
db->rollback();
1486 $this->
db->commit();
1489 $this->
db->rollback();
1501 public function create($user, $notrigger = 0)
1503 global $conf, $langs;
1509 $this->civility_code = trim((
string) $this->civility_code);
1510 $this->login = trim((
string) $this->login);
1511 if (!isset($this->entity)) {
1512 $this->entity = $conf->entity;
1515 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1517 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1520 if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1521 $langs->load(
"errors");
1522 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1525 if (empty($this->login)) {
1526 $langs->load(
"errors");
1527 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1529 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1530 $langs->load(
"errors");
1531 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1542 $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).
"'";
1543 $resqltochecklogin = $this->
db->query($sqltochecklogin);
1544 if ($resqltochecklogin) {
1545 $objtochecklogin = $this->
db->fetch_object($resqltochecklogin);
1546 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1547 $langs->load(
"errors");
1548 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1550 $this->
db->rollback();
1553 $this->
db->free($resqltochecklogin);
1556 if (!empty($this->email)) {
1557 $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).
"'";
1558 $resqltochecklogin = $this->
db->query($sqltochecklogin);
1559 if ($resqltochecklogin) {
1560 $objtochecklogin = $this->
db->fetch_object($resqltochecklogin);
1561 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1562 $langs->load(
"errors");
1563 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
1565 $this->
db->rollback();
1568 $this->
db->free($resqltochecklogin);
1573 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, entity)";
1574 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->
db->escape($this->login).
"', '".$this->
db->escape($this->ldap_sid).
"', ".((int) $this->entity).
")";
1575 $result = $this->
db->query($sql);
1577 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1579 $this->
id = $this->
db->last_insert_id($this->
db->prefix().
"user");
1583 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1584 $this->
db->rollback();
1588 if (!empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER) && !empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) {
1589 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1590 $langs->load(
"stocks");
1592 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1593 $entrepot->libelle = $entrepot->label;
1594 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1595 $entrepot->statut = 1;
1596 $entrepot->country_id = $mysoc->country_id;
1597 $warehouseid = $entrepot->create($user);
1599 $this->fk_warehouse = $warehouseid;
1603 $result = $this->
update($user, 1, 1);
1605 $this->
db->rollback();
1619 $this->
db->commit();
1624 $this->
db->rollback();
1628 $this->
error = $this->
db->lasterror();
1629 $this->
db->rollback();
1647 global $conf, $user, $langs;
1653 $this->civility_code = $contact->civility_code;
1654 $this->lastname = $contact->lastname;
1655 $this->firstname = $contact->firstname;
1656 $this->gender = $contact->gender;
1657 $this->email = $contact->email;
1658 $this->socialnetworks = $contact->socialnetworks;
1659 $this->office_phone = $contact->phone_pro;
1660 $this->office_fax = $contact->fax;
1661 $this->user_mobile = $contact->phone_mobile;
1662 $this->address = $contact->address;
1663 $this->zip = $contact->zip;
1664 $this->town = $contact->town;
1666 $this->state_id = $contact->state_id;
1667 $this->country_id = $contact->country_id;
1668 $this->employee = 0;
1670 if (empty($login)) {
1671 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1672 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1674 $this->login = $login;
1679 $result = $this->
create($user, 1);
1681 $sql =
"UPDATE ".$this->db->prefix().
"user";
1682 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1683 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1684 if ($contact->socid > 0) {
1685 $sql .=
", fk_soc=".((int) $contact->socid);
1687 $sql .=
" WHERE rowid=".((int) $this->
id);
1691 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1693 $this->context[
'createfromcontact'] =
'createfromcontact';
1698 $error++; $this->
db->rollback();
return -1;
1702 $this->
db->commit();
1705 $this->
error = $this->
db->error();
1707 $this->
db->rollback();
1712 dol_syslog(get_class($this).
"::create_from_contact - 0");
1714 $this->
db->rollback();
1731 global $conf, $user, $langs;
1735 $this->civility_code = $member->civility_id;
1736 $this->lastname = $member->lastname;
1737 $this->firstname = $member->firstname;
1738 $this->gender = $member->gender;
1739 $this->email = $member->email;
1740 $this->fk_member = $member->id;
1741 $this->address = $member->address;
1742 $this->zip = $member->zip;
1743 $this->town = $member->town;
1745 $this->state_id = $member->state_id;
1746 $this->country_id = $member->country_id;
1747 $this->socialnetworks = $member->socialnetworks;
1749 $this->pass = $member->pass;
1750 $this->pass_crypted = $member->pass_indatabase_crypted;
1752 if (empty($login)) {
1753 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1756 $this->login = $login;
1761 $result = $this->
create($user);
1763 if (!empty($this->pass)) {
1764 $newpass = $this->
setPassword($user, $this->pass);
1765 if (is_numeric($newpass) && $newpass < 0) {
1768 } elseif (!empty($this->pass_crypted)) {
1769 $sql =
"UPDATE ".$this->db->prefix().
"user";
1770 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
1771 $sql .=
" WHERE rowid=".((int) $this->
id);
1779 if ($result > 0 && $member->fk_soc) {
1780 $sql =
"UPDATE ".$this->db->prefix().
"user";
1781 $sql .=
" SET fk_soc=".((int) $member->fk_soc);
1782 $sql .=
" WHERE rowid=".((int) $this->
id);
1784 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
1787 $this->
db->commit();
1790 $this->
error = $this->
db->lasterror();
1792 $this->
db->rollback();
1799 $this->
db->commit();
1803 $this->
db->rollback();
1821 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
1822 $sql .=
" WHERE bydefault = 1";
1823 $sql .=
" AND entity = ".((int) $conf->entity);
1827 $num = $this->
db->num_rows(
$resql);
1830 $row = $this->
db->fetch_row(
$resql);
1838 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
1839 $result = $this->
db->query($sql);
1841 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
1842 $result = $this->
db->query($sql);
1862 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
1864 global $conf, $langs;
1866 $nbrowsaffected = 0;
1869 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
1872 $this->civility_code = trim((
string) $this->civility_code);
1873 $this->lastname = trim((
string) $this->lastname);
1874 $this->firstname = trim((
string) $this->firstname);
1875 $this->ref_employee = trim((
string) $this->ref_employee);
1876 $this->national_registration_number = trim((
string) $this->national_registration_number);
1877 $this->employee = ($this->employee > 0 ? $this->employee : 0);
1878 $this->login = trim((
string) $this->login);
1879 $this->gender = trim((
string) $this->gender);
1880 $this->pass = trim((
string) $this->pass);
1881 $this->api_key = trim((
string) $this->api_key);
1882 $this->address = trim((
string) $this->address);
1883 $this->zip = trim((
string) $this->zip);
1884 $this->town = trim((
string) $this->town);
1886 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
1887 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
1888 $this->office_phone = trim((
string) $this->office_phone);
1889 $this->office_fax = trim((
string) $this->office_fax);
1890 $this->user_mobile = trim((
string) $this->user_mobile);
1891 $this->personal_mobile = trim((
string) $this->personal_mobile);
1892 $this->email = trim((
string) $this->email);
1893 $this->personal_email = trim((
string) $this->personal_email);
1895 $this->job = trim((
string) $this->job);
1896 $this->signature = trim((
string) $this->signature);
1897 $this->note_public = trim((
string) $this->note_public);
1898 $this->note_private = trim((
string) $this->note_private);
1899 $this->openid = trim((
string) $this->openid);
1900 $this->admin = ($this->admin > 0 ? $this->admin : 0);
1902 $this->accountancy_code = trim((
string) $this->accountancy_code);
1903 $this->color = trim((
string) $this->color);
1904 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
1905 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
1906 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
1907 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
1908 $this->birth = empty($this->birth) ?
'' : $this->birth;
1909 $this->fk_warehouse = (int) $this->fk_warehouse;
1914 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1916 if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1917 $langs->load(
"errors");
1918 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1921 if (empty($this->login)) {
1922 $langs->load(
"errors");
1923 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
1925 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1926 $langs->load(
"errors");
1927 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName", $langs->transnoentitiesnoconv(
"Login"));
1934 if (!empty($this->oldcopy) && $this->oldcopy->login != $this->login) {
1935 $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).
"'";
1936 $resqltochecklogin = $this->
db->query($sqltochecklogin);
1937 if ($resqltochecklogin) {
1938 $objtochecklogin = $this->
db->fetch_object($resqltochecklogin);
1939 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1940 $langs->load(
"errors");
1941 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1943 $this->
db->rollback();
1948 if (!empty($this->oldcopy) && !empty($this->email) && $this->oldcopy->email != $this->email) {
1949 $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).
"'";
1950 $resqltochecklogin = $this->
db->query($sqltochecklogin);
1951 if ($resqltochecklogin) {
1952 $objtochecklogin = $this->
db->fetch_object($resqltochecklogin);
1953 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1954 $langs->load(
"errors");
1955 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
1957 $this->
db->rollback();
1964 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
1965 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
1966 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
1967 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
1968 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
1969 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
1970 $sql .=
", employee = ".(int) $this->employee;
1971 $sql .=
", login = '".$this->db->escape($this->login).
"'";
1972 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape($this->api_key).
"'" :
"null");
1973 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
1974 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
1975 if (!empty($user->admin)) {
1976 $sql .=
", admin = ".(int) $this->admin;
1978 $sql .=
", address = '".$this->db->escape($this->address).
"'";
1979 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
1980 $sql .=
", town = '".$this->db->escape($this->town).
"'";
1981 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".$this->
db->escape($this->state_id).
"'" :
"null");
1982 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".$this->
db->escape($this->country_id).
"'" :
"null");
1983 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
1984 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
1985 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
1986 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
1987 $sql .=
", email = '".$this->db->escape($this->email).
"'";
1988 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
1989 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1990 $sql .=
", job = '".$this->db->escape($this->job).
"'";
1991 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
1992 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
1993 $sql .=
", color = '".$this->db->escape($this->color).
"'";
1994 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
1995 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
1996 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
1997 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
1998 $sql .=
", note_private = '".$this->db->escape($this->note_private).
"'";
1999 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
2000 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
2001 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
2002 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".$this->db->escape($this->fk_user).
"'" :
"null");
2003 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".$this->db->escape($this->fk_user_expense_validator).
"'" :
"null");
2004 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".$this->db->escape($this->fk_user_holiday_validator).
"'" :
"null");
2005 if (isset($this->thm) || $this->thm !=
'') {
2006 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
2008 if (isset($this->tjm) || $this->tjm !=
'') {
2009 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
2011 if (isset($this->salary) || $this->salary !=
'') {
2012 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2014 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2015 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2017 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2018 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2019 $sql .=
", entity = ".((int) $this->entity);
2021 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2022 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2023 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2024 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2025 $sql .=
" WHERE rowid = ".((int) $this->
id);
2027 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2030 $nbrowsaffected += $this->
db->affected_rows(
$resql);
2033 if (!empty($this->pass)) {
2034 if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
2036 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass);
2044 if ($this->fk_member > 0) {
2045 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2046 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2049 $this->
error = $this->
db->error(); $this->
db->rollback();
return -5;
2053 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2054 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2057 $this->
error = $this->
db->error(); $this->
db->rollback();
return -5;
2060 if ($nbrowsaffected) {
2061 if ($this->fk_member > 0 && !$nosyncmember) {
2062 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2064 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2069 $result = $adh->fetch($this->fk_member);
2072 $adh->civility_code = $this->civility_code;
2073 $adh->firstname = $this->firstname;
2074 $adh->lastname = $this->lastname;
2075 $adh->login = $this->login;
2076 $adh->gender = $this->gender;
2077 $adh->birth = $this->birth;
2079 $adh->pass = $this->pass;
2081 $adh->address = $this->address;
2082 $adh->town = $this->town;
2083 $adh->zip = $this->zip;
2084 $adh->state_id = $this->state_id;
2085 $adh->country_id = $this->country_id;
2087 $adh->email = $this->email;
2089 $adh->socialnetworks = $this->socialnetworks;
2091 $adh->phone = $this->office_phone;
2092 $adh->phone_mobile = $this->user_mobile;
2094 $adh->default_lang = $this->lang;
2096 $adh->user_id = $this->id;
2097 $adh->user_login = $this->login;
2099 $result = $adh->update($user, 0, 1, 0);
2101 $this->
error = $adh->error;
2102 $this->errors = $adh->errors;
2103 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2106 } elseif ($result < 0) {
2107 $this->
error = $adh->error;
2108 $this->errors = $adh->errors;
2113 if ($this->contact_id > 0 && !$nosynccontact) {
2114 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2116 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2120 $result = $tmpobj->fetch($this->contact_id);
2123 $tmpobj->civility_code = $this->civility_code;
2124 $tmpobj->firstname = $this->firstname;
2125 $tmpobj->lastname = $this->lastname;
2126 $tmpobj->login = $this->login;
2127 $tmpobj->gender = $this->gender;
2128 $tmpobj->birth = $this->birth;
2132 $tmpobj->email = $this->email;
2134 $tmpobj->socialnetworks = $this->socialnetworks;
2136 $tmpobj->phone_pro = $this->office_phone;
2137 $tmpobj->phone_mobile = $this->user_mobile;
2138 $tmpobj->fax = $this->office_fax;
2140 $tmpobj->default_lang = $this->lang;
2142 $tmpobj->address = $this->address;
2143 $tmpobj->town = $this->town;
2144 $tmpobj->zip = $this->zip;
2145 $tmpobj->state_id = $this->state_id;
2146 $tmpobj->country_id = $this->country_id;
2148 $tmpobj->user_id = $this->id;
2149 $tmpobj->user_login = $this->login;
2151 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2153 $this->
error = $tmpobj->error;
2154 $this->errors = $tmpobj->errors;
2155 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2159 $this->
error = $tmpobj->error;
2160 $this->errors = $tmpobj->errors;
2176 if (!$error && !$notrigger) {
2186 $this->
db->commit();
2187 return $nbrowsaffected;
2190 $this->
db->rollback();
2194 $this->
error = $this->
db->lasterror();
2195 $this->
db->rollback();
2214 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2215 $sql .=
" datepreviouslogin = datelastlogin,";
2216 $sql .=
" ippreviouslogin = iplastlogin,";
2217 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2218 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2219 $sql .=
" tms = tms";
2220 $sql .=
" WHERE rowid = ".((int) $this->
id);
2222 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2225 $this->datepreviouslogin = $this->datelastlogin;
2226 $this->datelastlogin = $now;
2227 $this->ippreviouslogin = $this->iplastlogin;
2228 $this->iplastlogin = $userremoteip;
2231 $this->
error = $this->
db->lasterror().
' sql='.$sql;
2248 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0)
2250 global $conf, $langs;
2251 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2255 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2263 if (empty($passwordalreadycrypted)) {
2264 if (!empty($conf->global->USER_PASSWORD_GENERATED)) {
2266 $modGeneratePassClass =
'modGeneratePass'.ucfirst($conf->global->USER_PASSWORD_GENERATED);
2268 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2269 if (class_exists($modGeneratePassClass)) {
2270 $modGeneratePass =
new $modGeneratePassClass($this->
db, $conf, $langs, $user);
2273 $modGeneratePass->WithoutAmbi = 0;
2276 $testpassword = $modGeneratePass->validatePassword($password);
2277 if (!$testpassword) {
2278 $this->
error = $modGeneratePass->error;
2286 $password_crypted =
dol_hash($password);
2290 if (!$changelater) {
2291 if (!is_object($this->oldcopy)) {
2292 $this->oldcopy = clone $this;
2297 $sql =
"UPDATE ".$this->db->prefix().
"user";
2298 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2299 $sql .=
" pass_temp = null";
2300 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
2301 $sql .=
", pass = null";
2303 $sql .=
", pass = '".$this->db->escape($password).
"'";
2305 $sql .=
" WHERE rowid = ".((int) $this->
id);
2307 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2308 $result = $this->
db->query($sql);
2310 if ($this->
db->affected_rows($result)) {
2311 $this->pass = $password;
2312 $this->pass_indatabase = $password;
2313 $this->pass_indatabase_crypted = $password_crypted;
2315 if ($this->fk_member && !$nosyncmember) {
2316 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2321 $result = $adh->fetch($this->fk_member);
2324 $result = $adh->setPassword($user, $this->pass, (empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1), 1);
2326 $this->
error = $adh->error;
2331 $this->
error = $adh->error;
2336 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2338 if (!$error && !$notrigger) {
2340 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2342 $error++; $this->
db->rollback();
return -1;
2347 $this->
db->commit();
2350 $this->
db->rollback();
2354 $this->
db->rollback();
2361 $sql =
"UPDATE ".$this->db->prefix().
"user";
2362 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2363 $sql .=
" WHERE rowid = ".((int) $this->
id);
2365 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2366 $result = $this->
db->query($sql);
2388 global $conf, $langs, $mysoc;
2389 global $dolibarr_main_url_root;
2391 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2398 $outputlangs =
new Translate(
"", $conf);
2400 if (isset($this->
conf->MAIN_LANG_DEFAULT)
2401 && $this->conf->MAIN_LANG_DEFAULT !=
'auto') {
2402 $outputlangs->getDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2405 if ($this->
conf->MAIN_LANG_DEFAULT) {
2406 $outputlangs->setDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2408 $outputlangs = $langs;
2412 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2414 $appli = constant(
'DOL_APPLICATION_TITLE');
2415 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
2416 $appli = $conf->global->MAIN_APPLICATION_TITLE;
2419 $subject =
'['.$mysoc->name.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2422 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2423 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2425 if (!$changelater) {
2426 $url = $urlwithroot.
'/';
2427 if (!empty($conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD))
2428 $url = $conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD;
2429 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2430 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2431 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2432 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2435 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2437 $mesg .= $user->getFullName($outputlangs);
2439 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2441 global $dolibarr_main_instance_unique_id;
2444 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2445 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.$dolibarr_main_instance_unique_id));
2449 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2450 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2451 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2452 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2454 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2455 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2456 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2458 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2461 $trackid =
'use'.$this->id;
2466 $conf->global->MAIN_MAIL_EMAIL_FROM,
2480 if ($mailfile->sendfile()) {
2483 $langs->trans(
"errors");
2484 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2496 return $this->error;
2509 $sql =
"SELECT url, login, pass, poste ";
2510 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2511 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2516 $obj = $this->
db->fetch_object(
$resql);
2518 $this->clicktodial_url = $obj->url;
2519 $this->clicktodial_login = $obj->login;
2520 $this->clicktodial_password = $obj->pass;
2521 $this->clicktodial_poste = $obj->poste;
2524 $this->clicktodial_loaded = 1;
2529 $this->
error = $this->
db->error();
2545 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2546 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2548 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2549 $result = $this->
db->query($sql);
2551 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2552 $sql .=
" (fk_user,url,login,pass,poste)";
2553 $sql .=
" VALUES (".$this->id;
2554 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2555 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2556 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2557 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2559 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2560 $result = $this->
db->query($sql);
2562 $this->
db->commit();
2565 $this->
db->rollback();
2566 $this->
error = $this->
db->lasterror();
2584 global $conf, $langs, $user;
2590 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2591 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2592 $sql .=
" AND fk_usergroup = ".((int) $group);
2593 $sql .=
" AND entity = ".((int) $entity);
2595 $result = $this->
db->query($sql);
2597 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2598 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2600 $result = $this->
db->query($sql);
2602 if (!$error && !$notrigger) {
2603 $this->newgroupid = $group;
2604 $this->context = array(
'audit'=>$langs->trans(
"UserSetInGroup"),
'newgroupid'=>$group);
2615 $this->
db->commit();
2619 $this->
db->rollback();
2623 $this->
error = $this->
db->lasterror();
2624 $this->
db->rollback();
2641 global $conf, $langs, $user;
2647 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2648 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2649 $sql .=
" AND fk_usergroup = ".((int) $group);
2650 $sql .=
" AND entity = ".((int) $entity);
2652 $result = $this->
db->query($sql);
2654 if (!$error && !$notrigger) {
2655 $this->oldgroupid = $group;
2656 $this->context = array(
'audit'=>$langs->trans(
"UserRemovedFromGroup"),
'oldgroupid'=>$group);
2667 $this->
db->commit();
2670 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2671 $this->
db->rollback();
2675 $this->
error = $this->
db->lasterror();
2676 $this->
db->rollback();
2692 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
2694 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2695 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
2716 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
2718 global $langs, $conf, $db, $hookmanager, $user;
2719 global $dolibarr_main_authentication, $dolibarr_main_demo;
2720 global $menumanager;
2722 if (!$user->hasRight(
'user',
'user',
'read') && $user->id != $this->id) {
2726 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) {
2730 $result =
''; $label =
''; $companylink =
'';
2732 if (!empty($this->photo)) {
2733 $label .=
'<div class="photointooltip floatright">';
2734 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
2740 $label .=
'<div class="centpercent">';
2741 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u>';
2742 $label .=
' '.$this->getLibStatut(4);
2744 if (!empty($this->login)) {
2747 if (!empty($this->job)) {
2751 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
2752 $phonelist = array();
2753 if ($this->office_phone) {
2754 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2756 if ($this->office_fax) {
2757 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2759 if ($this->user_mobile) {
2760 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
2762 $label .=
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
2764 if (!empty($this->admin)) {
2765 $label .=
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
2767 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
2768 $label .=
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
2771 if (!empty($this->socid)) {
2772 $thirdpartystatic =
new Societe($db);
2773 $thirdpartystatic->fetch($this->socid);
2774 if (empty($hidethirdpartylogo)) {
2775 $companylink =
' '.$thirdpartystatic->getNomUrl(2, (($option ==
'nolink') ?
'nolink' :
''));
2779 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
2780 $label .=
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
2782 if ($infologin > 0) {
2784 $label .=
'<br><u>'.$langs->trans(
"Session").
'</u>';
2786 if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) {
2787 $label .=
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.$conf->entity.
' (User entity '.$this->entity.
')';
2789 $label .=
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
2790 $label .=
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
2791 $label .=
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
2793 $label .=
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
2795 $label .=
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
2796 $label .=
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag($conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
2797 $label .=
'<br><b>'.$langs->trans(
"Layout").
':</b> '.
dol_string_nohtmltag($conf->browser->layout);
2798 $label .=
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
2799 if ($conf->browser->layout ==
'phone') {
2800 $label .=
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
2802 if (!empty($_SESSION[
"disablemodules"])) {
2803 $label .=
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(join(
', ', explode(
',', $_SESSION[
"disablemodules"])));
2806 if ($infologin < 0) {
2810 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
2811 if ($option ==
'leave') {
2812 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
2815 if ($option !=
'nolink') {
2817 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2818 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2819 $add_save_lastsearch_values = 1;
2821 if ($add_save_lastsearch_values) {
2822 $url .=
'&save_lastsearch_values=1';
2826 $linkstart =
'<a href="'.$url.
'"';
2828 if (empty($notooltip)) {
2829 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2830 $langs->load(
"users");
2831 $label = $langs->trans(
"ShowUser");
2832 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2834 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
2835 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
2838 $linkstart .= $linkclose.
'>';
2842 $result .= (($option ==
'nolink') ?
'' : $linkstart);
2843 if ($withpictoimg) {
2844 $paddafterimage =
'';
2845 if (abs((
int) $withpictoimg) == 1) {
2846 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
2849 if ($withpictoimg > 0) {
2850 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
2853 $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>';
2857 if ($withpictoimg > -2 && $withpictoimg != 2) {
2858 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2859 $result .=
'<span class="nopadding usertext'.((!isset($this->statut) || $this->statut) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
2861 if ($mode ==
'login') {
2866 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2867 $result .=
'</span>';
2870 $result .= (($option ==
'nolink') ?
'' : $linkend);
2873 $result .= $companylink;
2876 $hookmanager->initHooks(array(
'userdao'));
2877 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
2878 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2880 $result = $hookmanager->resPrint;
2882 $result .= $hookmanager->resPrint;
2897 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
2899 global $langs, $user;
2903 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2907 if ((!$user->rights->user->user->lire && $this->id != $user->id)) {
2911 if ($option ==
'xxx') {
2912 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2916 if ($option ==
'nolink') {
2921 $result .= $linkstart;
2922 if ($withpictoimg) {
2923 $paddafterimage =
'';
2924 if (abs($withpictoimg) == 1) {
2925 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
2928 if ($withpictoimg > 0) {
2929 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
2932 $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>';
2936 $result .= $this->login;
2937 $result .= $linkend;
2950 return $this->
LibStatut(isset($this->statut) ? (
int) $this->statut : (
int) $this->status, $mode);
2966 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2969 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
2970 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
2971 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
2972 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
2975 $statusType =
'status5';
2976 if ($status == self::STATUS_ENABLED) {
2977 $statusType =
'status4';
2980 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
2992 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2993 $return .=
'<div class="info-box info-box-sm">';
2994 $return .=
'<span class="info-box-icon bg-infobox-action">';
2997 if (!empty($this->photo)) {
2999 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
3008 $return .=
'</span>';
3009 $return .=
'<div class="info-box-content">';
3010 $return .=
'<span class="info-box-ref">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3011 if (property_exists($this,
'label')) {
3012 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3015 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->email.
'</span>';
3017 if (method_exists($this,
'getLibStatut')) {
3018 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(5).
'</div>';
3020 $return .=
'</div>';
3021 $return .=
'</div>';
3022 $return .=
'</div>';
3045 $dn = $conf->global->LDAP_KEY_USERS.
"=".$info[$conf->global->LDAP_KEY_USERS].
",".$conf->global->LDAP_USER_DN;
3046 } elseif ($mode == 1) {
3047 $dn = $conf->global->LDAP_USER_DN;
3048 } elseif ($mode == 2) {
3049 $dn = $conf->global->LDAP_KEY_USERS.
"=".$info[$conf->global->LDAP_KEY_USERS];
3064 global $conf, $langs;
3070 $keymodified =
false;
3073 $info[
"objectclass"] = explode(
',', $conf->global->LDAP_USER_OBJECT_CLASS);
3079 'LDAP_FIELD_FULLNAME' =>
'fullname',
3080 'LDAP_FIELD_NAME' =>
'lastname',
3081 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3082 'LDAP_FIELD_LOGIN' =>
'login',
3083 'LDAP_FIELD_LOGIN_SAMBA'=>
'login',
3084 'LDAP_FIELD_PHONE' =>
'office_phone',
3085 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3086 'LDAP_FIELD_FAX' =>
'office_fax',
3087 'LDAP_FIELD_MAIL' =>
'email',
3088 'LDAP_FIELD_SID' =>
'ldap_sid',
3092 foreach ($ldapkey as $constname => $varname) {
3093 if (!empty($this->$varname) && !empty($conf->global->$constname)) {
3094 $info[$conf->global->$constname] = $this->$varname;
3097 if (!empty($conf->global->LDAP_KEY_USERS) && $conf->global->LDAP_KEY_USERS == $conf->global->$constname) {
3098 if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
3099 $keymodified =
true;
3104 foreach ($socialnetworks as $key => $value) {
3105 if (!empty($this->socialnetworks[$value[
'label']]) && !empty($conf->global->{
'LDAP_FIELD_'.strtoupper($value[
'label'])})) {
3106 $info[$conf->global->{
'LDAP_FIELD_'.strtoupper($value[
'label'])}] = $this->socialnetworks[$value[
'label']];
3109 if ($this->address && !empty($conf->global->LDAP_FIELD_ADDRESS)) {
3110 $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->address;
3112 if ($this->zip && !empty($conf->global->LDAP_FIELD_ZIP)) {
3113 $info[$conf->global->LDAP_FIELD_ZIP] = $this->zip;
3115 if ($this->town && !empty($conf->global->LDAP_FIELD_TOWN)) {
3116 $info[$conf->global->LDAP_FIELD_TOWN] = $this->town;
3118 if ($this->note_public && !empty($conf->global->LDAP_FIELD_DESCRIPTION)) {
3121 if ($this->socid > 0) {
3123 $soc->fetch($this->socid);
3125 $info[$conf->global->LDAP_FIELD_COMPANY] = $soc->name;
3126 if ($soc->client == 1) {
3127 $info[
"businessCategory"] =
"Customers";
3129 if ($soc->client == 2) {
3130 $info[
"businessCategory"] =
"Prospects";
3132 if ($soc->fournisseur == 1) {
3133 $info[
"businessCategory"] =
"Suppliers";
3138 if (!empty($this->pass)) {
3139 if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
3140 $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass;
3142 if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3143 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass,
'openldap');
3145 } elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !==
'3') {
3148 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
3150 if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) {
3151 if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3152 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dolGetLdapPasswordHash($this->pass_indatabase_crypted,
'md5frommd5');
3155 } elseif (!empty($this->pass_indatabase)) {
3157 if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
3158 $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass_indatabase;
3160 if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3161 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass_indatabase,
'openldap');
3166 if ($conf->global->LDAP_SERVER_TYPE ==
'egroupware') {
3167 $info[
"objectclass"][4] =
"phpgwContact";
3169 $info[
'uidnumber'] = $this->id;
3171 $info[
'phpgwTz'] = 0;
3172 $info[
'phpgwMailType'] =
'INTERNET';
3173 $info[
'phpgwMailHomeType'] =
'INTERNET';
3175 $info[
"phpgwContactTypeId"] =
'n';
3176 $info[
"phpgwContactCatId"] = 0;
3177 $info[
"phpgwContactAccess"] =
"public";
3180 $this->egroupware_id = 1;
3183 $info[
"phpgwContactOwner"] = $this->egroupware_id;
3186 $info[
"rfc822Mailbox"] = $this->email;
3188 if ($this->phone_mobile) {
3189 $info[
"phpgwCellTelephoneNumber"] = $this->phone_mobile;
3193 if (!empty($conf->global->LDAP_FIELD_USERID)) {
3194 $info[$conf->global->LDAP_FIELD_USERID] = $this->id;
3196 if (!empty($conf->global->LDAP_FIELD_GROUPID)) {
3198 $groupslist = $usergroup->listGroupsForUser($this->
id);
3199 $info[$conf->global->LDAP_FIELD_GROUPID] =
'65534';
3200 if (!empty($groupslist)) {
3201 foreach ($groupslist as $groupforuser) {
3202 $info[$conf->global->LDAP_FIELD_GROUPID] = $groupforuser->id;
3207 if (!empty($conf->global->LDAP_FIELD_HOMEDIRECTORY) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX)) {
3208 $info[$conf->global->LDAP_FIELD_HOMEDIRECTORY] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->login";
3224 global $user, $langs;
3230 $this->
ref =
'SPECIMEN';
3231 $this->specimen = 1;
3233 $this->lastname =
'DOLIBARR';
3234 $this->firstname =
'SPECIMEN';
3235 $this->gender =
'man';
3236 $this->note_public =
'This is a note public';
3237 $this->note_private =
'This is a note private';
3238 $this->email =
'email@specimen.com';
3239 $this->personal_email =
'personalemail@specimen.com';
3240 $this->socialnetworks = array(
3241 'skype' =>
'skypepseudo',
3242 'twitter' =>
'twitterpseudo',
3243 'facebook' =>
'facebookpseudo',
3244 'linkedin' =>
'linkedinpseudo',
3246 $this->office_phone =
'0999999999';
3247 $this->office_fax =
'0999999998';
3248 $this->user_mobile =
'0999999997';
3249 $this->personal_mobile =
'0999999996';
3251 $this->login =
'dolibspec';
3252 $this->pass =
'dolibSpec+@123';
3255 $this->datec = $now;
3256 $this->datem = $now;
3258 $this->datelastlogin = $now;
3259 $this->iplastlogin =
'127.0.0.1';
3260 $this->datepreviouslogin = $now;
3261 $this->ippreviouslogin =
'127.0.0.1';
3277 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
3278 $sql .=
" u.tms as date_modification, u.entity";
3279 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3280 $sql .=
" WHERE u.rowid = ".((int) $id);
3282 $result = $this->
db->query($sql);
3284 if ($this->
db->num_rows($result)) {
3285 $obj = $this->
db->fetch_object($result);
3287 $this->
id = $obj->rowid;
3289 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3290 $this->date_creation = $this->db->jdate($obj->datec);
3291 $this->date_modification = $this->
db->jdate($obj->date_modification);
3292 $this->entity = $obj->entity;
3295 $this->
db->free($result);
3309 $sql =
"SELECT count(mc.email) as nb";
3310 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3311 $sql .=
" WHERE mc.email = '".$this->db->escape($this->email).
"'";
3312 $sql .=
" AND mc.statut NOT IN (-1,0)";
3316 $obj = $this->
db->fetch_object(
$resql);
3322 $this->error = $this->
db->error();
3339 $sql =
"SELECT count(rowid) as nb";
3340 $sql .=
" FROM ".$this->db->prefix().
"user";
3341 if ($option ==
'superadmin') {
3342 $sql .=
" WHERE entity = 0";
3344 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3345 if ($limitTo ==
'active') {
3346 $sql .=
" AND statut = 1";
3350 $sql .=
" AND admin = ".(int) $admin;
3355 $obj = $this->
db->fetch_object(
$resql);
3356 $nb = (int) $obj->nb;
3361 $this->error = $this->
db->lasterror();
3377 global $user, $conf;
3382 $this->firstname = $ldapuser->$tmpvar;
3384 $this->lastname = $ldapuser->$tmpvar;
3386 $this->login = $ldapuser->$tmpvar;
3388 $this->pass = $ldapuser->$tmpvar;
3390 $this->pass_indatabase_crypted = $ldapuser->$tmpvar;
3393 $this->office_phone = $ldapuser->$tmpvar;
3395 $this->user_mobile = $ldapuser->$tmpvar;
3397 $this->office_fax = $ldapuser->$tmpvar;
3399 $this->email = $ldapuser->$tmpvar;
3400 foreach ($socialnetworks as $key => $value) {
3402 $this->socialnetworks[$value[
'label']] = $ldapuser->$tmpvar;
3405 $this->ldap_sid = $ldapuser->$tmpvar;
3408 $this->job = $ldapuser->$tmpvar;
3410 $this->note_public = $ldapuser->$tmpvar;
3412 $result = $this->update($user);
3414 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3430 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3431 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3433 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3434 $res = $this->
db->query($sql);
3437 while ($rec = $this->
db->fetch_array($res)) {
3438 $user =
new User($this->
db);
3439 $user->fetch($rec[
'rowid']);
3459 $this->parentof = array();
3462 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3463 $sql .=
" FROM ".$this->db->prefix().
"user";
3464 $sql .=
" WHERE fk_user <> 0";
3465 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3467 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3470 while ($obj = $this->
db->fetch_object(
$resql)) {
3471 $this->parentof[$obj->id_son] = $obj->id_parent;
3497 global $conf, $user;
3498 global $hookmanager;
3501 $hookmanager->initHooks(array(
'userdao'));
3503 $this->users = array();
3506 $this->loadParentOf();
3509 $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";
3510 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3512 $parameters = array();
3513 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3515 $sql .= $hookmanager->resPrint;
3517 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3520 $sql .=
" AND ".$filter;
3523 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3527 while ($obj = $this->
db->fetch_object(
$resql)) {
3528 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3529 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3530 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3531 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3532 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3533 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3534 $this->users[$obj->rowid][
'login'] = $obj->login;
3535 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3536 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3537 $this->users[$obj->rowid][
'email'] = $obj->email;
3538 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3539 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3540 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3549 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3550 foreach ($this->users as $key => $val) {
3551 $result = $this->build_path_from_id_user($key, 0);
3553 $this->error =
'ErrorLoopInHierarchy';
3559 if ($deleteafterid) {
3561 $keyfilter1 =
'^'.$deleteafterid.
'$';
3562 $keyfilter2 =
'_'.$deleteafterid.
'$';
3563 $keyfilter3 =
'^'.$deleteafterid.
'_';
3564 $keyfilter4 =
'_'.$deleteafterid.
'_';
3565 foreach ($this->users as $key => $val) {
3566 if (preg_match(
'/'.$keyfilter1.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter2.
'/', $val[
'fullpath'])
3567 || preg_match(
'/'.$keyfilter3.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter4.
'/', $val[
'fullpath'])) {
3568 unset($this->users[$key]);
3573 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
3574 $this->users =
dol_sort_array($this->users,
'fullname',
'asc',
true,
false);
3578 return $this->users;
3591 $childids = array();
3593 if (isset($this->cache_childids[$this->
id])) {
3594 $childids = $this->cache_childids[$this->id];
3597 $this->get_full_tree();
3599 $idtoscan = $this->id;
3601 dol_syslog(
"Build childid for id = ".$idtoscan);
3602 foreach ($this->users as $id => $val) {
3604 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
3605 $childids[$val[
'id']] = $val[
'id'];
3609 $this->cache_childids[$this->id] = $childids;
3611 if ($addcurrentuser) {
3612 $childids[$this->id] = $this->id;
3632 if (!empty($this->users[$id_user][
'fullpath'])) {
3634 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
3639 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
3640 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
3641 $i = 0; $cursor_user = $id_user;
3643 $useridfound = array($id_user);
3644 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
3645 if (in_array($this->parentof[$cursor_user], $useridfound)) {
3646 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
3649 $useridfound[] = $this->parentof[$cursor_user];
3650 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
3651 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
3652 $i++; $cursor_user = $this->parentof[$cursor_user];
3656 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
3690 $this->nb = array();
3692 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
3693 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3694 if (
isModEnabled(
'multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
3695 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
3696 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
3697 $sql .=
" AND ug.fk_user = u.rowid";
3699 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3701 $sql .=
" AND u.statut > 0";
3706 while ($obj = $this->
db->fetch_object(
$resql)) {
3707 $this->nb[
"users"] = $obj->nb;
3713 $this->error = $this->
db->error();
3729 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3731 global $conf, $user, $langs;
3733 $langs->load(
"user");
3737 if (!empty($conf->global->USER_ADDON_PDF)) {
3738 $modele = $conf->global->USER_ADDON_PDF;
3740 $modele =
'bluesky';
3744 $modelpath =
"core/modules/user/doc/";
3746 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3760 $user_property =
'';
3762 if (empty($rowid)) {
3766 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
3767 $sql .=
" FROM ".$this->db->prefix().
"user";
3768 $sql .=
" WHERE rowid = ".((int) $rowid);
3772 $nump = $this->
db->num_rows(
$resql);
3775 $obj = $this->
db->fetch_object(
$resql);
3777 if ($mode ==
'email') {
3778 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
3779 } elseif ($mode ==
'mobile') {
3780 $user_property = $obj->user_mobile;
3783 return $user_property;
3801 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter = array(), $filtermode =
'AND', $entityfilter =
false)
3803 global $conf, $user;
3805 $sql =
"SELECT t.rowid";
3806 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
3808 if ($entityfilter) {
3809 if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
3810 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
3811 $sql .=
" WHERE t.entity IS NOT NULL";
3813 $sql .=
",".$this->db->prefix().
"usergroup_user as ug";
3814 $sql .=
" WHERE ((ug.fk_user = t.rowid";
3815 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
3816 $sql .=
" OR t.entity = 0)";
3819 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
3822 $sql .=
" WHERE 1 = 1";
3826 $sqlwhere = array();
3827 if (!empty($filter)) {
3828 foreach ($filter as $key => $value) {
3829 if ($key ==
't.rowid') {
3830 $sqlwhere[] = $key.
" = ".((int) $value);
3831 } elseif (isset($this->fields[$key][
'type']) && in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
3832 $sqlwhere[] = $key.
" = '".$this->
db->idate($value).
"'";
3833 } elseif ($key ==
'customsql') {
3834 $sqlwhere[] = $value;
3836 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
3840 if (count($sqlwhere) > 0) {
3841 $sql .=
' AND ('.implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere).
')';
3843 $sql .= $this->
db->order($sortfield, $sortorder);
3845 $sql .= $this->
db->plimit($limit + 1, $offset);
3852 $this->users = array();
3853 $num = $this->
db->num_rows(
$resql);
3855 while ($obj = $this->
db->fetch_object(
$resql)) {
3856 $line =
new self($this->db);
3857 $result = $line->fetch($obj->rowid);
3858 if ($result > 0 && !empty($line->id)) {
3859 $this->users[$obj->rowid] = clone $line;
3866 $this->errors[] = $this->
db->lasterror();
3878 private $findUserIdByEmailCache;
3892 if (isset($this->findUserIdByEmailCache[$email])) {
3893 return $this->findUserIdByEmailCache[$email];
3896 $this->findUserIdByEmailCache[$email] = -1;
3900 $sql =
'SELECT rowid';
3901 $sql .=
' FROM '.$this->db->prefix().
'user';
3902 if (!empty($conf->global->AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR)) {
3903 $sql .=
" WHERE email LIKE '%".$this->db->escape($email).
"%'";
3905 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
3914 $obj = $this->
db->fetch_object(
$resql);
3919 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
3921 return $this->findUserIdByEmailCache[$email];
Class to manage members of a foundation.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
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...
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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.
SetInGroup($group, $entity, $notrigger=0)
Add user into a group.
LibStatut($status, $mode=0)
Return the label of a status of user (active, inactive)
get_children()
Return and array with all instanciated 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.
hasRight($module, $permlevel1, $permlevel2='')
Return if a user has a permission.
getKanbanView($option='')
Return clicable link of object (with eventually picto)
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()
Mise a jour en base de la date de derniere connexion d'un utilisateur Fonction appelee lors d'une nou...
__construct($db)
Constructor of the class.
RemoveFromGroup($group, $entity, $notrigger=0)
Remove a user from a group.
getNbOfUsers($limitTo, $option='', $admin=-1)
Return number of existing users.
fetch($id='', $login='', $sid='', $loadpersonalconf=0, $entity=-1, $email='', $fk_socpeople=0)
Load a user from database with its id or ref (login).
set_default_rights()
Assign rights by default.
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 (eventualy with picto)
setCategories($categories)
Sets object to supplied categories.
loadParentOf()
Load this->parentof that is array(id_son=>id_parent, ...)
fetch_clicktodial()
Read clicktodial information for user.
build_path_from_id_user($id_user, $protection=0)
For user id_user and its childs available in this->users, define property fullpath and fullname.
error()
Renvoie la derniere erreur fonctionnelle de manipulation de l'objet.
getAllChildIds($addcurrentuser=0)
Return list of all child users id in herarchy (all sublevels).
initAsSpecimen()
Initialise an instance with random values.
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 optionaly the picto) Use this->id,this->lastname,...
clearrights()
Clear all permissions array of user.
load_state_board()
Load metrics this->nb for dashboard.
update_clicktodial()
Update clicktodial info.
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)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
$clicktodial_url
@string clicktodial url
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.
update_ldap2dolibarr(&$ldapuser)
Update user using data from the LDAP.
getrights($moduletag='', $forcereload=0)
Load permissions granted to user into object user.
user_get_property($rowid, $mode)
Return property of user from its id.
send_password($user, $password='', $changelater=0)
Send new password by email.
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.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter=array(), $filtermode='AND', $entityfilter=false)
Load all objects into $this->users.
setPassword($user, $password='', $changelater=0, $notrigger=0, $nosyncmember=0, $passwordalreadycrypted=0)
Change password of a user.
findUserIdByEmail($email)
Find a user by the given e-mail and return it's user id when found.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_phone($phone, $countrycode='', $cid=0, $socid=0, $addlink='', $separ=" ", $withpicto='', $titlealt='', $adddivfloat=0)
Format phone numbers according to country.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
getArrayOfSocialNetworks()
Get array of social network dictionary.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.
getUserRemoteIP()
Return the IP of remote user.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dolGetLdapPasswordHash($password, $type='md5')
Returns a specific ldap hash of a password.
dol_hash($chain, $type='0')
Returns a hash (non reversible encryption) of a string.
$conf db
API class for accounts.