include_once("pkgs_po.inc"); # grab the current list of PackageCategories # function pkgCategories() { $cats = array(); $dbh = db_connect(); $q = "SELECT * FROM PackageCategories "; $q.= "ORDER BY Category ASC"; $result = db_query($q, $dbh); if ($result) { while ($row = mysql_fetch_row($result)) { $cats[$row[0]] = $row[1]; } } return $cats; } # grab the current list of PackageLocations # function pkgLocations() { $locs = array(); $dbh = db_connect(); $q = "SELECT * FROM PackageLocations "; $q.= "ORDER BY Location ASC"; $result = db_query($q, $dbh); if ($result) { while ($row = mysql_fetch_row($result)) { $locs[$row[0]] = $row[1]; } } return $locs; } # display the search form in a boxSoft style # function pkg_search_page($L="",$C="",$K="",$SB="",$O=0,$PP=25) { # L: PackageLocations.ID # C: PackageCategories.ID # K: Keywords # SB: Sort by # O: Row offset # PP: Per page $locs = pkgLocations(); $cats = pkgCategories(); $devs = getDevelopers(); $tus = getTrustedUsers(); $dbh = db_connect(); print "
\n"; print " ".__("Search Criteria")."\n"; print " | \n"; print "
\n"; print "\n"; print " | \n"; print "
\n"; print " \n"; print " | \n"; print "\n";
# query to pull out package info
#
$q = "SELECT Packages.*, IF(ISNULL(PackageID), 0, COUNT(*)) AS Popularity ";
$q.= "FROM Packages LEFT JOIN PackageVotes ";
$q.= "ON Packages.ID = PackageVotes.PackageID ";
$has_where = 0;
if ($L) {
$q.= "WHERE LocationID = ".intval($L)." ";
$has_where = 1;
}
if ($C) {
if (!$has_where) {
$q.= "WHERE CategoryID = ".intval($C)." ";
$has_where = 1;
} else {
$q.= "AND CategoryID = ".intval($C)." ";
}
}
if ($K) {
if (!$has_where) {
$q.= "WHERE (Name LIKE '".mysql_escape_string($K)."%' OR ";
$q.= "Description LIKE '%".mysql_escape_string($K)."%') ";
$has_where = 1;
} else {
$q.= "AND (Name LIKE '".mysql_escape_string($K)."%' OR ";
$q.= "Description LIKE '%".mysql_escape_string($K)."%') ";
}
}
$q.= "GROUP BY PackageID ";
switch ($SB) {
case 'c':
$q.= "ORDER BY CategoryID ASC, Name ASC, LocationID ASC ";
break;
case 'l':
$q.= "ORDER BY LocationID ASC, Name ASC, CategoryID ASC ";
break;
default:
$q.= "ORDER BY Name ASC, LocationID ASC, CategoryID ASC ";
break;
}
$q.= "LIMIT ".intval($O).", ".intval($PP);
$result = db_query($q, $dbh);
if (!$result) {
print $q." \n"; print __("No packages matched your search criteria."); } else { # print out package search results # print "
| \n";
print "