You are here

function invite_admin_details in Invite 7.2

Same name and namespace in other branches
  1. 5.2 invite.module \invite_admin_details()
  2. 6.2 invite_admin.inc \invite_admin_details()

Return a list of invites by a user.

Parameters

$account: A user object.

1 string reference to 'invite_admin_details'
invite_menu in ./invite.module
Implements hook_menu().

File

./invite.admin.inc, line 316
Administration functions for invite module.

Code

function invite_admin_details($account) {
  $header = array(
    array(
      'data' => t('E-mail'),
      'field' => 'i.email',
      'sort' => 'asc',
    ),
    array(
      'data' => t('Username'),
      'field' => 'u.name',
    ),
    array(
      'data' => t('Created'),
      'field' => 'i.created',
    ),
    array(
      'data' => t('Expires'),
      'field' => 'i.expiry',
    ),
    array(
      'data' => t('Status'),
      'field' => 'i.canceled',
    ),
  );
  $result = db_select('invite', 'i')
    ->fields('i')
    ->extend('TableSort')
    ->extend('PagerDefault');
  $result
    ->leftJoin('users', 'u', 'u.uid = i.invitee AND u.uid <> 0');
  $result
    ->condition('i.uid', $account->uid);
  $output = '';
  if (isset($_GET['filter']) && $_GET['filter'] != '') {
    $result
      ->where("LOWER(u.name) LIKE CONCAT('%', LOWER(:name), '%')", array(
      ':name' => $_GET['filter'],
    ));
    $output .= render(drupal_get_form('invite_admin_details_filter_form', $account->uid, $_GET['filter']));
  }
  $result = $result
    ->orderByHeader($header)
    ->execute()
    ->fetchAll();
  if (isset($_GET['order']) && $_GET['order'] == t('Status')) {
    usort($result, 'invite_sort_by_status');
    if (isset($_GET['sort']) && $_GET['sort'] == 'desc') {
      $result = array_reverse($result);
    }
  }
  $rows = array();
  foreach ($result as $row) {
    $invitee = user_load($row->invitee);
    $cells = array();
    $cells[] = check_plain($row->email);
    $cells[] = $row->joined ? theme('username', array(
      'account' => $invitee,
    )) : '';
    $cells[] = format_date($row->created, 'short');
    $cells[] = format_date($row->expiry, 'short');
    $cells[] = $row->canceled ? t('Withdrawn') : ($row->joined ? t('Joined') : ($row->expiry < REQUEST_TIME ? t('Expired') : t('Pending')));
    $rows[] = $cells;
  }
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'id' => 'invite',
    ),
  ));
  if (!$rows) {
    $output .= t('No invitees found.');
  }
  else {
    $output .= theme('pager');
  }
  return $output;
}