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

if (isset($_POST['search']))
{
    $department = $_POST['department'];
  $level = $_POST['level'];
  $session = $_POST['session'];
  $formno = $_POST['formno'];
  $prog = $_POST['programme'];
    
    // $_SESSION['level'] =  $lev;
    // $_SESSION['programme'] =  $prog;
    // $_SESSION['gender'] = $gend;
    if( $prog != "" && $department!="" && $session!="")
    {
        
        // $query = "SELECT * FROM `admission_list` WHERE `formno` LIKE '%$prog%' AND `department` = '$department' AND session = '$session'";
        
        $query = "SELECT admission_list.department,admission_list.formno,admission_list.names,admitted_student_details_2019.level,
                        admission_list.session,admission_list.admitted_date
                FROM admission_list JOIN admitted_student_details_2019 
                ON admission_list.formno = admitted_student_details_2019.formno 
                WHERE admission_list.formno LIKE '%$prog%' AND admission_list.session LIKE '%$session%' 
                AND admission_list.department = '{$department}' AND admitted_student_details_2019.level = '{$level}' ";
        
         $result = mysql_query($query) or die(mysql_error());
    }
    
    if($department =="" && $level !="" && $session !="")
    {
        $quy = "SELECT COUNT(admission_list.formno), admission_list.department FROM admission_list JOIN admitted_student_details_2019 
                    ON admitted_student_details_2019.formno = admission_list.formno WHERE admission_list.formno LIKE '%$prog%'
                    AND admitted_student_details_2019.level LIKE '{$level}' 
                    AND admission_list.session LIKE '{$session}' GROUP BY department";
        
        $rest = mysql_query($quy) or die(mysql_error());
    }
    
    if ($level == 'ND' && $prog == 'PU')
    {
        $msg = 'National Diploma On Full-Time Programme ';
    }
    elseif ($level == 'ND' && $prog == 'DP')
    {
        $msg = 'National Diploma On Daily Part-Time Programme ';
    }elseif ($level == 'HND' && $prog == 'FT')
    {
        $msg = 'Higher National Diploma On Full-Time Programme ';
    }elseif ($level == 'HND' && $prog == 'DP')
    {
        $msg = 'Higher National Diploma On Daily Part-Time Programme';
    }
    
}
$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" />
    <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">NUMBER OF ADMITTED STUDENTS999 </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="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 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>
    				</select>
    			</td>
    			<td>
					<select name="session" id="session" class="form-control action" style="width:120px">
						<option value="">Select Session</option>
						<?php foreach($allsession as $session){?>
						<option value="<?php echo $session->session;?>"><?php 
						echo $session->session?></option><?php }?>
					</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" width="50px">
        <div class="panel-heading ">
            <? echo $msg;?>
        </div><br/>
   <div class="table-responsive">
       <table id="mytable" class="table table-bordered table-striped" >
     <thead>
      <tr height ="40">
        <th>S/N</th>  
        <th>FORM NO</th>
        <th>FULL NAME</th>
        <th>DEPARTMENT</th>
        <th>LEVEL</th>
        <th>SESSION</th>
        <th>DATE</th>
      </tr>
     </thead>
    <?
     
    if ($result!="")
    {
        while($row = mysql_fetch_array($result)){
        echo    '<tr>'
                    .'<td>'.++$count.'</td>'
                    .'<td>'.$row['formno'].'</td>'
                    .'<td>'.$row['names'].'</td>'
                    .'<td>'.$row['department'].'</td>'
                    .'<td>'.$row['level'].'</td>'
                    .'<td>'.$row['session'].'</td>'
                    .'<td>'.$row['admitted_date'].'</td>'
				.'</tr>';
         }
                   
        
    }
    if ($rest){
        echo '<table id="summary" class="table table-striped table-bordered" >
                <tr>
                    <td width="50px">Total number of students:</td>
                    <td width="100px"> Department </td>';
                    while($row = mysql_fetch_array($rest)){
                        echo    '<tr>'
                                .'<td>'.$row['admission_list.formno'].'</td>'
                                .'<td>'.$row['department'].'</td>'
    						.'</tr>';
                     }
                   
                '</tr>';
            '</table>';
        
        }
    ?>
    </table>
   </div>
   </div>
  </div>
  <br />
  </form><br />
 </body>
</html>



    <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>
    
<script type="text/javascript" language="javascript" >
  {
    $('#mytable').DataTable( {
    dom: 'Bfrtip',
    buttons: [
        'copy', 'csv', 'excel', 'pdf', 'print'
        // extend:'print',
            // autoPrint: true,
            //     title: '2019/2020 ADIMISSION LIST',
    ]
});
  }
</script>