<?php 
require_once("includes/initialize.php");
// $alldept = ONLINEPAY:: showdept();
// $dprepare ="";
//session_start(); $faculty_dept=array();
 $fo =  $_SESSION['access_level'];

if ($fo == "DPT" or $fo == '')
{
    $faculty_dept = ONLINEPAY:: showdept();
}
else if ($fo =='Business and Management Sciences'|| $fo =='APPLIED SCIENCES'|| $fo =='MANAGEMENT SCIENCES'|| $fo =='ENGINEERING'|| $fo =='ENVIRONMENTAL STUDIES' || $fo == 'Information Communication and Technology')
{
    $faculty_dept = ONLINEPAY:: showdept_byf($fo);
}else {
    
     if ($fo == "Electrical Electronic Engineering")
      {
        $faculty_dept =array("Electrical Electronic Engineering","Power/Machine(Option)","Electronic/Telecommunication (Option)");
        //$_SESSION["$HoD"] = $Hod_EEE;
    
      }
      
  
      else if ($fo == "Applied science")
      {
          $faculty_dept =array("Applied Science (Microbiology Option)","Applied Science (Chemistry Option)","Applied Science (Physics with Electronics Option)","Applied Science (Biochemistry Option)","Applied Science (Environmental Biology Option)");
         // $_SESSION["$HoD"] = $Hod_APP;
         // $Hod_SLT;
      }
    
      else
      {
          $faculty_dept= array($fo);
      }
       
   // $faculty_dept= array($fo);
}
$allsession = ONLINEPAY::showsession();

$session='';
if (isset($_POST['search']))
{
   $depart = $_POST['department'];
   $level = $_POST['level'];
   
   if (isset($_POST['session'])){
      $session =$_SESSION['ses']= $_POST['session'];  
   }
  
   $prog = $_POST['prog'];
    if ($session == '2019/2020' AND ($level=='ND II' OR $level=='HND II'))
    {
        $allpayment =ONLINEPAY::get_phone18('schoolfees_tranzact',$depart,$prog,$level,$session);
        
       // print_r($allpayment);
    }else
    {
        echo "<br> Find me here: ".$depart." ".$prog." ".$level;
      $th= ONLINEPAY::get_all_matric_all();
        $allpayment =ONLINEPAY::get_all_matric($depart,$prog,$level);
    }
    
   // print_r($allpayment);
    $msg='';
    if ($level == 'ND')
    {
        $msg = 'ND I '.$depart. ' '.$session;
    }
    elseif ($level == 'ND' && $prog == 'PT')
    {
        $msg = 'National Diploma On Part-Time Programme '.$session;
    }
    elseif ($level == 'HND')
    {
        $msg = 'HND I '.$depart. ' '.$session;
     }
    
    elseif ($level == 'HND' && $prog == 'PT')
    {
        $msg = 'Higher National Diploma On Part-Time Programme '.$session;
    }
    
    
}

$count=0;
?>

<head>
   <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" align="center">
		    <?php
		    //COMMUNICATION AND INFORMATION TECHNOLOGY
		    if ($fo =='Business and Management Sciences'|| $fo =='APPLIED SCIENCES' || $fo =='Information Communication and Technology' || $fo =='MANAGEMENT SCIENCES'|| $fo =='ENGINEERING'|| $fo =='ENVIRONMENTAL STUDIES'){
			echo '<h2 align="center">Welcome :: '. $fo .' Faculty Officer</h2><br/>';
			}
		 	
		 	else if ($fo =='DPT'){
			echo '<h2 align="center">Welcome :: '. $fo.' Faculty Officer </h2><br/>';
		 	}
		 	
			else {
		echo '<h2 align="center">Welcome :: '. $fo.' Head of Department</h2><br/>';
			}
			
			 ?>
			    <form method="post" id="insert_data">
			        <div class="form-group input-group" align="center">
			            <table class="table table-bordered table-hover" align="center">
                        	<tr>
                            	<td>
                					<select name="department" id="department" class="form-control action" style="width:200px">
                						<option value="">Select Department</option>
                							<?php foreach($faculty_dept as $dept){?>
                							<option value="<?php 
                							if (isset($dept->department)){
                							echo $dept->department;
                							} else {
                							    echo $dept;
                							}
                							    ?>"><?php 
                							    if (isset($dept->department)){
                							echo ucwords($dept->department);
                							} else {
                							echo $dept;
                							}
                							?></option> <?php }?>
                					</select></td>
                					<td>
                					<select name="prog" id="prog" class="form-control action" style="width:120px">
                						<option value="">Select Programme</option>
                						<option value="PU22">Full Time(ND)</option>
                	                    <option value="PT22">Part Time</option>
                	                    <option value="FT22">Full Time(HND)</option>	
                					</select></td>
                					
        					    <td>
                					<select name="level" id="level" class="form-control action" style="width:120px">
                						<option value="">Select Level</option>
                						<option value="ND I">ND I</option>
                	                    <option value="ND II">ND II</option>
                	                    <option value="HND I">HND I</option>
                	                    <option value="HND II">HND II</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>
                					    <div class="col-md-4">
                                            <input type="submit" name="search" id ="search" value="Search" class="btn btn-info" />
                                        </div>
                					</td>
                					<!--<td>-->
        					        <!--    <input type="submit" name="Print_pdf" id ="Print_pdf" class="btn btn-danger" value="Print PDF" />-->
                					<!--</td>-->
        					</tr> 
                        </table>
					</div>
			    <!--</form>-->
			    <div class="panel panel-primary chat-panel">
                    <div class="panel-heading ">
                     <h3><? echo $resp = (!empty($msg))?  $msg:  "";?></h3>
                    </div><br/>
                <div class="table-responsive">
                    <table class="table table-bordered table-hover table-condensed" id="fo_table">
                       
                            <thead>
                              <tr>
                                <th>S/N</th>  
                                <th>MATRIC NO</th>  
                                <th>FULLNAME</th>
                         
                                
                                
                              </tr>
                             </thead>
                        
                        <?php
                        
                        //print_r($allpayment);
                        $alldata=array();
                        
                        
                        function compareMid($a, $b)
                    {
                    if ($a['mid'] == $b['mid']) {
                    return 0;
                    }
                    return ($a['mid'] < $b['mid']) ? -1 : 1;
                    }
                        
                        
                        if (isset($allpayment)){
                            foreach($allpayment as $rows)
                            {
                                $formno = $rows->formno;
                                
                                 $fullname = strtoupper($rows->surname).', '.strtolower($rows->othernames);
                               //  $sex = $rows->sex;
                            
                               // echo $formno." : ".$_SESSION['ses'];
                                //$getmatric = ONLINEPAY::getMatricNo($formno);
                                
                                // if ($rows->matricno != 0)
                                //     {
                                $alldata[]= array($rows->matricno,$fullname);
                                //echo "Fine: ". $getmatric->matricno;
                                
                            // }
                            }
                            
                            foreach ($alldata as $key => $row)
                            {
                                $matric[$key] = $row[0];
                            }
                            array_multisort($matric, SORT_ASC, $alldata);

                                                       
                               // $alldata3 = usort($alldata, 'compareMid');
                               // print_r($alldata);
                                
                                 //   if ($getmatric->matricno != 0)
                                   // {
                                  //      $matricno = $getmatric->matricno;
                                   // }else
                                    //{
                                    //    $matricno = $getmatric->formno;
                                   // }
                                   
                                
                          foreach ( $alldata as $stu){      
                        
                        echo  '<tr>'
                                .'<td>'.++$count.'</td>'
            					.'<td>'.$stu[0].'</td>'
            					.'<td>'.$stu[1].'</td>'
            					
        					.'</tr>';
                            }
                        }
                       // }
                        ?>
                        </table>
                    </div>
                    </div>
                   </form>  
                
        </div>
    </body>
    
    
    
    <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>
  {
    $('#fo_table').DataTable( {
    dom: 'Bfrtip',
    buttons: [
        'copy', 'csv', 'excel', 'pdf', 'print'
    ]
});
  }
</script>