Просмотр файла katrinka.ru/forum.php

Размер файла: 10.93Kb
<?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; }
  $fppp=3;
  $ftpp=10;
  $fnewtop='t';
#  $pflag=0;
  $lang=$_GET['lang'];
  $f=htmlspecialchars(trim($_GET['f']),ENT_QUOTES);
  $t=htmlspecialchars(trim($_GET['t']),ENT_QUOTES);
  $p=htmlspecialchars(trim($_GET['p']),ENT_QUOTES);
  if ($p=='') $p=0;
  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="&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430;">
<p align="center">
&#x041E;&#x0448;&#x0438;&#x0431;&#x043A;&#x0430; &#x043F;&#x043E;&#x0434;&#x043A;&#x043B;&#x044E;&#x0447;&#x0435;&#x043D;&#x0438;&#x044F; &#x043A; &#x0411;&#x0414<br/>
<a href="/">&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;</a>
</p>
</card>
</wml>
<?php
	exit;
    }

	$uid=0;
	$access=0;
	if (isset($_SESSION['id'])) {
		$uid=$_SESSION['id'];
		if ((!isset($_SESSION['access']))||(!isset($_SESSION['ftpp']))||(!isset($_SESSION['fppp']))||(!isset($_SESSION['fnewtop']))) {
			$res=pg_query($conn,"select access,fppp,ftpp,fnewtop from users where id='$uid';");
			$_SESSION['access']=pg_result($res,0,0);
			$_SESSION['fppp']=pg_result($res,0,1);
			$_SESSION['ftpp']=pg_result($res,0,2);
			$_SESSION['fnewtop']=pg_result($res,0,3);
		}
		$access=$_SESSION['access'];
		$fppp=$_SESSION['fppp'];
		$ftpp=$_SESSION['ftpp'];
		$fnewtop=$_SESSION['fnewtop'];

	} 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,fppp,ftpp,fnewtop 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);
			$fppp=pg_result($res,0,2);
			$ftpp=pg_result($res,0,3);
			$fnewtop=pg_result($res,0,4);
			$_SESSION['id']=$uid;
			$_SESSION['fppp']=$fppp;
			$_SESSION['access']=$access;
			$_SESSION['ftpp']=$ftpp;
			$_SESSION['fnewtop']=$fnewtop;
		}
	}
	}

if (($f==0)&&($t==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
	print "<card id=\"Forum\" title=\"&#x0424;&#x043E;&#x0440;&#x0443;&#x043C;\">\n";

	print "<do name=\"a1\" type=\"options\" label=\"&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;\">\n";
	print '<go href="index.php?lang='.$lang.'" />';
	print "</do>\n";

	print "<p align=\"center\">\n";
	print "<a href=\"frules/\">&#x041F;&#x0440;&#x0430;&#x0432;&#x0438;&#x043B;&#x0430; &#x0444;&#x043E;&#x0440;&#x0443;&#x043C;&#x0430;</a><br/><br/>\n";
	
	$res=pg_query($conn,"select id,name,flag,nthemes,nrepl,note from forums order by id;");
	$rows=pg_numrows($res);
	$timex=time()-300;
	for ($i=0; $i<$rows; $i++) {
		$rid=pg_result($res,$i,0);
		$nthemes=pg_result($res,$i,3);
		$nrepl=pg_result($res,$i,4);
		$note=pg_result($res,$i,5);
		$forum='';
		$flag=pg_result($res,$i,2);
		if (($flag!=1)||(($flag==1)&&($access))) {
			$isnew='';
			if ($uid) {
				$fres=pg_query($conn,"select id from fseen_by where uid='$uid' and forum='$rid';");
				if (!pg_numrows($fres)) $isnew='*';
			}
        		$forum=uconv(pg_result($res,$i,1));
			print "<a href=\"forum.php?f=".$rid."&amp;lang=".$lang."\">".$isnew." ".$forum." (".$nthemes.") [".$nrepl."]</a><br/>".$note."<br/><br/>\n";
		}
	}
	print "<br/><a href=\"user_settings.php\">&#x041D;&#x0430;&#x0441;&#x0442;&#x0440;&#x043E;&#x0439;&#x043A;&#x0438;</a><br/>\n";
}

	
if (($f>0)&&(!$t)) {
  	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,flag,nthemes from forums where id='$f';");
	$name=pg_result($res,0,0);
	$flag=pg_result($res,0,1);
	$nthemes=pg_result($res,0,2);
	if (!pg_numrows($res)) { pg_close($conn); exit; }
	if ($uid) {
		$res=pg_query($conn,"select id from fseen_by where uid='$uid' and forum='$f';");
		if (!pg_numrows($res))
			pg_query($conn,"insert into fseen_by (uid,forum) values ('$uid','$f');");
	}
	print "<card id=\"Forum\" title=\"".$name."\">\n";
	if ($p) {
		print "<do name=\"a1\" type=\"options\" label=\"Prev ".$ftpp."\">\n";
		print '<go href="forum.php?lang='.$lang.'&amp;f='.$f.'&amp;p='.($p-1).'" />';
		print "</do>\n";
	}
	if ($np > $p) {
		print "<do name=\"a2\" type=\"options\" label=\"Next ".$ftpp."\">\n";
		print '<go href="forum.php?lang='.$lang.'&amp;f='.$f.'&amp;p='.($p+1).'" />';
		print "</do>\n";
	}
	print "<do name=\"a3\" type=\"options\" label=\"&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;\">\n";
	print '<go href="index.php?lang='.$lang.'" />';
	print "</do>\n";
	print "<do name=\"a4\" type=\"options\" label=\"&#x0424;&#x043E;&#x0440;&#x0443;&#x043C;&#x044B;\">\n";
	print '<go href="forum.php?lang='.$lang.'" />';
	print "</do>\n";
	print "<do name=\"a5\" type=\"options\" label=\"&#x041D;&#x043E;&#x0432;&#x0430;&#x044F; &#x0442;&#x0435;&#x043C;&#x0430;\">\n";
	print '<go href="forum_post.php?lang='.$lang.'&amp;f='.$f.'" />';
	print "</do>\n";
	print "<p>\n";
	$offset=$p*$ftpp;
	$res=pg_query($conn,"select themes.id,themes.name,themes.rdnum,themes.rplnum,themes.time,themes.uid,users.login,themes.closed,themes.sticker from themes,users where users.id=themes.uid and users.moder=0 and themes.forum='$f' order by sticker desc,themes.lastrepl desc limit '$ftpp' offset '$offset';");
	$rows=pg_numrows($res);
	for ($i=0; $i<$rows; $i++) {
		$id=pg_result($res,$i,0);
		$name=uconv(pg_result($res,$i,1));
		$rdnum=pg_result($res,$i,2);
		$rplnum=pg_result($res,$i,3);
		$time=strftime("%d/%m %H:%M", pg_result($res,$i,4));
		$fr_u=pg_result($res,$i,5);
		$login=uconv(pg_result($res,$i,6));
		$closed=pg_result($res,$i,7);
		$sticker=pg_result($res,$i,8);
		$isnew='';
		$isclosed='';
		if ($closed) $isclosed='(closed)'; else $isclosed='';
		if ($sticker=='t') $issticker='(*)'; else $issticker='';
		if ($uid) {
			$fres=pg_query($conn,"select id from seen_by where uid='$uid' and theme='$id';");
			if (!pg_numrows($fres)) $isnew='(new)';
		}
		print "<a href=\"user_info.php?id=".$fr_u."\">".$login." [".$rplnum."] &lt;".$rdnum."&gt;</a><br/>".$time."<br/>".$name."<br/><a href=\"forum.php?t=".$id."&amp;lang=".$lang."\">".$issticker.$isnew.$isclosed."&gt;&gt;&gt;&gt;</a><br/>\n";
	}
	$np=floor($nthemes/$ftpp);
	print "<br/>Page: ".$p."/".$np."<br/>Go to page:\n";
	print "<input name=\"p\" type=\"text\" value=\"".$p."\" maxlength=\"3\" format=\"3N\"/><br/>\n";
	print "<anchor title=\"Go\">Go<go href=\"forum.php\" method=\"get\">\n";
	print "<postfield name=\"f\" value=\"".$f."\"/>\n";
	print "<postfield name=\"p\" value=\"$(p)\"/>\n";
	print "</go></anchor>\n";
}

if ($t>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 (!$p) pg_query($conn,"update themes set rdnum=rdnum+1 where id='$t';");
	if ($uid) {
		$res=pg_query($conn,"select id from seen_by where uid='$uid' and theme='$t';");
		if (!pg_numrows($res))
			pg_query($conn,"insert into seen_by (uid,theme) values ('$uid','$t');");
	}
	$res=pg_query($conn,"select themes.forum,forums.flag,themes.closed,themes.rplnum from themes,forums where themes.id='$t' and forums.id=themes.forum;");
	$f=pg_result($res,0,0);
	$flag=pg_result($res,0,1);
	$closed=pg_result($res,0,2);
	$rplnum=pg_result($res,0,3);
	$np=floor($rplnum/$fppp);
	if ($uid) {
		$res=pg_query($conn,"select id from forum_moder where uid='$uid' and forum='$f';");
		if (pg_numrows($res)) $access=3;
	}
	print "<card id=\"Theme\" title=\"Page ".$p."/".$np."\">\n";
	if (!$closed) {
		print "<do name=\"a1\" type=\"options\" label=\"&#x041E;&#x0442;&#x0432;&#x0435;&#x0442;\">\n";
		print '<go href="forum_post.php?lang='.$lang.'&amp;t='.$t.'" />';
		print "</do>\n";
	}
	if ($p) {
		print "<do name=\"a2\" type=\"options\" label=\"Prev ".$fppp."\">\n";
		print '<go href="forum.php?lang='.$lang.'&amp;t='.$t.'&amp;p='.($p-1).'" />';
		print "</do>\n";
	}
	if ($np > $p) {
		print "<do name=\"a3\" type=\"options\" label=\"Next ".$fppp."\">\n";
		print '<go href="forum.php?lang='.$lang.'&amp;t='.$t.'&amp;p='.($p+1).'" />';
		print "</do>\n";
	}
	print "<do name=\"a4\" type=\"options\" label=\"&#x041D;&#x0430; &#x0433;&#x043B;&#x0430;&#x0432;&#x043D;&#x0443;&#x044E;\">\n";
	print '<go href="index.php?lang='.$lang.'" />';
	print "</do>\n";
	print "<do name=\"a5\" type=\"options\" label=\"&#x0424;&#x043E;&#x0440;&#x0443;&#x043C;&#x044B;\">\n";
	print '<go href="forum.php?lang='.$lang.'" />';
	print "</do>\n";
	print "<do name=\"a6\" type=\"options\" label=\"&#x0421;&#x043F;&#x0438;&#x0441;&#x043E;&#x043A; &#x0442;&#x0435;&#x043C;\">\n";
	print '<go href="forum.php?lang='.$lang.'&amp;f='.$f.'" />';
	print "</do>\n";
	if ($access > 2) {
		print "<do name=\"a7\" type=\"options\" label=\"Del\">\n";
		print '<go href="forum_del.php?lang='.$lang.'&amp;t='.$t.'" />';
		print "</do>\n";
	}
	print "<p>\n";
	$offset=$p*$fppp;
	if ($fnewtop=='t') $rev='desc'; else $rev='';
	$res=pg_query($conn,"select threads.id,threads.message,threads.uid,threads.time,users.login where users.id=threads.uid and users.moder=0 and threads.theme='$t' order by threads.id $rev limit '$fppp' offset '$offset';");
	$rows=pg_numrows($res);
	for ($i=0; $i<$rows; $i++) {
		$id=pg_result($res,$i,0);
		$message=uconv(pg_result($res,$i,1));
		$fr_u=pg_result($res,$i,2);
		$time=strftime("%d/%m %H:%M",pg_result($res,$i,3));
		$login=uconv(pg_result($res,$i,4));
		print "<a href=\"user_info.php?id=".$fr_u."\">".$login."</a><br/>".$time."<br/>".$message."<br/>\n";
	}
	if ($rplnum > $fppp) {
		print "<br/>Page: \n";
		print "<select name=\"p\" value=\"".$p."\">\n";
		for ($i=0; $i<($np+1); $i++)
			print "<option value=\"".$i."\">".$i."</option>\n";
		print "</select><br/>\n";
		print "<anchor title=\"Go\">Go<go href=\"forum.php\" method=\"get\">\n";
		print "<postfield name=\"t\" value=\"".$t."\"/>\n";
		print "<postfield name=\"p\" value=\"$(p)\"/>\n";
		print "</go></anchor>\n";
	}

}

?>
</p>
<?php counters(); ?>
</card>
</wml>