<?php
class EmailForm extends Controller {

   function EmailForm(){
      parent::Controller();
	  //session_start();
	$this->lang->load('public');
   }

	function index() {
		$ld=$this->session->userdata('lang_id');
	  	# Validations
		//echo $ld;
	  	$this->load->library('validation');
		$this->validation->set_error_delimiters('<div class="warning">', '</div>');
	  	//$data['cats'] = $this->MCats->getTopCategories();
		//$data['pages'] = $this->MPages->getAllPages();
		$data['title'] = $this->lang->line('page_contact');
		$data['header'] = 'header';
	  	$rules['name'] = "trim|required|min_length[5]|xss_clean";
	  	$rules['email'] = "trim|required|valid_email";
		$rules['comments']="required";
		$this->validation->set_rules($rules);
	  	
	  	$fields['name']	= 'Full Name';
		$fields['email']	= 'Email';
		$fields['comments']	= 'Comments';
		$this->validation->set_fields($fields);
		
		# Input and textarea field attributes
		
		$data["name"] = array('name' => 'name', 'id' => 'name', 'size' => '40' );
		$data['email'] = array('name' => 'email', 'id' => 'email', 'size' => '40');
		$data['comments'] = array('name' => 'comments', 'id' => 'comments', 'rows' => 10, 'cols' => 40);
		$data['page_path']= 'contact_us';
		$data['header']='header';
		$data['main']='emailform';
		# Checkbox attributes
	//	$data['purpose'] = array('name' => 'seminar[]', 'id' => 'purpose', 'value' => 'Purpose of Prayer', 'checked' => FALSE);
	//	$data['prepare'] = array('name' => 'seminar[]', 'id' => 'prepare', 'value' => 'Prepare for Prayer', 'checked' => FALSE);
	//	$data['principles'] = array('name' => 'seminar[]', 'id' => 'principles', 'value' => 'Principles of Prayer', 'checked' => FALSE);
	//	$data['power'] = array('name' => 'seminar[]', 'id' => 'power', 'value' => 'Power in Prayer', 'checked' => FALSE);
		
		
		if ($this->validation->run() == FALSE)
		{
			$this->load->view('template', $data);
		}else{
			$this->load->helper('typography');
			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);
		
			$name = $this->input->post('name');
			$email = $this->input->post('email');
			$comments = $this->input->post('comments');
			$comments=auto_typography($comments);
	
			$data['comments'] = $comments;
	
			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);

			//$message = $comments;
			
			#Email send to the company!
			//$this->email->from($email, $name);
			$this->email->from('no-reply@nkepa.gr', 'www.nkepa.gr'.$email.", ".$name);
			$this->email->to('info@nkepa.gr', 'www.NKepa.gr');
			$this->email->subject($this->lang->line('email_subject'));
			//$this->email->message($comments);
			$this->email->message($emsg);	
			$this->email->send();
			
			#Email send to the user
			$this->email->from('no-reply@nkepa.gr', 'www.nkepa.gr');
			$this->email->to($email);
			$this->email->subject($this->lang->line('page_contact'));
			//$message=$this->lang->line('contact_email_message');
			//$message .="<br /><br />".$comments."<br /><br />";
			//$message .=$comments;
			//$message .="\n\n";
			$this->email->message($emsg);
			//$message .=$this->lang->line('contact_email_post_message');
			//$this->email->message($message);
			$this->email->send();
			
			redirect('contact','refresh');
			
		}	
	}
}	

?>