<?php
require_once('../../vendor/autoload.php');
require_once('../init.php');

function error_res($status, $response_code, $message)
{
    $response = new stdClass;
    $response->status = $status;
    $response->response_code = $response_code;
    $response->message = $message;
    return json_encode($response);
}
if (isset($_SESSION['user_id'])) {
    extract($_POST);

    if (isset($password, $address)) {

        $user = User::find_by_id(isset($user_id) ? $user_id : $_SESSION['user_id']);
        if ($user) {


            $user->password = $password;
            $user->address = $address;
            $user->status = $status;
            
            if ($user->save()) {
                # code...
                echo error_res(false, "00", "Profile Updated Successful");
                exit;
            } else {
                echo error_res(false, "03", "Update Request Failed!");
                exit;
            }
        }
    } else {

        echo error_res(false, "03", "Update Error Contact Administrator!");
        exit;
    }
} else {
    echo error_res(false, "03", "Contact Administrator!");
    exit;
}
