<?php 
    include'include/session.php';
    $result=mysql_query("SELECT * FROM school_staff_leave WHERE staffID='$staffID' ORDER BY applied DESC");
?>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Leave History | Procurement | WAKA CMEC</title>
    <link rel="shortcut icon" href="../../../assets/img/logo.png" />
    <link rel="stylesheet" href="../../../assets/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Slab:300,400|Roboto:300,400,700">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
    <link rel="stylesheet" href="../../../assets/fonts/font-awesome.min.css">
    <link rel="stylesheet" href="../../../assets/css/ebs-simple-login-form1.css">
    <link rel="stylesheet" href="../../../assets/css/ebs-simple-login-form2.css">
    <link rel="stylesheet" href="../../../assets/css/ebs-simple-login-form.css">
    <link rel="stylesheet" href="../../../assets/css/FPE-Gentella-form-elements.css">
    <link rel="stylesheet" href="../../../assets/css/FPE-Gentella-form-elements1.css">
    <link rel="stylesheet" href="../../../assets/css/MUSA_no-more-tables.css">
    <link rel="stylesheet" href="../../../assets/css/MUSA_no-more-tables1.css">
    <link rel="stylesheet" href="../../../assets/css/MUSA_panel-table.css">
    <link rel="stylesheet" href="../../../assets/css/MUSA_panel-table1.css">
    <link rel="stylesheet" href="../../../assets/css/nav.css">
    <link rel="stylesheet" href="../../../assets/css/Navbar-Fixed-Side1.css">
    <link rel="stylesheet" href="../../../assets/css/Profile-Edit.css">
    <link rel="stylesheet" href="../../../assets/css/Profile-Edit1.css">
    <link rel="stylesheet" href="../../../assets/css/Responsive-Form.css">
    <link rel="stylesheet" href="../../../assets/css/Responsive-Form1.css">
    <link rel="stylesheet" href="../../../assets/css/Sidebar-Menu.css">
    <link rel="stylesheet" href="../../../assets/css/Sidebar-Menu1.css">
    <link rel="stylesheet" href="../../../assets/css/styles.css">
    <link rel="stylesheet" href="../../../assets/css/Data-Table.css">
    <link rel="stylesheet" href="../../../assets/css/Data-Table1.css">
    <link rel="stylesheet" href="../../../assets/css/bootstrap-datetimepicker.min.css"  media="screen">
</head>

<body style="background-color:rgb(252,252,252);">
    <div></div>
    <div id="wrapper">
        <div id="sidebar-wrapper" style="background-color:rgb(21,164,113);">
            <ul class="sidebar-nav">
                <li class="sidebar-brand" style="color:rgb(255,255,255);"> 
                    <a href="#" style="font-weight:bold;color:rgb(254,254,254);">Proc | WAKA CMEC</a>
                </li>
                <li style="color:rgb(252,253,254);"> 
                    <a class="col-md-12" href="index.php" style="color:rgb(255,255,255);">
                        <p style="float:left;">Dashboard</p> 
                        <p style="float:left;text-align:center;padding:0px;margin:0px;color:red;" id="messageCounter"></p>
                    </a>
                    <a href="view-item.php" style="color:rgb(255,255,255);">View Items</a>
                    <a href="view-requisitoned.php" style="color:rgb(255,255,255);"> View Requisitions </a>
                    <a href="view-received.php" style="color:rgb(255,255,255);">View Received</a>
                    <a href="view-supplier.php" style="color:rgb(255,255,255);">View Supplier</a>
                    <a href="product-stock.php" style="color:rgb(255,255,255);" title="Items running out of stock">
                        <p class="bg-danger text-danger" title="Items running out of stock"  id="StockCounter"></p>
                    </a>
                </li>
            </ul>
        </div>
        <div class="page-content-wrapper">
            <div class="container-fluid"><a class="btn btn-link" role="button" href="#menu-toggle" id="menu-toggle"><i class="fa fa-bars"></i></a>
                <div class="dropdown" style="width:150px;float:right;margin-top:5px;">
                    <button class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false" type="button" style="width:150px;background-color:rgb(252,252,252);color:rgb(20,19,19);border:1px solid rgb(252,252,252);text-align:right;"><i class="fa fa-user"></i> &nbsp; <?php echo $pro;?> <span class="caret"></span></button>
                    <ul role="menu" class="dropdown-menu dropdown-menu-right">
                        <li role="presentation"><a href="settings.php"><i class="fa fa-wrench"></i> &nbsp;Settings</a></li>
                        <li role="presentation"><a href="../validate/logout.php"><i class="fa fa-power-off"></i> &nbsp; Logout</a></li>
                    </ul>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css" rel='stylesheet' type='text/css'>

                        <div class="container">
                            <div class="row">

                                <div class="col-md-12 ">

                                    <div class="panel panel-default panel-table">
                                        <div class="panel-heading">
                                            <div class="row">
                                              <div class="col col-xs-12">
                                                <h3 class="panel-title">
                                                    <em class="fa fa-history"></em> 
                                                    <b>My Leave History</b>
                                                 </h3>
                                              </div>
                                            </div>
                                        </div>
                                        
                                        <form method="POST">
                                            <?php 
                                                if(isset($_SESSION['success'])=="true"){
                                                    echo'<div class="alert alert-success col-md-12 absolue center text-center" role="alert">
                                                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                                                <span aria-hidden="true">×</span>
                                                            </button>
                                                            <span class="text-success">Leave Application submitted successfully</span>
                                                        </div>';
                                                    unset($_SESSION['success']); 
                                                }
                                                if(empty($result)){
                                                    echo'<div class="alert alert-danger absolue center text-center" role="alert">
                                                            <span class="text-danger">No records found</span>
                                                        </div>';
                                                }else{

                                            ?>
                                            <div class="col-md-12">
                                                &nbsp;
                                            </div>
                                                <div class="col-md-12" style="width:100%;">
                                                    <div class="table-responsive" style="margin-right:auto;margin-left:auto;">
                                                        <table class="table table-striped" id="myTable">
                                                            <thead style="background-color:rgb(21,164,113);color:rgb(254,255,255);">
                                                                <tr>
                                                                    <th style="width:7%;text-align:center;"># </th>
                                                                    <th>Leave</th>
                                                                    <th>Applied</th>
                                                                    <th>Start Date</th>
                                                                    <th>Report Date</th>
                                                                    <th>Days</th>
                                                                    <th>Remarks</th>
                                                                    <th style="width:100px;"><i class="fa fa-cog ml-3x"></i> Status </th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                <?php 
                                                                    $i=$p=$s=$q=$r=$a=$b=1;
                                                                    while($row = mysql_fetch_array($result)) {
                                                                        $days = round((strtotime($row['to'])-strtotime($row['from'])) / (60 * 60 * 24))+1;
                                                                ?>
                                                                    <tr>
                                                                        <td style="text-align:center;font-size:12px;font-weight:normal;color:rgb(3,3,3);"> <?php echo $i++;?> </td>
                                                                        <td style="font-size:12px;font-weight:normal;color:rgb(4,4,4);"> <?php echo $row['leave'];?> </td>
                                                                        <td style="font-weight:normal;font-size:12px;color:rgb(6,6,6);"> <?php echo date_format(date_create($row['applied']),"D d M, Y.").date(" g:i A", strtotime($row['applied']));?> </td>
                                                                        <td style="font-weight:normal;font-size:12px;color:rgb(6,6,6);"> <?php echo date_format(date_create($row['from']),"D d M, Y");?> </td>
                                                                        <td style="font-size:12px;font-weight:normal;color:rgb(4,4,4);"> <?php echo date_format(date_create($row['to']),"D d M, Y");?> </td>
                                                                        <td style="font-size:12px;font-weight:normal;color:rgb(4,4,4);"><?php if($days==1){echo $days." day";}else{echo $days." days";}?></td>
                                                                        <td style="font-size:12px;font-weight:normal;color:rgb(4,4,4);"> 
                                                                            <a href="#myModal<?php echo $p++;?>" data-toggle="modal" title="See full remarks">
                                                                                <?php if($row['description'] ==""){echo "__";}else if(strlen($row['description'])>30){echo substr($row['description'],0,30)."...";}else{echo $row['description'];}?> 
                                                                            </a>
                                                                            <div role="dialog" tabindex="-1" class="modal fade" id="myModal<?php echo $s++;?>">
                                                                                <div class="modal-dialog" role="document">
                                                                                    <div class="modal-content">
                                                                                        <div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                                                                                            <h4 class="modal-title">Leave Request Remarks</h4>
                                                                                        </div>
                                                                                        <div class="modal-body">
                                                                                            <p class="text-left text-muted" style="color:rgb(1,1,1);"><?php echo $row['description'];?></p>
                                                                                        </div>
                                                                                        <div class="modal-footer">
                                                                                            <button type="button" data-dismiss="modal" style="padding:5px 20px;color:rgb(1,1,1);">Close</button>
                                                                                        </div>
                                                                                    </div>
                                                                                </div>
                                                                            </div>
                                                                        </td>
                                                                        <td style="font-size:12px;font-weight:normal;text-align:center;"> 
                                                                            <?php if($row['status']==0){?>
                                                                            <a role="button" title="Pending Approval" class="text-info" style="font-weight:bold;">
                                                                                    <em class="fa fa-circle-o-notch fa-spin text-info"></em> Pending
                                                                                </a>
                                                                            <?php 
                                                                                }else
                                                                                if($row['status']==1){
                                                                            ?>  
                                                                                <a href="#myModalA<?php echo $a++;?>" data-toggle="modal" role="button" title="Approved" class="text-success" style="display:block;font-weight:bold;">
                                                                                    <em class="fa fa-check text-success"></em> Approved
                                                                                </a>
                                                                                <div role="dialog" tabindex="-1" class="modal fade" id="myModalA<?php echo $q++;?>">
                                                                                    <div class="modal-dialog" role="document">
                                                                                        <div class="modal-content">
                                                                                            <div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                                                                                                <h4 class="modal-title">Leave Request Approval Details</h4>
                                                                                            </div>
                                                                                            <div class="modal-body">
                                                                                                <p class="text-left text-muted" style="color:rgb(1,1,1);">
                                                                                                    <b>Approved on:</b> 
                                                                                                    <?php echo date_format(date_create($row['acted']),"D d M, Y")." <b>at</b> ".date(" g:i A", strtotime($row['acted']));?>
                                                                                                </p>
                                                                                                <p class="text-left text-muted" style="color:rgb(1,1,1);">
                                                                                                    <b>Administrator Remarks:</b> <br>
                                                                                                    <?php echo $row['remarks'];?>
                                                                                                </p>
                                                                                                <p class="text-left text-muted" style="color:rgb(1,1,1);">
                                                                                                    <b>Reported on:</b> 
                                                                                                    <?php if($row['reported']==''){echo'<em>N/A</em>';}else{ echo date_format(date_create($row['reported']),"D d M, Y")." <b>at</b> ".date(" g:i A", strtotime($row['reported']));}?>
                                                                                                </p>
                                                                                            </div>
                                                                                            <div class="modal-footer">
                                                                                                <button type="button" data-dismiss="modal" style="padding:5px 20px;color:rgb(1,1,1);">Close</button>
                                                                                            </div>
                                                                                        </div>
                                                                                    </div>
                                                                                </div>
                                                                            <?php 
                                                                                }else
                                                                                if($row['status']== -1){
                                                                            ?> 
                                                                            <a href="#myModalD<?php echo $b++;?>" data-toggle="modal" role="button" title="Denied" class="text-danger" style="display:block;font-weight:bold;">
                                                                                    <em class="fa fa-times text-danger"></em> Denied
                                                                                </a>
                                                                                <div role="dialog" tabindex="-1" class="modal fade" id="myModalD<?php echo $r++;?>">
                                                                                    <div class="modal-dialog" role="document">
                                                                                        <div class="modal-content">
                                                                                            <div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                                                                                                <h4 class="modal-title">Leave Denial Details</h4>
                                                                                            </div>
                                                                                            <div class="modal-body">
                                                                                                <p class="text-left text-muted" style="color:rgb(1,1,1);">
                                                                                                    <b>Denied on:</b> 
                                                                                                    <?php echo date_format(date_create($row['acted']),"D d M Y")." <b>at</b> ".date(" g:i A", strtotime($row['acted']));?>
                                                                                                </p>
                                                                                                <p class="text-left text-muted" style="color:rgb(1,1,1);">
                                                                                                    <b>Administrator Remarks:</b> 
                                                                                                </p>
                                                                                                <p class="text-left text-muted" style="color:rgb(1,1,1);">
                                                                                                    <?php echo $row['remarks'];?>
                                                                                                </p>
                                                                                            </div>
                                                                                            <div class="modal-footer">
                                                                                                <button type="button" data-dismiss="modal" style="padding:5px 20px;color:rgb(1,1,1);">Close</button>
                                                                                            </div>
                                                                                        </div>
                                                                                    </div>
                                                                                </div>
                                                                            <?php } ?>     

                                                                        </td>
                                                                    </tr>
                                                                <?php } ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                </div>
                                            <?php } ?>
                                        </form>
                                    
                                    </div>
                                </div>
                            </div>
                        
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="../../../assets/js/jquery.min.js"></script>
    <script src="../../../assets/bootstrap/js/bootstrap.min.js"></script>
    <script src="../../../assets/js/ebs-simple-login-form.js"></script>
    <script src="../../../assets/js/Profile-Edit.js"></script>
    <script src="../../../assets/js/Sidebar-Menu.js"></script>
    <script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
    <script src="https://cdn.datatables.net/1.10.15/js/dataTables.bootstrap.min.js"></script>
    <script src="ajax.js"></script>
    <script>
        $(document).ready(function(){
            $('#myTable').dataTable();
        });
    </script>
</body>
</html>