<?php

##################################################################################
## This is the file that handles all gateway authentications in to student portal platform
## file name:index.php :a stand for admin
## author: Aslapai asuleimanlapai@yahoo.com
## date: 14/5/2015
## date_modified:
## do not change anything on this page unless u are told to do so
##
#########################################################





//clear the buffer start
ob_start();

$_SESSION = array(); // delete all session variables

unset($_COOKIE['vstoox']); //destroy the cookie too
unset($_COOKIE['lstoox']); //destroy these cookeis


//start session
session_start();
//  This notice MUST stay intact for legal use





$time_out = time() + 216000;



//Connect to database from here
require_once('../../../includes/configuration_old.php');


// Get the user current ip
$user_ip = getenv('REMOTE_ADDR');



//get the posted values
$username=htmlspecialchars($_POST['username'],ENT_QUOTES);
$password= $_POST['password'];
$hashed_password=md5($password);

//now validating the username and password
$q = "SELECT * FROM students_nce
	   WHERE (number = '$username' AND password = '$hashed_password')"; //AND programme_id != 80  AND level = 'III'




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

if(@mysqli_num_rows($r) == 1)
{




	//return yes
	echo "yes";


	//pass the values to coookies and sessions
	$_SESSION = mysqli_fetch_array($r, MYSQLI_ASSOC);
	$user_id =$_SESSION['id'];

	//pass some to cookies
	setcookie('vstoox', md5($username), $time_out, '/');

	//collect user id
	setcookie("lstoox", $user_id ,  $time_out, '/');



	//update the db info
	$qry = "UPDATE students_nce SET online_status = 1, last_login = NOW(), last_login_ip = '$user_ip'
		  WHERE id = '$user_id'";

	$rst = mysqli_query($dbc, $qry);






	//So need to clear password protector variables
	//unset($_POST['username']);
	//unset($_POST['password']);
	//unset($_POST['act']);

	//$url = 'gateway.php';
	//header("Location: gateway.php");
	//head the guy from the js page



}
else
{

	//return no
	echo "no";
}

?>
