<?php 
include '../Admin_config/connection.php';
include '../Admin_controllers/login.php';

if(isset($_POST['submit'])){
//print_r($_POST);
	$user = $_POST['username'];
	$pass = md5($_POST['password']);

	$result = VALIDATE($user,$pass);

	if(!empty($result))
	{
		session_start();
		$_SESSION=$result;
		
		echo '<script type="text/javascript">';
		echo 'window.location.href = "../views/index.php";';
		echo '</script>';
		
	}else {
		echo '<script type="text/javascript">alert ("Invalid Credentials");';
		echo 'window.location.href = "../views/login.php";';
		echo '</script>';
	}

}

if(isset($_POST['forget'])){
	include '../views/forgot.php';
	$username = $_POST['username'];

}

if(isset($_POST['pass'])){
	$username = $_POST['username'];
	$new = md5($_POST['new']);
	$confirm = md5($_POST['confirm']);

	if ($new != $confirm) {
		echo '<script type="text/javascript">alert ("Passwords did not match");';
		echo 'window.history.back();';
		echo '</script>';
	}else{
		$res = FORGET_PASS($username,$new);
	}
}

?>