<?php 
defined('BASEPATH') or exit('Ação não permitida');

class Notification_model extends CI_Model{

	public function __construct()
	{
		parent::__construct();
	}

    public function send_email($template = NULL, $user_id = NULL, $data_email = NULL) {
        $user = $this->core_model->get_by_id('users', array('id' => $user_id));
        $email_data = array(
            'user_name'     => $user->first_name . ' ' . $user->last_name,
            'unique_code'   => $data_email['unique_code'],
        );
        $user_email  = $user->email;

        // Email Templates
        $welcome     = $this->load->view('restricted/email_template/welcome', $email_data, TRUE);
        $new_chapter = $this->load->view('restricted/email_template/new_chapter', $email_data, TRUE);
        $approved    = $this->load->view('restricted/email_template/approved_chapter', $email_data, TRUE);
        $recused     = $this->load->view('restricted/email_template/recused_chapter', $email_data, TRUE);
        $assigned    = $this->load->view('restricted/email_template/assigned_chapter', $email_data, TRUE);
        $resent_chapter = $this->load->view('restricted/email_template/resent_chapter', $email_data, TRUE);
        $resent_chapter_author = $this->load->view('restricted/email_template/resent_chapter_author', $email_data, TRUE);
        // Email Templates

        switch ($template):
            case 'new_chapter':
                $template = $new_chapter;
            break;
            case 'welcome':
                $template = $welcome;
            break;
            case 'approved':
                $template = $approved;
            break;
            case 'recused':
                $template = $recused;
            break;
            case 'assigned':
                $template = $assigned;
            break;
            case 'resent_chapter':
                $template = $resent_chapter;
            break;
            case 'resent_chapter_author':
                $template = $resent_chapter_author;
            break;
            default:
                $template = "";
            break;
        endswitch;
        
		$this->email->set_header('MIME-Version', 1.0);
		$this->email->set_header('Content-type', 'text/html');
		$this->email->set_header('charset', 'UTF-8');
        $this->email->set_mailtype("html");
        $this->email->set_newline("\r\n");
        
        $subject = "Novas atividades no DocNex!";
        $this->email->from('docnex@conexaoproweb.com.br', 'DocNex');
        $this->email->to($user_email);
        $this->email->subject($subject);
        $this->email->message($template);
        $this->email->send();
        echo "Email enviado";
    }


}