<script type="text/javascript">
function valban(form){
	if (form.title.value == ""){
		$(".page-error").show();
		form.title.focus();
		return (false);
	}
	if (form.url.value == ""){
		$(".page-error").show();
		form.url.focus();
		return (false);
	}
	return (true);
}
</script>

<script type="text/javascript">
$(document).ready(function () {
	$("#title").keyup(function() {
		$(".page-error").fadeOut('slow');
	});
	$("#url").keyup(function() {
		$(".page-error").fadeOut('slow');
	});
});
</script>

<script language="javascript">
$(document).ready( function() {
	$("#btnalertdel").click(function(){
		var id = $('#delid').val();
		var mod = 'banner';
		var act =  'delete';
		var dataString = 'id='+ id + '&mod='+ mod + '&act='+ act;
		$.ajax({
			type: "POST",
			url: "po-component/po-banner/proses.php",
			data: dataString,
			cache: false,
			success: function(){
				$('#del'+id).slideUp('slow', function() {$(this).remove();});
				$('#alertdel').modal('hide');
			}
		});
		return false;
	});
});
</script>

<?php
//Author  	= 'Jenuar Dwi Putra Dalapang';
//Contact 	= 'mailto:djenuar@gmail.com';

session_start();
if (empty($_SESSION['namauser']) AND empty($_SESSION['passuser'])){
	header('location:404.php');
}else{

$aksi="po-component/po-banner/proses.php";
switch($_GET[act]){
	default:
?>
<script language="javascript">
$(document).ready( function() {
var oTable = $('#tableboot').dataTable();
	oTable.$(".alertdel").click(function(){
		var id = $(this).attr("id");
		$('#alertdel').modal('show');
		$('#delid').val(id);
	});
});
</script>

<script language="javascript">
$(document).ready( function() {
var oTable = $('#tableboot').dataTable();
	oTable.$(".btn_edit").click(function(){
		var id = $(this).attr("id");
		$('#edit'+id).modal('show');
	});
});
</script>
<?php
	echo "<div class='page-header'>
		<div class='icon'>
			<span class='ico-coins'></span>
		</div>
		<h1>Banner Management<small><span class='text-info'>Input, edit, view and delete banner management</span></small></h1>
	</div>
	<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>";
				$tablebanner = new PoTable('banner');
				$banners = $tablebanner->findAll(id_banner, DESC);
				echo "<div class='data-fluid'>
				<a class='btn btn-inverse' href='?mod=banner&act=addnew'><i class='icon-plus-sign icon-white'></i> Add New</a>
				<p>&nbsp;</p>
					<table cellspacing='0' border='0' class='table table-hover' id='tableboot'>
						<thead><tr>
							<th>No</th>
							<th>Title</th>
							<th>Url</th>
							<th>Preview</th>
							<th>Date</th>
							<th>Size</th>
							<th>Action</th>
						</tr></thead><tbody>";
						$no=1;
						foreach($banners as $banner){
						$urlcar = addhttp($banner->url);
						echo "<tr class='gradeA' id='del$banner->id_banner'>
							<td>$no</td>
							<td>$banner->title</td>
							<td><a href='$urlcar' target='_blank'>$urlcar</a></td>
							<td><div id='gallery'><i class='icon-picture'></i> <a class='fb' rel='group' href='../po-content/po-upload/banner/$banner->picture'>Image</a></div></td>
							<td>$banner->date</td>
							<td>$banner->size</td>
							<td>
								<a href='#edit$banner->id_banner' id='$banner->id_banner' class='btn_edit'><span class='label label-info'><i class='icon-edit icon-white'></i>Edit</span></a>
								<a href='#delete$banner->id_banner' class='alertdel' id='$banner->id_banner'><span class='label label-important'><i class='icon-remove icon-white'></i>Delete</span></a>
							</td>
						</tr>
						<div id='edit$banner->id_banner' class='modal hide fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel2' aria-hidden='true' style='width:570px;'>
							<form method='post' action='$aksi' autocomplete='off'>
							<input type='hidden' name='mod' value='banner'>
							<input type='hidden' name='act' value='update'>
							<input type='hidden' name='id' value='$banner->id_banner'>
							<div class='modal-header'>
								<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
								<h3 id='myModalLabel2'>Edit Banner</h3>
							</div>
							<div class='modal-body'>
								<label>Title</label><input class='input-xxlarge' type='text' id='title' name='title' value='$banner->title' required>
								<label>Url</label><input class='input-xxlarge' type='text' id='url' name='url' value='$banner->url' required>
							</div>
							<div class='modal-footer'>
								<button class='btn' data-dismiss='modal' aria-hidden='true'>Cancel</button>
								<button class='btn btn-info' type='submit'>Submit</button>
							</div>
							</form>
						</div>";
						$no++;
						}
					echo "</tbody></table>
				</div>
			</div>
			<div style='width:100%; height:500px;'>&nbsp;</div>
		</div>
	</div>

	<div id='alertdel' class='modal hide fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel3' aria-hidden='true' style='width:570px;'>
		<div class='modal-header'>
			<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
			<h3 id='myModalLabel3'>Confirmation Deletion</h3>
		</div>
		<div class='modal-body'>
			<input type='hidden' id='delid' name='delid'>
			<span class='ico-warning'></span> Are you sure want to delete this data?
		</div>
		<div class='modal-footer'>
			<button id='btnalertdel' class='btn btn-danger'>Yes</button>
			<button class='btn' data-dismiss='modal' aria-hidden='true'>No</button>
		</div>
	</div>";
    break;

	case "addnew":
	echo "<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>
				<legend><i class='icon-plus-sign'></i> Add New</legend>
				<form method='post' action='$aksi' enctype='multipart/form-data' autocomplete='off' onSubmit='return valban(this)'>
					<input type='hidden' name='mod' value='banner'>
					<input type='hidden' name='act' value='input'>
					<fieldset>
						<label>Title</label><input class='input-xxlarge' type='text' id='title' name='title' required>
						<label>Url</label><input class='input-xxlarge' type='text' id='url' name='url' required>
						<label>Size</label>
						<select class='select' name='size' style='width:280px;'>
							<option value='180' selected>180</option>
							<option value='480'>480</option>
						</select>
						<label>Image *</label>
						<div id='uploadfpc'>
							<div class='fileupload fileupload-new' data-provides='fileupload'>
								<div class='fileupload-new thumbnail' style='width: 200px; height: 150px;'>
									<img src='data:image/gif;base64,R0lGODdhyACWAOMAAO/v76qqqubm5t3d3bu7u7KystXV1cPDw8zMzAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAyACWAAAE/hDISau9OOvNu/9gKI5kaZ5oqq5s675wLM90bd94ru987//AoHBILBqPyKRyyWw6n9CodEqtWq/YrHbL7Xq/4LB4TC6bz+i0es1uu9/wuHxOr9vv+Lx+z+/7/4CBgoOEhYaHiImKi4yNjo+QkZKTlJWWl5iZmpucnZ6foKGio6SlpqeoqaqrrK2ur7CxsrO0tba3TAMFBQO4LAUBAQW+K8DCxCoGu73IzSUCwQECAwQBBAIVCMAFCBrRxwDQwQLKvOHV1xbUwQfYEwIHwO3BBBTawu2BA9HGwcMT1b7Vw/Dt3z563xAIrHCQnzsAAf0F6ybhwDdwgAx8OxDQgASN/sKUBWNmwQDIfwBAThRoMYDHCRYJGAhI8eRMf+4OFrgZgCKgaB4PHqg4EoBQbxgBROtlrJu4ofYm0JMQkJk/mOMkTA10Vas1CcakJrXQ1eu/sF4HWhB3NphYlNsmxOWKsWtZtASTdsVb1mhEu3UDX3RLFyVguITzolQKji/GhgXNvhU7OICgsoflJr7Qd2/isgEPGGAruTTjnSZTXw7c1rJpznobf2Y9GYBjxIsJYQbXstfRDJ1luz6t2TDvosSJSpMw4GXG3TtT+hPpEoPJ6R89B7AaUrnolgWwnUQQEKVOAy199mlonPDfr3m/GeUHFjBhAf0SUh28+P12QOIIgDbcPdwgJV+Arf0jnwTwsHOQT/Hs1BcABObjDAcTXhiCOGppKAJI6nnIwQGiKZSViB2YqB+KHtxjjXMsxijjjDTWaOONOOao44489ujjj0AGKeSQRBZp5JFIJqnkkkw26eSTUEYp5ZRUVmnllVhmqeWWXHbp5ZdghinmmGSW6UsEADs=' />
								</div>
								<div class='fileupload-preview fileupload-exists thumbnail' style='max-width: 200px; max-height: 150px; line-height: 20px;'></div>
							<div>
							<span class='btn btn-file'>
								<span class='fileupload-new'>Select image</span>
								<span class='fileupload-exists'>Change</span>
								<input type='file' name='fupload' required>
							</span>
							<a href='#' class='btn fileupload-exists' data-dismiss='fileupload'>Remove</a>
						</div>
						</div></div>
						<span class='label label-important'>*) Please upload image type must be jpg.</span>
						<br /><br />
						<input class='btn btn-large' type='submit' value='Submit'>
						<input class='btn btn-large btn-inverse' type='button' value='Cancel' onclick=self.history.back()>
					</fieldset>
				</form><br />
				<div class='page-error'>
					<div class='alert alert-error'>
					<strong><i class='icon-file icon-white'></i> Warning!</strong> Best check yourself, you're not looking too good.
				</div>
			</div>
		</div>
	</div>
	<div style='width:100%; height:500px;'>&nbsp;</div>";
	break;
}
}
?>