<?php

class Page extends Controller {
  function Page(){
    parent::Controller();
	$this->output->enable_profiler(FALSE); 
    session_start();
	$this->lang->load('public');
		#check to see if the default lang_id exists, and if not set it
	if($this->session->userdata('lang_id')==null){
		$ld='1';
		$this->session->set_userdata('lang_id',$ld);
		//echo $ld;
	}else{
		$ld=$this->session->userdata('lang_id');
	}
	
  }

  function index(){
	//$data['page_id'] = $this->MPages->getPage(16);
	//$data['data'] = $this->MCats->getTopCategories();
	//$data['pages'] = $this->MPages->getAllPages();
//	$data['title'] = $this->lang->line('page_home');
//	$data['header'] = 'header';
//	$data['main'] = 'public_home';
//	$this->load->vars($data);
//	$this->load->view('template');
redirect("/languages/changelg/gr", 'refresh');
//redirect("page/navigation/index",'refresh');
	  
  
  }
  function navigation($path){
  if($this->session->userdata('lang_id')==null){
		$ld='1';
		$this->session->set_userdata('lang_id',$ld);
		//echo $ld;
	}else{
		$ld=$this->session->userdata('lang_id');
	}
  	$data['page_path']= $path;
 	$ld=$this->session->userdata('lang_id');
  	$data['page'] = $this->MPages->getPageid($path);
	$page_id=$data['page']['id'];
	$data['page_title']=$this->MPages->getPageTitle($page_id, $ld);
	$data['data'] = $this->MPages->getAllContent($page_id, $ld);
	$data['page_prjtitle']=$this->MPages->getPrjTitle($page_id, $ld);
	//$data['projects']=$this->MPages->getProjects($page_id, $ld);
	$data['title'] = $this->lang->line('page_home');
	//$data['header'] = 'header';
	if ($path == 'clients'){
	$data['client_cat']=$this->MPages->getAllClientsCategory($ld);
	$data['main']='page_clients';
	}
	elseif (($path == 'index') || ($path == 'profile')){
	//$data['client_cat']=$this->MPages->getAllClientsCategory($ld);
	$data['main']='page_home';
	}
	else{
	$data['main'] = 'page';
	}
	$data['header']='header';
	$this->load->vars($data);
	$this->load->view('template');  
	
  }
  	function thankyou(){
	$ld=$this->session->userdata('lang_id');
	$data['title'] = $this->lang->line('page_thankyou');
	$data['page_path']= '';
	$data['header']='header';
	$data['main'] = 'thankyou';
	$this->load->vars($data);
	$this->load->view('template');
	}
	function cvthankyou(){
	$ld=$this->session->userdata('lang_id');
	$data['page_path']= '';
	$data['title'] = $this->lang->line('page_thankyou');
	$data['header']='header';
	$data['main'] = 'cvthankyou';
	$this->load->vars($data);
	$this->load->view('template');
	}

  function post($id){
	$data['post'] = $this->MPosts->getPost($id);
	$data['comments'] = $this->MComments->getComments($id);
	$data['cats'] = $this->MCats->getTopCategories();
	//$data['pages'] = $this->MPages->getAllPages();
	$data['title'] = $data['post']['title'];
	$data['header']='header';
	$data['main'] = 'public_post';
	$this->load->vars($data);
	$this->load->view('template');  
  
  }

	function pages($path){
		$data['page']=$this->MPages->getPagePath($path);
		//print_r($page);
		//$data['pages'] = $this->MPages->getAllPages();
		$data['cats'] = $this->MCats->getTopCategories();
		$data['title'] = $data['page']['name'];
		$data['header'] = $data['page']['header_bg'];
		$data['main'] = 'page';
		$this->load->vars($data);
		$this->load->view('template');
  	}
  
  function category($id){
	$data['category'] = $this->MCats->getCategory($id);
	$data['posts'] = $this->MPosts->getAllPostsByCategory($id);
	$data['cats'] = $this->MCats->getTopCategories();
	//$data['pages'] = $this->MPages->getAllPages();
	$data['title'] = $data['category']['name'];
	$data['header'] = $data['category']['header_bg'];
	$data['main'] = 'news_home';
	$this->load->vars($data);
	$this->load->view('template');  
  
  }

	
	function ethankyou(){
	#check to see if the default lang_id exists, and if not set it
	//if($this->session->userdata('lang_id')==null){
	//	$ld='2';
	//	$this->session->set_userdata('lang_id',$ld);
		//echo $ld;
	//}else{
	//	$ld=$this->session->userdata('lang_id');
	//}
  	$data['cats'] = $this->MCats->getTopCategories();
	//$data['pages'] = $this->MPages->getAllPages();
	$data['title'] = "ThinkGlass - eNewsletter";
	$data['header'] = 'header_newsletter';
	$data['main'] = 'ethankyou';
	$this->load->vars($data);
	$this->load->view('template');
	}
  
  
  function addcomment(){
  	if ($this->input->post('body')){
  		$this->MComments->addComment();
  	}
  	
  	redirect('page/post/'.$this->input->post('post_id'), 'refresh');
  
  }
  
  function login(){
	//$data['cats'] = $this->MCats->getTopCategories();
	$data['title'] = "Login to the Dashboard";
	//$data['header'] = 'header';
	$data['page_path']= '';
	
	$data['main'] = 'public_login';
	$data['header']='header';
	$this->load->vars($data);
	$this->load->view('template');  
  
  }
    function newsletter(){
	//$data['cats'] = $this->MCats->getTopCategories();
	$data['title'] = "N/Kepa";
	//$data['header'] = 'header';
	$data['page_path']= '';
	
	//$data['main'] = 'public_login';
	//$data['header']='header';
	$this->load->vars($data);
	$this->load->view('template_cv');  
  
  }

  function verify(){
  	$this->load->library('encrypt');
	if ($this->input->post('username')){
		$u = $this->input->post('username');
		$pw = $this->input->post('password');
		$row = $this->MAdmins->verifyUser($u,$pw);
		if (count($row)){
			$_SESSION['userid'] = $row['id'];
			redirect('admin/dashboard','refresh');
		}else{
			redirect('admin','refresh');
		}
	}else{
		redirect('admin','refresh');
	}  
   
  }
	function upload_file(){
		//$id = $this->uri->segment(3);
		//if($this->input->post('email_un')){
		$data['page_path']= '';
		$name = $this->input->post('name');
		$cv = $this->input->post('cv');
		$email = $this->input->post('email');
		if($name==''){
			$ld=$this->session->userdata('lang_id');
			$data['title'] = $this->lang->line('page_cv');
			$data['header']='header';
			$data['main'] = 'reject';
			$this->load->vars($data);
			$this->load->view('template');
		}else{
			//$this->MPages->UploadCV();
					#Email send to the company!
					$config['upload_path'] = './cv/';
			$config['allowed_types'] = 'doc|pdf|docx|txt|odt';
			$config['max_size'] = '1000';
			$config['remove_spaces'] = true;
			$config['overwrite'] = true;
			$config['max_width'] = '0';
			$config['max_height'] = '0';
			
			$this->load->library('upload', $config);
			
			if(!$this->upload->do_upload('cv')){
			$this->upload->display_errors();
			exit();
			}
			$cv = $this->upload->data();
			if ($cv['file_name']){
			$data['cv'] = "/cv/".$cv['file_name'];
			}
			//$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 = $name."\n\n<br />";
			$this->email->message($comp_message);
			$this->email->attach('/home/getidbiz/public_html/nkepa/cv/'.$cv['file_name']);
			$this->email->send();
			
			#Email send to the user
			$this->email->from('no-reply@nkepa.gr', 'www.nkepa.gr');
			//$this->email->from('cv@nkepa.gr', 'www.NKepa.gr');
			$this->email->to($email);
			$this->email->subject($this->lang->line('cv_email_subject'));
			$message=$this->lang->line('contact_cvemail_message');
			$message .= "\n\n<br /><br />";
			$this->email->message($message);
			
			$this->email->send();
//			
//			redirect('page/cvthankyou','refresh');

		
		

         #complete serverpath must be given like
         #example "/apache/htdocs/myfile.pdf" ( not "http:xyz.com/myfile.pdf" )
         $DelFilePath = '/home/getidbiz/public_html/nkepa/cv/'.$cv['file_name'];
         # delete file if exists
         if (file_exists($DelFilePath)) { unlink ($DelFilePath); }


				//$check=$this->MSubscribers->checkSubscriber($email);
				//$this->MSubscribers->removeSubscriber($email);
			$ld=$this->session->userdata('lang_id');
			$data['title'] = $this->lang->line('page_cv');
			$data['header']='header';
			$data['main'] = 'cvthankyou';
			$this->load->vars($data);
			$this->load->view('template');
			}

//		}
		//}else{
		//	$this->session->set_flashdata('subscribe_msg',"You didn't fill out the email address");
		//	redirect('page/index','refresh');
		//}
  	}
	
  
  
}//end controller class

?>