<?php

include_once ('includes/config.php');

if (isset($_POST['get_programacao'])) {

    $query = "SELECT * from tbl_progamacao";
    $resouter = mysqli_query($connect, $query);

    $encode = array();

    if ($resouter->num_rows > 0) {
        $resouter->data_seek(0);

        while ($row = $resouter->fetch_assoc()) {
            $rows[] = $row;
        }
        echo json_encode($rows);
    }
}

if (isset($_POST['get_noticias'])) {

    $query = "SELECT * from tbl_noticias";
    $resouter = mysqli_query($connect, $query);

    $encode = array();

    if ($resouter->num_rows > 0) {
        $resouter->data_seek(0);


        while ($row = $resouter->fetch_assoc()) {

            $rows[] = $row;

        }
        echo json_encode($rows);

    }
}

if (isset($_GET['get_menu'])) {

    $query = "SELECT * from tbl_menu";
    $resouter = mysqli_query($connect, $query);

    $encode = array();

    if ($resouter->num_rows > 0) {
        $resouter->data_seek(0);


        while ($row = $resouter->fetch_assoc()) {

            $rows[] = $row;

        }
        echo json_encode($rows);

    }
}

if (isset($_GET['get_radio'])) {

    $query = "SELECT * from tbl_radio";
    $resouter = mysqli_query($connect, $query);

    $encode = array();

    if ($resouter->num_rows > 0) {
        $resouter->data_seek(0);


        while ($row = $resouter->fetch_assoc()) {

            $rows[] = $row;

        }
        echo json_encode($rows);

    }
}

if (isset($_POST['get_radio'])) {

    $query = "SELECT * from tbl_radio";
    $resouter = mysqli_query($connect, $query);

    $encode = array();

    if ($resouter->num_rows > 0) {
        $resouter->data_seek(0);


        while ($row = $resouter->fetch_assoc()) {

            $rows[] = $row;

        }
        echo json_encode($rows);

    }
}

if (isset($_POST['get_tv'])) {

    $query = "SELECT * from tbl_tv";
    $resouter = mysqli_query($connect, $query);

    $encode = array();

    if ($resouter->num_rows > 0) {
        $resouter->data_seek(0);


        while ($row = $resouter->fetch_assoc()) {

            $rows[] = $row;

        }
        echo json_encode($rows);

    }


}

if (isset($_GET['get_equipe'])) {
    $query = "SELECT * from tbl_equipe";
    $resouter = mysqli_query($connect, $query);
    $encode = array();
    if ($resouter->num_rows > 0) {
        $resouter->data_seek(0);
        while ($row = $resouter->fetch_assoc()) {
            $rows[] = $row;
        }
        echo json_encode($rows);
    }
}

if (isset($_GET['get_temas'])) {

    $query = "SELECT * from tbl_themas";
    $resouter = mysqli_query($connect, $query);

    $encode = array();

    if ($resouter->num_rows > 0) {
        $resouter->data_seek(0);


        while ($row = $resouter->fetch_assoc()) {

            $rows[] = $row;

        }
        echo json_encode($rows);

    }

}

if (isset($_GET['get_bg'])) {

    $query = "SELECT * from tbl_radio";
    $resouter = mysqli_query($connect, $query);

    $encode = array();

    if ($resouter->num_rows > 0) {
        $resouter->data_seek(0);


        while ($row = $resouter->fetch_assoc()) {

            $rows[] = $row;

        }
        echo json_encode($rows);

    }

}
    

if (isset($_GET['get_splash'])) {

    $query = "SELECT * from tbl_anuncio";
    $resouter = mysqli_query($connect, $query);

    $encode = array();

    if ($resouter->num_rows > 0) {
        $resouter->data_seek(0);


        while ($row = $resouter->fetch_assoc()) {

            $rows[] = $row;

        }
        echo json_encode($rows);

    }

}
    


if (isset($_POST['get_slides'])) {

    $query = "SELECT * from tbl_baner";
    $resouter = mysqli_query($connect, $query);

    $encode = array();

    if ($resouter->num_rows > 0) {
        $resouter->data_seek(0);


        while ($row = $resouter->fetch_assoc()) {

            $rows[] = $row;

        }
        echo json_encode($rows);

    }


}

if (isset($_POST['get_banertv'])) {

    $query = "SELECT * from tbl_banertv";
    $resouter = mysqli_query($connect, $query);

    $encode = array();

    if ($resouter->num_rows > 0) {
        $resouter->data_seek(0);


        while ($row = $resouter->fetch_assoc()) {

            $rows[] = $row;

        }
        echo json_encode($rows);

    }


}

if (isset($_POST['get_agenda'])) {

    $query = "SELECT * from tbl_agenda";
    $resouter = mysqli_query($connect, $query);

    $encode = array();

    if ($resouter->num_rows > 0) {
        $resouter->data_seek(0);


        while ($row = $resouter->fetch_assoc()) {

            $rows[] = $row;

        }
        echo json_encode($rows);

    }


}


if (isset($_GET['get_promocoes'])) {

    $query = "SELECT * from tbl_promocoes";
    $resouter = mysqli_query($connect, $query);

    $encode = array();

    if ($resouter->num_rows > 0) {
        $resouter->data_seek(0);


        while ($row = $resouter->fetch_assoc()) {

            $rows[] = $row;

        }
        echo json_encode($rows);

    }

}


if (isset($_GET['cadastrarPromocao']) && $_GET['cadastrarPromocao'] == true) {

    $nome = $_GET['nome'];
    $cpf = $_GET['cpf'];
    $email = $_GET['email'];
    $celular = $_GET['celular'];
    $dataNascimento = $_GET['nascimento'];
    $id_promocao = $_GET['id_promocao'];

    $query = "SELECT * from tbl_inscricoes WHERE email = '".$email."'";
    $resouter = mysqli_query($connect, $query);

    $encode = array();

    if ($resouter->num_rows == 0) {
        $inseriQuery = "INSERT INTO `tbl_inscricoes` (`id_promocao`, `nome`, `email`, `cpf`, `celular`, `nascimento`) VALUES   ('".$id_promocao."','".$nome."','".$email."','".$cpf."','".$celular."','".$dataNascimento."')";
        $con = mysqli_query($connect, $inseriQuery);
        $response = array('resposta' => true,'mensagem'=>'inscrição realizada com sucesso');
        echo json_encode($response);
    }else{
        $response = array('resposta' => false,'mensagem'=>'Usuário já participante');
        echo json_encode($response);
    }

}

if (isset($_GET['get_MenuApp'])) {

    $query = "SELECT * from menuapp_config";
    $resouter = mysqli_query($connect, $query);

    $encode = array();

    if ($resouter->num_rows > 0) {
        $resouter->data_seek(0);


        while ($row = $resouter->fetch_assoc()) {

            $rows[] = $row;

        }
        echo json_encode($rows);

    }


}


if (isset($_POST['set_mural'])) {

    $nome = $_POST['nome'];
    $mensagem = $_POST['mensagem'];

    //INCLUIR
    $query = "INSERT INTO tbl_mensagem (nome,mensagem) VALUES ('$nome','$mensagem')";

    $inclui = $connect->query($query);
    if ($inclui):
        echo json_encode(array('resposta' => 'adicionado com sucesso'));
    else:
        echo json_encode(array('resposta' => 'Erro ao adicionar'));
    endif;

}

if (isset($_POST['get_mural'])) {

    $query = "SELECT * from tbl_mensagem";
    $resouter = mysqli_query($connect, $query);

    $encode = array();

    if ($resouter->num_rows > 0) {
        $resouter->data_seek(0);


        while ($row = $resouter->fetch_assoc()) {

            $rows[] = $row;

        }
        echo json_encode($rows);

    }


}
