<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

class newsletter_site extends MX_Controller
{
    
    public function __construct()
    {
        $this->form_hash->time_point = 3;
    }

    public function index()
    {
        $this->load->helper('form');
        $content = array(
            'hash' => $this->form_hash->set_form_hash(),
        );

        return $this->parser->parse('newsletter/template', $content, TRUE);
    }

    public function add()
    {
        $data = array(
            'success' => false,
        );

        if ($this->input->post('email') && $this->form_hash->check_form_hash()) {
            $this->db->insert('newsletter_email', array(
                'email' => $this->input->post('email'),
                'date'  => date('Y-m-d H:i:s'),
            ));
            $data['success'] = ($this->db->insert_id() > 0);
        }
        
        $data['hash'] = $this->form_hash->set_form_hash();

        $this->output->set_content_type('application/json')->set_output(json_encode($data));
    }

}
