<?php 
require_once("includes/initialize.php");
global $database;
$alldept = ONLINEPAY:: showdept();
$allsession = ONLINEPAY:: showsession();

if (isset($_POST['btnsearch']))
{
    $dept = $_POST['depart'];
    $lev = $_POST['level'];
    $course_id = $_POST['course_id'];
    
    $deptlev = ONLINEPAY::deptlev($dept,$lev);
}
$count = 0;
?>

<html>
 <head>
  <title>Admin-Students</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">
   <h3 align="center">STUDENTS PER DEPARTMENTS</h3>
   <h3 align="center"></h3>
   <br />
   <form method="post" action="" role="form" enctype="multipart/form-data">                        	
    	<div class="form-group input-group" align="center">
    	<table class="table table-bordered table-hover" data-page-length='25'>
        	<tr>
        	    <td>
                    <select name = "depart" id="depart" class="form-control action" style="width:120px" required>
                        <option value="">Select Department...</option>
                        <?php foreach($alldept 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>
                    <span class="input-group-btn">
                        <input type="submit" class="btn btn-danger" name="btnsearch" value="Search" id="btnsearch" title="Search Student">
                    </span>
                </td>
         	</tr>
        </table>
        </br>
            <label>Course ID:</label></br><input type="text" name="course_id"  style="width:80px" id="course_id" required>
        </div>
    </form></br>
    
    <div class="panel panel-primary chat-panel">
        <div class="panel-heading ">
        </div><br/>
   <div class="table-responsive">
    <table id="applicant_table" class="table table-bordered table-striped">
     <thead>
      <!--<tr>-->
      <!--  <th width="5%">S/N</th>-->
        <th width="5%">courseid</th>
        <th width="10%">matricno</th>  
        <th width="20%">surname</th>  
        <th width="30%">othernames</th>  
        <th width="45%">department</th>
        <th width="10%">level</th>
        <th width="10%">picture</th>
      </tr>
     </thead>
     <?php
        try
            { 
                if(empty($deptlev)){throw new Exception ();}
                else{
                foreach ($deptlev as $rows)
                {
                    $level= $rows->level;
                    if ($level == 'ND') { $level = 1;}
                    elseif ($level == 'HND'){ $level = 3; }
                   echo  '<tr>'
                            .'<td>'.$course_id.'</td>'
        					.'<td>'.$rows->formno.'</td>'
        					.'<td>'.strtoupper($rows->surname).'</td>'
        					.'<td>'.strtoupper($rows->othernames).'</td>'
        					.'<td>'.$rows->department.'</td>'
        					.'<td>'.$level.'</td>'
        					.'<td>'.$rows->formno.'</td>'
    					.'</tr>';
                }
                
                }
            }catch (exception $e){ }
     
     ?>
    </table>
   </div>
   </div>
  </div>
  <br />
  <br />
 </body>
</html>

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