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
119 lines
3.7 KiB
PHP
119 lines
3.7 KiB
PHP
<?php
|
|
/*
|
|
Author: Riccardo Di Dato
|
|
Creation Date: 25/gen/2016
|
|
*/
|
|
|
|
|
|
require_once(dirname(__FILE__)."/../load.php");
|
|
|
|
GUIHandler::generateHtmlHeaders(array(),true);
|
|
|
|
if (!AdminLoginManager::isLogged()){
|
|
GUIHandler::redirect("admin/login.php");
|
|
}
|
|
else if (!AdminLoginManager::getLogged()->hasRole(AdminModel::ADMIN_TYPE_NEWSLETTER)){
|
|
GUIHandler::redirect("admin/index.php");
|
|
}
|
|
|
|
MenuGenerator::generateMenu();
|
|
|
|
HTMLHelper::generateAdminHead();
|
|
|
|
try {
|
|
$id = PostHandler::get("id");
|
|
|
|
$config = GlobalVariables::get("config");
|
|
|
|
$tmp = new stdClass();
|
|
$tmp->from = $config->emails->newsletter;
|
|
$tmp->fromName = "I Fatti di Napoli - Newsletter";
|
|
$tmp->subject = "";
|
|
$tmp->body = "";
|
|
$tmp->date = new MongoDate();
|
|
$mail = new MailTemplateModel($tmp);
|
|
|
|
|
|
if (!is_null($id) && strcmp("", $id)!=0){
|
|
$mail = GlobalVariables::get("dao")->getFirst("MailTemplateModel",array("id"=>$id));
|
|
if (is_null($mail)){
|
|
GUIHandler::redirect("admin/pendingNewsletters.php");
|
|
}
|
|
}
|
|
|
|
$action = PostHandler::get("action");
|
|
if (!is_null($action) && strcmp("", $action)!=0){
|
|
if (strcmp("cancel", $action)==0){
|
|
GUIHandler::redirect("admin/pendingNewsletters.php");
|
|
}
|
|
else if (strcmp("save", $action)==0){
|
|
$mail->subject = PostHandler::get("subject");
|
|
$mail->body = PostHandler::get("body");
|
|
|
|
$dateString = PostHandler::get("data")." ".PostHandler::get("time");
|
|
if(!preg_match("/^[0-9]{2}[-][0-9]{2}[-][0-9]{4} [0-9]{2}[:][0-9]{2}$/", $dateString)){
|
|
throw new GUIException("Il formato della data inserita non è corretto. Per favore segui il seguente formato Date: dd-mm-yyyy hh:ii");
|
|
}
|
|
$tmp->date = new MongoDate(strtotime($dateString));
|
|
|
|
GlobalVariables::get("dao")->save($mail);
|
|
|
|
GUIHandler::redirectPost("admin/confirmNewsletter.php",array("id"=>$mail->id));
|
|
}
|
|
}
|
|
}catch(GUIException $ex){
|
|
$error = $ex->getMessage();
|
|
}catch (Exception $exec){
|
|
LoggingFacilityManager::getLogger("gui")->log(LoggingFacility::$LEVEL_ERROR, $exec->getMessage());
|
|
$error = "Si è verificato un errore inaspettato durante l'esecuzione della pagina. Se l'errore persiste contattare il supporto tecnico.";
|
|
}
|
|
|
|
?>
|
|
<div>
|
|
<?php
|
|
if(strcmp($error, "")!=0){
|
|
echo '<div style="font-size: 16px; color:red;">'.$error.'</div>';
|
|
}
|
|
?>
|
|
<form id="mailForm" method="POST" action="">
|
|
<input type="hidden" name="action" value="" />
|
|
<input type="hidden" name="id" value="<?php echo $id;?>" />
|
|
<div>
|
|
<span class="label">Oggetto</span>
|
|
<input type="text" name="subject" value="<?php echo $mail->subject; ?>" />
|
|
</div>
|
|
<div>
|
|
<span class="label">Giorno</span>
|
|
<input type="text" id="datepicker" name="data" value="<?php echo ($edit)? date("d-m-Y",$mail->date->sec):date("d-m-Y");?>">
|
|
</div>
|
|
<div>
|
|
<span class="label">Ora</span>
|
|
<input type="text" id="timepicker" name="time" value="<?php echo ($edit)? date("H:i",$mail->date->sec):date("H:i");?>">
|
|
</div>
|
|
<div>
|
|
<span class="label">Corpo</span>
|
|
<textarea name="body" id="body_editor" rows="10" cols="80"><?php echo $mail->body;?></textarea>
|
|
</div>
|
|
</form>
|
|
<div class="formBtns">
|
|
<a href="#" id="mailForm_salva" >Salva</a>
|
|
<a href="#" id="mailForm_annulla">Annulla</a>
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
$(document).ready(function(event){
|
|
CKEDITOR.replace('body_editor');
|
|
$("#datepicker").datepicker({dateFormat:"dd-mm-yy"});
|
|
$("#timepicker").datetimepicker({datepicker:false,format:'H:i'});
|
|
|
|
|
|
$("#mailForm_salva").click(function(event){
|
|
$("form#mailForm input[type=hidden][name=action]").val("save");
|
|
$("form#mailForm").submit();
|
|
});
|
|
$("#mailForm_annulla").click(function(event){
|
|
$("form#mailForm input[type=hidden][name=action]").val("cancel");
|
|
$("form#mailForm").submit();
|
|
});
|
|
});
|
|
</script>
|