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

<?php
//Author  	= 'Jenuar Dwi Putra Dalapang';
//Contact 	= 'mailto:djenuar@gmail.com';

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

$aksi="po-component/po-comment/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>

<script type="text/javascript">
$(document).ready(function () {
var oTable = $('#tableboot').dataTable();
    oTable.$('.view').click(function(){
        var idisi = $(this).attr('id');
		$('#message'+idisi).modal('show');
    });
});
</script>

<script type="text/javascript">
$(document).ready(function () {
var oTable = $('#tableboot').dataTable();
    oTable.$('.alertapprove').click(function(){
        var ida = $(this).attr('id');
		var adata = $('#activespan'+ida).html();
		if (adata == "Y"){
			var active = "N";
		}else{
			var active = "Y";
		}
		var mod = 'comment';
		var act =  'approve';
		var dataString = 'id='+ ida + '&mod='+ mod + '&act='+ act + '&active='+ active;
		$.ajax({
			type: "POST",
			url: "po-component/po-comment/proses.php",
			data: dataString,
			cache: false,
			success: function(html){
				$('#activespan'+ida).html(html);
			}
		});
		return false;
    });
});
</script>
<?php
	echo "<div class='page-header'>
		<div class='icon'>
			<span class='ico-comments-alt'></span>
		</div>
		<h1>Comment Management<small><span class='text-info'>View, approve and delete comment management</span></small></h1>
	</div>
	<div class='row-fluid'>
		<div class='span12'>
			<div class='block'>";
				$tablecomment = new PoTable('comment');
				$comments = $tablecomment->findAll(id_comment, DESC);
				echo "<div class='data-fluid'>
					<table cellspacing='0' border='0' class='table table-hover' id='tableboot'>
						<thead><tr>
							<th>No</th>
							<th>Post</th>
							<th>Sender Name</th>
							<th>Email</th>
							<th>Url</th>
							<th>Date, Time</th>
							<th>Approve</th>
							<th>Action</th>
						</tr></thead><tbody>";
						$no=1;
						foreach($comments as $comment){
						$valid = $comment->id_post;
						$tablepost = new PoTable('post');
						$currentPost = $tablepost->findBy(id_post, $valid);
						$currentPost = $currentPost->current();
						$urlcar = addhttp($comment->url);
						echo "<tr class='gradeA' id='del$comment->id_comment'>
							<td>$no</td>
							<td>$currentPost->title_id</td>
							<td>$comment->name</td>
							<td>$comment->email</td>
							<td><a href='$urlcar' target='_blank'>Website</a></td>
							<td>$comment->date, $comment->time</td>
							<td><span id='activespan$comment->id_comment'>$comment->active</span></td>
							<td>
								<a href='#approve$comment->id_comment' class='alertapprove' id='$comment->id_comment'><span class='label label-warning'><i class='icon-ok icon-white'></i>Approve</span></a>
								<a href='#message$comment->id_comment' class='view' id='$comment->id_comment'><span class='label label-info'><i class='icon-envelope icon-white'></i> View Comment</span></a>
								<a href='#delete$comment->id_comment' class='alertdel' id='$comment->id_comment'><span class='label label-important'><i class='icon-remove icon-white'></i>Delete</span></a>
							</td>
						</tr>
						<div id='message$comment->id_comment' class='modal hide fade' tabindex='-1' role='dialog' aria-labelledby='myModalLabel2' aria-hidden='true'>
							<div class='modal-header'>
								<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
								<h3 id='myModalLabel2'>Comment Content</h3>
							</div>
							<div class='modal-body'>
								<p>$comment->comment</p>
							</div>
							<div class='modal-footer'>
								<button class='btn' data-dismiss='modal' aria-hidden='true'>Close</button>
							</div>
						</div>";
						$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='myModalLabel3' aria-hidden='true' style='width:570px;'>
		<div class='modal-header'>
			<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>×</button>
			<h3 id='myModalLabel3'>Confirmation Deletion</h3>
		</div>
		<div class='modal-body'>
			<input type='hidden' id='delid' name='delid'>
			<span class='ico-warning'></span> Are you sure want to delete this data?
		</div>
		<div class='modal-footer'>
			<button id='btnalertdel' class='btn btn-danger'>Yes</button>
			<button class='btn' data-dismiss='modal' aria-hidden='true'>No</button>
		</div>
	</div>";
    break;
}
}
?>