Gestion erreur user

This commit is contained in:
Laurent Destailleur 2007-04-13 16:11:44 +00:00
parent 3128ef4f87
commit ea2f6c356d

View File

@ -104,142 +104,150 @@ class User
} }
/** /**
\brief Charge un objet user avec toutes ces caractéristiques depuis un id ou login * \brief Charge un objet user avec toutes ces caractéristiques depuis un id ou login
\param login Si défini, login a utiliser pour recherche * \param login Si défini, login a utiliser pour recherche
\return int <0 si ko, >0 si ok * \return int <0 si ko, >0 si ok
*/ */
function fetch($login='') function fetch($login='')
{ {
global $conf; global $conf;
dolibarr_syslog("User::Fetch id=".$this->id." login=".$login, LOG_DEBUG); dolibarr_syslog("User::Fetch id=".$this->id." login=".$login, LOG_DEBUG);
// Recupere utilisateur // Recupere utilisateur
$sql = "SELECT u.rowid, u.name, u.firstname, u.email, u.office_phone, u.office_fax, u.user_mobile,"; $sql = "SELECT u.rowid, u.name, u.firstname, u.email, u.office_phone, u.office_fax, u.user_mobile,";
$sql.= " u.admin, u.login, u.pass, u.webcal_login, u.note,"; $sql.= " u.admin, u.login, u.pass, u.webcal_login, u.note,";
$sql.= " u.fk_societe, u.fk_socpeople, u.ldap_sid,"; $sql.= " u.fk_societe, u.fk_socpeople, u.ldap_sid,";
$sql.= " u.statut, u.lang,"; $sql.= " u.statut, u.lang,";
$sql.= " ".$this->db->pdate("u.datec")." as datec,"; $sql.= " ".$this->db->pdate("u.datec")." as datec,";
$sql.= " ".$this->db->pdate("u.tms")." as datem,"; $sql.= " ".$this->db->pdate("u.tms")." as datem,";
$sql.= " ".$this->db->pdate("u.datelastlogin")." as datel,"; $sql.= " ".$this->db->pdate("u.datelastlogin")." as datel,";
$sql.= " ".$this->db->pdate("u.datepreviouslogin")." as datep"; $sql.= " ".$this->db->pdate("u.datepreviouslogin")." as datep";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u";
if ($login) if ($login)
{ {
$sql .= " WHERE u.login = '".$login."'"; $sql .= " WHERE u.login = '".$login."'";
} }
else else
{ {
$sql .= " WHERE u.rowid = ".$this->id; $sql .= " WHERE u.rowid = ".$this->id;
} }
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
$obj = $this->db->fetch_object($result); $obj = $this->db->fetch_object($result);
if ($obj) if ($obj)
{ {
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->ldap_sid = $obj->ldap_sid; $this->ldap_sid = $obj->ldap_sid;
$this->nom = $obj->name; $this->nom = $obj->name;
$this->prenom = $obj->firstname; $this->prenom = $obj->firstname;
$this->fullname = trim($this->prenom . ' ' . $this->nom); $this->fullname = trim($this->prenom . ' ' . $this->nom);
$this->login = $obj->login; $this->login = $obj->login;
$this->pass_indatabase = $obj->pass; $this->pass_indatabase = $obj->pass;
if (! $conf->password_encrypted) $this->pass = $obj->pass; if (! $conf->password_encrypted) $this->pass = $obj->pass;
$this->office_phone = $obj->office_phone; $this->office_phone = $obj->office_phone;
$this->office_fax = $obj->office_fax; $this->office_fax = $obj->office_fax;
$this->user_mobile = $obj->user_mobile; $this->user_mobile = $obj->user_mobile;
$this->email = $obj->email; $this->email = $obj->email;
$this->admin = $obj->admin; $this->admin = $obj->admin;
$this->contact_id = $obj->fk_socpeople; $this->contact_id = $obj->fk_socpeople;
$this->note = $obj->note; $this->note = $obj->note;
$this->statut = $obj->statut; $this->statut = $obj->statut;
$this->lang = $obj->lang; $this->lang = $obj->lang;
$this->datec = $obj->datec; $this->datec = $obj->datec;
$this->datem = $obj->datem; $this->datem = $obj->datem;
$this->datelastlogin = $obj->datel; $this->datelastlogin = $obj->datel;
$this->datepreviouslogin = $obj->datep; $this->datepreviouslogin = $obj->datep;
$this->webcal_login = $obj->webcal_login; $this->webcal_login = $obj->webcal_login;
$this->societe_id = $obj->fk_societe; $this->societe_id = $obj->fk_societe;
if (! $this->lang) $this->lang='fr_FR'; if (! $this->lang) $this->lang='fr_FR';
}
$this->db->free($result); $this->db->free($result);
}
} else
else {
{ $this->error="USERNOTFOUND";
$this->error=$this->db->error(); dolibarr_syslog("User::fetch Error -2, fails to get user - ".$this->error." - sql=".$sql);
dolibarr_syslog("User::fetch Error -1, fails to get user - ".$this->error." - sql=".$sql);
return -1; $this->db->free($result);
} return -2;
}
// Recupere parametrage global propre à l'utilisateur }
// \todo a stocker/recupérer en session pour eviter ce select a chaque page else
$sql = "SELECT param, value FROM ".MAIN_DB_PREFIX."user_param"; {
$sql.= " WHERE fk_user = ".$this->id; $this->error=$this->db->error();
$sql.= " AND page = ''"; dolibarr_syslog("User::fetch Error -1, fails to get user - ".$this->error." - sql=".$sql);
$result=$this->db->query($sql); return -1;
if ($result) }
{
$num = $this->db->num_rows($result); // Recupere parametrage global propre à l'utilisateur
$i = 0; // \todo a stocker/recupérer en session pour eviter ce select a chaque page
while ($i < $num) $sql = "SELECT param, value FROM ".MAIN_DB_PREFIX."user_param";
{ $sql.= " WHERE fk_user = ".$this->id;
$obj = $this->db->fetch_object($result); $sql.= " AND page = ''";
$p=$obj->param; $result=$this->db->query($sql);
if ($p) $this->conf->$p = $obj->value; if ($result)
$i++; {
} $num = $this->db->num_rows($result);
$this->db->free($result); $i = 0;
} while ($i < $num)
else {
{ $obj = $this->db->fetch_object($result);
$this->error=$this->db->error(); $p=$obj->param;
dolibarr_syslog("User::fetch Error -2, fails to get setup user - ".$this->error." - sql=".$sql); if ($p) $this->conf->$p = $obj->value;
return -2; $i++;
} }
$this->db->free($result);
// Recupere parametrage propre à la page et à l'utilisateur }
// \todo SCRIPT_URL non defini sur tous serveurs else
// Paramétrage par page desactivé pour l'instant {
if (1==2 && isset($_SERVER['SCRIPT_URL'])) $this->error=$this->db->error();
{ dolibarr_syslog("User::fetch Error -2, fails to get setup user - ".$this->error." - sql=".$sql);
$sql = "SELECT param, value FROM ".MAIN_DB_PREFIX."user_param"; return -2;
$sql.= " WHERE fk_user = ".$this->id; }
$sql.= " AND page='".$_SERVER['SCRIPT_URL']."'";
$result=$this->db->query($sql); // Recupere parametrage propre à la page et à l'utilisateur
if ($result) // \todo SCRIPT_URL non defini sur tous serveurs
{ // Paramétrage par page desactivé pour l'instant
$num = $this->db->num_rows($result); if (1==2 && isset($_SERVER['SCRIPT_URL']))
$i = 0; {
$page_param_url = ''; $sql = "SELECT param, value FROM ".MAIN_DB_PREFIX."user_param";
$this->page_param = array(); $sql.= " WHERE fk_user = ".$this->id;
while ($i < $num) $sql.= " AND page='".$_SERVER['SCRIPT_URL']."'";
{ $result=$this->db->query($sql);
$obj = $this->db->fetch_object($result); if ($result)
$this->page_param[$obj->param] = $obj->value; {
$page_param_url .= $obj->param."=".$obj->value."&amp;"; $num = $this->db->num_rows($result);
$i++; $i = 0;
} $page_param_url = '';
$this->page_param_url = $page_param_url; $this->page_param = array();
$this->db->free($result); while ($i < $num)
} {
else $obj = $this->db->fetch_object($result);
{ $this->page_param[$obj->param] = $obj->value;
$this->error=$this->db->error(); $page_param_url .= $obj->param."=".$obj->value."&amp;";
return -1; $i++;
} }
} $this->page_param_url = $page_param_url;
$this->db->free($result);
return 1; }
} else
{
$this->error=$this->db->error();
return -1;
}
}
return 1;
}
/** /**
* \brief Ajoute un droit a l'utilisateur * \brief Ajoute un droit a l'utilisateur