<?php 

include('../dbconnect.php');
ob_start();
session_start();

if( !isset($_SESSION['user']) ) {
 header("Location: ../index.php");
 exit;
}

function mnltopst($date, $time){

    $convert = new DateTime($date.' '.$time, new DateTimeZone('Asia/Manila'));
    
    
    $convert->setTimezone(new DateTimeZone('America/Los_Angeles'));
    
    $datetime = $convert->format('m/d/Y h:i A');
    
    
    return ($datetime);
    
    
    
    
    }
    
    function psttomnl($date, $time){
    
      $convert = new DateTime($date.' '.$time, new DateTimeZone('America/Los_Angeles'));
      
      
      $convert->setTimezone(new DateTimeZone('Asia/Manila'));
      
      $datetime = $convert->format('m/d/Y h:i A');
      
      
      return ($datetime);
      
      
      
      
      }

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

  <head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Super Admin | Dashboard</title>

    <!-- Bootstrap core CSS-->
    <link href="../vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom fonts for this template-->
    <link href="../vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">

    <!-- Page level plugin CSS-->
    <link href="../vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">

    <!-- Custom styles for this template-->
        <link href="../css/sb-admin.css" rel="stylesheet">
    <link href="../css/style.css" rel="stylesheet">
    <link rel="icon" href="../images/logo.jpg" type="image/gif" sizes="16x16">



  </head>

  <body id="page-top">
	<div id="preloader">
   		<img src="../images/loaderS.gif" alt="processing..." height="150px" width="200px"/>
	</div>
    <div id="pageloader">
    <img src="../images/loaderS.gif" alt="processing..." height="150px" width="200px"/>
    </div>

 


    <?php include('uppernav.php')?>





      <!-- Sidebar -->
      
      <?php 
       $dashboard = "active";
      include('sidebar.php');
      ?>
      <div id="content-wrapper">

        <div class="container-fluid">

          <!-- Breadcrumbs-->
          <ol class="breadcrumb">
            <li class="breadcrumb-item">
              <a href="#"> Dashboard</a>
            </li>
            <li class="breadcrumb-item active">Overview</li>
          </ol>

          <div class="row">  
            <div class="col-lg-12">
                <table class="table table-hover table-bordered text-center">
                    <thead class="thead-dark">
                        <th>Sunday</th>
                        <th>Monday</th>
                        <th>Tuesday</th>
                        <th>Wednesday</th>
                        <th>Thursday</th>
                        <th>Friday</th>
                        <th>Saturday</th>
                    </thead>
                    <tbody>
                    <?php 
                    $weeks = array();
                    $year = date('Y');
                    
                    $mnlstart = array();
                    $mnldate = array();
                    $mnlendtime = array();
                    $headerdate =array();

                    $numofweeks ="SELECT * FROM schedule WHERE empid='ATV18-077' AND month='March'  GROUP BY week";
                    $numofweekres = mysqli_query($conn, $numofweeks);
                    $noofweeks = mysqli_num_rows($numofweekres);

                    while($numberofweeksrow = mysqli_fetch_assoc($numofweekres)){

                        $weeks[] = $numberofweeksrow['week'];

                    }

                    $header ="SELECT * FROM schedule WHERE empid='ATV18-077' AND month='March'";
                    $headerres = mysqli_query($conn, $header);
            
                    while($headerrow = mysqli_fetch_assoc($numofweekres)){

                        $headerdate[] = $headerrow['date'];

                    }



                    for($a=0; $a < count($weeks); $a++){
                        echo'<tr>';

                         $schedsql = "SELECT * FROM schedule WHERE empid='ATV18-077' AND week = '$weeks[$a]' AND year = '$year'  ";
                         $schedres = mysqli_query($conn, $schedsql);

                         

                         while($schedrow = mysqli_fetch_assoc($schedres)){
                          $mnlstart[] = $schedrow['starttime'];
                          $mnldate[] = $schedrow['date'];

                            echo '<td><b>'.date('m/d/Y', strtotime($schedrow['date'])).'</b>
                            <br>';

                            if($schedrow['starttime'] == 'OFF'){

                                echo 'OFF';


                            }else if($schedrow['starttime'] == 'HOLIDAY OFF'){
                                echo 'HOLIDAY OFF';
                            }else{

                                echo date('h:i A', strtotime($schedrow['starttime'])).'-'.date('h:i A', strtotime($schedrow['endtime']));
/* 
                                $PSTsched =  mnltopst($schedrow['date'], $schedrow['starttime']);

                                echo '<br>'.date('h:i A', strtotime($PSTsched));
 */

                            }

                           
                            
                           echo' </td>';

                            
                            
                            
                        
                         }


                         echo '</tr>';

                       
                        
                    }

                    for($b=0; $b < count($mnlstart); $b++){

                      if($mnlstart[$b] == 'OFF'){

                      }else{
                      

                        $startPST = mnltopst($mnldate[$b], $mnlstart[$b]).'<br>';

                      $PSTdate = date('Y-m-d', strtotime($startPST));


                      }

                      if($headerdate[$b] == $PSTdate[$b]){
                        echo $PSTdate[$b];
                      }
                      

                      

                     

                    }

                    mysqli_close($conn);



                    
                    
                    ?>
                    </tbody>
                </table>
      
                
            </div>
          
          </div>
   
          <!-- Icon Cards-->
      
        <!-- /.container-fluid -->

        <!-- Sticky Footer -->


      </div>
      <!-- /.content-wrapper -->

    </div>
    <!-- /#wrapper -->

    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
      <i class="fas fa-angle-up"></i>
    </a>

    <!-- Logout Modal-->
    <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
            <button class="close" type="button" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </div>
          <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
          <div class="modal-footer">
            <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
            <a class="btn btn-primary" href="login.html">Logout</a>
          </div>
        </div>
      </div>
    </div>

    <!-- Bootstrap core JavaScript-->
    <script src="../vendor/jquery/jquery.min.js"></script>
    <script src="../vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="../vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Page level plugin JavaScript-->
    <script src="../vendor/chart.js/Chart.min.js"></script>
    <script src="../vendor/datatables/jquery.dataTables.js"></script>
    <script src="../vendor/datatables/dataTables.bootstrap4.js"></script>

    <!-- Custom scripts for all pages-->
    <script src="../js/sb-admin.min.js"></script>

    <!-- Demo scripts for this page-->
    <script src="../js/demo/datatables-demo.js"></script>
    <script src="../js/demo/chart-area-demo.js"></script>

          <script language="javascript" type="text/javascript">
            $(document).ready(function(){
            $("form").on("submit", function(){
                $("#pageloader").fadeIn();
            });//submit

             $('#preloader').fadeOut();
            });//document ready



        </script>
</body>

</html>
