<?php
#==============================================================================================#
#                                   Name  :  Imperial CHAT                                     #
#                               Made by  :  MaZaFaKa (___хакер___)                             #
#                                  MODED :  vipsds  (   BOT  )                                 #
#                                  ICQ  :  350502220 (vipsds)                                  #
#                                E-mai :  vipsds@wapnn.org                                     #
# По всем вопросам и дополнительным модам обращайтесь на выше указанные данные                 #
#==============================================================================================#
error_reporting(0);
include('start.php');
include("config.php");
include("./includes/".$ver."/banned");

list($msec, $sec) = explode(chr(32), microtime());
$headtime = $sec + $msec;

$ref = rand(1000, 9999);

///////////////////////////////////////////////////////////////////////////////
$_POST['nickname']=trim(htmlspecialchars(mysql_escape_string($_POST['nickname'])));
///////////////////////////////////////////////////////////////////////////////

if(isset($_POST['action']))
{
$ttl="Результаты поиска";
}
else
{
$ttl= "Найти пользователя";
}
switch($ver)
{
////////////////////////////////////////////////////////
//WML VERSION
////////////////////////////////////////////////////////
case 'wml':
header ("Content-type:text/vnd.wap.wml; charset=utf-8");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must-relative");

//AUTH
$id = intval($_SESSION['id']);
$password = mysql_escape_string($_SESSION['password']);
$q = mysql_query("SELECT `level` FROM `chat_users` WHERE `id` = '".$id."' AND `password` = '".md5($password)."';");

if(mysql_num_rows($q) == 0)
{
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.3//EN\" \"http://www.wapforum.org/DTD/wml13.dtd\"><wml>\n";
echo "<card title=\"ERROR\" ontimer=\"/wml\"><timer value=\"15\"/><p align=\"left\">\n";
echo "<small>Ошибка авторизации!<br/>\n";
echo "<br/>$wmlfoot";
list($msec, $sec) = explode(chr(32), microtime());
echo "[".round(($sec+$msec)-$headtime,5)."] sec<br/>\n";
echo "</small></p></card></wml>";
exit();
}
//END AUTH

$level = mysql_result($q, 0);

//ONLINE
$online = time() + 60;
$update = mysql_query("UPDATE `chat_users` SET `time` = '".$online."', `place` = 0, `ip` = '".getenv('REMOTE_ADDR')."', `ua` = '".htmlspecialchars(getenv('HTTP_USER_AGENT'))."' WHERE `id` = '".$id."';");
//END ONLINE
$error="";
$error1="";
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.3//EN\" \"http://www.wapforum.org/DTD/wml13.dtd\"><wml>\n";
echo "<card title=\"$ttl\"><p align=\"left\">\n";
if(!empty($_POST['nickname']) && strlen($_POST['nickname']) < 3)
{
 $error .= "Неправильный ник. Длина ника от 3-х до 15-и сиволов. Допустимые символы: русские ИЛИ английские буквы, цифры, пробел и знаки _@=![]()~*.~-. Недопустимо одновременное использование русских и английских букв.<br/>";
 echo $error;
}
echo "<input name=\"nickname$ref\" maxlength=\"20\" title=\"nickname\"/><br/>\n";
echo "<anchor>Найти<go href=\"/search/$ref/wml\" method=\"post\">\n";
echo "<postfield name=\"nickname\" value=\"$(nickname$ref)\"/>\n";
echo "<postfield name=\"action\" value=\"search\"/>\n";
echo "</go></anchor><br/>\n";
echo'Введите весь ник или его часть (не менее 3-х символов).<br/>';
if(empty($_POST[nickname]) and empty($error))
{
$error1 .= "Пользователи не найдены.<br/>";
echo $error1;
}
if(isset($_POST['action']) and !empty($_POST[nickname]) and empty($error))
{
$q=mysql_query('SELECT * FROM `chat_users` WHERE `nickname` LIKE "%'.$_POST[nickname].'%" LIMIT 10;');

}
if(mysql_num_rows($q) == 0 and empty($error))
{
$error1 .= "Пользователи не найдены.<br/>";
echo $error1;
}
else
{
while($poisk = mysql_fetch_array($q))
{
$uid = $poisk['id'];
$pass = $poisk['password'];
$ip = $poisk['ip'];
$ua = $poisk['ua'];
$kick = $poisk['kick'];
$moder = $poisk['moder'];
$reason = $poisk['reason'];
$name = $poisk['name'];
$site = $poisk['site'];
$sex = $poisk['sex'];
$city = $poisk['city'];
$mobile = $poisk['mobile'];
$email = $poisk['email'];
$birthday = $poisk['birthday'];
$about = $poisk['about'];
$posts = $poisk['posts'];
$lev = $poisk['level'];
$answers = $poisk['answers'];
$gbalans = $poisk['gbalans'];
$status = $poisk['status'];
$regdate = $poisk['regdate'];
$place = $poisk['place'];
$time = $poisk['time'];
//
//
$ltime = time() - ($time - 60);

	if($ltime < 60 && $ltime >= 0)
	{
	$var = "Секунд";
	}
	elseif($ltime < 3600 && $ltime > 60)
	{
	$new = $ltime;
	$ltime = $new/60;
	$var = "Минут";
	}
	elseif($ltime < 86400 && $ltime > 3600)
	{
	$new = $ltime;
	$ltime = $new/3600;
	$var = "Часов";
	}
	elseif($ltime > 86400)
	{
	$new = $ltime;
	$ltime = $new/86400;
	$var = "Дней";
	}

$ltime = round($ltime, 2);
	////////////////////////////////////////////////////////

//
$qq = mysql_query("SELECT `id` FROM `chat_users` WHERE `nickname` = '".$poisk[nickname]."';");
$usid = mysql_fetch_array($qq);
//
$qwho = mysql_query("SELECT `name`, `id` FROM `chat_rooms` WHERE `id` = '".$place."';");
$whoroom = mysql_fetch_array($qwho);
$who = "$whoroom[name]";
//
if(empty($whode))
{
$whode="<a href=\"/menu/wml\">Прихожая</a><br/>";
}
else
{
$whode="<a href=\"/room/rid/wml\">$who</a><br/>";
}
echo"• <a href=\"/info/".$usid[id]."/wml/inf\">$poisk[nickname]</a> ";


if($ltime > 0)
	{
	echo "Последний визит: $ltime $var назад<br/>\n";
	}
	else
	{
    echo "Сейчас в: $whode  \n";
	}
}
}

echo "<br/>• <a href=\"/menu/wml\">В прихожую</a><br/>\n";
echo "<br/>$wmlfoot";
list($msec, $sec) = explode(chr(32), microtime());
echo "[".round(($sec+$msec)-$headtime,5)."] sec<br/>\n";
echo "</p></card></wml>";
break;

////////////////////////////////////////////////////////
//HTML VERSION
////////////////////////////////////////////////////////
case 'html':
header ("Content-type: text/html; charset=utf-8");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must-relative");

//AUTH
$id = intval($_SESSION['id']);
$password = mysql_escape_string($_SESSION['password']);
$q = mysql_query("SELECT `level` FROM `chat_users` WHERE `id` = '".$id."' AND `password` = '".md5($password)."';");

if(mysql_num_rows($q) == 0)
{
echo "$css";
echo'<title>'.$ttl.'</title>';
echo'<div class="d3">Ошибка</div>';
echo "<div class=\"d5\">Ошибка авторизации!</div>\n";
echo'<div class="d3">';
echo"$sitefoot";
list($msec, $sec) = explode(chr(32), microtime());
echo "[".round(($sec+$msec)-$headtime,5)."] sec<br/>\n";
echo'</div>';
echo "</body></html>";
exit();
}
//END AUTH

$level = mysql_result($q, 0);

//ONLINE
$online = time() + 60;
$update = mysql_query("UPDATE `chat_users` SET `time` = '".$online."', `place` = 0, `ip` = '".getenv('REMOTE_ADDR')."', `ua` = '".htmlspecialchars(getenv('HTTP_USER_AGENT'))."' WHERE `id` = '".$id."';");
//END ONLINE
echo "$css";
echo'<title>'.$ttl.'</title>';
echo'<div class="d3">'.$ttl.'</div>';
$error="";
$error1="";
if(!empty($_POST[nickname]) && strlen($_POST[nickname]) < 3)
{
 $error .= "<div class=\"d5\">Неправильный ник. Длина ника от 3-х до 15-и сиволов. Допустимые символы: русские ИЛИ английские буквы, цифры, пробел и знаки _@=![]()~*.~-. Недопустимо одновременное использование русских и английских букв.</div>";
 echo $error;
}
echo'<div class="d1">';
echo "<form method=\"post\" action=\"/search/$ref/html\">\n";
echo "<input name=\"nickname\" maxlength=\"20\"/>";
echo "<input type=\"hidden\" name=\"action\" value=\"search\"/>";
echo "<input type=\"submit\" value=\"Найти\"/></form>\n";
echo'Введите весь ник или его часть (не менее 3-х символов).</div>';
if(empty($_POST[nickname]) and empty($error))
{
$error1 .= "Пользователи не найдены.";
echo $error1;
}
if(isset($_POST['action']) and !empty($_POST[nickname]) and empty($error))
{
$q=mysql_query('SELECT * FROM `chat_users` WHERE `nickname` LIKE "%'.$_POST[nickname].'%" LIMIT 10;');

}
if(mysql_num_rows($q) == 0 and empty($error))
{
$error1 .= "Пользователи не найдены.";
echo $error1;
}
else
{
while($poisk = mysql_fetch_array($q))
{
$uid = $poisk['id'];
$pass = $poisk['password'];
$ip = $poisk['ip'];
$ua = $poisk['ua'];
$kick = $poisk['kick'];
$moder = $poisk['moder'];
$reason = $poisk['reason'];
$name = $poisk['name'];
$site = $poisk['site'];
$sex = $poisk['sex'];
$city = $poisk['city'];
$mobile = $poisk['mobile'];
$email = $poisk['email'];
$birthday = $poisk['birthday'];
$about = $poisk['about'];
$posts = $poisk['posts'];
$lev = $poisk['level'];
$answers = $poisk['answers'];
$gbalans = $poisk['gbalans'];
$status = $poisk['status'];
$regdate = $poisk['regdate'];
$place = $poisk['place'];
$time = $poisk['time'];
//
//
$ltime = time() - ($time - 60);

	if($ltime < 60 && $ltime >= 0)
	{
	$var = "Секунд";
	}
	elseif($ltime < 3600 && $ltime > 60)
	{
	$new = $ltime;
	$ltime = $new/60;
	$var = "Минут";
	}
	elseif($ltime < 86400 && $ltime > 3600)
	{
	$new = $ltime;
	$ltime = $new/3600;
	$var = "Часов";
	}
	elseif($ltime > 86400)
	{
	$new = $ltime;
	$ltime = $new/86400;
	$var = "Дней";
	}

$ltime = round($ltime, 2);
	////////////////////////////////////////////////////////

//
$qq = mysql_query("SELECT `id` FROM `chat_users` WHERE `nickname` = '".$poisk[nickname]."';");
$usid = mysql_fetch_array($qq);
//
$qwho = mysql_query("SELECT `name`, `id` FROM `chat_rooms` WHERE `id` = '".$place."';");
$whoroom = mysql_fetch_array($qwho);
$who = "$whoroom[name]";
//
if(empty($whode))
{
$whode="<a href=\"/menu/html\">Прихожая</a><br/>";
}
else
{
$whode="<a href=\"/room/rid/html\">$who</a><br/>";
}
echo"• <a href=\"/info/".$usid[id]."/html/inf\">$poisk[nickname]</a> ";


if($ltime > 0)
	{
	echo "Последний визит: $ltime $var назад<br/>\n";
	}
	else
	{
echo "Сейчас в: $whode  \n";
	}
}
}
echo "<div class=\"d1\">• <a href=\"/menu/html\">В прихожую</a></div>\n";
echo'<div class="d3">';
echo"$sitefoot";
list($msec, $sec) = explode(chr(32), microtime());
echo "[".round(($sec+$msec)-$headtime,5)."] sec<br/>\n";
echo'</div>';
echo "</body></html>";
break;
}
?>