<?php 

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

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


$sqlname = "SELECT * FROM empinfo WHERE empid='$empid'";
$sqlnameres = mysqli_query($conn, $sqlname);
$namerow = mysqli_fetch_assoc($sqlnameres);
$fullname = $namerow['firstname'].' '.$namerow['surname'];

if(isset($_POST['disapprove'])){

    $reason = phps($_POST['reason']);

    $reason = mysqli_real_escape_string($conn, $reason);


    $idl = $_POST['id'];
    $ptoid = $_POST['ptoid'];

    $alert = $_GET['alert'];
    $getpto = "SELECT * FROM pto WHERE id='$ptoid'";
    $ptores = mysqli_query($conn, $getpto);
    $ptorow = mysqli_fetch_assoc($ptores);
    $availablepto = $ptorow['availablepto'];
    $usedpto = $ptorow['usedpto'];
     $cancelduration = $_POST['duration'];
  
    $available = $availablepto + $cancelduration;
    $used = $usedpto - $cancelduration; 
  
  $cancel = "UPDATE `leave` SET status = '4.3', reason='$reason', approver='$empid'  WHERE idl='$idl'" ;
  $ptoupdate = "UPDATE `pto` SET usedpto='$used', availablepto='$available' WHERE id='$ptoid'";
  
  if(mysqli_query($conn, $cancel) && mysqli_query($conn, $ptoupdate)){
    $alert = '<div class="alert alert-success" role="alert">Leave successfully cancelled</div>';
  header('location: scratch.php?page_no='.$_GET['page_no'].'&alert='.$alert);
  
  
  }
  else{
    echo mysqli_error($conn);
  }

}

if(isset($_POST['approve'])){


  $id = $_POST['id'];
    $acceptsql = "UPDATE `leave` SET `status` = '3',approver='$empid' WHERE `idl`='$id' ";

    if(mysqli_query($conn, $acceptsql)){
        $alert = '<div class="alert alert-success" role="alert"> Leave successfully approved</div>';

      header('location: scratch.php?page_no='.$_GET['page_no'].'&alert='.$alert);

    }


}


      






?>
<!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 | PTO request</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">


</head>

<body id="page-top">


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

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


    <?php  ?>



    <!-- Sidebar -->

    <?php 
      $tools="active";
      $leave = "active";
      include('sidebar.php');

      
       ?>
    <div id="content-wrapper">

        <div class="container-fluid">



            <!-- Breadcrumbs-->
            <ol class="breadcrumb">

                <li class="breadcrumb-item active">PTO Request</li>
            </ol>
           
            <h4>PTO Request</h4>
            <?php echo $alert.$_GET['alert']?>
            <div class="col-sm-12 col-md-12  col-lg-12 p-3 form-inline">
                <form method="GET" action="scratch.php">
                
                    <button class="btn btn-primary" type="submit" name="filter" ><i class="fa fa-filter"></i> Filter </button>  &nbsp 
                    <select name="status" id="status" class="form-control">
                    <?php 
                    switch($_GET['status']){

                        case 'All': 
                        $all = "selected";
                        break;
                        case '2': 
                        $pending = "selected";
                        break;
                        case '3': 
                        $approved = "selected";
                        break;
                        case '4.1':
                        $declined = "selected";
                        break;



                    }
                    ?>
                    <option value="All" <?php echo $all ?>> All </option>
                    <option value="2" <?php echo $pending ?>> Pending </option>
                    <option value="3" <?php echo $approved ?>> Approved </option>
                    <option value="4.1" <?php echo $declined ?>> Declined </option>
        
                    
                    </select> &nbsp
                    <select name="employee" id="employee" class="form-control">
                    <option value="All"> All </option>
            
                    <?php 
                    $statsql ="SELECT * FROM empinfo JOIN empdetails ON empinfo.empid = empdetails.detailid ";
                    $statres = mysqli_query($conn, $statsql);

                    while($statrow = mysqli_fetch_assoc($statres)){

                        if($statrow['empid'] == $_GET['employee']){

                            echo'<option value="'.$statrow['empid'].'" selected>'.$statrow['empid'].'   '.$statrow['firstname'].' '.$statrow['surname'].'</option>';

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

                        }
            

                       


                    }
                    ?>
                    
                    </select>
                    <input type="hidden" name="page_no" value="<?php echo $_GET['page_no']?>">
     
                </form>

            </div>
            <div class="col-sm-12 col-md-12  col-lg-12">


            <table class="table">
                <thead class="thead-dark">
                <tr>
                    <th>Employee ID</th>
                    <th>Employee Name</th>
                    <th>Status</th>
                    <th>Type</th>
                    <th>Date</th>
                    <th>Duration</th>
                    <th>Team Head</th>
                    <th>HR</th>
                    <th>Manager</th>
                    <th>Action</th>

                </tr>
                </thead>
                <tbody>
                <?php
       
                if (isset($_GET['page_no']) && $_GET['page_no']!="") {
                    $page_no = $_GET['page_no'];
                    } else {
                        $page_no = 1;
                        }

                    $total_records_per_page = 8;
                    $offset = ($page_no-1) * $total_records_per_page;
                    $previous_page = $page_no - 1;
                    $next_page = $page_no + 1;
                    $adjacents = "2"; 

              

                    $result_count = mysqli_query($conn,"SELECT COUNT(*) As total_records FROM `leave` WHERE  status IN ('2','3','4.1','4.2','4.3')" );
                    $total_records = mysqli_fetch_array($result_count);
                    $total_records = $total_records['total_records'];
                    $total_no_of_pages = ceil($total_records / $total_records_per_page);
                    $second_last = $total_no_of_pages - 1; // total page minus 1


                    $leaverequest = "SELECT *, `leave`.status AS 'stat' FROM `leave` JOIN empdetails ON `leave`.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE `leave`.status IN ('2','3','4.1','4.2','4.3') LIMIT $offset, $total_records_per_page ";
   /////////////////////////////////////////////////////////////////////////////
                                    
if(isset($_GET['filter'])){
    $leavestat = $_GET['status'];
    $employee = $_GET['employee'];
  
    if($leavestat  =='All' && $employee  == 'All'){
       $leaverequest = "SELECT *, `leave`.status AS 'stat' FROM `leave` JOIN empdetails ON `leave`.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE `leave`.status IN ('2','3','4.1','4.2','4.3') LIMIT $offset, $total_records_per_page  ";
 


    }else if(isset($employee) && $leavestat == 'All' ){

      

           $leaverequest = "SELECT *, `leave`.status AS 'stat' FROM `leave` JOIN empdetails ON `leave`.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE  `empinfo`.empid = '$employee' AND `leave`.status != '5' ";
    
         


    

        



    }

    else if(isset($leavestat) &&  $employee  =='All' ){

        if($leavestat == '4.1'){

             $leaverequest = "SELECT *, `leave`.status AS 'stat' FROM `leave` JOIN empdetails ON `leave`.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE  `leave`.status >= '4.1'  AND `leave`.status != '5'  ";
    


        } else if($leavestat == '2'){

           $leaverequest = "SELECT *, `leave`.status AS 'stat' FROM `leave` JOIN empdetails ON `leave`.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE  `leave`.status = '$leavestat'  ";
    

        }else if($leavestat == '3'){

            $leaverequest = "SELECT *, `leave`.status AS 'stat' FROM `leave` JOIN empdetails ON `leave`.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE  `leave`.status = '$leavestat'  ";
    

        }






        



    }

    else if(isset($leavestat) &&  isset($employee) ){

        
        if($leavestat == '4.1'){

            $leaverequest = "SELECT *, `leave`.status AS 'stat' FROM `leave` JOIN empdetails ON `leave`.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE  `leave`.status >= '4.1' AND `leave`.empid='$employee' AND `leave`.status != '5' ";
    


        } else if($leavestat == '2'){

            $leaverequest = "SELECT *, `leave`.status AS 'stat' FROM `leave` JOIN empdetails ON `leave`.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE  `leave`.status = '$leavestat'  AND  `leave`.empid='$employee'";
    

        }else if($leavestat == '3'){

             $leaverequest = "SELECT *, `leave`.status AS 'stat' FROM `leave` JOIN empdetails ON `leave`.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE  `leave`.status = '$leavestat' AND `leave`.empid='$employee'";
    

        }





    }

                            



}
   
   
   
   /////////////////////////////////////////////////


                    $leaverequestres = mysqli_query($conn, $leaverequest);
                    while($rowrequest = mysqli_fetch_assoc($leaverequestres)){

                        
                                    
                                $leaveid = $rowrequest['type'];
                                $id = $rowrequest['idl'];
                                $ptoid = $rowrequest['ptoid'];
                                $leavesql = "SELECT * FROM pto WHERE id='$ptoid'";
                                $leavequery = mysqli_query($conn, $leavesql);
                                $ptorow1 = mysqli_fetch_assoc($leavequery);

                                $AP = $ptorow1['availablepto'];
                            


                                
                                echo '
                                
                                <td>'.$rowrequest['empid'].'</td>
                                <td>'.$rowrequest['firstname'].' '.$rowrequest['surname'].'</td>
                    

                                
                                ';

                                if($rowrequest['stat'] == '3'){
                                echo ' <td>Approved</td> ';
                                }else if($rowrequest['stat'] == '5'){
                                echo ' <td>Cancelled</td> ';
                                }else if($rowrequest['stat'] == '4.3' || $rowrequest['stat'] == '4.2' || $rowrequest['stat'] == '4.1'){
                                echo ' <td>Declined</td> ';
                                }else{

                                echo ' <td>Pending Approval</td> ';

                                }
                                echo'
                                <td>'.$rowrequest['name'].'</td>
                                <td>'.date('m/d/Y', strtotime($rowrequest['datefrom'])).' - '.date('m/d/Y', strtotime($rowrequest['dateto'])).'</td>
                                <td>'.$rowrequest['duration'].'</td>
                                
                                ';

                                if($rowrequest['stat'] == '0'){
                                $status = 'Pending Approval';
                                echo ' <td>Pending</td> ';
                                echo ' <td>Pending</td> ';
                                echo ' <td>Pending</td> ';
                                }else if($rowrequest['stat'] == '1'){
                                $status = 'Pending Approval';
                                echo ' <td>Approved
                                <br>'.$rowrequest['tl'].'
                                
                                </td> ';
                                echo ' <td>Pending</td> ';
                                echo ' <td>Pending</td> ';
                                }

                                
                                else if($rowrequest['stat'] == '2'){
                                $status = 'Pending Approval';
                                
                                echo ' <td>Approved
                                <br>'.$rowrequest['tl'].'
                                </td> ';
                                echo ' <td>Approved
                                <br>'.$rowrequest['hr'].'</td>
                                ';
                                echo ' <td>Pending</td> ';
                                
                                }

                                
                            else if($rowrequest['stat'] == '3'){
                                $status = 'Approved';
                                echo ' <td>Approved
                                <br>'.$rowrequest['tl'].'
                                </td> ';
                                echo ' <td>Approved
                                <br>'.$rowrequest['hr'].'</td>
                                ';
                                echo ' <td>Approved
                                <br>'.$rowrequest['approver'].'
                                </td> ';
                                }

                                else if($rowrequest['stat'] == '5'){
                                $status = 'Cancelled';
                                echo ' <td>Cancelled</td> ';
                                echo ' <td>Cancelled</td> ';
                                echo ' <td>Cancelled</td> ';
                                }
                                else if($rowrequest['stat'] == '4.1'){
                                $status = 'Declined';
                                echo ' <td>Declined <br>'.$rowrequest['tl'].'
                                </td> ';
                                echo ' <td>Declined</td> ';
                                echo ' <td>Declined</td> ';
                                }

                                else if($rowrequest['stat'] == '4.2'){
                                    $status = 'Declined';
                        
                                    echo ' <td>Approved <br>'.$rowrequest['tl'].'';
                                    echo ' <td>Declined  <br>'.$rowrequest['hr'].'
                                    </td> ';
                                    echo ' <td>Declined</td> ';
                                }

                                else if($rowrequest['stat'] == '4.3'){
                                    $status = 'Declined';
                            
                                    echo ' <td>Approved <br>'.$rowrequest['tl'].'';
                                    echo ' <td>Approved  <br>'.$rowrequest['hr'].'
                                    </td> ';
                                    echo ' <td>Declined <br>'.$rowrequest['approver'].'
                                    </td> ';
                                
                                }

                                


                                
                            
                                ?>
                        <td>
                            <a href="#view<?php echo $id;?>" data-toggle="modal">
                                <button type='button' class='btn btn-primary btn-sm'> <i class="fa fa-eye"></i>
                                </button>
                            </a>

                            <small>|</small>


                            <?php 

                                $sdate = strtotime($rowrequest['datefrom']);
                                $tdate = strtotime(date('Y-m-d'));



                                if($rowrequest['stat'] == '4.3' || $rowrequest['stat'] == '4.1' || $rowrequest['stat'] == '4.2' || $rowrequest['stat'] == '3'  ) {

                                    echo'
                                    <button type="button" class="btn btn-success btn-sm" disabled> <i class="fa fa-check"></i>   </button> 
                                    ';

                                }else{

                                    
                                    echo'
                                    <a href="#accept'.$id.'" data-toggle="modal">
                                    <button type="button" class="btn btn-success btn-sm"> <i class="fa fa-check"></i>   </button> 
                                    </a>
                                    ';


                                }



                                

                    /*             if(($sdate > $tdate) && ( $rowrequest['stat'] == '1' || $rowrequest['stat'] == '2' || $rowrequest['stat'] == '3')){


                                echo'
                                <button type="button" class="btn btn-success btn-sm" disabled> <i class="fa fa-check"></i>   </button> 
                                ';
                                }else if(($sdate < $tdate) && ( $rowrequest['stat'] == '1' || $rowrequest['stat'] == '2' || $rowrequest['stat'] == '3')){

                                echo'
                                <button type="button" class="btn btn-success btn-sm" disabled> <i class="fa fa-check"></i>   </button> 
                                ';

                                }

                                else{
                                echo'
                                <a href="#accept'.$id.'" data-toggle="modal">
                                <button type="button" class="btn btn-success btn-sm" > <i class="fa fa-check"></i>   </button> 
                                </a>

                                ';


                                } */

                                ?>



                            <small>| </small>


                            <?php 

                            $sdate = strtotime($rowrequest['datefrom']);
                            $tdate = strtotime(date('Y-m-d'));

                            if($rowrequest['stat'] == '4.1' || $rowrequest['stat'] == '4.2' || $rowrequest['stat'] == '4.3' ){




                            echo'
                            <button type="button" class="btn btn-danger btn-sm" disabled> <i class="fa fa-close"></i>   </button> 
                            ';
                        }

                            else{

                            echo'<a href="#reject'.$id.'" data-toggle="modal">
                            <button type="button" class="btn btn-danger btn-sm" > <i class="fa fa-close"></i>   </button> 
                            </a>';
                            


                            }

                            ?>
                            <small>| </small>

                            <button type="button" class="btn btn-warning btn-sm text-white"
                                onclick="printContent('leaveform<?php echo $id?>')"> <i class="fas fa-print"></i>
                                </button>









                        </td>
                    </tr>

                    <div id="reject<?php echo $id; ?>" class="modal fade" role="dialog">
                        <form method="post" class="form-horizontal" role="form">
                            <div class="modal-dialog modal-md modal-dialog-centered">
                                <!-- Modal content-->
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h4 class="modal-title">Decline Leave</h4>
                                        <button type="button" class="close" data-dismiss="modal">&times;</button>

                                    </div>
                                    <div class="modal-body">
                                        <input type="hidden" name="id" value="<?php echo $id; ?>">
                                        <div class="row">
                                            <div class="col-6">
                                                <label> Employee ID </label>
                                                <input type="text" name="empid" class="form-control"
                                                    value="<?php echo $rowrequest['empid']; ?>" readonly>
                                            </div>
                                            <div class="col-6">
                                                <label> Leave Type </label>
                                                <input type="text" name="type" class="form-control"
                                                    value="<?php echo $rowrequest['name']; ?>" readonly>
                                            </div>

                                            <div class="col-6">
                                                <label>Date </label>
                                                <input type="text" name="daterange" class="form-control"
                                                    value="<?php echo date('m/d/Y', strtotime($rowrequest['datefrom'])).' - '.date('m/d/Y', strtotime($rowrequest['dateto'])) ?>"
                                                    readonly>
                                            </div>
                                            <div class="col-6">
                                                <label> Duration </label>
                                                <input type="text" name="duration" class="form-control"
                                                    value="<?php echo $rowrequest['duration']; ?>" readonly>
                                            </div>

                                            <div class="col-12">
                                                <label> Reason </label>
                                                <textarea name="reason" id="" cols="20" rows="8"
                                                    placeholder="Reason" class="form-control" required></textarea>
                                                <input type="hidden" name="ptoid" value="<?php echo $ptoid; ?>">


                                            </div>

                                        </div>
                                    </div>

                                    <div class="modal-footer">
                                        <button type="submit" class="btn btn-success" name="disapprove"><i
                                                class="fas fa-check"> </i> Yes</button>
                                        <button type="button" class="btn btn-danger" data-dismiss="modal"><i
                                                class="fas fa-close"> </i> Cancel</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>


                    <div id="view<?php echo $id; ?>" class="modal fade" role="dialog">
                        <form method="post" class="form-horizontal" role="form">
                            <div class="modal-dialog modal-md modal-dialog-centered">
                                <!-- Modal content-->
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h4 class="modal-title"> View Leave</h4>
                                        <button type="button" class="close" data-dismiss="modal">&times;</button>

                                    </div>

                                    <div class="modal-body">
                                        <?php echo $rowrequest['firstname'].' '.$rowrequest['surname']?>
                                        <input type="hidden" name="id" value="<?php echo $id; ?>">
                                        <div class="row">

                                            <div class="col-6">
                                                <label> Employee ID </label>
                                                <input type="text" name="empid" class="form-control"
                                                    value="<?php echo $rowrequest['empid']; ?>" readonly>
                                            </div>
                                            <div class="col-6">
                                                <label> Leave Type </label>
                                                <input type="text" name="type" class="form-control"
                                                    value="<?php echo $rowrequest['name']; ?>" readonly>
                                            </div>

                                            <div class="col-6">
                                                <label>Date </label>
                                                <input type="text" name="daterange" class="form-control"
                                                    value="<?php echo date('m/d/Y', strtotime($rowrequest['datefrom'])).' - '.date('m/d/Y', strtotime($rowrequest['dateto'])) ?>"
                                                    readonly>
                                            </div>
                                            <div class="col-6">
                                                <label> Duration </label>
                                                <input type="text" name="duration" class="form-control"
                                                    value="<?php echo $rowrequest['duration']; ?>" readonly>
                                            </div>

                                            <div class="col-12">
                                                <label> Notes </label>
                                                <textarea name="reason" id="" cols="20" rows="8"
                                                    placeholder="Reason" class="form-control" required
                                                    readonly><?php echo $rowrequest['description']; ?></textarea>

                                            </div>

                                        </div>
                                    </div>

                                    <div class="modal-footer">

                                        <button type="button" class="btn btn-danger" data-dismiss="modal"><i
                                                class="fas fa-close"> </i> Cancel</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                        

                    </div>



                    <div id="accept<?php echo $id; ?>" class="modal fade" role="dialog">
                        <form method="post" class="form-horizontal" role="form">
                            <div class="modal-dialog modal-md modal-dialog-centered">
                                <!-- Modal content-->
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h4 class="modal-title">Approve Leave</h4>
                                        <button type="button" class="close" data-dismiss="modal">&times;</button>

                                    </div>
                                    <div class="modal-body">
                                        <input type="hidden" name="id" value="<?php echo $id; ?>">

                                        Are you sure you want to approve <?php echo $rowrequest['empid']?> leave
                                        request?


                                    </div>

                                    <div class="modal-footer">
                                        <button type="submit" class="btn btn-success" name="approve"><i
                                                class="fas fa-check"> </i> Yes</button>
                                        <button type="button" class="btn btn-danger" data-dismiss="modal"><i
                                                class="fas fa-close"> </i> Cancel</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>

                    <div id="leaveform<?php echo $id; ?>" class="leaveform" hidden>
                        <div class="container">
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="align-middle">
                                        <img src="../images/logo.jpg" class="float-left p-3" alt="" height="150px"
                                            width="150px">
                                        <br>

                                        <h1 style="font-size: 60px"> &nbsp ATV International ROHQ</h1>
                                        <br>
                                        <hr style="border: 2px solid black">

                                    </div>

                                    <h2 class="text-center">LEAVE FORM</h2>
                            

                                </div>
                                
                                <div class="col-4 p-3">
                                    <b>NAME: <?php echo $rowrequest['firstname'].' '.$rowrequest['surname'] ?> </b>
                                </div>
                                <div class="col-3 p-3">
                                    <b>EMPLOYEE ID: <?php echo $rowrequest['empid'] ?> </b>
                                </div>
                                <div class="col-5 p-3">
                                    <b>TEAM / DEPARTMENT: <?php echo $rowrequest['team'] ?> </b>
                                </div>

                                <div class="col-6">
                                    <div class="row p-1">
                                
                
                        

                                        <div class="col-6 p-1">
                                        Emergency Leave
                                        </div>

                                        <?php 
                                        if($rowrequest['name'] == 'Emergency Leave'){

                                            echo '



                                            <div class="col-2 p-1 border border-dark text-center">
                                            <i class="fa fa-check"> </i>
                                    
                                            </div>
                                            
                                            ';

                                        }else{
                                            echo'

                                            <div class="col-2 p-1 border border-dark">
                                        
                                            </div>
                                            
                                            ';


                                        }
                                        ?>



                                        <div class="col-6 p-1 ">
                                        Sick Leave
                                        </div>

                                        <?php 
                                        if($rowrequest['name'] == 'Sick Leave'){

                                            echo '


                                            <div class="col-2 p-1 border border-dark text-center">
                                            <i class="fa fa-check"> </i>
                                    
                                            </div>
                                            
                                            ';

                                        }else{
                                            echo'
                
                                            <div class="col-2 p-1 border border-dark">
                                        
                                            </div>
                                            
                                            ';


                                        }
                                        ?>

                                        <div class="col-6 p-1">
                                        Vacation Leave
                                        </div>
                                        
                                        <?php 
                                        if($rowrequest['name'] == 'Vacation Leave'){

                                            echo '

                
                                            <div class="col-2 p-1 border border-dark text-center">
                                            <i class="fa fa-check"> </i>
                                    
                                            </div>
                                            
                                            ';

                                        }else{
                                            echo'
                        
                                            <div class="col-2 p-1 border border-dark">
                                        
                                            </div>
                                            
                                            ';


                                        }
                                        ?>


                                        <div class="col-6 p-1">
                                        LWOP - Unpaid Leave
                                        </div>
                                        
                                        <?php 
                                        if($rowrequest['name'] == 'LWOP - Unpaid Leave'){

                                            echo '


                                            <div class="col-2 p-1 border border-dark text-center">
                                            <i class="fa fa-check"> </i>
                                    
                                            </div>
                                            
                                            ';

                                        }else{
                                            echo'

                                            <div class="col-2 p-1 border border-dark">
                                        
                                            </div>
                                            
                                            ';


                                        }
                                        ?>

                                        <?php
                                            $leave1 = "SELECT * FROM pto WHERE name IN('Magna Carta','Bereavement') GROUP BY name ";
                                                $leaveres1 = mysqli_query($conn, $leave1);
                                                while($leaverow1 = mysqli_fetch_assoc($leaveres1)){

                                                    echo'<div class="col-6 p-1">'.$leaverow1['name'].' Leave </div>';
                                                    
                                
                                                if($leaverow1['name'] == $rowrequest['type']){

                                                    echo '

                        
                                                    <div class="col-2 p-1 border border-dark text-center">
                                                    <i class="fa fa-check"> </i>
                                            
                                                    </div>
                                                    
                                                    ';

                                                }else{
                                                    echo'
                
                                                    <div class="col-2 p-1 border border-dark">
                                                
                                                    </div>
                                                    
                                                    ';


                                                }
                                            

                                                }
                                        
                                        ?>




                                    </div>

                                    <br>
                                </div>
                                <div class="col-6">
                                    <div class="row p-1">


                                        <?php
                                                $leave2 = "SELECT * FROM pto WHERE name != 'Paid Time Off' AND name !='Magna Carta' AND name != 'Bereavement' GROUP BY name ";
                                                $leaveres2 = mysqli_query($conn, $leave2);
                                                while($leaverow2 = mysqli_fetch_assoc($leaveres2)){
                                                    echo '<div class="col-6 p-1">'.$leaverow2['name'].' Leave </div>';

                                                    if($leaverow2['name'] == $rowrequest['type']){

                                                        echo '

                                    
                                                        <div class="col-2 p-1 border border-dark text-center">
                                                        <i class="fa fa-check"> </i>
                                                
                                                        </div>
                                                        
                                                        ';

                                                    }else{
                                                        echo'
                                
                                                        <div class="col-2 p-1 border border-dark">
                                                    
                                                        </div>
                                                        
                                                        ';


                                                    }
                                                


                                                

                                                
                                                }
                                        
                                        ?>
                                        <div class="col-12 p-1 ">
                                        Note/Comment/Reason: <u><?php echo $rowrequest['description']?></u>
                                
                                        
                                                
                                        </div>


                                    </div>
                                </div>




                
                                <div class="col-12 border border-secondary">
                                    <div class="row">
                                        <div class="col-6">
                                            LEAVE DATE: <?php echo date('m/d/Y', strtotime($rowrequest['datefrom'])).'-'.date('m/d/Y', strtotime($rowrequest['dateto']))?>

                                        </div>
                                        <div class="col-6">

                                            # of Approved Leave <?php echo $rowrequest['duration']?>

                                        </div>
                                    </div>



                                </div>

                                <div class="col-12 border-right border-left border-bottom border-secondary">
                                    <div class="row">
                                        <div class="col-6 p-3">
                                            EMPLOYEE'S SIGNATURE OVER PRINTED NAME <br>
                                            DATE FILED

                                        </div>
                                        <div class="col-6">
                                                <br>


                                            :  <?php echo '  '.$rowrequest['firstname'].' '.$rowrequest['surname']?><br>
                                            :  <?php echo '  '.date('m/d/Y', strtotime($rowrequest['datefiled']))?>

                                        </div>
                                    </div>



                                </div>
                                <div class="col-12 border-right border-left border-bottom border-secondary">
                                    <div class="row">
                                        <div class="col-6">
                                        <?php 
                                        $tl = $rowrequest['tl'];
                                            $tlsql ="SELECT * FROM empinfo WHERE empid='$tl'";
                                            $tlres = mysqli_query($conn, $tlsql);
                                            $tlrow = mysqli_fetch_assoc($tlres);
                                        ?>
                                            NOTED BY: <br>
                                            <?php echo '  '.$tlrow['firstname'].' '.$tlrow['surname']?><br>
                                            DATE FILED


                                        </div>
                                        <div class="col-6">

                                            <br>
                                            : <br>
                                            : <?php echo '  '.date('m/d/Y', strtotime($rowrequest['datefiled']))?>

                                        </div>
                                    </div>



                                </div>
                                <div class="col-12 border-right border-left border-bottom border-secondary">
                                    <div class="row">
                                        <div class="col-6 p-3">

                                            Yves Emor G. Marcelo <br>
                                            DATE FILED

                                        </div>
                                        <div class="col-6">
                                                <br>

                                            : <br>
                                            : <?php echo '  '.date('m/d/Y', strtotime($rowrequest['datefiled']))?>

                                        </div>
                                    </div>



                                </div>

                                <div class="col-12 border-right border-left border-bottom border-secondary">
                                    <div class="row">
                                        <div class="col-6 p-3">

                                            Marvin Cataquis<br>
                                            DATE FILED

                                        </div>
                                        <div class="col-6">
                                                <br>

                                            : <br>
                                            : <?php echo '  '.date('m/d/Y', strtotime($rowrequest['datefiled']))?>

                                        </div>
                                    </div>



                                </div>


                                <div class="col-12 p-4">

                                    <?php 
                                    if($rowrequest['stat'] == '3'){
                                        $approve = '<i class="fa fa-check"></i>';
                                        $disapprove ='';
                                    }else if($rowrequest['stat'] == '0' || $rowrequest['stat'] == '1' || $rowrequest['stat'] == '2'){
                                        $approve = '';
                                        $disapprove ='';

                                    }
                                    
                                    else{
                                        $disapprove ='<i class="fa fa-check"></i>';
                                        $approve = '';
                                    }
                                    ?>
                                    <p class="text-center">( FOR HUMAN RESOURCES ONLY )</p>
                                
                                    (<?php echo $approve?> ) Approved (<?php echo $disapprove?> ) Disapproved (If Approval is NOT
                                    RECOMMENDED, attach
                                    explanation) <br> <br>

                                    <div class="border border-round border-dark p-2" style="height: 100px">

                                    <?php echo $rowrequest['reason'] ?>

                                    </div>
                                    
                                </div>
                            


                                <div class="col-6">
                            
                                    _____________________________________<br>

                                    Human Resources Department/Date
                                
                                    <br>
                                    <br>

                                    Leave File Number <u><?php echo $rowrequest['idl']?></u>


                                </div>
                                <div class="col-6 text-right">
                            
                                    <u><?php echo '&nbsp &nbsp &nbsp
                                    &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
                                    ' .$AP.'&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp'; ?></u><br>
                                    REMAINING PTO CREDITS

                                    <br>
                                
                                    <br>
                                    Date Hire    <u><?php echo date('m/d/Y', strtotime($rowrequest['hireddate']))?></u>
                                </div>


                                <div class="col-12 p-3 text-center">
                                    <hr style="border: 2px solid black">
                                    <b>ATV International ROHQ </b> <br>
                                    <small>3rd floor Yupangco Bldg. 1606 Investment Dr cor Trade Ave., <br>
                                        Madrigal Business Park Ayala Alabang Muntinlupa City <br>
                                        Tel No. 632.551.55.88
                                    </small>

                                </div>




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

        <?php }



            mysqli_close($conn);
            ?>
                </tbody>
                </table>

                <div style='padding: 10px 20px 0px; border-top: dotted 1px #CCC;'>
                <p class="text-muted">Page <?php echo $page_no." of ".$total_no_of_pages; ?></p>
                </div>

                <nav aria-label="Page navigation example">

                    <ul class="pagination justify-content-start">
                        <?php // if($page_no > 1){ echo "<li><a href='?page_no=1'>First Page</a></li>"; } ?>
                        
                        <li class="page-item  <?php if($page_no <= 1){ echo " disabled"; } ?>">
                        <a  class="page-link" <?php if($page_no > 1){ echo "href='?page_no=$previous_page'"; } ?>>Previous</a>
                        </li>
                        
                        <?php 
                            if ($total_no_of_pages <= 10){  	 
                                for ($counter = 1; $counter <= $total_no_of_pages; $counter++){
                                    if ($counter == $page_no) {
                                echo "<li class='page-item active'><a class='page-link'>$counter</a></li>";	
                                        }else{
                                echo "<li class='page-item'><a class='page-link' href='?page_no=$counter'>$counter</a></li>";
                                        }
                                }
                            }
                            elseif($total_no_of_pages > 10){
                                
                            if($page_no <= 4) {			
                            for ($counter = 1; $counter < 8; $counter++){		 
                                    if ($counter == $page_no) {
                                echo "<li class='page-item active'><a class='page-link'>$counter</a></li>";	
                                        }else{
                                echo "<li class='page-item'><a class='page-link' href='?page_no=$counter'>$counter</a></li>";
                                        }
                                }
                                echo "<li class='page-item'><a class='page-link'>...</a></li>";
                                echo "<li class='page-item'><a  class='page-link' href='?page_no=$second_last'>$second_last</a></li>";
                                echo "<li class='page-item'><a class='page-link'  href='?page_no=$total_no_of_pages'>$total_no_of_pages</a></li>";
                                }

                            elseif($page_no > 4 && $page_no < $total_no_of_pages - 4) {		 
                                echo "<li class='page-item'><a class='page-link' href='?page_no=1'>1</a></li>";
                                echo "<li class='page-item'><a class='page-link' href='?page_no=2'>2</a></li>";
                                echo "<li class='page-item'><a class='page-link'>...</a></li>";
                                for ($counter = $page_no - $adjacents; $counter <= $page_no + $adjacents; $counter++) {			
                                if ($counter == $page_no) {
                                echo "<li class='page-item active'><a class='page-link'>$counter</a></li>";	
                                        }else{
                                echo "<li class='page-item'><a class='page-link' href='?page_no=$counter'>$counter</a></li>";
                                        }                  
                            }
                            echo "<li class='page-item'><a class='page-link'>...</a></li>";
                            echo "<li class='page-item'><a class='page-link' href='?page_no=$second_last'>$second_last</a></li>";
                            echo "<li class='page-item'><a class='page-link' href='?page_no=$total_no_of_pages'>$total_no_of_pages</a></li>";      
                                    }
                                
                                else {
                                echo "<li class='page-item'><a class='page-link' href='?page_no=1'>1</a></li>";
                                echo "<li class='page-item'><a class='page-link' href='?page_no=2'>2</a></li>";
                                echo "<li class='page-item'><a class='page-link' >...</a></li>";

                                for ($counter = $total_no_of_pages - 6; $counter <= $total_no_of_pages; $counter++) {
                                if ($counter == $page_no) {
                                echo "<li class='page-item active'><a class='page-link' >$counter</a></li>";	
                                        }else{
                                echo "<li class='page-item'><a class='page-link' href='?page_no=$counter'>$counter</a></li>";
                                        }                   
                                        }
                                    }
                            }
                        ?>
                        
                        <li class="page-item  <?php if($page_no >= $total_no_of_pages){ echo " disabled'"; } ?>" >
                        <a class='page-link' <?php if($page_no < $total_no_of_pages) { echo "href='?page_no=$next_page'"; } ?>>Next</a>
                        </li>
                        <?php if($page_no < $total_no_of_pages){
                            echo "<li class='page-item' ><a class='page-link' href='?page_no=$total_no_of_pages'>Last &rsaquo;&rsaquo;</a></li>";
                            } ?>
                    </ul>
                </nav>

                



            </div>














            <!-- Icon Cards-->

            <!-- /.container-fluid -->

            <!-- Sticky Footer -->


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

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

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

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

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

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

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

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

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

    <script>
    function printContent(el) {

        var css = '@page { size: auto }',
            head = document.head || document.getElementsByTagName('head')[0],
            style = document.createElement('style');

        style.type = 'text/css';
        style.media = 'print';

        if (style.styleSheet) {
            style.styleSheet.cssText = css;
        } else {
            style.appendChild(document.createTextNode(css));
        }

        head.appendChild(style);



        var restorepage = document.body.innerHTML;
        var printcontent = document.getElementById(el).innerHTML;
        document.body.innerHTML = printcontent;
        window.print();
        document.body.innerHTML = restorepage;
    }
    </script>

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

        $('#preloader').fadeOut();
    }); //document ready
    </script>
</body>

</html>