<?php
############################################################
# \-\-\-\-\-\-\     AzDG  - S C R I P T S    /-/-/-/-/-/-/ #
############################################################
# AzDGDatingMedium        Version 1.9.3                    #
# Written by              AzDG (support@azdg.com)          #
# Created 24/10/02        Last Modified 22/03/06           #
# Scripts Home:           http://www.azdg.com              #
############################################################
# File name               online.php                       #
# File purpose            Show online users                #
# File created by         AzDG <support@azdg.com>          #
############################################################
include_once 'include/config.inc.php';
include_once 'include/options.inc.php';
include_once 'include/security.inc.php';
include_once 'include/functions.inc.php';
include_once 'templates/'.C_TEMP.'/config.php';
IsSecure(C_ONLINE);
if(isset($set_cookies))
{

	function SetOnlineCookies($Const,$arr,$vname,$checkbox=null)
	{
		Global $$vname;
		if(isset($$vname))
		{
			$var = $$vname;
			if($checkbox == null)
			{
				if(IsAccess($Const) && is_numeric($var) && ($var >= 0) && ($var < sizeof($arr)))
				{
					setcookie(C_LOGIN_COOKIE.'on'.$vname, $var, time() + 86400 * C_COOKIE_LIFE);
				}
			}
			elseif($checkbox == 'num')
			{
				if(IsAccess($Const) && is_numeric($var))
				{
					setcookie(C_LOGIN_COOKIE.'on'.$vname, $var, time() + 86400 * C_COOKIE_LIFE);
				}
			}
			elseif($checkbox == 'text')
			{
				if(IsAccess($Const))
				{
					setcookie(C_LOGIN_COOKIE.'on'.$vname, $var, time() + 86400 * C_COOKIE_LIFE);
				}
			}
			else
			{
				if(IsAccess($Const) && ($var == 'on'))
				{
					setcookie(C_LOGIN_COOKIE.'on'.$vname, '1', time() + 86400 * C_COOKIE_LIFE);
				}
				else 
				{
					setcookie(C_LOGIN_COOKIE.'on'.$vname, '-1', time() + 86400 * C_COOKIE_LIFE);
				}
			}
		} else setcookie(C_LOGIN_COOKIE.'on'.$vname, '-1', time() + 86400 * C_COOKIE_LIFE);
	}
	SetOnlineCookies(C_ONLINE_GENDER,$wg,'gender');
	SetOnlineCookies(C_ONLINE_COUNTRY,$wcr,'country');
	SetOnlineCookies(C_ONLINE_CITY,null,'city','text');
	SetOnlineCookies(C_ONLINE_AGE,null,'agef','num');
	SetOnlineCookies(C_ONLINE_AGE,null,'aget','num');
	SetOnlineCookies(C_ONLINE_USERTYPE,$wpu,'usertype');
	SetOnlineCookies(C_ONLINE_PICTURE,null,'picture',True);
	include_once C_PATH.'/header.php';
	GoToURL(C_URL.'/online.php?l='.$l);
	printm($w[523]);
}
include_once C_PATH.'/header.php';

function GetOnlineCookies($Const,$arr,$vname,$checkbox=null)
{
	if(isset($_COOKIE[C_LOGIN_COOKIE.'on'.$vname]))
	{
		$var = $_COOKIE[C_LOGIN_COOKIE.'on'.$vname];
		if($checkbox == null)
		{
			if(IsAccess($Const) && isset($_COOKIE[C_LOGIN_COOKIE.'on'.$vname]) && is_numeric($_COOKIE[C_LOGIN_COOKIE.'on'.$vname]) && ($_COOKIE[C_LOGIN_COOKIE.'on'.$vname] >=0) && ($_COOKIE[C_LOGIN_COOKIE.'on'.$vname] < sizeof($arr)))
			{
				Return $_COOKIE[C_LOGIN_COOKIE.'on'.$vname];
			} else Return '-1';
		}
		elseif($checkbox == 'num')
		{
			if(IsAccess($Const) && isset($_COOKIE[C_LOGIN_COOKIE.'on'.$vname]) && is_numeric($_COOKIE[C_LOGIN_COOKIE.'on'.$vname]))
			{
				Return $_COOKIE[C_LOGIN_COOKIE.'on'.$vname];
			} else Return '-1';
		}
		elseif($checkbox == 'text')
		{
			if(IsAccess($Const) && isset($_COOKIE[C_LOGIN_COOKIE.'on'.$vname]))
			{
				Return cb($_COOKIE[C_LOGIN_COOKIE.'on'.$vname]);
			} else Return '-1';
		}
		else
		{
			if(IsAccess($Const) && isset($var) && ($var == '1'))
			{
				Return $_COOKIE[C_LOGIN_COOKIE.'on'.$vname];
			} else Return '-1';
		}
	}
}
$gender=GetOnlineCookies(C_ONLINE_GENDER,$wg,'gender');
$country=GetOnlineCookies(C_ONLINE_COUNTRY,$wcr,'country');
$city=GetOnlineCookies(C_ONLINE_CITY,null,'city','text');
$agef=GetOnlineCookies(C_ONLINE_AGE,null,'agef','num');
$aget=GetOnlineCookies(C_ONLINE_AGE,null,'aget','num');
$usertype=GetOnlineCookies(C_ONLINE_USERTYPE,$wpu,'usertype');
$picture=GetOnlineCookies(C_ONLINE_PICTURE,null,'picture',True);

if(file_exists(C_PATH.'/languages/'.$l.'/'.$l.'o.php')) include_once(C_PATH.'/languages/'.$l.'/'.$l.'o.php');
elseif(defined('C_USERLANG')) include_once(C_PATH.'/languages/'.C_USERLANG.'/'.C_USERLANG.'o.php');
else include_once(C_PATH.'/languages/default/defaulto.php');

define('USERS_ONLINE_VALUE',ONLINE_USERS);
define('USERNAME',$w[118]);
define('PURPOSES',$w[119]);
define('AGE',$w[120]);
define('COUNTRY',$w[121]);
define('CITY',$w[122]);
define('PAGE',$w[443]);
define('PHOTO',$w[87]);

$str=$color='';
$ids=$names=$genders=$purposes=$ages=$countries=$cities=$pictures=$colors=$pages=array();
$step = C_ONLINE_USERS_NUM;
if (!isset($from) || !is_numeric($from)) $from = 0;

$mgender=($gender < 1) ? '' : " AND t2.gender = '".$gender."'";
$mcountry=($country < 1) ? '' : " AND t2.country = '".$country."'";
$mcity=(trim($city) == '') ? '' : " AND t2.city = '".cb($city)."'";
$magef=($agef < 1) ? '' : " AND t2.birthday <= DATE_SUB(NOW(), INTERVAL ".$agef." YEAR)";
$maget=($aget < 1) ? '' : " AND t2.birthday >= DATE_SUB(NOW(), INTERVAL ".($aget+1)." YEAR)";
$musertype=($usertype < 1) ? '' : " AND t2.req >= '".$usertype."'";
$mpicture=($picture < 1) ? '' : " AND t2.files != ''";

$sql_dump = $mgender.$mcountry.$mcity.$magef.$maget.$musertype.$mpicture;

$tmp0=mysql_query("SELECT count(*) as total FROM ".C_MYSQL_ONLINE_USERS." as t1, ".C_MYSQL_MEMBERS_MAIN." as t2 WHERE t1.user = t2.id AND t2.status >= '7' AND t2.hide='0'".$sql_dump) or die(mysql_error());
$cnt=mysql_fetch_assoc($tmp0);
$count=$cnt['total'];#die($count);
$tmp=mysql_query("SELECT DISTINCT t1.user, t1.upage, t2.* FROM ".C_MYSQL_ONLINE_USERS." as t1, ".C_MYSQL_MEMBERS_MAIN." as t2 WHERE t1.user = t2.id AND t2.status >= '7' AND t2.hide='0'".$sql_dump." order by t1.utime desc limit ".$from.",".$step) or die(mysql_error());
$color='';
while($i=mysql_fetch_array($tmp)) {
	$color = ($color == COLOR4) ? COLOR3 : COLOR4;
	$colors[] = $color;
	$ids[]=$i['id'];
	$names[] = username($i['id'],$i['username'],$i['fname'],$i['lname']);
	$purposes[]=$wg[$i['gender']].' '.arr2val($wp, $i['purposes']);
	if($i['files'] == '') $pictures[] = $w[111];
	else {
		if(C_SEARCH_PHOTO) {
			$photo=ShowPic(not_empty($i['files'],$i['id']));
			$link = (C_SEARCH_PHOTO_LINK) ? C_URL.'/view.php?l='.$l.'&id='.$i['id'] : $photo.ShowPictureBigger();
			$pictures[]='<a href="'.$link.'" target="_blank"><img src="'.$photo.'" border="'.C_IMG_BRDR.'" width="'.C_SEARCH_PHOTO_WIDTH.'"></a>';
		} else $pictures[] = $w[112];
	}

	$ages[]=abs(mysql2data($i['birthday'],1));
	$countries[]=$wcr[$i['country']];
	$cities[]=$i['city'];$page='';reset($wo);
	while (list ($key, $val) = each ($wo)) {
		if(strpos($i['upage'], $key))
		{
			$page=$val;
			break;
		}
	}
	$pages[] = ($page == '') ? '' : $page;
	#$pages[] = ($page == '') ? $i['page'] : $page;
}
$param='l='.$l;
$colspan=8;
	define('GENDER',$w[57]);
	$Value='';$p=0;while(isset($wg[$p])) {$str=(($gender!='Nothing') && ($gender == $p)) ? ' selected' : '';$Value .= '<option value="'.$p.'"'.$str.'>'.$wg[$p];$p++;}
	define('GENDER_VALUE',$Value);
	$Value='';
	$p = 0;asort($wcr);reset($wcr);while (list ($p, $val) = each ($wcr)) {$str=(($country!='Nothing') && ($country == $p)) ? ' selected' : '';$Value .= '<option value="'.$p.'"'.$str.'>'.$wcr[$p];}
	define('COUNTRY_VALUE',$Value);
	define('CITY_VALUE',$city);
	define('AGEF_VALUE',$agef);
	define('AGET_VALUE',$aget);
	define('USERTYPE',$w[270]);
	$Value='';$p=0;while(isset($wpu[$p])) {$str=(($usertype!='Nothing') && ($usertype == $p)) ? ' selected' : '';$Value .= '<option value="'.$p.'"'.$str.'>'.$wpu[$p];$p++;}
	define('USERTYPE_VALUE',$Value);
	define('SEARCH_USERS_WITH',$w[143]);
	$str= ($picture > 0 ) ? ' checked' : '';
	define('PHOTO_CHECKED',$str);
	
	
	if(IsAccess(C_ONLINE_GENDER) || IsAccess(C_ONLINE_USERTYPE) || IsAccess(C_ONLINE_PICTURE)) define('SHOW_FORM','1');
	else  define('SHOW_FORM','0');
	if(IsAccess(C_ONLINE_GENDER)) define('SHOW_GENDER','1');
	else  define('SHOW_GENDER','0');
	if(IsAccess(C_ONLINE_COUNTRY)) define('SHOW_COUNTRY','1');
	else  define('SHOW_COUNTRY','0');
	if(IsAccess(C_ONLINE_CITY)) define('SHOW_CITY','1');
	else  define('SHOW_CITY','0');
	if(IsAccess(C_ONLINE_AGE)) define('SHOW_AGE','1');
	else  define('SHOW_AGE','0');
	if(IsAccess(C_ONLINE_USERTYPE)) define('SHOW_USERTYPE','1');
	else  define('SHOW_USERTYPE','0');
	if(IsAccess(C_ONLINE_PICTURE)) define('SHOW_PICTURE','1');
	else  define('SHOW_PICTURE','0');
	
$hidden_users = online_users() - $count;
if($hidden_users){
define('HAVE_HIDDEN_USERS',True);
if(strlen($sql_dump) == '0') define('HIDDEN_USERS',template($w[746],array($hidden_users)));
else define('HIDDEN_USERS',template($w[752],array($hidden_users)));
} 
else {define('HAVE_HIDDEN_USERS',False);define('HIDDEN_USERS','');}
	
define('PAGES',pages($from,$step,$count,$param,$colspan));
define('SEARCH_RESULTS',search_results($from,$step,$count,IsAccess(C_SHOW_SEARCH_COUNT),USERS_ONLINE));
$p=0;


include_once C_PATH.'/templates/'.C_TEMP.'/online.php';

include_once C_PATH.'/footer.php';

?>