<?php 
##################################################################
#  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('../includes/configuration.php');


	//function get_user()
//	{
//		$user_id = $_SESSION['id'];
//		return $user_id;
//	}





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

	
	
	

//Function to fetch User Last IP
	function get_last_login_ip($user_id)
	{
		$result = mysql_query("SELECT * FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_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 = mysql_query("SELECT DATE_FORMAT(last_login, '%b %e,%y  %l:%i:%p') as user_lastlogindate  FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_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 = mysql_query("SELECT * FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_fetch_assoc($result);
		$first_name = $row['first_name'];
		$other_names = $row['other_names'];
		
		$user_fullname = $first_name . " " . $other_names;

	return $user_fullname;
	}
	
	
//Function to fetch user name
	function get_user_username($user_id)
	{
		$result = mysql_query("SELECT username FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_fetch_assoc($result);
		$username = $row['username'];
		

	return $username;
	}
	
	
	
	
//Function to fetch email
	function get_user_email($user_id)
	{
		$result = mysql_query("SELECT email FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_fetch_assoc($result);
		$email = $row['email'];

	return $email;
	}
	
	
	
	//Function to fetch phone number
	function get_user_phone_no($user_id)
	{
		$result = mysql_query("SELECT phone_number FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_fetch_assoc($result);
		$ph = $row['phone_number'];

	return $ph;
	}
	
	
	//function dat get user security id  by id 
	function get_security_id($user_id)
	{
		$q = "SELECT security_id FROM applicants_nce WHERE id = '$user_id' ";
		$r = mysql_query($q);
		$row = mysql_fetch_assoc($r);
		
		return $row['security_id'];
		
		
	}
	
	
	//function dat get user address 
	function get_user_address($user_id)
	{
		$q = "SELECT address FROM applicants_nce WHERE id = '$user_id'";
		$r = mysql_query($q);
		$row = mysql_fetch_assoc($r);
		
		return $row['address'];
		
		
	}
	
	
	
	
	//function dat get user image by id 
	function get_user_image($user_id)
	{
	$q = "SELECT image FROM applicants_nce WHERE id = '$user_id'";
	$r = mysql_query($q);
	$row = mysql_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_nce WHERE id = '$user_id'";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	
	return $row['application_number'];
	
	
	}
	
	
	
	
	
	//Function to fetch role name
	function get_role_title($role_id)
	{
		$result = mysql_query("SELECT * FROM roles WHERE id = '$role_id'"); 
		$row = mysql_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 = mysql_query("SELECT first_name FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_fetch_assoc($result);
		$first_name = $row['first_name'];
	

	return $first_name;
	}
	
	//Functions to fetch user's other names
	function get_user_other_names($user_id)
	{
		$result = mysql_query("SELECT other_names FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_fetch_assoc($result);
		$on = $row['other_names'];
	

	return $on;
	}
	
	//Functions to fetch user's marital status
	function get_user_ms($user_id)
	{
		$result = mysql_query("SELECT marital_status FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_fetch_assoc($result);
		$ms = $row['marital_status'];
	

	return $ms;
	}
	
	
		//Functions to fetch user's gender
	function get_user_gender($user_id)
	{
		$result = mysql_query("SELECT gender FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_fetch_assoc($result);
		$gd = $row['gender'];
	

	return $gd;
	}
	
	
	
		//Functions to fetch user's religion
	function get_user_religion($user_id)
	{
		$result = mysql_query("SELECT religion FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_fetch_assoc($result);
		$religion = $row['religion'];
	

	return $religion;
	}
	
	
	
		//Functions to fetch user's place of birth
	function get_user_pob($user_id)
	{
		$result = mysql_query("SELECT place_of_birth FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['place_of_birth'];
	

	return $v;
	}
	
	
	
	//function fetch user day
	function get_user_day($id)
	{
		$result = mysql_query("SELECT day FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$day = $row['day'];
		
		return $day;
	}
	
	
	
	
	//function fetch user month
	function get_user_month($id)
	{
		$result = mysql_query("SELECT month FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$month = $row['month'];
		
		return $month;
	}
	
	
	
	//function fetch user year
	function get_user_year($id)
	{
		$result = mysql_query("SELECT year FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$year = $row['year'];
		
		return $year;
	}
	
	
	//function fetch user nationality
	function get_user_nationality($id)
	{
		$result = mysql_query("SELECT nationality FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$n = $row['nationality'];
		
		return $n;
	}
	
	
	
	//function fetch user country
	function get_user_country_id($id)
	{
		$result = mysql_query("SELECT country_id FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$country_id = $row['country_id'];
		
		return $country_id;
	}
	
	
	//function fetch user state id
	function get_user_state_id($id)
	{
		$result = mysql_query("SELECT state_id FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$sid = $row['state_id'];
		
		return $sid;
	}
	
	//function fetch user lga id
	function get_user_lga_id($id)
	{
		$result = mysql_query("SELECT lga_id FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$lid = $row['lga_id'];
		
		return $lid;
	}
	
	
	
	
	//function get user permanent address
	
	function get_user_permanent_address($id)
	{
		$result = mysql_query("SELECT permanent_address FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['permanent_address'];
		
		
		return $v;
	}
	
	
	
	
	//function get user guardian_name
	function get_user_guardian_name($id)
	{
		$result = mysql_query("SELECT guardian_name FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['guardian_name'];
		
		
		return $v;
	}
	
	
	
	
	//function get user guardian_relationship
	function get_user_guardian_relationship($id)
	{
		$result = mysql_query("SELECT guardian_relationship FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['guardian_relationship'];
		
		
		return $v;
	}


		//function get guardian_tel
	function get_user_guardian_tel($id)
	{
		$result = mysql_query("SELECT guardian_tel FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['guardian_tel'];
		
		
		return $v;
	}
	
	
	
	//function get guardian_address
	function get_user_guardian_address($id)
	{
		$result = mysql_query("SELECT guardian_address FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['guardian_address'];
		
		
		return $v;
	}
	
	
	
	//function get user sponsorhip type
	function get_user_sponsorship_type($id)
	{
		$result = mysql_query("SELECT sponsorship_type FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['sponsorship_type'];
		
		
		return $v;
	}
	

	//function get user sponsorhip type
	function get_user_sponsorhip_name($id)
	{
		$result = mysql_query("SELECT sponsorship_name FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['sponsorship_name'];
		
		
		return $v;
	}
	
	
	//function get user sponsorhip address
	function get_user_sponsorship_address($id)
	{
		$result = mysql_query("SELECT sponsorship_address FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['sponsorship_address'];
		
		
		return $v;
	}
	


//function fetch user programme type
	function get_user_programme_type($id)
	{
		$result = mysql_query("SELECT programme_type_applied_for FROM applicants_nce WHERE id = '$id'");
		$row = mysql_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 = mysql_query("SELECT programme_type_applied_for FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['programme_type_applied_for'];
		
		
		return $v;
	}
	
	
	//function fetch user school applied for 
	function get_user_school_applied_for($id)
	{
		$result = mysql_query("SELECT school_applied_for FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['school_applied_for'];
		
		
		return $v;
	}

//function fetch user programme_applied_for
	function get_user_programme_applied_for($id)
	{
		$result = mysql_query("SELECT programme_applied_for FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['programme_applied_for'];
		
		
		return $v;
	}


//function fetch user department applied for
	function get_user_department_applied_for($id)
	{
		$result = mysql_query("SELECT department_applied_for FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['department_applied_for'];
		
		
		return $v;
	}


	
	//function fetch user entry_year
	function get_user_entry_year($id)
	{
		$result = mysql_query("SELECT entry_year FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['entry_year'];
		
		
		return $v;
	}
	
	
	
	//function fetch user health status
	function get_user_h_status($id)
	{
		$result = mysql_query("SELECT H_status FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['H_status'];
		
		return $v;
	}
	
	
	
	//function fetch user disability
	function get_user_disability($id)
	{
		$result = mysql_query("SELECT disability FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['disability'];
		
		return $v;
	}
	
	//function fetch user blood group
	function get_user_bg($id)
	{
		$result = mysql_query("SELECT blood_type FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['blood_type'];
		
		
		return $v;
	}
	
	
	
	
	
	//function fetch user medication
	function get_user_medication($id)
	{
		$result = mysql_query("SELECT medi FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['medi'];
		
		return $v;
	}
	
	


	
	
	
	
	//function fetch user credential
	function get_user_credential($id)
	{
		$result = mysql_query("SELECT pdf_file FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['pdf_file'];
		
		return $v;
	}
	
	
	
	
	
	
//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>';
		
			
		}
		else if ($gd == 'F')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="M"> Male</option>';
			$output .= '<option value="F" selected > Female</option>';
		
			
		}
		else
		{
		
			$output = '<option value="0"  selected  > -- Please Select --</option>';
			$output .= '<option value="M"> Male</option>';
			$output .= '<option value="F"> Female</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" > UNICEF</option>';
			$output .= '<option value="5" > Sport</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" > UNICEF</option>';
			$output .= '<option value="5" > Sport </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" > UNICEF </option>';
			$output .= '<option value="5" > Sport </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 > UNICEF </option>';
			$output .= '<option value="5" > Sport </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" > UNICEF </option>';
			$output .= '<option value="5" selected > Sport </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"  > UNICEF </option>';
			$output .= '<option value="5"  > Sport </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 = 'UNICEF';
		
			
		}
		else if ($r == '5')
		{
			$output = 'Sport';
		
		
			
		}
		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 > Pre - NCE</option>';
			$output .= '<option value="2" > NCE </option>';
			$output .= '<option value="3" > Degree </option>';
			
		
			
		}
		else if ($pt == '2')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"> Pre - NCE</option>';
			$output .= '<option value="2" selected > NCE </option>';
			$output .= '<option value="3" > Degree </option>';
			
		
			
		}
		else if ($pt == '3')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"> Pre - NCE</option>';
			$output .= '<option value="2"> NCE </option>';
			$output .= '<option value="3" selected  > Degree </option>';
			
		
			
		}
		else
		{
		
			$output = '<option value="0"  selected > -- Please Select --</option>';
			$output .= '<option value="1"> Pre - NCE</option>';
			$output .= '<option value="2" > NCE </option>';
			$output .= '<option value="3" > Degree </option>';
		
		}

	return $output;

}
//end of select programme_type


//function show programme_type
function show_programme_type($pt)
{
		
		if ($pt == '1')
		{
			$output = 'PRE-NCE';
			
		}
		else if ($pt == '2')
		{
			$output = 'NCE';
		
		}
		else if ($pt == '3')
		{
			$output = 'DEGREE';
		
		}
		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 show study mode
function show_study_mode($pt)
{
		
		if ($pt == '1')
		{
			$output = 'FULL-TIME';
			
		}
		else if ($pt == '2')
		{
			$output = 'PART-TIME';
		
		}
		else if ($pt == '3')
		{
			$output = 'OTHERS';
		
		}
		else
		{
		
			$output = 'NIL';
		
		}

	return $output;

}
//end of show 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="A+"> A+</option>';
			$output .= '<option value="B+"> B+</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="A+"> A+</option>';
			$output .= '<option value="B+"> B+</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="A+" selected> A+</option>';
			$output .= '<option value="B+"> B+</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="A+" > A+</option>';
			$output .= '<option value="B+" selected> 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="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 = mysql_query("SELECT id, title  FROM o_level_subjects  ORDER BY title ");
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_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;

}
//end of select exam grade



	//function to check if user has been inserted before
	function if_student_is_available($id)
	{
		$result = mysql_query("SELECT * FROM applicants_nce_olevel WHERE applicant_id = '$id'");
		
		if(mysql_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)
	{
	    $id = 4;
		$result = mysql_query("SELECT id FROM sessions WHERE id = '$id'"); 
		$row = mysql_fetch_assoc($result);
		$id = $row['id'];
		
	return $id;
	}
	
	
	//Function to fetch  session
	function get_session_title($id)
	{
		$result = mysql_query("SELECT * FROM sessions WHERE id = '$id'"); 
		$row = mysql_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 = mysql_query("SELECT final_submission  FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_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 process, Please 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 = mysql_query("SELECT * FROM applicants_generate_application_number");
	while($row = mysql_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 = mysql_query($q);
	
	if(mysql_num_rows($r)>0)
	{
		$query = "UPDATE assets SET action = '$act', date_added = NOW()";
		mysql_query($query);
	}
	else
	{
	
		$query = "INSERT INTO assets (id, user_id, action, date_added)
				VALUES (NULL, '$user_id', '$act', NOW())";
		mysql_query($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 = mysql_query($q);
	
	$row = mysql_fetch_array($r, MYSQL_ASSOC);
	$at = $row['action'];
	
	return $at;
}





//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'";
		 mysql_query($query);
			
			
			if( $at != '') //if $at not empty then redirect
			{
				header("Location:gateway.php?act=$at");
		 
				
			}
		 
	
	
}



//function select country
function select_country($c)
{
	$r = mysql_query("SELECT id, country_name  FROM countries  ORDER BY country_name ");
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_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 = mysql_query("SELECT  country_name  FROM countries WHERE id = '$c'");
	$row = mysql_fetch_assoc($r);
		
    return $row['country_name'];
		
}
//end of show country_name






//function select state 
function select_state( $state)
{
	$r = mysql_query("SELECT id, title  FROM state  ORDER BY title ");
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			if($state == $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 state


//function show state
function show_state($c)
{
	$r = mysql_query("SELECT  title  FROM state WHERE id = '$c'");
	$row = mysql_fetch_assoc($r);
		
    return $row['title'];
		
}
//end of show state



function select_lga( $lga)
{
	$r = mysql_query("SELECT id, title  FROM lga  ORDER BY title ");
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			if($lga == $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 lga



//function show lga
function show_lga($c)
{
	$r = mysql_query("SELECT  title  FROM lga WHERE id = '$c'");
	$row = mysql_fetch_assoc($r);
		
    return $row['title'];
		
}
//end of show state






//select school
function select_school($department)
{
	$r = mysql_query("SELECT id, title  FROM schools WHERE real_ = '0' ORDER BY title");
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			if($department == $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 department
//select department
function select_department($department)
{
	$r = mysql_query("SELECT id, title  FROM departments WHERE real_ = '0' ORDER BY title");
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			if($department == $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 department




//select programme
function select_programme($p)
{
	$r = mysql_query("SELECT id, title  FROM programmes WHERE real_ = '0' AND type_id = 2 AND mode = 2  ORDER BY title");
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			if($p == $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 programmes



/* ################################# function that generates Transaxfrtion Id for applicants %%%%%%%%%%%%%%%%%%%%%%%%%% */
function generate_transaction_id()
{
	$result = mysql_query("SELECT * FROM generate_transaction_id");
	while($row = mysql_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 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, 2017);
	
	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 = mysql_query("SELECT title FROM programmes WHERE id = '$id'"); 
		$row = mysql_fetch_assoc($result);
		$title = $row['title'];

	return $title;
}
//

//get department name
function get_department_title($id)
{
	$result = mysql_query("SELECT title FROM departments WHERE id = '$id'"); 
	$row = mysql_fetch_assoc($result);
	$title = $row['title'];

	return $title;
}

//get school name
function get_school_title($id)
{
	$result = mysql_query("SELECT title FROM schools WHERE id = '$id'"); 
	$row = mysql_fetch_assoc($result);
	$title = $row['title'];

	return $title;
}




//function that gets  department base on user id
function  get_department_id($user_id)
{	
	$result = mysql_query("SELECT department_id FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_fetch_assoc($result);
		$department_id = $row['department_id'];

	return $department_id;
	
}


//function that gets  school id  base on user id
function  get_school_id($user_id)
{	
	$result = mysql_query("SELECT school_id FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['school_id'];

	return $v;
	
}


//function that gets programme_id base on user id
function  get_programme_id($user_id)
{	
	$result = mysql_query("SELECT programme_id FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_fetch_assoc($result);
		$programme_id = $row['programme_id'];

	return $programme_id;
	
}


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

	return $v;
	
}



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

	return $v;
	
}

//function that gets department id by user id
function  get_dept_id($user_id)
{	
	$result = mysql_query("SELECT department_id FROM applicants_nce WHERE id = '$user_id'"); 
		$row = mysql_fetch_assoc($result);
		$course_id = $row['department_id'];

	return $course_id;
	
}



//function that gets department id by programme
function  get_dept_id_prog_id($id)
{	
	$result = mysql_query("SELECT department_id FROM programmes WHERE id = '$id'"); 
		$row = mysql_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 = mysql_query("SELECT * FROM applicants_nce WHERE id = '$id'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['admission_status'];

		
		
		return $v;		
		
		//return value
		
}
	
	
	//function fetch user programme type
	function get_user_programme_type_admitted_to($id)
	{
		$result = mysql_query("SELECT type_id FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['type_id'];
		
		
		return $v;
	}

//function fetch user school admitted into
	function get_user_school_admitted_to($id)
	{
		$result = mysql_query("SELECT school_id FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['school_id'];
		
		
		return $v;
	}

//function fetch user department admitted into
	function get_user_department_admitted_to($id)
	{
		$result = mysql_query("SELECT department_id FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['department_id'];
		
		
		return $v;
	}

//function fetch user programme admitted into
	function get_user_programme_admitted_to($id)
	{
		$result = mysql_query("SELECT programme_id FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['programme_id'];
		
		
		return $v;
	}
	
	
	//function fetch user programme admission serial no
	function get_user_programme_admission_no($id)
	{
		$result = mysql_query("SELECT admission_serial_no FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['admission_serial_no'];
		
		
		return $v;
	}
	
	
	//get user study mode
	function get_user_study_mode($id)
	{
		$result = mysql_query("SELECT cart_id FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['cart_id'];
		
		
		return $v;
	}
	
	
	//generate applicant admision letter no.
	function generate_applicants_admission_serial_number()
	{
		$result = mysql_query("SELECT * FROM applicants_generate_admission_serial_number");
		while($row = mysql_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_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();
			
			mysql_query("UPDATE applicants_nce  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 = mysql_query("SELECT * FROM semesters WHERE current_session = '$id'"); 
		$row = mysql_fetch_assoc($result);
		$id = $row['id'];
		
	return $id;
	}
	
	
	//Function to fetch  semester
	function get_semester_title($id)
	{
		$result = mysql_query("SELECT * FROM semesters WHERE id = '$id'"); 
		$row = mysql_fetch_assoc($result);
		$title = $row['title'];
		
	return $title;
	}
	
	
	
	//############# recently the pattern to get the infrmation from set fee table is been modified because the application fee is unified payment
	// we temporarily removed the different parameters and changed them to mode (part time or regular)
	
	
	//application fee settings
	//Function to fetch  application_fee title
	function get_application_fee_title($m) //$pt programme type , $d -school , $p -programme id, $s semester
	{
		$result = mysql_query("SELECT title FROM set_application_fee_payments WHERE mode = '$m'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['title'];
		
	return $v;
	}
	
	
	//Function to fetch application_fee desc
	function get_application_fee_desc($m)
	{
		$result = mysql_query("SELECT description FROM set_application_fee_payments WHERE  mode = '$m'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['description'];
		
	return $v;
	}
	
	//Function to fetch  application_fee amount
	function get_application_fee_amount($m)
	{
		$result = mysql_query("SELECT amount FROM set_application_fee_payments WHERE  mode = '$m'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['amount'];
		
	return $v;
	}
	
	
	//Function to fetch  application _fee  total amountamount
	function get_application_fee_total_amount($m)
	{
		$result = mysql_query("SELECT total_amount FROM set_application_fee_payments WHERE mode = '$m'"); 
		$row = mysql_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, $pt, $d, $p) //$pt programme type , $d -school , $p -programme id, $s semester
	{
		$result = mysql_query("SELECT title FROM set_school_fee_payments_for_students_ WHERE level = '$level'  AND programme_type_id = '$pt' AND school_id = '$d' AND programme_id = '$p'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['title'];
		
	return $v;
	}
	
	
	//Function to fetch  school_fee desc
	function get_school_fee_desc($level,  $pt, $d, $p)
	{
		$result = mysql_query("SELECT description FROM set_school_fee_payments_for_students_ WHERE level = '$level'  AND programme_type_id = '$pt' AND school_id = '$d' AND programme_id = '$p'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['description'];
		
	return $v;
	}
	
	//Function to fetch  school_fee amount
	function get_school_fee_amount($level, $pt, $d, $p)
	{
		$result = mysql_query("SELECT amount FROM set_school_fee_payments_for_students_ WHERE level = '$level'  AND programme_type_id = '$pt' AND school_id = '$d' AND programme_id = '$p'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['amount'];
		
	return $v;
	}
	
	
	//Function to fetch  school_fee  total amountamount
	function get_school_fee_total_amount($level, $pt, $d, $p)
	{
		$result = mysql_query("SELECT total_amount FROM set_school_fee_payments_for_students_ WHERE level = '$level'  AND programme_type_id = '$pt' AND school_id = '$d' AND programme_id = '$p'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['total_amount'];
		
	return $v;
	}
	
	//Function to fetch  school_fee  partly amountamount
	function get_school_fee_partly_amount($level, $pt, $d, $p)
	{
		$result = mysql_query("SELECT partly_amount FROM set_school_fee_payments_for_students_ WHERE level = '$level'  AND programme_type_id = '$pt' AND school_id = '$d' AND programme_id = '$p'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['partly_amount'];
		
	return $v;
	}
	
	
	
	
	//Function to fetch  invoice credit
	function get_invoice_credit($total_amount , $amount_paid)
	{
		
		//here i think i interchange ot to be amount paid to be B side while total amount is the A side (A -B)
		
		//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 = mysql_query($q);
		$row = mysql_fetch_array($r,MYSQL_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 = mysql_query($q1);
		
		if(mysql_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 = mysql_query("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 = mysql_query("SELECT title FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['title'];
		
	return $v;
	}
	
	//Function to fetch  invoice type
	function get_invoice_type($iid)
	{
		$result = mysql_query("SELECT invoice_type FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['invoice_type'];
		
	return $v;
	}
	
	
	//Function to fetch date 
	function get_invoice_date($iid)
	{
		$result = mysql_query("SELECT  DATE_FORMAT(date_added, '%b %e, %Y') as date_added FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['date_added'];
		
	return $v;
	}
	
	//Function to fetch due date 
	function get_invoice_due_date($iid)
	{
		$result = mysql_query("SELECT  DATE_FORMAT(due_date, '%b %e, %Y') as due_date FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['due_date'];
		
	return $v;
	}


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

	
	
	//Function to fetch  invoice to
	function get_invoice_invoice_to($iid)
	{
		$result = mysql_query("SELECT invoice_to FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['invoice_to'];
		
	return $v;
	}
	
	
	//Function to fetch  pay to
	function get_invoice_pay_to($iid)
	{
		$result = mysql_query("SELECT pay_to FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['pay_to'];
		
	return $v;
	}
	
		
	//Function to fetch  invocie for 
	function get_invoice_for($iid)
	{
		$result = mysql_query("SELECT invoice_for FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['invoice_for'];
		
	return $v;
	}
	
	
	//Function to fetch descripion
	function get_invoice_desc($iid)
	{
		$result = mysql_query("SELECT description FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['description'];
		
	return $v;
	}



	//Function to fetch amount
	function get_invoice_amount($iid)
	{
		$result = mysql_query("SELECT amount FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['amount'];
		
	return $v;
	}
	
	
	
	//Function to fetch total amount
	function get_invoice_total_amount($iid)
	{
		$result = mysql_query("SELECT total_amount FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['total_amount'];
		
	return $v;
	}
	
	////Function to fetch partly amount
//	function get_invoice_partly_amount($iid)
//	{
//		$result = mysql_query("SELECT partly_amount FROM invoices WHERE invoice_id = '$iid'"); 
//		$row = mysql_fetch_assoc($result);
//		$v = $row['partly_amount'];
//		
//	return $v;
//	}
	
	
	//Function to fetch invoiced credit (credit of invoice generated)
	function get_invoiced_credit($iid)
	{
		$result = mysql_query("SELECT credit FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['credit'];
		
	return $v;
	}
	
	//Function to fetch payment_satus 
	function get_invoice_payment_status($iid)
	{
		$result = mysql_query("SELECT payment_status FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['payment_status'];
		
	return $v;
	}
	
	
	//Function to fetch invoice payment mode
	function get_invoice_payment_mode($iid)
	{
		$result = mysql_query("SELECT payment_mode FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['payment_mode'];
		
	return $v;
	}


//Function to fetch invoice payment programme type asin for which programme nce or deg
	function get_invoice_programme_type($iid)
	{
		$result = mysql_query("SELECT programme_type FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['programme_type'];
		
	return $v;
	}
//show payment mode

//function showpayment mode
function show_payment_mode($r)
{
		
		if ($r == '1')
		{
		
			$output = 'Instalment';
			
		
			
		}
		else if ($r == '2')
		{
			
			$output = 'Full';
		
			
		}
		else
		{
		
			$output = 'Default';
		}

	return $output;

}
//end of show payment mode

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`,`session`, `title`, `description`, `amount`,`total_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 = mysql_query($query);
   
	
	
	if(mysql_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 = mysql_fetch_array($result, MYSQL_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['total_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_invoices3&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,$semester)
	{
		$q = "SELECT student_id,session, payment_status 
			  FROM school_fee_payments_nce  
			  WHERE student_id = '$user_id' 
			  AND session = '$session'
			  AND semester = '$semester' 
			  AND payment_status  = '1'"; 
		$r = mysql_query($q);
		
		//$row = mysql_fetch_assoc($result);
		
		if(mysql_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 =mysql_query($q);
	
	//pass session through SESSION
	  $session = $row['session'];
	 @setcookie('ps',$session,20000, '/');
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	

	//$output ='<ul class="list-group">';
	
		
	
		while($row = mysql_fetch_array($r, MYSQL_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 = mysql_query($query);
	   
		
		
		if(mysql_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 = mysql_fetch_array($result, MYSQL_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 = mysql_query($q);
		//$row = mysql_fetch_assoc($result);
		//$an = $row['transaction_id'];
		
		if(mysql_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 = mysql_query($q);
		//$row = mysql_fetch_assoc($result);
		//$an = $row['transaction_id'];
		
		if(mysql_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 = mysql_query($q);
		//$row = mysql_fetch_assoc($result);
		//$an = $row['transaction_id'];
		
		if(mysql_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 = mysql_query($q);
		//$row = mysql_fetch_assoc($result);
		//$an = $row['transaction_id'];
		
		if(mysql_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 = mysql_query($query);
	   
		
		
		if(mysql_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>Payment Email</th>

	
			  </thead>
			  
			 <!-- <tfoot>
		
			  </tfoot>-->
			  
			  <tbody>';
		
		
			while($row = mysql_fetch_array($result, MYSQL_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 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 = mysql_query("SELECT user_id FROM remita_webpay_transaction_log WHERE transaction_reference = '$oid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['user_id'];
		
	return $v;
	}
	
	//function to get invoice id   using orderID
	function get_invoice_id_using_txnref($oid)
	{
		$result = mysql_query("SELECT invoice_id FROM remita_webpay_transaction_log WHERE transaction_reference = '$oid'"); 
		$row = mysql_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_nce_fee_payments  
		      WHERE applicant_id = '$user_id'"; 
		$r = mysql_query($q);
		
		//$row = mysql_fetch_assoc($result);
		
		if(mysql_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 to check if application or form sales is on // application is on 1
	function get_application_status()
	{
		$result = mysql_query("SELECT * FROM control WHERE id = 1");
		$row = mysql_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 = mysql_query("SELECT applicant_id FROM applicants_nce_fee_payments WHERE applicant_id = '$user_id'"); 
		//$row = mysql_fetch_assoc($result);
		//$an = $row['applicant_id'];
		
		if(mysql_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, school, $programme , level
	function get_total_programme_students($pt, $d, $p, $l)
	{
		$q = "SELECT COUNT(*) FROM students_nce_bu  WHERE   type_id = '$pt' AND school_id = '$d' AND programme_id = '$p' AND level = '$l' AND validity_status = '0'";
		$r = mysql_query($q);
		$row = mysql_fetch_array($r,MYSQL_NUM);
		
		return $row[0];
		
	}
	
	
	
	//function generate matric number
function generate_matric_number($pt, $dep, $p, $level, $total_in_programme)//$dep school
{
	
	//check programme type to know if to give AD or D
		if($pt == '1')
		{
			//$first_letter = 'PN';
		}
		else if($pt == '2')
		{
			
			//this is for NCE get the programme codes for schools
			//$first_letter = 'SE';
			
			//get school code by passing the school id
			$first_letter = strtoupper(get_school_code($dep));
		}
		else if($pt == '3')
		{
			$first_letter = 'U'; //This is for Degree
		}
		else
		{
			//do nothing
			
		}
	
	
	
	
	//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
	$matric_number =	 $first_letter.'/'.$programme_code.'/'.$year.'/'.$total;

	
	
	
	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
	       $mn =  $first_letter.'/'.$programme_code.'/'.$year.'/'; //collect the matric parameters

			//collect all the matric number
			
			
			$q = "SELECT number FROM students_nce_bu WHERE number LIKE '%$mn%'";
			$r = mysql_query($q);
			
			//$row = mysql_fetch_array($r, MYSQL_ASSOC);
			$mmno = array(); //array declared to hold all the matric numbers
			
			if(strlen($programme_code) <= 3)
			{
				$ln = 10;	
			}
			else
			{
				$ln = 14;
			}
				
			
			
			
			while($row = mysql_fetch_array($r, MYSQL_ASSOC))
			{
				
				$number = $row['number']; //collect all the matric numbers and pass to an array
				
				//$lenght
				
				
				
				
				$filtered_no = substr($number, $ln);
				$mmno[] = $filtered_no; //no need to implode
				//$filtered_no = $number[strlen($number) - 4];
				//$mmno[] = $filtered_no;
				
				
			}
			
					//$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
			$matric_numbe = $first_letter.'/'.$programme_code.'/'.$year.'/'.$hn; //pad the matric numbers with the right strings

			
			
			return $matric_numbe;
	
		//}

		
	}
	else
	{
		return $matric_number;
	}
	
	
	//return $matric_number;
	 
}//end of generate matric number for nce direct

	
	//function that gets school code base on course id
	function  get_school_code($id)
	{	
		$result = mysql_query("SELECT code FROM schools WHERE id = '$id'"); 
			$row = mysql_fetch_assoc($result);
			$v = $row['code'];
	
		return $v;
		
	}
	
	
	
	//function that gets programme code base on course id
	function  get_programme_code($id)
	{	
		$result = mysql_query("SELECT code FROM programmes WHERE id = '$id'"); 
			$row = mysql_fetch_assoc($result);
			$code = $row['code'];
	
		return $code;
		
	}
	
	//application number exist
	function application_number_exist($apn, $l)
	{
		$result = mysql_query("SELECT application_number  FROM students_nce_bu WHERE application_number = '$apn' AND level = '$l'"); 
		$row = mysql_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 = mysql_query("SELECT number FROM students_nce_bu WHERE number = '$mno'"); 
		$row = mysql_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_nce  WHERE student_id = '$sid' AND session = '$sess' AND semester = '$sem'";
		$r = mysql_query($q);
		
		
		if(mysql_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, $l)
	{
		$result = mysql_query("SELECT id FROM students_nce_bu WHERE application_number = '$id' AND level = '$l'");
		$row = mysql_fetch_assoc($result);
		$v = $row['id'];
		
		
		return $v;
	}
	
	


?>