166 lines
6.0 KiB
PHP
166 lines
6.0 KiB
PHP
<?php
|
|
|
|
|
|
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_EDITORE_SUPERVISOR) &&
|
|
!AdminLoginManager::getLogged()->hasRole(AdminModel::ADMIN_TYPE_EDITORE)){
|
|
GUIHandler::redirect("admin/index.php");
|
|
}
|
|
|
|
try{
|
|
$error = "";
|
|
$edit = false;
|
|
$notiziaId = PostHandler::get("id");
|
|
|
|
$notizia = new NotiziaModel();
|
|
// $notizia->about->data = new MongoDate();
|
|
$notizia->about->data = new MongoDB\BSON\UTCDateTime( time() * 1000 );
|
|
// var_dump($notizia);
|
|
if(!is_null($notiziaId) && strcmp($notiziaId, "")!=0){
|
|
|
|
$edit = true;
|
|
$notizia = GlobalVariables::get("dao")->getFirst("NotiziaModel",array("id"=>$notiziaId));
|
|
// echo "pene";
|
|
if(is_null($notizia)){
|
|
GUIHandler::redirect("admin/myNotizie.php");
|
|
}
|
|
|
|
if (!AdminLoginManager::getLogged()->hasRole(AdminModel::ADMIN_TYPE_EDITORE_SUPERVISOR) &&
|
|
AdminLoginManager::getLogged()->hasRole(AdminModel::ADMIN_TYPE_EDITORE)){
|
|
if($notizia->status == NotiziaModel::STATUS_ACCEPTED){
|
|
GUIHandler::redirect("admin/myNotizie.php");
|
|
}
|
|
|
|
if(strcmp($notizia->about->owner, AdminLoginManager::getLogged()->id) != 0){
|
|
GUIHandler::redirect("admin/myNotizie.php");
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
$notizia->about->author = AdminLoginManager::getLogged()->nome." ".AdminLoginManager::getLogged()->cognome;
|
|
}
|
|
|
|
MenuGenerator::generateMenu();
|
|
HTMLHelper::generateAdminHead();
|
|
|
|
if(!is_null(PostHandler::get("action")) && strcmp(PostHandler::get("action"), "")!=0){
|
|
$save = PostHandler::get("action");
|
|
if(strcmp($save, "save")==0){
|
|
|
|
$notizia->titolo = strip_tags(PostHandler::get("titolo"));
|
|
$notizia->sottotitolo = strip_tags(PostHandler::get("sottotitolo"));
|
|
$notizia->testo = PostHandler::get("testo");
|
|
$notizia->category = PostHandler::get("category");
|
|
$notizia->about->author = PostHandler::get("author");
|
|
|
|
$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");
|
|
}
|
|
|
|
// $mongoDate = new MongoDate(strtotime($dateString));
|
|
$mongoDate = new MongoDB\BSON\UTCDateTime( strtotime($dateString) * 1000);
|
|
$notizia->about->data = $mongoDate;
|
|
|
|
if(!$edit){
|
|
$notizia->status = NotiziaModel::STATUS_PENDING;
|
|
if (AdminLoginManager::getLogged()->hasRole(AdminModel::ADMIN_TYPE_EDITORE_SUPERVISOR)){
|
|
$notizia->status = NotiziaModel::STATUS_ACCEPTED;
|
|
}
|
|
|
|
$notizia->about->owner = AdminLoginManager::getLogged()->id;
|
|
}
|
|
|
|
$notizia->buildAutoShortenedUrl();
|
|
|
|
if (!array_key_exists($notizia->category,NotiziaModel::$NOTIZIE_CATEGORY)){
|
|
throw new GUIException("La categoria inserita non è valida");
|
|
}
|
|
|
|
GlobalVariables::get("dao")->save($notizia);
|
|
if (AdminLoginManager::getLogged()->hasRole(AdminModel::ADMIN_TYPE_EDITORE_SUPERVISOR)){
|
|
GUIHandler::redirectPost("admin/homeNotizie.php",array("id"=>$notizia->id));
|
|
}
|
|
else {
|
|
GUIHandler::redirect("admin/myNotizie.php");
|
|
}
|
|
}
|
|
}
|
|
}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){
|
|
?>
|
|
<div style="font-size: 16px; color:red;">
|
|
<?php echo $error;?>
|
|
</div>
|
|
<?php
|
|
}
|
|
?>
|
|
<form method="POST" id="notiziaForm">
|
|
<input type="hidden" value="<?php echo $notiziaId;?>" name="id"/>
|
|
<div style="padding:5px;display:inline-block;">
|
|
<span class="label">Categoria:</span>
|
|
<select name="category">
|
|
<option disabled="disabled" selected="selected" style="display:none;">Seleziona una categoria</option>
|
|
<?php foreach (NotiziaModel::$NOTIZIE_CATEGORY as $category=>$data){
|
|
if(strcmp($notizia->category,$category)==0){?>
|
|
<option value="<?php echo $category;?>" selected="selected">
|
|
<?php }
|
|
else{ ?>
|
|
<option value="<?php echo $category;?>">
|
|
<?php } ?>
|
|
<?php echo $data["label"];?></option>
|
|
<?php } ?>
|
|
</select>
|
|
</div>
|
|
<div >
|
|
<span class="label">Autore:</span>
|
|
<input type="text" value="<?php echo $notizia->about->author;?>" name="author"/>
|
|
</div>
|
|
<div style="">
|
|
<span class="label">Titolo:</span>
|
|
<textarea name="titolo" rows="3" cols="80" style="resize:none;"><?php echo $notizia->titolo;?></textarea>
|
|
</div>
|
|
<div style="">
|
|
<span class="label">Sottotitolo:</span>
|
|
<textarea name="sottotitolo" rows="3" cols="80" style="resize:none;"><?php echo $notizia->sottotitolo;?></textarea>
|
|
</div>
|
|
<div style="text-align:center;">Corpo della notizia</div>
|
|
<textarea name="testo" id="editore_testo" rows="10" cols="80"><?php echo $notizia->testo;?></textarea>
|
|
<div style="display:inline-block;"><span class="label">Data:</span><input type="text" id="datepicker" name="data" value="<?php echo (!is_null($notizia->about->data))?date("d-m-Y",$notizia->about->data->toDateTime()->getTimestamp()):"";?>"></div>
|
|
<div style="display:inline-block;"><span class="label">Ora:</span><input type="text" id="timepicker" name="time" value="<?php echo (!is_null($notizia->about->data))?date("H:i",$notizia->about->data->toDateTime()->getTimestamp()):"";?>"></div>
|
|
|
|
<input type="hidden" name="action" value=""/>
|
|
</form>
|
|
|
|
<div class="formBtns">
|
|
<a href="#" id="submit" >Salva</a>
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
CKEDITOR.replace( 'editore_testo');
|
|
$(document).ready(function(event){
|
|
$("#submit").click(function(event){
|
|
$("form#notiziaForm input[type=hidden][name=action]").val("save");
|
|
$("form#notiziaForm").submit();
|
|
});
|
|
|
|
$("#datepicker").datepicker({dateFormat:"dd-mm-yy"});
|
|
$("#timepicker").datetimepicker({datepicker:false,
|
|
format:'H:i'});
|
|
});
|
|
</script>
|