You are here

function uc_roles_user_view in Ubercart 6.2

Same name and namespace in other branches
  1. 7.3 uc_roles/uc_roles.module \uc_roles_user_view()

Implements hook_user_view().

Displays role expirations on the user account screen.

1 call to uc_roles_user_view()
uc_roles_user in uc_roles/uc_roles.module
Implements hook_user().

File

uc_roles/uc_roles.module, line 444

Code

function uc_roles_user_view(&$edit, &$account) {
  global $user;

  // Kick out anonymous.
  if (!$user->uid) {
    return;
  }

  // Only show if this user can access all role expirations, or if it's the same
  // user and the expirations are showing on the user pages.
  $show_expiration = variable_get('uc_roles_default_show_expiration', TRUE);
  if (!user_access('view all role expirations') && ($user->uid != $account->uid || !$show_expiration)) {
    return;
  }
  $items = array();
  $form = array();
  $expirations = db_query("SELECT * FROM {uc_roles_expirations} WHERE uid = %d", $account->uid);
  while ($expiration = db_fetch_object($expirations)) {
    $substitution = array(
      '!role_name' => check_plain(_uc_roles_get_name($expiration->rid)),
      '!date' => format_date($expiration->expiration, 'small'),
    );
    $form[$expiration->rid] = array(
      '#type' => 'user_profile_item',
      '#title' => strtr(variable_get('uc_roles_default_expiration_title', uc_get_message('uc_roles_user_expiration_title')), $substitution),
      '#value' => strtr(variable_get('uc_roles_default_expiration_message', uc_get_message('uc_roles_user_expiration_message')), $substitution),
    );
  }

  // Don't display anything if there isn't any expirations.
  if (!count($form)) {
    return;
  }
  $item = array(
    '#type' => 'user_profile_category',
    '#weight' => '-1',
    '#title' => variable_get('uc_roles_default_expiration_header', uc_get_message('uc_roles_user_expiration_header')),
  );
  $account->content['uc_roles'] = $item + $form;
}