Qual: Gestion erreur sur contact

This commit is contained in:
Laurent Destailleur 2007-09-10 00:17:28 +00:00
parent d89963b9fa
commit d64113bda5
2 changed files with 59 additions and 54 deletions

View File

@ -365,7 +365,7 @@ class Contact
* \brief Charge l'objet contact * \brief Charge l'objet contact
* \param id id du contact * \param id id du contact
* \param user Utilisateur lié au contact pour une alerte * \param user Utilisateur lié au contact pour une alerte
* \return int 1 si ok, -1 si erreur * \return int -1 if KO, 0 if OK but not found, 1 if OK
*/ */
function fetch($id, $user=0) function fetch($id, $user=0)
{ {
@ -424,59 +424,63 @@ class Contact
$this->user_id = $obj->user_id; $this->user_id = $obj->user_id;
$this->user_login = $obj->user_login; $this->user_login = $obj->user_login;
}
$this->db->free($resql);
// Recherche le user Dolibarr lié à ce contact // Recherche le user Dolibarr lié à ce contact
$sql = "SELECT u.rowid "; $sql = "SELECT u.rowid ";
$sql .= " FROM ".MAIN_DB_PREFIX."user as u"; $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
$sql .= " WHERE u.fk_socpeople = ". $id; $sql .= " WHERE u.fk_socpeople = ". $this->id;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
if ($this->db->num_rows($resql)) if ($this->db->num_rows($resql))
{ {
$uobj = $this->db->fetch_object($resql); $uobj = $this->db->fetch_object($resql);
$this->user_id = $uobj->rowid; $this->user_id = $uobj->rowid;
} }
$this->db->free($resql); $this->db->free($resql);
} }
else else
{ {
dolibarr_syslog("Error in Contact::fetch() selectuser sql=$sql"); dolibarr_syslog("Error in Contact::fetch() selectuser sql=$sql");
$this->error="Error in Contact::fetch() selectuser - ".$this->db->error()." - ".$sql; $this->error="Error in Contact::fetch() selectuser - ".$this->db->error()." - ".$sql;
return -1; return -1;
} }
// Charge alertes du user // Charge alertes du user
if ($user) if ($user)
{ {
$sql = "SELECT fk_user"; $sql = "SELECT fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."user_alert"; $sql .= " FROM ".MAIN_DB_PREFIX."user_alert";
$sql .= " WHERE fk_user = $user->id AND fk_contact = ".$id; $sql .= " WHERE fk_user = $user->id AND fk_contact = ".$id;
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
if ($this->db->num_rows($resql)) if ($this->db->num_rows($resql))
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
$this->birthday_alert = 1; $this->birthday_alert = 1;
} }
$this->db->free($resql); $this->db->free($resql);
} }
else else
{ {
dolibarr_syslog("Error in Contact::fetch() selectuseralert sql=$sql"); dolibarr_syslog("Error in Contact::fetch() selectuseralert sql=$sql");
$this->error="Error in Contact::fetch() selectuseralert - ".$this->db->error()." - ".$sql; $this->error="Error in Contact::fetch() selectuseralert - ".$this->db->error()." - ".$sql;
return -1; return -1;
} }
} }
return 1; return 1;
}
else
{
$this->error=$langs->trans("RecordNotFound");
return 0;
}
} }
else else
{ {

View File

@ -233,9 +233,10 @@ if ($_GET["id"] > 0)
// Si edition contact deja existant // Si edition contact deja existant
$contact = new Contact($db); $contact = new Contact($db);
$return=$contact->fetch($_GET["id"], $user); $return=$contact->fetch($_GET["id"], $user);
if ($return < 0) if ($return <= 0)
{ {
dolibarr_print_error('',$contact->error); dolibarr_print_error('',$contact->error);
$_GET["id"]=0;
} }
/* /*