<?php
@session_start();
##################################################################
#  This is the basic that can be called  within the web application
#  Include this after the configuration file on every page
#  File name: functions.php
##################################################################

//Call the configuration file
include('../scripts/configuration.php');

// This function is introduced to be able query the database using mysqli. i.e, it returning the mysqli connection function
// function $dbc
// {
//     return dbc();
// }

	function get_user_id()
			{
				$user_id = $_SESSION['applicant_id'];
				return $user_id;
	}

//instantiating Config Class
function dbc()
{
	$config = new Config();
	return $config->connect();
}


//not functional
//Get Current User's ID fro sessionif i need t use this in startic manner
	//function get_user_id()
	//{
	//	$pn = $_COOKIE['listdntttv'];
	//	return $pn;
//	}





//Function to fetch User Last IP
	function get_last_login_ip($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT * FROM applicants WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$last_login_ip = $row['last_login_ip'];

	return $last_login_ip;
	}

//Function to fetch applicants Lat login date
	function get_last_login($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT DATE_FORMAT(last_login, '%b %e,%y  %l:%i:%p') as user_lastlogindate  FROM applicants WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$last_login = $row['user_lastlogindate'];

	return $last_login;
	}

//Functions to fetch user's Full name
	function get_user_fullname($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT CONCAT_WS(' ', first_name, middle_name, last_name) AS name FROM applicants WHERE applicant_id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$user_fullname = $row['name'];


	return $user_fullname;
	}

//Function to fetch user name
	function get_user_username($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT * FROM applicants WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$username = $row['username'];


	return $username;
	}




//Function to fetch email
	function get_user_email($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT email FROM applicants WHERE applicant_id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$email = $row['email'];

	return $email;
	}



	//Function to fetch phone number
	function get_user_phone_no($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT phone_no FROM applicants WHERE applicant_id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$ph = $row['phone_no'];

	return $ph;
	}


	//function dat get user security id  by id
	function get_security_id($user_id)
	{
		$q = "SELECT security_id FROM applicants WHERE id = '$user_id' ";
		$r = mysqli_query(dbc(),$q);
		$row = mysqli_fetch_assoc($r);

		return $row['security_id'];


	}


	//function dat get user address
	function get_user_address($user_id)
	{
		$q = "SELECT address FROM applicants WHERE applicant_id = '$user_id'";
		$r = mysqli_query(dbc(),$q);
		$row = mysqli_fetch_assoc($r);

		return $row['address'];


	}




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

	return $row['image'];


	}


	//function dat get user application number
	function get_user_application_number($user_id)
	{
	$q = "SELECT application_number FROM applicants WHERE applicant_id = '$user_id'";
	$r = mysqli_query(dbc(),$q);
	$row = mysqli_fetch_assoc($r);

	return $row['application_number']."";


	}





	//Function to fetch role name
	function get_role_title($role_id)
	{
		$result = mysqli_query(dbc(),"SELECT * FROM roles WHERE applicant_id = '$role_id'");
		$row = mysqli_fetch_assoc($result);
		$role_title = $row['role_title'];

	return $role_title;
	}

	//Functions to fetch user's first name
	function get_user_first_name($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT first_name FROM applicants WHERE  applicant_id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$first_name = $row['first_name'];


	return $first_name;
	}

	//Functions to fetch user's other names
	function get_user_last_name($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT last_name FROM applicants WHERE applicant_id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$on = $row['last_name'];


	return $on;
	}

	//Functions to fetch user's other names
	function get_user_middle_name($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT middle_name FROM applicants WHERE applicant_id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$on = $row['middle_name'];


	return $on;
	}

	//Functions to fetch user's marital status
	function get_user_ms($user_applicant_id)
	{
		$result = mysqli_query(dbc(),"SELECT marital_status FROM applicants WHERE applicant_id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$ms = $row['marital_status'];


	return $ms;
	}


		//Functions to fetch user's gender
	function get_user_gender($user_applicant_id)
	{
		$result = mysqli_query(dbc(),"SELECT gender FROM applicants WHERE applicant_id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$gd = $row['gender'];


	return $gd;
	}



		//Functions to fetch user's religion
	function get_user_religion($user_applicant_id)
	{
		$result = mysqli_query(dbc(),"SELECT religion FROM applicants WHERE applicant_id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$religion = $row['religion'];


	return $religion;
	}



		//Functions to fetch user's place of birth
	function get_user_pob($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT place_of_birth FROM applicants WHERE applicant_id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['place_of_birth'];


	return $v;
	}


		//Functions to fetch user's working experience
	function get_user_working_experience($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT working_experience FROM applicants WHERE applicant_id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['working_experience'];


	return $v;
	}





	//function fetch user day
	function get_user_day($applicant_id)
	{
		$result = mysqli_query(dbc(),"SELECT day FROM applicants WHERE applicant_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$day = $row['day'];

		return $day;
	}




	//function fetch user month
	function get_user_month($id)
	{
		$result = mysqli_query(dbc(),"SELECT month FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$month = $row['month'];

		return $month;
	}



	//function fetch user year
	function get_user_year($id)
	{
		$result = mysqli_query(dbc(),"SELECT year FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$year = $row['year'];

		return $year;
	}


	//function fetch user nationality
	function get_user_nationality($id)
	{
		$result = mysqli_query(dbc(),"SELECT nationality FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$n = $row['nationality'];

		return $n;
	}



	//function fetch user country
	function get_user_country_id($id)
	{
		$result = mysqli_query(dbc(),"SELECT country_id FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$country_id = $row['country_id'];

		return $country_id;
	}


	//function fetch user state id
	function get_user_state_id($id)
	{
		$result = mysqli_query(dbc(),"SELECT state_id FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$sid = $row['state_id'];

		return $sid;
	}

	//function fetch user lga id
	function get_user_lga_id($id)
	{
		$result = mysqli_query(dbc(),"SELECT lga_id FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$lid = $row['lga_id'];

		return $lid;
	}




	//function get user permanent address

	function get_user_permanent_address($id)
	{
		$result = mysqli_query(dbc(),"SELECT permanent_address FROM applicants WHERE applicant_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['permanent_address'];


		return $v;
	}




	//function get user guardian_name
	function get_user_guardian_name($id)
	{
		$result = mysqli_query(dbc(),"SELECT guardian_name FROM applicants WHERE applicant_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['guardian_name'];


		return $v;
	}




	//function get user guardian_relationship
	function get_user_guardian_relationship($id)
	{
		$result = mysqli_query(dbc(),"SELECT guardian_relationship FROM applicants WHERE applicant_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['guardian_relationship'];


		return $v;
	}


		//function get guardian_tel
	function get_user_guardian_tel($id)
	{
		$result = mysqli_query(dbc(),"SELECT guardian_tel FROM applicants WHERE applicant_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['guardian_tel'];


		return $v;
	}

	//function get guardian_email
	function get_user_guardian_email($id)
	{
	$result = mysqli_query(dbc(),"SELECT guardian_email FROM applicants WHERE applicant_id = '$id'");
	$row = mysqli_fetch_assoc($result);
	$v = $row['guardian_email'];


	return $v;
	}

	//function get guardian_address
	function get_user_guardian_address($id)
	{
		$result = mysqli_query(dbc(),"SELECT guardian_address FROM applicants WHERE applicant_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['guardian_address'];


		return $v;
	}



	//function get user sponsorhip type
	function get_user_sponsorship_type($id)
	{
		$result = mysqli_query(dbc(),"SELECT sponsorship_type FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['sponsorship_type'];


		return $v;
	}


	//function get user sponsorhip type
	function get_user_sponsorhip_name($id)
	{
		$result = mysqli_query(dbc(),"SELECT sponsorship_name FROM applicants WHERE applicant_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['sponsorship_name'];


		return $v;
	}


	//function get user sponsorhip address
	function get_user_sponsorship_address($id)
	{
		$result = mysqli_query(dbc(),"SELECT sponsorship_address FROM applicants WHERE applicant_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['sponsorship_address'];


		return $v;
	}



//function fetch user programme type
	function get_user_programme_type($id)
	{
		$result = mysqli_query(dbc(),"SELECT programme_type_applied_for FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['programme_type_applied_for'];


		return $v;
	}

	//function fetch user programme type applied for
	function get_user_programme_type_applied_for($id)
	{
		$result = mysqli_query(dbc(),"SELECT school_applied_for FROM applicants WHERE applicant_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['school_applied_for'];


		return $v;
	}

//function fetch user programme_applied_for
	function get_user_programme_applied_for($id)
	{
		$result = mysqli_query(dbc(),"SELECT programme_applied_for FROM applicants WHERE applicant_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['programme_applied_for'];


		return $v;
	}


//function fetch user department applied for
	function get_user_department_applied_for($id)
	{
		$result = mysqli_query(dbc(),"SELECT department_applied_for FROM applicants WHERE applicant_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['department_applied_for'];


		return $v;
	}

	//function fetch user programme type
	function get_user_programme_type_admitted_to($id)
	{
		$result = mysqli_query(dbc(),"SELECT type_id FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['type_id'];


		return $v;
	}


	//function fetch user department_admitted_to
	function get_user_department_admitted_to($id)
	{
		$result = mysqli_query(dbc(),"SELECT department_id FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['department_id'];


		return $v;
	}


	//function fetch user programme_admitted_to
	function get_user_programme_admitted_to($id)
	{
		$result = mysqli_query(dbc(),"SELECT programme_id FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['programme_id'];


		return $v;
	}




	//function fetch user entry_year
	function get_user_entry_year($id)
	{
		$result = mysqli_query(dbc(),"SELECT entry_year FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['entry_year'];


		return $v;
	}


	//function fetch user level per programme
	function get_user_level_per_programme($id)
	{
		$result = mysqli_query(dbc(),"SELECT level  FROM programmes WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['level'];


		return $v;
	}



	//function fetch user health status
	function get_user_h_status($id)
	{
		$result = mysqli_query(dbc(),"SELECT H_status FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['H_status'];

		return $v;
	}



	//function fetch user disability
	function get_user_disability($id)
	{
		$result = mysqli_query(dbc(),"SELECT disability FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['disability'];

		return $v;
	}

	//function fetch user blood group
	function get_user_bg($id)
	{
		$result = mysqli_query(dbc(),"SELECT blood_type FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['blood_type'];


		return $v;
	}





	//function fetch user medication
	function get_user_medication($id)
	{
		$result = mysqli_query(dbc(),"SELECT medi FROM applicants WHERE applicant_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['medi'];

		return $v;
	}




	//function fetch user credential
	function get_user_credential($id)
	{
		$result = mysqli_query(dbc(),"SELECT pdf_file FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['pdf_file'];

		return $v;
	}





	##############################################
		//Educational History functions start//
    ##############################################

	//Function to fetch primary school name
	function get_user_school($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT instutition FROM applicants_alevel WHERE applicant_id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['instutition'];

		return $v;
	}

	//course studied in the school
	function get_user_start($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT start_year FROM applicants_alevel WHERE applicant_id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$s1 = $row['start_year'];

	return $s1;
	}

	//course studied in the school
	function get_user_end($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT end_year FROM applicants_alevel WHERE applicant_id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$s1 = $row['end_year'];

	return $s1;
	}






	//Functions to fetch user's fscl cert
	function get_user_course($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT course_studied FROM applicants_alevel WHERE applicant_id = '$user_id' ");
		$row = mysqli_fetch_assoc($result);
		$c1 = $row['course_studied'];


	return $c1;
	}

	//Functions to fetch user's fscl cert
	function get_user_qualification($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT course_studied FROM applicants_alevel WHERE applicant_id = '$user_id' ");
		$row = mysqli_fetch_assoc($result);
		$c1 = $row['course_studied'];


	return $c1;
	}


	//Functions to fetch user's result 1
	function get_user_result1($user_id,$nce_type)
	{
		$result = mysqli_query(dbc(),"SELECT result FROM  applicants_institutions WHERE user_id = '$user_id' AND nce_type = '$nce_type'");
		$row = mysqli_fetch_assoc($result);
		$c1 = $row['result'];


	return $c1;
	}
	//Functions to fetch user's result 1
	function get_user_nce_subject1($user_id,$nce_type)
	{
		$result = mysqli_query(dbc(),"SELECT nce_subject_1 FROM  applicants_institutions WHERE user_id = '$user_id' AND nce_type = '$nce_type'");
		$row = mysqli_fetch_assoc($result);
		$c1 = $row['nce_subject_1'];


	return $c1;
	}
	//Functions to fetch user's result 1
	function get_user_nce_subject2($user_id,$nce_type)
	{
		$result = mysqli_query(dbc(),"SELECT nce_subject_2 FROM  applicants_institutions WHERE user_id = '$user_id' AND nce_type = '$nce_type'");
		$row = mysqli_fetch_assoc($result);
		$c1 = $row['nce_subject_2'];


	return $c1;
	}
	//Functions to fetch user's result 1
	function get_user_nce_subject3($user_id,$nce_type)
	{
		$result = mysqli_query(dbc(),"SELECT nce_subject_3 FROM  applicants_institutions WHERE user_id = '$user_id' AND nce_type = '$nce_type'");
		$row = mysqli_fetch_assoc($result);
		$c1 = $row['nce_subject_3'];


	return $c1;
	}
	//Functions to fetch user's result 1
	function get_user_nce_subject4($user_id,$nce_type)
	{
		$result = mysqli_query(dbc(),"SELECT nce_subject_4 FROM  applicants_institutions WHERE user_id = '$user_id' AND nce_type = '$nce_type'");
		$row = mysqli_fetch_assoc($result);
		$c1 = $row['nce_subject_4'];


	return $c1;
	}
	//Functions to fetch user's result 1
	function get_user_nce_grade1($user_id,$nce_type)
	{
		$result = mysqli_query(dbc(),"SELECT nce_grade_1 FROM  applicants_institutions WHERE user_id = '$user_id' AND nce_type = '$nce_type'");
		$row = mysqli_fetch_assoc($result);
		$c1 = $row['nce_grade_1'];


	return $c1;
	}
	//Functions to fetch user's result 1
	function get_user_nce_grade2($user_id,$nce_type)
	{
		$result = mysqli_query(dbc(),"SELECT nce_grade_2 FROM  applicants_institutions WHERE user_id = '$user_id' AND nce_type = '$nce_type'");
		$row = mysqli_fetch_assoc($result);
		$c1 = $row['nce_grade_2'];


	return $c1;
	}
	//Functions to fetch user's result 1
	function get_user_nce_grade3($user_id,$nce_type)
	{
		$result = mysqli_query(dbc(),"SELECT nce_grade_3 FROM  applicants_institutions WHERE user_id = '$user_id' AND nce_type = '$nce_type'");
		$row = mysqli_fetch_assoc($result);
		$c1 = $row['nce_grade_3'];


	return $c1;
	}
	//Functions to fetch user's result 1
	function get_user_nce_grade4($user_id,$nce_type)
	{
		$result = mysqli_query(dbc(),"SELECT nce_grade_4 FROM  applicants_institutions WHERE user_id = '$user_id' AND nce_type = '$nce_type'");
		$row = mysqli_fetch_assoc($result);
		$c1 = $row['nce_grade_4'];


	return $c1;
	}

	//Function to fetch secondary school name
	function get_user_school2($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT school2 FROM applicants WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$s2 = $row['school2'];

	return $s2;
	}


	//course studied in the school
	function get_user_course2($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT course_of_study2 FROM applicants_institutions WHERE user_id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$s1 = $row['course_of_study2'];

	return $s1;
	}

	//function fetch user secondary Start year
	function get_user_start_year2($id)
	{
		$result = mysqli_query(dbc(),"SELECT start_year2 FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$sy2 = $row['start_year2'];
		return $sy2;
	}
	//function fetch user secondary end year
	function get_user_end_year2($id)
	{
		$result = mysqli_query(dbc(),"SELECT end_year2 FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$ey2 = $row['end_year2'];
		return $ey2;
	}


	//Functions to fetch user's sec cert
	function get_user_cert2($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT cert2 FROM applicants WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$c2 = $row['cert2'];


	return $c2;
	}



	//Functions to fetch user's result 2
	function get_user_result2($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT result2 FROM applicants WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$c1 = $row['result2'];


	return $c1;
	}


	//Function to fetch school3 name
	function get_user_school3($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT school3 FROM applicants WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$s3 = $row['school3'];

	return $s3;
	}



	//course studied in the school
	function get_user_course3($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT course_of_study3 FROM applicants_institutions WHERE user_id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$s1 = $row['course_of_study3'];

	return $s1;
	}

	//function fetch user school3 Start year
	function get_user_start_year3($id)
	{
		$result = mysqli_query(dbc(),"SELECT start_year3 FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$sy3 = $row['start_year3'];
		return $sy3;
	}
	//function fetch user school3 end year
	function get_user_end_year3($id)
	{
		$result = mysqli_query(dbc(),"SELECT end_year3 FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$ey3 = $row['end_year3'];
		return $ey3;
	}

	//Functions to fetch user school3 cert
	function get_user_cert3($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT cert3 FROM applicants WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$c3 = $row['cert3'];


	return $c3;
	}

	//Functions to fetch user school3 result
	function get_user_result3($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT result3 FROM applicants WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$r3 = $row['result3'];


	return $r3;
	}


	//function select school3 college cert type
function select_cert3($col)
{

		if ($col == '1')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1" selected > ND</option>';
			$output .= '<option value="2"  > NCE</option>';
			$output .= '<option value="3" > IJMB</option>';
			$output .= '<option value="4"  > HND</option>';
			$output .= '<option value="5"  > BSC</option>';
			$output .= '<option value="6"  > MSC</option>';
			$output .= '<option value="7" > MPHIL</option>';
			$output .= '<option value="8" > MTECH</option>';
			$output .= '<option value="9"> Others</option>';


		}
		else if ($col == '2')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"  > ND</option>';
			$output .= '<option value="2" selected > NCE</option>';
			$output .= '<option value="3" > IJMB</option>';
			$output .= '<option value="4"  > HND</option>';
			$output .= '<option value="5"  > BSC</option>';
			$output .= '<option value="6"  > MSC</option>';
			$output .= '<option value="7" > MPHIL</option>';
			$output .= '<option value="8" > MTECH</option>';
			$output .= '<option value="9"> Others</option>';


		}
		else if ($col == '3')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"  > ND</option>';
			$output .= '<option value="2"  > NCE</option>';
			$output .= '<option value="3" selected> IJMB</option>';
			$output .= '<option value="4"  > HND</option>';
			$output .= '<option value="5"  > BSC</option>';
			$output .= '<option value="6"  > MSC</option>';
			$output .= '<option value="7" > MPHIL</option>';
			$output .= '<option value="8" > MTECH</option>';
			$output .= '<option value="9"> Others</option>';



		}
		else if ($col == '4')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"  > ND</option>';
			$output .= '<option value="2"  > NCE</option>';
			$output .= '<option value="3" > IJMB</option>';
			$output .= '<option value="4"  selected> HND</option>';
			$output .= '<option value="5"  > BSC</option>';
			$output .= '<option value="6"  > MSC</option>';
			$output .= '<option value="7" > MPHIL</option>';
			$output .= '<option value="8" > MTECH</option>';
			$output .= '<option value="9"> Others</option>';
		}
		else if ($col == '5')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"  > ND</option>';
			$output .= '<option value="2"  > NCE</option>';
			$output .= '<option value="3" > IJMB</option>';
			$output .= '<option value="4"  > HND</option>';
			$output .= '<option value="5"  selected> BSC</option>';
			$output .= '<option value="6"  > MSC</option>';
			$output .= '<option value="7" > MPHIL</option>';
			$output .= '<option value="8" > MTECH</option>';
			$output .= '<option value="9"> Others</option>';
		}
		else if ($col == '6')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"  > ND</option>';
			$output .= '<option value="2"  > NCE</option>';
			$output .= '<option value="3" > IJMB</option>';
			$output .= '<option value="4"  > HND</option>';
			$output .= '<option value="5"  > BSC</option>';
			$output .= '<option value="6"  selected> MSC</option>';
			$output .= '<option value="7" > MPHIL</option>';
			$output .= '<option value="8" > MTECH</option>';
			$output .= '<option value="9"> Others</option>';
		}
		else if ($col == '7')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"  > ND</option>';
			$output .= '<option value="2"  > NCE</option>';
			$output .= '<option value="3" > IJMB</option>';
			$output .= '<option value="4"  > HND</option>';
			$output .= '<option value="5"  > BSC</option>';
			$output .= '<option value="6"  > MSC</option>';
			$output .= '<option value="7" selected> MPHIL</option>';
			$output .= '<option value="8" > MTECH</option>';
			$output .= '<option value="9"> Others</option>';
		}
		else if ($col == '8')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"  > ND</option>';
			$output .= '<option value="2"  > NCE</option>';
			$output .= '<option value="3" > IJMB</option>';
			$output .= '<option value="4"  > HND</option>';
			$output .= '<option value="5"  > BSC</option>';
			$output .= '<option value="6"  > MSC</option>';
			$output .= '<option value="7" > MPHIL</option>';
			$output .= '<option value="8" selected> MTECH</option>';
			$output .= '<option value="9"> Others</option>';
		}
		else if ($col == '9')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"  > ND</option>';
			$output .= '<option value="2"  > NCE</option>';
			$output .= '<option value="3" > IJMB</option>';
			$output .= '<option value="4"  > HND</option>';
			$output .= '<option value="5"  > BSC</option>';
			$output .= '<option value="6"  > MSC</option>';
			$output .= '<option value="7" > MPHIL</option>';
			$output .= '<option value="8" > MTECH</option>';
			$output .= '<option value="9" selected> Others</option>';
		}
		else
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"  > ND</option>';
			$output .= '<option value="2"  > NCE</option>';
			$output .= '<option value="3" > IJMB</option>';
			$output .= '<option value="4"  > HND</option>';
			$output .= '<option value="5"  > BSC</option>';
			$output .= '<option value="6"  > MSC</option>';
			$output .= '<option value="7" > MPHIL</option>';
			$output .= '<option value="8" > MTECH</option>';
			$output .= '<option value="9"> Others</option>';


		}
	return $output;

}
//end of select college cert


//function cert 3
function show_cert3($r)
{

		if ($r == '1')
		{

			$output .= 'ND';


		}
		else if ($r == '2')
		{

			$output .= 'NCE';



		}
		else if ($r == '3')
		{

			$output .= 'HND';



		}
		else if ($r == '4')
		{

			$output .= 'BSC';



		}
		else if ($r == '5')
		{


			$output .= 'MSC';



		}
		else if ($r == '6')
		{


			$output .= 'MPHIL';

		}
		else if ($r == '7')
		{


			$output .= 'MTECH';


		}
		else if ($r == '8')
		{


			$output .= 'Others';


		}
		else
		{


			$output .= 'NIL';
		}

	return $output;

}
//end of show cert 3

//function select class of degree
function select_class_degree($cd)
{

		if ($cd == '1')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1" selected > First Class</option>';
			$output .= '<option value="2"> Distinction</option>';
			$output .= '<option value="3"  > Second Class Upper</option>';
			$output .= '<option value="4"  > Upper Division</option>';
			$output .= '<option value="5"  > Second Class Lower</option>';
			$output .= '<option value="6"  > Lower Division</option>';
			$output .= '<option value="7"  > Third Class</option>';
			$output .= '<option value="8"  > Pass</option>';

		}

		else if ($cd == '2')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"  > First Class</option>';
			$output .= '<option value="2" selected> Distinction</option>';
			$output .= '<option value="3"  > Second Class Upper</option>';
			$output .= '<option value="4"  > Upper Division</option>';
			$output .= '<option value="5"  > Second Class Lower</option>';
			$output .= '<option value="6"  > Lower Division</option>';
			$output .= '<option value="7"  > Third Class</option>';
			$output .= '<option value="8"  > Pass</option>';

		}

		else if ($cd == '3')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"> First Class</option>';
			$output .= '<option value="2" > Distinction</option>';
			$output .= '<option value="3" selected  > Second Class Upper</option>';
			$output .= '<option value="4"  > Upper Division</option>';
			$output .= '<option value="5"  > Second Class Lower</option>';
			$output .= '<option value="6"  > Lower Division</option>';
			$output .= '<option value="7"  > Third Class</option>';
			$output .= '<option value="8"  > Pass</option>';

		}

		else if ($cd == '4')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"> First Class</option>';
			$output .= '<option value="2" > Distinction</option>';
			$output .= '<option value="3"   > Second Class Upper</option>';
			$output .= '<option value="4" selected > Upper Division</option>';
			$output .= '<option value="5"  > Second Class Lower</option>';
			$output .= '<option value="6"  > Lower Division</option>';
			$output .= '<option value="7"  > Third Class</option>';
			$output .= '<option value="8"  > Pass</option>';

		}

		else if ($cd == '5')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"> First Class</option>';
			$output .= '<option value="2" > Distinction</option>';
			$output .= '<option value="3"   > Second Class Upper</option>';
			$output .= '<option value="4" > Upper Division</option>';
			$output .= '<option value="5" selected > Second Class Lower</option>';
			$output .= '<option value="6"  > Lower Division</option>';
			$output .= '<option value="7"  > Third Class</option>';
			$output .= '<option value="8"  > Pass</option>';

		}

		else if ($cd == '6')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"> First Class</option>';
			$output .= '<option value="2" > Distinction</option>';
			$output .= '<option value="3"   > Second Class Upper</option>';
			$output .= '<option value="4"  > Upper Division</option>';
			$output .= '<option value="5"  > Second Class Lower</option>';
			$output .= '<option value="6" selected > Lower Division</option>';
			$output .= '<option value="7"  > Third Class</option>';
			$output .= '<option value="8"  > Pass</option>';

		}

		else if ($cd == '7')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"> First Class</option>';
			$output .= '<option value="2" > Distinction</option>';
			$output .= '<option value="3"   > Second Class Upper</option>';
			$output .= '<option value="4"  > Upper Division</option>';
			$output .= '<option value="5"  > Second Class Lower</option>';
			$output .= '<option value="6"  > Lower Division</option>';
			$output .= '<option value="7" selected > Third Class</option>';
			$output .= '<option value="8"  > Pass</option>';

		}

		else if ($cd == '8')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"> First Class</option>';
			$output .= '<option value="2" > Distinction</option>';
			$output .= '<option value="3"   > Second Class Upper</option>';
			$output .= '<option value="4"  > Upper Division</option>';
			$output .= '<option value="5"  > Second Class Lower</option>';
			$output .= '<option value="6"  > Lower Division</option>';
			$output .= '<option value="7"  > Third Class</option>';
			$output .= '<option value="8" selected > Pass</option>';

		}



		else
		{
			$output = '<option value="0" selected> -- Please Select --</option>';
			$output .= '<option value="1"> First Class</option>';
			$output .= '<option value="2" > Distinction</option>';
			$output .= '<option value="3"   > Second Class Upper</option>';
			$output .= '<option value="4"  > Upper Division</option>';
			$output .= '<option value="5"  > Second Class Lower</option>';
			$output .= '<option value="6"  > Lower Division</option>';
			$output .= '<option value="7"  > Third Class</option>';
			$output .= '<option value="8"  > Pass</option>';

		}
	return $output;

}
//end of select class of degree


//Functions to fetch user's fscl cert
//Functions to fetch user's fscl cert
function get_user_cert1($user_id,$nce_type)
{
	$result = mysqli_query(dbc(),"SELECT cert FROM applicants_institutions WHERE user_id = '$user_id' AND nce_type = '$nce_type'");
	$row = mysqli_fetch_assoc($result);
	$c1 = $row['cert'];


return $c1;
}

	//Function to fetch primary school name
		function get_user_school1($user_id)
		{
			$result = mysqli_query(dbc(),"SELECT instutition FROM applicants_alevel WHERE applicant_id = '$user_id'");
			$row = mysqli_fetch_assoc($result);
			$s1 = $row['instutition'];

		return $s1;
		}

		function get_user_start_year1($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT start_year FROM applicants_alevel WHERE applicant_id = '$user_id' ");
		$row = mysqli_fetch_assoc($result);
		$sy1 = $row['start_year'];
		return $sy1;
	}

	//function fetch user FSCL end year
		function get_user_end_year1($user_id)
		{
			$result = mysqli_query(dbc(),"SELECT end_year FROM applicants_alevel WHERE applicant_id = '$user_id' ");
			$row = mysqli_fetch_assoc($result);
			$ey1 = $row['end_year'];
			return $ey1;
		}


function show_class_cert($r)
{

		if ($r == '1')
		{

			$output .= 'First Class';


		}
		else if ($r == '2')
		{

			$output .= 'Distinction';



		}
		else if ($r == '3')
		{

			$output .= 'Second Class Upper';



		}
		else if ($r == '4')
		{

			$output .= 'Upper Division';



		}
		else if ($r == '5')
		{


			$output .= 'Second Class Lower';



		}
		else if ($r == '6')
		{


			$output .= 'Lower Division';

		}
		else if ($r == '7')
		{


			$output .= 'Third Class';


		}
		else if ($r == '8')
		{


			$output .= 'Pass';


		}
		else
		{


			$output .= 'NIL';
		}

	return $output;

}
//end of show class of cert

    ##############################################
		//Educational History functions end//
    ##############################################






//function select marital status
function select_marital_status($st)
{

		if ($st == 'single')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="single" selected > Single</option>';
			$output .= '<option value="married" > Married</option>';
			$output .= '<option value="divorced" >Divorced</option>';
			$output .= '<option value="widowed" >Widowed</option>';


		}
		else if ($st == 'married')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="single"  > Single</option>';
			$output .= '<option value="married" selected> Married</option>';
			$output .= '<option value="divorced" >Divorced</option>';
			$output .= '<option value="widowed" >Widowed</option>';


		}
		else if ($st == 'divorced')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="single"  > Single</option>';
			$output .= '<option value="married" > Married</option>';
			$output .= '<option value="divorced" selected >Divorced</option>';
			$output .= '<option value="widowed" >Widowed</option>';


		}
		else if ($st == 'widowed')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="single"  > Single</option>';
			$output .= '<option value="married" > Married</option>';
			$output .= '<option value="divorced"  >Divorced</option>';
			$output .= '<option value="widowed" selected >Widowed</option>';


		}
		else
		{

			$output = '<option value="0" selected> -- Please Select --</option>';
			$output .= '<option value="single"  > Single</option>';
			$output .= '<option value="married" > Married</option>';
			$output .= '<option value="divorced" >Divorced</option>';
			$output .= '<option value="widowed" >Widowed</option>';

		}

	return $output;

}
//end of select marrital status



//function select gender
function select_gender($gd)
{

		if ($gd == 'M')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="M" selected > Male</option>';
			$output .= '<option value="F" > Female</option>';
			$output .= '<option value="F" > Others</option>';


		}
		else if ($gd == 'F')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="M"> Male</option>';
			$output .= '<option value="F" selected > Female</option>';
			$output .= '<option value="F" > Others</option>';


		}
		else
		{

			$output = '<option value="0"  selected  > -- Please Select --</option>';
			$output .= '<option value="M"> Male</option>';
			$output .= '<option value="F"> Female</option>';
			$output .= '<option value="F" > Others</option>';
		}

	return $output;

}
//end of select gender








//function select religion
function select_religion($r)
{

		if ($r == '1')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1" selected > Islam</option>';
			$output .= '<option value="2" > Christianity</option>';
			$output .= '<option value="3" > Traditional</option>';
			$output .= '<option value="4" > Others</option>';


		}
		else if ($r == '2')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"  > Islam</option>';
			$output .= '<option value="2" selected > Christianity</option>';
			$output .= '<option value="3" > Traditional</option>';
			$output .= '<option value="4" > Others</option>';


		}
		else if ($r == '3')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"  > Islam</option>';
			$output .= '<option value="2" > Christianity</option>';
			$output .= '<option value="3" selected  > Traditional</option>';
			$output .= '<option value="4" > Others</option>';


		}
		else if ($r == '4')
		{
			$output = '<option value="0"> -- Please Select --</option>';
			$output .= '<option value="1"> Islam</option>';
			$output .= '<option value="2" > Christianity</option>';
			$output .= '<option value="3" > Traditional</option>';
			$output .= '<option value="4"  selected > Others</option>';


		}
		else
		{

			$output = '<option value="0"  selected> -- Please Select --</option>';
			$output .= '<option value="1"> Islam</option>';
			$output .= '<option value="2" > Christianity</option>';
			$output .= '<option value="3" > Traditional</option>';
			$output .= '<option value="4"  > Others</option>';
		}

	return $output;

}
//end of select religion


//function show religion
function show_religion($r)
{

		if ($r == '1')
		{

			$output .= 'Islam';

		}
		else if ($r == '2')
		{

			$output .= 'Christianity';


		}
		else if ($r == '3')
		{

			$output .= 'Traditional';

		}
		else if ($r == '4')
		{

			$output .= 'Others';


		}
		else
		{


			$output .= 'NIL';
		}

	return $output;

}
//end of show religion











//function select nationality
function select_nationality($n)
{

		if ($n == 'Nigerian')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="Nigerian" selected > Nigerian</option>';
			$output .= '<option value="Others" > NON Nigerian</option>';


		}
		else if ($n == 'Others')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="Nigerian" > Nigerian</option>';
			$output .= '<option value="Others"  selected>  NON Nigerian</option>';


		}
		else
		{

			$output = '<option value="0"  selected > -- Please Select --</option>';
			$output .= '<option value="Nigerian"> Nigerian</option>';
			$output .= '<option value="Others" > Others</option>';
		}

	return $output;

}

function show_nationality($n)
{

		if ($n == 'Nigerian')
		{
			$output = 'Nigerian';



		}
		else if ($n == 'Others')
		{
			$output = 'NON Nigerian';


		}
		else
		{

			$output = 'NIL';
		}

	return $output;

}



//function select sponsorship type
function select_sponsorship_type($r)
{

		if ($r == '1')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1" selected > Private</option>';
			$output .= '<option value="2" > Self</option>';
			$output .= '<option value="3" > Governmental</option>';
			$output .= '<option value="4" > Others</option>';
			$output .= '<option value="5" > Nil</option>';


		}
		else if ($r == '2')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1" > Private</option>';
			$output .= '<option value="2" selected  > Self</option>';
			$output .= '<option value="3" > Governmental</option>';
			$output .= '<option value="4" > Others</option>';
			$output .= '<option value="5" > Nil</option>';



		}
		else if ($r == '3')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1" > Private</option>';
			$output .= '<option value="2"  > Self</option>';
			$output .= '<option value="3" selected  > Governmental</option>';
			$output .= '<option value="4" > Others</option>';
			$output .= '<option value="5" > Nil</option>';


		}
		else if ($r == '4')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1" > Private</option>';
			$output .= '<option value="2" > Self</option>';
			$output .= '<option value="3" > Governmental</option>';
			$output .= '<option value="4" selected > Others</option>';
			$output .= '<option value="5" > Nil</option>';



		}
		else if ($r == '5')
		{
			$output = '<option value="0"  > -- Please Select --</option>';
			$output .= '<option value="1" > Private</option>';
			$output .= '<option value="2" > Self</option>';
			$output .= '<option value="3" > Governmental</option>';
			$output .= '<option value="4" > Others</option>';
			$output .= '<option value="5" selected > Nil</option>';



		}
		else
		{

			$output = '<option value="0" selected  > -- Please Select --</option>';
			$output .= '<option value="1" > Private</option>';
			$output .= '<option value="2" > Self</option>';
			$output .= '<option value="3" > Governmental</option>';
			$output .= '<option value="4" > Others</option>';
			$output .= '<option value="5" > Nil</option>';
		}

	return $output;

}
//end of select sponsorship type

//function show sponsorship type
function show_sponsorship_type($r)
{

		if ($r == '1')
		{

			$output = 'Private';



		}
		else if ($r == '2')
		{

			$output = 'Self';


		}
		else if ($r == '3')
		{
			$output = 'overnmental';



		}
		else if ($r == '4')
		{
			$output = 'Others';


		}
		else if ($r == '5')
		{
			$output = 'Nil';



		}
		else
		{

			$output = 'Nil';
		}

	return $output;

}
//end of show sponsorship type



//function select programme_type
function select_programme_type($pt)
{

		if ($pt == '1')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1" selected > PART TIME DEGREE </option>';
			$output .= '<option value="2" > Postgraduate </option>';
			//$output .= '<option value="3" > Certificate </option>';



		}
		else if ($pt == '2')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"> PART TIME DEGREE </option>';
			$output .= '<option value="2" selected > Postgraduate </option>';
			//$output .= '<option value="3" > Certificate </option>';



		}
		//else if ($pt == '3')
		//{
			//$output = '<option value="0" > -- Please Select --</option>';
			//$output .= '<option value="1"> Advanced Diploma</option>';
			//$output .= '<option value="2"> Diploma </option>';
			//$output .= '<option value="3" selected  > Certificate </option>';



		//}
		else
		{

			$output = '<option value="0"  selected > -- Please Select --</option>';
			$output .= '<option value="1"> PART TIME DEGREE </option>';
			$output .= '<option value="2" > Postgraduate </option>';
			//$output .= '<option value="3" > Certificate </option>';

		}

	return $output;

}
//end of select programme_type


//function show programme_type
function show_programme_type($pt)
{

		if ($pt == '1')
		{
			$output = 'PART TIME DEGREE';

		}
		else if ($pt == '2')
		{
			$output = 'Postgraduate';

		}
		else if ($pt == '3')
		{
			$output = 'Certificate';

		}
		else
		{

			$output = 'NIL';

		}

	return $output;

}
//end of show programme_type



//function select study_mode
function select_study_mode($sm)
{

		if ($sm == '1')
		{
			$output = 	'<option value="1" selected >Full-Time</option>';
			$output .= '<option value="2"  >Part-Time</option>';
			$output .= '<option value="3"  >Others</option>';



		}
		else if ($sm == '2')
		{
			$output = 	'<option value="1" >Full-Time</option>';
			$output .= '<option value="2"  selected >Part-Time</option>';
			$output .= '<option value="3"  >Others</option>';



		}
		else if ($sm == '3')
		{

			$output = 	'<option value="1" >Full-Time</option>';
			$output .= '<option value="2" >Part-Time</option>';
			$output .= '<option value="3" selected >Others</option>';

		}

		else
		{

			$output = 	'<option value="1"  selected >Full-Time</option>';
			$output .= '<option value="2" >Part-Time</option>';
			$output .= '<option value="3" >Others</option>';

		}

	return $output;

}
//end of select study_mode





//function select H status
function select_h_status($n)
{

		if ($n == 'Normal')
		{
			$output = '<option value="0"> -- Please Select --</option>';
			$output .= '<option value="Normal" selected >Normal</option>';
			$output .= '<option value="Handicapped" >Handicapped</option>';
			$output .= '<option value="Others" >Others</option>';


		}
		else if ($n == 'Handicapped')
		{
			$output = '<option value="0"> -- Please Select --</option>';
			$output .= '<option value="Normal" >Normal</option>';
			$output .= '<option value="Handicapped" selected >Handicapped</option>';
			$output .= '<option value="Others" >Others</option>';


		}
		else if ($n == 'Others')
		{
			$output = '<option value="0"> -- Please Select --</option>';
			$output .= '<option value="Normal" >Normal</option>';
			$output .= '<option value="Handicapped" >Handicapped</option>';
			$output .= '<option value="Others" selected >Others</option>';


		}
		else
		{
			$output = '<option value="0" selected > -- Please Select --</option>';
			$output .= '<option value="Normal" >Normal</option>';
			$output .= '<option value="Handicapped" >Handicapped</option>';
			$output .= '<option value="Others" >Others</option>';


		}

	return $output;

}


//function select disability
function select_disability($n)
{

		if ($n == 'Blind')
		{
			$output = '<option value="0"> -- Please Select --</option>';
			$output .= '<option value="Blind" selected> Blind</option>';
			$output .= '<option value="Deaf">  Deaf</option>';
			$output .= '<option value="Dumb">  Dumb</option>';
			$output .= '<option value="Handicapped">  Handicapped</option>';
			$output .= '<option value="None"> None</option>';
			$output .= '<option value="Others"> Others</option>';

		}
		else if ($n == 'Deaf' )
		{

			$output = '<option value="0"> -- Please Select --</option>';
			$output .= '<option value="Blind"> Blind</option>';
			$output .= '<option value="Deaf"  selected>  Deaf</option>';
			$output .= '<option value="Dumb">  Dumb</option>';
			$output .= '<option value="Handicapped">  Handicapped</option>';
			$output .= '<option value="None"> None</option>';
			$output .= '<option value="Others"> Others</option>';

		}
		else if ($n == 'Dumb' )
		{

			$output = '<option value="0"> -- Please Select --</option>';
			$output .= '<option value="Blind"> Blind</option>';
			$output .= '<option value="Deaf"  >  Deaf</option>';
			$output .= '<option value="Dumb" selected>  Dumb</option>';
			$output .= '<option value="Handicapped">  Handicapped</option>';
			$output .= '<option value="None"> None</option>';
			$output .= '<option value="Others"> Others</option>';

		}
		else if ($n == 'Handicapped' )
		{

			$output = '<option value="0"> -- Please Select --</option>';
			$output .= '<option value="Blind"> Blind</option>';
			$output .= '<option value="Deaf"  >  Deaf</option>';
			$output .= '<option value="Dumb" >  Dumb</option>';
			$output .= '<option value="Handicapped" selected>  Handicapped</option>';
			$output .= '<option value="None"> None</option>';
			$output .= '<option value="Others"> Others</option>';

		}
		else if ($n == 'None' )
		{

			$output = '<option value="0"> -- Please Select --</option>';
			$output .= '<option value="Blind"> Blind</option>';
			$output .= '<option value="Deaf"  >  Deaf</option>';
			$output .= '<option value="Dumb" >  Dumb</option>';
			$output .= '<option value="Handicapped">  Handicapped</option>';
			$output .= '<option value="None"  selected> None</option>';
			$output .= '<option value="Others"> Others</option>';

		}
		else if ($n == 'Others' )
		{

			$output = '<option value="0"> -- Please Select --</option>';
			$output .= '<option value="Blind"> Blind</option>';
			$output .= '<option value="Deaf"  >  Deaf</option>';
			$output .= '<option value="Dumb" >  Dumb</option>';
			$output .= '<option value="Handicapped">  Handicapped</option>';
			$output .= '<option value="None" > None</option>';
			$output .= '<option value="Others"  selected> Others</option>';

		}
		else
		{
			$output = '<option value="0"  selected> -- Please Select --</option>';
			$output .= '<option value="Blind"> Blind</option>';
			$output .= '<option value="Deaf"  >  Deaf</option>';
			$output .= '<option value="Dumb" >  Dumb</option>';
			$output .= '<option value="Handicapped">  Handicapped</option>';
			$output .= '<option value="None" > None</option>';
			$output .= '<option value="Others" > Others</option>';
		}

	return $output;

}


//function select bg
function select_bg($n)
{

		if ($n == 'AB')
		{
			$output = '<option value="0"> -- Please Select --</option>';
			$output .= '<option value="AB" selected> AB</option>';
			$output .= '<option value="O">  O </option>';
			$output .= '<option value="O+"> O+</option>';
			$output .= '<option value="A+"> A+</option>';
			$output .= '<option value="B+"> B+</option>';
			//$output .= '<option value="O+"> O+</option>';


		}
		else if ($n == 'O' )
		{

			$output = '<option value="0"> -- Please Select --</option>';
			$output .= '<option value="AB" > AB</option>';
			$output .= '<option value="O" selected>  O </option>';
			$output .= '<option value="O+"> O+</option>';
			$output .= '<option value="A+"> A+</option>';
			$output .= '<option value="B+"> B+</option>';
			//$output .= '<option value="O+"> O+</option>';

		}
		else if ($n == 'A+' )
		{

			$output = '<option value="0"> -- Please Select --</option>';
			$output .= '<option value="AB" > AB</option>';
			$output .= '<option value="O" >  O </option>';
			$output .= '<option value="O+"> O+</option>';
			$output .= '<option value="A+" selected> A+</option>';
			$output .= '<option value="B+"> B+</option>';
			//$output .= '<option value="O+"> O+</option>';

		}
		else if ($n == 'B+' )
		{

			$output = '<option value="0"> -- Please Select --</option>';
			$output .= '<option value="AB" > AB</option>';
			$output .= '<option value="O" >  O </option>';
			$output .= '<option value="O+"> O+</option>';
			$output .= '<option value="A+" > A+</option>';
			$output .= '<option value="B+" selected> B+</option>';


		}else if ($n == 'O+' )
		{

			$output = '<option value="0"> -- Please Select --</option>';
			$output .= '<option value="AB" > AB</option>';
			$output .= '<option value="O" >  O </option>';
			$output .= '<option value="O+" selected> O+</option>';
			$output .= '<option value="A+" > A+</option>';
			$output .= '<option value="B+"> B+</option>';


		}
		else
		{
			$output = '<option value="0"  selected> -- Please Select --</option>';
			$output .= '<option value="AB" > AB</option>';
			$output .= '<option value="O" >  O </option>';
			$output .= '<option value="O+"> O+</option>';
			$output .= '<option value="A+" > A+</option>';
			$output .= '<option value="B+"> B+</option>';

		}

	return $output;

}
//end of blood group selection


//function select exam _type
function select_exam_type($st)
{


		if ($st == 'GRADE II TEACHERS CERT.')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option  selected > GRADE II TEACHERS CERT.</option>';
			$output .= '<option > NABTEB</option>';
			$output .= '<option  >NECO</option>';
			$output .= '<option  >WAEC</option>';


		}
		else if ($st == 'NABTEB')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option > GRADE II TEACHERS CERT.</option>';
			$output .= '<option  selected  > NABTEB</option>';
			$output .= '<option  >NECO</option>';
			$output .= '<option  >WAEC</option>';


		}
		else if ($st == 'NECO')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option > GRADE II TEACHERS CERT.</option>';
			$output .= '<option > NABTEB</option>';
			$output .= '<option selected >NECO</option>';
			$output .= '<option  >WAEC</option>';


		}
		else if ($st == 'WAEC')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option > GRADE II TEACHERS CERT.</option>';
			$output .= '<option > NABTEB</option>';
			$output .= '<option>NECO</option>';
			$output .= '<option  selected>WAEC</option>';


		}
		else
		{

			$output = '<option value="0" selected > -- Please Select --</option>';
			$output .= '<option > GRADE II TEACHERS CERT.</option>';
			$output .= '<option > NABTEB</option>';
			$output .= '<option>NECO</option>';
			$output .= '<option  >WAEC</option>';

		}

	return $output;

}
//end of select exam type



//function select subjects
function select_subjects($c)
{
	$r = mysqli_query(dbc(),"SELECT id, title  FROM o_level_subjects  ORDER BY title ");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			if($c == $row['id'])
			{
				$output = "<option value=\"$row[id]\" selected>";
				$output .=  $row['title'];
				$output .="</option>";

			}
			else
			{
				$output = "<option value=\"$row[id]\" >";
				$output .= $row['title'];
				$output .="</option>";

			}


			echo $output;
		}
	}
	else
	{

			$output = "<option>";
			$output .="Not added yet";
			$output .="</option>";

			echo $output;
	}
}
//end of select subjects


//function select exam month
function select_exam_month($hiq)
{

		if ($hiq == '1')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'  selected  >JUN/JUL</option>";
			$output .= '<option value="2"  >OCT/NOV</option>';
			$output .= '<option value="3"  >NOV/DEC</option>';
			$output .= '<option value="4"  >JUNE</option>';
			$output .= '<option value="5"  >JULY</option>';
			$output .= '<option value="6"  >OCTOBER</option>';
			$output .= '<option value="7"  >NOVEMBER</option>';
			$output .= '<option value="8"  >DECEMBER</option>';


		}
		else if ($hiq == '2')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1' >JUN/JUL</option>";
			$output .= '<option value="2"  selected  >OCT/NOV</option>';
			$output .= '<option value="3"  >NOV/DEC</option>';
			$output .= '<option value="4"  >JUNE</option>';
			$output .= '<option value="5"  >JULY</option>';
			$output .= '<option value="6"  >OCTOBER</option>';
			$output .= '<option value="7"  >NOVEMBER</option>';
			$output .= '<option value="8"  >DECEMBER</option>';

		}
		else if ($hiq == '3')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1' >JUN/JUL</option>";
			$output .= '<option value="2"  >OCT/NOV</option>';
			$output .= '<option value="3"  selected  >NOV/DEC</option>';
			$output .= '<option value="4"  >JUNE</option>';
			$output .= '<option value="5"  >JULY</option>';
			$output .= '<option value="6"  >OCTOBER</option>';
			$output .= '<option value="7"  >NOVEMBER</option>';
			$output .= '<option value="8"  >DECEMBER</option>';

		}
		else if ($hiq == '4')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1' >JUN/JUL</option>";
			$output .= '<option value="2"  >OCT/NOV</option>';
			$output .= '<option value="3"  >NOV/DEC</option>';
			$output .= '<option value="4" selected >JUNE</option>';
			$output .= '<option value="5"  >JULY</option>';
			$output .= '<option value="6"  >OCTOBER</option>';
			$output .= '<option value="7"  >NOVEMBER</option>';
			$output .= '<option value="8"  >DECEMBER</option>';

		}
		else if ($hiq == '5')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1' >JUN/JUL</option>";
			$output .= '<option value="2"  >OCT/NOV</option>';
			$output .= '<option value="3"  >NOV/DEC</option>';
			$output .= '<option value="4"  >JUNE</option>';
			$output .= '<option value="5" selected >JULY</option>';
			$output .= '<option value="6"  >OCTOBER</option>';
			$output .= '<option value="7"  >NOVEMBER</option>';
			$output .= '<option value="8"  >DECEMBER</option>';

		}
		else if ($hiq == '6')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1' >JUN/JUL</option>";
			$output .= '<option value="2"  >OCT/NOV</option>';
			$output .= '<option value="3"  >NOV/DEC</option>';
			$output .= '<option value="4"  >JUNE</option>';
			$output .= '<option value="5"  >JULY</option>';
			$output .= '<option value="6" selected >OCTOBER</option>';
			$output .= '<option value="7"  >NOVEMBER</option>';
			$output .= '<option value="8"  >DECEMBER</option>';

		}
		else if ($hiq == '7')
		{
		    $output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1' >JUN/JUL</option>";
			$output .= '<option value="2"  >OCT/NOV</option>';
			$output .= '<option value="3"  >NOV/DEC</option>';
			$output .= '<option value="4"  >JUNE</option>';
			$output .= '<option value="5" >JULY</option>';
			$output .= '<option value="6"  >OCTOBER</option>';
			$output .= '<option value="7"  selected >NOVEMBER</option>';
			$output .= '<option value="8"  >DECEMBER</option>';

		}
		else if ($hiq == '8')
		{
			 $output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1' >JUN/JUL</option>";
			$output .= '<option value="2"  >OCT/NOV</option>';
			$output .= '<option value="3"  >NOV/DEC</option>';
			$output .= '<option value="4"  >JUNE</option>';
			$output .= '<option value="5" >JULY</option>';
			$output .= '<option value="6"  >OCTOBER</option>';
			$output .= '<option value="7" >NOVEMBER</option>';
			$output .= '<option value="8"  selected  >DECEMBER</option>';

		}
		else
		{
			$output = 	'<option value="0"  selected > -- Please Select-- </option>';
			$output .=  "<option value='1' >JUN/JUL</option>";
			$output .= '<option value="2"  >OCT/NOV</option>';
			$output .= '<option value="3"  >NOV/DEC</option>';
			$output .= '<option value="4"  >JUNE</option>';
			$output .= '<option value="5" >JULY</option>';
			$output .= '<option value="6"  >OCTOBER</option>';
			$output .= '<option value="7" >NOVEMBER</option>';
			$output .= '<option value="8"  >DECEMBER</option>';


		}
	return $output;

}
//end of select exam month



//function select highest qualification
function select_subject_grade($hiq)
{

		if ($hiq == '1')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'  selected  >A1</option>";
			$output .= '<option value="2"  >B2</option>';
			$output .= '<option value="3"  >B3</option>';
			$output .= '<option value="4"  >C4</option>';
			$output .= '<option value="5"  >C5</option>';
			$output .= '<option value="6"  >C6</option>';
			$output .= '<option value="7"  >D7</option>';
			$output .= '<option value="8"  >E8</option>';
			$output .= '<option value="9" >F9</option>';
			$output .= '<option value="10" >AR</option>';






		}
		else if ($hiq == '2')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1' >A1</option>";
			$output .= '<option value="2"   selected  >B2</option>';
			$output .= '<option value="3"  >B3</option>';
			$output .= '<option value="4"  >C4</option>';
			$output .= '<option value="5"  >C5</option>';
			$output .= '<option value="6"  >C6</option>';
			$output .= '<option value="7"  >D7</option>';
			$output .= '<option value="8"  >E8</option>';
			$output .= '<option value="9"  >F9</option>';
			$output .= '<option value="10" >AR</option>';

		}
		else if ($hiq == '3')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1' >A1</option>";
			$output .= '<option value="2"  >B2</option>';
			$output .= '<option value="3" selected >B3</option>';
			$output .= '<option value="4"  >C4</option>';
			$output .= '<option value="5"  >C5</option>';
			$output .= '<option value="6"  >C6</option>';
			$output .= '<option value="7"  >D7</option>';
			$output .= '<option value="8"  >E8</option>';
			$output .= '<option value="9"  >F9</option>';
			$output .= '<option value="10" >AR</option>';

		}
		else if ($hiq == '4')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1' >A1</option>";
			$output .= '<option value="2"  >B2</option>';
			$output .= '<option value="3"  >B3</option>';
			$output .= '<option value="4" selected >C4</option>';
			$output .= '<option value="5"  >C5</option>';
			$output .= '<option value="6"  >C6</option>';
			$output .= '<option value="7"  >D7</option>';
			$output .= '<option value="8"  >E8</option>';
			$output .= '<option value="9"  >F9</option>';
			$output .= '<option value="10" >AR</option>';

		}
		else if ($hiq == '5')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>A1</option>";
			$output .= '<option value="2" >B2</option>';
			$output .= '<option value="3" >B3</option>';
			$output .= '<option value="4" >C4</option>';
			$output .= '<option value="5"  selected >C5</option>';
			$output .= '<option value="6"  >C6</option>';
			$output .= '<option value="7"  >D7</option>';
			$output .= '<option value="8"  >E8</option>';
			$output .= '<option value="9"  >F9</option>';
			$output .= '<option value="10" >AR</option>';

		}
		else if ($hiq == '6')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>A1</option>";
			$output .= '<option value="2" >B2</option>';
			$output .= '<option value="3" >B3</option>';
			$output .= '<option value="4" >C4</option>';
			$output .= '<option value="5" >C5</option>';
			$output .= '<option value="6" selected >C6</option>';
			$output .= '<option value="7"  >D7</option>';
			$output .= '<option value="8"  >E8</option>';
			$output .= '<option value="9"  >F9</option>';
			$output .= '<option value="10" >AR</option>';

		}
		else if ($hiq == '7')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>A1</option>";
			$output .= '<option value="2" >B2</option>';
			$output .= '<option value="3" >B3</option>';
			$output .= '<option value="4" >C4</option>';
			$output .= '<option value="5" >C5</option>';
			$output .= '<option value="6" >C6</option>';
			$output .= '<option value="7"  selected  >D7</option>';
			$output .= '<option value="8"  >E8</option>';
			$output .= '<option value="9"  >F9</option>';
			$output .= '<option value="10" >AR</option>';

		}
		else if ($hiq == '8')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>A1</option>";
			$output .= '<option value="2" >B2</option>';
			$output .= '<option value="3" >B3</option>';
			$output .= '<option value="4" >C4</option>';
			$output .= '<option value="5" >C5</option>';
			$output .= '<option value="6" >C6</option>';
			$output .= '<option value="7" >D7</option>';
			$output .= '<option value="8" selected  >E8</option>';
			$output .= '<option value="9"  >F9</option>';
			$output .= '<option value="10" >AR</option>';

		}
		else if ($hiq == '9')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>A1</option>";
			$output .= '<option value="2" >B2</option>';
			$output .= '<option value="3" >B3</option>';
			$output .= '<option value="4" >C4</option>';
			$output .= '<option value="5" >C5</option>';
			$output .= '<option value="6" >C6</option>';
			$output .= '<option value="7" >D7</option>';
			$output .= '<option value="8" >E8</option>';
			$output .= '<option value="9"  selected  >F9</option>';
			$output .= '<option value="10" >AR</option>';

		}
		else if ($hiq == '10')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>A1</option>";
			$output .= '<option value="2" >B2</option>';
			$output .= '<option value="3" >B3</option>';
			$output .= '<option value="4" >C4</option>';
			$output .= '<option value="5" >C5</option>';
			$output .= '<option value="6" >C6</option>';
			$output .= '<option value="7" >D7</option>';
			$output .= '<option value="8" >E8</option>';
			$output .= '<option value="9"  >F9</option>';
			$output .= '<option value="10"  selected >AR</option>';

		}
		else
		{
			$output = '<option value="0"  selected  > -- Please Select-- </option>';
			$output .=  "<option value='1'>A1</option>";
			$output .= '<option value="2" >B2</option>';
			$output .= '<option value="3" >B3</option>';
			$output .= '<option value="4" >C4</option>';
			$output .= '<option value="5" >C5</option>';
			$output .= '<option value="6" >C6</option>';
			$output .= '<option value="7" >D7</option>';
			$output .= '<option value="8" >E8</option>';
			$output .= '<option value="9" >F9</option>';
			$output .= '<option value="10" >AR</option>';


		}
	return $output;

}
//function select highest qualification
function select_nce_grade($hiq)
{

		if ($hiq == '1')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'  selected  >A</option>";
			$output .= '<option value="2"  >B</option>';
			$output .= '<option value="3"  >C</option>';
			$output .= '<option value="4"  >D</option>';
			$output .= '<option value="5"  >E</option>';
			$output .= '<option value="6"  >F</option>';







		}

		else if ($hiq == '2')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'    >A</option>";
			$output .= '<option value="2"  selected >B</option>';
			$output .= '<option value="3"  >C</option>';
			$output .= '<option value="4"  >D</option>';
			$output .= '<option value="5"  >E</option>';
			$output .= '<option value="6"  >F</option>';


		}
		else if ($hiq == '3')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'    >A</option>";
			$output .= '<option value="2"   >B</option>';
			$output .= '<option value="3" selected >C</option>';
			$output .= '<option value="4"  >D</option>';
			$output .= '<option value="5"  >E</option>';
			$output .= '<option value="6"  >F</option>';


		}else if ($hiq == '4')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'    >A</option>";
			$output .= '<option value="2"   >B</option>';
			$output .= '<option value="3"  >C</option>';
			$output .= '<option value="4"  selected >D</option>';
			$output .= '<option value="5"  >E</option>';
			$output .= '<option value="6"  >F</option>';


		}else if ($hiq == '5')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'    >A</option>";
			$output .= '<option value="2"   >B</option>';
			$output .= '<option value="3"  >C</option>';
			$output .= '<option value="4"   >D</option>';
			$output .= '<option value="5" selected  >E</option>';
			$output .= '<option value="6"  >F</option>';


		}else if ($hiq == '6')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'    >A</option>";
			$output .= '<option value="2"   >B</option>';
			$output .= '<option value="3"  >C</option>';
			$output .= '<option value="4"   >D</option>';
			$output .= '<option value="5"   >E</option>';
			$output .= '<option value="6" selected >F</option>';


		}
		else
		{
			$output = 	'<option value="0" selected> -- Please Select-- </option>';
			$output .=  "<option value='1'   >A</option>";
			$output .= '<option value="2"  >B</option>';
			$output .= '<option value="3"  >C</option>';
			$output .= '<option value="4"  >D</option>';
			$output .= '<option value="5"  >E</option>';
			$output .= '<option value="6"  >F</option>';


		}
	return $output;

}
//end of select exam grade



	//function to check if user has been inserted before
	function if_student_is_available($id)
	{
		$result = mysqli_query(dbc(),"SELECT * FROM applicants_olevel WHERE applicant_id = '$id'");

		if(mysqli_num_rows($result) > 0 )
		{
			return true; //if available return true
		}
		else
		{
			return false; //else return false
		}


	}





	//Function to fetch current session
	function get_current_session($id)
	{
		$result = mysqli_query(dbc(),"SELECT * FROM sessions WHERE current_session = '$id'");
		$row = mysqli_fetch_assoc($result);
		$id = $row['id'];


		//set $id = 2 for current session for sales of forms is 2
		$id = 2;
	return $id;
	}


	//Function to fetch  session
	function get_session_title($id)
	{
		$result = mysqli_query(dbc(),"SELECT * FROM sessions WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$title = $row['title'];

	return $title;
	}



	// function that check if a user has finally submitted his/her application
	function check_final_submission($user_id,$session)
	{
		$result = mysqli_query(dbc(),"SELECT final_submission  FROM applicants WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$status = $row['final_submission'];

		if($status == '0')
		{
			$output ='';
					$output .=  '<div class="hide_me">







					 I <strong>'.get_user_fullname($user_id).'</strong> hereby declare that the particulars which I have supplied throughout the application process are true to the best of
					my knowledge and belief and that I understand I could be disqualified for any false information.

				  <br> <br> <br>

						<div class="btn-group" data-toggle="buttons" >
						   <label class="btn btn-success btn-small" >
						   		 <input id="checkbox-id" value="yes"  type="radio" name="agreement"  autocomplete="off"  />Yes

						   </label>

						   <label class="btn btn-success btn-small active" >
						   		 <input id="checkbox-id" value="no" type="radio" name="agreement"  autocomplete="off" checked /> No

						   </label>

						 </div>';



					//	 if(get_user_image($user_id) == '')
						// {
							// $output .='<br> <br> <br><br><br>
								//		<input  class="btn btn-danger btn-md" value="P l e a s e  U p l o a d   Y o u r   P a s s p o r t" type="submit"  data-toggle="tooltip" title="YOU MUST UPLOAD YOUR PASSPORT BEFORE FINAL DECLARATION"/>


									//	</div>';

						 //}
						 //else
						 if(!has_paid_applicant_fee($user_id))
						 {
							 $output .='<br> <br> <br><br><br>
										<input  class="btn btn-danger btn-md" value="P l e a s e  M a k e P a y m e n t s   F i r s t " type="submit"  data-toggle="tooltip" title="YOU MUST PAY BEFORE FINAL DECLARATION"/>


										</div>';
						 }
						 else
						 {



							  $output .='<br> <br> <br><br><br>
							  <input id="save_declaration" class="btn btn-success btn-md" value="C o n f i r m  -  D e c l a r a t i o n  -  &  -  S u b m i t  -  A p p l i c a t i o n" type="submit"  data-toggle="tooltip" title="Click here to submit"/>


							  </div>';

						}



				    return $output;


		}
		else
		{
			return '<div class="hide_me" >
					<div class="alert alert-info in"><button class="close" data-dismiss="alert" type="button">X</button>
			 		<i class="glyphicon glyphicon-info-sign"></i>&nbsp;&nbsp;
					You have successfully completed your application processPlease print your Acknowledgement Slip for reference purpose, we will keep you posted on when to log back to check your Application status. Thank You

					<br>



					</div>


					<br>
					 <a class="btn btn-success"  href="create_biodata_po.php?u='.$user_id.'&s='.$session.'&me='.sha1(md5('ku')).'&e='.sha1(md5('10000')).'&m='.sha1(md5('567')).'" target="_blank" data-toggle="tooltip" data-placement="top" title="Click here to print/download"> P r i n t  -   A c k n o w l e d g e m e n t -  S l i p </a>


							  <br/>


				             <br/> <a target="_blank" href="create_app_payment_slip.php?qlk='.md5(8).'&me='.$user_id.'&s='.$session.'" class="btn btn-info" data-toggle="tooltip" data-placement="top" title="Click here to Print / Download Payment Receipt"><i class="glyphicon glyphicon-print"> </i> P r i n t / D o w n l o a d A P P F e e R e c e i p t</a>

							  </div>
					</div>';


		}


	}
	//end of election interest buttons checking


	/* ################################# function that generates application id %%%%%%%%%%%%%%%%%%%%%%%%%% */
function generate_application_number_for_applicants()
{
	$result = mysqli_query(dbc(),"SELECT * FROM applicants_generate_application_number");
	while($row = mysqli_fetch_array($result))
	{
		$g_code = $row['code'];
	}

	//add 1 to $g_code and tek to d db
	$g_coded = $g_code + 1;

	mysql_query("UPDATE applicants_generate_application_number  SET code = '$g_coded'");

	$len_g_coded  = strlen($g_coded);

	if($len_g_coded == '1')
	{
		$code = '000'.$g_coded;
	}
	else if($len_g_coded == '2')
	{
		$code = '00'.$g_coded;
	}
	else if($len_g_coded == '3')
	{
		$code = '0'.$g_coded;
	}
	else
	{
		$code = $g_coded;
	}


	return $code;
}
//end of generate application number for applicants






	//function that check and show is payment status is paid or not
	function payment_status($status)
	{
		$st = $status;

		if($st == 1)
		{
			return '<h4 class="label label-success">PAID</h4>';
		}
		else
		{
			return '<h4 class="label label-danger">UNPAID</h4>';
		}
	}







//function that filters the browser
function filter_browser($browser, $platform)
{

  $browser = $browser;
  $platform =$platform;


 //reject user if not firefox
  if($browser != 'Mozilla' )
  {
	  header('location:autorize_message/'); // show authorize message
  }

  if($platform != 'Windows!')
  {
	   header('location:autorize_message/'); // show authorize message

  }



} // end of browser / platform filter



//function that set asset action to switch it to last action
function set_asset($user_id , $act)
{
	$q = "SELECT * FROM assets WHERE user_id = '$user_id'";
	$r = mysqli_query(dbc(),$q);

	if(mysqli_num_rows($r)>0)
	{
		$query = "UPDATE assets SET action = '$act', date_added = NOW()";
		mysqli_query(dbc(),$query);
	}
	else
	{

		$query = "INSERT INTO assets (id, user_id, action, date_added)
				VALUES (NULL, '$user_id', '$act', NOW())";
		mysqli_query(dbc(),$query);
	}
}


//check if he has last action stored, get it
function get_asset_action($user_id)
{
	$q = "SELECT * FROM assets WHERE user_id = '$user_id'";
	$r = mysqli_query(dbc(),$q);

	$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
	$at = $row['action'];

	return $at;
}



//delete user recors from applicantion institutions table
function delete_user_records_app_instutions($uid)
{
	$query = "DELETE FROM applicants_institutions  WHERE user_id = '$uid'";
	mysqli_query(dbc(),$query);
}

//function check if he jst assesed the site, if he did redirect the user base on timeout
function redirect_asset($user_id)
{


		 $at = get_asset_action($user_id); // get the last action and den delete

		 $query = "DELETE FROM assets  WHERE user_id = '$user_id'";
		 mysqli_query(dbc(),$query);


			if( $at != '') //if $at not empty then redirect
			{
				header("Location:gateway.php?act=$at");


			}



}



//function select country
function select_country($c)
{
	$r = mysqli_query(dbc(),"SELECT id, country_name  FROM countries  ORDER BY country_name ");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			if($c == $row['id'])
			{
				$output = "<option value=\"$row[id]\" selected>";
				$output .=  $row['country_name'];
				$output .="</option>";

			}
			else
			{
				$output = "<option value=\"$row[id]\" >";
				$output .= $row['country_name'];
				$output .="</option>";

			}


			echo $output;
		}
	}
	else
	{

			$output = "<option>";
			$output .="Not added yet";
			$output .="</option>";

			echo $output;
	}
}
//end of select country_name




//function show country title
function show_country($c)
{
	$r = mysqli_query(dbc(),"SELECT  country_name  FROM countries WHERE id = '$c'");
	$row = mysqli_fetch_assoc($r);

    return $row['country_name'];

}
//end of show country_name






//function select state
function select_state($state)
{
	$r = mysqli_query(dbc(), "SELECT state_id, title  FROM state  ORDER BY title ");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			if($state == $row['state_id'])
			{
				$output = "<option value=\"$row[state_id]\" selected>";
				$output .=  $row['title'];
				$output .="</option>";

			}
			else
			{
				$output = "<option value=\"$row[state_id]\" >";
				$output .= $row['title'];
				$output .="</option>";

			}


			echo $output;
		}
	}
	else
	{

			$output = "<option>";
			$output .="Not added yet";
			$output .="</option>";

			echo $output;
	}
}
//end of select state


//function show state
function show_state($c)
{
	$r = mysqli_query(dbc(),"SELECT  title  FROM state WHERE state_id = '$c'");
	$row = mysqli_fetch_assoc($r);

    return $row['title'];

}
//end of show state



function select_lga( $lga)
{
	$r = mysqli_query(dbc(),"SELECT lga_id, title  FROM lga  ORDER BY title ");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			if($lga == $row['lga_id'])
			{
				$output = "<option value=\"$row[lga_id]\" selected>";
				$output .=  $row['title'];
				$output .="</option>";

			}
			else
			{
				$output = "<option value=\"$row[lga_id]\" >";
				$output .= $row['title'];
				$output .="</option>";

			}


			echo $output;
		}
	}
	else
	{

			$output = "<option>";
			$output .="Not added yet";
			$output .="</option>";

			echo $output;
	}
}
//end of select lga



//function show lga
function show_lga($c)
{
	$r = mysqli_query(dbc(),"SELECT  title  FROM lga WHERE lga_id = '$c'");
	$row = mysqli_fetch_assoc($r);

    return $row['title'];

}
//end of show state


//select faculties
function select_faculty($f)
{
	$r = mysqli_query(dbc(),"SELECT id, title  FROM faculties  ORDER BY title");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			if($f == $row['id'])
			{
				$output = "<option value=\"$row[id]\" selected>";
				$output .=  $row['title'];
				$output .="</option>";

			}
			else
			{
				$output = "<option value=\"$row[id]\" >";
				$output .= $row['title'];
				$output .="</option>";

			}


			echo $output;
		}
	}
	else
	{

			$output = "<option>";
			$output .="Not added yet";
			$output .="</option>";

			echo $output;
	}
}
//end of select faculty




//select department
function select_department($department)
{
	$r = mysqli_query(dbc(),"SELECT department_id, title  FROM departments WHERE real_department = '0' ORDER BY title");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			if($department == $row['department_id'])
			{
				$output = "<option value=\"$row[department_id]\" selected>";
				$output .=  $row['title'];
				$output .="</option>";

			}
			else
			{
				$output = "<option value=\"$row[department_id]\" >";
				$output .= $row['title'];
				$output .="</option>";

			}


			echo $output;
		}
	}
	else
	{

			$output = "<option>";
			$output .="Not added yet";
			$output .="</option>";

			echo $output;
	}
}
//end of select department




//select programme
function select_programme($p)
{
	$r = mysqli_query(dbc(),"SELECT programme_id, title  FROM programmes WHERE real_programmes = '0' AND school_id = 1  ORDER BY title");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			if($p == $row['programme_id'])
			{
				$output = "<option class='col-md-5' value=\"$row[programme_id]\" selected>";
				$output .=  $row['title'];
				$output .="</option>";

			}
			else
			{
				$output = "<option class='col-md-5' value=\"$row[programme_id]\" >";
				$output .= $row['title'];
				$output .="</option>";

			}


			echo $output;
		}
	}
	else
	{

			$output = "<option>";
			$output .="Not added yet";
			$output .="</option>";

			echo $output;
	}
}
//end of select programmes



/* ################################# function that generates Transaxfrtion Id for applicants %%%%%%%%%%%%%%%%%%%%%%%%%% */
function generate_transaction_id()
{
	$result = mysqli_query(dbc(),"SELECT * FROM generate_transaction_id");
	while($row = mysqli_fetch_array($result))
	{
		$g_code = $row['code'];
	}

	//add 1 to $g_code and tek to d db
	$g_coded = $g_code + 1;

	mysqli_query(dbc(),"UPDATE generate_transaction_id  SET code = '$g_coded'");


	//add random four values before adding to the database
	$add_random_value = mt_rand(100, 999);
	$code = $add_random_value.$g_coded;
	$tid = date("Ymd-$code");

	return $tid;
}

/* end of function that generates transaction id */


//function calendar yer
function year($y)
{
	$y = $y;
	$years = range(1950, date('Y'));

	foreach ($years as $value)
	{
		if($y == $value)
		{
	   		echo "<option value=\"$value\" selected>$value</option>\n";
		}
		else
		{
			echo "<option value=\"$value\">$value</option>\n";
		}
	}


}//end of year



//function calendar months
function month($m)
{
	$m = $m;
	$months = range(1, 12);

	foreach ($months as $value)
	{
		if($m == $value)
		{
	   		echo "<option value=\"$value\" selected>$value</option>\n";
		}
		else
		{
			echo "<option value=\"$value\">$value</option>\n";
		}
	}


}




//function calendardays
function day($d)
{
	$d = $d;
	$days = range(1, 31);

	foreach ($days as $value)
	{
		if($d == $value)
		{
	   		echo "<option value=\"$value\" selected>$value</option>\n";
		}
		else
		{
			echo "<option value=\"$value\">$value</option>\n";
		}
	}


}


//get programme name
function get_programme_title($id)
{
	$result = mysqli_query(dbc(),"SELECT title FROM programmes WHERE programme_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$title = $row['title'];

	return $title;
}
//

//get department name
function get_department_title($id)
{
	$result = mysqli_query(dbc(),"SELECT title FROM departments WHERE department_id = '$id'");
	$row = mysqli_fetch_assoc($result);
	$title = $row['title'];

	return $title;
}




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

	return $department_id;

}


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

	return $programme_id;

}


//function that gets programme duration
function  get_programme_duration($id)
{
	$result = mysqli_query(dbc(),"SELECT duration FROM programmes WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['duration'];

	return $v;

}



//function that gets programme max duration
function  get_max_programme_duration($id)
{
	$result = mysqli_query(dbc(),"SELECT maximum_duration FROM programmes WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['maximum_duration'];

	return $v;

}

//function that gets department id by user id
function  get_dept_id($user_id)
{
	$result = mysqli_query(dbc(),"SELECT department_id FROM applicants WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$course_id = $row['department_id'];

	return $course_id;

}

//get admission status

//check if admitted and display MODAL  button
function is_applicant_admitted($id)
{
		$result = mysqli_query(dbc(),"SELECT * FROM applicants WHERE applicant_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['admission_status'];



		return $v;

		//return value

}

//check if admission batch and display MODAL  button
function get_admission_batch($id)
{
		$result = mysqli_query(dbc(),"SELECT * FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['admission_batch'];



		return $v;

		//return value

}









	//function fetch user programme admission serial no
	function get_user_programme_admission_no($id)
	{
		$result = mysqli_query(dbc(),"SELECT admission_serial_no FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['admission_serial_no'];


		return $v;
	}


	//generate applicant admision letter no.
	function generate_applicants_admission_serial_number()
	{
		$result = mysqli_query(dbc(),"SELECT * FROM applicants_generate_admission_serial_number");
		while($row = mysqli_fetch_array($result))
		{
			$g_code = $row['code'];
		}

		//add 1 to $g_code and tek to d db
		$g_coded = $g_code + 1;

		mysqli_query(dbc(),"UPDATE applicants_generate_admission_serial_number  SET code = '$g_coded'");

		$len_g_coded  = strlen($g_coded);

		if($len_g_coded == '1')
		{
			$code = '000'.$g_coded;
		}
		else if($len_g_coded == '2')
		{
			$code = '00'.$g_coded;
		}
		else if($len_g_coded == '3')
		{
			$code = '0'.$g_coded;
		}
		else
		{
			$code = $g_coded;
		}


		return $code;





	}
	//end of function geerate admission serial no


	//function fetch put user admission no
	function put_admission_serial_no($id)
	{

		if(get_user_programme_admission_no($id) == '')
		{
			$admission_sn = generate_applicants_admission_serial_number();

			mysqli_query(dbc(),"UPDATE applicants  SET admission_serial_no = '$admission_sn' WHERE id = '$id'");


		}
		else
		{
			$admission_sn = get_user_programme_admission_no($id);
		}


		return $admission_sn;
	}
	//end of generate adm serialno

	//Function to fetch current semester
	function get_current_semester($id)
	{
		$result = mysqli_query(dbc(),"SELECT * FROM semesters WHERE current_session = '$id'");
		$row = mysqli_fetch_assoc($result);
		$id = $row['id'];

	return $id;
	}


	//Function to fetch  semester
	function get_semester_title($id)
	{
		$result = mysqli_query(dbc(),"SELECT * FROM semesters WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$title = $row['title'];

	return $title;
	}



	//application fee settings
	//Function to fetch  application_fee title
	function get_application_fee_title($pt, $d, $p) //$pt programme type , $d -department , $p -programme id, $s semester
	{
		$result = mysqli_query(dbc(),"SELECT title FROM set_application_fee_payments WHERE programme_type_id = '$pt' AND department_id = '$d' AND programme_id = '$p'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['title'];

	return $v;
	}


	//Function to fetch application_fee desc
	function get_application_fee_desc($pt, $d, $p)
	{
		$result = mysqli_query(dbc(),"SELECT description FROM set_application_fee_payments WHERE  programme_type_id = '$pt' AND department_id = '$d' AND programme_id = '$p'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['description'];

	return $v;
	}

	//Function to fetch  application_fee amount
	function get_application_fee_amount($pt,$d, $p)
	{
		$result = mysqli_query(dbc(),"SELECT amount FROM set_application_fee_payments WHERE  programme_type_id = '$pt' AND department_id = '$d' AND programme_id = '$p'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['amount'];

	return $v;
	}


	//Function to fetch  application _fee  total amountamount
	function get_application_fee_total_amount($pt,$d, $p)
	{
		$result = mysqli_query(dbc(),"SELECT total_amount FROM set_application_fee_payments WHERE programme_type_id = '$pt' AND department_id = '$d' AND programme_id = '$p'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['total_amount'];

	return $v;
	}

	//end of application fee settings




	//Function to fetch  school_fee title
	function get_school_fee_title($level, $s, $pt, $d, $p) //$pt programme type , $d -department , $p -programme id, $s semester
	{
		$result = mysqli_query(dbc(),"SELECT title FROM set_school_fee_payments_for_students WHERE level = '$level' AND semester = '$s' AND programme_type_id = '$pt' AND department_id = '$d' AND programme_id = '$p'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['title'];

	return $v;
	}


	//Function to fetch  school_fee desc
	function get_school_fee_desc($level, $s, $pt, $d, $p)
	{
		$result = mysqli_query(dbc(),"SELECT description FROM set_school_fee_payments_for_students WHERE level = '$level' AND semester = '$s' AND programme_type_id = '$pt' AND department_id = '$d' AND programme_id = '$p'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['description'];

	return $v;
	}

	//Function to fetch  school_fee amount
	function get_school_fee_amount($level, $s, $pt, $d, $p)
	{
		$result = mysqli_query(dbc(),"SELECT amount FROM set_school_fee_payments_for_students WHERE level = '$level' AND semester = '$s' AND programme_type_id = '$pt' AND department_id = '$d' AND programme_id = '$p'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['amount'];

	return $v;
	}
	//Function to fetch  school_fee amount
	function get_school_fee_amount_2($level, $s)
	{
		$result = mysqli_query(dbc(),"SELECT amount FROM set_school_fee_payments_for_students WHERE level = '$level' AND semester = '$s'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['amount'];

	return $v;
	}


	//Function to fetch  school_fee amount
	function get_school_fee_amount_non_indigene($level, $s, $pt, $d, $p)
	{
		$result = mysqli_query(dbc(),"SELECT amount FROM set_school_fee_payments_for_students WHERE level = '$level' AND semester = '$s' AND programme_type_id = '$pt' AND department_id = '$d' AND programme_id = '$p'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['amount'];

	return $v;
	}


	//Function to fetch  school_fee  total amountamount
	function get_school_fee_total_amount($level, $s, $pt, $d, $p)
	{
		$result = mysqli_query(dbc(),"SELECT total_amount FROM set_school_fee_payments_for_students WHERE level = '$level' AND semester = '$s' AND programme_type_id = '$pt' AND department_id = '$d' AND programme_id = '$p'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['total_amount'];

	return $v;
	}

	//Function to fetch  school_fee  total amountamount
	function get_school_fee_total_amount_2($level, $s)
	{
		$result = mysqli_query(dbc(),"SELECT total_amount FROM set_school_fee_payments_for_students WHERE level = '$level' AND semester = '$s'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['total_amount'];

	return $v;
	}


	//Function to fetch  school_fee  total amountamount
	function get_school_fee_total_amount_non_indigene($level, $s, $pt, $d, $p)
	{
		$result = mysqli_query(dbc(),"SELECT total_non_indigene FROM set_school_fee_payments_for_students WHERE level = '$level' AND semester = '$s' AND programme_type_id = '$pt' AND department_id = '$d' AND programme_id = '$p'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['total_non_indigene'];

	return $v;
	}

	//Function to fetch  school_fee  total amountamount
	function get_school_fee_total_amount_non_indigene_2($level, $s)
	{
		$result = mysqli_query(dbc(),"SELECT total_non_indigene FROM set_school_fee_payments_for_students WHERE level = '$level' AND semester = '$s' ");
		$row = mysqli_fetch_assoc($result);
		$v = $row['total_non_indigene'];

	return $v;
	}




	//Function to fetch  invoice credit
	function get_invoice_credit($total_amount , $amount_paid)
	{

		//get total amount to be paid
		$total_amount = $total_amount;



		//get part amount paid
		$amount_paid = $amount_paid;

		//credit
		$credit = $total_amount - $amount_paid;

		 $v = $credit;

	    return $v;
	}



	//get total invoices
	function get_total_num_invoices()
	{
		//get total invoice


		$q = "SELECT COUNT(id) FROM invoices";
		$r = mysqli_query(dbc(),$q);
		$row = mysqli_fetch_array($r,MYSQLI_NUM);

		return $row[0];

	}


	//check if invoice id already exist
	function invoice_id_exist($iid)
	{
		//check if invoice id generated exist
		$q1 = "SELECT invoice_id FROM invoices WHERE invoice_id = '$iid'";
		$r1 = mysqli_query(dbc(),$q1);

		if(mysqli_num_rows($r1)>0)
		{
			return true;
		}
		else
		{
			return false;
		}


	}
	//check if invoice id already exist
	function user_id_exist_app_instutions($uid)
	{
		//check if invoice id generated exist
		$q1 = "SELECT user_id FROM applicants_institutions WHERE user_id = '$uid'";
		$r1 = mysqli_query(dbc(),$q1);

		if(mysqli_num_rows($r1)>0)
		{
			return true;
		}
		else
		{
			return false;
		}


	}




	/* ################################# function that generates invoice id %%%%%%%%%%%%%%%%%%%%%%%%%% */
	//returns true if succesfull
	function generate_invoice_id($id, $user, $type)
	{

		$total_num = get_total_num_invoices();


		//add 1 to $g_code and tek to d db
		$g_coded = $total_num + 1;


		$len_g_coded  = strlen($g_coded); //check lenght

		if($len_g_coded == '1')
		{
			$g_coded = '00'.$g_coded;
		}
		else if($len_g_coded == '2')
		{
			$g_coded = '0'.$g_coded;
		}
		else
		{
			$g_coded = $g_coded; //add strings to invoice id
		}

		$g_coded = $g_coded.mt_rand(10000,99999);

		if(invoice_id_exist($g_coded))
		{
			$g_coded = $g_coded + 1; //if it exist add 1 to it

		}




		//update invoice
		$r = mysqli_query(dbc(),"UPDATE invoices  SET invoice_id  = '$g_coded' WHERE id = '$id' AND invoice_to = '$user' AND invoice_type = '$type'");

		if($r)
		{
			return $g_coded;
		}
		else
		{
			return '';
		}



	}//end of generate invoice id




	//Function to fetch  invoice title
	function get_invoice_title($iid)
	{
		$result = mysqli_query(dbc(),"SELECT title FROM invoices WHERE invoice_id = '$iid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['title'];

		$v = preg_replace('/[^A-Za-z0-9\-]/', ' ', $v);

	return $v;
	}

	//Function to fetch  invoice type
	function get_invoice_type($iid)
	{
		$result = mysqli_query(dbc(),"SELECT invoice_type FROM invoices WHERE invoice_id = '$iid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['invoice_type'];

	return $v;
	}


	//Function to fetch date
	function get_invoice_date($iid)
	{
		$result = mysqli_query(dbc(),"SELECT  DATE_FORMAT(date_added, '%b %e, %Y') as date_added FROM invoices WHERE invoice_id = '$iid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['date_added'];

	return $v;
	}

	//Function to fetch due date
	function get_invoice_due_date($iid)
	{
		$result = mysqli_query(dbc(),"SELECT  DATE_FORMAT(due_date, '%b %e, %Y') as due_date FROM invoices WHERE invoice_id = '$iid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['due_date'];

	return $v;
	}



	//Function to fetch exp date
	function get_invoice_exp_date($iid)
	{
		$result = mysqli_query(dbc(),"SELECT  DATE_FORMAT(expire_date, '%b %e, %Y /  %l:%i:%p') as exp_date FROM invoices WHERE invoice_id = '$iid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['exp_date'];

	return $v;
	}







	//Function to fetch  invoice to
	function get_invoice_invoice_to($iid)
	{
		$result = mysqli_query(dbc(),"SELECT invoice_to FROM invoices WHERE invoice_id = '$iid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['invoice_to'];

	return $v;
	}


	//Function to fetch  pay to
	function get_invoice_pay_to($iid)
	{
		$result = mysqli_query(dbc(),"SELECT pay_to FROM invoices WHERE invoice_id = '$iid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['pay_to'];

	return $v;
	}


	//Function to fetch  invocie for
	function get_invoice_for($iid)
	{
		$result = mysqli_query(dbc(),"SELECT invoice_for FROM invoices WHERE invoice_id = '$iid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['invoice_for'];

	return $v;
	}


	//Function to fetch descripion
	function get_invoice_desc($iid)
	{
		$result = mysqli_query(dbc(),"SELECT description FROM invoices WHERE invoice_id = '$iid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['description'];

	return $v;
	}



	//Function to fetch amount
	function get_invoice_amount($iid)
	{
		$result = mysqli_query(dbc(),"SELECT amount FROM invoices WHERE invoice_id = '$iid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['amount'];

	return $v;
	}



	//Function to fetch total amount
	function get_invoice_total_amount($iid)
	{
		$result = mysqli_query(dbc(),"SELECT total_amount FROM invoices WHERE invoice_id = '$iid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['total_amount'];

	return $v;
	}


	//Function to fetch invoiced credit (credit of invoice generated)
	function get_invoiced_credit($iid)
	{
		$result = mysqli_query(dbc(),"SELECT credit FROM invoices WHERE invoice_id = '$iid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['credit'];

	return $v;
	}

	//Function to fetch payment_satus
	function get_invoice_payment_status($iid)
	{
		$result = mysqli_query(dbc(),"SELECT payment_status FROM invoices WHERE invoice_id = '$iid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['payment_status'];

	return $v;
	}


function view_invoices($user_id, $invoce_type, $session)
{

	//query the database
	$query = "SELECT `id`, `invoice_id`,`invoice_type`, `invoice_to`, `pay_to`, `invoice_for`, `payment_method`, `payment_status`,
			 `user_carts`, `title`, `description`, `amount`, `credit`, DATE_FORMAT(date_added, '%b %e, %Y') as date_added,
			 DATE_FORMAT(due_date, '%b %e, %Y') as due_date,
			 DATE_FORMAT(expire_date, '%b %e, %Y /  %l:%i:%p') as exp_date

			 FROM `invoices`
			 WHERE invoice_to = '$user_id' AND invoice_type = '$invoce_type'  AND session = '$session'


			 ORDER BY invoice_id DESC";
   $result = mysqli_query(dbc(),$query);



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


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

					  <th>Invoice #</th>
					  <th>Amount</th>
					  <th>Invoice Date</th>
					  <th>Due Date</th>
					  <th>Status</th>
					  <th></th>



		  </thead>

		 <!-- <tfoot>




		  </tfoot>-->

		  <tbody>';


		while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$row['invoice_id']."</td>"; //group belong to admin or user
			$output .= "<td> N".number_format($row['amount'])."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['due_date']."</td>";
			$output .= "<td>".payment_status($row['payment_status'])."</td>";


			if($invoce_type == 0)
			{
				$output .= '<td><a class="btn btn-default" href="dashboard.php?act=view_invoices&qlk='.md5(8).'&iid='.$row['invoice_id'].'"> View Invoice</a></td>';

			}
			else if($invoce_type == 1)
			{
				$output .= '<td><a class="btn btn-default" href="dashboard.php?act=view_invoices4&qlk='.md5(8).'&iid='.$row['invoice_id'].'"> View Invoice</a></td>';

			}
			else
			{
				$output .= '<td><a class="btn btn-default" href="dashboard.php?act=view_invoices2&qlk='.md5(8).'&iid='.$row['invoice_id'].'"> View Invoice</a></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 school fee invoices








	//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
			  WHERE student_id = '$user_id'
			  AND session = '$session'
			  AND payment_status  = '1'";
		$r = mysqli_query(dbc(),$q);

		//$row = mysql_fetch_assoc$result);

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

		}
		else
		{
			return true;
		}

	}






//function show school fee payment status, by session
function show_school_fee_payment($user_id, $sess)
{
	$q = "SELECT `id`, `student_id`,  `session`, `payment_status`,  DATE_FORMAT(date_added, '%M %e, %Y / %l:%i:%p') as date_added
		 FROM school_fee_payments WHERE student_id = '$user_id'  AND session = '$sess'";
	$r =mysqli_query(dbc(),$q);

	//pass session through SESSION
	  @$session = $row['session'];
	 @setcookie('ps',$session,20000, '/');

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



	//$output ='<ul class="list-group">';



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

			//$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['user_id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
			$output .= "<li class='list-group-item'>You have paid schoolfee for ".get_session_title($row['session'])." Academic Session</li>";
			$output .= "<li class='list-group-item'>Date / time of payment :- ".$row['date_added']."</li>";
			//$output .= "<li class='list-group-item'>STATUS:".payment_status($row['payment_status'])."</li>";

			$output .= "<div class='' style='height:20px;'></div>";


			$output .= '&nbsp;&nbsp;&nbsp;<a class="btn btn-success"  href="create_payment_slip.php?me='.$user_id.'&s='.$sess.'&myid='.md5('fuckusha1sha1').'."   data-toggle="tooltip" data-placement="top" title="Download / Print  ">Click here to  DOWNLOAD / PRINT </a>';




		}
	}
	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>';


	}





	return $output;




}

/* ################################# function that generates Transaxfrtion reference no. for applicants %%%%%%%%%%%%%%%%%%%%%%%%%% */
	function generate_vogue_txn_ref()
	{

		//add random four values before adding to the database
		$add_random_value = mt_rand(100, 999);
		$code = $add_random_value;
		$tid = date("Ymdhis$code");

		return $tid;
	}



	//function view transaction log
	function view_vogue_pay_transaction_log($user_id, $t_type, $t_for)
	{

		//query the database
		$query = "SELECT `id`, `invoice_id`, `transaction_type`, `user_id`, `transaction_for`, `payment_method`,
		`payment_status`, `response_code`, `response_description`, `transaction_id`,`transaction_reference`, `merchant_reference`,
		 `title`, `description`, `amount`, DATE_FORMAT(date_added, '%b %e, %Y /  %l:%i:%p') as date_added, email, total_paid_by_buyer,transaction_date

		  FROM `vogue_webpay_transaction_log`

		  WHERE user_id = '$user_id' AND transaction_type = '$t_type' AND transaction_for = '$t_for'


		 ORDER BY id DESC";
	   $result = mysqli_query(dbc(),$query);



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


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

						  <th>Invoice #</th>
						  <th>Transaction ID</th>
						  <th>Transaction Ref.</th>
						  <th>Title</th>
						  <th>Amount - (N)</th>
						  <th>Transaction Response</th>
						  <th>Date / Time</th>
						  <th>Status</th>
						  <th>Payment Email</th>


			  </thead>

			 <!-- <tfoot>

			  </tfoot>-->

			  <tbody>';


			while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
			{
				$output .= "<tr>";
				$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$row['invoice_id']."</td>"; //group belong to admin or user
				$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$row['transaction_id']."</td>";
				$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$row['transaction_reference']."</td>";
                $output .= "<td>".$row['title']."</td>";
				$output .= "<td>".number_format($row['amount'],2)."</td>";

				$output .= "<td>".$row['response_code'].")"."</td>";

				$output .= "<td>".$row['transaction_date']."</td>";
				$output .= "<td>".transaction_status($row['payment_status'])."</td>";
				//$output .= '<td><a href="" class="btn btn-primary" > Re query </a></td>';
				$output .= "<td>".$row['email']."</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 transaction log

	function get_payment_status_by_resp_code($resp_code)
	{
		if($resp_code == '00' || $resp_code == '01')
		{
			return 1;
		}
		else
		{
			return  2;
		}

	}//end of payments status



	//Function to fetch check ifparticular transaction id exist
	function v_tid_exist($tid,$uaid)
	{
		$q = "SELECT  	transaction_id FROM vogue_webpay_transaction_log
		      WHERE  transaction_id = '$tid'
			  AND  	user_id  = '$uaid'";

		$result = mysqli_query(dbc(),$q);
		//$row = mysql_fetch_assoc$result);
		//$an = $row['transaction_id'];

		if(mysqli_num_rows($result) > 0 )
		{
			return true;


		}
		else
		{
			return false;


		}

	}



	//Function to fetch check ifparticular transaction reference exist
	function v_trf_exist($trf,$uaid)
	{
		$q = "SELECT  	transaction_reference FROM vogue_webpay_transaction_log
		      WHERE  transaction_reference = '$trf'
			  AND  	user_id  = '$uaid'";

		$result = mysqli_query(dbc(),$q);
		//$row = mysql_fetch_assoc$result);
		//$an = $row['transaction_id'];

		if(mysqli_num_rows($result) > 0 )
		{
			return true;


		}
		else
		{
			return false;


		}

	}


	//remita processing starts here
	function generate_remita_txn_ref()
	{

		//add random four values before adding to the database
		$add_random_value = mt_rand(100, 999);
		$code = $add_random_value;
		$tid = date("Ymdhis$code");

		return $tid;
	}

	//Function to fetch check ifparticular transaction id exist
	function r_tid_exist($tid,$uaid)
	{
		$q = "SELECT  	transaction_id FROM remita_webpay_transaction_log
		      WHERE  transaction_id = '$tid'
			  AND  	user_id  = '$uaid'";

		$result = mysqli_query(dbc(),$q);
		//$row = mysql_fetch_assoc$result);
		//$an = $row['transaction_id'];

		if(mysqli_num_rows($result) > 0 )
		{
			return true;


		}
		else
		{
			return false;


		}

	}//end of if tid exist



	//Function to fetch check ifparticular transaction reference exist
	function r_trf_exist($trf,$uaid)
	{
		$q = "SELECT  	transaction_reference FROM remita_webpay_transaction_log
		      WHERE  transaction_reference = '$trf'
			  AND  	user_id  = '$uaid'";

		$result = mysqli_query(dbc(),$q);
		//$row = mysql_fetch_assoc$result);
		//$an = $row['transaction_id'];

		if(mysqli_num_rows($result) > 0 )
		{
			return true;


		}
		else
		{
			return false;


		}

	}
	//end of remita trf exist

		//function view transaction log
	function view_remita_pay_transaction_log($user_id, $t_type, $t_for)
	{

		//query the database
		$query = "SELECT `id`, `invoice_id`, `transaction_type`, `user_id`, `transaction_for`, `payment_method`,
		`payment_status`, `response_code`, `response_description`, `transaction_id`,`transaction_reference`, `merchant_reference`,
		 `title`, `description`, `amount`, DATE_FORMAT(date_added, '%b %e, %Y /  %l:%i:%p') as date_added, email, total_paid_by_buyer,transaction_date

		  FROM `remita_webpay_transaction_log`

		  WHERE user_id = '$user_id' AND transaction_type = '$t_type' AND transaction_for = '$t_for'


		 ORDER BY id DESC";
	   $result = mysqli_query(dbc(),$query);



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


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

						  <th>Invoice #</th>
						  <th>RRR</th>
						  <th>Transaction Ref.</th>
						  <th>Title</th>
						  <th>Amount - (N)</th>
						  <th>Transaction Response</th>
						  <th>Date / Time</th>
						  <th>Status</th>
						  <th>Action</th>


			  </thead>

			 <!-- <tfoot>

			  </tfoot>-->

			  <tbody>';


			while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
			{
				$output .= "<tr>";
				$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$row['invoice_id']."</td>"; //group belong to admin or user
				$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$row['transaction_id']."</td>";
				$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$row['transaction_reference']."</td>";
                $output .= "<td>".$row['title']."</td>";
				$output .= "<td>".number_format($row['amount'],2)."</td>";

				$output .= "<td>(".$row['response_code'].")"."</td>";

				$output .= "<td>".$row['transaction_date']."</td>";
				$output .= "<td>".transaction_status($row['payment_status'])."</td>";
				$output .= '<td>'.transaction_status_for_log($row['payment_status'],$row['transaction_reference']).'</td>';
				//$output .= "<td>".$row['email']."</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 transaction log for remita




	//function view transaction log
	function view_remita_pay_transaction_log_min($user_id, $t_type, $t_for)
	{

		//query the database
		$query = "SELECT `id`, `invoice_id`, `transaction_type`, `user_id`, `transaction_for`, `payment_method`,
		`payment_status`, `response_code`, `response_description`, `transaction_id`,`transaction_reference`, `merchant_reference`,
		 `title`, `description`, `amount`, DATE_FORMAT(date_added, '%b %e, %Y /  %l:%i:%p') as date_added, email, total_paid_by_buyer,transaction_date

		  FROM `remita_webpay_transaction_log`

		  WHERE user_id = '$user_id' AND transaction_type = '$t_type' AND transaction_for = '$t_for'


		 ORDER BY id DESC";
	   $result = mysqli_query(dbc(),$query);



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


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

						  <th>Invoice #</th>
						  <th>Transaction Ref.</th>
						  <th>Date / Time</th>
						  <th>Status</th>
						  <th>Action</th>


			  </thead>

			 <!-- <tfoot>

			  </tfoot>-->

			  <tbody>';


			while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
			{
				$output .= "<tr>";
				$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$row['invoice_id']."</td>"; //group belong to admin or user
				//$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$row['transaction_id']."</td>";
				$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$row['transaction_reference']."</td>";
                //$output .= "<td>".$row['title']."</td>";
				//$output .= "<td>".number_format($row['amount'],2)."</td>";

				//$output .= "<td>(".$row['response_code'].")"."</td>";

				$output .= "<td>".$row['transaction_date']."</td>";
				$output .= "<td>".transaction_status($row['payment_status'])."</td>";
				$output .= '<td>'.transaction_status_for_log($row['payment_status'],$row['transaction_reference']).'</td>';
				//$output .= "<td>".$row['email']."</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 transaction log for remita


















	//function tohandle remita pay response code
	function remita_response_code($stat, $rrr, $desc, $iid )
	{
		$mes = '<ul class="list-group">';

		if($stat == '01' || $stat == '00')
		{
			$mes .= '<li class="list-group-item list-group-item-success"><p><i class="glyphicon glyphicon-exclamation-sign"></i> Your transaction is Approved and being processed. <br/>';
			$mes .= '<h2>Transaction Successful</h2>';
			$mes .= "<h4> Transaction #ref: $iid</h4>";
			$mes .= "<br/><h3> Remita Retrieval Reference: $rrr </h3></p></li>";


		}
		else if($stat == '021')
		{
			$mes .= '<li class="list-group-item list-group-item-info"><p><i class="glyphicon glyphicon-exclamation-sign"></i> RRR!. <br/> ';
			$mes .= '<h2>RRR Generated Successfully</h2>';
			$mes .= "<h4>Transaction #ref: $iid</h4>";
            $mes .= "<br/><h3> Remita Retrieval Reference: $rrr </h3> You can take this RRR to Remita Enabled Banks to make payment!</p></li>";


		}
		else
		{
			$mes .= '<li class="list-group-item list-group-item-danger"><p><i class="glyphicon glyphicon-exclamation-sign"></i> <h2>Your Transaction was not Successful.</h2> <br/> ';


			if($rrr !=null)
			{
				$mes .= "<br/><h3> Remita Retrieval Reference: $rrr </h3>";
			}
			$mes .= "<h4>Transaction #ref: $iid</h4>";
            $mes .= "<br/> <strong>Reason:  $desc </strong> <br/><br/> ";
			$mes .= "Click view invoice on the top to try again!</p></li>";

		}

		$mes .='</ul>';


		return $mes;
	}

	//function to get invoice payment to using orderID
	function get_invoice_to_using_txnref($oid)
	{
		$result = mysqli_query(dbc(),"SELECT user_id FROM remita_webpay_transaction_log WHERE transaction_reference = '$oid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['user_id'];

	return $v;
	}

	//function to get invoice id   using orderID
	function get_invoice_id_using_txnref($oid)
	{
		$result = mysqli_query(dbc(),"SELECT invoice_id FROM remita_webpay_transaction_log WHERE transaction_reference = '$oid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['invoice_id'];

	return $v;
	}









	//Function to fetch check if payment has been made by particular applicant
	function has_paid_applicant_fee($user_id)
	{
		$q = "SELECT applicant_id FROM applicants_fee_payments
		      WHERE applicant_id = '$user_id'";
		$r = mysqli_query(dbc(),$q);

		//$row = mysql_fetch_assoc$result);

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

		}
		else
		{
			return true;
		}

	}

	//function transaction status
	  function transaction_status($id)
	  {
		  if($id == '1')
		  {
			  return '<label class="label label-success"> SUCCESSFUL </label>';
		  }
		  else
		  {
			  return  '<label class="label label-danger"> FAILED </label>';
		  }
	  }


	  //function transaction status
	  function transaction_status_for_log($id,$tref)
	  {
		  if($id == '1')
		  {
			  //return '<label class="label label-success"> SUCCESSFUL </label>';
		  }
		  else
		  {
			  return  '<a class="btn btn-sm  btn-danger" href="dashboard.php?act=check_trxn_status&txnref='.$tref.'" class="btn btn-primary" > Re-query </a>';
		  }
	  }





	//function to check if application or form sales is on // application is on 1
	function get_application_status()
	{
		$result = mysqli_query(dbc(),"SELECT * FROM control WHERE id = 1");
		$row = mysqli_fetch_assoc($result);
		$status = $row['status'];

		if($status == 1)
		{
			return true;
		}
		else
		{
			return false;
		}


	}



//function tohandle vogue pay response code
	function vog_response_code($stat, $mref, $tid, $desc )
	{
		$mes = '<ul class="list-group">';

		if($stat == 'success')
		{
			$mes .= '<li class="list-group-item list-group-item-success"><p><i class="glyphicon glyphicon-exclamation-sign"></i> Your transaction is Approved and being processed. <br/> Desc: ';
			$mes .= 'Approved by Financial Institution';
			$mes .= "<br/><strong> Invoice ref ID: $mref </strong>";
			$mes .= "<br/> <strong>Payment Reference ID: $tid </strong></p></li>";


		}
		else
		{
			$mes .= '<li class="list-group-item list-group-item-danger"><p><i class="glyphicon glyphicon-exclamation-sign"></i> Your transaction was not successful. <br/> Reason: ';
			$mes .= "$desc";
			$mes .= "<br/><strong> Invoice ref ID: $mref </strong>";
			$mes .= "<br/> <strong>Payment Reference ID: $tid </strong> <br/><br/> ";
			$mes .= "Click view invoice on the top to try again!</p></li>";

		}

		$mes .='</ul>';


		return $mes;
	}

	  // function that check if a applicant application number exist in stduents table or not
	function applicant_id_exist_payments($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT applicant_id FROM applicants_fee_payments WHERE applicant_id = '$user_id'");
		//$row = mysql_fetch_assoc$result);
		//$an = $row['applicant_id'];

		if(mysqli_num_rows($result)>0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	//end of application no exist



	//matric number funcions
	//function get total students in a programme per programme type, department, $programme , level
	function get_total_programme_students($pt, $d, $p, $l)
	{
		$q = "SELECT COUNT(*) FROM students  WHERE   type_id = '$pt' AND department_id = '$d' AND programme_id = '$p' AND level = '$l' AND validity_status = '0'";
		$r = mysqli_query(dbc(),$q);
		$row = mysqli_fetch_array($r,MYSQLI_NUM);

		return $row[0];

	}



	//function generate matric number
	function generate_matric_number($pt, $dep, $p, $level, $total_in_programme)
	{

		//check programme type to know if to give AD or D
		if($pt == '1')
		{
			$first_letter = 'A';
		}
		else if($pt == '2')
		{
			$first_letter = 'D';
		}
		else if($pt == '3')
		{
			$first_letter = 'C';
		}
		else
		{

		}




		//get programme code from programme

		$programme_code = strtoupper(get_programme_code($p));  //get the department code from applied department


		//if i know ur admitted departmen, ican check by passing the id to programme so to get total
		//$total_in_programme = get_total_programme_students($pt,$dep,$p,$l);

		$total = $total_in_programme;




		//getcuurent sesssiom
		//Function to fetch current session
		 $session = get_current_session($id ='1');

		 //get the session title
		 $session_title = get_session_title($session);


		 //get the year from the session
		 $year = substr ($session_title,2,2);



		//$year = date('Y');

		$count_character = strlen($total);

		if($count_character == '1')
		{
			$total = '000'.$total;
		}
		else if($count_character == '2')
		{
			$total = '00'.$total;
		}
		else if($count_character == '3')
		{
			$total = '0'.$total;
		}
		else if($count_character == '4')
		{
			$total = $total;
		}
		else
		{
			//do nothing for now
		}



		$matric_number = $first_letter.$year.'/'.$programme_code.'/'.$total; //give the matric number if not exist




		if(matric_number_exist($matric_number)) //if matric no exis, do obstruct and pass through some test
		{


				$mn = $first_letter.$year.'/'.$programme_code.'/'; //collect the matric parameters

				//collect all the matric number


				$q = "SELECT number FROM students WHERE number LIKE '%$mn%'";
				$r = mysqli_query(dbc(),$q);

				//$row = mysql_fetch_array($r, MYSQL_ASSOC);
				$mmno = array(); //array declared to hold all the matric numbers
				while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
				{

					$number = $row['number']; //collect all the matric numbers and pass to an array

					$filtered_no = substr($number, 9,4);
					$mmno[] = $filtered_no; //no need to implode

				}

						//$comma_separated = implode(",", $mmno);


				$highestmn = max($mmno); //check the max number from stored arrays

				$hn = $highestmn + 1; //ad 1 to the highest

				$count_character2 = strlen($hn); //count the xters

				if($count_character2 == '1')
				{
					$hn = '000'.$hn;
				}
				else if($count_character2 == '2')
				{
					$hn = '00'.$hn;
				}
				else if($count_character2 == '3')
				{
					$hn = '0'.$hn;
				}
				else if($count_character2 == '4')
				{
					$hn = $hn;
				}
				else
				{
					//do nothing for now
				}




				$matric_numbe = $first_letter.$year.'/'.$programme_code.'/'.$hn; //pad the matric numbers with the right strings


				return $matric_numbe ;

			//}


		}
		else
		{
			return $matric_number;
		}


		//return $matric_number;

	}


	//function that gets programme code base on course id
	function  get_programme_code($id)
	{
		$result = mysqli_query(dbc(),"SELECT code FROM programmes WHERE id = '$id'");
			$row = mysqli_fetch_assoc($result);
			$code = $row['code'];

		return $code;

	}

	//application number exist
	function application_number_exist($apn, $l)
	{
		$result = mysqli_query(dbc(),"SELECT application_number  FROM students WHERE application_number = '$apn' AND level = '$l'");
		$row = mysqli_fetch_assoc($result);
		$an = $row['application_number'];

		if($an == '')
		{

			return false;



		}
		else
		{
			return true;


		}


	}
	//end of checking if applicant exist

	//check if a particular matric number is on the system
	function matric_number_exist($mno)
	{
	    $result = mysqli_query(dbc(),"SELECT number FROM students WHERE number = '$mno'");
		$row = mysqli_fetch_assoc($result);
		$mno = $row['number'];

		if($mno == '')
		{

			return false;

		}
		else
		{
			return true;

		}


	}///end of check whether matric number exist


	//function dat checks if student exist in database table
	function student_id_exist_payments($sid,$sess, $sem)  //sid is the student id
	{
		$q = "SELECT student_id FROM school_fee_payments  WHERE student_id = '$sid' AND session = '$sess' AND semester = '$sem' ";
		$r = mysqli_query(dbc(),$q);


		if(mysqli_num_rows($r) > 0)
		{
			return true;
		}
		else
		{
			return false;
		}



	}//end of function that chk if student id exist in school fee payments


		//function fetch student id by application number
	function get_student_id_application_number($id)
	{
		$result = mysqli_query(dbc(),"SELECT id FROM students WHERE application_number = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['id'];


		return $v;
	}

	//function fetch user student matric no using serial no.o
	function get_student_matric_no_by_app_no($id, $s)
	{
		$result = mysqli_query(dbc(),"SELECT number FROM students WHERE application_number = '$id' AND session = '$s'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['number'];


		return $v;
	}


//function to check if nigerlite 1
	function is_nigerlite($u)
	{
		$result = mysqli_query(dbc(),"SELECT state_id FROM applicants WHERE state_id = 27 AND id = '$u'");
		$row = mysqli_fetch_assoc($result);
		$status = $row['state_id'];


		if($status == 27)
		{
			return true;
		}
		else
		{
			return false;
		}
	}

?>
