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

class Ajax extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->model('common_model');
		$this->load->helper('text');
	}
	public function recomend_availabity()
	{ 
		$code = $this->input->post('code');
		//var_dump($username);
		if($code!='' && is_numeric($code))
		{
			$existcode = $this->common_model->getAll('usr_users',array('unique_code'=>$code));
			//echo $this->db->last_query();
			if(count($existcode)>0)
			{
				echo 1;
			}
			else
			{
				echo 2;
			}
		}
		else
		{
			echo 2;
		}
		exit;
	}
	public function getactivityusers(){
		$newsletterUsers = $this->common_model->getAll('newsletter_couple_lady','','','RAND()',0,2);
		
		$castleevents = $this->common_model->getAllRow('feu_userdetails',array('feu_userdetails.user_id'=>11330),array('sys_files','feu_userdetails.avatar_file_id = sys_files.id'));
		//pr($castleevents);
		$data = array();
		$data = $this->input->post('data');
		$users = explode(',', $data);
		$main_arr = array();
		$lady = array();
		$gent = array();
		$couple = array();
		if(count($newsletterUsers)>0 && count($users)<5)
		{
			foreach($newsletterUsers as $key=>$val)
			{
				if(!in_array($val['id'], $data))
				{	
					$lady = $this->common_model->getAllRowMultipleJoin('newsletter_couple_lady',array('newsletter_couple_lady.id'=>$val['id']),array(array('feu_userdetails','feu_userdetails.user_id = newsletter_couple_lady.lady'),array('feu_countries','feu_userdetails.country = feu_countries.country_code'),array('sys_files','feu_userdetails.avatar_file_id = sys_files.id')));
					$gent = $this->common_model->getAllRowMultipleJoin('newsletter_couple_lady',array('newsletter_couple_lady.id'=>$val['id']),array(array('feu_userdetails','feu_userdetails.user_id = newsletter_couple_lady.gentleman'),array('feu_countries','feu_userdetails.country = feu_countries.country_code'),array('sys_files','feu_userdetails.avatar_file_id = sys_files.id')));
					$couple = $this->common_model->getAllRowMultipleJoin('newsletter_couple_lady',array('newsletter_couple_lady.id'=>$val['id']),array(array('feu_userdetails','feu_userdetails.user_id = newsletter_couple_lady.couple'),array('feu_countries','feu_userdetails.country = feu_countries.country_code'),array('sys_files','feu_userdetails.avatar_file_id = sys_files.id')));
					
					if(count($lady)>0)
					{
						if($lady['user_id']>0)
						{
							array_push($main_arr, $lady);
						}
					}
					if(count($gent)>0)
					{
						if($gent['user_id']>0)
						{
							array_push($main_arr, $gent);
						}
					}
					if(count($couple)>0)
					{
						if($couple['user_id']>0)
						{
							array_push($main_arr, $couple);
						}
					}
				}
			}
		}
		else
		{
			array_push($main_arr, $castleevents);
		}
		shuffle($main_arr);
		$html = '';
		if(count($main_arr)>0){ 
        $html.= '<div>
                  	<img src="';
                  	if($main_arr[0]['filename']!='' && file_exists(FCPATH.'assets/userfiles/'.$main_arr[0]['path'].'/80/'.$main_arr[0]['filename'].'.'.$main_arr[0]['extension']))
                  	{ 
        $html.=   		base_url().'assets/userfiles/'.$main_arr[0]['path'].'/80/'.$main_arr[0]['filename'].'.'.$main_arr[0]['extension']; 
        			}
        			else
        			{
        $html.=			base_url().'assets/images/crown_log.svg';	
        			}
        $html.= 	'" width="80"><div class="notification_div">';
                    if(count($users)==5)
                    {
        $html.= 	'<p>Many more appealing and tasteful Couples, Ladies and also Gentleman waiting to get to know you after registration!</p>';            	
                    }
                    else
                    {
        $html.= 	' <h3>'.$main_arr[0]['username'].'</h3>
        			  <p>'.word_limiter($main_arr[0]['about'], 8).'</p>';
                    } 
        
        $html.= ' </div></div>';
        }
        echo $html.'|'.$main_arr[0]['user_id']; die;
	}
}
