<?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)
############################################################################
# forums.php: last changed 20/08/2006  version 2.4.03
#             by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: forums.php,v 1.2 2006/10/15 19:08:53 fstuurman Exp $
############################################################################
#                        LICENSE INFORMATION
# Copyright (C) 2002, 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");
}

$result = mysql_query("SELECT * FROM $forumcat_table"); //get the forums 

print $sas_config['forum_welcome_text'];

print "<br><br><center>
       <table border='1' cellpadding='2' cellspacing='0' width='95%' bordercolor='$sas_lang[forum_bordercolor]'>
       <tr height='40' bgcolor='$SubtitleBackgroundColor'>
       <td>
       <font face='Arial' size='4' color='$forum_header_font_colour'>$sas_lang[forum_header]<br></font></td>
       <td>
       <font face='Arial' size='4' color='$forum_header_font_colour'>$sas_lang[forum_topics]:<br></font></td>
       <td>
       <font face='Arial' size='4' color='$forum_header_font_colour'>$sas_lang[forum_date_last_update]</font></td>
       <td>
       <font face='Arial' size='4' color='$forum_header_font_colour'>$sas_lang[forum_public]</font></td>
       </tr>";
$bgColor = $OddBackgroundColor;

while ($row = mysql_fetch_array($result))
{
	$result2 = mysql_query("SELECT count(*) FROM $forumtopics_table WHERE cat_index = $row[cat_index]");
	//get the number of topics
	if (mysql_num_rows($result2) > 0)
	{
		$reccount = mysql_result($result2, 0);
	}
	//get the last topic date
	$result3 = mysql_query("SELECT date FROM $forumtopics_table WHERE cat_index = $row[cat_index] ORDER BY date DESC LIMIT 1");

	if (mysql_num_rows($result3) > 0)
	{
		$lastdate_t = mysql_result($result3, 0);
	}
	else
	{
		$lastdate_t = "";
	}
	//get the last reply date   
	$result3 = mysql_query("SELECT date FROM $forumreplies_table WHERE cat_index = $row[cat_index] ORDER BY date DESC LIMIT 1");

	if (mysql_num_rows($result3) > 0)
	{
		$lastdate_r = mysql_result($result3, 0);
	}
	else
	{
		$lastdate_r = "";
	}

	//compare dates
	if ($lastdate_t > $lastdate_r)
	{
		$lastdate = $lastdate_t;
	}
	else
	{
		$lastdate = $lastdate_r;
	}

	$ts = mktime(substr($lastdate, 11, 2), substr($lastdate, 14, 2), substr($lastdate, 17, 2), substr($lastdate, 5, 2), substr($lastdate, 8, 2), substr($lastdate, 0, 4));

	print "<tr>
				 <td  height='30' bgcolor='$bgColor'><font face='Arial' size='2'>
				 <a href='index.php?section=$section&page=$page&option=forum&forumid=$row[cat_index]'><b>$row[name]</b></a></font>
				 <td bgcolor='$bgColor'><font face='Arial' size='2'>$reccount&nbsp;</font>
				 <td bgcolor='$bgColor'><font face='Arial' size='2'>" . strftime($sas_config['dateformat'] . ", %H:%M:%S", $ts) . "&nbsp;</td>";

	if ($row[type] > 2)
	{
		print "<td bgcolor='$bgColor'><font face='Arial' size='2'>$sas_lang[forum_yes]</td></tr>";
	}
	else
	{
		print "<td bgcolor='$bgColor'><font face='Arial' size='2'>$sas_lang[forum_no]</td></tr>";
	}

	if ($bgColor == $OddBackgroundColor)
	{
		$bgColor = $EvenBackgroundColor;
	}
	else
	{
		$bgColor = $OddBackgroundColor;
	}
}

print "</center></table>";
?>