You are here

function ad_click_history in Advertisement 5.2

Display click history for advertisemet, if user has necessary permission.

1 call to ad_click_history()
theme_node_ad in ./ad.module

File

./ad.module, line 969
An advertising system for Drupal powered websites.

Code

function ad_click_history($aid) {
  $output = '';
  if (ad_permission($aid, 'access click history')) {
    $header = array(
      array(
        'data' => t('Time'),
        'field' => 'timestamp',
        'sort' => 'desc',
      ),
      array(
        'data' => t('IP address'),
        'field' => 'hostname',
      ),
      array(
        'data' => t('URL where clicked'),
        'field' => 'url',
      ),
    );
    if (function_exists('click_filter_status_text') && user_access('view filtered clicks')) {
      $header[] = array(
        'data' => t('Status'),
        'field' => 'status',
      );
    }
    $header[] = array(
      'data' => t(' '),
    );
    if ($aid) {
      $sql = "SELECT cid, timestamp, uid, status, hostname, url FROM {ad_clicks} WHERE aid = {$aid}";
      $sql .= tablesort_sql($header);
      $result = pager_query($sql, 25);
      while ($ad = db_fetch_object($result)) {
        if (module_exists('click_filter') && $ad->status != CLICK_VALID) {

          // Only show filtered clicks to users with permission to view them.
          if (!user_access('view filtered clicks')) {
            continue;
          }
        }
        if (strlen($ad->url) > 40) {
          $url = substr($ad->url, 0, 37) . '...';
        }
        else {
          $url = $ad->url;
        }
        $row = array();
        $click_user = user_load(array(
          'uid' => $ad->uid,
        ));
        $row[] = format_date($ad->timestamp, 'custom', 'M j H:i');
        $row[] = $ad->hostname;
        $row[] = l($url, $ad->url);
        if (function_exists('click_filter_status_text') && user_access('view filtered clicks')) {
          $row[] = click_filter_status_text($ad->status);
        }
        $row[] = '[' . l('details', "node/{$aid}/details/{$ad->cid}") . ']';
        $rows[] = $row;
      }
      $click_history = theme('table', $header, $rows);
      $click_history .= theme('pager', NULL, 25, 0);
      $output .= theme('box', t('Click history'), $click_history);
    }
  }
  return $output;
}