<?php
require("../snippets/autoload.php");

$user = new UserAccount();

$rules = array(
    "FirstName"=> array("required","FullName"),
    "Email"=> array("required","Email"),
);

SanitizeRequest($rules, array());
AutomaticAssignment($_POST, $user);
$user->Id = $_POST["Id"];
if(count($errors)>0){
    $response_request["title"] = _("Attention!");
    $response_request["content"] = _("There are errors in form, please check them");
    $response_request["type"] = "error";
    $response_request["Errors"] = $errors;
    $response_request["Validations"] = $validations_errors;
}else {
    if(is_numeric($user->Id)){
        if($response = $user->UpdateRecord()>0){
            $response_request["type"] = "success";
            $response_request["title"] = _("Successful process");
            $response_request["content"] = _("The user was updated");

        }else{
            $response_request["type"] = "error";
            $response_request["title"] = _("Error presented");
            $response_request["content"] = _("Unexpected error trying to update user");
        }
    }else{
        $user->Password = $utils->EncryptWithoutReverse("precisetranslations22");
        $response = $user->InsertRecord();
        $user->Id = $response;
        if($user->Id>0){
            $response_request["type"] = "success";
            $response_request["title"] = _("success registration");
            $response_request["content"] = _("Now user can login in the application with password: precisetranslations22");

        }else{
            $response_request["type"] = "error";
            $response_request["title"] = _("Error presented");
            $response_request["content"] = _("Please try again");
        }


    }
}

echo json_encode($response_request);