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 'inventory' =>
'stock',
720 'invoice' =>
'facture',
721 'invoice_supplier' =>
'fournisseur',
722 'order_supplier' =>
'fournisseur',
723 'knowledgerecord' =>
'knowledgerecord@knowledgemanagement',
724 'skill@hrm' =>
'all@hrm',
725 'job@hrm' =>
'all@hrm',
726 'position@hrm' =>
'all@hrm',
727 'facturerec' =>
'facture'
730 if (!empty($moduletomoduletouse[$module])) {
731 $module = $moduletomoduletouse[$module];
734 $moduleRightsMapping = array(
735 'product' =>
'produit',
738 $rightsPath = $module;
739 if (!empty($moduleRightsMapping[$rightsPath])) {
740 $rightsPath = $moduleRightsMapping[$rightsPath];
744 $tmp = explode(
'@', $rightsPath, 2);
745 if (! empty($tmp[1])) {
746 if (strpos($module,
'@') !==
false) $module = $tmp[1];
747 $rightsPath = $tmp[1];
748 $permlevel2 = $permlevel1;
749 $permlevel1 = $tmp[0];
754 if (!in_array($module, $conf->modules)) {
759 if ($permlevel1 ==
'propale') {
760 $permlevel1 =
'propal';
762 if ($permlevel1 ==
'member') {
763 $permlevel1 =
'adherent';
765 if ($permlevel1 ==
'recruitmentcandidature') {
766 $permlevel1 =
'recruitmentjobposition';
770 if (empty($rightsPath) || empty($this->rights) || empty($this->rights->$rightsPath) || empty($permlevel1)) {
775 if (!empty($this->rights->$rightsPath->$permlevel1)) {
776 if (!empty($this->rights->$rightsPath->$permlevel1->$permlevel2)) {
777 return $this->rights->$rightsPath->$permlevel1->$permlevel2;
781 if ($permlevel2 ==
'read' && !empty($this->rights->$rightsPath->$permlevel1->lire)) {
782 return $this->rights->$rightsPath->$permlevel1->lire;
784 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->creer)) {
785 return $this->rights->$rightsPath->$permlevel1->creer;
787 if ($permlevel2 ==
'write' && !empty($this->rights->$rightsPath->$permlevel1->create)) {
788 return $this->rights->$rightsPath->$permlevel1->create;
790 if ($permlevel2 ==
'delete' && !empty($this->rights->$rightsPath->$permlevel1->supprimer)) {
791 return $this->rights->$rightsPath->$permlevel1->supprimer;
795 if (!empty($this->rights->$rightsPath->$permlevel1)) {
796 return $this->rights->$rightsPath->$permlevel1;
800 if ($permlevel1 ==
'read' && !empty($this->rights->$rightsPath->lire)) {
801 return $this->rights->$rightsPath->lire;
803 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->creer)) {
804 return $this->rights->$rightsPath->creer;
806 if ($permlevel1 ==
'write' && !empty($this->rights->$rightsPath->create)) {
807 return $this->rights->$rightsPath->create;
809 if ($permlevel1 ==
'delete' && !empty($this->rights->$rightsPath->supprimer)) {
810 return $this->rights->$rightsPath->supprimer;
828 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
830 global $conf, $user, $langs;
832 $entity = (empty($entity) ? $conf->entity : $entity);
834 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity, $notrigger for user id=".$this->
id);
842 $module = $perms = $subperms =
'';
845 $sql =
"SELECT module, perms, subperms";
846 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
847 $sql .=
" WHERE id = ".((int) $rid);
848 $sql .=
" AND entity = ".((int) $entity);
850 $result = $this->
db->query($sql);
852 $obj = $this->
db->fetch_object($result);
855 $module = $obj->module;
856 $perms = $obj->perms;
857 $subperms = $obj->subperms;
865 $whereforadd =
"id=".((int) $rid);
867 if (!empty($subperms)) {
868 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->
db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
869 } elseif (!empty($perms)) {
870 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
876 if (!empty($allmodule)) {
877 if ($allmodule ==
'allmodules') {
878 $whereforadd =
'allmodules';
880 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
881 if (!empty($allperms)) {
882 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
889 if (!empty($whereforadd)) {
892 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
893 $sql .=
" WHERE entity = ".((int) $entity);
894 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
895 $sql .=
" AND (".$whereforadd.
")";
898 $result = $this->
db->query($sql);
900 $num = $this->
db->num_rows($result);
903 $obj = $this->
db->fetch_object($result);
908 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id).
" AND fk_id = ".((int) $nid).
" AND entity = ".((int) $entity);
909 if (!$this->
db->query($sql)) {
912 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (entity, fk_user, fk_id) VALUES (".((int) $entity).
", ".((int) $this->
id).
", ".((int) $nid).
")";
913 if (!$this->
db->query($sql)) {
926 if (!$error && !$notrigger) {
927 $langs->load(
"other");
928 $this->context = array(
'audit'=>$langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
939 $this->
db->rollback();
959 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
961 global $conf, $user, $langs;
965 $entity = (!empty($entity) ? $entity : $conf->entity);
970 $module = $perms = $subperms =
'';
974 $sql =
"SELECT module, perms, subperms";
975 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
976 $sql .=
" WHERE id = '".$this->db->escape($rid).
"'";
977 $sql .=
" AND entity = ".((int) $entity);
979 $result = $this->
db->query($sql);
981 $obj = $this->
db->fetch_object($result);
984 $module = $obj->module;
985 $perms = $obj->perms;
986 $subperms = $obj->subperms;
994 $wherefordel =
"id=".((int) $rid);
996 if ($subperms ==
'lire' || $subperms ==
'read') {
997 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->
db->escape($perms).
"' AND subperms IS NOT NULL)";
999 if ($perms ==
'lire' || $perms ==
'read') {
1000 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
1005 if (!empty($allmodule)) {
1006 if ($allmodule ==
'allmodules') {
1007 $wherefordel =
'allmodules';
1009 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
1010 if (!empty($allperms)) {
1011 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
1018 if (!empty($wherefordel)) {
1021 $sql .=
" FROM ".$this->db->prefix().
"rights_def";
1022 $sql .=
" WHERE entity = ".((int) $entity);
1023 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
1024 $sql .=
" AND (".$wherefordel.
")";
1028 if ($this->admin == 1) {
1029 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
1030 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
1031 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
1032 $sql .=
" AND id NOT IN (358)";
1035 $result = $this->
db->query($sql);
1037 $num = $this->
db->num_rows($result);
1040 $obj = $this->
db->fetch_object($result);
1043 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights";
1044 $sql .=
" WHERE fk_user = ".((int) $this->
id).
" AND fk_id = ".((int) $nid);
1045 $sql .=
" AND entity = ".((int) $entity);
1046 if (!$this->
db->query($sql)) {
1058 if (!$error && !$notrigger) {
1059 $langs->load(
"other");
1060 $this->context = array(
'audit'=>$langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
1071 $this->
db->rollback();
1074 $this->
db->commit();
1088 dol_syslog(get_class($this).
"::clearrights reset user->rights");
1089 $this->rights = null;
1090 $this->nb_rights = 0;
1091 $this->all_permissions_are_loaded = 0;
1092 $this->_tab_loaded = array();
1104 public function getrights($moduletag =
'', $forcereload = 0)
1108 if (empty($forcereload)) {
1109 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
1114 if (!empty($this->all_permissions_are_loaded)) {
1121 if (!isset($this->rights) || !is_object($this->rights)) {
1122 $this->rights =
new stdClass();
1124 if (!isset($this->rights->user) || !is_object($this->rights->user)) {
1125 $this->rights->user =
new stdClass();
1131 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1132 $sql .=
" FROM ".$this->db->prefix().
"user_rights as ur,";
1133 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1134 $sql .=
" WHERE r.id = ur.fk_id";
1135 if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
1137 $sql .=
" AND r.entity IN (0,".(!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ?
"1," :
"").$conf->entity.
")";
1141 $sql .=
" AND r.entity = ".((int) $conf->entity).
" AND ur.entity = ".((int) $conf->entity);
1143 $sql .=
" AND ur.fk_user= ".((int) $this->
id);
1144 $sql .=
" AND r.perms IS NOT NULL";
1146 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1151 $num = $this->
db->num_rows(
$resql);
1154 $obj = $this->
db->fetch_object(
$resql);
1157 $module = $obj->module;
1158 $perms = $obj->perms;
1159 $subperms = $obj->subperms;
1161 if (!empty($perms)) {
1162 if (!empty($module)) {
1163 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1164 $this->rights->$module =
new stdClass();
1166 if (!empty($subperms)) {
1167 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1168 $this->rights->$module->$perms =
new stdClass();
1170 if (empty($this->rights->$module->$perms->$subperms)) {
1173 $this->rights->$module->$perms->$subperms = 1;
1175 if (empty($this->rights->$module->$perms)) {
1178 $this->rights->$module->$perms = 1;
1189 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1190 $sql .=
" FROM ".$this->db->prefix().
"usergroup_rights as gr,";
1191 $sql .=
" ".$this->db->prefix().
"usergroup_user as gu,";
1192 $sql .=
" ".$this->db->prefix().
"rights_def as r";
1193 $sql .=
" WHERE r.id = gr.fk_id";
1194 if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
1195 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1196 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1198 $sql .=
" AND r.entity = ".((int) $conf->entity);
1201 $sql .=
" AND gr.entity = ".((int) $conf->entity);
1205 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1206 $sql .=
" AND r.entity = ".((int) $conf->entity);
1208 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1209 $sql .=
" AND gu.fk_user = ".((int) $this->
id);
1210 $sql .=
" AND r.perms IS NOT NULL";
1212 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1217 $num = $this->
db->num_rows(
$resql);
1220 $obj = $this->
db->fetch_object(
$resql);
1223 $module = $obj->module;
1224 $perms = $obj->perms;
1225 $subperms = $obj->subperms;
1227 if (!empty($perms)) {
1228 if (!empty($module)) {
1229 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1230 $this->rights->$module =
new stdClass();
1232 if (!empty($subperms)) {
1233 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1234 $this->rights->$module->$perms =
new stdClass();
1236 if (empty($this->rights->$module->$perms->$subperms)) {
1239 $this->rights->$module->$perms->$subperms = 1;
1241 if (empty($this->rights->$module->$perms)) {
1245 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1246 $this->rights->$module->$perms = 1;
1258 if (!empty($this->admin)) {
1259 if (empty($this->rights->user->user)) {
1260 $this->rights->user->user =
new stdClass();
1262 $listofpermtotest = array(
'lire',
'creer',
'password',
'supprimer',
'export');
1263 foreach ($listofpermtotest as $permtotest) {
1264 if (empty($this->rights->user->user->$permtotest)) {
1265 $this->rights->user->user->$permtotest = 1;
1269 if (empty($this->rights->user->self)) {
1270 $this->rights->user->self =
new stdClass();
1272 $listofpermtotest = array(
'creer',
'password');
1273 foreach ($listofpermtotest as $permtotest) {
1274 if (empty($this->rights->user->self->$permtotest)) {
1275 $this->rights->user->self->$permtotest = 1;
1280 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
1281 if (empty($this->rights->user->user_advance)) {
1282 $this->rights->user->user_advance =
new stdClass();
1284 $listofpermtotest = array(
'readperms',
'write');
1285 foreach ($listofpermtotest as $permtotest) {
1286 if (empty($this->rights->user->user_advance->$permtotest)) {
1287 $this->rights->user->user_advance->$permtotest = 1;
1291 if (empty($this->rights->user->self_advance)) {
1292 $this->rights->user->self_advance =
new stdClass();
1294 $listofpermtotest = array(
'readperms',
'writeperms');
1295 foreach ($listofpermtotest as $permtotest) {
1296 if (empty($this->rights->user->self_advance->$permtotest)) {
1297 $this->rights->user->self_advance->$permtotest = 1;
1301 if (empty($this->rights->user->group_advance)) {
1302 $this->rights->user->group_advance =
new stdClass();
1304 $listofpermtotest = array(
'read',
'readperms',
'write',
'delete');
1305 foreach ($listofpermtotest as $permtotest) {
1306 if (empty($this->rights->user) || empty($this->rights->user->group_advance->$permtotest)) {
1307 $this->rights->user->group_advance->$permtotest = 1;
1315 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1316 $this->rights->propal = $this->rights->propale;
1318 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1319 $this->rights->propale = $this->rights->propal;
1325 $this->all_permissions_are_loaded = 1;
1328 $this->_tab_loaded[$moduletag] = 1;
1340 global $conf, $langs, $user;
1345 if ($this->statut == $status) {
1352 $sql =
"UPDATE ".$this->db->prefix().
"user";
1353 $sql .=
" SET statut = ".((int) $status);
1354 $sql .=
" WHERE rowid = ".((int) $this->
id);
1355 $result = $this->
db->query($sql);
1357 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1360 $result = $this->
call_trigger(
'USER_ENABLEDISABLE', $user);
1368 $this->
db->rollback();
1371 $this->status = $status;
1372 $this->statut = $status;
1373 $this->
db->commit();
1390 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1391 return parent::setCategoriesCommon($categories, Categorie::TYPE_USER);
1402 global $conf, $langs;
1408 $this->
fetch($this->
id);
1410 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1413 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = ".((int) $this->
id);
1415 if (!$error && !$this->
db->query($sql)) {
1417 $this->
error = $this->
db->lasterror();
1421 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user WHERE fk_user = ".((int) $this->
id);
1422 if (!$error && !$this->
db->query($sql)) {
1424 $this->
error = $this->
db->lasterror();
1428 $sql =
"DELETE FROM ".$this->db->prefix().
"user_param WHERE fk_user = ".((int) $this->
id);
1429 if (!$error && !$this->
db->query($sql)) {
1431 $this->
error = $this->
db->lasterror();
1435 if ($this->contact_id > 0) {
1436 $sql =
"UPDATE ".$this->db->prefix().
"socpeople SET fk_user_creat = null WHERE rowid = ".((int) $this->contact_id);
1437 if (!$error && !$this->
db->query($sql)) {
1439 $this->
error = $this->
db->lasterror();
1448 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1454 $sql =
"DELETE FROM ".$this->db->prefix().
"user WHERE rowid = ".((int) $this->
id);
1455 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1456 if (!$this->
db->query($sql)) {
1458 $this->
error = $this->
db->lasterror();
1467 $this->
db->rollback();
1472 $this->
db->commit();
1475 $this->
db->rollback();
1487 public function create($user, $notrigger = 0)
1489 global $conf, $langs;
1495 $this->civility_code = trim((
string) $this->civility_code);
1496 $this->login = trim((
string) $this->login);
1497 if (!isset($this->entity)) {
1498 $this->entity = $conf->entity;
1501 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1503 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1506 if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1507 $langs->load(
"errors");
1508 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1511 if (empty($this->login)) {
1512 $langs->load(
"errors");
1513 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1515 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1516 $langs->load(
"errors");
1517 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName");
1528 $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).
"'";
1529 $resqltochecklogin = $this->
db->query($sqltochecklogin);
1530 if ($resqltochecklogin) {
1531 $objtochecklogin = $this->
db->fetch_object($resqltochecklogin);
1532 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1533 $langs->load(
"errors");
1534 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1536 $this->
db->rollback();
1539 $this->
db->free($resqltochecklogin);
1542 if (!empty($this->email)) {
1543 $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).
"'";
1544 $resqltochecklogin = $this->
db->query($sqltochecklogin);
1545 if ($resqltochecklogin) {
1546 $objtochecklogin = $this->
db->fetch_object($resqltochecklogin);
1547 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1548 $langs->load(
"errors");
1549 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
1551 $this->
db->rollback();
1554 $this->
db->free($resqltochecklogin);
1559 $sql =
"INSERT INTO ".$this->db->prefix().
"user (datec, login, ldap_sid, entity)";
1560 $sql .=
" VALUES('".$this->db->idate($this->datec).
"', '".$this->
db->escape($this->login).
"', '".$this->
db->escape($this->ldap_sid).
"', ".((int) $this->entity).
")";
1561 $result = $this->
db->query($sql);
1563 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1565 $this->
id = $this->
db->last_insert_id($this->
db->prefix().
"user");
1569 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1570 $this->
db->rollback();
1574 if (!empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER) && !empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) {
1575 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1576 $langs->load(
"stocks");
1578 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1579 $entrepot->libelle = $entrepot->label;
1580 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1581 $entrepot->statut = 1;
1582 $entrepot->country_id = $mysoc->country_id;
1583 $warehouseid = $entrepot->create($user);
1585 $this->fk_warehouse = $warehouseid;
1589 $result = $this->
update($user, 1, 1);
1591 $this->
db->rollback();
1605 $this->
db->commit();
1610 $this->
db->rollback();
1614 $this->
error = $this->
db->lasterror();
1615 $this->
db->rollback();
1633 global $conf, $user, $langs;
1639 $this->civility_code = $contact->civility_code;
1640 $this->lastname = $contact->lastname;
1641 $this->firstname = $contact->firstname;
1642 $this->gender = $contact->gender;
1643 $this->email = $contact->email;
1644 $this->socialnetworks = $contact->socialnetworks;
1645 $this->office_phone = $contact->phone_pro;
1646 $this->office_fax = $contact->fax;
1647 $this->user_mobile = $contact->phone_mobile;
1648 $this->address = $contact->address;
1649 $this->zip = $contact->zip;
1650 $this->town = $contact->town;
1652 $this->state_id = $contact->state_id;
1653 $this->country_id = $contact->country_id;
1654 $this->employee = 0;
1656 if (empty($login)) {
1657 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1658 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1660 $this->login = $login;
1665 $result = $this->
create($user, 1);
1667 $sql =
"UPDATE ".$this->db->prefix().
"user";
1668 $sql .=
" SET fk_socpeople=".((int) $contact->id);
1669 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1670 if ($contact->socid > 0) {
1671 $sql .=
", fk_soc=".((int) $contact->socid);
1673 $sql .=
" WHERE rowid=".((int) $this->
id);
1677 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1679 $this->context[
'createfromcontact'] =
'createfromcontact';
1684 $error++; $this->
db->rollback();
return -1;
1688 $this->
db->commit();
1691 $this->
error = $this->
db->error();
1693 $this->
db->rollback();
1698 dol_syslog(get_class($this).
"::create_from_contact - 0");
1700 $this->
db->rollback();
1717 global $conf, $user, $langs;
1721 $this->civility_code = $member->civility_id;
1722 $this->lastname = $member->lastname;
1723 $this->firstname = $member->firstname;
1724 $this->gender = $member->gender;
1725 $this->email = $member->email;
1726 $this->fk_member = $member->id;
1727 $this->address = $member->address;
1728 $this->zip = $member->zip;
1729 $this->town = $member->town;
1731 $this->state_id = $member->state_id;
1732 $this->country_id = $member->country_id;
1733 $this->socialnetworks = $member->socialnetworks;
1735 $this->pass = $member->pass;
1736 $this->pass_crypted = $member->pass_indatabase_crypted;
1738 if (empty($login)) {
1739 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1742 $this->login = $login;
1747 $result = $this->
create($user);
1749 if (!empty($this->pass)) {
1750 $newpass = $this->
setPassword($user, $this->pass);
1751 if (is_numeric($newpass) && $newpass < 0) {
1754 } elseif (!empty($this->pass_crypted)) {
1755 $sql =
"UPDATE ".$this->db->prefix().
"user";
1756 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
1757 $sql .=
" WHERE rowid=".((int) $this->
id);
1765 if ($result > 0 && $member->fk_soc) {
1766 $sql =
"UPDATE ".$this->db->prefix().
"user";
1767 $sql .=
" SET fk_soc=".((int) $member->fk_soc);
1768 $sql .=
" WHERE rowid=".((int) $this->
id);
1770 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
1773 $this->
db->commit();
1776 $this->
error = $this->
db->lasterror();
1778 $this->
db->rollback();
1785 $this->
db->commit();
1789 $this->
db->rollback();
1807 $sql =
"SELECT id FROM ".$this->db->prefix().
"rights_def";
1808 $sql .=
" WHERE bydefault = 1";
1809 $sql .=
" AND entity = ".((int) $conf->entity);
1813 $num = $this->
db->num_rows(
$resql);
1816 $row = $this->
db->fetch_row(
$resql);
1824 $sql =
"DELETE FROM ".$this->db->prefix().
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
1825 $result = $this->
db->query($sql);
1827 $sql =
"INSERT INTO ".$this->db->prefix().
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
1828 $result = $this->
db->query($sql);
1848 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
1850 global $conf, $langs;
1852 $nbrowsaffected = 0;
1855 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
1858 $this->civility_code = trim((
string) $this->civility_code);
1859 $this->lastname = trim((
string) $this->lastname);
1860 $this->firstname = trim((
string) $this->firstname);
1861 $this->ref_employee = trim((
string) $this->ref_employee);
1862 $this->national_registration_number = trim((
string) $this->national_registration_number);
1863 $this->employee = ($this->employee > 0 ? $this->employee : 0);
1864 $this->login = trim((
string) $this->login);
1865 $this->gender = trim((
string) $this->gender);
1866 $this->pass = trim((
string) $this->pass);
1867 $this->api_key = trim((
string) $this->api_key);
1868 $this->address = trim((
string) $this->address);
1869 $this->zip = trim((
string) $this->zip);
1870 $this->town = trim((
string) $this->town);
1873 $this->state_id = ($this->state_id > 0 ? $this->state_id : 0);
1874 $this->country_id = ($this->country_id > 0 ? $this->country_id : 0);
1875 $this->office_phone = trim((
string) $this->office_phone);
1876 $this->office_fax = trim((
string) $this->office_fax);
1877 $this->user_mobile = trim((
string) $this->user_mobile);
1878 $this->personal_mobile = trim((
string) $this->personal_mobile);
1879 $this->email = trim((
string) $this->email);
1880 $this->personal_email = trim((
string) $this->personal_email);
1882 $this->job = trim((
string) $this->job);
1883 $this->signature = trim((
string) $this->signature);
1884 $this->note_public = trim((
string) $this->note_public);
1885 $this->note_private = trim((
string) $this->note_private);
1886 $this->openid = trim((
string) $this->openid);
1887 $this->admin = ($this->admin > 0 ? $this->admin : 0);
1889 $this->accountancy_code = trim((
string) $this->accountancy_code);
1890 $this->color = trim((
string) $this->color);
1891 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
1892 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
1893 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
1894 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
1895 $this->birth = empty($this->birth) ?
'' : $this->birth;
1896 $this->fk_warehouse = (int) $this->fk_warehouse;
1899 $badCharUnauthorizedIntoLoginName =
getDolGlobalString(
'MAIN_LOGIN_BADCHARUNAUTHORIZED',
',@<>"\'');
1901 if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1902 $langs->load(
"errors");
1903 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1906 if (empty($this->login)) {
1907 $langs->load(
"errors");
1908 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
1910 } elseif (preg_match(
'/['.preg_quote($badCharUnauthorizedIntoLoginName,
'/').
']/', $this->login)) {
1911 $langs->load(
"errors");
1912 $this->
error = $langs->trans(
"ErrorBadCharIntoLoginName");
1919 if (!empty($this->oldcopy) && $this->oldcopy->login != $this->login) {
1920 $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).
"'";
1921 $resqltochecklogin = $this->
db->query($sqltochecklogin);
1922 if ($resqltochecklogin) {
1923 $objtochecklogin = $this->
db->fetch_object($resqltochecklogin);
1924 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1925 $langs->load(
"errors");
1926 $this->
error = $langs->trans(
"ErrorLoginAlreadyExists", $this->login);
1928 $this->
db->rollback();
1933 if (!empty($this->oldcopy) && !empty($this->email) && $this->oldcopy->email != $this->email) {
1934 $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).
"'";
1935 $resqltochecklogin = $this->
db->query($sqltochecklogin);
1936 if ($resqltochecklogin) {
1937 $objtochecklogin = $this->
db->fetch_object($resqltochecklogin);
1938 if ($objtochecklogin && $objtochecklogin->nb > 0) {
1939 $langs->load(
"errors");
1940 $this->
error = $langs->trans(
"ErrorEmailAlreadyExists", $this->email);
1942 $this->
db->rollback();
1949 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
1950 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
1951 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
1952 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
1953 $sql .=
", ref_employee = '".$this->db->escape($this->ref_employee).
"'";
1954 $sql .=
", national_registration_number = '".$this->db->escape($this->national_registration_number).
"'";
1955 $sql .=
", employee = ".(int) $this->employee;
1956 $sql .=
", login = '".$this->db->escape($this->login).
"'";
1957 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape($this->api_key).
"'" :
"null");
1958 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
1959 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth,
'tzserver').
"'" :
'null');
1960 if (!empty($user->admin)) {
1961 $sql .=
", admin = ".(int) $this->admin;
1963 $sql .=
", address = '".$this->db->escape($this->address).
"'";
1964 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
1965 $sql .=
", town = '".$this->db->escape($this->town).
"'";
1966 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".$this->
db->escape($this->state_id).
"'" :
"null");
1967 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".$this->
db->escape($this->country_id).
"'" :
"null");
1968 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
1969 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
1970 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
1971 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
1972 $sql .=
", email = '".$this->db->escape($this->email).
"'";
1973 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
1974 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1975 $sql .=
", job = '".$this->db->escape($this->job).
"'";
1976 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
1977 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
1978 $sql .=
", color = '".$this->db->escape($this->color).
"'";
1979 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
1980 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
1981 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
1982 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
1983 $sql .=
", note = '".$this->db->escape($this->note_private).
"'";
1984 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
1985 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
1986 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
1987 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".$this->db->escape($this->fk_user).
"'" :
"null");
1988 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".$this->db->escape($this->fk_user_expense_validator).
"'" :
"null");
1989 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".$this->db->escape($this->fk_user_holiday_validator).
"'" :
"null");
1990 if (isset($this->thm) || $this->thm !=
'') {
1991 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
1993 if (isset($this->tjm) || $this->tjm !=
'') {
1994 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
1996 if (isset($this->salary) || $this->salary !=
'') {
1997 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
1999 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
2000 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
2002 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
2003 if (!empty($user->admin) && empty($user->entity) && $user->id != $this->id) {
2004 $sql .=
", entity = ".((int) $this->entity);
2006 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
2007 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
2008 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
2009 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
2010 $sql .=
" WHERE rowid = ".((int) $this->
id);
2012 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2015 $nbrowsaffected += $this->
db->affected_rows(
$resql);
2018 if (!empty($this->pass)) {
2019 if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
2021 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass);
2029 if ($this->fk_member > 0) {
2030 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
2031 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member = NULL where fk_member = ".((int) $this->fk_member);
2034 $this->
error = $this->
db->error(); $this->
db->rollback();
return -5;
2038 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
2039 $sql =
"UPDATE ".$this->db->prefix().
"user SET fk_member =".($this->fk_member > 0 ? ((int) $this->fk_member) :
'null').
" where rowid = ".((
int) $this->id);
2042 $this->
error = $this->
db->error(); $this->
db->rollback();
return -5;
2045 if ($nbrowsaffected) {
2046 if ($this->fk_member > 0 && !$nosyncmember) {
2047 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
2049 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2054 $result = $adh->fetch($this->fk_member);
2057 $adh->civility_code = $this->civility_code;
2058 $adh->firstname = $this->firstname;
2059 $adh->lastname = $this->lastname;
2060 $adh->login = $this->login;
2061 $adh->gender = $this->gender;
2062 $adh->birth = $this->birth;
2064 $adh->pass = $this->pass;
2066 $adh->address = $this->address;
2067 $adh->town = $this->town;
2068 $adh->zip = $this->zip;
2069 $adh->state_id = $this->state_id;
2070 $adh->country_id = $this->country_id;
2072 $adh->email = $this->email;
2074 $adh->socialnetworks = $this->socialnetworks;
2076 $adh->phone = $this->office_phone;
2077 $adh->phone_mobile = $this->user_mobile;
2079 $adh->user_id = $this->id;
2080 $adh->user_login = $this->login;
2082 $result = $adh->update($user, 0, 1, 0);
2084 $this->
error = $adh->error;
2085 $this->errors = $adh->errors;
2086 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2089 } elseif ($result < 0) {
2090 $this->
error = $adh->error;
2091 $this->errors = $adh->errors;
2096 if ($this->contact_id > 0 && !$nosynccontact) {
2097 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
2099 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2103 $result = $tmpobj->fetch($this->contact_id);
2106 $tmpobj->civility_code = $this->civility_code;
2107 $tmpobj->firstname = $this->firstname;
2108 $tmpobj->lastname = $this->lastname;
2109 $tmpobj->login = $this->login;
2110 $tmpobj->gender = $this->gender;
2111 $tmpobj->birth = $this->birth;
2115 $tmpobj->email = $this->email;
2117 $tmpobj->socialnetworks = $this->socialnetworks;
2119 $tmpobj->phone_pro = $this->office_phone;
2120 $tmpobj->phone_mobile = $this->user_mobile;
2121 $tmpobj->fax = $this->office_fax;
2123 $tmpobj->address = $this->address;
2124 $tmpobj->town = $this->town;
2125 $tmpobj->zip = $this->zip;
2126 $tmpobj->state_id = $this->state_id;
2127 $tmpobj->country_id = $this->country_id;
2129 $tmpobj->user_id = $this->id;
2130 $tmpobj->user_login = $this->login;
2132 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
2134 $this->
error = $tmpobj->error;
2135 $this->errors = $tmpobj->errors;
2136 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
2140 $this->
error = $tmpobj->error;
2141 $this->errors = $tmpobj->errors;
2157 if (!$error && !$notrigger) {
2167 $this->
db->commit();
2168 return $nbrowsaffected;
2171 $this->
db->rollback();
2175 $this->
error = $this->
db->lasterror();
2176 $this->
db->rollback();
2195 $sql =
"UPDATE ".$this->db->prefix().
"user SET";
2196 $sql .=
" datepreviouslogin = datelastlogin,";
2197 $sql .=
" ippreviouslogin = iplastlogin,";
2198 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
2199 $sql .=
" iplastlogin = '".$this->db->escape($userremoteip).
"',";
2200 $sql .=
" tms = tms";
2201 $sql .=
" WHERE rowid = ".((int) $this->
id);
2203 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
2206 $this->datepreviouslogin = $this->datelastlogin;
2207 $this->datelastlogin = $now;
2208 $this->ippreviouslogin = $this->iplastlogin;
2209 $this->iplastlogin = $userremoteip;
2212 $this->
error = $this->
db->lasterror().
' sql='.$sql;
2229 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0, $passwordalreadycrypted = 0)
2231 global $conf, $langs;
2232 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
2236 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
2244 if (empty($passwordalreadycrypted)) {
2245 if (!empty($conf->global->USER_PASSWORD_GENERATED)) {
2247 $modGeneratePassClass =
'modGeneratePass'.ucfirst($conf->global->USER_PASSWORD_GENERATED);
2249 include_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/'.$modGeneratePassClass.
'.class.php';
2250 if (class_exists($modGeneratePassClass)) {
2251 $modGeneratePass =
new $modGeneratePassClass($this->
db, $conf, $langs, $user);
2254 $modGeneratePass->WithoutAmbi = 0;
2257 $testpassword = $modGeneratePass->validatePassword($password);
2258 if (!$testpassword) {
2259 $this->
error = $modGeneratePass->error;
2267 $password_crypted =
dol_hash($password);
2271 if (!$changelater) {
2272 if (!is_object($this->oldcopy)) {
2273 $this->oldcopy = clone $this;
2278 $sql =
"UPDATE ".$this->db->prefix().
"user";
2279 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
2280 $sql .=
" pass_temp = null";
2281 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
2282 $sql .=
", pass = null";
2284 $sql .=
", pass = '".$this->db->escape($password).
"'";
2286 $sql .=
" WHERE rowid = ".((int) $this->
id);
2288 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2289 $result = $this->
db->query($sql);
2291 if ($this->
db->affected_rows($result)) {
2292 $this->pass = $password;
2293 $this->pass_indatabase = $password;
2294 $this->pass_indatabase_crypted = $password_crypted;
2296 if ($this->fk_member && !$nosyncmember) {
2297 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2302 $result = $adh->fetch($this->fk_member);
2305 $result = $adh->setPassword($user, $this->pass, (empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1), 1);
2307 $this->
error = $adh->error;
2312 $this->
error = $adh->error;
2317 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2319 if (!$error && !$notrigger) {
2321 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2323 $error++; $this->
db->rollback();
return -1;
2328 $this->
db->commit();
2331 $this->
db->rollback();
2335 $this->
db->rollback();
2342 $sql =
"UPDATE ".$this->db->prefix().
"user";
2343 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2344 $sql .=
" WHERE rowid = ".((int) $this->
id);
2346 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2347 $result = $this->
db->query($sql);
2369 global $conf, $langs, $mysoc;
2370 global $dolibarr_main_url_root;
2372 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2379 $outputlangs =
new Translate(
"", $conf);
2381 if (isset($this->
conf->MAIN_LANG_DEFAULT)
2382 && $this->conf->MAIN_LANG_DEFAULT !=
'auto') {
2383 $outputlangs->getDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2386 if ($this->
conf->MAIN_LANG_DEFAULT) {
2387 $outputlangs->setDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2389 $outputlangs = $langs;
2393 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2395 $appli = constant(
'DOL_APPLICATION_TITLE');
2396 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
2397 $appli = $conf->global->MAIN_APPLICATION_TITLE;
2400 $subject =
'['.$mysoc->name.
'] '.$outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2403 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2404 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2406 if (!$changelater) {
2407 $url = $urlwithroot.
'/';
2408 if (!empty($conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD))
2409 $url = $conf->global->URL_REDIRECTION_AFTER_CHANGEPASSWORD;
2410 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2411 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2412 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2413 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2416 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2418 $mesg .= $user->getFullName($outputlangs);
2420 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2422 global $dolibarr_main_instance_unique_id;
2425 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword';
2426 $url .=
'&username='.urlencode($this->login).
"&passworduidhash=".urlencode(
dol_hash($password.
'-'.$this->id.
'-'.$dolibarr_main_instance_unique_id));
2430 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"<br>\n";
2431 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :<br>\n<br>\n";
2432 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Login").
"</strong> = ".$this->login.
"<br>\n";
2433 $mesg .=
'<strong>'.$outputlangs->transnoentitiesnoconv(
"Password").
"</strong> = ".$password.
"<br>\n<br>\n";
2435 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :<br>\n";
2436 $mesg .=
'<a href="'.$url.
'" rel="noopener">'.$outputlangs->transnoentitiesnoconv(
"ConfirmPasswordChange").
'</a>'.
"<br>\n<br>\n";
2437 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"<br>\n<br>\n";
2439 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2442 $trackid =
'use'.$this->id;
2447 $conf->global->MAIN_MAIL_EMAIL_FROM,
2461 if ($mailfile->sendfile()) {
2464 $langs->trans(
"errors");
2465 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2477 return $this->error;
2490 $sql =
"SELECT url, login, pass, poste ";
2491 $sql .=
" FROM ".$this->db->prefix().
"user_clicktodial as u";
2492 $sql .=
" WHERE u.fk_user = ".((int) $this->
id);
2497 $obj = $this->
db->fetch_object(
$resql);
2499 $this->clicktodial_url = $obj->url;
2500 $this->clicktodial_login = $obj->login;
2501 $this->clicktodial_password = $obj->pass;
2502 $this->clicktodial_poste = $obj->poste;
2505 $this->clicktodial_loaded = 1;
2510 $this->
error = $this->
db->error();
2526 $sql =
"DELETE FROM ".$this->db->prefix().
"user_clicktodial";
2527 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2529 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2530 $result = $this->
db->query($sql);
2532 $sql =
"INSERT INTO ".$this->db->prefix().
"user_clicktodial";
2533 $sql .=
" (fk_user,url,login,pass,poste)";
2534 $sql .=
" VALUES (".$this->id;
2535 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2536 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2537 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2538 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2540 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2541 $result = $this->
db->query($sql);
2543 $this->
db->commit();
2546 $this->
db->rollback();
2547 $this->
error = $this->
db->lasterror();
2565 global $conf, $langs, $user;
2571 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2572 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2573 $sql .=
" AND fk_usergroup = ".((int) $group);
2574 $sql .=
" AND entity = ".((int) $entity);
2576 $result = $this->
db->query($sql);
2578 $sql =
"INSERT INTO ".$this->db->prefix().
"usergroup_user (entity, fk_user, fk_usergroup)";
2579 $sql .=
" VALUES (".((int) $entity).
",".((int) $this->
id).
",".((int) $group).
")";
2581 $result = $this->
db->query($sql);
2583 if (!$error && !$notrigger) {
2584 $this->newgroupid = $group;
2585 $this->context = array(
'audit'=>$langs->trans(
"UserSetInGroup"),
'newgroupid'=>$group);
2596 $this->
db->commit();
2600 $this->
db->rollback();
2604 $this->
error = $this->
db->lasterror();
2605 $this->
db->rollback();
2622 global $conf, $langs, $user;
2628 $sql =
"DELETE FROM ".$this->db->prefix().
"usergroup_user";
2629 $sql .=
" WHERE fk_user = ".((int) $this->
id);
2630 $sql .=
" AND fk_usergroup = ".((int) $group);
2631 $sql .=
" AND entity = ".((int) $entity);
2633 $result = $this->
db->query($sql);
2635 if (!$error && !$notrigger) {
2636 $this->oldgroupid = $group;
2637 $this->context = array(
'audit'=>$langs->trans(
"UserRemovedFromGroup"),
'oldgroupid'=>$group);
2648 $this->
db->commit();
2651 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2652 $this->
db->rollback();
2656 $this->
error = $this->
db->lasterror();
2657 $this->
db->rollback();
2673 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
2675 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2676 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
2697 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
2699 global $langs, $conf, $db, $hookmanager, $user;
2700 global $dolibarr_main_authentication, $dolibarr_main_demo;
2701 global $menumanager;
2703 if (!$user->rights->user->user->lire && $user->id != $this->id) {
2707 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) {
2711 $result =
''; $label =
'';
2714 if (!empty($this->photo)) {
2715 $label .=
'<div class="photointooltip floatright">';
2716 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photoref photowithmargin photologintooltip',
'small', 0, 1);
2722 $label .=
'<div class="centpercent">';
2723 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u>';
2724 $label .=
' '.$this->getLibStatut(4);
2726 if (!empty($this->login)) {
2729 if (!empty($this->job)) {
2733 if (!empty($this->office_phone) || !empty($this->office_fax) || !empty($this->fax)) {
2734 $phonelist = array();
2735 if ($this->office_phone) {
2736 $phonelist[] =
dol_print_phone($this->office_phone, $this->country_code, $this->
id, 0,
'',
' ',
'phone');
2738 if ($this->office_fax) {
2739 $phonelist[] =
dol_print_phone($this->office_fax, $this->country_code, $this->
id, 0,
'',
' ',
'fax');
2741 if ($this->user_mobile) {
2742 $phonelist[] =
dol_print_phone($this->user_mobile, $this->country_code, $this->
id, 0,
'',
' ',
'mobile');
2744 $label .=
'<br><b>'.$langs->trans(
'Phone').
':</b> '.implode(
' ', $phonelist);
2746 if (!empty($this->admin)) {
2747 $label .=
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
2749 if (!empty($this->accountancy_code) || $option ==
'accountancy') {
2750 $label .=
'<br><b>'.$langs->trans(
"AccountancyCode").
'</b>: '.$this->accountancy_code;
2753 if (!empty($this->socid)) {
2754 $thirdpartystatic =
new Societe($db);
2755 $thirdpartystatic->fetch($this->socid);
2756 if (empty($hidethirdpartylogo)) {
2757 $companylink =
' '.$thirdpartystatic->getNomUrl(2, (($option ==
'nolink') ?
'nolink' :
''));
2761 $type = ($this->socid ? $langs->trans(
"ExternalUser").$company : $langs->trans(
"InternalUser"));
2762 $label .=
'<br><b>'.$langs->trans(
"Type").
':</b> '.$type;
2764 if ($infologin > 0) {
2766 $label .=
'<br><u>'.$langs->trans(
"Session").
'</u>';
2768 if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) {
2769 $label .=
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.$conf->entity.
' (User entity '.$this->entity.
')';
2771 $label .=
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
2772 $label .=
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
2773 $label .=
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
2775 $label .=
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
2777 $label .=
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
2778 $label .=
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag($conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.$_SERVER[
'HTTP_USER_AGENT'].
')');
2779 $label .=
'<br><b>'.$langs->trans(
"Layout").
':</b> '.
dol_string_nohtmltag($conf->browser->layout);
2780 $label .=
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
2781 if ($conf->browser->layout ==
'phone') {
2782 $label .=
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
2784 if (!empty($_SESSION[
"disablemodules"])) {
2785 $label .=
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(join(
', ', explode(
',', $_SESSION[
"disablemodules"])));
2788 if ($infologin < 0) {
2792 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
2793 if ($option ==
'leave') {
2794 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
2797 if ($option !=
'nolink') {
2799 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2800 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2801 $add_save_lastsearch_values = 1;
2803 if ($add_save_lastsearch_values) {
2804 $url .=
'&save_lastsearch_values=1';
2808 $linkstart =
'<a href="'.$url.
'"';
2810 if (empty($notooltip)) {
2811 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2812 $langs->load(
"users");
2813 $label = $langs->trans(
"ShowUser");
2814 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2816 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
2817 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
2820 $linkstart .= $linkclose.
'>';
2824 $result .= (($option ==
'nolink') ?
'' : $linkstart);
2825 if ($withpictoimg) {
2826 $paddafterimage =
'';
2827 if (abs((
int) $withpictoimg) == 1) {
2828 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
2831 if ($withpictoimg > 0) {
2832 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
2835 $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>';
2839 if ($withpictoimg > -2 && $withpictoimg != 2) {
2840 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2841 $result .=
'<span class="nopadding usertext'.((!isset($this->statut) || $this->statut) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
2843 if ($mode ==
'login') {
2848 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2849 $result .=
'</span>';
2852 $result .= (($option ==
'nolink') ?
'' : $linkend);
2855 $result .= $companylink;
2858 $hookmanager->initHooks(array(
'userdao'));
2859 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
2860 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2862 $result = $hookmanager->resPrint;
2864 $result .= $hookmanager->resPrint;
2879 public function getLoginUrl($withpictoimg = 0, $option =
'', $notooltip = 0, $morecss =
'')
2881 global $langs, $user;
2885 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2889 if ((!$user->rights->user->user->lire && $this->id != $user->id)) {
2893 if ($option ==
'xxx') {
2894 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2898 if ($option ==
'nolink') {
2903 $result .= $linkstart;
2904 if ($withpictoimg) {
2905 $paddafterimage =
'';
2906 if (abs($withpictoimg) == 1) {
2907 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
2910 if ($withpictoimg > 0) {
2911 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
2914 $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>';
2918 $result .= $this->login;
2919 $result .= $linkend;
2932 return $this->
LibStatut(isset($this->statut) ? (
int) $this->statut : (
int) $this->status, $mode);
2948 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2951 $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
2952 $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
2953 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv(
'Enabled');
2954 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv(
'Disabled');
2957 $statusType =
'status5';
2958 if ($status == self::STATUS_ENABLED) {
2959 $statusType =
'status4';
2962 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
2974 $return =
'<div class="box-flex-item box-flex-grow-zero">';
2975 $return .=
'<div class="info-box info-box-sm">';
2976 $return .=
'<span class="info-box-icon bg-infobox-action">';
2979 if (!empty($this->photo)) {
2981 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photokanban photoref photowithmargin photologintooltip',
'small', 0, 1);
2990 $return .=
'</span>';
2991 $return .=
'<div class="info-box-content">';
2992 $return .=
'<span class="info-box-ref">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
2993 if (property_exists($this,
'label')) {
2994 $return .=
'<br><span class="info-box-label opacitymedium">'.$this->label.
'</span>';
2997 $return .=
'<br><span class="info-box-label opacitymedium small">'.img_picto(
'',
'email').
' '.$this->email.
'</span>';
2999 if (method_exists($this,
'getLibStatut')) {
3000 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(5).
'</div>';
3002 $return .=
'</div>';
3003 $return .=
'</div>';
3004 $return .=
'</div>';
3027 $dn = $conf->global->LDAP_KEY_USERS.
"=".$info[$conf->global->LDAP_KEY_USERS].
",".$conf->global->LDAP_USER_DN;
3028 } elseif ($mode == 1) {
3029 $dn = $conf->global->LDAP_USER_DN;
3030 } elseif ($mode == 2) {
3031 $dn = $conf->global->LDAP_KEY_USERS.
"=".$info[$conf->global->LDAP_KEY_USERS];
3046 global $conf, $langs;
3052 $keymodified =
false;
3055 $info[
"objectclass"] = explode(
',', $conf->global->LDAP_USER_OBJECT_CLASS);
3061 'LDAP_FIELD_FULLNAME' =>
'fullname',
3062 'LDAP_FIELD_NAME' =>
'lastname',
3063 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
3064 'LDAP_FIELD_LOGIN' =>
'login',
3065 'LDAP_FIELD_LOGIN_SAMBA'=>
'login',
3066 'LDAP_FIELD_PHONE' =>
'office_phone',
3067 'LDAP_FIELD_MOBILE' =>
'user_mobile',
3068 'LDAP_FIELD_FAX' =>
'office_fax',
3069 'LDAP_FIELD_MAIL' =>
'email',
3070 'LDAP_FIELD_SID' =>
'ldap_sid',
3074 foreach ($ldapkey as $constname => $varname) {
3075 if (!empty($this->$varname) && !empty($conf->global->$constname)) {
3076 $info[$conf->global->$constname] = $this->$varname;
3079 if (!empty($conf->global->LDAP_KEY_USERS) && $conf->global->LDAP_KEY_USERS == $conf->global->$constname) {
3080 if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
3081 $keymodified =
true;
3086 foreach ($socialnetworks as $key => $value) {
3087 if (!empty($this->socialnetworks[$value[
'label']]) && !empty($conf->global->{
'LDAP_FIELD_'.strtoupper($value[
'label'])})) {
3088 $info[$conf->global->{
'LDAP_FIELD_'.strtoupper($value[
'label'])}] = $this->socialnetworks[$value[
'label']];
3091 if ($this->address && !empty($conf->global->LDAP_FIELD_ADDRESS)) {
3092 $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->address;
3094 if ($this->zip && !empty($conf->global->LDAP_FIELD_ZIP)) {
3095 $info[$conf->global->LDAP_FIELD_ZIP] = $this->zip;
3097 if ($this->town && !empty($conf->global->LDAP_FIELD_TOWN)) {
3098 $info[$conf->global->LDAP_FIELD_TOWN] = $this->town;
3100 if ($this->note_public && !empty($conf->global->LDAP_FIELD_DESCRIPTION)) {
3103 if ($this->socid > 0) {
3105 $soc->fetch($this->socid);
3107 $info[$conf->global->LDAP_FIELD_COMPANY] = $soc->name;
3108 if ($soc->client == 1) {
3109 $info[
"businessCategory"] =
"Customers";
3111 if ($soc->client == 2) {
3112 $info[
"businessCategory"] =
"Prospects";
3114 if ($soc->fournisseur == 1) {
3115 $info[
"businessCategory"] =
"Suppliers";
3120 if (!empty($this->pass)) {
3121 if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
3122 $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass;
3124 if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3125 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass,
'openldap');
3127 } elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !==
'3') {
3130 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
3132 if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) {
3133 if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3134 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dolGetLdapPasswordHash($this->pass_indatabase_crypted,
'md5frommd5');
3137 } elseif (!empty($this->pass_indatabase)) {
3139 if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
3140 $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass_indatabase;
3142 if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
3143 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass_indatabase,
'openldap');
3148 if ($conf->global->LDAP_SERVER_TYPE ==
'egroupware') {
3149 $info[
"objectclass"][4] =
"phpgwContact";
3151 $info[
'uidnumber'] = $this->id;
3153 $info[
'phpgwTz'] = 0;
3154 $info[
'phpgwMailType'] =
'INTERNET';
3155 $info[
'phpgwMailHomeType'] =
'INTERNET';
3157 $info[
"phpgwContactTypeId"] =
'n';
3158 $info[
"phpgwContactCatId"] = 0;
3159 $info[
"phpgwContactAccess"] =
"public";
3162 $this->egroupware_id = 1;
3165 $info[
"phpgwContactOwner"] = $this->egroupware_id;
3168 $info[
"rfc822Mailbox"] = $this->email;
3170 if ($this->phone_mobile) {
3171 $info[
"phpgwCellTelephoneNumber"] = $this->phone_mobile;
3175 if (!empty($conf->global->LDAP_FIELD_USERID)) {
3176 $info[$conf->global->LDAP_FIELD_USERID] = $this->id;
3178 if (!empty($conf->global->LDAP_FIELD_GROUPID)) {
3180 $groupslist = $usergroup->listGroupsForUser($this->
id);
3181 $info[$conf->global->LDAP_FIELD_GROUPID] =
'65534';
3182 if (!empty($groupslist)) {
3183 foreach ($groupslist as $groupforuser) {
3184 $info[$conf->global->LDAP_FIELD_GROUPID] = $groupforuser->id;
3189 if (!empty($conf->global->LDAP_FIELD_HOMEDIRECTORY) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX)) {
3190 $info[$conf->global->LDAP_FIELD_HOMEDIRECTORY] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->login";
3206 global $user, $langs;
3212 $this->
ref =
'SPECIMEN';
3213 $this->specimen = 1;
3215 $this->lastname =
'DOLIBARR';
3216 $this->firstname =
'SPECIMEN';
3217 $this->gender =
'man';
3218 $this->note_public =
'This is a note public';
3219 $this->note_private =
'This is a note private';
3220 $this->email =
'email@specimen.com';
3221 $this->personal_email =
'personalemail@specimen.com';
3222 $this->socialnetworks = array(
3223 'skype' =>
'skypepseudo',
3224 'twitter' =>
'twitterpseudo',
3225 'facebook' =>
'facebookpseudo',
3226 'linkedin' =>
'linkedinpseudo',
3228 $this->office_phone =
'0999999999';
3229 $this->office_fax =
'0999999998';
3230 $this->user_mobile =
'0999999997';
3231 $this->personal_mobile =
'0999999996';
3233 $this->login =
'dolibspec';
3234 $this->pass =
'dolibSpec+@123';
3237 $this->datec = $now;
3238 $this->datem = $now;
3240 $this->datelastlogin = $now;
3241 $this->iplastlogin =
'127.0.0.1';
3242 $this->datepreviouslogin = $now;
3243 $this->ippreviouslogin =
'127.0.0.1';
3258 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
3259 $sql .=
" u.tms as date_modification, u.entity";
3260 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3261 $sql .=
" WHERE u.rowid = ".((int) $id);
3263 $result = $this->
db->query($sql);
3265 if ($this->
db->num_rows($result)) {
3266 $obj = $this->
db->fetch_object($result);
3268 $this->
id = $obj->rowid;
3270 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
3271 $this->date_creation = $this->db->jdate($obj->datec);
3272 $this->date_modification = $this->
db->jdate($obj->date_modification);
3273 $this->entity = $obj->entity;
3276 $this->
db->free($result);
3290 $sql =
"SELECT count(mc.email) as nb";
3291 $sql .=
" FROM ".$this->db->prefix().
"mailing_cibles as mc";
3292 $sql .=
" WHERE mc.email = '".$this->db->escape($this->email).
"'";
3293 $sql .=
" AND mc.statut NOT IN (-1,0)";
3297 $obj = $this->
db->fetch_object(
$resql);
3303 $this->error = $this->
db->error();
3320 $sql =
"SELECT count(rowid) as nb";
3321 $sql .=
" FROM ".$this->db->prefix().
"user";
3322 if ($option ==
'superadmin') {
3323 $sql .=
" WHERE entity = 0";
3325 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
3326 if ($limitTo ==
'active') {
3327 $sql .=
" AND statut = 1";
3331 $sql .=
" AND admin = ".(int) $admin;
3336 $obj = $this->
db->fetch_object(
$resql);
3337 $nb = (int) $obj->nb;
3342 $this->error = $this->
db->lasterror();
3358 global $user, $conf;
3362 $this->firstname = $ldapuser->{$conf->global->LDAP_FIELD_FIRSTNAME};
3363 $this->lastname = $ldapuser->{$conf->global->LDAP_FIELD_NAME};
3364 $this->login = $ldapuser->{$conf->global->LDAP_FIELD_LOGIN};
3365 $this->pass = $ldapuser->{$conf->global->LDAP_FIELD_PASSWORD};
3366 $this->pass_indatabase_crypted = $ldapuser->{$conf->global->LDAP_FIELD_PASSWORD_CRYPTED};
3368 $this->office_phone = $ldapuser->{$conf->global->LDAP_FIELD_PHONE};
3369 $this->user_mobile = $ldapuser->{$conf->global->LDAP_FIELD_MOBILE};
3370 $this->office_fax = $ldapuser->{$conf->global->LDAP_FIELD_FAX};
3371 $this->email = $ldapuser->{$conf->global->LDAP_FIELD_MAIL};
3372 foreach ($socialnetworks as $key => $value) {
3373 $tmpkey =
'LDAP_FIELD_'.strtoupper($value[
'label']);
3374 $this->socialnetworks[$value[
'label']] = $ldapuser->{$conf->global->$tmpkey};
3376 $this->ldap_sid = $ldapuser->{$conf->global->LDAP_FIELD_SID};
3378 $this->job = $ldapuser->{$conf->global->LDAP_FIELD_TITLE};
3379 $this->note_public = $ldapuser->{$conf->global->LDAP_FIELD_DESCRIPTION};
3381 $result = $this->update($user);
3383 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3399 $sql =
"SELECT rowid FROM ".$this->db->prefix().
"user";
3400 $sql .=
" WHERE fk_user = ".((int) $this->
id);
3402 dol_syslog(get_class($this).
"::get_children", LOG_DEBUG);
3403 $res = $this->
db->query($sql);
3406 while ($rec = $this->
db->fetch_array($res)) {
3407 $user =
new User($this->
db);
3408 $user->fetch($rec[
'rowid']);
3428 $this->parentof = array();
3431 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3432 $sql .=
" FROM ".$this->db->prefix().
"user";
3433 $sql .=
" WHERE fk_user <> 0";
3434 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3436 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3439 while ($obj = $this->
db->fetch_object(
$resql)) {
3440 $this->parentof[$obj->id_son] = $obj->id_parent;
3466 global $conf, $user;
3467 global $hookmanager;
3470 $hookmanager->initHooks(array(
'userdao'));
3472 $this->users = array();
3475 $this->loadParentOf();
3478 $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";
3479 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3481 $parameters = array();
3482 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3484 $sql .= $hookmanager->resPrint;
3486 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3489 $sql .=
" AND ".$filter;
3492 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3496 while ($obj = $this->
db->fetch_object(
$resql)) {
3497 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3498 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3499 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3500 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3501 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3502 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3503 $this->users[$obj->rowid][
'login'] = $obj->login;
3504 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3505 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3506 $this->users[$obj->rowid][
'email'] = $obj->email;
3507 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3508 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3509 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3518 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3519 foreach ($this->users as $key => $val) {
3520 $result = $this->build_path_from_id_user($key, 0);
3522 $this->error =
'ErrorLoopInHierarchy';
3528 if ($deleteafterid) {
3530 $keyfilter1 =
'^'.$deleteafterid.
'$';
3531 $keyfilter2 =
'_'.$deleteafterid.
'$';
3532 $keyfilter3 =
'^'.$deleteafterid.
'_';
3533 $keyfilter4 =
'_'.$deleteafterid.
'_';
3534 foreach ($this->users as $key => $val) {
3535 if (preg_match(
'/'.$keyfilter1.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter2.
'/', $val[
'fullpath'])
3536 || preg_match(
'/'.$keyfilter3.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter4.
'/', $val[
'fullpath'])) {
3537 unset($this->users[$key]);
3542 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
3543 $this->users =
dol_sort_array($this->users,
'fullname',
'asc',
true,
false);
3547 return $this->users;
3560 $childids = array();
3562 if (isset($this->cache_childids[$this->
id])) {
3563 $childids = $this->cache_childids[$this->id];
3566 $this->get_full_tree();
3568 $idtoscan = $this->id;
3570 dol_syslog(
"Build childid for id = ".$idtoscan);
3571 foreach ($this->users as $id => $val) {
3573 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
3574 $childids[$val[
'id']] = $val[
'id'];
3578 $this->cache_childids[$this->id] = $childids;
3580 if ($addcurrentuser) {
3581 $childids[$this->id] = $this->id;
3601 if (!empty($this->users[$id_user][
'fullpath'])) {
3603 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
3608 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
3609 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
3610 $i = 0; $cursor_user = $id_user;
3612 $useridfound = array($id_user);
3613 while (!empty($this->parentof[$cursor_user]) && !empty($this->users[$this->parentof[$cursor_user]])) {
3614 if (in_array($this->parentof[$cursor_user], $useridfound)) {
3615 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
3618 $useridfound[] = $this->parentof[$cursor_user];
3619 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
3620 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
3621 $i++; $cursor_user = $this->parentof[$cursor_user];
3625 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
3659 $this->nb = array();
3661 $sql =
"SELECT COUNT(DISTINCT u.rowid) as nb";
3662 $sql .=
" FROM ".$this->db->prefix().
"user as u";
3663 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
3664 $sql .=
", ".$this->db->prefix().
"usergroup_user as ug";
3665 $sql .=
" WHERE ug.entity IN (".getEntity(
'usergroup').
")";
3666 $sql .=
" AND ug.fk_user = u.rowid";
3668 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3670 $sql .=
" AND u.statut > 0";
3675 while ($obj = $this->
db->fetch_object(
$resql)) {
3676 $this->nb[
"users"] = $obj->nb;
3682 $this->error = $this->
db->error();
3698 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
3700 global $conf, $user, $langs;
3702 $langs->load(
"user");
3706 if (!empty($conf->global->USER_ADDON_PDF)) {
3707 $modele = $conf->global->USER_ADDON_PDF;
3709 $modele =
'bluesky';
3713 $modelpath =
"core/modules/user/doc/";
3715 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3729 $user_property =
'';
3731 if (empty($rowid)) {
3735 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
3736 $sql .=
" FROM ".$this->db->prefix().
"user";
3737 $sql .=
" WHERE rowid = ".((int) $rowid);
3741 $nump = $this->
db->num_rows(
$resql);
3744 $obj = $this->
db->fetch_object(
$resql);
3746 if ($mode ==
'email') {
3747 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
3748 } elseif ($mode ==
'mobile') {
3749 $user_property = $obj->user_mobile;
3752 return $user_property;
3770 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter = array(), $filtermode =
'AND', $entityfilter =
false)
3772 global $conf, $user;
3774 $sql =
"SELECT t.rowid";
3775 $sql .=
' FROM '.$this->db->prefix().$this->table_element.
' as t ';
3777 if ($entityfilter) {
3778 if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
3779 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
3780 $sql .=
" WHERE t.entity IS NOT NULL";
3782 $sql .=
",".$this->db->prefix().
"usergroup_user as ug";
3783 $sql .=
" WHERE ((ug.fk_user = t.rowid";
3784 $sql .=
" AND ug.entity IN (".getEntity(
'user').
"))";
3785 $sql .=
" OR t.entity = 0)";
3788 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
3791 $sql .=
" WHERE 1 = 1";
3795 $sqlwhere = array();
3796 if (!empty($filter)) {
3797 foreach ($filter as $key => $value) {
3798 if ($key ==
't.rowid') {
3799 $sqlwhere[] = $key.
" = ".((int) $value);
3800 } elseif (isset($this->fields[$key][
'type']) && in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
3801 $sqlwhere[] = $key.
" = '".$this->
db->idate($value).
"'";
3802 } elseif ($key ==
'customsql') {
3803 $sqlwhere[] = $value;
3805 $sqlwhere[] = $key.
" LIKE '%".$this->
db->escape($value).
"%'";
3809 if (count($sqlwhere) > 0) {
3810 $sql .=
' AND ('.implode(
' '.$this->
db->escape($filtermode).
' ', $sqlwhere).
')';
3812 $sql .= $this->
db->order($sortfield, $sortorder);
3814 $sql .= $this->
db->plimit($limit + 1, $offset);
3821 $this->users = array();
3822 $num = $this->
db->num_rows(
$resql);
3824 while ($obj = $this->
db->fetch_object(
$resql)) {
3825 $line =
new self($this->db);
3826 $result = $line->fetch($obj->rowid);
3827 if ($result > 0 && !empty($line->id)) {
3828 $this->users[$obj->rowid] = clone $line;
3835 $this->errors[] = $this->
db->lasterror();
3847 private $findUserIdByEmailCache;
3861 if (isset($this->findUserIdByEmailCache[$email])) {
3862 return $this->findUserIdByEmailCache[$email];
3865 $this->findUserIdByEmailCache[$email] = -1;
3869 $sql =
'SELECT rowid';
3870 $sql .=
' FROM '.$this->db->prefix().
'user';
3871 if (!empty($conf->global->AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR)) {
3872 $sql .=
" WHERE email LIKE '%".$this->db->escape($email).
"%'";
3874 $sql .=
" WHERE email = '".$this->db->escape($email).
"'";
3883 $obj = $this->
db->fetch_object(
$resql);
3888 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
3890 return $this->findUserIdByEmailCache[$email];
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
loadParentOf()
Load this->parentof that is array(id_son=>id_parent, ...)
user_get_property($rowid, $mode)
Return property of user from its id.
__construct($db)
Constructor of the class.
SetInGroup($group, $entity, $notrigger=0)
Add user into a group.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
_load_ldap_info()
Initialize the info array (array of LDAP values) that will be used to call LDAP functions.
dol_hash($chain, $type= '0')
Returns a hash of a string.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
addrights($rid, $allmodule= '', $allperms= '', $entity=0, $notrigger=0)
Add a right to the user.
create($user, $notrigger=0)
Create a user into database.
getUserRemoteIP()
Return the IP of remote user.
update_ldap2dolibarr(&$ldapuser)
Update user using data from the LDAP.
create_from_contact($contact, $login= '', $password= '')
Create a user from a contact object.
fetchAll($sortorder= '', $sortfield= '', $limit=0, $offset=0, $filter=array(), $filtermode= 'AND', $entityfilter=false)
Load all objects into $this->users.
getLibStatut($mode=0)
Return the label of the status of user (active, inactive)
hasRight($module, $permlevel1, $permlevel2= '')
Return if a user has a permission.
setUpperOrLowerCase()
Set to upper or ucwords/lower if needed.
update($user, $notrigger=0, $nosyncmember=0, $nosyncmemberpass=0, $nosynccontact=0)
Update a user into database (and also password if this->pass is defined)
conf($dolibarr_main_document_root)
Load conf file (file must exists)
$conf db
API class for accounts.
getArrayOfSocialNetworks()
Get array of social network dictionary.
setPassword($user, $password= '', $changelater=0, $notrigger=0, $nosyncmember=0, $passwordalreadycrypted=0)
Change password of a user.
getAllChildIds($addcurrentuser=0)
Return list of all child users id in herarchy (all sublevels).
set_default_rights()
Assign rights by default.
dol_now($mode= 'auto')
Return date for now.
getKanbanView($option= '')
Return clicable link of object (with eventually picto)
Class to manage Dolibarr users.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default= '')
Return dolibarr global constant string value.
Class to manage Dolibarr database access.
dol_print_phone($phone, $countrycode= '', $cid=0, $socid=0, $addlink= '', $separ=" ", $withpicto= '', $titlealt= '', $adddivfloat=0)
Format phone numbers according to country.
update_clicktodial()
Update clicktodial info.
Class to manage user groups.
LibStatut($status, $mode=0)
Return the label of a status of user (active, inactive)
getFullName($langs, $option=0, $nameorder=-1, $maxlen=0)
Return full name (civility+' '+name+' '+lastname)
dol_buildlogin($lastname, $firstname)
Build a login from lastname, firstname.
get_children()
Return and array with all instanciated first level children users of current user.
findUserIdByEmail($email)
Find a user by the given e-mail and return it's user id when found.
fetch_clicktodial()
Read clicktodial information for user.
send_password($user, $password= '', $changelater=0)
Send new password by email.
$clicktodial_url
clicktodial url
getrights($moduletag= '', $forcereload=0)
Load permissions granted to user into object user.
getLoginUrl($withpictoimg=0, $option= '', $notooltip=0, $morecss= '')
Return clickable link of login (eventualy with picto)
info($id)
Load info of user object.
getPhotoUrl($width, $height, $cssclass= '', $imagesize= '')
Return a link with photo Use this->id,this->photo.
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
getNomUrl($withpictoimg=0, $option= '', $infologin=0, $notooltip=0, $maxlen=24, $hidethirdpartylogo=0, $mode= '', $morecss= '', $save_lastsearch_value=-1)
Return a link to the user card (with optionaly the picto) Use this->id,this->lastname, this->firstname.
load_state_board()
Load metrics this->nb for dashboard.
RemoveFromGroup($group, $entity, $notrigger=0)
Remove a user from a group.
Class to manage third parties objects (customers, suppliers, prospects...)
initAsSpecimen()
Initialise an instance with random values.
setstatus($status)
Change status of a user.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
loadDefaultValues()
Load default values from database table into property ->default_values.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile->sendfile();.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage members of a foundation.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
deleteExtraFields()
Delete all extra fields values for the current object.
Class to manage translations.
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...
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
setCategories($categories)
Sets object to supplied categories.
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...
delrights($rid, $allmodule= '', $allperms= '', $entity=0, $notrigger=0)
Remove a right to the user.
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...
clearrights()
Clear all permissions array of user.
fetch($id= '', $login= '', $sid= '', $loadpersonalconf=0, $entity=-1, $email= '', $fk_socpeople=0)
Load a user from database with its id or ref (login).
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getNbOfUsers($limitTo, $option= '', $admin=-1)
Return number of existing users.
call_trigger($triggerName, $user)
Call trigger based on this instance.
dolGetLdapPasswordHash($password, $type= 'md5')
Returns a specific ldap hash of a password.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
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. ...
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
get_full_tree($deleteafterid=0, $filter= '')
Build the hierarchy/tree of users into an array.
create_from_member($member, $login= '')
Create a user into database from a member object.
getNbOfEMailings()
Return number of mass Emailing received by this contacts with its email.
picto_from_langcode($codelang, $moreatt= '', $notitlealt=0)
Return img flag of country for a language code or country code.
update_last_login_date()
Mise a jour en base de la date de derniere connexion d'un utilisateur Fonction appelee lors d'une nou...
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
error()
Renvoie la derniere erreur fonctionnelle de manipulation de l'objet.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
Class to manage warehouses.