Evite le double-enregistrement d'alertes sur anniversaire
This commit is contained in:
parent
bb609f3f5c
commit
4d4feab0e6
@ -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.")";
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$sql = "DELETE from ".MAIN_DB_PREFIX."user_alert ";
|
|
||||||
$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;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sql = "DELETE from ".MAIN_DB_PREFIX."user_alert ";
|
||||||
|
$sql.= "where type=1 AND fk_contact=".$id." AND fk_user=".$user->id;
|
||||||
|
$result = $this->db->query($sql);
|
||||||
|
if (!$result)
|
||||||
|
{
|
||||||
|
$this->error='Echec sql='.$sql;
|
||||||
|
}
|
||||||
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user