<?php
######################################################################
# Modulo Splatt Forum per PHP-NUKE 
#-------------------------
# Versione: 3.2
#
# Copyright (c) 2002 by:
#
# Giorgio Ciranni (~Splatt~)
# (http://www.splatt.it)
# (webmaster@splatt.it)
#
# Supporto tecnico disponibile sul Forum di www.splatt.it
######################################################################
# PHP-NUKE Add-On 2.0 :
# =====================
#
#              PHPBB Integration 1.0.BETA
#        Brought to you by PHPNuke Add-On Team
#
# Copyright (c) 2000 by Richard Tirtadji AKA King Richard (rtirtadji@hotmail.com)
#                       Hutdik Hermawan AKA hotFix (hutdik76@hotmail.com)
# http://www.phpnuke.web.id
#
#
######################################################################
# PHPBB
#
# Copyright (C) 2000 by James Atkinson (james@totalgeek.org)
# http://www.phpbb.com
#
#
######################################################################
# Splatt Forum 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.
# Splatt Forum 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
######################################################################

$module_name = "$name";

include("config.php");
include("modules/".$module_name."/functions.php");
include("modules/".$module_name."/auth.php");
include("header.php");

?>
<FORM NAME="Search" ACTION="modules.php?op=modload&name=<?php echo $module_name?>&file=searchbb" METHOD="POST">
<TABLE BORDER="0" CELLPADDING="1" CELLSPACING="0"  VALIGN="TOP" WIDTH="100%">
<TR>
        <TD  BGCOLOR="<?php echo $table_bgcolor?>" ALIGN="LEFT">
        <TABLE BORDER="0" CELLPADDING="1" CELLSPACING="1" WIDTH="100%" BGCOLOR="<?php echo $bgcolor1; ?>">
        <TR>
        <TD BGCOLOR="<?php echo $bgcolor1?>" WIDTH="20%" ALIGN="RIGHT">
                <b><?php echo _FKEY;?></b>:&nbsp;
        </TD>
        <TD BGCOLOR="<?php echo $bgcolor3?>" WIDTH="80%">
                <INPUT CLASS="textbox" TYPE="text" name="term">
        </TD>
        </TR>
        <TR>
        <TD BGCOLOR="<?php echo $bgcolor1?>" WIDTH="20%">&nbsp;</TD>
        <TD BGCOLOR="<?php echo $bgcolor3?>" WIDTH="80%">
                <INPUT TYPE="radio" name="addterms" value="any" CHECKED>
                <font size=-2><?php echo _FSEANY; ?>
        </TD>
        </TR>
        <TR>
        <TD BGCOLOR="<?php echo $bgcolor1?>" WIDTH="20%">&nbsp;</TD>
        <TD BGCOLOR="<?php echo $bgcolor3?>" WIDTH="80%">
                <INPUT TYPE="radio" name="addterms" value="all">
                <font size=-2><?php echo _FSEAL; ?>
        </TD>
        </TR>
        <TR>
        <TD BGCOLOR="<?php echo $bgcolor1?>" WIDTH="20%" ALIGN="RIGHT">
                <b><?php echo "Forum";?></b>:&nbsp;
        </TD>
        <TD BGCOLOR="<?php echo $bgcolor3?>" WIDTH="80%">
                <select name="forum">
                <option value="all"><?php echo _SALF;?></option>
                <?php
                        $query = "SELECT forum_name,forum_id FROM ${prefix}_forums WHERE forum_type != 1";
                        if(!$result = mysql_query($query,$db))
                        {
                                die("<font size=+1>"._ERRORE1."</font><hr>phpBB was unable to query the forums database");
                        }
                        while($row = @mysql_fetch_array($result))
                        {
                                echo "<option value=$row[forum_id]>$row[forum_name]</option>";
                        }
                ?>
                </select>
        </TD>
        </TR>
        <TR>
        <TD BGCOLOR="<?php echo $bgcolor1?>" WIDTH="20%" ALIGN="RIGHT">
                <b><?php echo _AUTN;?></b>:
        </TD>
        <TD BGCOLOR="<?php echo $bgcolor3?>" WIDTH="80%">
                <INPUT TYPE="text" CLASS="text" name="usernamex">
        </TD>
        </TR>
        <TR>
        <TD BGCOLOR="<?php echo $bgcolor1?>" WIDTH="20%" ALIGN="RIGHT">
                <b><?php echo _SORTBY;?></b><br>
        </TD>
        <TD BGCOLOR="<?php echo $bgcolor3?>" WIDTH="80%">
        <?php //All values are the fields used to search the database - a table must be specified for each field ?>
                <INPUT TYPE="radio" name="sortby" value="p.post_time" CHECKED><?php echo _FPTIM;?>
                &nbsp;&nbsp;
                <INPUT TYPE="radio" name="sortby" value="t.topic_title"><?php echo _FTOPICS;?>
                &nbsp;&nbsp;
                <INPUT TYPE="radio" name="sortby" value="f.forum_name"><?php echo _FORUM;?>
                &nbsp;&nbsp;
                <INPUT TYPE="radio" name="sortby" value="u.uname"><?php echo _FNICKNAME;?>
                &nbsp;&nbsp;
        </TD>
        <TR>
        <TD></TD>


        <TD>
        <INPUT TYPE="Submit" Name="submit" Value="<?php echo _FSEA;?>">&nbsp;&nbsp;<INPUT TYPE="reset" Name="reset" Value="<?php echo _FRESET; ?>">
        </TD></TR>
        </TABLE>

        </TD>
</TR>
</TABLE>
</FORM>

<?php

/**********
 Sept 6.
 $query is the basis of the query
 $addquery is all the additional search fields - necessary because of the WHERE clause in SQL
**********/

$query = "SELECT u.uid,f.forum_id,p.topic_id, u.uname, p.post_time,t.topic_title,f.forum_name FROM ${prefix}_posts p, ".$user_prefix."_users u, ${prefix}_forums f, ${prefix}_forumtopics t";
if(isset($term)&&$term!="")
{
        $terms = split(" ",addslashes($term));                                // Get all the words into an array
        $addquery .= "(p.post_text LIKE '%$terms[0]%'";
        if($addterms=="any")                                        // AND/OR relates to the ANY or ALL on Search Page
                $andor = "OR";
        else
                $andor = "AND";
        $size = sizeof($terms);
        for($i=1;$i<$size;$i++)
                $addquery.=" $andor p.post_text LIKE '%$terms[$i]%'";
        $addquery.=")";
}

if(isset($forum)&&$forum!="all")
{
        if(isset($addquery))
                $addquery.=" AND p.forum_id=$forum AND f.forum_id=$forum";
        else
                $addquery.=" p.forum_id=$forum AND f.forum_id=$forum";
}
if(isset($usernamex)&&$usernamex!="")
{
        if(!$result = mysql_query("SELECT uid FROM ".$user_prefix."_users WHERE uname='$usernamex'",$db))
        {
                die("<font size=+1>"._ERRORE1."</font><hr>phpBB was unable to query the forums database");
        }
        $row = @mysql_fetch_array($result);
        if(!$row)
                die("That user does not exist.  Please go back and search again.");
        $userid = $row[uid];
        if(isset($addquery))

                $addquery.=" AND p.poster_id=$userid AND u.uname='$usernamex'";
        else
                $addquery.=" p.poster_id=$userid AND u.uname='$usernamex'";
}

if(isset($addquery))
        $query.=" WHERE $addquery AND  ";
else
        $query.=" WHERE ";
$query.=" p.topic_id = t.topic_id AND p.forum_id = f.forum_id AND (p.poster_id = u.uid || p.poster_id = '1')	AND f.forum_type != 1 GROUP BY t.topic_id ORDER BY $sortby DESC LIMIT 200";

        if(!$result = mysql_query($query,$db))
        {
                die("<font size=+1>"._ERRORE1."</font><hr>phpBB was unable to query the forums database<br>".$query."");
        }

        if(!$row = @mysql_fetch_array($result))
        {
                echo "<center>"._FNOREC."</center>";;
        }
?>
<TABLE BORDER="0" CELLPADDING="1" CELLSPACING="0" ALIGN="CENTER" VALIGN="TOP" WIDTH="100%"><TR><TD>
<TABLE BORDER="0" CELLPADDING="1" CELLSPACING="1" WIDTH="100%">
<TR BGCOLOR="<?php echo $bgcolor2?>" ALIGN="LEFT">
        <TD ALIGN="CENTER" WIDTH="30%"><FONT SIZE=1 COLOR="<?php echo $textcolor1?>"><B><?php echo _FORUM;?></B></font></TD>
        <TD ALIGN="CENTER" WIDTH="30%"><FONT SIZE=1 COLOR="<?php echo $textcolor1?>"><B><?php echo _FFTOPIC;?></B></font></TD>
        <TD ALIGN="CENTER" WIDTH="25%"><FONT SIZE=1 COLOR="<?php echo $textcolor1?>"><B><?php echo _FPOSTER;?></B></font></TD>
        <TD ALIGN="CENTER" WIDTH="15%"><FONT SIZE=1 COLOR="<?php echo $textcolor1?>"><B><?php echo _FODATE;?></B></font></TD>
</TR>
<?php
        $count=0;
        do {
        if (($count%2)!=0) $color=$bgcolor3;
        else $color=$bgcolor1;

                echo "<TR BGCOLOR=\"$color\">";
                echo "<TD ALIGN=\"CENTER\" WIDTH=\"30%\" ><a href=\"modules.php?op=modload&name=".$module_name."&file=viewforum&forum=$row[forum_id]\">". stripslashes($row[forum_name]) . "</a></TD>";
                echo "<TD ALIGN=\"CENTER\" WIDTH=\"30%\" ><a href=\"modules.php?op=modload&name=".$module_name."&file=viewtopic&topic=$row[topic_id]&forum=$row[forum_id]\">". stripslashes($row[topic_title]) . "</a></TD>";
                echo "<TD ALIGN=\"CENTER\" WIDTH=\"25%\" ><a href=\"modules.php?name=Your_Account&op=userinfo&uname=$row[uname]\">$row[uname]</a></TD>";
                echo "<TD ALIGN=\"CENTER\" WIDTH=\"15%\" ><FONT SIZE=1>".convertiData($row[post_time])."<FONT SIZE=1></TD>";
                echo "</TR>";
        $count++;
        }while($row=@mysql_fetch_array($result));

echo"</TABLE></TR></TR></TABLE>";
//<!-- Don't touch the lines below please! --> 
echo"<p align=\"center\">Splatt Forum &copy; By: <a href=\"http://www.splatt.it\" target=\"_blank\">Splatt.it</a><br>Version: $forumver</font></p><br><br>";
        include('footer.php');
?>
