pkgfuncs.inc: Fix indentation.

Signed-off-by: Loui Chang <louipc.ist@gmail.com>
This commit is contained in:
Loui Chang 2009-03-03 12:11:49 -05:00
parent bbc05414cf
commit c949296a08

View file

@ -293,7 +293,7 @@ function package_details($id=0, $SID="") {
$q = "SELECT Packages.*,Location,Category "; $q = "SELECT Packages.*,Location,Category ";
$q.= "FROM Packages,PackageLocations,PackageCategories "; $q.= "FROM Packages,PackageLocations,PackageCategories ";
$q.= "WHERE Packages.LocationID = PackageLocations.ID "; $q.= "WHERE Packages.LocationID = PackageLocations.ID ";
$q.= "AND Packages.CategoryID = PackageCategories.ID "; $q.= "AND Packages.CategoryID = PackageCategories.ID ";
$q.= "AND Packages.ID = " . intval($id); $q.= "AND Packages.ID = " . intval($id);
$dbh = db_connect(); $dbh = db_connect();
@ -373,159 +373,165 @@ function package_details($id=0, $SID="") {
* do_UnNotify - Disable notification * do_UnNotify - Disable notification
*/ */
function pkg_search_page($SID="") { function pkg_search_page($SID="") {
// establish a db connection // establish a db connection
$dbh = db_connect(); $dbh = db_connect();
// get commonly used variables... // get commonly used variables...
// TODO: REDUCE DB HITS. // TODO: REDUCE DB HITS.
// grab info for user if they're logged in // grab info for user if they're logged in
if ($SID) if ($SID)
$myuid = uid_from_sid($SID); $myuid = uid_from_sid($SID);
// get a list of package locations // get a list of package locations
$locs = pkgLocations(); $locs = pkgLocations();
// get a list of package categories // get a list of package categories
$cats = pkgCategories(); //meow $cats = pkgCategories(); //meow
// sanitize paging variables // sanitize paging variables
// //
if (isset($_GET['O'])) { if (isset($_GET['O'])) {
$_GET['O'] = intval($_GET['O']); $_GET['O'] = intval($_GET['O']);
if ($_GET['O'] < 0) if ($_GET['O'] < 0)
$_GET['O'] = 0; $_GET['O'] = 0;
} else { }
$_GET['O'] = 0; else {
} $_GET['O'] = 0;
}
if (isset($_GET["PP"])) { if (isset($_GET["PP"])) {
$_GET["PP"] = intval($_GET["PP"]); $_GET["PP"] = intval($_GET["PP"]);
if ($_GET["PP"] < 25) if ($_GET["PP"] < 25)
$_GET["PP"] = 25; $_GET["PP"] = 25;
else if ($_GET["PP"] > 100) else if ($_GET["PP"] > 100)
$_GET["PP"] = 100; $_GET["PP"] = 100;
} else { }
$_GET["PP"] = 25; else {
} $_GET["PP"] = 25;
}
include('../template/pkg_search_form.php'); include('../template/pkg_search_form.php');
// FIXME: pull out DB-related code. all of it. // FIXME: pull out DB-related code. all of it.
// this one's worth a choco-chip cookie, // this one's worth a choco-chip cookie,
// one of those nice big soft ones // one of those nice big soft ones
// build the package search query // build the package search query
// //
$q = "SELECT SQL_CALC_FOUND_ROWS "; $q = "SELECT SQL_CALC_FOUND_ROWS ";
if ($SID) { if ($SID) {
$q .= "CommentNotify.UserID AS Notify, $q .= "CommentNotify.UserID AS Notify,
PackageVotes.UsersID AS Voted, "; PackageVotes.UsersID AS Voted, ";
} }
$q .= "Users.Username AS Maintainer, $q .= "Users.Username AS Maintainer,
PackageCategories.Category, PackageCategories.Category,
PackageLocations.Location, PackageLocations.Location,
Packages.Name, Packages.Version, Packages.Description, Packages.NumVotes, Packages.Name, Packages.Version, Packages.Description, Packages.NumVotes,
Packages.ID, Packages.OutOfDate Packages.ID, Packages.OutOfDate
FROM PackageCategories, PackageLocations, Packages FROM PackageCategories, PackageLocations, Packages
LEFT JOIN Users ON (Packages.MaintainerUID = Users.ID) "; LEFT JOIN Users ON (Packages.MaintainerUID = Users.ID) ";
if ($SID) {
$q .= "LEFT JOIN PackageVotes
ON (Packages.ID = PackageVotes.PackageID AND PackageVotes.UsersID = ".$myuid.")
LEFT JOIN CommentNotify
ON (Packages.ID = CommentNotify.PkgID AND CommentNotify.UserID = ".$myuid.") ";
}
$q .= "WHERE
Packages.CategoryID = PackageCategories.ID
AND Packages.LocationID = PackageLocations.ID
AND Packages.DummyPkg = 0 ";
// TODO: possibly do string matching on category and if ($SID) {
// location to make request variable values more sensible $q .= "LEFT JOIN PackageVotes
if (intval($_GET["L"])) { ON (Packages.ID = PackageVotes.PackageID AND PackageVotes.UsersID = $myuid)
$q .= "AND Packages.LocationID = ".intval($_GET["L"])." "; LEFT JOIN CommentNotify
} ON (Packages.ID = CommentNotify.PkgID AND CommentNotify.UserID = $myuid) ";
if (intval($_GET["C"])) { }
$q.= "AND Packages.CategoryID = ".intval($_GET["C"])." "; $q .= "WHERE
} Packages.CategoryID = PackageCategories.ID
AND Packages.LocationID = PackageLocations.ID
AND Packages.DummyPkg = 0 ";
if ($_GET['K']) { // TODO: possibly do string matching on category and
$_GET['K'] = mysql_real_escape_string(trim($_GET['K'])); // location to make request variable values more sensible
//search by maintainer if (intval($_GET["L"])) {
if ($_GET["SeB"] == "m"){ $q .= "AND Packages.LocationID = ".intval($_GET["L"])." ";
$q.= "AND Users.Username = '".$_GET['K']."' "; }
} elseif ($_GET["SeB"] == "s") { if (intval($_GET["C"])) {
// FIXME: this shouldn't be making 2 queries $q.= "AND Packages.CategoryID = ".intval($_GET["C"])." ";
// kill the call to uid_from_username }
$q.= "AND SubmitterUID = ".uid_from_username($_GET['K'])." ";
// the default behavior, query the name/description
} else {
$q.= "AND (Name LIKE '%".$_GET['K']."%' OR ";
$q.= "Description LIKE '%".$_GET['K']."%') ";
}
}
if ($_GET["do_Orphans"]) { if ($_GET['K']) {
$q.= "AND MaintainerUID = 0 "; $_GET['K'] = mysql_real_escape_string(trim($_GET['K']));
} # Search by maintainer
if ($_GET["SeB"] == "m") {
$q.= "AND Users.Username = '".$_GET['K']."' ";
}
elseif ($_GET["SeB"] == "s") {
// FIXME: this shouldn't be making 2 queries
// kill the call to uid_from_username
$q.= "AND SubmitterUID = ".uid_from_username($_GET['K'])." ";
// the default behavior, query the name/description
}
else {
$q.= "AND (Name LIKE '%".$_GET['K']."%' OR ";
$q.= "Description LIKE '%".$_GET['K']."%') ";
}
}
if ($_GET["do_Orphans"]) {
$q.= "AND MaintainerUID = 0 ";
}
if (isset($_GET['outdated'])) { if (isset($_GET['outdated'])) {
$q .= "AND OutOfDate = 1 "; $q .= "AND OutOfDate = 1 ";
} }
$order = $_GET["SO"] == 'd' ? 'DESC' : 'ASC'; $order = $_GET["SO"] == 'd' ? 'DESC' : 'ASC';
switch ($_GET["SB"]) { switch ($_GET["SB"]) {
case 'c': case 'c':
$q.= "ORDER BY CategoryID ".$order.", Name ASC, LocationID ASC "; $q.= "ORDER BY CategoryID ".$order.", Name ASC, LocationID ASC ";
$_GET["SB"] = 'c'; $_GET["SB"] = 'c';
break; break;
case 'l': case 'l':
$q.= "ORDER BY LocationID ".$order.", Name ASC, CategoryID DESC "; $q.= "ORDER BY LocationID ".$order.", Name ASC, CategoryID DESC ";
$_GET["SB"] = 'l'; $_GET["SB"] = 'l';
break; break;
case 'v': case 'v':
$q.= "ORDER BY NumVotes ".$order.", Name ASC, CategoryID DESC "; $q.= "ORDER BY NumVotes ".$order.", Name ASC, CategoryID DESC ";
$_GET["SB"] = 'v'; $_GET["SB"] = 'v';
break; break;
case 'm': case 'm':
$q.= "ORDER BY Maintainer ".$order.", Name ASC, LocationID ASC "; $q.= "ORDER BY Maintainer ".$order.", Name ASC, LocationID ASC ";
$_GET["SB"] = 'm'; $_GET["SB"] = 'm';
break; break;
case 'a': case 'a':
$q.= "ORDER BY GREATEST(SubmittedTS,ModifiedTS) ".$order.", Name ASC, LocationID ASC "; $q.= "ORDER BY GREATEST(SubmittedTS,ModifiedTS) ".$order.", Name ASC, LocationID ASC ";
$_GET["SB"] = 'a'; $_GET["SB"] = 'a';
break; break;
default: default:
$q.= "ORDER BY Name ".$order.", LocationID ASC, CategoryID DESC "; $q.= "ORDER BY Name ".$order.", LocationID ASC, CategoryID DESC ";
break; break;
} }
$q.= "LIMIT ".$_GET["O"].", ".$_GET["PP"]; $q.= "LIMIT ".$_GET["O"].", ".$_GET["PP"];
$result = db_query($q, $dbh); $result = db_query($q, $dbh);
$total = mysql_result(db_query('SELECT FOUND_ROWS() AS Total', $dbh), 0); $total = mysql_result(db_query('SELECT FOUND_ROWS() AS Total', $dbh), 0);
if ($result && $total > 0) { if ($result && $total > 0) {
if ($_GET["SO"] == "d"){ if ($_GET["SO"] == "d"){
$SO_next="a"; $SO_next="a";
$_GET["SO"] = 'd'; $_GET["SO"] = 'd';
} else { }
$SO_next="d"; else {
$_GET["SO"] = 'a'; $SO_next="d";
} $_GET["SO"] = 'a';
}
} }
// figure out the results to use // figure out the results to use
$first = $_GET['O'] + 1; $first = $_GET['O'] + 1;
if (($_GET['PP']+$_GET['O']) > $total) { if (($_GET['PP'] + $_GET['O']) > $total) {
$last = $total; $last = $total;
} else { } else {
$last = $_GET['PP'] + $_GET['O']; $last = $_GET['PP'] + $_GET['O'];
} }
include('pkg_search_results.php'); include('pkg_search_results.php');
return; return;
} }
/** /**