Mini Shell

Direktori : /home/mhcadmin/public_html/Portal/
Upload File :
Current File : /home/mhcadmin/public_html/Portal/Fees_Payment_List.php

<?php
$rootPath = realpath(dirname(__FILE__) . '/..');
require_once $rootPath . '/Portal/config/config.php'; // Use clean config file

session_start();

if ($_SERVER["REQUEST_METHOD"] == "POST") {
	

 $Grade = mysqli_real_escape_string($conn, $_POST['Grade']);
 if ($Grade == 'All') {
    $query = mysqli_query($conn, "SELECT * FROM student WHERE Status = 'Active' ORDER BY Level, Full_Name ASC");
} else {
    $query = mysqli_query($conn, "SELECT * FROM student WHERE Level = '$Grade' AND Status = 'Active' ORDER BY Level, Full_Name ASC");
}
    $num = mysqli_num_rows($query);
          
	        if ($num >0){
				
				$delimeter = ",";
                $filename = "Fees_Payment_List_" . date('d-m-Y:i') . ".csv";
				
								$f = fopen('php://memory', 'w');
				$fields = array('Student_No', 'Full_Name', 'Level', 'Amount_Paid', 'Payment_Mode','Reference_No','Date_Paid');
				fputcsv($f, $fields, $delimeter);

				while ($row = mysqli_fetch_assoc($query)) {
					// Create line data with empty Marks field for user to fill
					$lineData = array($row['Student_No'], $row['Full_Name'], $row['Level'], '', '', '', '');
					fputcsv($f, $lineData, $delimeter);
				}
				
					fseek ($f, 0);
					
					header ('Content-Type: txt/csv');
					header('Content-Disposition: attachment; filename="' .$filename . '";');
						
						fpassthru($f);
						} else {
							
						$_SESSION['failure'] = "Students list not found for the selected Class";
                        header('location: ManageFeesPayments.php');
						}exit;


}

?>