<?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)
############################################################################
# forumtopicdetails.php: last changed 05/10/2006  version 2.4.10
#                        by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: forumtopicdetails.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['topicid']))
{
	$topicid = intval($_GET['topicid']);
}
if (IsSet ($_GET['forumid']))
{
	$forumid = intval($_GET['forumid']);
}
if (IsSet ($_GET['b']))
{
	$b = $_GET['b'];
}
if (IsSet ($_GET['l']))
{
	$l = $_GET['l'];
}

if (IsSet ($_SESSION['forum_username']))
{
	$forum_username = $_SESSION['forum_username'];
}
else
{
	$forum_username = "";
}

$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 ($forumtype == 1) //check which forum the user belongs to
{
	$result3 = mysql_query("SELECT username FROM $table_users WHERE id = '$_SESSION[userid]'");

	if (mysql_num_rows($result3) > 0) //found one                            
	{
		$_SESSION[forum_username] = mysql_result($result3, 0);
		$user_forum = 1;
	}
}

if ($forumtype == 2)
{
	$result3 = mysql_query("SELECT username FROM $table_users WHERE id = '$_SESSION[userid]'");

	if (mysql_num_rows($result3) > 0) //found one                            
	{
		$_SESSION[forum_username] = mysql_result($result3, 0);
		$user_forum = 2;
	}
}

if ($forumtype > 2)
{
	$result3 = mysql_query("SELECT cat_index FROM $forumuser_table WHERE username = '$forum_username'");

	if (mysql_num_rows($result3) > 0) //found one                            
	{
		$user_forum = 3;
	}
}

if (($forumtype < 3) and ((!IsSet ($_SESSION['userid'])) AND (!IsSet ($forum_username))))
{
	exit; //if we are not logged in, exit
}
$result = mysql_query("SELECT * FROM $forumtopics_table WHERE topic_index=" . $topicid);
$row = mysql_fetch_array($result);
print "<p><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&option=forum&forumid=$forumid'><b>$sas_lang[forum_main_page]</b></a></td>
            <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>";

if ($user_forum == $forumtype)
{
	print "<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=reply&section=$section&page=$page&forumid=$forumid&topicid=$topicid'><b>$sas_lang[forum_reply]</b></a></td>
	                   <td background=\"$cmsdir/modules/sn_forum/right.gif\" width=\"10\">&nbsp;</td>";
}
else
{
	print "&nbsp;";
}
print "<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>
               <p><font face='Arial' size='4'>$sas_lang[forum_topic] $row[topictitle]</font>
               <table border='1' cellpadding='0' cellspacing='0' width='100%' bordercolor='" . $sas_lang[forum_bordercolor] . "'>
               <tr>
               <td width='100%'>
               <table border='0' cellpadding='5' cellspacing='0' width='100%'>
               <tr>
               <td width='40%' bgcolor='$OddBackgroundColor'><font face='Arial' size='2'>$sas_lang[forum_author]";
if ($forumtype > 2) //only for public forum give author details
{
	print "<a href='index.php?section=$section&page=$page&option=authdetails&forumid=$forumid&authid=$row[userid]'><b>$row[userid]</b></a></font></td>";
}
else
{
	print "<b>$row[userid]</b></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 align='right' width='40%' bgcolor='$OddBackgroundColor'><font face='Arial' size='2'>" . strftime("%A %d %B %Y, %H:%M:%S", $ts) . "</font></td>
               </tr>
               <tr>
               <td width='100%' colspan='3'><font face='Arial' size='2'>$row[topicbody]</font></td>
               </tr>
               </table>";

$reads = $row["topic_reads"];
$reads++;
$sql_str = "UPDATE $forumtopics_table SET topic_reads=" . $reads . " WHERE topic_index=" . $topicid;
mysql_query($sql_str);
$result = mysql_query("Select * from $forumreplies_table where topicindex=" . $topicid);
while ($row = mysql_fetch_array($result))
{
	print "<p><table border='0' cellpadding='0' cellspacing='0' width='100%'>
	               <tr>
	               <td width='100%'>
	               <table border='0' cellpadding='5' cellspacing='0' width='100%'>
	               <tr>
	               <td width='40%' bgcolor='$OddBackgroundColor'><font face='Arial' size='2'>$sas_lang[forum_author]";

	if ($forumtype > 2) //only for public forum give author details
	{
		print "<a href='index.php?section=$section&page=$page&option=authdetails&forumid=$forumid&authid=$row[userid]'><b>$row[userid]</b></a></font></td>";
	}
	else
	{
		print "<b>$row[userid]</b></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 align='right' width='40%' bgcolor='$OddBackgroundColor'><font face='Arial' size='2'>" . strftime("%A %d %B %Y, %H:%M:%S", $ts) . "</font></td>
	                </tr>
	                <tr>
	                <td width='100%' colspan='3'><font face='Arial' size='2'>" . $row["replybody"] . "</font></td>
	                </tr>
	                </table>
	                </td>
	                </tr>
	                </table></p>";
}
print "</td>
                </tr>
                </table></p>";
?>
