From 6adf639a341b8954e911fce2d2bd3e7443a1426c Mon Sep 17 00:00:00 2001 From: simo Date: Wed, 8 Jun 2005 01:07:55 +0000 Subject: 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. --- web/html/packages.php | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ web/html/pkgedit.php | 24 ++++++++++++++++++++++ 2 files changed, 81 insertions(+) (limited to 'web/html') diff --git a/web/html/packages.php b/web/html/packages.php index 4ea4b012..791837f4 100644 --- a/web/html/packages.php +++ b/web/html/packages.php @@ -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 "
\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 '

'; + print __("You have been added to the comment notification list."); + print '

'; + pkgdetails_link($pid); + } + } else { + print '

'; + print __("Couldn't add to notification list."); + print '

'; + } + } +} elseif (isset($_REQUEST["do_UnNotify"])) { + if (!$atype) { + print __("You must be logged in before you can cancel notification on comments."); + print "
\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 '

'; + print __("You have been removed from the comment notification list."); + print '

'; + pkgdetails_link($pid); + } + } else { + print '

'; + print __("Couldn't remove from notification list."); + print '

'; + } + } } else { # do_More/do_Less/do_Search/do_MyPackages - just do a search # diff --git a/web/html/pkgedit.php b/web/html/pkgedit.php index 6a3f9ffd..ae0170bd 100644 --- a/web/html/pkgedit.php +++ b/web/html/pkgedit.php @@ -76,6 +76,30 @@ if ($_REQUEST["add_Comment"]) { print __("Comment has been added.")."
 
\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 # -- cgit v1.2.3-24-g4f1b