<?php 

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

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


?>
<!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>EMS | View Schedule</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="schedule.php"> Schedule</a>
            </li>
            <li class="breadcrumb-item active">View Schedule</li>
          </ol>
          <h3>Employee Schedule</h3>
          <ul class="nav nav-tabs" id="myTab" role="tablist">
            <li class="nav-item">
              <a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Weekly </a>
            </li>
            <li class="nav-item">
              <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Monthly</a>
            </li>

          </ul>
         
          <div class="tab-content" id="myTabContent">
           
            <div class="tab-pane fade show active p-3" id="home" role="tabpanel" aria-labelledby="home-tab">

              <div class="row">
                <div class="col-lg-12">
                  <h5>Weekly Schedule</h5>
                </div>
                <div class="col-lg-12 form-inline py-2">
                  <button type="button" class="btn btn-primary" id="Bfilter"> <i class="fas fa-filter"></i> Filter</button> &nbsp
                  
                  <input type="week" id="week" class="form-control">&nbsp
                  <select name="team" id="team" class="form-control">
                    <?php 
                    $teamsql = "SELECT team FROM empdetails GROUP BY team";
                    $teamres = mysqli_query($conn, $teamsql);
                    while($teamrow = mysqli_fetch_assoc($teamres)){
                      echo'<option value="'.$teamrow['team'].'">'.$teamrow['team'].'</option>';

                    }
                    ?>
                  </select> &nbsp
                  <select name="tz" id="tz" class="form-control">
                    <option value="manila">Manila</option>
                    <option value="pacific">Pacific</option>
                  </select>
                </div>
                <div class="col-lg-12" id="schedtbl">
                </div>
              </div>

            </div>
            <div class="tab-pane fade p-3" id="profile" role="tabpanel" aria-labelledby="profile-tab">
                
              <div class="row">
                <div class="col-lg-12">
                  <h5>Monthly Schedule</h5>
                </div>
                <div class="col-lg-12 form-inline py-2">
                  <button type="button" class="btn btn-primary" id="monthlyfilter"> <i class="fas fa-filter"></i> Filter</button> &nbsp
                  
                  <input type="month" id="month" class="form-control">&nbsp
                  <select name="emp" id="emp" class="form-control">
                    <?php 
                    $teamsql = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid WHERE status = 'Active'";
                    $teamres = mysqli_query($conn, $teamsql);
                    while($teamrow = mysqli_fetch_assoc($teamres)){
                      echo'<option value="'.$teamrow['detailid'].'">'.$teamrow['detailid'].' '.$teamrow['firstname'].' '.$teamrow['surname'].'</option>';

                    }
                    ?>
                  </select> &nbsp
                  <select name="tzm" id="tzm" class="form-control">
                    <option value="manila">Manila</option>
                    <option value="pacific">Pacific</option>
                  </select>
                </div>
                <div class="col-lg-12" id="monthlytbl">
                </div>
              </div>
            
            </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();


             $("#Bfilter").on("click", function(){

            

               var week = $("#week").val();
               var team = $("#team").val();
               var timezone = $("#tz").val();

         
           
               $.ajax({

                 url: "loadviewsched.php",
                 type: "POST",
                 data: {
                   "Bfilter" : 1,
                   "week" : week,
                   "team" : team,
                   "timezone" : timezone
                 },
                 success: function(response){
                  

                   $("#schedtbl").html(response);

                
                 }

               });

             });

             $("#monthlyfilter").on("click", function(){
              

               var month = $("#month").val();
               var emp = $("#emp").val();
               var tzm = $("#tzm").val();


             
              $.ajax({

                url: "loadviewsched.php",
                type: "POST",
                data: {
                  "MF" : 1,
                  "month" : month,
                  "emp" : emp,
                  "tzm" : tzm
                },
                success: function(response){
                

                  $("#monthlytbl").html(response);



                }

              });


             });


            });//document ready



        </script>
</body>

</html>
