user.admin.inc 21.8 KB
Newer Older
1 2 3 4 5 6 7
<?php

/**
 * @file
 * Admin page callback file for the user module.
 */

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/**
 * Page callback: Generates the appropriate user administration form.
 *
 * This function generates the user registration, multiple user cancellation,
 * or filtered user list admin form, depending on the argument and the POST
 * form values.
 *
 * @param string $callback_arg
 *   (optional) Indicates which form to build. Defaults to '', which will
 *   trigger the user filter form. If the POST value 'op' is present, this
 *   function uses that value as the callback argument.
 *
 * @return string
 *   A renderable form array for the respective request.
 */
23 24 25 26 27 28
function user_admin($callback_arg = '') {
  $op = isset($_POST['op']) ? $_POST['op'] : $callback_arg;

  switch ($op) {
    case t('Create new account'):
    case 'create':
29 30
      $account = entity_create('user', array());
      $build['user_register'] = entity_get_form($account, 'register');
31 32
      break;
    default:
33
      if (!empty($_POST['accounts']) && isset($_POST['operation']) && ($_POST['operation'] == 'cancel')) {
34
        $build['user_multiple_cancel_confirm'] = drupal_get_form('user_multiple_cancel_confirm');
35 36
      }
      else {
37 38
        $build['user_filter_form'] = drupal_get_form('user_filter_form');
        $build['user_admin_account'] = drupal_get_form('user_admin_account');
39 40
      }
  }
41
  return $build;
42 43 44 45
}

/**
 * Form builder; Return form for user administration filters.
46
 *
47
 * @ingroup forms
48
 * @see user_filter_form_submit()
49 50
 */
function user_filter_form() {
51
  $session = isset($_SESSION['user_overview_filter']) ? $_SESSION['user_overview_filter'] : array();
52 53 54
  $filters = user_filters();

  $i = 0;
55
  $form['filters'] = array(
56
    '#type' => 'details',
57
    '#title' => t('Show only users where'),
58
    '#theme' => 'exposed_filters__user',
59
  );
60 61
  foreach ($session as $filter) {
    list($type, $value) = $filter;
62 63 64 65 66 67 68 69 70
    if ($type == 'permission') {
      // Merge arrays of module permissions into one.
      // Slice past the first element '[any]' whose value is not an array.
      $options = call_user_func_array('array_merge', array_slice($filters[$type]['options'], 1));
      $value = $options[$value];
    }
    else {
      $value = $filters[$type]['options'][$value];
    }
71
    $t_args = array('%property' => $filters[$type]['title'], '%value' => $value);
72
    if ($i++) {
73
      $form['filters']['current'][] = array('#markup' => t('and where %property is %value', $t_args));
74 75
    }
    else {
76
      $form['filters']['current'][] = array('#markup' => t('%property is %value', $t_args));
77
    }
78 79
  }

80 81 82 83 84 85 86 87 88
  $form['filters']['status'] = array(
    '#type' => 'container',
    '#attributes' => array('class' => array('clearfix')),
    '#prefix' => ($i ? '<div class="additional-filters">' . t('and where') . '</div>' : ''),
  );
  $form['filters']['status']['filters'] = array(
    '#type' => 'container',
    '#attributes' => array('class' => array('filters')),
  );
89
  foreach ($filters as $key => $filter) {
90
    $form['filters']['status']['filters'][$key] = array(
91 92
      '#type' => 'select',
      '#options' => $filter['options'],
93 94
      '#title' => $filter['title'],
      '#default_value' => '[any]',
95
    );
96 97
  }

98
  $form['filters']['status']['actions'] = array(
99 100
    '#type' => 'actions',
    '#attributes' => array('class' => array('container-inline')),
101
  );
102
  $form['filters']['status']['actions']['submit'] = array(
103 104 105
    '#type' => 'submit',
    '#value' => (count($session) ? t('Refine') : t('Filter')),
  );
106
  if (count($session)) {
107
    $form['filters']['status']['actions']['undo'] = array(
108 109 110
      '#type' => 'submit',
      '#value' => t('Undo'),
    );
111
    $form['filters']['status']['actions']['reset'] = array(
112 113 114
      '#type' => 'submit',
      '#value' => t('Reset'),
    );
115 116
  }

117
  drupal_add_library('system', 'drupal.form');
118

119 120 121 122 123 124 125 126 127 128
  return $form;
}

/**
 * Process result from user administration filter form.
 */
function user_filter_form_submit($form, &$form_state) {
  $op = $form_state['values']['op'];
  $filters = user_filters();
  switch ($op) {
129 130 131 132 133
    case t('Filter'):
    case t('Refine'):
      // Apply every filter that has a choice selected other than 'any'.
      foreach ($filters as $filter => $options) {
        if (isset($form_state['values'][$filter]) && $form_state['values'][$filter] != '[any]') {
134
          $_SESSION['user_overview_filter'][] = array($filter, $form_state['values'][$filter]);
135 136 137 138 139 140 141
        }
      }
      break;
    case t('Undo'):
      array_pop($_SESSION['user_overview_filter']);
      break;
    case t('Reset'):
142
      $_SESSION['user_overview_filter'] = array();
143 144 145 146 147
      break;
    case t('Update'):
      return;
  }

148
  $form_state['redirect'] = 'admin/people';
149 150 151 152 153 154 155
  return;
}

/**
 * Form builder; User administration page.
 *
 * @ingroup forms
156 157
 * @see user_admin_account_validate()
 * @see user_admin_account_submit()
158 159 160 161
 */
function user_admin_account() {

  $header = array(
162
    'username' => array('data' => t('Username'), 'field' => 'u.name'),
163 164 165 166
    'status' => array('data' => t('Status'), 'field' => 'u.status', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
    'roles' => array('data' => t('Roles'), 'class' => array(RESPONSIVE_PRIORITY_LOW)),
    'member_for' => array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
    'access' => array('data' => t('Last access'), 'field' => 'u.access', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
167
    'operations' => t('Operations'),
168 169
  );

170
  $query = db_select('users', 'u');
171 172
  $query->condition('u.uid', 0, '<>');
  user_build_filter_query($query);
173

174
  $count_query = clone $query;
175
  $count_query->addExpression('COUNT(u.uid)');
176

177 178
  $query = $query
    ->extend('Drupal\Core\Database\Query\PagerSelectExtender')
179
    ->extend('Drupal\Core\Database\Query\TableSortExtender');
180 181 182
  $query
    ->fields('u', array('uid', 'name', 'status', 'created', 'access'))
    ->limit(50)
183
    ->orderByHeader($header)
184 185
    ->setCountQuery($count_query);
  $result = $query->execute();
186 187

  $form['options'] = array(
188
    '#type' => 'details',
189
    '#title' => t('Update options'),
190
    '#attributes' => array('class' => array('container-inline')),
191 192 193 194 195 196 197
  );
  $options = array();
  foreach (module_invoke_all('user_operations') as $operation => $array) {
    $options[$operation] = $array['label'];
  }
  $form['options']['operation'] = array(
    '#type' => 'select',
198 199
    '#title' => t('Operation'),
    '#title_display' => 'invisible',
200 201 202
    '#options' => $options,
    '#default_value' => 'unblock',
  );
203
  $options = array();
204 205 206 207 208 209 210
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
  );

  $destination = drupal_get_destination();
  $status = array(t('blocked'), t('active'));
211
  $roles = array_map('check_plain', user_role_names(TRUE));
212
  $accounts = array();
213
  foreach ($result as $account) {
214
    $account = user_load($account->uid);
215
    $users_roles = array();
216 217
    $roles_result = db_query('SELECT rid FROM {users_roles} WHERE uid = :uid', array(':uid' => $account->uid));
    foreach ($roles_result as $user_role) {
218
      $users_roles[] = $roles[$user_role->rid];
219
    }
220
    asort($users_roles);
221

222
    $options[$account->uid] = array(
223
      'username' => theme('username', array('account' => $account)),
224
      'status' =>  $status[$account->status],
225
      'roles' => theme('item_list', array('items' => $users_roles)),
226 227
      'member_for' => format_interval(REQUEST_TIME - $account->created),
      'access' =>  $account->access ? t('@time ago', array('@time' => format_interval(REQUEST_TIME - $account->access))) : t('never'),
228 229 230
    );
    $links = array();
    $links['edit'] = array(
231
      'title' => t('Edit'),
232
      'href' => 'user/' . $account->uid . '/edit',
233 234
      'query' => $destination,
    );
235 236
    if (module_invoke('translation_entity', 'translate_access', $account)) {
      $links['translate'] = array(
237
        'title' => t('Translate'),
238 239 240 241
        'href' => 'user/' . $account->uid . '/translations',
        'query' => $destination,
      );
    }
242 243 244
    $options[$account->uid]['operations']['data'] = array(
      '#type' => 'operations',
      '#links' => $links,
245
    );
246
  }
247

248
  $form['accounts'] = array(
249 250 251 252
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $options,
    '#empty' => t('No people available.'),
253
  );
254
  $form['pager'] = array('#markup' => theme('pager'));
255 256 257 258 259 260 261 262

  return $form;
}

/**
 * Submit the user administration update form.
 */
function user_admin_account_submit($form, &$form_state) {
263
  $operations = module_invoke_all('user_operations', $form, $form_state);
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
  $operation = $operations[$form_state['values']['operation']];
  // Filter out unchecked accounts.
  $accounts = array_filter($form_state['values']['accounts']);
  if ($function = $operation['callback']) {
    // Add in callback arguments if present.
    if (isset($operation['callback arguments'])) {
      $args = array_merge(array($accounts), $operation['callback arguments']);
    }
    else {
      $args = array($accounts);
    }
    call_user_func_array($function, $args);

    drupal_set_message(t('The update has been performed.'));
  }
}

function user_admin_account_validate($form, &$form_state) {
  $form_state['values']['accounts'] = array_filter($form_state['values']['accounts']);
  if (count($form_state['values']['accounts']) == 0) {
    form_set_error('', t('No users selected.'));
  }
}

/**
 * Menu callback: administer permissions.
290
 *
291
 * @ingroup forms
292 293
 * @see user_admin_permissions_submit()
 * @see theme_user_admin_permissions()
294
 */
295
function user_admin_permissions($form, $form_state, $rid = NULL) {
296

297
  // Retrieve role names for columns.
298
  $role_names = user_role_names();
299
  if (isset($rid)) {
300
    $role_names = array($rid => $role_names[$rid]);
301
  }
302 303
  // Fetch permissions for all roles or the one selected role.
  $role_permissions = user_role_permissions($role_names);
304

305 306 307 308 309
  // Store $role_names for use when saving the data.
  $form['role_names'] = array(
    '#type' => 'value',
    '#value' => $role_names,
  );
310 311
  // Render role/permission overview:
  $options = array();
312
  $module_info = system_get_info('module');
313
  $hide_descriptions = system_admin_compact_mode();
314 315 316 317

  // Get a list of all the modules implementing a hook_permission() and sort by
  // display name.
  $modules = array();
318
  foreach (module_implements('permission') as $module) {
319
    $modules[$module] = $module_info[$module]['name'];
320
  }
321
  asort($modules);
322

323
  foreach ($modules as $module => $display_name) {
324
    if ($permissions = module_invoke($module, 'permission')) {
325
      $form['permission'][] = array(
326
        '#markup' => $module_info[$module]['name'],
327
        '#id' => $module,
328
      );
329
      foreach ($permissions as $perm => $perm_item) {
330 331 332 333 334 335
        // Fill in default values for the permission.
        $perm_item += array(
          'description' => '',
          'restrict access' => FALSE,
          'warning' => !empty($perm_item['restrict access']) ? t('Warning: Give to trusted roles only; this permission has security implications.') : '',
        );
336
        $options[$perm] = '';
337 338
        $form['permission'][$perm] = array(
          '#type' => 'item',
339
          '#markup' => $perm_item['title'],
340
          '#description' => theme('user_permission_description', array('permission_item' => $perm_item, 'hide' => $hide_descriptions)),
341
        );
342 343
        foreach ($role_names as $rid => $name) {
          // Builds arrays for checked boxes for each role
344
          if (isset($role_permissions[$rid][$perm])) {
345 346 347 348 349 350 351 352 353
            $status[$rid][] = $perm;
          }
        }
      }
    }
  }

  // Have to build checkboxes here after checkbox arrays are built
  foreach ($role_names as $rid => $name) {
354 355 356 357 358 359
    $form['checkboxes'][$rid] = array(
      '#type' => 'checkboxes',
      '#options' => $options,
      '#default_value' => isset($status[$rid]) ? $status[$rid] : array(),
      '#attributes' => array('class' => array('rid-' . $rid)),
    );
360
    $form['role_names'][$rid] = array('#markup' => check_plain($name), '#tree' => TRUE);
361
  }
362

363
  $form['actions'] = array('#type' => 'actions');
364
  $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save permissions'));
365

366
  $form['#attached']['library'][] = array('user', 'drupal.user.permissions');
367

368 369 370
  return $form;
}

371 372 373
/**
 * Save permissions selected on the administer permissions page.
 *
374
 * @see user_admin_permissions()
375
 */
376
function user_admin_permissions_submit($form, &$form_state) {
377
  foreach ($form_state['values']['role_names'] as $rid => $name) {
378
    user_role_change_permissions($rid, $form_state['values'][$rid]);
379 380 381 382
  }

  drupal_set_message(t('The changes have been saved.'));

383
  // Clear the cached pages and blocks.
384
  cache_invalidate_tags(array('content' => TRUE));
385 386 387
}

/**
388 389 390 391 392
 * Returns HTML for the administer permissions page.
 *
 * @param $variables
 *   An associative array containing:
 *   - form: A render element representing the form.
393 394 395
 *
 * @ingroup themeable
 */
396 397 398
function theme_user_admin_permissions($variables) {
  $form = $variables['form'];

399
  $roles = user_role_names();
400
  foreach (element_children($form['permission']) as $key) {
401 402 403
    $row = array();
    // Module name
    if (is_numeric($key)) {
404
      $row[] = array('data' => drupal_render($form['permission'][$key]), 'class' => array('module'), 'id' => 'module-' . $form['permission'][$key]['#id'], 'colspan' => count($form['role_names']['#value']) + 1);
405 406 407 408 409
    }
    else {
      // Permission row.
      $row[] = array(
        'data' => drupal_render($form['permission'][$key]),
410
        'class' => array('permission'),
411 412
      );
      foreach (element_children($form['checkboxes']) as $rid) {
413
        $form['checkboxes'][$rid][$key]['#title'] = $roles[$rid] . ': ' . $form['permission'][$key]['#markup'];
414 415
        $form['checkboxes'][$rid][$key]['#title_display'] = 'invisible';
        $row[] = array('data' => drupal_render($form['checkboxes'][$rid][$key]), 'class' => array('checkbox'));
416 417
      }
    }
418
    $rows[] = $row;
419 420 421
  }
  $header[] = (t('Permission'));
  foreach (element_children($form['role_names']) as $rid) {
422
    $header[] = array('data' => drupal_render($form['role_names'][$rid]), 'class' => array('checkbox'));
423
  }
424
  $output = theme('system_compact_link');
425
  $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'permissions')));
426
  $output .= drupal_render_children($form);
427 428 429
  return $output;
}

430
/**
431
 * Returns HTML for an individual permission description.
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
 *
 * @param $variables
 *   An associative array containing:
 *   - permission_item: An associative array representing the permission whose
 *     description is being themed. Useful keys include:
 *     - description: The text of the permission description.
 *     - warning: A security-related warning message about the permission (if
 *       there is one).
 *   - hide: A boolean indicating whether or not the permission description was
 *     requested to be hidden rather than shown.
 *
 * @ingroup themeable
 */
function theme_user_permission_description($variables) {
  if (!$variables['hide']) {
    $description = array();
    $permission_item = $variables['permission_item'];
    if (!empty($permission_item['description'])) {
      $description[] = $permission_item['description'];
    }
    if (!empty($permission_item['warning'])) {
      $description[] = '<em class="permission-warning">' . $permission_item['warning'] . '</em>';
    }
    if (!empty($description)) {
      return implode(' ', $description);
    }
  }
}

461
/**
462
 * Form to re-order roles or add a new one.
463
 *
464
 * @ingroup forms
465
 * @see theme_user_admin_roles()
466
 */
467
function user_admin_roles($form, $form_state) {
468
  $roles = user_roles();
469 470 471 472

  $form['roles'] = array(
    '#tree' => TRUE,
  );
473 474 475 476 477 478

  foreach ($roles as $rid => $role) {
    $form['roles'][$rid]['#role'] = $role;
    $form['roles'][$rid]['#weight'] = $role->weight;
    $form['roles'][$rid]['name'] = array(
      '#markup' => check_plain($role->label()),
479
    );
480
    $form['roles'][$rid]['weight'] = array(
481
      '#type' => 'textfield',
482
      '#title' => t('Weight for @title', array('@title' => $role->label())),
483
      '#title_display' => 'invisible',
484
      '#size' => 4,
485
      '#default_value' => $role->weight,
486
      '#attributes' => array('class' => array('role-weight')),
487
    );
488
    $links['edit'] = array(
489
      'title' => t('Edit role'),
490
      'href' => 'admin/people/roles/edit/' . $rid,
491 492 493
      'weight' => 0,
    );
    $links['permissions'] = array(
494
      'title' => t('Edit permissions'),
495
      'href' => 'admin/people/permissions/' . $rid,
496
      'weight' => 5,
497
    );
498
    $form['roles'][$rid]['operations'] = array(
499 500
      '#type' => 'operations',
      '#links' => $links,
501
    );
502 503
  }

504
  // Embed the role add form.
505 506 507 508
  $add_role = entity_create('user_role', array(
    'id' => NULL,
    'label' => NULL,
  ));
509 510 511 512 513 514 515
  $add_form = user_admin_role(array(), $form_state, $add_role);
  $add_form['actions']['submit']['#submit'] = array('user_admin_role_submit');
  $add_form['role']['actions'] = $add_form['actions'];
  unset($add_form['actions']);
  $form += $add_form;

  $form['actions']['#type'] = 'actions';
516
  $form['actions']['submit'] = array(
517 518
    '#type' => 'submit',
    '#value' => t('Save order'),
519 520
    // Do not validate the add form when saving the order.
    '#limit_validation_errors' => array(array('roles')),
521 522 523 524 525 526 527 528 529 530 531 532 533
    '#submit' => array('user_admin_roles_order_submit'),
  );

  return $form;
}

/**
 * Form submit function. Update the role weights.
 */
function user_admin_roles_order_submit($form, &$form_state) {
  foreach ($form_state['values']['roles'] as $rid => $role_values) {
    $role = $form['roles'][$rid]['#role'];
    $role->weight = $role_values['weight'];
534
    $role->save();
535
  }
536
  drupal_set_message(t('The role settings have been updated.'));
537 538 539
}

/**
540 541 542 543 544
 * Returns HTML for the role order and new role form.
 *
 * @param $variables
 *   An associative array containing:
 *   - form: A render element representing the form.
545 546 547 548 549 550
 *
 * @ingroup themeable
 */
function theme_user_admin_roles($variables) {
  $form = $variables['form'];

551
  $header = array(t('Name'), t('Weight'), t('Operations'));
552 553
  foreach (element_children($form['roles']) as $rid) {
    $row = array();
554 555
    foreach (element_children($form['roles'][$rid]) as $column) {
      $row[] = drupal_render($form['roles'][$rid][$column]);
556 557
    }
    $rows[] = array('data' => $row, 'class' => array('draggable'));
558
  }
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573

  // Distribute the role add form into table columns.
  $form['role']['name']['#title_display'] = 'invisible';
  unset($form['role']['name']['#description']);
  unset($form['role']['rid']['#description']);

  $actions = $form['role']['actions'];
  unset($form['role']['actions']);
  unset($form['role']['weight']);
  $row = array();
  $row[] = drupal_render($form['role']);
  // Empty placeholder for the weight column.
  $row[] = '';
  $row[] = array('data' => drupal_render($actions), 'colspan' => 2);
  $rows[] = array('data' => $row);
574 575 576 577 578 579 580 581 582 583 584 585 586 587

  drupal_add_tabledrag('user-roles', 'order', 'sibling', 'role-weight');

  $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'user-roles')));
  $output .= drupal_render_children($form);

  return $output;
}

/**
 * Form to configure a single role.
 *
 * @ingroup forms
 * @see user_admin_role_submit()
588 589
 *
 * @todo Move into a RoleFormController.
590 591
 */
function user_admin_role($form, $form_state, $role) {
592 593 594 595
  $form['role'] = array(
    '#tree' => TRUE,
    '#parents' => array('role'),
  );
596
  $form['role']['label'] = array(
597 598
    '#type' => 'textfield',
    '#title' => t('Role name'),
599
    '#default_value' => $role->label(),
600 601 602
    '#size' => 30,
    '#required' => TRUE,
    '#maxlength' => 64,
603
    '#description' => t('The name for this role. Example: "Moderator", "Editorial board", "Site architect".'),
604
  );
605
  $form['role']['id'] = array(
606
    '#type' => 'machine_name',
607
    '#default_value' => $role->id(),
608
    '#required' => TRUE,
609
    '#disabled' => !$role->isNew(),
610 611 612 613
    '#size' => 30,
    '#maxlength' => 64,
    '#machine_name' => array(
      'exists' => 'user_role_load',
614
      'source' => array('role', 'label'),
615
    ),
616
  );
617 618 619 620 621
  // @todo Remove once moved to RoleFormController.
  $form['role']['langcode'] = array(
    '#type' => 'value',
    '#value' => !$role->isNew() ? $role->langcode : language_default()->langcode,
  );
622
  $form['role']['weight'] = array(
623 624 625
    '#type' => 'value',
    '#value' => $role->weight,
  );
626
  $form['actions'] = array('#type' => 'actions');
627 628
  $form['actions']['submit'] = array(
    '#type' => 'submit',
629
    '#value' => !$role->isNew() ? t('Save role') : t('Add role'),
630 631 632 633
  );
  $form['actions']['delete'] = array(
    '#type' => 'submit',
    '#value' => t('Delete role'),
634
    '#access' => !$role->isNew() && !in_array($role->id(), array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID)),
635
    '#submit' => array('user_admin_role_delete_submit'),
636 637
  );

638 639 640
  return $form;
}

641 642 643
/**
 * Form submit handler for the user_admin_role() form.
 */
644
function user_admin_role_submit($form, &$form_state) {
645 646 647 648 649
  // Prevent leading and trailing spaces in role names.
  $form_state['values']['role']['label'] = trim($form_state['values']['role']['label']);

  $role = entity_create('user_role', $form_state['values']['role']);
  if ($role->save() == SAVED_UPDATED) {
650 651
    drupal_set_message(t('The role has been renamed.'));
  }
652
  else {
653 654
    drupal_set_message(t('The role has been added.'));
  }
655
  $form_state['redirect'] = 'admin/people/roles';
656 657
}

658 659 660 661
/**
 * Form submit handler for the user_admin_role() form.
 */
function user_admin_role_delete_submit($form, &$form_state) {
662
  $form_state['redirect'] = 'admin/people/roles/delete/' . $form_state['values']['role']['id'];
663 664 665 666 667 668
}

/**
 * Form to confirm role delete operation.
 */
function user_admin_role_delete_confirm($form, &$form_state, $role) {
669
  $form['id'] = array(
670
    '#type' => 'value',
671
    '#value' => $role->id(),
672
  );
673
  return confirm_form($form, t('Are you sure you want to delete the role %name ?', array('%name' => $role->label())), 'admin/people/roles', t('This action cannot be undone.'), t('Delete'));
674 675 676 677 678 679
}

/**
 * Form submit handler for user_admin_role_delete_confirm().
 */
function user_admin_role_delete_confirm_submit($form, &$form_state) {
680
  entity_delete_multiple('user_role', array($form_state['values']['id']));
681
  drupal_set_message(t('The role has been deleted.'));
682
  $form_state['redirect'] = 'admin/people/roles';
683
}