<?php



//session_start();

require_once('configuration.php');


ob_start();




//Function to fetch matric number
function get_student_mat_no($user_id)
{
	$result = mysqli_query(dbc(),"SELECT number FROM students_nce WHERE id = $user_id");
	$row = mysqli_fetch_assoc($result);
	$v = $row['number'];


return $v;
}


//Function to fetch matric number
function get_student_mat_no_prence($user_id)
{
	$result = mysqli_query(dbc(),"SELECT number FROM students_prence WHERE id = $user_id");
	$row = mysqli_fetch_assoc($result);
	$v = $row['number'];


return $v;
}

// //Functions to fetch user's gender
// 	function get_student_gender($user_id)
// 	{
// 		$result = mysqli_query(dbc(),"SELECT gender FROM students_nce WHERE id = '$user_id'");
// 		$row = mysqli_fetch_assoc($result);
// 		$gd = $row['gender'];
//
//
// 	return $gd;
// 	}



//function that gets  department base on user id
function  get_student_department_id($user_id)
{
$result = mysqli_query(dbc(),"SELECT department_id FROM students_nce WHERE id = $user_id");
  $row = mysqli_fetch_assoc($result);
  $v = $row['department_id'];

return $v;

}


// //function that gets  department base on user id
// function  get_student_department_id_prence($user_id)
// {
// $result = mysqli_query(dbc(),"SELECT department_id FROM students_prence WHERE id = $user_id");
//   $row = mysqli_fetch_assoc($result);
//   $v = $row['department_id'];
//
// return $v;
//
// }

//function that gets  programme base on user id
function  get_student_programme_id($user_id)
{
$result = mysqli_query(dbc(),"SELECT programme_id FROM students_nce WHERE id = $user_id");
  $row = mysqli_fetch_assoc($result);
  $v = $row['programme_id'];

return $v;

}


//function that gets  programme based on user id
function  get_student_SED_programme_id($user_id)
{
$result = mysqli_query(dbc(),"SELECT sed_prog_id  FROM students_nce WHERE id = $user_id");
  $row = mysqli_fetch_assoc($result);
  $v = $row['sed_prog_id'];

return $v;

}


// //function that gets  programme base on user id for prence
// function  get_student_programme_id_prence($user_id)
// {
// $result = mysqli_query(dbc(),"SELECT programme_id FROM students_prence WHERE id = $user_id");
//   $row = mysqli_fetch_assoc($result);
//   $v = $row['programme_id'];
//
// return $v;
//
// }


//function that gets programme type _id base on user id
	  function  get_student_programme_type_id($user_id)
	  {
		  $result = mysqli_query(dbc(),"SELECT type_id FROM students_nce WHERE id = $user_id");
			  $row = mysqli_fetch_assoc($result);
			  $v = $row['type_id'];

		  return $v;

	  }

		//function dat get user image by id
		function get_student_image($user_id)
		{
		$q = "SELECT image FROM students_nce WHERE id = '$user_id'";
		$r = mysqli_query(dbc(),$q);
		$row = mysqli_fetch_assoc($r);

		return $row['image'];


		}



		//function dat get user image by id for prence
		function get_student_image_prence($user_id)
		{
		$q = "SELECT image FROM students_prence WHERE id = '$user_id'";
		$r = mysqli_query(dbc(),$q);
		$row = mysqli_fetch_assoc($r);

		return $row['image'];


		}


		//function that gets  department base on user id
			  function  get_student_school_id($user_id)
			  {
				  $result = mysqli_query(dbc(),"SELECT school_id FROM students_nce WHERE id = $user_id");
					  $row = mysqli_fetch_assoc($result);
					  $v = $row['school_id'];

				  return $v;

			  }


				// //function that gets  department base on user id for prence
				// 		function  get_student_school_id_prence($user_id)
				// 		{
				// 			$result = mysqli_query(dbc(),"SELECT school_id FROM students_prence WHERE id = $user_id");
				// 				$row = mysqli_fetch_assoc($result);
				// 				$v = $row['school_id'];
				//
				// 			return $v;
				//
				// 		}

				//Function to fetch user level
	function get_student_level($id)
	{
		$result = mysqli_query(dbc(),"SELECT level FROM students_nce WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['level'];

	return $v;
	}



	//Function to fetch user level for prence
function get_student_level_prence($id)
{
$result = mysqli_query(dbc(),"SELECT level FROM students_prence WHERE id = '$id'");
$row = mysqli_fetch_assoc($result);
$v = $row['level'];

return $v;
}



//funcion that gets course name base on course id
	function get_student_course_name($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT title FROM courses WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$title = $row['title'];


	return $title;
	}


	//function that get course code base on course id
	function get_studentt_course_code($id)
	{
		$result = mysqli_query(dbc(),"SELECT code FROM courses WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$title = $row['code'];


	return $title;
	}



	//function that get course code base on course id for prence
	function get_studentt_course_code_prence($id)
	{
		$result = mysqli_query(dbc(),"SELECT code FROM courses WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$title = $row['code'];


	return $title;
	}



	//function that gets course unit base on course unit
	function get_student_course_unit($id)
	{
		$result = mysqli_query(dbc(),"SELECT unit FROM courses WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$unit = $row['unit'];


	return $unit;
	}

	//function that gets courses semester belongs to, using course id from courses table
	function get_student_course_semester($id)
	{
		$result = mysqli_query(dbc(),"SELECT semester FROM courses WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$semester = $row['semester'];


	return $semester;
	}



	//function that gets course unit base on course unit
	function get_student_course_dept_id($id)
	{
		$result = mysqli_query(dbc(),"SELECT department_id FROM courses WHERE id = $id");
		$row = mysqli_fetch_assoc($result);
		$v = $row['department_id'];


	return $v;
	}


	//function that gets course unit base on course unit
	function get_student_course_category($id)
	{
		$result = mysqli_query(dbc(),"SELECT course_category FROM courses WHERE id = $id");
		$row = mysqli_fetch_assoc($result);
		$v = $row['course_category'];


	return $v;
	}

	function get_student_course_token($id, $level, $student, $ses)
	{
		$result = mysqli_query(dbc(),"SELECT delete_token FROM students_courses_nce WHERE course_id = '$id' AND level = '$level' AND student_id = '$student' AND session_id = '$ses'");
		$row = mysqli_fetch_assoc($result);
		$token = $row['delete_token'];


	return $token;
	}

	function get_student_course_token_for_edit($id, $level, $student, $ses)
	{
		$result = mysqli_query(dbc(),"SELECT delete_token FROM students_courses_nce WHERE  level = '$level' AND student_id = '$student' AND session_id = '$ses'"); //course_id = '$id' AND
		$row = mysqli_fetch_assoc($result);
		$token = $row['delete_token'];


	return $token;
	}

	//function that gets courses level belongs to, using course id from programmes courses table
	function get_student_course_level_from_pc($programme_id,$id)
	{
		$result = mysqli_query(dbc(),"SELECT level FROM programmes_courses_nce WHERE programme_id ='$programme_id' AND course_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$level = $row['level'];


	return $level;
	}



	//function that gets courses level belongs to, using course id from programmes courses table
	function get_student_seen_as_elective_from_pc($programme_id,$id)
	{
		$result = mysqli_query(dbc(),"SELECT seen_as_elective FROM programmes_courses_nce WHERE  programme_id ='$programme_id' AND course_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['seen_as_elective'];


	return $v;
	}

	//function that gets courses token from students_courses table in order to delete by id , also pass level so it could del base on level you registered the corse
	// function get_student_course_token($id, $level, $student)
	// {
	// 	$result = mysqli_query(dbc(),"SELECT delete_token FROM students_courses_nce WHERE course_id = '$id' AND level = '$level' AND student_id = '$student'");
	// 	$row = mysqli_fetch_assoc($result);
	// 	$token = $row['delete_token'];


	// return $token;
	// }


	//Function to fetch check if payment has been made by particular student
	function has_paid_school_fee($user_id,$session)
	{
		$q = "SELECT student_id,session, payment_status
			  FROM school_fee_payments_nce
			  WHERE student_id = '$user_id'
			  AND session = '$session'
			  AND payment_status  = '1'";
		$r = mysqli_query(dbc(),$q);

		//$row = mysqli_fetch_assoc($result);

		if(mysqli_num_rows($r)== 0)
		{
			return false;

		}
		else
		{
			return true;
		}

	}


	//Function to fetch check if he has done registration in  a current session
	function has_done_registration($user_id, $session)
	{
		$q = "SELECT student_id, session_id FROM students_courses_nce  WHERE student_id = '$user_id' AND session_id = '$session'";
		$r = mysqli_query(dbc(),$q);

		//$row = mysqli_fetch_assoc($result);

		if(mysqli_num_rows($r)== 0)
		{
			return false;

		}
		else
		{
			return true;
		}

	}





//function that shows courses to register
function courses_to_register($student, $session, $semester, $dept, $programme, $level, $pt)
{


	//collect pre checked check boxes from session incase the page ahead bounces back
	if(isset($_SESSION['cs']))
	{
		$carts = $_SESSION['cs'];

	}
	else
	{
		//$carts = pre_check_courses($student,$level,$semester, $session);

		$carts = students_courses_comma_separated($student,$level,$semester, $session);

		//print_r($carts);

	}




	//comment incase
	//DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
	//	 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by

	//recently removed level and commented  - AND pc.level = '$level'
	//query the database
	$q = "SELECT c.id as cid, c.title, c.course_description, c.programme_id, c.department_id, c.code, c.unit, c.level, c.semester, c.course_type,c.major_status,
		 c.course_description, pc.department_id AS pc_did, pc.school_id AS pc_sid,
		  pc.programme_id AS pc_pid, pc.course_id AS pc_cid, pc.seen_as_elective, pc.session_id, pc.semester AS pc_semester, pc.level AS pc_level, pc.programme_type_id, pc.status
		  FROM courses c, programmes_courses_nce pc
		  WHERE c.semester = '$semester'
		  AND pc.course_id = c.id
		  AND pc.programme_id = '$programme'

		  AND pc.programme_type_id = '$pt'
		  AND pc.status = 0

			AND c.id NOT IN ($carts)


		  GROUP BY c.id
		  ORDER BY  pc.seen_as_elective ASC, c.code ASC"; //added cid NOT in recently so inserting can happen without deleting experience

	$r = mysqli_query(dbc(),$q);
	$sn = 0 ;
	if(mysqli_num_rows($r) > 0)
	{//show table


		  $output =
		  '<table class="table user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>S/N</th>
						<th>Code</th>
						<th>Title</th>
						<th>Type</th>
						<th>Credit Unit</th>
						<!--<th>Level</th>-->
						<!--<th>Semester</th>-->
						<th> <input type="checkbox" id="selecctall" data-toggle = "tooltip" title = "Check All"   value=""></th>


			</thead>
		  <tbody>';

		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{


			//get the course totals to add up units to show
			//add total unit carried
			$total_units = 0;
			$total_unit = $total_units + get_course_unit($row['cid']);
			$t += $total_unit;


			$output .= "<tr>";
			$output .= "<td>".$sn = $sn+1 ."</td>";
			$output .= "<td>".$row['code']."(".show_major_status($row['major_status']).")</td>";
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".seen_as_elective($row['seen_as_elective'])."</td>";
		    $output .= "<td>".$row['unit']."</td>";
			//$output .= "<td>".$row['level']."</td>";
			//$output .= "<td>".$row['semester']."</td>";

			//commecnted this
			//check if the passed ids are in new 1
			//the course id to check will be from programmes_courses table since its the 1 we used to know courses u wd do
			if(preg_match( "/\b".$row['cid']."\b/i", $carts))
			{
				$output .="<td><input type='checkbox' value='".$row['cid']."' name='course[]' id='course' class='checkbox1'  checked /></td>" ;

			}
			else
			{
				$output .="<td><input type='checkbox' value='".$row['cid']."' name='course[]' id='course' class='checkbox1' /></td>" ;

			}


			$output .= "</tr>";


		}

		$output .= "<tr>";
			$output .= "<td colspan='4'></td>";
			//$output .= "<td>Total - </td>";
			$output .= "<td>Sub Total </td>";
			$output .= "<td>".$t."</td>";
			$output .= "</tr>";
	}
	else
	{//show the msg

			$output =
				   '<div class="alert alert-danger alert-dismissable">
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';


	}



	$output .=
	'</tbody>
    </table>';





	return $output;


}//end of function



//function that check and show if course is seen as core or elective
	function seen_as_elective($c)
	{


		if($c == 0)
		{
			return '<h4 class="label label-default">CORE</h4>';
		}
		else if($c == 1)
		{
			return '<h4 class="label label-info">ELECTIVE</h4>';
		}
		else
		{
			return '<h4 class="label label-default">CORE</h4>';
		}
	}

	//function seen as elective for pdf
	function seen_as_elective_for_pdf($c)
	{


		if($c == 0)
		{
			return 'C';
		}
		else if($c == 1)
		{
			return 'E';
		}
		else
		{
			return 'C';
		}
	}


//function to pre check the courses
function pre_check_courses($student,$level,$semester, $session)
{
		$courses = array();

		$q3 = "SELECT id, student_id, programme_id, course_id, course_unit,session_id,  level, semester, date_added
			   FROM  students_courses_nce
			   WHERE
			   student_id = '$student'
			   AND semester = '$semester'

			   AND session_id = '$session'"; //AND level = '$level' didnt use level again because it was preventing to call other courses from different level

		$r3 = mysqli_query(dbc(),$q3);
	    $sn = 0 ;

	    $output = '';

				while($row3 = mysqli_fetch_array($r3, MYSQLI_ASSOC))
				{

						$courses[] = $row3['course_id'];
					//}

				}


			  $new_courses = implode(' ', $courses);



		return $new_courses;

}




//function to pre check the courses
function students_courses_comma_separated($student,$level,$semester, $session)
{
		$courses = array();

		$q3 = "SELECT id, student_id, programme_id, course_id, course_unit,session_id,  level, semester, date_added
			   FROM  students_courses_nce
			   WHERE
			   student_id = $student
			   AND semester = $semester

			   AND session_id = $session"; //AND level = '$level' didnt use level again because it was preventing to call other courses from different level

		$r3 = mysqli_query(dbc(),$q3);
	    $sn = 0 ;

	    $output = '';

				while($row3 = mysqli_fetch_array($r3, MYSQLI_ASSOC))
				{

						$courses[] = $row3['course_id'];
					//}

				}


			  $new_courses = implode(',', $courses);



		return $new_courses;

}// return registerd courses in comma seperated values

//function to get total units of courses a student carried per semester
function get_student_total_course_unit_registered_per_semester($student_id, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT SUM(course_unit) AS summed_up FROM students_courses_nce WHERE student_id = '$student_id' AND session_id = '$session' AND semester = '$semester'");
	$row = mysqli_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}

//function tha gen delete token for delete
function delete_course_token()
{
		for($i=0;$i<=20;$i++){
			$key .=mt_rand(0,9);
		}
		return $key.date('YHmhis');
}




//function that get student list in of computed results per semester
function view_students_list($ses,$sem,$sid,$pid,$level)
{








	//show list of students who are still in school
	//dont show the dropped course bu the students

	$q = "SELECT s.`id`, s.`number`, s.`first_name`,s.`other_names`



	FROM `students_nce` s


	WHERE  s.`programme_id` = '$pid' AND s.`level` = '$level'


	ORDER BY s.`number` ASC "; //sr.`student_id` = s.`id` AND


		//sr.`session_id` = '$ses' AND sr.`semester` = '$sem' AND





	$r = mysqli_query(dbc(),$q);



	//in the table below result_table stands for resullt fetch throug seraching table(ajax)


	if(mysqli_num_rows($r) > 0)
	{//show table




	$output ='<table id="example" class="user display table-bordered table-hover table-striped responsive" width="100%"  cellspacing="0" style="font-size:10px;">


				<thead>



				<tr>


				  		<td >S/NO </td>
				  		<td >MATRIC NO</td>

				  		<td >NAMES</td>

				  		<td > Gender </td>


				  		<td > Phone No. </td>
				  		<td > Action </td>







				</tr>
				</thead>


				<tbody>
				';



				//$sn = 0;

		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			$output .= "<tr>";

			$output .='<td width = "3%">&nbsp;&nbsp;<input type="checkbox" value="'.$row['srid'].'" name="result[]" id="result" class="checkbox1"/></td>' ;

			$output .= '<td width = "9%">'.$row['number'].'</td>';
			$output .= '<td width = "13%">'.strtoupper($row['first_name'].' '.$row['other_names']).'</td>';

			$output .= '<td width = "3%" >'.$row['edu_tcur'].'</td>';
			$output .= '<td width = "3%" >'.$row['edu_tcue'].'</td>';
			$output .= '<td width = "3%" >View Course Reg</td>';

			$output .= '</tr>';



		}
	}
	else
	{//show the msg

			$output =
				   '<div class="alert alert-danger alert-dismissable">
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';


	}



	$output .=
	'</tbody>
    </table>';





	return $output;




}//end of view students list of computed result

//implementation for more function from result system_inf

//function total credit unit registered  previously
function get_student_total_prev_credit_unit_registered_per_semester($student, $session, $semester)
{
 $result = mysqli_query(dbc(),"SELECT cum_ptcur FROM students_results_nce WHERE session_id = $session  AND student_id = $student AND semester = $semester");
 $row = mysqli_fetch_assoc($result);
 $v = $row['cum_ptcur'];


return $v;
}


//function total credit unit registered  previously for PRENCE
function get_student_total_prev_credit_unit_registered_per_semester_prence($student, $session, $semester)
{
 $result = mysqli_query(dbc(),"SELECT cum_ptcur FROM students_results_prence WHERE session_id = $session  AND student_id = $student AND semester = $semester");
 $row = mysqli_fetch_assoc($result);
 $v = $row['cum_ptcur'];


return $v;
}//for prence


//function total grade points   previously
function get_student_total_prev_grade_points_per_semester($student, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT cum_ptgpe FROM students_results_nce WHERE session_id = $session  AND student_id = $student AND semester = $semester");
	$row = mysqli_fetch_assoc($result);
	$v = $row['cum_ptgpe'];


return $v;
}


//function total grade points   previously for prence
function get_student_total_prev_grade_points_per_semester_prence($student, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT cum_ptgpe FROM students_results_prence WHERE session_id = $session  AND student_id = $student AND semester = $semester");
	$row = mysqli_fetch_assoc($result);
	$v = $row['cum_ptgpe'];


return $v;
}//for prence


//function total credit units earned  previously
function get_student_total_credit_units_earned_per_semester($student, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT cum_ptcue FROM students_results_nce WHERE session_id = $session  AND student_id = $student AND semester = $semester");
	$row = mysqli_fetch_assoc($result);
	$v = $row['cum_ptcue'];


return $v;
}


//function total credit units earned  previously for prence
function get_student_total_credit_units_earned_per_semester_prence($student, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT cum_ptcue FROM students_results_prence WHERE session_id = $session  AND student_id = $student AND semester = $semester");
	$row = mysqli_fetch_assoc($result);
	$v = $row['cum_ptcue'];


return $v;
}//for prence

//function total grade points average   previously
function get_student_total_prev_gpa_per_semester($student, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT prev_gpa FROM students_results_nce WHERE session_id = $session  AND student_id = $student AND semester = $semester");
	$row = mysqli_fetch_assoc($result);
	$v = $row['prev_gpa'];


return $v;
}


//function total grade points average   previously for PRENCE
function get_student_total_prev_gpa_per_semester_prence($student, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT prev_gpa FROM students_results_prence WHERE session_id = $session  AND student_id = $student AND semester = $semester");
	$row = mysqli_fetch_assoc($result);
	$v = $row['prev_gpa'];


return $v;
}//for prence

//function total credit unit registered present
function get_student_total_present_credit_unit_registered_per_semester($student, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT SUM(course_unit)  AS summed_up
			   FROM students_courses_nce  WHERE student_id = $student AND session_id = $session AND semester = $semester");
	$row = mysqli_fetch_assoc($result);
	$v = $row['summed_up'];


	return $v;
}


//function total credit unit registered present for prence
function get_student_total_present_credit_unit_registered_per_semester_prence($student, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT SUM(course_unit)  AS summed_up
			   FROM students_courses_prence  WHERE student_id = $student AND session_id = $session AND semester = $semester");
	$row = mysqli_fetch_assoc($result);
	$v = $row['summed_up'];


	return $v;
}//for prence



//function total grade_points present
function get_student_total_present_grade_points_per_semester($student, $session, $semester)
{
	$q = "SELECT course_unit,total_score

		   FROM students_courses_nce  WHERE student_id = $student AND session_id = $session AND semester = $semester";
			$r = mysqli_query(dbc(),$q);

			//initialise
			//$total_grade_point = 0;

	while ($row2 =mysqli_fetch_array($r,MYSQLI_ASSOC))
	{
		 $total_grade_point = get_student_grade_point_score($row2['total_score']) * $row2['course_unit'];

		 $total_grade_point2 += $total_grade_point;

	}


	return  $total_grade_point2;
}


//function total grade_points present
function get_student_total_present_grade_points_per_semester_prence($student, $session, $semester)
{
	$q = "SELECT course_unit,total_score

		   FROM students_courses_prence  WHERE student_id = $student AND session_id = $session AND semester = $semester";
			$r = mysqli_query(dbc(),$q);

			//initialise
			//$total_grade_point = 0;

	while ($row2 =mysqli_fetch_array($r,MYSQLI_ASSOC))
	{
		 $total_grade_point = get_student_grade_point_score($row2['total_score']) * $row2['course_unit'];

		 $total_grade_point2 += $total_grade_point;

	}


	return  $total_grade_point2;
}


//function total grade_points present
function get_student_total_present_credit_units_earned_per_semester($student, $session, $semester)
{
	$q = "SELECT SUM(course_unit)  AS summed_up
		FROM students_courses_nce  WHERE student_id = $student  AND semester = $semester AND session_id = $session AND total_score > 39";
	$r = mysqli_query(dbc(),$q);

	$row = mysqli_fetch_assoc($r);
	$v = $row['summed_up'];


	return $v;
}


//function total grade_points present
function get_student_total_present_credit_units_earned_per_semester_prence($student, $session, $semester)
{
	$q = "SELECT SUM(course_unit)  AS summed_up
		FROM students_courses_prence  WHERE student_id = $student  AND semester = $semester AND session_id = $session AND total_score > 39";
	$r = mysqli_query(dbc(),$q);

	$row = mysqli_fetch_assoc($r);
	$v = $row['summed_up'];


	return $v;
}

//function total gpa present
function get_student_total_present_gpa_per_semester($student, $session, $semester)
{


	//get total gradepoint earned divide by tcur registered



	 $tgp_earned_cummulativeo = get_student_total_present_grade_points_per_semester($student, $session, $semester);

	 $tcur_cummulativeo = get_student_total_present_credit_unit_registered_per_semester($student, $session, $semester);



	@$current_gpa =  $tgp_earned_cummulativeo / $tcur_cummulativeo;

	return  number_format($current_gpa,2);
}



//function total gpa present for PRENCE
function get_student_total_present_gpa_per_semester_prence($student, $session, $semester)
{


	//get total gradepoint earned divide by tcur registered



	 $tgp_earned_cummulativeo = get_student_total_present_grade_points_per_semester_prence($student, $session, $semester);

	 $tcur_cummulativeo = get_student_total_present_credit_unit_registered_per_semester_prence($student, $session, $semester);



	@$current_gpa =  $tgp_earned_cummulativeo / $tcur_cummulativeo;

	return  number_format($current_gpa,2);
}//for prence


//function total credit unit registered cumulative
function get_student_total_cummulative_credit_unit_registered_per_semester($student, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT cum_tcur FROM students_results_nce WHERE session_id = $session  AND student_id = $student AND semester = $semester");
	$row = mysqli_fetch_assoc($result);
	$v = $row['cum_tcur'];


	return $v;
}

//function total credit unit registered cumulative for prence
function get_student_total_cummulative_credit_unit_registered_per_semester_prence($student, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT cum_tcur FROM students_results_prence WHERE session_id = $session  AND student_id = $student AND semester = $semester");
	$row = mysqli_fetch_assoc($result);
	$v = $row['cum_tcur'];


	return $v;
}//fr prence


//function total credit unit  cumulative
function get_student_total_cummulative_grade_points_per_semester($student, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT cum_tgpe FROM students_results_nce WHERE session_id = $session  AND student_id = $student AND semester = $semester");
	$row = mysqli_fetch_assoc($result);
	$v = $row['cum_tgpe'];


	return $v;
}


//function total credit unit  cumulative for prence
function get_student_total_cummulative_grade_points_per_semester_prence($student, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT cum_tgpe FROM students_results_prence WHERE session_id = $session  AND student_id = $student AND semester = $semester");
	$row = mysqli_fetch_assoc($result);
	$v = $row['cum_tgpe'];


	return $v;
}


//function total credit unit  earned cumulative
function get_student_total_cummulative_credit_units_earned_per_semester($student, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT cum_tcue FROM students_results_nce WHERE session_id = $session  AND student_id = $student AND semester = $semester");
	$row = mysqli_fetch_assoc($result);
	$v = $row['cum_tcue'];


	return $v;
}


//function total credit unit  earned cumulative for PRENCE

function get_student_total_cummulative_credit_units_earned_per_semester_prence($student, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT cum_tcue FROM students_results_prence WHERE session_id = $session  AND student_id = $student AND semester = $semester");
	$row = mysqli_fetch_assoc($result);
	$v = $row['cum_tcue'];


	return $v;
}//for prence



//function total credit unit  cumulative
function get_student_total_cummulative_gpa_per_semester($student, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT cum_cgpa FROM students_results_nce WHERE session_id = $session  AND student_id = $student AND semester = $semester");
	$row = mysqli_fetch_assoc($result);
	$v = $row['cum_cgpa'];


	return $v;
}


//function total credit unit  cumulative for PRENCE
function get_student_total_cummulative_gpa_per_semester_prence($student, $session, $semester)
{
	$result = mysqli_query(dbc(),"SELECT cum_cgpa FROM students_results_prence WHERE session_id = $session  AND student_id = $student AND semester = $semester");
	$row = mysqli_fetch_assoc($result);
	$v = $row['cum_cgpa'];


	return $v;
}//for prence


//function remark 2 per semester
function get_student_remark2_per_semester($student, $session, $semester)
{


			$result = mysqli_query(dbc(),"SELECT remark2 FROM students_results_nce WHERE session_id = $session  AND student_id = $student AND semester = $semester");
			$row = mysqli_fetch_assoc($result);


			$v = $row['remark2'];

		  return $v;


}



//function remark 2 per semester for PRENCE
function get_student_remark2_per_semester_prence($student, $session, $semester)
{


			$result = mysqli_query(dbc(),"SELECT remark2 FROM students_results_prence WHERE session_id = $session  AND student_id = $student AND semester = $semester");
			$row = mysqli_fetch_assoc($result);


			$v = $row['remark2'];

		  return $v;


}//for prence


//function remark per semester
function get_student_remark1_per_semester($student, $session, $semester)
{



			$result = mysqli_query(dbc(),"SELECT remark1 FROM students_results_nce WHERE session_id = $session  AND student_id = $student AND semester = $semester");
			$row = mysqli_fetch_assoc($result);


 			$v = $row['remark1'];



			 	for ($i = 0; $i < count($v);$i++)
			    {
			       $v_array = explode(',', $v);

			    }



			    $o1= array();
			     //pass array for output
			    foreach ($v_array as $item)
			    {


			      $o1[] = get_course_code($item);

			    }

			    $o = implode(', ',$o1);





		    return $o;


}


//function remark per semester for PRENCE
function get_student_remark1_per_semester_prence($student, $session, $semester)
{



			$result = mysqli_query(dbc(),"SELECT remark1 FROM students_results_prence WHERE session_id = $session  AND student_id = $student AND semester = $semester");
			$row = mysqli_fetch_assoc($result);


 			$v = $row['remark1'];



			 	for ($i = 0; $i < count($v);$i++)
			    {
			       $v_array = explode(',', $v);

			    }



			    $o1= array();
			     //pass array for output
			    foreach ($v_array as $item)
			    {


			      $o1[] = get_course_code($item);

			    }

			    $o = implode(', ',$o1);





		    return $o;


}//for PRENCE






//get student course score froms tudent courses table
function get_student_tp_score($student, $tp_course_id, $ses)
{
	$result = mysqli_query(dbc(),"SELECT total_score FROM students_courses_nce WHERE course_id = $tp_course_id  AND student_id = $student AND session_id = '$ses'");
	$row = mysqli_fetch_assoc($result);
	$value = $row['total_score'];


return $value;
}


//get student TP  course score froms tudent courses without session
function get_student_tp_score2($student, $tp_course_id)
{
	$result = mysqli_query(dbc(),"SELECT total_score FROM students_courses_nce WHERE course_id = $tp_course_id  AND student_id = $student");
	$row = mysqli_fetch_assoc($result);
	$value = $row['total_score'];


return $value;
}



?>
