109 lines
3.6 KiB
PHP
109 lines
3.6 KiB
PHP
<?php
|
|
/*
|
|
Author: Riccardo Di Dato
|
|
Creation Date: 29/feb/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_COMMENTI_SUPERVISOR) ){
|
|
GUIHandler::redirect("admin/index.php");
|
|
}
|
|
|
|
MenuGenerator::generateMenu();
|
|
HTMLHelper::generateAdminHead();
|
|
|
|
try{
|
|
$commentoId = PostHandler::get("id");
|
|
if (is_null($commentoId)){
|
|
if (array_key_exists("i", $_GET) && strcmp("", $_GET["i"])!=0){
|
|
$commentoId = $_GET["i"];
|
|
}
|
|
else {
|
|
GUIHandler::redirect("admin/unacceptedCommenti.php");
|
|
}
|
|
}
|
|
|
|
$commento = GlobalVariables::get("dao")->getFirst("CommentoModel",array("id"=>$commentoId));
|
|
|
|
if (is_null($commento)){
|
|
GUIHandler::redirect("admin/unacceptedCommenti.php");
|
|
}
|
|
|
|
$notiziaId = $commento->notizia;
|
|
$notizia = GlobalVariables::get("dao")->getFirst("NotiziaModel",array("id"=>$notiziaId));
|
|
|
|
if (is_null($notizia)){
|
|
throw new Exception("Impossibile aprire il commento in quanto associato ad una notizia non valida. (Commento: '".$commentoId."', Notizia: '".$notiziaId."')");
|
|
}
|
|
|
|
$userId = $commento->user;
|
|
$userModel = GlobalVariables::get("dao")->getFirst("UserModel",array("id"=>$userId));
|
|
$userString = "Utente cancellato";
|
|
if (!is_null($userModel)){
|
|
$userString = $userModel->nome." ".$userModel->cognome;
|
|
}
|
|
|
|
$validation = PostHandler::get("status");
|
|
if (!is_null($validation)){
|
|
if (strcmp($validation, "accept")==0){
|
|
$commento->status = CommentoModel::STATUS_ACCEPTED;
|
|
GlobalVariables::get("dao")->save($commento);
|
|
GUIHandler::redirect("admin/unacceptedCommenti.php");
|
|
}
|
|
else if (strcmp($validation, "reject")==0){
|
|
$commento->status = CommentoModel::STATUS_REJECTED;
|
|
GlobalVariables::get("dao")->save($commento);
|
|
GUIHandler::redirect("admin/unacceptedCommenti.php");
|
|
}
|
|
}
|
|
|
|
}catch(GUIException $ex){
|
|
$error = $ex->getMessage();
|
|
}catch (Exception $exec){
|
|
$msg = LogModel::fromException($exec);
|
|
GlobalVariables::get("dao")->save($msg);
|
|
$error = "Si è verificato un errore inatteso durante l'esecuzione della pagina. Contattare il supporto tecnico comunicando il seguente codice di erore '".$msg->getCode()."'";
|
|
|
|
}
|
|
|
|
?>
|
|
<div>
|
|
<?php
|
|
if(strcmp($error, "")!=0){
|
|
echo '<div style="font-size: 16px; color:red;">'.$error.'</div>';
|
|
}
|
|
?>
|
|
<div class="commentoAcceptance">
|
|
<div class="commentoTitolo"><?php echo $commento->titolo; ?></div>
|
|
<div class="commentoTesto"><?php echo $commento->testo; ?></div>
|
|
<div class="commentoUser"><?php echo $userString; ?></div>
|
|
<div class="commentoDate"><?php echo date("d-m-Y H:i",$commento->date->toDateTime()->getTimestamp()); ?></div>
|
|
<div class="buttons">
|
|
<a class="green" href="javascript:void();">Accetta</a>
|
|
<a class="yellow" href="javascript:void();">Modifica</a>
|
|
<a class="red" href="javascript:void();">Cancella</a>
|
|
</div>
|
|
<script type="text/javascript">
|
|
$(".commentoAcceptance a.green").click(function () {
|
|
openPagePost("validateCommento.php", [{name:"id",value:"<?php echo $commentoId;?>"},{name:"status",value:"accept"}]);
|
|
});
|
|
$(".commentoAcceptance a.yellow").click(function () {
|
|
openPagePost("editCommento.php", [{name:"id",value:"<?php echo $commentoId;?>"}]);
|
|
});
|
|
$(".commentoAcceptance a.red").click(function () {
|
|
openPagePost("validateCommento.php", [{name:"id",value:"<?php echo $commentoId;?>"},{name:"status",value:"reject"}]);
|
|
});
|
|
</script>
|
|
</div>
|
|
<?php
|
|
echo new NotiziaBlock($notizia);
|
|
echo new NotiziaCommentiList($notizia);
|
|
|
|
?>
|
|
</div>
|