<?php
@session_start();

require_once('configuration.php');


ob_start();

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

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

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

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

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


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

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



		return $at;



}





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


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

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


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


			}



}


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

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

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



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

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

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







//get staff first name, last name
function get_staff_name($user_id)
{
	$query = "SELECT  first_name   AS name FROM staff WHERE id ='$user_id'";
	$result = mysqli_query(dbc(), $query);
	$row = mysqli_fetch_assoc($result);

	return $row['name'];

}

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

	return $row['last_logout'];
}



//function dat get staffgroup by id type
function get_staff_groupid($user_id)
{
	$q = "SELECT group_id FROM staff WHERE id = '$user_id' ";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);

	return $row['group_id'];


}


//function dat get staff group by title type
function get_staff_group_title($user_id)
{
	$q = "SELECT s.group_id, sg.id sg_id, sg.title as group_title FROM staff s, staff_groups sg
		  WHERE s.group_id = sg.id AND s.id = '$user_id' ";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);

	return $row['group_title'];


}


//function dat get staff group menu privileges based on logged in user
function get_user_group_header_menu_privileges($user_id)
{
	$q = "SELECT s.group_id, sg.id as sg_id, sg.header_menu FROM staff s, staff_groups sg
		  WHERE s.group_id = sg.id AND s.id = '$user_id' ";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);

	return $row['header_menu'];


}



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

	return $row['toolbar_menu'];


}




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

	return $row['home_menu'];


}




//function dat get staff group home menu privileges based on logged in user
function get_staff_group_landing_menu_privileges($user_id)
{
	$q = "SELECT s.group_id, sg.id as sg_id, sg.landing_menu FROM staff s, staff_groups sg
		  WHERE s.group_id = sg.id AND s.id = '$user_id' ";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);

	return $row['landing_menu'];


}



//function get user ip
function get_user_ip($user_id)
{
	$q = "SELECT last_login_ip FROM staff WHERE id = '$user_id' ";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);

	return $row['last_login_ip'];


}

//function dat get staff security id  by id
function get_security_id($user_id)
{
	$q = "SELECT security_id FROM staff WHERE id = '$user_id' ";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);

	return $row['security_id'];


}




//get department for staff
function get_user_department($user_id)
{
	$query = "SELECT  department_id   FROM staff WHERE id ='$user_id'";
	$result = mysqli_query(dbc(), $query);
	$row = mysqli_fetch_assoc($result);

	$v =  $row['department_id'];

	return $v;

}

//get department for staff using programme id supplied
function get_department_using_programme_id($id)
{
	$query = "SELECT  department_id   FROM programmes WHERE id ='$id'";
	$result = mysqli_query(dbc(), $query);
	$row = mysqli_fetch_assoc($result);

	$v =  $row['department_id'];

	return $v;

}


//get department comb using programme id
function get_department_comb_using_programme_id($id)
{
	$query = "SELECT  department_comb   FROM programmes WHERE id ='$id'";
	$result = mysqli_query(dbc(), $query);
	$row = mysqli_fetch_assoc($result);

	$v =  $row['department_comb'];

	return $v;

}

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

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

	mysqli_query(dbc(), "UPDATE generate_code  SET code = '$g_coded'");

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

	return $security_id;
}



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

}



//function view staff log
function view_staff_log()
{

	//query the database
	$query = "SELECT s.id as sid, s.security_id, CONCAT_WS(' ', s.first_name, s.other_names) as name, sl.log_id, sl.staff_id, sl.log_action,
			 DATE_FORMAT(sl.log_date, '%b %e, %Y  %l:%i:%p')as log_date

			 FROM staff s, staff_log sl

			 WHERE s.id = sl.staff_id


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










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


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

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



		  </thead>

		  <tfoot>

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



		  </tfoot>

		  <tbody>';


		while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .= "<td>".$row['name']."</td>"; //group belong to admin or user
			$output .= "<td>".$row['security_id']."</td>";
			$output .= "<td>".$row['log_action']."</td>";
			$output .= "<td>".$row['log_date']."</td>";
			$output .= "</tr>";

		}
	}
	else
	{//show the msg

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


	}



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





	return $output;






}//end of view user log






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





//function that gets header menu privileges
function header_menu($privileges)
{
	@$list .= '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/admin_small.png" />Extras<b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="landing.php?act=landing"><img src="images/admin_small.png" />Home</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=#"><img src="images/mass_messaging_small.png" />Message</a></li> -->
						</ul>
					</li>';

	if(is_admin(get_user_id())) //check if super admin
	{

	$privilege[1] = '<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#"><img src="images/users_icon.png" /> Staff <b class="caret"></b></a>
						<ul class="dropdown-menu">
							<li><a href="gateway.php?act=view_staffs"><img src="images/user_manager_small.png">Staff 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 -->
						 </ul>
					</li>';
	}//if super admin







	/*$privilege[4] = '<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 dat get student matric number
	function get_student_matric_number($user_id)
	{
	$q = "SELECT number FROM hostel_students WHERE id = '$user_id'";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);

	return $row['number'];


	}


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

	return $row['address'];


	}





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


		return $v;
	}



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


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


		return $v;
	}

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

		if($mno == '')
		{

			return false;

		}
		else
		{
			return true;

		}


	}


//function that displays landing menu goes here
function landing_menu($privileges)
{
	//check if admin and echo this
	if(is_admin(get_user_id()))
	{
	@$list .= '<a  href="gateway.php?act=view_staffs"><div class="well btn-default col-lg-2 text-center" style="margin-left:300px;"><img src="images/profile.png" data-toggle="tooltip" title="My Profile" />
	<h6>Staff Manager</h6></div></a>';

	}

	// $privilege[1] = '<div class="well btn-default col-lg-2 text-center"><a href="#"><img src="images/cv.png" data-toggle="tooltip" title="CV Manager" />
	// <h6>CV Manager</h6>	</a> </div>';

	$privilege[1] = '';

    $privilege[2] = '<a href="gateway.php?act=view_students_payments_b"><div class="well btn-default col-lg-2 text-center"><img src="images/list_todo.png" data-toggle="tooltip" title="Allocation/ Payment Verification" />
					<h6>Hostel Allocation Verification</h6></div></a>';


	$privilege[3] = '';

	if(is_admin(get_user_id()))
	{
		$privilege[4] = ''; //gateway.php?act=view_schools_list_cr

	}

		// $privilege[4] = '<div class="well btn-default col-lg-2 text-center"><a  href="#"><img src="images/hostel.png" data-toggle="tooltip" title="Hostel Admin" />
		// <h6>Hostel Admin</h6></a>
		// </div>';

	// $privilege[6] = '<div class="well btn-default col-lg-2 text-center"><a  href="gateway.php?act=view_system_info"><img src="images/dashboard.png" data-toggle="tooltip" title="Dashboard" />
	// 				<h6>Dashboard</h6></a>
	// 				</div>';


	/*$privilege[7] = '<div class="well btn-default col-lg-2 text-center"><a  href="gateway.php?act=view_system_info"><img src="images/paperless.png" data-toggle="tooltip" title="eOFFICE" />
					<h6>eOFFICE</h6></a>
					</div>';*/

	$privilege[5] = '<a  href="gateway.php?act=how_to_use"><div class="well btn-default col-lg-2 text-center"><img src="images/how_to_use.png" data-toggle="tooltip"
					title="Help Me" /><h6>How to use?</h6></div></a>';

					//gateway.php?act=view_how_to_use

	// $privilege[9] = '<div class="well btn-default col-lg-2 text-center"><a  href="gateway.php?act=view_how_to_use"><img src="images/support.png" data-toggle="tooltip"
	// 				title="Help Me" /><h6>Support</h6></a></div>';





	//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 landing menu


/*********************************** admin student module ****************************************/
//fucntion that returns searched students confirmation payments
function view_search_student_b($search_stb)
{

	//query the database
	$q = "SELECT CONCAT_WS(' ', first_name, other_names) as name, invoices.id,invoices.invoice_id,
	invoices.invoice_type,invoices.invoice_to, invoices.pay_to, invoices.invoice_for, invoices.payment_method,
	invoices.payment_status, invoices.title, invoices.description, invoices.amount, invoices.total_amount,
	invoices.credit, DATE_FORMAT(invoices.date_added, '%b %e, %Y  %l:%i:%p') as date_added, phone_no,number,
	hostel_students.id AS id,hostel_students.gender AS gender,state.title AS state,lga.title AS lga, hostel_campuses.title AS site,
	application_number, programmes.title AS programme, hostel_students.level as LEVEL,hostel_blocks.title AS category,
	hostel_rooms.title AS room FROM state, lga, hostel_campuses, hostel_allocation, hostel_blocks,hostel_rooms,
	invoices, hostel_students,programmes, hostel_fee_payments  WHERE hostel_fee_payments.student_id=hostel_students.id AND
	hostel_fee_payments.payment_status='1' AND hostel_students.programme_id=programmes.id  AND hostel_students.state_id = state.id
	AND hostel_students.lga_id = lga.id AND hostel_students.id = hostel_allocation.student_id AND
	hostel_allocation.campus_id=hostel_campuses.id AND hostel_allocation.room_id=hostel_rooms.id
	AND hostel_allocation.block_id= hostel_blocks.id AND hostel_students.hostel_allocation='1' AND
	hostel_students.number LIKE '$search_stb' AND invoices.payment_status='1' ORDER BY number ASC";

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




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

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




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

		  <thead>


		 			  <th><!--<input type="checkbox" id="selecctall"  value="" data-toggle="tooltip" title= "Check All"> --></th>
					  <th><h4 style="text-align:center;">Payment Details</h4></th>
					  <th><h4 style="text-align:center;">Students Details</h4></th>
					  <th ><h4 style="text-align:center;">Room Details</h4></th>

		  </thead>

		  <tbody>';




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


			if($row['invoice_type'] == '5')
			{

			$output .= '<li class="list-group-item help-block" style="text-align:center;">Description  ( '.get_session_title(get_current_session($id = 1)).' Academic Session ,
						  '.get_semester_title(get_current_semester($id = 1)).' ) </li>';



			$output .= "<tr>";
			$output .="<td width='5%' height='10px'><input type='checkbox' value='".$row['invoice_id']."' name='invoice[]' id='invoice' class='checkbox1' data-toggle='tooltip' title= 'Check' /></td>" ;
			$output .= '<td width="35%" height="10px" >Invoice # <span class="badge badge-success">'. $row['invoice_id']. '</span><br/>Invoice Date: '.get_invoice_date($row['invoice_id']).'<br/>
						Due Date: '.get_invoice_due_date($row['invoice_id']).'



                      		<li class="list-group-item help-block">
                            	<span>'.get_invoice_title($row['invoice_id']).'

                                </span>
                             </li>

						</td>';

			$output .= '<td width="30%" height="10px">'.get_applicant_fullname($row['invoice_to']).'<br><b>'.get_applicant_application_number($row['invoice_to']).'</b><br/>
                             '.get_applicant_address($row['invoice_to']).'<br> <hr/>


							 <li class="list-group-item help-block" style="height:auto;">
                            	<span>'.get_invoice_desc($row['invoice_id']).'
                                </span>

                            </li>
							 <li class="list-group-item help-block">
                            	<span>Sub Total:
                                </span>
                                <span class="pull-right">N'.number_format(get_invoice_amount($row['invoice_id']) ,2).'
                                </span>
                            </li>

                            <li class="list-group-item help-block">
                            	<span>Credit:
                                </span>
                                <span class="pull-right">N'.number_format(get_invoiced_credit($row['invoice_id']) ,2).'
                                </span>
                            </li>

							</td>';


			$output .= '<td width="30%">'.get_invoice_pay_to($row['invoice_id']).' <br/> <hr/>

							<li class="list-group-item help-block" style="min-height:60px;">


                                <span class="pull-right text-success" style="font-size:35px; font-weight:bold;">Total: N'.number_format(get_invoice_total_amount($row['invoice_id']) ,2).'K
                                </span>

                            </li>

					   </td>';

			$output .= "</tr>";

			}//end of if new student
			else
			{// begin if old student


				$output .= '<li class="list-group-item help-block" style="text-align:center;">Description  ( '.get_session_title(get_current_session($id = 1)).' Academic Session ,
						  '.get_semester_title(get_current_semester($id = 1)).' ) </li>';



				$output .= "<tr>";
				$output .="<td width='5%' height='10px'><input type='checkbox' value='".$row['invoice_id']."' name='invoice[]' id='invoice' class='checkbox1' data-toggle='tooltip' title= 'Check' /></td>" ;
				$output .= '<td width="35%" height="10px" >Invoice # <span class="badge badge-success">'. $row['invoice_id']. '</span><br/>Invoice Date: '.get_invoice_date($row['invoice_id']).'<br/>
							Due Date: '.get_invoice_due_date($row['invoice_id']).'



								<li class="list-group-item help-block ">
									<span>'.get_invoice_title($row['invoice_id']).'

									</span>
								 </li>

							</td>';

				$output .= '<td width="30%" height="10px">'.get_student_fullname($row['invoice_to']).'<br><b>'.get_student_matric_number($row['invoice_to']).'</b><br/>
								 '.get_student_address($row['invoice_to']).'<br> <hr/>


								 <li class="list-group-item help-block" style="height:auto;">
									<span>'.get_invoice_desc($row['invoice_id']).'
									</span>

								</li>
								 <li class="list-group-item help-block">
									<span>Sub Total:
									</span>
									<span class="pull-right">N'.number_format(get_invoice_amount($row['invoice_id']) ,2).'
									</span>
								</li>

								<li class="list-group-item help-block">
									<span>Credit:
									</span>
									<span class="pull-right">N'.number_format(get_invoiced_credit($row['invoice_id']) ,2).'
									</span>
								</li>

								</td>';


				$output .= '<td width="30%" style="font-size:20px;font-weight:bold;">'.strtoupper($row['site']).'<br>'.strtoupper($row['category']).'<br>'.strtoupper($row['room']).' <br/> <hr/>

								<li class="list-group-item help-block" style="min-height:60px;">


									<span class="pull-right text-success" style="font-size:35px; font-weight:bold;">Total: N'.number_format(get_invoice_total_amount($row['invoice_id']) ,2).'K
									</span>

								</li>

						   </td>';

				$output .= "</tr>";



			}

		}//end of while
//

	}
	else
	{//show the msg

			$output =
				   '<div class="alert alert-danger alert-dismissable">
					<button class="close" aria-hidden="true" data-dismiss="alert" type="button">x</button>
					<img src="images/info.png" />&nbsp;&nbsp; Candidate not recognise by the system. We apologize for any inconvenience..
				   </div>';


	}



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





	return $output;

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





}//end of view search candidate

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

	return $v;
	}

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

		return $v;
		}



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

		return $v;
		}


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

		return $v;
		}



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

		return $v;
		}


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

		return $v;
		}


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

		return $v;
		}


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

		return $v;
		}



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

		return $v;
		}


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

		return $v;
		}



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

		return $v;
		}


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

		return $v;
		}

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

		return $v;
		}

//function that get total number of students thatregistered for particular course
function get_total_students_per_course($course_id,$current_session)
{
	$q = "SELECT COUNT(DISTINCT(student_id))
		 FROM students_courses
		 WHERE course_id = $course_id
		 AND session_id  = $current_session
		";// AND programme_id = '$programme_id'
	$r = mysql_query($q);

	$row = mysql_fetch_array($r, MYSQL_NUM);

	return number_format($row[0]);
}



//get courses registered  by  students in comma separated values
function get_student_registered_courses($user_id, $level, $session, $semester)
{


		  	  $q ="SELECT  GROUP_CONCAT(c.`code` ORDER BY code SEPARATOR ', ')  AS comma_separated_courses

    			   FROM `students_courses` sr, courses c

                   WHERE sr.course_id = c.id AND  sr.student_id = $user_id AND

    sr.`session_id` = $session AND sr.`semester` = $semester  AND sr.`level` = $level";


	$r = mysql_query($q);


	$output = '';

	if(mysql_num_rows($r) > 0 )
	{
		$row = mysql_fetch_array($r, MYSQL_ASSOC);

		$output = $row['comma_separated_courses'];

	}//end of if there is value
	else
	{
		$output = 'NIL';
	}


	return $output;


}//end of function that get OC for particular students





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





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


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




	  </thead>





	  <tbody>';





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


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

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

		}
	}
	else
	{//show the msg

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


	}



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





	return $output;





}//end of view roles


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


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





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


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



	  </thead>





	  <tbody>';





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


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

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

		}
	}
	else
	{//show the msg

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


	}



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



	return $output;



}//end of view trashed roles



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

	$st = $status;

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

	return $output;


}//end of function dat shows publish user_groups image


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



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



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


		  </thead>

		  <tbody>';


		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['user_group_id']."' name='user_group[]' id='user_group' class='checkbox1'/></td>" ;
			$output .= "<td>".$row['title']."</td>"; //group belong to admin
			$output .= "<td>".user_groups_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['header_menu']."</td>";
			$output .= "<td>".$row['toolbar_menu']."</td>";
			$output .= "<td>".$row['home_menu']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "</tr>";
		}
	}
	else
	{//show the msg

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


	}



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





	return $output;





}//end of view user groups



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



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



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


		  </thead>

		  <tbody>';


		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['user_group_id']."' name='user_group[]' id='user_group' class='checkbox1'/></td>" ;
			$output .= "<td>".$row['title']."</td>"; //group belong to admin or user
			$output .= "<td>".$row['description']."</td>";
			$output .= "<td>".$row['header_menu']."</td>";
			$output .= "<td>".$row['toolbar_menu']."</td>";
			$output .= "<td>".$row['home_menu']."</td>";
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "<td>".$row['date_modified']."</td>";
			$output .= "<td>".$row['added_by']."</td>";
			$output .= "<td>".$row['modified_by']."</td>";
			$output .= "<td>".$row['date_trashed']."</td>";
			$output .= '<td><a class="btn btn-success btn-sm pull-right restore_user_group" id="'.$row['user_group_id'].'" > Restore</a>
						 <span id="loading"></span></td>';
			$output .= "</tr>";
		}
	}
	else
	{//show the msg

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


	}



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





	return $output;





}//end of view trashed user groups


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

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

			}



			return $output;

} // select statsu


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

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


			echo $output;
		}
	}
	else
	{

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

			echo $output;
	}
}
//select role



//function select group and auto select if it has a value
function select_group($group)
{
	// $r = 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;
	// }
	//



			if($group == '0')
			{
				$output = '<option value="0" selected>None</option>';
				$output .= '<option value="1" > Admin</option>';
				$output .= '<option value="2" > Super Admin</option>';
			}
			else if ($group == '1')
			{
				$output = '<option value="0">None</option>';
				$output .= '<option value="1"  selected > Admin</option>';
				$output .= '<option value="2" > Super Admin</option>';
			}
			else if ($group == '2')
			{
				$output = '<option value="0">None</option>';
				$output .= '<option value="1" > Admin`</option>';
				$output .= '<option value="2"   selected > Super Admin</option>';
			}
			else
			{
				$output = '<option value="0">None</option>';
				$output .= '<option value="1" > Admin`</option>';
				$output .= '<option value="2"   selected > Super Admin</option>';
			}

			echo $output;



}




//function view events

//function view faculties
function view_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_modified, '%M %d, %Y %l:%i:%p') as date_modified, added_by, modified_by
		 FROM  faculties
		 WHERE status = 0 OR status = 1
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysqli_query(dbc(), $q);

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



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

			</tfoot>

			<tbody>';

		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&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>".$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 faculties


//function view trashed faculties
function view_trashed_faculties()
{


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

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



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


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

			</tfoot>

			<tbody>';

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


		}
	}
	else
	{//show the msg

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


	}



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





	return $output;




}//end of view trashed faculties


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

	$st = $status;

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

	return $output;


}//end of function dat shows publish image



//function view departments
function view_departments()
{


	//query the database
	$q = "SELECT id, title, description, code, 	faculty_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  departments
		 WHERE status = 0 OR status = 1
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysqli_query(dbc(), $q);

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



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

			</tfoot>

			<tbody>';

		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td><input type='checkbox' value='".$row['id']."' name='department[]' id='department' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['code']."</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 .= "</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, 	faculty_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  departments
		 WHERE status = 2
		 ORDER BY date_added DESC, date_modified DESC";
	$r = mysqli_query(dbc(), $q);

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



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


			</tfoot>

			<tbody>';

		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='department[]' id='department' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['code']."</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







//show major staus 0 - single major, 1- doube major
function show_major_status($id)
{
	if($id == 0)
	{
		$output = 'SM';
	}
	else
	{
		$output = 'DM';
	}

	return $output;

}



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

	    return $id;
	}


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

	    return $title;
	}



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

	    return $id;
	}


	/////////////////report for the student
		//function count number of bank epin generated
		function get_total_confirmed_payments_per_semester($session, $semester)
		{
			$q = "SELECT COUNT(*) FROM hostel_fee_payments WHERE  session = '$session' AND semester = '$semester' AND student_id != ''";
			$r = mysqli_query(dbc(), $q);
			$row = mysqli_fetch_array($r,MYSQLI_NUM);


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

			return $v;
			//return ;
		}

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

	    return $title;
	}




//A >= 70
//B


#///////////// get student functions
/////////////////////////////////////////

//show grade base on score of ca and exam score
//GetColour code for current project completion status
function get_student_grade_by_score($total_score)
{
	//$total_score = $ca_score + $exam_score;


	if($total_score >= "70"){
	  $grade = 'A';
	  }
	if($total_score >= "60" && $total_score <= "69"){
	  $grade = 'B';
	  }
	  if($total_score >= "50" && $total_score <= "59"){
	  $grade = 'C';
	  }
	  if($total_score >= "45" && $total_score <= "49"){
	  $grade = 'D';
	  }
	  if($total_score >= "40" && $total_score <= "44"){
	  $grade = 'E';
	  }
	  if($total_score >= "0" && $total_score <= "39"){
	  $grade = 'F';
	  }

	return $grade;
}	//end of get student grade by scores



//GetColour code for grade by passing grade
function get_grade_color($grade)
{
	if($grade == 'A'){
	  $color = "text-success";
	  }
	if($grade == 'B'){
	  $color = "text-primary";
	  }
	if($grade == 'C'){
	  $color = "text-info";
	  }
	if($grade == 'D'){
	  $color = "text-warning";
	  }
	if($grade == 'E'){
	  $color = "text-default";
	  }
	if($grade == 'F'){
	  $color = "text-danger";
	  }

	return $color;
}



//GetColour code for current get grade point score
function get_student_grade_point_score($total_score)
{
	//$total_score = $ca_score + $exam_score;


	if($total_score >= 70){
	  $gp = 5;
	  }
	if($total_score >= 60 && $total_score <= 69){
	  $gp = 4;
	  }
	  if($total_score >= 50 && $total_score <= 59){
	  $gp = 3;
	  }
	  if($total_score >= 45 && $total_score <= 49){
	  $gp = 2;
	  }
	  if($total_score >= 40 && $total_score <= 44){
	  $gp = 1;
	  }
	  if($total_score >= 0 && $total_score <= 39){
	  $gp = 0;
	  }

	return $gp;
}	//end of get student gp by scores


//function tha gen delete token for delete
function result_entry_token()
{
		for($i=0;$i<=20;$i++){
			$key .=mt_rand(0,9);
		}
		return $key.time();
}


//function dat get student full name id
function get_student_fullname($user_id)
{
	$q = "SELECT first_name, other_names FROM hostel_students WHERE id = '$user_id' ";
	$r = mysqli_query(dbc(), $q);
	$row = mysqli_fetch_assoc($r);

	return $row['first_name'].' '.$row['other_names'];


}

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

	return $row['gender'];


}


//function that flip gender
function shorten_gender($gender)
{

	//flip gender and shorten it
	if($gender == 'M')
	{
		$gender = 'M';

	}
	else if ($gender == 'F')
	{
		$gender = 'F';

	}
	else
	{
		$gender = 'NIL';
	}

	return $gender;

}



//function dat get student department id
function get_student_department_id($user_id)
{
	$q = "SELECT department_id FROM hostel_students WHERE id = '$user_id' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['department_id'];


}





//function dat get student school id
function get_student_school_id($user_id)
{
	$q = "SELECT school_id FROM hostel_students WHERE id = '$user_id' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['school_id'];


}




//function dat get student programme id
function get_student_programme_id($user_id)
{
	$q = "SELECT programme_id FROM hostel_students WHERE id = '$user_id' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['programme_id'];


}




//function dat get student level
function get_student_level($user_id)
{
	$q = "SELECT level FROM hostel_students WHERE id = '$user_id' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['level'];


}





//function dat get student matric number
function get_student_matric_no($user_id)
{
	$q = "SELECT number FROM hostel_students WHERE id = '$user_id' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['number'];


}



//start working for education course
//get total credit unit registered for  courses
function get_total_credit_unit_registered_nce($user_id,$programme_id,$course_category,$level,$session,$semester)
{

		//plaay with course category
		if($course_category == 1 OR $course_category == 2)//gst or education
		{
			$q = "SELECT SUM(course_unit)
			   FROM students_courses_nce  WHERE student_id = '$user_id' AND course_category = '$course_category' AND level = '$level' AND session_id = '$session' AND semester = '$semester' ";
			$r = mysql_query($q);
			$row2 = mysql_fetch_array($r);


			return  $row2[0];

		}
		else
		{
			//declare an array
		   $debt_comb_array =array();

			//get department comb of programme combination
		    $debt_comb = get_department_comb_using_programme_id($programme_id);


		    //$countstring = strlen($debt_comb);
			//
			//check if string is greater 1
			//
			if(strpos($debt_comb, ',') !== false )
			{

				for ($i = 0; $i < count($debt_comb);$i++)
				{
					 $debt_comb_array = explode(',', $debt_comb);


				}

			 	 $first_debt = $debt_comb_array[0];

				 $second_debt = $debt_comb_array[1];
				//pass out an array
				$qx = "SELECT SUM(course_unit)
			   FROM students_courses_nce  WHERE student_id = '$user_id' AND course_category = '$course_category' AND level = '$level' AND session_id = '$session' AND semester = '$semester' AND course_department_id = '$first_debt' ";
				$rx = mysql_query($qx);
				$rowx = mysql_fetch_array($rx);


				$qy = "SELECT SUM(course_unit)
			   FROM students_courses_nce  WHERE student_id = '$user_id' AND course_category = '$course_category' AND level = '$level' AND session_id = '$session' AND semester = '$semester' AND course_department_id = '$second_debt'";
				$ry = mysql_query($qy);
				$rowy = mysql_fetch_array($ry);


			    $return_value = $rowx[0].','.$rowy[0];
				return $return_value;


			}
			else
			{
				$qz = "SELECT SUM(course_unit)
			   FROM students_courses_nce  WHERE student_id = '$user_id' AND course_category = '$course_category' AND level = '$level' AND session_id = '$session' AND semester = '$semester' AND course_department_id = '$debt_comb' ";
				$rz = mysql_query($qz);
				$rowz = mysql_fetch_array($rz);

				return $rowz[0];

			}
			//




		}//end of if category is 0




}//end of if function is


//get total credit unit earned from courses
function get_total_credit_unit_earned_nce($user_id,$programme_id,$course_category,$level,$session,$semester)
{

		//plaay with course category
		if($course_category == 1 OR $course_category == 2)//gst or education
		{
			$q = "SELECT SUM(course_unit)
			   FROM students_courses_nce  WHERE student_id = '$user_id' AND course_category = '$course_category' AND level = '$level' AND session_id = '$session' AND semester = '$semester' AND total_score > 39";
			$r = mysql_query($q);
			$row2 = mysql_fetch_array($r);


			return  $row2[0];

		}
		else
		{
			//declare an array
		   $debt_comb_array =array();

			//get department comb of programme combination
		    $debt_comb = get_department_comb_using_programme_id($programme_id);


		    //$countstring = strlen($debt_comb);
			//
			//check if string is greater 1
			//
			if(strpos($debt_comb, ',') !== false )
			{

				for ($i = 0; $i < count($debt_comb);$i++)
				{
					 $debt_comb_array = explode(',', $debt_comb);


				}

			 	 $first_debt = $debt_comb_array[0].'<br/>';

				 $second_debt = $debt_comb_array[1];
				//pass out an array
				$qx = "SELECT SUM(course_unit)
			   FROM students_courses_nce  WHERE student_id = '$user_id' AND course_category = '$course_category' AND level = '$level' AND session_id = '$session' AND semester = '$semester' AND course_department_id = '$first_debt'  AND total_score > 39 ";
				$rx = mysql_query($qx);
				$rowx = mysql_fetch_array($rx);


				$qy = "SELECT SUM(course_unit)
			   FROM students_courses_nce  WHERE student_id = '$user_id' AND course_category = '$course_category' AND level = '$level' AND session_id = '$session' AND semester = '$semester' AND course_department_id = '$second_debt'
			    AND total_score > 39";
				$ry = mysql_query($qy);
				$rowy = mysql_fetch_array($ry);


			    $return_value = $rowx[0].','.$rowy[0];
				return $return_value;


			}
			else
			{
				$qz = "SELECT SUM(course_unit)
			   FROM students_courses_nce  WHERE student_id = '$user_id' AND course_category = '$course_category' AND level = '$level' AND session_id = '$session' AND semester = '$semester' AND course_department_id = '$debt_comb'
			    AND total_score > 39";
				$rz = mysql_query($qz);
				$rowz = mysql_fetch_array($rz);

				return $rowz[0];

			}
			//




		}//end of if category is 0




}

//get total grade point  earned from courses
function get_total_grade_point_earned_nce($user_id,$programme_id,$course_category,$level,$session,$semester)
{

		//plaay with course category
		if($course_category == 1 OR $course_category == 2)//gst or education
		{
			$q = "SELECT course_unit,total_score

			     FROM students_courses_nce  WHERE student_id = '$user_id' AND course_category = '$course_category' AND level = '$level' AND session_id = '$session' AND semester = '$semester'";
			$r = mysql_query($q);
			//$row2 = mysql_fetch_array($r);
			//
			//initialise
			//$total_grade_point = 0;

			while ($row2 =mysql_fetch_array($r,MYSQL_ASSOC))
			{
				 $total_grade_point = get_student_grade_point_score($row2['total_score']) * $row2['course_unit'];

				 $total_grade_point2 += $total_grade_point;

			}


			return  $total_grade_point2;

		}
		else
		{
			//declare an array
		   $debt_comb_array =array();

			//get department comb of programme combination
		    $debt_comb = get_department_comb_using_programme_id($programme_id);


		    //$countstring = strlen($debt_comb);
			//
			//check if string is greater 1
			//
			if(strpos($debt_comb, ',') !== false )
			{

				for ($i = 0; $i < count($debt_comb);$i++)
				{
					 $debt_comb_array = explode(',', $debt_comb);


				}

			 	 $first_debt = $debt_comb_array[0].'<br/>';

				 $second_debt = $debt_comb_array[1];
				//pass out an array
				$qx = "SELECT course_unit,total_score

			     FROM students_courses_nce  WHERE student_id = '$user_id' AND course_category = '$course_category' AND level = '$level' AND session_id = '$session' AND semester = '$semester' AND course_department_id = '$first_debt'";
				$rx = mysql_query($qx);
				//$rowx = mysql_fetch_array($rx);


				while ($rowx =mysql_fetch_array($rx,MYSQL_ASSOC))
				{
					 $total_grade_point = get_student_grade_point_score($rowx['total_score']) * $rowx['course_unit'];

					 $total_grade_point2x += $total_grade_point;

				}


			//return  $total_grade_point2x;


				$qy = "SELECT course_unit,total_score

			     FROM students_courses_nce  WHERE student_id = '$user_id' AND course_category = '$course_category' AND level = '$level' AND session_id = '$session' AND semester = '$semester' AND course_department_id = '$second_debt'";
				$ry = mysql_query($qy);
				//$rowy = mysql_fetch_array($ry);
				//
				while ($rowy =mysql_fetch_array($ry,MYSQL_ASSOC))
				{
					 $total_grade_point = get_student_grade_point_score($rowy['total_score']) * $rowy['course_unit'];

					 $total_grade_point2y += $total_grade_point;

				}


			//return  $total_grade_point2y;



			    $return_value = $total_grade_point2x.','.$total_grade_point2y;

				return $return_value;


			}
			else
			{
				$qz = "SELECT course_unit,total_score

			     FROM students_courses_nce  WHERE student_id = '$user_id' AND course_category = '$course_category' AND level = '$level' AND session_id = '$session' AND semester = '$semester' AND course_department_id = '$debt_comb'
			    ";
				$rz = mysql_query($qz);
				//$rowz = mysql_fetch_array($rz);
				//
				while ($rowz =mysql_fetch_array($rz,MYSQL_ASSOC))
				{
					 $total_grade_point = get_student_grade_point_score($rowz['total_score']) * $rowz['course_unit'];

					 $total_grade_point2z += $total_grade_point;

				}


				return $total_grade_point2z;

			}
			//




		}//end of if category is 0




}//function to get tgp


//function dat get student id by matric number
function get_student_id_by_matric_no($id)
{
	$q = "SELECT id FROM hostel_students WHERE number = '$id' ";
	$r = mysql_query($q);
	$row = mysql_fetch_assoc($r);

	return $row['id'];


}


//function get student course title using  md5
function  get_student_course_code($id)
{
	$result = mysql_query("SELECT code FROM courses WHERE md5(id) = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['code'];

	return $v;

}









//function view trashed courses
function view_trashed_courses()
{


	//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  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"  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='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>".$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_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 view subjects
function view_subjects()
{

	//comment incase


	//query the database
	$q = "SELECT id, title, description, course_id, department_id, code, unit, level, semester, 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  subjects
		 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>Department</th>
						<th>Course</th>
						<th>Unit</th>
						<th>Level</th>
						<th>Semester</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"  data-toggle = "tooltip" title = "Check All" value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>Status</th>
						<th>Department</th>
						<th>Course</th>
						<th>Unit</th>
						<th>Level</th>
						<th>Semester</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='subject[]' id='subject' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['title']."</a></td>";
			$output .= "<td>".$row['code']."</td>";
			$output .= "<td>".subject_publish_status_image($row['status'])."</td>";
			$output .= "<td>".get_department_title($row['department_id'])."</td>";
			$output .= "<td>".get_course_title($row['course_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['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 subjects

//function view trashed subjects
function view_trashed_subjects()
{

	//comment incase


	//query the database
	$q = "SELECT id, title, description, course_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  subjects
		  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>Course</th>
						<th>Unit</th>
						<th>Level</th>
						<th>Semester</th>
						<th>Description</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"  data-toggle = "tooltip" title = "Check All" value=""> </th>
						<th>Title</th>
						<th>Code</th>
						<th>Department</th>
						<th>Course</th>
						<th>Unit</th>
						<th>Level</th>
						<th>Semester</th>
						<th>Description</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='subject[]' id='subject' 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_course_title($row['course_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_subject" 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 subjects



//function that shows subject publish status image
function subject_publish_status_image($status)
{

	$st = $status;

	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_subjects" id="publish_sj"
				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_subjects" id="unpublish_sj"
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}

	return $output;


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



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

  }
}


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



//fucntion that returns searched candidates
function view_search_candidate($search_c)
{





	//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=number">ID</a></th>
				  <!--<th class="header" ><a href="gateway.php?act=view_users&sort=image">Photo</a></th>-->

				  <th class="header" ><a href="gateway.php?act=view_users&sort=date_added">Last Visit</a></th>

	  </thead>

	  <tbody>';






	//query the database
	$q = "SELECT u.user_id AS user_id, u.other_names as name, u.phone_number, u.transaction_id, u.group_id,
		  DATE_FORMAT(u.date_added, '%b %e, %Y  %l:%i:%p') as date_added,  u.email, u.image


		 FROM users u

		 WHERE u.transaction_id = '$search_c'";

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

	if($r )
	{//show table

		$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><h3 class='badge badge-info'>".$row['transaction_id']."</h3></td>";
			//$output .= '<td><img class="img-responsive img-circle" src="uploads/pictures/'.$row['image'].'"  style="width:150px; height:150px;" />
					//	'.$row['image'].'</td>';
			$output .= "<td>".$row['date_added']."</td>";
			$output .= "</tr>";

			echo $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 table view
	echo
	'</tbody>
    </table>';







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


	}



}//end of function that shows candidate image


//generate serial number fro logging in
function generate_serial_number()
{
	$result = mysql_query("SELECT * FROM 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 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





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



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

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

			}


			echo $output;
		}
	}
	else
	{

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

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


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

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

			}


			echo $output;
		}
	}
	else
	{

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

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














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

	return $title;
}

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

	return $title;
}



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

	return $title;
}


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

	return $title;
}


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

	return $course_category;
}


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

	return $title;

}


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

	return $title;

}

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

	return $code;

}




//programme function
//get progrmmae title
function  get_programme_title($id)
{
		$result = mysql_query("SELECT title FROM programmes WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$title = $row['title'];

	return $title;

}


//get progrmmae title
function  get_actual_programme_title($id)
{
		$result = mysql_query("SELECT title FROM parent_programmes WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$title = $row['title'];

	return $title;

}



//programme function
//get progrmmae code
function  get_programme_code($id)
{
		$result = mysql_query("SELECT code FROM programmes WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['code'];

	return $v;

}


//get progrmmae code
function  get_actual_programme_code($id)
{
		$result = mysql_query("SELECT code FROM parent_programmes WHERE id = '$id'");
		$row = mysql_fetch_assoc($result);
		$v = $row['code'];

	return $v;

}


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

	return $title;
}

//get school id using programme _id
function get_school_id_using_programme_id($id)
{
	$query = "SELECT  school_id   FROM programmes WHERE id ='$id'";
	$result = mysql_query($query);
	$row = mysql_fetch_assoc($result);

	$v =  $row['school_id'];

	return $v;

}


//get programme level using programme id
function get_level_using_programme_id($id)
{
	$query = "SELECT  level   FROM programmes WHERE id ='$id'";
	$result = mysql_query($query);
	$row = mysql_fetch_assoc($result);

	$v =  $row['level'];

	return $v;

}




//function that gets course code base on course id
//function  get_course_code($id)
//{
//	$result = mysql_query("SELECT * FROM courses WHERE id = '$id'");
//		$row = mysql_fetch_assoc($result);
//		$code = $row['course_code'];
//
//	return $code;
//
//}


//function get schools list fro result computation
function get_schools_list_cr()
{

	$sn = 0; // serial no
	//query the database
	$q = "SELECT id, title, description, status
		 FROM  schools
		 WHERE status = 0
		 ORDER BY date_added DESC, date_modified DESC"; //AND id = '$department'
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>S/NO. </th>
						<th>SCHOOLS / GENERAL STUDIES / EDUCATION </th>
						<th></th>


			</thead>
			<tfoot>
						<th>S/NO. </th>
						<th>SCHOOLS / GENERAL STUDIES / EDUCATION </th>
						<th></th>




			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$sn = $sn + 1;

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

			$output .= "<td><a href='gateway.php?act=view_programmes_list_cr&xid=".md5(8)."&sid=".$row['id']."' class='btn btn-success btn-sm'  >  NCE </a>

			&nbsp &nbsp

			    <a href='gateway.php?act=view_programmes_list_prence_cr&xid=".md5(8)."&sid=".$row['id']."' class='btn btn-default btn-sm'  > PRE NCE </a>

			</td>";
// <a href='gateway.php?act=view_programmes_list&xid=".md5(8)."&sid=".$row['id']."' class='btn btn-success btn-sm'  > VIEW NCE </a>
			//<a href='gateway.php?act=view_programmes_list&xid=".md5(8)."&sid=".$row['id']."' class='btn btn-success btn-sm'  > NCE </a>
			//$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>".get_school_title($row['school_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 get school lists for compute result

//function get departments list
function get_departments_list_ex()
{

	$sn = 0; // serial no
	//query the database
	$q = "SELECT id, title, description, status
		 FROM  departments
		 WHERE status = 0
		 ORDER BY date_added DESC, date_modified DESC"; //AND id = '$department'
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>S/NO. </th>
						<th>DEPARTMENTS / GENERAL STUDIES  </th>
						<th></th>


			</thead>
			<tfoot>
						<th>S/NO. </th>
						<th>DEPARTMENTS / GENERAL STUDIES  </th>
						<th></th>




			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$sn = $sn + 1;

			$output .= "<tr>";
			$output .="<td>".$sn."</td>" ;
			$output .= "<td> <a href='gateway.php?act=view_courses&xid=".md5(8)."&sid=".$row['id']."'   >".$row['title']."</a></td>";

			$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 get school lists




//function get departments list
function get_departments_list()
{

	$sn = 0; // serial no
	//query the database
	$q = "SELECT id, title, description, status, school_id
		 FROM  departments
		 WHERE status = '0'
		 ORDER BY date_added DESC, date_modified DESC"; //AND id = '$department'
	$r = mysql_query($q);

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



		  $output =
		  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
			<thead>
						<th>S/No. </th>
						<th>Title</th>
						<!--<th>School</th>-->


			</thead>
			<tfoot>
						<th>S/No. </th>
						<th>Title</th>
						<!--<th>School</th>-->




			</tfoot>

			<tbody>';

		while($row = mysql_fetch_array($r, MYSQL_ASSOC))
		{
			$sn = $sn + 1;

			$output .= "<tr>";
			$output .="<td>".$sn."</td>" ;
			$output .= "<td> <a href='gateway.php?act=view_programmes_list&xid=".md5(8)."&did=".$row['id']."'>".$row['title']."</a></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>".get_school_title($row['school_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 get department lists


//function get programme list for computing result
function get_programmes_list_cr($sid)
{  //now switch the programme list based on core / general studies / education



	// if($sid == 8)//if general studies
	// {

	// 	//fetch by all schools base on general studies
	// 	$q = "SELECT id, title, description, status, school_id,department_id
	// 		 FROM  programmes
	// 		 WHERE  status = 0
	// 		 AND type_id = 2
	// 		 AND mode = 1

	// 		 ORDER BY title ASC";


	// }
	// else if($sid == 9)//if education
	// {

	// 	//fetch by all schools base on education
	// 	$q = "SELECT id, title, description, status, school_id,department_id
	// 		 FROM  programmes
	// 		 WHERE  status = 0
	// 		 AND type_id = 2
	// 		 AND mode = 1

	// 		 ORDER BY title ASC";

	// }
	// else
	// {

		//query the database
		$q = "SELECT id, title, description, status, school_id,department_id
			 FROM  programmes
			 WHERE school_id = '$sid'
			 AND status = 0
			 AND type_id = 2
			 AND mode = 1

			 ORDER BY date_added DESC, date_modified DESC";



	// }


		$r = mysql_query($q); //result of the sql query




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


			$sn = 0; // serial no


			  $output =
			  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
				<thead>
							<th>S/No. </th>
							<th>Programme Combination</th>
							<th>Department</th>
							<th>School</th>



				</thead>
				<tfoot>

							<th>S/No. </th>
							<th>Programme Combination</th>
							<th>Department</th>
							<th>School</th>





				</tfoot>

				<tbody>';

			while($row = mysql_fetch_array($r, MYSQL_ASSOC))
			{
				//here sid passed is collected from the parameters because we want to track virtual schools


				$sn = $sn + 1;

				$output .= "<tr>";
				$output .="<td>".$sn."</td>" ;
				$output .= "<td> <a href='gateway.php?act=view_courses_cr&xid=".md5(8)."&sid=".$sid."&pid=".$row['id']."'>".$row['title']."</a></td>";
				$output .= "<td>".get_department_title($row['department_id'])."</td>";

			    $output .= "<td>".get_school_title($row['school_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 get programme lists for computing results



//check if inserted already computation inserted already
function check_if_student_computatation_exist($student,$token, $session, $semester, $level)
{
	//check if invoice id generated exist
	$q1 = "SELECT student_id
		   FROM students_results_nce
		   WHERE student_id = '$student' AND delete_token = '$token'
		   AND session_id = '$session' AND semester = '$semester' AND level = '$level'";

	$r1 = mysql_query($q1);

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


}//end of if the computation is added already



//function that get student list in of computed results per semester
function view_students_list_form_b2($ses,$sem,$sid,$pid,$level)
{
	//show list of students who are still in school
	//dont show the dropped course bu the students

	$q = "SELECT `id`, `student_id`, `programme_id`, `session_id`, `semester`, `level`, `delete_token`, `result_date_added`, `status`, `date_trashed`, `date_added`, `date_modified`, `added_by`, `modified_by`, `edu_ptcur`, `edu_tcur`, `edu_ptcue`, `edu_tcue`, `edu_ptgp`, `edu_tgp`, `edu_ptgpe`, `edu_tgpe`, `edu_gpa`, `edu_cgpa`, `gst_ptcur`, `gst_tcur`, `gst_ptcue`, `gst_tcue`, `gst_ptgp`, `gst_tgp`, `gst_ptgpe`, `gst_tgpe`, `gst_gpa`, `gst_cgpa`, `core1_ptcur`, `core1_tcur`, `core1_ptcue`, `core1_tcue`, `core1_ptgp`, `core1_tgp`, `core1_ptgpe`, `core1_tgpe`, `core1_gpa`, `core1_cgpa`, `core2_ptcur`, `core2_tcur`, `core2_ptcue`, `core2_tcue`, `core2_ptgp`, `core2_tgp`, `core2_ptgpe`, `core2_tgpe`, `core2_gpa`, `core2_cgpa`




		FROM `students_results_nce`

		WHERE session_id = '$ses' AND semester = '$sem' AND programme_id = '$pid' AND level = '$level'";





	$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>S/NO</th>

				  		<th>MATRIC NO.</th>

				  		<th>NAMES</th>

				  		<th>TCUR</th>
				  		<th>TCUE</th>
				  		<th>TGP</th>
				  		<th>CGPA</th>

						<th>TCUR</th>
				  		<th>TCUE</th>
				  		<th>TGP</th>
				  		<th>CGPA</th>

				  		<th>TCUR</th>
				  		<th>TCUE</th>
				  		<th>TGP</th>
				  		<th>CGPA</th>

				  		<th>TCUR</th>
				  		<th>TCUE</th>
				  		<th>TGP</th>
				  		<th>CGPA</th>

						<th> </th>

						<th>TCUR</th>
				  		<th>TCUE</th>
				  		<th>TGP</th>
				  		<th>CGPA</th>

				  		<th>REMARK</th>

				</thead>



				<tr>

				  		<td></td>

				  		<td></td>

				  		<td></td>

				  		<td align=center colspan = 4> EDUCATION </td>


				  		<td align=center colspan = 4> GENERAL STUDIES</td>


				  		<td align=center colspan = 4>CORE 1</td>


				  		<td align=center colspan = 4>CORE 2</td>

						<td> TP </td>

						<td align=center colspan = 4>CUMMULATIVE</td>


				  		<td>REMARK</td>


				</tr>



				<tfoot>

				</tfoot>

				<tbody>';




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

			$output .= "<td>".$row['number']."</td>";
			$output .= "<td>".$row['student_id']."</td>";
			$output .= "<td>".strtoupper($row['name'])."</td>"; //nam eof the user
			$output .= "<td>".$row['edu_tcur']."</td>";
			$output .= "<td>".$row['edu_tcue']."</td>";
			$output .= "<td>".$row['edu_tgpe']."</td>";
			$output .= "<td>".$row['edu_cgpa']."</td>";

			$output .= "<td>".$row['gst_tcur']."</td>";
			$output .= "<td>".$row['gst_tcue']."</td>";
			$output .= "<td>".$row['gst_tgpe']."</td>";
			$output .= "<td>".$row['gst_cgpa']."</td>";


			$output .= "<td>".$row['core1_tcur']."</td>";
			$output .= "<td>".$row['core1_tcue']."</td>";
			$output .= "<td>".$row['core1_tgpe']."</td>";
			$output .= "<td>".$row['core1_cgpa']."</td>";


			$output .= "<td>".$row['core2_tcur']."</td>";
			$output .= "<td>".$row['core2_tcue']."</td>";
			$output .= "<td>".$row['core2_tgpe']."</td>";
			$output .= "<td>".$row['core2_cgpa']."</td>";

			//tp out put
			$output .= "<td>".$row['core1_tcur']."</td>";


			$output .= "<td>".$row['cum_tcur']."</td>";
			$output .= "<td>".$row['cum_tcue']."</td>";
			$output .= "<td>".$row['cum_tgpe']."</td>";
			$output .= "<td>".$row['cum_cgpa']."</td>";





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

			$output .= "</tr>";



		}
	}
	else
	{//show the msg

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


	}



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





	return $output;




}//end of view students list of computed result


// <thead>


// 				  		<th></th>

// 				  		<th></th>

// 				  		<th></th>

// 				  		<th> EDUCATION </th>
// 				  		<th></th>
// 				  		<th></th>
// 				  		<th></th>

// 				  		<th> GENERAL STUDIES</th>
// 				  		<th></th>
// 				  		<th></th>
// 				  		<th></th>

// 				  		<th>CORE 1</th>
// 				  		<th></th>
// 				  		<th></th>
// 				  		<th></th>

// 				  		<th>CORE 2</th>
// 				  		<th></th>
// 				  		<th></th>
// 				  		<th></th>

// 						<th> TP </th>

// 						<th>CUMMULATIVE</th>
// 				  		<th></th>
// 				  		<th></th>
// 				  		<th></th>

// 				  		<th></th>


// 				</thead>

// 				<tr>

// 				  		<td>S/NO</td>

// 				  		<td>MATRIC NO.</td>

// 				  		<td>NAMES</td>

// 				  		<td>TCUR</td>
// 				  		<td>TCUE</td>
// 				  		<td>TGP</td>
// 				  		<td>CGPA</td>

// 						<td>TCUR</td>
// 				  		<td>TCUE</td>
// 				  		<td>TGP</td>
// 				  		<td>CGPA</td>

// 				  		<td>TCUR</td>
// 				  		<td>TCUE</td>
// 				  		<td>TGP</td>
// 				  		<td>CGPA</td>

// 				  		<td>TCUR</td>
// 				  		<td>TCUE</td>
// 				  		<td>TGP</td>
// 				  		<td>CGPA</td>

// 						<td> </td>

// 						<td>TCUR</td>
// 				  		<td>TCUE</td>
// 				  		<td>TGP</td>
// 				  		<td>CGPA</td>

// 				  		<td>REMARK</td>

// 				</tr/>





//function get programme list
function get_programmes_list_ex($sid)
{  //now switch the programme list based on core / general studies / education



	// if($sid == 8)//if general studies
	// {

	// 	//fetch by all schools base on general studies
	// 	$q = "SELECT id, title, description, status, department_id
	// 		 FROM  programmes
	// 		 WHERE  status = 0

	// 		 ORDER BY title ASC";


	// }
	// else if($sid == 9)//if education
	// {

	// 	//fetch by all schools base on education
	// 	$q = "SELECT id, title, description, status, department_id
	// 		 FROM  programmes
	// 		 WHERE  status = 0

	// 		 ORDER BY title ASC";

	// }
	// else
	// {

		//query the database
		$q = "SELECT id, title, description, status, department_id
			 FROM  programmes
			 WHERE department_id = '$sid'
			 AND status = 0


			 ORDER BY date_added DESC, date_modified DESC";



	// }


		$r = mysql_query($q); //result of the sql query




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


			$sn = 0; // serial no


			  $output =
			  '<table id="example" class="user display table-bordered table-hover table-striped" cellspacing="0" width="100%" style="font-size:12px;">
				<thead>
							<th>S/No. </th>
							<th>Programme </th>
							<th>Department</th>
							<!--<th>School</th>-->



				</thead>
				<tfoot>

							<th>S/No. </th>
							<th>Programme </th>
							<th>Department</th>
							<!--<th>School</th>-->





				</tfoot>

				<tbody>';

			while($row = mysql_fetch_array($r, MYSQL_ASSOC))
			{
				//here sid passed is collected from the parameters because we want to track virtual schools


				$sn = $sn + 1;

				$output .= "<tr>";
				$output .="<td>".$sn."</td>" ;
				$output .= "<td> <a href='gateway.php?act=view_courses&xid=".md5(8)."&sid=".$sid."&pid=".$row['id']."'>".$row['title']."</a></td>";
				$output .= "<td>".get_department_title($row['department_id'])."</td>";

			    //$output .= "<td>".get_school_title($row['school_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 get programme lists




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

function staff_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 staff publish status image
function staff_publish_status_image($status)
{

	$st = $status;

	if($st == 0)
	{
		$output =  '<input type="submit" name="act" class="publish-icon-small" value="unpublish_staffs" id="publish_s"
				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_staffs" id="unpublish_s"
					data-toggle="tooltip" data-placement="right" title="Unpublished: Click to publish item">';
	}

	return $output;


}//end of function dat shows publish staffs image




//function view staff
//function that get staffs informatn
function view_staffs()
{

	//$user_id = get_user_id();

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


		 FROM staff
		 WHERE status = 0 OR status = 1



		 ORDER BY date_added DESC";
	$r = mysqli_query(dbc(), $q);



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


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

	$output ='<table id="example" class="staff 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>C-No.</th>
						<th>Status </th>
						<th>Username</th>
						<th>Active</th>
						<th>Ph No.</th>
						<th>Email</th>
						<th>Department</th>
						<th>Last Login Ip</th>
						<th>Last Visit Date</th>
						<th>Registration Date</th>

				</thead>



				<tfoot>
				   		<th > </th>
			  			<th>Name</th>
			  			<th>C-No.</th>
						<th> Status </th>
						<th>Username</th>
						<th>Active</th>
						<th>Ph No.</th>
						<th>Email</th>

						<th>Department</th>
						<th>Last Login Ip</th>
						<th>Last Visit Date</th>
						<th>Registration Date</th>
				</tfoot>

				<tbody>';



		while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
		{
			$output .= "<tr>";
			$output .="<td>&nbsp;&nbsp;&nbsp;<input type='checkbox' value='".$row['id']."' name='staff[]' id='staff' class='checkbox1'/></td>" ;
			$output .= "<td> <a href=''>".$row['name']."</a></td>"; //nam eof the staff
			$output .= "<td>".$row['number']."</td>";
			$output .= "<td>".staff_publish_status_image($row['status'])."</td>";
			$output .= "<td>".$row['username']."</td>";
			$output .= "<td>". staff_status_img($row['user_status'])."</td>";
			$output .= "<td>".$row['phone_number']."</td>";
			$output .= "<td>".$row['email']."</td>";
			$output .= "<td>".get_department_title($row['department_id'])."</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 staff




//function that get trashed  staff informatn
function view_trashed_staffs()
{

	//query the database
	$q = "SELECT id, CONCAT_WS(' ', first_name, other_names) as name, phone_number, number,
		  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



		 FROM staff
		 WHERE status = 2

		 ORDER BY date_added DESC";
	$r = mysqli_query(dbc(), $q);






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

	$output ='<table id="example" class="staff 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>C-No.</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>C-No.</th>
						<th>Email</th>
						<th>Registration Date</th>
						<th>Last Modified</th>
						<th>Deleted </th>
						<th></th>
				</tfoot>

				<tbody>';



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



?>
