<?php 

##################################################################################
## This is the file that handles all gateway authentications in the admin 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
##
#########################################################




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





//clear the buffer start
ob_start();




$time_out = time() + 216000;



//Connect to database from here
//require_once('../../../prence/includes/configuration.php');
require_once('../../../nce/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=md5($_POST['password']);

//now validating the username and password
$q = "SELECT * FROM users 
						  WHERE (username = '$username' AND password = '$password') 
						  AND user_status = 1
						  AND role_id = 1";
$r = mysqli_query($dbc, $q);

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

	
	
	//pass the values to coookies and sessions
	$_SESSION = mysqli_fetch_array($r, MYSQLI_ASSOC);
	$user_id =$_SESSION['user_id'];
	
	
	//pass some to cookies 
	setcookie('verify-admin', md5($username), $time_out, '/');
	
	//collect user id
	setcookie("lis", $user_id ,  $time_out, '/');
	
	
	
	//update the db info
	$qry = "UPDATE users SET online_status = 1, last_login = NOW(), last_login_ip = '$user_ip'
		  WHERE username = '$username'";
		  
	$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
    
    //return yes
	echo "yes";
	
	
}
else
{

	//return no
	echo "no";
}

?>