summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCallan Barrett <wizzomafizzo@gmail.com>2008-10-05 01:46:31 +0800
committerLoui Chang <louipc.ist@gmail.com>2008-10-14 19:36:04 -0400
commit8f5882e68deec6a8780653ae537aea7aa02283c3 (patch)
tree314c0c15b11f5b245c7f32ba1de5e9b5fce7e10b
parent2ce36384da97946bc6fe324a8c32a99c9b2d7873 (diff)
Convert package flagging to a function
Signed-off-by: Callan Barrett <wizzomafizzo@gmail.com> Signed-off-by: Loui Chang <louipc.ist@gmail.com>
-rw-r--r--web/html/packages.php101
-rw-r--r--web/lib/pkgfuncs.inc74
2 files changed, 79 insertions, 96 deletions
diff --git a/web/html/packages.php b/web/html/packages.php
index 4cfe9c4..317583f 100644
--- a/web/html/packages.php
+++ b/web/html/packages.php
@@ -37,106 +37,17 @@ if (isset($_COOKIE["AURSID"])) {
# grab the list of Package IDs to be operated on
#
isset($_POST["IDs"]) ? $ids = $_POST["IDs"] : $ids = array();
-#isset($_REQUEST["All_IDs"]) ?
-# $all_ids = explode(":", $_REQUEST["All_IDs"]) :
-# $all_ids = array();
-
# determine what button the visitor clicked
#
if ($_POST['action'] == "do_Flag" || isset($_POST['do_Flag'])) {
- if (!$atype) {
- print __("You must be logged in before you can flag packages.");
- print "<br />\n";
-
- } else {
-
- 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 "<p>\n";
- print __("The selected packages have been flagged out-of-date.");
- print "</p>\n";
-
- # notification by tardo.
- $f_name = username_from_sid($_COOKIE['AURSID']);
- $f_email = email_from_sid($_COOKIE['AURSID']);
- $f_uid = uid_from_sid($_COOKIE['AURSID']);
- $q = "SELECT Packages.Name, Users.Email, Packages.ID ";
- $q.= "FROM Packages, Users ";
- $q.= "WHERE Packages.ID IN (" . $flag .") ";
- $q.= "AND Users.ID = Packages.MaintainerUID ";
- $q.= "AND Users.ID != " . $f_uid;
- $result = db_query($q, $dbh);
- if (mysql_num_rows($result)) {
- while ($row = mysql_fetch_assoc($result)) {
- # construct email
- $body = "Your package " . $row['Name'] . " has been flagged out of date by " . $f_name . ". You may view your package at:\nhttp://aur.archlinux.org/packages.php?do_Details=1&ID=" . $row['ID'];
- $body = wordwrap($body, 70);
- $headers = "To: ".$row['Email']."\nReply-to: nobody@archlinux.org\nFrom:aur-notify@archlinux.org\nX-Mailer: PHP\nX-MimeOLE: Produced By AUR\n";
- @mail(' ', "AUR Out-of-date Notification for ".$row['Name'], $body, $headers);
- }
- }
-
- } else {
- print "<p>\n";
- print __("You did not select any packages to flag.");
- print "</p>\n";
- }
- }
-
+ print "<p>";
+ print pkg_flag($atype, $ids, True);
+ print "</p>";
} elseif ($_POST['action'] == "do_UnFlag" || isset($_POST['do_UnFlag'])) {
- if (!$atype) {
- print __("You must be logged in before you can unflag packages.");
- print "<br />\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 "<p>\n";
- print __("The selected packages have been unflagged.");
- print "</p>\n";
- } else {
- print "<p>\n";
- print __("You did not select any packages to unflag.");
- print "</p>\n";
- }
-
-
- }
-
+ print "<p>";
+ print pkg_flag($atype, $ids, False);
+ print "</p>";
} elseif ($_POST['action'] == "do_Disown" || isset($_POST['do_Disown'])) {
if (!$atype) {
print __("You must be logged in before you can disown packages.");
diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc
index 5ba56da..a508a0b 100644
--- a/web/lib/pkgfuncs.inc
+++ b/web/lib/pkgfuncs.inc
@@ -985,4 +985,76 @@ function pkg_search_page($SID="") {
return;
}
-?>
+function pkg_flag ($atype, $ids, $action = True) {
+ if (!$atype) {
+ if ($action) {
+ return __("You must be logged in before you can flag packages.");
+ } else {
+ return __("You must be logged in before you can unflag packages.");
+ }
+ }
+
+ if (empty($ids)) {
+ if ($action) {
+ return __("You did not select any packages to flag.");
+ } else {
+ return __("You did not select any packages to unflag.");
+ }
+ }
+
+ foreach ($ids as $pid => $v) {
+ if (!is_numeric($pid)) {
+ if ($action) {
+ return __("You did not select any packages to flag.");
+ } else {
+ return __("You did not select any packages to unflag.");
+ }
+ }
+ }
+
+ $dbh = db_connect();
+
+ $first = 1;
+ foreach ($ids as $pid => $v) {
+ if ($first) {
+ $first = 0;
+ $flag = $pid;
+ } else {
+ $flag .= ", " . $pid;
+ }
+ }
+
+ $ood = $action ? 1 : 0;
+ $q = "UPDATE Packages SET OutOfDate = " . $ood;
+ $q.= " WHERE ID IN (" . $flag . ")";
+
+ db_query($q, $dbh);
+
+ if ($action) {
+ # Notify of flagging by email
+ $f_name = username_from_sid($_COOKIE['AURSID']);
+ $f_email = email_from_sid($_COOKIE['AURSID']);
+ $f_uid = uid_from_sid($_COOKIE['AURSID']);
+ $q = "SELECT Packages.Name, Users.Email, Packages.ID ";
+ $q.= "FROM Packages, Users ";
+ $q.= "WHERE Packages.ID IN (" . $flag .") ";
+ $q.= "AND Users.ID = Packages.MaintainerUID ";
+ $q.= "AND Users.ID != " . $f_uid;
+ $result = db_query($q, $dbh);
+ if (mysql_num_rows($result)) {
+ while ($row = mysql_fetch_assoc($result)) {
+ # construct email
+ $body = "Your package " . $row['Name'] . " has been flagged out of date by " . $f_name . ". You may view your package at:\nhttp://aur.archlinux.org/packages.php?ID=" . $row['ID'];
+ $body = wordwrap($body, 70);
+ $headers = "To: ".$row['Email']."\nReply-to: nobody@archlinux.org\nFrom:aur-notify@archlinux.org\nX-Mailer: PHP\nX-MimeOLE: Produced By AUR\n";
+ @mail(' ', "AUR Out-of-date Notification for ".$row['Name'], $body, $headers);
+ }
+ }
+ }
+
+ if ($action) {
+ return __("The selected packages have been flagged out-of-date.");
+ } else {
+ return __("The selected packages have been unflagged.");
+ }
+}