2007-09-10 13:14:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Admin page callback file for the user module.
|
|
|
|
*/
|
|
|
|
|
2012-12-06 21:40:37 +00:00
|
|
|
/**
|
2013-06-13 20:57:33 +00:00
|
|
|
* Page callback: User administration page.
|
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'),
|
2012-09-26 18:26:15 +00:00
|
|
|
'status' => array('data' => t('Status'), 'field' => 'u.status', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
|
|
|
|
'roles' => array('data' => t('Roles'), 'class' => array(RESPONSIVE_PRIORITY_LOW)),
|
|
|
|
'member_for' => array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
|
|
|
|
'access' => array('data' => t('Last access'), 'field' => 'u.access', 'class' => array(RESPONSIVE_PRIORITY_LOW)),
|
2012-10-09 19:49:07 +00:00
|
|
|
'operations' => 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
|
|
|
|
2012-06-05 05:42:19 +00:00
|
|
|
$query = $query
|
|
|
|
->extend('Drupal\Core\Database\Query\PagerSelectExtender')
|
2012-06-08 12:26:56 +00:00
|
|
|
->extend('Drupal\Core\Database\Query\TableSortExtender');
|
2009-04-30 16:10:10 +00:00
|
|
|
$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
|
|
|
|
|
|
|
$destination = drupal_get_destination();
|
|
|
|
$status = array(t('blocked'), t('active'));
|
Issue #1479454 by Hugo Wetterberg, galooph, andypost, marcingy, heyrocker, larowlan, alexpott, tim.plunkett, fubhy, sun, dawehner: Convert user roles to configurables.
2013-01-19 21:53:56 +00:00
|
|
|
$roles = array_map('check_plain', user_role_names(TRUE));
|
2007-09-10 13:14:38 +00:00
|
|
|
$accounts = array();
|
2009-04-13 12:14:57 +00:00
|
|
|
foreach ($result as $account) {
|
2012-11-22 16:03:57 +00:00
|
|
|
$account = user_load($account->uid);
|
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);
|
2013-06-18 12:09:48 +00:00
|
|
|
$username = array(
|
|
|
|
'#theme' => 'username',
|
|
|
|
'#account' => $account,
|
|
|
|
);
|
|
|
|
$item_list = array(
|
|
|
|
'#theme' => 'item_list',
|
|
|
|
'#items' => $users_roles,
|
|
|
|
);
|
2009-10-08 18:26:33 +00:00
|
|
|
$options[$account->uid] = array(
|
2013-06-18 12:09:48 +00:00
|
|
|
'username' => drupal_render($username),
|
|
|
|
'status' => $status[$account->status],
|
|
|
|
'roles' => drupal_render($item_list),
|
2009-10-08 18:26:33 +00:00
|
|
|
'member_for' => format_interval(REQUEST_TIME - $account->created),
|
2013-06-18 12:09:48 +00:00
|
|
|
'access' => $account->access ? t('@time ago', array('@time' => format_interval(REQUEST_TIME - $account->access))) : t('never'),
|
2012-10-09 19:49:07 +00:00
|
|
|
);
|
|
|
|
$links = array();
|
|
|
|
$links['edit'] = array(
|
2013-02-18 17:16:37 +00:00
|
|
|
'title' => t('Edit'),
|
2012-11-22 16:03:57 +00:00
|
|
|
'href' => 'user/' . $account->uid . '/edit',
|
2012-10-09 19:49:07 +00:00
|
|
|
'query' => $destination,
|
|
|
|
);
|
2012-11-22 16:03:57 +00:00
|
|
|
if (module_invoke('translation_entity', 'translate_access', $account)) {
|
|
|
|
$links['translate'] = array(
|
2013-02-18 17:16:37 +00:00
|
|
|
'title' => t('Translate'),
|
2012-11-22 16:03:57 +00:00
|
|
|
'href' => 'user/' . $account->uid . '/translations',
|
|
|
|
'query' => $destination,
|
|
|
|
);
|
|
|
|
}
|
2012-10-09 19:49:07 +00:00
|
|
|
$options[$account->uid]['operations']['data'] = array(
|
|
|
|
'#type' => 'operations',
|
|
|
|
'#links' => $links,
|
2009-10-08 18:26:33 +00:00
|
|
|
);
|
2013-05-10 10:05:25 +00:00
|
|
|
|
|
|
|
$options[$account->uid]['title']['data']['#title'] = check_plain($account->name);
|
|
|
|
|
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(
|
2013-06-13 20:57:33 +00:00
|
|
|
'#theme' => 'table',
|
2009-10-08 18:26:33 +00:00
|
|
|
'#header' => $header,
|
2013-06-13 20:57:33 +00:00
|
|
|
'#rows' => $options,
|
2009-10-08 18:26:33 +00:00
|
|
|
'#empty' => t('No people available.'),
|
2007-09-10 13:14:38 +00:00
|
|
|
);
|
2013-06-18 12:09:48 +00:00
|
|
|
$form['pager'] = array(
|
|
|
|
'#theme' =>'pager',
|
|
|
|
);
|
2007-09-10 13:14:38 +00:00
|
|
|
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
Issue #1479454 by Hugo Wetterberg, galooph, andypost, marcingy, heyrocker, larowlan, alexpott, tim.plunkett, fubhy, sun, dawehner: Convert user roles to configurables.
2013-01-19 21:53:56 +00:00
|
|
|
$role_names = user_role_names();
|
2012-06-05 12:19:14 +00:00
|
|
|
if (isset($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.
|
2013-06-06 10:20:38 +00:00
|
|
|
$role_permissions = user_role_permissions(array_keys($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) {
|
2010-11-14 21:22:46 +00:00
|
|
|
$modules[$module] = $module_info[$module]['name'];
|
2009-12-02 17:04:25 +00:00
|
|
|
}
|
2010-11-14 21:22:46 +00:00
|
|
|
asort($modules);
|
2009-12-02 17:04:25 +00:00
|
|
|
|
2010-11-14 21:22:46 +00:00
|
|
|
foreach ($modules as $module => $display_name) {
|
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] = '';
|
2013-06-18 12:09:48 +00:00
|
|
|
$user_permission_description = array(
|
|
|
|
'#theme' => 'user_permission_description',
|
|
|
|
'#permission_item' => $perm_item,
|
|
|
|
'#hide' => $hide_descriptions,
|
|
|
|
);
|
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'],
|
2013-06-18 12:09:48 +00:00
|
|
|
'#description' => drupal_render($user_permission_description),
|
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) {
|
2011-07-03 17:48:22 +00:00
|
|
|
$form['checkboxes'][$rid] = array(
|
|
|
|
'#type' => 'checkboxes',
|
|
|
|
'#options' => $options,
|
|
|
|
'#default_value' => isset($status[$rid]) ? $status[$rid] : array(),
|
|
|
|
'#attributes' => array('class' => array('rid-' . $rid)),
|
|
|
|
);
|
2010-04-23 05:39:43 +00:00
|
|
|
$form['role_names'][$rid] = array('#markup' => check_plain($name), '#tree' => TRUE);
|
2007-09-10 13:14:38 +00:00
|
|
|
}
|
2010-01-30 07:59:26 +00:00
|
|
|
|
2010-04-24 14:49:14 +00:00
|
|
|
$form['actions'] = array('#type' => 'actions');
|
2010-01-03 21:01:04 +00:00
|
|
|
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save permissions'));
|
2007-09-10 13:14:38 +00:00
|
|
|
|
2012-08-30 19:24:38 +00:00
|
|
|
$form['#attached']['library'][] = array('user', 'drupal.user.permissions');
|
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.
|
2012-11-28 21:36:29 +00:00
|
|
|
cache_invalidate_tags(array('content' => TRUE));
|
2007-09-10 13:14:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-04-13 15:23:03 +00:00
|
|
|
* Returns HTML for the administer permissions page.
|
|
|
|
*
|
|
|
|
* @param $variables
|
|
|
|
* An associative array containing:
|
|
|
|
* - form: A render element representing the form.
|
2007-09-10 13:14:38 +00:00
|
|
|
*
|
|
|
|
* @ingroup themeable
|
|
|
|
*/
|
2009-10-09 01:00:08 +00:00
|
|
|
function theme_user_admin_permissions($variables) {
|
|
|
|
$form = $variables['form'];
|
|
|
|
|
Issue #1479454 by Hugo Wetterberg, galooph, andypost, marcingy, heyrocker, larowlan, alexpott, tim.plunkett, fubhy, sun, dawehner: Convert user roles to configurables.
2013-01-19 21:53:56 +00:00
|
|
|
$roles = user_role_names();
|
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) {
|
2010-11-17 04:10:52 +00:00
|
|
|
$form['checkboxes'][$rid][$key]['#title'] = $roles[$rid] . ': ' . $form['permission'][$key]['#markup'];
|
2010-07-28 02:04:44 +00:00
|
|
|
$form['checkboxes'][$rid][$key]['#title_display'] = 'invisible';
|
|
|
|
$row[] = array('data' => drupal_render($form['checkboxes'][$rid][$key]), 'class' => array('checkbox'));
|
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
|
|
|
}
|
2013-06-18 12:09:48 +00:00
|
|
|
$system_compact_link = array(
|
|
|
|
'#theme' => 'system_compact_link',
|
|
|
|
);
|
|
|
|
$table = array(
|
|
|
|
'#theme' => 'table',
|
|
|
|
'#header' => $header,
|
|
|
|
'#rows' => $rows,
|
|
|
|
'#attributes' => array(
|
|
|
|
'id' => 'permissions',
|
|
|
|
),
|
|
|
|
);
|
|
|
|
$output = drupal_render($system_compact_link);
|
|
|
|
$output .= drupal_render($table);
|
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
|
|
|
/**
|
2010-04-13 15:23:03 +00:00
|
|
|
* Returns HTML for an individual permission description.
|
2010-03-21 21:20:43 +00:00
|
|
|
*
|
|
|
|
* @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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|