<?php

$table_name = 'home_page_details';
$redirection_page = "index.php?action=$page_name";
$action_name = "action=$page_name";
$type = $_REQUEST['type'];
$edit_id = $_REQUEST['edit_id'];
$delete_id = $_REQUEST['delete_id'];
 

// For Submitting The Form

if(isset($_POST['submit'])){
  
  $field1    =  $_POST['field1'];
  $field2    =  $_POST['field2'];
  $field12    =  $_POST['field12'];

   
  $allow = array("jpg", "JPG", "jpeg", "JPEG", "gif", "GIF", "png", "PNG", "pdf", "PDF");
  //1st File
  if($_FILES['photo1']['name'] == "") {
    //echo "No Image"
  } else {

    $photo1=basename($_FILES['photo1']['name']);
    $extension = pathinfo($photo1, PATHINFO_EXTENSION);
    if(in_array($extension,$allow)){
      $target_path = "assets/images/Home-img/";
      $photo1 = md5(rand() * time()).'.'.$extension;
      $target_path = $target_path . $photo1;
      move_uploaded_file($_FILES['photo1']['tmp_name'], $target_path);
      $sql = ($photo1!='')?" home_img='$photo1' ". ',':'';
    }
  
  }
  
  $allow = array("jpg", "JPG", "jpeg", "JPEG", "gif", "GIF", "png", "PNG", "pdf", "PDF");
  //1st File
  if($_FILES['photo12']['name'] == "") {
    //echo "No Image"
  } else {

    $photo12=basename($_FILES['photo12']['name']);
    $extension = pathinfo($photo12, PATHINFO_EXTENSION);
    if(in_array($extension,$allow)){
      $target_path = "assets/images/Home-img/";
      $photo12 = md5(rand() * time()).'.'.$extension;
      $target_path = $target_path . $photo12;
      move_uploaded_file($_FILES['photo12']['tmp_name'], $target_path);
      $sql12 = ($photo12!='')?" home_img='$photo12' ". ',':'';
    }
  
  }
  //3RD
  $allow = array("jpg", "JPG", "jpeg", "JPEG", "gif", "GIF", "png", "PNG", "pdf", "PDF");
  //1st File
  if($_FILES['photo123']['name'] == "") {
    //echo "No Image"
  } else {

    $photo123=basename($_FILES['photo123']['name']);
    $extension = pathinfo($photo123, PATHINFO_EXTENSION);
    if(in_array($extension,$allow)){
      $target_path = "assets/images/Home-img/";
      $photo123 = md5(rand() * time()).'.'.$extension;
      $target_path = $target_path . $photo123;
      move_uploaded_file($_FILES['photo123']['tmp_name'], $target_path);
      $sql123 = ($photo123!='')?" home_img='$photo123' ". ',':'';
    }
  
  }


  $insert_bookings = "UPDATE `$table_name` SET
  $sql
  home_type   = 'home_slider'   
  where id='1'";   
  $sql_insert = $dbconn->prepare($insert_bookings);
  $sql_insert->execute();
  $message="Details successfully updated.";
  $status="success";
  header("Location: $redirection_page");

  $insert_bookings = "UPDATE `$table_name` SET
  $sql12
  home_type   = 'home_slider'   
  where id='2'";   
  $sql_insert = $dbconn->prepare($insert_bookings);
  $sql_insert->execute();
  $message="Details successfully updated.";
  $status="success";
  header("Location: $redirection_page");

   $insert_bookings = "UPDATE `$table_name` SET
  $sql123
  home_type   = 'home_slider'   
  where id='3'";   
  $sql_insert = $dbconn->prepare($insert_bookings);
  $sql_insert->execute();
  $message="Details successfully updated.";
  $status="success";
  header("Location: $redirection_page");
 
    
}

if (isset($_GET['pageno'])) {
            $pageno = $_GET['pageno'];
        } else {
            $pageno = 1;
        }
        $no_of_records_per_page = 20;
        $offset = ($pageno-1) * $no_of_records_per_page;


$select_enquiry="SELECT * FROM $table_name where status = 'Active' order by id desc";
 $sql=$dbconn->prepare($select_enquiry);
 $sql->execute();
 $total_rows = $sql->fetchColumn();
 $total_pages = ceil($total_rows / $no_of_records_per_page);

//         $select_enquiry = "SELECT * FROM $table_name where status = 'Active' order by id desc LIMIT $offset, $no_of_records_per_page";
// $sql=$dbconn->prepare($select_enquiry);
//  $sql->execute();
//  $wlvd=$sql->fetchAll(PDO::FETCH_OBJ);


 $select_bookings= "SELECT * FROM `$table_name` WHERE id = '1'";
 $sql1=$dbconn->prepare($select_bookings);
 $sql1->execute();
 $wlvd1=$sql1->fetchAll(PDO::FETCH_OBJ);
 foreach($wlvd1 as $rows1); 

//2nd tor babe
 $select_bookings12= "SELECT * FROM `$table_name` WHERE id = '2'";
 $sql12=$dbconn->prepare($select_bookings12);
 $sql12->execute();
 $wlvd12=$sql12->fetchAll(PDO::FETCH_OBJ);
 foreach($wlvd12 as $rows12);
 //3rd 
 $select_bookings123= "SELECT * FROM `$table_name` WHERE id = '3'";
 $sql123=$dbconn->prepare($select_bookings123);
 $sql123->execute();
 $wlvd123=$sql123->fetchAll(PDO::FETCH_OBJ);
 foreach($wlvd123 as $rows123);


?>
 
 
    <div class="container-fluid">
      
      <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"><?php  echo $page_name; ?></h4>
         <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="index.php?action=Welcome">Dashboard</a></li>
             
            <li class="breadcrumb-item active" aria-current="page"><a href="index.php?action=<?php  echo $page_name; ?>"><?php  echo $page_name; ?></a></li>
         </ol>
     </div>
     
     <div class="col-sm-3">
       <?php include ('plugins/alert.php') ;?>
       <!-- Button trigger modal -->
     </div>     
     </div>
    <!-- End Breadcrumb-->
   
        <div class="row">
        <div class="col-lg-4">
          <div class="card">
           
            <div class="card-body">
              <div class="table-responsive">
               
                <form id="formID" class="m-t-30" method="post" action="" enctype="multipart/form-data">
       
                  
                   <div class="row">   
                    <div class="col-md-12">
                      <div class="form-group">
                      <label for="inv_phone">Slider IMAGE NO 1</label>
                       
                      <input name="photo1" type="file" id="photo1" class="form-control">

                      <small id="emailHelp" class="form-text text-muted"></small>                      
                      </div>

                      </div>
                    </div>
                       <div class="row">   
                    <div class="col-md-12">
                      <div class="form-group">
                      <label for="inv_phone">Slider IMAGE NO 2</label>
                       
                      <input name="photo12" type="file" id="photo12" class="form-control">

                      <small id="emailHelp" class="form-text text-muted"></small> 
                      </div>
                      </div>
                    </div>
                     <div class="row">   
                    <div class="col-md-12">
                      <div class="form-group">
                      <label for="inv_phone">Slider IMAGE NO 3 </label> 
                      <input name="photo123" type="file" id="photo123" class="form-control">
                      <small id="emailHelp" class="form-text text-muted"></small> 
                      </div>
                      </div>
                    </div>
           
                  <button type="submit"  name="submit" value="Submit" class="btn btn-primary btn-lg btn-block waves-effect waves-light m-1">UPDATE</button>
                  
                  </form>
            </div>
            </div>
          </div>
        </div>

        <div class="col-lg-8">
          <div class="card">
            <div class="card-body">
              <div class="table-responsive">
               
                <table class="table table-hover" id="sample-table-1">
                    <thead class="thead-dark">
                      <tr>
                        <th class="center"> ID</th>
                        <th class="center">Slider IMAGE</th> 
                       
                      </tr>
                    </thead>
                    <tbody> 
        <?php

          //while($rows = mysql_fetch_array($aResult,MYSQL_ASSOC))
          //{ 
          if($sql->rowCount() > 0){
              foreach($wlvd1 as $rows1){
          $field1 = $rows1->id;
          $field3 = $rows1->home_img;     
          ?>                  
                      <tr>
                      <td class="center"><?php echo $field1;?></td>
                      <td class="center"><img style="height:150px; width:250px" src="assets/images/Home-img/<?php echo $field3;?>"></td>                     
                      
                     </tr>  

                      <?php 
                     }} 
                    ?>
                     </tbody> 
                  </table>                
              </div>


                <div class="table-responsive">
               
                <table class="table table-hover" id="sample-table-1">
                    <thead class="thead-dark">
                    <!--   <tr>
                        <th class="center"> ID</th>
                        <th class="center">Home Slider Image2</th> 
                       
                      </tr> -->
                    </thead>
                    <tbody> 
        <?php

          //while($rows = mysql_fetch_array($aResult,MYSQL_ASSOC))
          //{ 
          if($sql->rowCount() > 0){
              foreach($wlvd12 as $rows12){
          $field12 = $rows12->id;
          $field123 = $rows12->home_img;
           
          ?>                  
                      <tr>
                      <td class="center"><?php echo $field12;?></td>
                      <td class="center"><img style="height:150px; width:250px" src="assets/images/Home-img/<?php echo $field123;?>"></td>
                     
                     </tr>  

                      <?php 
                     }} 
                    ?>
                     </tbody> 
                  </table>
                
        </div>

          <div class="table-responsive">
               
                <table class="table table-hover" id="sample-table-1">
                    <thead class="thead-dark">
                     <!--  <tr>
                        <th class="center"> ID</th>
                        <th class="center">Home Slider Image3</th> 
                       
                      </tr> -->
                    </thead>
                    <tbody> 
        <?php

          //while($rows = mysql_fetch_array($aResult,MYSQL_ASSOC))
          //{ 
          if($sql->rowCount() > 0){
              foreach($wlvd123 as $rows123){
          $field12 = $rows123->id;

          $field123 = $rows123->home_img;
        


           
          ?>                  
                      <tr>
                      <td class="center"><?php echo $field12;?></td>
                      <td class="center"><img style="height:150px; width:250px" src="assets/images/Home-img/<?php echo $field123;?>"></td>
                      
                     
                      
                     </tr>  

                      <?php 
                     }} 
                    ?>
                     </tbody> 
                  </table>


                
        </div>



            </div>
            </div>
          </div>
    
      </div>
    <!-- End Row-->  
    </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-->