<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 = '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();});
				}
				});
				$( 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>

<script type="text/javascript">
$(document).ready( function() {
var oTable = $('.dTable').dataTable();
    // Dialog Link
    oTable.$('.tblview').click(function () {
		var idisi = $(this).attr('id');
        $('#viewdata'+idisi).dialog('open');
        return false;
    });
});
</script>

<script type="text/javascript">
$(document).ready(function () {
var oTable = $('.dTable').dataTable();
    oTable.$('.tblapprove').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
//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";
?>
	<div class="contentTop">
        <span class="pageTitle"><span class="icon-comments"></span>Comment Management</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>View, approve and delete comment management</a></li>
            </ul>
        </div>
    </div>
    <!-- Main content -->
    <div class="wrapper">
<?php
switch($_GET[act]){
  default:
?>
<form method="post" action="<?php echo $aksi; ?>">
	<input type="hidden" name="mod" value="comment">
	<input type="hidden" name="act" value="setting1">
	<input class="buttonS bBlue m10" type="submit" value="Without Approved" style="margin-top:10px;">
</form>
<form method="post" action="<?php echo $aksi; ?>">
	<input type="hidden" name="mod" value="comment">
	<input type="hidden" name="act" value="setting2">
	<input class="buttonS bLightBlue m10" type="submit" value="Must Be Approved" style="position:absolute; margin-top:-38px; margin-left:150px;">
</form>
	<div class="widget" style="margin-top:2px;">
		<div class="whead"><span class="titleIcon check"><input type="checkbox" id="titleCheck" name="titleCheck" /></span><h6>Comment Management</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="comment">
					<input type="hidden" name="act" value="multidelete">
					<input type="hidden" value="0" name="totaldata" id="totaldata">
<?php
				$tablecomment = new PoTable('comment');
				$comments = $tablecomment->findAll(id_comment, DESC);
				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>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><input type='checkbox' id='titleCheckdel'></td>
							<input type='hidden' class='deldata' name='item[$no][deldata]' value='$comment->id_comment' disabled>
							<td>$no</td>
							<td>$currentPost->title</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 class='tableActs' align='center'>
								<span id='$comment->id_comment' class='tblapprove'><a href='#approve$comment->id_comment' class='tablectrl_small bDefault tipS' title='Approve'><span class='iconb' data-icon='&#xe1f7;'></span></a></span>
								<span id='$comment->id_comment' class='tblview'><a href='#viewdata$comment->id_comment' class='tablectrl_small bDefault tipS' title='View Comment'><span class='iconb' data-icon='&#xe1db;'></span></a></span>
								<span id='$comment->id_comment' class='alertdel'><a href='#delete$comment->id_comment' class='tablectrl_small bDefault tipS' title='$langaction2'><span class='iconb' data-icon='&#xe136;'></span></a></span>
							</td>
						</tr>";
						?>
						<div id="viewdata<?php echo $comment->id_comment; ?>" class="viewdata" title="View Comment">
							<p><?php echo $comment->comment; ?></p>
						</div>
						<?php
						$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;
}
?>
	</div>
<?php
}
?>