<?php
include '../wap/guestbook/mylib.php';
include '../wap/config.php';
include 'acl.php';
$addr=$_SERVER['REMOTE_ADDR'];
list ($uid, $pl) = priv_level();
$fppp=30;
$ftpp=30;
$fnewtop='f';
if ($uid==1) $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);
?>
<?php
if (!($conn=pg_connect("host=$dbhost port=$dbport dbname=$dbname user=$dbuser password=$dbpass")))
{
exit;
}
pg_query($conn,"SET CLIENT_ENCODING TO 'KOI8';");
if (($f==0)&&($t==0)) {
header("Cache-Control: no-cache");
?>
<html>
<head><meta http-equiv="Cache-Control" content="no-cache"></head>
<body>
<?php
print "<p align=\"center\">\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))) {
if ($uid) {
$isnew='';
$fres=pg_query($conn,"select id from fseen_by where uid='$uid' and forum='$rid';");
if (!pg_numrows($fres)) $isnew='*';
}
$forum=pg_result($res,$i,1);
print "<a href=\"forum.php?f=".$rid."&lang=".$lang."\">".$isnew." ".$forum." (".$nthemes.") [".$nrepl."]</a><br/>".$note."<br/><br/>\n";
}
}
}
if (($f>0)&&(!$t)) {
header("Cache-Control: no-cache");
?>
<html>
<head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>
<body>
<?php
$res=pg_query($conn,"select name,flag from forums where id='$f';");
if (!pg_numrows($res)) { pg_close($conn); exit; }
$name=pg_result($res,0,0);
$flag=pg_result($res,0,1);
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 "<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=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=pg_result($res,$i,6);
$closed=pg_result($res,$i,7);
$sticker=pg_result($res,$i,8);
if ($closed) $isclosed='(closed)'; else $isclosed='';
if ($sticker=='t') $issticker='(*)'; else $issticker='';
$isnew='';
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=\"forum_del.php?t=".$id."\">[x]</a> <a href=\"forum_close.php?t=".$id."\">[c]</a> <a href=\"user_edit.php?id=".$fr_u."\">".$login." [".$rplnum."] <".$rdnum."></a> ".$time."<br/>".$name."<br/><a href=\"forum.php?t=".$id."&lang=".$lang."\">".$issticker.$isclosed.$isnew.">>>></a><br/>\n";
print "<hr>\n";
}
print "<br/>\n";
if ($p) print "<a href=\"forum.php?f=".$f."&p=".($p-1)."\">Prev ".$ftpp."</a><br/>";
if ($rows==$ftpp) print "<a href=\"forum.php?f=".$f."&p=".($p+1)."\">Next ".$ftpp."</a><br>";
print "<a href=\"forum.php\">уРЙУПЛ жПТХНПЧ</a> \n";
print "<a href=\"forum_post.php?f=".$f."\">оПЧБС ФЕНБ</a>\n";
}
if ($t>0) {
header("Cache-Control: no-cache");
?>
<html>
<head><meta http-equiv="Cache-Control" content="no-cache" forua="true"/></head>
<body>
<?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 from themes,forums where themes.id='$t' and forums.id=themes.forum;");
$f=pg_result($res,0,0);
$flag=pg_result($res,0,1);
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=pg_result($res,$i,1);
$fr_u=pg_result($res,$i,2);
$time=strftime("%d/%m %H:%M",pg_result($res,$i,3));
$login=pg_result($res,$i,4);
print "<a href=\"forum_del.php?pid=".$id."\">[x]</a> <a href=\"user_edit.php?id=".$fr_u."\">".$login."</a> ".$time."<br/>".$message."<br/>\n";
print "<hr>\n";
}
print "<br/>\n";
if ($p) print "<a href=\"forum.php?t=".$t."&p=".($p-1)."\">Prev ".$fppp."</a><br/>";
if ($rows==$fppp) print "<a href=\"forum.php?t=".$t."&p=".($p+1)."\">Next ".$fppp."</a>";
?>
<FORM NAME="message" METHOD=POST ACTION="forum_sign.php">
<input type="text" name="message" size="80">
<?php print "<input type=\"hidden\" name=\"t\" value=\"".$t."\">\n"; ?>
<INPUT TYPE=SUBMIT VALUE="рЕТЕУМБФШ">
</FORM>
<?php
print "<a href=\"forum.php?f=".$f."\">уРЙУПЛ фЕН</a>\n";
}
?>
</p>
</body>
</html>