From 8f5882e68deec6a8780653ae537aea7aa02283c3 Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Sun, 5 Oct 2008 01:46:31 +0800 Subject: Convert package flagging to a function Signed-off-by: Callan Barrett Signed-off-by: Loui Chang --- web/html/packages.php | 101 +++----------------------------------------------- web/lib/pkgfuncs.inc | 74 +++++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 96 deletions(-) (limited to 'web') 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 "
\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 "

\n"; - print __("The selected packages have been flagged out-of-date."); - print "

\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 "

\n"; - print __("You did not select any packages to flag."); - print "

\n"; - } - } - + print "

"; + print pkg_flag($atype, $ids, True); + print "

"; } elseif ($_POST['action'] == "do_UnFlag" || isset($_POST['do_UnFlag'])) { - if (!$atype) { - print __("You must be logged in before you can unflag packages."); - print "
\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 "

\n"; - print __("The selected packages have been unflagged."); - print "

\n"; - } else { - print "

\n"; - print __("You did not select any packages to unflag."); - print "

\n"; - } - - - } - + print "

"; + print pkg_flag($atype, $ids, False); + print "

"; } 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."); + } +} -- cgit v1.2.3-70-g09d2