<?php
session_start();

require_once('configuration_duap.php');



ob_start();

//function that clean all passed items from interface



//function get notifications error, info, info success



//function get user id brings user id
function get_user_id()
{
	//collect the id using cookie
	$user_id = $_COOKIE['lis'];
	return $user_id;
}

//collect the user id from the fucntion



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

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


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

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

  }



} // end of browser / platform filter



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

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

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


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

	$row = mysql_fetch_array($r, MYSQL_ASSOC);
	$at = $row['action'];




		return $at;



}





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


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

		 $query = "DELETE FROM assets  WHERE user_id = '$user_id'";
		 mysql_query($query);


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


			}



}


//function that return whether super administartor or not
function is_administrator($user_id)
{
	$q = "SELECT group_id FROM users WHERE user_id = '$user_id'";
	$r = mysql_query($q);

	$row = mysql_fetch_array($r, MYSQL_ASSOC);
	 $group_id = $row['group_id'];

	if($group_id == 1 || $group_id == 2)
	{return true;}
	else
	{return false;}
}





//get user first name, last name
function get_name($user_id)
{
	$query = "SELECT  first_name   AS name FROM users WHERE user_id ='$user_id'";
	$result = mysql_query($query);
	$row = mysql_fetch_assoc($result);

	return $row['name'];

}

//function get last login detail
function get_user_last_loggedout($user_id)
{
	$q = "SELECT DATE_FORMAT(last_logout, '%b %e, %Y  %l:%i:%p') as last_logout FROM users WHERE user_id = '$user_id'";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['last_logout'];
}



//function dat get usergroup by id type
function get_user_groupid($user_id)
{
	$q = "SELECT group_id FROM users WHERE user_id = '$user_id' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['group_id'];


}


//function dat get usergroup by title type
function get_user_group_title($user_id)
{
	$q = "SELECT u.group_id, ug.user_group_id, ug.title as group_title FROM users u, user_groups ug
		  WHERE u.group_id = ug.user_group_id AND u.user_id = '$user_id' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['group_title'];


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


		return $v;
	}

	//function fetch user programme type applied for
	function get_user_programme_type_applied_for($id)
	{
		$result = mysql_query("SELECT programme_type_applied_for FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['programme_type_applied_for'];


		return $v;
	}


function 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_payment_status($code)
	{
		if($code == '1')
		{
			return '<span class="btn btn-success"> PAID</span>';

		}
		else
		{
			return '<span class="btn btn-danger">NOT PAID</span>';
		}

	}//end of payments status

	//function fetch user programme type applied for
	function get_user_cart_id($id)
	{
		$result = mysql_query("SELECT cart_id FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['cart_id'];


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


		return $v;
	}

//function fetch user school applied for
	function get_user_school_applied_for($id)
	{
		$result = mysql_query("SELECT school_applied_for FROM applicants_nce WHERE id = $id");
		$row = mysql_fetch_assoc($result);
		$v = $row['school_applied_for'];


		return $v;
	}


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


		return $v;
	}


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

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

	return $user_fullname;
	}

//Functions to fetch user's Full name
	function get_user_username($user_id)
	{
		$result = mysql_query("SELECT username FROM users WHERE user_id = '$user_id'");
		$row = mysql_fetch_assoc($result);
		$username = $row['username'];

	return $username;
	}

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

	return $email;
	}

	//Function to fetch email
	function get_student_email($user_id)
	{
		$result = mysql_query("SELECT email FROM students_nce WHERE id = '$user_id'");
		$row = mysql_fetch_assoc($result);
		$email = $row['email'];

	return $email;
	}

//function dat get usergroup menu privileges based on logged in user
function get_user_group_header_menu_privileges($user_id)
{
	$q = "SELECT u.group_id, ug.user_group_id, ug.header_menu FROM users u, user_groups ug
		  WHERE u.group_id = ug.user_group_id AND u.user_id = '$user_id' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['header_menu'];


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

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

	return $ph;
	}

	//function dat get user application number
	function get_user_application_number($user_id)
	{
	$q = "SELECT application_number FROM applicants_nce WHERE id = '$user_id'";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['application_number'];


	}




	function applicant_id_exist_payments_4($user_id, $sess)
	{
		$result = mysql_query("SELECT applicant_id FROM applicants_nce_fee_payments WHERE applicant_id = '$user_id' AND session = '$sess'");
		//$row = mysql_fetch_assoc($result);
		//$an = $row['applicant_id'];

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


	//end of go live buttons checking
	function student_id_exist_payments_nce_4($user_id, $sess, $sem)
	{
		$result = mysql_query("SELECT student_id FROM school_fee_payments_nce WHERE student_id = '$user_id' AND
		 session = '$sess' AND semester = '$sem'");
		//$row = mysql_fetch_assoc($result);
		//$an = $row['applicant_id'];

		if(mysql_num_rows($result)>0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}


	//end of go live buttons checking
	function student_id_exist_payments_nce($user_id, $sess, $sem)
	{
		$result = mysql_query("SELECT student_id FROM school_fee_payments_nce WHERE student_id = '$user_id' AND
		 session = '$sess' AND semester = '$sem'");
		//$row = mysql_fetch_assoc($result);
		//$an = $row['applicant_id'];

		if(mysql_num_rows($result)>0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}


	//end of go live buttons checking
	function student_id_exist_payments_prence_4($user_id, $sess, $sem)
	{
		$result = mysql_query("SELECT student_id FROM school_fee_payments_prence WHERE student_id = '$user_id' AND
		 session = '$sess' AND semester = '$sem'");
		//$row = mysql_fetch_assoc($result);
		//$an = $row['applicant_id'];

		if(mysql_num_rows($result)>0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}



//function dat get usergroup menu privileges based on logged in user
function get_user_group_toolbar_menu_privileges($user_id)
{
	$q = "SELECT u.group_id, ug.user_group_id, ug.toolbar_menu FROM users u, user_groups ug
		  WHERE u.group_id = ug.user_group_id AND u.user_id = '$user_id' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['toolbar_menu'];


}




//function dat get usergroup home menu privileges based on logged in user
function get_user_group_home_menu_privileges($user_id)
{
	$q = "SELECT u.group_id, ug.user_group_id, ug.home_menu FROM users u, user_groups ug
		  WHERE u.group_id = ug.user_group_id AND u.user_id = '$user_id' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['home_menu'];


}



//function get user ip
function get_user_ip($user_id)
{
	$q = "SELECT last_login_ip FROM users WHERE user_id = '$user_id' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['last_login_ip'];


}




//function get total users online
function get_total_online_visitors()
{
	$noov = mysql_num_rows(mysql_query("SELECT * FROM online_visitors"));  //noov = number of online visitors

	return $noov;

}










//function get total users online
function get_total_users_online()
{
	$q = "SELECT COUNT(user_id) FROM users  WHERE online_status = '1'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function that get total number of ordinary users
function get_total_ordinary_users_online()
{
	$q = "SELECT COUNT(user_id) FROM users WHERE online_status = '1' AND group_id = '0'";
	$r = mysql_query($q);

	$row = mysql_fetch_array($r, MYSQL_NUM);

	return $row[0];
}



//function that get total number of admin users
function get_total_admin_users_online()
{
	$q = "SELECT COUNT(user_id) FROM users WHERE online_status = '1'
	AND (group_id = 1 OR group_id = 2 OR group_id = 3 OR group_id = 5)";
	$r = mysql_query($q);

	$row = mysql_fetch_array($r, MYSQL_NUM);

	return $row[0];
}



//function check last 5 logged in users log in user
function get_last_5logged_in_users()
{

	//get user id  so dat you cant check on ur sef some else does
	$user_id = get_user_id();

	$q = "SELECT CONCAT_WS(' ', u.first_name, u.other_names)  as name, u.group_id, DATE_FORMAT(u.last_login, '%b %e, %y  %l:%i:%p') as
			user_lastlogindate, u.online_status,
		  u.role_id, DATE_FORMAT(u.last_logout, '%b %e, %y  %l:%i:%p') as user_lastlogoutdate,
		  ug.user_group_id, ug.title as group_title
		  FROM users u, user_groups ug
		  WHERE u.group_id = ug.user_group_id
		  AND   u.online_status = 1

		  ORDER BY u.last_login DESC

		  LIMIT 5";
	$r = mysql_query($q);

	if(mysql_num_rows($r)>0)
	{
		while($row = mysql_fetch_assoc($r))
		{
			$output = "<tr>";
			$output .= "<td><a href=''>".$row['name']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['group_title']."</td>"; //group belong to admin or user
			//$output .= "<td>".$row['role_title']."</td>"; //role e.g cheif servant or commissioner etc
			$output .= "<td>".$row['user_lastlogindate']."</td>"; //logged in
			$output .= "<td>".$row['user_lastlogoutdate']."</td>"; //logged out
			//$output = "<td>Last acti</td>"; last activity if included
			$output .= "</tr>";


		}
	}


	return $output;
}


//function that get last 5 suspended users
function get_last_5blocked_users()
{

	//get user id  so dat you can check on ur sef some else does
	$user_id = get_user_id();

	$q = "SELECT CONCAT_WS(' ', u.first_name, u.other_names)  as name, u.group_id, DATE_FORMAT(u.last_login, '%b %e, %y  %l:%i:%p') as last_login,
		  u.role_id, DATE_FORMAT(u.last_logout, '%b %e, %y  %l:%i:%p') as last_logout,
		  ug.user_group_id, ug.title as group_title
		  FROM users u,  user_groups ug
		  WHERE u.group_id = ug.user_group_id

		  AND   u.user_id !=  '$user_id'
		  AND 	u.user_status = 0

		  ORDER BY name ASC
		  LIMIT 5";
	$r = mysql_query($q);

	if(mysql_num_rows($r)>0)
	{
		while($row = mysql_fetch_assoc($r))
		{
			$output = "<tr>";
			$output .= "<td><a href=''>".$row['name']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['group_title']."</td>"; //group belong to admin or user
			//$output .= "<td>".$row['role_title']."</td>"; //role e.g cheif servant or commissioner etc
			$output .= "<td>".$row['last_login']."</td>"; //logged in
			$output .= "<td>".$row['last_logout']."</td>"; //logged out
			//$output = "<td>Last acti</td>"; last activity if included
			$output .= "</tr>";

			echo $output;
		}
	}

}
//end of get last five suspended users


//function dat get user security id  by id
function get_security_id($user_id)
{
	$q = "SELECT security_id FROM users WHERE user_id = '$user_id' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['security_id'];


}

//function that generates security code
function generate_security_code()
{
	$result = mysql_query("SELECT * FROM generate_code");
	while($row = mysql_fetch_array($result))
	{
		$g_code = $row['code'];
	}

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

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

	$add_zeros = '0'.$g_coded;
	$security_id = date("Y-m-d-$add_zeros").'-IBBU';

	return $security_id;
}


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

	return $id;
	}
	
	//Function to fetch  session
	function get_session_title($id)
	{
		$result = mysql_query("SELECT * FROM sessions WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$title = $row['title'];

	return $title;
	}//end of get session title



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

	return $id;
	}


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

	return $title;
	}




	//function tha gen token for delete, and other purposes
	function generate_token()
	{
			for($i=0;$i<=20;$i++){
				$key .=mt_rand(0,9);
			}
			return $key.date();
	}//end of




///function for back up
function backup_tables($host,$user,$pass,$name,$tables = '*')
{

	$user_id =  get_user_id();


 	//collect the user security id to track who did the back up
	$sid = get_security_id($user_id);



    $link = mysql_connect($host,$user,$pass);
    mysql_select_db($name,$link);
    mysql_query("SET NAMES 'utf8'");

    //get all of the tables
    if($tables == '*')
    {
        $tables = array();
        $result = mysql_query('SHOW TABLES');
        while($row = mysql_fetch_row($result))
        {
            $tables[] = $row[0];
        }
    }
    else
    {
        $tables = is_array($tables) ? $tables : explode(',',$tables);
    }
    $return='';

    //cycle through
    foreach($tables as $table)
    {
        $result = mysql_query('SELECT * FROM '.$table);
        $num_fields = mysql_num_fields($result);

        $return.= 'DROP TABLE '.$table.';';
        $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
        $return.= "\n\n".$row2[1].";\n\n";

        for ($i = 0; $i < $num_fields; $i++)
        {
            while($row = mysql_fetch_row($result))
            {
                $return.= 'INSERT INTO '.$table.' VALUES(';
                for($j=0; $j<$num_fields; $j++)
                {
                    $row[$j] = addslashes($row[$j]);
                    $row[$j] = str_replace("\n","\\n",$row[$j]);
                    if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
                    if ($j<($num_fields-1)) { $return.= ','; }
                }
                $return.= ");\n";
            }
        }
        $return.="\n\n\n";
    }



	$dbn = $name.time();

    //save file
   // $handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+'); // i cancelled this out beccause of the complication
    $handle = fopen('db_backups/'.$dbn.'.sql','w+');
    fwrite($handle,$return);


	// after the write
	//then the send data to the db



	$q = "INSERT INTO `backups`(`id`, `file`, `status`, `date_added`,`added_by`)
		  VALUES (NULL,'$dbn','0',NOW(),'$sid')";
	$r = mysql_query($q);


	fclose($handle);


}
//end of back up function

//function get last time back up
//function get total users online
function get_last_time_backup()
{
	//query the database
	$q = "SELECT  DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added
		  FROM `backups`
		  ORDER BY date_added DESC LIMIT 1";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}


//function that get users roles
function view_backups()
{


	//query the database
	$q = "SELECT  `id`, `file`, `status`, DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, `date_trashed`, `added_by`
		  FROM `backups`
		  ORDER BY date_added DESC";
	$r = mysql_query($q);





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


	$output =
	'<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
	  <thead>
				<!--	<th > <input type="checkbox" id="selecctall"  value=""> </th>-->
				<th >File</th>
				<th >Date / Time Backed Up</th>
				<th >Added by</th>

	  </thead>





	  <tbody>';





		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			//$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='backup[]' id='role' class='checkbox1'/></td>" ;
			$output .= "<td><a href='db_backups/".$row['file'].".sql' data-toggle='tooltip' title='Click to Download'>".$row['file']."</a></td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['added_by']."</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 backups



//function audit trail and tracks what user does on the system
function set_user_log($user, $action)
{
	$query = "INSERT INTO user_log(log_id, user_id, log_action, log_date)
				VALUES (NULL, '$user', '$action', NOW())";
	mysql_query($query);

}



//function view user log
function view_user_log()
{

	//query the database
	$query = "SELECT u.user_id, u.security_id, CONCAT_WS(' ', u.first_name, u.other_names) as name, ul.log_id, ul.user_id, ul.log_action,
			 DATE_FORMAT(ul.log_date, '%b %e, %Y  %l:%i:%p')as log_date

			 FROM users u, user_log ul

			 WHERE u.user_id = ul.user_id


			 ORDER BY log_date";
   $result = mysql_query($query);










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


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

					  <th>Name</th>
					  <th>Security ID</th>
					  <th>Action</th>
					  <th>Date</th>



		  </thead>

		  <tfoot>

					  <th>Name</th>
					  <th>Security ID</th>
					  <th>Action</th>
					  <th>Date</th>



		  </tfoot>

		  <tbody>';


		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td>".$row['name']."</td>"; //group belong to admin or user
			$output .= "<td>".$row['security_id']."</td>";
			$output .= "<td>".$row['log_action']."</td>";
			$output .= "<td>".$row['log_date']."</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 user log






/* documentation for header menu **
** 0 - default that gives access to profile, track log, php version
** 1 - gives access to user manager, role, user group
** 2 - gives access to news manger, events
** 3 - gives access to picture manager, video or any content manager
** 4 - gives access to state manager, lga
** 5 - gives access to departments and schools
** 6 - givess access to reports
*/





//function that gets header menu privileges
function header_menu($privileges)
{
	$list = '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/admin_small.png" />Admin<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="gateway.php"><img src="images/control_panel_small.png" />Control Panel</a></li>
							<li><a href="gateway.php?act=view_profile"><img src="images/profile_small.png" />My Profile</a></li>
							<li><a href="gateway.php?act=view_global_settings"><img src="images/global_settings_small.png" />Global Configuration</a></li>
							<li><a tabindex="0" data-toggle="popover" data-trigger="focus" title="Mass Mail" data-content="This feature is coming at later versions"><img src="images/mass_messaging_small.png" />Message</a></li>
							<li><a tabindex="0" data-toggle="popover" data-trigger="focus" title="Mass Mail" data-content="This feature is coming at later versions">
								<img src="images/system_info_small.png" />Mass Mail</a></li>
						</ul>
					</li>';



	$privilege[1] = '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/users_icon.png" /> Users<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="gateway.php?act=view_users"><img src="images/user_manager_small.png">User Manager</a></li>
							<li><a href="gateway.php?act=view_roles"><img src="images/user_roles_small.png">Roles</a></li>
							<li><a href="gateway.php?act=view_user_groups"><img src="images/user_access_level_small.png">Access Level(User Groups)</a></li>
							<!-- <li><a href="#"><img src="images/user_notes_small.png">Notes user</a></li>
							<li><a href="#"><img src="images/mass_messaging_small.png">Mass mail message</a></li>-->
						</ul>
					</li>';

	$privilege[2] = '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/news_events_small.png"> Media<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="gateway.php?act=view_news"><img src="images/news_small.png">News Manager</a></li>
							<li><a href="gateway.php?act=view_events"><img src="images/events_small.png">&nbsp;&nbsp;Event Manager</a></li>
							<li><a href="gateway.php?act=view_pictures"><img src="images/pictures_small.png">Picture Manager</a></li>
							<li><a href="gateway.php?act=view_videos"><img src="images/videos_small.png">Video Manager</a></li>
							<li><a tabindex="0" data-toggle="popover" data-trigger="focus" title="Book of Life" data-content="This feature is coming at later versions"><img src="images/book-of-life-small.png">&nbsp;Book of Life</a></li>
						</ul>
					</li>';

	$privilege[3] = '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/faculty.png">
						School<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="gateway.php?act=view_admission_reports_landing"><img src="images/faculties-small.png">&nbsp;&nbsp;Admission Manager</a></li>
							<li><a href="gateway.php?act=view_departments"><img src="images/departments-small.png">Departments</a></li>
							<li><a href="gateway.php?act=view_programmes"><img src="images/programmes-small.png"> &nbsp;Programmes</a></li>
							<li><a href="gateway.php?act=view_courses"><img src="images/courses-small.png">&nbsp;Courses</a></li>
							<li><a href="gateway.php?act=view_programmes_courses"><img src="images/programmes-courses-small.png">&nbsp;Programmes >> Courses</a></li>
							<li><a href="gateway.php?act=view_supports"><img src="images/students-support-small.png">&nbsp;Supports</a></li>

						</ul>
					</li>';

  $privilege[4] = '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/bankers_small.png">
  Bankers<b class="caret"></b></a>
  <ul class="dropdown-menu">
	 <!-- <li><a href="gateway.php?act=view_applicants_pins"><img src="images/applicants_manager_small.png">&nbsp;&nbsp;Applicants PINS</a></li>-->
	  <!--<li><a href="gateway.php?act=view_students_payments_b"><img src="images/departments-small.png">Students Payments Confirmation</a></li>-->
	   <li><a href="gateway.php?act=view_app_fees_log"><img src="images/remitalogosmaller.jpg">Remita Transaction Log (App Fees)</a></li>
	   <li><a href="gateway.php?act=view_scrf_fees_log"><img src="images/remitalogosmaller.jpg">Remita Transaction Log (Screening Fees)</a></li>
	   <li><a href="gateway.php?act=view_fresh_sf_fees_log"><img src="images/remitalogosmaller.jpg">Remita Trans Log (Fresh Sch. Fees)</a></li>
	   <li><a href="gateway.php?act=view_return_sf_fees_log"><img src="images/remitalogosmaller.jpg">Remita Trans Log (Returning Sch. Fees)</a></li>




  </ul>
</li>';


   	$privilege[5] = '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/maintenance.png">
						Maintenance<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="gateway.php?act=view_system_backup"><img src="images/backup-small.png">System Backup Manager</a></li>
							<li><a href="gateway.php?act=view_system_log"><img src="images/system-log-small.png">System Log</a></li>
							<li><a href="gateway.php?act=view_ip_filter"><img src="images/ip-control-small.png">&nbsp;Ip Filter</a></li>
							<li><a href="gateway.php?act=view_control_boxs"><img src="images/control-box-small.png">Control Box</a></li>
						</ul>
					</li>';




	$privilege[6] = '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/report-1.png">&nbsp;Reports<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="gateway.php?act=view_reports"><img src="images/report-small.png">  Report Manager</a></li>
						</ul>
					</li>';


	$privilege[7] = '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/report-1.png">&nbsp;  Bursary / Provost Reports<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="gateway.php?act=view_student_info_sys"><img src="images/report-small.png">  Student Information Reports </a></li>
							<li><a href="gateway.php?act=view_student_fin_sys"><img src="images/report-small.png">  Financial Reportings</a></li>


						</ul>
					</li>';
	$privilege[8] = '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/bankers_small.png">
  Bankers<b class="caret"></b></a>
  <ul class="dropdown-menu">
	 <!-- <li><a href="gateway.php?act=view_applicants_pins"><img src="images/applicants_manager_small.png">&nbsp;&nbsp;Applicants PINS</a></li>-->
	  <li><a href="gateway.php?act=view_students_payments_b"><img src="images/departments-small.png">Students Payments Confirmation</a></li>
	   <li><a href="gateway.php?act=view_app_fees_log"><img src="images/new-remita-logo-smaller.jpg">Remita Transaction Log (App Fees)</a></li>
	   <li><a href="gateway.php?act=view_scrf_fees_log"><img src="images/new-remita-logo-smaller.jpg">Remita Transaction Log (Screening Fees)</a></li>
	   <li><a href="gateway.php?act=view_fresh_sf_fees_log"><img src="images/new-remita-logo-smaller.jpg">Remita Trans Log (Fresh Sch. Fees)</a></li>
	   <li><a href="gateway.php?act=view_return_sf_fees_log"><img src="images/new-remita-logo-smaller.jpg">Remita Trans Log (Returning Sch. Fees)</a></li>




  </ul>
</li>';

	//explode the privileges
	$allowed_privileges = explode(',',$privileges);

	for($i=0; $i<sizeof($allowed_privileges)-1; $i++)
	{
		if ($allowed_privileges[$i] == 8 ) {

			unset($list);
			$list = $privilege[$allowed_privileges[$i]];

		}else{
			$list .= $privilege[$allowed_privileges[$i]];
		}

	}

	$list .= "";

	//return $privileged_list;
	return $list;


}

//end of function header_menu


//function home menu goes here

/* home menu documentation
** 0 is for checking ur profile
** 1 is for add news
** 2 is is user manager
** 3 is for adding event
** 4 is checking system information
** 5 -  global settings like checking the configuration
** 6 -  adding video to youtube and
**/

function home_menu($privileges)
{
	$list .= '<span class="home_menu_icons"><a  href="gateway.php?act=view_profile&u='.get_user_id().'"><img src="images/profile.png" data-toggle="tooltip" title="View Profile" />
	&nbsp;&nbsp;Profile</a></span>';

	$privilege[1] = '<span class="home_menu_icons"><a href="gateway.php?act=add_news"><img src="images/add_news.png" data-toggle="tooltip" title="Add News" />
	Add News	</a>

			  </span>';

	$privilege[2] = '<span class="home_menu_icons"><a  href="gateway.php?act=view_users"><img src="images/user_manager.png" data-toggle="tooltip" title="User Manager" />
					User Manager</a></span>';




	$privilege[3] = '<span class="home_menu_icons"><a  href="gateway.php?act=add_events"><img src="images/add_events.png"
					data-toggle="tooltip" title="Add Events" />Add Events</a></span>';


	$privilege[4] = '<span class="home_menu_icons"><a  href="gateway.php?act=view_system_info"><img src="images/system_info.png" data-toggle="tooltip" title="System Infor" />
					System Info</a>
					</span>';

	$privilege[5] = '<span class="home_menu_icons"><a  href="gateway.php?act=view_global_settings"><img src="images/global_settings.png" data-toggle="tooltip"
					title="Global Setting" />Global Settings</a></span>';


	$privilege[6] = '<span class="home_menu_icons"><a  href="gateway.php?act=add_pictures"><img src="images/gallery.png" data-toggle="tooltip"
					title="Add Picture / Video Details" />Add Pics / Video</a></span>';





	//explode the privileges
	$allowed_privileges = explode(',',$privileges);

	for($i=0; $i<sizeof($allowed_privileges)-1; $i++)
	{
		$list .= $privilege[$allowed_privileges[$i]];

	}

	$list .= "";

	//return $privileged_list;
	return $list;


}
//end of function home menu


//function activity trail
function activity_menu()
{


}


//function tab menu
function tab_menu()
{

}



//function that checks if user status is blocked or unblocked 0- blocked 1 means unblocked
//by passing the blocked status

function user_status_img($status)
{
	$st = $status;

	if($st == 1)
	{
		return '<img src="images/active.png" data-toggle="tooltip" title="Active"/>';
	}
	else
	{
		return '<img src="images/blocked.png" data-toggle="tooltip" title="Blocked" />';
	}
}


//function that shows users publish status image
function users_publish_status_image($status)
{

	$st = $status;

	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_users" id="publish_u"
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_users" id="unpublish_u"
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}

	return $output;


}//end of function dat shows publish users image




//function view users
//function that get users informatn
function view_users()
{

	$user_id = get_user_id();

	//query the database
	$q = "SELECT u.user_id, u.group_id, CONCAT_WS(' ', u.first_name, u.other_names) as name, u.phone_number,u.username,
		  DATE_FORMAT(u.date_added, '%b %e, %Y  %l:%i:%p') as date_added,  u.online_status, u.user_status, u.email, u.status,
		  u.last_login, u.last_login_ip,
		  DATE_FORMAT(u.last_logout, '%b %e, %Y  %l:%i:%p') as last_logout,

		 ug.user_group_id, ug.title as group_title


		 FROM users u, user_groups ug
		 WHERE u.group_id = ug.user_group_id

		 AND u.user_id != '$user_id'
		 AND (u.status = 0 OR u.status = 1)



		 ORDER BY date_added DESC";
	$r = mysql_query($q);



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


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

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




						<th  > <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title="Check All"></th>


						<th>Name</th>
						<th> Status </th>
						<th>Username</th>
						<th>Active</th>
						<th>User group</th>
						<th>Email</th>
						<th>Last Login Ip</th>
						<th>Last Visit Date</th>
						<th>Registration Date</th>

				</thead>



				<tfoot>
				   		<th > </th>
			  			<th>Name</th>
						<th> Status </th>
						<th>Username</th>
						<th>Active</th>
						<th>User group</th>
						<th>Email</th>
						<th>Last Login Ip</th>
						<th>Last Visit Date</th>
						<th>Registration Date</th>
				</tfoot>

				<tbody>';



		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['user_id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['name']."</a></td>"; //nam eof the user
			$output .= "<td>".users_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['username']."</td>";
			$output .= "<td>". user_status_img($row['user_status'])."</td>";
			$output .= "<td>".$row['group_title']."</td>";
			$output .= "<td>".$row['email']."</td>";
			$output .= "<td>".$row['last_login_ip']."</td>";
			$output .= "<td>".$row['last_logout']."</td>";
			$output .= "<td>".$row['date_added']."</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 users




//function that get trashed  users informatn
function view_trashed_users()
{

	//query the database
	$q = "SELECT u.user_id, u.group_id, CONCAT_WS(' ', u.first_name, u.other_names) as name, u.phone_number,u.username,
		  DATE_FORMAT(u.date_added, '%b %e, %Y  %l:%i:%p') as date_added,  DATE_FORMAT(u.date_modified, '%b %e, %Y  %l:%i:%p') as date_modified,  u.online_status, u.user_status, u.email,
		  u.last_login, u.last_login_ip,
		  DATE_FORMAT(u.date_trashed, '%b %e, %Y  %l:%i:%p') as date_trashed,

		 ug.user_group_id, ug.title as group_title


		 FROM users u, user_groups ug
		 WHERE u.group_id = ug.user_group_id

		 AND u.user_id != '$user_id'
		 AND u.status = 2

		 ORDER BY date_added DESC";
	$r = mysql_query($q);






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

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




						<th  > <input type="checkbox" id="selecctall"  value=""></th>


						<th>Name</th>
						<th>Username</th>
						<th>User group</th>
						<th>Email</th>
						<th>Registration Date</th>
						<th> Last Modified</th>
						<th>Deleted </th>
						<th>

				</thead>



				<tfoot>
				   		<th > </th>
			  			<th>Name</th>
						<th>Username</th>
						<th>User group</th>
						<th>Email</th>
						<th>Registration Date</th>
						<th> Last Modified</th>
						<th>Deleted </th>
						<th></th>
				</tfoot>

				<tbody>';



		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['user_id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['name']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['username']."</td>";
			$output .= "<td>".$row['group_title']."</td>";
			$output .= "<td>".$row['email']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore" id="'.$row['user_id'].'" > Restore</a>
						 <span id="loading"></span></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 users


////fucntion that returns searched users
//function view_search_users($search_item)
//{
//	//get user
//	$user_id = get_user_id();
//
//
//
//	//collect the page number, sorting details and dis[lay per page
//	//no of display per page
//	$display_per_page = 10;
//
//
//	//collect the page variable from url
//	 //determin how many pages there are
//	if (isset($_GET['page']) && is_numeric($_GET['page']))
//	{//already determinwd
//		$pages = $_GET['page'];
//
//	}
//	else
//	{//needs to be determine
//
//
//		//get total projects base user role, mda
//		$q = "SELECT COUNT(user_id)
//
//			  FROM  users
//			  WHERE user_id != '$user_id'";
//		$r = @mysql_query($q);
//
//		$row = @mysql_fetch_array($r, MYSQL_NUM);
//		//records holds the result of the sql
//		$records = $row[0];
//
//
//
//		///calculate the no of pages
//		if($records > $pages)
//		{
//			$pages = ceil($records/$display_per_page);
//		}
//		else
//		{
//			$pages = 1;
//		}
//
//
//
//
//	}//end of pages if
//
//
//
//
//
//	//get the start of the query
//	//determin in the db where to start reurning result
//	if(isset($_GET['start']) && is_numeric($_GET['start']))
//	{
//		$start = $_GET['start'];
//	}
//	else
//	{
//		$start = 0;
//	}
//
//
//	//determine the sorting
//	$sort = (isset($_GET['sort'])?$_GET['sort']: 'date_added DESC');
//
//	//swith the order
//	switch($sort)
//	{
//		case 'name':
//		$order_by = 'name ASC';
//
//		break;
//
//		case 'role_title':
//		$order_by = 'role_title ASC';
//
//		break;
//
//		case 'user_status':
//		$order_by = 'user_status ASC';
//
//		break;
//
//
//		case 'group_title':
//		$order_by = 'group_title ASC';
//
//		break;
//
//
//		case 'email':
//		$order_by = 'email ASC';
//
//		break;
//
//		case 'last_logout':
//		$order_by = 'last_logout ASC';
//
//		break;
//
//
//		case 'date_added':
//		$order_by = 'date_added ASC';
//
//		break;
//
//
//		default:
//		$order_by = 'date_added DESC';
//
//		break;
//
//
//	}
//
//
//	//in the table below result_table stands for resullt fetch throug seraching table(ajax)
//
//	echo
//	'<table id="background-image" class="user tablesorter table-responsive" cellspacing="0">
//	  <thead>
//			 <th class="header" > <input type="checkbox" id="selecctall"  value=""> &nbsp;Check All</th>
//				  <th class="header" ><a href="gateway.php?act=view_users&sort=name">Name</a></th>
//				  <th class="header" ><a href="gateway.php?act=view_users&sort=role_title">Role</a></th>
//				  <th class="header" ><a href="gateway.php?act=view_users&sort=user_status">Status</a></th>
//				  <th class="header" ><a href="gateway.php?act=view_users&sort=group_title">User group</a></th>
//				  <th class="header" ><a href="gateway.php?act=view_users&sort=email">Email</a></th>
//				  <th class="header" ><a href="gateway.php?act=view_users&sort=security_id">Security ID</a></th>
//				  <th class="header" ><a href="gateway.php?act=view_users&sort=last_logout">Last Visit Date</a></th>
//				  <th class="header" ><a href="gateway.php?act=view_users&sort=date_added">Registration Date</a></th>
//
//	  </thead>
//
//	  <tbody>';
//
//
//
//
//
//
//	//query the database
//	$q = "SELECT u.user_id, u.group_id, u.role_id, CONCAT_WS(' ', u.first_name, u.other_names) as name, u.phone_number,
//		  DATE_FORMAT(u.date_added, '%b %e, %Y  %l:%i:%p') as date_added,  u.online_status, u.user_status, u.email, u.security_id,
//		  DATE_FORMAT(u.last_logout, '%b %e, %Y  %l:%i:%p') as last_logout,
//
//		 ug.user_group_id, ug.title as group_title,
//		 r.role_id, r.role_title
//
//		 FROM users u, user_groups ug, roles r
//
//		 WHERE u.group_id = ug.user_group_id
//		 AND u.role_id = r.role_id
//
//		 AND u.user_id != '$user_id'
//
//		 AND (u.first_name LIKE '%$search_item%'
//		 OR   u.other_names LIKE '%$search_item%'
//		 OR   u.phone_number LIKE '%$search_item%'
//		 OR   u.date_added LIKE '%$search_item%'
//		 OR   u.online_status LIKE '%$search_item%'
//		 OR   u.user_status LIKE '%$search_item%'
//		 OR   u.security_id LIKE '%$search_item%'
//		 OR   u.email LIKE '%$search_item%'
//		 OR   u.last_logout LIKE '%$search_item%'
//		 OR   r.role_title LIKE '%$search_item%'
//		 OR   ug.title LIKE '%$search_item%')
//
//		 ORDER BY $order_by
//
//		 LIMIT $start, $display_per_page";
//	$r = mysql_query($q);
//
//	if(mysql_num_rows($r) > 0)
//	{//show table
//
//		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
//		{
//			$output = "<tr>";
//			$output .="<td><input type='checkbox' value='".$row['user_id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
//			$output .= "<td> <a href=''>".$row['name']."</a></td>"; //nam eof the user
//
//			$output .= "<td>".$row['role_title']."</td>"; //group belong to admin or user
//			$output .= "<td>".$row['user_status']."</td>";
//
//			$output .= "<td>".$row['group_title']."</td>";
//			$output .= "<td>".$row['email']."</td>";
//			$output .= "<td>".$row['security_id']."</td>";
//			$output .= "<td>".$row['last_logout']."</td>";
//			$output .= "<td>".$row['date_added']."</td>";
//			$output .= "</tr>";
//
//			echo $output;
//
//		}
//	}
//
//
//	//end table view
//	echo
//	'</tbody>
//    </table>';
//
//
//	//check if pages is greater than 1
//	if($pages > 1)
//	{
//		echo '<p>';
//
//		//determine the current page
//		$current_page = ($start/$display_per_page)+1;
//
//		//if its not a current page display a previous link
//		if($current_page != 1)
//		{
//			echo '<a href="gateway.php?act=view_search_users&search_user='.$search_item.'&sort='.$sort.'&start='.($start - $display_per_page).'&page='.$pages.'" class="nav_button">Previous</a>';
//		}
//
//
//		//make all the numbered pages
//		for($i = 1; $i <= $pages; $i++)
//		{
//			if($i != $current_page)
//			{
//				echo
//				'<a href="gateway.php?act=view_search_users&search_user='.$search_item.'&sort='.$sort.'&start='.(($display_per_page * ($i - 1)))  .'&page='.$pages.'" >' . $i . '</a> ';
//			}
//			else
//			{
//				echo  $i . ' ';
//			}
//		}//end of forloop
//
//
//		//if itsnt d last page get the necxt link
//		if($current_page != $pages)
//		{
//			echo '<a href="gateway.php?act=view_search_users&search_user='.$search_item.'&sort='.$sort.'&start='.($start + $display_per_page).'&page='.$pages.'" class="nav_button">Next</a>';
//
//		}
//	}
//
//
//
//
//
//	echo '</p>';
//
//
//
//
//
//
//
//}//end of view search users




//function that shows roles publish status image
function roles_publish_status_image($status)
{

	$st = $status;

	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_roles" id="publish_rol"
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_roles" id="unpublish_rol"
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}

	return $output;


}//end of function dat shows publish roles image

//function view roles
//function that get users roles
function view_roles()
{


	//query the database
	$q = "SELECT `role_id`, `role_title`, `description`,  DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, status,
		  DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as `date_modified`,
		  `added_by`, `modified_by`  FROM `roles`
		  WHERE status = 0 OR status = 1
		  ORDER BY date_added DESC";
	$r = mysql_query($q);





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


	$output =
	'<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
	  <thead>
			 	  <th > <input type="checkbox" id="selecctall"  value=""> </th>
				  <th >Role</th>
				  <th >Status</th>
				  <th >Description</th>
				  <th >Date Added</th>
				  <th >Date Modified</th>
				  <th >Added by</th>
				  <th >Modified  by</th>




	  </thead>





	  <tbody>';





		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['role_id']."' name='role[]' id='role' class='checkbox1'/></td>" ;


			$output .= "<td>".$row['role_title']."</td>";
			$output .= "<td>".roles_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['description']."</td>";

			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</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 roles


//function that get view trashed roles
function view_trashed_roles()
{


	//query the database
	$q = "SELECT `role_id`, `role_title`, `description`,  DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, status,
		  DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as `date_modified`,
		  DATE_FORMAT(date_trashed, '%b %e, %Y  %l:%i:%p') as `date_trashed`, `added_by`, `modified_by`  FROM `roles`
		  WHERE status = 2
		  ORDER BY date_added DESC";
	$r = mysql_query($q);





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


	$output =
	'<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
	  <thead>
			 	  <th> <input type="checkbox" id="selecctall"  value=""> </th>
				  <th>Role</th>
				  <th>Description</th>
				  <th>Date Added</th>
				  <th>Date Modified</th>
				  <th>Added by</th>
				  <th>Modified  by</th>
				  <th>Deleted</th>
				  <th></th>



	  </thead>





	  <tbody>';





		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['role_id']."' name='role[]' id='role' class='checkbox1'/></td>" ;


			$output .= "<td>".$row['role_title']."</td>"; //group belong to admin or user
			$output .= "<td>".$row['description']."</td>";

			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_role" id="'.$row['role_id'].'" > Restore</a>
						 <span id="loading"></span></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 trashed roles



//function that shows user_groups publish status image
function user_groups_publish_status_image($status)
{

	$st = $status;

	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_user_groups" id="publish_ug"
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_user_groups" id="unpublish_ug"
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}

	return $output;


}//end of function dat shows publish user_groups image


//user groups
function view_user_groups()
{
	//query the database
	$q = "SELECT `user_group_id`, `title`, `description`, `header_menu`, `toolbar_menu`, `home_menu`,
		  DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as `date_modified`, `added_by` , modified_by, status
		  FROM `user_groups`
		  WHERE status = 0 OR status = 1
		  ORDER BY date_added DESC";
	$r = mysql_query($q);



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



		$output =
		'<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		  <thead>
				 	  <th> <input type="checkbox" id="selecctall"  value=""></th>
					  <th>Title</th>
					  <th>Status</th>
					  <th>Description</th>
					  <th>Header Menu Privs.</th>
					  <th>Toolbar Menu Privs.</th>
					  <th>Home Menu Privs.</th>
					  <th>Date</a></th>
					  <th>Date Modified</th>
					  <th>Added by</th>
					  <th>Modified  by</th>


		  </thead>

		  <tbody>';


		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['user_group_id']."' name='user_group[]' id='user_group' class='checkbox1'/></td>" ;
			$output .= "<td>".$row['title']."</td>"; //group belong to admin
			$output .= "<td>".user_groups_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['header_menu']."</td>";
			$output .= "<td>".$row['toolbar_menu']."</td>";
			$output .= "<td>".$row['home_menu']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</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 user groups



//user trashed  groups
function view_trashed_user_groups()
{
	//query the database
	$q = "SELECT `user_group_id`, `title`, `description`, `header_menu`, `toolbar_menu`, `home_menu`,
		  DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as `date_modified`,
		  DATE_FORMAT(date_trashed, '%b %e, %Y  %l:%i:%p') as `date_trashed`, `added_by` , modified_by , status
		  FROM `user_groups`
		  WHERE status = 2
		  ORDER BY date_added DESC";
	$r = mysql_query($q);



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



		$output =
		'<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		  <thead>
				 	  <th> <input type="checkbox" id="selecctall"  value=""></th>
					  <th>Title</th>
					  <th>Description</th>
					  <th>Header Menu Privs.</th>
					  <th>Toolbar Menu Privs.</th>
					  <th>Home Menu Privs.</th>
					  <th>Date</a></th>
					  <th>Date Modified</th>
					  <th>Added by</th>
					  <th>Modified  by</th>
					  <th>Deleted</th>
					  <th></th>


		  </thead>

		  <tbody>';


		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['user_group_id']."' name='user_group[]' id='user_group' class='checkbox1'/></td>" ;
			$output .= "<td>".$row['title']."</td>"; //group belong to admin or user
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['header_menu']."</td>";
			$output .= "<td>".$row['toolbar_menu']."</td>";
			$output .= "<td>".$row['home_menu']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_user_group" id="'.$row['user_group_id'].'" > Restore</a>
						 <span id="loading"></span></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 trashed user groups


//function select options
function select_status($status)
{

			if($status == '0')
			{
				$output = '<option value="0" selected>Published</option>';
				$output .= '<option value="1" > Unpublished</option>';
				$output .= '<option value="2" > Trashed</option>';
				$output .= '<option value="3" > Archived</option>';
			}
			else if ($status == '1')
			{
				$output = '<option value="0">Published</option>';
				$output .= '<option value="1"  selected > Unpublished</option>';
				$output .= '<option value="2" > Trashed</option>';
				$output .= '<option value="3" > Archived</option>';
			}
			else if ($status == '2')
			{
				$output = '<option value="0">Published</option>';
				$output .= '<option value="1" > Unpublished</option>';
				$output .= '<option value="2"   selected > Trashed</option>';
				$output .= '<option value="3" > Archived</option>';
			}
			else if ($status == '3')
			{
				$output = '<option value="0">Published</option>';
				$output .= '<option value="1"> Unpublished</option>';
				$output .= '<option value="2"> Trashed</option>';
				$output .= '<option value="3" selected> Archived</option>';
			}
			else
			{
				$output = '<option value="0">Published</option>';
				$output .= '<option value="1"> Unpublished</option>';
				$output .= '<option value="2"> Trashed</option>';
				$output .= '<option value="3"> Archived</option>';

			}



			return $output;

} // select statsu


//function select role
function select_role($role)
{
	$r = mysql_query("SELECT role_id, role_title FROM roles  ORDER BY role_title");
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			if($role == $row['role_id'])
			{
				$output = "<option value=\"$row[role_id]\" selected>";
				$output .=$row['role_title'];
				$output .="</option>";

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


			echo $output;
		}
	}
	else
	{

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

			echo $output;
	}
}
//select role



//function select group and auto select if it has a value
function select_group($group)
{
	$r = mysql_query("SELECT user_group_id, title FROM user_groups  ORDER BY title");
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			if($group == $row['user_group_id'])
			{
				$output = "<option value=\"$row[user_group_id]\" selected>";
				$output .=$row['title'];
				$output .="</option>";

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

			echo $output;
		}
	}
	else
	{

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

			echo $output;
	}
}



//function view news

function view_news()
{


	//query the database
	$q = "SELECT id, title, description, image,	news_carts,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added, status,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  news
		 WHERE status = 0 OR status = 1
		 ORDER BY date_added ASC";
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"> </th>
						<th>Title</th>
						<th>Status</th>
						<th>Description</th>
						<th>Images</th>
						<th>Carts</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>


			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"> </th>
						<th>Title</th>
						<th>Status</th>
						<th>Description</th>
						<th>Images</th>
						<th>Carts</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='news[]' id='news' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
		    $output .= "<td>".news_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= '<td><img class="img-responsive img-thumbnail" src="uploads/pictures/news_images/'.$row['image'].'" style="width:150px; height:80px"/><br/>
						'.$row['image'].'</td>';
		    $output .= "<td>".$row['news_carts']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</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 news

//fucntion show news carts
//function show_news_carts($carts)
//{
//	$new_carts = explode(',' , $carts);
//	foreach ($new_carts as $values)
//	{
//		echo "$values <br/>";
//	}
//}


//function view trashed news
function view_trashed_news()
{


	//query the database
	$q = "SELECT id, title, description, image,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,  DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by
		 FROM  news
		 WHERE status = 2
		 ORDER BY date_added DESC";
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
						<th>Title</th>
						<th>Description</th>
						<th>Images</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Deleted</th>
						<th></th>


			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
						<th>Title</th>
						<th>Description</th>
						<th>Images</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Deleted</th>
						<th></th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='news[]' id='news' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";

			$output .= "<td>".$row['description']."</td>";
			$output .= '<td><img class="img-responsive img-thumbnail" src="uploads/pictures/news_images/'.$row['image'].'" style="width:150px; height:80px"/>
						'.$row['image'].'</td>';
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_news" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></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 trashed  news

//function that shows news publish status image
function news_publish_status_image($status)
{

	$st = $status;

	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_news" id="publish_n"
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_news" id="unpublish_n"
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}

	return $output;


}//end of function dat shows publish image

//function to show news cart
function select_news_cart($carts)
{
	$checked_carts = explode(',' , $carts);

	$query = "SELECT * FROM news_carts ORDER BY title";

	$result = mysql_query($query);

	if(mysql_num_rows($result) > 0 )
	{
		while ($row_carts = mysql_fetch_array($result, MYSQL_ASSOC))
		{

			//echo "<p><input type='checkbox' name='carts[]' value=\"$row_carts[title]\" />&nbsp;&nbsp;".ucfirst($row_carts['title']).
			//"</p>";

			if(in_array($row_carts['title'],$checked_carts))
			{
				echo "<p><input type='checkbox' name='carts[]' value=\"$row_carts[title]\" checked />&nbsp;&nbsp;"
				.ucfirst($row_carts['title'])."</p>";

			}
			else
			{
				echo "<p><input type='checkbox' name='carts[]' value=\"$row_carts[title]\" />&nbsp;&nbsp;"
				.ucfirst($row_carts['title'])."</p>";

			}

		}
	}
	else

	{
			echo '<span class="label label-danger">No cartegories Added Yet!</span>';
	}

}
//end of function that shows carts

//checked selected news
function selected_news_cart($carts)
{
	//accept an array and check whc is checked
	//$carts = $row['news_carts'];

	$checked_carts = explode(',' , $carts);


	$query = "SELECT * FROM news_carts ORDER BY title";

	$result = mysql_query($query);


	if(mysql_num_rows($result) > 0 )
	{
		while ($row_carts = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			if(in_array($row_carts['title'],$checked_carts))
			{
				echo "<p><input type='checkbox' name='carts[]' value=\"$row_carts[title]\" checked />&nbsp;&nbsp;"
				.ucfirst($row_carts['title'])."</p>";

			}
			else
			{
				echo "<p><input type='checkbox' name='carts[]' value=\"$row_carts[title]\" />&nbsp;&nbsp;"
				.ucfirst($row_carts['title'])."</p>";

			}


		}
	}
	else

	{
				echo '<span class="label label-danger">No cartegories Added Yet!</span>';
	}
}


//function view events

function view_events()
{


	//query the database
	$q = "SELECT id, title, description, image, status,	venue, start_time, end_time, event_date,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by
		 FROM  events
		 WHERE status = 1 OR status = 0

		 ORDER BY date_added DESC";
	$r = mysql_query($q);

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

		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">  			           <thead>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Status</th>
				 <th>Description</th>
				 <th>Image</th>
				 <th>Venue</th>
				 <th>Event Date</th>
				 <th>Event Time</th>
                 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Modified By</th>

		  </thead>

		  <tfoot>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Status</th>
				 <th>Description</th>
				 <th>Image</th>
				 <th>Venue</th>
				 <th>Event Date</th>
				 <th>Event Time</th>
                 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Modified By</th>

		  </tfoot>

		  <tbody>';


		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='event[]' id='event' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".event_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= '<td><img class="img-responsive img-thumbnail" src="uploads/pictures/events_images/'.$row['image'].'"  style="width:150px; height:150px;" />
						'.$row['image'].'</td>';
			$output .= "<td>".$row['venue']."</td>";
			$output .= "<td>".$row['event_date']."</td>";
			$output .= "<td>".$row['start_time'].' - '.$row['end_time']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</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 events

function view_trashed_events()
{


	//query the database
	$q = "SELECT id, title, description, image, status,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added, DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by
		 FROM  events
		 WHERE status = 2

		 ORDER BY date_added DESC";
	$r = mysql_query($q);

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

		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">  			           <thead>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Description</th>
				 <th>Image</th>
                 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Modified By</th>
				 <th>Deleted</th>
				 <th></th>


		  </thead>

		  <tfoot>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Description</th>
				 <th>Image</th>
                 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Modified By</th>
				 <th>Deleted</th>
				 <th></th>

		  </tfoot>

		  <tbody>';


		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='event[]' id='event' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= '<td><img class="img-responsive img-thumbnail" src="uploads/pictures/events_images/'.$row['image'].'"  style="width:200px; height:150px;" />
						'.$row['image'].'</td>';
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_event" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></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 trashed events

//function that shows events publish status image
function event_publish_status_image($status)
{

	$st = $status;

	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_events" id="publish_ev"
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_events" id="unpublish_ev"
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}

	return $output;


}//end of function dat shows events publish image


//begin pictures
function view_pictures()
{


	//query the database
	$q = "SELECT id , title,description, image, status,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  pictures
		  WHERE status = 0 OR status = 1
		 ORDER BY date_added DESC";
	$r = mysql_query($q);

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

		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">  			           <thead>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"> </th>
			     <th>Title</th>
				 <th>Status</th>
				 <th>Description</th>
				 <th>Image</th>
                 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Modified By</th>

		  </thead>

		  <tfoot>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Status</th>
				 <th>Description</th>
				 <th>Image</th>
                 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Modified By</th>


		  </tfoot>

		  <tbody>';


		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='picture[]' id='picture' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".picture_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= '<td><img class="img-responsive img-thumbnail" src="uploads/pictures/gallery_pictures/'.$row['image'].'"
			style="width:150px; height:150px;" /><br/>'.$row['image'].'</td>';
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</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 pictures

//begin trashed pictures
function view_trashed_pictures()
{


	//query the database
	$q = "SELECT id , title,description, image, status,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,  DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  pictures
		 WHERE status = 2
		 ORDER BY date_added DESC";
	$r = mysql_query($q);

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

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

				 <th>Description</th>
				 <th>Image</th>
                 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Modified By</th>
				 <th>Deleted</th>
				 <th></th>

		  </thead>

		  <tfoot>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>

				 <th>Description</th>
				 <th>Image</th>
                 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Modified By</th>
				 <th>Deleted</th>
				 <th></th>


		  </tfoot>

		  <tbody>';


		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='picture[]' id='picture' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= '<td><img class="img-responsive img-thumbnail" src="uploads/pictures/gallery_pictures/'.$row['image'].'"
			style="width:150px; height:150px;" /><br/>'.$row['image'].'</td>';
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_picture" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></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 trashed  pictures



//function that shows pictures publish status image
function picture_publish_status_image($status)
{

	$st = $status;

	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_pictures" id="publish_pic"
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_pictures" id="unpublish_pic"
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}

	return $output;


}//end of function dat shows pictures publish image



//begin videos
function view_videos()
{


	//query the database
	$q = "SELECT id , title, youtube_link, description, image,  status,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  videos
		 WHERE status = 0 OR status = 1

		 ORDER BY date_added DESC";
	$r = mysql_query($q);

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

		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">  			           <thead>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Status</th>
				 <th>Youtube <br/> Link</th>
				 <th>Description</th>
				 <th>Image</th>
                 <th>Video</th>
				 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Mod. By</th>

		  </thead>

		  <tfoot>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Status</th>
				 <th>Youtube <br/> Link</th>
				 <th>Description</th>
				 <th>Image</th>
				 <th>Video</th>
				 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Mod. By</th>

		  </tfoot>

		  <tbody>';


		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='video[]' id='video' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".video_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['youtube_link']."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= '<td><img class="img-responsive img-thumbnail" src="uploads/pictures/video_pictures/'.$row['image'].'"
			style="width:150px; height:150px;" />
						'.$row['image'].'</td>';
			$output .= "<td>add youtube link here to see</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</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 videos


//begin trashed videos
function view_trashed_videos()
{


	//query the database
	$q = "SELECT id , title, youtube_link, description, image,  status,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,  DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  videos
		 WHERE status = 2

		 ORDER BY date_added DESC";
	$r = mysql_query($q);

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

		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">  			           <thead>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Youtube <br/> Link</th>
				 <th>Description</th>
				 <th>Image</th>
                 <th>Video</th>
				 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Deleted</th>
				 <th></th>


		  </thead>

		  <tfoot>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Youtube <br/> Link</th>
				 <th>Description</th>
				 <th>Image</th>
				 <th>Video</th>
				 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Deleted</th>
				 <th></th>

		  </tfoot>

		  <tbody>';


		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='video[]' id='video' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['youtube_link']."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= '<td><img class="img-responsive img-thumbnail" src="uploads/pictures/video_pictures/'.$row['image'].'"
			style="width:150px; height:150px;" />
						'.$row['image'].'</td>';
			$output .= "<td>add youtube link here to see</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_video" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></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  trashed videos

//function that shows videos publish status image
function video_publish_status_image($status)
{

	$st = $status;

	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_videos" id="publish_vid"
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_videos" id="unpublish_vid"
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}

	return $output;


}//end of function dat shows videos publish image


//function to show video cart
function select_video_cart($carts)
{
	$checked_carts = explode(',' , $carts);

	$query = "SELECT * FROM video_carts ORDER BY title";

	$result = mysql_query($query);

	if(mysql_num_rows($result) > 0 )
	{
		while ($row_carts = mysql_fetch_array($result, MYSQL_ASSOC))
		{

			//echo "<p><input type='checkbox' name='carts[]' value=\"$row_carts[title]\" />&nbsp;&nbsp;".ucfirst($row_carts['title']).
			//"</p>";

			if(in_array($row_carts['title'],$checked_carts))
			{
				echo "<p><input type='checkbox' name='carts[]' value=\"$row_carts[title]\" checked />&nbsp;&nbsp;"
				.ucfirst($row_carts['title'])."</p>";

			}
			else
			{
				echo "<p><input type='checkbox' name='carts[]' value=\"$row_carts[title]\" />&nbsp;&nbsp;"
				.ucfirst($row_carts['title'])."</p>";

			}

		}
	}
	else

	{
			echo '<span class="label label-danger">No cartegories Added Yet!</span>';
	}

}
//end of function that shows carts

//checked selected news
function selected_video_cart($carts)
{
	//accept an array and check whc is checked
	//$carts = $row['news_carts'];

	$checked_carts = explode(',' , $carts);


	$query = "SELECT * FROM video_carts ORDER BY title";

	$result = mysql_query($query);


	if(mysql_num_rows($result) > 0 )
	{
		while ($row_carts = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			if(in_array($row_carts['title'],$checked_carts))
			{
				echo "<p><input type='checkbox' name='carts[]' value=\"$row_carts[title]\" checked />&nbsp;&nbsp;"
				.ucfirst($row_carts['title'])."</p>";

			}
			else
			{
				echo "<p><input type='checkbox' name='carts[]' value=\"$row_carts[title]\" />&nbsp;&nbsp;"
				.ucfirst($row_carts['title'])."</p>";

			}


		}
	}
	else

	{
				echo '<span class="label label-danger">No cartegories Added Yet!</span>';
	}
}




//function view faculties
function view_faculties()
{


	//query the database
	$q = "SELECT id, title, description, code, status, faculty_image, dean_name, dean_picture, email, location, phone_contacts, pdf_details,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  faculties
		 WHERE status = '0' OR status = '1'
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall"  value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>Status</th>
						<th>Image</th>
						<th>Email</th>
						<th>Contacts</th>
						<th>Location</th>
						<th>Description</th>
						<th>PDF File</th>
						<th>Dean\'s Name</th>
						<th>Dean\'s Picture</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>


			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  value=""></th>
						<th>Title</th>
						<th>Code</th>
						<th>Status</th>
						<th>Image</th>
						<th>Email</th>
						<th>Contacts</th>
						<th>Location</th>
						<th>Description</th>
						<th>PDF File</th>
						<th>Dean\'s Name</th>
						<th>Dean\'s Picture</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='faculty[]' id='faculty' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['code']."</td>";
			$output .= "<td>".faculty_publish_status_image($row['status'])."</td>";
			$output .= "<td><img src='../faculties/pictures/".$row['faculty_image']."' height='70px' width='150px' /> </td>";
			$output .= "<td>".$row['email']."</td>";
			$output .= "<td>".$row['phone_contacts']."</td>";
			$output .= "<td>".$row['location']."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td><a class='btn btn-sm btn-success'  href='../faculties/uploads/pdf_files/".$row['pdf_details']."' target='_blank' title='Download this file for more details' data-toggle='tooltip' /> Download PDF</a></td>";
			$output .= "<td>".$row['dean_name']."</td>";
			$output .= "<td><img src='../faculties/deans/".$row['dean_picture']."' height='70px' width='70px' /> </td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</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 faculties


//function view trashed faculties
function view_trashed_faculties()
{


	//query the database
	$q = "SELECT id, title, description, code, status,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added, DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  faculties
		 WHERE status = 2
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall"  value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th>Deleted</th>
						<th></th>


			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  value=""></th>
						<th>Title</th>
						<th>Code</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th>Deleted</th>
						<th></th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='faculty[]' id='faculty' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['code']."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_faculty" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></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 trashed faculties


//function that shows faculty publish status image
function faculty_publish_status_image($status)
{

	$st = $status;

	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_faculties" id="publish_fac"
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_faculties" id="unpublish_fac"
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}

	return $output;


}//end of function dat shows publish image



//function view departments
function view_departments()
{


	//query the database
	$q = "SELECT id, title, description, status,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  departments
		 WHERE status = '0' OR status = '1'
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall"  value=""> </th>
						<th>Title</th>
					    <th>Status</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>


			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  value=""></th>
						<th>Title</th>
					    <th>Status</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='department[]' id='department' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".department_publish_status_image($row['status'])."</td>";
			//$output .= "<td>".get_faculty_title($row['faculty_id'])."</td>";
			//$output .= "<td><img src='../departments/hods/".$row['hod_picture']."' height='100px' width='100px' /> </td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</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 departments

//function view  trashed departments
function view_trashed_departments()
{


	//query the database
	$q = "SELECT id, title, description, code, 	  status,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added, DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  departments
		 WHERE status = 2
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall"  value=""> </th>
						<th>Title</th>
						<th>Status</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th> Deleted </th>
						<th></th>


			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  value=""></th>
						<th>Title</th>
						<th>Status</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th> Deleted </th>
						<th></th>


			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='department[]' id='department' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".department_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['description']."</td>";
			//$output .= "<td>".get_faculty_title($row['faculty_id'])."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_department" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></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 trashed departments


//function that shows department publish status image
function department_publish_status_image($status)
{

	$st = $status;

	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_departments" id="publish_dp"
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_departments" id="unpublish_dp"
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}

	return $output;


}//end of function dat shows publish image  for departments


//function view programmes
function view_programmes()
{


	//query the database
	$q = "SELECT id, title,type_id,duration,maximum_duration,maximum_credit_load,
		  minimum_credit_load, description, code, department_id, status,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  programmes
		 WHERE status = '0' OR status ='1'
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall"  value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>status</th>
						<th>Department</th>
						<th>Prog. Type</th>
						<th>Duration  Duration  </th>
						<th>Max. Duration</th>
						<th>Min. Credit Load / Max. Credit Load</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>

			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>status</th>
						<th>Department</th>
						<th>Prog. Type</th>
						<th>Duration  Duration  </th>
						<th>Max. Duration</th>
						<th>Min. Credit Load / Max. Credit Load</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='programme[]' id='programme' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['code']."</td>";
			$output .= "<td>".programme_publish_status_image($row['status'])."</td>";
			$output .= "<td>".get_department_title($row['department_id'])."</td>";
			$output .= "<td>".show_programme_type($row['type_id'])."</td>";
			$output .= "<td>".$row['duration']." </td>";
			$output .= "<td>".$row['maximum_duration']."</td>";
			$output .= "<td>".$row['maximum_credit_load']." / ".$row['minimum_credit_load']."</td>";
			//$output .= "<td><img src='../departments/programmes/pictures/".$row['picture']."' height='100px' width='170px' /> </td>";
			//$output .= "<td>".$row['philosophy_history']."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</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 courses



//function view trashed programmes
function view_trashed_programmes()
{


	//query the database
	$q = "SELECT id, title, description, code, department_id, status,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,  DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  programmes
		 WHERE status = '2'
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall"  value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>Department</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th>Deleted</th>
						<th></th>

			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>Department</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th>Deleted</th>
						<th></th>


			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='programme[]' id='programme' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['code']."</td>";
			$output .= "<td>".get_department_title($row['department_id'])."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_programme" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></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  trashed programmes

//function that shows programme publish status image
function programme_publish_status_image($status)
{

	$st = $status;

	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_programmes" id="publish_pm"
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_programmes" id="unpublish_pm"
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}

	return $output;


}//end of function dat shows publish image  for programmes



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

		if ($pt == '1')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1" selected > PRE -NCE</option>';
			$output .= '<option value="2" > NCE </option>';
			$output .= '<option value="3" > NCE LVSP </option>';
			$output .= '<option value="4" > DEGREE </option>';



		}
		else if ($pt == '2')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1">PRE - NCE</option>';
			$output .= '<option value="2" selected > NCE </option>';
			$output .= '<option value="3" > NCE LVSP </option>';
			$output .= '<option value="4" > DEGREE </option>';



		}
		else if ($pt == '3')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"> PRE-NCE</option>';
			$output .= '<option value="2"> NCE </option>';
			$output .= '<option value="3" selected > NCE LVSP </option>';
			$output .= '<option value="4" > DEGREE </option>';



		}else if ($pt == '4')
		{
			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1"> PRE-NCE</option>';
			$output .= '<option value="2"> NCE </option>';
			$output .= '<option value="3" > NCE LVSP </option>';
			$output .= '<option value="4" selected> DEGREE </option>';



		}
		else
		{

			$output = '<option value="0"  selected > -- Please Select --</option>';
			$output .= '<option value="1"> PRE-NCE</option>';
			$output .= '<option value="2" > NCE </option>';
			$output .= '<option value="3" > NCE LVSP </option>';
			$output .= '<option value="4" > DEGREE </option>';

		}

	return $output;

}
//end of select programme_type







//function view courses
function view_courses()
{

	//comment incase


	//query the database
	$q = "SELECT id, title, description, programme_id, department_id, code, unit, level, semester, status, course_type, course_description,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,type_id,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  courses
		 WHERE status = 0 OR status = 1
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall" data-toggle = "tooltip" title = "Check All"   value=""></th>
						<th>Title</th>
						<th>Code</th>
						<th>Status</th>
						<th>Type</th>
						<th>Prog. Type</th>
						<th>Department</th>
						<th>Programme</th>
						<th>Unit</th>
						<th>Level</th>
						<th>Semester</th>
						<th>C. Description</th>
						<th>N/Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>

			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  data-toggle = "tooltip" title = "Check All" value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>Status</th>
						<th>Type</th>
						<th>Prog. Type</th>
						<th>Department</th>
						<th>Programme</th>
						<th>Unit</th>
						<th>Level</th>
						<th>Semester</th>
						<th>C. Description</th>
						<th>N/Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='course[]' id='course' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['code']."</td>";
			$output .= "<td>".course_publish_status_image($row['status'])."</td>";
			$output .= "<td>".course_type($row['course_type'])."</td>";
			$output .= "<td>".show_programme_type($row['type_id'])."</td>";
            $output .= "<td>".get_department_title($row['department_id'])."</td>";
			$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
			$output .= "<td>".$row['unit']."</td>";
			$output .= "<td>".$row['level']."</td>";
			$output .= "<td>".$row['semester']."</td>";
			$output .= "<td>".$row['course_description']."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</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 courses

//function view trashed scourses
function view_trashed_courses()
{

	//comment incase


	//query the database
	$q = "SELECT id, title, description, programme_id, department_id, code, unit, level, semester, status,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added, DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  courses
		  WHERE status = 2
		  ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);

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



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

			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  data-toggle = "tooltip" title = "Check All" value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>Department</th>
						<th>Programme</th>
						<th>Unit</th>
						<th>Level</th>
						<th>Semester</th>
						<th>Added By</th>
						<th>Deleted</th>
						<th></th>


			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='course[]' id='course' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['code']."</td>";
			$output .= "<td>".get_department_title($row['department_id'])."</td>";
			$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
			$output .= "<td>".$row['unit']."</td>";
			$output .= "<td>".$row['level']."</td>";
			$output .= "<td>".$row['semester']."</td>";
			//$output .= "<td>".$row['description']."</td>";
//			$output .= "<td>".$row['date_added']."</td>";
//			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_course" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></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 trashed courses



//function that shows course publish status image
function course_publish_status_image($status)
{

	$st = $status;

	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_courses" id="publish_cs"
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_courses" id="unpublish_cs"
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}

	return $output;


}//end of function dat shows publish image  for courses


//function that shows course type
function course_type($status)
{

	$st = $status;

	if($st == '1')
	{
		$output =  'CORE';
	}
	else if($st == '2')
	{
		$output =  'ELECTIVE';
	}
	else
	{
		$output = '';
	}

	return $output;


}//end of function dat shows course type




//function view programmes courses
function view_programmes_courses()
{

	//comment incase


	//query the database
	$q = "SELECT id, programme_type_id,  programme_id, department_id, course_id, level,  status, token,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  programmes_courses_nce
		 WHERE status = '0' OR status = '1'
		 GROUP BY token
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall" data-toggle = "tooltip" title = "Check All"   value=""></th>
						<th>Level</th>
						<th>Programme</th>
						<th>Department</th>
						<th>School</th>
						<th>Prog. Type</th>
						<th>Courses Attcahed</th>
						<th>Status </th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th></th>

			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  data-toggle = "tooltip" title = "Check All" value=""> </th>
						<th>Level</th>
						<th>Programme</th>
						<th>Department</th>
						<th>School</th>
						<th>Prog. Type</th>
						<th>Courses Attcahed</th>
						<th>Status </th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th></th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['token']."' name='programme_course[]' id='programme_course' class='checkbox1'/></td>" ;

			$output .= "<td>".$row['level']."</td>";
			$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
			$output .= "<td>".get_department_title($row['department_id'])."</td>";
			$output .= "<td>".get_school_title($row['school_id'])."</td>";
			$output .= "<td>".show_programme_type($row['programme_type_id'])."</td>";
            $output .= "<td style='width:20%;'>".get_courses_for_level_programmes($row['level'], $row['programme_id'])."</td>";
			$output .= "<td>".programme_course_publish_status_image($row['status'])."</td>";
			//$output .= "<td>".course_type($row['course_type'])."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td><a href='gateway.php?act=add_supplementry_programmes_courses&id=".$row['token']."'> <i class='text-success glyphicon glyphicon-plus' data-toggle='tooltip' title='Click here add more courses'></i></a></td>";
			$output .= "</tr>";


		}
	}
	else
	{//show the msg

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


	}



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





	return $output;




}//end of view programme courses



//function view trashed  programmes courses
function view_trashed_programmes_courses()
{

	//comment incase


	//query the database
	$q = "SELECT id, programme_type_id, programme_id, department_id, course_id, level,  status, token,
		 DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,added_by
		 FROM  programmes_courses_nce
		 WHERE status = '2'
		 GROUP BY token
		 ORDER BY date_trashed DESC";
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall" data-toggle = "tooltip" title = "Check All"   value=""></th>
						<th>Level</th>
						<th>Programme</th>
						<th>Programme Type</th>
						<th>Department</th>
						<th>Courses Attcahed</th>

						<th>Added By</th>
						<th>Date Trashed</th>
						<th></th>

			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  data-toggle = "tooltip" title = "Check All" value=""> </th>
						<th>Level</th>
						<th>Programme</th>
						<th>Programme Type</th>
						<th>Department</th>
						<th>Courses Attcahed</th>
						<th>Added By</th>
						<th>Date Trashed</th>
						<th></th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['token']."' name='programme_course[]' id='programme_course' class='checkbox1'/></td>" ;

			$output .= "<td>".$row['level']."</td>";
			$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
			$output .= "<td>".show_programme_type($row['programme_type_id'])."</td>";
			$output .= "<td>".get_department_title($row['department_id'])."</td>";
			$output .= "<td style='width:20%;'>".get_courses_for_level_programmes($row['level'], $row['programme_id'])."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_programme_course" id="'.$row['token'].'" > Restore</a>
						 <span id="loading"></span></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 programme courses trashed

//function that shows programmes course publish status image
function programme_course_publish_status_image($status)
{

	$st = $status;

	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_programmes_courses" id="publish_pcs"
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_programmes_courses" id="unpublish_pcs"
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}

	return $output;


}//end of function dat shows publish image  for programmes courses

//function to get list pf courses attach to level and programmes
function get_courses_for_level_programmes($level, $programme)
{

	//comment incase


	//query the database
	$q = "SELECT c.id as cid, c.title, c.description, c.programme_id, c.department_id, c.code, c.unit, c.level,  c.status,
			pc.programme_id, pc.course_id, pc.department_id, pc.level, pc.status

		 FROM  courses c , programmes_courses_nce pc
		 WHERE
		 c.id = pc.course_id
		 AND pc.level = '$level'
		 AND pc.programme_id = '$programme'
		 AND pc.status = 0

		 ORDER BY c.code ASC";
	$r = mysql_query($q);

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



		  $output = '';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "".$row['code']."(".$row['unit']."), ";




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




}//end of get list of courses attched to a particular level and programme


//function that filters the ip
function filter_ip()
{

  $ip = getenv('REMOTE_ADDR'); //get user ip
  $ip=str_replace('.','',$ip); //str replace of dot

  $query_ip= mysql_query("SELECT * FROM ip_filter WHERE ips='$ip'") or die(mysql_error()); //query
  if($query_ip){

    $row=mysql_num_rows($query_ip);
    if($row==0){

      header('location:autorize_message/'); // show authorize message
    }

  }
} //end of filter the ip


//view ips
//function that get ips informatn
function view_ips()
{

	//query the database
	$q = "SELECT `id`, `ips`, `title`, `description`, `status`, `activate`,
		 DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as date_modified,
		 `added_by`, `modified_by`
		 FROM `ip_filter`
		 WHERE status = 1 OR status = 0

		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);



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


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

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




						<th  > <input type="checkbox" id="selecctall"  data-toggle = "tooltip" title = "Check All" value=""></th>
			  			<th>Title</th>tle
						<th>IPs</th>

						<th>Description</th>
						<th>Active Status</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>

				</thead>



				<tfoot>


						<th  > <input type="checkbox" id="selecctall" data-toggle = "tooltip" title = "Check All"  value=""></th>
			  			<th>Title</th>
						<th>IPs</th>
						<th>Description</th>
						<th>Active Status</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
				</tfoot>

				<tbody>';



		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='ip[]' id='ip' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['ips']."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".ip_status_img($row['activate'])."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</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  ips


//view trashed ips
//function that get ips informatn
function view_trashed_ips()
{

	//query the database
	$q = "SELECT `id`, `ips`, `title`, `description`, `status`, `activate`, DATE_FORMAT(date_trashed, '%b %e, %Y  %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as date_modified,
		 `added_by`, `modified_by`
		 FROM `ip_filter`
		 WHERE status = 2

		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);



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


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

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

				     	<th  > <input type="checkbox" id="selecctall"  data-toggle = "tooltip" title = "Check All" value=""></th>
			  			<th>Title</th>tle
						<th>IPs</th>
						<th>Description</th>
						<th>Active Status</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th>Deleted </th>
						<th></th>

				</thead>



				<tfoot>


						<th  > <input type="checkbox" id="selecctall" data-toggle = "tooltip" title = "Check All"  value=""></th>
			  			<th>Title</th>
						<th>IPs</th>
						<th>Description</th>
						<th>Active Status</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th>Deleted </th>
						<th></th>
				</tfoot>

				<tbody>';



		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='ip[]' id='ip' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['ips']."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".ip_status_img($row['activate'])."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_ip" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></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 trashed ips

//ip image status
//by passing the blocked status

function ip_status_img($status)
{
	$st = $status;

	if($st == 1)
	{
		return '<img src="images/active.png" data-toggle="tooltip" title="Active"/>';
	}
	else
	{
		return '<img src="images/blocked.png" data-toggle="tooltip" title="Blocked" />';
	}
}





//function that shows ips publish status image
function ip_publish_status_image($status)
{

	$st = $status;

	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small disabled" value="unpublish_ips" id="publish_ip"
				data-toggle="tooltip" data-placement="right" title="Published" disabled="disabled">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small disabled" value="publish_ips" id="unpublish_ip"
					data-toggle="tooltip" data-placement="right" title="Unpublished" disabled="disabled">';
	}

	return $output;


}//end of function dat shows publish image


//function that get control boxes informatn
function view_control_boxs()
{

	//query the database
	$q = "SELECT `id`, `controls_value`, `title`, `description`, `status`, `active`,
		 DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as date_modified,
		 `added_by`, `modified_by`
		 FROM `controls`
		 WHERE status = 1 OR status = 0

		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);



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


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

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




						<th  > <input type="checkbox" id="selecctall"  data-toggle = "tooltip" title = "Check All" value=""></th>
			  			<th>Title</th>
						<th>Controls</th>

						<th>Description</th>
						<th>Active Status</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>

				</thead>



				<tfoot>


						<th  > <input type="checkbox" id="selecctall" data-toggle = "tooltip" title = "Check All"  value=""></th>
			  			<th>Title</th>
						<th>Controls</th>
						<th>Description</th>
						<th>Active Status</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
				</tfoot>

				<tbody>';



		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='control_box[]' id='ip' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['controls_value']."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".control_box_status_img($row['active'])."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</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  control boxes

//function that get control_boxs informatn
function view_trashed_control_boxs()
{

	//query the database
	$q = "SELECT `id`, `controls_value`, `title`, `description`,  `active`, DATE_FORMAT(date_trashed, '%b %e, %Y  %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as date_modified,
		 `added_by`, `modified_by`
		 FROM `controls`
		 WHERE status = 2

		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);



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


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

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

				     	<th  > <input type="checkbox" id="selecctall"  data-toggle = "tooltip" title = "Check All" value=""></th>
			  			<th>Title</th>tle
						<th>Controls</th>
						<th>Description</th>
						<th>Active Status</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th>Deleted </th>
						<th></th>

				</thead>



				<tfoot>


						<th  > <input type="checkbox" id="selecctall" data-toggle = "tooltip" title = "Check All"  value=""></th>
			  			<th>Title</th>
						<th>Controls</th>
						<th>Description</th>
						<th>Active Status</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th>Deleted </th>
						<th></th>
				</tfoot>

				<tbody>';



		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='control_box[]' id='control_box' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['controls_value']."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".control_box_status_img($row['activate'])."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_control_box" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></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 trashed control_boxs

//control box image status
function control_box_status_img($status)
{
	$st = $status;

	if($st == 1)
	{
		return '<img src="images/active.png" data-toggle="tooltip" title="Active"/>';
	}
	else
	{
		return '<img src="images/blocked.png" data-toggle="tooltip" title="Inactive" />';
	}
}





//function view batches

function view_states()
{

	//query the database
	$q = "SELECT `id`, `title`,  `description`, DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, `added_by` FROM `state`
		 ORDER BY date_added  DESC";
	$r = mysql_query($q);

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


		 $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		  	<thead>
			  <th > <input type="checkbox" id="selecctall"  value=""> &nbsp;Check All</th>
			  <th>Title</th>
			  <th  >Description</th>
			  <th>Date Added</th>
			  <th>Added By</th>

		  </thead>

		  <tfoot>
			  <th > <input type="checkbox" id="selecctall"  value=""> &nbsp;Check All</th>
			  <th>Title</th>
			  <th>Description</th>
			  <th>Date Added</th>
			  <th>Added By</th>

		  </tfoot>

		  <tbody>';




		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='state[]' id='state' class='checkbox1'/></td>" ;
			$output .= "<td>".$row['title']."</td>"; //name
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['added_by']."</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 states



//function view lgas
function view_lgas()
{

	//query the database
	$q = "SELECT l.id, l.title, l.description, l.state_id, l.date_added, l.date_modified, l.added_by,
		 s.id as sid, s.title as stitle
		 FROM lga l, state s
		 WHERE s.id = l.state_id
		ORDER BY l.date_added DESC";
	$r = mysql_query($q);

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


		$output =
		'<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		  <thead>
					  <th> <input type="checkbox" id="selecctall"  value=""> &nbsp;Check All</th>
					  <th>Title</th>
					  <th>State</th>
					  <th>Description</th>
					  <th>Date Added</th>
					  <th>Added By</th>

		  </thead>
		   <tfoot>
					  <th> <input type="checkbox" id="selecctall"  value=""> &nbsp;Check All</th>
					  <th>Title</th>
					  <th>State</th>
					  <th>Description</th>
					  <th>Date Added</th>
					  <th>Added By</th>

		  </tfoot>

		  <tbody>';




		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='lga[]' id='lga' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>"; //title
			$output .= "<td> <a href=''>".$row['stitle']."</a></td>"; //title
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['added_by']."</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 lgas


//function that gets lga title
function  get_lga_title($id)
{
	$result = mysql_query("SELECT * FROM lga WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$title = $row['title'];

	return $title;

}



//function select state
function select_state( $state)
{
	$r = mysql_query("SELECT id, title  FROM state  ORDER BY title ");
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			if($state == $row['id'])
			{
				$output = "<option value=\"$row[id]\" selected>";
				$output .=  $row['title'];
				$output .="</option>";

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

			}


			echo $output;
		}
	}
	else
	{

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

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

//function that gets state title
function  get_state_title($id)
{
	$result = mysql_query("SELECT * FROM state WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$title = $row['title'];

	return $title;

}


//select programme
function select_programme_lvsp($p)
{
	$r = mysql_query("SELECT id, title  FROM programmes WHERE real_ = '0' AND type_id = 2 AND  mode = 2 ORDER BY title");
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			if($p == $row['id'])
			{
				$output = "<option value=\"$row[id]\" selected>";
				$output .=  $row['title'];
				$output .="</option>";

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

			}


			echo $output;
		}
	}
	else
	{

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

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


//select programme
function select_programme_duap($p,$pt)
{
	$r = mysql_query("SELECT id, title  FROM programmes WHERE type_id  = '$pt'");
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r))
		{
			if($p == $row['id'])
			{
				$output = "<option value=\"$row[id]\" selected>";
				$output .=  $row['title'];
				$output .="</option>";

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

			}


			echo $output;
		}
	}
	else
	{

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

			echo $output;
	}
}


//select programme
function select_programme($programme)
{
	$r = mysql_query("SELECT id, title,type_id  FROM programmes  ORDER BY title");
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			if($programme == $row['id'])
			{
				$output = "<option value=\"$row[id]\" selected>";
				$output .=  $row['title'];
				$output .=" (".show_programme_type($row['type_id']).")</option>";

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

			}


			echo $output;
		}
	}
	else
	{

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

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

function select_programme_nce($p)
{
	$r = mysql_query("SELECT id, title  FROM programmes WHERE real_ = '0' AND
			type_id = 2  AND mode = 1 ORDER BY title");
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			if($p == $row['id'])
			{
				$output = "<option value=\"$row[id]\" selected>";
				$output .=  $row['title'];
				$output .="</option>";

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

			}


			echo $output;
		}
	}
	else
	{

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

			echo $output;
	}
}

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


//select department
function select_department($department)
{
	$r = mysql_query("SELECT id, title  FROM departments  ORDER BY title");
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			if($department == $row['id'])
			{
				$output = "<option value=\"$row[id]\" selected>";
				$output .=  $row['title'];
				$output .="</option>";

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

			}


			echo $output;
		}
	}
	else
	{

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

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










//get course name passed by id of the course
function get_programme_title($id)
{
	$result = mysql_query("SELECT * FROM programmes WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$title = $row['title'];

	return $title;
}


//get course name passed by id of the schoo title
function get_school_title($id)
{
	$result = mysql_query("SELECT * FROM schools WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$title = $row['title'];

	return $title;
}


//get course name passed by id of the school id by programme
function get_school_id_by_programme($id)
{
	$result = mysql_query("SELECT school_id FROM programmes WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['school_id'];

	return $v;
}




//function that generates admission number students

//first we need to get applied  department of the student

//second we need to get department title by id

//we need to get department code by id

//we need to get the total number of people in the dept




//function that gets faculty title
function  get_faculty_title($id)
{
	$result = mysql_query("SELECT * FROM faculties WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$title = $row['title'];

	return $title;

}


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

	return $title;

}

//function that gets department code base department id
function  get_department_code($id)
{
	$result = mysql_query("SELECT * FROM departments WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$code = $row['department_code'];

	return $code;

}



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

	return $code;

}


//function that gets programme code base on course id
function  get_dep_id_prog_id($id)
{
	$result = mysql_query("SELECT department_id FROM programmes WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$code = $row['department_id'];

	return $code;

}




//******************************** functions on  student report **************************/





//function get total students in a
function get_total_students()
{
	$q = "SELECT COUNT(id) FROM students  WHERE validity_status = '0'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function get total male  students
function get_total_male_students()
{
	$q = "SELECT COUNT(id) FROM students  WHERE validity_status = '0' AND gender = 'M'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function get total female students
function get_total_female_students()
{
	$q = "SELECT COUNT(id) FROM students  WHERE validity_status = '0' AND gender = 'F'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



//function get total level students base on id pass students
function get_total_students_per_level($l)
{
	$q = "SELECT COUNT(id) FROM students  WHERE validity_status = '0' AND level = '$l'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}





//function get total students in a department
function get_total_department_students($id)
{
	$q = "SELECT COUNT(id) FROM students  WHERE validity_status = '0' AND department_id = '$id' AND validity_status = '0'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



//function get total students in a programme per programme type
function get_total_prog_type_students($pt,$p)
{
	$q = "SELECT COUNT(*) FROM students  WHERE   type_id = '$pt'  AND programme_id = '$p' AND validity_status = '0'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



//function get total students in a programme per programme type, department, $programme , level
function get_total_programme_students($pt, $d, $p, $l)
{
	$q = "SELECT COUNT(*) FROM students_nce  WHERE   type_id = '$pt' AND school_id = '$d' AND programme_id = '$p' AND level = '$l' AND validity_status = '0'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function get total students in a programme per programme type, department, $programme , level
function get_total_programme_students_prence($pt, $d, $p, $l)
{
	$q = "SELECT COUNT(*) FROM students_prence  WHERE   type_id = '$pt' AND school_id = '$d' AND programme_id = '$p' AND level = '$l' AND validity_status = '0'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}


//function get total students in a programme type
function get_total_programme_type_students($id)
{
	$q = "SELECT COUNT(id) FROM students  WHERE  type_id = '$id' AND validity_status = '0'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}




//function that get all programmes type students
function get_listed_programmes_types_for_students()
{

		$output =  '';


		for($i = 1 ; $i <= 3; $i++)
		{
			$output .= '<li class="list-group-item">'.show_programme_type($i).'
						<span class="pull-right badge">'.get_total_programme_type_students($i).'</span> <br/>

						</li>';


		}


	//<span class="help-block" style="font-size:10px">'.get_programme_title_for_applicants($i).'</span>
	return $output;

}







//function taht gets percentage
function get_percent($value, $total)
{

	if($value == 0)
	{
		$percent  = ($value / 1) * 100;
	}
	else
	{
		$percent  = ($value / $total) * 100;
	}

	return round($percent, 2);
}

//function that gets color of the progress bar
function get_color ($percent)
{
	if($percent > 0 && $percent <= 20)
	{
		return 'progress-bar-default';
	}
	else if ($percent > 20 && $percent <= 40)
	{
		return 'progress-bar-info';
	}
	else if ($percent > 40 && $percent <= 60)
	{
		return 'progress-bar-success';
	}
	else if ($percent > 60 && $percent <= 80)
	{
		return 'progress-bar-warning';
	}
	else if ($percent > 80 && $percent <= 100)
	{
		return 'progress-bar-danger';
	}
	else
	{
		return '';
	}

}//end of function that gets color





//function get total  faculty
function get_total_faculty()
{
	$q = "SELECT COUNT(id) FROM faculties  WHERE status = '0'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



//function get total department
function get_total_department()
{
	$q = "SELECT COUNT(id) FROM departments  WHERE status = '0'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



//function get total programmes
function get_total_programmes()
{
	$q = "SELECT COUNT(id) FROM programmes  WHERE status = '0'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}


//function that get all faculties
function get_listed_faculties()
{
	//query the database
	$q = "SELECT id, title,status FROM  faculties WHERE status = '0'  ORDER BY title";
	$r = mysql_query($q);

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

		$output =  '';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= '<li class="list-group-item">'.$row['title'].' <span class="pull-right badge">'.get_total_faculty_students($row['id']).'</span></li>';

		}
	}
	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.
				   </div>';

	}

	return $output;

}




//function that get all departments
function get_listed_departments()
{
	//query the database
	$q = "SELECT * FROM  departments WHERE status = '0' AND real_ = '0'  ORDER BY title";
	$r = mysql_query($q);

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

		$output =  '';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= '<li class="list-group-item">'.$row['title'].'
						<span class="pull-right badge">'.get_total_department_students($row['id']).'</span> <br/>
							</li>';

		}
	}
	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.
				   </div>';

	}

	return $output;

}



//function that get all programmes
function get_listed_programmes()
{
	//query the database
	$q = "SELECT id, title,department_id, status, type_id FROM  programmes WHERE status = '0' AND real_ = '0'  ORDER BY title";
	$r = mysql_query($q);

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

		$output =  '';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= '<li class="list-group-item">'.$row['title'].'
						<span class="pull-right badge">'.get_total_prog_type_students($row['type_id'],$row['id']).'</span> <br/>
						<span class="help-block" style="font-size:10px">'.get_department_title($row['department_id']).'</span>
						<span class="help-block" style="font-size:10px">'.show_programme_type($row['type_id']).'</span>

						</li>';

		}
	}
	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.
				   </div>';

	}

	return $output;

}






//******************************** functions on  staff report **************************/


//function get total staff
function get_total_staff()
{
	$q = "SELECT COUNT(id) FROM staff  WHERE validity_status = '0'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function get total academic staff
function get_total_academic_staff()
{
	$q = "SELECT COUNT(id) FROM staff  WHERE validity_status = '0' AND type_id = '1'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function get total non academic staff
function get_total_non_academic_staff()
{
	$q = "SELECT COUNT(id) FROM staff  WHERE validity_status = '0' AND type_id = '2'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



//function get total paermanent staff
function get_total_permanent_staff()
{
	$q = "SELECT COUNT(id) FROM staff  WHERE validity_status = '0' AND cart_id = '1'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



//function get total contract staff
function get_total_contract_staff()
{
	$q = "SELECT COUNT(id) FROM staff  WHERE validity_status = '0' AND cart_id = '12'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



//function get total male  staff
function get_total_male_staff()
{
	$q = "SELECT COUNT(id) FROM staff  WHERE validity_status = '0' AND gender = 'M'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function get total female staff
function get_total_female_staff()
{
	$q = "SELECT COUNT(id) FROM staff  WHERE validity_status = '0' AND gender = 'F'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}


//function get total staff in a faculty
function get_total_faculty_staff($fac_id)
{
	$q = "SELECT COUNT(id) FROM staff  WHERE validity_status = '0' AND faculty_id = '$fac_id'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



//function get total staff in a department
function get_total_department_staff($id)
{
	$q = "SELECT COUNT(id) FROM staff  WHERE validity_status = '0' AND department_id = '$id'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function get total staff in a department
function get_total_programme_staff($id)
{
	$q = "SELECT COUNT(id) FROM staff  WHERE validity_status = '0' AND programme_id = '$id'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}







//function that get all faculties staff
function get_listed_faculties_staff()
{
	//query the database
	$q = "SELECT id, title,status FROM  faculties WHERE status = '0'  ORDER BY title";
	$r = mysql_query($q);

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

		$output =  '';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= '<li class="list-group-item">'.$row['title'].' <span class="pull-right badge">'.get_total_faculty_staff($row['id']).'</span></li>';

		}
	}
	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.
				   </div>';

	}

	return $output;

}




//function that get all departments staff
function get_listed_departments_staff()
{
	//query the database
	$q = "SELECT id, title,faculty_id,status FROM  departments WHERE status = '0'  ORDER BY title";
	$r = mysql_query($q);

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

		$output =  '';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= '<li class="list-group-item">'.$row['title'].'
						<span class="pull-right badge">'.get_total_department_staff($row['id']).'</span> <br/>
						<span class="help-block" style="font-size:10px">'.get_faculty_title($row['faculty_id']).'</span>
						</li>';

		}
	}
	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.
				   </div>';

	}

	return $output;

}



//function that get all programmes
function get_listed_programmes_staff()
{
	//query the database
	$q = "SELECT id, title,department_id, status FROM  programmes WHERE status = '0'  ORDER BY title";
	$r = mysql_query($q);

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

		$output =  '';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= '<li class="list-group-item">'.$row['title'].'
						<span class="pull-right badge">'.get_total_programme_staff($row['id']).'</span> <br/>
						<span class="help-block" style="font-size:10px">'.get_department_title($row['department_id']).'</span>
						</li>';

		}
	}
	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.
				   </div>';

	}

	return $output;

}

///////////////////////////////////////// system reports functions  ////////////////////////////////////
//function get total students  online
function get_total_students_online()
{
	$q = "SELECT COUNT(id) FROM students  WHERE online_status = '1'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



//function get total staff  online
function get_total_staff_online()
{
	$q = "SELECT COUNT(id) FROM staff  WHERE online_status = '1'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



/*********************************** admin application module ****************************************/
//fucntion that returns searched candidates
function view_search_candidate($search_c)
{

	//query the database
	$q = "SELECT `id`, `fullname`, `phone_number`, `email`, `transaction_id`, `pin`, `serial_no`,
	     `status`,  `time`, `expiry_time`, `exired_date`,

		  DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added


		 FROM applicants_transaction_ids

		 WHERE transaction_id = '$search_c'";

		 //LIMIT $start, $display_per_page";
	$r = mysql_query($q) or die (mysql_error());




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

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


		$output = '<table  class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="text-align:center;">

		  <thead>


		 			  <th><!--<input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"> --></th>
					  <th><h4>Name</h4></th>
					  <th><h4>Transaction ID</h4></th>
					  <th ><h4>Date Generated</h4></th>

		  </thead>

		  <tbody>';




		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['transaction_id']."' name='applicant[]' id='applicant' class='checkbox1' data-toggle='tooltip' title= 'Check' /></td>" ;
			$output .= "<td> <h3>".$row['fullname']."</h3></td>"; //name of the user

			$output .= "<td><h3 style='font-size:14px;' class='label label-info'>".$row['transaction_id']."</h3></td>";

			$output .= "<td>".$row['date_added']."</td>";
			$output .= "</tr>";

		}//end of while


	}
	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; Candidate not recognise by the system. We apologize for any inconvenience..
				   </div>';


	}



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





	return $output;

	//else
//	{
//		$errors['error'] =  'Candidate not recognise by the system. We apologize for any inconvenience.';
//
//		header("Location: gateway.php?act=search_candidate&error=".urlencode($errors['error'])."");
//	}





}//end of view search candidate


//
////function get candidate image by passing id alone
//function get_candidate_image($user_id)
//{
//	$q = "SELECT u.user_id, u.image FROM users u
//		  WHERE  u.user_id = '$user_id'";
//
//	$r 	= mysql_query($q);
//
//	if(mysql_num_rows($r) > 0)
//	{//show table
//
//		$row = mysql_fetch_array($r, MYSQL_ASSOC);
//
//			$output = '<img class="img-responsive img-rounded img-thumbnail center-block" src="uploads/pictures/'.$row['image'].'" style="height:150px ;width:200px"    />';
//
//			return $output;
//
//
//	}
//
//}



//function dat get applicant full name by passing tid
function get_applicant_name($tid)
{
	$q = "SELECT fullname FROM applicants_transaction_ids WHERE transaction_id = '$tid' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	$v = $row['fullname'];

	return $v;


}//end of function that shows applicant full name


//function dat get applicant phone_ no by passing tid
function get_applicant_ph_no($tid)
{
	$q = "SELECT phone_number FROM applicants_transaction_ids WHERE transaction_id = '$tid' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	$v = $row['phone_number'];

	return $v;


}//end of function that shows applicant phone_number

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

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


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

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

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

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

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

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

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

	return $output;

}
//function dat get applicant email by passing tid
function get_applicant_email($tid)
{
	$q = "SELECT email FROM applicants_transaction_ids WHERE transaction_id = '$tid' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	$v = $row['email'];

	return $v;


}//end of function that shows applicant email

function get_applicant_swapped_prog_status($id)
{
	$q = "SELECT swapped_prog_status FROM applicants_nce WHERE id = '$id' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	$v = $row['swapped_prog_status'];

	return $v;


}//end of function that shows applicant email

function get_applicant_mode_of_entry($id)
{
	$result = mysql_query("SELECT mode_of_entry FROM applicants_nce WHERE id = '$id'");
	$row = mysql_fetch_assoc($result);
	$v = $row['mode_of_entry'];


	return $v;
}



//function select programme_type
function select_entry_mode($pt)
{
		$output = '';
		if ($pt == 1)
		{
			$output = '<option value="1" selected>TRANSITION</option>';

		}
		else if ($pt == 2)
		{

			$output = '<option value="2" selected>DIRECT</option>';

			//$output .= '<option value="3" > Certificate </option>';
		}else if ($pt == 3)
		{

			$output = '<option value="3" selected>JAMB </option>';


		}

		else
		{

			$output = '<option value="0" > -- Please Select --</option>';
			/*$output .= '<option value="1" >TRANSITION </option>';
			$output .= '<option value="2" > DIRECT</option>';
			$output .= '<option value="3" > JAMB </option>';*/



			//$output .= '<option value="3" > Certificate </option>';

		}

	return $output;

}
//function select programme_type
function select_applicant_entry_mode($pt)
{
		$output = '';
		if ($pt == 1)
		{
			$output = 'NCE TRANSITING';

		}
		else if ($pt == 2)
		{

			$output = ' NCE DIRECT';


		}else if ($pt == 3)
		{

			$output = 'NCE UTME ';


		}

		else
		{

			$output = 'Nothing';

		}

	return $output;

}
//function select programme_type
function select_programme_type_1($pt)
{
		$output = '';
		if ($pt == '1')
		{
			$output = '<option value="1" selected>NCE TRANSITING</option>';
			$output .= '<option value="2" >NCE DIRECT</option>';
			$output .= '<option value="3" >NCE UTME </option>';


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

			$output = '<option value="1" >NCE TRANSITING </option>';
			$output .= '<option value="2" selected>NCE DIRECT</option>';
			$output .= '<option value="3" >NCE UTME </option>';


			//$output .= '<option value="3" > Certificate </option>';
		}else if ($pt == '3')
		{
			$output = '<option value="1" >NCE TRANSITING </option>';
			$output .= '<option value="2" >NCE DIRECT</option>';
			$output .= '<option value="3" selected>NCE UTME </option>';


		}

		else
		{

			$output = '<option value="0" > -- Please Select --</option>';
			$output .= '<option value="1" >NCE TRANSITING </option>';
			$output .= '<option value="2" >NCE DIRECT</option>';
			$output .= '<option value="3" >NCE UTME </option>';



			//$output .= '<option value="3" > Certificate </option>';

		}

	return $output;

}
//function dat get applicanttid generated_time by passing tid
function get_applicant_tid_gen_time($tid)
{
	$q = "SELECT time FROM applicants_transaction_ids WHERE transaction_id = '$tid' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	$v = $row['time'];

	return $v;


}//end of function that shows applicant tid genrated time


//function dat get applicanttid expired_time by passing tid
function get_applicant_tid_exp_time($tid)
{
	$q = "SELECT expiry_time FROM applicants_transaction_ids WHERE transaction_id = '$tid' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	$v = $row['expiry_time'];

	return $v;


}//end of function that shows applicant tid expiry_time

//function dat get date and time tid was generated
function get_tid_date($tid)
{
	$q = "SELECT DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added FROM applicants_transaction_ids WHERE transaction_id = '$tid' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	$v = $row['date_added'];

	return $v;


}//end of function that shows get date and time tid was generated


//function dat get applicant pin from users db
function get_applicant_pin($tid)
{
	$q = "SELECT bank_epin FROM applicants WHERE transaction_id = '$tid' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	$v = $row['bank_epin'];

	return $v;


}//end of function that applicant pin from users db

//function dat get applicant serial number from users db
function get_applicant_sn($tid)
{
	$q = "SELECT serial_number FROM applicants WHERE transaction_id = '$tid' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	$v = $row['serial_number'];

	return $v;


}//end of function that applicant pin from users db





//function dat checks if tid exist in database table
function tid_exist($tid)
{
	$q = "SELECT transaction_id FROM applicants  WHERE transaction_id = '$tid' ";
	$r = mysql_query($q);


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



}//end of function that chk kif tid exist in users table



//function dat checks if tid has expired
function tid_expired($time_generated, $expired_time)
{
	//172800
	$present_time = time(); //present time
	$old_time_interval = $expired_time - $time_generated; //interval between time generated and elapse time
	$present_time_interval = $present_time - $time_generated; //interval betweeen now and time generated




	if($present_time_interval > $old_time_interval)
	{
		return true; //time has expired
	}
	else
	{
		return false; //else not expired
	}



}//end of function that chk kif tid exist in users table




//generate serial number for logging in
function generate_applicants_serial_number()
{
	$result = mysql_query("SELECT * FROM applicants_generate_serial_number");
	while($row = mysql_fetch_array($result))
	{
		$g_code = $row['code'];
	}

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

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


	//add random four values before adding to the database
	$add_random_value = mt_rand(1000000,9999999);
	$code = $add_random_value.$g_coded;
	$serial_number  = $code;

	return $serial_number;
}
//end of function generate serial number for logging in





//function that get epin passing  id
function get_candidate_epin($id)
{
	//collect applicant data
	$other_names = get_applicant_name($id);//
	$other_names = mysql_real_escape_string($other_names);
	$phone_number = get_applicant_ph_no($id);
	$email = get_applicant_email($id);
	$time = get_applicant_tid_gen_time($id);
	$exp_time = get_applicant_tid_exp_time($id);





	//collellect users info
	$user_id = $id; //collect the user id


	//before a pin is generated chek if the transsaction id has been given a pin and serial number,
	//if given fetch the pin from db cus the of network issue and regenration


		//if(!(is_epin_limit())) ///check if epin limit is exhausted
		//{



			if(!tid_expired($time, $exp_time)) //check if tid has expired
			{
				//check if tid has epin alredy to avoid duplicate
				//if it doesnt have generate a new 1 but if its dia copy from db
				if(!tid_exist($id))
				{

					  //generate new 1s
					  $pin = mt_rand(10000, 99999); //pin
					  $serial_number = generate_applicants_serial_number();


					  $q = "INSERT INTO `applicants`(`id`, `role_id`, `other_names`, `email`, `phone_number`,
						`user_status`, `date_added`, `transaction_id`, `bank_epin`,`serial_number`,`country_id`)
						VALUES (NULL,2,'$other_names','$email','$phone_number',1,NOW(),'$id', '$pin','$serial_number','159')";


					  $r = mysql_query($q) or die(mysql_error());

					  $ok = 'PIN-'.$pin .'<br/> S/N-'.$serial_number;

					  return $ok; //return details

				}//end of if tid  doesnt exist
				else
				{// if tid exist with pin show pin from db


						$pin = get_applicant_pin($id); //form db
						$serial_number = get_applicant_sn($id); //from db

						$ok = 'PIN-'.$pin .'<br/> S/N-'.$serial_number;

						return $ok; //return deatils



				}//end else of if tid exist



			}
			else
			{
				//$r = true; //set true to skip next error block

				//show pin and serial number from db
				$errors['error'] =  'Pin not generated,the <b>transaction id</b> has expired, please advice the applicant to go and re-generate transaction id if the form is still on sale. Thank you.';

		        header("Location: gateway.php?act=search_c&error=".urlencode($errors['error'])."");

			}/// end else of if tid has expired








		//}
		//else
		//{

			//$r = true;

			//$errors['error'] =  'Pin not generated! Maximum number of epin has been generated, contact the web master or school.
				//                 We apologize for any inconvenience. ';

			//header("Location: gateway.php?act=search_candidate&error=".urlencode($errors['error'])."");

		//}






}//end of function get user epin




function get_candidate_info($id)
{
	$q = "SELECT id,  role_id, other_names as name, phone_number, email, transaction_id,
		  DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as date_modified

		 FROM applicants
		 WHERE transaction_id = '$id'";

	$r 	= mysql_query($q);

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

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{

			$output .= '<li class="list-group-item">Name: '.$row['name'].'</li>'; //nam eof the user
			$output .= '<li class="list-group-item">Email: '.$row['email'].'</li>';
			$output .= '<li class="list-group-item">Transaction ID Date: '.get_tid_date($row['transaction_id']).'</li>';
			$output .= '<li class="list-group-item">PIN Gen. Date: '.$row['date_added'].'</li>';
			echo $output;

		}
	}



}//end of get candidate epin info


//function count number of bank epin used
function get_total_epin_used()
{
	$q = "SELECT COUNT(*) FROM applicants WHERE  pin_used = '1' ";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);


	$v = number_format($row[0]);

	return $v;
	//return ;
}




//function count number of bank epin generated
function get_total_epin_generated()
{
	$q = "SELECT COUNT(*) FROM applicants WHERE  bank_epin !='' AND serial_number != ''";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);


	$v = number_format($row[0]);

	return $v;
	//return ;
}



//function count number of tid generated
function get_total_tid_generated()
{
	$q = "SELECT COUNT(*) FROM applicants_transaction_ids WHERE  transaction_id !=''";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	$v = number_format($row[0]);

	return $v;
}


//function get total applicants
function get_total_applicants()
{
	$q = "SELECT COUNT(*) FROM applicants_fee_payments";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function get total applicants
function get_total_app_fees_payment_nce($pt, $ses)
{

	$q = "SELECT  DISTINCT (COUNT(applicant_id)) FROM applicants_nce_fee_payments
	  WHERE programme_type_id = '$pt' AND session= '$ses'

		";

			//AND applicants_nce_fee_payments.programme_type_id = '$pt' AND
		/*	WHERE applicants_nce_fee_payments.programme_type_id = '$pt' AND applicants_nce_fee_payments.session= '$ses'";*/
	//$q = "SELECT COUNT(applicants_nce_fee_paymentsid) FROM applicants_nce_fee_payments
			//WHERE programme_type_id = '$pt' AND session= '$ses'";
			//applicant_id

	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}
//function get total applicants
function get_total_course_change_nce($pt, $ses)
{

	$q = "SELECT  DISTINCT (COUNT(id)) FROM applicants_nce
	  WHERE programme_type_applied_for = '$pt' AND session= '$ses'
	  AND prog_applied_for_change > 0 AND prog_change_status = 0

		";

			//AND applicants_nce_fee_payments.programme_type_id = '$pt' AND
		/*	WHERE applicants_nce_fee_payments.programme_type_id = '$pt' AND applicants_nce_fee_payments.session= '$ses'";*/
	//$q = "SELECT COUNT(applicants_nce_fee_paymentsid) FROM applicants_nce_fee_payments
			//WHERE programme_type_id = '$pt' AND session= '$ses'";
			//applicant_id

	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}
//function get total applicants
function get_total_course_cleared($pt, $ses)
{

	$q = "SELECT  DISTINCT (COUNT(id)) FROM applicants_nce
	  WHERE programme_type_applied_for = '$pt' AND session= '$ses'
	  AND admission_status = '1' AND cleared = '1'

		";

			//AND applicants_nce_fee_payments.programme_type_id = '$pt' AND
		/*	WHERE applicants_nce_fee_payments.programme_type_id = '$pt' AND applicants_nce_fee_payments.session= '$ses'";*/
	//$q = "SELECT COUNT(applicants_nce_fee_paymentsid) FROM applicants_nce_fee_payments
			//WHERE programme_type_id = '$pt' AND session= '$ses'";
			//applicant_id

	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}//function get total applicants
function get_total_course_change_prence($pt, $ses)
{

	$q = "SELECT  DISTINCT (COUNT(id)) FROM applicants_nce
	  WHERE programme_type_applied_for = '$pt' AND session= '$ses'
	  AND prog_applied_for_change > 0 AND prog_change_status = 0

		";

			//AND applicants_nce_fee_payments.programme_type_id = '$pt' AND
		/*	WHERE applicants_nce_fee_payments.programme_type_id = '$pt' AND applicants_nce_fee_payments.session= '$ses'";*/
	//$q = "SELECT COUNT(applicants_nce_fee_paymentsid) FROM applicants_nce_fee_payments
			//WHERE programme_type_id = '$pt' AND session= '$ses'";
			//applicant_id

	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}
//function get total applicants
function get_total_app_fees_payment_nce_lvsp($pt, $mode, $ses)
{

	$q = "SELECT DISTINCT (COUNT(applicant_id)) FROM applicants_nce_fee_payments
	  WHERE programme_type_id = '$pt' AND mode  = '$mode' AND session = '$ses'

		";

			//AND applicants_nce_fee_payments.programme_type_id = '$pt' AND
		/*	WHERE applicants_nce_fee_payments.programme_type_id = '$pt' AND applicants_nce_fee_payments.session= '$ses'";*/
	//$q = "SELECT COUNT(applicants_nce_fee_paymentsid) FROM applicants_nce_fee_payments
			//WHERE programme_type_id = '$pt' AND session= '$ses'";
			//applicant_id

	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function get total applicants
function get_total_app_fees_payment_deg($ses)
{

	$q = "SELECT DISTINCT (COUNT(applicant_id)) FROM applicants_nce_fee_payments
	  WHERE  session = '$ses'

		";

			//AND applicants_nce_fee_payments.programme_type_id = '$pt' AND
		/*	WHERE applicants_nce_fee_payments.programme_type_id = '$pt' AND applicants_nce_fee_payments.session= '$ses'";*/
	//$q = "SELECT COUNT(applicants_nce_fee_paymentsid) FROM applicants_nce_fee_payments
			//WHERE programme_type_id = '$pt' AND session= '$ses'";
			//applicant_id

	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

function get_total_app_fees_payment_prence($mode,$pt, $ses)
{

	$q = "SELECT  DISTINCT (COUNT(applicant_id)) FROM applicants_nce_fee_payments
		WHERE mode= '$mode' AND programme_type_id = '$pt' AND session= '$ses'

			";

			//AND applicants_nce_fee_payments.programme_type_id = '$pt' AND
		/*	WHERE applicants_nce_fee_payments.programme_type_id = '$pt' AND applicants_nce_fee_payments.session= '$ses'";*/
	//$q = "SELECT COUNT(applicants_nce_fee_paymentsid) FROM applicants_nce_fee_payments
			//WHERE programme_type_id = '$pt' AND session= '$ses'";
			//applicant_id

	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



//function get total applicants
function get_total_applicants_all()
{
	$q = "SELECT COUNT(*) FROM applicants";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}


//function get total male  applicants
function get_total_male_applicants()
{
	$q = "SELECT COUNT(id) FROM applicants  WHERE  gender = 'M' AND bank_epin !='' AND serial_number != ''";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function get total female applicants
function get_total_female_applicants()
{
	$q = "SELECT COUNT(id) FROM applicants_nce  WHERE  gender = 'F' AND bank_epin !='' AND serial_number != ''";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



//function get total programme type  applicants base on id passed
function get_total_applicants_per_programme_type($l)
{
	$q = "SELECT COUNT(id) FROM applicants_nce  WHERE  programme_type_applied_for = '$l' AND bank_epin !='' AND serial_number != ''";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



//function get total applicants in a department application
function get_total_department_applicants($id)
{
	$q = "SELECT COUNT(id) FROM applicants_nce  WHERE  department_applied_for = '$id' AND bank_epin !='' AND serial_number != ''";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function get total applicants in a programme
function get_total_programme_applicants($id)
{
	$q = "SELECT COUNT(id) FROM applicants_nce  WHERE  programme_applied_for = '$id' AND bank_epin !='' AND serial_number != ''";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



//below function is suppose to count how many paid by applicants

//function get total applicants in a programme
function get_total_prog_type_programme_applicants($pt, $id)
{
	$q = "SELECT COUNT(id) FROM applicants_nce  WHERE programme_type_applied_for = '$pt' AND programme_applied_for = '$id'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function get total applicants in a programme
function get_total_prog_type_programme_applicants_4($pt, $id, $ses)
{
	$q = "SELECT  DISTINCT (COUNT(applicant_id)) FROM applicants_nce_fee_payments  WHERE programme_type_id = '$pt'
			AND programme_id = '$id' AND session= '$ses'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}
//function get total applicants in a programme
function get_total_prog_type_programme_applicants_prence($pt, $id, $md, $ses)
{
	$q = "SELECT  DISTINCT (COUNT(applicant_id)) FROM applicants_nce_fee_payments  WHERE programme_type_id = '$pt'
			AND programme_id = '$id' AND session= '$ses' AND mode = '$md'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}
//function get total applicants in a programme
function get_total_prog_type_programme_applicants_nce($pt, $id, $ses)
{
	$q = "SELECT DISTINCT (COUNT(applicant_id)) FROM applicants_nce_fee_payments  WHERE programme_type_id = '$pt'
			AND programme_id = '$id' AND session= '$ses' ";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}


//function get total applicants in a programme
function get_total_prog_type_programme_applicants_deg($id, $ses)
{
	$q = "SELECT DISTINCT (COUNT(applicant_id)) FROM applicants_nce_fee_payments  WHERE  programme_id = '$id' AND session= '$ses' ";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}
//function get total applicants in a programme
function get_records_applicants_nce($pt, $ses)
{
	$q = "SELECT DISTINCT (applicant_id) FROM applicants_nce_fee_payments  WHERE programme_type_id = '$pt'
			 AND session= '$ses' ";
	$r = mysql_query($q);
	$sn = 0;

	if(mysql_num_rows($r) > 0)
	{//show table
		//get applicant data


	  $output =
	  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		<thead>
			<th>S/No</th>
			<th>Application Number</th>
			<th>Name</th>
			<th>Phone No</th>
			<th>Gender</th>
			 <th>Programme Type</th>
			<th>Programme Applied</th>
			<th>Application Status</th>
			<th>Suggessted Courses</th>

		</thead>
		<tfoot>
			<th>S/No</th>
			<th>Application Number</th>
			<th>Name</th>
			<th>Phone No</th>
			<th>Gender</th>
			<th>Programme Type</th>
			<th>Programme Applied</th>
			<th>Application Status</th>
			<th>Suggessted Courses</th>

		</tfoot>

		<tbody>';
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$applicant_id =  $row['applicant_id'];

			//query the database
			$q2 = "SELECT id, programme_type_applied_for, school_applied_for,department_applied_for, programme_applied_for, application_number,
				  state_id, lga_id, first_name, other_names, phone_no, gender,  email, qualified,
				  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
				  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
				  FROM  applicants_nce

				  WHERE   id = '$applicant_id'

				  ORDER BY id ASC";

			$r2 = mysql_query($q2);


			while($row2 = mysql_fetch_array($r2, MYSQL_ASSOC))
			{
				$sn += 1;
				$output .= "<tr>";

				$output .= "<td>".$sn."</td>";
				$output .= "<td>".$row2['application_number']."</td>";
				$output .= "<td> <a href='#'>".$row2['first_name'].' '.$row2['other_names']."</a></td>";
				$output .= "<td>".$row2['phone_no']."</td>";
				$output .= "<td>".$row2['gender']."</td>";
				$output .= "<td>".show_programme_type($row2['programme_type_applied_for'])."</td>";
				$output .= "<td>".get_programme_title($row2['programme_applied_for'])."</td>";
				$output .= "<td>".get_user_qualified_status($applicant_id)."</td>";
				$output .= "<td>".validate_applicant_all_olevel($applicant_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 get total applicants in a programme
function get_records_applicants_deg( $ses)
{
	$q = "SELECT DISTINCT (applicant_id) FROM applicants_nce_fee_payments  WHERE session= '$ses' ";
	$r = mysql_query($q);
	$sn = 0;

	if(mysql_num_rows($r) > 0)
	{//show table
		//get applicant data


	  $output =
	  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		<thead>
			<th>S/No</th>
			<th>Application Number</th>
			<th>Name</th>
			<th>Phone No</th>
			<th>Gender</th>
			 <th>Programme Type</th>
			<th>Programme Applied</th>
			<th>Application Status</th>
			<th>Suggessted Courses</th>

		</thead>
		<tfoot>
			<th>S/No</th>
			<th>Application Number</th>
			<th>Name</th>
			<th>Phone No</th>
			<th>Gender</th>
			<th>Programme Type</th>
			<th>Programme Applied</th>
			<th>Application Status</th>
			<th>Suggessted Courses</th>

		</tfoot>

		<tbody>';
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$applicant_id =  $row['applicant_id'];

			//query the database
			$q2 = "SELECT id, programme_type_applied_for, school_applied_for,department_applied_for, programme_applied_for, application_number,
				  state_id, lga_id, first_name, other_names, phone_no, gender,  email, qualified,
				  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
				  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
				  FROM  applicants_nce

				  WHERE   id = '$applicant_id'

				  ORDER BY id ASC";

			$r2 = mysql_query($q2);


			while($row2 = mysql_fetch_array($r2, MYSQL_ASSOC))
			{
				$sn += 1;
				$output .= "<tr>";

				$output .= "<td>".$sn."</td>";
				$output .= "<td>".$row2['application_number']."</td>";
				$output .= "<td> <a href='#'>".$row2['first_name'].' '.$row2['other_names']."</a></td>";
				$output .= "<td>".$row2['phone_no']."</td>";
				$output .= "<td>".$row2['gender']."</td>";
				$output .= "<td>".show_programme_type($row2['programme_type_applied_for'])."</td>";
				$output .= "<td>".get_programme_title($row2['programme_applied_for'])."</td>";
				$output .= "<td>".get_user_qualified_status($applicant_id)."</td>";
				$output .= "<td>".validate_applicant_all_olevel($applicant_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 get total applicants in a programme
function get_records_applicants_sum( $ses)
{
	$q = "SELECT DISTINCT (student_id) FROM summer_application_fee_payments  WHERE session= '$ses' ";
	$r = mysql_query($q);
	$sn = 0;

	if(mysql_num_rows($r) > 0)
	{//show table
		//get applicant data


	  $output =
	  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		<thead>
			<th>S/No</th>
			<th>Application Number</th>
			<th>Name</th>
			<th>Phone No</th>
			<th>Gender</th>
			 <th>Programme Type</th>
			<th>Programme Applied</th>
			<th>Application Status</th>
			<th>Suggessted Courses</th>

		</thead>
		<tfoot>
			<th>S/No</th>
			<th>Application Number</th>
			<th>Name</th>
			<th>Phone No</th>
			<th>Gender</th>
			<th>Programme Type</th>
			<th>Programme Applied</th>
			<th>Application Status</th>
			<th>Suggessted Courses</th>

		</tfoot>

		<tbody>';
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$student_id =  $row['student_id'];

			//query the database
			$q2 = "SELECT id, programme_type_applied_for, school_applied_for,department_applied_for, programme_applied_for, application_number,
				  state_id, lga_id, first_name, other_names, phone_no, gender,  email,
				  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added
				  
				  FROM  applicants_nce

				  WHERE   id = '$student_id'

				  ORDER BY id ASC";

			$r2 = mysql_query($q2);
			
			while($row2 = mysql_fetch_array($r2, MYSQL_ASSOC))
			{
				$sn += 1;
				$output .= "<tr>";

				$output .= "<td>".$sn."</td>";
				$output .= "<td>".$row2['application_number']."</td>";
				$output .= "<td> <a href='#'>".$row2['first_name'].' '.$row2['other_names']."</a></td>";
				$output .= "<td>".$row2['phone_no']."</td>";
				$output .= "<td>".$row2['gender']."</td>";
				$output .= "<td>".show_programme_type($row2['programme_type_applied_for'])."</td>";
				$output .= "<td>".get_programme_title($row2['programme_applied_for'])."</td>";
				$output .= "<td>".get_user_qualified_status($student_id)."</td>";
				$output .= "<td>".validate_applicant_all_olevel($student_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 get total applicants in a programme
function get_total_prog_applicants($pt, $pid, $sess)
{
	$q = "SELECT  DISTINCT (COUNT(app.id)) FROM applicants_nce app, applicants_nce_fee_payments app_pay  WHERE app.programme_type_applied_for = '$pt'
			AND app.programme_applied_for = '$pid'
			AND app.session = '$sess' AND app_pay.applicant_id = app.id";//AND app.cart_id = '$md'


	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}//function get total applicants in a programme
function get_total_prog_applicants_admitted($pt, $pid, $sess,$clr)
{
	$q = "SELECT  DISTINCT (COUNT(id)) FROM applicants_nce  WHERE type_id = '$pt'
			AND programme_id = '$pid'  AND session = '$sess' AND cleared = '$clr'";


	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function get total applicants in a programme
function get_records_applicants_qualify($pt, $ses,$qi,$uid)
{

	 $output =
	  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		<thead>
			<th>S/No</th>
			<th>Applicant</th>
			<th>Programme Applied</th>
			<th>Olevel result 1</th>
			<th>Olevel result 2</th>
			<th>Action</th>

		</thead>
		<tfoot>
			<th>S/No</th>
			<th>Applicant</th>
			<th>Programme Applied</th>
			<th>Olevel result 1</th>
			<th>Olevel result 2</th>
			<th>Action</th>

		</tfoot>

		<tbody>';


			//query the database
			$q2 = "SELECT app.*
				  FROM  applicants_nce app, applicants_nce_fee_payments app_pay

				  WHERE  app.qualified = $qi AND app.programme_type_applied_for = $pt
				 AND app.session = $ses AND app.cleared ='0'  AND app.clear_reasons ='' AND
				   app_pay.applicant_id = app.id AND app.mode_of_entry != '1'  LIMIT 1000 ";
				  //ORDER BY app.programme_applied_for ASC ";

			$r2 = mysql_query($q2);


			while($row2 = mysql_fetch_array($r2))
			{

				$applicant_id = $row2['id'];
				$pid = $row2['programme_applied_for'];
				$cid = $row2['clr_changed_programme'];
				$sn += 1;
				$output .= "<tr>";

				$output .= "<td>".$sn."</td>";
				$output .= "<td><b>".$row2['application_number'].'<br>'.$row2['first_name'].' '.$row2['other_names']."</b></td>";

				$output .= "<td>".get_programme_title($pid)." <b>(".show_programme_type($row2['programme_type_applied_for']).")</b>
					<br>
					<span class='badge'>".get_total_prog_applicants_admitted($pt, $pid,$ses,$cleared = 1)."/".get_total_prog_applicants($pt, $pid,$ses)."</span>
				</td>";
				//$output .= "<td>".get_user_qualified_status($applicant_id)."</td>";
				/*$output .= "<td>".validate_applicant_all_olevel($applicant_id)."</td>";*/

				$output .= "<td>".get_applicant_olevel($applicant_id,'1')."</td>";
				$output .= "<td>".get_applicant_olevel($applicant_id,'2')."</td>";


				//get course suggestion
				$cs_lists = '';
				$cs_arr = '';

				//$cs_lists = validate_applicant_all_olevel2($applicant_id);
				$cs_lists = get_valid_programme_nce($pt );

				if (isset($cs_lists) && ! empty($cs_lists ) ){

            		$cs_arr = $cs_lists;
            	}
            	//dont list  programme when no olevel
            	if (applicant_olevel_exist($applicant_id)) {


						$output .= '<td><form method="POST" action="">
			 			<input type="hidden" name="app_id" value="'.$applicant_id.'">
			 			<input type="hidden" name="app_prog_id" value="'.$pid.'">
			 			';

			 			//get nce course
            			$nce_progs = get_valid_programme_nce($ptt=2);

  						$block = block_user($uid);

			 			if($pt == 1 && $block == false){//when prence

				 			$output .= '

								<div class="bg-info">
									<div>
										<h5 class="text-center"><b>PRE-NCE To NCE </b></h5>
										<select class="form-control" name="swap_prog_id" >
							                <option value=""> Select Course </option>
							                '.

							                 //displaying the prence courses

							                list_course($nce_progs)

							                .'
							            </select>
							            <input type="submit" name="swap_prog_btn" value="Convert Programme" class="btn btn-primary">
						            </div>
						            <br>
								</div>
								<br><br>

					 			';
				 		}



				 		if ($cs_arr !='') {


					 		$output .= '

					 		<h5><b>Course Suggestion</b></h5>
					 		<select class="form-control" name="prog_id" id="sug_courses" >
					                <option value=""> Select Course </option>
					                '.

					                 //displaying the courses


					                list_course2($cs_arr,$cid)

					                .'
					              </select>
					              <input type="submit" name="change_cs_btn2" value="Change Course" class="btn btn-success">
					              <br><br>
					              ';
				           $output .= ' <textarea name="action_msg" class="form-control" placeholder="Enter Remark">'.$row2["clear_reasons"].'</textarea>
				 			<br>';
					    }else{
					      	 $output .= ' <textarea name="action_msg" required class="form-control" placeholder="Enter Remark">'.$row2["clear_reasons"].'</textarea>
				 			<br>';
					     }

				 		$output .= '	<input type="submit" name="reject_btn" value="Reject" class="btn btn-danger">';

				 		if ($qi == 1) {
					 		$output .= '<input type="submit" name="clear_btn" value="Clear" class="btn btn-success">';
				 		}


						$output .= "
					 		</form></td>";
						$output .= "</tr>";




				}else{
					$cs_lists = '';
					$cs_arr = '';

				}
			}


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


		return $output;
}
//function get total applicants in a programme
function get_records_applicants_nce_trans_qualify($pt, $ses)
{

	 $output =
	  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		<thead>
			<th>S/No</th>
			<th>Applicant</th>
			<th>Programme Applied</th>
			<th>Olevel result 1</th>
			<th>Olevel result 2</th>
			<th>Action</th>

		</thead>
		<tfoot>
			<th>S/No</th>
			<th>Applicant</th>
			<th>Programme Applied</th>
			<th>Olevel result 1</th>
			<th>Olevel result 2</th>
			<th>Action</th>

		</tfoot>

		<tbody>';


			//query the database
			$q2 = "SELECT app.*
				  FROM  applicants_nce app, applicants_nce_fee_payments app_pay

				  WHERE  app.programme_type_applied_for = $pt AND app.mode_of_entry = '1'
				 AND app.session = $ses AND app.cleared ='0'  AND app.clear_reasons ='' AND
				   app_pay.applicant_id = app.id ";
				  //ORDER BY app.programme_applied_for ASC ";

			$r2 = mysql_query($q2);


			while($row2 = mysql_fetch_array($r2))
			{

				$applicant_id = $row2['id'];
				$pid = $row2['programme_applied_for'];
				$cid = $row2['clr_changed_programme'];
				$sn += 1;
				$output .= "<tr>";

				$output .= "<td>".$sn."</td>";
				$output .= "<td><b>".$row2['application_number'].'<br>'.$row2['first_name'].' '.$row2['other_names']."</b></td>";

				$output .= "<td>".get_programme_title($pid)." <b>(".show_programme_type($row2['programme_type_applied_for']).")</b>
					<br>
					<span class='badge'>".get_total_prog_applicants_admitted($pt,$pid,$ses,$cleared = 1)."/".get_total_prog_applicants($pt, $pid,$ses)."</span>
				</td>";
				//$output .= "<td>".get_user_qualified_status($applicant_id)."</td>";
				/*$output .= "<td>".validate_applicant_all_olevel($applicant_id)."</td>";*/

				$output .= "<td>".get_applicant_olevel($applicant_id,'1')."</td>";
				$output .= "<td>".get_applicant_olevel($applicant_id,'2')."</td>";


				//get course suggestion
				$cs_lists = '';
				$cs_arr = '';

				//$cs_lists = validate_applicant_all_olevel2($applicant_id);
				$cs_lists = get_valid_programme_nce($pt );

				if (isset($cs_lists) && ! empty($cs_lists ) ){

            		$cs_arr = $cs_lists;
            	}
            	//dont list  programme when no olevel
            	if (applicant_olevel_exist($applicant_id)) {


						$output .= '<td><form method="POST" action="">
			 			<input type="hidden" name="app_id" value="'.$applicant_id.'">
			 			<input type="hidden" name="app_prog_id" value="'.$pid.'">
			 			';


				 		if ($cs_arr !='') {


					 		$output .= '

					 		<h5><b>Course Suggestion</b></h5>
					 		<select class="form-control" name="prog_id" id="sug_courses" >
					                <option value=""> Select Course </option>
					                '.

					                 //displaying the courses


					                list_course2($cs_arr,$cid)

					                .'
					              </select>
					              <input type="submit" name="change_cs_btn2" value="Change Course" class="btn btn-success">
					              <br><br>
					              ';
				           $output .= ' <textarea name="action_msg" class="form-control" placeholder="Enter Remark">'.$row2["clear_reasons"].'</textarea>
				 			<br>';
					    }else{
					      	 $output .= ' <textarea name="action_msg" required class="form-control" placeholder="Enter Remark">'.$row2["clear_reasons"].'</textarea>
				 			<br>';
					     }

				 		$output .= '	<input type="submit" name="reject_btn" value="Reject" class="btn btn-danger">';

				 		//if ($qi == 1) {
					 		$output .= '<input type="submit" name="clear_btn" value="Clear" class="btn btn-success">';
				 		//}


						$output .= "
					 		</form></td>";
						$output .= "</tr>";




				}else{
					$cs_lists = '';
					$cs_arr = '';

				}
			}


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


		return $output;
}


//function get total applicants in a programme
function get_records_applicants_nce_trans_qualify_2($pt, $ses,$qi)
{

	 $output =
	  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		<thead>
			<th>S/No</th>
			<th>Applicant</th>
			<th>Programme Applied</th>
			<th>Olevel result 1</th>
			<th>Olevel result 2</th>
			<th>Action</th>

		</thead>
		<tfoot>
			<th>S/No</th>
			<th>Applicant</th>
			<th>Programme Applied</th>
			<th>Olevel result 1</th>
			<th>Olevel result 2</th>
			<th>Action</th>

		</tfoot>

		<tbody>';


			//query the database
			$q2 = "SELECT app.*
				  FROM  applicants_nce app, applicants_nce_fee_payments app_pay

				  WHERE  app.programme_type_applied_for = $pt
				 AND app.session = $ses AND app.cleared ='0'  AND app_pay.applicant_id = app.id AND app.mode_of_entry = '1'
				  ORDER BY app.programme_applied_for ASC";


			$r2 = mysql_query($q2);


			while($row2 = mysql_fetch_array($r2))
			{

				$applicant_id = $row2['id'];
				$pid = $row2['programme_applied_for'];
				$cid = $row2['clr_changed_programme'];
				$sn += 1;
				$output .= "<tr>";

				$output .= "<td>".$sn."</td>";
				$output .= "<td><b>".$row2['application_number'].'<br>'.$row2['first_name'].' '.$row2['other_names']."</b></td>";

				$output .= "<td>".get_programme_title($pid)." <b>(".show_programme_type($row2['programme_type_applied_for'])."-Transiting)</b>
					<br>
					<span class='badge'>".get_total_prog_applicants_admitted($pt, $pid,$ses,$cleared = 1)."/".get_total_prog_applicants($pt, $pid,$ses)."</span>
				</td>";
				//$output .= "<td>".get_user_qualified_status($applicant_id)."</td>";
				/*$output .= "<td>".validate_applicant_all_olevel($applicant_id)."</td>";*/

				$output .= "<td>".get_applicant_olevel($applicant_id,'1')."</td>";
				$output .= "<td>".get_applicant_olevel($applicant_id,'2')."</td>";


				//get course suggestion
				$cs_lists = '';
				$cs_arr = '';

				$cs_lists = validate_applicant_all_olevel2($applicant_id,$pt);

				if (isset($cs_lists) && ! empty($cs_lists ) ){

            		$cs_arr = $cs_lists;
            	}



				$output .= '<td><form method="POST" action="">
		 			<input type="hidden" name="app_id" value="'.$applicant_id.'">
		 			';


		 		if ($cs_arr !='') {


			 		$output .= '

			 		<h5><b>Course Suggestion</b></h5>
			 		<select class="form-control" name="prog_id" id="sug_courses" >
			                <option value=""> Select Course </option>
			                '.

			                 //displaying the courses


			                list_course2($cs_arr,$cid)

			                .'
			              </select>
			              <input type="submit" name="change_cs_btn2" value="Change Course" class="btn btn-success">
			              <br><br>
			              ';
		           $output .= ' <textarea name="action_msg" class="form-control" placeholder="Enter Remark">'.$row2["clear_reasons"].'</textarea>
		 			<br>';
			      }else{
			      	 $output .= ' <textarea name="action_msg" required class="form-control" placeholder="Enter Remark">'.$row2["clear_reasons"].'</textarea>
		 			<br>';
			      }

		 		$output .= '	<input type="submit" name="reject_btn" value="Reject" class="btn btn-danger">';


				if (applicant_olevel_exist($applicant_id)) {
			 		$output .= '<input type="submit" name="clear_btn" value="Clear" class="btn btn-success">';
		 		}



				$output .= "
			 		</form></td>";
				$output .= "</tr>";


			}



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


		return $output;
}

	function list_course($cs_arr)
	{
		 $dt = '';
		if ($cs_arr != '') {
			foreach ($cs_arr  as $cs) {
		       $dt .= '<option value='.$cs.'>'. get_programme_title( $cs).'</option>';
		    }

	    }

		    return $dt;

	}

	function list_course2($cs_arr,$pid)
	{
		 $dt = '';
		if ($cs_arr != '') {
			foreach ($cs_arr  as  $cs) {

				if ($pid == $cs) {

			       $dt .= '<option selected value='.$cs.'>'. get_programme_title( $cs).'</option>';

				}else{
			       $dt .= '<option value='.$cs.'>'. get_programme_title( $cs).'</option>';
				}
		    }

	    }

		    return $dt;

	}
//check if result already exist
	function applicant_olevel_exist($iid)
	{
		//check if invoice id generated exist
		$q1 = "SELECT applicant_id FROM applicants_olevel_nce WHERE  applicant_id = '$iid'";
		$r1 = mysql_query($q1);

		if(mysql_num_rows($r1)> 0)
		{
			return true;
		}


	}

function get_records_applicants_not_qualify($pt, $ses,$qi)
{

	 $output =
	  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		<thead>
			<th>S/No</th>
			<th>Applicant</th>
			<th>Programme Applied</th>
			<th>Olevel result 1</th>
			<th>Olevel result 2</th>
			<th>Action</th>

		</thead>
		<tfoot>
			<th>S/No</th>
			<th>Applicant</th>
			<th>Programme Applied</th>
			<th>Olevel result 1</th>
			<th>Olevel result 2</th>
			<th>Action</th>

		</tfoot>

		<tbody>';


			//query the database
			$q2 = "SELECT app.*
				  FROM  applicants_nce app, applicants_nce_fee_payments app_pay

				  WHERE   app.qualified = $qi AND app.programme_type_applied_for = $pt
				 AND app.session = $ses AND app.cleared ='0'  AND app_pay.applicant_id = app.id AND app.mode_of_entry != '1'

				  ORDER BY app.programme_applied_for ASC";
				  //AND app.batch = '1' AND app.admission_status = '1'
			$r2 = mysql_query($q2);


			while($row2 = mysql_fetch_array($r2))
			{

				$applicant_id = $row2['id'];
				$mode_of_entry = $row2['mode_of_entry'];
				$snn += 1;
				$output .= "<tr>";

				$output .= "<td>".$snn."</td>";
				$output .= "<td><b>".$row2['application_number'].'<br>'.$row2['first_name'].' '.$row2['other_names']."</b></td>";

				$output .= "<td>".get_programme_title($row2['programme_applied_for'])." <b>(".show_programme_type($row2['programme_type_applied_for']).")</b></td>";
				//$output .= "<td>".get_user_qualified_status($applicant_id)."</td>";
				/*$output .= "<td>".validate_applicant_all_olevel($applicant_id)."</td>";*/

				$output .= "<td>".get_applicant_olevel($applicant_id,'1')."</td>";
				$output .= "<td>".get_applicant_olevel($applicant_id,'2')."</td>";

				//get course suggestion
				$cs_lists = '';
				$cs_arr = '';

				//$cs_lists = validate_applicant_all_olevel($applicant_id);
				$cs_lists = get_valid_programme_nce($pt);

				if (isset($cs_lists) && ! empty($cs_lists ) ){

            		$cs_arr = $cs_lists;
            	}

            	//get prence course
            	$prence_progs = get_valid_programme_nce($ptt=1);


            	if (applicant_olevel_exist($applicant_id)) {

            			$output .= '<td><form method="POST" action="">
            				<input type="hidden" name="app_id" value="'.$applicant_id.'">';
			     		//when NCE
			    		if ($pt==2) {

							$output .= '

								<div class="bg-info">
									<div>
										<h5 class="text-center"><b>NCE TO PRE-NCE</b></h5>
										<select class="form-control" name="swap_prog_id" >
							                <option value=""> Select Course </option>
							                '.

							                 //displaying the prence courses

							                list_course($prence_progs)

							                .'
							            </select>
							            <input type="submit" name="swap_prog_btn" value="Convert Programme" class="btn btn-primary">
						            </div>
						            <br>
								</div>
								<br><br>

					 			';
						}

				 		if ($cs_arr !='') {


					 		$output .= '

					 		<h5><b>Course Suggestion</b></h5>
					 		<select class="form-control" name="prog_id" id="sug_courses" >
					                <option value=""> Select Course </option>
					                '.

					                 //displaying the courses


					                list_course($cs_arr)

					                .'
					              </select>
					              <input type="submit" name="change_cs_btn" value="Change Course" class="btn btn-success">
					              <br><br>
					              ';


					          	 $output .= ' <textarea name="action_msg" class="form-control" placeholder="Enter Remark">'.$row2["clear_reasons"].'</textarea>
					 			<br>';
					      }else{
					      	 $output .= ' <textarea name="action_msg" required class="form-control" placeholder="Enter Remark">'.$row2["clear_reasons"].'</textarea>
				 			<br>';
					      }




				 			$output .= '<input type="submit" name="reject_btn" value="Reject" class="btn btn-danger">';
				 		//when transiting
				 		if ($mode_of_entry == 1 && applicant_olevel_exist($applicant_id)) {
					 		$output .= '<input type="submit" name="clear_btn779" value="Clear" class="btn btn-success">';
				 		}


						$output .= "
					 		</form></td>";
						$output .= "</tr>";

				}else{
					$cs_lists = '';
					$cs_arr = '';


				}

			}



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



		return $output;
}

//function get total applicants in a programme
function get_records_applicants_prence($pt, $ses, $md)
{
	$q = "SELECT DISTINCT (applicant_id) FROM applicants_nce_fee_payments  WHERE programme_type_id = '$pt'
			 AND session= '$ses'  AND mode = '$md'";
	$r = mysql_query($q);
	$sn = 0;

	if(mysql_num_rows($r) > 0)
	{//show table
		//get applicant data


	  $output =
	  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		<thead>
			<th>S/No</th>
			<th>Application Number</th>
			<th>Name</th>
			<th>Phone No</th>
			<th>Gender</th>
			 <th>Programme Type</th>
			<th>Programme Applied</th>
			<th>Application Status</th>
			<th>Suggessted Courses</th>
		</thead>
		<tfoot>
			<th>S/No</th>
			<th>Application Number</th>
			<th>Name</th>
			<th>Phone No</th>
			<th>Gender</th>
			<th>Programme Type</th>
			<th>Programme Applied</th>
			<th>Application Status</th>
			<th>Suggessted Courses</th>
		</tfoot>

		<tbody>';
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$applicant_id =  $row['applicant_id'];

			//query the database
			$q2 = "SELECT id, programme_type_applied_for, school_applied_for,department_applied_for, programme_applied_for, application_number,
				  state_id, lga_id, first_name, other_names, phone_no, gender,  email, qualified,
				  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
				  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
				  FROM  applicants_nce

				  WHERE   id = '$applicant_id'

				  ORDER BY id ASC";

			$r2 = mysql_query($q2);


			while($row2 = mysql_fetch_array($r2, MYSQL_ASSOC))
			{
				$sn += 1;



				$output .= "<tr>";

				$output .= "<td>".$sn."</td>";
				$output .= "<td>".$row2['application_number']."</td>";
				$output .= "<td> <a href='#'>".$row2['first_name'].' '.$row2['other_names']."</a></td>";
				$output .= "<td>".$row2['phone_no']."</td>";
				$output .= "<td>".$row2['gender']."</td>";
				$output .= "<td>".show_programme_type($row2['programme_type_applied_for'])."</td>";
				$output .= "<td>".get_programme_title($row2['programme_applied_for'])."</td>";
				$output .= "<td>".get_user_qualified_status($applicant_id)."</td>";
				$output .= "<td>".validate_applicant_all_olevel($applicant_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 validate_applicant_all_olevel($id)
	{
		$olevel1_str = '';
		$olevel2_str = '';
		$all_olevel = array();

		//$sub_and_grd_1 ='';

		$q = "SELECT * FROM `applicants_olevel_nce`
				WHERE applicant_id = '$id' AND type = '1'";

		$q2 = "SELECT * FROM `applicants_olevel_nce`
				WHERE applicant_id = '$id' AND type = '2'";

		$r = mysql_query($q);
		$r2 = mysql_query($q2);

		if(mysql_num_rows($r) > 0 ){
			$rec = mysql_fetch_array($r,MYSQL_ASSOC);
			$rec2 = mysql_fetch_array($r2,MYSQL_ASSOC);

			//initializing variables to prevent errors
			for ($i = 1 ; $i < 10; $i++) {
				$sb = '';
				$gr = '';

				//passing values to new variable
				$sb = 'subject'. $i;
				$gr = 'grade'. $i;
				//fetching records
				$sb_val =  $rec[$sb];
				$gr_val =  $rec[$gr];

				$sb_val2 =  $rec2[$sb];
				$gr_val2 =  $rec2[$gr];

				if (pass_olevel($gr_val)) {
					$olevel1_str .= $sb_val.',' ;
				}

				if (pass_olevel($gr_val2)) {
					$olevel2_str .= $sb_val2.',' ;
				}

			}

		}

		//creating the array with valid subjects
		$olevel_1 =  explode( ',' , $olevel1_str);
		$olevel_2 =  explode( ',' , $olevel2_str);

		//removing the last empty data due to the last , comma
		for ($i = 0; $i < count($olevel_1); $i++) {
			if ($olevel_1[$i] !== '') {
				if ( ! in_array($olevel_1[$i], $all_olevel)) {
					//merging all olevel
					array_push( $all_olevel , $olevel_1[$i]);
				}
			}

		}
		//removing the last empty data due to the last , comma
		for ($i = 0; $i < count($olevel_2); $i++) {
			if ($olevel_2[$i] !== '') {
				if ( ! in_array($olevel_2[$i], $all_olevel)) {
					//merging all olevel
					array_push( $all_olevel , $olevel_2[$i]);
				}
			}

		}





		$qi = 0;
		$qualified = check_applicant_required_olevel($all_olevel, $id);


		if ($qualified == true) {
			//return $qi = 1;
			return '<p class="btn btn-success disabled">Qualified</p>';
		}else{
			//return $all_olevel;
			return get_course_suggestion2($all_olevel,$id);
		}


	}

	function validate_applicant_all_olevel2($id,$pt)
	{
		$olevel1_str = '';
		$olevel2_str = '';
		$all_olevel = array();

		//$sub_and_grd_1 ='';

		$q = "SELECT * FROM `applicants_olevel_nce`
				WHERE applicant_id = '$id' AND type = '1'";

		$q2 = "SELECT * FROM `applicants_olevel_nce`
				WHERE applicant_id = '$id' AND type = '2'";

		$r = mysql_query($q);
		$r2 = mysql_query($q2);

		if(mysql_num_rows($r) > 0 ){
			$rec = mysql_fetch_array($r,MYSQL_ASSOC);
			$rec2 = mysql_fetch_array($r2,MYSQL_ASSOC);

			//initializing variables to prevent errors
			for ($i = 1 ; $i < 10; $i++) {
				$sb = '';
				$gr = '';

				//passing values to new variable
				$sb = 'subject'. $i;
				$gr = 'grade'. $i;
				//fetching records
				$sb_val =  $rec[$sb];
				$gr_val =  $rec[$gr];

				$sb_val2 =  $rec2[$sb];
				$gr_val2 =  $rec2[$gr];

				if (pass_olevel($gr_val)) {
					$olevel1_str .= $sb_val.',' ;
				}

				if (pass_olevel($gr_val2)) {
					$olevel2_str .= $sb_val2.',' ;
				}

			}

		}

		//creating the array with valid subjects
		$olevel_1 =  explode( ',' , $olevel1_str);
		$olevel_2 =  explode( ',' , $olevel2_str);

		//removing the last empty data due to the last , comma
		for ($i = 0; $i < count($olevel_1); $i++) {
			if ($olevel_1[$i] !== '') {
				if ( ! in_array($olevel_1[$i], $all_olevel)) {
					//merging all olevel
					array_push( $all_olevel , $olevel_1[$i]);
				}
			}

		}
		//removing the last empty data due to the last , comma
		for ($i = 0; $i < count($olevel_2); $i++) {
			if ($olevel_2[$i] !== '') {
				if ( ! in_array($olevel_2[$i], $all_olevel)) {
					//merging all olevel
					array_push( $all_olevel , $olevel_2[$i]);
				}
			}

		}





		//$qi = 0;
		//$qualified = check_applicant_required_olevel($all_olevel, $id);


		if ($qualified == true) {
			//return $qi = 1;
			return '<p class="btn btn-success disabled">Qualified</p>';
		}else{
			//return $all_olevel;
			return get_course_suggestion3($all_olevel,$id,$pt);
		}


	}

	function pass_olevel($gr)
	{
		//validating pass grade
		if ( $gr > 0 &&   $gr < 7) {
			return true;
		}
	}

	function check_applicant_required_olevel($olevel_arr, $uid)
{
	//intializing an array for tracking validated subjects
	$dt = '';
	//get required subjects combination
	$app_prog = get_user_programme_applied_for($uid);
	$app_req_subj = get_applicant_required_subjects($app_prog);
	$app_opt_subj = get_applicant_optional_subjects($app_prog);
	$app_opt_sub_count = get_applicant_optional_count($app_prog);


	$req_subj =  explode( ',' , $app_req_subj);
	$opt_subj =  explode( ',' , $app_opt_subj);

	//getting the required subjects counts
	$app_req_subj_count = count($req_subj);


	 $req_sub_match = get_matched_subjects($olevel_arr, $req_subj);
	 $opt_sub_match = get_matched_subjects($olevel_arr, $opt_subj);


	//check if present validated subjects match required once
	 if ($req_sub_match == $app_req_subj_count ) {

	 	if ($app_opt_sub_count > 0) {
	 		//checking optional counts
	 		if ($opt_sub_match >= $app_opt_sub_count ) {
	 			$dt = true;
	 		}
	 	//when their is no optional count for the applicanr program
	 	//and the validated subjects match required once
	 	}else{
	 		$dt = true;
	 	}


	}else{
		$dt = false;
	}


		//$var = implode($dt, ' ');

	//return  $var[1];
	return   $dt;

}
//function that gets programme_id base on user id
function  get_applicant_required_subjects($pid)
{
	$result = mysql_query("SELECT required_subjects FROM programmes WHERE id = '$pid'");
		$row = mysql_fetch_assoc($result);
		$v = $row['required_subjects'];
	if ($v) {
		return $v;
	}


}
//function that gets programme_id base on user id
function  get_applicant_optional_subjects($pid)
{
	$result = mysql_query("SELECT optional_subjects FROM programmes WHERE id = '$pid'");
		$row = mysql_fetch_assoc($result);
		$v = $row['optional_subjects'];
	if ($v) {
		return $v;
	}


}
//function that gets programme_id base on user id
function  get_applicant_optional_count($pid)
{
	$result = mysql_query("SELECT optional_count FROM programmes WHERE id = '$pid'");
		$row = mysql_fetch_assoc($result);
		$v = $row['optional_count'];
	if ($v) {
		return $v;
	}

}
function get_matched_subjects($app_sub, $req_sub)
{
	//compare applicant subjects with required subjects
	$c = 0;
	for ($i = 0; $i < count($app_sub) ; $i++) {

		if (in_array($app_sub[$i], $req_sub)) {
			$c ++;

		}

	}

	return $c;

}
function get_suggested_courses($olevel_arr , $uid)
{
	//intializing an array for tracking validated subjects
	$dt[] = '';
	$ff = '';
	$app_prog = get_user_programme_applied_for($uid);
	$pt = get_user_programme_type_applied_for($uid);

	$r = mysql_query("SELECT title, id, required_subjects, optional_subjects,optional_count
					FROM programmes WHERE real_ = '0' AND type_id = '$pt'
					AND mode = 1 AND id != '$app_prog'
					ORDER BY title");

	//get required subjects combination
	/*$app_req_subj = get_applicant_required_subjects($app_prog);
	$app_opt_subj = get_applicant_optional_subjects($app_prog);
	$app_opt_sub_count = intval(get_applicant_optional_count($app_prog));
	*/
	$i = 0;
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			//looping through programs
			$rq_sub = $row['required_subjects'];
			$op_sub = $row['optional_subjects'];
			$opt_sub_count = intval($row['optional_count']);

			if ($rq_sub != '') {
				$i ++;


				$req_subj =  explode( ',' , $rq_sub);
				$opt_subj =  explode( ',' , $op_sub);

				$req_sub_match = get_matched_subjects($olevel_arr, $req_subj);
				$opt_sub_match = get_matched_subjects($olevel_arr, $opt_subj);
				//getting the required subjects counts
				$rq_sub_count = count($req_subj);

				//$ff .= $opt_sub_count .' '. $opt_sub_match.'<br>';
				//if required courses is empty, done even suggest
				if ($req_sub_match > 0) {
					//check if present validated subjects match required once
					if ($req_sub_match == $rq_sub_count ) {

					 	if ($opt_sub_count > 0) {
					 		//checking optional counts
					 		if ($opt_sub_match >= $opt_sub_count ) {
					 			//$dt = true;
					 			//get the program id
						 		$pid = $row['id'];
						 		array_push($dt, $pid);
					 		}
					 	//when their is no optional count for the applicanr program
					 	//and the validated subjects match required once
					 	}else{
					 		//$dt = true;
					 		//get the program id
					 		$pid = $row['id'];
					 		array_push($dt, $pid);
					 	}


					}else{
						//$d = false;
					}
				}

			}

		}


	}

	unset($dt['0']);
	return  $dt;
	//using while loop
	//get all program id
	//get required subjects combination
	/*	$app_prog = get_user_programme_applied_for($uid);






	*/

		//$var = implode($dt, ' ');

	//return  $var[1];


}
function get_blocked_nce_prog_id($pt)
{
	$pids = array();
	//prence
	if ($pt == 1) {
		/*$pids = [

				86, 89, 93, 98,
				99, 102, 103, 104,
				105, 106, 107, 108,
				120, 121, 124, 126,
				129, 130, 131, 138,
				140, 141, 143, 151,
				153, 158, 157 , 159,
				160, 161, 162, 167,
				171,172
			];*/

	//nce
	}else if ($pt == 2){

		/*$pids = [
				1, 4, 8, 13, 14, 17,
				18, 19, 20, 21, 22, 23,
				35, 36, 40, 43, 44, 45,
				51, 52, 54, 55, 61,
				63, 65, 69, 70, 71,
				72, 73, 85, 81, 82
			];*/
	}

	return $pids;
}
function get_suggested_courses3($olevel_arr , $uid , $pt)
{
	//courses to exempt

	$not_cs = get_blocked_nce_prog_id($pt);

	//intializing an array for tracking validated subjects
	$dt[] = '';
	$ff = '';
	$app_prog = get_user_programme_applied_for($uid);
	$pt = get_user_programme_type_applied_for($uid);


	$r = mysql_query("SELECT title, id, required_subjects, optional_subjects,optional_count
					FROM programmes WHERE real_ = '0' AND type_id = '$pt'
					AND mode = 1 AND id != '$app_prog'
					ORDER BY title");

	//get required subjects combination
	/*$app_req_subj = get_applicant_required_subjects($app_prog);
	$app_opt_subj = get_applicant_optional_subjects($app_prog);
	$app_opt_sub_count = intval(get_applicant_optional_count($app_prog));
	*/
	$i = 0;
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			//looping through programs
			$rq_sub = $row['required_subjects'];
			$op_sub = $row['optional_subjects'];
			$opt_sub_count = intval($row['optional_count']);

			if ($rq_sub != '') {
				$i ++;


				$req_subj =  explode( ',' , $rq_sub);
				$opt_subj =  explode( ',' , $op_sub);

				$req_sub_match = get_matched_subjects($olevel_arr, $req_subj);
				$opt_sub_match = get_matched_subjects($olevel_arr, $opt_subj);
				//getting the required subjects counts
				$rq_sub_count = count($req_subj);

				//$ff .= $opt_sub_count .' '. $opt_sub_match.'<br>';
				//if required courses is empty, done even suggest
				if ($req_sub_match > 0) {
					//check if present validated subjects match required once
					if ($req_sub_match == $rq_sub_count ) {

					 	if ($opt_sub_count > 0) {
					 		//checking optional counts
					 		if ($opt_sub_match >= $opt_sub_count ) {
					 			//$dt = true;
					 			//get the program id
						 		$pid = $row['id'];
						 		//only available courses
						 		/*for ($i = 0; $i < count($not_cs); $i++) {
								*/
								if (!in_array($pid, $not_cs)) {

									//$c ++;
							 		array_push($dt, $pid);

								}


					 		}
					 	//when their is no optional count for the applicanr program
					 	//and the validated subjects match required once
					 	}else{
					 		//$dt = true;
					 		//get the program id
					 		$pid = $row['id'];
					 		array_push($dt, $pid);
					 	}


					}else{
						//$d = false;
					}
				}

			}

		}


	}

	unset($dt['0']);
	return  $dt;
	//using while loop
	//get all program id
	//get required subjects combination
	/*	$app_prog = get_user_programme_applied_for($uid);






	*/

		//$var = implode($dt, ' ');

	//return  $var[1];


}

function get_valid_programme_nce($pt)
{
	//courses to exempt

	$not_cs = get_blocked_nce_prog_id($pt);

	//intializing an array for tracking validated subjects
	$dt[] = '';



	$r = mysql_query("SELECT title, id
					FROM programmes WHERE real_ = '0' AND type_id = '$pt'
					AND mode = 1
					ORDER BY title");

	//get required subjects combination
	/*$app_req_subj = get_applicant_required_subjects($app_prog);
	$app_opt_subj = get_applicant_optional_subjects($app_prog);
	$app_opt_sub_count = intval(get_applicant_optional_count($app_prog));
	*/
	$i = 0;
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$pid = $row['id'];
			//looping through programs
			if (!in_array($pid, $not_cs)) {

				//$c ++;
		 		array_push($dt, $pid);

			}
		}



	}

	unset($dt['0']);
	return  $dt;
	//using while loop
	//get all program id
	//get required subjects combination
	/*	$app_prog = get_user_programme_applied_for($uid);






	*/

		//$var = implode($dt, ' ');

	//return  $var[1];


}


function get_course_suggestion($all_olevel,$id)
{
		//print_r(get_suggested_courses($all_olevel));
		$dt_arr = get_suggested_courses($all_olevel,$id);
		$dt_count = count($dt_arr);
		$list ='';
		/*print_r($all_olevel);
		exit();*/

		if (isset($_SESSION['cs_lists'])) {
			unset($_SESSION['cs_lists']);
		}

		$_SESSION['cs_lists'] =  $dt_arr;

		if ($dt_count > 0) {
			//displaying the found suggested course
			for ( $dt_i = 1; $dt_i <= $dt_count; $dt_i++) {
				$list .= get_programme_code($dt_arr[$dt_i]).'<br>';
			}

			return   '<h5 class="alert-info">'.$list.'</h5>';

		} else {
			return  '<h5 class="alert-danger"> Sorry, no suggested course</h5>';

		}
}
function get_course_suggestion2($all_olevel,$id)
{
		//print_r(get_suggested_courses($all_olevel));
		$dt_arr = get_suggested_courses($all_olevel,$id);
		$dt_count = count($dt_arr);
		$list ='';
		/*print_r($all_olevel);
		exit();*/

		$dt_arr;

		if ($dt_arr != '') {
			return $dt_arr;

		} else {
			return  '';

		}
}
function get_course_suggestion3($all_olevel,$id ,$pt)
{
		//print_r(get_suggested_courses($all_olevel));
		$dt_arr = get_suggested_courses3($all_olevel,$id ,$pt);
		$dt_count = count($dt_arr);
		$list ='';
		/*print_r($all_olevel);
		exit();*/

		$dt_arr;

		if ($dt_arr != '') {
			return $dt_arr;

		} else {
			return  '';

		}
}
//function get total applicants in a programme
function get_records_applicants_nce_lvsp($pt, $ses, $md)
{
	$q = "SELECT DISTINCT (applicant_id) FROM applicants_nce_fee_payments  WHERE programme_type_id = '$pt'
			 AND session= '$ses'  AND mode = '$md'";
	$r = mysql_query($q);
	$sn = 0;

	if(mysql_num_rows($r) > 0)
	{//show table
		//get applicant data


	  $output =
	  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		<thead>
			<th>S/No</th>
			<th>Application Number</th>
			<th>Name</th>
			<th>Phone No</th>

			<th>Gender</th>
			 <th>Programme Type</th>
			<th>Programme Applied</th>
			<th>Application Status</th>
			<th>Suggessted Courses</th>


		</thead>
		<tfoot>
			<th>S/No</th>
			<th>Application Number</th>
			<th>Name</th>
			<th>Phone No</th>
			<th>Gender</th>
			<th>Programme Type</th>
			<th>Programme Applied</th>
			<th>Application Status</th>
			<th>Suggessted Courses</th>

		</tfoot>

		<tbody>';
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$applicant_id =  $row['applicant_id'];

			//query the database
			$q2 = "SELECT id, programme_type_applied_for, school_applied_for,department_applied_for, programme_applied_for, application_number,
				  state_id, lga_id, first_name, other_names, phone_no, gender,  email,  qualified,
				  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
				  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
				  FROM  applicants_nce

				  WHERE   id = '$applicant_id'

				  ORDER BY id ASC";

			$r2 = mysql_query($q2);


			while($row2 = mysql_fetch_array($r2, MYSQL_ASSOC))
			{
				$sn += 1;
				$output .= "<tr>";

				$output .= "<td>".$sn."</td>";
				$output .= "<td>".$row2['application_number']."</td>";
				$output .= "<td> <a href='#'>".$row2['first_name'].' '.$row2['other_names']."</a></td>";
				$output .= "<td>".$row2['phone_no']."</td>";
				$output .= "<td>".$row2['gender']."</td>";
				$output .= "<td>".show_programme_type($row2['programme_type_applied_for'])."</td>";
				$output .= "<td>".get_programme_title($row2['programme_applied_for'])."</td>";
				$output .= "<td>".get_user_qualified_status($applicant_id)."</td>";
				$output .= "<td>".validate_applicant_all_olevel($applicant_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 get total applicants in a programme
function check_applicant_is_nce_lvsp($id, $pt, $cid, $ses)
{
	$q = "SELECT * FROM applicants_nce   WHERE id = '$id' AND programme_type_applied_for = '$pt'
			AND cart_id = '$cid' AND session= '$ses' ";
	$r = mysql_query($q);
	if (mysql_num_rows($r) == 1) {
		return true;
	}

}


//function get total applicants in a programme
function check_applicant_is_prence($id, $pt, $cid, $ses)
{
	$q = "SELECT * FROM applicants_nce   WHERE id = '$id' AND programme_type_applied_for = '$pt'
			AND cart_id = '$cid' AND session= '$ses' ";
	$r = mysql_query($q);
	if (mysql_num_rows($r) == 1) {
		return true;
	}

}

//function get total applicants in a programme
function get_total_prog_type_programme_applicants_lvsp($pt, $md, $id)
{
	$q = "SELECT  DISTINCT (COUNT(applicant_id)) FROM applicants_nce_fee_payments  WHERE programme_type_id = '$pt'
			AND programme_id = '$id' AND mode = '$md'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



//function get total applicants in a programme type
function get_total_programme_type_applicants($id)
{
	$q = "SELECT COUNT(id) FROM applicants_nce  WHERE  programme_type_applied_for = '$id'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function fetch user qualified status
	function get_user_qualified_status($id)
	{
		$result = mysql_query("SELECT qualified FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['qualified'];
		if ($v) {
			return '<p class="btn btn-info disabled">Qualified</p>';
		}else{
			return '<p class="btn btn-danger disabled">Not Qualified</p>';
		}

	}
	//function fetch user qualified status
	function get_user_qualified_status_sum1($id)
	
	{
		$result = mysql_query("SELECT qualified FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['qualified'];
		if ($v) {
			return '<p class="btn btn-info disabled">Qualified</p>';
		}else{
			return '<p class="btn btn-danger disabled">Not Qualified</p>';
		}

	}
//function fetch user qualified status
	function get_user_qualified_status1($id)
	{
		$result = mysql_query("SELECT qualified FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['qualified'];
		if ($v) {
			return  true;
		}

	}


	function get_user_qualified_status_sum($id)
	{
		$result = mysql_query("SELECT qualified FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['qualified'];
		if ($v) {
			return  true;
		}

	}

//function view list with pins
function view_applicants_pins_list()
{


	//query the database
	$q = "SELECT `id`, `programme_type_applied_for`, `department_applied_for`, `programme_applied_for`, `application_number`, `state_id`, `lga_id`, `first_name`, `other_names`, `phone_no`,  `gender`,  `email`,  `transaction_id`, `bank_epin`, `serial_number`, DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		 FROM  applicants

		 ORDER BY application_number";
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>Application Number</th>
						<th>Name</th>
						<th>Gender</th>
						 <th>Programme Type</th>
						<th>Programme Applied</th>

						<th>Ph. Contacts</th>
						<th>Email</th>
						<th>TID</th>
						<th>Bank PIN</th>
						<th>Serial No.</th>



			</thead>
			<tfoot>
						<th>Application Number</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>Programme Applied</th>

						<th>Ph. Contacts</th>
						<th>Email</th>
						<th>TID</th>
						<th>Bank PIN</th>
						<th>Serial No.</th>

			</tfoot>

			<tbody>';

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

			$output .= "<td>".$row['application_number']."</td>";
			$output .= "<td> <a href=''>".$row['first_name'].' '.$row['other_names']."</a></td>";
			$output .= "<td>".$row['gender']."</td>";
			$output .= "<td>".show_programme_type($row['programme_type_applied_for'])."</td>";
			$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";

			$output .= "<td>".$row['phone_no']."</td>";
			$output .= "<td>".$row['email']."</td>";
			$output .= "<td>".$row['transaction_id']."</td>";
			$output .= "<td>".$row['bank_epin']."</td>";
			$output .= "<td>".$row['serial_number']."</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 applicants pin list

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

		if ($pt == '1')
		{
			$output = 'ABU';

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

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

		}
		else
		{

			$output = 'NIL';

		}

	return $output;

}
//end of show programme_type


//function that get all departments attached to applicants
function get_listed_departments_for_applicants()
{
	//query the database
	$q = "SELECT * FROM  departments WHERE status = '0' AND real_ = '0'  ORDER BY title";
	$r = mysql_query($q);

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

		$output =  '';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= '<li class="list-group-item">'.$row['title'].'
						<span class="pull-right badge">'.get_total_department_applicants($row['id']).'</span> <br/>

						</li>';

		}
	}
	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.
				   </div>';

	}

	return $output;

}



//function that get all programmes
function get_listed_programmes_for_applicants()
{
	//query the database
	$q = "SELECT * FROM  programmes WHERE status = '0' AND real_ = '0'  ORDER BY title";
	$r = mysql_query($q);

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

		$output =  '';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= '<li class="list-group-item">'.$row['title'].'
						<span class="pull-right badge">'.get_total_prog_type_programme_applicants($row['type_id'],$row['id']).'</span> <br/>
						<span class="help-block" style="font-size:10px">'.get_department_title($row['department_id']).'</span>
						<span class="help-block" style="font-size:10px">'.show_programme_type($row['type_id']).'</span>
						</li>';

		}
	}
	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.
				   </div>';

	}

	return $output;

}



//function that get all programmes type
function get_listed_programmes_types_for_applicants()
{

		$output =  '';


		for($i = 1 ; $i <= 3; $i++)
		{
			$output .= '<li class="list-group-item">'.show_programme_type($i).'
						<span class="pull-right badge">'.get_total_programme_type_applicants($i).'</span> <br/>

						</li>';


		}


	//<span class="help-block" style="font-size:10px">'.get_programme_title_for_applicants($i).'</span>
	return $output;

}

//function that gets programme title for applicants
function  get_programme_title_for_applicants($id)
{
	$result = mysql_query("SELECT * FROM applicants WHERE type_id = '$id'");
		$row = mysql_fetch_assoc($result);
		$title = $row['title'];

	return $title;

}

//function get applicant image by passing id alone
function get_applicant_image($id)
{
	$result = mysql_query("SELECT image FROM applicants_nce WHERE id = '$id'");
	$row = mysql_fetch_assoc($result);
	$image = $row['image'];




	if($image != '')
	{//show table



		  //get applicant pt
          $pty =  get_applicant_programme_type_applied_for($id);

          $up_path = '';

          //when Prence
           if( $pty == 1){
             $up_path = '../prence/uploads/';
             //when NCE
           }elseif ($pty == 2) {
                $up_path = '../nce/uploads/';
           }

			$output = '<img class="img-responsive img-rounded img-thumbnail center-block" src='.$up_path.$row["image"].' style="height:100px ;width:80px"    />'; //https://eportals.ibbuconsult.com.ng/ndp/uploads/'.$row['image'].'


	}
	else
	{
		$output = '<label class="label label-danger">NO IMAGE</label>';
	}


	return $output;




}//end of function that shows candidate image


//function get applicant image by passing id alone
function get_student_image($id, $pt)
{
	$result = mysql_query("SELECT image FROM students_nce WHERE id = '$id'");
	$row = mysql_fetch_assoc($result);
	$image = $row['image'];




	if($image != '')
	{//show table



		  //get applicant pt
          $pty =  $pt;

          $up_path = '';

          //when Prence
           if( $pty == 1){
             $up_path = '../prence/uploads/';
             //when NCE
           }elseif ($pty == 2) {
                $up_path = '../nce/uploads/';
           }

			$output = '<img class="img-responsive img-rounded img-thumbnail center-block" src='.$up_path.$row["image"].' style="height:100px ;width:80px"    />'; //https://eportals.ibbuconsult.com.ng/ndp/uploads/'.$row['image'].'


	}
	else
	{
		$output = '<label class="label label-danger">NO IMAGE</label>';
	}


	return $output;




}//end of function that shows candidate image


//function view applicants listings
function view_applicants_list()
{


	//query the database
	$q = "SELECT `id`, `programme_type_applied_for`, `department_applied_for`, `programme_applied_for`, `application_number`, `state_id`, `lga_id`, `first_name`, `other_names`, `phone_no`,  `gender`,  `email`,  `transaction_id`, `bank_epin`, `serial_number`, DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		 FROM  applicants


		 WHERE  bank_epin != ''

		 ORDER BY application_number ASC";
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>Applied For</th>
						<th>Ph. Contacts</th>
						<th>Email</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>



			</thead>
			<tfoot>

						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>Applied For</th>

						<th>Ph. Contacts</th>
						<th>Email</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td>".$row['application_number']."</td>";
			$output .= "<td> <a href='gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$row['id']."'>".$row['first_name'].' '.$row['other_names']."</a></td>";
			$output .= "<td>".$row['gender']."</td>";
			$output .= "<td>".show_programme_type($row['programme_type_applied_for'])."</td>";
			$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";

			$output .= "<td>".$row['phone_no']."</td>";
			$output .= "<td>".$row['email']."</td>";
			$output .= "<td>".get_state_title($row['state_id'])."</td>";
			$output .= "<td>".get_lga_title($row['lga_id'])."</td>";
			$output .= "<td>".get_applicant_image($row['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;




}//end of view applicants listings


//function view applicants listings per programmes
function view_applicants_list_per_programmes($pt, $p, $sess) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT id, programme_type_applied_for, school_applied_for,department_applied_for, programme_applied_for, application_number,
		  state_id, lga_id, first_name, other_names, phone_no, gender,  email,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		  FROM  applicants_nce

		  WHERE   programme_type_applied_for = '$pt' AND programme_applied_for = '$p'
		  AND session = '$sess'

		  ORDER BY application_number ASC

		  ";
	$r = mysql_query($q);



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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>School Applied For</th>
						<th>Applied For</th>

						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Application Status</th>
						<th>Admission Status</th>



			</thead>
			<tfoot>

						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>School Applied For</th>

						<th>Applied For</th>
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Application Status</th>
						<th>Admission Status</th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{

			//display applicant when has paid app fee
			if (applicant_has_paid_app_fees($row['id'])){

				$output .= "<tr>";
				$output .= "<td>".$row['application_number']."</td>";
				$output .= "<td> <a href='gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$row['id']."' target='_new'>".$row['first_name'].' '.$row['other_names']."</a></td>";
				$output .= "<td>".$row['gender']."</td>";
				$output .= "<td>".show_programme_type($row['programme_type_applied_for'])."</td>";
				$output .= "<td>".get_school_title($row['school_applied_for'])."</td>";

				$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";
				$output .= "<td>".$row['phone_no']."</td>";
				$output .= "<td>".get_state_title($row['state_id'])."</td>";
				$output .= "<td>".get_lga_title($row['lga_id'])."</td>";
				$output .= "<td>".get_applicant_image($row['id'])."</td>";
				$output .= "<td>".get_user_qualified_status($row['id'])."</td>";
				$output .= "<td>".is_admitted($row['id'])."</td>";



				$output .= "</tr>";

			}else{
				//echo $output .= $row['id'].'ujhjhkj';

			}

		}
	}
	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 applicants listings per programmes




//function view applicants listings per programmes
function view_acc_fee_list_per_programmes( $p, $sess) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT id, programme_type_applied_for, school_applied_for,department_applied_for, programme_applied_for, jamb_no,
		  state_id, lga_id, first_name, other_names, phone_no, gender,  email,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		  FROM  applicants_nce

		  WHERE   programme_applied_for = '$p'
		  AND session = '$sess'

		  ORDER BY jamb_no ASC

		  ";
	$r = mysql_query($q);



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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>JAMB No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>School Applied For</th>
						<th>Applied For</th>

						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Application Status</th>
						<th>Admission Status</th>



			</thead>
			<tfoot>

						<th>JAMB No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>School Applied For</th>

						<th>Applied For</th>
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Application Status</th>
						<th>Admission Status</th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			//display applicant when has paid app fee
			if (applicant_has_paid_acc_fees_deg($row['id'])){
			

				$output .= "<tr>";
				$output .= "<td>".$row['jamb_no']."</td>";
				$output .= "<td> <a href='gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$row['id']."' target='_new'>".$row['first_name'].' '.$row['other_names']."</a></td>";
				$output .= "<td>".$row['gender']."</td>";
				$output .= "<td>".show_programme_type($row['programme_type_applied_for'])."</td>";
				$output .= "<td>".get_school_title($row['school_applied_for'])."</td>";

				$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";
				$output .= "<td>".$row['phone_no']."</td>";
				$output .= "<td>".get_state_title($row['state_id'])."</td>";
				$output .= "<td>".get_lga_title($row['lga_id'])."</td>";
				$output .= "<td>".get_applicant_image($row['id'])."</td>";
				$output .= "<td>".get_user_qualified_status($row['id'])."</td>";
				$output .= "<td>".is_admitted($row['id'])."</td>";



				$output .= "</tr>";

			}else{
				//echo $output .= $row['id'].'ujhjhkj';

			}

		}
	}
	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 applicants listings per programmes


//function view applicants listings per programmes
function view_applicants_list_per_programmes_deg($p, $sess) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT id, programme_type_applied_for, school_applied_for,department_applied_for, programme_applied_for, application_number,
		  state_id, lga_id, first_name, other_names, phone_no, gender,  email,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added
		  FROM  applicants_nce

		  WHERE  programme_applied_for = '$p'
		  AND session = '$sess'

		  ORDER BY application_number ASC

		  ";
	$r = mysql_query($q);


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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>School Applied For</th>
						<th>Applied For</th>

						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Application Status</th>
						<th>Admission Status</th>



			</thead>
			<tfoot>

						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>School Applied For</th>

						<th>Applied For</th>
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Application Status</th>
						<th>Admission Status</th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{

			//display applicant when has paid app fee
			if (applicant_has_paid_app_fees_deg($row['id'])){

				$output .= "<tr>";
				$output .= "<td>".$row['application_number']."</td>";
				$output .= "<td> <a href='gateway.php?act=view_applicant_profile_sum&id=".md5('profile')."&xd=".$row['id']."' target='_new'>".$row['first_name'].' '.$row['other_names']."</a></td>";
				$output .= "<td>".$row['gender']."</td>";
				$output .= "<td>".show_programme_type($row['programme_type_applied_for'])."</td>";
				$output .= "<td>".get_school_title($row['school_applied_for'])."</td>";

				$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";
				$output .= "<td>".$row['phone_no']."</td>";
				$output .= "<td>".get_state_title($row['state_id'])."</td>";
				$output .= "<td>".get_lga_title($row['lga_id'])."</td>";
				$output .= "<td>".get_applicant_image($row['id'])."</td>";
				$output .= "<td>".get_user_qualified_status($row['id'])."</td>";
				$output .= "<td>".is_admitted($row['id'])."</td>";



				$output .= "</tr>";

			}else{
				//echo $output .= $row['id'].'ujhjhkj';

			}

		}
	}
	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 applicants listings per programmes
//function view applicants listings per programmes
function view_applicants_list_for_course_change($pt, $sess) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT  id, prog_applied_for_change, prog_change_status,
			application_number, first_name, other_names ,  DATE_FORMAT(prog_change_date, '%b %e, %Y /  %l:%i:%p') AS prog_change_date  FROM  applicants_nce

		  WHERE   programme_type_applied_for = '$pt' AND session = '$sess'

		  AND prog_applied_for_change > 0 AND prog_change_status = 0 ORDER BY prog_change_date ASC

		  ";
	$r = mysql_query($q);



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

			echo '<form method="POST" action="">
		 			<input type="hidden" name="app_id" value="'.$row['id'].'">
		 			<input type="hidden" name="prog_id" value="'.$row['prog_applied_for_change'].'">

		 			<input type="submit" name="change_all_btn" value="Approve All" class="btn btn-success pull-right">
		 		</form><br><br><br>';

		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
					<th>Application No.</th>
					<th>Fullname</th>
					<th>Applied For</th>
					<th>Applied Date</th>




			</thead>
			<tfoot>
					<th>Application No.</th>
					<th>Fullname</th>
					<th>Applied For</th>
					<th>Applied Date</th>


			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{

			//display applicant when has paid app fee
			if (applicant_has_paid_app_fees($row['id'])){

				$output .= "<tr>";
				$output .= "<td>".$row['application_number']."</td>";
				$output .= "<td> <a href='#' target='_new'>".$row['first_name'].' '.$row['other_names']."</a></td>";
				$output .= "<td>".get_programme_title($row['prog_applied_for_change'])."</td>";
				$output .= "<td>".$row['prog_change_date']."</td>";
				/* for single change
				$output .= '<td>

				 		<form method="POST" action="">
				 			<input type="hidden" name="app_id" value="'.$row['id'].'">
				 			<input type="hidden" name="prog_id" value="'.$row['prog_applied_for_change'].'">
				 			<input type="submit" name="change_btn" value="Approve" class="btn btn-success">
				 		</form>


					</td>';*/



				$output .= "</tr>";

			}else{
				//echo $output .= $row['id'].'ujhjhkj';

			}

		}
	}
	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 applicants listings per programme
function view_cleared_applicants_list($pt, $sess) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT  id, type_id, programme_id, application_number, first_name,
			other_names , batch, DATE_FORMAT(cleared_date, '%b %e, %Y /  %l:%i:%p') AS cleared_date  FROM  applicants_nce

		  WHERE   type_id = '$pt' AND session = '$sess'

		  AND cleared = '1' AND admission_status = '1' ORDER BY programme_id  ASC

		  ";
	$r = mysql_query($q);



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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
					<th>S/No</th>
					<th>Application No.</th>
					<th>Fullname</th>
					<th>Admitted Programme</th>
					<th>Batch</th>
					<th>Cleared Date</th>
					<th>Action</th>

			</thead>
			<tfoot>
			        <th>S/No</th>
					<th>Application No.</th>
					<th>Fullname</th>
					<th>Admitted Programme</th>
					<th>Batch</th>
					<th>Cleared Date</th>
					<th>Action</th>


			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{

			//display applicant when has paid app fee
			if (applicant_has_paid_app_fees($row['id'])){

				$snn += 1;
				$output .= "<tr>";

				$output .= "<td>".$snn."</td>";

				$output .= "<td>".$row['application_number']."</td>";
				$output .= "<td> <a href='#' >".$row['first_name'].' '.$row['other_names']."</a></td>";
				$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
				$output .= "<td>".$row['batch']."</td>";
				$output .= "<td>".$row['cleared_date']."</td>";

				// for single change
				$output .= '<td>

				 		<form method="POST" action="">

				 			<input type="hidden" name="app_id" value="'.$row['id'].'">';

				 		//get nce course
            			$prence_progs = get_valid_programme_nce($ptt=1);
            			$nce_progs = get_valid_programme_nce($ptt=2);

            			if ($pt == 2) {
				 				$output .= '

									<div class="bg-info">
										<div>
											<h5 class="text-center"><b> NCE To PRE-NCE </b></h5>
											<select class="form-control" name="swap_prog_id" >
								                <option value=""> Select Course </option>
								                '.

								                 //displaying the prence courses

								                list_course($prence_progs)

								                .'
								            </select>
								            <input type="submit" name="swap_prog_btn_nce" value="Convert Programme" class="btn btn-primary">
							            </div>
							            <br>
									</div>
									<br><br>

						 			';
						 	//NCE
				 		}elseif(get_applicant_swapped_prog_status($row['id']) == 1 && $pt == 1 ){
				 			//when prence

			 				$output .= '

								<div class="bg-info">
									<div>
										<h5 class="text-center"><b>PRE-NCE To NCE </b></h5>
										<select class="form-control" name="swap_prog_id" >
							                <option value=""> Select Course </option>
							                '.

							                 //displaying the prence courses

							                list_course($nce_progs)

							                .'
							            </select>
							            <input type="submit" name="swap_prog_btn" value="Convert Programme" class="btn btn-primary">
						            </div>
						            <br>
								</div>
								<br><br>

					 			';



				 		}



				 $output .= '<input type="submit" name="reject_btn" value="Reset" class="btn btn-warning">

				 			<input type="submit" name="revoke_btn" value="Revoke" class="btn btn-danger">
				 		</form>


					</td>';



				$output .= "</tr>";

			}else{
				//echo $output .= $row['id'].'ujhjhkj';

			}

		}
	}
	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 applicants listings per programmes
function view_rejected_applicants_list($pt, $sess) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT  id, application_number, first_name, programme_applied_for,
			other_names , batch, clear_reasons, phone_no,
			DATE_FORMAT(clr_modified_date, '%b %e, %Y /  %l:%i:%p') AS rejected_date  FROM  applicants_nce

		  WHERE   programme_type_applied_for  = '$pt' AND session = '$sess'
		  AND cleared = '0'  AND clear_reasons != ''  AND qualified = '1' AND clr_modified_date !=''
		  ORDER BY programme_applied_for  ASC

		  ";

		  //AND admission_status = '1' AND qualified = '1'
	$r = mysql_query($q);



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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
					<th>S/No</th>
					<th>Application No.</th>
					<th>Fullname</th>
					<th>Phone No.</th>
					<th>Applied Programme</th>
					<th>Batch</th>
					<th>Reason(s)</th>
					<th>Rejected Date</th>


			</thead>
			<tfoot>
			        <th>S/No</th>
					<th>Application No.</th>
					<th>Fullname</th>
					<th>Phone No.</th>
					<th>Applied Programme</th>
					<th>Batch</th>
					<th>Reason(s)</th>
					<th>Rejected Date</th>


			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{

			//display applicant when has paid app fee
			if (applicant_has_paid_app_fees($row['id'])){

				$snn += 1;
				$output .= "<tr>";

				$output .= "<td>".$snn."</td>";

				$output .= "<td>".$row['application_number']."</td>";
				$output .= "<td> <a href='#' >".$row['first_name'].' '.$row['other_names']."</a></td>";
				$output .= "<td>".$row['phone_no']."</td>";
				$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";
				$output .= "<td>".$row['batch']."</td>";
				$output .= "<td>".$row['clear_reasons']."</td>";
				$output .= "<td>".$row['rejected_date']."</td>";

				// for single change
				/*$output .= '<td>

				 		<form method="POST" action="">
				 			<input type="hidden" name="app_id" value="'.$row['id'].'">

				 			<input type="submit" name="reject_btn" value="Reset" class="btn btn-warning">

				 			<input type="submit" name="revoke_btn" value="Revoke" class="btn btn-danger">
				 		</form>


					</td>';*/



				$output .= "</tr>";

			}else{
				//echo $output .= $row['id'].'ujhjhkj';

			}

		}
	}
	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 applicants listings per programmes
//function view applicants listings per programmes
function change_applicant_course_all($pt, $sess) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT  id, prog_applied_for_change, prog_change_status,
			application_number, first_name, other_names ,  DATE_FORMAT(prog_change_date, '%b %e, %Y /  %l:%i:%p') AS prog_change_date  FROM  applicants_nce

		  WHERE   programme_type_applied_for = '$pt' AND session = '$sess'

		  AND prog_applied_for_change > 0 AND prog_change_status = 0 ORDER BY prog_change_date ASC

		  ";
	$r = mysql_query($q);



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



		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$q = 1;
			$chn_prg = $row['prog_applied_for_change'];
	        $sch_id =  get_school_id_by_programme($chn_prg);
	        $dept_id = get_department_id_by_programme($chn_prg);
			change_applicant_course($row['id'],$chn_prg,$dept_id,$sch_id,$sess,$q);

		}
		return true;
	}






}//end of view applicants listings per programmes

//get school id
function get_department_id_by_programme($id)
{
	$result = mysql_query("SELECT `department_id` FROM programmes WHERE id = $id");
		$row = mysql_fetch_assoc($result);
		$sch_id = $row['department_id'];

	return $sch_id ;
}

function change_applicant_course($id,$p,$dp,$sch,$ses,$q)
{


    $q = mysql_query("UPDATE applicants_nce SET programme_applied_for ='$p',
                     department_applied_for ='$dp', school_applied_for='$sch',
                     qualified = '$q', prog_change_status = 1
                     WHERE id='$id'") ;

     /* $sql = "UPDATE applicants_nce SET prog_applied_for_change ='$cs', prog_change_status = '0'
            WHERE id= '$user_id'";*/

     if ($q){

         	return true;
	     }

}
function change_applicant_course2($id,$p,$dp,$sch,$ses,$qu,$user)
{


    $q = mysql_query("UPDATE applicants_nce SET programme_applied_for ='$p',
                     department_applied_for ='$dp', school_applied_for='$sch',
                     qualified = '$qu', prog_change_status = '1',
                      clr_modified_by = '$user', clr_modified_date = NOW()
                     WHERE id='$id'") ;

    print_r($id);

        exit();
     /* $sql = "UPDATE applicants_nce SET prog_applied_for_change ='$cs', prog_change_status = '0'
            WHERE id= '$user_id'";*/

     if ($q){

         	return true;
	     }

}
function change_applicant_course3($id,$p,$dp,$sch,$ses,$qu,$user)
{

   $type_id = get_applicant_programme_type($id);

    $q = mysql_query("UPDATE applicants_nce SET
    				type_id = '$type_id', school_id = '$sch', department_id = '$dp',
					programme_id = '$p', programme_applied_for ='$p',
                     department_applied_for ='$dp', school_applied_for='$sch',
                     qualified = '$qu', prog_change_status = 1,
                      clr_modified_by = '$user', clr_modified_date = NOW(),
                      clr_changed_programme = '$p'
                     WHERE id='$id'") ;

     /* $sql = "UPDATE applicants_nce SET prog_applied_for_change ='$cs', prog_change_status = '0'
            WHERE id= '$user_id'";*/

     if ($q){

         	return true;
	     }

}


//function get total admitted applicants
function get_total_cleared_applicants_by_batch($pt,$sess, $batch)
{
	$q = "SELECT COUNT(id) FROM applicants_nce
		WHERE programme_type_applied_for ='$pt' AND admission_status = '1'
		AND cleared = '1'  AND session = '$sess' AND batch = '$batch'
	";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

function get_applicant_batch_no($pt,$sess)
{

	$batch = '';

	$first_batch = get_total_cleared_applicants_by_batch($pt, $sess, '1');
	$second_batch = get_total_cleared_applicants_by_batch($pt, $sess, '2');
	//count 2500 as First Batch
	if ($first_batch <= 2500) {
		//set batch 1
		$batch = 1;
	}else{

		if ($second_batch <= 2500) {
			//set batch 1
			$batch = 2;

		}else{
			//set batch 3

		}


	}

	return $batch;

}

function clear_applicant_nce_olevel($pt,$pid, $sess,$id,$msg,$stat, $user)
{

		$batch = get_applicant_batch_no($pt,$sess);
		//admit canditate
		$q = admit_applicant_nce($id,$pt,$pid,$msg,$stat,$user,$batch);
		/*$q = mysql_query("UPDATE applicants_nce SET cleared ='$stat',
		                     clear_reasons ='$msg', cleared_by = '$user',
		                     cleared_date = NOW()
		                     WHERE id='$id'") ;*/


	     /* $sql = "UPDATE applicants_nce SET prog_applied_for_change ='$cs', prog_change_status = '0'
	            WHERE id= '$user_id'";*/

    	if ($q){
        	return true;
	   }


}
function admit_applicant_nce($id,$pt,$pid,$msg,$stat,$user,$bt)
{
	$sch =  get_school_id_by_programme($pid);
   $dept = get_department_id_by_programme($pid);


    $q = mysql_query("UPDATE applicants_nce SET
    				type_id = '$pt', school_id = '$sch', department_id = '$dept',
					programme_id = '$pid', programme_applied_for ='$pid',
                    department_applied_for ='$dept', school_applied_for='$sch',
                    qualified = '1', admission_status = '1',
                    cleared ='$stat', clear_reasons ='$msg', cleared_by = '$user', cleared_date = NOW(), batch = '$bt'
                     WHERE id='$id'") ;

     /* $sql = "UPDATE applicants_nce SET prog_applied_for_change ='$cs', prog_change_status = '0'
            WHERE id= '$user_id'";*/

     if ($q){

         	return true;
	     }

}

function convert_applicant_nce_to_prence($pt,$s_id ,$sess,$id,$user)
{

	$sch =  get_school_id_by_programme($s_id);
   $dept = get_department_id_by_programme($s_id);
   $batch = get_applicant_batch_no($pt,$sess);


    $q = mysql_query("UPDATE applicants_nce SET
    				type_id = '$pt', cart_id = 1, school_id = '$sch', department_id = '$dept',
					programme_id = '$s_id', programme_type_applied_for ='$pt',
					programme_applied_for ='$s_id', department_applied_for ='$dept', school_applied_for='$sch', qualified = '1', admission_status = '1',
                    cleared ='1', clear_reasons ='Cleared', cleared_by = '$user',
                     cleared_date = NOW(), batch = '$batch',
                     swapped_prog_status ='1', swapped_prog_id = '$s_id'
                     WHERE id='$id'") ;

     /* $sql = "UPDATE applicants_nce SET prog_applied_for_change ='$cs', prog_change_status = '0'
            WHERE id= '$user_id'";*/

     if ($q){

         	return true;
	     }

}



function reject_applicant_nce_olevel($id,$msg,$stat, $user)
{
	//when rejected
	$q = mysql_query("UPDATE applicants_nce SET cleared ='$stat',
                 clear_reasons ='$msg', clr_modified_by = '$user',
                 clr_modified_date = NOW()
                 WHERE id='$id'") ;


     /* $sql = "UPDATE applicants_nce SET prog_applied_for_change ='$cs', prog_change_status = '0'
            WHERE id= '$user_id'";*/

	 if ($q){
	    	return true;
	   }


}

function revoke_applicant_admission($id,$msg,$stat, $user)
{

   		//when rejected
   	$q = mysql_query("UPDATE applicants_nce SET
   						type_id = '0',school_id = '0',department_id = '0',
   						programme_id = '0',admission_status ='0', batch = '0',
   						cleared ='$stat', clear_reasons ='$msg',
   						clr_modified_by = '$user', clr_modified_date = NOW()
	                    WHERE id='$id'") ;


     /* $sql = "UPDATE applicants_nce SET prog_applied_for_change ='$cs', prog_change_status = '0'
            WHERE id= '$user_id'";*/

     if ($q){
        	return true;
	   }


}

//function view applicants listings per programmes
function view_applicants_list_per_programmes_1($pt, $p, $sess) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT id, programme_type_applied_for, school_applied_for,department_applied_for, programme_applied_for, application_number,
		  state_id, lga_id, first_name, other_names, phone_no, gender,  email,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		  FROM  applicants_nce

		  WHERE   programme_type_applied_for = '$pt' AND programme_applied_for = '$p'
		  AND session = '$sess'

		  ORDER BY application_number ASC

		  ";
	$r = mysql_query($q);



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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>School Applied For</th>
						<th>Applied For</th>

						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Application Status</th>
						<th>Admission Status</th>



			</thead>
			<tfoot>

						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>School Applied For</th>

						<th>Applied For</th>
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Application Status</th>
						<th>Admission Status</th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{

			//display applicant when has paid app fee
			if (applicant_has_paid_app_fees($row['id'])){

				$output .= "<tr>";
				$output .= "<td>".$row['application_number']."</td>";
				$output .= "<td> <a href='#' target=''>".$row['first_name'].' '.$row['other_names']."</a></td>";
				$output .= "<td>".$row['gender']."</td>";
				$output .= "<td>".show_programme_type($row['programme_type_applied_for'])."</td>";
				$output .= "<td>".get_school_title($row['school_applied_for'])."</td>";

				$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";
				$output .= "<td>".$row['phone_no']."</td>";
				$output .= "<td>".get_state_title($row['state_id'])."</td>";
				$output .= "<td>".get_lga_title($row['lga_id'])."</td>";
				$output .= "<td>".get_applicant_image($row['id'])."</td>";
				$output .= "<td>".get_user_qualified_status($row['id'])."</td>";
				$output .= "<td>".is_admitted($row['id'])."</td>";



				$output .= "</tr>";

			}else{
				//echo $output .= $row['id'].'ujhjhkj';

			}

		}
	}
	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 applicants listings per programmes


//function view applicants listings per programmes
function view_applicants_list_per_programmes_deg_1($p, $sess) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT id, programme_type_applied_for, school_applied_for,department_applied_for, programme_applied_for, application_number,
		  state_id, lga_id, first_name, other_names, phone_no, gender,  email,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added
		  FROM  applicants_nce

		  WHERE  programme_applied_for = '$p'
		  AND session = '$sess'

		  ORDER BY application_number ASC

		  ";
	$r = mysql_query($q);



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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>School Applied For</th>
						<th>Applied For</th>

						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Application Status</th>
						<th>Admission Status</th>



			</thead>
			<tfoot>

						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>School Applied For</th>

						<th>Applied For</th>
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Application Status</th>
						<th>Admission Status</th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{

			//display applicant when has paid app fee
			if (applicant_has_paid_app_fees($row['id'])){

				$output .= "<tr>";
				$output .= "<td>".$row['application_number']."</td>";
				$output .= "<td> <a href='#' target=''>".$row['first_name'].' '.$row['other_names']."</a></td>";
				$output .= "<td>".$row['gender']."</td>";
				$output .= "<td>".show_programme_type($row['programme_type_applied_for'])."</td>";
				$output .= "<td>".get_school_title($row['school_applied_for'])."</td>";

				$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";
				$output .= "<td>".$row['phone_no']."</td>";
				$output .= "<td>".get_state_title($row['state_id'])."</td>";
				$output .= "<td>".get_lga_title($row['lga_id'])."</td>";
				$output .= "<td>".get_applicant_image($row['id'])."</td>";
				$output .= "<td>".get_user_qualified_status($row['id'])."</td>";
				$output .= "<td>".is_admitted($row['id'])."</td>";



				$output .= "</tr>";

			}else{
				//echo $output .= $row['id'].'ujhjhkj';

			}

		}
	}
	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 applicants listings per programmes

//function view applicants listings per programmes
function get_applicants_app_fees_paid_prence($pt, $sess) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT id, programme_type_applied_for, school_applied_for,department_applied_for, programme_applied_for, application_number,
		  state_id, lga_id, first_name, other_names, phone_no, gender,  email,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		  FROM  applicants_nce

		  WHERE   programme_type_applied_for = '$pt'
		  AND session = '$sess'

		  ORDER BY application_number ASC

		  ";
	$r = mysql_query($q);

	$jd_amt = 165;
	$output = '';
	if(mysql_num_rows($r) > 0)
	{


		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{

			//display applicant when has paid app fee
			if (applicant_has_paid_app_fees($row['id'])){

				$output .= "<tr>";
				$output .= "<td>".$row['application_number']."</td>";
				$output .= "<td> <a href='#' target=''>".$row['first_name'].' '.$row['other_names']."</a></td>";

				$output .= "<td>".show_programme_type($row['programme_type_applied_for'])."</td>";
				$output .= "<td>".get_school_title($row['school_applied_for'])."</td>";
				$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";

				$output .= "<td>N".number_format(get_applicant_paid_app_fees_amount($row['id']))."</td>";
				$output .= "<td>N".number_format($jd_amt)."</td>";




				$output .= "</tr>";

			}else{
				//echo $output .= $row['id'].'ujhjhkj';

			}

		}
	}
	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 applicants listings per programmes

//function view applicants listings per programmes
function get_applicants_app_fees_paid_nce($pt,$sess) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT id, programme_type_applied_for, school_applied_for,department_applied_for, programme_applied_for, application_number,
		  state_id, lga_id, first_name, other_names, phone_no, gender,  email,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		  FROM  applicants_nce

		  WHERE   programme_type_applied_for = '$pt'
		  AND session = '$sess'

		  ORDER BY application_number ASC

		  ";

	$r = mysql_query($q);

	$jd_amt = 165;
	$output = '';
	if(mysql_num_rows($r) > 0)
	{


		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{

			//display applicant when has paid app fee
			if (applicant_has_paid_app_fees($row['id'])){

				$output .= "<tr>";
				$output .= "<td>".$row['application_number']."</td>";
				$output .= "<td> <a href='#' target=''>".$row['first_name'].' '.$row['other_names']."</a></td>";

				$output .= "<td>".show_programme_type($row['programme_type_applied_for'])." (".	select_applicant_entry_mode(get_applicant_mode_of_entry($row['id']))." )</td>";
				$output .= "<td>".get_school_title($row['school_applied_for'])."</td>";
				$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";

				$output .= "<td>N".number_format(get_applicant_paid_app_fees_amount($row['id']))."</td>";
				$output .= "<td>N".number_format($jd_amt)."</td>";




				$output .= "</tr>";

			}else{
				//echo $output .= $row['id'].'ujhjhkj';

			}

		}
	}
	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 applicants listings per programmes



//function view applicants listings per programmes
function get_applicants_app_fees_paid_deg($sess) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT id, programme_type_applied_for, school_applied_for,department_applied_for, programme_applied_for, jamb_no,
		  state_id, lga_id, first_name, other_names, phone_no, gender,  email,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		  FROM  applicants_nce

		  WHERE  session = '$sess'

		  ORDER BY id ASC

		  ";

	$r = mysql_query($q);
	
	$jd_amt = 165;
	$output = '';
	if(mysql_num_rows($r) > 0)
	{


		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{

			//display applicant when has paid app fee
			if (applicant_has_paid_app_fees_deg($row['id'])){

				$output .= "<tr>";
				$output .= "<td>".$row['jamb_no']."</td>";
				$output .= "<td> <a href='#' target=''>".$row['first_name'].' '.$row['other_names']."</a></td>";

				$output .= "<td>".show_programme_type($row['programme_type_applied_for'])."</td>";
				$output .= "<td>".get_school_title($row['school_applied_for'])."</td>";
				$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";

				$output .= "<td>N".number_format(get_applicant_paid_app_fees_amount($row['id']))."</td>";
				$output .= "<td>N".number_format($jd_amt)."</td>";




				$output .= "</tr>";

			}else{
				//echo $output .= $row['id'].'ujhjhkj';

			}

		}
	}
	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 applicants listings per programmes

//function view applicants listings per programmes
function get_applicants_acc_fees_paid_deg($sess) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT id, programme_type_applied_for, school_applied_for,department_applied_for, programme_applied_for, jamb_no,
		  state_id, lga_id, first_name, other_names, phone_no, gender,  email,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		  FROM  applicants_nce

		  WHERE  session = '$sess'

		  ORDER BY id ASC

		  ";

	$r = mysql_query($q);
	
	$jd_amt = 165;
	$output = '';
	if(mysql_num_rows($r) > 0)
	{


		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{

			//display applicant when has paid app fee
			if (applicant_has_paid_acc_fees_deg($row['id'])){

				$output .= "<tr>";
				$output .= "<td>".$row['jamb_no']."</td>";
				$output .= "<td> <a href='#' target=''>".$row['first_name'].' '.$row['other_names']."</a></td>";

				$output .= "<td>".show_programme_type($row['programme_type_applied_for'])."</td>";
				$output .= "<td>".get_school_title($row['school_applied_for'])."</td>";
				$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";

				$output .= "<td>N".number_format(get_applicant_paid_acc_fees_amount($row['id']))."</td>";
				$output .= "<td>N".number_format($jd_amt)."</td>";




				$output .= "</tr>";

			}else{
				//echo $output .= $row['id'].'ujhjhkj';

			}

		}
	}
	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 applicants listings per programmes


function has_paid_school_fee($user_id,$session)
{
	$q = "SELECT student_id,session, payment_status
		  FROM school_fee_payments_nce
		  WHERE student_id = '$user_id'
		  AND session = '$session'
		  AND payment_status  = '1'";
	$r = mysql_query($q);

	//$row = mysql_fetch_assoc($result);

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

	}
	else
	{
		return true;
	}

}

function has_paid_school_fee_deg($user_id,$session)
{
	$q = "SELECT student_id,session, payment_status
		  FROM school_fee_payments_nce
		  WHERE student_id = '$user_id'
		  AND session = '$session'
		  AND payment_status  = '1'";
	$r = mysql_query($q);

	//$row = mysql_fetch_assoc($result);

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

	}
	else
	{
		return true;
	}

}


//has paid summer reg fee
function has_paid_school_fee_summer($user_id,$session)
{
	$q = "SELECT student_id,session, payment_status
		  FROM summer_school_fee_payments_nce
		  WHERE student_id = '$user_id'
		  AND session = '$session'";
	$r = mysql_query($q);

	//$row = mysql_fetch_assoc($result);

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

	}
	else
	{
		return true;
	}

}

//function get total student number for sch fees
function get_total_regular_nce_sf_payment($sess, $lev, $yr)
{
	//please remove applicant later

	//query the database
	$q = "SELECT COUNT(DISTINCT(std.id)) AS total_count FROM school_fee_payments_nce fees, students_nce std WHERE fees.session = '$sess' AND std.level = '$lev' AND std.id = fees.student_id AND std.entry_year = '$yr' AND fees.payment_status = 1 AND std.sponsorship_type < 4";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	$v = $row['total_count'];

			return $v;

}



//function get total student number for sch fees
function get_total_regular_nce_sf_payment_2($sess, $lev)
{
	//please remove applicant later

	//query the database
	$q = "SELECT COUNT(DISTINCT(std.id)) AS total_count FROM `school_fee_payments_nce` fees, students_nce std WHERE fees.session = '$sess' AND std.level = '$lev' AND std.id = fees.student_id AND fees.payment_status = 1 AND std.sponsorship_type < 4  ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	$v = $row['total_count'];

			return $v;

}

//function get total student number for sch fees
function get_total_deg_sf_payment_2($sess, $pt, $lev)
{
	//please remove applicant later

	//query the database
	$q = "SELECT COUNT(DISTINCT(std.id)) AS total_count FROM `school_fee_payments_nce` fees, students_nce std WHERE fees.session = '$sess' AND std.level = '$lev' AND std.id = fees.student_id AND fees.payment_status = 1 AND fees.programme_type_id = '$pt'  ";

	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	$v = $row['total_count'];

			return $v;

}
//function get total student number for sch fees
function get_total_others_nce_sf_payment($sess, $lev ,$spt)
{
	//please remove applicant later

	//query the database
	$q = "SELECT COUNT(DISTINCT(std.id)) AS total_count FROM `school_fee_payments_nce` fees, students_nce std WHERE fees.session = '$sess' AND std.level = '$lev' AND std.id = fees.student_id AND fees.payment_status = 1 AND std.sponsorship_type  = '$spt'  ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	$v = $row['total_count'];

			return $v;

}
//function get total student number for sch fees
function get_total_nce_sf_payment_by_level($sess, $lev )
{
	//please remove applicant later

	//query the database
	$q = "SELECT COUNT(DISTINCT(std.id)) AS total_count FROM `school_fee_payments_nce` fees, students_nce std WHERE fees.session = '$sess' AND std.level = '$lev' AND std.id = fees.student_id AND fees.payment_status = 1   ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	$v = $row['total_count'];

			return $v;

}


//for school fee nce
function get_sch_fees_paid_nce($pt, $sess, $lev) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT std.id, std.type_id, std.programme_id, std.`number`, std.level, std.first_name, std.other_names, DATE_FORMAT(std.date_added, '%M %d, %Y %l:%i:%p'), sf_pay.payment_status, sf_pay.amount
		  FROM  students_nce std, school_fee_payments_nce sf_pay

		  WHERE   sf_pay.programme_type_id = '$pt'  AND sf_pay.session = '$sess' AND std.id = sf_pay.student_id AND std.level = '$lev'

		  ORDER BY `number` ASC

		  ";
	$r = mysql_query($q);

	$jd_amt = 165;
	$output = '';
	if(mysql_num_rows($r) > 0)
	{


		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$amt = $row['amount'];
			$sumed_amt += $amt;
			//display applicant when has paid app fee
			if (has_paid_school_fee($row['id'],$sess)){

				$fullname= $row['first_name'].' '.$row['other_names'];

				$output .= "<tr>";
				$output .= "<td>".$row['number']."</td>";
				$output .= "<td> <a href='#' target=''>".strtoupper($fullname)."</a></td>";

				$output .= "<td>".show_programme_type($row['type_id'])."</td>";
				$output .= "<td>".$row['level']."</td>";
				$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
				$output .= "<td>N".$amt."</td>";
				$output .= "<td>".get_payment_status($row['payment_status'])."</td>";




				$output .= "</tr>";

			}else{
				//echo $output .= $row['id'].'ujhjhkj';

			}
		}
			//additional row for summing
			if ($output !== '') {
		    	$output .= "<tr>";
				$output .= "<td>XXXXXXXX</td>";
				$output .= "<td>XXXXXXXX</td>";
				$output .= "<td>XXXXXXXX</td>";
				$output .= "<td>XXXXXXXX</td>";
				$output .= "<td><b>NCE Total</b></td>";

				$output .= "<b><td><b>N".number_format($sumed_amt)."</b></td>";
				//$output .= "<td><b>N".number_format($nce_jdlab_sum)."</b></td></tr>";
				$output .= "<td>XXXXXXXX</td>";
		    }


	}
	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



//get students paids summer list
function get_sch_fees_paid_nce_summer($pt, $sess, $lev) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT std.id, std.type_id, std.programme_id, std.`number`, std.level, std.first_name, std.other_names, DATE_FORMAT(std.date_added, '%M %d, %Y %l:%i:%p'), sf_pay.payment_status, sf_pay.amount
		  FROM  applicants_nce std, summer_school_fee_payments_nce sf_pay

		  WHERE    sf_pay.session = '5' AND std.id = sf_pay.student_id

		  ORDER BY `number` ASC";
	$r = mysql_query($q);

	$jd_amt = 165;
	$output = '';
	if(mysql_num_rows($r) > 0)
	{


		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$amt = $row['amount'];
			$sumed_amt += $amt;
			//display applicant when has paid app fee
			if (has_paid_school_fee_summer($row['id'],$sess)){

				$fullname= $row['first_name'].' '.$row['other_names'];

				$output .= "<tr>";
				$output .= "<td>".$row['number']."</td>";
				$output .= "<td> <a href='#' target=''>".strtoupper($fullname)."</a></td>";

				$output .= "<td>".show_programme_type($row['type_id'])."</td>";
				//$output .= "<td>".$row['level']."</td>";
				$output .= "<td>SUMMER</td>";
				$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
				$output .= "<td>N".$amt."</td>";
				$output .= "<td>".get_payment_status($row['payment_status'])."</td>";




				$output .= "</tr>";

			}else{
				//echo $output .= $row['id'].'ujhjhkj';

			}
		}
			//additional row for summing
			if ($output !== '') {
		    	$output .= "<tr>";
				$output .= "<td>XXXXXXXX</td>";
				$output .= "<td>XXXXXXXX</td>";
				$output .= "<td>XXXXXXXX</td>";
				$output .= "<td>XXXXXXXX</td>";
				$output .= "<td><b>SUMMER NCE Total</b></td>";

				$output .= "<b><td><b>N".number_format($sumed_amt)."</b></td>";
				//$output .= "<td><b>N".number_format($nce_jdlab_sum)."</b></td></tr>";
				$output .= "<td>XXXXXXXX</td>";
		    }


	}
	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


//function view applicants listings per programmes
function get_sch_fees_paid_deg($sess) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT std.id, std.type_id, std.programme_id, std.`number`, std.level, std.first_name, std.other_names, DATE_FORMAT(std.date_added, '%M %d, %Y %l:%i:%p'), sf_pay.payment_status, sf_pay.amount
		  FROM  students_nce std, school_fee_payments_nce sf_pay

		  WHERE   sf_pay.session = '$sess' AND std.id = sf_pay.student_id

		  ORDER BY `number` ASC

		  ";
	$r = mysql_query($q);

	$jd_amt = 165;
	$output = '';

	if(mysql_num_rows($r) > 0)
	{


		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$amt = $row['amount'] ;
			$amtx = number_format($amt,2);
			$sumed_amt += $amt;
			//display applicant when has paid app fee
			if (has_paid_school_fee_deg($row['id'],$sess)){
				$mat_no = strtoupper($row['number']);

				$fullname= $row['first_name'].' '.$row['other_names'];

				$output .= "<tr>";
				$output .= "<td>".$mat_no."</td>";
				$output .= "<td> <a href='#' target=''>".strtoupper($fullname)."</a></td>";

				$output .= "<td>".show_programme_type($row['type_id'])."</td>";
				$output .= "<td>".$row['level']."</td>";
				$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
				$output .= "<td>N".$amtx."</td>";
				$output .= "<td>".get_payment_status($row['payment_status'])."</td>";




				$output .= "</tr>";

			}else{
				//echo $output .= $row['id'].'ujhjhkj';

			}
		}
			//additional row for summing
			if ($output !== '') {
		    	$output .= "<tr>";
				$output .= "<td>XXXXXXXX</td>";
				$output .= "<td>XXXXXXXX</td>";
				$output .= "<td>XXXXXXXX</td>";
				$output .= "<td>XXXXXXXX</td>";
				$output .= "<td><b>DUAP Total</b></td>";

				$output .= "<b><td><b>N".number_format($sumed_amt,2)."</b></td>";
				//$output .= "<td><b>N".number_format($nce_jdlab_sum)."</b></td></tr>";
				$output .= "<td>XXXXXXXX</td>";
		    }


	}
	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 applicants listings per programmes

//function view applicants listings per programmes
function get_applicants_app_fees_paid_nce_lvsp($pt, $md) // sess is 0 for now// pt programm type
{
	//please remove applicant later

	//query the database
	$q = "SELECT id, programme_type_applied_for, school_applied_for,department_applied_for, programme_applied_for, application_number,
		  state_id, lga_id, first_name, other_names, phone_no, gender,  email,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		  FROM  applicants_nce

		  WHERE   programme_type_applied_for = '2'
		   AND cart_id = '$md' AND session = '0'

		  ORDER BY application_number ASC";
	$r = mysql_query($q);

	$jd_amt = 165;
	$output = '';

	if(mysql_num_rows($r) > 0)
	{


		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{

			//display applicant when has paid app fee
			if (applicant_has_paid_app_fees($row['id'])){

				$output .= "<tr>";
				$output .= "<td>".$row['application_number']."</td>";
				$output .= "<td> <a href='#' target=''>".$row['first_name'].' '.$row['other_names']."</a></td>";

				$output .= "<td>".show_programme_type($row['programme_type_applied_for'])." (LVSP)</td>";
				$output .= "<td>".get_school_title($row['school_applied_for'])."</td>";
				$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";

				$output .= "<td>N".number_format(get_applicant_paid_app_fees_amount($row['id']))."</td>";
				$output .= "<td>N".number_format($jd_amt)."</td>";




				$output .= "</tr>";

			}else{
				//echo $output .= $row['id'].'ujhjhkj';

			}

		}
	}
	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 applicants listings per programmes


//function view applicants listings per programmes
function view_applicants_fin_summary($prence_dt, $nce_dt, $nce_lvsp_dt)
{
		//get all money including jdlab share
		$prence_sum = get_total_amount_paid_applicants_prence($prence_dt[0], $prence_dt[1], $prence_dt[2]);
		$prence_jdlab_sum = get_total_amount_paid_applicants_prence_jdlab($prence_dt[0], $prence_dt[1], $prence_dt[2]);

		$nce_sum = get_total_amount_paid_applicants_nce($nce_dt[0], $nce_dt[1]);
		$nce_jdlab_sum = get_total_amount_paid_applicants_nce_jdlab($nce_dt[0], $nce_dt[1]);

		$nce_lvsp_sum = get_total_amount_paid_applicants_nce_lvsp($nce_lvsp_dt[0], $nce_lvsp_dt[1],$nce_lvsp_dt[2]);
		$nce_lvsp_jdlab_sum = get_total_amount_paid_applicants_nce_lvsp_jdlab($nce_lvsp_dt[0], $nce_lvsp_dt[1],$nce_lvsp_dt[2]);

		$jdlab_total = $prence_jdlab_sum + $nce_jdlab_sum + $nce_lvsp_jdlab_sum;

		$type_sum = $prence_sum + $nce_sum + $nce_lvsp_sum;

		$all_sum = $type_sum + $jdlab_total;


		// if($prence_sum != '' &&  $nce_sum != ''  && $nce_lvsp_sum != '')
		// {//show table



			  $output =
			  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
				<thead>
					<th>Session</th>
					<th>PRE-NCE</th>
					<th>NCE</th>
					<th>NCE-LVSP</th>
					<th>DEGREE</th>
					<th>JDLAB</th>
					<th>TOTAL</th>
					<th>GRAND-TOTAL</th>

				</thead>
				<tfoot>
					<th>Session</th>
					<th>PRE-NCE</th>
					<th>NCE</th>
					<th>NCE-LVSP</th>
					<th>DEGREE</th>
					<th>JDLAB</th>
					<th>TOTAL</th>
					<th>GRAND-TOTAL</th>

				</tfoot>

				<tbody>';





				$output .= "<tr>";

					$output .= "<td>".get_session_title(get_current_session_4(4))."</td>";
					$output .= "<td>N".number_format($prence_sum)."</td>";
					$output .= "<td>N".number_format($nce_sum)."</td>";
					$output .= "<td>N".number_format($nce_lvsp_sum)."</td>";
					$output .= "<td>N".number_format(0)."</td>";
					$output .= "<td>N".number_format($jdlab_total)."</td>";
					$output .= "<td>N".number_format($type_sum)."</td>";
					$output .= "<td>N".number_format($all_sum)."</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 applicants listings per programmes

//function view applicants listings per programmes
function view_applicants_fin_summary_1($prence_dt, $nce_dt, $nce_lvsp_dt)
{
		//get all money including jdlab share
		$prence_sum = get_total_amount_paid_applicants_prence($prence_dt[0], $prence_dt[1], $prence_dt[2]);
		$prence_jdlab_sum = get_total_amount_paid_applicants_prence_jdlab($prence_dt[0], $prence_dt[1], $prence_dt[2]);

		$nce_sum = get_total_amount_paid_applicants_nce($nce_dt[0], $nce_dt[1]);
		$nce_jdlab_sum = get_total_amount_paid_applicants_nce_jdlab($nce_dt[0], $nce_dt[1]);

		$nce_lvsp_sum = get_total_amount_paid_applicants_nce_lvsp($nce_lvsp_dt[0], $nce_lvsp_dt[1],$nce_lvsp_dt[2]);
		$nce_lvsp_jdlab_sum = get_total_amount_paid_applicants_nce_lvsp_jdlab($nce_lvsp_dt[0], $nce_lvsp_dt[1],$nce_lvsp_dt[2]);

		$jdlab_total = $prence_jdlab_sum + $nce_jdlab_sum + $nce_lvsp_jdlab_sum;

		$type_sum = $prence_sum + $nce_sum + $nce_lvsp_sum;

		$all_sum = $type_sum + $jdlab_total;


		// if($prence_sum != '' &&  $nce_sum != ''  && $nce_lvsp_sum != '')
		// {//show table
		$output = '';
		$pre_output = '';
		$nce_output = '';
		$all_output1 = '';



			  $output =
			  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
				<thead>
					<th>Application No.</th>
					<th>Name</th>
					<th>Programme Type</th>
					<th>School Applied For</th>
					<th>Applied For</th>
					<th>Amount</th>
					<th>JDLAB</th>

				</thead>
				<tfoot>



				</tfoot>

				<tbody>';


				//for prence records
				$pre_output .= get_applicants_app_fees_paid_prence($prence_dt[1], $prence_dt[2]);
				//additional row for summing
				if ($pre_output !== '') {
			    	$pre_output1 .= "<tr>";
					$pre_output1 .= "<td>XXXXXXXX</td>";
					$pre_output1 .= "<td>XXXXXXXX</td>";
					$pre_output1 .= "<td>XXXXXXXX</td>";
					$pre_output1 .= "<td>XXXXXXXX</td>";
					$pre_output1 .= "<td><b>PRE-NCE Total</b></td>";

					$pre_output1 .= "<td width='100px'><b>N".number_format($prence_sum)."</b></td>";
					$pre_output1 .= "<td width='100px'><b>N".number_format($prence_jdlab_sum)."</b></td></tr>";
			    }

			    //for nce records
			    $nce_output .= get_applicants_app_fees_paid_nce($nce_dt[0], $nce_dt[1]);
					//additional row for summing
				if ($nce_output !== '') {
			    	$nce_output1 .= "<tr>";
					$nce_output1 .= "<td>XXXXXXXX</td>";
					$nce_output1 .= "<td>XXXXXXXX</td>";
					$nce_output1 .= "<td>XXXXXXXX</td>";
					$nce_output1 .= "<td>XXXXXXXX</td>";
					$nce_output1 .= "<td><b>NCE Total</b></td>";

					$nce_output1 .= "<b><td><b>N".number_format($nce_sum)."</b></td>";
					$nce_output1 .= "<td><b>N".number_format($nce_jdlab_sum)."</b></td></tr>";
			    }

			    //for nce_lvsp records
			    $lvsp_output .= get_applicants_app_fees_paid_nce_lvsp($nce_lvsp_dt[0], $nce_lvsp_dt[1], $nce_lvsp_dt[2] );
					//additional row for summing
				if ($lvsp_output !== '') {
			    	$lvsp_output1 .= "<tr>";
					$lvsp_output1 .= "<td>XXXXXXXX</td>";
					$lvsp_output1 .= "<td>XXXXXXXX</td>";
					$lvsp_output1 .= "<td>XXXXXXXX</td>";
					$lvsp_output1 .= "<td>XXXXXXXX</td>";
					$lvsp_output1 .= "<td><b>NCE-LVSP Total</b></td>";

					$lvsp_output1 .= "<b><td ><b>N".number_format($nce_lvsp_sum)."</b></td>";
					$lvsp_output1 .= "<td><b>N".number_format($nce_lvsp_jdlab_sum)."</b></td></tr>";
			    }

			    //additional row for summing grand total
				if ($all_sum !== '' ) {
			    	$all_output1 .= "<tr>";
					$all_output1 .= "<td>XXXXXXXX</td>";
					$all_output1 .= "<td>XXXXXXXX</td>";
					$all_output1 .= "<td>XXXXXXXX</td>";
					$all_output1 .= "<td>XXXXXXXX</td>";
					$all_output1 .= "<td><b>Grand Total</b></td>";

					$all_output1 .= "<b><td ><b>N".number_format($all_sum)."</b></td>";
					$all_output1 .= "<td><b>N".number_format($jdlab_total)."</b></td></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_last .=
		'</tbody>
	    </table>';





		return $output.
				$pre_output.$pre_output1.

				$nce_output.$nce_output1.

				$lvsp_output.$lvsp_output1.

				$all_output1.

				$output_last;




}//end of view applicants listings per programmes



//function view applicants listings per programmes
function view_applicants_fin_summary_2($sess)
{
		
		$deg_sum = get_total_amount_paid_applicants_deg($sess);
		$deg_jdlab_sum = get_total_amount_paid_applicants_deg_jdlab($sess);
	
		$type_sum = $deg_sum ;
		$jdlab_total = $deg_jdlab_sum;
		$all_sum = $type_sum + $deg_jdlab_sum;


		// if($prence_sum != '' &&  $nce_sum != ''  && $nce_lvsp_sum != '')
		// {//show table
		$output = '';
		
		$deg_output = '';
		$all_output1 = '';



			  $output =
			  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
				<thead>
					<th>JAMB No.</th>
					<th>Name</th>
					<th>Programme Type</th>
					<th>School Applied For</th>
					<th>Applied For</th>
					<th>Amount</th>
					<th>JDLAB</th>

				</thead>
				<tfoot>



				</tfoot>

				<tbody>';



			    //for nce records
			    $deg_output .= get_applicants_app_fees_paid_deg($sess);
			   
					//additional row for summing
				if ($deg_output !== '') {
			    	$deg_output1 .= "<tr>";
					$deg_output1 .= "<td>XXXXXXXX</td>";
					$deg_output1 .= "<td>XXXXXXXX</td>";
					$deg_output1 .= "<td>XXXXXXXX</td>";
					$deg_output1 .= "<td>XXXXXXXX</td>";
					$deg_output1 .= "<td><b>DUAP Total</b></td>";

					$deg_output1 .= "<b><td><b>N".number_format($deg_sum)."</b></td>";
					$deg_output1 .= "<td><b>N".number_format($deg_jdlab_sum)."</b></td></tr>";
			    }

			   
			    //additional row for summing grand total
				if ($all_sum !== '' ) {
			    	$all_output1 .= "<tr>";
					$all_output1 .= "<td>XXXXXXXX</td>";
					$all_output1 .= "<td>XXXXXXXX</td>";
					$all_output1 .= "<td>XXXXXXXX</td>";
					$all_output1 .= "<td>XXXXXXXX</td>";
					$all_output1 .= "<td><b>Grand Total</b></td>";

					$all_output1 .= "<b><td ><b>N".number_format($all_sum)."</b></td>";
					$all_output1 .= "<td><b>N".number_format($jdlab_total)."</b></td></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_last .=
		'</tbody>
	    </table>';





		return $output.
				$deg_output.$deg_output1.

				$all_output1.

				$output_last;




}//end of view applicants listings per programmes



//function view applicants listings per programmes
function view_acc_fee_fin_summary_2($sess)
{
		
		$deg_sum = get_total_amount_paid_acc_fee_deg($sess);
		$deg_jdlab_sum = get_total_amount_paid_acc_fee_deg_jdlab($sess);
	
		$type_sum = $deg_sum ;
		$jdlab_total = $deg_jdlab_sum;
		$all_sum = $type_sum + $deg_jdlab_sum;


		// if($prence_sum != '' &&  $nce_sum != ''  && $nce_lvsp_sum != '')
		// {//show table
		$output = '';
		
		$deg_output = '';
		$all_output1 = '';



			  $output =
			  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
				<thead>
					<th>JAMB No.</th>
					<th>Name</th>
					<th>Programme Type</th>
					<th>School Applied For</th>
					<th>Applied For</th>
					<th>Amount</th>
					<th>JDLAB</th>

				</thead>
				<tfoot>



				</tfoot>

				<tbody>';



			    //for nce records
			    $deg_output .= get_applicants_acc_fees_paid_deg($sess);
			   
					//additional row for summing
				if ($deg_output !== '') {
			    	$deg_output1 .= "<tr>";
					$deg_output1 .= "<td>XXXXXXXX</td>";
					$deg_output1 .= "<td>XXXXXXXX</td>";
					$deg_output1 .= "<td>XXXXXXXX</td>";
					$deg_output1 .= "<td>XXXXXXXX</td>";
					$deg_output1 .= "<td><b>DUAP Total</b></td>";

					$deg_output1 .= "<b><td><b>N".number_format($deg_sum)."</b></td>";
					$deg_output1 .= "<td><b>N".number_format($deg_jdlab_sum)."</b></td></tr>";
			    }

			   
			    //additional row for summing grand total
				if ($all_sum !== '' ) {
			    	$all_output1 .= "<tr>";
					$all_output1 .= "<td>XXXXXXXX</td>";
					$all_output1 .= "<td>XXXXXXXX</td>";
					$all_output1 .= "<td>XXXXXXXX</td>";
					$all_output1 .= "<td>XXXXXXXX</td>";
					$all_output1 .= "<td><b>Grand Total</b></td>";

					$all_output1 .= "<b><td ><b>N".number_format($all_sum)."</b></td>";
					$all_output1 .= "<td><b>N".number_format($jdlab_total)."</b></td></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_last .=
		'</tbody>
	    </table>';





		return $output.
				$deg_output.$deg_output1.

				$all_output1.

				$output_last;




}//end of view applicants listings per programmes



//function view students prence
function view_students_summary_prence($pt,$ses,$lev) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT id, type_id, school_id,department_id, programme_id, application_number,number,
		  state_id, lga_id, first_name, middle_name,other_names, phone_no, gender,  email,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added

		  FROM  students_prence

		  WHERE   type_id = '$pt' AND level = '$lev'

		  ORDER BY number ASC";
	$r = mysql_query($q);

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



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


						<th>Matric No.</th>
						<th>F. Name</th>
						<th>M. Name</th>
						<th>Other Names</th>
						<th>Gender</th>
						<th>Prog. Type</th>
						<!-- <th>School </th> -->
						<th>Programme</th>

						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>

						<th>App No.</th>
							<th>Actions</th>
						<th>Payment Status</th>
						<th>Photo</th>




			</thead>
			<tfoot>

						<th>Matric No.</th>

						<th>F. Name</th>
						<th>M. Name</th>
						<th>Other Names</th>

						<th>Gender</th>
						<th>Prog. Type</th>
						<!--<th>School </th> -->
						<th>Programme</th>

						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>

						<th>App No.</th>
							<th>Actions</th>
						<th>Payment Status </th>
							<th>Photo</th>



			</tfoot>

			<tbody>';

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


			$output .= "<td>".$row['number']."</td>";
			/*$output .= "<td> <a href='gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$row['id']."' target='_new'>".$row['first_name'].' '.$row['other_names']."</a></td>";*/
			$output .= "<td class='xeditfname' id='".$row['id']."' key='first_name'> ".$row['first_name']."</td>";
			$output .= "<td class='xeditmname' id='".$row['id']."' key='middle_name'> ".$row['middle_name']."</td>";
			$output .= "<td class='xeditoname' id='".$row['id']."' key='other_names'>".$row['other_names']."</td>";
			$output .= "<td>".$row['gender']."</td>";
			$output .= "<td>".show_programme_type($row['type_id'])."</td>";
			//$output .= "<td>".get_school_title($row['school_id'])."</td>";

			$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
			$output .= "<td>".$row['phone_no']."</td>";
			$output .= "<td>".get_state_title($row['state_id'])."</td>";
			$output .= "<td>".get_lga_title($row['lga_id'])."</td>";

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

			$output .= '<td><a  class="btn btn-sm btn-info reset_pw" id="'.$row['id'].'">  RESET PASSWORD </a> <span id="loading"></span> </td>';



			if( has_paid_school_fee($row['id'],$ses))
			{
				$output .= "<td> <label class='label label-success'> PAID </label> </td>";
			}
			else
			{
				$output .= "<td> <label class='label label-danger'> NOT PAID </label> </td>";
			}


			$output .= "<td>".get_student_image($row['id'], $row['type_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;





}//end of view students all list prence

//function view students listings per programmes
function view_students_summary_nce($pt,$ses,$lev) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT id, type_id, school_id,department_id, programme_id, application_number,number,
		  state_id, lga_id, first_name, middle_name,other_names, phone_no, gender,  email,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added

		  FROM  students_nce

		  WHERE   type_id = '$pt' AND level = '$lev'

		  ORDER BY number ASC";
	$r = mysql_query($q);

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



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


						<th>Matric No.</th>
						<th>F. Name</th>
						<th>M. Name</th>
						<th>Other Names</th>
						<th>Gender</th>
						<!-- <th>Prog. Type</th> -->
						<!-- <th>School </th> -->
						<th>Programme</th>

						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>

						<th>App No.</th>
							<th>Actions</th>
						<th>Payment Status</th>
						<th>Photo</th>




			</thead>
			<tfoot>

						<th>Matric No.</th>

						<th>F. Name</th>
						<th>M. Name</th>
						<th>Other Names</th>

						<th>Gender</th>
						<!-- <th>Prog. Type</th> -->
						<!--<th>School </th> -->
						<th>Programme</th>

						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>

						<th>App No.</th>
							<th>Actions</th>
						<th>Payment Status </th>
							<th>Photo</th>



			</tfoot>

			<tbody>';

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


			$output .= "<td>".$row['number']."</td>";
			/*$output .= "<td> <a href='gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$row['id']."' target='_new'>".$row['first_name'].' '.$row['other_names']."</a></td>";*/
			$output .= "<td class='xeditfname' id='".$row['id']."' key='first_name'> ".$row['first_name']."</td>";
			$output .= "<td class='xeditmname' id='".$row['id']."' key='middle_name'> ".$row['middle_name']."</td>";
			$output .= "<td class='xeditoname' id='".$row['id']."' key='other_names'>".$row['other_names']."</td>";
			$output .= "<td>".$row['gender']."</td>";
			//$output .= "<td>".show_programme_type($row['type_id'])."</td>";
			//$output .= "<td>".get_school_title($row['school_id'])."</td>";

			$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
			$output .= "<td>".$row['phone_no']."</td>";
			$output .= "<td>".get_state_title($row['state_id'])."</td>";
			$output .= "<td>".get_lga_title($row['lga_id'])."</td>";

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

			$output .= '<td><a  class="btn btn-sm btn-info reset_pw" id="'.$row['id'].'">  RESET PASSWORD </a> <span id="loading"></span> </td>';



			if( has_paid_school_fee($row['id'],$ses))
			{
				$output .= "<td> <label class='label label-success'> PAID </label> </td>";
			}
			else
			{
				$output .= "<td> <label class='label label-danger'> NOT PAID </label> </td>";
			}


			$output .= "<td>".get_student_image($row['id'], $row['type_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;

}//end of view students ants listings per programmes




//function view students listings per programmes
function view_students_summary_deg($ses,$lev) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT id, type_id, school_id,department_id, programme_id, application_number,number,
		  state_id, lga_id, first_name, middle_name,other_names, phone_no, gender,  email,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added

		  FROM  students_nce

		  WHERE    level = '$lev'

		  ORDER BY number ASC";
	$r = mysql_query($q);

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



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


						<th>Matric No.</th>
						<th>F. Name</th>
						<th>M. Name</th>
						<th>Other Names</th>
						<th>Gender</th>
						<!-- <th>Prog. Type</th> -->
						<!-- <th>School </th> -->
						<th>Programme</th>

						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>

						<th>App No.</th>
							<th>Actions</th>
						<th>Payment Status</th>
						<th>Photo</th>




			</thead>
			<tfoot>

						<th>Matric No.</th>

						<th>F. Name</th>
						<th>M. Name</th>
						<th>Other Names</th>

						<th>Gender</th>
						<!-- <th>Prog. Type</th> -->
						<!--<th>School </th> -->
						<th>Programme</th>

						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>

						<th>App No.</th>
							<th>Actions</th>
						<th>Payment Status </th>
							<th>Photo</th>



			</tfoot>

			<tbody>';

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


			$output .= "<td>".$row['number']."</td>";
			/*$output .= "<td> <a href='gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$row['id']."' target='_new'>".$row['first_name'].' '.$row['other_names']."</a></td>";*/
			$output .= "<td class='xeditfname' id='".$row['id']."' key='first_name'> ".$row['first_name']."</td>";
			$output .= "<td class='xeditmname' id='".$row['id']."' key='middle_name'> ".$row['middle_name']."</td>";
			$output .= "<td class='xeditoname' id='".$row['id']."' key='other_names'>".$row['other_names']."</td>";
			$output .= "<td>".$row['gender']."</td>";
			//$output .= "<td>".show_programme_type($row['type_id'])."</td>";
			//$output .= "<td>".get_school_title($row['school_id'])."</td>";

			$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
			$output .= "<td>".$row['phone_no']."</td>";
			$output .= "<td>".get_state_title($row['state_id'])."</td>";
			$output .= "<td>".get_lga_title($row['lga_id'])."</td>";

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

			$output .= '<td><a  class="btn btn-sm btn-info reset_pw" id="'.$row['id'].'">  RESET PASSWORD </a> <span id="loading"></span> </td>';



			if( has_paid_school_fee($row['id'],$ses))
			{
				$output .= "<td> <label class='label label-success'> PAID </label> </td>";
			}
			else
			{
				$output .= "<td> <label class='label label-danger'> NOT PAID </label> </td>";
			}


			$output .= "<td>".get_student_image($row['id'], $row['type_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;

}//end of view students ants listings per programmes



//function view applicants listings per programmes
function view_students_fin_summary_nce($pt,$ses,$lev)
{


		$output = '';
		$pre_output = '';
		$nce_output = '';
		$all_output1 = '';



			  $output =
			  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
				<thead>
					<th>Matric No.</th>
					<th>Name</th>
					<th>Programme Type</th>
					<th>Level</th>
					<th>Applied For</th>
					<th>Amount</th>
					<th>Payment Status</th>

				</thead>
				<tfoot>



				</tfoot>

				<tbody>';


			    //for nce records
			    $nce_output .= get_sch_fees_paid_nce($pt, $ses, $lev);






		/*	}
		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_last .=
		'</tbody>
	    </table>';





		return $output.
				$pre_output.$pre_output1.

				$nce_output.$nce_output1.

				$lvsp_output.$lvsp_output1.

				$all_output1.

				$output_last;




}//end of view applicants listings per programmes


	//function view applicants listings per programmes
function view_students_fin_summary_deg($ses)
{

		$output = '';
		$pre_output = '';
		$nce_output = '';
		$all_output1 = '';



			  $output =
			  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
				<thead>
					<th>Matric No.</th>
					<th>Name</th>
					<th>Programme Type</th>
					<th>Level</th>
					<th>Applied For</th>
					<th>Amount</th>
					<th>Payment Status</th>

				</thead>
				<tfoot>



				</tfoot>

				<tbody>';


			    //for nce records
			    $nce_output .= get_sch_fees_paid_deg($ses);






		/*	}
		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_last .=
		'</tbody>
	    </table>';





		return $output.
				$pre_output.$pre_output1.

				$nce_output.$nce_output1.

				$lvsp_output.$lvsp_output1.

				$all_output1.

				$output_last;




}//end of view applicants listings per programmes


//function view applicants listings per programmes
function view_students_fin_summary_nce_summer($pt,$ses,$lev)
{


		$output = '';
		$pre_output = '';
		$nce_output = '';
		$all_output1 = '';



			  $output =
			  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
				<thead>
					<th>Matric No.</th>
					<th>Name</th>
					<th>Programme Type</th>
					<th>Level</th>
					<th>Applied For</th>
					<th>Amount</th>
					<th>Payment Status</th>

				</thead>
				<tfoot>



				</tfoot>

				<tbody>';


			    //for nce records
			    $nce_output .= get_sch_fees_paid_nce_summer($pt, $ses, $lev);






		/*	}
		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_last .=
		'</tbody>
	    </table>';





		return $output.
				$pre_output.$pre_output1.

				$nce_output.$nce_output1.

				$lvsp_output.$lvsp_output1.

				$all_output1.

				$output_last;




}//end of view applicants listings per programmes


//check applicant that has paid app fees
function applicant_has_paid_app_fees_deg($id)
{
	//query the database
		$q = "SELECT applicant_id FROM applicants_nce_fee_payments
			WHERE  applicant_id = '$id'";
	   $r= mysql_query($q);

		if(mysql_num_rows($r) > 0){
			return true;
		}
}

//check applicant that has paid app fees
function applicant_has_paid_acc_fees_deg($id)
{
	//query the database
		$q = "SELECT applicant_id FROM acceptance_nce_fee_payments
			WHERE  applicant_id = '$id'";
	   $r= mysql_query($q);

		if(mysql_num_rows($r) > 0){
			return true;
		}
}
//check applicant that has paid app fees
function get_applicant_paid_app_fees_amount($id)
{
	//query the database
		$q = "SELECT (amount-165) AS amt FROM applicants_nce_fee_payments
			WHERE  applicant_id = '$id'";
	   $r= mysql_query($q);

		if($r){
			$row = mysql_fetch_assoc($r);
			$v = $row['amt'];

			return $v;
		}
}

//check applicant that has paid app fees
function get_applicant_paid_acc_fees_amount($id)
{
	//query the database
		$q = "SELECT (amount-165) AS amt FROM acceptance_nce_fee_payments
			WHERE  applicant_id = '$id'";
	   $r= mysql_query($q);

		if($r){
			$row = mysql_fetch_assoc($r);
			$v = $row['amt'];

			return $v;
		}
}


//check if admitted and display button
function is_admitted($id)
{
		$result = mysql_query("SELECT * FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$admission_status = $row['admission_status'];


		if($admission_status == '0')
		{
			return '<a class="btn btn-warning btn-sm" >  Pending </a> ';
		}
		else
		{
			return '<a class="btn btn-success btn-sm" >  Admitted </a> <br/><br/>
					';//<a class="btn-info btn-sm" target="_blank"  href="https://apply.ndp.ibbuconsult.com.ng/applications_1/create_application_letter.php?u='.$id.'&c='. md5('EasyBrother').'"> Print Letter </a>


		}



}// check if admitted


//check if admitted and display MODAL  button
function is_applicant_admitted($id)
{
		$result = mysql_query("SELECT * FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$admission_status = $row['admission_status'];



		return $admission_status;

		//return value

}


//check if admitted and display MODAL  button
function is_applicant_admitted_sum($id)
{
		$result = mysql_query("SELECT * FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$admission_status = $row['admission_status'];



		return $admission_status;

		//return value

}


//get list of the programmes
function  get_programme_list($pt)
{
	$result = mysql_query("SELECT * FROM programmes WHERE type_id = '$pt'");


	//if(mysql_num_rows($result>0))
//	{
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			echo '<a href="gateway.php?act=view_applicants_per_course&a='.sha1('fucku').'&pt='.$row['type_id'].'&p='.$row['id'].'" class="btn btn-success  btn-lg" target="_blank" style="margin:4px;" >'.$row['title'].' - <span class="badge">'.get_total_prog_type_programme_applicants($pt,$row['id']).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}
//get list of the programmes
function  get_programme_list_prence($pt,$md, $ses)
{
	$result = mysql_query("SELECT * FROM programmes WHERE type_id = '$pt'");


	//if(mysql_num_rows($result>0))
//	{
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			echo '<a href="gateway.php?act=view_applicants_per_course&a='.sha1('fucku').'&pt='.$row['type_id'].'&p='.$row['id'].'&ses='.$ses.'" class="btn btn-success  btn-lg" target="_blank" style="margin:4px;" >'.$row['title'].' - <span class="badge">'.get_total_prog_type_programme_applicants_prence($pt,$row['id'],$md, $ses).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}
//get list of the programmes
function  get_programme_list_nce($pt, $ses, $md)
{
	$result = mysql_query("SELECT * FROM programmes WHERE type_id = '$pt' AND mode='$md'");


	//if(mysql_num_rows($result>0))
	//	{
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			echo '<a href="gateway.php?act=view_applicants_per_course&a='.sha1('fucku').'&pt='.$row['type_id'].'&p='.$row['id'].'&ses='.$ses.'" class="btn btn-success  btn-lg" target="_blank" style="margin:4px;" >'.$row['title'].' - <span class="badge">'.get_total_prog_type_programme_applicants_nce($pt,$row['id'], $ses).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}

//get list of the programmes
function  get_programme_list_sum($ses)
{
	$result = mysql_query("SELECT * FROM programmes WHERE real_ = 0");


	//if(mysql_num_rows($result>0))
	//	{
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			echo '<a href="gateway.php?act=view_applicants_per_course_deg&a='.sha1('fucku').'&p='.$row['id'].'&ses='.$ses.'" class="btn btn-success  btn-lg" target="_blank" style="margin:4px;" >'.$row['title'].' - <span class="badge">'.get_total_prog_type_programme_applicants_sum($row['id'], $ses).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}

//get list of the programmes
function  get_programme_list_deg($ses)
{
	$result = mysql_query("SELECT * FROM programmes WHERE real_ = 0");


	//if(mysql_num_rows($result>0))
	//	{
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			echo '<a href="gateway.php?act=view_applicants_per_course_deg&a='.sha1('fucku').'&p='.$row['id'].'&ses='.$ses.'" class="btn btn-success  btn-lg" target="_blank" style="margin:4px;" >'.$row['title'].' - <span class="badge">'.get_total_prog_type_programme_applicants_deg($row['id'], $ses).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}

//get list of the programmes
function  get_programme_list_lvsp($pt,$mode)
{
	$result = mysql_query("SELECT * FROM programmes WHERE type_id = '$pt' AND mode = '$mode'");


	//if(mysql_num_rows($result>0))
//	{
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			echo '<a href="gateway.php?act=view_applicants_per_course&a='.sha1('fucku').'&pt='.$row['type_id'].'&p='.$row['id'].'" class="btn btn-success  btn-lg" target="_blank" style="margin:4px;" >'.$row['title'].' - <span class="badge">'.get_total_prog_type_programme_applicants($pt,$row['id']).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}
//get list of the programmes
function  get_programme_list_lvsp_4($pt,$mode)
{
	$result = mysql_query("SELECT * FROM programmes WHERE type_id = '$pt' AND mode = '$mode'");


	//if(mysql_num_rows($result>0))
//	{
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			echo '<a href="gateway.php?act=view_applicants_per_course&a='.sha1('fucku').'&pt='.$row['type_id'].'&p='.$row['id'].'&ses='.$sess.'" class="btn btn-success  btn-lg" target="_blank" style="margin:4px;" >'.$row['title'].' - <span class="badge">'.get_total_prog_type_programme_applicants_lvsp($pt,$mode, $row['id']).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}


//function get total admitted applicants
function get_total_admitted_applicants()
{
	$q = "SELECT COUNT(id) FROM applicants_nce WHERE  admission_status = '1'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}


//function get total admitted applicants  per programme type
function get_total_admitted_applicants_per_programme_type($pt)
{
	$q = "SELECT COUNT(id) FROM applicants_nce WHERE  admission_status = '1'  AND type_id = '$pt'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}


//get list of the programmes admitted candidate
function  get_programme_list_admitted_applicants($pt)
{
	$result = mysql_query("SELECT * FROM programmes WHERE type_id = '$pt'");


	//if(mysql_num_rows($result>0))
//	{
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			echo '<a href="gateway.php?act=view_admitted_applicants_per_course&a='.sha1('fucku').'&pt='.$row['type_id'].'&p='.$row['id'].'" class="btn btn-success  btn-lg" style="margin:4px;" >'.$row['title'].' - <span class="badge">'.get_total_prog_type_programme_admitted_applicants($row['type_id'],$row['id'], $admitted = '1').'</span> / <span class="badge">'.get_total_prog_type_programme_applicants($row['type_id'],$row['id']).'</span> '.'</a><br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}


//function get total applicants admitted in a programme
function get_total_prog_type_programme_admitted_applicants($pt, $id, $admitted)
{
	$q = "SELECT COUNT(id) FROM applicants_nce  WHERE type_id = '$pt' AND programme_id = '$id' AND admission_status = '$admitted'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}




//function view admitted applicants listings per programmes
function view_admitted_applicants_list_per_programmes($pt,$p, $admitted) // pt programm type , p programme
{


	//query the database
	$q = "SELECT `id`, `programme_type_applied_for`, `department_applied_for`, `programme_applied_for`,`type_id`,`department_id`,`programme_id`,
	     `application_number`, `state_id`, `lga_id`, `first_name`, `other_names`, `phone_no`,  `gender`,  `email`,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		  FROM  applicants_nce

		  WHERE   type_id = '$pt' AND programme_id = '$p' AND admission_status = '$admitted'

		  ORDER BY application_number ASC";
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>Applied For</th>
						<th>Department</th>
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>




			</thead>
			<tfoot>

						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>Applied For</th>
						<th>Department</th>
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>


			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td>".$row['application_number']."</td>";
			$output .= "<td> <a href='gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$row['id']."' target='_new'>".$row['first_name'].' '.$row['other_names']."</a></td>";
			$output .= "<td>".$row['gender']."</td>";
			$output .= "<td>".show_programme_type($row['type_id'])."</td>";
			$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";
			$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
			$output .= "<td>".$row['phone_no']."</td>";
			$output .= "<td>".get_state_title($row['state_id'])."</td>";
			$output .= "<td>".get_lga_title($row['lga_id'])."</td>";
			$output .= "<td>".get_applicant_image($row['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;




}//end of view admitted  applicants listings per programmes


//function view all admitted applicants listings
function view_all_admitted_applicants_list($admitted, $pt) // pt programm type , p programme
{


	//query the database
	$q = "SELECT `id`, `programme_type_applied_for`, `school_applied_for`,`department_applied_for`, `programme_applied_for`,`type_id`,`school_id`,`department_id`,`programme_id`,
	     `application_number`, `state_id`, `lga_id`, `first_name`, `other_names`, `phone_no`,  `gender`,  `email`,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		  FROM  applicants_nce

		  WHERE  admission_status = '$admitted' AND type_id = '$pt'

		  ORDER BY application_number ASC";
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>Applied For</th>
						<th>Department</th>
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>




			</thead>
			<tfoot>

						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>Applied For</th>
						<th>Department</th>
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>


			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td>".$row['application_number']."</td>";
			$output .= "<td> <a href='gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$row['id']."' target='_new'>".$row['first_name'].' '.$row['other_names']."</a></td>";
			$output .= "<td>".$row['gender']."</td>";
			$output .= "<td>".show_programme_type($row['type_id'])."</td>";
			$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";
			$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
			$output .= "<td>".$row['phone_no']."</td>";
			$output .= "<td>".get_state_title($row['state_id'])."</td>";
			$output .= "<td>".get_lga_title($row['lga_id'])."</td>";
			$output .= "<td>".get_applicant_image($row['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;




}//end of view all admitted  applicants




	//////////////////////// remita log
	//function view transaction log
	function view_remita_transaction_log()
	{

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

		 FROM `remita_webpay_transaction_log`

		 ORDER BY id DESC";
	   $result = mysql_query($query);



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


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

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


			  </thead>

			 <!-- <tfoot>

			  </tfoot>-->

			  <tbody>';


			while($row = mysql_fetch_array($result, MYSQL_ASSOC))
			{
			   // $int_amount = $row['amount'] * 100;


				$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_description'] ."(".$row['response_code'].")"."</td>";

				$output .= "<td>".show_transaction_type($row['transaction_type'])."</td>";
				$output .= "<td>".show_transaction_for($row['transaction_for'])."</td>";

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


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

				if($row['payment_status'] != '1')
				{
				  $output .= '<td><a target="_blank" class="btn btn-sm btn-primary" href="gateway.php?act=view_rr_log&u='.$row['user_id'].'&txnref='.$row['transaction_reference'].'" > Re - Query </a></td>';
				}
				else
				{
				   $output .= "<td></td>";

				}

				$output .= "</tr>";

			}
		}
		else
		{//show the msg

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


		}



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





		return $output;






	}//end of view transaction log

	//function view transaction log
	function view_app_fee_remita_transaction_log($trans_type , $trans_for)
	{

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

		 FROM `remita_webpay_transaction_log` rem , invoices invs
		 WHERE rem.transaction_type ='$trans_type' AND rem.transaction_for = '$trans_for'
		 AND rem.invoice_id = invs.invoice_id AND invs.session = '5'
		 ORDER BY rem.id DESC";//change  session value in invs.session = '4'
	   $result = mysql_query($query);



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


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

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


			  </thead>

			 <!-- <tfoot>

			  </tfoot>-->

			  <tbody>';


			while($row = mysql_fetch_array($result, MYSQL_ASSOC))
			{
			   // $int_amount = $row['amount'] * 100;

				$appno = get_applicant_application_number($row['user_id']);
				$first_name = get_applicant_first_name($row['user_id']);

				$output .= "<tr>";
				$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$appno." <br>( ".$first_name." )</td>"; //group belong to admin or user
				$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_description'] ."(".$row['response_code'].")"."</td>";

				$output .= "<td>".show_transaction_type($row['transaction_type'])."</td>";
				$output .= "<td>".show_transaction_for($row['transaction_for'])."</td>";

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


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

				if($row['payment_status'] != '1')
				{
					//when screening fees
					if ($trans_for == 1) {
						$output .= '<td><a target="_blank" class="btn btn-sm btn-primary" href="gateway.php?act=view_scrf_rr_log&u='.$row['user_id'].'&txnref='.$row['transaction_reference'].'" > Re - Query </a></td>';
					}else{
						$output .= '<td><a target="_blank" class="btn btn-sm btn-primary" href="gateway.php?act=view_rr_log&u='.$row['user_id'].'&txnref='.$row['transaction_reference'].'" > Re - Query </a></td>';
					}

				}
				else
				{
				   $output .= "<td></td>";

				}

				$output .= "</tr>";

			}
		}
		else
		{//show the msg

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


		}



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





		return $output;



	}//end of view transaction log


	//function view transaction log
	function view_sch_fee_remita_transaction_log($trans_type , $trans_for)
	{

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

		 FROM `remita_webpay_transaction_log`
		 WHERE transaction_type ='$trans_type' AND transaction_for = '$trans_for'
		 ORDER BY id DESC";
	   $result = mysql_query($query);



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


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

					 	//when returning student
				if ($trans_type == 2) {
					$output .= "<th>Matric. No.</th>";
				}else{
					$output .= "<th>App. No.</th>";
				}

			$output .='  <th>Invoice #</th>
						  <th>RRR</th>
						  <th>Transaction Ref.</th>
						  <th>Title</th>
						  <th>Amount- (N)</th>
						  <th>Transaction Response</th>
						  <th>Transaction Type</th>
						  <th>Transaction For</th>
						  <th>Transaction Date / Time</th>
						  <th>Status</th>
						  <th>Action</th>


			  </thead>

			 <!-- <tfoot>

			  </tfoot>-->

			  <tbody>';


			while($row = mysql_fetch_array($result, MYSQL_ASSOC))
			{
			   // $int_amount = $row['amount'] * 100;

				$appno = get_applicant_application_number($row['user_id']);

				$ap_first_name = get_applicant_first_name($row['user_id']);
				$mat_no = get_student_matric_number($row['user_id']);

				$output .= "<tr>";
				//when returning student
				if ($trans_type == 2) {
					$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$mat_no."</td>"; //group belong to admin or user
				}else{
					$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$appno."<br>( ".$ap_first_name." )</td>"; //group belong to admin or user

				}
				$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_description'] ."(".$row['response_code'].")"."</td>";

				$output .= "<td>".show_transaction_type($row['transaction_type'])."</td>";
				$output .= "<td>".show_transaction_for($row['transaction_for'])."</td>";

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


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

				if($row['payment_status'] != '1')
				{
					//get student level
					//'.$row['user_id'].'
					$lev = get_student_level_nce($row['user_id']);
					//when returning student
				  if ($trans_type == 2) {
				  	 $output .= '<td><a target="_blank" class="btn btn-sm btn-primary" href="gateway.php?act=view_sf_rr_log&u='.$row['user_id'].'&lev='.$lev.'&txnref='.$row['transaction_reference'].'" > Re - Query </a></td>';
				  } else {

					  $output .= '<td><a target="_blank" class="btn btn-sm btn-primary" href="gateway.php?act=view_sf_rr_log&u='.$row['user_id'].'&txnref='.$row['transaction_reference'].'" > Re - Query </a></td>';
				  }

				}
				else
				{
				   $output .= "<td></td>";

				}

				$output .= "</tr>";

			}
		}
		else
		{//show the msg

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


		}



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





		return $output;



	}//end of view transaction log




	//function view transaction log
	function view_sch_fee_remita_transaction_log_2($trans_type , $trans_for,$sess)
	{

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

		 FROM `remita_webpay_transaction_log`
		 WHERE transaction_type ='$trans_type' AND transaction_for = '$trans_for'
		 AND session = '$sess'
		 ORDER BY id DESC";
	   $result = mysql_query($query);



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


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

					 	//when returning student
				if ($trans_type == 2) {
					$output .= "<th>Matric. No.</th>";
				}else{
					$output .= "<th>App. No.</th>";
				}

			$output .='  <th>Invoice #</th>
						  <th>RRR</th>
						  <th>Transaction Ref.</th>
						  <th>Title</th>
						  <th>Amount- (N)</th>
						  <th>Transaction Response</th>
						  <th>Transaction Type</th>
						  <th>Transaction For</th>
						  <th>Transaction Date / Time</th>
						  <th>Status</th>
						  <th>Action</th>


			  </thead>

			 <!-- <tfoot>

			  </tfoot>-->

			  <tbody>';


			while($row = mysql_fetch_array($result, MYSQL_ASSOC))
			{
			   // $int_amount = $row['amount'] * 100;

				$appno = get_applicant_application_number($row['user_id']);

				$ap_first_name = get_applicant_first_name($row['user_id']);
				$mat_no = get_student_matric_number($row['user_id']);

				$output .= "<tr>";
				//when returning student
				if ($trans_type == 2) {
					$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$mat_no."</td>"; //group belong to admin or user
				}else{
					$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$appno."<br>( ".$ap_first_name." )</td>"; //group belong to admin or user

				}
				$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_description'] ."(".$row['response_code'].")"."</td>";

				$output .= "<td>".show_transaction_type($row['transaction_type'])."</td>";
				$output .= "<td>".show_transaction_for($row['transaction_for'])."</td>";

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


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

				if($row['payment_status'] != '1')
				{
					//get student level
					//'.$row['user_id'].'
					$lev = get_student_level_nce($row['user_id']);
					//when returning student
				  if ($trans_type == 2) {
				  	 $output .= '<td><a target="_blank" class="btn btn-sm btn-primary" href="gateway.php?act=view_sf_rr_log&u='.$row['user_id'].'&lev='.$lev.'&txnref='.$row['transaction_reference'].'" > Re - Query </a></td>';
				  } else {

					  $output .= '<td><a target="_blank" class="btn btn-sm btn-primary" href="gateway.php?act=view_sf_rr_log&u='.$row['user_id'].'&txnref='.$row['transaction_reference'].'" > Re - Query </a></td>';
				  }

				}
				else
				{
				   $output .= "<td></td>";

				}

				$output .= "</tr>";

			}
		}
		else
		{//show the msg

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


		}



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





		return $output;



	}//end of view transaction log



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



	  //function transaction type user
	  function transaction_type_user($id)
	  {
		  if($id == '0')
		  {
			  return '<label class="label label-default"> APPLICANT </label>';
		  }
		  else if($id == '1')
		  {
			  return  '<label class="label label-info"> FRESH STUDENT </label>';
		  }
		  else if ($id == '2')
		  {
			  return  '<label class="label label-primary"> RETURNING STUDENT </label>';

		  }
		  else if ($id == '3')
		  {
			  return  '<label class="label label-primary"> REMDIAL STUDENT </label>';

		  }
		  else
		  {
			  //
		  }
	  }
	  	//function to get invoice payment to using orderID
	function get_invoice_to_using_txnref($oid)
	{
		$result = mysql_query("SELECT user_id FROM remita_webpay_transaction_log WHERE transaction_reference = '$oid'");
		$row = mysql_fetch_assoc($result);
		$v = $row['user_id'];

	return $v;
	}

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

	return $v;
	}



	  //function for remita response code
	function remita_response_code($stat, $rrr, $desc, $iid, $u)
	{

	  	//use trans type and for to get the actual table either applicant or student

	  	//get user matric no or app
	  		$mat_no = '';
	  		$app_no = '';
	  		/*//check first if the user has matric num
	  		if (user_has_matric_no($u) != '' ) {
	  			$mat_no = user_has_matric_no($u);
	  		}elseif (user_has_app_no($u) != '' ) {
	  			$app_no = user_has_app_no($u);
	  		}
		*/



		  $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>";

			if ($mat_no != '' ) {
		  			$mes .= "<br/><h3>matric Number: $mat_no </h3></p></li>";
		  	}elseif ($app_no != '' ) {
		  			$mes .= "<br/><h3>App. Number: $app_no </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;
	}






/*********************************** admin student module ****************************************/
//fucntion that returns searched students confirmation payments
function view_search_student_b($search_stb)
{

	//query the database
	$q = "SELECT `id`, `invoice_id`, `invoice_type`, `invoice_to`, `pay_to`, `invoice_for`, `payment_method`, `payment_status`, `programme_type`,
		 `title`, `description`, `amount`, `total_amount`, `credit`,

		 DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added


		 FROM invoices

		 WHERE invoice_id = '$search_stb'";

		 //LIMIT $start, $display_per_page";
	$r = mysql_query($q) or die (mysql_error());




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

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




		$output = '<table  class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="text-align:center;">

		  <thead>


		 			  <th><!--<input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"> --></th>
					  <th><h4 style="text-align:center;">Invoice ID Details</h4></th>
					  <th><h4 style="text-align:center;">Invoice To</h4></th>
					  <th ><h4 style="text-align:center;">Pay To</h4></th>

		  </thead>

		  <tbody>';




		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			if($row['programme_type'] == '1')
			{// if pre nce


					  if($row['invoice_type'] == '1')
					  {

					  $output .= '<li class="list-group-item help-block" style="text-align:center;">Description  ( '.get_session_title(get_current_session($id = 1)).' Academic Session ,
									'.get_semester_title(get_current_semester($id = 1)).' ) </li>';



					  $output .= "<tr>";
					  $output .="<td width='5%' height='10px'><input type='checkbox' value='".$row['invoice_id']."' name='invoice_prence[]' id='invoice_prence' class='checkbox1' data-toggle='tooltip' title= 'Check' /></td>" ;
					  $output .= '<td width="35%" height="10px" >Invoice # <span class="badge badge-success">'. $row['invoice_id']. '</span><br/>Invoice Date: '.get_invoice_date($row['invoice_id']).'<br/>
								  Due Date: '.get_invoice_due_date($row['invoice_id']).'



									  <li class="list-group-item help-block">
										  <span>'.get_invoice_title($row['invoice_id']).'

										  </span>
									   </li>

								  </td>';

					  $output .= '<td width="30%" height="10px">'.get_applicant_fullname($row['invoice_to']).'<br><b>'.get_applicant_application_number($row['invoice_to']).'</b><br/><b>'.show_programme_type($row['programme_type']).'</b><br/>
									   '.get_applicant_address($row['invoice_to']).'<br> <hr/>


									   <li class="list-group-item help-block" style="height:auto;">
										  <span>'.get_invoice_desc($row['invoice_id']).'
										  </span>

									  </li>
									   <li class="list-group-item help-block">
										  <span>Sub Total:
										  </span>
										  <span class="pull-right">N'.number_format(get_invoice_amount($row['invoice_id']) ,2).'
										  </span>
									  </li>

									  <li class="list-group-item help-block">
										  <span>Credit:
										  </span>
										  <span class="pull-right">N'.number_format(get_invoiced_credit($row['invoice_id']) ,2).'
										  </span>
									  </li>

									  </td>';


					  $output .= '<td width="30%">'.get_invoice_pay_to($row['invoice_id']).' <br/> <hr/>

									  <li class="list-group-item help-block" style="min-height:60px;">


										  <span class="pull-right text-success" style="font-size:35px; font-weight:bold;">Total: N'.number_format(get_invoice_total_amount($row['invoice_id']) ,2).'K
										  </span>

									  </li>

								 </td>';

					  $output .= "</tr>";

					  }//end of if new student
					  else
					  {// begin if old student


						  $output .= '<li class="list-group-item help-block" style="text-align:center;">Description  ( '.get_session_title(get_current_session($id = 1)).' Academic Session ,
									'.get_semester_title(get_current_semester($id = 1)).' ) </li>';



						  $output .= "<tr>";
						  $output .="<td width='5%' height='10px'><input type='checkbox' value='".$row['invoice_id']."' name='invoice_prence[]' id='invoice_prence' class='checkbox1' data-toggle='tooltip' title= 'Check' /></td>" ;
						  $output .= '<td width="35%" height="10px" >Invoice # <span class="badge badge-success">'. $row['invoice_id']. '</span><br/>Invoice Date: '.get_invoice_date($row['invoice_id']).'<br/>
									  Due Date: '.get_invoice_due_date($row['invoice_id']).'



										  <li class="list-group-item help-block">
											  <span>'.get_invoice_title($row['invoice_id']).'

											  </span>
										   </li>

									  </td>';

						  $output .= '<td width="30%" height="10px">'.get_student_fullname($row['invoice_to']).'<br><b>'.get_student_matric_number($row['invoice_to']).'</b><br/>
										   '.get_student_address($row['invoice_to']).'<br> <hr/>


										   <li class="list-group-item help-block" style="height:auto;">
											  <span>'.get_invoice_desc($row['invoice_id']).'
											  </span>

										  </li>
										   <li class="list-group-item help-block">
											  <span>Sub Total:
											  </span>
											  <span class="pull-right">N'.number_format(get_invoice_amount($row['invoice_id']) ,2).'
											  </span>
										  </li>

										  <li class="list-group-item help-block">
											  <span>Credit:
											  </span>
											  <span class="pull-right">N'.number_format(get_invoiced_credit($row['invoice_id']) ,2).'
											  </span>
										  </li>

										  </td>';


						  $output .= '<td width="30%">'.get_invoice_pay_to($row['invoice_id']).' <br/> <hr/>

										  <li class="list-group-item help-block" style="min-height:60px;">


											  <span class="pull-right text-success" style="font-size:35px; font-weight:bold;">Total: N'.number_format(get_invoice_total_amount($row['invoice_id']) ,2).'K
											  </span>

										  </li>

									 </td>';

						  $output .= "</tr>";



					  }


			}
			else
			{

			//######################################## nce



					  if($row['invoice_type'] == '1')
					  {

					  $output .= '<li class="list-group-item help-block" style="text-align:center;">Description  ( '.get_session_title(get_current_session($id = 1)).' Academic Session ,
									'.get_semester_title(get_current_semester($id = 1)).' ) </li>';



					  $output .= "<tr>";
					  $output .="<td width='5%' height='10px'><input type='checkbox' value='".$row['invoice_id']."' name='invoice_nce[]' id='invoice_nce' class='checkbox1' data-toggle='tooltip' title= 'Check' /></td>" ;
					  $output .= '<td width="35%" height="10px" >Invoice # <span class="badge badge-success">'. $row['invoice_id']. '</span><br/>Invoice Date: '.get_invoice_date($row['invoice_id']).'<br/>
								  Due Date: '.get_invoice_due_date($row['invoice_id']).'



									  <li class="list-group-item help-block">
										  <span>'.get_invoice_title($row['invoice_id']).'

										  </span>
									   </li>

								  </td>';

					  $output .= '<td width="30%" height="10px">'.get_applicant_fullname($row['invoice_to']).'<br><b>'.get_applicant_application_number($row['invoice_to']).'</b><br/><br/><b>'.show_programme_type($row['programme_type']).'</b><br/>
									   '.get_applicant_address($row['invoice_to']).'<br> <hr/>


									   <li class="list-group-item help-block" style="height:auto;">
										  <span>'.get_invoice_desc($row['invoice_id']).'
										  </span>

									  </li>
									   <li class="list-group-item help-block">
										  <span>Sub Total:
										  </span>
										  <span class="pull-right">N'.number_format(get_invoice_amount($row['invoice_id']) ,2).'
										  </span>
									  </li>

									  <li class="list-group-item help-block">
										  <span>Credit:
										  </span>
										  <span class="pull-right">N'.number_format(get_invoiced_credit($row['invoice_id']) ,2).'
										  </span>
									  </li>

									  </td>';


					  $output .= '<td width="30%">'.get_invoice_pay_to($row['invoice_id']).' <br/> <hr/>

									  <li class="list-group-item help-block" style="min-height:60px;">


										  <span class="pull-right text-success" style="font-size:35px; font-weight:bold;">Total: N'.number_format(get_invoice_total_amount($row['invoice_id']) ,2).'K
										  </span>

									  </li>

								 </td>';

					  $output .= "</tr>";

					  }//end of if new student
					  else
					  {// begin if old student


						  $output .= '<li class="list-group-item help-block" style="text-align:center;">Description  ( '.get_session_title(get_current_session($id = 1)).' Academic Session ,
									'.get_semester_title(get_current_semester($id = 1)).' ) </li>';



						  $output .= "<tr>";
						  $output .="<td width='5%' height='10px'><input type='checkbox' value='".$row['invoice_id']."' name='invoice_nce[]' id='invoice_nce' class='checkbox1' data-toggle='tooltip' title= 'Check' /></td>" ;
						  $output .= '<td width="35%" height="10px" >Invoice # <span class="badge badge-success">'. $row['invoice_id']. '</span><br/>Invoice Date: '.get_invoice_date($row['invoice_id']).'<br/>
									  Due Date: '.get_invoice_due_date($row['invoice_id']).'



										  <li class="list-group-item help-block">
											  <span>'.get_invoice_title($row['invoice_id']).'

											  </span>
										   </li>

									  </td>';

						  $output .= '<td width="30%" height="10px">'.get_student_fullname($row['invoice_to']).'<br><b>'.get_student_matric_number($row['invoice_to']).'</b><br/>
										   '.get_student_address($row['invoice_to']).'<br> <hr/>


										   <li class="list-group-item help-block" style="height:auto;">
											  <span>'.get_invoice_desc($row['invoice_id']).'
											  </span>

										  </li>
										   <li class="list-group-item help-block">
											  <span>Sub Total:
											  </span>
											  <span class="pull-right">N'.number_format(get_invoice_amount($row['invoice_id']) ,2).'
											  </span>
										  </li>

										  <li class="list-group-item help-block">
											  <span>Credit:
											  </span>
											  <span class="pull-right">N'.number_format(get_invoiced_credit($row['invoice_id']) ,2).'
											  </span>
										  </li>

										  </td>';


						  $output .= '<td width="30%">'.get_invoice_pay_to($row['invoice_id']).' <br/> <hr/>

										  <li class="list-group-item help-block" style="min-height:60px;">


											  <span class="pull-right text-success" style="font-size:35px; font-weight:bold;">Total: N'.number_format(get_invoice_total_amount($row['invoice_id']) ,2).'K
											  </span>

										  </li>

									 </td>';

						  $output .= "</tr>";



					  }


			}//end of if nce

		}//end of while
//

	}
	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; Candidate not recognise by the system. We apologize for any inconvenience..
				   </div>';


	}



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





	return $output;

	//else
//	{
//		$errors['error'] =  'Candidate not recognise by the system. We apologize for any inconvenience.';
//
//		header("Location: gateway.php?act=search_candidate&error=".urlencode($errors['error'])."");
//	}





}//end of view search candidate





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

	return $v;
	}


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

	return $v;
	}

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

	return $v;
	}


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

	return $v;
	}





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

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



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

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

		 $v = $credit;

	    return $v;
	}





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

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


	}



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

	return $v;
	}

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

	return $v;
	}



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

	return $v;
	}



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

	return $v;
	}


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

	return $v;
	}

		
	//Function to fetch  invoice type
	function get_trans_ref($iid)
	{
		$result = mysql_query("SELECT transaction_reference FROM remita_webpay_transaction_log WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['transaction_reference'];
		
	return $v;
	}
	

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

	return $v;
	}


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

	return $v;
	}


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

	return $v;
	}


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

	return $v;
	}



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

	return $v;
	}



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

	return $v;
	}


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

	return $v;
	}

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

	return $v;
	}



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

	return $v;
	}


	//Function to fetch total unpaid  invoice generated
	function get_total_invoice_unpaid($current_session)
	{
		$result = mysql_query("SELECT COUNT(DISTINCT(invoice_to))  FROM invoices WHERE payment_status = '0' AND session = '$current_session'");
		$row = mysql_fetch_array($result,MYSQL_NUM);

	     return $row[0];

	}



	//function showpayment mode
	function show_payment_mode($r)
	{

			if ($r == '1')
			{

				$output = 'Instalment';



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

				$output = 'Full';


			}
			else
			{

				$output = 'Default';
			}

		return $output;

	}
	//end of show payment mode

	//function transaction type
	function show_transaction_type($r)
	{

			if ($r == '0')
			{

				$output = 'Applicant ';



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

				$output = 'Fresh Student';


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

				$output = 'Returning Student';


			}
			else
			{

				$output = 'Default';
			}

		return $output;

	}
	//end of show transaction type
	//function transaction for
	function show_transaction_for($r)
	{

			if ($r == '0')
			{

				$output = 'Application Fees ';



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

				$output = 'Screening Fees';


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

				$output = 'School Fees';


			}
			else
			{

				$output = 'Default';
			}

		return $output;

	}
	//end of show transaction for



	//Function to fetch programme type
	function get_invoice_programme_type($iid)
	{
		$result = mysql_query("SELECT programme_type FROM invoices WHERE invoice_id = '$iid'");
		$row = mysql_fetch_assoc($result);
		$v = $row['programme_type'];

	return $v;
	}

	function show_month($mnt)
	{

		$mnt -= 1;
		$months = array(
		    'January',
		    'February',
		    'March',
		    'April',
		    'May',
		    'June',
		    'July ',
		    'August',
		    'September',
		    'October',
		    'November',
		    'December',
		);

		return $months[$mnt];


	}

	////function show major status type
	function show_major_status($r)
	{

			if ($r == '0')
			{

				$output = 'SM';



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

				$output = 'Dm';


			}
			else
			{

				$output = 'NIL';
			}

		return $output;

	}
	//end of show programme  type

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

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

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


			 ORDER BY invoice_id DESC";
   $result = mysql_query($query);



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


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

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



		  </thead>

		 <!-- <tfoot>




		  </tfoot>-->

		  <tbody>';


		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$row['invoice_id']."</td>"; //group belong to admin or user
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['due_date']."</td>";
			$output .= "<td>".payment_status($row['payment_status'])."</td>";
			$output .= '<td><a class="btn btn-default" href="dashboard.php?act=view_invoices&qlk='.md5(2).'&iid='.$row['invoice_id'].'"> View Invoice</a></td>';
			$output .= "</tr>";

		}
	}
	else
	{//show the msg

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


	}



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





	return $output;






}//end of view school fee invoices





// function that check if a applicant application number exist in stduents table or not
	function application_number_exist($apn, $l)
	{
		$result = mysql_query("SELECT application_number  FROM students_nce WHERE application_number = '$apn' AND level = '$l'");
		$row = mysql_fetch_assoc($result);
		$an = $row['application_number'];

		if($an == '')
		{

			return false;



		}
		else
		{
			return true;


		}


	}
	//end of checking if applicant exist



	// function that check if a applicant application number exist in stduents table or not for pre nce
	function application_number_exist_prence($apn, $l)
	{
		$result = mysql_query("SELECT application_number  FROM students_prence WHERE application_number = '$apn' AND level = '$l'");
		$row = mysql_fetch_assoc($result);
		$an = $row['application_number'];

		if($an == '')
		{

			return false;



		}
		else
		{
			return true;


		}


	}
	//end of checking if applicant exist




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


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



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



		//function dat checks if student exist in database table  pre nce
		function student_id_exist_payments_prence($sid,$sess, $sem)
		{
			$q = "SELECT student_id FROM school_fee_payments_prence  WHERE student_id = '$sid' AND session = '$sess' AND semester = '$sem' ";
			$r = mysql_query($q);


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



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




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

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

			//this is for NCE get the programme codes for schools
			//$first_letter = 'SE';

			//get school code by passing the school id
			$first_letter = strtoupper(get_school_code($dep));
		}
		else if($pt == '3')
		{
			$first_letter = 'U'; //This is for Degree
		}
		else
		{
			//do nothing

		}




	//get programme code from programme

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


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

	$total = $total_in_programme;




	//getcuurent sesssiom
	//Function to fetch current session
	 $session = get_current_session_4($id ='4');

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


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



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

	$count_character = strlen($total);

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



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




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


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

			//collect all the matric number


			$q = "SELECT number FROM students_nce WHERE number LIKE '%$mn%'";
			$r = mysql_query($q);

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

			if(strlen($programme_code) <= 3)
			{
				$ln = 10;
			}
			else
			{
				$ln = 14;
			}




			while($row = mysql_fetch_array($r, MYSQL_ASSOC))
			{

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

				//$lenght




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


			}

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


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

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

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

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




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



			return $matric_numbe;

		//}


	}
	else
	{
		return $matric_number;
	}


	//return $matric_number;

}


//function that gets school code base on course id
	function  get_school_code($id)
	{
		$result = mysql_query("SELECT code FROM schools WHERE id = '$id'");
			$row = mysql_fetch_assoc($result);
			$v = $row['code'];

		return $v;

	}



//function generate matric number for pre nce
function generate_matric_number_prence($pt, $dep, $p, $level, $total_in_programme)
{

	//check programme type to know if to give
		if($pt == '1')
		{
			$first_letter = 'PR/'.strtoupper(get_school_code($dep));
		}
		else if($pt == '2')
		{

			//this is for NCE get the programme codes for schools
			//$first_letter = 'SE';

			//get school code by passing the school id
			//$first_letter = strtoupper(get_school_code($dep));
		}
		else if($pt == '3')
		{
			//$first_letter = 'U'; //This is for Degree
		}
		else
		{
			//do nothing

		}




	//get programme code from programme

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


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

	$total = $total_in_programme;




	//getcuurent sesssiom
	//Function to fetch current session
	 $session = get_current_session_4($id ='4');

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


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



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

	$count_character = strlen($total);

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



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




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


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

			//collect all the matric number


			$q = "SELECT number FROM students_prence WHERE number LIKE '%$mn%'";
			$r = mysql_query($q);

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


			if(strlen($programme_code) <= 3)
			{
				$ln = 13;
			}
			else
			{
				$ln = 17;
			}

			while($row = mysql_fetch_array($r, MYSQL_ASSOC))
			{

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



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

			}

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


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

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

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

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




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



			return $matric_numbe ;

		//}


	}
	else
	{
		return $matric_number;
	}


	//return $matric_number;

}
//end of generate matric no for pre nce

//Functions to fetch student Full name
	function get_student_fullname($id)
	{
		$result = mysql_query("SELECT * FROM students_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$first_name = $row['first_name'];
		$other_names = $row['other_names'];

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

	  return $user_fullname;
	}



//Functions to fetch student Full name
	function get_student_fullname_prence($id)
	{
		$result = mysql_query("SELECT * FROM students_prence WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$first_name = $row['first_name'];
		$other_names = $row['other_names'];

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

	  return $user_fullname;
	}




   //function dat get student matric number
	function get_student_matric_number($user_id)
	{
	$q = "SELECT number FROM students_nce WHERE id = '$user_id'";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['number'];


	}




	 //function dat get student matric number pre nce
	function get_student_matric_number_prence($user_id)
	{
	$q = "SELECT number FROM students_prence WHERE id = '$user_id'";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['number'];


	}
	//function dat get student level
	function get_student_level_nce($user_id)
	{
		$q = "SELECT level FROM students_nce WHERE id = '$user_id'";
		$r = mysql_query($q);
		$row = mysql_fetch_assoc($r);

		return $row['level'];


	}
	//function dat get student matric number pre nce
	function get_student_level_prence($user_id)
	{
		$q = "SELECT level FROM students_prence WHERE id = '$user_id'";
		$r = mysql_query($q);
		$row = mysql_fetch_assoc($r);

		return $row['level'];


	}


	//function dat get student address
	function get_student_address($user_id)
	{
	$q = "SELECT address FROM students_nce WHERE id = '$user_id'";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['address'];


	}


	//function fetch student department
	function get_student_department_id($id)
	{
		$result = mysql_query("SELECT department_id FROM students WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['department_id'];


		return $v;
	}



	//function fetch student programme
	function get_student_programme_id($id)
	{
		$result = mysql_query("SELECT programme_id FROM students_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['programme_id'];


		return $v;
	}

	//function fetch student programme  prence
	function get_student_programme_id_prence($id)
	{
		$result = mysql_query("SELECT programme_id FROM students_prence WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['programme_id'];


		return $v;
	}



	//function fetch student school
	function get_student_school_id($id)
	{
		$result = mysql_query("SELECT school_id FROM students_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['school_id'];


		return $v;
	}

	//function fetch student school  pre nce
	function get_student_school_id_prence($id)
	{
		$result = mysql_query("SELECT school_id FROM students_prence WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['school_id'];


		return $v;
	}


	//function fetch student programme type
	function get_student_programme_type_id($id)
	{
		$result = mysql_query("SELECT type_id FROM students_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['type_id'];


		return $v;
	}



	//function fetch student id by application number
	function get_student_id_application_number($id, $l) //$l is level
	{
		$result = mysql_query("SELECT id FROM students_nce WHERE application_number = '$id' AND level = '$l'");
		$row = mysql_fetch_assoc($result);
		$v = $row['id'];


		return $v;
	}

	//function fetch student id by application number
	function get_student_id_application_number_prence($id, $l) //$l is level
	{
		$result = mysql_query("SELECT id FROM students_prence WHERE application_number = '$id' AND level = '$l'");
		$row = mysql_fetch_assoc($result);
		$v = $row['id'];


		return $v;
	}

	//check if a particular matric number is on the system
	function matric_number_exist($mno)
	{
	    $result = mysql_query("SELECT number FROM students_nce WHERE number = '$mno'");
		$row = mysql_fetch_assoc($result);
		$mno = $row['number'];

		if($mno == '')
		{

			return false;

		}
		else
		{
			return true;

		}


	}


		//check if a particular matric number is on the system for prence
		function matric_number_exist_prence($mno)
		{
			$result = mysql_query("SELECT number FROM students_prence WHERE number = '$mno'");
			$row = mysql_fetch_assoc($result);
			$mno = $row['number'];

			if($mno == '')
			{

				return false;

			}
			else
			{
				return true;

			}


		}// matric number exist pre nce



	//function get user sponsorhip type
	function get_student_sponsorship_type_nce($id)
	{
		$result = mysql_query("SELECT sponsorship_type FROM students_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['sponsorship_type'];


		return $v;
	}

	/////////////////report for the student
	//function count number of non sport/unicef
	function get_total_confirmed_payments_per_semester($session, $semester)
	{
		$q = "SELECT COUNT(DISTINCT student_id) FROM school_fee_payments_nce WHERE  session = '$session' AND semester = '$semester' AND student_id != '' AND (sponsorship_type != '4' AND sponsorship_type != '5')";
		$r = mysql_query($q);
		$row = mysql_fetch_array($r,MYSQL_NUM);


		$v = number_format($row[0]);

		return $v;
		//return ;
	}




	//function count number of bank confirmation for prence non sport/unicef
	function get_total_confirmed_payments_per_semester_prence($session, $semester)
	{
		$q = "SELECT COUNT(DISTINCT student_id) FROM school_fee_payments_prence WHERE  session = '$session' AND semester = '$semester' AND student_id != '' AND (sponsorship_type != '4' AND sponsorship_type != '5')";
		$r = mysql_query($q);
		$row = mysql_fetch_array($r,MYSQL_NUM);


		$v = number_format($row[0]);

		return $v;
		//return ;
	}


		//function count number for support
	function get_total_confirmed_payments_per_semester_sport($session, $semester)
	{
		$q = "SELECT COUNT(DISTINCT student_id) FROM school_fee_payments_nce WHERE  session = '$session' AND semester = '$semester' AND student_id != '' AND sponsorship_type = '5'";
		$r = mysql_query($q);
		$row = mysql_fetch_array($r,MYSQL_NUM);


		$v = number_format($row[0]);

		return $v;
		//return ;
	}

	//function count number of bank confirmation for prence for sport
	function get_total_confirmed_payments_per_semester_prence_sport($session, $semester)
	{
		$q = "SELECT COUNT(DISTINCT student_id) FROM school_fee_payments_prence WHERE  session = '$session' AND semester = '$semester' AND student_id != '' AND sponsorship_type = '5'";
		$r = mysql_query($q);
		$row = mysql_fetch_array($r,MYSQL_NUM);


		$v = number_format($row[0]);

		return $v;
		//return ;
	}


		//function count number for unicef
	function get_total_confirmed_payments_per_semester_unicef($session, $semester)
	{
		$q = "SELECT COUNT(DISTINCT student_id) FROM school_fee_payments_nce WHERE  session = '$session' AND semester = '$semester' AND student_id != '' AND sponsorship_type = '4'";
		$r = mysql_query($q);
		$row = mysql_fetch_array($r,MYSQL_NUM);


		$v = number_format($row[0]);

		return $v;
		//return ;
	}

	//function count number of bank confirmation for prence for unicef
	function get_total_confirmed_payments_per_semester_prence_unicef($session, $semester)
	{
		$q = "SELECT COUNT(DISTINCT student_id) FROM school_fee_payments_prence WHERE  session = '$session' AND semester = '$semester' AND student_id != '' AND sponsorship_type = '4'";
		$r = mysql_query($q);
		$row = mysql_fetch_array($r,MYSQL_NUM);


		$v = number_format($row[0]);

		return $v;
		//return ;
	}



/********************* student function module ************************************************/






//function get total applicants in a particular programme
//function get_total_programme_applicants($id)
//{
	//$q = "SELECT COUNT(id) FROM applicants  WHERE  programme_applied_for = '$id' AND bank_epin !='' AND serial_number != ''";
	//$r = mysql_query($q);
	//$row = mysql_fetch_array($r,MYSQL_NUM);

	//return $row[0];

//}



//function check epin limt
//function is_epin_limit()
//{
//	//collect the total epin generated
//	$total = get_total_epin_generated();
//
//
//
//
//	if($total >=  200)
//	{
//
//		return true;
//	}
//	else
//	{
//		return false;
//	}
//}




/******************************** end of applicants module  ************************************/



/********************************** provost report *****************************************/
//get list of the programmes for students reports
function  get_programme_list_for_students_report($pt,$yr)
{
	$result = mysql_query("SELECT * FROM programmes WHERE type_id = '$pt' AND mode = '1'");


	//if(mysql_num_rows($result>0))
//	{
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			echo '<a href="gateway.php?act=view_students_per_course&a='.sha1('fucku').'&pt='.$row['type_id'].'&p='.$row['id'].'&yr='.$yr.'" class="btn btn-success  btn-lg" target="_blank" style="margin:4px;" >'.$row['title'].' - <span class="badge">'.get_total_prog_type_programme_students_prence($pt,$row['id'],$yr).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}




//function get total students in PreNCe programme
function get_total_prog_type_programme_students_prence($pt, $id, $yr)
{
	$q = "SELECT COUNT(id) FROM students_prence  WHERE type_id = '$pt'
		 AND programme_id = '$id' AND entry_year = '$yr'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function view students listings per programmes
function view_students_list_per_programmes_deg($p,$yr) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT std.id, std.type_id, std.school_id,std.department_id, std.programme_id, std.application_number,number,
		  state_id, std.lga_id, std.first_name, std.other_names, std.phone_no, std.gender, std.email,
		  DATE_FORMAT(std.date_added, '%M %d, %Y %l:%i:%p') as date_added

		 FROM  students_nce std, school_fee_payments_nce sf_pay

		  WHERE    std.id = sf_pay.student_id

		  	AND  std.programme_id = '$p' AND std.entry_year = '$yr'

		  	ORDER BY std.`number` ASC";
		  	
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>Matric No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>School </th>
						<th>Programme</th>

						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Admission No.</th>



			</thead>
			<tfoot>

						<th>Matric No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>School </th>
						<th>Programme</th>

						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Admission No.</th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td>".strtoupper($row['number'])."</td>";
			/*$output .= "<td> <a href='gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$row['id']."' target='_new'>".$row['first_name'].' '.$row['other_names']."</a></td>";*/
			$output .= "<td> <a href='#'>".$row['first_name'].' '.$row['other_names']."</a></td>";
			$output .= "<td>".$row['gender']."</td>";
			$output .= "<td>".show_programme_type($row['type_id'])."</td>";
			$output .= "<td>".get_school_title($row['school_id'])."</td>";

			$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
			$output .= "<td>".$row['phone_no']."</td>";
			$output .= "<td>".get_state_title($row['state_id'])."</td>";
			$output .= "<td>".get_lga_title($row['lga_id'])."</td>";
			$output .= "<td>".get_student_image($row['id'], $row['type_id'])."</td>";
			$output .= "<td>".$row['application_number']."</td>";



			$output .= "</tr>";


		}
	}
	else
	{//show the msg

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


	}



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





	return $output;




}//end of view students ants listings per programmes



//function get total students in NCe programme
function get_total_prog_type_students_nce($pt, $yr)
{
	$q = "SELECT COUNT(id) FROM students_nce  WHERE type_id = '$pt' AND entry_year = '$yr'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}



//function get total students in NCe programme
function get_total_prog_type_students_deg($yr)
{
	$q = "SELECT COUNT(id) FROM students_nce  WHERE entry_year = '$yr'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function get total students in NCe programme
function get_total_prog_type_students_deg_abu($pt,$yr)
{
	$q = "SELECT COUNT(id) FROM students_nce  WHERE type_id = '$pt' AND entry_year = '$yr'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}


//get list of the programmes for students reports
function  get_programme_list_for_students_report_deg_2( $yr)
{
	$result = mysql_query("SELECT * FROM programmes");


	//if(mysql_num_rows($result>0))
//	{
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			echo '<a href="gateway.php?act=view_students_per_course_nce&a='.sha1('fucku').'&pt='.$row['type_id'].'&p='.$row['id'].'&yr='.$yr.'" class="btn btn-success  btn-lg" target="_blank" style="margin:4px;" >'.$row['title'].' - <span class="badge">'.get_total_prog_type_programme_students_nce($pt,$row['id'],$yr).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}


//get list of the programmes for students reports
function  get_programme_list_for_students_report_deg_2x( $yr)
{
	$result = mysql_query("SELECT * FROM programmes");


	//if(mysql_num_rows($result>0))
//	{
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			echo '<a href="gateway.php?act=view_students_per_course_nce&a='.sha1('fucku').'&pt='.$row['type_id'].'&p='.$row['id'].'&yr='.$yr.'" class="btn btn-success  btn-lg" target="_blank" style="margin:4px;" >'.$row['title'].' - <span class="badge">'.get_total_prog_type_programme_students_deg($row['id'],$yr).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}



//function get total students in NCe programme
function get_total_prog_type_programme_students_nce($pt, $id, $yr)
{
	$q = "SELECT COUNT(id) FROM students_nce  WHERE type_id = '$pt'
		AND programme_id = '$id' AND entry_year = '$yr'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}

//function get total students in NCe programme
function get_total_prog_type_programme_students_deg($id, $yr)
{
	$q = "SELECT COUNT(id) FROM students_nce  WHERE programme_id = '$id' AND entry_year = '$yr'";
	$r = mysql_query($q);

	$row = mysql_fetch_array($r,MYSQL_NUM);

	return $row[0];

}


//function view students listings per programmes
function view_students_list_per_programmes_nce($pt,$p, $yr) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later

	//query the database
	$q = "SELECT id, type_id, school_id,department_id, programme_id, application_number,number,
		  state_id, lga_id, first_name, other_names, phone_no, gender,  email,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added

		  FROM  students_nce

		  WHERE   type_id = '$pt' AND programme_id = '$p'  AND entry_year = '$yr'

		  ORDER BY number ASC";
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>Matric No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>School </th>
						<th>Programme</th>

						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Admission No.</th>



			</thead>
			<tfoot>

						<th>Matric No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>School </th>
						<th>Programme</th>

						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Admission No.</th>

			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td>".$row['number']."</td>";
			/*$output .= "<td> <a href='gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$row['id']."' target='_new'>".$row['first_name'].' '.$row['other_names']."</a></td>";*/
			$output .= "<td> <a href='#' >".$row['first_name'].' '.$row['other_names']."</a></td>";
			$output .= "<td>".$row['gender']."</td>";
			$output .= "<td>".show_programme_type($row['type_id'])."</td>";
			$output .= "<td>".get_school_title($row['school_id'])."</td>";

			$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
			$output .= "<td>".$row['phone_no']."</td>";
			$output .= "<td>".get_state_title($row['state_id'])."</td>";
			$output .= "<td>".get_lga_title($row['lga_id'])."</td>";
			$output .= "<td>".get_student_image($row['id'], $row['type_id'])."</td>";
			$output .= "<td>".$row['application_number']."</td>";



			$output .= "</tr>";


		}
	}
	else
	{//show the msg

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


	}



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





	return $output;








}//end of view students ants listings per programmes


//function to get total sum of money paid for pre nce of courses a student carried per semester
function get_total_amount_paid_per_session_prence($session)
{
	$result = mysql_query("SELECT SUM(amount) AS summed_up FROM school_fee_payments_prence WHERE  session = '$session' AND semester = 1");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}


//function to get total sum of money paid for pre nce of courses a student carried per semester
function get_total_amount_paid_applicants_prence($mode , $pt , $sess )
{
	$result = mysql_query("SELECT SUM(amount-165) AS summed_up FROM applicants_nce_fee_payments
				WHERE programme_type_id = '$pt' AND session = '$sess' AND mode = '$mode'");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}
//function to get total sum of money paid for pre nce of courses a student carried per semester
function get_total_amount_paid_screening_prence($mode , $pt , $sess )
{
	$result = @mysql_query("SELECT SUM(amount-165) AS summed_up FROM  app_nce_screening_fee_payments
				WHERE programme_type_id = '$pt' AND session = '$sess' AND mode = '$mode'");
	$row = @mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}
//function to get total sum of money paid for pre nce of courses a student carried per semester
function get_total_amount_paid_applicants_prence_jdlab($mode , $pt , $sess )
{
	$result = mysql_query("SELECT SUM(165) AS summed_up FROM applicants_nce_fee_payments
				WHERE programme_type_id = '$pt' AND session = '$sess' AND mode = '$mode'");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}
//function to get total sum of money paid for pre nce of courses a student carried per semester
function get_total_amount_paid_applicants_deg( $sess )
{
	$result = mysql_query("SELECT SUM(amount-165) AS summed_up FROM applicants_nce_fee_payments
				WHERE session = '$sess' ");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}
function get_total_amount_paid_acc_fee_deg( $sess )
{
	$result = mysql_query("SELECT SUM(amount-165) AS summed_up FROM acceptance_nce_fee_payments
				WHERE session = '$sess' ");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}
//function to get total sum of money paid for pre nce of courses a student carried per semester
function get_total_amount_paid_students_nce( $pt , $sess )
{
	$result = mysql_query("SELECT SUM(amount) AS summed_up FROM school_fee_payments_nce
				WHERE programme_type_id = '$pt' AND session = '$sess' ");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}
function get_total_amount_paid_screening_nce( $pt , $sess )
{
	$result = @mysql_query("SELECT SUM(amount-165) AS summed_up FROM app_nce_screening_fee_payments
				WHERE programme_type_id = '$pt' AND session = '$sess' ");
	$row = @mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}
//function to get total sum of money paid for pre nce of courses a student carried per semester
function get_total_amount_paid_applicants_nce_jdlab( $pt , $sess )
{
	$result = mysql_query("SELECT SUM(165) AS summed_up FROM applicants_nce_fee_payments
				WHERE programme_type_id = '$pt' AND session = '$sess' ");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}

function get_total_amount_paid_applicants_deg_jdlab( $sess )
{
	$result = mysql_query("SELECT SUM(165) AS summed_up FROM applicants_nce_fee_payments
				WHERE session = '$sess' ");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}

function get_total_amount_paid_acc_fee_deg_jdlab( $sess )
{
	$result = mysql_query("SELECT SUM(165) AS summed_up FROM acceptance_nce_fee_payments
				WHERE session = '$sess' ");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}

//function to get total sum of money paid for pre nce of courses a student carried per semester
function get_total_amount_paid_applicants_nce_lvsp( $pt , $mode, $sess )
{
	$result = mysql_query("SELECT SUM(amount-165) AS summed_up FROM applicants_nce_fee_payments
				WHERE programme_type_id = '$pt' AND session = '$sess' AND mode = '$mode' ");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}



//function to get total sum of money paid for summer applicants
function get_total_amount_paid_applicants_nce_summer( $pt , $mode, $sess )
{
	$result = mysql_query("SELECT SUM(amount-480) AS summed_up FROM summer_application_fee_payments
				WHERE session = '$sess'");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}



//function to get total sum of money paid for pre nce of courses a student carried per semester
function get_total_amount_paid_screening_nce_lvsp( $pt , $mode, $sess )
{
	$result = @mysql_query("SELECT SUM(amount-165) AS summed_up FROM app_nce_screening_fee_payments
				WHERE programme_type_id = '$pt' AND session = '$sess' AND mode = '$mode' ");
	$row = @mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}

//function to get total sum of money paid for pre nce of courses a student carried per semester
function get_total_amount_paid_applicants_nce_lvsp_jdlab( $pt , $mode, $sess )
{
	$result = mysql_query("SELECT SUM(165) AS summed_up FROM applicants_nce_fee_payments
				WHERE programme_type_id = '$pt' AND session = '$sess' AND mode = '$mode' ");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}

//function to get total sum of money paid for pre nce of courses a student carried per semester
function get_total_amount_paid_per_session_prence_per_spons($session, $sp)
{
	$result = mysql_query("SELECT SUM(amount) AS summed_up FROM school_fee_payments_prence WHERE  session = '$session' AND sponsorship_type = '$sp' AND semester = 1  AND `added_by` LIKE 'ghost'");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}




//function to get total sum of money paid for nce of courses a student carried per semester
function get_total_amount_paid_per_session_nce($session)
{
	$result = mysql_query("SELECT SUM(amount) AS summed_up FROM school_fee_payments_nce WHERE  session = '$session' AND semester = 1");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}


//function to get total sum of money paid for nce of courses a student carried per semester
function get_total_amount_paid_per_session_deg($session)
{
	$result = mysql_query("SELECT SUM(amount) AS summed_up FROM school_fee_payments_nce WHERE  session = '$session'");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}

//function to get total sum of money paid for nce of courses a student carried per semester
function get_total_amount_paid_per_session_appfee($session)
{
	$result = mysql_query("SELECT SUM(amount) AS summed_up FROM acceptance_nce_fee_payments WHERE  session = '$session'");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}


//function to get total sum of money paid for  nce of courses a student carried per semester
function get_total_amount_paid_per_session_nce_per_spons($session, $sp)
{
	$result = mysql_query("SELECT SUM(amount) AS summed_up FROM school_fee_payments_nce WHERE  session = '$session' AND sponsorship_type = '$sp' AND semester = 1 AND `added_by` LIKE 'ghost'");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}


//function to get total sum of money paid for nce summer of courses a student carried per semester
function get_total_amount_paid_per_session_nce_summer($session)
{
	$result = mysql_query("SELECT SUM(amount) AS summed_up FROM summer_school_fee_payments_nce WHERE  session = '$session'");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}



//function to get total sum of money paid for  prence of courses a studer
function get_total_amount_paid_per_session_deg_per_programme($session,  $p)
{
	$result = mysql_query("SELECT SUM(amount) AS summed_up FROM school_fee_payments_nce WHERE  session = '$session' AND programme_id = '$p'  AND semester = 1");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}
//function to get total sum of money paid for  prence of courses a studer$pt = 1 , $mode = 1, $sess = 4
function get_total_amount_paid_applicants_deg_per_programme($session, $p  )
{
	$result = mysql_query("SELECT SUM(amount-165) AS summed_up FROM applicants_nce_fee_payments WHERE  session = '$session' AND programme_id = '$p'");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}

function get_total_amount_paid_acc_fee_deg_per_programme($session, $p  )
{
	$result = mysql_query("SELECT SUM(amount-165) AS summed_up FROM acceptance_nce_fee_payments WHERE  session = '$session' AND programme_id = '$p'");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}
function get_total_amount_paid_app_screening_prence_per_programme($session, $pt , $p ,$md )
{
	$result = mysql_query("SELECT SUM(amount-165) AS summed_up FROM app_nce_screening_fee_payments WHERE  session = '$session' AND programme_id = '$p' AND programme_type_id = '$pt' and mode = '$md'");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}
//function to get total sum of money paid for  prence of courses a studer$pt = 1 , $mode = 1, $sess = 4
function get_total_amount_paid_applicants_nce_per_programme($session, $pt , $p  )
{
	$result = mysql_query("SELECT SUM(amount-165) AS summed_up FROM applicants_nce_fee_payments WHERE  session = '$session' AND programme_id = '$p' AND programme_type_id = '$pt' ");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}

//function to get total sum of money paid for  prence of courses a studer$pt = 1 , $mode = 1, $sess = 4
function get_total_amount_paid_screening_nce_per_programme($session, $pt , $p  )
{
	$result = mysql_query("SELECT SUM(amount-165) AS summed_up FROM app_nce_screening_fee_payments WHERE  session = '$session' AND programme_id = '$p' AND programme_type_id = '$pt' ");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}

//function to get total sum of money paid for  prence of courses a studer$pt = 1 , $mode = 1, $sess = 4
function get_total_amount_paid_applicants_nce_lvsp_per_programme($session, $pt , $p, $md )
{
	$result = mysql_query("SELECT SUM(amount-165) AS summed_up FROM applicants_nce_fee_payments WHERE  session = '$session' AND programme_id = '$p' AND programme_type_id = '$pt' AND mode = '$md'");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}


//function to get total sum of money paid for nce of courses a studer
function get_total_amount_paid_per_session_nce_per_programme($session, $pt , $p)
{
	$result = mysql_query("SELECT SUM(amount) AS summed_up FROM school_fee_payments_nce WHERE  session = '$session' AND programme_id = '$p' AND programme_type_id = '$pt' AND semester = 1");
	$row = mysql_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}



//get list of the programmes for students payments reports
function  get_programme_list_for_students_payments_report_deg($ses,$yr)
{
	$result = mysql_query("SELECT * FROM programmes ");


	//if(mysql_num_rows($result>0))
//	{
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			echo '<a href="gateway.php?act=view_students_per_course&a='.sha1('fucku').'&pt='.$row['type_id'].'&p='.$row['id'].'&yr='.$yr.'" class="btn btn-success  btn-lg" target="_blank" style="margin:4px;" >'.$row['title'].' - <span class="badge">N'.number_format(get_total_amount_paid_per_session_deg_per_programme($ses,$row['id'])).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}

//get list of the programmes for students payments reports
function  get_programme_list_for_applicants_payments_report_prence___($pt, $md, $ses)
{
	$result = mysql_query("SELECT * FROM programmes WHERE type_id = '$pt'");


	//if(mysql_num_rows($result>0))
//	{
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			echo '<a href="gateway.php?act=view_students_per_course&a='.sha1('fucku').'&pt='.$row['type_id'].'&p='.$row['id'].'" class="btn btn-success  btn-lg" target="_blank" style="margin:4px;" >'.$row['title'].' - <span class="badge">N'.number_format(get_total_amount_paid_applicants_prence_per_programme($ses, $pt, $row['id'],  $md)).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}

//get list of the programmes for students payments reports
function  get_programme_list_for_applicants_payments_report_deg($ses)
{
	$result = mysql_query("SELECT * FROM programmes ");


	//if(mysql_num_rows($result>0))

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

					  <th>Programme</th>
					  <th>Amount</th>




		  </thead>

		  <tfoot>


			  <th>Programme</th>
			  <th>Amount</th>



		  </tfoot>

		  <tbody>';

	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
			$output .= "<tr>";
			$output .= '<td><a href="gateway.php?act=view_applicants_per_course&a='.sha1("fucku").'&pt='.$row["type_id"].'&p='.$row['id'].'&ses='.$ses.'"class="" target="_blank" style="margin:4px;" >'.$row['title']
			."</a></td>"; //group belong to admin or user
			$output .= '<td><span class="badge">N'.number_format(get_total_amount_paid_applicants_deg_per_programme($ses)).'</span></td>';
			$output .= "</tr>";


	}


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





	return $output;

}

//get list of the programmes for students payments reports
function  get_programme_list_for_acc_fee_payments_report_deg($ses)
{
	$result = mysql_query("SELECT * FROM programmes ");


	//if(mysql_num_rows($result>0))

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

					  <th>Programme</th>
					  <th>Amount</th>




		  </thead>

		  <tfoot>


			  <th>Programme</th>
			  <th>Amount</th>



		  </tfoot>

		  <tbody>';

	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
			$output .= "<tr>";
			$output .= '<td><a href="gateway.php?act=view_acc_fee_per_course&a='.sha1("fucku").'&pt='.$row["type_id"].'&p='.$row['id'].'&ses='.$ses.'"class="" target="_blank" style="margin:4px;" >'.$row['title']
			."</a></td>"; //group belong to admin or user
			$output .= '<td><span class="badge">N'.number_format(get_total_amount_paid_acc_fee_deg_per_programme($ses,$row['id'])).'</span></td>';
			$output .= "</tr>";


	}


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





	return $output;

}

//get list of the programmes for students payments reports
function  get_programme_list_for_app_screening_payments_report_prence($pt, $md, $ses)
{
	$result = mysql_query("SELECT * FROM programmes WHERE type_id = '$pt'");


	//if(mysql_num_rows($result>0))

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

					  <th>Programme</th>
					  <th>Amount</th>




		  </thead>

		  <tfoot>


			  <th>Programme</th>
			  <th>Amount</th>



		  </tfoot>

		  <tbody>';

	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
			$output .= "<tr>";
			$output .= '<td><a href="gateway.php?act=view_applicants_per_course&a='.sha1("fucku").'&pt='.$row["type_id"].'&p='.$row['id'].'&ses='.$ses.'"class="" target="_blank" style="margin:4px;" >'.$row['title']
			."</a></td>"; //group belong to admin or user
			$output .= '<td><span class="badge">N'.number_format(get_total_amount_paid_app_screening_prence_per_programme($ses, $pt, $row["id"],  $md)).'</span></td>';
			$output .= "</tr>";


	}


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





	return $output;

}

//get list of the programmes for students payments reports
function  get_programme_list_for_applicants_payments_report_nce($pt,$ses)
{
	$result = mysql_query("SELECT * FROM programmes WHERE type_id = '$pt' AND mode = '1'");


	//if(mysql_num_rows($result>0))

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

					  <th>Programme</th>
					  <th>Amount</th>




		  </thead>

		  <tfoot>


			  <th>Programme</th>
			  <th>Amount</th>



		  </tfoot>

		  <tbody>';

	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
			$output .= "<tr>";
			$output .= '<td><a href="gateway.php?act=view_applicants_per_course&a='.sha1("fucku").'&pt='.$row["type_id"].'&p='.$row['id'].'&ses='.$ses.'"class="" target="_blank" style="margin:4px;" >'.$row['title']
			."</a></td>"; //group belong to admin or user
			$output .= '<td><span class="badge">N'.number_format(get_total_amount_paid_screening_nce_per_programme($ses, $pt, $row["id"])).'</span></td>';
			$output .= "</tr>";


	}


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





	return $output;

}
//get list of the programmes for students payments reports
function  get_programme_list_for_screening_payments_report_nce($pt,$ses)
{
	$result = mysql_query("SELECT * FROM programmes WHERE type_id = '$pt' AND mode = '1'");


	//if(mysql_num_rows($result>0))

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

					  <th>Programme</th>
					  <th>Amount</th>




		  </thead>

		  <tfoot>


			  <th>Programme</th>
			  <th>Amount</th>



		  </tfoot>

		  <tbody>';

	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
			$output .= "<tr>";
			$output .= '<td><a href="gateway.php?act=view_applicants_per_course&a='.sha1("fucku").'&pt='.$row["type_id"].'&p='.$row['id'].'&ses='.$ses.'"class="" target="_blank" style="margin:4px;" >'.$row['title']
			."</a></td>"; //group belong to admin or user
			$output .= '<td><span class="badge">N'.number_format(get_total_amount_paid_screening_nce_per_programme($ses, $pt, $row["id"])).'</span></td>';
			$output .= "</tr>";


	}


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





	return $output;

}
//get list of the programmes for students payments reports
function  get_programme_list_for_applicants_payments_report_nce_lvsp($pt, $ses, $md)
{
	$result = mysql_query("SELECT * FROM programmes WHERE type_id = '$pt' AND mode = '$md'");


	//if(mysql_num_rows($result>0))

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

					  <th>Programme</th>
					  <th>Amount</th>




		  </thead>

		  <tfoot>


			  <th>Programme</th>
			  <th>Amount</th>



		  </tfoot>

		  <tbody>';


		  $ses_lvsp = 0 ;
	while($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{

			$output .= "<tr>";
			$output .= '<td><a href="gateway.php?act=view_applicants_per_course&a='.sha1("fucku").'&pt='.$row["type_id"].'&p='.$row['id'].'&ses='.$ses_lvsp .'"class="" target="_blank" style="margin:4px;" >'.$row['title']
			."</a></td>"; //group belong to admin or user
			$output .= '<td><span class="badge">N'.number_format(get_total_amount_paid_applicants_nce_lvsp_per_programme($ses, $pt, $row["id"], $md)).'</span></td>';
			$output .= "</tr>";


	}


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





	return $output;

}



//get list of the programmes for students payments reports
function  get_programme_list_for_students_payments_report_nce($pt, $ses, $yr)
{
	$result = mysql_query("SELECT * FROM programmes WHERE type_id = '$pt' AND mode='1'");


	//if(mysql_num_rows($result>0))
//	{
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			echo '<a href="gateway.php?act=view_students_per_course_nce&a='.sha1('fucku').'&pt='.$row['type_id'].'&p='.$row['id'].'&yr='.$yr.'" class="btn btn-success  btn-lg" target="_blank" style="margin:4px;" >'.$row['title'].' - <span class="badge">N'.number_format(get_total_amount_paid_per_session_nce_per_programme($ses,$pt,$row['id'])).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}
//Functions to fetch user's utme score
	function get_applicant_jamb_score($user_id)
	{
		$result = mysql_query("SELECT jamb_score FROM applicants_nce WHERE id = '$user_id'");
		$row = mysql_fetch_assoc($result);
		$jamb_score = $row['jamb_score'];

		if ($jamb_score) {
				return $jamb_score;

			}else{
				return false;
			}
	}


	//Functions to fetch user's prence no
	function get_applicant_prence_no($user_id)
	{
		$result = mysql_query("SELECT prence_no FROM applicants_nce WHERE id = '$user_id'");
		$row = mysql_fetch_assoc($result);
		$prence_no = $row['prence_no'];

		if ($prence_no) {
				return $prence_no;

			}else{
				return false;
			}
	}

	//Functions to fetch user's utme no
	function get_applicant_jamb_no($user_id)
	{
		$result = mysql_query("SELECT jamb_no FROM applicants_nce WHERE id = '$user_id'");
		$row = mysql_fetch_assoc($result);
		$jamb_no = $row['jamb_no'];

		if ($jamb_no) {
			return $jamb_no;

		}else{
			return false;
		}
	}

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


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


		return $v;
	}
//Functions to fetch user's first name
	function get_user_first_name($user_id)
	{
		$result = mysql_query("SELECT first_name FROM applicants_nce WHERE id = '$user_id'");
		$row = mysql_fetch_assoc($result);
		$first_name = $row['first_name'];


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


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


		return $v;
	}

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


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


		return $v;
	}

//function fetch user programme admitted into
	function get_user_programme_admitted_to($id)
	{
		$result = mysql_query("SELECT programme_id FROM applicants_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['programme_id'];


		return $v;
	}

	function get_student_programme_admitted_to($id)
	{
		$result = mysql_query("SELECT programme_id FROM students_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['programme_id'];


		return $v;
	}

//function select subjects
function show_subjects_title($id)
{
	$r = mysql_query("SELECT title  FROM o_level_subjects
					WHERE id = '$id' ");
	$row = mysql_fetch_assoc($r);
	$v = $row['title'];

	return $v;

}
//end of select subjects
//function select highest qualification
function show_subject_grade($hiq)
{

		if ($hiq == '1')
		{

			$output .=  "A1";






		}
		else if ($hiq == '2')
		{
			$output .=  "B2";

		}
		else if ($hiq == '3')
		{
			$output .=  "B3";

		}
		else if ($hiq == '4')
		{
			$output .=  "C4";

		}
		else if ($hiq == '5')
		{
			$output .=  "C5";

		}
		else if ($hiq == '6')
		{
			$output .=  "C6";

		}
		else if ($hiq == '7')
		{
			$output .=  "D7";

		}
		else if ($hiq == '8')
		{
			$output .=  "E8";

		}
		else if ($hiq == '9')
		{
			$output .=  "F9";

		}
		else if ($hiq == '10')
		{
			$output .=  "AR";

		}
		else
		{
			$output .=  "";


		}
	return $output;

}


function get_applicant_olevel($id,$ty)
{
		$olevel_str = '';


		//$sub_and_grd_1 ='';

		$q = "SELECT * FROM `applicants_olevel_nce`
				WHERE applicant_id = '$id' AND type = '$ty'";

		$r = mysql_query($q);

		if(mysql_num_rows($r) > 0 ){
			$rec = mysql_fetch_array($r,MYSQL_ASSOC);
			$sub_grd1 = '<b class=" badge"> Exam Type: '.$rec['exam_type'].'</b><br>';
			$sub_grd1 .= '<span class="list-group-item"><b>Exam No: '.$rec['exam_no'].'</b></span>';
			$sub_grd1 .= '<span class="list-group-item"><b>Exam Month: '.show_month($rec['exam_month']).'</b></span>';
			$sub_grd1 .= '<span class="list-group-item"><b>Exam Year: '.$rec['exam_year'].'</b></span>';
			$sub_grd1 .= '<span class="list-group-item"><b>Pin: '.$rec['card_pin'].'</b></span>';
			$sub_grd1 .= '<span class="list-group-item"><b>Pin S/NO: '.$rec['card_sno'].'</b></span>';
			//initializing variables to prevent errors
			for ($i = 1 ; $i < 10; $i++) {
				$sb = '';
				$gr = '';

				//passing values to new variable
				$sb = 'subject'. $i;
				$gr = 'grade'. $i;
				//fetching records
				$sb_val =  $rec[$sb];
				$gr_val =  $rec[$gr];

				if ($sb_val !='') {

					$sub_grd2 .= '<span  class="list-group-item">'.show_subjects_title($sb_val) . '<b class="badge pull-right">'. show_subject_grade($gr_val).'</b></span >';

				}

				$olevel_str .= $sub_grd2;


			}

		}


		$olevel_str = $sub_grd1.$sub_grd2;

		if ($olevel_str !== '') {
			//return $qi = 1;
			return $olevel_str;
		}else{

			return '<li class="list-group-item text-danger">NIL</li>';
		}


}

function block_user($user_id)
{
	$block_user = [11,12,13];//ids of users to block

	if (in_array($user_id, $block_user)) {
    	return true;

	}else{
	    return false;
	}
}



?>
