<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(1);
require_once '../cms/includes/inicio.php';

$email = addslashes(trim(@$_POST['newsemail']));

if (!empty($email)) {
    $dados = array(
        'email' => $email,
    );

    $existe = Newsletter::listar(" email LIKE '%".$email."%' ");
    if ($existe) {
        if (count($existe) > 0) {  
            $retorno = array('status' => false, 'msg' => htmlentities('E-mail já cadastrado.')); 
        }  
    } else {
        $news = New Newsletter();
        $news->email = $email;
        $news->inserir();
        $retorno = array('status' => true, 'msg' => htmlentities('E-mail cadastrado.'));
    }
} else {
     $retorno = array('status' => false, 'msg' => htmlentities('Preencha o campo de E-mail.')); 
}


header('Content-Type: application/json; charset=utf-8');
echo html_entity_decode(json_encode($retorno));
?>