summaryrefslogtreecommitdiff
path: root/modules/user.module
diff options
context:
space:
mode:
Diffstat (limited to 'modules/user.module')
-rw-r--r--modules/user.module456
1 files changed, 184 insertions, 272 deletions
diff --git a/modules/user.module b/modules/user.module
index e8b18a029..c7fbe548c 100644
--- a/modules/user.module
+++ b/modules/user.module
@@ -7,10 +7,10 @@
* We cannot use module_invoke() for this, becuse the arguments need to
* be passed by reference.
*/
-function user_module_invoke($type, &$array, &$user) {
+function user_module_invoke($type, &$array, &$user, $category = NULL) {
foreach (module_list() as $module) {
$function = $module .'_user';
- if (function_exists($function)) $function($type, $array, $user);
+ if (function_exists($function)) $function($type, $array, $user, $category);
}
}
@@ -62,11 +62,11 @@ function user_load($array = array()) {
return $user;
}
-function user_save($account, $array = array()) {
+function user_save($account, $array = array(), $category = 'account') {
// Dynamically compose a SQL query:
$user_fields = user_fields();
if ($account->uid) {
- user_module_invoke('update', $array, $account);
+ user_module_invoke('update', $array, $account, $category);
$data = unserialize(db_result(db_query('SELECT data FROM {users} WHERE uid = %d', $account->uid)));
foreach ($array as $key => $value) {
@@ -92,10 +92,10 @@ function user_save($account, $array = array()) {
db_query("UPDATE {users} SET $query changed = %d WHERE uid = %d", array_merge($v, array(time(), $account->uid)));
// reload user roles if provided
- if (is_array($array['rid'])) {
+ if (is_array($array['roles'])) {
db_query('DELETE FROM {users_roles} WHERE uid = %d', $account->uid);
- foreach ($array['rid'] as $rid) {
+ foreach ($array['roles'] as $rid) {
db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $account->uid, $rid);
}
}
@@ -134,13 +134,13 @@ function user_save($account, $array = array()) {
// Reload user roles (delete just to be safe).
db_query('DELETE FROM {users_roles} WHERE uid = %d', $array['uid']);
- foreach ($array['rid'] as $rid) {
+ foreach ($array['roles'] as $rid) {
db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $array['uid'], $rid);
}
$user = user_load(array('name' => $array['name']));
- module_invoke_all('user', 'insert', $array, $user);
+ module_invoke_all('user', 'insert', $array, $user, $category);
}
foreach ($array as $key => $value) {
@@ -418,10 +418,22 @@ function user_search($keys) {
/**
* Implementation of hook_user().
*/
-function user_user($type, &$edit, &$user) {
+function user_user($type, &$edit, &$user, $category = NULL) {
if ($type == 'view') {
return array(t('History') => form_item(t('Member for'), format_interval(time() - $user->created)));
}
+
+ if ($type == 'form' && $category == 'account') {
+ return user_edit_form(arg(1), $edit);
+ }
+
+ if ($type == 'validate' && $category == 'account') {
+ return user_edit_validate(arg(1), $edit);
+ }
+
+ if ($type == 'categories') {
+ return array(array('name' => 'account', 'title' => t('account settings'), 'weight' => 1));
+ }
}
/**
@@ -595,12 +607,19 @@ function user_menu() {
if (arg(0) == 'user' && is_numeric(arg(1))) {
$items[] = array('path' => 'user/'. arg(1), 'title' => t('user'),
'callback' => 'user_page', 'access' => TRUE);
- // Add the edit menu:
- if ($access) $function = 'user_admin_edit';
- else $function = 'user_page';
$items[] = array('path' => 'user/'. arg(1) .'/edit', 'title' => t('edit'),
- 'callback' => $function, 'access' => $access || $user->uid == arg(1),
+ 'callback' => 'user_edit', 'access' => $access || $user->uid == arg(1),
'type' => MENU_LOCAL_TASK);
+
+ if (arg(2) == 'edit') {
+ if (($categories = _user_categories()) && (count($categories) > 1)) {
+ foreach ($categories as $key => $category) {
+ $items[] = array('path' => 'user/'. arg(1) .'/edit/'. $category['name'], 'title' => $category['title'],
+ 'callback' => $function, 'access' => $access || $user->uid == arg(1),
+ 'type' => MENU_LOCAL_SUBTASK, 'weight' => $category['weight']);
+ }
+ }
+ }
}
if ($user->uid) {
@@ -763,7 +782,7 @@ function user_login($edit = array(), $msg = '') {
if (module_hook($module, 'auth')) {
if (module_invoke($module, 'auth', $name, $pass, $server)) {
if (variable_get('user_register', 1) == 1 && !user_load(array('name' => "$name@$server"))) { // Register this new user.
- $user = user_save('', array('name' => "$name@$server", 'pass' => user_password(), 'init' => "$name@$server", 'status' => 1, "authname_$module" => "$name@$server", 'rid' => array(_user_authenticated_id())));
+ $user = user_save('', array('name' => "$name@$server", 'pass' => user_password(), 'init' => "$name@$server", 'status' => 1, "authname_$module" => "$name@$server", 'roles' => array(_user_authenticated_id())));
watchdog('user', "new user: $name@$server ($module ID)", l(t('edit user'), "user/$user->uid/edit"));
break;
}
@@ -919,34 +938,7 @@ function user_register($edit = array()) {
}
if ($edit) {
- if ($error = user_validate_name($edit['name'])) {
- form_set_error('name', $error);
- }
- else if ($error = user_validate_mail($edit['mail'])) {
- form_set_error('mail', $error);
- }
- else if (user_deny('user', $edit['name'])) {
- form_set_error('name', t('The name "%s" has been denied access.', array('%s' => $edit['name'])));
- }
- else if (user_deny('mail', $edit['mail'])) {
- form_set_error('mail', t('The e-mail address "%s" has been denied access.', array('%s' => $edit['mail'])));
- }
- else if (db_num_rows(db_query("SELECT name FROM {users} WHERE LOWER(name) = LOWER('%s')", $edit['name'])) > 0) {
- form_set_error('name', t('The name "%s" is already taken.', array('%s' => $edit['name'])));
- }
- else if (db_num_rows(db_query("SELECT mail FROM {users} WHERE LOWER(mail) = LOWER('%s') OR LOWER(init) = LOWER('%s')", $edit['mail'], $edit['mail'])) > 0) {
- form_set_error('mail', t('The e-mail address "%s" is already taken.', array('%s' => $edit['mail'])));
- }
- else {
- foreach (module_list() as $module) {
- if (module_hook($module, 'user')) {
- $result = module_invoke($module, 'user', 'validate', $edit, $user);
- if (is_array($result)) {
- $data = array_merge($data, $result);
- }
- }
- }
- }
+ _user_profile($edit, NULL, 'validate', 'account');
if (!form_has_errors()) {
$from = variable_get('site_mail', ini_get('sendmail_from'));
@@ -954,7 +946,7 @@ function user_register($edit = array()) {
// TODO: Is this necessary? Won't session_write() replicate this?
unset($edit['session']);
- $account = user_save('', array_merge(array('name' => $edit['name'], 'pass' => $pass, 'init' => $edit['mail'], 'mail' => $edit['mail'], 'rid' => array(_user_authenticated_id()), 'status' => (variable_get('user_register', 1) == 1 ? 1 : 0)), $data));
+ $account = user_save('', array_merge(array('name' => $edit['name'], 'pass' => $pass, 'init' => $edit['mail'], 'mail' => $edit['mail'], 'roles' => array(_user_authenticated_id()), 'status' => (variable_get('user_register', 1) == 1 ? 1 : 0)), $data));
watchdog('user', 'new user: "'. $edit['name'] .'" <'. $edit['mail'] .'>', l(t('edit user'), "admin/user/edit/$account->uid"));
$variables = array('%username' => $edit['name'], '%site' => variable_get('site_name', 'drupal'), '%password' => $pass, '%uri' => $base_url, '%uri_brief' => substr($base_url, strlen('http://')), '%mailto' => $edit['mail'], '%date' => format_date(time()), '%login_uri' => url('user/login', NULL, NULL, TRUE), '%edit_uri' => url('user/edit', NULL, NULL, TRUE));
@@ -1000,7 +992,6 @@ function user_register($edit = array()) {
}
$output .= form_textfield(t('Username'), 'name', $edit['name'], 30, 64, t('Your full name or your preferred username; only letters, numbers and spaces are allowed.'));
$output .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 64, t('A password and instructions will be sent to this e-mail address, so make sure it is accurate.'));
- $output .= _user_profile($edit, $edit);
$output .= form_submit(t('Create new account'));
$items[] = l(t('Request new password'), 'user/password');
$items[] = l(t('Log in'), 'user/login');
@@ -1010,120 +1001,118 @@ function user_register($edit = array()) {
return form($output);
}
-function user_edit($edit = array()) {
- global $user;
-
- if ($user->uid) {
- if (!(is_null($edit['name']) && is_null($edit['mail']))) {
- if ($error = user_validate_name($edit['name'])) {
- form_set_error('name', $error);
- }
- else if ($error = user_validate_mail($edit['mail'])) {
- form_set_error('mail', $error);
- }
- else if (db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != $user->uid AND LOWER(name) = LOWER('%s')", $edit['name'])) > 0) {
- form_set_error('name', t('The name "%s" is already taken.', array('%s' => $edit['name'])));
- }
- else if ($edit['mail'] && db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != $user->uid AND LOWER(mail) = LOWER('%s')", $edit['mail'])) > 0) {
- form_set_name('mail', t('The e-mail address "%s" is already taken.', array('%s' => $edit['mail'])));
- }
- else {
- // If required, validate the picture.
- if ($file = file_check_upload('picture')) {
- user_validate_picture($file, $edit, $user);
- }
-
- // If required, check that proposed passwords match. If so,
- // add new password to $edit.
- if ($edit['pass1']) {
- if ($edit['pass1'] == $edit['pass2']) {
- $edit['pass'] = $edit['pass1'];
- }
- else {
- form_set_error('pass2', t('The specified passwords do not match.'));
- }
- }
- unset($edit['pass1'], $edit['pass2']);
-
- // Validate input fields to make sure users don't submit
- // invalid form data.
- if (!user_access('administer users')) {
- if (array_intersect(array_keys($edit), array('rid', 'init', 'session'))) {
- watchdog('warning', 'detected malicious attempt to alter a protected database field');
- }
-
- $edit['rid'] = array_keys($user->roles);
- $edit['init'] = $user->init;
- $edit['session'] = $user->session;
- }
-
- // Have the modules that extend the user information validate
- // their data.
- foreach (module_list() as $module) {
- if (module_hook($module, 'user')) {
- $result = module_invoke($module, 'user', 'validate', $edit, $user);
- }
- if (is_array($result)) {
- $data = array_merge($data, $result);
- }
- }
+function user_edit_form($uid, $edit) {
+ // Account information:
+ $group = form_textfield(t('Username'), 'name', $edit['name'], 30, 55, t('Your full name or your preferred username: only letters, numbers and spaces are allowed.'));
+ $group .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 55, t('Insert a valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'));
+ $group .= form_item(t('Password'), '<input type="password" name="edit[pass1]" size="12" maxlength="24" /> <input type="password" name="edit[pass2]" size="12" maxlength="24" />', t('Enter your new password twice if you want to change your current password, or leave it blank if you are happy with your current password.'));
- if (!form_has_errors()) {
- // Save user information.
- $user = user_save($user, array_merge($edit, $data));
+ if (user_access('administer users')) {
+ $group .= form_radios(t('Status'), 'status', $edit['status'], array(t('Blocked'), t('Active')));
+ $group .= form_checkboxes(t('Roles'), 'roles', array_keys($edit['roles']), user_roles(1), t('Select at least one role. The user receives the combined permissions of all of the selected roles.'));
+ }
- drupal_set_message(t('your user information changes have been saved.'));
- }
- }
- }
+ $data[] = array('title' => t('Account information'), 'data' => $group, 'weight' => 0);
- if (!$edit) {
- $edit = object2array($user);
+ // Picture/avatar:
+ if (variable_get('user_pictures', 0)) {
+ $group = '';
+ if (file_exists($edit['picture'])) {
+ $group .= '<img src="'. file_create_url($edit['picture']) .'" alt="" title="" />';
}
+ $group .= form_file(t('Upload picture'), 'picture', 48, t('Your virtual face or picture. Maximum dimensions are %dimensions and the maximum size is %size kB.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'), '%size' => variable_get('user_picture_file_size', '30'))) .' '. variable_get('user_picture_guidelines', ''));
+ $data[] = array('title' => t('Picture'), 'data' => $group, 'weight' => 1);
+ }
- $group = form_textfield(t('Username'), 'name', $edit['name'], 30, 55, t('Your full name or your preferred username: only letters, numbers and spaces are allowed.'));
- $group .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 55, t('Insert a valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'));
- $group .= form_item(t('Password'), '<input type="password" name="edit[pass1]" size="12" maxlength="24" /> <input type="password" name="edit[pass2]" size="12" maxlength="24" />', t('Enter your new password twice if you want to change your current password, or leave it blank if you are happy with your current password.'));
- $output = form_group(t('Account information'), $group);
+ return $data;
+}
- if (variable_get('user_pictures', 0)) {
- $group = '';
- if (file_exists($user->picture)) {
- $group .= '<img src="'. file_create_url($edit['picture']) .'" alt="" title="" />';
- }
- $group .= form_file(t('Upload picture'), 'picture', 48, t('Your virtual face or picture. Maximum dimensions are %dimensions and the maximum size is %size kB.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'), '%size' => variable_get('user_picture_file_size', '30'))) .' '. variable_get('user_picture_guidelines', ''));
- $output .= form_group(t('Picture'), $group);
- }
+function user_edit_validate($uid, &$edit) {
+ // Validate the username:
+ if ($error = user_validate_name($edit['name'])) {
+ form_set_error('name', $error);
+ }
+ else if (db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != %d AND LOWER(name) = LOWER('%s')", $uid, $edit['name'])) > 0) {
+ form_set_error('name', t('The name "%s" is already taken.', array('%s' => $edit['name'])));
+ }
+ else if (user_deny('user', $edit['name'])) {
+ form_set_error('name', t('The name "%s" has been denied access.', array('%s' => $edit['name'])));
+ }
- $output .= _user_profile($edit, $user);
- $output .= form_submit(t('Save user information'));
+ // Validate the e-mail address:
+ if ($error = user_validate_mail($edit['mail'])) {
+ form_set_error('mail', $error);
+ }
+ else if (db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != %d AND LOWER(mail) = LOWER('%s')", $uid, $edit['mail'])) > 0) {
+ form_set_name('mail', t('The e-mail address "%s" is already taken.', array('%s' => $edit['mail'])));
+ }
+ else if (user_deny('mail', $edit['mail'])) {
+ form_set_error('mail', t('The e-mail address "%s" has been denied access.', array('%s' => $edit['mail'])));
+ }
- $output = form($output, 'post', 0, array('enctype' => 'multipart/form-data'));
- // The "enctype" attribute is required to upload files such as pictures.
+ // If required, validate the uploaded picture.
+ if ($file = file_check_upload('picture')) {
+ user_validate_picture($file, $edit, $user);
}
- else {
- $output = user_login();
+
+ // If required, check that proposed passwords match. If so, add the new password to $edit.
+ if ($edit['pass1']) {
+ if ($edit['pass1'] == $edit['pass2']) {
+ $edit['pass'] = $edit['pass1'];
+ }
+ else {
+ form_set_error('pass2', t('The specified passwords do not match.'));
+ }
}
+ unset($edit['pass1'], $edit['pass2']);
- return $output;
+ return $edit;
}
-function _user_profile($edit, $account, $mode = 'form') {
- $groups = array();
- foreach (module_list() as $module) {
- if ($data = module_invoke($module, 'user', $mode, $edit, $account)) {
- foreach ($data as $title => $form) {
- $groups[$title] .= $form;
+function user_edit($category = 'account') {
+ global $user;
+
+ $account = $user->uid != arg(1) ? user_load(array('uid' => arg(1))) : $user;
+ $edit = $_POST['op'] ? $_POST['edit'] : object2array($account);
+
+ if ($_POST['op'] == t('Save account')) {
+ _user_validate($edit, $account, $category);
+
+ if (!form_has_errors()) {
+ // Validate input to ensure that non-privileged users can't alter protected data.
+ if (!user_access('administer users') && array_intersect(array_keys($edit), array('uid', 'roles', 'init', 'session'))) {
+ watchdog('warning', 'detected malicious attempt to alter a protected database field');
+ }
+ else {
+ user_save($account, $edit, $category);
+ drupal_set_message(t('the changes have been saved.'));
+ drupal_goto("user/$account->uid");
}
}
}
+ else if ($_POST['op'] == t('Delete account')) {
+ if ($account->status == 0) {
+ db_query('DELETE FROM {users} WHERE uid = %d', $account->uid);
+ db_query('DELETE FROM {users_roles} WHERE uid = %d', $account->uid);
+ db_query('DELETE FROM {authmap} WHERE uid = %d', $account->uid);
+ drupal_set_message(t('the account has been deleted.'));
+ module_invoke_all('user', 'delete', $edit, $account);
+ print theme('page', user_admin_account());
+ drupal_goto('admin/user');
+ }
+ else {
+ drupal_set_message(t('failed to delete account: the account has to be blocked first.'), 'error');
+ }
+ }
- $output = '';
- foreach ($groups as $title => $form) {
- $output .= form_group($title, $form);
+ $output = _user_forms($edit, $account, $category);
+ $output .= form_submit(t('Save account'));
+ if (user_access('administer users')) {
+ $output .= form_submit(t('Delete account'));
}
+ $output = form($output, 'post', 0, array('enctype' => 'multipart/form-data'));
- return $output;
+ print theme('page', $output, $account->name);
}
function user_view($uid = 0) {
@@ -1197,16 +1186,9 @@ function user_page() {
break;
case t('Log in'):
case 'login':
- $output = user_login($edit);
+ $outpute= user_login($edit);
print theme('page', $output, t('Log in'));
break;
- case t('Save user information'):
- case 'edit':
- $output = user_edit($edit);
- $GLOBALS['theme'] = init_theme();
- print theme('page', $output);
- break;
- case t('Logout'):
case 'logout':
print user_logout();
break;
@@ -1283,24 +1265,13 @@ function user_configure_settings() {
function user_admin_create($edit = array()) {
- if ($edit['name'] || $edit['mail']) {
- if ($error = user_validate_name($edit['name'])) {
- form_set_error('name', $error);
- }
- else if ($error = user_validate_mail($edit['mail'])) {
- form_set_error('mail', $error);
- }
- else if (db_num_rows(db_query("SELECT name FROM {users} WHERE LOWER(name) = LOWER('%s')", $edit['name'])) > 0) {
- form_set_error('name', t('The name "%s" is already taken.', array('%s' => $edit['name'])));
- }
- else if (db_num_rows(db_query("SELECT mail FROM {users} WHERE LOWER(mail) = LOWER('%s')", $edit['mail'])) > 0) {
- form_set_error('mail', t('The e-mail address "%s" is already taken.', array('%s' => $edit['mail'])));
- }
+ if ($edit) {
+ _user_profile($edit, NULL, 'validate', 'account');
if (!form_has_errors()) {
watchdog('user', 'new user: "'. $edit['name'] .'" &lt;'. $edit['mail'] .'&gt;');
- user_save('', array('name' => $edit['name'], 'pass' => $edit['pass'], 'init' => $edit['mail'], 'mail' => $edit['mail'], 'rid' => array(_user_authenticated_id()), 'status' => 1));
+ user_save('', array('name' => $edit['name'], 'pass' => $edit['pass'], 'init' => $edit['mail'], 'mail' => $edit['mail'], 'roles' => array(_user_authenticated_id()), 'status' => 1));
drupal_set_message(t('created a new user account. No e-mail has been sent.'));
@@ -1310,7 +1281,6 @@ function user_admin_create($edit = array()) {
$output = form_textfield(t('Username'), 'name', $edit['name'], 30, 55, t('Provide the username of the new account.'));
$output .= form_textfield(t('E-mail address'), 'mail', $edit['mail'], 30, 55, t('Provide the e-mail address associated with the new account.'));
- $output .= _user_profile($edit, $edit);
$output .= form_textfield(t('Password'), 'pass', $edit['pass'], 30, 55, t('Provide a password for the new account.'));
$output .= form_submit(t('Create account'));
@@ -1498,116 +1468,6 @@ function user_admin_role($edit = array()) {
return $output;
}
-function user_admin_edit() {
- $op = $_POST['op'];
- $edit = $_POST['edit'];
- $id = arg(1);
-
- if ($account = user_load(array('uid' => $id))) {
- if ($op == t('Save account')) {
- // TODO: This display/edit/validate should be moved to a new profile
- // module implementing hook_user().
-
- if ($error = user_validate_name($edit['name'])) {
- form_set_error('name', $error);
- }
- else if ($error = user_validate_mail($edit['mail'])) {
- form_set_error('mail', $error);
- }
- else if (count($edit['rid']) < 1) {
- form_set_error('rid', t('The user must have at least one role.'));
- }
- else if (db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != %d AND LOWER(name) = LOWER('%s')", $account->uid, $edit['name'])) > 0) {
- form_set_error('name', t('The name "%s" is already taken.', array('%s' => $edit['name'])));
- }
- else if ($edit['mail'] && db_num_rows(db_query("SELECT uid FROM {users} WHERE uid != %d AND LOWER(mail) = LOWER('%s')", $account->uid, $edit['mail'])) > 0) {
- form_set_error('mail', t('The e-mail address "%s" is already taken.', array('%s' => $edit['mail'])));
- }
-
- // Validate fields added by other modules.
- foreach (module_list() as $module) {
- if (module_hook($module, 'user')) {
- $result = module_invoke($module, 'user', 'validate', $edit, $account);
- }
- if (is_array($result)) {
- $data = array_merge($data, $result);
- }
- }
-
- // If required, validate the picture.
- if ($file = file_check_upload('picture')) {
- user_validate_picture($file, $edit, $account);
- }
-
- // If required, check that proposed passwords match. If so,
- // add new password to $edit.
- if ($edit['pass1']) {
- if ($edit['pass1'] == $edit['pass2']) {
- $edit['pass'] = $edit['pass1'];
- }
- else {
- form_set_error('pass2', t('The specified passwords do not match.'));
- }
- }
-
- unset($edit['pass1'], $edit['pass2']);
- if (!form_has_errors()) {
- $account = user_save($account, array_merge($edit, $data));
- drupal_set_message(t('the user information changes have been saved.'));
- }
- }
- else if ($op == t('Delete account')) {
- if ($edit['status'] == 0) {
- db_query('DELETE FROM {users} WHERE uid = %d', $account->uid);
- db_query('DELETE FROM {users_roles} WHERE uid = %d', $account->uid);
- db_query('DELETE FROM {authmap} WHERE uid = %d', $account->uid);
- drupal_set_message(t('the account has been deleted.'));
- module_invoke_all('user', 'delete', $edit, $account);
- print theme('page', user_admin_account());
- return;
- }
- else {
- drupal_set_message(t('failed to delete account: the account has to be blocked first.'), 'error');
- }
- }
-
- if (!$edit) {
- $edit = object2array($account);
- }
-
- // Display user form:
- $group = form_item(t('User ID'), $account->uid);
- $group .= form_textfield(t('Username'), 'name', $account->name, 30, 55, t('Your full name or your preferred username: only letters, numbers and spaces are allowed.'));
- $group .= form_textfield(t('E-mail address'), 'mail', $account->mail, 30, 55, t('Insert a valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.'));
- $group .= form_item(t('Password'), '<input type="password" name="edit[pass1]" size="12" maxlength="24" /> <input type="password" name="edit[pass2]" size="12" maxlength="24" />', t('Enter a new password twice if you want to change the current password for this user or leave it blank if you are happy with the current password.'));
- $group .= form_radios(t('Status'), 'status', $account->status, array(t('Blocked'), t('Active')));
- $group .= form_checkboxes(t('Roles'), 'rid', array_keys($account->roles), user_roles(1), t('Select at least one role. The user receives the combined permissions of all of the selected roles.'));
-
- $output = form_group(t('Account information'), $group);
-
- if (variable_get('user_pictures', 0)) {
- $group = '';
- if (file_exists($account->picture)) {
- $group .= '<img src="'. file_create_url($account->picture) .'" alt="" title="" />';
- }
- $group .= form_file(t('Upload picture or picture'), 'picture', 48, t('Maximum dimensions are %dimensions and the maximum size is %size kB.', array('%dimensions' => variable_get('user_picture_dimensions', '85x85'), '%size' => variable_get('user_picture_file_size', '30'))));
- $output .= form_group(t('Picture'), $group);
- }
-
- $output .= _user_profile($edit, $account, 'form');
-
- $output .= form_submit(t('Save account'));
- $output .= form_submit(t('Delete account'));
-
- $output = form($output, 'post', 0, array('enctype' => 'multipart/form-data'));
-
- print theme('page', $output, $account->name);
- }
- else {
- print theme('page', t('No such user'));
- }
-}
-
function user_admin_account() {
$header = array(
array('data' => t('ID'), 'field' => 'u.uid'),
@@ -1780,4 +1640,56 @@ function user_help_page() {
print theme('page', user_help('admin/help#user'));
}
+/**
+ * Retrieve a list of all user setting/information categories and sort them by weight.
+ */
+function _user_categories() {
+ $categories = array();
+
+ foreach (module_list() as $module) {
+ if ($data = module_invoke($module, 'user', 'categories')) {
+ foreach ($data as $category) {
+ $categories[$category['weight']] = $category;
+ }
+ }
+ }
+
+ return $categories;
+}
+
+function _user_sort($a, $b) {
+ return $a['weight'] < $b['weight'] ? -1 : ($a['weight'] > $b['weight'] ? 1 : ($a['title'] < $b['title'] ? -1 : 1));
+}
+
+/**
+ * Retrieve a list of all form elements for the specified category.
+ */
+function _user_forms(&$edit, $account, $category) {
+ $groups = array();
+ foreach (module_list() as $module) {
+ if ($data = module_invoke($module, 'user', 'form', $edit, $account, $category)) {
+ $groups = array_merge($data, $groups);
+ }
+ }
+
+ usort($groups, '_user_sort');
+
+ $output = '';
+ foreach ($groups as $group) {
+ $output .= form_group($group['title'], $group['data']);
+ }
+
+ return $output;
+}
+
+/**
+ * Validate the user data for the specified category.
+ */
+function _user_validate(&$edit, $account, $category) {
+ foreach (module_list() as $module) {
+ module_invoke($module, 'user', 'validate', $edit, $account, $category);
+ }
+}
+
+
?>