- <?php
- include 'guestbook/mylib.php';
- include 'config.php';
- if (!checkagent($_SERVER['HTTP_USER_AGENT'])) { noemul(); exit; }
- list ($opname, $chatok) = check_op($_SERVER['REMOTE_ADDR']);
- if (!$chatok) { unk_op(); exit; }
- $ppp=9;
- $showpics=1;
- $pflag=0;
- $lang=$_GET['lang'];
- $refresh=300;
- $p=htmlspecialchars(trim($_GET['p']),ENT_QUOTES);
- $r=htmlspecialchars(trim($_GET['r']),ENT_QUOTES);
- $n=$_GET['n']+1;
- session_start();
- ?>
- <?php
- if (!($conn=pg_connect("host=$dbhost port=$dbport dbname=$dbname user=$dbuser password=$dbpass")))
- {
- header("Cache-Control: no-cache");
- header("Content-type: text/vnd.wap.wml");
- ?>
- <?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>
- <card id="ChatErr" title="Ошибка">
- <p align="center">
- Ошибка подключения к БД<br/>
- <a href="/">На главную</a>
- </p>
- </card>
- </wml>
- <?php
- exit;
- }
-
- $uid=0;
- $access=0;
- if (isset($_SESSION['id'])) {
- $uid=$_SESSION['id'];
- if ((!isset($_SESSION['access']))||(!isset($_SESSION['ppp']))||(!isset($_SESSION['refresh']))||(!isset($_SESSION['showpics']))) {
- $res=pg_query($conn,"select access,ppp,refresh,showpics from users where id='$uid';");
- $_SESSION['access']=pg_result($res,0,0);
- $_SESSION['ppp']=pg_result($res,0,1);
- $_SESSION['refresh']=pg_result($res,0,2);
- $_SESSION['showpics']=pg_result($res,0,3);
- }
- $access=$_SESSION['access'];
- $ppp=$_SESSION['ppp'];
- $refresh=$_SESSION['refresh'];
- $showpics=$_SESSION['showpics'];
-
- } 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,ppp,refresh,showpics from users where login='$login' and passwd='$pass' and moder=0;");
- if (pg_numrows($res)==1) {
- $uid=pg_result($res,0,0);
- $access=pg_result($res,0,1);
- $ppp=pg_result($res,0,2);
- $refresh=pg_result($res,0,3);
- $showpics=pg_result($res,0,4);
- $_SESSION['id']=$uid;
- $_SESSION['ppp']=$ppp;
- $_SESSION['access']=$access;
- $_SESSION['refresh']=$refresh;
- $_SESSION['showpics']=$showpics;
- }
- }
- }
-
- #if ($r==18) {
- # if ($access==3) $access=2;
- # if ($uid==1) $access=1;
- # if ($uid==18172) $access=4;
- #}
-
- if ($r==0) {
- header("Cache-Control: no-cache");
- header("Content-type: text/vnd.wap.wml");
- ?>
- <?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 ($lang=='eng') {
- print "<card id=\"Chat\" title=\"Rooms\">\n";
- print "<do name=\"a1\" type=\"options\" label=\"Who's where\">\n";
- } else {
- print "<card id=\"Chat\" title=\"Комнаты\">\n";
- print "<do name=\"a1\" type=\"options\" label=\"Кто где\">\n";
- }
- print '<go href="chat_who.php?lang='.$lang.'" />';
- print "</do>\n";
- print "<p align=\"center\">\n";
- if ($lang!='eng') {
- print "<a href=\"/rules/\">Уголовный Кодекс чата</a><br/>\n";
- print "<a href=\"chat_smiley.php\">Смайлики</a><br/>\n";
- print "<a href=\"chat_pictures.php\">Картинки</a><br/>\n";
- print "<a href=\"tags.php\">Тэги</a><br/><br/>\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++) {
- $rid=pg_result($res,$i,0);
- # if (($rid==13)&&($uid!=1)&&($uid!=18172)&&($uid!=3)) continue;
- $room='';
- $flag=pg_result($res,$i,3);
- if (($flag!=1)||(($flag==1)&&($access))) {
- if ($lang!='eng') $room=uconv(pg_result($res,$i,2));
- if ($room=='') $room=uconv(pg_result($res,$i,1));
- if ($rid==18) {
- $res_cnt=pg_query($conn,"select distinct chat_tet.fr_u from chat_tet where chat_tet.time > '$timex';");
- } else {
- $res_cnt=pg_query($conn,"select distinct chat.fr_u from chat,users where chat.time > '$timex' and chat.room='$rid' and chat.fr_u=users.id 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 ($lang=='eng') {
- if ($uid) {
- print "<br/><a href=\"user_settings.php?lang=eng\">Chat settings</a><br/>\n";
- }
- print "<a href=\"index.php?lang=eng\">Main page</a>\n";
- } else {
- if ($uid) {
- print "<br/><a href=\"user_settings.php\">Настройки чата</a><br/>\n";
- }
- print "<a href=\"/\">На главную</a>\n";
- }
- ?>
- <br/><br/>
- <a href="http://pslink.ru/i.php?id=614">
- <img src="http://pslink.ru/b.php?id=614" alt="PSLink rating" />
- </a>
- <?php
- }
-
-
- if ($r>0) {
- if (($uid)&&(!$n)) {
- setcookie("Login", $login, time()+864000, "/");
- setcookie("Password", $pass, time()+864000, "/");
- }
- header("Cache-Control: no-cache");
- header("Content-type: text/vnd.wap.wml");
- ?>
- <?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
- $res=pg_query($conn,"select name_eng,name_rus,flag from chat_rooms where id='$r';");
- if (!pg_numrows($res)) { pg_close($conn); exit; }
- # if (($r==13)&&($uid!=1)&&($uid!=18172)&&($uid!=3)) { pg_close($conn); exit; }
- $timex=time()-300;
- if ($r==18) {
- $res_cnt=pg_query($conn,"select distinct chat_tet.fr_u from chat_tet where chat_tet.time > '$timex';");
- } else {
- $res_cnt=pg_query($conn,"select distinct chat.fr_u from chat,users where chat.time > '$timex' and chat.room='$r' and chat.fr_u=users.id and users.access<4;");
- }
- $rows_cnt=pg_numrows($res_cnt);
- $flag=pg_result($res,0,2);
- if (($flag==1)&&(!$access)) { pg_close($conn); exit; }
- if ($lang!='eng') $room=uconv(pg_result($res,0,1));
- if ($room=='') $room=uconv(pg_result($res,0,0));
- if (!$p) {
- print "<card id=\"Room\" title=\"".$room." (".$rows_cnt.")\" ontimer=\"http://wap.katrinka.ru/chat.php?lang=".$lang."&r=".$r."&n=".$n."&".SID."\">\n";
- print "<timer value=\"".$refresh."\"/>\n";
- } else {
- print "<card id=\"Room\" title=\"".$room."\">\n";
- }
- if ($lang=='eng')
- print "<do name=\"a1\" type=\"options\" label=\"Sign\">\n";
- else
- print "<do name=\"a1\" type=\"options\" label=\"Написать\">\n";
- print '<go href="chat_add.php?lang='.$lang.'&r='.$r.'" />';
- print "</do>\n";
- if ($lang=='eng')
- print "<do name=\"a2\" type=\"options\" label=\"Refresh\">\n";
- else
- print "<do name=\"a2\" type=\"options\" label=\"Обновить\">\n";
- print '<go href="chat.php?lang='.$lang.'&r='.$r.'&n='.$n.'" />';
- print "</do>\n";
- if ($lang=='eng')
- print "<do name=\"a3\" type=\"options\" label=\"Who's where\">\n";
- else
- print "<do name=\"a3\" type=\"options\" label=\"Кто где\">\n";
- print '<go href="chat_who.php?lang='.$lang.'" />';
- print "</do>\n";
- if ($lang=='eng')
- print "<do name=\"a4\" type=\"options\" label=\"Who's there\">\n";
- else
- print "<do name=\"a4\" type=\"options\" label=\"Кто здесь\">\n";
- print '<go href="chat_who.php?lang='.$lang.'&r='.$r.'" />';
- print "</do>\n";
- if ($lang=='eng')
- print "<do name=\"a5\" type=\"options\" label=\"Leave room\">\n";
- else
- print "<do name=\"a5\" type=\"options\" label=\"Покинуть комнату\">\n";
- print '<go href="chat.php?lang='.$lang.'" />';
- print "</do>\n";
- if ($lang=='eng')
- print "<do name=\"a6\" type=\"options\" label=\"Main page\">\n";
- else
- print "<do name=\"a6\" type=\"options\" label=\"На главную\">\n";
- print '<go href="index.php?lang='.$lang.'" />';
- print "</do>\n";
-
- print "<p>\n";
- $timex=time()-1800;
- if ($r==13) $timex=time()-86400;
- if ($r==18) $timex=time()-259200;
-
- $offset=$p*$ppp;
- if ($uid) {
- if ($r==18) {
- if ($access == 4) {
- $res=pg_query($conn,"select chat_tet.fr_u,chat_tet.to_u,chat_tet.message,chat_tet.time,users.login,users.posts,users.access,chat_tet.id from chat_tet,users where chat_tet.fr_u=users.id and chat_tet.time > '$timex' order by chat_tet.id desc limit $ppp offset $offset;");
- } else {
- $res=pg_query($conn,"select chat_tet.fr_u,chat_tet.to_u,chat_tet.message,chat_tet.time,users.login,users.posts,users.access,chat_tet.id from chat_tet,users where chat_tet.fr_u=users.id and (chat_tet.to_u=0 or chat_tet.to_u='$uid' or chat_tet.fr_u='$uid') and chat_tet.time > '$timex' order by chat_tet.id desc limit $ppp offset $offset;");
- $res_ign=pg_query($conn,"select who from users_ignore where uid='$uid';");
- }
- } else {
- if ($access > 3) {
- $res=pg_query($conn,"select chat.fr_u,chat.to_u,chat.message,chat.time,users.login,users.posts,users.access,chat.id,chat.flag from chat,users where chat.fr_u=users.id and chat.room='$r' and chat.time > '$timex' order by chat.id desc limit $ppp offset $offset;");
- } else {
- $res=pg_query($conn,"select chat.fr_u,chat.to_u,chat.message,chat.time,users.login,users.posts,users.access,chat.id,chat.flag from chat,users where chat.fr_u=users.id and chat.room='$r' and (chat.to_u=0 or chat.to_u='$uid' or chat.fr_u='$uid') and chat.time > '$timex' order by chat.id desc limit $ppp offset $offset;");
- $res_ign=pg_query($conn,"select who from users_ignore where uid='$uid';");
- }
- }
- } else {
- $res=pg_query($conn,"select chat.fr_u,chat.to_u,chat.message,chat.time,users.login,users.posts,users.access,chat.id,chat.flag from chat,users where chat.fr_u=users.id and chat.room='$r' and chat.to_u=0 and chat.time > '$timex' order by chat.id desc limit $ppp offset $offset;");
- }
- $rows=pg_numrows($res);
- $np=$p+1; $pp=$p-1;
- # $mp=floor($numrec/$ppp);
-
- for ($i=0;$i<$rows;$i++) {
- $posts=pg_result($res,$i,5);
- $uacc=pg_result($res,$i,6);
- if ($access==4) $pid=pg_result($res,$i,7);
- $fr_u=pg_result($res,$i,0);
- if ($r!=18) $pflag=pg_result($res,$i,8);
- if (($posts > 100)&&($showpics)) {
- $message=smileys(uconv(pg_result($res,$i,2)));
- if ($uacc > 1) $message=msmileys($message);
- if ($fr_u==549) $message=o_smileys($message);
- if ($uacc > 1) $message=psmileys($message);
- if (($fr_u==1)||($fr_u==2)) $message=ksmileys($message);
- } else {
- $message=uconv(pg_result($res,$i,2));
- }
- $name=uconv(pg_result($res,$i,4));
- # if ($access==3) $name = sprintf("<b><i>%s</i></b>", uconv(pg_result($res,$i,4)));
- # if ($access==2) $name = sprintf("<b>%s</b>", uconv(pg_result($res,$i,4)));
- $mtime=strftime("%H:%M", pg_result($res,$i,3));
- $to_u=pg_result($res,$i,1);
- if (($uid)&&($access < 2)) {
- $ign_rows=pg_numrows($res_ign);
- if ($ign_rows) {
- for ($k=0; $k<$ign_rows; $k++) {
- if (pg_result($res_ign,$k,0)==pg_result($res,$i,0))
- $message='Ignored';
- }
- }
-
- }
- if ($to_u) {
- $res_to_u=pg_query($conn,"select login from users where id='$to_u';");
- $name_to=uconv(pg_result($res_to_u,0,0));
- print "<a href=\"user_info.php?id=".pg_result($res,$i,0)."&r=".$r."&pid=".$pid."\">". $name." -> ".$name_to." ".$mtime."></a> ".$message."<br/>";
- } else {
- if ($pflag) {
- print "<a href=\"user_info.php?id=".pg_result($res,$i,0)."&r=".$r."&pid=".$pid."\">* [".$mtime."]</a> ". $name." ".$message."<br/>";
- } else {
- print "<a href=\"user_info.php?id=".pg_result($res,$i,0)."&r=".$r."&pid=".$pid."\">". $name." ".$mtime."></a> ".$message."<br/>";
- }
- }
- }
-
- if ($rows>=$ppp) print("<a href=\"chat.php?p=".$np."&r=".$r."&lang=".$lang."\">Next ".$ppp."</a><br/>");
- if ($p>0) print("<a href=\"chat.php?p=".$pp."&r=".$r."&lang=".$lang."\">Prev ".$ppp."</a><br/>");
- }
- pg_close($conn);
- ?>
- </p>
- </card>
- </wml>