<?php
session_start();
if($_SESSION['User']){
include ("db.php");

if(isset($_POST['update-trip'])){
   
    $client = $_POST['client'];
    $job = $_POST['job'];
    $expense = $_POST['expense_account'];
    $description = $_POST['description'];
    $destination = $_POST['destination'];
    $date = $_POST['date'];
    $starttime = $_POST['start_time'];
    $endtime = $_POST['end_time'];
    $starttime2 = $_POST['start_time2'];
    $endtime2 = $_POST['end_time2'];
    $startmileage = $_POST['start_mileage'];
    $endmileage = $_POST['end_mileage'];
    $stationmileage = $_POST['station_mileage'];
    $amount = $_POST['amount'];
    $litres = $_POST['litres'];
    
    $updatetrip = mysqli_query($conn, "UPDATE trips SET client='$client', 
    job='$job',expense_account='$expense',description='$description',destination='$destination',date='$date',start_time='$starttime',end_time = '$endtime',start_time2 = '$starttime2',end_time='$endtime2',start_mileage='$startmileage',
    end_mileage='$endmileage',station_mileage='$stationmileage',amount='$amount',litres = '$litres' WHERE id = '$_POST[id]' ");
    
}
if(isset($_POST['update'])){
  $expense = $_POST['expense_account'];
  $update = mysqli_query($conn, "UPDATE trips SET expense_account='$expense' WHERE id='$_POST[id]' ORDER BY id DESC ");
}

if(isset($_POST['delete-trip'])){
    $id = $_POST['id'];
    $delete = mysqli_query($conn, "DELETE FROM trips WHERE id = '$id'");
    if (!$delete) {
  echo("Error description: " . $delete -> error);
}

}
?>

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <link rel="apple-touch-icon" sizes="76x76" href="../assets/img/apple-icon.png">
  <link rel="icon" type="image/png" href="./assets/img/favicon.png">
  <title>
   Dicomm Driver Logbook
  </title>
  <!--     Fonts and icons     -->
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet" />
  <!-- Nucleo Icons -->
  <link href="./assets/css/nucleo-icons.css" rel="stylesheet" />
  <link href="./assets/css/nucleo-svg.css" rel="stylesheet" />
  <!-- Font Awesome Icons -->
  <script src="https://kit.fontawesome.com/42d5adcbca.js" crossorigin="anonymous"></script>
  <link href="./assets/css/nucleo-svg.css" rel="stylesheet" />
  <!-- CSS Files -->
  <link id="pagestyle" href="./assets/css/soft-ui-dashboard.css?v=1.0.1" rel="stylesheet" />
  <script src="https://kit.fontawesome.com/06d73363bc.js" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
 
</head>

<body class="g-sidenav-show  bg-gray-100">
<aside class="sidenav navbar navbar-vertical navbar-expand-xs border-0 border-radius-xl my-3 fixed-left ms-3" id="sidenav-main">
    <div class="sidenav-header">
      <i class="fas fa-times p-3 cursor-pointer text-secondary opacity-5 position-absolute right-0 top-0 d-none d-xl-none" aria-hidden="true" id="iconSidenav"></i>
    <a class="navbar-brand m-0" href="dashboard.php">
       
        <h6 class="ms-1 font-weight-bold text-info">Dicomm Driver Logbook</h6>
      </a>
    </div>
    <hr class="horizontal dark mt-0">
    <div class="collapse navbar-collapse  w-auto" id="sidenav-collapse-main">
      <ul class="navbar-nav">
        <li class="nav-item ">
          <a class="nav-link" href="dashboard.php">
            <div class="icon icon-shape  icon-sm shadow border-radius-md bg-white text-center me-2 d-flex align-items-center justify-content-center">
              <svg width="12px" height="12px" viewBox="0 0 45 40" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
                <title>shop </title>
                <g id="Basic-Elements" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                  <g id="Rounded-Icons" transform="translate(-1716.000000, -439.000000)" fill="#FFFFFF" fill-rule="nonzero">
                    <g id="Icons-with-opacity" transform="translate(1716.000000, 291.000000)">
                      <g id="shop-" transform="translate(0.000000, 148.000000)">
                        <path class="color-background" d="M46.7199583,10.7414583 L40.8449583,0.949791667 C40.4909749,0.360605034 39.8540131,0 39.1666667,0 L7.83333333,0 C7.1459869,0 6.50902508,0.360605034 6.15504167,0.949791667 L0.280041667,10.7414583 C0.0969176761,11.0460037 -1.23209662e-05,11.3946378 -1.23209662e-05,11.75 C-0.00758042603,16.0663731 3.48367543,19.5725301 7.80004167,19.5833333 L7.81570833,19.5833333 C9.75003686,19.5882688 11.6168794,18.8726691 13.0522917,17.5760417 C16.0171492,20.2556967 20.5292675,20.2556967 23.494125,17.5760417 C26.4604562,20.2616016 30.9794188,20.2616016 33.94575,17.5760417 C36.2421905,19.6477597 39.5441143,20.1708521 42.3684437,18.9103691 C45.1927731,17.649886 47.0084685,14.8428276 47.0000295,11.75 C47.0000295,11.3946378 46.9030823,11.0460037 46.7199583,10.7414583 Z" id="Path" opacity="0.598981585"></path>
                        <path class="color-background" d="M39.198,22.4912623 C37.3776246,22.4928106 35.5817531,22.0149171 33.951625,21.0951667 L33.92225,21.1107282 C31.1430221,22.6838032 27.9255001,22.9318916 24.9844167,21.7998837 C24.4750389,21.605469 23.9777983,21.3722567 23.4960833,21.1018359 L23.4745417,21.1129513 C20.6961809,22.6871153 17.4786145,22.9344611 14.5386667,21.7998837 C14.029926,21.6054643 13.533337,21.3722507 13.0522917,21.1018359 C11.4250962,22.0190609 9.63246555,22.4947009 7.81570833,22.4912623 C7.16510551,22.4842162 6.51607673,22.4173045 5.875,22.2911849 L5.875,44.7220845 C5.875,45.9498589 6.7517757,46.9451667 7.83333333,46.9451667 L19.5833333,46.9451667 L19.5833333,33.6066734 L27.4166667,33.6066734 L27.4166667,46.9451667 L39.1666667,46.9451667 C40.2482243,46.9451667 41.125,45.9498589 41.125,44.7220845 L41.125,22.2822926 C40.4887822,22.4116582 39.8442868,22.4815492 39.198,22.4912623 Z" id="Path"></path>
                      </g>
                    </g>
                  </g>
                </g>
              </svg>
            </div>
            <span class="nav-link-text ms-1">Dashboard</span>
          </a>
        </li>
        <li class="nav-item">
          <a class="nav-link  " href="driver-list.php">
            <div class="icon icon-shape icon-sm shadow border-radius-md bg-white text-center me-2 d-flex align-items-center justify-content-center">
              <svg width="12px" height="12px" viewBox="0 0 42 42" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
                <title>office</title>
                <g id="Basic-Elements" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                  <g id="Rounded-Icons" transform="translate(-1869.000000, -293.000000)" fill="#FFFFFF" fill-rule="nonzero">
                    <g id="Icons-with-opacity" transform="translate(1716.000000, 291.000000)">
                      <g id="office" transform="translate(153.000000, 2.000000)">
                        <path class="color-background" d="M12.25,17.5 L8.75,17.5 L8.75,1.75 C8.75,0.78225 9.53225,0 10.5,0 L31.5,0 C32.46775,0 33.25,0.78225 33.25,1.75 L33.25,12.25 L29.75,12.25 L29.75,3.5 L12.25,3.5 L12.25,17.5 Z" id="Path" opacity="0.6"></path>
                        <path class="color-background" d="M40.25,14 L24.5,14 C23.53225,14 22.75,14.78225 22.75,15.75 L22.75,38.5 L19.25,38.5 L19.25,22.75 C19.25,21.78225 18.46775,21 17.5,21 L1.75,21 C0.78225,21 0,21.78225 0,22.75 L0,40.25 C0,41.21775 0.78225,42 1.75,42 L40.25,42 C41.21775,42 42,41.21775 42,40.25 L42,15.75 C42,14.78225 41.21775,14 40.25,14 Z M12.25,36.75 L7,36.75 L7,33.25 L12.25,33.25 L12.25,36.75 Z M12.25,29.75 L7,29.75 L7,26.25 L12.25,26.25 L12.25,29.75 Z M35,36.75 L29.75,36.75 L29.75,33.25 L35,33.25 L35,36.75 Z M35,29.75 L29.75,29.75 L29.75,26.25 L35,26.25 L35,29.75 Z M35,22.75 L29.75,22.75 L29.75,19.25 L35,19.25 L35,22.75 Z" id="Shape"></path>
                      </g>
                    </g>
                  </g>
                </g>
              </svg>
            </div>
            <span class="nav-link-text ms-1">All drivers</span>
          </a>
        </li>
        <li class="nav-item">
          <a class="nav-link  " href="car-list.php">
            <div class="icon icon-shape icon-sm shadow border-radius-md bg-white text-center me-2 d-flex align-items-center justify-content-center">
              <svg width="12px" height="12px" viewBox="0 0 43 36" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
                <title>credit-card</title>
                <g id="Basic-Elements" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                  <g id="Rounded-Icons" transform="translate(-2169.000000, -745.000000)" fill="#FFFFFF" fill-rule="nonzero">
                    <g id="Icons-with-opacity" transform="translate(1716.000000, 291.000000)">
                      <g id="credit-card" transform="translate(453.000000, 454.000000)">
                        <path class="color-background" d="M43,10.7482083 L43,3.58333333 C43,1.60354167 41.3964583,0 39.4166667,0 L3.58333333,0 C1.60354167,0 0,1.60354167 0,3.58333333 L0,10.7482083 L43,10.7482083 Z" id="Path" opacity="0.593633743"></path>
                        <path class="color-background" d="M0,16.125 L0,32.25 C0,34.2297917 1.60354167,35.8333333 3.58333333,35.8333333 L39.4166667,35.8333333 C41.3964583,35.8333333 43,34.2297917 43,32.25 L43,16.125 L0,16.125 Z M19.7083333,26.875 L7.16666667,26.875 L7.16666667,23.2916667 L19.7083333,23.2916667 L19.7083333,26.875 Z M35.8333333,26.875 L28.6666667,26.875 L28.6666667,23.2916667 L35.8333333,23.2916667 L35.8333333,26.875 Z" id="Shape"></path>
                      </g>
                    </g>
                  </g>
                </g>
              </svg>
            </div>
            <span class="nav-link-text ms-1">All cars</span>
          </a>
        </li>
        

        <li class="nav-item">
          <a class="nav-link  " href="driver-list.php">
            <div class="icon icon-shape icon-sm shadow border-radius-md bg-white text-center me-2 d-flex align-items-center justify-content-center">
              <svg width="12px" height="12px" viewBox="0 0 42 42" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
                <title>office</title>
                <g id="Basic-Elements" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                  <g id="Rounded-Icons" transform="translate(-1869.000000, -293.000000)" fill="#FFFFFF" fill-rule="nonzero">
                    <g id="Icons-with-opacity" transform="translate(1716.000000, 291.000000)">
                      <g id="office" transform="translate(153.000000, 2.000000)">
                        <path class="color-background" d="M12.25,17.5 L8.75,17.5 L8.75,1.75 C8.75,0.78225 9.53225,0 10.5,0 L31.5,0 C32.46775,0 33.25,0.78225 33.25,1.75 L33.25,12.25 L29.75,12.25 L29.75,3.5 L12.25,3.5 L12.25,17.5 Z" id="Path" opacity="0.6"></path>
                        <path class="color-background" d="M40.25,14 L24.5,14 C23.53225,14 22.75,14.78225 22.75,15.75 L22.75,38.5 L19.25,38.5 L19.25,22.75 C19.25,21.78225 18.46775,21 17.5,21 L1.75,21 C0.78225,21 0,21.78225 0,22.75 L0,40.25 C0,41.21775 0.78225,42 1.75,42 L40.25,42 C41.21775,42 42,41.21775 42,40.25 L42,15.75 C42,14.78225 41.21775,14 40.25,14 Z M12.25,36.75 L7,36.75 L7,33.25 L12.25,33.25 L12.25,36.75 Z M12.25,29.75 L7,29.75 L7,26.25 L12.25,26.25 L12.25,29.75 Z M35,36.75 L29.75,36.75 L29.75,33.25 L35,33.25 L35,36.75 Z M35,29.75 L29.75,29.75 L29.75,26.25 L35,26.25 L35,29.75 Z M35,22.75 L29.75,22.75 L29.75,19.25 L35,19.25 L35,22.75 Z" id="Shape"></path>
                      </g>
                    </g>
                  </g>
                </g>
              </svg>
            </div>
            <span class="nav-link-text ms-1">All drivers</span>
          </a>
        </li>
        
        
        
      </ul>
    </div>
    
  </aside>
  <main class="main-content mt-1 border-radius-lg">
    <!-- Navbar -->
   
        
      </div>
    </nav>
    <!-- End Navbar -->
   <div style="position:fixed;" class="container-fluid "> 
   <div class="page-header min-height-200 border-radius-xl mt-4" style="background-image: url('./img/background.jpg'); background-size:cover;background-attachment:fixed;width:73%">
       
      </div>
      <div style="position:fixed;margin:-15% auto;width:66%;z-index:99;background-color:red;" class="card card-body blur shadow-blur mx-4 mt-n9">
        <div class="row gx-4">
          

    <?php
        $query = mysqli_query($conn, "SELECT * FROM cars WHERE car = '$_POST[car]' ");
        $details = mysqli_fetch_array($query);

        $getid = mysqli_query($conn, "SELECT * FROM trips WHERE car = '$_POST[car]'");
        $id = mysqli_fetch_array($getid);
    ?>

<div class="col-12" style="height:100px;text-align:center;align-items:center;">

<h3 class="mt-3">All Books For <?php echo $_POST['car']?></h3>
    <div class="d-flex col-4 mx-auto justify-content-around">
        <div>
            <form action="generate-report.php" method="POST">
                <input type="hidden" name="car" value="<?php echo $_POST['car']?>">
                <input type="submit" name="back" value="Back" class="btn btn-info">
            </form>
        </div>
        <div>
            <form action="print-report.php" method="POST" target="_blank">
                <input type="hidden" name="start" value="<?php echo $_POST['start']?>">
                <input type="hidden" name="end" value="<?php echo $_POST['end']?>">
                <input type="hidden" name="car" value="<?php echo $_POST['car']?>">
                <input type="submit" name="generate" value="Generate PDF" class="btn btn-success">
            </form>
        </div>
    </div>

      </div>
          
        </div>
      </div>
      </div>
  
    </div><br><br>

    <div style="margin:0 auto" class="card-body px-0 pt-0 pb-2 col-11">
              <div style="margin-top:18%;z-index:-1;" class="table-responsive p-0">
                <table style="width:100%;z-index:-1" class="table align-items-center mb-0">
                  <thead>
                    <tr>
                    <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">Date</th>  
                   
                    <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">Driver</th>       
                    <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">Client</th>  
                    <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">Expense Account</th>  
                              
                                   
                      <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">Start Mileage</th>
                      <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">End Mileage</th>
                     
                      <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">Fueling</th>
                     
                     
                      <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2"></th>
                    </tr>
                  </thead>
                  
                  <tbody>

                  <?php
                    $start = $_POST['start'];
                    $end = $_POST['end'];
                    if($end > 0){
                  $result = mysqli_query($conn, "SELECT * FROM trips WHERE car='$_POST[car]'  AND start_mileage BETWEEN '$start' and '$end' ORDER BY end_mileage DESC");
    while($row = mysqli_fetch_array($result)){
                         
    $mileage = $row['end_mileage'] - $row['start_mileage'];?>
                    <tr>
                     
                      <td>
                          <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#i<?php echo $row['id']?>">
                              <?php echo $row['date']?>
                            </button>
                            <div class="modal fade" id="i<?php echo $row['id']?>" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel"><?php echo $row['id']?></h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <form action="edit-trips.php" method="POST">
      <div class="modal-body">
          <label class="text-xxs">Client</label>
          <input type="text" class="form-control" name="client" value="<?php echo $row['client']?>">
          <label class="text-xxs">Job number</label>
           <input type="number" class="form-control" name="job" value="<?php echo $row['job']?>">
           <label class="text-xxs">Expense account</label>
           <input type="text" class="form-control" name="expense_account" value="<?php echo $row['expense_account']?>">
           <label class="text-xxs">Description</label>
            <input type="text" class="form-control" name="description" value="<?php echo $row['description']?>">
            <label class="text-xxs">Destination</label>
             <input type="text" class="form-control" name="destination" value="<?php echo $row['destination']?>">
             <label class="text-xxs">Datr</label>
              <input type="date" class="form-control" name="date" value="<?php echo $row['date']?>">
              <label class="text-xxs">1st leg start time</label>
               <input type="time" class="form-control" name="start_time" value="<?php echo $row['start_time']?>">
               <label class="text-xxs">1st leg end time</label>
                <input type="time" class="form-control" name="end_time" value="<?php echo $row['end_time']?>">
                <label class="text-xxs">2nd leg start time</label>
                 <input type="time" class="form-control" name="start_time2" value="<?php echo $row['start_time2']?>">
                 <label class="text-xxs">2nd leg end time</label>
                  <input type="time" class="form-control" name="end_time2" value="<?php echo $row['end_time2']?>">
                  <label class="text-xxs">Start mileage</label>
                   <input type="number" class="form-control" name="start_mileage" value="<?php echo $row['start_mileage']?>">
                   <label class="text-xxs">End mileage</label>
                    <input type="number" class="form-control" name="end_mileage" value="<?php echo $row['end_mileage']?>">
                    <label class="text-xxs">Station mileage</label>
                     <input type="number" class="form-control" name="station_mileage" value="<?php echo $row['station_mileage']?>">
                     <label class="text-xxs">Amount</label>
                      <input type="number" step="any" class="form-control" name="amount" value="<?php echo $row['amount']?>">
                      <label class="text-xxs">Litres</label>
                       <input type="number" step="any" class="form-control" name="litres" value="<?php echo $row['litres']?>">
      
      </div>
      <div class="modal-footer">
          <form action="edit-trips.php" method="POST">
              <input type="hidden" name="id" value="<?php echo $row['id']?>">
              <input type="hidden" name="start" value="<?php echo $_POST['start']?>">
              <input type="hidden" name="end" value="<?php echo $_POST['end']?>">
              <input type="submit" class="btn btn-danger" name="delete-trip" value="Delete">
          </form>
          <input type="hidden" name="username" value="<?php echo $row['username']?>">
          <input type="hidden" name="start" value="<?php echo $_POST['start']?>">
              <input type="hidden" name="end" value="<?php echo $_POST['end']?>">
        <input type="hidden" name="car" value="<?php echo $row['car']?>">
        <input type="hidden" name="id" value="<?php echo $row['id']?>">
        <input type="submit" name="update-trip" class="btn btn-primary" value="Save changes">
        </form>
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
                      </td>
                      <td>
                        <p class="text-xs font-weight-bold mb-0 " ><?php echo $row['username']?></p>
                        
                      </td>
                   
                      <td>
                        <p class="text-xs font-weight-bold mb-0 " ><?php echo $row['client']?></p>
                        
                      </td>
                      <td>
                        <p class="text-xs font-weight-bold mb-0 " ><?php echo $row['expense_account']?></p>
                        
                      </td>
                     
                      <td>
                        <p class="text-xs font-weight-bold mb-0" style="text-align:center"><?php echo $row['start_mileage']?></p>
                        
                      </td>
                      <td>
                        <p class="text-xs font-weight-bold mb-0" style="text-align:center"><?php echo $row['end_mileage']?></p>
                        
                      </td>
                      
                      <td>
                        <p class="text-xs font-weight-bold mb-0" style="text-align:center"><span style="font-weight:bold; color:red;">
                        <?php
                          if($row['station_mileage'] > 0){
                            echo $row['station_mileage'];
                          }
                        ?>
                      </span></p>
                        
                      </td>
                     
                     
                     
                     
                     
                     
                    </tr>
                        <?php }}else{
                             $result = mysqli_query($conn, "SELECT * FROM trips WHERE car='$_POST[car]'  AND start_mileage > $start ORDER BY start_mileage DESC ");
                             while($row = mysqli_fetch_array($result)){
                                                  
                             $mileage = $row['end_mileage'] - $row['start_mileage'];?>
                           
                    <tr>
                  
                      
                   
                                    <td>
                          <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#i<?php echo $row['id']?>">
                              <?php echo $row['date']?>
                            </button>
                            <div class="modal fade" id="i<?php echo $row['id']?>" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel"><?php echo $row['id']?></h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <form action="edit-trips.php" method="POST">
      <div class="modal-body">
          <label class="text-xxs">Client</label>
          <input type="text" class="form-control" name="client" value="<?php echo $row['client']?>">
          <label class="text-xxs">Job number</label>
           <input type="number" class="form-control" name="job" value="<?php echo $row['job']?>">
           <label class="text-xxs">Expense account</label>
           <input type="text" class="form-control" name="expense_account" value="<?php echo $row['expense_account']?>">
           <label class="text-xxs">Description</label>
            <input type="text" class="form-control" name="description" value="<?php echo $row['description']?>">
            <label class="text-xxs">Destination</label>
             <input type="text" class="form-control" name="destination" value="<?php echo $row['destination']?>">
             <label class="text-xxs">Datr</label>
              <input type="date" class="form-control" name="date" value="<?php echo $row['date']?>">
              <label class="text-xxs">1st leg start time</label>
               <input type="time" class="form-control" name="start_time" value="<?php echo $row['start_time']?>">
               <label class="text-xxs">1st leg end time</label>
                <input type="time" class="form-control" name="end_time" value="<?php echo $row['end_time']?>">
                <label class="text-xxs">2nd leg start time</label>
                 <input type="time" class="form-control" name="start_time2" value="<?php echo $row['start_time2']?>">
                 <label class="text-xxs">2nd leg end time</label>
                  <input type="time" class="form-control" name="end_time2" value="<?php echo $row['end_time2']?>">
                  <label class="text-xxs">Start mileage</label>
                   <input type="number" class="form-control" name="start_mileage" value="<?php echo $row['start_mileage']?>">
                   <label class="text-xxs">End mileage</label>
                    <input type="number" class="form-control" name="end_mileage" value="<?php echo $row['end_mileage']?>">
                    <label class="text-xxs">Station mileage</label>
                     <input type="number" class="form-control" name="station_mileage" value="<?php echo $row['station_mileage']?>">
                     <label class="text-xxs">Amount</label>
                      <input type="number" step="any" class="form-control" name="amount" value="<?php echo $row['amount']?>">
                      <label class="text-xxs">Litres</label>
                       <input type="number" step="any" class="form-control" name="litres" value="<?php echo $row['litres']?>">
      
      </div>
      <div class="modal-footer">
          <form action="edit-trips.php" method="POST">
              <input type="hidden" name="id" value="<?php echo $row['id']?>">
              <input type="hidden" name="start" value="<?php echo $_POST['start']?>">
              <input type="hidden" name="end" value="<?php echo $_POST['end']?>">
              <input type="submit" class="btn btn-danger" name="delete-trip" value="Delete">
          </form>
          <input type="hidden" name="username" value="<?php echo $row['username']?>">
          <input type="hidden" name="start" value="<?php echo $_POST['start']?>">
              <input type="hidden" name="end" value="<?php echo $_POST['end']?>">
        <input type="hidden" name="car" value="<?php echo $row['car']?>">
        <input type="hidden" name="id" value="<?php echo $row['id']?>">
        <input type="submit" name="update-trip" class="btn btn-primary" value="Save changes">
        </form>
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>
                      </td>
                        <!-- Button trigger modal -->


<!-- Modal -->

                      </td>
                      </td>
                     
                      
                      <td>
                        <p class="text-xs font-weight-bold mb-0 " ><?php echo $row['username']?></p>
                        
                      </td>
                   
                      <td>
                        <p class="text-xs font-weight-bold mb-0 " ><?php echo $row['client']?></p>
                        
                      </td>
                      <td>
                        <p class="text-xs font-weight-bold mb-0 " ><?php echo $row['expense_account']?></p>
                        
                      </td>
                     
                      <td>
                        <p class="text-xs font-weight-bold mb-0" style="text-align:center"><?php echo $row['start_mileage']?></p>
                        
                      </td>
                      <td>
                        <p class="text-xs font-weight-bold mb-0" style="text-align:center"><?php echo $row['end_mileage']?></p>
                        
                      </td>
                      
                      <td>
                        <p class="text-xs font-weight-bold mb-0" style="text-align:center"><span style="font-weight:bold; color:red;">
                        <?php
                          if($row['station_mileage'] > 0){
                            echo $row['station_mileage'];
                          }
                        ?>
                      </span></p>
                        
                      </td>
                     
                     
                     
                     
                     
                     
                    </tr>
                            
                            
                            <?php } }?>

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

?>
