Cambiata gui exception per estendere MultiMessageException Implementata logging degli accessi all'applicazione Modificato loginmanager per loggare gli accessi Creata classe d'appoggio per generare il testo delle email Creato stile di base per le form dell'amministrazione Bugfix e migliorie grafiche
93 lines
2.4 KiB
PHP
93 lines
2.4 KiB
PHP
<?php
|
|
/*
|
|
Author: Riccardo Di Dato
|
|
Creation Date: 25/gen/2016
|
|
*/
|
|
|
|
class FDN_Mailer {
|
|
|
|
public static function generateTemplateQueue(MailTemplateModel $mailTemplate){
|
|
$users = GlobalVariables::get("dao")->query("UserModel",array("newsletter"=>true));
|
|
|
|
foreach ($users as $user){
|
|
$tmp = new stdClass();
|
|
$tmp->from = $mailTemplate->from;
|
|
if ($mailTemplate->hasProperty("fromName")){
|
|
$tmp->fromName = $mailTemplate->fromName;
|
|
}
|
|
|
|
$tmp->recipient = $user->email;
|
|
|
|
$tmp->subject = $mailTemplate->subject;
|
|
$tmp->body = $mailTemplate->body;
|
|
if ($mailTemplate->hasProperty("altBody")){
|
|
$tmp->altBody = $mailTemplate->altBody;
|
|
}
|
|
|
|
if ($mailTemplate->hasProperty("attachment")){
|
|
$tmp->attachment = $mailTemplate->attachment;
|
|
}
|
|
|
|
$tmp->priority = MailModel::PRIORITY_LOW;
|
|
|
|
$mail = new MailModel($tmp);
|
|
GlobalVariables::get("dao")->save($mail);
|
|
}
|
|
|
|
}
|
|
|
|
public static function processQueue(){
|
|
$mails = GlobalVariables::get("dao")->query("MailModel",array("status"=>MailModel::STATUS_PENDING),array("order"=>array("priority","desc"),"limit"=>50));
|
|
|
|
if (sizeof($mails)>0){
|
|
foreach($mails as $mail){
|
|
self::sendMail($mail);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public static function sendMail(MailModel $mail){
|
|
$mailObj = $mail->getMailObject();
|
|
|
|
if(!$mailObj->send()) {
|
|
LoggingFacilityManager::getLogger("mail")->log(LoggingFacility::$LEVEL_ERROR,"Impossible to send email with id '".$mail->id."' to recipient '".$mail->recipient."' (".$mailObj->ErrorInfo.")");
|
|
$mail->status = MailModel::STATUS_PAUSED;
|
|
}
|
|
else {
|
|
$mail->status = MailModel::STATUS_SENT;
|
|
$mail->sendDate = new MongoDate();
|
|
}
|
|
GlobalVariables::get("dao")->save($mail);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static function queueAdminWarningMail($subj,$text){
|
|
$admins = GlobalVariables::get("dao")->query("AdminModel",array('$where'=>"obj.roles%(".AdminModel::ADMIN_TYPE_SUPERADMIN."*2) >= ".AdminModel::ADMIN_TYPE_SUPERADMIN));
|
|
if (sizeof($admins)>0){
|
|
foreach ($admins as $admin){
|
|
$tmp = new stdClass();
|
|
$tmp->from = GlobalVariables::get("config")->emails->system;
|
|
$tmp->fromName = "SYSTEM - I Fatti di Napoli";
|
|
|
|
$tmp->recipient = $admin->email;
|
|
|
|
$tmp->subject = $subj;
|
|
$tmp->body = $text;
|
|
|
|
$tmp->priority = MailModel::PRIORITY_HIGH;
|
|
|
|
$mail = new MailModel($tmp);
|
|
GlobalVariables::get("dao")->save($mail);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
?>
|