Wordpress 2.0.2
[autoinstalls/wordpress.git] / wp-admin / users.php
1 <?php
2 require_once('admin.php');
3 require_once( ABSPATH . WPINC . '/registration-functions.php');
4
5 $title = __('Users');
6 $parent_file = 'profile.php';
7         
8 $action = $_REQUEST['action'];
9 $update = '';
10
11 switch ($action) {
12
13 case 'promote':
14         check_admin_referer();
15
16         if (empty($_POST['users'])) {
17                 header('Location: users.php');
18         }
19
20         if ( !current_user_can('edit_users') )
21                 die(__('You can&#8217;t edit users.'));
22
23         $userids = $_POST['users'];
24         $update = 'promote';
25         foreach($userids as $id) {
26                 // The new role of the current user must also have edit_users caps
27                 if($id == $current_user->id && !$wp_roles->role_objects[$_POST['new_role']]->has_cap('edit_users')) {
28                         $update = 'err_admin_role';
29                         continue;
30                 }
31
32                 $user = new WP_User($id);
33                 $user->set_role($_POST['new_role']);
34         }
35                 
36         header('Location: users.php?update=' . $update);
37
38 break;
39
40 case 'dodelete':
41
42         check_admin_referer();
43
44         if ( empty($_POST['users']) ) {
45                 header('Location: users.php');
46         }
47
48         if ( !current_user_can('edit_users') )
49                 die(__('You can&#8217;t delete users.'));
50
51         $userids = $_POST['users'];
52         
53         $update = 'del';
54         foreach ($userids as $id) {
55                 if($id == $current_user->id) {
56                         $update = 'err_admin_del';
57                         continue;
58                 }
59                 switch($_POST['delete_option']) {
60                 case 'delete':
61                         wp_delete_user($id);
62                         break;
63                 case 'reassign':
64                         wp_delete_user($id, $_POST['reassign_user']);
65                         break;
66                 }
67         }
68
69         header('Location: users.php?update=' . $update);
70
71 break;
72
73 case 'delete':
74
75         check_admin_referer();
76
77         if (empty($_POST['users'])) {
78                 header('Location: users.php');
79         }
80
81         if ( !current_user_can('edit_users') )
82                 $error['edit_users'] = __('You can&#8217;t delete users.');
83
84         $userids = $_POST['users'];
85
86         include ('admin-header.php');
87 ?>
88 <form action="" method="post" name="updateusers" id="updateusers">
89 <div class="wrap">
90 <h2><?php _e('Delete Users'); ?></h2>
91 <p><?php _e('You have specified these users for deletion:'); ?></p>
92 <ul>
93 <?php
94         $go_delete = false;
95         foreach ($userids as $id) {
96                 $user = new WP_User($id);
97                 if ($id == $current_user->id) {
98                         echo "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\n";
99                 } else {
100                         echo "<li><input type=\"hidden\" name=\"users[]\" value=\"{$id}\" />" . sprintf(__('ID #%1s: %2s'), $id, $user->user_login) . "</li>\n";
101                         $go_delete = true;
102                 }
103         }
104         $all_logins = $wpdb->get_results("SELECT ID, user_login FROM $wpdb->users ORDER BY user_login");
105         $user_dropdown = '<select name="reassign_user">';
106         foreach ($all_logins as $login) {
107                 if ( $login->ID == $current_user->id || !in_array($login->ID, $userids) ) {
108                         $user_dropdown .= "<option value=\"{$login->ID}\">{$login->user_login}</option>";
109                 }
110         }
111         $user_dropdown .= '</select>';
112         ?>
113         </ul>
114 <?php if($go_delete) : ?>
115         <p><?php _e('What should be done with posts and links owned by this user?'); ?></p>
116         <ul style="list-style:none;">
117                 <li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" checked="checked" />
118                 <?php _e('Delete all posts and links.'); ?></label></li>
119                 <li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
120                 <?php echo '<label for="delete_option1">'.__('Attribute all posts and links to:')."</label> $user_dropdown"; ?></li>
121         </ul>
122         <input type="hidden" name="action" value="dodelete" />
123         <p class="submit"><input type="submit" name="submit" value="<?php _e('Confirm Deletion'); ?>" /></p>
124 <?php else : ?>
125         <p><?php _e('There are no valid users selected for deletion.'); ?></p>
126 <?php endif; ?>
127 </div>
128 </form>
129 <?php
130
131 break;
132
133 case 'adduser':
134         check_admin_referer();
135         
136         $errors = add_user();
137         
138         if(count($errors) == 0) {
139                 header('Location: users.php?update=add');
140                 die();
141         }
142
143 default:
144         
145         include ('admin-header.php');
146         
147         $userids = $wpdb->get_col("SELECT ID FROM $wpdb->users;");
148         
149         foreach($userids as $userid) {
150                 $tmp_user = new WP_User($userid);
151                 $roles = $tmp_user->roles;
152                 $role = array_shift($roles);
153                 $roleclasses[$role][$tmp_user->user_login] = $tmp_user;
154         }       
155         
156         ?>
157
158         <?php 
159         if (isset($_GET['update'])) : 
160                 switch($_GET['update']) {
161                 case 'del':
162                 ?>
163                         <div id="message" class="updated fade"><p><?php _e('User deleted.'); ?></p></div>
164                 <?php
165                         break;
166                 case 'add':
167                 ?>
168                         <div id="message" class="updated fade"><p><?php _e('New user created.'); ?></p></div>
169                 <?php
170                         break;
171                 case 'promote':
172                 ?>
173                         <div id="message" class="updated fade"><p><?php _e('Changed roles.'); ?></p></div>
174                 <?php
175                         break;
176                 case 'err_admin_role':
177                 ?>
178                         <div id="message" class="error"><p><?php _e("The current user's role must have user editing capabilities."); ?></p></div>
179                         <div id="message" class="updated fade"><p><?php _e('Other user roles have been changed.'); ?></p></div>
180                 <?php
181                         break;
182                 case 'err_admin_del':
183                 ?>
184                         <div id="message" class="error"><p><?php _e("You can't delete the current user."); ?></p></div>
185                         <div id="message" class="updated fade"><p><?php _e('Other users have been deleted.'); ?></p></div>
186                 <?php
187                         break;
188                 }
189         endif; 
190         if ( isset($errors) ) : ?>
191         <div class="error">
192                 <ul>
193                 <?php
194                 foreach($errors as $error) echo "<li>$error</li>";
195                 ?>
196                 </ul>
197         </div>
198         <?php 
199         endif;
200         ?>
201         
202 <form action="" method="post" name="updateusers" id="updateusers">
203 <div class="wrap">
204         <h2><?php _e('User List by Role'); ?></h2>
205   <table cellpadding="3" cellspacing="3" width="100%">
206         <?php
207         foreach($roleclasses as $role => $roleclass) {
208                 ksort($roleclass);
209                 ?>
210
211         <tr>
212         <th colspan="8" align="left">
213   <h3><?php echo $wp_roles->role_names[$role]; ?></h3>
214   </th></tr>
215
216         <tr>
217         <th><?php _e('ID') ?></th>
218         <th><?php _e('Username') ?></th>
219         <th><?php _e('Name') ?></th>
220         <th><?php _e('E-mail') ?></th>
221         <th><?php _e('Website') ?></th>
222         <th><?php _e('Posts') ?></th>
223         <th>&nbsp;</th>
224         </tr>
225         <?php
226         $style = '';
227         foreach ($roleclass as $user_object) {
228                 $email = $user_object->user_email;
229                 $url = $user_object->user_url;
230                 $short_url = str_replace('http://', '', $url);
231                 $short_url = str_replace('www.', '', $short_url);
232                 if ('/' == substr($short_url, -1))
233                         $short_url = substr($short_url, 0, -1);
234                 if (strlen($short_url) > 35)
235                 $short_url =  substr($short_url, 0, 32).'...';
236                 $style = ('class="alternate"' == $style) ? '' : 'class="alternate"';
237                 $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$user_object->ID' and post_status = 'publish'");
238                 if (0 < $numposts) $numposts = "<a href='edit.php?author=$user_object->ID' title='" . __('View posts') . "'>$numposts</a>";
239                 echo "
240 <tr $style>
241         <td><input type='checkbox' name='users[]' id='user_{$user_object->ID}' value='{$user_object->ID}' /> <label for='user_{$user_object->ID}'>{$user_object->ID}</label></td>
242         <td><label for='user_{$user_object->ID}'><strong>$user_object->user_login</strong></label></td>
243         <td><label for='user_{$user_object->ID}'>$user_object->first_name $user_object->last_name</label></td>
244         <td><a href='mailto:$email' title='" . sprintf(__('e-mail: %s'), $email) . "'>$email</a></td>
245         <td><a href='$url' title='website: $url'>$short_url</a></td>";
246         echo "<td align='right'>$numposts</td>";
247         echo '<td>';
248         if (current_user_can('edit_users'))
249                 echo "<a href='user-edit.php?user_id=$user_object->ID' class='edit'>".__('Edit')."</a>";
250         echo '</td>';
251         echo '</tr>';
252         }
253         
254         ?>
255         
256
257 <?php
258         }
259 ?>
260   </table>
261
262
263         <h2><?php _e('Update Users'); ?></h2>
264 <?php
265 $role_select = '<select name="new_role">';
266 foreach($wp_roles->role_names as $role => $name) {
267         $role_select .= "<option value=\"{$role}\">{$name}</option>";
268 }
269 $role_select .= '</select>';
270 ?>  
271   <ul style="list-style:none;">
272         <li><input type="radio" name="action" id="action0" value="delete" /> <label for="action0"><?php _e('Delete checked users.'); ?></label></li>
273         <li><input type="radio" name="action" id="action1" value="promote" /> <?php echo '<label for="action1">'.__('Set the Role of checked users to:')."</label> $role_select"; ?></li>
274   </ul>
275         <p class="submit"><input type="submit" value="<?php _e('Update &raquo;'); ?>" /></p>
276 </div>
277 </form>
278
279 <div class="wrap">
280 <h2><?php _e('Add New User') ?></h2>
281 <?php echo '<p>'.sprintf(__('Users can <a href="%1$s">register themselves</a> or you can manually create users here.'), get_settings('siteurl').'/wp-register.php').'</p>'; ?>
282 <form action="" method="post" name="adduser" id="adduser">
283   <table class="editform" width="100%" cellspacing="2" cellpadding="5">
284     <tr>
285       <th scope="row" width="33%"><?php _e('Nickname') ?>
286       <input name="action" type="hidden" id="action" value="adduser" /></th>
287       <td width="66%"><input name="user_login" type="text" id="user_login" value="<?php echo $new_user_login; ?>" /></td>
288     </tr>
289     <tr>
290       <th scope="row"><?php _e('First Name') ?> </th>
291       <td><input name="first_name" type="text" id="first_name" value="<?php echo $new_user_firstname; ?>" /></td>
292     </tr>
293     <tr>
294       <th scope="row"><?php _e('Last Name') ?> </th>
295       <td><input name="last_name" type="text" id="last_name" value="<?php echo $new_user_lastname; ?>" /></td>
296     </tr>
297     <tr>
298       <th scope="row"><?php _e('E-mail') ?></th>
299       <td><input name="email" type="text" id="email" value="<?php echo $new_user_email; ?>" /></td>
300     </tr>
301     <tr>
302       <th scope="row"><?php _e('Website') ?></th>
303       <td><input name="url" type="text" id="url" value="<?php echo $new_user_uri; ?>" /></td>
304     </tr>
305 <?php
306 $show_password_fields = apply_filters('show_password_fields', true);
307 if ( $show_password_fields ) :
308 ?>
309     <tr>
310       <th scope="row"><?php _e('Password (twice)') ?> </th>
311       <td><input name="pass1" type="password" id="pass1" />
312       <br />
313       <input name="pass2" type="password" id="pass2" /></td>
314     </tr>
315 <?php endif; ?>
316   </table>
317   <p class="submit">
318     <input name="adduser" type="submit" id="adduser" value="<?php _e('Add User') ?> &raquo;" />
319   </p>
320   </form>
321 </div>
322         <?php
323
324 break;
325 }
326
327 include('admin-footer.php');
328 ?>