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

	date_default_timezone_set("Asia/Kuala_Lumpur");			
	$date=date('Y-m-d');

	$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.catatan, user.nama_user FROM `tempahan_bilik` JOIN `user` 
	ON tempahan_bilik.kad_pengenalan=user.kad_pengenalan WHERE tempahan_bilik.tarikh >= '$date' ORDER BY tempahan_bilik.tarikh ASC, tempahan_bilik.masaDari ";
	$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.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.tarikhDestinasiDari >= '$date' ORDER BY tempahan_kenderaan.tarikhDestinasiDari ASC, tempahan_kenderaan.masaDari";
	$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>
  .about{
	  overflow-x:auto;
	  background-color:white;
  }
  </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>
<!-- ======= Header ======= -->
  <header id="header" class="header fixed-top d-flex align-items-center">

    <div class="d-flex align-items-center justify-content-between">
      <a href="" class="logo d-flex align-items-center">
        <img src="assets/img/logo_mainpp.png" alt="">
        <span class="d-none d-lg-block" style="font-size:18px;">Sistem Tempahan</span>
      </a>
      <i class="bi bi-list toggle-sidebar-btn"></i>
    </div><!-- End Logo -->

    <!-- ======= tambahan by fikri pptm ======= -->
    <nav class="header-nav ms-auto">
      <ul class="d-flex align-items-center">
        <li class="nav-item dropdown pe-3">
						<span>Hi, <?php echo $_SESSION["nama"]; ?></span>
        </li><!-- End Profile Nav -->
      </ul>
    </nav><!-- End Icons Navigation --> 

    <nav class="header-nav ms-auto">
      <ul class="d-flex align-items-center">
        <li class="nav-item dropdown pe-3">

			<a class="dropdown-item d-flex align-items-center" onclick="logout()">
				<i class="bi bi-box-arrow-right" ></i>
				<span>Log Keluar</span>
			</a>        
        </li><!-- End Profile Nav -->

      </ul>
    </nav><!-- End Icons Navigation -->      
    

  </header><!-- End Header -->
	<aside id="sidebar" class="sidebar">
		<ul class="sidebar-nav" id="sidebar-nav">
		  <li class="nav-item">
			<a class="nav-link collapsed" href="mainMenu.php">
			  <i class="bi bi-house-fill"></i>
			  <span>Menu Utama</span>
			</a>
		  </li><!-- End Dashboard Nav -->
		</ul>
	  </aside><!-- End Sidebar-->
	
<?php 

	if($row1['peranan_user']=="USER")
	{

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

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

    <section class="section dashboard" >

        <!-- Left side columns -->
        <div class="col-lg-12" >
          <div class="row">

            <!--Menu Bilik Mesyuarat-->
           <div class="col-xxl-4 col-md-6" >
               <a href="tempahanBilik/DashboardBilikMesyuarat.php"><div class="card info-card sales-card" style="background-color:#052090;">
                  <div class="d-flex align-items-center justify-content-center" >
						<center><h5 style="color:white">Tempahan<br>Bilik Mesyuarat/Perbincangan</h5></center>
                  </div>
              </div></a>
            </div><!-- End Bilik Mesyuarat -->

            <!--Menu Kenderaan-->
            <div class="col-xxl-4 col-md-6" >
              <a href="tempahanKenderaan/DashboardKenderaan.php"><div class="card info-card sales-card" style="background-color:#052090;">
                  <div class="d-flex align-items-center justify-content-center" >
						<h5 style="color:white">Tempahan<br>Kenderaan</h5>
                  </div>
              </div></a>
            </div><!-- End Kenderaan-->
    </section>       
			
	<div class="pagetitle">
	  <h1>Dashboard Utama</h1> 
	</div><!-- End Page Title -->
			
			<!-- Senarai Permohonan Bilik Mesyuarat -->
		<section class="about" id="about" >
		  <div class="row" >
			<div class="col-lg-12">
				  <h5 class="card-title">SENARAI PERMOHONAN BILIK MESYUARAT/PERBINCANGAN</h5>      
				  <!-- Table with stripped rows -->
				  <table class="table table-borderless" style="font-size:12px">
						<thead>
						  <tr style="background-color:#EAF1F9;">
							<th scope="col">TARIKH (DARI-HINGGA)</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">STATUS</th>
							<th scope="col">CATATAN</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")
							{
							?>
						  <tr style="background-color:#A1D7FA;">
						  <?php
							}
							else if($row['jenisBilik']=="BILIK PERBINCANGAN TINGKAT 8")
							{
							?>
							<tr style="background-color:#9CEC98;">
							<?php
							}
							else if($row['jenisBilik']=="BILIK PERBINCANGAN TINGKAT 7")
							{
							?>
							<tr style="background-color:#FAF5A1;">
							<?php
							}
							else if($row['jenisBilik']=="BILIK PERBINCANGAN TINGKAT 9(K)")
							{
							?>
							<tr style="background-color:#FFA38F;">
							<?php
							}
							else
							{
							?>
							<tr style="background-color:#EEADF6;">
							<?php
							}
							?>
							<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 date('h:i:s a', strtotime($row['masaDari'])) ?> - <?php echo date('h:i:s a', strtotime($row['masaHingga'])) ?></td>
							<th><?php echo $row['nama_mesyuarat'] ?></th>
							<td><?php echo $row['jenisBilik'] ?></td>
							<td><?php echo $row['nama_user'] ?></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>
						  </tr>
						  <?php
						}
						?>
						</tbody>
					  </table>
				  <!-- End Table with stripped rows -->

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

		<!-- Senarai Permohonan Kenderaan -->
        <section class="about" id="about" >
		  <div class="row" >
			<div class="col-lg-12">
				  <h5 class="card-title">SENARAI PERMOHONAN KENDERAAN</h5>  
				  <!-- Table with stripped rows -->
				  <table class="table table-borderless" style="font-size:12px">
						<thead>
						  <tr style="background-color:#EAF1F9;">
							<th scope="col">TARIKH</th>
							<th scope="col">MASA</th>
							<th scope="col">NAMA PEMOHON</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>
						  </tr>
						</thead>
						<tbody>
						<?php
						
						$no=0;
						$tarikhSemasa = '';
						$warnaTarikhSemasa = '#FFFFFF';
						while($row2 = mysqli_fetch_array($result2))
						{
							$no ++;
							$tarikhBaris = date('Y-m-d', strtotime($row2['tarikhDestinasiDari']));
							if ($tarikhBaris !== $tarikhSemasa)
							{
								$warnaTarikhSemasa = ($warnaTarikhSemasa === '#CFE8FF') ? '#FFFFFF' : '#CFE8FF';
								$tarikhSemasa = $tarikhBaris;
							}
							
							$pemandu_IC= $row2['pemanduID'];
							
							$sql3="SELECT nama_pemandu FROM pemandu where pemanduID='".$pemandu_IC."' ";
							$result3 = mysqli_query($conn,$sql3);
							$row3 = mysqli_fetch_array($result3);
							?>
							<tr style="background-color:<?php echo $warnaTarikhSemasa; ?>;">
							<td scope="row"><?php echo date("d-m-Y", strtotime($row2['tarikhDestinasiDari'])); ?><?php if ($row2['tarikhDestinasiHingga']==NULL){echo "";} else {echo '<label style="font-weight: bold;">&nbsp;HINGGA &nbsp;</label>'.date("d-m-Y", strtotime($row2['tarikhDestinasiHingga']));}  ?></td>
							<td><?php echo date('h:i:s a', strtotime($row2['masaDari'])) ?> - <?php echo date('h:i:s a', strtotime($row2['masaHingga'])) ?></td>
							<td><?php echo $row2['nama_user'] ?></td>
							<th><?php echo $row2['nama_penumpang'] ?></th>
							<td><?php echo $row2['destinasi'] ?></td>
							<?php
							if($pemandu_IC=="")
							{
							?>
							<td></td>
							<?php
							}
							else
							{
							?>
							<td><?php echo $row3['nama_pemandu'] ?></td>
							<?php
							}
							if ($row2['kenderaanID']=="")
							{
							?>
							<td></td>
							<?php
							}
							else
							{
							?>
							<td><?php echo $row2['kenderaanID'] ?></td>
							<?php					
							}
							if($row2['status']=='SEDANG DIPROSES')
							{
							?>
							<td><span class='badge bg-warning'><?php echo $row2['status'] ?></span></td>
							<?php
							}
							else if($row2['status']=="LULUS")
							{
							?>
							<td><span class='badge bg-success'><?php echo $row2['status'] ?></span></td>
							<?php
							}
							else
							{
							?>
							<td><span class='badge bg-danger'><?php echo $row2['status'] ?></span></td>
							<?php
							} 
							?>
							<td><?php echo $row2['catatan'] ?></td>
						  </tr>
						  <?php
						}
						?>
						</tbody>
					  </table>
				  <!-- End Table with stripped rows -->

				</div>
		  </div>
		</section><!-- Senarai Permohonan Kenderaan -->
          </div>
        </div><!-- End Left side columns -->
    

  </main><!-- End #main -->
<?php
	}
	else
	{

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

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

    <section class="section dashboard">

        <!-- Left side columns -->
        <div class="col-lg-12">
          <div class="row">

            <!--Menu Bilik Mesyuarat-->
           <div class="col-xxl-4 col-md-6" >
               <a href="tempahanBilik/DashboardBilikMesyuarat.php"><div class="card info-card sales-card" style="background-color:#052090;">
                  <div class="d-flex align-items-center justify-content-center" >
						<center><h5 style="color:white">Tempahan<br>Bilik Mesyuarat/Perbincangan</h5></center>
                  </div>
              </div></a>
            </div><!-- End Bilik Mesyuarat -->

            <!--Menu Kenderaan-->
            <div class="col-xxl-4 col-md-6" >
              <a href="tempahanKenderaan/DashboardKenderaan.php"><div class="card info-card sales-card" style="background-color:#052090;">
                  <div class="d-flex align-items-center justify-content-center" >
						<h5 style="color:white">Tempahan<br>Kenderaan</h5>
                  </div>
              </div></a>
            </div><!-- End Kenderaan-->
		   </div>
        </div><!-- End Left side columns -->
    </section>        
			
	<div class="pagetitle">
	  <h1>Dashboard</h1> 
	</div><!-- End Page Title -->
			
		<section class="about" id="about" >	<!-- Senarai Permohonan Bilik Mesyuarat -->
			<div class="row" >
              <div class="col-12">      
                  <h5 class="card-title">SENARAI PERMOHONAN BILIK MESYUARAT/PERBINCANGAN</h5>

                  <table class="table table-borderless" style="font-size:12px">
                    <thead>
                      <tr>
                        <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">STATUS</th>
                        <th scope="col">CATATAN</th>
                        <th scope="col">UBAHSUAI</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")
						{
						?>
						<tr style="background-color:#A1D7FA;">
						<?php
						}
						else if($row['jenisBilik']=="BILIK PERBINCANGAN TINGKAT 8")
						{
						?>
						<tr style="background-color:#9CEC98;">
						<?php
						}
						else if($row['jenisBilik']=="BILIK PERBINCANGAN TINGKAT 7")
						{
						?>
						<tr style="background-color:#FAF5A1;">
						<?php
						}
						else if($row['jenisBilik']=="BILIK PERBINCANGAN TINGKAT 9(K)")
						{
						?>
						<tr style="background-color:#FFA38F;">
						<?php
						}
						else
						{
						?>
						<tr style="background-color:#EEADF6;">
						<?php
						}
						?>
                        <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 date('h:i:s a', strtotime($row['masaDari'])) ?> - <?php echo date('h:i:s a', strtotime($row['masaHingga'])) ?></td>
                        <th><?php echo $row['nama_mesyuarat'] ?></th>
                        <td><?php echo $row['jenisBilik'] ?></td>
						<td><?php echo $row['nama_user'] ?></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>
						<td><a href="tempahanBilik/ubahsuaiKelulusanBilik.php?bilikID=<?php echo $row["bilikID"]; ?>"><center><i class="bi bi-pencil" ></i></center></a></td>					
					  </tr>
                      <?php
					}
					?>
                    </tbody>
                  </table>
				</div>
            </div><!-- Senarai Permohonan Bilik Mesyuarat -->
		</section>
		
		<!-- Senarai Permohonan Kenderaan -->
         <section class="about" id="about" >	<!-- Senarai Permohonan Bilik Mesyuarat -->
			<div class="row" style="background-color:white;">
            <div class="col-12">
                  <h5 class="card-title">SENARAI PERMOHONAN KENDERAAN</h5>

                  <table class="table table-borderless" style="font-size:12px">
                    <thead>
                      <tr>
                        <th scope="col">TARIKH</th>
                        <th scope="col">MASA</th>
						<th scope="col">NAMA PEMOHON</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>
                      </tr>
                    </thead>
                    <tbody>
					<?php
					
					$no=0;
					$tarikhSemasa = '';
					$warnaTarikhSemasa = '#FFFFFF';
					while($row2 = mysqli_fetch_array($result2))
					{
						$no ++;
						$tarikhBaris = date('Y-m-d', strtotime($row2['tarikhDestinasiDari']));
						if ($tarikhBaris !== $tarikhSemasa)
						{
							$warnaTarikhSemasa = ($warnaTarikhSemasa === '#CFE8FF') ? '#FFFFFF' : '#CFE8FF';
							$tarikhSemasa = $tarikhBaris;
						}
						
						$pemandu_IC= $row2['pemanduID'];
						
						$sql3="SELECT nama_pemandu FROM pemandu where pemanduID='".$pemandu_IC."' ";
						$result3 = mysqli_query($conn,$sql3);
						$row3 = mysqli_fetch_array($result3);
						?>
						<tr style="background-color:<?php echo $warnaTarikhSemasa; ?>;">
                        
                        <td scope="row"><?php echo date("d-m-Y", strtotime($row2['tarikhDestinasiDari'])); ?><?php if ($row2['tarikhDestinasiHingga']==NULL){echo "";} else {echo '<label style="font-weight: bold;">&nbsp;HINGGA &nbsp;</label>'.date("d-m-Y", strtotime($row2['tarikhDestinasiHingga']));}  ?></td>
                        <td><?php echo date('h:i:s a', strtotime($row2['masaDari'])) ?> - <?php echo date('h:i:s a', strtotime($row2['masaHingga'])) ?></td>
                        <td><?php echo $row2['nama_user'] ?></td>
                        <th><?php echo $row2['nama_penumpang'] ?></th>
                        <td><?php echo $row2['destinasi'] ?></td>
						<?php
						if($pemandu_IC=="")
						{
						?>
						<td></td>
						<?php
						}
						else
						{
						?>
						<td><?php echo $row3['nama_pemandu'] ?></td>
						<?php
						}
						if ($row2['kenderaanID']=="")
						{
						?>
						<td></td>
						<?php
						}
						else
						{
						?>
						<td><?php echo $row2['kenderaanID'] ?></td>
						<?php					
						}
						if($row2['status']=='SEDANG DIPROSES')
						{
						?>
						<td><span class='badge bg-warning'><?php echo $row2['status'] ?></span></td>
						<?php
						}
						else if($row2['status']=="LULUS")
						{
						?>
						<td><span class='badge bg-success'><?php echo $row2['status'] ?></span></td>
						<?php
						}
						else
						{
						?>
						<td><span class='badge bg-danger'><?php echo $row2['status'] ?></span></td>
						<?php
						} 
						?>
						<td><?php echo $row2['catatan'] ?></td>
						<td><a href="tempahanKenderaan/ubahsuaiKelulusanKenderaan.php?tempahanID=<?php echo $row2["tempahanID"]; ?>"><center><i class="bi bi-pencil" ></i></center></a></td>
                      </tr>
					  
                      <?php
					}
					?>
                    </tbody>
                  </table>

                </div>
			</div><!-- Senarai Permohonan Kenderaan -->
    </section>

  </main><!-- End #main -->
<?php
	}
?>
  <!-- ======= 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>
