<?php
    header("Content-Type:application/json");
    include("../connection.php");
    include("../utils.php");
    
    //Parametros obligatorios
    $parmsob = array("sessionid",'id');
    if (!parametrosValidos($_GET, $parmsob))
        badEnd("400", array("msg"=>"Parametros obligatorios " . implode(", ", $parmsob)));
    
    // Declaracion e inicializacion de variables
    $out = new stdClass();
    $sessionid = $_GET["sessionid"];
    $id = $_GET['id'];
    
    //Verificamos que la sesion no este expirada
    isSessionValid($db, $sessionid);
    
    // Consultamos la cantidad de registros que existen
    $sql = "SELECT COUNT(id) AS qty ".
    "       FROM settings".
    "       WHERE id = ".$id;
    if (!$rs=$db->query($sql))
        badEnd("500", array("msg"=>$db->error));
        
    $row = $rs->fetch_assoc();
    if($row['qty'] == 0){
        badEnd(204,array('msg'=>'Registro no encontrado'));
    }
    
    $sql = "SELECT * FROM settings".
    "       WHERE id = ".$id;
    if (!$rs=$db->query($sql))
        badEnd("500", array("msg"=>$db->error));
        
    $row = $rs->fetch_assoc();
    $out->entry = new stdClass();
    
    $out->entry->id = (int)$row['id'];
    $out->entry->name = $row['name'];
    $out->entry->type = (int)$row['type'];
    $out->entry->support = $row['support'];
    $out->entry->content = $row['content'];
    if($out->entry->type == 4){
        $out->entry->formatted = date('d/m/Y', strtotime($row['content']));
    }
    $out->entry->dsc = $row['dsc'];
    
    header("HTTP/1.1 200");
    echo (json_encode($out));
    die();
?>