<?php if (!$session->is_logged_in()){redirect_to("index.php");}	?>

<?php require_once("includes/initialize.php");

global $database;
$id=$session->user_id;

$user_data = Userdata::find_by_id($session->user_id);
 $biodata = Biodata::find_by_id($user_data->formno,$user_data->email);
 

$user_data = Userdata::find_by_id($session->user_id);

$level = $biodata->programme;


if (substr($user_data->formno,2,2)>=20){
    
    
    
    
         Switch(substr($user_data->formno,2,2))
      {
          case '20':$table='form_data';
          break;
          
          case '21': $table='form_data21';
          break;
          
          case '22': $table='form_data22';
      }
      
      
       $biodata = Biodata2::find_by_id($table, $user_data->formno, $user_data->email);
       
       
       
        $new_dp = DEPARTMENTCLASS::new_admin_dept($biodata->formno);
        
  
        
        
        
        
        
          if (!isset($new_dp->department)){
           $biodata->courses ='Nil';   
          }else if ($new_dp->department=='Microbiology (Option)'){
      $department= $biodata->courses= $biodata->department='(Microbiology (Option)'; 
       Schoolfees::updateDepartment($biodata->formno, $department);
          
        $department=$new_dp->department;
          }
       else if ($new_dp->department=='Electronic/Telecommunication (Option)'){
       $department= $biodata->courses= $biodata->department = 'Electronics/Telecommunication (Option)';
       
        Schoolfees::updateDepartment($biodata->formno, $department);
       
    }else{
        
         $department= $biodata->courses = $new_dp->department;

          }
       $level = $biodata->level;
       
       
     
        // $pixf = substr($biodata->passport, 10);
       $dp = DEPARTMENTCLASS::department_authenticate($new_dp->department);
       $pix = "http://admission.oscotechesaoke.edu.ng/passport/".trim($biodata->passport);
    
      $formno = $biodata->formno;
    
       
       
       
       
}else if (substr($user_data->formno,2,2)==19){
       
      
        $new_dp = DEPARTMENTCLASS::new_admin_dept($biodata->formno);
        
          if (!isset($new_dp->department)){
           $biodata->courses ='Nil';   
          }else{
        $biodata->courses = $new_dp->department;
        
       $department=$new_dp->department;
          }
     $level = $biodata->level;
       
       
     
        // $pixf = substr($biodata->passport, 10);
       $dp = DEPARTMENTCLASS::department_authenticate($new_dp->department);
       $pix = "http://admission.oscotechesaoke.edu.ng/passport/".trim($biodata->passport);
    
      $formno = $biodata->formno;
    
       
   
}else{
     
     $biodata = Biodata::find_by_id($user_data->formno, $user_data->email); 



    $dp = DEPARTMENTCLASS::department_authenticate($biodata->courses);
    $display_course = COURSECLASS::fetch_all_course($biodata->courses, $biodata->programme, $session_class->semester);
    $alldp = DEPARTMENTCLASS::find_all($dp->faculty);
    $pix = "../Oscotech-Wallet/passport/".$pixf;
    $level = $biodata->programme;
   $department = $biodata->courses;
    $formno = $biodata->formno;
}



$semester= find_semester($user_data->std_process_id);
$level= find_report($user_data->std_process_id,$level);




 $array_semester = SESSIONCLASSNEW::fetch_semester_all_id();
 


if (($user_data->matricno!=0) and (($level=='ND II') OR ($level=='HND II'))){
    $matricno=$user_data->matricno;
    $msg = 'MATRIC NO:';
    
 
   if ($level=='ND II'){
       $table='ndi_tbl';
       
       $oldLevel='ND I';
   }else if ($level=='HND II'){
       $table='hndi_tbl';
       $oldLevel='HND I';
   }
   
   
 
   $mydetails = COURSEREGCHECKER::fetchdata($table,$user_data->formno,$user_data->matricno,$department);
   
 
  
   foreach ($mydetails as $data){
       
       if ($data->ses_sem_id==3){
           
        
            $deleteduplicate =  COURSEREGCHECKER::deleteduplicate($table,$user_data->formno, 3,$department);
           
        
       }else if ($data->ses_sem_id==4){
           
          
            $update2 =  COURSEREGCHECKER::sempreviousupdate2($table,$user_data->formno,$user_data->matricno,$department);  
    
       }
   }
  
  
}



   if (isset($user_data->formno)){ 
   $formno=$user_data->formno;
    $msg = 'FORM NO:';
}
$ses_sem_id =$session_class->ses_sem_id;
     $surname = $biodata->surname;
   
    $prs = '20'.substr($user_data->formno,2,2);
    $session = $prs.'/'.($prs+1);
     
     
?>

    
    <div class="art-content-layout">
    <div class="art-content-layout-row">

 <div class="art-layout-cell layout-item-0" style="width: 100%" >
 
 <marquee behavior="alternate" scrolldelay="200" onmouseover="this.setAttribute('scrollamount',0,0);" onmouseout="this.setAttribute('scrollamount',6,0);" ><div style="color:#F00; font-style:italic; font-weight:bolder;">NOTE: <span style="color:#F00; font-style:italic;">Reprint all courses that has been registered by you.</span> </div></marquee>

 
 </div>
 </div>
 </div>  
    <div class="art-content-layout">
    <div class="art-content-layout-row">

 <div class="art-layout-cell layout-item-0" style="width: 100%" >
 
 
<div style="text-transform:uppercase; color:#099; font-weight:bolder; border-bottom:inset #000 thin;">Registration history </div>

</div>
 </div></div>



<div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-0" style="width: 100%; background-color:#FFF; margin:0; padding:0;" >
    
    
    <?php 
    
     
    
    
    foreach ($array_semester as $semid)
 
 {
     
    $semid1[]= $semid->sem_id;
     
 }
 
  $semid1 = array_values(array_unique($semid1));
          
     
  
    
    if (($level=='ND I') OR ($level=='ND II')){
        $lev='ND';
    }else if (($level=='HND I') OR ($level=='HND II')){
        $lev='HND';
    }
    
    //echo "<br> My level: ".$level;
     if (isset($semid1[0]) && ($semid1[0]==1)){
         
         
         
         $regTable = return_reg_table2($semid1[0], $lev);
         
      
         
       $found1= SESSIONCLASSNEW::Check_Stud_reg_rec($regTable, $semid1[0],$user_data->formno,$department);
        $prs = '20'.substr($user_data->formno,2,2);
    $session = $prs.'/'.($prs+1);
       
     }
     if  (isset($semid1[1]) && ($semid1[1]==2)){
         
         $regTable = return_reg_table2($semid1[1], $lev);
         
      $prs = '20'.substr($user_data->formno,2,2);
    $session = $prs.'/'.($prs+1);
       $found2= SESSIONCLASSNEW::Check_Stud_reg_rec($regTable, $semid1[1],$user_data->formno,$department);
     
  
         
     }
     if (isset($semid1[2]) && ($semid1[2]==3)){
         
       $regTable = return_reg_table2($semid1[2], $lev);
       
       
          $prs = '20'.(substr($user_data->formno,2,2) +1);
    $session2 = $prs.'/'.'20'.(substr($user_data->formno,2,2) +2);
       $found3= SESSIONCLASSNEW::Check_Stud_reg_rec($regTable,$semid1[2],$user_data->matricno,$department);
       
     }
     if (isset($semid1[3]) && ($semid1[3]==4)){
         
          $prs = '20'.(substr($user_data->formno,2,2) +1);
        $session2 = $prs.'/'.'20'.(substr($user_data->formno,2,2) +2);
         $regTable = return_reg_table2($semid1[3], $lev);
        
       $found4= SESSIONCLASSNEW::Check_Stud_reg_rec($regTable, $semid1[3],$user_data->matricno,$department);
       
     }
                
 if (isset($found1->matricno)){  
         
     $regTable = return_reg_table2($semid1[0], $lev);
    
	$qry = "SELECT * FROM $regTable
	WHERE matricno ='$found1->matricno' AND ses_sem_id='$semid1[0]' LIMIT 1";
    
    $result = $database->query($qry);
    
    	if ($result){

while($row = mysqli_fetch_array($result)){

    
   
    if (isset($row{"matricno"})){
    

         $matricno = $row{"matricno"};
        $ses_sem_id = $row{"ses_sem_id"};
         $code = $row{"courses"};
     	$date = $row{"regDate"};
    	
    
    	$ses_sem = SESSIONCLASS::find_by_id($ses_sem_id);
      
    	 //$session = $ses_sem->session;
          $semester = $ses_sem->semester;
    
        	?>
        	<p style=" text-transform:uppercase; color:#030;  font-weight:bolder; font-stretch:extra-expanded">
        	<?php echo $matricno.'     '. 'Registered Date: ' .$date.'       '. $session.'  '. $semester.'   ';?>
        	<a href="./reprint_courses.php?ses_sem_id=<? echo $ses_sem_id;?>" target ="_new"> <input type="button" class ="print" value="Reprint" /> </a>
    </p>
            <?php
    
    }
    
}
}
	

    
    
    
    
    
    
    
    
    
    
    
}
if (isset($found2->matricno))
{
    $regTable = return_reg_table2($semid1[1], $lev);
    
    
	$qry = "SELECT * FROM $regTable 
	WHERE matricno ='$found2->matricno' and ses_sem_id='$semid1[1]' LIMIT 1;
	";
	
	$result = $database->query($qry);
	

	
	if ($result){

while($row = mysqli_fetch_array($result)){

   
    if (isset($row{"matricno"})){
    

         $matricno = $row{"matricno"};
        $ses_sem_id = $row{"ses_sem_id"};
         $code = $row{"courses"};
     	$date = $row{"regDate"};
    	
    	$ses_sem = SESSIONCLASS::find_by_id($ses_sem_id);
        // $ses_sem = SESSIONCLASS::find_all();
    	// $session = $ses_sem->session;
         $semester = $ses_sem->semester;
    // 	if(($level == "ND I") OR ($level == "HND I"))
    // 	{
        	?>
        	<p style=" text-transform:uppercase; color:#030;  font-weight:bolder; font-stretch:extra-expanded"><?php echo $matricno;?>&nbsp<?php echo 'Registered Date: ' .$date;?>&nbsp<?php
        	echo $session;?>&nbsp<?php echo $semester;?>&nbsp<a href="./reprint_courses.php?ses_sem_id=<? echo $ses_sem_id;?>" style='color:#0f0'; target ="_new"> <input type="button" class ="print" value="Reprint" /> </a></p>
            <?php
    // 	}else{echo "Sorry, you have not registered for".$session." ".$semester;}
    	
    }
    
}
}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
if (isset($found3->matricno))
{
    $regTable = return_reg_table2($semid1[2], $lev);
   
	$qry = "SELECT * FROM $regTable 
	WHERE matricno in ($found3->matricno);
	";
	$result = $database->query($qry);
	
	
	
	
}
if (isset($found4->matricno))
{
    
  
      $regTable = return_reg_table2($semid1[3], $lev);
      
     
    $qry = "SELECT * FROM $regTable
	WHERE matricno in ($found4->matricno)
  ";
  
  $result = $database->query($qry);
}

//$result = mysql_query($qry);

if ($result){

while($row = mysqli_fetch_array($result)){

    
    
    if (isset($row{"matricno"})){
    

         $matricno = $row{"matricno"};
      $ses_sem_id = $row{"ses_sem_id"};
         $code = $row{"courses"};
     	$date = $row{"regDate"};
    	
    	$ses_sem = SESSIONCLASS::find_by_id($ses_sem_id);
        // $ses_sem = SESSIONCLASS::find_all();
    	 $session = $ses_sem->session;
         $semester = $ses_sem->semester;
    	if(($level == "ND I") OR ($level == "HND I"))
    	{
        	?>
        	<p style=" text-transform:uppercase; color:#030;  font-weight:bolder; font-stretch:extra-expanded"><?php echo $matricno;?>&nbsp<?php echo 'Registered Date: ' .$date;?>&nbsp<?php
        	echo $session2;?>&nbsp<?php echo $semester;?>&nbsp<a href="./reprint_courses.php?ses_sem_id=<? echo $ses_sem_id;?>" style='color:#0f0'; target ="_new"> <input type="button" class ="print" value="Reprint" /> </a></p>
            <?php
    	}
    	else if(($level == "ND II") OR ($level == "HND II"))
    	{
    	   
    	    ?>
    	    <p style=" text-transform:uppercase; color:#030;  font-weight:bolder; font-stretch:extra-expanded"><?php echo $matricno;?>&nbsp<?php echo 'Registered Date: ' .$date;?>&nbsp<?php
    	    echo $session2;?>&nbsp<?php echo $semester;?>&nbsp<a href="./reprint_courses.php?ses_sem_id=<? echo $ses_sem_id;?>" target ="_new"> <input type="button" class ="print" value="Reprint" /> </a></p>
            <?php
            
    	}else{echo "Sorry, you have not registered for".$session." ".$semester;}
    	
    }
    
}
}



  
      ?>
      
      
     
    
    
    <!--Display reg history content here......-->
    <!--<p style=" text-transform:uppercase; color:#030; font-size:22px; font-weight:bolder; font-stretch:extra-expanded"><?php echo $matricno; echo " "; echo $date; echo $ses_sem_id?></p>-->
    
    
    
    
    
    </div>
    
    </div>
</div>
</div>


</article></div>
    <style>
	/*#accept:hover {*/
	/*	text-decoration:none;*/
	/*	font-style:italic;*/
	/*}*/
	</style>
	
	<script >
	
//     $(document).ready(function(){
//         $(".print").on('click', function(e){
// 		e.preventDefault(e);
// 		$.ajax({
//             url:"Report.php",
//             method:"GET",
//             success: function(data)
// 			{
// 				window.open('Report.php');
// 			}
// 		})
//     });
    
//     $(".print2").on('click', function(e){
// 		e.preventDefault(e);
// 		$.ajax({
//             url:"Report2.php",
//             method:"GET",
//             success: function(data)
// 			{
// 				window.open('Report2.php');
// 			}
// 		})
//     });
    
//     });
        </script>