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

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

<script language="javascript">
$(document).ready( function() {
	$(".alertdel").click(function(){
		var id = $(this).attr("id");
		$('#alertdel').modal('show');
		$('#delid').val(id);
	});
});
</script>

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

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

$aksi="po-component/po-theme/proses.php";
switch($_GET[act]){
  default:
	if ($_SESSION[leveluser]=='admin'){
	echo "<div class='page-header'>
		<div class='icon'>
			<span class='ico-brush'></span>
		</div>
		<h1>$langtheme1<small><span class='text-info'>$langtheme2</span></small></h1>
	</div>
	<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>";
				$tabletheme = new PoTable('theme');
				$themes = $tabletheme->findAll(id_theme, DESC);
				echo "<div class='data-fluid'>
				<a class='btn btn-inverse' href='?mod=theme&act=addnew'><i class='icon-plus-sign icon-white'></i> $langtheme3</a>
				<p>&nbsp;</p>
				<div class='data-fluid thumbs'>";
					foreach($themes as $theme){
						echo "<div class='thumbnail' id='del$theme->id_theme'>
                            <a class='fb' rel='group' href='../po-content/$theme->folder/preview.jpg'><img src='../po-content/$theme->folder/preview.jpg' class='img-polaroid'/></a>
                            <div class='caption'>
								<h3>$theme->title</h3>
								<p>$langtheme4 $theme->author</p>
                                <p>
									<div class='alertdel' id='$theme->id_theme' style='float:left;'><a class='btn btn-warning' href='#delete$theme->id_theme'>$langtheme5</a>&nbsp;</div>
									<form method='post' action='$aksi' autocomplete='off'>
										<input type='hidden' name='mod' value='theme'>
										<input type='hidden' name='act' value='active'>
										<input type='hidden' name='id' value='$theme->id_theme'>";
											if ($theme->active=='Y'){
												echo "<input type='hidden' name='active' value='N'>
												<div style='float:left;'><button class='btn btn-inverse' type='submit'>$langtheme6</button></div>";
											}else{
												echo "<input type='hidden' name='active' value='Y'>
												<div style='float:left;'><button class='btn' type='submit'>$langtheme7</button></div>";
											}
									echo "</form>
								</p>
                            </div>
                        </div>";
					}
				echo "</div>
				</div>
			</div>
			<div style='width:100%; height:600px;'>&nbsp;</div>
		</div>
	</div>

	<div id='alertdel' 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'>$langdelete1</h3>
		</div>
		<div class='modal-body'>
			<input type='hidden' id='delid' name='delid'>
			<span class='ico-warning'></span> $langdelete2
		</div>
		<div class='modal-footer'>
			<button id='btnalertdel' class='btn btn-danger'>$langdelete3</button>
			<button class='btn' data-dismiss='modal' aria-hidden='true'>$langdelete4</button>
		</div>
	</div>";
	}else{
		echo "<div class='page-header'></div>
		<div class='row-fluid'>
			<div class='span12'>
				<div class='errorContainerpage'>
					<h1>404</h1>
					<h2>$langtheme1</h2>
					<button class='btn btn-large btn-primary' onClick='document.location.href=\"admin.php?mod=home\";'>$langpagenotfound2</button> <button class='btn btn-large' onClick='history.back();'>$langpagenotfound3</button>
				</div>
			</div>
		</div>";
	}
    break;


	case "addnew":
	if ($_SESSION[leveluser]=='admin'){
	echo "<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>
				<legend><i class='ico-brush'></i> Add New</legend>
				<form method='post' action='$aksi' enctype='multipart/form-data' autocomplete='off'>
					<input type='hidden' name='mod' value='theme'>
					<input type='hidden' name='act' value='input'>
					<fieldset>
						<label>Title</label><input class='input-xxlarge' type='text' id='title' name='title' required>
						<label>Author</label><input class='input-xxlarge' type='text' id='author' name='author' required>
						<label>Folder</label><input class='input-xxlarge' type='text' id='folder' name='folder' required>
						<label>Please select theme <i>(.zip)</i></label>
						<div class='row-form' style='margin-left:-15px;'>
						<div class='span4'>
                            <div class='input-append file'>
                                <input style='width: 284px;' name='fupload' type='file' required>
								<input style='width: 297px;' type='text'>
								<span class='btn'>Browse</span>
							</div>
                        </div>
						</div><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>Warning!</strong> Best check yourself, you're not looking too good.
					</div>
				</div>
			</div>
		</div>
	</div>
	<div style='width:100%; height:500px;'>&nbsp;</div>";
	}else{
		echo "<div class='page-header'></div>
		<div class='row-fluid'>
			<div class='span12'>
				<div class='errorContainerpage'>
					<h1>404</h1>
					<h2>$langtheme1</h2>
					<button class='btn btn-large btn-primary' onClick='document.location.href=\"admin.php?mod=home\";'>$langpagenotfound2</button> <button class='btn btn-large' onClick='history.back();'>$langpagenotfound3</button>
				</div>
			</div>
		</div>";
	}
	break;
}
}
?>