<?php
	ob_start();
	session_start();

	//Include Files

	include("../class/admin.php");
	include("../class/dbConnection.php");

	//Declaring Variables
	$loginId;
	$password;
	$adminId;
	$dbPassword;
	$message;

	//Retrieving Form Fields

	$loginId = $_REQUEST["userid"];
	$password =$_REQUEST["password"];

	//Creating 'dbConnection' Object

	$dbObj = new dbConnection();
	$con = $dbObj->getConnection();

	//echo $con . "<br/>";

	if($con)
	{
		//echo "MySQL Server Connected<br/>";

		$dbResult = $dbObj->selectDatabase();

		if($dbResult)
		{
			//echo "Database Selected<br/>";

			//Creating 'admin' Object	

			$adminObj = new admin();

			$message = $adminObj->validateLogin($loginId,$password,$con);

			if($message == "Correct")
			{

				$adminId = $adminObj->getAdminId($loginId,$con);

				//Creating Session Variable

				$_SESSION["adminId"] = $adminId;

				header('Location:home.php');

			}
			else
			{
				header('Location:index.php?message='.$message);
			}

		}
		else
		{
			echo mysql_errno() . " : " . mysql_error();
		}

	}
	else
	{
		echo mysql_errno() . " : " . mysql_error();
	}

?>