<?php
session_start();
ob_start();
 include "../config/config.php"; 
 include "../config/function.php"; 
 
 $private_key=get_privatekey($_SESSION['admin_name']);
 $request_from_server=$_SERVER['HTTP_REFERER'];
$this_server=$_SERVER['HTTP_HOST'];
if($request_from_server!=''){
	check_access_url($request_from_server,$this_server);
}

// echo $_SESSION['login_status'];echo "<br>";
// echo $_SESSION['private_key'];echo "<br>";
// echo $_SESSION['admin_name'];echo "<br>";

if($_SESSION['login_status']!='YES' || $_SESSION['private_key']!=$private_key || $_SESSION['private_key']=='' || $_SESSION['admin_name']=='')
{
    echo "Blank";
	header("Location:../AppLogin");
	exit();
}
else
{
    $admin_id=$_SESSION['admin_name'];
    $resChk=mysqli_query($connection,"Select * from tbl_account_login where account_user_name='$admin_id'");
    while($row=mysqli_fetch_array($resChk))
    {
        $idn=$row['admin_id'];
        $admin_pass=$row['account_password'];
        $oldpassword=RemoveSpecialChar($_POST['oldpassword']);
        $newpassword=RemoveSpecialChar($_POST['newpassword']);
        $confirmpassword=RemoveSpecialChar($_POST['confirmpassword']);
        if(strlen($newpassword)<10)
        {
            $msg="Minimum Length is 10 Charactor";
        }
        else if($newpassword!=$confirmpassword)
        {
            $msg="New Passowrd and Confirm Password not match";
        }
        else if($oldpassword!=$admin_pass)
        {
            $msg="Wrong Old Password";
        }
        else
        {
            mysqli_query($connection,"Update tbl_account_login set account_password='$newpassword' where account_user_name=$idn");
            $msg="Password Change Successfully";
        }
    }
}

header("Location:../ChangePassword?msg=$msg");
?>