<?php
include '../connect.php';
session_start();

	date_default_timezone_set("Asia/Kuala_Lumpur");			
	$date=date('Y-m-d');
	$time=date('H:i:sa');

	$sql = "SELECT tempahan_kenderaan.tempahanID, tempahan_kenderaan.kad_pengenalan, tempahan_kenderaan.tarikhDestinasiDari, tempahan_kenderaan.tarikhDestinasiHingga, tempahan_kenderaan.masaDari, tempahan_kenderaan.masaHingga,
			tempahan_kenderaan.destinasi, tempahan_kenderaan.pemanduID, tempahan_kenderaan.kenderaanID,tempahan_kenderaan.nama_penumpang,tempahan_kenderaan.status,tempahan_kenderaan.catatan, user.kad_pengenalan, user.nama_user 
			FROM tempahan_kenderaan JOIN user ON tempahan_kenderaan.kad_pengenalan=user.kad_pengenalan WHERE tempahan_kenderaan.kad_pengenalan='".$_SESSION['kadPengenalan']."' AND tempahan_kenderaan.tarikhDestinasiHingga>= '".$date."' ORDER BY tempahan_kenderaan.tarikhDestinasiDari ASC, tempahan_kenderaan.masaDari ASC";
	$result = mysqli_query($conn,$sql);
	
	$sql1 ="SELECT nama_user, peranan_user FROM user WHERE kad_pengenalan='".$_SESSION['kadPengenalan']."'";
	$result1 = mysqli_query($conn,$sql1);
	$row1 = mysqli_fetch_array($result1);

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

<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">

  <title>Sistem Tempahan</title>
  <meta content="" name="description">
  <meta content="" name="keywords">

  <!-- Favicons -->
  <link href="../assets/img/logo_tab.png" rel="icon">

  <!-- Google Fonts -->
  <link href="https://fonts.gstatic.com" rel="preconnect">
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">

  <!-- Vendor CSS Files -->
  <link href="../assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <link href="../assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
  <link href="../assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
  <link href="../assets/vendor/quill/quill.snow.css" rel="stylesheet">
  <link href="../assets/vendor/quill/quill.bubble.css" rel="stylesheet">
  <link href="../assets/vendor/remixicon/remixicon.css" rel="stylesheet">
  <link href="../assets/vendor/simple-datatables/style.css" rel="stylesheet">

  <!-- Template Main CSS File -->
  <link href="../assets/css/style.css" rel="stylesheet">
  
  <!-- Script logout -->
  <script type="text/javascript" src="../internalPage/logoutConfirmation.js"></script>
  
	<style>
	.about{
	overflow-x:auto;
	background-color:white;
	}
	.month-group-blue > th,
	.month-group-blue > td{
		background-color: var(--bs-primary-bg-subtle) !important;
	}
	.month-group-white > th,
	.month-group-white > td{
		background-color: #ffffff !important;
	}
	</style>
  
  <!-- =======================================================
  * Template Name: NiceAdmin - v2.2.0
  * Template URL: https://bootstrapmade.com/nice-admin-bootstrap-admin-html-template/
  * Author: BootstrapMade.com
  * License: https://bootstrapmade.com/license/
  ======================================================== -->
</head>

<body>

  <?php 
  if($row1['peranan_user']=='USER')
  {
	  include 'header.html';
  }
  else
  {
	  include 'headerAdmin.html';
  }
  ?>

  <main id="main" class="main">

    <div class="pagetitle">
      <h1>Dashboard</h1>
      
    </div><!-- End Page Title -->

    <section class="about" id="about">
      <div class="row">
        <div class="col-lg-12">
            <div class="col-12">
                  <h5 class="card-title">SENARAI PERMOHONAN KENDERAAN <br> DARIPADA <?php echo $row1['nama_user'] ?> </h5>
                  <table class="table table-bordered">
                    <thead>
                      <tr>
                        <th scope="col">TARIKH</th>
                        <th scope="col">MASA</th>
						<th scope="col">NAMA PENUMPANG</th>
                        <th scope="col">DESTINASI</th>
                        <th scope="col">PEMANDU</th>
                        <th scope="col">KENDERAAN</th>
						<th scope="col">STATUS</th>
						<th scope="col">CATATAN</th>
						<th scope="col">UBAHSUAI</th>
						<th scope="col">BATAL</th>
                      </tr>
                    </thead>
                    <tbody>
					<?php
					
					$no=0;
					$bulanSemasa = '';
					$warnaBulanSemasa = 'month-group-white';
					while($row = mysqli_fetch_array($result))
					{
						$no ++;
						$bulanBaris = date('Y-m', strtotime($row['tarikhDestinasiDari']));
						if ($bulanBaris !== $bulanSemasa)
						{
							$warnaBulanSemasa = ($warnaBulanSemasa === 'month-group-blue') ? 'month-group-white' : 'month-group-blue';
							$bulanSemasa = $bulanBaris;
						}
						
						$pemandu_IC= $row['pemanduID'];
						
						$sql3="SELECT nama_pemandu FROM pemandu where pemanduID='".$pemandu_IC."' ";
						$result3 = mysqli_query($conn,$sql3);
						$row3 = mysqli_fetch_array($result3);
						?>
					
                      <tr class="<?php echo $warnaBulanSemasa; ?>">
                        
                        <td scope="row"><b><?php echo date("d-m-Y", strtotime($row['tarikhDestinasiDari'])); ?><?php if ($row['tarikhDestinasiHingga']==NULL){echo "";} else {echo ' HINGGA '.date("d-m-Y", strtotime($row['tarikhDestinasiHingga']));}  ?></b></td>
                        <td><?php echo date('h:i:s a', strtotime($row['masaDari'])) ?> - <?php echo date('h:i:s a', strtotime($row['masaHingga'])) ?></td>
                        <th><?php echo $row['nama_penumpang'] ?></th>
                        <td><?php echo $row['destinasi'] ?></td>
						<?php
						if($pemandu_IC=="")
						{
						?>
						<td></td>
						<?php
						}
						else
						{
						?>
						<td><?php echo $row3['nama_pemandu'] ?></td>
						<?php
						}
						if ($row['kenderaanID']=="")
						{
						?>
						<td></td>
						<?php
						}
						else
						{
						?>
						<td><?php echo $row['kenderaanID'] ?></td>
						<?php					
						}
						if($row['status']=='SEDANG DIPROSES')
						{
						?>
						<td><span class='badge bg-warning'><?php echo $row['status'] ?></span></td>
						<?php
						}
						else if($row['status']=="LULUS")
						{
						?>
						<td><span class='badge bg-success'><?php echo $row['status'] ?></span></td>
						<?php
						}
						else
						{
						?>
						<td><span class='badge bg-danger'><?php echo $row['status'] ?></span></td>
						<?php
						}
						?>
						<td><?php echo $row['catatan'] ?></td>
						<?php						
						if($row['status']=="TIDAK LULUS" || $row['status']=="BATAL")
						{
						?>	
						<td></td>
						<?php
						}
						else
						{
						?>
						<td><a href="ubahsuaiTempahanKenderaan.php?tempahanID=<?php echo $row["tempahanID"]; ?>"><center><i class="bi bi-pencil" ></i></center></a></td>
						<?php
						}
						if($row['status']=="TIDAK LULUS" || $row['status']=="BATAL")
						{
						?>	
						<td></td>
						<?php
						}
						else
						{
						?>
						<td><a href="internalPage/batalTempahanKenderaan.php?tempahanID=<?php echo $row["tempahanID"]; ?>" onclick="return deleletconfig()"><center><i class="bi bi-x-circle-fill" ></i></center></a></td>
						<?php
						}
						?>
						
                      </tr>
                      <?php
					}
					?>
                    </tbody>
                  </table>
                </div>
          </div>
        </div>
      </div>
    </section>

  </main><!-- End #main -->

  <!-- ======= Footer ======= -->
  <footer id="footer" class="footer">
    <div class="copyright">
      &copy; Copyright <strong><span>Majlis Agama Islam Negeri Pulau Pinang @ 2022</span></strong>.
    </div>
  </footer><!-- End Footer -->

  <a href="#" class="back-to-top d-flex align-items-center justify-content-center"><i class="bi bi-arrow-up-short"></i></a>

  <!-- Vendor JS Files -->
  <script src="../assets/vendor/apexcharts/apexcharts.min.js"></script>
  <script src="../assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
  <script src="../assets/vendor/chart.js/chart.min.js"></script>
  <script src="../assets/vendor/echarts/echarts.min.js"></script>
  <script src="../assets/vendor/quill/quill.min.js"></script>
  <script src="../assets/vendor/simple-datatables/simple-datatables.js"></script>
  <script src="../assets/vendor/tinymce/tinymce.min.js"></script>
  <script src="../assets/vendor/php-email-form/validate.js"></script>

  <!-- Template Main JS File -->
  <script src="../assets/js/main.js"></script>

	<script>
		function deleletconfig(){

		var del=confirm("Anda pasti untuk BATAL tempahan?");
		if (del==true){
		alert ("Tempahan kenderaan berjaya dibatal.")
		}
		return del;
		}
	</script>

</body>

</html>
