2007-09-10 13:14:38 +00:00
< ? php
// $Id$
/**
* @ file
* 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' :
2009-10-10 16:48:39 +00:00
$build [ 'user_register' ] = drupal_get_form ( 'user_register_form' );
2007-09-10 13:14:38 +00:00
break ;
default :
2009-01-08 08:42:13 +00:00
if ( ! empty ( $_POST [ 'accounts' ]) && isset ( $_POST [ 'operation' ]) && ( $_POST [ 'operation' ] == 'cancel' )) {
2009-05-12 08:37:45 +00:00
$build [ 'user_multiple_cancel_confirm' ] = drupal_get_form ( 'user_multiple_cancel_confirm' );
2007-09-10 13:14:38 +00:00
}
else {
2009-05-12 08:37:45 +00:00
$build [ 'user_filter_form' ] = drupal_get_form ( 'user_filter_form' );
$build [ 'user_admin_account' ] = drupal_get_form ( 'user_admin_account' );
2007-09-10 13:14:38 +00:00
}
}
2009-05-12 08:37:45 +00:00
return $build ;
2007-09-10 13:14:38 +00:00
}
/**
* Form builder ; Return form for user administration filters .
2007-10-02 16:03:17 +00:00
*
2007-09-10 13:14:38 +00:00
* @ ingroup forms
2008-01-08 10:35:43 +00:00
* @ see user_filter_form_submit ()
2007-09-10 13:14:38 +00:00
*/
function user_filter_form () {
2009-06-02 06:58:17 +00:00
$session = isset ( $_SESSION [ 'user_overview_filter' ]) ? $_SESSION [ 'user_overview_filter' ] : array ();
2007-09-10 13:14:38 +00:00
$filters = user_filters ();
$i = 0 ;
2007-12-23 13:17:20 +00:00
$form [ 'filters' ] = array (
'#type' => 'fieldset' ,
'#title' => t ( 'Show only users where' ),
'#theme' => 'user_filters' ,
);
2007-09-10 13:14:38 +00:00
foreach ( $session as $filter ) {
list ( $type , $value ) = $filter ;
2009-11-17 02:50:41 +00:00
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 ];
}
$params = array ( '%property' => $filters [ $type ][ 'title' ] , '%value' => $value );
if ( $i ++ ) {
2008-07-16 21:59:29 +00:00
$form [ 'filters' ][ 'current' ][] = array ( '#markup' => t ( '<em>and</em> where <strong>%property</strong> is <strong>%value</strong>' , $params ));
2007-09-12 11:39:38 +00:00
}
else {
2008-07-16 21:59:29 +00:00
$form [ 'filters' ][ 'current' ][] = array ( '#markup' => t ( '<strong>%property</strong> is <strong>%value</strong>' , $params ));
2007-09-12 11:39:38 +00:00
}
2007-09-10 13:14:38 +00:00
}
foreach ( $filters as $key => $filter ) {
$names [ $key ] = $filter [ 'title' ];
2007-12-23 13:17:20 +00:00
$form [ 'filters' ][ 'status' ][ $key ] = array (
'#type' => 'select' ,
'#options' => $filter [ 'options' ],
2009-11-17 02:50:41 +00:00
'#title' => $filter [ 'title' ],
'#default_value' => '[any]' ,
2007-12-23 13:17:20 +00:00
);
2007-09-10 13:14:38 +00:00
}
2010-01-03 21:01:04 +00:00
$form [ 'filters' ][ 'actions' ] = array (
'#type' => 'container' ,
'#id' => 'user-admin-buttons' ,
'#attributes' => array ( 'class' => array ( 'form-actions' , 'container-inline' )),
);
$form [ 'filters' ][ 'actions' ][ 'submit' ] = array (
2007-12-23 13:17:20 +00:00
'#type' => 'submit' ,
'#value' => ( count ( $session ) ? t ( 'Refine' ) : t ( 'Filter' )),
);
2007-09-10 13:14:38 +00:00
if ( count ( $session )) {
2010-01-03 21:01:04 +00:00
$form [ 'filters' ][ 'actions' ][ 'undo' ] = array (
2007-12-23 13:17:20 +00:00
'#type' => 'submit' ,
'#value' => t ( 'Undo' ),
);
2010-01-03 21:01:04 +00:00
$form [ 'filters' ][ 'actions' ][ 'reset' ] = array (
2007-12-23 13:17:20 +00:00
'#type' => 'submit' ,
'#value' => t ( 'Reset' ),
);
2007-09-10 13:14:38 +00:00
}
2008-11-10 05:23:01 +00:00
drupal_add_js ( 'misc/form.js' );
2007-09-12 18:29:32 +00:00
2007-09-10 13:14:38 +00:00
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 ) {
2009-11-17 02:50:41 +00:00
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]' ) {
// Merge an array of arrays into one if necessary.
$options = ( $filter == 'permission' ) ? form_options_flatten ( $filters [ $filter ][ 'options' ]) : $filters [ $filter ][ 'options' ];
// Only accept valid selections offered on the dropdown, block bad input.
if ( isset ( $options [ $form_state [ 'values' ][ $filter ]])) {
$_SESSION [ 'user_overview_filter' ][] = array ( $filter , $form_state [ 'values' ][ $filter ]);
}
2007-09-10 13:14:38 +00:00
}
}
break ;
case t ( 'Undo' ) :
array_pop ( $_SESSION [ 'user_overview_filter' ]);
break ;
case t ( 'Reset' ) :
2009-06-02 06:58:17 +00:00
$_SESSION [ 'user_overview_filter' ] = array ();
2007-09-10 13:14:38 +00:00
break ;
case t ( 'Update' ) :
return ;
}
2009-08-11 11:47:58 +00:00
$form_state [ 'redirect' ] = 'admin/people' ;
2007-09-10 13:14:38 +00:00
return ;
}
/**
* Form builder ; User administration page .
*
* @ ingroup forms
2008-01-08 10:35:43 +00:00
* @ see user_admin_account_validate ()
* @ see user_admin_account_submit ()
2007-09-10 13:14:38 +00:00
*/
function user_admin_account () {
$header = array (
2009-10-08 18:26:33 +00:00
'username' => array ( 'data' => t ( 'Username' ), 'field' => 'u.name' ),
'status' => array ( 'data' => t ( 'Status' ), 'field' => 'u.status' ),
'roles' => array ( 'data' => t ( 'Roles' )),
'member_for' => array ( 'data' => t ( 'Member for' ), 'field' => 'u.created' , 'sort' => 'desc' ),
'access' => array ( 'data' => t ( 'Last access' ), 'field' => 'u.access' ),
'operations' => array ( 'data' => t ( 'Operations' )),
2007-09-10 13:14:38 +00:00
);
2009-04-13 12:14:57 +00:00
$query = db_select ( 'users' , 'u' );
2009-04-30 16:10:10 +00:00
$query -> condition ( 'u.uid' , 0 , '<>' );
user_build_filter_query ( $query );
2009-05-24 17:39:35 +00:00
2009-04-30 16:10:10 +00:00
$count_query = clone $query ;
2010-01-12 06:18:58 +00:00
$count_query -> addExpression ( 'COUNT(u.uid)' );
2009-04-30 16:10:10 +00:00
$query = $query -> extend ( 'PagerDefault' ) -> extend ( 'TableSort' );
$query
-> fields ( 'u' , array ( 'uid' , 'name' , 'status' , 'created' , 'access' ))
-> limit ( 50 )
2009-05-22 11:33:18 +00:00
-> orderByHeader ( $header )
2009-04-30 16:10:10 +00:00
-> setCountQuery ( $count_query );
$result = $query -> execute ();
2007-09-10 13:14:38 +00:00
$form [ 'options' ] = array (
'#type' => 'fieldset' ,
'#title' => t ( 'Update options' ),
2010-03-03 19:46:26 +00:00
'#attributes' => array ( 'class' => array ( 'container-inline' )),
2007-09-10 13:14:38 +00:00
);
$options = array ();
foreach ( module_invoke_all ( 'user_operations' ) as $operation => $array ) {
$options [ $operation ] = $array [ 'label' ];
}
$form [ 'options' ][ 'operation' ] = array (
'#type' => 'select' ,
'#options' => $options ,
'#default_value' => 'unblock' ,
);
2009-10-08 18:26:33 +00:00
$options = array ();
2007-09-10 13:14:38 +00:00
$form [ 'options' ][ 'submit' ] = array (
'#type' => 'submit' ,
'#value' => t ( 'Update' ),
);
$destination = drupal_get_destination ();
$status = array ( t ( 'blocked' ), t ( 'active' ));
2008-01-10 20:22:57 +00:00
$roles = user_roles ( TRUE );
2007-09-10 13:14:38 +00:00
$accounts = array ();
2009-04-13 12:14:57 +00:00
foreach ( $result as $account ) {
2009-02-26 07:30:29 +00:00
$users_roles = array ();
2009-04-13 12:14:57 +00:00
$roles_result = db_query ( 'SELECT rid FROM {users_roles} WHERE uid = :uid' , array ( ':uid' => $account -> uid ));
foreach ( $roles_result as $user_role ) {
2009-02-26 07:30:29 +00:00
$users_roles [] = $roles [ $user_role -> rid ];
2007-09-10 13:14:38 +00:00
}
2009-02-26 07:30:29 +00:00
asort ( $users_roles );
2009-12-02 17:04:25 +00:00
2009-10-08 18:26:33 +00:00
$options [ $account -> uid ] = array (
2009-10-09 01:00:08 +00:00
'username' => theme ( 'username' , array ( 'account' => $account )),
2009-10-08 18:26:33 +00:00
'status' => $status [ $account -> status ],
2009-10-09 01:00:08 +00:00
'roles' => theme ( 'item_list' , array ( 'items' => $users_roles )),
2009-10-08 18:26:33 +00:00
'member_for' => format_interval ( REQUEST_TIME - $account -> created ),
'access' => $account -> access ? t ( '@time ago' , array ( '@time' => format_interval ( REQUEST_TIME - $account -> access ))) : t ( 'never' ),
2009-11-28 21:44:54 +00:00
'operations' => array ( 'data' => array ( '#type' => 'link' , '#title' => t ( 'edit' ), '#href' => " user/ $account->uid /edit " , '#options' => array ( 'query' => $destination ))),
2009-10-08 18:26:33 +00:00
);
2007-09-10 13:14:38 +00:00
}
2009-12-02 17:04:25 +00:00
2007-09-10 13:14:38 +00:00
$form [ 'accounts' ] = array (
2009-10-08 18:26:33 +00:00
'#type' => 'tableselect' ,
'#header' => $header ,
'#options' => $options ,
'#empty' => t ( 'No people available.' ),
2007-09-10 13:14:38 +00:00
);
2009-10-09 01:00:08 +00:00
$form [ 'pager' ] = array ( '#markup' => theme ( 'pager' , array ( 'tags' => NULL )));
2007-09-10 13:14:38 +00:00
return $form ;
}
/**
* Submit the user administration update form .
*/
function user_admin_account_submit ( $form , & $form_state ) {
2009-09-18 00:12:48 +00:00
$operations = module_invoke_all ( 'user_operations' , $form , $form_state );
2007-09-10 13:14:38 +00:00
$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.' ));
}
}
/**
* Form builder ; Configure user settings for this site .
*
* @ ingroup forms
2008-01-08 10:35:43 +00:00
* @ see system_settings_form ()
2007-09-10 13:14:38 +00:00
*/
function user_admin_settings () {
2009-05-16 20:10:50 +00:00
// Settings for anonymous users.
$form [ 'anonymous_settings' ] = array (
'#type' => 'fieldset' ,
'#title' => t ( 'Anonymous users' ),
);
$form [ 'anonymous_settings' ][ 'anonymous' ] = array (
'#type' => 'textfield' ,
'#title' => t ( 'Name' ),
'#default_value' => variable_get ( 'anonymous' , t ( 'Anonymous' )),
'#description' => t ( 'The name used to indicate anonymous users.' ),
'#required' => TRUE ,
);
2007-09-10 13:14:38 +00:00
2009-06-04 09:52:33 +00:00
// Administrative role option.
$form [ 'admin_role' ] = array (
'#type' => 'fieldset' ,
2009-06-04 20:09:29 +00:00
'#title' => t ( 'Administrator role' ),
2009-06-04 09:52:33 +00:00
);
2009-06-04 20:09:29 +00:00
// Do not allow users to set the anonymous or authenticated user roles as the
2009-06-04 09:52:33 +00:00
// administrator role.
$roles = user_roles ();
2009-06-06 14:51:56 +00:00
unset ( $roles [ DRUPAL_ANONYMOUS_RID ]);
unset ( $roles [ DRUPAL_AUTHENTICATED_RID ]);
2009-06-04 09:52:33 +00:00
$roles [ 0 ] = t ( 'disabled' );
$form [ 'admin_role' ][ 'user_admin_role' ] = array (
'#type' => 'select' ,
'#title' => t ( 'Administrator role' ),
'#default_value' => variable_get ( 'user_admin_role' , 0 ),
'#options' => $roles ,
'#description' => t ( 'This role will be automatically assigned new permissions whenever a module is enabled. Changing this setting will not affect existing permissions.' ),
);
2009-05-16 20:10:50 +00:00
// User registration settings.
$form [ 'registration_cancellation' ] = array (
2009-01-08 08:42:13 +00:00
'#type' => 'fieldset' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Registration and cancellation' ),
);
$form [ 'registration_cancellation' ][ 'user_register' ] = array (
'#type' => 'radios' ,
'#title' => t ( 'Who can register accounts?' ),
'#default_value' => variable_get ( 'user_register' , 1 ),
'#options' => array (
t ( 'Administrators only' ),
t ( 'Visitors' ),
t ( 'Visitors, but administrator approval is required' ),
)
);
$form [ 'registration_cancellation' ][ 'user_email_verification' ] = array (
'#type' => 'checkbox' ,
'#title' => t ( 'Require e-mail verification when a visitor creates an account.' ),
'#default_value' => variable_get ( 'user_email_verification' , TRUE ),
2009-09-19 11:18:32 +00:00
'#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.' )
2009-01-08 08:42:13 +00:00
);
2009-05-16 20:10:50 +00:00
module_load_include ( 'inc' , 'user' , 'user.pages' );
$form [ 'registration_cancellation' ][ 'user_cancel_method' ] = array (
2009-01-08 08:42:13 +00:00
'#type' => 'item' ,
'#title' => t ( 'When cancelling a user account' ),
2010-02-07 17:29:09 +00:00
'#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/people/permissions' ))),
2009-01-08 08:42:13 +00:00
);
2009-05-16 20:10:50 +00:00
$form [ 'registration_cancellation' ][ 'user_cancel_method' ] += user_cancel_methods ();
foreach ( element_children ( $form [ 'registration_cancellation' ][ 'user_cancel_method' ]) as $element ) {
2009-01-08 08:42:13 +00:00
// Remove all account cancellation methods that have #access defined, as
// those cannot be configured as default method.
2009-05-16 20:10:50 +00:00
if ( isset ( $form [ 'registration_cancellation' ][ 'user_cancel_method' ][ $element ][ '#access' ])) {
$form [ 'registration_cancellation' ][ 'user_cancel_method' ][ $element ][ '#access' ] = FALSE ;
2009-01-08 08:42:13 +00:00
}
// Remove the description (only displayed on the confirmation form).
else {
2009-05-16 20:10:50 +00:00
unset ( $form [ 'registration_cancellation' ][ 'user_cancel_method' ][ $element ][ '#description' ]);
2009-01-08 08:42:13 +00:00
}
}
2009-05-16 20:10:50 +00:00
// Account settings.
$form [ 'personalization' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'fieldset' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Personalization' ),
);
$form [ 'personalization' ][ 'user_signatures' ] = array (
'#type' => 'checkbox' ,
'#title' => t ( 'Enable signatures.' ),
'#default_value' => variable_get ( 'user_signatures' , 0 ),
);
// If picture support is enabled, check whether the picture directory exists.
if ( variable_get ( 'user_pictures' , 0 )) {
2009-08-17 19:14:42 +00:00
$picture_path = variable_get ( 'file_default_scheme' , 'public' ) . '://' . variable_get ( 'user_picture_path' , 'pictures' );
if ( ! file_prepare_directory ( $picture_path , FILE_CREATE_DIRECTORY )) {
form_set_error ( 'user_picture_path' , t ( 'The directory %directory does not exist or is not writable.' , array ( '%directory' => $picture_path )));
watchdog ( 'file system' , 'The directory %directory does not exist or is not writable.' , array ( '%directory' => $picture_path ), WATCHDOG_ERROR );
}
2009-05-16 20:10:50 +00:00
}
$picture_support = variable_get ( 'user_pictures' , 0 );
$form [ 'personalization' ][ 'user_pictures' ] = array (
'#type' => 'checkbox' ,
'#title' => t ( 'Enable user pictures.' ),
'#default_value' => $picture_support ,
);
drupal_add_js ( drupal_get_path ( 'module' , 'user' ) . '/user.js' );
$form [ 'personalization' ][ 'pictures' ] = array (
2009-10-16 19:20:34 +00:00
'#type' => 'container' ,
'#states' => array (
// Hide the additional picture settings when user pictures are disabled.
'invisible' => array (
'input[name="user_pictures"]' => array ( 'checked' => FALSE ),
),
),
2009-05-16 20:10:50 +00:00
);
$form [ 'personalization' ][ 'pictures' ][ 'user_picture_path' ] = array (
'#type' => 'textfield' ,
'#title' => t ( 'Picture directory' ),
'#default_value' => variable_get ( 'user_picture_path' , 'pictures' ),
'#size' => 30 ,
'#maxlength' => 255 ,
'#description' => t ( 'Subdirectory in the directory %dir where pictures will be stored.' , array ( '%dir' => file_directory_path () . '/' )),
);
$form [ 'personalization' ][ 'pictures' ][ 'user_picture_default' ] = array (
'#type' => 'textfield' ,
'#title' => t ( 'Default picture' ),
'#default_value' => variable_get ( 'user_picture_default' , '' ),
'#size' => 30 ,
'#maxlength' => 255 ,
'#description' => t ( 'URL of picture to display for users with no custom picture selected. Leave blank for none.' ),
);
2009-07-12 08:36:35 +00:00
if ( module_exists ( 'image' )) {
$form [ 'personalization' ][ 'pictures' ][ 'settings' ][ 'user_picture_style' ] = array (
'#type' => 'select' ,
2009-07-21 07:09:47 +00:00
'#title' => t ( 'Picture display style' ),
2009-07-12 08:36:35 +00:00
'#options' => image_style_options ( TRUE ),
'#default_value' => variable_get ( 'user_picture_style' , '' ),
2009-08-20 10:48:03 +00:00
'#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' ))),
2009-07-12 08:36:35 +00:00
);
}
2009-05-16 20:10:50 +00:00
$form [ 'personalization' ][ 'pictures' ][ 'user_picture_dimensions' ] = array (
'#type' => 'textfield' ,
2009-07-21 07:09:47 +00:00
'#title' => t ( 'Picture upload dimensions' ),
2009-05-16 20:10:50 +00:00
'#default_value' => variable_get ( 'user_picture_dimensions' , '85x85' ),
2009-07-21 07:09:47 +00:00
'#size' => 10 ,
2009-05-16 20:10:50 +00:00
'#maxlength' => 10 ,
2009-07-21 07:09:47 +00:00
'#field_suffix' => ' ' . t ( 'pixels' ),
'#description' => t ( 'Maximum allowed dimensions for uploaded pictures.' ),
2009-05-16 20:10:50 +00:00
);
$form [ 'personalization' ][ 'pictures' ][ 'user_picture_file_size' ] = array (
'#type' => 'textfield' ,
2009-07-21 07:09:47 +00:00
'#title' => t ( 'Picture upload file size' ),
2009-05-16 20:10:50 +00:00
'#default_value' => variable_get ( 'user_picture_file_size' , '30' ),
2009-07-21 07:09:47 +00:00
'#size' => 10 ,
2009-05-16 20:10:50 +00:00
'#maxlength' => 10 ,
2009-07-21 07:09:47 +00:00
'#field_suffix' => ' ' . t ( 'KB' ),
'#description' => t ( 'Maximum allowed file size for uploaded pictures.' ),
2009-05-16 20:10:50 +00:00
);
$form [ 'personalization' ][ 'pictures' ][ 'user_picture_guidelines' ] = array (
'#type' => 'textarea' ,
'#title' => t ( 'Picture guidelines' ),
'#default_value' => variable_get ( 'user_picture_guidelines' , '' ),
'#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. " ),
);
$form [ 'email_title' ] = array (
'#type' => 'item' ,
'#title' => t ( 'E-mails' ),
);
$form [ 'email' ] = array (
'#type' => 'vertical_tabs' ,
2007-09-10 13:14:38 +00:00
);
// These email tokens are shared for all settings, so just define
// the list once to help ensure they stay in sync.
2010-01-29 13:50:14 +00:00
$email_token_help = t ( 'You can use the following tokens in your e-mail message text: !site-name-token, !site-url-token, !user-name-token, !user-mail-token, !site-login-url-token, !user-edit-url-token, !user-one-time-login-url-token, !user-cancel-url-token' , array ( '!site-name-token' => '[site:name]' , '!site-url-token' => '[site:url]' , '!user-name-token' => '[user:name]' , '!user-mail-token' => '[user:mail]' , '!site-login-url-token' => '[site:login-url]' , '!user-edit-url-token' => '[user:edit-url]' , '!user-one-time-login-url-token' => '[user:one-time-login-url]' , '!user-cancel-url-token' => '[user:cancel-url]' ));
2007-09-10 13:14:38 +00:00
2009-05-16 20:10:50 +00:00
$form [ 'email_admin_created' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'fieldset' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Welcome (new user created by administrator)' ),
2007-09-10 13:14:38 +00:00
'#collapsible' => TRUE ,
'#collapsed' => ( variable_get ( 'user_register' , 1 ) != 0 ),
2010-01-14 04:04:30 +00:00
'#description' => t ( 'Edit the welcome e-mail messages sent to new member accounts created by an administrator.' ) . ' ' . $email_token_help ,
2009-05-16 20:10:50 +00:00
'#group' => 'email' ,
2007-09-10 13:14:38 +00:00
);
2009-05-16 20:10:50 +00:00
$form [ 'email_admin_created' ][ 'user_mail_register_admin_created_subject' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Subject' ),
2010-01-29 13:50:14 +00:00
'#default_value' => _user_mail_text ( 'register_admin_created_subject' , NULL , array (), FALSE ),
2007-09-10 13:14:38 +00:00
'#maxlength' => 180 ,
);
2009-05-16 20:10:50 +00:00
$form [ 'email_admin_created' ][ 'user_mail_register_admin_created_body' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textarea' ,
'#title' => t ( 'Body' ),
2010-01-29 13:50:14 +00:00
'#default_value' => _user_mail_text ( 'register_admin_created_body' , NULL , array (), FALSE ),
2007-09-10 13:14:38 +00:00
'#rows' => 15 ,
);
2009-06-28 20:51:09 +00:00
$form [ 'email_pending_approval' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'fieldset' ,
2009-06-28 20:51:09 +00:00
'#title' => t ( 'Welcome (awaiting approval)' ),
2007-09-10 13:14:38 +00:00
'#collapsible' => TRUE ,
2009-06-28 20:51:09 +00:00
'#collapsed' => ( variable_get ( 'user_register' , 1 ) != 2 ),
2010-01-14 04:04:30 +00:00
'#description' => t ( 'Edit the welcome e-mail messages sent to new members upon registering, when administrative approval is required.' ) . ' ' . $email_token_help ,
2009-05-16 20:10:50 +00:00
'#group' => 'email' ,
2007-09-10 13:14:38 +00:00
);
2009-06-28 20:51:09 +00:00
$form [ 'email_pending_approval' ][ 'user_mail_register_pending_approval_subject' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Subject' ),
2010-01-29 13:50:14 +00:00
'#default_value' => _user_mail_text ( 'register_pending_approval_subject' , NULL , array (), FALSE ),
2007-09-10 13:14:38 +00:00
'#maxlength' => 180 ,
);
2009-06-28 20:51:09 +00:00
$form [ 'email_pending_approval' ][ 'user_mail_register_pending_approval_body' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textarea' ,
'#title' => t ( 'Body' ),
2010-01-29 13:50:14 +00:00
'#default_value' => _user_mail_text ( 'register_pending_approval_body' , NULL , array (), FALSE ),
2009-06-28 20:51:09 +00:00
'#rows' => 8 ,
2007-09-10 13:14:38 +00:00
);
2009-06-28 20:51:09 +00:00
$form [ 'email_no_approval_required' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'fieldset' ,
2009-06-28 20:51:09 +00:00
'#title' => t ( 'Welcome (no approval required)' ),
2007-09-10 13:14:38 +00:00
'#collapsible' => TRUE ,
2009-06-28 20:51:09 +00:00
'#collapsed' => ( variable_get ( 'user_register' , 1 ) != 1 ),
2010-01-14 04:04:30 +00:00
'#description' => t ( 'Edit the welcome e-mail messages sent to new members upon registering, when no administrator approval is required.' ) . ' ' . $email_token_help ,
2009-05-16 20:10:50 +00:00
'#group' => 'email' ,
2007-09-10 13:14:38 +00:00
);
2009-06-28 20:51:09 +00:00
$form [ 'email_no_approval_required' ][ 'user_mail_register_no_approval_required_subject' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Subject' ),
2010-01-29 13:50:14 +00:00
'#default_value' => _user_mail_text ( 'register_no_approval_required_subject' , NULL , array (), FALSE ),
2007-09-10 13:14:38 +00:00
'#maxlength' => 180 ,
);
2009-06-28 20:51:09 +00:00
$form [ 'email_no_approval_required' ][ 'user_mail_register_no_approval_required_body' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textarea' ,
'#title' => t ( 'Body' ),
2010-01-29 13:50:14 +00:00
'#default_value' => _user_mail_text ( 'register_no_approval_required_body' , NULL , array (), FALSE ),
2009-06-28 20:51:09 +00:00
'#rows' => 15 ,
2007-09-10 13:14:38 +00:00
);
2009-07-12 08:36:35 +00:00
2009-05-16 20:10:50 +00:00
$form [ 'email_password_reset' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'fieldset' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Password recovery' ),
2007-09-10 13:14:38 +00:00
'#collapsible' => TRUE ,
'#collapsed' => TRUE ,
2010-01-14 04:04:30 +00:00
'#description' => t ( 'Edit the e-mail messages sent to users who request a new password.' ) . ' ' . $email_token_help ,
2009-05-16 20:10:50 +00:00
'#group' => 'email' ,
'#weight' => 10 ,
2007-09-10 13:14:38 +00:00
);
2009-05-16 20:10:50 +00:00
$form [ 'email_password_reset' ][ 'user_mail_password_reset_subject' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Subject' ),
2010-01-29 13:50:14 +00:00
'#default_value' => _user_mail_text ( 'password_reset_subject' , NULL , array (), FALSE ),
2007-09-10 13:14:38 +00:00
'#maxlength' => 180 ,
);
2009-05-16 20:10:50 +00:00
$form [ 'email_password_reset' ][ 'user_mail_password_reset_body' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textarea' ,
'#title' => t ( 'Body' ),
2010-01-29 13:50:14 +00:00
'#default_value' => _user_mail_text ( 'password_reset_body' , NULL , array (), FALSE ),
2007-09-10 13:14:38 +00:00
'#rows' => 12 ,
);
2009-05-16 20:10:50 +00:00
$form [ 'email_activated' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'fieldset' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Account activation' ),
2007-09-10 13:14:38 +00:00
'#collapsible' => TRUE ,
'#collapsed' => TRUE ,
2010-01-14 04:04:30 +00:00
'#description' => t ( 'Enable and edit 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 ,
2009-05-16 20:10:50 +00:00
'#group' => 'email' ,
2007-09-10 13:14:38 +00:00
);
2009-05-16 20:10:50 +00:00
$form [ 'email_activated' ][ 'user_mail_status_activated_notify' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'checkbox' ,
'#title' => t ( 'Notify user when account is activated.' ),
'#default_value' => variable_get ( 'user_mail_status_activated_notify' , TRUE ),
);
2009-10-16 19:20:34 +00:00
$form [ 'email_activated' ][ 'settings' ] = array (
'#type' => 'container' ,
'#states' => array (
// Hide the additional settings when this email is disabled.
'invisible' => array (
'input[name="user_mail_status_activated_notify"]' => array ( 'checked' => FALSE ),
),
),
);
$form [ 'email_activated' ][ 'settings' ][ 'user_mail_status_activated_subject' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Subject' ),
2010-01-29 13:50:14 +00:00
'#default_value' => _user_mail_text ( 'status_activated_subject' , NULL , array (), FALSE ),
2007-09-10 13:14:38 +00:00
'#maxlength' => 180 ,
);
2009-10-16 19:20:34 +00:00
$form [ 'email_activated' ][ 'settings' ][ 'user_mail_status_activated_body' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textarea' ,
'#title' => t ( 'Body' ),
2010-01-29 13:50:14 +00:00
'#default_value' => _user_mail_text ( 'status_activated_body' , NULL , array (), FALSE ),
2007-09-10 13:14:38 +00:00
'#rows' => 15 ,
);
2009-05-16 20:10:50 +00:00
$form [ 'email_blocked' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'fieldset' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Account blocked' ),
2007-09-10 13:14:38 +00:00
'#collapsible' => TRUE ,
'#collapsed' => TRUE ,
2010-01-14 04:04:30 +00:00
'#description' => t ( 'Enable and edit e-mail messages sent to users when their accounts are blocked.' ) . ' ' . $email_token_help ,
2009-05-16 20:10:50 +00:00
'#group' => 'email' ,
2007-09-10 13:14:38 +00:00
);
2009-05-16 20:10:50 +00:00
$form [ 'email_blocked' ][ 'user_mail_status_blocked_notify' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'checkbox' ,
'#title' => t ( 'Notify user when account is blocked.' ),
'#default_value' => variable_get ( 'user_mail_status_blocked_notify' , FALSE ),
);
2009-10-16 19:20:34 +00:00
$form [ 'email_blocked' ][ 'settings' ] = array (
'#type' => 'container' ,
'#states' => array (
// Hide the additional settings when the blocked email is disabled.
'invisible' => array (
'input[name="user_mail_status_blocked_notify"]' => array ( 'checked' => FALSE ),
),
),
);
$form [ 'email_blocked' ][ 'settings' ][ 'user_mail_status_blocked_subject' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Subject' ),
2010-01-29 13:50:14 +00:00
'#default_value' => _user_mail_text ( 'status_blocked_subject' , NULL , array (), FALSE ),
2007-09-10 13:14:38 +00:00
'#maxlength' => 180 ,
);
2009-10-16 19:20:34 +00:00
$form [ 'email_blocked' ][ 'settings' ][ 'user_mail_status_blocked_body' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textarea' ,
'#title' => t ( 'Body' ),
2010-01-29 13:50:14 +00:00
'#default_value' => _user_mail_text ( 'status_blocked_body' , NULL , array (), FALSE ),
2007-09-10 13:14:38 +00:00
'#rows' => 3 ,
);
2009-05-16 20:10:50 +00:00
$form [ 'email_cancel_confirm' ] = array (
2009-01-08 08:42:13 +00:00
'#type' => 'fieldset' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Account cancellation confirmation' ),
2009-01-08 08:42:13 +00:00
'#collapsible' => TRUE ,
'#collapsed' => TRUE ,
2010-01-14 04:04:30 +00:00
'#description' => t ( 'Edit the e-mail messages sent to users when they attempt to cancel their accounts.' ) . ' ' . $email_token_help ,
2009-05-16 20:10:50 +00:00
'#group' => 'email' ,
2009-01-08 08:42:13 +00:00
);
2009-05-16 20:10:50 +00:00
$form [ 'email_cancel_confirm' ][ 'user_mail_cancel_confirm_subject' ] = array (
2009-01-08 08:42:13 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Subject' ),
2010-01-29 13:50:14 +00:00
'#default_value' => _user_mail_text ( 'cancel_confirm_subject' , NULL , array (), FALSE ),
2009-01-08 08:42:13 +00:00
'#maxlength' => 180 ,
);
2009-05-16 20:10:50 +00:00
$form [ 'email_cancel_confirm' ][ 'user_mail_cancel_confirm_body' ] = array (
2009-01-08 08:42:13 +00:00
'#type' => 'textarea' ,
'#title' => t ( 'Body' ),
2010-01-29 13:50:14 +00:00
'#default_value' => _user_mail_text ( 'cancel_confirm_body' , NULL , array (), FALSE ),
2009-01-08 08:42:13 +00:00
'#rows' => 3 ,
);
2009-05-16 20:10:50 +00:00
$form [ 'email_canceled' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'fieldset' ,
2009-05-16 20:10:50 +00:00
'#title' => t ( 'Account canceled' ),
2007-09-10 13:14:38 +00:00
'#collapsible' => TRUE ,
'#collapsed' => TRUE ,
2010-01-14 04:04:30 +00:00
'#description' => t ( 'Enable and edit e-mail messages sent to users when their accounts are canceled.' ) . ' ' . $email_token_help ,
2009-05-16 20:10:50 +00:00
'#group' => 'email' ,
2007-09-10 13:14:38 +00:00
);
2009-05-16 20:10:50 +00:00
$form [ 'email_canceled' ][ 'user_mail_status_canceled_notify' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'checkbox' ,
2009-01-08 08:42:13 +00:00
'#title' => t ( 'Notify user when account is canceled.' ),
'#default_value' => variable_get ( 'user_mail_status_canceled_notify' , FALSE ),
2007-09-10 13:14:38 +00:00
);
2009-10-16 19:20:34 +00:00
$form [ 'email_canceled' ][ 'settings' ] = array (
'#type' => 'container' ,
'#states' => array (
2009-12-02 17:04:25 +00:00
// Hide the settings when the cancel notify checkbox is disabled.
2009-10-16 19:20:34 +00:00
'invisible' => array (
'input[name="user_mail_status_canceled_notify"]' => array ( 'checked' => FALSE ),
),
),
);
$form [ 'email_canceled' ][ 'settings' ][ 'user_mail_status_canceled_subject' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textfield' ,
'#title' => t ( 'Subject' ),
2010-01-29 13:50:14 +00:00
'#default_value' => _user_mail_text ( 'status_canceled_subject' , NULL , array (), FALSE ),
2007-09-10 13:14:38 +00:00
'#maxlength' => 180 ,
);
2009-10-16 19:20:34 +00:00
$form [ 'email_canceled' ][ 'settings' ][ 'user_mail_status_canceled_body' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textarea' ,
'#title' => t ( 'Body' ),
2010-01-29 13:50:14 +00:00
'#default_value' => _user_mail_text ( 'status_canceled_body' , NULL , array (), FALSE ),
2007-09-10 13:14:38 +00:00
'#rows' => 3 ,
);
2009-01-11 21:19:19 +00:00
return system_settings_form ( $form , FALSE );
2007-09-10 13:14:38 +00:00
}
/**
* Menu callback : administer permissions .
2007-10-02 16:03:17 +00:00
*
2007-09-10 13:14:38 +00:00
* @ ingroup forms
2009-07-05 18:07:04 +00:00
* @ see user_admin_permissions_submit ()
* @ see theme_user_admin_permissions ()
2007-09-10 13:14:38 +00:00
*/
2009-09-18 00:12:48 +00:00
function user_admin_permissions ( $form , $form_state , $rid = NULL ) {
2007-09-10 13:14:38 +00:00
2008-01-10 16:00:44 +00:00
// Retrieve role names for columns.
$role_names = user_roles ();
2007-09-10 13:14:38 +00:00
if ( is_numeric ( $rid )) {
2008-01-10 16:00:44 +00:00
$role_names = array ( $rid => $role_names [ $rid ]);
2007-09-10 13:14:38 +00:00
}
2008-05-07 19:34:24 +00:00
// Fetch permissions for all roles or the one selected role.
$role_permissions = user_role_permissions ( $role_names );
2007-09-10 13:14:38 +00:00
2008-05-07 19:34:24 +00:00
// Store $role_names for use when saving the data.
$form [ 'role_names' ] = array (
'#type' => 'value' ,
'#value' => $role_names ,
);
2007-09-10 13:14:38 +00:00
// Render role/permission overview:
$options = array ();
2009-10-27 04:08:42 +00:00
$module_info = system_get_info ( 'module' );
2010-03-21 21:20:43 +00:00
$hide_descriptions = system_admin_compact_mode ();
2009-12-02 17:04:25 +00:00
// Get a list of all the modules implementing a hook_permission() and sort by
// display name.
$modules = array ();
2009-07-05 18:00:11 +00:00
foreach ( module_implements ( 'permission' ) as $module ) {
2009-12-02 17:04:25 +00:00
$modules [ $module_info [ $module ][ 'name' ]] = $module ;
}
ksort ( $modules );
foreach ( $modules as $display_name => $module ) {
2009-07-05 18:00:11 +00:00
if ( $permissions = module_invoke ( $module , 'permission' )) {
2007-09-10 13:14:38 +00:00
$form [ 'permission' ][] = array (
2009-10-27 04:08:42 +00:00
'#markup' => $module_info [ $module ][ 'name' ],
2009-04-26 15:03:22 +00:00
'#id' => $module ,
2009-09-19 10:54:36 +00:00
);
2008-10-09 15:15:55 +00:00
foreach ( $permissions as $perm => $perm_item ) {
2010-03-21 21:20:43 +00:00
// 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.' ) : '' ,
);
2007-09-10 13:14:38 +00:00
$options [ $perm ] = '' ;
2008-02-20 13:46:43 +00:00
$form [ 'permission' ][ $perm ] = array (
'#type' => 'item' ,
2008-10-09 15:15:55 +00:00
'#markup' => $perm_item [ 'title' ],
2010-03-21 21:20:43 +00:00
'#description' => theme ( 'user_permission_description' , array ( 'permission_item' => $perm_item , 'hide' => $hide_descriptions )),
2008-02-20 13:46:43 +00:00
);
2007-09-10 13:14:38 +00:00
foreach ( $role_names as $rid => $name ) {
// Builds arrays for checked boxes for each role
2008-05-07 19:34:24 +00:00
if ( isset ( $role_permissions [ $rid ][ $perm ])) {
2007-09-10 13:14:38 +00:00
$status [ $rid ][] = $perm ;
}
}
}
}
}
// Have to build checkboxes here after checkbox arrays are built
foreach ( $role_names as $rid => $name ) {
$form [ 'checkboxes' ][ $rid ] = array ( '#type' => 'checkboxes' , '#options' => $options , '#default_value' => isset ( $status [ $rid ]) ? $status [ $rid ] : array ());
2008-07-16 21:59:29 +00:00
$form [ 'role_names' ][ $rid ] = array ( '#markup' => $name , '#tree' => TRUE );
2007-09-10 13:14:38 +00:00
}
2010-01-30 07:59:26 +00:00
2010-01-03 21:01:04 +00:00
$form [ 'actions' ] = array ( '#type' => 'container' , '#attributes' => array ( 'class' => array ( 'form-actions' )));
$form [ 'actions' ][ 'submit' ] = array ( '#type' => 'submit' , '#value' => t ( 'Save permissions' ));
2007-09-10 13:14:38 +00:00
2009-09-05 15:05:05 +00:00
$form [ '#attached' ][ 'js' ][] = drupal_get_path ( 'module' , 'user' ) . '/user.permissions.js' ;
2009-05-10 19:16:03 +00:00
2007-09-10 13:14:38 +00:00
return $form ;
}
2008-05-07 19:34:24 +00:00
/**
* Save permissions selected on the administer permissions page .
*
2009-07-05 18:07:04 +00:00
* @ see user_admin_permissions ()
2008-05-07 19:34:24 +00:00
*/
2009-07-05 18:07:04 +00:00
function user_admin_permissions_submit ( $form , & $form_state ) {
2008-05-07 19:34:24 +00:00
foreach ( $form_state [ 'values' ][ 'role_names' ] as $rid => $name ) {
2009-09-19 10:54:36 +00:00
user_role_change_permissions ( $rid , $form_state [ 'values' ][ $rid ]);
2007-09-10 13:14:38 +00:00
}
drupal_set_message ( t ( 'The changes have been saved.' ));
2008-05-07 19:34:24 +00:00
// Clear the cached pages and blocks.
2007-09-10 13:14:38 +00:00
cache_clear_all ();
}
/**
* Theme the administer permissions page .
*
* @ ingroup themeable
*/
2009-10-09 01:00:08 +00:00
function theme_user_admin_permissions ( $variables ) {
$form = $variables [ 'form' ];
2007-10-01 09:04:54 +00:00
$roles = user_roles ();
2007-09-10 13:14:38 +00:00
foreach ( element_children ( $form [ 'permission' ]) as $key ) {
2009-06-15 09:49:58 +00:00
$row = array ();
// Module name
if ( is_numeric ( $key )) {
2009-08-22 14:34:23 +00:00
$row [] = array ( 'data' => drupal_render ( $form [ 'permission' ][ $key ]), 'class' => array ( 'module' ), 'id' => 'module-' . $form [ 'permission' ][ $key ][ '#id' ], 'colspan' => count ( $form [ 'role_names' ][ '#value' ]) + 1 );
2009-06-15 09:49:58 +00:00
}
else {
// Permission row.
$row [] = array (
'data' => drupal_render ( $form [ 'permission' ][ $key ]),
2009-08-22 14:34:23 +00:00
'class' => array ( 'permission' ),
2009-06-15 09:49:58 +00:00
);
foreach ( element_children ( $form [ 'checkboxes' ]) as $rid ) {
2009-08-22 14:34:23 +00:00
$row [] = array ( 'data' => drupal_render ( $form [ 'checkboxes' ][ $rid ][ $key ]), 'class' => array ( 'checkbox' ), 'title' => $roles [ $rid ] . ' : ' . t ( $key ));
2007-09-10 13:14:38 +00:00
}
}
2009-06-15 09:49:58 +00:00
$rows [] = $row ;
2007-09-10 13:14:38 +00:00
}
$header [] = ( t ( 'Permission' ));
foreach ( element_children ( $form [ 'role_names' ]) as $rid ) {
2009-08-22 14:34:23 +00:00
$header [] = array ( 'data' => drupal_render ( $form [ 'role_names' ][ $rid ]), 'class' => array ( 'checkbox' ));
2007-09-10 13:14:38 +00:00
}
2008-02-20 13:46:43 +00:00
$output = theme ( 'system_compact_link' );
2009-10-09 01:00:08 +00:00
$output .= theme ( 'table' , array ( 'header' => $header , 'rows' => $rows , 'attributes' => array ( 'id' => 'permissions' )));
2009-02-03 18:55:32 +00:00
$output .= drupal_render_children ( $form );
2007-09-10 13:14:38 +00:00
return $output ;
}
2010-03-21 21:20:43 +00:00
/**
* Theme an individual permission description .
*
* @ 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 );
}
}
}
2007-09-10 13:14:38 +00:00
/**
2010-03-24 07:34:10 +00:00
* Form to re - order roles or add a new one .
2010-03-23 19:22:58 +00:00
*
2007-09-10 13:14:38 +00:00
* @ ingroup forms
2010-03-24 07:34:10 +00:00
* @ see theme_user_admin_roles ()
2007-09-10 13:14:38 +00:00
*/
2010-03-24 07:34:10 +00:00
function user_admin_roles ( $form , $form_state ) {
$roles = user_roles ();
$form [ 'roles' ] = array (
'#tree' => TRUE ,
);
$order = 0 ;
foreach ( $roles as $rid => $name ) {
$form [ 'roles' ][ $rid ][ '#role' ] = ( object ) array (
'rid' => $rid ,
'name' => $name ,
'weight' => $order ,
2007-09-10 13:14:38 +00:00
);
2010-03-24 07:34:10 +00:00
$form [ 'roles' ][ $rid ][ '#weight' ] = $order ;
$form [ 'roles' ][ $rid ][ 'weight' ] = array (
2007-09-10 13:14:38 +00:00
'#type' => 'textfield' ,
2010-03-24 07:34:10 +00:00
'#size' => 4 ,
'#default_value' => $order ,
'#attributes' => array ( 'class' => array ( 'role-weight' )),
2007-09-10 13:14:38 +00:00
);
2010-03-24 07:34:10 +00:00
$order ++ ;
}
$form [ 'name' ] = array (
'#type' => 'textfield' ,
'#size' => 32 ,
'#maxlength' => 64 ,
);
$form [ 'add' ] = array (
'#type' => 'submit' ,
'#value' => t ( 'Add role' ),
'#validate' => array ( 'user_admin_role_validate' ),
'#submit' => array ( 'user_admin_role_submit' ),
);
$form [ 'submit' ] = array (
'#type' => 'submit' ,
'#value' => t ( 'Save order' ),
'#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' ];
user_role_save ( $role );
}
}
/**
* Theme the role order and new role form .
*
* @ ingroup themeable
*/
function theme_user_admin_roles ( $variables ) {
$form = $variables [ 'form' ];
$header = array ( t ( 'Name' ), t ( 'Weight' ), array ( 'data' => t ( 'Operations' ), 'colspan' => 2 ));
foreach ( element_children ( $form [ 'roles' ]) as $rid ) {
$name = $form [ 'roles' ][ $rid ][ '#role' ] -> name ;
$row = array ();
if ( in_array ( $rid , array ( DRUPAL_ANONYMOUS_RID , DRUPAL_AUTHENTICATED_RID ))) {
$row [] = t ( '@name <em>(locked)</em>' , array ( '@name' => $name ));
$row [] = drupal_render ( $form [ 'roles' ][ $rid ][ 'weight' ]);
$row [] = '' ;
$row [] = l ( t ( 'edit permissions' ), 'admin/people/permissions/' . $rid );
}
else {
$row [] = check_plain ( $name );
$row [] = drupal_render ( $form [ 'roles' ][ $rid ][ 'weight' ]);
$row [] = l ( t ( 'edit role' ), 'admin/people/permissions/roles/edit/' . $rid );
$row [] = l ( t ( 'edit permissions' ), 'admin/people/permissions/' . $rid );
}
$rows [] = array ( 'data' => $row , 'class' => array ( 'draggable' ));
2007-09-10 13:14:38 +00:00
}
2010-03-24 07:34:10 +00:00
$rows [] = array ( array ( 'data' => drupal_render ( $form [ 'name' ]) . drupal_render ( $form [ 'add' ]), 'colspan' => 4 , 'class' => 'edit-name' ));
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_validate ()
* @ see user_admin_role_submit ()
*/
function user_admin_role ( $form , $form_state , $role ) {
if ( $role -> rid == DRUPAL_ANONYMOUS_RID || $role -> rid == DRUPAL_AUTHENTICATED_RID ) {
drupal_goto ( 'admin/people/permissions/roles' );
}
// Display the edit role form.
$form [ 'name' ] = array (
'#type' => 'textfield' ,
'#title' => t ( 'Role name' ),
'#default_value' => $role -> name ,
'#size' => 30 ,
'#required' => TRUE ,
'#maxlength' => 64 ,
'#description' => t ( 'The name for this role. Example: "moderator", "editorial board", "site architect".' ),
);
$form [ 'rid' ] = array (
'#type' => 'value' ,
'#value' => $role -> rid ,
);
$form [ 'weight' ] = array (
'#type' => 'value' ,
'#value' => $role -> weight ,
);
$form [ 'actions' ] = array ( '#type' => 'container' , '#attributes' => array ( 'class' => array ( 'form-actions' )));
$form [ 'actions' ][ 'submit' ] = array (
'#type' => 'submit' ,
'#value' => t ( 'Save role' ),
);
$form [ 'actions' ][ 'delete' ] = array (
'#type' => 'submit' ,
'#value' => t ( 'Delete role' ),
2010-03-26 22:24:31 +00:00
'#submit' => array ( 'user_admin_role_delete_submit' ),
2010-03-24 07:34:10 +00:00
);
2007-09-10 13:14:38 +00:00
return $form ;
}
2010-03-23 19:22:58 +00:00
/**
* Form validation handler for the user_admin_role () form .
*/
2007-09-10 13:14:38 +00:00
function user_admin_role_validate ( $form , & $form_state ) {
2010-03-23 19:22:58 +00:00
if ( ! empty ( $form_state [ 'values' ][ 'name' ])) {
2007-09-10 13:14:38 +00:00
if ( $form_state [ 'values' ][ 'op' ] == t ( 'Save role' )) {
2010-03-23 19:22:58 +00:00
$role = user_role_load_by_name ( $form_state [ 'values' ][ 'name' ]);
2009-10-09 01:00:08 +00:00
if ( $role && $role -> rid != $form_state [ 'values' ][ 'rid' ]) {
2010-01-09 23:03:22 +00:00
form_set_error ( 'name' , t ( 'The role name %name already exists. Choose another role name.' , array ( '%name' => $form_state [ 'values' ][ 'name' ])));
2007-09-10 13:14:38 +00:00
}
}
2008-10-12 04:30:09 +00:00
elseif ( $form_state [ 'values' ][ 'op' ] == t ( 'Add role' )) {
2010-03-23 19:22:58 +00:00
if ( user_role_load_by_name ( $form_state [ 'values' ][ 'name' ])) {
2010-01-09 23:03:22 +00:00
form_set_error ( 'name' , t ( 'The role name %name already exists. Choose another role name.' , array ( '%name' => $form_state [ 'values' ][ 'name' ])));
2007-09-10 13:14:38 +00:00
}
}
}
else {
form_set_error ( 'name' , t ( 'You must specify a valid role name.' ));
}
}
2010-03-26 22:24:31 +00:00
/**
* Form submit handler for the user_admin_role () form .
*/
2007-09-10 13:14:38 +00:00
function user_admin_role_submit ( $form , & $form_state ) {
2009-08-27 20:25:29 +00:00
$role = ( object ) $form_state [ 'values' ];
2007-09-10 13:14:38 +00:00
if ( $form_state [ 'values' ][ 'op' ] == t ( 'Save role' )) {
2009-08-27 20:25:29 +00:00
user_role_save ( $role );
2007-09-10 13:14:38 +00:00
drupal_set_message ( t ( 'The role has been renamed.' ));
}
2008-10-12 04:30:09 +00:00
elseif ( $form_state [ 'values' ][ 'op' ] == t ( 'Add role' )) {
2009-08-27 20:25:29 +00:00
user_role_save ( $role );
2007-09-10 13:14:38 +00:00
drupal_set_message ( t ( 'The role has been added.' ));
}
2010-02-07 17:29:09 +00:00
$form_state [ 'redirect' ] = 'admin/people/permissions/roles' ;
2007-09-10 13:14:38 +00:00
return ;
}
2010-03-26 22:24:31 +00:00
/**
* Form submit handler for the user_admin_role () form .
*/
function user_admin_role_delete_submit ( $form , & $form_state ) {
$form_state [ 'redirect' ] = 'admin/people/permissions/roles/delete/' . $form_state [ 'values' ][ 'rid' ];
}
/**
* Form to confirm role delete operation .
*/
function user_admin_role_delete_confirm ( $form , & $form_state , $role ) {
$form [ 'rid' ] = array (
'#type' => 'value' ,
'#value' => $role -> rid ,
);
return confirm_form ( $form , t ( 'Are you sure you want to delete the role %name ?' , array ( '%name' => $role -> name )), 'admin/people/permissions/roles' , t ( 'This action cannot be undone.' ), t ( 'Delete' ));
}
/**
* Form submit handler for user_admin_role_delete_confirm () .
*/
function user_admin_role_delete_confirm_submit ( $form , & $form_state ) {
user_role_delete (( int ) $form_state [ 'values' ][ 'rid' ]);
drupal_set_message ( t ( 'The role has been deleted.' ));
$form_state [ 'redirect' ] = 'admin/people/permissions/roles' ;
}
2007-09-10 13:14:38 +00:00
/**
* Theme user administration filter selector .
2007-10-02 16:03:17 +00:00
*
2007-09-10 13:14:38 +00:00
* @ ingroup themeable
*/
2009-10-09 01:00:08 +00:00
function theme_user_filters ( $variables ) {
$form = $variables [ 'form' ];
2009-02-18 14:28:25 +00:00
$output = '<ul class="clearfix">' ;
2007-09-10 13:14:38 +00:00
if ( ! empty ( $form [ 'current' ])) {
foreach ( element_children ( $form [ 'current' ]) as $key ) {
2008-04-14 17:48:46 +00:00
$output .= '<li>' . drupal_render ( $form [ 'current' ][ $key ]) . '</li>' ;
2007-09-10 13:14:38 +00:00
}
}
2009-11-17 02:50:41 +00:00
$output .= '</ul>' ;
2007-09-10 13:14:38 +00:00
2010-03-07 06:49:10 +00:00
$output .= '<div class="clearfix">' ;
2009-11-17 02:50:41 +00:00
$output .= '<dl class="multiselect">' . ( ! empty ( $form [ 'current' ]) ? '<dt><em>' . t ( 'and' ) . '</em> ' . t ( 'where' ) . '</dt>' : '' );
2007-09-10 13:14:38 +00:00
2009-11-17 02:50:41 +00:00
$output .= '<dd>' ;
2007-09-10 13:14:38 +00:00
foreach ( element_children ( $form [ 'status' ]) as $key ) {
$output .= drupal_render ( $form [ 'status' ][ $key ]);
}
$output .= '</dd>' ;
$output .= '</dl>' ;
2010-01-03 21:01:04 +00:00
$output .= drupal_render ( $form [ 'actions' ]);
2007-09-10 13:14:38 +00:00
2010-03-07 06:49:10 +00:00
$output .= '</div>' ;
2007-09-10 13:14:38 +00:00
return $output ;
}