1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * Admin page callback file for the user module. |
---|
6 | */ |
---|
7 | |
---|
8 | /** |
---|
9 | * Page callback: Generates the appropriate user administration form. |
---|
10 | * |
---|
11 | * This function generates the user registration, multiple user cancellation, |
---|
12 | * or filtered user list admin form, depending on the argument and the POST |
---|
13 | * form values. |
---|
14 | * |
---|
15 | * @param string $callback_arg |
---|
16 | * (optional) Indicates which form to build. Defaults to '', which will |
---|
17 | * trigger the user filter form. If the POST value 'op' is present, this |
---|
18 | * function uses that value as the callback argument. |
---|
19 | * |
---|
20 | * @return string |
---|
21 | * A renderable form array for the respective request. |
---|
22 | */ |
---|
23 | function user_admin($callback_arg = '') { |
---|
24 | $op = isset($_POST['op']) ? $_POST['op'] : $callback_arg; |
---|
25 | |
---|
26 | switch ($op) { |
---|
27 | case t('Create new account'): |
---|
28 | case 'create': |
---|
29 | $output = drupal_get_form('user_register'); |
---|
30 | break; |
---|
31 | default: |
---|
32 | if (!empty($_POST['accounts']) && isset($_POST['operation']) && ($_POST['operation'] == 'delete')) { |
---|
33 | $output = drupal_get_form('user_multiple_delete_confirm'); |
---|
34 | } |
---|
35 | else { |
---|
36 | $output = drupal_get_form('user_filter_form'); |
---|
37 | $output .= drupal_get_form('user_admin_account'); |
---|
38 | } |
---|
39 | } |
---|
40 | return $output; |
---|
41 | } |
---|
42 | |
---|
43 | /** |
---|
44 | * Form builder; Return form for user administration filters. |
---|
45 | * |
---|
46 | * @ingroup forms |
---|
47 | * @see user_filter_form_submit() |
---|
48 | */ |
---|
49 | function user_filter_form() { |
---|
50 | $session = &$_SESSION['user_overview_filter']; |
---|
51 | $session = is_array($session) ? $session : array(); |
---|
52 | $filters = user_filters(); |
---|
53 | |
---|
54 | $i = 0; |
---|
55 | $form['filters'] = array( |
---|
56 | '#type' => 'fieldset', |
---|
57 | '#title' => t('Show only users where'), |
---|
58 | '#theme' => 'user_filters', |
---|
59 | ); |
---|
60 | foreach ($session as $filter) { |
---|
61 | list($type, $value) = $filter; |
---|
62 | // Merge an array of arrays into one if necessary. |
---|
63 | $options = $type == 'permission' ? call_user_func_array('array_merge', $filters[$type]['options']) : $filters[$type]['options']; |
---|
64 | $params = array('%property' => $filters[$type]['title'] , '%value' => $options[$value]); |
---|
65 | if ($i++ > 0) { |
---|
66 | $form['filters']['current'][] = array('#value' => t('<em>and</em> where <strong>%property</strong> is <strong>%value</strong>', $params)); |
---|
67 | } |
---|
68 | else { |
---|
69 | $form['filters']['current'][] = array('#value' => t('<strong>%property</strong> is <strong>%value</strong>', $params)); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | foreach ($filters as $key => $filter) { |
---|
74 | $names[$key] = $filter['title']; |
---|
75 | $form['filters']['status'][$key] = array( |
---|
76 | '#type' => 'select', |
---|
77 | '#options' => $filter['options'], |
---|
78 | ); |
---|
79 | } |
---|
80 | |
---|
81 | $form['filters']['filter'] = array( |
---|
82 | '#type' => 'radios', |
---|
83 | '#options' => $names, |
---|
84 | ); |
---|
85 | $form['filters']['buttons']['submit'] = array( |
---|
86 | '#type' => 'submit', |
---|
87 | '#value' => (count($session) ? t('Refine') : t('Filter')), |
---|
88 | ); |
---|
89 | if (count($session)) { |
---|
90 | $form['filters']['buttons']['undo'] = array( |
---|
91 | '#type' => 'submit', |
---|
92 | '#value' => t('Undo'), |
---|
93 | ); |
---|
94 | $form['filters']['buttons']['reset'] = array( |
---|
95 | '#type' => 'submit', |
---|
96 | '#value' => t('Reset'), |
---|
97 | ); |
---|
98 | } |
---|
99 | |
---|
100 | drupal_add_js('misc/form.js', 'core'); |
---|
101 | |
---|
102 | return $form; |
---|
103 | } |
---|
104 | |
---|
105 | /** |
---|
106 | * Process result from user administration filter form. |
---|
107 | */ |
---|
108 | function user_filter_form_submit($form, &$form_state) { |
---|
109 | $op = $form_state['values']['op']; |
---|
110 | $filters = user_filters(); |
---|
111 | switch ($op) { |
---|
112 | case t('Filter'): case t('Refine'): |
---|
113 | if (isset($form_state['values']['filter'])) { |
---|
114 | $filter = $form_state['values']['filter']; |
---|
115 | // Merge an array of arrays into one if necessary. |
---|
116 | $options = $filter == 'permission' ? call_user_func_array('array_merge', $filters[$filter]['options']) : $filters[$filter]['options']; |
---|
117 | if (isset($options[$form_state['values'][$filter]])) { |
---|
118 | $_SESSION['user_overview_filter'][] = array($filter, $form_state['values'][$filter]); |
---|
119 | } |
---|
120 | } |
---|
121 | break; |
---|
122 | case t('Undo'): |
---|
123 | array_pop($_SESSION['user_overview_filter']); |
---|
124 | break; |
---|
125 | case t('Reset'): |
---|
126 | $_SESSION['user_overview_filter'] = array(); |
---|
127 | break; |
---|
128 | case t('Update'): |
---|
129 | return; |
---|
130 | } |
---|
131 | |
---|
132 | $form_state['redirect'] = 'admin/user/user'; |
---|
133 | return; |
---|
134 | } |
---|
135 | |
---|
136 | /** |
---|
137 | * Form builder; User administration page. |
---|
138 | * |
---|
139 | * @ingroup forms |
---|
140 | * @see user_admin_account_validate() |
---|
141 | * @see user_admin_account_submit() |
---|
142 | */ |
---|
143 | function user_admin_account() { |
---|
144 | $filter = user_build_filter_query(); |
---|
145 | |
---|
146 | $header = array( |
---|
147 | array(), |
---|
148 | array('data' => t('Username'), 'field' => 'u.name'), |
---|
149 | array('data' => t('Status'), 'field' => 'u.status'), |
---|
150 | t('Roles'), |
---|
151 | array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'), |
---|
152 | array('data' => t('Last access'), 'field' => 'u.access'), |
---|
153 | t('Operations') |
---|
154 | ); |
---|
155 | |
---|
156 | if ($filter['join'] != "") { |
---|
157 | $sql = 'SELECT DISTINCT u.uid, u.name, u.status, u.created, u.access FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid '. $filter['join'] .' WHERE u.uid != 0 '. $filter['where']; |
---|
158 | $query_count = 'SELECT COUNT(DISTINCT u.uid) FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid '. $filter['join'] .' WHERE u.uid != 0 '. $filter['where']; |
---|
159 | } |
---|
160 | else { |
---|
161 | $sql = 'SELECT u.uid, u.name, u.status, u.created, u.access FROM {users} u WHERE u.uid != 0 '. $filter['where']; |
---|
162 | $query_count = 'SELECT COUNT(u.uid) FROM {users} u WHERE u.uid != 0 '. $filter['where']; |
---|
163 | } |
---|
164 | |
---|
165 | |
---|
166 | $sql .= tablesort_sql($header); |
---|
167 | |
---|
168 | $result = pager_query($sql, 50, 0, $query_count, $filter['args']); |
---|
169 | |
---|
170 | $form['options'] = array( |
---|
171 | '#type' => 'fieldset', |
---|
172 | '#title' => t('Update options'), |
---|
173 | '#prefix' => '<div class="container-inline">', |
---|
174 | '#suffix' => '</div>', |
---|
175 | ); |
---|
176 | $options = array(); |
---|
177 | foreach (module_invoke_all('user_operations') as $operation => $array) { |
---|
178 | $options[$operation] = $array['label']; |
---|
179 | } |
---|
180 | $form['options']['operation'] = array( |
---|
181 | '#type' => 'select', |
---|
182 | '#options' => $options, |
---|
183 | '#default_value' => 'unblock', |
---|
184 | ); |
---|
185 | $form['options']['submit'] = array( |
---|
186 | '#type' => 'submit', |
---|
187 | '#value' => t('Update'), |
---|
188 | ); |
---|
189 | |
---|
190 | $destination = drupal_get_destination(); |
---|
191 | |
---|
192 | $status = array(t('blocked'), t('active')); |
---|
193 | $roles = user_roles(TRUE); |
---|
194 | $accounts = array(); |
---|
195 | while ($account = db_fetch_object($result)) { |
---|
196 | $accounts[$account->uid] = ''; |
---|
197 | $form['name'][$account->uid] = array('#value' => theme('username', $account)); |
---|
198 | $form['status'][$account->uid] = array('#value' => $status[$account->status]); |
---|
199 | $users_roles = array(); |
---|
200 | $roles_result = db_query('SELECT rid FROM {users_roles} WHERE uid = %d', $account->uid); |
---|
201 | while ($user_role = db_fetch_object($roles_result)) { |
---|
202 | $users_roles[] = $roles[$user_role->rid]; |
---|
203 | } |
---|
204 | asort($users_roles); |
---|
205 | $form['roles'][$account->uid][0] = array('#value' => theme('item_list', $users_roles)); |
---|
206 | $form['member_for'][$account->uid] = array('#value' => format_interval(time() - $account->created)); |
---|
207 | $form['last_access'][$account->uid] = array('#value' => $account->access ? t('@time ago', array('@time' => format_interval(time() - $account->access))) : t('never')); |
---|
208 | $form['operations'][$account->uid] = array('#value' => l(t('edit'), "user/$account->uid/edit", array('query' => $destination))); |
---|
209 | } |
---|
210 | $form['accounts'] = array( |
---|
211 | '#type' => 'checkboxes', |
---|
212 | '#options' => $accounts |
---|
213 | ); |
---|
214 | $form['pager'] = array('#value' => theme('pager', NULL, 50, 0)); |
---|
215 | |
---|
216 | return $form; |
---|
217 | } |
---|
218 | |
---|
219 | /** |
---|
220 | * Submit the user administration update form. |
---|
221 | */ |
---|
222 | function user_admin_account_submit($form, &$form_state) { |
---|
223 | $operations = module_invoke_all('user_operations', $form_state); |
---|
224 | $operation = $operations[$form_state['values']['operation']]; |
---|
225 | // Filter out unchecked accounts. |
---|
226 | $accounts = array_filter($form_state['values']['accounts']); |
---|
227 | if ($function = $operation['callback']) { |
---|
228 | // Add in callback arguments if present. |
---|
229 | if (isset($operation['callback arguments'])) { |
---|
230 | $args = array_merge(array($accounts), $operation['callback arguments']); |
---|
231 | } |
---|
232 | else { |
---|
233 | $args = array($accounts); |
---|
234 | } |
---|
235 | call_user_func_array($function, $args); |
---|
236 | |
---|
237 | drupal_set_message(t('The update has been performed.')); |
---|
238 | } |
---|
239 | } |
---|
240 | |
---|
241 | function user_admin_account_validate($form, &$form_state) { |
---|
242 | $form_state['values']['accounts'] = array_filter($form_state['values']['accounts']); |
---|
243 | if (count($form_state['values']['accounts']) == 0) { |
---|
244 | form_set_error('', t('No users selected.')); |
---|
245 | } |
---|
246 | } |
---|
247 | |
---|
248 | /** |
---|
249 | * Form builder; Configure user settings for this site. |
---|
250 | * |
---|
251 | * @ingroup forms |
---|
252 | * @see system_settings_form() |
---|
253 | */ |
---|
254 | function user_admin_settings() { |
---|
255 | // User registration settings. |
---|
256 | $form['registration'] = array('#type' => 'fieldset', '#title' => t('User registration settings')); |
---|
257 | $form['registration']['user_register'] = array('#type' => 'radios', '#title' => t('Public registrations'), '#default_value' => variable_get('user_register', 1), '#options' => array(t('Only site administrators can create new user accounts.'), t('Visitors can create accounts and no administrator approval is required.'), t('Visitors can create accounts but administrator approval is required.'))); |
---|
258 | $form['registration']['user_email_verification'] = array('#type' => 'checkbox', '#title' => t('Require e-mail verification when a visitor creates an account'), '#default_value' => variable_get('user_email_verification', TRUE), '#description' => t('If this box is checked, new users will be required to validate their e-mail address prior to logging into the site, and will be assigned a system-generated password. With it unchecked, users will be logged in immediately upon registering, and may select their own passwords during registration.')); |
---|
259 | $form['registration']['user_registration_help'] = array('#type' => 'textarea', '#title' => t('User registration guidelines'), '#default_value' => variable_get('user_registration_help', ''), '#description' => t('This text is displayed at the top of the user registration form and is useful for helping or instructing your users.')); |
---|
260 | |
---|
261 | // User e-mail settings. |
---|
262 | $form['email'] = array( |
---|
263 | '#type' => 'fieldset', |
---|
264 | '#title' => t('User e-mail settings'), |
---|
265 | '#description' => t('Drupal sends emails whenever new users register on your site, and optionally, may also notify users after other account actions. Using a simple set of content templates, notification e-mails can be customized to fit the specific needs of your site.'), |
---|
266 | ); |
---|
267 | // These email tokens are shared for all settings, so just define |
---|
268 | // the list once to help ensure they stay in sync. |
---|
269 | $email_token_help = t('Available variables are:') .' !username, !site, !password, !uri, !uri_brief, !mailto, !date, !login_uri, !edit_uri, !login_url.'; |
---|
270 | |
---|
271 | $form['email']['admin_created'] = array( |
---|
272 | '#type' => 'fieldset', |
---|
273 | '#title' => t('Welcome, new user created by administrator'), |
---|
274 | '#collapsible' => TRUE, |
---|
275 | '#collapsed' => (variable_get('user_register', 1) != 0), |
---|
276 | '#description' => t('Customize welcome e-mail messages sent to new member accounts created by an administrator.') .' '. $email_token_help, |
---|
277 | ); |
---|
278 | $form['email']['admin_created']['user_mail_register_admin_created_subject'] = array( |
---|
279 | '#type' => 'textfield', |
---|
280 | '#title' => t('Subject'), |
---|
281 | '#default_value' => _user_mail_text('register_admin_created_subject'), |
---|
282 | '#maxlength' => 180, |
---|
283 | ); |
---|
284 | $form['email']['admin_created']['user_mail_register_admin_created_body'] = array( |
---|
285 | '#type' => 'textarea', |
---|
286 | '#title' => t('Body'), |
---|
287 | '#default_value' => _user_mail_text('register_admin_created_body'), |
---|
288 | '#rows' => 15, |
---|
289 | ); |
---|
290 | |
---|
291 | $form['email']['no_approval_required'] = array( |
---|
292 | '#type' => 'fieldset', |
---|
293 | '#title' => t('Welcome, no approval required'), |
---|
294 | '#collapsible' => TRUE, |
---|
295 | '#collapsed' => (variable_get('user_register', 1) != 1), |
---|
296 | '#description' => t('Customize welcome e-mail messages sent to new members upon registering, when no administrator approval is required.') .' '. $email_token_help |
---|
297 | ); |
---|
298 | $form['email']['no_approval_required']['user_mail_register_no_approval_required_subject'] = array( |
---|
299 | '#type' => 'textfield', |
---|
300 | '#title' => t('Subject'), |
---|
301 | '#default_value' => _user_mail_text('register_no_approval_required_subject'), |
---|
302 | '#maxlength' => 180, |
---|
303 | ); |
---|
304 | $form['email']['no_approval_required']['user_mail_register_no_approval_required_body'] = array( |
---|
305 | '#type' => 'textarea', |
---|
306 | '#title' => t('Body'), |
---|
307 | '#default_value' => _user_mail_text('register_no_approval_required_body'), |
---|
308 | '#rows' => 15, |
---|
309 | ); |
---|
310 | |
---|
311 | $form['email']['pending_approval'] = array( |
---|
312 | '#type' => 'fieldset', |
---|
313 | '#title' => t('Welcome, awaiting administrator approval'), |
---|
314 | '#collapsible' => TRUE, |
---|
315 | '#collapsed' => (variable_get('user_register', 1) != 2), |
---|
316 | '#description' => t('Customize welcome e-mail messages sent to new members upon registering, when administrative approval is required.') .' '. $email_token_help, |
---|
317 | ); |
---|
318 | $form['email']['pending_approval']['user_mail_register_pending_approval_subject'] = array( |
---|
319 | '#type' => 'textfield', |
---|
320 | '#title' => t('Subject'), |
---|
321 | '#default_value' => _user_mail_text('register_pending_approval_subject'), |
---|
322 | '#maxlength' => 180, |
---|
323 | ); |
---|
324 | $form['email']['pending_approval']['user_mail_register_pending_approval_body'] = array( |
---|
325 | '#type' => 'textarea', |
---|
326 | '#title' => t('Body'), |
---|
327 | '#default_value' => _user_mail_text('register_pending_approval_body'), |
---|
328 | '#rows' => 8, |
---|
329 | ); |
---|
330 | |
---|
331 | $form['email']['password_reset'] = array( |
---|
332 | '#type' => 'fieldset', |
---|
333 | '#title' => t('Password recovery email'), |
---|
334 | '#collapsible' => TRUE, |
---|
335 | '#collapsed' => TRUE, |
---|
336 | '#description' => t('Customize e-mail messages sent to users who request a new password.') .' '. $email_token_help, |
---|
337 | ); |
---|
338 | $form['email']['password_reset']['user_mail_password_reset_subject'] = array( |
---|
339 | '#type' => 'textfield', |
---|
340 | '#title' => t('Subject'), |
---|
341 | '#default_value' => _user_mail_text('password_reset_subject'), |
---|
342 | '#maxlength' => 180, |
---|
343 | ); |
---|
344 | $form['email']['password_reset']['user_mail_password_reset_body'] = array( |
---|
345 | '#type' => 'textarea', |
---|
346 | '#title' => t('Body'), |
---|
347 | '#default_value' => _user_mail_text('password_reset_body'), |
---|
348 | '#rows' => 12, |
---|
349 | ); |
---|
350 | |
---|
351 | $form['email']['activated'] = array( |
---|
352 | '#type' => 'fieldset', |
---|
353 | '#title' => t('Account activation email'), |
---|
354 | '#collapsible' => TRUE, |
---|
355 | '#collapsed' => TRUE, |
---|
356 | '#description' => t('Enable and customize e-mail messages sent to users upon account activation (when an administrator activates an account of a user who has already registered, on a site where administrative approval is required).') .' '. $email_token_help, |
---|
357 | ); |
---|
358 | $form['email']['activated']['user_mail_status_activated_notify'] = array( |
---|
359 | '#type' => 'checkbox', |
---|
360 | '#title' => t('Notify user when account is activated.'), |
---|
361 | '#default_value' => variable_get('user_mail_status_activated_notify', TRUE), |
---|
362 | ); |
---|
363 | $form['email']['activated']['user_mail_status_activated_subject'] = array( |
---|
364 | '#type' => 'textfield', |
---|
365 | '#title' => t('Subject'), |
---|
366 | '#default_value' => _user_mail_text('status_activated_subject'), |
---|
367 | '#maxlength' => 180, |
---|
368 | ); |
---|
369 | $form['email']['activated']['user_mail_status_activated_body'] = array( |
---|
370 | '#type' => 'textarea', |
---|
371 | '#title' => t('Body'), |
---|
372 | '#default_value' => _user_mail_text('status_activated_body'), |
---|
373 | '#rows' => 15, |
---|
374 | ); |
---|
375 | |
---|
376 | $form['email']['blocked'] = array( |
---|
377 | '#type' => 'fieldset', |
---|
378 | '#title' => t('Account blocked email'), |
---|
379 | '#collapsible' => TRUE, |
---|
380 | '#collapsed' => TRUE, |
---|
381 | '#description' => t('Enable and customize e-mail messages sent to users when their accounts are blocked.') .' '. $email_token_help, |
---|
382 | ); |
---|
383 | $form['email']['blocked']['user_mail_status_blocked_notify'] = array( |
---|
384 | '#type' => 'checkbox', |
---|
385 | '#title' => t('Notify user when account is blocked.'), |
---|
386 | '#default_value' => variable_get('user_mail_status_blocked_notify', FALSE), |
---|
387 | ); |
---|
388 | $form['email']['blocked']['user_mail_status_blocked_subject'] = array( |
---|
389 | '#type' => 'textfield', |
---|
390 | '#title' => t('Subject'), |
---|
391 | '#default_value' => _user_mail_text('status_blocked_subject'), |
---|
392 | '#maxlength' => 180, |
---|
393 | ); |
---|
394 | $form['email']['blocked']['user_mail_status_blocked_body'] = array( |
---|
395 | '#type' => 'textarea', |
---|
396 | '#title' => t('Body'), |
---|
397 | '#default_value' => _user_mail_text('status_blocked_body'), |
---|
398 | '#rows' => 3, |
---|
399 | ); |
---|
400 | |
---|
401 | $form['email']['deleted'] = array( |
---|
402 | '#type' => 'fieldset', |
---|
403 | '#title' => t('Account deleted email'), |
---|
404 | '#collapsible' => TRUE, |
---|
405 | '#collapsed' => TRUE, |
---|
406 | '#description' => t('Enable and customize e-mail messages sent to users when their accounts are deleted.') .' '. $email_token_help, |
---|
407 | ); |
---|
408 | $form['email']['deleted']['user_mail_status_deleted_notify'] = array( |
---|
409 | '#type' => 'checkbox', |
---|
410 | '#title' => t('Notify user when account is deleted.'), |
---|
411 | '#default_value' => variable_get('user_mail_status_deleted_notify', FALSE), |
---|
412 | ); |
---|
413 | $form['email']['deleted']['user_mail_status_deleted_subject'] = array( |
---|
414 | '#type' => 'textfield', |
---|
415 | '#title' => t('Subject'), |
---|
416 | '#default_value' => _user_mail_text('status_deleted_subject'), |
---|
417 | '#maxlength' => 180, |
---|
418 | ); |
---|
419 | $form['email']['deleted']['user_mail_status_deleted_body'] = array( |
---|
420 | '#type' => 'textarea', |
---|
421 | '#title' => t('Body'), |
---|
422 | '#default_value' => _user_mail_text('status_deleted_body'), |
---|
423 | '#rows' => 3, |
---|
424 | ); |
---|
425 | |
---|
426 | // User signatures. |
---|
427 | $form['signatures'] = array( |
---|
428 | '#type' => 'fieldset', |
---|
429 | '#title' => t('Signatures'), |
---|
430 | ); |
---|
431 | $form['signatures']['user_signatures'] = array( |
---|
432 | '#type' => 'radios', |
---|
433 | '#title' => t('Signature support'), |
---|
434 | '#default_value' => variable_get('user_signatures', 0), |
---|
435 | '#options' => array(t('Disabled'), t('Enabled')), |
---|
436 | ); |
---|
437 | |
---|
438 | // If picture support is enabled, check whether the picture directory exists: |
---|
439 | if (variable_get('user_pictures', 0)) { |
---|
440 | $picture_path = file_create_path(variable_get('user_picture_path', 'pictures')); |
---|
441 | file_check_directory($picture_path, 1, 'user_picture_path'); |
---|
442 | } |
---|
443 | |
---|
444 | $form['pictures'] = array( |
---|
445 | '#type' => 'fieldset', |
---|
446 | '#title' => t('Pictures'), |
---|
447 | ); |
---|
448 | $picture_support = variable_get('user_pictures', 0); |
---|
449 | $form['pictures']['user_pictures'] = array( |
---|
450 | '#type' => 'radios', |
---|
451 | '#title' => t('Picture support'), |
---|
452 | '#default_value' => $picture_support, |
---|
453 | '#options' => array(t('Disabled'), t('Enabled')), |
---|
454 | '#prefix' => '<div class="user-admin-picture-radios">', |
---|
455 | '#suffix' => '</div>', |
---|
456 | ); |
---|
457 | drupal_add_js(drupal_get_path('module', 'user') .'/user.js'); |
---|
458 | // If JS is enabled, and the radio is defaulting to off, hide all |
---|
459 | // the settings on page load via .css using the js-hide class so |
---|
460 | // that there's no flicker. |
---|
461 | $css_class = 'user-admin-picture-settings'; |
---|
462 | if (!$picture_support) { |
---|
463 | $css_class .= ' js-hide'; |
---|
464 | } |
---|
465 | $form['pictures']['settings'] = array( |
---|
466 | '#prefix' => '<div class="'. $css_class .'">', |
---|
467 | '#suffix' => '</div>', |
---|
468 | ); |
---|
469 | $form['pictures']['settings']['user_picture_path'] = array( |
---|
470 | '#type' => 'textfield', |
---|
471 | '#title' => t('Picture image path'), |
---|
472 | '#default_value' => variable_get('user_picture_path', 'pictures'), |
---|
473 | '#size' => 30, |
---|
474 | '#maxlength' => 255, |
---|
475 | '#description' => t('Subdirectory in the directory %dir where pictures will be stored.', array('%dir' => file_directory_path() .'/')), |
---|
476 | ); |
---|
477 | $form['pictures']['settings']['user_picture_default'] = array( |
---|
478 | '#type' => 'textfield', |
---|
479 | '#title' => t('Default picture'), |
---|
480 | '#default_value' => variable_get('user_picture_default', ''), |
---|
481 | '#size' => 30, |
---|
482 | '#maxlength' => 255, |
---|
483 | '#description' => t('URL of picture to display for users with no custom picture selected. Leave blank for none.'), |
---|
484 | ); |
---|
485 | $form['pictures']['settings']['user_picture_dimensions'] = array( |
---|
486 | '#type' => 'textfield', |
---|
487 | '#title' => t('Picture maximum dimensions'), |
---|
488 | '#default_value' => variable_get('user_picture_dimensions', '85x85'), |
---|
489 | '#size' => 15, |
---|
490 | '#maxlength' => 10, |
---|
491 | '#description' => t('Maximum dimensions for pictures, in pixels.'), |
---|
492 | ); |
---|
493 | $form['pictures']['settings']['user_picture_file_size'] = array( |
---|
494 | '#type' => 'textfield', |
---|
495 | '#title' => t('Picture maximum file size'), |
---|
496 | '#default_value' => variable_get('user_picture_file_size', '30'), |
---|
497 | '#size' => 15, |
---|
498 | '#maxlength' => 10, |
---|
499 | '#description' => t('Maximum file size for pictures, in kB.'), |
---|
500 | ); |
---|
501 | $form['pictures']['settings']['user_picture_guidelines'] = array( |
---|
502 | '#type' => 'textarea', |
---|
503 | '#title' => t('Picture guidelines'), |
---|
504 | '#default_value' => variable_get('user_picture_guidelines', ''), |
---|
505 | '#description' => t("This text is displayed at the picture upload form in addition to the default guidelines. It's useful for helping or instructing your users."), |
---|
506 | ); |
---|
507 | |
---|
508 | return system_settings_form($form); |
---|
509 | } |
---|
510 | |
---|
511 | /** |
---|
512 | * Menu callback: administer permissions. |
---|
513 | * |
---|
514 | * @ingroup forms |
---|
515 | * @see user_admin_perm_submit() |
---|
516 | * @see theme_user_admin_perm() |
---|
517 | */ |
---|
518 | function user_admin_perm($form_state, $rid = NULL) { |
---|
519 | if (is_numeric($rid)) { |
---|
520 | $result = db_query('SELECT r.rid, p.perm FROM {role} r LEFT JOIN {permission} p ON r.rid = p.rid WHERE r.rid = %d', $rid); |
---|
521 | } |
---|
522 | else { |
---|
523 | $result = db_query('SELECT r.rid, p.perm FROM {role} r LEFT JOIN {permission} p ON r.rid = p.rid ORDER BY name'); |
---|
524 | } |
---|
525 | |
---|
526 | // Compile role array: |
---|
527 | // Add a comma at the end so when searching for a permission, we can |
---|
528 | // always search for "$perm," to make sure we do not confuse |
---|
529 | // permissions that are substrings of each other. |
---|
530 | while ($role = db_fetch_object($result)) { |
---|
531 | $role_permissions[$role->rid] = $role->perm .','; |
---|
532 | } |
---|
533 | |
---|
534 | // Retrieve role names for columns. |
---|
535 | $role_names = user_roles(); |
---|
536 | if (is_numeric($rid)) { |
---|
537 | $role_names = array($rid => $role_names[$rid]); |
---|
538 | } |
---|
539 | |
---|
540 | // Render role/permission overview: |
---|
541 | $options = array(); |
---|
542 | foreach (module_list(FALSE, FALSE, TRUE) as $module) { |
---|
543 | if ($permissions = module_invoke($module, 'perm')) { |
---|
544 | $form['permission'][] = array( |
---|
545 | '#value' => $module, |
---|
546 | ); |
---|
547 | asort($permissions); |
---|
548 | foreach ($permissions as $perm) { |
---|
549 | $options[$perm] = ''; |
---|
550 | $form['permission'][$perm] = array('#value' => t($perm)); |
---|
551 | foreach ($role_names as $rid => $name) { |
---|
552 | // Builds arrays for checked boxes for each role |
---|
553 | if (strpos($role_permissions[$rid], $perm .',') !== FALSE) { |
---|
554 | $status[$rid][] = $perm; |
---|
555 | } |
---|
556 | } |
---|
557 | } |
---|
558 | } |
---|
559 | } |
---|
560 | |
---|
561 | // Have to build checkboxes here after checkbox arrays are built |
---|
562 | foreach ($role_names as $rid => $name) { |
---|
563 | $form['checkboxes'][$rid] = array('#type' => 'checkboxes', '#options' => $options, '#default_value' => isset($status[$rid]) ? $status[$rid] : array()); |
---|
564 | $form['role_names'][$rid] = array('#value' => $name, '#tree' => TRUE); |
---|
565 | } |
---|
566 | $form['submit'] = array('#type' => 'submit', '#value' => t('Save permissions')); |
---|
567 | |
---|
568 | return $form; |
---|
569 | } |
---|
570 | |
---|
571 | function user_admin_perm_submit($form, &$form_state) { |
---|
572 | // Save permissions: |
---|
573 | $result = db_query('SELECT * FROM {role}'); |
---|
574 | while ($role = db_fetch_object($result)) { |
---|
575 | if (isset($form_state['values'][$role->rid])) { |
---|
576 | // Delete, so if we clear every checkbox we reset that role; |
---|
577 | // otherwise permissions are active and denied everywhere. |
---|
578 | db_query('DELETE FROM {permission} WHERE rid = %d', $role->rid); |
---|
579 | $form_state['values'][$role->rid] = array_filter($form_state['values'][$role->rid]); |
---|
580 | if (count($form_state['values'][$role->rid])) { |
---|
581 | db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $role->rid, implode(', ', array_keys($form_state['values'][$role->rid]))); |
---|
582 | } |
---|
583 | } |
---|
584 | } |
---|
585 | |
---|
586 | drupal_set_message(t('The changes have been saved.')); |
---|
587 | |
---|
588 | // Clear the cached pages |
---|
589 | cache_clear_all(); |
---|
590 | } |
---|
591 | |
---|
592 | /** |
---|
593 | * Theme the administer permissions page. |
---|
594 | * |
---|
595 | * @ingroup themeable |
---|
596 | */ |
---|
597 | function theme_user_admin_perm($form) { |
---|
598 | $roles = user_roles(); |
---|
599 | foreach (element_children($form['permission']) as $key) { |
---|
600 | // Don't take form control structures |
---|
601 | if (is_array($form['permission'][$key])) { |
---|
602 | $row = array(); |
---|
603 | // Module name |
---|
604 | if (is_numeric($key)) { |
---|
605 | $row[] = array('data' => t('@module module', array('@module' => drupal_render($form['permission'][$key]))), 'class' => 'module', 'id' => 'module-'. $form['permission'][$key]['#value'], 'colspan' => count($form['role_names']) + 1); |
---|
606 | } |
---|
607 | else { |
---|
608 | $row[] = array('data' => drupal_render($form['permission'][$key]), 'class' => 'permission'); |
---|
609 | foreach (element_children($form['checkboxes']) as $rid) { |
---|
610 | if (is_array($form['checkboxes'][$rid])) { |
---|
611 | $row[] = array('data' => drupal_render($form['checkboxes'][$rid][$key]), 'class' => 'checkbox', 'title' => $roles[$rid] .' : '. t($key)); |
---|
612 | } |
---|
613 | } |
---|
614 | } |
---|
615 | $rows[] = $row; |
---|
616 | } |
---|
617 | } |
---|
618 | $header[] = (t('Permission')); |
---|
619 | foreach (element_children($form['role_names']) as $rid) { |
---|
620 | if (is_array($form['role_names'][$rid])) { |
---|
621 | $header[] = array('data' => drupal_render($form['role_names'][$rid]), 'class' => 'checkbox'); |
---|
622 | } |
---|
623 | } |
---|
624 | $output = theme('table', $header, $rows, array('id' => 'permissions')); |
---|
625 | $output .= drupal_render($form); |
---|
626 | return $output; |
---|
627 | } |
---|
628 | |
---|
629 | /** |
---|
630 | * Menu callback: administer roles. |
---|
631 | * |
---|
632 | * @ingroup forms |
---|
633 | * @see user_admin_role_validate() |
---|
634 | * @see user_admin_role_submit() |
---|
635 | * @see theme_user_admin_new_role() |
---|
636 | */ |
---|
637 | function user_admin_role() { |
---|
638 | $rid = arg(4); |
---|
639 | if ($rid) { |
---|
640 | if ($rid == DRUPAL_ANONYMOUS_RID || $rid == DRUPAL_AUTHENTICATED_RID) { |
---|
641 | drupal_goto('admin/user/roles'); |
---|
642 | } |
---|
643 | // Display the edit role form. |
---|
644 | $role = db_fetch_object(db_query('SELECT * FROM {role} WHERE rid = %d', $rid)); |
---|
645 | $form['name'] = array( |
---|
646 | '#type' => 'textfield', |
---|
647 | '#title' => t('Role name'), |
---|
648 | '#default_value' => $role->name, |
---|
649 | '#size' => 30, |
---|
650 | '#required' => TRUE, |
---|
651 | '#maxlength' => 64, |
---|
652 | '#description' => t('The name for this role. Example: "moderator", "editorial board", "site architect".'), |
---|
653 | ); |
---|
654 | $form['rid'] = array( |
---|
655 | '#type' => 'value', |
---|
656 | '#value' => $rid, |
---|
657 | ); |
---|
658 | $form['submit'] = array( |
---|
659 | '#type' => 'submit', |
---|
660 | '#value' => t('Save role'), |
---|
661 | ); |
---|
662 | $form['delete'] = array( |
---|
663 | '#type' => 'submit', |
---|
664 | '#value' => t('Delete role'), |
---|
665 | ); |
---|
666 | } |
---|
667 | else { |
---|
668 | $form['name'] = array( |
---|
669 | '#type' => 'textfield', |
---|
670 | '#size' => 32, |
---|
671 | '#maxlength' => 64, |
---|
672 | ); |
---|
673 | $form['submit'] = array( |
---|
674 | '#type' => 'submit', |
---|
675 | '#value' => t('Add role'), |
---|
676 | ); |
---|
677 | $form['#submit'][] = 'user_admin_role_submit'; |
---|
678 | $form['#validate'][] = 'user_admin_role_validate'; |
---|
679 | } |
---|
680 | return $form; |
---|
681 | } |
---|
682 | |
---|
683 | function user_admin_role_validate($form, &$form_state) { |
---|
684 | if ($form_state['values']['name']) { |
---|
685 | if ($form_state['values']['op'] == t('Save role')) { |
---|
686 | if (db_result(db_query("SELECT COUNT(*) FROM {role} WHERE name = '%s' AND rid != %d", $form_state['values']['name'], $form_state['values']['rid']))) { |
---|
687 | form_set_error('name', t('The role name %name already exists. Please choose another role name.', array('%name' => $form_state['values']['name']))); |
---|
688 | } |
---|
689 | } |
---|
690 | else if ($form_state['values']['op'] == t('Add role')) { |
---|
691 | if (db_result(db_query("SELECT COUNT(*) FROM {role} WHERE name = '%s'", $form_state['values']['name']))) { |
---|
692 | form_set_error('name', t('The role name %name already exists. Please choose another role name.', array('%name' => $form_state['values']['name']))); |
---|
693 | } |
---|
694 | } |
---|
695 | } |
---|
696 | else { |
---|
697 | form_set_error('name', t('You must specify a valid role name.')); |
---|
698 | } |
---|
699 | } |
---|
700 | |
---|
701 | function user_admin_role_submit($form, &$form_state) { |
---|
702 | if ($form_state['values']['op'] == t('Save role')) { |
---|
703 | db_query("UPDATE {role} SET name = '%s' WHERE rid = %d", $form_state['values']['name'], $form_state['values']['rid']); |
---|
704 | drupal_set_message(t('The role has been renamed.')); |
---|
705 | } |
---|
706 | else if ($form_state['values']['op'] == t('Delete role')) { |
---|
707 | db_query('DELETE FROM {role} WHERE rid = %d', $form_state['values']['rid']); |
---|
708 | db_query('DELETE FROM {permission} WHERE rid = %d', $form_state['values']['rid']); |
---|
709 | // Update the users who have this role set: |
---|
710 | db_query('DELETE FROM {users_roles} WHERE rid = %d', $form_state['values']['rid']); |
---|
711 | |
---|
712 | drupal_set_message(t('The role has been deleted.')); |
---|
713 | } |
---|
714 | else if ($form_state['values']['op'] == t('Add role')) { |
---|
715 | db_query("INSERT INTO {role} (name) VALUES ('%s')", $form_state['values']['name']); |
---|
716 | drupal_set_message(t('The role has been added.')); |
---|
717 | } |
---|
718 | $form_state['redirect'] = 'admin/user/roles'; |
---|
719 | return; |
---|
720 | } |
---|
721 | |
---|
722 | /** |
---|
723 | * Menu callback: list all access rules |
---|
724 | */ |
---|
725 | function user_admin_access_check() { |
---|
726 | $output = drupal_get_form('user_admin_check_user'); |
---|
727 | $output .= drupal_get_form('user_admin_check_mail'); |
---|
728 | $output .= drupal_get_form('user_admin_check_host'); |
---|
729 | return $output; |
---|
730 | } |
---|
731 | |
---|
732 | /** |
---|
733 | * Menu callback: add an access rule. |
---|
734 | */ |
---|
735 | function user_admin_access_add($mask = NULL, $type = NULL) { |
---|
736 | $edit = array(); |
---|
737 | $edit['aid'] = 0; |
---|
738 | $edit['mask'] = $mask; |
---|
739 | $edit['type'] = $type; |
---|
740 | return drupal_get_form('user_admin_access_add_form', $edit, t('Add rule')); |
---|
741 | } |
---|
742 | |
---|
743 | /** |
---|
744 | * Menu callback: edit an access rule. |
---|
745 | */ |
---|
746 | function user_admin_access_edit($aid = 0) { |
---|
747 | $edit = db_fetch_array(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid)); |
---|
748 | return drupal_get_form('user_admin_access_edit_form', $edit, t('Save rule')); |
---|
749 | } |
---|
750 | |
---|
751 | /** |
---|
752 | * Form builder; Configure access rules. |
---|
753 | * |
---|
754 | * @ingroup forms |
---|
755 | */ |
---|
756 | function user_admin_access_form(&$form_state, $edit, $submit) { |
---|
757 | $form = array(); |
---|
758 | $form['aid'] = array( |
---|
759 | '#type' => 'value', |
---|
760 | '#value' => $edit['aid'], |
---|
761 | ); |
---|
762 | $form['status'] = array( |
---|
763 | '#type' => 'radios', |
---|
764 | '#title' => t('Access type'), |
---|
765 | '#default_value' => isset($edit['status']) ? $edit['status'] : 0, |
---|
766 | '#options' => array('1' => t('Allow'), '0' => t('Deny')), |
---|
767 | ); |
---|
768 | $type_options = array('user' => t('Username'), 'mail' => t('E-mail'), 'host' => t('Host')); |
---|
769 | $form['type'] = array( |
---|
770 | '#type' => 'radios', |
---|
771 | '#title' => t('Rule type'), |
---|
772 | '#default_value' => (isset($type_options[$edit['type']]) ? $edit['type'] : 'user'), |
---|
773 | '#options' => $type_options, |
---|
774 | ); |
---|
775 | $form['mask'] = array( |
---|
776 | '#type' => 'textfield', |
---|
777 | '#title' => t('Mask'), |
---|
778 | '#size' => 30, |
---|
779 | '#maxlength' => 64, |
---|
780 | '#default_value' => $edit['mask'], |
---|
781 | '#description' => '%: '. t('Matches any number of characters, even zero characters') .'.<br />_: '. t('Matches exactly one character.'), |
---|
782 | '#required' => TRUE, |
---|
783 | ); |
---|
784 | $form['submit'] = array('#type' => 'submit', '#value' => $submit); |
---|
785 | $form['#submit'] = array('user_admin_access_form_submit'); |
---|
786 | |
---|
787 | return $form; |
---|
788 | } |
---|
789 | |
---|
790 | /** |
---|
791 | * Submit callback for user_admin_access_form(). |
---|
792 | */ |
---|
793 | function user_admin_access_form_submit($form, &$form_state) { |
---|
794 | $edit = $form_state['values']; |
---|
795 | if ($edit['aid']) { |
---|
796 | db_query("UPDATE {access} SET mask = '%s', type = '%s', status = '%s' WHERE aid = %d", $edit['mask'], $edit['type'], $edit['status'], $edit['aid']); |
---|
797 | drupal_set_message(t('The access rule has been saved.')); |
---|
798 | } |
---|
799 | else { |
---|
800 | db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', '%s', %d)", $edit['mask'], $edit['type'], $edit['status']); |
---|
801 | drupal_set_message(t('The access rule has been added.')); |
---|
802 | } |
---|
803 | $form_state['redirect'] = 'admin/user/rules'; |
---|
804 | } |
---|
805 | |
---|
806 | function user_admin_access_check_validate($form, &$form_state) { |
---|
807 | if (empty($form_state['values']['test'])) { |
---|
808 | form_set_error($form_state['values']['type'], t('No value entered. Please enter a test string and try again.')); |
---|
809 | } |
---|
810 | } |
---|
811 | |
---|
812 | function user_admin_check_user() { |
---|
813 | $form['user'] = array('#type' => 'fieldset', '#title' => t('Username')); |
---|
814 | $form['user']['test'] = array('#type' => 'textfield', '#title' => '', '#description' => t('Enter a username to check if it will be denied or allowed.'), '#size' => 30, '#maxlength' => USERNAME_MAX_LENGTH); |
---|
815 | $form['user']['type'] = array('#type' => 'hidden', '#value' => 'user'); |
---|
816 | $form['user']['submit'] = array('#type' => 'submit', '#value' => t('Check username')); |
---|
817 | $form['#submit'][] = 'user_admin_access_check_submit'; |
---|
818 | $form['#validate'][] = 'user_admin_access_check_validate'; |
---|
819 | $form['#theme'] = 'user_admin_access_check'; |
---|
820 | return $form; |
---|
821 | } |
---|
822 | |
---|
823 | function user_admin_check_mail() { |
---|
824 | $form['mail'] = array('#type' => 'fieldset', '#title' => t('E-mail')); |
---|
825 | $form['mail']['test'] = array('#type' => 'textfield', '#title' => '', '#description' => t('Enter an e-mail address to check if it will be denied or allowed.'), '#size' => 30, '#maxlength' => EMAIL_MAX_LENGTH); |
---|
826 | $form['mail']['type'] = array('#type' => 'hidden', '#value' => 'mail'); |
---|
827 | $form['mail']['submit'] = array('#type' => 'submit', '#value' => t('Check e-mail')); |
---|
828 | $form['#submit'][] = 'user_admin_access_check_submit'; |
---|
829 | $form['#validate'][] = 'user_admin_access_check_validate'; |
---|
830 | $form['#theme'] = 'user_admin_access_check'; |
---|
831 | return $form; |
---|
832 | } |
---|
833 | |
---|
834 | function user_admin_check_host() { |
---|
835 | $form['host'] = array('#type' => 'fieldset', '#title' => t('Hostname')); |
---|
836 | $form['host']['test'] = array('#type' => 'textfield', '#title' => '', '#description' => t('Enter a hostname or IP address to check if it will be denied or allowed.'), '#size' => 30, '#maxlength' => 64); |
---|
837 | $form['host']['type'] = array('#type' => 'hidden', '#value' => 'host'); |
---|
838 | $form['host']['submit'] = array('#type' => 'submit', '#value' => t('Check hostname')); |
---|
839 | $form['#submit'][] = 'user_admin_access_check_submit'; |
---|
840 | $form['#validate'][] = 'user_admin_access_check_validate'; |
---|
841 | $form['#theme'] = 'user_admin_access_check'; |
---|
842 | return $form; |
---|
843 | } |
---|
844 | |
---|
845 | function user_admin_access_check_submit($form, &$form_state) { |
---|
846 | switch ($form_state['values']['type']) { |
---|
847 | case 'user': |
---|
848 | if (drupal_is_denied('user', $form_state['values']['test'])) { |
---|
849 | drupal_set_message(t('The username %name is not allowed.', array('%name' => $form_state['values']['test']))); |
---|
850 | } |
---|
851 | else { |
---|
852 | drupal_set_message(t('The username %name is allowed.', array('%name' => $form_state['values']['test']))); |
---|
853 | } |
---|
854 | break; |
---|
855 | case 'mail': |
---|
856 | if (drupal_is_denied('mail', $form_state['values']['test'])) { |
---|
857 | drupal_set_message(t('The e-mail address %mail is not allowed.', array('%mail' => $form_state['values']['test']))); |
---|
858 | } |
---|
859 | else { |
---|
860 | drupal_set_message(t('The e-mail address %mail is allowed.', array('%mail' => $form_state['values']['test']))); |
---|
861 | } |
---|
862 | break; |
---|
863 | case 'host': |
---|
864 | if (drupal_is_denied('host', $form_state['values']['test'])) { |
---|
865 | drupal_set_message(t('The hostname %host is not allowed.', array('%host' => $form_state['values']['test']))); |
---|
866 | } |
---|
867 | else { |
---|
868 | drupal_set_message(t('The hostname %host is allowed.', array('%host' => $form_state['values']['test']))); |
---|
869 | } |
---|
870 | break; |
---|
871 | default: |
---|
872 | break; |
---|
873 | } |
---|
874 | } |
---|
875 | |
---|
876 | /** |
---|
877 | * Menu callback: delete an access rule |
---|
878 | * |
---|
879 | * @ingroup forms |
---|
880 | * @see user_admin_access_delete_confirm_submit() |
---|
881 | */ |
---|
882 | function user_admin_access_delete_confirm($form_state, $aid = 0) { |
---|
883 | $access_types = array('user' => t('username'), 'mail' => t('e-mail'), 'host' => t('host')); |
---|
884 | $edit = db_fetch_object(db_query('SELECT aid, type, status, mask FROM {access} WHERE aid = %d', $aid)); |
---|
885 | |
---|
886 | $form = array(); |
---|
887 | $form['aid'] = array('#type' => 'hidden', '#value' => $aid); |
---|
888 | $output = confirm_form($form, |
---|
889 | t('Are you sure you want to delete the @type rule for %rule?', array('@type' => $access_types[$edit->type], '%rule' => $edit->mask)), |
---|
890 | 'admin/user/rules', |
---|
891 | t('This action cannot be undone.'), |
---|
892 | t('Delete'), |
---|
893 | t('Cancel')); |
---|
894 | return $output; |
---|
895 | } |
---|
896 | |
---|
897 | function user_admin_access_delete_confirm_submit($form, &$form_state) { |
---|
898 | db_query('DELETE FROM {access} WHERE aid = %d', $form_state['values']['aid']); |
---|
899 | drupal_set_message(t('The access rule has been deleted.')); |
---|
900 | $form_state['redirect'] = 'admin/user/rules'; |
---|
901 | return; |
---|
902 | } |
---|
903 | |
---|
904 | /** |
---|
905 | * Menu callback: list all access rules |
---|
906 | */ |
---|
907 | function user_admin_access() { |
---|
908 | $header = array(array('data' => t('Access type'), 'field' => 'status'), array('data' => t('Rule type'), 'field' => 'type'), array('data' => t('Mask'), 'field' => 'mask'), array('data' => t('Operations'), 'colspan' => 2)); |
---|
909 | $result = db_query("SELECT aid, type, status, mask FROM {access}". tablesort_sql($header)); |
---|
910 | $access_types = array('user' => t('username'), 'mail' => t('e-mail'), 'host' => t('host')); |
---|
911 | $rows = array(); |
---|
912 | while ($rule = db_fetch_object($result)) { |
---|
913 | $rows[] = array($rule->status ? t('allow') : t('deny'), $access_types[$rule->type], $rule->mask, l(t('edit'), 'admin/user/rules/edit/'. $rule->aid), l(t('delete'), 'admin/user/rules/delete/'. $rule->aid)); |
---|
914 | } |
---|
915 | if (empty($rows)) { |
---|
916 | $rows[] = array(array('data' => '<em>'. t('There are currently no access rules.') .'</em>', 'colspan' => 5)); |
---|
917 | } |
---|
918 | return theme('table', $header, $rows); |
---|
919 | } |
---|
920 | |
---|
921 | /** |
---|
922 | * Theme user administration overview. |
---|
923 | * |
---|
924 | * @ingroup themeable |
---|
925 | */ |
---|
926 | function theme_user_admin_account($form) { |
---|
927 | // Overview table: |
---|
928 | $header = array( |
---|
929 | theme('table_select_header_cell'), |
---|
930 | array('data' => t('Username'), 'field' => 'u.name'), |
---|
931 | array('data' => t('Status'), 'field' => 'u.status'), |
---|
932 | t('Roles'), |
---|
933 | array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'), |
---|
934 | array('data' => t('Last access'), 'field' => 'u.access'), |
---|
935 | t('Operations') |
---|
936 | ); |
---|
937 | |
---|
938 | $output = drupal_render($form['options']); |
---|
939 | if (isset($form['name']) && is_array($form['name'])) { |
---|
940 | foreach (element_children($form['name']) as $key) { |
---|
941 | $rows[] = array( |
---|
942 | drupal_render($form['accounts'][$key]), |
---|
943 | drupal_render($form['name'][$key]), |
---|
944 | drupal_render($form['status'][$key]), |
---|
945 | drupal_render($form['roles'][$key]), |
---|
946 | drupal_render($form['member_for'][$key]), |
---|
947 | drupal_render($form['last_access'][$key]), |
---|
948 | drupal_render($form['operations'][$key]), |
---|
949 | ); |
---|
950 | } |
---|
951 | } |
---|
952 | else { |
---|
953 | $rows[] = array(array('data' => t('No users available.'), 'colspan' => '7')); |
---|
954 | } |
---|
955 | |
---|
956 | $output .= theme('table', $header, $rows); |
---|
957 | if ($form['pager']['#value']) { |
---|
958 | $output .= drupal_render($form['pager']); |
---|
959 | } |
---|
960 | |
---|
961 | $output .= drupal_render($form); |
---|
962 | |
---|
963 | return $output; |
---|
964 | } |
---|
965 | |
---|
966 | /** |
---|
967 | * Theme the new-role form. |
---|
968 | * |
---|
969 | * @ingroup themeable |
---|
970 | */ |
---|
971 | function theme_user_admin_new_role($form) { |
---|
972 | $header = array(t('Name'), array('data' => t('Operations'), 'colspan' => 2)); |
---|
973 | foreach (user_roles() as $rid => $name) { |
---|
974 | $edit_permissions = l(t('edit permissions'), 'admin/user/permissions/'. $rid); |
---|
975 | if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) { |
---|
976 | $rows[] = array($name, l(t('edit role'), 'admin/user/roles/edit/'. $rid), $edit_permissions); |
---|
977 | } |
---|
978 | else { |
---|
979 | $rows[] = array($name, t('locked'), $edit_permissions); |
---|
980 | } |
---|
981 | } |
---|
982 | $rows[] = array(drupal_render($form['name']), array('data' => drupal_render($form['submit']), 'colspan' => 2)); |
---|
983 | |
---|
984 | $output = drupal_render($form); |
---|
985 | $output .= theme('table', $header, $rows); |
---|
986 | |
---|
987 | return $output; |
---|
988 | } |
---|
989 | |
---|
990 | /** |
---|
991 | * Theme user administration filter form. |
---|
992 | * |
---|
993 | * @ingroup themeable |
---|
994 | */ |
---|
995 | function theme_user_filter_form($form) { |
---|
996 | $output = '<div id="user-admin-filter">'; |
---|
997 | $output .= drupal_render($form['filters']); |
---|
998 | $output .= '</div>'; |
---|
999 | $output .= drupal_render($form); |
---|
1000 | return $output; |
---|
1001 | } |
---|
1002 | |
---|
1003 | /** |
---|
1004 | * Theme user administration filter selector. |
---|
1005 | * |
---|
1006 | * @ingroup themeable |
---|
1007 | */ |
---|
1008 | function theme_user_filters($form) { |
---|
1009 | $output = '<ul class="clear-block">'; |
---|
1010 | if (!empty($form['current'])) { |
---|
1011 | foreach (element_children($form['current']) as $key) { |
---|
1012 | $output .= '<li>'. drupal_render($form['current'][$key]) .'</li>'; |
---|
1013 | } |
---|
1014 | } |
---|
1015 | |
---|
1016 | $output .= '<li><dl class="multiselect">'. (!empty($form['current']) ? '<dt><em>'. t('and') .'</em> '. t('where') .'</dt>' : '') .'<dd class="a">'; |
---|
1017 | foreach (element_children($form['filter']) as $key) { |
---|
1018 | $output .= drupal_render($form['filter'][$key]); |
---|
1019 | } |
---|
1020 | $output .= '</dd>'; |
---|
1021 | |
---|
1022 | $output .= '<dt>'. t('is') .'</dt><dd class="b">'; |
---|
1023 | |
---|
1024 | foreach (element_children($form['status']) as $key) { |
---|
1025 | $output .= drupal_render($form['status'][$key]); |
---|
1026 | } |
---|
1027 | $output .= '</dd>'; |
---|
1028 | |
---|
1029 | $output .= '</dl>'; |
---|
1030 | $output .= '<div class="container-inline" id="user-admin-buttons">'. drupal_render($form['buttons']) .'</div>'; |
---|
1031 | $output .= '</li></ul>'; |
---|
1032 | |
---|
1033 | return $output; |
---|
1034 | } |
---|