<?

header("Cache-Control: no-cache");
if ($ver=="wml")header ("Content-type:text/vnd.wap.wml; charset=utf-8");
else header("Content-Type:text/html; charset=UTF-8");

require("inc.php");
$link = connect_db();
list($row, $id, $ps, $fsize1, $fsize2) = check_login($link);
require("version.php");


for ($n = 0; $n <= 22; $n++){
$room = "room".$n;
$tm = time()-300;
$r = @mysql_query ("Select who from $room WHERE id > '".$tm."' group by who order by id desc;");
$asnum = mysql_affected_rows();
$siz[$n] = $asnum;
@$kol = $kol + $asnum;
$kolp=$siz[13]+$siz[14]+$siz[15]+$siz[16]+$siz[17]+$siz[18]+$siz[19]+$siz[20]+$siz[21]+$siz[22];
}

$pr_count = @mysql_query("SELECT id,user FROM users WHERE onl> '".$tm ."' AND room='holl' and level != '8' group by user order by onl desc;");
$kolpr = mysql_affected_rows();
$kols = $kol + $kolpr;

if ($ver=="wml"){
echo $xml;
echo $dtd;
echo "<wml>";
echo "<head><meta http-equiv=\"Cache-Control\" content=\"no-cache\" forua=\"true\"/></head>";
echo "<card id=\"who\" title=\"Кто где?(".$kols.")\">";
echo "<p align=\"left\">";
}else{
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">";
echo "<head><link rel=\"stylesheet\" type=\"text/css\" href=\"css/css.css\"/>";
echo "<title>Кто где?(".$kols.")</title>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/></head><body>";
echo "<div align=\"left\">";
}
echo $fsize1;

$tm = time()-300;
$ingame = "";
$outgame = "";
$res = @mysql_query ("Select * from room23 WHERE id > '".$tm."' group by usid order by id desc");
$kolm = mysql_affected_rows(); 
for ($k = 0; $k < $kolm; $k++){    
$lines = mysql_fetch_array ($res);
$user = $lines["who"];
$user_id = $lines["usid"];
$r = mysql_query("select * from ingame23 WHERE gamer_id = '".$user_id."'"); 
$a = mysql_fetch_array($r);
$id_in_game = $a["id_in_game"];
if (mysql_affected_rows()!=0) $ingame = $ingame."$user($id_in_game), "; else $outgame = $outgame."$user, ";
}      
unset($lines);
$roommaf = @mysql_fetch_array(@mysql_query ("Select name from rooms where rm='23' LIMIT 1;"));
echo "<a href=\"chat.php?$ses&amp;rm=23&amp;ref=$ref\">".$roommaf[0]."(".($kolm)."):</a><br/>\n";
echo "<b>В игре:</b><br/>\n";
echo "$ingame<br/>\n";
echo "<b>Вне игры:</b><br/>\n";
echo "$outgame<br/>\n";
echo $divide;
echo "<a href=\"pos.php?$ses&amp;ref=$ref\">Посольства(".($kolp)."):</a><br/>";
echo $divide;

if ($row["level"]==8){
$tm = time()-300;
$pr_count = @mysql_query("SELECT id,user FROM users WHERE onl> '".$tm ."' AND room='letters' group by user order by onl desc;");
$kol = mysql_affected_rows();
echo "<a href=\"chatmail.php?$ses&amp;ref=$ref\">Записки(".($kol)."):</a><br/>";
for ($k = 0; $k < $kol; $k++)
{
$pdc = @mysql_fetch_array($pr_count);
$user = $pdc["user"];
$nk = $pdc["id"];
echo "$user";
if (($k+1) != $kol) print ', ';
}
if($kol>0) echo "<br/>";
unset($pdc);
echo $divide;
}

$roomselect = @mysql_query ("Select name,rm from rooms order by pos limit 0,13;");
while($rooms = @mysql_fetch_array($roomselect)) {
$roomname=$rooms["name"];
$rms=$rooms["rm"];
$room="room".$rms;
$tm = time()-300;
if ($rms==10)$res = @mysql_query ("Select who,hid,pwd,usid from $room WHERE id > '".$tm."' group by who order by id desc;");
else $res = @mysql_query ("Select who,hid,usid from $room WHERE id > '".$tm."' group by who order by id desc;");
echo " ".mysql_error()." ";
$kol = mysql_affected_rows();
$siz[$rms] = $kol;
if ($rms==9) {
echo "<a href=\"anlim.php?$ses&amp;rm=$rms&amp;ref=$ref\">$roomname($siz[$rms]):</a><br/>";
} else if ($rms==11) {
echo "<a href=\"klaznet.php?$ses&amp;rm=$rms&amp;ref=$ref\">$roomname($siz[$rms]):</a><br/>";
} else if ($rms==10) {
if ($row["level"]==8) echo "<b><a href=\"intim.php?$ses&amp;rm=$rms&amp;ref=$ref\">$roomname($siz[$rms]):</a></b><br/>";
} else if ($rms==8) {
if ($row["level"]>3) echo "<b><a href=\"chat.php?$ses&amp;rm=$rms&amp;ref=$ref\">$roomname($siz[$rms]):</a></b><br/>";
} else {
echo "<a href=\"chat.php?$ses&amp;rm=$rms&amp;ref=$ref\">$roomname($siz[$rms]):</a><br/>";
}
if ($rms!=10){
for ($k = 0; $k < $kol; $k++){
$lines = mysql_fetch_array ($res);
$user = $lines["who"];
$nk = $lines["usid"];
$hd = $lines["hid"];
if ($hd != 1) echo "$user";
else if ($row["level"]==8) echo "$user(i)";
if (($k+1) != $kol) print ', ';
}
if($kol>0)echo "<br/>";
unset($lines);
}else{
if ($row["level"]==8){
for ($k = 0; $k < $kol; $k++){
$lines = mysql_fetch_array ($res);
$user = $lines["who"];
$nk = $lines["usid"];
$hd = $lines["hid"];
$pwd = $lines["pwd"];
if ($hd != 1)echo "$user($pwd)";
else echo "$user(!)($pwd)";
if (($k+1) != $kol) print ', ';
}
if($kol>0)echo "<br/>";
unset($lines);
}
}
}
echo $divide;
$tm = time()-300;
$pr_count = @mysql_query("SELECT id,user,inv,level FROM users WHERE onl> '".$tm ."' AND room='holl' group by user order by onl desc;");
$kolpr = mysql_affected_rows();
echo "<a href=\"enter.php?$ses&amp;ref=$ref\">&#8592; Прихожая(".($kolpr)."):</a><br/>";
for ($k = 0; $k < $kolpr; $k++)
{
$pdc = @mysql_fetch_array($pr_count);
$user = $pdc["user"];
$inv = $pdc["inv"];
$nk = $pdc["id"];
if ($inv != 1) echo "$user";
else if ($row["level"] >6 )  echo "$user(i)";
if (($k+1) != $kolpr) print ', ';
}
if($kolpr>0) echo "<br/>";
unset($pdc);
if (isset ($rm)){
if($rm==10) $takep="&amp;pwd=$pwd&amp;ref=$ref";
else if($mod=="privat") $takep="&amp;mod=$mod&amp;ref=$ref";
else $takep="&amp;ref=$ref";
echo $divide;
echo "<a href=\"chat.php?$ses&amp;rm=$rm$takep\">&#8592; В чат</a><br/>\n";
}
echo $fsize2;
if ($ver=="wml")echo "</p></card></wml>";
else echo "</div></body></html>";
mysql_close ($link);
?>