<script type="text/javascript">
$(document).ready( function() {
var oTable = $('.dTable').dataTable();
    $('#alertdel').dialog({
		autoOpen: false,
		width: 400,
		modal: true,
		buttons: {
			"<?php echo $langdelete3; ?>": 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();});
				}
				});
				$( this ).dialog( "close" );
			},
			"<?php echo $langdelete4; ?>": function() {
				$( this ).dialog( "close" );
			}
		}
	});
    oTable.$('.alertdel').click(function () {
		var id = $(this).attr("id");
        $('#alertdel').dialog('open');
		$('#delid').val(id);
        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";
?>
	<div class="contentTop">
        <span class="pageTitle"><span class="icon-list"></span><?php echo $langcategory1; ?></span>
    </div>
    <!-- Breadcrumbs line -->
    <div class="breadLine">
        <div class="bc">
            <ul id="breadcrumbs" class="breadcrumbs">
                <li><a href="admin.php?mod=home"><?php echo $langmenu1; ?></a></li>
                <li class="current"><a><?php echo $langcategory2; ?></a></li>
            </ul>
        </div>
    </div>
    <!-- Main content -->
    <div class="wrapper">
<?php
switch($_GET[act]){
  default:
?>
	<div class="widget">
		<div class="whead"><span class="titleIcon check"><input type="checkbox" id="titleCheck" name="titleCheck" /></span><h6><?php echo $langcategory1; ?></h6><div class="clear"></div></div>
			<div id="dyn" class="hiddenpars">
                <a class="tOptions" title="Options"><img src="images/icons/options" alt="" /></a>
				<form method="post" action="<?php echo $aksi; ?>">
					<input type="hidden" name="mod" value="category">
					<input type="hidden" name="act" value="multidelete">
					<input type="hidden" value="0" name="totaldata" id="totaldata">
<?php
				$tablecategory = new PoTable('category');
				$categorys = $tablecategory->findAll(id_category, DESC);
				$str = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
				$strlink = preg_replace("/\/po-admin\/(admin\.php$)/","",$str);
				echo "<table cellpadding='0' cellspacing='0' border='0' class='dTable checkAll check' id='dynamic'>
						<thead><tr>
							<th><img src='images/elements/other/tableArrows.png' /></th>
							<th>No</th>
							<th>Id</th>
							<th>$langcategory3 | Link</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><input type='checkbox' id='titleCheckdel'></td>
								<input type='hidden' class='deldata' name='item[$no][deldata]' value='$category->id_category' disabled>
								<td>$no</td>
								<td>$category->id_category</td>
								<td>
									$category->title
									<br /><i><a href='$strlink/category-$category->id_category-$category->seotitle.html' target='_blank'>$strlink/category-$category->id_category-$category->seotitle.html</a></i>
								</td>
								<td>$category->active</td>
								<td class='tableActs' align='center'>
									<a href='?mod=category&act=edit&id=$category->id_category' class='tablectrl_small bDefault tipS' title='$langaction1'><span class='iconb' data-icon='&#xe1db;'></span></a>
									<span id='$category->id_category' class='alertdel'><a href='#delete$category->id_category' class='tablectrl_small bDefault tipS' title='$langaction2'><span class='iconb' data-icon='&#xe136;'></span></a></span>
								</td>
							</tr>";
						$no++;
						}
					echo "</tbody>
					<tfoot>
						<tr><td colspan='6'><div class='itemActions'><input class='buttonS bRed' type='submit' value='Delete Selected Item' onClick=\"return confirm('$langdelete2')\"></div></td></tr>
					</tfoot>
				</table>";
?>
				</form>
			</div>
		<div class="clear"></div>
	</div>
	<div id="alertdel" title="<?php echo $langdelete1; ?>" style="display:none;">
		<p><input type='hidden' id='delid' name='delid'><span class='icon-warning'></span> <?php echo $langdelete2; ?></p>
	</div>
<?php
    break;


	case "addnew":
?>
		<form id="usualValidate" class="main" method="post" action="<?php echo $aksi; ?>" autocomplete="off">
            <fieldset>
				<div class="widget fluid">
				<div class="whead"><h6>Add New</h6><div class="clear"></div></div>
					<input type="hidden" name="mod" value="category">
					<input type="hidden" name="act" value="input">
					<div class="formRow">
						<div class="grid3"><label>Title</label></div>
						<div class="grid9"><input class="required" type="text" id="title" name="title" required></div>
						<div class="clear"></div>
					</div>
					<div class="formRow">
						<input class="buttonM bBlue" type="submit" value="Submit">
						<input class="buttonM bRed formSubmit" type="button" value="Cancel" onclick=self.history.back()><div class="clear"></div>
					</div>
				</div>
            </fieldset>
		</form>
<?php
	break;


	case "edit":
	$valid = $val->validasi($_GET['id'],'sql');
	$table = new PoTable('category');
	$currentCategory = $table->findBy(id_category, $valid);
	$currentCategory = $currentCategory->current();

	if ($currentCategory == '0'){
?>
		<div class="wrapper" id="errorWrapperadmin">
			<span class="errorNum">404</span>
			<div class="errorContent">
				<span class="errorDesc"><span class="icon-warning"></span>Sorry! Your Request Data Not Found. Please Try Again Submit Your Data</span>
			</div>
		</div>
<?php
	}else{
?>
		<form id="usualValidate" class="main" method="post" action="<?php echo $aksi; ?>" autocomplete="off">
            <fieldset>
				<div class="widget fluid">
				<div class="whead"><h6>Edit Category</h6><div class="clear"></div></div>
					<input type='hidden' name='mod' value='category'>
					<input type='hidden' name='act' value='update'>
					<input type='hidden' name='id' value='<?php echo $currentCategory->id_category; ?>'>
					<div class="formRow">
						<div class="grid3"><label>Title</label></div>
						<div class="grid9"><input class="required" type="text" id="title" name="title" value='<?php echo $currentCategory->title; ?>' required></div>
						<div class="clear"></div>
					</div>
					<div class="formRow">
						<?php if ($currentCategory->active=="N"){ ?>
							<div class="grid3"><label>Active</label></div>
							<div class="grid9">
								<div id="uniform-radio1" class="radio"><input style="opacity: 0;" type="radio" id="active1" name="active" value="Y"></div><label for="active1" class="mr20">Y</label>
								<div id="uniform-radio2" class="radio"><input style="opacity: 0;" type="radio" id="active2" name="active" value="N" checked="checked"></div><label for="active2" class="mr20">N</label>
							</div>
							<div class="clear"></div>
						<?php }else{ ?>
							<div class="grid3"><label>Active</label></div>
							<div class="grid9">
								<div id="uniform-radio1" class="radio"><input style="opacity: 0;" type="radio" id="active1" name="active" value="Y" checked="checked"></div><label for="active1" class="mr20">Y</label>
								<div id="uniform-radio2" class="radio"><input style="opacity: 0;" type="radio" id="active2" name="active" value="N"></div><label for="active2" class="mr20">N</label>
							</div>
							<div class="clear"></div>
						<?php } ?>
					</div>
					<div class="formRow">
						<input class="buttonM bBlue" type="submit" value="Submit">
						<input class="buttonM bRed formSubmit" type="button" value="Cancel" onclick=self.history.back()><div class="clear"></div>
					</div>
				</div>
            </fieldset>
		</form>
<?php
	}
    break;
}
?>
	</div>
<?php
}
?>