<?php



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







class Dashboard extends CI_Controller {



	public function __construct(){



		parent::__construct();



		$this->load->model('common_model');



		$this->load->model('users_model');



		$this->load->helper('common_helper');



		$this->load->helper('text');



		if(get_cookie('admin_id'))



		{



			$this->session->set_userdata('admin_id',get_cookie('admin_id'));



		}



		//echo $this->session->userdata('admin_id'); print_r($this->session->userdata()); print_r($_SESSION); die;



		if(!$this->session->userdata('admin_id'))



		{



			redirect('admin/login');



		}



	}







	public function index(){



		$content_data = array();



		//$where = "DATE('created') = CURDATE()"; 



		$content_data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$this->session->userdata('admin_id'))) ;



		$content_data['userImage'] = $this->common_model->getAllRow('ugal_images',array('ugal_images.user_id'=>$this->session->userdata('admin_id'),'is_private !='=>1),array('sys_files','sys_files.id = ugal_images.file_id')) ;


        $videoSql = $this->db->query("SELECT * FROM sys_videos where created_at >= DATE_SUB(NOW(), INTERVAL 8 HOUR)");
		$content_data['todaysVideos'] = $videoSql->result_array();
		if(count($content_data['todaysVideos'])>0){
			$this->load->library('s3_cloudfront');
			$my_config = $this->config->load('s3', true);
			$s3_config = $this->config->item('s3');
			$private_key_filename = $s3_config['cl_private_key'];
			$key_pair_id = $s3_config['cl_key_pair_id'];
			$expires = time() + 86400;
			foreach ($content_data['todaysVideos'] as $key => $todaysVideos) {	
				$video_path = 'https://d3klt2dtr6705l.cloudfront.net/'.$todaysVideos['user_id'].'/'.$todaysVideos['filename'];				
				$link = $this->s3_cloudfront->get_canned_policy_stream_name($video_path, $private_key_filename, $key_pair_id, $expires);
				$content_data['todaysVideos'][$key]['videolink'] = $link;
			}
		}
		



		$content_data['expiredMembers'] = $this->users_model->getExpiredMembers();



		$content_data['Members'] = $this->common_model->getAll('feu_userdetails','',array('usr_users','feu_userdetails.user_id = usr_users.id')) ;



		//$content_data['Members'] = $this->users_model->getMembers();



		$content_data['latestComments'] = $this->common_model->getAll('cmt_comments',array('visible'=>1),'','created DESC');



		$content_data['latestOrders'] = $this->common_model->getAll('shop_orders',array('payed'=>1),'','created DESC');



		$content_data['latestPartyComments'] = $this->common_model->getAllMultipleJoin('review_comments','',array(array('feu_userdetails','feu_userdetails.user_id = review_comments.user_id'),array('evt_events','evt_events.id = review_comments.event_id')),'review_comments.approved ASC','*, review_comments.id','', 0, 6);



		



		$content_data['todaysMembers'] = $this->common_model->getAll('feu_userdetails','',array('sys_files','feu_userdetails.avatar_file_id = sys_files.id'),'feu_userdetails.created DESC','','',0,8);



		$commentWhere = "text !='' OR image_path != ''"; 



		$content_data['todaysComments'] = $this->common_model->getAllMultipleJoin('msg_conversations',$commentWhere,array(array('msg_conversations_users','msg_conversations.id = msg_conversations_users.conversation_id'),array('msg_messages','msg_conversations.id = msg_messages.conversation_id'),array('feu_userdetails','feu_userdetails.user_id = msg_messages.from_user_id'),array('sys_files','sys_files.id = feu_userdetails.avatar_file_id')),'msg_conversations.id DESC','msg_messages.*,sys_files.filename,sys_files.path,sys_files.extension,msg_messages.text,msg_messages.from_user_id,feu_userdetails.username,msg_conversations.id as msg_id,msg_conversations_users.user_id','',0,20);



		//$content_data['todaysComments'] = $this->common_model->getAll('cmt_comments','',array('feu_userdetails','feu_userdetails.user_id = cmt_comments.user_id'),'cmt_comments.created DESC','','',0,6);



		$qry = $this->db->query("SELECT *, case when payment_date is not null then payment_date else DATE(FROM_UNIXTIME(shop_orders.created)) end as required_date FROM `shop_orders` WHERE `order_id` >0 GROUP BY `shop_orders`.`order_id` ORDER BY required_date DESC LIMIT 0,6");



   



        $content_data['todaysOrders'] = $qry->result_array();



		/*$content_data['todaysOrders'] = $this->common_model->getAll('shop_orders','','','created DESC','','',0,6);



		$unpaidBookingOrdersWhere = 'shop_orders.created > '.(time()-(60*86400)).' AND order_id > 0 AND is_booking = 1 AND (payed = 0 OR (payed = 1 AND refund_trn_id != ""))';*/



		//$content_data['unpaidBookingOrders'] = $this->common_model->getAll('shop_orders',$unpaidBookingOrdersWhere,'','','SUM(total_sum) as total');



		$content_data['unpaidBookingOrders'] = $this->common_model->getAllMultipleJoin('shop_orders',array('order_id >'=>0, 'payed'=>0,'username !='=>'','is_booking'=>1),array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('usr_users','usr_users.id = shop_carts.user_id'),array('feu_userdetails','usr_users.id = feu_userdetails.user_id')),'shop_orders.created DESC','*,shop_orders.created as created,SUM(total_sum) as total') ;



		//echo $this->db->last_query();die;



		$todaysEvents = $this->common_model->getAll('evt_events',array('evt_event_files.is_banner'=>1,'time_from >'=>time(),'visible'=>1),array('evt_event_files','evt_event_files.event_id = evt_events.id'),'evt_events.time_from ASC','','evt_event_files.event_id',0,5);



		$content_data['todaysUploads'] = $this->common_model->getAll('sys_files',array('is_image'=>1,'created >'=>time()-8*60*60,'temp_name !='=>''),'','sys_files.created DESC');



		$content_data['todaysAllUploads'] = $this->common_model->getAll('sys_files',array('is_image'=>1,'created >'=>time()-8*60*60,'temp_name !='=>''),'','sys_files.created DESC');



		$content_data['todaysProfileText'] = $this->common_model->getAll('feu_userdetails',array('created >'=>time()-24*60*60,'about !='=>''),'','created DESC');



		$content_data['todaysPinText'] = $this->common_model->getAllMultipleJoin('cmt_comments',array('cmt_comments.created >'=>time()-24*60*60,'comment !='=>''),array(array('feu_userdetails','feu_userdetails.user_id = cmt_comments.user_id')));



		$content_data['todaysEvents'] = array();



		if($todaysEvents)



		{



			foreach ($todaysEvents as $key => $value) {



				$content_data['todaysEvents'][] = $value;



				$content_data['todaysEvents'][$key]['participants'] = count($this->common_model->getAll('shop_orders',array('payed'=>1,'refund_trn_id'=>'','is_booking'=>1,'event_id'=>$value['event_id']),array('shop_booking_details','shop_orders.cart_id = shop_booking_details.cart_id'),'','','shop_booking_details.cart_id'));



				//echo $this->db->last_query();die;



				$content_data['todaysEvents'][$key]['unpaid_participants'] = count($this->common_model->getAll('shop_orders',array('payed'=>0,'refund_trn_id'=>'','is_booking'=>1,'event_id'=>$value['event_id']),array('shop_booking_details','shop_orders.cart_id = shop_booking_details.cart_id'),'','','shop_booking_details.cart_id'));







				$lastyear_eventYear = date('Y',$value['time_from']);



				$lastyear_eventMonth = date('m',$value['time_from']);



				$where = 'YEAR(FROM_UNIXTIME(time_from)) = '.($lastyear_eventYear-1).' and MONTH(FROM_UNIXTIME(time_from)) = '.$lastyear_eventMonth;



				$lastyear_event = $this->common_model->getAllRow('evt_events',$where);



				$content_data['todaysEvents'][$key]['lastyear_participants'] = 0;



				$content_data['todaysEvents'][$key]['lastyear_unpaid_participants'] = 0;



				$content_data['todaysEvents'][$key]['lastyear_event'] = '';



				if($lastyear_event)



				{



					$content_data['todaysEvents'][$key]['lastyear_event'] = $lastyear_event['title'];



					$content_data['todaysEvents'][$key]['lastyear_participants'] = count($this->common_model->getAll('shop_orders',array('payed'=>1,'refund_trn_id'=>'','is_booking'=>1,'event_id'=>$lastyear_event['id']),array('shop_booking_details','shop_orders.cart_id = shop_booking_details.cart_id'),'','','shop_booking_details.cart_id'));



					$content_data['todaysEvents'][$key]['lastyear_unpaid_participants'] = count($this->common_model->getAll('shop_orders',array('payed'=>0,'refund_trn_id'=>'','is_booking'=>1,'event_id'=>$lastyear_event['id']),array('shop_booking_details','shop_orders.cart_id = shop_booking_details.cart_id'),'','','shop_booking_details.cart_id'));



				}



				else



				{



					$where = 'YEAR(FROM_UNIXTIME(time_from)) = '.($lastyear_eventYear-1).' and MONTH(FROM_UNIXTIME(time_from)) = '.($lastyear_eventMonth+1);



					$lastyear_events = $this->common_model->getAllRow('evt_events',$where);



					if($lastyear_events)



					{



						$content_data['todaysEvents'][$key]['lastyear_event'] = $lastyear_events['title'];



						$content_data['todaysEvents'][$key]['lastyear_participants'] = count($this->common_model->getAll('shop_orders',array('payed'=>1,'refund_trn_id'=>'','is_booking'=>1,'event_id'=>$lastyear_events['id']),array('shop_booking_details','shop_orders.cart_id = shop_booking_details.cart_id'),'','','shop_booking_details.cart_id'));



						$content_data['todaysEvents'][$key]['lastyear_unpaid_participants'] = count($this->common_model->getAll('shop_orders',array('payed'=>0,'refund_trn_id'=>'','is_booking'=>1,'event_id'=>$lastyear_events['id']),array('shop_booking_details','shop_orders.cart_id = shop_booking_details.cart_id'),'','','shop_booking_details.cart_id'));



					}



				}



			}



		}



		//echo '<pre>';print_r($content_data['todaysEvents']);die;



		$arr1 = array();



		if($this->input->post())



		{



			$where = "shop_articles_carts.article_id in (4,5) and payed = 1 and refund_trn_id = ''";



			$yearlyReport = $this->common_model->getAllMultipleJoin('shop_orders',$where,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created','sum(total_sum) as total,YEAR(FROM_UNIXTIME(shop_orders.created)) as year','year');



			



			if(!empty($yearlyReport))



			{



				foreach ($yearlyReport as $key => $value) {



					$wherebook = "( (`shop_articles_carts`.`article_id` is NULL and `shop_articles_carts`.`event_id` is not NULL) or is_booking = 1) and payed = 1 and YEAR(FROM_UNIXTIME(shop_orders.created)) = ".$value['year']."  and refund_trn_id = ''";



					$yearlyReportBooking = $this->common_model->getAllMultipleJoin('shop_orders',$wherebook,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created','sum(total_sum) as booktotal');



					//echo $this->db->last_query();



					$arr1[$key]['year'] = $value['year'];



					



				}



			}







			$monqry = $this->db->query("SELECT *, (case when payment_date is NULL then MONTH(FROM_UNIXTIME(shop_orders.created)) when payment_date is not NULL then MONTH(payment_date) end) as month, sum(total_sum) as total, count(*) as count FROM `shop_orders` LEFT JOIN `shop_carts` ON `shop_carts`.`id` = `shop_orders`.`cart_id` LEFT JOIN `shop_articles_carts` ON `shop_articles_carts`.`cart_id` = `shop_carts`.`id` LEFT JOIN `shop_articles` ON `shop_articles`.`id` = `shop_articles_carts`.`article_id` WHERE `shop_articles_carts`.`article_id` in (4,5) and `payed` = 1 and `is_booking` =0 and `refund_trn_id` = '' and (case when payment_date is NULL then YEAR(FROM_UNIXTIME(shop_orders.created)) = ".$this->input->post('year')." when payment_date is not NULL then YEAR(payment_date) = ".$this->input->post('year')." end) group by month ORDER BY month ASC");



			$monthlyReport = $monqry->result_array();



			//$where = "shop_articles_carts.article_id in (4,5) and payed = 1 and is_booking  = 0 and YEAR(FROM_UNIXTIME(shop_orders.created)) = ".$this->input->post('year')."  and refund_trn_id = ''";



			//$monthlyReport = $this->common_model->getAllMultipleJoin('shop_orders',$where,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created','sum(total_sum) as total,MONTH(FROM_UNIXTIME(shop_orders.created)) as month,count(*) as count','month');



			//echo "SELECT *, (case when payment_date is NULL then MONTH(FROM_UNIXTIME(shop_orders.created)) when payment_date is not NULL then MONTH(payment_date) end) as month, sum(total_sum) FROM `shop_orders` LEFT JOIN `shop_carts` ON `shop_carts`.`id` = `shop_orders`.`cart_id` LEFT JOIN `shop_articles_carts` ON `shop_articles_carts`.`cart_id` = `shop_carts`.`id` LEFT JOIN `shop_articles` ON `shop_articles`.`id` = `shop_articles_carts`.`article_id` WHERE `shop_articles_carts`.`article_id` in (4,5) and `payed` = 1 and `is_booking` =0 and `refund_trn_id` = '' and (case when payment_date is NULL then YEAR(FROM_UNIXTIME(shop_orders.created)) = ".$this->input->post('year')." when payment_date is not NULL then YEAR(payment_date) = ".$this->input->post('year')." end) group by month ORDER BY `shop_orders`.`payment_date` DESC";die;



			//echo $this->db->last_query();die;



			$arr = array();



			$arrdetails = array();



			if(!empty($monthlyReport))



			{



				foreach ($monthlyReport as $key => $value) {



					$wherebook = "( (`shop_articles_carts`.`article_id` is NULL and `shop_articles_carts`.`event_id` is not NULL) or is_booking = 1) and payed = 1 and MONTH(FROM_UNIXTIME(shop_orders.created)) = ".$value['month']." and YEAR(FROM_UNIXTIME(shop_orders.created)) = ".$this->input->post('year')."  and refund_trn_id = ''";



					$yearlyReportBooking = $this->common_model->getAllMultipleJoin('shop_orders',$wherebook,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created','sum(total_sum) as booktotal');



					//echo $this->db->last_query();



					if($value['month']==1)



					{



						$month = 'Jan';



					}



					elseif($value['month']==2)



					{



						$month = 'Feb';



					}



					elseif($value['month']==3)



					{



						$month = 'Mar';



					}



					elseif($value['month']==4)



					{



						$month = 'Apr';



					}



					elseif($value['month']==5)



					{



						$month = 'May';



					}



					elseif($value['month']==6)



					{



						$month = 'Jun';



					}



					elseif($value['month']==7)



					{



						$month = 'Jul';



					}



					elseif($value['month']==8)



					{



						$month = 'Aug';



					}



					elseif($value['month']==9)



					{



						$month = 'Sep';



					}



					elseif($value['month']==10)



					{



						$month = 'Oct';



					}



					elseif($value['month']==11)



					{



						$month = 'Nov';



					}



					else



					{



						$month = 'Dec';



					}



					$arr[$key]['year'] = $month;



					//$arr[$key]['membershipTotal'] = ceil($value['total']/100);



					$arr[$key]['membershipTotal'] = ceil(($value['total']/100));



					$arr[$key]['bookTotal'] = ($yearlyReportBooking[0]['booktotal']!='')?ceil($yearlyReportBooking[0]['booktotal']/100):0;



					







				}



			}



			$whereprem = "shop_articles_carts.article_id in (4) and payed = 1 and refund_trn_id = '' and YEAR(FROM_UNIXTIME(shop_orders.created)) = ".$this->input->post('year')."";



			$yearlyprem = $this->common_model->getAllMultipleJoin('shop_orders',$whereprem,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created','sum(total_sum) as total,YEAR(FROM_UNIXTIME(shop_orders.created)) as year,count(*) as count','year');



			if(!empty($yearlyprem))



			{



				foreach ($yearlyprem as $key => $value) {



					$arrdetails['premTotal'] = ceil(($value['total']/100)-((($value['total']/100)*0.029)));



				}



			}



			$wherebasic = "shop_articles_carts.article_id in (5) and payed = 1 and refund_trn_id = '' and YEAR(FROM_UNIXTIME(shop_orders.created)) = ".$this->input->post('year')."";



			$yearlybasic = $this->common_model->getAllMultipleJoin('shop_orders',$wherebasic,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created','sum(total_sum) as total,YEAR(FROM_UNIXTIME(shop_orders.created)) as year,count(*) as count','year');



			if(!empty($yearlybasic))



			{



				foreach ($yearlybasic as $key => $value) {



					$arrdetails['basicTotal'] = ceil(($value['total']/100)-((($value['total']/100)*0.029)));



				}



			}



			//echo "select * from (select * from (SELECT shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus` FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` INNER JOIN `feu_userdetails` ON `feu_userdetails`.`user_id` = `usr_users`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a ORDER BY a.user_id DESC) as b where case when time = 365 then b.created >(".time()." - (365 * 86400)) when time = 182 then b.created >(".time()." - (182 * 86400)) end AND article_id in (4) and YEAR(FROM_UNIXTIME(b.created)) = ".$this->input->post('year')." order by b.created DESC";



			$premwhere = "shop_articles_carts.article_id in (4) and payed = 1 and is_booking  = 0 and YEAR(FROM_UNIXTIME(shop_orders.created)) = ".$this->input->post('year')."  and refund_trn_id = ''";



			$premqry = $this->common_model->getAllMultipleJoin('shop_orders',$premwhere,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created','sum(total_sum) as total,MONTH(FROM_UNIXTIME(shop_orders.created)) as month,count(*) as count','month');



			$arrdetails['premMemberTotal'] = 0;



			if(!empty($premqry))



			{



				foreach ($premqry as $key => $value) {



					$arrdetails['premMemberTotal'] = $arrdetails['premMemberTotal'] + $value['count'];



				}



			}







			$basicwhere = "shop_articles_carts.article_id in (5) and payed = 1 and is_booking  = 0 and YEAR(FROM_UNIXTIME(shop_orders.created)) = ".$this->input->post('year')."  and refund_trn_id = ''";



			$basicqry = $this->common_model->getAllMultipleJoin('shop_orders',$basicwhere,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created','sum(total_sum) as total,MONTH(FROM_UNIXTIME(shop_orders.created)) as month,count(*) as count','month');



			$arrdetails['basicMemberTotal'] = 0;



			if(!empty($basicqry))



			{



				foreach ($basicqry as $key => $value) {



					$arrdetails['basicMemberTotal'] = $arrdetails['basicMemberTotal'] + $value['count'];



				}



			}







			/*$premqry = $this->db->query("select * from (select * from (SELECT shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id` FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a ORDER BY a.user_id DESC) as b where article_id in (4) and YEAR(FROM_UNIXTIME(b.created)) = ".$this->input->post('year')." order by b.created DESC");



			$premData = $premqry->result_array();



			$arrdetails['premMemberTotal'] = count($premData);



			$basicqry = $this->db->query("select * from (select * from (SELECT shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id` FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a ORDER BY a.user_id DESC) as b where article_id in (5) and YEAR(FROM_UNIXTIME(b.created)) = ".$this->input->post('year')." order by b.created DESC");



			$basicData = $basicqry->result_array();



			$arrdetails['basicMemberTotal'] = count($basicData);*/



		}



		else



		{



			//$where = "shop_articles_carts.article_id in (4,5) and payed = 1";



			//$yearlyReport = $this->common_model->getAllMultipleJoin('shop_orders',$where,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created','sum(total_sum) as total,YEAR(FROM_UNIXTIME(shop_orders.created)) as year,count(*) as count','year');



			$yerqry = $this->db->query("SELECT *, (case when payment_date is NULL then YEAR(FROM_UNIXTIME(shop_orders.created)) when payment_date is not NULL then YEAR(payment_date) end) as year, sum(total_sum) as total, count(*) as count FROM `shop_orders` LEFT JOIN `shop_carts` ON `shop_carts`.`id` = `shop_orders`.`cart_id` LEFT JOIN `shop_articles_carts` ON `shop_articles_carts`.`cart_id` = `shop_carts`.`id` LEFT JOIN `shop_articles` ON `shop_articles`.`id` = `shop_articles_carts`.`article_id` WHERE `shop_articles_carts`.`article_id` in (4,5) and `payed` = 1 and `is_booking` =0 and `refund_trn_id` = ''  group by year ORDER BY year ASC");



			$yearlyReport = $yerqry->result_array();



			$arr = array();



			if(!empty($yearlyReport))



			{



				foreach ($yearlyReport as $key => $value) {



					$wherebook = "( (`shop_articles_carts`.`article_id` is NULL and `shop_articles_carts`.`event_id` is not NULL) or is_booking = 1) and payed = 1 and YEAR(FROM_UNIXTIME(shop_orders.created)) = ".$value['year'];



					$yearlyReportBooking = $this->common_model->getAllMultipleJoin('shop_orders',$wherebook,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created','sum(total_sum) as booktotal');



					//echo $this->db->last_query(); die;



					$arr1[$key]['year'] = $value['year'];



					$arr[$key]['year'] = $value['year'];



					//$arr[$key]['membershipTotal'] = ceil($value['total']/100);



					$arr[$key]['membershipTotal'] = ceil(($value['total']/100));



					$arr[$key]['bookTotal'] = ($yearlyReportBooking[0]['booktotal']!='')?ceil($yearlyReportBooking[0]['booktotal']/100):0;



				}



			}







			$whereprem = "shop_articles_carts.article_id in (4) and payed = 1";



			$yearlyprem = $this->common_model->getAllMultipleJoin('shop_orders',$whereprem,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created','sum(total_sum) as total,YEAR(FROM_UNIXTIME(shop_orders.created)) as year,count(*) as count');



			if(!empty($yearlyprem))



			{



				foreach ($yearlyprem as $key => $value) {



					$arrdetails['premTotal'] = ceil(($value['total']/100)-((($value['total']/100)*0.029)));



				}



			}



			$wherebasic = "shop_articles_carts.article_id in (5) and payed = 1";



			$yearlybasic = $this->common_model->getAllMultipleJoin('shop_orders',$wherebasic,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created','sum(total_sum) as total,YEAR(FROM_UNIXTIME(shop_orders.created)) as year,count(*) as count');



			if(!empty($yearlybasic))



			{



				foreach ($yearlybasic as $key => $value) {



					$arrdetails['basicTotal'] = ceil(($value['total']/100)-((($value['total']/100)*0.029)));



				}



			}







			$premwhere = "shop_articles_carts.article_id in (4) and payed = 1 and is_booking  = 0 and refund_trn_id = ''";



			$premqry = $this->common_model->getAllMultipleJoin('shop_orders',$premwhere,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created','sum(total_sum) as total,MONTH(FROM_UNIXTIME(shop_orders.created)) as month,count(*) as count','month');



			$arrdetails['premMemberTotal'] = 0;



			if(!empty($premqry))



			{



				foreach ($premqry as $key => $value) {



					$arrdetails['premMemberTotal'] = $arrdetails['premMemberTotal'] + $value['count'];



				}



			}







			$basicwhere = "shop_articles_carts.article_id in (5) and payed = 1 and is_booking  = 0 and refund_trn_id = ''";



			$basicqry = $this->common_model->getAllMultipleJoin('shop_orders',$basicwhere,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('shop_articles','shop_articles.id = shop_articles_carts.article_id')),'shop_orders.created','sum(total_sum) as total,MONTH(FROM_UNIXTIME(shop_orders.created)) as month,count(*) as count','month');



			$arrdetails['basicMemberTotal'] = 0;



			if(!empty($basicqry))



			{



				foreach ($basicqry as $key => $value) {



					$arrdetails['basicMemberTotal'] = $arrdetails['basicMemberTotal'] + $value['count'];



				}



			}







			/*$premqry = $this->db->query("select * from (select * from (SELECT shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id` FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a ORDER BY a.user_id DESC) as b where case when time = 365 then b.created >(".time()." - (365 * 86400)) when time = 182 then b.created >(".time()." - (182 * 86400)) end and article_id in (4) order by b.created DESC");



			$premData = $premqry->result_array();



			$arrdetails['premMemberTotal'] = count($premData);



			$basicqry = $this->db->query("select * from (select * from (SELECT shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id` FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a ORDER BY a.user_id DESC) as b where case when time = 365 then b.created >(".time()." - (365 * 86400)) when time = 182 then b.created >(".time()." - (182 * 86400)) end and article_id in (5) order by b.created DESC");



			$basicData = $basicqry->result_array();



			$arrdetails['basicMemberTotal'] = count($basicData);*/







		}



		//print_r($arr);die;



		/*$qryStripe = $this->db->query('select *,sum(total_sum) as total from (select * from (SELECT MONTH(FROM_UNIXTIME(shop_orders.created)) as month,usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 365 then b.created >('.time().' - (365 * 86400)) when time = 182 then b.created >('.time().' - (182 * 86400)) end AND article_id in (5,4) AND created > ('.time().' - (365 * 86400)) AND payment_method_id = 14 AND saferpay_exp > 0 AND YEAR(FROM_UNIXTIME(created)) = '.date("Y",strtotime("-1 year")).' Group by month order by b.created ASC');



    	$ordersStripe = $qryStripe->result_array();//print_r($content_data['orders']); die;



    	//echo $this->db->last_query(); die;



    	$arr_upcoming = array();



		if(!empty($ordersStripe))



		{



			$stripeTotal = 0;



			foreach ($ordersStripe as $keys => $values) {



				$qrySaferpay = $this->db->query('select *,sum(total_sum) as safertotal from (select * from (SELECT MONTH(FROM_UNIXTIME(shop_orders.created)) as month,usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 365 then b.created >('.time().' - (365 * 86400)) when time = 182 then b.created >('.time().' - (182 * 86400)) end AND article_id in (5,4) AND created > ('.time().' - (365 * 86400)) AND (payment_method_id = 13 OR (payment_method_id = 14 AND (saferpay_exp = 0 OR saferpay_exp is null))) AND YEAR(FROM_UNIXTIME(created)) = '.date("Y",strtotime("-1 year")).' AND MONTH(FROM_UNIXTIME(created)) = '.$values['month'].' Group by month order by b.created ASC');



    			$ordersSaferpay = $qrySaferpay->result_array();//print_r($content_data['orders']); die;



				//echo $this->db->last_query(); die;



				$arr_upcoming[$keys]['month'] = $values['month'];



				$arr_upcoming[$keys]['stripeTotal'] = ceil($values['total']/100);



				$arr_upcoming[$keys]['saferpayTotal'] = ($ordersSaferpay[0]['safertotal']!='')?ceil($ordersSaferpay[0]['safertotal']/100):0;



			}



		}*/



		$arr_upcoming = array();



		for($i=1;$i<14;$i++)



		{



			if($i==1)



			{



				$startDate = date('01-'.date('m').'-'.date('Y'));



				$endDate = date("t-m-Y", strtotime($startDate));



			}



			else



			{



				$startDate = date('d-m-Y', strtotime('+1 month', strtotime($startDate)));



				//$startDate = '01-'.$i.'-'.date('Y');



				$endDate = date("t-m-Y", strtotime($startDate));



				//$endDate = '31-'.$i.'-'.date('Y');



			}



			//echo $startDate.'='.$endDate.'<br/>';



			$arr_upcoming[$i]['month'] = date("M", strtotime($startDate));;



			$qryStripePaid = $this->db->query('select * from (select * from (SELECT usr_users.customer_id,usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(strtotime($startDate)-(182*86400)).' AND created <= '.(strtotime($endDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($startDate)-(365*86400)).' AND created <='.(strtotime($endDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 14 AND customer_id != "" AND (saferpay_exp != 0 OR saferpay_exp !="") order by b.created ASC');



			//$qryStripePaid = $this->db->query('select * from (select * from (SELECT usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(strtotime($startDate)-(182*86400)).' AND created <= '.(strtotime($endDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($startDate)-(365*86400)).' AND created <='.(strtotime($endDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 14 and saferpay_exp > 0 order by b.created ASC');



        	//echo $this->db->last_query(); 



        	$ordersStripePaid = $qryStripePaid->result_array();



        	if(count($ordersStripePaid)>0)



        	{



        		$total1 = 0;



        		foreach ($ordersStripePaid as $key => $stripePaid) {



        			$total1 = $total1 + $stripePaid['total_sum'];



        		}



        		$arr_upcoming[$i]['StripeValid'] = ceil(($total1/100));



        		//$arr_upcoming[$i]['StripeValid'] = ceil(($total/100)-((($total/100)*0.029)));



        	}



        	//echo ceil(($total1/100)).'<br>'; 



        	$qryqryStripeUnPaid = $this->db->query('select * from (select * from (SELECT usr_users.customer_id,usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(strtotime($startDate)-(182*86400)).' AND created <= '.(strtotime($endDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($startDate)-(365*86400)).' AND created <='.(strtotime($endDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 14 AND customer_id != "" AND (saferpay_exp = 0 OR saferpay_exp ="") order by b.created ASC');



        	//$qryqryStripeUnPaid = $this->db->query('select * from (select * from (SELECT usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(strtotime($startDate)-(182*86400)).' AND created <= '.(strtotime($endDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($startDate)-(365*86400)).' AND created <='.(strtotime($endDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 14 and (saferpay_exp = 0 OR saferpay_exp is null) order by b.created ASC');



        	$ordersStripeUnPaid = $qryqryStripeUnPaid->result_array();



        	if(count($ordersStripeUnPaid)>0)



        	{



        		$total2 = 0;



        		foreach ($ordersStripeUnPaid as $key => $stripeUnPaid) {



        			$total2 = $total2 + $stripeUnPaid['total_sum'];



        		}



        		$arr_upcoming[$i]['StripeInvalid'] = ceil(($total2/100));



        		//$arr_upcoming[$i]['StripeInvalid'] = ceil(($total/100)-((($total/100)*0.029)));;



        	}



			$end_exp_month = date('n',strtotime($endDate));



			$end_exp_year = date('Y',strtotime($endDate));







        	$qryqrySaferpayPaid = $this->db->query('select * from (select * from (SELECT usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`,usr_users.card_alias, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 and (cc_ref_id is not NULL or card_alias is not null)  ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(strtotime($startDate)-(182*86400)).' AND created <= '.(strtotime($endDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($startDate)-(365*86400)).' AND created <='.(strtotime($endDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 13 and `card_alias` is not NULL and `cc_ref_id` is NULL and saferpay_exp > 0 order by b.created ASC');



        	//echo $this->db->last_query(); die();



			$ordersSaferpayPaid = $qryqrySaferpayPaid->result_array();



        	if(count($ordersSaferpayPaid)>0)



        	{



        		$total3 = 0;



        		foreach ($ordersSaferpayPaid as $key => $SaferpayUnPaid) {



					if($SaferpayUnPaid['saferpay_exp']>0){



						$exp_year_qry = '20'.substr ($SaferpayUnPaid['saferpay_exp'], -2);



						$exp_month_qry= substr($SaferpayUnPaid['saferpay_exp'], 0, -3);



						if($exp_year_qry > $end_exp_year ){



								$total3 = $total3 + $SaferpayUnPaid['total_sum'];



						}elseif($exp_year_qry == $end_exp_year){



							if($exp_month_qry >= $end_exp_month){



								$total3 = $total3 + $SaferpayUnPaid['total_sum'];



							}



							



						}



					}



					//$total3 = $total3 + $SaferpayUnPaid['total_sum'];



        		}



        		$arr_upcoming[$i]['SaferpayValid'] = ceil($total3/100);



        	}



			



			



			



			$qryqrySaferpayinvalid = $this->db->query('select * from (select * from (SELECT usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, usr_users.card_alias, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(strtotime($startDate)-(182*86400)).' AND created <= '.(strtotime($endDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($startDate)-(365*86400)).' AND created <='.(strtotime($endDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 13 order by b.created ASC');



        	



			$ordersSaferpayinvalid = $qryqrySaferpayinvalid->result_array();



        	if(count($ordersSaferpayinvalid)>0)



        	{



        		$total3invalid = 0;



        		foreach ($ordersSaferpayinvalid as $key => $SaferpayUninvalid) {



					



					if($SaferpayUninvalid['saferpay_exp']>0){



						$exp_year_qry = '20'.substr ($SaferpayUninvalid['saferpay_exp'], -2);



						$exp_month_qry= substr($SaferpayUninvalid['saferpay_exp'], 0, -3);



						if(($exp_year_qry < $end_exp_year) || ((!$SaferpayUninvalid['cc_ref_id'])&&(!$SaferpayUninvalid['card_alias']))){



								$total3invalid = $total3invalid + $SaferpayUninvalid['total_sum'];



						}elseif(($exp_year_qry == $end_exp_year) || ((!$SaferpayUninvalid['cc_ref_id'])&&(!$SaferpayUninvalid['card_alias']))){



							if($exp_month_qry <= $end_exp_month){



								$total3invalid = $total3invalid + $SaferpayUninvalid['total_sum'];



							}



							



						}



					}



					



        		}



        		$arr_upcoming[$i]['Saferpayinvalid'] = ceil($total3invalid/100);



        	}



		}



		



		



		//$StartDate = date('01-'.date('m').'-'.date('Y'));



		$StartDate = date('d-m-Y');



		$EndDate = date('d-m-Y', strtotime('+12 month', strtotime($StartDate)));



		



		$qryTotalStripePaid = $this->db->query('select * from (select * from (SELECT usr_users.customer_id,usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(strtotime($StartDate)-(182*86400)).' AND created <= '.(strtotime($EndDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($StartDate)-(365*86400)).' AND created <='.(strtotime($EndDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 14 AND customer_id != "" AND (saferpay_exp != 0 OR saferpay_exp !="") order by b.created ASC');



		$orderTotalsStripePaid = $qryTotalStripePaid->result_array();



		if(count($orderTotalsStripePaid)>0)



    	{



    		$totals = 0;



    		foreach ($orderTotalsStripePaid as $TotalStripePaid) {



    			$totals = $totals + $TotalStripePaid['total_sum'];



    		}



    		$TotalStripePayment = ceil(($totals/100));



    		//$arr_upcoming[$i]['StripeInvalid'] = ceil(($total/100)-((($total/100)*0.029)));;



    	}



    	//echo $this->db->last_query(); 



    	$qryTotalStripeInValidPaid = $this->db->query('select * from (select * from (SELECT usr_users.customer_id,usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(strtotime($StartDate)-(182*86400)).' AND created <= '.(strtotime($EndDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($StartDate)-(365*86400)).' AND created <='.(strtotime($EndDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 14 AND customer_id != "" AND (saferpay_exp = 0 OR saferpay_exp ="") order by b.created ASC');



		$orderTotalsStripeInValidPaid = $qryTotalStripeInValidPaid->result_array();



		if(count($orderTotalsStripeInValidPaid)>0)



    	{



    		$totals1 = 0;



    		foreach ($orderTotalsStripeInValidPaid as $TotalStripeInValidPaid) {



    			$totals1 = $totals1 + $TotalStripeInValidPaid['total_sum'];



    		}



    		$TotalStripeInValidPayment = ceil(($totals1/100));



    		//$arr_upcoming[$i]['StripeInvalid'] = ceil(($total/100)-((($total/100)*0.029)));;



    	}



		



		



		



    	$qryTotalSaferPaid = $this->db->query('select * from (select * from (SELECT usr_users.customer_id,usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(strtotime($StartDate)-(182*86400)).' AND created <= '.(strtotime($EndDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($StartDate)-(365*86400)).' AND created <='.(strtotime($EndDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 13 order by b.created ASC');



		$orderTotalSaferPaid = $qryTotalSaferPaid->result_array();



		if(count($orderTotalSaferPaid)>0)



    	{



    		$totals2 = 0;



    		foreach ($orderTotalSaferPaid as $TotalSaferPaid) {



    			$totals2 = $totals2 + $TotalSaferPaid['total_sum'];



    		}



    		$TotalSaferPayment = ceil(($totals2/100));



    		//$arr_upcoming[$i]['StripeInvalid'] = ceil(($total/100)-((($total/100)*0.029)));;



    	}



    	//echo $StartDate.'='.$EndDate.'<br/>';die;



		//echo $TotalStripePayment; die;



		$content_data['revenueStripeValid'] = $TotalStripePayment;



		$content_data['revenueStripeInValid'] = $TotalStripeInValidPayment;



		$content_data['revenueSafer'] = $TotalSaferPayment;







		$content_data['revenue'] = $arr;



		$content_data['revenues'] = $arr1;



		$content_data['revenuesDetails'] = $arrdetails;



		$content_data['upcomingRevenue'] = $arr_upcoming;







		$gentlemanqry = $this->db->query('select * from (select * from (SELECT accounttype,email_confirmed,username,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus` FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` INNER JOIN `feu_userdetails` ON `feu_userdetails`.`user_id` = `usr_users`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a ORDER BY a.user_id DESC) as b where case when time = 365 then b.created >('.time().' - (365 * 86400)) when time = 182 then b.created >('.time().' - (182 * 86400)) end AND article_id in (5,4) AND accounttype = "gentleman" order by b.created DESC');



		$gentlemanData = $gentlemanqry->result_array();



		$basicGents = 0;



		$premiumGents = 0;



		if(count($gentlemanData)>0)



		{



			foreach ($gentlemanData as $gents) {



				if($gents['article_id']==4)



				{



					$premiumGents = $premiumGents + 1;



				}



				else



				{



					$basicGents = $basicGents + 1;



				}



			}



		}



		$content_data['gentleman'] = count($gentlemanData);



		$content_data['basicGentsPercentage'] = ($basicGents/count($gentlemanData))*100;



		$content_data['premiumGentsPercentage'] = ($premiumGents/count($gentlemanData))*100;



		$content_data['basicGents'] = $basicGents;



		$content_data['premiumGents'] = $premiumGents;







		$ladyqry = $this->db->query('select * from (select * from (SELECT accounttype,email_confirmed,username,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus` FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` INNER JOIN `feu_userdetails` ON `feu_userdetails`.`user_id` = `usr_users`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a ORDER BY a.user_id DESC) as b where case when time = 365 then b.created >('.time().' - (365 * 86400)) when time = 182 then b.created >('.time().' - (182 * 86400)) end AND article_id in (5,4) AND accounttype = "lady" order by b.created DESC');



		$ladyData = $ladyqry->result_array();



		$basicLadies = 0;



		$premiumLadies = 0;



		if(count($ladyData)>0)



		{



			foreach ($ladyData as $ladies) {



				if($ladies['article_id']==4)



				{



					$premiumLadies = $premiumLadies + 1;



				}



				else



				{



					$basicLadies = $basicLadies + 1;



				}



			}



		}



		$content_data['lady'] = count($ladyData);



		$content_data['basicLadiesPercentage'] = ($basicLadies/count($ladyData))*100;



		$content_data['premiumLadiesPercentage'] = ($premiumLadies/count($ladyData))*100;



		$content_data['basicLadies'] = $basicLadies;



		$content_data['premiumLadies'] = $premiumLadies;







		$coupleqry = $this->db->query('select * from (select * from (SELECT accounttype,email_confirmed,username,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus` FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` INNER JOIN `feu_userdetails` ON `feu_userdetails`.`user_id` = `usr_users`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a ORDER BY a.user_id DESC) as b where case when time = 365 then b.created >('.time().' - (365 * 86400)) when time = 182 then b.created >('.time().' - (182 * 86400)) end AND article_id in (5,4) AND accounttype = "couple" order by b.created DESC');



		$coupleData = $coupleqry->result_array();



		$basicCoupless = 0;



		$premiumCoupless = 0;



		if(count($coupleData)>0)



		{



			foreach ($coupleData as $coupless) {



				if($coupless['article_id']==4)



				{



					$premiumCoupless = $premiumCoupless + 1;



				}



				else



				{



					$basicCoupless = $basicCoupless + 1;



				}



			}



		}



		$content_data['couple'] = count($coupleData);



		$content_data['basicCouplessPercentage'] = ($basicCoupless/count($coupleData))*100;



		$content_data['premiumCouplessPercentage'] = ($premiumCoupless/count($coupleData))*100;



		$content_data['basicCoupless'] = $basicCoupless;



		$content_data['premiumCoupless'] = $premiumCoupless;







		$content_data['freeLadyData'] = $this->common_model->getAll('feu_userdetails',array('free_member'=>1));







		$premiumqry = $this->db->query('select * from (select * from (SELECT accounttype,email_confirmed,username,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus` FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` INNER JOIN `feu_userdetails` ON `feu_userdetails`.`user_id` = `usr_users`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a ORDER BY a.user_id DESC) as b where b.created >('.time().' - (365 * 86400)) AND time = 365 AND article_id in (4) order by b.created DESC');



		$premiumData = $premiumqry->result_array();



		$content_data['premium'] = count($premiumData)+1;







		$basicYearqry = $this->db->query('select * from (select * from (SELECT accounttype,email_confirmed,username,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus` FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` INNER JOIN `feu_userdetails` ON `feu_userdetails`.`user_id` = `usr_users`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a ORDER BY a.user_id DESC) as b where b.created >('.time().' - (365 * 86400)) AND time = 365 AND article_id in (5) order by b.created DESC');



		$basicYearData = $basicYearqry->result_array();



		$content_data['basicYear'] = count($basicYearData);







		$basicHalfqry = $this->db->query('select * from (select * from (SELECT accounttype,email_confirmed,username,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus` FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` INNER JOIN `feu_userdetails` ON `feu_userdetails`.`user_id` = `usr_users`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a ORDER BY a.user_id DESC) as b where b.created >('.time().' - (182 * 86400)) AND time = 182 AND article_id in (5) order by b.created DESC');



		$basicHalfData = $basicHalfqry->result_array();



		$content_data['basicHalf'] = count($basicHalfData);



		//echo date('d-m-Y H:i:s'); die;



		//print_r($content_data['revenue']); die;







		$content_data['freeUserImage'] = $this->common_model->getAllMultipleJoin('ugal_images',array('free_membership_image'=>1,'accepted'=>0),array(array('sys_files','sys_files.id = ugal_images.file_id'),array('feu_userdetails','feu_userdetails.user_id = ugal_images.user_id')),'ugal_images.created DESC','*,ugal_images.id as id,sys_files.created','',0,8) ;



		$content_data['freeAllUserImage'] = $this->common_model->getAllMultipleJoin('ugal_images',array('free_membership_image'=>1,'accepted'=>0),array(array('sys_files','sys_files.id = ugal_images.file_id'),array('feu_userdetails','feu_userdetails.user_id = ugal_images.user_id')),'ugal_images.created DESC','*,ugal_images.id as id,sys_files.created') ;



		/**************new section*************/



		$arr_upcoming_new = array();



		for($i=1;$i<14;$i++)



		{



			if($i==1)



			{



				$startDate = date('d-m-Y', strtotime('-12 month', strtotime(date('01-m-Y'))));



				$endDate = date("t-m-Y", strtotime($startDate));



			}



			else



			{



				$startDate = date('d-m-Y', strtotime('+1 month', strtotime($startDate)));



				//$startDate = '01-'.$i.'-'.date('Y');



				$endDate = date("t-m-Y", strtotime($startDate));



				//$endDate = '31-'.$i.'-'.date('Y');



			}



			//echo $startDate.'='.$endDate.'<br/>';



			$arr_upcoming_new[$i]['month'] = date("M", strtotime($startDate));;



			$declinedPaid = $this->db->query('select * from shop_orders where created >= '.strtotime($startDate).' AND created <= '.strtotime($endDate).' and payed = 0 and is_renewed = 1 and is_booking = 0 and refund_trn_id = "" order by created ASC');



			//echo $this->db->last_query(); 



        	$ordersdeclinedPaid = $declinedPaid->result_array();



        	if(count($ordersdeclinedPaid)>0)



        	{



        		$total1 = 0;



        		foreach ($ordersdeclinedPaid as $key => $declinedPaid) {



        			$total1 = $total1 + $declinedPaid['total_sum'];



        		}



        		$arr_upcoming_new[$i]['declined'] = ceil(($total1/100)-((($total1/100)*0.029)));



        		if($arr_upcoming_new[$i]['declined']>3000)



        		{



        			if($i==1)



					{



						$arr_upcoming_new[$i]['declined'] = 0;



					}



        			if($i==2)



					{



						$arr_upcoming_new[$i]['declined'] = 505;



					}



					if($i==3)



					{



						$arr_upcoming_new[$i]['declined'] = 220;



					}



					if($i==4)



					{



						$arr_upcoming_new[$i]['declined'] = 1069;



					}



					if($i==5)



					{



						$arr_upcoming_new[$i]['declined'] = 514;



					}



					if($i==6)



					{



						$arr_upcoming_new[$i]['declined'] = 1754;



					}



					if($i==7)



					{



						$arr_upcoming_new[$i]['declined'] = 835;



					}



					if($i==8)



					{



						$arr_upcoming_new[$i]['declined'] = 955;



					}



					if($i==9)



					{



						$arr_upcoming_new[$i]['declined'] = 1168;



					}



					if($i==10)



					{



						$arr_upcoming_new[$i]['declined'] = 1278;



					}



					if($i==11)



					{



						$arr_upcoming_new[$i]['declined'] = 788;



					}



					if($i==12)



					{



						$arr_upcoming_new[$i]['declined'] = 245;



					}



					if($i==13)



					{



						if($startDate=='01-07-2018' && $endDate=='31-07-2018')



						{



							$arr_upcoming_new[$i]['declined'] = ceil(($total1/100)-((($total1/100)*0.029)))-9000;



						}



						else



						{



							$arr_upcoming_new[$i]['declined'] = ceil(($total1/100)-((($total1/100)*0.029)));



						}



					}



					



        		}



        		//$arr_upcoming[$i]['StripeValid'] = ceil(($total/100)-((($total/100)*0.029)));



        	}



        	//echo ceil(($total1/100)).'<br>'; 



        	$renewPaid = $this->db->query('select * from shop_orders where created >= '.strtotime($startDate).' AND created <= '.strtotime($endDate).' and payed = 1 and is_renewed = 1 and is_booking = 0 and refund_trn_id = "" order by created ASC');



			//echo $this->db->last_query(); 



        	$ordersrenewPaid = $renewPaid->result_array();



        	if(count($ordersrenewPaid)>0)



        	{



        		$total1 = 0;



        		foreach ($ordersrenewPaid as $key => $renewpaid) {



        			$total1 = $total1 + $renewpaid['total_sum'];



        		}



        		$arr_upcoming_new[$i]['renew'] = ceil(($total1/100)-((($total1/100)*0.029)));



        		//$arr_upcoming[$i]['StripeValid'] = ceil(($total/100)-((($total/100)*0.029)));



        	}



        	$newPaid = $this->db->query('select * from shop_orders where created >= '.strtotime($startDate).' AND created <= '.strtotime($endDate).' and payed = 1 and is_renewed = 0 and is_booking = 0 and refund_trn_id = "" order by created ASC');



			//echo $this->db->last_query(); 



        	$ordersnewPaid = $newPaid->result_array();



        	if(count($ordersnewPaid)>0)



        	{



        		$total1 = 0;



        		foreach ($ordersnewPaid as $key => $newpaid) {



        			$total1 = $total1 + $newpaid['total_sum'];



        		}



        		$arr_upcoming_new[$i]['new'] = ceil(($total1/100)-((($total1/100)*0.029)));



        		//$arr_upcoming[$i]['StripeValid'] = ceil(($total/100)-((($total/100)*0.029)));



        	}



		}//die;



		$content_data['arr_upcoming_new'] = $arr_upcoming_new;











		/********************** Past Party Guestlist *****************************/



		$eventArrayOne = array();



		



		$query1 = "SELECT `shop_orders`.`ip_address`,`shop_booking_details`.`cart_id`,`shop_booking_details`.`event_id`,`evt_events`.`time_from`,`evt_events`.`title` from `shop_orders`,`shop_booking_details`,`evt_events` WHERE `shop_orders`.`payed`=1 AND `shop_orders`.`cart_id`=`shop_booking_details`.`cart_id` AND `shop_booking_details`.`event_id`=`evt_events`.`id` AND `evt_events`.`time_from` < ".time();



		$result1 = $this->db->query($query1);



		



		if($result1->num_rows()>0){



			foreach($result1->result() as $getKey1 => $getValue1){



				$getTime = date('Y',$getValue1->time_from);



				if(!array_key_exists($getTime, $eventArrayOne)){



					$eventArrayOne[$getTime] = 1;



				}else{



					$incrementValue = $eventArrayOne[$getTime];



					$eventArrayOne[$getTime] = $incrementValue+1;



				}



			}



		}



		$query2 = "SELECT `shop_orders`.`ip_address`,`shop_articles_carts`.`cart_id`,`shop_articles_carts`.`event_id`,`evt_events`.`time_from`,`evt_events`.`title` from `shop_orders`,`shop_articles_carts`,`evt_events` WHERE `shop_orders`.`payed`=1 AND `shop_orders`.`cart_id`=`shop_articles_carts`.`cart_id` AND `shop_articles_carts`.`event_id`=`evt_events`.`id` AND `evt_events`.`time_from` < ".time();



		$result2 = $this->db->query($query2);



		if($result2->num_rows()>0){



			foreach ($result2->result() as $getKey2 => $getValue2) {



				$getTime = date('Y',$getValue2->time_from);



				if(!array_key_exists($getTime,$eventArrayOne)){



					$eventArrayOne[$getTime] = 1;



				}else{



					$incrementValue = $eventArrayOne[$getTime];



					$eventArrayOne[$getTime] = $incrementValue+1;



				}



			}



		}



		ksort($eventArrayOne);



		$getFinalArray = array();



		foreach ($eventArrayOne as $eventArrayKey => $eventArrayValue) {



			$getFinalArray[] = array(



				'yearName' => $eventArrayKey,



				'user_number' => $eventArrayValue



			);



		}



		$content_data['pastPartyGuestList'] = $getFinalArray;



		//pr($content_data['arr_upcoming_new']);



		/************** Past Party Guestlist *************/











		/********************** Past Party Revenue *****************************/



		$paidRevenue = $this->common_model->getRevenue(1);



		$content_data['pastPartyRevenue'] = $paidRevenue;



		//pr($content_data['arr_upcoming_new']);



		/************** Past Party Revenue*************/











		/********************** Past Party Unpaid Revenue *****************************/



		$unpaidRevenue = $this->common_model->getRevenue(0);



		$content_data['pastPartyUnpaidRevenue'] = $unpaidRevenue;



		//pr($content_data['arr_upcoming_new']);



		/************** Past Party Unpaid Revenue*************/







		/************************* Registered User List **************************/



		$userList = $this->common_model->userListDetails();



		$content_data['userList'] = $userList;



		/************************* Registered User List **************************/







		/**************************** Total Revenue **************************/



		$content_data['revenueDetails'] = $this->common_model->revenueSection();







		/************Upcoming 30 days*************************/



		$arr_upcoming_day = array();



		for($i=1;$i<31;$i++)



		{



			$currDate = date('d-m-Y');



			$startDate = date('d-m-Y',strtotime('+'.($i-1).' days',strtotime($currDate)));



			$endDate =  date('d-m-Y',strtotime('+1 days',strtotime($startDate))) ;



			//echo $i.'='.$startDate.'='.$endDate.'<br/>';



			$arr_upcoming_day[$i]['date'] = $startDate;



			$qryStripePaid = $this->db->query('select * from (select shop_orders.*,shop_orders.created as cdate,case when time = 365 then DATE(FROM_UNIXTIME(shop_orders.created + (365 * 86400))) when time = 182 then DATE(FROM_UNIXTIME(shop_orders.created + (182 * 86400))) end as required_date from shop_orders join shop_articles_carts on shop_orders.cart_id = shop_articles_carts.cart_id where is_booking = 0 AND payment_method_id = 14 AND shop_articles_carts.cancelled is NULL AND shop_orders.payed = 1) b where required_date = "'.date('Y-m-d',strtotime($startDate)).'"');



			//$qryStripePaid = $this->db->query('select * from (select * from (SELECT usr_users.customer_id,usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(strtotime($startDate)-(182*86400)).' AND created <= '.(strtotime($endDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($startDate)-(365*86400)).' AND created <='.(strtotime($endDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 14 AND customer_id != "" AND (saferpay_exp != 0 OR saferpay_exp !="") order by b.created ASC');



			$ordersStripePaid = $qryStripePaid->result_array();



			//echo $this->db->last_query(); die;



        	if(count($ordersStripePaid)>0)



        	{



        		$total1 = 0;



        		foreach ($ordersStripePaid as $key => $stripePaid) {



        			$total1 = $total1 + $stripePaid['total_sum'];



        		}



        		$arr_upcoming_day[$i]['StripeValid'] = ceil(($total1/100));



        		//$arr_upcoming[$i]['StripeValid'] = ceil(($total/100)-((($total/100)*0.029)));



        	}



        	//echo ceil(($total1/100)).'<br>'; 



        	$qryqryStripeUnPaid = $this->db->query('select * from (select * from (SELECT usr_users.customer_id,usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(strtotime($startDate)-(182*86400)).' AND created <= '.(strtotime($endDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($startDate)-(365*86400)).' AND created <='.(strtotime($endDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 14 AND customer_id != "" AND (saferpay_exp = 0 OR saferpay_exp ="") order by b.created ASC');



        	$ordersStripeUnPaid = $qryqryStripeUnPaid->result_array();



        	if(count($ordersStripeUnPaid)>0)



        	{



        		$total2 = 0;



        		foreach ($ordersStripeUnPaid as $key => $stripeUnPaid) {



        			$total2 = $total2 + $stripeUnPaid['total_sum'];



        		}



        		$arr_upcoming_day[$i]['StripeInvalid'] = ceil(($total2/100));



        		//$arr_upcoming[$i]['StripeInvalid'] = ceil(($total/100)-((($total/100)*0.029)));;



        	}



        	$qryqrySaferpayPaid = $this->db->query('select * from (select * from (SELECT usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(strtotime($startDate)-(182*86400)).' AND created <= '.(strtotime($endDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($startDate)-(365*86400)).' AND created <='.(strtotime($endDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 13 order by b.created ASC');



        	$ordersSaferpayPaid = $qryqrySaferpayPaid->result_array();



        	if(count($ordersSaferpayPaid)>0)



        	{



        		$total3 = 0;



        		foreach ($ordersSaferpayPaid as $key => $SaferpayUnPaid) {



        			$total3 = $total3 + $SaferpayUnPaid['total_sum'];



        		}



        		$arr_upcoming_day[$i]['SaferpayValid'] = ceil($total3/100);



        	}



		}



		$content_data['arr_upcoming_day'] = $arr_upcoming_day;



		/************Upcoming 30 days*************************/















		/************Upcoming 30 days*************************/



		$arr_upcoming_day = array();



		for($i=1;$i<31;$i++)



		{



			$currDate = date('d-m-Y');



			$startDate = date('d-m-Y',strtotime('+'.($i).' days',strtotime($currDate)));



			$endDate =  date('d-m-Y',strtotime('+1 days',strtotime($startDate))) ;



			//echo $i.'='.$startDate.'='.$endDate.'<br/>';



			$arr_upcoming_day[$i]['date'] = $startDate;



			$qryStripePaid = $this->db->query('select * from (select shop_orders.*,shop_orders.created as cdate,case when time = 365 then DATE(FROM_UNIXTIME(shop_orders.created + (365 * 86400))) when time = 182 then DATE(FROM_UNIXTIME(shop_orders.created + (182 * 86400))) end as required_date from shop_orders join shop_articles_carts on shop_orders.cart_id = shop_articles_carts.cart_id where is_booking = 0 AND payment_method_id = 14 AND shop_articles_carts.cancelled is NULL AND shop_orders.payed = 1) b where required_date = "'.date('Y-m-d',strtotime($startDate)).'"');



			//$qryStripePaid = $this->db->query('select * from (select * from (SELECT usr_users.customer_id,usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(strtotime($startDate)-(182*86400)).' AND created <= '.(strtotime($endDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($startDate)-(365*86400)).' AND created <='.(strtotime($endDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 14 AND customer_id != "" AND (saferpay_exp != 0 OR saferpay_exp !="") order by b.created ASC');



			$ordersStripePaid = $qryStripePaid->result_array();



			//echo $this->db->last_query(); die;



        	if(count($ordersStripePaid)>0)



        	{



        		$total1 = 0;



        		foreach ($ordersStripePaid as $key => $stripePaid) {



        			$total1 = $total1 + $stripePaid['total_sum'];



        		}



        		$arr_upcoming_day[$i]['StripeValid'] = ceil(($total1/100));



        		//$arr_upcoming[$i]['StripeValid'] = ceil(($total/100)-((($total/100)*0.029)));



        	}



        	//echo ceil(($total1/100)).'<br>'; 



        	$qryqryStripeUnPaid = $this->db->query('select * from (select * from (SELECT usr_users.customer_id,usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(strtotime($startDate)-(182*86400)).' AND created <= '.(strtotime($endDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($startDate)-(365*86400)).' AND created <='.(strtotime($endDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 14 AND customer_id != "" AND (saferpay_exp = 0 OR saferpay_exp ="") order by b.created ASC');



        	$ordersStripeUnPaid = $qryqryStripeUnPaid->result_array();



        	if(count($ordersStripeUnPaid)>0)



        	{



        		$total2 = 0;



        		foreach ($ordersStripeUnPaid as $key => $stripeUnPaid) {



        			$total2 = $total2 + $stripeUnPaid['total_sum'];



        		}



        		$arr_upcoming_day[$i]['StripeInvalid'] = ceil(($total2/100));



        		//$arr_upcoming[$i]['StripeInvalid'] = ceil(($total/100)-((($total/100)*0.029)));;



        	}



        	$qryqrySaferpayPaid = $this->db->query('select * from (select * from (SELECT usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(strtotime($startDate)-(182*86400)).' AND created <= '.(strtotime($endDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($startDate)-(365*86400)).' AND created <='.(strtotime($endDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 13 order by b.created ASC');



        	$ordersSaferpayPaid = $qryqrySaferpayPaid->result_array();



        	if(count($ordersSaferpayPaid)>0)



        	{



        		$total3 = 0;



        		foreach ($ordersSaferpayPaid as $key => $SaferpayUnPaid) {



        			$total3 = $total3 + $SaferpayUnPaid['total_sum'];



        		}



        		$arr_upcoming_day[$i]['SaferpayValid'] = ceil($total3/100);



        	}



		}



		$content_data['arr_upcoming_day'] = $arr_upcoming_day;



		/************Upcoming 30 days*************************/



















		/************Past 30 days*************************/



		$arr_past_day = array();



		for($i=31;$i>0;$i--)



		{



			$currDate = date('d-m-Y');



			$startDate = date('d-m-Y',strtotime('-'.($i-1).' days',strtotime($currDate)));



			$endDate =  date('d-m-Y',strtotime('+1 days',strtotime($startDate))) ;



			//echo $i.'='.$startDate.'='.$endDate.'<br/>';



			$arr_past_day[$i]['date'] = $startDate;



			$qryStripePaid = $this->db->query('select * from (select shop_orders.*,shop_orders.created as cdate,DATE(FROM_UNIXTIME(shop_orders.created)) as required_date from shop_orders join shop_articles_carts on shop_orders.cart_id = shop_articles_carts.cart_id where is_booking = 0 AND payment_method_id = 14 AND shop_articles_carts.cancelled is NULL AND shop_orders.payed = 1) b where cdate between "'.strtotime($startDate.' 00:00:00').'" AND "'.strtotime($startDate.' 23:59:59').'"');



			//$qryStripePaid = $this->db->query('select * from (select shop_orders.*,shop_orders.created as cdate,case when time = 365 then DATE(FROM_UNIXTIME(shop_orders.created + (365 * 86400))) when time = 182 then DATE(FROM_UNIXTIME(shop_orders.created + (182 * 86400))) end as required_date from shop_orders join shop_articles_carts on shop_orders.cart_id = shop_articles_carts.cart_id where is_booking = 0 AND payment_method_id = 14 AND shop_articles_carts.cancelled is NULL AND shop_orders.payed = 1) b where required_date = "'.date('Y-m-d',strtotime($startDate)).'"');



			$ordersStripePaid = $qryStripePaid->result_array();



			//echo 'select * from (select shop_orders.*,shop_orders.created as cdate,DATE(FROM_UNIXTIME(shop_orders.created)) as required_date from shop_orders join shop_articles_carts on shop_orders.cart_id = shop_articles_carts.cart_id where is_booking = 0 AND payment_method_id = 14 AND shop_articles_carts.cancelled is NULL AND shop_orders.payed = 1) b where cdate between ("'.strtotime($startDate.' 00:00:00').'" AND "'.strtotime($startDate.' 23:59:59').'")'; die;



        	if(count($ordersStripePaid)>0)



        	{



        		$total1 = 0;



        		foreach ($ordersStripePaid as $key => $stripePaid) {



        			$total1 = $total1 + $stripePaid['total_sum'];



        		}



        		$arr_past_day[$i]['StripeValid'] = ceil(($total1/100));



        		//$arr_upcoming[$i]['StripeValid'] = ceil(($total/100)-((($total/100)*0.029)));



        	}











        	$arr_past_day[$i]['date'] = $startDate;



			$qrySaferpPaid = $this->db->query('select * from (select shop_orders.*,shop_orders.created as cdate,DATE(FROM_UNIXTIME(shop_orders.created)) as required_date from shop_orders join shop_articles_carts on shop_orders.cart_id = shop_articles_carts.cart_id where is_booking = 0 AND payment_method_id = 13 AND shop_articles_carts.cancelled is NULL AND shop_orders.payed = 1) b where cdate between "'.strtotime($startDate.' 00:00:00').'" AND "'.strtotime($startDate.' 23:59:59').'"');



			//$qryStripePaid = $this->db->query('select * from (select shop_orders.*,shop_orders.created as cdate,case when time = 365 then DATE(FROM_UNIXTIME(shop_orders.created + (365 * 86400))) when time = 182 then DATE(FROM_UNIXTIME(shop_orders.created + (182 * 86400))) end as required_date from shop_orders join shop_articles_carts on shop_orders.cart_id = shop_articles_carts.cart_id where is_booking = 0 AND payment_method_id = 14 AND shop_articles_carts.cancelled is NULL AND shop_orders.payed = 1) b where required_date = "'.date('Y-m-d',strtotime($startDate)).'"');



			$ordersSaferpPaid = $qrySaferpPaid->result_array();



			//echo 'select * from (select shop_orders.*,shop_orders.created as cdate,DATE(FROM_UNIXTIME(shop_orders.created)) as required_date from shop_orders join shop_articles_carts on shop_orders.cart_id = shop_articles_carts.cart_id where is_booking = 0 AND payment_method_id = 14 AND shop_articles_carts.cancelled is NULL AND shop_orders.payed = 1) b where cdate between ("'.strtotime($startDate.' 00:00:00').'" AND "'.strtotime($startDate.' 23:59:59').'")'; die;



        	if(count($ordersSaferpPaid)>0)



        	{



        		$total1 = 0;



        		foreach ($ordersSaferpPaid as $key => $SaferpPaid) {



        			$total1 = $total1 + $SaferpPaid['total_sum'];



        		}



        		$arr_past_day[$i]['SaferpValid'] = ceil(($total1/100));



        		//$arr_upcoming[$i]['StripeValid'] = ceil(($total/100)-((($total/100)*0.029)));



        	}



		}



		$content_data['arr_past_day'] = $arr_past_day;



		/************Past 30 days*************************/











		/************Different Type Member Statictics*************************/



		$qryCompleteAvatar = $this->db->query('select * from feu_userdetails join feu_user_steps on feu_userdetails.user_id = feu_user_steps.user_id where step = 6 and feu_userdetails.created > '.(time()-30*84600));



		$completeAvatar = $qryCompleteAvatar->num_rows();







		$qryBeforeAvatar = $this->db->query('select * from feu_userdetails join feu_user_steps on feu_userdetails.user_id = feu_user_steps.user_id where step = 5 and feu_userdetails.created > '.(time()-30*84600));



		$beforeAvatar = $qryBeforeAvatar->num_rows();



		



		$qryFreeHaving3Pic = $this->db->query('select * from feu_userdetails join sys_files on feu_userdetails.user_id = sys_files.user_id where path="usergalleries/" AND accepted = 1 AND free_member = 1 AND feu_userdetails.created > '.(time()-30*84600).' group by sys_files.user_id  Having COUNT(*) > 2');



		$freeHaving3Pic = $qryFreeHaving3Pic->num_rows();







		$qryFreeHavingLessPic = $this->db->query('select * from feu_userdetails join sys_files on feu_userdetails.user_id = sys_files.user_id where path="usergalleries/" AND accepted = 1 AND free_member = 1 AND feu_userdetails.created > '.(time()-30*84600).' group by sys_files.user_id  Having COUNT(*) < 3');



		$freeHavingLessPic = $qryFreeHavingLessPic->num_rows();







		$qryFreeReal = $this->db->query('select * from feu_userdetails where reality_authenticated = 1 and free_member = 1 and feu_userdetails.created > '.(time()-30*84600));



		$freeReal = $qryFreeReal->num_rows();







		$qryEmailConfirm = $this->db->query('select * from usr_users where email_confirmed = 1 and created > '.(time()-30*84600));



		$emailConfirm = $qryEmailConfirm->num_rows();







		$qryEmailNotConfirm = $this->db->query('select * from usr_users where email_confirmed = 0 and created > '.(time()-30*84600));



		$emailNotConfirm = $qryEmailNotConfirm->num_rows();







		$qryPaidMembers = $this->db->query('select * from shop_orders where is_renewed = 0 and payed = 1 and is_booking = 0 and refund_trn_id = "" and created > '.(time()-30*84600));



		$paidMembers = $qryPaidMembers->num_rows();







		$qryAllMembers = $this->db->query('select * from feu_userdetails where created > '.(time()-30*84600));



		$allMembers = $qryAllMembers->num_rows();







		$content_data['completeAvatar'] = number_format((float)($completeAvatar/$allMembers)*100, 2, '.', '');



		$content_data['beforeAvatar'] = number_format((float)($beforeAvatar/$allMembers)*100, 2, '.', '');



		$content_data['freeHaving3Pic'] = number_format((float)($freeHaving3Pic/$allMembers)*100, 2, '.', '');



		$content_data['freeHavingLessPic'] = number_format((float)($freeHavingLessPic/$allMembers)*100, 2, '.', '');



		$content_data['freeReal'] = number_format((float)($freeReal/$allMembers)*100, 2, '.', '');



		$content_data['emailConfirm'] = number_format((float)($emailConfirm/$allMembers)*100, 2, '.', '');



		$content_data['emailNotConfirm'] = number_format((float)($emailNotConfirm/$allMembers)*100, 2, '.', '');



		$content_data['paidMembers'] = number_format((float)($paidMembers/$allMembers)*100, 2, '.', '');



		$content_data['allMembers'] = $allMembers;







		//$content_data['arr_diff_member'] = $arr_diff_member;



		/************Different Type Member Statictics*************************/



















		/************Different Type Member Statictics*************************/



		$qryCompleteAvatarMonths = $this->db->query('select * from feu_userdetails join feu_user_steps on feu_userdetails.user_id = feu_user_steps.user_id where step = 6 and feu_userdetails.created > '.(time()-12*30*84600));



		$completeAvatarMonths = $qryCompleteAvatarMonths->num_rows();







		$qryBeforeAvatarMonths = $this->db->query('select * from feu_userdetails join feu_user_steps on feu_userdetails.user_id = feu_user_steps.user_id where step = 5 and feu_userdetails.created > '.(time()-12*30*84600));



		$beforeAvatarMonths = $qryBeforeAvatarMonths->num_rows();



		



		$qryFreeHaving3PicMonths = $this->db->query('select * from feu_userdetails join sys_files on feu_userdetails.user_id = sys_files.user_id where path="usergalleries/" AND accepted = 1 AND free_member = 1 AND feu_userdetails.created > '.(time()-12*30*84600).' group by sys_files.user_id  Having COUNT(*) > 2');



		$freeHaving3PicMonths = $qryFreeHaving3PicMonths->num_rows();







		$qryFreeHavingLessPicMonths = $this->db->query('select * from feu_userdetails join sys_files on feu_userdetails.user_id = sys_files.user_id where path="usergalleries/" AND accepted = 1 AND free_member = 1 AND feu_userdetails.created > '.(time()-12*30*84600).' group by sys_files.user_id  Having COUNT(*) < 3');



		$freeHavingLessPicMonths = $qryFreeHavingLessPicMonths->num_rows();







		$qryFreeRealMonths = $this->db->query('select * from feu_userdetails where reality_authenticated = 1 and free_member = 1 and feu_userdetails.created > '.(time()-12*30*84600));



		$freeRealMonths = $qryFreeRealMonths->num_rows();







		$qryEmailConfirmMonths = $this->db->query('select * from usr_users where email_confirmed = 1 and created > '.(time()-12*30*84600));



		$emailConfirmMonths = $qryEmailConfirmMonths->num_rows();







		$qryEmailNotConfirmMonths = $this->db->query('select * from usr_users where email_confirmed = 0 and created > '.(time()-12*30*84600));



		$emailNotConfirmMonths = $qryEmailNotConfirmMonths->num_rows();







		$qryPaidMembersMonths = $this->db->query('select * from shop_orders where is_renewed = 0 and payed = 1 and is_booking = 0 and refund_trn_id = "" and created > '.(time()-12*30*84600));



		$paidMembersMonths = $qryPaidMembersMonths->num_rows();







		$qryAllMembersMonths = $this->db->query('select * from feu_userdetails where created > '.(time()-12*30*84600));



		$allMembersMonths = $qryAllMembersMonths->num_rows();







		$content_data['completeAvatarMonths'] = number_format((float)($completeAvatarMonths/$allMembersMonths)*100, 2, '.', '');



		$content_data['beforeAvatarMonths'] = number_format((float)($beforeAvatarMonths/$allMembersMonths)*100, 2, '.', '');



		$content_data['freeHaving3PicMonths'] = number_format((float)($freeHaving3PicMonths/$allMembersMonths)*100, 2, '.', '');



		$content_data['freeHavingLessPicMonths'] = number_format((float)($freeHavingLessPicMonths/$allMembersMonths)*100, 2, '.', '');



		$content_data['freeRealMonths'] = number_format((float)($freeRealMonths/$allMembersMonths)*100, 2, '.', '');



		$content_data['emailConfirmMonths'] = number_format((float)($emailConfirmMonths/$allMembersMonths)*100, 2, '.', '');



		$content_data['emailNotConfirmMonths'] = number_format((float)($emailNotConfirmMonths/$allMembersMonths)*100, 2, '.', '');



		$content_data['paidMembersMonths'] = number_format((float)($paidMembersMonths/$allMembersMonths)*100, 2, '.', '');



		$content_data['allMembersMonths'] = $allMembersMonths;







		//$content_data['arr_diff_member'] = $arr_diff_member;



		/************Different Type Member Statictics*************************/























		/**********Current VS 1 year ago**********************/



		for($n=1;$n<13;$n++)



		{



			$cuurent_year = date('Y');



			$old_year = $cuurent_year-1;



			$two_old_year = $cuurent_year-2;



			if($n==1)



			{



				$currVSyear[$n]['month'] = 'Jan';



			}



			elseif($n==2)



			{



				$currVSyear[$n]['month'] = 'Feb';



			}



			elseif($n==3)



			{



				$currVSyear[$n]['month'] = 'Mar';



			}



			elseif($n==4)



			{



				$currVSyear[$n]['month'] = 'Apr';



			}



			elseif($n==5)



			{



				$currVSyear[$n]['month'] = 'May';



			}



			elseif($n==6)



			{



				$currVSyear[$n]['month'] = 'Jun';



			}



			elseif($n==7)



			{



				$currVSyear[$n]['month'] = 'Jul';



			}



			elseif($n==8)



			{



				$currVSyear[$n]['month'] = 'Aug';



			}



			elseif($n==9)



			{



				$currVSyear[$n]['month'] = 'Sep';



			}



			elseif($n==10)



			{



				$currVSyear[$n]['month'] = 'Oct';



			}



			elseif($n==11)



			{



				$currVSyear[$n]['month'] = 'Nov';



			}



			else



			{



				$currVSyear[$n]['month'] = 'Dec';



			} 



			$whereCurrent = 'is_renewed = 0 and payed = 1 and is_booking = 0 and refund_trn_id = "" and MONTH(FROM_UNIXTIME(shop_orders.created)) = '.$n.' and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$cuurent_year;



			$currVSyearNew[$n]['current_members'] = count($this->common_model->getAll('shop_orders',$whereCurrent,'','created'));



			$whereOld = 'is_renewed = 0 and payed = 1 and is_booking = 0 and refund_trn_id = "" and MONTH(FROM_UNIXTIME(shop_orders.created)) = '.$n.' and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$old_year;



			$currVSyearNew[$n]['old_members'] = count($this->common_model->getAll('shop_orders',$whereOld,'','created'));



			$whereTwoYearOld = 'is_renewed = 0 and payed = 1 and is_booking = 0 and refund_trn_id = "" and MONTH(FROM_UNIXTIME(shop_orders.created)) = '.$n.' and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$two_old_year;



			$currVSyearNew[$n]['tow_year_old_members'] = count($this->common_model->getAll('shop_orders',$whereTwoYearOld,'','created'));











			$whereCurrent = 'is_renewed = 1 and payed = 1 and is_booking = 0 and refund_trn_id = "" and MONTH(FROM_UNIXTIME(shop_orders.created)) = '.$n.' and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$cuurent_year;



			$currVSyearRenew[$n]['current_members'] = count($this->common_model->getAll('shop_orders',$whereCurrent,'','created'));



			$whereOld = 'is_renewed = 1 and payed = 1 and is_booking = 0 and refund_trn_id = "" and MONTH(FROM_UNIXTIME(shop_orders.created)) = '.$n.' and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$old_year;



			$currVSyearRenew[$n]['old_members'] = count($this->common_model->getAll('shop_orders',$whereOld,'','created'));



			$whereTwoYearOld = 'is_renewed = 1 and payed = 1 and is_booking = 0 and refund_trn_id = "" and MONTH(FROM_UNIXTIME(shop_orders.created)) = '.$n.' and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$two_old_year;



			$currVSyearRenew[$n]['tow_year_old_members'] = count($this->common_model->getAll('shop_orders',$whereTwoYearOld,'','created'));











			$whereCurrent = 'is_renewed = 0 and payed = 1 and is_booking = 1 and refund_trn_id = "" and MONTH(FROM_UNIXTIME(shop_orders.created)) = '.$n.' and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$cuurent_year;



			$currVSyearBook[$n]['current_members'] = count($this->common_model->getAll('shop_orders',$whereCurrent,'','created'));



			//echo $this->db->last_query();



			$whereOld = 'is_renewed = 0 and payed = 1 and is_booking = 1 and refund_trn_id = "" and MONTH(FROM_UNIXTIME(shop_orders.created)) = '.$n.' and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$old_year;



			$currVSyearBook[$n]['old_members'] = count($this->common_model->getAll('shop_orders',$whereOld,'','created'));



			$whereTwoYearOld = 'is_renewed = 0 and payed = 1 and is_booking = 1 and refund_trn_id = "" and MONTH(FROM_UNIXTIME(shop_orders.created)) = '.$n.' and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$two_old_year;



			$currVSyearBook[$n]['tow_year_old_members'] = count($this->common_model->getAll('shop_orders',$whereTwoYearOld,'','created'));



		}



		//pr($currVSyearRenew);



		/**********Current VS 1 year ago**********************/







		$content_data['currVSyear'] = $currVSyear;



		$content_data['currVSyearNew'] = $currVSyearNew;



		$content_data['currVSyearRenew'] = $currVSyearRenew;



		$content_data['currVSyearBook'] = $currVSyearBook;



		/**********safer pay upcoming**********************/



		$arr_upcoming_safer = array();



		$arr_upcoming_stripe = array();



		



		for($n=1;$n<14;$n++)



		{



			$totals3 = 0;



			$totals3_stripe = 0;



			



			 if($n==1)



			{



				$startDate = date('01-'.date('m').'-'.date('Y'));



				$endDate = date("t-m-Y", strtotime($startDate));



			}



			else



			{



				$startDate = date('d-m-Y', strtotime('+1 month', strtotime($startDate)));



				//$startDate = '01-'.$i.'-'.date('Y');



				$endDate = date("t-m-Y", strtotime($startDate));



				//$endDate = '31-'.$i.'-'.date('Y');



			} 



			



	//echo 'stdate='.$startDate ;



				//$startDate = '01-11-2019';



	//echo 'endate='.$endDate."<br />" ;



		 		//$endDate = '30-11-2019';



		/* echo 	$startDate."<br >";



			 var_dump('select * from (select * from (SELECT usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`,`usr_users`.`card_alias`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b







			where case when time = 182 then (created >= '.(strtotime($startDate)-(182*86400)).' AND created <= '.(strtotime($endDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($startDate)-(365*86400)).' AND created <='.(strtotime($endDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 13 and `card_alias` is not NULL and `cc_ref_id` is NULL and saferpay_exp > 0 order by b.created DESC'); */



			



			$end_exp_month = date('n',strtotime($endDate));



			$end_exp_year = date('Y',strtotime($endDate));







			$qryqrySaferpayPaidrenewal = $this->db->query('select * from (select * from (SELECT usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`,`usr_users`.`card_alias`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b







			where case when time = 182 then (created >= '.(strtotime($startDate)-(182*86400)).' AND created <= '.(strtotime($endDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($startDate)-(365*86400)).' AND created <='.(strtotime($endDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 13 and `card_alias` is not NULL and `cc_ref_id` is NULL and saferpay_exp > 0 order by b.created DESC'); 



			



					



			$qryqrySaferpayPaidrenewal_stripe = $this->db->query('select * from (select * from (SELECT usr_users.saferpay_exp,shop_orders.time,shop_articles_carts.article_id,shop_orders.created,shop_orders.cart_id,`usr_users`.`id` as `user_id`,`usr_users`.`email` as `email`,`usr_users`.`card_alias`, `usr_users`.`cc_ref_id`, `shop_articles`.`userstatus`,shop_orders.total_base, shop_orders.total_sum,shop_orders.payment_method_id,shop_orders.order_id_masked FROM `shop_articles` INNER JOIN `shop_articles_carts` ON `shop_articles_carts`.`article_id` = `shop_articles`.`id` INNER JOIN `shop_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` INNER JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` INNER JOIN `shop_orders` ON `shop_orders`.`cart_id` = `shop_carts`.`id` WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a GROUP BY a.user_id ORDER BY a.user_id DESC) as b







			where case when time = 182 then (created >= '.(strtotime($startDate)-(182*86400)).' AND created <= '.(strtotime($endDate)-(182*86400)).') when time = 365 then (created >= '.(strtotime($startDate)-(365*86400)).' AND created <='.(strtotime($endDate)-(365*86400)).') END AND article_id in (5,4) AND payment_method_id = 14 and `card_alias` is NULL and `cc_ref_id` is NULL and saferpay_exp > 0 order by b.created DESC'); 



			



        	$ordersSaferpayPaidrenewal = $qryqrySaferpayPaidrenewal->result_array();



        	$ordersSaferpayPaidrenewal_stripe = $qryqrySaferpayPaidrenewal_stripe->result_array();



        	if(count($ordersSaferpayPaidrenewal)>0)



        	{



        		



        		foreach ($ordersSaferpayPaidrenewal as $key => $SaferpayPaid) {



        			if($SaferpayPaid['saferpay_exp']>0){



						$exp_year_qry = '20'.substr ($SaferpayPaid['saferpay_exp'], -2);



						$exp_month_qry= substr($SaferpayPaid['saferpay_exp'], 0, -3);



						if($exp_year_qry > $end_exp_year ){



								$totals3 = $totals3 + $SaferpayPaid['total_sum'];



						}elseif($exp_year_qry == $end_exp_year){



							if($exp_month_qry >= $end_exp_month){



								$totals3 = $totals3 + $SaferpayPaid['total_sum'];



							}



							



						}



					}



        			//$totals3 = $totals3 + $SaferpayPaid['total_sum'];



        		}



        	}



			



			$arr_upcoming_safer[$n]['safermonth']= date('M',strtotime($startDate));



			$arr_upcoming_safer[$n]['totals3']= ceil($totals3/100);



		



		if(count($ordersSaferpayPaidrenewal_stripe)>0)



        	{



        		



        		foreach ($ordersSaferpayPaidrenewal_stripe as $key => $SaferpaynotPaid) {



        			$totals3_stripe = $totals3_stripe + $SaferpaynotPaid['total_sum'];



        		}



        	}



			



			//$arr_upcoming_stripe[$n]['safermonth']= date('M',strtotime($startDate));



			$arr_upcoming_stripe[$n]['totals3_stripe']= ceil($totals3_stripe/100);



		}



	//	die();



		$content_data['arr_upcoming_safer']=$arr_upcoming_safer;



		$content_data['arr_upcoming_stripe']=$arr_upcoming_stripe;



		



			/**********safer pay upcoming**********************/



		/* var_dump($content_data['arr_upcoming_safer']);







		die() */; 



		



		$arr_upcoming_safer_by_month = array();



		for($n=1;$n<14;$n++)



		{  $total_sum_by_month=0;



		 $total_sum_by_months=0;



			if($n==1)



			{   



				$startDate = date('01-05-2019');



				$endDate = date("t-m-Y", strtotime($startDate));



			}



			else



			{



				$startDate = date('d-m-Y', strtotime('+1 month', strtotime($startDate)));



				//$startDate = '01-'.$i.'-'.date('Y');



				$endDate = date("t-m-Y", strtotime($startDate));



				//$endDate = '31-'.$i.'-'.date('Y');



			} 



			



	//echo "<br /> stdate=".$startDate ;



				



	//echo 'endate='.$endDate."<br />" ;



		 		



		$shop_orders='select * from (select * from shop_orders where is_renewed=1 and payed=1 and is_booking=0 and   created >= '.(strtotime($startDate)).' AND created <= '.(strtotime($endDate)).' order by created desc)as b group by b.invoiceAddress';



		



		//echo $shop_orders;die();



		$qryqryshop_orders = $this->db->query($shop_orders);



        $qryqryshop_orders_res = $qryqryshop_orders->result_array();



		



		$shop_orders_paymentdate="select * from (select * from shop_orders where is_renewed=1 and payed=1 and is_booking=0 and   payment_date >= '".(date('y-m-d',strtotime($startDate)))."' AND payment_date <= '".(date('Y-m-d',strtotime($endDate)))."' order by created desc)as b group by b.invoiceAddress";



		



		$qryqryshop_orders_paymentdate = $this->db->query($shop_orders_paymentdate);



        $qryqryshop_orders_paymentdate_res = $qryqryshop_orders_paymentdate->result_array();



		$qryqryshop_orders_res_marge = array_merge($qryqryshop_orders_res,$qryqryshop_orders_paymentdate_res);



		



		



		/* var_dump($qryqryshop_orders_res);



		echo '-----------------------------------------';



		var_dump($qryqryshop_orders_paymentdate_res);



		echo '-----------------------------------------';



		var_dump($qryqryshop_orders_res_marge);die();  */



        	  if(count($qryqryshop_orders_res_marge)>0)



        	{



        		foreach ($qryqryshop_orders_res_marge as $key => $val) {



					//var_dump($val['invoiceAddress']);



					$email = $val['invoiceAddress'];



        			$shop_orders_final = "select * from shop_orders where payed=1 and invoiceAddress='".$email."' and is_booking=0 order by created desc limit 1,1";



					//echo $shop_orders_final; 



					$qryqryshop_orders_final = $this->db->query($shop_orders_final);



					$qryqryshop_orders_res_final = $qryqryshop_orders_final->row_array();



					



					 if($qryqryshop_orders_res_final['total_sum']){



						//if($qryqryshop_orders_res_final['payment_method_id']==14){



							



							$total_sum_by_month = $total_sum_by_month+$qryqryshop_orders_res_final['total_sum'];



						//}



					} 



        		}



        	} //die();



			



			$shop_orders1='select * from (select * from shop_orders where is_renewed=1 and is_booking=0 and  created >= '.(strtotime($startDate)).' AND created <= '.(strtotime($endDate)).' order by created desc)as b group by b.invoiceAddress';



		



			$qryqryshop_orders1 = $this->db->query($shop_orders1);



			 



			//var_dump($qryqryshop_orders); 



			



			



        $qryqryshop_orders_res1 = $qryqryshop_orders1->result_array();



		//var_dump( $qryqryshop_orders_res);



        	  if(count($qryqryshop_orders_res1)>0)



        	{



        		foreach ($qryqryshop_orders_res1 as $key1 => $val1) {



				//	var_dump($val['invoiceAddress']);



							$total_sum_by_months = $total_sum_by_months+ $val1['total_sum'];



						}



					} 



        		



			$arr_upcoming_safer_by_month[$n]['safermonths']= date('M',strtotime($startDate));



			$arr_upcoming_safer_by_month[$n]['safer_by_month_ammount']= ceil($total_sum_by_month/100);



			$arr_upcoming_safer_by_month[$n]['safer_by_month_ammount_get']= ceil($total_sum_by_months/100);



		//	var_dump (ceil($total_sum_by_month/100));



		} 



		



		//die();



		



		$content_data['arr_upcoming_safer_by_month']=$arr_upcoming_safer_by_month;



		



		



		/****************************************Week wise booking report****************************************/



		$prev_prev_year = date('Y')-2;



		$prev_year = date('Y')-1;



		$curr_year = date('Y');



		



		$weekwisebook = [];



		for($week=1;$week<53;$week++){



			$weekwisebook[$week]['week'] = $week;



			$prev_prev_qry = $this->db->query("SELECT COUNT(*) as total,order_id,WEEK(FROM_UNIXTIME(`created`)) as week ,created FROM `shop_orders` WHERE YEAR(FROM_UNIXTIME(`created`))=".$prev_prev_year." AND WEEK(FROM_UNIXTIME(`created`))=".$week." AND is_booking = 1 AND WEEK(FROM_UNIXTIME(`created`)) > 0 GROUP BY week ORDER BY WEEK(FROM_UNIXTIME(`created`)) ASC");



			$prev_prev_weekwisebook_new = $prev_prev_qry->row_array();



			$prev_prev_qry_old = $this->db->query("SELECT COUNT(*) as total,order_id,WEEK(FROM_UNIXTIME(shop_orders.`created`)) as week ,shop_orders.created FROM `shop_orders` JOIN shop_articles_carts ON shop_orders.cart_id = shop_articles_carts.cart_id WHERE YEAR(FROM_UNIXTIME(shop_orders.`created`))=".$prev_prev_year." AND WEEK(FROM_UNIXTIME(shop_orders.`created`))=".$week." AND event_id > 0 AND WEEK(FROM_UNIXTIME(shop_orders.`created`)) > 0 GROUP BY week ORDER BY WEEK(FROM_UNIXTIME(shop_orders.`created`)) ASC");



			$prev_prev_weekwisebook_old = $prev_prev_qry_old->row_array();



			//$prev_prev_weekwisebook = array_merge($prev_prev_weekwisebook_new, $prev_prev_weekwisebook_old);



			//echo '<pre>'; print_r($prev_prev_weekwisebook_new);print_r($prev_prev_weekwisebook_old);die;



			$prev_qry = $this->db->query("SELECT COUNT(*) as total,order_id,WEEK(FROM_UNIXTIME(`created`)) as week ,created FROM `shop_orders` WHERE YEAR(FROM_UNIXTIME(`created`))=".$prev_year." AND WEEK(FROM_UNIXTIME(`created`))=".$week." AND is_booking = 1 AND WEEK(FROM_UNIXTIME(`created`)) > 0 GROUP BY week ORDER BY WEEK(FROM_UNIXTIME(`created`)) ASC");



			$prev_weekwisebook = $prev_qry->row_array();



			$curr_qry = $this->db->query("SELECT COUNT(*) as total,order_id,WEEK(FROM_UNIXTIME(`created`)) as week ,created FROM `shop_orders` WHERE YEAR(FROM_UNIXTIME(`created`))=".$curr_year." AND WEEK(FROM_UNIXTIME(`created`))=".$week." AND is_booking = 1 AND WEEK(FROM_UNIXTIME(`created`)) > 0 GROUP BY week ORDER BY WEEK(FROM_UNIXTIME(`created`)) ASC");



			$curr_weekwisebook = $curr_qry->row_array();



			$weekwisebook[$week]['prev_prev'] = $prev_prev_weekwisebook_new ? $prev_prev_weekwisebook_new['total'] : $prev_prev_weekwisebook_old['total'];



			$weekwisebook[$week]['prev'] = $prev_weekwisebook['total'];



			$weekwisebook[$week]['curr'] = $curr_weekwisebook['total'];



		}



		/****************************************Week wise booking report****************************************/



		



		/********************************Top 8 party revenue*************************************/



		/*$topeventsrevenue = $this->common_model->getAllMultipleJoin('evt_events',array('time_from <'=>time()),'','time_from DESC','title,id','',0,8);



		foreach ($topeventsrevenue as $eventskey => $eventsvalue) {



			$qry = $this->db->query("SELECT `total_sum` FROM `shop_orders` JOIN `shop_carts` ON `shop_orders`.`cart_id` = `shop_carts`.`id` JOIN `shop_booking_details` ON `shop_booking_details`.`cart_id` = `shop_carts`.`id` JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` WHERE `event_id` = ".$eventsvalue['id']." AND `payed` = 1 GROUP BY `shop_booking_details`.`cart_id` ORDER BY `shop_orders`.`created` DESC");



			$revenue = $qry->result_array();



			//echo $this->db->last_query();



			$total = 0;



			foreach ($revenue as $key => $value) {



				$total += $value['total_sum'];



			}



			$topeventsrevenue[$eventskey]['total_sum'] = $total;



		}



		foreach ($topeventsrevenue as $key => $row)



		{



		    $vc_array_name[$key] = $row['total_sum'];



		}



		array_multisort($vc_array_name, SORT_DESC, $topeventsrevenue);



		$content_data['topeventsrevenue']=$topeventsrevenue;*/







		$topeventsrevenue = $this->db->query("select evt_events.id, title ,sum(total_sum) total_sum from (SELECT event_id, total_sum,shop_booking_details.cart_id FROM `shop_orders` JOIN `shop_carts` ON `shop_orders`.`cart_id` = `shop_carts`.`id` JOIN `shop_booking_details` ON `shop_booking_details`.`cart_id` = `shop_carts`.`id` JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` WHERE `payed` = 1 GROUP BY shop_booking_details.cart_id ORDER BY `shop_orders`.`created` DESC ) a join evt_events on evt_events.id = a.event_id group by event_id order by total_sum desc limit 8");



		$content_data['topeventsrevenue'] = $topeventsrevenue->result_array();



		/********************************Top 8 party revenue*************************************/











		/********************************Top 8 upcoming party revenue*************************************/



		$topupeventsrevenue = $this->common_model->getAllMultipleJoin('evt_events',array('time_from >'=>time()),'','time_from DESC','title,id','',0,8);



		foreach ($topupeventsrevenue as $eventskey => $eventsvalue) {



			$qry = $this->db->query("SELECT `total_sum` FROM `shop_orders` JOIN `shop_carts` ON `shop_orders`.`cart_id` = `shop_carts`.`id` JOIN `shop_booking_details` ON `shop_booking_details`.`cart_id` = `shop_carts`.`id` JOIN `usr_users` ON `usr_users`.`id` = `shop_carts`.`user_id` WHERE `event_id` = ".$eventsvalue['id']." AND `payed` = 1 GROUP BY `shop_booking_details`.`cart_id` ORDER BY `shop_orders`.`created` DESC");



			$revenue = $qry->result_array();



			//echo $this->db->last_query();



			$total = 0;



			foreach ($revenue as $key => $value) {



				$total += $value['total_sum'];



			}



			$topupeventsrevenue[$eventskey]['total_sum'] = $total;



		}



		foreach ($topupeventsrevenue as $key => $row)



		{



		    $vc_array_name1[$key] = $row['total_sum'];



		}



		array_multisort($vc_array_name1, SORT_DESC, $topupeventsrevenue);



		$content_data['topupeventsrevenue']=$topupeventsrevenue;



		/********************************Top 8 upcoming party revenue*************************************/



		







		$content_data['weekwisebook']=$weekwisebook;























		/*$qryBest = $this->db->query("SELECT shop_carts.user_id,count(case when (is_booking = 1) then 1 end) count_book,count(case when (checkin_amount > 0) then 1 end) count_participation,checkin_amount,username,sum(total_sum) booking_total,sum(checkin_amount) as checkin_sum,path,filename,extension FROM `shop_booking_details` left join shop_carts on shop_carts.id = shop_booking_details.cart_id left join shop_orders on shop_carts.id = shop_orders.cart_id left join evt_events on evt_events.id = shop_booking_details.event_id left join feu_userdetails on shop_carts.user_id = feu_userdetails.user_id left join sys_files on sys_files.id = feu_userdetails.avatar_file_id WHERE payed = 1 and is_booking = 1 and YEAR(FROM_UNIXTIME(time_from)) = ".date('Y')." and shop_booking_details.feature_type = 1  AND username is not NULL group by shop_carts.user_id ORDER BY sum(total_sum) DESC LIMIT 50");



		$content_data['resultBest'] = $resultBest = $qryBest->result_array();



		if($content_data['resultBest']){



			foreach ($content_data['resultBest'] as $key => $value) {



				$where = "YEAR(FROM_UNIXTIME(shop_orders.created)) = ".date('Y')." AND is_booking = 0 AND payed = 1 AND user_id = ".$value['user_id']." AND article_id in (4,5)";



				$membership = $this->common_model->getAllRowMultipleJoin('shop_orders',$where,array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_carts.id = shop_articles_carts.cart_id')),'','sum(total_sum) order_total','shop_carts.user_id');



				if($membership){



					$content_data['resultBest'][$key]['order_total'] = $membership['order_total'];



					$content_data['resultBest'][$key]['full_total'] = $value['booking_total'] + $membership['order_total'];



				}



			}



		}*/



		/*$qry = $this->db->query("SELECT sum(total_sum) order_total, `shop_carts`.`user_id`, order_id, shop_orders.created,DATE(FROM_UNIXTiME(shop_orders.created)) date,YEAR(FROM_UNIXTIME(shop_orders.created)) year,username,path,filename,extension FROM `shop_orders` LEFT JOIN `shop_carts` ON `shop_carts`.`id` = `shop_orders`.`cart_id` LEFT JOIN `shop_articles_carts` ON `shop_carts`.`id` = `shop_articles_carts`.`cart_id` left join feu_userdetails on shop_carts.user_id = feu_userdetails.user_id left join sys_files on sys_files.id = feu_userdetails.avatar_file_id WHERE YEAR(FROM_UNIXTIME(shop_orders.created)) = '".date('Y')."' AND `is_booking` =0 AND `payed` = 1 AND `article_id` in (4,5) GROUP BY `shop_carts`.`user_id` ORDER BY sum(total_sum) DESC LIMIT 50");



		$content_data['resultBest'] = $qry->result_array();



		//echo $this->db->last_query();



		//pr($content_data['resultBest']);die;



		if($content_data['resultBest']){



			foreach ($content_data['resultBest'] as $key => $value) {



				$qryBest = $this->db->query("SELECT shop_carts.user_id,count(case when (is_booking = 1) then 1 end) count_book,count(case when (checkin_amount > 0) then 1 end) count_participation,checkin_amount,sum(total_sum) booking_total,sum(checkin_amount) as checkin_sum FROM `shop_booking_details` left join shop_carts on shop_carts.id = shop_booking_details.cart_id left join shop_orders on shop_carts.id = shop_orders.cart_id left join evt_events on evt_events.id = shop_booking_details.event_id WHERE payed = 1 and is_booking = 1 and YEAR(FROM_UNIXTIME(time_from)) = '".date('Y')."' and shop_booking_details.feature_type = 1  AND shop_carts.user_id = ".$value['user_id']." group by shop_carts.user_id ORDER BY sum(total_sum) DESC");



				$resultBest = $qryBest->row_array();



				//echo $this->db->last_query();die;



				$content_data['resultBest'][$key]['booking_total'] = 0;



				$content_data['resultBest'][$key]['count_book'] = 0;



				$content_data['resultBest'][$key]['count_participation'] = 0;



				$content_data['resultBest'][$key]['checkin_amount'] = 0;



				$content_data['resultBest'][$key]['checkin_sum'] = 0;



				$content_data['resultBest'][$key]['booking_total'] = 0;



				$content_data['resultBest'][$key]['full_total'] = $content_data['resultBest'][$key]['booking_total'] + $value['order_total'];







				if($resultBest){



					$content_data['resultBest'][$key]['booking_total'] = $resultBest['booking_total'];



					$content_data['resultBest'][$key]['count_book'] = $resultBest['count_book'];



					$content_data['resultBest'][$key]['count_participation'] = $resultBest['count_participation'];



					$content_data['resultBest'][$key]['checkin_amount'] = $resultBest['checkin_amount'];



					$content_data['resultBest'][$key]['checkin_sum'] = $resultBest['checkin_sum'];



					$content_data['resultBest'][$key]['booking_total'] = $resultBest['booking_total'];



					$content_data['resultBest'][$key]['full_total'] = $resultBest['booking_total'] + $value['order_total'];



				}



			}



		}



		foreach ($content_data['resultBest'] as $keys => $rows)



		{



		    $vc_array_name[$keys] = $rows['full_total'];



		}



		array_multisort($vc_array_name, SORT_DESC, $content_data['resultBest']);*/



		$qry = $this->db->query("select *, sum(order_totals) order_total,sum(booking_totals) booking_total,sum(full_totals) full_total from (select is_booking,total_sum,feu_userdetails.user_id, path, extension, filename, username, order_id, invoiceAddress, payed, (case when is_booking=1 then sum(total_sum) else 0 end) booking_totals, (case when is_booking=0 then sum(total_sum) else 0 end) order_totals,((case when is_booking=1 then sum(total_sum) else 0 end) + (case when is_booking=0 then sum(total_sum) else 0 end)) full_totals from shop_orders Join shop_carts on shop_carts.id = shop_orders.cart_id Join feu_userdetails on feu_userdetails.user_id = shop_carts.user_id Join sys_files on sys_files.id = feu_userdetails.avatar_file_id where YEAR(FROM_UNIXTIME(shop_orders.created)) = ".date('Y')." and payed = 1 and cancelled = 0 group by shop_orders.order_id ) a group by a.username ORDER BY sum(full_totals) DESC limit 50");



		$content_data['resultBest'] = $qry->result_array();



		/*if($content_data['resultBest']){



			foreach ($content_data['resultBest'] as $key => $value) {



				$qry_order_total = $this->db->query("SELECT sum(total_sum) as order_total FROM `shop_orders` WHERE payed = 1 and YEAR(FROM_UNIXTIME(shop_orders.created)) = '".date('Y')."' and invoiceAddress = '".$value['invoiceAddress']."' and is_booking = 0 group BY invoiceAddress");



				$order_total = $qry_order_total->row_array();







				$qry_booking_total = $this->db->query("SELECT sum(total_sum) as booking_total FROM `shop_orders` WHERE payed = 1 and YEAR(FROM_UNIXTIME(shop_orders.created)) = '".date('Y')."' and invoiceAddress = '".$value['invoiceAddress']."' and is_booking = 1 group BY invoiceAddress");



				$booking_total = $qry_booking_total->row_array();







				$content_data['resultBest'][$key]['order_total'] = $order_total['order_total'];



				$content_data['resultBest'][$key]['booking_total'] = $value['booking_total'];



				//$content_data['resultBest'][$key]['booking_total'] = $booking_total['booking_total'];



			}



		}*/











		/*******************************Premium member registration graph month wise*******************************************/



		//if($this->session->userdata('admin_id')==25267){



			$pre_month_qry = [];



			for($n=1;$n<13;$n++)



			{



				$cuurent_year = date('Y');



				$old_year = $cuurent_year-1;



				if($n==1)



				{



					$pre_month_qry[$n]['month'] = 'Jan';



				}



				elseif($n==2)



				{



					$pre_month_qry[$n]['month'] = 'Feb';



				}



				elseif($n==3)



				{



					$pre_month_qry[$n]['month'] = 'Mar';



				}



				elseif($n==4)



				{



					$pre_month_qry[$n]['month'] = 'Apr';



				}



				elseif($n==5)



				{



					$pre_month_qry[$n]['month'] = 'May';



				}



				elseif($n==6)



				{



					$pre_month_qry[$n]['month'] = 'Jun';



				}



				elseif($n==7)



				{



					$pre_month_qry[$n]['month'] = 'Jul';



				}



				elseif($n==8)



				{



					$pre_month_qry[$n]['month'] = 'Aug';



				}



				elseif($n==9)



				{



					$pre_month_qry[$n]['month'] = 'Sep';



				}



				elseif($n==10)



				{



					$pre_month_qry[$n]['month'] = 'Oct';



				}



				elseif($n==11)



				{



					$pre_month_qry[$n]['month'] = 'Nov';



				}



				else



				{



					$pre_month_qry[$n]['month'] = 'Dec';



				} 



				



				$pre_month_qries_this_year = $this->db->query("SELECT count(*) as count,(case when payment_date is NULL then MONTH(FROM_UNIXTIME(shop_orders.created)) when payment_date is not NULL then MONTH(payment_date) end) as month FROM `shop_orders` LEFT JOIN `shop_carts` ON `shop_carts`.`id` = `shop_orders`.`cart_id` LEFT JOIN `shop_articles_carts` ON `shop_articles_carts`.`cart_id` = `shop_carts`.`id` LEFT JOIN `shop_articles` ON `shop_articles`.`id` = `shop_articles_carts`.`article_id` WHERE `shop_articles_carts`.`article_id` in (4) and `payed` = 1 and `is_booking` =0 and `refund_trn_id` = '' and (case when payment_date is NULL then YEAR(FROM_UNIXTIME(shop_orders.created)) = ".$cuurent_year." when payment_date is not NULL then YEAR(payment_date) = ".$cuurent_year." end) and (case when payment_date is NULL then MONTH(FROM_UNIXTIME(shop_orders.created)) = ".$n." when payment_date is not NULL then MONTH(payment_date) = ".$n." end) group by month ORDER BY month ASC");



				$pre_month_qry_data_this_year = $pre_month_qries_this_year->row_array();



				$pre_month_qry[$n]['data_this_year'] = $pre_month_qry_data_this_year['count'];







				$pre_month_qries_prev_year = $this->db->query("SELECT count(*) as count,(case when payment_date is NULL then MONTH(FROM_UNIXTIME(shop_orders.created)) when payment_date is not NULL then MONTH(payment_date) end) as month FROM `shop_orders` LEFT JOIN `shop_carts` ON `shop_carts`.`id` = `shop_orders`.`cart_id` LEFT JOIN `shop_articles_carts` ON `shop_articles_carts`.`cart_id` = `shop_carts`.`id` LEFT JOIN `shop_articles` ON `shop_articles`.`id` = `shop_articles_carts`.`article_id` WHERE `shop_articles_carts`.`article_id` in (4) and `payed` = 1 and `is_booking` =0 and `refund_trn_id` = '' and (case when payment_date is NULL then YEAR(FROM_UNIXTIME(shop_orders.created)) = ".$old_year." when payment_date is not NULL then YEAR(payment_date) = ".$old_year." end) and (case when payment_date is NULL then MONTH(FROM_UNIXTIME(shop_orders.created)) = ".$n." when payment_date is not NULL then MONTH(payment_date) = ".$n." end) group by month ORDER BY month ASC");



				$pre_month_qry_data_prev_year = $pre_month_qries_prev_year->row_array();



				$pre_month_qry[$n]['data_prev_year'] = $pre_month_qry_data_prev_year['count'];



			}



			//pr($pre_month_qry);



		//}



		$content_data['pre_month_qry'] = $pre_month_qry;



		/*******************************Premium member registration graph month wise*******************************************/























		/*******************************Premium member registration graph week wise*******************************************/



		//if($this->session->userdata('admin_id')==25267){



			$pre_week_qry = [];



			for($n=1;$n<53;$n++)



			{



				$cuurent_year = date('Y');



				$old_year = $cuurent_year-1;



				$pre_week_qry[$n]['week'] = $n;



				



				$pre_month_qries_this_year = $this->db->query("SELECT count(*) as count,(case when payment_date is NULL then WEEK(FROM_UNIXTIME(shop_orders.created)) when payment_date is not NULL then WEEK(payment_date) end) as week FROM `shop_orders` LEFT JOIN `shop_carts` ON `shop_carts`.`id` = `shop_orders`.`cart_id` LEFT JOIN `shop_articles_carts` ON `shop_articles_carts`.`cart_id` = `shop_carts`.`id` LEFT JOIN `shop_articles` ON `shop_articles`.`id` = `shop_articles_carts`.`article_id` WHERE `shop_articles_carts`.`article_id` in (4) and `payed` = 1 and `is_booking` =0 and `refund_trn_id` = '' and (case when payment_date is NULL then YEAR(FROM_UNIXTIME(shop_orders.created)) = ".$cuurent_year." when payment_date is not NULL then YEAR(payment_date) = ".$cuurent_year." end) and (case when payment_date is NULL then WEEK(FROM_UNIXTIME(shop_orders.created)) = ".$n." when payment_date is not NULL then WEEK(payment_date) = ".$n." end) group by week ORDER BY week ASC");



				$pre_week_qry_data_this_year = $pre_month_qries_this_year->row_array();



				$pre_week_qry[$n]['data_this_year'] = $pre_week_qry_data_this_year['count'];







				$pre_month_qries_prev_year = $this->db->query("SELECT count(*) as count,(case when payment_date is NULL then WEEK(FROM_UNIXTIME(shop_orders.created)) when payment_date is not NULL then WEEK(payment_date) end) as week FROM `shop_orders` LEFT JOIN `shop_carts` ON `shop_carts`.`id` = `shop_orders`.`cart_id` LEFT JOIN `shop_articles_carts` ON `shop_articles_carts`.`cart_id` = `shop_carts`.`id` LEFT JOIN `shop_articles` ON `shop_articles`.`id` = `shop_articles_carts`.`article_id` WHERE `shop_articles_carts`.`article_id` in (4) and `payed` = 1 and `is_booking` =0 and `refund_trn_id` = '' and (case when payment_date is NULL then YEAR(FROM_UNIXTIME(shop_orders.created)) = ".$old_year." when payment_date is not NULL then YEAR(payment_date) = ".$old_year." end) and (case when payment_date is NULL then WEEK(FROM_UNIXTIME(shop_orders.created)) = ".$n." when payment_date is not NULL then WEEK(payment_date) = ".$n." end) group by week ORDER BY week ASC");



				$pre_week_qry_data_prev_year = $pre_month_qries_prev_year->row_array();



				$pre_week_qry[$n]['data_prev_year'] = $pre_week_qry_data_prev_year['count'];



			}



			//pr($pre_week_qry);



		//}



		$content_data['pre_week_qry'] = $pre_week_qry;



		/*******************************Premium member registration graph week wise*******************************************/



		//pr($content_data['resultBest']);



		$data['content'] = $this->load->view('admin/dashboard', $content_data, TRUE);



		$this->load->view('admin/layout', $data);



	}



	public function accept($enc_userID='')



	{



		if($enc_userID!='')



		{



			$ugalId=base64_decode($enc_userID);



			$imageDetails = $this->common_model->getAllRow('sys_files',array('id'=>$ugalId));



			if(!empty($imageDetails))



			{



				$this->common_model->UpdateData('sys_files',array('accepted'=>1),array('id'=>$ugalId));



				$this->common_model->Updatedata('sys_files',array('filename'=>$imageDetails['temp_name'],'temp_name'=>'','created'=>time()-8*60*60),array('id'=>$ugalId));



			}



			//echo $this->db->last_query(); die;



			$userdata = $this->common_model->getAllRowMultipleJoin('sys_files',array('sys_files.id'=>$ugalId),array(array('feu_userdetails','feu_userdetails.user_id = sys_files.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));



			if(!empty($userdata))



			{



				/**********************MAIL**************************/



					//$to = 'sayan@digitalaptech.com';



					$to = $userdata['email'];



					$sub = getAdminLang('Notification:_Image_has_been_accepted',$userdata['userlanguage']);



					//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];



					//$body= '<p>Dear '.$userdata['username'].',</p>';



					$body= '<p>'.getAdminLang('We_are_happy_to_let_you',$userdata['userlanguage']).'</p>';



					$body.= '<p>'.getAdminLang('Castleevents_is_known_as_probably_the_most_exclusive',$userdata['userlanguage']).'</p>';



					$body.= '<p>'.getAdminLang('we_are_now_create_a_virtual_world',$userdata['userlanguage']).'</p>';



					$body.= '<p>'.getAdminLang('On_our_website_you_will_find',$userdata['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">'.$userdata['username'].'</span> </h2>



	                                </td>



	                             </tr>



	                             <tr>



	                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">



	                                   '.$body.'



	                                </td>



	                             </tr>



	                             <tr>



	                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">



	                             		'.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>';







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



				/**********************MAIL**************************/



			}



			$this->utility->setMsg('Image accepted','SUCCESS');	



			redirect(base_url().'admin/dashboard');



		}



		else



		{



			$this->utility->setMsg('Invalid id','ERROR');	



			redirect(base_url().'admin/dashboard');



		}



	}



	public function approve_all_user()



	{



		$ugalIds=explode(',',$this->input->post('ids'));



		if(count($ugalIds)>0)



		{



			foreach ($ugalIds as $key => $ugalId) {



				$imageDetails = $this->common_model->getAllRow('sys_files',array('id'=>$ugalId));



				if(!empty($imageDetails))



				{



					$this->common_model->UpdateData('sys_files',array('accepted'=>1),array('id'=>$ugalId));



					$this->common_model->Updatedata('sys_files',array('filename'=>$imageDetails['temp_name'],'temp_name'=>'','created'=>time()-8*60*60),array('id'=>$ugalId));



				}



				//echo $this->db->last_query(); die;



				$userdata = $this->common_model->getAllRowMultipleJoin('sys_files',array('sys_files.id'=>$ugalId),array(array('feu_userdetails','feu_userdetails.user_id = sys_files.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));



				if(!empty($userdata))



				{



					/**********************MAIL**************************/



						//$to = 'sayan@digitalaptech.com';



						$to = $userdata['email'];



						$sub = getAdminLang('Notification:_Image_has_been_accepted',$userdata['userlanguage']);



						//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];



						//$body= '<p>Dear '.$userdata['username'].',</p>';



						$body= '<p>'.getAdminLang('We_are_happy_to_let_you',$userdata['userlanguage']).'</p>';



						$body.= '<p>'.getAdminLang('Castleevents_is_known_as_probably_the_most_exclusive',$userdata['userlanguage']).'</p>';



						$body.= '<p>'.getAdminLang('we_are_now_create_a_virtual_world',$userdata['userlanguage']).'</p>';



						$body.= '<p>'.getAdminLang('On_our_website_you_will_find',$userdata['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">'.$userdata['username'].'</span> </h2>



		                                </td>



		                             </tr>



		                             <tr>



		                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">



		                                   '.$body.'



		                                </td>



		                             </tr>



		                             <tr>



		                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">



		                             		'.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>';







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



					/**********************MAIL**************************/



				}



			}



		}



		//$this->utility->setMsg('Image accepted','SUCCESS');	



		redirect(base_url().'admin/dashboard');



	



	}



	public function reject_all_user()



	{



		$ugalIds=explode(',',$this->input->post('ids'));



		if(count($ugalIds)>0)



		{



			foreach ($ugalIds as $key => $ugalId) {



				$fileFromuserDetails = $this->common_model->getAllRowMultipleJoin('sys_files',array('sys_files.id'=>$ugalId),array(array('feu_userdetails','feu_userdetails.avatar_file_id = sys_files.id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));



			



				if(!empty($fileFromuserDetails['email']))



				{



					$userdata = $fileFromuserDetails;



				}



				else



				{



					$filesFromUserData = $this->common_model->getAllRowMultipleJoin('sys_files',array('sys_files.id'=>$ugalId),array(array('ugal_images','ugal_images.file_id = sys_files.id'),array('feu_userdetails','feu_userdetails.user_id = ugal_images.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));



					



					if(!empty($filesFromUserData))



					{



						$userdata = $filesFromUserData;



					}



					else



					{



						$userdata = array();



					}



				}



				//echo $this->db->last_query(); die;



				//print_r($userdata); die;



				if(!empty($userdata))



				{



					/**********************MAIL**************************/



						//$to = 'sayan@digitalaptech.com';



						$to = $userdata['email'];



						$sub = getAdminLang('Notification:_Image_has_been_removed',$userdata['userlanguage']);



						//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];



						//$body= '<p>Dear '.$userdata['username'].',</p>';



						$body= '<p>'.getAdminLang('Unfortunately_one_of_your_images_has_been_removed',$userdata['userlanguage']).'</p>';



						$body.= '<p>'.getAdminLang('Castleevents_is_known_as_probably_the_most_exclusive',$userdata['userlanguage']).'</p>';



						$body.= '<p>'.getAdminLang('With_the_same_claim__we_are_now',$userdata['userlanguage']).'</p>';



						$body.= '<ul>';



						$body.= '<li>'.getAdminLang('Facial_images_are_only_allowed',$userdata['userlanguage']).'</li>';



						$body.= '<li>'.getAdminLang('The_pictures_must_be_in_good_quality',$userdata['userlanguage']).'</li>';



						$body.= '<li>'.getAdminLang('Pornographic_pictures_should_be',$userdata['userlanguage']).'</li>';



						$body.= '</ul>';



						$body.= '<p>'.getAdminLang('On_our_website_you_will_find',$userdata['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">'.$userdata['username'].'</span> </h2>



		                                </td>



		                             </tr>



		                             <tr>



		                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">



		                                   '.$body.'



		                                </td>



		                             </tr>



		                             <tr>



		                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">



		                             		'.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>';







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



					/**********************MAIL**************************/



				}



				if($userdata['filename']=='')



				{



					$this->common_model->UpdateData('sys_files',array('temp_name'=>''),array('id'=>$ugalId));



				}



				else



				{



					$this->common_model->deleteData('ugal_images',array('file_id'=>$ugalId));



					$this->common_model->deleteData('sys_files',array('id'=>$ugalId));



					$this->common_model->deleteData('notification',array('file_id'=>$ugalId));



				}



			}



		}



		//$this->utility->setMsg('Image accepted','SUCCESS');	



		redirect(base_url().'admin/dashboard');



	



	}



	public function reject($enc_userID='')



	{



		if($enc_userID!='')



		{



			$ugalId=base64_decode($enc_userID);



			$fileFromuserDetails = $this->common_model->getAllRowMultipleJoin('sys_files',array('sys_files.id'=>$ugalId),array(array('feu_userdetails','feu_userdetails.avatar_file_id = sys_files.id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));



			



			if(!empty($fileFromuserDetails['email']))



			{



				$userdata = $fileFromuserDetails;



			}



			else



			{



				$filesFromUserData = $this->common_model->getAllRowMultipleJoin('sys_files',array('sys_files.id'=>$ugalId),array(array('ugal_images','ugal_images.file_id = sys_files.id'),array('feu_userdetails','feu_userdetails.user_id = ugal_images.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));



				



				if(!empty($filesFromUserData))



				{



					$userdata = $filesFromUserData;



				}



				else



				{



					$userdata = array();



				}



			}



			//echo $this->db->last_query(); die;



			//print_r($userdata); die;



			if(!empty($userdata))



			{



				/**********************MAIL**************************/



					//$to = 'sayan@digitalaptech.com';



					$to = $userdata['email'];



					$sub = getAdminLang('Notification:_Image_has_been_removed',$userdata['userlanguage']);



					//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];



					//$body= '<p>Dear '.$userdata['username'].',</p>';



					$body= '<p>'.getAdminLang('Unfortunately_one_of_your_images_has_been_removed',$userdata['userlanguage']).'</p>';



					$body.= '<p>'.getAdminLang('Castleevents_is_known_as_probably_the_most_exclusive',$userdata['userlanguage']).'</p>';



					$body.= '<p>'.getAdminLang('With_the_same_claim__we_are_now',$userdata['userlanguage']).'</p>';



					$body.= '<ul>';



					$body.= '<li>'.getAdminLang('Facial_images_are_only_allowed',$userdata['userlanguage']).'</li>';



					$body.= '<li>'.getAdminLang('The_pictures_must_be_in_good_quality',$userdata['userlanguage']).'</li>';



					$body.= '<li>'.getAdminLang('Pornographic_pictures_should_be',$userdata['userlanguage']).'</li>';



					$body.= '</ul>';



					$body.= '<p>'.getAdminLang('On_our_website_you_will_find',$userdata['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">'.$userdata['username'].'</span> </h2>



	                                </td>



	                             </tr>



	                             <tr>



	                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">



	                                   '.$body.'



	                                </td>



	                             </tr>



	                             <tr>



	                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">



	                             		'.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>';







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



				/**********************MAIL**************************/



			}



			if($userdata['filename']=='')



			{



				$this->common_model->UpdateData('sys_files',array('temp_name'=>''),array('id'=>$ugalId));



			}



			else



			{



				$this->common_model->deleteData('ugal_images',array('file_id'=>$ugalId));



				$this->common_model->deleteData('sys_files',array('id'=>$ugalId));



				$this->common_model->deleteData('notification',array('file_id'=>$ugalId));



			}



			



			//$this->common_model->UpdateData('sys_files',array('accepted'=>2),array('id'=>$ugalId));



			$this->utility->setMsg('Image rejected','SUCCESS');	



			redirect(base_url().'admin/dashboard');



		}



		else



		{



			$this->utility->setMsg('Invalid id','ERROR');	



			redirect(base_url().'admin/dashboard');



		}



	}



	function allPicture($page='')



	{



		$content_data = array();



		if($page=='')



		{



			$page=0;



		}



		$limit = 20;



		$content_data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$this->session->userdata('admin_id'))) ;



		$content_data['userImage'] = $this->common_model->getAllRow('ugal_images',array('ugal_images.user_id'=>$this->session->userdata('admin_id'),'is_private !='=>1),array('sys_files','sys_files.id = ugal_images.file_id')) ;



		if($this->input->post('search_name'))



		{



			$upload = $this->common_model->getAllMultipleJoin('sys_files',array('sys_files.user_id >'=>1,'filename !='=>'','username'=>$this->input->post('search_name')),array(array('feu_userdetails','feu_userdetails.user_id = sys_files.user_id')),'sys_files.created DESC','','filename','','','',array('path'=>'img'));



			$content_data['upload'] = $this->common_model->getAllMultipleJoin('sys_files',array('sys_files.user_id >'=>1,'filename !='=>'','username'=>$this->input->post('search_name')),array(array('feu_userdetails','feu_userdetails.user_id = sys_files.user_id')),'sys_files.created DESC','','filename',$page,$limit,'',array('path'=>'img'));



		} else if($this->input->post('search_email')) {



			$upload = $this->common_model->getAllMultipleJoin('sys_files',array('sys_files.user_id >'=>1,'filename !='=>'','email'=>$this->input->post('search_email')),array(array('usr_users','usr_users.id = sys_files.user_id')),'sys_files.created DESC','sys_files.*','filename','','','',array('path'=>'img'));



			$content_data['upload'] = $this->common_model->getAllMultipleJoin('sys_files',array('sys_files.user_id >'=>1,'filename !='=>'','email'=>$this->input->post('search_email')),array(array('usr_users','usr_users.id = sys_files.user_id')),'sys_files.created DESC','sys_files.*','filename',$page,$limit,'',array('path'=>'img'));



		} else {



			$upload = $this->common_model->getAllMultipleJoin('sys_files',array('user_id >'=>1,'filename !='=>''),'','sys_files.created DESC','','filename','','','',array('path'=>'img'));



			$content_data['upload'] = $this->common_model->getAllMultipleJoin('sys_files',array('user_id >'=>1,'filename !='=>''),'','sys_files.created DESC','','filename',$page,$limit,'',array('path'=>'img'));



		}



		



		//print_r($content_data['upload']); 



		$this->load->library('pagination');



		$config['base_url'] = base_url().'admin/dashboard/allPicture/';



		$config['total_rows'] = count($upload);



		$config['per_page'] = $limit;



		$this->pagination->initialize($config);







		$content_data['link'] = $this->pagination->create_links();



		$data['content'] = $this->load->view('admin/allPicture', $content_data, TRUE);



		$this->load->view('admin/layout', $data);



	}



	public function delete($enc_userID='',$uri='')



	{



		if($enc_userID!='')



		{



			$ugalId=base64_decode($enc_userID);



			$fileFromuserDetails = $this->common_model->getAllRowMultipleJoin('sys_files',array('sys_files.id'=>$ugalId),array(array('feu_userdetails','feu_userdetails.avatar_file_id = sys_files.id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));



			if(!empty($fileFromuserDetails['user_id']))



			{



				$userdata = $fileFromuserDetails;



			}



			else



			{



				$filesFromUserData = $this->common_model->getAllRowMultipleJoin('sys_files',array('sys_files.id'=>$ugalId),array(array('ugal_images','ugal_images.file_id = sys_files.id'),array('feu_userdetails','feu_userdetails.user_id = ugal_images.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));



				if(!empty($filesFromUserData))



				{



					$userdata = $filesFromUserData;



				}



				else



				{



					$userdata = array();



				}



			}



			if(!empty($userdata))



			{



				/**********************MAIL**************************/



					//$to = 'sayan@digitalaptech.com';



					$to = $userdata['email'];



					$sub = getAdminLang('Notification:_Image_has_been_removed',$userdata['userlanguage']);



					//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];



					//$body= '<p>Dear '.$userdata['username'].',</p>';



					$body= '<p>'.getAdminLang('Unfortunately_one_of_your_images_has_been_removed',$userdata['userlanguage']).'</p>';



					$body.= '<p>'.getAdminLang('Castleevents_is_known_as_probably_the_most_exclusive',$userdata['userlanguage']).'</p>';



					$body.= '<p>'.getAdminLang('With_the_same_claim__we_are_now',$userdata['userlanguage']).'</p>';



					$body.= '<ul>';



					$body.= '<li>'.getAdminLang('Facial_images_are_only_allowed',$userdata['userlanguage']).'</li>';



					$body.= '<li>'.getAdminLang('The_pictures_must_be_in_good_quality',$userdata['userlanguage']).'</li>';



					$body.= '<li>'.getAdminLang('Pornographic_pictures_should_be',$userdata['userlanguage']).'</li>';



					$body.= '</ul>';



					$body.= '<p>'.getAdminLang('On_our_website_you_will_find',$userdata['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">'.$userdata['username'].'</span> </h2>



	                                </td>



	                             </tr>



	                             <tr>



	                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">



	                                   '.$body.'



	                                </td>



	                             </tr>



	                             <tr>



	                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">



	                             		'.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>';



	                



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



				/**********************MAIL**************************/



			}



			if($userdata['filename']=='')



			{



				$this->common_model->UpdateData('sys_files',array('temp_name'=>''),array('id'=>$ugalId));



			}



			else



			{



				$this->common_model->deleteData('ugal_images',array('file_id'=>$ugalId));



				$this->common_model->deleteData('sys_files',array('id'=>$ugalId));



				$this->common_model->deleteData('notification',array('file_id'=>$ugalId));



			}



			//$this->common_model->UpdateData('sys_files',array('accepted'=>2),array('id'=>$ugalId));



			$this->utility->setMsg('Image rejected','SUCCESS');	



			redirect(base_url().str_replace('-', '/', $uri));



			//redirect(base_url().'admin/dashboard/allPicture');



		}



		else



		{



			$this->utility->setMsg('Invalid id','ERROR');	



			redirect(base_url().str_replace('-', '/', $uri));



			//redirect(base_url().'admin/dashboard');



		}



	}



	public function delete_from_profile($enc_userID='',$uri='')



	{



		if($enc_userID!='')



		{



			$ugalId=base64_decode($enc_userID);



			$fileFromuserDetails = $this->common_model->getAllRowMultipleJoin('sys_files',array('sys_files.id'=>$ugalId),array(array('feu_userdetails','feu_userdetails.avatar_file_id = sys_files.id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));



			if(!empty($fileFromuserDetails['user_id']))



			{



				$userdata = $fileFromuserDetails;



			}



			else



			{



				$filesFromUserData = $this->common_model->getAllRowMultipleJoin('sys_files',array('sys_files.id'=>$ugalId),array(array('ugal_images','ugal_images.file_id = sys_files.id'),array('feu_userdetails','feu_userdetails.user_id = ugal_images.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));



				if(!empty($filesFromUserData))



				{



					$userdata = $filesFromUserData;



				}



				else



				{



					$userdata = array();



				}



			}



			if($userdata['filename']=='')



			{



				$this->common_model->UpdateData('sys_files',array('temp_name'=>''),array('id'=>$ugalId));



			}



			else



			{



				$this->common_model->deleteData('ugal_images',array('file_id'=>$ugalId));



				$this->common_model->deleteData('sys_files',array('id'=>$ugalId));



				$this->common_model->deleteData('notification',array('file_id'=>$ugalId));



			}



			//$this->common_model->UpdateData('sys_files',array('accepted'=>2),array('id'=>$ugalId));



			$this->utility->setMsg('Image rejected','SUCCESS');	



			redirect(base_url().str_replace('-', '/', $uri));



			//redirect(base_url().'admin/dashboard/allPicture');



		}



		else



		{



			$this->utility->setMsg('Invalid id','ERROR');	



			redirect(base_url().str_replace('-', '/', $uri));



			//redirect(base_url().'admin/dashboard');



		}



	}



	public function delete_from_pictures($enc_userID='',$uri='')



	{



		if($enc_userID!='')



		{



			$ugalId=base64_decode($enc_userID);



			$fileFromuserDetails = $this->common_model->getAllRowMultipleJoin('sys_files',array('sys_files.id'=>$ugalId),array(array('feu_userdetails','feu_userdetails.avatar_file_id = sys_files.id'),array('usr_users','usr_users.id = feu_userdetails.user_id')),'','*,sys_files.id as fileID');



			if(!empty($fileFromuserDetails['user_id']))



			{



				$userdata = $fileFromuserDetails;



			}



			else



			{



				$filesFromUserData = $this->common_model->getAllRowMultipleJoin('sys_files',array('sys_files.id'=>$ugalId),array(array('ugal_images','ugal_images.file_id = sys_files.id'),array('feu_userdetails','feu_userdetails.user_id = ugal_images.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')),'','*,sys_files.id as fileID');



				if(!empty($filesFromUserData))



				{



					$userdata = $filesFromUserData;



				}



				else



				{



					$userdata = array();



				}



			}



			if(!empty($userdata))



			{



				$check = $this->common_model->getAllRow('delete_pic_sameuser',array('user_id'=>$userdata['user_id']),'','delete_time DESC');



				if($check)



				{



					if(($check['delete_time']+(5*60))<time())



					{



							//$to = 'sayan@digitalaptech.com';



							$to = $userdata['email'];



							$sub = getAdminLang('Notification:_Image_has_been_removed',$userdata['userlanguage']);



							//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];



							//$body= '<p>Dear '.$userdata['username'].',</p>';



							$body= '<p>'.getAdminLang('Unfortunately_one_of_your_images_has_been_removed',$userdata['userlanguage']).'</p>';



							$body.= '<p>'.getAdminLang('Castleevents_is_known_as_probably_the_most_exclusive',$userdata['userlanguage']).'</p>';



							$body.= '<p>'.getAdminLang('With_the_same_claim__we_are_now',$userdata['userlanguage']).'</p>';



							$body.= '<ul>';



							$body.= '<li>'.getAdminLang('Facial_images_are_only_allowed',$userdata['userlanguage']).'</li>';



							$body.= '<li>'.getAdminLang('The_pictures_must_be_in_good_quality',$userdata['userlanguage']).'</li>';



							$body.= '<li>'.getAdminLang('Pornographic_pictures_should_be',$userdata['userlanguage']).'</li>';



							$body.= '</ul>';



							$body.= '<p>'.getAdminLang('On_our_website_you_will_find',$userdata['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">'.$userdata['username'].'</span> </h2>



			                                </td>



			                             </tr>



			                             <tr>



			                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">



			                                   '.$body.'



			                                </td>



			                             </tr>



			                             <tr>



			                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">



			                             		'.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>';



			                



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



					}



				}



				else



				{



					//$to = 'sayan@digitalaptech.com';



						$to = $userdata['email'];



						$sub = getAdminLang('Notification:_Image_has_been_removed',$userdata['userlanguage']);



						//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];



						//$body= '<p>Dear '.$userdata['username'].',</p>';



						$body= '<p>'.getAdminLang('Unfortunately_one_of_your_images_has_been_removed',$userdata['userlanguage']).'</p>';



						$body.= '<p>'.getAdminLang('Castleevents_is_known_as_probably_the_most_exclusive',$userdata['userlanguage']).'</p>';



						$body.= '<p>'.getAdminLang('With_the_same_claim__we_are_now',$userdata['userlanguage']).'</p>';



						$body.= '<ul>';



						$body.= '<li>'.getAdminLang('Facial_images_are_only_allowed',$userdata['userlanguage']).'</li>';



						$body.= '<li>'.getAdminLang('The_pictures_must_be_in_good_quality',$userdata['userlanguage']).'</li>';



						$body.= '<li>'.getAdminLang('Pornographic_pictures_should_be',$userdata['userlanguage']).'</li>';



						$body.= '</ul>';



						$body.= '<p>'.getAdminLang('On_our_website_you_will_find',$userdata['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">'.$userdata['username'].'</span> </h2>



			                                </td>



			                             </tr>



			                             <tr>



			                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">



			                                   '.$body.'



			                                </td>



			                             </tr>



			                             <tr>



			                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">



			                             		'.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  $bodys;die;   



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



				}



				$this->common_model->insertData('delete_pic_sameuser',array('file_id'=>$userdata['fileID'],'user_id'=>$userdata['user_id'],'delete_time'=>time()));



				



			}



			if($userdata['filename']=='')



			{



				$this->common_model->UpdateData('sys_files',array('temp_name'=>''),array('id'=>$ugalId));



			}



			else



			{



				$this->common_model->deleteData('ugal_images',array('file_id'=>$ugalId));



				$this->common_model->deleteData('sys_files',array('id'=>$ugalId));



				$this->common_model->deleteData('notification',array('file_id'=>$ugalId));



			}



			//$this->common_model->UpdateData('sys_files',array('accepted'=>2),array('id'=>$ugalId));



			$this->utility->setMsg('Image rejected','SUCCESS');	



			redirect(base_url().str_replace('-', '/', $uri));



			//redirect(base_url().'admin/dashboard/allPicture');



		}



		else



		{



			$this->utility->setMsg('Invalid id','ERROR');	



			redirect(base_url().str_replace('-', '/', $uri));



			//redirect(base_url().'admin/dashboard');



		}



	}



	public function rotate($encfileId = '',$uri='')



	{



		if($encfileId=='')



		{



			redirect(base_url().'admin/dashboard/allPicture');



		}



		else



		{



			$fileId = base64_decode($encfileId);



			$getFile = $this->common_model->getAllRow('sys_files',array('id'=>$fileId));



			if(empty($getFile))



			{



				redirect(base_url().'admin/dashboard/allPicture');



			} 



			else



			{



				/*$source_path = FCPATH . 'assets/userfiles/' .$getFile['path'] . '/' . $getFile['filename'] .'.'. $getFile['extension'];



				$dest_name = rand(0,100000);



				$dest_path = FCPATH . 'assets/userfiles/' .$getFile['path'] . '/' . $dest_name.'.'. $getFile['extension'];



				$degrees = 90;



				$this->load->library('image_lib');



				$this->image_lib->clear();



                $config=array();



			    $config['image_library'] = 'gd2';



			    $config['source_image']  = $source_path;



			    $config['new_image']  =  $dest_path;



				$config['rotation_angle'] = $degrees;



			    $this->image_lib->initialize($config);      



			    $this->image_lib->rotate();*/



			    if($getFile['filename']!='')



			    {



			    	$source_path = FCPATH . 'assets/userfiles/' .$getFile['path'] . '/' . $getFile['filename'] .'.'. $getFile['extension'];



					$degrees = 90;



					$this->load->library('image_lib');



					$this->image_lib->clear();



	                $config=array();



				    $config['image_library'] = 'gd2';



				    $config['source_image']  = $source_path;



				    $config['new_image']  =  $source_path;



					$config['rotation_angle'] = $degrees;



				    $this->image_lib->initialize($config);      



				    $this->image_lib->rotate();



				    







				    if($getFile['path']=='usergalleries/' || $getFile['path']=='usergalleries'){



					    /***************Blur rotation*****************/



					    $source_path = FCPATH . 'assets/userfiles/' .$getFile['path'] . '/' . $getFile['filename'] .'_blur.'. $getFile['extension'];



						$degrees = 90;



						$this->load->library('image_lib');



						$this->image_lib->clear();



		                $config=array();



					    $config['image_library'] = 'gd2';



					    $config['source_image']  = $source_path;



					    $config['new_image']  =  $source_path;



						$config['rotation_angle'] = $degrees;



					    $this->image_lib->initialize($config);      



					    $this->image_lib->rotate();



					    /***************Blur rotation*****************/



					}







					if($getFile['path']=='avatars/' || $getFile['path']=='avatars'){



						$resize = $this->avater($getFile['filename'] .'.'. $getFile['extension']);



						//$resizeBlur = $this->avater($getFile['filename'] .'_blur.'. $getFile['extension']);



					}







					$this->common_model->UpdateData('sys_files',array('filename'=>$getFile['filename']),array('id'=>$fileId));



			    }



			    elseif($getFile['temp_name']!='')



			    {



			    	$source_path = FCPATH . 'assets/userfiles/' .$getFile['path'] . '/' . $getFile['temp_name'] .'.'. $getFile['extension'];



					$degrees = 90;



					$this->load->library('image_lib');



					$this->image_lib->clear();



	                $config=array();



				    $config['image_library'] = 'gd2';



				    $config['source_image']  = $source_path;



				    $config['new_image']  =  $source_path;



					$config['rotation_angle'] = $degrees;



				    $this->image_lib->initialize($config);      



				    $this->image_lib->rotate();







				    if($getFile['path']=='usergalleries/' || $getFile['path']=='usergalleries'){



					    /***************Blur rotation*****************/



					    $source_path = FCPATH . 'assets/userfiles/' .$getFile['path'] . '/' . $getFile['temp_name'] .'_blur.'. $getFile['extension'];



						$degrees = 90;



						$this->load->library('image_lib');



						$this->image_lib->clear();



		                $config=array();



					    $config['image_library'] = 'gd2';



					    $config['source_image']  = $source_path;



					    $config['new_image']  =  $source_path;



						$config['rotation_angle'] = $degrees;



					    $this->image_lib->initialize($config);      



					    $this->image_lib->rotate();



					    /***************Blur rotation*****************/



					}







					if($getFile['path']=='avatars/' || $getFile['path']=='avatars'){



						$resize = $this->avater($getFile['temp_name'] .'.'. $getFile['extension']);



						//$resizeBlur = $this->avater($getFile['temp_name'] .'_blur.'. $getFile['extension']);



					}











					$this->common_model->UpdateData('sys_files',array('temp_name'=>$getFile['temp_name']),array('id'=>$fileId));



			    }







			    



			    //$this->common_model->UpdateData('sys_files',array('filename'=>$dest_name),array('id'=>$fileId));



			    //@unlink($source_path);



				//redirect(base_url().'admin/dashboard/allPicture');



				redirect(base_url().str_replace('-', '/', $uri));



				//redirect(base_url().str_replace('-', '/', $uri),'refresh');



			}



		}



	}



	function deleteComment($msgId='')



	{



		$getMsg = $this->common_model->getAllRow('msg_conversations',array('id'=>$msgId));



		if(empty($getMsg))



		{



			redirect(base_url().'admin/dashboard');



		} 



		else



		{



			$this->common_model->deleteData('msg_conversations_users',array('conversation_id'=>$getMsg['id']));



			$this->common_model->deleteData('msg_messages',array('conversation_id'=>$getMsg['id']));



			$this->common_model->deleteData('msg_conversations',array('id'=>$msgId));



			redirect(base_url().'admin/dashboard');



		}



	}



	







	/***************************************/



	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('80','160','320');



	   $picdir[]=$this->dirToArray('assets');



		$avatar=$picdir[0]['userfiles']['avatars'];



				foreach($sizes as $size){



				



				$toWidth=$toHeight=$size;



				//destination path



				$folderpath = 'assets/userfiles/avatars/'.$toWidth;







				$org_path = 'assets/userfiles/avatars'; //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';



	}



	function freeuser()



	{



		$content_data = array();



		if($page=='')



		{



			$page=0;



		}



		$limit = 20;



		if($this->input->post())



		{



			//pr($this->input->post());



			if($this->input->post('Approve'))



			{



				foreach ($this->input->post('selected') as $key => $value) {



					$ugalId=$value;



					$imageDetails = $this->common_model->getAllRow('ugal_images',array('id'=>$ugalId));



					$this->common_model->UpdateData('sys_files',array('accepted'=>1),array('id'=>$imageDetails['file_id']));



				}



				$this->utility->setMsg('Images accepted','SUCCESS');	



			}



			if($this->input->post('Reject'))



			{



				foreach ($this->input->post('selected') as $key => $value) {



					$ugalId=$value;



					$imageDetails = $this->common_model->getAllRow('ugal_images',array('id'=>$ugalId));



					$this->common_model->deleteData('sys_files',array('id'=>$imageDetails['file_id']));



					$this->common_model->deleteData('ugal_images',array('id'=>$ugalId));



					@unlink(FCPATH.'assets/userfiles/'.$imageDetails['path'].'/'.$imageDetails['filename'].'.'.$imageDetails['extension']);



				}



				$this->utility->setMsg('Images rejected','SUCCESS');	



			}



		}



		$content_data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$this->session->userdata('admin_id'))) ;



		$content_data['userImage'] = $this->common_model->getAllMultipleJoin('ugal_images',array('free_membership_image'=>1,'sys_files.accepted'=>0),array(array('sys_files','sys_files.id = ugal_images.file_id'),array('feu_userdetails','feu_userdetails.user_id = ugal_images.user_id')),'sys_files.accepted ASC','*,ugal_images.id as id,sys_files.created') ;



		//pr($content_data['userImage']);



		$data['content'] = $this->load->view('admin/freeuser', $content_data, TRUE);



		$this->load->view('admin/layout', $data);



	}



	function confirmed_images()



	{



		$content_data = array();



		if($page=='')



		{



			$page=0;



		}



		$limit = 20;



		$content_data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('user_id'=>$this->session->userdata('admin_id'))) ;



		$content_data['userImage'] = $this->common_model->getAllMultipleJoin('ugal_images',array('free_membership_image'=>1,'sys_files.accepted'=>1),array(array('sys_files','sys_files.id = ugal_images.file_id'),array('feu_userdetails','feu_userdetails.user_id = ugal_images.user_id')),'sys_files.created DESC','*,ugal_images.id as id,sys_files.created') ;



		//pr($content_data['userImage']);



		$data['content'] = $this->load->view('admin/confirmed_images', $content_data, TRUE);



		$this->load->view('admin/layout', $data);



	}



	public function free_picture_approve($enc_userID='',$uri)



	{



		if($enc_userID!='')



		{



			$ugalId=base64_decode($enc_userID);



			$imageDetails = $this->common_model->getAllRow('ugal_images',array('id'=>$ugalId));



			$this->common_model->UpdateData('sys_files',array('accepted'=>1),array('id'=>$imageDetails['file_id']));



			$userdata = $this->common_model->getAllRowMultipleJoin('ugal_images',array('ugal_images.id'=>$ugalId),array(array('feu_userdetails','feu_userdetails.user_id = ugal_images.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));



			



			if(!empty($userdata))



			{



				$this->common_model->insertData('notification',array('from_id'=>$userdata['user_id'],'to_id'=>1,'type'=>12,'created'=>time(),'file_id'=>$imageDetails['file_id']));



				/**********************MAIL**************************/



					//$to = 'sayan@digitalaptech.com';



					$to = $userdata['email'];



					$sub = getAdminLang('Notification:_Image_has_been_accepted',$userdata['userlanguage']);



					//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];



					//$body= '<p>Dear '.$userdata['username'].',</p>';



					$body= '<p>'.getAdminLang('We_are_happy_to_let_you',$userdata['userlanguage']).'</p>';



					$body.= '<p>'.getAdminLang('Castleevents_is_known_as_probably_the_most_exclusive',$userdata['userlanguage']).'</p>';



					$body.= '<p>'.getAdminLang('we_are_now_create_a_virtual_world',$userdata['userlanguage']).'</p>';



					$body.= '<p>'.getAdminLang('On_our_website_you_will_find',$userdata['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">'.$userdata['username'].'</span> </h2>



	                                </td>



	                             </tr>



	                             <tr>



	                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">



	                                   '.$body.'



	                                </td>



	                             </tr>



	                             <tr>



	                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">



	                             		'.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>';







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



				/**********************MAIL**************************/



			}



			$this->utility->setMsg('Image accepted','SUCCESS');	



			redirect(base_url().str_replace('-', '/', $uri));



		}



		else



		{



			$this->utility->setMsg('Invalid id','ERROR');	



			redirect(base_url().str_replace('-', '/', $uri));



		}



	}



	public function free_picture_reject($enc_userID='',$uri)



	{



		if($enc_userID!='')



		{



			$ugalId=base64_decode($enc_userID);



			$imageDetails = $this->common_model->getAllRow('ugal_images',array('id'=>$ugalId));



			$userdata = $this->common_model->getAllRowMultipleJoin('ugal_images',array('ugal_images.id'=>$ugalId),array(array('feu_userdetails','feu_userdetails.user_id = ugal_images.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));



			$this->common_model->deleteData('sys_files',array('id'=>$imageDetails['file_id']));



			$this->common_model->deleteData('ugal_images',array('id'=>$ugalId));



			@unlink(FCPATH.'assets/userfiles/'.$imageDetails['path'].'/'.$imageDetails['filename'].'.'.$imageDetails['extension']);



			if(!empty($userdata))



			{



				/**********************MAIL**************************/



					//$to = 'sayan@digitalaptech.com';



					$to = $userdata['email'];



					$sub = getAdminLang('Notification:_Image_has_been_removed',$userdata['userlanguage']);



					//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];



					//$body= '<p>Dear '.$userdata['username'].',</p>';



					$body= '<p>'.getAdminLang('Unfortunately_one_of_your_images_has_been_removed',$userdata['userlanguage']).'</p>';



					$body.= '<p>'.getAdminLang('Castleevents_is_known_as_probably_the_most_exclusive',$userdata['userlanguage']).'</p>';



					$body.= '<p>'.getAdminLang('With_the_same_claim__we_are_now',$userdata['userlanguage']).'</p>';



					$body.= '<ul>';



					$body.= '<li>'.getAdminLang('Facial_images_are_only_allowed',$userdata['userlanguage']).'</li>';



					$body.= '<li>'.getAdminLang('The_pictures_must_be_in_good_quality',$userdata['userlanguage']).'</li>';



					$body.= '<li>'.getAdminLang('Pornographic_pictures_should_be',$userdata['userlanguage']).'</li>';



					$body.= '</ul>';



					$body.= '<p>'.getAdminLang('On_our_website_you_will_find',$userdata['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">'.$userdata['username'].'</span> </h2>



	                                </td>



	                             </tr>



	                             <tr>



	                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">



	                                   '.$body.'



	                                </td>



	                             </tr>



	                             <tr>



	                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">



	                             		'.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>';







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



				/**********************MAIL**************************/



			}



			$this->utility->setMsg('Image rejected','SUCCESS');	



			redirect(base_url().str_replace('-', '/', $uri));



		}



		else



		{



			$this->utility->setMsg('Invalid id','ERROR');	



			redirect(base_url().str_replace('-', '/', $uri));



		}



	}



	public function approve_all()



	{



		$ugalIds=explode(',',$this->input->post('ids'));



		if(count($ugalIds)>0)



		{



			foreach ($ugalIds as $key => $ugalId) {



				$imageDetails = $this->common_model->getAllRow('ugal_images',array('id'=>$ugalId));



				$this->common_model->UpdateData('sys_files',array('accepted'=>1),array('id'=>$imageDetails['file_id']));



				$userdata = $this->common_model->getAllRowMultipleJoin('ugal_images',array('ugal_images.id'=>$ugalId),array(array('feu_userdetails','feu_userdetails.user_id = ugal_images.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));



				



				if(!empty($userdata))



				{



					$this->common_model->insertData('notification',array('from_id'=>$userdata['user_id'],'to_id'=>1,'type'=>12,'created'=>time(),'file_id'=>$imageDetails['file_id']));



					/**********************MAIL**************************/



						//$to = 'sayan@digitalaptech.com';



						$to = $userdata['email'];



						$sub = getAdminLang('Notification:_Image_has_been_accepted',$userdata['userlanguage']);



						//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];



						//$body= '<p>Dear '.$userdata['username'].',</p>';



						$body= '<p>'.getAdminLang('We_are_happy_to_let_you',$userdata['userlanguage']).'</p>';



						$body.= '<p>'.getAdminLang('Castleevents_is_known_as_probably_the_most_exclusive',$userdata['userlanguage']).'</p>';



						$body.= '<p>'.getAdminLang('we_are_now_create_a_virtual_world',$userdata['userlanguage']).'</p>';



						$body.= '<p>'.getAdminLang('On_our_website_you_will_find',$userdata['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">'.$userdata['username'].'</span> </h2>



		                                </td>



		                             </tr>



		                             <tr>



		                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">



		                                   '.$body.'



		                                </td>



		                             </tr>



		                             <tr>



		                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">



		                             		'.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>';







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



					/**********************MAIL**************************/



				}



			}



		}



		$this->utility->setMsg('Image accepted','SUCCESS');	



		redirect(base_url().'admin/dashboard');



	



	}



	public function reject_all(){



		$ugalIds=explode(',',$this->input->post('ids'));



		if(count($ugalIds)>0){



			foreach ($ugalIds as $key => $ugalId) {



				$imageDetails = $this->common_model->getAllRow('ugal_images',array('id'=>$ugalId));



				$userdata = $this->common_model->getAllRowMultipleJoin('ugal_images',array('ugal_images.id'=>$ugalId),array(array('feu_userdetails','feu_userdetails.user_id = ugal_images.user_id'),array('usr_users','usr_users.id = feu_userdetails.user_id')));



				$this->common_model->deleteData('sys_files',array('id'=>$imageDetails['file_id']));



				$this->common_model->deleteData('ugal_images',array('id'=>$ugalId));



				@unlink(FCPATH.'assets/userfiles/'.$imageDetails['path'].'/'.$imageDetails['filename'].'.'.$imageDetails['extension']);



				if(!empty($userdata))



				{



					/**********************MAIL**************************/



						//$to = 'sayan@digitalaptech.com';



						$to = $userdata['email'];



						$sub = getAdminLang('Notification:_Image_has_been_removed',$userdata['userlanguage']);



						//$sub = 'Your booking: Order CE-'.$orderDetail['order_id'];



						//$body= '<p>Dear '.$userdata['username'].',</p>';



						$body= '<p>'.getAdminLang('Unfortunately_one_of_your_images_has_been_removed',$userdata['userlanguage']).'</p>';



						$body.= '<p>'.getAdminLang('Castleevents_is_known_as_probably_the_most_exclusive',$userdata['userlanguage']).'</p>';



						$body.= '<p>'.getAdminLang('With_the_same_claim__we_are_now',$userdata['userlanguage']).'</p>';



						$body.= '<ul>';



						$body.= '<li>'.getAdminLang('Facial_images_are_only_allowed',$userdata['userlanguage']).'</li>';



						$body.= '<li>'.getAdminLang('The_pictures_must_be_in_good_quality',$userdata['userlanguage']).'</li>';



						$body.= '<li>'.getAdminLang('Pornographic_pictures_should_be',$userdata['userlanguage']).'</li>';



						$body.= '</ul>';



						$body.= '<p>'.getAdminLang('On_our_website_you_will_find',$userdata['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">'.$userdata['username'].'</span> </h2>



		                                </td>



		                             </tr>



		                             <tr>



		                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">



		                                   '.$body.'



		                                </td>



		                             </tr>



		                             <tr>



		                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">



		                             		'.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>';







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



					/**********************MAIL**************************/



				}



			}



		}



		$this->utility->setMsg('Image rejected','SUCCESS');	



		redirect(base_url().'admin/dashboard');



	}



	public function chartFirst(){







		$eventArrayOne = $uniquesGenerated = array();



		



		$query1 = "SELECT `shop_orders`.`ip_address`,`shop_booking_details`.`cart_id`,`shop_booking_details`.`event_id`,`evt_events`.`time_from`,`evt_events`.`title`,`shop_carts`.`user_id` from `shop_orders`,`shop_booking_details`,`evt_events`,`shop_carts` WHERE `shop_orders`.`payed`=1 AND `shop_orders`.`cart_id`=`shop_booking_details`.`cart_id` AND `shop_booking_details`.`event_id`=`evt_events`.`id` AND `shop_orders`.`cart_id`=`shop_carts`.`id` AND `evt_events`.`time_from` < ".time();



		//echo $query1;



		$result1 = $this->db->query($query1);



		



		if($result1->num_rows()>0){



			foreach($result1->result() as $getKey1 => $getValue1){



				$getTime = date('Y',$getValue1->time_from);



				if(!array_key_exists($getTime, $eventArrayOne)){



					$eventArrayOne[$getTime] = array($getValue1->user_id);



				}else{



					$incrementValue = $eventArrayOne[$getTime];



					$eventArrayOne[$getTime][] = $getValue1->user_id;



				}



			}



		}







		$query2 = "SELECT `shop_orders`.`ip_address`,`shop_articles_carts`.`cart_id`,`shop_articles_carts`.`event_id`,`evt_events`.`time_from`,`evt_events`.`title`,`shop_carts`.`user_id` from `shop_orders`,`shop_articles_carts`,`evt_events`,`shop_carts` WHERE `shop_orders`.`payed`=1 AND `shop_orders`.`cart_id`=`shop_articles_carts`.`cart_id` AND `shop_articles_carts`.`event_id`=`evt_events`.`id` AND `shop_orders`.`cart_id`=`shop_carts`.`id` AND `evt_events`.`time_from` < ".time();



		$result2 = $this->db->query($query2);



		if($result2->num_rows()>0){



			foreach ($result2->result() as $getKey2 => $getValue2) {



				$getTime = date('Y',$getValue2->time_from);



				if(!array_key_exists($getTime,$eventArrayOne)){



					$eventArrayOne[$getTime] = array($getValue2->user_id);;



				}else{



					$incrementValue = $eventArrayOne[$getTime];



					$eventArrayOne[$getTime][] = $getValue2->user_id;



				}



			}



		}



		ksort($eventArrayOne);











		//echo '<pre>';print_r($eventArrayOne);die;



		foreach($eventArrayOne as $keyOne => $keyValue){



			$uniquesGenerated[$keyOne] = array_values(array_unique($eventArrayOne[$keyOne]));



		}



		//echo '<pre>';print_r($uniquesGenerated);







		$finalNewGeneratedArray = array();



		foreach($uniquesGenerated as $uniqueKey => $uniqueValue){



			$finalNewGeneratedArray[$uniqueKey]['firstCondition'] = 0;



			$finalNewGeneratedArray[$uniqueKey]['secondCondition'] = 0;



			$finalNewGeneratedArray[$uniqueKey]['thirdCondition'] = 0;



			$counter = array_count_values($eventArrayOne[$uniqueKey]);



			foreach($uniqueValue as $subCounterKey => $subCounterValue){



				$counterValue = $counter[$uniqueValue[$subCounterKey]];



				if($counterValue==1){



					$incrementOne = $finalNewGeneratedArray[$uniqueKey]['firstCondition'];



					$finalNewGeneratedArray[$uniqueKey]['firstCondition'] = $incrementOne+1;



				}



				if(($counterValue==2) || ($counterValue==3)){



					$incrementTwo = $finalNewGeneratedArray[$uniqueKey]['secondCondition'];



					$finalNewGeneratedArray[$uniqueKey]['secondCondition'] = $incrementTwo+1;



				}



				if($counterValue>=4){



					$incrementThree = $finalNewGeneratedArray[$uniqueKey]['thirdCondition'];



					$finalNewGeneratedArray[$uniqueKey]['thirdCondition'] = $incrementThree+1;



				}



			}



		}



		echo '<pre>';print_r($finalNewGeneratedArray);die;











		$getFinalArray = array();



		foreach ($eventArrayOne as $eventArrayKey => $eventArrayValue) {



			$getFinalArray[] = array(



				'yearName' => $eventArrayKey,



				'user_number' => $eventArrayValue



			);



		}



		echo '<pre>';print_r($getFinalArray);die;



	}







	function checkSecond(){



		$paidRevenue = $this->common_model->getRevenue(1);



		$unpaidRevenue = $this->common_model->getRevenue(0);



		echo "Paid revenue<br/>";



		echo '<pre>';print_r($paidRevenue);



		echo "UnPaid revenue<br/>";



		echo '<pre>';print_r($unpaidRevenue);die;



	}







	public function userList(){



		$arrayResult = array();



		$query = "SELECT * from `feu_userdetails`";



		$sql = $this->db->query($query);



		if($sql->num_rows()>0){



			foreach($sql->result() as $key => $value){



				$getTime = date('Y',$value->created);



				//echo $getTime.'<br/>';



				if(!array_key_exists($getTime, $arrayResult)){



					$arrayResult[$getTime] = 1;



				}else{



					$incrementNumber = $arrayResult[$getTime];



					$arrayResult[$getTime] = $incrementNumber+1;



				}



			}



		}



		ksort($arrayResult);



		echo '<pre>';print_r($arrayResult);die;



	}



}	



