rendered paste body<?php
/*---------------------------------------------
-- In Game Forums
-- Made And Copyrighted By
-- RC
----------------------------------------------
*/
session_start();
require "global_func.php";
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
global $c;
$is=mysql_query("SELECT u.*,us.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid WHERE u.userid=$userid",$c) or die(mysql_error());
$ir=mysql_fetch_array($is);
check_level();
$fm=money_formatter($ir['money']);
$cm=money_formatter($ir['credits'],'');
$lv=date('F j, Y, g:i a',$ir['laston']);
$h->userdata($ir,$lv,$fm,$cm);
$h->menuarea();
print "<h3>Forums</h3><hr />";
if($ir['forumban'])
{
die("<font color=red><h3>! ERROR</h3>
You have been forum banned for {$ir['forumban']} days.<br />
<br />
<b>Reason: {$ir['fb_reason']}</font></b>");
}
$_GET['viewforum']=(int) $_GET['viewforum'];
if($_GET['viewtopic'] and $_GET['act'] != 'quote') { $_GET['act']='viewtopic'; }
if($_GET['viewforum']) { $_GET['act']='viewforum'; }
if($_GET['reply']) { $_GET['act']='reply'; }
if($_GET['empty']==1 && $_GET['code']=='kill' && $_SESSION['owner'])
{
emptyallforums();
}
function forum()
{
$_GET['topic'] = abs((int) $_GET['topic']);
$_GET['reply'] = abs((int) $_GET['reply']);
$_GET['t'] = abs((int) $_GET['t']);
global $ir,$c,$userid,$data;
if($_GET['topic'])
{
$_GET['act2']="viewtopic";
$_GET['t']=$_GET['topic'];
}
if($_GET['reply'])
{
$_GET['act2']="reply";
$_GET['t']=$_GET['reply'];
}
switch($_GET['act2'])
{
case "forum":
forum();
break;
case 'viewforum':
viewforum();
break;
case 'viewtopic':
viewtopic();
break;
case "reply":
forums_reply();
break;
case "newtopicform":
forums_newt_form();
break;
case "newtopicsub":
forums_newt_sub();
break;
default:
forums_idx();
break;
}
}
function forums_idx()
{
global $ir, $c, $userid, $h, $bbc;
$q=mysql_query("SELECT * FROM forum_forums WHERE ff_auth='public' ORDER BY ff_id ASC", $c) or die(mysql_error());
print "<table width='100%' border='2'>
<tr><th>Forum</th> <th>Posts</th> <th>Topics</th> <th>Last Post</th> </tr>\n";
while($r=mysql_fetch_array($q))
{
$t=date('F j Y, g:i:s a',$r['ff_lp_time']);
print "<tr> <td><a href='forums.php?viewforum={$r['ff_id']}' style='font-weight: 800'>{$r['ff_name']}</a><br /><small>{$r['ff_desc']}</small></td> <td>{$r['ff_posts']}</td> <td>{$r['ff_topics']}</td> <td>$t<br />
In: <a href='forums.php?viewtopic={$r['ff_lp_t_id']}&lastpost=1' style='font-weight: 800'>{$r['ff_lp_t_name']}</a><br />
By: <a href='viewuser.php?u={$r['ff_lp_poster_id']}'>{$r['ff_lp_poster_name']}</a> </td> </tr>\n";
}
print "\n</table>";
if($ir['user_level'] <> 1)
{
print "<hr /><a name='staff'><h3>Staff-Only Forums</h3></a><hr />";
$q=mysql_query("SELECT * FROM forum_forums WHERE ff_auth='staff' ORDER BY ff_id ASC", $c) or die(mysql_error());
print "<table width='100%' border='2'>
<tr><th>Forum</th> <th>Posts</th> <th>Topics</th> <th>Last Post</th> </tr>\n";
while($r=mysql_fetch_array($q))
{
$t=date('F j Y, g:i:s a',$r['ff_lp_time']);
print "<tr> <td><a href='forums.php?viewforum={$r['ff_id']}' style='font-weight: 800'>{$r['ff_name']}</a><br /><small>{$r['ff_desc']}</small></td> <td>{$r['ff_posts']}</td> <td>{$r['ff_topics']}</td> <td>$t<br />
In: <a href='forums.php?viewtopic={$r['ff_lp_t_id']}&lastpost=1' style='font-weight: 800'>{$r['ff_lp_t_name']}</a><br />
By: <a href='viewuser.php?u={$r['ff_lp_poster_id']}'>{$r['ff_lp_poster_name']}</a> </td> </tr>\n";
}
print "\n</table>";
}
$stats=cache_get('forumstats',$c);
print "<br /><br /><b>Forum Stats</b> (Updated Hourly)<br />
<b>{$stats['membs']}</b> MC players have posted at least 1 of the <b>{$stats['posts']}</b> posts in <b>{$stats['topics']}</b> topics.";
}
print "</table>";
}
function viewforum()
{
global $ir, $c, $userid, $h, $bbc;
$q=mysql_query("SELECT * FROM forum_forums WHERE ff_id={$_GET['viewforum']}", $c);
$r=mysql_fetch_array($q);
if($r['ff_auth']=='gang' OR ($r['ff_auth'] == 'staff' AND $ir['user_level'] < 2))
{
print "You have no permission to view this forum.<br />
> <a href='forums.php'>Back</a>";
$h->endpage();
exit;
}
if($_GET['viewforum'] <> 1 OR $ir['user_level']==2)
{
$ntl=" [<a href='forum.php?act=newtopicform&forum={$_GET['viewforum']}'>New Topic</a>]";
}
else
{
$ntl="";
}
print "<big><a href='forums.php'>Forums Home</a> >> <a href='forums.php?viewforum={$_GET['viewforum']}'>{$r['ff_name']}</a>$ntl</big><br /><br />
<table width='100%' border='2'>
<tr> <th>Topic</th> <th>Posts</th> <th>Started</th> <th>Last Post</th></tr>\n";
$q=mysql_query("SELECT * FROM forum_topics WHERE ft_forum_id={$_GET['viewforum']} ORDER BY ft_pinned DESC, ft_last_time DESC", $c) or die(mysql_error());
while($r2=mysql_fetch_array($q))
{
$t1=date('F j Y, g:i:s a',$r2['ft_start_time']);
$t2=date('F j Y, g:i:s a',$r2['ft_last_time']);
if($r2['ft_pinned']) { $pt="<b>Pinned:</b> "; } else { $pt=""; }
if($r2['ft_locked']) { $lt=" <b>(Locked)</b>"; } else { $lt=""; }
print "<tr> <td>$pt<a href='forums.php?viewtopic={$r2['ft_id']}&lastpost=1'>{$r2['ft_name']}</a>$lt<br />
<small>{$r2['ft_desc']}</small></td> <td>{$r2['ft_posts']}</td> <td>$t1<br />
By: <a href='viewuser.php?u={$r2['ft_owner_id']}'>{$r2['ft_owner_name']}</a></td> <td>$t2<br />
By: <a href='viewuser.php?u={$r2['ft_last_id']}'>{$r2['ft_last_name']}</a></td> </tr>\n";
}
print "</table>";
}
function forums_viewtopic()
{
global $ir,$c,$userid,$data;
$tpcd=mysql_query("SELECT t.*,u1.* FROM forums_topics t LEFT JOIN users u1 ON t.ft_userid=u1.userid WHERE t.ft_id={$_GET['t']}",$c);
mysql_query("UPDATE forums_topics SET ft_views=ft_views+1 WHERE ft_id={$_GET['t']}",$c);
$topic=mysql_fetch_array($tpcd);
$posts[0]['username']=$topic['username'];
$posts[0]['userid']=$topic['userid'];
$posts[0]['time']=$topic['ft_starttime'];
$posts[0]['level']=$topic['level'];
$posts[0]['nr']=1;
$posts[0]['text']=str_replace("\n","<br />",$topic['ft_text']);
$cntr=0;
$pq=mysql_query("SELECT r.*,u.* FROM forums_replies r LEFT JOIN users u ON r.fr_userid=u.userid WHERE r.fr_topic={$_GET['t']} ORDER BY fr_posttime ASC;",$c);
while($r=mysql_fetch_array($pq))
{
$cntr++;
$posts[$cntr]['username']=$r['username'];
$posts[$cntr]['userid']=$r['userid'];
$posts[$cntr]['time']=$r['fr_posttime'];
$posts[$cntr]['level']=$r['level'];
$posts[$cntr]['nr']=$cntr+1;
$posts[$cntr]['text']=str_replace("\n","<br />",$r['fr_text']);
}
print "<table width=80% border=2><tr style='background:black;'><th colspan=2>{$topic['ft_title']}</th></tr>";
foreach($posts as $cpost)
{
print "<tr><td>Post #{$cpost['nr']}</td><td>Time Posted: ".date('F j Y, g:i:s a',$cpost['time'])."</td></tr>
<tr><td><a href='viewuser.php?u={$cpost['userid']}'>{$cpost['username']}</a><br />Level: {$cpost['level']}</td><td>{$cpost['text']}</td></tr>";
}
print "</table>";
print "<br /><table width=80% border=2><tr style='background: black;'><th>Add Reply</th></tr>";
print "<tr><td align=center><form action='forum.php?action=forums&reply={$_GET['t']}' method='post'><b>Your Post:</b> (no HTML, linebreaks automatically converted to <br />)<br />
<textarea rows=10 cols=80 name='textpost'></textarea><br />
<input type='submit' value='Post' /></form></td></tr></table>";
}
function forums_reply()
{
global $ir,$c,$userid,$data;
$t=$_GET['t'];
$post=str_replace(array("<",">","'"),array("<",">","''"),$_POST['textpost']);
mysql_query("INSERT INTO forums_replies VALUES('',$userid,{$data['ID']},$t,'$post',unix_timestamp())",$c);
mysql_query("UPDATE forums_topics SET ft_replies=ft_replies+1,ft_lastpost=unix_timestamp(),ft_lastposterid=$userid WHERE ft_id=$t",$c);
print "<table width=80% border=2><tr style='background:black;'><th>News</th></tr><tr><td align=center>Reply Posted!</td></tr></table><br />";
forums_viewtopic();
}
function forums_newt_form()
{
global $ir,$c,$userid,$data;
print "<b>Creating New Topic....</b><br />
<table border=2>
<form action='.php?action=forums&act2=newtopicsub' method='post'>
<tr><td>Title:</td><td> <input type='text' name='topictitle' value='' /></td></tr>
<tr><td><b>Your Topic:</b> <br /><small>(no HTML, linebreaks automatically converted to <br />)</small></td><td><textarea rows=7 cols=40 name='topictext'></textarea></td></tr><tr>
<td colspan=2 align=center><input type='submit' value='Post' /></td></tr></form></table>";
}
function forums_newt_sub()
{
global $ir,$c,$userid,$data;
$title=str_replace(array("<",">","'"),array("<",">","''"),$_POST['topictitle']);
$post=str_replace(array("<",">","'"),array("<",">","''"),$_POST['topictext']);
mysql_query("INSERT INTO forums_topics VALUES('',$userid,{$data['ID']},'$title','$post',0,0,unix_timestamp(),$userid,
unix_timestamp())",$c);
$iq=mysql_query("SELECT max(ft_id) AS tid FROM forums_topics",$c);
$iee=mysql_fetch_array($iq);
print "<table width=80% border=2><tr style='background:black;'><th>News</th></tr><tr><td align=center>Topic Posted!</td></tr></table><br />";
$_GET['t']=$iee['tid'];
forums_viewtopic();
}
$h->endpage();
?>