Creati nuovi banner lunghi Aumentate numero notizie ansa Aumentate numero notizie cronaca in homepage fix mobile articolo per show player video modifica amministrazione per show player mobile
280 lines
11 KiB
PHP
280 lines
11 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)){
|
|
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){
|
|
$mediaType = PostHandler::get("mediaType");
|
|
if (!is_null($mediaType) && strcmp($mediaType, "")!=0){
|
|
$banner->type=$mediaType;
|
|
|
|
$banner->customer = PostHandler::get("customer");
|
|
// $banner->start = new Mongodate(strtotime(PostHandler::get("dateStart")));
|
|
// $banner->end = new Mongodate(strtotime(PostHandler::get("dateEnd")));
|
|
|
|
$banner->start = new MongoDB\BSON\UTCDateTime( strtotime(PostHandler::get("dateStart")) * 1000 );
|
|
$banner->end = new MongoDB\BSON\UTCDateTime( strtotime(PostHandler::get("dateEnd")) * 1000 );
|
|
|
|
$banner->link = PostHandler::get("link");
|
|
|
|
if (strcmp("",PostHandler::get("position"))==0){
|
|
throw new GUIException("Selezionare una posizione per il banner");
|
|
}
|
|
$banner->position = PostHandler::get("position");
|
|
|
|
$banner->categories = array();
|
|
|
|
$general = PostHandler::get("categories_".BannerModel::GENERAL_CATEGORY);
|
|
if (!is_null($general) && strcasecmp($general, BannerModel::GENERAL_CATEGORY)==0){
|
|
$banner->categories[] = BannerModel::GENERAL_CATEGORY;
|
|
}
|
|
foreach (NotiziaModel::$NOTIZIE_CATEGORY as $category=>$data){
|
|
$val = PostHandler::get("categories_".$category);
|
|
if (!is_null($val) && strcasecmp($val, $category)==0){
|
|
$banner->categories[] = $category;
|
|
}
|
|
}
|
|
|
|
$media = null;
|
|
if ($banner->type == MediaModel::TYPE_HTML5){
|
|
$saveableMedia = new stdClass();
|
|
$saveableMedia->mediaType = MediaModel::TYPE_HTML5;
|
|
$saveableMedia->code = PostHandler::get("data");
|
|
$media = DaoMediaHandler::createNewTextBasedMedia($saveableMedia);
|
|
}
|
|
else if ($banner->type == MediaModel::TYPE_IMAGE){
|
|
$saveableMedia = new stdClass();
|
|
$saveableMedia->mediaType = MediaModel::TYPE_IMAGE;
|
|
|
|
$file = $_FILES['data']['tmp_name'];
|
|
$extension = pathinfo($_FILES['data']['name'], PATHINFO_EXTENSION);
|
|
|
|
$media = DaoMediaHandler::createNewFileBasedMedia($saveableMedia, $file, $extension);
|
|
}
|
|
|
|
if (!is_null($media)){
|
|
GlobalVariables::get("dao")->save($banner);
|
|
// GlobalVariables::get("dao")->save($media);
|
|
DaoMediaHandler::addMedia($banner, $media);
|
|
// GlobalVariables::get("dao")->save($banner);
|
|
GUIHandler::redirectPost("admin/homeBanner.php",array("id"=>$banner->id));
|
|
}
|
|
else {
|
|
throw new GUIException("I dati inseriti per il file multimediale non sono validi");
|
|
}
|
|
}
|
|
else {
|
|
throw new GUIException("Selezionare il tipo di file multimediale da utilizzare");
|
|
}
|
|
|
|
|
|
// 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">Posizione:</span>
|
|
<select name="position">
|
|
<option disabled selected style="display:none;">Seleziona Posizione</option>
|
|
<option value="<?php echo BannerModel::POSITION_HEAD;?>"><?php echo BannerModel::$BANNER_POSITIONS[BannerModel::POSITION_HEAD]["label"];?></option>
|
|
<option value="<?php echo BannerModel::POSITION_BODY;?>"><?php echo BannerModel::$BANNER_POSITIONS[BannerModel::POSITION_BODY]["label"];?></option>
|
|
<option value="<?php echo BannerModel::POSITION_LONG;?>"><?php echo BannerModel::$BANNER_POSITIONS[BannerModel::POSITION_LONG]["label"];?></option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<span class="label">Tipo Multimedia:</span>
|
|
<select id="mediaType" name="mediaType">
|
|
<option disabled selected style="display:none;">Seleziona Tipo</option>
|
|
<option value="<?php echo MediaModel::TYPE_HTML5;?>"><?php echo MediaModel::$MEDIA_TYPES[MediaModel::TYPE_HTML5]["label"];?></option>
|
|
<option value="<?php echo MediaModel::TYPE_IMAGE;?>"><?php echo MediaModel::$MEDIA_TYPES[MediaModel::TYPE_IMAGE]["label"];?></option>
|
|
</select>
|
|
</div>
|
|
<div id="mediaDetailsRow">
|
|
<?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>
|
|
<span class="label">Cliente:</span>
|
|
<input type="text" name="customer" value="<?php echo $banner->customer;?>" />
|
|
</div>
|
|
<div>
|
|
<span class="label">Link:</span>
|
|
<input type="text" name="link" value="<?php echo $banner->link;?>" />
|
|
</div>
|
|
<div>
|
|
<span class="label">Data inizio:</span>
|
|
<input type="text" id="datepickerStart" name="dateStart" value="<?php echo ($edit)? date("d-m-Y",$banner->start->toDateTime()->getTimestamp()):date("d-m-Y");?>">
|
|
</div>
|
|
<div>
|
|
<span class="label">Data fine:</span>
|
|
<input type="text" id="datepickerEnd" name="dateEnd" value="<?php echo ($edit)? date("d-m-Y",$banner->end->toDateTime()->getTimestamp()):date("d-m-Y");?>">
|
|
</div>
|
|
<?php
|
|
echo '<div><span class="label">Generale</span><input type="checkbox" name="categories_'.BannerModel::GENERAL_CATEGORY.'" value="'.BannerModel::GENERAL_CATEGORY.'" '.(in_array(BannerModel::GENERAL_CATEGORY, $banner->categories)?'checked="checked"':"").' /><br/>';
|
|
foreach (NotiziaModel::$NOTIZIE_CATEGORY as $category=>$data){
|
|
echo '<div><span class="label">'.$data["label"].'</span><input type="checkbox" name="categories_'.$category.'" value="'.$category.'" '.(in_array($category, $banner->categories)?'checked="checked"':"").' /><br/>';
|
|
}
|
|
?>
|
|
</form>
|
|
<div class="formBtns">
|
|
<a href="#" id="submit" >Salva</a>
|
|
<a href="#" id="back" >Annulla</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){
|
|
var value = $(this).val();
|
|
|
|
if (value == <?php echo MediaModel::TYPE_HTML5; ?>){
|
|
$('#mediaDetailsRow').html('<span class="label">Inserire html:</span><textarea type="text" name ="data"/ rows="5" cols="30"></textarea>');
|
|
|
|
}
|
|
else if (value == <?php echo MediaModel::TYPE_IMAGE; ?>){
|
|
$('#mediaDetailsRow').html('<input type="hidden" name="MAX_FILE_SIZE" value="52428800" />'+
|
|
'<span class="label">Seleziona file</span><input type="file" name="data" />');
|
|
}
|
|
});
|
|
|
|
$("#back").click(function(event){
|
|
window.location.href="<?php echo GUIHandler::getBaseUrl();?>admin/listBanner.php";
|
|
});
|
|
|
|
$("#datepickerStart").datepicker({dateFormat:"dd-mm-yy"});
|
|
$("#datepickerEnd").datepicker({dateFormat:"dd-mm-yy"});
|
|
});
|
|
</script>
|