<?
include 'config.php';
include 'func.php';

head();
aut();
ban();


mysql_query("UPDATE `profile` SET `online` = 'love' WHERE `id` = '".$id_session."'");

if ( empty($_POST['submit'])) header('Location: index.php');
    
    
    


$sex = num($_POST['sex']);

$age1 = num($_POST['age1']);
$age2 = num($_POST['age2']);

$cel = num($_POST['cel']);
$city = html($_POST['city']);
$vip = num($_POST['vip']);
$online = num($_POST['online']);

$cityinf = mysql_fetch_assoc(mysql_query("SELECT * FROM `geo_cities` WHERE `city_name` = '".html($city)."'"));



    
if ( !empty($city) ) {

    if ( $online == 0 )
    
    $query = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM `profile` WHERE `sex` = '".$sex."' AND `geo_city` = '".$cityinf['city_id']."' order by rating desc");
    else
    $query = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM `profile` WHERE `sex` = '".$sex."' AND `time` > '".time()."' AND `geo_city` = '".$cityinf['city_id']."' order by rating desc");

} else {
    
    if ( $online == 0 )
    $query = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM `profile` WHERE `sex` = '".$sex."' order by rating desc");
    else
    $query = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM `profile` WHERE `sex` = '".$sex."' AND `time` > '".time()."' order by rating desc");
   
}
   

echo head. '<b>Расширенный поиск</b>' . div . katalog;
echo 'Результаты поиска' . div . katalog;
$total = mysql_result(mysql_query('SELECT FOUND_ROWS()'), 0);
	if($total == 0)
	{
		echo 'Совпадений не найдено';
	}
	else
	{
	   
		while($row = mysql_fetch_assoc($query))
		{
			
			
			$user = mysql_fetch_assoc(mysql_query("SELECT * FROM `profile` WHERE `id` = ".$row['id'].""));
            
            if ( !empty($age1) AND !empty($age2) ) {
            if ( (age($user['d'], $user['m'], $user['g'])) >= $age1 AND (age($user['d'], $user['m'], $user['g'])) <= $age2 )
		
                
                if($user['upload_ava']){
                $ava = '<a href="profile.php?id='.$user['id'].'"><img src="resize.php?img=upload_ava/'.$user['upload_ava'].'&width=60&height" alt=""/></a>';
                } else {
                $ava = '<a href="profile.php?id='.$user['id'].'"><img src="resize.php?img=noava.png&width=60&height" alt=""/></a>';
                }
                echo $ava . '<br />';
                	echo ''.xstatus($user['xstatus'], $user['id']).' <a href="http://'.$_SERVER['HTTP_HOST'].'/'.$user['id'].'">'.$user['login'].'</a><br/> Возраст: '.age($user['d'], $user['m'], $user['g']) .'<hr>';   
            } else {
                
             
             if($user['upload_ava']){
                $ava = '<a href="profile.php?id='.$user['id'].'"><img src="resize.php?img=upload_ava/'.$user['upload_ava'].'&width=60&height" alt=""/></a>';
                } else {
                $ava = '<a href="profile.php?id='.$user['id'].'"><img src="resize.php?img=noava.png&width=60&height" alt=""/></a>';
                }
                echo $ava . '<br />';
                echo ''.xstatus($user['xstatus'], $user['id']).' <a href="http://'.$_SERVER['HTTP_HOST'].'/'.$user['id'].'">'.$user['login'].'</a><br/> Возраст: '.age($user['d'], $user['m'], $user['g']) .' <hr>';   
            }
		}

	}
echo div;

///////////////////////////////


navig();
foot();
?>