Add notify column in search results and notify button

Adds a column to search results showing if a package has comment
notification enabled and adds support for toggling notify for
multiple packages from search

Signed-off-by: Callan Barrett <wizzomafizzo@gmail.com>
This commit is contained in:
Callan Barrett 2008-01-07 09:44:21 +09:00 committed by Dan McGee
parent bf5c28cf22
commit 8c94552042
5 changed files with 65 additions and 40 deletions

View file

@ -509,41 +509,33 @@ if (isset($_REQUEST["do_Flag"])) {
# There currently shouldn't be multiple requests here, but the format in which # There currently shouldn't be multiple requests here, but the format in which
# it's sent requires this # it's sent requires this
while (list($pid, $v) = each($ids)) { while (list($pid, $v) = each($ids)) {
$q = "SELECT Name FROM Packages WHERE ID = " . $pid;
$pkgname = mysql_result(db_query($q, $dbh), 0);
$q = "SELECT * FROM CommentNotify WHERE UserID = ".$uid;
$q.= " AND PkgID = ".$pid;
if (!mysql_num_rows(db_query($q, $dbh))) {
$q = "INSERT INTO CommentNotify (PkgID, UserID) VALUES (".$pid.', '.$uid.')'; $q = "INSERT INTO CommentNotify (PkgID, UserID) VALUES (".$pid.', '.$uid.')';
db_query($q, $dbh); db_query($q, $dbh);
print '<p>'; print '<p>';
print __("You have been added to the comment notification list."); print __("You have been added to the comment notification list for %s.",
array("<b>" . $pkgname . "</b>"));
print '<br /></p>'; print '<br /></p>';
pkgdetails_link($pid);
}
} else { } else {
print '<p>';
print __("Couldn't add to notification list.");
print '<br /></p>';
}
}
} elseif (isset($_REQUEST["do_UnNotify"])) {
if (!$atype) {
print __("You must be logged in before you can cancel notification on comments.");
print "<br />\n";
} else {
if (!empty($ids)) {
$dbh = db_connect();
$uid = uid_from_sid($_COOKIE["AURSID"]);
# There currently shouldn't be multiple requests here, but the format in which
# it's sent requires this
while (list($pid, $v) = each($ids)) {
$q = "DELETE FROM CommentNotify WHERE PkgID = ".$pid; $q = "DELETE FROM CommentNotify WHERE PkgID = ".$pid;
$q.= " AND UserID = ".$uid; $q.= " AND UserID = ".$uid;
db_query($q, $dbh); db_query($q, $dbh);
print '<p>'; print '<p>';
print __("You have been removed from the comment notification list."); print __("You have been removed from the comment notification list for %s.",
array("<b>" . $pkgname . "</b>"));
print '<br /></p>'; print '<br /></p>';
pkgdetails_link($pid);
} }
}
pkgdetails_link($pid);
} else { } else {
print '<p>'; print '<p>';
print __("Couldn't remove from notification list."); print __("Couldn't add to notification list.");
print '<br /></p>'; print '<br /></p>';
} }
} }

View file

@ -157,4 +157,6 @@ $_t["en"]["The above files have been verified (by %h%s%h) and are safe to use."]
$_t["en"]["This package has been flagged out of date."] = "This package has been flagged out of date."; $_t["en"]["This package has been flagged out of date."] = "This package has been flagged out of date.";
$_t["en"]["Toggle Notify"] = "Toggle Notify";
?> ?>

View file

@ -39,7 +39,7 @@ $_t["en"]["Error trying to retrieve package details."] = "Error trying to retrie
$_t["en"]["The selected packages have been adopted."] = "The selected packages have been adopted."; $_t["en"]["The selected packages have been adopted."] = "The selected packages have been adopted.";
$_t["en"]["You have been removed from the comment notification list."] = "You have been removed from the comment notification list."; $_t["en"]["You have been removed from the comment notification list for %s."] = "You have been removed from the comment notification listfor %s.";
$_t["en"]["Your votes have been cast for the selected packages."] = "Your votes have been cast for the selected packages."; $_t["en"]["Your votes have been cast for the selected packages."] = "Your votes have been cast for the selected packages.";
@ -47,7 +47,7 @@ $_t["en"]["You must be logged in before you can cancel notification on comments.
$_t["en"]["You must be logged in before you can adopt packages."] = "You must be logged in before you can adopt packages."; $_t["en"]["You must be logged in before you can adopt packages."] = "You must be logged in before you can adopt packages.";
$_t["en"]["You have been added to the comment notification list."] = "You have been added to the comment notification list."; $_t["en"]["You have been added to the comment notification list for %s."] = "You have been added to the comment notification list for %s.";
$_t["en"]["You did not select any packages to disown."] = "You did not select any packages to disown."; $_t["en"]["You did not select any packages to disown."] = "You did not select any packages to disown.";

View file

@ -108,7 +108,7 @@ class AurJSON {
private function info($pqdata) { private function info($pqdata) {
$base_query = "SELECT ID,Name,Version,Description,URL,URLPath,License,NumVotes,OutOfDate FROM Packages WHERE "; $base_query = "SELECT ID,Name,Version,Description,URL,URLPath,License,NumVotes,OutOfDate FROM Packages WHERE ";
if is_numeric($pqdata) { if ( is_numeric($pqdata) ) {
// just using sprintf to coerce the pqd to an int // just using sprintf to coerce the pqd to an int
// should handle sql injection issues, since sprintf will // should handle sql injection issues, since sprintf will
// bork if not an int, or convert the string to a number 0 // bork if not an int, or convert the string to a number 0

View file

@ -265,6 +265,26 @@ function pkgvotes_from_sid($sid="") {
return $pkgs; return $pkgs;
} }
# array of package ids that you're being notified for
# *yoink*
#
function pkgnotify_from_sid($sid="") {
$pkgs = array();
if (!$sid) {return $pkgs;}
$dbh = db_connect();
$q = "SELECT PkgID ";
$q.= "FROM CommentNotify, Users, Sessions ";
$q.= "WHERE Users.ID = Sessions.UsersID ";
$q.= "AND Users.ID = CommentNotify.UserID ";
$q.= "AND Sessions.SessionID = '".mysql_real_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 # display package details
# #
@ -475,7 +495,7 @@ function package_details($id=0, $SID="") {
echo "<input type='submit' class='button' name='do_Notify'"; echo "<input type='submit' class='button' name='do_Notify'";
echo " value='".__("Notify")."' title='".__("New Comment Notification")."'>"; echo " value='".__("Notify")."' title='".__("New Comment Notification")."'>";
} else { } else {
echo "<input type='submit' class='button' name='do_UnNotify'"; echo "<input type='submit' class='button' name='do_Notify'";
echo " value='".__("UnNotify")."' title='".__("No New Comment Notification")."'>"; echo " value='".__("UnNotify")."' title='".__("No New Comment Notification")."'>";
} }
@ -636,6 +656,7 @@ function pkg_search_page($SID="") {
$myuid = uid_from_sid($SID); $myuid = uid_from_sid($SID);
$acct = account_from_sid($SID); $acct = account_from_sid($SID);
$my_votes = pkgvotes_from_sid($SID); $my_votes = pkgvotes_from_sid($SID);
$my_notify = pkgnotify_from_sid($SID);
} }
# The search form # The search form
@ -964,11 +985,9 @@ function pkg_search_page($SID="") {
print "<input type='submit' class='button' name='do_Delete'"; print "<input type='submit' class='button' name='do_Delete'";
print " value='".__("Delete Packages")."'></td>\n"; print " value='".__("Delete Packages")."'></td>\n";
print " <td align='center'>"; print " <td align='center'>";
print "<input type='submit' class='button' name='do_Vote'"; print "<input type='submit' class='button' name='do_Notify'";
print " value='".__("Vote")."'></td>\n"; print " value='".__("Toggle Notify")."'></td>\n";
print " <td align='center'>"; print " <td align='center'>";
print "<input type='submit' class='button' name='do_UnVote'";
print " value='".__("Un-Vote")."'></td>\n";
print "</tr>\n"; print "</tr>\n";
print "</table>\n"; print "</table>\n";
print " </td>\n"; print " </td>\n";
@ -1023,6 +1042,10 @@ function pkg_search_page($SID="") {
print " <th style='border-bottom: #666 1px solid; vertical-align:"; print " <th style='border-bottom: #666 1px solid; vertical-align:";
print " bottom'><span class='f2'>".__("Voted")."</span></th>\n"; print " bottom'><span class='f2'>".__("Voted")."</span></th>\n";
} }
if ($SID) {
print " <th style='border-bottom: #666 1px solid; vertical-align:";
print " bottom'><span class='f2'>".__("Notify")."</span></th>\n";
}
print " <th style='border-bottom: #666 1px solid; vertical-align:"; print " <th style='border-bottom: #666 1px solid; vertical-align:";
print " bottom'><span class='f2'>".__("Description")."</a>"; print " bottom'><span class='f2'>".__("Description")."</a>";
print "</span></th>\n"; print "</span></th>\n";
@ -1091,6 +1114,14 @@ function pkg_search_page($SID="") {
print "&nbsp;</span></td>\n"; print "&nbsp;</span></td>\n";
} }
} }
if ($SID) {
print " <td class='".$c."'><span class='f5'><span class='blue'>";
if (isset($my_notify[$row["ID"]])) {
print "&nbsp;&nbsp;".__("Yes")."</span></td>\n";
} else {
print "&nbsp;</span></td>\n";
}
}
print " <td class='".$c."'><span class='f4'><span class='blue'>"; print " <td class='".$c."'><span class='f4'><span class='blue'>";
print $row["Description"]."</span></span></td>\n"; print $row["Description"]."</span></span></td>\n";
print " <td class='".$c."'><span class='f5'><span class='blue'>"; print " <td class='".$c."'><span class='f5'><span class='blue'>";