<?php

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

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

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

if(isset($paramObj->user) && isset($paramObj->pass)){
    $version = (isset($paramObj->version))?$paramObj->version:"1.0";
    $idDelivery=$paramObj->user;
    $pass=$paramObj->pass;
    
    $delivery = new Delivery($idDelivery);
    if ($delivery->appValidate($pass)){
        $ack['error'] = 0;
        $ack['userId'] = $delivery->idDelivery;
        $ack['user'] = $delivery->nombre;
        $ack['iniciales'] = $delivery->iniciales;
        $ack['idLocal'] = $delivery->localActual;
        $ack['token'] = session_id();
        $ack['srvVersion'] = "2.0";
        $delivery->updateToken($ack['token'], $version, time());
    } else {
        $ack['error'] = -2;
        $ack['userId'] = "";
    }
} else {
    $idDelivery = null;
    $pass = null;
    $ack['error'] = -1;
    $ack['userId'] = "";
}

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