<?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'];




 $leaverequest = "SELECT *, `ot`.status AS 'stat', ot.id AS 'otid', ot.date AS 'shiftdate' FROM `ot` JOIN empdetails ON `ot`.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE `ot`.status IN ('1','2','3','4.1','4.2','4.3') ";
                                 
if(isset($_POST['filter']) || $_GET['filter'] == '1'){
  


    if($_GET['filter'] == '1'){
   
        $leavestat = $_GET['status'];
        $employee = $_GET['employee'];

    }else{

        $leavestat = $_POST['status'];
        $employee = $_POST['employee'];

    }



    if($leavestat  =='All' && $employee  == 'All'){
         $leaverequest = "SELECT *, ot.status AS 'stat', ot.id AS 'otid', ot.date AS 'shiftdate' FROM ot JOIN empdetails ON ot.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE ot.status IN ('1','2','3','4.1','4.2','4.3') ";
 

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


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

    

        


        



    }

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


      
      if($leavestat == '4.1'){

        $leaverequest = "SELECT *, ot.status AS 'stat', ot.id AS 'otid', ot.date AS 'shiftdate' FROM ot JOIN empdetails ON ot.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE  ot.status IN ('4.1','4.2','4.3') AND ot.status != '5' ";
 


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

         $leaverequest = "SELECT *, ot.status AS 'stat', ot.id AS 'otid', ot.date AS 'shiftdate' FROM ot JOIN empdetails ON ot.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE  ot.status = '$leavestat'";
 

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

        $leaverequest = "SELECT *, ot.status AS 'stat', ot.id AS 'otid', ot.date AS 'shiftdate' FROM ot JOIN empdetails ON ot.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE  ot.status IN ('2','3') ";
 

     }



        



    }

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

        
   
      if($leavestat == '4.1'){

        $leaverequest = "SELECT *, ot.status AS 'stat', ot.id AS 'otid', ot.date AS 'shiftdate'FROM ot JOIN empdetails ON ot.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE  ot.status IN('4.1','4.2','4.3') AND ot.empid='$employee' AND ot.status != '5'  ";



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

        $leaverequest = "SELECT *, ot.status AS 'stat', ot.id AS 'otid', ot.date AS 'shiftdate' FROM ot JOIN empdetails ON ot.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE  ot.status = '$leavestat'  AND  ot.empid='$employee' ";


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

        $leaverequest = "SELECT *, ot.status AS 'stat', ot.id AS 'otid', ot.date AS 'shiftdate' FROM ot JOIN empdetails ON ot.empid = empdetails.detailid JOIN empinfo ON empdetails.detailid = empinfo.empid WHERE  ot.status = '$leavestat' AND ot.empid='$employee' ";


    }

    }

                            



}




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


  $otid = $_POST['otid'];
  $pageno = $_POST['pagenoaccept'];
  $ptoid = $_POST['ptoid'];
  $employee = $_POST['emp'];
  $status = $_POST['stat'];
    $acceptsql = "UPDATE ot SET `status` = '2',hr='$empid' WHERE `id`='$otid' ";

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

        header('location: otapproval.php?alert='.$alert.'&page_no='.$pageno.'&filter=1&status='.$status.'&employee='.$employee);


        //header('location: leaverequest.php?alert='.$alert.'&page_no='.$pageno);

    }


}



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


    $otid = $_POST['otid'];
    $pageno = $_POST['pagenoaccept'];
    $ptoid = $_POST['ptoid'];
    $employee = $_POST['emp'];
    $status = $_POST['stat'];
      echo  $acceptsql = "UPDATE ot SET `status` = '4.2',hr='$empid' WHERE `id`='$otid' ";
  
      if(mysqli_query($conn, $acceptsql)){
          $alert = '<div class="alert alert-success" role="alert"> Leave successfully approved</div>';
  
          header('location: otapproval.php?alert='.$alert.'&page_no='.$pageno.'&filter=1&status='.$status.'&employee='.$employee);
  
  
          //header('location: leaverequest.php?alert='.$alert.'&page_no='.$pageno);
  
      }
  
  
  }

      






?>
<!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">

    <script>
        function filters(){

            window.history.pushState('object', document.title, location.href.split("?")[0]);
        }
    </script>


</head>

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

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



    <?php  ?>



    <!-- Sidebar -->

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

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

        <div class="container-fluid">



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

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

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



                    }
                    ?>
                    <option value="All" <?php echo $all ?>> All </option>
                    <option value="1" <?php echo $pending ?>> Pending </option>
                    <option value="2" <?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'] == $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>
                   
     
                </form>

            </div>
            <div class="col-sm-12 col-md-12  col-lg-12">
                
                <table class="table" id="leavepto">
                    <thead class="thead-dark">
                        <tr class="thead-dark">
                            <th>Employee ID</th>
                            <th>Employee Name</th>
                            <th>Status</th>
                            <th>Type</th>
                            <th>Shift Date PST</th>
                            <th>Duration</th>
                            <th>Team Head</th>
                            <th>HR</th>
                            <th>Manager</th>
                            <th>Action</th>
                        
                        </tr>

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

                            
                            
      
                               $leaverequestres = mysqli_query($conn, $leaverequest);


                            if(mysqli_num_rows($leaverequestres) > 0){


                            



                                while($rowrequest = mysqli_fetch_assoc($leaverequestres)){

                                    $id = $rowrequest['otid'];
                        $schedcode = $rowrequest['schedule'];
                        $log = $rowrequest['attendance'];
  
                        $schedulesql ="SELECT * FROM schedule WHERE schedcode='$schedcode'";
                        $schedres = mysqli_query($conn, $schedulesql);
                        $schedrow = mysqli_fetch_assoc($schedres);
  
  
                        $logsql ="SELECT * FROM tbl_login WHERE id='$log'";
                        $logres = mysqli_query($conn, $logsql);
                        $logrow = mysqli_fetch_assoc($logres);

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

                            $schedpst = $schedrow['starttime'];



                        }else{

                            $schedMNLPST = new DateTime($schedrow['starttime'], new DateTimeZone('Asia/Manila'));

                            $schedMNLPST->setTimezone(new DateTimeZone('America/Los_Angeles'));


                            
                            $schedMNLPST1 = new DateTime($schedrow['endtime'], new DateTimeZone('Asia/Manila'));

                            $schedMNLPST1->setTimezone(new DateTimeZone('America/Los_Angeles'));

                            
    
                            $schedpst = $schedMNLPST->format('h:i A');

                            $schedpst1 = $schedMNLPST1->format('h:i A');
       



                        }






  
                
  
                        echo '<tr>';

                            echo '<td>'.$rowrequest['empid'].'</td>';
                            echo '<td>'.$rowrequest['firstname'].' '.$rowrequest['surname'].'</td>';
  
                        ////STATUS COLUMN
  
                        if($rowrequest['stat'] == '0' || $rowrequest['stat'] == '1' || $rowrequest['stat'] == '2' ){
  
                          echo '<td> Pending Approval </td>';
  
                        }else if($rowrequest['stat'] == '3'){
  
                          echo '<td> Approved </td>';
  
  
                        }else if($rowrequest['stat'] == '4.1' || $rowrequest['stat'] == '4.2' || $rowrequest['stat'] == '4.3'){
  
                          echo '<td> Declined </td>';
                        }else{
  
                          echo '<td> Cancelled </td>';
  
                        }
                        //////
  
                        echo'<td>'.$rowrequest['type'].'</td>';
                        echo'<td>'.date('m/d/Y', strtotime($rowrequest['shiftdate'])).'</td>';
                        echo'<td>'.$rowrequest['hrs'].'</td>';
  
                        ///TEAM HEAD, HR, MANAGER, 
  
                        
                        if($rowrequest['stat'] == '0'){
  
                          echo '<td> Pending </td>';
                          echo '<td> Pending </td>';
                          echo '<td> Pending </td>';
  
                        }
                        
                        else if($rowrequest['stat'] == '1'){
  
                          echo '<td> Approved <br> '.$rowrequest['tl'].' </td>';
                          echo '<td> Pending </td>';
                          echo '<td> Pending </td>';
  
  
  
                        } else if ($rowrequest['stat'] == '2' ){
  
                          echo '<td> Approved <br> '.$rowrequest['tl'].' </td>';
                          echo '<td> Approved <br> '.$rowrequest['hr'].' </td>';
                          echo '<td> Pending </td>';
  
                        }else if($rowrequest['stat'] == '3'){
  
                          echo '<td> Approved <br> '.$rowrequest['tl'].' </td>';
                          echo '<td> Approved <br> '.$rowrequest['hr'].' </td>';
                          echo '<td> Approved <br> '.$rowrequest['mng'].' </td>';
  
                        }else if($rowrequest['stat'] == '4.1'){
  
                          echo '<td> Declined <br> '.$rowrequest['tl'].' </td>';
                          echo '<td> Declined </td>';
                          echo '<td> Declined </td>';
  
  
  
                        } else if ($rowrequest['stat'] == '4.2' ){
  
                          echo '<td> Declined <br> '.$rowrequest['tl'].' </td>';
                          echo '<td> Declined <br> '.$rowrequest['hr'].' </td>';
                          echo '<td> Declined </td>';
  
                        }else if($rowrequest['stat'] == '4.3'){
  
                          echo '<td> Declined <br> '.$rowrequest['tl'].' </td>';
                          echo '<td> Declined <br> '.$rowrequest['hr'].' </td>';
                          echo '<td> Declined <br> '.$rowrequest['mng'].' </td>';
  
                        }else{
  
                          echo '<td> Cancelled <br> '.$rowrequest['tl'].' </td>';
                          echo '<td> Cancelled <br> '.$rowrequest['hr'].' </td>';
                          echo '<td> Cancelled <br> '.$rowrequest['mng'].' </td>';
  
  
                        }
  
  
                        ////ACTION 
  
                        echo '<td><a href="#view'.$id.'" class="btn btn-primary text-white btn-sm" data-toggle="modal"> <i class="far fa-eye"></i>  </a> | ';

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


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

                            echo '<a href="#approve'.$id.'" class="btn btn-success text-white btn-sm" data-toggle="modal" > <i class="fa fa-check"></i>  </a> | ';
                        

                            

                        }
                        if($rowrequest['stat'] == '5' || $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.'" class="btn btn-danger text-white btn-sm" data-toggle="modal"> <i class="fa fa-close"></i>  </a></td>';
                        } ?>
  
                          <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">
                                            <div class="row">
                                              <div class="col-lg-6">
                                                <label for=""> Date Filed</label> <br>
                                                <input type= "date" class="form-control" value="<?php  echo $rowrequest['datefiled']?>" disabled>
                                              </div>
                                              <div class="col-lg-6">
                                                <label for=""> Shift Date</label> <br>
                                                <input type= "date" class="form-control" value="<?php  echo $rowrequest['shiftdate']?>" disabled> 
                                              </div>
                                              <div class="col-lg-6">
                                                <label for=""> Schedule </label> <br>
                                                <input type= "text" class="form-control" value="<?php  echo $schedpst.' - ' .$schedpst1 ?> " disabled> 
                                              </div>
                                              <div class="col-lg-6">
                                                <label for=""> Attendance </label> <br>
                                                <input type= "text" class="form-control" value="<?php  echo $logrow['timein'].' - ' .$logrow['timeout']?> " disabled> 
                                              </div>
                                              <div class="col-lg-6">
                                                <label for=""> Type </label> <br>
                                                <input type= "text" class="form-control" value="<?php  echo  $rowrequest['type']?> " disabled> 
                                              </div>
  
                                              <div class="col-lg-6">
                                                <label for=""> No. of OT Hours </label> <br>
                                                <input type= "text" class="form-control" value="<?php  echo  $rowrequest['hrs']?> " disabled> 
                                              </div>
                                            
                                            </div>
                                           
                                              
  
                                          </div>
  
                                          <div class="modal-footer">
                                         
                                            <a href="viewutil.php?date=<?php echo date('m/d/Y', strtotime($schedrow['date'])); ?>&empid=<?php echo $rowrequest['empid'] ?>" class="btn btn-primary"> <i class="far fa-eye"> </i>  View Utilization</a>
  
                                              
  
                                              <button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fas fa-close"> </i> Close</button>
                                          </div>
                                      </div>
                                  </div>
                                  
                              </form>
                              
  
                          </div>


                          <div id="approve<?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 OT</h4>
                                              <button type="button" class="close" data-dismiss="modal">&times;</button>
  
                                          </div>
  
                                          <div class="modal-body">
                                          <input type="hidden" id="pagenoaccept" name="pagenoaccept" >
                                          <input type="hidden" id="otid" name="otid" value="<?php echo $id?>" >
                                            <input type="hidden" id="query" name="leavequery" value="<?php echo $leaverequest?>" >

                                            <input type="hidden" id="stat" name="stat" value="<?php echo $leavestat?>" >
                                            <input type="hidden" id="emp" name="emp" value="<?php echo $employee?>" >


                                                 Are you sure you want to approve <?php echo $rowrequest['empid']?> 
                                            Over Time 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> Close</button>
                                          </div>
                                      </div>
                                  </div>
                                  
                              </form>
                              
  
                          </div>

                          <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"> Disapprove OT</h4>
                                              <button type="button" class="close" data-dismiss="modal">&times;</button>
  
                                          </div>
  
                                          <div class="modal-body">
                                          <input type="hidden" id="pagenoreject" name="pagenoreject" >
                                          <input type="hidden" id="otid" name="otid" value="<?php echo $id?>" >
                                            <input type="hidden" id="query" name="leavequery" value="<?php echo $leaverequest?>" >

                                            <input type="hidden" id="stat" name="stat" value="<?php echo $leavestat?>" >
                                            <input type="hidden" id="emp" name="emp" value="<?php echo $employee?>" >

                                                 Are you sure you want to disapprove <?php echo $rowrequest['empid']?> 
                                            Over Time request?

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



                          

  
  
  
  
  
  
  
  
  
  
                        <?php 
  
                        
  
  
  
                        echo '</tr>';
  
  
  
                      }

                    }else{

                      echo' <tr> <td colspan= 8> No data found</td></tr>';
                      
                    }

                                    
               
                        

                            ?>
                        </tr>
                    </tbody>
                </table>
                <script>
                // get the table element
                var $table = document.getElementById("leavepto"),
                // number of rows per page
                $n = 8,
                // number of rows of the table
                $rowCount = $table.rows.length,
                // get the first cell's tag name (in the first row)
                $firstRow = $table.rows[0].firstElementChild.tagName,
                // boolean var to check if table has a head row
                $hasHead = ($firstRow === "TH"),
                // an array to hold each row
                $tr = [],
                // loop counters, to start count from rows[1] (2nd row) if the first row has a head tag
                $i,$ii,$j = ($hasHead)?1:0,
                // holds the first row if it has a (<TH>) & nothing if (<TD>)
                $th = ($hasHead?$table.rows[(0)].outerHTML:"");
                // count the number of pages
                var $pageCount = Math.ceil($rowCount / $n);
                // if we had one page only, then we have nothing to do ..
                if ($pageCount > 1) {
                  // assign each row outHTML (tag name & innerHTML) to the array
                  for ($i = $j,$ii = 0; $i < $rowCount; $i++, $ii++)
                    $tr[$ii] = $table.rows[$i].outerHTML;
                  // create a div block to hold the buttons
                  $table.insertAdjacentHTML("afterend","<div id='buttons'></div");
                  // the first sort, default page is the first one
                  sort(<?php 
                  if(empty($_GET['page_no'])){

                    echo '1';
                  } else{

                    echo $_GET['page_no'];
                  }
                  
                  
                  ?>);
                }

                // ($p) is the selected page number. it will be generated when a user clicks a button
                function sort($p) {
                  /* create ($rows) a variable to hold the group of rows
                  ** to be displayed on the selected page,
                  ** ($s) the start point .. the first row in each page, Do The Math
                  */
                  var $rows = $th,$s = (($n * $p)-$n);
                  for ($i = $s; $i < ($s+$n) && $i < $tr.length; $i++)
                    $rows += $tr[$i];
                  
                  // now the table has a processed group of rows ..
                  $table.innerHTML = $rows;
                  // create the pagination buttons
                  document.getElementById("buttons").innerHTML = pageButtons($pageCount,$p);
                  // CSS Stuff
                  document.getElementById("id"+$p).setAttribute("class","btn btn-primary btn-sm active");

                 var acc = document.getElementsByName('pagenoaccept');
                 
                 var rj = document.getElementsByName('pagenoreject');
                


       
                for (var a = 0; a < acc.length; a++) {
                   
                    acc[a].value = $p;
                
                }

                for (var b = 0; b < rj.length; b++) {

                    rj[b].value = $p;
                }



                 


                 
                }


                // ($pCount) : number of pages,($cur) : current page, the selected one ..
                function pageButtons($pCount,$cur) {
                  /* this variables will disable the "Prev" button on 1st page
                    and "next" button on the last one */
                  var	$prevDis = ($cur == 1)?"disabled":"",
                    $nextDis = ($cur == $pCount)?"disabled":"",
                    /* this ($buttons) will hold every single button needed
                    ** it will creates each button and sets the onclick attribute
                    ** to the "sort" function with a special ($p) number..
                    */
                    $buttons = "<input type='button' class='btn btn-default btn-sm text-primary' value='« Prev' onclick='sort("+($cur - 1)+")' "+$prevDis+"> &nbsp";

                  for ($i=1; $i<=$pCount;$i++)
                  
                    $buttons += "<input type='button' class='btn btn-default btn-sm text-primary pageno' name='pageno' id='id"+$i+"'value='"+$i+"' onclick='sort("+$i+")'> &nbsp";
                  $buttons += "<input type='button' class='btn btn-default btn-sm text-primary' value='Next »' onclick='sort("+($cur + 1)+")' "+$nextDis+"> &nbsp";
             
                  return $buttons;
                
                }


                </script>
            

            </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>