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};
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));
73 print start_div {-id => 'quickstats'};
81 print start_Tr {-align => 'right'};
83 td {-class => 'smalllabel',
87 td {-class => 'smallnumber',
89 $dates{$date}{'processed'};
91 td {-class => 'smallnumber',
97 print start_Tr {-align => 'right'};
100 my $value = $dates{$date}{$_};
103 if ($_ eq 'mailloop' || $_ eq 'registered') {
106 $percent = $dates{$date}{processed} == 0 ?
107 0 : $dates{$date}{$_} / $dates{$date}{processed} * 100;
108 $percent = sprintf '%5.1f%s', $percent, '%';
111 my $report = ucfirst $_;
113 $report = a {-href => "detail.cgi?type=$_;date=$date"}, $report if $value;
115 print td {-class => 'link'}, $report,
116 td {-class => 'smallnumber'}, $value,
117 td {-class => 'smallnumber'}, $percent;
127 } # displayquickstats
130 my ($table_name) = @_;
132 # General footing (copyright). Note we calculate the current year
133 # so that the copyright automatically extends itself.
134 my $year = substr((scalar (localtime)), 20, 4);
136 print start_div {-class => "copyright"};
137 print "Copyright © 2001-$year - All rights reserved";
139 a ({-href => 'https://defaria.com'},
141 a ({-href => 'mailto:Andrew@DeFaria.com'},
142 '<Andrew@DeFaria.com>'));
145 print end_div; # This div ends "content" which was started in Heading
146 print "<script language='JavaScript1.2'>AdjustTableWidth (\"$table_name\");</script>"
156 print br, font({ -class => 'error' }, 'DEBUG: '), $msg;
161 sub DisplayError($) {
175 # This subroutine puts out the header for web pages. It is called by
176 # various cgi scripts thus has a few parameters.
177 sub Heading($$$$;$$@) {
178 my ($action, # One of getcookie, setcookie, unsetcookie
179 $userid, # User id (if setting a cookie)
180 $title, # Title string
182 $h2, # H2 header (optional)
183 $table_name, # Name of table in page, if any
184 @scripts) = @_; # Array of JavaScript scripts to include
189 # Since CheckAddress appears on all pages (well except for the login
190 # page) include it by default along with MAPSUtils.js
191 push @java_scripts, [
192 {-language => 'JavaScript1.2',
193 -src => '/maps/JavaScript/MAPSUtils.js'},
194 {-language => 'JavaScript1.2',
195 -src => '/maps/JavaScript/CheckAddress.js'}
198 # Add on any additional JavaScripts that the caller wants. Note the
199 # odd single element array of hashes but that's what CGI requires!
200 # Build up scripts from array
202 push @{$java_scripts[0]},
203 {-language => 'JavaScript1.2',
204 -src => "/maps/JavaScript/$_"}
207 # Since Heading is called from various scripts we sometimes need to
208 # set a cookie, other times delete a cookie but most times return the
210 if ($action eq 'getcookie') {
211 # Get userid from cookie
212 $userid = cookie ('MAPSUser');
213 } elsif ($action eq 'setcookie') {
220 } elsif ($action eq 'unsetcookie') {
237 -author => 'Andrew\@DeFaria.com',
238 -style => {-src => '/maps/css/MAPSStyle.css'},
239 -onResize => "AdjustTableWidth (\"$table_name\");",
241 Link({-rel => 'icon',
242 -href => '/maps/MAPS.png',
243 -type => 'image/png'}),
244 Link({-rel => 'shortcut icon',
245 -href => '/maps/favicon.ico'})
247 -script => @java_scripts);
251 -author => 'Andrew\@DeFaria.com',
252 -style => {-src => '/maps/css/MAPSStyle.css'},
254 Link({-rel => 'icon',
255 -href => '/maps/MAPS.png',
256 -type => 'image/png'}),
257 Link({-rel => 'shortcut icon',
258 -href => '/maps/favicon.ico'})],
259 -script => @java_scripts);
262 print start_div {class => 'heading'};
265 -class => 'header'}, $h1;
267 if (defined $h2 && $h2 ne '') {
270 -class => 'header'}, $h2;
275 print start_div {-class => 'content'};
280 sub NavigationBar($) {
283 print start_div {-id => 'leftbar'};
286 print h2({-align => 'center'}, font({-color => 'white'}, "MAPS $MAPS::Version"));
287 print div ({-class => 'username'}, 'Welcome to MAPS');
288 print div ({-class => 'menu'},
289 (a {-href => '/maps/doc/'},
290 'What is MAPS?<br>'),
291 (a {-href => '/maps/doc/SPAM.html'},
292 'What is SPAM?<br>'),
293 (a {-href => '/maps/doc/Requirements.html'},
295 (a {-href => '/maps/SignupForm.html'},
297 (a {-href => '/maps/doc/Using.html'},
299 (a {-href => '/maps/doc/'},
303 print h2({-align => 'center'}, font({-color => 'white'}, "MAPS $MAPS::Version"));
304 print div ({-class => 'username'}, 'Welcome '. ucfirst $userid);
306 print div ({-class => 'menu'},
307 (a {-href => '/maps/'},
309 (a {-href => '/maps/bin/stats.cgi'},
311 (a {-href => '/maps/bin/editprofile.cgi'},
313 (a {-href => '/maps/php/Reports.php'},
315 (a {-href => '/maps/php/list.php?type=white'},
317 (a {-href => '/maps/php/list.php?type=black'},
319 (a {-href => '/maps/php/list.php?type=null'},
321 (a {-href => '/maps/doc/'},
323 (a {-href => '/maps/adm/'},
325 (a {-href => '/maps/?logout=yes'},
329 displayquickstats($userid);
331 print start_div {-class => 'search'};
332 print start_form {-method => 'get',
333 -action => '/maps/bin/search.cgi',
335 print 'Search Sender/Subject',
336 textfield {-class => 'searchfield',
337 -id => 'searchfield',
342 -onclick => "document.search.str.value = '';"};
346 print start_div {-class => 'search'};
347 print start_form {-method => 'post',
348 -action => 'javascript://',
350 -onsubmit => 'checkaddress(this);'};
351 print 'Check Email Address',
352 textfield {-class => 'searchfield',
353 -id => 'searchfield',
358 -onclick => "document.address.email.value = '';"};