_logged_in_data()); break; } return $block; } /** * Get the extra form elements for the block. * * @param * $delta - integer for the block number. * * @return * array containing the extra form elements for the block. */ function _logged_in_block_configure($delta) { drupal_add_css(drupal_get_path('module', 'logged_in') .'/logged_in.css'); $form = array(); $yesno = array(1 => t('Yes'), 0 => t('No')); switch ($delta) { case 0: $form['logged_in'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => FALSE, '#title' => t('Logged In Display'), '#description' => t('Select the options for the display.'), '#prefix' => '
', '#suffix' => '
', ); $form['logged_in']['show_roles'] = array( '#type' => 'radios', '#options' => $yesno, '#title' => t('Show user roles'), '#default_value' => (int) variable_get('logged_in_show_roles', 0), '#suffix' => '
', ); $form['logged_in']['show_perms'] = array( '#type' => 'radios', '#options' => $yesno, '#title' => t('Show permissions'), '#description' => t('This can be a very lengthy list.'), '#default_value' => (int) variable_get('logged_in_show_perms', 0), ); break; } return $form; } /** * Process the extra form values for the block. * * @param * $delta - integer for the block number. * @param * $edit - entered form values. */ function _logged_in_block_save($delta, $edit) { switch ($delta) { case 0: variable_set('logged_in_show_roles', $edit['show_roles']); variable_set('logged_in_show_perms', $edit['show_perms']); break; } } function _logged_in_data() { global $user; $output = NULL; $show_roles = variable_get('logged_in_show_roles', 0); $show_perms = variable_get('logged_in_show_perms', 0); if ($user->uid) { $output .= t('You are logged in as !username (@userid).', array('!username' => theme('username', $user), '@userid' => $user->uid) ); } else { $output .= t('You are not logged in.'); } if ($show_roles) { if ($user->uid == 1) { $roles = t('super-user'); } else { $roles = implode(', ', $user->roles); } $output .= '
'. t('Your roles: ') . $roles; } if (!$show_perms) { return $output; } if ($uid == 1) { $perms = array('all'); } else { $result = db_query("SELECT p.perm FROM {role} r INNER JOIN {permission} p ON p.rid = r.rid WHERE r.rid IN (". db_placeholders($user->roles) .")", array_keys($user->roles)); $perms = array(); while ($row = db_fetch_object($result)) { $perms += explode(', ', $row->perm); } } $perms = array_unique($perms); asort($perms); $class = count($perms) > 25 ? 'logged-in-xsmall' : 'logged-in-small'; $output .= '
'. t('Your permissions: ') ."
". implode(', ', $perms) .'
'; return $output; }