<?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)
############################################################################
# forumsearch.php: last changed 05/10/2006  version 2.4.10
#                  by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: forumsearch.php,v 1.2 2006/10/15 19:08:54 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 ($_POST['argument']))
{
	$argument = sql_addslashes($_POST['argument']);
}

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

$result2 = mysql_query("SELECT name FROM $forumcat_table WHERE cat_index = '" . $forumid . "'");
$forum_title = mysql_result($result2, 0);

$result3 = mysql_query("SELECT type FROM $forumcat_table WHERE cat_index = '" . $forumid . "'");

if (mysql_num_rows($result3) > 0) //what is the forum type
{
	$forumtype = mysql_result($result3, 0);
}

if ($argument == "")
{
	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?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>
		   </tr></table>";
	print "<table border='0' cellpadding='2' cellspacing='0' width='100%'>
		   <tr>
		   <td width='200' align='center'>
		   <font face='Arial' size='4'>$sas_lang[forum_search] : $forum_title</font></td>
		   </tr>
		   </table><br>";
	print "<form method='POST' action='index.php?option=search&section=$section&page=$page&forumid=$forumid' name='ForumSearch'>
		   <center>
		   <table border='1' cellpadding='0' cellspacing='0' width='60%' 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_search_arg]</font></td>
		   <td width='50%' bgcolor='$OddBackgroundColor'><font face='Arial' size='2'>
		   <input tabindex='1' type='text' name='argument' size='30'></font></td>
		   </tr>
		   <tr>
		   <tr bgcolor='$OddBackgroundColor'>
		   <td>&nbsp</td><td width='100%'>
		   <input tabindex='2' type='submit' value='$sas_lang[forum_search]' name='B1'></td>
		   </tr>
		   </table>
		   </td></tr>
		   </table>
		   </center>
		   </form>";
}
else
{
	$search_argument = "%" . $argument . "%";

	$result = mysql_query("SELECT DISTINCTROW topic_index,topictitle,t.userid,replies,topic_reads FROM $forumtopics_table t,$forumreplies_table r  
	                        WHERE (t.topicBody like '$search_argument' 
	                        or t.topictitle like '$search_argument'
	                        or r.replybody like '$search_argument')");

	$reccount = mysql_num_rows($result);
	print "<table border='0' cellpadding='2' cellspacing='0' width='100%'><tr><td>";

	if (!isset ($forum_username))
	{
		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?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>
				<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=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>
				<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\">";
		if ($forumtype > 2)
		{
			print "<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>";
		}
		print "<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=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 align='right' width='80%'>
				<font face='Arial' size='2'>$sas_lang[forum_loggedin]<b>$forum_username</b></font></td>
				<td> 
				<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>
				<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>
			<tr>
			<td width='100%' colspan='4'>
			<font face='Arial' size='2'>" . $sas_lang[forum_searched_on] . "<b>$argument</b> , " . $sas_lang['forum_search_hits'] . "<b>$reccount</b></font></td>
			</tr>";

	if ($reccount < 1) //no records found
	{
		print "<tr>
			   <td width='100%' colspan='4' bgcolor='$OddBackgroundColor'>
			   <font face='Arial' size='2'>$sas_lang[forum_search_not_found]</font></td>
			   </tr>";
	}
	else
	{
		print "<tr>
			   <td width='50%' bgcolor='$SubtitleBackgroundColor'>
			   <font face='Arial' size='3' color='$forum_header_font_colour'><b>$sas_lang[forum_topic]</b></font></td>
			   <td width='30%' bgcolor='$SubtitleBackgroundColor'>
			   <font face='Arial' size='3' color='$forum_header_font_colour'><b>$sas_lang[forum_author]</b></font></td>
			   <td width='10%' bgcolor='$SubtitleBackgroundColor'>
			   <font face='Arial' size='3' color='$forum_header_font_colour'><b>$sas_lang[forum_replies]</b></font></td>
			   <td width='10%' bgcolor='$SubtitleBackgroundColor'>
			   <font face='Arial' size='3' color='$forum_header_font_colour'><b>$sas_lang[forum_read]</b></font></td>
			   </tr>";
		$bgColor = $OddBackgroundColor;

		while ($row = mysql_fetch_array($result))
		{
			print "<tr>
						  <td width='50%' bgcolor='" . $bgColor . "'><font face='Arial' size='2'>
						  <a href='index.php?page=" . $page . "&section=" . $section . "&option=topicdetails&forumid=$forumid&topicid=" . $row["topic_index"] . "'>" . $row["topictitle"] . "</a></font></td>
						  <td width='30%' bgcolor='" . $bgColor . "'><font face='Arial' size='2'>
						  <a href='index.php?page=" . $page . "&section=" . $section . "&option=authdetails&forumid=$forumid&authid=" . $row["userid"] . "'>" . $row["userid"] . "</a></font></td>
						  <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["topics_reads"] . "</font></td>
						  </tr>";
			if ($bgColor == $OddBackgroundColor)
			{
				$bgColor = $EvenBackgroundColor;
			}
			else
			{
				$bgColor = $OddBackgroundColor;
			}
		}
	}
	print "</table>";
}
?>