#!/bin/perl -w require "adtracklib.pl"; print "Content-type: text/html\n\n"; &ReadFormInput; if ($INPUT{'site'}) { &InitSiteVars($INPUT{'site'}); } else { print "You need to set the site variable."; exit; } #&Initialize; &GetDatesFromReportFileList; #Round 'em to midnight #$earliest = &RoundUpMidnight($earliest); #$latest = time(); # Don't recount existing $date.db files #if ($dates[$#dates]) {$earliest = @dates[$#dates] + 86400;} if ($#dates >= 14) {$selectedStartDate = $dates[$#dates - 14] } else {$selectedStartDate = shift @dates; } #$nextPeriod = $earliest; # #while ($nextPeriod < ($latest + 1)) { # &GetStats($nextPeriod); # &PrintReport($nextPeriod); # push(@dates, $nextPeriod); # $nextPeriod = $nextPeriod + 86400; #} print "\n View Income By Date \n

View Income By Date
site: $INPUT{'site'}


Produces stacked bar graphs for income for chosen date ranges. Please make sure that the starting date is *before* the ending date.

\n
\n

Choose the starting date:

\n


Choose the ending date:



"; exit; sub GetDatesFromReportFileList { # Get a list of reports in the reports directory. # They are named by date, and we get a list of dates opendir(DIR,"$reports_dir"); @files = grep(/\.db/, readdir(DIR)); closedir(DIR); for (@files) { ($mydate, $spew) = split(/\.db/); push(@dates, $mydate); } @dates = sort ByNumber @dates; } sub ByNumber{$a <=> $b; } sub PrintDateSelector { $first_value = shift @_; $first_option = &ConvertTimeToString($first_value); print "\n"; for (@_) { $my_option = &ConvertTimeToString($_); print "\n"; } } sub Initialize { $earliest = time(); $latest = time(); opendir(DIR,"$logs_dir") || ReturnCGIError (500, "get_income.cgi Initialize","Could not open directory $logs_dir"); @files = sort grep(/\.log/, readdir(DIR)); closedir(DIR); print "Opened log directory."; for $eachfile (@files) { print "eachfile is $eachfile\n"; ($ad_sponsor, $spew) = split(/\./,$eachfile,2); # Open the hit file if ( $ad_sponsor ) { open (LOGFILE, "$logs_dir/$eachfile") || ReturnCGIError (500, "get_income.cgi Initialize", "Could not open file $logs_dir/$eachfile"); @hits = ; # Read in all the hits close LOGFILE; foreach $hit (@hits) { chop $hit; $count = ($hit =~ tr/ //); if ($count == 3) { $my_referer = 0; $my_ip = 0; ($my_ip, $my_time, $my_referer, $my_ad) = split(/ /,$hit,4); $show_banners{$my_ad} = $ad_sponsor; if ($my_time < $earliest) {$earliest = $my_time;} if ($my_time > $latest) {$latest = $my_time;} } else {print "Bad hit: $hit \n";} } } } #Read display variables in foreach $advertiser (keys %show_banners) { print "$advertiser $show_banners{$advertiser}\n"; # &ReadDisplayVars($advertiser); # $display_vars{$advertiser} = "$cents:$show_banners{$advertiser}:$adjustment"; } } sub RoundUpMidnight { ($sec, $min, $hour, $day, $startmon, $year, $junk1, $junk2, $junk3) = localtime($_[0]); $day++; $sec = 0; $min = 0; $hour = 0; $midnightTime = &timelocal($sec, $min, $hour, $day, $startmon, $year, $junk1, $junk2, $junk3); return $midnightTime; } sub RoundDownMidnight { ($sec, $min, $hour, $day, $startmon, $year, $junk1, $junk2, $junk3) = localtime($_[0]); $day--; $sec = 0; $min = 0; $hour = 0; $midnightTime = &timelocal($sec, $min, $hour, $day, $startmon, $year, $junk1, $junk2, $junk3); return $midnightTime; } sub CountUniques { # make this take a starting and ending time param # "count uniques for this advertiser and sponsor from start to finish" $sponsor = $_[0]; $logname = "$logs_dir/$sponsor.log"; $advertiser = $_[1]; $startTime = $_[2]; $finishTime = $_[3]; $startTimeStr = &ConvertTimeToString($startTime); $finishTimeStr = &ConvertTimeToString($finishTime); $unique_count = 0; if (-e $logname) { open (UNIQUELOG, "<$logname") || die("Could not open file $logs_dir/$logname.log"); while () { chop; $count = ($_ =~ tr/ //); if ($count == 3) { $referer = 0; $ip_addr = 0; ($ip_addr, $ip_time_logged, $referer, $gotclick) = split(/ /,$_,4); if ($gotclick eq $advertiser){ if (($startTime < $ip_time_logged) && ($ip_time_logged < $finishTime)) { $unique_count++; } } } } close UNIQUELOG; } print "Counted $unique_count hits between $startTimeStr and $finishTimeStr for .$advertiser. sponsored by .$sponsor.\n"; return $unique_count; } sub GetStats { $now = $_[0]; $oneDayAgo = $now - 86400; foreach $advertiser (keys %show_banners) { $uniques{$advertiser} = &CountUniques($show_banners{$advertiser},$advertiser,$oneDayAgo,$now); #print "uniques{$advertiser} = $uniques{$advertiser}\n"; } } sub PrintReport { $reportname = "$reports_dir/$_[0].db"; $timestring = &ConvertStringToTime($_[0]); print "\nprinting report for $timestring\n"; if (open (OUTFILE, ">$reportname")) { foreach $advertiser (sort(keys %show_banners)) { #print "$advertiser:$display_vars{$advertiser}:$uniques{$advertiser}:$prev_in{$advertiser}:$wk_in{$advertiser}:$lstwk_in{$advertiser}\n"; print "$advertiser:$display_vars{$advertiser}:$uniques{$advertiser}\n"; #print OUTFILE "$advertiser:$display_vars{$advertiser}:$uniques{$advertiser}:$prev_in{$advertiser}:$wk_in{$advertiser}:$lstwk_in{$advertiser}\n"; print OUTFILE "$advertiser:$display_vars{$advertiser}:$uniques{$advertiser}\n"; } close OUTFILE; } }