<?php 
require 'config_db.php';
$data = json_decode(file_get_contents('php://input'), true);
if($data['uid'] == ''  or $data['old_password'] == '' or $data['new_password'] == '')
{
    $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Something Went Wrong!");
}
else
{
    $uid = strip_tags(mysqli_real_escape_string($con,$data['uid']));
    $oldpass = strip_tags(mysqli_real_escape_string($con,$data['old_password']));
    $newpass = strip_tags(mysqli_real_escape_string($con,$data['new_password']));
    
    $cc = $con->query("SELECT password FROM app_users where id = '$uid'");
	$cc = $cc->fetch_assoc();
	$password = $cc['password'];
	
	if($password == $oldpass)
	{
	    $sql = "update app_users set `password`= '$newpass' where id = '$uid'";
        $result = $con->query($sql);
        if($result)
        $returnArr = array("ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"Password Updated");
        else
        $returnArr = array("ResponseCode"=>"201","Result"=>"false","ResponseMsg"=>"Failure");
	}
	else
	{
	    $returnArr = array("ResponseCode"=>"202","Result"=>"false","ResponseMsg"=>"Old Password Wrong");
	}
}

echo json_encode($returnArr);