<?php if (!defined('RESTRICTED')) { include ('./../../templates/error/404.php'); } else { ?>

<?php
	
	error_reporting(0);

	if (isset($_GET['id'])) {
		$ID = $_GET['id'];
	} else {
		$ID = "";
	}

	$qry = "SELECT c.comment_id, c.content, c.date_time, c.comment_status, u.id, u.name, n.nid, n.news_title 
				FROM tbl_comments c, tbl_users u, tbl_news n 
				WHERE c.user_id = u.id AND c.nid = n.nid AND c.comment_id = '$ID'";
	$result = mysqli_query($connect, $qry);
	$data    = mysqli_fetch_assoc($result);

	if (isset($_GET['delete'])) {
		if (validateResourceAccess($inputToken)) {
			$sql_delete = "DELETE FROM tbl_comments WHERE comment_id = '$ID'";
			$delete = $connect->query($sql_delete);
			if ($delete) {
				$_SESSION['msg'] = "Comment deleted successfully...";
			    header( "Location:comment.php");
			    exit;
			}
		} else {
			systemUpdateFlag($invalidResponse);
		}
	}

	if (isset($_GET['approve'])) {
    	if (validateResourceAccess($inputToken)) {
			$commentId = $_GET['approve'];
			$data = array('comment_status' => '1');	
			$update = update('tbl_comments', $data, "WHERE comment_id = '$commentId'");
			if ($update > 0) {
				$_SESSION['msg'] = 'Comment approved...';
				header( "Location:comment.php?detail&id=$commentId");
				exit;
			}
		} else {
			systemUpdateFlag($invalidResponse);
		}		
	}	

?>

	<section class="content">

        <ol class="breadcrumb breadcrumb-offset">
            <li><a href="dashboard.php">Dashboard</a></li>
            <li><a href="comment.php">Manage Comment</a></li>
            <li class="active">Comment Details</a></li>
        </ol>

        <div class="container-fluid" id="fade-in">

            <div class="row clearfix">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                	<form method="post">
                	<div class="card corner-radius">
                		<div class="header">
                			<h2>COMMENT DETAIL</h2>
                			<div class="header-dropdown m-r--5" style="margin-right: 10px;">
                				<?php if ($data['comment_status'] == '0') { ?>
	                				<?php if ($comment_approval == 'yes') { ?>
	                				<a href="comment.php?approve&id=<?php echo $data['comment_id'];?>" onclick="return confirm('Approve this comment? if its approved, it cannot be undone.')">
	                					<i class="material-icons">check</i>
	                				</a>
	                				<?php } ?>
                				<?php } ?>

                				<a href="comment.php?delete&id=<?php echo $data['comment_id'];?>" onclick="return confirm('Are you sure want to delete this comment?')" >
                					<i class="material-icons">delete</i>
                				</a>
                			</div>
                		</div>
                        <div class="body">

                        	<div class="row clearfix">
                        	<div class="form-group form-float col-sm-12">

                        		<?php if (isset($_SESSION['msg'])) { ?>
									<div class='alert alert-info alert-dismissible corner-radius bottom-offset' role='alert'>
										<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span>&nbsp;&nbsp;</button>
										<?php echo $_SESSION['msg']; ?>
									</div>
									<?php unset($_SESSION['msg']); } ?>

                        		<h4><?php echo $data['name']; ?></h4>

                        		<?php if ($comment_approval == 'yes') { ?>
	                        		<?php if ($data['comment_status'] == '1') { ?>
	                        			<span class="label label-rounded bg-green">&nbsp;Approved&nbsp;</span>
	                        		<?php } else { ?>
	                        			<span class="label label-rounded bg-red">&nbsp;Pending&nbsp;</span>
	                        		<?php } ?>
                        		<?php } ?>

								<p><?php echo $data['date_time']; ?></p>
								<p><?php echo $data['content']; ?></p>
								
                	</form>

							</div>
                        	</div>
                        </div>
                    </div>

                </div>

            </div>
            
        </div>

    </section>

<?php } ?>