<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Add_card extends CI_Controller
{
	public function __construct()
	{ 
		parent:: __construct();
		$this->load->model('common_model');
		$this->load->model('users_model');
		if(get_cookie('user_id'))
		{
			$this->session->set_userdata('user_id',get_cookie('user_id'));
		}
		if(!$this->session->userdata('user_id'))
		{
			redirect('home/login');
		}
		
	}
	public function index($order_id=null){
		$langId = 2;
		$data = array();
		$content_data['$order_id'] = $order_id;
		//redirect(base_url().'profile');
		//die;
		$content_data['userMembershipDetails'] = $this->users_model->getMembershipDetails($this->session->userdata('user_id'));
		//$content_data['orderDetails'] = $this->common_model->getAllRow('shop_orders',array('cart_id'=>$content_data['userMembershipDetails']['cart_id']));
		//pr($content_data['orderDetails']);
		$content_data['expiry'] = $this->common_model->getAll('usr_users',array('id'=>$this->session->userdata('user_id'))) ;
		if($order_id){
			$order_id=base64_decode($order_id);
			$content_data['orderDetails'] = $this->common_model->getAllRow('shop_orders',array('is_renewed'=>1 , 'is_booking'=>0 , 'invoiceAddress'=>$content_data['expiry'][0]['email'], 'order_id'=>$order_id ),'','created DESC'); 
			
		}else{
			$content_data['orderDetails'] = $this->common_model->getAllRow('shop_orders',array('is_renewed'=>1 , 'is_booking'=>0 ,'payed'=>0, 'invoiceAddress'=>$content_data['expiry'][0]['email'] ),'','created DESC'); 
		}
		
		$content_data['steps'] = $data['steps'] = $this->common_model->getAllRow('feu_user_steps',array('user_id'=>$this->session->userdata('user_id'))) ;
		//print_r($data['steps']); die;
		$content_data['userDetials'] = $this->common_model->getAllRowMultipleJoin('feu_userdetails',array('feu_userdetails.user_id'=>$this->session->userdata('user_id')),array(array('sys_files','sys_files.id = feu_userdetails.avatar_file_id'),array('feu_countries','feu_countries.country_code = feu_userdetails.country'))) ;
		//print_r($content_data['comments']); die;
		$content_data['languages'] = $this->common_model->getAll('sys_languages') ;
		$content_data['memberships'] = $this->common_model->getAll('shop_articles',array('id >'=>3,'id <'=>6),'','id Desc') ;
		$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		if(empty($data['upcomingEvents']))
		{
			$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		}
		if(empty($data['lastEvents']))
		{
			$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		}
		$data['checkinEvents'] = $this->common_model->getAllMultipleJoin('shop_orders',array('shop_orders.payed'=>1,'shop_carts.user_id'=>$this->session->userdata('user_id'),'shop_orders.checkin_payed'=>NULL,'evt_language_values.lang_id'=>$langId),array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_booking_details','shop_booking_details.cart_id = shop_carts.id'),array('evt_language_values','evt_language_values.event_id = shop_booking_details.event_id'),array('evt_events','evt_language_values.event_id = evt_events.id')),'','shop_orders.created,shop_orders.cart_id,evt_language_values.title,evt_events.alias','shop_booking_details.cart_id') ;
		$data['unfinishedPayment'] = $this->common_model->getAllMultipleJoin('shop_booking_details',array('is_booking'=>1,'payed'=>0,'shop_carts.user_id'=>$this->session->userdata('user_id')),array(array('shop_carts','shop_carts.id = shop_booking_details.cart_id'),array('shop_orders','shop_orders.cart_id = shop_carts.id')),'shop_orders.created','','shop_booking_details.cart_id');
		//echo $this->db->last_query();die;
		$content_data['countries'] = $this->common_model->getAll('feu_countries') ;
		$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
		$data['userDetials'] = $this->common_model->getAllRowMultipleJoin('feu_userdetails',array('feu_userdetails.user_id'=>$this->session->userdata('user_id')),array(array('sys_files','sys_files.id = feu_userdetails.avatar_file_id'),array('feu_countries','feu_countries.country_code = feu_userdetails.country'))) ;
		$data['cms_pages_1'] = $this->common_model->getAllMultipleJoin('cms_page',array('section_id'=>1,'language_id'=>$langId),array(array('sys_files','sys_files.id = cms_page.image_id')),'cms_page.id ASC','*','');
		$data['cms_pages_2'] = $this->common_model->getAllMultipleJoin('cms_page',array('section_id'=>2,'language_id'=>$langId),array(array('sys_files','sys_files.id = cms_page.image_id')),'cms_page.id ASC','*','');
		$data['cms_pages_3'] = $this->common_model->getAllMultipleJoin('cms_page',array('section_id'=>3,'language_id'=>$langId),array(array('sys_files','sys_files.id = cms_page.image_id')),'cms_page.id ASC','*','');
		$data['cms_pages_4'] = $this->common_model->getAllMultipleJoin('cms_page',array('section_id'=>4,'language_id'=>$langId),array(array('sys_files','sys_files.id = cms_page.image_id')),'cms_page.id ASC','*','');
		$data['title'] = "Add Card | ".$data['userDetials']['username'];
		//print_r($data);die;
		$data['content'] = $this->load->view('add_card', $content_data, TRUE);
		$this->load->view('template', $data);
	}

	
}
