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 +++----------------------------------------------- 1 file changed, 6 insertions(+), 95 deletions(-) (limited to 'web/html/packages.php') 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."); -- cgit v1.2.3-70-g09d2 From a447281d4f5ce2071ebc81b375c70ae44231b046 Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Sat, 4 Oct 2008 03:42:34 +0800 Subject: Convert package deletion to a function Signed-off-by: Callan Barrett Signed-off-by: Loui Chang --- web/html/packages.php | 90 +++------------------------------------------------ web/lib/pkgfuncs.inc | 73 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 86 deletions(-) (limited to 'web/html/packages.php') diff --git a/web/html/packages.php b/web/html/packages.php index 317583f..bc3ed18 100644 --- a/web/html/packages.php +++ b/web/html/packages.php @@ -22,7 +22,7 @@ if (isset($_GET['ID'])) { $title = __("Packages"); } -html_header($title); # print out the HTML header +html_header($title); # get login privileges # @@ -95,91 +95,9 @@ if ($_POST['action'] == "do_Flag" || isset($_POST['do_Flag'])) { } elseif ($_POST['action'] == "do_Delete" || isset($_POST['do_Delete'])) { - if (!$atype) { - print __("You must be logged in before you can disown packages."); - print "
\n"; - } else { - # Delete the packages in $ids array (but only if they are Unsupported) - # - if (!empty($ids)) { - $dbh = db_connect(); - - # Delete the packages in $ids array - # - $first = 1; - while (list($pid, $v) = each($ids)) { - if ($first) { - $first = 0; - $delete = $pid; - } else { - $delete .= ", ".$pid; - } - } - - $field = "MaintainerUID"; - - # Only grab Unsupported packages that "we" own or are not owned at all - # - $ids_to_delete = array(); - $q = "SELECT Packages.ID FROM Packages, PackageLocations "; - $q.= "WHERE Packages.ID IN (" . $delete . ") "; - $q.= "AND Packages.LocationID = PackageLocations.ID "; - $q.= "AND PackageLocations.Location = 'unsupported' "; - # If they're a TU or dev, can always delete, otherwise check ownership - # - if ($atype == "Trusted User" || $atype == "Developer") { - $result = db_query($q, $dbh); - } - if ($result != Null && mysql_num_rows($result) > 0) { - while ($row = mysql_fetch_assoc($result)) { - $ids_to_delete[] = $row['ID']; - } - } - if (!empty($ids_to_delete)) { - # These are the packages that are safe to delete - # - foreach ($ids_to_delete as $id) { - # delete from PackageVotes - $q = "DELETE FROM PackageVotes WHERE PackageID = " . $id; - $result = db_query($q, $dbh); - - # delete from PackageDepends - $q = "DELETE FROM PackageDepends WHERE PackageID = " . $id; - $result = db_query($q, $dbh); - - # delete from PackageSources - $q = "DELETE FROM PackageSources WHERE PackageID = " . $id; - $result = db_query($q, $dbh); - - # delete from PackageComments - $q = "DELETE FROM PackageComments WHERE PackageID = " . $id; - $result = db_query($q, $dbh); - - # delete from Packages - $q = "DELETE FROM Packages WHERE ID = " . $id; - $result = db_query($q, $dbh); - - # delete from CommentNotify - $q = "DELETE FROM CommentNotify WHERE PkgID = " . $id; - $result = db_query($q, $dbh); - - # Print the success message - print "

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

\n"; - } - } else { - print "

\n"; - print __("None of the selected packages could be deleted."); - print "

\n"; - } # end if (!empty($ids_to_delete)) - } else { - print "

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

\n"; - } # end if (!empty($ids)) - } # end if (!atype) - + print "

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

"; } elseif ($_POST['action'] == "do_Adopt" || isset($_POST['do_Adopt'])) { if (!$atype) { print __("You must be logged in before you can adopt packages."); diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index a508a0b..c952b85 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -1058,3 +1058,76 @@ function pkg_flag ($atype, $ids, $action = True) { return __("The selected packages have been unflagged."); } } + +function pkg_delete ($atype, $ids) { + if (!$atype) { + return __("You must be logged in before you can disown packages."); + } + + if (empty($ids)) { + return __("You did not select any packages to delete."); + } + + # Delete the packages in $ids array (but only if they are Unsupported) + # + $dbh = db_connect(); + + # Delete the packages in $ids array + # + $first = 1; + foreach ($ids as $pid => $v) { + if ($first) { + $first = 0; + $delete = $pid; + } else { + $delete .= ", ".$pid; + } + } + + $field = "MaintainerUID"; + + # Only grab Unsupported packages that "we" own or are not owned at all + $ids_to_delete = array(); + $q = "SELECT Packages.ID FROM Packages, PackageLocations "; + $q.= "WHERE Packages.ID IN (" . $delete . ") "; + $q.= "AND Packages.LocationID = PackageLocations.ID "; + $q.= "AND PackageLocations.Location = 'unsupported' "; + + # If they're a TU or dev, can delete + if ($atype == "Trusted User" || $atype == "Developer") { + $result = db_query($q, $dbh); + } + + if ($result != Null && mysql_num_rows($result) > 0) { + while ($row = mysql_fetch_assoc($result)) { + $ids_to_delete[] = $row['ID']; + } + } + + if (empty($ids_to_delete)) { + return __("None of the selected packages could be deleted."); + } + + # These are the packages that are safe to delete + foreach ($ids_to_delete as $id) { + $q = "DELETE FROM PackageVotes WHERE PackageID = " . $id; + $result = db_query($q, $dbh); + + $q = "DELETE FROM PackageDepends WHERE PackageID = " . $id; + $result = db_query($q, $dbh); + + $q = "DELETE FROM PackageSources WHERE PackageID = " . $id; + $result = db_query($q, $dbh); + + $q = "DELETE FROM PackageComments WHERE PackageID = " . $id; + $result = db_query($q, $dbh); + + $q = "DELETE FROM Packages WHERE ID = " . $id; + $result = db_query($q, $dbh); + + $q = "DELETE FROM CommentNotify WHERE PkgID = " . $id; + $result = db_query($q, $dbh); + } + + return __("The selected packages have been deleted."); +} -- cgit v1.2.3-70-g09d2 From 5d4303d0b6afacb2b3a8731bdb9fdbd6c40f5c0e Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Sun, 5 Oct 2008 02:13:35 +0800 Subject: Convert package adoption/disowning to a function Signed-off-by: Callan Barrett Signed-off-by: Loui Chang --- web/html/packages.php | 100 +++----------------------------------------------- web/lib/pkgfuncs.inc | 58 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 94 deletions(-) (limited to 'web/html/packages.php') diff --git a/web/html/packages.php b/web/html/packages.php index bc3ed18..5935ebd 100644 --- a/web/html/packages.php +++ b/web/html/packages.php @@ -49,105 +49,17 @@ if ($_POST['action'] == "do_Flag" || isset($_POST['do_Flag'])) { 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."); - print "
\n"; - - } else { - # Disown the packages in $ids array - # - if (!empty($ids)) { - $dbh = db_connect(); - - # Disown the packages in $ids array - # - $first = 1; - while (list($pid, $v) = each($ids)) { - if ($first) { - $first = 0; - $disown = $pid; - } else { - $disown .= ", ".$pid; - } - } - - $field = "MaintainerUID"; - $q = "UPDATE Packages "; - $q.= "SET ".$field." = 0 "; - $q.= "WHERE ID IN (" . $disown . ") "; - # If a user is a TU or dev they can disown any package - if ($atype == "User") { - $q.= "AND ".$field." = ".uid_from_sid($_COOKIE["AURSID"]); - } - db_query($q, $dbh); - - print "

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

\n"; - } else { - print "

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

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

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

"; } elseif ($_POST['action'] == "do_Delete" || isset($_POST['do_Delete'])) { print "

"; print pkg_delete($atype, $ids, False); print "

"; } elseif ($_POST['action'] == "do_Adopt" || isset($_POST['do_Adopt'])) { - if (!$atype) { - print __("You must be logged in before you can adopt packages."); - print "
\n"; - - } else { - # Adopt the packages in $ids array - # - if (!empty($ids)) { - $dbh = db_connect(); - - # Adopt the packages in $ids array - # - $first = 1; - while (list($pid, $v) = each($ids)) { - if ($first) { - $first = 0; - $adopt = $pid; - } else { - $adopt .= ", ".$pid; - } - } - - $field = "MaintainerUID"; - # NOTE: Only "orphaned" packages can be adopted at a particular - # user class (TU/Dev or User). - # - $q = "UPDATE Packages "; - $q.= "SET ".$field." = ".uid_from_sid($_COOKIE["AURSID"])." "; - $q.= "WHERE ID IN (" . $adopt . ") "; - if ($atype == "User") - { - # Regular users may only adopt orphan packages from unsupported - # FIXME: We assume that LocationID for unsupported is "2" - $q.= "AND ".$field." = 0"; - $q.= " AND LocationID = 2"; - } - db_query($q, $dbh); - - print "

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

\n"; - } else { - print "

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

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

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

"; } elseif ($_POST['action'] == "do_Vote" || isset($_POST['do_Vote'])) { if (!$atype) { print __("You must be logged in before you can vote for packages."); diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index c952b85..415f3e7 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -1131,3 +1131,61 @@ function pkg_delete ($atype, $ids) { return __("The selected packages have been deleted."); } + +function pkg_adopt ($atype, $ids, $action = True) { + if (!$atype) { + if ($action) { + return __("You must be logged in before you can adopt packages."); + } else { + return __("You must be logged in before you can disown packages."); + } + } + + if (empty($ids)) { + if ($action) { + return __("You did not select any packages to adopt."); + } else { + return __("You did not select any packages to disown."); + } + } + + $dbh = db_connect(); + + $first = 1; + foreach ($ids as $pid => $v) { + if ($first) { + $first = 0; + $pkg = $pid; + } else { + $pkg .= ", ".$pid; + } + } + + $field = "MaintainerUID"; + $q = "UPDATE Packages "; + + if ($action) { + $user = uid_from_sid($_COOKIE["AURSID"]); + } else { + $user = 0; + } + + $q.= "SET $field = $user "; + $q.= "WHERE ID IN ($pkg) "; + + if ($action && $atype == "User") { + # Regular users may only adopt orphan packages from unsupported + $q.= "AND $field = 0 "; + $q.= "AND LocationID = 2 "; + } else if ($atype == "User") { + $q.= "AND $field = " . uid_from_sid($_COOKIE["AURSID"]); + } + + db_query($q, $dbh); + + if ($action) { + return __("The selected packages have been adopted."); + } else { + return __("The selected packages have been disowned."); + } +} -- cgit v1.2.3-70-g09d2 From 132fd7cfc791a76f084140b2901018a046160b84 Mon Sep 17 00:00:00 2001 From: Callan Barrett Date: Sun, 5 Oct 2008 02:54:13 +0800 Subject: Convert package voting to a function Signed-off-by: Callan Barrett Signed-off-by: Loui Chang --- web/html/packages.php | 112 +++----------------------------------------------- web/lib/pkgfuncs.inc | 77 ++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 106 deletions(-) (limited to 'web/html/packages.php') diff --git a/web/html/packages.php b/web/html/packages.php index 5935ebd..91b0e6e 100644 --- a/web/html/packages.php +++ b/web/html/packages.php @@ -61,113 +61,13 @@ if ($_POST['action'] == "do_Flag" || isset($_POST['do_Flag'])) { print pkg_adopt($atype, $ids, True); print "

"; } elseif ($_POST['action'] == "do_Vote" || isset($_POST['do_Vote'])) { - if (!$atype) { - print __("You must be logged in before you can vote for packages."); - print "
\n"; - - } else { - # vote on the packages in $ids array. - # - if (!empty($ids)) { - $dbh = db_connect(); - $my_votes = pkgvotes_from_sid($_COOKIE["AURSID"]); - $uid = uid_from_sid($_COOKIE["AURSID"]); - # $vote_ids will contain the string of Package.IDs that - # the visitor hasn't voted for already - # - $first = 1; - while (list($pid, $v) = each($ids)) { - if (!isset($my_votes[$pid])) { - # cast a vote for this package - # - if ($first) { - $first = 0; - $vote_ids = $pid; - $vote_clauses = "(".$uid.", ".$pid.")"; - } else { - $vote_ids .= ", ".$pid; - $vote_clauses .= ", (".$uid.", ".$pid.")"; - } - } - } - # only vote for packages the user hasn't already voted for - # - $q = "UPDATE Packages SET NumVotes = NumVotes + 1 "; - $q.= "WHERE ID IN (".$vote_ids.")"; - db_query($q, $dbh); - - $q = "INSERT INTO PackageVotes (UsersID, PackageID) VALUES "; - $q.= $vote_clauses; - db_query($q, $dbh); - - # Update the LastVoted field for this user - # - $q = "UPDATE Users SET LastVoted = UNIX_TIMESTAMP() "; - $q.= "WHERE ID = ".$uid; - db_query($q, $dbh); - - print "

\n"; - print __("Your votes have been cast for the selected packages."); - print "

\n"; - - } else { - print "

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

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

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

"; } elseif ($_POST['action'] == "do_UnVote" || isset($_POST['do_UnVote'])) { - if (!$atype) { - print __("You must be logged in before you can un-vote for packages."); - print "
\n"; - - } else { - # un-vote on the packages in $ids array. - # - if (!empty($ids)) { - $dbh = db_connect(); - $my_votes = pkgvotes_from_sid($_COOKIE["AURSID"]); - $uid = uid_from_sid($_COOKIE["AURSID"]); - # $unvote_ids will contain the string of Package.IDs that - # the visitor has voted for and wants to unvote. - # - $first = 1; - while (list($pid, $v) = each($ids)) { - if (isset($my_votes[$pid])) { - # cast a un-vote for this package - # - if ($first) { - $first = 0; - $unvote_ids = $pid; - } else { - $unvote_ids .= ", ".$pid; - } - } - } - # only un-vote for packages the user has already voted for - # - $q = "UPDATE Packages SET NumVotes = NumVotes - 1 "; - $q.= "WHERE ID IN (".$unvote_ids.")"; - db_query($q, $dbh); - - $q = "DELETE FROM PackageVotes WHERE UsersID = ".$uid." "; - $q.= "AND PackageID IN (".$unvote_ids.")"; - db_query($q, $dbh); - - print "

\n"; - print __("Your votes have been removed from the selected packages."); - print "

\n"; - - } else { - print "

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

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

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

"; } elseif (isset($_GET["ID"])) { if (!intval($_GET["ID"])) { diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index 415f3e7..7fe3f31 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -1189,3 +1189,80 @@ function pkg_adopt ($atype, $ids, $action = True) { return __("The selected packages have been disowned."); } } + +function pkg_vote ($atype, $ids, $action = True) { + if (!$atype) { + if ($action) { + return __("You must be logged in before you can vote for packages."); + } else { + return __("You must be logged in before you can un-vote for packages."); + } + } + + if (empty($ids)) { + if ($action) { + return __("You did not select any packages to vote for."); + } else { + return __("Your votes have been removed from the selected packages."); + } + } + + $dbh = db_connect(); + $my_votes = pkgvotes_from_sid($_COOKIE["AURSID"]); + $uid = uid_from_sid($_COOKIE["AURSID"]); + + $first = 1; + foreach ($ids as $pid => $v) { + if ($action) { + $check = !isset($my_votes[$pid]); + } else { + $check = isset($my_votes[$pid]); + } + + if ($check) { + if ($first) { + $first = 0; + $vote_ids = $pid; + if ($action) { + $vote_clauses = "($uid, $pid)"; + } + } else { + $vote_ids .= ", $pid"; + if ($action) { + $vote_clauses .= ", ($uid, $pid)"; + } + } + } + } + + # only vote for packages the user hasn't already voted for + # + $op = $action ? "+" : "-"; + $q = "UPDATE Packages SET NumVotes = NumVotes $op 1 "; + $q.= "WHERE ID IN ($vote_ids)"; + + db_query($q, $dbh); + + if ($action) { + $q = "INSERT INTO PackageVotes (UsersID, PackageID) VALUES "; + $q.= $vote_clauses; + } else { + $q = "DELETE FROM PackageVotes WHERE UsersID = $uid "; + $q.= "AND PackageID IN ($vote_ids)"; + } + + db_query($q, $dbh); + + if ($action) { + $q = "UPDATE Users SET LastVoted = UNIX_TIMESTAMP() "; + $q.= "WHERE ID = $uid"; + + db_query($q, $dbh); + } + + if ($action) { + return __("Your votes have been cast for the selected packages."); + } else { + return __("Your votes have been removed from the selected packages."); + } +} -- cgit v1.2.3-70-g09d2