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

	$sql = "SELECT tempahan_bilik.bilikID, tempahan_bilik.kad_pengenalan, tempahan_bilik.nama_mesyuarat,tempahan_bilik.tarikh,tempahan_bilik.tarikhHingga, tempahan_bilik.masaDari, tempahan_bilik.masaHingga, tempahan_bilik.jenisBilik, tempahan_bilik.status, tempahan_bilik.tarikh_mohon, user.nama_user FROM `tempahan_bilik` JOIN `user` ON tempahan_bilik.kad_pengenalan=user.kad_pengenalan WHERE tempahan_bilik.status='SEDANG DIPROSES' ORDER BY tempahan_bilik.tarikh 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_bilik.bilikID, tempahan_bilik.kad_pengenalan, tempahan_bilik.nama_mesyuarat,tempahan_bilik.tarikh,tempahan_bilik.tarikhHingga, tempahan_bilik.masaDari, tempahan_bilik.masaHingga, tempahan_bilik.jenisBilik, tempahan_bilik.status,tempahan_bilik.tarikh_mohon, user.nama_user FROM `tempahan_bilik` JOIN `user` ON tempahan_bilik.kad_pengenalan=user.kad_pengenalan WHERE tempahan_bilik.status='SENARAI MENUNGGU' ORDER BY tempahan_bilik.tarikh 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 Pendaftaran Surat</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>

  <!-- =======================================================
  * 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 Bilik</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 (DARI-HINGGA)</th>
						<th scope="col">TAJUK MESYUARAT/PERBINCANGAN</th>
                        <th scope="col">JENIS BILIK</th>
                        <th scope="col">NAMA PEMOHON</th>
                        <th scope="col">TARIKH MOHON</th>
                        <th scope="col">DETAIL</th>
                        <th scope="col">BATAL</th>						
                      </tr>
                    </thead>
                    <tbody>
					<?php
					
					$no=0;
					while($row = mysqli_fetch_array($result))
					{
						$no ++;
						
						if(($row['jenisBilik']=="BILIK MESYUARAT TINGKAT 7" || $row['jenisBilik']=="BILIK MESYUARAT") && $row['tarikh_mohon'] > $row['tarikh'])
						{
					?>
                      <tr style="background-color:#A1D7FA; color:red ">
					  <?php
						}
						else if($row['jenisBilik']=="BILIK PERBINCANGAN TINGKAT 9(K)" && $row['tarikh_mohon'] > $row['tarikh'])
						{
						?>
                        <tr style="background-color:#FFA38F; color:red">
						<?php
						}
						else if($row['jenisBilik']=="BILIK PERBINCANGAN TINGKAT 9(B)" && $row['tarikh_mohon'] > $row['tarikh'])
						{
						?>
                        <tr style="background-color:#EEADF6; color:red">
						<?php
						}
						else if($row['jenisBilik']=="BILIK PERBINCANGAN TINGKAT 8" && $row['tarikh_mohon'] > $row['tarikh'])
						{
						?>
                        <tr style="background-color:#9CEC98; color:red">
						<?php
						}
						else if($row['jenisBilik']=="BILIK PERBINCANGAN TINGKAT 7" && $row['tarikh_mohon'] > $row['tarikh'])
						{
						?>
                        <tr style="background-color:#FAF5A1; color:red">
						<?php
						}
						else if($row['jenisBilik']=="BILIK MESYUARAT TINGKAT 7" || $row['jenisBilik']=="BILIK MESYUARAT" )
						{
						?>
                        <tr style="background-color:#A1D7FA;">
						<?php
						}
						else if($row['jenisBilik']=="BILIK PERBINCANGAN TINGKAT 9(K)")
						{
						?>
                        <tr style="background-color:#FFA38F;">
						<?php
						}
						else if($row['jenisBilik']=="BILIK PERBINCANGAN TINGKAT 9(B)")
						{
						?>
                        <tr style="background-color:#EEADF6;">
						<?php
						}
						else if($row['jenisBilik']=="BILIK PERBINCANGAN TINGKAT 8" )
						{
						?>
                        <tr style="background-color:#9CEC98;">
						<?php
						}
						else 
						{
						?>
                        <tr style="background-color:#FAF5A1;">
						<?php
						}						
						?>
                        <th><?php echo $no; ?></th>
                        <td scope="row"><?php echo date("d-m-Y", strtotime($row['tarikh'])); ?><?php if ($row['tarikhHingga']==NULL){echo "";} else {echo '<label style="font-weight: bold;">&nbsp;HINGGA &nbsp;</label>'.date("d-m-Y", strtotime($row['tarikhHingga']));}  ?></td>
                        <td><?php echo $row['masaDari'] ?> - <?php echo $row['masaHingga'] ?></td>
                        <th><?php echo $row['nama_mesyuarat'] ?></th>
                        <td><?php echo $row['jenisBilik'] ?></td>
						<td><?php echo $row['nama_user'] ?></td>
						<td><?php echo $row['tarikh_mohon'] ?></td>
						<td><a href="semakKelulusan.php?bilikID=<?php echo $row["bilikID"];?>"><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["bilikID"];?>"><i class="bi bi-x-circle-fill" ></i></button>
							<div class="modal fade" id="basicModal<?php echo $row["bilikID"];?>" 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/batalBilikAdmin.php?bilikID=<?php echo $row["bilikID"]; ?>" 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>
					<?php
						}	
					?>
                    </tbody>
              </table>  
              <!-- End Table with stripped rows -->
            </div>
          </div>

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

  </main><!-- End #main -->
  
  <main id="main" class="main"><!-- senarai menunggu -->

    <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 (DARI-HINGGA)</th>
						<th scope="col">TAJUK MESYUARAT/PERBINCANGAN</th>
                        <th scope="col">JENIS BILIK</th>
                        <th scope="col">NAMA PEMOHON</th>						
                      </tr>
                    </thead>
                    <tbody>
					<?php
					
					$no=0;
					while($row2 = mysqli_fetch_array($result2))
					{
						$no ++;
						
						if(($row2['jenisBilik']=="BILIK MESYUARAT TINGKAT 7" || $row2['jenisBilik']=="BILIK MESYUARAT") && $row2['tarikh_mohon'] > $row2['tarikh'])
						{
					?>
                      <tr style="background-color:#A1D7FA; color:red ">
					  <?php
						}
						else if($row2['jenisBilik']=="BILIK PERBINCANGAN TINGKAT 8" && $row2['tarikh_mohon'] > $row2['tarikh'])
						{
						?>
                        <tr style="background-color:#9CEC98; color:red">
						<?php
						}
						else if($row2['jenisBilik']=="BILIK PERBINCANGAN TINGKAT 7" && $row2['tarikh_mohon'] > $row2['tarikh'])
						{
						?>
                        <tr style="background-color:#FAF5A1; color:red">
						<?php
						}
						else if($row2['jenisBilik']=="BILIK MESYUARAT TINGKAT 7" || $row2['jenisBilik']=="BILIK MESYUARAT" )
						{
						?>
                        <tr style="background-color:#A1D7FA;">
						<?php
						}
						else if($row2['jenisBilik']=="BILIK PERBINCANGAN TINGKAT 8" )
						{
						?>
                        <tr style="background-color:#9CEC98;">
						<?php
						}
						else 
						{
						?>
                        <tr style="background-color:#FAF5A1;">
						<?php
						}						
						?>
                        <th><?php echo $no; ?></th>
                        <td scope="row"><?php echo date("d-m-Y", strtotime($row2['tarikh'])); ?><?php if ($row2['tarikhHingga']==NULL){echo "";} else {echo '<label style="font-weight: bold;">&nbsp;HINGGA &nbsp;</label>'.date("d-m-Y", strtotime($row2['tarikhHingga']));}  ?></td>
                        <td><?php echo $row2['masaDari'] ?> - <?php echo $row2['masaHingga'] ?></td>
                        <th><?php echo $row2['nama_mesyuarat'] ?></th>
                        <td><?php echo $row2['jenisBilik'] ?></td>
						<td><?php echo $row2['nama_user'] ?></td>						
                      </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>
