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

class Parties extends CI_Controller
{
	public function __construct()
	{ 
		parent:: __construct();
		$this->load->model('users_model');
		$this->load->model('common_model');
		$this->load->library('Mobile_detect');
		$this->load->helper('text');
		if(checkStep()==1)
		{
			redirect('profile');
		}
		if(checkCardUpdated()==2)
		{
			redirect('profile');
		}
		if(get_cookie('user_id'))
		{
			$this->session->set_userdata('user_id',get_cookie('user_id'));
		}
		if($this->session->userdata('user_id')){
			//if($this->session->userdata('user_id')==25267){
				if(getOpenBookingInvoices() > 0)
				{
					$this->session->set_userdata('pay_book_first',1);
					redirect('invoice');
				}
			//}
		}
	}
	public function details($slug='')
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$this->session->userdata('user_id'))) ;
		/*if($content_data['loginDetails'][0]['id']=='11330')
		{
			$content_data['allMembers'] = $this->common_model->getAll('usr_users') ;
		}*/
		$content_data['userDiscounts'] = $this->common_model->getAllRow('feu_user_discounts',array('user_id'=>$this->session->userdata('user_id')));
		$content_data['steps'] = $this->common_model->getAllRow('feu_user_steps',array('user_id'=>$this->session->userdata('user_id'))) ;
		$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) ;
		}
		$content_data['partyDetails'] = $this->common_model->getAllRowMultipleJoin('evt_events',array('evt_event_files.is_banner'=>1,'evt_language_values.lang_id'=>$langId,'evt_events.alias'=>$slug),array(array('evt_language_values','evt_language_values.event_id = evt_events.id'),array('loc_events_locations','evt_events.id = loc_events_locations.event_id'),array('loc_locations','loc_events_locations.location_id = loc_locations.id'),array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('sys_files','sys_files.id = evt_event_files.file_id')),'evt_events.created DESC','evt_events.id as id, evt_events.*,sys_files.path,sys_files.filename,sys_files.extension,loc_locations.name,loc_locations.country,loc_locations.city,loc_locations.zipcode,evt_event_files.is_banner,evt_language_values.title,evt_language_values.sub_title,evt_language_values.description,evt_language_values.teasertext,evt_language_values.extra_info,evt_language_values.extra_text','loc_events_locations.event_id,evt_language_values.title,evt_language_values.description');
		//echo $this->db->last_query();die;
		if(empty($content_data['partyDetails']))
		{
			redirect(base_url());
		}
		$content_data['pastParties'] = $this->common_model->getAllMultipleJoin('evt_events',array('evt_event_files.is_banner'=>1,'evt_language_values.lang_id'=>$langId,'evt_events.visible'=>1,'time_from <'=>time()),array(array('evt_language_values','evt_language_values.event_id = evt_events.id'),array('loc_events_locations','evt_events.id = loc_events_locations.event_id'),array('loc_locations','loc_events_locations.location_id = loc_locations.id'),array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('sys_files','sys_files.id = evt_event_files.file_id')),'RAND()','evt_events.id as id, evt_events.*,sys_files.path,sys_files.filename,sys_files.extension,loc_locations.name,loc_locations.country,loc_locations.city,loc_locations.zipcode,evt_event_files.is_banner,evt_language_values.title,evt_language_values.description,evt_language_values.teasertext','loc_events_locations.event_id,evt_language_values.title,evt_language_values.description',0,3);
		if($content_data['partyDetails']['past_parties']!='')
		{
			$where = "evt_event_files.is_banner =1 and evt_language_values.lang_id =".$langId." and evt_events.id in(".$content_data['partyDetails']['past_parties'].") and evt_events.visible=1 and time_from <".time();	
			$content_data['pastParties'] = $this->common_model->getAllMultipleJoin('evt_events',$where,array(array('evt_language_values','evt_language_values.event_id = evt_events.id'),array('loc_events_locations','evt_events.id = loc_events_locations.event_id'),array('loc_locations','loc_events_locations.location_id = loc_locations.id'),array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('sys_files','sys_files.id = evt_event_files.file_id')),'RAND()','evt_events.id as id, evt_events.*,sys_files.path,sys_files.filename,sys_files.extension,loc_locations.name,loc_locations.country,loc_locations.city,loc_locations.zipcode,evt_event_files.is_banner,evt_language_values.title,evt_language_values.description,evt_language_values.teasertext','loc_events_locations.event_id,evt_language_values.title,evt_language_values.description');
			//echo $this->db->last_query(); die;
		}
		if($content_data['partyDetails']['stripe_account_id']>0)
		{
			$content_data['stripe_credentials'] = $this->common_model->getAllRow('stripe_credentials',array('id'=>$content_data['partyDetails']['stripe_account_id']));
			//echo $this->db->last_query(); die;
		}  
		//print_r($content_data['pastParties']); die;
		$data['checkinEvents'] = array();
		if($this->session->userdata('user_id'))
		{
			$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') ;
			$content_data['userDetials'] = $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'))) ;
			$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');
		}
		$content_data['partyPrice'] = $this->common_model->getAllRowMultipleJoin('evt_events',array('event_features.event_id'=>$content_data['partyDetails']['id'],'event_features.type'=>1),array(array('event_features','event_features.event_id = evt_events.id')),'event_features.base_price ASC');
		$content_data['entries'] = $this->common_model->getAllMultipleJoin('evt_events',array('event_features.event_id'=>$content_data['partyDetails']['id'],'event_features.type'=>1,'event_features_lang_values.lang_id'=>$langId,'event_features.is_hidden'=>0),array(array('event_features','event_features.event_id = evt_events.id'),array('event_features_lang_values','event_features_lang_values.event_feature_id = event_features.id'),array('sys_files','sys_files.id = event_features.image_id')),'event_features.base_price ASC','event_features_lang_values.*,sys_files.*,event_features.*');
		if($content_data['entries'])
		{
			foreach ($content_data['entries'] as $key => $entryy) {
				$entry_id = $entryy['event_feature_id'];
				$rooms = $this->common_model->getAllMultipleJoin('evt_events',array('event_features.entry_id'=>$entry_id,'event_features.type'=>2,'event_features_lang_values.lang_id'=>$langId),array(array('event_features','event_features.event_id = evt_events.id'),array('event_features_lang_values','event_features_lang_values.event_feature_id = event_features.id'),array('sys_files','sys_files.id = event_features.image_id')),'event_features.base_price ASC','event_features_lang_values.*,sys_files.*,event_features.*');
				$html = '';
				if(!empty($rooms)){ 
		            foreach ($rooms as $room) { 
						if($room['is_sold']==0)
						{
							$html .= $room['title'].' '.number_format($room['base_price'],2,',','.').' &euro;, ';
						}
						else
						{
							$html .= '<strike>'.$room['title'].' '.number_format($room['base_price'],2,',','.').' &euro; ('.getLang('Sold_Out').')</strike>, ';
						}
		        	} 
		    	}
		    	$content_data['entries'][$key]['room_info'] = trim($html,', ');
		    }
		}
		$content_data['booked_users'] = $booked_users = $this->common_model->getAllMultipleJoin('shop_booking_details',array('shop_booking_details.event_id'=>$content_data['partyDetails']['id'],'feu_userdetails.user_id >'=>0, 'feu_userdetails.user_id !='=>25267),array(array('shop_carts','shop_carts.id = shop_booking_details.cart_id'),array('feu_userdetails','feu_userdetails.user_id = shop_carts.user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'RAND()','','shop_booking_details.cart_id');
		if(count($booked_users)>5)
		{
			$content_data['booked_users'] = $this->common_model->getAllMultipleJoin('shop_booking_details',array('shop_booking_details.event_id'=>$content_data['partyDetails']['id'],'feu_userdetails.user_id >'=>0, 'feu_userdetails.user_id !='=>25267),array(array('shop_carts','shop_carts.id = shop_booking_details.cart_id'),array('feu_userdetails','feu_userdetails.user_id = shop_carts.user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'RAND()','','shop_carts.user_id',0,10);
		}

		$related_users = [];
		$related_users_id = [];
		if($this->session->userdata('user_id')){
			if(count($booked_users)>0){
				//echo '<pre>';print_r($booked_users);die;
				foreach ($booked_users as $key => $value) {
					if(($this->session->userdata('user_id')!=$value['user_id']) && !in_array($value['user_id'], $related_users_id)){
						$friend = $this->common_model->getAllRowMultipleJoin('feu_relationships',array('user_id_1'=>$value['user_id'],'user_id_2'=>$this->session->userdata('user_id'),'type'=>'friend','status'=>'accepted'));
						$unfriend = $this->common_model->getAllRow('feu_relationships',array('user_id_2'=>$value['user_id'],'user_id_1'=>$this->session->userdata('user_id'),'type'=>'friend','status'=>'accepted'));
						$hotshottedhis = $this->common_model->getAllRow('like_likes',array('user_id'=>$value['user_id'],'identifier'=>'profile:'.$this->session->userdata('user_id'))) ;
						$hotshottedme = $this->common_model->getAllRow('like_likes',array('user_id'=>$this->session->userdata('user_id'),'identifier'=>'profile:'.$value['user_id'])) ;
						if($friend){
							array_push($related_users, $value);
						} elseif($unfriend){
							array_push($related_users, $value);
						} elseif($hotshottedhis){
							array_push($related_users, $value);
						} elseif($hotshottedme){
							array_push($related_users, $value);
						}
						array_push($related_users_id, $value['user_id']);
					}
				}
				//pr($related_users);
			}
		}
		$content_data['related_users']=$related_users;
		//echo count($booked_users);die;
		$content_data['userDetail']='';
		$content_data['userMembershipDetails']='';
		if($this->session->userdata('user_id'))
		{
			$content_data['userDetail'] = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$this->session->userdata('user_id'))) ;
			$content_data['userMembershipDetails'] = $this->users_model->getMembershipDetails($this->session->userdata('user_id'));
		}
		
		$content_data['logged_in_gentleman'] = $this->common_model->getAllMultipleJoin('usr_users',array('filename!='=>'','accounttype'=>'gentleman','about !='=>'','gentleman >'=>0),array(array('feu_userdetails','feu_userdetails.user_id = usr_users.id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id'),array('newsletter_couple_lady','newsletter_couple_lady.gentleman = usr_users.id'),array('feu_countries','feu_countries.country_code = feu_userdetails.country')),'RAND(), feu_userdetails.reality_authenticated','*,feu_userdetails.alias','feu_userdetails.user_id');

		$content_data['logged_in_lady'] = $this->common_model->getAllMultipleJoin('usr_users',array('filename!='=>'','accounttype'=>'lady','usr_users.id !='=>11330,'about !='=>'','lady >'=>0),array(array('feu_userdetails','feu_userdetails.user_id = usr_users.id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id'),array('feu_countries','feu_countries.country_code = feu_userdetails.country'),array('newsletter_couple_lady','newsletter_couple_lady.lady = usr_users.id')),'RAND(), feu_userdetails.reality_authenticated','*,feu_userdetails.alias','feu_userdetails.user_id');
		//echo $this->db->last_query();die;
		
		$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
		$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['device'] = ($this->mobile_detect->isMobile() ? ($this->mobile_detect->isTablet() ? 'tablet' : 'phone') : 'computer');
		$data['title'] = "Castleevents | ".getLang('Party_Details');
		$data['meta_title'] = "Castleevents | ".getLang('Party_Details');
		$data['meta_description'] = "Castleevents | ".getLang('Party_Details');
		$data['meta_keywords'] = "Castleevents, ".getLang('Party_Details');
		$data['meta_genre'] = 'partyDetails';
		if(!empty($content_data['partyDetails']))
		{
			$data['title'] = "Castleevents | ".$content_data['partyDetails']['title'];
			$data['meta_title'] = $content_data['partyDetails']['title'];
			$data['meta_description'] = strip_tags(html_entity_decode($content_data['partyDetails']['description']));
			$data['meta_keywords'] = $content_data['partyDetails']['title'];
		}
		$content_data['side_events'] = $this->common_model->getAllMultipleJoin('side_events',array('side_events_to_event.event_id'=>$content_data['partyDetails']['id'],'lang_id'=>$langId,'is_visible'=>1),array(array('side_events_lang_values','side_events.id = side_events_lang_values.side_event_id'),array('side_events_to_event','side_events.id = side_events_to_event.side_event_id')),'side_events.created DESC');
		$content_data['is_booked'] = 0;
		if($this->session->userdata('user_id'))
		{
			$where = 'shop_booking_details.event_id = '.$content_data['partyDetails']['id'].' and user_id='.$this->session->userdata('user_id').' and payed = 1 and refund_trn_id="" and event_guest.event_id > 0 ';
			//$where = 'shop_booking_details.event_id = '.$content_data['partyDetails']['id'].' and user_id='.$this->session->userdata('user_id').' and payed = 1 and (side_events IS NULL OR side_events = "") and refund_trn_id="" and event_guest.event_id > 0 ';
			$is_booked = $this->common_model->getAllMultipleJoin('shop_orders',$where,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_booking_details','shop_booking_details.cart_id = shop_orders.cart_id'),array('event_guest','event_guest.order_id = shop_orders.order_id')),'','','shop_booking_details.cart_id');
			
			if(count($is_booked)>0)
			{
				$content_data['is_booked'] = 1;
			}
		}
		$comments = $this->common_model->getAllMultipleJoin('review_comments',array('event_id'=>$content_data['partyDetails']['id'],'parent_id'=>0,'approved'=>1),array(array('feu_userdetails','feu_userdetails.user_id = review_comments.user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'review_comments.created DESC','*, review_comments.id','',0,2);
		//echo '<pre>';print_r($comments);die;
		if($comments){
			foreach ($comments as $key => $value) {
				$replies = $this->common_model->getAllMultipleJoin('review_comments',array('event_id'=>$content_data['partyDetails']['id'],'parent_id'=>$value['id'],'approved'=>1),array(array('feu_userdetails','feu_userdetails.user_id = review_comments.user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'review_comments.created DESC');
					
				$comments[$key]['replies'] = $replies;
			}
		}
		$content_data['site_address_name'] = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_name'));
		$content_data['site_address_city'] = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_city'));
		$content_data['site_address_country_zip'] = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_country_zip'));
		$content_data['comments'] = $comments;
		$data['content'] = $this->load->view('parties', $content_data, TRUE);
		$this->load->view('template', $data);
	}
	public function getRooms()
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		
		$type = $this->input->post('type')+1;
		if($type==2)
		{
			$entry_id = $this->input->post('entry_id');
			$rooms = $this->common_model->getAllMultipleJoin('evt_events',array('event_features.entry_id'=>$entry_id,'event_features.type'=>$type,'event_features_lang_values.lang_id'=>$langId),array(array('event_features','event_features.event_id = evt_events.id'),array('event_features_lang_values','event_features_lang_values.event_feature_id = event_features.id'),array('sys_files','sys_files.id = event_features.image_id')),'is_sold,event_features.base_price ASC','event_features_lang_values.*,sys_files.*,event_features.*');
			$html = '';
			$user_Discount = 0;
			if(!empty($rooms)){ 
	            foreach ($rooms as $room) { 
	            	$userDiscountData = $this->common_model->getAllRow('feu_user_discounts',array('user_id'=>$this->input->post('user_id'),'discount >'=>0));
					if($userDiscountData){
						$user_Discount = $userDiscountData['discount'];
					}
					if($room['is_sold']==0)
					{
						$html.='<div class="entryBox box2" data-title="'.$room['title'].'" data-id="'.$room['id'].'" data-price="'.$room['base_price']*(1-($user_Discount/100)).'" style="border:1px solid #42424c" data-type="2">';
					}
					else
					{
						$html.='<div class="entryBox" data-title="'.$room['title'].'" data-id="'.$room['id'].'" data-price="'.$room['base_price'].'" style="border:1px solid #42424c" data-type="2">';
					}
	             	$html.='<img src="'.base_url().'assets/userfiles/'.$room['path'].$room['filename'].'.'.$room['extension'].'" alt="">
	                      <div class="entrycontent">';
						  if($room['is_sold']==0)
						  {
							 $html.='<h4>'.$room['title'].'</h4>';
						  }
						  else
						  {
							 $html.='<h4>'.$room['title'].'   <span style="color:red">'.getLang('Sold_Out').'</span></h4>';
						  }
	                       if($user_Discount > 0){
	                       		$html.='<p>'.strip_tags($room['content']).'</p>
		                       <span><strike>EUR '.$room['base_price'].'</strike></span>
	                        	<span class="entryDiscount">'.$user_Discount.' % Discount</span>
		                        <span>EUR '.number_format($room['base_price']*(1-($user_Discount/100)),2,',','.').'/ '.getLang('Partynight').' (EUR '.number_format($room['extra_night_price'],2,',','.').' '.getLang('additional_nights').')</span>
		                      </div>';
	                       } else {
	                       		$html.='<p>'.strip_tags($room['content']).'</p>
		                       <span>EUR '.number_format($room['base_price'],2,',','.').'/ '.getLang('Partynight').' (EUR '.number_format($room['extra_night_price'],2,',','.').' '.getLang('additional_nights').')</span>
		                      </div>';
	                       }
	                       $html.='
	                    </div>
	                    <input type="hidden" id="step_2_price" value="0">
	                	<input type="hidden" id="room_id" value="">';
	        	} 
	    	}
	    	else
	    	{
	    		$html.='<div class="extranight">                   
                     <h4 class="text_white">'.getLang('No_rooms_available').'</h4>                 
                 </div>';
	    	}
		}
		elseif($type==3)
		{
			$room_id = $this->input->post('room_id');
			$rooms = $this->common_model->getAllMultipleJoin('evt_events',array('event_features.room_id'=>$room_id,'event_features.type'=>$type),array(array('event_features','event_features.event_id = evt_events.id')),'event_features.base_price ASC','event_features.*');
			$roomDetails = $this->common_model->getAllRowMultipleJoin('event_features',array('event_features.id'=>$room_id,'event_features_lang_values.lang_id'=>$langId),array(array('event_features_lang_values','event_features_lang_values.event_feature_id = event_features.id'),array('sys_files','sys_files.id = event_features.image_id')),'event_features.base_price ASC','event_features_lang_values.*,sys_files.*,event_features.*');
			//echo $this->db->last_query(); die;
			$html = '';
			if(!empty($rooms))
			{

	             	$html.='<div class="entryBox box3" id="" style="border:1px solid #42424c" data-type="3">
	                      <img src="'.base_url().'assets/userfiles/'.$roomDetails['path'].$roomDetails['filename'].'.'.$roomDetails['extension'].'" alt="">
	                      <div class="entrycontent">
	                        <h4>'.getLang('Extra_Nights').'</h4>
	                        <p>';
	                        if(!empty($rooms))	
	                        {
	                        	foreach ($rooms as $value) {
	                        		$html.='<p class="checkboxGold"><input type="checkbox" id="test'.$value['id'].'" data-id="'.$roomDetails['title'].'" class="chk" name="extracheck[]" value="'.$value['id'].'"><label for="test'.$value['id'].'">'.date('l',$value['date']).' '.date('d.m.Y',$value['date']).'</label></p>';
	                        	}
	                        }
	                $html.='</p>
	                        <span>EUR '.number_format($roomDetails['extra_night_price'],2,',','.').'</span>
	                      </div>
	                    </div>
	                    <input type="hidden" id="night_price" value="'.$roomDetails['extra_night_price'].'">
	                    <input type="hidden" id="step_3_price" value="0">
	                	<input type="hidden" id="extra_id" value="">';
			}
			else
	    	{
	    		$html.='<div class="extranight">                   
                     <h4 class="text_white">'.getLang('No_extra_night_available').'</h4>                 
                 </div>';
	    	}
	        	
		}
		elseif($type==4)
		{
			$entry_id = $this->input->post('entry_id');
			$services = $this->common_model->getAllMultipleJoin('evt_events',array('event_features.entry_id'=>$entry_id,'event_features.type'=>$type,'event_features_lang_values.lang_id'=>$langId),array(array('event_features','event_features.event_id = evt_events.id'),array('event_features_lang_values','event_features_lang_values.event_feature_id = event_features.id'),array('sys_files','sys_files.id = event_features.image_id')),'event_features.base_price ASC','event_features_lang_values.*,sys_files.*,event_features.*');
			$html = '';
	             	if(!empty($services))
	             	{
	             		$html.='<div class="entryBox box4" id="" style="border:1px solid #42424c" data-type="3">
	                      <!--<img src="'.base_url().'assets/userfiles/'.$services[0]['path'].$services[0]['filename'].'.'.$services[0]['extension'].'" alt="">-->
	                      <img src="'.base_url().'assets/images/limousine.jpg" alt="">
	                      <div class="entrycontent">
	                        <h4>'.getLang('Limousine_Service').'</h4>
	                        <p>';
	                        if(!empty($services))	
	                        {
	                        	foreach ($services as $value) {
	                        		$html.='<p class="checkboxGold"><input type="checkbox" id="test1'.$value['id'].'" data-id="'.$value['title'].'" class="limousine" name="limousine[]" value="'.$value['id'].'"><label for="test1'.$value['id'].'">'.$value['title'].'</label></p>';
	                        	}
	                        }
		                $html.='</p>
		                        <span>'.getLang('Price_per_transfer').' EUR '.number_format($services[0]['base_price'],2,',','.').'</span>
		                      </div>
		                    </div>
		                    <input type="hidden" id="limousine_price" value="'.$services[0]['base_price'].'">
		                    <input type="hidden" id="step_4_price" value="0">
		                	<input type="hidden" id="limousine_id" value="">';
	             	}
	             	else
			    	{
			    		$html.='<div class="extranight">                   
		                     <h4 class="text_white">'.getLang('No_limousine_services_available').'</h4>                 
		                 </div>';
			    	}
		}
    	echo $html;exit;
	}
	public function bookParty()
	{
		$userDetails = $this->common_model->getAllRow('usr_users',array('id'=>$this->input->post('user_id')));
		$userData = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$this->input->post('user_id')));
		$cartArr = array(
					'created'=>time(),
					'user_id'=>$this->input->post('user_id'),
					'session_id'=>$this->session->userdata('session_id'),
					'ordered'=>1
			);
		$cartId = $this->common_model->insertData('shop_carts',$cartArr);
		
		$event_id = $this->input->post('event_id');
		$entry_id = $this->input->post('entry_id');
		$room_id = $this->input->post('room_id')?$this->input->post('room_id'):'';
		$extra_id = $this->input->post('extra_id')?$this->input->post('extra_id'):'';
		$limousine_id = $this->input->post('limousine_id')?$this->input->post('limousine_id'):'';

		$step_1_price = $this->input->post('step_1_price');
		$step_2_price = $this->input->post('step_2_price');
		$step_3_price = $this->input->post('step_3_price');
		$step_4_price = $this->input->post('step_4_price');
		$step_1_discount = $this->input->post('step_1_discount');
		$early_discount = $this->input->post('early_discount');
		$early_bird_discount = 0;
		if($early_discount>0)
		{
			$entryData = $this->common_model->getAllRow('event_features',array('id'=>$entry_id));
			if(count($entryData)>0)
			{
				$early_bird_discount = ($entryData['base_price'] - $step_1_price)*100;
			}
		}
		$featureArr=array();
		if($entry_id !='')
		{
			$entryDetails= $this->common_model->getAllRowMultipleJoin('event_features',array('event_features.id'=>$entry_id),array(array('event_features_lang_values','event_features_lang_values.event_feature_id = event_features.id')));
			$featureArr = array(
					'event_id'=>$event_id,
					'cart_id'=>$cartId,
					'feature_id'=>$entry_id,
					'feature_type'=>1,
					'price'=>$step_1_price
			);
			$this->common_model->insertData('shop_booking_details',$featureArr);
		}
		if($room_id !='' && $room_id > 0)
		{
			$roomDetails= $this->common_model->getAllRowMultipleJoin('event_features',array('event_features.id'=>$room_id),array(array('event_features_lang_values','event_features_lang_values.event_feature_id = event_features.id')));
			$featureArr = array(
					'event_id'=>$event_id,
					'cart_id'=>$cartId,
					'feature_id'=>$room_id,
					'feature_type'=>2,
					'price'=>$step_2_price
			);
			$this->common_model->insertData('shop_booking_details',$featureArr);
		}
		if($extra_id !='')
		{
			$featureArr = array(
					'event_id'=>$event_id,
					'cart_id'=>$cartId,
					'feature_id'=>$extra_id,
					'feature_type'=>3,
					'price'=>$step_3_price
			);
			$this->common_model->insertData('shop_booking_details',$featureArr);
		}
		if($limousine_id !='')
		{
			$featureArr = array(
					'event_id'=>$event_id,
					'cart_id'=>$cartId,
					'feature_id'=>$limousine_id,
					'feature_type'=>4,
					'price'=>$step_4_price
			);
			$this->common_model->insertData('shop_booking_details',$featureArr);
		}
		$orderDetails = $this->common_model->getAllRow('shop_orders','','','','max(order_id) as order_id');
		
		$booked_by = 0;
		if($this->input->post('user_id')!=$this->session->userdata('user_id'))
		{
			$booked_by = 1;
		}
		$user_Discount = 0;
		$party_Discount = 0;
		if($step_1_discount>0){
			$userDiscountData = $this->common_model->getAllRow('feu_user_discounts',array('user_id'=>$this->input->post('user_id'),'discount >'=>0));
			if($userDiscountData){
				$user_Discount = $userDiscountData['discount'];
			}
		}
		$room_discount = 0;
		if($early_bird_discount>0){
			$partyDiscountData = $this->common_model->getAllRow('evt_events',array('id'=>$event_id));
			if($partyDiscountData){
				$party_Discount = $partyDiscountData['discount'];
			}
		}
		if($user_Discount>0){
			$roomData = $this->common_model->getAllRow('event_features',array('id'=>$room_id));
			if($roomData)
			{
				$room_discount = ($roomData['base_price']*($user_Discount/100))*100;
			}
		}

		/*reservation*/
		$mainTotal = (($step_1_price-$step_1_discount)+$step_2_price+$step_3_price+$step_4_price);
		$finalTotal = (($step_1_price-$step_1_discount)+$step_2_price+$step_3_price+$step_4_price);
		$reservation = $this->input->post('reservation');
		$reservationFee = 0;
		$is_recomended = 0;
		if($reservation == 1) {
			$setting = getValue('sys_settings', array('key'=>'reservation_fee')); 
			$reservation_charge = $setting ? $setting['value'] : 0;
			$finalTotal = (($finalTotal * $reservation_charge)/100);
			$is_recomended = 1;
		}
		$dataset = array(
			'order_id'				=> $orderDetails['order_id']+1,
			'cart_id' 				=> $cartId,
			'shipping_address_id' 	=> 13,
			'invoice_address_id' 	=> 13,
			'ip_address' 			=> $this->input->ip_address(),
			'total_base' 			=> $finalTotal*100,
			'shipping_fee' 			=> 0,
			'payment_fee' 			=> 0,
			'vat' 					=> 0,
			'total_sum' 			=> $finalTotal*100,
			'payment_method_id' 	=> 12,
			'invoiceAddress' 		=> $userDetails['email'],
            'discount'              => ($step_1_discount*100)+$early_bird_discount,
            'room_discount'         => $room_discount,
            'party_discount'        => $party_Discount,
            'user_discount'         => $user_Discount,
            'time'					=> 0,
            'created'				=> time(),
            'terms_accept_date'		=> time(),
            'is_booking'			=> 1,
            'booked_by'				=> $booked_by,
            'is_recomended'			=> $is_recomended,
            'reservation_rest_amount'=> ($mainTotal - $finalTotal)*100,
		);
		$this->common_model->insertData('shop_orders',$dataset);
		$orderId = $orderDetails['order_id']+1;
		
		$this->common_model->UpdateData('shop_orders',array('order_id_masked'=>'CE-'.$orderId),array('order_id'=>$orderId));

		$eventsData = $this->common_model->getAllRow('evt_events',array('id'=>$event_id));
		$Pertydiscount = 0;
		if(!empty($eventsData))
		{
			if($eventsData['discount']>0)
			{
				$Pertydiscount = $eventsData['discount'];
			}
		}
		$to = $userDetails['email'];
		$sub = getUserLang('Thanks_For_your_booking', $this->input->post('user_id')).': Order CE-'.$orderId;
		//$sub = 'Confirmation: Successful payment';
		//$body= '<p>Dear '.$userData['username'].',</p><br/>';
		$body= '<p>'.getUserLang('We_have_received_your_booking', $this->input->post('user_id')).'!</p>';
		$body.= '<p>'.getUserLang('Below_you_will_find_your_order', $this->input->post('user_id')).'.</p><br/>';
		$detailsData = $this->common_model->getAllRow('evt_events',array('id'=>$event_id));
		$orderData = $this->common_model->getAllRow('shop_orders',array('order_id'=>$orderId));
		if(count($detailsData)>0)
		{
			$body.= '<p>Event Date and Place: '.date('d M Y',$detailsData['time_from']).' - '.eventDetails($detailsData['id']).'</p>';
		}
		$body.= '<p>'.getUserLang('Invoice_Number', $this->input->post('user_id')).': CE-'.$orderId.'</p><p>'.getUserLang('Generated_On', $this->input->post('user_id')).': '.date('Y-m-d',time()).'</p><p>'.getUserLang('Due_to', $this->input->post('user_id')).': '.date('Y-m-d',strtotime("+7 day")).'</p><p>'.getUserLang('Amount', $this->input->post('user_id')).': '.number_format(($orderData['total_sum']/100),2, '.', '').' EUR</p>';
		
		$body.= '<p>'.getUserLang('Details_of_your_Order', $this->input->post('user_id')).':</p><br/>';
		if($entry_id !='')
		{
			$body.= '<p>- '.((!empty($entryDetails))?$entryDetails['title']:"").' '.$step_1_price.' EUR';
			if($Pertydiscount>0)
			{
				$body.= ' ('.$Pertydiscount.'% Discount)';
			}
			$body.= '</p>';
		}
		

		if($room_id !='')
		{
			if($room_discount > 0){
				$body.= '<p>- '.((!empty($roomDetails))?$roomDetails['title']:"").' '.($step_2_price).' EUR</p>';
				$body.= ' ('.$user_Discount.'% Discount)';
			} else {
				$body.= '<p>- '.((!empty($roomDetails))?$roomDetails['title']:"").' '.$step_2_price.' EUR</p>';
			}
			
		}
		if($extra_id !='')
		{
			$body.= '<p>- '.getUserLang('Extra_Nights', $this->input->post('user_id')).' '.$step_3_price.' EUR</p>';
		}
		if($limousine_id)
		{
			$body.= '<p>- '.getUserLang('Limousine_Service', $this->input->post('user_id')).' '.$step_4_price.' EUR</p>';
		}
		if($step_1_discount >0)
		{
			$body.= '<p>- '.getUserLang('User_Discount', $this->input->post('user_id')).' '.$step_1_discount.' EUR</p>';
		}
		if($is_recomended>0)
		{
			$body.= '<p>- Deposit '.($finalTotal).' EUR</p>';
			$body.= '<p>- Rest payment at arrival '.($mainTotal - $finalTotal).' EUR</p>';
		}
		$body.= '<br/>';
		$body.= '<p>'.getUserLang('You_will_find_the_invoice_and_payment', $this->input->post('user_id')).'.</p>';
		$body.= '<p>'.getUserLang('We_appreciate_very_much', $this->input->post('user_id')).'.</p><br/>';
		$body.= '<p>'.getUserLang('Please_do_not_hesitate_to_contact', $this->input->post('user_id')).'.</p><br/><br/>';
		//$body.= '<p>Best regards,</p><p>Your Castleevents Team </p>';


		$bodys=' <table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
	                    <tr>
	                       <td>
	                          <table cellspacing="0" cellpadding="0" border="0" width="100%">
	                             <tr>
	                                <td align="center" style="padding: 40px; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #b3975b;">
	                                   <h2>'.getUserLang('Dear', $this->input->post('user_id')).' <span style="text-transform:capitalize">'.$userData['username'].'</span> </h2>
	                                </td>
	                             </tr>
	                             <tr>
	                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
	                                   '.$body.'
	                                </td>
	                             </tr>
	                             <tr>
	                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">
	                             		'.getUserLang('Best_regards', $this->input->post('user_id')).' <br>
	                             		<p style="margin:5px 0 0">'.getUserLang('Your_Castleevents_Team', $this->input->post('user_id')).'</p> 
	                             	</td>
	                             </tr>
	                          </table>
	                       </td>
	                    </tr>
	                </table>';
	    $is_mail = 0;
	    if($this->input->post('is_mail')) {
	    	$is_mail = 1;
	    }
	    if($is_mail == 0) {
			$this->utility->sendOrderMail($to,$sub,$bodys);
		}
		/*************message sent**************************/
		$adminDetails = $this->common_model->getAllRowMultipleJoin('usr_users',array('email'=>'info@castleevents.com'),array(array('feu_userdetails','feu_userdetails.user_id = usr_users.id')));
		$eventDetails = $this->common_model->getAllRow('evt_events',array('id'=>$event_id));
		$newtitle = '';
		if(count($eventDetails)>0)
		{
			$newtitle = $eventDetails['title'];
		}
		$text='<p>'.getUserLang('Good_morning', $this->input->post('user_id')).' '.strtoupper($userData['username']).'</p><p></p>';
		$text.='<p>'.getUserLang('I_just_wanted_to_thank_you', $this->input->post('user_id')).' '.$newtitle.'. '.getUserLang('If_you_have_any_questions_or_requests', $this->input->post('user_id')).' </p>';
		$text.='<p>'.getUserLang('Best_regards', $this->input->post('user_id')).',</p>';
		$text.='<p>'.getUserLang('Your_Castleevents_Team', $this->input->post('user_id')).'</p>';

		$meg_conv_instId = $this->common_model->insertData('msg_conversations',array('created'=>time()));
		$meg_conv_user_instId = $this->common_model->insertData('msg_conversations_users',array('conversation_id'=>$meg_conv_instId,'user_id'=>$userData['user_id'],'latest_read'=>0));
		$meg_message_instId = $this->common_model->insertData('msg_messages',array('created'=>time(),'conversation_id'=>$meg_conv_instId,'from_user_id'=>$adminDetails['user_id'],'text'=>$text));
		/*************message sent**************************/
		//echo $body; die;
		$mask = 'CE-'.$orderId;
		echo $cartId.'|'.$mask;exit;
	}
	public function updatePaymentMethod()
	{
		$cart_id = $this->input->post('cart_id');
		$this->common_model->UpdateData('shop_orders',array('payment_method_id'=>12),array('cart_id'=>$cart_id));

		/********************New mail***************************/
		$orderDetails = $this->common_model->getAllMultipleJoin('shop_carts',array('shop_carts.id'=>$cart_id),array(array('shop_orders','shop_carts.id = shop_orders.cart_id'),array('usr_users','usr_users.id = shop_carts.user_id'),array('shop_booking_details','shop_booking_details.cart_id = shop_carts.id')));
		//echo $this->db->last_query();
		$userData = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$orderDetails[0]['user_id']));
		//$orderDetails = $this->common_model->getAllMultipleJoin('shop_booking_details',array('cart_id'=>$cart_id));
        $orderDetail = $this->common_model->getAllRowMultipleJoin('shop_orders',array('cart_id'=>$cart_id));
        $total = number_format($orderDetail['total_sum']/100,2,',','.');
        //pr($orderDetails);
        $to = $orderDetails[0]['email'];
		$sub = getUserLang('Thanks_For_your_booking', $orderDetails[0]['user_id']).': Order '.$orderDetail['order_id_masked'];
        $body='<p>'.getUserLang('please_transfer_the_following_amount', $orderDetails[0]['user_id']).'</p><br>';
        if(!empty($orderDetails))
		{
			$body.='<p>'.getUserLang('Please_transfer_the_full_amount_of', $orderDetails[0]['user_id']).' <span class="total">EUR '.$total.'</span> </p><br>
                         <p><strong>'.getUserLang('Invoice_Number', $orderDetails[0]['user_id']).':</strong> <span class="invoiceID">'.$orderDetail['order_id_masked'].'</span></p>
                         <p><strong>'.getUserLang('Generated_On', $orderDetails[0]['user_id']).':</strong> '.date('Y-m-d',$orderDetail['created']).'</p>
                         <p><strong>'.getUserLang('Due_to', $orderDetails[0]['user_id']).':</strong> '.date('Y-m-d',strtotime(date('Y-m-d',$orderDetail['created'])." + 10days")).'</p>
                         <p><strong>'.getUserLang('Outstanding_Amount', $orderDetails[0]['user_id']).': </strong><span class="total">'.$total.' EUR</span></p>
                         <br>
                         <strong>'.getUserLang('Details_of_your_Order', $orderDetails[0]['user_id']).':</strong>';
			foreach ($orderDetails as $value)
			{
				if($value['price'] > 0)
                {
					$name = getValue('event_features_lang_values',array('event_feature_id'=>$value['feature_id'],'lang_id'=>$langId));
					if(empty($name))
					{
						$name = getValue('event_features_lang_values',array('event_feature_id'=>$value['feature_id'],'lang_id'=>2));
					}
					
					$dates = explode(',', $value['feature_id']);
                    $date='';
                    if(!empty($dates))
                    {
                      foreach ($dates as $dateVal) {
                        $val = getValue('event_features',array('id'=>$dateVal));
                        $date .= date('d.m.Y',$val['date']).',';
                      }
                    }
					if(!empty($name))
					{
						$title = $name['title'];
					}
					else
					{
						$title = getUserLang('Extra_Nights', $orderDetails[0]['user_id']).' ('.rtrim($date,',').')';
					}
	        		$body.=' <p><span>-</span> <span class="entryDetails">'.$title.'</span></p>';
	        	}
            }
            $site_address_name = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_name'));
			$site_address_city = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_city'));
			$site_address_country_zip = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_country_zip'));
            $body.=' <br>
                         <strong>'.getUserLang('Bank_Details', $orderDetails[0]['user_id']).':</strong>
                         <br>
                         <p><strong>IBAN:</strong> CH810023123110716660E</p>
                         <p><strong>'.getUserLang('Clearing', $orderDetails[0]['user_id']).':</strong> 231</p>
                         <p><strong>Swift:</strong> UBSWCHZH80A</p>
                         <p><strong>'.getUserLang('Payment_Reason', $orderDetails[0]['user_id']).':</strong> '.$orderDetail['order_id_masked'].'</p>
                         <p><strong>'.getUserLang('Amount', $orderDetails[0]['user_id']).':</strong> <span class="total">'.$total.'</span></p>
                         <p><strong>'.getUserLang('Bank', $orderDetails[0]['user_id']).':</strong> UBS, Bahnhofstrasse 1, 5000 Aarau, Switzerland</p>
                         <p><strong>'.getUserLang('Recipient', $orderDetails[0]['user_id']).':</strong> '.$site_address_name['value'].', '.$site_address_city['value'].', '.$site_address_country_zip['value'].'</p>
                        </div> ';
        }
        $body.= '<p><a href="'.base_url().'invoice">'.getUserLang('Please_find_the_link_below_to_pay', $orderDetails[0]['user_id']).'</a></p>';
		$body.= '<p>'.getUserLang('We_appreciate_very_much', $orderDetails[0]['user_id']).'.</p><br/>';
		$body.= '<p>'.getUserLang('Please_do_not_hesitate_to_contact', $orderDetails[0]['user_id']).'.</p><br/><br/>';
		//$body.= '<p>Best regards,</p><p>Your Castleevents Team </p>';


		$bodys=' <table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
	                    <tr>
	                       <td>
	                          <table cellspacing="0" cellpadding="0" border="0" width="100%">
	                             <tr>
	                                <td align="center" style="padding: 40px; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #b3975b;">
	                                   <h2>'.getUserLang('Dear', $orderDetails[0]['user_id']).' <span style="text-transform:capitalize">'.$userData['username'].'</span> </h2>
	                                </td>
	                             </tr>
	                             <tr>
	                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
	                                   '.$body.'
	                                </td>
	                             </tr>
	                             <tr>
	                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">
	                             		'.getUserLang('Best_regards', $this->input->post('user_id')).' <br>
	                             		<p style="margin:5px 0 0">'.getUserLang('Your_Castleevents_Team', $orderDetails[0]['user_id']).'</p> 
	                             	</td>
	                             </tr>
	                          </table>
	                       </td>
	                    </tr>
	                </table>';


		$this->utility->sendOrderMail($to,$sub,$bodys);
		/********************New mail***************************/
	}
	public function pay()
	{
		$userData = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$this->session->userdata('user_id')));
		$oderDetails = $this->common_model->getAllRow('shop_orders',array('cart_id'=>$this->input->post('cart_id')));
		$eventDetails = $this->common_model->getAllRow('shop_booking_details',array('cart_id'=>$this->input->post('cart_id')));
		$stripeDetails = array();
		if(count($eventDetails)>0)
		{
			$stripeDetails = $this->common_model->getAllRow('evt_events',array('evt_events.id'=>$eventDetails['event_id']),array('stripe_credentials','stripe_credentials.id = evt_events.stripe_account_id'));
		}

		/*********TEST*************/
		/*$CustomerId = 246934;	
		$TerminalId = 17951970;	
		$username = 'API_246934_23183450';
		$password = 'JsonApiPwd1_a8EpfvCy';	*/
		/*********TEST*************/

		/*********LIVE*************/
		$CustomerId = 403547;
		$TerminalId = 17799239;	
		$username = 'API_403547_78643204';
		$password = 'JsonApiPwdAnexus1_a8EpfvCy';	
		/*********LIVE*************/
		
		$oderDetails = $this->common_model->getAllRow('shop_orders',array('cart_id'=>$this->input->post('cart_id')));
		$Price = 0;
		if(!empty($oderDetails))
		{
			$Price = $oderDetails['total_sum']/100;
		}
		//print_r($Price);die;
		if($this->input->post('price'))
		{
			$userDetail = $this->common_model->getAllRow('usr_users',array('id'=>$this->session->userdata('user_id')));
			$orderDetail = $this->common_model->getAllRow('shop_orders',array('cart_id'=>$this->input->post('cart_id')));

		/***********************Create Transaction Direct********************/
			$JSONObj  = '{
			  "RequestHeader": {
			    "SpecVersion": "1.10",
			    "CustomerId": "'.$CustomerId.'",
			    "RequestId": "aScdFewDSRFrfas2wsad3",
			    "RetryIndicator": 0
			  },
			  "TerminalId": "'.$TerminalId.'",
			  "Payment": {
			    "Amount": {
			      "Value": "'.$orderDetail['total_sum'].'",
			      "CurrencyCode": "EUR"
			    },
			    "Description": "Event Service",
			    "PayerNote": "Event Service"
			  },
			  "PaymentMeans": {
			    "Card": {
			      "Number": "'.$this->input->post('card_number').'",
			      "ExpYear": '.$this->input->post('exp_year').',
			      "ExpMonth": '.$this->input->post('exp_month').',
			      "HolderName": "'.$this->input->post('card_holder').'",
			      "VerificationCode": "'.$this->input->post('card_cvc').'"
			    }
			  }
			}';

			//$url = 'https://test.saferpay.com/api/Payment/v1/Transaction/AuthorizeDirect';
			$url = 'https://www.saferpay.com/api/Payment/v1/Transaction/AuthorizeDirect';
		    
		    $JSONObj = json_decode($JSONObj);
		    $curl = curl_init($url);
		    curl_setopt($curl, CURLOPT_HEADER, false);
		    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		    curl_setopt($curl, CURLOPT_HTTPHEADER,array("Content-type: application/json"));
		    curl_setopt($curl, CURLOPT_POST, true);
		    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($JSONObj));
		    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
		    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
		    curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
		    $jsonResponse = curl_exec($curl);
		    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
		    if ( $status != 200 ) {
		        if($status == 400) {
		    		$fail_reason = 'Validation error';
		    	} elseif($status == 401) {
		    		$fail_reason = 'Authentication of the request failed';
		    	} elseif($status == 402) {
		    		$fail_reason = 'Requested action failed';
		    	} elseif($status == 403) {
		    		$fail_reason = 'Access denied';
		    	} elseif($status == 406) {
		    		$fail_reason = 'Not acceptable (wrong accept header)';
		    	} elseif($status == 415) {
		    		$fail_reason = 'Unsupported media type (wrong content-type header)';
		    	} elseif($status == 500) {
		    		$fail_reason = 'Internal error';
		    	}
		    	$errorresponse = json_decode($jsonResponse, true);
		    	if($errorresponse)
		    	{
		    		if($errorresponse['ProcessorMessage'])
		    		{
		    			$fail_reason = $errorresponse['ProcessorMessage'];
		    		}
		    	}
		        $this->common_model->UpdateData('shop_orders',array('fail_reason'=>$fail_reason),array('cart_id'=>$this->input->post('cart_id')));
		        die("Error: ".$fail_reason);
		    }
		    curl_close($curl);
		    $transactionresponse = json_decode($jsonResponse, true);
		    $this->common_model->UpdateData('shop_orders',array('real_name'=>$transactionresponse['PaymentMeans']['Card']['HolderName'], 'card_origin'=>$transactionresponse['PaymentMeans']['Card']['CountryCode']),array('cart_id'=>$this->input->post('cart_id')));
		  	//echo "<pre>";
			//print_r($transactionresponse);die;
		/***********************Create Transaction Direct********************/


		/***********************Create Capture Direct********************/
			$JSONObj  = '{
			  "RequestHeader": {
			    "SpecVersion": "1.10",
			    "CustomerId": "'.$CustomerId.'",
			    "RequestId": "aScdFewDSRFrfas2wsad3",
			    "RetryIndicator": 0
			  },
			  "TransactionReference": {
			    "TransactionId": "'.$transactionresponse['Transaction']['Id'].'"
			  }
			}';
			//echo $JSONObj;die;
			//$url = 'https://test.saferpay.com/api/Payment/v1/Transaction/Capture';
			$url = 'https://www.saferpay.com/api/Payment/v1/Transaction/Capture';
		    
		    $JSONObj = json_decode($JSONObj);
		    $curl = curl_init($url);
		    curl_setopt($curl, CURLOPT_HEADER, false);
		    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		    curl_setopt($curl, CURLOPT_HTTPHEADER,array("Content-type: application/json"));
		    curl_setopt($curl, CURLOPT_POST, true);
		    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($JSONObj));
		    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
		    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
		    curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
		    $jsonResponse = curl_exec($curl);
		    $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
		    if ( $status != 200 ) {
		        if($status == 400) {
		    		$fail_reason = 'Validation error';
		    	} elseif($status == 401) {
		    		$fail_reason = 'Authentication of the request failed';
		    	} elseif($status == 402) {
		    		$fail_reason = 'Requested action failed';
		    	} elseif($status == 403) {
		    		$fail_reason = 'Access denied';
		    	} elseif($status == 406) {
		    		$fail_reason = 'Not acceptable (wrong accept header)';
		    	} elseif($status == 415) {
		    		$fail_reason = 'Unsupported media type (wrong content-type header)';
		    	} elseif($status == 500) {
		    		$fail_reason = 'Internal error';
		    	}
		    	$errorresponse = json_decode($jsonResponse, true);
		    	if($errorresponse)
		    	{
		    		if($errorresponse['ProcessorMessage'])
		    		{
		    			$fail_reason = $errorresponse['ProcessorMessage'];
		    		}
		    	}
		        $this->common_model->UpdateData('shop_orders',array('fail_reason'=>$fail_reason),array('cart_id'=>$this->input->post('cart_id')));
		        die("Error: ".$fail_reason);
		    }
		    curl_close($curl);
		    $response = json_decode($jsonResponse, true);
		    
		  	//echo "<pre>";
			//print_r($response);die;
		/***********************Create Capture Direct********************/
			if($response)
			{
				$this->common_model->UpdateData('shop_orders',array('payed'=>1,'trn_id'=>$transactionresponse['Transaction']['Id'],'payment_method_id'=>13,'fail_reason'=>'','payment_date'=>date('Y-m-d')),array('cart_id'=>$this->input->post('cart_id')));

				$this->common_model->UpdateData('feu_userdetails',array('reality_authenticated'=>1),array('user_id'=>$this->session->userdata('user_id')));
						
				$to = $userDetail['email'];
				$sub = getLang('Confirmation').': '.getLang('Successful_payment');
				//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];
				//$body= '<p>Dear '.$userData['username'].',</p>';
				$bookingDetails = $this->common_model->getAllRow('shop_booking_details',array('cart_id'=>$this->input->post('cart_id')),array('evt_events','evt_events.id = shop_booking_details.event_id'));
				
				$body= '<p>'.getLang('We_have_received_your_payment').'!</p>';
				if(count($bookingDetails)>0)
				{
					$body.= '<p>Event Date and Place: '.date('d M Y',$bookingDetails['time_from']).' - '.eventDetails($bookingDetails['event_id']).'</p>';
				}
				$body.= '<p>'.getLang('Invoice_Number').': CE-'.$orderDetail['order_id'].'</p><p>'.getLang('Generated_On').': '.date('Y-m-d',time()).'</p><p>'.getLang('Paid_Amount').': '.$this->input->post('price').' EUR</p>';
				$body.= '<p>'.getLang('Invoice_will_be_located').' www.castleevents.com.</p>';
				$body.= '<p>'.getLang('We_appreciate_very_much').'.</p>';
				$body.= '<p>'.getLang('Please_do_not_hesitate_to_contact').'.</p>';

				$body.= '<p></p>';
				$body.= '<p>This payment is related our <a href="'.base_url('terms').'">terms and conditions</a> confirmed from you on '.date('d-m-Y H:i:s').' </p>';
				//$body.= '<p>Best regards,</p><p>Your Castleevents Team </p>';


				$bodys=' <table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
                <tr>
                   <td>
                      <table cellspacing="0" cellpadding="0" border="0" width="100%">
                         <tr>
                            <td align="center" style="padding: 40px; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #b3975b;">
                               <h2>'.getLang('Dear').' <span style="text-transform:capitalize">'.$userData['username'].'</span> </h2>
                            </td>
                         </tr>
                         <tr>
                            <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
                               '.$body.'
                            </td>
                         </tr>
                         <tr>
                         	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">
                         		'.getLang('Best_regards').' <br>
                         		<p style="margin:5px 0 0">'.getLang('Your_Castleevents_Team').'</p> 
                         	</td>
                         </tr>
                      </table>
                   </td>
                </tr>
	            </table>';


				$this->utility->sendOrderMail($to,$sub,$bodys);

			
				$subRe = getLang('VALIDATE_YOUR_MOBILE_NUMBER');
				$bodyRe=' <table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
		                    <tr>
		                       <td>
		                          <table cellspacing="0" cellpadding="0" border="0" width="100%">
		                             <tr>
		                                <td align="center" style="padding: 40px; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #b3975b;">
		                                   <h2>'.getLang('Hello').' <span style="text-transform:capitalize">'.$userData['username'].'</span> </h2>
		                                </td>
		                             </tr>
		                             <tr>
		                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
		                                   <p>
		                                      '.getLang('Before_attending_the_party').'
		                                      <br/><br/>
		                                      '.getLang('On_that_number_we_will_send_you_36_hours').'
		                                      <br/><br/>
		                                      '.getLang('After_full_filled_validation_you').'
		                                      
		                                   </p>
		                                   <br>
		                                </td>
		                             </tr>
		                             <tr>
		                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">
		                             		'.getLang('Best_regards').' <br>
		                             		<p style="margin:5px 0 0">'.getLang('Your_Castleevents_Team').'</p> 
		                             	</td>
		                             </tr>
		                          </table>
		                       </td>
		                    </tr>
		                </table>';//echo $body; die;
				$this->utility->sendOrderMail($to,$subRe,$bodyRe);
			
				/****extra mail****/
					$to = 'alorenc@me.com';
					$sub = 'Payment recieved';
					$body= 'CE-'.$orderDetail['order_id'].', EUR '.number_format(($orderDetail['total_sum']/100), 2,',', '.');
					$body.= '<p>Paid Party Booking Fees</p>';
					$body.= '<p>'.$userData['username'].'</p>';
					$body.= '<p>Event Name: '.$bookingDetails['title'].'</p>';
					$bodys=' <table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
					            <tr>
					               <td>
					                  <table cellspacing="0" cellpadding="0" border="0" width="100%">
					                     <tr>
					                        <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
					                           '.$body.'
					                        </td>
					                     </tr>
					                  </table>
					               </td>
					            </tr>
					        </table>';
					$this->utility->sendOrderMail($to,$sub,$bodys);
				/****extra mail****/

				echo 2;
			}
			else
			{
				$this->common_model->UpdateData('shop_orders',array('fail_reason'=>'Card authorization denied','payment_method_id'=>13),array('cart_id'=>$this->input->post('cart_id')));
				echo 'Card authorization denied';
			}
		}
		exit;
	}
	public function reviews($slug='')
	{ 
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$this->session->userdata('user_id'))) ;
		$content_data['userDiscounts'] = $this->common_model->getAllRow('feu_user_discounts',array('user_id'=>$this->session->userdata('user_id')));
		$content_data['steps'] = $this->common_model->getAllRow('feu_user_steps',array('user_id'=>$this->session->userdata('user_id'))) ;
		$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) ;
		}
		$content_data['partyDetails'] = $this->common_model->getAllRowMultipleJoin('evt_events',array('evt_event_files.is_banner'=>1,'evt_events.alias'=>$slug,'evt_language_values.lang_id'=>$langId),array(array('evt_language_values','evt_language_values.event_id = evt_events.id'),array('loc_events_locations','evt_events.id = loc_events_locations.event_id'),array('loc_locations','loc_events_locations.location_id = loc_locations.id'),array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('sys_files','sys_files.id = evt_event_files.file_id')),'evt_events.created DESC','evt_events.id as id, evt_events.*,sys_files.path,sys_files.filename,sys_files.extension,loc_locations.name,loc_locations.country,loc_locations.city,loc_locations.zipcode,evt_event_files.is_banner,evt_language_values.title,evt_language_values.sub_title,evt_language_values.description,evt_language_values.teasertext','loc_events_locations.event_id,evt_language_values.title,evt_language_values.description');
		$content_data['partyImages'] = $this->common_model->getAllMultipleJoin('evt_events',array('evt_event_files.is_banner'=>0,'evt_events.alias'=>$slug),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('sys_files','sys_files.id = evt_event_files.file_id')),'RAND()','evt_events.id as id, evt_events.*,sys_files.path,sys_files.filename,sys_files.extension,evt_event_files.is_banner');
		//print_r($content_data['partyImages']); die;
		if(empty($content_data['partyDetails']))
		{
			redirect(base_url());
		}
		$data['checkinEvents'] = array();
		$content_data['userParticipation'] = array();
		$content_data['userParticipation_old'] = array();
		if($this->session->userdata('user_id'))
		{
			$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') ;
			$content_data['userDetials'] = $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'))) ;
			$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');
		


			$content_data['userParticipation'] = $this->common_model->getAllMultipleJoin('shop_orders',array('shop_carts.user_id'=>$this->session->userdata('user_id'),'payed'=>1,'shop_orders.is_booking'=>1,'shop_booking_details.event_id'=>$content_data['partyDetails']['id'],'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_events','evt_events.id = shop_booking_details.event_id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'shop_carts.created DESC','*,evt_language_values.title,evt_events.alias','evt_events.id,shop_booking_details.cart_id');
		
			$ids = '';
			if(!empty($content_data['userParticipation']))
			{
				foreach ($content_data['userParticipation'] as $key => $value) {
					if($value['event_id']>0)
					{
						$ids = $ids.$value['event_id'].',';
					}
				}
				//echo $ids;die;
			}
			$where="";
			if($ids != '')
			{
				$where = " `shop_carts`.`user_id` = ".$this->session->userdata('user_id')." AND `payed` = 1 AND `shop_articles_carts`.`event_id` = ".$content_data['partyDetails']['id']." AND `shop_orders`.`is_booking` =0 and evt_events.id not in (".trim($ids,',').") AND evt_language_values.lang_id = ".$langId;
			}
			else
			{
				$where = " `shop_carts`.`user_id` = ".$this->session->userdata('user_id')." AND `payed` = 1 AND `shop_articles_carts`.`event_id` = ".$content_data['partyDetails']['id']." AND `shop_orders`.`is_booking` =0 AND evt_language_values.lang_id = ".$langId;
			}
			//echo $where;die;
			//$content_data['userParticipation_old'] = array();
			$content_data['userParticipation_old'] = $this->common_model->getAllMultipleJoin('shop_orders',$where,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('evt_events','evt_events.id = shop_articles_carts.event_id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'shop_carts.created DESC','*,evt_events.title,evt_events.alias','evt_events.id,shop_articles_carts.event_id');
		}
		$comments = $this->common_model->getAllMultipleJoin('review_comments',array('event_id'=>$content_data['partyDetails']['id'],'parent_id'=>0,'approved'=>1),array(array('feu_userdetails','feu_userdetails.user_id = review_comments.user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'review_comments.created DESC','*, review_comments.id','',0,2);
		$allcomments = $this->common_model->getAllMultipleJoin('review_comments',array('event_id'=>$content_data['partyDetails']['id'],'parent_id'=>0,'approved'=>1),array(array('feu_userdetails','feu_userdetails.user_id = review_comments.user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'review_comments.created DESC','*, review_comments.id');
		//echo '<pre>';print_r($comments);die;
		if($comments){
			foreach ($comments as $key => $value) {
				$replies = $this->common_model->getAllMultipleJoin('review_comments',array('event_id'=>$content_data['partyDetails']['id'],'parent_id'=>$value['id'],'approved'=>1),array(array('feu_userdetails','feu_userdetails.user_id = review_comments.user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'review_comments.created DESC');
					
				$comments[$key]['replies'] = $replies;
			}
		}
		$content_data['comments'] = $comments;
		$content_data['allcomments'] = $allcomments;

		$content_data['partyPrice'] = $this->common_model->getAllRowMultipleJoin('evt_events',array('evt_events.alias'=>$slug,'event_features.type'=>1),array(array('event_features','event_features.event_id = evt_events.id')),'event_features.base_price ASC');
		$content_data['entries'] = $this->common_model->getAllMultipleJoin('evt_events',array('evt_events.alias'=>$slug,'event_features.type'=>1,'event_features_lang_values.lang_id'=>$langId),array(array('event_features','event_features.event_id = evt_events.id'),array('event_features_lang_values','event_features_lang_values.event_feature_id = event_features.id'),array('sys_files','sys_files.id = event_features.image_id')),'event_features.base_price ASC','event_features_lang_values.*,sys_files.*,event_features.*');
		$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
		$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['device'] = ($this->mobile_detect->isMobile() ? ($this->mobile_detect->isTablet() ? 'tablet' : 'phone') : 'computer');
		$data['title'] = "Castleevents | ".getLang('Party_Reviews');
		if(!empty($content_data['partyDetails']))
		{
			$data['title'] = "Castleevents | ".$content_data['partyDetails']['title'];
			$data['meta_title'] = $content_data['partyDetails']['title'];
			$data['meta_description'] = strip_tags(html_entity_decode($content_data['partyDetails']['description']));
			$data['meta_keywords'] = $content_data['partyDetails']['title'];
			$data['meta_genre'] = 'Party Reviews';
		}
		$data['content'] = $this->load->view('reviews', $content_data, TRUE);
		$this->load->view('template', $data);
	}
	public function allparties()
	{ 
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$this->session->userdata('user_id'))) ;
		$content_data['userDiscounts'] = $this->common_model->getAllRow('feu_user_discounts',array('user_id'=>$this->session->userdata('user_id')));
		$content_data['steps'] = $this->common_model->getAllRow('feu_user_steps',array('user_id'=>$this->session->userdata('user_id'))) ;
		$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) ;
		}
		if($this->session->userdata('user_id'))
		{
			$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['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'))) ;
			$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');
		}
		$content_data['allParties'] = $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'),array('sys_files','sys_files.id = evt_event_files.file_id')),'time_from ASC','sys_files.*,evt_events.*,evt_event_files.*,evt_language_values.title,evt_language_values.description,evt_language_values.teasertext','evt_event_files.event_id') ;
		$content_data['allPastParties'] = $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'),array('sys_files','sys_files.id = evt_event_files.file_id')),'time_from DESC','sys_files.*,evt_events.*,evt_event_files.*,evt_language_values.title,evt_language_values.description,evt_language_values.teasertext','evt_event_files.event_id',0,6) ;
		//echo $this->db->last_query(); die;
		$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
		$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['device'] = ($this->mobile_detect->isMobile() ? ($this->mobile_detect->isTablet() ? 'tablet' : 'phone') : 'computer');
		$data['title'] = "Castleevents | ".getLang('All_Parties');
		$page_meta = $this->common_model->getAllRow('page_meta',array('id'=>4));
		if(!empty($page_meta))
		{
			//$data['title'] = $page_meta['page_title'];
			$data['meta_title'] = $page_meta['meta_title'];
			$data['meta_description'] = strip_tags(html_entity_decode($page_meta['meta_desc']));
			$data['meta_keywords'] = $page_meta['meta_keywords'];
			$data['meta_genre'] = 'All parties';
		}
		$data['content'] = $this->load->view('allparties', $content_data, TRUE);
		$this->load->view('template', $data);
	}
	public function getUserList()
	{
		$seacrh = $this->utility->info_cleanQuery($this->input->post('search')); 
		$members = $this->common_model->getAllMultipleJoin('feu_userdetails','','','username ASC','','','','',array('username'=>$seacrh));
		//$members = $this->common_model->getAllMultipleJoin('usr_users','','','email ASC','','','','',array('email'=>$seacrh));
		$html = '';
		if(!empty($members))
		{
			$html .='<ul class="userLists">';
			foreach ($members as $value) {
				$userDiscounts = $this->common_model->getAllRow('feu_user_discounts',array('user_id'=>$value['user_id'],'discount >'=>0));
				$discount = 0;
				if(!empty($userDiscounts))
				{
					$discount = $userDiscounts['discount'];
				}
				$html .='<li class="userListLi" data-id="'.$value['user_id'].'" data-discount="'.$discount.'">'.$value['username'].'</li>';
			}
			$html .='</ul>';
		}
		echo $html;exit;
	}
	public function side_events($slug='')
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$this->session->userdata('user_id'))) ;
		$content_data['userDiscounts'] = $this->common_model->getAllRow('feu_user_discounts',array('user_id'=>$this->session->userdata('user_id')));
		$content_data['steps'] = $this->common_model->getAllRow('feu_user_steps',array('user_id'=>$this->session->userdata('user_id'))) ;
		$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) ;
		}
		$content_data['partyDetails'] = $this->common_model->getAllRowMultipleJoin('evt_events',array('evt_event_files.is_banner'=>1,'evt_language_values.lang_id'=>$langId,'evt_events.alias'=>$slug),array(array('evt_language_values','evt_language_values.event_id = evt_events.id'),array('loc_events_locations','evt_events.id = loc_events_locations.event_id'),array('loc_locations','loc_events_locations.location_id = loc_locations.id'),array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('sys_files','sys_files.id = evt_event_files.file_id')),'evt_events.created DESC','evt_events.id as id, evt_events.*,sys_files.path,sys_files.filename,sys_files.extension,loc_locations.name,loc_locations.country,loc_locations.city,loc_locations.zipcode,evt_event_files.is_banner,evt_language_values.title,evt_language_values.sub_title,evt_language_values.description,evt_language_values.teasertext','loc_events_locations.event_id,evt_language_values.title,evt_language_values.description');
		if(empty($content_data['partyDetails']))
		{
			redirect(base_url());
		}
		$content_data['pastParties'] = $this->common_model->getAllMultipleJoin('evt_events',array('evt_event_files.is_banner'=>1,'evt_language_values.lang_id'=>$langId,'evt_events.visible'=>1,'time_from <'=>time()),array(array('evt_language_values','evt_language_values.event_id = evt_events.id'),array('loc_events_locations','evt_events.id = loc_events_locations.event_id'),array('loc_locations','loc_events_locations.location_id = loc_locations.id'),array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('sys_files','sys_files.id = evt_event_files.file_id')),'RAND()','evt_events.id as id, evt_events.*,sys_files.path,sys_files.filename,sys_files.extension,loc_locations.name,loc_locations.country,loc_locations.city,loc_locations.zipcode,evt_event_files.is_banner,evt_language_values.title,evt_language_values.description,evt_language_values.teasertext','loc_events_locations.event_id,evt_language_values.title,evt_language_values.description',0,3);
		if($content_data['partyDetails']['past_parties']!='')
		{
			$where = "evt_event_files.is_banner =1 and evt_language_values.lang_id =".$langId." and evt_events.id in(".$content_data['partyDetails']['past_parties'].") and evt_events.visible=1 and time_from <".time();	
			$content_data['pastParties'] = $this->common_model->getAllMultipleJoin('evt_events',$where,array(array('evt_language_values','evt_language_values.event_id = evt_events.id'),array('loc_events_locations','evt_events.id = loc_events_locations.event_id'),array('loc_locations','loc_events_locations.location_id = loc_locations.id'),array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('sys_files','sys_files.id = evt_event_files.file_id')),'RAND()','evt_events.id as id, evt_events.*,sys_files.path,sys_files.filename,sys_files.extension,loc_locations.name,loc_locations.country,loc_locations.city,loc_locations.zipcode,evt_event_files.is_banner,evt_language_values.title,evt_language_values.description,evt_language_values.teasertext','loc_events_locations.event_id,evt_language_values.title,evt_language_values.description');
			//echo $this->db->last_query(); die;
		}
		if($content_data['partyDetails']['stripe_account_id']>0)
		{
			$content_data['stripe_credentials'] = $this->common_model->getAllRow('stripe_credentials',array('id'=>$content_data['partyDetails']['stripe_account_id']));
			//echo $this->db->last_query(); die;
		}  
		//print_r($content_data['pastParties']); die;
		$data['checkinEvents'] = array();
		if($this->session->userdata('user_id'))
		{
			$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['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'))) ;
			$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');
		}
		$content_data['partyPrice'] = $this->common_model->getAllRowMultipleJoin('evt_events',array('event_features.event_id'=>$content_data['partyDetails']['id'],'event_features.type'=>1),array(array('event_features','event_features.event_id = evt_events.id')),'event_features.base_price ASC');
		$content_data['entries'] = $this->common_model->getAllMultipleJoin('evt_events',array('event_features.event_id'=>$content_data['partyDetails']['id'],'event_features.type'=>1,'event_features_lang_values.lang_id'=>$langId),array(array('event_features','event_features.event_id = evt_events.id'),array('event_features_lang_values','event_features_lang_values.event_feature_id = event_features.id'),array('sys_files','sys_files.id = event_features.image_id')),'event_features.base_price ASC','event_features_lang_values.*,sys_files.*,event_features.*');
		$content_data['booked_users'] = $booked_users = $this->common_model->getAllMultipleJoin('shop_booking_details',array('shop_booking_details.event_id'=>$content_data['partyDetails']['id']),array(array('shop_carts','shop_carts.id = shop_booking_details.cart_id'),array('feu_userdetails','feu_userdetails.user_id = shop_carts.user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'RAND()','','shop_booking_details.cart_id');
		if(count($booked_users)>5)
		{
			$content_data['booked_users'] = $this->common_model->getAllMultipleJoin('shop_booking_details',array('shop_booking_details.event_id'=>$content_data['partyDetails']['id']),array(array('shop_carts','shop_carts.id = shop_booking_details.cart_id'),array('feu_userdetails','feu_userdetails.user_id = shop_carts.user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'RAND()','','shop_carts.user_id',0,5);
		}
		$content_data['userDetail']='';
		$content_data['userMembershipDetails']='';
		if($this->session->userdata('user_id'))
		{
			$content_data['userDetail'] = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$this->session->userdata('user_id'))) ;
			$content_data['userMembershipDetails'] = $this->users_model->getMembershipDetails($this->session->userdata('user_id'));
		}
		$content_data['logged_in_gentleman'] = $this->common_model->getAllMultipleJoin('usr_users',array('filename!='=>'','accounttype'=>'gentleman','shop_articles.id'=>4,'about !='=>''),array(array('feu_userdetails','feu_userdetails.user_id = usr_users.id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id'),array('shop_carts','shop_carts.user_id = usr_users.id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id'),array('feu_countries','feu_countries.country_code = feu_userdetails.country')),'RAND()','*,feu_userdetails.alias','feu_userdetails.user_id');
		$content_data['logged_in_lady'] = $this->common_model->getAllMultipleJoin('usr_users',array('filename!='=>'','accounttype'=>'lady','escort_interest'=>1,'usr_users.id !='=>11330,'about !='=>''),array(array('feu_userdetails','feu_userdetails.user_id = usr_users.id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id'),array('feu_countries','feu_countries.country_code = feu_userdetails.country')),'RAND()','*,feu_userdetails.alias','feu_userdetails.user_id');
		
		$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
		$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['device'] = ($this->mobile_detect->isMobile() ? ($this->mobile_detect->isTablet() ? 'tablet' : 'phone') : 'computer');
		$data['title'] = "Castleevents | ".getLang('Party_Details');
		$data['meta_title'] = "Castleevents | ".getLang('Party_Details');
		$data['meta_description'] = "Castleevents | ".getLang('Party_Details');
		$data['meta_keywords'] = "Castleevents, ".getLang('Party_Details');
		$data['meta_genre'] = 'partyDetails';
		if(!empty($content_data['partyDetails']))
		{
			$data['title'] = "Castleevents | ".$content_data['partyDetails']['title'];
			$data['meta_title'] = $content_data['partyDetails']['title'];
			$data['meta_description'] = strip_tags(html_entity_decode($content_data['partyDetails']['description']));
			$data['meta_keywords'] = $content_data['partyDetails']['title'];
		}
		/*if(!$this->session->userdata('user_id'))
		{
			redirect(base_url('parties/'.$slug));
		}*/
		$content_data['is_booked'] = 0;
		if($this->session->userdata('user_id'))
		{
			$where = 'shop_booking_details.event_id = '.$content_data['partyDetails']['id'].' and user_id='.$this->session->userdata('user_id').' and payed = 1 and refund_trn_id="" and event_guest.event_id > 0 ';
			$is_booked = $this->common_model->getAllMultipleJoin('shop_orders',$where,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_booking_details','shop_booking_details.cart_id = shop_orders.cart_id'),array('event_guest','event_guest.order_id = shop_orders.order_id')),'','','shop_booking_details.cart_id');
			
			if(count($is_booked)==0)
			{
				$this->session->set_userdata('error_book_first',1);
				redirect(base_url('parties/'.$slug));
			}
			else
			{
				$content_data['is_booked'] = 1;
			}
		}
		$content_data['side_events'] = $this->common_model->getAllMultipleJoin('side_events',array('side_events_to_event.event_id'=>$content_data['partyDetails']['id'],'lang_id'=>$langId,'is_visible'=>1),array(array('side_events_lang_values','side_events.id = side_events_lang_values.side_event_id'),array('side_events_to_event','side_events.id = side_events_to_event.side_event_id')),'side_events.created DESC');
		$data['content'] = $this->load->view('side_events', $content_data, TRUE);
		$this->load->view('template', $data);
	}
	public function side_event_choose()
	{
		$side_events_ids = explode(',',trim($this->input->post('ids'),',')); 
		$event_id = $this->input->post('event_id'); 
		$side_events = '';
		if(!empty($side_events_ids))
		{
			foreach ($side_events_ids as $value) {
				$where = 'shop_booking_details.event_id = '.$event_id.' and user_id='.$this->session->userdata('user_id').' and payed = 1 and refund_trn_id=""';
				$orderDetails = $this->common_model->getAllRowMultipleJoin('shop_orders',$where,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_booking_details','shop_booking_details.cart_id = shop_orders.cart_id')),'','','shop_booking_details.cart_id');
				$check = $this->common_model->getAllRow('shop_side_events',array('user_id'=>$this->session->userdata('user_id'),'side_event_id'=>$value));
				if(!$check)
				{
					$arr = array(
									'user_id'=>$this->session->userdata('user_id'),
									'side_event_id'=>$value,
									'order_id'=>$orderDetails['order_id'],
									'created'=>time()
								);
					$this->common_model->insertData('shop_side_events',$arr);
				}
				$sideevent_details = $this->common_model->getAllRow('side_events',array('id'=>$value));
				if($sideevent_details)
				{
					$side_events .= $sideevent_details['title'].',';
				}
			}
			
			if($side_events!='')
			{
				
				//echo $this->db->last_query();
				if($orderDetails)
				{
					$this->common_model->UpdateData('event_guest',array('side_events'=>trim($side_events,',')),array('order_id'=>$orderDetails['order_id']));
					$userdatails = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$this->session->userdata('user_id')));
				}
				$eventDetails = $this->common_model->getAllRow('evt_events',array('id'=>$event_id));
				$title = '';
				if($eventDetails)
				{
					$title = $eventDetails['title'];
				}
				//$to = 'sayan@digitalaptech.com';
				$to = 'info@castleevents.com';
				$sub = 'Successful side event booking for '.$title;
				
				$body= '<p>'.$userdatails['username'].' has booked Side Events.</p>';
				$body.= '<p style="text-decoration:underline;">Event names are below:</p>';
				$names = explode(',', trim($side_events,','));
				if($names)
				{
					foreach ($names as $key => $value) {
						$body.= '<p>'.($key+1).'. '.$value.'</p>';
					}
				}


				$bodys=' <table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
                <tr>
                   <td>
                      <table cellspacing="0" cellpadding="0" border="0" width="100%">
                         <tr>
                            <td align="center" style="padding: 40px; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #b3975b;">
                               <h2>'.getLang('Dear').' <span style="text-transform:capitalize">Admin</span> </h2>
                            </td>
                         </tr>
                         <tr>
                            <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
                               '.$body.'
                            </td>
                         </tr>
                         <tr>
                         	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">
                         		'.getLang('Best_regards').' <br>
                         		<p style="margin:5px 0 0">'.getLang('Your_Castleevents_Team').'</p> 
                         	</td>
                         </tr>
                      	</table>
                       </td>
                    </tr>
                </table>';


				$this->utility->sendCIMail($to,$sub,$bodys);
				echo 1;
			}
		}
		exit;
	}

	public function reviewcomment()
	{
		$parent_id = $this->input->post('parent_id') ? $this->input->post('parent_id') : 0; 
		$party_id = $this->input->post('party_id'); 
		$user_id = $this->session->userdata('user_id'); 
		$reviewcomment = $this->input->post('reviewcomment'); 
		
		$inserted = $this->common_model->insertData('review_comments',array('created'=>time(),'user_id'=>$user_id,'event_id'=>$party_id,'comment'=>$reviewcomment,'parent_id'=>$parent_id,'approved'=>0));

		/********mail to admin****************/
		$userdatailsData = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$user_id));
		$eventdatailsData = $this->common_model->getAllRow('evt_events',array('id'=>$party_id));
		
		//$to = 'sayan@digitalaptech.com';
		$to = 'info@castleevents.com';
		$sub = $userdatailsData['username'].' post a feedback for '.$eventdatailsData['title'];
		
		$body= '<p>'.$userdatailsData['username'].' post a feedback for '.$eventdatailsData['title'].'</p>';
		$body.= '<p>Feedback is below:</p>';
		$body.= '<p>'.$reviewcomment.'</p>';


		$bodys=' <table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
        <tr>
           <td>
              <table cellspacing="0" cellpadding="0" border="0" width="100%">
                 <tr>
                    <td align="center" style="padding: 40px; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #b3975b;">
                       <h2>'.getLang('Dear').' <span style="text-transform:capitalize">Admin</span> </h2>
                    </td>
                 </tr>
                 <tr>
                    <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
                       '.$body.'
                    </td>
                 </tr>
                 <tr>
                 	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">
                 		'.getLang('Best_regards').' <br>
                 		<p style="margin:5px 0 0">'.getLang('Your_Castleevents_Team').'</p> 
                 	</td>
                 </tr>
              	</table>
               </td>
            </tr>
        </table>';


		$this->utility->sendCIMail($to,$sub,$bodys);
		/********mail to admin****************/

		$comments = $this->common_model->getAllMultipleJoin('review_comments',array('event_id'=>$party_id,'parent_id'=>0,'approved'=>1),array(array('feu_userdetails','feu_userdetails.user_id = review_comments.user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'review_comments.created DESC','*, review_comments.id','',0,2);
		$html = '';
		if($parent_id == 0) {
				if($comments){
						foreach ($comments as $key => $value) {
							$replies = $this->common_model->getAllMultipleJoin('review_comments',array('event_id'=>$party_id,'parent_id'=>$value['id'],'approved'=>1),array(array('feu_userdetails','feu_userdetails.user_id = review_comments.user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'review_comments.created DESC');

			$html .= '	<li>
							<div class="comment-main-level">
							<div class="comment-avatar"><img src="';
								if(!empty($value) && $value['filename']!='' && file_exists(FCPATH.'assets/userfiles/'.$value['path'].'/160/'.$value['filename'].'.'.$value['extension'])){ 
			$html .= 				base_url().'assets/userfiles/'.$value['path'].'/160/'.$value['filename'].'.'.$value['extension']; 
								} else { 						
			$html .=				base_url().'assets/images/default-avatar.jpg'; 
								}
			$html .=			'" alt=""></div>
								
								<div class="comment-box">
									<div class="comment-head">
										<h6 class="comment-name by-author"><a href="javascript:void(0)">'.$value['username'].'</a></h6>
										<span>'.$value['accounttype'].'</span>
								
									</div>
									<div class="comment-content">
										<p>'.$value['comment'].'</p>
										<a href="javascript:void(0)" class="comment-reply" data-id="'.$value['id'].'">Reply</a>
										<span></span>
										</div>
										</div>
	                              </div>';
								if($replies){
			$html .= '			<ul class="comments-list reply-list">';
									foreach ($replies as $k => $val) {
			$html .= '					<li>	
											<div class="comment-avatar"><img src="';
											if(!empty($val) && $val['filename']!='' && file_exists(FCPATH.'assets/userfiles/'.$val['path'].'/160/'.$val['filename'].'.'.$val['extension'])){ 
			$html .= 							base_url().'assets/userfiles/'.$val['path'].'/160/'.$val['filename'].'.'.$val['extension']; 
											} else { 						
			$html .=							base_url().'assets/images/default-avatar.jpg'; 
											}
			$html .=						'" alt=""></div>
											
											<div class="comment-box">
												<div class="comment-head">
													<h6 class="comment-name"><a href="javascript:void(0)">'.$val['username'].'</a></h6>
													<span>'.$val['accounttype'].'</span>
											
												</div>
												<div class="comment-content">
													<p>'.$val['comment'].'</p>
												</div>
											</div>
										</li>';
									}
			$html .= '			</ul>';
								}
			$html .= '		</li>';			
						}
					}
		} else {
			$reply = $this->common_model->getAllMultipleJoin('review_comments',array('review_comments.parent_id'=>$parent_id,'approved'=>1),array(array('feu_userdetails','feu_userdetails.user_id = review_comments.user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'review_comments.created DESC');
			//echo '<pre>';print_r($replies);die;
			if($reply) {
				$html .= '<ul class="comments-list reply-list">';
						foreach ($reply as $k => $replies) {
				$html .= '	<li>	
								<div class="comment-avatar"><img src="';
									if(!empty($replies) && $replies['filename']!='' && file_exists(FCPATH.'assets/userfiles/'.$replies['path'].'/160/'.$replies['filename'].'.'.$replies['extension'])){ 
				$html .= 				base_url().'assets/userfiles/'.$replies['path'].'/160/'.$replies['filename'].'.'.$replies['extension']; 
									} else { 						
				$html .=				base_url().'assets/images/default-avatar.jpg'; 
									}
				$html .=			'" alt=""></div>
												
									<div class="comment-box">
										<div class="comment-head">
											<h6 class="comment-name"><a href="javascript:void(0)">'.$replies['username'].'</a></h6>
											<span>'.$replies['accounttype'].'</span>
									
										</div>
										<div class="comment-content">
											<p>'.$replies['comment'].'</p>
										</div>
									</div>
							</li>';
							}
				$html .= '</ul>';
			}
		}
		
		echo $html;
		die;
	}

	public function reviewmorecomment()
	{
		$count = $this->input->post('count'); 
		$party_id = $this->input->post('party_id'); 
		$user_id = $this->session->userdata('user_id'); 
		$comments = $this->common_model->getAllMultipleJoin('review_comments',array('event_id'=>$party_id,'parent_id'=>0,'approved'=>1),array(array('feu_userdetails','feu_userdetails.user_id = review_comments.user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'review_comments.created DESC','*, review_comments.id','',$count,2);
		$html = '';
				if($comments){
					foreach ($comments as $key => $value) {
						$replies = $this->common_model->getAllMultipleJoin('review_comments',array('event_id'=>$party_id,'parent_id'=>$value['id'],'approved'=>1),array(array('feu_userdetails','feu_userdetails.user_id = review_comments.user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'review_comments.created DESC');
						
		$html .= '	<li>
						<div class="comment-main-level">
						<div class="comment-avatar"><img src="';
							if(!empty($value) && $value['filename']!=''){ 
		$html .= 				base_url().'assets/userfiles/'.$value['path'].'/160/'.$value['filename'].'.'.$value['extension']; 
							} else { 						
		$html .=				base_url().'assets/images/default-avatar.jpg'; 
							}
		$html .=			'" alt=""></div>
							
							<div class="comment-box">
								<div class="comment-head">
									<h6 class="comment-name by-author"><a href="javascript:void(0)">'.$value['username'].'</a></h6>
									<span>'.$value['accounttype'].'</span>
							
								</div>
								<div class="comment-content">
									<p>'.$value['comment'].'</p>
									<a href="javascript:void(0)" class="comment-reply" data-id="'.$value['id'].'">Reply</a>
									<span></span>
									</div>
								</div>
                              </div>';
							if($replies){
		$html .= '			<ul class="comments-list reply-list">';
								foreach ($replies as $k => $val) {
		$html .= '					<li>	
										<div class="comment-avatar"><img src="';
										if(!empty($val) && $val['filename']!=''){ 
		$html .= 							base_url().'assets/userfiles/'.$val['path'].'/160/'.$val['filename'].'.'.$val['extension']; 
										} else { 						
		$html .=							base_url().'assets/images/default-avatar.jpg'; 
										}
		$html .=						'" alt=""></div>
										
										<div class="comment-box">
											<div class="comment-head">
												<h6 class="comment-name"><a href="javascript:void(0)">'.$val['username'].'</a></h6>
												<span>'.$val['accounttype'].'</span>
										
											</div>
											<div class="comment-content">
												<p>'.$val['comment'].'</p>
											</div>
										</div>
									</li>';
								}
		$html .= '			</ul>';
							}
		$html .= '		</li>';			
					}
				}
		echo $html;
		die;
	}

	function downloadInvoicePDF($cart_id){

		$site_address_name = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_name'));
		$site_address_city = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_city'));
		$site_address_country_zip = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_country_zip'));
		/********************New mail***************************/
		$orderDetails = $this->common_model->getAllMultipleJoin('shop_carts',array('shop_carts.id'=>$cart_id),array(array('shop_orders','shop_carts.id = shop_orders.cart_id'),array('usr_users','usr_users.id = shop_carts.user_id'),array('shop_booking_details','shop_booking_details.cart_id = shop_carts.id')));

		$loginUserDetails = $this->common_model->getAllRow('usr_users',array('id'=>$this->session->userdata('user_id')));
		//echo $this->db->last_query();
		if($loginUserDetails['email'] == $orderDetails[0]['invoiceAddress']){
			$userData = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$orderDetails[0]['user_id']));
			//$orderDetails = $this->common_model->getAllMultipleJoin('shop_booking_details',array('cart_id'=>$cart_id));
	        $orderDetail = $this->common_model->getAllRowMultipleJoin('shop_orders',array('cart_id'=>$cart_id));
	        $total = number_format($orderDetail['total_sum']/100,2,',','.');
	        //pr($orderDetails);
	        $body='<!DOCTYPE html>
						<html>
						   <head>
						      <title>invoice</title>
						   </head>
						   <body>
						      <div style="max-width:960px; width:100%; margin:0 auto 0; font-family: sans-serif; padding: 0 50px;">
						      <div style="padding: 15px 0 20px; ">
							          
							         </div>
						      <p style="margin-top:60px;">'.getUserLang('please_transfer_the_following_amount', $orderDetails[0]['user_id']).'</p><br>';
	        if(!empty($orderDetails))
			{
				$body.='<p>'.getUserLang('Please_transfer_the_full_amount_of', $orderDetails[0]['user_id']).' <span class="total">EUR '.$total.'</span> </p><br>
	                         <p><strong>'.getUserLang('Invoice_Number', $orderDetails[0]['user_id']).':</strong> <span class="invoiceID">'.$orderDetail['order_id_masked'].'</span></p>
	                         <p><strong>'.getUserLang('Generated_On', $orderDetails[0]['user_id']).':</strong> '.date('Y-m-d',$orderDetail['created']).'</p>
	                         <p><strong>'.getUserLang('Due_to', $orderDetails[0]['user_id']).':</strong> '.date('Y-m-d',strtotime(date('Y-m-d',$orderDetail['created'])." + 10days")).'</p>
	                         <p><strong>'.getUserLang('Outstanding_Amount', $orderDetails[0]['user_id']).': </strong><span class="total">'.$total.' EUR</span></p>
	                         <br>
	                         <strong>'.getUserLang('Details_of_your_Order', $orderDetails[0]['user_id']).':</strong>';
				foreach ($orderDetails as $value)
				{
					if($value['price'] > 0)
	                {
						$name = getValue('event_features_lang_values',array('event_feature_id'=>$value['feature_id'],'lang_id'=>$langId));
						if(empty($name))
						{
							$name = getValue('event_features_lang_values',array('event_feature_id'=>$value['feature_id'],'lang_id'=>2));
						}
						
						$dates = explode(',', $value['feature_id']);
	                    $date='';
	                    if(!empty($dates))
	                    {
	                      foreach ($dates as $dateVal) {
	                        $val = getValue('event_features',array('id'=>$dateVal));
	                        $date .= date('d.m.Y',$val['date']).',';
	                      }
	                    }
						if(!empty($name))
						{
							$title = $name['title'];
						}
						else
						{
							$title = getUserLang('Extra_Nights', $orderDetails[0]['user_id']).' ('.rtrim($date,',').')';
						}
		        		$body.=' <p><span>-</span> <span class="entryDetails">'.$title.'</span></p>';
		        	}
	            }
	            $site_address_name = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_name'));
				$site_address_city = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_city'));
				$site_address_country_zip = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_country_zip'));
	            $body.=' <br>
	                         <strong>'.getUserLang('Bank_Details', $orderDetails[0]['user_id']).':</strong>
	                         <br>
	                         <p><strong>IBAN:</strong> CH810023123110716660E</p>
	                         <p><strong>'.getUserLang('Clearing', $orderDetails[0]['user_id']).':</strong> 231</p>
	                         <p><strong>Swift:</strong> UBSWCHZH80A</p>
	                         <p><strong>'.getUserLang('Payment_Reason', $orderDetails[0]['user_id']).':</strong> '.$orderDetail['order_id_masked'].'</p>
	                         <p><strong>'.getUserLang('Amount', $orderDetails[0]['user_id']).':</strong> <span class="total">'.$total.'</span></p>
	                         <p><strong>'.getUserLang('Bank', $orderDetails[0]['user_id']).':</strong> UBS, Bahnhofstrasse 1, 5000 Aarau, Switzerland</p>
	                         <p><strong>'.getUserLang('Recipient', $orderDetails[0]['user_id']).':</strong> '.$site_address_name['value'].', '.$site_address_city['value'].', '.$site_address_country_zip['value'].'</p>
	                        </div> ';
	        }
	        
			
			//$body.= '<p>Best regards,</p><p>Your Castleevents Team </p>';


			$body.='</div>
						   </body>
						</html>';

			//echo $body;die;
			//print_r($orderDetails);
			$pdfFilePath = $orderDetails[0]['order_id_masked'].".pdf";
	        $this->load->library('m_pdf');

	        $this->m_pdf->pdf->useOnlyCoreFonts = true;    // false is default
			$this->m_pdf->pdf->SetTitle("Castleevents Title");
			$this->m_pdf->pdf->SetAuthor("Author");
			$this->m_pdf->pdf->SetDisplayMode('fullpage'); 
			$this->m_pdf->pdf->WriteHTML($body);
			$this->m_pdf->pdf->Output($pdfFilePath, "D");    
	        die;
			/********************New mail***************************/
		}
	}
}
