You are here

function download_count_view_page in Download Count 5

Same name and namespace in other branches
  1. 6.2 includes/download_count.pages.inc \download_count_view_page()
  2. 6 download_count.module \download_count_view_page()
  3. 7.3 includes/download_count.pages.inc \download_count_view_page()
  4. 7.2 includes/download_count.pages.inc \download_count_view_page()
1 string reference to 'download_count_view_page'
download_count_menu in ./download_count.module
Implementation of hook_menu()

File

./download_count.module, line 135
Download counter

Code

function download_count_view_page() {
  global $user;
  drupal_set_title(variable_get('download_counter_view_page_title', t('Download counter')));
  $header[] = array(
    'data' => t('filename'),
    'field' => 'filename',
  );
  $header[] = array(
    'data' => t('hits'),
    'field' => 'count',
    'sort' => 'desc',
  );
  $header[] = array(
    'data' => t('last download'),
    'field' => 'timestamp',
  );
  $header[] = array(
    'data' => t('action'),
  );
  $rows = array();
  $fileDirectoryPath = file_directory_path() . '/';
  if (user_access('view all downloads count')) {
    $result = db_query("SELECT fd.filename, fd.count, fd.timestamp, f.nid, n.type FROM {file_downloads} fd JOIN {files} f ON f.filepath = CONCAT('%s', fd.filename) JOIN {node} n ON n.nid = f.nid" . tablesort_sql($header), $fileDirectoryPath);
  }
  else {
    $result = db_query("SELECT fd.filename, fd.count, fd.timestamp, f.nid, n.type FROM {file_downloads} fd JOIN {files} f ON f.filepath = CONCAT('%s', fd.filename) JOIN {node} n ON n.nid = f.nid WHERE n.uid = %d" . tablesort_sql($header), $fileDirectoryPath, $user->uid);
  }
  while ($file = db_fetch_object($result)) {
    $row = array();
    $row[] = $file->filename;
    $row[] = $file->count;
    $row[] = format_interval(time() - $file->timestamp) . ' ago';
    $row[] = l(t('view ' . $file->type), 'node/' . $file->nid);
    $rows[] = $row;
  }
  if (empty($rows)) {
    $rows[] = array(
      array(
        'data' => t('No file attachment has been downloaded.'),
        'colspan' => '4',
      ),
    );
  }
  $output = check_markup(variable_get('download_counter_view_page_header', ''), variable_get('download_counter_view_page_format', 0), false);
  $output .= theme('table', $header, $rows, array(
    'class' => 'download_count',
  ));
  $output .= check_markup(variable_get('download_counter_view_page_footer', ''), variable_get('download_counter_view_page_format', 0), false);
  return $output;
}