Location: PHPKode > projects > Crown of Evanion > final/forums.php
<?php
/*
*   This file is part of 'Crown of Evanion'.
*
*    'Crown of Evanion' is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    'Crown of Evanion' is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with 'Crown of Evanion'; if not, write to the Free Software
*    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

# These forums are so sexy.

$title = "Forums";
include("include.php");

logincheck($Username);

if(!$page) {
	$select = mysql_query("SELECT * FROM forums WHERE stat <= '$Status'");
	echo "<div align=\"center\"><p class=\"drag\"><a href=\"codes.php\">Chat Codes</a> | <a href=\"avatar.php\">Avatars</a></p>
	<div class=\"forumfront\">
	<table cellspacing=\"1\" cellpadding=\"2\" id=\"forumfront\">
	<tr>
	<td bgcolor=\"red\">Name</td>
	<td bgcolor=\"red\">Description</td>
	<td bgcolor=\"red\">Posts</td>
	</tr>";
	
	while ($forums = mysql_fetch_array($select)) {
		$sel = mysql_query("SELECT id FROM forum_topics WHERE forum = '$forums[id]'");
		$num = mysql_num_rows($sel);
		if(!$num) {
			$num = "None!";
		}
		echo "<tr>
		<td bgcolor=\"white\"><div class=\"topic\"><a href=\"$PHP_SELF?page=viewforum&id=$forums[id]\">$forums[name]</a></div></td>
		<td bgcolor=\"white\">$forums[des]</td>
		<td bgcolor=\"white\">$num</td>
		</tr>";
	}
	echo "</table></div></div>";
}

if($page == "viewforum") {
	$select = mysql_query("SELECT id,name FROM forums WHERE id = '$id'");
	$num = mysql_num_rows($select);
	if(!$num) {
		forumkill("No such forum!");
	}
	$forums = mysql_fetch_array($select);
	echo "<div align=\"center\">
	<h3>$forums[name]</h3>
	<p class=\"drag\"><a href=\"$PHP_SELF?page=newtopic&forumid=$forums[id]\">Post Topic</a> | <a href=\"$PHP_SELF\">Home</a></p>";
	
	echo "<p class=\"drag\"><a href=\"codes.php\">Chat Codes</a></p>
	<div class=\"forumfront\">
	<table cellspacing=\"1\" cellpadding=\"2\" id=\"forumfront\">
	<tr>
	<td bgcolor=\"red\">Title</td>
	<td bgcolor=\"red\" width=\"20%\">Posted By</td>
	<td bgcolor=\"red\" width=\"10%\">Replies</td>
	</tr>";
	$select = mysql_query("SELECT * FROM forum_topics WHERE stuck = '1' AND forum = '$forums[id]' ORDER BY lastpost DESC");
	while($stucktopics = mysql_fetch_array($select)) {
		$sel = mysql_query("SELECT username FROM users WHERE id = '$stucktopics[poster]'");
		$poster = mysql_fetch_array($sel);
		
		$sel = mysql_query("SELECT id FROM forum_reply WHERE topic = '$stucktopics[id]'");
		$num = mysql_num_rows($sel);
		if(!$num) {
			$num = "None!";
		}
		if($stucktopics[locked]) {
			$a = "[";
			$b = "]";
		}
		echo "<tr>
		<td bgcolor=\"white\"><div class=\"topics\">$a<a href=\"$PHP_SELF?page=viewpost&id=$stucktopics[id]\">$stucktopics[topic]</a>$b</div></td>
		<td bgcolor=\"white\" width=\"20%\">$poster[username]</td>
		<td bgcolor=\"white\" width=\"10%\">$num</td>
		</tr>";
		$a = "";
		$b = "";
	}
	$select = mysql_query("SELECT * FROM forum_topics WHERE stuck = '0' AND forum = '$forums[id]' ORDER BY lastpost DESC LIMIT 35");
		
	while($topics = mysql_fetch_array($select)) {
		$sel = mysql_query("SELECT username FROM users WHERE id = '$topics[poster]'");
		$poster = mysql_fetch_array($sel);
		
		$sel = mysql_query("SELECT id FROM forum_reply WHERE topic = '$topics[id]'");
		$num = mysql_num_rows($sel);
		if(!$num) {
			$num = "None!";
		}
		if($topics[locked]) {
			$a = "[";
			$b = "]";
		}
		echo "<tr>
		<td bgcolor=\"white\"><div class=\"topic\">$a<a href=\"$PHP_SELF?page=viewpost&id=$topics[id]\" class=\"topic\">$topics[topic]</a>$b</div></td>
		<td bgcolor=\"white\" width=\"20%\">$poster[username]</td>
		<td bgcolor=\"white\" width=\"10%\">$num</td>
		</tr>";
	
		$a = "";
		$b = "";
		
		}
	echo "</table></div>";	
}

if($page == "viewpost") {
	echo "<!-- The CSS/HTML for the forum posts is pretty much ripped from Leif's RR site. Credit to him? Hope he doesn't mind =X -->";
	$select = mysql_query("SELECT * FROM forum_topics WHERE id = '$id'");
	$num = mysql_num_rows($select);
	
	if(!$num) {
		forumkill("No such post!");
	}
	$post = mysql_fetch_array($select);
	
	$select = mysql_query("SELECT id,name FROM forums WHERE id = '$post[forum]'");
	$forum = mysql_fetch_array($select);
	
	$select = mysql_query("SELECT id,username,usertitle,sig,avatar FROM users WHERE id = '$post[poster]'");
	$usr = mysql_fetch_array($select);  
	$message = filter($post[message],1);
	$sig = filter($usr[sig], 1);
	
	if($Status == 2) {
		$options = "<div class=\"black\"><a href=\"$PHP_SELF?page=deletetop&topic=$post[id]&forum=$forum[id]\">Delete</a></div>";
	}
	if($Status >= 3) {
		if(!$post[locked]) {
			$lock = "<div class=\"black\"><a href=\"$PHP_SELF?page=lock&topic=$post[id]&forum=$forum[id]\">Lock Topic</a></div>";
		} else {
			$lock = "<div class=\"black\"><a href=\"$PHP_SELF?page=unlock&topic=$post[id]&forum=$forum[id]\">Unlock Topic</a></div>";
		}
		
		if(!$post[stuck]) {		
			$stuck = "<div class=\"black\"><a href=\"$PHP_SELF?page=stick&topic=$post[id]&forum=$forum[id]\">Stick Topic</a></div>";
		} else {
			$stuck = "<div class=\"black\"><a href=\"$PHP_SELF?page=unstick&topic=$post[id]&forum=$forum[id]\">Unstick Topic</a></div>";
		}
		$options = "<div class=\"black\"><a href=\"$PHP_SELF?page=deletetop&topic=$post[id]&forum=$forum[id]\">Delete</a></div>
		<div class=\"black\"><a href=\"$PHP_SELF?page=edittop&topic=$post[id]&forum=$forum[id]\">Edit</a></div>" . $stuck . $lock;
	}
	
	$select = mysql_query("SELECT image,alt FROM avatars WHERE id = '$usr[avatar]'");
	$avatarinf = mysql_fetch_array($select);
	$avatar = $avatarinf[image];
	$avatartext = $avatarinf[alt];
	
	echo "<div align=\"center\"><p class=\"drag\"><a href=\"$PHP_SELF\">Forum Index</a> > <a href=\"$PHP_SELF?page=viewforum&id=$post[forum]\">$forum[name]</a> > <strong>$post[topic]</strong></p></div>";
	echo "<div class=\"firstforumpost\">
	<div class=\"forumpostinfo\">
	<div><strong>$usr[username]</strong></div>
	<div><img src=\"$avatar\" height=\"70\" width=\"70\" border=\"0\" alt=\"$avatartext\"></div>
	<div>$usr[usertitle]</div>
	<br />
	<div>$post[time]</div>
	$options
	</div>
	<div class=\"forumpostmessage\">$message
	<div class=\"forumpostsig\">$sig</div>
	</div>
	</div>";
	$select = mysql_query("SELECT * FROM forum_reply WHERE topic = '$post[id]' ORDER BY id ASC");
	while ($reply = mysql_fetch_array($select)) {
		if($Status == 2) {
			$option = "<div class=\"black\"><a href=\"$PHP_SELF?page=deleterep&reply=$reply[id]&post=$post[id]\">Delete</a></div>";
		}
		if($Status >= 3) {
			$option = "<div class=\"black\"><a href=\"$PHP_SELF?page=deleterep&reply=$reply[id]&post=$post[id]\">Delete</a></div>
			<div class=\"black\"><a href=\"$PHP_SELF?page=editrep&reply=$reply[id]&post=$post[id]\">Edit</a></div>";
		}
		
		$sel = mysql_query("SELECT username,usertitle,sig,avatar FROM users WHERE id = '$reply[poster]'");
		$usrr = mysql_fetch_array($sel);	
		$message = filter($reply[message],1);
		$sig = filter($usrr[sig], 1);	
		$sel = mysql_query("SELECT image,alt FROM avatars WHERE id = '$usrr[avatar]'");
		$avatarinf = mysql_fetch_array($sel);
		$avatar = $avatarinf[image];
		$avatartext = $avatarinf[alt];
	
		echo "<div class=\"forumpost\">
		<div class=\"forumpostinfo\">
		<div><strong>$usrr[username]</strong></div>
		<div><img src=\"$avatar\" height=\"70\" width=\"70\" border=\"0\" alt=\"$avatartext\"></div>
		<div>$usrr[usertitle]</div>
		<br />
		<div>$reply[time]</div>
		$option
		</div>
		<div class=\"forumpostmessage\">$message
		<div class=\"forumpostsig\">$sig</div>
		</div>
		</div>";
	}
	
	if(!$post[locked]) {
		echo "<br /><br /><br /><br /><br />
		<div align=\"left\">
		<div class=\"res\">
		<form action=\"$PHP_SELF\" method=\"POST\">
		<input type=\"hidden\" name=\"page\" value=\"reply\">
		<input type=\"hidden\" name=\"topic\" value=\"$post[id]\">
		<input type=\"hidden\" name=\"forum\" value=\"$forum[id]\">
		<p><strong>Reply</strong>
		<p><textarea name=\"message\" cols=\"40\" rows=\"7\"></textarea>
		<p><input type=\"submit\" value=\"Reply\"></p>
		</form></div></div>";
	}
}
if($page == "newtopic") {
	if(!$forumid) {
		$forumid = 1;
	}
	echo "<div align=\"center\"><p class=\"drag\"><a href=\"$PHP_SELF?page=newtopic&forumid=$forums[id]\">Post Topic</a> | <a href=\"$PHP_SELF\">Home</a></p>";
	
	echo "
	<form action=\"$PHP_SELF\" method=\"POST\">
	<input type=\"hidden\" name=\"page\" value=\"postnewpro\">
	<input type=\"hidden\" name=\"id\" value=\"$forumid\">
	<p><strong>Topic</strong> <input type=\"text\" name=\"topic\"></p>
	<p><strong>Message</strong></p>
	<p><textarea name=\"message\" cols=\"40\" rows=\"7\"></textarea></p>";
	
	if($Status >= 3) {
		echo "<p><strong>Stick</strong>
		<select name=\"stuck\">
		<option value=\"0\">No</option>
		<option value=\"1\">Yes</option>
		</select></p>
		<p><strong>Lock</strong>
		<select name=\"locked\">
		<option value=\"0\">No</option>
		<option value=\"1\">Yes</option>
		</select></p>";
	}
	
	echo "<p><input type=\"submit\" value=\"Post\"></p>
	</form></div>";
}

if($page == "postnewpro") {
	$id = $_POST['id'];
	$topic = $_POST['topic'];
	$message = $_POST['message'];
	$stuck = $_POST['stuck'];
	$locked = $_POST['locked'];
	
	$select = mysql_query("SELECT id,stat FROM forums WHERE id = '$id'");
	$num = mysql_num_rows($select);
	
	if(!$num) {
		forumkill("Error - The forum you want to post in does not exist.");
	}
	
	$forum = mysql_fetch_array($select);
	
	if($forum[stat] > $Status) {
		forumkill("Oh, just go to hell, wiseass.");
	}
	
	if(!$topic) {
		forumkill("You forgot to enter a topic.");
	}
	if(!$message) {
		forumkill("You forgot to enter a message.");
	}
	
	$thing = $user_data[lastpost] + 5;
	
	
	if($thing > $timeofu) {	
		forumkill("Christ, you fucking spammer! Give it five fucking seconds!");
	}
	if(!$locked) {
		$locked = 0;
	}
	if(!$stuck) {
		$stuck = 0;
	}
	mysql_query("INSERT INTO forum_topics (topic,message,poster,time,lastpost,forum,stuck,locked) VALUES ('$topic','$message','$UserID','$date <br /> $time','$timeofu','$forum[id]','$stuck','$locked')") or die("Error - " . mysql_error());
	header("location: $PHP_SELF?page=viewforum&id=$forum[id]");
}

if($page == "reply") {
	$message = $_POST['message'];
	$topic = $_POST['topic'];
	$forum = $_POST['forum'];
	
	$select = mysql_query("SELECT id,locked FROM forum_topics WHERE id = '$topic'");
	$numtop = mysql_num_rows($select);
	$topinf = mysql_fetch_array($select);
	$select = mysql_query("SELECT id,stat FROM forums WHERE id = '$forum'");
	$numfor = mysql_num_rows($select);
	$for = mysql_fetch_array($select);
	
	if(!$numfor) {
		forumkill("The forum you are trying to post on does not exist.");
	}
	if($for[stat] > $Status) {
		forumkill("Oh, just go to hell, wiseass.");
	}
	if(!$numtop) {
		forumkill("That topic does not exist!");
	}
	if($topinf[locked]) {
		forumkill("That topic is locked!");
	}
	mysql_query("INSERT INTO forum_reply (message,time,poster,topic) VALUES ('$message','$date <br /> $time','$UserID','$topic')") or die("Error - " . mysql_error());
	mysql_query("UPDATE forum_topics SET lastpost = '$timeofu' WHERE id = '$topic'") or die("ERROR!");
	mysql_query("UPDATE users SET lastpost = '$timeofu' WHERE id = '$UserID'");
	header("location: $PHP_SELF?page=viewpost&id=$topic");
	die;
	
}

if($Status >= 2) {

	if($page == "deletetop") {	
		$select = mysql_query("SELECT poster FROM forum_topics WHERE id = '$topic'");
		$num = mysql_num_rows($select);
		$top = mysql_fetch_array($select);
		
		if(!$num) {
			forumkill("No such topic.");
		}
		
		mysql_query("INSERT INTO deletelog (staff,poster,wen,type) VALUES ('$UserID','$top[poster]','$date $time','topic')");
		mysql_query("DELETE FROM forum_topics WHERE id = '$topic'");
		mysql_query("DELETE FROM forum_reply WHERE topic = '$topic'");
		header("location: $PHP_SELF?page=viewforum&id=$forum");
	}

	if($page == "deleterep") {	
		$select = mysql_query("SELECT poster FROM forum_reply WHERE id = '$reply'");
		$num = mysql_num_rows($select);
		$top = mysql_fetch_array($select);
		
		if(!$num) {
			forumkill("No such topic.");
		}
		
		mysql_query("INSERT INTO deletelog (staff,poster,wen,type) VALUES ('$UserID','$top[poster]','$date $time','reply')");
		mysql_query("DELETE FROM forum_reply WHERE id = '$reply'");
		header("location: $PHP_SELF?page=viewpost&id=$post");
	}
}

if($Status >= 3) {
	if($page == "edittop") {
		$select = mysql_query("SELECT * FROM forum_topics WHERE id = '$topic'");
		$num = mysql_num_rows($select);
		$top = mysql_fetch_array($select);
		
		if(!$num) {
			forumkill("No such topic.");
		}
	
		echo "<form action=\"$PHP_SELF\" method=\"POST\">
		<input type=\"hidden\" name=\"page\" value=\"edittoppro\">
		<input type=\"hidden\" name=\"topicid\" value=\"$topic\">
		<p><strong>Topic</strong> <input type=\"text\" name=\"topic\" value=\"$top[topic]\"></p>
		<p><strong>Message</strong></p>
		<p><textarea name=\"message\" cols=\"40\" rows=\"7\">$top[message]</textarea></p>
		<p><input type=\"submit\" value=\"Edit\"></p>
		</form>";
}
	
	if($page == "edittoppro") {
		$topicid = $_POST['topicid'];
		$topic = $_POST['topic'];
		$message = $_POST['message'];
		
		if(!$topic) {
			forumkill("You can't leave the topic blank.");
		}
		if(!$message) {
			forumkill("You can't leave the message blank.");
		}
		
		mysql_query("UPDATE forum_topics SET topic = '$topic' WHERE id = '$topicid'");
		mysql_query("UPDATE forum_topics SET message = '$message' WHERE id = '$topicid'");
		header("location: $PHP_SELF?page=viewpost&id=$topicid");
		die;
	}
	
		if($page == "editrep") {
		$select = mysql_query("SELECT * FROM forum_reply WHERE id = '$reply'");
		$num = mysql_num_rows($select);
		$rep = mysql_fetch_array($select);
		
		if(!$num) {
			forumkill("No such reply.");
		}
	
		echo "<form action=\"$PHP_SELF\" method=\"POST\">
		<input type=\"hidden\" name=\"page\" value=\"editreppro\">
		<input type=\"hidden\" name=\"topic\" value=\"$post\">
		<input type=\"hidden\" name=\"reply\" value=\"$reply\">
		<p><strong>Message</strong></p>
		<p><textarea name=\"message\" cols=\"40\" rows=\"7\">$rep[message]</textarea></p>
		<p><input type=\"submit\" value=\"Edit\"></p>
		</form>";
}
	if($page == "editreppro") {
		$topic = $_POST['topic'];
		$reply = $_POST['reply'];
		$message = $_POST['message'];
		
		if(!$message) {
			forumkill("You can't leave the message blank.");
		}
		mysql_query("UPDATE forum_reply SET message = '$message' WHERE id = '$reply'");
		header("location: $PHP_SELF?page=viewpost&id=$topic");
		die;
	}
	if($page == "stick") {
		$select = mysql_query("SELECT id FROM forum_topics WHERE id = '$topic'");
		$num = mysql_num_rows($select);
		
		if(!$num) {	
			forumkill("No such topic.");
		}
		
		mysql_query("UPDATE forum_topics SET stuck = '1' WHERE id = '$topic'");
		header("location: $PHP_SELF?page=viewpost&id=$topic");
	}
	if($page == "unstick") {
		$select = mysql_query("SELECT id FROM forum_topics WHERE id = '$topic'");
		$num = mysql_num_rows($select);
		
		if(!$num) {	
			forumkill("No such topic.");
		}
		
		mysql_query("UPDATE forum_topics SET stuck = '0' WHERE id = '$topic'");
		//header("location: $PHP_SELF?page=viewforum&id=$forum");
		header("location: $PHP_SELF?page=viewpost&id=$topic");
	}
	if($page == "lock") {
		$select = mysql_query("SELECT id FROM forum_topics WHERE id = '$topic'");
		$num = mysql_num_rows($select);
		
		if(!$num) {	
			forumkill("No such topic.");
		}
		
		mysql_query("UPDATE forum_topics SET locked = '1' WHERE id = '$topic'");
		header("location: $PHP_SELF?page=viewpost&id=$topic");
	}
	if($page == "unlock") {
		$select = mysql_query("SELECT id FROM forum_topics WHERE id = '$topic'");
		$num = mysql_num_rows($select);
		
		if(!$num) {	
			forumkill("No such topic.");
		}
		
		mysql_query("UPDATE forum_topics SET locked = '0' WHERE id = '$topic'");
		header("location: $PHP_SELF?page=viewpost&id=$topic");
	}
}	
	
include("footer.php");	
Return current item: Crown of Evanion