You are here

function uc_file_user_downloads in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_file/uc_file.module \uc_file_user_downloads()
  2. 7.3 uc_file/uc_file.pages.inc \uc_file_user_downloads()

Table builder for user downloads.

1 string reference to 'uc_file_user_downloads'
uc_file_menu in uc_file/uc_file.module
Implements hook_menu().

File

uc_file/uc_file.pages.inc, line 68
File menu items.

Code

function uc_file_user_downloads($account) {

  // Create a header and the pager it belongs to.
  $header = array(
    array(
      'data' => t('Purchased'),
      'field' => 'u.granted',
      'sort' => 'desc',
    ),
    array(
      'data' => t('Filename'),
      'field' => 'f.filename',
    ),
    array(
      'data' => t('Description'),
      'field' => 'p.description',
    ),
    array(
      'data' => t('Downloads'),
      'field' => 'u.accessed',
    ),
    array(
      'data' => t('Addresses'),
    ),
  );
  drupal_set_title(t('File downloads'));
  $files = array();
  $result = pager_query("SELECT u.granted, f.filename, u.accessed, u.addresses, p.description, u.file_key, f.fid, u.download_limit, u.address_limit, u.expiration FROM {uc_file_users} as u " . "LEFT JOIN {uc_files} as f ON u.fid = f.fid " . "LEFT JOIN {uc_file_products} as p ON p.pfid = u.pfid WHERE uid = %d" . tablesort_sql($header), UC_FILE_PAGER_SIZE, 0, "SELECT COUNT(*) FROM {uc_file_users} WHERE uid = %d", $account->uid);
  $row = 0;
  while ($file = db_fetch_object($result)) {
    $download_limit = $file->download_limit;

    // Set the JS behavior when this link gets clicked.
    $onclick = array(
      'attributes' => array(
        'onclick' => 'uc_file_update_download(' . $row . ', ' . $file->accessed . ', ' . (empty($download_limit) ? -1 : $download_limit) . ');',
        'id' => 'link-' . $row,
      ),
    );

    // Expiration set to 'never'
    if ($file->expiration == FALSE) {
      $file_link = l(basename($file->filename), 'download/' . $file->fid . '/' . $file->file_key, $onclick);
    }
    elseif (time() > $file->expiration) {
      $file_link = basename($file->filename);
    }
    else {
      $file_link = l(basename($file->filename), 'download/' . $file->fid . '/' . $file->file_key, $onclick) . ' (' . t('expires on @date', array(
        '@date' => format_date($file->expiration, 'custom', variable_get('uc_date_format_default', 'm/d/Y')),
      )) . ')';
    }
    $files[] = array(
      'granted' => $file->granted,
      'link' => $file_link,
      'description' => $file->description,
      'accessed' => $file->accessed,
      'download_limit' => $file->download_limit,
      'addresses' => $file->addresses,
      'address_limit' => $file->address_limit,
    );
    $row++;
  }
  $output = theme('uc_file_user_downloads', $header, $files);
  if (user_access('administer users')) {
    $output .= drupal_get_form('uc_file_user_form', $account);
  }
  return $output;
}