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

if (isset($_POST['search']))
{
    $lev = $_POST['level'];
    $prog = $_POST['programme'];
    $session = $_POST['session'];
    $dept =$_POST['dept'];
    
    $_SESSION['level'] =  $lev;
    $_SESSION['programme'] =  $prog;
    $_SESSION['session'] = $session;
    $_SESSION['dept']=$dept;
    
    if($session != "" || $lev != "" || $prog != "" || $dept !="")
    {
        $query = "SELECT student_account.formno,student_account.surname,student_account.othernames,admitted_student_details_2019.formno
          FROM admitted_student_details_2019, student_account
          WHERE student_account.formno=admitted_student_details_2019.formno AND student_account.department='$dept' 
          group by ";
        
        // $query = "SELECT courses, COUNT(sex) FROM admitted_student_details WHERE 
                    // programme = '$lev' AND formno LIKE '%$prog%' AND sex LIKE '%$gend%' GROUP BY courses";
    // //  Full Time   
    //     $query1 = "SELECT courses, COUNT(sex) FROM admitted_student_details JOIN schoolfees_tranzact ON schoolfees_tranzact.formno = admitted_student_details.formno WHERE 
    //                 programme = 'HND' AND formno LIKE '%FT%' AND sex LIKE '%Male%' GROUP BY courses";
        
    //      $query2 = "SELECT courses, COUNT(sex) FROM admitted_student_details WHERE 
    //                 programme = 'HND' AND formno LIKE '%FT%' AND sex LIKE '%Female%' GROUP BY courses";
        
    //      $query3 = "SELECT courses, COUNT(sex) FROM admitted_student_details WHERE 
    //                 programme = 'ND' AND formno LIKE '%PU%' AND sex LIKE '%Male%' GROUP BY courses";
        
    //      $query4 = "SELECT courses, COUNT(sex) FROM admitted_student_details WHERE 
    //                 programme = 'ND' AND formno LIKE '%PU%' AND sex LIKE '%Female%' GROUP BY courses";
    // // DPT
    //     $query5 = "SELECT courses, COUNT(sex) FROM admitted_student_details WHERE 
    //                 programme = 'HND' AND formno LIKE '%DP%' AND sex LIKE '%Male%' GROUP BY courses";
        
    //      $query6 = "SELECT courses, COUNT(sex) FROM admitted_student_details WHERE 
    //                 programme = 'HND' AND formno LIKE '%DP%' AND sex LIKE '%Female%' GROUP BY courses";
        
    //      $query7 = "SELECT courses, COUNT(sex) FROM admitted_student_details WHERE 
    //                 programme = 'ND' AND formno LIKE '%DP%' AND sex LIKE '%Male%' GROUP BY courses";
        
    //      $query8 = "SELECT courses, COUNT(sex) FROM admitted_student_details WHERE 
    //                 programme = 'ND' AND formno LIKE '%DP%' AND sex LIKE '%Female%' GROUP BY courses";
        
         $result = mysql_query($query) or die(mysql_error());
    }
    if ($lev == 'ND' && $prog == 'PU')
    {
        $msg = 'National Diploma On Full-Time Programme '.$gend;
    }
    elseif ($lev == 'ND' && $prog == 'DP')
    {
        $msg = 'National Diploma On Daily Part-Time Programme '.$gend;
    }elseif ($lev == 'HND' && $prog == 'FT')
    {
        $msg = 'Higher National Diploma On Full-Time Programme '.$gend;
    }elseif ($lev == 'HND' && $prog == 'DP')
    {
        $msg = 'Higher National Diploma On Daily Part-Time Programme '.$gend;
    }
    
}
$count = 0;

?>

<html>
 <head>
  <title>Gender-Generate</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">NUMBERS OF APPLICANT </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="dept" id="dept" class="form-control action" style="width:120px" required>
						<option value="">Select Department</option>
							<option value="">All Department</option>
						<?php foreach($alldept as $dept){?>
						<option value="<?php echo $dept->department;?>"><?php 
						echo ucwords($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>
    				<select name="session" id="session" class="form-control action" style="width:120px" required>
    					<option value="">Select session</option>
    					<option value="Male">2020/2021</option>
                        <option value="Female">2021/2022</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="60%">DEPARTMENT</th>
        <th width="30%">Number of Students</th>
      </tr>
     </thead>
    <?
     
    if ($result)
    {
        while($row = mysql_fetch_array($result)){
        echo    '<tr>'
                    .'<td>'.++$count.'</td>'
                    .'<td>'.$row['courses'].'</td>'
                    .'<td>'.$row['COUNT(sex)'].'</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'
        ]
    });
    
$('#Print_pdf').on("click", function(e){
    e.preventDefault(e);
    
        {
    		window.open("MaFePDF.php");
        }
 });
});
 
</script>