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 as 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, 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 ((empty($conf->multicompany->enabled) || 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 (!empty($conf->multicompany->enabled) && !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 = (array) json_decode($obj->socialnetworks,
true);
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;
556 $this->statut = $obj->statut;
557 $this->photo = $obj->photo;
558 $this->openid = $obj->openid;
559 $this->lang = $obj->lang;
560 $this->entity = $obj->entity;
561 $this->accountancy_code = $obj->accountancy_code;
562 $this->thm = $obj->thm;
563 $this->tjm = $obj->tjm;
564 $this->salary = $obj->salary;
565 $this->salaryextra = $obj->salaryextra;
566 $this->weeklyhours = $obj->weeklyhours;
567 $this->color = $obj->color;
568 $this->dateemployment = $this->
db->jdate($obj->dateemployment);
569 $this->dateemploymentend = $this->
db->jdate($obj->dateemploymentend);
571 $this->datec = $this->
db->jdate($obj->datec);
572 $this->datem = $this->
db->jdate($obj->datem);
573 $this->datelastlogin = $this->
db->jdate($obj->datel);
574 $this->datepreviouslogin = $this->
db->jdate($obj->datep);
575 $this->iplastlogin = $obj->iplastlogin;
576 $this->ippreviouslogin = $obj->ippreviouslogin;
577 $this->datestartvalidity = $this->
db->jdate($obj->datestartvalidity);
578 $this->dateendvalidity = $this->
db->jdate($obj->dateendvalidity);
580 $this->socid = $obj->fk_soc;
581 $this->contact_id = $obj->fk_socpeople;
582 $this->fk_member = $obj->fk_member;
583 $this->fk_user = $obj->fk_user;
584 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
585 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
587 $this->default_range = $obj->default_range;
588 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
589 $this->fk_warehouse = $obj->fk_warehouse;
593 if (empty($conf->multicompany->enabled) && $this->admin && $this->entity == 1) {
601 $this->
db->free($result);
603 $this->
error =
"USERNOTFOUND";
604 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
606 $this->
db->free($result);
610 $this->
error = $this->
db->lasterror();
615 if ($loadpersonalconf) {
617 $sql =
"SELECT param, value FROM ".$this->db->prefix().
"user_param";
618 $sql .=
" WHERE fk_user = ".((int) $this->
id);
619 $sql .=
" AND entity = ".((int) $conf->entity);
626 $obj = $this->
db->fetch_object(
$resql);
627 $p = (!empty($obj->param) ? $obj->param :
'');
629 $this->
conf->$p = $obj->value;
635 $this->
error = $this->
db->lasterror();
642 $this->
error = $this->
db->lasterror();
658 if (!empty($conf->global->MAIN_ENABLE_DEFAULT_VALUES)) {
660 require_once DOL_DOCUMENT_ROOT.
'/core/class/defaultvalues.class.php';
663 $result = $defaultValues->fetchAll(
'',
'', 0, 0, array(
't.user_id'=>array(0, $this->
id),
'entity'=>array((isset($this->entity) ? $this->entity : $conf->entity), $conf->entity)));
665 if (!is_array($result) && $result < 0) {
669 } elseif (count($result) > 0) {
670 foreach ($result as $defval) {
671 if (!empty($defval->page) && !empty($defval->type) && !empty($defval->param)) {
672 $pagewithoutquerystring = $defval->page;
675 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
676 $pagewithoutquerystring = $reg[1];
677 $pagequeries = $reg[2];
679 $this->default_values[$pagewithoutquerystring][$defval->type][$pagequeries ? $pagequeries :
'_noquery_'][$defval->param] = $defval->value;
683 if (!empty($this->default_values)) {
684 foreach ($this->default_values as $a => $b) {
685 foreach ($b as $c => $d) {
686 krsort($this->default_values[$a][$c]);
705 public function hasRight($module, $permlevel1, $permlevel2 =
'')
709 $moduletomoduletouse = array(
710 'contract' =>
'contrat',
711 'member' =>
'adherent',
713 'order' =>
'commande',
715 'project' =>
'projet',
716 'shipping' =>
'expedition',
717 'task' =>
'task@projet',
718 'fichinter' =>
'ficheinter',
719 'propale' =>
'propal',
720 'inventory' =>
'stock',
721 'invoice' =>
'facture',
722 'invoice_supplier' =>
'fournisseur',
723 'order_supplier' =>
'fournisseur',
724 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
725 'skill@hrm' =>
'all@hrm',
726 'job@hrm' =>
'all@hrm',
727 'position@hrm' =>
'all@hrm',
728 'facturerec' =>
'facture'
731 if (!empty($moduletomoduletouse[$module])) {
732 $module = $moduletomoduletouse[$module];
735 $moduleRightsMapping = array(
736 'product' =>
'produit',
739 $rightsPath = $module;
740 if (!empty($moduleRightsMapping[$rightsPath])) {
741 $rightsPath = $moduleRightsMapping[$rightsPath];
745 $tmp = explode(
'@', $rightsPath, 2);
746 if (! empty($tmp[1])) {
747 if (strpos($module,
'@') !==
false) $module = $tmp[1];
748 $rightsPath = $tmp[1];
749 $permlevel2 = $permlevel1;
750 $permlevel1 = $tmp[0];
755 if (!in_array($module, $conf->modules)) {
760 if ($permlevel1 ==
'propale') {
761 $permlevel1 =
'propal';
763 if ($permlevel1 ==
'member') {
764 $permlevel1 =
'adherent';
766 if ($permlevel1 ==
'recruitmentcandidature') {
767 $permlevel1 =
'recruitmentjobposition';
771 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
776 if (!empty($this->rights->$rightsPath->$permlevel1)) {
777 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
778 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
782 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
783 return $this->rights->$rightsPath->$permlevel1->lire;
785 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
786 return $this->rights->$rightsPath->$permlevel1->creer;
788 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
789 return $this->rights->$rightsPath->$permlevel1->create;
791 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
792 return $this->rights->$rightsPath->$permlevel1->supprimer;
796 if (!empty($this->rights->$rightsPath->$permlevel1)) {
797 return $this->rights->$rightsPath->$permlevel1;
801 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
802 return $this->rights->$rightsPath->lire;
804 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
805 return $this->rights->$rightsPath->creer;
807 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
808 return $this->rights->$rightsPath->create;
810 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
811 return $this->rights->$rightsPath->supprimer;
829 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
831 global $conf, $user, $langs;
833 $entity = (empty($entity) ? $conf->entity : $entity);
835 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
843 $module = $perms = $subperms =
'';
846 $sql =
"SELECT module, perms, subperms";
847 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
848 $sql .=
" WHERE id = ".((int) $rid);
849 $sql .=
" AND entity = ".((int) $entity);
851 $result = $this->
db->query($sql);
853 $obj = $this->
db->fetch_object($result);
856 $module = $obj->module;
857 $perms = $obj->perms;
858 $subperms = $obj->subperms;
866 $whereforadd =
"id=".((int) $rid);
868 if (!empty($subperms)) {
869 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->
db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
870 } elseif (!empty($perms)) {
871 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
877 if (!empty($allmodule)) {
878 if ($allmodule ==
'allmodules') {
879 $whereforadd =
'allmodules';
881 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
882 if (!empty($allperms)) {
883 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
890 if (!empty($whereforadd)) {
893 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
894 $sql .=
" WHERE entity = ".((int) $entity);
895 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
896 $sql .=
" AND (".$whereforadd.
")";
899 $result = $this->
db->query($sql);
901 $num = $this->
db->num_rows($result);
904 $obj = $this->
db->fetch_object($result);
909 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id).
" AND fk_id = ".((int) $nid).
" AND entity = ".((int) $entity);
910 if (!$this->
db->query($sql)) {
913 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
914 if (!$this->
db->query($sql)) {
927 if (!$error && !$notrigger) {
928 $langs->load(
"other");
929 $this->context = array(
'audit'=>$langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
940 $this->
db->rollback();
960 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
962 global $conf, $user, $langs;
966 $entity = (!empty($entity) ? $entity : $conf->entity);
971 $module = $perms = $subperms =
'';
975 $sql =
"SELECT module, perms, subperms";
976 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
977 $sql .=
" WHERE id = '".$this->db->escape($rid).
"'";
978 $sql .=
" AND entity = ".((int) $entity);
980 $result = $this->
db->query($sql);
982 $obj = $this->
db->fetch_object($result);
985 $module = $obj->module;
986 $perms = $obj->perms;
987 $subperms = $obj->subperms;
995 $wherefordel =
"id=".((int) $rid);
997 if ($subperms ==
'lire' || $subperms ==
'read') {
998 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->
db->escape($perms).
"' AND subperms IS NOT NULL)";
1000 if ($perms ==
'lire' || $perms ==
'read') {
1001 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1006 if (!empty($allmodule)) {
1007 if ($allmodule ==
'allmodules') {
1008 $wherefordel =
'allmodules';
1010 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1011 if (!empty($allperms)) {
1012 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1019 if (!empty($wherefordel)) {
1022 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1023 $sql .=
" WHERE entity = ".((int) $entity);
1024 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1025 $sql .=
" AND (".$wherefordel.
")";
1029 if ($this->admin == 1) {
1030 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1031 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1032 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1033 $sql .=
" AND id NOT IN (358)";
1036 $result = $this->
db->query($sql);
1038 $num = $this->
db->num_rows($result);
1041 $obj = $this->
db->fetch_object($result);
1044 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1045 $sql .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id = ".((int) $nid);
1046 $sql .=
" AND entity = ".((int) $entity);
1047 if (!$this->
db->query($sql)) {
1059 if (!$error && !$notrigger) {
1060 $langs->load(
"other");
1061 $this->context = array(
'audit'=>$langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1072 $this->
db->rollback();
1075 $this->
db->commit();
1089 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1090 $this->rights =
null;
1091 $this->nb_rights = 0;
1092 $this->all_permissions_are_loaded = 0;
1093 $this->_tab_loaded = array();
1105 public function getrights($moduletag =
'', $forcereload = 0)
1109 if (empty($forcereload)) {
1110 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1115 if (!empty($this->all_permissions_are_loaded)) {
1122 if (!isset($this->rights) || !is_object($this->rights)) {
1123 $this->rights =
new stdClass();
1125 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1126 $this->rights->user =
new stdClass();
1132 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1133 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1134 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1135 $sql .=
" WHERE r.id = ur.fk_id";
1136 if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
1138 $sql .=
" AND r.entity IN (0,".(!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ?
"1," :
"").$conf->entity.
")";
1142 $sql .=
" AND r.entity = ".((int) $conf->entity).
" AND ur.entity = ".((int) $conf->entity);
1144 $sql .=
" AND ur.fk_user= ".((int) $this->
id);
1145 $sql .=
" AND r.perms IS NOT NULL";
1147 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1152 $num = $this->
db->num_rows(
$resql);
1155 $obj = $this->
db->fetch_object(
$resql);
1158 $module = $obj->module;
1159 $perms = $obj->perms;
1160 $subperms = $obj->subperms;
1162 if (!empty($perms)) {
1163 if (!empty($module)) {
1164 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1165 $this->rights->$module =
new stdClass();
1167 if (!empty($subperms)) {
1168 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1169 $this->rights->$module->$perms =
new stdClass();
1171 if (empty($this->rights->$module->$perms->$subperms)) {
1174 $this->rights->$module->$perms->$subperms = 1;
1176 if (empty($this->rights->$module->$perms)) {
1179 $this->rights->$module->$perms = 1;
1190 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1191 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1192 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1193 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1194 $sql .=
" WHERE r.id = gr.fk_id";
1195 if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
1196 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1197 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1199 $sql .=
" AND r.entity = ".((int) $conf->entity);
1202 $sql .=
" AND gr.entity = ".((int) $conf->entity);
1206 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1207 $sql .=
" AND r.entity = ".((int) $conf->entity);
1209 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1210 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1211 $sql .=
" AND r.perms IS NOT NULL";
1213 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1218 $num = $this->
db->num_rows(
$resql);
1221 $obj = $this->
db->fetch_object(
$resql);
1224 $module = $obj->module;
1225 $perms = $obj->perms;
1226 $subperms = $obj->subperms;
1228 if (!empty($perms)) {
1229 if (!empty($module)) {
1230 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1231 $this->rights->$module =
new stdClass();
1233 if (!empty($subperms)) {
1234 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1235 $this->rights->$module->$perms =
new stdClass();
1237 if (empty($this->rights->$module->$perms->$subperms)) {
1240 $this->rights->$module->$perms->$subperms = 1;
1242 if (empty($this->rights->$module->$perms)) {
1246 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1247 $this->rights->$module->$perms = 1;
1259 if (!empty($this->admin)) {
1260 if (empty($this->rights->user->user)) {
1261 $this->rights->user->user =
new stdClass();
1263 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1264 foreach ($listofpermtotest as $permtotest) {
1265 if (empty($this->rights->user->user->$permtotest)) {
1266 $this->rights->user->user->$permtotest = 1;
1270 if (empty($this->rights->user->self)) {
1271 $this->rights->user->self =
new stdClass();
1273 $listofpermtotest = array(
'creer',
'password');
1274 foreach ($listofpermtotest as $permtotest) {
1275 if (empty($this->rights->user->self->$permtotest)) {
1276 $this->rights->user->self->$permtotest = 1;
1281 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
1282 if (empty($this->rights->user->user_advance)) {
1283 $this->rights->user->user_advance =
new stdClass();
1285 $listofpermtotest = array(
'readperms',
'write');
1286 foreach ($listofpermtotest as $permtotest) {
1287 if (empty($this->rights->user->user_advance->$permtotest)) {
1288 $this->rights->user->user_advance->$permtotest = 1;
1292 if (empty($this->rights->user->self_advance)) {
1293 $this->rights->user->self_advance =
new stdClass();
1295 $listofpermtotest = array(
'readperms',
'writeperms');
1296 foreach ($listofpermtotest as $permtotest) {
1297 if (empty($this->rights->user->self_advance->$permtotest)) {
1298 $this->rights->user->self_advance->$permtotest = 1;
1302 if (empty($this->rights->user->group_advance)) {
1303 $this->rights->user->group_advance =
new stdClass();
1305 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1306 foreach ($listofpermtotest as $permtotest) {
1307 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1308 $this->rights->user->group_advance->$permtotest = 1;
1316 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1317 $this->rights->propal = $this->rights->propale;
1319 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1320 $this->rights->propale = $this->rights->propal;
1326 $this->all_permissions_are_loaded = 1;
1329 $this->_tab_loaded[$moduletag] = 1;
1341 global $conf, $langs, $user;
1346 if ($this->statut == $status) {
1353 $sql =
"UPDATE ".$this->db->prefix().
"user";
1354 $sql .=
" SET statut = ".((int) $status);
1355 $sql .=
" WHERE rowid = ".((int) $this->
id);
1356 $result = $this->
db->query($sql);
1358 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1361 $result = $this->
call_trigger(
'USER_ENABLEDISABLE', $user);
1369 $this->
db->rollback();
1372 $this->status = $status;
1373 $this->statut = $status;
1374 $this->
db->commit();
1391 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1392 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1403 global $conf, $langs;
1409 $this->
fetch($this->
id);
1411 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1414 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1416 if (!$error && !$this->
db->query($sql)) {
1418 $this->
error = $this->
db->lasterror();
1422 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1423 if (!$error && !$this->
db->query($sql)) {
1425 $this->
error = $this->
db->lasterror();
1429 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1430 if (!$error && !$this->
db->query($sql)) {
1432 $this->
error = $this->
db->lasterror();
1436 if ($this->contact_id > 0) {
1437 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1438 if (!$error && !$this->
db->query($sql)) {
1440 $this->
error = $this->
db->lasterror();
1449 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1455 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1456 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1457 if (!$this->
db->query($sql)) {
1459 $this->
error = $this->
db->lasterror();
1468 $this->
db->rollback();
1473 $this->
db->commit();
1476 $this->
db->rollback();
1488 public function create($user, $notrigger = 0)
1490 global $conf, $langs;
1496 $this->civility_code = trim((
string) $this->civility_code);
1497 $this->login = trim((
string) $this->login);
1498 if (!isset($this->entity)) {
1499 $this->entity = $conf->entity;
1502 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1504 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1507 if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1508 $langs->load(
"errors");
1509 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1512 if (empty($this->login)) {
1513 $langs->load(
"errors");
1514 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1516 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1517 $langs->load(
"errors");
1518 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName");
1529 $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).
"'";
1530 $resqltochecklogin = $this->
db->query($sqltochecklogin);
1531 if ($resqltochecklogin) {
1532 $objtochecklogin = $this->
db->fetch_object($resqltochecklogin);
1533 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1534 $langs->load(
"errors");
1535 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1537 $this->
db->rollback();
1540 $this->
db->free($resqltochecklogin);
1543 if (!empty($this->email)) {
1544 $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).
"'";
1545 $resqltochecklogin = $this->
db->query($sqltochecklogin);
1546 if ($resqltochecklogin) {
1547 $objtochecklogin = $this->
db->fetch_object($resqltochecklogin);
1548 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1549 $langs->load(
"errors");
1550 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
1552 $this->
db->rollback();
1555 $this->
db->free($resqltochecklogin);
1560 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, entity)";
1561 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->
db->escape($this->login).
"', '".$this->
db->escape($this->ldap_sid).
"', ".((int) $this->entity).
")";
1562 $result = $this->
db->query($sql);
1564 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1566 $this->
id = $this->
db->last_insert_id($this->
db->prefix().
"user");
1570 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1571 $this->
db->rollback();
1575 if (!empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER) && !empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) {
1576 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1577 $langs->load(
"stocks");
1579 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1580 $entrepot->libelle = $entrepot->label;
1581 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1582 $entrepot->statut = 1;
1583 $entrepot->country_id = $mysoc->country_id;
1584 $warehouseid = $entrepot->create($user);
1586 $this->fk_warehouse = $warehouseid;
1590 $result = $this->
update($user, 1, 1);
1592 $this->
db->rollback();
1606 $this->
db->commit();
1611 $this->
db->rollback();
1615 $this->
error = $this->
db->lasterror();
1616 $this->
db->rollback();
1634 global $conf, $user, $langs;
1640 $this->civility_code = $contact->civility_code;
1641 $this->lastname = $contact->lastname;
1642 $this->firstname = $contact->firstname;
1643 $this->gender = $contact->gender;
1644 $this->email = $contact->email;
1645 $this->socialnetworks = $contact->socialnetworks;
1646 $this->office_phone = $contact->phone_pro;
1647 $this->office_fax = $contact->fax;
1648 $this->user_mobile = $contact->phone_mobile;
1649 $this->address = $contact->address;
1650 $this->zip = $contact->zip;
1651 $this->town = $contact->town;
1653 $this->state_id = $contact->state_id;
1654 $this->country_id = $contact->country_id;
1655 $this->employee = 0;
1657 if (empty($login)) {
1658 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1659 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1661 $this->login = $login;
1666 $result = $this->
create($user, 1);
1668 $sql =
"UPDATE ".$this->db->prefix().
"user";
1669 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1670 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1671 if ($contact->socid > 0) {
1672 $sql .=
", fk_soc=".((int) $contact->socid);
1674 $sql .=
" WHERE rowid=".((int) $this->
id);
1678 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1680 $this->context[
'createfromcontact'] =
'createfromcontact';
1685 $error++; $this->
db->rollback();
return -1;
1689 $this->
db->commit();
1692 $this->
error = $this->
db->error();
1694 $this->
db->rollback();
1699 dol_syslog(get_class($this).
"::create_from_contact - 0");
1701 $this->
db->rollback();
1718 global $conf, $user, $langs;
1722 $this->civility_code = $member->civility_id;
1723 $this->lastname = $member->lastname;
1724 $this->firstname = $member->firstname;
1725 $this->gender = $member->gender;
1726 $this->email = $member->email;
1727 $this->fk_member = $member->id;
1728 $this->address = $member->address;
1729 $this->zip = $member->zip;
1730 $this->town = $member->town;
1732 $this->state_id = $member->state_id;
1733 $this->country_id = $member->country_id;
1734 $this->socialnetworks = $member->socialnetworks;
1736 $this->pass = $member->pass;
1737 $this->pass_crypted = $member->pass_indatabase_crypted;
1739 if (empty($login)) {
1740 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1743 $this->login = $login;
1748 $result = $this->
create($user);
1750 if (!empty($this->pass)) {
1751 $newpass = $this->
setPassword($user, $this->pass);
1752 if (is_numeric($newpass) && $newpass < 0) {
1755 } elseif (!empty($this->pass_crypted)) {
1756 $sql =
"UPDATE ".$this->db->prefix().
"user";
1757 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
1758 $sql .=
" WHERE rowid=".((int) $this->
id);
1766 if ($result > 0 && $member->fk_soc) {
1767 $sql =
"UPDATE ".$this->db->prefix().
"user";
1768 $sql .=
" SET fk_soc=".((int) $member->fk_soc);
1769 $sql .=
" WHERE rowid=".((int) $this->
id);
1771 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
1774 $this->
db->commit();
1777 $this->
error = $this->
db->lasterror();
1779 $this->
db->rollback();
1786 $this->
db->commit();
1790 $this->
db->rollback();
1808 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
1809 $sql .=
" WHERE bydefault = 1";
1810 $sql .=
" AND entity = ".((int) $conf->entity);
1814 $num = $this->
db->num_rows(
$resql);
1817 $row = $this->
db->fetch_row(
$resql);
1825 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
1826 $result = $this->
db->query($sql);
1828 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
1829 $result = $this->
db->query($sql);
1849 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
1851 global $conf, $langs;
1853 $nbrowsaffected = 0;
1856 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
1859 $this->civility_code = trim((
string) $this->civility_code);
1860 $this->lastname = trim((
string) $this->lastname);
1861 $this->firstname = trim((
string) $this->firstname);
1862 $this->ref_employee = trim((
string) $this->ref_employee);
1863 $this->national_registration_number = trim((
string) $this->national_registration_number);
1864 $this->employee = ($this->employee > 0 ? $this->employee : 0);
1865 $this->login = trim((
string) $this->login);
1866 $this->gender = trim((
string) $this->gender);
1867 $this->pass = trim((
string) $this->pass);
1868 $this->api_key = trim((
string) $this->api_key);
1869 $this->address = trim((
string) $this->address);
1870 $this->zip = trim((
string) $this->zip);
1871 $this->town = trim((
string) $this->town);
1874 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
1875 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
1876 $this->office_phone = trim((
string) $this->office_phone);
1877 $this->office_fax = trim((
string) $this->office_fax);
1878 $this->user_mobile = trim((
string) $this->user_mobile);
1879 $this->personal_mobile = trim((
string) $this->personal_mobile);
1880 $this->email = trim((
string) $this->email);
1881 $this->personal_email = trim((
string) $this->personal_email);
1883 $this->job = trim((
string) $this->job);
1884 $this->signature = trim((
string) $this->signature);
1885 $this->note_public = trim((
string) $this->note_public);
1886 $this->note_private = trim((
string) $this->note_private);
1887 $this->openid = trim((
string) $this->openid);
1888 $this->admin = ($this->admin > 0 ? $this->admin : 0);
1890 $this->accountancy_code = trim((
string) $this->accountancy_code);
1891 $this->color = trim((
string) $this->color);
1892 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
1893 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
1894 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
1895 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
1896 $this->birth = empty($this->birth) ?
'' : $this->birth;
1897 $this->fk_warehouse = (int) $this->fk_warehouse;
1900 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1902 if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1903 $langs->load(
"errors");
1904 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1907 if (empty($this->login)) {
1908 $langs->load(
"errors");
1909 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
1911 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1912 $langs->load(
"errors");
1913 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName");
1920 if (!empty($this->oldcopy) && $this->oldcopy->login != $this->login) {
1921 $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).
"'";
1922 $resqltochecklogin = $this->
db->query($sqltochecklogin);
1923 if ($resqltochecklogin) {
1924 $objtochecklogin = $this->
db->fetch_object($resqltochecklogin);
1925 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1926 $langs->load(
"errors");
1927 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1929 $this->
db->rollback();
1934 if (!empty($this->oldcopy) && !empty($this->email) && $this->oldcopy->email != $this->email) {
1935 $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).
"'";
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(
"ErrorEmailAlreadyExists", $this->email);
1943 $this->
db->rollback();
1950 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
1951 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
1952 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
1953 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
1954 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
1955 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
1956 $sql .=
", employee = ".(int) $this->employee;
1957 $sql .=
", login = '".$this->db->escape($this->login).
"'";
1958 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape($this->api_key).
"'" :
"null");
1959 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
1960 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
1961 if (!empty($user->admin)) {
1962 $sql .=
", admin = ".(int) $this->admin;
1964 $sql .=
", address = '".$this->db->escape($this->address).
"'";
1965 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
1966 $sql .=
", town = '".$this->db->escape($this->town).
"'";
1967 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".$this->
db->escape($this->state_id).
"'" :
"null");
1968 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".$this->
db->escape($this->country_id).
"'" :
"null");
1969 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
1970 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
1971 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
1972 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
1973 $sql .=
", email = '".$this->db->escape($this->email).
"'";
1974 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
1975 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1976 $sql .=
", job = '".$this->db->escape($this->job).
"'";
1977 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
1978 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
1979 $sql .=
", color = '".$this->db->escape($this->color).
"'";
1980 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
1981 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
1982 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
1983 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
1984 $sql .=
", note = '".$this->db->escape($this->note_private).
"'";
1985 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
1986 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
1987 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
1988 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".$this->db->escape($this->fk_user).
"'" :
"null");
1989 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".$this->db->escape($this->fk_user_expense_validator).
"'" :
"null");
1990 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".$this->db->escape($this->fk_user_holiday_validator).
"'" :
"null");
1991 if (isset($this->thm) || $this->thm !=
'') {
1992 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
1994 if (isset($this->tjm) || $this->tjm !=
'') {
1995 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
1997 if (isset($this->salary) || $this->salary !=
'') {
1998 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
2000 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2001 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2003 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2004 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2005 $sql .=
", entity = ".((int) $this->entity);
2007 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2008 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2009 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2010 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2011 $sql .=
" WHERE rowid = ".((int) $this->
id);
2013 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2016 $nbrowsaffected += $this->
db->affected_rows(
$resql);
2019 if (!empty($this->pass)) {
2020 if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
2022 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass);
2030 if ($this->fk_member > 0) {
2031 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2032 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2035 $this->
error = $this->
db->error(); $this->
db->rollback();
return -5;
2039 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2040 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2043 $this->
error = $this->
db->error(); $this->
db->rollback();
return -5;
2046 if ($nbrowsaffected) {
2047 if ($this->fk_member > 0 && !$nosyncmember) {
2048 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2050 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2055 $result = $adh->fetch($this->fk_member);
2058 $adh->civility_code = $this->civility_code;
2059 $adh->firstname = $this->firstname;
2060 $adh->lastname = $this->lastname;
2061 $adh->login = $this->login;
2062 $adh->gender = $this->gender;
2063 $adh->birth = $this->birth;
2065 $adh->pass = $this->pass;
2067 $adh->address = $this->address;
2068 $adh->town = $this->town;
2069 $adh->zip = $this->zip;
2070 $adh->state_id = $this->state_id;
2071 $adh->country_id = $this->country_id;
2073 $adh->email = $this->email;
2075 $adh->socialnetworks = $this->socialnetworks;
2077 $adh->phone = $this->office_phone;
2078 $adh->phone_mobile = $this->user_mobile;
2080 $adh->user_id = $this->id;
2081 $adh->user_login = $this->login;
2083 $result = $adh->update($user, 0, 1, 0);
2085 $this->
error = $adh->error;
2086 $this->errors = $adh->errors;
2087 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2090 } elseif ($result < 0) {
2091 $this->
error = $adh->error;
2092 $this->errors = $adh->errors;
2097 if ($this->contact_id > 0 && !$nosynccontact) {
2098 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2100 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2104 $result = $tmpobj->fetch($this->contact_id);
2107 $tmpobj->civility_code = $this->civility_code;
2108 $tmpobj->firstname = $this->firstname;
2109 $tmpobj->lastname = $this->lastname;
2110 $tmpobj->login = $this->login;
2111 $tmpobj->gender = $this->gender;
2112 $tmpobj->birth = $this->birth;
2116 $tmpobj->email = $this->email;
2118 $tmpobj->socialnetworks = $this->socialnetworks;
2120 $tmpobj->phone_pro = $this->office_phone;
2121 $tmpobj->phone_mobile = $this->user_mobile;
2122 $tmpobj->fax = $this->office_fax;
2124 $tmpobj->address = $this->address;
2125 $tmpobj->town = $this->town;
2126 $tmpobj->zip = $this->zip;
2127 $tmpobj->state_id = $this->state_id;
2128 $tmpobj->country_id = $this->country_id;
2130 $tmpobj->user_id = $this->id;
2131 $tmpobj->user_login = $this->login;
2133 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2135 $this->
error = $tmpobj->error;
2136 $this->errors = $tmpobj->errors;
2137 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2141 $this->
error = $tmpobj->error;
2142 $this->errors = $tmpobj->errors;
2158 if (!$error && !$notrigger) {
2168 $this->
db->commit();
2169 return $nbrowsaffected;
2172 $this->
db->rollback();
2176 $this->
error = $this->
db->lasterror();
2177 $this->
db->rollback();
2196 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2197 $sql .=
" datepreviouslogin = datelastlogin,";
2198 $sql .=
" ippreviouslogin = iplastlogin,";
2199 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2200 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2201 $sql .=
" tms = tms";
2202 $sql .=
" WHERE rowid = ".((int) $this->
id);
2204 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2207 $this->datepreviouslogin = $this->datelastlogin;
2208 $this->datelastlogin = $now;
2209 $this->ippreviouslogin = $this->iplastlogin;
2210 $this->iplastlogin = $userremoteip;
2213 $this->
error = $this->
db->lasterror().
' sql='.$sql;
2230 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0)
2232 global $conf, $langs;
2233 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2237 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2245 if (empty($passwordalreadycrypted)) {
2246 if (!empty($conf->global->USER_PASSWORD_GENERATED)) {
2248 $modGeneratePassClass =
'modGeneratePass'.ucfirst($conf->global->USER_PASSWORD_GENERATED);
2250 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2251 if (class_exists($modGeneratePassClass)) {
2252 $modGeneratePass =
new $modGeneratePassClass($this->
db, $conf, $langs, $user);
2255 $modGeneratePass->WithoutAmbi = 0;
2258 $testpassword = $modGeneratePass->validatePassword($password);
2259 if (!$testpassword) {
2260 $this->
error = $modGeneratePass->error;
2268 $password_crypted =
dol_hash($password);
2272 if (!$changelater) {
2273 if (!is_object($this->oldcopy)) {
2274 $this->oldcopy = clone $this;
2279 $sql =
"UPDATE ".$this->db->prefix().
"user";
2280 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2281 $sql .=
" pass_temp = null";
2282 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
2283 $sql .=
", pass = null";
2285 $sql .=
", pass = '".$this->db->escape($password).
"'";
2287 $sql .=
" WHERE rowid = ".((int) $this->
id);
2289 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2290 $result = $this->
db->query($sql);
2292 if ($this->
db->affected_rows($result)) {
2293 $this->pass = $password;
2294 $this->pass_indatabase = $password;
2295 $this->pass_indatabase_crypted = $password_crypted;
2297 if ($this->fk_member && !$nosyncmember) {
2298 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2303 $result = $adh->fetch($this->fk_member);
2306 $result = $adh->setPassword($user, $this->pass, (empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1), 1);
2308 $this->
error = $adh->error;
2313 $this->
error = $adh->error;
2318 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2320 if (!$error && !$notrigger) {
2322 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2324 $error++; $this->
db->rollback();
return -1;
2329 $this->
db->commit();
2332 $this->
db->rollback();
2336 $this->
db->rollback();
2343 $sql =
"UPDATE ".$this->db->prefix().
"user";
2344 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2345 $sql .=
" WHERE rowid = ".((int) $this->
id);
2347 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2348 $result = $this->
db->query($sql);
2370 global $conf, $langs, $mysoc;
2371 global $dolibarr_main_url_root;
2373 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2380 $outputlangs =
new Translate(
"", $conf);
2382 if (isset($this->
conf->MAIN_LANG_DEFAULT)
2383 && $this->conf->MAIN_LANG_DEFAULT !=
'auto') {
2384 $outputlangs->getDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2387 if ($this->
conf->MAIN_LANG_DEFAULT) {
2388 $outputlangs->setDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2390 $outputlangs = $langs;
2394 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2396 $appli = constant(
'DOL_APPLICATION_TITLE');
2397 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
2398 $appli = $conf->global->MAIN_APPLICATION_TITLE;
2401 $subject =
'['.$mysoc->name.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2404 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2405 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2407 if (!$changelater) {
2408 $url = $urlwithroot.
'/';
2409 if (!empty($conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD))
2410 $url = $conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD;
2411 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2412 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2413 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2414 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2417 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2419 $mesg .= $user->getFullName($outputlangs);
2421 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2423 global $dolibarr_main_instance_unique_id;
2426 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2427 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.$dolibarr_main_instance_unique_id));
2428 if (!empty($conf->multicompany->enabled)) {
2429 $url .=
'&entity='.(!empty($this->entity) ? $this->entity : 1);
2434 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2435 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2436 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2437 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2439 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2440 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2441 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2443 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2446 $trackid =
'use'.$this->id;
2451 $conf->global->MAIN_MAIL_EMAIL_FROM,
2465 if ($mailfile->sendfile()) {
2468 $langs->trans(
"errors");
2469 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2481 return $this->error;
2494 $sql =
"SELECT url, login, pass, poste ";
2495 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2496 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2501 $obj = $this->
db->fetch_object(
$resql);
2503 $this->clicktodial_url = $obj->url;
2504 $this->clicktodial_login = $obj->login;
2505 $this->clicktodial_password = $obj->pass;
2506 $this->clicktodial_poste = $obj->poste;
2509 $this->clicktodial_loaded = 1;
2514 $this->
error = $this->
db->error();
2530 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2531 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2533 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2534 $result = $this->
db->query($sql);
2536 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2537 $sql .=
" (fk_user,url,login,pass,poste)";
2538 $sql .=
" VALUES (".$this->id;
2539 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2540 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2541 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2542 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2544 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2545 $result = $this->
db->query($sql);
2547 $this->
db->commit();
2550 $this->
db->rollback();
2551 $this->
error = $this->
db->lasterror();
2569 global $conf, $langs, $user;
2575 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2576 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2577 $sql .=
" AND fk_usergroup = ".((int) $group);
2578 $sql .=
" AND entity = ".((int) $entity);
2580 $result = $this->
db->query($sql);
2582 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2583 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2585 $result = $this->
db->query($sql);
2587 if (!$error && !$notrigger) {
2588 $this->newgroupid = $group;
2589 $this->context = array(
'audit'=>$langs->trans(
"UserSetInGroup"),
'newgroupid'=>$group);
2600 $this->
db->commit();
2604 $this->
db->rollback();
2608 $this->
error = $this->
db->lasterror();
2609 $this->
db->rollback();
2626 global $conf, $langs, $user;
2632 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2633 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2634 $sql .=
" AND fk_usergroup = ".((int) $group);
2635 $sql .=
" AND entity = ".((int) $entity);
2637 $result = $this->
db->query($sql);
2639 if (!$error && !$notrigger) {
2640 $this->oldgroupid = $group;
2641 $this->context = array(
'audit'=>$langs->trans(
"UserRemovedFromGroup"),
'oldgroupid'=>$group);
2652 $this->
db->commit();
2655 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2656 $this->
db->rollback();
2660 $this->
error = $this->
db->lasterror();
2661 $this->
db->rollback();
2677 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
2679 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2680 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
2701 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
2703 global $langs, $conf, $db, $hookmanager, $user;
2704 global $dolibarr_main_authentication, $dolibarr_main_demo;
2705 global $menumanager;
2707 if (!$user->rights->user->user->lire && $user->id != $this->id) {
2711 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) {
2715 $result =
''; $label =
'';
2718 if (!empty($this->photo)) {
2719 $label .=
'<div class="photointooltip floatright">';
2720 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
2726 $label .=
'<div class="centpercent">';
2727 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u>';
2728 $label .=
' '.$this->getLibStatut(4);
2730 if (!empty($this->login)) {
2733 if (!empty($this->job)) {
2737 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
2738 $phonelist = array();
2739 if ($this->office_phone) {
2740 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2742 if ($this->office_fax) {
2743 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2745 if ($this->user_mobile) {
2746 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
2748 $label .=
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
2750 if (!empty($this->admin)) {
2751 $label .=
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
2753 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
2754 $label .=
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
2757 if (!empty($this->socid)) {
2758 $thirdpartystatic =
new Societe($db);
2759 $thirdpartystatic->fetch($this->socid);
2760 if (empty($hidethirdpartylogo)) {
2761 $companylink =
' '.$thirdpartystatic->getNomUrl(2, (($option ==
'nolink') ?
'nolink' :
''));
2765 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
2766 $label .=
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
2768 if ($infologin > 0) {
2770 $label .=
'<br><u>'.$langs->trans(
"Session").
'</u>';
2772 if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) {
2773 $label .=
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.$conf->entity.
' (User entity '.$this->entity.
')';
2775 $label .=
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
2776 $label .=
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
2777 $label .=
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
2779 $label .=
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
2781 $label .=
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
2782 $label .=
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag($conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
2783 $label .=
'<br><b>'.$langs->trans(
"Layout").
':</b> '.
dol_string_nohtmltag($conf->browser->layout);
2784 $label .=
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
2785 if ($conf->browser->layout ==
'phone') {
2786 $label .=
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
2788 if (!empty($_SESSION[
"disablemodules"])) {
2789 $label .=
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(join(
', ', explode(
',', $_SESSION[
"disablemodules"])));
2792 if ($infologin < 0) {
2796 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
2797 if ($option ==
'leave') {
2798 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
2801 if ($option !=
'nolink') {
2803 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2804 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2805 $add_save_lastsearch_values = 1;
2807 if ($add_save_lastsearch_values) {
2808 $url .=
'&save_lastsearch_values=1';
2812 $linkstart =
'<a href="'.$url.
'"';
2814 if (empty($notooltip)) {
2815 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2816 $langs->load(
"users");
2817 $label = $langs->trans(
"ShowUser");
2818 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2820 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
2821 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
2824 $linkstart .= $linkclose.
'>';
2828 $result .= (($option ==
'nolink') ?
'' : $linkstart);
2829 if ($withpictoimg) {
2830 $paddafterimage =
'';
2831 if (abs((
int) $withpictoimg) == 1) {
2832 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
2835 if ($withpictoimg > 0) {
2836 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
2839 $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>';
2843 if ($withpictoimg > -2 && $withpictoimg != 2) {
2844 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2845 $result .=
'<span class="nopadding usertext'.((!isset($this->statut) || $this->statut) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
2847 if ($mode ==
'login') {
2852 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2853 $result .=
'</span>';
2856 $result .= (($option ==
'nolink') ?
'' : $linkend);
2859 $result .= $companylink;
2862 $hookmanager->initHooks(array(
'userdao'));
2863 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
2864 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2866 $result = $hookmanager->resPrint;
2868 $result .= $hookmanager->resPrint;
2883 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
2885 global $langs, $user;
2889 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2893 if ((!$user->rights->user->user->lire && $this->id != $user->id)) {
2897 if ($option ==
'xxx') {
2898 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2902 if ($option ==
'nolink') {
2907 $result .= $linkstart;
2908 if ($withpictoimg) {
2909 $paddafterimage =
'';
2910 if (abs($withpictoimg) == 1) {
2911 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
2914 if ($withpictoimg > 0) {
2915 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
2918 $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>';
2922 $result .= $this->login;
2923 $result .= $linkend;
2936 return $this->
LibStatut(isset($this->statut) ? (
int) $this->statut : (
int) $this->status, $mode);
2952 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2955 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
2956 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
2957 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
2958 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
2961 $statusType =
'status5';
2962 if ($status == self::STATUS_ENABLED) {
2963 $statusType =
'status4';
2966 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
2978 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2979 $return .=
'<div class="info-box info-box-sm">';
2980 $return .=
'<span class="info-box-icon bg-infobox-action">';
2983 if (!empty($this->photo)) {
2985 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
2994 $return .=
'</span>';
2995 $return .=
'<div class="info-box-content">';
2996 $return .=
'<span class="info-box-ref">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
2997 if (property_exists($this,
'label')) {
2998 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
3001 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->email.
'</span>';
3003 if (method_exists($this,
'getLibStatut')) {
3004 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(5).
'</div>';
3006 $return .=
'</div>';
3007 $return .=
'</div>';
3008 $return .=
'</div>';
3031 $dn = $conf->global->LDAP_KEY_USERS.
"=".$info[$conf->global->LDAP_KEY_USERS].
",".$conf->global->LDAP_USER_DN;
3032 } elseif ($mode == 1) {
3033 $dn = $conf->global->LDAP_USER_DN;
3034 } elseif ($mode == 2) {
3035 $dn = $conf->global->LDAP_KEY_USERS.
"=".$info[$conf->global->LDAP_KEY_USERS];
3050 global $conf, $langs;
3056 $keymodified =
false;
3059 $info[
"objectclass"] = explode(
',', $conf->global->LDAP_USER_OBJECT_CLASS);
3065 'LDAP_FIELD_FULLNAME' =>
'fullname',
3066 'LDAP_FIELD_NAME' =>
'lastname',
3067 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3068 'LDAP_FIELD_LOGIN' =>
'login',
3069 'LDAP_FIELD_LOGIN_SAMBA'=>
'login',
3070 'LDAP_FIELD_PHONE' =>
'office_phone',
3071 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3072 'LDAP_FIELD_FAX' =>
'office_fax',
3073 'LDAP_FIELD_MAIL' =>
'email',
3074 'LDAP_FIELD_SID' =>
'ldap_sid',
3078 foreach ($ldapkey as $constname => $varname) {
3079 if (!empty($this->$varname) && !empty($conf->global->$constname)) {
3080 $info[$conf->global->$constname] = $this->$varname;
3083 if (!empty($conf->global->LDAP_KEY_USERS) && $conf->global->LDAP_KEY_USERS == $conf->global->$constname) {
3084 if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
3085 $keymodified =
true;
3090 foreach ($socialnetworks as $key => $value) {
3091 if (!empty($this->socialnetworks[$value[
'label']]) && !empty($conf->global->{
'LDAP_FIELD_'.strtoupper($value[
'label'])})) {
3092 $info[$conf->global->{
'LDAP_FIELD_'.strtoupper($value[
'label'])}] = $this->socialnetworks[$value[
'label']];
3095 if ($this->address && !empty($conf->global->LDAP_FIELD_ADDRESS)) {
3096 $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->address;
3098 if ($this->zip && !empty($conf->global->LDAP_FIELD_ZIP)) {
3099 $info[$conf->global->LDAP_FIELD_ZIP] = $this->zip;
3101 if ($this->town && !empty($conf->global->LDAP_FIELD_TOWN)) {
3102 $info[$conf->global->LDAP_FIELD_TOWN] = $this->town;
3104 if ($this->note_public && !empty($conf->global->LDAP_FIELD_DESCRIPTION)) {
3107 if ($this->socid > 0) {
3109 $soc->fetch($this->socid);
3111 $info[$conf->global->LDAP_FIELD_COMPANY] = $soc->name;
3112 if ($soc->client == 1) {
3113 $info[
"businessCategory"] =
"Customers";
3115 if ($soc->client == 2) {
3116 $info[
"businessCategory"] =
"Prospects";
3118 if ($soc->fournisseur == 1) {
3119 $info[
"businessCategory"] =
"Suppliers";
3124 if (!empty($this->pass)) {
3125 if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
3126 $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass;
3128 if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3129 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass,
'openldap');
3131 } elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !==
'3') {
3134 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
3136 if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) {
3137 if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3138 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dolGetLdapPasswordHash($this->pass_indatabase_crypted,
'md5frommd5');
3141 } elseif (!empty($this->pass_indatabase)) {
3143 if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
3144 $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass_indatabase;
3146 if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3147 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass_indatabase,
'openldap');
3152 if ($conf->global->LDAP_SERVER_TYPE ==
'egroupware') {
3153 $info[
"objectclass"][4] =
"phpgwContact";
3155 $info[
'uidnumber'] = $this->id;
3157 $info[
'phpgwTz'] = 0;
3158 $info[
'phpgwMailType'] =
'INTERNET';
3159 $info[
'phpgwMailHomeType'] =
'INTERNET';
3161 $info[
"phpgwContactTypeId"] =
'n';
3162 $info[
"phpgwContactCatId"] = 0;
3163 $info[
"phpgwContactAccess"] =
"public";
3166 $this->egroupware_id = 1;
3169 $info[
"phpgwContactOwner"] = $this->egroupware_id;
3172 $info[
"rfc822Mailbox"] = $this->email;
3174 if ($this->phone_mobile) {
3175 $info[
"phpgwCellTelephoneNumber"] = $this->phone_mobile;
3179 if (!empty($conf->global->LDAP_FIELD_USERID)) {
3180 $info[$conf->global->LDAP_FIELD_USERID] = $this->id;
3182 if (!empty($conf->global->LDAP_FIELD_GROUPID)) {
3184 $groupslist = $usergroup->listGroupsForUser($this->
id);
3185 $info[$conf->global->LDAP_FIELD_GROUPID] =
'65534';
3186 if (!empty($groupslist)) {
3187 foreach ($groupslist as $groupforuser) {
3188 $info[$conf->global->LDAP_FIELD_GROUPID] = $groupforuser->id;
3193 if (!empty($conf->global->LDAP_FIELD_HOMEDIRECTORY) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX)) {
3194 $info[$conf->global->LDAP_FIELD_HOMEDIRECTORY] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->login";
3210 global $user, $langs;
3216 $this->
ref =
'SPECIMEN';
3217 $this->specimen = 1;
3219 $this->lastname =
'DOLIBARR';
3220 $this->firstname =
'SPECIMEN';
3221 $this->gender =
'man';
3222 $this->note_public =
'This is a note public';
3223 $this->note_private =
'This is a note private';
3224 $this->email =
'email@specimen.com';
3225 $this->personal_email =
'personalemail@specimen.com';
3226 $this->socialnetworks = array(
3227 'skype' =>
'skypepseudo',
3228 'twitter' =>
'twitterpseudo',
3229 'facebook' =>
'facebookpseudo',
3230 'linkedin' =>
'linkedinpseudo',
3232 $this->office_phone =
'0999999999';
3233 $this->office_fax =
'0999999998';
3234 $this->user_mobile =
'0999999997';
3235 $this->personal_mobile =
'0999999996';
3237 $this->login =
'dolibspec';
3238 $this->pass =
'dolibSpec+@123';
3241 $this->datec = $now;
3242 $this->datem = $now;
3244 $this->datelastlogin = $now;
3245 $this->iplastlogin =
'127.0.0.1';
3246 $this->datepreviouslogin = $now;
3247 $this->ippreviouslogin =
'127.0.0.1';
3262 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
3263 $sql .=
" u.tms as date_modification, u.entity";
3264 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3265 $sql .=
" WHERE u.rowid = ".((int) $id);
3267 $result = $this->
db->query($sql);
3269 if ($this->
db->num_rows($result)) {
3270 $obj = $this->
db->fetch_object($result);
3272 $this->
id = $obj->rowid;
3274 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3275 $this->date_creation = $this->db->jdate($obj->datec);
3276 $this->date_modification = $this->
db->jdate($obj->date_modification);
3277 $this->entity = $obj->entity;
3280 $this->
db->free($result);
3294 $sql =
"SELECT count(mc.email) as nb";
3295 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3296 $sql .=
" WHERE mc.email = '".$this->db->escape($this->email).
"'";
3297 $sql .=
" AND mc.statut NOT IN (-1,0)";
3301 $obj = $this->
db->fetch_object(
$resql);
3307 $this->error = $this->
db->error();
3324 $sql =
"SELECT count(rowid) as nb";
3325 $sql .=
" FROM ".$this->db->prefix().
"user";
3326 if ($option ==
'superadmin') {
3327 $sql .=
" WHERE entity = 0";
3329 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3330 if ($limitTo ==
'active') {
3331 $sql .=
" AND statut = 1";
3335 $sql .=
" AND admin = ".(int) $admin;
3340 $obj = $this->
db->fetch_object(
$resql);
3341 $nb = (int) $obj->nb;
3346 $this->error = $this->
db->lasterror();
3362 global $user, $conf;
3366 $this->firstname = $ldapuser->{$conf->global->LDAP_FIELD_FIRSTNAME};
3367 $this->lastname = $ldapuser->{$conf->global->LDAP_FIELD_NAME};
3368 $this->login = $ldapuser->{$conf->global->LDAP_FIELD_LOGIN};
3369 $this->pass = $ldapuser->{$conf->global->LDAP_FIELD_PASSWORD};
3370 $this->pass_indatabase_crypted = $ldapuser->{$conf->global->LDAP_FIELD_PASSWORD_CRYPTED};
3372 $this->office_phone = $ldapuser->{$conf->global->LDAP_FIELD_PHONE};
3373 $this->user_mobile = $ldapuser->{$conf->global->LDAP_FIELD_MOBILE};
3374 $this->office_fax = $ldapuser->{$conf->global->LDAP_FIELD_FAX};
3375 $this->email = $ldapuser->{$conf->global->LDAP_FIELD_MAIL};
3376 foreach ($socialnetworks as $key => $value) {
3377 $tmpkey =
'LDAP_FIELD_'.strtoupper($value[
'label']);
3378 $this->socialnetworks[$value[
'label']] = $ldapuser->{$conf->global->$tmpkey};
3380 $this->ldap_sid = $ldapuser->{$conf->global->LDAP_FIELD_SID};
3382 $this->job = $ldapuser->{$conf->global->LDAP_FIELD_TITLE};
3383 $this->note_public = $ldapuser->{$conf->global->LDAP_FIELD_DESCRIPTION};
3385 $result = $this->update($user);
3387 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3403 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3404 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3406 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3407 $res = $this->
db->query($sql);
3410 while ($rec = $this->
db->fetch_array($res)) {
3411 $user =
new User($this->
db);
3412 $user->fetch($rec[
'rowid']);
3432 $this->parentof = array();
3435 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3436 $sql .=
" FROM ".$this->db->prefix().
"user";
3437 $sql .=
" WHERE fk_user <> 0";
3438 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3440 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3443 while ($obj = $this->
db->fetch_object(
$resql)) {
3444 $this->parentof[$obj->id_son] = $obj->id_parent;
3470 global $conf, $user;
3471 global $hookmanager;
3474 $hookmanager->initHooks(array(
'userdao'));
3476 $this->users = array();
3479 $this->loadParentOf();
3482 $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";
3483 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3485 $parameters = array();
3486 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3488 $sql .= $hookmanager->resPrint;
3490 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3493 $sql .=
" AND ".$filter;
3496 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3500 while ($obj = $this->
db->fetch_object(
$resql)) {
3501 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3502 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3503 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3504 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3505 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3506 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3507 $this->users[$obj->rowid][
'login'] = $obj->login;
3508 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3509 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3510 $this->users[$obj->rowid][
'email'] = $obj->email;
3511 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3512 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3513 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3522 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3523 foreach ($this->users as $key => $val) {
3524 $result = $this->build_path_from_id_user($key, 0);
3526 $this->error =
'ErrorLoopInHierarchy';
3532 if ($deleteafterid) {
3534 $keyfilter1 =
'^'.$deleteafterid.
'$';
3535 $keyfilter2 =
'_'.$deleteafterid.
'$';
3536 $keyfilter3 =
'^'.$deleteafterid.
'_';
3537 $keyfilter4 =
'_'.$deleteafterid.
'_';
3538 foreach ($this->users as $key => $val) {
3539 if (preg_match(
'/'.$keyfilter1.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter2.
'/', $val[
'fullpath'])
3540 || preg_match(
'/'.$keyfilter3.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter4.
'/', $val[
'fullpath'])) {
3541 unset($this->users[$key]);
3546 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
3547 $this->users =
dol_sort_array($this->users,
'fullname',
'asc',
true,
false);
3551 return $this->users;
3564 $childids = array();
3566 if (isset($this->cache_childids[$this->
id])) {
3567 $childids = $this->cache_childids[$this->id];
3570 $this->get_full_tree();
3572 $idtoscan = $this->id;
3574 dol_syslog(
"Build childid for id = ".$idtoscan);
3575 foreach ($this->users as $id => $val) {
3577 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
3578 $childids[$val[
'id']] = $val[
'id'];
3582 $this->cache_childids[$this->id] = $childids;
3584 if ($addcurrentuser) {
3585 $childids[$this->id] = $this->id;
3605 if (!empty($this->users[$id_user][
'fullpath'])) {
3607 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
3612 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
3613 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
3614 $i = 0; $cursor_user = $id_user;
3616 $useridfound = array($id_user);
3617 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
3618 if (in_array($this->parentof[$cursor_user], $useridfound)) {
3619 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
3622 $useridfound[] = $this->parentof[$cursor_user];
3623 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
3624 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
3625 $i++; $cursor_user = $this->parentof[$cursor_user];
3629 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
3663 $this->nb = array();
3665 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
3666 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3667 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
3668 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
3669 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
3670 $sql .=
" AND ug.fk_user = u.rowid";
3672 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3674 $sql .=
" AND u.statut > 0";
3679 while ($obj = $this->
db->fetch_object(
$resql)) {
3680 $this->nb[
"users"] = $obj->nb;
3686 $this->error = $this->
db->error();
3702 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3704 global $conf, $user, $langs;
3706 $langs->load(
"user");
3710 if (!empty($conf->global->USER_ADDON_PDF)) {
3711 $modele = $conf->global->USER_ADDON_PDF;
3713 $modele =
'bluesky';
3717 $modelpath =
"core/modules/user/doc/";
3719 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3733 $user_property =
'';
3735 if (empty($rowid)) {
3739 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
3740 $sql .=
" FROM ".$this->db->prefix().
"user";
3741 $sql .=
" WHERE rowid = ".((int) $rowid);
3745 $nump = $this->
db->num_rows(
$resql);
3748 $obj = $this->
db->fetch_object(
$resql);
3750 if ($mode ==
'email') {
3751 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
3752 } elseif ($mode ==
'mobile') {
3753 $user_property = $obj->user_mobile;
3756 return $user_property;
3774 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter = array(), $filtermode =
'AND', $entityfilter =
false)
3776 global $conf, $user;
3778 $sql =
"SELECT t.rowid";
3779 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
3781 if ($entityfilter) {
3782 if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
3783 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
3784 $sql .=
" WHERE t.entity IS NOT NULL";
3786 $sql .=
",".$this->db->prefix().
"usergroup_user as ug";
3787 $sql .=
" WHERE ((ug.fk_user = t.rowid";
3788 $sql .=
" AND ug.entity IN (".getEntity(
'usergroup').
"))";
3789 $sql .=
" OR t.entity = 0)";
3792 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
3795 $sql .=
" WHERE 1 = 1";
3799 $sqlwhere = array();
3800 if (!empty($filter)) {
3801 foreach ($filter as $key => $value) {
3802 if ($key ==
't.rowid') {
3803 $sqlwhere[] = $key.
" = ".((int) $value);
3804 } elseif (isset($this->fields[$key][
'type']) && in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
3805 $sqlwhere[] = $key.
" = '".$this->
db->idate($value).
"'";
3806 } elseif ($key ==
'customsql') {
3807 $sqlwhere[] = $value;
3809 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
3813 if (count($sqlwhere) > 0) {
3814 $sql .=
' AND ('.implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere).
')';
3816 $sql .= $this->
db->order($sortfield, $sortorder);
3818 $sql .= $this->
db->plimit($limit + 1, $offset);
3825 $this->users = array();
3826 $num = $this->
db->num_rows(
$resql);
3828 while ($obj = $this->
db->fetch_object(
$resql)) {
3829 $line =
new self($this->db);
3830 $result = $line->fetch($obj->rowid);
3831 if ($result > 0 && !empty($line->id)) {
3832 $this->users[$obj->rowid] = clone $line;
3839 $this->errors[] = $this->
db->lasterror();
3851 private $findUserIdByEmailCache;
3865 if (isset($this->findUserIdByEmailCache[$email])) {
3866 return $this->findUserIdByEmailCache[$email];
3869 $this->findUserIdByEmailCache[$email] = -1;
3873 $sql =
'SELECT rowid';
3874 $sql .=
' FROM '.$this->db->prefix().
'user';
3875 if (!empty($conf->global->AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR)) {
3876 $sql .=
" WHERE email LIKE '%".$this->db->escape($email).
"%'";
3878 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
3887 $obj = $this->
db->fetch_object(
$resql);
3892 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
3894 return $this->findUserIdByEmailCache[$email];