130 lines
4.0 KiB
PHP
130 lines
4.0 KiB
PHP
<?php
|
|
/*
|
|
Author: Riccardo Di Dato
|
|
Creation Date: 02/mar/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_BANNER)){
|
|
GUIHandler::redirect("admin/listBanner.php");
|
|
}
|
|
|
|
MenuGenerator::generateMenu();
|
|
HTMLHelper::generateAdminHead();
|
|
|
|
|
|
try{
|
|
$error = "";
|
|
$bannerId = PostHandler::get("id");
|
|
|
|
$banner = null;
|
|
if (!is_null($bannerId) && strcmp("",$bannerId)!=0){
|
|
$banner = GlobalVariables::get("dao")->getFirst("BannerModel",array("id"=>$bannerId));
|
|
}
|
|
if (is_null($banner)){
|
|
GUIHandler::redirect("admin/listBanner.php");
|
|
}
|
|
|
|
|
|
if(array_key_exists("action", $_POST) && strcmp(PostHandler::get("action"), "save")==0){
|
|
$mediaType = PostHandler::get("mediaType");
|
|
|
|
if (!is_null($mediaType) && strcmp($mediaType, "")!=0){
|
|
$media = null;
|
|
$banner->type=$mediaType;
|
|
|
|
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($media);
|
|
DaoMediaHandler::deleteAllMedias($banner);
|
|
DaoMediaHandler::setMainMediaToModel($banner, $media);
|
|
|
|
GUIHandler::redirectPost("admin/homeBanner.php",array("id"=>$banner->id));
|
|
}
|
|
}
|
|
}
|
|
|
|
}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){
|
|
?>
|
|
<div style="font-size: 16px; color:red;">
|
|
<?php echo $error;?>
|
|
</div>
|
|
<?php
|
|
}
|
|
?>
|
|
<div>
|
|
<form enctype="multipart/form-data" id="loadFile" method="POST">
|
|
<input type="hidden" name="id" value="<?php echo $bannerId;?>" />
|
|
<input type="hidden" name="action" value=""/>
|
|
<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"></div>
|
|
</form>
|
|
<div class="formBtns">
|
|
<a href="#" id="submit" >Salva</a>
|
|
<a href="#" id="back" >Annulla</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
$("#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){
|
|
openPagePost('homeBanner.php',[{name:'id',value:'<?php echo $bannerId;?>'}]);
|
|
});
|
|
</script>
|