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


  <!-- Content Wrapper. Contains page content -->
<!--For save data-->

<?php
 include_once ('includes/config.php');
   
// Check connection
    if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
    } 

if(isset($_POST['submit']))
{
 

$id=$_GET['id'];
$vendor =$_POST['vendor'];
$vehicle = $_POST['vehicle'];

$measurement =$_POST['measurement'];




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

  
     $sql="Update `measurements` SET `vehicle_id`='".$vehicle."',`vendor_id`='".$vendor."',`vmeasurement`='".$measurement."' WHERE ms_id
   ='$id'";
   // echo"<script type='text/javascript'>alert('Record Successfully Added!');</script>";
     //       echo "<script>(window.location.href='vendormeasurement.php');</script>";


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


$resnew = mysqli_query($con, $sql);

//echo "<script>(window.location.href='vendormeasurement.php?success');</script>";
$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>';
}
?>
 

  

  <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>Vendor Measurement</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="vendormeasurement.php">Dataview</a></li>
             <li class="breadcrumb-item active"><a href="dashboard.php">Dashboard</a></li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

 <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <!-- SELECT2 EXAMPLE -->
        <div class="card card-default">
          <div class="card-header">
            <h3 class="card-title">Edit Info</h3>
<?php
                    include('includes/config.php');
                    
        
       $id=$_GET['id'];
    $result = mysqli_query($con, " SELECT * FROM `measurements` 
 WHERE ms_id='$id'");
   while($row = mysqli_fetch_assoc($result)) {
                
                    
            ?>
            <div class="card-tools">
              <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-minus"></i></button>
              <button type="button" class="btn btn-tool" data-card-widget="remove"><i class="fas fa-times"></i></button>
            </div>
          </div>
          <!-- /.card-header -->
          <div class="card-body">
          	<form method="post"  enctype="multipart/form-data">
             <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="<?php echo $row['vendor_id']; ?>">Selecteded <?php echo $row['vendor_id']; ?></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="<?php echo $row['vehicle_id']; ?>">Selected <?php echo $row['vehicle_id']; ?></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})?" value="<?php echo $row['vmeasurement']; ?>">
                    </div></div>
          	        
                    
          	      
          	 
          	    </div>
       
          
          
          
          
          <?php } ?>
            
        
          </div>
          <!-- /.card-body -->
          <div class="card-footer">
           <button type="submit" name="submit" class="btn btn-danger">Submit</button>
          </div>
</form>
        <!-- /.card -->


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



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






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