<?php
 session_start();
?>
 <!--Edit Product code Start -->
 
<?php
include("dbcon.php"); 
error_reporting(0);        //form and imge code
//include("admin/header.php");
if(isset($_POST['submit']))
{
    
$dist=$_POST['dist'];
$cat=$_POST['cat'];
$name=$_POST['name'];
$desc=$_POST['desc'];




//$sub=$_POST['status'];


$image_name=$_FILES['file1']['name'];
$image_size=$_FILES['file1']['size'];
$image_type=$_FILES['file1']['type'];
$image_temp=$_FILES['file1']['tmp_name'];
$store="images/".$image_name;                               /* location to store image 2 */
$upload=move_uploaded_file($image_tmp,$store);
    
    if($image_name=='')
    {
     $image_name=$_POST['hidden1'];
    }
      else
      {
      $image_name=$_FILES['file1']['name'];
    }

   $query=mysqli_query($con,"UPDATE tbl_product SET manudist_id='$dist', cat_id='$cat',product='',mobile='',website='',name='$name',description='$desc',image='$image_name',date=now() where pro_id='".$_GET['update']."' ");
   if($query==true)
   {
     echo"<script>alert('Your details has been updated');
     window.location.href='product_detail.php';</script>";
   }
   else
   {
     echo"<script>alert('Your details has not been updated');window.location.href='product_detail.php';</script>";
   }
   }
   ?>
 <!--Edit 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>SAGI Quality-One Step Ahead</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"/>
  <!-- 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"/>
  
  <script src="ckeditor/ckeditor.js"></script>
  
</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-body">
                
                
                <?php 
    
        $query=mysqli_query($con,"SELECT * FROM  tbl_product where pro_id='".$_GET['update']."' ");
        while($row=mysqli_fetch_array($query)){ ?> 
              
              
              <form id="signupForm" method="post" enctype="multipart/form-data">
        
               
        
               

                <div class="form-group row">
                    
                   <label for="input-11" class="col-sm-2 col-form-label">Distributor</label>
                 <div class="col-sm-4">
                    <?php 
                 
                  $nitin=mysqli_query($con,"SELECT * FROM tbl_manudistributor order by manudist_id");
                  ?>
             <select class="form-control"    name="dist">
                    <?php while($sql=mysqli_fetch_array($nitin)){?>
                    <option value="<?php echo $sql['manudist_id'];?>" <?php if($sql['manudist_id']==$row['manudist_id']) { echo "selected"; }?> ><?php echo $sql['manudistributor_name'];?></option>
                  <?php }?>
                    </select>
                  </div> 
                    
                    
                  <label for="input-11" class="col-sm-2 col-form-label">Category</label>
                 <div class="col-sm-4">
                    <?php 
                 
                  $nitin=mysqli_query($con,"SELECT * FROM tbl_category order by cat_id");
                  ?>
             <select class="form-control"    name="cat">
                    <?php while($sql=mysqli_fetch_array($nitin)){?>
                    <option value="<?php echo $sql['cat_id'];?>" <?php if($sql['cat_id']==$row['cat_id']) { echo "selected"; }?> ><?php echo $sql['category_name'];?></option>
                  <?php }?>
                    </select>
                  </div>
                  
                  <br><br>
                  
                  
                  
                 
                  
                  
                
                </div>
                
                
 <div class="form-group row">
                  <label for="input-14" class="col-sm-2 col-form-label">Name</label>
                  <div class="col-sm-4">
                    <input type="text"  name="name" class="form-control" id="input-14" onkeypress="return this.value.length < 10;" value="<?php echo $row['name'];?>" >
                  </div>

                </div>
                
                  <textarea class="ckeditor" name="desc"><?php echo $row['description'];?></textarea>
                
                
                
                <div class="form-group row">
                 
                   <label data-error="wrong" data-success="right" for="defaultForm-pass">Image </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>
                
              
                
               
                </div>
                
                <br><br><br><br>
                
                

                
               
                <div class="form-footer">
                   <center> <button type="text" class="btn btn-danger"><i class="fa fa-times"></i> CANCEL</button>
                    <button type="submit" name="submit" class="btn btn-success"><i class="fa fa-check-square-o"></i> UPDATE</button></center>
                </div>
              </form>
              
              <?php } ?>
            </div>
          </div>
        </div>
      </div><!--End Row-->
    
    
      <!--<div class="row">
        <div class="col-lg-12">
          <div class="card">
            <div class="card-header"><i class="fa fa-table"></i>Image Details</div>
            <div class="card-body">
              <div class="table-responsive">
              <table id="example" class="table table-bordered">
                <thead>
                    <tr>
                        <th>Sr No.</th>
                        <th>Name</th>
                        <th>Image</th>
                        <th>Date</th>
                        <th>Actions</th>
                      
                    </tr>
                </thead>
                <tbody>
        
        <?php 
    $a=1;
    $query=mysqli_query($con,"SELECT * FROM tbl_gallery order by id desc limit 10"); ?>
    <?php while($row=mysqli_fetch_array($query)){?>
      
                    <tr>
                        <td><?php echo $a;?></td>
                        <td><?php echo $row['name'];?></td>
            <td><?php echo $row['date'];?></td>
                        <td><img src="gym_image/<?php echo $row['image'];?>" style="height:90px;width:90px;"></td>
                        
                     
                       <td>
      
                   <a onclick="return confirm('Are you sure want to delete ?');" style="color:white" href="gallery?dashboard/state/id=<?php echo $row['id'];?>"> <button type="submit"  class="btn btn-danger"><i class="fa fa-times"></i>DElete</button></a>
          </td>
                    </tr>

    <?php $a++;}?>
    
    
                   
                </tbody>
               
            </table><br>
      
      <div class="form-footer">
                  <center>  <a href="gallery_list" style="color:white"><button type="submit"  class="btn btn-primary">View More</button></a></center>
                  
                </div>
      
            </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>

  <!--Form Validatin Script-->
    <script src="assets/plugins/jquery-validation/js/jquery.validate.min.js"></script>
  
<!--Sweet Alerts -->
  <script src="assets/plugins/alerts-boxes/js/sweetalert.min.js"></script>
  <script src="assets/plugins/alerts-boxes/js/sweet-alert-script.js"></script>  
  
  
  
  
  
  
  
  
    <script>

    $().ready(function() {

    $("#personal-info").validate();

   // validate signup form on keyup and submit
    $("#signupForm").validate({
        rules: {
            firstname: "required",
            lastname: "required",
            username: {
                required: true,
                minlength: 2
            },
            password: {
                required: true,
                minlength: 5
            },
            confirm_password: {
                required: true,
                minlength: 5,
                equalTo: "#password"
            },
            email: {
                required: true,
                email: true
            },
             contactnumber: {
                required: true,
                minlength: 10
            },
            topic: {
                required: "#newsletter:checked",
                minlength: 2
            },
            agree: "required"
        },
        messages: {
            firstname: "Please enter your firstname",
            lastname: "Please enter your lastname",
            username: {
                required: "Please enter a username",
                minlength: "Your username must consist of at least 2 characters"
            },
            password: {
                required: "Please provide a password",
                minlength: "Your password must be at least 5 characters long"
            },
            confirm_password: {
                required: "Please provide a password",
                minlength: "Your password must be at least 5 characters long",
                equalTo: "Please enter the same password as above"
            },
            email: "Please enter a valid email address",
            contactnumber: "Please enter your 10 digit number",
            agree: "Please accept our policy",
            topic: "Please select at least 2 topics"
        }
    });

});

     </script>
  
  <!-- SWeet Alert Js -->
  <script src="js/sweetalert.js"></script>
   <?php 
   if(isset($_SESSION['status']) && $_SESSION['status']!='' )
   {
    
   ?>
  <script>
 swal({
  title: "<?php echo $_SESSION['status'];?>",
  //text: "You clicked the button!",
  icon: "<?php echo $_SESSION['status_code'];?>",
  button: "Ok!",
});
  </script>
  <?php 
   unset($_SESSION['status']);
   }
   ?> 
  
</body>


</html>
