123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053 |
- <?php
- function user_admin($callback_arg = '') {
- $op = isset($_POST['op']) ? $_POST['op'] : $callback_arg;
- switch ($op) {
- case t('Create new account'):
- case 'create':
- $build['user_register'] = drupal_get_form('user_register_form');
- break;
- default:
- if (!empty($_POST['accounts']) && isset($_POST['operation']) && ($_POST['operation'] == 'cancel')) {
- $build['user_multiple_cancel_confirm'] = drupal_get_form('user_multiple_cancel_confirm');
- }
- else {
- $build['user_filter_form'] = drupal_get_form('user_filter_form');
- $build['user_admin_account'] = drupal_get_form('user_admin_account');
- }
- }
- return $build;
- }
- function user_filter_form() {
- $session = isset($_SESSION['user_overview_filter']) ? $_SESSION['user_overview_filter'] : array();
- $filters = user_filters();
- $i = 0;
- $form['filters'] = array(
- '#type' => 'fieldset',
- '#title' => t('Show only users where'),
- '#theme' => 'exposed_filters__user',
- );
- foreach ($session as $filter) {
- list($type, $value) = $filter;
- if ($type == 'permission') {
-
-
- $options = call_user_func_array('array_merge', array_slice($filters[$type]['options'], 1));
- $value = $options[$value];
- }
- else {
- $value = $filters[$type]['options'][$value];
- }
- $t_args = array('%property' => $filters[$type]['title'], '%value' => $value);
- if ($i++) {
- $form['filters']['current'][] = array('#markup' => t('and where %property is %value', $t_args));
- }
- else {
- $form['filters']['current'][] = array('#markup' => t('%property is %value', $t_args));
- }
- }
- $form['filters']['status'] = array(
- '#type' => 'container',
- '#attributes' => array('class' => array('clearfix')),
- '#prefix' => ($i ? '<div class="additional-filters">' . t('and where') . '</div>' : ''),
- );
- $form['filters']['status']['filters'] = array(
- '#type' => 'container',
- '#attributes' => array('class' => array('filters')),
- );
- foreach ($filters as $key => $filter) {
- $form['filters']['status']['filters'][$key] = array(
- '#type' => 'select',
- '#options' => $filter['options'],
- '#title' => $filter['title'],
- '#default_value' => '[any]',
- );
- }
- $form['filters']['status']['actions'] = array(
- '#type' => 'actions',
- '#attributes' => array('class' => array('container-inline')),
- );
- $form['filters']['status']['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => (count($session) ? t('Refine') : t('Filter')),
- );
- if (count($session)) {
- $form['filters']['status']['actions']['undo'] = array(
- '#type' => 'submit',
- '#value' => t('Undo'),
- );
- $form['filters']['status']['actions']['reset'] = array(
- '#type' => 'submit',
- '#value' => t('Reset'),
- );
- }
- drupal_add_library('system', 'drupal.form');
- return $form;
- }
- function user_filter_form_submit($form, &$form_state) {
- $op = $form_state['values']['op'];
- $filters = user_filters();
- switch ($op) {
- case t('Filter'):
- case t('Refine'):
-
- foreach ($filters as $filter => $options) {
- if (isset($form_state['values'][$filter]) && $form_state['values'][$filter] != '[any]') {
-
- $options = ($filter == 'permission') ? form_options_flatten($filters[$filter]['options']) : $filters[$filter]['options'];
-
- if (isset($options[$form_state['values'][$filter]])) {
- $_SESSION['user_overview_filter'][] = array($filter, $form_state['values'][$filter]);
- }
- }
- }
- break;
- case t('Undo'):
- array_pop($_SESSION['user_overview_filter']);
- break;
- case t('Reset'):
- $_SESSION['user_overview_filter'] = array();
- break;
- case t('Update'):
- return;
- }
- $form_state['redirect'] = 'admin/people';
- return;
- }
- function user_admin_account() {
- $header = array(
- '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')),
- );
- $query = db_select('users', 'u');
- $query->condition('u.uid', 0, '<>');
- user_build_filter_query($query);
- $count_query = clone $query;
- $count_query->addExpression('COUNT(u.uid)');
- $query = $query->extend('PagerDefault')->extend('TableSort');
- $query
- ->fields('u', array('uid', 'name', 'status', 'created', 'access'))
- ->limit(50)
- ->orderByHeader($header)
- ->setCountQuery($count_query);
- $result = $query->execute();
- $form['options'] = array(
- '#type' => 'fieldset',
- '#title' => t('Update options'),
- '#attributes' => array('class' => array('container-inline')),
- );
- $options = array();
- foreach (module_invoke_all('user_operations') as $operation => $array) {
- $options[$operation] = $array['label'];
- }
- $form['options']['operation'] = array(
- '#type' => 'select',
- '#title' => t('Operation'),
- '#title_display' => 'invisible',
- '#options' => $options,
- '#default_value' => 'unblock',
- );
- $options = array();
- $form['options']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Update'),
- );
- $destination = drupal_get_destination();
- $status = array(t('blocked'), t('active'));
- $roles = array_map('check_plain', user_roles(TRUE));
- $accounts = array();
- foreach ($result as $account) {
- $users_roles = array();
- $roles_result = db_query('SELECT rid FROM {users_roles} WHERE uid = :uid', array(':uid' => $account->uid));
- foreach ($roles_result as $user_role) {
- $users_roles[] = $roles[$user_role->rid];
- }
- asort($users_roles);
- $options[$account->uid] = array(
- 'username' => theme('username', array('account' => $account)),
- 'status' => $status[$account->status],
- 'roles' => theme('item_list', array('items' => $users_roles)),
- 'member_for' => format_interval(REQUEST_TIME - $account->created),
- 'access' => $account->access ? t('@time ago', array('@time' => format_interval(REQUEST_TIME - $account->access))) : t('never'),
- 'operations' => array('data' => array('#type' => 'link', '#title' => t('edit'), '#href' => "user/$account->uid/edit", '#options' => array('query' => $destination))),
- );
- }
- $form['accounts'] = array(
- '#type' => 'tableselect',
- '#header' => $header,
- '#options' => $options,
- '#empty' => t('No people available.'),
- );
- $form['pager'] = array('#markup' => theme('pager'));
- return $form;
- }
- function user_admin_account_submit($form, &$form_state) {
- $operations = module_invoke_all('user_operations', $form, $form_state);
- $operation = $operations[$form_state['values']['operation']];
-
- $accounts = array_filter($form_state['values']['accounts']);
- if ($function = $operation['callback']) {
-
- 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.'));
- }
- }
- function user_admin_settings() {
-
- $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,
- );
-
- $form['admin_role'] = array(
- '#type' => 'fieldset',
- '#title' => t('Administrator role'),
- );
-
-
- $roles = user_roles();
- unset($roles[DRUPAL_ANONYMOUS_RID]);
- unset($roles[DRUPAL_AUTHENTICATED_RID]);
- $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.'),
- );
-
- $form['registration_cancellation'] = array(
- '#type' => 'fieldset',
- '#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', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL),
- '#options' => array(
- USER_REGISTER_ADMINISTRATORS_ONLY => t('Administrators only'),
- USER_REGISTER_VISITORS => t('Visitors'),
- USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL => 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),
- '#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.')
- );
- module_load_include('inc', 'user', 'user.pages');
- $form['registration_cancellation']['user_cancel_method'] = array(
- '#type' => 'item',
- '#title' => t('When cancelling a user account'),
- '#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'))),
- );
- $form['registration_cancellation']['user_cancel_method'] += user_cancel_methods();
- foreach (element_children($form['registration_cancellation']['user_cancel_method']) as $element) {
-
-
- if (isset($form['registration_cancellation']['user_cancel_method'][$element]['#access'])) {
- $form['registration_cancellation']['user_cancel_method'][$element]['#access'] = FALSE;
- }
-
- else {
- unset($form['registration_cancellation']['user_cancel_method'][$element]['#description']);
- }
- }
-
- $form['personalization'] = array(
- '#type' => 'fieldset',
- '#title' => t('Personalization'),
- );
- $form['personalization']['user_signatures'] = array(
- '#type' => 'checkbox',
- '#title' => t('Enable signatures.'),
- '#default_value' => variable_get('user_signatures', 0),
- );
-
- if (variable_get('user_pictures', 0)) {
- $picture_path = file_default_scheme() . '://' . 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);
- }
- }
- $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(
- '#type' => 'container',
- '#states' => array(
-
- 'invisible' => array(
- 'input[name="user_pictures"]' => array('checked' => FALSE),
- ),
- ),
- );
- $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 file upload directory where pictures will be stored.'),
- );
- $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.'),
- );
- if (module_exists('image')) {
- $form['personalization']['pictures']['settings']['user_picture_style'] = array(
- '#type' => 'select',
- '#title' => t('Picture display style'),
- '#options' => image_style_options(TRUE, PASS_THROUGH),
- '#default_value' => variable_get('user_picture_style', ''),
- '#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'))),
- );
- }
- $form['personalization']['pictures']['user_picture_dimensions'] = array(
- '#type' => 'textfield',
- '#title' => t('Picture upload dimensions'),
- '#default_value' => variable_get('user_picture_dimensions', '85x85'),
- '#size' => 10,
- '#maxlength' => 10,
- '#field_suffix' => ' ' . t('pixels'),
- '#description' => t('Pictures larger than this will be scaled down to this size.'),
- );
- $form['personalization']['pictures']['user_picture_file_size'] = array(
- '#type' => 'textfield',
- '#title' => t('Picture upload file size'),
- '#default_value' => variable_get('user_picture_file_size', '30'),
- '#size' => 10,
- '#maxlength' => 10,
- '#field_suffix' => ' ' . t('KB'),
- '#description' => t('Maximum allowed file size for uploaded pictures. Upload size is normally limited only by the PHP maximum post and file upload settings, and images are automatically scaled down to the dimensions specified above.'),
- '#element_validate' => array('element_validate_integer_positive'),
- );
- $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',
- );
-
-
- $email_token_help = t('Available variables are: [site:name], [site:url], [user:name], [user:mail], [site:login-url], [site:url-brief], [user:edit-url], [user:one-time-login-url], [user:cancel-url].');
- $form['email_admin_created'] = array(
- '#type' => 'fieldset',
- '#title' => t('Welcome (new user created by administrator)'),
- '#collapsible' => TRUE,
- '#collapsed' => (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) != USER_REGISTER_ADMINISTRATORS_ONLY),
- '#description' => t('Edit the welcome e-mail messages sent to new member accounts created by an administrator.') . ' ' . $email_token_help,
- '#group' => 'email',
- );
- $form['email_admin_created']['user_mail_register_admin_created_subject'] = array(
- '#type' => 'textfield',
- '#title' => t('Subject'),
- '#default_value' => _user_mail_text('register_admin_created_subject', NULL, array(), FALSE),
- '#maxlength' => 180,
- );
- $form['email_admin_created']['user_mail_register_admin_created_body'] = array(
- '#type' => 'textarea',
- '#title' => t('Body'),
- '#default_value' => _user_mail_text('register_admin_created_body', NULL, array(), FALSE),
- '#rows' => 15,
- );
- $form['email_pending_approval'] = array(
- '#type' => 'fieldset',
- '#title' => t('Welcome (awaiting approval)'),
- '#collapsible' => TRUE,
- '#collapsed' => (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) != USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL),
- '#description' => t('Edit the welcome e-mail messages sent to new members upon registering, when administrative approval is required.') . ' ' . $email_token_help,
- '#group' => 'email',
- );
- $form['email_pending_approval']['user_mail_register_pending_approval_subject'] = array(
- '#type' => 'textfield',
- '#title' => t('Subject'),
- '#default_value' => _user_mail_text('register_pending_approval_subject', NULL, array(), FALSE),
- '#maxlength' => 180,
- );
- $form['email_pending_approval']['user_mail_register_pending_approval_body'] = array(
- '#type' => 'textarea',
- '#title' => t('Body'),
- '#default_value' => _user_mail_text('register_pending_approval_body', NULL, array(), FALSE),
- '#rows' => 8,
- );
- $form['email_no_approval_required'] = array(
- '#type' => 'fieldset',
- '#title' => t('Welcome (no approval required)'),
- '#collapsible' => TRUE,
- '#collapsed' => (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) != USER_REGISTER_VISITORS),
- '#description' => t('Edit the welcome e-mail messages sent to new members upon registering, when no administrator approval is required.') . ' ' . $email_token_help,
- '#group' => 'email',
- );
- $form['email_no_approval_required']['user_mail_register_no_approval_required_subject'] = array(
- '#type' => 'textfield',
- '#title' => t('Subject'),
- '#default_value' => _user_mail_text('register_no_approval_required_subject', NULL, array(), FALSE),
- '#maxlength' => 180,
- );
- $form['email_no_approval_required']['user_mail_register_no_approval_required_body'] = array(
- '#type' => 'textarea',
- '#title' => t('Body'),
- '#default_value' => _user_mail_text('register_no_approval_required_body', NULL, array(), FALSE),
- '#rows' => 15,
- );
- $form['email_password_reset'] = array(
- '#type' => 'fieldset',
- '#title' => t('Password recovery'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#description' => t('Edit the e-mail messages sent to users who request a new password.') . ' ' . $email_token_help,
- '#group' => 'email',
- '#weight' => 10,
- );
- $form['email_password_reset']['user_mail_password_reset_subject'] = array(
- '#type' => 'textfield',
- '#title' => t('Subject'),
- '#default_value' => _user_mail_text('password_reset_subject', NULL, array(), FALSE),
- '#maxlength' => 180,
- );
- $form['email_password_reset']['user_mail_password_reset_body'] = array(
- '#type' => 'textarea',
- '#title' => t('Body'),
- '#default_value' => _user_mail_text('password_reset_body', NULL, array(), FALSE),
- '#rows' => 12,
- );
- $form['email_activated'] = array(
- '#type' => 'fieldset',
- '#title' => t('Account activation'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#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,
- '#group' => 'email',
- );
- $form['email_activated']['user_mail_status_activated_notify'] = array(
- '#type' => 'checkbox',
- '#title' => t('Notify user when account is activated.'),
- '#default_value' => variable_get('user_mail_status_activated_notify', TRUE),
- );
- $form['email_activated']['settings'] = array(
- '#type' => 'container',
- '#states' => array(
-
- 'invisible' => array(
- 'input[name="user_mail_status_activated_notify"]' => array('checked' => FALSE),
- ),
- ),
- );
- $form['email_activated']['settings']['user_mail_status_activated_subject'] = array(
- '#type' => 'textfield',
- '#title' => t('Subject'),
- '#default_value' => _user_mail_text('status_activated_subject', NULL, array(), FALSE),
- '#maxlength' => 180,
- );
- $form['email_activated']['settings']['user_mail_status_activated_body'] = array(
- '#type' => 'textarea',
- '#title' => t('Body'),
- '#default_value' => _user_mail_text('status_activated_body', NULL, array(), FALSE),
- '#rows' => 15,
- );
- $form['email_blocked'] = array(
- '#type' => 'fieldset',
- '#title' => t('Account blocked'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#description' => t('Enable and edit e-mail messages sent to users when their accounts are blocked.') . ' ' . $email_token_help,
- '#group' => 'email',
- );
- $form['email_blocked']['user_mail_status_blocked_notify'] = array(
- '#type' => 'checkbox',
- '#title' => t('Notify user when account is blocked.'),
- '#default_value' => variable_get('user_mail_status_blocked_notify', FALSE),
- );
- $form['email_blocked']['settings'] = array(
- '#type' => 'container',
- '#states' => array(
-
- 'invisible' => array(
- 'input[name="user_mail_status_blocked_notify"]' => array('checked' => FALSE),
- ),
- ),
- );
- $form['email_blocked']['settings']['user_mail_status_blocked_subject'] = array(
- '#type' => 'textfield',
- '#title' => t('Subject'),
- '#default_value' => _user_mail_text('status_blocked_subject', NULL, array(), FALSE),
- '#maxlength' => 180,
- );
- $form['email_blocked']['settings']['user_mail_status_blocked_body'] = array(
- '#type' => 'textarea',
- '#title' => t('Body'),
- '#default_value' => _user_mail_text('status_blocked_body', NULL, array(), FALSE),
- '#rows' => 3,
- );
- $form['email_cancel_confirm'] = array(
- '#type' => 'fieldset',
- '#title' => t('Account cancellation confirmation'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#description' => t('Edit the e-mail messages sent to users when they attempt to cancel their accounts.') . ' ' . $email_token_help,
- '#group' => 'email',
- );
- $form['email_cancel_confirm']['user_mail_cancel_confirm_subject'] = array(
- '#type' => 'textfield',
- '#title' => t('Subject'),
- '#default_value' => _user_mail_text('cancel_confirm_subject', NULL, array(), FALSE),
- '#maxlength' => 180,
- );
- $form['email_cancel_confirm']['user_mail_cancel_confirm_body'] = array(
- '#type' => 'textarea',
- '#title' => t('Body'),
- '#default_value' => _user_mail_text('cancel_confirm_body', NULL, array(), FALSE),
- '#rows' => 3,
- );
- $form['email_canceled'] = array(
- '#type' => 'fieldset',
- '#title' => t('Account canceled'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#description' => t('Enable and edit e-mail messages sent to users when their accounts are canceled.') . ' ' . $email_token_help,
- '#group' => 'email',
- );
- $form['email_canceled']['user_mail_status_canceled_notify'] = array(
- '#type' => 'checkbox',
- '#title' => t('Notify user when account is canceled.'),
- '#default_value' => variable_get('user_mail_status_canceled_notify', FALSE),
- );
- $form['email_canceled']['settings'] = array(
- '#type' => 'container',
- '#states' => array(
-
- 'invisible' => array(
- 'input[name="user_mail_status_canceled_notify"]' => array('checked' => FALSE),
- ),
- ),
- );
- $form['email_canceled']['settings']['user_mail_status_canceled_subject'] = array(
- '#type' => 'textfield',
- '#title' => t('Subject'),
- '#default_value' => _user_mail_text('status_canceled_subject', NULL, array(), FALSE),
- '#maxlength' => 180,
- );
- $form['email_canceled']['settings']['user_mail_status_canceled_body'] = array(
- '#type' => 'textarea',
- '#title' => t('Body'),
- '#default_value' => _user_mail_text('status_canceled_body', NULL, array(), FALSE),
- '#rows' => 3,
- );
- return system_settings_form($form);
- }
- function user_admin_permissions($form, $form_state, $rid = NULL) {
-
- $role_names = user_roles();
- if (is_numeric($rid)) {
- $role_names = array($rid => $role_names[$rid]);
- }
-
- $role_permissions = user_role_permissions($role_names);
-
- $form['role_names'] = array(
- '#type' => 'value',
- '#value' => $role_names,
- );
-
- $options = array();
- $module_info = system_get_info('module');
- $hide_descriptions = system_admin_compact_mode();
-
-
- $modules = array();
- foreach (module_implements('permission') as $module) {
- $modules[$module] = $module_info[$module]['name'];
- }
- asort($modules);
- foreach ($modules as $module => $display_name) {
- if ($permissions = module_invoke($module, 'permission')) {
- $form['permission'][] = array(
- '#markup' => $module_info[$module]['name'],
- '#id' => $module,
- );
- foreach ($permissions as $perm => $perm_item) {
-
- $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.') : '',
- );
- $options[$perm] = '';
- $form['permission'][$perm] = array(
- '#type' => 'item',
- '#markup' => $perm_item['title'],
- '#description' => theme('user_permission_description', array('permission_item' => $perm_item, 'hide' => $hide_descriptions)),
- );
- foreach ($role_names as $rid => $name) {
-
- if (isset($role_permissions[$rid][$perm])) {
- $status[$rid][] = $perm;
- }
- }
- }
- }
- }
-
- foreach ($role_names as $rid => $name) {
- $form['checkboxes'][$rid] = array(
- '#type' => 'checkboxes',
- '#options' => $options,
- '#default_value' => isset($status[$rid]) ? $status[$rid] : array(),
- '#attributes' => array('class' => array('rid-' . $rid)),
- );
- $form['role_names'][$rid] = array('#markup' => check_plain($name), '#tree' => TRUE);
- }
- $form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save permissions'));
- $form['#attached']['js'][] = drupal_get_path('module', 'user') . '/user.permissions.js';
- return $form;
- }
- function user_admin_permissions_submit($form, &$form_state) {
- foreach ($form_state['values']['role_names'] as $rid => $name) {
- user_role_change_permissions($rid, $form_state['values'][$rid]);
- }
- drupal_set_message(t('The changes have been saved.'));
-
- cache_clear_all();
- }
- function theme_user_admin_permissions($variables) {
- $form = $variables['form'];
- $roles = user_roles();
- foreach (element_children($form['permission']) as $key) {
- $row = array();
-
- if (is_numeric($key)) {
- $row[] = array('data' => drupal_render($form['permission'][$key]), 'class' => array('module'), 'id' => 'module-' . $form['permission'][$key]['#id'], 'colspan' => count($form['role_names']['#value']) + 1);
- }
- else {
-
- $row[] = array(
- 'data' => drupal_render($form['permission'][$key]),
- 'class' => array('permission'),
- );
- foreach (element_children($form['checkboxes']) as $rid) {
- $form['checkboxes'][$rid][$key]['#title'] = $roles[$rid] . ': ' . $form['permission'][$key]['#markup'];
- $form['checkboxes'][$rid][$key]['#title_display'] = 'invisible';
- $row[] = array('data' => drupal_render($form['checkboxes'][$rid][$key]), 'class' => array('checkbox'));
- }
- }
- $rows[] = $row;
- }
- $header[] = (t('Permission'));
- foreach (element_children($form['role_names']) as $rid) {
- $header[] = array('data' => drupal_render($form['role_names'][$rid]), 'class' => array('checkbox'));
- }
- $output = theme('system_compact_link');
- $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'permissions')));
- $output .= drupal_render_children($form);
- return $output;
- }
- 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);
- }
- }
- }
- 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,
- );
- $form['roles'][$rid]['#weight'] = $order;
- $form['roles'][$rid]['weight'] = array(
- '#type' => 'textfield',
- '#title' => t('Weight for @title', array('@title' => $name)),
- '#title_display' => 'invisible',
- '#size' => 4,
- '#default_value' => $order,
- '#attributes' => array('class' => array('role-weight')),
- );
- $order++;
- }
- $form['name'] = array(
- '#type' => 'textfield',
- '#title' => t('Name'),
- '#title_display' => 'invisible',
- '#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['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save order'),
- '#submit' => array('user_admin_roles_order_submit'),
- );
- return $form;
- }
- 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);
- }
- drupal_set_message(t('The role settings have been updated.'));
- }
- 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'));
- }
- $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;
- }
- 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');
- }
-
- $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' => 'actions');
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save role'),
- );
- $form['actions']['delete'] = array(
- '#type' => 'submit',
- '#value' => t('Delete role'),
- '#submit' => array('user_admin_role_delete_submit'),
- );
- return $form;
- }
- function user_admin_role_validate($form, &$form_state) {
- if (!empty($form_state['values']['name'])) {
- if ($form_state['values']['op'] == t('Save role')) {
- $role = user_role_load_by_name($form_state['values']['name']);
- if ($role && $role->rid != $form_state['values']['rid']) {
- form_set_error('name', t('The role name %name already exists. Choose another role name.', array('%name' => $form_state['values']['name'])));
- }
- }
- elseif ($form_state['values']['op'] == t('Add role')) {
- if (user_role_load_by_name($form_state['values']['name'])) {
- form_set_error('name', t('The role name %name already exists. Choose another role name.', array('%name' => $form_state['values']['name'])));
- }
- }
- }
- else {
- form_set_error('name', t('You must specify a valid role name.'));
- }
- }
- function user_admin_role_submit($form, &$form_state) {
- $role = (object) $form_state['values'];
- if ($form_state['values']['op'] == t('Save role')) {
- user_role_save($role);
- drupal_set_message(t('The role has been renamed.'));
- }
- elseif ($form_state['values']['op'] == t('Add role')) {
- user_role_save($role);
- drupal_set_message(t('The role has been added.'));
- }
- $form_state['redirect'] = 'admin/people/permissions/roles';
- return;
- }
- function user_admin_role_delete_submit($form, &$form_state) {
- $form_state['redirect'] = 'admin/people/permissions/roles/delete/' . $form_state['values']['rid'];
- }
- 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'));
- }
- 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';
- }
|