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

$user = new UserAccount();
$user->Id = $LoggedUser;

if($_FILES["file"]["name"]==""){
    $response_request["type"] = "error";
    $response_request["title"] = _("Error presented");
    $response_request["content"] = _("We can't upload your image, please try again");
}else{
    $check = getimagesize($_FILES["file"]["tmp_name"]);
    if($check !== false) {
        $filePath = realpath($_FILES["file"]["tmp_name"]);
        $name = $utils->CompressImage($filePath,"../../uploads/user",$_FILES["file"]["name"],90);
        $user->Avatar = $name;
        if($user->UpdateAvatar()){
            $response_request["type"] = "success";
            $response_request["title"] = _("Successful process");
            $response_request["content"] = _("Your avatar was updated successfully!");
        }else{
            $response_request["type"] = "error";
          $response_request["title"] = _("Error presented");
          $response_request["content"] = _("We can't upload your image, please try again");
        }
    } else {
        $response_request["type"] = "error";
      $response_request["title"] = _("Error presented");
      $response_request["content"] = _("We can't upload your image, please try again");
    }
}
echo json_encode($response_request);