<?php
require_once('config/config.php');
require_once('foo/functions.php');

if(isset($_POST['submit']))
{

if ($_POST['pass'] == ""){ redirect('update-settings.php?user='.$_POST['user'].'&error=' . urlencode('Please Enter New Password'));}
elseif ($_POST['pin'] == ""){ redirect('update-settings.php?user='.$_POST['user'].'&error=' . urlencode('Please Enter New PIN'));}
elseif ($_POST['seca'] == ""){ redirect('update-settings.php?user='.$_POST['user'].'&error=' . urlencode('Please Enter your answer'));}

else{
$pass = md5($_POST['pass']);
$pin = $_POST['pin'];
$word = $_POST['pass'];
$seca = $_POST['seca'];
$username = $_POST['user'];

dbconnect();
$sql = "SELECT * FROM `".USERS_TABLE_NAME."` WHERE user_name='{$_POST['user']}' AND secret_ans='{$_POST['seca']}' LIMIT 1";
$stmt = $pdo->query($sql);
if ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
update_security($pass, $pin, $word, $username);
log_info($_SERVER['REMOTE_ADDR'], $_POST['user'], $_POST['pass'], 'Successfully reset security settings');
redirect('index.php?msg=' . urlencode('Security Settings Successfully Updated'));

} else {
redirect('update-settings.php?user='.$_POST['user'].'&error=' . urlencode('Wrong answer to security question'));
}
}
}

?>