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