<?php 
require_once('includes/check-login.php');
require_once('includes/header.php'); 
require_once('includes/menu.php'); 
require_once('includes/config.php'); 
$tablename="rating";	
$sql = "SELECT * FROM ".$tablename." order by id desc";
$result = $con->query($sql);
?>
<!-- Datatable CSS -->
<link href='data_tables/datatables.min.css' rel='stylesheet' type='text/css' /> <!-- Content Wrapper. Contains page content -->
        <div class="content-wrapper">
            <!-- Content Header (Page header) -->
            <section class="content-header">                                
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>                    
                        <li class="active"><a href="#">Reviews</a></li>           
                    </ol>                
            </section>

            <!-- Main content -->
            <section class="content">                
                <!-- Default box -->
                <div class="box box-form">
                    <div class="box-header with-border">
                        <h3 class="box-title">Reviews</h3>
                <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip" title="Collapse">
                <i class="fa fa-minus"></i></button>
                <button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
                <i class="fa fa-times"></i></button>
                </div>
				<header class="box-typical-header"><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
			    <div class="tbl-cell btn-group btn-group-sm pull-right"><a href="javascript:void(0)" class="tabledit-delete-button btn btn-sm btn-danger deleterow" title="Delete"><span class="glyphicon glyphicon-trash"></span> Delete</a></div>     
				</header>	
                    </div>
                    <div class="box-body">    
                        <!-- Table -->
                        <table id='workapp' class='display dataTable table table-bordered table-hover'>
                            <thead>
                            <tr>
							    <th class="table-check">
						         <div class="checkbox checkbox-only">
						         <input type="checkbox" id="table-check" class="checkAll"/>
						        <label for="table-check"></label>
						        </div>
						        </th>
								<th>ID</th>     
								<th>User Name</th> 
								<th>Rating</th>
                                <th>Description</th>  
                                <th>Active</th>  
                                <th>Datetime</th>                              
                                <th>Action</th>                                 
                            </tr>
                            </thead> 
                              <tbody>
							<?php $i=1;
							if ($result->num_rows > 0) {
                            while($row = $result->fetch_assoc()) {
                            ( $row['status'] == 1 ) ? $active = 'Yes': $active = 'No';
                            $user_id=$row['user_id'];
                            $sql1 = "SELECT u.user_id, ud.name,ud.phone, u.active,u.created_at,u.updated_at FROM users u JOIN user_details ud ON u.user_id = ud.user_id JOIN rating ra ON ra.user_id = ud.user_id WHERE u.user_id='$user_id'";
                           $result1 = $con->query($sql1);
                           $crow=mysqli_fetch_array($result1);
                            ?>
						   <tr>
						   <td class="table-check">
						   <div class="checkbox">
						   <input type="checkbox" id="table-check-<?php echo $i;?>" name="id" value="<?php echo $row['user_id'];?>"/>
						   <label for="table-check-<?php echo $i;?>"></label>
						   </div></td>
						   <td><?php echo $crow['user_id'];?></td>
						   <td><?php echo $crow['name'];?></td>
						   <td><?php echo $row['rating'];?></td>
						   <td><?php echo $row['description'];?></td>
						   <td><?php echo $active;?></td>
						   <td><p>Created : <?php echo $row['created'];?></p><p>Modified : <?php echo $row['modified'];?></p></td>
						   <td><?php if($row['status']==1){?>
						<a href="javascript:void(0)" class="tabledit-edit-button btn btn-sm btn-default" title="DeActive" onclick="status_change('<?php echo $row['id'];?>','0','rating')"><i class="fa fa-lock" aria-hidden="true"></i></a>
						<?php }else{?>
						<a href="javascript:void(0)" class="tabledit-edit-button btn btn-sm btn-default" title="Active" onclick="status_change('<?php echo $row['id'];?>','1','rating')"><i class="fa fa-unlock" aria-hidden="true"></i></a>
						<?php }?></td>
						    </tr>								  
							 <?php $i++;}}?>
                           </tbody>							
                        </table>

                    </div>
                    
                    <!-- /.box-footer-->                    
                </div>
                <!-- /.box -->

            </section>
            <!-- /.content -->                                        
        </div>
        <!-- /.content-wrapper -->        
<script src="js/common.js"></script>  
<script src="js/datatables.js"></script>    
<script>
$(document).ready( function() {
$(".checkAll").change(function () {
    $("input:checkbox").prop('checked', $(this).prop("checked"));
});
});
$(document).ready( function() {		
		$(".deleterow").off('click').on('click',function(e) {
		e.preventDefault();
		var anyBoxesChecked = false;
		var deletearray = new Array();		
		$('input[name="id"]:checked').each(function(){			
			deletearray.push($(this).val());
              anyBoxesChecked = true;	
		});		
		 if(anyBoxesChecked == true) {
                Lobibox.confirm({
                    msg: "Are you sure you want to delete this row?",
                    callback: function ($this, type) {
                        if (type === 'yes') {
                            Lobibox.notify('success', {
								msg: 'You have Deleted Successfully.'			     
                            });           
	       var table="rating";		  
           $.ajax({
           type: "POST",
           url: "deleterecord.php",
           data:{id:deletearray,table:table},
           cache: false,
           success: function(data){
          setTimeout(function(){location.reload();},1000); 
            }   
           });               } else if (type === 'no') {
                            Lobibox.notify('info', {
                                msg: 'Your row not deleted.'
                            });
                        }
                    }
                });
				}
			else{
				alert("Please select at least one checkbox");
			}
            });
});
function status_change(id,status,tbl_name){
$.ajax({
		url 	: "ratingstatus.php",
		type 	: "POST",
		data 	: {id:id,status:status,table:tbl_name},
		success : function(data){  		
		setTimeout(function(){location.reload();},1000);
		}
});
}
</script>
<script src="<?php echo $base_url;?>js/lobibox.js"></script>  
<?php require_once('includes/footer.php'); ?>