forums.php
<?php
session_start();
include 'include/config.php';
echo ' <p><span class="pagetitle">IceRegent NetWorx User Forums</span></p>';
echo '<div class="forums">';
if($_SESSION['valid'] <> "yes") //Let user know they must be logged in before they can post - from valid session info
{
echo '<b> You must be logged in to post to the User Forums section </b>';
} //End LOGGED IN
if($_GET['select'] == "forums") //If user selected the forums, intitiate and display the main forum display section
{
$_SESSION['return'] = NULL;
$_SESSION['select'] = "forums";
$_SESSION['forum'] = "view";
$_SESSION['ftitle'] = NULL;
$_SESSION['origthread'] = NULL;
$_SESSION['topic'] = NULL;
echo '<span class="route"><h3><a href="index.php?select=forums" target ="_self">Forums</a></h3></span>';
echo '<table class="forumslist">';
mysql_select_db(iceregen_bands);
$query = "SELECT * FROM forumcat";
$result = mysql_query($query) or exit(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo '<tr><td><a href="index.php?ftitle='. $row['forumtitle'] . '" target ="_self">' . $row['forumtitle'] . '</a></td></tr>';
}
echo '</table>';
mysql_close();
} //End MAIN FORUM DISPLAY section
if($_GET['forum'] == "post") //If user has selected to POST NEW TOPIC, then display POST NEW TOPIC form
{
$posttopic = $_SESSION['ftitle'];
echo '<span class="route"><a href="index.php?select=forums" target ="_self"><h3>Forums</a> - ';
echo '<a href="index.php?ftitle='. $_SESSION['ftitle'] . '" target ="_self">' . $_SESSION['ftitle'] . '</a></h3></span>';
echo '<form action="index.php" method="post" value="yes">';
echo '<table>';
echo '<tr>';
echo '<td>Forum Posting to:</td><td>' . $posttopic . '</td>';
echo '</tr>';
echo '<input type="hidden" name="fpost" value="yes">';
echo '<tr>';
echo '<td>Forum Topic?</td><td><input type="text" name="ftopic"></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Your Content:</td><td><textarea name="fcontent" rows="3" cols="30"></textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="submit" value="Post Topic"><input type="reset"></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
} //End of POST NEW TOPIC display form
if($_POST['fpost'] == "yes") //If POST NEW TOPIC form has been submitted, then process the form
{
$_POST['fpost'] = NULL;
$_SESSION['return'] = "titles";
$ftitle=$_SESSION['ftitle'];
$ftopic=$_POST['ftopic'];
$fcontent=$_POST['fcontent'];
$ftopic = stripslashes($ftopic);
$ftopic = mysql_real_escape_string($ftopic);
$fcontent = stripslashes($fcontent);
$fcontent = mysql_real_escape_string($fcontent);
$user=$_SESSION['user'];
$fdate=date("y-m-d H:i:s", time());
$query = "INSERT INTO forumtop (ftid, forumtitle, topic, forumcont, uid, date, subtopic) VALUES (NULL, '$ftitle', '$ftopic', '$fcontent', '$user', '$fdate', NULL)";
$result = mysql_query($query) or exit(mysql_error());
} //End of POST NEW TOPIC processing section
if(($_GET['ftitle'] <> NULL) or ($_SESSION['return'] == "titles")) //If user has chosen a Forum to view, display all topics in the chosen forum
{
$_SESSION['return'] = NULL;
$_SESSION['ftitle'] = $_GET['ftitle'];
if($_SESSION['valid'] == "yes") //If user is logged in, display option to post a new topic
{
echo '<table class="button1">';
echo '<tr><td><a href="index.php?forum=post" target ="_self">NEW TOPIC</a></td></tr>';
echo '</table>';
} //End NEW TOPIC
echo '<span class="route"><h3><a href="index.php?select=forums" target ="_self">Forums</a> - ';
echo '<a href="index.php?ftitle='. $_SESSION['ftitle'] . '" target ="_self">' . $_SESSION['ftitle'] . '</a></h3></span>';
echo '<table class="forumslist">';
$ftitle=$_GET['ftitle'];
mysql_select_db(iceregen_bands);
$query = "SELECT ftid, topic, subtopic FROM forumtop WHERE forumtitle='$ftitle'";
$result = mysql_query($query) or exit(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
if($row['subtopic'] == NULL)
{
echo '<tr><td><a href="index.php?topic='. $row['topic'] . '" target ="_self">' . $row['topic'] . '</a></td></tr>';
}
}
echo '</table>';
mysql_close();
} //End DISPLAY ALL TOPICS section
if($_GET['topic'] <> NULL) //If user has selected a topic, then display all messages posted to that topic
{
echo '<span class="route"><h3><a href="index.php?select=forums" target ="_self">Forums</a> - ';
echo '<a href="index.php?ftitle='. $_SESSION['ftitle'] . '" target ="_self">' . $_SESSION['ftitle'] . '</a></h3></span>';
$_SESSION['return'] = NULL;
$ftopic=$_GET['topic'];
$_SESSION['topic'] = $ftopic;
mysql_select_db(iceregen_bands);
$query = "SELECT * FROM forumtop WHERE topic='$ftopic'";
$result = mysql_query($query) or exit(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo '<table class="forumtopic">';
echo '<tr><td><b>TOPIC : </b>' . $row['topic'] . '</td></tr>';
echo '<tr><td><b>POSTED BY: </b>' . $row['uid'] . '</td></tr>';
echo '<tr><td class="lace"><b>THREAD: </b>' . $row['forumcont'] . '</td></tr>';
echo '<tr><td><b>Date Posted: </b>' . $row['date'] . '</td></tr>';
// echo '<tr><td><b>Sub Topic: </b>' . $row['subtopic'] . '</td></tr>';
echo '</table>';
if($row['subtopic'] <> NULL)
{
$_SESSION['origthread'] = $row['subtopic'];
}
if($row['subtopic'] == NULL)
{
$_SESSION['origthread'] = $row['ftid'];
}
} //End Display single Topics
if($_SESSION['valid'] == "yes")
{
echo '<table class="button1">';
echo '<tr><td><a href="index.php?forum=reply" target ="_self">REPLY THREAD</a></td></tr><br>';
echo '</table>';
}
mysql_close();
} //End DISPLAY ALL MESSAGES in Selected Topic
if($_GET['forum'] == "reply") //Display the reply to message topic form
{
echo '<span class="route"><h3><a href="index.php?select=forums" target ="_self">Forums</a> - ';
echo '<a href="index.php?ftitle='. $_SESSION['ftitle'] . '" target ="_self">' . $_SESSION['ftitle'] . '</a></h3></span>';
$postforum=$_SESSION['ftitle'];
$posttopic=$_SESSION['topic'];
$origthread=$_SESSION['origthread'];
echo '<form action="index.php" method="post">';
echo '<table>';
echo '<input type="hidden" name="tpost" value="yes">';
echo '<tr>';
echo '<td>Forum Posting to:</td><td>' . $postforum . '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Original Thread:</td><td>' . $posttopic . '</td>';
echo '</tr>';
echo '<td>Your Reply:</td><td><textarea name="fcontent" rows="3" cols="30"></textarea></td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="submit" value="Post Reply"><input type="reset"></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
} //End REPLY to MESSAGE form
if($_POST['tpost'] == "yes") //If user has hit the submit button on the REPLY to MESSAGE form, process the data
{
$_POST['tpost'] = NULL;
$_SESSION['return'] = "forums";
$ftitle=$_SESSION['ftitle'];
$ftopic=$_SESSION['topic'];
$fcontent=$_POST['fcontent'];
$ftoporig=$_SESSION['origthread'];
$fcontent = stripslashes($fcontent);
$fcontent = mysql_real_escape_string($fcontent);
$user=$_SESSION['user'];
$fdate=date("y-m-d H:i:s", time());
$query = "INSERT INTO forumtop (ftid, forumtitle, topic, forumcont, uid, date, subtopic) VALUES (NULL, '$ftitle', '$ftopic', '$fcontent', '$user', '$fdate', '$ftoporig')";
$result = mysql_query($query) or exit(mysql_error());
} //End Process REPLY to MESSAGE
if($_SESSION['return'] == "forums") //If reply has posted, return to this point
{
echo '<span class="route"><h3><a href="index.php?select=forums" target ="_self">Forums</a> - ';
echo '<a href="index.php?ftitle='. $_SESSION['ftitle'] . '" target ="_self">' . $_SESSION['ftitle'] . '</a></h3></span>';
$_SESSION['return'] = NULL;
$ftopic = $_SESSION['topic'];
include 'include/config.php';
mysql_select_db(iceregen_bands);
$query = "SELECT * FROM forumtop WHERE topic='$ftopic'";
$result = mysql_query($query) or exit(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo '<table class="forumtopic">';
echo '<tr><td><b>TOPIC : </b>' . $row['topic'] . '</td></tr>';
echo '<tr><td><b>POSTED BY: </b>' . $row['uid'] . '</td></tr>';
echo '<tr><td class="lace"><b>THREAD: </b>' . $row['forumcont'] . '</td></tr>';
echo '<tr><td><b>Date Posted: </b>' . $row['date'] . '</td></tr>';
// echo '<tr><td><b>Sub Topic: </b>' . $row['subtopic'] . '</td></tr>';
echo '</table>';
if($row['subtopic'] <> NULL)
{
$_SESSION['origthread'] = $row['subtopic'];
}
if($row['subtopic'] == NULL)
{
$_SESSION['origthread'] = $row['ftid'];
}
}
} //End Display single Topics
echo '</div>';
?>
So, I know there are numerous way to do things better, but, as I said, I am not a pro,so I am doing the best I can.
Ice