You are here

function referral_view in User Referral 6

Same name and namespace in other branches
  1. 5 referral.module \referral_view()
  2. 7 referral.module \referral_view()
1 string reference to 'referral_view'
referral_menu in ./referral.module

File

./referral.module, line 323

Code

function referral_view() {
  global $user;
  if (variable_get(REFERRAL_DISPLAY_MODE, 0)) {
    $output .= '<div class="referral_link">';
    $output .= t('Your referral link: ');
    $output .= url('referral/' . _referral_uid2ref($user->uid), array(
      'query' => NULL,
      'fragment' => NULL,
      'absolute' => TRUE,
    ));
    $output .= '</div>';
  }
  $header = array(
    array(
      'data' => t('User'),
      'field' => 'u.name',
    ),
    array(
      'data' => t('Roles'),
    ),
    array(
      'data' => t('Flag'),
      'field' => 'r.flag',
    ),
    array(
      'data' => t('Time'),
      'field' => 'r.created',
      'sort' => 'desc',
    ),
  );
  $sql = 'SELECT u.uid, u.name, r.created, r.flag
    FROM {referral} r INNER JOIN {users} u USING(uid)
    WHERE referral_uid = %d
    AND u.status = 1
    ORDER BY r.created DESC';
  $result = pager_query($sql, REFERRAL_PAGE_COUNT, 0, NULL, $user->uid);
  while ($data = db_fetch_object($result)) {
    $rows[] = array(
      array(
        'data' => l($data->name, "user/{$data->uid}"),
      ),
      array(
        'data' => implode(',', _referral_get_user_roles($data->uid)),
      ),
      array(
        'data' => $data->flag ? 'Yes' : 'No',
      ),
      array(
        'data' => format_date($data->created, 'custom', REFERRAL_DATE_FORMAT),
      ),
    );
  }
  if (!$rows) {
    $rows[] = array(
      array(
        'data' => t('No data.'),
        'colspan' => '4',
      ),
    );
  }
  $pager = theme('pager', NULL, REFERRAL_PAGE_COUNT, 0);
  if (!empty($pager)) {
    $rows[] = array(
      array(
        'data' => $pager,
        'colspan' => '4',
      ),
    );
  }
  $output .= theme('table', $header, $rows);
  return $output;
}