<?php  session_start(); error_reporting(0); 
//if session
if(isset($_SESSION['j_admin'])){ }else{ 
    die(
    "
    <div class='alert alert-danger'> Error 100. Try again.</div>
    "
    );
}
require_once("../j_conn/url.php");
require_once("../j_conn/dbc.php");
require_once("../j_incs/functions.php");
if(isset($_POST['search'])){ }else{ 
die(
"
<div class='alert alert-danger'> Error 101. Try again.</div>
"
);
}

$name_old = $name;
$phone_old = $phone;
$email_old = $email;
$username_old = $username;
//
$search = RMC($_POST["search"]);  
$i_url = RMC($_POST["url"]);  
if(!empty($search) 
 ){ //check if required field is not empty
}else{ die("<div class='alert alert-danger'> Enter Search.</div>");}  
//search now

if(strpos($i_url, 'comments-view') !== false){
	//$url = urlencode("".$dir."items-view/");
	$url = urlencode("$i_url");
	$sql4="SELECT * from j_courses_comments WHERE 
	j_deleted < 1 AND j_transact_id LIKE '%".$search."%'
	|| j_deleted < 1 AND j_course_id LIKE '%".$search."%'
	|| j_deleted < 1 AND j_desc LIKE '%".$search."%'
	|| j_deleted < 1 AND j_date LIKE '%".$search."%'
	order by j_id desc limit 50"; //check  
	$result4 = runSQL($sql4);
	$count = mysqli_num_rows($result4);
}

if($count<1){
    die("<div class='alert alert-danger'> No record found. Try another search.</div>
    <script> $('[name=search]').css({'border-color': 'brown', 'border-width':'1px', 'border-style':'solid'});</script>
    ");
}
echo ("<script> $('[name=search]').css({'border-color': '#efefef', 'border-width':'1px', 'border-style':'solid'});</script>");
?>

<?php 
$num = 1;
?>
<div class="table-responsive m-t-10 my-content">
    <table style="font-size:11px;" class="table table-hover table-bordered">
		<thead>
            <tr>
                <th>S/N</th>
                 <th>Reference ID</th>
                 <th>Course</th>
                 <th>Comment</th>
                 <th>Status</th>
                   <th>Date</th>
                  <th>Menu </th>
              </tr>
        </thead>
		<tbody>
			<?php
			while ($row = mysqli_fetch_array($result4)){
			$sql44="SELECT * from j_courses WHERE j_id='".$row['j_course_id']."'"; //check 
            $result44 = runSQL($sql44);
            $data44 = mysqli_fetch_array($result44);
            $course = $data44['j_title'];
            $course_ref = $data44['j_transact_id'];
            ?>

            <tr id="i<?php echo $row['j_id']; ?>">
                <td> <?php echo $num++; ?></td>
                <td> <?php echo $row['j_transact_id']; ?></td>
                <td> <?php echo $course; ?></td>
                <td> <?php echo $row['j_desc']; ?></td>
                <td> 
                    <?php 
                    if($row['j_status'] > 0){ echo "Enabled"; }else{ echo "Disabled";  }
                    ?>
                </td>
                <td> <?php echo FULL_DATE($row['j_date']); ?></td>

                <td>

                    <div class="btn-group" role="group">
                        <button id="btnGroupDrop1" type="button" class="dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                          Option
                        </button>
                        <div class="dropdown-menu" aria-labelledby="btnGroupDrop1">

                        <a class="dropdown-item" href="<?php echo $dir; ?>comments-view/enable.php?t_id=<?php echo base64_encode($row['j_id']);?>&b_url=<?php echo $url;?>">
                            <?php 
                            if($row['j_status'] > 0){ echo "Disable"; }else{ echo "Enable";  }
                            ?>
                            </a>

                         <div class="dropdown-divider"></div>

                          <a class="dropdown-item" href="<?php echo $dir; ?>comments-view/del.php?t_id=<?php echo base64_encode($row['j_id']);?>&b_url=<?php echo $url;?>">Delete</a>
                        </div>
                    </div>

                </td>




            </tr>
			<?php } ?>

		</tbody>
	</table>

</div>

<script>
    $(".hide-item").on('click', function(){
        var id = $(this);
        var id_value = id.html();
        if(id_value=="Hide"){
            swal('Item', "is being hidden from store...");
        }else{
            swal('Item', "is being displayed in store...");
        }

        var item_id = $(this).attr("id");
        $(this).attr('disabled','');
        $.post("<?php echo $dir; ?>items-view/hide.php",
        {
        item_id:item_id
        }, function(data){
            if(data){
                $("#cart-result").html(data);
                if(id_value=="Hide"){
                    id.html('Show');
                }else{
                    id.html('Hide');
                }
            }else{
                swal(nameProduct, "could not delete item from cart !", "error");
            }
        });
    });
    
    
    
    $(".del-item").on('click', function(){
        var id = $(this);
        swal('Item', "is being deleted from store...");
        var item_id = $(this).attr("id");
        $(this).attr('disabled','');
        $.post("<?php echo $dir; ?>items-view/del.php",
        {
        item_id:item_id
        }, function(data){
            if(data){
                $("#cart-result").html(data);
            }else{
                swal(nameProduct, "could not delete item from cart !", "error");
            }
        });
    });
        
        
        
    
    
</script>