<?php

class Contactos extends MY_Controller
{

    function __construct()
    {
        parent::__construct();
        $this->title = $this->lang->line('Contactos');
    }

    function index()
    {
        parent::renderPage("contactos_view");
    }

    function submeter_contacto()
    {

        $this->load->library('email');

        $this->email->from(EMAIL_GERAL, COMPANY_NAME);
        $this->email->to(EMAIL_GERAL_DEST);

        $this->load->helper('date');
        $data = mdate("%Y-%m-%d", now());

        $this->email->subject('Contacto, via website');
        $this->email->message(

            '<h2>Dados</h2>
                            <p><b>Nome: </b>' . $this->input->post('nome') . '</p>
                            <p><b>Email: </b>' . $this->input->post('email') . '</p>
                            <p><b>Telefone: </b>' . $this->input->post('telefone') . '</p>
                            <br/>
                            <h2>Mensagem</h2>
                            <p>' . $this->input->post('mensagem') . '</p>'

        );

        $data_info = $this->input->post();
        $data_info['data'] = $data;

        $this->email->send();

        $this->load->model('contacto_model');
        $this->contacto_model->add_contacto($data_info);

        echo json_encode(
            array(
                'error' => ''
            )
        );
        return true;
    }

}