258 lines
9.4 KiB
PHP
258 lines
9.4 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->link = PostHandler::get("link");
|
|
|
|
if (strcmp("",PostHandler::get("position"))==0){
|
|
throw new GUIException("Selezionare una posizione per il banner");
|
|
}
|
|
$banner->position = PostHandler::get("position");
|
|
|
|
|
|
$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>
|
|
</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->sec):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->sec):date("d-m-Y");?>">
|
|
</div>
|
|
|
|
</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>
|