<?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;
//	}


//instantiating Config Class
function dbc()
{
	$config = new Config();
	return $config->connect();
}
//cleaning user input and output
function clean_data($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = strip_tags($data);
  $data = htmlspecialchars($data);
  return $data;
}
//sanitizing user input before inserting
function db_escape($dt){
	return  var_export( dbc()->real_escape_string($dt),True);

}





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




//Function to fetch user's Rool
	function get_user_role($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT * FROM summer_students WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$role_id = $row['role_id'];

	return $role_id;
	}

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

	return $last_login_ip;
	}

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

	return $last_login;
	}

//Functions to fetch user's Full name
	function get_user_fullname($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT * FROM summer_students WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$first_name = $row['first_name'];
		$mid_names = $row['middle_name'];
		$other_names = $row['other_names'];

		$user_fullname = $first_name ." ". $mid_names ." " . $other_names;

	return $user_fullname;
	}


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


	return $username;
	}


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


	return $admission_number;
	}

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


	return $v;
	}


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

		  return $department_id;

	  }


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

		  return $department_id;

	  }


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

		  return $programme_id;

	  }



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

		  return $v;

	  }


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

	return $email;
	}


	//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'";
		$r = mysqli_query(dbc(),$q);


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



	}//end of function that chk if student id exist in school fee payments
		//function to get invoice payment to using orderID
	function get_invoice_to_using_txnref($oid)
	{
		$result = mysqli_query(dbc(),"SELECT user_id FROM remita_webpay_transaction_log WHERE transaction_reference = '$oid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['user_id'];

	return $v;
	}

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

	return $v;
	}

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

	return $ph;
	}


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

		return $row['security_id'];


	}


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

	return $v;
	}

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

		return $row['address'];


	}


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

	return $row['image'];


	}

	//function dat get user signature by id
	function get_user_sign($user_id)
	{
	$q = "SELECT sign FROM summer_students WHERE id = '$user_id'";
	$r = mysqli_query(dbc(),$q);
	$row = mysqli_fetch_assoc($r);

	return $row['sign'];


	}





	//function dat get user matric number
	function get_matric_no($user_id)
	{
	$q = "SELECT number FROM summer_students WHERE id = '$user_id' ";
	$r = mysqli_query(dbc(),$q);
	$row = mysqli_fetch_assoc($r);

	return $row['number'];


	}

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

	return $role_title;
	}

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


	return $first_name;
	}

	//Functions to fetch user's other names
	function get_user_other_names($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT other_names FROM summer_students WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$on = $row['other_names'];


	return $on;
	}


	//Functions to fetch user's middle name
	function get_user_middle_name($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT middle_name FROM summer_students WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$on = $row['middle_name'];


	return $on;
	}


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


	return $ms;
	}


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


	return $gd;
	}



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


	return $religion;
	}



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


	return $v;
	}



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

	return $level;
	}



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

		return $day;
	}




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

		return $month;
	}



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

		return $year;
	}



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

		return $year;
	}

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

		return $n;
	}



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

		return $country_id;
	}


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

		return $sid;
	}

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

		return $lid;
	}




	//function get user permanent address

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


		return $v;
	}




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


		return $v;
	}




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


		return $v;
	}


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


		return $v;
	}



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


		return $v;
	}


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


		return $v;
	}


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


		return $v;
	}


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


		return $v;
	}



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


		return $v;
	}

//function fetch user study_mode
	function get_user_study_mode($id)
	{
		$result = mysqli_query(dbc(),"SELECT cart_id FROM summer_students WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['cart_id'];


		return $v;
	}

//function fetch user entry_mode
	function get_user_entry_mode($id)
	{
		$result = mysqli_query(dbc(),"SELECT mode_of_entry FROM summer_students WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['mode_of_entry'];


		return $v;
	}


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


		return $v;
	}


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


		return $v;
	}



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


		return $v;
	}

		//function fetch user get_highest qualififcation
	function get_user_highest_qualification($id)
	{
		$result = mysqli_query(dbc(),"SELECT highest_qualification FROM summer_students WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['highest_qualification'];


		return $v;
	}

		//function fetch user get obtained_institution
	function get_user_institution_obtained($id)
	{
		$result = mysqli_query(dbc(),"SELECT institution_obtained FROM summer_students WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['institution_obtained'];


		return $v;
	}

		//function fetch user get first_degree
	function get_user_first_degree($id)
	{
		$result = mysqli_query(dbc(),"SELECT first_degree FROM summer_students WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['first_degree'];


		return $v;
	}



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

		return $v;
	}



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

		return $v;
	}

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


		return $v;
	}





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

		return $v;
	}


	//function fetch user jamb score
	function get_user_jamb_score($id)
	{
		$result = mysqli_query(dbc(),"SELECT jambscore FROM summer_students WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['jambscore'];

		return $v;
	}



	//function fetch user jamb number
	function get_user_jamb_number($id)
	{
		$result = mysqli_query(dbc(),"SELECT jamb_number FROM summer_students WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['jamb_number'];

		return $v;
	}



	//function fetch user de number
	function get_user_de_number($id)
	{
		$result = mysqli_query(dbc(),"SELECT de_number FROM summer_students WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['de_number'];

		return $v;
	}


	//function fetch user de qualification
	function get_user_de_qualification($id)
	{
		$result = mysqli_query(dbc(),"SELECT de_qualification FROM summer_students WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['de_qualification'];

		return $v;
	}



	//function fetch user de grade
	function get_user_de_grade($id)
	{
		$result = mysqli_query(dbc(),"SELECT de_grade FROM summer_students WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['de_grade'];

		return $v;
	}



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

		return $v;
	}


		//function fetch user minimum credit load
	function get_user_min_credit_load($id)
	{
		$result = mysqli_query(dbc(),"SELECT minimum_credit_load FROM summer_students WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['minimum_credit_load'];

		return $v;
	}


		//function fetch user maximum credit load
	function get_user_max_credit_load($id)
	{
		$result = mysqli_query(dbc(),"SELECT maximum_credit_load FROM summer_students WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['maximum_credit_load'];

		return $v;
	}

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


		return $v;
	}


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

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

			mysqli_query(dbc(),"UPDATE summer_students  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


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

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

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

		$len_g_coded  = strlen($g_coded);

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


		return $code;





	}
	//end of function geerate admission serial no





//function 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 == 'Male')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="Male" selected > Male</option>';
			$output .= '<option value="Female" > Female</option>';


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


		}
		else
		{

			$output = '<option value="0"  selected  > -- Please Select --</option>';
			$output .= '<option value="Male"> Male</option>';
			$output .= '<option value="Female"> 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($sm)
{

		if ($sm == '1')
		{
			$output = 	'Full-Time';


		}
		else if ($sm == '2')
		{
			$output = 	'Part-Time';

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

			$output = 	'Others';

		}

		else
		{

			$output = 	'NIL';

		}

	return $output;

}
//end of show study_mode


//function select entry_mode
function select_entry_mode($sm)
{

		if ($sm == '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"  >Others</option>';



		}
		else if ($sm == '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"  >Others</option>';



		}
		else if ($sm == '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 >Others</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" >Others</option>';

		}

	return $output;

}
//end of select entry_mode



//function show entry_mode
function show_entry_mode($sm)
{

		if ($sm == '1')
		{
			$output  = 	'PRE-NCE';

		}
		else if ($sm == '2')
		{
			$output  = 'NCE-DIRECT';

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

			$output  = 'Others';

		}
		else
		{

			$output = ' NIL';
		}

	return $output;

}
//end of show entry_mode


//function select award_in_view
function select_award_in_view($aiv)
{

		if ($aiv == '1')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .= '<option value="1"  selected  >NCE</option>';
			$output .= '<option value="2"  > N.D </option>';



		}
		else if ($aiv == '2')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .= '<option value="1"    >NCE</option>';
			$output .= '<option value="2" selected >N.D</option>';


		}

		else
		{
			$output = 	'<option value="0"  selected> -- Please Select-- </option>';
			$output .= '<option value="1" >NCE</option>';
			$output .= '<option value="2" >N.D</option>';


		}
	return $output;

}
//end of select award in view


//function show award_in_view
function show_award_in_view($aiv)
{

		if ($aiv == '1')
		{
			$output = 	'NCE';

		}
		else if ($aiv == '2')
		{
			$output = 	'N.D';

		}
		else
		{
			$output = 	'NIL';

		}
	return $output;

}
//end of show award in view



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

		if ($hiq == '1')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'  selected  >Bachelor's Degree</option>";
			$output .= '<option value="2"  >HND</option>';
			$output .= '<option value="3"  >HSG / GCE AL</option>';
			$output .= '<option value="4"  >Masters</option>';
			$output .= '<option value="5"  >NCE</option>';
			$output .= '<option value="6"  >NDA</option>';
			$output .= '<option value="7"  >OND/HND</option>';
			$output .= '<option value="8"  >Others</option>';
			$output .= '<option value="9"  >PGD</option>';
			$output .= '<option value="10"  >PH.d</option>';
			$output .= '<option value="11"  >SSCE (WAEC/NECO/NABTEB)</option>';
			$output .= '<option value="12"  >TCI / ACE</option>';
			$output .= '<option value="13"  >WASC /GCE OL</option>';




		}
		else if ($hiq == '2')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1' >Bachelor's Degree</option>";
			$output .= '<option value="2" selected >HND</option>';
			$output .= '<option value="3"  >HSG / GCE AL</option>';
			$output .= '<option value="4"  >Masters</option>';
			$output .= '<option value="5"  >NCE</option>';
			$output .= '<option value="6"  >NDA</option>';
			$output .= '<option value="7"  >OND/HND</option>';
			$output .= '<option value="8"  >Others</option>';
			$output .= '<option value="9"  >PGD</option>';
			$output .= '<option value="10"  >PH.d</option>';
			$output .= '<option value="11"  >SSCE (WAEC/NECO/NABTEB)</option>';
			$output .= '<option value="12"  >TCI / ACE</option>';
			$output .= '<option value="13"  >WASC /GCE OL</option>';

		}
		else if ($hiq == '3')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>Bachelor's Degree</option>";
			$output .= '<option value="2" >HND</option>';
			$output .= '<option value="3" selected >HSG / GCE AL</option>';
			$output .= '<option value="4" >Masters</option>';
			$output .= '<option value="5" >NCE</option>';
			$output .= '<option value="6" >NDA</option>';
			$output .= '<option value="7" >OND/HND</option>';
			$output .= '<option value="8" >Others</option>';
			$output .= '<option value="9" >PGD</option>';
			$output .= '<option value="10" >PH.d</option>';
			$output .= '<option value="11" >SSCE (WAEC/NECO/NABTEB)</option>';
			$output .= '<option value="12">TCI / ACE</option>';
			$output .= '<option value="13" >WASC /GCE OL</option>';

		}
		else if ($hiq == '4')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>Bachelor's Degree</option>";
			$output .= '<option value="2" >HND</option>';
			$output .= '<option value="3" >HSG / GCE AL</option>';
			$output .= '<option value="4" selected >Masters</option>';
			$output .= '<option value="5" >NCE</option>';
			$output .= '<option value="6" >NDA</option>';
			$output .= '<option value="7" >OND/HND</option>';
			$output .= '<option value="8" >Others</option>';
			$output .= '<option value="9" >PGD</option>';
			$output .= '<option value="10" >PH.d</option>';
			$output .= '<option value="11" >SSCE (WAEC/NECO/NABTEB)</option>';
			$output .= '<option value="12">TCI / ACE</option>';
			$output .= '<option value="13" >WASC /GCE OL</option>';

		}
		else if ($hiq == '5')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>Bachelor's Degree</option>";
			$output .= '<option value="2" >HND</option>';
			$output .= '<option value="3" >HSG / GCE AL</option>';
			$output .= '<option value="4"  >Masters</option>';
			$output .= '<option value="5" selected >NCE</option>';
			$output .= '<option value="6" >NDA</option>';
			$output .= '<option value="7" >OND/HND</option>';
			$output .= '<option value="8" >Others</option>';
			$output .= '<option value="9" >PGD</option>';
			$output .= '<option value="10" >PH.d</option>';
			$output .= '<option value="11" >SSCE (WAEC/NECO/NABTEB)</option>';
			$output .= '<option value="12">TCI / ACE</option>';
			$output .= '<option value="13" >WASC /GCE OL</option>';

		}
		else if ($hiq == '6')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>Bachelor's Degree</option>";
			$output .= '<option value="2" >HND</option>';
			$output .= '<option value="3" >HSG / GCE AL</option>';
			$output .= '<option value="4"  >Masters</option>';
			$output .= '<option value="5"  >NCE</option>';
			$output .= '<option value="6" selected >NDA</option>';
			$output .= '<option value="7" >OND/HND</option>';
			$output .= '<option value="8" >Others</option>';
			$output .= '<option value="9" >PGD</option>';
			$output .= '<option value="10" >PH.d</option>';
			$output .= '<option value="11" >SSCE (WAEC/NECO/NABTEB)</option>';
			$output .= '<option value="12">TCI / ACE</option>';
			$output .= '<option value="13" >WASC /GCE OL</option>';

		}
		else if ($hiq == '7')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>Bachelor's Degree</option>";
			$output .= '<option value="2" >HND</option>';
			$output .= '<option value="3" >HSG / GCE AL</option>';
			$output .= '<option value="4"  >Masters</option>';
			$output .= '<option value="5"  >NCE</option>';
			$output .= '<option value="6" >NDA</option>';
			$output .= '<option value="7" selected >OND/HND</option>';
			$output .= '<option value="8" >Others</option>';
			$output .= '<option value="9" >PGD</option>';
			$output .= '<option value="10" >PH.d</option>';
			$output .= '<option value="11" >SSCE (WAEC/NECO/NABTEB)</option>';
			$output .= '<option value="12">TCI / ACE</option>';
			$output .= '<option value="13" >WASC /GCE OL</option>';

		}
		else if ($hiq == '8')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>Bachelor's Degree</option>";
			$output .= '<option value="2" >HND</option>';
			$output .= '<option value="3" >HSG / GCE AL</option>';
			$output .= '<option value="4"  >Masters</option>';
			$output .= '<option value="5"  >NCE</option>';
			$output .= '<option value="6" >NDA</option>';
			$output .= '<option value="7">OND/HND</option>';
			$output .= '<option value="8"   selected >Others</option>';
			$output .= '<option value="9" >PGD</option>';
			$output .= '<option value="10" >PH.d</option>';
			$output .= '<option value="11" >SSCE (WAEC/NECO/NABTEB)</option>';
			$output .= '<option value="12">TCI / ACE</option>';
			$output .= '<option value="13" >WASC /GCE OL</option>';

		}
		else if ($hiq == '9')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>Bachelor's Degree</option>";
			$output .= '<option value="2" >HND</option>';
			$output .= '<option value="3" >HSG / GCE AL</option>';
			$output .= '<option value="4"  >Masters</option>';
			$output .= '<option value="5"  >NCE</option>';
			$output .= '<option value="6" >NDA</option>';
			$output .= '<option value="7">OND/HND</option>';
			$output .= '<option value="8">Others</option>';
			$output .= '<option value="9"  selected >PGD</option>';
			$output .= '<option value="10" >PH.d</option>';
			$output .= '<option value="11" >SSCE (WAEC/NECO/NABTEB)</option>';
			$output .= '<option value="12">TCI / ACE</option>';
			$output .= '<option value="13" >WASC /GCE OL</option>';

		}
		else if ($hiq == '10')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>Bachelor's Degree</option>";
			$output .= '<option value="2" >HND</option>';
			$output .= '<option value="3" >HSG / GCE AL</option>';
			$output .= '<option value="4"  >Masters</option>';
			$output .= '<option value="5"  >NCE</option>';
			$output .= '<option value="6" >NDA</option>';
			$output .= '<option value="7">OND/HND</option>';
			$output .= '<option value="8">Others</option>';
			$output .= '<option value="9" >PGD</option>';
			$output .= '<option value="10"  selected  >PH.d</option>';
			$output .= '<option value="11" >SSCE (WAEC/NECO/NABTEB)</option>';
			$output .= '<option value="12">TCI / ACE</option>';
			$output .= '<option value="13" >WASC /GCE OL</option>';

		}
		else if ($hiq == '11')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>Bachelor's Degree</option>";
			$output .= '<option value="2" >HND</option>';
			$output .= '<option value="3" >HSG / GCE AL</option>';
			$output .= '<option value="4"  >Masters</option>';
			$output .= '<option value="5"  >NCE</option>';
			$output .= '<option value="6" >NDA</option>';
			$output .= '<option value="7">OND/HND</option>';
			$output .= '<option value="8">Others</option>';
			$output .= '<option value="9" >PGD</option>';
			$output .= '<option value="10" >PH.d</option>';
			$output .= '<option value="11"   selected >SSCE (WAEC/NECO/NABTEB)</option>';
			$output .= '<option value="12">TCI / ACE</option>';
			$output .= '<option value="13" >WASC /GCE OL</option>';

		}
		else if ($hiq == '12')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>Bachelor's Degree</option>";
			$output .= '<option value="2" >HND</option>';
			$output .= '<option value="3" >HSG / GCE AL</option>';
			$output .= '<option value="4"  >Masters</option>';
			$output .= '<option value="5"  >NCE</option>';
			$output .= '<option value="6" >NDA</option>';
			$output .= '<option value="7">OND/HND</option>';
			$output .= '<option value="8">Others</option>';
			$output .= '<option value="9" >PGD</option>';
			$output .= '<option value="10" >PH.d</option>';
			$output .= '<option value="11" >SSCE (WAEC/NECO/NABTEB)</option>';
			$output .= '<option value="12" selected>TCI / ACE</option>';
			$output .= '<option value="13" >WASC /GCE OL</option>';

		}
		else if ($hiq == '13')
		{
			$output = 	'<option value="0"> -- Please Select-- </option>';
			$output .=  "<option value='1'>Bachelor's Degree</option>";
			$output .= '<option value="2" >HND</option>';
			$output .= '<option value="3" >HSG / GCE AL</option>';
			$output .= '<option value="4"  >Masters</option>';
			$output .= '<option value="5"  >NCE</option>';
			$output .= '<option value="6" >NDA</option>';
			$output .= '<option value="7">OND/HND</option>';
			$output .= '<option value="8">Others</option>';
			$output .= '<option value="9" >PGD</option>';
			$output .= '<option value="10" >PH.d</option>';
			$output .= '<option value="11" >SSCE (WAEC/NECO/NABTEB)</option>';
			$output .= '<option value="12">TCI / ACE</option>';
			$output .= '<option value="13"  selected>WASC /GCE OL</option>';

		}
		else
		{
			$output = 	'<option value="0"   selected> -- Please Select-- </option>';
			$output .=  "<option value='1'>Bachelor's Degree</option>";
			$output .= '<option value="2" >HND</option>';
			$output .= '<option value="3" >HSG / GCE AL</option>';
			$output .= '<option value="4"  >Masters</option>';
			$output .= '<option value="5"  >NCE</option>';
			$output .= '<option value="6" >NDA</option>';
			$output .= '<option value="7">OND/HND</option>';
			$output .= '<option value="8">Others</option>';
			$output .= '<option value="9" >PGD</option>';
			$output .= '<option value="10" >PH.d</option>';
			$output .= '<option value="11" >SSCE (WAEC/NECO/NABTEB)</option>';
			$output .= '<option value="12">TCI / ACE</option>';
			$output .= '<option value="13">WASC /GCE OL</option>';


		}
	return $output;

}
//end of select highest

//function show  highest qualification
function show_highest_qualification($hiq)
{

		if ($hiq == '1')
		{
			$output = 	"Bachelor's Degree";


		}
		else if ($hiq == '2')
		{
			$output = 	'HND';

		}
		else if ($hiq == '3')
		{
			$output = 	'HSG / GCE AL';

		}
		else if ($hiq == '4')
		{
			$output = 	'Masters';

		}
		else if ($hiq == '5')
		{
			$output = 	'NCE';

		}
		else if ($hiq == '6')
		{
			$output = 	'NDA';

		}
		else if ($hiq == '7')
		{
			$output = 	'OND/HND';

		}
		else if ($hiq == '8')
		{
			$output = 	'Others';

		}
		else if ($hiq == '9')
		{
			$output = 	'PGD';

		}
		else if ($hiq == '10')
		{
			$output = 	'PH.d';

		}
		else if ($hiq == '11')
		{
			$output = 	'SSCE (WAEC/NECO/NABTEB)';

		}
		else if ($hiq == '12')
		{
			$output = 	'TCI / ACE';

		}
		else if ($hiq == '13')
		{
			$output = 	'WASC /GCE OL';

		}
		else
		{
			$output = 	'NIL';


		}
	return $output;

}
//end of show highest qualification



//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 = mysqli_query(dbc(),"SELECT id, title  FROM o_level_subjects  ORDER BY title ");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			if($c == $row['id'])
			{
				$output = "<option value=\"$row[id]\" selected>";
				$output .=  $row['title'];
				$output .="</option>";

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

			}


			echo $output;
		}
	}
	else
	{

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

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


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

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


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

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

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

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

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

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

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

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


		}
	return $output;

}
//end of select exam month



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

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






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

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

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

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

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

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

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

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

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

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


		}
	return $output;

}
//end of select exam grade








	//Function to fetch current session
	function get_current_session($id)
	{

		//$result = mysqli_query(dbc(),"SELECT * FROM sessions WHERE current_session = '$id'");
		$result = mysqli_query(dbc(),"SELECT * FROM sessions WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$id = $row['id'];

	  $id = 6;

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

		$id = 6;

	return $id;
	}


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

	return $title;
	}



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

	return $id;
	}


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

	return $title;
	}




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

	return $v;
	}


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

	return $v;
	}

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

	return $v;
	}


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

	return $v;
	}





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

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



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

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

		 $v = $credit;

	    return $v;
	}



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


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

		return $row[0];

	}


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

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


	}




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

		$total_num = get_total_num_invoices();


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


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

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

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

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

		}




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

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



	}//end of generate invoice id





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

	return $v;
	}

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

	return $v;
	}



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

	return $v;
	}



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

	return $v;
	}


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

	return $v;
	}



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

	return $v;
	}


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

	return $v;
	}


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

	return $v;
	}


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

	return $v;
	}



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

	return $v;
	}



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

	return $v;
	}


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

	return $v;
	}

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

	return $v;
	}


	//function view invoices
function view_invoices($user_id, $type, $session)
{

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

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


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



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


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

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



		  </thead>

		 <!-- <tfoot>




		  </tfoot>-->

		  <tbody>';


		while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$row['invoice_id']."</td>"; //group belong to admin or user
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['due_date']."</td>";
			$output .= "<td>".payment_status($row['payment_status'])."</td>";
			$output .= '<td><a class="btn btn-default" href="dashboard.php?act=view_invoices4&qlk='.md5(2).'&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 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>';
		}
	}


//remita processing starts here
	function generate_remita_txn_ref()
	{

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

		return $tid;
	}

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

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

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


		}
		else
		{
			return false;


		}

	}//end of if tid exist



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

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

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


		}
		else
		{
			return false;


		}

	}
	//end of remita trf exist

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

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

		  FROM `remita_webpay_transaction_log`

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


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



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


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

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


			  </thead>

			 <!-- <tfoot>

			  </tfoot>-->

			  <tbody>';


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

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

				$output .= "<td>".$row['transaction_date']."</td>";
				$output .= "<td>".transaction_status($row['payment_status'])."</td>";
				//$output .= '<td><a href="" class="btn btn-primary" > Re query </a></td>';
				//$output .= "<td>".$row['email']."</td>";
				$output .= '<td>'.transaction_status_for_log($row['payment_status'],$row['transaction_reference'],$row['transaction_type']).'</td>';




				$output .= "</tr>";

			}
		}
		else
		{//show the msg

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


		}



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





		return $output;






	}//end of view transaction log for remita



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

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

	FROM `remita_webpay_transaction_log`

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


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



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


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

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


		</thead>

	 <!-- <tfoot>

		</tfoot>-->

		<tbody>';


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

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

		$output .= "<td>".$row['transaction_date']."</td>";
	    $pay_stat = 0;
		//really paid with out any db input failure
		if($stat){
			$pay_stat = $row['payment_status'];
		}
		
		$output .= "<td>".transaction_status($pay_stat)."</td>";
		$output .= '<td>'.transaction_status_for_log($pay_stat,$row['transaction_reference'],$row['transaction_type']).'</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 transaction status
	function transaction_status($id)
	{
		if($id == '1')
		{
			return '<label class="label label-success"> SUCCESSFUL </label>';
		}
		else
		{
			return  '<label class="label label-danger"> PENDING </label>';
		}
	}


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


				}
				else
				{
					 return  '<a class="btn btn-sm  btn-danger" href="dashboard.php?act=check_trxn_status&txnref='.$tref.'" class="btn btn-primary" > Re-query </a>';

				}//end of elese o

			}
		}


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

		//$row = mysqli_fetch_assoc($result);

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

		}
		else
		{
			return true;
		}

	}




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

			//$row = mysqli_fetch_assoc($result);

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

			}
			else
			{
				return true;
			}

		}


//function show school fee payment status, by session
function show_school_fee_payment($user_id, $sess, $sem)
{
	$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_nce WHERE student_id = '$user_id'  AND session = '$sess' AND semester = '$sem'";
	$r =mysqli_query(dbc(),$q);

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

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



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



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

			//$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['user_id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
			$output .= "<li class='list-group-item'>You have paid schoolfee for this Semester, ".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 show school fee payment status, by session
function show_school_fee_payment_by_session($user_id, $sess)
{
	$q = "SELECT `id`, `student_id`,  `session`, `payment_status`, `payment_mode`,`payment_method`, DATE_FORMAT(date_added, '%M %e, %Y / %l:%i:%p') as date_added
		 FROM summer_school_fee_payments_nce WHERE student_id = '$user_id'  AND session = '$sess'";
	$r =mysqli_query(dbc(),$q);

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

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



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



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

			//$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['user_id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
			$output .= "<li class='list-group-item'> You have paid school fee for  ".get_session_title($row['session'])." Academic Session</li>";
			$output .= "<li class='list-group-item'><span class='label label-success'> Date / time of payment: </span> ".$row['date_added']."</li>";
			$output .= "<li class='list-group-item'><span class='label label-info'> Payment Mode: </span>".show_payment_mode($row['payment_mode'])."</li>";
			$output .= "<li class='list-group-item'><span class='label label-warning'> Payment Mode: </span>".show_payment_method($row['payment_method'])."</li>";


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


			$output .= '&nbsp;&nbsp;&nbsp;<a class="btn btn-success"  href="create_sf_payment_slip.php?me='.$user_id.'&s='.$sess.'&myid='.md5('fuckusha1sha1').'."   data-toggle="tooltip" data-placement="top" title="Download / Print  "> DOWNLOAD / PRINT RECEIPT </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 to show information for school fee payment



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

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

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



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



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

			//$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['user_id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
			$output .= "<li class='list-group-item'> You have paid App fee for  ".get_session_title($row['session'])." Academic Session</li>";
			$output .= "<li class='list-group-item'><span class='label label-success'> Date / time of payment: </span> ".$row['date_added']."</li>";
			// $output .= "<li class='list-group-item'><span class='label label-info'> Payment Mode: </span>".show_payment_mode($row['payment_mode'])."</li>";
			// $output .= "<li class='list-group-item'><span class='label label-warning'> Payment Mode: </span>".show_payment_method($row['payment_method'])."</li>";


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


			$output .= '&nbsp;&nbsp;&nbsp;<a class="btn btn-success"  href="create_sm_payment_slip.php?me='.$user_id.'&s='.$sess.'&myid='.md5('fuckusha1sha1').'."   data-toggle="tooltip" data-placement="top" title="Download / Print  "> DOWNLOAD / PRINT RECEIPT </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 to show information for school fee payment


//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 showpayment method
	function show_payment_method($r)
	{

			if ($r == '1')
			{

				$output = 'Remita - Card Payment';



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

				$output = 'Remita - Bank Branch';


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

				//$output = 'COEMX MFB';
				$output = 'Default';


			}
			else
			{

				$output = 'Default';
			}

		return $output;

	}
	//end of show payment method



    //payment status
    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 if he has done registration in  a current session
	function has_done_registration($user_id, $session, $semester)
	{
		$q = "SELECT student_id, session_id FROM summer_students_courses_nce  WHERE student_id = '$user_id' AND session_id = '$session'";
		$r = mysqli_query(dbc(),$q);

		//$row = mysqli_fetch_assoc($result);

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

		}
		else
		{
			return true;
		}

	}





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


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

	}
	else
	{
		$carts = pre_check_courses($student = get_user_id(),$level,$semester, $session = get_current_session('1'));

	}








	//comment incase
	//DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
	//	 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
	//query the database
	$q = "SELECT c.id as cid, c.title, c.course_description, c.programme_id, c.department_id, c.code, c.unit, c.level, c.semester, c.course_type,
		 c.course_description, pc.department_id AS pc_did, pc.school_id AS pc_sid,
		  pc.programme_id AS pc_pid, pc.course_id AS pc_cid, pc.seen_as_elective, pc.session_id, pc.semester AS pc_semester, pc.level AS pc_level, pc.programme_type_id, pc.status
		  FROM courses c, programmes_courses_nce pc
		  WHERE c.semester = '$semester'
		  AND pc.course_id = c.id
		  AND pc.programme_id = '$programme'

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

		  GROUP BY c.id
		  ORDER BY  pc.seen_as_elective ASC, c.code ASC"; //AND pc.level = '$level'

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


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


			</thead>
		  <tbody>';

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


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





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


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

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

			}


			$output .= "</tr>";


		}

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

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


	}



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





	return $output;


}//end of function



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


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

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


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


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

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

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

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

	    $output = '';

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

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

				}


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



		return $new_courses;

}

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

	return $summed_up;
}

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







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

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


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

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

  }



} // end of browser / platform filter



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

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

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


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

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

	return $at;
}





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


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

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


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


			}



}



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

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

			}


			echo $output;
		}
	}
	else
	{

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

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




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

    return $row['country_name'];

}
//end of show country_name






//function select state
function select_state( $state)
{
	$r = mysqli_query(dbc(),"SELECT id, title  FROM state  ORDER BY title ");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r, MYSQLI_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 = mysqli_query(dbc(),"SELECT  title  FROM state WHERE id = '$c'");
	$row = mysqli_fetch_assoc($r);

    return $row['title'];

}
//end of show state



function select_lga( $lga)
{
	$r = mysqli_query(dbc(),"SELECT id, title  FROM lga  ORDER BY title ");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r, MYSQLI_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 = mysqli_query(dbc(),"SELECT  title  FROM lga WHERE id = '$c'");
	$row = mysqli_fetch_assoc($r);

    return $row['title'];

}
//end of show state


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

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

			}


			echo $output;
		}
	}
	else
	{

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

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




//select department
function select_department($department)
{
	$r = mysqli_query(dbc(),"SELECT id, title  FROM departments  ORDER BY title");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r, MYSQLI_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 = mysqli_query(dbc(),"SELECT id, title  FROM programmes  ORDER BY title");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r, MYSQLI_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 = mysqli_query(dbc(),"SELECT * FROM generate_transaction_id");
	while($row = mysqli_fetch_array($result))
	{
		$g_code = $row['code'];
	}

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

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


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

	return $tid;
}

/* end of function that generates transaction id */


//function calendar year
function year($y)
{
	$y = $y;
	$years = range(2015, date('Y') - 5);

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


}//end of year


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

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


}




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

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


}


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

	return $title;
}
//

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

	return $title;
}


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

	return $title;
}



//get departmet id base on user id

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

	return $v;

}






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

	return $v;

}



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

	return $v;

}

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

	return $course_id;

}

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


	return $title;
	}


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


	return $title;
	}



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


	return $unit;
	}


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


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


	return $course_category;
	}

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


	return $semester;
	}


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


	return $level;
	}




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


	return $v;
	}

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


	return $token;
	}







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

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


	}

	//function to check if school_resgistration status  1
	function get_school_registration_status()
	{
		$result = mysqli_query(dbc(),"SELECT * FROM control WHERE id = '2'");
		$row = mysqli_fetch_assoc($result);
		$status = $row['status'];


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

	//function to check if school fee payment is on 1
	function get_school_fee_status()
	{
		$result = mysqli_query(dbc(),"SELECT * FROM control WHERE id = 3");
		$row = mysqli_fetch_assoc($result);
		$status = $row['status'];


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


// function that check if a user has registered election for election before
	function check_election_interest($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT election_interest  FROM summer_students WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$status = $row['election_interest'];

		if($status == '0')
		{

			return '<div class="hide_me"><input  style="height:10px; width:10px; box-shadow:#060 0 0 2px" type="checkbox"  name="agreement" value="yes" id="checkbox-id" data-toggle="tooltip" title="Click on the checkbox to agree"/ > &nbsp; Yes, I agree

				    <br>
					<input class="btn btn-success btn-md pull-right" value="Register..." type="submit" id="save_election_interest" data-toggle="tooltip" title="Click here to register"/></div>';



		}
		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 been registered to be part of this year\'s election .
					We will keep you posted on when to log back to print  your username and password. Thank You

					<br>


					<p>If yo do not want to participate any more, click on the <b>"De - Register.."</b> buttton below </p>
					</div>


					<br>
					<input class="btn btn-success btn-md pull-right" value="De - Register ..." type="submit" id="de_save_election_interest" />
					</div>';


		}


	}
	//end of election interest buttons checking



// function that check if a user has applied for hostel before
	function check_hostel_application($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT hostel_interest  FROM summer_students WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$status = $row['hostel_interest'];

		if($status == '0')  //if 0 u can apply
		{

			return '<div class="hide_me">
					 <input class="btn btn-success btn-md" value="Click here to apply for hostel bed space" type="submit" id="apply_hostel" data-toggle="tooltip" title="Click here to apply for hostel"  /> <img src="images/loader.gif" id="loader_gif" />
					  </div>';



		}
		else if($status == '1')
		{
			return '<div class="hide_me">
					 <input class="btn btn-success btn-md" value="You have already applied for hostel bed space" type="submit" data-toggle="tooltip" title="You have already applied for hostel bed space"  disabled="disabled" />
					  </div>';


		}
		else if($status == '2')
		{
			return '<div class="hide_me alert alert-success">
					  <i class="glyphicon glyphicon-ok"></i> Your hostel application has been approved, please click on the payment tab menu and pay hostel fee to get a bed space
					  </div>';


		}
		else
		{
			//do nothing for now
		}

	}
	//end of go live buttons checking
	//
	//



//function to start with result and other queries


	//show grade base on score of ca and exam score
//GetColour code for current project completion status
function get_student_grade_by_score($total_score)
{
	//$total_score = $ca_score + $exam_score;


		if($total_score >= "70")
		{
		  $grade = 'A';
		}
		if($total_score >= "60" && $total_score <= "69")
		{
		  $grade = 'B';
		}
		if($total_score >= "50" && $total_score <= "59"){
	  $grade = 'C';
	  }
	  if($total_score >= "45" && $total_score <= "49"){
	  $grade = 'D';
	  }
	  if($total_score >= "40" && $total_score <= "44"){
	  $grade = 'E';
	  }
	  if($total_score >= "0" && $total_score <= "39"){
	  $grade = 'F';
	  }

	return $grade;
}	//end of get student grade by scores



//GetColour code for grade by passing grade
function get_grade_color($grade)
{
	if($grade == 'A')
	{
	  $color = "text-success";
	}
	if($grade == 'B')
	{
	  $color = "text-primary";
	}
	if($grade == 'C')
	{
	  $color = "text-info";
	}
	if($grade == 'D')
	{
	  $color = "text-warning";
	}
	if($grade == 'E')
	{
	  $color = "text-default";
	}
	if($grade == 'F')
	{
	  $color = "text-danger";
	}

	return $color;
}



//GetColour code for current get grade point score
function get_student_grade_point_score($total_score)
{
	//$total_score = $ca_score + $exam_score;


	if($total_score >= 70){
	  $gp = 5;
	  }
	if($total_score >= 60 && $total_score <= 69){
	  $gp = 4;
	  }
	  if($total_score >= 50 && $total_score <= 59){
	  $gp = 3;
	  }
	  if($total_score >= 45 && $total_score <= 49){
	  $gp = 2;
	  }
	  if($total_score >= 40 && $total_score <= 44){
	  $gp = 1;
	  }
	  if($total_score >= 0 && $total_score <= 39){
	  $gp = 0;
	  }

	return $gp;
}	//end of get student gp by scores



//All these codes might have to change becuase hence we might have to keep present tcur and previous separately aside from cummulative

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


return $v;
}


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


	return $v;
}


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


	return $v;
}




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


return $v;
}


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

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

			//initialise
			//$total_grade_point = 0;

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

		 $total_grade_point2 += $total_grade_point;

	}


	return  $total_grade_point2;
}


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


	return $v;
}





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


return $v;
}


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

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


	return $v;
}


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


	return $v;
}


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


return $v;
}


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

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

	// 		//initialise
	// 		//$total_grade_point = 0;

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

	// 	 $total_grade_point2 += $total_grade_point;

	// }

	//get total gradepoint earned divide by tcur registered



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

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



	@$current_gpa =  $tgp_earned_cummulativeo / $tcur_cummulativeo;

	return  number_format($current_gpa,2);
}


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


	return $v;
}


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



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


 			$v = $row['remark1'];



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

			    }



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


			      $o1[] = get_course_code($item);

			    }

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





		    return $o;


}



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





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


			$v = $row['remark2'];

		    return $v;




}



//function fetch validity status
	function get_user_validity_status($id)
	{
		$result = mysqli_query(dbc(),"SELECT validity_status FROM summer_students WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$n = $row['validity_status'];

		return $n;
	}


	//function to check whether result is published or not
	function check_results_published($student, $session, $semester)
	{





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


				$v = $row['status'];



				if($v == '0')
				{
					return true;
				}
				else
				{
					return false;
				}




	}



?>
