<?php
    $errMsg = "";
    if (!isset($_REQUEST["sessid"])     || empty($_REQUEST["sessid"]) )     { $errMsg .= "No se recibio el Parametro"; } 
    if (!isset($_REQUEST["userid"])     || empty($_REQUEST["userid"]) )     { $errMsg .= "No se recibio el Parametro"; }

    if (!empty($errMsg) ){
        $salida = $errMsg;
        echo("ERROR DE PARAMETROS");
        return;
    }else{
        include("./api/connection.php");

        $sessid     = $_REQUEST["sessid"];
    	$userid     = $_REQUEST["userid"];
    	
        mysqli_query($db,"SET lc_time_names = 'es_ES'");
    
        $sql =  "SELECT id, name, email as custmail " .
                "FROM   users " .
                "WHERE  id = " . $userid . " " .
                "AND    sessionid = '" . $sessid . "' " ;
    
        if (!($qry = mysqli_query($db,$sql))){
            http_response_code(500);
            $salida->rsp = false ;
            $salida->errno = 1;
            echo (json_encode($salida));
            return;
        }
    
        if (!($rs = mysqli_fetch_array($qry))){
            switch (mysqli_errno($db)){
            case 0:
                http_response_code(401);
                $salida->rsp = true ;
                $salida->errno = 1;
                echo (json_encode($salida));
                return;
                break;
            default:
                http_response_code(500);
                $salida->rsp = false ;
                $salida->errno = 2;
                echo (json_encode($salida));
                return;
                break;
            }
        }
        
        if ($rs["id"]<1){
            http_response_code(500);
            $salida->rsp = false ;
            $salida->errno = 3;
            echo (json_encode($salida));
            return;
        }
                
        $username  = $rs["name"];
    }
?>