<?php
session_start();
if(isset($_SESSION['User'])){
include("db.php");
$date = date("Y-m-d");

?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <title>Driver Logbook</title>
    <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="assets/fonts/font-awesome.min.css">
    <link rel="stylesheet" href="assets/css/Registration-Form-with-Photo.css">
    <link rel="stylesheet" href="assets/css/styles.css">
</head>
<div class="login-clean" style="height: 660px;background-image: url(&quot;assets/img/star-sky.jpg&quot;);">
  <div class="form-container" style="padding-top:60px">
  <div class="card" style=" max-width:900px; width:80%; margin:auto; border-radius:20px;">
    <form action="trips.php" method="POST">
  <div class="card-header">
    <h5 class="mb-0" style="text-align:left;">Start Trips</h5>
    <input type="hidden" name="date" value="<?php echo date("Y-m-d")?>"></h5>
  </div>
  <div class="card-body">
      <?php  $name = mysqli_query($conn, "SELECT username FROM users WHERE username='$_POST[username]'");
      $result = mysqli_query($conn, "SELECT car FROM cars WHERE car='$_POST[car]'");
      $car = mysqli_fetch_array($result);
        $row = mysqli_fetch_array($name);
        $get = mysqli_query($conn, "SELECT code FROM users WHERE username='$_POST[username]'");
        $getid = mysqli_fetch_array($get);
        ?>


    <h3 class="mb-0" style="text-align:left"> <?php echo $row['username'];?><span style="margin-left:250px"></span>You are using <?php echo $car['car']?></h3>

    </div>
    <?php $name2 = mysqli_query($conn, "SELECT * FROM clients ORDER BY name");?>
    <div class="form-group"><select name="client" class="form-control" >
      <option>--Select clients--</option>
      <?php while($row2 = mysqli_fetch_array($name2)){?>
        <option><?php echo $row2['name']?><option>

        <?php }?>
        </select>

    </div>
   
    <div class="form-group"><input class="form-control" type="number" maxlength="6" name="job" placeholder="Job Number"></div>
        <input type="hidden" name="employeecode" value="<?php echo $getid['code']?>">
      <div class="form-group"><textarea class="form-control" type="text" required name="description" placeholder="Description"></textarea></div>
      
      <div class="form-group"><input class="form-control" required type="text" name="destination" placeholder="Destination"></div>
      <h3 style="margin-top:5px;">Fueling</h3><br>
      <div class="input-group" style="margin-top:-20px; border:2px solid red; padding:5px">
      <input type="number" class="form-control"  name="station_mileage" placeholder="Mileage"/>
        <span class="input-group-addon">-</span>
        <input type="text" class="form-control" name="amount" placeholder="Amount"/>
        <span class="input-group-addon">-</span>
        <input type="text" class="form-control" name="litres" placeholder="Litres"/>
      </div>
      <p class="mb-0">First leg time</p><br>
      <div class="input-group" style="margin-top:-20px;">
      <input type="time" class="form-control" name="start_time" required placeholder="Start-Time"/>
        <span class="input-group-addon">-</span>
        <input type="time" class="form-control" name="end_time" required placeholder="End-Time"/>
      </div>
      <p class="mb-0">Second leg time</p><br>
      <div class="input-group" style="margin-top:-20px;">
        <?php

          $miles = mysqli_query($conn, "SELECT end_mileage FROM trips WHERE car='$_POST[car]' ORDER BY end_mileage DESC LIMIT 1");
          $get = mysqli_fetch_array($miles);
        ?>
      <input type="time" class="form-control" name="start_time2" required placeholder="Start-Time"/>
        <span class="input-group-addon">-</span>
        <input type="time" class="form-control" name="end_time2" required placeholder="End-Time"/>
      </div><br>
      <p class="mb-0">Start Mileage</p>
      <div class="input-group">
        <input type="number" class="form-control" required name="start_mileage" value="<?php

        echo $get['end_mileage']?>"/>
        <span class="input-group-addon">-</span>
        <input type="number" class="form-control" name="end_mileage" required placeholder="End-Mileage"/>
      </div>
      <div class="form-group"><input type="hidden" value="<?php echo $row['username'];?>" name="username">
        <input type="hidden" name="car" value="<?php echo $car['car']?>">
        <input type="hidden" value="<?php date('Y-m-d'); ?>" name="date">
    <input type="submit" name="submit" value="Enter" class="btn btn-primary btn-block"  style="background-color: rgb(7,166,128); margin-left:100px; margin-top:30px; width:40%">

  </form>


  </div>
</div>
</body>

</html>
<?php }else{
  header("Location: index.php");
}?>