You are here

function download_count_view_page in Download Count 6

Same name and namespace in other branches
  1. 5 download_count.module \download_count_view_page()
  2. 6.2 includes/download_count.pages.inc \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 121
Download counter

Code

function download_count_view_page() {
  global $user;
  drupal_set_title(check_plain(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, u.nid, nt.name FROM {file_downloads} fd JOIN {files} f ON f.filepath = CONCAT('%s', fd.filename) JOIN {upload} u ON u.fid = f.fid JOIN {node} n ON n.nid = u.nid JOIN {node_type} nt ON nt.type = n.type" . tablesort_sql($header), $fileDirectoryPath);
  }
  else {
    $result = db_query("SELECT fd.filename, fd.count, fd.timestamp, u.nid, nt.name FROM {file_downloads} fd JOIN {files} f ON f.filepath = CONCAT('%s', fd.filename) JOIN {upload} u ON u.fid = f.fid JOIN {node} n ON n.nid = u.nid JOIN {node_type} nt ON nt.type = n.type WHERE n.uid = %d" . tablesort_sql($header), $fileDirectoryPath, $user->uid);
  }
  while ($file = db_fetch_object($result)) {
    $row = array();
    $row[] = check_plain($file->filename);
    $row[] = $file->count;
    $row[] = t('@time ago', array(
      '@time' => format_interval(time() - $file->timestamp),
    ));
    $row[] = l(t('view @type', array(
      '@type' => $file->name,
    )), 'node/' . $file->nid);
    $rows[] = $row;
  }
  if (empty($rows)) {
    $rows[] = array(
      array(
        'data' => t('No file attachment has been downloaded.'),
        'colspan' => '4',
      ),
    );
  }
  $output = check_markup(check_plain(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(check_plain(variable_get('download_counter_view_page_footer', '')), variable_get('download_counter_view_page_format', 0), false);
  return $output;
}