summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerek Wright2007-05-18 19:06:07 (GMT)
committer Derek Wright2007-05-18 19:06:07 (GMT)
commit523a946f991fd66eff62a63a4b45089770e77d0b (patch)
tree5e038c9ad6e3325750570a99b8e512d4f2767322
parent6f03ebca687829d489a96391052e3401293e2e78 (diff)
#99531 by dww (inspired by a patch by salvis): "Switch users" block
should prefer to list users that are allowed to switch, and visually mark them (via theme('placeholder')) so you know who can switch back.
-rw-r--r--devel.module30
1 files changed, 23 insertions, 7 deletions
diff --git a/devel.module b/devel.module
index 3f36a09..22742d4 100644
--- a/devel.module
+++ b/devel.module
@@ -260,16 +260,32 @@ function devel_block($op = 'list', $delta = 0) {
else if ($op == 'view') {
switch ($delta) {
case 0:
- $block['subject'] = t('switch user');
+ $block['subject'] = t('Switch user');
+ $links = array();
if (user_access('switch users')) {
- $users = db_query_range('SELECT uid, name FROM {users} WHERE uid > 0 ORDER BY access DESC', 0, 10);
- while ($account = db_fetch_object($users)) {
- $dest = drupal_get_destination();
- $links[] = l(check_plain($account->name), 'devel/switch/'. $account->name, array(), $dest);
+ $dest = drupal_get_destination();
+ // Try to find at least 10 users that can switch.
+ $roles = user_roles(1, 'switch users');
+ $where = array('u.uid = 1');
+ if (count($roles)) {
+ $where[] = 'r.rid IN ('. implode(',', array_keys($roles)) .')';
+ }
+ $where_sql = implode(' OR ', $where);
+ $users = db_query_range("SELECT DISTINCT u.uid, u.name FROM {users} u LEFT JOIN {users_roles} r ON u.uid = r.uid WHERE $where_sql ORDER BY u.access DESC", 0, 10);
+ while ($user = db_fetch_object($users)) {
+ $links[$user->uid] = l(theme('placeholder', $user->name), 'devel/switch/'. $user->name, array('title' => t('This user can switch back.')), $dest, NULL, FALSE, TRUE);
+ }
+ $num_links = count($links);
+ if ($num_links < 10) {
+ // If we don't have enough, add distinct uids until we hit 10.
+ $users = db_query_range('SELECT uid, name FROM {users} WHERE uid NOT IN ('. implode(',', array_keys($links)) .') ORDER BY access DESC', 0, 10 - $num_links);
+ while (($user = db_fetch_object($users)) && count($links) < 10) {
+ $links[$user->uid] = l($user->name, 'devel/switch/'. $user->name, array('title' => t('Caution: this user will be unable to switch back.')), $dest);
+ }
}
}
- if ($links) {
- $block['content'] = theme('item_list', $links);
+ if (!empty($links)) {
+ $block['content'] .= theme('item_list', $links);
$block['content'] .= drupal_get_form('devel_switch_user_form');
}
break;