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;
93 public $personal_email;
98 public $socialnetworks;
155 public $office_phone;
170 public $personal_mobile;
200 public $pass_indatabase;
205 public $pass_indatabase_crypted;
249 public $fk_user_expense_validator;
254 public $fk_user_holiday_validator;
264 public $clicktodial_login;
269 public $clicktodial_password;
274 public $clicktodial_poste;
276 public $datelastlogin;
277 public $datepreviouslogin;
278 public $datestartvalidity;
279 public $dateendvalidity;
295 public $all_permissions_are_loaded;
305 private $_tab_loaded = array();
311 public $default_values;
312 public $lastsearch_values_tmp;
313 public $lastsearch_values;
315 public $users = array();
317 private $cache_childids;
319 public $accountancy_code;
333 public $dateemployment;
334 public $dateemploymentend;
336 public $default_c_exp_tax_cat;
337 public $default_range;
342 public $fk_warehouse;
344 public $fields = array(
345 'rowid'=>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'index'=>1,
'position'=>1,
'comment'=>
'Id'),
346 'lastname'=>array(
'type'=>
'varchar(50)',
'label'=>
'Name',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>20,
'searchall'=>1),
347 'firstname'=>array(
'type'=>
'varchar(50)',
'label'=>
'Name',
'enabled'=>1,
'visible'=>1,
'notnull'=>1,
'showoncombobox'=>1,
'index'=>1,
'position'=>10,
'searchall'=>1),
351 const STATUS_DISABLED = 0;
352 const STATUS_ENABLED = 1;
366 $this->liste_limit = 0;
367 $this->clicktodial_loaded = 0;
370 $this->all_permissions_are_loaded = 0;
371 $this->nb_rights = 0;
377 $this->
conf =
new stdClass();
378 $this->rights =
new stdClass();
379 $this->rights->user =
new stdClass();
380 $this->rights->user->user =
new stdClass();
381 $this->rights->user->self =
new stdClass();
396 public function fetch($id =
'', $login =
'', $sid =
'', $loadpersonalconf = 0, $entity = -1, $email =
'')
401 $login = trim($login);
404 $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,";
405 $sql .=
" u.socialnetworks,";
406 $sql .=
" u.signature, u.office_phone, u.office_fax, u.user_mobile, u.personal_mobile,";
407 $sql .=
" u.address, u.zip, u.town, u.fk_state as state_id, u.fk_country as country_id,";
408 $sql .=
" u.admin, u.login, u.note as note_private, u.note_public,";
409 $sql .=
" u.pass, u.pass_crypted, u.pass_temp, u.api_key,";
410 $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,";
411 $sql .=
" u.statut, u.lang, u.entity,";
412 $sql .=
" u.datec as datec,";
413 $sql .=
" u.tms as datem,";
414 $sql .=
" u.datelastlogin as datel,";
415 $sql .=
" u.datepreviouslogin as datep,";
416 $sql .=
" u.datelastpassvalidation,";
417 $sql .=
" u.datestartvalidity,";
418 $sql .=
" u.dateendvalidity,";
419 $sql .=
" u.photo as photo,";
420 $sql .=
" u.openid as openid,";
421 $sql .=
" u.accountancy_code,";
424 $sql .=
" u.salary,";
425 $sql .=
" u.salaryextra,";
426 $sql .=
" u.weeklyhours,";
428 $sql .=
" u.dateemployment, u.dateemploymentend,";
429 $sql .=
" u.fk_warehouse,";
430 $sql .=
" u.ref_ext,";
431 $sql .=
" u.default_range, u.default_c_exp_tax_cat,";
432 $sql .=
" c.code as country_code, c.label as country,";
433 $sql .=
" d.code_departement as state_code, d.nom as state";
434 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
435 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as c ON u.fk_country = c.rowid";
436 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as d ON u.fk_state = d.rowid";
439 if ((empty($conf->multicompany->enabled) || empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) && (!empty($user->entity))) {
440 $sql .=
" WHERE u.entity IN (0,".$conf->entity.
")";
442 $sql .=
" WHERE u.entity IS NOT NULL";
446 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
447 $sql .=
" WHERE u.entity IS NOT NULL";
449 $sql .=
" WHERE u.entity IN (0, ".(($entity !=
'' && $entity >= 0) ? $entity : $conf->entity).
")";
454 $sql .=
" AND (u.ldap_sid = '".$this->db->escape($sid).
"' OR u.login = '".$this->
db->escape($login).
"') LIMIT 1";
456 $sql .=
" AND u.login = '".$this->db->escape($login).
"'";
458 $sql .=
" AND u.email = '".$this->db->escape($email).
"'";
460 $sql .=
" AND u.rowid = ".$id;
462 $sql .=
" ORDER BY u.entity ASC";
464 $result = $this->
db->query($sql);
466 $obj = $this->
db->fetch_object($result);
468 $this->
id = $obj->rowid;
469 $this->ref = $obj->rowid;
471 $this->ref_ext = $obj->ref_ext;
473 $this->ldap_sid = $obj->ldap_sid;
474 $this->civility_code = $obj->civility_code;
475 $this->lastname = $obj->lastname;
476 $this->firstname = $obj->firstname;
478 $this->employee = $obj->employee;
480 $this->login = $obj->login;
481 $this->gender = $obj->gender;
482 $this->birth = $this->
db->jdate($obj->birth);
483 $this->pass_indatabase = $obj->pass;
484 $this->pass_indatabase_crypted = $obj->pass_crypted;
485 $this->pass = $obj->pass;
486 $this->pass_temp = $obj->pass_temp;
487 $this->api_key = $obj->api_key;
489 $this->address = $obj->address;
490 $this->zip = $obj->zip;
491 $this->town = $obj->town;
493 $this->country_id = $obj->country_id;
494 $this->country_code = $obj->country_id ? $obj->country_code :
'';
497 $this->state_id = $obj->state_id;
498 $this->state_code = $obj->state_code;
499 $this->state = ($obj->state !=
'-' ? $obj->state :
'');
501 $this->office_phone = $obj->office_phone;
502 $this->office_fax = $obj->office_fax;
503 $this->user_mobile = $obj->user_mobile;
504 $this->personal_mobile = $obj->personal_mobile;
505 $this->email = $obj->email;
506 $this->personal_email = $obj->personal_email;
507 $this->socialnetworks = (array) json_decode($obj->socialnetworks,
true);
508 $this->job = $obj->job;
509 $this->signature = $obj->signature;
510 $this->admin = $obj->admin;
511 $this->note_public = $obj->note_public;
512 $this->note_private = $obj->note_private;
513 $this->
note = $obj->note_private;
514 $this->
statut = $obj->statut;
515 $this->photo = $obj->photo;
516 $this->openid = $obj->openid;
517 $this->lang = $obj->lang;
518 $this->entity = $obj->entity;
519 $this->accountancy_code = $obj->accountancy_code;
520 $this->thm = $obj->thm;
521 $this->tjm = $obj->tjm;
522 $this->salary = $obj->salary;
523 $this->salaryextra = $obj->salaryextra;
524 $this->weeklyhours = $obj->weeklyhours;
525 $this->color = $obj->color;
526 $this->dateemployment = $this->
db->jdate($obj->dateemployment);
527 $this->dateemploymentend = $this->
db->jdate($obj->dateemploymentend);
529 $this->datec = $this->
db->jdate($obj->datec);
530 $this->datem = $this->
db->jdate($obj->datem);
531 $this->datelastlogin = $this->
db->jdate($obj->datel);
532 $this->datepreviouslogin = $this->
db->jdate($obj->datep);
533 $this->datestartvalidity = $this->
db->jdate($obj->datestartvalidity);
534 $this->dateendvalidity = $this->
db->jdate($obj->dateendvalidity);
536 $this->socid = $obj->fk_soc;
537 $this->contact_id = $obj->fk_socpeople;
538 $this->fk_member = $obj->fk_member;
539 $this->fk_user = $obj->fk_user;
540 $this->fk_user_expense_validator = $obj->fk_user_expense_validator;
541 $this->fk_user_holiday_validator = $obj->fk_user_holiday_validator;
543 $this->default_range = $obj->default_range;
544 $this->default_c_exp_tax_cat = $obj->default_c_exp_tax_cat;
545 $this->fk_warehouse = $obj->fk_warehouse;
549 if (empty($conf->multicompany->enabled) && $this->admin && $this->entity == 1) {
557 $this->
db->free($result);
559 $this->
error =
"USERNOTFOUND";
560 dol_syslog(get_class($this).
"::fetch user not found", LOG_DEBUG);
562 $this->
db->free($result);
566 $this->
error = $this->
db->lasterror();
571 if ($loadpersonalconf) {
573 $sql =
"SELECT param, value FROM ".MAIN_DB_PREFIX.
"user_param";
574 $sql .=
" WHERE fk_user = ".$this->id;
575 $sql .=
" AND entity = ".$conf->entity;
582 $obj = $this->
db->fetch_object(
$resql);
583 $p = (!empty($obj->param) ? $obj->param :
'');
585 $this->
conf->$p = $obj->value;
591 $this->
error = $this->
db->lasterror();
598 $this->
error = $this->
db->lasterror();
616 $sql =
"SELECT rowid, entity, type, page, param, value";
617 $sql .=
" FROM ".MAIN_DB_PREFIX.
"default_values";
618 $sql .=
" WHERE entity IN (".($this->entity > 0 ? $this->entity.
", " :
"").$conf->entity.
")";
619 $sql .=
" AND user_id IN (0".($this->id > 0 ?
", ".$this->id :
"").
")";
622 while ($obj = $this->
db->fetch_object(
$resql)) {
623 if (!empty($obj->page) && !empty($obj->type) && !empty($obj->param)) {
627 $pagewithoutquerystring = $obj->page;
630 if (preg_match(
'/^([^\?]+)\?(.*)$/', $pagewithoutquerystring, $reg)) {
631 $pagewithoutquerystring = $reg[1];
632 $pagequeries = $reg[2];
634 $this->default_values[$pagewithoutquerystring][$obj->type][$pagequeries ? $pagequeries :
'_noquery_'][$obj->param] = $obj->value;
639 if (!empty($this->default_values)) {
640 foreach ($this->default_values as $a => $b) {
641 foreach ($b as $c => $d) {
642 krsort($this->default_values[$a][$c]);
666 public function addrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
668 global $conf, $user, $langs;
670 $entity = (!empty($entity) ? $entity : $conf->entity);
672 dol_syslog(get_class($this).
"::addrights $rid, $allmodule, $allperms, $entity");
679 $module = $perms = $subperms =
'';
683 $sql =
"SELECT module, perms, subperms";
684 $sql .=
" FROM ".MAIN_DB_PREFIX.
"rights_def";
685 $sql .=
" WHERE id = ".((int) $rid);
686 $sql .=
" AND entity = ".((int) $entity);
688 $result = $this->
db->query($sql);
690 $obj = $this->
db->fetch_object($result);
693 $module = $obj->module;
694 $perms = $obj->perms;
695 $subperms = $obj->subperms;
703 $whereforadd =
"id=".((int) $rid);
705 if (!empty($subperms)) {
706 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->
db->escape($perms).
"' AND (subperms='lire' OR subperms='read'))";
707 } elseif (!empty($perms)) {
708 $whereforadd .=
" OR (module='".$this->db->escape($module).
"' AND (perms='lire' OR perms='read') AND subperms IS NULL)";
714 if (!empty($allmodule)) {
715 if ($allmodule ==
'allmodules') {
716 $whereforadd =
'allmodules';
718 $whereforadd =
"module='".$this->db->escape($allmodule).
"'";
719 if (!empty($allperms)) {
720 $whereforadd .=
" AND perms='".$this->db->escape($allperms).
"'";
727 if (!empty($whereforadd)) {
730 $sql .=
" FROM ".MAIN_DB_PREFIX.
"rights_def";
731 $sql .=
" WHERE entity = ".$entity;
732 if (!empty($whereforadd) && $whereforadd !=
'allmodules') {
733 $sql .=
" AND ".$whereforadd;
736 $result = $this->
db->query($sql);
738 $num = $this->
db->num_rows($result);
741 $obj = $this->
db->fetch_object($result);
744 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"user_rights WHERE fk_user = ".$this->
id.
" AND fk_id=".$nid.
" AND entity = ".$entity;
745 if (!$this->
db->query($sql)) {
748 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"user_rights (entity, fk_user, fk_id) VALUES (".$entity.
", ".$this->
id.
", ".$nid.
")";
749 if (!$this->
db->query($sql)) {
761 if (!$error && !$notrigger) {
762 $langs->load(
"other");
763 $this->context = array(
'audit'=>$langs->trans(
"PermissionsAdd").($rid ?
' (id='.$rid.
')' :
''));
774 $this->
db->rollback();
794 public function delrights($rid, $allmodule =
'', $allperms =
'', $entity = 0, $notrigger = 0)
796 global $conf, $user, $langs;
800 $entity = (!empty($entity) ? $entity : $conf->entity);
805 $module = $perms = $subperms =
'';
809 $sql =
"SELECT module, perms, subperms";
810 $sql .=
" FROM ".MAIN_DB_PREFIX.
"rights_def";
811 $sql .=
" WHERE id = '".$this->db->escape($rid).
"'";
812 $sql .=
" AND entity = ".$entity;
814 $result = $this->
db->query($sql);
816 $obj = $this->
db->fetch_object($result);
819 $module = $obj->module;
820 $perms = $obj->perms;
821 $subperms = $obj->subperms;
829 $wherefordel =
"id=".((int) $rid);
831 if ($subperms ==
'lire' || $subperms ==
'read') {
832 $wherefordel .=
" OR (module='".$this->db->escape($module).
"' AND perms='".$this->
db->escape($perms).
"' AND subperms IS NOT NULL)";
834 if ($perms ==
'lire' || $perms ==
'read') {
835 $wherefordel .=
" OR (module='".$this->db->escape($module).
"')";
840 if (!empty($allmodule)) {
841 if ($allmodule ==
'allmodules') {
842 $wherefordel =
'allmodules';
844 $wherefordel =
"module='".$this->db->escape($allmodule).
"'";
845 if (!empty($allperms)) {
846 $wherefordel .=
" AND perms='".$this->db->escape($allperms).
"'";
853 if (!empty($wherefordel)) {
856 $sql .=
" FROM ".MAIN_DB_PREFIX.
"rights_def";
857 $sql .=
" WHERE entity = ".$entity;
858 if (!empty($wherefordel) && $wherefordel !=
'allmodules') {
859 $sql .=
" AND ".$wherefordel;
863 if ($this->admin == 1) {
864 $sql .=
" AND id NOT IN (251, 252, 253, 254, 255, 256)";
865 $sql .=
" AND id NOT IN (341, 342, 343, 344)";
866 $sql .=
" AND id NOT IN (351, 352, 353, 354)";
867 $sql .=
" AND id NOT IN (358)";
870 $result = $this->
db->query($sql);
872 $num = $this->
db->num_rows($result);
875 $obj = $this->
db->fetch_object($result);
878 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"user_rights";
879 $sql .=
" WHERE fk_user = ".$this->id.
" AND fk_id=".$nid;
880 $sql .=
" AND entity = ".$entity;
881 if (!$this->
db->query($sql)) {
893 if (!$error && !$notrigger) {
894 $langs->load(
"other");
895 $this->context = array(
'audit'=>$langs->trans(
"PermissionsDelete").($rid ?
' (id='.$rid.
')' :
''));
906 $this->
db->rollback();
923 dol_syslog(get_class($this).
"::clearrights reset user->rights");
924 $this->rights = null;
925 $this->nb_rights = 0;
926 $this->all_permissions_are_loaded = 0;
927 $this->_tab_loaded = array();
939 public function getrights($moduletag =
'', $forcereload = 0)
943 if (empty($forcereload)) {
944 if ($moduletag && isset($this->_tab_loaded[$moduletag]) && $this->_tab_loaded[$moduletag]) {
949 if (!empty($this->all_permissions_are_loaded)) {
958 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
959 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur";
960 $sql .=
", ".MAIN_DB_PREFIX.
"rights_def as r";
961 $sql .=
" WHERE r.id = ur.fk_id";
962 if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
963 $sql .=
" AND r.entity IN (0,".(!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ?
"1," :
"").$conf->entity.
")";
965 $sql .=
" AND ur.entity = ".$conf->entity;
967 $sql .=
" AND ur.fk_user= ".$this->id;
968 $sql .=
" AND r.perms IS NOT NULL";
970 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
979 $obj = $this->
db->fetch_object(
$resql);
982 $module = $obj->module;
983 $perms = $obj->perms;
984 $subperms = $obj->subperms;
986 if (!empty($perms)) {
987 if (!isset($this->rights) || !is_object($this->rights)) {
988 $this->rights =
new stdClass();
990 if (!empty($module)) {
991 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
992 $this->rights->$module =
new stdClass();
994 if (!empty($subperms)) {
995 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
996 $this->rights->$module->$perms =
new stdClass();
998 if (empty($this->rights->$module->$perms->$subperms)) {
1001 $this->rights->$module->$perms->$subperms = 1;
1003 if (empty($this->rights->$module->$perms)) {
1006 $this->rights->$module->$perms = 1;
1017 $sql =
"SELECT DISTINCT r.module, r.perms, r.subperms";
1018 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_rights as gr,";
1019 $sql .=
" ".MAIN_DB_PREFIX.
"usergroup_user as gu,";
1020 $sql .=
" ".MAIN_DB_PREFIX.
"rights_def as r";
1021 $sql .=
" WHERE r.id = gr.fk_id";
1022 if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
1023 if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1024 $sql .=
" AND gu.entity IN (0,".$conf->entity.
")";
1026 $sql .=
" AND r.entity = ".$conf->entity;
1029 $sql .=
" AND gr.entity = ".$conf->entity;
1030 $sql .=
" AND gu.entity = ".$conf->entity;
1031 $sql .=
" AND r.entity = ".$conf->entity;
1033 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
1034 $sql .=
" AND gu.fk_user = ".$this->id;
1035 $sql .=
" AND r.perms IS NOT NULL";
1037 $sql .=
" AND r.module = '".$this->db->escape($moduletag).
"'";
1042 $num = $this->
db->num_rows(
$resql);
1045 $obj = $this->
db->fetch_object(
$resql);
1048 $module = $obj->module;
1049 $perms = $obj->perms;
1050 $subperms = $obj->subperms;
1052 if (!empty($perms)) {
1053 if (!isset($this->rights) || !is_object($this->rights)) {
1054 $this->rights =
new stdClass();
1056 if (!empty($module)) {
1057 if (!isset($this->rights->$module) || !is_object($this->rights->$module)) {
1058 $this->rights->$module =
new stdClass();
1060 if (!empty($subperms)) {
1061 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1062 $this->rights->$module->$perms =
new stdClass();
1064 if (empty($this->rights->$module->$perms->$subperms)) {
1067 $this->rights->$module->$perms->$subperms = 1;
1069 if (empty($this->rights->$module->$perms)) {
1073 if (!isset($this->rights->$module->$perms) || !is_object($this->rights->$module->$perms)) {
1074 $this->rights->$module->$perms = 1;
1086 if (isset($this->rights->propale) && !isset($this->rights->propal)) {
1087 $this->rights->propal = $this->rights->propale;
1089 if (isset($this->rights->propal) && !isset($this->rights->propale)) {
1090 $this->rights->propale = $this->rights->propal;
1096 $this->all_permissions_are_loaded = 1;
1099 $this->_tab_loaded[$moduletag] = 1;
1111 global $conf, $langs, $user;
1116 if ($this->
statut == $status) {
1125 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user";
1126 $sql .=
" SET statut = ".$this->statut;
1127 $sql .=
" WHERE rowid = ".$this->id;
1128 $result = $this->
db->query($sql);
1130 dol_syslog(get_class($this).
"::setstatus", LOG_DEBUG);
1133 $result = $this->
call_trigger(
'USER_ENABLEDISABLE', $user);
1141 $this->
db->rollback();
1144 $this->
db->commit();
1161 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1163 $type_categ = Categorie::TYPE_USER;
1166 if (!is_array($categories)) {
1167 $categories = array($categories);
1172 $existing = $c->containing($this->
id, $type_categ,
'id');
1175 if (is_array($existing)) {
1176 $to_del = array_diff($existing, $categories);
1177 $to_add = array_diff($categories, $existing);
1180 $to_add = $categories;
1184 foreach ($to_del as $del) {
1185 if ($c->fetch($del) > 0) {
1186 $c->del_type($this, $type_categ);
1189 foreach ($to_add as $add) {
1190 if ($c->fetch($add) > 0) {
1191 $c->add_type($this, $type_categ);
1206 global $conf, $langs;
1212 $this->
fetch($this->
id);
1214 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1217 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"user_rights WHERE fk_user = ".$this->id;
1219 if (!$error && !$this->
db->query($sql)) {
1221 $this->
error = $this->
db->lasterror();
1225 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"usergroup_user WHERE fk_user = ".$this->id;
1226 if (!$error && !$this->
db->query($sql)) {
1228 $this->
error = $this->
db->lasterror();
1232 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"user_param WHERE fk_user = ".$this->id;
1233 if (!$error && !$this->
db->query($sql)) {
1235 $this->
error = $this->
db->lasterror();
1239 if ($this->contact_id > 0) {
1240 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"socpeople SET fk_user_creat = null WHERE rowid = ".$this->contact_id;
1241 if (!$error && !$this->
db->query($sql)) {
1243 $this->
error = $this->
db->lasterror();
1252 dol_syslog(get_class($this).
"::delete error -4 ".$this->
error, LOG_ERR);
1258 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"user WHERE rowid = ".$this->id;
1259 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1260 if (!$this->
db->query($sql)) {
1262 $this->
error = $this->
db->lasterror();
1271 $this->
db->rollback();
1276 $this->
db->commit();
1279 $this->
db->rollback();
1291 public function create($user, $notrigger = 0)
1293 global $conf, $langs;
1299 $this->civility_code = trim($this->civility_code);
1300 $this->login = trim($this->login);
1301 if (!isset($this->entity)) {
1302 $this->entity = $conf->entity;
1305 dol_syslog(get_class($this).
"::create login=".$this->login.
", user=".(is_object($user) ? $user->id :
''), LOG_DEBUG);
1308 if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1309 $langs->load(
"errors");
1310 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1313 if (empty($this->login)) {
1314 $langs->load(
"errors");
1315 $this->
error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Login"));
1324 $sql =
"SELECT login FROM ".MAIN_DB_PREFIX.
"user";
1325 $sql .=
" WHERE login ='".$this->db->escape($this->login).
"'";
1326 $sql .=
" AND entity IN (0,".$this->db->escape($conf->entity).
")";
1328 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1331 $num = $this->
db->num_rows(
$resql);
1335 $this->
error =
'ErrorLoginAlreadyExists';
1337 $this->
db->rollback();
1340 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"user (datec,login,ldap_sid,entity)";
1341 $sql .=
" VALUES('".$this->db->idate($this->datec).
"','".$this->
db->escape($this->login).
"','".$this->
db->escape($this->ldap_sid).
"',".$this->
db->escape($this->entity).
")";
1342 $result = $this->
db->query($sql);
1344 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1346 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"user");
1350 $this->
error =
'ErrorFailedToSetDefaultRightOfUser';
1351 $this->
db->rollback();
1355 if (!empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER) && !empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) {
1356 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/entrepot.class.php';
1357 $langs->load(
"stocks");
1359 $entrepot->label = $langs->trans(
"PersonalStock", $this->
getFullName($langs));
1360 $entrepot->libelle = $entrepot->label;
1361 $entrepot->description = $langs->trans(
"ThisWarehouseIsPersonalStock", $this->
getFullName($langs));
1362 $entrepot->statut = 1;
1363 $entrepot->country_id = $mysoc->country_id;
1364 $warehouseid = $entrepot->create($user);
1366 $this->fk_warehouse = $warehouseid;
1370 $result = $this->
update($user, 1, 1);
1372 $this->
db->rollback();
1386 $this->
db->commit();
1391 $this->
db->rollback();
1395 $this->
error = $this->
db->lasterror();
1396 $this->
db->rollback();
1401 $this->
error = $this->
db->lasterror();
1402 $this->
db->rollback();
1420 global $conf, $user, $langs;
1426 $this->civility_code = $contact->civility_code;
1427 $this->lastname = $contact->lastname;
1428 $this->firstname = $contact->firstname;
1429 $this->gender = $contact->gender;
1430 $this->email = $contact->email;
1431 $this->socialnetworks = $contact->socialnetworks;
1432 $this->office_phone = $contact->phone_pro;
1433 $this->office_fax = $contact->fax;
1434 $this->user_mobile = $contact->phone_mobile;
1435 $this->address = $contact->address;
1436 $this->zip = $contact->zip;
1437 $this->town = $contact->town;
1438 $this->state_id = $contact->state_id;
1439 $this->country_id = $contact->country_id;
1440 $this->employee = 0;
1442 if (empty($login)) {
1443 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1444 $login =
dol_buildlogin($contact->lastname, $contact->firstname);
1446 $this->login = $login;
1451 $result = $this->
create($user, 1);
1453 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user";
1454 $sql .=
" SET fk_socpeople=".$contact->id;
1455 $sql .=
", civility='".$this->db->escape($contact->civility_code).
"'";
1456 if ($contact->socid > 0) {
1457 $sql .=
", fk_soc=".$contact->socid;
1459 $sql .=
" WHERE rowid=".((int) $this->
id);
1462 dol_syslog(get_class($this).
"::create_from_contact", LOG_DEBUG);
1464 $this->context[
'createfromcontact'] =
'createfromcontact';
1469 $error++; $this->
db->rollback();
return -1;
1473 $this->
db->commit();
1476 $this->
error = $this->
db->error();
1478 $this->
db->rollback();
1483 dol_syslog(get_class($this).
"::create_from_contact - 0");
1485 $this->
db->rollback();
1502 global $conf, $user, $langs;
1506 $this->civility_code = $member->civility_id;
1507 $this->lastname = $member->lastname;
1508 $this->firstname = $member->firstname;
1509 $this->gender = $member->gender;
1510 $this->email = $member->email;
1511 $this->fk_member = $member->id;
1512 $this->address = $member->address;
1513 $this->zip = $member->zip;
1514 $this->town = $member->town;
1515 $this->state_id = $member->state_id;
1516 $this->country_id = $member->country_id;
1517 $this->socialnetworks = $member->socialnetworks;
1519 $this->pass = $member->pass;
1520 $this->pass_crypted = $member->pass_indatabase_crypted;
1522 if (empty($login)) {
1523 include_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
1526 $this->login = $login;
1531 $result = $this->
create($user);
1533 if (!empty($this->pass)) {
1534 $newpass = $this->
setPassword($user, $this->pass);
1535 if (is_numeric($newpass) && $newpass < 0) {
1538 } elseif (!empty($this->pass_crypted)) {
1539 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user";
1540 $sql .=
" SET pass_crypted = '".$this->db->escape($this->pass_crypted).
"'";
1541 $sql .=
" WHERE rowid=".$this->id;
1549 if ($result > 0 && $member->fk_soc) {
1550 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user";
1551 $sql .=
" SET fk_soc=".$member->fk_soc;
1552 $sql .=
" WHERE rowid=".$this->id;
1554 dol_syslog(get_class($this).
"::create_from_member", LOG_DEBUG);
1557 $this->
db->commit();
1560 $this->
error = $this->
db->lasterror();
1562 $this->
db->rollback();
1569 $this->
db->commit();
1573 $this->
db->rollback();
1591 $sql =
"SELECT id FROM ".MAIN_DB_PREFIX.
"rights_def";
1592 $sql .=
" WHERE bydefault = 1";
1593 $sql .=
" AND entity = ".$conf->entity;
1597 $num = $this->
db->num_rows(
$resql);
1600 $row = $this->
db->fetch_row(
$resql);
1608 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]";
1609 $result = $this->
db->query($sql);
1611 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])";
1612 $result = $this->
db->query($sql);
1632 public function update($user, $notrigger = 0, $nosyncmember = 0, $nosyncmemberpass = 0, $nosynccontact = 0)
1634 global $conf, $langs;
1636 $nbrowsaffected = 0;
1639 dol_syslog(get_class($this).
"::update notrigger=".$notrigger.
", nosyncmember=".$nosyncmember.
", nosyncmemberpass=".$nosyncmemberpass);
1642 $this->civility_code = trim($this->civility_code);
1643 $this->lastname = trim($this->lastname);
1644 $this->firstname = trim($this->firstname);
1645 $this->employee = $this->employee ? $this->employee : 0;
1646 $this->login = trim($this->login);
1647 $this->gender = trim($this->gender);
1648 $this->pass = trim($this->pass);
1649 $this->api_key = trim($this->api_key);
1650 $this->address = $this->address ? trim($this->address) : trim($this->address);
1651 $this->zip = $this->zip ? trim($this->zip) : trim($this->zip);
1652 $this->town = $this->town ? trim($this->town) : trim($this->town);
1654 $this->state_id = trim($this->state_id);
1655 $this->country_id = ($this->country_id > 0) ? $this->country_id : 0;
1656 $this->office_phone = trim($this->office_phone);
1657 $this->office_fax = trim($this->office_fax);
1658 $this->user_mobile = trim($this->user_mobile);
1659 $this->personal_mobile = trim($this->personal_mobile);
1660 $this->email = trim($this->email);
1661 $this->personal_email = trim($this->personal_email);
1663 $this->job = trim($this->job);
1664 $this->signature = trim($this->signature);
1665 $this->note_public = trim($this->note_public);
1666 $this->note_private = trim($this->note_private);
1667 $this->openid = trim(empty($this->openid) ?
'' : $this->openid);
1668 $this->admin = $this->admin ? $this->admin : 0;
1669 $this->address = empty($this->address) ?
'' : $this->address;
1670 $this->zip = empty($this->zip) ?
'' : $this->zip;
1671 $this->town = empty($this->town) ?
'' : $this->town;
1672 $this->accountancy_code = trim($this->accountancy_code);
1673 $this->color = empty($this->color) ?
'' : $this->color;
1674 $this->dateemployment = empty($this->dateemployment) ?
'' : $this->dateemployment;
1675 $this->dateemploymentend = empty($this->dateemploymentend) ?
'' : $this->dateemploymentend;
1676 $this->datestartvalidity = empty($this->datestartvalidity) ?
'' : $this->datestartvalidity;
1677 $this->dateendvalidity = empty($this->dateendvalidity) ?
'' : $this->dateendvalidity;
1678 $this->birth = trim($this->birth);
1679 $this->fk_warehouse = (int) $this->fk_warehouse;
1682 if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
1683 $langs->load(
"errors");
1684 $this->
error = $langs->trans(
"ErrorBadEMail", $this->email);
1687 if (empty($this->login)) {
1688 $langs->load(
"errors");
1689 $this->
error = $langs->trans(
"ErrorFieldRequired",
'Login');
1696 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user SET";
1697 $sql .=
" civility = '".$this->db->escape($this->civility_code).
"'";
1698 $sql .=
", lastname = '".$this->db->escape($this->lastname).
"'";
1699 $sql .=
", firstname = '".$this->db->escape($this->firstname).
"'";
1700 $sql .=
", employee = ".(int) $this->employee;
1701 $sql .=
", login = '".$this->db->escape($this->login).
"'";
1702 $sql .=
", api_key = ".($this->api_key ?
"'".$this->db->escape($this->api_key).
"'" :
"null");
1703 $sql .=
", gender = ".($this->gender != -1 ?
"'".$this->db->escape($this->gender).
"'" :
"null");
1704 $sql .=
", birth=".(strval($this->birth) !=
'' ?
"'".$this->db->idate($this->birth).
"'" :
'null');
1705 if (!empty($user->admin)) {
1706 $sql .=
", admin = ".(int) $this->admin;
1708 $sql .=
", address = '".$this->db->escape($this->address).
"'";
1709 $sql .=
", zip = '".$this->db->escape($this->zip).
"'";
1710 $sql .=
", town = '".$this->db->escape($this->town).
"'";
1711 $sql .=
", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ?
"'".$this->
db->escape($this->state_id).
"'" :
"null");
1712 $sql .=
", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ?
"'".$this->
db->escape($this->country_id).
"'" :
"null");
1713 $sql .=
", office_phone = '".$this->db->escape($this->office_phone).
"'";
1714 $sql .=
", office_fax = '".$this->db->escape($this->office_fax).
"'";
1715 $sql .=
", user_mobile = '".$this->db->escape($this->user_mobile).
"'";
1716 $sql .=
", personal_mobile = '".$this->db->escape($this->personal_mobile).
"'";
1717 $sql .=
", email = '".$this->db->escape($this->email).
"'";
1718 $sql .=
", personal_email = '".$this->db->escape($this->personal_email).
"'";
1719 $sql .=
", socialnetworks = '".$this->db->escape(json_encode($this->socialnetworks)).
"'";
1720 $sql .=
", job = '".$this->db->escape($this->job).
"'";
1721 $sql .=
", signature = '".$this->db->escape($this->signature).
"'";
1722 $sql .=
", accountancy_code = '".$this->db->escape($this->accountancy_code).
"'";
1723 $sql .=
", color = '".$this->db->escape($this->color).
"'";
1724 $sql .=
", dateemployment=".(strval($this->dateemployment) !=
'' ?
"'".$this->db->idate($this->dateemployment).
"'" :
'null');
1725 $sql .=
", dateemploymentend=".(strval($this->dateemploymentend) !=
'' ?
"'".$this->db->idate($this->dateemploymentend).
"'" :
'null');
1726 $sql .=
", datestartvalidity=".(strval($this->datestartvalidity) !=
'' ?
"'".$this->db->idate($this->datestartvalidity).
"'" :
'null');
1727 $sql .=
", dateendvalidity=".(strval($this->dateendvalidity) !=
'' ?
"'".$this->db->idate($this->dateendvalidity).
"'" :
'null');
1728 $sql .=
", note = '".$this->db->escape($this->note_private).
"'";
1729 $sql .=
", note_public = '".$this->db->escape($this->note_public).
"'";
1730 $sql .=
", photo = ".($this->photo ?
"'".$this->db->escape($this->photo).
"'" :
"null");
1731 $sql .=
", openid = ".($this->openid ?
"'".$this->db->escape($this->openid).
"'" :
"null");
1732 $sql .=
", fk_user = ".($this->fk_user > 0 ?
"'".$this->db->escape($this->fk_user).
"'" :
"null");
1733 $sql .=
", fk_user_expense_validator = ".($this->fk_user_expense_validator > 0 ?
"'".$this->db->escape($this->fk_user_expense_validator).
"'" :
"null");
1734 $sql .=
", fk_user_holiday_validator = ".($this->fk_user_holiday_validator > 0 ?
"'".$this->db->escape($this->fk_user_holiday_validator).
"'" :
"null");
1735 if (isset($this->thm) || $this->thm !=
'') {
1736 $sql .=
", thm= ".($this->thm !=
'' ?
"'".$this->db->escape($this->thm).
"'" :
"null");
1738 if (isset($this->tjm) || $this->tjm !=
'') {
1739 $sql .=
", tjm= ".($this->tjm !=
'' ?
"'".$this->db->escape($this->tjm).
"'" :
"null");
1741 if (isset($this->salary) || $this->salary !=
'') {
1742 $sql .=
", salary= ".($this->salary !=
'' ?
"'".$this->db->escape($this->salary).
"'" :
"null");
1744 if (isset($this->salaryextra) || $this->salaryextra !=
'') {
1745 $sql .=
", salaryextra= ".($this->salaryextra !=
'' ?
"'".$this->db->escape($this->salaryextra).
"'" :
"null");
1747 $sql .=
", weeklyhours= ".($this->weeklyhours !=
'' ?
"'".$this->db->escape($this->weeklyhours).
"'" :
"null");
1748 $sql .=
", entity = '".$this->db->escape($this->entity).
"'";
1749 $sql .=
", default_range = ".($this->default_range > 0 ? $this->default_range :
'null');
1750 $sql .=
", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat :
'null');
1751 $sql .=
", fk_warehouse = ".($this->fk_warehouse > 0 ? $this->fk_warehouse :
"null");
1752 $sql .=
", lang = ".($this->lang ?
"'".$this->db->escape($this->lang).
"'" :
"null");
1753 $sql .=
" WHERE rowid = ".$this->id;
1755 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1758 $nbrowsaffected += $this->
db->affected_rows(
$resql);
1761 if (!empty($this->pass)) {
1762 if ($this->pass != $this->pass_indatabase && $this->pass != $this->pass_indatabase_crypted) {
1764 $result = $this->
setPassword($user, $this->pass, 0, $notrigger, $nosyncmemberpass);
1765 if (!$nbrowsaffected) {
1772 if ($this->fk_member > 0) {
1773 dol_syslog(get_class($this).
"::update remove link with member. We will recreate it later", LOG_DEBUG);
1774 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user SET fk_member = NULL where fk_member = ".$this->fk_member;
1777 $this->
error = $this->
db->error(); $this->
db->rollback();
return -5;
1781 dol_syslog(get_class($this).
"::update set link with member", LOG_DEBUG);
1782 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user SET fk_member =".($this->fk_member > 0 ? $this->fk_member :
'null').
" where rowid = ".$this->
id;
1785 $this->
error = $this->
db->error(); $this->
db->rollback();
return -5;
1788 if ($nbrowsaffected) {
1789 if ($this->fk_member > 0 && !$nosyncmember) {
1790 dol_syslog(get_class($this).
"::update user is linked with a member. We try to update member too.", LOG_DEBUG);
1792 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
1797 $result = $adh->fetch($this->fk_member);
1800 $adh->civility_code = $this->civility_code;
1801 $adh->firstname = $this->firstname;
1802 $adh->lastname = $this->lastname;
1803 $adh->login = $this->login;
1804 $adh->gender = $this->gender;
1805 $adh->birth = $this->birth;
1807 $adh->pass = $this->pass;
1811 $adh->address = $this->address;
1812 $adh->town = $this->town;
1813 $adh->zip = $this->zip;
1814 $adh->state_id = $this->state_id;
1815 $adh->country_id = $this->country_id;
1817 $adh->email = $this->email;
1819 $adh->socialnetworks = $this->socialnetworks;
1821 $adh->phone = $this->office_phone;
1822 $adh->phone_mobile = $this->user_mobile;
1824 $adh->user_id = $this->id;
1825 $adh->user_login = $this->login;
1827 $result = $adh->update($user, 0, 1, 0);
1829 $this->
error = $adh->error;
1830 $this->errors = $adh->errors;
1831 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
1834 } elseif ($result < 0) {
1835 $this->
error = $adh->error;
1836 $this->errors = $adh->errors;
1841 if ($this->contact_id > 0 && !$nosynccontact) {
1842 dol_syslog(get_class($this).
"::update user is linked with a contact. We try to update contact too.", LOG_DEBUG);
1844 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1848 $result = $tmpobj->fetch($this->contact_id);
1851 $tmpobj->civility_code = $this->civility_code;
1852 $tmpobj->firstname = $this->firstname;
1853 $tmpobj->lastname = $this->lastname;
1854 $tmpobj->login = $this->login;
1855 $tmpobj->gender = $this->gender;
1856 $tmpobj->birth = $this->birth;
1862 $tmpobj->email = $this->email;
1864 $tmpobj->socialnetworks = $this->socialnetworks;
1866 $tmpobj->phone_pro = $this->office_phone;
1867 $tmpobj->phone_mobile = $this->user_mobile;
1868 $tmpobj->fax = $this->office_fax;
1870 $tmpobj->address = $this->address;
1871 $tmpobj->town = $this->town;
1872 $tmpobj->zip = $this->zip;
1873 $tmpobj->state_id = $this->state_id;
1874 $tmpobj->country_id = $this->country_id;
1876 $tmpobj->user_id = $this->id;
1877 $tmpobj->user_login = $this->login;
1879 $result = $tmpobj->update($tmpobj->id, $user, 0,
'update', 1);
1881 $this->
error = $tmpobj->error;
1882 $this->errors = $tmpobj->errors;
1883 dol_syslog(get_class($this).
"::update error after calling adh->update to sync it with user: ".$this->
error, LOG_ERR);
1887 $this->
error = $tmpobj->error;
1888 $this->errors = $tmpobj->errors;
1904 if (!$error && !$notrigger) {
1914 $this->
db->commit();
1915 return $nbrowsaffected;
1918 $this->
db->rollback();
1922 $this->
error = $this->
db->lasterror();
1923 $this->
db->rollback();
1940 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user SET";
1941 $sql .=
" datepreviouslogin = datelastlogin,";
1942 $sql .=
" datelastlogin = '".$this->db->idate($now).
"',";
1943 $sql .=
" tms = tms";
1944 $sql .=
" WHERE rowid = ".$this->id;
1946 dol_syslog(get_class($this).
"::update_last_login_date user->id=".$this->
id.
" ".$sql, LOG_DEBUG);
1949 $this->datepreviouslogin = $this->datelastlogin;
1950 $this->datelastlogin = $now;
1953 $this->
error = $this->
db->lasterror().
' sql='.$sql;
1969 public function setPassword($user, $password =
'', $changelater = 0, $notrigger = 0, $nosyncmember = 0)
1971 global $conf, $langs;
1972 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
1976 dol_syslog(get_class($this).
"::setPassword user=".$user->id.
" password=".preg_replace(
'/./i',
'*', $password).
" changelater=".$changelater.
" notrigger=".$notrigger.
" nosyncmember=".$nosyncmember, LOG_DEBUG);
1984 $password_crypted =
dol_hash($password);
1987 if (!$changelater) {
1988 if (!is_object($this->oldcopy)) {
1989 $this->oldcopy = clone $this;
1994 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user";
1995 $sql .=
" SET pass_crypted = '".$this->db->escape($password_crypted).
"',";
1996 $sql .=
" pass_temp = null";
1997 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
1998 $sql .=
", pass = null";
2000 $sql .=
", pass = '".$this->db->escape($password).
"'";
2002 $sql .=
" WHERE rowid = ".$this->id;
2004 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2005 $result = $this->
db->query($sql);
2007 if ($this->
db->affected_rows($result)) {
2008 $this->pass = $password;
2009 $this->pass_indatabase = $password;
2010 $this->pass_indatabase_crypted = $password_crypted;
2012 if ($this->fk_member && !$nosyncmember) {
2013 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
2018 $result = $adh->fetch($this->fk_member);
2021 $result = $adh->setPassword($user, $this->pass, (empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1), 1);
2023 $this->
error = $adh->error;
2028 $this->
error = $adh->error;
2033 dol_syslog(get_class($this).
"::setPassword notrigger=".$notrigger.
" error=".$error, LOG_DEBUG);
2035 if (!$error && !$notrigger) {
2037 $result = $this->
call_trigger(
'USER_NEW_PASSWORD', $user);
2039 $error++; $this->
db->rollback();
return -1;
2044 $this->
db->commit();
2047 $this->
db->rollback();
2051 $this->
db->rollback();
2058 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"user";
2059 $sql .=
" SET pass_temp = '".$this->db->escape($password).
"'";
2060 $sql .=
" WHERE rowid = ".$this->id;
2062 dol_syslog(get_class($this).
"::setPassword", LOG_DEBUG);
2063 $result = $this->
db->query($sql);
2086 global $conf, $langs;
2087 global $dolibarr_main_url_root;
2089 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2096 $outputlangs =
new Translate(
"", $conf);
2098 if (isset($this->
conf->MAIN_LANG_DEFAULT)
2099 && $this->conf->MAIN_LANG_DEFAULT !=
'auto') {
2100 $outputlangs->getDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2103 if ($this->
conf->MAIN_LANG_DEFAULT) {
2104 $outputlangs->setDefaultLang($this->
conf->MAIN_LANG_DEFAULT);
2106 $outputlangs = $langs;
2110 $outputlangs->loadLangs(array(
"main",
"errors",
"users",
"other"));
2112 $appli = constant(
'DOL_APPLICATION_TITLE');
2113 if (!empty($conf->global->MAIN_APPLICATION_TITLE)) {
2114 $appli = $conf->global->MAIN_APPLICATION_TITLE;
2117 $subject = $outputlangs->transnoentitiesnoconv(
"SubjectNewPassword", $appli);
2120 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2121 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2123 if (!$changelater) {
2124 $url = $urlwithroot.
'/';
2125 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
".\n";
2126 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyIs").
" :\n\n";
2127 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2128 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2131 $mesg .= $outputlangs->transnoentitiesnoconv(
"ClickHereToGoTo", $appli).
': '.$url.
"\n\n";
2133 $mesg .= $user->getFullName($outputlangs);
2135 dol_syslog(get_class($this).
"::send_password changelater is off, url=".$url);
2137 $url = $urlwithroot.
'/user/passwordforgotten.php?action=validatenewpassword&username='.urlencode($this->login).
"&passwordhash=".
dol_hash($password);
2139 $mesg .= $outputlangs->transnoentitiesnoconv(
"RequestToResetPasswordReceived").
"\n";
2140 $mesg .= $outputlangs->transnoentitiesnoconv(
"NewKeyWillBe").
" :\n\n";
2141 $mesg .= $outputlangs->transnoentitiesnoconv(
"Login").
" = ".$this->login.
"\n";
2142 $mesg .= $outputlangs->transnoentitiesnoconv(
"Password").
" = ".$password.
"\n\n";
2144 $mesg .= $outputlangs->transnoentitiesnoconv(
"YouMustClickToChange").
" :\n";
2145 $mesg .= $url.
"\n\n";
2146 $mesg .= $outputlangs->transnoentitiesnoconv(
"ForgetIfNothing").
"\n\n";
2148 dol_syslog(get_class($this).
"::send_password changelater is on, url=".$url);
2151 $trackid =
'use'.$this->id;
2156 $conf->global->MAIN_MAIL_EMAIL_FROM,
2170 if ($mailfile->sendfile()) {
2173 $langs->trans(
"errors");
2174 $this->
error = $langs->trans(
"ErrorFailedToSendPassword").
' '.$mailfile->error;
2186 return $this->error;
2199 $sql =
"SELECT url, login, pass, poste ";
2200 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_clicktodial as u";
2201 $sql .=
" WHERE u.fk_user = ".$this->id;
2206 $obj = $this->
db->fetch_object(
$resql);
2208 $this->clicktodial_url = $obj->url;
2209 $this->clicktodial_login = $obj->login;
2210 $this->clicktodial_password = $obj->pass;
2211 $this->clicktodial_poste = $obj->poste;
2214 $this->clicktodial_loaded = 1;
2219 $this->
error = $this->
db->error();
2235 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"user_clicktodial";
2236 $sql .=
" WHERE fk_user = ".$this->id;
2238 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2239 $result = $this->
db->query($sql);
2241 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"user_clicktodial";
2242 $sql .=
" (fk_user,url,login,pass,poste)";
2243 $sql .=
" VALUES (".$this->id;
2244 $sql .=
", '".$this->db->escape($this->clicktodial_url).
"'";
2245 $sql .=
", '".$this->db->escape($this->clicktodial_login).
"'";
2246 $sql .=
", '".$this->db->escape($this->clicktodial_password).
"'";
2247 $sql .=
", '".$this->db->escape($this->clicktodial_poste).
"')";
2249 dol_syslog(get_class($this).
'::update_clicktodial', LOG_DEBUG);
2250 $result = $this->
db->query($sql);
2252 $this->
db->commit();
2255 $this->
db->rollback();
2256 $this->
error = $this->
db->lasterror();
2274 global $conf, $langs, $user;
2280 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"usergroup_user";
2281 $sql .=
" WHERE fk_user = ".$this->id;
2282 $sql .=
" AND fk_usergroup = ".$group;
2283 $sql .=
" AND entity = ".$entity;
2285 $result = $this->
db->query($sql);
2287 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"usergroup_user (entity, fk_user, fk_usergroup)";
2288 $sql .=
" VALUES (".$entity.
",".$this->
id.
",".$group.
")";
2290 $result = $this->
db->query($sql);
2292 if (!$error && !$notrigger) {
2293 $this->newgroupid = $group;
2294 $this->context = array(
'audit'=>$langs->trans(
"UserSetInGroup"),
'newgroupid'=>$group);
2305 $this->
db->commit();
2309 $this->
db->rollback();
2313 $this->
error = $this->
db->lasterror();
2314 $this->
db->rollback();
2331 global $conf, $langs, $user;
2337 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"usergroup_user";
2338 $sql .=
" WHERE fk_user = ".$this->id;
2339 $sql .=
" AND fk_usergroup = ".$group;
2340 $sql .=
" AND entity = ".$entity;
2342 $result = $this->
db->query($sql);
2344 if (!$error && !$notrigger) {
2345 $this->oldgroupid = $group;
2346 $this->context = array(
'audit'=>$langs->trans(
"UserRemovedFromGroup"),
'oldgroupid'=>$group);
2357 $this->
db->commit();
2360 dol_syslog(get_class($this).
"::RemoveFromGroup ".$this->
error, LOG_ERR);
2361 $this->
db->rollback();
2365 $this->
error = $this->
db->lasterror();
2366 $this->
db->rollback();
2382 public function getPhotoUrl($width, $height, $cssclass =
'', $imagesize =
'')
2384 $result =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2385 $result .=
Form::showphoto(
'userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
2406 public function getNomUrl($withpictoimg = 0, $option =
'', $infologin = 0, $notooltip = 0, $maxlen = 24, $hidethirdpartylogo = 0, $mode =
'', $morecss =
'', $save_lastsearch_value = -1)
2408 global $langs, $conf, $db, $hookmanager, $user;
2409 global $dolibarr_main_authentication, $dolibarr_main_demo;
2410 global $menumanager;
2412 if (!$user->rights->user->user->lire && $user->id != $this->id) {
2416 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) && $withpictoimg) {
2420 $result =
''; $label =
'';
2423 if (!empty($this->photo)) {
2424 $label .=
'<div class="photointooltip">';
2425 $label .=
Form::showphoto(
'userphoto', $this, 0, 60, 0,
'photowithmargin photologintooltip',
'small', 0, 1);
2426 $label .=
'</div><div style="clear: both;"></div>';
2430 $label .=
'<div class="centpercent">';
2431 $label .=
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"User").
'</u>';
2432 $label .=
' '.$this->getLibStatut(4);
2434 if (!empty($this->login)) {
2437 if (!empty($this->job)) {
2441 if (!empty($this->phone)) {
2444 if (!empty($this->admin)) {
2445 $label .=
'<br><b>'.$langs->trans(
"Administrator").
'</b>: '.
yn($this->admin);
2448 if (!empty($this->socid)) {
2449 $thirdpartystatic =
new Societe($db);
2450 $thirdpartystatic->fetch($this->socid);
2451 if (empty($hidethirdpartylogo)) {
2452 $companylink =
' '.$thirdpartystatic->getNomUrl(2, (($option ==
'nolink') ?
'nolink' :
''));
2454 $company =
' ('.$langs->trans(
"Company").
': '.
dol_string_nohtmltag($thirdpartystatic->name).
')';
2456 $type = ($this->socid ? $langs->trans(
"External").$company : $langs->trans(
"Internal"));
2459 if ($infologin > 0) {
2461 $label .=
'<br><u>'.$langs->trans(
"Session").
'</u>';
2463 if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) {
2464 $label .=
'<br><b>'.$langs->trans(
"ConnectedOnMultiCompany").
':</b> '.$conf->entity.
' (User entity '.$this->entity.
')';
2466 $label .=
'<br><b>'.$langs->trans(
"AuthenticationMode").
':</b> '.
dol_string_nohtmltag($_SESSION[
"dol_authmode"].(empty($dolibarr_main_demo) ?
'' :
' (demo)'));
2467 $label .=
'<br><b>'.$langs->trans(
"ConnectedSince").
':</b> '.
dol_print_date($this->datelastlogin,
"dayhour",
'tzuser');
2468 $label .=
'<br><b>'.$langs->trans(
"PreviousConnexion").
':</b> '.
dol_print_date($this->datepreviouslogin,
"dayhour",
'tzuser');
2470 $label .=
'<br><b>'.$langs->trans(
"CurrentMenuManager").
':</b> '.
dol_string_nohtmltag($menumanager->name);
2472 $label .=
'<br><b>'.$langs->trans(
"CurrentUserLanguage").
':</b> '.
dol_string_nohtmltag(($s ? $s.
' ' :
'').$langs->getDefaultLang());
2473 $label .=
'<br><b>'.$langs->trans(
"Browser").
':</b> '.
dol_string_nohtmltag($conf->browser->name.($conf->browser->version ?
' '.$conf->browser->version :
'').
' ('.
$_SERVER[
'HTTP_USER_AGENT'].
')');
2474 $label .=
'<br><b>'.$langs->trans(
"Layout").
':</b> '.
dol_string_nohtmltag($conf->browser->layout);
2475 $label .=
'<br><b>'.$langs->trans(
"Screen").
':</b> '.
dol_string_nohtmltag($_SESSION[
'dol_screenwidth'].
' x '.$_SESSION[
'dol_screenheight']);
2476 if ($conf->browser->layout ==
'phone') {
2477 $label .=
'<br><b>'.$langs->trans(
"Phone").
':</b> '.$langs->trans(
"Yes");
2479 if (!empty($_SESSION[
"disablemodules"])) {
2480 $label .=
'<br><b>'.$langs->trans(
"DisabledModules").
':</b> <br>'.
dol_string_nohtmltag(join(
', ', explode(
',', $_SESSION[
"disablemodules"])));
2483 if ($infologin < 0) {
2487 $url = DOL_URL_ROOT.
'/user/card.php?id='.$this->id;
2488 if ($option ==
'leave') {
2489 $url = DOL_URL_ROOT.
'/holiday/list.php?id='.$this->id;
2492 if ($option !=
'nolink') {
2494 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2495 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) {
2496 $add_save_lastsearch_values = 1;
2498 if ($add_save_lastsearch_values) {
2499 $url .=
'&save_lastsearch_values=1';
2503 $linkstart =
'<a href="'.$url.
'"';
2505 if (empty($notooltip)) {
2506 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2507 $langs->load(
"users");
2508 $label = $langs->trans(
"ShowUser");
2509 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2511 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
2512 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
2522 $linkstart .= $linkclose.
'>';
2526 $result .= (($option ==
'nolink') ?
'' : $linkstart);
2527 if ($withpictoimg) {
2528 $paddafterimage =
'';
2529 if (abs($withpictoimg) == 1) {
2530 $paddafterimage =
'style="margin-'.($langs->trans(
"DIRECTION") ==
'rtl' ?
'left' :
'right').
': 3px;"';
2533 if ($withpictoimg > 0) {
2534 $picto =
'<!-- picto user --><span class="nopadding userimg'.($morecss ?
' '.$morecss :
'').
'">'.
img_object(
'',
'user', $paddafterimage.
' '.($notooltip ?
'' :
'class="paddingright classfortooltip"'), 0, 0, $notooltip ? 0 : 1).
'</span>';
2538 $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>';
2542 if ($withpictoimg > -2 && $withpictoimg != 2) {
2543 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2544 $result .=
'<span class="nopadding usertext'.((!isset($this->
statut) || $this->statut) ?
'' :
' strikefordisabled').($morecss ?
' '.$morecss :
'').
'">';
2546 if ($mode ==
'login') {
2551 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2552 $result .=
'</span>';
2555 $result .= (($option ==
'nolink') ?
'' : $linkend);
2558 $result .= $companylink;
2561 $hookmanager->initHooks(array(
'userdao'));
2562 $parameters = array(
'id'=>$this->
id,
'getnomurl'=>$result);
2563 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2565 $result = $hookmanager->resPrint;
2567 $result .= $hookmanager->resPrint;
2582 global $langs, $user;
2586 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2590 if ((!$user->rights->user->user->lire && $this->id != $user->id)) {
2594 if ($option ==
'xxx') {
2595 $linkstart =
'<a href="'.DOL_URL_ROOT.
'/user/card.php?id='.$this->
id.
'">';
2599 if ($option ==
'nolink') {
2604 $result .= $linkstart;
2606 $result .=
img_object($langs->trans(
"ShowUser"),
'user',
'class="paddingright"');
2608 $result .= $this->login;
2609 $result .= $linkend;
2637 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
2640 $this->labelStatus[self::STATUS_ENABLED] = $langs->trans(
'Enabled');
2641 $this->labelStatus[self::STATUS_DISABLED] = $langs->trans(
'Disabled');
2642 $this->labelStatusShort[self::STATUS_ENABLED] = $langs->trans(
'Enabled');
2643 $this->labelStatusShort[self::STATUS_DISABLED] = $langs->trans(
'Disabled');
2646 $statusType =
'status5';
2647 if ($status == self::STATUS_ENABLED) {
2648 $statusType =
'status4';
2651 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
2672 $dn = $conf->global->LDAP_KEY_USERS.
"=".$info[$conf->global->LDAP_KEY_USERS].
",".$conf->global->LDAP_USER_DN;
2673 } elseif ($mode == 1) {
2674 $dn = $conf->global->LDAP_USER_DN;
2675 } elseif ($mode == 2) {
2676 $dn = $conf->global->LDAP_KEY_USERS.
"=".$info[$conf->global->LDAP_KEY_USERS];
2691 global $conf, $langs;
2697 $keymodified =
false;
2700 $info[
"objectclass"] = explode(
',', $conf->global->LDAP_USER_OBJECT_CLASS);
2706 'LDAP_FIELD_FULLNAME' =>
'fullname',
2707 'LDAP_FIELD_NAME' =>
'lastname',
2708 'LDAP_FIELD_FIRSTNAME' =>
'firstname',
2709 'LDAP_FIELD_LOGIN' =>
'login',
2710 'LDAP_FIELD_LOGIN_SAMBA'=>
'login',
2711 'LDAP_FIELD_PHONE' =>
'office_phone',
2712 'LDAP_FIELD_MOBILE' =>
'user_mobile',
2713 'LDAP_FIELD_FAX' =>
'office_fax',
2714 'LDAP_FIELD_MAIL' =>
'email',
2715 'LDAP_FIELD_SID' =>
'ldap_sid',
2719 foreach ($ldapkey as $constname => $varname) {
2720 if (!empty($this->$varname) && !empty($conf->global->$constname)) {
2721 $info[$conf->global->$constname] = $this->$varname;
2724 if (!empty($conf->global->LDAP_KEY_USERS) && $conf->global->LDAP_KEY_USERS == $conf->global->$constname) {
2725 if (!empty($this->oldcopy) && $this->$varname != $this->oldcopy->$varname) {
2726 $keymodified =
true;
2731 foreach ($socialnetworks as $key => $value) {
2732 if ($this->socialnetworks[$value[
'label']] && !empty($conf->global->{
'LDAP_FIELD_'.strtoupper($value[
'label'])})) {
2733 $info[$conf->global->{
'LDAP_FIELD_'.strtoupper($value[
'label'])}] = $this->socialnetworks[$value[
'label']];
2736 if ($this->address && !empty($conf->global->LDAP_FIELD_ADDRESS)) {
2737 $info[$conf->global->LDAP_FIELD_ADDRESS] = $this->address;
2739 if ($this->zip && !empty($conf->global->LDAP_FIELD_ZIP)) {
2740 $info[$conf->global->LDAP_FIELD_ZIP] = $this->zip;
2742 if ($this->town && !empty($conf->global->LDAP_FIELD_TOWN)) {
2743 $info[$conf->global->LDAP_FIELD_TOWN] = $this->town;
2745 if ($this->note_public && !empty($conf->global->LDAP_FIELD_DESCRIPTION)) {
2748 if ($this->socid > 0) {
2750 $soc->fetch($this->socid);
2752 $info[$conf->global->LDAP_FIELD_COMPANY] = $soc->name;
2753 if ($soc->client == 1) {
2754 $info[
"businessCategory"] =
"Customers";
2756 if ($soc->client == 2) {
2757 $info[
"businessCategory"] =
"Prospects";
2759 if ($soc->fournisseur == 1) {
2760 $info[
"businessCategory"] =
"Suppliers";
2765 if (!empty($this->pass)) {
2766 if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
2767 $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass;
2769 if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
2770 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass, 4);
2774 elseif ($conf->global->LDAP_SERVER_PROTOCOLVERSION !==
'3') {
2775 if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
2777 if (empty($conf->global->MAIN_SECURITY_HASH_ALGO)) {
2778 if ($this->pass_indatabase_crypted && !empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
2779 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass_indatabase_crypted, 5);
2784 elseif (!empty($this->pass_indatabase)) {
2785 if (!empty($conf->global->LDAP_FIELD_PASSWORD)) {
2786 $info[$conf->global->LDAP_FIELD_PASSWORD] = $this->pass_indatabase;
2788 if (!empty($conf->global->LDAP_FIELD_PASSWORD_CRYPTED)) {
2789 $info[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED] =
dol_hash($this->pass_indatabase, 4);
2794 if ($conf->global->LDAP_SERVER_TYPE ==
'egroupware') {
2795 $info[
"objectclass"][4] =
"phpgwContact";
2797 $info[
'uidnumber'] = $this->id;
2799 $info[
'phpgwTz'] = 0;
2800 $info[
'phpgwMailType'] =
'INTERNET';
2801 $info[
'phpgwMailHomeType'] =
'INTERNET';
2803 $info[
"phpgwContactTypeId"] =
'n';
2804 $info[
"phpgwContactCatId"] = 0;
2805 $info[
"phpgwContactAccess"] =
"public";
2808 $this->egroupware_id = 1;
2811 $info[
"phpgwContactOwner"] = $this->egroupware_id;
2814 $info[
"rfc822Mailbox"] = $this->email;
2816 if ($this->phone_mobile) {
2817 $info[
"phpgwCellTelephoneNumber"] = $this->phone_mobile;
2821 if (!empty($conf->global->LDAP_FIELD_USERID)) {
2822 $info[$conf->global->LDAP_FIELD_USERID] = $this->id;
2824 if (!empty($info[$conf->global->LDAP_FIELD_GROUPID])) {
2826 $groupslist = $usergroup->listGroupsForUser($this->
id);
2827 $info[$conf->global->LDAP_FIELD_GROUPID] =
'1';
2828 if (!empty($groupslist)) {
2829 foreach ($groupslist as $groupforuser) {
2830 $info[$conf->global->LDAP_FIELD_GROUPID] = $groupforuser->id;
2835 if (!empty($this->firstname) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORY) && !empty($conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX)) {
2836 $info[$conf->global->LDAP_FIELD_HOMEDIRECTORY] =
"{$conf->global->LDAP_FIELD_HOMEDIRECTORYPREFIX}/$this->firstname";
2852 global $user, $langs;
2858 $this->ref =
'SPECIMEN';
2859 $this->specimen = 1;
2861 $this->lastname =
'DOLIBARR';
2862 $this->firstname =
'SPECIMEN';
2863 $this->gender =
'man';
2864 $this->note_public =
'This is a note public';
2865 $this->note_private =
'This is a note private';
2866 $this->email =
'email@specimen.com';
2867 $this->personal_email =
'personalemail@specimen.com';
2868 $this->socialnetworks = array(
2869 'skype' =>
'skypepseudo',
2870 'twitter' =>
'twitterpseudo',
2871 'facebook' =>
'facebookpseudo',
2872 'linkedin' =>
'linkedinpseudo',
2874 $this->office_phone =
'0999999999';
2875 $this->office_fax =
'0999999998';
2876 $this->user_mobile =
'0999999997';
2877 $this->personal_mobile =
'0999999996';
2879 $this->login =
'dolibspec';
2880 $this->pass =
'dolibspec';
2883 $this->datec = $now;
2884 $this->datem = $now;
2886 $this->datelastlogin = $now;
2887 $this->datepreviouslogin = $now;
2902 $sql =
"SELECT u.rowid, u.login as ref, u.datec,";
2903 $sql .=
" u.tms as date_modification, u.entity";
2904 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
2905 $sql .=
" WHERE u.rowid = ".$id;
2907 $result = $this->
db->query($sql);
2909 if ($this->
db->num_rows($result)) {
2910 $obj = $this->
db->fetch_object($result);
2912 $this->
id = $obj->rowid;
2914 $this->ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
2915 $this->date_creation = $this->db->jdate($obj->datec);
2916 $this->date_modification = $this->
db->jdate($obj->date_modification);
2917 $this->entity = $obj->entity;
2920 $this->
db->free($result);
2934 $sql =
"SELECT count(mc.email) as nb";
2935 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mailing_cibles as mc";
2936 $sql .=
" WHERE mc.email = '".$this->db->escape($this->email).
"'";
2937 $sql .=
" AND mc.statut NOT IN (-1,0)";
2941 $obj = $this->
db->fetch_object(
$resql);
2947 $this->error = $this->
db->error();
2964 $sql =
"SELECT count(rowid) as nb";
2965 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user";
2966 if ($option ==
'superadmin') {
2967 $sql .=
" WHERE entity = 0";
2969 $sql .=
" WHERE entity IN (".getEntity(
'user', 0).
")";
2970 if ($limitTo ==
'active') {
2971 $sql .=
" AND statut = 1";
2975 $sql .=
" AND admin = ".(int) $admin;
2980 $obj = $this->
db->fetch_object(
$resql);
2981 $nb = (int) $obj->nb;
2986 $this->error = $this->
db->lasterror();
3002 global $user, $conf;
3006 $this->firstname = $ldapuser->{$conf->global->LDAP_FIELD_FIRSTNAME};
3007 $this->lastname = $ldapuser->{$conf->global->LDAP_FIELD_NAME};
3008 $this->login = $ldapuser->{$conf->global->LDAP_FIELD_LOGIN};
3009 $this->pass = $ldapuser->{$conf->global->LDAP_FIELD_PASSWORD};
3010 $this->pass_indatabase_crypted = $ldapuser->{$conf->global->LDAP_FIELD_PASSWORD_CRYPTED};
3012 $this->office_phone = $ldapuser->{$conf->global->LDAP_FIELD_PHONE};
3013 $this->user_mobile = $ldapuser->{$conf->global->LDAP_FIELD_MOBILE};
3014 $this->office_fax = $ldapuser->{$conf->global->LDAP_FIELD_FAX};
3015 $this->email = $ldapuser->{$conf->global->LDAP_FIELD_MAIL};
3016 foreach ($socialnetworks as $key => $value) {
3017 $tmpkey =
'LDAP_FIELD_'.strtoupper($value[
'label']);
3018 $this->socialnetworks[$value[
'label']] = $ldapuser->{$conf->global->$tmpkey};
3020 $this->ldap_sid = $ldapuser->{$conf->global->LDAP_FIELD_SID};
3022 $this->job = $ldapuser->{$conf->global->LDAP_FIELD_TITLE};
3023 $this->note_public = $ldapuser->{$conf->global->LDAP_FIELD_DESCRIPTION};
3025 $result = $this->update($user);
3027 dol_syslog(get_class($this).
"::update_ldap2dolibarr result=".$result, LOG_DEBUG);
3043 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"user";
3044 $sql .=
" WHERE fk_user = ".$this->id;
3046 dol_syslog(get_class($this).
"::get_children sql=".$sql, LOG_DEBUG);
3047 $res = $this->
db->query($sql);
3050 while ($rec = $this->
db->fetch_array($res)) {
3051 $user =
new User($this->
db);
3052 $user->fetch($rec[
'rowid']);
3072 $this->parentof = array();
3075 $sql =
"SELECT fk_user as id_parent, rowid as id_son";
3076 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user";
3077 $sql .=
" WHERE fk_user <> 0";
3078 $sql .=
" AND entity IN (".getEntity(
'user').
")";
3080 dol_syslog(get_class($this).
"::loadParentOf", LOG_DEBUG);
3083 while ($obj = $this->
db->fetch_object(
$resql)) {
3084 $this->parentof[$obj->id_son] = $obj->id_parent;
3110 global $conf, $user;
3111 global $hookmanager;
3114 $hookmanager->initHooks(array(
'userdao'));
3116 $this->users = array();
3119 $this->loadParentOf();
3122 $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";
3123 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
3125 $parameters = array();
3126 $reshook = $hookmanager->executeHooks(
'printUserListWhere', $parameters);
3128 $sql .= $hookmanager->resPrint;
3130 $sql .=
" WHERE u.entity IN (".getEntity(
'user').
")";
3133 $sql .=
" AND ".$filter;
3136 dol_syslog(get_class($this).
"::get_full_tree get user list", LOG_DEBUG);
3140 while ($obj = $this->
db->fetch_object(
$resql)) {
3141 $this->users[$obj->rowid][
'rowid'] = $obj->rowid;
3142 $this->users[$obj->rowid][
'id'] = $obj->rowid;
3143 $this->users[$obj->rowid][
'fk_user'] = $obj->fk_user;
3144 $this->users[$obj->rowid][
'fk_soc'] = $obj->fk_soc;
3145 $this->users[$obj->rowid][
'firstname'] = $obj->firstname;
3146 $this->users[$obj->rowid][
'lastname'] = $obj->lastname;
3147 $this->users[$obj->rowid][
'login'] = $obj->login;
3148 $this->users[$obj->rowid][
'statut'] = $obj->statut;
3149 $this->users[$obj->rowid][
'entity'] = $obj->entity;
3150 $this->users[$obj->rowid][
'email'] = $obj->email;
3151 $this->users[$obj->rowid][
'gender'] = $obj->gender;
3152 $this->users[$obj->rowid][
'admin'] = $obj->admin;
3153 $this->users[$obj->rowid][
'photo'] = $obj->photo;
3162 dol_syslog(get_class($this).
"::get_full_tree call to build_path_from_id_user", LOG_DEBUG);
3163 foreach ($this->users as $key => $val) {
3164 $result = $this->build_path_from_id_user($key, 0);
3166 $this->error =
'ErrorLoopInHierarchy';
3172 if ($deleteafterid) {
3174 $keyfilter1 =
'^'.$deleteafterid.
'$';
3175 $keyfilter2 =
'_'.$deleteafterid.
'$';
3176 $keyfilter3 =
'^'.$deleteafterid.
'_';
3177 $keyfilter4 =
'_'.$deleteafterid.
'_';
3178 foreach ($this->users as $key => $val) {
3179 if (preg_match(
'/'.$keyfilter1.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter2.
'/', $val[
'fullpath'])
3180 || preg_match(
'/'.$keyfilter3.
'/', $val[
'fullpath']) || preg_match(
'/'.$keyfilter4.
'/', $val[
'fullpath'])) {
3181 unset($this->users[$key]);
3186 dol_syslog(get_class($this).
"::get_full_tree dol_sort_array", LOG_DEBUG);
3187 $this->users =
dol_sort_array($this->users,
'fullname',
'asc',
true,
false);
3191 return $this->users;
3204 $childids = array();
3206 if (isset($this->cache_childids[$this->
id])) {
3207 $childids = $this->cache_childids[$this->id];
3210 $this->get_full_tree();
3212 $idtoscan = $this->id;
3214 dol_syslog(
"Build childid for id = ".$idtoscan);
3215 foreach ($this->users as $id => $val) {
3217 if (preg_match(
'/_'.$idtoscan.
'_/', $val[
'fullpath'])) {
3218 $childids[$val[
'id']] = $val[
'id'];
3222 $this->cache_childids[$this->id] = $childids;
3224 if ($addcurrentuser) {
3225 $childids[$this->id] = $this->id;
3245 if (!empty($this->users[$id_user][
'fullpath'])) {
3247 dol_syslog(get_class($this).
"::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING);
3252 $this->users[$id_user][
'fullpath'] =
'_'.$id_user;
3253 $this->users[$id_user][
'fullname'] = $this->users[$id_user][
'lastname'];
3254 $i = 0; $cursor_user = $id_user;
3256 $useridfound = array($id_user);
3257 while (!empty($this->parentof[$cursor_user])) {
3258 if (in_array($this->parentof[$cursor_user], $useridfound)) {
3259 dol_syslog(
"The hierarchy of user has a recursive loop", LOG_WARNING);
3262 $useridfound[] = $this->parentof[$cursor_user];
3263 $this->users[$id_user][
'fullpath'] =
'_'.$this->parentof[$cursor_user].$this->users[$id_user][
'fullpath'];
3264 $this->users[$id_user][
'fullname'] = $this->users[$this->parentof[$cursor_user]][
'lastname'].
' >> '.$this->users[$id_user][
'fullname'];
3265 $i++; $cursor_user = $this->parentof[$cursor_user];
3269 $this->users[$id_user][
'level'] =
dol_strlen(preg_replace(
'/[^_]/i',
'', $this->users[$id_user][
'fullpath']));
3302 $this->nb = array();
3304 $sql =
"SELECT count(u.rowid) as nb";
3305 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user as u";
3306 $sql .=
" WHERE u.statut > 0";
3308 $sql .=
" AND u.entity IN (".getEntity(
'user').
")";
3312 while ($obj = $this->
db->fetch_object(
$resql)) {
3313 $this->nb[
"users"] = $obj->nb;
3319 $this->error = $this->
db->error();
3335 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
3337 global $conf, $user, $langs;
3339 $langs->load(
"user");
3343 if (!empty($conf->global->USER_ADDON_PDF)) {
3344 $modele = $conf->global->USER_ADDON_PDF;
3346 $modele =
'bluesky';
3350 $modelpath =
"core/modules/user/doc/";
3352 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3366 $user_property =
'';
3368 if (empty($rowid)) {
3372 $sql =
"SELECT rowid, email, user_mobile, civility, lastname, firstname";
3373 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user";
3374 $sql .=
" WHERE rowid = ".((int) $rowid);
3378 $nump = $this->
db->num_rows(
$resql);
3381 $obj = $this->
db->fetch_object(
$resql);
3383 if ($mode ==
'email') {
3384 $user_property =
dolGetFirstLastname($obj->firstname, $obj->lastname).
" <".$obj->email.
">";
3385 } elseif ($mode ==
'mobile') {
3386 $user_property = $obj->user_mobile;
3389 return $user_property;
3407 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, $filter = array(), $filtermode =
'AND', $entityfilter =
false)
3409 global $conf, $user;
3411 $sql =
"SELECT t.rowid";
3412 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as t ';
3414 if ($entityfilter) {
3415 if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
3416 if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
3417 $sql .=
" WHERE t.entity IS NOT NULL";
3419 $sql .=
",".MAIN_DB_PREFIX.
"usergroup_user as ug";
3420 $sql .=
" WHERE ((ug.fk_user = t.rowid";
3421 $sql .=
" AND ug.entity IN (".getEntity(
'user').
"))";
3422 $sql .=
" OR t.entity = 0)";
3425 $sql .=
" WHERE t.entity IN (".getEntity(
'user').
")";
3432 $sqlwhere = array();
3433 if (!empty($filter)) {
3434 foreach ($filter as $key => $value) {
3435 if ($key ==
't.rowid') {
3436 $sqlwhere[] = $key.
'='.$value;
3437 } elseif (strpos($key,
'date') !==
false) {
3438 $sqlwhere[] = $key.
' = \''.$this->
db->idate($value).
'\'';
3439 } elseif ($key ==
'customsql') {
3440 $sqlwhere[] = $value;
3442 $sqlwhere[] = $key.
' LIKE \'%'.$this->
db->escape($value).
'%\'';
3446 if (count($sqlwhere) > 0) {
3447 $sql .=
' AND ('.implode(
' '.$filtermode.
' ', $sqlwhere).
')';
3449 $sql .= $this->
db->order($sortfield, $sortorder);
3451 $sql .= $this->
db->plimit($limit + 1, $offset);
3458 $this->users = array();
3459 $num = $this->
db->num_rows(
$resql);
3461 while ($obj = $this->
db->fetch_object(
$resql)) {
3462 $line =
new self($this->db);
3463 $result = $line->fetch($obj->rowid);
3464 if ($result > 0 && !empty($line->id)) {
3465 $this->users[$obj->rowid] = clone $line;
3472 $this->errors[] = $this->
db->lasterror();
3484 private $findUserIdByEmailCache;
3498 if ($this->findUserIdByEmailCache[$email]) {
3499 return $this->findUserIdByEmailCache[$email];
3502 $this->findUserIdByEmailCache[$email] = -1;
3506 $sql =
'SELECT rowid';
3507 $sql .=
' FROM '.MAIN_DB_PREFIX.
'user';
3509 if (!empty($conf->global->AGENDA_DISABLE_EXACT_USER_EMAIL_COMPARE_FOR_EXTERNAL_CALENDAR)) {
3510 $sql .=
' WHERE email LIKE "%'.$email.
'%"';
3512 $sql .=
' WHERE email = "'.$email.
'"';
3522 $obj = $this->
db->fetch_object(
$resql);
3527 $this->findUserIdByEmailCache[$email] = (int) $obj->rowid;
3529 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.
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
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)
setPassword($user, $password= '', $changelater=0, $notrigger=0, $nosyncmember=0)
Change password of a user.
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)
getArrayOfSocialNetworks()
Get array of social network dictionary.
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.
Class to manage Dolibarr users.
Class to manage Dolibarr database access.
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.
$conf db
API class for accounts.
send_password($user, $password= '', $changelater=0)
Send new password by email.
$clicktodial_url
clicktodial url
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.
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.
Class to manage categories.
setstatus($status)
Change status of a user.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
loadDefaultValues()
Load default value in 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...
_load_ldap_dn($info, $mode=0)
Retourne chaine DN complete dans l'annuaire LDAP pour l'objet.
print $_SERVER["PHP_SELF"]
Edit parameters.
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.
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.
fetch($id= '', $login= '', $sid= '', $loadpersonalconf=0, $entity=-1, $email= '')
Load a user from database with its id or ref (login).
getrights($moduletag= '', $forcereload=0)
Load permissions granted to user into object user.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
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.
update_last_login_date()
Mise a jour en base de la date de derniere connexion d'un utilisateur Fonction appelee lors d'une nou...
picto_from_langcode($codelang, $moreatt= '')
Return img flag of country for a language code or country code.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
error()
Renvoie la derniere erreur fonctionnelle de manipulation de l'objet.
if(!empty($search_group)) natural_search(array("g.nom"g note
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
getLoginUrl($withpicto=0, $option= '')
Return clickable link of login (eventualy with picto)
Class to manage warehouses.