#!/usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use Fcntl qw(:flock :seek);
use strict;

print header;
print start_html("Ad Counts");
print qq(<h2 align="CENTER">Ad Counts</h2>);

print qq(<table border=0 width=100%>
<tr>
    <th align="LEFT">ID</th>
    <th align="LEFT">Ad</th>
    <th align="LEFT">Max</th>
    <th align="LEFT">Hits</th>
</tr>\n);

open(F,"addata.txt") or &dienice("Can't open data file: $!");
flock(F,LOCK_SH);      # shared lock
seek(F,0,SEEK_SET);    # rewind to beginning of file
while (my $line = <F>) {
    chomp($line);
    my($id,$img,$url,$alt,$max,$count) = split(/\|/,$line);
    print qq(<tr>
        <td>$id</td> <td>$alt (<a href="$url">$url</a>)</td>
        <td>$max</td> <td>$count</td> </tr>\n);
}
print qq(</table>\n);

print end_html;