<?php 
##################################################################
#  This is the basic that can be called  within the web application
#  Include this after the configuration file on every page
#  File name: functions.php
##################################################################

//Call the configuration file
include('configuration.php');

//Get Current User's ID fro Ciokie if i need t use this in startic manner
	function get_user()
	{
		$user_id = $_COOKIE['loged_221'];
		return $user_id;
	}


//functio  that sets online visitors 
function set_online_visitors()
{
	
	//First we have to start the session only if it has not been started
	if(!isset($_SESSION)){
		@session_start();
	}
	
	$session_id = session_id();	//We assign the session id to the variable $session_id
	
	
	$time = time(); 	//We assign the current time to the variable $time
	
	
	
	$time_limit = $time-600;	//We give the session only 10 minutes if it exists
	
	
	/**
	*We need to check the session_id is already stored or not
	*/
	
	$num = mysqli_num_rows(mysqli_query(dbc(),"SELECT * FROM online_visitors WHERE session_id='{$session_id}' LIMIT 1"));
	
	
	
	//if it doesn't exist, then we'll store it
	//And if does exist, we will update the session's time in the DB
	if($num != 1)
	{
		$sql = "INSERT INTO online_visitors VALUES('{$session_id}','{$time}')";
		$query = mysqli_query(dbc(),$sql) or die("<span class='text-danger'>Error</span><br />".mysql_error());
	}else
	{
		$sql = "UPDATE online_visitors SET time='{$time}' WHERE session_id='{$session_id}'";
		$query = mysqli_query(dbc(),$sql) or die("<span class='text-danger'>Error</span>".mysql_error());
	}
	
	//Now the following code is to get the count of visitors currently online
	//$noov = mysqli_num_rows(mysqli_query(dbc(),"SELECT * FROM online_visitors"));  //noov = number of online visitors
	
	//echo 'Visitors currently online: ',$noov;
	
	//Now, check if the session was stored for more than 10 minutes and delete it if it is.
	$delete_session = mysqli_query(dbc(),"DELETE FROM online_visitors WHERE time<'{$time_limit}'");
	
	//close the connection
	//mysql_close();
	
	
}

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

	return $role_id;
	}

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

	return $last_login_ip;
	}

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

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

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

	return $username;
	}
	
	
	
//Function to fetch email
	function get_user_email($user_id)
	{
		$result = mysqli_query(dbc(),"SELECT * FROM users WHERE user_id = '$user_id'"); 
		$row = mysqli_fetch_assoc($result);
		$email = $row['email'];

	return $email;
	}
	
	
	//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 dat get user image by id 
	function get_user_image($user_id)
	{
	$q = "SELECT image FROM users WHERE user_id = '$user_id' ";
	$r = mysqli_query(dbc(),$q);
	$row = mysqli_fetch_assoc($r);
	
	return $row['image'];
	
	
	}
	
	//Function to fetch role name
	function get_role_title($role_id)
	{
		$result = mysqli_query(dbc(),"SELECT * FROM roles WHERE id = '$role_id'"); 
		$row = mysqli_fetch_assoc($result);
		$role_title = $row['role_title'];
		
	return $role_title;
	}


	
	//=========================================== get posted by by passing security ID == ===========/
	function get_posted_by($security_id)
	{	
		$query = "SELECT first_name, other_names as name
				 
				 FROM users
				 
				 WHERE security_id = '$security_id'";
					
		$result = mysqli_query(dbc(),$query); 
							
		$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
		$poster = $row['name'];
		
	return $poster;
	}
	
	
	
	// latest slider news 
	function get_latest_slider_updates()
	{
		$type = 'slider';
		
		$q = "SELECT id,title,LEFT(description, 100) as description,status,image, DATE_FORMAT(date_added, '%b %e, %Y %l:%i:%p') as date_added, added_by

		FROM news WHERE status = '0'  AND news_carts LIKE '%$type%'
		
		ORDER BY date_added DESC
		
		LIMIT 0,4";
		$r = mysqli_query(dbc(),$q);
		
		if(mysqli_num_rows($r)>0)
		{
			while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
			{
				
				///extract the description so dat 100 words can be displayed only
				$extract_description = $row['description'];
				$get_last_space = strrpos($extract_description, ' ');
				$extracted_description = substr($extract_description, 0, $get_last_space);
				
				
				$output  = '<a  href="single_news.php?i='.sha1($row['id']).'"><div class="item">';
				$output .= ' <img src="admin/uploads/pictures/news_images/'.$row['image'].'" height="340" width="1200" />';
				$output .= ' <div class="carousel-caption black_float_position">';
				$output .= ' <h3>'.$row['title'].'</h3>';
				$output .= '<p>'.$extracted_description.'</p>';
				//$output .=  get_posted_by($row['added_by']).'';
				$output .= '</div></div></a>';
				
				
			
				
				echo $output;
			}
		}
		
		
	}//end of get latest slider update
	
	
	
	
	//============================================ latest updates index.php =========================================//
	//function that gets tge latest four news on index.php
	function get_latest_updates()
	{
		$type = 'general';
		
		$q = "SELECT id,title,LEFT(description, 250) as description,status,image, DATE_FORMAT(date_added, '%b %e, %Y %l:%i:%p') as date_added, added_by

		FROM news WHERE status = '0' AND news_carts LIKE '%$type%'
		
		ORDER BY date_added DESC
		
		LIMIT 0,3";
		$r = mysqli_query(dbc(),$q);
		
		if(mysqli_num_rows($r)>0)
		{
			while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
			{
				
				///extract the description so dat 100 words can be displayed only
				$extract_description = $row['description'];
				$get_last_space = strrpos($extract_description, ' ');
				$extracted_description = substr($extract_description, 0, $get_last_space);
				
				
				$output  = '<div class="col-md-4 text-justify">';
				$output .= '<img class="img-responsive img-rounded" width="100px" height="100px" 
							src="admin/uploads/pictures/news_images/'.$row['image'].'"  style="float:left; margin:5px;" />';
				$output .= '';
				$output .= '<b>'.$row['title'].'</b>';
				$output .= '<p>'.$extracted_description.'... <p class="label label-default">'.$row['date_added'].'</p><hr/>';
				//$output .=  get_posted_by($row['added_by']).'<hr/>';
				$output .= '<a class="btn btn-sm btn-success" href="single_news.php?i='.sha1($row['id']).'"> Read More</a></p> ';
				$output .= '</div>';
				
				
				echo $output;
			}
		}
		
		
	}//end of get latest update
	
	
	
	// latest news from admin
	function get_latest_admin_updates()
	{
		$type = 'admin';
		
		$q = "SELECT id,title,LEFT(description, 250) as description,status,image, DATE_FORMAT(date_added, '%b %e, %Y %l:%i:%p') as date_added, added_by

		FROM news WHERE status = '0'  AND news_carts LIKE '%$type%'
		
		ORDER BY date_added DESC
		
		LIMIT 0,3";
		$r = mysqli_query(dbc(),$q);
		
		if(mysqli_num_rows($r)>0)
		{
			while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
			{
				
				///extract the description so dat 100 words can be displayed only
				$extract_description = $row['description'];
				$get_last_space = strrpos($extract_description, ' ');
				$extracted_description = substr($extract_description, 0, $get_last_space);
				
				
				$output  = '<div class="col-md-4 text-justify">';
				$output .= '<img class="img-responsive img-rounded" width="100px" height="100px" 
							src="admin/uploads/pictures/news_images/'.$row['image'].'"  style="float:left; margin:5px;" />';
				$output .= '';
				$output .= '<b>'.$row['title'].'</b>';
				$output .= '<p>'.$extracted_description.'... <p class="label label-default">'.$row['date_added'].'</p><hr/>';
				//$output .=  get_posted_by($row['added_by']).'';
				$output .= '<a class="btn btn-sm btn-success" href="single_news.php?i='.sha1($row['id']).'"> Read More</a></p> ';
				$output .= '</div>';
				
				
				echo $output;
			}
		}
		
		
	}//end of get latest update
	
	
	// latest news from department 
	function get_latest_department_updates()
	{
		$type = 'department';
		
		$q = "SELECT id,title,LEFT(description, 250) as description,status,image, DATE_FORMAT(date_added, '%b %e, %Y %l:%i:%p') as date_added, added_by

		FROM news WHERE status = '0'  AND news_carts LIKE '%$type%'
		
		ORDER BY date_added DESC
		
		LIMIT 0,3";
		$r = mysqli_query(dbc(),$q);
		
		if(mysqli_num_rows($r)>0)
		{
			while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
			{
				
				///extract the description so dat 100 words can be displayed only
				$extract_description = $row['description'];
				$get_last_space = strrpos($extract_description, ' ');
				$extracted_description = substr($extract_description, 0, $get_last_space);
				
				
				$output  = '<div class="col-md-4 text-justify">';
				$output .= '<img class="img-responsive img-rounded" width="100px" height="100px" 
							src="admin/uploads/pictures/news_images/'.$row['image'].'"  style="float:left; margin:5px;" />';
				$output .= '';
				$output .= '<b>'.$row['title'].'</b>';
				$output .= '<p>'.$extracted_description.'... <p class="label label-default">'.$row['date_added'].'</p><hr/>';
				//$output .=  get_posted_by($row['added_by']).'';
				$output .= '<a class="btn btn-sm btn-success" href="single_news.php?i='.sha1($row['id']).'"> Read More</a></p> ';
				$output .= '</div>';
				
				
				echo $output;
			}
		}
		
		
	}//end of get latest update
	
	
	
	
	//function get lates events on index.php 
	function get_latest_events()
	{
		$q = "SELECT id,title,LEFT(description, 100) as description, image, venue, event_date, start_time, end_time, DATE_FORMAT(date_added, '%b %e, %Y %l:%i:%p') as date_added, DATE_FORMAT(event_date, '%b') as event_month, 
			DATE_FORMAT(event_date, '%e') as event_day,added_by

		FROM events WHERE status = '0'
		
		ORDER BY date_added DESC
		
		LIMIT 0,5";
		$r = mysqli_query(dbc(),$q);
		
		if(mysqli_num_rows($r)>0)
		{
			while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
			{
				
				
				$output  = '<a style="text-decoration:none;color:#666;" class="text-justify" href="single_event.php?i='.sha1($row['id']).'">';
				$output .= '<div style="float:left;margin-right:7px;"><div class="event_green_bg text-center">'.$row['event_month'].'</div><div class="event_white_bg text-center">'.$row['event_day'].'</div></div>';
				$output  .= $row['title'];
				$output .= ' <br> <i class="glyphicon glyphicon-time"></i> '.$row['start_time'].' - '.$row['end_time'].' <br> <i class="glyphicon glyphicon-map-marker"></i> '.$row['venue'];
				$output  .= '</a><br> <hr/>';
				
				echo $output;
			}
		}
		
	}//end of get latest events
	
	/*======================================  index functions end ==============================*/



/* ============================================== news functions begn ===============================*/

	
//function view news

function show_news()
{
	
	
	//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(id) 
			
			  FROM  news WHERE status = '0'";
		$r = @mysqli_query(dbc(),$q);
			
		$row = @mysqli_fetch_array($r, MYSQLI_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 'title':
		$order_by = 'title ASC';
		
		break;
		
		case 'description':
		$order_by = 'description ASC';
		
		break;
		
		
		case 'added_by':
		$order_by = 'added_by ASC';
		
		break;
		
		
		case 'date_added':
		$order_by = 'date_added ASC';
		
		break;
		
		case 'date_modified':
		$order_by = 'date_added ASC';
		
		break;
		
		
		default:
		$order_by = 'date_added DESC';
		
		break;
		
		
	}
	
	
	
	
	//query the database
	$q = "SELECT id, title, LEFT(description, 150) as description, image,		  
		 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  news WHERE status = '0'
		 ORDER BY $order_by LIMIT $start , $display_per_page";
	$r = mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) > 0)
	{//show table
	
		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			///extract the description so dat 100 words can be displayed only
			$extract_description = $row['description'];
			$get_last_space = strrpos($extract_description, ' ');
			$extracted_description = substr($extract_description, 0, $get_last_space);
			
			
			$output = '<div class="col-md-12 text-center">';
			$output .= '<div class="col-md-6 text-center">';
			$output .='<img class="img-rounded  img-responsive center-block" width="200px" height="200px" 
						src="admin/uploads/pictures/news_images/'.$row['image'].'" />' ;
			$output .= '<br>';
			
			$output .= '</div>'; 
			$output .= '<div class="col-md-6 text-left">';
			$output .= '<h4><b>'.$row['title'].'</b></h4> <span class="label label-default">'.$row['date_added'].'</span>';
			$output .= '<p>'.strip_tags ($extracted_description).'- '.get_posted_by($row['added_by']).'</p>';
			$output .= '<a class="btn btn-sm btn-success" href="single_news.php?i='.sha1($row['id']).'"> Read More</a>';
			$output .= '</div><br/>';
			$output .= '</div>';
			$output .= '<br><div class="col-md-12 text-center"><hr>';
			$output .= '<br/><br/></div>';
			
			echo $output;
			
		}
	}
	
	
	//check if pages is greater than 1
	if($pages > 1)
	{
		echo '<div class="text-center"><ul class="pagination">';
		
		//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 '<li><a href="news.php?sort='.$sort.'&start='.($start - $display_per_page).'&page='.$pages.'" >«</a></li>';
		}
		
		
		//make all the numbered pages
		for($i = 1; $i <= $pages; $i++)
		{
			if($i != $current_page)
			{
				echo 
				'<li><a href="news.php?sort='.$sort.'&start='.(($display_per_page * ($i - 1)))  .'&page='.$pages.'" >' . $i . '</a> </li>';
			}
			else
			{
				echo  '<li><a href="#">'. $i . '</a></li> ';
			}
		}//end of forloop
		
		
		//if itsnt d last page get the necxt link
		if($current_page != $pages)
		{
			echo '<li><a href="news.php?sort='.$sort.'&start='.($start + $display_per_page).'&page='.$pages.'">»</a></li>';
			
		}
	}
	
	
	
	
	
	echo '</ul></div>';
								

	
	
	
	
	
}//end of view news


//function that shows the news, title, news date , news posted by 
function get_news_title($id)
{
	$q = "SELECT title FROM news  WHERE '$id' = SHA1(id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$title = $row['title'];
	}
	
	return $title;
	
}

//function that gets the date news was posted 
function get_news_date($id)
{
	$q = "SELECT DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added FROM news WHERE '$id' = SHA1(id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$date_added = $row['date_added'];
	}
	
	return $date_added;
	
}
//end of get when news was posted


//function that  news posted by on signle_news.php page
function get_news_poster($id)
{
	$q = "SELECT n.id as nid, n.title, n.added_by, u.user_id as uid, u.first_name, u.security_id 
	   FROM news n , users u
	  
	   WHERE 
	   u.security_id = n.added_by
		AND '$id' = SHA1(id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$first_name = $row['first_name'];
	}
	
	return $first_name;
	
}//end of get poster for a single page


//function that gets the image for single_news.php
function get_news_image($id)
{
	$q = "SELECT image FROM news WHERE '$id' = SHA1(id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$image = $row['image'];
	}
	
	return $image;
	
}
//end of get when image




//function that gets news description for single_news.php
function get_news_description($id)
{
	$q = "SELECT description FROM news WHERE '$id' = SHA1(id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$description = $row['description'];
	}
	
	return $description;
	
}
//end of get when description



//show eevnts on single_news.php page
function show_3_events()
{
	
	
	//query the database
	$q = "SELECT id, title, LEFT(description, 150) as description, image,		  
		 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 = '0'
		 ORDER BY date_added DESC LIMIT 0 , 3";
	$r = mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) > 0)
	{//show table
	
		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			///extract the description so dat 100 words can be displayed only
			$extract_description = $row['description'];
			$get_last_space = strrpos($extract_description, ' ');
			$extracted_description = substr($extract_description, 0, $get_last_space);
			
			
			$output = '<div class="col-md-12 text-center">';
			$output .= '<div class="col-md-6 text-center">';
			$output .='<img class="img-circle center-block" width="100px" height="100px" 
						src="admin/uploads/pictures/events_images/'.$row['image'].'" />' ;
			$output .= '<br>';
			
			$output .= '</div>'; 
			$output .= '<div class="col-md-6">';
			$output .= '<h4><b>'.$row['title'].'</b></h4>';
			$output .= '<p>'.$extracted_description.'</p>';
			$output .= '<a class="btn btn-sm btn-success" href="single_event.php?i='.sha1($row['id']).'"> Read More</a>';
			$output .= '</div>';
			$output .= '</div>';
			$output .= '<div class="col-md-12 text-center"><br/><hr/></div>';
			
			echo $output;
			
		}
	}
	
	
								

	
	
	
	
	
}//end of events single_news.php


/* ======================================= end of news funtion =====================================*/


function show_events()
{
	
	
	//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(id) 
			
			  FROM  events WHERE status = '0'";
		$r = @mysqli_query(dbc(),$q);
			
		$row = @mysqli_fetch_array($r, MYSQLI_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 'title':
		$order_by = 'title ASC';
		
		break;
		
		case 'description':
		$order_by = 'description ASC';
		
		break;
		
		
		case 'added_by':
		$order_by = 'added_by ASC';
		
		break;
		
		
		case 'date_added':
		$order_by = 'date_added ASC';
		
		break;
		
		case 'date_modified':
		$order_by = 'date_added ASC';
		
		break;
		
		
		default:
		$order_by = 'date_added DESC';
		
		break;
		
		
	}
	
	
	
	
	//query the database

	$q = "SELECT id, title, LEFT(description, 150) as description, image,		  
		 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 = '0'
		 ORDER BY $order_by LIMIT $start , $display_per_page";
	$r = mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) > 0)
	{//show table
	
		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			///extract the description so dat 100 words can be displayed only
			$extract_description = $row['description'];
			$get_last_space = strrpos($extract_description, ' ');
			$extracted_description = substr($extract_description, 0, $get_last_space);
			
			
			$output = '<div class="col-md-12 text-center">';
			$output .= '<div class="col-md-6 text-center">';
			$output .='<img class="img-thumbnail  img-responsive center-block" width="200px" height="200px" 
						src="admin/uploads/pictures/events_images/'.$row['image'].'" />' ;
			$output .= '<br>';
			
			$output .= '</div>'; 
			$output .= '<div class="col-md-6">';
			$output .= '<h4><b>'.$row['title'].'</b></h4> <span class="label label-default">'.$row['date_added'].'</span>';
			$output .= '<p>'.$extracted_description.'</p>';
			$output .= '<a class="btn btn-sm btn-success" href="single_event.php?i='.sha1($row['id']).'"> Read More</a>';
			$output .= '</div><br/><hr/>';
			$output .= '</div>';
			$output .= '';
			
			echo $output;
			
		}
	}
	
	
	//check if pages is greater than 1
	if($pages > 1)
	{
		echo '<div class="text-center"><ul class="pagination">';
		
		//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 '<li><a href="events.php?sort='.$sort.'&start='.($start - $display_per_page).'&page='.$pages.'" >«</a></li>';
		}
		
		
		//make all the numbered pages
		for($i = 1; $i <= $pages; $i++)
		{
			if($i != $current_page)
			{
				echo 
				'<li><a href="events.php?sort='.$sort.'&start='.(($display_per_page * ($i - 1)))  .'&page='.$pages.'" >' . $i . '</a> </li>';
			}
			else
			{
				echo  '<li><a href="#">'. $i . '</a></li> ';
			}
		}//end of forloop
		
		
		//if itsnt d last page get the necxt link
		if($current_page != $pages)
		{
			echo '<li><a href="events.php?sort='.$sort.'&start='.($start + $display_per_page).'&page='.$pages.'">»</a></li>';
			
		}
	}
	
	
	
	
	
	echo '</ul></div>';
								

	
	
	
	
	
}//end of view events



//function that shows the events, title, events date , events posted by 
function get_event_title($id)
{
	$q = "SELECT title FROM events WHERE '$id' = SHA1(id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$title = $row['title'];
	}
	
	return $title;
	
}

//function that gets the date event was posted 
function get_event_date($id)
{
	$q = "SELECT DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added FROM events WHERE '$id' = SHA1(id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$date_added = $row['date_added'];
	}
	
	return $date_added;
	
}
//end of get when events was posted


//function that  event posted by on signle_event.php page
function get_event_poster($id)
{
	$q = "SELECT e.id as eid, e.title, e.added_by, u.user_id as uid, u.first_name, u.security_id 
	   FROM events e , users u
	  
	   WHERE 
	   u.security_id = e.added_by
		AND '$id' = SHA1(id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$first_name = $row['first_name'];
	}
	
	return $first_name;
	
}//end of get poster for a single page


//function that gets the image for single_event.php
function get_event_image($id)
{
	$q = "SELECT image FROM events WHERE '$id' = SHA1(id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$image = $row['image'];
	}
	
	return $image;
	
}
//end of get when image




//function that gets events description for single_event.php
function get_event_description($id)
{
	$q = "SELECT description FROM events WHERE '$id' = SHA1(id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$description = $row['description'];
	}
	
	return $description;
	
}
//end of get when description  



//pictures 
function show_pictures()
{
	
	
	//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(id) 
			
			  FROM  pictures WHERE status = '0'";
		$r = @mysqli_query(dbc(),$q);
			
		$row = @mysqli_fetch_array($r, MYSQLI_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 'title':
		$order_by = 'title ASC';
		
		break;
		
		case 'description':
		$order_by = 'description ASC';
		
		break;
		
		
		case 'added_by':
		$order_by = 'added_by ASC';
		
		break;
		
		
		case 'date_added':
		$order_by = 'date_added ASC';
		
		break;
		
		case 'date_modified':
		$order_by = 'date_added ASC';
		
		break;
		
		
		default:
		$order_by = 'date_added DESC';
		
		break;
		
		
	}
	
	
	
	
	//query the database

	$q = "SELECT id, title, LEFT(description, 150) as description, image,		  
		 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  pictures WHERE status = '0'
		 ORDER BY $order_by LIMIT $start , $display_per_page";
	$r = mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) > 0)
	{//show table
	
		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			///extract the description so dat 100 words can be displayed only
			$id =  $row['id'];
			$extract_description = $row['description'];
			$get_last_space = strrpos($extract_description, ' ');
			$extracted_description = substr($extract_description, 0, $get_last_space);
			

			
			
			
			//$output = '<h4 class="text-danger">'.get_picture_title($id).'</h4>';
			 $output = '<div class="gallery_wrapper col-lg-3"> ';
			 $output .=		'<h4 class="text-primary">'.get_picture_title($id).'</h4>';
			 $output .= 	'<a  class="photobox_a" href="admin/uploads/pictures/gallery_pictures/'.$row['image'].'" title="'.get_picture_description($id) .'">';
             $output .=      '<img class="small-img" src="admin/uploads/pictures/gallery_pictures/'.$row['image'].'"  width="150" height="150" 
			 				alt="'.get_picture_title($id).' Posted By '.get_picture_poster($id).'" /></a>';
		     $output .=	'</div>';
						
			echo $output;
		}
	}
	
	
	//check if pages is greater than 1
	if($pages > 1)
	{
		echo '<div class="text-center"><ul class="pagination">';
		
		//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 '<li><a href="pictures.php?sort='.$sort.'&start='.($start - $display_per_page).'&page='.$pages.'" >«</a></li>';
		}
		
		
		//make all the numbered pages
		for($i = 1; $i <= $pages; $i++)
		{
			if($i != $current_page)
			{
				echo 
				'<li><a href="pictures.php?sort='.$sort.'&start='.(($display_per_page * ($i - 1)))  .'&page='.$pages.'" >' . $i . '</a> </li>';
			}
			else
			{
				echo  '<li><a href="#">'. $i . '</a></li> ';
			}
		}//end of forloop
		
		
		//if itsnt d last page get the necxt link
		if($current_page != $pages)
		{
			echo '<li><a href="pictures.php?sort='.$sort.'&start='.($start + $display_per_page).'&page='.$pages.'">»</a></li>';
			
		}
	}
	
	
	
	
	
	echo '</ul></div>';
								

	
	
	
	
	
}//end of view pictures





//function that shows the pictures, title, pictures date , pictures posted by 
function get_picture_title($id)
{
	$q = "SELECT title FROM pictures WHERE '$id' = (id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$title = $row['title'];
	}
	
	return $title;
	
}

//function that gets the date picture was posted 
function get_picture_date($id)
{
	$q = "SELECT DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added FROM pictures WHERE '$id' = (id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$date_added = $row['date_added'];
	}
	
	return $date_added;
	
}
//end of get when pictures was posted


//function that  picture posted by on signle_picture.php page
function get_picture_poster($id)
{
	$q = "SELECT p.id as pid, p.title, p.added_by, u.user_id as uid, u.first_name, u.security_id 
	   FROM pictures p , users u
	  
	   WHERE 
	   u.security_id = p.added_by
		AND '$id' = (id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$first_name = $row['first_name'];
	}
	
	return $first_name;
	
}//end of get poster for a single page


//function that gets the image for single_picture.php
function get_picture_image($id)
{
	$q = "SELECT image FROM pictures WHERE '$id' = (id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$image = $row['image'];
	}
	
	return $image;
	
}
//end of get when image




//function that gets pictures description for 
function get_picture_description($id)
{
	$q = "SELECT description FROM pictures WHERE '$id' = (id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$description = $row['description'];
	}
	
	return $description;
	
}
//end of get when description 






//videos
function show_videos()
{
	
	
	//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(id) 
			
			  FROM  videos WHERE status = '0'";
		$r = @mysqli_query(dbc(),$q);
			
		$row = @mysqli_fetch_array($r, MYSQLI_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 'title':
		$order_by = 'title ASC';
		
		break;
		
		case 'description':
		$order_by = 'description ASC';
		
		break;
		
		
		case 'added_by':
		$order_by = 'added_by ASC';
		
		break;
		
		
		case 'date_added':
		$order_by = 'date_added ASC';
		
		break;
		
		case 'date_modified':
		$order_by = 'date_added ASC';
		
		break;
		
		
		default:
		$order_by = 'date_added DESC';
		
		break;
		
		
	}
	
	
	
	
	//query the database

	$q = "SELECT id, title, LEFT(description, 150) as description, image,		  
		 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  videos WHERE status = '0'
		 ORDER BY $order_by LIMIT $start , $display_per_page";
	$r = mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) > 0)
	{//show table
	
		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			///extract the description so dat 100 words can be displayed only
			$extract_description = $row['description'];
			$get_last_space = strrpos($extract_description, ' ');
			$extracted_description = substr($extract_description, 0, $get_last_space);
			
			
			$output = '<div class="col-md-12 text-center">';
			$output .= '<div class="col-md-6 text-center">';
			$output .='<img class="img-thumbnail  img-responsive center-block" width="200px" height="200px" 
						src="admin/uploads/pictures/video_pictures/'.$row['image'].'" />' ;
			$output .= '<br>';
			
			$output .= '</div>'; 
			$output .= '<div class="col-md-6">';
			$output .= '<h4><b>'.$row['title'].'</b></h4> <span class="label label-default">'.$row['date_added'].'</span>';
			$output .= '<p>'.$extracted_description.'</p>';
			$output .= '<a class="btn btn-sm btn-success" href="single_video.php?i='.sha1($row['id']).'"> Read More</a>';
			$output .= '</div>';
			$output .= '</div>';
			$output .= '<div class="col-md-12 text-center"><br/><hr/></div>';
			
			echo $output;
			
		}
	}
	
	
	//check if pages is greater than 1
	if($pages > 1)
	{
		echo '<div class="text-center"><ul class="pagination">';
		
		//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 '<li><a href="videos.php?sort='.$sort.'&start='.($start - $display_per_page).'&page='.$pages.'" >«</a></li>';
		}
		
		
		//make all the numbered pages
		for($i = 1; $i <= $pages; $i++)
		{
			if($i != $current_page)
			{
				echo 
				'<li><a href="videos.php?sort='.$sort.'&start='.(($display_per_page * ($i - 1)))  .'&page='.$pages.'" >' . $i . '</a> </li>';
			}
			else
			{
				echo  '<li><a href="#">'. $i . '</a></li> ';
			}
		}//end of forloop
		
		
		//if itsnt d last page get the necxt link
		if($current_page != $pages)
		{
			echo '<li><a href="videos.php?sort='.$sort.'&start='.($start + $display_per_page).'&page='.$pages.'">»</a></li>';
			
		}
	}
	
	
	
	
	
	echo '</ul></div>';
								

	
	
	
	
	
}//end of view videos



//function that shows the videos, title, videos date , video posted by 
function get_video_title($id)
{
	$q = "SELECT title FROM videos WHERE '$id' = SHA1(id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$title = $row['title'];
	}
	
	return $title;
	
}

//function that gets the date video was posted 
function get_video_date($id)
{
	$q = "SELECT DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added FROM videos WHERE '$id' = SHA1(id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$date_added = $row['date_added'];
	}
	
	return $date_added;
	
}
//end of get when video was posted


//function that  video posted by on signle_video.php page
function get_video_poster($id)
{
	$q = "SELECT v.id as vid, v.title, v.added_by, u.user_id as uid, u.first_name, u.security_id 
	   FROM videos v , users u
	  
	   WHERE 
	   u.security_id = u.added_by
		AND '$id' = SHA1(id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$first_name = $row['first_name'];
	}
	
	return $first_name;
	
}//end of get poster for a single page


//function that gets the image for single_video.php
function get_video_image($id)
{
	$q = "SELECT image FROM videos WHERE '$id' = SHA1(id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$image = $row['image'];
	}
	
	return $image;
	
}
//end of get  image for the video

//function that gets the youtube link for single_video.php
function get_video_youtube_link($id)
{
	$q = "SELECT youtube_link FROM videos WHERE '$id' = SHA1(id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$image = $row['image'];
	}
	
	return $image;
	
}
//end of get  youtube link for the video




//function that gets videos description for single_video.php
function get_video_description($id)
{
	$q = "SELECT description FROM videos WHERE '$id' = SHA1(id)";
	$r= mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) >0)
	{
		$row = mysqli_fetch_array($r, MYSQLI_ASSOC);
		
		$description = $row['description'];
	}
	
	return $description;
	
}
//end of get video description  




//show eevnts on single_event.php page
function show_5_news()
{
	
	
	//query the database
	$q = "SELECT id, title, LEFT(description, 100) as description, image,		  
		 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  news WHERE status = '0'
		 ORDER BY date_added DESC LIMIT 0 , 5";
	$r = mysqli_query(dbc(),$q);
	
	if(mysqli_num_rows($r) > 0)
	{//show table
	
		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			///extract the description so dat 100 words can be displayed only
			$extract_description = $row['description'];
			$get_last_space = strrpos($extract_description, ' ');
			$extracted_description = substr($extract_description, 0, $get_last_space);
			
			
			$output = '<div class="col-md-12 text-center">';
			$output .= '<div class="col-md-6 text-center">';
			$output .='<img class="img-circle center-block" width="100px" height="100px" 
						src="admin/uploads/pictures/news_images/'.$row['image'].'" />' ;
			$output .= '<br>';
			
			$output .= '</div>'; 
			$output .= '<div class="col-md-6">';
			$output .= '<h4><b>'.$row['title'].'</b></h4>';
			$output .= '<p>'.htmlentities ($extracted_description).'</p>';
			$output .= '<a class="btn btn-sm btn-success" href="single_news.php?i='.sha1($row['id']).'"> Read More</a>';
			$output .= '</div><br/>';
			$output .= '</div>';
			$output .= '<div class="col-md-12 text-center"><hr /></div>';
			
			echo $output;
			
		}
	}
	
	
	
	
}//end of events single_event.php


/* ============================================================= end of event functions =================================*/



//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 select_lga( $lga)
{
	$r = mysqli_query(dbc(),"SELECT id, title  FROM lga  ORDER BY title ");
	if(mysqli_num_rows($r) > 0 )
	{
		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			if($lga == $row['id'])
			{
				$output = "<option value=\"$row[id]\" selected>";
				$output .=  $row['title'];
				$output .="</option>";
				
			}
			else
			{
				$output = "<option value=\"$row[id]\" >";
				$output .= $row['title'];
				$output .="</option>";
				
			}
			 
			
			echo $output;
		}
	}
	else
	{
		
			$output = "<option>";
			$output .="Not added yet";
			$output .="</option>"; 
			
			echo $output;
	}
}
//end of select lga



//function calendar yer
function year($y)
{
	$y = $y;
	$years = range(1980, 2014);
	
	foreach ($years as $value) 
	{
		if($y == $value)
		{
	   		echo "<option value=\"$value\" selected>$value</option>\n";
		}
		else
		{
			echo "<option value=\"$value\">$value</option>\n";
		}
	}
	
	
}

/*
//function grade
function grades($g) //passed a parameter $g
{
	 if($g == 'A1')
	 {
		 echo
		'<option value="A1" selected="selected">A1</option>
		<option value="B2">B2</option>
		<option value="B3">B3</option>
		<option value="C4">C4</option>
		<option value="C5">C5</option>
		<option value="C6">C6</option>
		<option value="D7">D7</option>
		<option value="E8">E8</option>
		<option value="F9">F9</option> ';
	 }else if($g == 'B2')
	 {
		  echo
		'<option value="A1" >A1</option>
		<option value="B2" selected="selected">B2</option>
		<option value="B3">B3</option>
		<option value="C4">C4</option>
		<option value="C5">C5</option>
		<option value="C6">C6</option>
		<option value="D7">D7</option>
		<option value="E8">E8</option>
		<option value="F9">F9</option> ';
	 }else if($g == 'B3')
	 {
		  echo
		'<option value="A1" >A1</option>
		<option value="B2" >B2</option>
		<option value="B3" selected="selected">B3</option>
		<option value="C4">C4</option>
		<option value="C5">C5</option>
		<option value="C6">C6</option>
		<option value="D7">D7</option>
		<option value="E8">E8</option>
		<option value="F9">F9</option> '; 
	 }else if ($g == 'C4')
	 {
		 echo
		'<option value="A1" >A1</option>
		<option value="B2" >B2</option>
		<option value="B3" >B3</option>
		<option value="C4"selected="selected">C4</option>
		<option value="C5">C5</option>
		<option value="C6">C6</option>
		<option value="D7">D7</option>
		<option value="E8">E8</option>
		<option value="F9">F9</option> '; 	 
	 }else if($g == 'C5')
	 {
		  echo
		'<option value="A1" >A1</option>
		<option value="B2" >B2</option>
		<option value="B3" >B3</option>
		<option value="C4">C4</option>
		<option value="C5" selected="selected">C5</option>
		<option value="C6">C6</option>
		<option value="D7">D7</option>
		<option value="E8">E8</option>
		<option value="F9">F9</option> '; 	
	 }else if($g == 'C6')
	 {
		 
		  echo
		'<option value="A1" >A1</option>
		<option value="B2" >B2</option>
		<option value="B3" >B3</option>
		<option value="C4">C4</option>
		<option value="C5" >C5</option>
		<option value="C6" selected="selected">C6</option>
		<option value="D7">D7</option>
		<option value="E8">E8</option>
		<option value="F9">F9</option> '; 
	 }else if($g == 'D7')
	 {
		  echo
		'<option value="A1" >A1</option>
		<option value="B2" >B2</option>
		<option value="B3" >B3</option>
		<option value="C4">C4</option>
		<option value="C5" >C5</option>
		<option value="C6" >C6</option>
		<option value="D7" selected="selected" >D7</option>
		<option value="E8">E8</option>
		<option value="F9">F9</option> '; 
	 }else if($g == 'E8')
	 {
		 echo
		'<option value="A1" >A1</option>
		<option value="B2" >B2</option>
		<option value="B3" >B3</option>
		<option value="C4">C4</option>
		<option value="C5" >C5</option>
		<option value="C6" >C6</option>
		<option value="D7"  >D7</option>
		<option value="E8"selected="selected">E8</option>
		<option value="F9">F9</option> '; 
	 }else if ($g == 'F9')
	 {
		  echo
		'<option value="A1" >A1</option>
		<option value="B2" >B2</option>
		<option value="B3" >B3</option>
		<option value="C4">C4</option>
		<option value="C5" >C5</option>
		<option value="C6" >C6</option>
		<option value="D7"  >D7</option>
		<option value="E8">E8</option>
		<option value="F9" selected="selected">F9</option> '; 
		 
	 }else
	 {
		  echo
		'<option value="A1" >A1</option>
		<option value="B2" >B2</option>
		<option value="B3" >B3</option>
		<option value="C4">C4</option>
		<option value="C5" >C5</option>
		<option value="C6" >C6</option>
		<option value="D7"  >D7</option>
		<option value="E8">E8</option>
		<option value="F9" >F9</option> '; 
		 
	 }
	 
	 
                          			  
}//end of function grade 
*/


//function check tid limit
function is_tid_limit()
{
	//collect the total tid generated
	$total = get_total_tid_generated();
	
	
	if($total <= 600)
	{
		return false;
	}
	else
	{
		return true;
	}
}



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

	return $v;
}


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

	return $v;
}



//get department hod picture
function get_department_hod_picture($id)
{
	$result = mysqli_query(dbc(),"SELECT hod_picture FROM departments WHERE id = '$id'"); 
	$row = mysqli_fetch_assoc($result);
	$v = $row['hod_picture'];

	return $v;
}

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

	return $v;
}

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

	return $v;
}


//get department phone cotacts
function get_department_phone_no($id)
{
	$result = mysqli_query(dbc(),"SELECT phone_contacts FROM departments WHERE id = '$id'"); 
	$row = mysqli_fetch_assoc($result);
	$v = $row['phone_contacts'];

	return $v;
}



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

	return $v;
}


//get department history introduction
function get_department_introduction($id)
{
	$result = mysqli_query(dbc(),"SELECT history_introduction FROM departments WHERE id = '$id'"); 
	$row = mysqli_fetch_assoc($result);
	$v = $row['history_introduction'];

	return $v;
}


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

	return $v;
}
//function get department programme offered
function get_department_programmes($id, $path)
{
		
		
		$q = "SELECT id, department_id, title,status,picture, LEFT(history, 250) as history, DATE_FORMAT(date_added, '%b %e, %Y %l:%i:%p') as date_added, added_by

		FROM programmes WHERE status = '0' AND department_id =  '$id'
		
		ORDER BY title ASC";
		$r = mysqli_query(dbc(),$q);
		
		if(mysqli_num_rows($r)>0)
		{
			while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
			{
				
				///extract the description so dat 100 words can be displayed only
				$extract_description = $row['description'];
				$get_desc_last_space = strrpos($extract_description, ' ');
				$extracted_description = substr($extract_description, 0, $get_desc_last_space);
				
				
				///extract the philosophy_history so dat 100 words can be displayed only
				$extract_philosophy_history = $row['history'];
				$get_last_space = strrpos($extract_philosophy_history, ' ');
				$extracted_philosophy_history = substr($extract_philosophy_history, 0, $get_last_space);
				
				
				$output  = '<a  href="programmes/index.php?carryp='.$row['id'].'&carryd='.$row['department_id'].'" data-toggle="tooltip" title="Click to see more details on  '.$row['title'].'"> <div class="col-lg-3">';
				
				if($row['picture'] == '')
				{
					$output .= '<img class="img-responsive img-rounded" width="200px" height="100px" 
							src="'.$path.'images/alt_image_2.png"  style="float:left; margin:5px;" />';
					
				}
				else
				{
					$output .= '<img class="img-responsive img-rounded" width="200px" height="100px" 
							src="'.$path.'departments/programmes/pictures/'.$row['picture'].'"  style="float:left; margin:5px;" />';
				
				}
				
				$output .= '</div>';
				$output .= '<div class="col-lg-9">';
				$output .= '<h3 class="text-success" >'.$row['title'].'</h3>';
				$output .= '<p>'.$extracted_philosophy_history.'... </p>';
				$output .= '<hr/>';
				$output .= '</div></a><div style="clear:both"></div>';
				
				
				echo $output;
			}
		}
		
		
}//end of department programme offered

//get department staff list
function get_department_staff_list($id)
{
	$result = mysqli_query(dbc(),"SELECT staff_list_file FROM departments WHERE id = '$id'"); 
	$row = mysqli_fetch_assoc($result);
	$v = $row['staff_list_file'];

	return $v;
}
	
	
//get department pdf details
function get_department_pdf_details($id)
{
	$result = mysqli_query(dbc(),"SELECT department_details FROM departments WHERE id = '$id'"); 
	$row = mysqli_fetch_assoc($result);
	$v = $row['department_details'];

	return $v;
}
	


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

	return $v;
}




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

	return $v;
}


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

	return $v;
	
}


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

	return $v;
	
}


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

	return $v;
	
}

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

	return $v;
	
}



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

	return $v;
	
}


//function that gets programme min credit load
function  get_programme_min_credit_load($id)
{	
	$result = mysqli_query(dbc(),"SELECT minimum_credit_load FROM programmes WHERE id = '$id'"); 
		$row = mysqli_fetch_assoc($result);
		$v = $row['minimum_credit_load'];

	return $v;
	
}



//get programme history philosophy
function get_programme_introduction($id)
{
	$result = mysqli_query(dbc(),"SELECT history FROM programmes WHERE id = '$id'"); 
	$row = mysqli_fetch_assoc($result);
	$v = $row['history'];

	return $v;
}


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

	return $v;
}

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

	return $v;
}


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

	return $v;
}

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

	return $v;
}


//get programme entry requirement
function get_programme_entry_requirements($id)
{
	$result = mysqli_query(dbc(),"SELECT entry_requirements FROM programmes WHERE id = '$id'"); 
	$row = mysqli_fetch_assoc($result);
	$v = $row['entry_requirements'];

	return $v;
}



//get programme more details
function get_programme_pdf_details($id)
{
	$result = mysqli_query(dbc(),"SELECT programme_details FROM programmes WHERE id = '$id'"); 
	$row = mysqli_fetch_assoc($result);
	$v = $row['programme_details'];

	return $v;
}


//get programme course structures
function get_programme_course_structures($id)
{
	$result = mysqli_query(dbc(),"SELECT course_structures FROM programmes WHERE id = '$id'"); 
	$row = mysqli_fetch_assoc($result);
	$v = $row['course_structures'];

	return $v;
}



//function that gets faculty id of a department from departments table
function  get_faculty_id_of_department($id)
{	
	$result = mysqli_query(dbc(),"SELECT faculty_id FROM departments WHERE id = '$id'"); 
		$row = mysqli_fetch_assoc($result);
		$v = $row['faculty_id'];

	return $v;
	
}



//function that gets faculty title
function  get_faculty_title($id)
{	
	$result = mysqli_query(dbc(),"SELECT title FROM faculties WHERE id = '$id'"); 
		$row = mysqli_fetch_assoc($result);
		$v = $row['title'];

	return $v;
	
}



//get faculty picture
function get_faculty_picture($id)
{
	$result = mysqli_query(dbc(),"SELECT faculty_image FROM faculties WHERE id = '$id'"); 
		$row = mysqli_fetch_assoc($result);
		$v = $row['faculty_image'];

	return $v;
}




//function get  departments in faculty
function get_faculty_department($id, $path)
{
		
		
		$q = "SELECT id, faculty_id, title,status,department_image, LEFT(history_introduction, 250) as philosophy_history, description,
		DATE_FORMAT(date_added, '%b %e, %Y %l:%i:%p') as date_added, added_by

		FROM departments WHERE status = '0' AND faculty_id =  '$id'
		
		ORDER BY title ASC";
		$r = mysqli_query(dbc(),$q);
		
		if(mysqli_num_rows($r)>0)
		{
			while($row = mysqli_fetch_array($r,MYSQLI_ASSOC))
			{
				
				///extract the description so dat 100 words can be displayed only
				$extract_description = $row['description'];
				$get_desc_last_space = strrpos($extract_description, ' ');
				$extracted_description = substr($extract_description, 0, $get_desc_last_space);
				
				
				///extract the philosophy_history so dat 100 words can be displayed only
				$extract_philosophy_history = $row['philosophy_history'];
				$get_last_space = strrpos($extract_philosophy_history, ' ');
				$extracted_philosophy_history = substr($extract_philosophy_history, 0, $get_last_space);
				
				
				$output  = '<a  href="'.$path.'departments/index.php?carryd='.$row['id'].'&carryf='.$row['faculty_id'].'" data-toggle="tooltip" title="Click to see more details on  '.$row['title'].'"><div class="col-lg-3"> ';
				
				if($row['department_image'] == '')
				{
					$output .= '<img class="img-responsive img-rounded" width="200px" height="100px" 
							src="'.$path.'images/alt_image_2.png"  style="float:left; margin:5px;" />';
					
				}
				else
				{
					$output .= '<img class="img-responsive img-rounded" width="200px" height="100px" 
							src="'.$path.'departments/pictures/'.$row['department_image'].'"  style="float:left; margin:5px;" />';
				
				}
				$output .= '</div>';
				$output .= '<div class="col-lg-9">';
				$output .= '<h3 class="text-success" >'.$row['title'].'</h3>';
				$output .= '<p>'.$extracted_philosophy_history.'... </p>';
				$output .= '<hr/>';
				$output .= '</div></a> <div style="clear:both"></div>';
				
				
				echo $output;
			}
		}
		
		
}//end of department in faculties



//get faculty dean picture
function get_faculty_dean_picture($id)
{
	$result = mysqli_query(dbc(),"SELECT dean_picture FROM faculties WHERE id = '$id'"); 
	$row = mysqli_fetch_assoc($result);
	$v = $row['dean_picture'];

	return $v;
}

//get faculty dean name
function get_faculty_dean_name($id)
{
	$result = mysqli_query(dbc(),"SELECT dean_name FROM faculties WHERE id = '$id'"); 
	$row = mysqli_fetch_assoc($result);
	$v = $row['dean_name'];

	return $v;
}

//get faculty email
function get_faculty_email($id)
{
	$result = mysqli_query(dbc(),"SELECT email FROM faculties WHERE id = '$id'"); 
	$row = mysqli_fetch_assoc($result);
	$v = $row['email'];

	return $v;
}


//get faculties phone cotacts
function get_faculty_phone_no($id)
{
	$result = mysqli_query(dbc(),"SELECT phone_contacts FROM faculties WHERE id = '$id'"); 
	$row = mysqli_fetch_assoc($result);
	$v = $row['phone_contacts'];

	return $v;
}



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

	return $v;
}



//get faculties more details on pdf
function get_faculty_pdf_details($id)
{
	$result = mysqli_query(dbc(),"SELECT pdf_details FROM faculties WHERE id = '$id'"); 
	$row = mysqli_fetch_assoc($result);
	$v = $row['pdf_details'];

	return $v;
}



//get faculties history introduction
//function get_department_introduction($id)
//{
//	$result = mysqli_query(dbc(),"SELECT history_introduction FROM departments WHERE id = '$id'"); 
//	$row = mysqli_fetch_assoc($result);
//	$v = $row['history_introduction'];
//
//	return $v;
//}




?>