<?php include('common/header.php'); ?>
  <!-- Main Sidebar Container -->
<?php include('common/sidenav.php'); ?>


 
<?php
include_once ('includes/config.php');

// Check connection
if ($con->connect_error) {
  die("Connection failed: " . $con->connect_error);
}

if(isset($_POST['save'])) {
  $statusArray = $_POST['status'];

  foreach($statusArray as $m_id => $dstatus) {
    

  if ($dstatus == "2") {
      // Permanently delete the user record
      $query = "DELETE FROM `vehicles` WHERE vehicle_id='$m_id'";
    } else if($dstatus =="0") {
      // Update the user status
     $query = "UPDATE `vehicles` SET v_status='".$dstatus."' WHERE vehicle_id='$m_id'";
    }
     $resnew = mysqli_query($con, $query);
}
  echo "<script type='text/javascript'>alert('Status Successfully Updated!');</script>";
  echo "<script>window.location.href='vehicletrashlist.php';</script>";

  $con->close();
}
?>



  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
  

    <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Vehicle Trash List</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
            
            <!--   <li class="breadcrumb-item">  <button id="formButton" type="button"  class="btn btn-danger"><i class="fa fa-plus">Add New</i></button></li>
             
           <li class="breadcrumb-item active"><a href="#">Dashboard</a></li>-->
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">


            <div class="card">
              <div class="card-header">
                    <!-- add customer -->

    <!-- end add customer -->
                <h3 class="card-title">Lists</h3>
              </div>
        
              <!-- /.card-header -->
              <div class="card-body">
 <form method="post">
  <table id="example1" class="table table-striped">
    <thead class="bg bg-danger">
      <tr>
        <th>S No</th>
        <th>Name</th>
       
        <th>Status</th>
      </tr>
    </thead>
    <tbody>
      <?php
      include('includes/config.php');
      $no=0;
      $result = mysqli_query($con, "SELECT * FROM `vehicles` where v_status='1' ORDER BY vehicle_id ASC");
      while($row = mysqli_fetch_assoc($result)) {
        $no++;
        $id = $row['vehicle_id'];
        $status = $row['v_status'];
        $statusText = $status == 1 ? 'Active' : 'Deactive';
      ?>
      <tr>
        <td><?php echo $no; ?></td>
        <td><?php echo $row['vname']; ?></td>
       
        <td>
          <select class="form-control" name="status[<?php echo $id; ?>]">
            <option value="1">Select</option>
            <option value="0">Recover</option>
            <option value="2">Permanently Delete </option>
          </select>
        </td>
       
      </tr>
      <?php
      }
      ?>
    </tbody>
    <tfooter>
        <tr>
            <th></th>
            <th></th>
            
            <th><button type="submit" name="save" id="updateBtn" class="btn btn-danger" style="display: none;">Update Status</button>
</th>
           
            
              
        </tr>
    </tfooter>
  </table>

</form>






                
                
                
                
                
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
    <!-- /.content -->



<script>
  //show a confirmation and redirect to the delete profile script
  function deleteProfile() {
    if (confirm("Do you really want to delete your profile?")) {
        //location.href = '/deleteuser.php';
    }
}
</script>


  </div>
  <!-- /.content-wrapper -->


<?php include('common/footer.php'); ?>