30d37c8b4b58dd0bc2ce821297b787ceb80a270f
[autoinstalls/wordpress.git] / wp-admin / categories.php
1 <?php
2 require_once('admin.php');
3
4 $title = __('Categories');
5 $parent_file = 'edit.php';
6 $list_js = true;
7
8 $wpvarstoreset = array('action','cat');
9 for ($i=0; $i<count($wpvarstoreset); $i += 1) {
10     $wpvar = $wpvarstoreset[$i];
11     if (!isset($$wpvar)) {
12         if (empty($_POST["$wpvar"])) {
13             if (empty($_GET["$wpvar"])) {
14                 $$wpvar = '';
15             } else {
16                 $$wpvar = $_GET["$wpvar"];
17             }
18         } else {
19             $$wpvar = $_POST["$wpvar"];
20         }
21     }
22 }
23
24 switch($action) {
25
26 case 'addcat':
27
28         check_admin_referer('add-category');
29
30         if ( !current_user_can('manage_categories') )
31                 die (__('Cheatin&#8217; uh?'));
32         
33         wp_insert_category($_POST);
34
35         wp_redirect('categories.php?message=1#addcat');
36 break;
37
38 case 'delete':
39         $cat_ID = (int) $_GET['cat_ID'];
40         check_admin_referer('delete-category_' .  $cat_ID);
41
42         if ( !current_user_can('manage_categories') )
43                 die (__('Cheatin&#8217; uh?'));
44
45         $cat_name = get_catname($cat_ID);
46
47         // Don't delete the default cats.
48         if ( $cat_ID == get_option('default_category') )
49                 die(sprintf(__("Can't delete the <strong>%s</strong> category: this is the default one"), $cat_name));
50
51         wp_delete_category($cat_ID);
52
53         wp_redirect('categories.php?message=2');
54
55 break;
56
57 case 'edit':
58
59     require_once ('admin-header.php');
60     $cat_ID = (int) $_GET['cat_ID'];
61     $category = get_category_to_edit($cat_ID);
62     ?>
63
64 <div class="wrap">
65  <h2><?php _e('Edit Category') ?></h2>
66  <form name="editcat" action="categories.php" method="post">
67           <?php wp_nonce_field('update-category_' .  $category->cat_ID); ?>
68           <table class="editform" width="100%" cellspacing="2" cellpadding="5">
69                 <tr>
70                   <th width="33%" scope="row"><?php _e('Category name:') ?></th>
71                   <td width="67%"><input name="cat_name" type="text" value="<?php echo wp_specialchars($category->cat_name); ?>" size="40" /> <input type="hidden" name="action" value="editedcat" />
72 <input type="hidden" name="cat_ID" value="<?php echo $category->cat_ID ?>" /></td>
73                 </tr>
74                 <tr>
75                         <th scope="row"><?php _e('Category slug:') ?></th>
76                         <td><input name="category_nicename" type="text" value="<?php echo wp_specialchars($category->category_nicename); ?>" size="40" /></td>
77                 </tr>
78                 <tr>
79                         <th scope="row"><?php _e('Category parent:') ?></th>
80                         <td>        
81                         <select name='category_parent'>
82           <option value='0' <?php if (!$category->category_parent) echo " selected='selected'"; ?>><?php _e('None') ?></option>
83           <?php wp_dropdown_cats($category->cat_ID, $category->category_parent); ?>
84           </select></td>
85                 </tr>
86                 <tr>
87                         <th scope="row"><?php _e('Description:') ?></th>
88                         <td><textarea name="category_description" rows="5" cols="50" style="width: 97%;"><?php echo wp_specialchars($category->category_description, 1); ?></textarea></td>
89                 </tr>
90                 </table>
91           <p class="submit"><input type="submit" name="submit" value="<?php _e('Edit category') ?> &raquo;" /></p>
92  </form>
93  <p><a href="categories.php"><?php _e('&laquo; Return to category list'); ?></a></p>
94 </div>
95     <?php
96
97 break;
98
99 case 'editedcat':
100         $cat_ID = (int) $_POST['cat_ID'];
101         check_admin_referer('update-category_' . $cat_ID);
102
103         if ( !current_user_can('manage_categories') )
104                 die (__('Cheatin&#8217; uh?'));
105         
106         wp_update_category($_POST);
107
108         wp_redirect('categories.php?message=3');
109 break;
110
111 default:
112
113 require_once ('admin-header.php');
114
115 $messages[1] = __('Category added.');
116 $messages[2] = __('Category deleted.');
117 $messages[3] = __('Category updated.');
118 ?>
119
120 <?php if (isset($_GET['message'])) : ?>
121 <div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div>
122 <?php endif; ?>
123
124 <div class="wrap">
125 <?php if ( current_user_can('manage_categories') ) : ?>
126         <h2><?php printf(__('Categories (<a href="%s">add new</a>)'), '#addcat') ?> </h2>
127 <?php else : ?>
128         <h2><?php _e('Categories') ?> </h2>
129 <?php endif; ?>
130 <table id="the-list-x" width="100%" cellpadding="3" cellspacing="3">
131         <tr>
132                 <th scope="col"><?php _e('ID') ?></th>
133         <th scope="col"><?php _e('Name') ?></th>
134         <th scope="col"><?php _e('Description') ?></th>
135         <th scope="col"><?php _e('# Posts') ?></th>
136         <th colspan="2"><?php _e('Action') ?></th>
137         </tr>
138 <?php
139 cat_rows();
140 ?>
141 </table>
142
143 <div id="ajax-response"></div>
144
145 </div>
146
147 <?php if ( current_user_can('manage_categories') ) : ?>
148 <div class="wrap">
149 <p><?php printf(__('<strong>Note:</strong><br />Deleting a category does not delete posts from that category, it will just set them back to the default category <strong>%s</strong>.'), get_catname(get_option('default_category'))) ?></p>
150 </div>
151
152 <div class="wrap">
153     <h2><?php _e('Add New Category') ?></h2>
154     <form name="addcat" id="addcat" action="categories.php" method="post">
155     <?php wp_nonce_field('add-category'); ?>
156         <p><?php _e('Name:') ?><br />
157         <input type="text" name="cat_name" value="" /></p>
158         <p><?php _e('Category parent:') ?><br />
159         <select name='category_parent' class='postform'>
160         <option value='0'><?php _e('None') ?></option>
161         <?php wp_dropdown_cats(0); ?>
162         </select></p>
163         <p><?php _e('Description: (optional)') ?> <br />
164         <textarea name="category_description" rows="5" cols="50" style="width: 97%;"></textarea></p>
165         <p class="submit"><input type="hidden" name="action" value="addcat" /><input type="submit" name="submit" value="<?php _e('Add Category &raquo;') ?>" /></p>
166     </form>
167 </div>
168 <?php endif; ?>
169
170 <?php
171 break;
172 }
173
174 include('admin-footer.php');
175 ?>