<?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']))
{
    
$menu=$_POST['menu'];
$submenu=$_POST['submenu'];

$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'];
    }

    /*$image_name2=$_FILES['file2']['name'];
$image_size=$_FILES['file2']['size'];
$image_type=$_FILES['file2']['type'];
$image_temp=$_FILES['file2']['tmp_name'];
$store="images/".$image_name2;                               
$upload=move_uploaded_file($image_tmp,$store);
    
    if($image_name2=='')
    {
     $image_name2=$_POST['hidden2'];
    }
      else
      {
      $image_name2=$_FILES['file2']['name'];
    }

    $image_name3=$_FILES['file3']['name'];
$image_size=$_FILES['file3']['size'];
$image_type=$_FILES['file3']['type'];
$image_temp=$_FILES['file3']['tmp_name'];
$store="images/".$image_name3;                              
$upload=move_uploaded_file($image_tmp,$store);
    
    if($image_name3=='')
    {
     $image_name3=$_POST['hidden3'];
    }
      else
      {
      $image_name3=$_FILES['file3']['name'];
    }

    $image_name4=$_FILES['file4']['name'];
$image_size=$_FILES['file4']['size'];
$image_type=$_FILES['file4']['type'];
$image_temp=$_FILES['file4']['tmp_name'];
$store="images/".$image_name4;                               
$upload=move_uploaded_file($image_tmp,$store);
    
    if($image_name4=='')
    {
     $image_name4=$_POST['hidden4'];
    }
      else
      {
      $image_name4=$_FILES['file4']['name'];
    }*/

   $query=mysqli_query($con,"UPDATE tbl_product SET menu_id='$menu', submenu_id='$submenu',product_name='$name',description='$desc',image='$image_name',date=now() where product_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>Update Product</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/ckeditor.js"></script>
  
  
  <!---start code for dependent dropdown---->
      <script type="text/javascript">
    function myfunction(datavalue)
    {
        $.ajax({
        url: 'ajax.php',
        type: 'post',
        data: { datapost : datavalue},

        success : function(result){
        $('#dataget').html(result);
        }
        });
    }
    
    </script>     
<!---end code of dependent dropdown--->


  
</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">
      <!-- Breadcrumb-->
     <!--<div class="row pt-2 pb-2">
        <div class="col-sm-9">
        <h4 class="page-title">Gallery</h4>
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="javaScript:void();">Rukada</a></li>
            <li class="breadcrumb-item"><a href="javaScript:void();">Forms</a></li>
            <li class="breadcrumb-item active" aria-current="page">Form Validation</li>
         </ol>
     </div>
     <div class="col-sm-3">
       <div class="btn-group float-sm-right">
        <button type="button" class="btn btn-outline-primary waves-effect waves-light"><i class="fa fa-cog mr-1"></i> Setting</button>
        <button type="button" class="btn btn-outline-primary dropdown-toggle dropdown-toggle-split waves-effect waves-light" data-toggle="dropdown">
        <span class="caret"></span>
        </button>
        <div class="dropdown-menu">
          <a href="javaScript:void();" class="dropdown-item">Action</a>
          <a href="javaScript:void();" class="dropdown-item">Another action</a>
          <a href="javaScript:void();" class="dropdown-item">Something else here</a>
          <div class="dropdown-divider"></div>
          <a href="javaScript:void();" class="dropdown-item">Separated link</a>
        </div>
      </div>
     </div>
     </div>-->
    <!-- End Breadcrumb-->
  
  

      <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 product_id='".$_GET['update']."' ");
        while($row=mysqli_fetch_array($query)){ ?> 
              <form id="signupForm" method="post" enctype="multipart/form-data">
        
              
        
        
                <h4 class="form-header text-uppercase">
                  Add Product
                </h4>

                <div class="form-group row">

                  <label for="input-11" class="col-sm-2 col-form-label">menu</label>
                 
                  <div class="col-sm-4">
                    <?php 
                 
                  $nitin=mysqli_query($con,"SELECT * FROM tbl_menu order by menu_id");
                  ?>
                   <select class="form-control" onchange="myfunction(this.value)"   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>


                   <label for="input-11" class="col-sm-2 col-form-label">sub_menu</label>
                  
                  <div class="col-sm-4">
                     <?php 
                 
                  $nitin=mysqli_query($con,"SELECT * FROM tbl_submenu order by submenu_id");
                  ?>
                   <select class="form-control" id="dataget"  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>

                  
                

                   <br><br>
                   
                   <label for="input-14" class="col-sm-2 col-form-label">Product Name</label>
                  <div class="col-sm-4">
                    <input type="text"  name="name" class="form-control" id="input-14" value="<?php echo $row['product_name'];?>">
                  </div>
                  
                 
                  
                  </div>
                  <br>
                  
                   <div class="form-group row">
                  
                  <div class="col-sm-3">
                    image1
                   <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'];?>" >
            <img src="images/<?php echo $row['image']; ?>" style="width:100px;height:100px;">
                  </div>
               
              
                 <!-- <div class="col-sm-3">
                    image2
                   <input type="file" name="file2" id="defaultForm-pass" class="form-control validate" >
      <input type="hidden" name="hidden2" class="form-control" value="<?php echo $row['image2'];?>" >
           <img src="images/<?php //echo $row['image2']; ?>" style="width:100px;height:100px;">
                  </div>
                  
                 
                  <div class="col-sm-3">
                    image3
                    <input type="file" name="file3" id="defaultForm-pass" class="form-control validate" >
      <input type="hidden" name="hidden3" class="form-control" value="<?php echo $row['image3'];?>" >
          <img src="images/<?php //echo $row['image3']; ?>" style="width:100px;height:100px;">
                  </div>
                  
                   
                  <div class="col-sm-3">
                    image4
                    <input type="file" name="file4" id="defaultForm-pass" class="form-control validate" >
      <input type="hidden" name="hidden4" class="form-control" value="<?php echo $row['image4'];?>" >
           <img src="images/<?php //echo $row['image4']; ?>" style="width:100px;height:100px;">
                  </div>-->
               
               
                </div>
                
                
                <br><br>

                <label for="input-14" class="col-sm-2 col-form-label">Description</label>
                  <!--<div class="col-sm-12">
                    <input type="text"  name="desc" class="form-control" id="input-14" value="<?php echo $row['description'];?>">
                  </div>-->
                  
                
                <textarea class="ckeditor" name="desc"><?php echo $row['description'];?></textarea>
                 
                
                 

                
        
                <div class="form-footer">
                   <center> <button type="text" class="btn btn-danger"><i class="fa fa-times"></i> CANCEL</button>
                    <button type="text" 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>
    <!-- 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>
