<script type="text/javascript">
function valcat(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 language="javascript">
$(document).ready( function() {
	$("#btnalertdel").click(function(){
		var id = $('#delid').val();
		var mod = 'category';
		var act =  'delete';
		var dataString = 'id='+ id + '&mod='+ mod + '&act='+ act;
		$.ajax({
			type: "POST",
			url: "po-component/po-category/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-category/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>
<?php
	echo "<div class='page-header'>
		<div class='icon'>
			<span class='ico-pen-2'></span>
		</div>
		<h1>$langcategory1<small><span class='text-info'>$langcategory2</span></small></h1>
	</div>
	<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>";
				$tablecategory = new PoTable('category');
				$categorys = $tablecategory->findAll(id_category, DESC);
				echo "<div class='data-fluid'>
				<a class='btn btn-inverse' href='?mod=category&act=addnew'><i class='icon-pencil icon-white'></i> $langcategory7</a>
				<p>&nbsp</p>
					<table cellspacing='0' border='0' class='table table-hover' id='tableboot'>
						<thead><tr>
							<th>No</th>
							<th>$langcategory3 <i>($langcategory4)</i></th>
							<th>$langcategory5</th>
							<th>$langcategory6</th>
						</tr></thead><tbody>"; 
						$no=1;
						foreach($categorys as $category){
							echo "<tr class='gradeA' id='del$category->id_category'>
								<td>$no</td>
								<td>$category->title_id <i>($category->title_en)</i></td>
								<td>$category->active</td>
								<td>
									<a href='?mod=category&act=edit&id=$category->id_category'><span class='label label-info'><i class='icon-file icon-white'></i> $langaction1</span></a>
									<a href='#delete$category->id_category' class='alertdel' id='$category->id_category'><span class='label label-important'><i class='icon-remove icon-white'></i>$langaction2</span></a>
								</td>
						</tr>";
						$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='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>";
    break;


	case "addnew":
	echo "<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>
				<legend><i class='icon-pencil'></i> Add New</legend>
				<form method='post' action='$aksi' onSubmit='return valcat(this)' autocomplete='off'>
					<input type='hidden' name='mod' value='category'>
					<input type='hidden' name='act' value='input'>
					<fieldset>
						<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>
						<p>&nbsp</p>
						<input class='btn btn-large' type='submit' value='Submit'>
						<input class='btn btn-large btn-inverse' type='button' value='Cancel' onclick=self.history.back()>
						<p>&nbsp</p>
						<p>&nbsp</p>
					</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:600px;'>&nbsp;</div>";
	break;


	case "edit":
	$valid = $val->validasi($_GET['id'],'sql');
	$table = new PoTable('category');
	$currentCategory = $table->findBy(id_category, $valid);
	$currentCategory = $currentCategory->current();
	echo "<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>
				<legend><i class='icon-pencil'></i> Edit Category</legend>
				<form method='post' action='$aksi' onSubmit='return valcat(this)' autocomplete='off'>
					<input type='hidden' name='mod' value='category'>
					<input type='hidden' name='act' value='update'>
					<input type='hidden' name='id' value='$currentCategory->id_category'>
					<fieldset>
						<label>Title Id</label><input class='input-xxlarge' type='text' id='title_id' name='title_id' value='$currentCategory->title_id' required>
						<label>Title En</label><input class='input-xxlarge' type='text' id='title_en' name='title_en' value='$currentCategory->title_en' required>";
						if ($currentCategory->active=='N'){
							echo "<label>Active</label>
							<label class='radio inline'><input type='radio' name='active' value='Y'>Y</label>
							<label class='radio inline'><input type='radio' name='active' value='N' checked>N</label><br /><br />";
						}else{
							echo "<label>Active</label>
							<label class='radio inline'><input type='radio' name='active' value='Y' checked>Y</label>
							<label class='radio inline'><input type='radio' name='active' value='N'>N</label><br /><br />";
						}
						echo "<input class='btn btn-large' type='submit' value='Submit'>
						<input class='btn btn-large btn-inverse' type='button' value='Cancel' onclick=self.history.back()>
						<p>&nbsp</p>
						<p>&nbsp</p>
					</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:600px;'>&nbsp;</div>";
	break;
}
}
?>