<?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
$vendor =$_POST['vendor'];
$vehicle = $_POST['vehicle'];

$measurement =$_POST['measurement'];








 // Check connection
    if ($con->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    } 
  else
  
  
    $sql = "SELECT * FROM `measurements` WHERE vehicle_id ='$vehicle' AND vendor_id='$vendor'";
    $results = $con->query($sql);
   if ($results->num_rows > 0) 

  {
      
//   echo"<script type='text/javascript'>alert('Measurement Already Exist.');</script>";
  //    echo "<script>(window.location.href='vendor.php'?Failed');</script>";
  
   echo "<div class='container'><div class='custom-alert'>Measurement Already Exist.</div></div>";
        echo "<script>setTimeout(function() { window.location.href='vendormeasurement.php'; }, 2000);</script>";
  }

   

    else{
    $sql="INSERT INTO measurements(`vehicle_id`,`vendor_id`,`vmeasurement`)Values('$vehicle','$vendor','$measurement')";
    
     //echo"<script type='text/javascript'>alert('Record Successfully Added!');</script>";
       // echo "<script>(window.location.href='vendormeasurement.php');</script>";
       
        echo "<div class='container'><div class='custom-alert'>Record Successfully Added!</div></div>";
        echo "<script>setTimeout(function() { window.location.href='vendormeasurement.php'; }, 1000);</script>";
    
    }
 
 
  $resnew = mysqli_query($con, $sql);
  




$con->close();
}
 ?>


 <?php
//vendor
include('includes/config.php');
$v = '';

$query = "SELECT * FROM `vendors` where vs_status='0' ORDER BY company_name ASC";
$result = mysqli_query($con, $query);
while($row = mysqli_fetch_array($result))
{
 $v .= '<option value="'.$row["company_name"].'">'.$row["company_name"].' </option>';
}
?>

 <?php
//vehicle
include('includes/config.php');
$c = '';

$query = "SELECT * FROM `vehicles` where v_status='0'  ORDER BY vname ASC";
$result = mysqli_query($con, $query);
while($row = mysqli_fetch_array($result))
{
 $c .= '<option value="'.$row["vname"].'">'.$row["vname"].' </option>';
}
?>
  <!-- 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>Vendor Measurement</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 driver -->
    
      	<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>Vendor</label>
                               <select  required="required" class="form-control selectpicker actionv"  data-live-search="true" id="vendor" name="vendor">
                  <option value="">Select Vendor</option>
                  <?php echo $v; ?>
                  </select>
                      </div>       
                        
                    </div>
          	      
          	         <div class="col-md-4">
                         <div class="form-group">
                        <label>Vehicle</label>
                            <select required="required"  class="form-control action" id="vehicle" name="vehicle">
                                    <option value="">Select Vehicle</option>
                                    <?php echo  $c ; ?>
                            </select>
                    </div></div>
                     <div class="col-md-4">
                         <div class="form-group">
                        <label>Measurement</label>
                        <input type="number" class="form-control" required name="measurement" placeholder="Measurement" step="0.01" pattern="\d+(\.\d{1,2})?">
                    </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 driver -->
                <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>Company</th>
                    <th>Vehicle</th>
                    <th>Measurement</th>
                    <th>Action</th>
                  </tr>
                  </thead>
                  <tbody>

  <?php
    include('includes/config.php');
               
      $no=0;
      $result = mysqli_query($con, "SELECT * FROM `measurements` where md_status='0'
 ORDER BY ms_id ASC");
       while($row = mysqli_fetch_assoc($result)) {
       $no++; 
      
          
  ?>
                  <tr>
                      <?php $id = $row['ms_id']; ?>
                    <td><?php echo $no; ?></td>
                  
                    <td><?php echo $row['vendor_id']; ?></td>
                    <td><?php echo $row['vehicle_id']; ?></td>
                    <td><?php echo $row['vmeasurement']; ?></td>
                   
                   <!-- <td><?php// echo $row['vendor_measurement']; ?></td>-->
                   
                   
                    <td>
                        <a href="vendormsedit.php?id=<?php echo $row['ms_id']; ?>">
                  <i class="fas fa-edit"></i>
                          ||
                        <a  onclick="return confirm('Are you sure <?php echo $row['company_name']; ?> <?php echo $row['vmeasurement']; ?> ?')" href="vendormsdelete.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'); ?>