#!/bin/perl -w require "adtracklib.pl"; # a good array of pretty distinct colors, # each associated with an advertiser @color_assign = ( "#FFFF00","#CCFF00","#99FF00","#66FF00","#33FF00", "#00FF00","#00FF33","#00FF66","#00FF99","#00FFCC", "#00FFFF","#00CCFF","#0099FF","#0066FF","#0033FF", "#0000FF","#3300FF","#6600FF","#9900FF","#CC00FF", "#FF00FF","#FF00CC","#FF0099","#FF0066","#FF0033", "#FF0000","#FF3300","#FF6600","#FF9900","#FFCC00"); $next_color = 0; $background_color = "#FFFFFF"; print "Content-type: text/html\n\n"; &ReadFormInput; if (! $INPUT{'date'}) { print "Access this utility through get_income.cgi"; exit;} $start_date = $INPUT{'date'}; $str_start_date = &ConvertTimeToString($start_date); $site = $INPUT{'site'}; &InitSiteVars($site); print "\n View Hits and Income for $site on $str_start_date \n

Hits and Income

Site: $site
Date: $str_start_date
"; #figure out how many records are in the directory &read_date_file($start_date); &print_table($start_date); print ""; exit; sub print_table { $my_date = $_[0]; $my_date_string = &ConvertTimeToString($this_date); $str_income = sprintf('%3.2f',$total_income{$my_date}); print "$my_date_string $str_income"; print ""; print "\n"; print ""; print ""; print ""; print ""; print ""; print ""; print "\n"; @adsort = (sort {$income{$a} <=> $income{$b}} keys %income); foreach $advertiser (@adsort) { print "\n"; print " "; print ""; print ""; print ""; print ""; print ""; print "\n"; } print "
AdvertiserIncome Hits Cents Adjust. Sponsor
$advertiser$income{$advertiser}$hits{$advertiser}$cents{$advertiser}$adjustment{$advertiser}$sponsor{$advertiser}
"; } sub read_date_file { # takes a date # sets up the "income" associative array # sets up advertiser colors as necessary $this_date = $_[0]; if (open INFILE, "$reports_dir/$this_date.db"){ while () { ($advertiser,$cents,$sponsor,$adjustment,$hits) = split(/:/,$_,5); #if it's a new advertiser without an assigned color, #assign a new color to it, otherwise use the colors #we have already set. if (! grep(/$advertiser/, keys( %color))) { #print "new advertiser! $advertiser $next_color $color_assign[$next_color]\n"; $color{$advertiser} = $color_assign[$next_color]; $next_color = $next_color + 1; } $income{$advertiser} = (($cents - $adjustment) * $hits); $hits{$advertiser} = $hits; $sponsor{$advertiser} = $sponsor; $cents{$advertiser} = $cents; $adjustment{$advertiser} = $adjustment; $total_income{$this_date} = $total_income{$this_date} + $income{$advertiser}; } } close INFILE; }