function ad_report_admin_display in Advertisement 6.3
Same name and namespace in other branches
- 5.2 report/ad_report.module \ad_report_admin_display()
- 6.2 report/ad_report.module \ad_report_admin_display()
- 7 report/ad_report.module \ad_report_admin_display()
Display the administrative report.
1 string reference to 'ad_report_admin_display'
- ad_report_menu in report/
ad_report.module - Implementation of hook_menu().
File
- report/
ad_report.module, line 219 - Provides comprehensive charts and reports about advertising statistics.
Code
function ad_report_admin_display() {
$start = isset($_SESSION['ad_report_start']) ? $_SESSION['ad_report_start'] : 0;
$end = isset($_SESSION['ad_report_end']) ? $_SESSION['ad_report_end'] : 0;
$group = isset($_SESSION['ad_report_group']) ? $_SESSION['ad_report_group'] : array();
if (!$start && !$end) {
drupal_goto('admin/content/ad/report');
}
$ads = array();
$output .= ad_report_admin_ad_table(strtotime($start), strtotime($end), $group, FALSE, $ads);
$output .= '<div>' . l(t('Modify report'), 'admin/content/ad/report') . '</div>';
$start_time = strtotime($start);
$end_time = strtotime($end);
$elapse = $end_time - $start_time;
if (count($ads) && $start && $end && $elapse > 0 && $start > 0 && $end > 0) {
if ($elapse > 86400 * 100) {
// months
$segment = 2678400;
}
else {
if ($elapse > 86400 * 5) {
// days
$segment = 86400;
}
else {
// hours
$segment = 3600;
}
}
$max = 0;
$elements = round($elapse / $segment, 0);
$space = _ad_report_size($elements);
$s = $space;
for ($i = $start_time; $i < $end_time; $i += $segment) {
$start_date = _ad_report_format_date_db($i);
$end_date = _ad_report_format_date_db($i + $segment);
foreach ($ads as $aid) {
$ad = node_load($aid);
$imp = (int) db_result(db_query("SELECT SUM(count) FROM {ad_statistics} WHERE aid = %d AND action = 'view' AND date >= %d AND date <= %d", $aid, $start_date, $end_date));
if ($imp > $max) {
$max = $imp;
}
$title = isset($ad->title) ? $ad->title : "ad {$aid}";
$impressions[$title][] = $imp ? $imp : '0';
}
if ($s++ >= $space) {
if ($segment == 3600) {
$labels[] = date('M j ga', $i);
}
else {
$labels[] = date('M j', $i);
}
$s = 0;
}
else {
$labels[] = '';
}
}
$values = array();
$i = 0;
foreach ($ads as $aid) {
if (++$i > 5) {
// if we include too many ads, the URL is too long for the browser
drupal_set_message(t('Only plotting the first five ads on the graph.'));
break;
}
$ad = node_load($aid);
$title = isset($ad->title) ? $ad->title : "ad {$aid}";
$values[$title] = $impressions[$title];
}
if (!empty($values)) {
$values['#max'] = $max;
$values['#labels'] = $labels;
$values['#title'] = 'ad impressions';
}
$output .= ad_report_generate_bargraph($values);
}
return $output;
}