<?php
include ('../dbconnect.php');
ob_start();
session_start();
if (!isset($_SESSION['user']))
{
    header("Location: ../index.php");
    exit;
}

$empid = $_SESSION['user'];
$w = date('W');
$week = ltrim($w, '0');
$year = date('Y');
$month = date('F');
$getmonth = $_POST['month'];


$weeklysched = "Current Week Schedule";
if (isset($_POST['filterw']))
{

    $weekno = $_POST['weekno'];
    $date = $_POST['weekdate'];
    $week = $weekno;

    $weeklysched = "Week  " . $weekno . " Schedule";

}

?>
<!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>Team Head | 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">
    <style>
    .tableFixHead    { overflow-y: auto; ; }
.tableFixHead th { position: sticky; top: 0; }

/* Just common table stuff. Really. */
table  { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 16px; }
th     { background:#eee; }

    </style>
  </head>
  <body id="page-top" onload=display_ct();>
    <?php include ('uppernav.php') ?>
    <!-- Sidebar -->
    <?php
$tools = "active";
$schedule = "active";
include ('sidebar.php');
?>
    <div id="content-wrapper">
      <div class="container-fluid">
        <!-- Breadcrumbs-->
        <ol class="breadcrumb">
          <li class="breadcrumb-item active">Schedule
          </li>
        </ol>
            <?php 
            $style="style='display: block' ";
            ?>
        <div class="text-right"><a href="updatesched.php?teamtab=<?php echo $style?>" class="btn btn-primary btn-sm"><i class="fas fa-edit"></i> Edit Schedule</a></div>

        <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"> <i class="fas fa-user"> </i> My Schedule & Attendance</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"> <i class="fas fa-users"> </i> Team Schedule & Attendance</a>
        </li>

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

            <div class="col-lg-12 col-sm-12 col-md-12">
              <div class="row">
                <div class="col-lg-6 col-sm-12 col-md-12">
                  <h5>Schedule 
                  </h5>
        
                  
                </div>
                <div class="col-lg-6 col-sm-12 col-md-12">
                  <h5>Attendance
                  </h5>
            
                </div>
                <!-- FILTER WEEKLY  -->
                <div class="col-lg-12 col-sm-12 col-md-12 form-inline">
              
                
                  <form method="post" enctype="multipart/form-data">  
              
                      <button type="submit" class="btn btn-primary btn-sm" name="filterw" > <i class='fas fa-filter'></i> Filter </button> &nbsp



            
              
                          <?php
                            $getyear = $_GET['year'];
                            if (empty($getyear))
                            {

                                $getyear = $year;
                            }

                            $qt = "SELECT * FROM schedule  WHERE year='$getyear' GROUP BY week ORDER BY date ASC ";
                            $rt = mysqli_query($conn, $qt);
                            echo "<select name='weekno' class='form-control form-control-sm' required>";
                            echo "<option value='' disabled selected> Week </option>";

                            while ($r = mysqli_fetch_array($rt))
                            {
                                $month = $r['month'];
                                if ($weekno == $r['week'] || date('W') == $r['week'])
                                {
                                    echo "<option value='" . $r['week'] . "' selected='selected'>Week  " . $r['week'] . " - " . date('F, j Y', strtotime($r['date'])) . "</option>";

                                }
                                else
                                {
                                    echo "<option value='" . $r['week'] . "' >Week  " . $r['week'] . " - " . date('F, j Y', strtotime($r['date'])) . "</option>";

                                }

                            }
                            echo "</select>";

                            ?>

                              <select name="time" id="time" onchange="schedpst()" class="form-control form-control-sm">
                              <option value="manila" selected>Manila</option>
                              <option value="pacific">Pacific</option>
                              
                              </select>

                            
                
                      <br>
                    
                  </form>
                
                </div>
                <!-- TABLE WEEKLY -->
                <div class="col-lg-6 col-sm-12 col-md-12" style="padding: 10px;" >
                    <!-- SCHEDULE TABLE MANILA TIME  -->
                    <table class="table table-sm table-bordered " id="scheduleweekly" >
                      <thead class="thead-dark">
                        <tr>
                          <?php

                          $leavedates = array();
                          $scheddate = array();

                          $leavesql = "SELECT * FROM `leave` WHERE status='3' AND empid = '$empid' ORDER BY datefrom ASC";
                          $lresult = mysqli_query($conn, $leavesql);
                          while ($lrow = mysqli_fetch_assoc($lresult))
                          {
                              $leavedates[] = $lrow['datefrom'];

                          }

                          $query = "SELECT * FROM schedule WHERE week='$week'   AND year='$getyear' AND empid='$empid'  ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') LIMIT 7";
                          $result = mysqli_query($conn, $query);
                          if (mysqli_num_rows($result) > 0)
                          {
                              while ($row = mysqli_fetch_assoc($result))
                              {
                                  echo '<th style="text-align: Center">' . $row['day'] . '<br/>' . date('m/d/Y', strtotime($row['date'])) . ' </th> ';
                              }
                          }
                          ?>
                        </tr>
                      </thead>
                      <tbody>
                        <?php
                          $query = "SELECT * FROM schedule WHERE week='$week'   AND year='$getyear' AND empid='$empid'  ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') LIMIT 7";
                          $result = mysqli_query($conn, $query);
                          if (mysqli_num_rows($result) > 0)
                          {

                              $a = 0;
                              while ($row = mysqli_fetch_assoc($result))
                              {

                                  if ($row['starttime'] == 'OFF')
                                  {
                                      echo ' <td style="text-align:center">';
                                      echo ' <span class="text-danger">OFF </span> </td>';
                                  }
                                  else if ($row['starttime'] == 'HOLIDAY OFF')
                                  {
                                      echo ' <td style="text-align:center">';
                                      echo ' <span class="text-danger">HOLIDAY OFF </span> </td>';
                                  }
                                  else if ($row['idl'] != '')
                                  {
                                      $idl = $row['idl'];

                                      $leavequery = "SELECT * FROM `leave` WHERE idl='$idl' AND status='3' ";
                                      $leaveres = mysqli_query($conn, $leavequery);
                                      $leaverow = mysqli_fetch_assoc($leaveres);
                                      $duration = $leaverow['duration'];

                                      $dur = substr($duration, -2);

                                      
                                      if (mysqli_num_rows($leaveres) > 0)
                                      {

                                          if ($row['leaveduration'] == '0.5')
                                          {

                                              echo ' <td style="text-align:center">';
                                              echo ' <span class="text-danger">' . $leaverow['name'] . ' Halfday</span> </td>';

                                          }
                                          else
                                          {

                                              echo ' <td style="text-align:center">';
                                              echo ' <span class="text-danger">' . $leaverow['name'] . '  </span> </td>';

                                          }

                                      }
                                      else
                                      {

                                          echo '<td style="text-align:center">';
                                          $time = date("g:i A", strtotime($row['starttime']));
                                          echo $time;
                                          echo '</td>';

                                      }

                                  }

                                  else
                                  {
                                      echo '<td style="text-align:center">';
                                      $time = date("g:i A", strtotime($row['starttime']));
                                      echo $time;
                                      echo '</td>';
                                  }

                              }
                              $a++;

                          }
                          ?>
                      </tbody>
                    </table>


                    <!--SCHEDULE TABLE PST TIME  -->
                    <table class="table table-sm table-bordered" id="scheduleweeklypst" hidden >
                      <thead class="thead-dark">
                        <tr>
                          <?php

                        $leavedates = array();
                        $scheddate = array();

                        $leavesql = "SELECT * FROM `leave` WHERE status='3' AND empid = '$empid' ORDER BY datefrom ASC";
                        $lresult = mysqli_query($conn, $leavesql);
                        while ($lrow = mysqli_fetch_assoc($lresult))
                        {
                            $leavedates[] = $lrow['datefrom'];

                        }

                        $getst = "SELECT * FROM schedule WHERE  team='$team'  AND year='$getyear' AND empid='$empid' AND week='$week' AND starttime != 'OFF' AND starttime != 'HOLIDAY OFF' LIMIT 1"; //GET EMPLOYEE
                        $getstresult = mysqli_query($conn, $getst);


                        $getstr = mysqli_fetch_assoc($getstresult);
                        $pstst = $getstr['starttime'];

                        $query = "SELECT * FROM schedule WHERE week='$week'   AND year='$getyear' AND empid='$empid'  ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') LIMIT 7";
                        $result = mysqli_query($conn, $query);
                        if (mysqli_num_rows($result) > 0)
                        {
                            while ($row = mysqli_fetch_assoc($result))
                            {
                                echo '<th style="text-align: Center">' . $row['day'] . '<br/>' . date('m/d/Y', strtotime($row['date'])) . ' </th> ';
                            }
                        }
                        ?>
                        </tr>
                      </thead>
                      <tbody>

                        <?php
                          if (new DateTime($pstst) >= new DateTime('16:00') && new DateTime($pstst) <= new DateTime('23:59'))
                          {

                              $query = "SELECT * FROM schedule WHERE week='$week'   AND year='$getyear' AND empid='$empid'  ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') LIMIT 7";
                          }
                          else if (new DateTime($pstst) >= new DateTime('00:00') && new DateTime($pstst) <= new DateTime('15:59'))
                          {

                              $query = "SELECT * FROM schedule WHERE week='$week'   AND year='$getyear' AND empid='$empid'  ORDER BY FIELD(day, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday') LIMIT 7";

                          }
                          $result = mysqli_query($conn, $query);
                          if (mysqli_num_rows($result) > 0)
                          {

                              $a = 0;
                              while ($row = mysqli_fetch_assoc($result))
                              {

                                  $day = $row['day'];
                                  $dates = $row['date'];
                                  $start = $row['starttime'];

                                  $GMT = 'GMT+8';
                                  $parameter = $day . ', ' . $dates . ' ' . $start . ' ' . $GMT;

                                  if ($row['starttime'] == 'OFF')
                                  {
                                      echo ' <td style="text-align:center">';
                                      echo ' <span class="text-danger">OFF </span> </td>';
                                  }
                                  else if ($row['starttime'] == 'HOLIDAY OFF')
                                  {
                                      echo ' <td style="text-align:center">';
                                      echo ' <span class="text-danger">HOLIDAY OFF </span> </td>';
                                  }
                                  else if ($row['idl'] != '')
                                  {
                                      $idl = $row['idl'];

                                      $leavequery = "SELECT * FROM `leave` WHERE idl='$idl' AND status='3' ";
                                      $leaveres = mysqli_query($conn, $leavequery);
                                      $leaverow = mysqli_fetch_assoc($leaveres);
                                      $duration = $leaverow['duration'];

                                      $dur = substr($duration, -2);

                                      if (mysqli_num_rows($leaveres) > 0)
                                      {

                                          if ($row['leaveduration'] == '0.5')
                                          {

                                              echo ' <td style="text-align:center">';
                                              echo ' <span class="text-danger">' . $leaverow['name'] . ' Halfday</span> </td>';

                                          }
                                          else
                                          {

                                              echo ' <td style="text-align:center">';
                                              echo ' <span class="text-danger">' . $leaverow['name'] . '  </span> </td>';

                                          }

                                      }
                                      else
                                      {

                                          $tz = new DateTimeZone('America/Los_Angeles');
                                          $PST = new DateTime($parameter);
                                          $PST->setTimezone($tz);

                                          echo '<td style="text-align:center">';
                                          $time = $PST->format('g:i A');
                                          echo $time;
                                          echo '</td>';

                                      }

                                  }

                                  else
                                  {
                                      $tz = new DateTimeZone('America/Los_Angeles');
                                      $PST = new DateTime($parameter);
                                      $PST->setTimezone($tz);

                                      echo '<td style="text-align:center">';
                                      $time = $PST->format('g:i A');
                                      echo $time;
                                      echo '</td>';

                                  }

                              }
                              $a++;

                          }
                          ?>
                      </tbody>
                    </table><!-- END SCHEDULE WEEKLY PST -->





                    <hr>
                </div>



                <!-- TABLE ATTENDANCE WEEKLY  -->
                <div class="col-lg-6 col-sm-12 col-md-12" style="padding: 10px;">
                
              
                  <table class="table table-sm table-bordered" id="attendanceweekly">
                    <thead class="thead-dark">
                      <tr>
                        <?php

                        $leavedates = array();
                        $scheddate = array();
                        $headerdate = array();

                        $leavesql = "SELECT * FROM `leave` WHERE status='3' AND empid = '$empid' ORDER BY datefrom ASC";
                        $lresult = mysqli_query($conn, $leavesql);
                        while ($lrow = mysqli_fetch_assoc($lresult))
                        {
                            $leavedates[] = $lrow['datefrom'];

                        }

                        $query = "SELECT * FROM schedule WHERE week='$week'   AND year='$getyear' AND empid='$empid'  ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') LIMIT 7";
                        $result = mysqli_query($conn, $query);
                        if (mysqli_num_rows($result) > 0)
                        {
                            while ($row = mysqli_fetch_assoc($result))
                            {
                                echo '<th style="text-align: Center">' . $row['day'] . '<br/>' . date('m/d/Y', strtotime($row['date'])) . ' </th> ';

                                $headerdate[] = date('m/d/Y', strtotime($row['date']));
                            }
                        }
                        ?>
                                              </tr>
                                            </thead>
                                            <tbody>
                                              <?php
                        $query = "SELECT * FROM schedule WHERE week='$week'   AND year='$getyear' AND empid='$empid'  ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') LIMIT 7";
                        $result = mysqli_query($conn, $query);
                        if (mysqli_num_rows($result) > 0)
                        {

                            $a = 0;
                  
                                    

         


                            while ($row = mysqli_fetch_assoc($result))
                            {







                                if ($row['starttime'] == 'OFF')
                                {
                                    echo ' <td style="text-align:center">';
                                    echo ' <span class="text-danger">OFF </span> </td>';
                                }
                                else if ($row['starttime'] == 'HOLIDAY OFF')
                                {
                                    echo ' <td style="text-align:center">';
                                    echo ' <span class="text-danger">HOLIDAY OFF </span> </td>';
                                }
                                else if ($row['idl'] != '')
                                {
                                    $idl = $row['idl'];

                                    $leavequery = "SELECT * FROM `leave` WHERE idl='$idl' AND status='3' ";
                                    $leaveres = mysqli_query($conn, $leavequery);
                                    $leaverow = mysqli_fetch_assoc($leaveres);
                                    $duration = $leaverow['duration'];



                                    


                                    $dur = substr($duration, -2);

                                    if (mysqli_num_rows($leaveres) > 0)
                                    {

                                        if ($row['leaveduration'] == '0.5')
                                        {

                                            echo ' <td style="text-align:center">';
                                            echo ' <span class="text-danger">' . $leaverow['name'] . ' Halfday</span> </td>';

                                        }
                                        else
                                        {

                                            echo ' <td style="text-align:center">';
                                            echo ' <span class="text-danger">' . $leaverow['name'] . '  </span> </td>';

                                        }

                                    }
                                    else
                                    {

                                        echo '<td style="text-align:center">';
                                        $time = date("g:i A", strtotime($row['starttime']));
                                        echo $utilrow['starttime'];
                                        echo '</td>';

                                    }

                                }

                                else
                                {
                                    
                                 $dte = $row['date'];
                                 $dy = $row['day'];
                                 $tm = $row['starttime'];
                                 $dystr = date('l', strtotime($dte));


                                 $GMT = 'GMT+8';

                               $pmtr = $dystr.', '.$dte.' '.$tm.' '.$GMT;

                               $tz = new DateTimeZone('America/Los_Angeles');
                               $PST = new DateTime($pmtr);
                               $PST->setTimezone($tz);

                               $hdate = $PST->format('m/d/Y');

                              $util = "SELECT * FROM `tbl_login` WHERE empid='$empid' AND date='$hdate'";
                               $utilres = mysqli_query($conn, $util);
                               $utilrow = mysqli_fetch_assoc($utilres);

                               $utildate = $utilrow['date'];
                               $utilday = date('l', strtotime($utildate));
                               $utiltime = $utilrow['timein'];
                          

                               
                               if(empty($utildate)){

                                echo '<td style="text-align:center">';
                                $time = date("g:i A", strtotime($row['starttime']));
                               // echo $hdate = $PSTph->format('g:i A');

                                echo '--- </td>';



                               }else{

                                $pmtrph = $utildate.' '.$utiltime.' '.$utilgmt;


                                $tzph = new DateTimeZone('Asia/Manila');
                                $PSTph = new DateTime($pmtrph);
                                $PSTph->setTimezone($tzph);
 

                                echo '<td style="text-align:center">';
                                $time = date("g:i A", strtotime($row['starttime']));
                                echo $hdate = $PSTph->format('g:i A');

                                echo '</td>';
                                
                            
                               }



                                }

                            }
                            $a++;

                        }
                        ?>
                    </tbody>
                  </table>


                                    <!--SCHEDULE TABLE PST TIME  -->
                  <table class="table table-sm table-bordered" id="attendanceweeklypst" hidden>
                    <thead class="thead-dark">
                      <tr>
                        <?php

                          $leavedates = array();
                          $scheddate = array();

                          $leavesql = "SELECT * FROM `leave` WHERE status='3' AND empid = '$empid' ORDER BY datefrom ASC";
                          $lresult = mysqli_query($conn, $leavesql);
                          while ($lrow = mysqli_fetch_assoc($lresult))
                          {
                              $leavedates[] = $lrow['datefrom'];

                          }

                          $getst = "SELECT * FROM schedule WHERE  team='$team'  AND year='$getyear' AND empid='$empid' AND week='$week' AND starttime != 'OFF' AND starttime
                           != 'HOLIDAY OFF' LIMIT 1"; //GET EMPLOYEE
                          $getstresult = mysqli_query($conn, $getst);

                          $getstr = mysqli_fetch_assoc($getstresult);
                          $pstst = $getstr['starttime'];

                          $query = "SELECT * FROM schedule WHERE week='$week'   AND year='$getyear' AND empid='$empid'  ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') LIMIT 7";
                          $result = mysqli_query($conn, $query);
                          if (mysqli_num_rows($result) > 0)
                          {
                              while ($row = mysqli_fetch_assoc($result))
                              {
                                  echo '<th style="text-align: Center">' . $row['day'] . '<br/>' . date('m/d/Y', strtotime($row['date'])) . ' </th> ';
                              }
                          }
                          ?>
                                                </tr>
                                              </thead>
                                              <tbody>

                                                <?php
                          if (new DateTime($pstst) >= new DateTime('16:00') && new DateTime($pstst) <= new DateTime('23:59'))
                          {

                              $query = "SELECT * FROM schedule WHERE week='$week'   AND year='$getyear' AND empid='$empid'  ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') LIMIT 7";
                          }
                          else if (new DateTime($pstst) >= new DateTime('00:00') && new DateTime($pstst) <= new DateTime('15:59'))
                          {

                              $query = "SELECT * FROM schedule WHERE week='$week'   AND year='$getyear' AND empid='$empid'  ORDER BY FIELD(day, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday') LIMIT 7";

                          }
                          $result = mysqli_query($conn, $query);
                          if (mysqli_num_rows($result) > 0)
                          {

                              $a = 0;
                              while ($row = mysqli_fetch_assoc($result))
                              {

                                  $day = $row['day'];
                                  $dates = $row['date'];
                                  $start = $row['starttime'];

                                  $GMT = 'GMT+8';
                                  $parameter = $day . ', ' . $dates . ' ' . $start . ' ' . $GMT;


                                  $hdate = date('m/d/Y', strtotime($row['date']));
                                  $util = "SELECT * FROM `tbl_login` WHERE empid='$empid' AND date='$hdate'";
                                   $utilres = mysqli_query($conn, $util);
                                   $utilrow = mysqli_fetch_assoc($utilres);
                                    $login = $utilrow['timein'];
   

                                  if ($row['starttime'] == 'OFF')
                                  {
                                      echo ' <td style="text-align:center">';
                                      echo ' <span class="text-danger">OFF </span> </td>';
                                  }
                                  else if ($row['starttime'] == 'HOLIDAY OFF')
                                  {
                                      echo ' <td style="text-align:center">';
                                      echo ' <span class="text-danger">HOLIDAY OFF </span> </td>';
                                  }
                                  else if ($row['idl'] != '')
                                  {
                                      $idl = $row['idl'];

                                      $leavequery = "SELECT * FROM `leave` WHERE idl='$idl' AND status='3' ";
                                      $leaveres = mysqli_query($conn, $leavequery);
                                      $leaverow = mysqli_fetch_assoc($leaveres);
                                      $duration = $leaverow['duration'];

                                      $dur = substr($duration, -2);

                                      if (mysqli_num_rows($leaveres) > 0)
                                      {

                                          if ($row['leaveduration'] == '0.5')
                                          {

                                              echo ' <td style="text-align:center">';
                                              echo ' <span class="text-danger">' . $leaverow['name'] . ' Halfday</span> </td>';

                                          }
                                          else
                                          {

                                              echo ' <td style="text-align:center">';
                                              echo ' <span class="text-danger">' . $leaverow['name'] . '  </span> </td>';

                                          }

                                      }
                                      else
                                      {


                                        $dte = $row['date'];
                                        $dy = $row['day'];
                                        $tm = $row['starttime'];
                                        $dystr = date('l', strtotime($dte));
       
       
                                        $GMT = 'GMT+8';
       
                                      $pmtr = $dystr.', '.$dte.' '.$tm.' '.$GMT;
       
                                      $tz = new DateTimeZone('America/Los_Angeles');
                                      $PST = new DateTime($pmtr);
                                      $PST->setTimezone($tz);
       
                                      $hdate = $PST->format('m/d/Y');
       
                                     $util = "SELECT * FROM `tbl_login` WHERE empid='$empid' AND date='$hdate'";
                                      $utilres = mysqli_query($conn, $util);
                                      $utilrow = mysqli_fetch_assoc($utilres);
       
                                      $utildate = $utilrow['date'];
                                      $utilday = date('l', strtotime($utildate));
                                      $utiltime = $utilrow['timein'];
                                 
       
                                      
                                      if(empty($utildate)){
       
                                       echo '<td style="text-align:center">';
                                       //$time = date("g:i A", strtotime($row['starttime']));
                                      // echo $hdate = $PSTph->format('g:i A');
       
                                       echo '--- </td>';
       
       
       
                                      }else{
       
    
        
       
                                       echo '<td style="text-align:center">';
                                       //$time = date("g:i A", strtotime($row['starttime']));
                                       echo $utilrow['starttime'];;
       
                                       echo '</td>';
                                       
                                   
                                      }
                                      

                                      }

                                  }

                                  else
                                  {

                                    $dte = $row['date'];
                                    $dy = $row['day'];
                                    $tm = $row['starttime'];
                                    $dystr = date('l', strtotime($dte));
   
   
                                    $GMT = 'GMT+8';
   
                                  $pmtr = $dystr.', '.$dte.' '.$tm.' '.$GMT;
   
                                  $tz = new DateTimeZone('America/Los_Angeles');
                                  $PST = new DateTime($pmtr);
                                  $PST->setTimezone($tz);
   
                                  $hdate = $PST->format('m/d/Y');
   
                                 $util = "SELECT * FROM `tbl_login` WHERE empid='$empid' AND date='$hdate'";
                                  $utilres = mysqli_query($conn, $util);
                                  $utilrow = mysqli_fetch_assoc($utilres);
   
                                  $utildate = $utilrow['date'];
                                  $utilday = date('l', strtotime($utildate));
                                  $utiltime = $utilrow['timein'];
                             
   
                                  
                                  if(empty($utildate)){
   
                                   echo '<td style="text-align:center">';
                                   //$time = date("g:i A", strtotime($row['starttime']));
                                  // echo $hdate = $PSTph->format('g:i A');
   
                                   echo '--- </td>';
   
   
   
                                  }else{
   

    
   
                                   echo '<td style="text-align:center">';
                                   //$time = date("g:i A", strtotime($row['starttime']));
                                   echo $utilrow['starttime'];;
   
                                   echo '</td>';
                                   
                               
                                  }

                                  }

                              }
                              $a++;

                          }
                          ?>
                    </tbody>
                  </table><!-- END SCHEDULE WEEKLY PST -->



                  <hr>
                </div>
                
                <!-- FILTER MONTHLY  -->
                <div class="col-sm-12 form-inline">
                    <form method="post" enctype="multipart/form-data">  
                      <button type="submit" class="btn btn-primary btn-sm" name="filterm"> <i class='fas fa-filter'></i> Filter </button> &nbsp

                        
                        

                      

                                <?php

                                $qt = "SELECT * FROM schedule  WHERE year='$year' GROUP BY month ORDER BY FIELD(month, 'January', 'February', 'March', 'April','May', 'June', 'July','August','September','October','November','December'); ";
                                $rt = mysqli_query($conn, $qt);
                                echo "<select name='month' class='form-control form-control-sm' required>";
                                echo "<option value='' disabled selected> Month </option>";

                                while ($r = mysqli_fetch_array($rt))
                                {
                                    $month = $r['month'];
                                    if ($getmonth == $r['month'] || date('F') == $r['month'])
                                    {
                                        echo "<option value='" . $r['month'] . "' selected='selected'>" . $r['month'] . "</option>";

                                    }
                                    else
                                    {
                                        echo "<option value='" . $r['month'] . "' >" . $r['month'] . "</option>";
                                    }

                                }
                                echo "</select>";
                                ?>

                              <select name="timezone" id="timezone" onchange="attpst()" class="form-control form-control-sm">
                              <option value="manila" selected>Manila</option>
                              <option value="pacific">Pacific</option>
                              
                              </select>


                      

                    </form>

                    

                </div>

                <!-- TABLE MONTHLY  -->
                <div class="col-lg-6 col-sm-12 col-md-12" > 
                  <br>
                  <table class="table table-bordered" id="schedulemanilamonthtable" name="manilamonthtable" >
                    <thead class="thead-dark">
                      <tr>
                        
                  
                        <th scope="col" style="text-align: center"> Sunday</th>
                        <th scope="col" style="text-align: center">Monday </th>
                        <th scope="col" style="text-align: center">Tuesday </th>
                        <th scope="col" style="text-align: center"> Wednesday</th>
                        <th scope="col" style="text-align: center">Thursday </th>
                        <th scope="col" style="text-align: center">Friday </th>  
                        <th scope="col" style="text-align: center">Saturday </th>                  
                      </tr>
                    </thead>
                    <tbody>
            
                    
                    
                        <?php
                          $month = date('F');
                          if (isset($_POST['filterm']))
                          {

                              $month = $getmonth;
                          }

                          $getnoweeks = "SELECT * FROM `schedule` WHERE year='$year' AND empid = '$empid' AND month='$month' GROUP BY week ORDER BY week ";
                          $getnres = mysqli_query($conn, $getnoweeks);
                          $noofweeks = mysqli_num_rows($getnres);
                          $getweekno = mysqli_fetch_assoc($getnres);
                          $weeks = $getweekno['week'];

                          //GET EMPLOYEE NAME


                          for ($i = 1;$i <= $noofweeks;$i++)
                          {

                              $query = "SELECT * FROM schedule WHERE month='$month'  AND year='$year' AND empid='$empid' and week='$weeks' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                              $result = mysqli_query($conn, $query);

                              if (mysqli_num_rows($result) > 0)
                              {

                                  echo '<tr>';

                                  while ($row = mysqli_fetch_assoc($result))
                                  {

                                      if ($empnamerow['status'] == 'Inactive')
                                      {

                                          echo ' <td style="text-align:center">';
                                          echo ' <span class="text-danger">--</span> </td>';

                                      }
                                      else
                                      {
                                          if ($row['starttime'] == 'OFF')
                                          {
                                              echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                              echo ' <span class="text-danger">OFF </span></td>';
                                          }
                                          else if ($row['starttime'] == 'HOLIDAY OFF')
                                          {
                                              echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                              echo ' <span class="text-danger" >HOLIDAY OFF </span></td>';
                                          }
                                          else if ($row['idl'] != '')
                                          {
                                              $idl = $row['idl'];

                                              $leavequery = "SELECT * FROM `leave` WHERE idl='$idl' AND status='3' ";
                                              $leaveres = mysqli_query($conn, $leavequery);
                                              $leaverow = mysqli_fetch_assoc($leaveres);
                                              $duration = $leaverow['duration'];

                                              $dur = substr($duration, -2);

                                              if (mysqli_num_rows($leaveres) > 0)
                                              {

                                                  if ($row['leaveduration'] == '0.5')
                                                  {

                                                      echo ' <td style="text-align:center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                                      echo ' <span class="text-danger">' . $leaverow['name'] . '<br/> Halfday</span> </td>';

                                                  }
                                                  else
                                                  {

                                                      echo ' <td style="text-align:center"> <span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                                      echo ' <span class="text-danger">' . $leaverow['name'] . '  </span> </td>';

                                                  }

                                              }
                                              else
                                              {

                                                  echo '<td style="text-align:center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';

                                                  $time = date("g:i A", strtotime($row['starttime']));
                                                  echo $time;
                                                  echo '</td>';

                                              }

                                          }
                                          else
                                          {
                                              echo '<td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                              echo '' . date("g:i A", strtotime($row['starttime'])) . ' <br/>';

                                              // echo   ''.date("g:i A", strtotime($timestart)).' - '.date("g:i A", strtotime($timeend)).'</td>';
                                              
                                          }

                                      }

                                  }
                                  echo '</tr>';
                              }
                              else
                              {

                              }
                              echo '<tr>';

                              $weeks++;

                          }

                          ?>
                      
                
                    </tbody>
                  </table>

                  <table class="table table-bordered" id="pstschedulemonthtable"  hidden>
                    <thead class="thead-dark">
                      <tr>
                        
                  
                        <th scope="col" style="text-align: center"> Sunday</th>
                        <th scope="col" style="text-align: center">Monday </th>
                        <th scope="col" style="text-align: center">Tuesday </th>
                        <th scope="col" style="text-align: center"> Wednesday</th>
                        <th scope="col" style="text-align: center">Thursday </th>
                        <th scope="col" style="text-align: center">Friday </th>  
                        <th scope="col" style="text-align: center">Saturday </th>                  
                      </tr>
                    </thead>
                    <tbody>
            
                    
                    
                      <?php
                        $month = date('F');
                        if (isset($_POST['filterm']))
                        {

                            $month = $getmonth;
                        }

                        $getnoweeks = "SELECT * FROM `schedule` WHERE year='$year' AND empid = '$empid' AND month='$month' GROUP BY week";
                        $getnres = mysqli_query($conn, $getnoweeks);
                        $noofweeks = mysqli_num_rows($getnres);
                        $getweekno = mysqli_fetch_assoc($getnres);
                        $weeks = $getweekno['week'];

                        $pstdate = "SELECT * FROM schedule WHERE month='$getmonth'  AND year='$year' AND empid='$empid'  AND starttime != 'OFF' AND starttime != 'HOLIDAY OFF' GROUP BY week";

                        $getstresult = mysqli_query($conn, $pstdate);

                        while ($getpst = mysqli_fetch_assoc($getstresult))
                        {
                            $pstmonthst[] = $getpst['starttime'];

                        }

                        //GET EMPLOYEE NAME


                        for ($i = 0;$i < $noofweeks;$i++)
                        {
                           

                            if (new DateTime($pstmonthst[$i]) >= new DateTime('16:00') && new DateTime($pstmonthst[$i]) <= new DateTime('23:59'))
                            {

                                $query = "SELECT * FROM schedule WHERE month='$month'  AND year='$year' AND empid='$empid' and week='$weeks' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";
                                $datesql = "SELECT * FROM schedule WHERE month='$month'  AND year='$year' AND empid='$empid' and week='$weeks' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                            }
                            else if (new DateTime($pstmonthst[$i]) >= new DateTime('00:00') && new DateTime($pstmonthst[$i]) <= new DateTime('15:59'))
                            {

                                $query = "SELECT * FROM schedule WHERE month='$month'  AND year='$year' AND empid='$empid' and week='$weeks' ORDER BY FIELD(day,  'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday') ";
                                $datesql = "SELECT * FROM schedule WHERE month='$month'  AND year='$year' AND empid='$empid' and week='$weeks' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                            }

                            $result = mysqli_query($conn, $query);
                            $dateresult = mysqli_query($conn, $datesql);

                            if (mysqli_num_rows($result) > 0)
                            {

                                echo '<tr>';

                                while (($row = mysqli_fetch_assoc($result)) && ($daterow = mysqli_fetch_assoc($dateresult)))
                                {

                                    if ($empnamerow['status'] == 'Inactive')
                                    {

                                        echo ' <td style="text-align:center">';
                                        echo ' <span class="text-danger">--</span> </td>';

                                    }
                                    else
                                    {
                                        if ($row['starttime'] == 'OFF')
                                        {
                                            echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($daterow['date'])) . ' </span><br/>';
                                            echo ' <span class="text-danger">OFF </span></td>';
                                        }
                                        else if ($row['starttime'] == 'HOLIDAY OFF')
                                        {
                                            echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($daterow['date'])) . ' </span><br/>';
                                            echo ' <span class="text-danger" >HOLIDAY OFF </span></td>';
                                        }
                                        else if ($row['idl'] != '')
                                        {
                                            $idl = $row['idl'];

                                            $leavequery = "SELECT * FROM `leave` WHERE idl='$idl' AND status='3' ";
                                            $leaveres = mysqli_query($conn, $leavequery);
                                            $leaverow = mysqli_fetch_assoc($leaveres);
                                            $duration = $leaverow['duration'];

                                            $dur = substr($duration, -2);

                                            if (mysqli_num_rows($leaveres) > 0)
                                            {

                                                if ($row['leaveduration'] == '0.5')
                                                {

                                                    echo ' <td style="text-align:center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($daterow['date'])) . ' </span><br/>';
                                                    echo ' <span class="text-danger">' . $leaverow['name'] . '<br/> Halfday</span> </td>';

                                                }
                                                else
                                                {

                                                    echo ' <td style="text-align:center"> <span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($daterow['date'])) . ' </span><br/>';
                                                    echo ' <span class="text-danger">' . $leaverow['name'] . '  </span> </td>';

                                                }

                                            }
                                            else
                                            {
                                                $day = $row['day'];
                                                $dates = $row['date'];
                                                $start = $row['starttime'];

                                                $GMT = 'GMT+8';
                                                $parameter = $day . ', ' . $dates . ' ' . $start . ' ' . $GMT;

                                                $tz = new DateTimeZone('America/Los_Angeles');
                                                $PST = new DateTime($parameter);
                                                $PST->setTimezone($tz);

                                                echo '<td style="text-align:center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($daterow['date'])) . ' </span><br/>';

                                                $time = $PST->format('g:i A');
                                                echo $time;
                                                echo '</td>';

                                            }

                                        }
                                        else
                                        {

                                            $day = $row['day'];
                                            $dates = $row['date'];
                                            $start = $row['starttime'];

                                            $GMT = 'GMT+8';
                                            $parameter = $day . ', ' . $dates . ' ' . $start . ' ' . $GMT;

                                            $tz = new DateTimeZone('America/Los_Angeles');
                                            $PST = new DateTime($parameter);
                                            $PST->setTimezone($tz);

                                            echo '<td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($daterow['date'])) . ' </span><br/>';
                                            $time = $PST->format('g:i A');
                                            echo $time;
                                            echo '</td>';

                                            // echo   ''.date("g:i A", strtotime($timestart)).' - '.date("g:i A", strtotime($timeend)).'</td>';
                                            
                                        }

                                    }

                                }
                                echo '</tr>';
                            }
                            else
                            {

                            }
                            echo '<tr>';

                            $weeks++;

                        }

                        ?>
                                              
                
                    </tbody>
                  </table>


                </div>




                <!-- TABLE ATTENDANCE MONTHLY   -->
                      
                <div class="col-lg-6 col-sm-12 col-md-12" > 
                  <br>
                  <table class="table table-bordered" id="manilaatt" name="manilaatt" >
                      <thead class="thead-dark">
                        <tr>
                          
                    
                          <th scope="col" style="text-align: center"> Sunday</th>
                          <th scope="col" style="text-align: center">Monday </th>
                          <th scope="col" style="text-align: center">Tuesday </th>
                          <th scope="col" style="text-align: center"> Wednesday</th>
                          <th scope="col" style="text-align: center">Thursday </th>
                          <th scope="col" style="text-align: center">Friday </th>  
                          <th scope="col" style="text-align: center">Saturday </th>                  
                        </tr>
                      </thead>
                      <tbody>
              
                      
                      
                        <?php
                          $month = date('F');
                          if (isset($_POST['filterm']))
                          {

                              $month = $getmonth;
                          }

                          $getnoweeks = "SELECT * FROM `schedule` WHERE year='$year' AND empid = '$empid' AND month='$month' GROUP BY week ORDER BY week ";
                          $getnres = mysqli_query($conn, $getnoweeks);
                          $noofweeks = mysqli_num_rows($getnres);
                          $getweekno = mysqli_fetch_assoc($getnres);
                          $weeks = $getweekno['week'];

                          //GET EMPLOYEE NAME


                          for ($i = 1;$i <= $noofweeks;$i++)
                          {

                              $query = "SELECT * FROM schedule WHERE month='$month'  AND year='$year' AND empid='$empid' and week='$weeks' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                              $result = mysqli_query($conn, $query);

                              if (mysqli_num_rows($result) > 0)
                              {

                                  echo '<tr>';

                                  while ($row = mysqli_fetch_assoc($result))
                                  {

                                      if ($empnamerow['status'] == 'Inactive')
                                      {

                                          echo ' <td style="text-align:center">';
                                          echo ' <span class="text-danger">--</span> </td>';

                                      }
                                      else
                                      {
                                          if ($row['starttime'] == 'OFF')
                                          {
                                              echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span> <br/>';
                                              echo ' <span class="text-danger">OFF </span></td>';
                                          }
                                          else if ($row['starttime'] == 'HOLIDAY OFF')
                                          {
                                              echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span> <br/>';
                                              echo ' <span class="text-danger" >HOLIDAY OFF </span></td>';
                                          }
                                          else if ($row['idl'] != '')
                                          {
                                              $idl = $row['idl'];

                                              $leavequery = "SELECT * FROM `leave` WHERE idl='$idl' AND status='3' ";
                                              $leaveres = mysqli_query($conn, $leavequery);
                                              $leaverow = mysqli_fetch_assoc($leaveres);
                                              $duration = $leaverow['duration'];

                                              $dur = substr($duration, -2);

                                              if (mysqli_num_rows($leaveres) > 0)
                                              {

                                                  if ($row['leaveduration'] == '0.5')
                                                  {

                                                      echo ' <td style="text-align:center"> <span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                                      echo ' <span class="text-danger">' . $leaverow['name'] . '<br/> Halfday</span> </td>';

                                                  }
                                                  else
                                                  {

                                                      echo ' <td style="text-align:center"> <span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                                      echo ' <span class="text-danger">' . $leaverow['name'] . '  </span> </td>';

                                                  }

                                              }
                                              else
                                              {

                                                  echo '<td style="text-align:center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';

                                                  $time = date("g:i A", strtotime($row['starttime']));
                                                  // echo $time;
                                                  echo '--- </td>';

                                              }

                                          }
                                          else
                                          {
                                            $dte = $row['date'];
                                            $dy = $row['day'];
                                            $tm = $row['starttime'];
                                            $dystr = date('l', strtotime($dte));
           
           
                                            $GMT = 'GMT+8';
           
                                          $pmtr = $dystr.', '.$dte.' '.$tm.' '.$GMT;
           
                                          $tz = new DateTimeZone('America/Los_Angeles');
                                          $PST = new DateTime($pmtr);
                                          $PST->setTimezone($tz);
           
                                          $hdate = $PST->format('m/d/Y');
           
                                         $util = "SELECT * FROM `tbl_login` WHERE empid='$empid' AND date='$hdate'";
                                          $utilres = mysqli_query($conn, $util);
                                          $utilrow = mysqli_fetch_assoc($utilres);
           
                                          $utildate = $utilrow['date'];
                                          $utilday = date('l', strtotime($utildate));
                                          $utiltime = $utilrow['timein'];
                                     
           
                                          
                                          if(empty($utildate)){
           
                                            echo '<td style="text-align:center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';

                                           $time = date("g:i A", strtotime($row['starttime']));
                                          // echo $hdate = $PSTph->format('g:i A');
           
                                           echo '--- </td>';
           
           
           
                                          }else{
           
                                           $pmtrph = $utildate.' '.$utiltime.' '.$utilgmt;
           
           
                                           $tzph = new DateTimeZone('Asia/Manila');
                                           $PSTph = new DateTime($pmtrph);
                                           $PSTph->setTimezone($tzph);
            
           
                                           echo '<td style="text-align:center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';

                                           $time = date("g:i A", strtotime($row['starttime']));
                                           echo $hdate = $PSTph->format('g:i A');
           
                                           echo '</td>';
                                           
                                       
                                          }

                                          }

                                      }

                                  }
                                  echo '</tr>';
                              }
                              else
                              {

                              }
                              echo '<tr>';

                              $weeks++;

                          }

                          ?>
                        
                  
                      </tbody>
                  </table>

                  <table class="table table-bordered" id="pstatt" name="pstatt" hidden>
                      <thead class="thead-dark">
                        <tr>
                          
                    
                          <th scope="col" style="text-align: center"> Sunday</th>
                          <th scope="col" style="text-align: center">Monday </th>
                          <th scope="col" style="text-align: center">Tuesday </th>
                          <th scope="col" style="text-align: center"> Wednesday</th>
                          <th scope="col" style="text-align: center">Thursday </th>
                          <th scope="col" style="text-align: center">Friday </th>  
                          <th scope="col" style="text-align: center">Saturday </th>                  
                        </tr>
                      </thead>
                      <tbody>
              
                      
                      
                        <?php
                          $month = date('F');
                          if (isset($_POST['filterm']))
                          {

                              $month = $getmonth;
                          }

                          $getnoweeks = "SELECT * FROM `schedule` WHERE year='$year' AND empid = '$empid' AND month='$month' GROUP BY week ";
                          $getnres = mysqli_query($conn, $getnoweeks);
                          $noofweeks = mysqli_num_rows($getnres);
                          $getweekno = mysqli_fetch_assoc($getnres);
                          $weeks = $getweekno['week'];

                          //GET EMPLOYEE NAME


                          $pstdate = "SELECT * FROM schedule WHERE month='$getmonth'  AND year='$year' AND empid='$empid'  AND starttime != 'OFF' AND starttime != 'HOLIDAY OFF' GROUP BY week";

                          $getstresult = mysqli_query($conn, $pstdate);

                          while ($getpst = mysqli_fetch_assoc($getstresult))
                          {
                              $attpst[] = $getpst['starttime'];

                          }

                          for ($i = 0;$i < $noofweeks;$i++)
                          {

                              if (new DateTime($attpst[$i]) >= new DateTime('16:00') && new DateTime($attpst[$i]) <= new DateTime('23:59'))
                              {

                                  $query = "SELECT * FROM schedule WHERE month='$month'  AND year='$year' AND empid='$empid' and week='$weeks' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";
                                  $datesql = "SELECT * FROM schedule WHERE month='$month'  AND year='$year' AND empid='$empid' and week='$weeks' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                              }
                              else if (new DateTime($attpst[$i]) >= new DateTime('00:00') && new DateTime($attpst[$i]) <= new DateTime('15:59'))
                              {

                                  $query = "SELECT * FROM schedule WHERE month='$month'  AND year='$year' AND empid='$empid' and week='$weeks' ORDER BY FIELD(day,  'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday') ";
                                  $datesql = "SELECT * FROM schedule WHERE month='$month'  AND year='$year' AND empid='$empid' and week='$weeks' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                              }

                              $result = mysqli_query($conn, $query);
                              $dateres = mysqli_query($conn, $datesql);

                              if (mysqli_num_rows($result) > 0)
                              {

                                  echo '<tr>';

                                  while (($row = mysqli_fetch_assoc($result)) && ($daterow = mysqli_fetch_assoc($dateres)))
                                  {

                                      if ($empnamerow['status'] == 'Inactive')
                                      {

                                          echo ' <td style="text-align:center">';
                                          echo ' <span class="text-danger">--</span> </td>';

                                      }
                                      else
                                      {
                                          if ($row['starttime'] == 'OFF')
                                          {
                                              echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($daterow['date'])) . ' </span> <br/>';
                                              echo ' <span class="text-danger">OFF </span></td>';
                                          }
                                          else if ($row['starttime'] == 'HOLIDAY OFF')
                                          {
                                              echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($daterow['date'])) . ' </span> <br/>';
                                              echo ' <span class="text-danger" >HOLIDAY OFF </span></td>';
                                          }
                                          else if ($row['idl'] != '')
                                          {
                                              $idl = $row['idl'];

                                              $leavequery = "SELECT * FROM `leave` WHERE idl='$idl' AND status='3' ";
                                              $leaveres = mysqli_query($conn, $leavequery);
                                              $leaverow = mysqli_fetch_assoc($leaveres);
                                              $duration = $leaverow['duration'];

                                              $dur = substr($duration, -2);

                                              if (mysqli_num_rows($leaveres) > 0)
                                              {

                                                  if ($row['leaveduration'] == '0.5')
                                                  {

                                                      echo ' <td style="text-align:center"> <span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($daterow['date'])) . ' </span><br/>';
                                                      echo ' <span class="text-danger">' . $leaverow['name'] . '<br/> Halfday</span> </td>';

                                                  }
                                                  else
                                                  {

                                                      echo ' <td style="text-align:center"> <span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($daterow['date'])) . ' </span><br/>';
                                                      echo ' <span class="text-danger">' . $leaverow['name'] . '  </span> </td>';

                                                  }

                                              }
                                              else
                                              {

                                                  echo '<td style="text-align:center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($daterow['date'])) . ' </span><br/>';

                                                  $time = date("g:i A", strtotime($row['starttime']));
                                                  // echo $time;
                                                  echo '--- </td>';

                                              }

                                          }
                                          else
                                          {
                                      
                                            $dte = $row['date'];
                                            $dy = $row['day'];
                                            $tm = $row['starttime'];
                                            $dystr = date('l', strtotime($dte));
              
              
                                            $GMT = 'GMT+8';
              
                                          $pmtr = $dystr.', '.$dte.' '.$tm.' '.$GMT;
              
                                          $tz = new DateTimeZone('America/Los_Angeles');
                                          $PST = new DateTime($pmtr);
                                          $PST->setTimezone($tz);
              
                                          $hdate = $PST->format('m/d/Y');
              
                                          $util = "SELECT * FROM `tbl_login` WHERE empid='$empid' AND date='$hdate'";
                                          $utilres = mysqli_query($conn, $util);
                                          $utilrow = mysqli_fetch_assoc($utilres);
              
                                          $utildate = $utilrow['date'];
                                          $utilday = date('l', strtotime($utildate));
                                          $utiltime = $utilrow['timein'];
                                     
              
                                          
                                          if(empty($utildate)){
              
                                            echo '<td style="text-align:center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
              
                                           $time = date("g:i A", strtotime($row['starttime']));
                                          // echo $hdate = $PSTph->format('g:i A');
              
                                           echo ' --- </td>';
              
              
              
                                          }else{
              
                                            $pmtrph = $utildate.' '.$utiltime.' '.$utilgmt;
              
              
                                           $tzph = new DateTimeZone('Asia/Manila');
                                           $PSTph = new DateTime($pmtrph);
                                           $PSTph->setTimezone($tzph);
              
              
                                           echo '<td style="text-align:center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
              
                                           $time = date("g:i A", strtotime($row['starttime']));
                                           echo $utiltime;
              
                                           echo '</td>';
                                           
                                       
                                          }
              
                                              
                                          }

                                      }

                                  }
                                  echo '</tr>';
                              }
                              else
                              {

                              }
                              echo '<tr>';

                              $weeks++;

                          }

                          ?>
                        
                  
                      </tbody>
                  </table>

      

                </div>
                
              </div>

                



            
    

          
            </div>
            

    
          

      
          </div>
          <!--
              TEAM WEEK SCHEDULE TEAM WEEK SCHEDULE 


          -->
          <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">
            <div class="row p-3">
              <div class="col-lg-6 col-md-12 col-sm-12">
                <h5>Schedule</h5>
              </div>
              <div class="col-lg-6 col-md-12 col-sm-12">
                <h5>Attendance</h5>
              </div>
              <div class="col-lg-12 col-md-12 col-sm-12 form-inline"> <!-- FILTER TEAM WEEK  -->
                <form method="post" enctype="multipart/form-data">  
                  <button type="submit" class="btn btn-primary btn-sm" name="filtertw"> <i class='fas fa-filter'></i> Filter </button> &nbsp


                                              
                    <?php

                    $qt = "SELECT * FROM schedule  WHERE year='$year' GROUP BY week ORDER BY date ASC ";
                    $rt = mysqli_query($conn, $qt);
                    echo "<select name='teamweek' class='form-control form-control-sm' required>";
                    echo "<option value='' disabled selected> Week </option>";

                    while ($r = mysqli_fetch_array($rt))
                    {
                        $month = $r['month'];
                        if ($teamweek == $r['week'] || $_POST['teamweek'] == $r['week'])
                        {
                            echo "<option value='" . $r['week'] . "' selected='selected'>Week  " . $r['week'] . " - " . date('F, j Y', strtotime($r['date'])) . "</option>";

                        }
                        else
                        {
                            echo "<option value='" . $r['week'] . "' >Week  " . $r['week'] . " - " . date('F, j Y', strtotime($r['date'])) . "</option>";
                        }

                    }
                    echo "</select>";
                    ?>
                                              
                    <select name="teamstatus" id="status" class="form-control form-control-sm">
                        <?php
                    switch ($teamstatus)
                    {
                    case 'All':
                        $All = "selected";
                    break;
                    case 'Active':
                        $Active = "selected";
                    break;

                    }
                    ?>

                        <option value="All" <?php echo $All ?>> All </option>
                        <option value="Active" <?php echo $Active ?>> Active </option>
                    </select>
                    <select name="tzwk" id="tzwk" onchange="teampacifictime()" class="form-control form-control-sm" >
                    <option value="manila"> Manila </option>
                    <option value="pacific"> Pacific </option>
                    </select>




                </form>

              </div>
              <div class="col-lg-6 col-md-12 col-sm-12 p-2"> <!-- SCHEDULE TABLE TEAM WEEK  -->
                  <div class="tableFixHead" id="schedteammanila" style="height: 300px" > <!-- TABLE TEAM WEEK MANILA TIME  -->
                    <table class="table table-bordered table-sm table-fixed" style="font-size:13px;" >
                      <thead>
                      <tr class="thead-dark"><th colspan='9'> Team Weekly Schedule </th></tr>
                      <tr class="thead-dark">
                      
                        <th style="vertical-align:middle;">Employee ID</th>
                        <th style="vertical-align:middle;">Employee Name</th>
                        <?php
                          $w = date('W');

                          $teamweek = ltrim($w, '0');
                          if (isset($_POST['teamweek']))
                          {
                        
                              $teamweek = $_POST['teamweek'];
                              $teamstatus = $_POST['teamstatus'];
                        
                          }

                          
                          $getemp = "SELECT * FROM schedule WHERE week='$teamweek'  AND year='$year' AND indi='0'  LIMIT 1";
                          $getempresult = mysqli_query($conn, $getemp);

                          $getemprow = mysqli_fetch_assoc($getempresult);

                          $firstemp = $getemprow['empid'];

                          $query = "SELECT * FROM schedule WHERE week='$teamweek'   AND year='$year' AND empid='$firstemp'  ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') LIMIT 7";
                          $result = mysqli_query($conn, $query);

                          if (mysqli_num_rows($result) > 0)
                          {

                              while ($row = mysqli_fetch_assoc($result))
                              {

                                  echo '<th style="text-align: Center">' . $row['day'] . '<br/>' . date('m/d/y', strtotime($row['date'])) . ' </th> ';

                              }

                          }
                          else
                          {
                              echo '<tr><td><h6> No schedule added for the current week </h6> <td> </tr>';
                          }

                          ?>
                                                        </tr>
                      </thead>
                      <tbody>
                        <?php

                              $getemp = "SELECT * FROM schedule WHERE week='$teamweek' AND team='$team'  AND year='$year' GROUP BY empid"; //GET EMPLOYEE
                              $getempresult = mysqli_query($conn, $getemp);

                              $getemprow = mysqli_num_rows($getempresult);

                              $empid = array();

                              while ($r = mysqli_fetch_assoc($getempresult))
                              {

                                  $empid[] = $r['empid'];

                              }

                              ?>
                    
                    
                        <?php

                          for ($i = 0;$i < $getemprow;$i++)
                          {
                              //GET ALL SCHEDULE OF EMPLOYEE
                              $query = "SELECT * FROM schedule WHERE  team='$team'  AND year='$year' AND empid='$empid[$i]' AND week='$teamweek' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                              //GET EMPLOYEE NAME
                              $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid  WHERE empinfo.empid='$empid[$i]' AND empdetails.team= '$team'";

                              if (isset($_POST['filtertw']))
                              {
                                  $teamstatus = $_POST['teamstatus'];

                                  $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid  WHERE empinfo.empid='$empid[$i]'AND empdetails.team= '$team'  AND status='$teamstatus'";
                                  $query = "SELECT * FROM schedule JOIN empdetails ON schedule.empid = empdetails.detailid  WHERE  schedule.team='$team'  AND year='$year' AND schedule.empid='$empid[$i]' AND schedule.week='$teamweek' AND empdetails.status = '$teamstatus' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                                  if ($teamstatus == 'All')
                                  {
                                      $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid  WHERE empinfo.empid='$empid[$i]'";
                                      $query = "SELECT * FROM schedule WHERE  team='$team'  AND year='$year' AND empid='$empid[$i]' AND week='$teamweek' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                                  }

                              }

                              $result = mysqli_query($conn, $query);
                              $resultname = mysqli_query($conn, $empname);

                              $empnamerow = mysqli_fetch_assoc($resultname);

                              if (mysqli_num_rows($result) > 0)
                              {

                                  echo '<tr>';
                                 echo '<td><strong>' . $empnamerow['empid'] . '</strong></td>';
                                  echo '<td><strong>' . $empnamerow['firstname'] . ' ' . $empnamerow['surname'] . '</strong></td>';


                                  while ($row = mysqli_fetch_assoc($result))
                                  {

                                      if ($empnamerow['status'] == 'Inactive')
                                      {
                                          echo ' <td style="text-align:center">';
                                          echo ' <span class="text-danger">---</span> </td>';

                                      }
                                      else
                                      {

                                          if ($row['starttime'] == 'OFF')
                                          {
                                              echo ' <td style="text-align:center">';
                                              echo ' <span class="text-danger">OFF </span> </td>';
                                          }

                                          else if ($row['starttime'] == 'HOLIDAY OFF')
                                          {
                                              echo ' <td style="text-align:center">';
                                              echo ' <span class="text-danger">HOLIDAY OFF </span> </td>';
                                          }
                                          else if ($row['idl'] != '')
                                          {
                                            $idl = $row['idl'];

                                            $leavequery = "SELECT * FROM `leave` WHERE idl='$idl' AND status='3' ";
                                            $leaveres = mysqli_query($conn, $leavequery);
                                            $leaverow = mysqli_fetch_assoc($leaveres);
                                            $duration = $leaverow['duration'];
      
                                            $dur = substr($duration, -2);
      
                                            
                                            if (mysqli_num_rows($leaveres) > 0)
                                            {
      
                                                if ($row['leaveduration'] == '0.5')
                                                {
      
                                                    echo ' <td style="text-align:center">';
                                                    echo ' <span class="text-danger">' . $leaverow['name'] . ' Halfday</span> </td>';
      
                                                }
                                                else
                                                {
      
                                                    echo ' <td style="text-align:center">';
                                                    echo ' <span class="text-danger">' . $leaverow['name'] . '  </span> </td>';
      
                                                }
      
                                            }
                                            else
                                            {
      
                                                echo '<td style="text-align:center">';
                                                $time = date("g:i A", strtotime($row['starttime']));
                                                echo $time;
                                                echo '</td>';
      
                                            }
      
 

                                          }

                                          else
                                          {
                                              echo '<td style="text-align:center">';

                                              $time = date("g:i A", strtotime($row['starttime']));

                                              echo $time;

                                              echo '</td>';

                                          }

                                      }

                                  }
                                  echo '</tr>';
                              }
                              else
                              {

                              }
                              echo '<tr>';

                          }

                          ?>
                        
                
                      </tbody>

                    </table>

                
                  </div>
                  <div class="tableFixHead" id="schedteampstw" style="height: 300px"  hidden> <!-- TABLE TEAM WEEK PACIFIC TIME  -->
                    <table class="table table-bordered table-sm table-fixed" style="font-size:13px;">
                      <thead>
                      <tr class="thead-dark"><th colspan='9'> Team Weekly Schedule </th></tr>
                      <tr class="thead-dark">
                      
                        <th style="vertical-align:middle;">Employee ID</th>
                        <th style="vertical-align:middle;">Employee Name</th>
                        <?php
                            $getemp = "SELECT * FROM schedule WHERE week='$teamweek'  AND year='$year' AND indi='0'  LIMIT 1";
                            $getempresult = mysqli_query($conn, $getemp);

                            $getemprow = mysqli_fetch_assoc($getempresult);

                            $firstemp = $getemprow['empid'];

                            $query = "SELECT * FROM schedule WHERE week='$teamweek'   AND year='$year' AND empid='$firstemp'  ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') LIMIT 7";
                            $result = mysqli_query($conn, $query);

                            if (mysqli_num_rows($result) > 0)
                            {

                                while ($row = mysqli_fetch_assoc($result))
                                {

                                    echo '<th style="text-align: Center">' . $row['day'] . '<br/>' . date('m/d/y', strtotime($row['date'])) . ' </th> ';

                                }

                            }
                            else
                            {
                                echo '<tr><td><h6> No schedule added for the current week </h6> <td> </tr>';
                            }

                          ?>
                      </tr>
                      </thead>
                      <tbody>
                        <?php

                          $getemp = "SELECT * FROM schedule WHERE week='$teamweek' AND team='$team'  AND year='$year' GROUP BY empid"; //GET EMPLOYEE
                          $getempresult = mysqli_query($conn, $getemp);

                          $getemprow = mysqli_num_rows($getempresult);

                          $empid = array();
                          $pstst = array();

                          while ($r = mysqli_fetch_assoc($getempresult))
                          {

                              $empid[] = $r['empid'];

                          }

                          for ($a = 0;$a < $getemprow;$a++)
                          {

                              $getst = "SELECT * FROM schedule WHERE  team='$team'  AND year='$year' AND empid='$empid[$a]' AND week='$week' AND starttime != 'OFF'  AND starttime != 'HOLIDAY OFF' LIMIT 1"; //GET EMPLOYEE
                              $getstresult = mysqli_query($conn, $getst);

                              while ($getstr = mysqli_fetch_assoc($getstresult))
                              {
                                  $pstst[] = $getstr['starttime'];

                              }

                          }

                          ?>
                    
                    
                        <?php

                          for ($i = 0;$i < $getemprow;$i++)
                          {
                              //GET ALL SCHEDULE OF EMPLOYEE
                              $query = "SELECT * FROM schedule WHERE  team='$team'  AND year='$year' AND empid='$empid[$i]' AND week='$teamweek' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                              //GET EMPLOYEE NAME
                              $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid  WHERE empinfo.empid='$empid[$i]' AND empdetails.team= '$team'";
                              if (isset($_POST['filterw']))
                              {

                                  $teamstatus = $_POST['status'];

                                  if ($teamstatus == 'All')
                                  {

                                      if (new DateTime($pstst[$i]) >= new DateTime('16:00') && new DateTime($pstst[$i]) <= new DateTime('23:59'))
                                      {

                                          $query = "SELECT * FROM schedule WHERE  team='$team'  AND year='$year' AND empid='$empid[$i]' AND week='$teamweek' ORDER BY FIELD(day, 'Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                                          $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid WHERE empinfo.empid='$empid[$i]'";

                                      }
                                      else if (new DateTime($pstst[$i]) >= new DateTime('00:00') && new DateTime($pstst[$i]) <= new DateTime('15:59'))
                                      {

                                          $query = "SELECT * FROM schedule WHERE  team='$team'  AND year='$year' AND empid='$empid[$i]' AND week='$teamweek' ORDER BY FIELD(day, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday') ";

                                          $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid WHERE empinfo.empid='$empid[$i]'";

                                      }

                                  }
                                  else
                                  {

                                      if (new DateTime($pstst[$i]) >= new DateTime('16:00') && new DateTime($pstst[$i]) <= new DateTime('23:59'))
                                      {

                                          $query = "SELECT * FROM schedule JOIN empdetails ON schedule.empid = empdetails.detailid WHERE  empdetails.team='$team'  AND empdetails.status ='$teamstatus' AND year='$year' AND schedule.empid='$empid[$i]' AND week='$teamweek' ORDER BY FIELD(day, 'Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                                          $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid  WHERE empinfo.empid='$empid[$i]'AND empdetails.team= '$team'  AND status='$teamstatus'";

                                      }
                                      else if (new DateTime($pstst[$i]) >= new DateTime('00:00') && new DateTime($pstst[$i]) <= new DateTime('15:59'))
                                      {

                                          $query = "SELECT * FROM schedule JOIN empdetails ON schedule.empid = empdetails.detailid WHERE  empdetails.team='$team'  AND empdetails.status ='$teamstatus' AND year='$year' AND schedule.empid='$empid[$i]' AND week='$teamweek' ORDER BY FIELD(day, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday') ";
                                          $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid  WHERE empinfo.empid='$empid[$i]'AND empdetails.team= '$team'  AND status='$teamstatus'";

                                      }

                                  }

                              }
                              else
                              {

                                  $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid WHERE empinfo.empid='$empid[$i]'";

                                  if (new DateTime($pstst[$i]) >= new DateTime('16:00') && new DateTime($pstst[$i]) <= new DateTime('23:59'))
                                  {

                                      $query = "SELECT * FROM schedule WHERE  team='$team'  AND year='$year' AND empid='$empid[$i]' AND week='$teamweek' ORDER BY FIELD(day, 'Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                                  }
                                  else if (new DateTime($pstst[$i]) >= new DateTime('00:00') && new DateTime($pstst[$i]) <= new DateTime('15:59'))
                                  {

                                      $query = "SELECT * FROM schedule WHERE  team='$team'  AND year='$year' AND empid='$empid[$i]' AND week='$teamweek' ORDER BY FIELD(day, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday') ";

                                  }

                              }

                              $result = mysqli_query($conn, $query);
                              $resultname = mysqli_query($conn, $empname);

                              $empnamerow = mysqli_fetch_assoc($resultname);

                              if (mysqli_num_rows($result) > 0)
                              {

                                  echo '<tr>';
                                  echo '<td><strong>' . $empnamerow['empid'] . '</strong></td>';
                                  echo '<td><strong>' . $empnamerow['firstname'] . ' ' . $empnamerow['surname'] . '</strong></td>';

                                  while ($row = mysqli_fetch_assoc($result))
                                  {
                                      $day = $row['day'];
                                      $dates = $row['date'];
                                      $start = $row['starttime'];

                                      $GMT = 'GMT+8';
                                    $parameter = $day . ', ' . $dates . ' ' . $start . ' ' . $GMT;

                                      if ($empnamerow['status'] == 'Inactive')
                                      {
                                          echo ' <td style="text-align:center">';
                                          echo ' <span class="text-danger">---</span> </td>';

                                      }
                                      else
                                      {

                                          if ($row['starttime'] == 'OFF')
                                          {
                                              echo ' <td style="text-align:center">';
                                              echo ' <span class="text-danger">OFF </span> </td>';
                                          }

                                          else if ($row['starttime'] == 'HOLIDAY OFF')
                                          {
                                              echo ' <td style="text-align:center">';
                                              echo ' <span class="text-danger">HOLIDAY OFF </span> </td>';
                                          }
                                          else if ($row['idl'] != '')
                                          {
                                            $idl = $row['idl'];

                                            $leavequery = "SELECT * FROM `leave` WHERE idl='$idl' AND status='3' ";
                                            $leaveres = mysqli_query($conn, $leavequery);
                                            $leaverow = mysqli_fetch_assoc($leaveres);
                                            $duration = $leaverow['duration'];
      
                                            $dur = substr($duration, -2);
      
                                            
                                            if (mysqli_num_rows($leaveres) > 0)
                                            {
      
                                                if ($row['leaveduration'] == '0.5')
                                                {
      
                                                    echo ' <td style="text-align:center">';
                                                    echo ' <span class="text-danger">' . $leaverow['name'] . ' Halfday</span> </td>';
      
                                                }
                                                else
                                                {
      
                                                    echo ' <td style="text-align:center">';
                                                    echo ' <span class="text-danger">' . $leaverow['name'] . '  </span> </td>';
      
                                                }
      
                                            }
                                            else
                                            {
      
                                                echo '<td style="text-align:center">';
                                                $time = date("g:i A", strtotime($row['starttime']));
                                                echo $time;
                                                echo '</td>';
      
                                            }
      
   
                                          }

                                          else
                                          {
                                              echo '<td style="text-align:center">';

                                              $tz = new DateTimeZone('America/Los_Angeles');
                                              $PST = new DateTime($parameter);
                                              $PST->setTimezone($tz);

                                              echo $time =$PST->format('g:i A');
         

                                              echo '</td>';

                                          }

                                      }

                                  }
                                  echo '</tr>';
                              }
                              else
                              {

                              }
                              echo '<tr>';

                          }

                          ?>
                                                          
                
                      </tbody>

                    </table>
                  </div>
              </div>

              <div class="col-lg-6 col-md-12 col-sm-12 p-2"> <!--ATTENDANCE TABLE TEAM WEEK  -->
                  <div class="tableFixHead" style="height: 300px"  id="attteammanila" > <!-- TABLE TEAM WEEK MANILA TIME  -->
                    <table class="table table-bordered table-sm table-fixed" style="font-size:13px;" >
                      <thead>
                      <tr class="thead-dark"><th colspan='9'> Team Weekly Schedule </th></tr>
                      <tr class="thead-dark">
                      
                        <th style="vertical-align:middle;">Employee ID</th>
                        <th style="vertical-align:middle;">Employee Name</th>
                        <?php
                          $getemp = "SELECT * FROM schedule WHERE week='$teamweek'  AND year='$year' AND indi='0'  LIMIT 1";
                          $getempresult = mysqli_query($conn, $getemp);

                          $getemprow = mysqli_fetch_assoc($getempresult);

                          $firstemp = $getemprow['empid'];

                          $query = "SELECT * FROM schedule WHERE week='$teamweek'   AND year='$year' AND empid='$firstemp'  ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') LIMIT 7";
                          $result = mysqli_query($conn, $query);

                          if (mysqli_num_rows($result) > 0)
                          {

                              while ($row = mysqli_fetch_assoc($result))
                              {

                                  echo '<th style="text-align: Center">' . $row['day'] . '<br/>' . date('m/d/y', strtotime($row['date'])) . ' </th> ';

                              }

                          }
                          else
                          {
                              echo '<tr><td><h6> No schedule added for the current week </h6> <td> </tr>';
                          }

                          ?>
                                                        </tr>
                      </thead>
                      <tbody>
                        <?php

                              $getemp = "SELECT * FROM schedule WHERE week='$teamweek' AND team='$team'  AND year='$year' GROUP BY empid"; //GET EMPLOYEE
                              $getempresult = mysqli_query($conn, $getemp);

                              $getemprow = mysqli_num_rows($getempresult);

                              $empid = array();

                              while ($r = mysqli_fetch_assoc($getempresult))
                              {

                                  $empid[] = $r['empid'];

                              }

                              ?>
                    
                    
                        <?php

                          for ($i = 0;$i < $getemprow;$i++)
                          {
                              //GET ALL SCHEDULE OF EMPLOYEE
                              $query = "SELECT * FROM schedule WHERE  team='$team'  AND year='$year' AND empid='$empid[$i]' AND week='$teamweek' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                              //GET EMPLOYEE NAME
                              $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid  WHERE empinfo.empid='$empid[$i]' AND empdetails.team= '$team'";

                              if (isset($_POST['filtertw']))
                              {
                              
                                  $teamstatus = $_POST['teamstatus'];

                                  $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid  WHERE empinfo.empid='$empid[$i]'AND empdetails.team= '$team'  AND status='$teamstatus'";
                                  $query = "SELECT * FROM schedule JOIN empdetails ON schedule.empid = empdetails.detailid  WHERE  schedule.team='$team'  AND year='$year' AND schedule.empid='$empid[$i]' AND schedule.week='$teamweek' AND empdetails.status = '$teamstatus' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                                  if ($teamstatus == 'All')
                                  {
                                      $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid  WHERE empinfo.empid='$empid[$i]'";
                                      $query = "SELECT * FROM schedule WHERE  team='$team'  AND year='$year' AND empid='$empid[$i]' AND week='$teamweek' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                                  }

                              }

                              $result = mysqli_query($conn, $query);
                              $resultname = mysqli_query($conn, $empname);

                              $empnamerow = mysqli_fetch_assoc($resultname);

                              if (mysqli_num_rows($result) > 0)
                              {

                                  echo '<tr>';
                                  echo '<td><strong>' . $empnamerow['empid'] . '</strong></td>';
                                  echo '<td><strong>' . $empnamerow['firstname'] . ' ' . $empnamerow['surname'] . '</strong></td>';

                                  while ($row = mysqli_fetch_assoc($result))
                                  {

                                      if ($empnamerow['status'] == 'Inactive')
                                      {
                                          echo ' <td style="text-align:center">';
                                          echo ' <span class="text-danger">---</span> </td>';

                                      }
                                      else
                                      {

                                          if ($row['starttime'] == 'OFF')
                                          {
                                              echo ' <td style="text-align:center">';
                                              echo ' <span class="text-danger">OFF </span> </td>';
                                          }

                                          else if ($row['starttime'] == 'HOLIDAY OFF')
                                          {
                                              echo ' <td style="text-align:center">';
                                              echo ' <span class="text-danger">HOLIDAY OFF </span> </td>';
                                          }
                                          else if ($row['idl'] != '')
                                          {

                                            $idl = $row['idl'];

                                            $leavequery = "SELECT * FROM `leave` WHERE idl='$idl' AND status='3' ";
                                            $leaveres = mysqli_query($conn, $leavequery);
                                            $leaverow = mysqli_fetch_assoc($leaveres);
                                            $duration = $leaverow['duration'];
      
                                            $dur = substr($duration, -2);
      
                                            
                                            if (mysqli_num_rows($leaveres) > 0)
                                            {
      
                                                if ($row['leaveduration'] == '0.5')
                                                {
      
                                                    echo ' <td style="text-align:center">';
                                                    echo ' <span class="text-danger">' . $leaverow['name'] . ' Halfday</span> </td>';
      
                                                }
                                                else
                                                {
      
                                                    echo ' <td style="text-align:center">';
                                                    echo ' <span class="text-danger">' . $leaverow['name'] . '  </span> </td>';
      
                                                }
      
                                            }
                                            else
                                            {
      
                                                echo '<td style="text-align:center">';
                                                $time = date("g:i A", strtotime($row['starttime']));
                                                echo $time;
                                                echo '</td>';
      
                                            }
      
    
                                          }

                                          else
                                          {
                                              
                                            $dte = $row['date'];
                                            $dy = $row['day'];
                                            $tm = $row['starttime'];
                                            $dystr = date('l', strtotime($dte));


                                            $GMT = 'GMT+8';

                                            $pmtr = $dystr.', '.$dte.' '.$tm.' '.$GMT;

                                            $tz = new DateTimeZone('America/Los_Angeles');
                                            $PST = new DateTime($pmtr);
                                            $PST->setTimezone($tz);

                                            $hdate = $PST->format('m/d/Y');

                                            $util = "SELECT * FROM `tbl_login` WHERE empid='$empid[$i]' AND date='$hdate'";
                                            $utilres = mysqli_query($conn, $util);
                                            $utilrow = mysqli_fetch_assoc($utilres);

                                            $utildate = $utilrow['date'];
                                            $utilday = date('l', strtotime($utildate));
                                            $utiltime = $utilrow['timein'];
                                    

                                            
                                            if(empty($utildate)){

                                            echo '<td style="text-align:center">';
                                            $time = date("g:i A", strtotime($row['starttime']));
                                            // echo $hdate = $PSTph->format('g:i A');

                                            echo '--- </td>';



                                            }else{

                                            $pmtrph = $utildate.' '.$utiltime.' '.$utilgmt;


                                            $tzph = new DateTimeZone('Asia/Manila');
                                            $PSTph = new DateTime($pmtrph);
                                            $PSTph->setTimezone($tzph);


                                            echo '<td style="text-align:center">';
                                            $time = date("g:i A", strtotime($row['starttime']));
                                            echo $hdate = $PSTph->format('g:i A');

                                            echo '</td>';
                                            
                                        
                                            }

                                          }

                                      }

                                  }
                                  echo '</tr>';
                              }
                              else
                              {

                              }
                              echo '<tr>';

                          }

                          ?>
                        
                
                      </tbody>

                    </table>

                
                  </div>
                  <div class="tableFixHead" style="height: 300px"  id="attteampstw" hidden > <!-- TABLE TEAM WEEK MANILA TIME  -->
                    <table class="table table-bordered table-sm table-fixed" style="font-size:13px;" >
                      <thead>
                      <tr class="thead-dark"><th colspan='9'> Team Weekly Schedule </th></tr>
                      <tr class="thead-dark">
                      
                        <th style="vertical-align:middle;">Employee ID</th>
                        <th style="vertical-align:middle;">Employee Name</th>
                        <?php
                            $getemp = "SELECT * FROM schedule WHERE week='$teamweek'  AND year='$year' AND indi='0'  LIMIT 1";
                            $getempresult = mysqli_query($conn, $getemp);

                            $getemprow = mysqli_fetch_assoc($getempresult);

                            $firstemp = $getemprow['empid'];

                            $query = "SELECT * FROM schedule WHERE week='$teamweek'   AND year='$year' AND empid='$firstemp'  ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') LIMIT 7";
                            $result = mysqli_query($conn, $query);

                            if (mysqli_num_rows($result) > 0)
                            {

                                while ($row = mysqli_fetch_assoc($result))
                                {

                                    echo '<th style="text-align: Center">' . $row['day'] . '<br/>' . date('m/d/y', strtotime($row['date'])) . ' </th> ';

                                }

                            }
                            else
                            {
                                echo '<tr><td><h6> No schedule added for the current week </h6> <td> </tr>';
                            }

                          ?>
                      </tr>
                      </thead>
                      <tbody>
                        <?php

                          $getemp = "SELECT * FROM schedule WHERE week='$teamweek' AND team='$team'  AND year='$year' GROUP BY empid"; //GET EMPLOYEE
                          $getempresult = mysqli_query($conn, $getemp);

                          $getemprow = mysqli_num_rows($getempresult);

                          $empid = array();
                          $pstst = array();

                          while ($r = mysqli_fetch_assoc($getempresult))
                          {

                              $empid[] = $r['empid'];

                          }

                          for ($a = 0;$a < $getemprow;$a++)
                          {

                              $getst = "SELECT * FROM schedule WHERE  team='$team'  AND year='$year' AND empid='$empid[$a]' AND week='$week' AND starttime != 'OFF' AND starttime != 'HOLIDAY OFF' LIMIT 1"; //GET EMPLOYEE
                              $getstresult = mysqli_query($conn, $getst);

                              while ($getstr = mysqli_fetch_assoc($getstresult))
                              {
                                  $pstst[] = $getstr['starttime'];

                              }

                          }

                          ?>
                    
                    
                        <?php

                          for ($i = 0;$i < $getemprow;$i++)
                          {
                              //GET ALL SCHEDULE OF EMPLOYEE
                              $query = "SELECT * FROM schedule WHERE  team='$team'  AND year='$year' AND empid='$empid[$i]' AND week='$teamweek' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                              //GET EMPLOYEE NAME
                              $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid  WHERE empinfo.empid='$empid[$i]' AND empdetails.team= '$team'";
                              if (isset($_POST['filterw']))
                              {

                                  $teamstatus = $_POST['status'];

                                  if ($teamstatus == 'All')
                                  {

                                      if (new DateTime($pstst[$i]) >= new DateTime('16:00') && new DateTime($pstst[$i]) <= new DateTime('23:59'))
                                      {

                                          $query = "SELECT * FROM schedule WHERE  team='$team'  AND year='$year' AND empid='$empid[$i]' AND week='$week' ORDER BY FIELD(day, 'Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                                          $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid WHERE empinfo.empid='$empid[$i]'";

                                      }
                                      else if (new DateTime($pstst[$i]) >= new DateTime('00:00') && new DateTime($pstst[$i]) <= new DateTime('15:59'))
                                      {

                                          $query = "SELECT * FROM schedule WHERE  team='$team'  AND year='$year' AND empid='$empid[$i]' AND week='$week' ORDER BY FIELD(day, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday') ";

                                          $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid WHERE empinfo.empid='$empid[$i]'";

                                      }

                                  }
                                  else
                                  {

                                      if (new DateTime($pstst[$i]) >= new DateTime('16:00') && new DateTime($pstst[$i]) <= new DateTime('23:59'))
                                      {

                                          $query = "SELECT * FROM schedule JOIN empdetails ON schedule.empid = empdetails.detailid WHERE  empdetails.team='$team'  AND empdetails.status ='$teamstatus' AND year='$year' AND schedule.empid='$empid[$i]' AND week='$week' ORDER BY FIELD(day, 'Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                                          $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid  WHERE empinfo.empid='$empid[$i]'AND empdetails.team= '$team'  AND status='$teamstatus'";

                                      }
                                      else if (new DateTime($pstst[$i]) >= new DateTime('00:00') && new DateTime($pstst[$i]) <= new DateTime('15:59'))
                                      {

                                          $query = "SELECT * FROM schedule JOIN empdetails ON schedule.empid = empdetails.detailid WHERE  empdetails.team='$team'  AND empdetails.status ='$teamstatus' AND year='$year' AND schedule.empid='$empid[$i]' AND week='$week' ORDER BY FIELD(day, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday') ";
                                          $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid  WHERE empinfo.empid='$empid[$i]'AND empdetails.team= '$team'  AND status='$teamstatus'";

                                      }

                                  }

                              }
                              else
                              {

                                  $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid WHERE empinfo.empid='$empid[$i]'";

                                  if (new DateTime($pstst[$i]) >= new DateTime('16:00') && new DateTime($pstst[$i]) <= new DateTime('23:59'))
                                  {

                                      $query = "SELECT * FROM schedule WHERE  team='$team'  AND year='$year' AND empid='$empid[$i]' AND week='$week' ORDER BY FIELD(day, 'Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                                  }
                                  else if (new DateTime($pstst[$i]) >= new DateTime('00:00') && new DateTime($pstst[$i]) <= new DateTime('15:59'))
                                  {

                                      $query = "SELECT * FROM schedule WHERE  team='$team'  AND year='$year' AND empid='$empid[$i]' AND week='$week' ORDER BY FIELD(day, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday') ";

                                  }

                              }

                              $result = mysqli_query($conn, $query);
                              $resultname = mysqli_query($conn, $empname);

                              $empnamerow = mysqli_fetch_assoc($resultname);

                              if (mysqli_num_rows($result) > 0)
                              {

                                  echo '<tr>';
                                  echo '<td><strong>' . $empnamerow['empid'] . '</strong></td>';
                                  echo '<td><strong>' . $empnamerow['firstname'] . ' ' . $empnamerow['surname'] . '</strong></td>';

                                  while ($row = mysqli_fetch_assoc($result))
                                  {
                                      $day = $row['day'];
                                      $dates = $row['date'];
                                      $start = $row['starttime'];

                                      $GMT = 'GMT+8';
                                      $parameter = $day . ', ' . $dates . ' ' . $start . ' ' . $GMT;

                                      if ($empnamerow['status'] == 'Inactive')
                                      {
                                          echo ' <td style="text-align:center">';
                                          echo ' <span class="text-danger">---</span> </td>';

                                      }
                                      else
                                      {

                                          if ($row['starttime'] == 'OFF')
                                          {
                                              echo ' <td style="text-align:center">';
                                              echo ' <span class="text-danger">OFF </span> </td>';
                                          }

                                          else if ($row['starttime'] == 'HOLIDAY OFF')
                                          {
                                              echo ' <td style="text-align:center">';
                                              echo ' <span class="text-danger">HOLIDAY OFF </span> </td>';
                                          }
                                          else if ($row['idl'] != '')
                                          {
                                            $idl = $row['idl'];

                                            $leavequery = "SELECT * FROM `leave` WHERE idl='$idl' AND status='3' ";
                                            $leaveres = mysqli_query($conn, $leavequery);
                                            $leaverow = mysqli_fetch_assoc($leaveres);
                                            $duration = $leaverow['duration'];
      
                                            $dur = substr($duration, -2);
      
                                            
                                            if (mysqli_num_rows($leaveres) > 0)
                                            {
      
                                                if ($row['leaveduration'] == '0.5')
                                                {
      
                                                    echo ' <td style="text-align:center">';
                                                    echo ' <span class="text-danger">' . $leaverow['name'] . ' Halfday</span> </td>';
      
                                                }
                                                else
                                                {
      
                                                    echo ' <td style="text-align:center">';
                                                    echo ' <span class="text-danger">' . $leaverow['name'] . '  </span> </td>';
      
                                                }
      
                                            }
                                            else
                                            {
      
                                                echo '<td style="text-align:center">';
                                                $time = date("g:i A", strtotime($row['starttime']));
                                                echo $time;
                                                echo '</td>';
      
                                            }
      
    
                                          }

                                          else
                                          {

                                            $dte = $row['date'];
                                            $dy = $row['day'];
                                            $tm = $row['starttime'];
                                            $dystr = date('l', strtotime($dte));


                                            $GMT = 'GMT+8';

                                            $pmtr = $dystr.', '.$dte.' '.$tm.' '.$GMT;

                                            $tz = new DateTimeZone('America/Los_Angeles');
                                            $PST = new DateTime($pmtr);
                                            $PST->setTimezone($tz);

                                            $hdate = $PST->format('m/d/Y');

                                            $util = "SELECT * FROM `tbl_utilization` WHERE empid='$empid[$i]' AND date='$hdate' AND activity = 'Log In'";
                                            $utilres = mysqli_query($conn, $util);
                                            $utilrow = mysqli_fetch_assoc($utilres);

                                            $utildate = $utilrow['date'];
                                            $utilday = date('l', strtotime($utildate));
                                            $utiltime = $utilrow['starttime'];
                                    

                                            
                                            if(empty($utildate)){

                                            echo '<td style="text-align:center">';
                                            $time = date("g:i A", strtotime($row['starttime']));
                                            // echo $hdate = $PSTph->format('g:i A');

                                            echo '--- </td>';



                                            }else{

                                            $pmtrph = $utildate.' '.$utiltime.' '.$utilgmt;


                                            $tzph = new DateTimeZone('Asia/Manila');
                                            $PSTph = new DateTime($pmtrph);
                                            $PSTph->setTimezone($tzph);


                                            echo '<td style="text-align:center">';
                                            $time = date("g:i A", strtotime($row['starttime']));
                                            echo $utiltime;

                                            echo '</td>';
                                            
                                        
                                            }



                                          }

                                      }

                                  }
                                  echo '</tr>';
                              }
                              else
                              {

                              }
                              echo '<tr>';

                          }

                          ?>
                                                          
                
                      </tbody>

                    </table>
                  </div>
              </div>

              <div class="col-lg-12 col-md-12 col-sm-12 form-inline"><!-- FILTER MONTHLY TEAM -->
                  <?php
                $getmonth = date('m');
                $employee = $empid;

                if (isset($_POST['filterm']))
                {
                    $getmonth = $_POST['month'];
                    $employee = $_POST['employee'];

                }

                ?>
                                      
                <form method="post" enctype="multipart/form-data">  
                    <button type="submit" class="btn btn-primary btn-sm" name="filterm"> <i class='fas fa-filter'></i> Filter </button> &nbsp

                    <?php

                    $teamquery = "SELECT * FROM schedule WHERE team='$team' GROUP BY empid ";
                    $teamres = mysqli_query($conn, $teamquery);
                    echo "<select name='employee' class='form-control form-control-sm' required>";
                    echo "<option value='' disabled selected> Employee ID </option>";

                    while ($teamrow = mysqli_fetch_array($teamres))
                    {

                        if ($employee == $teamrow['empid'])
                        {
                            echo "<option value='" . $teamrow['empid'] . "' selected='selected'> " . $teamrow['empid'] . "</option>";

                        }
                        else
                        {
                            echo "<option value='" . $teamrow['empid'] . "' >" . $teamrow['empid'] . "</option>";
                        }

                    }
                    echo "</select>";
                    ?>
                    
                    <?php

                    $qt = "SELECT * FROM schedule  WHERE year='$year' GROUP BY month ORDER BY FIELD(month, 'January', 'February', 'March', 'April','May', 'June', 'July','August','September','October','November','December'); ";
                    $rt = mysqli_query($conn, $qt);
                    echo "<select name='month' class='form-control form-control-sm' required>";
                    echo "<option value='' disabled selected> Month </option>";

                    while ($r = mysqli_fetch_array($rt))
                    {
                        $month = $r['month'];
                        if ($getmonth == $r['month'])
                        {
                            echo "<option value='" . $r['month'] . "' selected='selected'>" . $r['month'] . "</option>";

                        }
                        else
                        {
                            echo "<option value='" . $r['month'] . "' >" . $r['month'] . "</option>";
                        }

                    }
                    echo "</select>";

                    ?>
                    <select name="tzm" id="tzm" onchange="monthlyteampst()" class="form-control form-control-sm">
                    <option value="manila"> Manila </option>
                    <option value="pacific"> Pacific </option>
                    </select>

                </form>
              </div>
              <div class="col-lg-6 col-md-12 col-sm-12 p-2">

                <table class="table table-bordered table-sm" id="manilamonthtable" name="manilamonthtable" style="font-size:13px;" ><!-- MONTHLY TABLE MANILA -->
                    <thead class="thead-dark">
                    <tr><th colspan='7'> Team Monthly Schedule </th></tr>
                      <tr>
                        
                  
                        <th scope="col" style="text-align: center"> Sunday</th>
                        <th scope="col" style="text-align: center">Monday </th>
                        <th scope="col" style="text-align: center">Tuesday </th>
                        <th scope="col" style="text-align: center"> Wednesday</th>
                        <th scope="col" style="text-align: center">Thursday </th>
                        <th scope="col" style="text-align: center">Friday </th>  
                        <th scope="col" style="text-align: center">Saturday </th>                  
                      </tr>
                    </thead>
                    <tbody>
            
                    
                    
                      <?php

                        $getnoweeks = "SELECT * FROM `schedule` WHERE year='$year' AND empid= '$employee' AND month='$getmonth' GROUP BY week ORDER BY week ";
                        $getnres = mysqli_query($conn, $getnoweeks);
                        $noofweeks = mysqli_num_rows($getnres);
                        $getweekno = mysqli_fetch_assoc($getnres);
                        $weeks = $getweekno['week'];

                        //GET EMPLOYEE NAME
                        $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid WHERE empinfo.empid='$employee'";
                        $resultname = mysqli_query($conn, $empname);

                        $empnamerow = mysqli_fetch_assoc($resultname);

                        for ($i = 1;$i <= $noofweeks;$i++)
                        {

                            $query = "SELECT * FROM schedule WHERE month='$getmonth'  AND year='$year' AND empid='$employee' and week='$weeks' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                            $result = mysqli_query($conn, $query);

                            if (mysqli_num_rows($result) > 0)
                            {

                                echo '<tr>';

                                while ($row = mysqli_fetch_assoc($result))
                                {

                                    if ($empnamerow['status'] == 'Inactive')
                                    {

                                        echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                             
                                        echo ' <span class="text-danger">---</span></span> </td>';

                                    }
                                    else
                                    {
                                        if ($row['starttime'] == 'OFF')
                                        {
                                            echo ' <td style="text-align:center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date('m/d/Y', strtotime($row['date'])) . ' </span><br/>';
                                            echo ' <span class="text-danger">OFF </span></td>';
                                        }
                                        else if ($row['starttime'] == 'HOLIDAY OFF')
                                        {
                                            echo ' <td style="text-align:center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date('m/d/Y', strtotime($row['date'])) . ' </span><br/>';
                                            echo ' <span class="text-danger" >HOLIDAY OFF </span></td>';
                                        }
                                        else if ($row['idl'] != '')
                                        {
                                            $idl = $row['idl'];

                                            $leavequery = "SELECT * FROM `leave` WHERE idl='$idl' AND status='3' ";
                                            $leaveres = mysqli_query($conn, $leavequery);
                                            $leaverow = mysqli_fetch_assoc($leaveres);
                                            $duration = $leaverow['duration'];
      
                                            $dur = substr($duration, -2);
      
                                            
                                            if (mysqli_num_rows($leaveres) > 0)
                                            {
      
                                                if ($row['leaveduration'] == '0.5')
                                                {
      
                                                    echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                          
                                                    echo ' <span class="text-danger">' . $leaverow['name'] . ' Halfday</span> </td>';
      
                                                }
                                                else
                                                {
      
                                                    echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                          
                                                    echo ' <span class="text-danger">' . $leaverow['name'] . '  </span> </td>';
      
                                                }
      
                                            }
                                            else
                                            {
      
                                                echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                          
                                                $time = date("g:i A", strtotime($row['starttime']));
                                                echo $time;
                                                echo '</td>';
      
                                            }
      

                                        }

                                        else
                                        {
                                            echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                             
                                            echo '' . date("g:i A", strtotime($row['starttime'])) . ' <br/>';

                                            // echo   ''.date("g:i A", strtotime($timestart)).' - '.date("g:i A", strtotime($timeend)).'</td>';
                                            
                                        }

                                    }

                                }
                                echo '</tr>';
                            }
                            else
                            {

                            }
                            echo '<tr>';

                            $weeks++;

                        }

                        ?>
                      
                
                    </tbody>
                </table>

                <table class="table table-bordered table-sm" id="pstmonthtable" name="pstmonthtable" style="font-size:13px;" hidden > <!-- PACIFIC TABLE MANILA -->
                    <thead class="thead-dark">
                    <tr><th colspan='7'> Team Monthly Schedule </th></tr>
                      <tr>
                        
                  
                        <th scope="col" style="text-align: center"> Sunday</th>
                        <th scope="col" style="text-align: center">Monday </th>
                        <th scope="col" style="text-align: center">Tuesday </th>
                        <th scope="col" style="text-align: center"> Wednesday</th>
                        <th scope="col" style="text-align: center">Thursday </th>
                        <th scope="col" style="text-align: center">Friday </th>  
                        <th scope="col" style="text-align: center">Saturday </th>                  
                      </tr>
                    </thead>
                    <tbody>
            
                    
                    
                      <?php

                        $getnoweeks = "SELECT * FROM `schedule` WHERE year='$year' AND empid= '$employee' AND month='$getmonth' GROUP BY week ORDER BY week ";
                        $getnres = mysqli_query($conn, $getnoweeks);
                        $noofweeks = mysqli_num_rows($getnres);
                        $getweekno = mysqli_fetch_assoc($getnres);
                        $weeks = $getweekno['week'];
                        $pstweek = $getweekno['week'];

                        for ($b = 0 ;$b < $noofweeks;$b++)
                        {

                            $pstdate = "SELECT * FROM schedule WHERE month='$getmonth'  AND year='$year' AND empid='$employee' and week='$pstweek' AND starttime != 'OFF' AND starttime != 'HOLIDAY OFF' ORDER BY week LIMIT 1";

                            $getstresult = mysqli_query($conn, $pstdate);

                            while ($getpst = mysqli_fetch_assoc($getstresult))
                            {
                              $pstmonthst1[] = $getpst['starttime'];
                              

                            }
                            $pstweek++;
                        
                        }
  

                        //GET EMPLOYEE NAME
                        $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid WHERE empinfo.empid='$employee'";
                        $resultname = mysqli_query($conn, $empname);

                        $empnamerow = mysqli_fetch_assoc($resultname);

                        for ($i = 0;$i < $noofweeks;$i++)
                        {
                          
                        
            

                            $query = "SELECT * FROM schedule WHERE month='$getmonth'  AND year='$year' AND empid='$employee' and week='$weeks' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                            if (new DateTime($pstmonthst1[$i]) >= new DateTime('16:00') && new DateTime($pstmonthst1[$i]) <= new DateTime('23:59'))
                            {

                                $query = "SELECT * FROM schedule WHERE month='$getmonth'  AND year='$year' AND empid='$employee' and week='$weeks' 
                                                  ORDER BY FIELD(day,  'Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                                $pstdate = "SELECT * FROM schedule WHERE month='$getmonth'  AND year='$year' AND empid='$employee' and week='$weeks' 
                                                  ORDER BY FIELD(day,  'Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                            }
                            else if (new DateTime($pstmonthst1[$i]) >= new DateTime('00:00') && new DateTime($pstmonthst1[$i]) <= new DateTime('15:59'))
                            {

                                $query = "SELECT * FROM schedule WHERE month='$getmonth'  AND year='$year' AND empid='$employee' and week='$weeks' 
                                                  ORDER BY FIELD(day,  'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')  ";

                                $pstdate = "SELECT * FROM schedule WHERE month='$getmonth'  AND year='$year' AND empid='$employee' and week='$weeks' 
                                                  ORDER BY FIELD(day,  'Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                            }

                            $result = mysqli_query($conn, $query);
                            $pstres = mysqli_query($conn, $pstdate);

                            if (mysqli_num_rows($result) > 0)
                            {

                                echo '<tr>';

                                while (($row = mysqli_fetch_assoc($result)) && ($pstrow = mysqli_fetch_assoc($pstres)))
                                {

                                    $day = $row['day'];
                                    $dates = $row['date'];
                                    $start = $row['starttime'];

                                    $GMT = 'GMT+8';
                                    $parameter = $day . ', ' . $dates . ' ' . $start . ' ' . $GMT;

                                    if ($empnamerow['status'] == 'Inactive')
                                    {

                                        echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($pstrow['date'])) . ' </span><br/>';
                                             
                                        echo ' <span class="text-danger">---</span> </td>';

                                    }
                                    else
                                    {
                                        if ($row['starttime'] == 'OFF')
                                        {
                                            echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($pstrow['date'])) . ' </span><br/>';
                                             
                                            echo ' <span class="text-danger">OFF </span></td>';
                                        }
                                        else if ($row['starttime'] == 'HOLIDAY OFF')
                                        {
                                            echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($pstrow['date'])) . ' </span><br/>';
                                             
                                            echo ' <span class="text-danger" >HOLIDAY OFF </span></td>';
                                        }
                                        else if ($row['idl'] != '')
                                        {
                                            $idl = $row['idl'];

                                            $leavequery = "SELECT * FROM `leave` WHERE idl='$idl' AND status='3' ";
                                            $leaveres = mysqli_query($conn, $leavequery);
                                            $leaverow = mysqli_fetch_assoc($leaveres);
                                            $duration = $leaverow['duration'];
      
                                            $dur = substr($duration, -2);
      
                                            
                                            if (mysqli_num_rows($leaveres) > 0)
                                            {
      
                                                if ($row['leaveduration'] == '0.5')
                                                {
      
                                                    echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($pstrow['date'])) . ' </span><br/>';
                                          
                                                    echo ' <span class="text-danger">' . $leaverow['name'] . ' Halfday</span> </td>';
      
                                                }
                                                else
                                                {
      
                                                    echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($pstrow['date'])) . ' </span><br/>';
                                          
                                                    echo ' <span class="text-danger">' . $leaverow['name'] . '  </span> </td>';
      
                                                }
      
                                            }
                                            else
                                            {
      
                                                echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                          
                                                $time = date("g:i A", strtotime($row['starttime']));
                                                echo $time;
                                                echo '</td>';
      
                                            }
      

                                        }

                                        else
                                        {
                                            $tz = new DateTimeZone('America/Los_Angeles');
                                            $PST = new DateTime($parameter);
                                            $PST->setTimezone($tz);
                                            echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($pstrow['date'])) . ' </span><br/>';
                                             

                                            echo $PST->format('g:i A');

                                            // echo   ''.date("g:i A", strtotime($timestart)).' - '.date("g:i A", strtotime($timeend)).'</td>';
                                            
                                        }

                                    }

                                }
                                echo '</tr>';
                            }
                            else
                            {

                            }
                            echo '<tr>';

                            $weeks++;

                        }

                        ?>
                                                    
                
                    </tbody>
                </table>

              </div>

              <div class="col-lg-6 col-md-12 col-sm-12 p-2">

                <table class="table table-bordered table-sm" id="attmanilamonthtable" name="manilamonthtable" style="font-size:13px;" ><!-- ATTENDANCE TABLE MANILA -->
                    <thead class="thead-dark">
                    <tr><th colspan='7'> Team Monthly Schedule </th></tr>
                      <tr>
                        
                  
                        <th scope="col" style="text-align: center"> Sunday</th>
                        <th scope="col" style="text-align: center">Monday </th>
                        <th scope="col" style="text-align: center">Tuesday </th>
                        <th scope="col" style="text-align: center"> Wednesday</th>
                        <th scope="col" style="text-align: center">Thursday </th>
                        <th scope="col" style="text-align: center">Friday </th>  
                        <th scope="col" style="text-align: center">Saturday </th>                  
                      </tr>
                    </thead>
                    <tbody>

                    
                    
                      <?php

                        $getnoweeks = "SELECT * FROM `schedule` WHERE year='$year' AND empid= '$employee' AND month='$getmonth' GROUP BY week ORDER BY week ";
                        $getnres = mysqli_query($conn, $getnoweeks);
                        $noofweeks = mysqli_num_rows($getnres);
                        $getweekno = mysqli_fetch_assoc($getnres);
                        $weeks = $getweekno['week'];

                        //GET EMPLOYEE NAME
                        $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid WHERE empinfo.empid='$employee'";
                        $resultname = mysqli_query($conn, $empname);

                        $empnamerow = mysqli_fetch_assoc($resultname);

                        for ($i = 0;$i <= $noofweeks;$i++)
                        {

                            $query = "SELECT * FROM schedule WHERE month='$getmonth'  AND year='$year' AND empid='$employee' and week='$weeks' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                            $result = mysqli_query($conn, $query);

                            if (mysqli_num_rows($result) > 0)
                            {

                                echo '<tr>';

                                while ($row = mysqli_fetch_assoc($result))
                                {

                                    if ($empnamerow['status'] == 'Inactive')
                                    {

                                        echo ' <td style="text-align:center">';
                                        echo ' <span class="text-danger">---</span> </td>';

                                    }
                                    else
                                    {
                                        if ($row['starttime'] == 'OFF')
                                        {
                                            echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                             
                                            echo ' <span class="text-danger">OFF </span></td>';
                                        }
                                        else if ($row['starttime'] == 'HOLIDAY OFF')
                                        {
                                            echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                          
                                            echo ' <span class="text-danger" >HOLIDAY OFF </span></td>';
                                        }
                                        else if ($row['idl'] != '')
                                        {

                                            $idl = $row['idl'];

                                            $leavequery = "SELECT * FROM `leave` WHERE idl='$idl' AND status='3' ";
                                            $leaveres = mysqli_query($conn, $leavequery);
                                            $leaverow = mysqli_fetch_assoc($leaveres);
                                            $duration = $leaverow['duration'];
      
                                            $dur = substr($duration, -2);
      
                                            
                                            if (mysqli_num_rows($leaveres) > 0)
                                            {
      
                                                if ($row['leaveduration'] == '0.5')
                                                {
      
                                                    echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                          
                                                    echo ' <span class="text-danger">' . $leaverow['name'] . ' Halfday</span> </td>';
      
                                                }
                                                else
                                                {
      
                                                    echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                          
                                                    echo ' <span class="text-danger">' . $leaverow['name'] . '  </span> </td>';
      
                                                }
      
                                            }
                                            else
                                            {
      
                                                echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                          
                                                $time = date("g:i A", strtotime($row['starttime']));
                                                echo $time;
                                                echo '</td>';
      
                                            }
      

                                        }

                                        else
                                        {

                                                            
                                            $dte = $row['date'];
                                            $dy = $row['day'];
                                            $tm = $row['starttime'];
                                            $dystr = date('l', strtotime($dte));


                                            $GMT = 'GMT+8';

                                            $pmtr = $dystr.', '.$dte.' '.$tm.' '.$GMT;

                                            $tz = new DateTimeZone('America/Los_Angeles');
                                            $PST = new DateTime($pmtr);
                                            $PST->setTimezone($tz);

                                            $hdate = $PST->format('m/d/Y');

                                           $util = "SELECT * FROM `tbl_login` WHERE empid='$employee' AND date='$hdate' ";
                                            $utilres = mysqli_query($conn, $util);
                                            $utilrow = mysqli_fetch_assoc($utilres);

                                            $utildate = $utilrow['date'];
                                            $utilday = date('l', strtotime($utildate));
                                            $utiltime = $utilrow['timein'];
                                    

                                            
                                            if(empty($utildate)){

                                                echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                          
                                            $time = date("g:i A", strtotime($row['timein']));
                                            // echo $hdate = $PSTph->format('g:i A');

                                            echo '--- </td>';



                                            }else{

                                            $pmtrph = $utildate.' '.$utiltime.' '.$utilgmt;


                                            $tzph = new DateTimeZone('Asia/Manila');
                                            $PSTph = new DateTime($pmtrph);
                                            $PSTph->setTimezone($tzph);


                                            echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($row['date'])) . ' </span><br/>';
                                          
                                            $time = date("g:i A", strtotime($row['starttime']));
                                            echo $hdate = $PSTph->format('g:i A');

                                            echo '</td>';
                                            
                                        
                                            }

                                        }

                                    }

                                }
                                echo '</tr>';
                            }
                            else
                            {

                            }
                            echo '<tr>';

                            $weeks++;

                        }

                        ?>
                      

                    </tbody>
                </table>

                <table class="table table-bordered table-sm" id="attpstmonthtable" name="pstmonthtable" style="font-size:13px;" hidden> <!-- ATTENDANCE TABLE MANILA -->
                    <thead class="thead-dark">
                    <tr><th colspan='7'> Team Monthly Schedule </th></tr>
                      <tr>
                        
                  
                        <th scope="col" style="text-align: center"> Sunday</th>
                        <th scope="col" style="text-align: center">Monday </th>
                        <th scope="col" style="text-align: center">Tuesday </th>
                        <th scope="col" style="text-align: center"> Wednesday</th>
                        <th scope="col" style="text-align: center">Thursday </th>
                        <th scope="col" style="text-align: center">Friday </th>  
                        <th scope="col" style="text-align: center">Saturday </th>                  
                      </tr>
                    </thead>
                    <tbody>

                    
                    
                      <?php

                        $getnoweeks = "SELECT * FROM `schedule` WHERE year='$year' AND empid= '$employee' AND month='$getmonth' GROUP BY week ORDER BY week ";
                        $getnres = mysqli_query($conn, $getnoweeks);
                        $noofweeks = mysqli_num_rows($getnres);
                        $getweekno = mysqli_fetch_assoc($getnres);
                        $weeks = $getweekno['week'];
                        $pstweek = $getweekno['week'];

                        for ($b = 0 ;$b < $noofweeks;$b++)
                        {

                            $pstdate = "SELECT * FROM schedule WHERE month='$getmonth'  AND year='$year' AND empid='$employee' and week='$pstweek' AND starttime != 'OFF' AND starttime != 'HOLIDAY OFF' ORDER BY week LIMIT 1";

                            $getstresult = mysqli_query($conn, $pstdate);

                            while ($getpst = mysqli_fetch_assoc($getstresult))
                            {
                              $pstmonthst1[] = $getpst['starttime'];
                              

                            }
                            $pstweek++;
                        
                        }


                        //GET EMPLOYEE NAME
                        $empname = "SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid WHERE empinfo.empid='$employee'";
                        $resultname = mysqli_query($conn, $empname);

                        $empnamerow = mysqli_fetch_assoc($resultname);

                        for ($i = 0;$i < $noofweeks;$i++)
                        {
                          
                        


                            $query = "SELECT * FROM schedule WHERE month='$getmonth'  AND year='$year' AND empid='$employee' and week='$weeks' ORDER BY FIELD(day, 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                            if (new DateTime($pstmonthst1[$i]) >= new DateTime('16:00') && new DateTime($pstmonthst1[$i]) <= new DateTime('23:59'))
                            {

                                $query = "SELECT * FROM schedule WHERE month='$getmonth'  AND year='$year' AND empid='$employee' and week='$weeks' 
                                                  ORDER BY FIELD(day,  'Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                                $pstdate = "SELECT * FROM schedule WHERE month='$getmonth'  AND year='$year' AND empid='$employee' and week='$weeks' 
                                                  ORDER BY FIELD(day,  'Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                            }
                            else if (new DateTime($pstmonthst1[$i]) >= new DateTime('00:00') && new DateTime($pstmonthst1[$i]) <= new DateTime('15:59'))
                            {

                                $query = "SELECT * FROM schedule WHERE month='$getmonth'  AND year='$year' AND empid='$employee' and week='$weeks' 
                                                  ORDER BY FIELD(day,  'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')  ";

                                $pstdate = "SELECT * FROM schedule WHERE month='$getmonth'  AND year='$year' AND empid='$employee' and week='$weeks' 
                                                  ORDER BY FIELD(day,  'Sunday','Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') ";

                            }

                            $result = mysqli_query($conn, $query);
                            $pstres = mysqli_query($conn, $pstdate);

                            if (mysqli_num_rows($result) > 0)
                            {

                                echo '<tr>';

                                while (($row = mysqli_fetch_assoc($result)) && ($pstrow = mysqli_fetch_assoc($pstres)))
                                {

                                    $day = $row['day'];
                                    $dates = $row['date'];
                                    $start = $row['starttime'];

                                    $GMT = 'GMT+8';
                                    $parameter = $day . ', ' . $dates . ' ' . $start . ' ' . $GMT;

                                    if ($empnamerow['status'] == 'Inactive')
                                    {

                                        echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($pstrow['date'])) . ' </span><br/>';
                                          
                                        echo ' <span class="text-danger">---</span> </td>';

                                    }
                                    else
                                    {
                                        if ($row['starttime'] == 'OFF')
                                        {
                                            echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($pstrow['date'])) . ' </span><br/>';
                                        
                                            echo ' <span class="text-danger">OFF </span></td>';
                                        }
                                        else if ($row['starttime'] == 'HOLIDAY OFF')
                                        {
                                            echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($pstrow['date'])) . ' </span><br/>';
                                        
                                            echo ' <span class="text-danger" >HOLIDAY OFF </span></td>';
                                        }
                                        else if ($row['idl'] != '')
                                        {
                                            $idl = $row['idl'];

                                            $leavequery = "SELECT * FROM `leave` WHERE idl='$idl' AND status='3' ";
                                            $leaveres = mysqli_query($conn, $leavequery);
                                            $leaverow = mysqli_fetch_assoc($leaveres);
                                            $duration = $leaverow['duration'];

                                            $dur = substr($duration, -2);

                                            if (mysqli_num_rows($leaveres) > 0)
                                            {

                                                echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($pstrow['date'])) . ' </span><br/>';
                                        
                                                echo ' <span class="text-danger">' . $leaverow['name'] . '</span> </td>';

                                            }
                                            else
                                            {

                                                $tz = new DateTimeZone('America/Los_Angeles');
                                                $PST = new DateTime($parameter);
                                                $PST->setTimezone($tz);
                                                echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($pstrow['date'])) . ' </span><br/>';
                                        

                                                // echo $PST->format('g:i A');

                                            }

                                        }

                                        else
                                        {

                                            $dte = $row['date'];
                                            $dy = $row['day'];
                                            $tm = $row['starttime'];
                                            $dystr = date('l', strtotime($dte));


                                            $GMT = 'GMT+8';

                                            $pmtr = $dystr.', '.$dte.' '.$tm.' '.$GMT;

                                            $tz = new DateTimeZone('America/Los_Angeles');
                                            $PST = new DateTime($pmtr);
                                            $PST->setTimezone($tz);

                                            $hdate = $PST->format('m/d/Y');

                                           $util = "SELECT * FROM `tbl_login` WHERE empid='$employee' AND date='$hdate' ";
                                            $utilres = mysqli_query($conn, $util);
                                            $utilrow = mysqli_fetch_assoc($utilres);

                                            $utildate = $utilrow['date'];
                                            $utilday = date('l', strtotime($utildate));
                                            $utiltime = $utilrow['timein'];
                                    

                                            
                                            if(empty($utildate)){

                                                echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($pstrow['date'])) . ' </span><br/>';
                                        
                                            $time = date("g:i A", strtotime($row['timein']));
                                            // echo $hdate = $PSTph->format('g:i A');

                                            echo '--- </td>';



                                            }else{

                                            $pmtrph = $utildate.' '.$utiltime.' '.$utilgmt;


                                            $tzph = new DateTimeZone('Asia/Manila');
                                            $PSTph = new DateTime($pmtrph);
                                            $PSTph->setTimezone($tzph);

                                            echo ' <td  style="text-align: center"><span style="border-radius: 6px;" class="p-1 text-white bg-primary">' . date("m/d/Y", strtotime($pstrow['date'])) . ' </span><br/>';
                                        
                                            $time = date("g:i A", strtotime($row['starttime']));
                                            echo $utiltime;

                                            echo '</td>';
                                            
                                        
                                            }

                                        }

                                    }

                                }
                                echo '</tr>';
                            }
                            else
                            {

                            }
                            echo '<tr>';

                            $weeks++;

                        }

                        ?>
                                                    

                    </tbody>
                </table>

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

        

        <!-- Icon Cards-->
        <!-- /.container-fluid -->
        <!-- Sticky Footer -->
<!--         <footer class="sticky-footer">
          <div class="container my-auto">
            <div class="copyright text-center my-auto">
              <span>Copyright © Your Website 2018
              </span>
            </div>
          </div>
        </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>
    $('a[data-toggle="tab"]').click(function (e) {
    e.preventDefault();
    $(this).tab('show');
});

$('a[data-toggle="tab"]').on("shown.bs.tab", function (e) {
    var id = $(e.target).attr("href");
    localStorage.setItem('selectedTab', id)
});

var selectedTab = localStorage.getItem('selectedTab');
if (selectedTab != null) {
    $('a[data-toggle="tab"][href="' + selectedTab + '"]').tab('show');
}


function schedpst(){

var schedmanila = document.getElementById('scheduleweekly');
var schedpst = document.getElementById('scheduleweeklypst');

var attmanila = document.getElementById('attendanceweekly');
var attpst = document.getElementById('attendanceweeklypst');


var timezone = document.getElementById('time');

if(timezone.value == 'pacific'){


  schedpst.hidden = false;
  schedmanila.hidden = true;


  attpst.hidden = false;
  attmanila.hidden = true;



  
}else{

schedpst.hidden = true;
  schedmanila.hidden = false;

  attpst.hidden = true;
  attmanila.hidden = false;

}

}


function attpst(){

var schedmanila = document.getElementById('schedulemanilamonthtable');
var schedpst = document.getElementById('pstschedulemonthtable');

var attmanila = document.getElementById('manilaatt');
var attpst = document.getElementById('pstatt');


var timezone = document.getElementById('timezone');
if(timezone.value == 'pacific'){



schedpst.hidden = false;
schedmanila.hidden = true;

attpst.hidden = false;
attmanila.hidden = true;



}else{

schedpst.hidden = true;
schedmanila.hidden = false;

attpst.hidden = true;
attmanila.hidden = false;

}

}




function teampacifictime(){

  var schedmanila = document.getElementById('schedteammanila');
var schedpst = document.getElementById('schedteampstw');

var attmanila = document.getElementById('attteammanila');
var attpst = document.getElementById('attteampstw');


var timezone = document.getElementById('tzwk');
if(timezone.value == 'pacific'){



schedpst.hidden = false;
schedmanila.hidden = true;

attpst.hidden = false;
attmanila.hidden = true;



}else{

schedpst.hidden = true;
schedmanila.hidden = false;

attpst.hidden = true;
attmanila.hidden = false;

}

}

function monthlyteampst(){

  var schedmanila = document.getElementById('manilamonthtable');
var schedpst = document.getElementById('pstmonthtable');

var attmanila = document.getElementById('attmanilamonthtable');
var attpst = document.getElementById('attpstmonthtable');


var timezone = document.getElementById('tzm');
if(timezone.value == 'pacific'){



schedpst.hidden = false;
schedmanila.hidden = true;

attpst.hidden = false;
attmanila.hidden = true;



}else{

schedpst.hidden = true;
schedmanila.hidden = false;

attpst.hidden = true;
attmanila.hidden = false;

}



}

  




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

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



        </script>
</body>
</html>
