<?php
defined('BASEPATH') OR exit('No direct script access allowed');
date_default_timezone_set("Europe/Zurich");
class Log extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->model('common_model');
		$this->load->model('users_model');
		if(get_cookie('admin_id'))
		{
			$this->session->set_userdata('admin_id',get_cookie('admin_id'));
		}
		if(!$this->session->userdata('admin_id'))
		{
			redirect('admin/login');
		}
	}
	public function index(){
		$content_data = array();
		$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
		$sql = "SELECT * from (SELECT username,email,logout_time,last_login,login_time, FROM_UNIXTIME(usr_users.last_login) as date FROM `feu_userdetails` JOIN `usr_users` ON `feu_userdetails`.`user_id` = `usr_users`.`id` ORDER BY `usr_users`.`last_login` DESC) as a WHERE a.date >= '".date('Y-m-d 00:00:00')."' and a.date <= '".date('Y-m-d 23:59:59')."'";
		$res = $this->db->query($sql);
		$content_data['users'] = $res->result_array();

		$sqlMsg = "SELECT * from (SELECT username,email,msg_messages.created,text, FROM_UNIXTIME(msg_messages.created) as date FROM `msg_messages` JOIN `usr_users` ON `msg_messages`.`from_user_id` = `usr_users`.`id` INNER JOIN feu_userdetails ON feu_userdetails.user_id = usr_users.id ORDER BY `msg_messages`.`created` DESC) as a WHERE a.date >= '".date('Y-m-d 00:00:00')."' and a.date <= '".date('Y-m-d 23:59:59')."'";
		$resMsg = $this->db->query($sqlMsg);
		$content_data['messages'] = $resMsg->result_array();
		if($this->input->post())
		{
			$fromtime = date('Y-m-d',strtotime($this->input->post('fromDate')));
			$totime = date('Y-m-d',strtotime($this->input->post('fromDate')));
			$sql = "SELECT * from (SELECT username,email,logout_time,last_login,login_time, FROM_UNIXTIME(usr_users.last_login) as date FROM `feu_userdetails` JOIN `usr_users` ON `feu_userdetails`.`user_id` = `usr_users`.`id` ORDER BY `usr_users`.`last_login` DESC) as a WHERE a.date >= '".date($fromtime.' 00:00:00')."' and a.date <= '".date($totime.' 23:59:59')."'";
			$res = $this->db->query($sql);
			$content_data['users'] = $res->result_array();

			$sqlMsg = "SELECT * from (SELECT username,email,msg_messages.created,text, FROM_UNIXTIME(msg_messages.created) as date FROM `msg_messages` JOIN `usr_users` ON `msg_messages`.`from_user_id` = `usr_users`.`id` INNER JOIN feu_userdetails ON feu_userdetails.user_id = usr_users.id ORDER BY `msg_messages`.`created` DESC) as a WHERE a.date >= '".date($fromtime.' 00:00:00')."' and a.date <= '".date($totime.' 23:59:59')."'";
			$resMsg = $this->db->query($sqlMsg);
			$content_data['messages'] = $resMsg->result_array();
		}
		//print_r($content_data); die;
		$data['content'] = $this->load->view('admin/log/list', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function alllist(){
		$content_data = array();
		$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
		
		/***************Yearly******************/
		$sql = "SELECT count(*) as total, YEAR(FROM_UNIXTIME(usr_users.last_login)) as year FROM `feu_userdetails` JOIN `usr_users` ON `feu_userdetails`.`user_id` = `usr_users`.`id` GROUP BY YEAR(FROM_UNIXTIME(usr_users.last_login)) ORDER BY `usr_users`.`last_login` DESC";
		$res = $this->db->query($sql);
		$content_data['users']['yearly'] = $res->result_array();
		$content_data['users']['year'] = $res->result_array();

		$sqlMsg = "SELECT count(*) as total, YEAR(FROM_UNIXTIME(msg_messages.created)) as year FROM `msg_messages` JOIN `usr_users` ON `msg_messages`.`from_user_id` = `usr_users`.`id` INNER JOIN feu_userdetails ON feu_userdetails.user_id = usr_users.id GROUP BY YEAR(FROM_UNIXTIME(msg_messages.created)) ORDER BY `msg_messages`.`created` DESC";
		$resMsg = $this->db->query($sqlMsg);
		$content_data['messages']['yearly'] = $resMsg->result_array();
		/***************Yearly******************/
		if($this->input->post('year')!='')
		{
			/***************Monthly******************/
			$sql = "SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(usr_users.last_login)) as year FROM `feu_userdetails` JOIN `usr_users` ON `feu_userdetails`.`user_id` = `usr_users`.`id` WHERE YEAR(FROM_UNIXTIME(usr_users.last_login)) = '".$this->input->post('year')."' GROUP BY MONTH(FROM_UNIXTIME(usr_users.last_login)) ORDER BY `usr_users`.`last_login` DESC";
			$res = $this->db->query($sql);
			$content_data['users']['yearly'] = $res->result_array();

			$sqlMsg = "SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(msg_messages.created)) as year FROM `msg_messages` JOIN `usr_users` ON `msg_messages`.`from_user_id` = `usr_users`.`id` INNER JOIN feu_userdetails ON feu_userdetails.user_id = usr_users.id WHERE YEAR(FROM_UNIXTIME(msg_messages.created)) = '".$this->input->post('year')."' GROUP BY MONTH(FROM_UNIXTIME(msg_messages.created)) ORDER BY `msg_messages`.`created` DESC";
			$resMsg = $this->db->query($sqlMsg);
			$content_data['messages']['yearly'] = $resMsg->result_array();
			
			/***************Monthly******************/
			if($this->input->post('month')!='')
			{
				/***************Daily******************/
				$sql = "SELECT count(*) as total, DATE(FROM_UNIXTIME(usr_users.last_login)) as year FROM `feu_userdetails` JOIN `usr_users` ON `feu_userdetails`.`user_id` = `usr_users`.`id` WHERE YEAR(FROM_UNIXTIME(usr_users.last_login)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(usr_users.last_login)) = '".$this->input->post('month')."' GROUP BY DATE(FROM_UNIXTIME(usr_users.last_login)) ORDER BY `usr_users`.`last_login` DESC";
				$res = $this->db->query($sql);
				$content_data['users']['yearly'] = $res->result_array();

				$sqlMsg = "SELECT count(*) as total, DATE(FROM_UNIXTIME(msg_messages.created)) as year FROM `msg_messages` JOIN `usr_users` ON `msg_messages`.`from_user_id` = `usr_users`.`id` INNER JOIN feu_userdetails ON feu_userdetails.user_id = usr_users.id WHERE YEAR(FROM_UNIXTIME(msg_messages.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(msg_messages.created)) = '".$this->input->post('month')."' GROUP BY DATE(FROM_UNIXTIME(msg_messages.created)) ORDER BY `msg_messages`.`created` DESC";
				$resMsg = $this->db->query($sqlMsg);
				$content_data['messages']['yearly'] = $resMsg->result_array();
				/***************Daily******************/
			}
		}


		$premiumSendMessageqry = $this->db->query('select * from (select * from (SELECT shop_orders.time,shop_orders.created,`usr_users`.`id` as `user_id`,shop_articles_carts.article_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` INNER JOIN `feu_userdetails` ON `feu_userdetails`.`user_id` = `usr_users`.`id` INNER JOIN msg_messages ON feu_userdetails.user_id = msg_messages.from_user_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) group by user_id order by b.created DESC');
		$premiumSendMessageData = $premiumSendMessageqry->result_array();
		$content_data['premiumSendMessage'] = count($premiumSendMessageData);

		$basicYearSendMessageqry = $this->db->query('select * from (select * from (SELECT shop_orders.time,shop_orders.created,`usr_users`.`id` as `user_id`,shop_articles_carts.article_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` INNER JOIN `feu_userdetails` ON `feu_userdetails`.`user_id` = `usr_users`.`id` INNER JOIN msg_messages ON feu_userdetails.user_id = msg_messages.from_user_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) group by user_id order by b.created DESC');
		$basicYearSendMessageData = $basicYearSendMessageqry->result_array();
		$content_data['basicYearSendMessage'] = count($basicYearSendMessageData);

		$basicHalfSendMessageqry = $this->db->query('select * from (select * from (SELECT shop_orders.time,shop_orders.created,`usr_users`.`id` as `user_id`,shop_articles_carts.article_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` INNER JOIN `feu_userdetails` ON `feu_userdetails`.`user_id` = `usr_users`.`id` INNER JOIN msg_messages ON feu_userdetails.user_id = msg_messages.from_user_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) group by user_id order by b.created DESC');
		$basicHalfSendMessageData = $basicHalfSendMessageqry->result_array();
		$content_data['basicHalfSendMessage'] = count($basicHalfSendMessageData);


		$premiumGetMessageqry = $this->db->query('select * from (select * from (SELECT shop_orders.time,shop_orders.created,`usr_users`.`id` as `user_id`,shop_articles_carts.article_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` INNER JOIN `feu_userdetails` ON `feu_userdetails`.`user_id` = `usr_users`.`id` INNER JOIN msg_conversations_users ON feu_userdetails.user_id = msg_conversations_users.user_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) group by user_id order by b.created DESC');
		$premiumGetMessageData = $premiumGetMessageqry->result_array();
		$content_data['premiumGetMessage'] = count($premiumGetMessageData);

		$basicYearGetMessageqry = $this->db->query('select * from (select * from (SELECT shop_orders.time,shop_orders.created,`usr_users`.`id` as `user_id`,shop_articles_carts.article_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` INNER JOIN `feu_userdetails` ON `feu_userdetails`.`user_id` = `usr_users`.`id` INNER JOIN msg_conversations_users ON feu_userdetails.user_id = msg_conversations_users.user_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) group by user_id order by b.created DESC');
		$basicYearGetMessageData = $basicYearGetMessageqry->result_array();
		$content_data['basicYearGetMessage'] = count($basicYearGetMessageData);

		$basicHalfGetMessageqry = $this->db->query('select * from (select * from (SELECT shop_orders.time,shop_orders.created,`usr_users`.`id` as `user_id`,shop_articles_carts.article_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` INNER JOIN `feu_userdetails` ON `feu_userdetails`.`user_id` = `usr_users`.`id` INNER JOIN msg_conversations_users ON feu_userdetails.user_id = msg_conversations_users.user_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) group by user_id order by b.created DESC');
		$basicHalfGetMessageData = $basicHalfGetMessageqry->result_array();
		$content_data['basicHalfGetMessage'] = count($basicHalfGetMessageData);




		$basicCoupleSendOneMessageqry = $this->db->query('select *,count(text) as total from (select * from (SELECT text,shop_orders.time,shop_orders.created,`usr_users`.`id` as `user_id`,shop_articles_carts.article_id,msg_messages.from_user_id,msg_conversations_users.user_id as to_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` INNER JOIN `feu_userdetails` ON `feu_userdetails`.`user_id` = `usr_users`.`id` INNER JOIN msg_messages ON feu_userdetails.user_id = msg_messages.from_user_id INNER JOIN msg_conversations_users ON msg_messages.conversation_id = msg_conversations_users.conversation_id WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 AND accounttype = "couple" ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(time()-182*86400).') when time = 365 then (created > '.(time()-365*86400).') END AND article_id in (5) group by user_id order by b.created DESC');
		$basicCoupleSendOneMessageData = $basicCoupleSendOneMessageqry->result_array();
		$coupletotalOne = 0;
		$coupletotalTwo = 0;
		$coupletotalMore = 0;
		if(count($basicCoupleSendOneMessageData)>0)
		{
			foreach($basicCoupleSendOneMessageData as $res)
			{
				if($res['total']==1)
				{
					$coupletotalOne = $coupletotalOne+1;
				}
				if($res['total']==2)
				{
					$coupletotalTwo = $coupletotalTwo+1;
				}
				if($res['total']>2)
				{
					$coupletotalMore = $coupletotalMore+1;
				}
			}
		}

		$basicGentlemanSendOneMessageqry = $this->db->query('select *,count(text) as total from (select * from (SELECT text,shop_orders.time,shop_orders.created,`usr_users`.`id` as `user_id`,shop_articles_carts.article_id,msg_messages.from_user_id,msg_conversations_users.user_id as to_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` INNER JOIN `feu_userdetails` ON `feu_userdetails`.`user_id` = `usr_users`.`id` INNER JOIN msg_messages ON feu_userdetails.user_id = msg_messages.from_user_id INNER JOIN msg_conversations_users ON msg_messages.conversation_id = msg_conversations_users.conversation_id WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 AND accounttype = "gentleman" ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(time()-182*86400).') when time = 365 then (created > '.(time()-365*86400).') END AND article_id in (5) group by user_id order by b.created DESC');
		$basicGentlemanSendOneMessageData = $basicGentlemanSendOneMessageqry->result_array();
		$gentlemantotalOne = 0;
		$gentlemantotalTwo = 0;
		$gentlemantotalMore = 0;
		if(count($basicGentlemanSendOneMessageData)>0)
		{
			foreach($basicGentlemanSendOneMessageData as $res)
			{
				if($res['total']==1)
				{
					$gentlemantotalOne = $gentlemantotalOne+1;
				}
				if($res['total']==2)
				{
					$gentlemantotalTwo = $gentlemantotalTwo+1;
				}
				if($res['total']>2)
				{
					$gentlemantotalMore = $gentlemantotalMore+1;
				}
			}
		}

		$basicLadySendOneMessageqry = $this->db->query('select *,count(text) as total from (select * from (SELECT text,shop_orders.time,shop_orders.created,`usr_users`.`id` as `user_id`,shop_articles_carts.article_id,msg_messages.from_user_id,msg_conversations_users.user_id as to_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` INNER JOIN `feu_userdetails` ON `feu_userdetails`.`user_id` = `usr_users`.`id` INNER JOIN msg_messages ON feu_userdetails.user_id = msg_messages.from_user_id INNER JOIN msg_conversations_users ON msg_messages.conversation_id = msg_conversations_users.conversation_id WHERE ( `shop_articles_carts`.`cancelled` != 1 OR `shop_articles_carts`.`cancelled` IS NULL ) AND `shop_orders`.`payed` = 1 AND accounttype = "lady" ORDER BY `usr_users`.`id` DESC, `shop_carts`.`created` DESC) as a ORDER BY a.user_id DESC) as b where case when time = 182 then (created >= '.(time()-182*86400).') when time = 365 then (created > '.(time()-365*86400).') END AND article_id in (5) group by user_id order by b.created DESC');
		$basicLadySendOneMessageData = $basicLadySendOneMessageqry->result_array();
		$ladytotalOne = 0;
		$ladytotalTwo = 0;
		$ladytotalMore = 0;
		if(count($basicLadySendOneMessageData)>0)
		{
			foreach($basicLadySendOneMessageData as $res)
			{
				if($res['total']==1)
				{
					$ladytotalOne = $ladytotalOne+1;
				}
				if($res['total']==2)
				{
					$ladytotalTwo = $ladytotalTwo+1;
				}
				if($res['total']>2)
				{
					$ladytotalMore = $ladytotalMore+1;
				}
			}
		}

		//print_r($content_data); die;
		//echo $coupletotalOne.'='.$coupletotalTwo.'='.$coupletotalMore; die;
		$content_data['coupletotalOne'] = $coupletotalOne;
		$content_data['coupletotalTwo'] = $coupletotalTwo;
		$content_data['coupletotalMore'] = $coupletotalMore;

		$content_data['gentlemantotalOne'] = $gentlemantotalOne;
		$content_data['gentlemantotalTwo'] = $gentlemantotalTwo;
		$content_data['gentlemantotalMore'] = $gentlemantotalMore;

		$content_data['ladytotalOne'] = $ladytotalOne;
		$content_data['ladytotalTwo'] = $ladytotalTwo;
		$content_data['ladytotalMore'] = $ladytotalMore;


		$sqlCountry = "SELECT count(*) as total, country_name FROM feu_userdetails JOIN feu_countries ON feu_userdetails.country = feu_countries.country_code  GROUP BY feu_countries.country_code ORDER BY feu_countries.country_name ASC limit 50";
		$resCountry = $this->db->query($sqlCountry);
		$content_data['country'] = $resCountry->result_array();

		$sqlCountry100 = "SELECT count(*) as total, country_name FROM feu_userdetails JOIN feu_countries ON feu_userdetails.country = feu_countries.country_code  GROUP BY feu_countries.country_code ORDER BY feu_countries.country_name ASC limit 50,50";
		$resCountry100 = $this->db->query($sqlCountry100);
		$content_data['country100'] = $resCountry100->result_array();

		$sqlCountry150 = "SELECT count(*) as total, country_name FROM feu_userdetails JOIN feu_countries ON feu_userdetails.country = feu_countries.country_code  GROUP BY feu_countries.country_code ORDER BY feu_countries.country_name ASC limit 100,50";
		$resCountry150 = $this->db->query($sqlCountry150);
		$content_data['country150'] = $resCountry150->result_array();

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

		$data['content'] = $this->load->view('admin/log/alllist', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	function activity()
	{
		date_default_timezone_set("Europe/Zurich");
		$content_data = array();
		if($this->input->post())
		{
			if($this->input->post('year') && $this->input->post('month')=='')
			{
				$ConnectRequestRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 1 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['ConnectRequest'] = $ConnectRequestRes->result_array();
				$MessageRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 4 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Message'] = $MessageRes->result_array();
				$PrivacyRequestRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 5 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['PrivacyRequest'] = $PrivacyRequestRes->result_array();
				$HotshotProfileRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 8 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['HotshotProfile'] = $HotshotProfileRes->result_array();
				$HotshotPictureRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 9 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['HotshotPicture'] = $HotshotPictureRes->result_array();
				$VisitRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 10 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Visit'] = $VisitRes->result_array();
				$RegisterRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 11 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Register'] = $RegisterRes->result_array();
				$UploadRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 12 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Upload'] = $UploadRes->result_array();
				$UpgradeRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 14 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Upgrade'] = $UpgradeRes->result_array();
				$LoginRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(usr_log.log_time)) as year FROM `usr_log` WHERE YEAR(FROM_UNIXTIME(usr_log.log_time)) = '".$this->input->post('year')."' GROUP BY MONTH(FROM_UNIXTIME(usr_log.log_time)) ORDER BY usr_log.log_time DESC");
				$content_data['Login'] = $LoginRes->result_array();
			}
			if($this->input->post('year') && $this->input->post('month')  && $this->input->post('day')=='')
			{
				$ConnectRequestRes = $this->db->query("SELECT count(*) as total, DATE(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 1 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' GROUP BY DATE(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['ConnectRequest'] = $ConnectRequestRes->result_array();
				$MessageRes = $this->db->query("SELECT count(*) as total, DATE(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 4 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' GROUP BY DATE(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Message'] = $MessageRes->result_array();
				$PrivacyRequestRes = $this->db->query("SELECT count(*) as total, DATE(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 5 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' GROUP BY DATE(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['PrivacyRequest'] = $PrivacyRequestRes->result_array();
				$HotshotProfileRes = $this->db->query("SELECT count(*) as total, DATE(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 8 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' GROUP BY DATE(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['HotshotProfile'] = $HotshotProfileRes->result_array();
				$HotshotPictureRes = $this->db->query("SELECT count(*) as total, DATE(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 9 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' GROUP BY DATE(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['HotshotPicture'] = $HotshotPictureRes->result_array();
				$VisitRes = $this->db->query("SELECT count(*) as total, DATE(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 10 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' GROUP BY DATE(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Visit'] = $VisitRes->result_array();
				$RegisterRes = $this->db->query("SELECT count(*) as total, DATE(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 11 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' GROUP BY DATE(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Register'] = $RegisterRes->result_array();
				$UploadRes = $this->db->query("SELECT count(*) as total, DATE(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 12 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' GROUP BY DATE(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Upload'] = $UploadRes->result_array();
				$UpgradeRes = $this->db->query("SELECT count(*) as total, DATE(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 14 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' GROUP BY DATE(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Upgrade'] = $UpgradeRes->result_array();
				$LoginRes = $this->db->query("SELECT count(*) as total, DATE(FROM_UNIXTIME(usr_log.log_time)) as year FROM `usr_log` WHERE YEAR(FROM_UNIXTIME(usr_log.log_time)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(usr_log.log_time)) = '".$this->input->post('month')."' GROUP BY DATE(FROM_UNIXTIME(usr_log.log_time)) ORDER BY usr_log.log_time DESC");
				$content_data['Login'] = $LoginRes->result_array();
				//echo $this->db->last_query(); die;
				//pr($content_data);
			}
			if($this->input->post('year') && $this->input->post('month') && $this->input->post('day') && $this->input->post('hour')=='')
			{
				$date = $this->input->post('year').'-'.$this->input->post('month').'-'.$this->input->post('day');
				$ConnectRequestRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 1 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['ConnectRequest'] = $ConnectRequestRes->result_array();
				$MessageRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 4 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Message'] = $MessageRes->result_array();
				$PrivacyRequestRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 5 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['PrivacyRequest'] = $PrivacyRequestRes->result_array();
				$HotshotProfileRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 8 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['HotshotProfile'] = $HotshotProfileRes->result_array();
				$HotshotPictureRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 9 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['HotshotPicture'] = $HotshotPictureRes->result_array();
				$VisitRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 10 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Visit'] = $VisitRes->result_array();
				$RegisterRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 11 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Register'] = $RegisterRes->result_array();
				$UploadRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 12 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Upload'] = $UploadRes->result_array();
				$UpgradeRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 14 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Upgrade'] = $UpgradeRes->result_array();
				$LoginRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(usr_log.log_time)) as year FROM `usr_log` WHERE YEAR(FROM_UNIXTIME(usr_log.log_time)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(usr_log.log_time)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(usr_log.log_time)) = '".$date."' GROUP BY HOUR(FROM_UNIXTIME(usr_log.log_time)) ORDER BY usr_log.log_time DESC");
				$content_data['Login'] = $LoginRes->result_array();
				
				//pr($content_data);
			}
			if($this->input->post('year') && $this->input->post('month') && $this->input->post('day') && $this->input->post('hour'))
			{
				$date = $this->input->post('year').'-'.$this->input->post('month').'-'.$this->input->post('day');
				$ConnectRequestRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 1 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' AND HOUR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('hour')."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['ConnectRequest'] = $ConnectRequestRes->result_array();
				$MessageRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 4 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' AND HOUR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('hour')."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Message'] = $MessageRes->result_array();
				$PrivacyRequestRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 5 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' AND HOUR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('hour')."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['PrivacyRequest'] = $PrivacyRequestRes->result_array();
				$HotshotProfileRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 8 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' AND HOUR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('hour')."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['HotshotProfile'] = $HotshotProfileRes->result_array();
				$HotshotPictureRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 9 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' AND HOUR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('hour')."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['HotshotPicture'] = $HotshotPictureRes->result_array();
				$VisitRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 10 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' AND HOUR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('hour')."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Visit'] = $VisitRes->result_array();
				$RegisterRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 11 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' AND HOUR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('hour')."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Register'] = $RegisterRes->result_array();
				$UploadRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 12 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' AND HOUR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('hour')."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Upload'] = $UploadRes->result_array();
				$UpgradeRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 14 AND YEAR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(notification.created)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(notification.created)) = '".$date."' AND HOUR(FROM_UNIXTIME(notification.created)) = '".$this->input->post('hour')."' GROUP BY HOUR(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
				$content_data['Upgrade'] = $UpgradeRes->result_array();
				$LoginRes = $this->db->query("SELECT count(*) as total, HOUR(FROM_UNIXTIME(usr_log.log_time)) as year FROM `usr_log` WHERE YEAR(FROM_UNIXTIME(usr_log.log_time)) = '".$this->input->post('year')."' AND MONTH(FROM_UNIXTIME(usr_log.log_time)) = '".$this->input->post('month')."' AND DATE(FROM_UNIXTIME(usr_log.log_time)) = '".$date."' AND HOUR(FROM_UNIXTIME(usr_log.log_time)) = '".$this->input->post('hour')."' GROUP BY HOUR(FROM_UNIXTIME(usr_log.log_time)) ORDER BY usr_log.log_time DESC");
				$content_data['Login'] = $LoginRes->result_array();
				//echo $this->db->last_query(); die;
				//pr($content_data);
			}
		}
		else
		{
			$ConnectRequestRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 1 AND YEAR(FROM_UNIXTIME(notification.created)) = '".date('Y')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
			$content_data['ConnectRequest'] = $ConnectRequestRes->result_array();
			$MessageRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 4 AND YEAR(FROM_UNIXTIME(notification.created)) = '".date('Y')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
			$content_data['Message'] = $MessageRes->result_array();
			$PrivacyRequestRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 5 AND YEAR(FROM_UNIXTIME(notification.created)) = '".date('Y')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
			$content_data['PrivacyRequest'] = $PrivacyRequestRes->result_array();
			$HotshotProfileRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 8 AND YEAR(FROM_UNIXTIME(notification.created)) = '".date('Y')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
			$content_data['HotshotProfile'] = $HotshotProfileRes->result_array();
			$HotshotPictureRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 9 AND YEAR(FROM_UNIXTIME(notification.created)) = '".date('Y')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
			$content_data['HotshotPicture'] = $HotshotPictureRes->result_array();
			$VisitRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 10 AND YEAR(FROM_UNIXTIME(notification.created)) = '".date('Y')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
			$content_data['Visit'] = $VisitRes->result_array();
			$RegisterRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 11 AND YEAR(FROM_UNIXTIME(notification.created)) = '".date('Y')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
			$content_data['Register'] = $RegisterRes->result_array();
			$UploadRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 12 AND YEAR(FROM_UNIXTIME(notification.created)) = '".date('Y')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
			$content_data['Upload'] = $UploadRes->result_array();
			$UpgradeRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(notification.created)) as year FROM `notification` WHERE type= 14 AND YEAR(FROM_UNIXTIME(notification.created)) = '".date('Y')."' GROUP BY MONTH(FROM_UNIXTIME(notification.created)) ORDER BY `notification`.`created` ASC");
			$content_data['Upgrade'] = $UpgradeRes->result_array();
			$LoginRes = $this->db->query("SELECT count(*) as total, MONTHNAME(FROM_UNIXTIME(usr_log.log_time)) as year FROM `usr_log` WHERE YEAR(FROM_UNIXTIME(usr_log.log_time)) = '".date('Y')."' GROUP BY MONTH(FROM_UNIXTIME(usr_log.log_time)) ORDER BY usr_log.log_time ASC");
			$content_data['Login'] = $LoginRes->result_array();
		}
		
		
		//print_r($content_data); die;

		$data['content'] = $this->load->view('admin/log/activitylist', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function userlog($page=''){
		$content_data = array();
		if($page=='')
		{
			$page=0;
		}
		$limit = 100;

		$data['loginDetails'] = $this->common_model->getAllRow('feu_userdetails',array('id'=>$this->session->userdata('admin_id')),array('usr_users','feu_userdetails.user_id = usr_users.id')) ;
		$content_data['users'] = $this->common_model->getAllMultipleJoin('usr_log','',array(array('feu_userdetails','feu_userdetails.user_id = usr_log.user_id'),array('usr_users','feu_userdetails.user_id = usr_users.id')),'usr_log.log_time DESC','','',$page,$limit) ;
		
		$userlist = $this->common_model->getAllMultipleJoin('usr_log','',array(array('feu_userdetails','feu_userdetails.user_id = usr_log.user_id'),array('usr_users','feu_userdetails.user_id = usr_users.id')),'usr_log.log_time DESC','','',0,5000) ;
		if($this->input->post())
		{
			if($this->input->post('search') && $this->input->post('search_name'))
			{
				$content_data['users'] = $this->common_model->getAllMultipleJoin('usr_log','',array(array('feu_userdetails','feu_userdetails.user_id = usr_log.user_id'),array('usr_users','feu_userdetails.user_id = usr_users.id')),'usr_log.log_time DESC','','',$page,$limit,array('email'=>$this->input->post('search'),'username'=>$this->input->post('search_name'))) ;
				$userlist = $this->common_model->getAllMultipleJoin('usr_log','',array(array('feu_userdetails','feu_userdetails.user_id = usr_log.user_id'),array('usr_users','feu_userdetails.user_id = usr_users.id')),'usr_log.log_time DESC','','','','',array('email'=>$this->input->post('search'),'username'=>$this->input->post('search_name'))) ;
			}
			if($this->input->post('search'))
			{
				$content_data['users'] = $this->common_model->getAllMultipleJoin('usr_log','',array(array('feu_userdetails','feu_userdetails.user_id = usr_log.user_id'),array('usr_users','feu_userdetails.user_id = usr_users.id')),'usr_log.log_time DESC','','',$page,$limit,array('email'=>$this->input->post('search'))) ;
				$userlist = $this->common_model->getAllMultipleJoin('usr_log','',array(array('feu_userdetails','feu_userdetails.user_id = usr_log.user_id'),array('usr_users','feu_userdetails.user_id = usr_users.id')),'usr_log.log_time DESC','','','','',array('email'=>$this->input->post('search'))) ;
			}
			if($this->input->post('search_name'))
			{
				$content_data['users'] = $this->common_model->getAllMultipleJoin('usr_log','',array(array('feu_userdetails','feu_userdetails.user_id = usr_log.user_id'),array('usr_users','feu_userdetails.user_id = usr_users.id')),'usr_log.log_time DESC','','',$page,$limit,array('username'=>$this->input->post('search_name'))) ;
				$userlist = $this->common_model->getAllMultipleJoin('usr_log','',array(array('feu_userdetails','feu_userdetails.user_id = usr_log.user_id'),array('usr_users','feu_userdetails.user_id = usr_users.id')),'usr_log.log_time DESC','','','','',array('username'=>$this->input->post('search_name'))) ;
			}
			if($this->input->post('fromDate'))
			{
				$where = "DATE(FROM_UNIXTIME(usr_log.log_time)) = '".date('Y-m-d',strtotime($this->input->post('fromDate')))."'";
				$content_data['users'] = $this->common_model->getAllMultipleJoin('usr_log',$where,array(array('feu_userdetails','feu_userdetails.user_id = usr_log.user_id'),array('usr_users','feu_userdetails.user_id = usr_users.id')),'usr_log.log_time DESC','','',$page,$limit) ;
				//echo $this->db->last_query(); die;
				$userlist = $this->common_model->getAllMultipleJoin('usr_log',$where,array(array('feu_userdetails','feu_userdetails.user_id = usr_log.user_id'),array('usr_users','feu_userdetails.user_id = usr_users.id')),'usr_log.log_time DESC') ;
			}
		}
		$this->load->library('pagination');
		$config['base_url'] = base_url().'admin/log/userlog/';
		$config['total_rows'] = count($userlist);
		$config['per_page'] = $limit;
		$this->pagination->initialize($config);

		$content_data['link'] = $this->pagination->create_links();
		$data['content'] = $this->load->view('admin/log/userlog', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function vat_users()
	{
		/*****************SWISS CARD (VAT) PAYMENT STAT QUARTARLY**************/
	    if($this->input->post('vat_year'))
	    {
	      $whereCurrent = 'vat > 0 and payed = 1 and is_booking = 0 and MONTH(FROM_UNIXTIME(shop_orders.created)) in (1,2,3) and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$this->input->post('vat_year');
	      $content_data['first_quartar'] = $this->common_model->getAll('shop_orders',$whereCurrent,'','created DESC');
	      $whereCurrent = 'vat > 0 and payed = 1 and is_booking = 0 and MONTH(FROM_UNIXTIME(shop_orders.created)) in (4,5,6) and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$this->input->post('vat_year');
	      $content_data['second_quartar'] = $this->common_model->getAll('shop_orders',$whereCurrent,'','created DESC');
	      $whereCurrent = 'vat > 0 and payed = 1 and is_booking = 0 and MONTH(FROM_UNIXTIME(shop_orders.created)) in (7,8,9) and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$this->input->post('vat_year');
	      $content_data['third_quartar'] = $this->common_model->getAll('shop_orders',$whereCurrent,'','created DESC');
	      $whereCurrent = 'vat > 0 and payed = 1 and is_booking = 0 and MONTH(FROM_UNIXTIME(shop_orders.created)) in (10,11,12) and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$this->input->post('vat_year');
	      $content_data['fourth_quartar'] = $this->common_model->getAll('shop_orders',$whereCurrent,'','created DESC');
	    }
	    else
	    {
	      $whereCurrent = 'vat > 0 and payed = 1 and is_booking = 0 and MONTH(FROM_UNIXTIME(shop_orders.created)) in (1,2,3) and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.date('Y');
	      $content_data['first_quartar'] = $this->common_model->getAll('shop_orders',$whereCurrent,'','created DESC');
	      $whereCurrent = 'vat > 0 and payed = 1 and is_booking = 0 and MONTH(FROM_UNIXTIME(shop_orders.created)) in (4,5,6) and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.date('Y');
	      $content_data['second_quartar'] =$this->common_model->getAll('shop_orders',$whereCurrent,'','created DESC');
	      $whereCurrent = 'vat > 0 and payed = 1 and is_booking = 0 and MONTH(FROM_UNIXTIME(shop_orders.created)) in (7,8,9) and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.date('Y');
	      $content_data['third_quartar'] = $this->common_model->getAll('shop_orders',$whereCurrent,'','created DESC');
	      $whereCurrent = 'vat > 0 and payed = 1 and is_booking = 0 and MONTH(FROM_UNIXTIME(shop_orders.created)) in (10,11,12) and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.date('Y');
	      $content_data['fourth_quartar'] = $this->common_model->getAll('shop_orders',$whereCurrent,'','created DESC');
	    }
	    /*****************SWISS CARD (VAT) PAYMENT STAT QUATARLY**************/
		$data['content'] = $this->load->view('admin/log/vat_users', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function download_vat1($year)
	{
		$whereCurrent = 'vat > 0 and payed = 1 and is_booking = 0 and MONTH(FROM_UNIXTIME(shop_orders.created)) in (1,2,3) and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$year;
      	$first_quartar = $this->common_model->getAll('shop_orders',$whereCurrent,'','created DESC');
      	$site_address_name = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_name'));
		$site_address_city = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_city'));
		$site_address_country_zip = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_country_zip'));
      	/*************************Q1 PDF*************************/
		$q1html='<!DOCTYPE html>
					<html>
					   <head>
					      <title>invoice</title>
					   </head>
					   <body>
					      <div style="max-width:960px; width:100%; margin:0 auto 0; font-family: sans-serif; padding: 0 50px;">
					         <div style="padding: 50px 0 70px; ">
					          <p style="margin:0;">'.$site_address_name['value'].'</p>
					          <p style="margin:0;">'.$site_address_city['value'].',</p>
					          <p style="margin:0;">'.$site_address_country_zip['value'].'</p>
					          <p style="padding-top: 10px;">UID: CHE-362.535.263</p>
					         </div>
					         <h2 style="padding: 10px;border-bottom:1px solid #ccc; display: block;">Q1 - Mwst Abrechnung '.$year.'</h2>

					         <div style="width:700px; float: left;">

					         	<div style="width: 100%; float: left; padding-left:10px;">         	
					 			   	<div style="padding:10px ; font-weight: bold; width: 20%; height: 19px; line-height: 19px; float: left;">Date</div>
					               	<div style="padding:10px ; font-weight: bold; width: 20%; float: left; height: 19px; line-height: 19px;">Referenz</div>
					               	<div style=" font-weight: bold; padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">Betrag</div>
					               	<div style=" font-weight: bold; padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">Herkunft</div>
					         	</div>';
					         	if(!empty($first_quartar)){ 
					         		$total_first=0;
						            foreach ($first_quartar as $data) {
						            	$total_first+=$data['total_sum'];
		$q1html.='						<div style="width: 100%; float: left; padding-left:10px;">         	
							 			   	<div style="padding:10px ; width: 20%; height: 19px; line-height: 19px; float: left;">'.date('d-m-Y',$data['created']).'</div>
							               	<div style="padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">'.$data['order_id_masked'].'</div>
							               	<div style=" padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">'.number_format($data['total_sum']/100, 2,',', '.').' &euro;</div>
							               	<div style=" padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">CH</div>
							         	</div>';			            	
						            }
						        }
		$q1html.='			<div style="padding:10px ; font-weight: bold; width: 40%; height: 19px; line-height: 19px; float: left;">Total</div>
							<div style="padding:10px ; font-weight: bold; width: 20%; height: 19px; line-height: 19px; float: left;">'.number_format($total_first/100, 2,',', '.').' &euro;</div>
							</div>
					   </body>
					</html>';
		//echo $q1html;die;
		$pdfFilePath = "Q1 - Mwst Abrechnung ".$year.".pdf";
        $this->load->library('m_pdf');
        $this->m_pdf->pdf->useOnlyCoreFonts = true;    // false is default
		//$this->m_pdf->pdf->SetProtection(array('print'));
		$this->m_pdf->pdf->SetTitle("Castleevents Title");
		$this->m_pdf->pdf->SetAuthor("Author");
		/*$this->m_pdf->pdf->SetWatermarkText("Castleevents.com");
		$this->m_pdf->pdf->showWatermarkText = true;
		$this->m_pdf->pdf->watermark_font = 'DejaVuSansCondensed';
		$this->m_pdf->pdf->watermarkTextAlpha = 0.1;*/
		$this->m_pdf->pdf->SetDisplayMode('fullpage'); 
		$this->m_pdf->pdf->WriteHTML($q1html);
		$this->m_pdf->pdf->Output($pdfFilePath, "D");  
        die;
        /*************************Q1 PDF*************************/

	}

	public function download_vat2($year)
	{
		$whereCurrent = 'vat > 0 and payed = 1 and is_booking = 0 and MONTH(FROM_UNIXTIME(shop_orders.created)) in (4,5,6) and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$year;
      	$second_quartar =$this->common_model->getAll('shop_orders',$whereCurrent,'','created DESC');
      	$site_address_name = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_name'));
		$site_address_city = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_city'));
		$site_address_country_zip = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_country_zip'));
      	/*************************Q2 PDF*************************/
        $q2html='<!DOCTYPE html>
					<html>
					   <head>
					      <title>invoice</title>
					   </head>
					   <body>
					      <div style="max-width:960px; width:100%; margin:0 auto 0; font-family: sans-serif; padding: 0 50px;">
					         <div style="padding: 50px 0 70px; ">
					          <p style="margin:0;">'.$site_address_name['value'].'</p>
					          <p style="margin:0;">'.$site_address_city['value'].',</p>
					          <p style="margin:0;">'.$site_address_country_zip['value'].'</p>
					          <p style="padding-top: 10px;">UID: CHE-362.535.263</p>
					         </div>
					         <h2 style="padding: 10px;border-bottom:1px solid #ccc; display: block;">Q2 - Mwst Abrechnung '.$year.'</h2>

					         <div style="width:700px; float: left;">

					         	<div style="width: 100%; float: left; padding-left:10px;">         	
					 			   	<div style="padding:10px ; font-weight: bold; width: 20%; height: 19px; line-height: 19px; float: left;">Date</div>
					               	<div style="padding:10px ; font-weight: bold; width: 20%; float: left; height: 19px; line-height: 19px;">Referenz</div>
					               	<div style=" font-weight: bold; padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">Betrag</div>
					               	<div style=" font-weight: bold; padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">Herkunft</div>
					         	</div>';
					         	if(!empty($second_quartar)){ 
					         		$total_second=0;
						            foreach ($second_quartar as $data) {
						            	$total_second+=$data['total_sum'];
		$q2html.='						<div style="width: 100%; float: left; padding-left:10px;">         	
							 			   	<div style="padding:10px ; width: 20%; height: 19px; line-height: 19px; float: left;">'.date('d-m-Y',$data['created']).'</div>
							               	<div style="padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">'.$data['order_id_masked'].'</div>
							               	<div style=" padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">'.number_format($data['total_sum']/100, 2,',', '.').' &euro;</div>
							               	<div style=" padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">CH</div>
							         	</div>';			            	
						            }
						        }
		$q2html.='			<div style="padding:10px ; font-weight: bold; width: 40%; height: 19px; line-height: 19px; float: left;">Total</div>
							<div style="padding:10px ; font-weight: bold; width: 20%; height: 19px; line-height: 19px; float: left;">'.number_format($total_second/100, 2,',', '.').' &euro;</div>
							</div>
					   </body>
					</html>';

		$pdfFilePath = "Q2 - Mwst Abrechnung ".$year.".pdf";
        $this->load->library('m_pdf');
        $this->m_pdf->pdf->useOnlyCoreFonts = true;    // false is default
		//$this->m_pdf->pdf->SetProtection(array('print'));
		$this->m_pdf->pdf->SetTitle("Castleevents Title");
		$this->m_pdf->pdf->SetAuthor("Author");
		/*$this->m_pdf->pdf->SetWatermarkText("Castleevents.com");
		$this->m_pdf->pdf->showWatermarkText = true;
		$this->m_pdf->pdf->watermark_font = 'DejaVuSansCondensed';
		$this->m_pdf->pdf->watermarkTextAlpha = 0.1;*/
		$this->m_pdf->pdf->SetDisplayMode('fullpage'); 
		$this->m_pdf->pdf->WriteHTML($q2html);
		$this->m_pdf->pdf->Output($pdfFilePath, "D");  
        die;
        /*************************Q2 PDF*************************/

	}

	public function download_vat3($year)
	{
		$whereCurrent = 'vat > 0 and payed = 1 and is_booking = 0 and MONTH(FROM_UNIXTIME(shop_orders.created)) in (7,8,9) and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$year;
      	$third_quartar = $this->common_model->getAll('shop_orders',$whereCurrent,'','created DESC');
      	$site_address_name = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_name'));
		$site_address_city = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_city'));
		$site_address_country_zip = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_country_zip'));
      	/*************************Q3 PDF*************************/
        $q3html='<!DOCTYPE html>
					<html>
					   <head>
					      <title>invoice</title>
					   </head>
					   <body>
					      <div style="max-width:960px; width:100%; margin:0 auto 0; font-family: sans-serif; padding: 0 50px;">
					         <div style="padding: 50px 0 70px; ">
					          <p style="margin:0;">'.$site_address_name['value'].'</p>
					          <p style="margin:0;">'.$site_address_city['value'].',</p>
					          <p style="margin:0;">'.$site_address_country_zip['value'].'</p>
					          <p style="padding-top: 10px;">UID: CHE-362.535.263</p>
					         </div>
					         <h2 style="padding: 10px;border-bottom:1px solid #ccc; display: block;">Q3 - Mwst Abrechnung '.$year.'</h2>

					         <div style="width:700px; float: left;">

					         	<div style="width: 100%; float: left; padding-left:10px;">         	
					 			   	<div style="padding:10px ; font-weight: bold; width: 20%; height: 19px; line-height: 19px; float: left;">Date</div>
					               	<div style="padding:10px ; font-weight: bold; width: 20%; float: left; height: 19px; line-height: 19px;">Referenz</div>
					               	<div style=" font-weight: bold; padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">Betrag</div>
					               	<div style=" font-weight: bold; padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">Herkunft</div>
					         	</div>';
					         	if(!empty($third_quartar)){ 
					         		$total_third=0;
						            foreach ($third_quartar as $data) {
						            	$total_third+=$data['total_sum'];
		$q3html.='						<div style="width: 100%; float: left; padding-left:10px;">         	
							 			   	<div style="padding:10px ; width: 20%; height: 19px; line-height: 19px; float: left;">'.date('d-m-Y',$data['created']).'</div>
							               	<div style="padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">'.$data['order_id_masked'].'</div>
							               	<div style=" padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">'.number_format($data['total_sum']/100, 2,',', '.').' &euro;</div>
							               	<div style=" padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">CH</div>
							         	</div>';			            	
						            }
						        }
		$q3html.='			<div style="padding:10px ; font-weight: bold; width: 40%; height: 19px; line-height: 19px; float: left;">Total</div>
							<div style="padding:10px ; font-weight: bold; width: 20%; height: 19px; line-height: 19px; float: left;">'.number_format($total_third/100, 2,',', '.').' &euro;</div>
							</div>
					   </body>
					</html>';

		$pdfFilePath = "Q3 - Mwst Abrechnung ".$year.".pdf";
        $this->load->library('m_pdf');
        $this->m_pdf->pdf->useOnlyCoreFonts = true;    // false is default
		//$this->m_pdf->pdf->SetProtection(array('print'));
		$this->m_pdf->pdf->SetTitle("Castleevents Title");
		$this->m_pdf->pdf->SetAuthor("Author");
		/*$this->m_pdf->pdf->SetWatermarkText("Castleevents.com");
		$this->m_pdf->pdf->showWatermarkText = true;
		$this->m_pdf->pdf->watermark_font = 'DejaVuSansCondensed';
		$this->m_pdf->pdf->watermarkTextAlpha = 0.1;*/
		$this->m_pdf->pdf->SetDisplayMode('fullpage'); 
		$this->m_pdf->pdf->WriteHTML($q3html);
		$this->m_pdf->pdf->Output($pdfFilePath, "D");  
        die;
        /*************************Q3 PDF*************************/

	}

	public function download_vat4($year)
	{
		$whereCurrent = 'vat > 0 and payed = 1 and is_booking = 0 and MONTH(FROM_UNIXTIME(shop_orders.created)) in (10,11,12) and YEAR(FROM_UNIXTIME(shop_orders.created)) = '.$year;
      	$fourth_quartar = $this->common_model->getAll('shop_orders',$whereCurrent,'','created DESC');
		$site_address_name = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_name'));
		$site_address_city = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_city'));
		$site_address_country_zip = $this->common_model->getAllRow('site_settings',array('code'=>'site_address_country_zip'));
        /*************************Q4 PDF*************************/
        $q4html='<!DOCTYPE html>
					<html>
					   <head>
					      <title>invoice</title>
					   </head>
					   <body>
					      <div style="max-width:960px; width:100%; margin:0 auto 0; font-family: sans-serif; padding: 0 50px;">
					         <div style="padding: 50px 0 70px; ">
					          <p style="margin:0;">'.$site_address_name['value'].'</p>
					          <p style="margin:0;">'.$site_address_city['value'].',</p>
					          <p style="margin:0;">'.$site_address_country_zip['value'].'</p>
					          <p style="padding-top: 10px;">UID: CHE-362.535.263</p>
					         </div>
					         <h2 style="padding: 10px;border-bottom:1px solid #ccc; display: block;">Q4 - Mwst Abrechnung '.$year.'</h2>

					         <div style="width:700px; float: left;">

					         	<div style="width: 100%; float: left; padding-left:10px;">         	
					 			   	<div style="padding:10px ; font-weight: bold; width: 20%; height: 19px; line-height: 19px; float: left;">Date</div>
					               	<div style="padding:10px ; font-weight: bold; width: 20%; float: left; height: 19px; line-height: 19px;">Referenz</div>
					               	<div style=" font-weight: bold; padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">Betrag</div>
					               	<div style=" font-weight: bold; padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">Herkunft</div>
					         	</div>';
					         	if(!empty($fourth_quartar)){ 
					         		$total_fourth=0;
						            foreach ($fourth_quartar as $data) {
						            	$total_fourth+=$data['total_sum'];
		$q4html.='						<div style="width: 100%; float: left; padding-left:10px;">         	
							 			   	<div style="padding:10px ; width: 20%; height: 19px; line-height: 19px; float: left;">'.date('d-m-Y',$data['created']).'</div>
							               	<div style="padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">'.$data['order_id_masked'].'</div>
							               	<div style=" padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">'.number_format($data['total_sum']/100, 2,',', '.').' &euro;</div>
							               	<div style=" padding:10px ; width: 20%; float: left; height: 19px; line-height: 19px;">CH</div>
							         	</div>';			            	
						            }
						        }
		$q4html.='			<div style="padding:10px ; font-weight: bold; width: 40%; height: 19px; line-height: 19px; float: left;">Total</div>
							<div style="padding:10px ; font-weight: bold; width: 20%; height: 19px; line-height: 19px; float: left;">'.number_format($total_fourth/100, 2,',', '.').' &euro;</div>
							</div>
					   </body>
					</html>';

		$pdfFilePath = "Q4 - Mwst Abrechnung ".$year.".pdf";
        $this->load->library('m_pdf');
        $this->m_pdf->pdf->useOnlyCoreFonts = true;    // false is default
		//$this->m_pdf->pdf->SetProtection(array('print'));
		$this->m_pdf->pdf->SetTitle("Castleevents Title");
		$this->m_pdf->pdf->SetAuthor("Author");
		/*$this->m_pdf->pdf->SetWatermarkText("Castleevents.com");
		$this->m_pdf->pdf->showWatermarkText = true;
		$this->m_pdf->pdf->watermark_font = 'DejaVuSansCondensed';
		$this->m_pdf->pdf->watermarkTextAlpha = 0.1;*/
		$this->m_pdf->pdf->SetDisplayMode('fullpage'); 
		$this->m_pdf->pdf->WriteHTML($q4html);
		$this->m_pdf->pdf->Output($pdfFilePath, "D");  
        die;
        /*************************Q24 PDF*************************/
	}
}