Index: modules/user/user.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.admin.inc,v
retrieving revision 1.67
diff -u -p -r1.67 user.admin.inc
--- modules/user/user.admin.inc 11 Aug 2009 11:47:58 -0000 1.67
+++ modules/user/user.admin.inc 14 Aug 2009 07:21:34 -0000
@@ -6,24 +6,20 @@
* Admin page callback file for the user module.
*/
-function user_admin($callback_arg = '') {
- $op = isset($_POST['op']) ? $_POST['op'] : $callback_arg;
-
- switch ($op) {
- case t('Create new account'):
- case 'create':
- $build['user_register'] = drupal_get_form('user_register');
- break;
- default:
- if (!empty($_POST['accounts']) && isset($_POST['operation']) && ($_POST['operation'] == 'cancel')) {
- $build['user_multiple_cancel_confirm'] = drupal_get_form('user_multiple_cancel_confirm');
- }
- else {
- $build['user_filter_form'] = drupal_get_form('user_filter_form');
- $build['user_admin_account'] = drupal_get_form('user_admin_account');
- }
+/**
+ * Form builder; Return user administration forms.
+ *
+ * @ingroup forms
+ */
+function user_admin_form(&$form_state) {
+ if (!empty($form_state['values']['accounts']) && isset($form_state['values']['operation']) && ($form_state['values']['operation'] == 'cancel')) {
+ return user_multiple_cancel_confirm($form_state);
+ }
+ else {
+ $form = user_filter_form();
+ $form['user_admin_account'] = user_admin_account();
+ return $form;
}
- return $build;
}
/**
@@ -42,6 +38,7 @@ function user_filter_form() {
'#title' => t('Show only users where'),
'#theme' => 'user_filters',
);
+ $form['#submit'][] = 'user_filter_form_submit';
foreach ($session as $filter) {
list($type, $value) = $filter;
// Merge an array of arrays into one if necessary.
@@ -82,8 +79,6 @@ function user_filter_form() {
);
}
- drupal_add_js('misc/form.js');
-
return $form;
}
@@ -94,12 +89,14 @@ function user_filter_form_submit($form,
$op = $form_state['values']['op'];
$filters = user_filters();
switch ($op) {
- case t('Filter'): case t('Refine'):
- if (isset($form_state['values']['filter'])) {
+ case t('Filter'):
+ case t('Refine'):
+ if (!empty($form_state['values']['filter'])) {
$filter = $form_state['values']['filter'];
- // Merge an array of arrays into one if necessary.
- $options = $filter == 'permission' ? call_user_func_array('array_merge', $filters[$filter]['options']) : $filters[$filter]['options'];
- if (isset($options[$form_state['values'][$filter]])) {
+ // Flatten the options array to accommodate hierarchical/nested options.
+ $flat_options = form_options_flatten($filters[$filter]['options']);
+
+ if (isset($flat_options[$form_state['values'][$filter]])) {
$_SESSION['user_overview_filter'][] = array($filter, $form_state['values'][$filter]);
}
}
@@ -113,9 +110,6 @@ function user_filter_form_submit($form,
case t('Update'):
return;
}
-
- $form_state['redirect'] = 'admin/people';
- return;
}
/**
@@ -153,6 +147,8 @@ function user_admin_account() {
->setCountQuery($count_query);
$result = $query->execute();
+ $form['#theme'] = 'user_admin_account';
+
$form['options'] = array(
'#type' => 'fieldset',
'#title' => t('Update options'),
@@ -171,6 +167,8 @@ function user_admin_account() {
$form['options']['submit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
+ '#submit' => array('user_admin_account_submit'),
+ '#validate' => array('user_admin_account_validate'),
);
$destination = drupal_get_destination();
@@ -221,6 +219,10 @@ function user_admin_account_submit($form
call_user_func_array($function, $args);
drupal_set_message(t('The update has been performed.'));
+ } else {
+ // We need to rebuild the form to go to a second step. For example, to
+ // show the confirmation form for the deletion of nodes.
+ $form_state['rebuild'] = TRUE;
}
}
@@ -973,3 +975,83 @@ function user_modules_uninstalled($modul
->execute();
}
}
+
+/**
+ * Form builder; Mass-account cancellation form.
+ *
+ * @ingroup forms
+ * @see user_multiple_cancel_confirm_submit()
+ */
+function user_multiple_cancel_confirm(&$form_state) {
+ $edit = $form_state['input'];
+
+ $form['#submit'][] = 'user_multiple_cancel_confirm_submit';
+ $form['accounts'] = array('#prefix' => '
', '#tree' => TRUE);
+ // array_filter() returns only elements with TRUE values.
+ foreach (array_filter($edit['accounts']) as $uid => $value) {
+ $user = db_query('SELECT name FROM {users} WHERE uid = :uid', array(':uid' => $uid))->fetchField();
+ $form['accounts'][$uid] = array('#type' => 'hidden', '#value' => $uid, '#prefix' => '', '#suffix' => check_plain($user) . "\n");
+ }
+
+ $form['operation'] = array('#type' => 'hidden', '#value' => 'cancel');
+
+ module_load_include('inc', 'user', 'user.pages');
+ $form['user_cancel_method'] = array(
+ '#type' => 'item',
+ '#title' => t('When cancelling these accounts'),
+ );
+ $form['user_cancel_method'] += user_cancel_methods();
+ // Remove method descriptions.
+ foreach (element_children($form['user_cancel_method']) as $element) {
+ unset($form['user_cancel_method'][$element]['#description']);
+ }
+
+ // Allow to send the account cancellation confirmation mail.
+ $form['user_cancel_confirm'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Require e-mail confirmation to cancel account.'),
+ '#default_value' => FALSE,
+ '#description' => t('When enabled, the user must confirm the account cancellation via e-mail.'),
+ );
+ // Also allow to send account canceled notification mail, if enabled.
+ $form['user_cancel_notify'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Notify user when account is canceled.'),
+ '#default_value' => FALSE,
+ '#access' => variable_get('user_mail_status_canceled_notify', FALSE),
+ '#description' => t('When enabled, the user will receive an e-mail notification after the account has been cancelled.'),
+ );
+
+ return confirm_form($form,
+ t('Are you sure you want to cancel these user accounts?'),
+ 'admin/people', t('This action cannot be undone.'),
+ t('Cancel accounts'), t('Cancel'));
+}
+
+/**
+ * Submit handler for mass-account cancellation form.
+ *
+ * @see user_multiple_cancel_confirm()
+ * @see user_cancel_confirm_form_submit()
+ */
+function user_multiple_cancel_confirm_submit($form, &$form_state) {
+ global $user;
+
+ if ($form_state['values']['confirm']) {
+ foreach ($form_state['values']['accounts'] as $uid => $value) {
+ // Prevent user administrators from deleting themselves without confirmation.
+ if ($uid == $user->uid) {
+ $admin_form_state = $form_state;
+ unset($admin_form_state['values']['user_cancel_confirm']);
+ $admin_form_state['values']['_account'] = $user;
+ drupal_function_exists('user_cancel_confirm_form_submit');
+ user_cancel_confirm_form_submit(array(), $admin_form_state);
+ }
+ else {
+ user_cancel($form_state['values'], $uid, $form_state['values']['user_cancel_method']);
+ }
+ }
+ }
+ $form_state['redirect'] = 'admin/people';
+ return;
+}
Index: modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.1021
diff -u -p -r1.1021 user.module
--- modules/user/user.module 12 Aug 2009 12:36:05 -0000 1.1021
+++ modules/user/user.module 14 Aug 2009 07:21:36 -0000
@@ -1316,8 +1316,8 @@ function user_menu() {
// User administration pages.
$items['admin/people'] = array(
'title' => 'People',
- 'page callback' => 'user_admin',
- 'page arguments' => array('list'),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('user_admin_form'),
'access arguments' => array('administer users'),
'weight' => -4,
);
@@ -1328,7 +1328,8 @@ function user_menu() {
);
$items['admin/people/create'] = array(
'title' => 'Add user',
- 'page arguments' => array('create'),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('user_register'),
'access arguments' => array('administer users'),
'type' => MENU_LOCAL_TASK,
);
@@ -1400,8 +1401,8 @@ function user_menu() {
$items['user/%user/edit'] = array(
'title' => 'Edit',
- 'page callback' => 'user_edit',
- 'page arguments' => array(1),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('user_profile_form', 1),
'access callback' => 'user_edit_access',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
@@ -1420,8 +1421,8 @@ function user_menu() {
$items['user/%user_category/edit/' . $category['name']] = array(
'title callback' => 'check_plain',
'title arguments' => array($category['title']),
- 'page callback' => 'user_edit',
- 'page arguments' => array(1, 3),
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('user_profile_form', 1, 3),
'access callback' => isset($category['access callback']) ? $category['access callback'] : 'user_edit_access',
'access arguments' => isset($category['access arguments']) ? $category['access arguments'] : array(1),
'type' => MENU_LOCAL_TASK,
@@ -2218,6 +2219,7 @@ function user_user_operations($form_stat
),
'cancel' => array(
'label' => t('Cancel the selected user accounts'),
+ 'callback' => NULL,
),
);
@@ -2330,78 +2332,6 @@ function user_multiple_role_edit($accoun
}
}
-function user_multiple_cancel_confirm(&$form_state) {
- $edit = $form_state['input'];
-
- $form['accounts'] = array('#prefix' => '', '#tree' => TRUE);
- // array_filter() returns only elements with TRUE values.
- foreach (array_filter($edit['accounts']) as $uid => $value) {
- $user = db_query('SELECT name FROM {users} WHERE uid = :uid', array(':uid' => $uid))->fetchField();
- $form['accounts'][$uid] = array('#type' => 'hidden', '#value' => $uid, '#prefix' => '', '#suffix' => check_plain($user) . "\n");
- }
-
- $form['operation'] = array('#type' => 'hidden', '#value' => 'cancel');
-
- module_load_include('inc', 'user', 'user.pages');
- $form['user_cancel_method'] = array(
- '#type' => 'item',
- '#title' => t('When cancelling these accounts'),
- );
- $form['user_cancel_method'] += user_cancel_methods();
- // Remove method descriptions.
- foreach (element_children($form['user_cancel_method']) as $element) {
- unset($form['user_cancel_method'][$element]['#description']);
- }
-
- // Allow to send the account cancellation confirmation mail.
- $form['user_cancel_confirm'] = array(
- '#type' => 'checkbox',
- '#title' => t('Require e-mail confirmation to cancel account.'),
- '#default_value' => FALSE,
- '#description' => t('When enabled, the user must confirm the account cancellation via e-mail.'),
- );
- // Also allow to send account canceled notification mail, if enabled.
- $form['user_cancel_notify'] = array(
- '#type' => 'checkbox',
- '#title' => t('Notify user when account is canceled.'),
- '#default_value' => FALSE,
- '#access' => variable_get('user_mail_status_canceled_notify', FALSE),
- '#description' => t('When enabled, the user will receive an e-mail notification after the account has been cancelled.'),
- );
-
- return confirm_form($form,
- t('Are you sure you want to cancel these user accounts?'),
- 'admin/people', t('This action cannot be undone.'),
- t('Cancel accounts'), t('Cancel'));
-}
-
-/**
- * Submit handler for mass-account cancellation form.
- *
- * @see user_multiple_cancel_confirm()
- * @see user_cancel_confirm_form_submit()
- */
-function user_multiple_cancel_confirm_submit($form, &$form_state) {
- global $user;
-
- if ($form_state['values']['confirm']) {
- foreach ($form_state['values']['accounts'] as $uid => $value) {
- // Prevent user administrators from deleting themselves without confirmation.
- if ($uid == $user->uid) {
- $admin_form_state = $form_state;
- unset($admin_form_state['values']['user_cancel_confirm']);
- $admin_form_state['values']['_account'] = $user;
- user_cancel_confirm_form_submit(array(), $admin_form_state);
- }
- else {
- user_cancel($form_state['values'], $uid, $form_state['values']['user_cancel_method']);
- }
- }
- }
- $form_state['redirect'] = 'admin/people';
- return;
-}
-
/**
* Implement hook_help().
*/
Index: modules/user/user.pages.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.pages.inc,v
retrieving revision 1.48
diff -u -p -r1.48 user.pages.inc
--- modules/user/user.pages.inc 12 Aug 2009 12:36:05 -0000 1.48
+++ modules/user/user.pages.inc 14 Aug 2009 07:21:36 -0000
@@ -225,18 +225,6 @@ function template_preprocess_user_profil
}
/**
- * Form builder; Present the form to edit a given user or profile category.
- *
- * @ingroup forms
- * @see user_edit_validate()
- * @see user_edit_submit()
- */
-function user_edit($account, $category = 'account') {
- drupal_set_title($account->name);
- return drupal_get_form('user_profile_form', $account, $category);
-}
-
-/**
* Form builder; edit a user account or one of their profile categories.
*
* @ingroup forms
@@ -247,6 +235,8 @@ function user_edit($account, $category =
function user_profile_form($form_state, $account, $category = 'account') {
global $user;
+ drupal_set_title($account->name);
+
$edit = (empty($form_state['values'])) ? (array)$account : $form_state['values'];
$form = _user_forms($edit, $account, $category);
@@ -262,7 +252,7 @@ function user_profile_form($form_state,
'#type' => 'submit',
'#value' => t('Cancel account'),
'#weight' => 31,
- '#submit' => array('user_edit_cancel_submit'),
+ '#submit' => array('user_profile_form_cancel_submit'),
);
}
@@ -309,7 +299,7 @@ function user_profile_form_submit($form,
/**
* Submit function for the 'Cancel account' button on the user edit form.
*/
-function user_edit_cancel_submit($form, &$form_state) {
+function user_profile_form_cancel_submit($form, &$form_state) {
$destination = '';
if (isset($_REQUEST['destination'])) {
$destination = drupal_get_destination();
@@ -323,7 +313,7 @@ function user_edit_cancel_submit($form,
* Form builder; confirm form for cancelling user account.
*
* @ingroup forms
- * @see user_edit_cancel_submit()
+ * @see user_profile_form_cancel_submit()
*/
function user_cancel_confirm_form(&$form_state, $account) {
global $user;
@@ -517,30 +507,6 @@ function user_cancel_confirm($account, $
drupal_access_denied();
}
-function user_edit_validate($form, &$form_state) {
- user_module_invoke('validate', $form_state['values'], $form_state['values']['_account'], $form_state['values']['_category']);
- // Validate input to ensure that non-privileged users can't alter protected data.
- if ((!user_access('administer users') && array_intersect(array_keys($form_state['values']), array('uid', 'init', 'session'))) || (!user_access('administer permissions') && isset($form_state['values']['roles']))) {
- watchdog('security', 'Detected malicious attempt to alter protected user fields.', array(), WATCHDOG_WARNING);
- // set this to a value type field
- form_set_error('category', t('Detected malicious attempt to alter protected user fields.'));
- }
-}
-
-function user_edit_submit($form, &$form_state) {
- $account = $form_state['values']['_account'];
- $category = $form_state['values']['_category'];
- unset($form_state['values']['_account'], $form_state['values']['op'], $form_state['values']['submit'], $form_state['values']['cancel'], $form_state['values']['form_token'], $form_state['values']['form_id'], $form_state['values']['_category'], $form_state['values']['form_build_id']);
- user_module_invoke('submit', $form_state['values'], $account, $category);
- user_save($account, $form_state['values'], $category);
-
- // Clear the page cache because pages can contain usernames and/or profile information:
- cache_clear_all();
-
- drupal_set_message(t('The changes have been saved.'));
- return;
-}
-
/**
* Access callback for path /user.
*