<?php

session_start();

?>

<?php  
include("dbcon.php");         //form and imge code
//include("admin/header.php");
if(isset($_POST['submit']))
{


$menu=$_POST['menu'];
$submenu=$_POST['submenu'];
$product_code="PR".rand(100000,999999);
$name=$_POST['name'];




$desc=$_POST['desc'];




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


$image_name=$_FILES['image']['name'];
$image_size=$_FILES['image']['size'];
$image_type=$_FILES['image']['type'];
$image_temp=$_FILES['image']['tmp_name'];
$store="images/".$image_name;
$upload=move_uploaded_file($image_temp, $store);




/*$image_name2=$_FILES['image2']['name'];
$image_size=$_FILES['image2']['size'];
$image_type=$_FILES['image2']['type'];
$image_temp=$_FILES['image2']['tmp_name'];
$store="images/".$image_name2;
$upload=move_uploaded_file($image_temp, $store);




$image_name3=$_FILES['image3']['name'];
$image_size=$_FILES['image3']['size'];
$image_type=$_FILES['image3']['type'];
$image_temp=$_FILES['image3']['tmp_name'];
$store="images/".$image_name3;
$upload=move_uploaded_file($image_temp, $store);




$image_name4=$_FILES['image4']['name'];
$image_size=$_FILES['image4']['size'];
$image_type=$_FILES['image4']['type'];
$image_temp=$_FILES['image4']['tmp_name'];
$store="images/".$image_name4;
$upload=move_uploaded_file($image_temp, $store);*/

$qry = mysqli_query($con,"INSERT INTO tbl_product(menu_id,submenu_id,product_code,product_name,description,status,image,image2,image3,image4,date) VALUES ('$menu','$submenu','$product_code','$name','$desc','1','$image_name','','','',now())");  
if($qry==true)
{
$_SESSION['status']="product has been Added Seccessfully..";
        $_SESSION['status_code']="success";
         ?>
     <script>
     setTimeout(function () {
       window.location.href = "product.php"; //will redirect to your stud_registration page after 3000 ms
    }, 3000);
  </script>
  <?php 
}
else
{
  $_SESSION['status']="project has not been Added ..";
        $_SESSION['status_code']="error";
         ?>
     <script>
     setTimeout(function () {
       window.location.href = "product.php"; //will redirect to your stud_registration page after 3000 ms
    }, 3000);
  </script>
  <?php 
}
}
?>
 


<!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>Add 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">
              <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">Category</label>
                  <?php 
                 
                  $nitin=mysqli_query($con,"SELECT * FROM tbl_menu");
                  ?>
                  <div class="col-sm-4">
                   <select class="form-control"  onchange="myfunction(this.value)" name="menu">
                    <option>Select the Menu Name</option>
                    <?php while($row=mysqli_fetch_array($nitin)){?>
                    <option value="<?php echo $row['menu_id'];?>"><?php echo $row['menu_name'];?></option>
                  <?php }?>
                    </select>
                  </div>


                   <label for="input-11" class="col-sm-2 col-form-label">Sub Category</label>
                  <?php 
                
                  $nitin=mysqli_query($con,"SELECT * FROM tbl_submenu");
                  ?>
                  <div class="col-sm-4">
                   <select class="form-control" id="dataget" name="submenu">
                   <option>Select Submneu Name</option>
                    <?php while($row=mysqli_fetch_array($nitin)){?>
                    
                  <?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" placeholder="nter product  name...">
                  </div>
                  
                 
                  
                  </div>
                  <br>
                  
                 <div class="form-group row">
                  
                  <div class="col-sm-12">
                    Upload Product<input type="file" class="form-control" id="input-7" name="image">
                  </div>
               
              
                 <!-- <div class="col-sm-3">
                    image2<input type="file" class="form-control" id="input-7" name="image2">
                  </div>
                  
                 
                  <div class="col-sm-3">
                    image3<input type="file" class="form-control" id="input-7" name="image3">
                  </div>
                  
                   
                  <div class="col-sm-3">
                    image4<input type="file" class="form-control" id="input-7" name="image4">
                  </div>-->
               
               
                </div>
                
                
                <br><br>
                
                
                 
                
                 

                 <textarea class="ckeditor" name="desc"></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>ADD</button></center>
                </div>
              </form>
            </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>
