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

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

<script type="text/javascript">
$(document).ready(function () {
	$('#picture').keypress(function(e){
		e.preventDefault();    
	});
    $('#btn_uploadfpc').click(function(){
		$('#uploadfpc').show();
		$('#uploadfweb').hide();
		$('#picture').val('');
    });
    $('#btn_uploadfweb').click(function(){
		$('#uploadfpc').hide();
		$('#uploadfweb').show();
		$('#picture').val('');
    });
});
</script>

<script type="text/javascript">
	$(document).ready(function(){
		$('#paging_container').pajinate({
			items_per_page : 5,
			num_page_links_to_display : 5
					
		});
	});
</script>

<script type="text/javascript">
$(document).ready(function(){
	$('a[data-toggle="modal"]').click(function(e) {
		e.preventDefault();
		target = ($ @).attr('data-target')
		url = ($ @).attr('href')
		($ target).load(url)
	});
});
</script>

<script type="text/javascript">
$(document).ready(function () {
    $('.addtoform').click(function(){
		var name = $(this).attr("id");
		$('#addimage').modal('hide');
		$('#picture').val(name);
    });
});
</script>

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

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

<script type="text/javascript">
$(document).ready(function () {
    $('#btnaddalbum').click(function(){
		$('#addalbum').modal('show');
    });
});
</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-gallery/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_editgallery").click(function(){
		var id = $(this).attr("id");
		$('#editgal'+id).modal('show');
	});
});
</script>
<?php
	echo "<div class='page-header'>
		<div class='icon'>
			<span class='ico-image'></span>
		</div>
		<h1>Gallery Management<small><span class='text-info'>Input, edit, view and delete gallery management</span></small></h1>
	</div>
	<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>";
				$tablegallery = new PoTable('gallery');
				$gallerys = $tablegallery->findAll(id_gallery, DESC);
				echo "<div class='data-fluid'>
				<a class='btn btn-inverse' href='?mod=gallery&act=addnew'><i class='icon-picture icon-white'></i> Add New</a>
				<a class='btn btn-inverse' href='?mod=gallery&act=album'><i class='icon-picture icon-white'></i> Album</a>
				<p>&nbsp;</p>
					<table cellspacing='0' border='0' class='table table-hover' id='tableboot'>
						<thead><tr>
							<th>No</th>
							<th>Album</th>
							<th>Title <i>(Title En)</i></th>
							<th>Preview</th>
							<th>Action</th>
						</tr></thead><tbody>";
						$no=1;
						foreach($gallerys as $gallery){
						$valid = $gallery->id_album;
						$tablealbum = new PoTable('album');
						$currentAlbum = $tablealbum->findBy(id_album, $valid);
						$currentAlbum = $currentAlbum->current();
						echo "<tr class='gradeA' id='del$gallery->id_gallery'>
							<td>$no</td>
							<td>$currentAlbum->title_id</td>
							<td>$gallery->title_id <i>($gallery->title_en)</i></td>
							<td><div id='gallery'><i class='icon-picture'></i> <a class='fb' rel='group' href='../po-content/po-upload/$gallery->picture'>Image</a></div></td>
							<td>
								<a href='#edit$gallery->id_gallery' id='$gallery->id_gallery' class='btn_editgallery'><span class='label label-info'><i class='icon-edit icon-white'></i>Edit</span></a>
								<a href='#delete$gallery->id_gallery' class='alertdel' id='$gallery->id_gallery'><span class='label label-important'><i class='icon-remove icon-white'></i>Delete</span></a>
							</td>
						</tr>
						<div id='editgal$gallery->id_gallery' class='modal hide fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel4' aria-hidden='true' style='width:570px;'>
							<form method='post' action='$aksi' autocomplete='off'>
							<input type='hidden' name='mod' value='gallery'>
							<input type='hidden' name='act' value='editgallery'>
							<input type='hidden' name='id' value='$gallery->id_gallery'>
							<div class='modal-header'>
								<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
								<h3 id='myModalLabel4'>Edit Gallery</h3>
							</div>
							<div class='modal-body'>
								<label>Album</label>
								<select class='select' name='id_album' style='width:280px;'>";
									echo "<option value='$currentAlbum->id_album'>$currentAlbum->title_id</option>";
									$als = $tablealbum->findNotAll(id_album, $valid);
									foreach($als as $al){
										echo "<option value='$al->id_album'>$al->title_id</option>";
									}
								echo "</select>
								<label>Title Id</label><input class='input-xxlarge' type='text' id='title_id' name='title_id' value='$gallery->title_id' required>
								<label>Title En</label><input class='input-xxlarge' type='text' id='title_en' name='title_en' value='$gallery->title_id' 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-picture'></i> Add New</legend>
				<form method='post' action='$aksi' enctype='multipart/form-data' autocomplete='off' onSubmit='return valgal(this)'>
					<input type='hidden' name='mod' value='gallery'>
					<input type='hidden' name='act' value='inputgallery'>
					<fieldset>";
						$tablealbums = new PoTable('album');
						$albums = $tablealbums->findAll(id_album, DESC);
						$numalbums = $tablealbums->numRow();
						if ($numalbums > 0){
							echo "<select class='select' name='id_album' style='width:280px;'>";
							foreach($albums as $album){
								echo "<option value='$album->id_album'>$album->title_id</option>";
							}
							echo "</select>";
							echo "&nbsp;&nbsp;OR&nbsp;&nbsp;<a href='#addalbum' id='btnaddalbum' class='btn btn-info'><i class='icon-plus icon-white'></i> Add New Album</a>";
						}else{
							echo "<a href='#addalbum' id='btnaddalbum' class='btn btn-info'><i class='icon-plus icon-white'></i> Add New Album</a>";
						}
						echo "<p>&nbsp;</p>
						<label>Title Id</label><input class='input-xxlarge' type='text' id='title_id' name='title_id' required>
						<label>Title En</label><input class='input-xxlarge' type='text' id='title_en' name='title_en' required>
						<label>Image *</label>
						<div class='btn-group' data-toggle='buttons-radio'>
							<button type='button' id='btn_uploadfpc' class='btn'>Image From PC</button>
							<a class='btn' id='btn_uploadfweb' data-toggle='modal' href='po-component/po-gallery/media.php' data-target='#addimage'>Image From Web</a>
						</div><br />
						<div id='uploadfpc' style='display:none;'>
							<p>&nbsp;</p>
							<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' />
							</span>
							<a href='#' class='btn fileupload-exists' data-dismiss='fileupload'>Remove</a>
						</div>
						</div></div>
						<div id='uploadfweb' style='display:none;'>
							<p>&nbsp;</p>
							<label>Image</label><input class='input-xxlarge' type='text' id='picture' name='picture'>
						</div><br />&nbsp;
						<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>

	<div id='addalbum' class='modal hide fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true' style='width:570px;'>
	<form method='post' action='$aksi' autocomplete='off'>
		<input type='hidden' name='mod' value='gallery'>
		<input type='hidden' name='act' value='inputalbum'>
		<div class='modal-header'>
			<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
			<h3 id='myModalLabel'>Add New Album</h3>
		</div>
		<div class='modal-body'>
			<label>Title Id</label><input class='input-xxlarge' type='text' id='title_id' name='title_id' required>
			<label>Title En</label><input class='input-xxlarge' type='text' id='title_en' name='title_en' 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 New Album</button>
		</div>
	</div>

	<div id='addimage' class='modal hide fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel2' aria-hidden='true' style='width:570px;'>
		<div class='modal-header'>
			<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
			<h3 id='myModalLabel2'>Add Image From Web</h3>
		</div>
		<div class='modal-body'>
		</div>
		<div class='modal-footer'>
			<button class='btn' data-dismiss='modal' aria-hidden='true'>Cancel</button>
		</div>
	</div>";
	break;

	case "album":
?>
<script language="javascript">
$(document).ready( function() {
var oTable = $('#tableboot').dataTable();
	oTable.$(".alertdela").click(function(){
		var id = $(this).attr("id");
		$('#alertdela').modal('show');
		$('#delida').val(id);
	});
});
</script>

<script language="javascript">
$(document).ready( function() {
var oTable = $('#tableboot').dataTable();
	oTable.$(".btn_editalbum").click(function(){
		var id = $(this).attr("id");
		$('#editalb'+id).modal('show');
	});
});
</script>
<?php
	echo "<div class='page-header'>
		<div class='icon'>
			<span class='ico-image'></span>
		</div>
		<h1>Album Management<small><span class='text-info'>Edit and delete album management</span></small></h1>
	</div>
	<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>";
				$tablealbum = new PoTable('album');
				$albums = $tablealbum->findAll(id_album, DESC);
				echo "<div class='data-fluid'>
				<a class='btn btn-inverse' href='admin.php?mod=gallery'><i class='icon-picture icon-white'></i> Back To Gallery</a>
				<p>&nbsp;</p>
					<table cellspacing='0' border='0' class='table table-hover' id='tableboot'>
						<thead><tr>
							<th>No</th>
							<th>Title <i>(Title En)</i></th>
							<th>Active</th>
							<th>Action</th>
						</tr></thead><tbody>";
						$no=1;
						foreach($albums as $album){
						echo "<tr class='gradeA' id='dela$album->id_album'>
							<td>$no</td>
							<td style='width:60%;'>$album->title_id <i>($album->title_en)</i></td>
							<td>$album->active</td>
							<td>
								<a href='#edit$album->id_album' id='$album->id_album' class='btn_editalbum'><span class='label label-info'><i class='icon-edit icon-white'></i> Edit Album</span></a>
								<a href='#delete$album->id_album' class='alertdela' id='$album->id_album'><span class='label label-important'><i class='icon-remove icon-white'></i>Delete Album</span></a>
							</td>
						</tr>
						<div id='editalb$album->id_album' class='modal hide fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel4' aria-hidden='true' style='width:570px;'>
							<form method='post' action='$aksi' autocomplete='off'>
							<input type='hidden' name='mod' value='gallery'>
							<input type='hidden' name='act' value='editalbum'>
							<input type='hidden' name='id' value='$album->id_album'>
							<div class='modal-header'>
								<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
								<h3 id='myModalLabel4'>Edit Album</h3>
							</div>
							<div class='modal-body'>
								<label>Title Id</label><input class='input-xxlarge' type='text' id='title_id' name='title_id' value='$album->title_id' required>
								<label>Title En</label><input class='input-xxlarge' type='text' id='title_en' name='title_en' value='$album->title_en' required>
								<label>Active</label>
								<select name='activealb' style='width:50px;'>";
								if ($album->active=='N'){
									echo "<option value='N'>N</option>
									<option value='Y'>Y</option>";
								}else{
									echo "<option value='Y'>Y</option>
									<option value='N'>N</option>";
								}
								echo "</select></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='alertdela' class='modal hide fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel5' aria-hidden='true' style='width:570px;'>
		<div class='modal-header'>
			<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
			<h3 id='myModalLabel5'>Confirmation Deletion</h3>
		</div>
		<div class='modal-body'>
			<input type='hidden' id='delida' name='delida'>
			<span class='ico-warning'></span> Are you sure want to delete this data?
		</div>
		<div class='modal-footer'>
			<button id='btnalertdela' class='btn btn-danger'>Yes</button>
			<button class='btn' data-dismiss='modal' aria-hidden='true'>No</button>
		</div>
	</div>";
    break;
}
}
?>