require_once __DIR__ . "/../logging.php";
require_once __DIR__ . "/../tools.php";
require_once __DIR__ . "/../auth/AuthManager.php";
require_once __DIR__ . "/classes/Eventos.php";
try {
    $result = null;
    $am = new AuthManager("eventsFunctions");
    $operation = http_request("Operation", "s", null);
    $data = array('ID' => http_request("ID", "i", 0), 'Session' => http_request("Session", "i", 0), 'TimeStamp' => http_request("TimeStamp", "i", 0), 'Type' => http_request("Type", "s", ""), 'Source' => http_request("Source", "s", ""), 'Pru' => http_request("Prueba", "i", 0), 'Jor' => http_request("Jornada", "i", 0), 'Mng' => http_request("Manga", "i", 0), 'Tnd' => http_request("Tanda", "i", 0), 'Dog' => http_request("Perro", "i", 0), 'Drs' => http_request("Dorsal", "i", 0), 'Hot' => http_request("Celo", "i", 0), 'Eqp' => http_request("Equipo", "i", 0), 'Flt' => http_request("Faltas", "i", -1), 'Toc' => http_request("Tocados", "i", -1), 'Reh' => http_request("Rehuses", "i", -1), 'NPr' => http_request("NoPresentado", "i", -1), 'Eli' => http_request("Eliminado", "i", -1), 'Tim' => http_request("Tiempo", "d", -1), 'Value' => http_request("Value", "i", -1), 'stop' => http_request("stop", "i", 0), 'start' => http_request("start", "i", 0));
    if ($operation === null) {
        throw new Exception("Call to eventFunctions without 'Operation' requested");
    }
    $eventmgr = new Eventos("eventFunctions", $data['Session'], $am);
    switch ($operation) {
        case "getEvents":
            $result = $eventmgr->getEvents($data);
            break;
        case "putEvent":
            $am->access(PERMS_ASSISTANT);
            $result = $eventmgr->putEvent($data);
            break;
        case "chronoEvent":
            $am->access(PERMS_CHRONO);
            $result = $eventmgr->putEvent($data);
            break;
        case "listEvents":
            $result = $eventmgr->listEvents($data);
            break;
        case "connect":
            $result = $eventmgr->connect($data);
            break;