<?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['submit']))
{
 
$sess= $_SESSION['sess_user'];


   
//insert.php
$name =$_POST['name'];
$measurement = $_POST['measurement'];







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

 

    
    $sql="INSERT INTO vehicles(`vname`)Values('$name')";
    
 
 
  


if ($con->multi_query($sql) === TRUE) 
{
    // echo "Successfully Added";


 echo "<div class='container'><div class='custom-alert'>Record Successfully Added!</div></div>";
        echo "<script>setTimeout(function() { window.location.href='vehicle.php'; }, 1000);</script>";
 

?>
  <!--<script>
        alert('Record has Been Added Successfully.');
        window.location.href='vehicle.php';
    </script>-->
<?php
}
else {
    echo "Error: " . $sql . "<br>" . $con->error;
  }

$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 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 vehicle -->
    
      	<form id="form1" class="form-hidden" method="post">
          			<h3>Add Info</h3>

          	    <div class="row">
          	        <div class="col-md-4">
          	            <div class="form-group">
          	                  <label>Name</label>
                 <input type="text" placeholder="Vehicle Name" required="required" class="form-control" name="name">
          	            </div>
          	            
          	        </div>
                    
                  
          	    
          	  
          	    </div>

               
                <div class="row">
                  <div class="col-md-6">
                      <div class="form-group">
                           
                      <div class="form-example-int mg-t-15">
                            <button name="submit" class="btn btn-danger notika-btn-success">Submit</button>
                        </div>
                     
                  </div>
                </div>
                </div>
           </form>
              

    <!-- end add vehicle -->
                <h3 class="card-title">Lists</h3>
              </div>
        
              <!-- /.card-header -->
              <div class="card-body">
               <table id="example1" class="table table-striped">
                  <thead class="bg bg-danger">
                  <tr>
                    <th>S No</th>
                    <th>Name</th>
                    
                    <th>Action</th>
                  </tr>
                  </thead>
                  <tbody>

  <?php
    include('includes/config.php');
               
      $no=0;
      $result = mysqli_query($con, "SELECT * FROM `vehicles` where v_status='0' ORDER BY vehicle_id ASC");
       while($row = mysqli_fetch_assoc($result)) {
       $no++; 
      
          
  ?>
                  <tr>
                      <?php $id = $row['vehicle_id']; ?>
                    <td><?php echo $no; ?></td>
                    <!--<td><center><img src="uploads/laptop/<?php// echo $row['image'];?>" height="100px" width="70px"/></center>
                          </td>-->
                    <td><?php echo $row['vname']; ?></td>
                     <td>
                        <a href="vehicleedit.php?id=<?php echo $row['vehicle_id']; ?>">
                  <i class="fas fa-edit"></i>
                          ||
                        <a  onclick="return confirm('Are you sure <?php echo $row['vname']; ?> ?')" href="vehicledelete.php?id=<?php echo $id; ?>"  ><i style="font-size:15px; color:red;"  class="fa fa-trash"></i></a>
                        
                    </td>
                    
                  </tr>

                    


    <?php
    }

  
  ?>
 
                  </tbody>
                </table>
                     
                
                
                
                
                
              </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'); ?>