<?php
include 'config.php';
include 'guestbook/mylib.php';
if (!checkagent($_SERVER['HTTP_USER_AGENT'])) { noemul(); exit; }
list ($opname, $chatok) = check_op($_SERVER['REMOTE_ADDR']);
if (!$chatok) { unk_op(); exit; }
header("Cache-Control: no-cache");
header("Content-type: text/vnd.wap.wml");
$lang=$_GET['lang'];
$r=htmlspecialchars(trim($_GET['r']),ENT_QUOTES);
$mot=0;
if (ereg("^MOT-.*",$_SERVER['HTTP_USER_AGENT'])) $mot=1;
session_start();
?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN" "http://www.wapforum.org/DTD/wml_1.2.dtd">
<wml>
<head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>
<?php
if (!($conn=pg_connect("host=$dbhost port=$dbport dbname=$dbname user=$dbuser password=$dbpass")))
{ ?>
<card id="ChatErr" title="Ошибка">
<p align="center">
Ошибка подключения к БД<br/>
<a href="/">На главную</a>
</p>
</card>
</wml>
<?php
exit;
}
$id=0;
$access=0;
# if ($_SERVER['REMOTE_ADDR']=='212.93.97.200') $access=1;
if (isset($_SESSION['id'])) {
$id=$_SESSION['id'];
if (!isset($_SESSION['access'])) {
$res=pg_query($conn,"select access from users where id='$id';");
$_SESSION['access']=pg_result($res,0,0);
}
$access=$_SESSION['access'];
} else {
if ((trim($_COOKIE['Login'])!='')&&(trim($_COOKIE['Password'])!='')) {
$login=htmlspecialchars(trim($_COOKIE['Login']),ENT_QUOTES);
$pass=htmlspecialchars(trim($_COOKIE['Password']),ENT_QUOTES);
$res=pg_query($conn,"select id,access from users where login='$login' and passwd='$pass' and moder=0;");
if (pg_numrows($res)==1) {
$id=pg_result($res,0,0);
$access=pg_result($res,0,1);
$_SESSION['id']=$id;
$_SESSION['access']=$access;
}
}
}
if ($lang=='eng')
print "<card id=\"WhoWhere\" title=\"Who's where\">\n";
else
print "<card id=\"WhoWhere\" title=\"Кто где\">\n";
print "<p align=\"center\">\n";
$res=pg_query($conn,"select id,name_eng,name_rus,flag from chat_rooms order by id;");
$rows=pg_numrows($res);
$timex=time()-300;
for ($i=0; $i<$rows; $i++) {
$flag=pg_result($res,$i,3);
$room='';
if ($lang!='eng') $room=uconv(pg_result($res,$i,2));
$rid=pg_result($res,$i,0);
if (($rid==16)&&($id!=1)&&($id!=2)&&($id!=3)) continue;
if (($flag!=1)||(($flag==1)&&($access))) {
if ($room=='') $room=uconv(pg_result($res,$i,1));
if ($rid==18) {
if ($access == 4) {
$res_cnt=pg_query($conn,"select distinct chat_tet.fr_u,users.login,users.id from chat_tet,users where users.id=chat_tet.fr_u and users.moder=0 and chat_tet.time > '$timex'");
} else {
$res_cnt=pg_query($conn,"select distinct chat_tet.fr_u,users.login,users.id from chat_tet,users where users.id=chat_tet.fr_u and users.moder=0 and chat_tet.time > '$timex' and (chat_tet.fr_u='$id' or chat_tet.to_u='$id') and users.invisible=0;");
}
} else {
if ($access > 1) {
$res_cnt=pg_query($conn,"select distinct chat.fr_u,users.login,users.id from chat,users where users.id=chat.fr_u and users.moder=0 and chat.time > '$timex' and chat.room='$rid' and users.access<4;");
} else {
$res_cnt=pg_query($conn,"select distinct chat.fr_u,users.login,users.id from chat,users where users.id=chat.fr_u and users.moder=0 and chat.time > '$timex' and chat.room='$rid' and users.invisible=0 and users.access<4;");
}
}
$rows_cnt=pg_numrows($res_cnt);
print "<a href=\"chat.php?r=".$rid."&lang=".$lang."\">".$room." (".$rows_cnt.")</a><br/>\n";
if ((!$r)||($r==$rid)) {
for ($j=0; $j<$rows_cnt; $j++) {
$login=uconv(pg_result($res_cnt,$j,1));
$uid=pg_result($res_cnt,$j,2);
if (($uid==1)&&($access!=4)) {
} else {
if (($r)||($mot)) { print "<a href=\"user_info.php?id=".$uid."&r=".$rid."&lang=".$lang."\">".$login."</a> \n";
} else { print $login; if ($j!=$rows_cnt-1) print ", \n"; }
}
}
if ($rows_cnt) print "<br/>------<br/>\n";
}
}
}
pg_close($conn);
?>
</p>
<?php counters(); ?>
</card>
</wml>