<?php

ob_start();
include ('../db_connect/db.php');
//get department name
function dbc()
{
    global $conn_1;

    return $conn_1;
}

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 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 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 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 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 amount
//function get_invoice_late_amount($iid)
/*{

    $result = mysqli_query(dbc(), "SELECT late_payment FROM invoices WHERE invoice_id = '$iid'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['late_payment'];

    if ($v != null) {
        return $v;
    } else {
        return 0;
    }
}*/

//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 get_user_gender($user_id)
{

    $result = mysqli_query(dbc(), "SELECT gender FROM students_nce WHERE id = '$user_id'");
    $row = mysqli_fetch_assoc($result);
    $gd = $row['gender'];

    return $gd;
}

//Functions to fetch user's religion
function get_user_religion($user_id)
{

    $result = mysqli_query(dbc(), "SELECT religion FROM students_nce WHERE id = '$user_id'");
    $row = mysqli_fetch_assoc($result);
    $religion = $row['religion'];

    return $religion;
}

function show_nationality($n)
{

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

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

    } else {

        $output = 'NIL';
    }

    return $output;

}

function get_user_nationality($id)
{

    $result = mysqli_query(dbc(), "SELECT nationality FROM students_nce 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 students_nce WHERE id = '$id'");
    $row = mysqli_fetch_assoc($result);
    $country_id = $row['country_id'];

    return $country_id;
}

function show_lga($c)
{

    $r = mysqli_query(dbc(), "SELECT  title  FROM lga WHERE id = '$c'");
    $row = mysqli_fetch_assoc($r);

    return $row['title'];

}

//function that gets programme_id base on user id
function get_user_programme_id($user_id)
{

    $result = mysqli_query(dbc(), "SELECT programme_id FROM hostel_students WHERE id = '$user_id'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['programme_id'];

    return $v;

}

//function that gets programme_id base on user id // THIS WAS CREATED IN OTHER TO SOLVE THE ISSUE OF HAVING TO MIGRATE TO NEXT LEVEL WITH DIFFERENT PROGRAMME IDS
function get_user_actual_programme_id($user_id)
{

    $result = mysqli_query(dbc(), "SELECT actual_programme_id FROM students_nce WHERE id = '$user_id'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['actual_programme_id'];

    return $v;

}

//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 students_nce 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 hostel_students WHERE id = '$user_id'");
    $row = mysqli_fetch_assoc($result);
    $email = $row['email'];

    return $email;
}

//Function to fetch phone number
function get_user_phone_no($user_id)
{

    $result = mysqli_query(dbc(), "SELECT phone_no FROM hostel_students WHERE id = '$user_id'");
    $row = mysqli_fetch_assoc($result);
    $ph = $row['phone_no'];

    return $ph;
}

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

}

//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'];

}

//Functions to fetch user's place of birth
function get_user_pob($user_id)
{

    $result = mysqli_query(dbc(), "SELECT place_of_birth FROM students_nce WHERE id = '$user_id'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['place_of_birth'];

    return $v;
}

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 get_user_mat_no($user_id)
{

    $result = mysqli_query(dbc(), "SELECT number FROM hostel_students WHERE id = '$user_id'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['number'];

    return $v;
}

//function get user sponsorhip type
function get_user_sponsorship_type($id)
{

    $result = mysqli_query(dbc(), "SELECT sponsorship_type FROM students_nce 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 students_nce WHERE id = '$id'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['sponsorship_name'];

    return $v;
}

function get_user_permanent_address($id)
{

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

    return $v;
}

//function get user sponsorhip address
function get_user_sponsorship_address($id)
{

    $result = mysqli_query(dbc(), "SELECT sponsorship_address FROM students_nce WHERE id = '$id'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['sponsorship_address'];

    return $v;
}

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

function get_user_image($user_id)
{

    $q = "SELECT image FROM students_nce WHERE id = '$user_id'";
    $r = mysqli_query(dbc(), $q);
    $row = mysqli_fetch_assoc($r);

    return $row['image'];

}

//Function to fetch matric number
	function get_student_matric_no_prence($conn_1, $user_id)
	{

		$result = mysqli_query($conn_1,"SELECT number FROM students_prence WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['number'];


	return $v;
	}
	
//Function to fetch matric number
	function get_student_matric_no($conn_1, $user_id)
	{

		$result = mysqli_query($conn_1,"SELECT number FROM hostel_students WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['number'];


	return $v;
	}
	
//Function to fetch matric number
	function get_student_matric_no_duap($conn_2, $user_id)
	{

		$result = mysqli_query($conn_2,"SELECT number FROM students_nce WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['number'];


	return $v;
	}
	
//Function to fetch matric number
	function get_student_matric_no_summer($conn_1, $user_id)
	{

		$result = mysqli_query($conn_1,"SELECT number FROM summer_students WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['number'];


	return $v;
	}
	
//Function to fetch matric number
	function get_student_matric_no_lvsp($conn_1, $user_id)
	{

		$result = mysqli_query($conn_1,"SELECT number FROM students_nce WHERE id = '$user_id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['number'];


	return $v;
	}


//Function to fetch student id
	function get_student_id_prence($conn_1, $mat)
	{

		$result = mysqli_query($conn_1,"SELECT id FROM students_prence WHERE number = '$mat'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['id'];


	return $v;
	}
	
//Function to fetch student id
	function get_student_id_nce($conn_1, $mat)
	{

		$result = mysqli_query($conn_1,"SELECT id FROM students_nce WHERE number = '$mat'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['id'];


	return $v;
	}
	
//Function to fetch student id
	function get_student_id_duap($conn_2, $mat)
	{

		$result = mysqli_query($conn_2,"SELECT id FROM students_nce WHERE number = '$mat'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['id'];


	return $v;
	}
	
//Function to fetch student id
	function get_student_id_summer($conn_1, $mat)
	{

		$result = mysqli_query($conn_1,"SELECT id FROM summer_students WHERE number = '$mat'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['id'];


	return $v;
	}
	
//Function to fetch student id
	function get_student_id_lvsp($conn_1, $mat)
	{

		$result = mysqli_query($conn_1,"SELECT id FROM students_nce WHERE number = '$mat'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['id'];


	return $v;
	}


function get_user_department_id($user_id)
{

    $result = mysqli_query(dbc(), "SELECT department_id FROM hostel_students WHERE id = '$user_id'");
    $row = mysqli_fetch_assoc($result);
    $department_id = $row['department_id'];

    return $department_id;

}

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

function show_programme_type($pt)
{

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

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

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

    } else {

        $output = 'NIL';

    }

    return $output;

}

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

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

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

    } else {

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

    return $output;

}
//end of select gender

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

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

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

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

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

    } else {

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

    return $output;

}
//end of select religion

//function 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 marital status
function select_credential_status($st)
{

    if ($st == 'waec') {
        $output = '<option value="0" > -- Please Select --</option>';
        $output .= '<option value="waec" selected > WAEC</option>';
        $output .= '<option value="neco" > NECO</option>';
        $output .= '<option value="nd" >ND</option>';
        $output .= '<option value="nce" >NCE</option>';
        $output .= '<option value="hnd" >HND</option>';
        $output .= '<option value="bsc" >BSC</option>';
        $output .= '<option value="msc" >MSC</option>';
        $output .= '<option value="mphil" >MPHIL</option>';

    } else if ($st == 'neco') {
        $output = '<option value="0" > -- Please Select --</option>';
        $output .= '<option value="waec"  > WAEC</option>';
        $output .= '<option value="neco" selected> NECO</option>';
        $output .= '<option value="nd" >ND</option>';
        $output .= '<option value="nce" >NCE</option>';
        $output .= '<option value="hnd" >HND</option>';
        $output .= '<option value="bsc" >BSC</option>';
        $output .= '<option value="msc" >MSC</option>';
        $output .= '<option value="mphil" >MPHIL</option>';

    } else if ($st == 'nd') {
        $output = '<option value="0" > -- Please Select --</option>';
        $output .= '<option value="waec"  > WAEC</option>';
        $output .= '<option value="neco" > NECO</option>';
        $output .= '<option value="nd" selected>ND</option>';
        $output .= '<option value="nce" >NCE</option>';
        $output .= '<option value="hnd" >HND</option>';
        $output .= '<option value="bsc" >BSC</option>';
        $output .= '<option value="msc" >MSC</option>';
        $output .= '<option value="mphil" >MPHIL</option>';

    } else if ($st == 'nce') {
        $output = '<option value="0" > -- Please Select --</option>';
        $output .= '<option value="waec"  > WAEC</option>';
        $output .= '<option value="neco" > NECO</option>';
        $output .= '<option value="nd" >ND</option>';
        $output .= '<option value="nce" selected>NCE</option>';
        $output .= '<option value="hnd" >HND</option>';
        $output .= '<option value="bsc" >BSC</option>';
        $output .= '<option value="msc" >MSC</option>';
        $output .= '<option value="mphil" >MPHIL</option>';

    } else if ($st == 'hnd') {
        $output = '<option value="0" > -- Please Select --</option>';
        $output .= '<option value="waec"  > WAEC</option>';
        $output .= '<option value="neco" > NECO</option>';
        $output .= '<option value="nd" >ND</option>';
        $output .= '<option value="nce" >NCE</option>';
        $output .= '<option value="hnd" selected>HND</option>';
        $output .= '<option value="bsc" >BSC</option>';
        $output .= '<option value="msc" >MSC</option>';
        $output .= '<option value="mphil" >MPHIL</option>';

    } else if ($st == 'bsc') {
        $output = '<option value="0" > -- Please Select --</option>';
        $output .= '<option value="waec"  > WAEC</option>';
        $output .= '<option value="neco" > NECO</option>';
        $output .= '<option value="nd" >ND</option>';
        $output .= '<option value="nce" >NCE</option>';
        $output .= '<option value="hnd" >HND</option>';
        $output .= '<option value="bsc" selected>BSC</option>';
        $output .= '<option value="msc" >MSC</option>';
        $output .= '<option value="mphil" >MPHIL</option>';

    } else if ($st == 'msc') {
        $output = '<option value="0" > -- Please Select --</option>';
        $output .= '<option value="waec"  > WAEC</option>';
        $output .= '<option value="neco"> NECO</option>';
        $output .= '<option value="nd" >ND</option>';
        $output .= '<option value="nce" >NCE</option>';
        $output .= '<option value="hnd" >HND</option>';
        $output .= '<option value="bsc" >BSC</option>';
        $output .= '<option value="msc" selected>MSC</option>';
        $output .= '<option value="mphil" >MPHIL</option>';

    } else if ($st == 'mphil') {
        $output = '<option value="0" > -- Please Select --</option>';
        $output .= '<option value="waec"  > WAEC</option>';
        $output .= '<option value="neco"> NECO</option>';
        $output .= '<option value="nd" >ND</option>';
        $output .= '<option value="nce" >NCE</option>';
        $output .= '<option value="hnd" >HND</option>';
        $output .= '<option value="bsc" >BSC</option>';
        $output .= '<option value="msc" >MSC</option>';
        $output .= '<option value="mphil" selected>MPHIL</option>';

    } else {

        $output = '<option value="0" selected> -- Please Select --</option>';
        $output .= '<option value="waec"  > WAEC</option>';
        $output .= '<option value="neco" > NECO</option>';
        $output .= '<option value="nd" >ND</option>';
        $output .= '<option value="nce" >NCE</option>';
        $output .= '<option value="hnd" >HND</option>';
        $output .= '<option value="bsc" >BSC</option>';
        $output .= '<option value="msc" >MSC</option>';
        $output .= '<option value="mphil" >MPHIL</option>';

    }

    return $output;

}
//end of select marrital status

//nationality

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

}
//end

//function select state
function select_state($state_id)
{
    $r = mysqli_query(dbc(), "SELECT *  FROM state  ORDER BY title ");
    if (mysqli_num_rows($r) > 0) {
        while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
            if ($state_id == $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 select_lga($state, $lga)
{
    $r = mysqli_query(dbc(), "SELECT *  FROM lga where state_id='$state' 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 select sponsorship type
function select_sponsorship_type($r)
{

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

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

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

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

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

    } else {

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

    return $output;

}
//end of select sponsorship type

//select school
function select_school($con)
{
    $r = mysqli_query(dbc(), "SELECT *FROM schools  WHERE school_status ='1' ORDER BY title ");
    if (mysqli_num_rows($r) > 0) {
        while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
            if ($school == $row['school_id']) {
                $output = "<option class='col-md-5' value=\"$row[school_id]\" selected>";
                $output .= $row['title'];
                $output .= "</option>";

            } else {
                $output = "<option class='col-md-5' value=\"$row[school_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_programme($con)
{
    $r = mysqli_query(dbc(), "SELECT *FROM programmes  WHERE real_programmes =0 ORDER BY title ");
    if (mysqli_num_rows($r) > 0) {
        while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
            if ($programme_applied_for == $row['programme_id']) {
                $output = "<option class='col-md-4' value=\"$row[programme_id]\" selected>";
                $output .= $row['title'];
                $output .= "</option>";

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

            }

            echo $output;
        }
    } else {

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

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

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

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

            }

            echo $output;
        }
    } else {

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

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

//get department id for  a programme
function get_department_id_from_programmes($con, $p)
{
    $result = mysqli_query(dbc(), "SELECT department_id FROM programmes WHERE programme_id = '$p'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['department_id'];

    return $v;

}

//get department id for  a programme
function get_student_type($user_id)
{
    $result = mysqli_query(dbc(), "SELECT type_id FROM hostel_students WHERE id = '$user_id'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['type_id'];

    return $v;

}


//function dat checks if student exist in database table for school fee
	function get_prence_school_fee_payment_status($conn_1,$sid,$sess)  //sid is the student id
	{
		$q = "SELECT student_id FROM school_fee_payments_prence  WHERE student_id = '$sid' AND session = '$sess' ";
		$r = mysqli_query($conn_1,$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

  //for nce students
  function get_nce_school_fee_payment_status($conn_1,$sid,$sess)  //sid is the student id
	{
		$q = "SELECT student_id FROM school_fee_payments_nce  WHERE student_id = '$sid' AND session = '$sess' ";
		$r = mysqli_query($conn_1,$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

  //for duap students
  function get_duap_school_fee_payment_status($conn_2,$sid,$sess)  //sid is the student id
	{
		$q = "SELECT student_id FROM school_fee_payments_nce  WHERE student_id = '$sid' AND session = '$sess' ";
		$r = mysqli_query($conn_2,$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

 //for duap students
  function get_summer_school_fee_payment_status($conn_1,$sid,$sess)  //sid is the student id
	{
		$q = "SELECT student_id FROM summer_school_fee_payments_nce  WHERE student_id = '$sid' AND session = '$sess' ";
		$r = mysqli_query($conn_1,$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


  //check if the student have paid the hostel application fee
  function get_hostel_app_fee_payment_status($conn_1,$sid,$sess)  //sid is the student id
  {
    $q = "SELECT student_id FROM hostel_app_fee_payments  WHERE student_id = '$sid' AND session_id = '$sess' ";
    $r = mysqli_query($conn_1,$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


//get department id for  a programme
function get_school_code_by_id($con, $p)
{
    $result = mysqli_query(dbc(), "SELECT * FROM schools WHERE school_id = '$p'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['code'];

    return $v;

}

function get_user_id()
{
    $pn = $_SESSION['student_id'];
    return $pn;
}

function get_user_programme_type($id)
{

    $result = mysqli_query(dbc(), "SELECT type_id FROM students_nce WHERE id = '$id'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['type_id'];

    return $v;
}

function show_sponsorship_type($r)
{

    if ($r == '1') {

        $output = 'Private';

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

        $output = 'Self';

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

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

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

    } else {

        $output = 'Nil';
    }

    return $output;

}

function r_trf_exist($trf, $uaid)
{

    $q = "SELECT  	transaction_reference FROM remita_webpay_transaction_log
		      WHERE  transaction_reference = '$trf'
			  AND  	user_id  = '$uaid'";

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

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

    } else {
        return false;

    }

}

function get_user_level($id)
{

    $result = mysqli_query(dbc(), "SELECT level FROM students_nce WHERE id = '$id'");
    $row = mysqli_fetch_assoc($result);
    $level = $row['level'];

    return $level;
}

function show_hostel_fee_payment($user_id, $sess)
{

    $q = "SELECT `id`, `student_id`,  `session_id`, `semester_id`, `payment_status`,  DATE_FORMAT(date_added, '%M %e, %Y / %l:%i:%p') as date_added
		 FROM hostel_fee_payments WHERE student_id = '$user_id'  AND session_id = '$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 Hostel Fee for this " . get_session_title($row['session_id']) . " 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=' . $row['session_id'] . '&sem=' . $row['semester_id'] . '&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_hostel_app_fee_payment($user_id, $sess)
{

    $q = "SELECT `id`, `student_id`,  `session_id`, `semester_id`, `payment_status`,  DATE_FORMAT(date_added, '%M %e, %Y / %l:%i:%p') as date_added
		 FROM hostel_app_fee_payments WHERE student_id = '$user_id'  AND session_id = '$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 Hostel Application for this " . get_session_title($row['session_id']) . " 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=' . $row['session_id'] . '&sem=' . $row['semester_id'] . '&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 payment_status($status)
{
    $st = $status;

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

function 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  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>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>" . $row['date_added'] . "</td>";
            $output .= "<td>" . $row['due_date'] . "</td>";
            $output .= "<td>" . payment_status($row['payment_status']) . "</td>";

			if($type == 5)
			{
				$output .= '<td><a class="btn btn-primary btn-sm" href="dashboard.php?sms=view_invoice&qlk=' . md5(2) . '&iid=' . $row['invoice_id'] . '"> View Invoice</a></td>';

			}
			else if($type == 55)
			{
				$output .= '<td><a class="btn btn-primary btn-sm" href="dashboard.php?sms=view_invoice2&qlk=' . md5(2) . '&iid=' . $row['invoice_id'] . '"> View Invoice</a></td>';

			}
			else
			{
				$output .= '<td><a class="btn btn-primary btn-sm" href="dashboard.php?sms=view_invoice4&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;

}

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

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

    FROM `remita_webpay_transaction_log`

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


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

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

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

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


        </thead>

     <!-- <tfoot>

        </tfoot>-->

        <tbody>';

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

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

            $output .= "<td>" . $row['transaction_date'] . "</td>";
            $output .= "<td>" . transaction_status($row['payment_status']) . "</td>";
            $output .= '<td>' . transaction_status_for_log($row['payment_status'], $row['transaction_reference'],$t_type, $t_for) . '</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 get_user_year($id)
{

    $result = mysqli_query(dbc(), "SELECT year FROM students_nce WHERE id = '$id'");
    $row = mysqli_fetch_assoc($result);
    $year = $row['year'];

    return $year;
}
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;

}
function get_user_study_mode($id)
{

    $result = mysqli_query(dbc(), "SELECT cart_id FROM students_nce WHERE id = '$id'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['cart_id'];

    return $v;
}
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 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";
        }
    }

}

function transaction_status_for_log($id, $tref,$t_type, $t_for)
{
    if ($id == '1') {
        //return '<label class="label label-success"> SUCCESSFUL </label>';
    }
    elseif($t_type == 5 && $t_for == 5)
     {
       return  '<a class="btn btn-sm  btn-danger" href="dashboard.php?sms=check_trxn_status&txnref='.$tref.'" class="btn btn-primary" > Re-query </a>';
     } elseif($t_type == 55 && $t_for == 55)
     {
       return  '<a class="btn btn-sm  btn-danger" href="dashboard.php?sms=check_trxn_status_app&txnref='.$tref.'" class="btn btn-primary" > Re-query </a>';
     }

}

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

function get_hostel_category($con, $user_id)
{

    $result = mysqli_query(dbc(), "SELECT `block_id` FROM `hostel_allocation` WHERE `student_id` = '$user_id' AND `status` = '1'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['block_id'];

    return $v;
}

function get_hostel_room($con, $user_id)
{

    $result = mysqli_query(dbc(), "SELECT `room_id` FROM `hostel_allocation` WHERE `student_id` = '$user_id' AND `status` = '1'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['room_id'];

    return $v;
}

function get_hostel_site($con, $user_id)
{

    $result = mysqli_query(dbc(), "SELECT `campus_id` FROM `hostel_allocation` WHERE `student_id` = '$user_id' AND `status` = '1'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['campus_id'];

    return $v;
}

function get_hostel_room_title($con, $id)
{

    $result = mysqli_query(dbc(), "SELECT `title` FROM `hostel_rooms` WHERE `id` = '$id'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['title'];

    return $v;
}

function get_hostel_cat_title($con, $id)
{

    $result = mysqli_query(dbc(), "SELECT `title` FROM `hostel_blocks` WHERE `id` = '$id'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['title'];

    return $v;
}

function get_hostel_site_title($con, $id)
{

    $result = mysqli_query(dbc(), "SELECT `title` FROM `hostel_campuses` WHERE `id` = '$id'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['title'];

    return $v;
}

function get_hostel_cat_amount($con, $id)
{

    $result = mysqli_query(dbc(), "SELECT `hostel_amount` FROM `hostel_blocks` WHERE `id` = '$id'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['hostel_amount'];

    return $v;
}

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

function get_total_num_invoices()
{
    //get total invoice

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

    return $row[0];

}

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

}

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

    //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 get_user_fullname($user_id)
{

    $result = mysqli_query(dbc(), "SELECT * FROM hostel_students WHERE id = '$user_id'");
    $row = mysqli_fetch_assoc($result);
    $first_name = $row['first_name'];
    $other_names = $row['other_names'];

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

    return $user_fullname;
}

function get_user_state_id($id)
{

    $result = mysqli_query(dbc(), "SELECT state_id FROM students_nce 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 students_nce WHERE id = '$id'");
    $row = mysqli_fetch_assoc($result);
    $lid = $row['lga_id'];

    return $lid;
}

function get_user_address($user_id)
{

    $q = "SELECT address FROM students_nce WHERE id = '$user_id'";
    $r = mysqli_query(dbc(), $q);
    $row = mysqli_fetch_assoc($r);

    return $row['address'];

}

function view_hostel_allocation($user_id, $session)
{

    $checking = mysqli_query(dbc(), "SELECT * FROM hostel_fee_payments WHERE student_id='$user_id' AND `session_id` = '$session' AND payment_status= '1' ") or die(mysqli_error(dbc()));
    if (mysqli_num_rows($checking) > 0) {

        $member = mysqli_query(dbc(), "SELECT CONCAT_WS(' ', first_name, other_names) as `name`, phone_no,number, hostel_students.id AS id,
            hostel_students.gender AS gender, state.title AS state, lga.title AS lga, hostel_campuses.title AS site, hostel_students.image AS image,
            application_number, programmes.title AS programme, hostel_students.email as email, hostel_blocks.title AS category,
            hostel_rooms.title AS room FROM state, lga, hostel_campuses, hostel_allocation,hostel_blocks,hostel_rooms,
            hostel_students, programmes, hostel_fee_payments  WHERE hostel_students.programme_id =programmes.id  AND hostel_students.state_id = state.id AND
            hostel_students.lga_id = lga.id AND hostel_students.id = hostel_allocation.student_id AND
            hostel_allocation.campus_id = hostel_campuses.id AND hostel_allocation.room_id = hostel_rooms.id AND
            hostel_allocation.block_id = hostel_blocks.id AND hostel_students.hostel_allocation = 1 AND hostel_students.id = hostel_fee_payments.student_id AND
            hostel_fee_payments.payment_status = 1
            AND hostel_allocation.status = 1
					 ") or die(mysqli_error(dbc()));

        if ($member) {
            if (mysqli_num_rows($member) > 0) {
                $result = '<div class="col-md-12" style="padding-left:0px; padding-right:0px;">
								<div class="list-group">
								    <ul class="list-group">
										<li class="list-group-item list-group-item-success">
											<h3>My Room Member Information</h3>
										</li>
									</ul>
								</div>
							</div>';
                while ($get = mysqli_fetch_array($member)) {
                    $result .= '
							<div class="panel panel-default">
								<div class="panel-heading">
									<h3 class="panel-title">' . strtoupper($get['site']) . ' --- ' . strtoupper($get['category']) . ' --- ' . strtoupper($get['room']) . '</h3>
								</div>
								<div class="panel-body">';

                    $img = $get['image'];

                    if ($img == "") {

                        $pic = '<img src="../uploads/bg.jpg" width="120px" height="130px" class="img-circle"/>';
                    } else {

                        $pic = '<img src="../uploads/' . $img . '" width="120px" height="130px" class="img-circle"/>';

                    }

                    $result .= '
                        <table width="100%" class="table">
						    <tr>
								<td width="10%">' . $pic . '</td>
									<td width="90%">
							    		<table width="100%">
											<tr>
												<td width="100%"><h3 class="label label-success">NAME: ' . strtoupper($get['name']) . '</h3><hr/>
								    			</td>
											</tr>
											<tr>
												<td width="100%"><h3 class="label label-success">Phone Number: ' . strtoupper($get['phone_no']) . '</h3><hr/>
												</td>
											</tr>
											<tr>
												<td width="100%"><h3 class="label label-success">Email: ' . strtoupper($get['email']) . '</h3><hr/>
												</td>
											</tr>
										</table>
									</td>
							</tr>
						</table><hr/>';
                }
            }

            $result .= '</div></div>';

            return $result;
        }

    } else {

        $count_Cat = mysqli_query(dbc(), "SELECT * FROM hostel_allocation WHERE student_id='$user_id' AND `session_id`='$session'");
        if (mysqli_num_rows($count_Cat) > 0) {
            $vv = mysqli_fetch_assoc($count_Cat);

            $cat_idd = $vv['block_id'];
            $room_idd = $vv['room_id'];
            $iddd = $vv['campus_id'];
            $st_id = $vv['student_id'];

            //get his room title
            $allocate = mysqli_query(dbc(), "SELECT  title FROM hostel_rooms WHERE id='$room_idd' ") or die(mysqli_error(dbc()));
            $sql_room = mysqli_fetch_assoc($allocate);
            $Room_title = $sql_room['title'];

            //get his room title
            $allocate = mysqli_query(dbc(), "SELECT  title FROM hostel_campuses WHERE id='$iddd' ") or die(mysqli_error(dbc()));
            $sql_site = mysqli_fetch_assoc($allocate);
            $Site_title = $sql_site['title'];

            //get his category title
            $allocate = mysqli_query(dbc(), "SELECT  title FROM hostel_blocks WHERE id='$cat_idd' ") or die(mysqli_error(dbc()));
            $sql_category = mysqli_fetch_assoc($allocate);
            $Cat_title = $sql_category['title'];

            //get his category title
            $student_details = mysqli_query(dbc(), "SELECT  * FROM hostel_students WHERE id='$st_id' ") or die(mysqli_error(dbc()));
            $student_details_sql = mysqli_fetch_assoc($student_details);
            $gender = $student_details_sql['gender'] == "F" ? "FEMALE" : "MALE";
            echo '
        <div class="col-md-12" style="padding-left:0px; padding-right:0px;">
            <div class="list-group">
                <ul class="list-group">
                    <li class="list-group-item list-group-item-success">
                        <h3>My Bed Space Information/ Make Payment</h3>
                    </li>
                </ul>
            </div>
        </div>

        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">' . strtoupper($Site_title) . ' ------- ' . strtoupper($Cat_title) . ' ------- ' . strtoupper($Room_title) . '</h3>
            </div>
            <div class="panel-body">';

            echo '
        <label class="alert alert-danger">
            You have already been allocated room, proceed to payment please!
        </label><br>
        <table width="100%" class="table">
            <tr>
                <td width="10%">
                    <img src="../students/images/user.jpg" width="120px" height="130px" class="img-circle"/>
                </td>
                <td width="90%">
                <table width="100%">
                    <tr>
                        <td width="100%"><h3 class="label label-success" style="font-size:12px;">NAME: ' . strtoupper($student_details_sql['first_name'] . ' ' . $student_details_sql['other_names']) . '</h3><hr/></td>
                    </tr>
                    <tr>
                        <td width="100%"><h3 class="label label-success" style="font-size:12px;">Matric Number: ' . strtoupper($student_details_sql['number']) . '</h3><hr/></td>
                    </tr>
                    <tr>
                        <td width="100%"><h3 class="label label-success" style="font-size:12px;">Phone Number: ' . strtoupper($student_details_sql['phone_no']) . '</h3><hr/></td>
                    </tr>
                    <tr>
                        <td width="100%"><h3 class="label label-success" style="font-size:12px;">Email: ' . strtoupper($student_details_sql['email']) . '</h3><hr/></td>
                    </tr>
                    <tr>
                        <td width="100%"><h3 class="label label-success" style="font-size:12px;">Gender: ' . $gender . '</h3><hr/></td>
                    </tr>
                </table>
                <!-- PROCEED TO PAYMENT --> <a class="btn btn-primary" style="width:80%; margin-top:20px;" href="dashboard.php?sms=payments" data-toggle="tooltip" title="Click here to Proceed to payment" data-placement="top"><i class="glyphicon glyphicon-ok"> </i> PROCEED TO PAYMENT</a>
            </td>
        </tr>

    </table><hr/>';
        } else {
            return 'Not allocate yet';
        }
    }

}

//get current academic year
function get_current_session($id)
{
    $result = mysqli_query(dbc(), "SELECT * FROM `sessions` WHERE current_session = '$id'");
    $row = mysqli_fetch_assoc($result);
    $v = $row['id'];

    return $v;

}

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

//get current academic year
function get_institute_code($con)
{
    $result = mysqli_query(dbc(), "SELECT * FROM sms_settings ");
    $row = mysqli_fetch_assoc($result);
    $v = $row['school_code'];

    return $v;

}

//get total applicants
function get_total_num_applicants($con, $s)
{
    //get total invoice

    $q = "SELECT COUNT(applicant_id) FROM applicants WHERE school_id='$s'";
    $r = mysqli_query(dbc(), $q);
    $row = mysqli_fetch_array($r, MYSQLI_NUM);

    return $row[0];

}

//function taht generate app no
function generate_application_number_for_applicants($con, $school_id)
{

    $total_num = get_total_num_applicants($con, $school_id);

    //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 = '0000' . $g_coded;
    } else if ($len_g_coded == '2') {
        $g_coded = '00' . $g_coded;
    } else if ($len_g_coded == '3') {
        $g_coded = '0' . $g_coded;
    } else {
        $g_coded = $g_coded; //add strings to invoice id
    }

    if (applicant_no_exist($con, $g_coded)) {
        $g_coded = $g_coded + 1; //if it exist add 1 to it

    }

    return $g_coded;

} //end of generate apl no

//check if applicant no  already exist
function applicant_no_exist($con, $iid)
{
    //check if invoice id generated exist
    $q1 = "SELECT application_number FROM applicants WHERE application_number = '$iid'";
    $r1 = mysqli_query(dbc(), $q1);

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

}

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

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

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

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

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

    }

    return $output;

}

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

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

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

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

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

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

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

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

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

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

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

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

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

    return $output;

}

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

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

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

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

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

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

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

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

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

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

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

    }

    return $output;

}
//end of blood group selection

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

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

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

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

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

    } else {

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

    }

    return $output;

}
//end of select exam type

//function select 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 calendar yer
function year($y)
{
    $y = $y;
    $years = range(1950, date('Y'));

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

} //end of year

//function select subjects
function select_subjects($con, $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 highest qualification
function select_subject_grade($hiq)
{

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

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

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

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

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

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

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

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

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

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

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

    }
    return $output;

}

function has_paid_hostel_fee($user_id, $session)
{

    $q = "SELECT student_id,`session_id`, payment_status
			  FROM hostel_fee_payments
			  WHERE student_id = '$user_id'
			  AND `session_id` = '$session'
			  AND payment_status  = '1'";
    $r = mysqli_query(dbc(), $q);

    //$row = mysql_fetch_assoc($result);

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

    } else {
        return true;
    }

}

function has_paid_hostel_app_fee($user_id, $session)
{

    $q = "SELECT student_id,`session_id`, payment_status
			  FROM hostel_app_fee_payments
			  WHERE student_id = '$user_id'
			  AND `session_id` = '$session'
			  AND payment_status  = '1'";
    $r = mysqli_query(dbc(), $q);

    //$row = mysql_fetch_assoc($result);

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

    } else {
        return true;
    }

}

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

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

}

//function to get applicant alevel
function get_applicant_alevel($con, $id)
{
    $sql_get_app = mysqli_query(dbc(), "select * FROM applicants_alevel where applicant_id ='$id' and applicant_alevel_status= '1' ");

    if ($sql_get_app) {
        $sql_get_app_row = mysqli_num_rows($sql_get_app);
        if ($sql_get_app_row > 0) {
            $output =
                '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
											    <thead>
											          <th>S/N</th>
											          <th>INSTITUTION</th>
											          <th>QUALIFICATION</th>
											          <th>COURSE</th>
											          <th>CLASS OF DEGREE</th>
											          <th>START</th>
											          <th>END</th>
																<th>CGPA</th>
											          <th>ACTION</th>




											    </thead>
											    <tfoot>

											          <th>S/N</th>
											          <th>INSTITUTION</th>
											          <th>QUALIFICATION</th>
											          <th>COURSE</th>
											          <th>CLASS OF DEGREE</th>
											          <th>START</th>
											          <th>END</th>
																<th>CGPA</th>
											          <th>ACTION</th>

											    </tfoot>

											    <tbody>';

            while ($row = mysqli_fetch_assoc($sql_get_app)) {

                //getting Certificate type
                $cert = $row['cert'];
                if ($cert == 1) {
                    $cert = 'ND';
                } else if ($cert == 2) {
                    $cert = 'NCE';
                } else if ($cert == 3) {
                    $cert = 'IJMB';
                } else if ($cert == 4) {
                    $cert = 'HND';
                } else if ($cert == 5) {
                    $cert = 'BSC';
                } else if ($cert == 6) {
                    $cert = 'MSC';
                } else if ($cert == 7) {
                    $cert = 'MPHIL';
                } else if ($cert == 8) {
                    $cert = 'MTECH';
                } else if ($cert == 9) {
                    $cert = 'Others';
                }

                //getting class of degree
                $degree = $row['class_of_degree'];
                if ($degree == 1) {
                    $degree = 'First Class';
                } else if ($degree == 2) {
                    $degree = 'Distinction';
                } else if ($degree == 3) {
                    $degree = 'Merit';
                } else if ($degree == 4) {
                    $degree = 'Second Class Upper';
                } else if ($degree == 5) {
                    $degree = 'Upper Division';
                } else if ($degree == 6) {
                    $degree = 'Second Class Lower';
                } else if ($degree == 7) {
                    $degree = 'Lower Division';
                } else if ($degree == 8) {
                    $degree = 'Third Class';
                } else if ($degree == 9) {
                    $degree = 'Pass';
                }

                @$sn += 1;
                $output .= "<tr>";
                $output .= "<td>" . $sn . "</td>";
                $output .= "<td>" . $row['institution'] . "</td>";
                $output .= "<td>" . $cert . "</td>";
                $output .= "<td>" . $row['course_of_study'] . "</td>";
                $output .= "<td>" . $degree . "</td>";
                $output .= "<td>" . $row['start_year'] . "</td>";
                $output .= "<td>" . $row['end_year'] . "</td>";
                $output .= "<td>" . $row['cgpa'] . "</td>";
                $output .= '<td style="padding:0px;margin:0px;"><a href="includes/php/delete_alevel.php" class="btn btn-login btn-green" id="action" onclick="action()" style="width:70px; margin-right:-22px; padding:0px;"><span>delete</span></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;
}

//function to get applicant alevel
function get_applicant_credential($con, $id)
{
    $sql_get_app = mysqli_query(dbc(), "select * FROM applicants_credential where applicant_id ='$id' AND credential_status='1' ");

    if ($sql_get_app) {
        $sql_get_app_row = mysqli_num_rows($sql_get_app);
        if ($sql_get_app_row > 0) {
            $output =
                '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
												    <thead>
												          <th>S/N</th>
												          <th>DOCUMENT/CREDENTIAL DESCRIPTION</th>
												          <th>ACTION</th>




												    </thead>
												    <tfoot>

														<th>S/N</th>
														<th>DOCUMENT/CREDENTIAL DESCRIPTION</th>
														<th>ACTION</th>

												    </tfoot>

												    <tbody>';

            while ($row = mysqli_fetch_assoc($sql_get_app)) {
                @$sn += 1;
                $id = $row['id'];
                $output .= "<tr>";
                $output .= "<td>" . $sn . "</td>";
                $output .= "<td>" . $row['file_name'] . "</td>";
                $output .= '<td style="padding:0px;margin:0px;"><a href="includes/php/delete_credential.php" class="btn btn-login btn-green" id="action" onclick="action()" style="width:133px; margin-right:-162px; padding:0px;"><span>delete</span></a></td>';
                $output .= '<td style="padding:0px;margin:0px;"><input type="hidden" name="file" value=' . $id . '></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;
}

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

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

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

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

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

    }
    return $output;

}
//end of select college cert

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

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

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

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

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

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

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

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

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

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

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

    }
    return $output;

}
//end of select class of degree

//Functions to fetch user's fscl cert
function get_user_cert1($con, $id, $type)
{
    $result = mysqli_query(dbc(), "SELECT cert FROM applicants_alevel WHERE applicant_id = '$id' AND result_type = '$type'");
    $row = mysqli_fetch_assoc($result);
    $c1 = $row['cert'];

    return $c1;
}

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

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

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

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

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

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

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

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

    }
    return $output;

}
//end of select exam grade
?>
