<?php
session_start();
require_once("includes/initialize.php");
global $database;
// global $mail;
date_default_timezone_set('Africa/Lagos');
ini_set('max_execution_time', 300);



$alldept = ONLINEPAY::showdept();

// date_default_timezone_set('Africa/Lagos');
// $dprepare ="";
$allsession = ONLINEPAY::showsession();

// $tag = $_GET['type'];
// $_SESSION['tablename'] =$tag;

$_SESSION['ptype']='Testpass';

$Hod = $_SESSION["$HoD"];
// print_r($Hod);

$allsession = ONLINEPAY:: showsession();

$semesters = ONLINEPAY:: showsemester();




 $output=''; $output2='';$prog='';
  $course_arr=array();
 $courses='';
                

// //if(isset($_POST['fac']) || ($_POST['dpt']))
 if (isset($_POST['search']))
 {
 
 $dept = $_POST['department'];
 $session = $_POST['session'];
 $level = $_POST['level'];

  $semester = $_POST['semester'];
  
  
  
  
  $_SESSION['dept']= $dept;
  $_SESSION['sess']= $session;
  $_SESSION['lev']= $level;
 $_SESSION['semester']= $semester;
 
 
  
  switch ($level)
  {
  case 'ND I':
      $table='admitted_student_details_2019';
      $ctable='ndi_tbl';
      $ses_sem_id=3;
    break;  
  case 'HND I':
      $table='admitted_student_details_2019';
       $ctable='hndi_tbl';
        $ses_sem_id=3;
       break;
  case 'ND II':
     echo $table='admitted_student_details';
       $ctable='ndii_tbl';
        $ses_sem_id=3;
       break;
  case 'HND II': 
       $table='admitted_student_details';
       $ctable='hndii_tbl';
       $ses_sem_id=3;
         
  }
  
  $_SESSION['ses_sem_id'] =  $ses_sem_id;
  $table2="student_activity_level";
  //echo $table;
  $paydetails=array();
 $count = 0; $total_sum=0; $brief='';

    if ($level=='ND I'){
        $nlevel =substr($level, 0,2);
    }else{
       $nlevel =substr($level, 0,3); 
    }
   
   
   //echo "guyy: ".$nlevel." po:m ". $level."<br>";
    if (($level=='ND I') OR ($level=='HND I')){
        
         mysql_query("SET SQL_BIG_SELECTS=1");
        
    //   $sql = mysql_query("SELECT s.formno as formno, l.matricno as matricno FROM schoolfees_tranzact as s JOIN student_activity_level as l ON s.formno = l.formno AND s.responsecode='00' AND s.session='{$session}' AND s.level IN ('$level', '$nlevel') AND s.department LIKE '%$dept%' JOIN $ctable as c ON c.matricno = l.matricno AND c.ses_sem_id='{$ses_sem_id}' ORDER BY s.formno ASC
    //   ");
        
        
        
        
        
        
     $sql = mysql_query("SELECT schoolfees_tranzact.formno as formno, $ctable.matricno as matricno FROM schoolfees_tranzact INNER JOIN $ctable ON schoolfees_tranzact.formno = $ctable.matricno WHERE schoolfees_tranzact.department LIKE '%$dept%' and schoolfees_tranzact.level IN ('$level', '$nlevel') and schoolfees_tranzact.session= '{$session}' and schoolfees_tranzact.responsecode='00' and $ctable.ses_sem_id='{$ses_sem_id}' ORDER BY formno ASC ");
    }
    else if (($level=='ND II') OR ($level=='HND II')){
        
        mysql_query("SET SQL_BIG_SELECTS=1");
        
      $sql = mysql_query("SELECT s.formno as formno, c.matricno as matricno FROM schoolfees_tranzact as s JOIN student_activity_level as l ON s.formno = l.formno AND s.responsecode='00' AND s.session='{$session}' AND s.level='{$level}' AND s.department LIKE '%$dept%' JOIN $ctable as c ON c.matricno = l.matricno AND c.ses_sem_id='{$ses_sem_id}' ORDER BY c.matricno ASC
      ");

        // $sql = mysql_query("SELECT s.formno, c.matricno FROM schoolfees_tranzact as s LEFT JOIN student_activity_level as l ON s.formno = l.formno AND s.responsecode='00' AND s.session='{$session}' AND s.level='{$level}' AND s.department LIKE '%$dept%' LEFT JOIN $ctable as c ON c.matricno = l.matricno AND c.ses_sem_id='{$ses_sem_id}' ORDER BY c.matricno ASC
              
            
        //   ");
          
          //   $sql = mysql_query("SELECT schoolfees_tranzact.formno as formno, student_activity_level.matricno as matricno FROM student_activity_level INNER JOIN schoolfees_tranzact ON schoolfees_tranzact.formno = student_activity_level.formno
            //   WHERE schoolfees_tranzact.department LIKE '%$dept%' and schoolfees_tranzact.level IN ('$level') and schoolfees_tranzact.session= '{$session}' and schoolfees_tranzact.responsecode='00'  ORDER BY student_activity_level.matricno ASC

    }

   if (!$sql){
       
       echo "<span style='color:red; font-weight:bolder; text-align:center'>".'Error retrieving datas, please try again !!!.'."</span>";
       
   }else {
    while ($row=mysql_fetch_array($sql)){
        
        if (isset($row['matricno'])){
            $formno = $row['matricno'];
        }
         
         
             $formno2 = $row['formno']; 
          
              
        if (($level=='ND I') OR ($level=='HND I')){
           
           $formno = $formno2;
         $sql1 = mysql_query("SELECT admission_list.formno,admission_list.names  FROM admission_list INNER JOIN admitted_student_details_2019 ON admission_list.formno = admitted_student_details_2019.formno WHERE admission_list.formno='".$formno."' ORDER BY formno ASC");
         
           
        
        while ($row1 = mysql_fetch_array($sql1)){
            
           $names = $row1['names'];
              
         }
        
            
        } else if (($level=='ND II') OR ($level=='HND II')){
            
            //echo "Test".' '.$level;
        
        
        
        
        
        
         $sql5 = mysql_query("SELECT admitted_student_details.surname, admitted_student_details.othernames FROM admitted_student_details  WHERE admitted_student_details.formno='".$formno2."' LIMIT 1");
        
        if ($row5 = mysql_fetch_array($sql5)){
            
            $names = $row5['surname'] .' '.$row5['othernames'];
            
            //echo "yuu: ".$formno = $row1['formno'];
            
                
                
               
                
          //  }
            
        }
        
        }
        
      
        $paydetails[]=array($formno, $names, $pix, $courses);
        
     
        } 
   } // From the first mysql_num_rows in ND I and HND I
             
            //print_r($course_arr);
 
 } else {
   $output= "<center><h4>No record to display</h4></center>";
   
 }

            
            
            
            
  ?>          
            
  
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
    <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>  
    <script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script> 
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.css" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>
</head>
    <body>       
		<div class="container" align="center">
			<h2 align="center">Welcome :: <?php echo $Hod;?> Head of Department</h2><br/>
			    <form method="post" action="?type=Testpass" enctype="multipart/form-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 if (is_array($Hod))
                							{
                							    foreach($Hod as $dept)
                							{ ?>
                							<option value="<?php echo $dept;?>"><?php 
                							echo strtoupper($dept);?></option> <?php }}
                							else 
                							{?>
                							    <option value="<?php echo $Hod;?>"><?php 
                							echo strtoupper($Hod);?></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>
                                    <select name="semester" id="semester" class="form-control action" style="width:120px">
                                        <option value="">Select Semester</option>
                                        <?php foreach($semesters as $sem){?>
                                        <option value="<?php echo $sem->semester;?>"><?php 
                                        echo $sem->semester?></option><?php }?>
                                    </select></td>
                                    <!--<td>-->
                                    <!--<select name="batch" id="batch" class="form-control action" style="width:120px">-->
                                    <!--    <option value="">Select Matric Batch</option>-->
                                    <!--    <option value="1">Batch 1</option>-->
                                    <!--    <option value="2">Batch 2</option>-->
                                    <!--    <option value="3">Batch 3</option>-->
                                    <!--    <option value="4">Batch 4</option>-->
                                    <!--</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>
					
					
					
					 <div class="panel panel-primary chat-panel">
                    <div class="panel-heading ">
                     <h3><? echo $msg;?></h3>
                    </div><br/>
                <div class="table-responsive">
                    <table class="table table-bordered table-hover table-condensed" id="fo_table">
                   
                    <thead>
                        <tr>
                            <th colspan="3" style="text-align: center"><h1>Department: <?php echo $_SESSION['dept']; ?></h1></th>
                            </tr>
                            
                            <tr>
                            <th><strong>Session: <?php echo $semester; ?></strong></th>
                            
                             <th><strong>Level: <?php echo $level; ?></strong></th>
                             
                             <th><strong>Semester: <?php echo $semester; ?></strong></th>
                        </tr>
                             
                             <tr><th colspan="3"></th></tr>
                              <tr>
                                
                                
                                     <th>S/N</th>  
                                         <th>MATRIC NO</th>  
                                         
                                         <th>FULLNAME</th>     
                                          
                                     </tr>
                                
                              </tr>
                     </thead>   
                        
                        <?php
                        
                       if (isset($paydetails) AND sizeof($paydetails)>0){
                
                        foreach ($paydetails as $student){
    
                       
					   echo '<tr>'
 							.'<td>'.++$count.'</td>'
 							.'<td>'.$student[0].'</td>'
 							.'<td>'.strtoupper($student[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>
            
            
            
            
            
            
            
             