<?php 

include('config/function.php');

if(!isset($_SESSION['user_name']) || empty($_SESSION['user_name']))
{
header('location:login.php');
exit();
}
 	if(isset($_GET['delete']) && $_GET['delete']!="")
{
	$id = $_GET['delete'];
	$query_select = "SELECT * FROM cat_prod WHERE id ='".$id."'";
	if($sql_select = $conn->query($query_select))
	{
		$result = $sql_select->fetch_array(MYSQLI_ASSOC);
		@unlink("uploads/video/".$result['video']);
		@unlink("uploads/fvicon/".$result['fvicon']);
		@unlink("uploads/up_image/".$result['up_image']);
		@unlink("uploads/up_pdf/".$result['up_pdf']);
	}
	$query_delete="DELETE FROM cat_prod WHERE id='".$id."'";
	if($sql_delete=$conn->query($query_delete))
	{
		$sess_msg="Deleted Successfully.";
							
	}
}
$sess_msg="";
?>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <title>Admin</title>
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
  <link rel="stylesheet" href="bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
  <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
  <link rel="stylesheet"
        href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
		    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.2/sweetalert.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.2/sweetalert.min.css" /> 
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
   <?php include('header.php') ?>
  <?php include('left-menu.php') ?>
  <div class="content-wrapper">
   <!-- Main content -->
    <section class="content">
      <div class="row">
        <div class="col-xs-12">


          <div class="box">
            <div class="main-title">
          
		    <?php if($sess_msg!="") { ?> <h3 class="h5-headn hegt-96" style="color:red;"><?php echo $sess_msg; ?></h3> <?php } else { ?>			
           <h3>All Product</h3>
		   <?php } ?>
		   
		   
		   <ul  class="right-links">
		    <li><a href="add-product.php">Add Serives <i class="fa fa-angle-right"></i><i class="fa fa-angle-right"></i><i class="fa fa-angle-right"></i></a></li>
		   <!--<li><a href="#">Proud <i class="fa fa-angle-right"></i><i class="fa fa-angle-right"></i><i class="fa fa-angle-right"></i></a></li>
		    <li><a href="#">Main <i class="fa fa-angle-right"></i><i class="fa fa-angle-right"></i><i class="fa fa-angle-right"></i></a></li>-->
		   </ul>
           </div>
		   <form class="" action="<?php $_SERVER['PHP_SELF'] ?>" method ="post">
		  
      
 
 
            <div class="box-body" style="overflow-x:auto;">
			<table id="example1" class="table table-bordered table-striped" >
                <thead>
                <tr>
              <tr>
            
                  <td colspan="6" style="text-align:left;">
               
                  </td>
                  <td colspan="5" style="text-align:left;">
                  <!--<input type="submit" name="updatedrteorder" value="Update Order" onClick="return confirm('Are you sure you want to update order?');" class="btn btn-warning">-->
                   <input type="submit" name="chk_btn" value="Active" onClick="return confirm('Are you sure you want to activate ?');" class="btn btn-success">
                  <input type="submit" name="unchk_btn" value="Deactivate" onClick="return confirm('Are you sure you want to deactivate ?');" class="btn btn-danger">
                  </td>
                </tr>
                <tr>
                <th>Sr. N.</th>    
                  <th>Products Name</th>
                  <th>Category</th>
                 
                <th>Images</th>
                  <th>Status</th>
                 <th>
                       <input type="checkbox" name="checkedAll" id="checkedAll" />
                    </th>
                     <th>Action</th>
                </tr>
                </thead>
                <tbody>
		 
			 <?php 
			 $i=1;
                 $category=mysqli_query($conn,"select cp.ct_pd_name,cp.status, cp.id, cp.cat_pd_image, cm.page_name from cat_prod cp INNER JOIN cms_menu cm ON cp.category_id = cm.id");
                 while($row=mysqli_fetch_array($category)){


			  ?>
			    
                <tr>
                <td><?php echo $i++; ?></td>    
                    <td><?php echo $row['ct_pd_name']; ?></td>
                     <td><?php echo $row['page_name']; ?></td>
                  
                    <td>
                        <img src="uploads/product/<?php echo str_replace(',','',$row['cat_pd_image']); ?>" style="width: 50px; height: 50px;">
                    	</td>
                   <td> <?php  if($row['status']=='1'){ echo "Enable";}else { echo "Disable";}   ?></td>
                    
                 <td>
                    <input type="checkbox" value="<?php echo $row['id']; ?>" name="check_status[]" class="checkSingle"  />
                    </td>
                  <td>
                      
                   <ul class="edit-button">
                          <li><a href="add-products.php?id=<?=$row['id']?>"><i class="fa fa-edit"></i></a></li>
                          <li><a href="view-product.php?delete=<?=$row['id']?>"><i class="fa fa-remove"></i></a></li>
                      </ul> 
                    </td>
                </tr>
               <?php }?>
			 
			 
		   </tbody>
              </table>
			  
			  
			  
			
            </div>	
          </div>
          <!-- /.box -->
		  </form>
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
<?php include 'footer.php';?>

</div>
<!-- ./wrapper -->

<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<script src="bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<script src="bower_components/fastclick/lib/fastclick.js"></script>
<script src="dist/js/adminlte.min.js"></script>

    <!-- AdminLTE App -->
    <script src="dist/js/app.min.js"></script>
    <!-- AdminLTE for demo purposes -->
    <script src="dist/js/demo.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.2/sweetalert-dev.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.2/sweetalert-dev.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.2/sweetalert.min.js"></script> 
<script>
  $(function () {
    $('#example1').DataTable()
    $('#example2').DataTable({
      'paging'      : true,
      'lengthChange': false,
      'searching'   : false,
      'ordering'    : true,
      'info'        : true,
      'autoWidth'   : false
    })
  })
</script>
<script>
    $(document).ready(function() {
    $("#checkedAll").change(function() {
        if (this.checked) {
            $(".checkSingle").each(function() {
                this.checked=true;
            });
        } else {
            $(".checkSingle").each(function() {
                this.checked=false;
            });
        }
    });

    $(".checkSingle").click(function () {
        if ($(this).is(":checked")) {
            var isAllChecked = 0;

            $(".checkSingle").each(function() {
                if (!this.checked)
                    isAllChecked = 1;
            });

            if (isAllChecked == 0) {
                $("#checkedAll").prop("checked", true);
            }     
        }
        else {
            $("#checkedAll").prop("checked", false);
        }
    });
});
    </script>
	
	<script>
  function remove(ids){ 
  
  swal({   title: "Are you sure?", 
    text: "Want remove this menu", 
    type: "warning",  
    showCancelButton: true,   
    confirmButtonColor: "#DD6B55",  
    cancelButtonText: "No, cancel it!",
    confirmButtonText: "Yes, remove it!", 
    showLoaderOnConfirm:true, 
    closeOnConfirm: false,   
    closeOnCancel: true }, 
    function(isConfirm){   
      if (isConfirm) {    
       $.ajax({
        url: "sandeepphp/actions.php",
        data: {'id': ids ,'remove_product':'action'} ,
        type: "POST",
        success: function (data) {
          if(data=='OK'){
            swal("Remove!", "Menu has been removed", "success"); 
            location.reload();
          }
          else{
            sweetAlert("Oops", data, "error");
          }
          },
          error: function () {
            sweetAlert("Oops...", data, "error");
          }
        });
      }  
    });       
  }        
</script>
	<script>
$("#checkAllbox").change(function () {
    $(".checkbox").prop('checked', $(this).prop("checked"));
});
</script>
</body>

</html>
