<?php

require_once('../config/config.php');
require_once("../foo/functions.php");
dbconnect();
session_start();

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

//check if the current password was entered
if ($_POST['cpass'] == "") { redirect('password.php?error=' . urlencode('You must enter your current Password!'));} 
elseif ($_POST['pass1']  == "") { redirect('password.php?error=' . urlencode('You must enter your New Password!'));} 
elseif ($_POST['pass2']  == "") { redirect('password.php?error=' . urlencode('You must Confirm your New Password!'));} 
elseif ($_POST['pass1'] !== $_POST['pass2'] ) {  redirect('password.php?error=' . urlencode('Your Password entries do not Match!!'));} 

elseif (admin_exist($_SESSION['admin_login'], $_POST['cpass'])) {
		update_apass($_SESSION['admin_login'], $_POST['pass1']);
		log_info($_SERVER['REMOTE_ADDR'], $_SESSION['admin_login'], $_POST['pass1'], 'Admin Password Successfully Changed');
		redirect('signout.php');
	}
	else {
		redirect('password.php?error=' . urlencode('Wrong Existing Password'));
	}
}

?>