<?
include_once 'sys/inc/start.php';
include_once 'sys/inc/compress.php';
include_once 'sys/inc/sess.php';
include_once 'sys/inc/home.php';
include_once 'sys/inc/settings.php';
include_once 'sys/inc/db_connect.php';
include_once 'sys/inc/ipua.php';
include_once 'sys/inc/fnc.php';
include_once 'sys/inc/user.php';

$set['title']='Поиск анкет'; // заголовок страницы
include_once 'sys/inc/thead.php';
title();
aut();











################## go поиск в базе ##################

if (preg_match('#[^A-zА-я0-9 _\-\.,]#ui',$_POST['pol']))$err[]='Используются запрещенные символы';

else
{

$pol=NULL;
if (isset($_SESSION['pol']))$pol=$_SESSION['pol'];
if (isset($_POST['pol']))$pol=$_POST['pol'];
$_SESSION['pol']=$pol;
$pol=ereg_replace("( ){1,}","",$pol);}



if (preg_match('#[^A-zА-я0-9 _\-\.,]#ui',$_POST['ank_city']))$err[]='Используются запрещенные символы';


else
{
$ank_city=NULL;
if (isset($_SESSION['ank_city']))$ank_city=esc(stripcslashes(htmlspecialchars($_SESSION['ank_city'])));
if (isset($_POST['ank_city']))$ank_city=esc(stripcslashes(htmlspecialchars($_POST['ank_city'])));
$_SESSION['ank_city']=$ank_city;
$ank_city=ereg_replace("( ){1,}","",$ank_city);}

if (preg_match('#[^A-zА-я0-9 _\-\.,]#ui',$_POST['age']))$err[]='Используются запрещенные символы';

else
{
$age=NULL;
if (isset($_SESSION['age']))$age=esc(stripcslashes(htmlspecialchars($_SESSION['age'])));
if (isset($_POST['age']))$age=esc(stripcslashes(htmlspecialchars($_POST['age'])));
$_SESSION['age']=$age;
$age=ereg_replace("( ){1,}","",$age);}


if (isset($_GET['go']) && $ank_city!=NULL)
{
$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `pol` = '".$pol."' AND `ank_city` like '%".mysql_escape_string($ank_city)."%'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];

if ($k_post==0)
echo "Извините, по Вашему запросу ничего не найдено";


if (preg_match('#[^A-zА-я0-9 _\-\.,]#ui',$_POST['ank_city']))$err[]='Используются запрещенные символы';

$q=mysql_query("SELECT * FROM `user` WHERE `pol` = '".$pol."' AND `ank_city` like '%".mysql_escape_string($ank_city)."%' ORDER BY rating DESC LIMIT $start, $set[p_str]");


while ($ank = mysql_fetch_array($q))
{
if($num==1){
echo "<div class='rowup'>\n";
echo " \n";
echo "<a href='/info.php?id=$ank[id]'><span style=\"color:$ank[color]\">$ank[nick]</span></a>\n";

echo "<br />\n";
if ($ank['pol']==1)echo "<span class=\"ank_d\">(Муж)</span>\n"; else echo "<span class=\"ank_d\">(Жен)</span> \n";

if ($ank['ank_d_r']!=NULL && $ank['ank_m_r']!=NULL && $ank['ank_g_r']!=NULL){
$ank['ank_age']=date("Y")-$ank['ank_g_r'];
if (date("n")<$ank['ank_m_r'])$ank['ank_age']=$ank['ank_age']-1;
elseif (date("n")==$ank['ank_m_r']&& date("j")<$ank['ank_d_r'])$ank['ank_age']=$ank['ank_age']-1;
echo "<span class=\"ank_d\">$ank[ank_age] лет</span>\n";
}

if ($ank['ank_city']!=NULL)echo ", <span class=\"ank_d\">$ank[ank_city]</span><br />\n";
echo "</div>\n";
$num=0;
}else{ 
echo "<div class='rowdown'>\n";
echo "\n";
echo "".online($ank['id'])."<a href='/info.php?id=$ank[id]'><span style=\"color:$ank[color]\">$ank[nick]</span></a> \n";

echo "<br />\n";
if ($ank['pol']==1)echo "<span class=\"ank_d\">(Муж)</span>\n"; else echo "<span class=\"ank_d\">(Жен)</span> \n";

if ($ank['ank_d_r']!=NULL && $ank['ank_m_r']!=NULL && $ank['ank_g_r']!=NULL){
$ank['ank_age']=date("Y")-$ank['ank_g_r'];
if (date("n")<$ank['ank_m_r'])$ank['ank_age']=$ank['ank_age']-1;
elseif (date("n")==$ank['ank_m_r']&& date("j")<$ank['ank_d_r'])$ank['ank_age']=$ank['ank_age']-1;
echo "<span class=\"ank_d\">$ank[ank_age] лет</span>\n";
}

if ($ank['ank_city']!=NULL)echo ", <span class=\"ank_d\">$ank[ank_city]</span><br />\n";
echo "</div>\n";
$num=1;}
}



if ($k_page>1)str("search.php?go&amp;",$k_page,$page); // Вывод страниц
echo "<a href=\"search.php\" title=\"Поиск половинки\">Новый поиск</a>";
include_once 'sys/inc/tfoot.php';
}
else          /////////// формы ввода критериев поиска             /////////// формы ввода критериев поиска
echo "<div class='rowup'>";

echo "<form method=\"post\" action=\"search.php?go\">";
//echo "<br />";
echo "Ищу<br />\n";
echo "<select name=\"pol\">\r\n";
echo "<option value=\"1\">Парня</option>\r\n";
echo "<option value=\"0\">Девушку</option>\r\n";
echo "</select><br />\r\n";

echo "";

echo "Город<br/>";
echo "<input type=\"text\" name=\"ank_city\" value=\"$ank_city\"/><br />\r\n";



echo "<br>C фото:<input type=\"checkbox\" name=\"\" /><br />\r\n";

//echo "<input type=\"checkbox\" name=\"$online\" />Онлайн<br />\r\n";

echo "<br />";

echo "<input type=\"submit\" value=\"Найти\" />";
echo "</form>\n";
echo "</div>\n";
////////////////////////////////////////////////////////////

echo" <a href='/women.php'>ТОП-100 Девушки</a></b><br>";



if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user`"), 0) == 0) {
	echo '<div class="main_menu">Пользователей нет</div>';
} else {

	if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `pol` = '0'"), 0) == 0) {
          echo '<div class="main_menu">Девушек нет</div>';
	} else {
		
		
		$female = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `pol` = '0' ORDER BY `rating` DESC LIMIT 1"));
		
		if ($set['set_show_icon']==1){
}
elseif ($set['set_show_icon']==1)
echo "  </td>\n";
{
echo "  <td class=''>\n";
if(is_file("sys/avatar/$female[id].gif")){
echo "<img src='/sys/avatar/$female[id].gif' align='left' width='35' height='35' alt='' style='margin-right:4px;border-right:0px solid #99ccff'>\n";
}else if(is_file("sys/avatar/$female[id].jpg")){
echo "<img src='/sys/avatar/$female[id].jpg' align='left' width='35' height='35' alt='' style='margin-right:4px;border-right:0px solid #99ccff'>\n";
}else if(is_file("sys/avatar/$female[id].png")){
echo "<img src='/sys/avatar/$female[id].png' align='left' width='35' height='35' alt='' style='margin-right:4px;border-right:0px solid #99ccff'>\n";
}else{
echo '<img src="/sys/avatar/0.png" align="left" width="35" height="35" alt="" style="margin-right:4px;border-right:0px solid #99ccff">';}
}
		
echo "<a href='/info.php?id=$female[id]'><span style=\"color:$female[color]\">$female[nick]</span></b></a>,";

if ($female['ank_d_r']!=NULL && $female['ank_m_r']!=NULL && $female['ank_g_r']!=NULL){
$female['ank_age']=date("Y")-$female['ank_g_r'];
if (date("n")<$female['ank_m_r'])$female['ank_age']=$female['ank_age']-1;
elseif (date("n")==$female['ank_m_r']&& date("j")<$female['ank_d_r'])$female['ank_age']=$female['ank_age']-1;
echo "$female[ank_age] </span>\n";
echo "\n";
}



echo "".online($female['id'])."<br />";

if ($female['ank_city']!=NULL)echo "$female[ank_city]</span> \n";















else
echo "Город не указан \n";

if ($female['ank_strana']==Украина)echo "<img src='style/usr/ua.png' alt=''><br />";
if ($female['ank_strana']==Россия)echo "<img src='style/usr/ru.png' alt=''><br />";
if ($female['ank_strana']==Узбекистан)echo "<img src='style/usr/uz.png' alt=''><br />";
if ($female['ank_strana']==Казахстан)echo "<img src='style/usr/kz.png' alt=''><br />";
if ($female['ank_strana']==$strana)echo "<img src='style/usr/dr.png' alt=''><br />";
if ($female['ank_strana']==Белоруссия)echo "<img src='style/usr/by.png' alt=''><br />";
if ($female['ank_strana']==Азербайджан)echo "<img src='style/usr/az.png' alt=''><br />";

echo "<hr>";
echo" <br><a href='/men.php'>ТОП-100 Парни</a></b><br>";

	}

	if (mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `pol` = '1'"), 0) == 0) {
          echo '<div class="main_menu">Парней нет</div>';
	} else {
		

		$male = mysql_fetch_array(mysql_query("SELECT * FROM `user` WHERE `pol` = '1' ORDER BY `rating` DESC LIMIT 1"));

		if ($set['set_show_icon']==1){
}
elseif ($set['set_show_icon']==1)
echo "  </td>\n";
{
echo "  <td class=''>\n";
if(is_file("sys/avatar/$male[id].gif")){
echo "<img src='/sys/avatar/$male[id].gif' align='left' width='35' height='35' alt='' style='margin-right:4px;border-right:0px solid #99ccff'>\n";
}else if(is_file("sys/avatar/$male[id].jpg")){
echo "<img src='/sys/avatar/$male[id].jpg' align='left' width='35' height='35' alt='' style='margin-right:4px;border-right:0px solid #99ccff'>\n";
}else if(is_file("sys/avatar/$male[id].png")){
echo "<img src='/sys/avatar/$male[id].png' align='left' width='35' height='35' alt='' style='margin-right:4px;border-right:0px solid #99ccff'>\n";
}else{
echo '<img src="/sys/avatar/0.png" align="left" width="35" height="35" alt="" style="margin-right:4px;border-right:0px solid #99ccff">';}
}

echo "<a href='/info.php?id=$male[id]'><span style=\"color:$male[color]\">$male[nick]</a></b></span>,";

if ($male['ank_d_r']!=NULL && $male['ank_m_r']!=NULL && $male['ank_g_r']!=NULL){
$male['ank_age']=date("Y")-$male['ank_g_r'];
if (date("n")<$male['ank_m_r'])$male['ank_age']=$male['ank_age']-1;
elseif (date("n")==$male['ank_m_r']&& date("j")<$male['ank_d_r'])$male['ank_age']=$male['ank_age']-1;
echo "$male[ank_age]</span>\n";
echo "\n";
}

echo "".online($male['id'])."<br />";

if ($male['ank_city']!=NULL)echo "$male[ank_city]</span> \n";
else
echo "Город не указан \n";


if ($male['ank_strana']==Украина)echo "<img src='style/usr/ua.png' alt=''><br />";
if ($male['ank_strana']==Россия)echo "<img src='style/usr/ru.png' alt=''><br />";
if ($male['ank_strana']==Узбекистан)echo "<img src='style/usr/uz.png' alt=''><br />";
if ($male['ank_strana']==Казахстан)echo "<img src='style/usr/kz.png' alt=''><br />";
if ($male['ank_strana']==$strana)echo "<img src='style/usr/dr.png' alt=''><br />";
if ($male['ank_strana']==Белоруссия)echo "<img src='style/usr/by.png' alt=''><br />";
if ($male['ank_strana']==Азербайджан)echo "<img src='style/usr/az.png' alt=''><br />";



echo "<hr>";




	}

}


echo" <br><a href='/users.php'>Новые пользователи ...</a>";






include_once 'sys/inc/tfoot.php';
?>