From d17e406ac61094a0ad6d433c8e24be9b8b140959 Mon Sep 17 00:00:00 2001 From: eric Date: Sat, 10 Jul 2004 20:51:56 +0000 Subject: pkgsearch is done (except for some serious debugging) --- web/html/index.php | 4 +- web/html/pkgsearch.php | 261 ++++++++++++++++++++++++++++++++++++++++++++--- web/lang/pkgfuncs_po.inc | 20 ++++ web/lang/search_po.inc | 70 +++++++++++++ web/lib/aur.inc | 1 + web/lib/pkgfuncs.inc | 86 +++++++++++++--- 6 files changed, 410 insertions(+), 32 deletions(-) diff --git a/web/html/index.php b/web/html/index.php index 64a1c2f..7b2213a 100644 --- a/web/html/index.php +++ b/web/html/index.php @@ -86,11 +86,11 @@ print " \n"; if (!isset($_COOKIE["AURSID"])) { # the user is not logged in, give them login widgets # - print "
\n"; if ($login_error) { print "" . $login_error . "
\n"; } print "\n"; + print "\n"; print "\n"; print ""; print ""; @@ -104,8 +104,8 @@ if (!isset($_COOKIE["AURSID"])) { print ""; print "\n"; - print "
".__("Username:")."
\n"; print "
\n"; + print "\n"; } else { print __("Logged-in as: %h%s%h", diff --git a/web/html/pkgsearch.php b/web/html/pkgsearch.php index 6524b51..546ed2b 100644 --- a/web/html/pkgsearch.php +++ b/web/html/pkgsearch.php @@ -6,11 +6,15 @@ set_lang(); # this sets up the visitor's language check_sid(); # see if they're still logged in html_header(); # print out the HTML header -# define variables used during pkgsearch +# enable debugging # -$pkgsearch_vars = array("O", "L", "C", "K", "SB", "PP", "do_MyPackages"); +$DBUG = 0; +if ($DBUG) { + print "
\n";
+	print_r($_REQUEST);
+	print "
\n"; +} - # get login privileges # if (isset($_COOKIE["AURSID"])) { @@ -24,6 +28,9 @@ if (isset($_COOKIE["AURSID"])) { # grab the list of Package IDs to be operated on # isset($_REQUEST["IDs"]) ? $ids = $_REQUEST["IDs"] : $ids = array(); +#isset($_REQUEST["All_IDs"]) ? +# $all_ids = explode(":", $_REQUEST["All_IDs"]) : +# $all_ids = array(); # determine what button the visitor clicked @@ -34,15 +41,75 @@ if (isset($_REQUEST["do_Flag"])) { print "
\n"; } else { - # Flag the packages in $ids array, and unflag any other - # packages listed in $_REQUEST["All_IDs"] - # - print "flagging
\n"; + + if (!empty($ids)) { + $dbh = db_connect(); + + # Flag the packages in $ids array + # + $first = 1; + while (list($pid, $v) = each($ids)) { + if ($first) { + $first = 0; + $flag = $pid; + } else { + $flag .= ", ".$pid; + } + } + $q = "UPDATE Packages SET OutOfDate = 1 "; + $q.= "WHERE ID IN (" . $flag . ")"; + db_query($q, $dbh); + + print "

\n"; + print __("The selected packages have been flagged out-of-date."); + print "

\n"; + } else { + print "

\n"; + print __("You did not select any packages to flag."); + print "

\n"; + } pkgsearch_results_link(); } +} elseif (isset($_REQUEST["do_UnFlag"])) { + if (!$atype) { + print __("You must be logged in before you can unflag packages."); + print "
\n"; + + } else { + + if (!empty($ids)) { + $dbh = db_connect(); + + # Un-Flag the packages in $ids array + # + $first = 1; + while (list($pid, $v) = each($ids)) { + if ($first) { + $first = 0; + $unflag = $pid; + } else { + $unflag .= ", ".$pid; + } + } + $q = "UPDATE Packages SET OutOfDate = 0 "; + $q.= "WHERE ID IN (" . $unflag . ")"; + db_query($q, $dbh); + + print "

\n"; + print __("The selected packages have been unflagged."); + print "

\n"; + } else { + print "

\n"; + print __("You did not select any packages to unflag."); + print "

\n"; + } + + pkgsearch_results_link(); + + } } elseif (isset($_REQUEST["do_Disown"])) { if (!$atype) { @@ -52,7 +119,45 @@ if (isset($_REQUEST["do_Flag"])) { } else { # Disown the packages in $ids array # - print "disowning
\n"; + if (!empty($ids)) { + $dbh = db_connect(); + + # Disown the packages in $ids array + # + $first = 1; + while (list($pid, $v) = each($ids)) { + if ($first) { + $first = 0; + $disown = $pid; + } else { + $disown .= ", ".$pid; + } + } + $atype = account_from_sid($_COOKIE["AURSID"]); + if ($atype == "Trusted User" || $atype == "Developer") { + $field = "AURMaintainerUID"; + } elseif ($atype == "User") { + $field = "MaintainerUID"; + } else { + $field = ""; + } + + if ($field) { + $q = "UPDATE Packages "; + $q.= "SET ".$field." = 0 "; + $q.= "WHERE ID IN (" . $disown . ") "; + $q.= "AND ".$field." = ".uid_from_sid($_COOKIE["AURSID"]); + db_query($q, $dbh); + } + + print "

\n"; + print __("The selected packages have been disowned."); + print "

\n"; + } else { + print "

\n"; + print __("You did not select any packages to disowned."); + print "

\n"; + } pkgsearch_results_link(); @@ -67,7 +172,45 @@ if (isset($_REQUEST["do_Flag"])) { } else { # Adopt the packages in $ids array # - print "adopting
\n"; + if (!empty($ids)) { + $dbh = db_connect(); + + # Adopt the packages in $ids array + # + $first = 1; + while (list($pid, $v) = each($ids)) { + if ($first) { + $first = 0; + $adopt = $pid; + } else { + $adopt .= ", ".$pid; + } + } + $atype = account_from_sid($_COOKIE["AURSID"]); + if ($atype == "Trusted User" || $atype == "Developer") { + $field = "AURMaintainerUID"; + } elseif ($atype == "User") { + $field = "MaintainerUID"; + } else { + $field = ""; + } + + if ($field) { + $q = "UPDATE Packages "; + $q.= "SET ".$field." = ".uid_from_sid($_COOKIE["AURSID"])." "; + $q.= "WHERE ID IN (" . $adopt . ") "; + $q.= "AND ".$field." = 0"; + db_query($q, $dbh); + } + + print "

\n"; + print __("The selected packages have been adopted."); + print "

\n"; + } else { + print "

\n"; + print __("You did not select any packages to adopt."); + print "

\n"; + } pkgsearch_results_link(); @@ -80,10 +223,102 @@ if (isset($_REQUEST["do_Flag"])) { print "
\n"; } else { - # vote on the packages in $ids array. 'unvote' for any packages - # listed in the $_REQUEST["All_IDs"] array. + # vote on the packages in $ids array. + # + if (!empty($ids)) { + $dbh = db_connect(); + $my_votes = pkgvotes_from_sid($_COOKIE["AURSID"]); + $uid = uid_from_sid($_COOKIE["AURSID"]); + # $vote_ids will contain the string of Package.IDs that + # the visitor hasn't voted for already + # + $first = 1; + while (list($pid, $v) = each($ids)) { + if (!isset($my_votes[$pid])) { + # cast a vote for this package + # + if ($first) { + $first = 0; + $vote_ids = $pid; + $vote_clauses = "(".$uid.", ".$pid.")"; + } else { + $vote_ids .= ", ".$pid; + $vote_clauses .= ", (".$uid.", ".$pid.")"; + } + } + } + # only vote for packages the user hasn't already voted for + # + $q = "UPDATE Packages SET NumVotes = NumVotes + 1 "; + $q.= "WHERE ID IN (".$vote_ids.")"; + db_query($q, $dbh); + + $q = "INSERT INTO PackageVotes (UsersID, PackageID) VALUES "; + $q.= $vote_clauses; + db_query($q, $dbh); + + print "

\n"; + print __("Your votes have been cast for the selected packages."); + print "

\n"; + + } else { + print "

\n"; + print __("You did not select any packages to vote for."); + print "

\n"; + } + + pkgsearch_results_link(); + + } + + +} elseif (isset($_REQUEST["do_UnVote"])) { + if (!$atype) { + print __("You must be logged in before you can un-vote for packages."); + print "
\n"; + + } else { + # un-vote on the packages in $ids array. # - print "voting
\n"; + if (!empty($ids)) { + $dbh = db_connect(); + $my_votes = pkgvotes_from_sid($_COOKIE["AURSID"]); + $uid = uid_from_sid($_COOKIE["AURSID"]); + # $unvote_ids will contain the string of Package.IDs that + # the visitor has voted for and wants to unvote. + # + $first = 1; + while (list($pid, $v) = each($ids)) { + if (isset($my_votes[$pid])) { + # cast a un-vote for this package + # + if ($first) { + $first = 0; + $unvote_ids = $pid; + } else { + $unvote_ids .= ", ".$pid; + } + } + } + # only un-vote for packages the user has already voted for + # + $q = "UPDATE Packages SET NumVotes = NumVotes - 1 "; + $q.= "WHERE ID IN (".$unvote_ids.")"; + db_query($q, $dbh); + + $q = "DELETE FROM PackageVotes WHERE UsersID = ".$uid." "; + $q.= "AND PackageID IN (".$unvote_ids.")"; + db_query($q, $dbh); + + print "

\n"; + print __("Your votes have been removed from the selected packages."); + print "

\n"; + + } else { + print "

\n"; + print __("You did not select any packages to un-vote for."); + print "

\n"; + } pkgsearch_results_link(); @@ -101,8 +336,6 @@ if (isset($_REQUEST["do_Flag"])) { print "
\n"; pkgsearch_results_link(); - print "\n"; - print "
\n"; } else { diff --git a/web/lang/pkgfuncs_po.inc b/web/lang/pkgfuncs_po.inc index 72a239b..054ad91 100644 --- a/web/lang/pkgfuncs_po.inc +++ b/web/lang/pkgfuncs_po.inc @@ -141,4 +141,24 @@ $_t["en"]["Manage"] = "Manage"; # $_t["fr"]["Manage"] = "--> Traduction française ici. <--"; # $_t["de"]["Manage"] = "--> Deutsche Übersetzung hier. <--"; +$_t["en"]["Un-flag Out-of-date"] = "Un-flag Out-of-date"; +# $_t["es"]["Un-flag Out-of-date"] = "--> Traducción española aquí. <--"; +# $_t["fr"]["Un-flag Out-of-date"] = "--> Traduction française ici. <--"; +# $_t["de"]["Un-flag Out-of-date"] = "--> Deutsche Übersetzung hier. <--"; + +$_t["en"]["Unflag Out-of-date"] = "Unflag Out-of-date"; +# $_t["es"]["Unflag Out-of-date"] = "--> Traducción española aquí. <--"; +# $_t["fr"]["Unflag Out-of-date"] = "--> Traduction française ici. <--"; +# $_t["de"]["Unflag Out-of-date"] = "--> Deutsche Übersetzung hier. <--"; + +$_t["en"]["Un-Vote"] = "Un-Vote"; +# $_t["es"]["Un-Vote"] = "--> Traducción española aquí. <--"; +# $_t["fr"]["Un-Vote"] = "--> Traduction française ici. <--"; +# $_t["de"]["Un-Vote"] = "--> Deutsche Übersetzung hier. <--"; + +$_t["en"]["Yes"] = "Yes"; +# $_t["es"]["Yes"] = "--> Traducción española aquí. <--"; +# $_t["fr"]["Yes"] = "--> Traduction française ici. <--"; +# $_t["de"]["Yes"] = "--> Deutsche Übersetzung hier. <--"; + ?> \ No newline at end of file diff --git a/web/lang/search_po.inc b/web/lang/search_po.inc index 6714b85..4e3c528 100644 --- a/web/lang/search_po.inc +++ b/web/lang/search_po.inc @@ -51,4 +51,74 @@ $_t["en"]["You must be logged in before you can adopt packages."] = "You must be # $_t["fr"]["You must be logged in before you can adopt packages."] = "--> Traduction française ici. <--"; # $_t["de"]["You must be logged in before you can adopt packages."] = "--> Deutsche Übersetzung hier. <--"; +$_t["en"]["The selected packages have been flagged out-of-date."] = "The selected packages have been flagged out-of-date."; +# $_t["es"]["The selected packages have been flagged out-of-date."] = "--> Traducción española aquí. <--"; +# $_t["fr"]["The selected packages have been flagged out-of-date."] = "--> Traduction française ici. <--"; +# $_t["de"]["The selected packages have been flagged out-of-date."] = "--> Deutsche Übersetzung hier. <--"; + +$_t["en"]["You did not select any packages to flag."] = "You did not select any packages to flag."; +# $_t["es"]["You did not select any packages to flag."] = "--> Traducción española aquí. <--"; +# $_t["fr"]["You did not select any packages to flag."] = "--> Traduction française ici. <--"; +# $_t["de"]["You did not select any packages to flag."] = "--> Deutsche Übersetzung hier. <--"; + +$_t["en"]["The selected packages have been unflagged."] = "The selected packages have been unflagged."; +# $_t["es"]["The selected packages have been unflagged."] = "--> Traducción española aquí. <--"; +# $_t["fr"]["The selected packages have been unflagged."] = "--> Traduction française ici. <--"; +# $_t["de"]["The selected packages have been unflagged."] = "--> Deutsche Übersetzung hier. <--"; + +$_t["en"]["You must be logged in before you can unflag packages."] = "You must be logged in before you can unflag packages."; +# $_t["es"]["You must be logged in before you can unflag packages."] = "--> Traducción española aquí. <--"; +# $_t["fr"]["You must be logged in before you can unflag packages."] = "--> Traduction française ici. <--"; +# $_t["de"]["You must be logged in before you can unflag packages."] = "--> Deutsche Übersetzung hier. <--"; + +$_t["en"]["You did not select any packages to unflag."] = "You did not select any packages to unflag."; +# $_t["es"]["You did not select any packages to unflag."] = "--> Traducción española aquí. <--"; +# $_t["fr"]["You did not select any packages to unflag."] = "--> Traduction française ici. <--"; +# $_t["de"]["You did not select any packages to unflag."] = "--> Deutsche Übersetzung hier. <--"; + +$_t["en"]["You did not select any packages to adopt."] = "You did not select any packages to adopt."; +# $_t["es"]["You did not select any packages to adopt."] = "--> Traducción española aquí. <--"; +# $_t["fr"]["You did not select any packages to adopt."] = "--> Traduction française ici. <--"; +# $_t["de"]["You did not select any packages to adopt."] = "--> Deutsche Übersetzung hier. <--"; + +$_t["en"]["You did not select any packages to disowned."] = "You did not select any packages to disowned."; +# $_t["es"]["You did not select any packages to disowned."] = "--> Traducción española aquí. <--"; +# $_t["fr"]["You did not select any packages to disowned."] = "--> Traduction française ici. <--"; +# $_t["de"]["You did not select any packages to disowned."] = "--> Deutsche Übersetzung hier. <--"; + +$_t["en"]["The selected packages have been adopted."] = "The selected packages have been adopted."; +# $_t["es"]["The selected packages have been adopted."] = "--> Traducción española aquí. <--"; +# $_t["fr"]["The selected packages have been adopted."] = "--> Traduction française ici. <--"; +# $_t["de"]["The selected packages have been adopted."] = "--> Deutsche Übersetzung hier. <--"; + +$_t["en"]["The selected packages have been disowned."] = "The selected packages have been disowned."; +# $_t["es"]["The selected packages have been disowned."] = "--> Traducción española aquí. <--"; +# $_t["fr"]["The selected packages have been disowned."] = "--> Traduction française ici. <--"; +# $_t["de"]["The selected packages have been disowned."] = "--> Deutsche Übersetzung hier. <--"; + +$_t["en"]["You must be logged in before you can un-vote for packages."] = "You must be logged in before you can un-vote for packages."; +# $_t["es"]["You must be logged in before you can un-vote for packages."] = "--> Traducción española aquí. <--"; +# $_t["fr"]["You must be logged in before you can un-vote for packages."] = "--> Traduction française ici. <--"; +# $_t["de"]["You must be logged in before you can un-vote for packages."] = "--> Deutsche Übersetzung hier. <--"; + +$_t["en"]["Your votes have been removed from the selected packages."] = "Your votes have been removed from the selected packages."; +# $_t["es"]["Your votes have been removed from the selected packages."] = "--> Traducción española aquí. <--"; +# $_t["fr"]["Your votes have been removed from the selected packages."] = "--> Traduction française ici. <--"; +# $_t["de"]["Your votes have been removed from the selected packages."] = "--> Deutsche Übersetzung hier. <--"; + +$_t["en"]["You did not select any packages to vote for."] = "You did not select any packages to vote for."; +# $_t["es"]["You did not select any packages to vote for."] = "--> Traducción española aquí. <--"; +# $_t["fr"]["You did not select any packages to vote for."] = "--> Traduction française ici. <--"; +# $_t["de"]["You did not select any packages to vote for."] = "--> Deutsche Übersetzung hier. <--"; + +$_t["en"]["You did not select any packages to un-vote for."] = "You did not select any packages to un-vote for."; +# $_t["es"]["You did not select any packages to un-vote for."] = "--> Traducción española aquí. <--"; +# $_t["fr"]["You did not select any packages to un-vote for."] = "--> Traduction française ici. <--"; +# $_t["de"]["You did not select any packages to un-vote for."] = "--> Deutsche Übersetzung hier. <--"; + +$_t["en"]["Your votes have been cast for the selected packages."] = "Your votes have been cast for the selected packages."; +# $_t["es"]["Your votes have been cast for the selected packages."] = "--> Traducción española aquí. <--"; +# $_t["fr"]["Your votes have been cast for the selected packages."] = "--> Traduction française ici. <--"; +# $_t["de"]["Your votes have been cast for the selected packages."] = "--> Deutsche Übersetzung hier. <--"; + ?> \ No newline at end of file diff --git a/web/lib/aur.inc b/web/lib/aur.inc index 26e538a..005c564 100644 --- a/web/lib/aur.inc +++ b/web/lib/aur.inc @@ -423,6 +423,7 @@ function html_header() { # function html_footer($ver="") { print "\n\n\n"; + print "
\n"; print " \n"; print " \n"; print "\n"; diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index ae30657..0b7a000 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -1,14 +1,20 @@ "; print __("Go back to %hsearch results%h.", array($url_data, "")); + print "\n
\n"; return; } @@ -113,9 +120,32 @@ function package_sources($pkgid=0) { return $sources; } + +# grab array of Package.IDs that I've voted for: $pkgs[1234] = 1, ... +# +function pkgvotes_from_sid($sid="") { + $pkgs = array(); + if (!$sid) {return $pkgs;} + $dbh = db_connect(); + $q = "SELECT PackageID "; + $q.= "FROM PackageVotes, Users, Sessions "; + $q.= "WHERE Users.ID = Sessions.UsersID "; + $q.= "AND Users.ID = PackageVotes.UsersID "; + $q.= "AND Sessions.SessionID = '".mysql_escape_string($sid)."'"; + $result = db_query($q, $dbh); + if ($result) { + while ($row = mysql_fetch_row($result)) { + $pkgs[$row[0]] = 1; + } + } + return $pkgs; +} + + # display package details # function package_details($id=0) { + global $_REQUEST; global $pkgsearch_vars; $q = "SELECT *,Location,Category "; $q.= "FROM Packages,PackageLocations,PackageCategories "; @@ -190,7 +220,11 @@ function package_details($id=0) { while (list($k, $darr) = each($deps)) { $url = "".$darr[1]."
\n"; @@ -252,12 +286,13 @@ function pkg_search_page($SID="") { if ($O < 0) { $O = 0; } - if ($_REQUEST["do_Search"]) { - # reset the offset to zero if they hit Go/My Packages + if ($_REQUEST["do_Search"] && $_REQUEST["do_Search"] != 1) { + # reset the offset to zero if they hit Go # $_REQUEST["do_MyPackages"] = 0; $O = 0; } + $_REQUEST["O"] = $O; # so that pkg_search_results() works # grab info for user if they're logged in @@ -265,6 +300,7 @@ function pkg_search_page($SID="") { if ($SID) { $myuid = uid_from_sid($SID); $acct = account_from_sid($SID); + $my_votes = pkgvotes_from_sid($SID); } # The search form @@ -438,10 +474,6 @@ function pkg_search_page($SID="") { break; } $q.= "LIMIT ".$O.", ".$PP; - print $q."
\n"; - print "
\n";
-	print_r($_REQUEST);
-	print "
\n"; $result = db_query($q, $dbh); if (!$result) { @@ -470,6 +502,9 @@ function pkg_search_page($SID="") { print "\n"; print " "; + print "\n"; + print " "; print "\n"; print " "; @@ -478,6 +513,9 @@ function pkg_search_page($SID="") { print " "; print "\n"; + print " "; + print "\n"; print "\n"; print "\n"; print " \n"; @@ -512,6 +550,10 @@ function pkg_search_page($SID="") { print " bottom'>".__("Name")."\n"; print " ".__("Votes")."\n"; + if ($SID) { + print " ".__("Vote")."\n"; + } print " ".__("Description")."\n"; print " "; } - print ""; - if ($i == 0) { - $all_ids = $row["ID"]; - } else { - $all_ids .= ":".$row["ID"]; - } + print ""; +# if ($i == 0) { +# $all_ids = $row["ID"]; +# } else { +# $all_ids .= ":".$row["ID"]; +# } if ($row["OutOfDate"]) { print ""; } @@ -554,7 +596,11 @@ function pkg_search_page($SID="") { # php.net recommends htmlentities(urlencode(data)), but that # doesn't work! # - $url .= "&".$var."=".rawurlencode(stripslashes($_REQUEST[$var])); + if ($var == "do_MyPackages" && $_REQUEST[$var]) { + $url .= "&".$var."=1"; + } else { + $url .= "&".$var."=".rawurlencode(stripslashes($_REQUEST[$var])); + } } reset($pkgsearch_vars); $url.= "'>".$row["Name"]; @@ -562,6 +608,14 @@ function pkg_search_page($SID="") { print $url."\n"; print " "; print "   ".$row["NumVotes"]."\n"; + if ($SID) { + print " "; + if (isset($my_votes[$row["ID"]])) { + print "  ".__("Yes")."\n"; + } else { + print " \n"; + } + } print " "; print $row["Description"]."\n"; print " "; @@ -598,7 +652,7 @@ function pkg_search_page($SID="") { print " \n"; print "\n"; print "\n"; - print "\n"; +# print "\n"; if ($_REQUEST["do_MyPackages"]) { print "\n"; } -- cgit v1.2.3-54-g00ecf