Henry Lyne (henrylyne) wrote in changelog,
Henry Lyne
henrylyne
changelog

[livejournal] r15455: New page that allows admins to remove ca...

Committer: henrylyne
New page that allows admins to remove categories.

A   trunk/htdocs/admin/browse/remove_category.bml
Added: trunk/htdocs/admin/browse/remove_category.bml
===================================================================
--- trunk/htdocs/admin/browse/remove_category.bml	                        (rev 0)
+++ trunk/htdocs/admin/browse/remove_category.bml	2009-07-09 17:18:46 UTC (rev 15455)
@@ -0,0 +1,88 @@
+<?page
+body<=
+<?_code
+{
+    use strict;
+    use vars qw(%GET %POST $title $headextra @errors @warnings);
+    use Class::Autouse qw( LJ::Browse );
+
+    my $remote = LJ::get_remote();
+
+    return "<?needlogin?>"
+        unless $remote;
+
+    return "You are not allowed to view this page"
+        unless LJ::check_priv($remote, 'siteadmin', 'category_admin') || $LJ::IS_DEV_SERVER;
+
+    $title = "Remove Category";
+    my $ret = "";
+
+    my $caturl;
+
+    if (LJ::did_post() and $POST{'remove'}) {
+        $caturl = $POST{'caturl'};
+
+        push @errors, "Invalid form submission" unless LJ::check_form_auth();
+        {
+            # Check for required data
+            unless ($caturl) {
+                push @errors, "Please select a category to remove";
+                next;
+            }
+
+            # Has a valid category been chosen
+            my $category = LJ::Browse->load_by_url("/browse" . $caturl);
+            push @errors, "Invalid category" unless $category;
+
+            my @children = $category->children;
+            # Does the category have sub-categories
+            push @errors, "Cannot remove category while sub-categories exist"
+                if ($category && @children);
+
+            next if @errors;
+
+            # Remove category
+            if ($category->delete) {
+                $ret .= "<span class='super notice'>Category removed.</span>";
+            } else {
+                $ret .= "<span class='super notice'>Category not removed.</span>";
+            }
+        }
+    }
+
+    $headextra = "<style>table td.label { text-align: right; vertical-align: top;}</style>";
+
+    $ret .= "<form method='POST'>\n";
+    $ret .= LJ::form_auth();
+
+    # Get the full list of categories
+    my @categories = LJ::Browse->load_all;
+    # Get the unique URI for each
+    my @caturls = map { $_->uri, $_->uri } @categories;
+    @caturls = sort { $a cmp $b } @caturls;
+
+    $ret .= "<p>Remove Category:<br />";
+    $ret .= LJ::html_select({
+                name => 'caturl',
+                selected => $caturl },
+                { text => 'Select Category',
+                value => '' },
+                @caturls
+            );
+    $ret .= "</p>\n";
+
+    $ret .= "</table></p>\n";
+
+    $ret .= "<p>" . LJ::html_submit('remove', 'Remove') . "</p>";
+
+    $ret .= "</form>";
+
+    return "<body>$ret</body>";
+}
+_code?>
+<=body
+title=><?_code return $title; _code?>
+head<=
+<?_code return $headextra; _code?>
+<=head
+page?>

Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments