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

if (isset($_POST['btnsearch']))
{
    echo $dept = $_POST['department'];
    echo $lev = $_POST['level'];
    echo $prog = $_POST['programme'];
    $ses = $_POST['session'];
    
    if($lev != "" || $prog != "")
    {
        $get_prog = ONLINEPAY:: searchbyprog19($lev,$prog,$dept);
        
        $query = "SELECT department, COUNT(formno) FROM admitted_student_details_2019 WHERE formno LIKE '%$prog%' AND level LIKE '%$level%' GROUP BY department";
        $result = mysql_query($query) or die(mysql_error());
    }
    
    if ($lev == 'ND' && $prog == 'PU')
    {
        $msg = 'National Diploma On Full-Time Programme';
    }
    elseif ($lev == 'ND' && $prog == 'DP')
    {
        $msg = 'National Diploma On Daily Part-Time Programme';
    }elseif ($lev == 'HND' && $prog == 'FT')
    {
        $msg = 'Higher National Diploma On Full-Time Programme';
    }elseif ($lev == 'HND' && $prog == 'DP')
    {
        $msg = 'Higher National Diploma On Daily Part-Time Programme';
    }
}
$count = 0;
?>

<html>
 <head>
  <title>Admin-Dashboard</title>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
  <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/r/dt/jq-2.1.4,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.9,af-2.0.0,b-1.0.3,b-colvis-1.0.3,b-html5-1.0.3,b-print-1.0.3,se-1.0.1/datatables.min.css"/>
  <script type="text/javascript" src="https://cdn.datatables.net/r/dt/jq-2.1.4,jszip-2.5.0,pdfmake-0.1.18,dt-1.10.9,af-2.0.0,b-1.0.3,b-colvis-1.0.3,b-html5-1.0.3,b-print-1.0.3,se-1.0.1/datatables.min.js"></script>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
   <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>  
   <script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>            
   <link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
 </head>
 <body>
  <div class="container box">
   <h3 align="center">Admin-Dashboard :: Applicants</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">
        	<tr>
        	    <td>
					<select name="department" id="department" class="form-control action" style="width:200px">
						<option value="">Select Department</option>
						<option value="">All Department</option>
							<?php foreach($alldept as $dept){?>
							<option value="<?php echo $dept->department;?>"><?php 
							echo strtolower($dept->department);?></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>
    					<option value="DP">Daily-PartTime</option>
                        <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="btnsearch" value="Search" id="btnsearch" title="Search Student">
                    </span>
                </td>
         	</tr>
        </table>
        </div>
    </form></br>
    <div class="panel panel-primary chat-panel">
        <div class="panel-heading ">
            <? echo $msg;?>
        </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="10%">FORM NO</th>  
        <th width="20%">SURNAME</th>  
        <th width="30%">OTHER NAMES</th>  
        <th width="45%">DEPARTMENT</th>
        <th width="10%">LEVEL</th>
        <th width="10%">SESSION</th>
        <th width="10%">DATE/TIME</th>
      </tr>
     </thead>
     <?php
        try
            { 
                if(empty($get_prog)){throw new Exception ();}
                else{
                foreach ($get_prog as $rows)
                { 
                   echo  '<tr>'
                            .'<td>'.++$count.'</td>'
        					.'<td>'.$rows->formno.'</td>'
        					.'<td>'.$rows->surname.'</td>'
        					.'<td>'.$rows->othernames.'</td>'
        					.'<td>'.$rows->department.'</td>'
        					.'<td>'.$rows->level.'</td>'
        					.'<td>'.$rows->session.'</td>'
        					.'<td>'.$rows->reg_date.'</td>'
    					.'</tr>';
                }
                }
            }catch (exception $e){ }
        
     
     
     ?>
    </table>
   </div>
   <div class="col-sm-4">
        <table id="my_table" class="table table-bordered table-striped">
            <tr>
                <th width="10%">FORM NO</th>
                <th width="45%">DEPARTMENT</th>
              </tr>
    <?php
    
        if ($result){
        while($row = mysql_fetch_array($result))
        {
            echo    '<tr>'
                        .'<td>'.$row['COUNT(formno)'].'</td>'
                        .'<td>'.$row['department'].'</td>'
			.'</tr>';
          $row['COUNT(formno)'];
          $row['department'];
        }}
    ?>
    </table>
    </div>
   </div>
  </div>
  <br />
  <br />
 </body>
</html>


<script type="text/javascript" language="javascript" >
 $(document).ready(function(){

//   $("#applicant_table").DataTable({
//   "processing" : true,
//   "serverSide" : true,
//   "ajax" : {
//     url:"applicant_fetch.php",
//     type:"POST"
//   },
//   dom: 'lBfrtip',
//   buttons: [
//     'excel', 'csv', 'pdf', 'copy'
//   ],
//   "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "All"] ]
//   });
  
//  });
 
 $('#applicant_table').DataTable();
 $('#my_table').DataTable();
// $('#my_table').DataTable( {
//         dom: 'Bfrtip',
//         buttons: [{
//             // 'copy', 'csv', 'excel', 'pdf', 'print',
//             extend:'print',
//             autoPrint: true,
//                 title: 'Supplementary Matric Number List 2',
            
            
            
            
//         }]
//     });
});
 
</script>