<?php
// File: $Id: dl-search.php,v 1.3 2001/12/09 15:44:49 gregorrothfuss Exp $ $Name: $
// ----------------------------------------------------------------------
// POST-NUKE Content Management System
// Copyright (C) 2001 by the Post-Nuke Development Team.
// http://www.postnuke.com/
// ----------------------------------------------------------------------
// Based on:
// PHP-NUKE Web Portal System - http://phpnuke.org/
// Thatware - http://thatware.org/
// ----------------------------------------------------------------------
// LICENSE
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// 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.
//
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Original Author of file: Francisco Burzi
// Purpose of file:
// ----------------------------------------------------------------------
/**
* search
*/
function search($query, $min, $orderby, $show) {
include(WHERE_IS_PERSO."config.php");
global $admin, $perpage, $bgcolor2, $ModName, $pntable, $dbconn, $modurl;
if (!isset($min)) $min=0;
if (!isset($max)) $max=$min+$downloadsresults;
if(isset($orderby)) {
$orderby = convertorderbyin($orderby);
} else {
$orderby = "title ASC";
}
if ($show!="") {
$downloadsresults = $show;
} else {
$show=$downloadsresults;
}
$query = stripslashes($query);
$column = &$pntable['downloads_downloads_column'];
$sql = "SELECT $column[lid], $column[cid], $column[sid],
$column[title], $column[url], $column[description],
$column[date], $column[hits], $column[downloadratingsummary],
$column[totalvotes], $column[totalcomments],
$column[filesize], $column[version], $column[homepage]
FROM $pntable[downloads_downloads]
WHERE $column[title] LIKE '%$query%'
OR $column[description] LIKE '%$query%'
ORDER BY '$pntable[downloads_downloads].$orderby'";
$result = $dbconn->SelectLimit($sql, $downloadsresults, $min);
$fullcountresult=$dbconn->Execute("SELECT count(*) from $pntable[downloads_downloads]
WHERE $column[title] LIKE '%$query%'
OR $column[description] LIKE '%$query%' ");
$totalselecteddownloads = $fullcountresult->PO_RecordCount();
$nrows = $result->PO_RecordCount();
$resultx = $dbconn->Execute("SELECT * FROM ".$pntable['downloads_subcategories'].
" WHERE ".$pntable['downloads_subcategories_column']['title']." LIKE '%".$query.
"%' ORDER BY ".$pntable['downloads_subcategories_column']['title']." DESC");
$nrowsx = $resultx->PO_RecordCount();
$x=0;
include("header.php");
menu(1);
echo "<br>";
OpenTable();
if ($query != "") {
if ($nrows>0 OR $nrowsx>0) {
$column = &$pntable['downloads_subcategories_column'];
$result2 = $dbconn->Execute("SELECT $column[cid], $column[sid],
$column[title] FROM $pntable[downloads_subcategories]
WHERE $column[title] LIKE '%$query%'
ORDER BY $column[title] DESC");
echo "<font class=\"pn-title\">"._SEARCHRESULTS4.": $query</font><br><br>"
."<table width=\"100%\" bgcolor=\"$bgcolor2\"><tr><td><font class=\"pn-title\">"._USUBCATEGORIES."</font></td></tr></table>";
// FTO Check EOF and databse error
if (!$result2) {
PN_DBMsgError($dbconn, __FILE__, __LINE__, "An error ocurred");
die();
}
while(!$result2->EOF) {
list($cid, $sid, $stitle) = $result2->fields;
$catname = downloads_CatNameFromCID($sid);
if (!(authorised(0, 'Downloads::Category', "$catnme::$sid", ACCESS_READ))) {
echo _DOWNLOADSACCESSNOAUTH;
include 'footer.php';
return;
}
$cate = $dbconn->Execute("SELECT {$pntable[downloads_categories_column][title]}
FROM $pntable[downloads_categories]
WHERE {$pntable[downloads_categories_column][cid]}=$cid");
list($ctitle) = $cate->fields;
$res = $dbconn->Execute("SELECT *
FROM $pntable[downloads_downloads]
WHERE {$pntable[downloads_downloads_column][sid]}=$sid");
$numrows = $res->PO_RecordCount();
$ctitle = ereg_replace($query, "<font class=\"pn-normal\">$query</font>", $ctitle);
$stitle = ereg_replace($query, "<font class=\"pn-normal\">$query</font>", $stitle);
echo "<strong><big>·</big></strong> <a class=\"pn-normal\" href=\"$modurl&req=viewsdownload&sid=$sid\">$ctitle / $stitle</a> ($numrows)<br>";
$result2->MoveNext();
}
echo "<br><table width=\"100%\" bgcolor=\"$bgcolor2\"><tr><td><font class=\"pn-title\">"._UDOWNLOADS."</font></td></tr></table>";
$orderbyTrans = convertorderbytrans($orderby);
echo "<center><font class=\"pn-normal\">"._SORTDOWNLOADSBY.": "
.""._TITLE." (<a class=\"pn-normal\" href=\"$modurl&req=search&query=$query&orderby=titleA\">A</a>\<a href=\"$modurl&req=search&query=$query&orderby=titleD\">D</a>) "
.""._DATE." (<a class=\"pn-normal\" href=\"$modurl&req=search&query=$query&orderby=dateA\">A</a>\<a href=\"$modurl&req=search&query=$query&orderby=dateD\">D</a>) "
.""._RATING." (<a class=\"pn-normal\" href=\"$modurl&req=search&query=$query&orderby=ratingA\">A</a>\<a href=\"$modurl&req=search&query=$query&orderby=ratingD\">D</a>) "
.""._POPULARITY." (<a class=\"pn-normal\" href=\"$modurl&req=search&query=$query&orderby=hitsA\">A</a>\<a href=\"$modurl&req=search&query=$query&orderby=hitsD\">D</a>)"
."<br>"._RESSORTED.": $orderbyTrans</center><br><br><br>";
// FTO Check EOF and databse error
if (!$result) {
PN_DBMsgError($dbconn, __FILE__, __LINE__, "An error ocurred");
die();
}
while(!$result->EOF) {
list($lid, $cid, $sid, $title, $url, $description, $time, $hits, $downloadratingsummary, $totalvotes, $totalcomments, $filesize, $version, $homepage) = $result->fields;
$result->MoveNext();
$downloadratingsummary = number_format($downloadratingsummary, $mainvotedecimal);
$title = stripslashes($title); $description = stripslashes($description);
$transfertitle = str_replace (" ", "_", $title);
$title = ereg_replace($query, "$query", $title);
$catname = downloads_CatNameFromCID($cid);
if (authorised(0, 'Downloads::Item', "$title:$catname:$cid", ACCESS_READ)) {
if (authorised(0, 'Downloads::Item', "$title:$catname:$cid", ACCESS_EDIT)) {
echo "<a class=\"pn-normal\" href=\"admin.php?op=DownloadsModDownload&lid=$lid\"><img src=\"modules/$ModName/images/lwin.gif\" border=\"0\" alt=\""._EDIT."\"></a> ";
} else {
echo "<img src=\"modules/$ModName/images/lwin.gif\" border=\"0\" alt=\"\"> ";
}
echo "<a class=\"pn-normal\" href=\"$modurl&req=getit&lid=$lid\">$title</a>";
newdownloadgraphic($datetime, $time);
popgraphic($hits);
detecteditorial($lid, $transfertitle, 1);
echo "<br>";
$description = ereg_replace($query, "<font class=\"pn-normal\">$query</font>", $description);
echo "<font class=\"pn-normal\">"._DESCRIPTION.": $description</font><br>";
setlocale ("LC_TIME", "$locale");
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $time, $datetime);
$datetime = ml_ftime(""._LINKSDATESTRING."", mktime($datetime[4],$datetime[5],$datetime[6],$datetime[2],$datetime[3],$datetime[1]));
$datetime = ucfirst($datetime);
echo "<font class=\"pn-normal\">"._VERSION.": $version "._FILESIZE.": ".CoolSize($filesize)."</font><br>";
echo "<font class=\"pn-normal\">"._ADDEDON.": $datetime "._UDOWNLOADS.": $hits</font>";
/* voting & comments stats */
if ($totalvotes == 1) {
$votestring = _VOTE;
} else {
$votestring = _VOTES;
}
if ($downloadratingsummary!="0" || $downloadratingsummary!="0.0") {
echo " <font class=\"pn-normal\">"._RATING.": $downloadratingsummary ($totalvotes $votestring)</font>";
}
if ($homepage == "") {
echo "<br>";
} else {
echo "<br><a class=\"pn-normal\" href=\"$homepage\" target=\"new\">"._HOMEPAGE."</a> | ";
}
if (authorised(0, 'Downloads::Item', "$title:$catname:$cid", ACCESS_COMMENT)) {
echo "<a class=\"pn-normal\" href=\"$modurl&req=ratedownload&lid=$lid&ttitle=$transfertitle\">"._RATERESOURCE."</a>";
echo " | ";
}
echo "<a class=\"pn-normal\" href=\"$modurl&req=viewdownloaddetails&lid=$lid&ttitle=$transfertitle\">"._DETAILS."</a>";
if ($totalcomments != 0) {
echo " | <a class=\"pn-normal\" href=\"$modurl&req=viewdownloadcomments&lid=$lid&ttitle=$transfertitle>"._COMMENTS." ($totalcomments)</a>";
}
detecteditorial($lid, $transfertitle, 0);
echo "<br>";
$result3 = $dbconn->Execute("SELECT {$pntable[downloads_categories_column][title]}
FROM $pntable[downloads_categories]
WHERE {$pntable[downloads_categories_column][cid]}=$cid");
$result4 = $dbconn->Execute("SELECT {$pntable[downloads_subcategories_column][title]}
FROM $pntable[downloads_subcategories]
WHERE {$pntable[downloads_subcategories_column][sid]}=$sid");
list($ctitle) = $result3->fields;
list($stitle) = $result4->fields;
if ($stitle=="") {
$slash = "";
} else {
$slash = "/";
}
echo "<font class=\"pn-normal\">"._CATEGORY.": $ctitle $slash $stitle</font><br><br>";
$x++;
}
}
echo "</font>";
$orderby = convertorderbyout($orderby);
} else {
echo "<br><br><center><font class=\"pn-title\">"._NOMATCHES."</font><br><br><font class=\"pn-normal\">"._GOBACK."</font><br></center>";
}
/* Calculates how many pages exist. Which page one should be on, etc... */
$downloadpagesint = ($totalselecteddownloads / $downloadsresults);
$downloadpageremainder = ($totalselecteddownloads % $downloadsresults);
if ($downloadpageremainder != 0) {
$downloadpages = ceil($downloadpagesint);
if ($totalselecteddownloads < $downloadsresults) {
$downloadpageremainder = 0;
}
} else {
$downloadpages = $downloadpagesint;
}
/* Page Numbering */
if ($downloadpages!=1 && $downloadpages!=0) {
echo "<br><br>"
."<font class=\"pn-normal\">"._SELECTPAGE.":</font> ";
$prev=$min-$downloadsresults;
if ($prev>=0) {
echo " [ <a class=\"pn-normal\" href=\"$modurl&req=search&query=$query&min=$prev&orderby=$orderby&show=$show\">"
." << "._PREVIOUS."</a> ] ";
}
$counter = 1;
$currentpage = ($max / $downloadsresults);
while ($counter<=$downloadpages ) {
$cpage = $counter;
$mintemp = ($perpage * $counter) - $downloadsresults;
if ($counter == $currentpage) {
echo "<font class=\"pn-normal\">$counter</font> ";
} else {
echo "<a class=\"pn-normal\" href=\"$modurl&req=search&query=$query&min=$mintemp&orderby=$orderby&show=$show\">$counter</a> ";
}
$counter++;
}
$next=$min+$downloadsresults;
if ($x>=$perpage) {
echo " [ <a class=\"pn-normal\" href=\"$modurl&req=search&query=$query&min=$max&orderby=$orderby&show=$show\">"
." "._NEXT." >></a> ]";
}
}
echo "<br><br><center><font class=\"pn-normal\">"
.""._TRY2SEARCH." \"$query\" "._INOTHERSENGINES."<br>"
."<a class=\"pn-normal\" target=\"_blank\" href=\"http://www.altavista.com/cgi-bin/query?pg=q&sc=on&hl=on&act=2006&par=0&q=$query&kl=XX&stype=stext\">Alta Vista</a> - "
."<a class=\"pn-normal\" target=\"_blank\" href=\"http://www.hotbot.com/?MT=$query&DU=days&SW=web\">HotBot</a> - "
."<a class=\"pn-normal\" target=\"_blank\" href=\"http://www.infoseek.com/Titles?qt=$query\">Infoseek</a> - "
."<a class=\"pn-normal\" target=\"_blank\" href=\"http://www.dejanews.com/dnquery.xp?QRY=$query\">Deja News</a> - "
."<a class=\"pn-normal\" target=\"_blank\" href=\"http://www.lycos.com/cgi-bin/pursuit?query=$query&maxhits=20\">Lycos</a> - "
."<a class=\"pn-normal\" target=\"_blank\" href=\"http://search.yahoo.com/bin/search?p=$query\">Yahoo</a>"
."<br>"
."<a class=\"pn-normal\" target=\"_blank\" href=\"http://es.linuxstart.com/cgi-bin/sqlsearch.cgi?pos=1&query=$query&language=&advanced=&urlonly=&withid=\">LinuxStart</a> - "
."<a class=\"pn-normal\" target=\"_blank\" href=\"http://search.1stlinuxsearch.com/compass?scope=$query&ui=sr\">1stLinuxSearch</a> - "
."<a class=\"pn-normal\" target=\"_blank\" href=\"http://www.google.com/search?q=$query\">Google</a> - "
."<a class=\"pn-normal\" target=\"_blank\" href=\"http://www.linuxdownloads.com/cgi-bin/search.cgi?query=$query&engine=Downloads\">LinuxDownloads</a> - "
."<a class=\"pn-normal\" target=\"_blank\" href=\"http://www.freshmeat.net/search.php?query=$query\">Freshmeat</a> - "
."<a class=\"pn-normal\" target=\"_blank\" href=\"http://www.justlinux.com/bin/search.pl?key=$query\">JustLinux</a>"
."</font>";
} else {
echo "<center><font class=\"pn-title\">"._NOMATCHES."</center></font><br><br>";
}
CloseTable();
include("footer.php");
}
?>