<?php

class Page extends Controller {
      
   function Page(){
    parent::Controller();
 	$this->output->enable_profiler(FALSE); 
	session_start();
	$this->load->library('session');
    $this->load->library('cart');
		if($this->session->userdata('lang_id')==null){
			$ld='1';
			$this->session->set_userdata('lang_id',$ld);
			$this->lang->load('public', 'greek');
			$config['lang_selected'] = 'gr';
			$this->lang_detect->changeLang('gr');
			//redirect($this->uri->uri_string());
			//echo $ld;
		}else{
		
		if($this->session->userdata('lang_id')=='1') {
			$ld='1';
			$this->session->set_userdata('lang_id',$ld);
			$this->lang->load('public', 'greek');
			$config['lang_selected'] = 'gr';
			$this->lang_detect->changeLang('gr');
			}
			elseif ($this->session->userdata('lang_id')=='2') {
			$ld='2';
			$this->session->set_userdata('lang_id',$ld);
			$this->lang->load('public', 'english');
			$config['lang_selected'] = 'en';
			$this->lang_detect->changeLang('en');
			}
		}
		
	}
	
   	function index(){
	 //redirect("/languages/changelg/gr", 'refresh');
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['content'] = $this->MFuncs->getPage('home', $ld);
		$data['products'] = $this->MFuncs->getRandProducts();
		$data['fproducts'] = $this->MFuncs->getRandForeignProducts();
		$data['ofproducts'] = $this->MFuncs->getRandOfferProducts(9);
		$data['title'] = $this->lang->line('links_home');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['category_id'] = '';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'home_new2';
		$this->load->vars($data);
		$this->load->view('template_master');
	}

	function home(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['content'] = $this->MFuncs->getPage('home', $ld);
		$data['products'] = $this->MFuncs->getRandProducts();
		$data['fproducts'] = $this->MFuncs->getRandForeignProducts();
		$data['ofproducts'] = $this->MFuncs->getRandOfferProducts(9);
		$data['title'] = $this->lang->line('links_home');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['category_id'] = '';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'home_new2';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function home_new(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['content'] = $this->MFuncs->getPage('home', $ld);
		$data['products'] = $this->MFuncs->getRandProducts();
		$data['fproducts'] = $this->MFuncs->getRandForeignProducts();
		$data['ofproducts'] = $this->MFuncs->getRandOfferProducts(9);
		$data['title'] = $this->lang->line('links_home');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['category_id'] = '';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'home';
		$this->load->vars($data);
		$this->load->view('template_master_new');
	}
	function home_new2(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['content'] = $this->MFuncs->getPage('home', $ld);
		$data['products'] = $this->MFuncs->getRandProducts();
		$data['fproducts'] = $this->MFuncs->getRandForeignProducts();
		$data['ofproducts'] = $this->MFuncs->getRandOfferProducts(9);
		$data['title'] = $this->lang->line('links_home');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['category_id'] = '';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'home_new2';
		$this->load->vars($data);
		$this->load->view('template_master_new2');
	}
	function update_prds_weight($cat_id){
		$products = $this->MFuncs->getProductsbyCatall($cat_id);
    	foreach($products as $result=>$prd):
		$this->MFuncs->updateProductPrice($prd['id']);
		endforeach;
		echo 'DONE!';
	}
	function update_prds_weight_bysubcat($subcat_id){
		$products = $this->MFuncs->getProductsbySubCatall($subcat_id);
    	foreach($products as $result=>$prd):
		$this->MFuncs->updateProductPrice($prd['id']);
		endforeach;
		echo 'DONE!';
	}
	function test(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['content'] = $this->MFuncs->getPage('home', $ld);
		$data['products'] = $this->MFuncs->getRandProducts();
		$data['title'] = $this->lang->line('links_home');
		$data['left_nav'] = 'left_nav_3';
		$data['right_nav'] = 'right_nav';
		$data['category_id'] = '';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'home';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function variety($var_id){
		$ld=$this->session->userdata('lang_id');
		$data['content'] = $this->MFuncs->getVariety($var_id, $ld);
		$data['title'] = $data['content']['name'];
		$this->load->vars($data);
		$this->load->view('template_popup');
	}
	function pages($key){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['content'] = $this->MFuncs->getPage($key, $ld);
		if (!$data['content']) {
			redirect('main', 'refresh');
		} else {
		$data['title'] = $data['content']['title'];
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'pages';
		$this->load->vars($data);
		$this->load->view('template_master');
		}
	}
	function pages_2($key){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['content'] = $this->MFuncs->getPagebyID($key);
		$data['title'] = $data['content']['title'];
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'pages';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function pages_3($key){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['content'] = $this->MFuncs->getPagebyID2($key);
		$data['title'] = $data['content']['title'];
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'pages';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function terms(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('links_terms');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'terms';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function klirwsi(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('links_terms');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'klirwsi';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function name_day(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('links_terms');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		//$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = 'εορτολόγιο, εορτολογιο, ΕΟΡΤΟΛΟΓΙΟ, γιορτη, γιορτή, ΓΙΟΡΤΗ, εορτή, εορτη, ΕΟΡΤΗ, συναξαριστής, συναξαριστης, συναξάρι, συναξαρι, γιορτάζει, γιορταζει, γιορτεσ, γιορτέσ, ποιός γιορτάζει, πότε γιορτάζει ο/η, ποιος γιορταζει, ποτε γιορταζει ο/η, υπολογισμός, κινητές, γιορτές, κινητες, γιορτες, κινητή, γιορτή, κινητη, γιορτη, κινητών, γιορτών, κινητων, γιορτων, ονομαστική, ονομαστικές, ονομαστικη, ονομαστικες, ονομαστικών, ονομαστικων, Πάσχα, Πασχα, αργίες, αργιες, greek namedays, name day, pote giortazo, pote giortazei, 2005, 2006, 2007, 2008, 2009, 2010
';
		$data['main'] = 'name_day';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function health(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('link_wine_health');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'wine-health';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function newsletter_easter(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('link_newsletter_easter');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'newsletter_easter';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function newsletter_spring(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('link_newsletter_spring');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'newsletter_spring';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function wine_roads(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('link_wine_roads');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'wine-roads';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function payment(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('links_payment');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'payment';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function shipping(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('links_shipping');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'shipping';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function personal(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('links_personal');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'personal';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function search(){
		if($this->input->post('term')){
		$this->session->set_userdata("search_field",$this->input->post('term'));
		redirect('search_results/priceasc', 'refresh');
		} else {
			$this->session->set_flashdata('message', $this->lang->line('search_missing'));
			redirect('main', 'refresh');
		}
	}
	function search_results($sorted){
		if ($this->session->userdata('search_field')) {
		$term = $this->session->userdata('search_field');
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('search_results');
		$config['per_page'] = '10';
		$config['base_url'] = base_url().'page/search_results/'.$sorted;
		$config['uri_segment'] = "4";
		$data['sorted'] = $sorted;
		$data['products']=$this->MFuncs->search($this->session->userdata('search_field'), $config['per_page'], $this->uri->segment(4), $sorted);
		//$data['products'] = $this->MFuncs->getProductsbyCatPrice_new($cat_id, $config['per_page'], $this->uri->segment(6), $sorted);
		$qusql = "SELECT * FROM products JOIN product_details ON products.id=product_details.p_id WHERE product_details.lang_id=".$ld." AND products.published='Yes' AND (product_details.name LIKE '%".$term."%' OR product_details.description LIKE '%".$term."%' OR product_details.suggestions LIKE '%".$term."%' OR product_details.characteristics LIKE '%".$term."%' OR product_details.vinifications LIKE '%".$term."%' OR product_details.microclimate LIKE '%".$term."%' OR product_details.other_characteristics LIKE '%".$term."%')";
		//$qusql = count($data['products']);
			if (!$data['products']) { 
			$this->session->set_flashdata('message', $this->lang->line('no_resutls'));
			redirect('main', 'refresh');
			}
		$query = $this->db->query($qusql);
		$tra = $query->num_rows(); 
		$config['next_tag_open'] = ' ';
		$config['next_tag_close'] = ' ';
		$config['prev_tag_open'] = ' ';
		$config['prev_tag_close'] = ' ';
		$config['num_tag_open'] = ' ';
		$config['num_tag_close'] = ' ';
		$config['last_tag_open'] = ' ';
		$config['last_tag_close'] = ' ';
		$config['first_tag_open'] = ' ';
		$config['first_tag_close'] = ' ';
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = $this->lang->line('first_link');
$config['last_link'] =$this->lang->line('last_link');
$config['prev_link'] =$this->lang->line('prev_link');
$config['next_link'] =$this->lang->line('next_link');
		$this->load->library('pagination');
		//$config['base_url'] = 'page/under_construction';
		//$config['total_rows'] = $this->db->count_all('project');
        $config['total_rows'] = $tra;
		$this->pagination->initialize($config);
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'search_new';
		$this->load->vars($data);
		$this->load->view('template_master');
		} else {
			$this->session->set_flashdata('message', $this->lang->line('search_missing'));
			redirect('main', 'refresh');
		}
	}
	function live_search_results($keyword){
		$this->config->set_item('compress_output', FALSE); 
		if ($keyword) {
		//$serach_term = $this->MFuncs->stringURLSafe($keyword);
		$data['products']=$this->MFuncs->Livesearch($keyword);
			if ($data['products']) {
				foreach($data['products'] as $result=>$prd) {
				$url_title = $this->MFuncs->stringURLSafe($prd['name']);
				     echo '<p>'.anchor('product/'.$prd['p_id'].'/'.$url_title, $prd['name']).'</p>';
				}
			//} else { 
			//echo $this->lang->line('no_resutls_live_search')." ".$keyword;
			}
		} else {
			echo $this->lang->line('search_missing');
		}
	}
	function nameday_results($sorted){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('name_day');
		$config['per_page'] = '10';
		$config['base_url'] = base_url().'page/nameday_results/'.$sorted;
		$config['uri_segment'] = "4";
		$data['sorted'] = $sorted;
		$data['products']=$this->MFuncs->getNameDayPrds($config['per_page'], $this->uri->segment(4), $sorted);
		//$data['products'] = $this->MFuncs->getProductsbyCatPrice_new($cat_id, $config['per_page'], $this->uri->segment(6), $sorted);
		$qusql = "SELECT * FROM products JOIN product_details ON products.id=product_details.p_id WHERE product_details.lang_id=".$ld." AND products.published='Yes' AND products.nameday='Yes'";
		//$qusql = count($data['products']);
//			if (!$data['products']) { 
//			$this->session->set_flashdata('message', $this->lang->line('no_resutls'));
//			redirect('main', 'refresh');
//			}
		$query = $this->db->query($qusql);
		$tra = $query->num_rows(); 
		$config['next_tag_open'] = ' ';
		$config['next_tag_close'] = ' ';
		$config['prev_tag_open'] = ' ';
		$config['prev_tag_close'] = ' ';
		$config['num_tag_open'] = ' ';
		$config['num_tag_close'] = ' ';
		$config['last_tag_open'] = ' ';
		$config['last_tag_close'] = ' ';
		$config['first_tag_open'] = ' ';
		$config['first_tag_close'] = ' ';
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = $this->lang->line('first_link');
$config['last_link'] =$this->lang->line('last_link');
$config['prev_link'] =$this->lang->line('prev_link');
$config['next_link'] =$this->lang->line('next_link');
		$this->load->library('pagination');
		//$config['base_url'] = 'page/under_construction';
		//$config['total_rows'] = $this->db->count_all('project');
        $config['total_rows'] = $tra;
		$this->pagination->initialize($config);
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'nameday_prd';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function nameday_res(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('name_day');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'nameday';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function christmass_offer(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('name_day');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'christmass_offers';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function history(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['content'] = $this->MFuncs->getPage('history', $ld);
		$data['title'] = $this->lang->line('links_history');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'pages';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function view_new($id){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['new'] = $this->MFuncs->getNew($id);
		if (!$data['new']) {
		redirect('home', 'location');
		}
		$data['title'] = $data['new']['title'];
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'news';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function register(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('create_account');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'register';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function buy_offer_1(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		//$data['product'] = $this->MFuncs->getProductDetails($p_id);
		//$this->session->set_userdata("temp_p_id",$p_id);
		$data['title'] = $this->lang->line('buy_offer_1_title');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'buy_offer_1';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
  function create_offer_user(){
	if ($this->input->post('qty') && $this->input->post('fname') && $this->input->post('lname') && $this->input->post('address') && $this->input->post('city') && $this->input->post('postal') && $this->input->post('tel') && $this->input->post('mob') && $this->input->post('email')){
			
			//$check = $this->MFuncs->CheckUser($this->input->post('email'));
			if(!$this->MFuncs->validEmail($this->input->post('email'))){
				$this->session->set_flashdata('message',$this->lang->line('validEmail'));
				redirect('buy_offer_1','refresh');
			//} elseif ($check==true) {
			//	$this->session->set_flashdata('message', $this->lang->line('email_registered'));
			//	redirect('register','refresh');
			} else {
			//$p_id = $this->session->userdata('temp_p_id');
			//$data['product'] = $this->MFuncs->getProductDetails($p_id);
			//if (($data['product']['offers']=='Yes') && ($data['product']['offer_price']!=0)) {
			//$p_price = $data['product']['offer_price'];
			//} else { 
			//$p_price = $data['product']['price'];
			//}
			$p_price = 23.20;
			$total_cost = $p_price*$this->input->post('qty');
			$temp_u_id = $this->MFuncs->insertOfferUser($total_cost);
			$this->session->set_userdata("temp_u_id",$temp_u_id);
			redirect('buy_offer_2','location');
			}
	}   else {
	$this->session->set_flashdata('message', $this->lang->line('missing_fields'));
	redirect('buy_offer_1','');
	}
  }
	function buy_offer_2(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$temp_u_id = $this->session->userdata('temp_u_id');
		$data['offer_order'] = $this->MFuncs->getOfferOrder($temp_u_id);
		//$data['product'] = $this->MFuncs->getProductDetails($data['offer_order']['p_id']);
		$data['title'] = $this->lang->line('buy_offer_2_title');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'buy_offer_2';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function buy_offer_1b(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$temp_u_id = $this->session->userdata('temp_u_id');
		$data['offer_order'] = $this->MFuncs->getOfferOrder($temp_u_id);
		//$data['product'] = $this->MFuncs->getProductDetails($data['offer_order']['p_id']);
		$data['title'] = $this->lang->line('buy_offer_1_title');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'buy_offer_1b';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
  function update_offer_user(){
	if ($this->input->post('qty') && $this->input->post('fname') && $this->input->post('lname') && $this->input->post('address') && $this->input->post('city') && $this->input->post('postal') && $this->input->post('tel') && $this->input->post('mob') && $this->input->post('email')){
			
			if(!$this->MFuncs->validEmail($this->input->post('email'))){
				$this->session->set_flashdata('message',$this->lang->line('validEmail'));
				redirect('buy_offer_1b','refresh');
			//} elseif ($check==true) {
			//	$this->session->set_flashdata('message', $this->lang->line('email_registered'));
			//	redirect('register','refresh');
			} else {
			$temp_u_id = $this->session->userdata('temp_u_id');
			//$p_id = $this->session->userdata('temp_p_id');
			//$data['product'] = $this->MFuncs->getProductDetails($p_id);
			//if (($data['product']['offers']=='Yes') && ($data['product']['offer_price']!=0)) {
			//$p_price = $data['product']['offer_price'];
			//} else { 
			//$p_price = $data['product']['price'];
			//}
			$p_price = 23.20;
			$total_cost = $p_price*$this->input->post('qty');
			$this->MFuncs->updateOfferUser($total_cost, $temp_u_id);
			redirect('buy_offer_2','location');
			}
	}   else {
	$this->session->set_flashdata('message', $this->lang->line('missing_fields'));
	redirect('buy_offer_1b','');
	}
  }
	function send_offer_order(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$temp_u_id = $this->session->userdata('temp_u_id');
		$data['offer_order'] = $this->MFuncs->getOfferOrder($temp_u_id);
		//$data['product'] = $this->MFuncs->getProductDetails($data['offer_order']['p_id']);
			//if (($data['product']['offers']=='Yes') && ($data['product']['offer_price']!=0)) {
			//$p_price = $data['product']['offer_price'];
			//} else { 
			//$p_price = $data['product']['price'];
			//}
			$p_price = 23.20;
			$client = $this->lang->line('product').": Mediterra 3 φιάλες Chardonnay λευκό &amp; 3 φιάλες Merlot ερυθρό".br(1);
			$client .= $this->lang->line('price_txt').": ".$p_price." &euro;".br(1);
			$client .= $this->lang->line('cart_qty').": ".$data['offer_order']['qty'].br(1);
			$client .= $this->lang->line('cart_total').": ".$data['offer_order']['total']." &euro;".br(1);
			$client .= $this->lang->line('fname').": ".$data['offer_order']['fname'].br(1);
			$client .= $this->lang->line('lname').": ".$data['offer_order']['lname'].br(1);
			$client .= $this->lang->line('address').": ".$data['offer_order']['address'].br(1);
			$client .= $this->lang->line('city').": ".$data['offer_order']['city'].br(1);
			$client .= $this->lang->line('postal').": ".$data['offer_order']['postal'].br(1);
			$client .= $this->lang->line('floor').": ".$data['offer_order']['floor'].br(1);
			$client .= $this->lang->line('name_bell').": ".$data['offer_order']['name_bell'].br(1);
			$client .= $this->lang->line('tel').": ".$data['offer_order']['tel'].br(1);
			$client .= $this->lang->line('mob').": ".$data['offer_order']['mob'].br(1);
			$client .= $this->lang->line('email').": ".$data['offer_order']['email'].br(1);

			$data['msg_title'] = $this->lang->line('dear')." ".$data['offer_order']['fname']." ".$data['offer_order']['lname'].",".br(1).$this->lang->line('offer_order_msg');
			$data['comments'] = $this->lang->line('order_details_msg').br(1).$client;
			$data['post_msg'] = $this->lang->line('offer_order_msg2').br(1);

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);
			
			#Email send to the user
			//$this->email->from('info@wines2u.gr', 'www.wines2u.gr');
			$this->email->from('no-reply@wines2u.gr', 'www.wines2u.gr');
			$this->email->to($data['offer_order']['email']);
			$this->email->subject('www.wines2u.gr - Φόρμα Παραγγελίας - Order Form');
			$this->email->message($emsg);
			$this->email->send();



			$data['msg_title'] = $data['offer_order']['fname']." ".$data['offer_order']['lname']." has completed a new order in wines2u.gr".br(1);
			$data['comments'] = "The order details are the following: ".br(1).$client;
			$data['post_msg'] = "";

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);

			#Email send to the company!
			//$this->email->from('info@wines2u.gr',  $data['offer_order']['fname']." ". $data['offer_order']['lname']." ".$data['offer_order']['email']);
			$this->email->from('no-reply@wines2u.gr', $data['offer_order']['fname']." ". $data['offer_order']['lname']." ".$data['offer_order']['email']);
			$this->email->to('info@wines2u.gr', 'www.wines2u.gr');
			//$this->email->to('dtangos@getid.gr', 'www.wines2u.gr');
			$this->email->subject('www.wines2u.gr - Φόρμα Παραγγελίας - Order Form');
			$this->email->message($emsg);
			$this->email->send();
	redirect('final_offer_order','');
	}
	function final_offer_order(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$temp_u_id = $this->session->userdata('temp_u_id');
		$data['offer_order'] = $this->MFuncs->getOfferOrder($temp_u_id);
		//$data['product'] = $this->MFuncs->getProductDetails($data['offer_order']['p_id']);
		$data['title'] = $this->lang->line('cart_complete');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'buy_offer_3';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function change_info(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['title'] = $this->lang->line('change_info');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'change_info';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function change_password(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['title'] = $this->lang->line('change_password');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'change_password';
		$this->load->library('form_validation');
		// field name, error message, validation rules
		$this->form_validation->set_rules('old_password', $this->lang->line('current_password'), 'trim|required');
		$this->form_validation->set_rules('password', $this->lang->line('new_password'), 'trim|required|min_length[4]|max_length[32]');
		$this->form_validation->set_rules('password2', $this->lang->line('confirm_password'), 'trim|required|matches[password]');
		if($this->form_validation->run() == FALSE)
		{
			$this->load->view('template_master', $data);
		} else {
			$pass = md5($this->input->post('old_password'));
			//$pass = dohash($this->input->post('old_password'), 'md5');
			if ($pass==$data['userdata']['password']) {
			$this->MFuncs->updateUserPassword($data['userdata']['id'], $this->input->post('password'));
			$this->session->set_flashdata('message', $this->lang->line('changes_saved'));
			redirect('home', 'location');
			} else { 
			$this->session->set_flashdata('message', $this->lang->line('wrong_old_password'));
			redirect('change_password', 'location');
			}
		}
  }
	function forgot_psrd(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('forgot_password');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'forgot_psrd';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function view_orders(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$id=$this->session->userdata('userid');		
		$data['orders'] = $this->MFuncs->getUserOrders($id);
		$data['title'] = $this->lang->line('orders_title');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'orders';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function view_order($order_id){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('view_order');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'order';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function products($type, $cat_id){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$config['per_page'] = '5';
		$config['base_url'] = base_url().'page/products/'.$type.'/'.$cat_id;
		$config['uri_segment'] = "5";
		$data['int_cat_id'] = $cat_id;
		$data['type'] = $type;
		$data['sorted'] = 'No';
		$data['by_price'] = 'No';
		if ($type=='cat') {
		$data['subcategory'] = '';
		$data['category'] = $this->MFuncs->getCategory($cat_id);
		$data['category_id'] = $cat_id;
		$data['title'] = $data['category']['cat_name'];
		$data['products'] = $this->MFuncs->getProductsbyCat($cat_id, $config['per_page'], $this->uri->segment(5));
		$qusql = "SELECT * FROM product_categories JOIN products ON product_categories.p_id=products.id WHERE product_categories.cat_id=".$cat_id." AND products.published='Yes'";
		} elseif ($type=='sub') {
		$data['subcategory'] = $this->MFuncs->getSubCategory($cat_id);
		$data['category'] = $this->MFuncs->getCategory($data['subcategory']['cat_id']);
		$data['category_id'] = $data['subcategory']['cat_id'];
		$data['title'] = $data['category']['cat_name']." : ".$data['subcategory']['name'];
		$data['products'] = $this->MFuncs->getProductsbySubCat($cat_id, $config['per_page'], $this->uri->segment(5));
		$qusql = "SELECT * FROM product_subcategories JOIN products ON product_subcategories.p_id=products.id WHERE product_subcategories.subcat_id=".$cat_id." AND products.published='Yes'";
		}
		$query = $this->db->query($qusql);
		$tra = $query->num_rows(); 
		$config['next_tag_open'] = ' ';
		$config['next_tag_close'] = ' ';
		$config['prev_tag_open'] = ' ';
		$config['prev_tag_close'] = ' ';
		$config['num_tag_open'] = ' ';
		$config['num_tag_close'] = ' ';
		$config['last_tag_open'] = ' ';
		$config['last_tag_close'] = ' ';
		$config['first_tag_open'] = ' ';
		$config['first_tag_close'] = ' ';
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = $this->lang->line('first_link');
$config['last_link'] =$this->lang->line('last_link');
$config['prev_link'] =$this->lang->line('prev_link');
$config['next_link'] =$this->lang->line('next_link');
		$this->load->library('pagination');
		//$config['base_url'] = 'page/under_construction';
		//$config['total_rows'] = $this->db->count_all('project');
        $config['total_rows'] = $tra;
		$this->pagination->initialize($config);
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'products';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function product_price($type, $cat_id, $sorted){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$config['per_page'] = '5';
		$config['base_url'] = base_url().'page/product_price/'.$type.'/'.$cat_id.'/'.$sorted;
		$config['uri_segment'] = "6";
		$data['int_cat_id'] = $cat_id;
		$data['type'] = $type;
		$data['sorted'] = $sorted;
		$data['by_price'] = 'No';
		if ($type=='cat') {
		$data['subcategory'] = '';
		$data['category'] = $this->MFuncs->getCategory($cat_id);
		$data['category_id'] = $cat_id;
		$data['title'] = $data['category']['cat_name'];
		$data['products'] = $this->MFuncs->getProductsbyCatPrice($cat_id, $config['per_page'], $this->uri->segment(6), $sorted);
		$qusql = "SELECT * FROM product_categories JOIN products ON product_categories.p_id=products.id WHERE product_categories.cat_id=".$cat_id." AND products.published='Yes'";
		} elseif ($type=='sub') {
		$data['subcategory'] = $this->MFuncs->getSubCategory($cat_id);
		$data['category'] = $this->MFuncs->getCategory($data['subcategory']['cat_id']);
		$data['category_id'] = $data['subcategory']['cat_id'];
		$data['title'] = $data['category']['cat_name']." : ".$data['subcategory']['name'];
		$data['products'] = $this->MFuncs->getProductsbySubCatPrice($cat_id, $config['per_page'], $this->uri->segment(6), $sorted);
		$qusql = "SELECT * FROM product_subcategories JOIN products ON product_subcategories.p_id=products.id WHERE product_subcategories.subcat_id=".$cat_id." AND products.published='Yes'";
		}
		$query = $this->db->query($qusql);
		$tra = $query->num_rows(); 
		$config['next_tag_open'] = ' ';
		$config['next_tag_close'] = ' ';
		$config['prev_tag_open'] = ' ';
		$config['prev_tag_close'] = ' ';
		$config['num_tag_open'] = ' ';
		$config['num_tag_close'] = ' ';
		$config['last_tag_open'] = ' ';
		$config['last_tag_close'] = ' ';
		$config['first_tag_open'] = ' ';
		$config['first_tag_close'] = ' ';
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = $this->lang->line('first_link');
$config['last_link'] =$this->lang->line('last_link');
$config['prev_link'] =$this->lang->line('prev_link');
$config['next_link'] =$this->lang->line('next_link');
		$this->load->library('pagination');
		//$config['base_url'] = 'page/under_construction';
		//$config['total_rows'] = $this->db->count_all('project');
        $config['total_rows'] = $tra;
		$this->pagination->initialize($config);
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'products';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function product_price_new($type, $cat_id, $sorted){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$config['per_page'] = '5';
		$config['base_url'] = base_url().'page/product_price_new/'.$type.'/'.$cat_id.'/'.$sorted;
		$config['uri_segment'] = "6";
		$data['int_cat_id'] = $cat_id;
		$data['type'] = $type;
		$data['sorted'] = $sorted;
		$data['by_price'] = 'No';
		if ($type=='cat') {
		$data['subsubcategory'] = '';
		$data['subcategory'] = '';
		$data['category'] = $this->MFuncs->getCategory($cat_id);
		$data['category_id'] = $cat_id;
		$data['title'] = $data['category']['cat_name'];
		$data['products'] = $this->MFuncs->getProductsbyCatPrice_new($cat_id, $config['per_page'], $this->uri->segment(6), $sorted);
		$qusql = "SELECT * FROM product_categories JOIN products ON product_categories.p_id=products.id WHERE product_categories.cat_id=".$cat_id." AND products.published='Yes'";
		} elseif ($type=='sub') {
		$data['subsubcategory'] = '';
		$data['subcategory'] = $this->MFuncs->getSubCategory($cat_id);
		$data['category'] = $this->MFuncs->getCategory($data['subcategory']['cat_id']);
		$data['category_id'] = $data['subcategory']['cat_id'];
		$data['title'] = $data['category']['cat_name']." : ".$data['subcategory']['name'];
		$data['products'] = $this->MFuncs->getProductsbySubCatPrice_new($cat_id, $config['per_page'], $this->uri->segment(6), $sorted);
		$qusql = "SELECT * FROM product_subcategories JOIN products ON product_subcategories.p_id=products.id WHERE product_subcategories.subcat_id=".$cat_id." AND products.published='Yes'";
		} elseif ($type=='subsub') {
		$data['subsubcategory'] = $this->MFuncs->getSubSubCategory($cat_id);
		$data['subcategory'] = $this->MFuncs->getSubCategory($data['subsubcategory']['sub_id']);
		$data['category'] = $this->MFuncs->getCategory($data['subsubcategory']['cat_id']);
		$data['category_id'] = $data['subsubcategory']['cat_id'];
		$data['title'] = $data['category']['cat_name']." : ".$data['subcategory']['name'];
		$data['products'] = $this->MFuncs->getProductsbySubSubCatPrice_new($cat_id, $config['per_page'], $this->uri->segment(6), $sorted);
		$qusql = "SELECT * FROM product_subsubcategories JOIN products ON product_subsubcategories.p_id=products.id WHERE product_subsubcategories.subsubcat_id=".$cat_id." AND products.published='Yes'";
		}
		$query = $this->db->query($qusql);
		$tra = $query->num_rows(); 
		$config['next_tag_open'] = ' ';
		$config['next_tag_close'] = ' ';
		$config['prev_tag_open'] = ' ';
		$config['prev_tag_close'] = ' ';
		$config['num_tag_open'] = ' ';
		$config['num_tag_close'] = ' ';
		$config['last_tag_open'] = ' ';
		$config['last_tag_close'] = ' ';
		$config['first_tag_open'] = ' ';
		$config['first_tag_close'] = ' ';
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = $this->lang->line('first_link');
$config['last_link'] =$this->lang->line('last_link');
$config['prev_link'] =$this->lang->line('prev_link');
$config['next_link'] =$this->lang->line('next_link');
		$this->load->library('pagination');
		//$config['base_url'] = 'page/under_construction';
		//$config['total_rows'] = $this->db->count_all('project');
        $config['total_rows'] = $tra;
		$this->pagination->initialize($config);
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'products_new';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function get_result(){
	  $options='';
	  if ($this->input->post('cabin_id')!='0'){
	  $persons = $this->input->post('cabin_id') * 2;
	 		for ( $i = $this->input->post('cabin_id'); $i <= $persons; $i += 1) {
					$options.='<option value="'.$i.'" class="dynamic">'.$i.'</option>';
				}
		   echo $options;
	  }
  }
	function by_price(){
		$this->session->set_userdata("by_price",$this->input->post('price'));
			redirect('by_price_view','location');
	}

	function by_price_view(){
		if($this->session->userdata('by_price')) {
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$config['per_page'] = '5';
		$config['base_url'] = base_url().'page/by_price_view';
		$config['uri_segment'] = "3";
		$data['products'] = $this->MFuncs->getProductsbyPrice($config['per_page'], $this->uri->segment(3));
		//$data['product_cat'] = $this->MFuncs->getProductCat($data['products']['id']);
		$data['category_id'] = '';
		$data['by_price'] = 'Yes';
		if ($this->session->userdata('by_price')=='0-10') { 
		$data['title'] = $this->lang->line('search_price')." 0 &euro; - 10 &euro;";
		$qusql = "SELECT * FROM products JOIN product_categories ON products.id=product_categories.p_id WHERE products.price < 10 AND products.published='Yes' AND product_categories.cat_id != '21' AND product_categories.cat_id != '7'";
		} elseif ($this->session->userdata('by_price')=='10-15') { 
		$data['title'] = $this->lang->line('search_price')." 10 &euro; - 15 &euro;";
		$qusql = "SELECT * FROM products JOIN product_categories ON products.id=product_categories.p_id WHERE products.price > 10 AND products.price < 15 AND products.published='Yes' AND product_categories.cat_id != '21' AND product_categories.cat_id != '7'";
		} elseif ($this->session->userdata('by_price')=='15-20') { 
		$data['title'] = $this->lang->line('search_price')." 15 &euro; - 20 &euro;";
		$qusql = "SELECT * FROM products JOIN product_categories ON products.id=product_categories.p_id WHERE products.price > 15 AND products.price < 20 AND products.published='Yes' AND product_categories.cat_id != '21' AND product_categories.cat_id != '7'";
		} elseif ($this->session->userdata('by_price')=='20') { 
		$data['title'] = $this->lang->line('search_price')." 20 &euro; +";
		$qusql = "SELECT * FROM products JOIN product_categories ON products.id=product_categories.p_id WHERE products.price > 20 AND products.published='Yes' AND product_categories.cat_id != '21' AND product_categories.cat_id != '7'";
		} elseif ($this->session->userdata('by_price')=='offers') { 
		$data['title'] = $this->lang->line('offers_txt');
		$qusql = "SELECT * FROM products JOIN product_categories ON products.id=product_categories.p_id WHERE products.offers = 'Yes' AND products.published='Yes' AND product_categories.cat_id != '21' AND product_categories.cat_id != '7'";
		}
		$query = $this->db->query($qusql);
		$tra = $query->num_rows(); 
		//$tra = mysql_num_rows($data['products']);
		$config['next_tag_open'] = ' ';
		$config['next_tag_close'] = ' ';
		$config['prev_tag_open'] = ' ';
		$config['prev_tag_close'] = ' ';
		$config['num_tag_open'] = ' ';
		$config['num_tag_close'] = ' ';
		$config['last_tag_open'] = ' ';
		$config['last_tag_close'] = ' ';
		$config['first_tag_open'] = ' ';
		$config['first_tag_close'] = ' ';
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = $this->lang->line('first_link');
$config['last_link'] =$this->lang->line('last_link');
$config['prev_link'] =$this->lang->line('prev_link');
$config['next_link'] =$this->lang->line('next_link');
		$this->load->library('pagination');
		//$config['base_url'] = 'page/under_construction';
		//$config['total_rows'] = $this->db->count_all('project');
        $config['total_rows'] = $tra;
		$this->pagination->initialize($config);
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'products';
		$this->load->vars($data);
		$this->load->view('template_master');
		} else {
			$this->session->set_flashdata('message', $this->lang->line('missing_fields'));
			redirect('home','refresh');
			}
	}
	function by_price_cat_view($cat_id){
		if($this->session->userdata('by_price')) {
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$config['per_page'] = '5';
		$config['base_url'] = base_url().'page/by_price_cat_view/'.$cat_id;
		$config['uri_segment'] = "4";
		$data['products'] = $this->MFuncs->getProductsbyPriceNew($cat_id, $config['per_page'], $this->uri->segment(4));
		$data['products_cat'] = $this->MFuncs->getCategory($cat_id);
		$data['category_id'] = '';
		$data['by_price'] = 'Yes';
		if ($this->session->userdata('by_price')=='0-10') { 
		$data['title'] = $this->lang->line('search_price')." 0 &euro; - 10 &euro; :: ".$data['products_cat']['cat_name'];
		$qusql = "SELECT * FROM products JOIN product_categories ON products.id=product_categories.p_id WHERE products.price < 10 AND products.published='Yes' AND product_categories.cat_id = ".$cat_id."";
		} elseif ($this->session->userdata('by_price')=='10-15') { 
		$data['title'] = $this->lang->line('search_price')." 10 &euro; - 15 &euro; :: ".$data['products_cat']['cat_name'];
		$qusql = "SELECT * FROM products JOIN product_categories ON products.id=product_categories.p_id WHERE products.price > 10 AND products.price < 15 AND products.published='Yes' AND product_categories.cat_id = ".$cat_id."";
		} elseif ($this->session->userdata('by_price')=='15-20') { 
		$data['title'] = $this->lang->line('search_price')." 15 &euro; - 20 &euro; :: ".$data['products_cat']['cat_name'];
		$qusql = "SELECT * FROM products JOIN product_categories ON products.id=product_categories.p_id WHERE products.price > 15 AND products.price < 20 AND products.published='Yes' AND product_categories.cat_id = ".$cat_id."";
		} elseif ($this->session->userdata('by_price')=='20') { 
		$data['title'] = $this->lang->line('search_price')." 20 &euro; + :: ".$data['products_cat']['cat_name'];
		$qusql = "SELECT * FROM products JOIN product_categories ON products.id=product_categories.p_id WHERE products.price > 20 AND products.published='Yes' AND product_categories.cat_id = ".$cat_id."";
		} elseif ($this->session->userdata('by_price')=='offers') { 
		$data['title'] = $this->lang->line('offers_txt')." :: ".$data['products_cat']['cat_name'];
		$qusql = "SELECT * FROM products JOIN product_categories ON products.id=product_categories.p_id WHERE products.offers = 'Yes' AND products.published='Yes' AND product_categories.cat_id = ".$cat_id."";
		}
		$query = $this->db->query($qusql);
		$tra = $query->num_rows(); 
		//$tra = mysql_num_rows($data['products']);
		$config['next_tag_open'] = ' ';
		$config['next_tag_close'] = ' ';
		$config['prev_tag_open'] = ' ';
		$config['prev_tag_close'] = ' ';
		$config['num_tag_open'] = ' ';
		$config['num_tag_close'] = ' ';
		$config['last_tag_open'] = ' ';
		$config['last_tag_close'] = ' ';
		$config['first_tag_open'] = ' ';
		$config['first_tag_close'] = ' ';
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = $this->lang->line('first_link');
$config['last_link'] =$this->lang->line('last_link');
$config['prev_link'] =$this->lang->line('prev_link');
$config['next_link'] =$this->lang->line('next_link');
		$this->load->library('pagination');
		//$config['base_url'] = 'page/under_construction';
		//$config['total_rows'] = $this->db->count_all('project');
        $config['total_rows'] = $tra;
		$this->pagination->initialize($config);
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'products';
		$this->load->vars($data);
		$this->load->view('template_master');
		} else {
			$this->session->set_flashdata('message', $this->lang->line('missing_fields'));
			redirect('home','refresh');
			}
	}
	function by_price_new(){
		$this->session->set_userdata("by_price",$this->input->post('price'));
			redirect('page/by_price_cats','location');
	}
	function by_price_cats(){
		if($this->session->userdata('by_price')) {
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['products_cat'] = $this->MFuncs->getProductsCatbyPrice();
		if ($this->session->userdata('by_price')=='0-10') { 
		$data['title'] = $this->lang->line('search_price')." 0 &euro; - 10 &euro;";
		} elseif ($this->session->userdata('by_price')=='10-15') { 
		$data['title'] = $this->lang->line('search_price')." 10 &euro; - 15 &euro;";
		} elseif ($this->session->userdata('by_price')=='15-20') { 
		$data['title'] = $this->lang->line('search_price')." 15 &euro; - 20 &euro;";
		} elseif ($this->session->userdata('by_price')=='20') { 
		$data['title'] = $this->lang->line('search_price')." 20 &euro; +";
		} elseif ($this->session->userdata('by_price')=='offers') { 
		$data['title'] = $this->lang->line('offers_txt');
		}
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'products_price_cat';
		$this->load->vars($data);
		$this->load->view('template_master');
		} else {
			$this->session->set_flashdata('message', $this->lang->line('missing_fields'));
			redirect('home','refresh');
		}
	}

	function by_price_view_new(){
		if($this->session->userdata('by_price')) {
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$config['per_page'] = '5';
		$config['base_url'] = base_url().'page/by_price_view_new';
		$config['uri_segment'] = "3";
		$data['products'] = $this->MFuncs->getProductsbyPrice($config['per_page'], $this->uri->segment(3));
		//$data['product_cat'] = $this->MFuncs->getProductCat($data['products']['id']);
		$data['category_id'] = '';
		$data['by_price'] = 'Yes';
		if ($this->session->userdata('by_price')=='0-10') { 
		$data['title'] = $this->lang->line('search_price')." 0 &euro; - 10 &euro;";
		$qusql = "SELECT * FROM products JOIN product_categories ON products.id=product_categories.p_id WHERE products.price < 10 AND products.published='Yes' AND product_categories.cat_id != '21' AND product_categories.cat_id != '7'";
		} elseif ($this->session->userdata('by_price')=='10-15') { 
		$data['title'] = $this->lang->line('search_price')." 10 &euro; - 15 &euro;";
		$qusql = "SELECT * FROM products JOIN product_categories ON products.id=product_categories.p_id WHERE products.price > 10 AND products.price < 15 AND products.published='Yes' AND product_categories.cat_id != '21' AND product_categories.cat_id != '7'";
		} elseif ($this->session->userdata('by_price')=='15-20') { 
		$data['title'] = $this->lang->line('search_price')." 15 &euro; - 20 &euro;";
		$qusql = "SELECT * FROM products JOIN product_categories ON products.id=product_categories.p_id WHERE products.price > 15 AND products.price < 20 AND products.published='Yes' AND product_categories.cat_id != '21' AND product_categories.cat_id != '7'";
		} elseif ($this->session->userdata('by_price')=='20') { 
		$data['title'] = $this->lang->line('search_price')." 20 &euro; +";
		$qusql = "SELECT * FROM products JOIN product_categories ON products.id=product_categories.p_id WHERE products.price > 20 AND products.published='Yes' AND product_categories.cat_id != '21' AND product_categories.cat_id != '7'";
		} elseif ($this->session->userdata('by_price')=='offers') { 
		$data['title'] = $this->lang->line('offers_txt');
		$qusql = "SELECT * FROM products JOIN product_categories ON products.id=product_categories.p_id WHERE products.offers = 'Yes' AND products.published='Yes' AND product_categories.cat_id != '21' AND product_categories.cat_id != '7'";
		}
		$query = $this->db->query($qusql);
		$tra = $query->num_rows(); 
		//$tra = mysql_num_rows($data['products']);
		$config['next_tag_open'] = ' ';
		$config['next_tag_close'] = ' ';
		$config['prev_tag_open'] = ' ';
		$config['prev_tag_close'] = ' ';
		$config['num_tag_open'] = ' ';
		$config['num_tag_close'] = ' ';
		$config['last_tag_open'] = ' ';
		$config['last_tag_close'] = ' ';
		$config['first_tag_open'] = ' ';
		$config['first_tag_close'] = ' ';
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = $this->lang->line('first_link');
$config['last_link'] =$this->lang->line('last_link');
$config['prev_link'] =$this->lang->line('prev_link');
$config['next_link'] =$this->lang->line('next_link');
		$this->load->library('pagination');
		//$config['base_url'] = 'page/under_construction';
		//$config['total_rows'] = $this->db->count_all('project');
        $config['total_rows'] = $tra;
		$this->pagination->initialize($config);
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'products';
		$this->load->vars($data);
		$this->load->view('template_master');
		} else {
			$this->session->set_flashdata('message', $this->lang->line('missing_fields'));
			redirect('home','refresh');
			}
	}
function view_product($id){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['product'] = $this->MFuncs->getProductDetails($id);
		$category = $this->MFuncs->getProductCat($id);
		$data['category_id'] = $category['cat_id'];
		$data['title'] = $data['product']['name'];
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'].", ".$data['product']['name'].", ".$data['product']['keywords'];
		$data['main'] = 'product';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function product($id, $name){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['product'] = $this->MFuncs->getProductDetails($id);
		$category = $this->MFuncs->getProductCat($id);
		$data['category_id'] = $category['cat_id'];
		$data['title'] = $data['product']['name'];
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'].", ".$data['product']['name'].", ".$data['product']['keywords'];
		$data['main'] = 'product';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function view_more_photos($id){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['product'] = $this->MFuncs->getProductDetails($id);
		$data['product_photos'] = $this->MFuncs->getProductPhotos($id);
		$category = $this->MFuncs->getProductCat($id);
		$data['category_id'] = $category['cat_id'];
		$data['title'] = $data['product']['name'];
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'].", ".$data['product']['name'].", ".$data['product']['keywords'];
		$data['main'] = 'product_photos';
		$this->load->vars($data);
		$this->load->view('template_master');
	}

function add_to_cart($id){
			 	$product_details = $this->MFuncs->getProductDetails($id);
				date_default_timezone_set("Europe/Athens");
				$now = date("Y-m-d G:i:s");
				$name = $product_details['name'];
				
				$today = strtotime($now); 
			if (($product_details['offers']=='Yes') && ($product_details['offer_price']!=0)) {
			$p_price = $product_details['offer_price'];
			} else {
			$p_price = $product_details['price'];
			}

				
			$data = array(
               'id'      => $id,
               'qty'     => 1,
               'price'   => $p_price,
               'name'    => 'name_'.$id,
               'options' => array('Date' => $now)
            );

			$this->cart->insert($data); 
			$this->session->set_flashdata('message', $this->lang->line('msg_prd_added'));

		$url = $this->session->flashdata('uri');
		//log_message('debug', "Redirect to $url (flashdata)");
		redirect($url, '');

		//redirect('view_cart','refresh');
	
}
	function view_cart(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('shopping_cart');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['sent'] = false;
		$data['postal_results'] = false;
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'cart';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function update_cart(){
		$i = 1;
		foreach($this->cart->contents() as $items):
					$data = $this->input->post($i);
		$this->cart->update($data); 
		$i++;
		endforeach;
			$this->session->set_flashdata('message', $this->lang->line('msg_cart_update'));
			redirect('view_cart','refresh');
}

function remove_product($rowid){
		$data = array(
               'rowid' => $rowid,
               'qty'   => 0
            );
		$this->cart->update($data); 
		$this->session->set_flashdata('message', $this->lang->line('msg_prd_removed'));
		redirect('view_cart','refresh');
}
  function create_user(){
	if ($this->input->post('fname') && $this->input->post('lname') && $this->input->post('country') && $this->input->post('address') && $this->input->post('city') && $this->input->post('postal') && $this->input->post('tel') && $this->input->post('mob') && $this->input->post('email') && $this->input->post('password')){
			
			$check = $this->MFuncs->CheckUser($this->input->post('email'));
			if(!$this->MFuncs->validEmail($this->input->post('email'))){
				$this->session->set_flashdata('message',$this->lang->line('validEmail'));
				redirect('register','refresh');
			} elseif ($check==true) {
				$this->session->set_flashdata('message', $this->lang->line('email_registered'));
				redirect('register','refresh');
			} else {
			
			$this->MFuncs->insertUser();
			
			$client = $this->lang->line('fname').": ".$this->input->post('fname').br(1);
			$client .= $this->lang->line('lname').": ".$this->input->post('lname').br(1);
			$client .= $this->lang->line('country').": ".$this->input->post('country').br(1);
			$client .= $this->lang->line('address').": ".$this->input->post('address').br(1);
			$client .= $this->lang->line('city').": ".$this->input->post('city').br(1);
			$client .= $this->lang->line('postal').": ".$this->input->post('postal').br(1);
			$client .= $this->lang->line('tel').": ".$this->input->post('tel').br(1);
			$client .= $this->lang->line('mob').": ".$this->input->post('mob').br(1);
			$client .= $this->lang->line('email').": ".$this->input->post('email').br(1);
			$client .= $this->lang->line('password').": ".$this->input->post('password').br(1);

			$data['msg_title'] = $this->lang->line('dear')." ".$this->input->post('fname')." ". $this->input->post('lname').",".br(1).$this->lang->line('register_msg');
			$data['comments'] = $this->lang->line('your_information').br(1).$client;
			$data['post_msg'] = "".br(1);

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);
			
			#Email send to the user
			$this->email->from('no-reply@wines2u.gr', 'www.wines2u.gr');
			$this->email->to($this->input->post('email'));
			$this->email->subject('www.wines2u.gr - Φόρμα Εγγραφής - Registration');
			$this->email->message($emsg);
			$this->email->send();



			$data['msg_title'] = $this->input->post('fname')." ". $this->input->post('lname')." has registered in wines2u.gr".br(1);
			$data['comments'] = "The information are the following: ".br(1).$client;
			$data['post_msg'] = "";

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);

			#Email send to the company!
			$this->email->from('no-reply@wines2u.gr',  $this->input->post('fname')." ". $this->input->post('lname')." ".$this->input->post('email'));
			$this->email->to('info@wines2u.gr', 'www.wines2u.gr');
			$this->email->subject('www.wines2u.gr - Φόρμα Εγγραφής - Registration');
			$this->email->message($emsg);
			$this->email->send();
			
	if ($this->cart->contents()) { 


		$u = $this->input->post('email');
		$pw = $this->input->post('password');
		$row = $this->MFuncs->verifyClient($u,$pw);
		if (count($row)){
			$_SESSION['userid'] = $row['id'];
			$this->session->set_userdata("userid",$row['id']);
			$this->session->set_flashdata('message', $this->lang->line('logged_in'));
			$id=$this->session->userdata('userid');
			$order_id = $this->MFuncs->insertOrder($id);
			$this->session->set_userdata("orderid",$order_id);
			redirect('complete_order_2/false','location');
		} else{
			$this->session->set_flashdata('message', $this->lang->line('wrong_combination'));
			redirect('complete_order_1','location');
		}
	} else { 
	$this->session->set_flashdata('message', $this->lang->line('registered_suc'));
	redirect('home','refresh');
	}
	}
	}   else {
	$this->session->set_flashdata('message', $this->lang->line('missing_fields'));
	redirect('register','');
	}
  }
  function update_user(){
	if ($this->input->post('fname') && $this->input->post('lname') && $this->input->post('address') && $this->input->post('country') && $this->input->post('city') && $this->input->post('postal') && $this->input->post('tel') && $this->input->post('mob') && $this->input->post('email')){

			$this->MFuncs->updateUser();
	$this->session->set_flashdata('message', $this->lang->line('changes_saved'));
	redirect('home','location');
	}   else {
	$this->session->set_flashdata('message', $this->lang->line('missing_fields'));
	redirect('change_info','');
	}
  }
  function delete_account(){
		$id=$this->session->userdata('userid');
		$this->MFuncs->deleteUser($id);
		$this->session->set_userdata("userid",'');
		$_SESSION['userid'] = '';
		$this->session->set_flashdata('message', $this->lang->line('account_deleted'));
		redirect('home','location');
  }
function send_psrd(){
	if ($this->input->post('email')){

			$user = $this->MFuncs->GetUser($this->input->post('email'));
			
			if ($user!=false) {
			$a_user = $this->MFuncs->createRandomPassword();
			$this->MFuncs->updateUserPassword($user['id'], $a_user);
			$data['msg_title'] = $this->lang->line('dear')." ".$user['fname']." ". $user['lname'].",".br(1);
			$data['comments'] = $this->lang->line('your_password').br(1).$this->lang->line('password_usr')." ".$a_user.br(2).$this->lang->line('your_password_2');
			$data['post_msg'] = $this->lang->line('thank_you');

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);
			
			#Email send to the user
			$this->email->from('no-reply@wines2u.gr', 'www.wines2u.gr');
			$this->email->to($this->input->post('email'));
			$this->email->subject('www.wines2u.gr - Password Recovery');
			$this->email->message($emsg);
			$this->email->send();

	$this->session->set_flashdata('message', $this->lang->line('password_sent'));
	redirect('home','refresh');
	} else {
	$this->session->set_flashdata('message', $this->lang->line('not_registered_email'));
	redirect('home','refresh');
	}
	}   else {
	$this->session->set_flashdata('message', $this->lang->line('missing_fields'));
	redirect('forgot_psrd','');
	}
  }

function step_1(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('login_register');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_1';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function step_2($flag){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$id=$this->session->userdata('userid');
		if ($flag=='true') {
			$order_id = $this->MFuncs->insertOrder($id);
			$this->session->set_userdata("orderid",$order_id);
		}
		$order_id=$this->session->userdata('orderid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('payment_method');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_2';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function step_2_2(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['select'] = false;
		$data['sel_loc'] = false;
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('shipping_method');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_2_2';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function step_2_2_new(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['select'] = false;
		$data['sel_loc'] = false;
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('shipping_method');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_2_2_new';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function step_2_2_new2(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['select'] = false;
		$data['sel_loc'] = false;
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('shipping_method');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_2_2_new2';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function transfer_estimator(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['title'] = $this->lang->line('transfer_estimator_title');
		$data['postal_results'] = false;
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'tranfer_estimation_calc';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function transfer_estimator_step2(){
	if ($this->input->post('postal')) {
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['postal_results'] = true;
		$data['postal_input'] = $this->input->post('postal');
		$data['title'] = $this->lang->line('shopping_cart');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'cart';
		$this->load->vars($data);
		$this->load->view('template_master');
	} else { 
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['postal_results'] = false;
		$data['title'] = $this->lang->line('shopping_cart');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'cart';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
}
function step_2_3(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('invoice_details');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_2_3';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function step_3(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('verify_data');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_3';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function step_3_new(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('verify_data');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_3_new';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function step_3_new2(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('verify_data');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_3_new2';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function step_4(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);

 if ($data['orderdata']) { 
 $cart = "<table class='full' width='100%' border='0'>";
 $cart .= "<tr>";
 $cart .= "<th>".$this->lang->line('cart_qty')."</th>";
 $cart .= "<th>".$this->lang->line('cart_desc')."</th>";
 $cart .= "<th>".$this->lang->line('cart_price')."</th>";
 $cart .= "<th>".$this->lang->line('cart_sub')."</th>";
 $cart .= "</tr>";

		$order_details = $this->MFuncs->GetOrderDetails($data['orderdata']['id']);
		if ($order_details) {
		$total = 0;
		$weight = 0;
		$bot_num = 0;
		$pack_total = 0;
		$ship_total = 0;

    	foreach($order_details as $result=>$order_det):
        $product_details = $this->MFuncs->getProductDetails($order_det['product_id']);
		$product_category = $this->MFuncs->getProductCat($order_det['product_id']);
		$product_category_name = $this->MFuncs->getCategory($product_category['cat_id']);
		$product_sub_category = $this->MFuncs->getProductSubCat($order_det['product_id']);
		if ($product_sub_category) {
		$product_sub_category_name = $this->MFuncs->getSubCategory($product_sub_category['subcat_id']);
		}
		
 $cart .= "<tr>";
 $cart .= "<td>".$order_det['quantity']."</td>";
 if ($product_sub_category) {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_sub_category_name['name']."-".$product_details['name']."</td>";
 } else {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_details['name']."</td>";
 }
 $cart .= "<td>".number_format($order_det['price'], 2, '.', '')."</td>";
 $cart .= "<td>&euro; ".number_format($order_det['price']*$order_det['quantity'], 2, '.', '')."</td>";
 $total = $total + $order_det['price']*$order_det['quantity'];
 $weight = $weight + ($product_details['weight'] * $order_det['quantity']);
 if ($product_category['cat_id']!='7') { 
          $bot_num = $bot_num + $order_det['quantity']; 
		  }
$cart .= "</tr>";
    	endforeach;
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
 if ($data['orderdata']['offer_code']!=0) {
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_discount')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total*$data['orderdata']['offer_code'], 2, '.', '')."</td>";
 $cart .= "</tr>";
 $total = $total - ($total*$data['orderdata']['offer_code']);
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
 }
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $cart .= "<td>&euro; ".$total - $total/1.21."</td>";
// $cart .= "</tr>";
// $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
// $cart .= "<td>&euro; ".$total."</td>";
// $cart .= "</tr>";

         if (($data['orderdata']['same_address']=='No') && ($data['orderdata']['country_id']!='1')) { 
        if ($data['orderdata']['ship_method']=='courier') { 
        	//$rounded_weight = round($weight/1000, 2);
	   		$rounded_weight = ceil(($weight/1000)*2)/2;
			if ($data['orderdata']['same_address']=='No') {
			$c_id = $data['orderdata']['country_id'];
			} else { 
			$c_id = $data['userdata']['country_id'];
			}
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getFed_Ex_Cost($rounded_weight, $country_zone['zones']);
			$ship_total = ($value['price']*0.152) + $value['price'];
			if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			}
			$ship_total = number_format($ship_total, 2, '.', ''); 
         }
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";
         } elseif (($data['orderdata']['same_address']=='Yes') && ($data['userdata']['country_id']!='1')) { 
        if ($data['orderdata']['ship_method']=='courier') { 
        	//$rounded_weight = round($weight/1000, 2);
	   		$rounded_weight = ceil(($weight/1000)*2)/2;
			if ($data['orderdata']['same_address']=='No') {
			$c_id = $data['orderdata']['country_id'];
			} else { 
			$c_id = $data['userdata']['country_id'];
			}
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getFed_Ex_Cost($rounded_weight, $country_zone['zones']);
			$ship_total = ($value['price']*0.152) + $value['price'];
			if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			}
			$ship_total = number_format($ship_total, 2, '.', ''); 
         }
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";

//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//$cart .= "<td>&euro; ".$ship_total."</td>";
//$cart .= "</tr>";
//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//$cart .= "</tr>";
         } else { 
 
 if ($data['orderdata']['ship_method']=='courier') {
 $pack_total = (ceil($bot_num/2))*0.53;
           if ($data['orderdata']['ship_dest']=='attica') {
			   if ($weight == 0) { 
			   $ship_total = number_format(0, 2, '.', '');
			   } 
			   elseif ($weight < 3000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.57, 2, '.', '');
			   } else {
			   //$ship_total = 3.45 + $pack_total;
			   $ship_total = 3.57;
			   $weight = $weight - 3000;
			   $i = ceil($weight/1000);
			   $ship_total = number_format($ship_total + ($i*1.23), 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='greece') {
			   if ($weight == 0) { 
			   $ship_total = number_format(0, 2, '.', '');
			   } 
			   elseif ($weight < 5000) {
			   $ship_total = 5.90; 
			   $ship_total = number_format($ship_total, 2, '.', '');
			   } elseif ($weight < 10000){
			   $ship_total = 10.58;
			   //$weight = $weight - 2000;
			   //$i = ceil($weight/1000);
			   $ship_total = number_format($ship_total, 2, '.', '');
			   } else {
			   $ship_total = 16.48;
			   //$weight = $weight - 2000;
			   //$i = ceil($weight/1000);
			   $ship_total = number_format($ship_total, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='islands') {
			   if ($weight == 0) { 
			   $ship_total = number_format(0, 2, '.', '');
			   } 
			   elseif ($weight < 5000) {
			   $ship_total = 8.86; 
			   $ship_total = number_format($ship_total, 2, '.', '');
			   } elseif ($weight < 10000){
			   $ship_total = 15.87;
			   //$weight = $weight - 2000;
			   //$i = ceil($weight/1000);
			   $ship_total = number_format($ship_total, 2, '.', '');
			   } else {
			   $ship_total = 24.60;
			   //$weight = $weight - 2000;
			   //$i = ceil($weight/1000);
			   $ship_total = number_format($ship_total, 2, '.', '');
			   }
			}
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";


//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//$cart .= "<td>&euro; ".$ship_total."</td>";
//$cart .= "</tr>";
//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//$cart .= "</tr>";
         } elseif ($data['orderdata']['ship_method']=='day_delivery') {
        		$ship_total = number_format(14.76, 2, '.', '');
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";
				
//				$cart .= "<tr>";
//				$cart .= "<td colspan='2'></td>";
//				$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//				$cart .= "<td>&euro; ".$ship_total."</td>";
//				$cart .= "</tr>";
//				$cart .= "<tr>";
//				$cart .= "<td colspan='2'></td>";
//				$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//				$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//				$cart .= "</tr>";
		 }
		 }
	}
 $cart .= "</table>";
 $cart .= "<Br>";
 $cart .= "<em>".$this->lang->line('vat_included_cart')."</em>";
 if (($data['orderdata']['ship_method']=='courier') || ($data['orderdata']['ship_method']=='day_delivery')) {
 if ($data['orderdata']['ship_method']=='courier') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('courier_delivery')."</h4>";
 } else {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('day_delivery')."</h4>";
 }
 $cart .= "<h4>".$this->lang->line('delivery_address')."</h4>";
 if ($data['orderdata']['same_address']=='Yes') {
 $country_zone = $this->MFuncs->getCountryZone($data['userdata']['country_id']);
 $cart .= "<h4>".$data['userdata']['address'].", ".$data['userdata']['city'].", ".$data['userdata']['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$data['userdata']['floor'].", ".$this->lang->line('name_bell').": ".$data['userdata']['name_bell']."<br>".$this->lang->line('tel').": ".$data['userdata']['tel'].", ".$this->lang->line('mob').": ".$data['userdata']['mob']."</h4>";
 }else { 
  $country_zone = $this->MFuncs->getCountryZone($data['orderdata']['country_id']);
 $cart .= "<h4>".$data['orderdata']['address'].", ".$data['orderdata']['city'].", ".$data['orderdata']['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$data['orderdata']['floor'].", ".$this->lang->line('name_bell').": ".$data['orderdata']['name_bell']."<br>".$this->lang->line('tel').": ".$data['userdata']['tel'].", ".$this->lang->line('mob').": ".$data['userdata']['mob']."</h4>";
 } 
 } else {
  $cart .= "<h4>".$this->lang->line('pickup_title')."</h4>";
  $cart .= "<h4>".$this->lang->line('pickup_txt')."</h4>";
 }
  if ($data['orderdata']['pay_method']=='Cash') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('cash_on_delivery')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='Bank') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('bank_deposit')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='Credit') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('credit_card')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='PayPal') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('pay_pal')."</h4>";
 }
 $cart .= "<Br>";
  if ($data['orderdata']['receipt_type']=='receipt') {
 $cart .= "<h4>".$this->lang->line('receipt_type')."</h4>";
 $cart .= "<h4>".$this->lang->line('type_receipt')."</h4>";
 } elseif ($data['orderdata']['receipt_type']=='invoice') {
 $cart .= "<h4>".$this->lang->line('receipt_type')."</h4>";
 $cart .= "<h4>".$this->lang->line('type_invoice')."</h4>";
 $invoice_details = $this->MFuncs->getInvoiceDetails($data['orderdata']['id']);
 	if ($invoice_details) { 
	 $cart .= "<Br>";
	 $cart .= "<p>".$this->lang->line('cmp_name').": ".$invoice_details['cmp_name']."<Br>";
	 $cart .= $this->lang->line('cmp_occupation').": ".$invoice_details['cmp_occupation']."<Br>";
	 $cart .= $this->lang->line('cmp_afm').": ".$invoice_details['cmp_afm']."<Br>";
	 $cart .= $this->lang->line('cmp_address').": ".$invoice_details['cmp_address']."<Br>";
	 $cart .= $this->lang->line('cmp_city').": ".$invoice_details['cmp_city']."<Br>";
	 $cart .= $this->lang->line('cmp_doy').": ".$invoice_details['cmp_doy']."</p>";
	}
 }

			$data['msg_title'] = "A new order has been made by ".$data['userdata']['fname']." ".$data['userdata']['lname'];
			$data['comments'] = "The order details are the following:".br(2).$cart;
			$data['post_msg'] = "";
			
			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);

			#Email send to the company!
			$this->email->from('no-reply@wines2u.gr', $data['userdata']['fname']." ".$data['userdata']['lname']." ".$data['userdata']['email']);
			$this->email->to('info@wines2u.gr', 'www.wines2u.gr');
			$this->email->cc('b.a@wines2u.gr', 'www.wines2u.gr');
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
	
			$data['msg_title'] = $this->lang->line('dear')." ".$data['userdata']['fname']." ".$data['userdata']['lname'].",".br(1).$this->lang->line('order_msg');
			$data['comments'] = $this->lang->line('order_details_msg').br(2).$cart;
			$data['post_msg'] = $this->lang->line('contact_dept').br(1);

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);
		
			#Email send to the user
			$this->email->from('no-reply@wines2u.gr', 'www.wines2u.gr');
			$this->email->to($data['userdata']['email']);
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
			
		$data['order_cart'] = $cart;
}
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$this->MFuncs->finaliseOrder($order_id);
		$this->cart->destroy();
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('thank_you');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['main'] = 'step_4';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function step_4_new(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);

 if ($data['orderdata']) { 
 $cart = "<table class='full' width='100%' border='0'>";
 $cart .= "<tr>";
 $cart .= "<th>".$this->lang->line('cart_qty')."</th>";
 $cart .= "<th>".$this->lang->line('cart_desc')."</th>";
 $cart .= "<th>".$this->lang->line('cart_price')."</th>";
 $cart .= "<th>".$this->lang->line('cart_sub')."</th>";
 $cart .= "</tr>";

		$order_details = $this->MFuncs->GetOrderDetails($data['orderdata']['id']);
		if ($order_details) {
		$total = 0;
		$weight = 0;
		$bot_num = 0;
		$pack_total = 0;
		$ship_total = 0;

    	foreach($order_details as $result=>$order_det):
        $product_details = $this->MFuncs->getProductDetails($order_det['product_id']);
		$product_category = $this->MFuncs->getProductCat($order_det['product_id']);
		$product_category_name = $this->MFuncs->getCategory($product_category['cat_id']);
		$product_sub_category = $this->MFuncs->getProductSubCat($order_det['product_id']);
		if ($product_sub_category) {
		$product_sub_category_name = $this->MFuncs->getSubCategory($product_sub_category['subcat_id']);
		}
		
 $cart .= "<tr>";
 $cart .= "<td>".$order_det['quantity']."</td>";
 if ($product_sub_category) {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_sub_category_name['name']."-".$product_details['name']."</td>";
 } else {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_details['name']."</td>";
 }
 $cart .= "<td>".number_format($order_det['price'], 2, '.', '')."</td>";
 $cart .= "<td>&euro; ".number_format($order_det['price']*$order_det['quantity'], 2, '.', '')."</td>";
 $total = $total + $order_det['price']*$order_det['quantity'];
 $weight = $weight + ($product_details['weight'] * $order_det['quantity']);
 if ($product_category['cat_id']!='7') { 
          $bot_num = $bot_num + $order_det['quantity']; 
		  }
$cart .= "</tr>";
    	endforeach;
 $pay_on_arrival_cost=0;
 $can_ship=true;
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
  if ($data['orderdata']['offer_code']!=0) {
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_discount')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total*$data['orderdata']['offer_code'], 2, '.', '')."</td>";
 $cart .= "</tr>";
 $total = $total - ($total*$data['orderdata']['offer_code']);
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
 }

//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $cart .= "<td>&euro; ".$total - $total/1.21."</td>";
// $cart .= "</tr>";
// $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
// $cart .= "<td>&euro; ".$total."</td>";
// $cart .= "</tr>";

         if (($data['orderdata']['same_address']=='No') && ($data['orderdata']['country_id']!='1')) { 
        if ($data['orderdata']['ship_method']=='courier') { 
        	//$rounded_weight = round($weight/1000, 2);
	   		$rounded_weight = ceil(($weight/1000)*2)/2;
			if ($data['orderdata']['same_address']=='No') {
			$c_id = $data['orderdata']['country_id'];
			} else { 
			$c_id = $data['userdata']['country_id'];
			}
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getFed_Ex_Cost($rounded_weight, $country_zone['zones']);
			$ship_total = ($value['price']*0.152) + $value['price'];
			if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			}
			$ship_total = number_format($ship_total, 2, '.', ''); 
         }
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";
         } elseif (($data['orderdata']['same_address']=='Yes') && ($data['userdata']['country_id']!='1')) { 
        if ($data['orderdata']['ship_method']=='courier') { 
        	//$rounded_weight = round($weight/1000, 2);
	   		$rounded_weight = ceil(($weight/1000)*2)/2;
			if ($data['orderdata']['same_address']=='No') {
			$c_id = $data['orderdata']['country_id'];
			} else { 
			$c_id = $data['userdata']['country_id'];
			}
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getFed_Ex_Cost($rounded_weight, $country_zone['zones']);
			$ship_total = ($value['price']*0.152) + $value['price'];
			if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			}
			$ship_total = number_format($ship_total, 2, '.', ''); 
         }
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";

//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//$cart .= "<td>&euro; ".$ship_total."</td>";
//$cart .= "</tr>";
//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//$cart .= "</tr>";
         } else { 
 
 if (($data['orderdata']['ship_method']=='courier') || ($data['orderdata']['ship_method']=='elta')){
		   $pack_total = (ceil($bot_num/2))*0.53;
           if ($data['orderdata']['ship_dest']=='attica-center') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(0, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(2.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(4.96, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-suberbs') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(6.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(9.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-suberbs-out') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(5.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(9.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(13.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-rest') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(2.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(4.96, 2, '.', '');
			   } else {
			   $ship_total = number_format(6.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-peir') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(6.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(9.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-peir-out') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(5.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(9.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(13.90, 2, '.', '');
			   }
/////
//			   if ($weight == 0) { 
//			   $ship_total = number_format(0, 2, '.', '');
//			   } 
//			   elseif ($weight < 3000) {
//			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
//			   $ship_total = number_format(3.57, 2, '.', '');
//			   } else {
//			   //$ship_total = 3.45 + $pack_total;
//			   $ship_total = 3.57;
//			   $weight = $weight - 3000;
//			   $i = ceil($weight/1000);
//			   $ship_total = number_format($ship_total + ($i*1.00), 2, '.', '');
//			   }

		   } elseif ($data['orderdata']['ship_dest']=='attica') { 
             $i = ceil($weight/1000);
			 if ($data['orderdata']['ship_method']=='courier') {
             if ($i>35) { 
             $can_ship=false;
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_attica_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_attica_cost');
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else { 
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_attica_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } 
            
             } 
	   
		   } elseif ($data['orderdata']['ship_dest']=='greece') { 
             $i = ceil($weight/1000); 
			 if ($data['orderdata']['ship_method']=='courier') { 
             if ($i>35) { 
             $can_ship=false; 
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_greece_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_greece_cost');
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else {
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_greece_cost');
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', '');
			 } else {
             $ship_total = number_format(0, 2, '.', '');
             } 
             } 
            
             } 
 		   } elseif ($data['orderdata']['ship_dest']=='crete') { 
             $i = ceil($weight/1000);
			 if ($data['orderdata']['ship_method']=='courier') { 
             if ($i>35) { 
             $can_ship=false; 
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_crete_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_crete_cost'); 
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else { 
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_crete_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } 
            
             } 
         
          
           } 
         if ($can_ship==false) {
$cart .= "<tr>";
$cart .= "<td colspan='1'></td>";
$cart .= "<td colspan='3'><strong>".$this->lang->line('cannot_ship_txt')."</strong></td>";
$cart .= "</tr>";
        $ship_total=0;
          } else {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
         } 
 if (($data['orderdata']['ship_dest']=='attica') || ($data['orderdata']['ship_dest']=='greece') || ($data['orderdata']['ship_dest']=='crete')) {
	  if ($data['orderdata']['pay_method']=='Cash') {
		  if ($data['orderdata']['ship_method']=='elta') {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('cash_on_delivery_total')."</strong></td>";
$pay_on_arrival_cost = number_format(2.30, 2, '.', '');
$cart .= "<td>&euro; ".number_format($pay_on_arrival_cost, 2, '.', '')."</td>";
$cart .= "</tr>";
         } elseif ($data['orderdata']['ship_method']=='courier') {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('cash_on_delivery_total')."</strong></td>";
$pay_on_arrival_cost = number_format(5.17, 2, '.', '');
$cart .= "<td>&euro; ".number_format($pay_on_arrival_cost, 2, '.', '')."</td>";
$cart .= "</tr>";
          } 
      }        
  }
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total + $pay_on_arrival_cost."</td>";
$cart .= "</tr>";


//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//$cart .= "<td>&euro; ".$ship_total."</td>";
//$cart .= "</tr>";
//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//$cart .= "</tr>";
         } elseif ($data['orderdata']['ship_method']=='day_delivery') {
        		$ship_total = number_format(14.76, 2, '.', '');
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";
				
//				$cart .= "<tr>";
//				$cart .= "<td colspan='2'></td>";
//				$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//				$cart .= "<td>&euro; ".$ship_total."</td>";
//				$cart .= "</tr>";
//				$cart .= "<tr>";
//				$cart .= "<td colspan='2'></td>";
//				$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//				$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//				$cart .= "</tr>";
		 }
		 }
	}
 $cart .= "</table>";
 $cart .= "<Br>";
 $cart .= "<em>".$this->lang->line('vat_included_cart')."</em>";
 if (($data['orderdata']['ship_method']=='courier') || ($data['orderdata']['ship_method']=='day_delivery') || ($data['orderdata']['ship_method']=='elta')) {
 if ($data['orderdata']['ship_method']=='courier') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('courier_delivery')."</h4>";
 } elseif ($data['orderdata']['ship_method']=='elta') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('elta_delivery')."</h4>";
 } else {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('day_delivery')."</h4>";
 }
 $cart .= "<h4>".$this->lang->line('delivery_address')."</h4>";
 if ($data['orderdata']['same_address']=='Yes') {
 $country_zone = $this->MFuncs->getCountryZone($data['userdata']['country_id']);
 $cart .= "<h4>".$data['userdata']['address'].", ".$data['userdata']['city'].", ".$data['userdata']['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$data['userdata']['floor'].", ".$this->lang->line('name_bell').": ".$data['userdata']['name_bell']."<br>".$this->lang->line('tel').": ".$data['userdata']['tel'].", ".$this->lang->line('mob').": ".$data['userdata']['mob']."</h4>";
 }else { 
  $country_zone = $this->MFuncs->getCountryZone($data['orderdata']['country_id']);
 $cart .= "<h4>".$data['orderdata']['address'].", ".$data['orderdata']['city'].", ".$data['orderdata']['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$data['orderdata']['floor'].", ".$this->lang->line('name_bell').": ".$data['orderdata']['name_bell']."<br>".$this->lang->line('tel').": ".$data['userdata']['tel'].", ".$this->lang->line('mob').": ".$data['userdata']['mob']."</h4>";
 } 
 } else {
  $cart .= "<h4>".$this->lang->line('pickup_title')."</h4>";
  $cart .= "<h4>".$this->lang->line('pickup_txt')."</h4>";
 }
  if ($data['orderdata']['pay_method']=='Cash') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('cash_on_delivery')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='Bank') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('bank_deposit')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='Credit') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('credit_card')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='PayPal') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('pay_pal')."</h4>";
 }
 $cart .= "<Br>";
  if ($data['orderdata']['receipt_type']=='receipt') {
 $cart .= "<h4>".$this->lang->line('receipt_type')."</h4>";
 $cart .= "<h4>".$this->lang->line('type_receipt')."</h4>";
 } elseif ($data['orderdata']['receipt_type']=='invoice') {
 $cart .= "<h4>".$this->lang->line('receipt_type')."</h4>";
 $cart .= "<h4>".$this->lang->line('type_invoice')."</h4>";
 $invoice_details = $this->MFuncs->getInvoiceDetails($data['orderdata']['id']);
 	if ($invoice_details) { 
	 $cart .= "<Br>";
	 $cart .= "<p>".$this->lang->line('cmp_name').": ".$invoice_details['cmp_name']."<Br>";
	 $cart .= $this->lang->line('cmp_occupation').": ".$invoice_details['cmp_occupation']."<Br>";
	 $cart .= $this->lang->line('cmp_afm').": ".$invoice_details['cmp_afm']."<Br>";
	 $cart .= $this->lang->line('cmp_address').": ".$invoice_details['cmp_address']."<Br>";
	 $cart .= $this->lang->line('cmp_city').": ".$invoice_details['cmp_city']."<Br>";
	 $cart .= $this->lang->line('cmp_doy').": ".$invoice_details['cmp_doy']."</p>";
	}
 }

			$data['msg_title'] = "A new order has been made by ".$data['userdata']['fname']." ".$data['userdata']['lname'];
			$data['comments'] = "The order details are the following:".br(2).$cart;
			$data['post_msg'] = "";
			
			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);

			#Email send to the company!
			$this->email->from('no-reply@wines2u.gr', $data['userdata']['fname']." ".$data['userdata']['lname']." ".$data['userdata']['email']);
			$this->email->to('info@wines2u.gr', 'www.wines2u.gr');
			$this->email->cc('b.a@wines2u.gr', 'www.wines2u.gr');
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
	
			$data['msg_title'] = $this->lang->line('dear')." ".$data['userdata']['fname']." ".$data['userdata']['lname'].",".br(1).$this->lang->line('order_msg');
			$data['comments'] = $this->lang->line('order_details_msg').br(2).$cart;
			$data['post_msg'] = $this->lang->line('contact_dept').br(1);

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);
		
			#Email send to the user
			$this->email->from('no-reply@wines2u.gr', 'www.wines2u.gr');
			$this->email->to($data['userdata']['email']);
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
			
		$data['order_cart'] = $cart;
}
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$this->MFuncs->finaliseOrder($order_id);
		$this->cart->destroy();
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('thank_you');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['main'] = 'step_4';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function step_4_new2() {
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);

 if ($data['orderdata']) { 
 $cart = "<table class='full' width='100%' border='0'>";
 $cart .= "<tr>";
 $cart .= "<th>".$this->lang->line('cart_qty')."</th>";
 $cart .= "<th>".$this->lang->line('cart_desc')."</th>";
 $cart .= "<th>".$this->lang->line('cart_price')."</th>";
 $cart .= "<th>".$this->lang->line('cart_sub')."</th>";
 $cart .= "</tr>";

		$order_details = $this->MFuncs->GetOrderDetails($data['orderdata']['id']);
		if ($order_details) {
		$total = 0;
		$weight = 0;
		$bot_num = 0;
		$pack_total = 0;
		$ship_total = 0;

    	foreach($order_details as $result=>$order_det):
        $product_details = $this->MFuncs->getProductDetails($order_det['product_id']);
		$product_category = $this->MFuncs->getProductCat($order_det['product_id']);
		$product_category_name = $this->MFuncs->getCategory($product_category['cat_id']);
		$product_sub_category = $this->MFuncs->getProductSubCat($order_det['product_id']);
		if ($product_sub_category) {
		$product_sub_category_name = $this->MFuncs->getSubCategory($product_sub_category['subcat_id']);
		}
		
 $cart .= "<tr>";
 $cart .= "<td>".$order_det['quantity']."</td>";
 if ($product_sub_category) {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_sub_category_name['name']."-".$product_details['name']."</td>";
 } else {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_details['name']."</td>";
 }
 $cart .= "<td>".number_format($order_det['price'], 2, '.', '')."</td>";
 $cart .= "<td>&euro; ".number_format($order_det['price']*$order_det['quantity'], 2, '.', '')."</td>";
 $total = $total + $order_det['price']*$order_det['quantity'];
 $weight = $weight + ($product_details['weight'] * $order_det['quantity']);
 if ($product_category['cat_id']!='7') { 
          $bot_num = $bot_num + $order_det['quantity']; 
		  }
$cart .= "</tr>";
    	endforeach;
 $pay_on_arrival_cost=0;
 $can_ship=true;
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
 if ($data['orderdata']['offer_code']!=0) {
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_discount')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total*$data['orderdata']['offer_code'], 2, '.', '')."</td>";
 $cart .= "</tr>";
 $total = $total - ($total*$data['orderdata']['offer_code']);
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
 }
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $cart .= "<td>&euro; ".$total - $total/1.21."</td>";
// $cart .= "</tr>";
// $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
// $cart .= "<td>&euro; ".$total."</td>";
// $cart .= "</tr>";
        if ($data['orderdata']['same_address']=='No') { 
 			$c_id = $data['orderdata']['country_id']; 
        } elseif ($data['orderdata']['same_address']=='Yes') {
            $c_id = $data['userdata']['country_id'];
        }
        if ($c_id!='1') { 
        if ($data['orderdata']['ship_method']=='courier_economy') { 
	   		$rounded_weight = ceil($weight/1000);
			$insurance_cost = $rounded_weight*0.05;
			if ($insurance_cost>10) { $insurance_cost=10; }
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getTNT_Cost_economy($rounded_weight, $country_zone['tnt_zones']);
			$ship_total = ($value['price']*0.205) + $value['price'];
			//if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			//}
			$ship_total = $insurance_cost + $ship_total;
			$ship_total = number_format($ship_total, 2, '.', '');
        } elseif ($data['orderdata']['ship_method']=='courier_express') { 
	   		$rounded_weight = ceil($weight/1000);
			$insurance_cost = $rounded_weight*0.05;
			if ($insurance_cost>10) { $insurance_cost=10; }
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			if ($rounded_weight<=30) {
			$value = $this->MFuncs->getTNT_Cost_express($rounded_weight, $country_zone['tnt_zones_express']);
			$total_ship_cost = $value['price'];
			} else {
			$value = $this->MFuncs->getTNT_Cost_express(30, $country_zone['tnt_zones_express']);
			$extra_cost_pk = $this->MFuncs->getTNT_extra_Cost($country_zone['tnt_zones_express']);
			$extra_ship_cost = (($rounded_weight-30) * $extra_cost_pk['price']);
			$total_ship_cost = $extra_ship_cost + $value['price'];
			}
			$ship_total = ($total_ship_cost*0.205) + $total_ship_cost;
			//if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			//}
			$ship_total = $insurance_cost + $ship_total;
			$ship_total = number_format($ship_total, 2, '.', '');
         }
            $cart .= "<tr>";
            $cart .= "<td colspan='2'></td>";
            $cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
            $cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
            $cart .= "</tr>";
			$cart .= "<tr>";
			$cart .= "<td colspan='2'></td>";
			$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
			$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
			$cart .= "</tr>";


         } else { 
 
 if (($data['orderdata']['ship_method']=='courier') || ($data['orderdata']['ship_method']=='elta')){
		   $pack_total = (ceil($bot_num/2))*0.53;
           if ($data['orderdata']['ship_dest']=='attica-center') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(0, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(2.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(4.96, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-suberbs') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(6.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(9.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-suberbs-out') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(5.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(9.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(13.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-rest') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(2.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(4.96, 2, '.', '');
			   } else {
			   $ship_total = number_format(6.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-peir') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(6.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(9.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-peir-out') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(5.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(9.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(13.90, 2, '.', '');
			   }
/////
//			   if ($weight == 0) { 
//			   $ship_total = number_format(0, 2, '.', '');
//			   } 
//			   elseif ($weight < 3000) {
//			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
//			   $ship_total = number_format(3.57, 2, '.', '');
//			   } else {
//			   //$ship_total = 3.45 + $pack_total;
//			   $ship_total = 3.57;
//			   $weight = $weight - 3000;
//			   $i = ceil($weight/1000);
//			   $ship_total = number_format($ship_total + ($i*1.00), 2, '.', '');
//			   }

		   } elseif ($data['orderdata']['ship_dest']=='attica') { 
             $i = ceil($weight/1000);
			 if ($data['orderdata']['ship_method']=='courier') {
             if ($i>35) { 
             $can_ship=false;
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_attica_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_attica_cost');
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else { 
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_attica_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } 
            
             } 
	   
		   } elseif ($data['orderdata']['ship_dest']=='greece') { 
             $i = ceil($weight/1000); 
			 if ($data['orderdata']['ship_method']=='courier') { 
             if ($i>35) { 
             $can_ship=false; 
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_greece_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_greece_cost');
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else {
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_greece_cost');
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', '');
			 } else {
             $ship_total = number_format(0, 2, '.', '');
             } 
             } 
            
             } 
 		   } elseif ($data['orderdata']['ship_dest']=='crete') { 
             $i = ceil($weight/1000);
			 if ($data['orderdata']['ship_method']=='courier') { 
             if ($i>35) { 
             $can_ship=false; 
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_crete_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_crete_cost'); 
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else { 
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_crete_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } 
            
             } 
         
          
           } 
         if ($can_ship==false) {
$cart .= "<tr>";
$cart .= "<td colspan='1'></td>";
$cart .= "<td colspan='3'><strong>".$this->lang->line('cannot_ship_txt')."</strong></td>";
$cart .= "</tr>";
        $ship_total=0;
          } else {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
         } 
 if (($data['orderdata']['ship_dest']=='attica') || ($data['orderdata']['ship_dest']=='greece') || ($data['orderdata']['ship_dest']=='crete')) {
	  if ($data['orderdata']['pay_method']=='Cash') {
		  if ($data['orderdata']['ship_method']=='elta') {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('cash_on_delivery_total')."</strong></td>";
$pay_on_arrival_cost = number_format(2.30, 2, '.', '');
$cart .= "<td>&euro; ".number_format($pay_on_arrival_cost, 2, '.', '')."</td>";
$cart .= "</tr>";
         } elseif ($data['orderdata']['ship_method']=='courier') {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('cash_on_delivery_total')."</strong></td>";
$pay_on_arrival_cost = number_format(5.17, 2, '.', '');
$cart .= "<td>&euro; ".number_format($pay_on_arrival_cost, 2, '.', '')."</td>";
$cart .= "</tr>";
          } 
      }        
  }
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total + $pay_on_arrival_cost."</td>";
$cart .= "</tr>";


//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//$cart .= "<td>&euro; ".$ship_total."</td>";
//$cart .= "</tr>";
//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//$cart .= "</tr>";
         } elseif ($data['orderdata']['ship_method']=='day_delivery') {
        		$ship_total = number_format(14.76, 2, '.', '');
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";
				
//				$cart .= "<tr>";
//				$cart .= "<td colspan='2'></td>";
//				$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//				$cart .= "<td>&euro; ".$ship_total."</td>";
//				$cart .= "</tr>";
//				$cart .= "<tr>";
//				$cart .= "<td colspan='2'></td>";
//				$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//				$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//				$cart .= "</tr>";
		 }
		 }
	}
 $cart .= "</table>";
 $cart .= "<Br>";
 $cart .= "<em>".$this->lang->line('vat_included_cart')."</em>";
 if (($data['orderdata']['ship_method']=='courier') || ($data['orderdata']['ship_method']=='day_delivery') || ($data['orderdata']['ship_method']=='elta') || ($data['orderdata']['ship_method']=='courier_economy') || ($data['orderdata']['ship_method']=='courier_express')) {
 
 if ($data['orderdata']['ship_method']=='courier_economy') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('courier_delivery_abroad_economy')."</h4>";
 } elseif ($data['orderdata']['ship_method']=='courier_express') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('courier_delivery_abroad_express')."</h4>";
 } elseif ($data['orderdata']['ship_method']=='courier') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('courier_delivery')."</h4>";
 } elseif ($data['orderdata']['ship_method']=='elta') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('elta_delivery')."</h4>";
 } else {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('day_delivery')."</h4>";
 }
 $cart .= "<h4>".$this->lang->line('delivery_address')."</h4>";
 if ($data['orderdata']['same_address']=='Yes') {
 $country_zone = $this->MFuncs->getCountryZone($data['userdata']['country_id']);
 $cart .= "<h4>".$data['userdata']['address'].", ".$data['userdata']['city'].", ".$data['userdata']['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$data['userdata']['floor'].", ".$this->lang->line('name_bell').": ".$data['userdata']['name_bell']."<br>".$this->lang->line('tel').": ".$data['userdata']['tel'].", ".$this->lang->line('mob').": ".$data['userdata']['mob']."</h4>";
 }else { 
  $country_zone = $this->MFuncs->getCountryZone($data['orderdata']['country_id']);
 $cart .= "<h4>".$data['orderdata']['address'].", ".$data['orderdata']['city'].", ".$data['orderdata']['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$data['orderdata']['floor'].", ".$this->lang->line('name_bell').": ".$data['orderdata']['name_bell']."<br>".$this->lang->line('tel').": ".$data['userdata']['tel'].", ".$this->lang->line('mob').": ".$data['userdata']['mob']."</h4>";
 } 
 } else {
  $cart .= "<h4>".$this->lang->line('pickup_title')."</h4>";
  $cart .= "<h4>".$this->lang->line('pickup_txt')."</h4>";
 }
  if ($data['orderdata']['pay_method']=='Cash') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('cash_on_delivery')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='Bank') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('bank_deposit')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='Credit') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('credit_card')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='PayPal') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('pay_pal')."</h4>";
 }
 $cart .= "<Br>";
  if ($data['orderdata']['receipt_type']=='receipt') {
 $cart .= "<h4>".$this->lang->line('receipt_type')."</h4>";
 $cart .= "<h4>".$this->lang->line('type_receipt')."</h4>";
 } elseif ($data['orderdata']['receipt_type']=='invoice') {
 $cart .= "<h4>".$this->lang->line('receipt_type')."</h4>";
 $cart .= "<h4>".$this->lang->line('type_invoice')."</h4>";
 $invoice_details = $this->MFuncs->getInvoiceDetails($data['orderdata']['id']);
 	if ($invoice_details) { 
	 $cart .= "<Br>";
	 $cart .= "<p>".$this->lang->line('cmp_name').": ".$invoice_details['cmp_name']."<Br>";
	 $cart .= $this->lang->line('cmp_occupation').": ".$invoice_details['cmp_occupation']."<Br>";
	 $cart .= $this->lang->line('cmp_afm').": ".$invoice_details['cmp_afm']."<Br>";
	 $cart .= $this->lang->line('cmp_address').": ".$invoice_details['cmp_address']."<Br>";
	 $cart .= $this->lang->line('cmp_city').": ".$invoice_details['cmp_city']."<Br>";
	 $cart .= $this->lang->line('cmp_doy').": ".$invoice_details['cmp_doy']."</p>";
	}
 }

			$data['msg_title'] = "A new order has been made by ".$data['userdata']['fname']." ".$data['userdata']['lname'];
			$data['comments'] = "The order details are the following:".br(2).$cart;
			$data['post_msg'] = "";
			
			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);

			#Email send to the company!
			$this->email->from('no-reply@wines2u.gr', $data['userdata']['fname']." ".$data['userdata']['lname']." ".$data['userdata']['email']);
			$this->email->to('info@wines2u.gr', 'www.wines2u.gr');
			$this->email->cc('b.a@wines2u.gr', 'www.wines2u.gr');
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
	
			$data['msg_title'] = $this->lang->line('dear')." ".$data['userdata']['fname']." ".$data['userdata']['lname'].",".br(1).$this->lang->line('order_msg');
			$data['comments'] = $this->lang->line('order_details_msg').br(2).$cart;
			$data['post_msg'] = $this->lang->line('contact_dept').br(1);

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);
		
			#Email send to the user
			$this->email->from('no-reply@wines2u.gr', 'www.wines2u.gr');
			$this->email->to($data['userdata']['email']);
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
			
		$data['order_cart'] = $cart;
}
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$this->MFuncs->finaliseOrder($order_id);
		$this->cart->destroy();
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('thank_you');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['main'] = 'step_4';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function validation(){
		$ld=$this->session->userdata('lang_id');
		$order_ref =$this->session->userdata('order_ref');
		$B_merch_ID = $_POST["Shop"];
		$B_amount = $_POST["Amount"];
		$B_curr = trim($_POST["Currency"]);
		$B_order_id = $_POST["Ref"];

		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);

		$orderdata = $this->MFuncs->GetOrderbyRef($B_order_id);
		$total = 0;
		$super_total = 0;
		$gen_total = 0;
		$weight = 0;
		$bot_num = 0;
		$pack_total = 0;
		$ship_total = 0;
		if ($orderdata) { 
		$order_details = $this->MFuncs->GetOrderDetails($orderdata['id']);
		foreach($order_details as $result=>$order_det):
		$product_details = $this->MFuncs->getProductDetails($order_det['product_id']); 
		$product_category = $this->MFuncs->getProductCat($order_det['product_id']);
		$total = $total + $order_det['price']*$order_det['quantity'];
		$weight = $weight + ($product_details['weight'] * $order_det['quantity']);
		if ($product_category['cat_id']!='7') {
          $bot_num = $bot_num + $order_det['quantity']; 
		}
		endforeach;
		//$sum = number_format($total, 2, '.', '');
		   if ($orderdata['ship_method']=='courier') {
           $pack_total = (ceil($bot_num/2))*0.53;
           if ($orderdata['ship_dest']=='attica') {
			   if ($weight == 0) { 
			   $ship_total = number_format(0, 2, '.', '');
			   } 
		   elseif ($weight < 3000) {
		   $ship_total = number_format(3.57, 2, '.', '');
		   } else {
		   $ship_total = 3.57;
		   $weight = $weight - 2000;
		   $i = ceil($weight/1000);
		   $ship_total = number_format($ship_total + ($i*1.23), 2, '.', '');
		   }
		   } else {
		   if ($weight < 3000) {
		   $ship_total = 6.20; 
		   } else {
		   $ship_total = 6.20;
		   $weight = $weight - 2000;
		   $i = ceil($weight/1000);
		   $ship_total = number_format($ship_total + ($i*1.85), 2, '.', '');
		   }
		   }
		   $gen_total = $ship_total + $total;
		   }
		   if ($orderdata['ship_method']=='courier') {
		   $super_total = $gen_total;
		   } else { 
		   $super_total = $total;
		   }
		   $sum = number_format($super_total, 2, '.', '');
		if (($B_merch_ID=="90003432") && ($B_amount==$sum) && ($B_curr=="978") && ($B_order_id==$orderdata['ref'])) {
		echo "[OK]";
		} else {
		echo "[BAD], ".$B_merch_ID."=90003432, ".$B_amount."=".$sum.", ".$B_curr."=978, ".$B_order_id."=".$orderdata['ref'];
		}
		}else {
		echo "[NOK], Shop: ".$B_merch_ID."=90003432, Amount: ".$B_amount."=".$sum.", Currency: ".$B_curr."=978, Ref: ".$B_order_id."=".$orderdata['ref'];
		}
	}
function complete_payment(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);

 if ($data['orderdata']) { 
 $cart = "<table class='full' width='100%' border='0'>";
 $cart .= "<tr>";
 $cart .= "<th>".$this->lang->line('cart_qty')."</th>";
 $cart .= "<th>".$this->lang->line('cart_desc')."</th>";
 $cart .= "<th>".$this->lang->line('cart_price')."</th>";
 $cart .= "<th>".$this->lang->line('cart_sub')."</th>";
 $cart .= "</tr>";

		$order_details = $this->MFuncs->GetOrderDetails($data['orderdata']['id']);
		if ($order_details) {
		$total = 0;
		
		$weight = 0;
		$bot_num = 0;
		$pack_total = 0;
		$ship_total = 0;

    	foreach($order_details as $result=>$order_det):
        $product_details = $this->MFuncs->getProductDetails($order_det['product_id']);
		$product_category = $this->MFuncs->getProductCat($order_det['product_id']);

		$product_category_name = $this->MFuncs->getCategory($product_category['cat_id']);
		$product_sub_category = $this->MFuncs->getProductSubCat($order_det['product_id']);
  		if ($product_sub_category) {
		$product_sub_category_name = $this->MFuncs->getSubCategory($product_sub_category['subcat_id']);
		}
		
 $cart .= "<tr>";
 $cart .= "<td>".$order_det['quantity']."</td>";
  if ($product_sub_category) {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_sub_category_name['name']."-".$product_details['name']."</td>";
 } else {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_details['name']."</td>";
 }
 $cart .= "<td>".number_format($order_det['price'], 2, '.', '')."</td>";
 $cart .= "<td>&euro; ".number_format($order_det['price']*$order_det['quantity'], 2, '.', '')."</td>";
 $total = $total + $order_det['price']*$order_det['quantity'];
 $weight = $weight + ($product_details['weight'] * $order_det['quantity']);
 if ($product_category['cat_id']!='7') { 
          $bot_num = $bot_num + $order_det['quantity']; 
		  }
 $cart .= "</tr>";
    	endforeach;
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
 if ($data['orderdata']['offer_code']!=0) {
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_discount')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total*$data['orderdata']['offer_code'], 2, '.', '')."</td>";
 $cart .= "</tr>";
 $total = $total - ($total*$data['orderdata']['offer_code']);
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
 }
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $cart .= "<td>&euro; ".$total - $total/1.21."</td>";
// $cart .= "</tr>";
// $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
// $cart .= "<td>&euro; ".$total."</td>";
// $cart .= "</tr>";

        if (($data['orderdata']['same_address']=='No') && ($data['orderdata']['country_id']!='1')) { 
        if ($data['orderdata']['ship_method']=='courier') { 
        	//$rounded_weight = round($weight/1000, 2);
	   		$rounded_weight = ceil(($weight/1000)*2)/2;
			if ($data['orderdata']['same_address']=='No') {
			$c_id = $data['orderdata']['country_id'];
			} else { 
			$c_id = $data['userdata']['country_id'];
			}
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getFed_Ex_Cost($rounded_weight, $country_zone['zones']);
			$ship_total = ($value['price']*0.152) + $value['price'];
			if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			}
			$ship_total = number_format($ship_total, 2, '.', ''); 
         }
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";

//	$cart .= "<tr>";
//	$cart .= "<td colspan='2'></td>";
//	$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//	$cart .= "<td>&euro; ".$ship_total."</td>";
//	$cart .= "</tr>";
//	$cart .= "<tr>";
//	$cart .= "<td colspan='2'></td>";
//	$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//	$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//	$cart .= "</tr>";
         } elseif (($data['orderdata']['same_address']=='Yes') && ($data['userdata']['country_id']!='1')) { 
        if ($data['orderdata']['ship_method']=='courier') { 
        	//$rounded_weight = round($weight/1000, 2);
	   		$rounded_weight = ceil(($weight/1000)*2)/2;
			if ($data['orderdata']['same_address']=='No') {
			$c_id = $data['orderdata']['country_id'];
			} else { 
			$c_id = $data['userdata']['country_id'];
			}
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getFed_Ex_Cost($rounded_weight, $country_zone['zones']);
			$ship_total = ($value['price']*0.152) + $value['price'];
			if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			}
			$ship_total = number_format($ship_total, 2, '.', ''); 
         }
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";


//	$cart .= "<tr>";
//	$cart .= "<td colspan='2'></td>";
//	$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//	$cart .= "<td>&euro; ".$ship_total."</td>";
//	$cart .= "</tr>";
//	$cart .= "<tr>";
//	$cart .= "<td colspan='2'></td>";
//	$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//	$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//	$cart .= "</tr>";
         } else { 

 if ($data['orderdata']['ship_method']=='courier') {
 $pack_total = (ceil($bot_num/2))*0.53;
           if ($data['orderdata']['ship_dest']=='attica') {
			   if ($weight == 0) { 
			   $ship_total = number_format(0, 2, '.', '');
			   } 
			   elseif ($weight < 3000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.57, 2, '.', '');
			   } else {
			   //$ship_total = 3.45 + $pack_total;
			   $ship_total = 3.57;
			   $weight = $weight - 3000;
			   $i = ceil($weight/1000);
			   $ship_total = number_format($ship_total + ($i*1.23), 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='greece') {
			   if ($weight == 0) { 
			   $ship_total = number_format(0, 2, '.', '');
			   } 
			   elseif ($weight < 5000) {
			   $ship_total = 5.90; 
			   $ship_total = number_format($ship_total, 2, '.', '');
			   } elseif ($weight < 10000){
			   $ship_total = 10.58;
			   //$weight = $weight - 2000;
			   //$i = ceil($weight/1000);
			   $ship_total = number_format($ship_total, 2, '.', '');
			   } else {
			   $ship_total = 16.48;
			   //$weight = $weight - 2000;
			   //$i = ceil($weight/1000);
			   $ship_total = number_format($ship_total, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='islands') {
			   if ($weight == 0) { 
			   $ship_total = number_format(0, 2, '.', '');
			   } 
			   elseif ($weight < 5000) {
			   $ship_total = 8.86; 
			   $ship_total = number_format($ship_total, 2, '.', '');
			   } elseif ($weight < 10000){
			   $ship_total = 15.87;
			   //$weight = $weight - 2000;
			   //$i = ceil($weight/1000);
			   $ship_total = number_format($ship_total, 2, '.', '');
			   } else {
			   $ship_total = 24.60;
			   //$weight = $weight - 2000;
			   //$i = ceil($weight/1000);
			   $ship_total = number_format($ship_total, 2, '.', '');
			   }
			}
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";


//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//$cart .= "<td>&euro; ".$ship_total."</td>";
//$cart .= "</tr>";
//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//$cart .= "</tr>";
         } elseif ($data['orderdata']['ship_method']=='day_delivery') {
        		$ship_total = number_format(14.76, 2, '.', '');
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";

				
//				$cart .= "<tr>";
//				$cart .= "<td colspan='2'></td>";
//				$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//				$cart .= "<td>&euro; ".$ship_total."</td>";
//				$cart .= "</tr>";
//				$cart .= "<tr>";
//				$cart .= "<td colspan='2'></td>";
//				$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//				$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//				$cart .= "</tr>";
		 }
	   }
	}
 $cart .= "</table>";
 $cart .= "<Br>";
 $cart .= "<em>".$this->lang->line('vat_included_cart')."</em>";
 if (($data['orderdata']['ship_method']=='courier') || ($data['orderdata']['ship_method']=='day_delivery')) {
  if ($data['orderdata']['ship_method']=='courier') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('courier_delivery')."</h4>";
 } else {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('day_delivery')."</h4>";
 }
 $cart .= "<h4>".$this->lang->line('delivery_address')."</h4>";
 if ($data['orderdata']['same_address']=='Yes') {
 $country_zone = $this->MFuncs->getCountryZone($data['userdata']['country_id']);
 $cart .= "<h4>".$data['userdata']['address'].", ".$data['userdata']['city'].", ".$data['userdata']['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$data['userdata']['floor'].", ".$this->lang->line('name_bell').": ".$data['userdata']['name_bell']."<br>".$this->lang->line('tel').": ".$data['userdata']['tel'].", ".$this->lang->line('mob').": ".$data['userdata']['mob']."</h4>";
 }else { 
 $country_zone = $this->MFuncs->getCountryZone($data['orderdata']['country_id']);
 $cart .= "<h4>".$data['orderdata']['address'].", ".$data['orderdata']['city'].", ".$data['orderdata']['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$data['orderdata']['floor'].", ".$this->lang->line('name_bell').": ".$data['orderdata']['name_bell']."<br>".$this->lang->line('tel').": ".$data['userdata']['tel'].", ".$this->lang->line('mob').": ".$data['userdata']['mob']."</h4>";
 } 
 } else {
  $cart .= "<h4>".$this->lang->line('pickup_title')."</h4>";
  $cart .= "<h4>".$this->lang->line('pickup_txt')."</h4>";
 }
  if ($data['orderdata']['pay_method']=='Cash') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('cash_on_delivery')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='Bank') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('bank_deposit')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='Credit') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('credit_card')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='PayPal') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('pay_pal')."</h4>";
 }

 $cart .= "<Br>";
  if ($data['orderdata']['receipt_type']=='receipt') {
 $cart .= "<h4>".$this->lang->line('receipt_type')."</h4>";
 $cart .= "<h4>".$this->lang->line('type_receipt')."</h4>";
 } elseif ($data['orderdata']['receipt_type']=='invoice') {
 $cart .= "<h4>".$this->lang->line('receipt_type')."</h4>";
 $cart .= "<h4>".$this->lang->line('type_invoice')."</h4>";
 $invoice_details = $this->MFuncs->getInvoiceDetails($orderdata['id']);
 	if ($invoice_details) { 
	 $cart .= "<Br>";
	 $cart .= "<p>".$this->lang->line('cmp_name').": ".$invoice_details['cmp_name']."<Br>";
	 $cart .= $this->lang->line('cmp_occupation').": ".$invoice_details['cmp_occupation']."<Br>";
	 $cart .= $this->lang->line('cmp_afm').": ".$invoice_details['cmp_afm']."<Br>";
	 $cart .= $this->lang->line('cmp_address').": ".$invoice_details['cmp_address']."<Br>";
	 $cart .= $this->lang->line('cmp_city').": ".$invoice_details['cmp_city']."<Br>";
	 $cart .= $this->lang->line('cmp_doy').": ".$invoice_details['cmp_doy']."</p>";
	}
 }
			$data['msg_title'] = "A new order has been made by ".$data['userdata']['fname']." ".$data['userdata']['lname'];
			$data['comments'] = "The order details are the following:".br(2).$cart;
			$data['post_msg'] = "";
			
			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);

			#Email send to the company!
			$this->email->from('no-reply@wines2u.gr', $data['userdata']['fname']." ".$data['userdata']['lname']." ".$data['userdata']['email']);
			$this->email->to('info@wines2u.gr', 'www.wines2u.gr');
			$this->email->cc('b.a@wines2u.gr', 'www.wines2u.gr');
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
	
			$data['msg_title'] = $this->lang->line('dear')." ".$data['userdata']['fname']." ".$data['userdata']['lname'].",".br(1).$this->lang->line('order_msg');
			$data['comments'] = $this->lang->line('order_details_msg').br(2).$cart;
			$data['post_msg'] = $this->lang->line('contact_dept').br(1);

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);
		
			#Email send to the user
			$this->email->from('no-reply@wines2u.gr', 'www.wines2u.gr');
			$this->email->to($data['userdata']['email']);
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
			
		$data['order_cart'] = $cart;
}
		$this->MFuncs->finaliseOrderPayed($order_id);
		$this->cart->destroy();
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('successful_payment');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'complete_payment';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function complete_payment_new(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);

 if ($data['orderdata']) { 
 $cart = "<table class='full' width='100%' border='0'>";
 $cart .= "<tr>";
 $cart .= "<th>".$this->lang->line('cart_qty')."</th>";
 $cart .= "<th>".$this->lang->line('cart_desc')."</th>";
 $cart .= "<th>".$this->lang->line('cart_price')."</th>";
 $cart .= "<th>".$this->lang->line('cart_sub')."</th>";
 $cart .= "</tr>";

		$order_details = $this->MFuncs->GetOrderDetails($data['orderdata']['id']);
		if ($order_details) {
		$total = 0;
		
		$weight = 0;
		$bot_num = 0;
		$pack_total = 0;
		$ship_total = 0;

    	foreach($order_details as $result=>$order_det):
        $product_details = $this->MFuncs->getProductDetails($order_det['product_id']);
		$product_category = $this->MFuncs->getProductCat($order_det['product_id']);

		$product_category_name = $this->MFuncs->getCategory($product_category['cat_id']);
		$product_sub_category = $this->MFuncs->getProductSubCat($order_det['product_id']);
  		if ($product_sub_category) {
		$product_sub_category_name = $this->MFuncs->getSubCategory($product_sub_category['subcat_id']);
		}
		
 $cart .= "<tr>";
 $cart .= "<td>".$order_det['quantity']."</td>";
  if ($product_sub_category) {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_sub_category_name['name']."-".$product_details['name']."</td>";
 } else {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_details['name']."</td>";
 }
 $cart .= "<td>".number_format($order_det['price'], 2, '.', '')."</td>";
 $cart .= "<td>&euro; ".number_format($order_det['price']*$order_det['quantity'], 2, '.', '')."</td>";
 $total = $total + $order_det['price']*$order_det['quantity'];
 $weight = $weight + ($product_details['weight'] * $order_det['quantity']);
 if ($product_category['cat_id']!='7') { 
          $bot_num = $bot_num + $order_det['quantity']; 
		  }
 $cart .= "</tr>";
    	endforeach;
$pay_on_arrival_cost=0;
$can_ship=true;
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
 if ($data['orderdata']['offer_code']!=0) {
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_discount')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total*$data['orderdata']['offer_code'], 2, '.', '')."</td>";
 $cart .= "</tr>";
 $total = $total - ($total*$data['orderdata']['offer_code']);
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
 }
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $cart .= "<td>&euro; ".$total - $total/1.21."</td>";
// $cart .= "</tr>";
// $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
// $cart .= "<td>&euro; ".$total."</td>";
// $cart .= "</tr>";

        if (($data['orderdata']['same_address']=='No') && ($data['orderdata']['country_id']!='1')) { 
        if ($data['orderdata']['ship_method']=='courier') { 
        	//$rounded_weight = round($weight/1000, 2);
	   		$rounded_weight = ceil(($weight/1000)*2)/2;
			if ($data['orderdata']['same_address']=='No') {
			$c_id = $data['orderdata']['country_id'];
			} else { 
			$c_id = $data['userdata']['country_id'];
			}
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getFed_Ex_Cost($rounded_weight, $country_zone['zones']);
			$ship_total = ($value['price']*0.152) + $value['price'];
			if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			}
			$ship_total = number_format($ship_total, 2, '.', ''); 
         }
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";

//	$cart .= "<tr>";
//	$cart .= "<td colspan='2'></td>";
//	$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//	$cart .= "<td>&euro; ".$ship_total."</td>";
//	$cart .= "</tr>";
//	$cart .= "<tr>";
//	$cart .= "<td colspan='2'></td>";
//	$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//	$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//	$cart .= "</tr>";
         } elseif (($data['orderdata']['same_address']=='Yes') && ($data['userdata']['country_id']!='1')) { 
        if ($data['orderdata']['ship_method']=='courier') { 
        	//$rounded_weight = round($weight/1000, 2);
	   		$rounded_weight = ceil(($weight/1000)*2)/2;
			if ($data['orderdata']['same_address']=='No') {
			$c_id = $data['orderdata']['country_id'];
			} else { 
			$c_id = $data['userdata']['country_id'];
			}
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getFed_Ex_Cost($rounded_weight, $country_zone['zones']);
			$ship_total = ($value['price']*0.152) + $value['price'];
			if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			}
			$ship_total = number_format($ship_total, 2, '.', ''); 
         }
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";


//	$cart .= "<tr>";
//	$cart .= "<td colspan='2'></td>";
//	$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//	$cart .= "<td>&euro; ".$ship_total."</td>";
//	$cart .= "</tr>";
//	$cart .= "<tr>";
//	$cart .= "<td colspan='2'></td>";
//	$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//	$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//	$cart .= "</tr>";
         } else { 

 if (($data['orderdata']['ship_method']=='courier') || ($data['orderdata']['ship_method']=='elta')) {
$pack_total = (ceil($bot_num/2))*0.53;
           if ($data['orderdata']['ship_dest']=='attica-center') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(0, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(2.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(4.96, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-suberbs') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(6.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(9.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-suberbs-out') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(5.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(9.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(13.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-rest') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(2.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(4.96, 2, '.', '');
			   } else {
			   $ship_total = number_format(6.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-peir') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(6.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(9.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-peir-out') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(5.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(9.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(13.90, 2, '.', '');
			   }
/////
//			   if ($weight == 0) { 
//			   $ship_total = number_format(0, 2, '.', '');
//			   } 
//			   elseif ($weight < 3000) {
//			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
//			   $ship_total = number_format(3.57, 2, '.', '');
//			   } else {
//			   //$ship_total = 3.45 + $pack_total;
//			   $ship_total = 3.57;
//			   $weight = $weight - 3000;
//			   $i = ceil($weight/1000);
//			   $ship_total = number_format($ship_total + ($i*1.00), 2, '.', '');
//			   }

		   } elseif ($data['orderdata']['ship_dest']=='attica') { 
             $i = ceil($weight/1000);
			 if ($data['orderdata']['ship_method']=='courier') {
             if ($i>35) { 
             $can_ship=false;
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_attica_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_attica_cost');
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else { 
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_attica_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 

             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } 
            
             } 
	   
		   } elseif ($data['orderdata']['ship_dest']=='greece') { 
             $i = ceil($weight/1000); 
			 if ($data['orderdata']['ship_method']=='courier') { 
             if ($i>35) { 
             $can_ship=false; 
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_greece_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_greece_cost');
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else {
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_greece_cost');
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', '');
			 } else {
             $ship_total = number_format(0, 2, '.', '');
             } 
             } 
            
             } 
 		   } elseif ($data['orderdata']['ship_dest']=='crete') { 
             $i = ceil($weight/1000);
			 if ($data['orderdata']['ship_method']=='courier') { 
             if ($i>35) { 
             $can_ship=false; 
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_crete_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_crete_cost'); 
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else { 
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_crete_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } 
            
             } 
         
          
           } 
        if ($can_ship==false) {
$cart .= "<tr>";
$cart .= "<td colspan='1'></td>";
$cart .= "<td colspan='3'><strong>".$this->lang->line('cannot_ship_txt')."</strong></td>";
$cart .= "</tr>";
        $ship_total=0;
          } else {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
         } 
 if (($data['orderdata']['ship_dest']=='attica') || ($data['orderdata']['ship_dest']=='greece') || ($data['orderdata']['ship_dest']=='crete')) {
	  if ($data['orderdata']['pay_method']=='Cash') {
		  if ($data['orderdata']['ship_method']=='elta') {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('cash_on_delivery_total')."</strong></td>";
$pay_on_arrival_cost = number_format(2.30, 2, '.', '');
$cart .= "<td>&euro; ".number_format($pay_on_arrival_cost, 2, '.', '')."</td>";
$cart .= "</tr>";
         } elseif ($data['orderdata']['ship_method']=='courier') {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('cash_on_delivery_total')."</strong></td>";
$pay_on_arrival_cost = number_format(5.17, 2, '.', '');
$cart .= "<td>&euro; ".number_format($pay_on_arrival_cost, 2, '.', '')."</td>";
$cart .= "</tr>";
          } 
      }        
  }
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total + $pay_on_arrival_cost."</td>";
$cart .= "</tr>";


//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//$cart .= "<td>&euro; ".$ship_total."</td>";
//$cart .= "</tr>";
//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//$cart .= "</tr>";         
} elseif ($data['orderdata']['ship_method']=='day_delivery') {
        		$ship_total = number_format(14.76, 2, '.', '');
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";

				
//				$cart .= "<tr>";
//				$cart .= "<td colspan='2'></td>";
//				$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//				$cart .= "<td>&euro; ".$ship_total."</td>";
//				$cart .= "</tr>";
//				$cart .= "<tr>";
//				$cart .= "<td colspan='2'></td>";
//				$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//				$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//				$cart .= "</tr>";
		 }
	   }
	}
 $cart .= "</table>";
 $cart .= "<Br>";
 $cart .= "<em>".$this->lang->line('vat_included_cart')."</em>";
 if (($data['orderdata']['ship_method']=='courier') || ($data['orderdata']['ship_method']=='day_delivery') || ($data['orderdata']['ship_method']=='elta')) {
  if ($data['orderdata']['ship_method']=='courier') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('courier_delivery')."</h4>";
} elseif ($data['orderdata']['ship_method']=='elta') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('elta_delivery')."</h4>";
 } else {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('day_delivery')."</h4>";
 }
 $cart .= "<h4>".$this->lang->line('delivery_address')."</h4>";
 if ($data['orderdata']['same_address']=='Yes') {
 $country_zone = $this->MFuncs->getCountryZone($data['userdata']['country_id']);
 $cart .= "<h4>".$data['userdata']['address'].", ".$data['userdata']['city'].", ".$data['userdata']['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$data['userdata']['floor'].", ".$this->lang->line('name_bell').": ".$data['userdata']['name_bell']."<br>".$this->lang->line('tel').": ".$data['userdata']['tel'].", ".$this->lang->line('mob').": ".$data['userdata']['mob']."</h4>";
 }else { 
 $country_zone = $this->MFuncs->getCountryZone($data['orderdata']['country_id']);
 $cart .= "<h4>".$data['orderdata']['address'].", ".$data['orderdata']['city'].", ".$data['orderdata']['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$data['orderdata']['floor'].", ".$this->lang->line('name_bell').": ".$data['orderdata']['name_bell']."<br>".$this->lang->line('tel').": ".$data['userdata']['tel'].", ".$this->lang->line('mob').": ".$data['userdata']['mob']."</h4>";
 } 
 } else {
  $cart .= "<h4>".$this->lang->line('pickup_title')."</h4>";
  $cart .= "<h4>".$this->lang->line('pickup_txt')."</h4>";
 }
  if ($data['orderdata']['pay_method']=='Cash') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('cash_on_delivery')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='Bank') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('bank_deposit')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='Credit') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('credit_card')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='PayPal') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('pay_pal')."</h4>";
 }

 $cart .= "<Br>";
  if ($data['orderdata']['receipt_type']=='receipt') {
 $cart .= "<h4>".$this->lang->line('receipt_type')."</h4>";
 $cart .= "<h4>".$this->lang->line('type_receipt')."</h4>";
 } elseif ($data['orderdata']['receipt_type']=='invoice') {
 $cart .= "<h4>".$this->lang->line('receipt_type')."</h4>";
 $cart .= "<h4>".$this->lang->line('type_invoice')."</h4>";
 $invoice_details = $this->MFuncs->getInvoiceDetails($data['orderdata']['id']);
 	if ($invoice_details) { 
	 $cart .= "<Br>";
	 $cart .= "<p>".$this->lang->line('cmp_name').": ".$invoice_details['cmp_name']."<Br>";
	 $cart .= $this->lang->line('cmp_occupation').": ".$invoice_details['cmp_occupation']."<Br>";
	 $cart .= $this->lang->line('cmp_afm').": ".$invoice_details['cmp_afm']."<Br>";
	 $cart .= $this->lang->line('cmp_address').": ".$invoice_details['cmp_address']."<Br>";
	 $cart .= $this->lang->line('cmp_city').": ".$invoice_details['cmp_city']."<Br>";
	 $cart .= $this->lang->line('cmp_doy').": ".$invoice_details['cmp_doy']."</p>";
	}
 }
			$data['msg_title'] = "A new order has been made by ".$data['userdata']['fname']." ".$data['userdata']['lname'];
			$data['comments'] = "The order details are the following:".br(2).$cart;
			$data['post_msg'] = "";
			
			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);

			#Email send to the company!
			$this->email->from('no-reply@wines2u.gr', $data['userdata']['fname']." ".$data['userdata']['lname']." ".$data['userdata']['email']);
			$this->email->to('info@wines2u.gr', 'www.wines2u.gr');
			$this->email->cc('b.a@wines2u.gr', 'www.wines2u.gr');
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
	
			$data['msg_title'] = $this->lang->line('dear')." ".$data['userdata']['fname']." ".$data['userdata']['lname'].",".br(1).$this->lang->line('order_msg');
			$data['comments'] = $this->lang->line('order_details_msg').br(2).$cart;
			$data['post_msg'] = $this->lang->line('contact_dept').br(1);

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);
		
			#Email send to the user
			$this->email->from('no-reply@wines2u.gr', 'www.wines2u.gr');
			$this->email->to($data['userdata']['email']);
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
			
		$data['order_cart'] = $cart;
}
		$this->MFuncs->finaliseOrderPayed($order_id);
		$this->cart->destroy();
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('successful_payment');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'complete_payment';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function complete_payment_new2() {

		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);

 if ($data['orderdata']) { 
 $cart = "<table class='full' width='100%' border='0'>";
 $cart .= "<tr>";
 $cart .= "<th>".$this->lang->line('cart_qty')."</th>";
 $cart .= "<th>".$this->lang->line('cart_desc')."</th>";
 $cart .= "<th>".$this->lang->line('cart_price')."</th>";
 $cart .= "<th>".$this->lang->line('cart_sub')."</th>";
 $cart .= "</tr>";

		$order_details = $this->MFuncs->GetOrderDetails($data['orderdata']['id']);
		if ($order_details) {
		$total = 0;
		
		$weight = 0;
		$bot_num = 0;
		$pack_total = 0;
		$ship_total = 0;

    	foreach($order_details as $result=>$order_det):
        $product_details = $this->MFuncs->getProductDetails($order_det['product_id']);
		$product_category = $this->MFuncs->getProductCat($order_det['product_id']);

		$product_category_name = $this->MFuncs->getCategory($product_category['cat_id']);
		$product_sub_category = $this->MFuncs->getProductSubCat($order_det['product_id']);
  		if ($product_sub_category) {
		$product_sub_category_name = $this->MFuncs->getSubCategory($product_sub_category['subcat_id']);
		}
		
 $cart .= "<tr>";
 $cart .= "<td>".$order_det['quantity']."</td>";
  if ($product_sub_category) {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_sub_category_name['name']."-".$product_details['name']."</td>";
 } else {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_details['name']."</td>";
 }
 $cart .= "<td>".number_format($order_det['price'], 2, '.', '')."</td>";
 $cart .= "<td>&euro; ".number_format($order_det['price']*$order_det['quantity'], 2, '.', '')."</td>";
 $total = $total + $order_det['price']*$order_det['quantity'];
 $weight = $weight + ($product_details['weight'] * $order_det['quantity']);
 if ($product_category['cat_id']!='7') { 
          $bot_num = $bot_num + $order_det['quantity']; 
		  }
 $cart .= "</tr>";
    	endforeach;
$pay_on_arrival_cost=0;
$can_ship=true;
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
 if ($data['orderdata']['offer_code']!=0) {
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_discount')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total*$data['orderdata']['offer_code'], 2, '.', '')."</td>";
 $cart .= "</tr>";
 $total = $total - ($total*$data['orderdata']['offer_code']);
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
 }
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $cart .= "<td>&euro; ".$total - $total/1.21."</td>";
// $cart .= "</tr>";
// $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
// $cart .= "<td>&euro; ".$total."</td>";
// $cart .= "</tr>";

        if ($data['orderdata']['same_address']=='No') { 
 			$c_id = $data['orderdata']['country_id']; 
        } elseif ($data['orderdata']['same_address']=='Yes') {
            $c_id = $data['userdata']['country_id'];
        }
        if ($c_id!='1') { 
        if ($data['orderdata']['ship_method']=='courier_economy') { 
	   		$rounded_weight = ceil($weight/1000);
			$insurance_cost = $rounded_weight*0.05;
			if ($insurance_cost>10) { $insurance_cost=10; }
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getTNT_Cost_economy($rounded_weight, $country_zone['tnt_zones']);
			$ship_total = ($value['price']*0.205) + $value['price'];
			//if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			//}
			$ship_total = $insurance_cost + $ship_total;
			$ship_total = number_format($ship_total, 2, '.', '');
        } elseif ($data['orderdata']['ship_method']=='courier_express') { 
	   		$rounded_weight = ceil($weight/1000);
			$insurance_cost = $rounded_weight*0.05;
			if ($insurance_cost>10) { $insurance_cost=10; }
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			if ($rounded_weight<=30) {
			$value = $this->MFuncs->getTNT_Cost_express($rounded_weight, $country_zone['tnt_zones_express']);
			$total_ship_cost = $value['price'];
			} else {
			$value = $this->MFuncs->getTNT_Cost_express(30, $country_zone['tnt_zones_express']);
			$extra_cost_pk = $this->MFuncs->getTNT_extra_Cost($country_zone['tnt_zones_express']);
			$extra_ship_cost = (($rounded_weight-30) * $extra_cost_pk['price']);
			$total_ship_cost = $extra_ship_cost + $value['price'];
			}
			$ship_total = ($total_ship_cost*0.205) + $total_ship_cost;
			//if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			//}
			$ship_total = $insurance_cost + $ship_total;
			$ship_total = number_format($ship_total, 2, '.', '');
         }
            $cart .= "<tr>";
            $cart .= "<td colspan='2'></td>";
            $cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
            $cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
            $cart .= "</tr>";
			$cart .= "<tr>";
			$cart .= "<td colspan='2'></td>";
			$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
			$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
			$cart .= "</tr>";


         } else { 
		 
 if (($data['orderdata']['ship_method']=='courier') || ($data['orderdata']['ship_method']=='elta')) {
$pack_total = (ceil($bot_num/2))*0.53;
           if ($data['orderdata']['ship_dest']=='attica-center') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(0, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(2.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(4.96, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-suberbs') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(6.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(9.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-suberbs-out') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(5.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(9.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(13.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-rest') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(2.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(4.96, 2, '.', '');
			   } else {
			   $ship_total = number_format(6.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-peir') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(6.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(9.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-peir-out') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(5.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(9.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(13.90, 2, '.', '');
			   }
/////
//			   if ($weight == 0) { 
//			   $ship_total = number_format(0, 2, '.', '');
//			   } 
//			   elseif ($weight < 3000) {
//			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
//			   $ship_total = number_format(3.57, 2, '.', '');
//			   } else {
//			   //$ship_total = 3.45 + $pack_total;
//			   $ship_total = 3.57;
//			   $weight = $weight - 3000;
//			   $i = ceil($weight/1000);
//			   $ship_total = number_format($ship_total + ($i*1.00), 2, '.', '');
//			   }

		   } elseif ($data['orderdata']['ship_dest']=='attica') { 
             $i = ceil($weight/1000);
			 if ($data['orderdata']['ship_method']=='courier') {
             if ($i>35) { 
             $can_ship=false;
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_attica_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_attica_cost');
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else { 
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_attica_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 

             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } 
            
             } 
	   
		   } elseif ($data['orderdata']['ship_dest']=='greece') { 
             $i = ceil($weight/1000); 
			 if ($data['orderdata']['ship_method']=='courier') { 
             if ($i>35) { 
             $can_ship=false; 
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_greece_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_greece_cost');
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else {
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_greece_cost');
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', '');
			 } else {
             $ship_total = number_format(0, 2, '.', '');
             } 
             } 
            
             } 
 		   } elseif ($data['orderdata']['ship_dest']=='crete') { 
             $i = ceil($weight/1000);
			 if ($data['orderdata']['ship_method']=='courier') { 
             if ($i>35) { 
             $can_ship=false; 
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_crete_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_crete_cost'); 
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else { 
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_crete_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } 
            
             } 
         
          
           } 
        if ($can_ship==false) {
$cart .= "<tr>";
$cart .= "<td colspan='1'></td>";
$cart .= "<td colspan='3'><strong>".$this->lang->line('cannot_ship_txt')."</strong></td>";
$cart .= "</tr>";
        $ship_total=0;
          } else {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
         } 
 if (($data['orderdata']['ship_dest']=='attica') || ($data['orderdata']['ship_dest']=='greece') || ($data['orderdata']['ship_dest']=='crete')) {
	  if ($data['orderdata']['pay_method']=='Cash') {
		  if ($data['orderdata']['ship_method']=='elta') {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('cash_on_delivery_total')."</strong></td>";
$pay_on_arrival_cost = number_format(2.30, 2, '.', '');
$cart .= "<td>&euro; ".number_format($pay_on_arrival_cost, 2, '.', '')."</td>";
$cart .= "</tr>";
         } elseif ($data['orderdata']['ship_method']=='courier') {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('cash_on_delivery_total')."</strong></td>";
$pay_on_arrival_cost = number_format(5.17, 2, '.', '');
$cart .= "<td>&euro; ".number_format($pay_on_arrival_cost, 2, '.', '')."</td>";
$cart .= "</tr>";
          } 
      }        
  }
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total + $pay_on_arrival_cost."</td>";
$cart .= "</tr>";


//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//$cart .= "<td>&euro; ".$ship_total."</td>";
//$cart .= "</tr>";
//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//$cart .= "</tr>";         
} elseif ($data['orderdata']['ship_method']=='day_delivery') {
        		$ship_total = number_format(14.76, 2, '.', '');
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";

				
//				$cart .= "<tr>";
//				$cart .= "<td colspan='2'></td>";
//				$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//				$cart .= "<td>&euro; ".$ship_total."</td>";
//				$cart .= "</tr>";
//				$cart .= "<tr>";
//				$cart .= "<td colspan='2'></td>";
//				$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//				$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//				$cart .= "</tr>";
		 }
	   }
	}
 $cart .= "</table>";
 $cart .= "<Br>";
 $cart .= "<em>".$this->lang->line('vat_included_cart')."</em>";
 if (($data['orderdata']['ship_method']=='courier') || ($data['orderdata']['ship_method']=='day_delivery') || ($data['orderdata']['ship_method']=='elta') || ($data['orderdata']['ship_method']=='courier_economy') || ($data['orderdata']['ship_method']=='courier_express')) {
if ($data['orderdata']['ship_method']=='courier_economy') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('courier_delivery_abroad_economy')."</h4>";
 } elseif ($data['orderdata']['ship_method']=='courier_express') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('courier_delivery_abroad_express')."</h4>";
 } elseif ($data['orderdata']['ship_method']=='courier') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('courier_delivery')."</h4>";
} elseif ($data['orderdata']['ship_method']=='elta') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('elta_delivery')."</h4>";
 } else {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('day_delivery')."</h4>";
 }
 $cart .= "<h4>".$this->lang->line('delivery_address')."</h4>";
 if ($data['orderdata']['same_address']=='Yes') {
 $country_zone = $this->MFuncs->getCountryZone($data['userdata']['country_id']);
 $cart .= "<h4>".$data['userdata']['address'].", ".$data['userdata']['city'].", ".$data['userdata']['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$data['userdata']['floor'].", ".$this->lang->line('name_bell').": ".$data['userdata']['name_bell']."<br>".$this->lang->line('tel').": ".$data['userdata']['tel'].", ".$this->lang->line('mob').": ".$data['userdata']['mob']."</h4>";
 }else { 
 $country_zone = $this->MFuncs->getCountryZone($data['orderdata']['country_id']);
 $cart .= "<h4>".$data['orderdata']['address'].", ".$data['orderdata']['city'].", ".$data['orderdata']['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$data['orderdata']['floor'].", ".$this->lang->line('name_bell').": ".$data['orderdata']['name_bell']."<br>".$this->lang->line('tel').": ".$data['userdata']['tel'].", ".$this->lang->line('mob').": ".$data['userdata']['mob']."</h4>";
 } 
 } else {
  $cart .= "<h4>".$this->lang->line('pickup_title')."</h4>";
  $cart .= "<h4>".$this->lang->line('pickup_txt')."</h4>";
 }
  if ($data['orderdata']['pay_method']=='Cash') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('cash_on_delivery')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='Bank') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('bank_deposit')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='Credit') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('credit_card')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='PayPal') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('pay_pal')."</h4>";
 }

 $cart .= "<Br>";
  if ($data['orderdata']['receipt_type']=='receipt') {
 $cart .= "<h4>".$this->lang->line('receipt_type')."</h4>";
 $cart .= "<h4>".$this->lang->line('type_receipt')."</h4>";
 } elseif ($data['orderdata']['receipt_type']=='invoice') {
 $cart .= "<h4>".$this->lang->line('receipt_type')."</h4>";
 $cart .= "<h4>".$this->lang->line('type_invoice')."</h4>";
 $invoice_details = $this->MFuncs->getInvoiceDetails($data['orderdata']['id']);
 	if ($invoice_details) { 
	 $cart .= "<Br>";
	 $cart .= "<p>".$this->lang->line('cmp_name').": ".$invoice_details['cmp_name']."<Br>";
	 $cart .= $this->lang->line('cmp_occupation').": ".$invoice_details['cmp_occupation']."<Br>";
	 $cart .= $this->lang->line('cmp_afm').": ".$invoice_details['cmp_afm']."<Br>";
	 $cart .= $this->lang->line('cmp_address').": ".$invoice_details['cmp_address']."<Br>";
	 $cart .= $this->lang->line('cmp_city').": ".$invoice_details['cmp_city']."<Br>";
	 $cart .= $this->lang->line('cmp_doy').": ".$invoice_details['cmp_doy']."</p>";
	}
 }
			$data['msg_title'] = "A new order has been made by ".$data['userdata']['fname']." ".$data['userdata']['lname'];
			$data['comments'] = "The order details are the following:".br(2).$cart;
			$data['post_msg'] = "";
			
			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);

			#Email send to the company!
			$this->email->from('no-reply@wines2u.gr', $data['userdata']['fname']." ".$data['userdata']['lname']." ".$data['userdata']['email']);
			$this->email->to('info@wines2u.gr', 'www.wines2u.gr');
			$this->email->cc('b.a@wines2u.gr', 'www.wines2u.gr');
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
	
			$data['msg_title'] = $this->lang->line('dear')." ".$data['userdata']['fname']." ".$data['userdata']['lname'].",".br(1).$this->lang->line('order_msg');
			$data['comments'] = $this->lang->line('order_details_msg').br(2).$cart;
			$data['post_msg'] = $this->lang->line('contact_dept').br(1);

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);
		
			#Email send to the user
			$this->email->from('no-reply@wines2u.gr', 'www.wines2u.gr');
			$this->email->to($data['userdata']['email']);
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
			
		$data['order_cart'] = $cart;
}
		$this->MFuncs->finaliseOrderPayed($order_id);
		$this->cart->destroy();
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('successful_payment');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'complete_payment';
		$this->load->vars($data);
		$this->load->view('template_master');
}	
function complete_payment_paypal($orderid){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		//$order_id=$this->session->userdata('orderid');
		$order_id=$orderid;
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $orderid);

 if ($data['orderdata']) { 
 $cart = "<table class='full' width='100%' border='0'>";
 $cart .= "<tr>";
 $cart .= "<th>".$this->lang->line('cart_qty')."</th>";
 $cart .= "<th>".$this->lang->line('cart_desc')."</th>";
 $cart .= "<th>".$this->lang->line('cart_price')."</th>";
 $cart .= "<th>".$this->lang->line('cart_sub')."</th>";
 $cart .= "</tr>";

		$order_details = $this->MFuncs->GetOrderDetails($data['orderdata']['id']);
		if ($order_details) {
		$total = 0;
		
		$weight = 0;
		$bot_num = 0;
		$pack_total = 0;
		$ship_total = 0;

    	foreach($order_details as $result=>$order_det):
        $product_details = $this->MFuncs->getProductDetails($order_det['product_id']);
		$product_category = $this->MFuncs->getProductCat($order_det['product_id']);

		$product_category_name = $this->MFuncs->getCategory($product_category['cat_id']);
		$product_sub_category = $this->MFuncs->getProductSubCat($order_det['product_id']);
  		if ($product_sub_category) {
		$product_sub_category_name = $this->MFuncs->getSubCategory($product_sub_category['subcat_id']);
		}
		
 $cart .= "<tr>";
 $cart .= "<td>".$order_det['quantity']."</td>";
  if ($product_sub_category) {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_sub_category_name['name']."-".$product_details['name']."</td>";
 } else {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_details['name']."</td>";
 }
 $cart .= "<td>".number_format($order_det['price'], 2, '.', '')."</td>";
 $cart .= "<td>&euro; ".number_format($order_det['price']*$order_det['quantity'], 2, '.', '')."</td>";
 $total = $total + $order_det['price']*$order_det['quantity'];
 $weight = $weight + ($product_details['weight'] * $order_det['quantity']);
 if ($product_category['cat_id']!='7') { 
          $bot_num = $bot_num + $order_det['quantity']; 
		  }
 $cart .= "</tr>";
    	endforeach;
$pay_on_arrival_cost=0;
$can_ship=true;
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
 if ($data['orderdata']['offer_code']!=0) {
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_discount')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total*$data['orderdata']['offer_code'], 2, '.', '')."</td>";
 $cart .= "</tr>";
 $total = $total - ($total*$data['orderdata']['offer_code']);
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
 }
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $cart .= "<td>&euro; ".$total - $total/1.21."</td>";
// $cart .= "</tr>";
// $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
// $cart .= "<td>&euro; ".$total."</td>";
// $cart .= "</tr>";

        if (($data['orderdata']['same_address']=='No') && ($data['orderdata']['country_id']!='1')) { 
        if ($data['orderdata']['ship_method']=='courier') { 
        	//$rounded_weight = round($weight/1000, 2);
	   		$rounded_weight = ceil(($weight/1000)*2)/2;
			if ($data['orderdata']['same_address']=='No') {
			$c_id = $data['orderdata']['country_id'];
			} else { 
			$c_id = $data['userdata']['country_id'];
			}
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getFed_Ex_Cost($rounded_weight, $country_zone['zones']);
			$ship_total = ($value['price']*0.152) + $value['price'];
			if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			}
			$ship_total = number_format($ship_total, 2, '.', ''); 
         }
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";

//	$cart .= "<tr>";
//	$cart .= "<td colspan='2'></td>";
//	$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//	$cart .= "<td>&euro; ".$ship_total."</td>";
//	$cart .= "</tr>";
//	$cart .= "<tr>";
//	$cart .= "<td colspan='2'></td>";
//	$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//	$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//	$cart .= "</tr>";
         } elseif (($data['orderdata']['same_address']=='Yes') && ($data['userdata']['country_id']!='1')) { 
        if ($data['orderdata']['ship_method']=='courier') { 
        	//$rounded_weight = round($weight/1000, 2);
	   		$rounded_weight = ceil(($weight/1000)*2)/2;
			if ($data['orderdata']['same_address']=='No') {
			$c_id = $data['orderdata']['country_id'];
			} else { 
			$c_id = $data['userdata']['country_id'];
			}
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getFed_Ex_Cost($rounded_weight, $country_zone['zones']);
			$ship_total = ($value['price']*0.152) + $value['price'];
			if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			}
			$ship_total = number_format($ship_total, 2, '.', ''); 
         }
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";


//	$cart .= "<tr>";
//	$cart .= "<td colspan='2'></td>";
//	$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//	$cart .= "<td>&euro; ".$ship_total."</td>";
//	$cart .= "</tr>";
//	$cart .= "<tr>";
//	$cart .= "<td colspan='2'></td>";
//	$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//	$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//	$cart .= "</tr>";
         } else { 

 if (($data['orderdata']['ship_method']=='courier') || ($data['orderdata']['ship_method']=='elta')) {
$pack_total = (ceil($bot_num/2))*0.53;
           if ($data['orderdata']['ship_dest']=='attica-center') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(0, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(2.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(4.96, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-suberbs') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(6.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(9.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-suberbs-out') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(5.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(9.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(13.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-rest') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(2.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(4.96, 2, '.', '');
			   } else {
			   $ship_total = number_format(6.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-peir') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(6.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(9.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-peir-out') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(5.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(9.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(13.90, 2, '.', '');
			   }
/////
//			   if ($weight == 0) { 
//			   $ship_total = number_format(0, 2, '.', '');
//			   } 
//			   elseif ($weight < 3000) {
//			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
//			   $ship_total = number_format(3.57, 2, '.', '');
//			   } else {
//			   //$ship_total = 3.45 + $pack_total;
//			   $ship_total = 3.57;
//			   $weight = $weight - 3000;
//			   $i = ceil($weight/1000);
//			   $ship_total = number_format($ship_total + ($i*1.00), 2, '.', '');
//			   }

		   } elseif ($data['orderdata']['ship_dest']=='attica') { 
             $i = ceil($weight/1000);
			 if ($data['orderdata']['ship_method']=='courier') {
             if ($i>35) { 
             $can_ship=false;
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_attica_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_attica_cost');
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else { 
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_attica_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 

             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } 
            
             } 
	   
		   } elseif ($data['orderdata']['ship_dest']=='greece') { 
             $i = ceil($weight/1000); 
			 if ($data['orderdata']['ship_method']=='courier') { 
             if ($i>35) { 
             $can_ship=false; 
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_greece_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_greece_cost');
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else {
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_greece_cost');
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', '');
			 } else {
             $ship_total = number_format(0, 2, '.', '');
             } 
             } 
            
             } 
 		   } elseif ($data['orderdata']['ship_dest']=='crete') { 
             $i = ceil($weight/1000);
			 if ($data['orderdata']['ship_method']=='courier') { 
             if ($i>35) { 
             $can_ship=false; 
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_crete_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_crete_cost'); 
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else { 
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_crete_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } 
            
             } 
         
          
           } 
        if ($can_ship==false) {
$cart .= "<tr>";
$cart .= "<td colspan='1'></td>";
$cart .= "<td colspan='3'><strong>".$this->lang->line('cannot_ship_txt')."</strong></td>";
$cart .= "</tr>";
        $ship_total=0;
          } else {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
         } 
 if (($data['orderdata']['ship_dest']=='attica') || ($data['orderdata']['ship_dest']=='greece') || ($data['orderdata']['ship_dest']=='crete')) {
	  if ($data['orderdata']['pay_method']=='Cash') {
		  if ($data['orderdata']['ship_method']=='elta') {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('cash_on_delivery_total')."</strong></td>";
$pay_on_arrival_cost = number_format(2.30, 2, '.', '');
$cart .= "<td>&euro; ".number_format($pay_on_arrival_cost, 2, '.', '')."</td>";
$cart .= "</tr>";
         } elseif ($data['orderdata']['ship_method']=='courier') {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('cash_on_delivery_total')."</strong></td>";
$pay_on_arrival_cost = number_format(5.17, 2, '.', '');
$cart .= "<td>&euro; ".number_format($pay_on_arrival_cost, 2, '.', '')."</td>";
$cart .= "</tr>";
          } 
      }        
  }
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total + $pay_on_arrival_cost."</td>";
$cart .= "</tr>";


//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//$cart .= "<td>&euro; ".$ship_total."</td>";
//$cart .= "</tr>";
//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//$cart .= "</tr>";         
} elseif ($data['orderdata']['ship_method']=='day_delivery') {
        		$ship_total = number_format(14.76, 2, '.', '');
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";

				
//				$cart .= "<tr>";
//				$cart .= "<td colspan='2'></td>";
//				$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//				$cart .= "<td>&euro; ".$ship_total."</td>";
//				$cart .= "</tr>";
//				$cart .= "<tr>";
//				$cart .= "<td colspan='2'></td>";
//				$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//				$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//				$cart .= "</tr>";
		 }
	   }
	}
 $cart .= "</table>";
 $cart .= "<Br>";
 $cart .= "<em>".$this->lang->line('vat_included_cart')."</em>";
 if (($data['orderdata']['ship_method']=='courier') || ($data['orderdata']['ship_method']=='day_delivery') || ($data['orderdata']['ship_method']=='elta')) {
  if ($data['orderdata']['ship_method']=='courier') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('courier_delivery')."</h4>";
} elseif ($data['orderdata']['ship_method']=='elta') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('elta_delivery')."</h4>";
 } else {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('day_delivery')."</h4>";
 }
 $cart .= "<h4>".$this->lang->line('delivery_address')."</h4>";
 if ($data['orderdata']['same_address']=='Yes') {
 $country_zone = $this->MFuncs->getCountryZone($data['userdata']['country_id']);
 $cart .= "<h4>".$data['userdata']['address'].", ".$data['userdata']['city'].", ".$data['userdata']['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$data['userdata']['floor'].", ".$this->lang->line('name_bell').": ".$data['userdata']['name_bell']."<br>".$this->lang->line('tel').": ".$data['userdata']['tel'].", ".$this->lang->line('mob').": ".$data['userdata']['mob']."</h4>";
 }else { 
 $country_zone = $this->MFuncs->getCountryZone($data['orderdata']['country_id']);
 $cart .= "<h4>".$data['orderdata']['address'].", ".$data['orderdata']['city'].", ".$data['orderdata']['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$data['orderdata']['floor'].", ".$this->lang->line('name_bell').": ".$data['orderdata']['name_bell']."<br>".$this->lang->line('tel').": ".$data['userdata']['tel'].", ".$this->lang->line('mob').": ".$data['userdata']['mob']."</h4>";
 } 
 } else {
  $cart .= "<h4>".$this->lang->line('pickup_title')."</h4>";
  $cart .= "<h4>".$this->lang->line('pickup_txt')."</h4>";
 }
  if ($data['orderdata']['pay_method']=='Cash') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('cash_on_delivery')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='Bank') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('bank_deposit')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='Credit') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('credit_card')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='PayPal') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('pay_pal')."</h4>";
 }

 $cart .= "<Br>";
  if ($data['orderdata']['receipt_type']=='receipt') {
 $cart .= "<h4>".$this->lang->line('receipt_type')."</h4>";
 $cart .= "<h4>".$this->lang->line('type_receipt')."</h4>";
 } elseif ($data['orderdata']['receipt_type']=='invoice') {
 $cart .= "<h4>".$this->lang->line('receipt_type')."</h4>";
 $cart .= "<h4>".$this->lang->line('type_invoice')."</h4>";
 $invoice_details = $this->MFuncs->getInvoiceDetails($data['orderdata']['id']);
 	if ($invoice_details) { 
	 $cart .= "<Br>";
	 $cart .= "<p>".$this->lang->line('cmp_name').": ".$invoice_details['cmp_name']."<Br>";
	 $cart .= $this->lang->line('cmp_occupation').": ".$invoice_details['cmp_occupation']."<Br>";
	 $cart .= $this->lang->line('cmp_afm').": ".$invoice_details['cmp_afm']."<Br>";
	 $cart .= $this->lang->line('cmp_address').": ".$invoice_details['cmp_address']."<Br>";
	 $cart .= $this->lang->line('cmp_city').": ".$invoice_details['cmp_city']."<Br>";
	 $cart .= $this->lang->line('cmp_doy').": ".$invoice_details['cmp_doy']."</p>";
	}
 }
			$data['msg_title'] = "A new order has been made by ".$data['userdata']['fname']." ".$data['userdata']['lname'];
			$data['comments'] = "The order details are the following:".br(2).$cart;
			$data['post_msg'] = "";
			
			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);

			#Email send to the company!
			$this->email->from('no-reply@wines2u.gr', $data['userdata']['fname']." ".$data['userdata']['lname']." ".$data['userdata']['email']);
			$this->email->to('info@wines2u.gr', 'www.wines2u.gr');
			$this->email->cc('b.a@wines2u.gr', 'www.wines2u.gr');
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
	
			$data['msg_title'] = $this->lang->line('dear')." ".$data['userdata']['fname']." ".$data['userdata']['lname'].",".br(1).$this->lang->line('order_msg');
			$data['comments'] = $this->lang->line('order_details_msg').br(2).$cart;
			$data['post_msg'] = $this->lang->line('contact_dept').br(1);

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);
		
			#Email send to the user
			$this->email->from('no-reply@wines2u.gr', 'www.wines2u.gr');
			$this->email->to($data['userdata']['email']);
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
			
		$data['order_cart'] = $cart;
}
		$this->MFuncs->finaliseOrderPayed($order_id);
		$this->cart->destroy();
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('successful_payment');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'complete_payment';
		$this->load->vars($data);
		$this->load->view('template_master');
}
function complete_payment_paypal_new ($orderid) {

		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		//$order_id=$this->session->userdata('orderid');
		$order_id=$orderid;
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);

 if ($data['orderdata']) { 
 $cart = "<table class='full' width='100%' border='0'>";
 $cart .= "<tr>";
 $cart .= "<th>".$this->lang->line('cart_qty')."</th>";
 $cart .= "<th>".$this->lang->line('cart_desc')."</th>";
 $cart .= "<th>".$this->lang->line('cart_price')."</th>";
 $cart .= "<th>".$this->lang->line('cart_sub')."</th>";
 $cart .= "</tr>";

		$order_details = $this->MFuncs->GetOrderDetails($data['orderdata']['id']);
		if ($order_details) {
		$total = 0;
		
		$weight = 0;
		$bot_num = 0;
		$pack_total = 0;
		$ship_total = 0;

    	foreach($order_details as $result=>$order_det):
        $product_details = $this->MFuncs->getProductDetails($order_det['product_id']);
		$product_category = $this->MFuncs->getProductCat($order_det['product_id']);

		$product_category_name = $this->MFuncs->getCategory($product_category['cat_id']);
		$product_sub_category = $this->MFuncs->getProductSubCat($order_det['product_id']);
  		if ($product_sub_category) {
		$product_sub_category_name = $this->MFuncs->getSubCategory($product_sub_category['subcat_id']);
		}
		
 $cart .= "<tr>";
 $cart .= "<td>".$order_det['quantity']."</td>";
  if ($product_sub_category) {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_sub_category_name['name']."-".$product_details['name']."</td>";
 } else {
 $cart .= "<td>".$product_category_name['cat_name']."-".$product_details['name']."</td>";
 }
 $cart .= "<td>".number_format($order_det['price'], 2, '.', '')."</td>";
 $cart .= "<td>&euro; ".number_format($order_det['price']*$order_det['quantity'], 2, '.', '')."</td>";
 $total = $total + $order_det['price']*$order_det['quantity'];
 $weight = $weight + ($product_details['weight'] * $order_det['quantity']);
 if ($product_category['cat_id']!='7') { 
          $bot_num = $bot_num + $order_det['quantity']; 
		  }
 $cart .= "</tr>";
    	endforeach;
$pay_on_arrival_cost=0;
$can_ship=true;
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
 if ($data['orderdata']['offer_code']!=0) {
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_discount')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total*$data['orderdata']['offer_code'], 2, '.', '')."</td>";
 $cart .= "</tr>";
 $total = $total - ($total*$data['orderdata']['offer_code']);
 $cart .= "<tr>";
 $cart .= "<td colspan='2'> </td>";
 $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
 $cart .= "<td>&euro; ".number_format($total, 2, '.', '')."</td>";
 $cart .= "</tr>";
 }
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $cart .= "<td>&euro; ".$total - $total/1.21."</td>";
// $cart .= "</tr>";
// $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_total')."</strong></td>";
// $cart .= "<td>&euro; ".$total."</td>";
// $cart .= "</tr>";

        if ($data['orderdata']['same_address']=='No') { 
 			$c_id = $data['orderdata']['country_id']; 
        } elseif ($data['orderdata']['same_address']=='Yes') {
            $c_id = $data['userdata']['country_id'];
        }
        if ($c_id!='1') { 
        if ($data['orderdata']['ship_method']=='courier_economy') { 
	   		$rounded_weight = ceil($weight/1000);
			$insurance_cost = $rounded_weight*0.05;
			if ($insurance_cost>10) { $insurance_cost=10; }
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			$value = $this->MFuncs->getTNT_Cost_economy($rounded_weight, $country_zone['tnt_zones']);
			$ship_total = ($value['price']*0.205) + $value['price'];
			//if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			//}
			$ship_total = $insurance_cost + $ship_total;
			$ship_total = number_format($ship_total, 2, '.', '');
        } elseif ($data['orderdata']['ship_method']=='courier_express') { 
	   		$rounded_weight = ceil($weight/1000);
			$insurance_cost = $rounded_weight*0.05;
			if ($insurance_cost>10) { $insurance_cost=10; }
			$country_zone = $this->MFuncs->getCountryZone($c_id);
			if ($rounded_weight<=30) {
			$value = $this->MFuncs->getTNT_Cost_express($rounded_weight, $country_zone['tnt_zones_express']);
			$total_ship_cost = $value['price'];
			} else {
			$value = $this->MFuncs->getTNT_Cost_express(30, $country_zone['tnt_zones_express']);
			$extra_cost_pk = $this->MFuncs->getTNT_extra_Cost($country_zone['tnt_zones_express']);
			$extra_ship_cost = (($rounded_weight-30) * $extra_cost_pk['price']);
			$total_ship_cost = $extra_ship_cost + $value['price'];
			}
			$ship_total = ($total_ship_cost*0.205) + $total_ship_cost;
			//if (($country_zone['zones']=='F') || ($country_zone['zones']=='FCY') || ($country_zone['zones']=='M')) {
			$ship_total = ($ship_total*0.23) + $ship_total;
			//}
			$ship_total = $insurance_cost + $ship_total;
			$ship_total = number_format($ship_total, 2, '.', '');
         }
            $cart .= "<tr>";
            $cart .= "<td colspan='2'></td>";
            $cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
            $cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
            $cart .= "</tr>";
			$cart .= "<tr>";
			$cart .= "<td colspan='2'></td>";
			$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
			$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
			$cart .= "</tr>";


         } else { 
 if (($data['orderdata']['ship_method']=='courier') || ($data['orderdata']['ship_method']=='elta')) {
$pack_total = (ceil($bot_num/2))*0.53;
           if ($data['orderdata']['ship_dest']=='attica-center') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(0, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(2.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(4.96, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-suberbs') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(6.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(9.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-suberbs-out') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(5.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(9.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(13.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-rest') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(2.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(4.96, 2, '.', '');
			   } else {
			   $ship_total = number_format(6.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-peir') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(3.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(6.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(9.90, 2, '.', '');
			   }
		   } elseif ($data['orderdata']['ship_dest']=='attica-peir-out') {
			   if ($weight < 20000) {
			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
			   $ship_total = number_format(5.90, 2, '.', '');
			   } elseif ($weight < 50000) {
			   $ship_total = number_format(9.90, 2, '.', '');
			   } else {
			   $ship_total = number_format(13.90, 2, '.', '');
			   }
/////
//			   if ($weight == 0) { 
//			   $ship_total = number_format(0, 2, '.', '');
//			   } 
//			   elseif ($weight < 3000) {
//			   //$ship_total = number_format(3.45 + $pack_total, 2, '.', ''); 
//			   $ship_total = number_format(3.57, 2, '.', '');
//			   } else {
//			   //$ship_total = 3.45 + $pack_total;
//			   $ship_total = 3.57;
//			   $weight = $weight - 3000;
//			   $i = ceil($weight/1000);
//			   $ship_total = number_format($ship_total + ($i*1.00), 2, '.', '');
//			   }

		   } elseif ($data['orderdata']['ship_dest']=='attica') { 
             $i = ceil($weight/1000);
			 if ($data['orderdata']['ship_method']=='courier') {
             if ($i>35) { 
             $can_ship=false;
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_attica_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_attica_cost');
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else { 
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_attica_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 

             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } 
            
             } 
	   
		   } elseif ($data['orderdata']['ship_dest']=='greece') { 
             $i = ceil($weight/1000); 
			 if ($data['orderdata']['ship_method']=='courier') { 
             if ($i>35) { 
             $can_ship=false; 
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_greece_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_greece_cost');
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else {
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_greece_cost');
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', '');
			 } else {
             $ship_total = number_format(0, 2, '.', '');
             } 
             } 
            
             } 
 		   } elseif ($data['orderdata']['ship_dest']=='crete') { 
             $i = ceil($weight/1000);
			 if ($data['orderdata']['ship_method']=='courier') { 
             if ($i>35) { 
             $can_ship=false; 
             } else { 
             $can_ship=true; 
             } 
             $value_ship = $this->MFuncs->getCourierCost($i, 'courier_crete_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } elseif ($data['orderdata']['ship_method']=='elta') { 
             if ($i>20) { 
             $value_ship = $this->MFuncs->getCourierCost(20, 'elta_crete_cost'); 
			 $remaining_weight = $i - 20; 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'] + ($remaining_weight*0.60), 2, '.', '');
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } else { 
             $value_ship = $this->MFuncs->getCourierCost($i, 'elta_crete_cost'); 
             if ($value_ship) { 
             $ship_total = number_format($value_ship['price'], 2, '.', ''); 
			 } else { 
             $ship_total = number_format(0, 2, '.', ''); 
             } 
             } 
            
             } 
         
          
           } 
        if ($can_ship==false) {
$cart .= "<tr>";
$cart .= "<td colspan='1'></td>";
$cart .= "<td colspan='3'><strong>".$this->lang->line('cannot_ship_txt')."</strong></td>";
$cart .= "</tr>";
        $ship_total=0;
          } else {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
         } 
 if (($data['orderdata']['ship_dest']=='attica') || ($data['orderdata']['ship_dest']=='greece') || ($data['orderdata']['ship_dest']=='crete')) {
	  if ($data['orderdata']['pay_method']=='Cash') {
		  if ($data['orderdata']['ship_method']=='elta') {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('cash_on_delivery_total')."</strong></td>";
$pay_on_arrival_cost = number_format(2.30, 2, '.', '');
$cart .= "<td>&euro; ".number_format($pay_on_arrival_cost, 2, '.', '')."</td>";
$cart .= "</tr>";
         } elseif ($data['orderdata']['ship_method']=='courier') {
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('cash_on_delivery_total')."</strong></td>";
$pay_on_arrival_cost = number_format(5.17, 2, '.', '');
$cart .= "<td>&euro; ".number_format($pay_on_arrival_cost, 2, '.', '')."</td>";
$cart .= "</tr>";
          } 
      }        
  }
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total + $pay_on_arrival_cost."</td>";
$cart .= "</tr>";


//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//$cart .= "<td>&euro; ".$ship_total."</td>";
//$cart .= "</tr>";
//$cart .= "<tr>";
//$cart .= "<td colspan='2'></td>";
//$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//$cart .= "</tr>";         
} elseif ($data['orderdata']['ship_method']=='day_delivery') {
        		$ship_total = number_format(14.76, 2, '.', '');
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
$cart .= "<td>&euro; ".number_format($ship_total, 2, '.', '')."</td>";
$cart .= "</tr>";
//  $cart .= "<tr>";
// $cart .= "<td colspan='2'> </td>";
// $cart .= "<td><strong>".$this->lang->line('cart_vat')."</strong></td>";
// $vat_total = ($ship_total - $ship_total) + ($total - $total);
// $cart .= "<td>&euro; ".number_format($vat_total, 2, '.', '')."</td>";
// $cart .= "</tr>";
$cart .= "<tr>";
$cart .= "<td colspan='2'></td>";
$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
$cart .= "</tr>";

				
//				$cart .= "<tr>";
//				$cart .= "<td colspan='2'></td>";
//				$cart .= "<td><strong>".$this->lang->line('ship_total')."</strong></td>";
//				$cart .= "<td>&euro; ".$ship_total."</td>";
//				$cart .= "</tr>";
//				$cart .= "<tr>";
//				$cart .= "<td colspan='2'></td>";
//				$cart .= "<td><strong>".$this->lang->line('gen_total')."</strong></td>";
//				$cart .= "<td>&euro; ".$gen_total = $ship_total + $total."</td>";
//				$cart .= "</tr>";
		 }
	   }
	}
 $cart .= "</table>";
 $cart .= "<Br>";
 $cart .= "<em>".$this->lang->line('vat_included_cart')."</em>";
 if (($data['orderdata']['ship_method']=='courier') || ($data['orderdata']['ship_method']=='day_delivery') || ($data['orderdata']['ship_method']=='elta') || ($data['orderdata']['ship_method']=='courier_economy') || ($data['orderdata']['ship_method']=='courier_express')) {
if ($data['orderdata']['ship_method']=='courier_economy') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('courier_delivery_abroad_economy')."</h4>";
 } elseif ($data['orderdata']['ship_method']=='courier_express') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('courier_delivery_abroad_express')."</h4>";
 } elseif ($data['orderdata']['ship_method']=='courier') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('courier_delivery')."</h4>";
} elseif ($data['orderdata']['ship_method']=='elta') {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('elta_delivery')."</h4>";
 } else {
 $cart .= "<h4>".$this->lang->line('way_of_receive')."</h4>";
 $cart .= "<h4>".$this->lang->line('day_delivery')."</h4>";
 }
 $cart .= "<h4>".$this->lang->line('delivery_address')."</h4>";
 if ($data['orderdata']['same_address']=='Yes') {
 $country_zone = $this->MFuncs->getCountryZone($data['userdata']['country_id']);
 $cart .= "<h4>".$data['userdata']['address'].", ".$data['userdata']['city'].", ".$data['userdata']['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$data['userdata']['floor'].", ".$this->lang->line('name_bell').": ".$data['userdata']['name_bell']."<br>".$this->lang->line('tel').": ".$data['userdata']['tel'].", ".$this->lang->line('mob').": ".$data['userdata']['mob']."</h4>";
 }else { 
 $country_zone = $this->MFuncs->getCountryZone($data['orderdata']['country_id']);
 $cart .= "<h4>".$data['orderdata']['address'].", ".$data['orderdata']['city'].", ".$data['orderdata']['postal'].", ".$country_zone['name']."<br>".$this->lang->line('floor').": ".$data['orderdata']['floor'].", ".$this->lang->line('name_bell').": ".$data['orderdata']['name_bell']."<br>".$this->lang->line('tel').": ".$data['userdata']['tel'].", ".$this->lang->line('mob').": ".$data['userdata']['mob']."</h4>";
 } 
 } else {
  $cart .= "<h4>".$this->lang->line('pickup_title')."</h4>";
  $cart .= "<h4>".$this->lang->line('pickup_txt')."</h4>";
 }
  if ($data['orderdata']['pay_method']=='Cash') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('cash_on_delivery')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='Bank') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('bank_deposit')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='Credit') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('credit_card')."</h4>";
 } elseif ($data['orderdata']['pay_method']=='PayPal') {
 $cart .= "<h4>".$this->lang->line('payment_method')."</h4>";
 $cart .= "<h4>".$this->lang->line('pay_pal')."</h4>";
 }

 $cart .= "<Br>";
  if ($data['orderdata']['receipt_type']=='receipt') {
 $cart .= "<h4>".$this->lang->line('receipt_type')."</h4>";
 $cart .= "<h4>".$this->lang->line('type_receipt')."</h4>";
 } elseif ($data['orderdata']['receipt_type']=='invoice') {
 $cart .= "<h4>".$this->lang->line('receipt_type')."</h4>";
 $cart .= "<h4>".$this->lang->line('type_invoice')."</h4>";
 $invoice_details = $this->MFuncs->getInvoiceDetails($data['orderdata']['id']);
 	if ($invoice_details) { 
	 $cart .= "<Br>";
	 $cart .= "<p>".$this->lang->line('cmp_name').": ".$invoice_details['cmp_name']."<Br>";
	 $cart .= $this->lang->line('cmp_occupation').": ".$invoice_details['cmp_occupation']."<Br>";
	 $cart .= $this->lang->line('cmp_afm').": ".$invoice_details['cmp_afm']."<Br>";
	 $cart .= $this->lang->line('cmp_address').": ".$invoice_details['cmp_address']."<Br>";
	 $cart .= $this->lang->line('cmp_city').": ".$invoice_details['cmp_city']."<Br>";
	 $cart .= $this->lang->line('cmp_doy').": ".$invoice_details['cmp_doy']."</p>";
	}
 }
			$data['msg_title'] = "A new order has been made by ".$data['userdata']['fname']." ".$data['userdata']['lname'];
			$data['comments'] = "The order details are the following:".br(2).$cart;
			$data['post_msg'] = "";
			
			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);

			#Email send to the company!
			$this->email->from('no-reply@wines2u.gr', $data['userdata']['fname']." ".$data['userdata']['lname']." ".$data['userdata']['email']);
			$this->email->to('info@wines2u.gr', 'www.wines2u.gr');
			$this->email->cc('b.a@wines2u.gr', 'www.wines2u.gr');
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
	
			$data['msg_title'] = $this->lang->line('dear')." ".$data['userdata']['fname']." ".$data['userdata']['lname'].",".br(1).$this->lang->line('order_msg');
			$data['comments'] = $this->lang->line('order_details_msg').br(2).$cart;
			$data['post_msg'] = $this->lang->line('contact_dept').br(1);

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);
		
			#Email send to the user
			$this->email->from('no-reply@wines2u.gr', 'www.wines2u.gr');
			$this->email->to($data['userdata']['email']);
			$this->email->subject('www.wines2u.gr - Νέα Παραγγελία - New Order');
			$this->email->message($emsg);
			$this->email->send();
			
		$data['order_cart'] = $cart;
}
		$this->MFuncs->finaliseOrderPayed($order_id);
		$this->cart->destroy();
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('successful_payment');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'complete_payment';
		$this->load->vars($data);
		$this->load->view('template_master');
}
function payment_declined(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('payment_declined');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'declined_payment';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
function cancel_order(){
		$data['liID']=$this->uri->segment(1);
		$this->cart->destroy();
			$this->session->set_flashdata('message', $this->lang->line('order_canceled'));
			redirect('home','location');
	}

function payment_method(){
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		if ($this->input->post('select')!='') {
		$this->MFuncs->updatePayMethod($order_id, $id);
		}
		if (($this->input->post('country')!=$data['userdata']['country_id']) || ($this->input->post('address')!=$data['userdata']['address']) || ($this->input->post('city')!=$data['userdata']['city']) || ($this->input->post('postal')!=$data['userdata']['postal']) || ($this->input->post('floor')!=$data['userdata']['floor']) || ($this->input->post('name_bell')!=$data['userdata']['name_bell'])) {
		$this->MFuncs->updateShipAddress($order_id, $id);		
		}
		if ($this->input->post('select2')!='') {
		$this->MFuncs->updateReceiptType($order_id, $id);
		}
		
		if (($this->input->post('offer_code')!='') && ($this->input->post('offer_code')!='0')) {
		$check_code = $this->MFuncs->GetOfferCode($this->input->post('offer_code'));
		if ($check_code) {
		if ($check_code['active']=='Yes') {
			if ($check_code['global_use']=='Yes') {
				$this->MFuncs->updateOrderCodeUID($order_id, $id, $check_code['discount'], $check_code['code']);
			} else {
				if ($check_code['user_id']==0) {
					$this->MFuncs->updateOrderCodeUID($order_id, $id, $check_code['discount'], $check_code['code']);
				} elseif ($check_code['user_id']==$id) {
					$this->MFuncs->updateOrderCode($order_id, $id, $check_code['discount']);
				} else {
				$this->session->set_flashdata('message', $this->lang->line('wrong_offer_code'));
				redirect('complete_order_2/false','location');
				}
			}
		} else {
			$this->session->set_flashdata('message', $this->lang->line('wrong_offer_code'));
			redirect('complete_order_2/false','location');
		}
		} else {
			$this->session->set_flashdata('message', $this->lang->line('wrong_offer_code'));
			redirect('complete_order_2/false','location');
		}
		}
		
		if (($this->input->post('select')=='Cash') || ($this->input->post('select')=='Bank')  || ($this->input->post('select')=='Credit') || ($this->input->post('select')=='PayPal')) {
		if (($this->input->post('select')=='Cash') && ($this->input->post('country')!='1')) {
			$this->session->set_flashdata('message', $this->lang->line('pay_method_not_supported'));
			redirect('complete_order_2/false','location');
		} else {
			if ($this->input->post('select2')=='receipt') {
				redirect('complete_order_2_2','location');
			} elseif ($this->input->post('select2')=='invoice') {
				redirect('complete_order_2_3','location');
			} else {
			$this->session->set_flashdata('message', $this->lang->line('select_receipt_type'));
			redirect('complete_order_2/false','location');
			}
		}
		} else {
			$this->session->set_flashdata('message', $this->lang->line('select_pay_method'));
			redirect('complete_order_2/false','location');
		}
	}
function invoice_details(){
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
	if ($this->input->post('cmp_name') && $this->input->post('cmp_occupation') && $this->input->post('cmp_afm') && $this->input->post('cmp_address') && $this->input->post('cmp_city') && $this->input->post('cmp_doy')){
		$this->MFuncs->insertInvoiceDetails($order_id, $id);		
			redirect('complete_order_2_2','location');
		} else {
			$this->session->set_flashdata('message', $this->lang->line('complete_details'));
			redirect('complete_order_2_3','location');
		}
	}
function shipping_method(){
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		if ($this->input->post('select')!='') {
		$this->MFuncs->updateShipMethod($order_id, $id);
		if ($this->input->post('select')=='take_over') {
			redirect('complete_order_3','location');
		} else {
		$data['select'] = false;
		$data['sel_loc'] = true;
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('shipping_method');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_2_2';
		$this->load->vars($data);
		$this->load->view('template_master');
		}
		} else {
			$this->session->set_flashdata('message', $this->lang->line('select_ship_method'));
			redirect('complete_order_2_2','location');
		}
	}
function shipping_method_new(){
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
	if ($this->input->post('select')!='') {
		$this->MFuncs->updateShipMethod($order_id, $id);
		if ($this->input->post('select')=='take_over') {
			redirect('complete_order_3','location');
		} else {
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);

				if ($data['orderdata']['same_address']=='Yes') { 
				$postal = str_replace (" ", "", $data['userdata']['postal']);		
				$county = $this->MFuncs->GetCountybyPostal($postal);
				} else {
				$postal = str_replace (" ", "", $data['orderdata']['postal']);		
				$county = $this->MFuncs->GetCountybyPostal($postal);
				}
		if (!$county) {
		$data['select'] = false;
		$data['sel_loc'] = true;
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('shipping_method');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_2_2';
		$this->load->vars($data);
		$this->load->view('template_master');
		} else {
			if (($this->input->post('select')=='day_delivery') && ($county['flag']!='attica')) {
				$this->session->set_flashdata('message', $this->lang->line('not_out_of_attica'));
				redirect('complete_order_2_2','location');
			} else {
		$this->MFuncs->updateShipDestination2($order_id, $id, $county['flag']);
		$data['select'] = true;
		$data['sel_loc'] = true;
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('shipping_method');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_2_2';
		$this->load->vars($data);
		$this->load->view('template_master');
			}
			}
		}
	} else {
			$this->session->set_flashdata('message', $this->lang->line('select_ship_method'));
			redirect('complete_order_2_2','location');
	}
}
function shipping_method_new2(){
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
	if ($this->input->post('select')!='') {
		$this->MFuncs->updateShipMethod($order_id, $id);
		if ($this->input->post('select')=='take_over') {
			redirect('complete_order_3','location');
		} else {
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);

				if ($data['orderdata']['same_address']=='Yes') { 
				$postal = str_replace (" ", "", $data['userdata']['postal']);		
				$county = $this->MFuncs->GetCountybyPostal_new($postal);
				} else {
				$postal = str_replace (" ", "", $data['orderdata']['postal']);		
				$county = $this->MFuncs->GetCountybyPostal_new($postal);
				}
		if (!$county) {
		$data['select'] = false;
		$data['sel_loc'] = true;
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('shipping_method');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_2_2_new';
		$this->load->vars($data);
		$this->load->view('template_master');
		} else {
			if (($this->input->post('select')=='day_delivery') && ($county['flag']!='attica')) {
				$this->session->set_flashdata('message', $this->lang->line('not_out_of_attica'));
				redirect('complete_order_2_2_new','location');
			} else {
		$this->MFuncs->updateShipDestination2($order_id, $id, $county['flag']);
		$data['select'] = true;
		$data['sel_loc'] = true;
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('shipping_method');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_2_2_new';
		$this->load->vars($data);
		$this->load->view('template_master');
			}
			}
		}
	} else {
			$this->session->set_flashdata('message', $this->lang->line('select_ship_method'));
			redirect('complete_order_2_2_new','location');
	}
}
function shipping_method_abroad(){
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
	if ($this->input->post('select')!='') {
		$this->MFuncs->updateShipMethod($order_id, $id);

		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
				if ($data['orderdata']['same_address']=='Yes') { 
				//$postal = str_replace (" ", "", $data['userdata']['postal']);		
				$country_id = $data['userdata']['country_id'];
				} else {
				//$postal = str_replace (" ", "", $data['orderdata']['postal']);		
				$country_id = $data['orderdata']['country_id'];
				}
		$this->MFuncs->updateShipDestination3($order_id, $id);
		$data['select'] = true;
		$data['sel_loc'] = true;
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('shipping_method');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_2_2';
		$this->load->vars($data);
		$this->load->view('template_master');
	} else {
			$this->session->set_flashdata('message', $this->lang->line('select_ship_method'));
			redirect('complete_order_2_2','location');
	}
}
function shipping_method_abroad_new(){
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
	if ($this->input->post('select')!='') {
		$this->MFuncs->updateShipMethod($order_id, $id);

		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
				if ($data['orderdata']['same_address']=='Yes') { 
				//$postal = str_replace (" ", "", $data['userdata']['postal']);		
				$country_id = $data['userdata']['country_id'];
				} else {
				//$postal = str_replace (" ", "", $data['orderdata']['postal']);		
				$country_id = $data['orderdata']['country_id'];
				}
		$this->MFuncs->updateShipDestination3($order_id, $id);
		$data['select'] = true;
		$data['sel_loc'] = true;
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('shipping_method');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_2_2_new2';
		$this->load->vars($data);
		$this->load->view('template_master');
	} else {
			$this->session->set_flashdata('message', $this->lang->line('select_ship_method'));
			redirect('complete_order_2_2','location');
	}
}
function shipping_destination(){
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		if ($this->input->post('destination')!='') {
		$this->MFuncs->updateShipDestination($order_id, $id);
		$data['select'] = true;
		$data['sel_loc'] = true;
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('shipping_method');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_2_2';
		$this->load->vars($data);
		$this->load->view('template_master');
		} else {
			$this->session->set_flashdata('message', $this->lang->line('select_ship_method'));
			redirect('complete_order_2_2','location');
		}
	}
function shipping_destination2(){
		$order_id=$this->session->userdata('orderid');
		$id=$this->session->userdata('userid');
		if ($this->input->post('destination')!='') {
		$this->MFuncs->updateShipDestination($order_id, $id);
		$data['select'] = true;
		$data['sel_loc'] = true;
		$data['userdata'] = $this->MFuncs->GetUserbyID($id);
		$data['orderdata'] = $this->MFuncs->GetOrderbyID($id, $order_id);
		$data['title'] = $this->lang->line('cart_complete')." | ".$this->lang->line('shipping_method');
		$data['left_nav'] = 'left_nav';
		$data['right_nav'] = 'right_nav';
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'step_2_2_new';
		$this->load->vars($data);
		$this->load->view('template_master');
		} else {
			$this->session->set_flashdata('message', $this->lang->line('select_ship_method'));
			redirect('complete_order_2_2_new','location');
		}
	}
function send_order(){
	if ($this->input->post('fname') && $this->input->post('lname') && $this->input->post('address') && $this->input->post('city') && $this->input->post('postal') && $this->input->post('tel') && $this->input->post('mob') && $this->input->post('email')){

$cart = "<table cellpadding='6' cellspacing='1' style='width:100%' border='0'>";
$cart .= "<tr>";
$cart .= "<th>".$this->lang->line('cart_qty')."</th>";
$cart .= "<th>".$this->lang->line('cart_desc')."</th>";
$cart .= "<th style='text-align:right'>".$this->lang->line('cart_price')."</th>";
$cart .= "<th style='text-align:right'>".$this->lang->line('cart_sub')."</th>";
$cart .= "</tr>";
$i = 1;
foreach($this->cart->contents() as $items):
$product_details = $this->MFuncs->getProductDetails($items['id']);
$cart .= "<tr>";
$cart .= "<td>".$items['qty']."</td>";
$cart .= "<td>".$product_details['name'];
if ($this->cart->has_options($items['rowid']) == TRUE):
$cart .= "<p>";
foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value):
$cart .= "<strong>".$option_name.":</strong>".$option_value."<br />";
endforeach;
$cart .= "</p>";
endif;				
$cart .= "</td>";
$cart .= "<td style='text-align:right'>".$this->cart->format_number($items['price'])."</td>";
$cart .= "<td style='text-align:right'>&euro;".$this->cart->format_number($items['subtotal'])."</td>";
$cart .= "</tr>";
$i++;
endforeach;
$cart .= "<tr>";
$cart .= "<td colspan='2'> </td>";
$cart .= "<td class='right'><strong>".$this->lang->line('cart_total')."</strong></td>";
$cart .= "<td class='right'>&euro;".$this->cart->format_number($this->cart->total())."</td>";
$cart .= "</tr>";
$cart .= "</table>";
	
			$message = $cart;

			$data['msg_title'] = "Dear ".$this->input->post('fname')." ". $this->input->post('lname').",".br(1)."Thank you for ordering from Gallery2u.";
			$data['comments'] = "Your order is the following: ".br(1).$cart;
			$data['post_msg'] = "We will reply to you shortly".br(2)."Thank You!";

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);
			
			#Email send to the user
			$this->email->from('info@getid.gr', 'www.gallery2u.gr');
			$this->email->to($this->input->post('email'));
			$this->email->subject('www.gallery2u.gr - Φόρμα Παραγγελίας');
			$this->email->message($emsg);
			$this->email->send();

			$client = "First Name: ".$this->input->post('fname').br(1);
			$client .= "Last Name: ".$this->input->post('lname').br(1);
			$client .= "Address: ".$this->input->post('address').br(1);
			$client .= "City: ".$this->input->post('city').br(1);
			$client .= "Postal: ".$this->input->post('postal').br(1);
			$client .= "Telephone: ".$this->input->post('tel').br(1);
			$client .= "Mobile: ".$this->input->post('mob').br(1);
			$client .= "E-mail: ".$this->input->post('email').br(1);


			$data['msg_title'] = $this->input->post('fname')." ". $this->input->post('lname')." has placed an order in karite.gr".br(1);
			$data['comments'] = "The order is the following: ".br(1).$cart.br(2)."With the following information: ".br(1).$client;
			$data['post_msg'] = "They are waiting for our reply".br(2)."Thank You!";

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);

			#Email send to the company!
			$this->email->from($this->input->post('email'),  $this->input->post('fname')." ". $this->input->post('lname'));
			$this->email->to('dimitristangos@gmail.com', 'www.gallery2u.gr');
			$this->email->subject('www.gallery2u.gr - Φόρμα Παραγγελίας');
			$this->email->message($emsg);
			$this->email->send();
			

	$this->session->set_flashdata('message', 'Η παραγγελία σας συμπληρώθηκε με επιτυχία');
	redirect('view_cart','refresh');
	}   else {
	$this->session->set_flashdata('message', 'Δεν έχετε συμπληρώσει όλα τα πεδία');
	redirect('view_cart','');
	}
  }

function login(){
   	$data['liID']=$this->uri->segment(1);
	//$data['cats'] = $this->MCats->getTopCategories();
	$data['title'] = "Admin Login";
	$data['main'] = 'public_login';
	$this->load->vars($data);
	$this->load->view('template');  
}
function verify(){
  	$this->load->library('encrypt');
	if ($this->input->post('username') && $this->input->post('password')){
		$u = $this->input->post('username');
		$pw = $this->input->post('password');
		$row = $this->MAdmins->verifyUser($u,$pw);
		if (count($row)){
			$_SESSION['adminuserid'] = $row['id'];
			$this->session->set_userdata("adminuserid",$row['id']);

			redirect('admin/dashboard','refresh');
		}else{
			$this->session->set_flashdata('message', 'Wrong combination of username/password');
			redirect('admin','refresh');
		}
	}else{
			$this->session->set_flashdata('message', 'You must enter username and password');
			redirect('admin','refresh');
	}  
   
  }
function verify_client(){
  	$this->load->library('encrypt');
	if ($this->input->post('username') && $this->input->post('password')){
		$u = $this->input->post('username');
		$pw = $this->input->post('password');
		$row = $this->MFuncs->verifyClient($u,$pw);
		if (count($row)){
			$_SESSION['userid'] = $row['id'];
			$this->session->set_userdata("userid",$row['id']);
			$this->session->set_flashdata('message', $this->lang->line('logged_in'));
			if ($this->cart->contents()) {
			$id=$this->session->userdata('userid');
			$order_id = $this->MFuncs->insertOrder($id);
			$this->session->set_userdata("orderid",$order_id);
			redirect('complete_order_2/false','location');
			} else {
			redirect('home','refresh');
			}
		}else{
			$this->session->set_flashdata('message', $this->lang->line('wrong_combination'));
			if ($this->cart->contents()) {
			redirect('complete_order_1','location');
			} else {
			redirect('home','refresh');
			}
	}
	}
	else{
			$this->session->set_flashdata('message', $this->lang->line('enter_usr_pass'));
			if ($this->cart->contents()) {
			redirect('complete_order_1','location');
			} else {
			redirect('home','refresh');
			} 
			} 
  }

 function logout_client(){
	$this->session->set_userdata("userid",'');
	$_SESSION['userid'] = '';
	$this->session->set_flashdata('error',"You've been logged out!");
	redirect('home','refresh'); 	
 }

	function undercnstr(){
		$data['liID']=$this->uri->segment(1);
		$ld=$this->session->userdata('lang_id');
		$data['title'] = $this->lang->line('links_projects')." | ".$this->lang->line('links_undercnstr');
		$data['key'] = $this->MFuncs->getKeywords();
		$data['keywords'] = $data['key']['keywords'];
		$data['main'] = 'home';
		$this->load->vars($data);
		$this->load->view('template_master');
	}
	function subscribe(){
		$email=$this->input->post('email');
		if($email){
			$check=$this->MSubscribers->checkIfExistSub($email);
			if ($check==false) {
				$this->MSubscribers->createSubscriber();


			$data['msg_title'] = "New subscriber to wines2u.gr with e-mail address".br(1).$email;
			$data['comments'] = "";
			$data['post_msg'] = "";

			$this->load->library('parser');
			$emsg = $this->parser->parse('template_contact', $data, TRUE);

			#Email send to the company!
			$this->email->from('no-reply@wines2u.gr',  $this->input->post('email'));
			$this->email->to('info@wines2u.gr', 'www.wines2u.gr');
			//$this->email->to('dtangos@getid.gr', 'www.wines2u.gr');
			$this->email->subject('www.wines2u.gr - Newsletter');
			$this->email->message($emsg);
			$this->email->send();
				$this->session->set_flashdata('message',$this->lang->line('text_newsletter_success'));
				redirect('home','refresh');
			}else{
				$this->session->set_flashdata('message',$this->lang->line('text_newsletter_already'));
				redirect('home','refresh');
			}
		}else{
			$this->session->set_flashdata('message',$this->lang->line('text_newsletter_missing'));
			redirect('home','refresh');
		}
	}

function update_product_price(){
		$new_prices = $this->MFuncs->getAllnewPrPrice();
		$i=1;
		foreach($new_prices as $result=>$new_price):
		$this->MFuncs->updatePrPrice($new_price['pr_id'], $new_price['price']);
		$i++;
		endforeach;
			$this->session->set_flashdata('message', 'OK '.$i.'updated');
			redirect('home','refresh');
}


}
?>