Commit 6adf639a authored by simo's avatar simo
Browse files

SQL CHANGES: New table CommentNotify with fields:

	PkgID
	UserID
This implements emailing comment notifications, including a user option to
enable/disable it on the package page. It uses php's mail() function to do
it and sends to everyone on the notify list as BCC.

This needs some more testing before public consumption.
parent 9c004010
......@@ -198,3 +198,12 @@ CREATE TABLE PackageComments (
FOREIGN KEY (PackageID) REFERENCES Packages(ID) ON DELETE CASCADE
);
-- Comment addition notifications
--
CREATE TABLE CommentNotify (
PkgID INTEGER UNSIGNED NOT NULL,
UserID INTEGER UNSIGNED NOT NULL,
FOREIGN KEY (PkgID) REFERENCES Packages(ID) ON DELETE CASCADE,
FOREIGN KEY (UserID) REFERENCES Users(ID) ON DELETE CASCADE
);
......@@ -243,6 +243,10 @@ if (isset($_REQUEST["do_Flag"])) {
$q = "DELETE FROM Packages WHERE ID = " . $id;
$result = db_query($q, $dbh);
# 7) delete from CommentNotify
$q = "DELETE FROM CommentNotify WHERE ID = " . $id;
$result = db_query($q, $dbh);
# TODO question: Now that the package as been deleted, does
# the unsupported repo need to be regenerated?
# ANSWER: No, there is no actual repo for unsupported, so no worries! (PJM)
......@@ -458,6 +462,59 @@ if (isset($_REQUEST["do_Flag"])) {
pkgsearch_results_link();
} elseif (isset($_REQUEST["do_Notify"])) {
# I realize that the implementation here seems a bit convoluted, but we want to
# ensure that everything happens as it should, even if someone called this page
# without having clicked a button somewhere (naughty naughty). This also leaves
# room to someday expand and allow to add oneself to multiple lists at once. -SL
if (!$atype) {
print __("You must be logged in before you can get notifications 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 = "INSERT INTO CommentNotify (PkgID, UserID) VALUES (".$pid.', '.$uid.')';
db_query($q, $dbh);
print '<p>';
print __("You have been added to the comment notification list.");
print '<br /></p>';
pkgdetails_link($pid);
}
} 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.= " AND UserID = ".$uid;
db_query($q, $dbh);
print '<p>';
print __("You have been removed from the comment notification list.");
print '<br /></p>';
pkgdetails_link($pid);
}
} else {
print '<p>';
print __("Couldn't remove from notification list.");
print '<br /></p>';
}
}
} else {
# do_More/do_Less/do_Search/do_MyPackages - just do a search
#
......
......@@ -76,6 +76,30 @@ if ($_REQUEST["add_Comment"]) {
print __("Comment has been added.")."<br />&nbsp;<br />\n";
pkgdetails_link($_REQUEST["ID"]);
# Send email notifications
#
$q = "SELECT CommentNotify.*, Users.Email ";
$q.= "FROM CommentNotify, Users ";
$q.= "WHERE Users.ID = CommentNotify.UserID ";
$q.= "AND CommentNotify.PkgID = ".intval($_REQUEST["ID"]);
$result = db_query($q, $dbh);
$bcc = array();
if (mysql_num_rows($result)) {
while ($row = mysql_fetch_assoc($result)) {
array_push($bcc, $row['Email']);
}
$q = "SELECT Packages.Name ";
$q.= "FROM Packages ";
$q.= "WHERE Packages.ID = ".intval($_REQUEST["ID"]);
$result = db_query($q, $dbh);
$row = mysql_fetch_assoc($result);
$body = __("A comment has been added to %s, you may view it at:\nhttp://aur.archlinux.org/packages.php?do_Details=1&ID=%s\n\nYou recieved this e-mail because you chose to recieve notifications of new comments on this package, if you no longer wish to recieve notifications about this package, please go the the above package page and click the appropriate control.",array($row['Name'],$_REQUEST["ID"]));
$body = wordwrap($body, 70);
$bcc = implode(', ', $bcc);
$headers = "Bcc: $bcc\nReply-to: nobody@archlinux.org\nFrom:aur-notify@archlinux.org\nX-Mailer: PHP\nX-MimeOLE: Produced By AUR\n";
@mail(' ', __("AUR Comment Notification for %s",array($row['Name'])), $body, $headers);
}
} else {
# Prompt visitor for comment
#
......
......@@ -327,4 +327,4 @@ $_t["en"]["You do not have permission to edit this account."] = "You do not have
$_t["de"]["You do not have permission to edit this account."] = "Zugriff für das Bearbeiten dieses Benutzerkontos verweigert.";
$_t["pl"]["You do not have permission to edit this account."] = "Nie masz uprawnień do edycji tego konta.";
?>
?>
\ No newline at end of file
......@@ -233,4 +233,4 @@ $_t["en"]["A Trusted User cannot assign Developer status."] = "A Trusted User ca
# $_t["de"]["A Trusted User cannot assign Developer status."] = "--> Deutsche Übersetzung hier. <--";
$_t["pl"]["A Trusted User cannot assign Developer status."] = "Zaufany użytkownik nie może nadać statusu developera.";
?>
?>
\ No newline at end of file
......@@ -89,4 +89,4 @@ $_t["en"]["Developer"] = "Developer";
$_t["de"]["Developer"] = "Entwickler";
$_t["pl"]["Developer"] = "Developer";
?>
?>
\ No newline at end of file
......@@ -77,4 +77,4 @@ $_t["en"]["Username"] = "Username";
$_t["de"]["Username"] = "Benutzername";
$_t["pl"]["Username"] = "Użytkownik";
?>
?>
\ No newline at end of file
......@@ -23,4 +23,4 @@ $_t["en"]["If this problem persists, please contact the site administrator."] =
# $_t["de"]["If this problem persists, please contact the site administrator."] = "--> Deutsche Übersetzung hier. <--";
$_t["pl"]["If this problem persists, please contact the site administrator."] = "Jeżeli ten problem się powtarza, skontaktuj się z administratorem strony.";
?>
?>
\ No newline at end of file
......@@ -155,4 +155,4 @@ $_t["en"]["Though we can't vouch for their contents, we provide a %hlist of user
# $_t["de"]["Though we can't vouch for their contents, we provide a %hlist of user repositories%h for your convenience."] = "--> Deutsche Übersetzung hier. <--";
$_t["pl"]["Though we can't vouch for their contents, we provide a %hlist of user repositories%h for your convenience."] = "Dla Twojej wygody podajemy %hlistę repozytoriów użytkowników%h, ale uwaga - nie odpowiadamy za ich zawartość.";
?>
?>
\ No newline at end of file
......@@ -23,4 +23,4 @@ $_t["en"]["You have been successfully logged out."] = "You have been successfull
# $_t["de"]["You have been successfully logged out."] = "--> Deutsche Übersetzung hier. <--";
$_t["pl"]["You have been successfully logged out."] = "Zostałeś pomyślnie wylogowany.";
?>
?>
\ No newline at end of file
......@@ -89,4 +89,14 @@ $_t["en"]["You've found a bug if you see this...."] = "You've found a bug if you
# $_t["de"]["Category"] = "--> Deutsche Übersetzung hier. <--";
$_t["pl"]["You've found a bug if you see this...."] = "Jeżeli to widzisz, to znalazłeś błąd...";
?>
$_t["en"]["A comment has been added to %s, you may view it at:\nhttp://aur.archlinux.org/packages.php?do_Details=1&ID=%s\n\nYou recieved this e-mail because you chose to recieve notifications of new comments on this package, if you no longer wish to recieve notifications about this package, please go the the above package page and click the appropriate control."] = "A comment has been added to %s, you may view it at:\nhttp://aur.archlinux.org/packages.php?do_Details=1&ID=%s\n\nYou recieved this e-mail because you chose to have recieve notifications of new comments on this package, if you no longer wish to recieve notifications about this package, please go the the above package page and click the appropriate control.";
# $_t["es"]["A comment has been added to %s, you may view it at:\nhttp://aur.archlinux.org/packages.php?do_Details=1&ID=%s\n\nYou recieved this e-mail because you chose to have recieve notifications of new comments on this package, if you no longer wish to recieve notifications about this package, please go the the above package page and click the appropriate control."] = "--> Traduccin espaola aqu. <--";
# $_t["fr"]["A comment has been added to %s, you may view it at:\nhttp://aur.archlinux.org/packages.php?do_Details=1&ID=%s\n\nYou recieved this e-mail because you chose to have recieve notifications of new comments on this package, if you no longer wish to recieve notifications about this package, please go the the above package page and click the appropriate control."] = "--> Traduction franaise ici. <--";
# $_t["de"]["A comment has been added to %s, you may view it at:\nhttp://aur.archlinux.org/packages.php?do_Details=1&ID=%s\n\nYou recieved this e-mail because you chose to have recieve notifications of new comments on this package, if you no longer wish to recieve notifications about this package, please go the the above package page and click the appropriate control."] = "--> Deutsche bersetzung hier. <--";
$_t["en"]["AUR Comment Notification for %s"] = "AUR Comment Notification for %s";
# $_t["es"]["AUR Comment Notification for %s"] = "--> Traduccin espaola aqu. <--";
# $_t["fr"]["AUR Comment Notification for %s"] = "--> Traduction franaise ici. <--";
# $_t["de"]["AUR Comment Notification for %s"] = "--> Deutsche bersetzung hier. <--";
?>
\ No newline at end of file
......@@ -308,4 +308,14 @@ $_t["en"]["Package Listing"] = "Package Listing";
# $_t["de"]["Package Listing"] = "--> Deutsche Übersetzung hier. <--";
$_t["pl"]["Package Listing"] = "Lista pakietów";
?>
$_t["en"]["UnNotify"] = "UnNotify";
# $_t["es"]["UnNotify"] = "--> Traduccin espaola aqu. <--";
# $_t["fr"]["UnNotify"] = "--> Traduction franaise ici. <--";
# $_t["de"]["UnNotify"] = "--> Deutsche bersetzung hier. <--";
$_t["en"]["Notify"] = "Notify";
# $_t["es"]["Notify"] = "--> Traduccin espaola aqu. <--";
# $_t["fr"]["Notify"] = "--> Traduction franaise ici. <--";
# $_t["de"]["Notify"] = "--> Deutsche bersetzung hier. <--";
?>
\ No newline at end of file
......@@ -143,4 +143,54 @@ $_t["en"]["Your votes have been cast for the selected packages."] = "Your votes
# $_t["de"]["Your votes have been cast for the selected packages."] = "--> Deutsche Übersetzung hier. <--";
$_t["pl"]["Your votes have been cast for the selected packages."] = "Twoje głosy zostały przyznane wybranym pakietom.";
?>
$_t["en"]["None of the selected packages could be deleted."] = "None of the selected packages could be deleted.";
# $_t["es"]["None of the selected packages could be deleted."] = "--> Traduccin espaola aqu. <--";
# $_t["fr"]["None of the selected packages could be deleted."] = "--> Traduction franaise ici. <--";
# $_t["de"]["None of the selected packages could be deleted."] = "--> Deutsche bersetzung hier. <--";
$_t["en"]["You must be logged in before you can get notifications on comments."] = "You must be logged in before you can get notifications on comments.";
# $_t["es"]["You must be logged in before you can get notifications on comments."] = "--> Traduccin espaola aqu. <--";
# $_t["fr"]["You must be logged in before you can get notifications on comments."] = "--> Traduction franaise ici. <--";
# $_t["de"]["You must be logged in before you can get notifications on comments."] = "--> Deutsche bersetzung hier. <--";
$_t["en"]["The selected packages have been deleted."] = "The selected packages have been deleted.";
# $_t["es"]["The selected packages have been deleted."] = "--> Traduccin espaola aqu. <--";
# $_t["fr"]["The selected packages have been deleted."] = "--> Traduction franaise ici. <--";
# $_t["de"]["The selected packages have been deleted."] = "--> Deutsche bersetzung hier. <--";
$_t["en"]["You have been removed from the comment notification list."] = "You have been removed from the comment notification list.";
# $_t["es"]["You have been removed from the comment notification list."] = "--> Traduccin espaola aqu. <--";
# $_t["fr"]["You have been removed from the comment notification list."] = "--> Traduction franaise ici. <--";
# $_t["de"]["You have been removed from the comment notification list."] = "--> Deutsche bersetzung hier. <--";
$_t["en"]["You must be logged in before you can cancel notification on comments."] = "You must be logged in before you can cancel notification on comments.";
# $_t["es"]["You must be logged in before you can cancel notification on comments."] = "--> Traduccin espaola aqu. <--";
# $_t["fr"]["You must be logged in before you can cancel notification on comments."] = "--> Traduction franaise ici. <--";
# $_t["de"]["You must be logged in before you can cancel notification on comments."] = "--> Deutsche bersetzung hier. <--";
$_t["en"]["You have been added to the comment notification list."] = "You have been added to the comment notification list.";
# $_t["es"]["You have been added to the comment notification list."] = "--> Traduccin espaola aqu. <--";
# $_t["fr"]["You have been added to the comment notification list."] = "--> Traduction franaise ici. <--";
# $_t["de"]["You have been added to the comment notification list."] = "--> Deutsche bersetzung hier. <--";
$_t["en"]["You did not select any packages to disown."] = "You did not select any packages to disown.";
# $_t["es"]["You did not select any packages to disown."] = "--> Traduccin espaola aqu. <--";
# $_t["fr"]["You did not select any packages to disown."] = "--> Traduction franaise ici. <--";
# $_t["de"]["You did not select any packages to disown."] = "--> Deutsche bersetzung hier. <--";
$_t["en"]["You did not select any packages to delete."] = "You did not select any packages to delete.";
# $_t["es"]["You did not select any packages to delete."] = "--> Traduccin espaola aqu. <--";
# $_t["fr"]["You did not select any packages to delete."] = "--> Traduction franaise ici. <--";
# $_t["de"]["You did not select any packages to delete."] = "--> Deutsche bersetzung hier. <--";
$_t["en"]["Couldn't add to notification list."] = "Couldn't add to notification list.";
# $_t["es"]["Couldn't add to notification list."] = "--> Traduccin espaola aqu. <--";
# $_t["fr"]["Couldn't add to notification list."] = "--> Traduction franaise ici. <--";
# $_t["de"]["Couldn't add to notification list."] = "--> Deutsche bersetzung hier. <--";
$_t["en"]["Couldn't remove from notification list."] = "Couldn't remove from notification list.";
# $_t["es"]["Couldn't remove from notification list."] = "--> Traduccin espaola aqu. <--";
# $_t["fr"]["Couldn't remove from notification list."] = "--> Traduction franaise ici. <--";
# $_t["de"]["Couldn't remove from notification list."] = "--> Deutsche bersetzung hier. <--";
?>
\ No newline at end of file
......@@ -244,4 +244,4 @@ $_t["en"]["Error - No file uploaded"] = "Error - No file uploaded";
# $_t["fr"]["Package upload successful"] = "--> Traduction française ici. <--";
# $_t["de"]["Package upload successful"] = "--> Deutsche Übersetzung hier. <--";
?>
?>
\ No newline at end of file
......@@ -17,4 +17,4 @@ $_t["en"]["Hi, this is worth reading!"] = "Hi, this is worth reading!";
# $_t["de"]["Hi, this is worth reading!"] = "--> Deutsche Übersetzung hier. <--";
$_t["pl"]["Hi, this is worth reading!"] = "Witaj, warto to przeczytać!";
?>
?>
\ No newline at end of file
......@@ -35,4 +35,4 @@ $_t["fr"]["My current language tag is: '%s'."] = "Ma étiquette de langue couran
$_t["de"]["My current language tag is: '%s'."] = "Meine gegenwärtige Sprachflagge ist: '%s'.";
$_t["pl"]["My current language tag is: '%s'."] = "Etykieta mojego obecnego języka to: '%s'.";
?>
?>
\ No newline at end of file
......@@ -23,4 +23,4 @@ $_t["en"]["Your session has timed out. You must log in again."] = "Your session
# $_t["de"]["Your session has timed out. You must log in again."] = "--> Deutsche Übersetzung hier. <--";
$_t["pl"]["Your session has timed out. You must log in again."] = "Twoja sesja wygasła. Musisz zalogować się ponownie.";
?>
?>
\ No newline at end of file
......@@ -434,6 +434,8 @@ function package_details($id=0, $SID="") {
print "<td><form action='/packages.php' method='post'>\n";
print "<input type='hidden' name='IDs[".$row["ID"]."]' value='1'>\n";
print "<input type='hidden' name='ID' value='".$row["ID"]."'>\n";
# Voting Button
#
$q = "SELECT * FROM PackageVotes WHERE UsersID = ".uid_from_sid($SID);
$q.= " AND PackageID = ".$row["ID"];
if (!mysql_num_rows(db_query($q, $dbh))) {
......@@ -443,7 +445,18 @@ function package_details($id=0, $SID="") {
print "<input type='submit' class='button' name='do_UnVote'";
print " value='".__("Un-Vote")."'>";
}
print "</form></td>\n";
# Comment Nofify Button
#
$q = "SELECT * FROM CommentNotify WHERE UserID = ".uid_from_sid($SID);
$q.= " AND PkgID = ".$row["ID"];
if (!mysql_num_rows(db_query($q, $dbh))) {
print "<input type='submit' class='button' name='do_Notify'";
print " value='".__("Notify")."'>";
} else {
print "<input type='submit' class='button' name='do_UnNotify'";
print " value='".__("UnNotify")."'>";
}
print "</form></td>\n";
}
print "</tr>\n";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment