<title>Menu</title>
<div id="pagetitle">MENU</div>
<div id="batascontent" class="clearfix">
	<?php if ($udt['admincat_id'] != "1") {} else { ?>
		<div id="tomboltambah">
			<a href="?m=menu_input" class="addbutton">+ MENU</a>
		</div>
	<?php } ?>
	<div id="tableres">
		<table width="100%" cellpadding="0" cellspacing="0" border="0" class="display" id="example">
			<thead>
				<tr align="left">
					<th>NO</th>
					<th>MENU</th>
					<th>TITLE</th>
					<th>URL</th>
					<th>KATEGORI</th>
					<th></th>
					<th>ORD</th>
				</tr>
			</thead>
			<tbody id="post_list">
				<?php
					$nomor = 1;
					$db = mysqli_query($koneksi, "SELECT * FROM cmas_menu ORDER BY menucat_id ASC, menu_order ASC");
					$rowCount = mysqli_num_rows($db);
					
					if($rowCount > 0){
						while($dt  = mysqli_fetch_array($db)) {
						
						if ($dt['menu_status'] == "Non-Aktif") {
							$menu_status = "<img src='assets/images/icons/icon_no.png' width='20' title='$dt[menu_status]'>";
						} else {
							$menu_status = "<img src='assets/images/icons/icon_yes.png' width='20' title='$dt[menu_status]'>";
						}
				?>
					<tr data-post-id="<?php echo $dt["menu_id"]; ?>">
						<td align="center" width="1%">
							<?php echo $nomor; ?>
						</td>
						<td> 
							<a href="?m=menu_edit&id=<?php echo $dt['menu_id']; ?>">
								<?php echo $dt["menu_nama"]; ?>
							</a>
						</td>
						<td>
							<?php echo $dt["menu_title"]; ?>
						</td>
						<td>
							<?php echo $dt["menu_seo"]; ?>
						</td>
						<td>
							<?php echo $dt["menucat_nama"]; ?>
						</td>
						<?php if ($udt['admincat_id'] == "1") { ?>
							<td align="center" width="8%">
								<a href="?m=menu_updatestatus&id=<?php echo $dt['menu_id']; ?>">
									<?php echo $menu_status; ?>
								</a>
								<a href="?m=menu_edit&id=<?php echo $dt['menu_id']; ?>">
									<img src="assets/images/icons/icon_edit.png" width="20" title="Edit Data">
								</a>
								<a href="?m=menu_hapus&id=<?php echo $dt['menu_id']; ?>" onclick="return confirm('DATA AKAN DIHAPUS, ANDA YAKIN?');">
									<img src="assets/images/icons/icon_delete.png" width="20" title="Hapus Data">
								</a>
							</td>
						<?php } else { ?>
							<td align="center" width="5%">
								<a href="?m=menu_updatestatus&id=<?php echo $dt['menu_id']; ?>">
									<?php echo $menu_status; ?>
								</a>
								<a href="?m=menu_edit&id=<?php echo $dt['menu_id']; ?>">
									<img src="assets/images/icons/icon_edit.png" width="20" title="Edit Data">
								</a>
							</td>
						<?php } ?>
						<td align="center" width="1%">
							<?php echo $dt['menu_order']; ?>
						</td>
					</tr>
				<?php $nomor++; } } ?> 
			</tbody>
		</table>
		<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
		<script>
			$( "#post_list" ).sortable({
				placeholder : "ui-state-highlight",
				update  : function(event, ui)
				{
					var post_order_ids = new Array();
					$('#post_list tr').each(function(){
						post_order_ids.push($(this).data("post-id"));
					});
					$.ajax({
						url:"libs/orderMenu.php",
						method:"POST",
						data:{post_order_ids:post_order_ids},
						success:function(data)
						{
						 if(data){
							$(".alert-danger").hide();
							$(".alert-success ").show();
						 }else{
							$(".alert-success").hide();
							$(".alert-danger").show();
						 }
						}
					});
				}
			});
		</script>
	</div>
</div>