<?php
//session_start();

//require_once('configuration.php');
require_once('../db_connect/db.php');

//instantiating Config Class
function dbc()
{
	global $conn_1;

	return $conn_1;
}

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


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 check and show is payment status is paid or not


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

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


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

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

  }



} // end of browser / platform filter



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

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

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


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

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



		return $at;



}





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


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

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


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


			}



}


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

	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $query);
	$row = mysqli_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);

	return $row['last_logout'];
}


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


	return $v;
}

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


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


	return $v;
}


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

	return $row['application_number'];

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

	if(mysqli_num_rows($result)>0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
//
// function that check if a applicant application number exist in stduents table or not
function applicant_id_exist_payments_acc_fees($user_id)
{
	$result = mysqli_query(dbc(), "SELECT student_id FROM hostel_fee_payments WHERE student_id = '$user_id'");
	//$row = mysql_fetch_assoc($result);
	//$an = $row['applicant_id'];

	if(mysqli_num_rows($result)>0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
//end of application no exist
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 dat get usergroup by id type
function get_user_groupid($user_id)
{
	$q = "SELECT group_id FROM users WHERE user_id = '$user_id' ";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);

	return $row['group_title'];


}


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

	return $row['header_menu'];


}



//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 = mysqli_query(dbc(), $q);
	$row = mysqli_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 = mysqli_query(dbc(), $q);
	$row = mysqli_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);

	return $row['last_login_ip'];


}




//function get total users online
function get_total_online_visitors()
{
	$noov = mysqli_num_rows(mysqli_query(dbc(), "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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

	$row = mysqli_fetch_array($r, MYSQLI_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 = mysqli_query(dbc(), $q);

	$row = mysqli_fetch_array($r, MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_num_rows($r)>0)
	{
		while($row = mysqli_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 = mysqli_query(dbc(), $q);

	if(mysqli_num_rows($r)>0)
	{
		while($row = mysqli_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);

	return $row['security_id'];


}

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

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

	mysql_query("UPDATE 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 = mysqli_query(dbc(), "SELECT * FROM sessions WHERE current_session = '$id'");
		$row = mysqli_fetch_assoc($result);
		$id = $row['id'];

	return $id;
	}


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

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



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

	return $id;
	}


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

	return $title;
	}




	//function 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 = mysqli_connect($host,$user,$pass);
    mysqli_select_db($name,$link);
    mysqli_query($link, "SET NAMES 'utf8'");

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

    //cycle through
    foreach($tables as $table)
    {
        $result = mysqli_query(dbc(), 'SELECT * FROM '.$table);
        $num_fields = mysqli_num_fields($result);

        $return.= 'DROP TABLE '.$table.';';
        $row2 = mysqli_fetch_row(mysqli_query(dbc(), 'SHOW CREATE TABLE '.$table));
        $return.= "\n\n".$row2[1].";\n\n";

        for ($i = 0; $i < $num_fields; $i++)
        {
            while($row = mysqli_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 = mysqli_query(dbc(), $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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);





	if(mysqli_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 = mysqli_fetch_array($r, MYSQLI_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())";
	mysqli_query(dbc(), $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 = mysqli_query(dbc(), $query);










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


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

					  <th>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 = mysqli_fetch_array($result,MYSQLI_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" /> Manage Staffs<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">
						<strong>&nbsp;&nbsp;&nbsp;Hostel Management&nbsp;&nbsp;</strong><b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="gateway.php?act=view_hostel_sites"><img src="images/faculties-small.png">&nbsp;&nbsp;&nbsp;&nbsp;Hostel Sites</a></li>
							<li><a href="gateway.php?act=view_hostel_rooms"><img src="images/departments-small.png">&nbsp;&nbsp;Hostel Rooms</a></li>
							<li><a href="gateway.php?act=view_hostel_categories"><img src="images/courses-small.png">&nbsp;&nbsp;&nbsp;Hostel Categories</a></li>
							<li><a href="gateway.php?act=view_allocated_students"><img src="images/programmes-courses-small.png">&nbsp;&nbsp;&nbsp;Manage Allotees</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_fin_reports">&nbsp;&nbsp;Applicants FIN MAN </a></li> -->
	 <!--  <li><a href="gateway.php?act=view_students_payments_b"><img src="images/departments-small.png">students_nce Payments Confirmation</a></li>--->

	  <li><a href="gateway.php?act=view_r_log_app_fees"><img src="images/remitalogosmaller.jpg">Remita Trans. Log (Hostel 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>
								<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>';


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



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


	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 view_students()
{

	$user_id = get_user_id();

	//query the database
	$q = "SELECT id, address, CONCAT_WS(' ', first_name, other_names) as name, phone_no,
	gender, DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, validity_status,
	number, email, level


		 FROM students_nce WHERE hostel_eligibility ='1' ORDER BY number DESC ";
	$r = mysqli_query(dbc(), $q) ;



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


	if(mysqli_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> Address </th>
						<th>Matric Number</th>
						<th>Active</th>
						<th>Phone Number</th>
						<th>Email</th>
						<th>Gender</th>
						<th>Level</th>
						<th>Registration Date</th>

				</thead>



				<tfoot>
				   		<th > </th>
							<th>Name</th>
							<th> Address </th>
							<th>Matric Number</th>
							<th>Active</th>
							<th>Phone Number</th>
							<th>Email</th>
							<th>Gender</th>
							<th>Level</th>
							<th>Registration Date</th>
				</tfoot>

				<tbody>';



		while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['name']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['address']."</td>";
			$output .= "<td>".$row['number']."</td>";
			$output .= "<td>". user_status_img($row['validity_status'])."</td>";
			$output .= "<td>".$row['phone_no']."</td>";
			$output .= "<td>".$row['email']."</td>";
			$output .= "<td>".$row['gender']."</td>";
			$output .= "<td>".$row['level']."</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 view_hostel_site()
{

	$user_id = get_user_id();

	//query the database
	$q = "SELECT id, title, description, published,
	 DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, status, modified_by,
	added_by, DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as date_modified
	FROM hostel_campuses WHERE status='1' ORDER BY date_added DESC ";
	$r = mysqli_query(dbc(), $q);



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


	if(mysqli_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>title</th>
						<th> Description </th>
						<th>Published</th>
						<!----<th>Trashed</th>--->
						<th>Date added</th>
						<th>Added by</th>
						<th>Date modified</th>
						<th>Modiefied By</th>
						<th>Status</th>

				</thead>



				<tfoot>
				   		<th > </th>
							<th>title</th>
							<th> Description </th>
							<th>Published</th>
							<!----<th>Trashed</th>--->
							<th>Date added</th>
							<th>Added by</th>
							<th>Date modified</th>
							<th>Modified By</th>
							<th>Status</th>
				</tfoot>

				<tbody>';



		while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
		{
			$publish = $row['published'];
			if ($publish == 1)
			{
				$publish = 'Published';
			}else
			{
				$publish = 'Unpublished';
			}

			$status = $row['status'];
			if ($status == 0)
			{
				$status = 'Delected';
			}else if ($status == 1)
			{
				$status = 'Active';
			}else{
				$status = 'Achieve';
			}
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$publish."</td>";
			//$output .= "<td>".$row['trashed']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$status."</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 sites

function view_hostel_rooms()
{

	$user_id = get_user_id();

	//query the database
	$q = "SELECT hostel_rooms.id AS id, hostel_rooms.title AS title, hostel_rooms.description AS description,
	hostel_rooms.modified_by AS modified_by,  hostel_campuses.title AS hostel_site,hostel_blocks.title AS hostel_categories,
	hostel_rooms.bed_space AS bedspace, DATE_FORMAT(hostel_rooms.date_added, '%b %e, %Y  %l:%i:%p') as date_added,
	hostel_rooms.added_by AS added_by, DATE_FORMAT(hostel_rooms.date_modified, '%b %e, %Y  %l:%i:%p') as date_modified
	FROM hostel_rooms,hostel_campuses,hostel_blocks WHERE hostel_rooms.campus_id=hostel_campuses.id AND
	hostel_rooms.block_id= hostel_blocks.id AND hostel_rooms.status='1' AND hostel_rooms.status='1' ORDER BY date_added DESC ";
	$r = mysqli_query(dbc(), $q);



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


	if(mysqli_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>title</th>
						<th> Description </th>
						<th>Hostel Site</th>
						<th>Hostel Categories</th>
						<th>Bedspace</th>
						<th>Added By</th>
						<th>Date Added</th>
						<th>Date modified</th>
						<th>Modified By</th>


				</thead>



				<tfoot>
				   		<th > </th>
							<th>title</th>
							<th> Description </th>
							<th>Hostel Site</th>
							<th>Hostel Categories</th>
							<th>Bedspace</th>
							<th>Added By</th>
							<th>Date Added</th>
							<th>Date modified</th>
							<th>Modified By</th>

				</tfoot>

				<tbody>';



		while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['hostel_site']."</td>";
			$output .= "<td>".$row['hostel_categories']."</td>";
			$output .= "<td>".$row['bedspace']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</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 categories

function view_hostel_categories()
{

	$user_id = get_user_id();

	//query the database
	$q = "SELECT hostel_blocks.id AS id, hostel_blocks.title AS title,
	hostel_blocks.description AS description, hostel_blocks.campus_id AS hostel_site,
	hostel_blocks.bed_space AS bed_space, hostel_blocks.gender AS gender,hostel_blocks.hostel_amount AS hostel_amount,
	hostel_campuses.title AS titles,
	 DATE_FORMAT(hostel_blocks.date_added, '%b %e, %Y  %l:%i:%p') as date_added, hostel_blocks.status AS status,
	hostel_blocks.added_by AS added_by, DATE_FORMAT(hostel_blocks.date_modified, '%b %e, %Y  %l:%i:%p') as date_modified,
	hostel_blocks.modified_by AS modified_by
	FROM hostel_campuses,hostel_blocks WHERE hostel_blocks.campus_id= hostel_campuses.id AND hostel_blocks.trashed='0'
	AND hostel_blocks.status='1' ORDER BY date_added DESC ";
	$r = mysqli_query(dbc(), $q);



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


	if(mysqli_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>title</th>
						<th> Description </th>
						<th>Hostel Site</th>
						<th>Gender</th>
						<th>Bedspace</th>
						<th>Added By</th>
						<th>Date Added</th>
						<th>Date modified</th>
						<th>Modified By</th>


				</thead>



				<tfoot>
				   		<th > </th>
							<th>title</th>
							<th> Description </th>
							<th>Hostel Site</th>
							<th>Gender</th>
							<th>Bedspace</th>
							<th>Added By</th>
							<th>Date Added</th>
							<th>Date modified</th>
							<th>Modified By</th>

				</tfoot>

				<tbody>';



		while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['titles']."</td>";
			$output .= "<td>".$row['gender']."</td>";
			$output .= "<td>".$row['bed_space']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			//$output .= "<td>".$row['status']."</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 categories


//function that get trashed  users informatn
function view_trashed_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,  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 = mysqli_query(dbc(), $q);






	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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

//function that get trashed  users informatn
function view_trashed_hostel_site()
{
$user_id = get_user_id();
	//query the database
	$q = " SELECT id,title, description, published,
			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 hostel_campuses WHERE status='2' ORDER BY date_added DESC ";
	$r = mysqli_query(dbc(), $q);






	if(mysqli_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>Title</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Added By</th>
						<th>Date Modified</th>
						<th> Modified By</th>
						<th>

				</thead>



				<tfoot>
				   		<th > </th>
							<th>Title</th>
							<th>Description</th>
							<th>Date Added</th>
							<th>Added By</th>
							<th>Date Modified</th>
							<th> Modified By</th>
							<th></th>
				</tfoot>

				<tbody>';



		while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
		//	$output .= "<td>".$row['date_deleted']."</td>";
			//$output .= '<td><a class="btn btn-success btn-sm pull-right restore_site" 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 users


//function that get trashed  hostel categories informatn
function view_trashed_hostel_categories()
{
$user_id = get_user_id();
	//query the database
	$q = " SELECT id,title, description,bed_space, gender,status,hostel_amount,
			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 hostel_blocks WHERE trashed='1' ORDER BY date_added DESC ";
	$r = mysqli_query(dbc(), $q);






	if(mysqli_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>Title</th>
						<th>Description</th>
						<th>BedSpace</th>
						<th>Gender</th>
						<th>Date Added</th>
						<th>Added By</th>
						<th>Date Modified</th>
						<th> Modified By</th>
						<th>Amount</th>

						<th>

				</thead>



				<tfoot>
				   		<th > </th>
							<th>Title</th>
							<th>Description</th>
							<th>BedSpace</th>
							<th>Gender</th>
							<th>Date Added</th>
							<th>Added By</th>
							<th>Date Modified</th>
							<th> Modified By</th>
							<th>Amount</th>

						<th></th>
				</tfoot>

				<tbody>';



		while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['bed_space']."</td>";
			$output .= "<td>".$row['gender']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['hostel_amount']."</td>";
			//$output .= '<td><a class="btn btn-success btn-sm pull-right restore_category" 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 users


//function that get trashed  users informatn
function view_trashed_hostel_rooms()
{
$user_id = get_user_id();
	//query the database
	$q = " SELECT id,title, description, published, bed_space, reserved,

			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 hostel_rooms WHERE status='2' ORDER BY date_modified DESC ";
	$r = mysqli_query(dbc(), $q);






	if(mysqli_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>Title</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>BedSpace</th>
						<th>Reserve</th>
						<th>Added By</th>
						<th>Date Modified</th>
						<th> Modified By</th>

						<th>

				</thead>



				<tfoot>
				   		<th > </th>
							<th>Title</th>
							<th>Description</th>
							<th>Date Added</th>
							<th>BedSpace</th>
							<th>Reserve</th>
							<th>Added By</th>
							<th>Date Modified</th>
							<th> Modified By</th>

						<th></th>
				</tfoot>

				<tbody>';



		while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['bed_space']."</td>";
			$output .= "<td>".$row['reserved']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			//$output .= '<td><a class="btn btn-success btn-sm pull-right restore_room" 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 users


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

	//query the database
	$q = "SELECT id, address, CONCAT_WS(' ', first_name, other_names) as name, phone_no,
	gender, DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, validity_status,
	number, email, DATE_FORMAT(last_logout, '%b %e, %Y  %l:%i:%p') as last_logout


		 FROM hostel_studes WHERE validity_status=2 ORDER BY date_added DESC ";


	$r = mysqli_query(dbc(), $q);






	if(mysqli_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>Matric Number</th>
						<th>Phone Number</th>
						<th>Email</th>
						<th>Gender </th>
						<th>Registration Date</th>
						<th> Last Modified</th>

						<th>

				</thead>



				<tfoot>
				   		<th > </th>
							<th>Name</th>
							<th>Matric Number</th>
							<th>Phone Number</th>
							<th>Email</th>
							<th>Gender </th>
							<th>Registration Date</th>
							<th> Last Modified</th>
						<th></th>
				</tfoot>

				<tbody>';



		while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['name']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['number']."</td>";
			$output .= "<td>".$row['phone_no']."</td>";
			$output .= "<td>".$row['email']."</td>";
			$output .= "<td>".$row['gender']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['last_logout']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore" 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 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 = mysqli_query(dbc(), $q);





	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);





	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);



	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);



	if(mysqli_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 = mysqli_fetch_array($r,MYSQLi_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 = mysqli_query(dbc(), "SELECT role_id, role_title FROM roles  ORDER BY role_title");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), "SELECT user_group_id, title FROM user_groups  ORDER BY title");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $query);

	if(mysqli_num_rows($result) > 0 )
	{
		while ($row_carts = mysqli_fetch_array($result,MYSQLI_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 = mysqli_query(dbc(), $query);


	if(mysqli_num_rows($result) > 0 )
	{
		while ($row_carts = mysqli_fetch_array($result,MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $query);

	if(mysqli_num_rows($result) > 0 )
	{
		while ($row_carts = mysqli_fetch_array($result,MYSQLI_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 = mysqli_query(dbc(), $query);


	if(mysqli_num_rows($result) > 0 )
	{
		while ($row_carts = mysqli_fetch_array($result,MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query($q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLi_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 > PT Degree</option>';
			$output .= '<option value="2" > Diploma </option>';
			$output .= '<option value="3" > Certificate </option>';



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



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



		}
		else
		{

			$output = '<option value="0"  selected > -- Please Select --</option>';
			$output .= '<option value="1"> PT Degree</option>';
			$output .= '<option value="2" > Diploma </option>';
			$output .= '<option value="3" > Certificate </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 = mysqli_query($q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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
		 WHERE status = '0' OR status = '1'
		 GROUP BY token
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysqli_query(dbc(), $q);

	if(mysqli_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>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>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 = mysqli_fetch_array($r,MYSQLI_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>".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
		 WHERE status = '2'
		 GROUP BY token
		 ORDER BY date_trashed DESC";
	$r = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 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 = mysqli_query(dbc(), $q);

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



		  $output = '';

		while($row = mysqli_fetch_array($r,MYSQLI_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= mysqli_query(dbc(), "SELECT * FROM ip_filter WHERE ips='$ip'") or die(mysql_error()); //query
  if($query_ip){

    $row=mysqli_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 = mysqli_query(dbc(), $q);



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


	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);



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


	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);



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


	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);



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


	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), "SELECT * FROM lga WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$title = $row['title'];

	return $title;

}



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

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

			}


			echo $output;
		}
	}
	else
	{

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

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

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

	return $title;

}



//select programme
function select_programme($programme)
{
	$r = mysqli_query(dbc(), "SELECT id, title,type_id  FROM programmes  ORDER BY title");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r,MYSQLI_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



//select faculty
function select_faculty($faculty)
{
	$r = mysqli_query(dbc(), "SELECT id, title  FROM faculties  ORDER BY title");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
		{
			if($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 faculties


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

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

			}


			echo $output;
		}
	}
	else
	{

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

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


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

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

			}


			echo $output;
		}
	}
	else
	{

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

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










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

	return $title;
}


//get programme actual programme id passed by id of the course
function get_programme_actual_programme_id($id)
{
	$result = mysqli_query(dbc(), "SELECT school_id FROM programmes WHERE id = '$id'");
	$row = mysqli_fetch_assoc($result);
	$title = $row['school_id'];



	return $title;
}




//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 = mysqli_query(dbc(), "SELECT * FROM departments WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$title = $row['title'];

	return $title;

}


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

	return $title;

}

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

	return $code;

}



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

	return $code;

}




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





//function get total students_ncein a
function get_total_students()
{
	$q = "SELECT COUNT(id) FROM students_nce  WHERE validity_status = '0'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}

//function get total male  students
function get_total_male_students()
{
	$q = "SELECT COUNT(id) FROM students_nce  WHERE validity_status = '0' AND (gender = 'M' OR gender='Male')";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}

//function get total female students
function get_total_female_students()
{
	$q = "SELECT COUNT(id) FROM students_nce  WHERE validity_status = '0' AND (gender = 'F' OR gender='Female')";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}



//function get total level students_ncebase on id pass students
function get_total_students_per_level($l)
{
	$q = "SELECT COUNT(id) FROM students_nce  WHERE validity_status = '0' AND level = '$l'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}





//function get total students_ncein a department
function get_total_department_students($id)
{
	$q = "SELECT COUNT(id) FROM students_nce  WHERE validity_status = '0' AND department_id = '$id' AND validity_status = '0'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}



//function get total students_ncein a programme per programme type
function get_total_prog_type_students($pt,$p)
{
	$q = "SELECT COUNT(*) FROM students_nce  WHERE   type_id = '$pt'  AND programme_id = '$p' AND validity_status = '0'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}



//function get total students_ncein 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 department_id = '$d' AND programme_id = '$p' AND level = '$l' AND validity_status = '0'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}


//function get total students_ncein a programme type
function get_total_programme_type_students($id)
{
	$q = "SELECT COUNT(id) FROM students_nce WHERE  type_id = '$id' AND validity_status = '0'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}



//function get total department
function get_total_department()
{
	$q = "SELECT COUNT(id) FROM departments  WHERE status = '0'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}



//function get total programmes
function get_total_programmes()
{
	$q = "SELECT COUNT(id) FROM programmes  WHERE status = '0'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

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

		$output =  '';

		while($row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

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

		$output =  '';

		while($row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

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

		$output =  '';

		while($row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}







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

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

		$output =  '';

		while($row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

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

		$output =  '';

		while($row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

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

		$output =  '';

		while($row = mysqli_fetch_array($r,MYSQLI_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_nce online
function get_total_students_online()
{
	$q = "SELECT COUNT(id) FROM students_nce  WHERE online_status = '1'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q) or die (mysqli_error());




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

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);
	$v = $row['phone_number'];

	return $v;


}//end of function that shows applicant phone_number

//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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);
	$v = $row['email'];

	return $v;


}//end of function that shows applicant email


//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 = mysqli_query(dbc(), $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 = mysqli_query(dbc(), $q);
	$row = mysqli_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 = mysqli_query(dbc(), $q);
	$row = mysqli_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 = mysqli_query(dbc(), $q);
	$row = mysqli_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 = mysqli_query(dbc(), $q);
	$row = mysqli_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 = mysqli_query(dbc(), $q);


	if(mysqli_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 = mysqli_query(dbc(), "SELECT * FROM applicants_generate_serial_number");
	while($row = mysqli_fetch_array($result))
	{
		$g_code = $row['code'];
	}

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

	mysqli_query(dbc(), "UPDATE applicants_generate_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(dbc(), $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 = mysqli_query(dbc(), $q) or die(mysql_error(dbc()));

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

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

		while($row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

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

	return $v;
}


//function get total applicants
function get_total_applicants()
{
	$q = "SELECT COUNT(*) FROM hostel_fee_payments";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}

//function get total applicants
function get_all_total_applicants()
{
	$q = "SELECT COUNT(*) FROM students_nce";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}

//function get total applicants
function get_all_total_applicants4()
{
	$q = "SELECT COUNT(*) FROM summer_students";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}

//function get total applicants
function get_all_total_applicants5()
{
	$q = "SELECT COUNT(*) FROM students_nce";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}

//function get total applicants
function get_all_total_applicants2()
{
	$q = "SELECT COUNT(*) FROM students_prence";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}

//function get total applicants
function get_all_total_applicants3($conn_2)
{
	$q = "SELECT COUNT(*) FROM students_nce";
	$r = mysqli_query($conn_2, $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}
//function get total applicants
function get_total_applicants_paid()
{
	$q = "SELECT SUM(amount - 900) FROM hostel_fee_payments";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return number_format($row[0]);

}



//function get total applicants
function get_total_applicants_all()
{
	$q = "SELECT COUNT(*) FROM applicants";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}//function get total applicants
function get_upaid_total_applicants_app_fee()
{
	$q = "SELECT COUNT(app.id) FROM applicants app,  applicants_fee_payments  app_fees WHERE app.id != app_fees.applicant_id";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}

//function get total female applicants
function get_total_female_applicants()
{
	$q = "SELECT COUNT(id) FROM applicants  WHERE  gender = 'F' AND bank_epin !='' AND serial_number != ''";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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  WHERE  programme_type_applied_for = '$l' AND bank_epin !='' AND serial_number != ''";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}



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

	return $row[0];

}

//function get total applicants in a 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 = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}



//function get total applicants in a programme
function get_total_prog_type_programme_applicants($pt, $id)
{
	$q = "SELECT COUNT(id) FROM hostel_fee_payments  WHERE programme_type_id = '$pt' AND programme_id = '$id'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}

//function get total applicants in a programme
function get_total_prog_type_programme_applicants_paid($pt, $id)
{
	$q = "SELECT SUM(amount - 900) FROM applicants_fee_payments  WHERE programme_type_id = '$pt' AND programme_id = '$id'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return number_format($row[0]);

}



//function get total applicants in a programme type
function get_total_programme_type_applicants($id)
{
	$q = "SELECT COUNT(id) FROM applicants  WHERE  programme_type_applied_for = '$id' AND bank_epin !='' AND serial_number != ''";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}




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

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 = 'PRE-NCE';

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

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

		}
		else
		{

			$output = 'NIL';

		}

	return $output;

}
//end of show programme_type


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

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

		$output =  '';

		while($row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), $q);

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

		$output =  '';

		while($row = mysqli_fetch_array($r,MYSQLI_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 = mysqli_query(dbc(), "SELECT * FROM applicants WHERE type_id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$title = $row['title'];

	return $title;

}

//function get applicant image by passing id alone
function get_applicant_image($id)
{
	$result = mysqli_query(dbc(), "SELECT image FROM applicants WHERE id = '$id'");
	$row = mysqli_fetch_assoc($result);
	$image = $row['image'];




	if($image != '')
	{//show table



			$output = '<img class="img-responsive img-rounded img-thumbnail center-block" src="https://ibbuiceel.edu.ng/eportals/pd/uploads/'.$row['image'].'" style="height:100px ;width:80px"    />';


	}
	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 = mysqli_query(dbc(), $q);

	if(@mysqli_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 = mysqli_fetch_array($r,MYSQLI_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) // pt programm type , p programme
{


	//query the database
	$q = "SELECT students_nce.id, students_nce.school_id, students_nce.department_id,
				students_nce.programme_id, students_nce.application_number,
		 students_nce.state_id, students_nce.lga_id, students_nce.first_name, students_nce.other_names,
		 students_nce.phone_no,
		 students_nce.gender,  students_nce.email,
		  DATE_FORMAT(students_nce.date_added, '%M %d, %Y %l:%i:%p') as date_added,
		   hostel_fee_payments.student_id
		  FROM  students_nce, hostel_fee_payments

		  WHERE   students_nce.school_id = '$pt' AND
			students_nce.programme_id = '$p' AND students_nce.id = hostel_fee_payments.student_id

		  ORDER BY students_nce.number ASC";
	$r = mysqli_query(dbc(), $q);

	if(mysqli_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>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Admission Status</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>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Admission Status</th>

			</tfoot>

			<tbody>';

		while($row = mysqli_fetch_array($r,MYSQLI_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['programme_type_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>".is_admitted($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 per programmes



//function view applicants listings per programmes
function view_all_applicants($pt) // pt programm type , p programme
{


	//query the database
	$q = "SELECT id, programme_type_applied_for, department_applied_for,number, 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  students

		  WHERE   programme_type_applied_for = '$pt'

		  ORDER BY students.application_number ASC";
	$r = mysqli_query(dbc(), $q);

	if(mysqli_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>Matric No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>Applied For</th>
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>




			</thead>
			<tfoot>
						<th>Application No.</th>
						<th>Matric No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>Applied For</th>
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>

			</tfoot>

			<tbody>';

		while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td>".$row['application_number']."</td>";
				$output .= "<td>".$row['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>".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>".is_admitted($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;

}
//function view applicants listings per app fees payment
function view_all_paid_applicants_app_fees()
{


	//query the database
	$q = "SELECT app.id, app.programme_type_applied_for, app.department_applied_for, app.programme_applied_for, app.number,
		 app.state_id, app.lga_id, app.first_name, app.other_names, app.phone_no, app.gender,  app.email,
		  DATE_FORMAT(app.date_added, '%M %d, %Y %l:%i:%p') as date_added
		  FROM  students_nce app, hostel_fee_payments app_fees

		  WHERE   app_fees.student_id = app.id

		  ORDER BY app.number ASC";
	$r = mysqli_query(dbc(), $q);

	if(mysqli_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>State</th>
						<th>L.G.A</th>
						<th>Payments Status</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>State</th>
						<th>L.G.A</th>
						<th>Payments Status</th>

			</tfoot>

			<tbody>';

		while($row = mysqli_fetch_array($r,MYSQLI_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>".$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>".get_state_title($row['state_id'])."</td>";
			$output .= "<td>".get_lga_title($row['lga_id'])."</td>";
			$output .= "<td>".payment_status(1)."</td>";
			/*$output .= "<td>".get_applicant_image($row['id'])."</td>";
			$output .= "<td>".is_admitted($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 per programmes



//function view applicants listings per app fees payment
function view_all_not_allocated_students()
{


	//query the database
	$q = "SELECT CONCAT_WS(' ', first_name, other_names) as name, students_prence.id AS id,
	phone_no,number,gender,state.title AS state,lga.title AS lga,
	application_number, programmes.title AS programme, students_prence.level as LEVEL, students_prence.hostel_allocation='0'
	FROM state, lga, students_prence, programmes  WHERE students_prence.programme_id=programmes.id AND
	students_prence.state_id = state.id AND students_prence.lga_id = lga.id AND students_prence.hostel_allocation='0'
	ORDER BY number ASC ";
	$r = mysqli_query(dbc(), $q);

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

	$output_q =
	 '<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>Name</th>
	   <th>Matric Number</th>
	   <th>Phone Number</th>
	   <th>Level</th>
	   <th>Application Number</th>
	   <th>Gender</th>
	   <th>Programme</th>
	   <th>State</th>
	   <th>LGA</th>


	 </thead>
	 <tfoot>
	   <th>S/No</th>
	   <th>Name</th>
	   <th>Matric Number</th>
	   <th>Phone Number</th>
	   <th>Level</th>
	   <th>Application Number</th>
	   <th>Gender</th>
	   <th>Programme</th>
	   <th>State</th>
	   <th>LGA</th>


	 </tfoot>

	 <tbody>';

	 while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
	{
	  $output_q .= "<tr>";
		$output_q .= "<input type='hidden' value='1' name='type'/>";
		$output_q .= "<input type='hidden' value='".$row['id']."' name='user_id'/>";
	  $output_q .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
	  $output_q .= "<td> <a href='gateway.php?act=new_allocation&id=".$row['id']." && type_id=1'>".$row['name']."</a></td>"; //nam eof the user
	  $output_q .= "<td>".$row['number']."</td>";
	  $output_q .= "<td>".$row['phone_no']."</td>";
	  $output_q .= "<td>".$row['LEVEL']."</td>";
	  $output_q .= "<td>".$row['application_number']."</td>";
	  $output_q .= "<td>".$row['gender']."</td>";
	  $output_q .= "<td>".$row['programme']."</td>";

	  $output_q .= "<td>".$row['state']."</td>";
	  $output_q .= "<td>".$row['lga']."</td>";

	  $output_q .= "</tr>";



	}
	}
	else
	{//show the msg

	  $output_q =
	       '<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_q .=
	 '</tbody>
	   </table>';

	   echo $output_q;




}//end of view applicants listings per programmes

//function view applicants listings per app fees payment
function view_all_not_allocated_students2()
{


	//query the database
	$q = "SELECT CONCAT_WS(' ', first_name, other_names) as name, students_nce.id AS id,
	phone_no,number,gender,state.title AS state,lga.title AS lga,
	application_number, programmes.title AS programme, students_nce.level as LEVEL, students_nce.hostel_allocation='0'
	FROM state, lga, students_nce, programmes  WHERE students_nce.programme_id=programmes.id AND
	students_nce.state_id = state.id AND students_nce.lga_id = lga.id AND students_nce.hostel_allocation='0'
	ORDER BY number ASC ";
	$r = mysqli_query(dbc(), $q);

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

	$output_q =
	 '<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>Name</th>
	   <th>Matric Number</th>
	   <th>Phone Number</th>
	   <th>Level</th>
	   <th>Application Number</th>
	   <th>Gender</th>
	   <th>Programme</th>
	   <th>State</th>
	   <th>LGA</th>


	 </thead>
	 <tfoot>
	   <th>S/No</th>
	   <th>Name</th>
	   <th>Matric Number</th>
	   <th>Phone Number</th>
	   <th>Level</th>
	   <th>Application Number</th>
	   <th>Gender</th>
	   <th>Programme</th>
	   <th>State</th>
	   <th>LGA</th>


	 </tfoot>

	 <tbody>';

	 while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
	{
		$output_q .= "<tr>";
	  $output_q .= "<input type='hidden' value='2' name='type'/>";
		//$output_q .= "<input type='hidden' value='".$row['id']."' name='user_id'/>";
	  $output_q .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
	  $output_q .= "<td> <a href='gateway.php?act=new_allocation&id=".$row['id']." && type_id=2'>".$row['name']."</a></td>"; //nam eof the user
	  $output_q .= "<td>".$row['number']."</td>";
	  $output_q .= "<td>".$row['phone_no']."</td>";
	  $output_q .= "<td>".$row['LEVEL']."</td>";
	  $output_q .= "<td>".$row['application_number']."</td>";
	  $output_q .= "<td>".$row['gender']."</td>";
	  $output_q .= "<td>".$row['programme']."</td>";

	  $output_q .= "<td>".$row['state']."</td>";
	  $output_q .= "<td>".$row['lga']."</td>";

	  $output_q .= "</tr>";



	}
	}
	else
	{//show the msg

	  $output_q =
	       '<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_q .=
	 '</tbody>
	   </table>';

	   echo $output_q;




}//end of view applicants listings per programmes


//function view applicants listings per app fees payment
function view_all_not_allocated_students3($conn_2)
{


	//query the database
	$q = "SELECT CONCAT_WS(' ', first_name, other_names) as name, students_nce.id AS id,
	phone_no,number,gender,state.title AS state,lga.title AS lga,
	application_number, programmes.title AS programme, students_nce.level as LEVEL, students_nce.hostel_allocation='0'
	FROM state, lga, students_nce, programmes  WHERE students_nce.programme_id=programmes.id AND
	students_nce.state_id = state.id AND students_nce.lga_id = lga.id AND students_nce.hostel_allocation='0'
	ORDER BY number ASC ";
	$r = mysqli_query($conn_2, $q);

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

	$output_q =
	 '<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>Name</th>
	   <th>Matric Number</th>
	   <th>Phone Number</th>
	   <th>Level</th>
	   <th>Application Number</th>
	   <th>Gender</th>
	   <th>Programme</th>
	   <th>State</th>
	   <th>LGA</th>


	 </thead>
	 <tfoot>
	   <th>S/No</th>
	   <th>Name</th>
	   <th>Matric Number</th>
	   <th>Phone Number</th>
	   <th>Level</th>
	   <th>Application Number</th>
	   <th>Gender</th>
	   <th>Programme</th>
	   <th>State</th>
	   <th>LGA</th>


	 </tfoot>

	 <tbody>';

	 while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
	{
	  $output_q .= "<tr>";
		$output_q .= "<input type='hidden' value='3' name='type'/>";
		//$output_q .= "<input type='hidden' value='".$row['id']."' name='user_id'/>";
	  $output_q .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
	  $output_q .= "<td> <a href='gateway.php?act=new_allocation&id=".$row['id']." && type_id=3'>".$row['name']."</a></td>"; //nam eof the user
	  $output_q .= "<td>".$row['number']."</td>";
	  $output_q .= "<td>".$row['phone_no']."</td>";
	  $output_q .= "<td>".$row['LEVEL']."</td>";
	  $output_q .= "<td>".$row['application_number']."</td>";
	  $output_q .= "<td>".$row['gender']."</td>";
	  $output_q .= "<td>".$row['programme']."</td>";

	  $output_q .= "<td>".$row['state']."</td>";
	  $output_q .= "<td>".$row['lga']."</td>";

	  $output_q .= "</tr>";



	}
	}
	else
	{//show the msg

	  $output_q =
	       '<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_q .=
	 '</tbody>
	   </table>';

	   echo $output_q;




}//end of view applicants listings per programmes


//function view applicants listings per app fees payment
function view_all_not_allocated_students4()
{


	//query the database
	$q = "SELECT CONCAT_WS(' ', first_name, other_names) as name, summer_students.id AS id,
	phone_no,number,gender,	application_number, programmes.title AS programme, summer_students.level as LEVEL,
	summer_students.hostel_allocation='0' FROM summer_students, programmes  WHERE
	summer_students.programme_id=programmes.id AND summer_students.hostel_allocation='0'
	ORDER BY number ASC ";
	$r = mysqli_query(dbc(), $q);

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

	$output_q =
	 '<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>Name</th>
	   <th>Matric Number</th>
	   <th>Phone Number</th>
	   <th>Level</th>
	   <th>Application Number</th>
	   <th>Gender</th>
	   <th>Programme</th>
	   <th>State</th>
	   <th>LGA</th>


	 </thead>
	 <tfoot>
	   <th>S/No</th>
	   <th>Name</th>
	   <th>Matric Number</th>
	   <th>Phone Number</th>
	   <th>Level</th>
	   <th>Application Number</th>
	   <th>Gender</th>
	   <th>Programme</th>
	   <th>State</th>
	   <th>LGA</th>


	 </tfoot>

	 <tbody>';

	 while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
	{
	  $output_q .= "<tr>";
		$output_q .= "<input type='hidden' value='5' name='type'/>";
		//$output_q .= "<input type='hidden' value='".$row['id']."' name='user_id'/>";
	  $output_q .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
	  $output_q .= "<td> <a href='gateway.php?act=new_allocation&id=".$row['id']." && type_id=5'>".$row['name']."</a></td>"; //nam eof the user
	  $output_q .= "<td>".$row['number']."</td>";
	  $output_q .= "<td>".$row['phone_no']."</td>";
	  $output_q .= "<td>".$row['LEVEL']."</td>";
	  $output_q .= "<td>".$row['application_number']."</td>";
	  $output_q .= "<td>".$row['gender']."</td>";
	  $output_q .= "<td>".$row['programme']."</td>";

	  $output_q .= "<td> Nil </td>";
	  $output_q .= "<td> Nil </td>";

	  $output_q .= "</tr>";



	}
	}
	else
	{//show the msg

	  $output_q =
	       '<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_q .=
	 '</tbody>
	   </table>';

	   echo $output_q;




}//end of view applicants listings per programmes

//function view applicants listings per app fees payment
function view_all_qualified_allocated_students()
{


	//query the database
	$q = "SELECT CONCAT_WS(' ', first_name, other_names) as name, students_nce.id AS id,
	phone_no,number,gender,state.title AS state,lga.title AS lga,
	application_number, programmes.title AS programme, students_nce.level as LEVEL
	FROM state, lga, students_nce, programmes  WHERE students_nce.programme_id=programmes.id AND
	students_nce.state_id = state.id AND students_nce.lga_id = lga.id AND students_nce.hostel_allocation='0'
	ORDER BY number ASC";
	$r = mysqli_query(dbc(), $q);

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

	$output_q =
	 '<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>Name</th>
	   <th>Matric Number</th>
	   <th>Phone Number</th>
	   <th>Level</th>
	   <th>Application Number</th>
	   <th>Gender</th>
	   <th>Programme</th>
	   <th>State</th>
	   <th>LGA</th>


	 </thead>
	 <tfoot>
	   <th>S/No</th>
	   <th>Name</th>
	   <th>Matric Number</th>
	   <th>Phone Number</th>
	   <th>Level</th>
	   <th>Application Number</th>
	   <th>Gender</th>
	   <th>Programme</th>
	   <th>State</th>
	   <th>LGA</th>


	 </tfoot>

	 <tbody>';

	 while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
	{
	  $output_q .= "<tr>";
	  $output_q .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
	  $output_q .= "<td> <a href=''>".$row['name']."</a></td>"; //nam eof the user
	  $output_q .= "<td>".$row['number']."</td>";
	  $output_q .= "<td>".$row['phone_no']."</td>";
	  $output_q .= "<td>".$row['LEVEL']."</td>";
	  $output_q .= "<td>".$row['application_number']."</td>";
	  $output_q .= "<td>".$row['gender']."</td>";
	  $output_q .= "<td>".$row['programme']."</td>";

	  $output_q .= "<td>".$row['state']."</td>";
	  $output_q .= "<td>".$row['lga']."</td>";

	  $output_q .= "</tr>";



	}
	}
	else
	{//show the msg

	  $output_q =
	       '<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_q .=
	 '</tbody>
	   </table>';

	   echo $output_q;




}//end of view applicants listings per programmes

//function view applicants listings per app fees payment
function view_all_unpaid_applicants_app_fees()
{


	//query the database
	$q = "SELECT app.id, app.programme_type_applied_for, app.department_applied_for, app.programme_applied_for, app.application_number,
		 app.state_id, app.lga_id, app.first_name, app.other_names, app.phone_no, app.gender,  app.email,
		  DATE_FORMAT(app.date_added, '%M %d, %Y %l:%i:%p') as date_added,
		  DATE_FORMAT(app.date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		  FROM  applicants app, applicants_fee_payments app_fees

		  WHERE   app_fees.applicant_id != app.id

		  ORDER BY app.application_number ASC";
	$r = mysqli_query(dbc(), $q);

	if(mysqli_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>State</th>
						<th>L.G.A</th>
						<th>Payment  Status</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>State</th>
						<th>L.G.A</th>
						<th>Payment  Status</th>

			</tfoot>

			<tbody>';

		while($row = mysqli_fetch_array($r,MYSQLI_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['programme_type_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>".payment_status(0)."</td>";
			/*$output .= "<td>".get_applicant_image($row['id'])."</td>";
			$output .= "<td>".is_admitted($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 per programmes

//function dat get student id using application number
	function get_student_id_by_app_no($id)
	{
	$q = "SELECT id FROM students_nce WHERE application_number = '$id'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);

	return $row['id'];


	}



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

		$student_id = get_student_id_by_app_no($app_no);



		if($admission_status == '0')
		{
			return '<a class="btn btn-warning btn-sm" >  Pending </a> ';
		}
		else
		{

		    $output = '<a class="btn btn-success btn-sm" >  Admitted </a> <br/>';



					if($student_id != '')
					{
					    $output .= '<a class="btn-info btn-sm" target="_blank"  href="https://ibbuiceel.edu.ng/eportals/pd/applications_1/create_application_letter_pl2.php?u='.$id.'&c='. md5('EasyBrother').'"> Print Letter </a>
					';
					}
					else
					{
					    $output .= '<a class="btn-danger btn-sm"  href="#"> Unpaid </a>';
					}


			return $output;


		}

		//<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 = mysqli_query(dbc(), "SELECT * FROM applicants WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$admission_status = $row['admission_status'];



		return $admission_status;

		//return value

}


//get list of the programmes
function  get_programme_list($pt)
{
	$result = mysqli_query(dbc(), "SELECT * FROM programmes WHERE real_ = 0 ");


	//if(mysql_num_rows($result>0))
//	{
		while($row = mysqli_fetch_array($result,MYSQLI_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>';
			echo '<a href="#" class="btn btn-success  btn-lg"  style="margin:4px;" >'.$row['title'].' - <span class="badge">'.get_total_prog_type_programme_applicants($pt,$row['id']).'</span>'.'</a>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}


//get list of the programmes
function  get_programme_list2($conn_2, $pt)
{
	$result = mysqli_query($conn_2, "SELECT * FROM programmes WHERE real_ = 0 ");


	//if(mysql_num_rows($result>0))
//	{
		while($row = mysqli_fetch_array($result,MYSQLI_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>';
			echo '<a href="#" class="btn btn-success  btn-lg"  style="margin:4px;" >'.$row['title'].' - <span class="badge">'.get_total_prog_type_programme_applicants($pt,$row['id']).'</span>'.'</a>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}

//get list of the programmes
function  get_programme_list_paid($pt)
{
	$result = mysqli_query(dbc(), "SELECT * FROM programmes WHERE type_id = '$pt' AND id != 8 AND id != 9");


	//if(mysql_num_rows($result>0))
//	{
		while($row = mysqli_fetch_array($result,MYSQLI_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_paid($pt,$row['id']).'</span>'.'</a>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}



//function get total admitted applicants
function get_total_admitted_applicants_batch_1()
{
	$q = "SELECT COUNT(id) FROM applicants WHERE  admission_status = '1' AND admission_batch = '1'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}


//function get total admitted applicants
function get_total_admitted_applicants_batch_2()
{
	$q = "SELECT COUNT(id) FROM applicants WHERE  admission_status = '1' AND admission_batch = '2'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}


//function get total admitted applicants
function get_total_admitted_applicants_batch_3()
{
	$q = "SELECT COUNT(id) FROM applicants WHERE  admission_status = '1' AND admission_batch = '3'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}


//get list of the programmes admitted candidate
function  get_programme_list_admitted_applicants($pt)
{
	$result = mysqli_query(dbc(), "SELECT * FROM programmes WHERE type_id = '$pt'");


	//if(mysql_num_rows($result>0))
//	{
		while($row = mysqli_fetch_array($result,MYSQLI_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>';
		}

	//}
//	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  WHERE type_id = '$pt' AND programme_id = '$id' AND admission_status = '$admitted'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_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

		  WHERE   type_id = '$pt' AND programme_id = '$p' AND admission_status = '$admitted'

		  ORDER BY application_number ASC";
	$r = mysqli_query(dbc(), $q);

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_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 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

		  WHERE  admission_status = '$admitted'

		  ORDER BY application_number ASC";
	$r = mysqli_query(dbc(), $q); //AND admission_batch = 3

	if(mysqli_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>
						<th>Batch</th>
						<th> Admission Letter</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>
						<th>Batch</th>


			</tfoot>

			<tbody>';

		while($row = mysqli_fetch_array($r,MYSQLI_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> <a href='#' 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 .= "<td>".get_admission_batch($row['id'])."</td>";

            // Added this column to make the admission letter available on the view all admitted applicants tab. I added it on the 26th January 2020
			$output .= "<td>" .is_admitted($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

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



		if($v == 1)
		{

			$batch = 'Batch A';

		}
		else if($v == 2)
		{
			$batch = 'Batch B';

		}
		else
		{
			$batch = 'Batch C';


		}

		return $batch;

		//return value

}


//get course name o_level_subjects by id of the course
function get_o_level_subjects_title($id)
{
	$result = mysqli_query(dbc(), "SELECT title FROM o_level_subjects WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$title = substr($row['title'],0,3);

	return $title;
}


//get grade name o_level_subjects by id of
function get_o_level_grade_title($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
		{
			//$output = ' NIL';


		}

	return $output;
}


//function view all admitted applicants listings
function view_all_admitted_applicants_list_wq($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

		  WHERE  admission_status = '$admitted'

		  ORDER BY application_number ASC";
	$r = mysqli_query(dbc(), $q);

	if(mysqli_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>Applied Course</th>
						<th>Admitted Course</th>
						<th>Subjects</th>






			</thead>
			<tfoot>

						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Applied Course</th>
						<th>Admitted Course</th>
						<th>Subjects</th>





			</tfoot>

			<tbody>';

		while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td>".$row['application_number']."</td>";
			$output .= "<td> <a href='#' target='_new'>".strtoupper($row['first_name']).'  '.strtoupper($row['other_names'])."</a></td>";
			//$output .= "<td> <a href='gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$row['id']."' target='_new'>".strtoupper($row['first_name']).'  '.strtoupper($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>1. ".strtoupper(view_all_merited_subjects($row['id']))." <br/>2. ".strtoupper(view_all_merited_subjects2($row['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


//function view all admitted applicants listings
function view_all_merited_subjects($aid) // pt programm type , p programme
{


	//query the database
	$q = "SELECT applicant_id,  `subject1`, `grade1`, `subject2`, `grade2`, `subject3`, `grade3`, `subject4`, `grade4`, `subject5`, `grade5`, `subject6`, `grade6`, `subject7`, `grade7`, `subject8`, `grade8`, `subject9`, `grade9`
	     FROM  applicants_olevel

		  WHERE  applicant_id = '$aid' AND type = 1

		  AND
		  (
		  (`grade1`  = '1' OR `grade1`  = '2'  OR `grade1`  = '3' OR `grade1`  = '4' OR `grade1`  = '5' OR `grade1`  = '6'  OR `grade1`  = '' )
		  OR
		  (`grade2`  = '1' OR `grade2`  = '2'  OR `grade2`  = '3' OR `grade2`  = '4' OR `grade2`  = '5' OR `grade2`  = '6' OR `grade2`  = '' )
		    OR
		  (`grade3`  =  '1' OR `grade3`  = '2'  OR `grade3`  = '3' OR `grade3`  = '4' OR `grade3`  = '5' OR `grade3`  = '6'  OR `grade3`  = '')
		   OR
		  (`grade4`  = '1' OR `grade4`  = '2'  OR `grade4`  = '3' OR `grade4`  = '4' OR `grade4`  = '5' OR `grade4`  = '6' OR `grade4`  = '' )
		   OR
		  (`grade5`  = '1' OR `grade5`  = '2'  OR `grade5`  = '3' OR `grade5`  = '4' OR `grade5`  = '5' OR `grade5`  = '6' OR `grade5`  = '' )
		   OR
		  (`grade6`  = '1' OR `grade6`  = '2'  OR `grade6`  = '3' OR `grade6`  = '4' OR `grade6`  = '5' OR `grade6`  = '6' OR `grade6`  = '')
		   OR
		  (`grade7`  = '1' OR `grade7`  = '2'  OR `grade7`  = '3' OR `grade7`  = '4' OR `grade7`  = '5' OR `grade7`  = '6' OR `grade7`  = '')
		   OR
		  (`grade8`  = '1' OR `grade8`  = '2'  OR `grade8`  = '3' OR `grade8`  = '4' OR `grade8`  = '5' OR `grade8`  = '6' OR `grade8`  = '')
		   OR
		  (`grade9`  = '1' OR `grade9`  = '2'  OR `grade9`  = '3' OR `grade9`  = '4' OR `grade9`  = '5' OR `grade9`  = '6' OR `grade9`  = '')
		   )
		   ";
	$r = mysqli_query(dbc(), $q);

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



		  $output = '';

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

			$output .= get_o_level_subjects_title($row['subject1']).' : '.get_o_level_grade_title($row['grade1']).' , ';
			$output .= get_o_level_subjects_title($row['subject2']).' : '.get_o_level_grade_title($row['grade2']).' , ';
			$output .= get_o_level_subjects_title($row['subject3']).' : '.get_o_level_grade_title($row['grade3']).' , ';
            $output .= get_o_level_subjects_title($row['subject4']).' : '.get_o_level_grade_title($row['grade4']).' , ';
			$output .= get_o_level_subjects_title($row['subject5']).' : '.get_o_level_grade_title($row['grade5']).' , ';
			$output .= get_o_level_subjects_title($row['subject6']).' : '.get_o_level_grade_title($row['grade6']).' , ';
			$output .= get_o_level_subjects_title($row['subject7']).' : '.get_o_level_grade_title($row['grade7']).' , ';
			$output .= get_o_level_subjects_title($row['subject8']).' : '.get_o_level_grade_title($row['grade8']).' , ';
			$output .= get_o_level_subjects_title($row['subject9']).' : '.get_o_level_grade_title($row['grade9']).'';









		}
	}
	else
	{//show the msg

			$output =
				   ' No rec.
				   ';


	}




	return $output;




}//end of view all subjects with qualified grade


//function view all admitted applicants listings
function view_all_merited_subjects2($aid) // pt programm type , p programme
{


	//query the database
	$q = "SELECT applicant_id,  `subject1`, `grade1`, `subject2`, `grade2`, `subject3`, `grade3`, `subject4`, `grade4`, `subject5`, `grade5`, `subject6`, `grade6`, `subject7`, `grade7`, `subject8`, `grade8`, `subject9`, `grade9`
	     FROM  applicants_olevel

		  WHERE  applicant_id = '$aid' AND type = 2

		  AND
		  (
		  (`grade1`  = '1' OR `grade1`  = '2'  OR `grade1`  = '3' OR `grade1`  = '4' OR `grade1`  = '5' OR `grade1`  = '6'  OR `grade1`  = '' )
		  OR
		  (`grade2`  = '1' OR `grade2`  = '2'  OR `grade2`  = '3' OR `grade2`  = '4' OR `grade2`  = '5' OR `grade2`  = '6' OR `grade2`  = '' )
		    OR
		  (`grade3`  =  '1' OR `grade3`  = '2'  OR `grade3`  = '3' OR `grade3`  = '4' OR `grade3`  = '5' OR `grade3`  = '6'  OR `grade3`  = '')
		   OR
		  (`grade4`  = '1' OR `grade4`  = '2'  OR `grade4`  = '3' OR `grade4`  = '4' OR `grade4`  = '5' OR `grade4`  = '6' OR `grade4`  = '' )
		   OR
		  (`grade5`  = '1' OR `grade5`  = '2'  OR `grade5`  = '3' OR `grade5`  = '4' OR `grade5`  = '5' OR `grade5`  = '6' OR `grade5`  = '' )
		   OR
		  (`grade6`  = '1' OR `grade6`  = '2'  OR `grade6`  = '3' OR `grade6`  = '4' OR `grade6`  = '5' OR `grade6`  = '6' OR `grade6`  = '')
		   OR
		  (`grade7`  = '1' OR `grade7`  = '2'  OR `grade7`  = '3' OR `grade7`  = '4' OR `grade7`  = '5' OR `grade7`  = '6' OR `grade7`  = '')
		   OR
		  (`grade8`  = '1' OR `grade8`  = '2'  OR `grade8`  = '3' OR `grade8`  = '4' OR `grade8`  = '5' OR `grade8`  = '6' OR `grade8`  = '')
		   OR
		  (`grade9`  = '1' OR `grade9`  = '2'  OR `grade9`  = '3' OR `grade9`  = '4' OR `grade9`  = '5' OR `grade9`  = '6' OR `grade9`  = '')
		   )
		   ";
	$r = mysqli_query(dbc(), $q);

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



		  $output = '';

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

			$output .= get_o_level_subjects_title($row['subject1']).' : '.get_o_level_grade_title($row['grade1']).' , ';
			$output .= get_o_level_subjects_title($row['subject2']).' : '.get_o_level_grade_title($row['grade2']).' , ';
			$output .= get_o_level_subjects_title($row['subject3']).' : '.get_o_level_grade_title($row['grade3']).' , ';
            $output .= get_o_level_subjects_title($row['subject4']).' : '.get_o_level_grade_title($row['grade4']).' , ';
			$output .= get_o_level_subjects_title($row['subject5']).' : '.get_o_level_grade_title($row['grade5']).' , ';
			$output .= get_o_level_subjects_title($row['subject6']).' : '.get_o_level_grade_title($row['grade6']).' , ';
			$output .= get_o_level_subjects_title($row['subject7']).' : '.get_o_level_grade_title($row['grade7']).' , ';
			$output .= get_o_level_subjects_title($row['subject8']).' : '.get_o_level_grade_title($row['grade8']).' , ';
			$output .= get_o_level_subjects_title($row['subject9']).' : '.get_o_level_grade_title($row['grade9']).'';







		}
	}
	else
	{//show the msg

			$output =
				   ' No rec.
				   ';


	}




	return $output;




}//end of view all subjects with qualified grade 2




	//////////////////////// remita log
	//function view transaction log
	function view_remita_transaction_log($trans_type , $trans_for )
	{

		$sess = get_current_session(1);

		//query the database
		$query = "SELECT `id`, `invoice_id`, `transaction_type`, `user_id`, `transaction_for`, `payment_method`,
		`payment_status`, `response_code`, `response_description`,`transaction_id`, `transaction_reference`,
		 `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 `hostel_remita_webpay_transaction_log`

		 WHERE transaction_type = '$trans_type' AND	 transaction_for = '$trans_for'
		 ORDER BY id DESC"; //AND session = $sess
	   $result = mysqli_query(dbc(), $query);



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


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

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


			  </thead>

			 <!-- <tfoot>

			  </tfoot>-->

			  <tbody>';


			while($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
			{
			   // $int_amount = $row['amount'] * 100;


				$output .= "<tr>";
					$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".get_student_matric_number($row['user_id'])."</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'>".get_student_fullname($row['user_id'])."</td>";

				$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>".$row['date_added']."</td>";


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

				if($row['payment_status'] != '1')
				{
					//app fees
					if($trans_for == 5 ){
						$output .= '<td><a target="_blank" class="btn btn-sm btn-primary" href="gateway.php?act=view_rr_log_app_fees&txnref='.$row['transaction_reference'].'" > Re - Query </a></td>';
					//accept. fees
					}elseif($trans_for == 5){
						$output .= '<td><a target="_blank" class="btn btn-sm btn-primary" href="gateway.php?act=view_rr_log_app_fees&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 to get invoice payment to using orderID
	function get_invoice_to_using_txnref($oid)
	{
		$result = mysqli_query(dbc(), "SELECT user_id FROM hostel_remita_webpay_transaction_log WHERE transaction_reference = '$oid'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['user_id'];

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

	return $v;
	}


	//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 for remita response code
	  function remita_response_code($stat, $rrr, $desc, $iid )
	  {
		  $mes = '<ul class="list-group">';

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


		  }
		  else if($stat == '021')
		  {
			  $mes .= '<li class="list-group-item list-group-item-success"><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_nceconfirmation 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`,
		 `title`, `description`, `amount`, `total_amount`, `credit`,

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


		 FROM hostel_invoices

		 WHERE invoice_id = '$search_stb'";

		 //LIMIT $start, $display_per_page";
	$r = mysqli_query(dbc(), $q) or die (mysqli_error(dbc()));




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

	if(mysqli_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 = mysqli_fetch_array($r,MYSQLI_ASSOC))
		{
			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[]' id='invoice' 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/>
                             '.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[]' id='invoice' 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 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 = mysqli_query(dbc(), "SELECT title FROM set_hostel_fee_payments_for_students_nce WHERE level = '$level' AND semester = '$s' AND programme_type_id = '$pt' AND department_id = '$d' AND programme_id = '$p'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['title'];

	return $v;
	}


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

	return $v;
	}

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

	return $v;
	}


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

	return $v;
	}





	//Function to fetch  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 hostel_invoices WHERE invoice_id = '$iid'";
		$r1 = mysqli_query(dbc(), $q1);

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


	}



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

	return $v;
	}

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

	return $v;
	}



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

	return $v;
	}



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

	return $v;
	}


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

	return $v;
	}



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

	return $v;
	}


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

	return $v;
	}


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

	return $v;
	}


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

	return $v;
	}



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

	return $v;
	}


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

	return $v;
	}

	function load_campus()
	{
		$q = "SELECT * FROM hostel_campuses WHERE status='1' ORDER BY date_added ASC ";
		$r = mysqli_query(dbc(), $q) ;

		if(mysqli_num_rows($r) > 0)
		{//show table
			while($row = mysqli_fetch_array($r)){


				$rr= '

				<option value="'.$row['id'].'">'.$row['title'].'</option>';

		}
	}else{
			$rr = '<option>No record</option>';
	}
	return $rr;
	}

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

	return $v;
	}



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

	return $v;
	}


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

	return $v;
	}

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

	return $v;
	}


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

	//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 `hostel_invoices`
			 WHERE invoice_to = '$user_id' AND invoice_type = '$type'


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



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


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

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



		  </thead>

		 <!-- <tfoot>




		  </tfoot>-->

		  <tbody>';


		while($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$row['invoice_id']."</td>"; //group belong to admin or user
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['due_date']."</td>";
			$output .= "<td>".payment_status($row['payment_status'])."</td>";
			$output .= '<td><a class="btn btn-default" href="dashboard.php?act=view_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 = mysqli_query(dbc(), "SELECT application_number  FROM students_nce WHERE application_number = '$apn' AND level = '$l'");
		$row = mysqli_fetch_assoc($result);
		$an = $row['application_number'];

		if($an == '')
		{

			return false;



		}
		else
		{
			return true;


		}


	}
	//end of checking if applicant exist


	// function that check if a applicant application number exist in stduents table or not
	function application_number_exist_1($apn, $l,$sess)
	{
		$result = mysqli_query(dbc(), "SELECT application_number  FROM students_nce WHERE application_number = '$apn' AND
		level = '$l' AND session = '$sess'");
		$row = mysqli_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)
	{
		$q = "SELECT student_id FROM hostel_fee_payments  WHERE student_id = '$sid' AND session_id = '$sess' ";
		$r = mysqli_query(dbc(), $q);


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



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



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


		return $v;
	}



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

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

	// }




	//get programme code from programme

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


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

	$total = $total_in_programme;






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

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


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



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

	$count_character = strlen($total);


	//check for level and count
	if($level == '100')
	{
		$l = '1';
	}
	else if ($level == '200')
	{
		$l = '2';
	}
	else if ($level == '300')
	{
		$l = '3';
	}
	else
	{
		//
	}

	//echo $l;



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



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




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


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

			//collect all the matric number


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


			$ln = 14; //lenght of the code

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

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

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

			}

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


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

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

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

			//echo $l.'- '. $hn;

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




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


			return $matric_numbe ;

		//}


	}
	else
	{
		return $matric_number;
	}


	//return $matric_number;

}



//Functions to fetch student Full name
	function get_student_fullname($id)
	{
		$result = mysqli_query(dbc(), "SELECT * FROM students_nce WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$first_name = $row['first_name'];
		$other_names = $row['other_names'];

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

	  return $user_fullname;
	}




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

	return $row['number'];


	}


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

	return $row['address'];


	}


	//function fetch student department
	function get_student_department_id($id)
	{
		$result = mysqli_query(dbc(), "SELECT department_id FROM students_nce WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['department_id'];


		return $v;
	}



	//function fetch student programme
	function get_student_programme_id($id)
	{
		$result = mysqli_query(dbc(), "SELECT programme_id FROM students_nce WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['programme_id'];


		return $v;
	}


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


		return $v;
	}



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


		return $v;
	}
	//function fetch student id by application number
	function get_student_id_application_number_1($id, $l,$sess) //$l is level
	{
		$result = mysqli_query(dbc(), "SELECT id FROM students_nce WHERE application_number = '$id' AND
		level = '$l' AND session = '$sess'");
		$row = mysqli_fetch_assoc($result);
		$v = $row['id'];


		return $v;
	}

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

		if($mno == '')
		{

			return false;

		}
		else
		{
			return true;

		}


	}




	/////////////////report for the student
	//function count number of bank epin generated
	function get_total_confirmed_payments_per_semester($session, $semester)
	{
		$q = "SELECT COUNT(*) FROM hostel_fee_payments WHERE  session_id = '$session' AND semester_id = '$semester' AND student_id != ''";
		$r = mysqli_query(dbc(), $q);
		$row = mysqli_fetch_array($r,MYSQLI_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  ************************************/
//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 get total students_ncein NCe programme
function get_total_prog_type_students_by_year($pt,$yr)
{
	$q = "SELECT COUNT(id) FROM students_nce";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}
//function get total students_ncein NCe programme
function get_total_prog_type_students_prence($pt)
{
	$q = "SELECT COUNT(id) FROM students_prence  WHERE type_id = '$pt'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}


//get list of the programmes for students_ncereports
function  get_programme_list_for_students_report_ptd($pt,$yr)
{
	$result = mysqli_query(dbc(), "SELECT * FROM programmes WHERE type_id = '1'");


	//if(mysql_num_rows($result>0))
	//	{
		while($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
		{
			echo '<a href="gateway.php?act=view_students_per_course_ptd&a='.sha1('fucku').'&pt='.$pt.'&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_ptd($pt,$row['id'],$yr).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}
//get list of the programmes for students_ncereports
function  get_programme_list_for_students_report_dip($pt,$yr)
{
	$result = mysqli_query(dbc(), "SELECT * FROM programmes WHERE type_id = '1'");


	//if(mysql_num_rows($result>0))
	//	{
		while($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
		{
			echo '<a href="gateway.php?act=view_students_per_course_dip&a='.sha1('fucku').'&pt='.$pt.'&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_ptd($pt,$row['id'],$yr).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}//get list of the programmes for students_ncereports
function  get_programme_list_for_students_report_cert($pt,$yr)
{
	$result = mysqli_query(dbc(), "SELECT * FROM programmes WHERE type_id = '1'");


	//if(mysql_num_rows($result>0))
	//	{
		while($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
		{
			echo '<a href="gateway.php?act=view_students_per_course_cert&a='.sha1('fucku').'&pt='.$pt.'&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_ptd($pt,$row['id'],$yr).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}
//function get total students_ncein NCe programme
function get_total_prog_type_programme_students_ptd($pt, $id, $yr)
{
	$q = "SELECT COUNT(id) FROM students_nce WHERE type_id = '$pt' AND programme_id = '$id' AND entry_year = '$yr'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}


//function get total student number for sch fees
function get_total_regular_ptd_sf_payment($pt,$sess, $lev, $yr)
{
	//please remove applicant later

	//query the database
	$q = "SELECT COUNT(DISTINCT(std.id)) AS total_count FROM `hostel_fee_payments` 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 fees.programme_type_id = $pt ";
	$r = mysqli_query(dbc(), $q);

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

			return $v;

}

//function get total student number for sch fees
function get_total_regular_dip_sf_payment($pt,$sess, $lev, $yr)
{
	//please remove applicant later

	//query the database
	$q = "SELECT COUNT(DISTINCT(std.id)) AS total_count FROM `hostel_fee_payments` 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 fees.programme_type_id = $pt ";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);
	$v = $row['total_count'];

			return $v;

}

//function get total student number for sch fees
function get_total_regular_cert_sf_payment($pt,$sess, $lev, $yr)
{
	//please remove applicant later

	//query the database
	$q = "SELECT COUNT(DISTINCT(std.id)) AS total_count FROM `hostel_fee_payments` 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 fees.programme_type_id = $pt ";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);
	$v = $row['total_count'];

			return $v;

}

//function view students_ncelistings per programmes
function view_students_list_per_programmes_ptd($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, 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,admission_serial_no

		  FROM  students

		  WHERE   type_id = '$pt' AND programme_id = '$p' AND entry_year = '$yr'

		  ORDER BY number ASC";
	$r = mysqli_query(dbc(), $q);

	if(mysqli_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>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>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 = mysqli_fetch_array($r,MYSQLI_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['admission_serial_no']."</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_nceants listings per programmes

//function get applicant image by passing id alone
function get_student_image($id, $pt)
{
	$result = mysqli_query(dbc(), "SELECT image FROM students_nce WHERE id = '$id'");
	$row = mysqli_fetch_assoc($result);
	$image = $row['image'];




	if($image != '')
	{//show table




           // $up_path = '../pt/uploads/';
           $up_path = '../part_time_degree_programmes/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 students_ncelistings per programmes
function view_students_summary($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,department_id, programme_id, application_number,`number`,
		  state_id, lga_id, first_name,other_names, phone_no, gender,  email, level,
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added

		  FROM  students

		  WHERE   type_id = '$pt' AND level = '$lev'

		  ORDER BY number ASC";
	$r = mysqli_query(dbc(), $q);

	if(mysqli_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>Other Names</th>
						<th>Level</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>Other Names</th>

						<th>Level</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 = mysqli_fetch_array($r,MYSQLI_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='xeditoname' id='".$row['id']."' key='other_names'>".$row['other_names']."</td>";
			$output .= "<td>".$row['level']."</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>

					'.get_sed_sub_courses($row['id']).'

				</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_nceants listings per programmes
function has_paid_school_fee($user_id,$session)
{
	$q = "SELECT student_id,session, payment_status
		  FROM hostel_fee_payments
		  WHERE student_id = '$user_id'
		  AND session = '$session'
		  AND payment_status  = '1'";
	$r = mysqli_query(dbc(), $q);

	//$row = mysqli_fetch_assoc($result);

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

	}
	else
	{
		return true;
	}

}
function view_applicants_fin_summary_1($ptd, $dip, $cert)
{
		//get all money including jdlab share
		$ptd_sum = get_total_amount_paid_applicants($ptd[0], $ptd[1]);
		$ptd_jdlab_sum = get_total_amount_paid_applicants_jdlab($ptd[0]);


		$dip_sum = get_total_amount_paid_applicants($dip[0], $dip[1]);
		$dip_jdlab_sum = get_total_amount_paid_applicants_jdlab($dip[0]);

		//$nce_jdlab_sum = get_total_amount_paid_applicants_nce_jdlab($dip[0], $dip[1]);

		 $jdlab_total = $ptd_jdlab_sum + $dip_jdlab_sum + $cert_jdlab_sum;

		$type_sum = $ptd_sum + $dip_sum + $cert_sum;

		//$all_sum = $type_sum + $jdlab_total;
		$all_sum = $type_sum ;


		// if($ptd_sum != '' &&  $dip_sum != ''  && $cert_sum != '')
		// {//show table
		$output = '';
		$ptd_output = '';
		$dip_output = '';
		$cert_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>Applied For</th>
					<th>Amount</th>
					<th>JDLAB</th>
					<th>PUR. DATE</th>


				</thead>
				<tfoot>



				</tfoot>

				<tbody>';


				//for pt degree records
				$ptd_output .= get_applicants_app_fees_paid($ptd[0], $ptd[1]);
				//additional row for summing
				if ($ptd_output !== '') {
			    	$ptd_output1 .= "<tr>";
					$ptd_output1 .= "<td>XXXXXXXX</td>";
					$ptd_output1 .= "<td>XXXXXXXX</td>";
					$ptd_output1 .= "<td>XXXXXXXX</td>";
					//$ptd_output1 .= "<td>XXXXXXXX</td>";
					$ptd_output1 .= "<td><b>PT Degree Total</b></td>";

					$ptd_output1 .= "<td width='100px'><b>N".number_format($ptd_sum)."</b></td>";
					$ptd_output1 .= "<td width='100px'><b>N".number_format($ptd_jdlab_sum)."</b></td>";
					$ptd_output1 .= "<td>XXXXXXXX</td></tr>";
			    }


				//for diploma records
				 $dip_output .= get_applicants_app_fees_paid($dip[0], $dip[1]);
				//echo $dip_output;

				//additional row for summing
				// if ($dip_output !== '') {
			 //   	$dip_output1 .= "<tr>";
				// 	$dip_output1 .= "<td>XXXXXXXX</td>";
				// 	$dip_output1 .= "<td>XXXXXXXX</td>";
				// 	$dip_output1 .= "<td>XXXXXXXX</td>";
				// 	//$dip_output1 .= "<td>XXXXXXXX</td>";
				// 	$dip_output1 .= "<td><b>Diploma Total</b></td>";

				// 	$dip_output1 .= "<td width='100px'><b>N".number_format($dip_sum)."</b></td>";
				// 	$dip_output1 .= "<td width='100px'><b>N".number_format($dip_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>";
					$all_output1 .= "<td>XXXXXXXX</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.
				$ptd_output.$ptd_output1.

				$dip_output.$dip_output1.

				$cert_output.$cert_output1.

				$all_output1.

				$output_last;




}//end of view applicants listings per programmes

//function to get total sum of money paid of courses a student carried per semester
function get_total_amount_paid_applicants($pt , $sess )
{
	$result = mysqli_query(dbc(), "SELECT SUM(amount-500) AS summed_up FROM hostel_fee_payments
				WHERE programme_type_id = '$pt' ");

				//AND session = '$sess' AND mode = '$mode'");
	$row = mysqli_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}

function get_total_amount_paid_applicants_per_prog($pt , $prog, $sess)
{
	$result = mysqli_query(dbc(), "SELECT SUM(amount-500) AS summed_up FROM applicants_fee_payments
				WHERE programme_type_id = '$pt'  AND programme_id = '$prog'");

				//AND session = '$sess' AND mode = '$mode'");
	$row = mysqli_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}
//function view applicants listings per programmes
function get_applicants_app_fees_paid($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,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

		  WHERE   programme_type_applied_for = '$pt'

		  ORDER BY application_number ASC

		  ";
	$r = mysqli_query(dbc(), $q);

	$jd_amt = 500;
	$output = '';
	if(mysqli_num_rows($r) > 0)
	{


		while($row = mysqli_fetch_array($r,MYSQLI_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 .= "<td>".get_applicant_app_paid_date($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


//check applicant that has paid app fees
function applicant_has_paid_app_fees($id)
{
	//query the database
		$q = "SELECT applicant_id FROM applicants_fee_payments
			WHERE  applicant_id = '$id'";
	   $r= mysqli_query(dbc(), $q);

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



function get_applicant_paid_app_fees_amount($id)
{
	//query the database
		$q = "SELECT (amount-500) AS amt FROM applicants_fee_payments
			WHERE  applicant_id = '$id'";
	   $r= mysqli_query(dbc(), $q);

		if($r){
			$row = mysqli_fetch_assoc($r);
			$v = $row['amt'];

			return $v;
		}
}



//get date of payment by candidate
function get_applicant_app_paid_date($id)
{
	//query the database
		$q = "SELECT DATE_FORMAT(date_added, '%M %d, %Y') as date_added FROM applicants_fee_payments
			WHERE  applicant_id = '$id'";
	   $r= mysqli_query(dbc(), $q);

		if($r){
			$row = mysqli_fetch_assoc($r);
			$v = $row['date_added'];

			return $v;
		}
}



//function to get total sum of money paid for pre nce of courses a student carried per semester
function get_total_amount_paid_applicants_jdlab($pt )
{
	$result = mysqli_query(dbc(), "SELECT SUM(500) AS summed_up FROM applicants_fee_payments
				WHERE programme_type_id = '$pt'");
	$row = mysqli_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}

//get list of the programmes for students_ncepayments reports
function  get_programme_list_for_applicants_payments_report($pt, $ses)
{
	$result = mysqli_query(dbc(), "SELECT * FROM programmes WHERE type_id = '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 = mysqli_fetch_array($result,MYSQLI_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_per_prog( $pt , $row['id'], $ses)).'</span></td>';
			$output .= "</tr>";


	}


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





	return $output;

}

//function to get total sum of money paid for nce of courses a student carried per semester
function get_total_amount_paid_per_session($pt,$session, $semester)
{
	$result = mysqli_query(dbc(), "SELECT SUM(amount - 500) AS summed_up FROM hostel_fee_payments WHERE  session_id = '6'");
	$row = mysqli_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}

//get list of the programmes for students_ncepayments reports
function  get_programme_list_for_students_payments_report($pt,$ses,$yr)
{
	$result = mysqli_query(dbc(), "SELECT * FROM programmes WHERE type_id = 1");


	//if(mysql_num_rows($result>0))
	//	{
		while($row = mysqli_fetch_array($result,MYSQLI_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_per_programme($ses,$pt,$row['id'])).'</span>'.'</a> <br/>';
		}

	//}
//	else
//	{
//		echo "No data found..";
//	}

}

//function to get total sum of money paid for  prence of courses a studer
function get_total_amount_paid_per_session_per_programme($session, $pt , $p)
{
	$result = mysqli_query(dbc(), "SELECT SUM(amount) AS summed_up FROM hostel_fee_payments WHERE  session = '$session' AND programme_id = '$p' AND programme_type_id = '$pt' AND semester = 1");
	$row = mysqli_fetch_assoc($result);
	$summed_up = $row['summed_up'];

	return $summed_up;
}

	//function view applicants listings per programmes
function view_students_fin_summary_ptd($pt,$ses)
{


		$output = '';
		$ptd_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>Fullname</th>
					<th>Programme Type</th>
					<th>Level</th>
					<th>Applied For</th>
					<th>Amount</th>
					<th>Payment Type</th>
				    <th>Date</th>

				</thead>
				<tfoot>



				</tfoot>

				<tbody>';


			    //for nce records
			    $ptd_output .= get_sch_fees_paid_ptd($pt, $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.
				$ptd_output.
				$all_output1.

				$output_last;




}//end of view applicants listings per programmes
//function view applicants listings per programmes
function get_sch_fees_paid_ptd($pt, $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, DATE_FORMAT(sf_pay.date_added, '%m %d, %Y %l:%i:%p') AS sch_date, sf_pay.invoice_id
		  FROM  students_nce std, hostel_fee_payments sf_pay

		  WHERE   sf_pay.session = '$sess' AND std.id = sf_pay.student_id

		  ORDER BY `number` ASC

		  ";
	$r = mysqli_query(dbc(), $q);

	$jd_amt = 500;
	$output = '';
	if(mysqli_num_rows($r) > 0)
	{


		while($row = mysqli_fetch_array($r, MYSQLI_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>".transaction_type_user(get_invoice_type($row['invoice_id']))."</td>";

				$output .= "<td>".$row['sch_date']."</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>XXXXXXXX</td>";
				//$pt = 3;
				if ($pt == 1) {

					$output .= "<td><b>PT DEGREE Total</b></td>";
				}elseif ($pt == 2){
					$output .= "<td><b>DIPLOMA Total</b></td>";

				}elseif ($pt == 3){
					$output .= "<td><b>CERTIFICATE 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>";
				$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 get_records_applicants_not_qualify($qi)
{

	$output1 =
	 '<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>Higher Qualification</th>
		 <th>Status</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>Higher Qualification</th>
		 <th>Status</th>
		 <th>Action</th>

	 </tfoot>

	 <tbody>';

		 //resetting qualified applicants ids
		 if (isset($_SESSION['app_id_arr'])) {
			 unset($_SESSION['app_id_arr']);
		 }
		 $app_id_arr = array();

				 //query the database
		 $q2 = "SELECT *FROM  students_nce WHERE level = '200' OR level = '300' ORDER BY number ASC";

				 //AND app.batch = '1' AND app.admission_status = '1'
		 $r2 = mysqli_query(dbc(), $q2);

		 $snn = 0;
		 //get course suggestion
		 $cs_lists = '';
		 $cs_arr = '';
		 //echo $qi = 1;
		 while($row2 = mysqli_fetch_array($r2))
		 {

			 $applicant_id = $row2['id'];

			 $cs_lists = validate_applicant_all_olevel($applicant_id);


			 //print_r($cs_lists[0]);
			 //when Qualified
			 if (isset($cs_lists) ){


				 //compute higher result to get final qualified status

				 $prog = $row2['programme_applied_for'];
				 $app_level = get_programme_level($prog);
				 //when truely qualified
				 $out_q = get_to_admit_based_on_level($applicant_id, $app_level);

				 //when not qualified
				 if ($qi == 0 ) {
					 //initialize
					 $out_q = 'Yes';
				 }


								 if ( $cs_lists[0] == $qi && $out_q != '' ) {
					 $snn += 1;
					 $output_q .= "<tr>";

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

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

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

					 $output_q .= "<td>".get_applicant_high_qualification($applicant_id)."</td>";

					 //echo get_programme_title($prog);
					 //$cs_lists = get_valid_programme_nce($pt);


									 if ($qi == 1 && $out_q != '') {

										 if ($app_level == 100) {

											 $output_q .= "<td>".show_qualified_status(1)."</td>";

											 array_push($app_id_arr, $applicant_id);

											 $output_q .= $out_q;


										 }elseif ($app_level == 200) {
											 //cecking ND,NCE... result category

							 if ($out_q != '') {

												 $output_q .= "<td>".show_qualified_status(1)."</td>";
												 $output_q .= $out_q;
												 array_push($app_id_arr, $applicant_id);
							 }else{

												 $output_q .= "<td>".show_qualified_status(0)."</td>";
												 $output_q .= "<td></td>";

							 }



										 }elseif ($app_level == 300) {
											 array_push($app_id_arr, $applicant_id);

										 }

									 }else{

										 $output_q .= "<td>".show_qualified_status(0)."</td>";

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

						 //$sug_cs_lists = validate_applicant_all_olevel2($applicant_id);
										 //get program suggestion based on olevel and high grade

						 $sug_prog = get_program_suggestions($applicant_id,$cs_lists[1],$app_level);


										 $output_q .= $sug_prog;
									 }


								 }



							 }else{

									 //echo 1;


							 }




		 }



	 $output2 .=
	 '</tbody>
		 </table>';
	 $_SESSION['app_id_arr'] = $app_id_arr;
		// if ($qi == 1) {
		 return $output1.$output_q.$output2;
		 //}elseif($qi == 0){
		 //return $output1.$output_nq.$output2;
		 //}


}

function get_applicant_olevel($id,$ty)
{
		$olevel_str = '';


		//$sub_and_grd_1 ='';

		$q = "SELECT * FROM `applicants_olevel`
				WHERE applicant_id = '$id' AND type = '$ty'";

		$r = mysqli_query(dbc(), $q);

		if(mysqli_num_rows($r) > 0 ){
			$rec = mysqli_fetch_array($r,MYSQLI_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 get_applicant_high_qualification($id)
{
		$output = '' ;

		$q = "SELECT * FROM `applicants_institutions`
				WHERE user_id = '$id' ";


		$r = mysqli_query(dbc(), $q);

		if(mysqli_num_rows($r) > 0 ){

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

				//when not nce result
				if ($rec['cert'] != 2  && $rec['school'] !='') {

					$output1 = '<b class=" badge"> Result Type: '.show_cert3($rec['cert']).'</b><br>';
					$output1 .= '<span class="list-group-item"><b>School: '.$rec['school'].'</b></span>';
					$output1 .= '<span class="list-group-item"><b>Cert. Class: '.show_class_cert($rec['result']).'</b></span>';

					$output .= $output1;
				}else{

					$output1 = '<b class=" badge"> Result Type: '.show_cert3($rec['cert']).'</b><br>';
					$output1 .= '<span class="list-group-item"><b>School: '.$rec['school'].'</b></span>';

					$output .= $output1;

				}

			}



		}


		if ($output !== '') {
			//return $qi = 1;
			return $output;
		}else{

			return '<li class="list-group-item text-danger">NIL</li>';
		}


}

function show_month($mnt)
{

	$mnt -= 1;
	$months = array(
	    'January',
	    'February',
	    'March',
	    'April',
	    'May',
	    'June',
	    'July ',
	    'August',
	    'September',
	    'October',
	    'November',
	    'December',
	);

	return $months[$mnt];


}


	//function select subjects
function show_subjects_title($id)
{
	$r = mysqli_query(dbc(), "SELECT title  FROM o_level_subjects
					WHERE id = '$id' ");
	$row = mysqli_fetch_assoc($r);
	$v = $row['title'];

	return $v;

}

//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 that check and show is qualified status
function show_qualified_status($status)
{
	$st = $status;

	if($st == 1)
	{
		return '<h4 class="btn btn-success disabled">QUALIFIED</h4>';
	}
	else
	{
		return '<h4 class="btn btn-danger disabled">NOT QUALIFIED</h4>';
	}
}

function validate_applicant_all_olevel($id)
	{
		$olevel1_str = '';
		$olevel2_str = '';
		$all_olevel = array();

		//$sub_and_grd_1 ='';

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

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

		$r = mysqli_query(dbc(), $q);
		$r2 = mysqli_query(dbc(), $q2);

		if(mysqli_num_rows($r) > 0 ){
			$rec = mysqli_fetch_array($r,MYSQLI_ASSOC);
			$rec2 = mysqli_fetch_array($r2,MYSQLI_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);


		$data = array();

		if ($qualified == true) {

			$data = [$qi = 1, ''];
			return $data;
		}else{

			$data = [$qi = 0, $all_olevel ];
			//return $all_olevel;
			return $data;
		}


	}


	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 pass_olevel($gr)
{
	//validating pass grade
	if ( $gr > 0 &&   $gr < 7) {
		return true;
	}
}

//function that gets programme_id base on user id
function  get_applicant_required_subjects($pid)
{
	$result = mysqli_query(dbc(), "SELECT required_subjects FROM programmes WHERE id = '$pid'");
		$row = mysqli_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 = mysqli_query(dbc(), "SELECT optional_subjects FROM programmes WHERE id = '$pid'");
		$row = mysqli_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 = mysqli_query(dbc(), "SELECT optional_count FROM programmes WHERE id = '$pid'");
		$row = mysqli_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 = mysqli_query(dbc(), "SELECT title, id, required_subjects, optional_subjects,optional_count
					FROM programmes WHERE type_id = '$pt'
					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(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r,MYSQLI_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_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  '';

		}
}

//admiting applicants
function admit_applicant($id)
{

	$pid =  get_user_programme_applied_for($id);
	$pt =  get_user_programme_type_applied_for($id);
   	$dept = get_user_department_applied_for($id);


    $q = mysqli_query(dbc(), "UPDATE applicants SET
    				type_id = '$pt', department_id = '$dept',
					programme_id = '$pid', programme_applied_for ='$pid',
                    department_applied_for ='$dept',
                    admission_status = '1', qualified = '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 get total students_ncein NCe programme
function get_total_admtted_applicants($adm_stat , $qi)
{
	$q = "SELECT COUNT(id) FROM applicants  WHERE admission_status = '$adm_stat' AND qualified = '$qi'";

	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}
//function get total students_ncein NCe programme
function get_total_admtted_applicants_niger_state($adm_stat , $qi)
{
	$q = "SELECT COUNT(id) FROM applicants  WHERE admission_status = '$adm_stat' AND qualified = '$qi' AND state_id = 27";

	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}
//function get total students_ncein NCe programme
function get_total_admtted_applicants_other_state($adm_stat , $qi)
{
	$q = "SELECT COUNT(id) FROM applicants  WHERE admission_status = '$adm_stat' AND qualified = '$qi' AND state_id != 27";

	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_array($r,MYSQLI_NUM);

	return $row[0];

}
//get course name passed by id of the course
function get_programme_level($id)
{
	$result = mysqli_query(dbc(), "SELECT level FROM programmes WHERE id = '$id'");
		$row = mysqli_fetch_assoc($result);
		$level = $row['level'];

	return $level;
}
//get admit menu based level
function get_to_admit_based_on_level($app_id, $app_lev)
{
	$output_q ='';
	$cert_res_arr = array();

	$q = "SELECT * FROM `applicants_institutions`
				WHERE user_id = '$app_id' ";

	$r = mysqli_query(dbc(), $q);

	if(mysqli_num_rows($r) > 0 ){

		while($rec = mysqli_fetch_array($r,MYSQLI_ASSOC)){
			//when not nce result
			if ($rec['cert'] != 2 ) {
				if ($rec['result'] > 0) {

					//store into array
					array_push($cert_res_arr, $rec['result'] );
				}

			}else{


			}
		}
	}




	$i ="";
	$ress = 0;
	//getting best result grade
	for ($i=0 ; $i <= count($cert_res_arr); $i++) {
		//validating result grade
		$c_res = $cert_res_arr[$i];
		if ($c_res < 6 && $c_res > 0) {
			//initially
			if ($ress < 1) {
				$ress = $c_res;
			}else{
				if ($c_res < $ress ) {
					$ress = $c_res;
				}else{
					//do nothing for now
					//$ress = $ress;
				}

			}
		}
	}


	//qualifying based on level
	if ($app_lev == 100) {
		$output_q .= '<td>
			<form method="POST" action="gateway.php">

              <input type="submit" name="clear_one"  class="btn btn-primary" value="Admit">
              <input type="hidden" name="act" value="view_qualified_applicants">
              <input type="hidden" name="app_id" value="'.$applicant_id.'">
              <br><br><br>

            </form>
		</td>';

	}elseif ($app_lev == 200) {

		//confirming if really qualified
		if ($ress < 6 && $ress > 0) {
			$output_q .= '<td>
				<form method="POST" action="gateway.php">

		          <input type="submit" name="clear_one"  class="btn btn-primary" value="Admit">
		          <input type="hidden" name="act" value="view_qualified_applicants">
		          <input type="hidden" name="app_id" value="'.$app_id.'">
		          <br><br><br>

		        </form>
			</td>';
		}else{
			$output_q = '';
		}

	}elseif ($app_lev == 300) {



	}


	/*$result = mysql_query("SELECT level FROM programmes WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$level = $row['level'];

	return $level;*/

	return $output_q;


}

function get_program_suggestions($app_id,$o_level,$level)
{
	/*for ($i=0; $i < count($o_level); $i++) {
		//echo $o_level[$i];
	}*/
//$pprogram = mysqli_query("SELECT * FROM ")
	$sug_cs_lists = get_suggested_program($app_id,$o_level,$level);


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

		$cs_arr = $sug_cs_lists;
	}

	//dont list  programme when no olevel
	if (applicant_olevel_exist($app_id)) {

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

 			';


	 		$output .= '

					<div class="bg-info">
						<div>
							<h5 class="text-center"><b>Change of Programme</b></h5>
							<select class="form-control" name="swap_prog_id" >
				                <option value=""> Select Programme </option>
				                '.

				                 //displaying the prence courses

				                list_course($sug_cs_lists)

				                .'
				            </select>
				            <input type="hidden" name="act" value="view_not_qualified_applicants">
				            <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>";


	}else{
		$sug_cs_lists = '';
		$cs_arr = '';
		$output = '<td></td>';

	}

	return $output;

}

function get_suggested_program($uid,$olevel_arr,$level )
{
	//intializing an array for tracking validated subjects
	$dt = array();
	$ff = '';
	$app_prog = get_user_programme_applied_for($uid);
	$pt = get_user_programme_type_applied_for($uid);

	$r = mysqli_query(dbc(), "SELECT title, id, required_subjects, optional_subjects,optional_count
					FROM programmes WHERE real_ = '0' AND type_id = '$pt' AND  level <= '$level'
					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(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r,MYSQLI_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];


}

//check if result already exist
function applicant_olevel_exist($iid)
{
	//check if invoice id generated exist
	$q1 = "SELECT applicant_id FROM applicants_olevel WHERE  applicant_id = '$iid'";
	$r1 = mysqli_query(dbc(), $q1);

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

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;

}



?>
