go("SELECT * FROM r_alert_task WHERE dataOra <= NOW() AND DATE(dataOra) = DATE(NOW()) AND sent = 'N'"); if ($eventi->rowCount() > 0) { while($evento = $eventi->fetch(PDO::FETCH_ASSOC)) { if (!isset($promemoria[$evento["codice_ente"]])) { $promemoria[$evento["codice_ente"]] = []; } $promemoria[$evento["codice_ente"]][] = $evento; } } if (!empty($promemoria)) { $enti = array_keys($promemoria); foreach($enti AS $codice_ente) { $taskRis = $pdo->prepare("SELECT * FROM b_tasks WHERE codice = :codice AND codice_utente = :codice_utente "); $updateTask = $pdo->prepare("UPDATE r_alert_task SET sent = 'S' WHERE codice = :codice"); foreach($promemoria[$codice_ente] AS $evento) { $taskRis->bindValue(":codice",$evento["codice_task"]); $taskRis->bindValue(":codice_utente",$evento["codice_utente"]); $taskRis->execute(); if ($taskRis->rowCount() > 0) { $task = $taskRis->fetch(PDO::FETCH_ASSOC); $utente = Utente::getInfoFromID($task["codice_utente"]); $corpo = $task["oggetto"] . "
" . $task["descrizione"]; $mailer = new Communicator(); $mailer->oggetto = $task["oggetto"]; $mailer->corpo = $corpo; $mailer->codice_pec = -3; $mailer->codice_ente = $codice_ente; $mailer->destinatari = $utente["email"]; $mailer->comunicazione = false; if ($mailer->send()) { $updateTask->bindValue(":codice",$evento["codice"]); $updateTask->execute(); } } } } } } ?>