<?php 
session_start();
if (isset($_SESSION['id'])) {
$id = $_SESSION['id'];
}else{
header("location:login");
} 
include_once '../includes/autoloader.php';
include_once '../includes/function.php';
$newfx = new bank;
$fetch = $newfx->fetch_Admin_by_id($id);
 
$old = purify($_POST["old_pin"]);
$pass = purify($_POST["new_pass"]);
$cpass = purify($_POST["con_pass"]);
if ($old == FALSE) {
echo "<div class='alert alert-danger'>the old password field Cannot be empty</div>";
} else {
if ($pass == FALSE) {
echo "<div class='alert alert-danger'>the new password field Cannot be empty</div>";
} else {
if ($cpass == FALSE) {
echo "<div class='alert alert-danger'>the confirm password field Cannot be empty</div>";
} else{ 

$pinn = $fetch["pass"];

if ($old == $pinn) {
if ($pass == $cpass) {
$db = new dbh;
$dbconn = $db->connect();
$sql = "UPDATE `administrators` SET pass = '$pass' WHERE id = '$id'";
$conn = $dbconn->prepare($sql);
$update = $conn->execute();
if (!$update) {
echo "<div class='alert alert-danger'>not updated</div>";
}else{
echo "<div class='alert alert-success'>your password was updated successfully</div>";
}
}else{
echo "<div class='alert alert-danger'>your passwords does not match</div>";
}
}else{
echo "<div class='alert alert-danger'>your current password is wrong</div>";
}
}
}
}


?>
