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

class Hotshot extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->model('common_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 *,count(*) as count FROM `like_likes` where identifier like 'profile%' group by `identifier` ORDER by count desc";
		$res = $this->db->query($sql);
		$receive_hotshot = $res->result_array();
		$arr=array();
		if(count($receive_hotshot)>0)
		{
			foreach ($receive_hotshot as $key => $value) {
				$g_user= explode(':',$value['identifier']);
				$g_userId = 0;
				if(!empty($g_user) && count($g_user)>1)
				{
					$g_userId = $g_user[1];
				}
				$sqlUser = "SELECT *,feu_userdetails.user_id from feu_userdetails join usr_users on usr_users.id = feu_userdetails.user_id join sys_files on sys_files.id = feu_userdetails.avatar_file_id where filename>0 and username!='' and feu_userdetails.user_id = ".$g_userId;
				$resUser = $this->db->query($sqlUser);
				//echo $this->db->last_query();
				$user_details = $resUser->row_array();
				$receive_hotshot[$key]['user_id'] = $user_details['user_id'];
				$receive_hotshot[$key]['email'] = $user_details['email'];
				$receive_hotshot[$key]['dob_lady'] = $user_details['dob_lady'];
				$receive_hotshot[$key]['dob_gentleman'] = $user_details['dob_gentleman'];
				$receive_hotshot[$key]['username'] = $user_details['username'];
				$receive_hotshot[$key]['extension'] = $user_details['extension'];
				$receive_hotshot[$key]['filename'] = $user_details['filename'];
				$receive_hotshot[$key]['path'] = $user_details['path'];

				$ugalsql = $this->common_model->getAllMultipleJoin('ugal_images',array('ugal_images.user_id'=>$g_userId,'filename !='=>''),array(array('sys_files','sys_files.id = ugal_images.file_id')),'sys_files.id DESC') ;
				$receive_hotshot[$key]['images'] = count($ugalsql);
			}
		}
		//pr($receive_hotshot);
		$content_data['receive_hotshot'] = $receive_hotshot;
		$data['content'] = $this->load->view('admin/hotshot/list', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function picture(){
		$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 *,count(*) as count FROM `like_likes` where identifier like 'picture%' group by `identifier` ORDER by count desc limit 100";
		$res = $this->db->query($sql);
		$receive_hotshot = $res->result_array();
		$arr=array();
		if(count($receive_hotshot)>0)
		{
			foreach ($receive_hotshot as $key => $value) {
				$g_user= explode(':',$value['identifier']);
				$g_userId = 0;
				if(!empty($g_user) && count($g_user)>1)
				{
					$g_userId = $g_user[1];
				}
				$sqlUser = "SELECT *,feu_userdetails.user_id from feu_userdetails join usr_users on usr_users.id = feu_userdetails.user_id join sys_files on sys_files.id = feu_userdetails.avatar_file_id where filename>0 and username!='' and sys_files.id = ".$g_userId;
				$resUser = $this->db->query($sqlUser);
				//echo $this->db->last_query();
				$user_details = $resUser->row_array();
				$receive_hotshot[$key]['user_id'] = $user_details['user_id'];
				$receive_hotshot[$key]['email'] = $user_details['email'];
				$receive_hotshot[$key]['dob_lady'] = $user_details['dob_lady'];
				$receive_hotshot[$key]['dob_gentleman'] = $user_details['dob_gentleman'];
				$receive_hotshot[$key]['username'] = $user_details['username'];
				$receive_hotshot[$key]['extension'] = $user_details['extension'];
				$receive_hotshot[$key]['filename'] = $user_details['filename'];
				$receive_hotshot[$key]['path'] = $user_details['path'];

				$ugalsql = $this->common_model->getAllMultipleJoin('ugal_images',array('ugal_images.user_id'=>$g_userId,'filename !='=>''),array(array('sys_files','sys_files.id = ugal_images.file_id')),'sys_files.id DESC') ;
				$receive_hotshot[$key]['images'] = count($ugalsql);
			}
		}
		pr($receive_hotshot);
		$content_data['receive_hotshot'] = $receive_hotshot;
		$data['content'] = $this->load->view('admin/hotshot/picture', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}*/
	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 *,count(*) as count,feu_userdetails.user_id from notification join feu_userdetails on notification.to_id = feu_userdetails.user_id join sys_files on sys_files.id = feu_userdetails.avatar_file_id join usr_users on usr_users.id = feu_userdetails.user_id where type=8 group by notification.to_id order by count DESC limit 100";
		$res = $this->db->query($sql);
		$receive_hotshot = $res->result_array();
		if(count($receive_hotshot)>0)
		{
			foreach ($receive_hotshot as $key => $value) {
				$ugalsql = $this->common_model->getAllMultipleJoin('ugal_images',array('ugal_images.user_id'=>$value['user_id'],'filename !='=>''),array(array('sys_files','sys_files.id = ugal_images.file_id')),'sys_files.id DESC') ;
				$receive_hotshot[$key]['images'] = count($ugalsql);
				$userParticipation = $this->common_model->getAllMultipleJoin('shop_orders',array('shop_carts.user_id'=>$value['user_id'],'payed'=>1,'shop_orders.is_booking'=>1,'shop_booking_details.event_id >'=>0),array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_booking_details','shop_booking_details.cart_id = shop_carts.id'),array('evt_events','evt_events.id = shop_booking_details.event_id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'shop_carts.created DESC','*,evt_events.alias','shop_booking_details.cart_id');
        		$userParticipationOld = $this->common_model->getAllMultipleJoin('shop_orders',array('shop_carts.user_id'=>$value['user_id'],'payed'=>1,'shop_articles_carts.event_id >'=>0),array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('evt_events','evt_events.id = shop_articles_carts.event_id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'shop_carts.created DESC','','shop_articles_carts.event_id');
				$attend = 0;
				if(count($userParticipation)>0)
				{
					$attend = $attend + count($userParticipation);
				}
				if(count($userParticipationOld)>0)
				{
					$attend = $attend + count($userParticipationOld);
				}
				$receive_hotshot[$key]['attend'] = $attend;
			}
		}
		//pr($receive_hotshot);
		$content_data['receive_hotshot'] = $receive_hotshot;
		$data['content'] = $this->load->view('admin/hotshot/list', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function picture(){
		$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 *,count(*) as count,feu_userdetails.user_id from notification join feu_userdetails on notification.to_id = feu_userdetails.user_id join sys_files on sys_files.id = feu_userdetails.avatar_file_id join usr_users on usr_users.id = feu_userdetails.user_id where type=9 group by notification.to_id order by count DESC limit 100";
		$res = $this->db->query($sql);
		$receive_hotshot = $res->result_array();
		if(count($receive_hotshot)>0)
		{
			foreach ($receive_hotshot as $key => $value) {
				$ugalsql = $this->common_model->getAllMultipleJoin('ugal_images',array('ugal_images.user_id'=>$value['user_id'],'filename !='=>''),array(array('sys_files','sys_files.id = ugal_images.file_id')),'sys_files.id DESC') ;
				$receive_hotshot[$key]['images'] = count($ugalsql);
				$userParticipation = $this->common_model->getAllMultipleJoin('shop_orders',array('shop_carts.user_id'=>$value['user_id'],'payed'=>1,'shop_orders.is_booking'=>1,'shop_booking_details.event_id >'=>0),array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_booking_details','shop_booking_details.cart_id = shop_carts.id'),array('evt_events','evt_events.id = shop_booking_details.event_id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'shop_carts.created DESC','*,evt_events.alias','shop_booking_details.cart_id');
        		$userParticipationOld = $this->common_model->getAllMultipleJoin('shop_orders',array('shop_carts.user_id'=>$value['user_id'],'payed'=>1,'shop_articles_carts.event_id >'=>0),array(array('shop_carts','shop_carts.id = shop_orders.cart_id'),array('shop_articles_carts','shop_articles_carts.cart_id = shop_carts.id'),array('evt_events','evt_events.id = shop_articles_carts.event_id'),array('evt_language_values','evt_events.id = evt_language_values.event_id')),'shop_carts.created DESC','','shop_articles_carts.event_id');
				$attend = 0;
				if(count($userParticipation)>0)
				{
					$attend = $attend + count($userParticipation);
				}
				if(count($userParticipationOld)>0)
				{
					$attend = $attend + count($userParticipationOld);
				}
				$receive_hotshot[$key]['attend'] = $attend;
			}
		}
		//pr($receive_hotshot);
		$content_data['receive_hotshot'] = $receive_hotshot;
		$data['content'] = $this->load->view('admin/hotshot/picture', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
}