Wordpress 2.0.4-scripts
[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('bulk-users');
15
16         if (empty($_POST['users'])) {
17                 wp_redirect('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         wp_redirect('users.php?update=' . $update);
37
38 break;
39
40 case 'dodelete':
41
42         check_admin_referer('delete-users');
43
44         if ( empty($_POST['users']) ) {
45                 wp_redirect('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         wp_redirect('users.php?update=' . $update);
70
71 break;
72
73 case 'delete':
74
75         check_admin_referer('bulk-users');
76
77         if ( empty($_POST['users']) )
78                 wp_redirect('users.php');
79
80         if ( !current_user_can('edit_users') )
81                 $error['edit_users'] = __('You can&#8217;t delete users.');
82
83         $userids = $_POST['users'];
84
85         include ('admin-header.php');
86 ?>
87 <form action="" method="post" name="updateusers" id="updateusers">
88 <?php wp_nonce_field('delete-users') ?>
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('add-user');
135         
136         $errors = add_user();
137         
138         if(count($errors) == 0) {
139                 wp_redirect('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 <?php wp_nonce_field('bulk-users') ?>
204 <div class="wrap">
205         <h2><?php _e('User List by Role'); ?></h2>
206   <table cellpadding="3" cellspacing="3" width="100%">
207         <?php
208         foreach($roleclasses as $role => $roleclass) {
209                 ksort($roleclass);
210                 ?>
211
212         <tr>
213         <th colspan="8" align="left">
214   <h3><?php echo $wp_roles->role_names[$role]; ?></h3>
215   </th></tr>
216
217         <tr>
218         <th><?php _e('ID') ?></th>
219         <th><?php _e('Username') ?></th>
220         <th><?php _e('Name') ?></th>
221         <th><?php _e('E-mail') ?></th>
222         <th><?php _e('Website') ?></th>
223         <th><?php _e('Posts') ?></th>
224         <th>&nbsp;</th>
225         </tr>
226         <?php
227         $style = '';
228         foreach ($roleclass as $user_object) {
229                 $email = $user_object->user_email;
230                 $url = $user_object->user_url;
231                 $short_url = str_replace('http://', '', $url);
232                 $short_url = str_replace('www.', '', $short_url);
233                 if ('/' == substr($short_url, -1))
234                         $short_url = substr($short_url, 0, -1);
235                 if (strlen($short_url) > 35)
236                 $short_url =  substr($short_url, 0, 32).'...';
237                 $style = ('class="alternate"' == $style) ? '' : 'class="alternate"';
238                 $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = '$user_object->ID' and post_status = 'publish'");
239                 if (0 < $numposts) $numposts = "<a href='edit.php?author=$user_object->ID' title='" . __('View posts') . "'>$numposts</a>";
240                 echo "
241 <tr $style>
242         <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>
243         <td><label for='user_{$user_object->ID}'><strong>$user_object->user_login</strong></label></td>
244         <td><label for='user_{$user_object->ID}'>$user_object->first_name $user_object->last_name</label></td>
245         <td><a href='mailto:$email' title='" . sprintf(__('e-mail: %s'), $email) . "'>$email</a></td>
246         <td><a href='$url' title='website: $url'>$short_url</a></td>";
247         echo "<td align='right'>$numposts</td>";
248         echo '<td>';
249         if (current_user_can('edit_users'))
250                 echo "<a href='user-edit.php?user_id=$user_object->ID' class='edit'>".__('Edit')."</a>";
251         echo '</td>';
252         echo '</tr>';
253         }
254         
255         ?>
256         
257
258 <?php
259         }
260 ?>
261   </table>
262
263
264         <h2><?php _e('Update Users'); ?></h2>
265 <?php
266 $role_select = '<select name="new_role">';
267 foreach($wp_roles->role_names as $role => $name) {
268         $role_select .= "<option value=\"{$role}\">{$name}</option>";
269 }
270 $role_select .= '</select>';
271 ?>  
272   <ul style="list-style:none;">
273         <li><input type="radio" name="action" id="action0" value="delete" /> <label for="action0"><?php _e('Delete checked users.'); ?></label></li>
274         <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>
275   </ul>
276         <p class="submit"><input type="submit" value="<?php _e('Update &raquo;'); ?>" /></p>
277 </div>
278 </form>
279
280 <div class="wrap">
281 <h2><?php _e('Add New User') ?></h2>
282 <?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>'; ?>
283 <form action="" method="post" name="adduser" id="adduser">
284   <?php wp_nonce_field('add-user') ?>
285   <table class="editform" width="100%" cellspacing="2" cellpadding="5">
286     <tr>
287       <th scope="row" width="33%"><?php _e('Nickname') ?>
288       <input name="action" type="hidden" id="action" value="adduser" /></th>
289       <td width="66%"><input name="user_login" type="text" id="user_login" value="<?php echo $new_user_login; ?>" /></td>
290     </tr>
291     <tr>
292       <th scope="row"><?php _e('First Name') ?> </th>
293       <td><input name="first_name" type="text" id="first_name" value="<?php echo $new_user_firstname; ?>" /></td>
294     </tr>
295     <tr>
296       <th scope="row"><?php _e('Last Name') ?> </th>
297       <td><input name="last_name" type="text" id="last_name" value="<?php echo $new_user_lastname; ?>" /></td>
298     </tr>
299     <tr>
300       <th scope="row"><?php _e('E-mail') ?></th>
301       <td><input name="email" type="text" id="email" value="<?php echo $new_user_email; ?>" /></td>
302     </tr>
303     <tr>
304       <th scope="row"><?php _e('Website') ?></th>
305       <td><input name="url" type="text" id="url" value="<?php echo $new_user_uri; ?>" /></td>
306     </tr>
307 <?php
308 $show_password_fields = apply_filters('show_password_fields', true);
309 if ( $show_password_fields ) :
310 ?>
311     <tr>
312       <th scope="row"><?php _e('Password (twice)') ?> </th>
313       <td><input name="pass1" type="password" id="pass1" />
314       <br />
315       <input name="pass2" type="password" id="pass2" /></td>
316     </tr>
317 <?php endif; ?>
318   </table>
319   <p class="submit">
320     <input name="adduser" type="submit" id="adduser" value="<?php _e('Add User') ?> &raquo;" />
321   </p>
322   </form>
323 </div>
324         <?php
325
326 break;
327 }
328
329 include('admin-footer.php');
330 ?>