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

class Profile extends CI_Controller
{
	public function __construct()
	{ 
		parent:: __construct();
		$this->load->model('common_model');
		$this->load->model('users_model');
		if(!$this->session->userdata('user_id'))
		{
			redirect('home/login');
		}
		$this->load->library('Mobile_detect');
		avatarCron();
	}
	public function index()
	{
		$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['steps'] = $this->common_model->getAllRow('feu_user_steps',array('user_id'=>$this->session->userdata('user_id'))) ;
		$content_data['userDetials'] = $this->common_model->getAllRowMultipleJoin('feu_userdetails',array('feu_userdetails.user_id'=>$this->session->userdata('user_id')),array(array('sys_files','sys_files.id = feu_userdetails.avatar_file_id'),array('feu_countries','feu_countries.country_code = feu_userdetails.country'))) ;
		$content_data['device'] = ($this->mobile_detect->isMobile() ? ($this->mobile_detect->isTablet() ? 'tablet' : 'phone') : 'computer');
		$content_data['userMembershipDetails'] = $this->users_model->getMembershipDetails($this->session->userdata('user_id'));
		//$content_data['userMembershipDetails'] = $this->common_model->getAllRowMultipleJoin('shop_orders',array('shop_carts.user_id'=>$this->session->userdata('user_id'),'shop_orders.payed'=>1,'shop_orders.is_booking'=>0),array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created','shop_articles.id');
		$content_data['userImages'] = $this->common_model->getAllMultipleJoin('ugal_images',array('ugal_images.user_id'=>$this->session->userdata('user_id')),array(array('sys_files','sys_files.id = ugal_images.file_id')),'sys_files.id DESC') ;
		$content_data['userPreferences'] = $this->common_model->getAll('feu_sexual_preference',array('user_id'=>$this->session->userdata('user_id')));
		$content_data['userParticipation'] = $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'),array('evt_events','evt_events.id = shop_booking_details.event_id')),'shop_orders.created','','shop_booking_details.cart_id');
		$content_data['latestMembers'] = $this->common_model->getAllMultipleJoin('feu_userdetails',array('avatar_file_id >'=>0,'feu_userdetails.user_id !='=>$this->session->userdata('user_id'),'filename !='=>''),array(array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'RAND()','','',0,8);
		$content_data['comments'] = $this->common_model->getAllMultipleJoin('feu_userdetails',array('alias_path'=>'community/profil/'.$content_data['userDetials']['alias']),array(array('sys_files','sys_files.id = feu_userdetails.avatar_file_id'),array('cmt_comments','cmt_comments.user_id = feu_userdetails.user_id')),'cmt_comments.created DESC','*,cmt_comments.created,cmt_comments.id','',0,8);
		
		//print_r($content_data['comments']); die;
		$content_data['languages'] = $this->common_model->getAll('sys_languages') ;
		$content_data['memberships'] = $this->common_model->getAll('shop_articles',array('id >'=>3,'id <'=>6),'','id Desc') ;
		$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1),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_events.title as title','id',0,2) ;
		$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1),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_events.title as title','id',0,4) ;
		if(empty($data['upcomingEvents']))
		{
			$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1),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_events.title as title','id',0,2) ;
		}
		if(empty($data['lastEvents']))
		{
			$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1),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_events.title as title','id',0,4) ;
		}
		$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'=>2),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')),'','shop_orders.created,shop_orders.cart_id,evt_language_values.title,evt_language_values.alias','shop_booking_details.cart_id') ;
		$data['unfinishedPayment'] = $this->common_model->getAllMultipleJoin('shop_booking_details',array('is_booking'=>1,'payed'=>0,'shop_carts.user_id'=>$this->session->userdata('user_id')),array(array('shop_carts','shop_carts.id = shop_booking_details.cart_id'),array('shop_orders','shop_orders.cart_id = shop_carts.id')),'shop_orders.created','','shop_booking_details.cart_id');
		//echo $this->db->last_query();die;
		$data['languages'] = $this->common_model->getAll('sys_languages') ;
		$data['userDetials'] = $this->common_model->getAllRowMultipleJoin('feu_userdetails',array('feu_userdetails.user_id'=>$this->session->userdata('user_id')),array(array('sys_files','sys_files.id = feu_userdetails.avatar_file_id'),array('feu_countries','feu_countries.country_code = feu_userdetails.country'))) ;
		$data['cms_pages_1'] = $this->common_model->getAllMultipleJoin('cms_page',array('section_id'=>1),array(array('sys_files','sys_files.id = cms_page.thumb_id')),'cms_page.id ASC','*','');
		$data['cms_pages_2'] = $this->common_model->getAllMultipleJoin('cms_page',array('section_id'=>2),array(array('sys_files','sys_files.id = cms_page.thumb_id')),'cms_page.id ASC','*','');
		$data['cms_pages_3'] = $this->common_model->getAllMultipleJoin('cms_page',array('section_id'=>3),array(array('sys_files','sys_files.id = cms_page.thumb_id')),'cms_page.id ASC','*','');
		$data['cms_pages_4'] = $this->common_model->getAllMultipleJoin('cms_page',array('section_id'=>4),array(array('sys_files','sys_files.id = cms_page.thumb_id')),'cms_page.id ASC','*','');
		$data['device'] = ($this->mobile_detect->isMobile() ? ($this->mobile_detect->isTablet() ? 'tablet' : 'phone') : 'computer');
		$data['title'] = "Profile | ".$data['userDetials']['username'];
		$data['content'] = $this->load->view('profile', $content_data, TRUE);
		$this->load->view('template', $data);
	}
	public function step1()
	{
		$userlanguage = $this->input->post('userlanguage');
		$interest_lady = $this->input->post('interest_lady');
		$interest_gentleman = $this->input->post('interest_gentleman');
		$interest_couples = $this->input->post('interest_couples');
		$interest_escort = $this->input->post('interest_escort');
		$interest_private = $this->input->post('interest_private');
		$preferences = $this->input->post('preferences');
		$arr = array(
					'userlanguage'=>$userlanguage,
					'interested_in_ladies'=>$interest_lady,
					'interested_in_gentlemen'=>$interest_gentleman,
					'interested_in_couples'=>$interest_couples,
					'interested_in_private_meeting'=>$interest_private,
					'interested_financial_interests'=>$interest_escort,
					'preferences'=>$preferences
			);
		$this->common_model->UpdateData('feu_userdetails',$arr,array('user_id'=>$this->session->userdata('user_id')));
		$update = $this->common_model->UpdateData('feu_user_steps',array('step'=>2),array('user_id'=>$this->session->userdata('user_id')));
		/*if($update>0)
		{
			echo 1;
		}
		else
		{
			echo 0;
		}*/
		echo 1;
	}
	public function step2()
	{
		$she_year = $this->input->post('she_year');
		$she_month = $this->input->post('she_month');
		$she_date = $this->input->post('she_date');
		$she_physis = $this->input->post('she_physis');
		$he_year = $this->input->post('he_year');
		$he_month = $this->input->post('he_month');
		$he_date = $this->input->post('he_date');
		$he_physis = $this->input->post('he_physis');
		$arr = array(
					'dob_lady'=>strtotime($she_date.'-'.$she_month.'-'.$she_year),
					'dob_gentleman'=>strtotime($he_year.'-'.$he_month.'-'.$he_date),
					'physis_lady'=>$she_physis,
					'physis_gentleman'=>$he_physis
			);
		$this->common_model->UpdateData('feu_userdetails',$arr,array('user_id'=>$this->session->userdata('user_id')));
		$update = $this->common_model->UpdateData('feu_user_steps',array('step'=>3),array('user_id'=>$this->session->userdata('user_id')));
		/*if($update>0)
		{
			echo 1;
		}
		else
		{
			echo 0;
		}*/
		echo 1;
	}
	public function step10()
	{
		$sexual_preference = $this->input->post('sexual_preference');
		foreach ($sexual_preference as $key => $value) {
			$arr = array(
					'user_id'=>$this->session->userdata('user_id'),
					'sex_preference'=>$value,
			);
			$this->common_model->insertData('feu_sexual_preference',$arr);
		}
		
		$update = $this->common_model->UpdateData('feu_user_steps',array('step'=>4),array('user_id'=>$this->session->userdata('user_id')));
		/*if($update>0)
		{
			echo 1;
		}
		else
		{
			echo 0;
		}*/
		echo 1;
	}
	public function step3()
	{
		$about = $this->input->post('about');
		$arr = array(
					'about'=>$about,
			);
		$this->common_model->UpdateData('feu_userdetails',$arr,array('user_id'=>$this->session->userdata('user_id')));
		$update = $this->common_model->UpdateData('feu_user_steps',array('step'=>5),array('user_id'=>$this->session->userdata('user_id')));
		/*if($update>0)
		{
			echo 1;
		}
		else
		{
			echo 0;
		}*/
		echo 1;
	}
	public function step4()
	{
		if($_FILES['file']['name']!='')
		{
			$imagefolder = 'avatars/' ;
	        $uploadpath = 'assets/userfiles/'. $imagefolder;
			/*if (!file_exists(FCPATH . $uploadpath)) {
			    mkdir(FCPATH . $uploadpath, 0777, true);
			} */ 
			$filename = time().$_FILES['file']['name'];
	        $config = array(
	            'upload_path' 		=> FCPATH . $uploadpath . '/',
	            'allowed_types' 	=> 'jpg|png',
	            'encrypt_name' 		=> true,
	            'file_name'			=> $filename,
	            'file_ext_tolower' 	=> true,
	            //'max_size' 			=> (int)MSysSettings::getValue('upload_max_filesize') * 1024,
	        );

	        $this->load->library('upload', $config);
	       
	        if(!$this->upload->do_upload('file')) {

	            echo $this->upload->display_errors();
	        }

	        $uploaddata = $this->upload->data();
	        $file = array(
	            'user_id' 	=> $this->session->userdata('user_id'),
	            'path' 		=> $imagefolder,
	            'filename' 	=> '',
	            'extension' => substr($uploaddata['file_ext'], 1),
	            'mimetype' 	=> $uploaddata['file_type'],
	            'is_image' 	=> $uploaddata['is_image'],
	            'attr_alt' 	=> 'Bild von ' ,
	            'created'	=> time(),
	            'temp_name'	=> $uploaddata['raw_name']
	        );
	        
	        $imagesize = getimagesize($uploaddata['full_path']);
	        $file['width'] 	= $imagesize[0];
	        $file['height'] = $imagesize[1];


	        $fileId = $this->common_model->insertData('sys_files',$file);
	        $this->common_model->UpdateData('feu_userdetails',array('avatar_file_id'=>$fileId),array('user_id'=>$this->session->userdata('user_id')));
			$update = $this->common_model->UpdateData('feu_user_steps',array('step'=>6),array('user_id'=>$this->session->userdata('user_id')));
			/**********************MAIL**************************/
				$userDetails = $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')));
				//$to = 'sayan@digitalaptech.com';
				$to = 'andrej@castleevents.com';
				$sub = 'New: Avatar Picture Upload';
				//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];
				$body= '<p>Dear Admin,</p>';
				$body.= '<p>the User '.$userDetails['username'].' uploaded the following avatar. Below the image:</p>';
				$body.= '<p><img src = "';
				if(file_exists(FCPATH.'assets/userfiles/'.$imagefolder.'/'.$uploaddata['raw_name'].'.'.substr($uploaddata['file_ext'], 1)))
				{ 
					$body.= base_url().'assets/userfiles/'.$imagefolder.'/'.$uploaddata['raw_name'].'.'.substr($uploaddata['file_ext'], 1);
				} 
				else 
				{ 
					$body.= 'images/default-avatar.jpg';
				}	
				$body.= '"></p>';
				$body.= '<p><a href="'.base_url().'admin">Login Admin</a></p>';
				$body.= '<p>Please do not hesitate to contact us for any other requests.</p>';
				$body.= '<p>Best regards,</p><p>Your Castleevents Team </p>';
				$this->utility->sendMail($to,$sub,$body);
			/**********************MAIL**************************/
		}
		/*if($update>0)
		{
			echo 1;
		}
		else
		{
			echo 0;
		}*/
		echo 1;
	}
	public function createOrder()
	{
		$origPrice = $this->input->post('price');
		$feePrice = $this->input->post('feePrice');
		$vatPrice = $this->input->post('vatPrice');
		$type = $this->input->post('type');
		$user_id = $this->session->userdata('user_id');
		$userDetails = $this->common_model->getAllRow('usr_users',array('id'=>$this->session->userdata('user_id')));

		$cartArr = array(
					'created'=>time(),
					'user_id'=>$user_id,
					'session_id'=>$this->session->userdata('session_id'),
					'ordered'=>1
			);
		$cartId = $this->common_model->insertData('shop_carts',$cartArr);
		$artArr = array(
					'created'=>time(),
					'cart_id'=>$cartId,
					'article_id'=>$type,
					'quantity'=>1
			);
		$cartId = $this->common_model->insertData('shop_articles_carts',$artArr);
		$orderDetails = $this->common_model->getAllRow('shop_orders','','','','max(order_id) as order_id');

		$dataset = array(
			'order_id'				=> $orderDetails['order_id']+1,
			'cart_id' 				=> $cartId,
			'shipping_address_id' 	=> 0,
			'invoice_address_id' 	=> 0,
			'ip_address' 			=> $this->input->ip_address(),
			'total_base' 			=> $origPrice*100,
			'shipping_fee' 			=> 0,
			'payment_fee' 			=> ($feePrice - $origPrice)*100,
			'vat' 					=> ($vatPrice - $feePrice)*100,
			'total_sum' 			=> ($origPrice+$feePrice+$vatPrice)*100 ,
			'payment_method_id' 	=> 14,
			'checkin_required' 		=> 0,
			'checkin_amount' 		=> 0,
			'invoiceAddress' 		=> $user->email,//$invoiceAdress['shipping']['email'],
            'discount'              => 0,
		);
		$orderId = $this->common_model->insertData('shop_orders',$dataset);

		$this->common_model->UpdateData('shop_orders',array('order_id_masked'=>'CE-'.$orderId),array('order_id'=>$orderId));
	}

	public function confirmOrder()
	{
		
		$origPrice = $this->input->post('price');
		$feePrice = $this->input->post('feePrice');
		$vatPrice = $this->input->post('vatPrice');
		$type = $this->input->post('type');
		$user_id = $this->session->userdata('user_id');
		$userDetails = $this->common_model->getAllRow('usr_users',array('id'=>$this->session->userdata('user_id')));
		$userData = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$this->session->userdata('user_id')));
		$finaltotal = 0;
		if($vatPrice > 0)
		{
			$finaltotal = $vatPrice;
		}
		else
		{
			$finaltotal = $feePrice;
		}
		$cartArr = array(
					'created'=>time(),
					'user_id'=>$user_id,
					'session_id'=>$this->session->userdata('session_id'),
					'ordered'=>1
			);
		$cartId = $this->common_model->insertData('shop_carts',$cartArr);
		$artArr = array(
					'created'=>time(),
					'cart_id'=>$cartId,
					'article_id'=>$type,
					'quantity'=>1
			);
		$cartArtId = $this->common_model->insertData('shop_articles_carts',$artArr);
		$orderDetails = $this->common_model->getAllRow('shop_orders','','','','max(order_id) as order_id');
		
		$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' 			=> $origPrice*100,
			'shipping_fee' 			=> 0,
			'payment_fee' 			=> ($feePrice - $origPrice)*100,
			'vat' 					=> ($vatPrice - $feePrice)*100,
			'total_sum' 			=> $finaltotal*100 ,
			'payment_method_id' 	=> 14,
			'invoiceAddress' 		=> $userDetails['email'],
            'discount'              => 0,
            'time'					=>($origPrice==170)?6:1,
            'created'				=> time()
		);
		$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));
		
		require $_SERVER['DOCUMENT_ROOT'].'/castle/stripe/Stripe.php';
		$params = array(
				"testmode"   => "on",
				"private_live_key" => "sk_live_7yHhLLeHGtSdGfc0rJNbLXZl",
				"public_live_key"  => "pk_live_TyYHG0MtVuby9Ja5c8gkddCx",
				"private_test_key" => "sk_test_S1Eg863dRzyX5S6deJ39KLIh",
				"public_test_key"  => "pk_test_J4rdzwRQrf2RsXG6xafA4y4q",
				//"private_test_key"  => "sk_test_OFGHKhrV3K6yzNg1RtxDaakA",
				//"public_test_key"  => "pk_test_8TMqaTrtjzh44TBsV9uzi0J6",
			);
			
			if ($params['testmode'] == "on") {
				Stripe::setApiKey($params['private_test_key']);
				$pubkey = $params['public_test_key'];
			} else {
				Stripe::setApiKey($params['private_live_key']);
				$pubkey = $params['public_live_key'];
			}
			if($this->input->post('stripeToken'))
			{
				//$amount_cents = str_replace(".","","10.52");  // Chargeble amount
				$invoiceid = "14526321";  
				if($origPrice==170)      
				{
					$month = '6 Months';
				} 
				else
				{
					$month = '1 Year';
				}             // Invoice ID
				$description = "Memberhsip for " .$month;
				
				$userDetail = $this->common_model->getAllRow('usr_users',array('id'=>$this->session->userdata('user_id')));
				
				try {
					
					$customer = Stripe_Customer::create(array(		 
						  "email" => $userDetail['email'],
						  "source" => $this->input->post('stripeToken'))
					);
					$cust_id =0;
					if(!empty($customer))
					{
						$cust_id = $customer->id;
					}
					$charge = Stripe_Charge::create(array(		 
						  "amount" => $finaltotal*100,
						  "currency" => "eur",
						  "customer" => $cust_id)
					);
			 		
					/*if ($charge->card->address_zip_check == "fail") {
						throw new Exception("zip_check_invalid");
					} else if ($charge->card->address_line1_check == "fail") {
						throw new Exception("address_check_invalid");
					} else if ($charge->card->cvc_check == "fail") {
						throw new Exception("cvc_check_invalid");
					}*/
				$result = "success";
		 
					} catch(Stripe_CardError $e) {			
				 
					$error = $e->getMessage();
						$result = "declined";
				 
					} catch (Stripe_InvalidRequestError $e) {
						$result = "declined";		  
					} catch (Stripe_AuthenticationError $e) {
						$result = "declined";
					} catch (Stripe_ApiConnectionError $e) {
						$result = "declined";
					} catch (Stripe_Error $e) {
						$result = "declined";
					} catch (Exception $e) {
				 
						if ($e->getMessage() == "zip_check_invalid") {
							$result = "declined";
						} else if ($e->getMessage() == "address_check_invalid") {
							$result = "declined";
						} else if ($e->getMessage() == "cvc_check_invalid") {
							$result = "declined";
						} else {
							$result = "declined";
						}		  
					}
					if($result=='success')
					{
						$this->common_model->UpdateData('shop_orders',array('payed'=>1,'trn_id'=>$charge->id),array('order_id'=>$orderId));
						$this->common_model->UpdateData('usr_users',array('customer_id'=>$customer->id),array('id'=>$this->session->userdata('user_id')));
						
						$this->common_model->deleteData('feu_user_steps',array('user_id'=>$this->session->userdata('user_id')));
						
						$to = $userDetail['email'];
						$sub = 'Membership Invoice mail from Castleevents';
						$body= '<p>Dear '.$userData['username'].',</p>';
						$body.= '<p>We have received your payment, thank you!</p>';
						$body.= '<p>Invoice Number: CE-'.$orderId.'</p><p>Generated on: '.date('Y-m-d',time()).'</p><p>Paid Amount: '.($origPrice+$feePrice+$vatPrice).' EUR</p>';
						$body.= '<p>Invoice will be located in your profile settings area, please login at www.castleevents.com.</p>';
						$body.= '<p>We appreciate very much your trust.</p>';
						$body.= '<p>Please do not hesitate to contact us for any other requests.</p>';
						$body.= '<p>Best regards,</p><p>Your Castleevents Team </p>';
						$this->utility->sendMail($to,$sub,$body);
						echo 2;
					}
					else
					{
						echo 'Authentication Denied';
					}
			}
	}
	public function invoice()
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		if(checkStep()==1)
		{
			redirect('profile');
		}
		$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$this->session->userdata('user_id'))) ;
		$content_data['invoices'] = $this->common_model->getAllMultipleJoin('shop_booking_details',array('is_booking'=>1,'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'),array('evt_events','evt_events.id = shop_booking_details.event_id'),array('evt_language_values','evt_language_values.event_id = evt_events.id'),array('loc_events_locations','loc_events_locations.event_id = evt_events.id'),array('loc_locations','loc_locations.id = loc_events_locations.location_id')),'shop_orders.created DESC','*,evt_events.alias','shop_booking_details.cart_id');
		$content_data['orders'] = $this->common_model->getAllMultipleJoin('shop_articles_carts',array('is_booking'=>0,'payed'=>1,'shop_carts.user_id'=>$this->session->userdata('user_id')),array(array('shop_carts','shop_carts.id = shop_articles_carts.cart_id'),array('shop_orders','shop_orders.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created DESC','*,shop_orders.created','shop_articles_carts.cart_id');
		$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1),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_events.title as title','id',0,2) ;
		$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1),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_events.title as title','id',0,4) ;
		if(empty($data['upcomingEvents']))
		{
			$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1),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_events.title as title','id',0,2) ;
		}
		if(empty($data['lastEvents']))
		{
			$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1),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_events.title as title','id',0,4) ;
		}
		$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'=>2),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')),'','shop_orders.created,shop_orders.cart_id,evt_language_values.title,evt_language_values.alias','shop_booking_details.cart_id') ;
		$data['unfinishedPayment'] = $this->common_model->getAllMultipleJoin('shop_booking_details',array('is_booking'=>1,'payed'=>0,'shop_carts.user_id'=>$this->session->userdata('user_id')),array(array('shop_carts','shop_carts.id = shop_booking_details.cart_id'),array('shop_orders','shop_orders.cart_id = shop_carts.id')),'shop_orders.created','','shop_booking_details.cart_id');
		//echo $this->db->last_query();die;
		//print_r($content_data['orders']);die;
		$data['languages'] = $this->common_model->getAll('sys_languages') ;
		$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['cms_pages_1'] = $this->common_model->getAllMultipleJoin('cms_page',array('section_id'=>1),array(array('sys_files','sys_files.id = cms_page.thumb_id')),'cms_page.id ASC','*','');
		$data['cms_pages_2'] = $this->common_model->getAllMultipleJoin('cms_page',array('section_id'=>2),array(array('sys_files','sys_files.id = cms_page.thumb_id')),'cms_page.id ASC','*','');
		$data['cms_pages_3'] = $this->common_model->getAllMultipleJoin('cms_page',array('section_id'=>3),array(array('sys_files','sys_files.id = cms_page.thumb_id')),'cms_page.id ASC','*','');
		$data['cms_pages_4'] = $this->common_model->getAllMultipleJoin('cms_page',array('section_id'=>4),array(array('sys_files','sys_files.id = cms_page.thumb_id')),'cms_page.id ASC','*','');
		$data['device'] = ($this->mobile_detect->isMobile() ? ($this->mobile_detect->isTablet() ? 'tablet' : 'phone') : 'computer');
		$data['title'] = "Invoice | ".$data['userDetials']['username'];
		$data['content'] = $this->load->view('invoice', $content_data, TRUE);
		$this->load->view('template', $data);
	}
	public function orderDetails()
	{
		$cart_id = $this->input->post('cart_id');
		$type = $this->input->post('type');
		if($type==2)
		{
			$orderDetails = $this->common_model->getAllMultipleJoin('shop_booking_details',array('cart_id'=>$cart_id));
			$html='<table class="order-table"><tr><td>Feature</td><td>Quantity</td><td>Price(EUR)</td></tr>';
			$total = 0;
			if(!empty($orderDetails))
			{
				foreach ($orderDetails as $value)
				{
					$total = $total + $value['price'];
					$name = getValue('event_features_lang_values',array('event_feature_id'=>$value['feature_id'],'lang_id'=>1));
					if(!empty($name))
					{
						$title = $name['title'];
					}
					else
					{
						$title = 'Extra Nights';
					}
					$quantity = count(explode(',', $value['feature_id']));
				$html.='<tr><td>'.$title.'</td><td>'.$quantity.'</td><td>'.number_format($value['price'],2,',','.').'</td></tr>';
	            }
	            $html.='<tr><td></td><td>Total</td><td>'.number_format($total,2,',','.').'</td></tr>';
			}
			$html.='</table>';
		}
		else
		{
			$orderDetails = $this->common_model->getAllRowMultipleJoin('shop_articles_carts',array('shop_orders.cart_id'=>$cart_id),array(array('shop_carts','shop_carts.id = shop_articles_carts.cart_id'),array('shop_orders','shop_orders.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created DESC','*,shop_orders.created','shop_articles_carts.cart_id');
			$html='<table class="order-table"><tr><td></td><td>Feature</td><td>Price(EUR)</td></tr>';
			$total = 0;
			if(!empty($orderDetails))
			{
				$html.='<tr><td></td><td>'.ucfirst($orderDetails['alias']).'</td><td>'.number_format($orderDetails['total_base']/100,2,',','.').'</td></tr>';
				$html.='<tr><td></td><td>Payment Fee</td><td>'.number_format($orderDetails['payment_fee']/100,2,',','.').'</td></tr>';
				$html.='<tr><td></td><td>Vat</td><td>'.number_format($orderDetails['vat']/100,2,',','.').'</td></tr>';
				$html.='<tr><td></td><td>Total</td><td>'.number_format($orderDetails['total_sum']/100,2,',','.').'</td></tr>';
			}
			$html.='</table>';
		}
		echo $html;
	}
	public function Invoicepay()
	{
		$userData = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$this->session->userdata('user_id')));
		require $_SERVER['DOCUMENT_ROOT'].'/castle/stripe/Stripe.php';
		$params = array(
				"testmode"   => "on",
				"private_live_key" => "sk_live_7yHhLLeHGtSdGfc0rJNbLXZl",
				"public_live_key"  => "pk_live_TyYHG0MtVuby9Ja5c8gkddCx",
				"private_test_key" => "sk_test_S1Eg863dRzyX5S6deJ39KLIh",
				"public_test_key"  => "pk_test_J4rdzwRQrf2RsXG6xafA4y4q",
				//"private_test_key"  => "sk_test_OFGHKhrV3K6yzNg1RtxDaakA",
				//"public_test_key"  => "pk_test_8TMqaTrtjzh44TBsV9uzi0J6",
			);
			
			if ($params['testmode'] == "on") {
				Stripe::setApiKey($params['private_test_key']);
				$pubkey = $params['public_test_key'];
			} else {
				Stripe::setApiKey($params['private_live_key']);
				$pubkey = $params['public_live_key'];
			}
			if($this->input->post('stripeToken'))
			{
				//$amount_cents = str_replace(".","","10.52");  // Chargeble amount
				$invoiceid = "14526321";  
				$description = "Party Booking";
				
				$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')));
				
				try {
					
					$customer = Stripe_Customer::create(array(		 
						  "email" => $userDetail['email'],
						  "source" => $this->input->post('stripeToken'))
					);
					$cust_id =0;
					if(!empty($customer))
					{
						$cust_id = $customer->id;
					}
					$charge = Stripe_Charge::create(array(		 
						  "amount" => $this->input->post('price')*100,
						  "currency" => "eur",
						  "customer" => $cust_id)
					);
			 		
					/*if ($charge->card->address_zip_check == "fail") {
						throw new Exception("zip_check_invalid");
					} else if ($charge->card->address_line1_check == "fail") {
						throw new Exception("address_check_invalid");
					} else if ($charge->card->cvc_check == "fail") {
						throw new Exception("cvc_check_invalid");
					}*/
				$result = "success";
		 
					} catch(Stripe_CardError $e) {			
				 
					$error = $e->getMessage();
						$result = "declined";
				 
					} catch (Stripe_InvalidRequestError $e) {
						$result = "declined";		  
					} catch (Stripe_AuthenticationError $e) {
						$result = "declined";
					} catch (Stripe_ApiConnectionError $e) {
						$result = "declined";
					} catch (Stripe_Error $e) {
						$result = "declined";
					} catch (Exception $e) {
				 
						if ($e->getMessage() == "zip_check_invalid") {
							$result = "declined";
						} else if ($e->getMessage() == "address_check_invalid") {
							$result = "declined";
						} else if ($e->getMessage() == "cvc_check_invalid") {
							$result = "declined";
						} else {
							$result = "declined";
						}		  
					}
					if($result=='success')
					{
						$this->common_model->UpdateData('shop_orders',array('payed'=>1,'trn_id'=>$charge->id,'payment_method_id'=>14),array('cart_id'=>$this->input->post('cart_id')));
						
						$to = $userDetail['email'];
						$sub = 'Confirmation: Successful payment';
						//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];
						$body= '<p>Dear '.$userData['username'].',</p>';
						$body.= '<p>We have received your payment, thank you!</p>';
						$body.= '<p>Invoice Number: CE-'.$orderDetail['order_id'].'</p><p>Generated on: '.date('Y-m-d',time()).'</p><p>Paid Amount: '.$this->input->post('price').' EUR</p>';
						$body.= '<p>Invoice will be located in your profile settings area, please login at www.castleevents.com.</p>';
						$body.= '<p>We appreciate very much your trust.</p>';
						$body.= '<p>Please do not hesitate to contact us for any other requests.</p>';
						$body.= '<p>Best regards,</p><p>Your Castleevents Team </p>';
						$this->utility->sendMail($to,$sub,$body);
						echo 2;
					}
					else
					{
						echo 'Authentication Denied';
					}
			}
	}
	public function printDetails()
	{
		$cart_id = $this->input->post('cart_id');
		$type = $this->input->post('type');
		/*$eventDetails = $this->common_model->getAllRow('shop_booking_details',array('cart_id'=>$cart_id));
		$partyDetails = $this->common_model->getAllRow('evt_events',array('id'=>$eventDetails['event_id']));
		
		$userDetail = $this->common_model->getAllRow('usr_users',array('id'=>$this->session->userdata('user_id')));
		$userDetials = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$this->session->userdata('user_id')));
		$html='<div class="printInner" id="printInner">                    
                          Dear '.$userDetials['username'].',
                          <P style="margin-bottom:15px; font-family: Ariel">we are glad to welcome you on ';
                if(!empty($partyDetails)){ 
        $html.=	date('l',$partyDetails['time_from']); 
                } 
                if(!empty($partyDetails)){
        $html.=	date('jS F',$partyDetails['time_from']); 
                } 
        $html.=' for an unforgettable ';
                if(!empty($partyDetails)){ 
        $html.= $partyDetails['title']; 
                }
        $html.=' in the following destination.</P>
                          <div style="position: relative; text-align:center;">
                            <h3 style="position: absolute; top:30px; padding:0 60px; color:#b3975b; text-transform:uppercase; font-weight:600;">Address will be shown 2 days before the party take place</h3>
                             <h4 style="position: absolute; top:50px; padding:0 60px; left: 50%; width: 345px; margin-left: -172px; padding-top: 10px;  color:#fff; ">40 days 20 hours 2 seconds</h4>
                            <img style="margin-bottom:15px; opacity:0.3;" src="http://cisites.dapldevelopment.com/castle/assets/images/invoiceImg.jpg" alt="">
                          </div>                       
                          
                          <p>The check-in for overnight stay at the party location will be after 3 pm on Saturday, Check-out will be until 3 pm on Sunday. The breakfast buffet will be available from 9 to 12 on Sunday.</p> 
                          <h3 style="color:#b3975b; text-transform:uppercase; font-weight:600; margin:15px 0 5px;">Identification</h3>
                          <p style="margin-bottom:40px;">Identify yourself on the gate with the security team, at the reception or our team with your Pseudonym.</p>
                          <h3 style="color:#b3975b; text-transform:uppercase; font-weight:600; margin:15px 0 5px;">SPA Area</h3>
                          <p style="margin-bottom:40px;">After the first visit of the Chateau we where amazed of the beautiful SPA and finally we got the permission to rent it as well for exclusive use. As you can see on the website http://www.chateau-augerville.com the SPA delivers the perfect switch off from everyday life before an unforgettable Eyes Wide Shut Party, as well for slowing down afterwards. The opening times for exclusive use on Saturday will be 14.00-20.00 clock and on Sunday 9.00-16.00 clock. For a fun-filled stay we will provide free beverages (also alcoholic) for self service.</p>
                           
                           <h3 style="color:#b3975b; text-transform:uppercase; font-weight:600; margin:15px 0 5px;">PARTY BEGIN 20.00 CLOCK</h3>
                           <p style="margin-bottom:40px;">At the entrance of the Castle you have to check-in for entering the party. From 20.00h we are inviting you to an aperitif in the bar zone followed by a flying dinner at the terrace.</p>
                           <h3 style="color:#b3975b; text-transform:uppercase; font-weight:600; margin:15px 0 5px;">DRESSCODE</h3>
                           <p style="margin-bottom:40px;">Please make sure the party entrance is only allowed by wearing a smoking with tie. The ladies have to wear a cocktail dress or a wardrobe with nice lingerie, fishnet stockings and garters. During the whole event we ask for high-quality clothing non fetish like lacquer, leather, animal pattern, platform shoes or boots.</p>

                           <h3 style="color:#b3975b; text-transform:uppercase; font-weight:600; margin:15px 0 5px;">CEREMONIAL DRESSCODE</h3>
                           <p style="margin-bottom:40px;">The ceremony which is the transmission in to the erotic world takes place at 23.00h. Wearing a cape is mandatory here. Underneath the cape ladies are only covered by bra and panties, or topless. Gentlemen must wear black trousers and shirt without jacket. If the body-type allows they can also access with black underwear and open shirt or shirt-less. Please note: white underwear will not be allowed! </p>
                           <h3 style="color:#b3975b; text-transform:uppercase; font-weight:600; margin:15px 0 5px;">VENETIAN MASKS</h3>
                           <p style="margin-bottom:40px;">There we also provide a great range of Venetian masks for sale. You can also rent high-quality capes. Masks must be worn during the entire event.</p>
                           <h3 style="color:#b3975b; text-transform:uppercase; font-weight:600; margin:15px 0 5px;">SMOKING AREAS </h3>
                           <p style="margin-bottom:40px;">Also we would like you to keep in mind that smoking is forbidden in the entire interior. Please remember that no cameras, mobile phones or other electronic devices are allowed to carry. Our security staff is going to do controls at the entrance and random controls during the party.</p>

                           <p style="margin-bottom:40px;">If you have any questions, feel free to contact us. We are looking forward to a sparkling night. </p>
                           <p >Your Castleevents-Team </p>


                        </div>';*/
        $html='';
        if($type==2)
        {
        	$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,',','.');
	        if(!empty($orderDetails))
			{
				$html.='<div class="printInner" id="printInner">
	                        <p>Please transfer the full amount of <span class="total">EUR '.$total.'</span> to the bank accunt below. important note: As reason of payment, please use the invoice number!</p><br>
	                         <p><strong>Invoice Number:</strong> <span class="invoiceID">'.$orderDetail['order_id_masked'].'</span></p>
	                         <p><strong>Generated On:</strong> '.date('Y-m-d',$orderDetail['created']).'</p>
	                         <p><strong>Due to:</strong> '.date('Y-m-d',strtotime(date('Y-m-d',$orderDetail['created'])." + 10days")).'</p>
	                         <p><strong>Outstanding Amount: </strong><span class="total">'.$total.' EUR</span></p>
	                         <br>
	                         <strong>Details of your Order:</strong>';
				foreach ($orderDetails as $value)
				{
					$name = getValue('event_features_lang_values',array('event_feature_id'=>$value['feature_id'],'lang_id'=>1));
					if(!empty($name))
					{
						$title = $name['title'];
					}
					else
					{
						$title = 'Extra Nights';
					}
	        		$html.=' <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'));
	            $html.=' <br>
	                         <strong>Bank Details:</strong>
	                         <br>
	                         <p><strong>IBAN:</strong> CH810023123110716660E</p>
	                         <p><strong>Clearing:</strong> 231</p>
	                         <p><strong>Swift:</strong> UBSWCHZH80A</p>
	                         <p><strong>Payment Reason:</strong> 201789987</p>
	                         <p><strong>Amount:</strong> <span class="total">'.$total.'</span></p>
	                         <p><strong>Bank:</strong> UBS, Bahnhofstrasse 1, 5000 Araau, Switzerland</p>
	                         <p><strong>Recipient:</strong> '.$site_address_name['value'].', '.$site_address_city['value'].', '.$site_address_country_zip['value'].'</p>
	                        </div> ';
	        } 
        }
        else
        {
        	$orderDetails = $this->common_model->getAllRowMultipleJoin('shop_articles_carts',array('shop_orders.cart_id'=>$cart_id),array(array('shop_carts','shop_carts.id = shop_articles_carts.cart_id'),array('shop_orders','shop_orders.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created DESC','*,shop_orders.created','shop_articles_carts.cart_id');
	        if(!empty($orderDetails))
			{
				$html.='<div class="printInner" id="printInner">
                        <p><strong>Invoice Number:</strong> <span class="invoiceID">'.$orderDetails['order_id_masked'].'</span></p>
                        <p><strong>Generated On:</strong> '.date('Y-m-d',$orderDetails['created']).'</p>
                        <p><strong>Outstanding Amount: </strong><span class="total">'.number_format($orderDetails['total_sum']/100,2,',','.').' EUR</span></p>
                        <br>
                         <strong>Details of your Order:</strong>';
                $html.='<table class="order-table" style="width: 100%;">';
                $html.='<tr><td><strong></strong></td><td><strong>Feature</strong></td><td><strong>Price(EUR)</strong></td></tr>';         
                $html.='<tr><td></td><td>'.ucfirst($orderDetails['alias']).'</td><td>'.number_format($orderDetails['total_base']/100,2,',','.').'</td></tr>';
				$html.='<tr><td></td><td>Payment Fee</td><td>'.number_format($orderDetails['payment_fee']/100,2,',','.').'</td></tr>';
				$html.='<tr><td></td><td>Vat</td><td>'.number_format($orderDetails['vat']/100,2,',','.').'</td></tr>';
				$html.='<tr><td></td><td>Total</td><td>'.number_format($orderDetails['total_sum']/100,2,',','.').'</td></tr>';         
				$html.='</table></div>'; 
	        }                 
        }               
        echo $html;                
	}
	public function logout()
	{
		$this->session->unset_userdata('user_id');
		redirect(base_url());
	}
	public function other($alias = '')
	{
		$steps = getValue('feu_user_steps',array('user_id'=>$this->session->userdata('user_id')));
		if(count($steps)>0)
		{
			redirect(base_url().'profile');
		}
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$user = $this->common_model->getAllRow('feu_userdetails',array('alias'=>$alias));
		
		if(!empty($user))
		{
			$visitEntry = $this->common_model->getAllRow('feu_profilevisits',array('from_user_id'=>$this->session->userdata('user_id'),'to_user_id'=>$user['user_id']));
			if(empty($visitEntry)){
				$this->common_model->insertData('feu_profilevisits',array('from_user_id'=>$this->session->userdata('user_id'),'to_user_id'=>$user['user_id'],'created'=>time()));	
			}
			else
			{
				$this->common_model->UpdateData('feu_profilevisits',array('created'=>time()),array('from_user_id'=>$this->session->userdata('user_id'),'to_user_id'=>$user['user_id']));
			}
			$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$this->session->userdata('user_id'))) ;
			$content_data['userDetials'] = $this->common_model->getAllRowMultipleJoin('feu_userdetails',array('feu_userdetails.user_id'=>$user['user_id']),array(array('sys_files','sys_files.id = feu_userdetails.avatar_file_id'),array('feu_countries','feu_countries.country_code = feu_userdetails.country')),'','*,feu_userdetails.user_id') ;
			$content_data['device'] = ($this->mobile_detect->isMobile() ? ($this->mobile_detect->isTablet() ? 'tablet' : 'phone') : 'computer');
			$content_data['loggedInUserMembershipDetails'] = $this->users_model->getMembershipDetails($this->session->userdata('user_id'));
			$content_data['userMembershipDetails'] = $this->users_model->getMembershipDetails($user['user_id']);
			$content_data['loggedInUserImages'] = $this->common_model->getAllMultipleJoin('ugal_images',array('ugal_images.user_id'=>$this->session->userdata('user_id')),array(array('sys_files','sys_files.id = ugal_images.file_id')),'sys_files.id DESC') ;
			$userImages = $this->common_model->getAllMultipleJoin('ugal_images',array('ugal_images.user_id'=>$user['user_id']),array(array('sys_files','sys_files.id = ugal_images.file_id')),'sys_files.id DESC','*,sys_files.id as fileID') ;
			$content_data['userImages'] = $userImages;
			if(!empty($userImages))
			{
				$i = 0;
				foreach ($userImages as $value) {
					$userLikes = $this->common_model->getAllMultipleJoin('like_likes','',array(array('feu_userdetails','feu_userdetails.user_id = like_likes.user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'like_likes.created DESC','*,feu_userdetails.user_id','',0,5,array('identifier'=>$value['fileID'])) ;
					$content_data['userImages'][$i]['likeUsers'] = $userLikes;
					$i++;
				}
			}
			$hasBlurImage = count($this->common_model->getAllMultipleJoin('ugal_images',array('ugal_images.user_id'=>$user['user_id'],'is_private'=>1),array(array('sys_files','sys_files.id = ugal_images.file_id')),'sys_files.id DESC')) ;
			$content_data['hasBlurImage'] = 0;
			if($hasBlurImage>0)
			{
				$content_data['hasBlurImage'] = 1;
			}
			$content_data['userPrivacy'] = $this->common_model->getAllRowMultipleJoin('ugal_images_user_privacy',array('from_user_id'=>$this->session->userdata('user_id'),'to_user_id'=>$user['user_id'])) ;
			$content_data['userPreferences'] = $this->common_model->getAll('feu_sexual_preference',array('user_id'=>$user['user_id']));
			$content_data['userParticipation'] = $this->common_model->getAllMultipleJoin('shop_booking_details',array('is_booking'=>1,'payed'=>0,'shop_carts.user_id'=>$user['user_id']),array(array('shop_carts','shop_carts.id = shop_booking_details.cart_id'),array('shop_orders','shop_orders.cart_id = shop_carts.id'),array('evt_events','evt_events.id = shop_booking_details.event_id')),'shop_orders.created','','shop_booking_details.cart_id');
			$content_data['latestMembers'] = $this->common_model->getAllMultipleJoin('feu_userdetails',array('avatar_file_id >'=>0,'feu_userdetails.user_id !='=>$this->session->userdata('user_id'),'filename !='=>''),array(array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'RAND()','','',0,8);
			$content_data['comments'] = $this->common_model->getAllMultipleJoin('feu_userdetails',array('alias_path'=>'community/profil/'.$user['alias']),array(array('sys_files','sys_files.id = feu_userdetails.avatar_file_id'),array('cmt_comments','cmt_comments.user_id = feu_userdetails.user_id')),'cmt_comments.created DESC','*,cmt_comments.created,cmt_comments.id','',0,8);
			$content_data['friend'] = $this->common_model->getAllRowMultipleJoin('feu_relationships',array('user_id_1'=>$this->session->userdata('user_id'),'user_id_2'=>$user['user_id'],'type'=>'friend'));
			$content_data['unfriend'] = $this->common_model->getAllRowMultipleJoin('feu_relationships',array('user_id_2'=>$this->session->userdata(