1 #################################################################################
3 # File: $RCSfile: MAPSWeb.pm,v $
4 # Revision: $Revision: 1.1 $
5 # Description: Routines for generating portions of MAPSWeb
6 # Author: Andrew@DeFaria.com
7 # Created: Fri Nov 29 14:17:21 2002
8 # Modified: $Date: 2013/06/12 14:05:47 $
11 # (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
13 ################################################################################
19 use base qw(Exporter);
26 use CGI qw(:standard *table start_Tr end_Tr start_div end_div);
36 sub getquickstats(%) {
40 userid => $params{userid},
42 date => $params{date},
45 my $date = $params{date};
47 for (@MAPSLog::Types) {
48 $dates{$date}{processed} += $dates{$date}{$_};
54 sub displayquickstats($) {
57 # Quick stats are today only
58 my $today = Today2SQLDatetime;
59 my $time = substr $today, 11;
60 my $date = substr $today, 0, 10;
61 my %dates = getquickstats(
66 print start_div {-class => 'quickstats'};
67 print h4 {-class => 'todaysactivity',
70 print p {-align => 'center'},
71 b ('as of ' . FormatTime($time));
77 print start_Tr {-align => 'right'};
79 td {-class => 'smalllabel',
83 td {-class => 'smallnumber',
85 $dates{$date}{'processed'};
87 td {-class => 'smallnumber',
92 for (@MAPSLog::Types) {
93 print start_Tr {-align => 'right'};
95 my $value = $dates{$date}{$_};
98 if ($_ eq 'mailloop' || $_ eq 'registered') {
101 $percent = $dates{$date}{processed} == 0 ?
102 0 : $dates{$date}{$_} / $dates{$date}{processed} * 100;
103 $percent = sprintf '%5.1f%s', $percent, '%';
106 my $report = ucfirst $_;
109 $report = a {-href => "detail.cgi?type=$_;date=$date"}, $report;
110 $value = a {-href => "detail.cgi?type=$_;date=$date"}, $value;
111 $percent = a {-href => "detail.cgi?type=$_;date=$date"}, $percent;
114 print td {-class => 'smalllabel'}, $report,
115 td {-class => 'smallnumber'}, $value,
116 td {-class => 'smallnumber'}, $percent;
125 } # displayquickstats
128 my ($table_name) = @_;
130 # General footing (copyright). Note we calculate the current year
131 # so that the copyright automatically extends itself.
132 my $year = substr((scalar (localtime)), 20, 4);
134 print start_div {-class => "copyright"};
135 print "Copyright © 2001-$year - All rights reserved";
137 a ({-href => 'https://defaria.com'},
139 a ({-href => 'mailto:Andrew@DeFaria.com'},
140 '<Andrew@DeFaria.com>'));
143 print end_div; # This div ends "content" which was started in Heading
144 print "<script language='JavaScript1.2'>AdjustTableWidth (\"$table_name\");</script>"
154 print br, font({ -class => 'error' }, 'DEBUG: '), $msg;
159 sub DisplayError($) {
173 # This subroutine puts out the header for web pages. It is called by
174 # various cgi scripts thus has a few parameters.
175 sub Heading($$$$;$$@) {
176 my ($action, # One of getcookie, setcookie, unsetcookie
177 $userid, # User id (if setting a cookie)
178 $title, # Title string
180 $h2, # H2 header (optional)
181 $table_name, # Name of table in page, if any
182 @scripts) = @_; # Array of JavaScript scripts to include
187 # Since CheckAddress appears on all pages (well except for the login
188 # page) include it by default along with MAPSUtils.js
189 push @java_scripts, [
190 {-language => 'JavaScript1.2',
191 -src => '/maps/JavaScript/MAPSUtils.js'},
192 {-language => 'JavaScript1.2',
193 -src => '/maps/JavaScript/CheckAddress.js'}
196 # Add on any additional JavaScripts that the caller wants. Note the
197 # odd single element array of hashes but that's what CGI requires!
198 # Build up scripts from array
200 push @{$java_scripts[0]},
201 {-language => 'JavaScript1.2',
202 -src => "/maps/JavaScript/$_"}
205 # Since Heading is called from various scripts we sometimes need to
206 # set a cookie, other times delete a cookie but most times return the
208 if ($action eq 'getcookie') {
209 # Get userid from cookie
210 $userid = cookie ('MAPSUser');
211 } elsif ($action eq 'setcookie') {
218 } elsif ($action eq 'unsetcookie') {
235 -author => 'Andrew\@DeFaria.com',
236 -style => {-src => '/maps/css/MAPSStyle.css'},
237 -onResize => "AdjustTableWidth (\"$table_name\");",
239 Link({-rel => 'icon',
240 -href => '/maps/MAPS.png',
241 -type => 'image/png'}),
242 Link({-rel => 'shortcut icon',
243 -href => '/maps/favicon.ico'})
245 -script => @java_scripts);
249 -author => 'Andrew\@DeFaria.com',
250 -style => {-src => '/maps/css/MAPSStyle.css'},
252 Link({-rel => 'icon',
253 -href => '/maps/MAPS.png',
254 -type => 'image/png'}),
255 Link({-rel => 'shortcut icon',
256 -href => '/maps/favicon.ico'})],
257 -script => @java_scripts);
260 print start_div {class => 'heading'};
263 -class => 'header'}, $h1;
265 if (defined $h2 && $h2 ne '') {
268 -class => 'header'}, $h2;
273 print start_div {-class => 'content'};
278 sub NavigationBar($) {
281 print start_div {-id => 'leftbar'};
284 print h2({-align => 'center'}, font({-color => 'white'}, "MAPS $MAPS::Version"));
285 print div ({-class => 'username'}, 'Welcome to MAPS');
286 print div ({-class => 'menu'},
287 (a {-href => '/maps/doc/'},
288 'What is MAPS?<br>'),
289 (a {-href => '/maps/doc/SPAM.html'},
290 'What is SPAM?<br>'),
291 (a {-href => '/maps/doc/Requirements.html'},
293 (a {-href => '/maps/SignupForm.html'},
295 (a {-href => '/maps/doc/Using.html'},
297 (a {-href => '/maps/doc/'},
301 print h2({-align => 'center'}, font({-color => 'white'}, "MAPS $MAPS::Version"));
302 print div ({-class => 'username'}, 'Welcome '. ucfirst $userid);
304 print div ({-class => 'menu'},
305 (a {-href => '/maps/'},
307 (a {-href => '/maps/bin/stats.cgi'},
309 (a {-href => '/maps/bin/editprofile.cgi'},
311 (a {-href => '/maps/php/Reports.php'},
313 (a {-href => '/maps/php/list.php?type=white'},
315 (a {-href => '/maps/php/list.php?type=black'},
317 (a {-href => '/maps/php/list.php?type=null'},
319 (a {-href => '/maps/doc/'},
321 (a {-href => '/maps/adm/'},
323 (a {-href => '/maps/?logout=yes'},
327 displayquickstats($userid);
329 print start_div {-class => 'search'};
330 print start_form {-method => 'get',
331 -action => '/maps/bin/search.cgi',
333 print 'Search Sender/Subject',
334 textfield {-class => 'searchfield',
335 -id => 'searchfield',
340 -onclick => "document.search.str.value = '';"};
344 print start_div {-class => 'search'};
345 print start_form {-method => 'post',
346 -action => 'javascript://',
348 -onsubmit => 'checkaddress(this);'};
349 print 'Check Email Address',
350 textfield {-class => 'searchfield',
351 -id => 'searchfield',
356 -onclick => "document.address.email.value = '';"};