<title>Konten</title>
<div id="pagetitle">KONTEN</div>
<div id="batascontent" class="clearfix">
	<div id="tableres">
		<table width="100%" cellpadding="0" cellspacing="0" border="0" class="display" id="example">
			<thead>
				<tr align="left">
					<th>NO</th>
					<th></th>
					<th>KONTEN</th>
					<th>KONTEN KATEGORI</th>
					<th>IMG</th>
					<th>TAGS</th>
					<th>VIEWS</th>
					<th>HITS</th>
					<th></th>
					<th>ORD</th>
				</tr>
			</thead>
			<tbody id="post_list">
				<?php
					$nomor = 1;
					$id = mysqli_real_escape_string($koneksi, $_GET['id']);
					$db = mysqli_query($koneksi, "SELECT * FROM cmas_konten ORDER BY konten_order ASC");
					$rowCount = mysqli_num_rows($db);
					
					if($rowCount > 0){
						while($dt = mysqli_fetch_array($db)){
						
						if ($dt['konten_status'] == "Aktif") {
							$konten_status = "<img src='assets/images/icons/icon_yes.png' width='20' title='$dt[konten_status]'>";
						} else {
							$konten_status = "<img src='assets/images/icons/icon_no.png' width='20' title='$dt[konten_status]'>";
						}
						
						if ($dt['konten_imageid'] == 0) {
							$konten_image = "<img src='assets/images/noimage.jpg' width='50' alt='$dt[konten_judul]' title='$dt[konten_judul]'>";
						} else {
							$konten_image = "<img src='assets/images/konten/$dt[konten_image]' width='50' alt='$dt[konten_judul]' title='$dt[konten_judul]'>";
						}
				?>
					<tr data-post-id="<?php echo $dt["konten_id"]; ?>">
						<td align="center" width="1%">
							<?php echo $nomor; ?>
						</td>
						<td width="1%">
							<a href="?m=konten_edit&id=<?php echo $dt['konten_id']; ?>">
								<?php echo $konten_image; ?>
							</a>
						</td>
						<td>
							<a href="?m=konten_edit&id=<?php echo $dt['konten_id']; ?>">
								<?php echo $dt['konten_judul']; ?>
							</a>
						</td>
						<td>
							<?php echo $dt["kontenkat_judul"]; ?>
						</td>
						<td align="center" width="1%">
							<?php
								$tdb = mysqli_query($koneksi, "SELECT COUNT(kontenimg_id) AS JumlahIMG FROM cmas_kontenimg WHERE konten_id='$dt[konten_id]'");
								$tdt = mysqli_fetch_array($tdb);
								echo $tdt['JumlahIMG'];
								echo "IMG";
							?><br>
							<a href="?m=kontenimg_input&id=<?php echo $dt['konten_id']; ?>">
								<img src="assets/images/icons/icon_adds.png" width="20" title="Tambah Tags">
							</a>
						</td>
						<td align="center" width="1%">
							<?php
								$tdb = mysqli_query($koneksi, "SELECT COUNT(kontentag_id) AS JumlahTags FROM cmas_kontentag WHERE konten_id='$dt[konten_id]'");
								$tdt = mysqli_fetch_array($tdb);
								echo $tdt['JumlahTags'];
								echo "Tags";
							?><br>
							<a href="?m=kontentag_input&id=<?php echo $dt['konten_id']; ?>">
								<img src="assets/images/icons/icon_adds.png" width="20" title="Tambah Tags">
							</a>
						</td>
						<td align="center" width="1%">
							<?php
								$vdb = mysqli_query($koneksi, "SELECT COUNT(loghits_ip) AS JumlahIP FROM cmas_loghits WHERE contentid='$dt[konten_id]'");
								$vdt = mysqli_fetch_array($vdb);
								echo $vdt['JumlahIP'];
							?>
						</td>
						<td align="center" width="1%">
							<?php
								$hdb = mysqli_query($koneksi, "SELECT SUM(loghits_hits) AS JumlahHits FROM cmas_loghits WHERE contentid='$dt[konten_id]'");
								$hdt = mysqli_fetch_array($hdb);
								echo $hdt['JumlahHits'];
							?>
						</td>
						<?php if ($udt['admincat_id'] == "1") { ?>
							<td align="center" width="8%">
								<a href="?m=konten_updatestatus&id=<?php echo $dt['konten_id']; ?>">
									<?php echo $konten_status; ?>
								</a>
								<a href="?m=konten_edit&id=<?php echo $dt['konten_id']; ?>">
									<img src="assets/images/icons/icon_edit.png" width="20" title="Edit Data">
								</a>
								<a href="?m=konten_hapus&id=<?php echo $dt['konten_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=konten_updatestatus&id=<?php echo $dt['konten_id']; ?>">
									<?php echo $konten_status; ?>
								</a>
								<a href="?m=konten_edit&id=<?php echo $dt['konten_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['konten_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/orderArtikel.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>