Create pagine per notizie in pending e rifiutate; Creati componenti grafici per mostrare Notizia, Commento e lista commenti; Bugfix e limature su amministrazione
199 lines
7.0 KiB
PHP
199 lines
7.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_BANNER_SUPERVISOR)){
|
|
GUIHandler::redirect("admin/index.php");
|
|
}
|
|
|
|
MenuGenerator::generateMenu();
|
|
|
|
HTMLHelper::generateAdminHead();
|
|
|
|
$bannerId = PostHandler::get("id");
|
|
|
|
try{
|
|
$error="";
|
|
$edit=false;
|
|
$banner = new BannerModel();
|
|
$newMedia = null;
|
|
$mediaTypeSaved = PostHandler::get("mediaType");
|
|
|
|
if(!is_null($bannerId) && strcmp($bannerId, "")!=0){
|
|
$edit = true;
|
|
$banner = GlobalVariables::get("dao")->getFirst("BannerModel",array("id"=>$bannerId));
|
|
$newMedias = DaoMediaHandler::getMedias($banner);
|
|
if(sizeof($newMedias)>0){
|
|
$newMedia = reset($newMedias);
|
|
}
|
|
if($banner->hasProperty("type") && !is_null($banner->type)){
|
|
$mediaTypeSaved = $banner->type;
|
|
}
|
|
}
|
|
|
|
if(array_key_exists("action", $_POST) && strcmp(PostHandler::get("action"), "save")==0){
|
|
if(is_null($bannerId) || strcmp($bannerId, "")==0){
|
|
$banner->customer = PostHandler::get("customer");
|
|
$banner->type = PostHandler::get("mediaType");
|
|
$banner->start = new Mongodate(strtotime(PostHandler::get("dateStart")));
|
|
$banner->end = new Mongodate(strtotime(PostHandler::get("dateEnd")));
|
|
GlobalVariables::get("dao")->save($banner);
|
|
$bannerId = $banner->id;
|
|
}
|
|
|
|
if(!is_null($bannerId) && strcmp($bannerId, "")!=0){
|
|
$edit=true;
|
|
// $banner = GlobalVariables::get("dao")->getFirst("BannerModel",array("id"=>$bannerId));
|
|
$file = "";
|
|
|
|
$mediaType = PostHandler::get("mediaType");
|
|
$banner->type=$mediaType;
|
|
if(strcmp($mediaType, "")!=0){
|
|
$tmp = array();
|
|
$saveable = new stdClass();
|
|
$saveable->mediaType = $mediaType;
|
|
if(strcmp($mediaType,MediaModel::TYPE_HTML5)==0){
|
|
$saveable->code = PostHandler::get("data");
|
|
$media = DaoMediaHandler::createNewTextBasedMedia($saveable);
|
|
}
|
|
else if(strcmp($mediaType,MediaModel::TYPE_IMAGE)==0){
|
|
$file = $_FILES['data']['tmp_name'];
|
|
$info = pathinfo($_FILES['data']['name']);
|
|
// $file = PostHandler::get("data");
|
|
$media = DaoMediaHandler::createNewFileBasedMedia($saveable, $file,$info["extension"]);
|
|
}
|
|
|
|
if(!is_null($media)){
|
|
GlobalVariables::get("dao")->save($media);
|
|
DaoMediaHandler::addMedia($banner, $media);
|
|
GlobalVariables::get("dao")->save($banner);
|
|
}
|
|
else{
|
|
throw new Exception("Cannot save a null media in the news with id '".$bannerId."'");
|
|
}
|
|
}
|
|
else{
|
|
throw new Exception("Invalid mediaType '".$mediaType."' while trying to add the media in editBanner");
|
|
}
|
|
|
|
GUIHandler::redirect("admin/listBanner.php");
|
|
}
|
|
}
|
|
// else if(array_key_exists("action", $_POST) && strcmp(PostHandler::get("action"), "delete")==0){
|
|
// if(!is_null($bannerId) && strcmp($bannerId, "")!=0){
|
|
// $banner = GlobalVariables::get("dao")->getFirst("BannerModel",array("id"=>$bannerId));
|
|
// $medias = DaoMediaHandler::getMedias($banner);
|
|
// // $media = reset($medias);
|
|
// // $media = GlobalVariables::get("dao")->getFirst("MediaModel",array("id"=>$mediaId));
|
|
// foreach ($medias as $media){
|
|
// DaoMediaHandler::deleteMedia($banner, $media);
|
|
// $banner->type = null;
|
|
// GlobalVariables::get("dao")->save($banner);
|
|
// }
|
|
// }
|
|
// GUIHandler::redirect("admin/listBanner.php");
|
|
// }
|
|
$formFile = '<input type="hidden" name="MAX_FILE_SIZE" value="52428800" />
|
|
<span class="label">Seleziona file</span><input type="file" name="data" />';
|
|
if($edit && !is_null($newMedia)){
|
|
$formHtml = '<span class="label">Inserire html:</span><textarea type="text" name ="data"/ rows="5" cols="30">'.$newMedia->code.'</textarea>';
|
|
}
|
|
else{
|
|
$formHtml = '<span class="label">Inserire html:</span><textarea type="text" name ="data"/ rows="5" cols="30"></textarea>';
|
|
}
|
|
|
|
}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
|
|
}
|
|
?>
|
|
<div>
|
|
<form enctype="multipart/form-data" id="loadFile" method="POST">
|
|
<div>
|
|
<span class="label">Tipo:</span>
|
|
<select id="mediaType" name="mediaType">
|
|
<option disabled selected style="display:none;">Seleziona Tipo</option>
|
|
<?php foreach (MediaModel::$MEDIA_TYPES as $mediaType=>$data){
|
|
if(strcmp($mediaType, MediaModel::TYPE_HTML5)==0 || strcmp($mediaType, MediaModel::TYPE_IMAGE)==0){
|
|
if(strcmp($mediaTypeSaved,$mediaType)==0){?>
|
|
<option name="<?php echo $data["label"];?>" value="<?php echo $mediaType;?>" selected="selected">
|
|
<?php
|
|
}
|
|
else{?>
|
|
<option name="<?php echo $data["label"];?>" value="<?php echo $mediaType;?>">
|
|
<?php
|
|
}
|
|
}?>
|
|
<?php echo $data["label"];?></option>
|
|
<?php }?>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<?php
|
|
// <input type="hidden" name="MAX_FILE_SIZE" value="52428800" />
|
|
// <input type="file" name="userFile"/>
|
|
|
|
if(strcmp($mediaTypeSaved, MediaModel::TYPE_HTML5)==0){
|
|
echo $formHtml;
|
|
}
|
|
else if (strcmp($mediaTypeSaved, MediaModel::TYPE_IMAGE)==0){
|
|
echo $formFile;
|
|
}
|
|
?>
|
|
</div>
|
|
<input type="hidden" name="id" value="<?php echo $bannerId;?>" />
|
|
<input type="hidden" name="action" value=""/>
|
|
<div style="margin:10px 0px;"><span class="label">Cliente:</span><input type="text" name="customer" value="<?php echo $banner->customer;?>" /></div>
|
|
<div style=""><span class="label">Data inizio:</span><input type="text" id="datepickerStart" name="dateStart" value="<?php echo ($edit)? date("d-m-Y",$banner->start->sec):date("d-m-Y");?>"></div>
|
|
<div style=""><span class="label">Data fine:</span><input type="text" id="datepickerEnd" name="dateEnd" value="<?php echo ($edit)? date("d-m-Y",$banner->end->sec):date("d-m-Y");?>"></div>
|
|
|
|
</form>
|
|
<div style="margin:15px 5px;">
|
|
<a href="#" id="submit" >Invia</a>
|
|
<a href="#" id="back" >Back</a>
|
|
<!-- <a href="#" id="delete">Delete</a> -->
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
$(document).ready(function(event){
|
|
$("#submit").click(function(event){
|
|
$("form#loadFile input[type=hidden][name=action]").val("save");
|
|
$("form#loadFile").submit();
|
|
});
|
|
|
|
$("#mediaType").change(function (event){
|
|
$("form#loadFile input[type=hidden][name=action]").val("change");
|
|
$("form#loadFile").submit();
|
|
});
|
|
|
|
$("#back").click(function(event){
|
|
$("form#loadFile").attr("action","listBanner.php");
|
|
$("form#loadFile").submit();
|
|
});
|
|
|
|
// $("#delete").click(function(event){
|
|
// $("form#loadFile input[type=hidden][name=action]").val("delete");
|
|
// $("form#loadFile").submit();
|
|
// });
|
|
|
|
$("#datepickerStart").datepicker({dateFormat:"dd-mm-yy"});
|
|
$("#datepickerEnd").datepicker({dateFormat:"dd-mm-yy"});
|
|
});
|
|
</script>
|