<?php

//include '../configuration.php';


require_once '../functions_.php';

	//collect the course id
	if(isset($_GET['pid']))
	{
		$course_id = $_GET['cid'];

		//$did = $_GET['did']; //programme id
		$pid = $_GET['pid']; //programme id
		$ses = $_GET['ses']; //session id passed
		$ses = 5;
		$sem = $_GET['sem']; //semester id passed
		$level = $_GET['level']; //semester id passed
	}


//get current session
$session = 5;//get_current_session(1);//deprecatd for now
$session_title = get_session_title($ses);//passed
$session_titlet = str_replace('/','-',$session_title);



$semester = get_current_semester(1); //deprecated since I am using semester passed from url


//get the  course ttitle
// $code =  get_student_course_code($course_id);
// $code = str_replace(' ','-',$code);


//  $department_title = get_department_title($did);
//
//  $department_code = get_department_code($did);
//
// $title = $code.'-'.$session_titlet;


$programme_title = get_programme_title($pid);

$programme_code = get_programme_code($pid);

$title = $session_titlet.'-'.$programme_code;






header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename='.$programme_code.$level.$title.'.csv');

// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');

// output the column headings
fputcsv($output, array('RegNumber', 'MatricNo', 'SurName','OtherNames','Gender','CosCode','Prog','Mode','Level','Subjects','CAScore','ExamScore','SEDOption'));


// $rows = mysqli_query(dbc(),"SELECT   `student_id`, `total_score` ,`number`
// 					FROM `students_courses`
// 					WHERE session_id = '$ses' AND semester = '$sem'  AND md5(course_id) = '$course_id'
// 					ORDER BY `number`");


$rows1 = mysqli_query(dbc(),"SELECT s.id AS sid, s.number, s.first_name, s.other_names, s.department_id, s.programme_id, s.level

	FROM summer_students s, summer_school_fee_payments_nce sf
	WHERE s.id = sf.student_id AND s.programme_id = $pid AND s.session = $ses
	ORDER BY s.`number`");


//s.department_id = '$did'

//SELECT      `ca_score`, `exam_score`   FROM `students_courses_nce`

//s.level = '$level' AND
//AND session = '$ses'
// SELECT   `student_id`,`ca_score`, `exam_score` ,`number`
// 					FROM `summer_students_courses_nce`
// 					WHERE session_id = '$ses' AND semester = '$sem' AND programme_id = '$pid' AND md5(course_id) = '$course_id'
// 					ORDER BY `number`
//
//

// loop over the rows, outputting them
while ($rows = mysqli_fetch_array($rows1, MYSQLI_ASSOC))
{

	//fputcsv($output, $row);


	$name = str_replace(',',' ',get_student_fullname_summer($rows['sid']));

	$gender = get_student_gender_summer($rows['sid']);
	$number = $rows['number'];
	//
	//$department_title =  get_department_title($rows['department_id']);
	$programme_title =  get_programme_title($rows['programme_id']);
	$firstname = strtoupper($rows['first_name']);
	$other_names = strtoupper($rows['other_names']);
	//$programme_code;
	$prog = 'NCE';
	$mode = 'FT';
	$level = 'III';
	$subjects = get_student_registered_courses_summer($rows['sid'], $level, $ses, $sem);
	$ca_Score = get_student_cascore_courses_summer($rows['sid'], $level, $ses, $sem);
	$get_exam_score = get_student_examscore_courses_summer($rows['sid'], $level, $ses, $sem);
	$sed_option = '';





	//shorten gender
	//$gender = shorten_gender($gender);

	$line_data = array($number,$number,$other_names,$firstname,$gender,$programme_code,$prog,$mode,$level,$subjects,$ca_Score,$get_exam_score,$sed_option); //get_student_matric_no(

	fputcsv($output, $line_data);

}






exit();









?>
