<?php
/**
 * Created by PhpStorm.
 * User: Joseg
 * Date: 25/5/2018
 * Time: 4:52 PM
 */

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

if (isset($_REQUEST['token'])) {
    $Valido = new validator();
    $ImageUploader = new uploadImage();
    if ($Valido->checkToken($_REQUEST['token'])){
        if (isset($_REQUEST['asunto']) && isset($_REQUEST['descripcion'])) {
                $creadoPor = $Valido->retornarIdToken($_REQUEST['token']);
                $condominio = $Valido->retornarDatos($creadoPor);
                $aviso = R::dispense('aviso');
                $aviso->asunto = $_REQUEST['asunto'];
                $aviso->descripcion = $_REQUEST['descripcion'];
                if (isset($_REQUEST['imagen'])){
                    $imagen = $_REQUEST['imagen'];
                    $aviso->imagen = $ImageUploader->subirImagen($imagen);
                }else{
                    $aviso->imagen = '';
                }
                $aviso->id_condominio = $condominio["condominio_id"];
                $aviso->id_autor = $creadoPor;
                $aviso->fechaRegistro = date('Y-m-d H:i:s');
                $aviso->fechaModificacion = date('Y-m-d H:i:s');
                $aviso->estado = 1;
                $id = R::store($aviso);
                include '../comun/mensajeCreado.php';

        }else{
            include '../comun/mensajeFaltanCampos.php';
        }
    }else{
        include '../comun/mensajeDatosInvalidos.php';
    }
}else{
    include '../comun/mensajeSesionInvalida.php';
}