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 ################################################################################
20 use lib $FindBin::Bin;
26 use CGI qw (:standard *table start_Tr end_Tr start_div end_div);
27 use vars qw (@ISA @EXPORT);
44 my %dates = GetStats (1, $date);
46 foreach (@MAPSLog::Types) {
47 $dates{$date}{processed} += $dates{$date}{$_};
53 sub displayquickstats {
54 # Quick stats are today only.
55 my $today = Today2SQLDatetime;
56 my $time = substr $today, 11;
57 my $date = substr $today, 0, 10;
58 my %dates = getquickstats $date;
60 print start_div {-class => 'quickstats'};
61 print h4 {-class => 'header',
64 print p {-align => 'center'},
65 b ('as of ' . FormatTime ($time));
71 print start_Tr {-align => 'right'};
73 td {-class => 'smalllabel',
77 td {-class => 'smallnumber',
79 $dates{$date}{'processed'};
81 td {-class => 'smallnumber',
86 foreach (@MAPSLog::Types) {
87 print start_Tr {-align => 'right'};
89 my $value = $dates{$date}{$_};
91 if ($_ eq 'mailloop' || $_ eq 'registered') {
94 $percent = $dates{$date}{processed} == 0 ?
95 0 : $dates{$date}{$_} / $dates{$date}{processed} * 100;
96 $percent = sprintf '%5.1f%s', $percent, '%';
98 my $stat = $value == 0 ?
99 0 : a {-href => "detail.cgi?type=$_;date=$date"}, $value;
101 td {-class => 'smalllabel'}, ucfirst ($_);
103 td {-class => 'smallnumber'}, $stat;
105 td {-class => 'smallnumber'}, $percent;
110 } # displayquickstats
113 my ($table_name) = @_;
115 # General footing (copyright). Note we calculate the current year
116 # so that the copyright automatically extends itself.
117 my $year = substr ((scalar (localtime)), 20, 4);
119 print start_div {-class => "copyright"};
120 print "Copyright © 2001-$year - All rights reserved";
122 a ({-href => 'http://defaria.com'},
124 a ({-href => 'mailto:Andrew@DeFaria.com'},
125 '<Andrew@DeFaria.com>'));
128 print end_div; # This div ends "content" which was started in Heading
129 print "<script language='JavaScript1.2'>AdjustTableWidth (\"$table_name\");</script>"
137 print br, font ({ -class => 'error' }, 'DEBUG: '), $msg;
140 sub DisplayError ($) {
143 print h3 ({-class => 'error',
144 -align => 'center'}, 'ERROR: ' . $errmsg);
151 # This subroutine puts out the header for web pages. It is called by
152 # various cgi scripts thus has a few parameters.
153 sub Heading ($$$$;$$@) {
154 my ($action, # One of getcookie, setcookie, unsetcookie
155 $userid, # User id (if setting a cookie)
156 $title, # Title string
158 $h2, # H2 header (optional)
159 $table_name, # Name of table in page, if any
160 @scripts) = @_; # Array of JavaScript scripts to include
165 # Since CheckAddress appears on all pages (well except for the login
166 # page) include it by default along with MAPSUtils.js
167 push @java_scripts, [
168 {-language => 'JavaScript1.2',
169 -src => '/maps/JavaScript/MAPSUtils.js'},
170 {-language => 'JavaScript1.2',
171 -src => '/maps/JavaScript/CheckAddress.js'}
174 # Add on any additional JavaScripts that the caller wants. Note the
175 # odd single element array of hashes but that's what CGI requires!
176 # Build up scripts from array
178 push @{$java_scripts[0]},
179 {-language => 'JavaScript1.2',
180 -src => "/maps/JavaScript/$_"}
183 # Since Heading is called from various scripts we sometimes need to
184 # set a cookie, other times delete a cookie but most times return the
186 if ($action eq 'getcookie') {
187 # Get userid from cookie
188 $userid = cookie ('MAPSUser');
189 } elsif ($action eq 'setcookie') {
196 } elsif ($action eq 'unsetcookie') {
206 header (-title => "MAPS: $title",
209 if (defined $table_name) {
211 start_html (-title => "MAPS: $title",
212 -author => 'Andrew\@DeFaria.com',
213 -style => {-src => '/maps/css/MAPSStyle.css'},
214 -onResize => "AdjustTableWidth (\"$table_name\");",
216 Link ({-rel => 'icon',
217 -href => '/maps/MAPS.png',
218 -type => 'image/png'}),
219 Link ({-rel => 'shortcut icon',
220 -href => '/maps/favicon.ico'})
222 -script => @java_scripts);
225 start_html (-title => "MAPS: $title",
226 -author => 'Andrew\@DeFaria.com',
227 -style => {-src => '/maps/css/MAPSStyle.css'},
229 Link ({-rel => 'icon',
230 -href => '/maps/MAPS.png',
231 -type => 'image/png'}),
232 Link ({-rel => 'shortcut icon',
233 -href => '/maps/favicon.ico'})],
234 -script => @java_scripts);
237 print start_div {class => 'heading'};
238 print h2 {-align => 'center',
240 font ({-class => 'standout'}, 'MAPS'),
243 if (defined $h2 && $h2 ne '') {
244 print h3 {-align => 'center',
251 print start_div {-class => 'content'};
259 print start_div {-id => 'leftbar'};
261 if (!defined $userid) {
262 print div ({-class => 'username'}, 'Welcome to MAPS');
263 print div ({-class => 'menu'},
264 (a {-href => '/maps/doc/'},
265 'What is MAPS?<br>'),
266 (a {-href => '/maps/doc/SPAM.html'},
267 'What is SPAM?<br>'),
268 (a {-href => '/maps/doc/Requirements.html'},
270 (a {-href => '/maps/SignupForm.html'},
272 (a {-href => '/maps/doc/Using.html'},
274 (a {-href => '/maps/doc/'},
278 print div ({-class => 'username'}, 'Welcome '. ucfirst $userid);
279 print div ({-class => 'menu'},
280 (a {-href => '/maps/'},
282 (a {-href => '/maps/bin/stats.cgi'},
284 (a {-href => '/maps/bin/editprofile.cgi'},
286 (a {-href => '/maps/php/Reports.php'},
288 (a {-href => '/maps/php/list.php?type=white'},
290 (a {-href => '/maps/php/list.php?type=black'},
292 (a {-href => '/maps/php/list.php?type=null'},
294 (a {-href => '/maps/doc/'},
296 (a {-href => '/maps/adm/'},
298 (a {-href => '/maps/?logout=yes'},
301 print start_div {-class => 'search'};
302 print start_form {-method => 'get',
303 -action => '/maps/bin/search.cgi',
305 print 'Search Sender/Subject',
306 textfield {-class => 'searchfield',
307 -id => 'searchfield',
312 -onclick => "document.search.str.value = '';"};
318 print start_div {-class => 'search'};
319 print start_form {-method => 'post',
320 -action => 'javascript://',
322 -onsubmit => 'checkaddress(this);'};
323 print 'Check Email Address',
324 textfield {-class => 'searchfield',
325 -id => 'searchfield',
330 -onclick => "document.address.email.value = '';"};