<?php
/**
 * Created by PhpStorm.
 * User: Joseg
 * Date: 11/6/2018
 * Time: 9:30 PM
 */

include '../comun/validarSesion.php';

if (isset($_REQUEST['token'])) {
    $Valido = new validator();
    if ($Valido->checkToken($_REQUEST['token'])){
        $creadoPor = $Valido->retornarIdToken($_REQUEST['token']);
        $condominioData = $Valido->retornarDatos($creadoPor);
        $condominio = $condominioData["condominio_id"];
        $avisos = R::findAll( 'aviso', 'id_condominio = ?', [$condominio]);
        foreach ($avisos as $valor) {
            $idavi= $valor['id'];
            $avisos[$idavi]['fecha_registro']=$Valido->time_elapsed_string($avisos[$idavi]['fecha_registro']);
        }
            include '../comun/mensajeOk.php';
        print_r(json_encode($avisos));
    }else{
        include '../comun/mensajeDatosInvalidos.php';
    }
}else{
    include '../comun/mensajeSesionInvalida.php';
}