<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.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.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
/********************************************************/
/* NSN GR Downloads                                     */
/* By: NukeScripts Network (webmaster@nukescripts.net)  */
/* http://www.nukescripts.net                           */
/* Copyright  2000-2005 by NukeScripts Network         */
/********************************************************/
defined('MAXIMUS') or Header("Location: index.php");

if (!isset($min)) $min=0;
if (!isset($max)) $max=$min+$dl_config['results'];
if(isset($orderby)) { $orderby = convertorderbyin($orderby); } else { $orderby = "title ASC"; }
$query = addslashes($query);
$totalselected = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_DOWNLOADS."` WHERE (`title` LIKE '%$query%' OR `description` LIKE '%$query%') AND `active`>'0'"));
$the_query = stripslashes($query);
$the_query = str_replace("\'", "'", $the_query);
$pagetitle = "- "._SEARCHRESULTS4.": $the_query";
incoh();
menu('1');
br('1');
if ($query != "") {
  title(_SEARCHRESULTS4.": $the_query");
  Max_OpenTable();
  echo "<table width='100%' bgcolor='$bgcolor2'><tr><td align='center'><font class='storytitle'><b>"._USUBCATEGORIES."</b></font></td></tr></table>";
  $crows  = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_CATEGORIES."` WHERE `title` LIKE '%$query%' AND `active`>'0' ORDER BY `title` DESC"));
  if ($crows > 0) {
    $result2 = $GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_CATEGORIES."` WHERE `title` LIKE '%$query%' ORDER BY `title` DESC");
    while($cidinfo2 = $GLOBALS['db']->sql_fetchrow($result2)) {
      $numrows = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_DOWNLOADS."` WHERE `cid`='".$cidinfo2['cid']."'"));
      $cidinfo3 = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_CATEGORIES."` WHERE `cid`='".$cidinfo2['cid']."'"));
      if ($cidinfo3['parentid'] > 0) $cidinfo3['title'] = getparent($cidinfo3['parentid'], $cidinfo3['title']);
      $cidinfo3['title'] = ereg_replace($query, "<b>$query</b>", $cidinfo3['title']);
      echo "<strong><big></big></strong>&nbsp;<a href='modules.php?name=$module_name&amp;cid=".$cidinfo2['cid']."'>".$cidinfo3['title']."</a> ($numrows)<br />";
    }
  } else {
    echo "<center><font class='option'><b>"._NOMATCHES."</b></font><br /><br /></center>";
  }
  Max_CloseTable();
  echo"<br />\n";
  Max_OpenTable();
  echo "<table width='100%' bgcolor='$bgcolor2'><tr><td align='center'><font class='storytitle'><b>"._DOWNLOADS."</b></font></td></tr></table>";
  $nrows  = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_NSNGD_DOWNLOADS."` WHERE (`title` LIKE '%$query%' OR `description` LIKE '%$query%') AND `active`>'0' ORDER BY $orderby LIMIT $min,".$dl_config['results']));
  if ($nrows>0) {
    echo "<table border='0' cellpadding='0' cellspacing='4' width='100%'>";
    $orderbyTrans = convertorderbytrans($orderby);
    echo "<tr><td align='center' colspan='2'><font class='content'>"._SORTDOWNLOADSBY.": ";
    echo ""._TITLE." (<a href='modules.php?name=$module_name&amp;op=search&amp;query=$the_query&amp;orderby=titleA'>A</a>\<a href='modules.php?name=$module_name&amp;op=search&amp;query=$the_query&amp;orderby=titleD'>D</a>) ";
    echo ""._DATE." (<a href='modules.php?name=$module_name&amp;op=search&amp;query=$the_query&amp;orderby=dateA'>A</a>\<a href='modules.php?name=$module_name&amp;op=search&amp;query=$the_query&amp;orderby=dateD'>D</a>) ";
    echo ""._POPULARITY." (<a href='modules.php?name=$module_name&amp;op=search&amp;query=$the_query&amp;orderby=hitsA'>A</a>\<a href='modules.php?name=$module_name&amp;op=search&amp;query=$the_query&amp;orderby=hitsD'>D</a>)";
    echo "<br /><b>"._RESSORTED.": $orderbyTrans</b></center></td></tr>";
    echo "</table>";
    pagenums($cid, $query, $orderby, $op, $totalselected, $dl_config['perpage'], $max);
    $x = 0;
    $a = 0;
    $result = $GLOBALS['db']->sql_query("SELECT `lid` FROM `".TABLE_NSNGD_DOWNLOADS."` WHERE (`title` LIKE '%$query%' OR `description` LIKE '%$query%') AND `active`>'0' ORDER BY $orderby LIMIT $min,".$dl_config['results']);
    echo "<table border='0' cellpadding='0' cellspacing='4' width='100%'>";
    while(list($lid) = $GLOBALS['db']->sql_fetchrow($result)) {
      if ($a == 0) { echo "<tr>"; }
      echo "<td valign='top' width='50%'><font class='content'>";
      showresulting($lid);
      echo "</font></td>";
      $a++;
      if ($a == 2) { echo "</tr>"; $a = 0; }
      $x++;
    }
    if ($a ==1) { echo "<td width=\"50%\">&nbsp;</td></tr>"; } else { echo "</tr>"; }
    $orderby = convertorderbyout($orderby);
    echo "</table>";
    pagenums($cid, $query, $orderby, $op, $totalselected, $dl_config['perpage'], $max);
  } else {
    echo "<center><font class='option'><b>"._NOMATCHES."</b></font></center><br /><br />";
  }
}
Max_CloseTable();
incof();