<?

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

require("inc.php");
$link = connect_db();
list($row, $id, $ps, $fsize1, $fsize2) = check_login($link);
require("version.php");
$us=$row["user"];
$sex=$row["sex"];
$level=$row["level"];

$t=date("H:i", mktime(date ("H")+0)); ## время, +0 - отличие от времени сервера ##

for ($n = 0; $n <= 12; $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;
}

for ($s = 13; $s <= 22; $s++){
$room = "room".$s;
$tmr = time()-300;
$pr = @mysql_query ("Select who from $room WHERE id > '".$tmr."' group by who order by id desc;");
$asnums = mysql_affected_rows();
$sizn[$s] = $asnums;
@$kolp = $kolp + $asnums;
}

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

$tm = time()-300;
$r = @mysql_query ("Select who from room23 WHERE id > '".$tm."' group by who order by id desc;");
$asnum3 = mysql_affected_rows();

$kols = $kol + $kolp + $kolpr + $asnum3;

$r = mysql_query ("select count(readd) as num from zapiski WHERE (idtowhom = '".$id."')and(readd = '0')and(ininc = '1');");
$a = mysql_fetch_array($r);
$inb = $a["num"]; 

$cmc = mysql_query ("select count(id) as num from vstrechi WHERE 1;");
$cmac = mysql_fetch_array($cmc);
$cmtot = $cmac["num"]; 

$setting = @mysql_query ("Select * from setting where klu4='1'");
$set = mysql_fetch_array ($setting);

if (($ver!="wml")&&($ver!="xhtml")){
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.2//EN\" \"http://www.wapforum.org/DTD/wml12.dtd\">\n";
echo "<wml>\n";
echo "<head><meta http-equiv=\"Cache-Control\" content=\"no-cache\" forua=\"true\"/></head>\n";
echo "<card id=\"index\" title=\"Лучший чат\">\n";
echo "<p align=\"center\">";
echo "<small>"; 
echo "Выберите версию загрузки чата.<br/>"; 
echo "---<br/>"; //разделитель
echo "<b><a href=\"enter.php?ver=wml&amp;id=$id&amp;ps=$ps&amp;ref=$ref\">Версия WAP 1.2</a></b><br/>";
echo "<b><a href=\"enter.php?ver=xhtml&amp;id=$id&amp;ps=$ps&amp;ref=$ref\">Версия WAP 2.0</a></b><br/>";
echo "---<br/>";
if($set["link1"]!="") echo "<small><a href=\"http://".$set["link1"]."\">".$set["link1_name"]."</a></small><br/>\n";
if($set["link2"]!="") echo "<small><a href=\"http://".$set["link2"]."\">".$set["link2_name"]."</a></small><br/>\n";
if($set["link3"]!="") echo "<small><a href=\"http://".$set["link3"]."\">".$set["link3_name"]."</a></small><br/>\n";
echo "---<br/>";
echo "&#169; WAB2.WUP.RU<br/>";
echo "</small>";
echo "</p></card></wml>";
mysql_close ($link);
exit;
}


ob_start();
if (($ver=="wml")||($ver=="xhtml")){
if ($ver=="wml"){
echo $xml;
echo $dtd;
echo "<wml>";
echo "<card id=\"enter\" title=\"Улица | ".$t."\">";
echo "<p align=\"center\">";
}else if ($ver=="xhtml"){
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>Улица | ".$t."</title>";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/></head><body>";
echo "<div align=\"center\">";
}
echo $fsize1;
require("calendar.php");
if ($row["level"]>6){
if ($ver=="wml") echo $divide;
else if ($ver=="xhtml") echo "<br/>";
echo "<a href=\"apanel.php?$ses&amp;ref=$ref\">Админка</a><br/>";
echo $divide;
}
else if ($row["level"]>3){
echo "<a href=\"mpanel.php?$ses&amp;ref=$ref\">Модерка</a><br/>";
echo $divide;
}
if ($row["level"]<4) {echo $divide;}
echo "<a href=\"rules.php?$ses&amp;ref=$ref\">Правила</a><br/>";
echo "<a href=\"vstrechi.php?$ses&amp;ref=$ref\">Встречи(".$cmtot.")</a><br/>";
$svadbi=mysql_fetch_array(mysql_query ("select count(id) as num from svadbi"));
echo "<a href=\"svadbi.php?$ses&amp;ref=$ref\">Свадьбы(".$svadbi[0].")</a><br/>";
$cmc = mysql_query ("select count(id) as num from gazeta WHERE 1;");
$cmac = mysql_fetch_array($cmc);
$cmtot2 = $cmac["num"]; 
echo "<a href=\"gazeta.php?$ses&amp;ref=$ref\">Газета чата(".$cmtot2.")</a><br/>";
$cmc = mysql_query ("select count(id) as num from infa WHERE 1;");
$cmac = mysql_fetch_array($cmc);
$cmtot3 = $cmac["num"]; 
echo "<a href=\"infa.php?$ses&amp;ref=$ref\">Полезная инфа(".$cmtot3.")</a><br/>";
$idnews=mysql_fetch_array(mysql_query("SELECT MAX(id) FROM news"));
if ($idnews[0]>0) $news=mysql_fetch_array(mysql_query("SELECT date FROM news where id=$idnews[0]"));
if (isset($news[0])) echo "<a href=\"news.php?$ses&amp;ref=$ref\">Новости(".$news[0].")</a><br/>";
echo $divide;
$q = mysql_query("select id,title from obiav order by id desc;");
while($arr=mysql_fetch_array($q)) {
echo "<a href=\"view_obiav.php?$ses&amp;mid=".$arr['id']."&amp;ref=$ref\">".$arr['title']."</a><br/>"; }
echo $divide;
$gallery = mysql_query ("select count(id) as num from users where img!=''");
$foto = mysql_fetch_array($gallery);
$kolfoto = $foto["num"]; 
echo "<a href=\"galery.php?$ses&amp;ref=$ref\">Фотогалерея чата(".$kolfoto.")</a><br/>";
echo $divide;
echo "<a href=\"cabinet.php?$ses&amp;ref=$ref\">Личный кабинет</a><br/>";
$r = mysql_query ("select count(readd) as num from zapiski WHERE (idtowhom = '".$id."')and(readd = '0')and(ininc = '1');");
$a = mysql_fetch_array($r);
$inb = $a["num"]; 
if($inb != "0") echo "<img src=\"smile/new.gif\" alt=\"NEW\"/><b>Вам письмо<a href=\"inbox.php?$ses&amp;ref=$ref\">(".$inb.")</a></b><br/>\n";
$d=date("d-m-");
$birth = mysql_fetch_array(mysql_query ("Select count(id) from users where birth LIKE '%$d%'"));
if ($birth[0]>0) echo "Именинники: <a href=\"statistik.php?$ses&amp;mod=birthday&amp;ref=$ref\">".$birth[0]."</a><br/>";
echo $divide;
echo "<a href=\"who.php?$ses&amp;ref=$ref\">Кто где?(".$kols.")</a><br/>";
echo "<a href=\"systs.php?$ses&amp;ref=$ref\">Система поиска</a><br/>";
echo $divide;
echo "<a href=\"games.php?$ses&amp;ref=$ref\">Казино</a><br/>";
$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]."(".$asnum3.")</a><br/>\n";
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"];
$rm=$rooms["rm"];
$room="room".$rm;
$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[$rm] = $asnum;
if ($rm==9) {
echo "<a href=\"anlim.php?$ses&amp;rm=$rm&amp;ref=$ref\">$roomname($siz[$rm])</a><br/>";
} else if ($rm==11) {
echo "<a href=\"klaznet.php?$ses&amp;rm=$rm&amp;ref=$ref\">$roomname($siz[$rm])</a><br/>";
} else if ($rm==10) {
echo "<a href=\"intim.php?$ses&amp;rm=$rm&amp;ref=$ref\">$roomname($siz[$rm])</a><br/>";
} else if ($rm==8) {
echo "<a href=\"chat.php?$ses&amp;rm=$rm&amp;ref=$ref\">$roomname($siz[$rm])</a><br/>";
} else {
echo "<a href=\"chat.php?$ses&amp;rm=$rm&amp;ref=$ref\">$roomname($siz[$rm])</a><br/>";
}
} 
echo $divide;
echo "<a href=\"pos.php?$ses&amp;ref=$ref\">Посольства(".$kolp.")</a><br/>\n";
echo $divide;
echo "<a href=\"faq.php?$ses&amp;ref=$ref\">Справка | Смайлы</a><br/>";
echo "<a href=\"statistik.php?$ses&amp;ref=$ref\">Статистика</a><br/>";
$curdate=date("d-m-Y");
$newtoday=mysql_fetch_array(mysql_query("SELECT COUNT(id) from users WHERE date = '".$curdate."'"));
if ($newtoday[0]>0){ 
echo "Новички: <a href=\"statistik.php?$ses&amp;mod=newtoday&amp;ref=$ref\">".$newtoday[0]."</a><br/>";
}
$pr_count = @mysql_query("SELECT id,user FROM users WHERE onl> '".$tm ."' AND room='holl' group by user order by onl desc;");
$kolpe = mysql_affected_rows();
echo $divide;
echo "В прихожей: <a href=\"prwho.php?$ses&amp;ref=$ref\">".$kolpe."</a><br/>";
info_compress();
echo $divide;
echo "Версия чата:<br/>"; 
if ($ver=="wml") echo "[WML | <a href=\"enter.php?ver=xhtml&amp;id=$id&amp;ps=$ps&amp;ref=$ref\">xHTML</a>]<br/>";
else if ($ver=="xhtml") echo "<div class=\"ibutton\">[<a href=\"enter.php?ver=wml&amp;id=$id&amp;ps=$ps&amp;ref=$ref\">WML</a> | xHTML]<br/>";
$time = getmicrotime();
$tm = time()-300;
mysql_query ("Update users set  onl='".$time."', room='holl' where id ='".$id."'");
$f = fopen("log/kol.dat", "a+"); 
flock($f,LOCK_EX);
ftruncate($f,0);
fwrite($f, $kols);	
fflush($f);
flock($f,LOCK_UN);
fclose($f);
if ($ver=="wml") echo $divide;
else if ($ver=="xhtml") echo "<br/>";
if ($ver=="wml"){
if($set["link1"]!="") echo "<small><a href=\"http://".$set["link1"]."?ver=".$ver."\">&#8592; ".$set["link1_name"]."</a></small><br/>\n";
if($set["link2"]!="") echo "<small><a href=\"http://".$set["link2"]."?ver=".$ver."\">&#8592; ".$set["link2_name"]."</a></small><br/>\n";
if($set["link3"]!="") echo "<small><a href=\"http://".$set["link3"]."?ver=".$ver."\">&#8592; ".$set["link3_name"]."</a></small><br/>\n";
}else if ($ver=="xhtml"){
if($set["link1"]!="") {echo "<div class=\"d1\"><a href=\"http://".$set["link1"]."?ver=".$ver."\">&#8592; ".$set["link1_name"]."</a></div>\n";}
if($set["link2"]!="") {echo "<div class=\"d1\"><a href=\"http://".$set["link2"]."?ver=".$ver."\">&#8592; ".$set["link2_name"]."</a></div>\n";}
if($set["link3"]!="") {echo "<div class=\"d1\"><a href=\"http://".$set["link3"]."?ver=".$ver."\">&#8592; ".$set["link3_name"]."</a></div>\n";}
}
echo $fsize2;
if ($ver=="wml")echo "</p></card></wml>";
else if ($ver=="xhtml") echo "</div></body></html>";
$alltraf=$row["alltraf"];
$pagesize=round((ob_get_length())/1024,1);
$alltraf=$alltraf+$pagesize;
mysql_query ("Update users set alltraf='".$alltraf."', lasttraf='".$pagesize."' where id='".$id."'");
mysql_close ($link);
ob_end_flush();
}
?>