<?php 
 session_start();
?>











<?php 
include('dbcon.php');

error_reporting(0);
   if($_GET['status']==0)
   {
    
  $sub=$_GET['product_id'];
   //$qry="UPDATE tbl_submenu SET sub_menu='$submenu' where submenu_id='$sub'";
  $result=mysqli_query($con,"UPDATE tbl_product SET  status='1' where pro_id='$sub'");
  if($result==true)
   {
     echo"<script>window.location.href='product_detail.php',</script>";
   }
   else
   {
     echo"<script>window.location.href='product_detail.php',</script>";
   }
   }
   ?>
 
 
 
 <?php 
include('dbcon.php');
   if($_GET['status']==1)
   {
    
  $sub=$_GET['product_id'];
   //$qry="UPDATE tbl_submenu SET sub_menu='$submenu' where submenu_id='$sub'";
  $result=mysqli_query($con,"UPDATE tbl_product SET  status='0' where pro_id='$sub'");
  if($result==true)
   {
     echo"<script>window.location.href='product_detail.php',</script>";
   }
   else
   {
     echo"<script>window.location.href='product_detail.php',</script>";
   }
   }
   ?>

  <!--Edit Product code Start -->
 
 <?php 
 
 include('dbcon.php');


   if(isset($_POST['change']))
   {
    $i=$_POST['sbmid'];

    $menu=$_POST['menu'];

    $submenu=$_POST['submenu'];

    $product=$_POST['product'];




$image_name1=$_FILES['file1']['name'];                  /* Update a image 2*/
$image_size=$_FILES['file1']['size'];
$image_type=$_FILES['file1']['type'];
$image_tmp=$_FILES['file1']['tmp_name'];
$store="images/".$image_name1;                               /* location to store image 2 */
$upload=move_uploaded_file($image_tmp,$store);
    
    if($image_name1=='')
    {
     $image_name1=$_POST['hidden1'];
    }
      else
      {
      $image_name1=$_FILES['file1']['name'];
    }
    
   
   $query="UPDATE tbl_product SET product_name='$product',menu_id='$menu',submenu_id='$submenu',image='$image_name1',date=now() where product_id='$i'";
  $result=mysqli_query($con,$query);
  if($result==true)
   {
     echo"<script>alert('Your details has been Updated'); window.location.href='product_detail.php';</script>";
   }
   else
   {
     echo"<script>alert('Your details has not Updated');window.location.href='product_detail.php';</script>";
   }
   }
   ?>
   
 <!--Edit Product code End -->

 
 
 <!--Delete Product code Start -->
 
<?php

error_reporting(0);
if($_GET['state_id'])
{
$j=$_GET['state_id'];
$query=mysqli_query($con,"DELETE FROM tbl_product WHERE  pro_id='$j'");
if($query)
{
   echo"<script>alert('Your details has been Deleted');
     window.location.href='product_detail.php';
    </script>";
}
else{
  echo"<script>alert('Detail has not deleted');</script>";
}
}
?>

<!--Delete Product code End -->


 
 







<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8"/>
  <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
  <meta name="description" content=""/>
  <meta name="author" content=""/>
  <title>Product Detail</title>
  <!--favicon-->
  <link rel="icon" href="assets/images/favicon.ico" type="image/x-icon">
  <!-- simplebar CSS-->
  <link href="assets/plugins/simplebar/css/simplebar.css" rel="stylesheet"/>
  <!-- Bootstrap core CSS-->
  <link href="assets/css/bootstrap.min.css" rel="stylesheet"/>
  <!--Data Tables -->
  <link href="assets/plugins/bootstrap-datatable/css/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css">
  <link href="assets/plugins/bootstrap-datatable/css/buttons.bootstrap4.min.css" rel="stylesheet" type="text/css">
  <!-- animate CSS-->
  <link href="assets/css/animate.css" rel="stylesheet" type="text/css"/>
  <!-- Icons CSS-->
  <link href="assets/css/icons.css" rel="stylesheet" type="text/css"/>
  <!-- Sidebar CSS-->
  <link href="assets/css/sidebar-menu.css" rel="stylesheet"/>
  <!-- Custom Style-->
  <link href="assets/css/app-style.css" rel="stylesheet"/>
  
</head>

<body>

<!-- Start wrapper-->
 <div id="wrapper">
 
   <!--Start sidebar-wrapper-->
   
   <?php include('sidebar.php'); ?>
   
   <!--End sidebar-wrapper-->

<!--Start topbar header-->

<?php include('header.php'); ?>
<!--End topbar header-->

<div class="clearfix"></div>
	
  <div class="content-wrapper">
    <div class="container-fluid">
    



      <div class="row">
        <div class="col-lg-12">
          <div class="card">
            <div class="card-header"><i class="fa fa-table"></i>Manufacturer Advertisement Detail</div>
            <div class="card-body">
              <div class="table-responsive">
              <table id="example" class="table table-bordered">
                <thead>
                    <tr>
                        <th>Sr No.</th>
                        <th>Action</th>
                       
                       <th>Manfacturer</th>
                           <th>Product</th>
                            <th>Name</th>
                             <th>Description</th>
                          
                             <th>Image</th>
                         
                        <th>Date</th>
                        <th>Status</th>
                         
                        
                    </tr>
                </thead>
                <tbody>
				
				<?php 
				$a=1;
				$query=mysqli_query($con,"SELECT * FROM tbl_product order by pro_id desc");?>
				<?php while($row=mysqli_fetch_array($query)){ 
		$status="Active";
	if($row['status']=='Deactive')
	{
		$status="Deactive";
	}
	
		?>
                    <tr>
                        
                        
                        
          
                        
                        
                        <td><?php echo $a;?></td>

                        <td>          
          
<a href="update-product.php?update=<?php echo $row['pro_id'];?>"><i class="fa fa-edit" data-toggle="modal" data-target="#m<?php echo $row['pro_id'];?>" style="font-size:23px;color:blue"></i></a>  / 
<a onclick="return confirm('Are you sure want to delete ?');" style="color:white" href="product_detail?state_id=<?php echo $row['pro_id'];?>"> <i class="fa fa-trash-o" style="font-size:23px;color:red"></i></a>         
          </td>
                       
            
           
                
            
            

                    
                       
                       
                       <td>
                <?php 
                                       
                    $qry=mysqli_query($con,"SELECT * FROM tbl_manudistributor where manudist_id='".$row['manudist_id']."' "); ?>
                     <?php while($rows=mysqli_fetch_array($qry)){
                     echo $rows['manudistributor_name'] ; } ?></td>    
                     
                         <!--submenu fech by id--> 
            
            <td>
                <?php 
                                       
                    $qry=mysqli_query($con,"SELECT * FROM  tbl_category where cat_id='".$row['cat_id']."' "); ?>
                     <?php while($rows=mysqli_fetch_array($qry)){
                     echo $rows['category_name'] ; } ?></td>
                     
                     <!--submenu fecth by id end-->
                     
                     <!--title condition apply-->
<?php if($row['name']!=''){ ?>
 <td class="center"><?php echo $row['name']; ?></td>
<?php } else { ?>   
  <td class="center"><?php echo "............"; ?></td>
<?php }?>

<!--title condition end--->
                     
                     
                   <td class="center"><?php echo $row['description']; ?></td>
                     
                       
                    
                          
              
                       
                        
                      <td class="center"><img src="images/<?php echo $row['image']; ?>" style="width:70px;height:70px;"> </td> 
                      
                    
                        
                        
                        
                        
                     

                  

	



                      
					  
 


            <td><?php echo $row['date'];?></td>


          
 <?php if($row['status']=='0'){?>      
         <td><button type="submit"  class="btn btn-danger"><a href="product_detail.php?product_id=<?php echo $row['pro_id'];?>&status=<?php echo $row['status']; ?>" style="color:white">Deactive</a></button></td>
        <?php } else {?>
    <td><button type="submit"  class="btn btn-success"><a href="product_detail.php?product_id=<?php echo $row['pro_id'];?>&status=<?php echo $row['status']; ?>" style="color:white">Active</a></button></td>
        <?php }?>
        
        
        
                       


 
                    </tr>
					
					
<!-- start Popup Modal -->

<div class="modal fade" id="m<?php echo $row['product_id'];?>"  tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">Edit Your Details</h4>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
	   <form method="post" action="#" enctype="multipart/form-data">
	  <input type="hidden" name="sbmid" value="<?php echo $row['product_id'];?>">
      <div class="modal-body mx-3">
        

<div class="md-form mb-5">
          <i class="zmdi zmdi-star-outline"></i>
      <label data-error="wrong" data-success="right" for="defaultForm-email">Update Menu Name</label>
             <?php 
                 
                  $nitin=mysqli_query($con,"SELECT * FROM tbl_menu order by menu_id");
                  ?>
             <select class="form-control"   name="menu">
                    <?php while($sql=mysqli_fetch_array($nitin)){?>
                    <option value="<?php echo $sql['menu_id'];?>" <?php if($sql['menu_id']==$row['menu_id']) { echo "selected"; }?> ><?php echo $sql['menu_name'];?></option>
                  <?php }?>
                    </select>
                </div>



                <div class="md-form mb-5">
          <i class="zmdi zmdi-star-outline"></i>
      <label data-error="wrong" data-success="right" for="defaultForm-email">Update Submenu Name</label>
             <?php 
                 
                  $nitin=mysqli_query($con,"SELECT * FROM tbl_submenu order by submenu_id");
                  ?>
             <select class="form-control"   name="submenu">
                    <?php while($sql=mysqli_fetch_array($nitin)){?>
                    <option value="<?php echo $sql['submenu_id'];?>" <?php if($sql['submenu_id']==$row['submenu_id']) { echo "selected"; }?> ><?php echo $sql['sub_menu'];?></option>
                  <?php }?>
                    </select>
                </div>



        <div class="md-form mb-5">
          <i class="zmdi zmdi-star-outline"></i>
		  <label data-error="wrong" data-success="right" for="defaultForm-email">Update Product Name</label>
              <input type="text" name="product" id="" class="form-control validate" value="<?php echo $row['product_name'];?>">
                </div>
                
                
                
                
                
                
                 <div class="col-md-12">
          <i class="fas fa-lock prefix grey-text"></i>
      <label data-error="wrong" data-success="right" for="defaultForm-pass">Image1 </label>
          <input type="file" name="file1" id="defaultForm-pass" class="form-control validate" >
      <input type="hidden" name="hidden1" class="form-control" value="<?php echo $row['image'];?>" >
           <center> <img src="images/<?php echo $row['image']; ?>" style="width:100px;height:100px;"></center>
    </div><br>
    
     
      </div>
	    <div class="modal-footer d-flex justify-content-center">
      <center>  <button type="submit" class="btn btn-primary" name="change">Save Changes</button></center>
      </div>
	  </form>
    </div>
  </div>
</div>

<!-- End Popup Modal -->

					<?php $a++;}?>
					
                    <!--tr>
                        <td>Garrett Winters</td>
                        <td>Accountant</td>
                        <td>Tokyo</td>
                        <td>63</td>
                        <td>2011/07/25</td>
                        <td>$170,750</td>
                    </tr>
                    <tr>
                        <td>Ashton Cox</td>
                        <td>Junior Technical Author</td>
                        <td>San Francisco</td>
                        <td>66</td>
                        <td>2009/01/12</td>
                        <td>$86,000</td>
                    </tr>-->
                  
                </tbody>
                <!--tfoot>
                    <tr>
                        <th>Name</th>
                        <th>Position</th>
                        <th>Office</th>
                        <th>Age</th>
                        <th>Start date</th>
                        <th>Salary</th>
                    </tr>
                </tfoot>-->
            </table>
            </div>
            </div>
          </div>
        </div>
      </div><!-- End Row-->

    </div>
    <!-- End container-fluid-->
    
    </div><!--End content-wrapper-->
   <!--Start Back To Top Button-->
    <a href="javaScript:void();" class="back-to-top"><i class="fa fa-angle-double-up"></i> </a>
    <!--End Back To Top Button-->
	
	<!--Start footer-->
	<?php include('footer.php');?>
	<!--End footer-->
   
  </div><!--End wrapper-->


  <!-- Bootstrap core JavaScript-->
  <script src="assets/js/jquery.min.js"></script>
  <script src="assets/js/popper.min.js"></script>
  <script src="assets/js/bootstrap.min.js"></script>
	
	<!-- simplebar js -->
	<script src="assets/plugins/simplebar/js/simplebar.js"></script>
  <!-- waves effect js -->
  <script src="assets/js/waves.js"></script>
	<!-- sidebar-menu js -->
	<script src="assets/js/sidebar-menu.js"></script>
  <!-- Custom scripts -->
  <script src="assets/js/app-script.js"></script>

  <!--Data Tables js-->
  <script src="assets/plugins/bootstrap-datatable/js/jquery.dataTables.min.js"></script>
  <script src="assets/plugins/bootstrap-datatable/js/dataTables.bootstrap4.min.js"></script>
  <script src="assets/plugins/bootstrap-datatable/js/dataTables.buttons.min.js"></script>
  <script src="assets/plugins/bootstrap-datatable/js/buttons.bootstrap4.min.js"></script>
  <script src="assets/plugins/bootstrap-datatable/js/jszip.min.js"></script>
  <script src="assets/plugins/bootstrap-datatable/js/pdfmake.min.js"></script>
  <script src="assets/plugins/bootstrap-datatable/js/vfs_fonts.js"></script>
  <script src="assets/plugins/bootstrap-datatable/js/buttons.html5.min.js"></script>
  <script src="assets/plugins/bootstrap-datatable/js/buttons.print.min.js"></script>
  <script src="assets/plugins/bootstrap-datatable/js/buttons.colVis.min.js"></script>

    <script>
     $(document).ready(function() {
      //Default data table
       $('#default-datatable').DataTable();


       var table = $('#example').DataTable( {
        lengthChange: false,
        buttons: [ ]
      } );
 
     table.buttons().container()
        .appendTo( '#example_wrapper .col-md-6:eq(0)' );
      
      } );

    </script>
	
</body>

</html>
