<?php
	session_start();
	
	$HOST = '184.168.194.75';
	$UID = 'Mars';
	$PWD = 'ExineAdmin1#27';
	$DB = 'StormyTest';
	
	$sUser = $_POST['User'];
	$sPass = $_POST['Pass'];
	
	$connectionInfo = array("Database"=>$DB, "UID"=>$UID, "PWD"=>$PWD);
	$conn = sqlsrv_connect($HOST, $connectionInfo);
	
	if ($conn)
	{
		$loginQuery = "SELECT * FROM tUser WHERE sUserID='$sUser' AND sUserPW='$sPass'";
		$doLogin = sqlsrv_query($conn, $loginQuery, array(), array( "Scrollable" => 'static' ));
		
		$userCount = sqlsrv_num_rows($doLogin);
		
		if ($doLogin)
		{
			if ($userCount > 1)
			{
				echo 'There have been duplicate accounts found. Please contact an administrator.';	
			}
			
			if ($userCount == 1) // we're logged in, an account was found
			{
				$userRow = sqlsrv_fetch_array($doLogin);
				$_SESSION['userID'] = $userRow['nUserNo'];
				$_SESSION['logged_in'] = true;
				echo 'OK';
			}
			
			if ($userCount < 1)
			{
				echo 'Wrong credentials. Sorry';
			}
		}
		else {
			echo 'Sorry, there was an error. Please try again later.';	
		}
	}
	else {
		echo 'Could not connect';	
	}
?>