<?php
class Ecv extends Controller {

   function Ecv(){
      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('cv_form_title');
		//$data['header'] = 'header';
	  	$rules['name'] = "trim|min_length[5]|xss_clean";
		$rules['last_name'] = "trim|min_length[5]|xss_clean";
		//$rules['father_name'] = "trim|required|min_length[5]|xss_clean";
		$rules['date_of_birth']="";
		$rules['work']="required";
		$rules['tel']="";
		$rules['mob_tel']="";
	  	$rules['email'] = "trim|valid_email";
		$rules['marital_status'] = "trim|required|min_length[5]|xss_clean";
		$rules['military'] = "trim|required|min_length[5]|xss_clean";

		$rules['address']="";
		$rules['city']="";
		$rules['postal']="";
		$rules['education']="required";
		$rules['other_education']="required";
		$rules['other_info']="";

		$rules['languages']="required";
		
		$this->validation->set_rules($rules);
	  	
	  	$fields['name']	= $this->lang->line('cv_form_name');
		$fields['last_name']	= $this->lang->line('cv_form_last_name');
		$fields['date_of_birth']	= $this->lang->line('cv_form_date_of_birth');
		$fields['work']	= $this->lang->line('cv_form_work');
		$fields['tel']	= $this->lang->line('cv_form_tel');
		$fields['mob_tel']	= $this->lang->line('cv_form_mob_tel');
		$fields['email']	= $this->lang->line('cv_form_email');
		$fields['marital_status']	= $this->lang->line('cv_form_marital_status');
		$fields['military']	= $this->lang->line('cv_form_military');

		$fields['address']	= $this->lang->line('cv_form_address');
		$fields['city']	= $this->lang->line('cv_form_city');
		$fields['postal']	= $this->lang->line('cv_form_postal');
		$fields['education']	= $this->lang->line('cv_form_education');
		$fields['other_education']	= $this->lang->line('cv_form_other_education');
		$fields['other_info']	= $this->lang->line('cv_form_other_info');

		$fields['languages']	= $this->lang->line('cv_form_languages');
		$this->validation->set_fields($fields);
		
		# Input and textarea field attributes
		
		$data["name"] = array('name' => 'name', 'id' => 'name');
		$data["last_name"] = array('name' => 'last_name', 'id' => 'last_name');
		$data["date_of_birth"] = array('name' => 'date_of_birth', 'id' => 'date_of_birth');
		$data["tel"] = array('name' => 'tel', 'id' => 'tel');
		$data["mob_tel"] = array('name' => 'mob_tel', 'id' => 'mob_tel');
		$data['email'] = array('name' => 'email', 'id' => 'email');
		$data["marital_status"] = array('name' => 'marital_status', 'id' => 'marital_status');
		$data["military"] = array('name' => 'military', 'id' => 'military');

		$data['address'] = array('name' => 'address', 'id' => 'address');
		$data['city'] = array('name' => 'city', 'id' => 'city');
		$data['postal'] = array('name' => 'postal', 'id' => 'postal');
		$data['education'] = array('name' => 'education', 'id' => 'education', 'rows' => 10, 'cols' => 40);
		$data['other_education'] = array('name' => 'other_education', 'id' => 'other_education', 'rows' => 10, 'cols' => 40);
		$data['other_info'] = array('name' => 'other_info', 'id' => 'other_info', 'rows' => 10, 'cols' => 40);

		$data['work'] = array('name' => 'work', 'id' => 'work', 'rows' => 10, 'cols' => 40);

		$data['languages'] = array('name' => 'languages', 'id' => 'languages', 'rows' => 10, 'cols' => 40);
		$data['page_path']= 'contact_us';
		$data['header']='header';
		$data['main']='upload_cv';
		# 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');
			
			$name = $this->input->post('name');
			$last_name = $this->input->post('last_name');
			$date_of_birth = $this->input->post('date_of_birth');
			$work = $this->input->post('work');
			$tel = $this->input->post('tel');
			$mob_tel = $this->input->post('mob_tel');
			$email = $this->input->post('email');
			$marital_status= $this->input->post('marital_status');
			$military= $this->input->post('military');
			$address = $this->input->post('address');
			$city = $this->input->post('city');
			$postal = $this->input->post('postal');
			$education = $this->input->post('education');
			$other_education = $this->input->post('other_education');
			$other_info = $this->input->post('other_info');

			$languages = $this->input->post('languages');
			//$message = $comments;
			
		$fields['name']	= $this->lang->line('cv_form_name');
		$fields['last_name']	= $this->lang->line('cv_form_last_name');
		$fields['date_of_birth']	= $this->lang->line('cv_form_date_of_birth');
		$fields['work']	= $this->lang->line('cv_form_work');
		$fields['tel']	= $this->lang->line('cv_form_tel');
		$fields['mob_tel']	= $this->lang->line('cv_form_mob_tel');
		$fields['email']	= $this->lang->line('cv_form_email');
		$fields['marital_status']	= $this->lang->line('cv_form_marital_status');
		$fields['military']	= $this->lang->line('cv_form_military');

		$fields['address']	= $this->lang->line('cv_form_address');
		$fields['city']	= $this->lang->line('cv_form_city');
		$fields['postal']	= $this->lang->line('cv_form_postal');
		$fields['education']	= $this->lang->line('cv_form_education');
		
		$fields['other_education']	= $this->lang->line('cv_form_other_education');
		$fields['other_info']	= $this->lang->line('cv_form_other_info');

		$fields['languages']	= $this->lang->line('cv_form_languages');
			$data['name']=$name;
			$data['last_name']=$last_name;
			$data['date_of_birth']=$date_of_birth;
			$data['work']=$work;
			$data['tel']=$tel;
			$data['mob_tel']=$mob_tel;
			$data['email']=$email;
			$data['marital_status']=$marital_status;
			$data['military']=$military;
			$data['address']=$address;
			$data['city']=$city;
			$data['postal']=$postal;
			$data['education']=$education;
			$data['other_education']=$other_education;
			$data['other_info']=$other_info;
			$data['languages']=$languages;
			
			$this->load->library('parser');
			$emsg = $this->parser->parse('template_cv', $data, TRUE);
			
			#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('cv@nkepa.gr', 'www.NKepa.gr');
			$this->email->subject($this->lang->line('cv_email_subject'));
			
//			$comp_message = $this->lang->line('cv_intro_subject');
//			$comp_message .= "\n\n<br /><br />";
//			$comp_message .= $this->lang->line('cv_form_personal_data');
//			$comp_message .= "\n<br />";
//			$comp_message .= $this->lang->line('cv_form_name');
//			$comp_message .= ": ".$name."\n<br />";
//			$comp_message .= $this->lang->line('cv_form_last_name');
//			$comp_message .= ": ".$last_name."\n<br />";
//			$comp_message .= $this->lang->line('cv_form_date_of_birth');
//			$comp_message .= ": ".$date_of_birth."\n<br />";
//			$comp_message .= $this->lang->line('cv_form_address_data');
//			$comp_message .= "\n<br />";
//			$comp_message .= $this->lang->line('cv_form_address');
//			$comp_message .= ": ".$address."\n<br />";
//			$comp_message .= $this->lang->line('cv_form_city');
//			$comp_message .= ": ".$city."\n<br />";
//			$comp_message .= $this->lang->line('cv_form_postal');
//			$comp_message .= ": ".$postal."\n<br />";
//			$comp_message .= $this->lang->line('cv_form_tel');
//			$comp_message .= ": ".$tel."\n<br />";
//			$comp_message .= $this->lang->line('cv_form_mob_tel');
//			$comp_message .= ": ".$mob_tel."\n<br />";
//			$comp_message .= $this->lang->line('cv_form_email');
//			$comp_message .= ": ".$email."\n<br />";
//			$comp_message .= "\n<br />";
//			$comp_message .= $this->lang->line('cv_form_marital_status');
//			$comp_message .= ": ".$marital_status."\n<br />";
//			$comp_message .= "\n<br />";
//			$comp_message .= $this->lang->line('cv_form_military');
//			$comp_message .= ": ".$military."\n<br />";
//			$comp_message .= "\n<br />";
//			$comp_message .= $this->lang->line('cv_form_education');
//			$comp_message .= "\n<br />";
//			$comp_message .= $this->lang->line('cv_form_education_data');
//			$comp_message .= "\n<br />";
//			$comp_message .= ": ".$education."\n<br />";
//			$comp_message .= $this->lang->line('cv_form_other_education');
//			$comp_message .= ": ".$other_education."\n<br />";
//			$comp_message .= "\n<br />";
//			$comp_message .= $this->lang->line('cv_form_languages');
//			$comp_message .= ": ".$languages."\n<br />";
//			$comp_message .= "\n<br />";
//			$comp_message .= $this->lang->line('cv_form_work');
//			$comp_message .= ": ".$work."\n<br />";
//			$comp_message .= "\n<br />";
//			$comp_message .= $this->lang->line('cv_form_other_info');
//			$comp_message .= ": ".$other_info."\n<br />";
			//$this->email->message($comp_message);
			$this->email->message($emsg);		
			$this->email->send();
			
			#Email send to the user
			//$this->email->from('cv@nkepa.gr', 'www.NKepa.gr');
			$this->email->from('no-reply@nkepa.gr', 'www.nkepa.gr');
			$this->email->to($email);
			$this->email->subject($this->lang->line('cv_email_subject'));
//			$message=$this->lang->line('contact_email_message');
//			$message = $this->lang->line('cv_intro_subject');
//			$message .= "\n\n<br /><br />";
//			$message .= $this->lang->line('cv_form_personal_data');
//			$message .= "\n<br />";
//			$message .= $this->lang->line('cv_form_name');
//			$message .= ": ".$name."\n<br />";
//			$message .= $this->lang->line('cv_form_last_name');
//			$message .= ": ".$last_name."\n<br />";
//			$message .= $this->lang->line('cv_form_date_of_birth');
//			$message .= ": ".$date_of_birth."\n<br />";
//			$message .= $this->lang->line('cv_form_address_data');
//			$message .= "\n<br />";
//			$message .= $this->lang->line('cv_form_address');
//			$message .= ": ".$address."\n<br />";
//			$message .= $this->lang->line('cv_form_city');
//			$message .= ": ".$city."\n<br />";
//			$message .= $this->lang->line('cv_form_postal');
//			$message .= ": ".$postal."\n<br />";
//			$message .= $this->lang->line('cv_form_tel');
//			$message .= ": ".$tel."\n<br />";
//			$message .= $this->lang->line('cv_form_mob_tel');
//			$message .= ": ".$mob_tel."\n<br />";
//			$message .= $this->lang->line('cv_form_email');
//			$message .= ": ".$email."\n<br />";
//			$message .= "\n<br />";
//			$message .= $this->lang->line('cv_form_marital_status');
//			$message .= ": ".$marital_status."\n<br />";
//			$message .= "\n<br />";
//			$message .= $this->lang->line('cv_form_military');
//			$message .= ": ".$military."\n<br />";
//			$message .= $this->lang->line('cv_form_education');
//			$message .= "\n<br />";
//			$message .= $this->lang->line('cv_form_education_data');
//			$message .= "\n<br />";
//			$message .= ": ".$education."\n<br />";
//			$message .= $this->lang->line('cv_form_other_education');
//			$message .= ": ".$other_education."\n<br />";
//			$message .= "\n<br />";
//			$message .= $this->lang->line('cv_form_languages');
//			$message .= ": ".$languages."\n<br />";
//			$message .= "\n<br />";
//			$message .= $this->lang->line('cv_form_work');
//			$message .= ": ".$work."\n<br />";
//			$message .= "\n<br />";
//			$message .= $this->lang->line('cv_form_other_info');
//			$message .= ": ".$other_info."\n<br />";
//
//			$message .=$this->lang->line('cv_post_message');
//			$this->email->message($message);
			$this->email->message($emsg);		
			$this->email->send();
			
			redirect('send','refresh');
			
		}	
	}
}	

?>