<?php 
$form_name = "";
$table_name = "custom_participant_registration";
$primary_key = "reg_id";

$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : "";

include_once("includes/sha256.php");
include_once("includes/config.php");
include_once("includes/common_functions.php");

$common = new General_Functions();
$css_class = "x-gray";
// $common->SetCssClass($css_class);

$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : "";
$act_type = isset($_REQUEST['act_type']) ? $_REQUEST['act_type'] : "";
$cancel_link = $_SERVER['SCRIPT_NAME'].'?page='.$_REQUEST['page'];
$action = $_SERVER['SCRIPT_NAME']."?page=login&mode=submit";
?>
<style>
	.content_bg
	{
		border-radius: 0px;
		background-color: #ffffff;
	}
	#frm_display
	{
		background: url("includes/images/loginbackground.jpg") no-repeat scroll 240px 40px transparent; 
		height:400px;
		text-align:center;
	}
	.form
	{
		margin-left: 38%;
		/*margin-top: 55px;
		position: inherit;*/
		padding-top: 95px;
		text-align: right;
		width: 35%;
	}
</style>
<?php
switch($mode)
{
	case "submit":
		$qry = "SELECT * FROM lime_users WHERE users_name = '".$_REQUEST['username']."' AND password = '".md5($_REQUEST['password'])."'";
		
		$qry = "SELECT * FROM lime_users WHERE users_name = '".$_REQUEST['username']."' AND status = 'Y'";
		$common->sql->query($qry, SQL_ALL, SQL_ASSOC);
		$rec = $common->sql->record;
		$msg = "";
		
		if(count($rec) != 0)
		{
			// if(SHA256::hashing($_REQUEST['password']) == $rec[0]['password'])

			if(md5($_REQUEST['password']) == $rec[0]['password'])
			{
				$_SESSION['TER']["user"] = $rec[0]['usr_id'];
				$_SESSION['TER']["user_name"] = $rec[0]['full_name'];
				$_SESSION['TER']['admin'] = true;
				// echo $_SERVER['SCRIPT_NAME'];
				// header("location:".$_SERVER['SCRIPT_NAME']);
				// $link = $_SERVER['SCRIPT_NAME'].'?page=';
				$link = $_SERVER['SCRIPT_NAME'];
				header("location:".$link);
				//header('location:'.SITE_URL);
			}
			else
			{
				echo '<div class="content_bg">';
					$msg = "Invalid Password";
					include("add.php");
				echo '</div>';
			}
		}
		else
		{
			echo '<div class="content_bg">';
				$msg = "Invalid Username";
				include("add.php");
			echo '</div>';
		}
	break;
	
	default:
		echo '<div class="content_bg">';
			include("add.php");
		echo '</div>';
	break;
}
?>