<?php
session_start();
// header("location:add-ad.php");
include('conn.php');
if(isset($_POST['submit']))
{
  
  
  $name = $conn->real_escape_string($_POST['add_name']);
  $add_about = $conn->real_escape_string($_POST['add_about']);
  $mail = $conn->real_escape_string($_POST['desc']);
  $cate_id = $conn->real_escape_string($_POST['category']);
  $pcode = $conn->real_escape_string($_POST['pcode']);

   //$vendor=$_SESSION['code'];

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

  $allowed_types = array(
    'image/gif',
    'image/jpeg',
    'image/jpg',
    'image/webp'
);

// Process the first image
$image_name = $_FILES['add_image']['name'];
$image_type = $_FILES['add_image']['type'];
$image_temp = $_FILES['add_image']['tmp_name'];

if (in_array($image_type, $allowed_types)) {
    $store = "pic/" . $image_name;

    // Move the uploaded file to the destination directory
    if (move_uploaded_file($image_temp, $store)) {
        // Image 1 uploaded successfully
    }
}

// Process the second image
$image_name1 = $_FILES['add_image1']['name'];
$image_type1 = $_FILES['add_image1']['type'];
$image_temp1 = $_FILES['add_image1']['tmp_name'];

if (in_array($image_type1, $allowed_types)) {
    $store = "pic/" . $image_name1;

    // Move the uploaded file to the destination directory
    if (move_uploaded_file($image_temp1, $store)) {
        // Image 2 uploaded successfully
    }
}

// Process the third image
$image_name2 = $_FILES['add_image2']['name'];
$image_type2 = $_FILES['add_image2']['type'];
$image_temp2 = $_FILES['add_image2']['tmp_name'];

if (in_array($image_type2, $allowed_types)) {
    $store = "pic/" . $image_name2;

    // Move the uploaded file to the destination directory
    if (move_uploaded_file($image_temp2, $store)) {
        // Image 3 uploaded successfully
    }
}

// Process the fourth image
$image_name3 = $_FILES['add_image3']['name'];
$image_type3 = $_FILES['add_image3']['type'];
$image_temp3 = $_FILES['add_image3']['tmp_name'];

if (in_array($image_type3, $allowed_types)) {
    $store = "pic/" . $image_name3;

    // Move the uploaded file to the destination directory
    if (move_uploaded_file($image_temp3, $store)) {
        // Image 4 uploaded successfully
    }
}

$queryy="INSERT INTO `add_adver`( `product_name`, `product_price`,`product_img`,`add_img1`,`add_img2`,`email`,`procode`,`add_img3`,`cate_id`, status, Date) VALUES('$name','$add_about','$image_name','$image_name1','$image_name2','$mail','$pcode','$image_name3','$cate_id','1',now())";   
$run=mysqli_query($conn,$queryy);

}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="refresh" URL='index.php'/>
    <script>
        // Prevent the page from refreshing
        if (window.history.replaceState) {
            window.history.replaceState(null, null, window.location.href);
        }
    </script>
  <title>Adult Shop</title>

  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/adminlte.min.css">
  <script async src="https://www.googletagmanager.com/gtag/js?id=UA-90614514-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-90614514-2');
</script>
<meta name="google-site-verification" content="Htm2ZwE8DZTCNr7vy9OKPmcHlBy7_bkVi43Td4dpxvQ" />    <!--    Google Analytics Code Ends-->


 <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  
  <script src="js/countrystatecity.js?v2"></script>

</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
  <!-- Navbar -->
  <?php
 include "header.php"; 
  ?>
  <!-- /.navbar -->
  <?php
 include "sidebar.php"; 
  ?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Add Product</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#">Home</a></li>
              <li class="breadcrumb-item active">Add Product</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
         <div class="row">
          <!-- left column -->
          <div class="col-md-12">
            <!-- general form elements -->
            <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Product</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <form method="post" enctype="multipart/form-data">
                <div class="card-body">
                  <div class="form-group">
                    <label for="exampleInputEmail1">Product Name</label>
                    <input type="text" class="form-control" name="add_name" id="exampleInputEmail1" placeholder="" required>
                  </div>
                  <div class="form-group">
                    <label for="exampleInputPassword1">Product Price</label>
                    <input type="text" class="form-control" name ="add_about"id="exampleInputPassword1" placeholder="" required>
                  </div>
                    <div class="form-group">
                    <label for="exampleInputPassword1">Description</label>
                    <input type="text" class="form-control" name ="desc"placeholder="">
                  </div>

                 <div class="form-group">
  <label for="exampleInputPassword1">Product Code</label>
  <input type="text" class="form-control" name="pcode" value="<?php echo generateRandomCode(8); ?>" readonly>
</div>

<?php
// Function to generate a random alphanumeric string of a given length
function generateRandomCode($length) {
    $charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    $result = "";
    for ($i = 0; $i < $length; $i++) {
        $randomIndex = rand(0, strlen($charset) - 1);
        $result .= $charset[$randomIndex];
    }
    return $result;
}
?>

                  
                   <?php 
                 
                  $nitin=mysqli_query($conn,"SELECT * FROM  add_category");
                  ?> 
                  <div class="form-group ca-sh-user">
                  <label for="exampleInputPassword1">Select Category</label>

                              	<select class="form-control" name="category">
					    
					    
					    <option>Select</option>
                      <?php while($row=mysqli_fetch_array($nitin)){?>
                    <option value="<?php echo $row['category_name'];?>"><?php echo $row['category_name'];?></option>
                    <?php }?>
                     
                  
                                   </select>
                            </div>

                  <!-- <div class="form-group ca-sh-user">
                  <label for="exampleInputPassword1">Select Location</label>

                               <select  name="country"   class="countries form-control" id="country">
                                                <option value="" >Select Country</option>
                                    </select>
                               
                            </div>



                            <div class="form-group ca-sh-user">
                               <select name="state"  class=" states form-control"  id="region">
                                                <option value="">Select State</option></select>
                                
                            </div>


                            <div class="form-group ca-sh-user">
                              <select name="city"  class="cities form-control" id="city">
                                                <option value=""  >Select City</option></select>
                              
                            </div> -->
                  <div class="form-group">
                    <label for="exampleInputFile">Image 1</label>
                     <div class="input-group">
                      <div class="custom-file">
                        <input type="file" class="custom-file-input" id="exampleInputFile" name = "add_image">
                        <label class="custom-file-label" for="exampleInputFile">Choose file</label>
                      </div>
                      <div class="input-group-append">
                        <span class="input-group-text">Upload</span>
                      </div>
                     
                    </div>
                    <div class="form-group">
                    <label for="exampleInputFile">Image 2</label>
                     <div class="input-group">
                      <div class="custom-file">
                        <input type="file" class="custom-file-input" id="exampleInputFile" name = "add_image1">
                        <label class="custom-file-label" for="exampleInputFile">Choose file</label>
                      </div>
                      <div class="input-group-append">
                        <span class="input-group-text">Upload</span>
                      </div>
                     
                    </div>
                    <div class="form-group">
                    <label for="exampleInputFile">Image 3</label>
                     <div class="input-group">
                      <div class="custom-file">
                        <input type="file" class="custom-file-input" id="exampleInputFile" name = "add_image2">
                        <label class="custom-file-label" for="exampleInputFile">Choose file</label>
                      </div>
                      <div class="input-group-append">
                        <span class="input-group-text">Upload</span>
                      </div>
                     
                    </div>
                    <div class="form-group">
                    <label for="exampleInputFile">Image 4</label>
                     <div class="input-group">
                      <div class="custom-file">
                        <input type="file" class="custom-file-input" id="exampleInputFile" name = "add_image3">
                        <label class="custom-file-label" for="exampleInputFile">Choose file</label>
                      </div>
                      <div class="input-group-append">
                        <span class="input-group-text">Upload</span>
                      </div>
                     
                    </div>
                     <!-- <div class="form-group ca-sh-user">
                  <label for="exampleInputPassword1">Select Direction</label>

                               <select  name="dire" class="countries form-control" >
                                   <option value="" >Select Direction</option>
                                                <option value="Left" >Left</option>
                                                <option value="Right" >Right</option>

                                                
                                    </select>
                               
                            </div> -->
                            
                            <!-- <div class="form-group ca-sh-user">
                  <label for="exampleInputPassword1">Select Color</label>

                               <select  name="bg" class="countries form-control" >
                                   <option value="" >Select Color</option>
                                                <option value="orange" style="background-color:#ffa5006b;">Orange</option>
                                                <option value="blue" style="background-color:#add8e6a8;">Blue</option>
                                                <option value="green" style="background-color:#90ee904d;">Green</option>
                                                <option value="yellow" style="background-color:#e9e90d5c;">Yellow</option>
                                        
                                                
                                                 <option value="white" style="background-color:#ffff;">White</option>
                                                 <option value="pink" style="background-color:#ffb6c154;">Pink</option>
                                                 <option value="gray" style="background-color:#d3d3d34d;">Gray</option>
                                                 <option value="cyan" style="background-color:#e0ffff57;">cyan</option>
                                                
                                               


                                                
                                    </select>
                                    
                                    
                               
                            </div> -->
                  </div>
                  <!-- <div class="form-check">-->
                  <!--  <input type="checkbox" class="form-check-input" id="exampleCheck1">-->
                  <!--  <label class="form-check-label" for="exampleCheck1">Check me out</label>-->
                  <!--</div> -->
                </div>
                <!-- /.card-body -->

                <div class="card-footer">
                  <button type="submit" name ="submit" class="btn btn-primary">Submit</button>
                </div>
              </form>
            </div>
            <!-- /.card -->

            <!-- general form elements -->
            <!-- <div class="card card-primary">
              <div class="card-header">
                <h3 class="card-title">Different Styles</h3>
              </div> -->
              <!-- /.card-header -->
              <!-- <div class="card-body">
                <h4>Input</h4>
                <div class="form-group">
                  <label for="exampleInputBorder">Bottom Border only <code>.form-control-border</code></label>
                  <input type="text" class="form-control form-control-border" id="exampleInputBorder" placeholder=".form-control-border">
                </div>
                <div class="form-group">
                  <label for="exampleInputBorderWidth2">Bottom Border only 2px Border <code>.form-control-border.border-width-2</code></label>
                  <input type="text" class="form-control form-control-border border-width-2" id="exampleInputBorderWidth2" placeholder=".form-control-border.border-width-2">
                </div>
                <div class="form-group">
                  <label for="exampleInputRounded0">Flat <code>.rounded-0</code></label>
                  <input type="text" class="form-control rounded-0" id="exampleInputRounded0" placeholder=".rounded-0">
                </div>
                <h4>Custom Select</h4>
                <div class="form-group">
                  <label for="exampleSelectBorder">Bottom Border only <code>.form-control-border</code></label>
                  <select class="custom-select form-control-border" id="exampleSelectBorder">
                    <option>Value 1</option>
                    <option>Value 2</option>
                    <option>Value 3</option>
                  </select>
                </div>
                <div class="form-group">
                  <label for="exampleSelectBorderWidth2">Bottom Border only <code>.form-control-border.border-width-2</code></label>
                  <select class="custom-select form-control-border border-width-2" id="exampleSelectBorderWidth2">
                    <option>Value 1</option>
                    <option>Value 2</option>
                    <option>Value 3</option>
                  </select>
                </div>
                <div class="form-group">
                  <label for="exampleSelectRounded0">Flat <code>.rounded-0</code></label>
                  <select class="custom-select rounded-0" id="exampleSelectRounded0">
                    <option>Value 1</option>
                    <option>Value 2</option>
                    <option>Value 3</option>
                  </select>
                </div>
              </div> -->
              <!-- /.card-body -->
            <!-- </div> -->
            <!-- /.card -->

            
              
                    
</div>
            <!-- /.card -->
          <!--/.col (right) -->
        </div>
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  <?php
 include "footer.php"; 
  ?>

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->
  </aside>
  <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->

<!-- jQuery -->
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script><script  src="script.js"></script>

<script src="plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- bs-custom-file-input -->
<script src="plugins/bs-custom-file-input/bs-custom-file-input.min.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="dist/js/demo.js"></script>
<!-- Page specific script -->
<script>
$(function () {
  bsCustomFileInput.init();
});

</script>
</body>
</html>
