Skip to content
Snippets Groups Projects
Commit 4d4feab0 authored by Yannick Warnier's avatar Yannick Warnier
Browse files

Evite le double-enregistrement d'alertes sur anniversaire

parent bb609f3f
Branches
Tags
No related merge requests found
...@@ -321,20 +321,35 @@ class Contact ...@@ -321,20 +321,35 @@ class Contact
// Mis a jour alerte birthday // Mis a jour alerte birthday
if ($this->birthday_alert) if ($this->birthday_alert)
{ {
//check existing
$sql_check = "SELECT * FROM ".MAIN_DB_PREFIX."user_alert WHERE type=1 AND fk_contact=$id AND fk_user=".$user->id;
$result_check = $this->db->query($sql_check);
if (!$result_check or ($this->db->num_rows($result_check)<1))
{
//insert
$sql = "INSERT into ".MAIN_DB_PREFIX."user_alert(type,fk_contact,fk_user) "; $sql = "INSERT into ".MAIN_DB_PREFIX."user_alert(type,fk_contact,fk_user) ";
$sql.= "values (1,".$id.",".$user->id.")"; $sql.= "values (1,".$id.",".$user->id.")";
$result = $this->db->query($sql);
if (!$result)
{
$this->error='Echec sql='.$sql;
}
}
else
{
$result = true;
}
} }
else else
{ {
$sql = "DELETE from ".MAIN_DB_PREFIX."user_alert "; $sql = "DELETE from ".MAIN_DB_PREFIX."user_alert ";
$sql.= "where type=1 AND fk_contact=".$id." AND fk_user=".$user->id; $sql.= "where type=1 AND fk_contact=".$id." AND fk_user=".$user->id;
}
$result = $this->db->query($sql); $result = $this->db->query($sql);
if (!$result) if (!$result)
{ {
$this->error='Echec sql='.$sql; $this->error='Echec sql='.$sql;
} }
}
return $result; return $result;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment