00001 <?php
00002
00003
00009 function user_admin($callback_arg = '') {
00010 $op = isset($_POST['op']) ? $_POST['op'] : $callback_arg;
00011
00012 switch ($op) {
00013 case t('Create new account'):
00014 case 'create':
00015 $output = drupal_get_form('user_register');
00016 break;
00017 default:
00018 if (!empty($_POST['accounts']) && isset($_POST['operation']) && ($_POST['operation'] == 'delete')) {
00019 $output = drupal_get_form('user_multiple_delete_confirm');
00020 }
00021 else {
00022 $output = drupal_get_form('user_filter_form');
00023 $output .= drupal_get_form('user_admin_account');
00024 }
00025 }
00026 return $output;
00027 }
00028
00035 function user_filter_form() {
00036 $session = &$_SESSION['user_overview_filter'];
00037 $session = is_array($session) ? $session : array();
00038 $filters = user_filters();
00039
00040 $i = 0;
00041 $form['filters'] = array(
00042 '#type' => 'fieldset',
00043 '#title' => t('Show only users where'),
00044 '#theme' => 'user_filters',
00045 );
00046 foreach ($session as $filter) {
00047 list($type, $value) = $filter;
00048
00049 $options = $type == 'permission' ? call_user_func_array('array_merge', $filters[$type]['options']) : $filters[$type]['options'];
00050 $params = array('%property' => $filters[$type]['title'] , '%value' => $options[$value]);
00051 if ($i++ > 0) {
00052 $form['filters']['current'][] = array('#value' => t('<em>and</em> where <strong>%property</strong> is <strong>%value</strong>', $params));
00053 }
00054 else {
00055 $form['filters']['current'][] = array('#value' => t('<strong>%property</strong> is <strong>%value</strong>', $params));
00056 }
00057 }
00058
00059 foreach ($filters as $key => $filter) {
00060 $names[$key] = $filter['title'];
00061 $form['filters']['status'][$key] = array(
00062 '#type' => 'select',
00063 '#options' => $filter['options'],
00064 );
00065 }
00066
00067 $form['filters']['filter'] = array(
00068 '#type' => 'radios',
00069 '#options' => $names,
00070 );
00071 $form['filters']['buttons']['submit'] = array(
00072 '#type' => 'submit',
00073 '#value' => (count($session) ? t('Refine') : t('Filter')),
00074 );
00075 if (count($session)) {
00076 $form['filters']['buttons']['undo'] = array(
00077 '#type' => 'submit',
00078 '#value' => t('Undo'),
00079 );
00080 $form['filters']['buttons']['reset'] = array(
00081 '#type' => 'submit',
00082 '#value' => t('Reset'),
00083 );
00084 }
00085
00086 drupal_add_js('misc/form.js', 'core');
00087
00088 return $form;
00089 }
00090
00094 function user_filter_form_submit($form, &$form_state) {
00095 $op = $form_state['values']['op'];
00096 $filters = user_filters();
00097 switch ($op) {
00098 case t('Filter'): case t('Refine'):
00099 if (isset($form_state['values']['filter'])) {
00100 $filter = $form_state['values']['filter'];
00101
00102 $options = $filter == 'permission' ? call_user_func_array('array_merge', $filters[$filter]['options']) : $filters[$filter]['options'];
00103 if (isset($options[$form_state['values'][$filter]])) {
00104 $_SESSION['user_overview_filter'][] = array($filter, $form_state['values'][$filter]);
00105 }
00106 }
00107 break;
00108 case t('Undo'):
00109 array_pop($_SESSION['user_overview_filter']);
00110 break;
00111 case t('Reset'):
00112 $_SESSION['user_overview_filter'] = array();
00113 break;
00114 case t('Update'):
00115 return;
00116 }
00117
00118 $form_state['redirect'] = 'admin/user/user';
00119 return;
00120 }
00121
00129 function user_admin_account() {
00130 $filter = user_build_filter_query();
00131
00132 $header = array(
00133 array(),
00134 array('data' => t('Username'), 'field' => 'u.name'),
00135 array('data' => t('Status'), 'field' => 'u.status'),
00136 t('Roles'),
00137 array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'),
00138 array('data' => t('Last access'), 'field' => 'u.access'),
00139 t('Operations')
00140 );
00141
00142 $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'];
00143 $sql .= tablesort_sql($header);
00144 $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'];
00145 $result = pager_query($sql, 50, 0, $query_count, $filter['args']);
00146
00147 $form['options'] = array(
00148 '#type' => 'fieldset',
00149 '#title' => t('Update options'),
00150 '#prefix' => '<div class="container-inline">',
00151 '#suffix' => '</div>',
00152 );
00153 $options = array();
00154 foreach (module_invoke_all('user_operations') as $operation => $array) {
00155 $options[$operation] = $array['label'];
00156 }
00157 $form['options']['operation'] = array(
00158 '#type' => 'select',
00159 '#options' => $options,
00160 '#default_value' => 'unblock',
00161 );
00162 $form['options']['submit'] = array(
00163 '#type' => 'submit',
00164 '#value' => t('Update'),
00165 );
00166
00167 $destination = drupal_get_destination();
00168
00169 $status = array(t('blocked'), t('active'));
00170 $roles = user_roles(TRUE);
00171 $accounts = array();
00172 while ($account = db_fetch_object($result)) {
00173 $accounts[$account->uid] = '';
00174 $form['name'][$account->uid] = array('#value' => theme('username', $account));
00175 $form['status'][$account->uid] = array('#value' => $status[$account->status]);
00176 $users_roles = array();
00177 $roles_result = db_query('SELECT rid FROM {users_roles} WHERE uid = %d', $account->uid);
00178 while ($user_role = db_fetch_object($roles_result)) {
00179 $users_roles[] = $roles[$user_role->rid];
00180 }
00181 asort($users_roles);
00182 $form['roles'][$account->uid][0] = array('#value' => theme('item_list', $users_roles));
00183 $form['member_for'][$account->uid] = array('#value' => format_interval(time() - $account->created));
00184 $form['last_access'][$account->uid] = array('#value' => $account->access ? t('@time ago', array('@time' => format_interval(time() - $account->access))) : t('never'));
00185 $form['operations'][$account->uid] = array('#value' => l(t('edit'), "user/$account->uid/edit", array('query' => $destination)));
00186 }
00187 $form['accounts'] = array(
00188 '#type' => 'checkboxes',
00189 '#options' => $accounts
00190 );
00191 $form['pager'] = array('#value' => theme('pager', NULL, 50, 0));
00192
00193 return $form;
00194 }
00195
00199 function user_admin_account_submit($form, &$form_state) {
00200 $operations = module_invoke_all('user_operations', $form_state);
00201 $operation = $operations[$form_state['values']['operation']];
00202
00203 $accounts = array_filter($form_state['values']['accounts']);
00204 if ($function = $operation['callback']) {
00205
00206 if (isset($operation['callback arguments'])) {
00207 $args = array_merge(array($accounts), $operation['callback arguments']);
00208 }
00209 else {
00210 $args = array($accounts);
00211 }
00212 call_user_func_array($function, $args);
00213
00214 drupal_set_message(t('The update has been performed.'));
00215 }
00216 }
00217
00218 function user_admin_account_validate($form, &$form_state) {
00219 $form_state['values']['accounts'] = array_filter($form_state['values']['accounts']);
00220 if (count($form_state['values']['accounts']) == 0) {
00221 form_set_error('', t('No users selected.'));
00222 }
00223 }
00224
00231 function user_admin_settings() {
00232
00233 $form['registration'] = array('#type' => 'fieldset', '#title' => t('User registration settings'));
00234 $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.')));
00235 $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.'));
00236 $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.'));
00237
00238
00239 $form['email'] = array(
00240 '#type' => 'fieldset',
00241 '#title' => t('User e-mail settings'),
00242 '#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.'),
00243 );
00244
00245
00246 $email_token_help = t('Available variables are:') . ' !username, !site, !password, !uri, !uri_brief, !mailto, !date, !login_uri, !edit_uri, !login_url.';
00247
00248 $form['email']['admin_created'] = array(
00249 '#type' => 'fieldset',
00250 '#title' => t('Welcome, new user created by administrator'),
00251 '#collapsible' => TRUE,
00252 '#collapsed' => (variable_get('user_register', 1) != 0),
00253 '#description' => t('Customize welcome e-mail messages sent to new member accounts created by an administrator.') . ' ' . $email_token_help,
00254 );
00255 $form['email']['admin_created']['user_mail_register_admin_created_subject'] = array(
00256 '#type' => 'textfield',
00257 '#title' => t('Subject'),
00258 '#default_value' => _user_mail_text('register_admin_created_subject'),
00259 '#maxlength' => 180,
00260 );
00261 $form['email']['admin_created']['user_mail_register_admin_created_body'] = array(
00262 '#type' => 'textarea',
00263 '#title' => t('Body'),
00264 '#default_value' => _user_mail_text('register_admin_created_body'),
00265 '#rows' => 15,
00266 );
00267
00268 $form['email']['no_approval_required'] = array(
00269 '#type' => 'fieldset',
00270 '#title' => t('Welcome, no approval required'),
00271 '#collapsible' => TRUE,
00272 '#collapsed' => (variable_get('user_register', 1) != 1),
00273 '#description' => t('Customize welcome e-mail messages sent to new members upon registering, when no administrator approval is required.') . ' ' . $email_token_help
00274 );
00275 $form['email']['no_approval_required']['user_mail_register_no_approval_required_subject'] = array(
00276 '#type' => 'textfield',
00277 '#title' => t('Subject'),
00278 '#default_value' => _user_mail_text('register_no_approval_required_subject'),
00279 '#maxlength' => 180,
00280 );
00281 $form['email']['no_approval_required']['user_mail_register_no_approval_required_body'] = array(
00282 '#type' => 'textarea',
00283 '#title' => t('Body'),
00284 '#default_value' => _user_mail_text('register_no_approval_required_body'),
00285 '#rows' => 15,
00286 );
00287
00288 $form['email']['pending_approval'] = array(
00289 '#type' => 'fieldset',
00290 '#title' => t('Welcome, awaiting administrator approval'),
00291 '#collapsible' => TRUE,
00292 '#collapsed' => (variable_get('user_register', 1) != 2),
00293 '#description' => t('Customize welcome e-mail messages sent to new members upon registering, when administrative approval is required.') . ' ' . $email_token_help,
00294 );
00295 $form['email']['pending_approval']['user_mail_register_pending_approval_subject'] = array(
00296 '#type' => 'textfield',
00297 '#title' => t('Subject'),
00298 '#default_value' => _user_mail_text('register_pending_approval_subject'),
00299 '#maxlength' => 180,
00300 );
00301 $form['email']['pending_approval']['user_mail_register_pending_approval_body'] = array(
00302 '#type' => 'textarea',
00303 '#title' => t('Body'),
00304 '#default_value' => _user_mail_text('register_pending_approval_body'),
00305 '#rows' => 8,
00306 );
00307
00308 $form['email']['password_reset'] = array(
00309 '#type' => 'fieldset',
00310 '#title' => t('Password recovery email'),
00311 '#collapsible' => TRUE,
00312 '#collapsed' => TRUE,
00313 '#description' => t('Customize e-mail messages sent to users who request a new password.') . ' ' . $email_token_help,
00314 );
00315 $form['email']['password_reset']['user_mail_password_reset_subject'] = array(
00316 '#type' => 'textfield',
00317 '#title' => t('Subject'),
00318 '#default_value' => _user_mail_text('password_reset_subject'),
00319 '#maxlength' => 180,
00320 );
00321 $form['email']['password_reset']['user_mail_password_reset_body'] = array(
00322 '#type' => 'textarea',
00323 '#title' => t('Body'),
00324 '#default_value' => _user_mail_text('password_reset_body'),
00325 '#rows' => 12,
00326 );
00327
00328 $form['email']['activated'] = array(
00329 '#type' => 'fieldset',
00330 '#title' => t('Account activation email'),
00331 '#collapsible' => TRUE,
00332 '#collapsed' => TRUE,
00333 '#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,
00334 );
00335 $form['email']['activated']['user_mail_status_activated_notify'] = array(
00336 '#type' => 'checkbox',
00337 '#title' => t('Notify user when account is activated.'),
00338 '#default_value' => variable_get('user_mail_status_activated_notify', TRUE),
00339 );
00340 $form['email']['activated']['user_mail_status_activated_subject'] = array(
00341 '#type' => 'textfield',
00342 '#title' => t('Subject'),
00343 '#default_value' => _user_mail_text('status_activated_subject'),
00344 '#maxlength' => 180,
00345 );
00346 $form['email']['activated']['user_mail_status_activated_body'] = array(
00347 '#type' => 'textarea',
00348 '#title' => t('Body'),
00349 '#default_value' => _user_mail_text('status_activated_body'),
00350 '#rows' => 15,
00351 );
00352
00353 $form['email']['blocked'] = array(
00354 '#type' => 'fieldset',
00355 '#title' => t('Account blocked email'),
00356 '#collapsible' => TRUE,
00357 '#collapsed' => TRUE,
00358 '#description' => t('Enable and customize e-mail messages sent to users when their accounts are blocked.') . ' ' . $email_token_help,
00359 );
00360 $form['email']['blocked']['user_mail_status_blocked_notify'] = array(
00361 '#type' => 'checkbox',
00362 '#title' => t('Notify user when account is blocked.'),
00363 '#default_value' => variable_get('user_mail_status_blocked_notify', FALSE),
00364 );
00365 $form['email']['blocked']['user_mail_status_blocked_subject'] = array(
00366 '#type' => 'textfield',
00367 '#title' => t('Subject'),
00368 '#default_value' => _user_mail_text('status_blocked_subject'),
00369 '#maxlength' => 180,
00370 );
00371 $form['email']['blocked']['user_mail_status_blocked_body'] = array(
00372 '#type' => 'textarea',
00373 '#title' => t('Body'),
00374 '#default_value' => _user_mail_text('status_blocked_body'),
00375 '#rows' => 3,
00376 );
00377
00378 $form['email']['deleted'] = array(
00379 '#type' => 'fieldset',
00380 '#title' => t('Account deleted email'),
00381 '#collapsible' => TRUE,
00382 '#collapsed' => TRUE,
00383 '#description' => t('Enable and customize e-mail messages sent to users when their accounts are deleted.') . ' ' . $email_token_help,
00384 );
00385 $form['email']['deleted']['user_mail_status_deleted_notify'] = array(
00386 '#type' => 'checkbox',
00387 '#title' => t('Notify user when account is deleted.'),
00388 '#default_value' => variable_get('user_mail_status_deleted_notify', FALSE),
00389 );
00390 $form['email']['deleted']['user_mail_status_deleted_subject'] = array(
00391 '#type' => 'textfield',
00392 '#title' => t('Subject'),
00393 '#default_value' => _user_mail_text('status_deleted_subject'),
00394 '#maxlength' => 180,
00395 );
00396 $form['email']['deleted']['user_mail_status_deleted_body'] = array(
00397 '#type' => 'textarea',
00398 '#title' => t('Body'),
00399 '#default_value' => _user_mail_text('status_deleted_body'),
00400 '#rows' => 3,
00401 );
00402
00403
00404 $form['signatures'] = array(
00405 '#type' => 'fieldset',
00406 '#title' => t('Signatures'),
00407 );
00408 $form['signatures']['user_signatures'] = array(
00409 '#type' => 'radios',
00410 '#title' => t('Signature support'),
00411 '#default_value' => variable_get('user_signatures', 0),
00412 '#options' => array(t('Disabled'), t('Enabled')),
00413 );
00414
00415
00416 if (variable_get('user_pictures', 0)) {
00417 $picture_path = file_create_path(variable_get('user_picture_path', 'pictures'));
00418 file_check_directory($picture_path, 1, 'user_picture_path');
00419 }
00420
00421 $form['pictures'] = array(
00422 '#type' => 'fieldset',
00423 '#title' => t('Pictures'),
00424 );
00425 $picture_support = variable_get('user_pictures', 0);
00426 $form['pictures']['user_pictures'] = array(
00427 '#type' => 'radios',
00428 '#title' => t('Picture support'),
00429 '#default_value' => $picture_support,
00430 '#options' => array(t('Disabled'), t('Enabled')),
00431 '#prefix' => '<div class="user-admin-picture-radios">',
00432 '#suffix' => '</div>',
00433 );
00434 drupal_add_js(drupal_get_path('module', 'user') . '/user.js');
00435
00436
00437
00438 $css_class = 'user-admin-picture-settings';
00439 if (!$picture_support) {
00440 $css_class .= ' js-hide';
00441 }
00442 $form['pictures']['settings'] = array(
00443 '#prefix' => '<div class="' . $css_class . '">',
00444 '#suffix' => '</div>',
00445 );
00446 $form['pictures']['settings']['user_picture_path'] = array(
00447 '#type' => 'textfield',
00448 '#title' => t('Picture image path'),
00449 '#default_value' => variable_get('user_picture_path', 'pictures'),
00450 '#size' => 30,
00451 '#maxlength' => 255,
00452 '#description' => t('Subdirectory in the directory %dir where pictures will be stored.', array('%dir' => file_directory_path() . '/')),
00453 );
00454 $form['pictures']['settings']['user_picture_default'] = array(
00455 '#type' => 'textfield',
00456 '#title' => t('Default picture'),
00457 '#default_value' => variable_get('user_picture_default', ''),
00458 '#size' => 30,
00459 '#maxlength' => 255,
00460 '#description' => t('URL of picture to display for users with no custom picture selected. Leave blank for none.'),
00461 );
00462 $form['pictures']['settings']['user_picture_dimensions'] = array(
00463 '#type' => 'textfield',
00464 '#title' => t('Picture maximum dimensions'),
00465 '#default_value' => variable_get('user_picture_dimensions', '85x85'),
00466 '#size' => 15,
00467 '#maxlength' => 10,
00468 '#description' => t('Maximum dimensions for pictures, in pixels.'),
00469 );
00470 $form['pictures']['settings']['user_picture_file_size'] = array(
00471 '#type' => 'textfield',
00472 '#title' => t('Picture maximum file size'),
00473 '#default_value' => variable_get('user_picture_file_size', '30'),
00474 '#size' => 15,
00475 '#maxlength' => 10,
00476 '#description' => t('Maximum file size for pictures, in kB.'),
00477 );
00478 $form['pictures']['settings']['user_picture_guidelines'] = array(
00479 '#type' => 'textarea',
00480 '#title' => t('Picture guidelines'),
00481 '#default_value' => variable_get('user_picture_guidelines', ''),
00482 '#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."),
00483 );
00484
00485 return system_settings_form($form);
00486 }
00487
00495 function user_admin_perm($form_state, $rid = NULL) {
00496
00497
00498 $role_names = user_roles();
00499 if (is_numeric($rid)) {
00500 $role_names = array($rid => $role_names[$rid]);
00501 }
00502
00503 $role_permissions = user_role_permissions($role_names);
00504
00505
00506 $form['role_names'] = array(
00507 '#type' => 'value',
00508 '#value' => $role_names,
00509 );
00510
00511 $options = array();
00512 $hide_descriptions = !system_admin_compact_mode();
00513 foreach (module_list(FALSE, FALSE, TRUE) as $module) {
00514 if ($permissions = module_invoke($module, 'perm')) {
00515 $form['permission'][] = array(
00516 '#value' => $module,
00517 );
00518 ksort($permissions);
00519 foreach ($permissions as $perm => $description) {
00520
00521 if (is_int($perm)) {
00522 $perm = $description;
00523 $description = NULL;
00524 }
00525 $options[$perm] = '';
00526 $form['permission'][$perm] = array(
00527 '#type' => 'item',
00528 '#value' => t($perm),
00529 '#description' => $hide_descriptions ? $description : NULL,
00530 );
00531 foreach ($role_names as $rid => $name) {
00532
00533 if (isset($role_permissions[$rid][$perm])) {
00534 $status[$rid][] = $perm;
00535 }
00536 }
00537 }
00538 }
00539 }
00540
00541
00542 foreach ($role_names as $rid => $name) {
00543 $form['checkboxes'][$rid] = array('#type' => 'checkboxes', '#options' => $options, '#default_value' => isset($status[$rid]) ? $status[$rid] : array());
00544 $form['role_names'][$rid] = array('#value' => $name, '#tree' => TRUE);
00545 }
00546 $form['submit'] = array('#type' => 'submit', '#value' => t('Save permissions'));
00547
00548 return $form;
00549 }
00550
00556 function user_admin_perm_submit($form, &$form_state) {
00557 foreach ($form_state['values']['role_names'] as $rid => $name) {
00558 $checked = array_filter($form_state['values'][$rid]);
00559
00560 db_query("DELETE FROM {role_permission} WHERE rid = %d", $rid);
00561 foreach ($checked as $permission) {
00562 db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", $rid, $permission);
00563 }
00564 }
00565
00566 drupal_set_message(t('The changes have been saved.'));
00567
00568
00569 cache_clear_all();
00570 }
00571
00577 function theme_user_admin_perm($form) {
00578 $roles = user_roles();
00579 foreach (element_children($form['permission']) as $key) {
00580
00581 if (is_array($form['permission'][$key])) {
00582 $row = array();
00583
00584 if (is_numeric($key)) {
00585 $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);
00586 }
00587 else {
00588
00589 $row[] = array(
00590 'data' => drupal_render($form['permission'][$key]),
00591 'class' => 'permission',
00592 );
00593 foreach (element_children($form['checkboxes']) as $rid) {
00594 if (is_array($form['checkboxes'][$rid])) {
00595 $row[] = array('data' => drupal_render($form['checkboxes'][$rid][$key]), 'class' => 'checkbox', 'title' => $roles[$rid] . ' : ' . t($key));
00596 }
00597 }
00598 }
00599 $rows[] = $row;
00600 }
00601 }
00602 $header[] = (t('Permission'));
00603 foreach (element_children($form['role_names']) as $rid) {
00604 if (is_array($form['role_names'][$rid])) {
00605 $header[] = array('data' => drupal_render($form['role_names'][$rid]), 'class' => 'checkbox');
00606 }
00607 }
00608 $output = theme('system_compact_link');
00609 $output .= theme('table', $header, $rows, array('id' => 'permissions'));
00610 $output .= drupal_render($form);
00611 return $output;
00612 }
00613
00622 function user_admin_role() {
00623 $rid = arg(4);
00624 if ($rid) {
00625 if ($rid == DRUPAL_ANONYMOUS_RID || $rid == DRUPAL_AUTHENTICATED_RID) {
00626 drupal_goto('admin/user/roles');
00627 }
00628
00629 $role = db_fetch_object(db_query('SELECT * FROM {role} WHERE rid = %d', $rid));
00630 $form['name'] = array(
00631 '#type' => 'textfield',
00632 '#title' => t('Role name'),
00633 '#default_value' => $role->name,
00634 '#size' => 30,
00635 '#required' => TRUE,
00636 '#maxlength' => 64,
00637 '#description' => t('The name for this role. Example: "moderator", "editorial board", "site architect".'),
00638 );
00639 $form['rid'] = array(
00640 '#type' => 'value',
00641 '#value' => $rid,
00642 );
00643 $form['submit'] = array(
00644 '#type' => 'submit',
00645 '#value' => t('Save role'),
00646 );
00647 $form['delete'] = array(
00648 '#type' => 'submit',
00649 '#value' => t('Delete role'),
00650 );
00651 }
00652 else {
00653 $form['name'] = array(
00654 '#type' => 'textfield',
00655 '#size' => 32,
00656 '#maxlength' => 64,
00657 );
00658 $form['submit'] = array(
00659 '#type' => 'submit',
00660 '#value' => t('Add role'),
00661 );
00662 $form['#submit'][] = 'user_admin_role_submit';
00663 $form['#validate'][] = 'user_admin_role_validate';
00664 }
00665 return $form;
00666 }
00667
00668 function user_admin_role_validate($form, &$form_state) {
00669 if ($form_state['values']['name']) {
00670 if ($form_state['values']['op'] == t('Save role')) {
00671 if (db_result(db_query("SELECT COUNT(*) FROM {role} WHERE name = '%s' AND rid != %d", $form_state['values']['name'], $form_state['values']['rid']))) {
00672 form_set_error('name', t('The role name %name already exists. Please choose another role name.', array('%name' => $form_state['values']['name'])));
00673 }
00674 }
00675 else if ($form_state['values']['op'] == t('Add role')) {
00676 if (db_result(db_query("SELECT COUNT(*) FROM {role} WHERE name = '%s'", $form_state['values']['name']))) {
00677 form_set_error('name', t('The role name %name already exists. Please choose another role name.', array('%name' => $form_state['values']['name'])));
00678 }
00679 }
00680 }
00681 else {
00682 form_set_error('name', t('You must specify a valid role name.'));
00683 }
00684 }
00685
00686 function user_admin_role_submit($form, &$form_state) {
00687 if ($form_state['values']['op'] == t('Save role')) {
00688 db_query("UPDATE {role} SET name = '%s' WHERE rid = %d", $form_state['values']['name'], $form_state['values']['rid']);
00689 drupal_set_message(t('The role has been renamed.'));
00690 }
00691 else if ($form_state['values']['op'] == t('Delete role')) {
00692 db_query('DELETE FROM {role} WHERE rid = %d', $form_state['values']['rid']);
00693 db_query('DELETE FROM {role_permission} WHERE rid = %d', $form_state['values']['rid']);
00694
00695 db_query('DELETE FROM {users_roles} WHERE rid = %d', $form_state['values']['rid']);
00696
00697 drupal_set_message(t('The role has been deleted.'));
00698 }
00699 else if ($form_state['values']['op'] == t('Add role')) {
00700 db_query("INSERT INTO {role} (name) VALUES ('%s')", $form_state['values']['name']);
00701 drupal_set_message(t('The role has been added.'));
00702 }
00703 $form_state['redirect'] = 'admin/user/roles';
00704 return;
00705 }
00706
00712 function theme_user_admin_account($form) {
00713
00714 $header = array(
00715 theme('table_select_header_cell'),
00716 array('data' => t('Username'), 'field' => 'u.name'),
00717 array('data' => t('Status'), 'field' => 'u.status'),
00718 t('Roles'),
00719 array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'),
00720 array('data' => t('Last access'), 'field' => 'u.access'),
00721 t('Operations')
00722 );
00723
00724 $output = drupal_render($form['options']);
00725 if (isset($form['name']) && is_array($form['name'])) {
00726 foreach (element_children($form['name']) as $key) {
00727 $rows[] = array(
00728 drupal_render($form['accounts'][$key]),
00729 drupal_render($form['name'][$key]),
00730 drupal_render($form['status'][$key]),
00731 drupal_render($form['roles'][$key]),
00732 drupal_render($form['member_for'][$key]),
00733 drupal_render($form['last_access'][$key]),
00734 drupal_render($form['operations'][$key]),
00735 );
00736 }
00737 }
00738 else {
00739 $rows[] = array(array('data' => t('No users available.'), 'colspan' => '7'));
00740 }
00741
00742 $output .= theme('table', $header, $rows);
00743 if ($form['pager']['#value']) {
00744 $output .= drupal_render($form['pager']);
00745 }
00746
00747 $output .= drupal_render($form);
00748
00749 return $output;
00750 }
00751
00757 function theme_user_admin_new_role($form) {
00758 $header = array(t('Name'), array('data' => t('Operations'), 'colspan' => 2));
00759 foreach (user_roles() as $rid => $name) {
00760 $edit_permissions = l(t('edit permissions'), 'admin/user/permissions/' . $rid);
00761 if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
00762 $rows[] = array($name, l(t('edit role'), 'admin/user/roles/edit/' . $rid), $edit_permissions);
00763 }
00764 else {
00765 $rows[] = array($name, t('locked'), $edit_permissions);
00766 }
00767 }
00768 $rows[] = array(drupal_render($form['name']), array('data' => drupal_render($form['submit']), 'colspan' => 2));
00769
00770 $output = drupal_render($form);
00771 $output .= theme('table', $header, $rows);
00772
00773 return $output;
00774 }
00775
00781 function theme_user_filter_form($form) {
00782 $output = '<div id="user-admin-filter">';
00783 $output .= drupal_render($form['filters']);
00784 $output .= '</div>';
00785 $output .= drupal_render($form);
00786 return $output;
00787 }
00788
00794 function theme_user_filters($form) {
00795 $output = '<ul class="clear-block">';
00796 if (!empty($form['current'])) {
00797 foreach (element_children($form['current']) as $key) {
00798 $output .= '<li>' . drupal_render($form['current'][$key]) . '</li>';
00799 }
00800 }
00801
00802 $output .= '<li><dl class="multiselect">' . (!empty($form['current']) ? '<dt><em>' . t('and') . '</em> ' . t('where') . '</dt>' : '') . '<dd class="a">';
00803 foreach (element_children($form['filter']) as $key) {
00804 $output .= drupal_render($form['filter'][$key]);
00805 }
00806 $output .= '</dd>';
00807
00808 $output .= '<dt>' . t('is') . '</dt><dd class="b">';
00809
00810 foreach (element_children($form['status']) as $key) {
00811 $output .= drupal_render($form['status'][$key]);
00812 }
00813 $output .= '</dd>';
00814
00815 $output .= '</dl>';
00816 $output .= '<div class="container-inline" id="user-admin-buttons">' . drupal_render($form['buttons']) . '</div>';
00817 $output .= '</li></ul>';
00818
00819 return $output;
00820 }