<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
include_once GROCERY_CRUD;

class Cadastro extends Builder_Controller
{
    function __construct() 
    {
        parent::__construct();
        $this->load->model('newsletter_model');
        $this->load->library('newsletter/newsletter');
    }
    
    public function teste_email()
    {
        $this->load->library('newsletter/newsletter',null,'nwl');
        echo $this->nwl->enviar_email_campanha('ricardo.luis@viewbrasil.com.br', 1);
    }
    
    public function cadastro() 
    {
        //var_dump("aqui");die();
        
        if ($this->input->post()) 
        {
            $dados = $this->input->post();
            if ($this->validaEmail($dados['email'])) 
            {
                $data['email'] = trim($dados['email']);
                //$data['nome'] = $dados['nome'];
                $data['origem'] = $dados['origin'];
                
                $db = @$this->db->where('email', $data['email'])->get('nwl_emails')->row();
                if($db != null)
                {
                    $html = 'O seu e-mail já está cadastrado. Clique ';
                    $html.= '<a id="reenvio" href="#" class="reenvio">aqui</a> ';
                    $html.= 'para novo envio do e-mail.';
                    $result['result'] = 2; // ja tem
                    //$result['msg'] = $html;
                    $result['msg'] = 'Ops! Este e-mail já foi cadastrado em nossa comunidade. Que tal tentar outro?';
                    
                    if ($db->status != 1 || $db->origem != $data['origem'])
                        @$this->db->where('email',$data['email'])->set('status', 1)->set('origem', $data['origem'])->update('nwl_emails');
                    
                    if ($db->status == 2){
                        @$this->db->where('email',$data['email'])->set('status', 1)->set('origem', $data['origem'])->set('criado_em', date('Y-m-d H:i:s'))->update('nwl_emails');
                        $this->newsletter->enviar_email_campanha($dados['email'], 43, $dados);
                        $result['result'] = 2; // ja tem
                        $result['msg'] = 'Oba! O seu cadastro foi realizado com sucesso. Enviamos uma mensagem para o seu e-mail, não esqueça de conferir sua caixa de spam.';
                    }
                        
                }
                else
                {
                    $data['criado_em'] = date('Y-m-d H:i:s');
                    @$this->db->insert('nwl_emails', $data);
                    $this->newsletter->enviar_email_campanha($dados['email'], 43, $dados);
                    $result['result'] = 1; // ok
                    $result['msg'] = 'Oba! O seu cadastro foi realizado com sucesso. Enviamos uma mensagem para o seu e-mail, não esqueça de conferir sua caixa de spam.';
                }
            } 
            else
            {
                $result['result'] = 3; // nao cadastrou
                $result['msg'] = 'Esse endereço de e-mail não é válido!';
            }
            echo json_encode($result);
        }
    }
    
    public function servicos() 
    {
        if ($this->input->post()) 
        {
            $dados = $this->input->post();
            if ($this->validaEmail($dados['email'])) 
            {
                $data['email'] = trim($dados['email']);
                $data['nome'] = $dados['nome'];
                $data['origem'] = $dados['origin'];
                
                $db = @$this->db->where('email', $data['email'])->get('nwl_emails')->row();
                if($db != null)
                {
                    $html = 'O seu e-mail já está cadastrado. Clique ';
                    $html.= '<a id="reenvio" href="#" class="reenvio">aqui</a> ';
                    $html.= 'para novo envio do e-mail.';
                    $result['result'] = 2; // ja tem
                    $result['msg'] = $html;
                    
                    if ($db->status != 1 || $db->origem != $data['origem'])
                        @$this->db->where('email',$data['email'])->set('status', 1)->set('origem', $data['origem'])->update('nwl_emails');
                }
                else
                {
                    @$this->db->insert('nwl_emails', $data);
                    /*$this->newsletter->enviar_email_campanha($dados['email'], 2, $dados);*/
                    $result['result'] = 1; // ok
                    $result['msg'] = 'Cadastro realizado com sucesso.';
                }
            } 
            else
            {
                $result['result'] = 3; // nao cadastrou
                $result['msg'] = 'Esse endereço de e-mail não é válido!';
            }
            echo json_encode($result);
        }
    }
    
    public function reenvio() 
    {
        if ($this->input->post()) 
        {
            $dados = $this->input->post();
            $data['nome'] = $dados['nome'];
            $data['email'] = $dados['email'];
            
            
            $result['result'] = $this->newsletter->enviar_email_campanha($dados['email'], 2, $dados); // ok
            $result['msg'] = 'O E-book gratuito foi enviado para o seu e-mail, verifique também na sua caixa de spam.';
            
            echo json_encode($result);
        }
    }
    
    
    
    public function cadastro_bk() 
    {
        $data_location = $this->get_api_location_();
        if ($this->input->post()) 
        {
            $dados = $this->input->post();
            if(isset($dados['http_referer']))
            {
                $data_location['http_referer'] = $dados['http_referer'];
            }
            
            if ($this->validaEmail($dados['email'])) 
            {
                    $data['email'] = $dados['email'];
                    $data['origem'] = $dados['origin'];
                    $data['activation_key'] = md5(rand() . microtime());
                    $email_dados = $this->newsletter_model->confirma_email($data['email']);
                    if ($email_dados !== NULL) 
                    {
                        if ($email_dados->status != 1) 
                        {
                            $html = 'O seu e-mail já está cadastrado. Clique ';
                            $html.= '<a id="reenvio" href="#" class="reenvio">aqui</a> ';
                            $html.= 'para novo envio do e-mail de ativação.';
                            
                            $success['result'] = 1; // ja tem
                            $success['form'] = $html;
                        } 
                        else
                        {
                            $success['result'] = 3; // email ja confirmado
                            $success['form'] = 'O seu e-mail já está cadastrado e ativado';
                        }
                    } 
                    else
                    {
                        $id = $this->newsletter_model->insere_news_email($data);
                        
                        if ($id != NULL) 
                        {
                            $data_location['id_email'] = $id;
                            $this->newsletter_model->insert_local_cadastro($data_location);
                            
                            $data['id'] = $id;
                            $data['key_concat'] = $id . $data['activation_key'];
                            $data['subject'] = "Ativação de cadastro!";
                            $result_email = $this->envia_confirmacao($data);
                            //$result_email = $this->enviar_email_campanha($data['email'], 1);
                            //$result_email = true;
                            if ($result_email === true) 
                            {
                                $this->newsletter_model->enviou_email_1($id);
                                $success['result'] = 2;
                            } 
                            else
                            {
                                $success['result'] = $result_email;
                            }
                        } 
                        else
                        {
                            $success['result'] = 3; // nao cadastrou
                            $success['form'] = '<strong>Ops! </strong> Parece que ocorreu um erro, tente novamente.';
                        }
                    }
            } 
            else
            {
                $success['result'] = 3; // nao cadastrou
                $success['form'] = 'Esse endereço de e-mail não é válido!';
            }
            echo json_encode($success);
        }
    }
    
    public function reenvio_bk() 
    {
        if ($this->input->post()) 
        {
            
            $dados = $this->input->post();
            $data['email'] = $dados['email'];
            
            $email_dados = $this->newsletter_model->confirma_email($data['email']);
            if ($email_dados !== NULL && $email_dados->status != 1) 
            {
                $data['activation_key'] = $email_dados->activation_key;
                $data['id'] = $email_dados->id;
                $data['key_concat'] = $email_dados->id . $email_dados->activation_key;
                
                $data['subject'] = "Ativação de cadastro!";
                $result_email = $this->envia_confirmacao($data);
                if ($result_email === true) 
                {
                    $this->newsletter_model->reenviou_email_conf($email_dados->id);
                    $success['result'] = 2;
                } 
                else
                {
                    $success['result'] = 3; // nao cadastrou
                    $success['form'] = '<strong>Ops! </strong> Parece que ocorreu um erro, tente novamente.';
                }
            } 
            else
            {
                $success['result'] = 3; // email ja confirmado
                $success['form'] = 'O seu e-mail já está cadastrado e ativado';
            }
            echo json_encode($success);
        }
    }
    
    public function envia_confirmacao($data) 
    {
        $data['key_concat'] = $data['id'] . $data['activation_key'];
        return $this->enviar_email_campanha($data['email'], 1, $data);
    }
    
    /* public function envia_confirmacao($data) 
    {
        
        $this->load->library('email');
        
        $data['url'] = base_url() . "newsletter/confirmacao/confirmacao/" . $data['id'] . $data['activation_key'];
        //$data = array('nome'=>$new_nome,'url'=>$url);
        
        $config['protocol'] = 'mail';
        $config['mailpath'] = '/usr/sbin/sendmail';
        $config['charset'] = 'utf-8';
        $config['wordwrap'] = TRUE;
        
        $this->load->library('email');
        $this->email->from('contato@viewbrasil.com.br', "QiClub");
        $this->email->to($data['email']);
        $this->email->subject($data['subject']);
        $this->email->message($this->load->view('email-activate-html', $data, TRUE));
        
        if ($this->email->send()) 
        {
            return true;
        } 
        else
        {
            return $this->email->print_debugger();
        }
    }*/
    
    
    
    function enviar_email_campanha($email, $id_campanha, $dados = null) 
    {
        $this->load->model('newsletter/newsletter_model');
        if($email != null)
        {
            $campanha = $this->newsletter_model->get_campanha($id_campanha);
            if($campanha != null)
            {
                $config = $this->newsletter_model->get_config_campanha();
                if ($campanha->view_html == "") 
                {
                    $view = 'newsletter/campanha/email_default_html';
                } 
                else
                {
                    $view = $campanha->view_html;
                }
                $key_log = md5($email . $id_campanha . date('Y-m-d H:i:s'));
                $data = array(
                    'campanha'      => $campanha->campanha,
                    'base_url'      => base_url(),
                    'email'         => $email,
                    'key_log'       => $key_log,
                    'subject'       => $campanha->subject,
                    'link'          => $campanha->link_destino,
                    'from_email'    => $config->from_email,
                    'from_titulo'   => $config->from_titulo,
                    'img'           => $config->img,
                    'mensagem'      => $campanha->mensagem,
                    'view_html'     => $view,
                );
                if($dados != null)
                {
                    $data = array_merge($data, $dados);
                }
                $rst_email = $this->_envia_email_campanha($data);
                if ($rst_email === true) 
                {
                    $this->enviou_email_campanha($email, $id_campanha, 1, $key_log);
                    return true;
                } 
                else
                {
                    $this->enviou_email_campanha($email, $id_campanha, 0, $key_log);
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
        
    }
    
    public function _envia_email_campanha($data) 
    {
        $this->load->library('parser');
        $this->load->library('email');
        $config['protocol'] = 'sendmail';
        $config['mailpath'] = '/usr/sbin/sendmail';
        $config['charset'] = 'iso-8859-1';
        $config['wordwrap'] = TRUE;
        
        $this->load->library('email');
        //$this->email->initialize($config);
        
        $this->email->from($data['from_email'], $data['from_titulo']);
        $this->email->to($data['email']);
        $this->email->subject($data['subject']);
        
        $this->email->message($this->parser->parse($data['view_html'], $data, TRUE));
                                 
        if ($this->email->send() === true) 
        {
            //var_dump($data);
            //echo "foi";
            return true;
        } 
        else
        {
            //echo $this->email->print_debugger();
            return $this->email->print_debugger();
        }
    }
    
    function enviou_email_campanha($email, $id_campanha, $st, $key_log) 
    {
        $this->load->model('newsletter/newsletter_model');
        
        $insert = array(
            'email' => $email,
            'id_campanha' => $id_campanha,
            'key_log' => $key_log,
            'enviado' => $st,
            'enviado_em' => date('Y-m-d H:i:s'),
        );
        $this->newsletter_model->insere_log($insert);
        if ($st == 1) 
        {
            $this->newsletter_model->enviou_campanha($id_campanha);
        } 
        else
        {
            $this->newsletter_model->falhou_campanha($id_campanha);
        }
    }
    
    
    
    
    
    private function validaEmail($email) 
    {
        $array_invalidos = array(
            '@mailinator.com',
            '@harakirimail.com'
            );
        $syntaxe = '#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$#';
        if (preg_match($syntaxe, $email))
        {
            foreach($array_invalidos as $invalido)
            {
                $result = strrpos($email, $invalido); //Resultado: 8
                if($result != null)
                {
                   return false;
                }
            }
                    
              return true;
        }
        else 
        {
            return false;
        }
       
    }
    
    //##################################################################################################################################################################################
    
    
    public function envia_email_comingsoon() 
    {
        $result = $this->newsletter_model->listar_leads();
        
        if ($result !== NULL) 
        {
            foreach($result as $lead)
            {
                 /*if((int)$lead->id === 28)
                {*/
                    $data['id'] = $lead->id;
                    $data['activation_key'] = $lead->activation_key;
                    $data['key_concat'] = $lead->id . $lead->activation_key;
                    $data['subject'] = "Ative o seu cadastro para iniciarmos o nosso relacionamento de sucesso!";
                    $data['email'] = $lead->email;
                    
                    $result_email = $this->envia_confirmacao($data);
                    if ($result_email === true) 
                    {
                        $this->newsletter_model->enviou_email_1($lead->id);
                        echo "lead:".$lead->id." - enviado com sucesso <br>";
                    } 
                    else
                    {
                        echo "lead:".$lead->id." - erro ao enviar e-mail <br>";
                    }
               /*}*/
            }
        } 
        else
        {
            echo "Erro";
        }
    }
    
    public function desinscrever() 
    {
        $data['key_desinscrever_email'] = $this->uri->segment(3);
        $this->session->set_userdata($data);
        
        redirect('newsletter/desinscrever_email');
    }
    
    public function desinscrever_email()
    {
        $link_redirect = 'http://blog.viewbrasil.com.br';
        $key = $this->session->key_desinscrever_email;
        //$key = "102be40b5c35be856a8665aa67679e9f7";//comentar
        if(!isset($key) || $key == NULL)
        {
            redirect($link_redirect);
        }
        
        $this->load->model('newsletter/newsletter_model');
        
        if($this->newsletter_model->verifica_cadastro($key) == 2)
        {
            redirect($link_redirect);
        }
        
        $this->load->library('form_validation');
        
        if ($this->input->post() == TRUE) 
        {
            $this->form_validation->set_rules('motivo', 'razão da sua desinscrição', 'required');
    		if($this->input->post('motivo') == "Outro")$this->form_validation->set_rules('obs', 'Texto', 'required|trim');
    		
    		if ($this->form_validation->run() != FALSE)
    		{
    		    $data['motivo'] = $this->input->post('motivo');
    		    $data['obs'] = $this->input->post('obs');
    		    $this->session->unset_userdata('key_desinscrever_email');
    		    $return = $this->desinscreve($key, $data);
    		    if($return === true)
    		    {
    		        $data['form'] = false;
    		    }
    		}
    		
        }
        
        Template::set_message(validation_errors());
        Template::set_theme('newsletter');
    	Assets::add_module_css('newsletter',array(
				'styles-desinsc.css'
		));
		Assets::add_css(array(
    		    
		    ));
	    Assets::add_js(array(
				
		    ));
	    Assets::add_module_js('newsletter',array(
			
		));
    	
    	$data['action'] = base_url().'newsletter/desinscrever_email';
        $data['page_title'] = "View Brasil - Marketing Digital";
        
        Template::set($data);
	    Template::set_view('desinscrever_view');
	    Template::render();
    }
    
    public function feedback_email()
    {
        /*$link_redirect = 'http://blog.viewbrasil.com.br';
        $key = $this->session->key_desinscrever_email;
        //$key = "102be40b5c35be856a8665aa67679e9f7";//comentar
        if(!isset($key) || $key == NULL)
        {
            redirect($link_redirect);
        }
        $this->load->model('newsletter/newsletter_model');
        if($this->newsletter_model->verifica_cadastro($key) == 2)
        {
            redirect($link_redirect);
        }
        
        $this->load->library('form_validation');
        
        if ($this->input->post() == TRUE) 
        {
            $this->form_validation->set_rules('motivo', 'razão da sua desinscrição', 'required');
    		if($this->input->post('motivo') == "Outro")$this->form_validation->set_rules('obs', 'Texto', 'required|trim');
    		
    		if ($this->form_validation->run() != FALSE)
    		{
    		    $data['motivo'] = $this->input->post('motivo');
    		    $data['obs'] = $this->input->post('obs');
    		    $this->session->unset_userdata('key_desinscrever_email');
    		    $return = $this->desinscreve($key, $data);
    		    if($return === true)
    		    {
    		        $data['form'] = false;
    		    }
    		}
    		
        }*/
        
        /*Template::set_message(validation_errors());*/
        Template::set_theme('newsletter');
    	Assets::add_module_css('newsletter',array(
				'styles.css'
		));
		Assets::add_css(array(
    		    'remodal-default-theme.css',
    		    'remodal.css'
		    ));
	    Assets::add_js(array(
				'jquery-migrate-1.2.1.min.js',
				'jquery.backstretch.min.js',
				'scrollReveal.js',
				//'remodal.js',
		    ));
	    Assets::add_module_js('newsletter',array(
				//'custom.js',
		));
    	
    	$data['action'] = base_url().'newsletter/desinscrever_email';
        $data['page_title'] = "View Brasil - Marketing Digital de Sucesso";
        Template::set($data);
	    Template::set_view('feedback_view');
	    Template::render();
    }
    
    public function desinscreve($key, $data)
    {
        $link = ("http://blog.viewbrasil.com.br");
        $this->load->model('newsletter/newsletter_model');
        $id = $this->newsletter_model->confirma_key($key);
        if ($id != NULL) 
        {
            $i = $this->newsletter_model->verifica_cadastro($key);
            
            if ($i == 2) 
            {
                redirect($link);
                // "<p>Email Ja foi desinscrito</p>"
            } 
            else
            {
                if ($this->desativa_email($id, $key, $data)) 
                {
                    $r_act_membro = $this->delete_membro($id);
                    if ($r_act_membro == NULL) 
                    {
                        $this->newsletter_model->deletou_membro($id);
                    }
                    //"<p>Seu descadastrado foi ativado com sucesso.</p>";
                    return true;
                    //redirect($link);
                } 
                else
                {
                    redirect($link);
                    //"<p>Dados incorretos.</p>";
                }
            } 
        } 
        else
        {
            redirect($link);
            // "<p>Dados incorretos</p>";
        }
    }
   
    
    
    public function get_api_location_()
    {
        $ip = $this->input->ip_address();
        $data_location = get_api_location($ip);
        
        $data = array(
            'ip_address'          => $data_location['query'], 
            'country_code'          => $data_location['countryCode'], 
            'country'          => $data_location['country'], 
            'region_code'          => $data_location['region'], 
            'region'          => $data_location['regionName'], 
            'city'          => $data_location['city'], 
            'latitude'          => $data_location['lat'], 
            'longitude'          => $data_location['lon'], 
            'zip_code'          => $data_location['zip'], 
            'timezone'          => $data_location['timezone'], 
            'isp'          => $data_location['isp'], 
            'as'          => $data_location['as'] 
            );
        
        if(strcmp ( $data_location['status'] , 'success' ) === 0)
        {
            return $data;
        }
        else
        {
            return $data;
            //echo 'ip inválido';
        }
        
        /*if(!isset($_SERVER["HTTP_REFERER"]))
        {
            echo 'Direct Access';
        }
        else
        {
            echo '<br> '.$_SERVER["HTTP_REFERER"];
        }*/
        
    }
    
    
    
    function add_pending_membro($id_email) 
    {
        
        $result = $this->newsletter_model->get_email($id_email);
        // create a new cURL resource
        //$post = $this->input->post();
        $ch = curl_init();
        // set URL and other appropriate options
        curl_setopt($ch, CURLOPT_URL, "https://us13.api.mailchimp.com/3.0/lists/5f1750514a/members/" . md5($result->email));
        curl_setopt($ch, CURLOPT_USERPWD, "Authorization:2f7b5f3ecc8ef4835ad5a2d1fdaa0d0d-us13");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'content-type: application/json'
        ));
        
        $data = array(
            'email_address' => $result->email,
            'status' => 'pending',
            /*'merge_fields' => array(
                'FNAME' => $result->nome,
                'LNAME' => $result->sobrenome
            )*/
        );
        
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
        
        $data = json_encode($data);
        // return into variable if true
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        // debug if true
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        
        curl_setopt($ch, CURLOPT_HEADER, 1);
        // grab URL and pass it to the browser
        $response = curl_exec($ch);
        // Then, after your curl_exec call:
        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        $header = substr($response, 0, $header_size);
        $body = substr($response, $header_size);
        // close cURL resource, and free up system resources
        curl_close($ch);
    }
    //ver email de confirmação 1
    public function aedf00fba56c1f3d65() 
    {
        $key = $this->uri->segment(4);
        $data = array(
            'key_concat' => $key,
            'url' => base_url() . "newsletter/confirmacao/confirmacao/" . $key,
            'web' => true
        );
        
        $this->load->view('email-activate-html', $data);
    }
    //ver email de não confirmação 2
    public function bejhf96fb957c1gud65() 
    {
        $key = $this->uri->segment(4);
        $data = array(
            'key_concat' => $key,
            'url' => base_url() . "newsletter/confirmacao/confirmacao/" . $key,
            'web' => true
        );
        
        $this->load->view('email-nao-ativacao-html', $data);
    }
    //ver email da campanha
    public function dc52a5ada774d48be845b4() 
    {
        $key = $this->uri->segment(4);
        $log = $this->newsletter_model->select_log_email($key);
        $email = $this->newsletter_model->get_email_by_email($log->email);
        $campanha = $this->newsletter_model->get_campanha($log->id_campanha);
        
        $data = array(
            'email' => $email->email,
            'nome' => $email->nome,
            'sexo' => $email->sexo,
            'key_log' => $log->key_log,
            'key_concat' => $email->id . $email->activation_key ,
            'subject' => $campanha->subject,
            'view_html' => $campanha->view_html,
            'web' => true
        );
        $this->load->view('campanha/' . $campanha->view_html, $data);
    }
    
   
    
    public function activate_bk() 
    {
        $key = $this->uri->segment(4);
        $link = ("http://blog.viewbrasil.com.br");
        $id = $this->newsletter_model->confirma_key($key);
        if ($id != NULL) 
        {
            $status = $this->newsletter_model->verifica_cadastro($key);
            
            if ($status == 1) 
            {
                redirect($link);
                // "<p>Email Ja foi Confirmado</p>"
                
            } 
            elseif ($status == 0) 
            {
                if ($this->input->post()) 
                {
                    $post = $this->input->post();
                    $dados['nome'] = $post['nome'];
                    $dados['sobrenome'] = $post['sobrenome'];
                    $dados['sexo'] = $post['sexo'];
                    
                    if ($key == "29c44957ecdf19c639080d957b9e328b7") 
                    {
                        var_dump($dados);
                        //break;
                    }
                    
                    if ($this->activate_email($key, $dados)) 
                    {
                        $r_act_membro = $this->active_membro($id);
                        
                        if (isset($r_act_membro->status) && $r_act_membro->status == 'subscribed') 
                        {
                            $this->newsletter_model->adicionou_membro($id);
                        }
                        $this->enviar_email_campanha($id, 1);
                        $mensagem = "<p>Seu cadastro foi ativado com sucesso, e alguma mensagem aqui.</p>";
                        $data['mensagem'] = $mensagem;
                        $data['form'] = false;
                        redirect($link);
                    } 
                    else
                    {
                        redirect($link);
                        //"<p>Dados incorretos ou o link de ativação expirou.</p>";
                    }
                } 
                else
                {
                    $data['url'] = base_url() . "newsletter/newsletter/activate/" . $key;//viewbrasil/confirmacao
                    $data['form'] = true;
                }
            } 
            else
            {
                redirect($link);
                //"<p>Dados incorretos</p>";
            }
        } 
        else
        {
            redirect($link);
            // "<p>Dados incorretos</p>";
        }
        
        $this->load->view('viewbrasil/public_confirmacao_view', $data);
    }
    
    function activate_email($key, $dados) 
    {
        
        $result = $this->newsletter_model->activate_email_cadastro($key, $dados);
        return $result;
    }
    function desativa_email($id, $key, $dados) 
    {
        
        $result = $this->newsletter_model->desativa_email_cadastro($key, $dados);
        if($result)
        {
            $dados['id_email'] = $id;
            return $this->newsletter_model->insere_desinscricao($dados);
        }
        return $result;
    }
    
    //mailchimp
    public function active_membro($id_email) 
    {
        
        $result = $this->newsletter_model->get_email($id_email);
        // create a new cURL resource
        //$post = $this->input->post();
        $ch = curl_init();
        // set URL and other appropriate options
        curl_setopt($ch, CURLOPT_URL, "https://us13.api.mailchimp.com/3.0/lists/5f1750514a/members/" . md5($result->email));
        curl_setopt($ch, CURLOPT_USERPWD, "Authorization:2f7b5f3ecc8ef4835ad5a2d1fdaa0d0d-us13");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'content-type: application/json'
        ));
        
        $data = array(
            'email_address' => $result->email,
            'status' => 'subscribed',
            'merge_fields' => array(
                'FNAME' => $result->nome,
                'LNAME' => $result->sobrenome
            )
        );
        
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
        
        $data = json_encode($data);
        // return into variable if true
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        // debug if true
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        
        curl_setopt($ch, CURLOPT_HEADER, 1);
        // grab URL and pass it to the browser
        $response = curl_exec($ch);
        // Then, after your curl_exec call:
        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        $header = substr($response, 0, $header_size);
        $body = substr($response, $header_size);
        
        $resultado = json_decode($body);
        // close cURL resource, and free up system resources
        curl_close($ch);
        return $resultado;
    }
    
    //mailchimp
    function delete_membro($id_email) 
    {
        $result = $this->newsletter_model->get_email($id_email);
        // create a new cURL resource
        //$post = $this->input->post();
        $ch = curl_init();
        // set URL and other appropriate options
        curl_setopt($ch, CURLOPT_URL, "https://us13.api.mailchimp.com/3.0/lists/5f1750514a/members/". md5($result->email));
        curl_setopt($ch, CURLOPT_USERPWD, "Authorization:2f7b5f3ecc8ef4835ad5a2d1fdaa0d0d-us13");
        
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
        // return into variable if true
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        // debug if true
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        
        curl_setopt($ch, CURLOPT_HEADER, 1);
        // grab URL and pass it to the browser
        $response = curl_exec($ch);
        // Then, after your curl_exec call:
        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        $header = substr($response, 0, $header_size);
        $body = substr($response, $header_size);
        
        $resultado = json_decode($body);
        // close cURL resource, and free up system resources
        curl_close($ch);
        return $resultado;
    }
    
    
    
    function xenviar_email_campanha($id_email, $id_campanha) 
    {
        $r_log = $this->newsletter_model->verifica_log_email($id_email, $id_campanha);
        if ($r_log === false) 
        {
            $email = $this->newsletter_model->get_email($id_email);
            $campanha = $this->newsletter_model->get_campanha($id_campanha);
            /* echo "<pre>";
             var_dump($email->email, $campanha->id_campanha);*/
            
            $data = array(
                'email' => $email->email,
                'key_log' => md5($id_email . $id_campanha) ,
                'subject' => $campanha->subject,
                'view_html' => $campanha->view_html,
            );
            $rst_email = $this->_envia_email_campanha($data);
            //var_dump($rst_email);
            if ($rst_email === true) 
            {
                $this->enviou_email_campanha($id_email, $id_campanha, 1);
            } 
            else
            {
                
                $this->enviou_email_campanha($id_email, $id_campanha, 0);
            }
        }
    }
    
    function xenviou_email_campanha($id_email, $id_campanha, $st) 
    {
        //`id`, `id_email`, `id_campanha`, `enviado`, `abriu`, `clicou`, `enviado_em`
        $insert = array(
            'id_email' => $id_email,
            'id_campanha' => $id_campanha,
            'key_log' => md5($id_email . $id_campanha) ,
            'enviado' => $st,
            'enviado_em' => date('Y-m-d H:i:s') ,
        );
        $this->newsletter_model->insere_log($insert);
        if ($st == 1) 
        {
            $this->newsletter_model->enviou_campanha($id_campanha);
        } 
        else
        {
            $this->newsletter_model->falhou_campanha($id_campanha);
        }
    }
    
    public function x_envia_email_campanha($data) 
    {
         
        $this->load->library('email');
        $config['protocol'] = 'mail';
        $config['mailpath'] = '/usr/sbin/sendmail';
        $config['charset'] = 'utf-8';
        $config['wordwrap'] = TRUE;
         
        $this->load->library('email');
        $this->email->from('contato@viewbrasil.com.br', "View Brasil - Mkt Digital");
        $this->email->to($data['email']);
        $this->email->subject($data['subject']);
        $this->email->message($this->load->view('campanha/' . $data['view_html'], $data, TRUE));
         
        if ($this->email->send() === true) 
        {
            return true;
        } 
        else
        {
            return $this->email->print_debugger();
        }
    }
    
    
    
    //#####################################################################################################################################################
     
    function create_msg($id_campanha, $id_email) 
    {
        $ch = curl_init();
        //curl --request POST \
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        //--url 'https://usX.api.mailchimp.com/3.0/conversations/fa8c387539/messages' \
        curl_setopt($ch, CURLOPT_URL, "https://us13.api.mailchimp.com/3.0/conversations/7c42ee9771/messages");
        //--user 'anystring:apikey' \
        curl_setopt($ch, CURLOPT_USERPWD, "Authorization:2f7b5f3ecc8ef4835ad5a2d1fdaa0d0d-us13");
        //--header 'content-type: application/json' \
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'content-type: application/json'
        ));
         
        $data = array(
            'from_email' => 'urist.mcvankab@freddiesjokes.com',
            'read' => false,
            'message' => 'aaa',
        );
         
        $data = json_encode($data);
        // return into variable if true
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        // debug if true
        curl_setopt($ch, CURLOPT_VERBOSE, true);
         
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
         
        curl_setopt($ch, CURLOPT_HEADER, 1);
        // grab URL and pass it to the browser
        $response = curl_exec($ch);
        // Then, after your curl_exec call:
        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        $header = substr($response, 0, $header_size);
        $body = substr($response, $header_size);
         
        $result1 = json_decode($body);
        var_dump($result1);
    }
     
    function add_member() 
    {
        $id_email = 4;
         
        $result = $this->newsletter_model->get_email($id_email);
        // create a new cURL resource
        //$post = $this->input->post();
        $ch = curl_init();
        // set URL and other appropriate options
        curl_setopt($ch, CURLOPT_URL, "https://us13.api.mailchimp.com/3.0/lists/5f1750514a/members/" . md5($result->email));
        curl_setopt($ch, CURLOPT_USERPWD, "Authorization:2f7b5f3ecc8ef4835ad5a2d1fdaa0d0d-us13");
         
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'content-type: application/json'
        ));
         
        $data = array(
            'email_address' => $result->email,
            'status' => 'subscribed'
        );
         
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
         
        $data = json_encode($data);
        // return into variable if true
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        // debug if true
        curl_setopt($ch, CURLOPT_VERBOSE, true);
         
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
         
        curl_setopt($ch, CURLOPT_HEADER, 1);
        // grab URL and pass it to the browser
        $response = curl_exec($ch);
        // Then, after your curl_exec call:
        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        $header = substr($response, 0, $header_size);
        $body = substr($response, $header_size);
         
        $result1 = json_decode($body);
        var_dump($result1);
        //break; verificar depois - blog comdono
        die(); // no lugar do break acima
        var_dump($response);
        // var_dump($response); break;
         
        $result = json_decode($response);
        // close cURL resource, and free up system resources
        curl_close($ch);
    }
     
    function delete() 
    {
        $id_email = 6;
         
        $result = $this->newsletter_model->get_email($id_email);
        // create a new cURL resource
        //$post = $this->input->post();
        $ch = curl_init();
        // set URL and other appropriate options
        curl_setopt($ch, CURLOPT_URL, "https://us13.api.mailchimp.com/3.0/lists/5f1750514a/members/ce11fce876c93ed5d2a72da660496473");
        curl_setopt($ch, CURLOPT_USERPWD, "Authorization:2f7b5f3ecc8ef4835ad5a2d1fdaa0d0d-us13");
         
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
        // return into variable if true
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        // debug if true
        curl_setopt($ch, CURLOPT_VERBOSE, true);
         
        curl_setopt($ch, CURLOPT_HEADER, 1);
        // grab URL and pass it to the browser
        $response = curl_exec($ch);
        // Then, after your curl_exec call:
        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        $header = substr($response, 0, $header_size);
        $body = substr($response, $header_size);
         
        var_dump($response);
        //break; verificar depois - blog comdono
        die(); // no lugar do break acima
        $result1 = json_decode($response);
         
        var_dump($response);
        // var_dump($response); break;
         
        $result = json_decode($response);
        // close cURL resource, and free up system resources
        curl_close($ch);
    }
     
    function edit() 
    {
        $id_email = 6;
         
        $result = $this->newsletter_model->get_email($id_email);
        // create a new cURL resource
        //$post = $this->input->post();
        $ch = curl_init();
        // set URL and other appropriate options
        curl_setopt($ch, CURLOPT_URL, "https://us13.api.mailchimp.com/3.0/lists/5f1750514a/members/" . md5($result->email));
        curl_setopt($ch, CURLOPT_USERPWD, "Authorization:2f7b5f3ecc8ef4835ad5a2d1fdaa0d0d-us13");
         
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'content-type: application/json'
        ));
         
        $data = array(
            'status' => 'subscribed',
            'merge_fields' => array(
                'FNAME' => $result->nome,
                'LNAME' => $result->sobrenome
            )
        );
         
        $data = json_encode($data);
         
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        // grab URL and pass it to the browser
        $response = curl_exec($ch);
        $result = json_decode($response, true);
        // close cURL resource, and free up system resources
        curl_close($ch);
    }
     
    function list_members() 
    {
         
        $ch = curl_init();
        // set URL and other appropriate options
        curl_setopt($ch, CURLOPT_URL, "https://us13.api.mailchimp.com/3.0/lists/5f1750514a/members");
        curl_setopt($ch, CURLOPT_USERPWD, "Authorization:2f7b5f3ecc8ef4835ad5a2d1fdaa0d0d-us13");
        // curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
         
        // return into variable if true
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        // debug if true
        curl_setopt($ch, CURLOPT_VERBOSE, true);
         
        curl_setopt($ch, CURLOPT_HEADER, 1);
        // grab URL and pass it to the browser
        $response = curl_exec($ch);
        // Then, after your curl_exec call:
        $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
        $header = substr($response, 0, $header_size);
        $body = substr($response, $header_size);
         
        var_dump($response);
        //break; verificar depois - blog comdono
        die(); // no lugar do break acima
        $result1 = json_decode($response);
         
        var_dump($response);
        // var_dump($response); break;
         
        $result = json_decode($response);
        // close cURL resource, and free up system resources
        curl_close($ch);
    }
     
    function auth_info() 
    {
        // create a new cURL resource
        $ch = curl_init();
        // set URL and other appropriate options
        curl_setopt($ch, CURLOPT_URL, "https://us13.api.mailchimp.com/3.0/");
        curl_setopt($ch, CURLOPT_USERPWD, "Authorization:2f7b5f3ecc8ef4835ad5a2d1fdaa0d0d-us13");
        // Authorization: apikey 2f7b5f3ecc8ef4835ad5a2d1fdaa0d0d-us13
         
        // grab URL and pass it to the browser
        $response = curl_exec($ch);
         
        var_dump($response);
        // close cURL resource, and free up system resources
        curl_close($ch);
    }
     
    function create_list() 
    {
        // create a new cURL resource
        $ch = curl_init();
        // set URL and other appropriate options
        curl_setopt($ch, CURLOPT_URL, "https://us13.api.mailchimp.com/3.0/lists");
        curl_setopt($ch, CURLOPT_USERPWD, "Authorization:2f7b5f3ecc8ef4835ad5a2d1fdaa0d0d-us13");
         
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'content-type: application/json'
        ));
         
        $data = array(
            'name' => 'View Brasil',
            'contact' => array(
                'company' => 'MailChimp',
                'address1' => '675 Ponce De Leon Ave NE',
                "address2" => "Suite 5000",
                "city" => "Atlanta",
                "state" => "GA",
                "zip" => "30308",
                "country" => "US",
                "phone" => ""
            ) ,
            'permission_reminder' => 'Você está recebendo este e-mail porque se cadastrou na campanha.',
            'campaign_defaults' => array(
                'from_name' => 'View Brasil - Marketing Digital',
                'from_email' => 'contato@viewbrasil.com.br',
                'subject' => '',
                'language' => 'en'
            ) ,
            'email_type_option' => true
        );
         
        $data = json_encode($data);
         
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        // grab URL and pass it to the browser
        $response = curl_exec($ch);
         
        var_dump($response);
        // close cURL resource, and free up system resources
        curl_close($ch);
    }
     
    function create_lists_members() 
    {
        // create a new cURL resource
        //$post = $this->input->post();
        $ch = curl_init();
        // set URL and other appropriate options
        curl_setopt($ch, CURLOPT_URL, "https://us13.api.mailchimp.com/3.0/lists/5f1750514a/members");
        curl_setopt($ch, CURLOPT_USERPWD, "Authorization:2f7b5f3ecc8ef4835ad5a2d1fdaa0d0d-us13");
         
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'content-type: application/json'
        ));
         
        $data = array(
            'email_address' => 'ramon.marques@viewbrasil.com.br',
            'status' => 'subscribed',
            'merge_fields' => array(
                'FNAME' => 'Ramon'
            )
        );
         
        $data = json_encode($data);
         
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        // grab URL and pass it to the browser
        $response = curl_exec($ch);
        $result = json_decode($response, true);
        var_dump($result);
        // close cURL resource, and free up system resources
        curl_close($ch);
    }
     
    function create_campaign() 
    {
        // create a new cURL resource
         
        $ch = curl_init();
        // set URL and other appropriate options
        curl_setopt($ch, CURLOPT_URL, "https://us13.api.mailchimp.com/3.0/campaigns");
        curl_setopt($ch, CURLOPT_USERPWD, "Authorization:2f7b5f3ecc8ef4835ad5a2d1fdaa0d0d-us13");
         
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'content-type: application/json'
        ));
         
        $data = array(
            'recipients' => array(
                'list_id' => '382b150521',
            ) ,
            'type' => 'regular',
            'settings' => array(
                'subject_line' => 'O recibo de compra',
                'reply_to' => 'orders@mammothhouse.com',
                'from_name' => 'Serviço ao cliente',
            ) ,
        );
         
        $data = json_encode($data);
         
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        // grab URL and pass it to the browser
        $response = curl_exec($ch);
        $result = json_decode($response, true);
        var_dump($result);
        // close cURL resource, and free up system resources
        curl_close($ch);
    }
     
    function create_template() 
    {
        // create a new cURL resource
         
        $ch = curl_init();
        // set URL and other appropriate options
        curl_setopt($ch, CURLOPT_URL, "https://us13.api.mailchimp.com/3.0/templates");
        curl_setopt($ch, CURLOPT_USERPWD, "Authorization:2f7b5f3ecc8ef4835ad5a2d1fdaa0d0d-us13");
         
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'content-type: application/json'
        ));
         
        $data = $this->data_template;
        $data = json_encode($data);
         
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        // grab URL and pass it to the browser
        $response = curl_exec($ch);
        $result = json_decode($response, true);
        echo "<pre>";
        var_dump($result);
        // close cURL resource, and free up system resources
        curl_close($ch);
    }
     
    function create_template_folders() 
    {
        // create a new cURL resource
         
        $ch = curl_init();
        // set URL and other appropriate options
        curl_setopt($ch, CURLOPT_URL, "https://us13.api.mailchimp.com/3.0/template-folders");
        curl_setopt($ch, CURLOPT_USERPWD, "Authorization:2f7b5f3ecc8ef4835ad5a2d1fdaa0d0d-us13");
         
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'content-type: application/json'
        ));
         
        $data = array(
            'name' => 'O nome da pasta',
        );
         
        $data = json_encode($data);
         
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        // grab URL and pass it to the browser
        $response = curl_exec($ch);
        $result = json_decode($response, true);
        echo "<pre>";
        var_dump($result);
        // close cURL resource, and free up system resources
        curl_close($ch);
    }
     
    private $data_template = array(
        'name' => 'Test Template',
        'html' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html>
                <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                     
                    <meta property="og:title" content="*|MC:SUBJECT|*">
                     
                    <title>*|MC:SUBJECT|*</title>
                     
                <style type="text/css">
                    #outlook a{
                        padding:0;
                    }
                    body{
                        width:100% !important;
                    }
                    body{
                        -webkit-text-size-adjust:none;
                    }
                    body{
                        margin:0;
                        padding:0;
                    }
                    img{
                        border:none;
                        font-size:14px;
                        font-weight:bold;
                        height:auto;
                        line-height:100%;
                        outline:none;
                        text-decoration:none;
                        text-transform:capitalize;
                    }
                    #backgroundTable{
                        height:100% !important;
                        margin:0;
                        padding:0;
                        width:100% !important;
                    }
                    body,.backgroundTable{
                        background-color:#FAFAFA;
                    }
                    #templateContainer{
                        border:1px solid #DDDDDD;
                    }
                    h1,.h1{
                        color:#202020;
                        display:block;
                        font-family:Arial;
                        font-size:34px;
                        font-weight:bold;
                        line-height:100%;
                        margin-bottom:10px;
                        text-align:left;
                    }
                    h2,.h2{
                        color:#202020;
                        display:block;
                        font-family:Arial;
                        font-size:30px;
                        font-weight:bold;
                        line-height:100%;
                        margin-bottom:10px;
                        text-align:left;
                    }
                    h3,.h3{
                        color:#202020;
                        display:block;
                        font-family:Arial;
                        font-size:26px;
                        font-weight:bold;
                        line-height:100%;
                        margin-bottom:10px;
                        text-align:left;
                    }
                    h4,.h4{
                        color:#202020;
                        display:block;
                        font-family:Arial;
                        font-size:22px;
                        font-weight:bold;
                        line-height:100%;
                        margin-bottom:10px;
                        text-align:left;
                    }
                    #templatePreheader{
                        background-color:#FAFAFA;
                    }
                    .preheaderContent div{
                        color:#505050;
                        font-family:Arial;
                        font-size:10px;
                        line-height:100%;
                        text-align:left;
                    }
                    .preheaderContent div a:link,.preheaderContent div a:visited{
                        color:#336699;
                        font-weight:normal;
                        text-decoration:underline;
                    }
                    .preheaderContent div img{
                        height:auto;
                        max-width:600px;
                    }
                    #templateHeader{
                        background-color:#FFFFFF;
                        border-bottom:0;
                    }
                    .headerContent{
                        color:#202020;
                        font-family:Arial;
                        font-size:34px;
                        font-weight:bold;
                        line-height:100%;
                        padding:0;
                        text-align:center;
                        vertical-align:middle;
                    }
                    .headerContent a:link,.headerContent a:visited{
                        color:#336699;
                        font-weight:normal;
                        text-decoration:underline;
                    }
                    #headerImage{
                        height:auto;
                        max-width:600px !important;
                    }
                    #templateContainer,.bodyContent{
                        background-color:#FDFDFD;
                    }
                    .bodyContent div{
                        color:#505050;
                        font-family:Arial;
                        font-size:14px;
                        line-height:150%;
                        text-align:left;
                    }
                    .bodyContent div a:link,.bodyContent div a:visited{
                        color:#336699;
                        font-weight:normal;
                        text-decoration:underline;
                    }
                    .bodyContent img{
                        display:inline;
                        margin-bottom:10px;
                    }
                    #templateFooter{
                        background-color:#FDFDFD;
                        border-top:0;
                    }
                    .footerContent div{
                        color:#707070;
                        font-family:Arial;
                        font-size:12px;
                        line-height:125%;
                        text-align:left;
                    }
                    .footerContent div a:link,.footerContent div a:visited{
                        color:#336699;
                        font-weight:normal;
                        text-decoration:underline;
                    }
                    .footerContent img{
                        display:inline;
                    }
                    #social{
                        background-color:#FAFAFA;
                        border:1px solid #F5F5F5;
                    }
                    #social div{
                        text-align:center;
                    }
                    #utility{
                        background-color:#FDFDFD;
                        border-top:1px solid #F5F5F5;
                    }
                    #utility div{
                        text-align:center;
                    }
                    #monkeyRewards img{
                        max-width:160px;
                    }
            </style></head>
                <body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0" offset="0">
                    <center>
                        <table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%" id="backgroundTable">
                            <tr>
                                <td align="center" valign="top">
                                    <table border="0" cellpadding="10" cellspacing="0" width="600" id="templatePreheader">
                                        <tr>
                                            <td valign="top" class="preheaderContent">
                                             
                                                <table border="0" cellpadding="10" cellspacing="0" width="100%">
                                                    <tr>
                                                        <td valign="top">
                                                            <div mc:edit="std_preheader_content">
                                                                Use one or two sentences in this area to offer a teaser of your email content. Text here will show in a preview area in some email clients.
                                                            </div>
                                                        </td>
                                                        <td valign="top" width="180">
                                                            <div mc:edit="std_preheader_links">
                                                                <!-- *|IFNOT:ARCHIVE_PAGE|* -->Is this email not displaying correctly?<br><a href="*|ARCHIVE|*" target="_blank">View it in your browser</a>.<!-- *|END:IF|* -->
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                             
                                            </td>
                                        </tr>
                                    </table>
                                    <table border="0" cellpadding="0" cellspacing="0" width="600" id="templateContainer">
                                        <tr>
                                            <td align="center" valign="top">
                                                <table border="0" cellpadding="0" cellspacing="0" width="600" id="templateHeader">
                                                    <tr>
                                                        <td class="headerContent">
                                                         
                                                            <img src="http://gallery.mailchimp.com/653153ae841fd11de66ad181a/images/placeholder_600.gif" style="max-width:600px;" id="headerImage campaign-icon" mc:label="header_image" mc:edit="header_image" mc:allowdesigner="" mc:allowtext="">
                                                         
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="center" valign="top">
                                                <table border="0" cellpadding="10" cellspacing="0" width="600" id="templateBody">
                                                    <tr>
                                                        <td valign="top" class="bodyContent">
                                             
                                                            <table border="0" cellpadding="10" cellspacing="0" width="100%">
                                                                <tr>
                                                                    <td valign="top">
                                                                        <div mc:edit="std_content00">
                                                                            <span class="h1">Heading 1</span>
                                                                            <span class="h2">Heading 2</span>
                                                                            <span class="h3">Heading 3</span>
                                                                            <span class="h4">Heading 4</span>
                                                                            <strong>Getting started:</strong> Customize your template by clicking on the style editor tabs up above. Set your fonts, colors, and styles. After setting your styling is all done you can click here in this area, delete the text, and start adding your own awesome content.
                                                                            <br>
                                                                            <br>
                                                                            After you enter your content, highlight the text you want to style and select the options you set in the style editor in the "styles" drop down box. Want to <a href="http://www.mailchimp.com/kb/article/im-using-the-style-designer-and-i-cant-get-my-formatting-to-change" target="_blank">get rid of styling on a bit of text</a>, but having trouble doing it? Just use the "clear styles" button to strip the text of any formatting and reset your style.
                                                                        </div>
                                                                    </td>
                                                                </tr>
                                                            </table>                                              
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="center" valign="top">
                                                <table border="0" cellpadding="10" cellspacing="0" width="600" id="templateFooter">
                                                    <tr>
                                                        <td valign="top" class="footerContent">
                                                            <table border="0" cellpadding="10" cellspacing="0" width="100%">
                                                                <tr>
                                                                    <td colspan="2" valign="middle" id="social">
                                                                        <div mc:edit="std_social">
                                                                            &nbsp;<a href="*|TWITTER:PROFILEURL|*">follow on Twitter</a> | <a href="*|FACEBOOK:PROFILEURL|*">friend on Facebook</a> | <a href="*|FORWARD|*">forward to a friend</a>&nbsp;
                                                                        </div>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td valign="top" width="370">
                                                                        <br>
                                                                        <div mc:edit="std_footer">
                                                                            *|IF:LIST|*
                                                                            <em>Copyright &copy; *|CURRENT_YEAR|* *|LIST:COMPANY|*, All rights reserved.</em>
                                                                            <br>
                                                                            <!-- *|IFNOT:ARCHIVE_PAGE|* -->
                                                                            *|LIST:DESCRIPTION|*
                                                                            <br>
                                                                            <strong>Our mailing address is:</strong>
                                                                            <br>
                                                                            *|HTML:LIST_ADDRESS_HTML|*
                                                                            <br>
                                                                            <!-- *|END:IF|* -->
                                                                            *|ELSE:|*
                                                                            <!-- *|IFNOT:ARCHIVE_PAGE|* -->
                                                                            <em>Copyright &copy; *|CURRENT_YEAR|* *|USER:COMPANY|*, All rights reserved.</em>
                                                                            <br>
                                                                            <strong>Our mailing address is:</strong>
                                                                            <br>
                                                                            *|USER:ADDRESS_HTML|*
                                                                            <!-- *|END:IF|* -->
                                                                            *|END:IF|*
                                                                        </div>
                                                                        <br>
                                                                    </td>
                                                                    <td valign="top" width="170" id="monkeyRewards">
                                                                        <br>
                                                                        <div mc:edit="monkeyrewards">
                                                                            *|IF:REWARDS|* *|HTML:REWARDS|* *|END:IF|*
                                                                        </div>
                                                                        <br>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td colspan="2" valign="middle" id="utility">
                                                                        <div mc:edit="std_utility">
                                                                            &nbsp;<a href="*|UNSUB|*">unsubscribe from this list</a> | <a href="*|UPDATE_PROFILE|*">update subscription preferences</a><!-- *|IFNOT:ARCHIVE_PAGE|* --> | <a href="*|ARCHIVE|*">view email in browser</a><!-- *|END:IF|* -->&nbsp;
                                                                        </div>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                         
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                    </table>
                                    <br>
                                </td>
                            </tr>
                        </table>
                    </center>
                </body>
            </html>',
    );
}