<?php require_once("./includes/initialize.php");
global $database;
$mat = array();
$mat2 = array();
session_start();

  $department = $_POST['department'];
  $level = $_POST['level'];
  $session = $_POST['session'];
  $semester = $_POST['semester'];
  
  $_SESSION['department'] =  $department;
 $_SESSION['level'] =  $level;
 $_SESSION['session'] =  $session;
 $_SESSION['semester'] =  $semester;
  
    // $get_id = ONLINEPAY::get_ses_sem_id($session,$semester);
  
 
$count = 0;
  
if(isset($_POST['department']))
{
    $department = $_POST['department'];
    $level = $_POST['level'];
    $session = $_POST['session'];
    $semester = $_POST['semester'];
    // $id = 1;//$get_id->ses_sem_id;
    
    $_SESSION['department'] =  $department;
 $_SESSION['level'] =  $level;
 $_SESSION['session'] =  $session;
 $_SESSION['semester'] =  $semester;
    
    
    $get_id = ONLINEPAY::get_ses_sem_id($session,$semester);
    foreach ($get_id as $reg){ $id =$reg->ses_sem_id; }
    
    // echo 'Hello'.$id.$semester.$session.$level.$department;
    if ($level == 'ND')
    {
        $table = 'ndi_tbl';
        $reg = ONLINEPAY:: reg_students($table,$department,$id);
    }
    elseif ($level == 'ND II')
    {
        $table = 'ndii_tbl';
        $reg = ONLINEPAY:: reg_students($table,$department,$id);
    }
    elseif ($level == 'HND')
    {
         $table = 'hndi_tbl';
        $reg = ONLINEPAY:: reg_students($table,$department,$id);
    }
    elseif ($level == 'HND II')
    {
         $table = 'hndii_tbl';
        $reg = ONLINEPAY:: reg_students($table,$department,$id);
    }
    
    
    else{ echo "Error 442";}
    
    echo '<table id="mytable" class="table table-bordered table-hover" style = "height:20px">  
            <thead>
                <tr>  
                    <th width="5%">S/N</th>  
                    <th width="10%">FORM NO</th> 
                    <th width="15%">SURNAME</th>
                    <th width="40%">OTHER NAMES</th>
                    <th width="40%">DEPARTMENT</th>
                    <th width="50%">COURSES</th>
                    <th width="30%">REGISTERED DATE</th>
               </tr>  
            </thead>';
    foreach($reg as $pay) 
    {
        
        $names = ONLINEPAY:: getdetails($pay->matricno);
        $mat[] = $pay->matricno;
        
       
        foreach ($names as $row)
        {
            $surname = $row->surname;
            $othernames = $row->othernames;
            $email = $row->email;
            $mat2[]=$row->email;
        }
        echo '<tr>'
				.'<td>'.++$count.'</td>'
				.'<td>'.$pay->matricno.'</td>'
				.'<td>'.$surname.'</td>'
				.'<td>'.$othernames.'</td>'
				.'<td>'.$pay->department.'</td>'
				.'<td>'.$pay->courses.'</td>'
				.'<td>
                    	<p style=" text-transform:uppercase; color:#030; font-size:14px; font-weight:bolder; font-stretch:extra-expanded">'.$pay->regDate." ".$pay->matricno.
                    	'<a href="./Report_E.php?formno='.$pay->matricno.'&email='.$row->email.'" target ="_new"> <input type="button" class ="print" value="Exam-Pass" /></a></p>
                </td>'
			.'</tr>'; 
			
			 echo '<script>';
        
     'window.open(<a href="./Report_E.php?id="'.json_encode($pay->matricno). 'target ="_new"><input type="button" class ="print" value="Exam-Pass" /></a>)';
     echo ' </script>';
    }
    echo '</table>';
   // print_r($mat);
   // print_r($mat2);
  $_SESSION['names'] = $mat;
  $_SESSION['names2'] = $mat2;
 
  $name = $_SESSION['names'];
 $name2 = $_SESSION['names2'];

}?>