<?php

require_once('../../config.php');




	header("Content-Type: application/ms-excel");    
	header("Content-Disposition: attachment; filename=PSI Report.xls");  
	header("Pragma: no-cache"); 
	header("Expires: 0");


	
	$output = "";

	$output .="
		<table>
			<thead>
				<tr>
				 
					<th>Beneficiary Names</th>
                    <th>Birth Cert No</th>
                    <th>Nemis No</th>
                    <th>Name of Institution</th>
                    <th>Expected Y.O.C</th>
                    <th>Gender</th>
                    <th>Learner with special need</th>
                    <th>Amount Applied</th>
                    <th>Amount Awarded</th>
                    <th>Acknowledgement Ref No</th>
                    <th>Type of Sponsorship</th>
                    <th>Family Background</th>
                    <th>Ward</th>
                    <th>Institution Type</th>
                    
                    
                    
              
                   

				</tr>
			<tbody>
	";
	
	$query = $conn->query("SELECT * from details order by `ward` desc");
	while($fetch = $query->fetch_array()){
	    $sid=$fetch['name_of_institution'];
	    $uid=$fetch['uid'];
	    
		$sql11 = "SELECT * FROM schcode WHERE id='$sid'";
     $result11 = $conn-> query($sql11);

     
						 while ($row11 = $result11-> fetch_assoc()){
						 $schname=$row11['name'];
						 
		$sql1 = "SELECT * FROM applications WHERE user_id='$uid' and approved=1 and app_amount>0";
     $result1 = $conn-> query($sql1);

     
						 while ($row1 = $result1-> fetch_assoc()){
						 /*$row1['name']*/			 
						 
	 if($row1['sponsor'] == 2): 
          $sp="Partial Sponsored";
          else: 
           if($row1['sponsor'] == 0): 
               $sp="None";
              else: 
            $sp="Fully Sponsored";
             endif; endif; 			 
						 
						 
				$i=1;		 
						 
	$output .= "

				<tr>
				   
                    <td>".$fetch['name']."</td>
                    <td>".$fetch['dobn']."</td>
                    <td>".$fetch['admission_number']."</td>
                    <td>".$row11['name']."</td>
                     <td>".$fetch['year']."</td>
                     <td>".$fetch['gender']."</td>
                     <td>".$fetch['lneed']."</td>
                     <td>".$fetch['family_income']."</td>
                     <td>".$row1['app_amount']."</td>
                     <td>".$fetch['ack']."</td>
                     <td>".$sp."</td>
                     <td>".$fetch['fstatus']."</td>
                    <td>".$fetch['ward']."</td>
                    <td>".$fetch['inst_type']."</td>
                   
                    
                    
                    
                    
                    
                   
                    
                    

				</tr>
	";
	}
	}
	}
	$output .="
			</tbody>
			
		</table>
	";
	
	echo $output;
	
	

?>