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

class Blacklist extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->model('common_model');
		$this->load->library('Utility');
		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 feu_userdetails.verified,feu_userdetails.user_id,usr_users.blacklist,feu_userdetails.username,usr_users.email,count(*) as count FROM `msg_conversations_users` left join usr_users on usr_users.id = msg_conversations_users.user_id left join feu_userdetails on feu_userdetails.user_id = usr_users.id GROUP by msg_conversations_users.user_id) as b WHERE b.count > 20 and username != '' and user_id != 11330 order by count DESC";
		$res = $this->db->query($sql);
		$blacklist = $res->result_array();
		$arr = array();
		//print_r($blacklist); die;
		if(!empty($blacklist))
		{
			$i= 0;
			foreach ($blacklist as $key => $value) {
				$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');
				if(count($userParticipation)>0 || count($userParticipationOld)>0 || $value['verified']==1)
				{
					//continue;
				}
				else
				{
					$arr[$i]['user_id'] = $value['user_id'];
					$arr[$i]['blacklist'] = $value['blacklist'];
					$arr[$i]['username'] = $value['username'];
					$arr[$i]['count'] = $value['count'];
				}
			$i++;	
			}
		}
		$content_data['blacklist'] = $arr;
		//print_r($content_data['blacklist']); die;
		$data['content'] = $this->load->view('admin/blacklist/list', $content_data, TRUE);
		$this->load->view('admin/layout', $data);
	}
	public function mark($user_id){
		$userId = base64_decode($user_id);
		$this->common_model->UpdateData('usr_users',array('blacklist'=>1),array('id'=>$userId));
		$userdata = $this->common_model->getAllRow('usr_users',array('user_id'=>$userId),array('feu_userdetails','feu_userdetails.user_id = usr_users.id'));
		//print_r($userdata); die;
		/**********************MAIL**************************/
		$to = $userdata['email'];
		//$to = 'sayan@digitalaptech.com';
		$sub = getAdminLang('Verify_your_account',$userdata['userlanguage']);
		$body=' <table cellspacing="0" cellpadding="0" border="0" align="center" bgcolor="#22222c" width="100%" style="max-width: 600px;">
	                    <tr>
	                       <td>
	                          <table cellspacing="0" cellpadding="0" border="0" width="100%">
	                             <tr>
	                                <td align="center" style="padding: 40px; font-family: sans-serif; font-size: 15px; mso-height-rule: exactly; line-height: 20px; color: #b3975b;">
	                                   <h2>'.getAdminLang('Hello',$userdata['userlanguage']).' <span style="text-transform:capitalize">'.$userdata['username'].'</span> </h2>
	                                </td>
	                             </tr>
	                             <tr>
	                                <td style="font-family: sans-serif; color: #fff; padding: 0px 40px 40px; font-size: 16px; line-height: 30px;">
	                                   <p>
	                                      '.getAdminLang('the_well_being_of_our_guests',$userdata['userlanguage']).'
	                                      <br/><br/>
	                                      '.getAdminLang('Therefore_it_is_our_concern_to_take_care',$userdata['userlanguage']).'
	                                      <br/>
	                                      '.getAdminLang('We_kindly_ask_you_to_verify_your_profile',$userdata['userlanguage']).'
	                                      <br/><br/>
	                                      '.getAdminLang('The_ability_to_send_and_receive_messages',$userdata['userlanguage']).'

	                                   </p>
	                                   <br>
	                                </td>
	                             </tr>
	                             <tr>
	                             	<td align="center" style="font-family: sans-serif; color: rgb(179, 151, 91); padding: 20px 40px; border-top: 1px solid rgb(79, 79, 79); background: rgb(19, 18, 24) none repeat scroll 0px 0px;">
	                             		'.getAdminLang('Best_regards',$userdata['userlanguage']).' <br>
	                             		<p style="margin:5px 0 0">'.getAdminLang('Your_team_of_castleevents',$userdata['userlanguage']).'</p> 
	                             	</td>
	                             </tr>
	                          </table>
	                       </td>
	                    </tr>
	                </table>';//echo $body; die;
		$mail_send = $this->utility->sendCIMail($to,$sub,$body);
		/**********************MAIL**************************/
		$this->utility->setMsg('The user mark as blacklisted','SUCCESS');	
		redirect(base_url().'admin/blacklist');
	}
}