summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoui Chang <louipc.ist@gmail.com>2009-01-25 13:17:54 -0500
committerLoui Chang <louipc.ist@gmail.com>2009-01-25 13:17:54 -0500
commit354c86b6c608c8923d0a087285f97d5d8121ed08 (patch)
tree2815243ed6596ca75a849e0191ef52712132d1ea
parentf729eca80dbbce94ce02a5315794145fb8cd9bf7 (diff)
downloadaurweb-354c86b6c608c8923d0a087285f97d5d8121ed08.tar.xz
Move package comment form into a new template.
Feature the form on the package details page. Signed-off-by: Loui Chang <louipc.ist@gmail.com>
-rw-r--r--web/html/pkgedit.php67
-rw-r--r--web/lib/pkgfuncs.inc17
-rw-r--r--web/template/actions_form.php6
-rw-r--r--web/template/pkg_comment_form.php68
4 files changed, 78 insertions, 80 deletions
diff --git a/web/html/pkgedit.php b/web/html/pkgedit.php
index 5907d2c..3b1c825 100644
--- a/web/html/pkgedit.php
+++ b/web/html/pkgedit.php
@@ -53,73 +53,6 @@ if ($_REQUEST["del_Comment"]) {
exit();
}
-# Add a comment to this package
-#
-if ($_REQUEST["add_Comment"]) {
- if ($_REQUEST["comment"]) {
- # Insert the comment
- #
- $dbh = db_connect();
- $q = "INSERT INTO PackageComments ";
- $q.= "(PackageID, UsersID, Comments, CommentTS) VALUES (";
- $q.= intval($_REQUEST["ID"]).", ".uid_from_sid($_COOKIE["AURSID"]) . ", ";
- $q.= "'".mysql_real_escape_string($_REQUEST["comment"])."', ";
- $q.= "UNIX_TIMESTAMP())";
- db_query($q, $dbh);
- print __("Comment has been added.");
-
- # Send email notifications
- #
- $q = "SELECT CommentNotify.*, Users.Email ";
- $q.= "FROM CommentNotify, Users ";
- $q.= "WHERE Users.ID = CommentNotify.UserID ";
- $q.= "AND CommentNotify.UserID != ".uid_from_sid($_COOKIE["AURSID"])." ";
- $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);
- #TODO: native language emails for users, based on their prefs
- # Simply making these strings translatable won't work, users would be
- # getting emails in the language that the user who posted the comment was in
- $body =
- "from http://aur.archlinux.org/packages.php?ID="
- . $_REQUEST["ID"] . "\n"
- . username_from_sid($_COOKIE["AURSID"]) . " wrote:\n\n"
- . $_POST['comment']
- . "\n\n---\nIf you no longer wish to receive notifications about this package, please go the the above package page and click the UnNotify button.";
- $body = wordwrap($body, 70);
- $bcc = implode(', ', $bcc);
- $headers = "Bcc: $bcc\nReply-to: nobody@archlinux.org\nFrom: aur-notify@archlinux.org\nX-Mailer: AUR\n";
- @mail(' ', "AUR Comment for ".$row['Name'], $body, $headers);
- }
-
- } else {
- # Prompt visitor for comment
- #
- print "<div align='center'>\n";
- print "<form action='pkgedit.php' method='post'>\n";
- print "<input type='hidden' name='add_Comment' value='1'>\n";
- print "<input type='hidden' name='ID' value=\"".$_REQUEST["ID"]."\">\n";
- print __("Enter your comment below.")."<br />&nbsp;<br />\n";
- print "<textarea name='comment' rows='10' cols='50'></textarea>\n";
- print "<br />&nbsp;<br />\n";
- print "<input type='submit' value=\"".__("Submit")."\">\n";
- print "<input type='reset' value=\"".__("Reset")."\">\n";
- print "</form>\n";
- print "</div>\n";
- }
- html_footer(AUR_VERSION);
- exit();
-}
-
# Change package category
#
if ($_REQUEST["change_Category"]) {
diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc
index b6f32e6..150f552 100644
--- a/web/lib/pkgfuncs.inc
+++ b/web/lib/pkgfuncs.inc
@@ -180,7 +180,7 @@ function package_comments($pkgid=0) {
$q.= " AND DelUsersID = 0"; # only display non-deleted comments
$q.= " ORDER BY CommentTS DESC";
$result = db_query($q, $dbh);
- if (!$result) {return array();}
+ if (!$result) {print 'poop';return array();}
while ($row = mysql_fetch_assoc($result)) {
$comments[] = $row;
}
@@ -272,20 +272,22 @@ function package_details($id=0, $SID="") {
global $pkgsearch_vars;
$atype = account_from_sid($SID);
$uid = uid_from_sid($SID);
+
$q = "SELECT Packages.*,Location,Category ";
$q.= "FROM Packages,PackageLocations,PackageCategories ";
$q.= "WHERE Packages.LocationID = PackageLocations.ID ";
$q.= "AND Packages.CategoryID = PackageCategories.ID ";
- $q.= "AND Packages.ID = ".intval($_REQUEST["ID"]);
+ $q.= "AND Packages.ID = " . intval($_REQUEST['ID']);
$dbh = db_connect();
$results = db_query($q, $dbh);
- if (!$results) {
- print __("Error retrieving package details.")."<br />\n";
- } else {
+ if (!$results) {
+ print __("Error retrieving package details.") . "<br />\n";
+ }
+ else {
$row = mysql_fetch_assoc($results);
if (empty($row)) {
- print __("Package details could not be found.")."<br />\n";
+ print __("Package details could not be found.") . "<br />\n";
}
else {
@@ -294,10 +296,11 @@ function package_details($id=0, $SID="") {
# Actions Bar
if ($SID) {
include('actions_form.php');
+ include('pkg_comment_form.php');
}
# Print Comments
- $comments = package_comments($row["ID"]);
+ $comments = package_comments($_REQUEST['ID']);
if (!empty($comments)) {
include('pkg_comments.php');
}
diff --git a/web/template/actions_form.php b/web/template/actions_form.php
index 6299819..de77645 100644
--- a/web/template/actions_form.php
+++ b/web/template/actions_form.php
@@ -51,10 +51,4 @@ if ($row["MaintainerUID"] == 0) {
?>
</form>
-<br />
-
- <form action='pkgedit.php' method='post'>
- <input type='hidden' name='ID' value="<?php echo $row['ID'] ?>" />
- <input type='submit' class='button' name='add_Comment' value="<?php echo __('Add Comment') ?>" />
- </form>
</div>
diff --git a/web/template/pkg_comment_form.php b/web/template/pkg_comment_form.php
new file mode 100644
index 0000000..70570da
--- /dev/null
+++ b/web/template/pkg_comment_form.php
@@ -0,0 +1,68 @@
+<?php
+# Add a comment to this package
+if (isset($_REQUEST['comment'])) {
+
+ # Insert the comment
+ $dbh = db_connect();
+ $q = 'INSERT INTO PackageComments ';
+ $q.= '(PackageID, UsersID, Comments, CommentTS) VALUES (';
+ $q.= intval($_REQUEST['ID']) . ', ' . uid_from_sid($_COOKIE['AURSID']) . ', ';
+ $q.= "'" . mysql_real_escape_string($_REQUEST['comment']) . "', ";
+ $q.= 'UNIX_TIMESTAMP())';
+ db_query($q, $dbh);
+
+ # Send email notifications
+ $q = 'SELECT CommentNotify.*, Users.Email ';
+ $q.= 'FROM CommentNotify, Users ';
+ $q.= 'WHERE Users.ID = CommentNotify.UserID ';
+ $q.= 'AND CommentNotify.UserID != ' . uid_from_sid($_COOKIE['AURSID']) . ' ';
+ $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);
+
+ # TODO: native language emails for users, based on their prefs
+ # Simply making these strings translatable won't work, users would be
+ # getting emails in the language that the user who posted the comment was in
+ $body =
+ 'from http://aur.archlinux.org/packages.php?ID='
+ . $_REQUEST['ID'] . "\n"
+ . username_from_sid($_COOKIE['AURSID']) . " wrote:\n\n"
+ . $_POST['comment']
+ . "\n\n---\nIf you no longer wish to receive notifications about this package, please go the the above package page and click the UnNotify button.";
+ $body = wordwrap($body, 70);
+ $bcc = implode(', ', $bcc);
+ $headers = "Bcc: $bcc\nReply-to: nobody@archlinux.org\nFrom: aur-notify@archlinux.org\nX-Mailer: AUR\n";
+ @mail(' ', "AUR Comment for " . $row['Name'], $body, $headers);
+ }
+}
+
+ # Prompt visitor for comment
+?>
+<div class="pgbox">
+ <form action='<?php echo $_SERVER['PHP_SELF'] . '?ID=' . $_REQUEST['ID'] ?>' method='post'>
+ <div style="padding: 1%">
+<?php
+if (isset($_REQUEST['comment'])) {
+ echo '<b>' . __('Comment has been added.') . '</b>';
+}
+?>
+ <input type='hidden' name='ID' value="<?php echo $_REQUEST['ID'] ?>">
+ <?php echo __('Enter your comment below.') ?><br />
+ <textarea name='comment' rows='10' style="width: 100%"></textarea><br />
+ <input type='submit' value="<?php echo __("Submit") ?>">
+ <input type='reset' value="<?php echo __("Reset") ?>">
+ </div>
+ </form>
+</div>
+