<?php
include("../../db.php");
error_reporting(E_ALL);
header("Access-Control-Allow-Origin: * ");
//$_POST['json'];
$abc = base64_decode($_POST['json']);

$idata = json_decode($abc, true);
$session = $idata['session'];
$id = $idata['id'];
$old_pass = $idata['old_pass'];
$new_pass = $idata['new_pass'];

$passEnc = new password();
$old_pass_enc = $passEnc->password($old_pass);
$new_pass_enc = $passEnc->password($new_pass);

// 	 $session=mysql_real_escape_string($session);
// 	 $id=mysql_real_escape_string($id);
// 	 $old_pass=mysql_real_escape_string($old_pass);
// 	 $new_pass=mysql_real_escape_string($new_pass);

$check_data = $db->getval("select password from staff where idno='$id' and session='$session'");

if ($old_pass_enc == $check_data) {

    $saveAry = array("password" => $new_pass_enc);

    $flgUp = $db->updateAry("staff", $saveAry, "where idno='$id'  and session='$session'");

    if (!is_null($flgUp)) {
        echo json_encode(array('status' => 1, 'msg' => 'Password Changed Successfully..!'));

    } else {
        echo json_encode(array('status' => 0, 'msg' => 'Unable to change password..!'));
    }

} else {
    echo json_encode(array('status' => 0, 'msg' => 'old Password does not match..!'));
}
