function delete_mail_reference($user_id, $mail_ids)
{
    global $dbh;
    global $logger;
    if (count($mail_ids) < 1) {
        #not sure if this  is possible, but
        return;
        # we should not do anything if the list is empty
    }
    // Delete a specific users' recipient reference to these mail messages.
    $delete = "DELETE FROM maia_mail_recipients WHERE recipient_id = ? AND mail_id IN (";
    $delete .= '?' . str_repeat(',?', count($mail_ids) - 1);
    $delete .= ")";
    $res = $dbh->query($delete, array_merge((array) $user_id, (array) $mail_ids));
    sql_check($res, "delete_mail_reference", $delete);
    // If there are no other recipients referenced by each mail item,
    // delete it.
    $select = "SELECT recipient_id, mail_id, maia_mail.id " . "FROM      maia_mail " . "LEFT JOIN maia_mail_recipients " . "ON maia_mail.id = maia_mail_recipients.mail_id " . "WHERE maia_mail.id IN (?" . str_repeat(',?', count($mail_ids) - 1) . ") " . "AND mail_id IS NULL";
    $sth = $dbh->query($select, $mail_ids);
    sql_check($sth, "delete_mail_reference", $select);
    $deletions = array();
    while ($row = $sth->fetchrow()) {
        array_push($deletions, $row['id']);
    }
    $sth->free();
    if (count($deletions) > 0) {
        delete_mail($deletions);
    }
}
Example #2
0
<?php

include "inc/connect.php";
include "inc/functions.php";
if ($_POST) {
    $id = nettoyage($_POST['id']);
    delete_mail($connexion, $id);
    echo "l'id a bien été suprimer" . $id;
    header('Refresh: 2; URL=platform.php');
} else {
}