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

class Home extends CI_Controller
{
	public function __construct()
	{ 
		parent:: __construct();
		$this->load->model('common_model');
		if(get_cookie('user_id'))
		{
			$this->session->set_userdata('user_id',get_cookie('user_id'));
		}
		$this->load->library('Mobile_detect');
		$this->load->helper('text');
		avatarCron();
	}
	public function index()
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
			if($this->session->userdata('user_id'))
			{
				$this->common_model->UpdateData('feu_userdetails',array('userlanguage'=>$langId),array('user_id'=>$this->session->userdata('user_id')));
				//echo $this->db->last_query(); die;
			}
		}
		$content_data['latestUsers'] = $this->common_model->getAll('feu_userdetails',array('avatar_file_id >'=>0,'filename !='=>''),array('sys_files','feu_userdetails.avatar_file_id = sys_files.id'),'feu_userdetails.created DESC','','',0,5);
		$content_data['mediaLogos'] = $this->common_model->getAllMultipleJoin('b_article',array('b_article.staus'=>1,'b_category.status'=>1,'b_gallery.status'=>1,'logo_path !='=>'','is_home'=>1,'b_article_lang_values.lang_id'=>$langId),array(array('b_article_lang_values','b_article_lang_values.blog_id = b_article.blog_id'),array('b_category','b_category.cat_id = b_article.cat_id'),array('b_gallery','b_gallery.b_article_id = b_article.blog_id')),'display_order ASC','','b_gallery.b_article_id');
		$content_data['adverts'] = $data['adverts'] = $this->common_model->getAllMultipleJoin('adverts',array('visible'=>1,'lang_id'=>$langId),array(array('adverts_lang_values','adverts_lang_values.adverts_id = adverts.id')),'display_order ASC');
		$data['nextParty'] = $this->common_model->getAllRowMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>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_language_values.title as title','id') ;
		$content_data['nextParty'] = $data['nextParty'];
		$content_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) ;
		$content_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(empty($data['upcomingEvents']))
		{
			$content_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']))
		{
			$content_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) ;
		}
		//print_r($data['lastEvents']); die;
		$data['checkinEvents'] = array();
		if($this->session->userdata('user_id'))
		{
			$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$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');
		}

		$newsletterUsers = $this->common_model->getAll('newsletter_couple_lady','','','RAND()',0,1);
		
		$main_arr = array();
		$lady = array();
		if(count($newsletterUsers)>0)
		{
			foreach($newsletterUsers as $key=>$val)
			{
				if(!in_array($val['id'], $data))
				{	
					$lady = $this->common_model->getAllRowMultipleJoin('newsletter_couple_lady',array('newsletter_couple_lady.id'=>$val['id']),array(array('feu_userdetails','feu_userdetails.user_id = newsletter_couple_lady.lady'),array('feu_countries','feu_userdetails.country = feu_countries.country_code'),array('sys_files','feu_userdetails.avatar_file_id = sys_files.id')));
					if(count($lady)>0)
					{
						if($lady['user_id']>0)
						{
							array_push($main_arr, $lady);
						}
					}
				}
			}
		}
		else
		{
			array_push($main_arr, $castleevents);
		}
		$content_data['main_arr'] = $main_arr;


		$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['content'] = $this->load->view('index', $content_data, TRUE);
		$page_meta = $this->common_model->getAllRow('page_meta',array('page_name'=>'Home','lang_id'=>$langId));
		$data['title'] = getLang('The_Worlds_Leading_Eyes');

		//If Cookie or Session exist, but user deleted
		if($this->session->userdata('user_id'))
		{
			$usr_users = $this->common_model->getAllRow('usr_users',array('id'=>$this->session->userdata('user_id')));
			$feu_userdetails = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$this->session->userdata('user_id')));

			if(!$usr_users && !$feu_userdetails){
				redirect('profile/logout');
			}
		}

		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'] = 'Home';
		}
		
		$this->load->view('template', $data);
	}
	public function changelanguage()
	{
		$langId = $this->input->post('lang'); 
		$requestURL = $this->input->post('requestURL');
		$cookie = array(
		        'name'   => 'lang',
		        'value'  => $langId,
		        'expire' => time()+86500,
		        );
		 
		set_cookie($cookie);
		if($this->session->userdata('user_id'))
		{
			$this->common_model->UpdateData('feu_userdetails',array('userlanguage'=>$langId),array('user_id'=>$this->session->userdata('user_id')));
			//echo $this->db->last_query(); die;
		}
		
		redirect(base_url().$requestURL);
	}
	public function acceptterms()
	{
		if($this->session->userdata('user_id'))
		{
			$this->common_model->UpdateData('feu_userdetails',array('accept_terms'=>1,'accept_date'=>time()),array('user_id'=>$this->session->userdata('user_id')));
			//echo $this->db->last_query(); die;
		}
		redirect(base_url().'profile');
	}
	public function acceptcookie($url='')
	{
		$cookie = array(
		        'name'   => 'site_cookie',
		        'value'  => 1,
		        'expire' => time()+(10 * 365 * 24 * 60 * 60),
		        );
		 
		set_cookie($cookie);
		echo 1; exit;
	}
	public function login()
	{
		if($this->input->post())
		{
			$this->form_validation->set_rules('email','Email','trim|required');
			$this->form_validation->set_rules('password','Password','required');
			$captcha_response = $this->utility->info_cleanQuery(trim($this->input->post('g-recaptcha-response')));
			if($captcha_response != '')
			{
				$keySecret = RECAPTCHA_SECRET_KEY;
				$check = array(
					'secret'		=>	$keySecret,
					'response'		=>	$captcha_response
				);
				$startProcess = curl_init();
				curl_setopt($startProcess, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
				curl_setopt($startProcess, CURLOPT_POST, true);
				curl_setopt($startProcess, CURLOPT_POSTFIELDS, http_build_query($check));
				curl_setopt($startProcess, CURLOPT_SSL_VERIFYPEER, false);
				curl_setopt($startProcess, CURLOPT_RETURNTRANSFER, true);
				$receiveData = curl_exec($startProcess);
				$finalResponse = json_decode($receiveData, true);
				if($finalResponse['success'])
				{
					if($this->form_validation->run())
					{
						$emailExist = $this->common_model->getAllRow('usr_users',array('email'=>$this->utility->info_cleanQuery($this->input->post('email'))));
						$usernameExist = $this->common_model->getAllRow('feu_userdetails',array('username'=>$this->utility->info_cleanQuery($this->input->post('email'))));
						if(empty($emailExist) && !empty($usernameExist))
						{
							$emailExist = $this->common_model->getAllRow('usr_users',array('id'=>$usernameExist['user_id']));
						}
						if(!empty($emailExist))
						{
							$inputPassword  = $this->common_model->generateHash($this->utility->info_cleanQuery($this->input->post('password')));
							$password  = $emailExist['password'];
							
							if($inputPassword == $password )
							{
								if($emailExist['email_confirmed']==1)
								{
									if($emailExist['status']==0)
									{
										$this->session->set_userdata('error_msg',getLang('Your_account_is_blocked'));
										redirect(base_url());
									}
									$this->session->set_userdata('user_id',$emailExist['id']);
									$cookie = array(
									        'name'   => 'user_id',
									        'value'  => $emailExist['id'],
									        'expire' => time()+86500,
									        );
									 
									set_cookie($cookie);
									//$this->common_model->UpdateData('usr_users',array('last_login'=>time()),array('id'=>$emailExist['id']));
									$qry = $this->db->query('select * from (select * from (SELECT shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus` FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a ORDER BY a.user_id DESC) as b where case when time = 365 then b.created <('.time().' - (365 * 86400)) when time = 182 then b.created <('.time().' - (182 * 86400)) end AND article_id in (5,4) and user_id = '.$emailExist['id'].' order by b.created DESC');
							        //echo $this->db->last_query(); die;
							        $getUserListData = $qry->row_array();

							        $activeqry = $this->db->query('select * from (select * from (SELECT shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus` FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a ORDER BY a.user_id DESC) as b where case when time = 365 then b.created >('.time().' - (365 * 86400)) when time = 182 then b.created >('.time().' - (182 * 86400)) end AND article_id in (5,4) and user_id = '.$emailExist['id'].' order by b.created DESC');
							        //echo $this->db->last_query(); die;
							        $activegetUserListData = $activeqry->row_array();
							        $step = $this->common_model->getAllRow('feu_user_steps',array('user_id'=>$emailExist['id']));
							        //print_r($getUserListData);die;
							        //print_r($activegetUserListData);die;
							        /*****************FREE MEMBERSHIP**********************/
							        $userData = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$this->session->userdata('user_id')));
							        
							        $order_to_reminder = $this->common_model->getAllRowMultipleJoin('order_to_reminder',array('order_to_reminder.user_id'=>$emailExist['id'],'payed'=>0,'time_from >'=>time()),array(array('shop_orders','shop_orders.order_id = order_to_reminder.order_id'),array('evt_events','evt_events.id = order_to_reminder.event_id')),'count(*) DESC,event_id DESC','count(*) as total','order_to_reminder.order_id');
							        if($userData['free_member']==1 && $userData['accounttype']=='lady')
							        {
							        	$free_image = $this->common_model->getAll('sys_files',array('filename !='=>'','free_membership_image'=>1,'accepted'=>1,'ugal_images.user_id'=>$this->session->userdata('user_id')),array('ugal_images','ugal_images.file_id = sys_files.id'),'sys_files.created DESC','*,sys_files.created,sys_files.id');
							        	if(count($free_image)>=3)
							        	{
							        		$this->common_model->UpdateData('feu_userdetails',array('online_status'=>1),array('user_id'=>$this->session->userdata('user_id')));
							        		$this->common_model->UpdateData('usr_users',array('last_login'=>time(),'login_time'=>time(),'reminder_mail_send'=>1),array('id'=>$this->session->userdata('user_id')));
							        		$this->common_model->insertData('usr_log',array('log_time'=>time(),'user_id'=>$this->session->userdata('user_id'),'type'=>1));
							        		$this->common_model->deleteData('feu_user_steps',array('user_id'=>$this->session->userdata('user_id')));
							        		if($order_to_reminder)
							        		{
							        			if($order_to_reminder['total']>=4)
							        			{
							        				$this->session->set_userdata('pay_book_first',1);
							        				redirect(base_url().'invoice');
							        			}
							        			else
							        			{
							        				redirect(base_url().'profile');
							        			}
							        		}
							        		else
							        		{
							        			redirect(base_url().'profile');
							        		}
							        	}
							        	else
							        	{
							        		$this->common_model->UpdateData('feu_userdetails',array('online_status'=>1),array('user_id'=>$this->session->userdata('user_id')));
							        		$this->common_model->UpdateData('usr_users',array('last_login'=>time(),'login_time'=>time(),'reminder_mail_send'=>1),array('id'=>$this->session->userdata('user_id')));
							        		$this->common_model->insertData('usr_log',array('log_time'=>time(),'user_id'=>$this->session->userdata('user_id'),'type'=>1));
							        		redirect(base_url().'profile');
							        	}
							        }
							        /*****************FREE MEMBERSHIP**********************/
							        elseif (count($activegetUserListData)>0) {
							        	$this->common_model->UpdateData('feu_userdetails',array('online_status'=>1),array('user_id'=>$this->session->userdata('user_id')));
							        	$this->common_model->UpdateData('usr_users',array('last_login'=>time(),'login_time'=>time(),'reminder_mail_send'=>1),array('id'=>$this->session->userdata('user_id')));
							        	$this->common_model->insertData('usr_log',array('log_time'=>time(),'user_id'=>$this->session->userdata('user_id'),'type'=>1));
							        	$this->common_model->deleteData('feu_user_steps',array('user_id'=>$this->session->userdata('user_id')));
							        	if($order_to_reminder)
						        		{
						        			if($order_to_reminder['total']>=4)
						        			{
						        				$this->session->set_userdata('pay_book_first',1);
						        				redirect(base_url().'invoice');
						        			}
						        			else
						        			{
						        				redirect(base_url().'profile');
						        			}
						        		}
						        		else
						        		{
						        			redirect(base_url().'profile');
						        		}
							        }
							        elseif(count($getUserListData)>0)
							        {
							        	$time = $getUserListData['created']+($getUserListData['time']*86400);
							        	$this->session->set_userdata('member_msg',getLang('Expired').' '.date('d.m.Y',$time).', '.getLang('please_re_activate_your'));
							        	if(count($step)==0)
							        	{
							        		$update = $this->common_model->insertData('feu_user_steps',array('user_id'=>$this->session->userdata('user_id'),'step'=>6,'created'=>time()));
							        		$this->common_model->UpdateData('feu_userdetails',array('online_status'=>1),array('user_id'=>$this->session->userdata('user_id')));
							        		$this->common_model->UpdateData('usr_users',array('last_login'=>time(),'login_time'=>time(),'reminder_mail_send'=>1),array('id'=>$this->session->userdata('user_id')));
							        		$this->common_model->insertData('usr_log',array('log_time'=>time(),'user_id'=>$this->session->userdata('user_id'),'type'=>1));
							        		redirect(base_url().'profile');
							        	}
							        	else
							        	{
							        		$this->common_model->UpdateData('feu_userdetails',array('online_status'=>1),array('user_id'=>$this->session->userdata('user_id')));
							        		$this->common_model->UpdateData('usr_users',array('last_login'=>time(),'login_time'=>time(),'reminder_mail_send'=>1),array('id'=>$this->session->userdata('user_id')));
							        		$this->common_model->insertData('usr_log',array('log_time'=>time(),'user_id'=>$this->session->userdata('user_id'),'type'=>1));
							        		redirect(base_url().'profile');
							        	}
							        }
							        else
							        {
							        	if(count($step)==0)
							        	{
							        		$update = $this->common_model->insertData('feu_user_steps',array('user_id'=>$this->session->userdata('user_id'),'step'=>6,'created'=>time()));
							        		$this->common_model->UpdateData('feu_userdetails',array('online_status'=>1),array('user_id'=>$this->session->userdata('user_id')));
							        		$this->common_model->UpdateData('usr_users',array('last_login'=>time(),'login_time'=>time(),'reminder_mail_send'=>1),array('id'=>$this->session->userdata('user_id')));
							        		redirect(base_url().'profile');
							        	}
							        	else
							        	{
							        		$this->common_model->UpdateData('feu_userdetails',array('online_status'=>1),array('user_id'=>$this->session->userdata('user_id')));
							        		$this->common_model->UpdateData('usr_users',array('last_login'=>time(),'login_time'=>time(),'reminder_mail_send'=>1),array('id'=>$this->session->userdata('user_id')));
							        		redirect(base_url().'profile');
							        	}
							        	//redirect(base_url().'profile');
							        }
								}
								else
								{
									$this->session->set_userdata('error_msg',getLang('Please_verify_your_email'));
									redirect(base_url());
								}
							}
							else
							{
								$this->session->set_userdata('error_msg',getLang('Invalid_password'));
								redirect(base_url());
							}
						}
						else
						{
							$this->session->set_userdata('error_msg',getLang('Invalid_email'));
							redirect(base_url());
						}
					}
					else{
						$this->session->set_userdata('error_msg',validation_errors());
						redirect(base_url());
					}
				} else {
					$this->session->set_userdata('error_msg',getLang('Please_complete_CAPTCHA_authentication'));
					redirect(base_url());
				}
			} else {
				$this->session->set_userdata('error_msg',getLang('Please_complete_CAPTCHA_authentication'));
				redirect(base_url());
			}
		}
		else
		{
			redirect(base_url());
		}
	}
	public function checkAvailability()
	{ 
		$username = $this->utility->info_cleanQuery(trim($this->input->post('regusername')));
		//var_dump($username);
		if($username!='')
		{
			$existUsername = $this->common_model->getAll('feu_userdetails',array('username'=>$username));
			if(!empty($existUsername))
			{
				echo 1;
			}
			else
			{
				echo 2;
			}
		}
		else
		{
			echo 3;
		}
		exit;
	}
	public function registration()
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$username = $this->utility->info_cleanQuery(trim($this->input->post('regusername')));
		$email = $this->utility->info_cleanQuery($this->input->post('regemail'));
		$password = $this->input->post('regpassword');
		$accounttype = $this->input->post('accounttype');
		$captcha_response = $this->utility->info_cleanQuery(trim($this->input->post('g-recaptcha-response')));
		if($captcha_response != '')
		{
			$keySecret = RECAPTCHA_SECRET_KEY;
			$check = array(
				'secret'		=>	$keySecret,
				'response'		=>	$captcha_response
			);
			$startProcess = curl_init();
			curl_setopt($startProcess, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
			curl_setopt($startProcess, CURLOPT_POST, true);
			curl_setopt($startProcess, CURLOPT_POSTFIELDS, http_build_query($check));
			curl_setopt($startProcess, CURLOPT_SSL_VERIFYPEER, false);
			curl_setopt($startProcess, CURLOPT_RETURNTRANSFER, true);
			$receiveData = curl_exec($startProcess);
			$finalResponse = json_decode($receiveData, true);
			if($finalResponse['success'])
			{
				if($username=='' || $email=='' || $password==''){
					echo 4;exit;
				}
				$existEmail = $this->common_model->getAll('usr_users',array('email'=>$email));
				//print_r($existEmail); die;
				if(!empty($existEmail))
				{
					echo 2;exit;
				}
				else
				{
					$inputPassword  = $this->common_model->generateHash($this->utility->info_cleanQuery($password));
					$isGoogle = 0;
					$campaign_id = '';
					if($this->session->userdata('google'))
					{
						$isGoogle = 1;
						$campaign_id = $this->session->userdata('google');
						$this->session->unset_userdata('google');
					}
					if($this->session->userdata('facebook'))
					{
						$isGoogle = 2;
						//$campaign_id = $this->session->userdata('facebook');
						$this->session->unset_userdata('facebook');
					}
					$con = array(
							'email'=>$email,
							'password'=>$inputPassword,
							'created'=>time(),
							'email_confirmed'=>0,
							'came_from'=>$isGoogle,
							'campaign_id'=>$campaign_id,
							'ip_address'=>$this->input->ip_address(),
							'monthly_summary_send_date'=>date('Y-m-d')
						);
					$userId = $this->common_model->insertData('usr_users',$con);
					
					$conArr = array(
							'username'=>$username,
							'alias'=>strtolower(preg_replace('/[^A-Za-z0-9\-]/', '', str_replace(' ', '-', $this->input->post('regusername')))),
							'accounttype'=>$accounttype,
							'userlanguage'=>$langId,
							'created'=>time(),
							'user_id'=>$userId,
							'visitor_mail'=>1,
							'accept_terms'=>1,
							'accept_date'=>time()
						);
					$this->common_model->insertData('feu_userdetails',$conArr);
					$stepArr = array(
							'step'=>1,
							'created'=>time(),
							'user_id'=>$userId
						);
					$this->common_model->insertData('feu_user_steps',$stepArr);

					/*****************INSERT AS GUEST WITH ADMIN****************/
					$adminDetails = $this->common_model->getAllRowMultipleJoin('usr_users',array('email'=>'info@castleevents.com'),array(array('feu_userdetails','feu_userdetails.user_id = usr_users.id')));
					//print_r($adminDetails); die;
					if(!empty($adminDetails))
					{
						$this->common_model->insertData('feu_relationships',array('user_id_1'=>$userId,'user_id_2'=>$adminDetails['user_id'],'created'=>time(),'type'=>'guest','status'=>'guest'));
						$text='<p>Hello '.strtoupper($username).'</p><p></p>';
						$text.='<p>welcome to the castleevents community. </p>';
						$text.='<p>Thank you very much for your registration. </p>';
						$text.='<p>If you have any questions please don’t hesitate to contact us.</p>';
						$text.='<p>We will answer all your questions as soon as possible.</p><p></p>';
						$text.='<p>Kind regards,</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'=>$userId,'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));
						$this->common_model->insertData('notification',array('from_id'=>$adminDetails['user_id'],'to_id'=>$userId,'type'=>4,'created'=>time()));
					}
					
					/*****************INSERT AS GUEST WITH ADMIN****************/

					$to = $email;
					$sub = getLang('Confirm_your_registration_at').' Castleevents';
			        $body=' <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">'.$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('Thank_you_for_your_registration').'.
				                                   </p>
				                                   <br>
				                                   <p>'.getLang('Your_confirmation_URL').': <a href="'.base_url().'home/validate/'.base64_encode($userId).'" style="color:#b3975b">'.getLang('Click_here_to_verify').'</a></p>
				                                   <p style=" color: #c1c1c1; font-size: 14px; line-height: 16px; padding-bottom: 10px; margin: 0 0 60px; font-family: Arial, Helvetica, sans-serif;">'.base_url().'home/validate/'.base64_encode($userId).'</p>
				                                </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,$body);
					$this->utility->sendMandrillCIMail($to,$sub,$body);
					echo 3;exit;
				}
			} else {
				echo 5; exit;
			}
		} else {
			echo 5; exit;
		}
	}
	public function validate($encId = '')
	{
		$userId= base64_decode($encId);
		$this->common_model->UpdateData('usr_users',array('email_confirmed'=>1),array('id'=>$userId));
		$userData = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$userId));
		if(!empty($userData))
		{
			$this->session->set_userdata('success_pop',$userData['username']);
		}
		redirect(base_url());
	}
	public function contact()
	{
		//$to = 'andrej@castleevents.com';
		//$to = 'testdevloper007@gmail.com';
		$to = 'info@castleevents.com';
		$sub = 'Castleevents '.getLang('contact_mail');
		$body=' <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">Castleevents</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('A_member_contact_for_some_query').'.
	                                      <br/>
	                                      <strong>'.getLang('Member_Details').':</strong>
	                                      <br/>
	                                      <span style="color:#b3975b">'.getLang('Email').':</span> '.$this->input->post('contactEmail').'
	                                      <br/>
	                                      <span style="color:#b3975b">'.getLang('Message').':</span> '.$this->input->post('message').'
	                                   </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>';
		$mail_send = $this->utility->sendCIMail($to,$sub,$body);
		echo $mail_send;exit;
	}
	public function page($alias = '')
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$pageData = $this->common_model->getAllRow('cms_page',array('alias'=>$alias,'language_id'=>$langId));
		if(!empty($pageData))
		{
			$content_data['testimonials'] = array();
			if($alias=='testimonial')
			{
				$content_data['testimonials'] = $this->common_model->getAllMultipleJoin('testimonials',array('status'=>1),'','display_order ASC');
			}
			
			$content_data['cmsSectionDetails'] = $this->common_model->getAllMultipleJoin('cms_page_content',array('cms_page_content.page_id'=>$pageData['id']),array(array('sys_files','sys_files.id = cms_page_content.content_image_id')),'cms_page_content.id ASC','cms_page_content.*, sys_files.filename,sys_files.path,sys_files.extension ') ;
			$content_data['cmsDetails'] = $this->common_model->getAllRowMultipleJoin('cms_page',array('cms_page.id'=>$pageData['id']),array(array('sys_languages','cms_page.language_id = sys_languages.id'),array('sys_files','sys_files.id = cms_page.image_id')),'','sys_languages.name as lang_name,cms_page.*,sys_files.path,sys_files.filename,sys_files.extension') ;
			$content_data['latestUsers'] = $this->common_model->getAll('feu_userdetails',array('avatar_file_id >'=>0,'id >'=>1),array('sys_files','feu_userdetails.avatar_file_id = sys_files.id'),'feu_userdetails.created DESC','','',0,5);
			$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			if(empty($data['upcomingEvents']))
			{
				$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			}
			if(empty($data['lastEvents']))
			{
				$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			}
			$data['content'] = $this->load->view('cms', $content_data, TRUE);
			$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
			$data['checkinEvents'] = array();
			if($this->session->userdata('user_id'))
			{
				$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$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');
			}
			$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');
			$section = '';
            if($pageData['section_id']==1)
            {
              $section = getLang('Insights');
            }
            elseif($pageData['section_id']==2)
            {
              $section = getLang('Community');
            }
            elseif($pageData['section_id']==3)
            {
              $section = getLang('Shop');
            }
            else
            {
              $section = getLang('About_Us');
            }
			$data['title'] = "Castleevents - ".$section." - ".$pageData['title'];
			$data['meta_title'] = $pageData['meta_title'];
			$data['meta_description'] = $pageData['meta_desc'];
			$data['meta_keywords'] = $pageData['meta_keywords'];
			$data['meta_genre'] = 'CMS page';
			$this->load->view('template', $data);
		}
		else
		{
			redirect(base_url());
		}
	}
	public function shop()
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$content_data['shopDetails'] = $this->common_model->getAllMultipleJoin('shop',array('lang_id'=>$langId,'is_default'=>1),array(array('shop_images','shop.id = shop_images.shop_id'),array('shop_lang_values','shop.id = shop_lang_values.shop_id')),'display_order ASC','*,shop.id as shop_id');
		$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		if(empty($data['upcomingEvents']))
		{
			$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		}
		if(empty($data['lastEvents']))
		{
			$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		}
		$data['content'] = $this->load->view('shop', $content_data, TRUE);
		$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
		$data['checkinEvents'] = array();
		if($this->session->userdata('user_id'))
		{
			$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$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');
		}
		$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');
		$section = getLang('Shop');
        $data['title'] = "Castleevents - ".$section." - ".getLang('book');
		$data['meta_title'] = "Castleevents - ".$section." - ".getLang('book');
		$data['meta_description'] = "Castleevents - ".$section." - ".getLang('book');
		$data['meta_keywords'] = $section.','.getLang('book');
		$data['meta_genre'] = 'Shop';
		$this->load->view('template', $data);
	}
	public function shopDetails($alias = '')
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$content_data['shopDetails'] = $this->common_model->getAllRowMultipleJoin('shop',array('alias'=>$alias),array(array('shop_lang_values','shop.id = shop_lang_values.shop_id')),'display_order ASC','*,shop.id as shop_id');
		//echo $this->db->last_query(); die;
		if(count($content_data['shopDetails'])>0)
		{
			$content_data['shopImages'] = $this->common_model->getAllMultipleJoin('shop_images',array('shop_id'=>$content_data['shopDetails']['shop_id']),'','id ASC');
			$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			if(empty($data['upcomingEvents']))
			{
				$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			}
			if(empty($data['lastEvents']))
			{
				$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			}
			$data['content'] = $this->load->view('shopDetails', $content_data, TRUE);
			$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
			$data['checkinEvents'] = array();
			if($this->session->userdata('user_id'))
			{
				$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$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');
			}
			$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');
			$section = getLang('Shop');
	        $data['title'] = $content_data['shopDetails']['title'];
			$data['meta_title'] = $content_data['shopDetails']['meta_title'];
			$data['meta_description'] = $content_data['shopDetails']['meta_desc'];
			$data['meta_keywords'] = $content_data['shopDetails']['meta_title'];
			$data['meta_genre'] = 'Shop details';
			$this->load->view('template', $data);
		}
		else{
			redirect(base_url());
		}
	}
	public function forgetPassword()
	{
		$captcha_response = $this->utility->info_cleanQuery(trim($this->input->post('g-recaptcha-response')));
		if($captcha_response != '')
		{
			$keySecret = RECAPTCHA_SECRET_KEY;
			$check = array(
				'secret'		=>	$keySecret,
				'response'		=>	$captcha_response
			);
			$startProcess = curl_init();
			curl_setopt($startProcess, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
			curl_setopt($startProcess, CURLOPT_POST, true);
			curl_setopt($startProcess, CURLOPT_POSTFIELDS, http_build_query($check));
			curl_setopt($startProcess, CURLOPT_SSL_VERIFYPEER, false);
			curl_setopt($startProcess, CURLOPT_RETURNTRANSFER, true);
			$receiveData = curl_exec($startProcess);
			$finalResponse = json_decode($receiveData, true);
			if($finalResponse['success'])
			{
				$userexist = $this->common_model->getAllRow('usr_users',array('email'=>$this->utility->info_cleanQuery($this->input->post('forgetEmail'))));
				
				if(empty($userexist))
				{
					echo getLang('You_are_not_a_registered_member');exit;
				}
				else
				{
					$userDetails = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$userexist['id']));
					$newpassword = $this->utility->passwordGenaretor();
					$updatePassword = $this->common_model->generateHash($newpassword);
					$this->common_model->UpdateData('usr_users',array('password'=>$updatePassword,'email_confirmed'=>1),array('id'=>$userexist['id']));
					
					$to = $this->input->post('forgetEmail');
					$sub = 'Castleevents '.getLang('Password_Recovery');
					
					$body=' <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">'.$userDetails['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>
			                                      <p>'.getLang('You_have_requested_a_new_password').'.</p>
			                                   </p>
											   <p>'.getLang('Your_new_password_is').' : '.$newpassword.'</p><p>'.getLang('We_recommend_that_you_log_in').'.</p>
			                                  
			                                </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;  	
					$mail_send = $this->utility->sendCIMail($to,$sub,$body);
					echo 1;
					exit;
				}
			} else {
				echo getLang('Please_complete_CAPTCHA_authentication');exit;
			}
		} else {
			echo getLang('Please_complete_CAPTCHA_authentication');exit;
		}
	}
	public function media()
	{
		$langId = 2;
		/*if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}*/
		$content_data['mediaDetails'] = $this->common_model->getAllMultipleJoin('blog_articles',array('blog_articles.visible'=>1),array(array('sys_files','sys_files.id = blog_articles.image_id')),'sort ASC','blog_articles.*, sys_files.filename,sys_files.path,sys_files.extension ') ;
		$content_data['latestUsers'] = $this->common_model->getAll('feu_userdetails',array('avatar_file_id >'=>0,'id >'=>1),array('sys_files','feu_userdetails.avatar_file_id = sys_files.id'),'feu_userdetails.created DESC','','',0,5);
		$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>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,3) ;
		$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>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,'visible'=>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,3) ;
		}
		if(empty($data['lastEvents']))
		{
			$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>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['content'] = $this->load->view('media', $content_data, TRUE);
		$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
		$data['checkinEvents'] = array();
		$data['checkinEvents'] = array();
		if($this->session->userdata('user_id'))
		{
			$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$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');
		}
		$data['cms_pages_1'] = $this->common_model->getAllMultipleJoin('cms_page',array('section_id'=>1,'language_id'=>2),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'=>2),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'=>2),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'=>2),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('Media');
		$this->load->view('template', $data);
	}
	public function medias($alias = '')
	{
		$langId = 2;
		/*if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}*/
		$pageData = $this->common_model->getAllRow('blog_articles',array('alias'=>$alias,'language_id'=>$langId));
		if(!empty($pageData))
		{
			$content_data['contentDetails'] = $this->common_model->getAllRowMultipleJoin('blog_articles',array('id'=>$pageData['id']),array(array('sys_languages','blog_articles.lang_id = sys_languages.id'))) ;
			$content_data['latestUsers'] = $this->common_model->getAll('feu_userdetails',array('avatar_file_id >'=>0,'id >'=>1),array('sys_files','feu_userdetails.avatar_file_id = sys_files.id'),'feu_userdetails.created DESC','','',0,5);
			$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>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,4) ;
			$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>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,'visible'=>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,4) ;
			}
			if(empty($data['lastEvents']))
			{
				$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>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['content'] = $this->load->view('media_details', $content_data, TRUE);
			$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
			$data['checkinEvents'] = array();
			$data['checkinEvents'] = array();
			if($this->session->userdata('user_id'))
			{
				$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$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');
			}
			$data['cms_pages_1'] = $this->common_model->getAllMultipleJoin('cms_page',array('section_id'=>1,'language_id'=>2),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'=>2),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'=>2),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'=>2),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('Media_Details');
			$this->load->view('template', $data);
		}
		else
		{
			redirect(base_url());
		}
	}
	public function news($slug='')
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$content_data['categorylist'] = $this->common_model->getAll('b_category',array('b_category.status'=>1,'b_category_lang_values.lang_id'=>$langId),array('b_category_lang_values','b_category_lang_values.cat_id = b_category.cat_id'),'b_category_lang_values.cat_name ASC','b_category_lang_values.cat_name,cat_slug') ; 	
		
		if($slug=='')
		{
			$content_data['articles'] = $this->common_model->getAllMultipleJoin('b_article',array('b_article.staus'=>1,'b_category.status'=>1,'b_article_lang_values.lang_id'=>$langId),array(array('b_article_lang_values','b_article_lang_values.blog_id = b_article.blog_id'),array('b_category','b_category.cat_id = b_article.cat_id'),array('b_category_lang_values','b_category_lang_values.cat_id = b_category.cat_id'),array('b_gallery','b_gallery.b_article_id = b_article.blog_id','left')),'display_order ASC','','b_gallery.b_article_id');
		}
		else
		{
			$content_data['articles'] = $this->common_model->getAllMultipleJoin('b_article',array('b_article.staus'=>1,'b_category.status'=>1,'b_article_lang_values.lang_id'=>$langId,'cat_slug'=>$slug),array(array('b_article_lang_values','b_article_lang_values.blog_id = b_article.blog_id'),array('b_category','b_category.cat_id = b_article.cat_id'),array('b_category_lang_values','b_category_lang_values.cat_id = b_category.cat_id'),array('b_gallery','b_gallery.b_article_id = b_article.blog_id','left')),'display_order ASC','','b_gallery.b_article_id');
		}
		$data['meta_title'] = (!empty($content_data['articles']))?$content_data['articles'][0]['cat_name']:'';
		$data['meta_description'] = (!empty($content_data['articles']))?$content_data['articles'][0]['cat_name']:'';
		$data['meta_keywords'] = (!empty($content_data['articles']))?$content_data['articles'][0]['cat_name']:'';
		$data['meta_genre'] = 'Blog posting';
		//echo $this->db->last_query();die;
		$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		if(empty($data['upcomingEvents']))
		{
			$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		}
		if(empty($data['lastEvents']))
		{
			$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		}
		$data['content'] = $this->load->view('blog_list', $content_data, TRUE);
		$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
		$data['checkinEvents'] = array();
		$data['checkinEvents'] = array();
		if($this->session->userdata('user_id'))
		{
			$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$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');
		}
		$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('News').' '.$slug;
		$this->load->view('template', $data);
	}
	public function news_details($slug = '')
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$content_data['categorylist'] = $this->common_model->getAll('b_category',array('b_category.status'=>1,'b_category_lang_values.lang_id'=>$langId),array('b_category_lang_values','b_category_lang_values.cat_id = b_category.cat_id'),'b_category_lang_values.cat_name ASC','b_category_lang_values.cat_name,cat_slug') ; 	
		
		$content_data['articles'] = $this->common_model->getAllMultipleJoin('b_article',array('b_article.staus'=>1,'b_category.status'=>1,'blog_slug'=>$slug,'b_article_lang_values.lang_id'=>$langId),array(array('b_article_lang_values','b_article_lang_values.blog_id = b_article.blog_id'),array('b_category','b_category.cat_id = b_article.cat_id'),array('b_gallery','b_gallery.b_article_id = b_article.blog_id','left')),'b_article.blog_title ASC');
		$content_data['other_articles'] = $this->common_model->getAllMultipleJoin('b_article',array('b_article.staus'=>1,'b_category.status'=>1,'b_article_lang_values.lang_id'=>$langId),array(array('b_article_lang_values','b_article_lang_values.blog_id = b_article.blog_id'),array('b_category','b_category.cat_id = b_article.cat_id'),array('b_category_lang_values','b_category_lang_values.cat_id = b_category.cat_id'),array('b_gallery','b_gallery.b_article_id = b_article.blog_id','left')),'create_date DESC','','b_gallery.b_article_id');
		$data['meta_title'] = (!empty($content_data['articles']))?$content_data['articles'][0]['meta_tag']:'';
		$data['meta_description'] = (!empty($content_data['articles']))?html_entity_decode(strip_tags($content_data['articles'][0]['meta_description'])):'';
		$data['meta_keywords'] = (!empty($content_data['articles']))?$content_data['articles'][0]['meta_keywords']:'';
		$data['meta_genre'] = 'Blog details';
		//print_r($content_data); print_r($data); die;
		if(!empty($content_data['articles']))
		{
			$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			if(empty($data['upcomingEvents']))
			{
				$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			}
			if(empty($data['lastEvents']))
			{
				$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			}
			$data['content'] = $this->load->view('blog_details', $content_data, TRUE);
			$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
			$data['checkinEvents'] = array();
			$data['checkinEvents'] = array();
			if($this->session->userdata('user_id'))
			{
				$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$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');
			}
			$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('News_Details')." - ".$content_data['articles'][0]['blog_title'];
			$this->load->view('template', $data);
		}
		else
		{
			redirect(base_url());
		}
	}
	public function terms()
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$content_data['std_content'] = $this->common_model->getAllRow('std_contents',array('lang_id'=>$langId));
		$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) ;
		//print_r();die;
		if(empty($data['upcomingEvents']))
		{
			$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		}
		if(empty($data['lastEvents']))
		{
			$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		}
		$data['content'] = $this->load->view('terms', $content_data, TRUE);
		$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
		$data['checkinEvents'] = array();
		$data['checkinEvents'] = array();
		if($this->session->userdata('user_id'))
		{
			$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$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');
		}
		$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('Terms_and_conditions');
		$page_meta = $this->common_model->getAllRow('page_meta',array('page_name'=>'Terms','lang_id'=>$langId));
		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'] = 'Terms and conditions';
		}
		$this->load->view('template', $data);
	}
	public function privacy()
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$content_data['content'] = $this->common_model->getAllRow('privacy_policy',array('lang_id'=>$langId));
		if($content_data['content']['content']=='')
		{
			$content_data['content'] = $this->common_model->getAllRow('privacy_policy',array('lang_id'=>2));
		}
		$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) ;
		//print_r();die;
		if(empty($data['upcomingEvents']))
		{
			$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		}
		if(empty($data['lastEvents']))
		{
			$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		}
		$data['content'] = $this->load->view('privacy', $content_data, TRUE);
		$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
		$data['checkinEvents'] = array();
		$data['checkinEvents'] = array();
		if($this->session->userdata('user_id'))
		{
			$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$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');
		}
		$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('Privat_Policy');
		$this->load->view('template', $data);
	}
	public function feedback()
	{
		$out = $this->common_model->getAll('testimonials');
		$name = $this->utility->info_cleanQuery($_POST['feedbackUsername']);
		$feedback = $this->utility->info_cleanQuery($_POST['feedback']);
		$feedback = preg_replace('/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i','',$feedback); // extract email
		$feedback = preg_replace('/(\d{5,})/', '', $feedback); // extract phonenumber
		$main = explode('@', $feedback);
		$pos = strpos($feedback,'@');
		if(count($main)>0 && $pos!==false)
		{
			if(count($main)>0)
				$start = explode(' ', trim($main[0]));
				array_pop($start);
				$text1 = implode(' ', $start);
			if(count($main)>1)
				$end = explode(' ', trim($main[1]));
				array_shift($end);
				$text2 = implode(' ', $end);
			$feedback = $text1.' '.$text2;	
		}
		
		$arr=array(
				'name'=>$name,
				'text'=>$feedback,
				'display_order'=>count($out)+1,
				'status'=>0
		);		//print_r($arr);
		$inst = $this->common_model->insertData('testimonials',$arr);
		$languages = $this->common_model->getAll('sys_languages');
		$arr= array();
		if(!empty($languages))
		{
			foreach ($languages as $value) {
				$arr=array(
						'testimonial_id'=>$inst,
						'text'=>$feedback,
						'lang_id'=>$value['id']
				);
				$this->common_model->insertData('testimonial_values',$arr);
			}
		}		
		
		if($_FILES['file']['name']!='')
		{
			$imagefolder = 'img/section-image/' ;
	        $uploadpath = 'assets/userfiles/'. $imagefolder;
			/*if (!file_exists(FCPATH . $uploadpath)) {
			    mkdir(FCPATH . $uploadpath, 0777, true);
			} */ 
			$filename = microtime().$_FILES['file']['name'];
	        $config = array(
	            'upload_path' 		=> FCPATH . $uploadpath . '/',
	            'allowed_types' 	=> 'jpg|JPG|png|PNG|jpeg|JPEG',
	            '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();
	        if($uploaddata)
	        {
	        	$file = array(
	            'user_id' 	=> $this->session->userdata('user_id'),
	            'path' 		=> $imagefolder,
	            'filename' 	=> $uploaddata['raw_name'],
	            '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('testimonials',array('image_id'=>$fileId),array('id'=>$inst));
	        }
	        
		}
		
		echo 1;exit;
	}
	public function testimonials()
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
			$content_data['testimonials'] = $this->common_model->getAllMultipleJoin('testimonials',array('status'=>1,'lang_id'=>$langId),array(array('testimonial_values','testimonial_values.testimonial_id = testimonials.id')),'display_order ASC');
			
			$content_data['latestUsers'] = $this->common_model->getAll('feu_userdetails',array('avatar_file_id >'=>0,'id >'=>1),array('sys_files','feu_userdetails.avatar_file_id = sys_files.id'),'feu_userdetails.created DESC','','',0,5);
			$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			if(empty($data['upcomingEvents']))
			{
				$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			}
			if(empty($data['lastEvents']))
			{
				$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			}
			$data['content'] = $this->load->view('testimonial', $content_data, TRUE);
			$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
			$data['checkinEvents'] = array();
			if($this->session->userdata('user_id'))
			{
				$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$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');
			}
			$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('Testimonials');
			$page_meta = $this->common_model->getAllRow('page_meta',array('page_name'=>'Testimonial','lang_id'=>$langId));
			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'] = 'Testimonials';
			}
			$this->load->view('template', $data);
	}
	public function unsubscribe($list_id='')
	{
		$this->common_model->UpdateData('usr_users',array('last_login'=>time()),array('id'=>$this->session->userdata('user_id')));
		$this->session->unset_userdata('user_id');
		if($this->input->post())
		{
			$email = $this->input->post('unsubEmail');
			$list_id = $this->input->post('list_id');
			$userdata = $this->common_model->getAllRow('usr_users',array('email'=>$email));
			if(empty($userdata))
			{
				echo getLang('You_are_not_a_registered_member');exit;
			}
			else
			{
				$inputPassword  = $this->common_model->generateHash($this->utility->info_cleanQuery($this->input->post('unsubPassword')));
				$password  = $userdata['password'];
				
				if($inputPassword == $password )
				{
					$this->common_model->UpdateData('feu_userdetails',array('subscribe'=>0),array('user_id'=>$userdata['id']));
					
					$apiKey = "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";
					$this->load->model('common_model');
					$curl = curl_init();

					curl_setopt_array($curl, array(
					  CURLOPT_URL => "https://api.sendgrid.com/v3/marketing/contacts/search/emails",
					  CURLOPT_RETURNTRANSFER => true,
					  CURLOPT_ENCODING => "",
					  CURLOPT_MAXREDIRS => 10,
					  CURLOPT_TIMEOUT => 30,
					  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
					  CURLOPT_CUSTOMREQUEST => "POST",
					  CURLOPT_POSTFIELDS => "{\"emails\":[\"$email\"]}",
					  CURLOPT_HTTPHEADER => array(
					    "authorization: Bearer ".$apiKey,
					    "content-type: application/json"
					  ),
					));

					$response = curl_exec($curl);
					$err = curl_error($curl);

					curl_close($curl);
					if ($err) {
					  echo 2;die;
					} else {
					  	$outout = json_decode($response, true);
					  	$ids = '';
						if(isset($outout['result'])) {
							if(isset($outout['result'][$email])) {
								if(isset($outout['result'][$email]['contact'])) {
									$ids = $outout['result'][$email]['contact']['id'];
								}
							}
						}
					  /*delete*/
					  	if($ids) {
						  	$curl = curl_init();
							curl_setopt_array($curl, array(
							  CURLOPT_URL => "https://api.sendgrid.com/v3/marketing/contacts?ids=".$ids,
							  CURLOPT_RETURNTRANSFER => true,
							  CURLOPT_ENCODING => "",
							  CURLOPT_MAXREDIRS => 10,
							  CURLOPT_TIMEOUT => 30,
							  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
							  CURLOPT_CUSTOMREQUEST => "DELETE",
							  CURLOPT_POSTFIELDS => "{}",
							  CURLOPT_HTTPHEADER => array(
							    "authorization: Bearer ".$apiKey,
							    "content-type: application/json"
							  ),
							));
							$response = curl_exec($curl);
							$err = curl_error($curl);
							curl_close($curl);
							if ($err) {
							  echo 2;die;
							} else {
							  echo 1; exit;
							}
						} else {
							echo 1; exit;
						}
					}
				} else {
					echo getLang('You_are_not_a_registered_member');exit;
				}
			}
		}
		$this->session->set_userdata('unsubscribe',$list_id);
		redirect(base_url());
	}
	public function language()
	{
		$this->session->set_userdata('lang_pop','1');
		redirect(base_url());
	}
	public function bounced()
	{
		$email = $this->input->post('bouncedEmail');
		
		$userdata = $this->common_model->getAllRow('usr_users',array('id'=>$this->session->userData('user_id')),array('feu_userdetails','feu_userdetails.user_id = usr_users.id'));
		if(empty($userdata))
		{
			echo getLang('You_are_not_a_registered_member');exit;
		}
		else
		{
			if($userdata['userlanguage']==1)
			{
				$list_id = '4b705bab4e';
			}
			else
			{
				$list_id = 'a8efb2baef';
			}
			$this->common_model->UpdateData('feu_userdetails',array('subscribe'=>1,'mailchimp_list_id'=>$list_id,'email_status'=>'sent'),array('user_id'=>$userdata['id']));
			$this->common_model->UpdateData('usr_users',array('email'=>$email),array('id'=>$userdata['id']));
			/*******************Unsubcsribe********************/
				$apiKey = "9a1d414f170b904492f76c4b4aaad59c-us14";
				$url = "https://us14.api.mailchimp.com/3.0/lists/".$list_id."/members/".md5(strtolower($userdata['email']));
				$operation = array(
			            'email_address'=>$userdata['email'],
			            'status'=>'unsubscribed',
			            );
				$request_encoded = json_encode($operation);
			    $curl = curl_init($url);
			    curl_setopt($curl, CURLOPT_USERPWD, 'user:' . $apiKey);    
			    curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
			    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);//raw output
			    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
			    curl_setopt($curl, CURLOPT_POSTFIELDS, $request_encoded); 
				$result = curl_exec($curl);
				//var_dump($result);
			/*******************Unsubcsribe********************/

			/*******************Subcsribe********************/
				$apiKey = "9a1d414f170b904492f76c4b4aaad59c-us14";
				$url = "https://us14.api.mailchimp.com/3.0/lists/".$list_id."/members/".md5(strtolower($email));
				$operation = array(
			            'email_address'=>$email,
			            'status'=>'subscribed',
			            'merge_fields'=>array(
		            		'FNAME'=>$userdata['username'],
		            		'LNAME'=>$userdata['alias']
		            		)
			            );
				$request_encoded = json_encode($operation);
			    $curl = curl_init($url);
			    curl_setopt($curl, CURLOPT_USERPWD, 'user:' . $apiKey);    
			    curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
			    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);//raw output
			    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
			    curl_setopt($curl, CURLOPT_POSTFIELDS, $request_encoded); 
				$result = curl_exec($curl);
				//var_dump($result);
			/*******************Subcsribe********************/
			//var_dump($result);
			//$this->session->set_userdata('unsubscribed','1');
			//redirect(base_url());
			echo 1; exit;
		}
	}
	public function sendOTP()
	{
		$mobile_number = $this->utility->info_cleanQuery($this->input->post('mobile_number'));
		$otp = $this->utility->passwordGenaretor();
		
		$message = urlencode($this->character_resolve(getLang('Your_verification_code_is'))).'+'.$otp;
		$url = "https://api.budgetsms.net/sendsms/?username=CASTLE&handle=ba04586987ec104e74b2374f59d51593&userid=18554&msg=".$message."&from=Castle&to=+".trim($mobile_number); 
		//$url = "https://bulksms.vsms.net/eapi/submission/send_sms/2/2.0?username=Sakrileg&password=ppp79111&message=".$message."&msisdn=+".trim($mobile_number); 
		$curl = curl_init($url);
	    curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
	    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);//raw output
	    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
	    $result = curl_exec($curl);
	    //print_r($result); die;
		if($result)
		{
			$output = explode(' ', $result);
			if(!empty($output))
			{
				if($output[0]=='OK')
				{
					$this->common_model->UpdateData('usr_users',array('otp'=>$otp),array('id'=>$this->session->userdata('user_id')));
					echo 1;
				}
				else
				{
					echo 0;
				}
			}
			else
			{
				echo 0;
			}
		}
		else
		{
			echo 0;
		}
		exit;
	}
	public function verifyOTP()
	{
		$mobile_number = $this->utility->info_cleanQuery($this->input->post('mobile_number'));
		$otp = $this->input->post('otp');
		$otpDetails = $this->common_model->getAllRow('usr_users',array('otp'=>$otp,'id'=>$this->session->userdata('user_id')));
		$mobileDetails = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$this->session->userdata('user_id')));
		if(!empty($otpDetails))
		{
			if($mobileDetails['mobile_number']>0)
			{
				$this->common_model->UpdateData('feu_userdetails',array('mobile_number'=>'+'.trim($mobile_number)),array('user_id'=>$this->session->userdata('user_id')));
				$this->common_model->insertData('usr_phones',array('user_id'=>$this->session->userdata('user_id'),'mobile_number'=>$mobileDetails['mobile_number']));
			}
			else
			{
				$this->common_model->UpdateData('feu_userdetails',array('mobile_number'=>'+'.trim($mobile_number)),array('user_id'=>$this->session->userdata('user_id')));
			}
			$this->common_model->UpdateData('usr_users',array('otp'=>''),array('id'=>$this->session->userdata('user_id')));
			echo 1;
		}
		else
		{
			echo 0;
		}
		exit;
	}
	public function character_resolve($body) {
	  $special_chrs = array(
	  'Δ'=>'0xD0', 'Φ'=>'0xDE', 'Γ'=>'0xAC', 'Λ'=>'0xC2', 'Ω'=>'0xDB',
	  'Π'=>'0xBA', 'Ψ'=>'0xDD', 'Σ'=>'0xCA', 'Θ'=>'0xD4', 'Ξ'=>'0xB1',
	  '¡'=>'0xA1', '£'=>'0xA3', '¤'=>'0xA4', '¥'=>'0xA5', '§'=>'0xA7',
	  '¿'=>'0xBF', 'Ä'=>'0xC4', 'Å'=>'0xC5', 'Æ'=>'0xC6', 'Ç'=>'0xC7',
	  'É'=>'0xC9', 'Ñ'=>'0xD1', 'Ö'=>'0xD6', 'Ø'=>'0xD8', 'Ü'=>'0xDC',
	  'ß'=>'0xDF', 'à'=>'0xE0', 'ä'=>'0xE4', 'å'=>'0xE5', 'æ'=>'0xE6',
	  'è'=>'0xE8', 'é'=>'0xE9', 'ì'=>'0xEC', 'ñ'=>'0xF1', 'ò'=>'0xF2',
	  'ö'=>'0xF6', 'ø'=>'0xF8', 'ù'=>'0xF9', 'ü'=>'0xFC',
	  );

	  $ret_msg = '';
	  if( mb_detect_encoding($body, 'UTF-8') != 'UTF-8' ) {
	    $body = utf8_encode($body);
	  }
	  for ( $i = 0; $i < mb_strlen( $body, 'UTF-8' ); $i++ ) {
	    $c = mb_substr( $body, $i, 1, 'UTF-8' );
	    if( isset( $special_chrs[ $c ] ) ) {
	      $ret_msg .= chr( $special_chrs[ $c ] );
	    }
	    else {
	      $ret_msg .= $c;
	    }
	  }
	  return $ret_msg;
	}
	public function not_found()
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$content_data = array();
		$content_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) ;
		$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) ;
		//echo $this->db->last_query();  die;
		if(empty($data['upcomingEvents']))
		{
			$content_data['upcomingEvents'] = $data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		}
		if(empty($data['lastEvents']))
		{
			$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		}
		$data['content'] = $this->load->view('404', $content_data, TRUE);
		$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
		$data['checkinEvents'] = array();
		if($this->session->userdata('user_id'))
		{
			$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$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');
		}
		$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('Testimonials');
		$page_meta = $this->common_model->getAllRow('page_meta',array('page_name'=>'All Parties','lang_id'=>$langId));
		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']));
		}
		$this->load->view('template', $data);
	}
	public function sitemap()
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$data['meta_title'] = getLang('Sitemap');
		$data['meta_description'] = getLang('Sitemap');
		$data['meta_keywords'] = getLang('Sitemap');
		$data['meta_genre'] = getLang('Sitemap');
		//echo $this->db->last_query();die;
		$content_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) ;
		$content_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(empty($data['upcomingEvents']))
		{
			$content_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']))
		{
			$content_data['lastEvents'] = $data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		}
		$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
		$data['checkinEvents'] = array();
		$data['checkinEvents'] = array();
		if($this->session->userdata('user_id'))
		{
			$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$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['articles'] = $this->common_model->getAllMultipleJoin('b_article',array('b_article.staus'=>1,'b_category.status'=>1,'b_gallery.status'=>1,'b_article_lang_values.lang_id'=>$langId),array(array('b_article_lang_values','b_article_lang_values.blog_id = b_article.blog_id'),array('b_category','b_category.cat_id = b_article.cat_id'),array('b_category_lang_values','b_category_lang_values.cat_id = b_category.cat_id'),array('b_gallery','b_gallery.b_article_id = b_article.blog_id')),'display_order ASC','','b_gallery.b_article_id');
		
		$content_data['cms_pages_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','*','');
		$content_data['cms_pages_2'] = $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','*','');
		$content_data['cms_pages_3'] = $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','*','');
		$content_data['cms_pages_4'] = $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('Sitemap');;
		
		$data['content'] = $this->load->view('sitemap', $content_data, TRUE);
		$this->load->view('template', $data);
	}

	public function news_blog($slug='')
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$content_data['categorylist'] = $this->common_model->getAll('b_category',array('b_category.status'=>1,'b_category_lang_values.lang_id'=>$langId),array('b_category_lang_values','b_category_lang_values.cat_id = b_category.cat_id'),'b_category_lang_values.cat_name ASC','b_category_lang_values.cat_name,cat_slug') ; 	
		
		if($slug=='')
		{
			$content_data['articles'] = $this->common_model->getAllMultipleJoin('b_article',array('b_article.staus'=>1,'b_category.status'=>1,'b_article_lang_values.lang_id'=>$langId),array(array('b_article_lang_values','b_article_lang_values.blog_id = b_article.blog_id'),array('b_category','b_category.cat_id = b_article.cat_id'),array('b_category_lang_values','b_category_lang_values.cat_id = b_category.cat_id'),array('b_gallery','b_gallery.b_article_id = b_article.blog_id','left')),'create_date DESC','','b_gallery.b_article_id');
		}
		else
		{
			$content_data['articles'] = $this->common_model->getAllMultipleJoin('b_article',array('b_article.staus'=>1,'b_category.status'=>1,'b_article_lang_values.lang_id'=>$langId,'cat_slug'=>$slug),array(array('b_article_lang_values','b_article_lang_values.blog_id = b_article.blog_id'),array('b_category','b_category.cat_id = b_article.cat_id'),array('b_category_lang_values','b_category_lang_values.cat_id = b_category.cat_id'),array('b_gallery','b_gallery.b_article_id = b_article.blog_id','left')),'create_date DESC','','b_gallery.b_article_id');
		}
		$data['meta_title'] = (!empty($content_data['articles']))?$content_data['articles'][0]['cat_name']:'';
		$data['meta_description'] = (!empty($content_data['articles']))?$content_data['articles'][0]['cat_name']:'';
		$data['meta_keywords'] = (!empty($content_data['articles']))?$content_data['articles'][0]['cat_name']:'';
		$data['meta_genre'] = 'Blog posting';
		//echo $this->db->last_query();die;
		$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		if(empty($data['upcomingEvents']))
		{
			$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		}
		if(empty($data['lastEvents']))
		{
			$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
		}
		$data['content'] = $this->load->view('news_blog', $content_data, TRUE);
		$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
		$data['checkinEvents'] = array();
		$data['checkinEvents'] = array();
		if($this->session->userdata('user_id'))
		{
			$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$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');
		}
		$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('News').' '.$slug;
		$this->load->view('template', $data);
	}
	public function news_blog_details($slug = '')
	{
		$langId = 2;
		if(get_cookie('lang'))
		{
			$langId = get_cookie('lang');
		}
		$content_data['categorylist'] = $this->common_model->getAll('b_category',array('b_category.status'=>1,'b_category_lang_values.lang_id'=>$langId),array('b_category_lang_values','b_category_lang_values.cat_id = b_category.cat_id'),'b_category_lang_values.cat_name ASC','b_category_lang_values.cat_name,cat_slug') ; 	
		
		$content_data['articles'] = $this->common_model->getAllMultipleJoin('b_article',array('b_article.staus'=>1,'b_category.status'=>1,'blog_slug'=>$slug,'b_article_lang_values.lang_id'=>$langId),array(array('b_article_lang_values','b_article_lang_values.blog_id = b_article.blog_id'),array('b_category','b_category.cat_id = b_article.cat_id'),array('b_gallery','b_gallery.b_article_id = b_article.blog_id','left')),'b_article.blog_title ASC');
		$content_data['other_articles'] = $this->common_model->getAllMultipleJoin('b_article',array('b_article.staus'=>1,'b_category.status'=>1,'b_article_lang_values.lang_id'=>$langId),array(array('b_article_lang_values','b_article_lang_values.blog_id = b_article.blog_id'),array('b_category','b_category.cat_id = b_article.cat_id'),array('b_category_lang_values','b_category_lang_values.cat_id = b_category.cat_id'),array('b_gallery','b_gallery.b_article_id = b_article.blog_id','left')),'create_date DESC','','b_gallery.b_article_id');
		$data['meta_title'] = (!empty($content_data['articles']))?$content_data['articles'][0]['blog_title']:'';
		$data['meta_description'] = (!empty($content_data['articles']))?html_entity_decode(strip_tags($content_data['articles'][0]['blog_desc'])):'';
		$data['meta_keywords'] = (!empty($content_data['articles']))?$content_data['articles'][0]['blog_title']:'';
		$data['meta_genre'] = 'Blog details';
		//print_r($content_data); print_r($data); die;
		if(!empty($content_data['articles']))
		{
			$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			if(empty($data['upcomingEvents']))
			{
				$data['upcomingEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from > '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from ASC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			}
			if(empty($data['lastEvents']))
			{
				$data['lastEvents'] = $this->common_model->getAllMultipleJoin('evt_events',array('time_from < '=>time(),'sorting'=>1,'is_banner'=>1,'visible'=>1,'lang_id'=>$langId),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'time_from DESC','evt_events.*,evt_event_files.*,evt_language_values.title as title','id',0,6) ;
			}
			$data['content'] = $this->load->view('news_blog_details', $content_data, TRUE);
			$data['languages'] = $this->common_model->getAll('sys_languages',array('visible'=>1)) ;
			$data['checkinEvents'] = array();
			$data['checkinEvents'] = array();
			if($this->session->userdata('user_id'))
			{
				$content_data['loginDetails'] = $this->common_model->getAll('usr_users',array('id'=>$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');
			}
			$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('News_Details')." - ".$content_data['articles'][0]['blog_title'];
			$this->load->view('template', $data);
		}
		else
		{
			redirect(base_url());
		}
	}
	function go_to_message()
	{
		if(!$this->session->userdata('user_id'))
		{
			$this->session->set_userdata('go_to_message',1);
		}
		redirect('messages');
	}

	public function sendTermsMail()
	{
		$userdetails = $this->common_model->getAllRow('feu_userdetails', array('user_id'=>$this->session->userdata('user_id')),array('usr_users','usr_users.id = feu_userdetails.user_id'));
		if($userdetails){
			$to = $userdetails['email'];
			$sub = 'Castleevents terms and conditions check mail';
			
			$body=' <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">'.$userdetails['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>
	                                      <p>You have accepted the terms and conditions on: '.date('d-m-Y H:i:s').'</p>
	                                   </p>
	                                </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;  	
			//$mail_send = $this->utility->sendCIRenewMail($to,$sub,$body);
			echo 1;
			exit;
		}
	}
}
