<?php 
require_once("includes/initialize.php");
global $database;
session_start();
$fo = $_SESSION["$fo"];

if ($fo == "Dpt" or $fo == '')
{
    $faculty_dept = ONLINEPAY:: showdept();
}
else
{
    $faculty_dept = ONLINEPAY:: showdept_byf($fo);
}
// $alldept = ONLINEPAY:: showdept();
$allsession = ONLINEPAY:: showsession();


if (isset($_POST['search']))
{
    $dept = $_POST['depart'];
    $lev = $_POST['level'];
    $prog = $_POST['programme'];
    
    $_SESSION['department'] =  $dept;
    $_SESSION['level'] =  $lev;
    $_SESSION['programme'] =  $prog;
    if($dept != "" || $lev != "" || $prog != "")
    {
        $get_mat = ONLINEPAY:: view_matricno($dept,$lev,$prog);
    }
    if ($lev == 'ND' && $prog == 'PU')
    {
        $msg = 'National Diploma On Full-Time Programme '.$dept;
    }
    elseif ($lev == 'ND' && $prog == 'DP')
    {
        $msg = 'National Diploma On Daily Part-Time Programme '.$dept;
    }elseif ($lev == 'HND' && $prog == 'FT')
    {
        $msg = 'Higher National Diploma On Full-Time Programme '.$dept;
    }elseif ($lev == 'HND' && $prog == 'DP')
    {
        $msg = 'Higher National Diploma On Daily Part-Time Programme '.$dept;
    }
    
}
$count = 0;

?>

<html>
 <head>
  <title>Admin-GenerateMatric</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
        <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
        <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
        <script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
        <script src="https://cdn.datatables.net/buttons/1.5.2/js/dataTables.buttons.min.js"></script>
        <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.flash.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
        <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.html5.min.js"></script>
        <script src="https://cdn.datatables.net/buttons/1.5.2/js/buttons.print.min.js"></script>
        <link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css"/>
        <link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.5.2/css/buttons.dataTables.min.css"/>
 </head>
 <body>
  <div class="container box">
   <h2 align="center">MATRICULATION LIST FOR <? echo " ".(strtoupper($fo)) ?> </h2>
   <h3 align="center"></h3>
   <br />
   <form method="POST">                        	
    	<div class="form-group input-group" align="center">
    	<table class="table table-bordered table-hover">
        	<tr>
        	    <td>
                    <select name = "depart" id="depart" class="form-control action" style="width:120px" required>
                        <option value="">Select Department...</option>
                        <?php foreach($faculty_dept as $dept){?>
                        <option value="<?php echo $dept->department;?>"><?php 
                        $dprepare= strtolower($dept->department);
                        echo ucwords($dprepare);?></option> <?php }?>
                    </select>
                </td>
                <td>
                	<select name="level" id="level" class="form-control action" style="width:120px" required>
						<option value="">Select Level</option>
						<option value="ND">ND</option>
	                    <option value="HND">HND</option>		
					</select>
                </td>
                <td>
    				<select name="programme" id="programme" class="form-control action" style="width:120px" required>
    					<option value="">Select Programme</option>
    					<? if ($fo == "Dpt") {?>
    					    <option value="DP">Daily-PartTime</option>
    					<? } elseif ($fo == '') { ?>
    					<option value="DP">Daily-PartTime</option>
                        <option value="PU">Full-Time(ND)</option>
                        <option value="FT">Full-Time(HND)</option>
                        <? } else { ?>
                        <option value="FT">Full-Time(HND)</option>
                        <option value="PU">Full-Time(ND)</option>
                        <? }?>
    				</select>
    			</td>
            	<td>
                    <span class="input-group-btn">
                        <input type="submit" class="btn btn-danger" name="search" value="Search" id="search">
                    </span>
                </td>
                <td>
                    <div>
                        <input type="submit" name="Print_pdf" id ="Print_pdf" class="btn btn-danger" value="Print PDF" />
                    </div>
                </td>
         	</tr>
        </table>
        </div>
    </br>
    
    <div class="panel panel-primary chat-panel">
        <div class="panel-heading ">
            <? echo $msg;?>
        </div><br/>
   <div class="table-responsive">
    <table id="mytable" class="table table-bordered table-striped">
     <thead>
      <tr>
        <th width="5%">S/N</th>
        <th width="10%">MATRIC NUMBER</th>
        <th width="20%">SURNAME</th>  
        <th width="30%">OTHER NAMES</th>  
        <th width="45%">DEPARTMENT</th>
        <th width="10%">STATE</th>
        <th width="10%">LGA</th>
        <th width="10%">GENDER</th>
        <th width="10%">DOB</th>        
        <th width="20%">EMAIL</th>
        <th width="10%">LEVEL</th>
      </tr>
     </thead>
     <?
     if ($get_mat){
     foreach($get_mat as $mat) 
        {
            echo 
                '<tr>'
					.'<td>'.++$count.'</td>'
					.'<td>'.$mat->matricno.'</td>'
					.'<td>'.$mat->surname.'</td>'
					.'<td>'.$mat->othernames.'</td>'
					.'<td>'.$mat->courses.'</td>'
					.'<td>'.$mat->state.'</td>'
					.'<td>'.$mat->lga.'</td>'
					.'<td>'.$mat->sex.'</td>'
					.'<td>'.$mat->dob.'</td>'
					.'<td>'.$mat->email.'</td>'
					.'<td>'.$mat->programme.'</td>'
				.'</tr>'; 
        } 
     }
    ?>
    </table>
   </div>
   </div>
  </div>
  <br />
  </form><br />
 </body>
</html>


<script type="text/javascript" language="javascript" >
 $(document).ready(function(){
     $('#mytable').DataTable( {
        dom: 'Bfrtip',
        buttons: [
            'copy', 'csv', 'excel', 'pdf', 'print'
        ]
    });

// $('#search').on("click", function(e){
//     e.preventDefault(e);
//     var department = $('#depart').val();
//     var level = $('#level').val();
//     var programme = $('#programme').val();
//     alert(level)
//         {
//             $.ajax({
//             	url:"getMatricList.php",
//             	method:"POST",
//             	data:{department:department,level:level,programme:programme},
//             	success:function(data)
//             	{
//             		$data = $("#mytable").html(data);
//             	}
//             });
//         }
//  });


$('#Print_pdf').on("click", function(e){
    e.preventDefault(e);
    
        {
            // $.ajax({
            // 	url:"admin_report.php",
            // 	method:"POST",
            // 	data:{department:department,level:level,session:session,start_date:start_date,end_date:end_date},
            // 	success:function(data)
            // 	{
            		window.open("MatListPDF.php");
            // 	}
            // });
        }
 });
});
 
</script>