| 1 |
<?php
|
| 2 |
// $Id: user.admin.inc,v 1.87 2009/10/27 04:08:42 webchick Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Admin page callback file for the user module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
function user_admin($callback_arg = '') {
|
| 10 |
$op = isset($_POST['op']) ? $_POST['op'] : $callback_arg;
|
| 11 |
|
| 12 |
switch ($op) {
|
| 13 |
case t('Create new account'):
|
| 14 |
case 'create':
|
| 15 |
$build['user_register'] = drupal_get_form('user_register_form');
|
| 16 |
break;
|
| 17 |
default:
|
| 18 |
if (!empty($_POST['accounts']) && isset($_POST['operation']) && ($_POST['operation'] == 'cancel')) {
|
| 19 |
$build['user_multiple_cancel_confirm'] = drupal_get_form('user_multiple_cancel_confirm');
|
| 20 |
}
|
| 21 |
else {
|
| 22 |
$build['user_filter_form'] = drupal_get_form('user_filter_form');
|
| 23 |
$build['user_admin_account'] = drupal_get_form('user_admin_account');
|
| 24 |
}
|
| 25 |
}
|
| 26 |
return $build;
|
| 27 |
}
|
| 28 |
|
| 29 |
/**
|
| 30 |
* Form builder; Return form for user administration filters.
|
| 31 |
*
|
| 32 |
* @ingroup forms
|
| 33 |
* @see user_filter_form_submit()
|
| 34 |
*/
|
| 35 |
function user_filter_form() {
|
| 36 |
$session = isset($_SESSION['user_overview_filter']) ? $_SESSION['user_overview_filter'] : array();
|
| 37 |
$filters = user_filters();
|
| 38 |
|
| 39 |
$i = 0;
|
| 40 |
$form['filters'] = array(
|
| 41 |
'#type' => 'fieldset',
|
| 42 |
'#title' => t('Show only users where'),
|
| 43 |
'#theme' => 'user_filters',
|
| 44 |
);
|
| 45 |
foreach ($session as $filter) {
|
| 46 |
list($type, $value) = $filter;
|
| 47 |
// Merge an array of arrays into one if necessary.
|
| 48 |
$options = $type == 'permission' ? call_user_func_array('array_merge', $filters[$type]['options']) : $filters[$type]['options'];
|
| 49 |
$params = array('%property' => $filters[$type]['title'] , '%value' => $options[$value]);
|
| 50 |
if ($i++ > 0) {
|
| 51 |
$form['filters']['current'][] = array('#markup' => t('<em>and</em> where <strong>%property</strong> is <strong>%value</strong>', $params));
|
| 52 |
}
|
| 53 |
else {
|
| 54 |
$form['filters']['current'][] = array('#markup' => t('<strong>%property</strong> is <strong>%value</strong>', $params));
|
| 55 |
}
|
| 56 |
}
|
| 57 |
|
| 58 |
foreach ($filters as $key => $filter) {
|
| 59 |
$names[$key] = $filter['title'];
|
| 60 |
$form['filters']['status'][$key] = array(
|
| 61 |
'#type' => 'select',
|
| 62 |
'#options' => $filter['options'],
|
| 63 |
);
|
| 64 |
}
|
| 65 |
|
| 66 |
$form['filters']['filter'] = array(
|
| 67 |
'#type' => 'radios',
|
| 68 |
'#options' => $names,
|
| 69 |
);
|
| 70 |
$form['filters']['buttons']['submit'] = array(
|
| 71 |
'#type' => 'submit',
|
| 72 |
'#value' => (count($session) ? t('Refine') : t('Filter')),
|
| 73 |
);
|
| 74 |
if (count($session)) {
|
| 75 |
$form['filters']['buttons']['undo'] = array(
|
| 76 |
'#type' => 'submit',
|
| 77 |
'#value' => t('Undo'),
|
| 78 |
);
|
| 79 |
$form['filters']['buttons']['reset'] = array(
|
| 80 |
'#type' => 'submit',
|
| 81 |
'#value' => t('Reset'),
|
| 82 |
);
|
| 83 |
}
|
| 84 |
|
| 85 |
drupal_add_js('misc/form.js');
|
| 86 |
|
| 87 |
return $form;
|
| 88 |
}
|
| 89 |
|
| 90 |
/**
|
| 91 |
* Process result from user administration filter form.
|
| 92 |
*/
|
| 93 |
function user_filter_form_submit($form, &$form_state) {
|
| 94 |
$op = $form_state['values']['op'];
|
| 95 |
$filters = user_filters();
|
| 96 |
switch ($op) {
|
| 97 |
case t('Filter'): case t('Refine'):
|
| 98 |
if (isset($form_state['values']['filter'])) {
|
| 99 |
$filter = $form_state['values']['filter'];
|
| 100 |
// Merge an array of arrays into one if necessary.
|
| 101 |
$options = $filter == 'permission' ? call_user_func_array('array_merge', $filters[$filter]['options']) : $filters[$filter]['options'];
|
| 102 |
if (isset($options[$form_state['values'][$filter]])) {
|
| 103 |
$_SESSION['user_overview_filter'][] = array($filter, $form_state['values'][$filter]);
|
| 104 |
}
|
| 105 |
}
|
| 106 |
break;
|
| 107 |
case t('Undo'):
|
| 108 |
array_pop($_SESSION['user_overview_filter']);
|
| 109 |
break;
|
| 110 |
case t('Reset'):
|
| 111 |
$_SESSION['user_overview_filter'] = array();
|
| 112 |
break;
|
| 113 |
case t('Update'):
|
| 114 |
return;
|
| 115 |
}
|
| 116 |
|
| 117 |
$form_state['redirect'] = 'admin/people';
|
| 118 |
return;
|
| 119 |
}
|
| 120 |
|
| 121 |
/**
|
| 122 |
* Form builder; User administration page.
|
| 123 |
*
|
| 124 |
* @ingroup forms
|
| 125 |
* @see user_admin_account_validate()
|
| 126 |
* @see user_admin_account_submit()
|
| 127 |
*/
|
| 128 |
function user_admin_account() {
|
| 129 |
|
| 130 |
$header = array(
|
| 131 |
'username' => array('data' => t('Username'), 'field' => 'u.name'),
|
| 132 |
'status' => array('data' => t('Status'), 'field' => 'u.status'),
|
| 133 |
'roles' => array('data' => t('Roles')),
|
| 134 |
'member_for' => array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'),
|
| 135 |
'access' => array('data' => t('Last access'), 'field' => 'u.access'),
|
| 136 |
'operations' => array('data' => t('Operations')),
|
| 137 |
);
|
| 138 |
|
| 139 |
$query = db_select('users', 'u');
|
| 140 |
$query->leftJoin('users_roles', 'ur', 'u.uid = ur.uid');
|
| 141 |
$query->condition('u.uid', 0, '<>');
|
| 142 |
user_build_filter_query($query);
|
| 143 |
|
| 144 |
$count_query = clone $query;
|
| 145 |
$count_query->addExpression('COUNT(DISTINCT u.uid)');
|
| 146 |
|
| 147 |
$query = $query->extend('PagerDefault')->extend('TableSort');
|
| 148 |
$query
|
| 149 |
->fields('u', array('uid', 'name', 'status', 'created', 'access'))
|
| 150 |
->limit(50)
|
| 151 |
->orderByHeader($header)
|
| 152 |
->setCountQuery($count_query);
|
| 153 |
$result = $query->execute();
|
| 154 |
|
| 155 |
$form['options'] = array(
|
| 156 |
'#type' => 'fieldset',
|
| 157 |
'#title' => t('Update options'),
|
| 158 |
'#prefix' => '<div class="container-inline">',
|
| 159 |
'#suffix' => '</div>',
|
| 160 |
);
|
| 161 |
$options = array();
|
| 162 |
foreach (module_invoke_all('user_operations') as $operation => $array) {
|
| 163 |
$options[$operation] = $array['label'];
|
| 164 |
}
|
| 165 |
$form['options']['operation'] = array(
|
| 166 |
'#type' => 'select',
|
| 167 |
'#options' => $options,
|
| 168 |
'#default_value' => 'unblock',
|
| 169 |
);
|
| 170 |
$options = array();
|
| 171 |
$form['options']['submit'] = array(
|
| 172 |
'#type' => 'submit',
|
| 173 |
'#value' => t('Update'),
|
| 174 |
);
|
| 175 |
|
| 176 |
$destination = drupal_get_destination();
|
| 177 |
|
| 178 |
$status = array(t('blocked'), t('active'));
|
| 179 |
$roles = user_roles(TRUE);
|
| 180 |
$accounts = array();
|
| 181 |
foreach ($result as $account) {
|
| 182 |
$users_roles = array();
|
| 183 |
$roles_result = db_query('SELECT rid FROM {users_roles} WHERE uid = :uid', array(':uid' => $account->uid));
|
| 184 |
foreach ($roles_result as $user_role) {
|
| 185 |
$users_roles[] = $roles[$user_role->rid];
|
| 186 |
}
|
| 187 |
asort($users_roles);
|
| 188 |
|
| 189 |
$options[$account->uid] = array(
|
| 190 |
'username' => theme('username', array('account' => $account)),
|
| 191 |
'status' => $status[$account->status],
|
| 192 |
'roles' => theme('item_list', array('items' => $users_roles)),
|
| 193 |
'member_for' => format_interval(REQUEST_TIME - $account->created),
|
| 194 |
'access' => $account->access ? t('@time ago', array('@time' => format_interval(REQUEST_TIME - $account->access))) : t('never'),
|
| 195 |
'operations' => array('data' => array('#link' => array('title' => t('edit'), 'href' => "user/$account->uid/edit", 'query' => $destination))),
|
| 196 |
);
|
| 197 |
}
|
| 198 |
|
| 199 |
$form['accounts'] = array(
|
| 200 |
'#type' => 'tableselect',
|
| 201 |
'#header' => $header,
|
| 202 |
'#options' => $options,
|
| 203 |
'#empty' => t('No people available.'),
|
| 204 |
);
|
| 205 |
$form['pager'] = array('#markup' => theme('pager', array('tags' => NULL)));
|
| 206 |
|
| 207 |
return $form;
|
| 208 |
}
|
| 209 |
|
| 210 |
/**
|
| 211 |
* Submit the user administration update form.
|
| 212 |
*/
|
| 213 |
function user_admin_account_submit($form, &$form_state) {
|
| 214 |
$operations = module_invoke_all('user_operations', $form, $form_state);
|
| 215 |
$operation = $operations[$form_state['values']['operation']];
|
| 216 |
// Filter out unchecked accounts.
|
| 217 |
$accounts = array_filter($form_state['values']['accounts']);
|
| 218 |
if ($function = $operation['callback']) {
|
| 219 |
// Add in callback arguments if present.
|
| 220 |
if (isset($operation['callback arguments'])) {
|
| 221 |
$args = array_merge(array($accounts), $operation['callback arguments']);
|
| 222 |
}
|
| 223 |
else {
|
| 224 |
$args = array($accounts);
|
| 225 |
}
|
| 226 |
call_user_func_array($function, $args);
|
| 227 |
|
| 228 |
drupal_set_message(t('The update has been performed.'));
|
| 229 |
}
|
| 230 |
}
|
| 231 |
|
| 232 |
function user_admin_account_validate($form, &$form_state) {
|
| 233 |
$form_state['values']['accounts'] = array_filter($form_state['values']['accounts']);
|
| 234 |
if (count($form_state['values']['accounts']) == 0) {
|
| 235 |
form_set_error('', t('No users selected.'));
|
| 236 |
}
|
| 237 |
}
|
| 238 |
|
| 239 |
/**
|
| 240 |
* Form builder; Configure user settings for this site.
|
| 241 |
*
|
| 242 |
* @ingroup forms
|
| 243 |
* @see system_settings_form()
|
| 244 |
*/
|
| 245 |
function user_admin_settings() {
|
| 246 |
// Settings for anonymous users.
|
| 247 |
$form['anonymous_settings'] = array(
|
| 248 |
'#type' => 'fieldset',
|
| 249 |
'#title' => t('Anonymous users'),
|
| 250 |
);
|
| 251 |
$form['anonymous_settings']['anonymous'] = array(
|
| 252 |
'#type' => 'textfield',
|
| 253 |
'#title' => t('Name'),
|
| 254 |
'#default_value' => variable_get('anonymous', t('Anonymous')),
|
| 255 |
'#description' => t('The name used to indicate anonymous users.'),
|
| 256 |
'#required' => TRUE,
|
| 257 |
);
|
| 258 |
|
| 259 |
// Administrative role option.
|
| 260 |
$form['admin_role'] = array(
|
| 261 |
'#type' => 'fieldset',
|
| 262 |
'#title' => t('Administrator role'),
|
| 263 |
);
|
| 264 |
|
| 265 |
// Do not allow users to set the anonymous or authenticated user roles as the
|
| 266 |
// administrator role.
|
| 267 |
$roles = user_roles();
|
| 268 |
unset($roles[DRUPAL_ANONYMOUS_RID]);
|
| 269 |
unset($roles[DRUPAL_AUTHENTICATED_RID]);
|
| 270 |
$roles[0] = t('disabled');
|
| 271 |
|
| 272 |
$form['admin_role']['user_admin_role'] = array(
|
| 273 |
'#type' => 'select',
|
| 274 |
'#title' => t('Administrator role'),
|
| 275 |
'#default_value' => variable_get('user_admin_role', 0),
|
| 276 |
'#options' => $roles,
|
| 277 |
'#description' => t('This role will be automatically assigned new permissions whenever a module is enabled. Changing this setting will not affect existing permissions.'),
|
| 278 |
);
|
| 279 |
|
| 280 |
// User registration settings.
|
| 281 |
$form['registration_cancellation'] = array(
|
| 282 |
'#type' => 'fieldset',
|
| 283 |
'#title' => t('Registration and cancellation'),
|
| 284 |
);
|
| 285 |
$form['registration_cancellation']['user_register'] = array(
|
| 286 |
'#type' => 'radios',
|
| 287 |
'#title' => t('Who can register accounts?'),
|
| 288 |
'#default_value' => variable_get('user_register', 1),
|
| 289 |
'#options' => array(
|
| 290 |
t('Administrators only'),
|
| 291 |
t('Visitors'),
|
| 292 |
t('Visitors, but administrator approval is required'),
|
| 293 |
)
|
| 294 |
);
|
| 295 |
$form['registration_cancellation']['user_email_verification'] = array(
|
| 296 |
'#type' => 'checkbox',
|
| 297 |
'#title' => t('Require e-mail verification when a visitor creates an account.'),
|
| 298 |
'#default_value' => variable_get('user_email_verification', TRUE),
|
| 299 |
'#description' => t('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 this setting disabled, users will be logged in immediately upon registering, and may select their own passwords during registration.')
|
| 300 |
);
|
| 301 |
module_load_include('inc', 'user', 'user.pages');
|
| 302 |
$form['registration_cancellation']['user_cancel_method'] = array(
|
| 303 |
'#type' => 'item',
|
| 304 |
'#title' => t('When cancelling a user account'),
|
| 305 |
'#description' => t('Users with the %select-cancel-method or %administer-users <a href="@permissions-url">permissions</a> can override this default method.', array('%select-cancel-method' => t('Select method for cancelling account'), '%administer-users' => t('Administer users'), '@permissions-url' => url('admin/config/people/permissions'))),
|
| 306 |
);
|
| 307 |
$form['registration_cancellation']['user_cancel_method'] += user_cancel_methods();
|
| 308 |
foreach (element_children($form['registration_cancellation']['user_cancel_method']) as $element) {
|
| 309 |
// Remove all account cancellation methods that have #access defined, as
|
| 310 |
// those cannot be configured as default method.
|
| 311 |
if (isset($form['registration_cancellation']['user_cancel_method'][$element]['#access'])) {
|
| 312 |
$form['registration_cancellation']['user_cancel_method'][$element]['#access'] = FALSE;
|
| 313 |
}
|
| 314 |
// Remove the description (only displayed on the confirmation form).
|
| 315 |
else {
|
| 316 |
unset($form['registration_cancellation']['user_cancel_method'][$element]['#description']);
|
| 317 |
}
|
| 318 |
}
|
| 319 |
|
| 320 |
// Account settings.
|
| 321 |
$form['personalization'] = array(
|
| 322 |
'#type' => 'fieldset',
|
| 323 |
'#title' => t('Personalization'),
|
| 324 |
);
|
| 325 |
$form['personalization']['user_signatures'] = array(
|
| 326 |
'#type' => 'checkbox',
|
| 327 |
'#title' => t('Enable signatures.'),
|
| 328 |
'#default_value' => variable_get('user_signatures', 0),
|
| 329 |
);
|
| 330 |
// If picture support is enabled, check whether the picture directory exists.
|
| 331 |
if (variable_get('user_pictures', 0)) {
|
| 332 |
$picture_path = variable_get('file_default_scheme', 'public') . '://' . variable_get('user_picture_path', 'pictures');
|
| 333 |
if (!file_prepare_directory($picture_path, FILE_CREATE_DIRECTORY)) {
|
| 334 |
form_set_error('user_picture_path', t('The directory %directory does not exist or is not writable.', array('%directory' => $picture_path)));
|
| 335 |
watchdog('file system', 'The directory %directory does not exist or is not writable.', array('%directory' => $picture_path), WATCHDOG_ERROR);
|
| 336 |
}
|
| 337 |
}
|
| 338 |
$picture_support = variable_get('user_pictures', 0);
|
| 339 |
$form['personalization']['user_pictures'] = array(
|
| 340 |
'#type' => 'checkbox',
|
| 341 |
'#title' => t('Enable user pictures.'),
|
| 342 |
'#default_value' => $picture_support,
|
| 343 |
);
|
| 344 |
drupal_add_js(drupal_get_path('module', 'user') . '/user.js');
|
| 345 |
$form['personalization']['pictures'] = array(
|
| 346 |
'#type' => 'container',
|
| 347 |
'#states' => array(
|
| 348 |
// Hide the additional picture settings when user pictures are disabled.
|
| 349 |
'invisible' => array(
|
| 350 |
'input[name="user_pictures"]' => array('checked' => FALSE),
|
| 351 |
),
|
| 352 |
),
|
| 353 |
);
|
| 354 |
$form['personalization']['pictures']['user_picture_path'] = array(
|
| 355 |
'#type' => 'textfield',
|
| 356 |
'#title' => t('Picture directory'),
|
| 357 |
'#default_value' => variable_get('user_picture_path', 'pictures'),
|
| 358 |
'#size' => 30,
|
| 359 |
'#maxlength' => 255,
|
| 360 |
'#description' => t('Subdirectory in the directory %dir where pictures will be stored.', array('%dir' => file_directory_path() . '/')),
|
| 361 |
);
|
| 362 |
$form['personalization']['pictures']['user_picture_default'] = array(
|
| 363 |
'#type' => 'textfield',
|
| 364 |
'#title' => t('Default picture'),
|
| 365 |
'#default_value' => variable_get('user_picture_default', ''),
|
| 366 |
'#size' => 30,
|
| 367 |
'#maxlength' => 255,
|
| 368 |
'#description' => t('URL of picture to display for users with no custom picture selected. Leave blank for none.'),
|
| 369 |
);
|
| 370 |
if (module_exists('image')) {
|
| 371 |
$form['personalization']['pictures']['settings']['user_picture_style'] = array(
|
| 372 |
'#type' => 'select',
|
| 373 |
'#title' => t('Picture display style'),
|
| 374 |
'#options' => image_style_options(TRUE),
|
| 375 |
'#default_value' => variable_get('user_picture_style', ''),
|
| 376 |
'#description' => t('The style selected will be used on display, while the original image is retained. Styles may be configured in the <a href="!url">Image styles</a> administration area.', array('!url' => url('admin/config/media/image-styles'))),
|
| 377 |
);
|
| 378 |
}
|
| 379 |
$form['personalization']['pictures']['user_picture_dimensions'] = array(
|
| 380 |
'#type' => 'textfield',
|
| 381 |
'#title' => t('Picture upload dimensions'),
|
| 382 |
'#default_value' => variable_get('user_picture_dimensions', '85x85'),
|
| 383 |
'#size' => 10,
|
| 384 |
'#maxlength' => 10,
|
| 385 |
'#field_suffix' => ' ' . t('pixels'),
|
| 386 |
'#description' => t('Maximum allowed dimensions for uploaded pictures.'),
|
| 387 |
);
|
| 388 |
$form['personalization']['pictures']['user_picture_file_size'] = array(
|
| 389 |
'#type' => 'textfield',
|
| 390 |
'#title' => t('Picture upload file size'),
|
| 391 |
'#default_value' => variable_get('user_picture_file_size', '30'),
|
| 392 |
'#size' => 10,
|
| 393 |
'#maxlength' => 10,
|
| 394 |
'#field_suffix' => ' ' . t('KB'),
|
| 395 |
'#description' => t('Maximum allowed file size for uploaded pictures.'),
|
| 396 |
);
|
| 397 |
$form['personalization']['pictures']['user_picture_guidelines'] = array(
|
| 398 |
'#type' => 'textarea',
|
| 399 |
'#title' => t('Picture guidelines'),
|
| 400 |
'#default_value' => variable_get('user_picture_guidelines', ''),
|
| 401 |
'#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."),
|
| 402 |
);
|
| 403 |
|
| 404 |
$form['email_title'] = array(
|
| 405 |
'#type' => 'item',
|
| 406 |
'#title' => t('E-mails'),
|
| 407 |
);
|
| 408 |
$form['email'] = array(
|
| 409 |
'#type' => 'vertical_tabs',
|
| 410 |
);
|
| 411 |
// These email tokens are shared for all settings, so just define
|
| 412 |
// the list once to help ensure they stay in sync.
|
| 413 |
$email_token_help = t('Available variables are:') . ' [site:name], [site:url], [user:name], [user:mail], [site:login-url], [user:edit-url], [user:password], [user:one-time-login-url], [user:cancel-url].';
|
| 414 |
|
| 415 |
$form['email_admin_created'] = array(
|
| 416 |
'#type' => 'fieldset',
|
| 417 |
'#title' => t('Welcome (new user created by administrator)'),
|
| 418 |
'#collapsible' => TRUE,
|
| 419 |
'#collapsed' => (variable_get('user_register', 1) != 0),
|
| 420 |
'#description' => t('Customize welcome e-mail messages sent to new member accounts created by an administrator.') . ' ' . $email_token_help,
|
| 421 |
'#group' => 'email',
|
| 422 |
);
|
| 423 |
$form['email_admin_created']['user_mail_register_admin_created_subject'] = array(
|
| 424 |
'#type' => 'textfield',
|
| 425 |
'#title' => t('Subject'),
|
| 426 |
'#default_value' => _user_mail_text('register_admin_created_subject'),
|
| 427 |
'#maxlength' => 180,
|
| 428 |
);
|
| 429 |
$form['email_admin_created']['user_mail_register_admin_created_body'] = array(
|
| 430 |
'#type' => 'textarea',
|
| 431 |
'#title' => t('Body'),
|
| 432 |
'#default_value' => _user_mail_text('register_admin_created_body'),
|
| 433 |
'#rows' => 15,
|
| 434 |
);
|
| 435 |
|
| 436 |
$form['email_pending_approval'] = array(
|
| 437 |
'#type' => 'fieldset',
|
| 438 |
'#title' => t('Welcome (awaiting approval)'),
|
| 439 |
'#collapsible' => TRUE,
|
| 440 |
'#collapsed' => (variable_get('user_register', 1) != 2),
|
| 441 |
'#description' => t('Customize welcome e-mail messages sent to new members upon registering, when administrative approval is required.') . ' ' . $email_token_help,
|
| 442 |
'#group' => 'email',
|
| 443 |
);
|
| 444 |
$form['email_pending_approval']['user_mail_register_pending_approval_subject'] = array(
|
| 445 |
'#type' => 'textfield',
|
| 446 |
'#title' => t('Subject'),
|
| 447 |
'#default_value' => _user_mail_text('register_pending_approval_subject'),
|
| 448 |
'#maxlength' => 180,
|
| 449 |
);
|
| 450 |
$form['email_pending_approval']['user_mail_register_pending_approval_body'] = array(
|
| 451 |
'#type' => 'textarea',
|
| 452 |
'#title' => t('Body'),
|
| 453 |
'#default_value' => _user_mail_text('register_pending_approval_body'),
|
| 454 |
'#rows' => 8,
|
| 455 |
);
|
| 456 |
|
| 457 |
$form['email_no_approval_required'] = array(
|
| 458 |
'#type' => 'fieldset',
|
| 459 |
'#title' => t('Welcome (no approval required)'),
|
| 460 |
'#collapsible' => TRUE,
|
| 461 |
'#collapsed' => (variable_get('user_register', 1) != 1),
|
| 462 |
'#description' => t('Customize welcome e-mail messages sent to new members upon registering, when no administrator approval is required.') . ' ' . $email_token_help,
|
| 463 |
'#group' => 'email',
|
| 464 |
);
|
| 465 |
$form['email_no_approval_required']['user_mail_register_no_approval_required_subject'] = array(
|
| 466 |
'#type' => 'textfield',
|
| 467 |
'#title' => t('Subject'),
|
| 468 |
'#default_value' => _user_mail_text('register_no_approval_required_subject'),
|
| 469 |
'#maxlength' => 180,
|
| 470 |
);
|
| 471 |
$form['email_no_approval_required']['user_mail_register_no_approval_required_body'] = array(
|
| 472 |
'#type' => 'textarea',
|
| 473 |
'#title' => t('Body'),
|
| 474 |
'#default_value' => _user_mail_text('register_no_approval_required_body'),
|
| 475 |
'#rows' => 15,
|
| 476 |
);
|
| 477 |
|
| 478 |
$form['email_password_reset'] = array(
|
| 479 |
'#type' => 'fieldset',
|
| 480 |
'#title' => t('Password recovery'),
|
| 481 |
'#collapsible' => TRUE,
|
| 482 |
'#collapsed' => TRUE,
|
| 483 |
'#description' => t('Customize e-mail messages sent to users who request a new password.') . ' ' . $email_token_help,
|
| 484 |
'#group' => 'email',
|
| 485 |
'#weight' => 10,
|
| 486 |
);
|
| 487 |
$form['email_password_reset']['user_mail_password_reset_subject'] = array(
|
| 488 |
'#type' => 'textfield',
|
| 489 |
'#title' => t('Subject'),
|
| 490 |
'#default_value' => _user_mail_text('password_reset_subject'),
|
| 491 |
'#maxlength' => 180,
|
| 492 |
);
|
| 493 |
$form['email_password_reset']['user_mail_password_reset_body'] = array(
|
| 494 |
'#type' => 'textarea',
|
| 495 |
'#title' => t('Body'),
|
| 496 |
'#default_value' => _user_mail_text('password_reset_body'),
|
| 497 |
'#rows' => 12,
|
| 498 |
);
|
| 499 |
|
| 500 |
$form['email_activated'] = array(
|
| 501 |
'#type' => 'fieldset',
|
| 502 |
'#title' => t('Account activation'),
|
| 503 |
'#collapsible' => TRUE,
|
| 504 |
'#collapsed' => TRUE,
|
| 505 |
'#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,
|
| 506 |
'#group' => 'email',
|
| 507 |
);
|
| 508 |
$form['email_activated']['user_mail_status_activated_notify'] = array(
|
| 509 |
'#type' => 'checkbox',
|
| 510 |
'#title' => t('Notify user when account is activated.'),
|
| 511 |
'#default_value' => variable_get('user_mail_status_activated_notify', TRUE),
|
| 512 |
);
|
| 513 |
$form['email_activated']['settings'] = array(
|
| 514 |
'#type' => 'container',
|
| 515 |
'#states' => array(
|
| 516 |
// Hide the additional settings when this email is disabled.
|
| 517 |
'invisible' => array(
|
| 518 |
'input[name="user_mail_status_activated_notify"]' => array('checked' => FALSE),
|
| 519 |
),
|
| 520 |
),
|
| 521 |
);
|
| 522 |
$form['email_activated']['settings']['user_mail_status_activated_subject'] = array(
|
| 523 |
'#type' => 'textfield',
|
| 524 |
'#title' => t('Subject'),
|
| 525 |
'#default_value' => _user_mail_text('status_activated_subject'),
|
| 526 |
'#maxlength' => 180,
|
| 527 |
);
|
| 528 |
$form['email_activated']['settings']['user_mail_status_activated_body'] = array(
|
| 529 |
'#type' => 'textarea',
|
| 530 |
'#title' => t('Body'),
|
| 531 |
'#default_value' => _user_mail_text('status_activated_body'),
|
| 532 |
'#rows' => 15,
|
| 533 |
);
|
| 534 |
|
| 535 |
$form['email_blocked'] = array(
|
| 536 |
'#type' => 'fieldset',
|
| 537 |
'#title' => t('Account blocked'),
|
| 538 |
'#collapsible' => TRUE,
|
| 539 |
'#collapsed' => TRUE,
|
| 540 |
'#description' => t('Enable and customize e-mail messages sent to users when their accounts are blocked.') . ' ' . $email_token_help,
|
| 541 |
'#group' => 'email',
|
| 542 |
);
|
| 543 |
$form['email_blocked']['user_mail_status_blocked_notify'] = array(
|
| 544 |
'#type' => 'checkbox',
|
| 545 |
'#title' => t('Notify user when account is blocked.'),
|
| 546 |
'#default_value' => variable_get('user_mail_status_blocked_notify', FALSE),
|
| 547 |
);
|
| 548 |
$form['email_blocked']['settings'] = array(
|
| 549 |
'#type' => 'container',
|
| 550 |
'#states' => array(
|
| 551 |
// Hide the additional settings when the blocked email is disabled.
|
| 552 |
'invisible' => array(
|
| 553 |
'input[name="user_mail_status_blocked_notify"]' => array('checked' => FALSE),
|
| 554 |
),
|
| 555 |
),
|
| 556 |
);
|
| 557 |
$form['email_blocked']['settings']['user_mail_status_blocked_subject'] = array(
|
| 558 |
'#type' => 'textfield',
|
| 559 |
'#title' => t('Subject'),
|
| 560 |
'#default_value' => _user_mail_text('status_blocked_subject'),
|
| 561 |
'#maxlength' => 180,
|
| 562 |
);
|
| 563 |
$form['email_blocked']['settings']['user_mail_status_blocked_body'] = array(
|
| 564 |
'#type' => 'textarea',
|
| 565 |
'#title' => t('Body'),
|
| 566 |
'#default_value' => _user_mail_text('status_blocked_body'),
|
| 567 |
'#rows' => 3,
|
| 568 |
);
|
| 569 |
|
| 570 |
$form['email_cancel_confirm'] = array(
|
| 571 |
'#type' => 'fieldset',
|
| 572 |
'#title' => t('Account cancellation confirmation'),
|
| 573 |
'#collapsible' => TRUE,
|
| 574 |
'#collapsed' => TRUE,
|
| 575 |
'#description' => t('Customize e-mail messages sent to users when they attempt to cancel their accounts.') . ' ' . $email_token_help,
|
| 576 |
'#group' => 'email',
|
| 577 |
);
|
| 578 |
$form['email_cancel_confirm']['user_mail_cancel_confirm_subject'] = array(
|
| 579 |
'#type' => 'textfield',
|
| 580 |
'#title' => t('Subject'),
|
| 581 |
'#default_value' => _user_mail_text('cancel_confirm_subject'),
|
| 582 |
'#maxlength' => 180,
|
| 583 |
);
|
| 584 |
$form['email_cancel_confirm']['user_mail_cancel_confirm_body'] = array(
|
| 585 |
'#type' => 'textarea',
|
| 586 |
'#title' => t('Body'),
|
| 587 |
'#default_value' => _user_mail_text('cancel_confirm_body'),
|
| 588 |
'#rows' => 3,
|
| 589 |
);
|
| 590 |
|
| 591 |
$form['email_canceled'] = array(
|
| 592 |
'#type' => 'fieldset',
|
| 593 |
'#title' => t('Account canceled'),
|
| 594 |
'#collapsible' => TRUE,
|
| 595 |
'#collapsed' => TRUE,
|
| 596 |
'#description' => t('Enable and customize e-mail messages sent to users when their accounts are canceled.') . ' ' . $email_token_help,
|
| 597 |
'#group' => 'email',
|
| 598 |
);
|
| 599 |
$form['email_canceled']['user_mail_status_canceled_notify'] = array(
|
| 600 |
'#type' => 'checkbox',
|
| 601 |
'#title' => t('Notify user when account is canceled.'),
|
| 602 |
'#default_value' => variable_get('user_mail_status_canceled_notify', FALSE),
|
| 603 |
);
|
| 604 |
$form['email_canceled']['settings'] = array(
|
| 605 |
'#type' => 'container',
|
| 606 |
'#states' => array(
|
| 607 |
// Hide the settings when the cancel notify checkbox is disabled.
|
| 608 |
'invisible' => array(
|
| 609 |
'input[name="user_mail_status_canceled_notify"]' => array('checked' => FALSE),
|
| 610 |
),
|
| 611 |
),
|
| 612 |
);
|
| 613 |
$form['email_canceled']['settings']['user_mail_status_canceled_subject'] = array(
|
| 614 |
'#type' => 'textfield',
|
| 615 |
'#title' => t('Subject'),
|
| 616 |
'#default_value' => _user_mail_text('status_canceled_subject'),
|
| 617 |
'#maxlength' => 180,
|
| 618 |
);
|
| 619 |
$form['email_canceled']['settings']['user_mail_status_canceled_body'] = array(
|
| 620 |
'#type' => 'textarea',
|
| 621 |
'#title' => t('Body'),
|
| 622 |
'#default_value' => _user_mail_text('status_canceled_body'),
|
| 623 |
'#rows' => 3,
|
| 624 |
);
|
| 625 |
|
| 626 |
return system_settings_form($form, FALSE);
|
| 627 |
}
|
| 628 |
|
| 629 |
/**
|
| 630 |
* Menu callback: administer permissions.
|
| 631 |
*
|
| 632 |
* @ingroup forms
|
| 633 |
* @see user_admin_permissions_submit()
|
| 634 |
* @see theme_user_admin_permissions()
|
| 635 |
*/
|
| 636 |
function user_admin_permissions($form, $form_state, $rid = NULL) {
|
| 637 |
|
| 638 |
// Retrieve role names for columns.
|
| 639 |
$role_names = user_roles();
|
| 640 |
if (is_numeric($rid)) {
|
| 641 |
$role_names = array($rid => $role_names[$rid]);
|
| 642 |
}
|
| 643 |
// Fetch permissions for all roles or the one selected role.
|
| 644 |
$role_permissions = user_role_permissions($role_names);
|
| 645 |
|
| 646 |
// Store $role_names for use when saving the data.
|
| 647 |
$form['role_names'] = array(
|
| 648 |
'#type' => 'value',
|
| 649 |
'#value' => $role_names,
|
| 650 |
);
|
| 651 |
// Render role/permission overview:
|
| 652 |
$options = array();
|
| 653 |
$module_info = system_get_info('module');
|
| 654 |
$hide_descriptions = !system_admin_compact_mode();
|
| 655 |
foreach (module_implements('permission') as $module) {
|
| 656 |
if ($permissions = module_invoke($module, 'permission')) {
|
| 657 |
$form['permission'][] = array(
|
| 658 |
'#markup' => $module_info[$module]['name'],
|
| 659 |
'#id' => $module,
|
| 660 |
);
|
| 661 |
foreach ($permissions as $perm => $perm_item) {
|
| 662 |
$options[$perm] = '';
|
| 663 |
$form['permission'][$perm] = array(
|
| 664 |
'#type' => 'item',
|
| 665 |
'#markup' => $perm_item['title'],
|
| 666 |
'#description' => $hide_descriptions && isset($perm_item['description']) ? $perm_item['description'] : NULL,
|
| 667 |
);
|
| 668 |
foreach ($role_names as $rid => $name) {
|
| 669 |
// Builds arrays for checked boxes for each role
|
| 670 |
if (isset($role_permissions[$rid][$perm])) {
|
| 671 |
$status[$rid][] = $perm;
|
| 672 |
}
|
| 673 |
}
|
| 674 |
}
|
| 675 |
}
|
| 676 |
}
|
| 677 |
|
| 678 |
// Have to build checkboxes here after checkbox arrays are built
|
| 679 |
foreach ($role_names as $rid => $name) {
|
| 680 |
$form['checkboxes'][$rid] = array('#type' => 'checkboxes', '#options' => $options, '#default_value' => isset($status[$rid]) ? $status[$rid] : array());
|
| 681 |
$form['role_names'][$rid] = array('#markup' => $name, '#tree' => TRUE);
|
| 682 |
}
|
| 683 |
$form['submit'] = array('#type' => 'submit', '#value' => t('Save permissions'));
|
| 684 |
|
| 685 |
$form['#attached']['js'][] = drupal_get_path('module', 'user') . '/user.permissions.js';
|
| 686 |
|
| 687 |
return $form;
|
| 688 |
}
|
| 689 |
|
| 690 |
/**
|
| 691 |
* Save permissions selected on the administer permissions page.
|
| 692 |
*
|
| 693 |
* @see user_admin_permissions()
|
| 694 |
*/
|
| 695 |
function user_admin_permissions_submit($form, &$form_state) {
|
| 696 |
foreach ($form_state['values']['role_names'] as $rid => $name) {
|
| 697 |
user_role_change_permissions($rid, $form_state['values'][$rid]);
|
| 698 |
}
|
| 699 |
|
| 700 |
drupal_set_message(t('The changes have been saved.'));
|
| 701 |
|
| 702 |
// Clear the cached pages and blocks.
|
| 703 |
cache_clear_all();
|
| 704 |
}
|
| 705 |
|
| 706 |
/**
|
| 707 |
* Theme the administer permissions page.
|
| 708 |
*
|
| 709 |
* @ingroup themeable
|
| 710 |
*/
|
| 711 |
function theme_user_admin_permissions($variables) {
|
| 712 |
$form = $variables['form'];
|
| 713 |
|
| 714 |
$roles = user_roles();
|
| 715 |
foreach (element_children($form['permission']) as $key) {
|
| 716 |
$row = array();
|
| 717 |
// Module name
|
| 718 |
if (is_numeric($key)) {
|
| 719 |
$row[] = array('data' => drupal_render($form['permission'][$key]), 'class' => array('module'), 'id' => 'module-' . $form['permission'][$key]['#id'], 'colspan' => count($form['role_names']['#value']) + 1);
|
| 720 |
}
|
| 721 |
else {
|
| 722 |
// Permission row.
|
| 723 |
$row[] = array(
|
| 724 |
'data' => drupal_render($form['permission'][$key]),
|
| 725 |
'class' => array('permission'),
|
| 726 |
);
|
| 727 |
foreach (element_children($form['checkboxes']) as $rid) {
|
| 728 |
$row[] = array('data' => drupal_render($form['checkboxes'][$rid][$key]), 'class' => array('checkbox'), 'title' => $roles[$rid] . ' : ' . t($key));
|
| 729 |
}
|
| 730 |
}
|
| 731 |
$rows[] = $row;
|
| 732 |
}
|
| 733 |
$header[] = (t('Permission'));
|
| 734 |
foreach (element_children($form['role_names']) as $rid) {
|
| 735 |
$header[] = array('data' => drupal_render($form['role_names'][$rid]), 'class' => array('checkbox'));
|
| 736 |
}
|
| 737 |
$output = theme('system_compact_link');
|
| 738 |
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'permissions')));
|
| 739 |
$output .= drupal_render_children($form);
|
| 740 |
return $output;
|
| 741 |
}
|
| 742 |
|
| 743 |
/**
|
| 744 |
* Menu callback: administer roles.
|
| 745 |
*
|
| 746 |
* @ingroup forms
|
| 747 |
* @see user_admin_role_validate()
|
| 748 |
* @see user_admin_role_submit()
|
| 749 |
* @see theme_user_admin_new_role()
|
| 750 |
*/
|
| 751 |
function user_admin_role() {
|
| 752 |
$rid = arg(5);
|
| 753 |
if ($rid) {
|
| 754 |
if ($rid == DRUPAL_ANONYMOUS_RID || $rid == DRUPAL_AUTHENTICATED_RID) {
|
| 755 |
drupal_goto('admin/config/people/roles');
|
| 756 |
}
|
| 757 |
// Display the edit role form.
|
| 758 |
$role = db_query('SELECT * FROM {role} WHERE rid = :rid', array(':rid' => $rid))->fetchObject();
|
| 759 |
$form['name'] = array(
|
| 760 |
'#type' => 'textfield',
|
| 761 |
'#title' => t('Role name'),
|
| 762 |
'#default_value' => $role->name,
|
| 763 |
'#size' => 30,
|
| 764 |
'#required' => TRUE,
|
| 765 |
'#maxlength' => 64,
|
| 766 |
'#description' => t('The name for this role. Example: "moderator", "editorial board", "site architect".'),
|
| 767 |
);
|
| 768 |
$form['rid'] = array(
|
| 769 |
'#type' => 'value',
|
| 770 |
'#value' => $rid,
|
| 771 |
);
|
| 772 |
$form['submit'] = array(
|
| 773 |
'#type' => 'submit',
|
| 774 |
'#value' => t('Save role'),
|
| 775 |
);
|
| 776 |
$form['delete'] = array(
|
| 777 |
'#type' => 'submit',
|
| 778 |
'#value' => t('Delete role'),
|
| 779 |
);
|
| 780 |
}
|
| 781 |
else {
|
| 782 |
$form['name'] = array(
|
| 783 |
'#type' => 'textfield',
|
| 784 |
'#size' => 32,
|
| 785 |
'#maxlength' => 64,
|
| 786 |
);
|
| 787 |
$form['submit'] = array(
|
| 788 |
'#type' => 'submit',
|
| 789 |
'#value' => t('Add role'),
|
| 790 |
);
|
| 791 |
$form['#submit'][] = 'user_admin_role_submit';
|
| 792 |
$form['#validate'][] = 'user_admin_role_validate';
|
| 793 |
}
|
| 794 |
return $form;
|
| 795 |
}
|
| 796 |
|
| 797 |
function user_admin_role_validate($form, &$form_state) {
|
| 798 |
if ($form_state['values']['name']) {
|
| 799 |
if ($form_state['values']['op'] == t('Save role')) {
|
| 800 |
$role = user_role_load($form_state['values']['name']);
|
| 801 |
if ($role && $role->rid != $form_state['values']['rid']) {
|
| 802 |
form_set_error('name', t('The role name %name already exists. Please choose another role name.', array('%name' => $form_state['values']['name'])));
|
| 803 |
}
|
| 804 |
}
|
| 805 |
elseif ($form_state['values']['op'] == t('Add role')) {
|
| 806 |
if (user_role_load($form_state['values']['name'])) {
|
| 807 |
form_set_error('name', t('The role name %name already exists. Please choose another role name.', array('%name' => $form_state['values']['name'])));
|
| 808 |
}
|
| 809 |
}
|
| 810 |
}
|
| 811 |
else {
|
| 812 |
form_set_error('name', t('You must specify a valid role name.'));
|
| 813 |
}
|
| 814 |
}
|
| 815 |
|
| 816 |
function user_admin_role_submit($form, &$form_state) {
|
| 817 |
$role = (object)$form_state['values'];
|
| 818 |
if ($form_state['values']['op'] == t('Save role')) {
|
| 819 |
user_role_save($role);
|
| 820 |
drupal_set_message(t('The role has been renamed.'));
|
| 821 |
}
|
| 822 |
elseif ($form_state['values']['op'] == t('Delete role')) {
|
| 823 |
user_role_delete($form_state['values']['rid']);
|
| 824 |
drupal_set_message(t('The role has been deleted.'));
|
| 825 |
}
|
| 826 |
elseif ($form_state['values']['op'] == t('Add role')) {
|
| 827 |
user_role_save($role);
|
| 828 |
drupal_set_message(t('The role has been added.'));
|
| 829 |
}
|
| 830 |
$form_state['redirect'] = 'admin/config/people/roles';
|
| 831 |
return;
|
| 832 |
}
|
| 833 |
|
| 834 |
/**
|
| 835 |
* Theme the new-role form.
|
| 836 |
*
|
| 837 |
* @ingroup themeable
|
| 838 |
*/
|
| 839 |
function theme_user_admin_new_role($variables) {
|
| 840 |
$form = $variables['form'];
|
| 841 |
|
| 842 |
$header = array(t('Name'), array('data' => t('Operations'), 'colspan' => 2));
|
| 843 |
foreach (user_roles() as $rid => $name) {
|
| 844 |
$edit_permissions = l(t('edit permissions'), 'admin/config/people/permissions/' . $rid);
|
| 845 |
if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
|
| 846 |
$rows[] = array($name, l(t('edit role'), 'admin/config/people/roles/edit/' . $rid), $edit_permissions);
|
| 847 |
}
|
| 848 |
else {
|
| 849 |
$rows[] = array($name, t('locked'), $edit_permissions);
|
| 850 |
}
|
| 851 |
}
|
| 852 |
$rows[] = array(drupal_render($form['name']), array('data' => drupal_render($form['submit']), 'colspan' => 2));
|
| 853 |
|
| 854 |
$output = drupal_render_children($form);
|
| 855 |
$output .= theme('table', array('header' => $header, 'rows' => $rows));
|
| 856 |
|
| 857 |
return $output;
|
| 858 |
}
|
| 859 |
|
| 860 |
/**
|
| 861 |
* Theme user administration filter form.
|
| 862 |
*
|
| 863 |
* @ingroup themeable
|
| 864 |
*/
|
| 865 |
function theme_user_filter_form($variables) {
|
| 866 |
$form = $variables['form'];
|
| 867 |
|
| 868 |
$output = '<div id="user-admin-filter">';
|
| 869 |
$output .= drupal_render($form['filters']);
|
| 870 |
$output .= '</div>';
|
| 871 |
$output .= drupal_render_children($form);
|
| 872 |
return $output;
|
| 873 |
}
|
| 874 |
|
| 875 |
/**
|
| 876 |
* Theme user administration filter selector.
|
| 877 |
*
|
| 878 |
* @ingroup themeable
|
| 879 |
*/
|
| 880 |
function theme_user_filters($variables) {
|
| 881 |
$form = $variables['form'];
|
| 882 |
|
| 883 |
$output = '<ul class="clearfix">';
|
| 884 |
if (!empty($form['current'])) {
|
| 885 |
foreach (element_children($form['current']) as $key) {
|
| 886 |
$output .= '<li>' . drupal_render($form['current'][$key]) . '</li>';
|
| 887 |
}
|
| 888 |
}
|
| 889 |
|
| 890 |
$output .= '<li><dl class="multiselect">' . (!empty($form['current']) ? '<dt><em>' . t('and') . '</em> ' . t('where') . '</dt>' : '') . '<dd class="a">';
|
| 891 |
foreach (element_children($form['filter']) as $key) {
|
| 892 |
$output .= drupal_render($form['filter'][$key]);
|
| 893 |
}
|
| 894 |
$output .= '</dd>';
|
| 895 |
|
| 896 |
$output .= '<dt>' . t('is') . '</dt><dd class="b">';
|
| 897 |
|
| 898 |
foreach (element_children($form['status']) as $key) {
|
| 899 |
$output .= drupal_render($form['status'][$key]);
|
| 900 |
}
|
| 901 |
$output .= '</dd>';
|
| 902 |
|
| 903 |
$output .= '</dl>';
|
| 904 |
$output .= '<div class="container-inline" id="user-admin-buttons">' . drupal_render($form['buttons']) . '</div>';
|
| 905 |
$output .= '</li></ul>';
|
| 906 |
|
| 907 |
return $output;
|
| 908 |
}
|