Location: PHPKode > projects > SiteX > forums_view.php
<?PHP
ob_start();
session_start();
include("includes/globals.php.inc");
include("includes/functions.php");
include("lang/English.php");
if(strtolower($sxSetup['Language']) != 'english') include("lang/".$sxSetup['Language'].".php");
include("themes/$THEME_FOLDER/config.php.inc");

protectComponentPage(6);

$forumid = intval($forumid);
protectPrivateForum($forumid);

// Search forums only
if($search_text_forum)
{
	header("Location: search.php?type=forum&search=".urlencode($search_text_forum));
	die();
}

// Subscribe to forum
if($subscribe == 1)
{
	$query = "INSERT INTO $DB_Forums_Notify (userid, notified, id_type, id_num) VALUES ('$THIS_USER', '0', 'forum', '$forumid')";
	$result = mysql_query($query, $Link) or queryError("69", mysql_error());
}

// Unsubscribe to forum
if($unsubscribe == 1)
{
	$query = "DELETE FROM $DB_Forums_Notify WHERE userid='$THIS_USER' AND id_type='forum' AND id_num='$forumid'";
	$result = mysql_query($query, $Link) or queryError("70", mysql_error());
}

// Clear notified flags for forum
$query = "UPDATE $DB_Forums_Notify SET notified='0' WHERE userid='$THIS_USER' AND id_num='$forumid' AND id_type='forum'";
$result = mysql_query($query, $Link) or queryError("71", mysql_error());

// Count topics
$query = "SELECT * FROM $DB_Forums_Posts WHERE forumid='$forumid' AND replyto='0'";
$result = mysql_query($query, $Link) or queryError("71", mysql_error());
$totalTopics = mysql_num_rows($result);

// Fetch forum info
$query = "SELECT * FROM $DB_Forums WHERE id='$forumid'";
$result = mysql_query($query, $Link) or queryError("72", mysql_error());
$ROW = mysql_fetch_object($result);

// Create page number
if(!$page)
	$page = 1;
$start = ($page - 1)*$sxSetup['ForumTopicsPerPage'];

$sxTitleAddendum = getComponentName("6").' - '.$ROW->name;
include("themes/$THEME_FOLDER/header.php");
?>
 <div class="bodyWrapper">
 <h1><?PHP echo getComponentName("6"); ?></h1>
  <table border="0" cellpadding="3" cellspacing="0" width="<?PHP echo $sxSetup['ForumWidth']; ?>" align="center">
	<tr>
	  <td><span class="sxSmallText"><a href="forums.php"><?PHP echo getComponentName("6"); ?></a> > <?PHP echo $ROW->name; ?></span></td>
	</tr>
	<tr>
	  <td><div style="float:left;" class="sxLargeText"><?PHP echo $ROW->name; ?></div>
	  <div style="float:right;"><a href="forums_post.php?forumid=<?PHP echo $forumid; ?>"><?PHP echo $sxLang['ForumLinkAddTopic']; ?></a></div>
	  </td>
	</tr>
	<tr>
	  <td><?PHP
		if($totalTopics > $sxSetup['ForumTopicsPerPage']) echo '<div style="padding-top:8px;padding-bottom:8px;font-size:10px;">';
		pageTurns($PHP_SELF.'?forumid=' . $forumid . '&', $totalTopics, $page, $sxSetup['ForumTopicsPerPage']);
		if($totalTopics > $sxSetup['ForumTopicsPerPage']) echo '</div>';
	  ?></td>
	</tr>
  </table>
  <table border="0" cellspacing="1" cellpadding="6" width="<?PHP echo $sxSetup['ForumWidth']; ?>" align="center">
	<tr>
	  <td class="tableColumn"><?PHP echo $sxLang['ForumItemTopic']; ?></td>
	  <td class="tableColumn"><?PHP echo $sxLang['ForumItemReplies']; ?></td>
	  <td class="tableColumn"><?PHP echo $sxLang['ForumItemAuthor']; ?></td>
	  <td class="tableColumn"><?PHP echo $sxLang['ForumItemViews']; ?></td>
	  <td class="tableColumn"><?PHP echo $sxLang['ForumItemLastPost']; ?></td>
	</tr>
	<?PHP
		
	$query = "SELECT * FROM $DB_Forums_Posts WHERE forumid='$forumid' AND replyto='0' ORDER BY sticky DESC, updated DESC LIMIT $start, ".$sxSetup['ForumTopicsPerPage'];
	$result = mysql_query($query, $Link) or queryError("777", mysql_error());
	while($ROW = mysql_fetch_object($result)){
		
		echo '<tr bgcolor="' . $sxTheme['ColorTableRow'] . '">';
		echo '<td nowrap="nowrap"><table border="0" cellpadding="0" cellspacing="0"><tr><td>';
		echo '<table border="0" style="width:5px;height:12px;" bgcolor="';
		
		$uid = $HTTP_SESSION_VARS['userid'];
			
		$query3 = "SELECT * FROM $DB_Forums_Unread, $DB_Forums_Posts
				   WHERE $DB_Forums_Posts.id=$DB_Forums_Unread.postid AND
						 $DB_Forums_Unread.userid='$uid' AND (
						 $DB_Forums_Posts.replyto='$ROW->id' OR
						 $DB_Forums_Posts.id='$ROW->id')";
		$result3 = mysql_query($query3, $Link) or queryError("71", mysql_error());
		
		if(mysql_num_rows($result3))
			echo $sxTheme['ColorTextTable'];
		else
			echo  $sxTheme['ColorTable'];
		
		echo '">';
		echo '<tr><td></td></tr></table></td><td width="8">&nbsp;</td><td>';
		
		if($ROW->sticky)
			echo '<img alt="' . $sxLang['ForumTopicSticky'] . '" src="images/sticky.gif" style="border: 0;" align="absmiddle" /> ';
		
		if($ROW->topic)
			echo '<strong><a href="forums_topic.php?topicid=' . $ROW->id . '">' . limitString($ROW->topic, 40) . '</a>';
		else
			echo '<strong><a href="forums_topic.php?topicid=' . $ROW->id . '">[' . $sxLang['ForumUntitledTopic'] . ']</a>';
					
		$query0 = "SELECT * FROM $DB_Forums_Posts WHERE id='$ROW->id' OR replyto='$ROW->id'";
		$result0 = mysql_query($query0, $Link) or queryError("73", mysql_error());
		$totalPosts = mysql_num_rows($result0);
		
		echo '<span class="sxSmallText">';
		pageTurnsSpecial('forums_topic.php?topicid=' . $ROW->id . '&', $totalPosts, $sxSetup['ForumPostsPerPage']);
		echo '</span>';
		
		if($ROW->locked)
			echo ' <span class="sxSmallText">(' . $sxLang['ForumLocked'] . ')</span>';
		echo '</strong></td></tr></table></td>';
		
		echo '<td>';
		$query2 = "SELECT * FROM $DB_Forums_Posts WHERE replyto='$ROW->id'";
		$result2 = mysql_query($query2, $Link) or queryError("74", mysql_error());
		echo mysql_num_rows($result2);
		echo '</td>';
		
		if($ROW->userid != 0){
			$query2 = "SELECT * FROM $DB_Users WHERE id='$ROW->userid'";
			$result2 = mysql_query($query2, $Link) or queryError("75", mysql_error());
			$ROW2 = mysql_fetch_object($result2);			
			echo '<td><a href="admin/profile_view.php?user=' . $ROW2->username . '"><span class="sxSmallText">' . $ROW2->username . '</span></a></td>';
		}else echo '<td><span class="sxSmallText">' . $sxLang['Anonymous'] . '</span></td>';
		
		echo '<td>' . number_format($ROW->views) . '</td>';
		
		echo '<td width="125">';
		$query2 = "SELECT * FROM $DB_Forums_Posts WHERE replyto='$ROW->id' OR id='$ROW->id' ORDER BY timestamp DESC LIMIT 0,1";
		$result2 = mysql_query($query2, $Link) or queryError("76", mysql_error());
		$ROW2 = mysql_fetch_object($result2);
		echo '<span class="sxSmallText">' . fetchDate($ROW2->timestamp, 1, 1) . '<br />' . $sxLang['ForumBy'] . ' ';
		
		if($ROW2->userid != 0){
			$query3 = "SELECT * FROM $DB_Users WHERE id='$ROW2->userid'";
			$result3 = mysql_query($query3, $Link) or queryError("77", mysql_error());
			$ROW3 = mysql_fetch_object($result3);
			echo '<a href="admin/profile_view.php?user=' . $ROW3->username . '">' . $ROW3->username . '</a></font>';
		}else echo $sxLang['Anonymous'].'</span>';
		
		echo '</td></tr>';
	}
	if(mysql_num_rows($result) == 0) echo '<tr bgcolor="' . $sxTheme['ColorTableRow'] . '"><td colspan="5"><em>' . $sxLang['NoTopics'] . '</em></td></tr>';
  ?></table>
  <table border="0" cellpadding="3" cellspacing="0" width="<?PHP echo $sxSetup['ForumWidth']; ?>" align="center">
	<tr>
	  <td><br /><a href="forums_post.php?forumid=<?PHP echo $forumid; ?>"><?PHP echo $sxLang['ForumLinkAddTopic']; ?></a></td>
		<td align="right"><?PHP
		if($totalTopics > $sxSetup['ForumTopicsPerPage']) echo '<div style="padding-top:8px;padding-bottom:8px;font-size:10px;">';
		pageTurns($PHP_SELF.'?forumid=' . $forumid . '&', $totalTopics, $page, $sxSetup['ForumTopicsPerPage']);
		if($totalTopics > $sxSetup['ForumTopicsPerPage']) echo '</div>';
	  ?></td>
    </tr>
	<?PHP if(loggedIn()){ ?><tr>
	  <td colspan="2"><div style="text-align:right;font-size:10px;">
		  <?PHP 
		  if(sxForumSubscription('forum', $forumid))
			echo '<a href="' . $_SERVER['PHP_SELF'] . '?forumid=' . $forumid . '&unsubscribe=1">' . $sxLang['ForumUnsubscribe'] . '</a>'; 
		  else
			echo '<a href="' . $_SERVER['PHP_SELF'] . '?forumid=' . $forumid . '&subscribe=1">' . $sxLang['ForumSubscribe'] . '</a>'; 
		  ?>
		  </div>
      </td>
	</tr><?PHP } ?>
	<tr>
	  <td colspan="4" align="right">
		  <form action="<?PHP echo $PHP_SELF; ?>" name="sxFormSearchForum" method="post">
		  <?PHP echo $sxLang['MessageForumSearch']; ?>: 
		  <input type="text" name="search_text_forum" style="width:150px;" /> 
		  <input type="submit" name="StartSearch" value="<?PHP echo $sxLang['ButtonFind']; ?>" style="width:50px;" class="sxButton" />
		  </form></td>
	</tr>
  </table>
 </div>
<?PHP
include("themes/$THEME_FOLDER/footer.php");
ob_end_flush();
?>
Return current item: SiteX