<?php

#############################################################################
#                              WIZZ FORUM
#  Wizz Forum is a KISS Forum: Keep It Small and Simple.
#
# About the Wizz Forum:
# Original Idea & PHP coding: Mike Kroger (mikek@icon.co.za),
# who granted permission to put Wizz forum uder the GNU GPL.  
# Code adaptations and modularization for Site@School:
# Fred Stuurman (fc.stuurman@hccnet.nl)
############################################################################
# forum.php: last changed 05/10/2006  version 2.4.10
#                 by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: forum.php,v 1.2 2006/10/15 19:08:53 fstuurman Exp $
############################################################################
#                        LICENCE INFORMATION
# Copyright (C) 2006, Rosa Boekdrukker Primary School, Holland.
#
# This program 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.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
##############################################################################
if (!defined('IN_SAS'))
{
	die("Hacking attempt");
}

if (IsSet ($_GET[forumid]))
{
	$forumid = intval($_GET[forumid]);
}
if (IsSet ($_GET[forumtype]))
{
	$forumtype = intval($_GET[forumtype]);
}
if (IsSet ($_GET[suboption]))
{
	$suboption = $_GET[suboption];
}
if (IsSet ($_POST[forumuserid]))
{
	$forumuserid = strip_tags($_POST[forumuserid]);
}
if (IsSet ($_POST[password]))
{
	$password = strip_tags($_POST[password]);
}
if (IsSet ($_GET[b]))
{
	$b = $_GET[b];
}
if (IsSet ($_GET[l]))
{
	$l = $_GET[l];
}

if ($suboption == "logout")
{
	session_unset();
	session_destroy();
}

if (IsSet ($_SESSION['userid'])) //if user is already logged as teacher OR pupil
{
	$userid = $_SESSION['userid'];
	$usertype = $_SESSION['usertype'];

	if ($usertype == "student")
	{
		$forum_userindex = 1;
	}
	if ($usertype == "teacher")
	{
		$forum_userindex = 2;
	}

	$result = mysql_query("SELECT username FROM $table_users WHERE id='$userid'");
	$forum_username = mysql_result($result, 0); //get the username of the user
}

if (IsSet ($_SESSION[forum_username]))
{
	$forum_username = $_SESSION[forum_username];
}
if (IsSet ($_SESSION[forum_userindex]))
{
	$forum_userindex = $_SESSION[forum_userindex];
}

$page_count = 10; //number of topics per page
if ($b == "")
{
	$b = 1;
	$l = $page_count;
}

$result2 = mysql_query("SELECT type FROM $forumcat_table WHERE cat_index = '$forumid'");
if (mysql_num_rows($result2) > 0) //what is the forum type
{
	$forumtype = mysql_result($result2, 0);
}

if ($suboption == "verifylogin") // check userid and password
{
	$error = true;

	if ($forumtype == 1)
	{
		$result = mysql_query("SELECT * FROM $table_users WHERE username='$forumuserid' AND (type = 1 OR type = 21)");
		$forum_userindex = 1;
	}
	if ($forumtype == 2)
	{
		$result = mysql_query("SELECT * FROM $table_users WHERE username='$forumuserid' AND (type = 2 OR type = 22)");
		$forum_userindex = 2;
	}
	if ($forumtype > 2)
	{
		$result = mysql_query("SELECT * FROM $forumuser_table WHERE username='$forumuserid'");
	}

	$_SESSION[forum_userindex] = $forum_userindex;
	if (mysql_num_rows($result) == 0)
	{
		$msg = $sas_lang[forum_msg12];
	}
	else
	{
		$row = mysql_fetch_array($result);
		if ($row["password"] == $password)
		{
			$forum_username = $row["username"];
			$_SESSION['forum_username'] = $forum_username;
			$_SESSION['userid'] = $row["id"];
			$sql_str = "UPDATE $forumuser_table SET lastlogin='" . date("Y-m-d H:i:s") . "' WHERE user_index=" . $row["user_index"];
			if (mysql_query($sql_str))
			{
				$error = false;
			}
			else
			{
				$msg = "Your log in failed. Something went wrong with the database.";
			}
		}
		else
		{
			$msg = $sas_lang[forum_msg13];
		}
	}
}

if (!$error)
{
	$result3 = mysql_query("SELECT cat_index FROM $forumuser_table WHERE username = '$forum_username'");
	if (mysql_num_rows($result3) > 0) //check if the user exists then access to public forums 
	{
		$user_forum = $forumid; //give him the actual forumid.
	}
}

if (($forumtype == "1") OR ($forumtype == "2"))
{
	if (!IsSet ($forum_username) OR ($forumtype != $forum_userindex)) //user is not logged into this forum
	{
		session_unset();
		$result2 = mysql_query("SELECT name FROM $forumcat_table WHERE cat_index = '$forumid'");
		if (mysql_num_rows($result2) > 0) //get the forum title 
		{
			$forum_title = mysql_result($result2, 0);
		}
		print "<table border='0' cellpadding='2' cellspacing='0' width='100%'>
		           <tr>";
		print "<td width='100%'>
		          <font face='Arial' size='4'>$sas_lang[forum_login]: $forum_title </font></td>
		          </tr> 
		          </table><br>";
		print "<form method='POST' action='index.php?option=forum&suboption=verifylogin&section=$section&page=$page&forumid=$forumid' 
		            name='ForumLoginSubmit'>                                
		           <input type='hidden' name='forumtype' value='$forum_type'><center>
		           <table border='1' cellpadding='0' cellspacing='0' width='80%' bordercolor='" . $sas_lang[forum_bordercolor] . "'>
		           <tr>
		           <td width='100%'>
		           <table border='0' cellpadding='3' cellspacing='0' width='100%'>
		           <tr>
		           <td width='50%' align='right' bgcolor='$OddBackgroundColor'>
		           <font face='Arial' size='2'>$sas_lang[forum_userid]</font></td>
		           <td width='50%' bgcolor='$OddBackgroundColor'><font face='Arial' size='2'>
		           <input tabindex='1' type='text' name='forumuserid' size='30'></font></td>
		           </tr>
		           <tr>
		           <td width='50%' align='right' bgcolor='$EvenBackgroundColor'>
		           <font face='Arial' size='2'>$sas_lang[forum_password]</font></td>
		           <td width='50%' bgcolor='$EvenBackgroundColor'><font face='Arial' size='2'>
		           <input tabindex='2' type='password' name='password' size='30'></font></td>
		           </tr>
		           <tr>
		           <td width='100%' colspan='2' align='center' bgcolor='$OddBackgroundColor'>
		           <input tabindex='3' type='submit' value='$sas_lang[forum_login]' name='B1'></td>
		           </tr>
		           </table>
		           </td></tr>
		           <tr><td align='center' bgcolor='$EvenBackgroundColor'><font face='Arial' size='2'><b>$msg</b></font></td>               </tr>
		           </table>
		           </center><br><br>
		           <table cellspacing=\"0\" cellpadding=\"0\"><tr height=\"25\">
		           <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
		           <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
		           <a href = 'index.php?section=$section&page=$page'><b>$sas_lang[forum_forums]</b></a></td>
		           <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
		           </tr></table></form>";
	}
	else //show teacher OR student forum
		{
		$result = mysql_query("SELECT * FROM $forumtopics_table WHERE cat_index='$forumid'");
		$number = mysql_num_rows($result); //number of forumentries
		$limit_begin = $b -1;
		$result = mysql_query("SELECT * FROM $forumtopics_table WHERE cat_index='$forumid' ORDER BY date DESC LIMIT $limit_begin,$page_count");
		$result2 = mysql_query("SELECT name FROM $forumcat_table WHERE cat_index = '$forumid'");
		if (mysql_num_rows($result2) > 0) //get the forum title 
		{
			$forum_title = mysql_result($result2, 0);
		}
		print "<table cellspacing=\"0\" cellpadding=\"0\"><tr height=\"25\">
		       <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
		       <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
		       <a href = 'index.php?option=newtopic&section=$section&page=$page&forumid=$forumid'><b>$sas_lang[forum_new_topic]</b></a></td>
		       <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
		       <td width=\"15\">&nbsp;</td>
		       <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
		       <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
		       <a href = 'index.php?option=forum&suboption=logout&section=$section&page=$page&forumid=$forumid'><b>$sas_lang[forum_logout]</b></a></td>
		       <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
		       <td width=\"15\">&nbsp;</td>
		       <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
		       <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
		       <a href = 'index.php?option=search&section=$section&page=$page&forumid=$forumid&b=$b&l=$l'><b>$sas_lang[forum_search]</b></a></td>
		       <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
		       <td width=\"15\">&nbsp;</td>
		       <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
		       <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
		       <a href = 'index.php?section=$section&page=$page'><b>$sas_lang[forum_forums]</b></a></td>
		       <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
		       </tr></table>";
		print "<table border='0' cellpadding='2' cellspacing='0' width='100%'>
		       <tr> 
		       <td align='right' width='100%'>
		       <font face='Arial' size='2'>$sas_lang[forum_loggedin]<b>$forum_username</b></font></td> 
		       </tr></table>";

		$i = 0;
		$pagtot = ceil($number / $page_count); //number of pages
		if ($b == 1)
		{
			$pag = 1;
		} //page 1
		else
		{
			$pag = $l / $page_count;
		} //not page 1

		if ($number < $l)
		{
			$l = $number;
		} //Less records as the total records

		$low = $b - $page_count;

		if ($b > $page_count) //
		{
			$high = $b -1;
			$previous_page = "<a STYLE=\"color: blue ; font-size: 12\" href=\"index.php?section=$section&page=$page&option=forum&forumid=$forumid&b=$low&l=$high\">$sas_lang[forum_previous_page]</a>";
		}
		else
		{
			$previous_page = ''; //no next page
		}
		if ($number > $l) //number of records greater as $l
		{
			$low = $b + $page_count; //$b + number per page
			$high = $l + $page_count; //$l + number per page
			$next_page = "<a STYLE=\"color: blue ; font-size: 12\" href=\"index.php?section=$section&page=$page&option=forum&forumid=$forumid&b=$low&l=$high\">$sas_lang[forum_next_page]</a>";
		}
		else
		{
			$next_page = ''; //no next page
		}
		$page_info = $number . " $sas_lang[forum_topics] - $sas_lang[forum_page] " . $pag . " / " . $pagtot;

		print "<table width='100%'><tr>
		       <td width='28%' align=\"left\">$previous_page&nbsp;</td>
		       <td width='44%' align=\"center\">&nbsp;</td>
		       <td width='28%' align=\"right\">&nbsp$next_page</td>
		       </tr></table>";
		print "<table border='1' cellpadding='2' cellspacing='0' width='100%' bordercolor='$sas_lang[forum_bordercolor]'>
		              <tr> 
		              <td width='100%' align='center' colspan='5'>
		              <font face='Arial' size='4'>$forum_title</font></td>
		              </tr>";
		if (mysql_num_rows($result) == 0)
		{
			print "<tr>";
			print "<td width='100%' colspan='5' bgcolor='$OddBackgroundColor'>
			                   <font face='Arial' size='2'>" . $sas_lang['forum_no_topics'] . "</font></td>
			             </tr>";
		}
		else
		{
			print "<tr bgcolor='$SubtitleBackgroundColor'>
			               <td width='40%'>
			               <font face='Arial' size='3' color='$forum_header_font_colour'><b>$sas_lang[forum_topic]</b></font></td>
			               <td width='30%'>
			               <font face='Arial' size='3' color='$forum_header_font_colour'><b>$sas_lang[forum_author]</b></font></td>
			               <td width='10%'>
			               <font face='Arial' size='3' color='$forum_header_font_colour'><b>$sas_lang[forum_replies]</b></font></td>
			               <td width='10%'>
			               <font face='Arial' size='3' color='$forum_header_font_colour'><b>$sas_lang[forum_read]</b></font></td>
			               <td width='10%'>
			               <font face='Arial' size='3' color='$forum_header_font_colour'><b>$sas_lang[forum_date]</b></font></td>
			               </tr>";
			$bgColor = $OddBackgroundColor;

			while ($row = mysql_fetch_array($result))
			{
				print "<tr>
				               <td width='40%' bgcolor='$bgColor'><font face='Arial' size='2'>
				               <a href='index.php?section=$section&page=$page&option=topicdetails&forumid=$forumid&topicid=$row[topic_index]&b=$b&l=$l'>$row[topictitle]</a></font></td> 
				               <td width='30%' bgcolor='$bgColor'><font face='Arial' size='2'>";
				if ($forumtype > 2)
				{
					print "<a href='index.php?section=$section&page=$page&option=authdetails&forumid=$forumid&authid=$row[userid]&b=$b&l=$l'>$row[userid]</a></font></td>";
				}
				else
				{
					print "$row[userid]</font></td>";
				}
				print "<td width='10%' bgcolor='$bgColor'>
				               <font face='Arial' size='2'>$row[replies]</font></td>
				               <td width='10%' bgcolor='$bgColor'>
				               <font face='Arial' size='2'>$row[topic_reads]</font></td>";
				$ts = mktime(substr($row["date"], 11, 2), substr($row["date"], 14, 2), substr($row["date"], 17, 2), substr($row["date"], 5, 2), substr($row["date"], 8, 2), substr($row["date"], 0, 4));

				print "<td width='10%' bgcolor='$bgColor'>
				               <font face='Arial' size='2'>" . strftime($sas_config['dateformat'], $ts) . "&nbsp;</font></td>
				               </tr>";
				if ($bgColor == $OddBackgroundColor)
				{
					$bgColor = $EvenBackgroundColor;
				}
				else
				{
					$bgColor = $OddBackgroundColor;
				}
				$i = $i +1; //count +1 
			}

		}
		print "</table>
		       <table width='100%'><tr><td align=\"left\">$previous_page</td><td align=\"right\"$next_page</td></tr>
		       <tr><td colspan=\"2\" align=\"center\"><font face='Arial' size='2'><b>$page_info</b></font></td></tr></table>";
	}
}
else
{
	if (!$error)
	{
		$result = mysql_query("SELECT * FROM $forumtopics_table WHERE cat_index='$forumid'");
		$number = mysql_num_rows($result); //number of records
		$limit_begin = $b -1;
		$result = mysql_query("SELECT * FROM $forumtopics_table WHERE cat_index='$forumid' ORDER BY date DESC LIMIT $limit_begin,$page_count");
		$result2 = mysql_query("SELECT name FROM $forumcat_table WHERE cat_index = '$forumid'");
		if (mysql_num_rows($result2) > 0) //get the forum title 
		{
			$forum_title = mysql_result($result2, 0);
		}

		print "<table border='0' cellpadding='2' cellspacing='0' width='100%'><tr><td>";

		if (($user_forum != $forumid) OR ($forumtype < 3)) //user is not logged into this forum
		{
			print "<table cellspacing=\"0\" cellpadding=\"0\"><tr height=\"25\">
					   <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
					   <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
					   <a href = 'index.php?option=login&section=$section&page=$page&forumid=$forumid'><b>$sas_lang[forum_login]</b></a></td>
					   <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
					   <td width=\"10\">&nbsp;</td>
					   <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
					   <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
					   <a href = 'index.php?option=newacc&section=$section&page=$page&forumid=$forumid'><b>$sas_lang[forum_register]</b></a></td>
					   <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
					   <td width=\"10\">&nbsp;</td>
					   <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
					   <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
					   <a href = 'index.php?option=search&section=$section&page=$page&forumid=$forumid&b=$b&l=$l'><b>$sas_lang[forum_search]</b></a></td>
					   <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
					   <td width=\"10\">&nbsp;</td>
					   <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
					   <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
					   <a href = 'index.php?section=$section&page=$page'><b>$sas_lang[forum_forums]</b></a></td>
					   <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
					   </tr></table>
					   </td></tr>
					   <tr>
					   <td align='right' width='100%'>
					   <font face='Arial' size='2'>$sas_lang[forum_not_loggedin]</font></td>
					   </tr></table>";

		}
		else
		{
			print "<tr><td colspan=\"2\">
							 <table cellspacing=\"0\" cellpadding=\"0\"><tr height=\"25\">
							 <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
							 <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
							 <a href = 'index.php?option=newtopic&section=$section&page=$page&forumid=$forumid'><b>$sas_lang[forum_new_topic]</b></a></td>
							 <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
							 <td width=\"15\">&nbsp;</td>
							 <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
							 <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
							 <a href = 'index.php?option=updateacc&section=$section&page=$page&forumid=$forumid&b=$b&l=$l'><b>$sas_lang[forum_change_profile]</b></a></td>
							 <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
							 <td width=\"15\">&nbsp;</td>
							 <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
							 <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
							 <a href = 'index.php?option=stats&section=$section&page=$page&forumid=$forumid&b=$b&l=$l'><b>$sas_lang[forum_profile]</b></a></td>
							 <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
							 <td width=\"15\">&nbsp;</td>
							 <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
							 <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
							 <a href = 'index.php?option=search&section=$section&page=$page&forumid=$forumid&b=$b&l=$l'><b>$sas_lang[forum_search]</b></a></td>
							 <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
							 <td width=\"15\">&nbsp;</td>
							 <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
							 <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
							 <a href = 'index.php?section=$section&page=$page'><b>$sas_lang[forum_forums]</b></a></td>
							 <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
							 </tr></table> 
							 </td></tr>
							 <tr><td width=\"80%\" align='right'>
							 <font face='Arial' size='2'>$sas_lang[forum_loggedin]<b>$forum_username</b></font></td>
							 <td width=\"20%\" align=\"right\">
							 <table cellspacing=\"0\" cellpadding=\"0\"><tr height=\"25\">
							 <td background=\"$cmsdir/modules/sn_forum/left.gif\" width=\"10\">&nbsp;</td>
							 <td background=\"$cmsdir/modules/sn_forum/middle.gif\" align=\"center\">
							 <a href = 'index.php?option=forum&suboption=logout&section=$section&page=$page&forumid=$forumid'><b>$sas_lang[forum_logout]</b></a></td>
							 <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>
							 </tr></table>
							 </td>  
							 </tr></table>";
		}
		$i = 0;
		$pagtot = ceil($number / $page_count); //number of pages
		if ($b == 1)
		{
			$pag = 1;
		} //page 1
		else
		{
			$pag = $l / $page_count;
		} //not page 1

		if ($number < $l)
		{
			$l = $number;
		} //less records than the number per page

		$low = $b - $page_count;

		if ($b > $page_count) //
		{
			$high = $b -1;
			$previous_page = "<a STYLE=\"color: blue ; font-size: 12\" href=\"index.php?section=$section&page=$page&option=forum&forumid=$forumid&b=$low&l=$high\">$sas_lang[forum_previous_page]</a>";
		}
		else
		{
			$previous_page = ''; //no next page
		}
		if ($number > $l) //number of records greater as $l
		{
			$low = $b + $page_count; //$b + number per page
			$high = $l + $page_count; //$l + number per page
			$next_page = "<a STYLE=\"color: blue ; font-size: 12\" href=\"index.php?section=$section&page=$page&option=forum&forumid=$forumid&b=$low&l=$high\">$sas_lang[forum_next_page]</a>";
		}
		else
		{
			$next_page = ''; //no next page
		}
		$page_info = $number . " $sas_lang[forum_topics] - $sas_lang[forum_page] " . $pag . " / " . $pagtot;

		print "<table width='100%'><tr>
				   <td width='28%' align=\"left\">$previous_page&nbsp;</td>
				   <td width='44%' align=\"center\">&nbsp;</td>
				   <td width='28%' align=\"right\">&nbsp$next_page</td>
				   </tr></table>
				   <table border='1' cellpadding='2' cellspacing='0' width='100%' bordercolor='$sas_lang[forum_bordercolor]'>
				   <tr> 
				   <td width='100%' align='center' colspan='5'>
				   <font face='Arial' size='4'>$forum_title</font></td>
				   </tr>";
		if (mysql_num_rows($result) == 0)
		{
			print "<tr>";
			print "<td width='100%' colspan='5' bgcolor='$OddBackgroundColor'>
								   <font face='Arial' size='2'>" . $sas_lang['forum_no_topics'] . "</font></td>
							 </tr>";
		}
		else
		{
			print "<tr bgcolor='$SubtitleBackgroundColor'>
							   <td width='40%'>
							   <font face='Arial' size='3' color='$forum_header_font_colour'><b>$sas_lang[forum_topic]</b></font></td>
							   <td width='30%'>
							   <font face='Arial' size='3' color='$forum_header_font_colour'><b>$sas_lang[forum_author]</b></font></td>
							   <td width='10%'>
							   <font face='Arial' size='3' color='$forum_header_font_colour'><b>$sas_lang[forum_replies]</b></font></td>
							   <td width='10%'>
							   <font face='Arial' size='3' color='$forum_header_font_colour'><b>$sas_lang[forum_read]</b></font></td>
							   <td width='10%'>
							   <font face='Arial' size='3' color='$forum_header_font_colour'><b>$sas_lang[forum_date]</b></font></td>
							   </tr>";
			$bgColor = $OddBackgroundColor;

			while ($row = mysql_fetch_array($result))
			{
				print "<tr>
								   <td width='40%' bgcolor='$bgColor'><font face='Arial' size='2'>
								   <a href='index.php?section=$section&page=$page&option=topicdetails&forumid=$forumid&topicid=$row[topic_index]&b=$b&l=$l'>$row[topictitle]</a></font></td> 
								   <td width='30%' bgcolor='$bgColor'><font face='Arial' size='2'>";
				if ($forumtype > 2)
				{
					print "<a href='index.php?section=$section&page=$page&option=authdetails&forumid=$forumid&authid=$row[userid]&b=$b&l=$l'>$row[userid]</a></font></td>";
				}
				else
				{
					print "$row[userid]</font></td>";
				}
				print "<td width='10%' bgcolor='$bgColor'>
								   <font face='Arial' size='2'>$row[replies]</font></td>
								   <td width='10%' bgcolor='$bgColor'>
								   <font face='Arial' size='2'>$row[topic_reads]</font></td>";
				$ts = mktime(substr($row["date"], 11, 2), substr($row["date"], 14, 2), substr($row["date"], 17, 2), substr($row["date"], 5, 2), substr($row["date"], 8, 2), substr($row["date"], 0, 4));

				print "<td width='10%' bgcolor='$bgColor'>
								   <font face='Arial' size='2'>" . strftime($sas_config['dateformat'], $ts) . "&nbsp;</font></td>
								   </tr>";
				if ($bgColor == $OddBackgroundColor)
				{
					$bgColor = $EvenBackgroundColor;
				}
				else
				{
					$bgColor = $OddBackgroundColor;
				}
				$i = $i +1; //count +1 
			}

		}
		print "</table>";
		print "<table width='100%'><tr><td align=\"left\">$previous_page</td><td align=\"right\"$next_page</td></tr>
				   <tr><td colspan=\"2\" align=\"center\"><font face='Arial' size='2'><b>$page_info</b></font></td></tr></table>";
	}
	else
	{
		print "<table border='0' cellpadding='2' cellspacing='0' width='100%'>
				   <tr>
				   <td width='100%' bgcolor='" . $TitleBackgroundColor . "'>
				   <font face='Arial' size='4'>$sas_lang[forum_error]</font></td>
				   </tr>
				   </table>
				   <p><font face='Arial' size='2'>" . $msg . "</font>
				   <font face='Arial' size='2'><p><A HREF=JavaScript:history.back()>$sas_lang[forum_back]</a></font></p>";
	}
}
?>
