<?php

set_include_path("../../");
include_once("server/lib/mod_dbm/package.dbm.php");
include_once("server/class/Audit/Logger.php");

$jsonParams = file_get_contents('php://input');
$paramObj = json_decode($jsonParams);

if (isset($paramObj->token) && ($paramObj->token == TOKEN_WEB || $paramObj->token == TOKEN_BRODEVO)) {

    $dao = new dbObject();
    $q = "SELECT 1 as one";
    $res = $dao->fetchQuery($q);
    if (is_array($res) && count($res) && $res[0]['one'] === "1") {
        Logger::log(sprintf("CheckStatus: Rq Token %s, status OK", $paramObj->token));
        $jsonContent['err'] = 0;
        $jsonContent['msg'] = "Status OK";
    } else {
        Logger::log(sprintf("CheckStatus: Rq Token %s, status FAIL!", $paramObj->token));
        $jsonContent['err'] = -1;
        $jsonContent['msg'] = "Fail!";
    }
} else {
    if (isset($paramObj->token)) {
        Logger::log(sprintf("CheckStatus: Token no admitido (%s)", $paramObj->token));
    } else {
        Logger::log("CheckStatus: Token no presente");
    }
    $jsonContent['err'] = -2;
    $jsonContent['msg'] = "Parámetros incorrectos";
}

header('Content-Type: application/json; charset=utf-8');
echo json_encode($jsonContent);

