On Saturday 31 July 2010 21:29:46 Loui Chang wrote:
> On Sat 31 Jul 2010 21:10 +0200, Dan Vratil wrote:
> > On Saturday 31 July 2010 18:26:59 Loui Chang wrote:
> > > On Sat 31 Jul 2010 17:54 +0200, Dan Vratil wrote:
> > > > this patch is adding meta refresh tag and a link back to the package
> > > > page from the screens that confirm comment deletion and change of
> > > > package category.
> > > > 
> > > > The link is displayed always, but the autoredirection is done only
> > > > when the action was sucessfull. This allows user to read or note down
> > > > a possible error output in case of failure.
> > > > 
> > > > The delay for refresh is set to 5 seconds, but that can be discussed.
> > > 
> > > This isn't consistent with the way the other 'redirection' is
> > > performed. It would be preferable to just load on the package page
> > > with a message at the top saying that the comment was deleted.
> > > 
> > > Please have a look at how flagging, orphaning, and adopting work.
> > > It probably will take more effort to implement, but it's the proper
> > > solution that will work with all web browsers.
> > > 
> > > Thanks for you contributions!
> > 
> > Sure, I thought it won't be that easy :)
> > 
> > I've finished deleting comments and now I'm thinking about where to
> > put the code for the form for changing the package category and I got
> > an idea, that the best solution would be to replace the link with the
> > current category name by a combobox with list of categories and the
> > text "(change category)" by a button with the same text that would
> > submit the new category directly. This would also allow me to remove
> > the pkgedit.php script entirely.
> > 
> > What do you think about? I don't want to make such a big change in layout
> > without permission :)
> 
> Sounds like a good idea to me.


So here comes another revision :-)

-- 
---------------------------------
Dan Vrátil
[email protected]
ICQ 249163429
Jabber [email protected]
Tel. +420 732 326 870

Tento email neobsahuje žádné viry, protože odesílatel nepoužívá Windows. /
This email does not contain any viruses because the sender does not use 
Windows.
diff --git a/web/html/css/containers.css b/web/html/css/containers.css
index fd3bea2..a3ae81c 100644
--- a/web/html/css/containers.css
+++ b/web/html/css/containers.css
@@ -187,4 +187,8 @@ input.button {
   font-size: 12px;
   padding: 2px;
 }
+input[type=image] {
+  border: 0;
+  background: none;
+}
 
diff --git a/web/html/packages.php b/web/html/packages.php
index 472f6a2..f77ce04 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 @@
-<?php
-
-set_include_path(get_include_path() . PATH_SEPARATOR . '../lib');
-
-include_once("aur.inc");         # access AUR common functions
-include_once("pkgfuncs.inc");    # use some form of this for i18n support
-set_lang();                 # this sets up the visitor's language
-check_sid();                # see if they're still logged in
-html_header();              # print out the HTML header
-
-# Make sure this visitor is logged in
-#
-if (isset($_COOKIE["AURSID"])) {
-	$atype = account_from_sid($_COOKIE["AURSID"]);
-} else {
-	$atype = "";
-}
-if (!$atype) {
-	print __("You must be logged in before you can edit package information.");
-	print "<br />\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 "<br />\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.")."<br />\n";
-		} else {
-			print __("You are not allowed to delete this comment.")."<br />\n";
-		}
-	} else {
-		print __("Missing comment ID.")."<br />\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.")."<br />\n";
-
-		} else {
-			print __("Invalid category ID.")."<br />\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 "<form action='pkgedit.php' method='post'>\n";
-		print "<input type='hidden' name='change_Category' value='1'>\n";
-		print "<input type='hidden' name='ID' value=\"".$_REQUEST["ID"]."\">\n";
-		print __("Select new category").":&nbsp;\n";
-		print "<select name='category_id'>\n";
-		while (list($id,$cat) = each($cat_array)) {
-			print "<option value='".$id."'";
-			if ($id == $catid[0]) {
-				print " selected";
-			}
-			print "> ".$cat."</option>\n";
-		}
-		print "</select>\n";
-		print "<br />&nbsp;<br />\n";
-		print "<input type='submit' value=\"".__("Submit")."\">\n";
-		print "<input type='reset' value=\"".__("Reset")."\">\n";
-		print "</form>\n";
-
-	}
-	html_footer(AUR_VERSION);
-	exit();
-}
-
-print __("You've found a bug if you see this....")."<br />\n";
-
-html_footer(AUR_VERSION);
-
diff --git a/web/lib/pkgfuncs.inc b/web/lib/pkgfuncs.inc
index 5605daa..bead547 100644
--- a/web/lib/pkgfuncs.inc
+++ b/web/lib/pkgfuncs.inc
@@ -979,3 +979,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.");
+        }
+}
\ No newline at end of file
diff --git a/web/template/pkg_comments.php b/web/template/pkg_comments.php
index 02171a0..a5608cc 100644
--- a/web/template/pkg_comments.php
+++ b/web/template/pkg_comments.php
@@ -3,20 +3,26 @@
 $uid = uid_from_sid($SID);
 while (list($indx, $carr) = each($comments)) { ?>
 	<div class="comment-header"><?php
-	if (canDeleteCommentArray($carr, $atype, $uid)) {
-		$durl = '<a href="pkgedit.php?del_Comment=1';
-		$durl.= '&comment_id=' . $carr['ID'] . '&ID=' . $row['ID'];
-		$durl.= '"><img src="images/x.png" border="0"';
-		$durl.= ' alt="' . __("Delete comment") . '"></a> ';
-
-		echo $durl;
-	}
 
 	if ($SID) {
 		$carr['UserName'] = "<a href=\"account.php?Action=AccountInfo&amp;ID={$carr['UsersID']}\">{$carr['UserName']}</a>";
 	}
 
-	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 = '<form method="POST" action="packages.php?ID='.$row['ID'].'">';
+                $durl.= '<input type="hidden" name="action" value="do_DeleteComment">';
+                $durl.= '<input type="hidden" name="comment_id" value="'.$carr['ID'].'">';
+                $durl.= '<input type="image" src="images/x.png" border="0" ';
+                $durl.= ' alt="'.__("Delete comment").'" name="submit" value="1" ';
+                $durl.= ' width="19" height="18">&nbsp;';
+
+                $commentHeader = $durl.$commentHeader."</form>";
+	}
+
+
+	echo $commentHeader
 ?></div>
 	<blockquote class="comment-body">
 	<div>
diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php
index 9c76ab3..44db52d 100644
--- a/web/template/pkg_details.php
+++ b/web/template/pkg_details.php
@@ -4,13 +4,25 @@ $pkgid = intval($_REQUEST['ID']);
 if ($row["Location"] == "unsupported" and ($uid == $row["MaintainerUID"] or
 	($atype == "Developer" or $atype == "Trusted User"))) {
 
-	$edit_cat = "<a href='pkgedit.php?change_Category=1&amp;ID=";
-	$edit_cat .= $pkgid ."'>".$row["Category"]."</a>";
-	$edit_cat .= " &nbsp;<span class='fix'>(";
-	$edit_cat .= __("change category").")</span>";
+        $catarr = pkgCategories();
+        $edit_cat = "<form method='POST' action='packages.php?ID=".$pkgid."'>\n";
+        $edit_cat.= "<input type='hidden' name='action' value='do_ChangeCategory'>";
+        $edit_cat.= $row['Location']." :: ";
+        $edit_cat.= "<select name='category_id'>\n";
+        foreach ($catarr as $id => $catname) {
+                $edit_cat.= "<option value='".$id."'";
+                if ($id == $row["CategoryID"]) {
+                    $edit_cat.="selected";
+                }
+                $edit_cat.=">".$catname."</option>";
+        }
+        $edit_cat.= "</select>&nbsp;<input type='submit' value='Change category'>";
+        $edit_cat.= "</form>";
+
+
 }
 else {
-	$edit_cat = $row['Category'];
+	$edit_cat = $row['Location']." :: ".$row['Category'];
 }
 
 if ($row["MaintainerUID"]) {
@@ -48,7 +60,7 @@ $submitted_time = ($row["SubmittedTS"] == 0) ? "(unknown)" : gmdate("r", intval(
 	</p>
 
 	<p>
-	<span class='f3'><?php echo $row['Location'] . ' :: ' . $edit_cat ?></span><br />
+	<span class='f3'><?php echo $edit_cat ?></span><br />
 	<span class='f3'><?php echo __('Maintainer') .': ' . $maintainer ?></span><br />
 	<span class='f3'><?php echo $votes ?></span>
 	</p>

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to