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}{$_};
97 if ($_ eq 'mailloop' || $_ eq 'registered') {
100 $percent = $dates{$date}{processed} == 0 ?
101 0 : $dates{$date}{$_} / $dates{$date}{processed} * 100;
102 $percent = sprintf '%5.1f%s', $percent, '%';
104 my $stat = $value == 0 ?
105 0 : a {-href => "detail.cgi?type=$_;date=$date"}, $value;
107 td {-class => 'smalllabel'}, ucfirst ($_);
109 td {-class => 'smallnumber'}, $stat;
111 td {-class => 'smallnumber'}, $percent;
118 } # displayquickstats
121 my ($table_name) = @_;
123 # General footing (copyright). Note we calculate the current year
124 # so that the copyright automatically extends itself.
125 my $year = substr((scalar (localtime)), 20, 4);
127 print start_div {-class => "copyright"};
128 print "Copyright © 2001-$year - All rights reserved";
130 a ({-href => 'https://defaria.com'},
132 a ({-href => 'mailto:Andrew@DeFaria.com'},
133 '<Andrew@DeFaria.com>'));
136 print end_div; # This div ends "content" which was started in Heading
137 print "<script language='JavaScript1.2'>AdjustTableWidth (\"$table_name\");</script>"
147 print br, font({ -class => 'error' }, 'DEBUG: '), $msg;
152 sub DisplayError($) {
166 # This subroutine puts out the header for web pages. It is called by
167 # various cgi scripts thus has a few parameters.
168 sub Heading($$$$;$$@) {
169 my ($action, # One of getcookie, setcookie, unsetcookie
170 $userid, # User id (if setting a cookie)
171 $title, # Title string
173 $h2, # H2 header (optional)
174 $table_name, # Name of table in page, if any
175 @scripts) = @_; # Array of JavaScript scripts to include
180 # Since CheckAddress appears on all pages (well except for the login
181 # page) include it by default along with MAPSUtils.js
182 push @java_scripts, [
183 {-language => 'JavaScript1.2',
184 -src => '/maps/JavaScript/MAPSUtils.js'},
185 {-language => 'JavaScript1.2',
186 -src => '/maps/JavaScript/CheckAddress.js'}
189 # Add on any additional JavaScripts that the caller wants. Note the
190 # odd single element array of hashes but that's what CGI requires!
191 # Build up scripts from array
193 push @{$java_scripts[0]},
194 {-language => 'JavaScript1.2',
195 -src => "/maps/JavaScript/$_"}
198 # Since Heading is called from various scripts we sometimes need to
199 # set a cookie, other times delete a cookie but most times return the
201 if ($action eq 'getcookie') {
202 # Get userid from cookie
203 $userid = cookie ('MAPSUser');
204 } elsif ($action eq 'setcookie') {
211 } elsif ($action eq 'unsetcookie') {
228 -author => 'Andrew\@DeFaria.com',
229 -style => {-src => '/maps/css/MAPSStyle.css'},
230 -onResize => "AdjustTableWidth (\"$table_name\");",
232 Link({-rel => 'icon',
233 -href => '/maps/MAPS.png',
234 -type => 'image/png'}),
235 Link({-rel => 'shortcut icon',
236 -href => '/maps/favicon.ico'})
238 -script => @java_scripts);
242 -author => 'Andrew\@DeFaria.com',
243 -style => {-src => '/maps/css/MAPSStyle.css'},
245 Link({-rel => 'icon',
246 -href => '/maps/MAPS.png',
247 -type => 'image/png'}),
248 Link({-rel => 'shortcut icon',
249 -href => '/maps/favicon.ico'})],
250 -script => @java_scripts);
253 print start_div {class => 'heading'};
256 -class => 'header'}, $h1;
258 if (defined $h2 && $h2 ne '') {
261 -class => 'header'}, $h2;
266 print start_div {-class => 'content'};
271 sub NavigationBar($) {
274 print start_div {-id => 'leftbar'};
277 print h2({-align => 'center'}, font({-color => 'white'}, "MAPS $MAPS::Version"));
278 print div ({-class => 'username'}, 'Welcome to MAPS');
279 print div ({-class => 'menu'},
280 (a {-href => '/maps/doc/'},
281 'What is MAPS?<br>'),
282 (a {-href => '/maps/doc/SPAM.html'},
283 'What is SPAM?<br>'),
284 (a {-href => '/maps/doc/Requirements.html'},
286 (a {-href => '/maps/SignupForm.html'},
288 (a {-href => '/maps/doc/Using.html'},
290 (a {-href => '/maps/doc/'},
294 print h2({-align => 'center'}, font({-color => 'white'}, "MAPS $MAPS::Version"));
295 print div ({-class => 'username'}, 'Welcome '. ucfirst $userid);
297 print div ({-class => 'menu'},
298 (a {-href => '/maps/'},
300 (a {-href => '/maps/bin/stats.cgi'},
302 (a {-href => '/maps/bin/editprofile.cgi'},
304 (a {-href => '/maps/php/Reports.php'},
306 (a {-href => '/maps/php/list.php?type=white'},
308 (a {-href => '/maps/php/list.php?type=black'},
310 (a {-href => '/maps/php/list.php?type=null'},
312 (a {-href => '/maps/doc/'},
314 (a {-href => '/maps/adm/'},
316 (a {-href => '/maps/?logout=yes'},
320 displayquickstats($userid);
322 print start_div {-class => 'search'};
323 print start_form {-method => 'get',
324 -action => '/maps/bin/search.cgi',
326 print 'Search Sender/Subject',
327 textfield {-class => 'searchfield',
328 -id => 'searchfield',
333 -onclick => "document.search.str.value = '';"};
337 print start_div {-class => 'search'};
338 print start_form {-method => 'post',
339 -action => 'javascript://',
341 -onsubmit => 'checkaddress(this);'};
342 print 'Check Email Address',
343 textfield {-class => 'searchfield',
344 -id => 'searchfield',
349 -onclick => "document.address.email.value = '';"};