<?php

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

class newsletter_admin extends MX_Controller
{

    public function email()
    {
        $this->load->model('newsletter/crud_newsletter_email');

        return array('content' => $this->crud_newsletter_email->render(), 'title' => $this->lang->line('Newsletter') . '/' . $this->lang->line('Emails'));
    }

    public function message()
    {
        $this->load->model('newsletter/crud_messeges');

        return array('content' => $this->crud_messeges->render(), 'title' => $this->lang->line('Newsletter') . '/' . $this->lang->line('Messages'));
    }

    public function mail_chimp()
    {
        $this->load->library('ciext/configurator');
        $conf = new configurator('newsletter');

        $conf->add_radio('mailchimp_activation');
        $conf->add_input('mc_api_key');
        $conf->add_input('mc_list_id');

        $conf->display_as('mailchimp_activation', $this->lang->line('Copy email to MailChimp'));
        $conf->display_as('mc_api_key', $this->lang->line('API key'));
        $conf->display_as('mc_list_id', $this->lang->line('List id'));


        return array('content' => $conf->render(), 'title' => $this->lang->line('Newsletter') . '/' . $this->lang->line('MailChimp'));
    }

    public function export()
    {
        $type = (string) $this->input->get('type');
        switch ($type) {
            case 'gmail':
            case 'outlook':
                $exp = $this->load->library('newsletter/outlook_export');
                break;
            default :
                $exp = $this->load->library('newsletter/csv_export');
                break;
        }

        $exp->export($type, (string) $this->input->get('tags'));
    }

}
