<?php
/**
 * pragmaMx  Content Management System
 * Copyright (c) 2006 pragmaMx Dev Team - http://pragmaMx.org
 * 
 * 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.
 * 
 * $Source: /home/www/dps3311/home/cvsroot/pragmamx/html/modules/Search/index.php,v $
 * $Revision: 1.5.4.7 $
 * $Author: tora60 $
 * $Date: 2006/12/03 12:02:36 $
 * 
 * this file based on:
 * php-nuke Web Portal System - http://phpnuke.org/
 * Thatware - http://thatware.org/
 */

if (!defined("mxMainFileLoaded")) die ("You can't access this file directly...");
// / die Suche nach Administratoren (Autoren) in Artikeln ermöglichen?
$search_show_authors = 0;
// / Anzahl der Suchergebnisse auf einer Seite
$offset = 10;

function convertquerystring($query)
{
    $query = stripslashes(strip_tags($query));
    $query = ereg_replace("[[:space:]]{1,}", "%", $query);
    $query = ereg_replace("[[:punct:]]{1,}", "%", $query);
    $query = trim(str_replace("%%", "%", $query));
    return $query;
} 

$module_name = basename(dirname(__FILE__));
mxGetLangfile($module_name);

$min = (empty($min)) ? 0 : intval($min);
$max = (empty($max)) ? $min + $offset : intval($min);

$sid = (empty($sid)) ? 0 : intval($sid);
$topic = (empty($topic)) ? 0 : intval($topic);

$days = (empty($days)) ? 0 : (int)$days;
$category = (empty($category)) ? "" : $category;
$author = (empty($author)) ? "" : $author;
$type = (empty($type)) ? "" : $type;

if (isset($query)) {
    $query = convertquerystring($query);
    if (empty($query)) {
        $query = '%';
    } 
} else {
    $query = '';
} 

$t = "";

if ($GLOBALS["multilingual"] == 1) {
    if (ereg("german", $GLOBALS["currentlang"])) $thislang = "german";
    else $thislang = $GLOBALS["currentlang"];
    $queryalang = "AND (s.alanguage LIKE '$thislang%' OR s.alanguage='')";
    /* stories */
    $queryslang = "AND slanguage LIKE '$thislang%' ";
    /* sections */
} else {
    $queryalang = "";
    $queryslang = "";
} 

$topictext = '';
$instory = '';

if ($type == "users") {
    $caption = _SEARCHUSERS;
} elseif ($type == "sections") {
    $caption = _SEARCHSECTIONS;
} elseif ($type == "comments" && !empty($sid)) {
    $res = sql_query("select title from ${prefix}_stories where sid='" . intval($sid) . "'");
    list($caption) = sql_fetch_row($res);
    $instory = "AND c.sid='" . intval($sid) . "'";
    $caption = _SEARCHINSTORY . " " . $caption;
} elseif ($type == "comments") {
    $caption = _SEARCHIN . " " . _SCOMMENTS;
} elseif ($type == "content") {
    $caption = _SEARCHIN . " " . _RESTOFSITE;
} elseif ($type == "forum") {
    $caption = _searchforum;
} elseif ($type == "smf") {
    $caption = _searchforum;
} elseif ($type == "coppermine") {
    $caption = _searchgal;
} elseif ($type == "galerie") {
    $caption = _searchgal;
} else {
    $type = 'stories';
    $caption = _SEARCHIN . " " . _ARTICLES;
    if ($topic) {
        $result = sql_query("select topicimage, topictext from " . $prefix . "_topics where topicid='" . intval($topic) . "'");
        list($topicimage, $topictext) = sql_fetch_row($result);
        $caption = _SEARCHIN . " " . $topictext;
        $topicimage = trim($tipath, ' ;,:./\\') . '/' . $topicimage;
        if (!is_file($topicimage)) {
            unset($topicimage);
        } 
    } 
} 

$topic_select = '';
$category_select = '';
$authors_select = '';
$date_select = '';

if (mxModuleAllowed('News')) {
    /* Topic Selection */
    $result = sql_query("select topicid, topictext from " . $prefix . "_topics ORDER BY topictext");
    if (sql_num_rows($result) > 1) {
        $topic_select .= "<select name=\"topic\">";
        $topic_select .= "<option value=\"\">" . _ALLTOPICS . "</option>\n";
        while (list($topicid, $topics) = sql_fetch_row($result)) {
            $sel = ($topicid == $topic) ? "selected" : "";
            $topic_select .= "<option $sel value=\"$topicid\">" . mxCutString($topics, 50) . "</option>\n";
            $sel = "";
        } 
        $topic_select .= "</select>";
    } 
    /* Category Selection */
    $result = sql_query("select catid, title from ${prefix}_stories_cat ORDER BY title");
    if (sql_num_rows($result) > 1) {
        $category_select .= "<select name=\"category\">";
        $category_select .= "<option value=\"0\">" . _ARTICLES . "</option>\n";
        while (list($catid, $title) = sql_fetch_row($result)) {
            if ($catid == $category) {
                $sel = "selected ";
            } 
            $category_select .= "<option $sel value=\"$catid\">" . mxCutString($title, 50) . "</option>\n";
            $sel = "";
        } 
        $category_select .= "</select>";
    } 
    /* Authors Selection */
    if ($search_show_authors) {
        $result = sql_query("SELECT DISTINCT aid FROM " . $prefix . "_stories ORDER BY aid"); 
        // nur wenn mehr als 1 Autor vorhanden
        if (sql_num_rows($result) > 1) {
            $authors_select .= "<select name=\"author\">";
            $authors_select .= "<option value=\"\">" . _ALLAUTHORS . "</option>\n";
            while (list($authors) = sql_fetch_row($result)) {
                $sel = ($authors == $author) ? "selected" : "";
                $authors_select .= "<option value=\"$authors\" $sel>" . mxCutString($authors, 50) . "</option>\n";
            } 
            $authors_select .= "</select>";
        } 
    } 

    /* Date Selection */
    $date_select .= '<select name="days">
	<option value="0"' . (($days == 0) ? ' selected' : '') . '>' . _ALL . '</option>
	<option value="7"' . (($days == 7) ? ' selected' : '') . '>1 ' . _WEEK . '</option>
	<option value="14"' . (($days == 14) ? ' selected' : '') . '>2 ' . _WEEKS . '</option>
	<option value="30"' . (($days == 30) ? ' selected' : '') . '>1 ' . _MONTH . '</option>
	<option value="60"' . (($days == 60) ? ' selected' : '') . '>2 ' . _MONTHS . '</option>
	<option value="90"' . (($days == 90) ? ' selected' : '') . '>3 ' . _MONTHS . '</option>
	</select>';
} 

if (!isset($topicimage)) {
    $topicimage = trim($tipath, ' ;,:./\\') . '/' . 'AllTopics.gif';
} 
$topicimage = mxCreateImage($topicimage, $topictext, 0, ' align="right"');

$pagetitle = _SEARCH;
include("header.php");
OpenTable();
echo '
<div align="center" class="title"><b>' . $caption . '</b>' . $topicimage . '</div><br>
<form action="modules.php" method="GET">
<table border="0" cellspacing="0" cellpadding="0" align="center"><tr valign="top">
<td><fieldset>';

if (mxModuleAllowed('News')) {
    echo '
	<input type="radio" name="type" value="stories"' . (($type == 'stories') ? 'checked' : '') . '> ' . _SSTORIES . '
	<table border="0">
	' . (($topic_select) ? '<tr><td>&nbsp;&nbsp;' . _TOPIC . ':</td><td>' . $topic_select . '</td></tr>' : '') . '
	' . (($category_select) ? '<tr><td>&nbsp;&nbsp;' . _SKATEGORIE . ':</td><td>' . $category_select . '</td></tr>' : '') . '
	' . (($date_select) ? '<tr><td>&nbsp;&nbsp;' . _STIMERANGE . ':</td><td>' . $date_select . '</td></tr>' : '') . '
	' . (($authors_select) ? '<tr><td>&nbsp;&nbsp;' . _CONTRIBUTEDBY . ':</td><td>' . $authors_select . '</td></tr>' : '') . '
	</table>
	</fieldset>
	';
    echo '</td><td>&nbsp;</td>
	<td><fieldset>';
} 

if (mxModuleAllowed('Content')) {
    echo '<input type="radio" name="type" value="content"' . (($type == 'content') ? 'checked' : '') . '> ' . _RESTOFSITE . '<br>';
} 
if (mxModuleAllowed('Sections')) {
    $num_sec = sql_num_rows(sql_query("select * from " . $prefix . "_sections"));
    if ($num_sec) {
        echo '<input type="radio" name="type" value="sections"' . (($type == 'sections') ? 'checked' : '') . '> ' . _SSECTIONS . '<br>';
    } 
} 
if (mxModuleAllowed('eBoard')) {
    echo '<input type="radio" name="type" value="forum"' . (($type == 'forum') ? 'checked' : '') . '> ' . _DFORUM . '<br>';
}
if (mxModuleAllowed('Forum')) {
    echo '<input type="radio" name="type" value="smf"' . (($type == 'smf') ? 'checked' : '') . '> Forum - SMF <br>';
}  
if (mxModuleAllowed('My_eGallery')) {
    echo '<input type="radio" name="type" value="galerie"' . (($type == 'galerie') ? 'checked' : '') . '> ' . _PGAL . '<br>';
} 
//if (mxModuleAllowed('Gallery')) {
//    echo '<input type="radio" name="type" value="coppermine"' . (($type == 'coppermine') ? 'checked' : '') . '> ' . _PGAL . ' - coppermine <br>';
//}
if (mxModuleAllowed('Userinfo')) {
    echo '<input type="radio" name="type" value="users"' . (($type == 'users') ? 'checked' : '') . '> ' . _SUSERS . '<br>';
} 
if (mxModuleAllowed('News') && $articlecomm) {
    echo '<input type="radio" name="type" value="comments"' . (($type == 'comments') ? 'checked' : '') . '> ' . _SCOMMENTS . '<br>';
} 

echo '</fieldset></td>
</tr>
<tr><td colspan="3" align="center"><br>
<input type="hidden" name="sid" value="' . $sid . '">
<input type="hidden" name="name" value="' . $module_name . '">
' . _SEARCHON . '
<input size="25" type="text" name="query" value="' . mxEntityQuotes(trim(str_replace('%', ' ', $query))) . '">
<input type="submit" value="' . _SEARCH . '">
</td></tr>
</table>
</form>
';
CloseTable();

echo '<br>';
OpenTable();
echo '<div align="center" class="title"><b>' . _SEARCHRESULTS . '</b></div><br>';
if ($type == "stories" OR !$type) {
    if ($category > 0) {
        $categ = "AND catid=" . intval($category) . " ";
    } elseif ($category == 0) {
        $categ = "";
    } 
    $q = "select s.sid, s.aid, s.informant, s.title, s.time, s.hometext, s.bodytext, a.url, s.comments, s.topic, t.topictext from ${prefix}_stories s, " . $prefix . "_authors a, " . $prefix . "_topics t where (s.aid=a.aid AND s.topic=t.topicid) AND s.time <= now() " . $queryalang . " " . $categ;
    if (!empty($query)) $q .= "AND (s.title LIKE '%" . mxAddSlashesForSQL($query) . "%' OR s.hometext LIKE '%" . mxAddSlashesForSQL($query) . "%' OR s.bodytext LIKE '%" . mxAddSlashesForSQL($query) . "%' OR s.notes LIKE '%" . mxAddSlashesForSQL($query) . "%') ";
    if (!empty($author) && $search_show_authors) $q .= "AND s.aid='" . mxAddSlashesForSQL($author) . "' ";
    if (!empty($topic)) $q .= "AND s.topic='" . intval($topic) . "' ";
    if (!empty($days)) $q .= "AND TO_DAYS(NOW()) - TO_DAYS(time) <= '" . intval($days) . "' ";
    $q .= " ORDER BY s.time DESC LIMIT " . intval($min) . "," . intval($offset);
    $var = (empty($topic)) ? "" : $topic;
    $result = sql_query($q);
    $nrows = sql_num_rows($result);
    $x = 0;
    if (!empty($query)) {
        echo "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"5\" border=\"0\" bgcolor=\"$bgcolor1\">\n";
        if ($nrows > 0) {
            while (list($sid, $aid, $informant, $title, $time, $hometext, $bodytext, $url, $comments, $topic, $topictext) = sql_fetch_row($result)) {
                $furl = "modules.php?name=News&amp;file=article&amp;sid=$sid";
                $datetime = formatTimestamp($time);
                if ($informant == "") {
                    $informant = $anonymous;
                } else {
                    $informant = "<a href=\"modules.php?name=Userinfo&amp;uname=$informant\">$informant</a>";
                } 
                $a = 0;
                $match = "";
                if (!empty($query)) {
                    if (eregi("$query", $title)) {
                        $a = 1;
                    } 
                    $text = "$hometext$bodytext";
                    if (eregi("$query", $text)) {
                        $a = 2;
                    } 
                    if (eregi("$query", $text) AND eregi("$query", $title)) {
                        $a = 3;
                    } 
                    if ($a == 1) {
                        $match = _MATCHTITLE;
                    } elseif ($a == 2) {
                        $match = _MATCHTEXT;
                    } elseif ($a == 3) {
                        $match = _MATCHBOTH;
                    } 
                    if (!isset($a)) {
                        $match = "";
                    } else {
                        $match = "$match<br>";
                    } 
                } 
                printf("<tr bgcolor=\"$bgcolor2\"><td><img src=\"images/folders.gif\" border=\"0\" alt=\"\">&nbsp;<font class=\"option\"><a href=\"%s\"><b>%s</b></a></font><br><font class=\"content\">" . _CONTRIBUTEDBY . " $informant<br>" . _POSTEDBY . " <a href=\"%s\">%s</a>", $furl, $title, $url, $aid, $informant);
                echo " " . _ON . " $datetime<br>"
                 . "$match"
                 . _TOPIC . ": <a href=\"modules.php?name=$module_name&amp;query=&amp;topic=$topic\">$topictext</a> ";
                if ($comments == 0) {
                    echo "(" . _NOCOMMENTS . ")";
                } elseif ($comments == 1) {
                    echo "($comments " . _UCOMMENT . ")";
                } elseif ($comments > 1) {
                    echo "($comments " . _UCOMMENTS . ")";
                } 
                if (MX_IS_ADMIN) {
                    echo " [&nbsp;<a href=\"admin.php?op=EditStory&amp;sid=$sid\">" . _EDIT . "</a> | <a href=\"admin.php?op=RemoveStory&amp;sid=$sid\">" . _DELETE . "</a>&nbsp;]";
                } 
                echo "</font><br></td></tr>\n";
                $x++;
            } 
            echo "</table>";
        } else {
            echo "<tr><td><center><font class=\"option\"><b>" . _NOMATCHES . "</b></font></center><br><br>";
            echo "</td></tr></table>";
        } 
        $prev = $min - $offset;
        if ($prev >= 0) {
            print "<br><br><center><a href=\"modules.php?name=$module_name&amp;author=$author&amp;topic=$t&amp;min=$prev&amp;query=$query&amp;type=$type&amp;category=$category\">";
            print "<b>$min " . _PREVMATCHES . "</b></a></center>";
        } 
        $next = $min + $offset;
        if ($x >= ($offset-1)) {
            print "<br><br><center><a href=\"modules.php?name=$module_name&amp;author=$author&amp;topic=$t&amp;min=$max&amp;query=$query&amp;type=$type&amp;category=$category\">";
            print "<b>" . _NEXTMATCHES . "</b></a></center>";
        } 
    } 
} elseif ($type == "comments") {
    $qry = "select c.tid, c.sid, c.subject, c.reply_date, c.name, s.title from " . $prefix . "_comments AS c, ${prefix}_stories AS s where c.sid=s.sid AND (c.subject LIKE '%" . mxAddSlashesForSQL($query) . "%' OR c.comment LIKE '%" . mxAddSlashesForSQL($query) . "%') AND s.time <= now() $instory ORDER BY reply_date DESC limit " . intval($min) . "," . intval($offset);
    $result = sql_query($qry);
    $nrows = sql_num_rows($result);
    $x = 0;
    if (!empty($query)) {
        echo "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"5\" border=\"0\" bgcolor=\"$bgcolor1\">\n";
        if ($nrows > 0) {
            while (list($tid, $sid, $subject, $date, $name, $title) = sql_fetch_row($result)) {
                // $reply = sql_num_rows(sql_query("select * from ".$prefix."_comments where pid='$tid'"));
                $furl = "modules.php?name=News&amp;file=article&amp;sid=$sid#$tid";
                if (empty($subject)) {
                    $subject = 're: ' . $title;
                } 
                if ($name && $name != $anonymous) {
                    $name = "<a href=\"modules.php?name=Userinfo&amp;uname=$name\">$name</a>";
                } 
                $datetime = mx_strftime(_DATESTRING, $date);
                echo "<tr bgcolor=\"$bgcolor2\"><td><img src=\"images/folders.gif\" border=\"0\" alt=\"\">&nbsp;<font class=\"option\"><a href=\"$furl\"><b>$subject</b></a></font><font class=\"content\"><br>" . _POSTEDBY . " $name"
                 . " " . _ON . " $datetime<br>"
                 . _ATTACHART . ": $title<br>"; 
                // if ($reply == 1)
                // {
                // echo "($reply "._SREPLY.")";
                // }
                // else
                // {
                // echo "($reply "._SREPLIES.")";
                // }
                if (MX_IS_ADMIN) {
                    echo " [&nbsp;<a href=\"admin.php?op=RemoveComment&amp;tid=$tid&amp;sid=$sid\">" . _DELETE . "</a>&nbsp;]";
                } 
                echo "<br></font></td></tr>\n";
                $x++;
            } 
            echo "</table>";
        } else {
            echo "<tr><td><center><font class=\"option\"><b>" . _NOMATCHES . "</b></font></center><br><br>";
            echo "</td></tr></table>";
        } 
        $prev = $min - $offset;
        if ($prev >= 0) {
            print "<br><br><center><a href=\"modules.php?name=$module_name&amp;author=$author&amp;topic=$topic&amp;min=$prev&amp;query=$query&amp;type=$type\">";
            print "<b>$min " . _PREVMATCHES . "</b></a></center>";
        } 
        $next = $min + $offset;
        if ($x >= ($offset-1)) {
            print "<br><br><center><a href=\"modules.php?name=$module_name&amp;author=$author&amp;topic=$topic&amp;min=$max&amp;query=$query&amp;type=$type\">";
            print "<b>" . _NEXTMATCHES . "</b></a></center>";
        } 
    } 
} elseif ($type == "sections") {
    $result = sql_query("select a.artid, a.secid, a.title, a.content, b.secname from " . $prefix . "_seccont a, " . $prefix . "_sections b where a.secid=b.secid AND (a.title LIKE '%" . mxAddSlashesForSQL($query) . "%' OR a.content LIKE '%" . mxAddSlashesForSQL($query) . "%') $queryslang ORDER BY a.artid DESC limit " . intval($min) . "," . intval($offset));
    $nrows = sql_num_rows($result);
    $x = 0;
    if (!empty($query)) {
        echo "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"5\" border=\"0\" bgcolor=\"$bgcolor1\">\n";
        if ($nrows > 0) {
            while (list($artid, $secid, $title, $content, $sectitle) = sql_fetch_row($result)) {
                $pages = count(explode("<!--pagebreak-->", $content)); 
                // $result2 = sql_query("select secname from ".$prefix."_sections where secid='$secid'");
                // list($sectitle) = sql_fetch_row($result2);
                $surl = "modules.php?name=Sections&amp;sop=listarticles&amp;secid=$secid";
                $furl = "modules.php?name=Sections&amp;sop=viewarticle&amp;artid=$artid";
                echo "<tr bgcolor=\"$bgcolor2\"><td><img src=\"images/folders.gif\" border=\"0\" alt=\"\">&nbsp;<font class=\"option\"><a href=\"$furl\"><b>$title</b></a></font><font class=\"content\"><br>" . _INSECTION . ": <a href=\"$surl\">$sectitle</a><br>";
                if ($pages == 1) {
                    echo "($pages " . _PAGE . ")";
                } else {
                    echo "($pages " . _PAGES . ")";
                } 
                if (MX_IS_ADMIN) {
                    echo " [&nbsp;<a href=\"admin.php?op=secartedit&amp;artid=$artid\">" . _EDIT . "</a> | <a href=\"admin.php?op=secartdelete&amp;artid=$artid&amp;ok=0\">" . _DELETE . "</a>&nbsp;]";
                } 
                echo "</font><br></td></tr>\n";
                $x++;
            } 
            echo "</table>";
        } else {
            echo "<tr><td><center><font class=\"option\"><b>" . _NOMATCHES . "</b></font></center><br><br>";
            echo "</td></tr></table>";
        } 
        $prev = $min - $offset;
        if ($prev >= 0) {
            print "<br><br><center><a href=\"modules.php?name=$module_name&amp;author=$author&amp;topic=$t&amp;min=$prev&amp;query=$query&amp;type=$type\">";
            print "<b>$min " . _PREVMATCHES . "</b></a></center>";
        } 
        $next = $min + $offset;
        if ($x >= ($offset-1)) {
            print "<br><br><center><a href=\"modules.php?name=$module_name&amp;author=$author&amp;topic=$t&amp;min=$max&amp;query=$query&amp;type=$type\">";
            print "<b>" . _NEXTMATCHES . "</b></a></center>";
        } 
    } 
} elseif ($type == "users") {
    $userstat = (mxGetadminPref('radminuser')) ? '' : ' AND user_stat=1';
    $result = sql_query("select uid, uname, name from " . $user_prefix . "_users where (uname LIKE '%" . mxAddSlashesForSQL($query) . "%' OR name LIKE '%" . mxAddSlashesForSQL($query) . "%' OR bio LIKE '%" . mxAddSlashesForSQL($query) . "%' OR femail LIKE '%" . mxAddSlashesForSQL($query) . "%') " . $userstat . " ORDER BY uname ASC limit " . intval($min) . "," . intval($offset));
    $nrows = sql_num_rows($result);
    $x = 0;
    if (!empty($query)) {
        echo "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"5\" border=\"0\" bgcolor=\"$bgcolor1\">\n";
        if ($nrows > 0) {
            while (list($uid, $uname, $name) = sql_fetch_row($result)) {
                $furl = "modules.php?name=Userinfo&amp;uname=$uname";
                if ($name == "") {
                    $name = _NONAME;
                } 
                echo "<tr bgcolor=\"$bgcolor2\"><td><img src=\"images/folders.gif\" border=\"0\" alt=\"\">&nbsp;<font class=\"option\"><a href=\"$furl\"><b>$uname</b></a></font><font class=\"content\"> ($name)";
                if (MX_IS_ADMIN) {
                    echo " [&nbsp;<a href=\"admin.php?chng_uid=$uid&amp;op=modifyUser\">" . _EDIT . "</a> | <a href=\"admin.php?op=delUser&amp;chng_uid=$uid\">" . _DELETE . "</a>&nbsp;]";
                } 
                echo "</font></td></tr>\n";
                $x++;
            } 
            echo "</table>";
        } else {
            echo "<tr><td><center><font class=\"option\"><b>" . _NOMATCHES . "</b></font></center><br><br>";
            echo "</td></tr></table>";
        } 
        $prev = $min - $offset;
        if ($prev >= 0) {
            print "<br><br><center><a href=\"modules.php?name=$module_name&amp;author=$author&amp;topic=$t&amp;min=$prev&amp;query=$query&amp;type=$type\">";
            print "<b>$min " . _PREVMATCHES . "</b></a></center>";
        } 
        $next = $min + $offset;
        if ($x >= ($offset-1)) {
            print "<br><br><center><a href=\"modules.php?name=$module_name&amp;author=$author&amp;topic=$t&amp;min=$max&amp;query=$query&amp;type=$type\">";
            print "<b>" . _NEXTMATCHES . "</b></a></center>";
        } 
    } 
} 
// ######################BEGINN CONTENT###############################
elseif ($type == "content") {
    $result = sql_query("select pid, title, subtitle, page_header, text, page_footer, `date`, counter from " . $prefix . "_pages where (title LIKE '%" . mxAddSlashesForSQL($query) . "%' OR subtitle LIKE '%" . mxAddSlashesForSQL($query) . "%' OR page_header LIKE '%" . mxAddSlashesForSQL($query) . "%' OR text LIKE '%" . mxAddSlashesForSQL($query) . "%' OR page_footer LIKE '%" . mxAddSlashesForSQL($query) . "%') ORDER BY counter DESC limit " . intval($min) . "," . intval($offset));
    $nrows = sql_num_rows($result);
    $x = 0;
    if (!empty($query)) {
        echo "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"5\" border=\"0\" bgcolor=\"$bgcolor1\">\n";
        if ($nrows > 0) {
            while (list($pid, $title, $subtitle, $page_header, $text, $page_footer, $date, $counter) = sql_fetch_row($result)) {
                $titel = trim(substr($title, 0, 35));
                echo "<tr><td width =\"50%\">"
                 . "<img src=\"images/folders.gif\">"
                 . "<strong><a href=\"modules.php?name=Content&amp;pa=showpage&amp;pid=$pid\"> $titel...</a></strong>"
                 . "</td>"
                 . "<td width=\"25%\">$date</td>"
                 . "<td width=\"25%\">$counter mal gelesen.</td></tr>";
                $x++;
            } 
            echo "</table>";
        } else {
            echo "<tr><td><center><font class=\"option\"><b>" . _NOMATCHES . "</b></font></center><br><br>";
            echo "</td></tr></table>";
        } 
        $prev = $min - $offset;
        if ($prev >= 0) {
            print "<br><br><center><a href=\"modules.php?name=Search&amp;author=$author&amp;topic=$t&amp;min=$prev&amp;query=$query&amp;type=$type\">";
            print "<b>$min " . _PREVMATCHES . "</b></a></center>";
        } 
        $next = $min + $offset;
        if ($x >= ($offset-1)) {
            print "<br><br><center><a href=\"modules.php?name=Search&amp;author=$author&amp;topic=$t&amp;min=$max&amp;query=$query&amp;type=$type\">";
            print "<b>" . _NEXTMATCHES . "</b></a></center>";
        } 
    } 
} 
// ######################ENDE CONTENT#################################
// ######################BEGINN eBOARD################################
elseif ($type == "forum") {
    unset($table_posts);
    if (@file_exists('modules/eBoard/settings.php')) {
        include('modules/eBoard/settings.php');
        $result = sql_query("select tid, subject, author, icon, message from " . $table_threads . " WHERE (subject LIKE '%" . mxAddSlashesForSQL($query) . "%' OR message LIKE '%" . mxAddSlashesForSQL($query) . "%') ORDER BY tid DESC limit " . intval($min) . "," . intval($offset));
        $nrows = sql_num_rows($result);
    } else {
        $nrows = 0;
        $result = false;
    } 
    print "<br><strong>Dans les fils de discussions: </strong><br><br>";
    $x = 0;
    if (!empty($query)) {
        echo "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"5\" border=\"0\" bgcolor=\"$bgcolor1\">\n";
        if ($nrows > 0) {
            while (list($tid, $subject, $author, $icon, $message) = sql_fetch_row($result)) {
                // Anzahl der Antworten
                // $neuezahl=$tid;
                // $result1 = sql_query("select tid from ".$prefix."_eBoard_posts where (tid like ".intval($neuezahl).") ORDER BY tid DESC limit ".intval($min).",".intval($offset));
                // $nrows1  = sql_num_rows($result1);
                // Ende
                $text = trim(substr($subject, 0, 45));
                if ($icon == "") $icon = "smilies/exclamation.gif";

                echo "<tr bgcolor=\"$bgcolor2\"><td width =\"60%\">"
                 . "<img src=\"modules/eBoard/images/$icon\">"
                 . "<strong><a href=\"modules.php?name=eBoard&amp;file=viewthread&amp;tid=$tid\"> $text...</a></strong>"
                 . "</td><td width=\"25%\">"
                 . "<a href=\"modules.php?name=Userinfo&amp;uname=$author\">$author</a>"
                 . "</td><td width=\"15%\">" 
                // ."$nrows1 Antwort (en)."
                . "</td></tr>";
                $x++;
            } 
            echo"</table>";
        } else {
            echo "<tr><td><center><font class=\"option\"><b>" . _NOMATCHES . "</b></font></center><br><br>";
            echo "</td></tr></table>";
        } 
        $prev = $min - $offset;
        if ($prev >= 0) {
            print "<br><br><center><a href=\"modules.php?name=Search&amp;author=$author&amp;topic=$t&amp;min=$prev&amp;query=$query&amp;type=$type\">";
            print "<b>$min " . _PREVMATCHES . "</b></a></center>";
        } 
        $next = $min + $offset;
        if ($x >= ($offset-1)) {
            print "<br><br><center><a href=\"modules.php?name=Search&amp;author=$author&amp;topic=$t&amp;min=$max&amp;query=$query&amp;type=$type\">";
            print "<b>" . _NEXTMATCHES . "</b></a></center>";
        } 
    } 
    // ############ Antworten
    if (isset($table_posts)) {
        $result2 = sql_query("select fid, pid, tid, author, message, dateline from " . $table_posts . " where (message LIKE '%" . mxAddSlashesForSQL($query) . "%') ORDER BY pid DESC limit " . intval($min) . "," . intval($offset));
        $nrows2 = sql_num_rows($result2);
    } else {
        $nrows2 = 0;
        $result2 = false;
    } 
    print "<br><strong>in den Antworten: </strong><br><br>";
    if (!empty($query)) {
        echo "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"5\" border=\"0\" bgcolor=\"$bgcolor1\">\n";
        while (list($fid, $pid, $tid, $author, $message, $dateline) = sql_fetch_row($result2)) {
            $antwort = trim(substr($message, 0, 45));
            echo "<tr bgcolor=\"$bgcolor2\"><td width =\"60%\">"
             . "<a href=\"modules.php?name=eBoard&amp;file=viewthread&amp;tid=$tid#pid$pid\">"
             . "<img src=\"modules/eBoard/images/smilies/exclamation.gif\" border=\"0\">"
             . "$antwort..."
             . "</td><td width=\"25%\">"
             . "<a href=\"modules.php?name=Userinfo&amp;uname=$author\">$author</a>"
             . "</td><td width=\"15%\">"
             . "<a href=\"modules.php?name=eBoard&amp;file=forumdisplay&amp;fid=$fid\">"
             . "Forum ID: $fid</a>"
             . "</td></tr>";
        } 

        echo"</table>";
    } 
} 
// ######################ENDE eBOARD################################
// ######################BEGINN smf ################################
elseif ($type == "smf") {
    
    if (@file_exists('modules/Forum/smf/Settings.php')) {
        include('modules/Forum/smf/Settings.php');
        
		$result = sql_query("select ID_TOPIC, ID_MSG, subject, posterName, icon, body from {$db_prefix}messages WHERE (subject LIKE '%" . mxAddSlashesForSQL($query) . "%' OR body LIKE '%" . mxAddSlashesForSQL($query) . "%') ORDER BY ID_TOPIC DESC limit " . intval($min) . "," . intval($offset));
        $nrows = sql_num_rows($result);
        
    } else {
        $nrows = 0;
        $result = false;
    } 
    print "<br><strong>in Threads: </strong><br><br>";
    $x = 0;
    if (!empty($query)) {
        echo "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"5\" border=\"0\" bgcolor=\"$bgcolor1\">\n";
        if ($nrows > 0) {
            while (list($id_topic , $id_msg, $subject, $author, $icon, $message) = sql_fetch_row($result)) {
                // Anzahl der Antworten
                // $neuezahl=$tid;
                // $result1 = sql_query("select tid from ".$prefix."_eBoard_posts where (tid like ".intval($neuezahl).") ORDER BY tid DESC limit ".intval($min).",".intval($offset));
                // $nrows1  = sql_num_rows($result1);
                // Ende
                $text = trim(substr($subject, 0, 45));
                if ($icon == "") $icon = "exclamation.gif";

                echo "<tr bgcolor=\"$bgcolor2\"><td width =\"60%\">"
                 . "<img src=\"modules/Forum/smf/Themes/mx-port/images/post/{$icon}.gif\">"
                 . "<strong><a href=\"modules.php?name=Forum&topic={$id_topic}.msg{$id_msg}\"> $text...</a></strong>"
                 . "</td><td width=\"25%\">"
                 . "<a href=\"modules.php?name=Userinfo&amp;uname=$author\">$author</a>"
                 . "</td><td width=\"15%\">" 
                // ."$nrows1 Antwort (en)."
                . "</td></tr>";
                $x++;
            } 
            echo"</table>";
        } else {
            echo "<tr><td><center><font class=\"option\"><b>" . _NOMATCHES . "</b></font></center><br><br>";
            echo "</td></tr></table>";
        } 
        $prev = $min - $offset;
        if ($prev >= 0) {
            print "<br><br><center><a href=\"modules.php?name=Search&amp;author=$author&amp;topic=$t&amp;min=$prev&amp;query=$query&amp;type=$type\">";
            print "<b>$min " . _PREVMATCHES . "</b></a></center>";
        } 
        $next = $min + $offset;
        if ($x >= ($offset-1)) {
            print "<br><br><center><a href=\"modules.php?name=Search&amp;author=$author&amp;topic=$t&amp;min=$max&amp;query=$query&amp;type=$type\">";
            print "<b>" . _NEXTMATCHES . "</b></a></center>";
        } 
    } 

} 
// ######################ENDE smf ################################
// ######################BEGINN GALLERIE############################
elseif ($type == "galerie") {
    $result = sql_query("select pid, submitter, `date`, name, description from " . $prefix . "_gallery_pictures where (name LIKE '%" . mxAddSlashesForSQL($query) . "%' OR description LIKE '%" . mxAddSlashesForSQL($query) . "%') ORDER BY date DESC limit " . intval($min) . "," . intval($offset));
    $nrows = sql_num_rows($result);
    $x = 0;
    if (!empty($query)) {
        echo "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"5\" border=\"0\" bgcolor=\"$bgcolor1\">\n";
        if ($nrows > 0) {
            while (list($pid, $submitter, $date, $name, $description) = sql_fetch_row($result)) {
                $text = trim(substr($description, 0, 35));
                if ($text == "") {
                    $text = $name;
                } 
                $on = _ON;
                $by = _BY;
                echo "<tr bgcolor=\"$bgcolor2\"><td width =\"50%\">"
                 . "<img src=\"images/folders.gif\">"
                 . "<strong><a href=\"modules.php?name=My_eGallery&amp;do=showpic&amp;pid=$pid\">$text</a>...</strong></td>"
                 . "<td width=\"25%\">"
                 . "$by <a href=\"modules.php?name=Userinfo&amp;uname=$submitter\">$submitter</a>"
                 . "</td><td width=\"25%\">$on $date</td></tr>";
                $text = "";
                $x++;
            } 
            echo "</table>";
        } else {
            echo "<tr><td><center><font class=\"option\"><b>" . _NOMATCHES . "</b></font></center><br><br>";
            echo "</td></tr></table>";
        } 
        $prev = $min - $offset;
        if ($prev >= 0) {
            print "<br><br><center><a href=\"modules.php?name=Search&amp;author=$author&amp;topic=$t&amp;min=$prev&amp;query=$query&amp;type=$type\">";
            print "<b>$min " . _PREVMATCHES . "</b></a></center>";
        } 
        $next = $min + $offset;
        if ($x >= ($offset-1)) {
            print "<br><br><center><a href=\"modules.php?name=Search&amp;author=$author&amp;topic=$t&amp;min=$max&amp;query=$query&amp;type=$type\">";
            print "<b>" . _NEXTMATCHES . "</b></a></center>";
        } 
    } 
} 
// #####################ENDE GALLERIE###############################
// ######################BEGINN COPPERMINE GALLERIE############################
elseif ($type == "coppermine") {
    
    if (@file_exists('modules/Gallery/include/config.inc.php')) {
        define('IN_COPPERMINE', true);
		include('modules/Gallery/include/config.inc.php');
       
	$result = sql_query("select pid, aid, ctime, title, caption, owner_name, filename from " . $CONFIG['TABLE_PREFIX'] . "pictures where (title LIKE '%" . mxAddSlashesForSQL($query) . "%' OR caption LIKE '%" . mxAddSlashesForSQL($query) . "%') ORDER BY ctime DESC limit " . intval($min) . "," . intval($offset));
    $nrows = sql_num_rows($result);
    $x = 0;
    if (!empty($query)) {
        echo "<table width=\"100%\" cellspacing=\"1\" cellpadding=\"5\" border=\"0\" bgcolor=\"$bgcolor1\">\n";
        if ($nrows > 0) {
            while (list($pid, $aid, $date, $name, $description, $submitter, $filename) = sql_fetch_row($result)) {
                $text = trim(substr($description, 0, 35));
                if ($text == "") {
                    $text = $name;
                   if ($text == "") {
                       $text = $filename;
                
				   } 
                } 
                $on = _ON;
                $by = _BY;
                $date = date('Y-m-d H:i:s', $date) ."\n";
                echo "<tr bgcolor=\"$bgcolor2\"><td width =\"50%\">"
                 . "<img src=\"images/folders.gif\">"
                 . "<strong><a href=\"modules.php?name=Gallery&act=displayimage&pos=-$pid\">$text</a>...</strong></td>"
                 . "<td width=\"25%\">"
                 . " $by <a href=\"modules.php?name=Userinfo&amp;uname=$submitter\">$submitter</a>"
                 . "</td><td width=\"25%\">$on $date</td></tr>";
                $text = "";
                $x++;
            } 
            echo "</table>";
        } else {
            echo "<tr><td><center><font class=\"option\"><b>" . _NOMATCHES . "</b></font></center><br><br>";
            echo "</td></tr></table>";
        } 
        $prev = $min - $offset;
        if ($prev >= 0) {
            print "<br><br><center><a href=\"modules.php?name=Search&amp;author=$author&amp;topic=$t&amp;min=$prev&amp;query=$query&amp;type=$type\">";
            print "<b>$min " . _PREVMATCHES . "</b></a></center>";
        } 
        $next = $min + $offset;
        if ($x >= ($offset-1)) {
            print "<br><br><center><a href=\"modules.php?name=Search&amp;author=$author&amp;topic=$t&amp;min=$max&amp;query=$query&amp;type=$type\">";
            print "<b>" . _NEXTMATCHES . "</b></a></center>";
        } 
    } 
} 
}
// #####################ENDE COPPERMINE GALLERIE###############################
CloseTable();
$mods = "";
if (!empty($query)) {
    if (mxModuleAllowed("Downloads")) {
        $cnt = sql_num_rows(sql_query("select * from " . $prefix . "_downloads_downloads WHERE cid > 0 AND (title LIKE '%" . mxAddSlashesForSQL($query) . "%' OR description LIKE '%" . mxAddSlashesForSQL($query) . "%')"));
        $mods .= "<li> <a href=\"modules.php?name=Downloads&amp;op=search&amp;query=$query\">" . _DOWNLOADS . "</a> ($cnt " . _SEARCHRESULTS . ")";
    } 

    if (mxModuleAllowed("Web_Links")) {
        $cnt = sql_num_rows(sql_query("select * from " . $prefix . "_links_links WHERE title LIKE '%" . mxAddSlashesForSQL($query) . "%' OR description LIKE '%" . mxAddSlashesForSQL($query) . "%'"));
        $mods .= "<li> <a href=\"modules.php?name=Web_Links&amp;op=search&amp;query=$query\">" . _WEBLINKS . "</a> ($cnt " . _SEARCHRESULTS . ")";
    } 
    // / Die Suche in der Enzyklopädie funktiooniert nicht ohne Angabe der $eid !!!
    // if (mxModuleAllowed("Encyclopedia"))
    // {
    // $cnt = sql_num_rows(sql_query("select a.title, a.description, b.title, b.text from ".$prefix."_encyclopedia a, ".$prefix."_encyclopedia_text b  WHERE a.eid=b.eid AND (active='1') AND ((a.title LIKE '%".mxAddSlashesForSQL($query)."%' OR a.description LIKE '%".mxAddSlashesForSQL($query)."%') OR (b.title LIKE '%".mxAddSlashesForSQL($query)."%' OR b.text LIKE '%".mxAddSlashesForSQL($query)."%'))"));
    // $mods .= "<li> <a href=\"modules.php?name=Encyclopedia&amp;file=search&amp;query=$query&amp;eid=\">"._ENCYCLOPEDIA."</a> ($cnt "._SEARCHRESULTS.")";
    // }
} 

$query = trim(str_replace("%", " ", $query));
if (!empty($query)) {
    echo '<br>';
    OpenTable();
    echo "<div class=\"title\">" . _FINDMORE . "</div><br>
	    <div class=\"content\">" . _DIDNOTFIND . "<br><br>"
     . _SEARCH . " \"<b>$query</b>\" " . _SEARCHINGIN . ":<br><br>"
     . "<ul>"
     . $mods
     . "<li> <a href=\"http://www.google.com/search?q=" . urlencode($query) . "\" target=\"new\">Google</a>"
     . "<li> <a href=\"http://groups.google.com/groups?q=" . urlencode($query) . "\" target=\"new\">Google Groups</a>"
     . "</ul></div>";
    CloseTable();
} 

include("footer.php");

?>

