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

class Event extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->model('common_model');
		$this->load->model('users_model');
		if(get_cookie('admin_id'))
		{
			$this->session->set_userdata('admin_id',get_cookie('admin_id'));
		}
		if(!$this->session->userdata('admin_id'))
		{
			redirect('admin/login');
		}
	}
	public function index()
	{
		$content_data = array();
		$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
		$content_data['events'] = $this->common_model->getAllMultipleJoin('evt_events',array('is_banner'=>1,'evt_events.id !='=>76),array(array('loc_events_locations','evt_events.id = loc_events_locations.event_id'),array('loc_locations','loc_events_locations.location_id = loc_locations.id'),array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('sys_files','sys_files.id = evt_event_files.file_id')),'evt_events.time_from DESC','evt_events.id as id, evt_events.*,sys_files.path,sys_files.filename,sys_files.extension,loc_locations.name,loc_locations.country,loc_locations.city,loc_locations.zipcode,evt_event_files.is_banner,evt_events.is_sold','loc_events_locations.event_id');
		if($content_data['events'])
		{
			foreach ($content_data['events'] as $key => $value) {
				$side_events = $this->common_model->getAllRowMultipleJoin('side_events',array('side_events_to_event.event_id'=>$value['id']),array(array('side_events_to_event','side_events_to_event.side_event_id = side_events.id')),'side_events.created DESC');
				
				if($side_events['is_visible']==1)
				{
					$content_data['events'][$key]['side_event_visible'] = 1;
				}
				else
				{
					$content_data['events'][$key]['side_event_visible'] = 0;
				}
			}
		}
		//echo $this->db->last_query();die;
		$data['content'] = $this->load->view('admin/events/list', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function delete($enc_userID='')
	{
		if($enc_userID!='')
		{
			$eventId=base64_decode($enc_userID);
			$this->common_model->deleteData('evt_events',array('id'=>$eventId));
			$this->common_model->deleteData('evt_language_values',array('event_id'=>$eventId));
			$this->common_model->deleteData('loc_events_locations',array('event_id'=>$eventId));
			$this->common_model->deleteData('evt_event_files',array('event_id'=>$eventId));
			$this->common_model->deleteData('event_guest',array('event_id'=>$eventId));
			$this->utility->setMsg('Event deleted','SUCCESS');	
			redirect(base_url().'admin/event');
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event');
		}
	}
	public function visibility($enc_userID='',$status='')
	{
		if($enc_userID!='')
		{
			$eventId=base64_decode($enc_userID);
			if($status==1)
			{
				$newstatus = 1;
			}
			else
			{
				$newstatus = 0;
			}
			$this->common_model->UpdateData('evt_events',array('visible'=>$newstatus),array('id'=>$eventId));
			$this->utility->setMsg('Event status changed','SUCCESS');	
			redirect(base_url().'admin/event');
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event');
		}
	}
	public function side_event_visible($enc_userID='',$status='')
	{
		if($enc_userID!='')
		{
			$eventId=base64_decode($enc_userID);
			if($status==1)
			{
				$newstatus = 1;
			}
			else
			{
				$newstatus = 0;
			}
			$side_events = $this->common_model->getAll('side_events_to_event',array('event_id'=>$eventId));
			//pr($side_events);
			if($side_events)
			{
				foreach ($side_events as $key => $value) {
					$this->common_model->UpdateData('side_events',array('is_visible'=>$newstatus),array('id'=>$value['side_event_id']));
				}
			}
			//echo $this->db->last_query();die;
			$this->utility->setMsg('Event side event status changed','SUCCESS');	
			redirect(base_url().'admin/event');
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event');
		}
	}
	public function add()
	{
		if($this->input->post())
		{
			$serArr = array();
			$i = 0;
			foreach ($this->input->post('services') as $serv) {
				$serArr[$serv]['checked'] = 1;
				$serArr[$serv]['text'] = "";
				$i++;
			}
			$aliss = str_replace(' ','-',trim(strtolower($this->input->post('name_2'))));
			$aliss = preg_replace('/[^A-Za-z0-9\-]/', '-', $aliss);
			

			$evtArr = array(
							'title'=>$this->input->post('name_2'),
							'teasertext'=>$this->input->post('teasertext_2'),
							'alias'=>$aliss,
							'description'=>$this->input->post('content_2'),
							'time_from'=>strtotime($this->input->post('fromDate')),
							'time_to'=>strtotime($this->input->post('toDate')),
							'created'=>time(),
							'basic_drinking'=>$this->input->post('basic_drinking'),
							'premium_drinking'=>$this->input->post('premium_drinking'),
							'video_url'=>$this->input->post('video_url'),
							'services'=>json_encode($serArr),
							'address'=>$this->input->post('address'),
							'party_details'=>$this->input->post('party_details_2'),
							'event_video'=>$this->input->post('event_video'),
							'airport_distance'=>$this->input->post('airport_distance'),
							'discount'=>$this->input->post('discount'),
							'discount_end_date'=>date('Y-m-d',strtotime($this->input->post('discount_end_date'))),
							'rating'=>$this->input->post('rating'),
							'extra_info'=>$this->input->post('extra_info_2'),
							'extra_text'=>$this->input->post('extra_text_2'),
				);//print_r($evtArr); die;
			$evtId = $this->common_model->insertData('evt_events',$evtArr);
			$eventValue = $this->common_model->getAllRow('evt_events',array('alias'=>$aliss,'id !='=>$evtId));
			if(count($eventValue)>0)
			{
				$aliss = $aliss.'-'.$evtId;
				$this->common_model->UpdateData('evt_events',array('alias'=>$aliss),array('id'=>$evtId));
			}

			$from_year = date('Y', strtotime($this->input->post('fromDate')));
			$getEventListDataSql = $this->db->query("SELECT id, title, YEAR(FROM_UNIXTIME(time_from)) as year, MONTH(FROM_UNIXTIME(time_from)) as month,event_unique_id FROM `evt_events` WHERE YEAR(FROM_UNIXTIME(time_from)) = ".$from_year." order by YEAR(FROM_UNIXTIME(time_from)) ASC, MONTH(FROM_UNIXTIME(time_from)) ASC");
			$getEventListData = $getEventListDataSql->result_array();
			$event_unique_id = $from_year.'-'.(count($getEventListData)+1);
			$this->common_model->UpdateData('evt_events',array('event_unique_id'=>$event_unique_id),array('id'=>$evtId));

			$languages = $this->common_model->getAll('sys_languages');
			$arr= array();
			if(!empty($languages))
			{
				foreach ($languages as $value) {
					$arr['event_id'] = $evtId;
					$arr['lang_id'] = $value['id'];
					$arr['title'] = $this->input->post('name_'.$value['id']);
					$arr['alias'] = str_replace(' ','-',trim(strtolower($this->input->post('name_'.$value['id']))));
					$arr['sub_title'] = $this->input->post('sub_title'.$value['id']);
					$arr['description'] = $this->input->post('content_'.$value['id']);
					$arr['teasertext'] = $this->input->post('teasertext_'.$value['id']);
					$arr['party_details'] = $this->input->post('party_details_'.$value['id']);
					$arr['extra_info'] = $this->input->post('extra_info_'.$value['id']);
					$arr['extra_text'] = $this->input->post('extra_text_'.$value['id']);
					$arr['created'] = time();
					$instLngVal = $this->common_model->insertData('evt_language_values',$arr);
				}
			}
			

			$locations = $this->input->post('location_id');
			if(!empty($locations))
			{
				foreach ($locations as $loc)
				{
					$locArr=array(
									'event_id'=>$evtId,
									'location_id'=>$loc
								);
					$instLoc = $this->common_model->insertData('loc_events_locations',$locArr);
				}
			}

			if($_FILES['banner_image']['name']!='')
			{
				$imagefolder = 'img/parties/';
		        $uploadpath = 'assets/userfiles/'. $imagefolder;
				$config = array(
		            'upload_path' 		=> FCPATH . $uploadpath . '/',
		            'allowed_types' 	=> '*',
		            'encrypt_name' 		=> true,
		            'file_ext_tolower' 	=> true,
		            //'max_size' 			=> (int)MSysSettings::getValue('upload_max_filesize') * 1024,
		        );

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

		            $this->utility->setMsg($this->upload->display_errors(),'ERROR');	
					redirect(base_url().'admin/event/add/');
		        }

		        $uploaddata = $this->upload->data();

		        $this->utility->pic_resize($uploadpath.$uploaddata['raw_name'].'.'.substr($uploaddata['file_ext'], 1),$uploadpath.$uploaddata['raw_name'].'_thumb'.'.'.substr($uploaddata['file_ext'], 1),'275','160'); 

		        $file = array(
		            'user_id' 	=> 1,
		            '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 ' . $username,
		        );

		        $imagesize = getimagesize($uploaddata['full_path']);

		        $file['width'] 	= $imagesize[0];
		        $file['height'] = $imagesize[1];


		        $bannerId = $this->common_model->insertData('sys_files',$file);
		        $this->common_model->insertData('evt_event_files',array('event_id'=>$evtId,'file_id'=>$bannerId,'sorting'=>1,'is_banner'=>1));
				$resizeBlur = $this->avater($uploaddata['raw_name'] .'.'. substr($uploaddata['file_ext'], 1));
			}
			if($_FILES['party_image']['name'][0]!='')
			{
				for($i=0; $i<count($_FILES['party_image']['name']); $i++) 
				{
					if($_FILES['party_image']['name'][$i]!='')
					{
						$_FILES['userFile']['name'] = $_FILES['party_image']['name'][$i];
		                $_FILES['userFile']['type'] = $_FILES['party_image']['type'][$i];
		                $_FILES['userFile']['tmp_name'] = $_FILES['party_image']['tmp_name'][$i];
		                $_FILES['userFile']['error'] = $_FILES['party_image']['error'][$i];
		                $_FILES['userFile']['size'] = $_FILES['party_image']['size'][$i];

						$imagefolder = 'img/parties/night-image/';
				        $uploadpath = 'assets/userfiles/'. $imagefolder;
						$config = array(
				            'upload_path' 		=> FCPATH . $uploadpath . '/',
				            'allowed_types' 	=> '*',
				            'encrypt_name' 		=> true,
				            'file_ext_tolower' 	=> true,
				            //'max_size' 			=> (int)MSysSettings::getValue('upload_max_filesize') * 1024,
				        );

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

				            $this->utility->setMsg($this->upload->display_errors(),'ERROR');	
							redirect(base_url().'admin/event/add/');
				        }

				        $uploaddata = $this->upload->data();

				        $file = array(
				            'user_id' 	=> 1,
				            '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 ' . $username,
				        );

				        $imagesize = getimagesize($uploaddata['full_path']);

				        $file['width'] 	= $imagesize[0];
				        $file['height'] = $imagesize[1];


				        $nightId = $this->common_model->insertData('sys_files',$file);
				        $this->common_model->insertData('evt_event_files',array('event_id'=>$evtId,'file_id'=>$nightId,'sorting'=>1,'is_banner'=>0));
					}
				}
			}
			redirect(base_url().'admin/event');
		}
		$content_data = array();
		$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
		$content_data['languages'] = $this->common_model->getAll('sys_languages') ;
		$content_data['locations'] = $this->common_model->getAll('loc_locations',array('name !='=>''),'','name ASC') ;
		$content_data['services'] = $this->_getServiceArray();
		$data['content'] = $this->load->view('admin/events/add', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	private function _getServiceArray() {

		return array(
			'Castle',
			'Medieval Castle',
			'Villa',
			'Penthouse',
			'Luxury Boutique Hotel',
			//'Yacht',
			'Five Star Location',
			'Gourmet',
			'Rooms & Suites',
			'Delicious Dinner',
			'Flying Dinner Buffet',
			'Airport Service',
			'Ceremony',
			'Cigar Lounge',
			'Wellness Area',
			'Premium Offers',
			'Live Music & Show',
			'A Few Single Lady Entries available',
			'Masks & Capes Large Selection On Site',
			'Guarded Wardrobe',
			'Dresscode',
            'Cape Required',
            'Venetian Masks',
            'Dresscode Black Tie',
            'Dresscode See Further Information',
            'For Couples only',
            //'rentacape',
		);
	}
	public function edit($enc_userID='')
	{
		if($enc_userID!='')
		{
			$evtId=base64_decode($enc_userID);
			if($this->input->post())
			{
				$serArr = array();
				$i = 0;
				foreach ($this->input->post('services') as $serv) {
					$serArr[$serv]['checked'] = 1;
					$serArr[$serv]['text'] = "";
					$i++;
				}
				$aliss = str_replace(' ','-',trim(strtolower($this->input->post('name_2'))));
				$aliss = preg_replace('/[^A-Za-z0-9\-]/', '-', $aliss);
				$evtArr = array(
								'title'=>$this->input->post('name_2'),
								'teasertext'=>$this->input->post('teasertext_2'),
								'alias'=>$aliss,
								'description'=>$this->input->post('content_2'),
								'time_from'=>strtotime($this->input->post('fromDate')),
								'time_to'=>strtotime($this->input->post('toDate')),
								'created'=>time(),
								'basic_drinking'=>$this->input->post('basic_drinking'),
								'premium_drinking'=>$this->input->post('premium_drinking'),
								'video_url'=>$this->input->post('video_url'),
								'services'=>json_encode($serArr),
								'address'=>$this->input->post('address'),
								'party_details'=>$this->input->post('party_details_2'),
								'discount'=>$this->input->post('discount'),
								'discount_end_date'=>date('Y-m-d',strtotime($this->input->post('discount_end_date'))),
								'stripe_account_id'=>$this->input->post('stripe_account_id'),
								'event_video'=>$this->input->post('event_video'),
								'airport_distance'=>$this->input->post('airport_distance'),
								'rating'=>$this->input->post('rating'),
								'extra_info'=>$this->input->post('extra_info_2'),
								'extra_text'=>$this->input->post('extra_text_2'),
								'rating_on_off'=>$this->input->post('rating_on_off') ? $this->input->post('rating_on_off') : 0,
								'add_checkin_title'=>$this->input->post('add_checkin_title_2') ? $this->input->post('add_checkin_title_2') : "",
								'add_checkin_info'=>$this->input->post('add_checkin_info_2') ? $this->input->post('add_checkin_info_2') : "",
								'add_checkin_price'=>$this->input->post('add_checkin_price') ? $this->input->post('add_checkin_price') : 0,
								'show_addion_step'=>$this->input->post('show_addion_step') ? $this->input->post('show_addion_step') : 0,
								'additonal_step_is_mandatory'=>$this->input->post('additonal_step_is_mandatory') ? $this->input->post('additonal_step_is_mandatory') : 0,
								'event_unique_id'=>$this->input->post('event_unique_id') ? $this->input->post('event_unique_id') : '',
					);//print_r($evtArr); die;
				$this->common_model->UpdateData('evt_events',$evtArr,array('id'=>$evtId));
				$eventValue = $this->common_model->getAllRow('evt_events',array('alias'=>$aliss,'id !='=>$evtId));
				if(count($eventValue)>0)
				{
					$aliss = $aliss.'-'.$evtId;
					$this->common_model->UpdateData('evt_events',array('alias'=>$aliss),array('id'=>$evtId));
				}

				/*$from_year = date('Y', strtotime($this->input->post('fromDate')));
				$getEventListDataSql = $this->db->query("SELECT id, title, YEAR(FROM_UNIXTIME(time_from)) as year, MONTH(FROM_UNIXTIME(time_from)) as month,event_unique_id FROM `evt_events` WHERE YEAR(FROM_UNIXTIME(time_from)) = ".$from_year." order by YEAR(FROM_UNIXTIME(time_from)) ASC, MONTH(FROM_UNIXTIME(time_from)) ASC");
				$getEventListData = $getEventListDataSql->result_array();
				echo $event_unique_id = $from_year.'-'.(count($getEventListData)+1);die;*/
				//$this->common_model->UpdateData('evt_events',array('event_unique_id'=>$event_unique_id),array('id'=>$evtId));

				if($this->input->post('past_parties'))
				{
					$past_parties = implode(',', $this->input->post('past_parties'));
					$this->common_model->UpdateData('evt_events',array('past_parties'=>$past_parties),array('id'=>$evtId));
				}


				$languages = $this->common_model->getAll('sys_languages');
				$arr= array();
				if(!empty($languages))
				{
					$this->common_model->deleteData('evt_language_values',array('event_id'=>$evtId));
					foreach ($languages as $value) {
						$arr['event_id'] = $evtId;
						$arr['lang_id'] = $value['id'];
						$arr['title'] = $this->input->post('name_'.$value['id']);
						$arr['alias'] = str_replace(' ','-',trim(strtolower($this->input->post('name_'.$value['id']))));
						$arr['sub_title'] = $this->input->post('sub_title'.$value['id']);
						$arr['description'] = $this->input->post('content_'.$value['id']);
						$arr['teasertext'] = $this->input->post('teasertext_'.$value['id']);
						$arr['party_details'] = $this->input->post('party_details_'.$value['id']);
						$arr['extra_info'] = $this->input->post('extra_info_'.$value['id']);
						$arr['extra_text'] = $this->input->post('extra_text_'.$value['id']);
						$arr['add_checkin_title'] = $this->input->post('add_checkin_title_'.$value['id']);
						$arr['add_checkin_info'] = $this->input->post('add_checkin_info_'.$value['id']);
						$arr['created'] = time();
						$instLngVal = $this->common_model->insertData('evt_language_values',$arr);
					}
				}

				if($_FILES['add_checkin_picture']['name']!='')
				{
					$imagefolder = 'img/checkin_steps/';
			        $uploadpath = 'assets/userfiles/'. $imagefolder;
					$config = array(
			            'upload_path' 		=> FCPATH . $uploadpath . '/',
			            'allowed_types' 	=> '*',
			            'encrypt_name' 		=> true,
			            'file_ext_tolower' 	=> true,
			            //'max_size' 			=> (int)MSysSettings::getValue('upload_max_filesize') * 1024,
			        );

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

			            $this->utility->setMsg($this->upload->display_errors(),'ERROR');	
						//redirect(base_url().'admin/checkin/checkin_steps_add/');
			        }

			        $uploaddata = $this->upload->data();

			        $add_checkin_picture = $imagefolder.$uploaddata['raw_name'].'.'.substr($uploaddata['file_ext'], 1);
			        $this->common_model->UpdateData('evt_events',array('add_checkin_picture'=>$add_checkin_picture),array('id'=>$evtId));
				
				}
				

				$locations = $this->input->post('location_id');
				if(!empty($locations))
				{	
					$this->common_model->deleteData('loc_events_locations',array('event_id'=>$evtId));
					foreach ($locations as $loc)
					{
						$locArr=array(
										'event_id'=>$evtId,
										'location_id'=>$loc
									);
						$instLoc = $this->common_model->insertData('loc_events_locations',$locArr);
					}
				}

				if($_FILES['banner_image']['name']!='')
				{
					$imagefolder = 'img/parties/';
			        $uploadpath = 'assets/userfiles/'. $imagefolder;
					$config = array(
			            'upload_path' 		=> FCPATH . $uploadpath . '/',
			            'allowed_types' 	=> '*',
			            'encrypt_name' 		=> true,
			            'file_ext_tolower' 	=> true,
			            //'max_size' 			=> (int)MSysSettings::getValue('upload_max_filesize') * 1024,
			        );

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

			            $this->utility->setMsg($this->upload->display_errors(),'ERROR');	
						redirect(base_url().'admin/event/edit/'.$enc_userID);
			        }

			        $uploaddata = $this->upload->data();

			        $this->utility->pic_resize($uploadpath.$uploaddata['raw_name'].'.'.substr($uploaddata['file_ext'], 1),$uploadpath.$uploaddata['raw_name'].'_thumb'.'.'.substr($uploaddata['file_ext'], 1),'275','160'); 
			       
			        $file = array(
			            'user_id' 	=> 1,
			            '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 ' . $username,
			        );

			        $imagesize = getimagesize($uploaddata['full_path']);

			        $file['width'] 	= $imagesize[0];
			        $file['height'] = $imagesize[1];


			        $bannerId = $this->common_model->insertData('sys_files',$file);
			        $bennerImagehas = $this->common_model->getAllRow('evt_event_files',array('event_id'=>$evtId,'is_banner'=>1));
			        if(empty($bennerImagehas))
			        {
			        	$this->common_model->insertData('evt_event_files',array('event_id'=>$evtId,'file_id'=>$bannerId,'sorting'=>1,'is_banner'=>1));
						$resizeBlur = $this->avater($uploaddata['raw_name'] .'.'. substr($uploaddata['file_ext'], 1));
			        }
			        else
			        {
			        	$this->common_model->UpdateData('evt_event_files',array('file_id'=>$bannerId),array('event_id'=>$evtId,'is_banner'=>1));
						$resizeBlur = $this->avater($uploaddata['raw_name'] .'.'. substr($uploaddata['file_ext'], 1));
			        }
			        
				}
				if($_FILES['party_image']['name'][0]!='')
				{
					for($i=0; $i<count($_FILES['party_image']['name']); $i++) 
					{
						if($_FILES['party_image']['name'][$i]!='')
						{
							$_FILES['userFile']['name'] = $_FILES['party_image']['name'][$i];
			                $_FILES['userFile']['type'] = $_FILES['party_image']['type'][$i];
			                $_FILES['userFile']['tmp_name'] = $_FILES['party_image']['tmp_name'][$i];
			                $_FILES['userFile']['error'] = $_FILES['party_image']['error'][$i];
			                $_FILES['userFile']['size'] = $_FILES['party_image']['size'][$i];

							$imagefolder = 'img/parties/night-image/';
					        $uploadpath = 'assets/userfiles/'. $imagefolder;
							$config = array(
					            'upload_path' 		=> FCPATH . $uploadpath . '/',
					            'allowed_types' 	=> '*',
					            'encrypt_name' 		=> true,
					            'file_ext_tolower' 	=> true,
					            //'max_size' 			=> (int)MSysSettings::getValue('upload_max_filesize') * 1024,
					        );

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

					            $this->utility->setMsg($this->upload->display_errors(),'ERROR');	
								redirect(base_url().'admin/event/edit/'.$enc_userID);
					        }

					        $uploaddata = $this->upload->data();

					        $file = array(
					            'user_id' 	=> 1,
					            '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 ' . $username,
					        );

					        $imagesize = getimagesize($uploaddata['full_path']);

					        $file['width'] 	= $imagesize[0];
					        $file['height'] = $imagesize[1];
					        /****************Blur Image******************/
					        if(!file_exists(FCPATH . 'assets/userfiles/'. $imagefolder . $uploaddata['raw_name'] .'_blur.'. substr($uploaddata['file_ext'], 1))){
					            $im = new Imagick(FCPATH . 'assets/userfiles/'. $imagefolder . $uploaddata['raw_name'] .'.'. substr($uploaddata['file_ext'], 1));
					            //print_r(FCPATH . 'assets/userfiles/' . $fileDetails['path'] . '/' . $fileDetails['filename'] .'.'. $fileDetails['extension']); die;
					            $im->blurImage(30,20);
					            $blurredImg = FCPATH . 'assets/userfiles/'. $imagefolder . $uploaddata['raw_name'] .'_blur.'. substr($uploaddata['file_ext'], 1);
					            $fp = fopen($blurredImg, "x");
					            $im->writeImageFile($fp);
					            //fclose($fp);
				        	}
					        /****************Blur Image******************/

					        $nightId = $this->common_model->insertData('sys_files',$file);
					        //$this->common_model->deleteData('evt_event_files',array('event_id'=>$evtId));
					        $this->common_model->insertData('evt_event_files',array('event_id'=>$evtId,'file_id'=>$nightId,'sorting'=>1,'is_banner'=>0));
						}
					}
				}
				redirect(base_url().'admin/event/edit/'.$enc_userID);
			}
			$content_data = array();
			$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
			$content_data['languages'] = $this->common_model->getAll('sys_languages') ;
			$content_data['locations'] = $this->common_model->getAll('loc_locations',array('name !='=>''),'','name ASC') ;
			$content_data['services'] = $this->_getServiceArray();
			$content_data['eventDetail'] = $this->common_model->getAllRow('evt_events',array('evt_events.id'=>$evtId));
			//$content_data['langDetails'] = $this->common_model->getAll('evt_language_values',array('event_id'=>$evtId),array('sys_languages','sys_languages.id = evt_language_values.lang_id'));
			$content_data['stripe_accounts'] = $this->common_model->getAll('stripe_credentials') ;
			$content_data['bannerImageDetails'] = $this->common_model->getAllRow('evt_event_files',array('event_id'=>$evtId,'is_banner'=>1),array('sys_files','sys_files.id = evt_event_files.file_id'));
			$content_data['imageDetails'] = $this->common_model->getAll('evt_event_files',array('event_id'=>$evtId,'is_banner'=>0),array('sys_files','sys_files.id = evt_event_files.file_id'));
			$locationDetails = $this->common_model->getAll('loc_events_locations',array('event_id'=>$evtId),'','','location_id');
			$content_data['locationDetails'] = array();
			$content_data['pastParties'] = array();
			if($content_data['eventDetail']['time_from']>time())
			{
				$content_data['pastParties'] = $this->common_model->getAllMultipleJoin('evt_events',array('evt_event_files.is_banner'=>1,'time_from <'=>time()),array(array('evt_event_files','evt_event_files.event_id = evt_events.id'),array('sys_files','sys_files.id = evt_event_files.file_id')),'title ASC','evt_events.id as id, evt_events.*,sys_files.path,sys_files.filename,sys_files.extension','evt_events.id');
				if($content_data['pastParties']){
					foreach ($content_data['pastParties'] as $key => $value) {
						$pastFileData = $this->common_model->getAll('evt_event_files',array('is_banner'=>0, 'event_id'=>$value['id']));
						$content_data['pastParties'][$key]['files_have'] = count($pastFileData);
						$content_data['pastParties'][$key]['video_have'] = ($value['video_url']!='') ? 1 : 0;
					}
				}
			}
			//print_r($content_data['eventDetail']); die;
			if(!empty($locationDetails ))
			{
				foreach ($locationDetails  as $values) {
					array_push($content_data['locationDetails'], $values['location_id']);
				}
			}
			$content_data['evtServices'] = array();
			if(!empty($content_data['eventDetail']['services'] ))
			{
				$services = json_decode($content_data['eventDetail']['services']);
				foreach ($services  as $key=>$service) {
					array_push($content_data['evtServices'], $key);
				}
			}
			//print_r($content_data); die;
			$data['content'] = $this->load->view('admin/events/edit', $content_data, TRUE);
			$this->load->view('admin/layout', $data);
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event');
		}
	}
	public function entrylist($enc_userID='')
	{
		if($enc_userID!='')
		{
			$evtId=base64_decode($enc_userID);
			$content_data = array();
			$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
			$content_data['entry'] = $this->common_model->getAllMultipleJoin('event_features',array('event_features.type'=>1,'event_id'=>$evtId,'event_features_lang_values.lang_id'=>2),array(array('event_features_lang_values','event_features_lang_values.event_feature_id = event_features.id'),array('sys_files','sys_files.id = event_features.image_id')),'event_features.created DESC','event_features.*,sys_files.path,sys_files.filename,sys_files.extension,event_features_lang_values.title');
			//print_r($content_data['entry']);
			$data['content'] = $this->load->view('admin/events/entrylist', $content_data, TRUE);
			$this->load->view('admin/layout', $data);
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/entrylist/'.$enc_userID);
		}
	}
	public function entry_add($enc_userID='')
	{
		if($this->input->post())
		{
			$arr['event_id'] = $this->input->post('event_id');
			$arr['created'] = time();
			$arr['type'] = 1;
			$arr['base_price'] = $this->input->post('basic_price');
			$entryId = $this->common_model->insertData('event_features',$arr);

			$languages = $this->common_model->getAll('sys_languages');
			$arr= array();
			if(!empty($languages))
			{
				foreach ($languages as $value) {
					$arr['event_feature_id'] = $entryId;
					$arr['lang_id'] = $value['id'];
					$arr['title'] = $this->input->post('name_'.$value['id']);
					$arr['content'] = $this->input->post('content_'.$value['id']);
					$this->common_model->insertData('event_features_lang_values',$arr);
				}
			}
			if($_FILES['image']['name']!='')
			{
				$imagefolder = 'img/parties/event_features/';
		        $uploadpath = 'assets/userfiles/'. $imagefolder;
				$config = array(
		            'upload_path' 		=> FCPATH . $uploadpath . '/',
		            'allowed_types' 	=> '*',
		            'encrypt_name' 		=> true,
		            'file_ext_tolower' 	=> true,
		            //'max_size' 			=> (int)MSysSettings::getValue('upload_max_filesize') * 1024,
		        );

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

		            $this->utility->setMsg($this->upload->display_errors(),'ERROR');	
					redirect(base_url().'admin/event/entry_add/'.$enc_userID);
		        }

		        $uploaddata = $this->upload->data();

		        $file = array(
		            'user_id' 	=> 1,
		            '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 ' . $username,
		        );

		        $imagesize = getimagesize($uploaddata['full_path']);

		        $file['width'] 	= $imagesize[0];
		        $file['height'] = $imagesize[1];

		        $bannerId = $this->common_model->insertData('sys_files',$file);
		        $this->common_model->UpdateData('event_features',array('image_id'=>$bannerId),array('id'=>$entryId));
			
			}
			redirect(base_url().'admin/event/entrylist/'.$enc_userID);
		}
			
		$content_data = array();
		$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
		$content_data['languages'] = $this->common_model->getAll('sys_languages') ;
		$data['content'] = $this->load->view('admin/events/entry_add', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function entry_delete($enc_userID='',$enc_entryID = '')
	{
		if($enc_entryID!='')
		{
			$entryFeatureId=base64_decode($enc_entryID);
			$this->common_model->deleteData('event_features',array('id'=>$entryFeatureId));
			$this->utility->setMsg('Entry deleted','SUCCESS');	
			redirect(base_url().'admin/event/entrylist/'.$enc_userID);
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/entrylist/'.$enc_userID);
		}
	}
	public function entry_sold($enc_entryID = '',$enc_userID='',$status='')
	{
		if($enc_userID!='')
		{
			if($status==2)
			{
				$new = 0;
			}
			else
			{
				$new = 1;
			}
			$userId=base64_decode($enc_userID);
			$this->common_model->UpdateData('event_features',array('is_sold'=>$new),array('id'=>$userId));
			$this->utility->setMsg('Entry solded out','SUCCESS');	
			redirect(base_url().'admin/event/entrylist/'.$enc_entryID);
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/entrylist/'.$enc_entryID);
		}
	}
	public function room_mandatory($enc_entryID = '',$enc_userID='',$status='')
	{
		if($enc_userID!='')
		{
			$userId=base64_decode($enc_userID);
			$this->common_model->UpdateData('event_features',array('room_mandatory'=>$status),array('id'=>$userId));
			//echo $this->db->last_query(); die;
			$this->utility->setMsg('Entry room mandatory status changed','SUCCESS');	
			redirect(base_url().'admin/event/entrylist/'.$enc_entryID);
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/entrylist/'.$enc_entryID);
		}
	}
	public function entry_edit($enc_userID='',$enc_entryID = '')
	{
		$id = base64_decode($enc_entryID);
		if($this->input->post())
		{
			$arr['base_price'] = $this->input->post('basic_price');
			$entryId = $this->common_model->UpdateData('event_features',$arr,array('id'=>$id));

			$languages = $this->common_model->getAll('sys_languages');
			$arr= array();
			if(!empty($languages))
			{
				foreach ($languages as $value) {
					$arr['title'] = $this->input->post('name_'.$value['id']);
					$arr['content'] = $this->input->post('content_'.$value['id']);
					$exist = $this->common_model->getAllRow('event_features_lang_values',array('event_feature_id'=>$id,'lang_id'=>$value['id']));
					if(empty($exist))
					{
						$arr1['event_feature_id'] = $id;
						$arr1['lang_id'] = $value['id'];
						$arr1['title'] = $this->input->post('name_'.$value['id']);
						$arr1['content'] = $this->input->post('content_'.$value['id']);
						$this->common_model->insertData('event_features_lang_values',$arr1);
					}
					else
					{
						$this->common_model->UpdateData('event_features_lang_values',$arr,array('event_feature_id'=>$id,'lang_id'=>$value['id']));
					}
					
				}
			}
			if($_FILES['image']['name']!='')
			{
				$imagefolder = 'img/parties/event_features/';
		        $uploadpath = 'assets/userfiles/'. $imagefolder;
				$config = array(
		            'upload_path' 		=> FCPATH . $uploadpath . '/',
		            'allowed_types' 	=> '*',
		            'encrypt_name' 		=> true,
		            'file_ext_tolower' 	=> true,
		            //'max_size' 			=> (int)MSysSettings::getValue('upload_max_filesize') * 1024,
		        );

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

		            $this->utility->setMsg($this->upload->display_errors(),'ERROR');	
					redirect(base_url().'admin/event/entry_edit/'.$enc_userID);
		        }

		        $uploaddata = $this->upload->data();

		        $file = array(
		            'user_id' 	=> 1,
		            '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 ' . $username,
		        );

		        $imagesize = getimagesize($uploaddata['full_path']);

		        $file['width'] 	= $imagesize[0];
		        $file['height'] = $imagesize[1];

		        $bannerId = $this->common_model->insertData('sys_files',$file);
		        $this->common_model->UpdateData('event_features',array('image_id'=>$bannerId),array('id'=>$id));
			
			}
			redirect(base_url().'admin/event/entrylist/'.$enc_userID);
		}
			
		$content_data = array();
		$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
		$content_data['languages'] = $this->common_model->getAll('sys_languages') ;
		$content_data['entryDetails'] = $this->common_model->getAllRowMultipleJoin('event_features',array('event_features.id'=>$id),array(array('sys_files','sys_files.id = event_features.image_id')),'event_features.created DESC','event_features.*,sys_files.path,sys_files.filename,sys_files.extension');
		//print_r($content_data['entryDetails']); die;
		$data['content'] = $this->load->view('admin/events/entry_edit', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function roomlist($enc_userID='')
	{
		if($enc_userID!='')
		{
			$entryId=base64_decode($enc_userID);
			$content_data = array();
			$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
			$content_data['rooms'] = $this->common_model->getAllMultipleJoin('event_features',array('event_features.type'=>2,'entry_id'=>$entryId,'event_features_lang_values.lang_id'=>2),array(array('event_features_lang_values','event_features_lang_values.event_feature_id = event_features.id'),array('sys_files','sys_files.id = event_features.image_id')),'event_features.created DESC','event_features.*,sys_files.path,sys_files.filename,sys_files.extension,event_features_lang_values.title');
			//echo $this->db->last_query();
			if($content_data['rooms']){
				foreach ($content_data['rooms'] as $key => $value) {
					$booked_rooms = $this->common_model->getAll('shop_booking_details',array('feature_type'=>2,'feature_id'=>$value['id']),array('shop_orders','shop_orders.cart_id = shop_booking_details.cart_id'),'','','shop_booking_details.cart_id');
					if(count($booked_rooms)>0){
						$content_data['rooms'][$key]['booked_rooms'] = count($booked_rooms);
						$booked_rooms_paid = 0;
						if($booked_rooms){
							foreach ($booked_rooms as $k => $val) {
								if($val['payed']==1)
									$booked_rooms_paid += 1; 
							}
						}
						$content_data['rooms'][$key]['booked_rooms_paid'] += $booked_rooms_paid; 
					}
				}
			}
			$data['content'] = $this->load->view('admin/events/roomlist', $content_data, TRUE);
			$this->load->view('admin/layout', $data);
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/roomlist/'.$enc_userID);
		}
	}
	public function room_delete($enc_roomID = '')
	{
		if($enc_roomID!='')
		{
			$roomId=base64_decode($enc_roomID);
			$roomDetail = $this->common_model->getAllRow('event_features',array('id'=>$roomId));
			$this->common_model->deleteData('event_features',array('id'=>$roomId));
			$this->utility->setMsg('Room deleted','SUCCESS');	
			redirect(base_url().'admin/event/roomlist/'.base64_encode($roomDetail['entry_id']));
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/roomlist/'.base64_encode($roomDetail['entry_id']));
		}
	}
	public function room_sold($enc_userID='',$status='')
	{
		if($enc_userID!='')
		{
			if($status==2)
			{
				$new = 0;
			}
			else
			{
				$new = 1;
			}
			$userId=base64_decode($enc_userID);
			$roomDetail = $this->common_model->getAllRow('event_features',array('id'=>$userId));
			$this->common_model->UpdateData('event_features',array('is_sold'=>$new),array('id'=>$userId));
			$this->utility->setMsg('Room solded out','SUCCESS');	
			redirect(base_url().'admin/event/roomlist/'.base64_encode($roomDetail['entry_id']));
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/roomlist/'.base64_encode($roomDetail['entry_id']));
		}
	}
	public function room_add($enc_userID='')
	{
		if($this->input->post())
		{
			$entryId = base64_decode($enc_userID);

			$entryDetails = $this->common_model->getAllRow('event_features',array('id'=>$entryId));

			$arr['event_id'] = $entryDetails['event_id'];
			$arr['entry_id'] = $entryId;
			$arr['created'] = time();
			$arr['type'] = 2;
			$arr['base_price'] = $this->input->post('party_price');
			$arr['extra_night_price'] = $this->input->post('extra_price');
			$arr['room_total'] = $this->input->post('room_total');
			$roomId = $this->common_model->insertData('event_features',$arr);

			$languages = $this->common_model->getAll('sys_languages');
			$arr= array();
			if(!empty($languages))
			{
				foreach ($languages as $value) {
					$arr['event_feature_id'] = $roomId;
					$arr['lang_id'] = $value['id'];
					$arr['title'] = $this->input->post('name_'.$value['id']);
					$arr['content'] = $this->input->post('content_'.$value['id']);
					$this->common_model->insertData('event_features_lang_values',$arr);
				}
			}
			if($_FILES['image']['name']!='')
			{
				$imagefolder = 'img/parties/event_features/';
		        $uploadpath = 'assets/userfiles/'. $imagefolder;
				$config = array(
		            'upload_path' 		=> FCPATH . $uploadpath . '/',
		            'allowed_types' 	=> '*',
		            'encrypt_name' 		=> true,
		            'file_ext_tolower' 	=> true,
		            //'max_size' 			=> (int)MSysSettings::getValue('upload_max_filesize') * 1024,
		        );

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

		            $this->utility->setMsg($this->upload->display_errors(),'ERROR');	
					redirect(base_url().'admin/event/room_add/'.$enc_userID);
		        }

		        $uploaddata = $this->upload->data();

		        $file = array(
		            'user_id' 	=> 1,
		            '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 ' . $username,
		        );

		        $imagesize = getimagesize($uploaddata['full_path']);

		        $file['width'] 	= $imagesize[0];
		        $file['height'] = $imagesize[1];

		        $bannerId = $this->common_model->insertData('sys_files',$file);
		        $this->common_model->UpdateData('event_features',array('image_id'=>$bannerId),array('id'=>$roomId));
			
			}
			redirect(base_url().'admin/event/roomlist/'.$enc_userID);
		}
			
		$content_data = array();
		$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
		$content_data['languages'] = $this->common_model->getAll('sys_languages') ;
		$data['content'] = $this->load->view('admin/events/room_add', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function room_edit($enc_userID='')
	{
		if($enc_userID!='')
		{
			$roomId=base64_decode($enc_userID);
			if($this->input->post())
			{
				$roomsDetails = $this->common_model->getAllRow('event_features',array('id'=>$roomId));

				$arr['base_price'] = $this->input->post('party_price');
				$arr['extra_night_price'] = $this->input->post('extra_price');
				$arr['room_total'] = $this->input->post('room_total');
				$this->common_model->UpdateData('event_features',$arr,array('id'=>$roomId));

				$languages = $this->common_model->getAll('sys_languages');
				$arr= array();
				if(!empty($languages))
				{
					foreach ($languages as $value) {
						$arr['title'] = $this->input->post('name_'.$value['id']);
						$arr['content'] = $this->input->post('content_'.$value['id']);
						$exist = $this->common_model->getAllRow('event_features_lang_values',array('event_feature_id'=>$roomId,'lang_id'=>$value['id']));
						if(empty($exist))
						{
							$arr1['event_feature_id'] = $roomId;
							$arr1['lang_id'] = $value['id'];
							$arr1['title'] = $this->input->post('name_'.$value['id']);
							$arr1['content'] = $this->input->post('content_'.$value['id']);
							$this->common_model->insertData('event_features_lang_values',$arr1);
						}
						else
						{
							$this->common_model->UpdateData('event_features_lang_values',$arr,array('event_feature_id'=>$roomId,'lang_id'=>$value['id']));
						}
					}
				}
				if($_FILES['image']['name']!='')
				{
					$imagefolder = 'img/parties/event_features/';
			        $uploadpath = 'assets/userfiles/'. $imagefolder;
					$config = array(
			            'upload_path' 		=> FCPATH . $uploadpath . '/',
			            'allowed_types' 	=> '*',
			            'encrypt_name' 		=> true,
			            'file_ext_tolower' 	=> true,
			            //'max_size' 			=> (int)MSysSettings::getValue('upload_max_filesize') * 1024,
			        );

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

			            $this->utility->setMsg($this->upload->display_errors(),'ERROR');	
						redirect(base_url().'admin/event/room_edit/'.base64_encode($roomsDetails['entry_id']));
			        }

			        $uploaddata = $this->upload->data();

			        $file = array(
			            'user_id' 	=> 1,
			            '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 ' . $username,
			        );

			        $imagesize = getimagesize($uploaddata['full_path']);

			        $file['width'] 	= $imagesize[0];
			        $file['height'] = $imagesize[1];

			        $bannerId = $this->common_model->insertData('sys_files',$file);
			        $this->common_model->UpdateData('event_features',array('image_id'=>$bannerId),array('id'=>$roomId));
				
				}
				redirect(base_url().'admin/event/roomlist/'.base64_encode($roomsDetails['entry_id']));
			}
			$content_data = array();
			$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
			$content_data['languages'] = $this->common_model->getAll('sys_languages') ;
			$content_data['roomDetail'] = $this->common_model->getAllRowMultipleJoin('event_features',array('event_features.id'=>$roomId),array(array('sys_files','sys_files.id = event_features.image_id')),'event_features.created DESC','event_features.*,sys_files.path,sys_files.filename,sys_files.extension');
			//print_r($content_data); die;
			$data['content'] = $this->load->view('admin/events/room_edit', $content_data, TRUE);
			$this->load->view('admin/layout', $data);
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/roomlist/'.base64_encode($roomsDetails['entry_id']));
		}
	}
	public function extraNightlist($enc_userID='')
	{
		if($enc_userID!='')
		{
			$roomId=base64_decode($enc_userID);
			$content_data = array();
			$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
			$content_data['extra_nights'] = $this->common_model->getAllMultipleJoin('event_features',array('event_features.type'=>3,'room_id'=>$roomId),array(array('sys_files','sys_files.id = event_features.image_id')),'event_features.created DESC','event_features.*,sys_files.path,sys_files.filename,sys_files.extension');
			//echo $this->db->last_query();
			$data['content'] = $this->load->view('admin/events/extraNightlist', $content_data, TRUE);
			$this->load->view('admin/layout', $data);
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/extraNightlist/'.$enc_userID);
		}
	}
	public function extraNight_delete($enc_nightID = '')
	{
		if($enc_nightID!='')
		{
			$extraId=base64_decode($enc_nightID);
			$extraDetail = $this->common_model->getAllRow('event_features',array('id'=>$extraId));
			$this->common_model->deleteData('event_features',array('id'=>$extraId));
			$this->utility->setMsg('Extra Night deleted','SUCCESS');	
			redirect(base_url().'admin/event/extraNightlist/'.base64_encode($extraDetail['room_id']));
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/extraNightlist/'.base64_encode($extraDetail['room_id']));
		}
	}
	public function extraNight_add($enc_userID='')
	{
		$roomId = base64_decode($enc_userID);
		if($this->input->post())
		{
			$roomDetails = $this->common_model->getAllRow('event_features',array('id'=>$roomId));
			$rooms = $this->common_model->getAll('event_features',array('entry_id'=>$roomDetails['entry_id'], 'event_id'=>$roomDetails['event_id'], 'type'=>2));
			//pr($rooms);
			if($this->input->post('date'))
			{
				foreach ($this->input->post('date') as $key => $value) {
					if($value!=''){
						if($rooms){
							foreach ($rooms as $k => $roomval) {
								$arr['event_id'] = $roomDetails['event_id'];
								$arr['entry_id'] = $roomDetails['entry_id'];
								$arr['room_id'] = $roomval['id'];
								$arr['created'] = time();
								$arr['date'] = strtotime($value);
								$arr['type'] = 3;
								$extraId = $this->common_model->insertData('event_features',$arr);
							}
						}
					}
				}
			}
			redirect(base_url().'admin/event/extraNightlist/'.$enc_userID);
		}	
		$content_data = array();
		$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
		$roomdata = $this->common_model->getAllRow('event_features',array('id'=>$roomId));
		$content_data['eventDetails'] = $this->common_model->getAllRow('evt_events',array('id'=>$roomdata['event_id']));
		$data['content'] = $this->load->view('admin/events/extraNight_add', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function extraNight_edit($enc_userID='')
	{
		if($enc_userID!='')
		{
			$extraId = base64_decode($enc_userID);
			if($this->input->post())
			{
				$extraDetails = $this->common_model->getAllRow('event_features',array('id'=>$extraId));
				$arr['date'] = strtotime($this->input->post('date'));
				$this->common_model->UpdateData('event_features',$arr,array('id'=>$extraId));
				
				redirect(base_url().'admin/event/extraNightlist/'.base64_encode($extraDetails['room_id']));
			}	
			$content_data = array();
			$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
			$roomdata = $this->common_model->getAllRow('event_features',array('id'=>$extraId));
			$content_data['eventDetails'] = $this->common_model->getAllRow('evt_events',array('id'=>$roomdata['event_id']));
			$content_data['extraDetails'] = $this->common_model->getAllRow('event_features',array('id'=>$extraId));
			$data['content'] = $this->load->view('admin/events/extraNight_edit', $content_data, TRUE);
			$this->load->view('admin/layout', $data);
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/extraNightlist/'.base64_encode($extraDetails['room_id']));
		}
	}
	public function limousinelist($enc_userID='')
	{
		if($enc_userID!='')
		{
			$entryId=base64_decode($enc_userID);
			$content_data = array();
			$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
			$content_data['limousines'] = $this->common_model->getAllMultipleJoin('event_features',array('event_features.type'=>4,'entry_id'=>$entryId,'event_features_lang_values.lang_id'=>2),array(array('event_features_lang_values','event_features_lang_values.event_feature_id = event_features.id'),array('sys_files','sys_files.id = event_features.image_id')),'event_features.created DESC','event_features.*,sys_files.path,sys_files.filename,sys_files.extension,event_features_lang_values.title');
			//echo $this->db->last_query();
			$data['content'] = $this->load->view('admin/events/limousinelist', $content_data, TRUE);
			$this->load->view('admin/layout', $data);
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/limousinelist/'.$enc_userID);
		}
	}
	public function limousine_delete($enc_roomID = '')
	{
		if($enc_roomID!='')
		{
			$limousineId=base64_decode($enc_roomID);
			$limousineDetail = $this->common_model->getAllRow('event_features',array('id'=>$limousineId));
			$this->common_model->deleteData('event_features',array('id'=>$limousineId));
			$this->utility->setMsg('Room deleted','SUCCESS');	
			redirect(base_url().'admin/event/limousinelist/'.base64_encode($limousineDetail['entry_id']));
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/limousinelist/'.base64_encode($limousineDetail['entry_id']));
		}
	}
	public function limousine_add($enc_userID='')
	{
		if($this->input->post())
		{
			$entryId = base64_decode($enc_userID);

			$entryDetails = $this->common_model->getAllRow('event_features',array('id'=>$entryId));

			$arr['event_id'] = $entryDetails['event_id'];
			$arr['entry_id'] = $entryId;
			$arr['created'] = time();
			$arr['type'] = 4;
			$arr['base_price'] = $this->input->post('limousine_price');
			$limousineId = $this->common_model->insertData('event_features',$arr);

			$languages = $this->common_model->getAll('sys_languages');
			$arr= array();
			if(!empty($languages))
			{
				foreach ($languages as $value) {
					$arr['event_feature_id'] = $limousineId;
					$arr['lang_id'] = $value['id'];
					$arr['title'] = $this->input->post('name_'.$value['id']);
					//$arr['content'] = $this->input->post('content_'.$value['id']);
					$this->common_model->insertData('event_features_lang_values',$arr);
				}
			}
			/*if($_FILES['image']['name']!='')
			{
				$imagefolder = 'img/parties/event_features/';
		        $uploadpath = 'assets/userfiles/'. $imagefolder;
				$config = array(
		            'upload_path' 		=> FCPATH . $uploadpath . '/',
		            'allowed_types' 	=> '*',
		            'encrypt_name' 		=> true,
		            'file_ext_tolower' 	=> true,
		            //'max_size' 			=> (int)MSysSettings::getValue('upload_max_filesize') * 1024,
		        );

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

		            $this->utility->setMsg($this->upload->display_errors(),'ERROR');	
					redirect(base_url().'admin/event/limousine_add/'.$enc_userID);
		        }

		        $uploaddata = $this->upload->data();

		        $file = array(
		            'user_id' 	=> 1,
		            '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 ' . $username,
		        );

		        $imagesize = getimagesize($uploaddata['full_path']);

		        $file['width'] 	= $imagesize[0];
		        $file['height'] = $imagesize[1];

		        $bannerId = $this->common_model->insertData('sys_files',$file);
		        $this->common_model->UpdateData('event_features',array('image_id'=>$bannerId),array('id'=>$limousineId));
			
			}*/
			redirect(base_url().'admin/event/limousinelist/'.$enc_userID);
		}
			
		$content_data = array();
		$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
		$content_data['languages'] = $this->common_model->getAll('sys_languages') ;
		$data['content'] = $this->load->view('admin/events/limousine_add', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function limousine_edit($enc_userID='')
	{
		if($enc_userID!='')
		{
			$limousineId=base64_decode($enc_userID);
			if($this->input->post())
			{
				$limousineDetails = $this->common_model->getAllRow('event_features',array('id'=>$limousineId));

				$arr['base_price'] = $this->input->post('limousine_price');
				$this->common_model->UpdateData('event_features',$arr,array('id'=>$limousineId));

				$languages = $this->common_model->getAll('sys_languages');
				$arr= array();
				if(!empty($languages))
				{
					foreach ($languages as $value) {
						$arr['title'] = $this->input->post('name_'.$value['id']);
						//$arr['content'] = $this->input->post('content_'.$value['id']);
						$exist = $this->common_model->getAllRow('event_features_lang_values',array('event_feature_id'=>$limousineId,'lang_id'=>$value['id']));
						if(empty($exist))
						{
							$arr1['event_feature_id'] = $limousineId;
							$arr1['lang_id'] = $value['id'];
							$arr1['title'] = $this->input->post('name_'.$value['id']);
							$this->common_model->insertData('event_features_lang_values',$arr1);
						}
						else
						{
							$this->common_model->UpdateData('event_features_lang_values',$arr,array('event_feature_id'=>$limousineId,'lang_id'=>$value['id']));
						}
					}
				}
				/*if($_FILES['image']['name']!='')
				{
					$imagefolder = 'img/parties/event_features/';
			        $uploadpath = 'assets/userfiles/'. $imagefolder;
					$config = array(
			            'upload_path' 		=> FCPATH . $uploadpath . '/',
			            'allowed_types' 	=> '*',
			            'encrypt_name' 		=> true,
			            'file_ext_tolower' 	=> true,
			            //'max_size' 			=> (int)MSysSettings::getValue('upload_max_filesize') * 1024,
			        );

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

			            $this->utility->setMsg($this->upload->display_errors(),'ERROR');	
						redirect(base_url().'admin/event/limousine_edit/'.base64_encode($limousineDetails['entry_id']));
			        }

			        $uploaddata = $this->upload->data();

			        $file = array(
			            'user_id' 	=> 1,
			            '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 ' . $username,
			        );

			        $imagesize = getimagesize($uploaddata['full_path']);

			        $file['width'] 	= $imagesize[0];
			        $file['height'] = $imagesize[1];

			        $bannerId = $this->common_model->insertData('sys_files',$file);
			        $this->common_model->UpdateData('event_features',array('image_id'=>$bannerId),array('id'=>$limousineId));
				
				}*/
				redirect(base_url().'admin/event/limousinelist/'.base64_encode($limousineDetails['entry_id']));
			}
			$content_data = array();
			$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
			$content_data['languages'] = $this->common_model->getAll('sys_languages') ;
			$content_data['limousineDetail'] = $this->common_model->getAllRowMultipleJoin('event_features',array('event_features.id'=>$limousineId),array(array('sys_files','sys_files.id = event_features.image_id')),'event_features.created DESC','event_features.*,sys_files.path,sys_files.filename,sys_files.extension');
			//print_r($content_data); die;
			$data['content'] = $this->load->view('admin/events/limousine_edit', $content_data, TRUE);
			$this->load->view('admin/layout', $data);
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/limousinelist/'.base64_encode($limousineDetails['entry_id']));
		}
	}	
	public function guestlist($enc_userID='')
	{
		if($enc_userID!='')
		{
			$eventId=base64_decode($enc_userID);
			$content_data = array();
			$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
			$guestlist = $this->common_model->getAllMultipleJoin('shop_booking_details',array('event_id'=>$eventId,'feu_userdetails.user_id !='=>'','shop_booking_details.cart_id !='=>''),array(array('shop_carts','shop_carts.id = shop_booking_details.cart_id'),array('shop_orders','shop_orders.cart_id = shop_carts.id'),array('feu_userdetails','feu_userdetails.user_id = shop_carts.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')),'shop_orders.payed ASC','*,sum(price) as booking_total,shop_orders.created as book_date, checkin_payment_method_id, checkin_payed','shop_booking_details.cart_id');
			//echo $this->db->last_query();die;
			//print_r($guestlist); die;
			$eventDetails = $this->common_model->getAllRow('evt_events',array('id'=>$eventId));
			$arr = array();
			if(!empty($guestlist))
			{
				$i = 0;
				foreach ($guestlist as $value) 
				{
					if($value['order_id']!='')
					{
					$arr[] = $value;
					$guest = $this->common_model->getAllRowMultipleJoin('event_guest',array('order_id'=>$value['order_id']),'','confirmed ASC');
					//$membership = $this->users_model->getMembershipDetails($value['user_id']);
					$where = "is_booking = 0 and article_id in (4,5) and invoiceAddress = '".$value['email']."'";
					$membership = $this->common_model->getAllRowMultipleJoin('shop_orders',$where,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id')),'shop_orders.created DESC');
					
					$arr[$i]['guest'] = '';
					$usersmembership = 'No membership';
					if($value['free_member'] == 1){
						$usersmembership = 'Free';
					} else if($membership) {
						if($membership['article_id'] == 4) {
							if($membership['payed'] == 1) {
								$usersmembership = 'Premium (Paid)';
							} else {
								$usersmembership = 'Premium (Unpaid)';
							}
						} else {
							if($membership['payed'] == 1) {
								$usersmembership = 'Basic (Paid)';
							} else {
								$usersmembership = 'Basic (Unpaid)';
							}
						}
					}
					$arr[$i]['usersmembership'] = $usersmembership;
					if(!empty($guest))
					{
						$arr[$i]['confirmed'] = $guest['confirmed'];
						$arr[$i]['drinking_package'] = $guest['drinking_package'];
						$arr[$i]['cape'] = $guest['cape'];
						$arr[$i]['ceremonial'] = $guest['ceremonial'];
						$arr[$i]['extra_wish'] = $guest['extra_wish'];
						$arr[$i]['summury'] = $guest['summury'];
						$arr[$i]['additional'] = $guest['additional'];
						$arr[$i]['details_check'] = $guest['details_check'];
						$arr[$i]['payment'] = $guest['payment'];
						$arr[$i]['order_id'] = $value['order_id'];
						$arr[$i]['checkin_payed'] = $value['checkin_payed'];
						$arr[$i]['checkin_payment_method_id'] = $value['checkin_payment_method_id'];
						$arr[$i]['dates'] = '';

						
						//echo '<pre>';print_r($dateDetails);
					}
					$room_Details = $this->common_model->getAllRowMultipleJoin('shop_booking_details',array('cart_id'=>$value['cart_id'],'feature_type'=>2));
					if($room_Details)
					{
						$room_category = $this->common_model->getAllRow('event_features_lang_values',array('event_feature_id'=>$room_Details['feature_id'],'lang_id'=>2));
						$arr[$i]['room_category'] = $room_category['title'];
					}
					$nightsAvailable = getNights('event_features',array('room_id'=>$room_Details['feature_id']));
					//print_r($nightsAvailable);//die;
					$dateDetails = $this->common_model->getAllRowMultipleJoin('shop_booking_details',array('cart_id'=>$value['cart_id'],'feature_type'=>3));
					if($dateDetails)
					{
						$dates = explode(',', $dateDetails['feature_id']);
	                    $date='';

	                    if(!empty($dates))
	                    {
	                      	if(count($dates)==1 && $nightsAvailable > 0)
                          	{
                            	$date = date('d.m.Y', strtotime("+1 day", $eventDetails['time_from']));
                            	//$date = date('d.m.Y',$nightsAvailable['date']);
                          	} else {
                            	foreach ($dates as $dateVal) {
		                        	$val = getValue('event_features',array('id'=>$dateVal));
		                        	if($val['date']!='')
		                        	{
		                        		$date .= date('d.m.Y',$val['date']).',';
		                        	}
		                      	}
                          	}
	                       	$arr[$i]['dates'] = $date;
	                    }
	                    $arr[$i]['feature_id'] = $dateDetails['feature_id'];
	                    $arr[$i]['feature_type'] = $dateDetails['feature_type'];
					}

					
					$order_to_reminder = $this->common_model->getAllRow('order_to_reminder',array('order_id'=>$value['order_id']),'','remind_date DESC','count(*) as total,remind_date');
					//echo $this->db->last_query();die;
					if($order_to_reminder)
					{
						$arr[$i]['remind_date'] = $order_to_reminder['remind_date'];
						$arr[$i]['totalreminder'] = $order_to_reminder['total'];
					}
					$arr[$i]['party_address'] = $this->character_resolve($eventDetails['address']);
					$arr[$i]['member_status'] = '';
					if(!empty($membership))
					{
						$arr[$i]['member_status'] = $membership['id'];
					}
				$i++;
					}
				}
			}
			//echo '<pre>';print_r($arr); 
			//die;
			$content_data['guestlist'] = $arr;
			$data['content'] = $this->load->view('admin/events/guestlist', $content_data, TRUE);
			$this->load->view('admin/layout', $data);
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/');
		}
	}
	function deleteParty($fileId='',$uri='')
	{
		$getFile = $this->common_model->getAllRow('sys_files',array('id'=>$fileId));
		if(empty($getFile))
		{
			redirect(base_url().str_replace('-','/',$uri));
		} 
		else
		{
			$filename = $getFile['filename'].'.'.$getFile['extension'];
			$filename_blur = $getFile['filename'].'_blur.'.$getFile['extension'];
			@unlink(FCPATH.'assets/userfiles/'.$getFile['path'].'/'.$filename);
			@unlink(FCPATH.'assets/userfiles/'.$getFile['path'].'/'.$filename);
			$this->common_model->deleteData('sys_files',array('id'=>$fileId));
			$this->common_model->deleteData('evt_event_files',array('file_id'=>$fileId));
			redirect(base_url().str_replace('-','/',$uri));
		}
	}	
	/***************************************/
	public function dirToArray($dir){
  
			$result = array();
			$cdir = scandir($dir);
		   foreach ($cdir as $key => $value)
		   {
			  if (!in_array($value,array(".","..")))
			  {
				 if (is_dir($dir . DIRECTORY_SEPARATOR . $value))
				 {
					$result[$value] = $this->dirToArray($dir . DIRECTORY_SEPARATOR . $value);
				 }
				 else
				 {
					$result[] = $value;
				 }
			  }
		   }
  		return $result;
	}
	
	public function createThumb($spath, $dpath, $maxd) {
	$info = getimagesize($spath);
    $mime = $info['mime'];
	//var_dump($mime);
	if($mime=='image/png'){
		
			$src = ImageCreateFromPNG($spath);
			if (!$src) {return false;} else {
		  $srcw=imagesx($src);
		  $srch=imagesy($src);
		  if ($srcw<$srch) {$height=$maxd;$width=floor($srcw*$height/$srch);}
		  else {$width=$maxd;$height=floor($srch*$width/$srcw);}
		  if ($width>$srcw && $height>$srch) {$width=$srcw;$height=$srch;}  //if image is actually smaller than you want, leave small (remove this line to resize anyway)
		  $thumb=imagecreatetruecolor($width, $height);
			imagealphablending($thumb, false);
		 //if ($height<100) {imagecopyresized($thumb, $src, 0, 0, 0, 0, $width, $height, imagesx($src), imagesy($src));}
		 // else {
			imagecopyresampled($thumb, $src, 0, 0, 0, 0, $width, $height, imagesx($src), imagesy($src));
			//  }
			
				imagepng($thumb, $dpath,9);
			}
		 return true;
	}else{
	
		$src=@imagecreatefromjpeg($spath);

	if (!$src) {return false;} else {
	  $srcw=imagesx($src);
	  $srch=imagesy($src);
	  if ($srcw<$srch) {$height=$maxd;$width=floor($srcw*$height/$srch);}
	  else {$width=$maxd;$height=floor($srch*$width/$srcw);}
	  if ($width>$srcw && $height>$srch) {$width=$srcw;$height=$srch;}  //if image is actually smaller than you want, leave small (remove this line to resize anyway)
	  $thumb=imagecreatetruecolor($width, $height);
	// if ($height<100) {imagecopyresized($thumb, $src, 0, 0, 0, 0, $width, $height, imagesx($src), imagesy($src));}
	//  else {
		imagecopyresampled($thumb, $src, 0, 0, 0, 0, $width, $height, imagesx($src), imagesy($src));
		//  }
		
			imagejpeg($thumb, $dpath,90);
		}
		 return true;
	}
  
 
	}
	//avater
	public function avater($picval=''){
		//$sizes=array('60','80','120','160','240','320');
	$sizes=array('250','500','750','1000');
	   /*$picdir[]=$this->dirToArray('assets');
		$avatar=$picdir[0]['userfiles']['img']['parties'];*/
				foreach($sizes as $size){
				
				$toWidth=$toHeight=$size;
				//destination path
				$folderpath = 'assets/userfiles/img/parties/'.$toWidth;

				$org_path = 'assets/userfiles/img/parties/'; //source path
				if (!file_exists($folderpath)) { // file exist in target folder
					mkdir($folderpath, 0777, true);
				}
				$source_path = $org_path.'/'.$picval;
				$d_path = $folderpath.'/'.$picval;
				$this->createThumb($source_path,$d_path,$toWidth);
			}//end of avaters resizer
		
		return '1';
	}
	public function delete_guest($enc_userID='',$uri='')
	{
		if($enc_userID!='')
		{
			$eventId=base64_decode($enc_userID);
			$this->common_model->deleteData('shop_orders',array('order_id'=>$eventId));
			$this->utility->setMsg('Event guest deleted','SUCCESS');	
			redirect(base_url().str_replace('-', '/', $uri));
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().str_replace('-', '/', $uri));
		}
	}
	public function locationlist()
	{
		$content_data = array();
		$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
		$content_data['locations'] = $this->common_model->getAllMultipleJoin('loc_locations',array('name !='=>''),'','name ASC');
		//print_r($content_data); die;
		$data['content'] = $this->load->view('admin/location/list', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function location_delete($enc_roomID = '')
	{
		if($enc_roomID!='')
		{
			$locationId=base64_decode($enc_roomID);
			$this->common_model->deleteData('loc_locations',array('id'=>$locationId));
			$this->utility->setMsg('Location deleted','SUCCESS');	
			redirect(base_url().'admin/event/locationlist');
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/locationlist');
		}
	}
	public function location_add($enc_userID='')
	{
		if($this->input->post())
		{
			$arr['created'] = time();
			$arr['name'] = $this->input->post('name_2');
			$arr['alias'] = str_replace(' ','-',trim(strtolower($this->input->post('name_2'))));
			$arr['city'] = $this->input->post('city_2');
			$arr['country'] = $this->input->post('country_2');
			$locationId = $this->common_model->insertData('loc_locations',$arr);
			$languages = $this->common_model->getAll('sys_languages');
			$arr= array();
			if(!empty($languages))
			{
				foreach ($languages as $value) {
					$arr['location_id'] = $locationId;
					$arr['lang_id'] = $value['id'];
					$arr['name'] = $this->input->post('name_'.$value['id']);
					$arr['city'] = $this->input->post('city_'.$value['id']);
					$arr['country'] = $this->input->post('country_'.$value['id']);
					$this->common_model->insertData('loc_location_lang_values',$arr);
				}
			}
			redirect(base_url().'admin/event/locationlist');
		}	
		$content_data = array();
		$content_data['language'] = $this->common_model->getAll('sys_languages');
		$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
		$data['content'] = $this->load->view('admin/location/add', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function location_edit($enc_userID='')
	{
		if($enc_userID!='')
		{
			$locationId=base64_decode($enc_userID);
			if($this->input->post())
			{
				$arr['name'] = $this->input->post('name_2');
				$arr['city'] = $this->input->post('city_2');
				$arr['country'] = $this->input->post('country_2');
				$this->common_model->UpdateData('loc_locations',$arr,array('id'=>$locationId));
				
				$languages = $this->common_model->getAll('sys_languages');
				$arr= array();
				if(!empty($languages))
				{
					foreach ($languages as $value) {
						$arr1['name'] = $this->input->post('name_'.$value['id']);
						$arr1['city'] = $this->input->post('city_'.$value['id']);
						$arr1['country'] = $this->input->post('country_'.$value['id']);
						$exist = $this->common_model->getAllRow('loc_location_lang_values',array('location_id'=>$locationId,'lang_id'=>$value['id']));
						if(empty($exist))
						{
							$arr['location_id'] = $locationId;
							$arr['lang_id'] = $value['id'];
							$arr['name'] = $this->input->post('name_'.$value['id']);
							$arr['city'] = $this->input->post('city_'.$value['id']);
							$arr['country'] = $this->input->post('country_'.$value['id']);
							$this->common_model->insertData('loc_location_lang_values',$arr);
						}
						else
						{
							$this->common_model->UpdateData('loc_location_lang_values',$arr1,array('location_id'=>$locationId,'lang_id'=>$value['id']));
						}
					}
				}
				redirect(base_url().'admin/event/locationlist');
			}	
			$content_data = array();
			$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
			$content_data['locationDetail'] = $this->common_model->getAllRowMultipleJoin('loc_locations',array('id'=>$locationId));
			//print_r($content_data); die;
			$content_data['language'] = $this->common_model->getAll('sys_languages');
			$data['content'] = $this->load->view('admin/location/edit', $content_data, TRUE);
			$this->load->view('admin/layout', $data);
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/locationlist');
		}
	}
	public function sendSMS($enc_userID='',$enc_evtID='',$uri='')
    {
        if($enc_userID!='')
        {
            $userId=base64_decode($enc_userID);
            $eventId=base64_decode($enc_evtID);
            $userdetails = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$userId));
            $eventdetails = $this->common_model->getAllRow('evt_events',array('id'=>$eventId));
            if(!empty($userdetails) && !empty($eventdetails))
            {
                if($eventdetails['address']!='')
                {
                    $url = "https://api.budgetsms.net/sendsms/?username=CASTLE&handle=ba04586987ec104e74b2374f59d51593&userid=18554&msg=".str_replace('%C2%A0','+',urlencode(html_entity_decode(strip_tags($this->character_resolve($eventdetails['address'])),ENT_QUOTES)))."&from=Castle&to=".$userdetails['mobile_number']; 
                    //$url = "https://bulksms.vsms.net/eapi/submission/send_sms/2/2.0?username=Sakrileg&password=ppp79111&message=".str_replace('%C2%A0','+',urlencode(html_entity_decode(strip_tags($this->character_resolve($eventdetails['address'])),ENT_QUOTES)))."&msisdn=".$userdetails['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); 
                    if($result)
                    {
                        $output = explode('|', $result);
                        if(!empty($output))
                        {
                            if($output[0]==0)
                            {
                                $this->utility->setMsg('SMS send successfully','SUCCESS');  
                                redirect(base_url().str_replace('-', '/', $uri));
                            }
                            else
                            {
                                $this->utility->setMsg($output[1],'ERROR'); 
                                redirect(base_url().str_replace('-', '/', $uri));
                            }
                        }
                        else
                        {
                            $this->utility->setMsg('Sorry some error occured','ERROR'); 
                            redirect(base_url().str_replace('-', '/', $uri));
                        }
                    }
                    else
                    {
                        $this->utility->setMsg('Sorry some error occured','ERROR'); 
                        redirect(base_url().str_replace('-', '/', $uri));
                    }
                }
                else
                {
                    $this->utility->setMsg('First fill address','ERROR');   
                    redirect(base_url().str_replace('-', '/', $uri));
                }
            }
            else
            {
                $this->utility->setMsg('Invalid id','ERROR');   
                redirect(base_url().str_replace('-', '/', $uri));
            }
        }
        else
        {
            $this->utility->setMsg('Invalid id','ERROR');   
            redirect(base_url().str_replace('-', '/', $uri));
        }
    }
	public function sendBulkSMS()
	{
		if($this->input->post())
		{
			$url=explode(',',$this->input->post('url'));
			$uri=$this->input->post('uri');
			$party_address=str_replace('%C2%A0','+',urlencode(html_entity_decode(strip_tags($this->character_resolve($this->input->post('party_address'))),ENT_QUOTES)));
			if($url){
				foreach ($url as $key => $value) {
					$url = "https://api.budgetsms.net/sendsms/?username=CASTLE&handle=ba04586987ec104e74b2374f59d51593&userid=18554&msg=".$party_address."&from=Castle&to=+".trim($value); 
					$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);
				}
			}
			if($result)
			{
				$this->utility->setMsg('SMS send successfully','SUCCESS');	
				redirect(base_url().str_replace('-', '/', $uri));
			}
			else
			{
				$this->utility->setMsg('Sorry some error occured','ERROR');	
				redirect(base_url().str_replace('-', '/', $uri));
			}
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().str_replace('-', '/', $uri));
		}
	}
	public function sendReminder($enc_userID='',$enc_eventID='',$uri='')
	{
		if($enc_userID!='')
		{
			$userId=base64_decode($enc_userID);
			$userdata = $this->common_model->getAllRowMultipleJoin('feu_userdetails',array('user_id'=>$userId),array(array('usr_users','usr_users.id = feu_userdetails.user_id')));
			//print_r($cartDetail); die;
			//$to = 'sayan@digitalaptech.com';
			$to = $userdata['email'];
			$sub = getAdminLang('VALIDATE_YOUR_MOBILE_NUMBER',$userdata['userlanguage']);
			$this->load->library('Utility');
			$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>'.getAdminLang('Hello',$userdata['userlanguage']).' <span style="text-transform:capitalize">'.$userdata['username'].'</span> </h2>
	                                </td>
	                             </tr>
	                             <tr>
	                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
	                                   <p>
	                                      '.getAdminLang('Before_attending_the_party',$userdata['userlanguage']).'
	                                      <br/><br/>
	                                      '.getAdminLang('On_that_number_we_will_send_you_36_hours',$userdata['userlanguage']).'
	                                      <br/><br/>
	                                      '.getAdminLang('After_full_filled_validation_you',$userdata['userlanguage']).'
	                                      
	                                   </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;">
	                             		'.getAdminLang('Best_regards',$userdata['userlanguage']).' <br>
	                             		<p style="margin:5px 0 0">'.getAdminLang('Your_team_of_castleevents',$userdata['userlanguage']).'</p> 
	                             	</td>
	                             </tr>
	                          </table>
	                       </td>
	                    </tr>
	                </table>';//echo $body; die;
			$mail_send = $this->utility->sendCIMail($to,$sub,$body);
			//$this->utility->sendMail($to,$sub,$body);

			$this->utility->setMsg('Reminder sent successfully','SUCCESS');	
			redirect(base_url().str_replace('-', '/', $uri));
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().str_replace('-', '/', $uri));
		}
	}
	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 is_sold($enc_userID='',$status='')
	{
		if($enc_userID!='')
		{
			$userId=base64_decode($enc_userID);
			$this->common_model->UpdateData('evt_events',array('is_sold'=>$status),array('id'=>$userId));
			$this->utility->setMsg('Event solded out','SUCCESS');	
			redirect(base_url().'admin/event');
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event');
		}
	}
	public function check_revenue()
	{
		$id=$this->input->post('id');
		$revenue = $this->common_model->getAllMultipleJoin('shop_orders',array('event_id'=>$id,'payed'=>1),array(array('shop_carts','shop_orders.cart_id = shop_carts.id'),array('shop_booking_details','shop_booking_details.cart_id = shop_carts.id'),array('usr_users','usr_users.id = shop_carts.user_id')),'shop_orders.created DESC','email,total_sum, payment_method_id, payed','shop_booking_details.cart_id');
		
		$html = '<table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>#</th>
                  <th>Email</th>
                  <th>Amount(&euro;)</th>
                  <th>Payment Status</th>
                  <th>Payment Mode</th>
                </tr>
                </thead>';
                if(count($revenue)>0)
				{
		$html .= '<tbody>';
                $i=1;
                $total = 0;
	                foreach ($revenue as $data) 
	                {
	                	if($data['payment_method_id']==12){ 
	                		$payment_method = 'Bank Transfer'; 
	                	} elseif($data['payment_method_id']==13){ 
	                		$payment_method = 'Saferpay'; 
	                	} elseif($data['payment_method_id']==14){ 
	                		$payment_method = 'Stripe'; 
	                	} else{ 
	                		$payment_method = 'Pay By Bank'; 
	                	}

	                	if($data['payed']==1){ 
	                		$status = 'Paid';
	                	} else{ 
	                		$status = 'Unpaid'; 
	                	}
	                	if($data['email']!='')
	                	{
	                		$total = $total+$data['total_sum'];
	        $html .='<tr>
	                    <td>'.$i.'</td>
	                    <td>'.$data['email'].'</td>
	                    <td>'.number_format($data['total_sum']/100, 2,',', '.').'</td>
	                    <td>'.$status.'</td>
	                    <td>'.$payment_method.'</td>
	                </tr>';
					$i++; }
					} 
                }
                else
                {
        $html .='<tr>
                    <td colspan="3">No records found...</td>
                </tr>';        	
                }
        $html .='<tr>
                    <td colspan="3" style="color:orange">Total Revenue: '.number_format($total/100, 2,',', '.').' &euro;</td>
                </tr>';        
        $html .='</tbody>'; 
        $html .='<tfoot>
                </tfoot>
              </table>';
		echo $html; die;
	}

	public function checkin_revenue()
	{
		$id=$this->input->post('id');
		$revenue = $this->common_model->getAllMultipleJoin('shop_orders',array('event_id'=>$id,'checkin_amount >'=>0),array(array('shop_carts','shop_orders.cart_id = shop_carts.id'),array('shop_booking_details','shop_booking_details.cart_id = shop_carts.id'),array('usr_users','usr_users.id = shop_carts.user_id')),'shop_orders.created DESC','email,checkin_amount,checkin_payed','shop_booking_details.cart_id');
		$html = '<table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>#</th>
                  <th>Email</th>
                  <th>Amount(&euro;)</th>
                  <th>Payment Status</th>
                </tr>
                </thead>';
                if(count($revenue)>0)
				{
		$html .= '<tbody>';
                $i=1;
                $total = 0;
	                foreach ($revenue as $data) 
	                {
	                	if($data['email']!='')
	                	{
	                		$total = $total+$data['checkin_amount'];
	        $html .='<tr>
	                    <td>'.$i.'</td>
	                    <td>'.$data['email'].'</td>
	                    <td>'.number_format($data['checkin_amount'], 2,',', '.').'</td>
	                    <td>'.(($data['checkin_payed']==1)?'Paid':'Unpaid').'</td>
	                </tr>';
					$i++; }
					} 
                }
                else
                {
        $html .='<tr>
                    <td colspan="4">No records found...</td>
                </tr>';        	
                }
        $html .='<tr>
                    <td colspan="4" style="color:orange">Total Revenue: '.number_format($total, 2,',', '.').' &euro;</td>
                </tr>';        
        $html .='</tbody>'; 
        $html .='<tfoot>
                </tfoot>
              </table>';
		echo $html; die;
	}
	public function reminder($enc_userID='',$uri='')
	{
		if($enc_userID!='')
		{
			$orderId=base64_decode($enc_userID);
			$orderDetail = $this->common_model->getAllRow('shop_orders',array('order_id'=>$orderId));
			$cartDetail = $this->common_model->getAllRow('shop_carts',array('id'=>$orderDetail['cart_id']));
			$userDetail = $this->common_model->getAllRowMultipleJoin('feu_userdetails',array('user_id'=>$cartDetail['user_id']),array(array('usr_users','usr_users.id = feu_userdetails.user_id')));
			
			$eventDetail = $this->common_model->getAllRowMultipleJoin('shop_booking_details',array('cart_id'=>$orderDetail['cart_id']),array(array('evt_events','evt_events.id = shop_booking_details.event_id')));
			$title = '';
			$event_id = 0;
			if(count($eventDetail)>0)
			{
				$title = $eventDetail['title'];
				$event_id = $eventDetail['event_id'];
			}
			$instArr = array(
								'order_id'=>$orderId,
								'order_created'=>$orderDetail['created'],
								'remind_date'=>date('Y-m-d'),
								'user_id'=>$userDetail['user_id'],
								'event_id'=>$event_id,
							);
			$this->common_model->insertData('order_to_reminder',$instArr);

			$order_to_reminder = $this->common_model->getAll('order_to_reminder',array('order_id'=>$orderId));
			$this->load->library('Utility');
			//print_r($cartDetail); die;
			$to = $userDetail['email'];
	        $sub = getAdminLang('Payment_reminder',$userDetail['userlanguage']).' CE-'.$orderDetail['order_id'];
			
	        if(count($order_to_reminder)>=4)
			{
				$body= '<p>'.getAdminLang('After_reviewing_your_booking_for_our',$userDetail['userlanguage']).' '.$title.' '.getAdminLang('we_havent_found_the_payment',$userDetail['userlanguage']).'. </p>';
				$body.= '<p>'.getAdminLang('We_already_send_you_several_reminders',$userDetail['userlanguage']).'.</p>';
				$body.= '<p>'.getAdminLang('The_booking_for_our_event_was_a_binding_reservation',$userDetail['userlanguage']).':</p>';
				$body.= '<br/><p>'.getAdminLang('If_the_payment_has_been_made_recently',$userDetail['userlanguage']).'.</p>';
				$body.= '<br/><p>'.getAdminLang('Your_Castleevents_Team',$userDetail['userlanguage']).'.</p>';
				$bodys=' <table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
	                    <tr>
	                       <td>
	                          <table cellspacing="0" cellpadding="0" border="0" width="100%">
	                             <tr>
	                                <td align="center" style="padding: 40px; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #b3975b;">
	                                   <h2>'.getAdminLang('Good_afternoon',$userDetail['userlanguage']).' <span style="text-transform:capitalize">'.$userDetail['username'].'</span> </h2>
	                                </td>
	                             </tr>
	                             <tr>
	                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
	                                   '.$body.'
	                                </td>
	                             </tr>
	                          </table>
	                       </td>
	                    </tr>
	                </table>';
			}
			else
			{
				$site_address_name = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_name'));
				$site_address_city = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_city'));
				$site_address_country_zip = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_country_zip'));

				$body= '<p>'.getAdminLang('We_would_like_to_remind_you',$userDetail['userlanguage']).' '.($orderDetail['total_sum']/100).' EUR '.getAdminLang('of_your_order_from',$userDetail['userlanguage']).' '.date('Y-m-d',$orderDetail['created']).' '.getAdminLang('is_still_unpaid_after',$userDetail['userlanguage']).' 7-'.getAdminLang('day_payment_obligation',$userDetail['userlanguage']).'. </p>';
				$body.= '<p>'.getAdminLang('Please_arrange_the_appropriate_payment_within',$userDetail['userlanguage']).' 3-'.getAdminLang('days_or_contact_us_to_make',$userDetail['userlanguage']).'.</p>';
				$body.= '<p><strong>IBAN:</strong> CH810023123110716660E</p>
	                     <p><strong>'.getAdminLang('Clearing',$userDetail['userlanguage']).':</strong> 231</p>
	                     <p><strong>'.getAdminLang('Swift',$userDetail['userlanguage']).':</strong> UBSWCHZH80A</p>
	                     <p><strong>'.getAdminLang('Payment_Reason',$userDetail['userlanguage']).':</strong> '.$orderDetail['order_id_masked'].'</p>
	                     <p><strong>'.getAdminLang('Amount',$userDetail['userlanguage']).':</strong> <span class="total">'.($orderDetail['total_sum']/100).' EUR</span></p>
	                     <p><strong>'.getAdminLang('Bank',$userDetail['userlanguage']).':</strong> UBS, Bahnhofstrasse 1, 5000 Aarau, '.getAdminLang('Switzerland',$userDetail['userlanguage']).'</p>
	                     <p><strong>'.getAdminLang('Recipient',$userDetail['userlanguage']).':</strong> '.$site_address_name['value'].', '.$site_address_city['value'].', '.$site_address_country_zip['value'].'</p>';
				$body.= '<p>'.getAdminLang('If_you_have_any_questions_about_your_order',$userDetail['userlanguage']).':</p>';
				$body.= '<br/><p>'.getAdminLang('Customer_Services_Events',$userDetail['userlanguage']).'</p>';
				$body.= '<p>info@castleevents.com</p>';

				$body.= '<br/><p>'.getAdminLang('If_the_payment_has_been_made_recently',$userDetail['userlanguage']).'.</p>';
				$body.= '<br/><p>'.getAdminLang('Your_Castleevents_Team',$userDetail['userlanguage']).'.</p>';
				//$body.= '<p>Best regards,</p><p>Your Castleevents Team </p>';
				$bodys=' <table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
		                    <tr>
		                       <td>
		                          <table cellspacing="0" cellpadding="0" border="0" width="100%">
		                             <tr>
		                                <td align="center" style="padding: 40px; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #b3975b;">
		                                   <h2>Dear <span style="text-transform:capitalize">'.$userDetail['username'].'</span> </h2>
		                                </td>
		                             </tr>
		                             <tr>
		                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
		                                   '.$body.'
		                                </td>
		                             </tr>
		                          </table>
		                       </td>
		                    </tr>
		                </table>';
		    }
	        //echo $bodys; die;
			$this->utility->sendCIMail($to,$sub,$bodys);

			$this->utility->setMsg('Reminder sent successfully','SUCCESS');	
			redirect(base_url().str_replace('-', '/', $uri));
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().str_replace('-', '/', $uri));
		}
	}
	public function download_guestlist($enc_userID)
	{
		$eventId=base64_decode($enc_userID);
		$content_data = array();
		$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
		$guestlist = $this->common_model->getAllMultipleJoin('shop_booking_details',array('event_id'=>$eventId,'feu_userdetails.user_id !='=>'','shop_booking_details.cart_id !='=>''),array(array('shop_carts','shop_carts.id = shop_booking_details.cart_id'),array('shop_orders','shop_orders.cart_id = shop_carts.id'),array('feu_userdetails','feu_userdetails.user_id = shop_carts.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')),'username ASC','*,sum(price) as booking_total,shop_orders.created as book_date, checkin_payment_method_id,checkin_payed','shop_booking_details.cart_id');
		//print_r($guestlist); die;
		//$guestlist = $this->common_model->getAllMultipleJoin('event_guest',array('event_id'=>$eventId,'user_id !='=>''),array(array('feu_userdetails','feu_userdetails.username = event_guest.username'),array('usr_users','usr_users.id = feu_userdetails.user_id')),'event_guest.confirmed DESC');
		$eventDetails = $this->common_model->getAllRow('evt_events',array('id'=>$eventId));
		$arr = array();
		if(!empty($guestlist))
		{
			$i = 0;
			foreach ($guestlist as $value) 
			{
				if($value['order_id']!='')
				{
					$arr[] = $value;
					$guest = $this->common_model->getAllRowMultipleJoin('event_guest',array('order_id'=>$value['order_id']),'','confirmed ASC');
					//$membership = $this->users_model->getMembershipDetails($value['user_id']);
					$where = "is_booking = 0 and article_id in (4,5) and invoiceAddress = '".$value['email']."'";
					$membership = $this->common_model->getAllRowMultipleJoin('shop_orders',$where,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id')),'shop_orders.created DESC');
					
					$arr[$i]['guest'] = '';
					$usersmembership = 'No membership';
					if($value['free_member'] == 1){
						$usersmembership = 'Free';
					} else if($membership) {
						if($membership['article_id'] == 4) {
							if($membership['payed'] == 1) {
								$usersmembership = 'Premium (Paid)';
							} else {
								$usersmembership = 'Premium (Unpaid)';
							}
						} else {
							if($membership['payed'] == 1) {
								$usersmembership = 'Basic (Paid)';
							} else {
								$usersmembership = 'Basic (Unpaid)';
							}
						}
					}
					$arr[$i]['usersmembership'] = $usersmembership;
					$arr[$i]['book_date'] = $value['book_date'];
					if(!empty($guest))
					{
						$arr[$i]['confirmed'] = $guest['confirmed'];
						$arr[$i]['drinking_package'] = $guest['drinking_package'];
						$arr[$i]['drinking_price'] = $guest['drink_price'];
						$arr[$i]['cape'] = $guest['cape'];
						$arr[$i]['ceremonial'] = $guest['ceremonial'];
						$arr[$i]['extra_wish'] = $guest['extra_wish'];
						$arr[$i]['additional'] = $guest['additional'];
						$arr[$i]['summury'] = $guest['summury'];
						$arr[$i]['details_check'] = $guest['details_check'];
						$arr[$i]['payment'] = $guest['payment'];
						$arr[$i]['order_id'] = $value['order_id']. (($data['is_exchanged'] == 1) ? ' (Exchanged Order)' : '');
						$arr[$i]['checkin_payment_method_id'] = $value['checkin_payment_method_id'];
						$arr[$i]['checkin_payed'] = $value['checkin_payed'];
					}
					$arr[$i]['extra_night_dates'] = '';
					$arr[$i]['entry'] = '--';
					$arr[$i]['room'] = '--';
					$entryDetails = $this->common_model->getAllRowMultipleJoin('shop_booking_details',array('cart_id'=>$value['cart_id'],'feature_type'=>1));
					$roomDetails = $this->common_model->getAllRowMultipleJoin('shop_booking_details',array('cart_id'=>$value['cart_id'],'feature_type'=>2));
					$extra_night_dateDetails = $this->common_model->getAllRowMultipleJoin('shop_booking_details',array('cart_id'=>$value['cart_id'],'feature_type'=>3));
					$nightsAvailable = getNights('event_features',array('room_id'=>$roomDetails['feature_id']));
					if($extra_night_dateDetails)
					{
						$dates = explode(',', $extra_night_dateDetails['feature_id']);
	                    $date='';
	                    if(!empty($dates))
	                    {
	                      	if(count($dates)==1 && $nightsAvailable > 0)
                          	{
                            	$date = date('d.m.Y', strtotime("+1 day", $eventDetails['time_from']));
                            	//$date = date('d.m.Y',$nightsAvailable['date']);
                          	} else {
		                      	foreach ($dates as $dateVal) {
		                        	$val = getValue('event_features',array('id'=>$dateVal));
		                        	if($val['date']!='')
		                        	{
		                        		$date .= date('d.m.Y',$val['date']).',';
		                        	}
		                      	}
		                      }
	                       	$arr[$i]['extra_night_dates'] = $date;
	                    }
					}

					if($entryDetails)
					{
						$entry = getValue('event_features_lang_values',array('event_feature_id'=>$entryDetails['feature_id'],'lang_id'=>2));
						$arr[$i]['entry'] = $entry['title'];
					}

					if($roomDetails)
					{
						$room = getValue('event_features_lang_values',array('event_feature_id'=>$roomDetails['feature_id'],'lang_id'=>2));
						$arr[$i]['room'] = $room['title'];
					}
					$order_to_reminder = $this->common_model->getAllRow('order_to_reminder',array('order_id'=>$value['order_id']),'','remind_date DESC','count(*) as total,remind_date');
					//echo $this->db->last_query();die;
					if($order_to_reminder)
					{
						$arr[$i]['remind_date'] = $order_to_reminder['remind_date'];
						$arr[$i]['totalreminder'] = $order_to_reminder['total'];
					}
					/*Total participated by a user*/
					$totalParticipate = getAllCount('event_guest', array('username'=>$value['username']));
					$arr[$i]['totalParticipate'] = $totalParticipate;
					/*Total participated by a user*/
				$i++;
				}
			}
		}
		//echo '<pre>';print_r($arr); 
		//die;
		$guestarr = $arr;
		//echo $this->db->last_query();die;
		/*if($guestarr)
		{ 
			$html='<style>
				   	body {font-family: sans-serif;
					    font-size: 10pt;
					}
					p { margin: 0pt;
					}
					td { vertical-align: top; }
					.items td {
					    border-left: 0.1mm solid #000000;
					    border-right: 0.1mm solid #000000;
					}
					table thead td { background-color: #b3975b;
					    border: 0.1mm solid #000000;
					    color: #fff;
					}
					.items td.blanktotal {
					    background-color: #FFFFFF;
					    border: 0mm none #000000;
					    border-top: 0.1mm solid #000000;
					    border-right: 0.0mm solid #000000;
					}
					.items td.totals {
					    text-align: right;
					    border-top: 0.1mm solid #000000;
					    border-right: 0.0mm solid #000000;
					    border-left: 0.0mm solid #000000;
					}
					.items td.totals1 {
					    text-align: right;
					    border-top: 0.0mm solid #000000;
					    border-right: 0.0mm solid #000000;
					    border-left: 0.0mm solid #000000;
					}
				   </style>
				   							  
				         <h2 style="padding: 10px;border-bottom:1px solid #ccc; display: block;">'.$eventDetails['title'].' -- Guestlist</h2>
				         <table class="items" width="100%" style="font-size: 9pt; border-collapse: collapse;" cellpadding="8">
						    <thead>
						        <tr>
							        <td style="padding:10px ; font-weight: bold; height: 19px; line-height: 19px; float: left;">Pseudonym</td>';
							        if($this->session->userdata('admin_id')==25267 || $this->session->userdata('admin_id')==19624){ 
			$html.=									'<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">Email</td>'; 
												}
			$html.=					'<td style="padding:10px ; font-weight: bold; height: 19px; line-height: 19px; float: left;">Membership (Payment Status)</td>
							        <td style="padding:10px ; font-weight: bold; height: 19px; line-height: 19px; float: left;">Order no.</td>
					               	<td style="padding:10px ; font-weight: bold; float: left; height: 19px; line-height: 19px;">Order Date</td>
					               	<td style="padding:10px ; font-weight: bold; float: left; height: 19px; line-height: 19px;">Article</td>
					               	<td style="padding:10px ; font-weight: bold; float: left; height: 19px; line-height: 19px;">Extra Nights</td>
					               	<td style="padding:10px ; font-weight: bold; float: left; height: 19px; line-height: 19px;">Drink Package</td>
					               	<td style="padding:10px ; font-weight: bold; float: left; height: 19px; line-height: 19px;">Cape</td>
					               	<td style="padding:10px ; font-weight: bold; float: left; height: 19px; line-height: 19px;">Ceremonial</td>
					               	<td style="padding:10px ; font-weight: bold; float: left; height: 19px; line-height: 19px;">Additional Step</td>
					               	<td style="padding:10px ; font-weight: bold; float: left; height: 19px; line-height: 19px;">Extra Wish</td>
					               	<td style=" font-weight: bold; padding:10px ; float: left; height: 19px; line-height: 19px;">Booking Total(&euro;)</td>
					               	<td style=" font-weight: bold; padding:10px ; float: left; height: 19px; line-height: 19px;">Booking Payment Status</td>
					               	<td style=" font-weight: bold; padding:10px ; float: left; height: 19px; line-height: 19px;">Booking Payment Type</td>
				         		</tr>
				         	</thead>';
				            if(!empty($guestarr)){ 
					         		$guestlist_total=0;
					         		foreach ($guestarr as $key=>$data) {
					         			if($data['payed']==1){
					         				$guestlist_total+=$data['total_sum'];
					         			}
						            	
			$html.='					<tbody style="border-bottom:1px solid #000;">
											<tr style="width: 100%; float: left; padding-left:10px;">         	
								 			   	<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">'.$data['username'].'</td>';
								 			   	if($this->session->userdata('admin_id')==25267 || $this->session->userdata('admin_id')==19624){ 
			$html.=									'<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">'.$data['invoiceAddress'].'</td>'; 
												}
			$html.=				'<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">'.$data['usersmembership'].'</td>
								 			   	<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">'.$data['order_id_masked'].'</td>
								               	<td style="padding:10px ; float: left; height: 19px; line-height: 19px;">'.date('d-m-Y',$data['book_date']).'</td>
								               	<td style="padding:10px ; float: left; height: 19px; line-height: 19px;"><strong>Entry:</strong> '.$data['entry'].', <strong>Room:</strong> '.$data['room'].'</td>
								               	<td style="padding:10px ; float: left; height: 19px; line-height: 19px;">'.trim($data['extra_night_dates'],',').'</td>';
								               	if($data['drinking_package']==1){ 
			$html.=									'<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">Basic</td>'; 
												} 
												elseif($data['drinking_package']==2){ 
			$html.=									'<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">Premium</td>'; 
												}
												else{ 
			$html.=									'<td style="padding:10px ; height: 19px; line-height: 19px; float: left;"></td>'; 
												}
			$html.=						        '<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">'.$data['cape'].'</td>';
								               	if($data['ceremonial']==1){ 
			$html.=									'<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">Accepted</td>'; 
												}
												else{
			$html.=									'<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">--</td>'; 
												}
			$html.=					            '<td style=" padding:10px ; float: left; height: 19px; line-height: 19px;">'.number_format($data['additional'],2,',','.').'</td><td style="padding:10px ; height: 19px; line-height: 19px; float: left;">'.(($data['extra_wish']!='')?$data['extra_wish']:'--').'</td>
								               	<td style=" padding:10px ; float: left; height: 19px; line-height: 19px;">'.number_format($data['total_sum']/100,2,',','.').'</td>';
								               	if($data['payed']==1){ 
			$html.=									'<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">Paid</td>'; 
												} 
												else{ 
			$html.=									'<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">Unpaid</td>'; 
												}
								               	if($data['payment_method_id']==12){ 
			$html.=					               	'<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">Bank Transfer</td>'; 
												} 
												elseif($data['payment_method_id']==13){ 
			$html.=									'<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">Saferpay</td>'; 
												} 
												elseif($data['payment_method_id']==14){ 
			$html.=									'<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">Stripe</td>'; 
												} 
												else{ 
			$html.=									'<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">Pay By Bank</td>'; 
												}
			$html.=					        '</tr>';	
									}
						        }
			$html.='			</tbody>
							</table>
							<table  width="100%" style="font-size: 9pt; border-collapse: collapse;" cellpadding="8">
                               <tbody>
                                   <tr style="background:#ddd;">
                                    <td style="padding:10px; border-top:2px solid #000; width:30%; font-weight: bold;">Total Participants</td>
									<td style="padding:10px; border-top:2px solid #000; font-weight: bold;">'.count($guestarr).' Bookings</td>
									<td style="padding:10px; border-top:2px solid #000; width:30%; font-weight: bold;">Checkin Amount Total</td>
									<td style="padding:10px; border-top:2px solid #000; font-weight: bold;">'.number_format($guestlist_total/100, 2,',', '.').' &euro;</td>
								 </tr>
                               </tbody>
							</table>';
		}		
        //echo $html;die;
        $pdfFilePath = "Guestlist_".$eventDetails['title'].".pdf";
        $this->load->library('m_pdf');

        $this->m_pdf->pdf->useOnlyCoreFonts = true;    // false is default
		//$this->m_pdf->pdf->SetProtection(array('print'));
		$this->m_pdf->pdf->SetTitle("Castleevents Title");
		$this->m_pdf->pdf->SetAuthor("Author");
		
		$this->m_pdf->pdf->SetDisplayMode('fullpage'); 
		$this->m_pdf->pdf->WriteHTML($html);
		$this->m_pdf->pdf->Output($pdfFilePath, "D"); */



				if($guestarr){
					$csv_fields=array();
					$csv_fields[] = 'Pseudonym';
					if($this->session->userdata('admin_id')==25267 || $this->session->userdata('admin_id')==19624){ 
					$csv_fields[] = 'Email';
					}
					$csv_fields[] = 'Membership (Payment Status)';
					$csv_fields[] = 'Order No.';
					$csv_fields[] = 'Order Date';
					$csv_fields[] = 'Article';
					$csv_fields[] = 'Extra Nights';
					$csv_fields[] = 'Drink Package';
					$csv_fields[] = 'Cape';
					$csv_fields[] = 'Ceremonial';
					$csv_fields[] = 'Additional Step';
					$csv_fields[] = 'Extra Wish';
					$csv_fields[] = 'Checkin Total';
					$csv_fields[] = 'Booking Total';
					$csv_fields[] = 'Rest Payment At Arrival';
					$csv_fields[] = 'Booking Payment Status';
					$csv_fields[] = 'Booking Payment Type';
					$csv_fields[] = 'Is Exchanged Order';
					$csv_fields[] = 'Total Participation';

					$output_filename = 'Guestlist_'.$eventDetails['title'].'.csv';
					$output_handle = @fopen( 'php://output', 'w' );
					
					header( 'Content-type: text/csv' );
					header( 'Content-Disposition: attachment; filename=' . $output_filename );
					
					fputcsv( $output_handle, $csv_fields );
					$i=1;
					$package_name = '';
					$ceremony = '';
					$payment_type = 'Pay By Bank';
					$guestlist_total=0;
	         		foreach ($guestarr as $key=>$data) {
	         			if($data['payed']==1){
	         				$guestlist_total+=$data['total_sum'];
	         			}
						if($data['drinking_package']==1){ 
							$package_name = 'Basic'; 
						} else if($data['drinking_package']==2){ 
							$package_name = 'Premium'; 
						}

						if($data['ceremonial']==1){
							$ceremony = 'Accepted';
						}
						/*Reservation*/
						$reservation_total = '';
						if($data['is_recomended'] == 1) {
	                      	$setting = getValue('sys_settings', array('key'=>'reservation_fee'));
	                      	$reservation_charge = $setting ? $setting['value'] : 0;
	                      	$reservation_total = ' (40% Deposit)';
	                    }

						if($data['payment_method_id']==12){ 
							$payment_type = 'Pay By Bank';
						} else if($data['payment_method_id']==13){ 
							$payment_type = 'Saferpay';
						} else if($data['payment_method_id']==14){ 
							$payment_type = 'Stripe';
						}

						$details = ' (';
						if($data['drinking_price']>0){
							$details .= '1 '.$package_name.' Drink Package';
						}
						if($data['cape']>0){
							$details .= ' '.$data['cape'].' cape';
						}
						if($data['additional']>0){
							$details .= ' 1 Additional';
						}
						$details .= ')';	

						if($data['drinking_price']==0 && $data['cape']==0 && $data['additional']==0){
							$details = '';
						}									
						//$leadArray = (array) $Result; // Cast the Object to an array
						$leadArray['Pseudonym']=html_entity_decode($data['username']);
						if($this->session->userdata('admin_id')==25267 || $this->session->userdata('admin_id')==19624){ 
						$leadArray['Email']=$data['invoiceAddress'];
						}
						$leadArray['Membership (Payment Status)']=$data['usersmembership'];
						$leadArray['Order No.']=$data['order_id_masked'];
						$leadArray['Order Date']=date('Y-m-d',$data['book_date']);
						$leadArray['Article']='Entry: '.$data['entry'].', Room: '.$data['room'];
						$leadArray['Extra Nights']=trim($data['extra_night_dates'],',');
						$leadArray['Drink Package']=$package_name;
						$leadArray['Cape']=$data['cape'];
						$leadArray['Ceremonial']=$ceremony;
						$leadArray['Additional Step']=number_format($data['additional'],2,',','.');
						$leadArray['Extra Wish']=(($data['extra_wish']!='')?$data['extra_wish']:'--');
						$leadArray['Checkin Total(&euro;)']=number_format($data['summury'],2,',','.').$details;
						$leadArray['Booking Total(&euro;)']=number_format($data['total_sum']/100,2,',','.').$reservation_total;
						$leadArray['Rest Payment At Arrival']=number_format(($data['reservation_rest_amount']/100),2,',','.'); 
						$leadArray['Booking Payment Status']=(($data['payed']==1)?'Paid':'Unpaid');
						$leadArray['Booking Payment Type']=$payment_type;
						$leadArray['Is Exchanged Order']= (($data['is_exchanged'] == 1) ? ' (Exchanged Order)' : '');
						$leadArray['Total Participation']= $data['totalParticipate'];
						fputcsv( $output_handle, $leadArray );
						
						$i++;
					}

					$leadArray['Pseudonym']="";
					if($this->session->userdata('admin_id')==25267 || $this->session->userdata('admin_id')==19624){ 
					$leadArray['Email']="";
					}
					$leadArray['Membership (Payment Status)']="";
					$leadArray['Order No.']="";
					$leadArray['Order Date']="";
					$leadArray['Article']="";
					$leadArray['Extra Nights']="";
					$leadArray['Drink Package']="";
					$leadArray['Cape']="";
					$leadArray['Ceremonial']="";
					$leadArray['Additional Step']="";
					$leadArray['Extra Wish']="";
					$leadArray['Checkin Total(&euro;)']="";
					$leadArray['Booking Total(&euro;)']="";
					$leadArray['Booking Payment Status']="";
					$leadArray['Booking Payment Type']="";
					$leadArray['Is Exchanged Order']="";
					$leadArray['Total Participation']="";
					fputcsv( $output_handle, $leadArray );


					$leadArray['Pseudonym']="";
					if($this->session->userdata('admin_id')==25267 || $this->session->userdata('admin_id')==19624){ 
					$leadArray['Email']="";
					}
					$leadArray['Membership (Payment Status)']="";
					$leadArray['Order No.']="";
					$leadArray['Order Date']="";
					$leadArray['Article']="";
					$leadArray['Extra Nights']="";
					$leadArray['Drink Package']="";
					$leadArray['Cape']="";
					$leadArray['Ceremonial']="";
					$leadArray['Additional Step']="";
					$leadArray['Extra Wish']="";
					$leadArray['Checkin Total(&euro;)']="";
					$leadArray['Booking Total(&euro;)']="";
					$leadArray['Booking Payment Status']="";
					$leadArray['Booking Payment Type']="";
					$leadArray['Is Exchanged Order']="";
					$leadArray['Total Participation']="";
					fputcsv( $output_handle, $leadArray );


					$leadArray['Pseudonym']="";
					if($this->session->userdata('admin_id')==25267 || $this->session->userdata('admin_id')==19624){ 
					$leadArray['Email']="";
					}
					$leadArray['Membership (Payment Status)']="Total Participants";
					$leadArray['Order No.']=count($guestarr)." Bookings";
					$leadArray['Order Date']="";
					$leadArray['Article']="Checkin Amount Total";
					$leadArray['Extra Nights']=number_format($guestlist_total/100, 2,',', '.');
					$leadArray['Drink Package']="";
					$leadArray['Cape']="";
					$leadArray['Ceremonial']="";
					$leadArray['Additional Step']="";
					$leadArray['Extra Wish']="";
					$leadArray['Checkin Total(&euro;)']="";
					$leadArray['Booking Total(&euro;)']="";
					$leadArray['Booking Payment Status']="";
					$leadArray['Booking Payment Type']="";
					$leadArray['Is Exchanged Order']="";
					$leadArray['Total Participation']="";
					fputcsv( $output_handle, $leadArray );
					fclose( $output_handle ); 
					die();
				} 
        die;
	}
	public function check_revenue_pdf($id)
	{
		$id=base64_decode($id);
		$revenue = $this->common_model->getAllMultipleJoin('shop_orders',array('event_id'=>$id,'payed'=>1),array(array('shop_carts','shop_orders.cart_id = shop_carts.id'),array('shop_booking_details','shop_booking_details.cart_id = shop_carts.id'),array('usr_users','usr_users.id = shop_carts.user_id')),'shop_orders.created DESC','email,total_sum, shop_orders.order_id_masked, shop_orders.created, shop_carts.user_id, payment_method_id, payed','shop_booking_details.cart_id');
		$eventDetails = $this->common_model->getAllRow('evt_events',array('id'=>$id));
		$html='<style>
				   	body {font-family: sans-serif;
					    font-size: 10pt;
					}
					p { margin: 0pt;
					}
					td { vertical-align: top; }
					.items td {
					    border-left: 0.1mm solid #000000;
					    border-right: 0.1mm solid #000000;
					}
					table thead td { background-color: #b3975b;
					    border: 0.1mm solid #000000;
					    color: #fff;
					}
					.items td.blanktotal {
					    background-color: #FFFFFF;
					    border: 0mm none #000000;
					    border-top: 0.1mm solid #000000;
					    border-right: 0.0mm solid #000000;
					}
					.items td.totals {
					    text-align: right;
					    border-top: 0.1mm solid #000000;
					    border-right: 0.0mm solid #000000;
					    border-left: 0.0mm solid #000000;
					}
					.items td.totals1 {
					    text-align: right;
					    border-top: 0.0mm solid #000000;
					    border-right: 0.0mm solid #000000;
					    border-left: 0.0mm solid #000000;
					}
				   </style>
				   							  
				         <h2 style="padding: 10px;border-bottom:1px solid #ccc; display: block;">'.$eventDetails['title'].' -- Revenue</h2>
				         <table class="items" width="100%" style="font-size: 9pt; border-collapse: collapse;" cellpadding="8">
						    <thead>
						        <tr>
							        <td style="padding:10px ; font-weight: bold; height: 19px; line-height: 19px; float: left;">Pseudonym</td>
							        <td style="padding:10px ; font-weight: bold; height: 19px; line-height: 19px; float: left;">Email</td>
							        <td style="padding:10px ; font-weight: bold; height: 19px; line-height: 19px; float: left;">Booking No.</td>
					               	<td style="padding:10px ; font-weight: bold; float: left; height: 19px; line-height: 19px;">Booking Date</td>
					               	<td style=" font-weight: bold; padding:10px ; float: left; height: 19px; line-height: 19px;">Booking Amount</td>
					               	<td style=" font-weight: bold; padding:10px ; float: left; height: 19px; line-height: 19px;">Paymemt Status</td>
					               	<td style=" font-weight: bold; padding:10px ; float: left; height: 19px; line-height: 19px;">Payment Mode</td>
				         		</tr>
				         	</thead>
				         	<tbody style="border-bottom:1px solid #000;">';
			            	if(count($revenue)>0)
							{
				            	$i=1;
				                $total = 0;
				                foreach ($revenue as $data) 
				                {
				                	if($data['payment_method_id']==12){ 
				                		$payment_method = 'Bank Transfer'; 
				                	} elseif($data['payment_method_id']==13){ 
				                		$payment_method = 'Saferpay'; 
				                	} elseif($data['payment_method_id']==14){ 
				                		$payment_method = 'Stripe'; 
				                	} else{ 
				                		$payment_method = 'Pay By Bank'; 
				                	}
				                	if($data['payed']==1){ 
				                		$status = 'Paid';
				                	} else{ 
				                		$status = 'Unpaid'; 
				                	}
				                	$userDetails = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$data['user_id']));
				                	if($data['email']!='')
				                	{
				                		$total = $total+$data['total_sum'];
						            	
			$html.='					<tr style="width: 100%; float: left; padding-left:10px;">         	
							 			   	<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">'.$userDetails['username'].'</td>
							 			   	<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">'.$data['email'].'</td>
							 			   	<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">'.$data['order_id_masked'].'</td>
							               	<td style="padding:10px ; float: left; height: 19px; line-height: 19px;">'.date('d-m-Y',$data['created']).'</td>
											<td style="padding:10px ; float: left; height: 19px; line-height: 19px;">'.number_format($data['total_sum']/100, 2,',', '.').'</td>	
											<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">'.$status.'</td>
											<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">'.$payment_method.'</td>						               	
										</tr>';	
									$i++; 
									}
								} 
			$html.='			</tbody>
							</table>
							<table  width="100%" style="font-size: 9pt; border-collapse: collapse;" cellpadding="8">
                               <tbody>
                                   <tr style="background:#ddd;">
                                    <td style="padding:10px; border-top:2px solid #000; width:30%; font-weight: bold;">Total Revenue</td>
									<td style="padding:10px; border-top:2px solid #000; font-weight: bold;">'.number_format($total/100, 2,',', '.').' &euro;</td>
								 </tr>
                               </tbody>
							</table>';
							} else {
			$html.='			<tr style="width: 100%; float: left; padding-left:10px;">         	
					 			   	<td style="padding:10px ; height: 19px; line-height: 19px; float: left;">No Revenue found...</td>
					 			</tr>';	
							}
		$pdfFilePath = "Revenue_".$eventDetails['title'].".pdf";
        $this->load->library('m_pdf');

        $this->m_pdf->pdf->useOnlyCoreFonts = true;    // false is default
		$this->m_pdf->pdf->SetTitle("Castleevents Title");
		$this->m_pdf->pdf->SetAuthor("Author");
		$this->m_pdf->pdf->SetDisplayMode('fullpage'); 
		$this->m_pdf->pdf->WriteHTML($html);
		$this->m_pdf->pdf->Output($pdfFilePath, "D"); 
		die;
	}
	public function sendReminderAll($enc_eventID='',$uri)
	{
		if($enc_eventID!='')
		{
			$eventId=base64_decode($enc_eventID);
			$orderdata = $this->common_model->getAllMultipleJoin('shop_booking_details',array('event_id'=>$eventId,'payed'=>0,'is_booking'=>1),array(array('shop_orders','shop_orders.cart_id = shop_booking_details.cart_id'),array('shop_carts','shop_carts.id = shop_booking_details.cart_id'),array('feu_userdetails','feu_userdetails.user_id = shop_carts.user_id')),'','','shop_booking_details.cart_id');
			//print_r($orderdata); die;
			//$to = 'sayan@digitalaptech.com';
			if(count($orderdata)>0){
				foreach ($orderdata as $key => $value) {
					$orderId=$value['order_id'];
					$orderDetail = $this->common_model->getAllRow('shop_orders',array('order_id'=>$orderId));
					$cartDetail = $this->common_model->getAllRow('shop_carts',array('id'=>$orderDetail['cart_id']));
					$userDetail = $this->common_model->getAllRowMultipleJoin('feu_userdetails',array('user_id'=>$cartDetail['user_id']),array(array('usr_users','usr_users.id = feu_userdetails.user_id')));
					
					$eventDetail = $this->common_model->getAllRowMultipleJoin('shop_booking_details',array('cart_id'=>$orderDetail['cart_id']),array(array('evt_events','evt_events.id = shop_booking_details.event_id')));
					$title = '';
					$event_id = 0;
					if(count($eventDetail)>0)
					{
						$title = $eventDetail['title'];
						$event_id = $eventDetail['event_id'];
					}
					$instArr = array(
										'order_id'=>$orderId,
										'order_created'=>$orderDetail['created'],
										'remind_date'=>date('Y-m-d'),
										'user_id'=>$userDetail['user_id'],
										'event_id'=>$event_id,
									);
					$this->common_model->insertData('order_to_reminder',$instArr);

					$order_to_reminder = $this->common_model->getAll('order_to_reminder',array('order_id'=>$orderId));
					$this->load->library('Utility');
					//print_r($cartDetail); die;
					$to = $userDetail['email'];
			        $sub = getAdminLang('Payment_reminder',$userDetail['userlanguage']).' CE-'.$orderDetail['order_id'];
					
			        if(count($order_to_reminder)>=4)
					{
						$body= '<p>'.getAdminLang('After_reviewing_your_booking_for_our',$userDetail['userlanguage']).' '.$title.' '.getAdminLang('we_havent_found_the_payment',$userDetail['userlanguage']).'. </p>';
						$body.= '<p>'.getAdminLang('We_already_send_you_several_reminders',$userDetail['userlanguage']).'.</p>';
						$body.= '<p>'.getAdminLang('The_booking_for_our_event_was_a_binding_reservation',$userDetail['userlanguage']).':</p>';
						$body.= '<br/><p>'.getAdminLang('If_the_payment_has_been_made_recently',$userDetail['userlanguage']).'.</p>';
						$body.= '<br/><p>'.getAdminLang('Your_Castleevents_Team',$userDetail['userlanguage']).'.</p>';
						$bodys=' <table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
			                    <tr>
			                       <td>
			                          <table cellspacing="0" cellpadding="0" border="0" width="100%">
			                             <tr>
			                                <td align="center" style="padding: 40px; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #b3975b;">
			                                   <h2>'.getAdminLang('Good_afternoon',$userDetail['userlanguage']).' <span style="text-transform:capitalize">'.$userDetail['username'].'</span> </h2>
			                                </td>
			                             </tr>
			                             <tr>
			                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
			                                   '.$body.'
			                                </td>
			                             </tr>
			                          </table>
			                       </td>
			                    </tr>
			                </table>';
					}
					else
					{
						$site_address_name = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_name'));
						$site_address_city = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_city'));
						$site_address_country_zip = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_country_zip'));

						$body= '<p>'.getAdminLang('We_would_like_to_remind_you',$userDetail['userlanguage']).' '.($orderDetail['total_sum']/100).' EUR '.getAdminLang('of_your_order_from',$userDetail['userlanguage']).' '.date('Y-m-d',$orderDetail['created']).' '.getAdminLang('is_still_unpaid_after',$userDetail['userlanguage']).' 7-'.getAdminLang('day_payment_obligation',$userDetail['userlanguage']).'. </p>';
						$body.= '<p>'.getAdminLang('Please_arrange_the_appropriate_payment_within',$userDetail['userlanguage']).' 3-'.getAdminLang('days_or_contact_us_to_make',$userDetail['userlanguage']).'.</p>';
						$body.= '<p><strong>IBAN:</strong> CH810023123110716660E</p>
			                     <p><strong>'.getAdminLang('Clearing',$userDetail['userlanguage']).':</strong> 231</p>
			                     <p><strong>'.getAdminLang('Swift',$userDetail['userlanguage']).':</strong> UBSWCHZH80A</p>
			                     <p><strong>'.getAdminLang('Payment_Reason',$userDetail['userlanguage']).':</strong> '.$orderDetail['order_id_masked'].'</p>
			                     <p><strong>'.getAdminLang('Amount',$userDetail['userlanguage']).':</strong> <span class="total">'.($orderDetail['total_sum']/100).' EUR</span></p>
			                     <p><strong>'.getAdminLang('Bank',$userDetail['userlanguage']).':</strong> UBS, Bahnhofstrasse 1, 5000 Aarau, '.getAdminLang('Switzerland',$userDetail['userlanguage']).'</p>
			                     <p><strong>'.getAdminLang('Recipient',$userDetail['userlanguage']).':</strong> '.$site_address_name['value'].', '.$site_address_city['value'].', '.$site_address_country_zip['value'].'</p>';
						$body.= '<p>'.getAdminLang('If_you_have_any_questions_about_your_order',$userDetail['userlanguage']).':</p>';
						$body.= '<br/><p>'.getAdminLang('Customer_Services_Events',$userDetail['userlanguage']).'</p>';
						$body.= '<p>info@castleevents.com</p>';

						$body.= '<br/><p>'.getAdminLang('If_the_payment_has_been_made_recently',$userDetail['userlanguage']).'.</p>';
						$body.= '<br/><p>'.getAdminLang('Your_Castleevents_Team',$userDetail['userlanguage']).'.</p>';
						//$body.= '<p>Best regards,</p><p>Your Castleevents Team </p>';
						$bodys=' <table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
				                    <tr>
				                       <td>
				                          <table cellspacing="0" cellpadding="0" border="0" width="100%">
				                             <tr>
				                                <td align="center" style="padding: 40px; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #b3975b;">
				                                   <h2>Dear <span style="text-transform:capitalize">'.$userDetail['username'].'</span> </h2>
				                                </td>
				                             </tr>
				                             <tr>
				                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
				                                   '.$body.'
				                                </td>
				                             </tr>
				                          </table>
				                       </td>
				                    </tr>
				                </table>';
				    }
			        //echo $bodys; die;
					$this->utility->sendCIMail($to,$sub,$bodys);
				}
			}
			$this->utility->setMsg('Reminder sent to all pending users successfully','SUCCESS');	
			redirect(base_url().str_replace('-','/',$uri));
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().str_replace('-','/',$uri));
		}
	}

	public function entry_visible($enc_entryID = '',$enc_userID='')
	{
		if($enc_userID!='')
		{
			$userId=base64_decode($enc_userID);
			$data = $this->common_model->getAllRow('event_features', array('id'=>$userId));
			if($data) {
				$is_hidden = $data['is_hidden'] == 1 ? 0 : 1;
				$this->common_model->UpdateData('event_features',array('is_hidden'=>$is_hidden),array('id'=>$userId));
				//echo $this->db->last_query(); die;
				$this->utility->setMsg('Entry visibility status changed','SUCCESS');	
				redirect(base_url().'admin/event/entrylist/'.$enc_entryID);
			} else  {
				$this->utility->setMsg('Invalid id','ERROR');	
				redirect(base_url().'admin/event/entrylist/'.$enc_entryID);
			}			
		}
		else
		{
			$this->utility->setMsg('Invalid id','ERROR');	
			redirect(base_url().'admin/event/entrylist/'.$enc_entryID);
		}
	}
}