<?php
define('_IN_JOHNCMS', 1);
require_once('../incfiles/core.php');
$set_znak = unserialize($set['znak']);

////////////////////////////////////////////////////////////
// Ограничиваем доступ к знакомствам                      //
////////////////////////////////////////////////////////////
$sql = mysql_query("select * from users where id='$user_id'");
$row = mysql_fetch_assoc($sql);
$error = '';
if (!$set['mod_znak'] && $rights < 7)
    $error = 'Знакомства закрыты';
elseif ($set['mod_znak'] == 1 && !$user_id)
    $error = 'Доступ к знакомствам открыт только <a href="../login.php">авторизованным</a> посетителям';
if ($error)
{
    require_once('../incfiles/head.php');
    echo '<div class="rmenu">' . $error . '</div>';
    require_once('../incfiles/end.php');
    exit;
}

$headmod = $id ? 'znak,' . $id : 'znak';
// Заголовки Знакомств
if (empty($id))
{
    $textl = 'Знакомства';
}
require_once('../incfiles/head.php');
    if($_POST['new_poisk'] == 'new'){
        unset($_SESSION['sex']);
        unset($_SESSION['age_ot']);
        unset($_SESSION['age_do']);
        unset($_SESSION['live']);
        unset($_SESSION['photo']);
        unset($_SESSION['online']);
        unset($_SESSION['new']);
    }
    if(!empty($_POST['sex'])) $_SESSION['sex'] = htmlspecialchars(mysql_escape_string(trim($_POST['sex'])));
    if(!empty($_POST['age_ot'])) $_SESSION['age_ot'] = htmlspecialchars(mysql_escape_string(trim($_POST['age_ot'])));
    if(!empty($_POST['age_do'])) $_SESSION['age_do'] = htmlspecialchars(mysql_escape_string(trim($_POST['age_do'])));
    if(!empty($_POST['live'])) $_SESSION['live'] = htmlspecialchars(mysql_escape_string(trim($_POST['live'])));
    if(!empty($_POST['photo'])) $_SESSION['photo'] = htmlspecialchars(mysql_escape_string(trim($_POST['photo'])));
    if(!empty($_POST['online'])) $_SESSION['online'] = htmlspecialchars(mysql_escape_string(trim($_POST['online'])));
    if(!empty($_POST['new'])) $_SESSION['new'] = htmlspecialchars(mysql_escape_string(trim($_POST['new'])));
    if ($_SESSION['age_ot'] > $_SESSION['age_do'])
        $error = $error . 'Неверно указан диапазон возрастов!<br/>';
    if (empty($error)) {
        
    } else {
        echo '<div class="rmenu"><p><b>ОШИБКА!</b><br />' . $error . '</p></div>';
    }
    $poisk_set = '';
    if(!empty($_SESSION['online']) && $_SESSION['online'] = 1){
        $poisk_set .= " AND `lastdate` > '" . ($realtime - 300) . "'";
    }
    if(!empty($_SESSION['new']) && $_SESSION['new'] = 1){
        $poisk_set .= " AND `datereg` > '" . ($realtime - 86400) . "'";
    }        
    if(!empty($_SESSION['age_ot']) && !empty($_SESSION['age_do'])) $poisk_set .= " AND `age` >= '".$_SESSION['age_ot']."' AND `age` <= '".$_SESSION['age_do']."' ";
    if($_SESSION['sex'] == 'm') $poisk_set .= " AND sex = 'm' "; else $poisk_set .= " AND sex = 'zh' ";
    if(!empty($_SESSION['live'])) $poisk_set .= " AND live LIKE  '".$_SESSION['live']."' ";
    if($_SESSION['photo'] == 1) $poisk_set .= " AND ava ='1' ";
    $del = 0;
    $req = mysql_query("SELECT `id`, `name`, `sex`, `lastdate`, `datereg`, `statusik`, `statusik_img`, `rights`, `ip`, `browser`, `rights` FROM `users` WHERE `preg` = 1 ".$poisk_set." ORDER BY `datereg` DESC LIMIT $start, $kmess");
    while ($res = mysql_fetch_assoc($req)) {
        echo ($i % 2) ? '<div class="list2">' : '<div class="list1">';
        echo show_user($res, 1, (($rights > 1) ? 2 : 0)) . '</div>';
        ++$i;
    }
    $req = mysql_query("SELECT id FROM `users` WHERE `preg` = 1 ".$poisk_set."");
    $total = mysql_num_rows($req);
    echo '<div class="phdr">Всего: ' . $total . '</div><p>';
    if ($total > $kmess) {
        echo '<p>' . pagenav('poisk.php?', $start, $total, $kmess) . '</p>';
        echo '<p><form action="poisk.php" method="post"><input type="text" name="page" size="2"/><input type="submit" value="К странице &gt;&gt;"/></form></p>';
    }
    echo '</p>';
    echo '<div class="ffmenu"><a href="index.php">Назад</a></div>';

require_once("../incfiles/end.php");
?>