<?php  

class Mailing extends CI_Controller {

	function __construct(){
	  parent::__construct();
          
        }
        public  function index()
	{
            $this->db->distinct();
            $result = $this->db->get('test_prefixt1')->result_array();
            $this->db->truncate('test_prefixt1');
            foreach ($result as $r){
                $this->db->set('Field1',$r);
                $this->db->insert('test_prefixt1');                
            }
            
	}
        /**
         * This function save the mail in database
         */
        public  function send()
	{
            $this->form_validation->set_error_delimiters("<span class='incorrect'>", "</span>");
            $this->form_validation->set_rules('TxtEmailingList', 'البريد الالكتروني', 'trim|required|xss_clean|htmlspecialchars|valid_email');
            if($this->form_validation->run()== false){                
               $this->view('site/mailinglist');
            }elseif($this->check_email()){
                $data['msg'] = "هذا الإيميل مسجل لدينا من قبل";
                $this->view('site/mailinglist', $data);
            }else{
            $this->mailinglist->send();
            $data['msg'] = "تم إرسال بريدك الالكتروني بنجاح";
            $this->view('theme/msg', $data);
            }
        }
        
        function check_email()
        {
            $u_email = $this->input->post('TxtEmailingList');
            $check_email = $this->mailinglist->check_email($u_email);
            if($check_email != NULL){               
                return TRUE;  
                //echo "ahmed";
            }else{
                return FALSE;
                //echo "alaa";
            }

        }
}
/* End of file dashboard.php */
/* Location: ./system/application/modules/matchbox/controllers/dashboard.php */