<?php
session_start();

require_once('../nce/includes/configuration.php');


ob_start();	

//function that clean all passed items from interface




//function get notifications error, info, info success




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

//collect the user id from the fucntion



//function that filters the browser
function filter_browser($browser, $platform)
{
  
  $browser = $browser;
  $platform =$platform;
  
  
 //reject user if not firefox  
  if($browser != 'Mozilla' )
  {
	  header('location:autorize_message/'); // show authorize message
  }
  
  if($platform != 'Windows!')
  {
	   header('location:autorize_message/'); // show authorize message
	  
  }
    
  
  
} // end of browser / platform filter



//function that set asset action to switch it to last action
function set_asset($user_id , $act)
{
	$q = "SELECT * FROM assets WHERE user_id = '$user_id'";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r)>0)
	{
		$query = "UPDATE assets SET action = '$act', date_added = NOW()";
		mysql_query($query);
	}
	else
	{
	
		$query = "INSERT INTO assets (id, user_id, action, date_added)
				VALUES (NULL, '$user_id', '$act', NOW())";
		mysql_query($query);
	}
}


//check if he has last action stored, get it 
function get_asset_action($user_id)
{
	$q = "SELECT * FROM assets WHERE user_id = '$user_id'";
	$r = mysql_query($q);
	
	$row = mysql_fetch_array($r, MYSQL_ASSOC);
	$at = $row['action'];
	
	
		
		return $at;
		
	
	
}





//function check if he jst assesed the site, if he did redirect the user base on timeout
function redirect_asset($user_id)
{
	
			
		 $at = get_asset_action($user_id); // get the last action and den delete 
		 
		 $query = "DELETE FROM assets  WHERE user_id = '$user_id'";
		 mysql_query($query);
			
			
			if( $at != '') //if $at not empty then redirect
			{
				header("Location:gateway.php?act=$at");
		 
				
			}
		 
	
	
}


//function that return whether super administartor or not
function is_administrator($user_id)
{
	$q = "SELECT group_id FROM users WHERE user_id = '$user_id'";
	$r = mysql_query($q);
	
	$row = mysql_fetch_array($r, MYSQL_ASSOC);
	 $group_id = $row['group_id'];
	
	if($group_id == 1 || $group_id == 2)
	{return true;}
	else
	{return false;}
}





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

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



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


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


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



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




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



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




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










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

//function that get total number of ordinary users 
function get_total_ordinary_users_online()
{
	$q = "SELECT COUNT(user_id) FROM users WHERE online_status = '1' AND group_id = '0'";
	$r = mysql_query($q);
	
	$row = mysql_fetch_array($r, MYSQL_NUM);
	
	return $row[0];
}



//function that get total number of admin users 
function get_total_admin_users_online()
{
	$q = "SELECT COUNT(user_id) FROM users WHERE online_status = '1' 
	AND (group_id = 1 OR group_id = 2 OR group_id = 3 OR group_id = 5)";
	$r = mysql_query($q);
	
	$row = mysql_fetch_array($r, MYSQL_NUM);
	
	return $row[0];
}



//function check last 5 logged in users log in user
function get_last_5logged_in_users()
{
	
	//get user id  so dat you cant check on ur sef some else does 
	$user_id = get_user_id();
	
	$q = "SELECT CONCAT_WS(' ', u.first_name, u.other_names)  as name, u.group_id, DATE_FORMAT(u.last_login, '%b %e, %y  %l:%i:%p') as 
			user_lastlogindate, u.online_status,
		  u.role_id, DATE_FORMAT(u.last_logout, '%b %e, %y  %l:%i:%p') as user_lastlogoutdate, 
		  ug.user_group_id, ug.title as group_title
		  FROM users u, user_groups ug
		  WHERE u.group_id = ug.user_group_id
		  AND   u.online_status = 1
		  
		  ORDER BY u.last_login DESC
		  
		  LIMIT 5";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r)>0)
	{
		while($row = mysql_fetch_assoc($r))
		{
			$output = "<tr>";
			$output .= "<td><a href=''>".$row['name']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['group_title']."</td>"; //group belong to admin or user
			//$output .= "<td>".$row['role_title']."</td>"; //role e.g cheif servant or commissioner etc
			$output .= "<td>".$row['user_lastlogindate']."</td>"; //logged in
			$output .= "<td>".$row['user_lastlogoutdate']."</td>"; //logged out
			//$output = "<td>Last acti</td>"; last activity if included
			$output .= "</tr>";
			
			
		}
	}
	
	
	return $output;
}


//function that get last 5 suspended users
function get_last_5blocked_users()
{
	
	//get user id  so dat you can check on ur sef some else does 
	$user_id = get_user_id();
	
	$q = "SELECT CONCAT_WS(' ', u.first_name, u.other_names)  as name, u.group_id, DATE_FORMAT(u.last_login, '%b %e, %y  %l:%i:%p') as last_login, 
		  u.role_id, DATE_FORMAT(u.last_logout, '%b %e, %y  %l:%i:%p') as last_logout, 
		  ug.user_group_id, ug.title as group_title
		  FROM users u,  user_groups ug
		  WHERE u.group_id = ug.user_group_id
		 
		  AND   u.user_id !=  '$user_id'
		  AND 	u.user_status = 0
		  
		  ORDER BY name ASC
		  LIMIT 5";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r)>0)
	{
		while($row = mysql_fetch_assoc($r))
		{
			$output = "<tr>";
			$output .= "<td><a href=''>".$row['name']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['group_title']."</td>"; //group belong to admin or user
			//$output .= "<td>".$row['role_title']."</td>"; //role e.g cheif servant or commissioner etc
			$output .= "<td>".$row['last_login']."</td>"; //logged in
			$output .= "<td>".$row['last_logout']."</td>"; //logged out
			//$output = "<td>Last acti</td>"; last activity if included
			$output .= "</tr>";
			
			echo $output;
		}
	}
	
}
//end of get last five suspended users


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

//function that generates security code
function generate_security_code()
{
	$result = mysql_query("SELECT * FROM generate_code");
	while($row = mysql_fetch_array($result))
	{
		$g_code = $row['code'];
	}
	
	//add 1 to $g_code and tek to d db
	$g_coded = $g_code + 1;
	
	mysql_query("UPDATE generate_code  SET code = '$g_coded'");
	
	$add_zeros = '0'.$g_coded;
	$security_id = date("Y-m-d-$add_zeros").'-IBBU';
	
	return $security_id;
}


//Function to fetch current session
	function get_current_session($id)
	{
		$result = mysql_query("SELECT * FROM sessions WHERE current_session = '$id'"); 
		$row = mysql_fetch_assoc($result);
		$id = $row['id'];
		
	return $id;
	}
	
	
	//Function to fetch  session
	function get_session_title($id)
	{
		$result = mysql_query("SELECT * FROM sessions WHERE id = '$id'"); 
		$row = mysql_fetch_assoc($result);
		$title = $row['title'];
		
	return $title;
	}//end of get session title
	
	
	
		//Function to fetch current semester
	function get_current_semester($id)
	{
		$result = mysql_query("SELECT * FROM semesters WHERE current_session = '$id'"); 
		$row = mysql_fetch_assoc($result);
		$id = $row['id'];
		
	return $id;
	}
	
	
	//Function to fetch  semester
	function get_semester_title($id)
	{
		$result = mysql_query("SELECT * FROM semesters WHERE id = '$id'"); 
		$row = mysql_fetch_assoc($result);
		$title = $row['title'];
		
	return $title;
	}
	
	
	
	
	//function tha gen token for delete, and other purposes
	function generate_token()
	{
			for($i=0;$i<=20;$i++){
				$key .=mt_rand(0,9);
			}
			return $key.date();
	}//end of




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


 	//collect the user security id to track who did the back up
	$sid = get_security_id($user_id);
	
	
	
    $link = mysql_connect($host,$user,$pass);
    mysql_select_db($name,$link);
    mysql_query("SET NAMES 'utf8'");

    //get all of the tables
    if($tables == '*')
    {
        $tables = array();
        $result = mysql_query('SHOW TABLES');
        while($row = mysql_fetch_row($result))
        {
            $tables[] = $row[0];
        }
    }
    else
    {
        $tables = is_array($tables) ? $tables : explode(',',$tables);
    }
    $return='';
	
    //cycle through
    foreach($tables as $table)
    {
        $result = mysql_query('SELECT * FROM '.$table);
        $num_fields = mysql_num_fields($result);

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

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


	
	$dbn = $name.time();
	
    //save file
   // $handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+'); // i cancelled this out beccause of the complication
    $handle = fopen('db_backups/'.$dbn.'.sql','w+');
    fwrite($handle,$return); 
	
	
	// after the write 
	//then the send data to the db
	
	
	
	$q = "INSERT INTO `backups`(`id`, `file`, `status`, `date_added`,`added_by`) 
		  VALUES (NULL,'$dbn','0',NOW(),'$sid')";
	$r = mysql_query($q);
	
	
	fclose($handle);
	
	
}
//end of back up function

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


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

	
	//query the database
	$q = "SELECT  `id`, `file`, `status`, DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, `date_trashed`, `added_by`
		  FROM `backups`
		  ORDER BY date_added DESC";
	$r = mysql_query($q);
	
	
	
	
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
	$output = 
	'<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
	  <thead>
				<!--	<th > <input type="checkbox" id="selecctall"  value=""> </th>-->				 
				<th >File</th>
				<th >Date / Time Backed Up</th>
				<th >Added by</th>
				
	  </thead>
	  
	  
	  
	  
	  
	  <tbody>';
	
	
	
	
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			//$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='backup[]' id='role' class='checkbox1'/></td>" ;
			$output .= "<td><a href='db_backups/".$row['file'].".sql' data-toggle='tooltip' title='Click to Download'>".$row['file']."</a></td>"; 
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "</tr>";
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
	
}//end of view backups



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



//function view user log
function view_user_log()
{
	
	//query the database
	$query = "SELECT u.user_id, u.security_id, CONCAT_WS(' ', u.first_name, u.other_names) as name, ul.log_id, ul.user_id, ul.log_action,
			 DATE_FORMAT(ul.log_date, '%b %e, %Y  %l:%i:%p')as log_date
			 
			 FROM users u, user_log ul
			 
			 WHERE u.user_id = ul.user_id
			 
			 
			 ORDER BY log_date";
   $result = mysql_query($query);
   
	
	
	
	
	
	
	
	
	
	if(mysql_num_rows($result) > 0)
	{//show table
	
	
		$output = 
		'<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		  <thead>
				 
					  <th>Name</th>
					  <th>Security ID</th>
					  <th>Action</th>
					  <th>Date</th>
					 
					
	
		  </thead>
		  
		  <tfoot>
				 
					  <th>Name</th>
					  <th>Security ID</th>
					  <th>Action</th>
					  <th>Date</th>
					 
					
	
		  </tfoot>
		  
		  <tbody>';
	
	
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td>".$row['name']."</td>"; //group belong to admin or user
			$output .= "<td>".$row['security_id']."</td>";
			$output .= "<td>".$row['log_action']."</td>";
			$output .= "<td>".$row['log_date']."</td>";
			$output .= "</tr>";
			
		}
	}
	else
	{//show the msg 
	
		  $output = 
				 '<div class="alert alert-danger alert-dismissable"> 
				  <button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
				  <img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				 </div>';
	  
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
   

}//end of view user log






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





//function that gets header menu privileges 
function header_menu($privileges)
{
	$list .= '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/admin_small.png" />Admin<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="gateway.php"><img src="images/control_panel_small.png" />Control Panel</a></li>
							<li><a href="gateway.php?act=view_profile"><img src="images/profile_small.png" />My Profile</a></li>
							<li><a href="gateway.php?act=view_global_settings"><img src="images/global_settings_small.png" />Global Configuration</a></li>
							<li><a tabindex="0" data-toggle="popover" data-trigger="focus" title="Mass Mail" data-content="This feature is coming at later versions"><img src="images/mass_messaging_small.png" />Message</a></li>
							<li><a tabindex="0" data-toggle="popover" data-trigger="focus" title="Mass Mail" data-content="This feature is coming at later versions">
								<img src="images/system_info_small.png" />Mass Mail</a></li>
						</ul>
					</li>';
	 
	
						
	$privilege[1] = '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/users_icon.png" /> Users<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="gateway.php?act=view_users"><img src="images/user_manager_small.png">User Manager</a></li>
							<li><a href="gateway.php?act=view_roles"><img src="images/user_roles_small.png">Roles</a></li>
							<li><a href="gateway.php?act=view_user_groups"><img src="images/user_access_level_small.png">Access Level(User Groups)</a></li>
							<!-- <li><a href="#"><img src="images/user_notes_small.png">Notes user</a></li>
							<li><a href="#"><img src="images/mass_messaging_small.png">Mass mail message</a></li>-->
						</ul>
					</li>';				  
					  
	$privilege[2] = '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/news_events_small.png"> Media<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="gateway.php?act=view_news"><img src="images/news_small.png">News Manager</a></li>
							<li><a href="gateway.php?act=view_events"><img src="images/events_small.png">&nbsp;&nbsp;Event Manager</a></li>
							<li><a href="gateway.php?act=view_pictures"><img src="images/pictures_small.png">Picture Manager</a></li>
							<li><a href="gateway.php?act=view_videos"><img src="images/videos_small.png">Video Manager</a></li>
							<li><a tabindex="0" data-toggle="popover" data-trigger="focus" title="Book of Life" data-content="This feature is coming at later versions"><img src="images/book-of-life-small.png">&nbsp;Book of Life</a></li>
						</ul>
					</li>';
						
	$privilege[3] = '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/faculty.png">
						School<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="gateway.php?act=view_admission_reports_landing"><img src="images/faculties-small.png">&nbsp;&nbsp;Admission Manager</a></li>
							<li><a href="gateway.php?act=view_departments"><img src="images/departments-small.png">Departments</a></li>
							<li><a href="gateway.php?act=view_programmes"><img src="images/programmes-small.png"> &nbsp;Programmes</a></li>
							<li><a href="gateway.php?act=view_courses"><img src="images/courses-small.png">&nbsp;Courses</a></li>
							<li><a href="gateway.php?act=view_programmes_courses"><img src="images/programmes-courses-small.png">&nbsp;Programmes >> Courses</a></li>
							<li><a href="gateway.php?act=view_supports"><img src="images/students-support-small.png">&nbsp;Supports</a></li>
						
						</ul>
					</li>';
					
  $privilege[4] = '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/bankers_small.png">
  Bankers<b class="caret"></b></a>
  <ul class="dropdown-menu">
	 <!-- <li><a href="gateway.php?act=view_applicants_pins"><img src="images/applicants_manager_small.png">&nbsp;&nbsp;Applicants PINS</a></li>-->
	  <li><a href="gateway.php?act=view_students_payments_b"><img src="images/departments-small.png">Students Payments Confirmation</a></li>
	  <!-- <li><a href="gateway.php?act=view_r_log"><img src="images/new-remita-logo- smaller.jpg">Remita Transaction Log</a></li>-->

	 
	
  
  </ul>
</li>';
					
					
   	$privilege[5] = '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/maintenance.png">
						Maintenance<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="gateway.php?act=view_system_backup"><img src="images/backup-small.png">System Backup Manager</a></li>
							<li><a href="gateway.php?act=view_system_log"><img src="images/system-log-small.png">System Log</a></li>
							<li><a href="gateway.php?act=view_ip_filter"><img src="images/ip-control-small.png">&nbsp;Ip Filter</a></li>
							<li><a href="gateway.php?act=view_control_boxs"><img src="images/control-box-small.png">Control Box</a></li>
						</ul>
					</li>';
	
					
					
	
	$privilege[6] = '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/report-1.png">&nbsp;Reports<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="gateway.php?act=view_reports"><img src="images/report-small.png">  Report Manager</a></li>
						</ul>
					</li>';
						
						
	//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 .= '<span class="home_menu_icons"><a  href="gateway.php?act=view_profile&u='.get_user_id().'"><img src="images/profile.png" data-toggle="tooltip" title="View Profile" />
	&nbsp;&nbsp;Profile</a></span>';
	 
	$privilege[1] = '<span class="home_menu_icons"><a href="gateway.php?act=add_news"><img src="images/add_news.png" data-toggle="tooltip" title="Add News" />
	Add News	</a>
				
			  </span>';
						
	$privilege[2] = '<span class="home_menu_icons"><a  href="gateway.php?act=view_users"><img src="images/user_manager.png" data-toggle="tooltip" title="User Manager" />
					User Manager</a></span>';
					  
					  
	
						
	$privilege[3] = '<span class="home_menu_icons"><a  href="gateway.php?act=add_events"><img src="images/add_events.png" 
					data-toggle="tooltip" title="Add Events" />Add Events</a></span>';
						
								
	$privilege[4] = '<span class="home_menu_icons"><a  href="gateway.php?act=view_system_info"><img src="images/system_info.png" data-toggle="tooltip" title="System Infor" />
					System Info</a>
					</span>';
						
	$privilege[5] = '<span class="home_menu_icons"><a  href="gateway.php?act=view_global_settings"><img src="images/global_settings.png" data-toggle="tooltip"
					title="Global Setting" />Global Settings</a></span>';
					
					
	$privilege[6] = '<span class="home_menu_icons"><a  href="gateway.php?act=add_pictures"><img src="images/gallery.png" data-toggle="tooltip"
					title="Add Picture / Video Details" />Add Pics / Video</a></span>';
					
	

					
						
	//explode the privileges
	$allowed_privileges = explode(',',$privileges);
	
	for($i=0; $i<sizeof($allowed_privileges)-1; $i++)
	{
		$list .= $privilege[$allowed_privileges[$i]];
		
	}
		
	$list .= "";
					  
	//return $privileged_list;
	return $list;
	
	
}
//end of function home menu


//function activity trail
function activity_menu()
{

	
}


//function tab menu
function tab_menu()
{
	
}



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

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


//function that shows users publish status image
function users_publish_status_image($status)
{
	
	$st = $status;
	
	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_users" id="publish_u"  
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_users" id="unpublish_u"  
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}
	
	return $output;
	
	
}//end of function dat shows publish users image




//function view users
//function that get users informatn
function view_users()
{
	
	$user_id = get_user_id();
	
	//query the database
	$q = "SELECT u.user_id, u.group_id, CONCAT_WS(' ', u.first_name, u.other_names) as name, u.phone_number,u.username, 	
		  DATE_FORMAT(u.date_added, '%b %e, %Y  %l:%i:%p') as date_added,  u.online_status, u.user_status, u.email, u.status, 
		  u.last_login, u.last_login_ip,
		  DATE_FORMAT(u.last_logout, '%b %e, %Y  %l:%i:%p') as last_logout,
		  
		 ug.user_group_id, ug.title as group_title
		
		 
		 FROM users u, user_groups ug		 
		 WHERE u.group_id = ug.user_group_id

		 AND u.user_id != '$user_id'
		 AND (u.status = 0 OR u.status = 1)
		 
		
		 
		 ORDER BY date_added DESC";
	$r = mysql_query($q);
	
	
	
	//in the table below result_table stands for resullt fetch throug seraching table(ajax)
	
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	$output ='<table id="example" class="user display table-bordered table-hover table-striped responsive" width="100%"  cellspacing="0" style="font-size:12px;">
				<thead>
				  
				  
				  		
						
						<th  > <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title="Check All"></th>
			  
					   
						<th>Name</th>
						<th> Status </th>
						<th>Username</th>
						<th>Active</th>
						<th>User group</th>
						<th>Email</th>
						<th>Last Login Ip</th>
						<th>Last Visit Date</th>
						<th>Registration Date</th>
						
				</thead>
			
			
			
				<tfoot>
				   		<th > </th>
			  			<th>Name</th>
						<th> Status </th>
						<th>Username</th>
						<th>Active</th>
						<th>User group</th>
						<th>Email</th>
						<th>Last Login Ip</th>
						<th>Last Visit Date</th>
						<th>Registration Date</th>
				</tfoot>
			
				<tbody>';
	
		
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['user_id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['name']."</a></td>"; //nam eof the user
			$output .= "<td>".users_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['username']."</td>";
			$output .= "<td>". user_status_img($row['user_status'])."</td>";
			$output .= "<td>".$row['group_title']."</td>";
			$output .= "<td>".$row['email']."</td>";
			$output .= "<td>".$row['last_login_ip']."</td>";
			$output .= "<td>".$row['last_logout']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "</tr>";
			
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view users




//function that get trashed  users informatn
function view_trashed_users()
{
	
	//query the database
	$q = "SELECT u.user_id, u.group_id, CONCAT_WS(' ', u.first_name, u.other_names) as name, u.phone_number,u.username, 	
		  DATE_FORMAT(u.date_added, '%b %e, %Y  %l:%i:%p') as date_added,  DATE_FORMAT(u.date_modified, '%b %e, %Y  %l:%i:%p') as date_modified,  u.online_status, u.user_status, u.email, 
		  u.last_login, u.last_login_ip,
		  DATE_FORMAT(u.date_trashed, '%b %e, %Y  %l:%i:%p') as date_trashed,
		  
		 ug.user_group_id, ug.title as group_title
		
		 
		 FROM users u, user_groups ug		 
		 WHERE u.group_id = ug.user_group_id

		 AND u.user_id != '$user_id'
		 AND u.status = 2
		 
		 ORDER BY date_added DESC";
	$r = mysql_query($q);
	
	
	
	
	
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	$output ='<table id="example" class="user display table-bordered table-hover table-striped responsive" width="100%"  cellspacing="0" style="font-size:12px;">
				<thead>
				  
				  
				  		
						
						<th  > <input type="checkbox" id="selecctall"  value=""></th>
			  
					   
						<th>Name</th>
						<th>Username</th>
						<th>User group</th>
						<th>Email</th>
						<th>Registration Date</th>
						<th> Last Modified</th>
						<th>Deleted </th>
						<th>
						
				</thead>
			
			
			
				<tfoot>
				   		<th > </th>
			  			<th>Name</th>
						<th>Username</th>
						<th>User group</th>
						<th>Email</th>
						<th>Registration Date</th>
						<th> Last Modified</th>
						<th>Deleted </th>
						<th></th>
				</tfoot>
			
				<tbody>';
	
		
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['user_id']."' name='user[]' id='user' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['name']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['username']."</td>";
			$output .= "<td>".$row['group_title']."</td>";
			$output .= "<td>".$row['email']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore" id="'.$row['user_id'].'" > Restore</a>
						 <span id="loading"></span></td>';
			$output .= "</tr>";
			
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view users


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




//function that shows roles publish status image
function roles_publish_status_image($status)
{
	
	$st = $status;
	
	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_roles" id="publish_rol"  
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_roles" id="unpublish_rol"  
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}
	
	return $output;
	
	
}//end of function dat shows publish roles image

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

	
	//query the database
	$q = "SELECT `role_id`, `role_title`, `description`,  DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, status,
		  DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as `date_modified`,
		  `added_by`, `modified_by`  FROM `roles`
		  WHERE status = 0 OR status = 1
		  ORDER BY date_added DESC";
	$r = mysql_query($q);
	
	
	
	
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
	$output = 
	'<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
	  <thead>
			 	  <th > <input type="checkbox" id="selecctall"  value=""> </th>
				  <th >Role</th>
				  <th >Status</th>
				  <th >Description</th>
				  <th >Date Added</th>
				  <th >Date Modified</th>
				  <th >Added by</th>
				  <th >Modified  by</th>
				 
				  
				

	  </thead>
	  
	  
	  
	  
	  
	  <tbody>';
	
	
	
	
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['role_id']."' name='role[]' id='role' class='checkbox1'/></td>" ;
		
			
			$output .= "<td>".$row['role_title']."</td>"; 
			$output .= "<td>".roles_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['description']."</td>";
			
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "</tr>";
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
	
}//end of view roles


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

	
	//query the database
	$q = "SELECT `role_id`, `role_title`, `description`,  DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, status,
		  DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as `date_modified`,
		  DATE_FORMAT(date_trashed, '%b %e, %Y  %l:%i:%p') as `date_trashed`, `added_by`, `modified_by`  FROM `roles`
		  WHERE status = 2
		  ORDER BY date_added DESC";
	$r = mysql_query($q);
	
	
	
	
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
	$output = 
	'<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
	  <thead>
			 	  <th> <input type="checkbox" id="selecctall"  value=""> </th>
				  <th>Role</th>
				  <th>Description</th>
				  <th>Date Added</th>
				  <th>Date Modified</th>
				  <th>Added by</th>
				  <th>Modified  by</th>
				  <th>Deleted</th>
				  <th></th>
				   
				

	  </thead>
	  
	  
	  
	  
	  
	  <tbody>';
	
	
	
	
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['role_id']."' name='role[]' id='role' class='checkbox1'/></td>" ;
		
			
			$output .= "<td>".$row['role_title']."</td>"; //group belong to admin or user
			$output .= "<td>".$row['description']."</td>";
			
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_role" id="'.$row['role_id'].'" > Restore</a>
						 <span id="loading"></span></td>';
			$output .= "</tr>";
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	return $output;
	
	
	
}//end of view trashed roles



//function that shows user_groups publish status image
function user_groups_publish_status_image($status)
{
	
	$st = $status;
	
	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_user_groups" id="publish_ug"  
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_user_groups" id="unpublish_ug"  
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}
	
	return $output;
	
	
}//end of function dat shows publish user_groups image


//user groups
function view_user_groups()
{
	//query the database
	$q = "SELECT `user_group_id`, `title`, `description`, `header_menu`, `toolbar_menu`, `home_menu`, 
		  DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as `date_modified`, `added_by` , modified_by, status
		  FROM `user_groups`
		  WHERE status = 0 OR status = 1
		  ORDER BY date_added DESC";
	$r = mysql_query($q);
	
	
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
	
		$output = 
		'<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		  <thead>
				 	  <th> <input type="checkbox" id="selecctall"  value=""></th>
					  <th>Title</th>
					  <th>Status</th>
					  <th>Description</th>
					  <th>Header Menu Privs.</th>
					  <th>Toolbar Menu Privs.</th>
					  <th>Home Menu Privs.</th>
					  <th>Date</a></th>
					  <th>Date Modified</th>
					  <th>Added by</th>
					  <th>Modified  by</th>
					
	
		  </thead>
		  
		  <tbody>';
	
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['user_group_id']."' name='user_group[]' id='user_group' class='checkbox1'/></td>" ;
			$output .= "<td>".$row['title']."</td>"; //group belong to admin 
			$output .= "<td>".user_groups_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['header_menu']."</td>";
			$output .= "<td>".$row['toolbar_menu']."</td>";
			$output .= "<td>".$row['home_menu']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "</tr>";
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
	
}//end of view user groups



//user trashed  groups
function view_trashed_user_groups()
{
	//query the database
	$q = "SELECT `user_group_id`, `title`, `description`, `header_menu`, `toolbar_menu`, `home_menu`, 
		  DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as `date_modified`, 
		  DATE_FORMAT(date_trashed, '%b %e, %Y  %l:%i:%p') as `date_trashed`, `added_by` , modified_by , status
		  FROM `user_groups`
		  WHERE status = 2
		  ORDER BY date_added DESC";
	$r = mysql_query($q);
	
	
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
	
		$output = 
		'<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		  <thead>
				 	  <th> <input type="checkbox" id="selecctall"  value=""></th>
					  <th>Title</th>
					  <th>Description</th>
					  <th>Header Menu Privs.</th>
					  <th>Toolbar Menu Privs.</th>
					  <th>Home Menu Privs.</th>
					  <th>Date</a></th>
					  <th>Date Modified</th>
					  <th>Added by</th>
					  <th>Modified  by</th>
					  <th>Deleted</th>
					  <th></th>
					
	
		  </thead>
		  
		  <tbody>';
	
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['user_group_id']."' name='user_group[]' id='user_group' class='checkbox1'/></td>" ;
			$output .= "<td>".$row['title']."</td>"; //group belong to admin or user
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['header_menu']."</td>";
			$output .= "<td>".$row['toolbar_menu']."</td>";
			$output .= "<td>".$row['home_menu']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_user_group" id="'.$row['user_group_id'].'" > Restore</a>
						 <span id="loading"></span></td>';
			$output .= "</tr>";
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
	
}//end of view trashed user groups


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

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

			
				
			return $output;
	
} // select statsu


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



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



//function view news

function view_news()
{
	
	
	//query the database
	$q = "SELECT id, title, description, image,	news_carts,	  
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added, status,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  news
		 WHERE status = 0 OR status = 1
		 ORDER BY date_added ASC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"> </th>
						<th>Title</th>
						<th>Status</th>
						<th>Description</th>
						<th>Images</th>
						<th>Carts</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						
						
			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"> </th>
						<th>Title</th>
						<th>Status</th>
						<th>Description</th>
						<th>Images</th>
						<th>Carts</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='news[]' id='news' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
		    $output .= "<td>".news_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['description']."</td>"; 
			$output .= '<td><img class="img-responsive img-thumbnail" src="uploads/pictures/news_images/'.$row['image'].'" style="width:150px; height:80px"/><br/>
						'.$row['image'].'</td>';
		    $output .= "<td>".$row['news_carts']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view news

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


//function view trashed news
function view_trashed_news()
{
	
	
	//query the database
	$q = "SELECT id, title, description, image,		  
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,  DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by
		 FROM  news
		 WHERE status = 2 
		 ORDER BY date_added DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
						<th>Title</th>
						<th>Description</th>
						<th>Images</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Deleted</th>
						<th></th>
						
						
			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
						<th>Title</th>
						<th>Description</th>
						<th>Images</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Deleted</th>
						<th></th>
						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='news[]' id='news' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			
			$output .= "<td>".$row['description']."</td>"; 
			$output .= '<td><img class="img-responsive img-thumbnail" src="uploads/pictures/news_images/'.$row['image'].'" style="width:150px; height:80px"/>
						'.$row['image'].'</td>';
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_news" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></td>';
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view trashed  news

//function that shows news publish status image
function news_publish_status_image($status)
{
	
	$st = $status;
	
	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_news" id="publish_n"  
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_news" id="unpublish_n"  
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}
	
	return $output;
	
	
}//end of function dat shows publish image 

//function to show news cart
function select_news_cart($carts)
{
	$checked_carts = explode(',' , $carts);
	
	$query = "SELECT * FROM news_carts ORDER BY title";

	$result = mysql_query($query);

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

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

		}
	}
	else

	{
			echo '<span class="label label-danger">No cartegories Added Yet!</span>';
	}
	
}
//end of function that shows carts

//checked selected news
function selected_news_cart($carts)
{
	//accept an array and check whc is checked
	//$carts = $row['news_carts'];
	
	$checked_carts = explode(',' , $carts);
	
  
	$query = "SELECT * FROM news_carts ORDER BY title";
  
	$result = mysql_query($query);
  
  
	if(mysql_num_rows($result) > 0 )
	{
		while ($row_carts = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			if(in_array($row_carts['title'],$checked_carts))
			{
				echo "<p><input type='checkbox' name='carts[]' value=\"$row_carts[title]\" checked />&nbsp;&nbsp;"
				.ucfirst($row_carts['title'])."</p>";
  
			}
			else
			{
				echo "<p><input type='checkbox' name='carts[]' value=\"$row_carts[title]\" />&nbsp;&nbsp;"
				.ucfirst($row_carts['title'])."</p>";
  
			}
  
			
		}
	}
	else
  
	{
				echo '<span class="label label-danger">No cartegories Added Yet!</span>';
	}
}


//function view events

function view_events()
{
	
	
	//query the database
	$q = "SELECT id, title, description, image, status,	venue, start_time, end_time, event_date,	  
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by
		 FROM  events 
		 WHERE status = 1 OR status = 0
		
		 ORDER BY date_added DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">  			           <thead>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Status</th>
				 <th>Description</th>
				 <th>Image</th>
				 <th>Venue</th>
				 <th>Event Date</th>
				 <th>Event Time</th>
                 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Modified By</th>
					  
		  </thead>
		  
		  <tfoot>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Status</th>
				 <th>Description</th>
				 <th>Image</th>
				 <th>Venue</th>
				 <th>Event Date</th>
				 <th>Event Time</th>
                 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Modified By</th>
					  
		  </tfoot>
		  
		  <tbody>';
	
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='event[]' id='event' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".event_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= '<td><img class="img-responsive img-thumbnail" src="uploads/pictures/events_images/'.$row['image'].'"  style="width:150px; height:150px;" />
						'.$row['image'].'</td>'; 
			$output .= "<td>".$row['venue']."</td>";
			$output .= "<td>".$row['event_date']."</td>";
			$output .= "<td>".$row['start_time'].' - '.$row['end_time']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
	
	
}//end of view events

function view_trashed_events()
{
	
	
	//query the database
	$q = "SELECT id, title, description, image, status,		  
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added, DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by
		 FROM  events 
		 WHERE status = 2
		
		 ORDER BY date_added DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">  			           <thead>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Description</th>
				 <th>Image</th>
                 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Modified By</th>
				 <th>Deleted</th>
				 <th></th>
				 
					  
		  </thead>
		  
		  <tfoot>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Description</th>
				 <th>Image</th>
                 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Modified By</th>
				 <th>Deleted</th>
				 <th></th>
					  
		  </tfoot>
		  
		  <tbody>';
	
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='event[]' id='event' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= '<td><img class="img-responsive img-thumbnail" src="uploads/pictures/events_images/'.$row['image'].'"  style="width:200px; height:150px;" />
						'.$row['image'].'</td>'; 
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_event" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></td>';
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
	
	
}//end of view trashed events

//function that shows events publish status image
function event_publish_status_image($status)
{
	
	$st = $status;
	
	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_events" id="publish_ev"  
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_events" id="unpublish_ev"  
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}
	
	return $output;
	
	
}//end of function dat shows events publish image 


//begin pictures
function view_pictures()
{
	
	
	//query the database
	$q = "SELECT id , title,description, image, status,		  
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  pictures 
		  WHERE status = 0 OR status = 1
		 ORDER BY date_added DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">  			           <thead>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"> </th>
			     <th>Title</th>
				 <th>Status</th>
				 <th>Description</th>
				 <th>Image</th>
                 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Modified By</th>
					  
		  </thead>
		  
		  <tfoot>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Status</th>
				 <th>Description</th>
				 <th>Image</th>
                 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Modified By</th>

					  
		  </tfoot>
		  
		  <tbody>';
	
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='picture[]' id='picture' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".picture_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= '<td><img class="img-responsive img-thumbnail" src="uploads/pictures/gallery_pictures/'.$row['image'].'"  
			style="width:150px; height:150px;" /><br/>'.$row['image'].'</td>'; 
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
	
	
}//end of view pictures

//begin trashed pictures
function view_trashed_pictures()
{
	
	
	//query the database
	$q = "SELECT id , title,description, image, status,		  
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,  DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  pictures 
		 WHERE status = 2
		 ORDER BY date_added DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">  			           <thead>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"> </th>
			     <th>Title</th>
				
				 <th>Description</th>
				 <th>Image</th>
                 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Modified By</th>
				 <th>Deleted</th>
				 <th></th>
					  
		  </thead>
		  
		  <tfoot>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				
				 <th>Description</th>
				 <th>Image</th>
                 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Modified By</th>
				 <th>Deleted</th>
				 <th></th>
				
					  
		  </tfoot>
		  
		  <tbody>';
	
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='picture[]' id='picture' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= '<td><img class="img-responsive img-thumbnail" src="uploads/pictures/gallery_pictures/'.$row['image'].'"  
			style="width:150px; height:150px;" /><br/>'.$row['image'].'</td>'; 
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_picture" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></td>';
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
	
	
}//end of view trashed  pictures



//function that shows pictures publish status image
function picture_publish_status_image($status)
{
	
	$st = $status;
	
	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_pictures" id="publish_pic"  
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_pictures" id="unpublish_pic"  
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}
	
	return $output;
	
	
}//end of function dat shows pictures publish image 



//begin videos
function view_videos()
{
	
	
	//query the database
	$q = "SELECT id , title, youtube_link, description, image,  status,		  
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  videos 
		 WHERE status = 0 OR status = 1
		
		 ORDER BY date_added DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">  			           <thead>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Status</th>
				 <th>Youtube <br/> Link</th>
				 <th>Description</th>
				 <th>Image</th>
                 <th>Video</th>
				 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Mod. By</th>
					  
		  </thead>
		  
		  <tfoot>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Status</th>
				 <th>Youtube <br/> Link</th>
				 <th>Description</th>
				 <th>Image</th>
				 <th>Video</th>
				 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Mod. By</th>
					  
		  </tfoot>
		  
		  <tbody>';
	
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='video[]' id='video' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".video_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['youtube_link']."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= '<td><img class="img-responsive img-thumbnail" src="uploads/pictures/video_pictures/'.$row['image'].'"  
			style="width:150px; height:150px;" />
						'.$row['image'].'</td>'; 
			$output .= "<td>add youtube link here to see</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
}//end of view videos


//begin trashed videos
function view_trashed_videos()
{
	
	
	//query the database
	$q = "SELECT id , title, youtube_link, description, image,  status, 		  
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,  DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  videos 
		 WHERE status = 2
		
		 ORDER BY date_added DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">  			           <thead>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Youtube <br/> Link</th>
				 <th>Description</th>
				 <th>Image</th>
                 <th>Video</th>
				 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Deleted</th>
				 <th></th>
				 
					  
		  </thead>
		  
		  <tfoot>
				 <th> <input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"></th>
			     <th>Title</th>
				 <th>Youtube <br/> Link</th>
				 <th>Description</th>
				 <th>Image</th>
				 <th>Video</th>
				 <th>Date Added</th>
			     <th>Date Mod.</th>
			     <th>Added By</th>
				 <th>Deleted</th>
				 <th></th>
				 	  
		  </tfoot>
		  
		  <tbody>';
	
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='video[]' id='video' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['youtube_link']."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= '<td><img class="img-responsive img-thumbnail" src="uploads/pictures/video_pictures/'.$row['image'].'"  
			style="width:150px; height:150px;" />
						'.$row['image'].'</td>'; 
			$output .= "<td>add youtube link here to see</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_video" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></td>';
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
}//end of view  trashed videos

//function that shows videos publish status image
function video_publish_status_image($status)
{
	
	$st = $status;
	
	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_videos" id="publish_vid"  
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_videos" id="unpublish_vid"  
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}
	
	return $output;
	
	
}//end of function dat shows videos publish image 


//function to show video cart
function select_video_cart($carts)
{
	$checked_carts = explode(',' , $carts);
	
	$query = "SELECT * FROM video_carts ORDER BY title";

	$result = mysql_query($query);

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

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

		}
	}
	else

	{
			echo '<span class="label label-danger">No cartegories Added Yet!</span>';
	}
	
}
//end of function that shows carts

//checked selected news
function selected_video_cart($carts)
{
	//accept an array and check whc is checked
	//$carts = $row['news_carts'];
	
	$checked_carts = explode(',' , $carts);
	
  
	$query = "SELECT * FROM video_carts ORDER BY title";
  
	$result = mysql_query($query);
  
  
	if(mysql_num_rows($result) > 0 )
	{
		while ($row_carts = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			if(in_array($row_carts['title'],$checked_carts))
			{
				echo "<p><input type='checkbox' name='carts[]' value=\"$row_carts[title]\" checked />&nbsp;&nbsp;"
				.ucfirst($row_carts['title'])."</p>";
  
			}
			else
			{
				echo "<p><input type='checkbox' name='carts[]' value=\"$row_carts[title]\" />&nbsp;&nbsp;"
				.ucfirst($row_carts['title'])."</p>";
  
			}
  
			
		}
	}
	else
  
	{
				echo '<span class="label label-danger">No cartegories Added Yet!</span>';
	}
}




//function view faculties
function view_faculties()
{
	
	
	//query the database
	$q = "SELECT id, title, description, code, status, faculty_image, dean_name, dean_picture, email, location, phone_contacts, pdf_details,		  
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  faculties
		 WHERE status = '0' OR status = '1'
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall"  value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>Status</th>
						<th>Image</th>
						<th>Email</th>
						<th>Contacts</th>
						<th>Location</th>
						<th>Description</th>
						<th>PDF File</th>
						<th>Dean\'s Name</th>
						<th>Dean\'s Picture</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						
						
			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  value=""></th>
						<th>Title</th>
						<th>Code</th>
						<th>Status</th>
						<th>Image</th>
						<th>Email</th>
						<th>Contacts</th>
						<th>Location</th>
						<th>Description</th>
						<th>PDF File</th>
						<th>Dean\'s Name</th>
						<th>Dean\'s Picture</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='faculty[]' id='faculty' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['code']."</td>";
			$output .= "<td>".faculty_publish_status_image($row['status'])."</td>";
			$output .= "<td><img src='../faculties/pictures/".$row['faculty_image']."' height='70px' width='150px' /> </td>";
			$output .= "<td>".$row['email']."</td>";
			$output .= "<td>".$row['phone_contacts']."</td>";
			$output .= "<td>".$row['location']."</td>";    
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td><a class='btn btn-sm btn-success'  href='../faculties/uploads/pdf_files/".$row['pdf_details']."' target='_blank' title='Download this file for more details' data-toggle='tooltip' /> Download PDF</a></td>"; 
			$output .= "<td>".$row['dean_name']."</td>";  
			$output .= "<td><img src='../faculties/deans/".$row['dean_picture']."' height='70px' width='70px' /> </td>"; 
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view faculties


//function view trashed faculties
function view_trashed_faculties()
{
	
	
	//query the database
	$q = "SELECT id, title, description, code, status, 		  
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added, DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  faculties
		 WHERE status = 2 		 
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall"  value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th>Deleted</th>
						<th></th>
						
						
			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  value=""></th>
						<th>Title</th>
						<th>Code</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th>Deleted</th>
						<th></th>
						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='faculty[]' id='faculty' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['code']."</td>";
			$output .= "<td>".$row['description']."</td>"; 
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_faculty" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></td>';
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view trashed faculties


//function that shows faculty publish status image
function faculty_publish_status_image($status)
{
	
	$st = $status;
	
	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_faculties" id="publish_fac"  
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_faculties" id="unpublish_fac"  
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}
	
	return $output;
	
	
}//end of function dat shows publish image 



//function view departments
function view_departments()
{
	
	
	//query the database
	$q = "SELECT id, title, description, status, 
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  departments
		 WHERE status = '0' OR status = '1'
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall"  value=""> </th>
						<th>Title</th>
					    <th>Status</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						
						
			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  value=""></th>
						<th>Title</th>
					    <th>Status</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='department[]' id='department' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".department_publish_status_image($row['status'])."</td>";
			//$output .= "<td>".get_faculty_title($row['faculty_id'])."</td>"; 
			//$output .= "<td><img src='../departments/hods/".$row['hod_picture']."' height='100px' width='100px' /> </td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view departments

//function view  trashed departments
function view_trashed_departments()
{
	
	
	//query the database
	$q = "SELECT id, title, description, code, 	  status,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added, DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  departments
		 WHERE status = 2
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall"  value=""> </th>
						<th>Title</th>
						<th>Status</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th> Deleted </th>
						<th></th>
						
						
			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  value=""></th>
						<th>Title</th>
						<th>Status</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th> Deleted </th>
						<th></th>
						
						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='department[]' id='department' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".department_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['description']."</td>";
			//$output .= "<td>".get_faculty_title($row['faculty_id'])."</td>"; 
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_department" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></td>';
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view trashed departments


//function that shows department publish status image
function department_publish_status_image($status)
{
	
	$st = $status;
	
	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_departments" id="publish_dp"  
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_departments" id="unpublish_dp"  
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}
	
	return $output;
	
	
}//end of function dat shows publish image  for departments


//function view programmes
function view_programmes()
{
	
	
	//query the database
	$q = "SELECT id, title,type_id,duration,maximum_duration,maximum_credit_load,
		  minimum_credit_load, description, code, department_id, status,		  
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  programmes
		 WHERE status = '0' OR status ='1'
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall"  value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>status</th>
						<th>Department</th>
						<th>Prog. Type</th>
						<th>Duration  Duration  </th>
						<th>Max. Duration</th>
						<th>Min. Credit Load / Max. Credit Load</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						
			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>status</th>
						<th>Department</th>
						<th>Prog. Type</th>
						<th>Duration  Duration  </th>
						<th>Max. Duration</th>
						<th>Min. Credit Load / Max. Credit Load</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='programme[]' id='programme' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['code']."</td>";
			$output .= "<td>".programme_publish_status_image($row['status'])."</td>";
			$output .= "<td>".get_department_title($row['department_id'])."</td>";
			$output .= "<td>".show_programme_type($row['type_id'])."</td>";
			$output .= "<td>".$row['duration']." </td>"; 
			$output .= "<td>".$row['maximum_duration']."</td>"; 
			$output .= "<td>".$row['maximum_credit_load']." / ".$row['minimum_credit_load']."</td>";
			//$output .= "<td><img src='../departments/programmes/pictures/".$row['picture']."' height='100px' width='170px' /> </td>";
			//$output .= "<td>".$row['philosophy_history']."</td>";
			$output .= "<td>".$row['description']."</td>"; 
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "</tr>";
	
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view courses



//function view trashed programmes
function view_trashed_programmes()
{
	
	
	//query the database
	$q = "SELECT id, title, description, code, department_id, status,		  
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,  DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  programmes 
		 WHERE status = '2'
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall"  value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>Department</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th>Deleted</th>
						<th></th>
						
			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>Department</th>
						<th>Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th>Deleted</th>
						<th></th>

						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='programme[]' id='programme' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['code']."</td>";
			$output .= "<td>".get_department_title($row['department_id'])."</td>";
			$output .= "<td>".$row['description']."</td>"; 
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_programme" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></td>';
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view  trashed programmes

//function that shows programme publish status image
function programme_publish_status_image($status)
{
	
	$st = $status;
	
	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_programmes" id="publish_pm"  
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_programmes" id="unpublish_pm"  
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}
	
	return $output;
	
	
}//end of function dat shows publish image  for programmes



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

	return $output;

}
//end of select programme_type




//function view courses
function view_courses()
{
	
	//comment incase
	
	
	//query the database
	$q = "SELECT id, title, description, programme_id, department_id, code, unit, level, semester, status, course_type, course_description,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,type_id,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  courses 
		 WHERE status = 0 OR status = 1 
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall" data-toggle = "tooltip" title = "Check All"   value=""></th>
						<th>Title</th>
						<th>Code</th>
						<th>Status</th>
						<th>Type</th>
						<th>Prog. Type</th>
						<th>Department</th>
						<th>Programme</th>
						<th>Unit</th>
						<th>Level</th>
						<th>Semester</th>
						<th>C. Description</th>
						<th>N/Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						
			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  data-toggle = "tooltip" title = "Check All" value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>Status</th>
						<th>Type</th>
						<th>Prog. Type</th>
						<th>Department</th>
						<th>Programme</th>
						<th>Unit</th>
						<th>Level</th>
						<th>Semester</th>
						<th>C. Description</th>
						<th>N/Description</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='course[]' id='course' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['code']."</td>";
			$output .= "<td>".course_publish_status_image($row['status'])."</td>";
			$output .= "<td>".course_type($row['course_type'])."</td>";
			$output .= "<td>".show_programme_type($row['type_id'])."</td>";
            $output .= "<td>".get_department_title($row['department_id'])."</td>";
			$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
			$output .= "<td>".$row['unit']."</td>"; 	
			$output .= "<td>".$row['level']."</td>";
			$output .= "<td>".$row['semester']."</td>"; 
			$output .= "<td>".$row['course_description']."</td>"; 
			$output .= "<td>".$row['description']."</td>"; 
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view courses

//function view trashed scourses
function view_trashed_courses()
{
	
	//comment incase
	
	
	//query the database
	$q = "SELECT id, title, description, programme_id, department_id, code, unit, level, semester, status,
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added, DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  courses
		  WHERE status = 2
		  ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall" data-toggle = "tooltip" title = "Check All"   value=""></th>
						<th>Title</th>
						<th>Code</th>
						<th>Department</th>
						<th>Programme</th>
						<th>Unit</th>
						<th>Level</th>
						<th>Semester</th>
						<th>Added By</th>
						<th>Deleted</th>
						<th></th>
						
			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  data-toggle = "tooltip" title = "Check All" value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>Department</th>
						<th>Programme</th>
						<th>Unit</th>
						<th>Level</th>
						<th>Semester</th>
						<th>Added By</th>
						<th>Deleted</th>
						<th></th>
						
						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='course[]' id='course' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['code']."</td>";
			$output .= "<td>".get_department_title($row['department_id'])."</td>";
			$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
			$output .= "<td>".$row['unit']."</td>"; 	
			$output .= "<td>".$row['level']."</td>";
			$output .= "<td>".$row['semester']."</td>";  
			//$output .= "<td>".$row['description']."</td>"; 
//			$output .= "<td>".$row['date_added']."</td>";
//			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_course" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></td>';
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view trashed courses



//function that shows course publish status image
function course_publish_status_image($status)
{
	
	$st = $status;
	
	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_courses" id="publish_cs"  
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_courses" id="unpublish_cs"  
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}
	
	return $output;
	
	
}//end of function dat shows publish image  for courses


//function that shows course type
function course_type($status)
{
	
	$st = $status;
	
	if($st == '1')
	{
		$output =  'CORE';
	}
	else if($st == '2')
	{
		$output =  'ELECTIVE';
	}
	else
	{
		$output = '';
	}
	
	return $output;
	
	
}//end of function dat shows course type




//function view programmes courses
function view_programmes_courses()
{
	
	//comment incase
	
	
	//query the database
	$q = "SELECT id, programme_type_id,  programme_id, department_id, course_id, level,  status, token, 
		 DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  programmes_courses_nce 
		 WHERE status = '0' OR status = '1' 
		 GROUP BY token
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall" data-toggle = "tooltip" title = "Check All"   value=""></th>
						<th>Level</th>
						<th>Programme</th>
						<th>Department</th>
						<th>School</th>
						<th>Prog. Type</th>
						<th>Courses Attcahed</th>
						<th>Status </th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th></th>
						
			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  data-toggle = "tooltip" title = "Check All" value=""> </th>
						<th>Level</th>
						<th>Programme</th>
						<th>Department</th>
						<th>School</th>
						<th>Prog. Type</th>
						<th>Courses Attcahed</th>
						<th>Status </th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th></th>
						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['token']."' name='programme_course[]' id='programme_course' class='checkbox1'/></td>" ;
			
			$output .= "<td>".$row['level']."</td>";
			$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
			$output .= "<td>".get_department_title($row['department_id'])."</td>";
			$output .= "<td>".get_school_title($row['school_id'])."</td>";
			$output .= "<td>".show_programme_type($row['programme_type_id'])."</td>";
            $output .= "<td style='width:20%;'>".get_courses_for_level_programmes($row['level'], $row['programme_id'])."</td>";
			$output .= "<td>".programme_course_publish_status_image($row['status'])."</td>";
			//$output .= "<td>".course_type($row['course_type'])."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td><a href='gateway.php?act=add_supplementry_programmes_courses&id=".$row['token']."'> <i class='text-success glyphicon glyphicon-plus' data-toggle='tooltip' title='Click here add more courses'></i></a></td>";
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view programme courses



//function view trashed  programmes courses
function view_trashed_programmes_courses()
{
	
	//comment incase
	
	
	//query the database
	$q = "SELECT id, programme_type_id, programme_id, department_id, course_id, level,  status, token, 
		 DATE_FORMAT(date_trashed, '%M %d, %Y %l:%i:%p') as date_trashed,added_by
		 FROM  programmes_courses_nce 
		 WHERE status = '2' 
		 GROUP BY token
		 ORDER BY date_trashed DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th> <input type="checkbox" id="selecctall" data-toggle = "tooltip" title = "Check All"   value=""></th>
						<th>Level</th>
						<th>Programme</th>
						<th>Programme Type</th>
						<th>Department</th>
						<th>Courses Attcahed</th>
					
						<th>Added By</th>
						<th>Date Trashed</th>
						<th></th>
						
			</thead>
			<tfoot>
						<th> <input type="checkbox" id="selecctall"  data-toggle = "tooltip" title = "Check All" value=""> </th>
						<th>Level</th>
						<th>Programme</th>
						<th>Programme Type</th>
						<th>Department</th>
						<th>Courses Attcahed</th>
						<th>Added By</th>
						<th>Date Trashed</th>
						<th></th>
						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['token']."' name='programme_course[]' id='programme_course' class='checkbox1'/></td>" ;
			
			$output .= "<td>".$row['level']."</td>";
			$output .= "<td>".get_programme_title($row['programme_id'])."</td>";
			$output .= "<td>".show_programme_type($row['programme_type_id'])."</td>";
			$output .= "<td>".get_department_title($row['department_id'])."</td>";
			$output .= "<td style='width:20%;'>".get_courses_for_level_programmes($row['level'], $row['programme_id'])."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_programme_course" id="'.$row['token'].'" > Restore</a>
						 <span id="loading"></span></td>';
			$output .= "</tr>";
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view programme courses trashed

//function that shows programmes course publish status image
function programme_course_publish_status_image($status)
{
	
	$st = $status;
	
	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_programmes_courses" id="publish_pcs"  
				data-toggle="tooltip" data-placement="right" title="Published: Click to unpublish item">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small" value="publish_programmes_courses" id="unpublish_pcs"  
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}
	
	return $output;
	
	
}//end of function dat shows publish image  for programmes courses

//function to get list pf courses attach to level and programmes
function get_courses_for_level_programmes($level, $programme)
{
	
	//comment incase
	
	
	//query the database
	$q = "SELECT c.id as cid, c.title, c.description, c.programme_id, c.department_id, c.code, c.unit, c.level,  c.status,
			pc.programme_id, pc.course_id, pc.department_id, pc.level, pc.status 
		 
		 FROM  courses c , programmes_courses_nce pc 
		 WHERE 
		 c.id = pc.course_id
		 AND pc.level = '$level'
		 AND pc.programme_id = '$programme'
		 AND pc.status = 0
		   
		 ORDER BY c.code ASC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = '';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "".$row['code']."(".$row['unit']."), "; 
			 
				
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	
	
	return $output;
	
	
	
	
}//end of get list of courses attched to a particular level and programme


//function that filters the ip
function filter_ip()
{
  
  $ip = getenv('REMOTE_ADDR'); //get user ip
  $ip=str_replace('.','',$ip); //str replace of dot 
  
  $query_ip= mysql_query("SELECT * FROM ip_filter WHERE ips='$ip'") or die(mysql_error()); //query
  if($query_ip){
    
    $row=mysql_num_rows($query_ip);
    if($row==0){
      
      header('location:autorize_message/'); // show authorize message
    }
    
  }
} //end of filter the ip


//view ips
//function that get ips informatn
function view_ips()
{
		
	//query the database
	$q = "SELECT `id`, `ips`, `title`, `description`, `status`, `activate`, 
		 DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as date_modified,
		 `added_by`, `modified_by` 
		 FROM `ip_filter` 
		 WHERE status = 1 OR status = 0
	     
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);
	
	
	
	//in the table below result_table stands for resullt fetch throug seraching table(ajax)
	
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	$output ='<table id="example" class="ip display table-bordered table-hover table-striped responsive" width="100%"  cellspacing="0" style="font-size:12px;">
				<thead>
				  
				  
				  		
						
						<th  > <input type="checkbox" id="selecctall"  data-toggle = "tooltip" title = "Check All" value=""></th>
			  			<th>Title</th>tle
						<th>IPs</th>
						
						<th>Description</th>
						<th>Active Status</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						
				</thead>
			
			
			
				<tfoot>
				   		
						
						<th  > <input type="checkbox" id="selecctall" data-toggle = "tooltip" title = "Check All"  value=""></th>
			  			<th>Title</th>
						<th>IPs</th>
						<th>Description</th>
						<th>Active Status</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
				</tfoot>
			
				<tbody>';
	
		
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='ip[]' id='ip' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['ips']."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".ip_status_img($row['activate'])."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "</tr>";
			
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view  ips


//view trashed ips
//function that get ips informatn
function view_trashed_ips()
{
		
	//query the database
	$q = "SELECT `id`, `ips`, `title`, `description`, `status`, `activate`, DATE_FORMAT(date_trashed, '%b %e, %Y  %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as date_modified,
		 `added_by`, `modified_by` 
		 FROM `ip_filter` 
		 WHERE status = 2
	     
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);
	
	
	
	//in the table below result_table stands for resullt fetch throug seraching table(ajax)
	
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	$output ='<table id="example" class="ip display table-bordered table-hover table-striped responsive" width="100%"  cellspacing="0" style="font-size:12px;">
				<thead>
				  
				     	<th  > <input type="checkbox" id="selecctall"  data-toggle = "tooltip" title = "Check All" value=""></th>
			  			<th>Title</th>tle
						<th>IPs</th>
						<th>Description</th>
						<th>Active Status</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th>Deleted </th>
						<th></th>
						
				</thead>
			
			
			
				<tfoot>
				   		
						
						<th  > <input type="checkbox" id="selecctall" data-toggle = "tooltip" title = "Check All"  value=""></th>
			  			<th>Title</th>
						<th>IPs</th>
						<th>Description</th>
						<th>Active Status</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th>Deleted </th>
						<th></th>
				</tfoot>
			
				<tbody>';
	
		
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='ip[]' id='ip' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['ips']."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".ip_status_img($row['activate'])."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_ip" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></td>';
			$output .= "</tr>";
			
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view trashed ips

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

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





//function that shows ips publish status image
function ip_publish_status_image($status)
{
	
	$st = $status;
	
	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small disabled" value="unpublish_ips" id="publish_ip"  
				data-toggle="tooltip" data-placement="right" title="Published" disabled="disabled">';
	}
	else
	{
		$output =  '<input type="submit" name="act" class="unpublish-icon-small disabled" value="publish_ips" id="unpublish_ip"  
					data-toggle="tooltip" data-placement="right" title="Unpublished" disabled="disabled">';
	}
	
	return $output;
	
	
}//end of function dat shows publish image 


//function that get control boxes informatn
function view_control_boxs()
{
		
	//query the database
	$q = "SELECT `id`, `controls_value`, `title`, `description`, `status`, `active`, 
		 DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as date_modified,
		 `added_by`, `modified_by` 
		 FROM `controls` 
		 WHERE status = 1 OR status = 0
	     
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);
	
	
	
	//in the table below result_table stands for resullt fetch throug seraching table(ajax)
	
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	$output ='<table id="example" class="control_box display table-bordered table-hover table-striped responsive" width="100%"  cellspacing="0" style="font-size:12px;">
				<thead>
				  
				  
				  		
						
						<th  > <input type="checkbox" id="selecctall"  data-toggle = "tooltip" title = "Check All" value=""></th>
			  			<th>Title</th>
						<th>Controls</th>
						
						<th>Description</th>
						<th>Active Status</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						
				</thead>
			
			
			
				<tfoot>
				   		
						
						<th  > <input type="checkbox" id="selecctall" data-toggle = "tooltip" title = "Check All"  value=""></th>
			  			<th>Title</th>
						<th>Controls</th>
						<th>Description</th>
						<th>Active Status</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
				</tfoot>
			
				<tbody>';
	
		
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='control_box[]' id='ip' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['controls_value']."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".control_box_status_img($row['active'])."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "</tr>";
			
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view  control boxes

//function that get control_boxs informatn
function view_trashed_control_boxs()
{
		
	//query the database
	$q = "SELECT `id`, `controls_value`, `title`, `description`,  `active`, DATE_FORMAT(date_trashed, '%b %e, %Y  %l:%i:%p') as date_trashed,
		 DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as date_modified,
		 `added_by`, `modified_by` 
		 FROM `controls` 
		 WHERE status = 2
	     
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysql_query($q);
	
	
	
	//in the table below result_table stands for resullt fetch throug seraching table(ajax)
	
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	$output ='<table id="example" class="control_box display table-bordered table-hover table-striped responsive" width="100%"  cellspacing="0" style="font-size:12px;">
				<thead>
				  
				     	<th  > <input type="checkbox" id="selecctall"  data-toggle = "tooltip" title = "Check All" value=""></th>
			  			<th>Title</th>tle
						<th>Controls</th>
						<th>Description</th>
						<th>Active Status</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th>Deleted </th>
						<th></th>
						
				</thead>
			
			
			
				<tfoot>
				   		
						
						<th  > <input type="checkbox" id="selecctall" data-toggle = "tooltip" title = "Check All"  value=""></th>
			  			<th>Title</th>
						<th>Controls</th>
						<th>Description</th>
						<th>Active Status</th>
						<th>Date Added</th>
						<th>Date Mod.</th>
						<th>Added By</th>
						<th>Modified By</th>
						<th>Deleted </th>
						<th></th>
				</tfoot>
			
				<tbody>';
	
		
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='control_box[]' id='control_box' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>"; //nam eof the user
			$output .= "<td>".$row['controls_value']."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".control_box_status_img($row['activate'])."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_control_box" id="'.$row['id'].'" > Restore</a>
						 <span id="loading"></span></td>';
			$output .= "</tr>";
			
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view trashed control_boxs

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





//function view batches

function view_states()
{
	
	//query the database
	$q = "SELECT `id`, `title`,  `description`, DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified, `added_by` FROM `state`
		 ORDER BY date_added  DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		 $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">    		
		  	<thead>
			  <th > <input type="checkbox" id="selecctall"  value=""> &nbsp;Check All</th>
			  <th>Title</th>
			  <th  >Description</th>
			  <th>Date Added</th>
			  <th>Added By</th>
			  
		  </thead>
		  
		  <tfoot>
			  <th > <input type="checkbox" id="selecctall"  value=""> &nbsp;Check All</th>
			  <th>Title</th>
			  <th>Description</th>
			  <th>Date Added</th>
			  <th>Added By</th>
			  
		  </tfoot>
		  
		  <tbody>';
		
	
	
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='state[]' id='state' class='checkbox1'/></td>" ;
			$output .= "<td>".$row['title']."</td>"; //name
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "</tr>";
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
	
	
	
}//end of view states



//function view lgas
function view_lgas()
{
	
	//query the database
	$q = "SELECT l.id, l.title, l.description, l.state_id, l.date_added, l.date_modified, l.added_by,
		 s.id as sid, s.title as stitle
		 FROM lga l, state s
		 WHERE s.id = l.state_id
		ORDER BY l.date_added DESC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		$output =
		'<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		  <thead>
					  <th> <input type="checkbox" id="selecctall"  value=""> &nbsp;Check All</th>
					  <th>Title</th>
					  <th>State</th>				  
					  <th>Description</th>
					  <th>Date Added</th>
					  <th>Added By</th>
					  
		  </thead>
		   <tfoot>
					  <th> <input type="checkbox" id="selecctall"  value=""> &nbsp;Check All</th>
					  <th>Title</th>
					  <th>State</th>				  
					  <th>Description</th>
					  <th>Date Added</th>
					  <th>Added By</th>
					  
		  </tfoot>
		  
		  <tbody>';
		
	
	
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='lga[]' id='lga' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>"; //title
			$output .= "<td> <a href=''>".$row['stitle']."</a></td>"; //title
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "</tr>";
			
		}
	}
	
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
	
}//end of view lgas


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

	return $title;
	
}



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

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

	return $title;
	
}


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



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

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



//select school
function select_school($faculty)
{
	$r = mysql_query("SELECT id, title  FROM schools  ORDER BY title");
	if(mysql_num_rows($r) > 0 )
	{
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			if($faculty == $row['id'])
			{
				$output = "<option value=\"$row[id]\" selected>";
				$output .=  $row['title'];
				$output .="</option>";
				
			}
			else
			{
				$output = "<option value=\"$row[id]\" >";
				$output .= $row['title'];
				$output .="</option>";
				
			}
			 
			
			echo $output;
		}
	}
	else
	{
		
			$output = "<option>";
			$output .="Not added yet";
			$output .="</option>"; 
			
			echo $output;
	}
}
//end of select schools


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










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

	return $title;
}


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

	return $title;
}


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

	return $v;
}




//function that generates admission number students

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

//second we need to get department title by id

//we need to get department code by id 

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




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

	return $title;
	
}


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

	return $title;
	
}

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

	return $code;
	
}



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

	return $code;
	
}


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

	return $code;
	
}




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





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

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

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



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





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



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

///function get total applicants in a programme 
function check_applicant_is_nce_lvsp($id, $pt, $cid, $ses)
{
	$q = "SELECT * FROM applicants_nce   WHERE id = '$id' AND programme_type_applied_for = '$pt' 
			AND cart_id = '$cid' AND session= '$ses' ";
	$r = mysql_query($q);
	if (mysql_num_rows($r) == 1) {
		return true;
	}
	
}
//function get total applicants in a programme 
function check_applicant_is_prence($id, $pt, $cid, $ses)
{
	$q = "SELECT * FROM applicants_nce   WHERE id = '$id' AND programme_type_applied_for = '$pt' 
			AND cart_id = '$cid' AND session= '$ses' ";
	$r = mysql_query($q);
	if (mysql_num_rows($r) == 1) {
		return true;
	}
	
}

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

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


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




//function that get all programmes type students
function get_listed_programmes_types_for_students()
{
	
		$output =  '';
	
	
		for($i = 1 ; $i <= 3; $i++)
		{
			$output .= '<li class="list-group-item">'.show_programme_type($i).' 
						<span class="pull-right badge">'.get_total_programme_type_students($i).'</span> <br/> 
						
						</li>';
						
						
		}
		
	
	//<span class="help-block" style="font-size:10px">'.get_programme_title_for_applicants($i).'</span>
	return $output;
	
}







//function taht gets percentage 
function get_percent($value, $total)
{
	
	if($value == 0)
	{
		$percent  = ($value / 1) * 100;	
	}
	else
	{
		$percent  = ($value / $total) * 100;
	}
	
	return round($percent, 2); 
}

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





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



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



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


//function that get all faculties
function get_listed_faculties()
{
	//query the database
	$q = "SELECT id, title,status FROM  faculties WHERE status = '0'  ORDER BY title";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
		$output =  '';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= '<li class="list-group-item">'.$row['title'].' <span class="pull-right badge">'.get_total_faculty_students($row['id']).'</span></li>';
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found.
				   </div>';
		
	}
	
	return $output;
	
}




//function that get all departments
function get_listed_departments()
{
	//query the database
	$q = "SELECT * FROM  departments WHERE status = '0' AND real_ = '0'  ORDER BY title";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
		$output =  '';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= '<li class="list-group-item">'.$row['title'].' 
						<span class="pull-right badge">'.get_total_department_students($row['id']).'</span> <br/> 
							</li>';
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found.
				   </div>';
		
	}
	
	return $output;
	
}



//function that get all programmes
function get_listed_programmes()
{
	//query the database
	$q = "SELECT id, title,department_id, status, type_id FROM  programmes WHERE status = '0' AND real_ = '0'  ORDER BY title";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
		$output =  '';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= '<li class="list-group-item">'.$row['title'].' 
						<span class="pull-right badge">'.get_total_prog_type_students($row['type_id'],$row['id']).'</span> <br/> 
						<span class="help-block" style="font-size:10px">'.get_department_title($row['department_id']).'</span>
						<span class="help-block" style="font-size:10px">'.show_programme_type($row['type_id']).'</span>
						
						</li>';
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found.
				   </div>';
		
	}
	
	return $output;
	
}






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


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

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

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



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



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



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

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


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



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

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







//function that get all faculties staff
function get_listed_faculties_staff()
{
	//query the database
	$q = "SELECT id, title,status FROM  faculties WHERE status = '0'  ORDER BY title";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
		$output =  '';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= '<li class="list-group-item">'.$row['title'].' <span class="pull-right badge">'.get_total_faculty_staff($row['id']).'</span></li>';
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found.
				   </div>';
		
	}
	
	return $output;
	
}




//function that get all departments staff
function get_listed_departments_staff()
{
	//query the database
	$q = "SELECT id, title,faculty_id,status FROM  departments WHERE status = '0'  ORDER BY title";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
		$output =  '';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= '<li class="list-group-item">'.$row['title'].' 
						<span class="pull-right badge">'.get_total_department_staff($row['id']).'</span> <br/> 
						<span class="help-block" style="font-size:10px">'.get_faculty_title($row['faculty_id']).'</span>
						</li>';
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found.
				   </div>';
		
	}
	
	return $output;
	
}



//function that get all programmes
function get_listed_programmes_staff()
{
	//query the database
	$q = "SELECT id, title,department_id, status FROM  programmes WHERE status = '0'  ORDER BY title";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
		$output =  '';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= '<li class="list-group-item">'.$row['title'].' 
						<span class="pull-right badge">'.get_total_programme_staff($row['id']).'</span> <br/> 
						<span class="help-block" style="font-size:10px">'.get_department_title($row['department_id']).'</span>
						</li>';
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found.
				   </div>';
		
	}
	
	return $output;
	
}

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



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



/*********************************** admin application module ****************************************/
//fucntion that returns searched candidates
function view_search_candidate($search_c)
{
	
	//query the database
	$q = "SELECT `id`, `fullname`, `phone_number`, `email`, `transaction_id`, `pin`, `serial_no`, 
	     `status`,  `time`, `expiry_time`, `exired_date`,
	     
		  DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added
		   
		 	 
		 FROM applicants_transaction_ids
		 
		 WHERE transaction_id = '$search_c'";
		 
		 //LIMIT $start, $display_per_page";
	$r = mysql_query($q) or die (mysql_error());
	
	
	
	
	//in the table below result_table stands for resullt fetch throug seraching table(ajax)
	
	if(mysql_num_rows($r) > 0 )
	{//show table
	
			
		$output = '<table  class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="text-align:center;">
			  
		  <thead>
		  
		  
		 			  <th><!--<input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"> --></th>
					  <th><h4>Name</h4></th>
					  <th><h4>Transaction ID</h4></th>
					  <th ><h4>Date Generated</h4></th>
	
		  </thead>
		  
		  <tbody>';
	
	
	
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['transaction_id']."' name='applicant[]' id='applicant' class='checkbox1' data-toggle='tooltip' title= 'Check' /></td>" ;
			$output .= "<td> <h3>".$row['fullname']."</h3></td>"; //name of the user
			
			$output .= "<td><h3 style='font-size:14px;' class='label label-info'>".$row['transaction_id']."</h3></td>";
			
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "</tr>";
			
		}//end of while
			
		
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; Candidate not recognise by the system. We apologize for any inconvenience..
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	//else
//	{
//		$errors['error'] =  'Candidate not recognise by the system. We apologize for any inconvenience.';
//										
//		header("Location: gateway.php?act=search_candidate&error=".urlencode($errors['error'])."");
//	}

	
	
	
	
}//end of view search candidate


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


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


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

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


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


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

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


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

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





//function dat checks if tid exist in database table 
function tid_exist($tid)
{
	$q = "SELECT transaction_id FROM applicants  WHERE transaction_id = '$tid' ";
	$r = mysql_query($q);
	
	
	if(mysql_num_rows($r) > 0)
	{
		return true;
	}
	else
	{
		return false;
	}
	
	
	
}//end of function that chk kif tid exist in users table



//function dat checks if tid has expired
function tid_expired($time_generated, $expired_time)
{
	//172800
	$present_time = time(); //present time
	$old_time_interval = $expired_time - $time_generated; //interval between time generated and elapse time
	$present_time_interval = $present_time - $time_generated; //interval betweeen now and time generated
	
	
	
	
	if($present_time_interval > $old_time_interval)
	{
		return true; //time has expired 
	}
	else
	{
		return false; //else not expired
	}
	
	
	
}//end of function that chk kif tid exist in users table




//generate serial number for logging in
function generate_applicants_serial_number()
{
	$result = mysql_query("SELECT * FROM applicants_generate_serial_number");
	while($row = mysql_fetch_array($result))
	{
		$g_code = $row['code'];
	}
	
	//add 1 to $g_code and tek to d db
	$g_coded = $g_code + 1;
	
	mysql_query("UPDATE applicants_generate_serial_number  SET code = '$g_coded'");
	
	
	//add random four values before adding to the database
	$add_random_value = mt_rand(1000000,9999999);
	$code = $add_random_value.$g_coded;
	$serial_number  = $code;
	
	return $serial_number;
}
//end of function generate serial number for logging in





//function that get epin passing  id
function get_candidate_epin($id)
{
	//collect applicant data
	$other_names = get_applicant_name($id);//
	$other_names = mysql_real_escape_string($other_names);
	$phone_number = get_applicant_ph_no($id);
	$email = get_applicant_email($id);
	$time = get_applicant_tid_gen_time($id);
	$exp_time = get_applicant_tid_exp_time($id);
	
	
	
	
	
	//collellect users info
	$user_id = $id; //collect the user id
	
	
	//before a pin is generated chek if the transsaction id has been given a pin and serial number, 
	//if given fetch the pin from db cus the of network issue and regenration
	
	
		//if(!(is_epin_limit())) ///check if epin limit is exhausted
		//{
			
						
		
			if(!tid_expired($time, $exp_time)) //check if tid has expired
			{
				//check if tid has epin alredy to avoid duplicate
				//if it doesnt have generate a new 1 but if its dia copy from db 
				if(!tid_exist($id))
				{	
				
					  //generate new 1s
					  $pin = mt_rand(10000, 99999); //pin
					  $serial_number = generate_applicants_serial_number();
	
				 
					  $q = "INSERT INTO `applicants`(`id`, `role_id`, `other_names`, `email`, `phone_number`, 
						`user_status`, `date_added`, `transaction_id`, `bank_epin`,`serial_number`,`country_id`) 
						VALUES (NULL,2,'$other_names','$email','$phone_number',1,NOW(),'$id', '$pin','$serial_number','159')";
						
						
					  $r = mysql_query($q) or die(mysql_error());
					  
					  $ok = 'PIN-'.$pin .'<br/> S/N-'.$serial_number;
					  
					  return $ok; //return details

				}//end of if tid  doesnt exist
				else
				{// if tid exist with pin show pin from db
				
				
						$pin = get_applicant_pin($id); //form db
						$serial_number = get_applicant_sn($id); //from db
						
						$ok = 'PIN-'.$pin .'<br/> S/N-'.$serial_number;
						
						return $ok; //return deatils
						
				
						
				}//end else of if tid exist
			
			
			
			}
			else
			{
				//$r = true; //set true to skip next error block
				
				//show pin and serial number from db
				$errors['error'] =  'Pin not generated,the <b>transaction id</b> has expired, please advice the applicant to go and re-generate transaction id if the form is still on sale. Thank you.';
										
		        header("Location: gateway.php?act=search_c&error=".urlencode($errors['error'])."");
				
			}/// end else of if tid has expired
	
	
	
			
			
			
			
			
		//}
		//else
		//{
			
			//$r = true;
			
			//$errors['error'] =  'Pin not generated! Maximum number of epin has been generated, contact the web master or school.
				//                 We apologize for any inconvenience. ';
										
			//header("Location: gateway.php?act=search_candidate&error=".urlencode($errors['error'])."");
			
		//}
	

	
	

	
}//end of function get user epin




function get_candidate_info($id)
{
	$q = "SELECT id,  role_id, other_names as name, phone_number, email, transaction_id, 	
		  DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added, DATE_FORMAT(date_modified, '%b %e, %Y  %l:%i:%p') as date_modified
		 
		 FROM applicants	 
		 WHERE transaction_id = '$id'";
	
	$r 	= mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			
			$output .= '<li class="list-group-item">Name: '.$row['name'].'</li>'; //nam eof the user
			$output .= '<li class="list-group-item">Email: '.$row['email'].'</li>';
			$output .= '<li class="list-group-item">Transaction ID Date: '.get_tid_date($row['transaction_id']).'</li>';
			$output .= '<li class="list-group-item">PIN Gen. Date: '.$row['date_added'].'</li>';
			echo $output;
			
		}
	}
	
	
	
}//end of get candidate epin info


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




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



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


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



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

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

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



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



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

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



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

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




//function get total applicants in a programme type 
function get_total_programme_type_applicants($id)
{
	$q = "SELECT COUNT(id) FROM applicants_nce  WHERE  programme_type_applied_for = '$id'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);
	
	return $row[0];
	
}




//function view list with pins
function view_applicants_pins_list()
{
	
	
	//query the database
	$q = "SELECT `id`, `programme_type_applied_for`, `department_applied_for`, `programme_applied_for`, `application_number`, `state_id`, `lga_id`, `first_name`, `other_names`, `phone_no`,  `gender`,  `email`,  `transaction_id`, `bank_epin`, `serial_number`, DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		 FROM  applicants
		 
		 ORDER BY application_number";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>Application Number</th>
						<th>Name</th>
						<th>Gender</th>
						 <th>Programme Type</th>
						<th>Programme Applied</th>
					
						<th>Ph. Contacts</th>
						<th>Email</th>
						<th>TID</th>
						<th>Bank PIN</th>
						<th>Serial No.</th>
						
						
						
			</thead>
			<tfoot>
						<th>Application Number</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>Programme Applied</th>
						
						<th>Ph. Contacts</th>
						<th>Email</th>
						<th>TID</th>
						<th>Bank PIN</th>
						<th>Serial No.</th>
						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			
			$output .= "<td>".$row['application_number']."</td>";
			$output .= "<td> <a href=''>".$row['first_name'].' '.$row['other_names']."</a></td>";
			$output .= "<td>".$row['gender']."</td>";
			$output .= "<td>".show_programme_type($row['programme_type_applied_for'])."</td>";
			$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>"; 
			
			$output .= "<td>".$row['phone_no']."</td>"; 
			$output .= "<td>".$row['email']."</td>";
			$output .= "<td>".$row['transaction_id']."</td>";
			$output .= "<td>".$row['bank_epin']."</td>";
			$output .= "<td>".$row['serial_number']."</td>";
			
			
			
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view applicants pin list

//function show programme_type
function show_programme_type($pt)
{
		
		if ($pt == '1')
		{
			$output = '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 = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
		$output =  '';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= '<li class="list-group-item">'.$row['title'].' 
						<span class="pull-right badge">'.get_total_department_applicants($row['id']).'</span> <br/> 
						
						</li>';
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found.
				   </div>';
		
	}
	
	return $output;
	
}



//function that get all programmes
function get_listed_programmes_for_applicants()
{
	//query the database
	$q = "SELECT * FROM  programmes WHERE status = '0' AND real_ = '0'  ORDER BY title";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
		$output =  '';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= '<li class="list-group-item">'.$row['title'].' 
						<span class="pull-right badge">'.get_total_prog_type_programme_applicants($row['type_id'],$row['id']).'</span> <br/> 
						<span class="help-block" style="font-size:10px">'.get_department_title($row['department_id']).'</span>
						<span class="help-block" style="font-size:10px">'.show_programme_type($row['type_id']).'</span>
						</li>';
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found.
				   </div>';
		
	}
	
	return $output;
	
}



//function that get all programmes type
function get_listed_programmes_types_for_applicants()
{
	
		$output =  '';
	
	
		for($i = 1 ; $i <= 3; $i++)
		{
			$output .= '<li class="list-group-item">'.show_programme_type($i).' 
						<span class="pull-right badge">'.get_total_programme_type_applicants($i).'</span> <br/> 
						
						</li>';
						
						
		}
		
	
	//<span class="help-block" style="font-size:10px">'.get_programme_title_for_applicants($i).'</span>
	return $output;
	
}

//function that gets programme title for applicants
function  get_programme_title_for_applicants($id)
{	
	$result = mysql_query("SELECT * FROM applicants WHERE type_id = '$id'"); 
		$row = mysql_fetch_assoc($result);
		$title = $row['title'];

	return $title;
	
}

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

	
	
	
	if($image != '')
	{//show table
	
		  //get applicant pt
          $pty =  get_applicant_programme_type_applied_for($id);

          $up_path = '';
       
          //when Prence
           if( $pty == 1){
             $up_path = '../prence/uploads/';
             //when NCE
           }elseif ($pty == 2) {
                $up_path = '../nce/uploads/';
           }
		
			$output = '<img class="img-responsive img-rounded img-thumbnail center-block" src='.$up_path.$row["image"].' style="height:100px ;width:80px"    />'; //https://eportals.ibbuconsult.com.ng/ndp/uploads/'.$row['image'].'
			
	
	}
	else
	{
		$output = '<label class="label label-danger">NO IMAGE</label>'; 
	}
	
	
	return $output;
	
	
	
	
}//end of function that shows candidate image


//function view applicants listings
function view_applicants_list()
{
	
	
	//query the database
	$q = "SELECT `id`, `programme_type_applied_for`, `department_applied_for`, `programme_applied_for`, `application_number`, `state_id`, `lga_id`, `first_name`, `other_names`, `phone_no`,  `gender`,  `email`,  `transaction_id`, `bank_epin`, `serial_number`, DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		 DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		 FROM  applicants
		 
		 
		 WHERE  bank_epin != ''
		 
		 ORDER BY application_number ASC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>Applied For</th>
						<th>Ph. Contacts</th>
						<th>Email</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						
						
						
			</thead>
			<tfoot>
						
						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>Applied For</th>
						
						<th>Ph. Contacts</th>
						<th>Email</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td>".$row['application_number']."</td>";
			$output .= "<td> <a href='gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$row['id']."'>".$row['first_name'].' '.$row['other_names']."</a></td>";
			$output .= "<td>".$row['gender']."</td>";
			$output .= "<td>".show_programme_type($row['programme_type_applied_for'])."</td>";
			$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>"; 
			
			$output .= "<td>".$row['phone_no']."</td>"; 
			$output .= "<td>".$row['email']."</td>";
			$output .= "<td>".get_state_title($row['state_id'])."</td>";
			$output .= "<td>".get_lga_title($row['lga_id'])."</td>";
			$output .= "<td>".get_applicant_image($row['id'])."</td>";
			
			
			
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view applicants listings


//function view applicants listings per programmes
function view_applicants_list_per_programmes($pt,$p) // pt programm type , p programme //AND applicants.id = applicants_fee_payments.applicant_id
{
	//please remove applicant later
	
	//query the database
	$q = "SELECT id, programme_type_applied_for, school_applied_for,department_applied_for, programme_applied_for, application_number,
		  state_id, lga_id, first_name, other_names, phone_no, gender,  email,   
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		  FROM  applicants_nce 
		 
		  WHERE   programme_type_applied_for = '$pt' AND programme_applied_for = '$p' 
		 
		  ORDER BY application_number ASC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>School Applied For</th>
						<th>Applied For</th>
						
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Admission Status</th>
						
						
						
			</thead>
			<tfoot>
						
						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>School Applied For</th>

						<th>Applied For</th>
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						<th>Admission Status</th>
						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td>".$row['application_number']."</td>";
			$output .= "<td> <a href='gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$row['id']."' target='_new'>".$row['first_name'].' '.$row['other_names']."</a></td>";
			$output .= "<td>".$row['gender']."</td>";
			$output .= "<td>".show_programme_type($row['programme_type_applied_for'])."</td>";
			$output .= "<td>".get_school_title($row['school_applied_for'])."</td>"; 

			$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>"; 
			$output .= "<td>".$row['phone_no']."</td>"; 
			$output .= "<td>".get_state_title($row['state_id'])."</td>";
			$output .= "<td>".get_lga_title($row['lga_id'])."</td>";
			$output .= "<td>".get_applicant_image($row['id'])."</td>";
			$output .= "<td>".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

	



//check if admitted and display button
function is_admitted($id)
{
		$result = mysql_query("SELECT * FROM applicants WHERE id = '$id'"); 
		$row = mysql_fetch_assoc($result);
		$admission_status = $row['admission_status'];

		
		if($admission_status == '0')
		{
			return '<a class="btn btn-warning btn-sm" >  Pending </a> ';
		}
		else
		{
			return '<a class="btn btn-success btn-sm" >  Admitted </a> <br/><br/>
					';//<a class="btn-info btn-sm" target="_blank"  href="https://apply.ndp.ibbuconsult.com.ng/applications_1/create_application_letter.php?u='.$id.'&c='. md5('EasyBrother').'"> Print Letter </a>
			
			
		}
		
		
		
}// check if admitted


//check if admitted and display MODAL  button
function is_applicant_admitted($id)
{
		$result = mysql_query("SELECT * FROM applicants_nce WHERE id = '$id'"); 
		$row = mysql_fetch_assoc($result);
		$admission_status = $row['admission_status'];

		
		
		return $admission_status;		
		
		//return value
		
}


//get list of the programmes 
function  get_programme_list($pt)
{	
	$result = mysql_query("SELECT * FROM programmes WHERE type_id = '$pt'"); 
		
		
	//if(mysql_num_rows($result>0))
//	{	
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			echo '<a href="gateway.php?act=view_applicants_per_course&a='.sha1('fucku').'&pt='.$row['type_id'].'&p='.$row['id'].'" class="btn btn-success  btn-lg" target="_blank" style="margin:4px;" >'.$row['title'].' - <span class="badge">'.get_total_prog_type_programme_applicants($pt,$row['id']).'</span>'.'</a> <br/>';
		}
		
	//}
//	else
//	{
//		echo "No data found..";
//	}
		
}


//function get total admitted applicants  
function get_total_admitted_applicants()
{
	$q = "SELECT COUNT(id) FROM applicants_nce WHERE  admission_status = '1'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);
	
	return $row[0];
	
}


//function get total admitted applicants  per programme type
function get_total_admitted_applicants_per_programme_type($pt)
{
	$q = "SELECT COUNT(id) FROM applicants_nce WHERE  admission_status = '1'  AND type_id = '$pt'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);
	
	return $row[0];
	
}


//get list of the programmes admitted candidate
function  get_programme_list_admitted_applicants($pt)
{	
	$result = mysql_query("SELECT * FROM programmes WHERE type_id = '$pt'"); 
		
		
	//if(mysql_num_rows($result>0))
//	{	
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			echo '<a href="gateway.php?act=view_admitted_applicants_per_course&a='.sha1('fucku').'&pt='.$row['type_id'].'&p='.$row['id'].'" class="btn btn-success  btn-lg" style="margin:4px;" >'.$row['title'].' - <span class="badge">'.get_total_prog_type_programme_admitted_applicants($row['type_id'],$row['id'], $admitted = '1').'</span> / <span class="badge">'.get_total_prog_type_programme_applicants($row['type_id'],$row['id']).'</span> '.'</a><br/>';
		}
		
	//}
//	else
//	{
//		echo "No data found..";
//	}
		
}


//function get total applicants admitted in a programme 
function get_total_prog_type_programme_admitted_applicants($pt, $id, $admitted)
{
	$q = "SELECT COUNT(id) FROM applicants_nce  WHERE type_id = '$pt' AND programme_id = '$id' AND admission_status = '$admitted'";
	$r = mysql_query($q);
	$row = mysql_fetch_array($r,MYSQL_NUM);
	
	return $row[0];
	
}




//function view admitted applicants listings per programmes
function view_admitted_applicants_list_per_programmes($pt,$p, $admitted) // pt programm type , p programme
{
	
	
	//query the database
	$q = "SELECT `id`, `programme_type_applied_for`, `department_applied_for`, `programme_applied_for`,`type_id`,`department_id`,`programme_id`,
	     `application_number`, `state_id`, `lga_id`, `first_name`, `other_names`, `phone_no`,  `gender`,  `email`, 
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		  FROM  applicants_nce
		 
		  WHERE   type_id = '$pt' AND programme_id = '$p' AND admission_status = '$admitted' 
		 
		  ORDER BY application_number ASC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>Applied For</th>
						<th>Department</th>
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						
						
						
						
			</thead>
			<tfoot>
						
						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>Applied For</th>
						<th>Department</th>
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						
						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td>".$row['application_number']."</td>";
			$output .= "<td> <a href='gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$row['id']."' target='_new'>".$row['first_name'].' '.$row['other_names']."</a></td>";
			$output .= "<td>".$row['gender']."</td>";
			$output .= "<td>".show_programme_type($row['type_id'])."</td>";
			$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";
			$output .= "<td>".get_programme_title($row['programme_id'])."</td>"; 
			$output .= "<td>".$row['phone_no']."</td>"; 
			$output .= "<td>".get_state_title($row['state_id'])."</td>";
			$output .= "<td>".get_lga_title($row['lga_id'])."</td>";
			$output .= "<td>".get_applicant_image($row['id'])."</td>";
			
			
			
			
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view admitted  applicants listings per programmes


//function view all admitted applicants listings 
function view_all_admitted_applicants_list($admitted, $pt) // pt programm type , p programme
{
	
	
	//query the database
	$q = "SELECT `id`, `programme_type_applied_for`, `school_applied_for`,`department_applied_for`, `programme_applied_for`,`type_id`,`school_id`,`department_id`,`programme_id`,
	     `application_number`, `state_id`, `lga_id`, `first_name`, `other_names`, `phone_no`,  `gender`,  `email`, 
		  DATE_FORMAT(date_added, '%M %d, %Y %l:%i:%p') as date_added,
		  DATE_FORMAT(date_modified, '%M %d, %Y %l:%i:%p') as date_modified
		  FROM  applicants_nce
		 
		  WHERE  admission_status = '$admitted' AND type_id = '$pt'
		 
		  ORDER BY application_number ASC";
	$r = mysql_query($q);
	
	if(mysql_num_rows($r) > 0)
	{//show table
	
	
		
		  $output = 
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>Applied For</th>
						<th>Department</th>
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						
						
						
						
			</thead>
			<tfoot>
						
						<th>Application No.</th>
						<th>Name</th>
						<th>Gender</th>
						<th>Programme Type</th>
						<th>Applied For</th>
						<th>Department</th>
						<th>Ph. Contacts</th>
						<th>State</th>
						<th>L.G.A</th>
						<th>Passports</th>
						
						
			</tfoot>
			
			<tbody>';
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td>".$row['application_number']."</td>";
			$output .= "<td> <a href='gateway.php?act=view_applicant_profile&id=".md5('profile')."&xd=".$row['id']."' target='_new'>".$row['first_name'].' '.$row['other_names']."</a></td>";
			$output .= "<td>".$row['gender']."</td>";
			$output .= "<td>".show_programme_type($row['type_id'])."</td>";
			$output .= "<td>".get_programme_title($row['programme_applied_for'])."</td>";
			$output .= "<td>".get_programme_title($row['programme_id'])."</td>"; 
			$output .= "<td>".$row['phone_no']."</td>"; 
			$output .= "<td>".get_state_title($row['state_id'])."</td>";
			$output .= "<td>".get_lga_title($row['lga_id'])."</td>";
			$output .= "<td>".get_applicant_image($row['id'])."</td>";
			
			
			
			
			$output .= "</tr>";
			
			
		}
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
}//end of view all admitted  applicants 




	//////////////////////// remita log 
	//function view transaction log
	function view_remita_transaction_log()
	{
		
		//query the database
		$query = "SELECT `id`, `invoice_id`, `transaction_type`, `user_id`, `transaction_for`, `payment_method`, 
		`payment_status`, `response_code`, `response_description`,`transaction_id`, `transaction_reference`,
		 `title`, `description`, `amount`, DATE_FORMAT(date_added, '%b %e, %Y /  %l:%i:%p') as date_added,
		 DATE_FORMAT(transaction_date, '%b %e, %Y /  %l:%i:%p') as transaction_date

		 FROM `remita_webpay_transaction_log`
		 		 
		 ORDER BY id DESC";
	   $result = mysql_query($query);
	   
		
		
		if(mysql_num_rows($result) > 0)
		{//show table
		
		
			$output = 
			'<table id="example" class="user display table-bordered table-hover table-striped responsive" width="100%"  cellspacing="0" style="font-size:12px;">
			  <thead>
					 
						  <th>Invoice #</th>
						  <th>RRR</th>
						  <th>Transaction Ref.</th>
						  <th>Title</th>
						  <th>Amount- (N)</th>
						  <th>Transaction Response</th>
						  <th>Transaction Date / Time</th>
						  <th>Status</th>
						  <th>Action</th>

		
			  </thead>
			  
			 <!-- <tfoot>
		
			  </tfoot>-->
			  
			  <tbody>';
		
		
			while($row = mysql_fetch_array($result, MYSQL_ASSOC))
			{
			   // $int_amount = $row['amount'] * 100;

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

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

				$output .= "<td>".$row['date_added']."</td>";
				
				
				$output .= "<td>".transaction_status($row['payment_status'])."</td>";
				
				if($row['payment_status'] != '1')
				{
				  $output .= '<td><a target="_blank" class="btn btn-sm btn-primary" href="gateway.php?act=view_rr_log&txnref='.$row['transaction_reference'].'" > Re - Query </a></td>';
				}
				else
				{ 
				   $output .= "<td></td>";
					
				}
				
				$output .= "</tr>";
				
			}
		}
		else
		{//show the msg 
		
			  $output = 
					 '<div class="alert alert-danger alert-dismissable"> 
					  <button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					  <img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
					 </div>';
		  
			
		}
		
		
		
		$output .=
		'</tbody>
		</table>';
		
		
		
		
		
		return $output;
		
		
		
		
	   
	
	}//end of view transaction log
	
	
	//function transaction status
	  function transaction_status($id)
	  {
		  if($id == '1')
		  {
			  return '<label class="label label-success"> SUCCESSFUL </label>';
		  }
		  else
		  {
			  return  '<label class="label label-danger"> PENDING </label>';
		  }
	  }
	  
	  
	  
	  //function transaction type user
	  function transaction_type_user($id)
	  {
		  if($id == '0')
		  {
			  return '<label class="label label-default"> APPLICANT </label>';
		  }
		  else if($id == '1')
		  {
			  return  '<label class="label label-info"> FRESH STUDENT </label>';
		  }
		  else if ($id == '2')
		  {
			  return  '<label class="label label-primary"> RETURNING STUDENT </label>';

		  }
		  else if ($id == '3')
		  {
			  return  '<label class="label label-primary"> REMDIAL STUDENT </label>';

		  }
		  else
		  {
			  //
		  }
	  }
	  
	  //function 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 confirmation payments
function view_search_student_b($search_stb)
{
	
	//query the database
	$q = "SELECT `id`, `invoice_id`, `invoice_type`, `invoice_to`, `pay_to`, `invoice_for`, `payment_method`, `payment_status`, `programme_type`,
		 `title`, `description`, `amount`, `total_amount`, `credit`,
	     
		 DATE_FORMAT(date_added, '%b %e, %Y  %l:%i:%p') as date_added
		   
		 	 
		 FROM invoices
		 
		 WHERE invoice_id = '$search_stb'";
		 
		 //LIMIT $start, $display_per_page";
	$r = mysql_query($q) or die (mysql_error());
	
	
	
	
	//in the table below result_table stands for resullt fetch throug seraching table(ajax)
	
	if(mysql_num_rows($r) > 0 )
	{//show table
	
	
	
			
		$output = '<table  class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="text-align:center;">
			  
		  <thead>
		  
		  
		 			  <th><!--<input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"> --></th>
					  <th><h4 style="text-align:center;">Invoice ID Details</h4></th>
					  <th><h4 style="text-align:center;">Invoice To</h4></th>
					  <th ><h4 style="text-align:center;">Pay To</h4></th>
	
		  </thead>
		  
		  <tbody>';
	
	
	
	
		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			if($row['programme_type'] == '1')
			{// if pre nce
				
				
					  if($row['invoice_type'] == '1')
					  {
						  
					  $output .= '<li class="list-group-item help-block" style="text-align:center;">Description  ( '.get_session_title(get_current_session($id = 1)).' Academic Session , 
									'.get_semester_title(get_current_semester($id = 1)).' ) </li>';
								
					  
					  
					  $output .= "<tr>";
					  $output .="<td width='5%' height='10px'><input type='checkbox' value='".$row['invoice_id']."' name='invoice[]' 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/><b>'.show_programme_type($row['programme_type']).'</b><br/>
									   '.get_applicant_address($row['invoice_to']).'<br> <hr/> 
									   
									   
									   <li class="list-group-item help-block" style="height:auto;">
										  <span>'.get_invoice_desc($row['invoice_id']).' 
										  </span> 
																	   
									  </li>
									   <li class="list-group-item help-block">
										  <span>Sub Total: 
										  </span> 
										  <span class="pull-right">N'.number_format(get_invoice_amount($row['invoice_id']) ,2).' 
										  </span>
									  </li>
									  
									  <li class="list-group-item help-block">
										  <span>Credit: 
										  </span> 
										  <span class="pull-right">N'.number_format(get_invoiced_credit($row['invoice_id']) ,2).' 
										  </span>
									  </li>
									  
									  </td>';
					  
					  
					  $output .= '<td width="30%">'.get_invoice_pay_to($row['invoice_id']).' <br/> <hr/>
					  
									  <li class="list-group-item help-block" style="min-height:60px;">
										  
											
										  <span class="pull-right text-success" style="font-size:35px; font-weight:bold;">Total: N'.number_format(get_invoice_total_amount($row['invoice_id']) ,2).'K 
										  </span>
										 
									  </li>  
								  
								 </td>';
					  
					  $output .= "</tr>";
					  
					  }//end of if new student
					  else
					  {// begin if old student
						  
						  
						  $output .= '<li class="list-group-item help-block" style="text-align:center;">Description  ( '.get_session_title(get_current_session($id = 1)).' Academic Session , 
									'.get_semester_title(get_current_semester($id = 1)).' ) </li>';
								
						  
						  
						  $output .= "<tr>";
						  $output .="<td width='5%' height='10px'><input type='checkbox' value='".$row['invoice_id']."' name='invoice[]' 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>";
						  
						  
						  
					  }
				
				
			}
			else
			{
				
			//######################################## nce
			
					  
					  
					  if($row['invoice_type'] == '1')
					  {
						  
					  $output .= '<li class="list-group-item help-block" style="text-align:center;">Description  ( '.get_session_title(get_current_session($id = 1)).' Academic Session , 
									'.get_semester_title(get_current_semester($id = 1)).' ) </li>';
								
					  
					  
					  $output .= "<tr>";
					  $output .="<td width='5%' height='10px'><input type='checkbox' value='".$row['invoice_id']."' name='invoice[]' 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/><br/><b>'.show_programme_type($row['programme_type']).'</b><br/>
									   '.get_applicant_address($row['invoice_to']).'<br> <hr/> 
									   
									   
									   <li class="list-group-item help-block" style="height:auto;">
										  <span>'.get_invoice_desc($row['invoice_id']).' 
										  </span> 
																	   
									  </li>
									   <li class="list-group-item help-block">
										  <span>Sub Total: 
										  </span> 
										  <span class="pull-right">N'.number_format(get_invoice_amount($row['invoice_id']) ,2).' 
										  </span>
									  </li>
									  
									  <li class="list-group-item help-block">
										  <span>Credit: 
										  </span> 
										  <span class="pull-right">N'.number_format(get_invoiced_credit($row['invoice_id']) ,2).' 
										  </span>
									  </li>
									  
									  </td>';
					  
					  
					  $output .= '<td width="30%">'.get_invoice_pay_to($row['invoice_id']).' <br/> <hr/>
					  
									  <li class="list-group-item help-block" style="min-height:60px;">
										  
											
										  <span class="pull-right text-success" style="font-size:35px; font-weight:bold;">Total: N'.number_format(get_invoice_total_amount($row['invoice_id']) ,2).'K 
										  </span>
										 
									  </li>  
								  
								 </td>';
					  
					  $output .= "</tr>";
					  
					  }//end of if new student
					  else
					  {// begin if old student
						  
						  
						  $output .= '<li class="list-group-item help-block" style="text-align:center;">Description  ( '.get_session_title(get_current_session($id = 1)).' Academic Session , 
									'.get_semester_title(get_current_semester($id = 1)).' ) </li>';
								
						  
						  
						  $output .= "<tr>";
						  $output .="<td width='5%' height='10px'><input type='checkbox' value='".$row['invoice_id']."' name='invoice[]' 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 if nce
			
		}//end of while
//			
		
	}
	else
	{//show the msg 
	
			$output = 
				   '<div class="alert alert-danger alert-dismissable"> 
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; Candidate not recognise by the system. We apologize for any inconvenience..
				   </div>';
		
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	//else
//	{
//		$errors['error'] =  'Candidate not recognise by the system. We apologize for any inconvenience.';
//										
//		header("Location: gateway.php?act=search_candidate&error=".urlencode($errors['error'])."");
//	}

	
	
	
	
}//end of view search candidate





//Function to fetch  school_fee title
	function get_school_fee_title($level, $s, $pt, $d, $p) //$pt programme type , $d -department , $p -programme id, $s semester
	{
		$result = mysql_query("SELECT title FROM set_school_fee_payments_for_students WHERE level = '$level' AND semester = '$s' AND programme_type_id = '$pt' AND department_id = '$d' AND programme_id = '$p'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['title'];
		
	return $v;
	}
	
	
	//Function to fetch  school_fee desc
	function get_school_fee_desc($level, $s, $pt, $d, $p)
	{
		$result = mysql_query("SELECT description FROM set_school_fee_payments_for_students WHERE level = '$level' AND semester = '$s' AND programme_type_id = '$pt' AND department_id = '$d' AND programme_id = '$p'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['description'];
		
	return $v;
	}
	
	//Function to fetch  school_fee amount
	function get_school_fee_amount($level, $s, $pt, $d, $p)
	{
		$result = mysql_query("SELECT amount FROM set_school_fee_payments_for_students WHERE level = '$level' AND semester = '$s' AND programme_type_id = '$pt' AND department_id = '$d' AND programme_id = '$p'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['amount'];
		
	return $v;
	}
	
	
	//Function to fetch  school_fee  total amountamount
	function get_school_fee_total_amount($level, $s, $pt, $d, $p)
	{
		$result = mysql_query("SELECT total_amount FROM set_school_fee_payments_for_students WHERE level = '$level' AND semester = '$s' AND programme_type_id = '$pt' AND department_id = '$d' AND programme_id = '$p'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['total_amount'];
		
	return $v;
	}
	
	
	
	
	
	//Function to fetch  invoice credit
	function get_invoice_credit($total_amount , $amount_paid)
	{
		
		//get total amount to be paid
		$total_amount = $total_amount;
		
		
		
		//get part amount paid
		$amount_paid = $amount_paid;
		
		//credit
		$credit = $total_amount - $amount_paid; 
		
		 $v = $credit;
		
	    return $v;
	}
	
	
	
	
	
	//check if invoice id already exist
	function invoice_id_exist($iid)
	{
		//check if invoice id generated exist
		$q1 = "SELECT invoice_id FROM invoices WHERE invoice_id = '$iid'";
		$r1 = mysql_query($q1);
		
		if(mysql_num_rows($r1)>0)
		{
			return true;
		}
		else
		{
			return false;
		}
	
		
	}
	
	
	
	//Function to fetch date 
	function get_invoice_date($iid)
	{
		$result = mysql_query("SELECT  DATE_FORMAT(date_added, '%b %e, %Y') as date_added FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['date_added'];
		
	return $v;
	}
	
	//Function to fetch due date 
	function get_invoice_due_date($iid)
	{
		$result = mysql_query("SELECT  DATE_FORMAT(due_date, '%b %e, %Y') as due_date FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['due_date'];
		
	return $v;
	}


		
	//Function to fetch exp date 
	function get_invoice_exp_date($iid)
	{
		$result = mysql_query("SELECT  DATE_FORMAT(expire_date, '%b %e, %Y /  %l:%i:%p') as exp_date FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['exp_date'];
		
	return $v;
	}
	
	
	
	//Function to fetch  invoice title
	function get_invoice_title($iid)
	{
		$result = mysql_query("SELECT title FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['title'];
		
	return $v;
	}
	
	
	//Function to fetch  invoice type
	function get_invoice_type($iid)
	{
		$result = mysql_query("SELECT invoice_type FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['invoice_type'];
		
	return $v;
	}
	
	
	
	//Function to fetch  invoice to
	function get_invoice_invoice_to($iid)
	{
		$result = mysql_query("SELECT invoice_to FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['invoice_to'];
		
	return $v;
	}
	
	
	//Function to fetch  pay to
	function get_invoice_pay_to($iid)
	{
		$result = mysql_query("SELECT pay_to FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['pay_to'];
		
	return $v;
	}
	
		
	//Function to fetch  invocie for 
	function get_invoice_for($iid)
	{
		$result = mysql_query("SELECT invoice_for FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['invoice_for'];
		
	return $v;
	}
	
	
	//Function to fetch descripion
	function get_invoice_desc($iid)
	{
		$result = mysql_query("SELECT description FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['description'];
		
	return $v;
	}



	//Function to fetch amount
	function get_invoice_amount($iid)
	{
		$result = mysql_query("SELECT amount FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['amount'];
		
	return $v;
	}
	
	
	
	//Function to fetch total amount
	function get_invoice_total_amount($iid)
	{
		$result = mysql_query("SELECT total_amount FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['total_amount'];
		
	return $v;
	}
	
	
	//Function to fetch invoiced credit (credit of invoice generated)
	function get_invoiced_credit($iid)
	{
		$result = mysql_query("SELECT credit FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['credit'];
		
	return $v;
	}
	
	//Function to fetch payment_satus 
	function get_invoice_payment_status($iid)
	{
		$result = mysql_query("SELECT payment_status FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['payment_status'];
		
	return $v;
	}
	
	
	
	//Function to fetch payment mode 
	function get_invoice_payment_mode($iid)
	{
		$result = mysql_query("SELECT payment_mode FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['payment_mode'];
		
	return $v;
	}
	
	
	//Function to fetch total unpaid  invoice generated  
	function get_total_invoice_unpaid($current_session)
	{
		$result = mysql_query("SELECT COUNT(DISTINCT(invoice_to))  FROM invoices WHERE payment_status = '0' AND session = '$current_session'"); 
		$row = mysql_fetch_array($result,MYSQL_NUM);
	
	     return $row[0];
	
	}
	
	
	
	//function showpayment mode
	function show_payment_mode($r)
	{
			
			if ($r == '1')
			{
			
				$output = 'Instalment';
				
			
				
			}
			else if ($r == '2')
			{
				
				$output = 'Full';
			
				
			}
			else
			{
			
				$output = 'Default';
			}
	
		return $output;
	
	}
	//end of show payment mode
	
	
	
	//Function to fetch programme type 
	function get_invoice_programme_type($iid)
	{
		$result = mysql_query("SELECT programme_type FROM invoices WHERE invoice_id = '$iid'"); 
		$row = mysql_fetch_assoc($result);
		$v = $row['programme_type'];
		
	return $v;
	}
	
	
	
	////function show major status type
	function show_major_status($r)
	{
			
			if ($r == '0')
			{
			
				$output = 'SM';
				
			
				
			}
			else if ($r == '1')
			{
				
				$output = 'Dm';
			
				
			}
			else
			{
			
				$output = 'NIL';
			}
	
		return $output;
	
	}
	//end of show programme  type
	
	//function view invoices
function view_invoices($user_id, $type)
{
	
	//query the database
	$query = "SELECT `id`, `invoice_type`,`invoice_id`, `invoice_to`, `pay_to`, `invoice_for`, `payment_method`, `payment_status`,
			 `user_carts`, `title`, `description`, `amount`, `credit`, DATE_FORMAT(date_added, '%b %e, %Y') as date_added, 
			 DATE_FORMAT(due_date, '%b %e, %Y') as due_date, 
			 DATE_FORMAT(expire_date, '%b %e, %Y /  %l:%i:%p') as exp_date
			
			 FROM `invoices` 
			 WHERE invoice_to = '$user_id' AND invoice_type = '$type'
			 
			 
			 ORDER BY invoice_id DESC";
   $result = mysql_query($query);
   
	
	
	if(mysql_num_rows($result) > 0)
	{//show table
	
	
		$output = 
		'<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
		  <thead>
				 
					  <th>Invoice #</th>
					  <th>Invoice Date</th>
					  <th>Due Date</th>
					  <th>Status</th>
					  <th></th>
					 
					
	
		  </thead>
		  
		 <!-- <tfoot>
				 
					 
					
	
		  </tfoot>-->
		  
		  <tbody>';
	
	
		while($row = mysql_fetch_array($result, MYSQL_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td class='text-info' style='font-size:14px; font-weight:bold'>".$row['invoice_id']."</td>"; //group belong to admin or user
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['due_date']."</td>";
			$output .= "<td>".payment_status($row['payment_status'])."</td>";
			$output .= '<td><a class="btn btn-default" href="dashboard.php?act=view_invoices&qlk='.md5(2).'&iid='.$row['invoice_id'].'"> View Invoice</a></td>';
			$output .= "</tr>";
			
		}
	}
	else
	{//show the msg 
	
		  $output = 
				 '<div class="alert alert-danger alert-dismissable"> 
				  <button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
				  <img src="images/info.png" />&nbsp;&nbsp; No record found in the system.
				 </div>';
	  
		
	}
	
	
	
	$output .=
	'</tbody>
    </table>';
	
	
	
	
	
	return $output;
	
	
	
	
   

}//end of view school fee invoices





// function that check if a applicant application number exist in stduents table or not
	function application_number_exist($apn, $l)
	{
		$result = mysql_query("SELECT application_number  FROM students_nce WHERE application_number = '$apn' AND level = '$l'"); 
		$row = mysql_fetch_assoc($result);
		$an = $row['application_number'];
		
		if($an == '')
		{
			
			return false;
					

			
		}
		else
		{
			return true;
			

		}
		
	 
	}
	//end of checking if applicant exist
	
	
	
	// function that check if a applicant application number exist in stduents table or not for pre nce
	function application_number_exist_prence($apn, $l)
	{
		$result = mysql_query("SELECT application_number  FROM students_prence WHERE application_number = '$apn' AND level = '$l'"); 
		$row = mysql_fetch_assoc($result);
		$an = $row['application_number'];
		
		if($an == '')
		{
			
			return false;
					

			
		}
		else
		{
			return true;
			

		}
		
	 
	}
	//end of checking if applicant exist
	
	
	
	
	//function dat checks if student exist in database table 
	function student_id_exist_payments($sid,$sess, $sem)
	{
		$q = "SELECT student_id FROM school_fee_payments_nce  WHERE student_id = '$sid' AND session = '$sess' AND semester = '$sem' ";
		$r = mysql_query($q);
		
		
		if(mysql_num_rows($r) > 0)
		{
			return true;
		}
		else
		{
			return false;
		}
		
		
		
	}//end of function that chk if student id exist in school fee payments
	
	
	
		//function dat checks if student exist in database table  pre nce
		function student_id_exist_payments_prence($sid,$sess, $sem)
		{
			$q = "SELECT student_id FROM school_fee_payments_prence  WHERE student_id = '$sid' AND session = '$sess' AND semester = '$sem' ";
			$r = mysql_query($q);
			
			
			if(mysql_num_rows($r) > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
			
			
			
		}//end of function that chk if student id exist in school fee payments




//function generate matric number
function generate_matric_number($pt, $dep, $p, $level, $total_in_programme)
{
	
	//check programme type to know if to give AD or D
		if($pt == '1')
		{
			$first_letter = 'PN';
		}
		else if($pt == '2')
		{
			
			//this is for NCE get the programme codes for schools
			//$first_letter = 'SE';
			
			//get school code by passing the school id
			$first_letter = strtoupper(get_school_code($dep));
		}
		else if($pt == '3')
		{
			$first_letter = 'U'; //This is for Degree
		}
		else
		{
			//do nothing
			
		}
	
	
	
	
	//get programme code from programme 
	
	$programme_code = strtoupper(get_programme_code($p));  //get the department code from applied department
	
	
	//if i know ur admitted departmen, ican check by passing the id to programme so to get total
	//$total_in_programme = get_total_programme_students($pt,$dep,$p,$l);
	
	$total = $total_in_programme;
	
	
	
	
	//getcuurent sesssiom
	//Function to fetch current session
	 $session = get_current_session($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);
	
	if($count_character == '1')
	{
		$total = '000'.$total;
	}
	else if($count_character == '2')
	{
		$total = '00'.$total;
	}
	else if($count_character == '3')
	{
		$total = '0'.$total;
	}
	else if($count_character == '4')
	{
		$total = $total;
	}
	else
	{
		//do nothing for now
	}
	
	
	
	//$matric_number = $first_letter.$year.'/'.$programme_code.'/'.$total; //give the matric number if not exist
	$matric_number =	 $first_letter.'/'.$programme_code.'/'.$year.'/'.$total;

	
	
	
	if(matric_number_exist($matric_number)) //if matric no exis, do obstruct and pass through some test
	{
		
			
			//$mn = $first_letter.$year.'/'.$programme_code.'/'; //collect the matric parameters
			$mn =  $first_letter.'/'.$programme_code.'/'.$year.'/'; //collect the matric parameters

			//collect all the matric number
			
			
			$q = "SELECT number FROM students_nce WHERE number LIKE '%$mn%'";
			$r = mysql_query($q);
			
			//$row = mysql_fetch_array($r, MYSQL_ASSOC);
			$mmno = array(); //array declared to hold all the matric numbers
			while($row = mysql_fetch_array($r, MYSQL_ASSOC))
			{
				
				$number = $row['number']; //collect all the matric numbers and pass to an array
				
				$filtered_no = substr($number, 15,4);
				$mmno[] = $filtered_no; //no need to implode
				
			}
			
					//$comma_separated = implode(",", $mmno);
		
			
			$highestmn = max($mmno); //check the max number from stored arrays
			
			$hn = $highestmn + 1; //ad 1 to the highest
			
			$count_character2 = strlen($hn); //count the xters
	
			if($count_character2 == '1')
			{
				$hn = '000'.$hn;
			}
			else if($count_character2 == '2')
			{
				$hn = '00'.$hn;
			}
			else if($count_character2 == '3')
			{
				$hn = '0'.$hn;
			}
			else if($count_character2 == '4')
			{
				$hn = $hn;
			}
			else
			{
				//do nothing for now
			}
	
		
	
	
			//$matric_numbe = $first_letter.$year.'/'.$programme_code.'/'.$hn; //pad the matric numbers with the right strings
			$matric_numbe = $first_letter.'/'.$programme_code.'/'.$year.'/'.$hn; //pad the matric numbers with the right strings

			
			
			return $matric_numbe ;
	
		//}

		
	}
	else
	{
		return $matric_number;
	}
	
	
	//return $matric_number;
	 
}


//function that gets school code base on course id
	function  get_school_code($id)
	{	
		$result = mysql_query("SELECT code FROM schools WHERE id = '$id'"); 
			$row = mysql_fetch_assoc($result);
			$v = $row['code'];
	
		return $v;
		
	}
	


//function generate matric number for pre nce
function generate_matric_number_prence($pt, $dep, $p, $level, $total_in_programme)
{
	
	//check programme type to know if to give 
		if($pt == '1')
		{
			$first_letter = 'PR/'.strtoupper(get_school_code($dep));;
		}
		else if($pt == '2')
		{
			
			//this is for NCE get the programme codes for schools
			//$first_letter = 'SE';
			
			//get school code by passing the school id
			//$first_letter = strtoupper(get_school_code($dep));
		}
		else if($pt == '3')
		{
			//$first_letter = 'U'; //This is for Degree
		}
		else
		{
			//do nothing
			
		}
	
	
	
	
	//get programme code from programme 
	
	$programme_code = strtoupper(get_programme_code($p));  //get the department code from applied department
	
	
	//if i know ur admitted departmen, ican check by passing the id to programme so to get total
	//$total_in_programme = get_total_programme_students($pt,$dep,$p,$l);
	
	$total = $total_in_programme;
	
	
	
	
	//getcuurent sesssiom
	//Function to fetch current session
	 $session = get_current_session($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);
	
	if($count_character == '1')
	{
		$total = '000'.$total;
	}
	else if($count_character == '2')
	{
		$total = '00'.$total;
	}
	else if($count_character == '3')
	{
		$total = '0'.$total;
	}
	else if($count_character == '4')
	{
		$total = $total;
	}
	else
	{
		//do nothing for now
	}
	
	
	
	//$matric_number = $first_letter.$year.'/'.$programme_code.'/'.$total; //give the matric number if not exist
	$matric_number =	 $first_letter.'/'.$programme_code.'/'.$year.'/'.$total;

	
	
	
	if(matric_number_exist_prence($matric_number)) //if matric no exis, do obstruct and pass through some test
	{
		
			
			//$mn = $first_letter.$year.'/'.$programme_code.'/'; //collect the matric parameters
			$mn =  $first_letter.'/'.$programme_code.'/'.$year.'/'; //collect the matric parameters

			//collect all the matric number
			
			
			$q = "SELECT number FROM students_prence WHERE number LIKE '%$mn%'";
			$r = mysql_query($q);
			
			//$row = mysql_fetch_array($r, MYSQL_ASSOC);
			$mmno = array(); //array declared to hold all the matric numbers
			while($row = mysql_fetch_array($r, MYSQL_ASSOC))
			{
				
				$number = $row['number']; //collect all the matric numbers and pass to an array
				
				$filtered_no = substr($number, 15,4);
				$mmno[] = $filtered_no; //no need to implode
				
			}
			
					//$comma_separated = implode(",", $mmno);
		
			
			$highestmn = max($mmno); //check the max number from stored arrays
			
			$hn = $highestmn + 1; //ad 1 to the highest
			
			$count_character2 = strlen($hn); //count the xters
	
			if($count_character2 == '1')
			{
				$hn = '000'.$hn;
			}
			else if($count_character2 == '2')
			{
				$hn = '00'.$hn;
			}
			else if($count_character2 == '3')
			{
				$hn = '0'.$hn;
			}
			else if($count_character2 == '4')
			{
				$hn = $hn;
			}
			else
			{
				//do nothing for now
			}
	
		
	
	
			//$matric_numbe = $first_letter.$year.'/'.$programme_code.'/'.$hn; //pad the matric numbers with the right strings
			$matric_numbe = $first_letter.'/'.$programme_code.'/'.$year.'/'.$hn; //pad the matric numbers with the right strings

			
			
			return $matric_numbe ;
	
		//}

		
	}
	else
	{
		return $matric_number;
	}
	
	
	//return $matric_number;
	 
}
//end of generate matric no for pre nce

//Functions to fetch student Full name
	function get_student_fullname($id)
	{
		$result = mysql_query("SELECT * FROM students_nce WHERE id = '$id'"); 
		$row = mysql_fetch_assoc($result);
		$first_name = $row['first_name'];
		$other_names = $row['other_names'];
		
		$user_fullname = $first_name . " " . $other_names;

	  return $user_fullname;
	}



//Functions to fetch student Full name
	function get_student_fullname_prence($id)
	{
		$result = mysql_query("SELECT * FROM students_prence WHERE id = '$id'"); 
		$row = mysql_fetch_assoc($result);
		$first_name = $row['first_name'];
		$other_names = $row['other_names'];
		
		$user_fullname = $first_name . " " . $other_names;

	  return $user_fullname;
	}




   //function dat get student matric number
	function get_student_matric_number($user_id)
	{
	$q = "SELECT number FROM students_nce WHERE id = '$user_id'";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	
	return $row['number'];
	
	
	}
	
	
	
	
	 //function dat get student matric number pre nce
	function get_student_matric_number_prence($user_id)
	{
	$q = "SELECT number FROM students_prence WHERE id = '$user_id'";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	
	return $row['number'];
	
	
	}
	
	
	//function dat get student address
	function get_student_address($user_id)
	{
	$q = "SELECT address FROM students_nce WHERE id = '$user_id'";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);
	
	return $row['address'];
	
	
	}
	
	
	//function fetch student department 
	function get_student_department_id($id)
	{
		$result = mysql_query("SELECT department_id FROM students WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['department_id'];
		
		
		return $v;
	}
	
	
	
	//function fetch student programme 
	function get_student_programme_id($id)
	{
		$result = mysql_query("SELECT programme_id FROM students_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['programme_id'];
		
		
		return $v;
	}
	
	//function fetch student programme  prence
	function get_student_programme_id_prence($id)
	{
		$result = mysql_query("SELECT programme_id FROM students_prence WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['programme_id'];
		
		
		return $v;
	}
	
	
	
	//function fetch student school 
	function get_student_school_id($id)
	{
		$result = mysql_query("SELECT school_id FROM students_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['school_id'];
		
		
		return $v;
	}
	
	//function fetch student school  pre nce
	function get_student_school_id_prence($id)
	{
		$result = mysql_query("SELECT school_id FROM students_prence WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['school_id'];
		
		
		return $v;
	}
	
	
	//function fetch student programme type
	function get_student_programme_type_id($id)
	{
		$result = mysql_query("SELECT type_id FROM students_nce WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['type_id'];
		
		
		return $v;
	}
	
	
	
	//function fetch student id by application number
	function get_student_id_application_number($id, $l) //$l is level
	{
		$result = mysql_query("SELECT id FROM students_nce WHERE application_number = '$id' AND level = '$l'");
		$row = mysql_fetch_assoc($result);
		$v = $row['id'];
		
		
		return $v;
	}
	
	//function fetch student id by application number
	function get_student_id_application_number_prence($id, $l) //$l is level
	{
		$result = mysql_query("SELECT id FROM students_prence WHERE application_number = '$id' AND level = '$l'");
		$row = mysql_fetch_assoc($result);
		$v = $row['id'];
		
		
		return $v;
	}
	
	//check if a particular matric number is on the system
	function matric_number_exist($mno)
	{
	    $result = mysql_query("SELECT number FROM students_nce WHERE number = '$mno'"); 
		$row = mysql_fetch_assoc($result);
		$mno = $row['number'];
		
		if($mno == '')
		{
			
			return false;
			
		}
		else
		{
			return true;

		}
	
	
	}
	
	
		//check if a particular matric number is on the system for prence
		function matric_number_exist_prence($mno)
		{
			$result = mysql_query("SELECT number FROM students_prence WHERE number = '$mno'"); 
			$row = mysql_fetch_assoc($result);
			$mno = $row['number'];
			
			if($mno == '')
			{
				
				return false;
				
			}
			else
			{
				return true;
	
			}
		
		
		}// matric number exist pre nce
	
	
	
	
	/////////////////report for the student
	//function count number of non sport/unicef
	function get_total_confirmed_payments_per_semester($session, $semester)
	{
		$q = "SELECT COUNT(DISTINCT student_id) FROM school_fee_payments_nce WHERE  session = '$session' AND semester = '$semester' AND student_id != '' AND (sponsorship_type != '4' AND sponsorship_type != '5')";
		$r = mysql_query($q);
		$row = mysql_fetch_array($r,MYSQL_NUM);
		
		
		$v = number_format($row[0]);
		
		return $v;
		//return ;
	}




	//function count number of bank confirmation for prence non sport/unicef
	function get_total_confirmed_payments_per_semester_prence($session, $semester)
	{
		$q = "SELECT COUNT(DISTINCT student_id) FROM school_fee_payments_prence WHERE  session = '$session' AND semester = '$semester' AND student_id != '' AND (sponsorship_type != '4' AND sponsorship_type != '5')";
		$r = mysql_query($q);
		$row = mysql_fetch_array($r,MYSQL_NUM);
		
		
		$v = number_format($row[0]);
		
		return $v;
		//return ;
	}


		//function count number for support
	function get_total_confirmed_payments_per_semester_sport($session, $semester)
	{
		$q = "SELECT COUNT(DISTINCT student_id) FROM school_fee_payments_nce WHERE  session = '$session' AND semester = '$semester' AND student_id != '' AND sponsorship_type = '5'";
		$r = mysql_query($q);
		$row = mysql_fetch_array($r,MYSQL_NUM);
		
		
		$v = number_format($row[0]);
		
		return $v;
		//return ;
	}
	
	//function count number of bank confirmation for prence for sport
	function get_total_confirmed_payments_per_semester_prence_sport($session, $semester)
	{
		$q = "SELECT COUNT(DISTINCT student_id) FROM school_fee_payments_prence WHERE  session = '$session' AND semester = '$semester' AND student_id != '' AND sponsorship_type = '5'";
		$r = mysql_query($q);
		$row = mysql_fetch_array($r,MYSQL_NUM);
		
		
		$v = number_format($row[0]);
		
		return $v;
		//return ;
	}
	
	
		//function count number for unicef
	function get_total_confirmed_payments_per_semester_unicef($session, $semester)
	{
		$q = "SELECT COUNT(DISTINCT student_id) FROM school_fee_payments_nce WHERE  session = '$session' AND semester = '$semester' AND student_id != '' AND sponsorship_type = '4'";
		$r = mysql_query($q);
		$row = mysql_fetch_array($r,MYSQL_NUM);
		
		
		$v = number_format($row[0]);
		
		return $v;
		//return ;
	}
	
	//function count number of bank confirmation for prence for unicef
	function get_total_confirmed_payments_per_semester_prence_unicef($session, $semester)
	{
		$q = "SELECT COUNT(DISTINCT student_id) FROM school_fee_payments_prence WHERE  session = '$session' AND semester = '$semester' AND student_id != '' AND sponsorship_type = '4'";
		$r = mysql_query($q);
		$row = mysql_fetch_array($r,MYSQL_NUM);
		
		
		$v = number_format($row[0]);
		
		return $v;
		//return ;
	}



/********************* student function module ************************************************/






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



//function check epin limt
//function is_epin_limit()
//{
//	//collect the total epin generated
//	$total = get_total_epin_generated();
//	
//	
//	
//	
//	if($total >=  200)
//	{
//		
//		return true;
//	}
//	else
//	{
//		return false;
//	}
//}




/******************************** end of applicants module  ************************************/


?>