From ae26c9ce2a0bfe6ed0f5282f08cb672364de1c19 Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 2 Jul 2004 12:47:16 +0000 Subject: baby steps --- web/lib/pkgfuncs.inc | 109 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 79 insertions(+), 30 deletions(-) (limited to 'web/lib/pkgfuncs.inc') diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index 15dd2d66..ae306577 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -1,6 +1,49 @@ "; + print __("Go back to %hsearch results%h.", + array($url_data, "")); + + return; +} + + +# see if this Users.ID can manage the package +# +function canManagePackage($uid=0,$AURMUID=0, $MUID=0, $SUID=0, $managed=0) { + if (!$uid) {return 0;} + + # The uid of the TU/Dev that manages the package + # + if ($uid == $AURMUID) {return 1;} + + # If the package isn't maintained by a TU/Dev, is this the user-maintainer? + # + if ($uid == $MUID && !$managed) {return 1;} + + # If the package isn't maintained by a TU/Dev, is this the user-submitter? + # + if ($uid == $SUID && !$managed) {return 1;} + + # otherwise, no right to manage this package + # + return 0; +} + # grab the current list of PackageCategories # function pkgCategories() { @@ -197,21 +240,22 @@ function pkg_search_page($SID="") { # determine paging variables # - isset($_REQUEST["PP"]) ? $PP = intval($_REQUEST["PP"]) : $PP = 25; + $_REQUEST["PP"] ? $PP = intval($_REQUEST["PP"]) : $PP = 25; if ($PP < 25) {$PP = 25;} if ($PP > 100) {$PP = 100;} - isset($_REQUEST["O"]) ? $O = intval($_REQUEST["O"]) : $O = 0; - if (isset($_REQUEST["do_More"])) { + $_REQUEST["O"] ? $O = intval($_REQUEST["O"]) : $O = 0; + if ($_REQUEST["do_More"]) { $O += $PP; - } elseif (isset($_REQUEST["do_Less"])) { + } elseif ($_REQUEST["do_Less"]) { $O -= $PP; } if ($O < 0) { $O = 0; } - if (isset($_REQUEST["do_Search"]) || isset($_REQUEST["do_MyPackages"])) { + if ($_REQUEST["do_Search"]) { # reset the offset to zero if they hit Go/My Packages # + $_REQUEST["do_MyPackages"] = 0; $O = 0; } @@ -341,11 +385,11 @@ function pkg_search_page($SID="") { # $q.= "ON Packages.ID = PackageVotes.PackageID "; $q = "SELECT * FROM Packages "; $has_where = 0; - if (isset($_REQUEST["L"]) && intval($_REQUEST["L"])) { + if (intval($_REQUEST["L"])) { $q.= "WHERE LocationID = ".intval($_REQUEST["L"])." "; $has_where = 1; } - if (isset($_REQUEST["C"]) && intval($_REQUEST["C"])) { + if (intval($_REQUEST["C"])) { if (!$has_where) { $q.= "WHERE CategoryID = ".intval($_REQUEST["C"])." "; $has_where = 1; @@ -363,18 +407,18 @@ function pkg_search_page($SID="") { $q.= "Description LIKE '%".mysql_escape_string($K)."%') "; } } - if (isset($_REQUEST["do_MyPackages"]) && $SID) { + if ($_REQUEST["do_MyPackages"] && $SID) { # list packages that the user is a AUR Maintainer of, or if it the # vistior is a registered user, if they are the Maintainer. # if ($myuid) { if (!$has_where) { $q.= "WHERE (AURMaintainerUID = ".$myuid." OR "; - $q.= "MaintainerUID = " . $myuid.") "; + $q.= "MaintainerUID = ".$myuid." OR SubmitterUID = ".$myuid.") "; $has_where = 1; } else { $q.= "AND (AURMaintainerUID = ".$myuid." OR "; - $q.= "MaintainerUID = " . $myuid.") "; + $q.= "MaintainerUID = ".$myuid." OR SubmitterUID = ".$myuid.") "; } } } @@ -394,10 +438,10 @@ function pkg_search_page($SID="") { break; } $q.= "LIMIT ".$O.", ".$PP; - #print $q."
\n"; - #print "
\n";
-	#print_r($_REQUEST);
-	#print "
\n"; + print $q."
\n"; + print "
\n";
+	print_r($_REQUEST);
+	print "
\n"; $result = db_query($q, $dbh); if (!$result) { @@ -502,41 +546,43 @@ function pkg_search_page($SID="") { print " "; print $cats[$row["CategoryID"]]."\n"; print " "; - $details_url = "".$row["Name"]; - $details_url.= "-".$row["Version"].""; - print $details_url."\n"; + reset($pkgsearch_vars); + $url.= "'>".$row["Name"]; + $url.= "-".$row["Version"].""; + print $url."\n"; print " "; print "   ".$row["NumVotes"]."\n"; print " "; print $row["Description"]."\n"; print " "; - $not_managed = 0; + + # print the package manager, also determine if it is managed + # + $managed = 1; if (isset($devs[$row["AURMaintainerUID"]])) { print $devs[$row["AURMaintainerUID"]]["Username"]; } elseif (isset($tus[$row["AURMaintainerUID"]])) { print $tus[$row["AURMaintainerUID"]]["Username"]; } else { print "None"; - $not_managed = 1; + $managed = 0; } print "\n"; - if ($myuid == $row["AURMaintainerUID"] || $not_managed || - ($myuid == $row["MaintainerUID"] && $not_managed)) { - # Only allow TUs/Devs to manage packages, or if it is a regular - # user and the package has not been adopted by a TU/Dev, then the - # regular user (most likely the submitter) can manage it. - # + + # print the managed link if applicable + # + if (canManagePackage($myuid, $row["AURMaintainerUID"], + $row["MaintainerUID"], $row["SubmitterUID"], $managed)) { $manage_url = "Manage"; print " "; @@ -553,6 +599,9 @@ function pkg_search_page($SID="") { print "\n"; print "\n"; print "\n"; + if ($_REQUEST["do_MyPackages"]) { + print "\n"; + } print "\n"; print "\n"; -- cgit v1.2.3-24-g4f1b