2023-11-01 00:27:17 +05:30
|
|
|
<?php // JSON-related functions
|
2023-08-12 04:09:17 +05:30
|
|
|
|
2023-11-01 00:27:17 +05:30
|
|
|
// Includes
|
|
|
|
require_once("_errorslist.php");
|
2023-08-12 04:09:17 +05:30
|
|
|
|
2023-08-16 09:04:01 +05:30
|
|
|
|
|
|
|
|
2023-11-01 00:27:17 +05:30
|
|
|
// Write valid JSON data to stdout and exit
|
|
|
|
function JSON_ReturnData ($arr) {
|
2023-08-12 04:09:17 +05:30
|
|
|
$data = json_encode($arr);
|
|
|
|
if (!$data) {
|
2023-11-01 00:27:17 +05:30
|
|
|
$data = json_encode(
|
|
|
|
array(
|
|
|
|
"error" => Errors_ResolveNameByCode(E_UNS_JSONBADINP)
|
|
|
|
)
|
|
|
|
);
|
2023-08-12 04:09:17 +05:30
|
|
|
}
|
|
|
|
header("Content-Type: application/json; charset=utf-8");
|
|
|
|
echo $data;
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2023-11-01 00:27:17 +05:30
|
|
|
// Return error as JSON data to stdout and exit
|
|
|
|
function JSON_ReturnError (int $code = -1, string $name = "", string $desc = "") {
|
|
|
|
if ($code === -1 && empty($name))
|
|
|
|
JSON_ReturnError(code: E_UNS_INTERNAL, desc: "cant return error without specified code or name");
|
|
|
|
else if ($code === -1)
|
|
|
|
$code = Errors_ResolveCodeByName($name);
|
|
|
|
else if (empty($name))
|
|
|
|
$name = Errors_ResolveNameByCode($code);
|
|
|
|
|
|
|
|
JSON_ReturnData(array(
|
|
|
|
"error" => $name, // Name
|
|
|
|
"error_code" => $code, // Code
|
|
|
|
"error_hum" => Errors_ResolveDescByCode($code), // Common description
|
|
|
|
"description" => $desc // Detailed decription
|
2023-08-12 04:09:17 +05:30
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2023-11-01 00:27:17 +05:30
|
|
|
|
|
|
|
|
2023-08-12 04:09:17 +05:30
|
|
|
?>
|