From 57a5cbfd88b2b91722ce0bf6911b416d051dde65 Mon Sep 17 00:00:00 2001 From: Dan Vratil Date: Sun, 21 Nov 2010 02:59:07 -0500 Subject: Auto redirect from confirmation screens. Finally move comment deletion and category editing into functions and remove pkgedit.php Signed-off-by: Loui Chang -Fix indentation -Fix variable naming conflict $id vs $cid --- web/html/css/containers.css | 4 ++ web/html/packages.php | 4 ++ web/html/pkgedit.php | 109 ------------------------------------------ web/lib/pkgfuncs.inc | 86 +++++++++++++++++++++++++++++++++ web/template/pkg_comments.php | 23 +++++---- web/template/pkg_details.php | 23 ++++++--- 6 files changed, 125 insertions(+), 124 deletions(-) delete mode 100644 web/html/pkgedit.php (limited to 'web') diff --git a/web/html/css/containers.css b/web/html/css/containers.css index fc092de..12362f6 100644 --- a/web/html/css/containers.css +++ b/web/html/css/containers.css @@ -187,4 +187,8 @@ input.button { font-size: 12px; padding: 2px 8px; } +input[type=image] { + border: 0; + background: none; +} diff --git a/web/html/packages.php b/web/html/packages.php index 472f6a2..741ffb1 100644 --- a/web/html/packages.php +++ b/web/html/packages.php @@ -57,6 +57,10 @@ if ($_POST['action'] == "do_Flag" || isset($_POST['do_Flag'])) { $output = pkg_notify($atype, $ids); } elseif ($_POST['action'] == "do_UnNotify" || isset($_POST['do_UnNotify'])) { $output = pkg_notify($atype, $ids, False); +} elseif ($_POST['action'] == "do_DeleteComment" || isset($_POST["do_DeleteComment"])) { + $output = pkg_delete_comment($atype); +} elseif ($_POST['action'] == "do_ChangeCategory" || isset($_POST['do_ChangeCategory'])) { + $output = pkg_change_category($atype); } html_header($title); diff --git a/web/html/pkgedit.php b/web/html/pkgedit.php deleted file mode 100644 index 0339d00..0000000 --- a/web/html/pkgedit.php +++ /dev/null @@ -1,109 +0,0 @@ -\n"; - html_footer(AUR_VERSION); - exit(); -} - -# Must know what package to operate on throughout this entire script -# -if (!$_REQUEST["ID"]) { - print __("Missing package ID."); - print "
\n"; - html_footer(AUR_VERSION); - exit(); -} - - -# Delete a comment for this package -# -if ($_REQUEST["del_Comment"]) { - if ($_REQUEST["comment_id"]) { - $uid = uid_from_sid($_COOKIE["AURSID"]); - if (canDeleteComment($_REQUEST["comment_id"], $atype, $uid)) { - $dbh = db_connect(); - $q = "UPDATE PackageComments "; - $q.= "SET DelUsersID = ".$uid." "; - $q.= "WHERE ID = ".intval($_REQUEST["comment_id"]); - db_query($q, $dbh); - print __("Comment has been deleted.")."
\n"; - } else { - print __("You are not allowed to delete this comment.")."
\n"; - } - } else { - print __("Missing comment ID.")."
\n"; - } - html_footer(AUR_VERSION); - exit(); -} - -# Change package category -# -if ($_REQUEST["change_Category"]) { - $cat_array = pkgCategories(); - $dbh = db_connect(); - - if ($_REQUEST["category_id"]) { - # Try and set the requested category_id - # - if (array_key_exists($_REQUEST["category_id"], $cat_array)) { - $q = "UPDATE Packages SET CategoryID = ".intval($_REQUEST["category_id"]); - $q.= " WHERE ID = ".intval($_REQUEST["ID"]); - db_query($q, $dbh); - print __("Package category updated.")."
\n"; - - } else { - print __("Invalid category ID.")."
\n"; - } - } else { - # Prompt visitor for new category_id - # - $q = "SELECT CategoryID FROM Packages WHERE ID = ".intval($_REQUEST["ID"]); - $result = db_query($q, $dbh); - if ($result != NULL) { - $catid = mysql_fetch_row($result); - } - print "
\n"; - print "\n"; - print "\n"; - print __("Select new category").": \n"; - print "\n"; - print "
 
\n"; - print "\n"; - print "\n"; - print "
\n"; - - } - html_footer(AUR_VERSION); - exit(); -} - -print __("You've found a bug if you see this....")."
\n"; - -html_footer(AUR_VERSION); - diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc index 0f45124..c701348 100644 --- a/web/lib/pkgfuncs.inc +++ b/web/lib/pkgfuncs.inc @@ -984,3 +984,89 @@ function pkg_notify ($atype, $ids, $action = True) { return $output; } + + +/** + * Delete comment + * + * @param string $atype Account type, output of account_from_sid + * @return string Translated error or success message + */ +function pkg_delete_comment($atype) { + if (!$atype) { + return __("You must be logged before you can edit package information."); + } + + # Get ID of comment to be removed + if (isset($_POST["comment_id"])) { + $comment_id = $_POST["comment_id"]; + } else { + return __("Missing comment ID."); + } + + $uid = uid_from_sid($_COOKIE["AURSID"]); + if (canDeleteComment($comment_id, $atype, $uid)) { + + $dbh = db_connect(); + $q = "UPDATE PackageComments "; + $q.= "SET DelUsersID = ".$uid." "; + $q.= "WHERE ID = ".intval($comment_id); + db_query($q, $dbh); + return __("Comment has been deleted."); + } else { + return __("You are not allowed to delete this comment."); + } +} + +/** + * Change package category + * + * @param string $atype Account type, output of account_from_sid + * @return string Translated error or success message + */ +function pkg_change_category($atype) { + if (!$atype) { + return __("You must be logged before you can edit package information."); + } + + # Get ID of the new category + if (isset($_POST["category_id"])) { + $category_id = $_POST["category_id"]; + } else { + return __("Missing category ID."); + } + + $catArray = pkgCategories(); + if (!array_key_exists($category_id, $catArray)) { + return __("Invalid category ID."); + } + + if (isset($_GET["ID"])) { + $pid = $_GET["ID"]; + } else { + return __("Missing package ID."); + } + + # Verify package ownership and location + $dbh = db_connect(); + $q = "SELECT Packages.MaintainerUID,"; + $q.= "PackageLocations.Location "; + $q.= "FROM Packages "; + $q.= "LEFT JOIN PackageLocations ON Packages.LocationID = PackageLocations.ID "; + $q.= "WHERE Packages.ID = ".$pid; + $result = db_query($q, $dbh); + echo mysql_error(); + $pkg = mysql_fetch_assoc($result); + + $uid = uid_from_sid($_COOKIE["AURSID"]); + if ($pkg["Location"] == "unsupported" and ($uid == $pkg["MaintainerUID"] or + ($atype == "Developer" or $atype == "Trusted User"))) { + $q = "UPDATE Packages "; + $q.= "SET CategoryID = ".intval($category_id)." "; + $q.= "WHERE ID = ".intval($pid); + db_query($q, $dbh); + return __("Package category changed."); + } else { + return __("You are not allowed to change this package category."); + } +} diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php index 02171a0..e4a9da1 100644 --- a/web/template/pkg_comments.php +++ b/web/template/pkg_comments.php @@ -3,20 +3,25 @@ $uid = uid_from_sid($SID); while (list($indx, $carr) = each($comments)) { ?>
'; - - echo $durl; - } if ($SID) { $carr['UserName'] = "{$carr['UserName']}"; } - echo __('Comment by: %s on %s', $carr['UserName'], gmdate('r', $carr['CommentTS'])); + $commentHeader =__('Comment by: %s on %s', $carr['UserName'], gmdate('r', $carr['CommentTS'])); + + if (canDeleteCommentArray($carr, $atype, $uid)) { + $durl = '
'; + $durl.= ''; + $durl.= ''; + $durl.= '"; + } + + echo $commentHeader; ?>
diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index a4b8f95..7c6356d 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -4,13 +4,24 @@ $pkgid = intval($_REQUEST['ID']); if ($row["Location"] == "unsupported" and ($uid == $row["MaintainerUID"] or ($atype == "Developer" or $atype == "Trusted User"))) { - $edit_cat = "".$row["Category"].""; - $edit_cat .= "  ("; - $edit_cat .= __("change category").")"; + $catarr = pkgCategories(); + $edit_cat = "\n"; + $edit_cat.= ""; + $edit_cat.= $row['Location']." :: "; + $edit_cat.= " "; + $edit_cat.= ""; + } else { - $edit_cat = $row['Category']; + $edit_cat = $row['Location']." :: ".$row['Category']; } if ($row["MaintainerUID"]) { @@ -49,7 +60,7 @@ $out_of_date_time = ($row["OutOfDateTS"] == 0) ? $msg : gmdate("r", intval($row[

-
+

-- cgit v1.2.3-70-g09d2