<?php

/*
 * ROMAN DIGITAL - Autor: Américo Patetta
 */

set_include_path("../../");
include_once("server/class/Delivery.php");
include_once("server/class/EventsManager.php");
@session_start();

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

// eventCode:
// GPS: Se desconectó el GPS.

if (isset($paramObj->evtCode) && isset($paramObj->token)) {
    $delivery = new Delivery(-1);
    $timestamp = isset($paramObj->timestamp)?$paramObj->timestamp:time();
    $deliveryId = $delivery->setIdDeliveryFromToken($paramObj->token);
    if(!($deliveryId === -1)){
        $evMgr = new EventsManager();
        $evMgr->addEvent($deliveryId, $paramObj->evtCode, $timestamp);   
        $ack['error'] = 0;
    } else {
        $ack['error'] = -2;
    }
    
    try{
        
    } catch (Exception $ex) {

    }
    
    
} else {
    $ack['error'] = -1;
}

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