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

	$sql = "SELECT tempahan_kenderaan.tempahanID,tempahan_kenderaan.kad_pengenalan, tempahan_kenderaan.tarikhMohon, tempahan_kenderaan.masaMohon, tempahan_kenderaan.tarikhDestinasiDari, tempahan_kenderaan.tarikhDestinasiHingga, tempahan_kenderaan.masaDari, tempahan_kenderaan.masaHingga,
			tempahan_kenderaan.destinasi, tempahan_kenderaan.pemanduID, tempahan_kenderaan.kenderaanID,tempahan_kenderaan.status, user.kad_pengenalan, user.nama_user 
			FROM tempahan_kenderaan JOIN user ON tempahan_kenderaan.kad_pengenalan=user.kad_pengenalan WHERE tempahan_kenderaan.status='SEDANG DIPROSES' ORDER BY tempahan_kenderaan.tarikhDestinasiDari ASC, tempahan_kenderaan.masaDari ASC, tempahan_kenderaan.tarikhMohon ASC, tempahan_kenderaan.masaMohon ASC";
	$result = mysqli_query($conn,$sql);
	
	$sql1 ="SELECT peranan_user FROM user WHERE kad_pengenalan='".$_SESSION['kadPengenalan']."'";
	$result1 = mysqli_query($conn,$sql1);
	$row1 = mysqli_fetch_array($result1);
	
	$sql2 = "SELECT tempahan_kenderaan.tempahanID, tempahan_kenderaan.kad_pengenalan, tempahan_kenderaan.tarikhMohon, tempahan_kenderaan.masaMohon, tempahan_kenderaan.tarikhDestinasiDari, tempahan_kenderaan.tarikhDestinasiHingga, tempahan_kenderaan.masaDari, tempahan_kenderaan.masaHingga,
			tempahan_kenderaan.destinasi, tempahan_kenderaan.pemanduID, tempahan_kenderaan.kenderaanID,tempahan_kenderaan.status, user.kad_pengenalan, user.nama_user 
			FROM tempahan_kenderaan JOIN user ON tempahan_kenderaan.kad_pengenalan=user.kad_pengenalan WHERE tempahan_kenderaan.status='SENARAI MENUNGGU' ORDER BY tempahan_kenderaan.tarikhDestinasiDari ASC, tempahan_kenderaan.masaDari ASC, tempahan_kenderaan.tarikhMohon ASC, tempahan_kenderaan.masaMohon ASC";
	$result2 = mysqli_query($conn,$sql2);
	

?>

<!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>
	.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>Semak Kelulusan Tempahan</h1>
     
    </div><!-- End Page Title -->
    <!-- Section Table -->
	<section class="section">
      <div class="row">
        <div class="col-lg-12">

          <div class="card" style="overflow:scroll">
            <div class="card-body">
              <!-- Table with stripped rows -->
              <table class="table datatable">
                <thead>
                      <tr>
						<th scope="col">No.</th>
                        <th scope="col">TARIKH</th>
                        <th scope="col">MASA</th>
						<th scope="col">NAMA PENUMPANG</th>
						<th scope="col">TARIKH/MASA MOHON</th>
                        <th scope="col">DESTINASI</th>
                        <th scope="col">DETAIL</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;
						}
					
						if ($row['tarikhMohon'] > $row['tarikhDestinasiDari'])
						{
						?>					
						<tr class="<?php echo $warnaBulanSemasa; ?>" style="color:red;">
						<?php
						}
						else
						{
						?>
						<tr class="<?php echo $warnaBulanSemasa; ?>">
						<?php
						}
						?>
                        <th><?php echo $no; ?></th>
                        <td scope="row"><?php echo date("d-m-Y", strtotime($row['tarikhDestinasiDari'])); ?> - <?php echo date("d-m-Y", strtotime($row['tarikhDestinasiHingga'])); ?></td>
                        <td><?php echo $row['masaDari'] ?> - <?php echo $row['masaHingga'] ?></td>
                        <th><?php echo $row['nama_user'] ?></th>
                        <td><?php echo date("d-m-Y", strtotime($row['tarikhMohon'])); ?><?php if ($row['masaMohon']==NULL){echo "";} else {echo " ".date("h:i:s a", strtotime($row['masaMohon']));} ?></td>
                        <td><?php echo $row['destinasi'] ?></td>
						<td><a href="semakKelulusan.php?tempahanID=<?php echo $row['tempahanID'];?>"><i class="bi bi-gear-fill"></i></a></td>
						<td><button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#basicModal<?php echo $row['tempahanID'];?>"><i class="bi bi-x-circle-fill" ></i></button>
							<div class="modal fade" id="basicModal<?php echo $row['tempahanID'];?>" tabindex="-1">
								<div class="modal-dialog">
								  <div class="modal-content">
									<div class="modal-header">
									  <h5 class="modal-title">Anda pasti untuk BATAL tempahan?</h5>
									  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
									</div>
									<form class="row g-3" action="internalPage/batalTempahanKenderaanAdmin.php?tempahanID=<?php echo $row["tempahanID"]; ?>" method="post" enctype="multipart/form-data">
										<div class="modal-body">
											<label for="inputDate" class="col-sm-6 col-form-label">Jika Ya, sila masukkan catatan:</label>
											<div class="col-sm-6" >
												<input type="text" class="form-control" name="catatan" id="catatan" required>
											</div>
										</div>
									
									<div class="modal-footer">
										<button type="submit" class="btn btn-primary">Ya</button>
										<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tidak</button>
									</div>
									</form>
								  </div>
								</div>
							</div>
						</td>
                      </tr>                    
                      </tr>
					
					<?php
						}	
					?>
                    </tbody>
              </table>
			  
              <!-- End Table with stripped rows -->

            </div>
          </div>

        </div>
      </div>
    </section>

  </main><!-- End #main -->
  
  <!-- Waiting list -->
  <main id="main" class="main">

    <div class="pagetitle">
      <h1 style="color:red;">Senarai Menunggu</h1>
     
    </div><!-- End Page Title -->
    <!-- Section Table -->
	<section class="section">
      <div class="row">
        <div class="col-lg-12">

          <div class="card" style="overflow:scroll">
            <div class="card-body">
              <!-- Table with stripped rows -->
              <table class="table datatable">
                <thead>
                      <tr>
						<th scope="col">No.</th>
                        <th scope="col">TARIKH</th>
                        <th scope="col">MASA</th>
						<th scope="col">NAMA PENUMPANG</th>
						<th scope="col">TARIKH/MASA MOHON</th>
                        <th scope="col">DESTINASI</th>
                        <th scope="col">DETAIL</th>
						<th scope="col">BATAL</th>
                      </tr>
                    </thead>
                    <tbody>
					<?php
					
					$no=0;
					$bulanSemasa = '';
					$warnaBulanSemasa = 'month-group-white';
					while($row2 = mysqli_fetch_array($result2))
					{
						$no ++;
						$bulanBaris = date('Y-m', strtotime($row2['tarikhDestinasiDari']));
						if ($bulanBaris !== $bulanSemasa)
						{
							$warnaBulanSemasa = ($warnaBulanSemasa === 'month-group-blue') ? 'month-group-white' : 'month-group-blue';
							$bulanSemasa = $bulanBaris;
						}
					
						if ($row2['tarikhMohon'] > $row2['tarikhDestinasiDari'])
						{
						?>					
						<tr class="<?php echo $warnaBulanSemasa; ?>" style="color:red;">
						<?php
						}
						else
						{
						?>
						<tr class="<?php echo $warnaBulanSemasa; ?>">
						<?php
						}
						?>
							<th><?php echo $no; ?></th>
							<td scope="row"><?php echo date("d-m-Y", strtotime($row2['tarikhDestinasiDari'])); ?> - <?php echo date("d-m-Y", strtotime($row2['tarikhDestinasiHingga'])); ?></td>
							<td><?php echo $row2['masaDari'] ?> - <?php echo $row2['masaHingga'] ?></td>
							<th><?php echo $row2['nama_user'] ?></th>
							<td><?php echo date("d-m-Y", strtotime($row2['tarikhMohon'])); ?><?php if ($row2['masaMohon']==NULL){echo "";} else {echo " ".date("h:i:s a", strtotime($row2['masaMohon']));} ?></td>
							<td><?php echo $row2['destinasi'] ?></td>
							<td><a href="semakKelulusan.php?tempahanID=<?php echo $row2["tempahanID"];?>"><i class="bi bi-gear-fill"></i></a></td>
							<td><button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#basicModal<?php echo $row2["tempahanID"];?>"><i class="bi bi-x-circle-fill" ></i></button>
								<div class="modal fade" id="basicModal<?php echo $row2["tempahanID"];?>" tabindex="-1">
									<div class="modal-dialog">
									  <div class="modal-content">
										<div class="modal-header">
										  <h5 class="modal-title">Anda pasti untuk BATAL tempahan?</h5>
										  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
										</div>
										<form class="row g-3" action="internalPage/batalTempahanKenderaanAdmin.php?tempahanID=<?php echo $row2["tempahanID"]; ?>" method="post" enctype="multipart/form-data">
											<div class="modal-body">
												<label for="inputDate" class="col-sm-6 col-form-label">Jika Ya, sila masukkan catatan:</label>
												<div class="col-sm-6" >
													<input type="text" class="form-control" name="catatan" id="catatan" required>
												</div>
											</div>
										
										<div class="modal-footer">
											<button type="submit" class="btn btn-primary">Ya</button>
											<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Tidak</button>
										</div>
										</form>
									  </div>
									</div>
								</div>
							</td>
						  </tr>                    
                      </tr>
					
					<?php
						}	
					?>
                    </tbody>
              </table>
			  
              <!-- End Table with stripped rows -->

            </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>

</body>

</html>
