Fixed VERSION
[clearscm.git] / maps / lib / MAPSWeb.pm
index 4f3afda..59ec10b 100644 (file)
 package MAPSWeb;
 
 use strict;
-#use warnings;
+use warnings;
 
-use MAPS;
-use MAPSLog;
-use MAPSUtil;
+use base qw(Exporter);
 
-use CGI qw (:standard *table start_Tr end_Tr start_div end_div);
-use vars qw (@ISA @EXPORT);
+use DateUtils;
 
-use Exporter;
+use MAPS;
+use MAPSLog;
 
-@ISA = qw (Exporter);
+use CGI qw(:standard *table start_Tr end_Tr start_div end_div);
 
-@EXPORT = qw (
-  Debug
+our @EXPORT = qw(
+  DebugWeb
   DisplayError
   Footing
   Heading
   NavigationBar
 );
 
-sub getquickstats($) {
-  my ($date) = @_;
+sub getquickstats(%) {
+  my (%params) = @_;
 
-  my %dates = GetStats (1, $date);
+  my %dates = GetStats(
+    userid => $params{userid},
+    days   => 1,
+    date   => $params{date},
+  );
 
-  for (@MAPSLog::Types) {
+  my $date = $params{date};
+
+  for (@Types) {
     $dates{$date}{processed} += $dates{$date}{$_};
   } # for
 
   return %dates;
 } # getquickstats
 
-sub displayquickstats() {
-  # Quick stats are today only.
+sub displayquickstats($) {
+  my ($userid) = @_;
+
+  # Quick stats are today only
   my $today = Today2SQLDatetime;
   my $time  = substr $today, 11;
   my $date  = substr $today, 0, 10;
-  my %dates = getquickstats $date;
+  my %dates = getquickstats(
+    userid => $userid,
+    date   => $date
+  );
 
   print start_div {-class => 'quickstats'};
-  print h4 {-class    => 'header',
+  print h4 {-class    => 'todaysactivity',
             -align    => 'center'},
     'Today\'s Activity';
   print p {-align     => 'center'},
-    b ('as of ' . FormatTime ($time));
+    b ('as of ' . FormatTime($time));
+
+  print start_div {-id => 'quickstats'};
+
   print start_table {
-    -align       => 'center',
-    -border      => 0,
     -cellspacing => 0,
-    -cellpadding => 2};
+    -border      => 0,
+    -align       => 'center',
+    -cellpadding => 2,
+  };
   print start_Tr {-align => 'right'};
   print
     td {-class => 'smalllabel',
@@ -80,11 +93,13 @@ sub displayquickstats() {
       'n/a';
   print end_Tr;
 
-  for (@MAPSLog::Types) {
+  for (@Types) {
     print start_Tr {-align => 'right'};
 
+    my $foo = $_;
     my $value = $dates{$date}{$_};
     my $percent;
+
     if ($_ eq 'mailloop' || $_ eq 'registered') {
       $percent = 'n/a';
     } else {
@@ -92,18 +107,21 @@ sub displayquickstats() {
         0 : $dates{$date}{$_} / $dates{$date}{processed} * 100;
       $percent = sprintf '%5.1f%s', $percent, '%';
     } # if
-    my $stat = $value == 0 ?
-      0 : a {-href => "detail.cgi?type=$_;date=$date"}, $value;
-    print
-      td {-class => 'smalllabel'}, ucfirst ($_);
-    print
-      td {-class => 'smallnumber'}, $stat;
-    print
-      td {-class => 'smallnumber'}, $percent;
+
+    my $report = ucfirst $_;
+
+    $report  = a {-href => "detail.cgi?type=$_;date=$date"}, $report if $value;
+
+    print td {-class => 'link'},  $report,
+          td {-class => 'smallnumber'}, $value,
+          td {-class => 'smallnumber'}, $percent;
+
     print end_Tr;
-  } # foreach
+  } # for
+
   print end_table;
   print end_div;
+  print end_div;
 
   return;
 } # displayquickstats
@@ -118,7 +136,7 @@ sub Footing(;$) {
   print start_div {-class => "copyright"};
   print "Copyright © 2001-$year - All rights reserved";
   print br (
-    a ({-href => 'http://defaria.com'},
+    a ({-href => 'https://defaria.com'},
       'Andrew DeFaria'),
     a ({-href => 'mailto:Andrew@DeFaria.com'},
       '<Andrew@DeFaria.com>'));
@@ -132,10 +150,10 @@ sub Footing(;$) {
   return;
 } # Footing
 
-sub Debug($) {
+sub DebugWeb($) {
   my ($msg) = @_;
 
-  print br, font ({ -class => 'error' }, 'DEBUG: '), $msg;
+  print br, font({ -class => 'error' }, 'DEBUG: '), $msg;
 
   return;
 } # Debug
@@ -143,8 +161,11 @@ sub Debug($) {
 sub DisplayError($) {
   my ($errmsg) = @_;
 
-  print h3 ({-class => 'error',
-             -align => 'center'}, 'ERROR: ' . $errmsg);
+  print h3({
+    -class => 'error',
+    -align => 'center'},
+    'ERROR: ' . $errmsg
+  );
 
   Footing;
 
@@ -154,13 +175,13 @@ sub DisplayError($) {
 # This subroutine puts out the header for web pages. It is called by
 # various cgi scripts thus has a few parameters.
 sub Heading($$$$;$$@) {
-  my ($action,             # One of getcookie, setcookie, unsetcookie
-      $userid,             # User id (if setting a cookie)
-      $title,              # Title string
-      $h1,                 # H1 header
-      $h2,                 # H2 header (optional)
-      $table_name,         # Name of table in page, if any
-      @scripts)    = @_;   # Array of JavaScript scripts to include
+  my ($action,          # One of getcookie, setcookie, unsetcookie
+      $userid,          # User id (if setting a cookie)
+      $title,           # Title string
+      $h1,              # H1 header
+      $h2,              # H2 header (optional)
+      $table_name,      # Name of table in page, if any
+      @scripts) = @_;   # Array of JavaScript scripts to include
 
   my @java_scripts;
   my $cookie;
@@ -205,48 +226,48 @@ sub Heading($$$$;$$@) {
     );
   } # if
 
-  print
-    header (-title  => "MAPS: $title",
-            -cookie => $cookie);
-
-  if (defined $table_name) {
-    print
-      start_html (-title    => "MAPS: $title",
-                  -author   => 'Andrew\@DeFaria.com',
-                  -style    => {-src    => '/maps/css/MAPSStyle.css'},
-                  -onResize => "AdjustTableWidth (\"$table_name\");",
-                  -head     => [
-            Link ({-rel  => 'icon',
-                   -href => '/maps/MAPS.png',
-                   -type => 'image/png'}),
-            Link ({-rel  => 'shortcut icon',
-                   -href => '/maps/favicon.ico'})
-                  ],
-          -script    => @java_scripts);
+  print header(
+    -title  => $title,
+    -cookie => $cookie
+  );
+
+  if ($table_name) {
+    print start_html(
+      -title    => $title,
+      -author   => 'Andrew\@DeFaria.com',
+      -style    => {-src    => '/maps/css/MAPSStyle.css'},
+      -onResize => "AdjustTableWidth (\"$table_name\");",
+      -head     => [
+      Link({-rel  => 'icon',
+        -href => '/maps/MAPS.png',
+        -type => 'image/png'}),
+      Link({-rel  => 'shortcut icon',
+        -href => '/maps/favicon.ico'})
+      ],
+      -script    => @java_scripts);
   } else {
-    print
-      start_html (-title  => "MAPS: $title",
-                  -author => 'Andrew\@DeFaria.com',
-                  -style  => {-src    => '/maps/css/MAPSStyle.css'},
-                  -head   => [
-             Link ({-rel  => 'icon',
-                    -href => '/maps/MAPS.png',
-                    -type => 'image/png'}),
-             Link ({-rel  => 'shortcut icon',
-                    -href => '/maps/favicon.ico'})],
-                   -script    => @java_scripts);
+    print start_html(
+      -title  => $title,
+      -author => 'Andrew\@DeFaria.com',
+      -style  => {-src    => '/maps/css/MAPSStyle.css'},
+      -head   => [
+      Link({-rel  => 'icon',
+        -href => '/maps/MAPS.png',
+        -type => 'image/png'}),
+      Link({-rel  => 'shortcut icon',
+        -href => '/maps/favicon.ico'})],
+        -script    => @java_scripts);
   } # if
 
   print start_div {class => 'heading'};
-  print h2 {-align => 'center',
-            -class => 'header'},
-    font ({-class  => 'standout'}, 'MAPS'),
-      $h1;
+  print h2 {
+    -align => 'center',
+    -class => 'header'}, $h1;
 
   if (defined $h2 && $h2 ne '') {
-    print h3 {-align => 'center',
-              -class => 'header'},
-      $h2;
+    print h3 {
+      -align => 'center',
+      -class => 'header'}, $h2;
   } # if
   print end_div;
 
@@ -261,7 +282,8 @@ sub NavigationBar($) {
 
   print start_div {-id => 'leftbar'};
 
-  if (!defined $userid) {
+  unless ($userid) {
+    print h2({-align => 'center'}, font({-color => 'white'}, "MAPS $MAPS::VERSION"));
     print div ({-class => 'username'}, 'Welcome to MAPS');
     print div ({-class => 'menu'},
       (a {-href => '/maps/doc/'},
@@ -278,7 +300,9 @@ sub NavigationBar($) {
         'Help<br>'),
     );
   } else {
+    print h2({-align => 'center'}, font({-color => 'white'}, "MAPS $MAPS::VERSION"));
     print div ({-class => 'username'}, 'Welcome '. ucfirst $userid);
+
     print div ({-class => 'menu'},
       (a {-href => '/maps/'},
         'Home<br>'),
@@ -297,10 +321,13 @@ sub NavigationBar($) {
       (a {-href => '/maps/doc/'},
         'Help<br>'),
       (a {-href => '/maps/adm/'},
-        'MAPS<br>'),
+        'Admin<br>'),
       (a {-href => '/maps/?logout=yes'},
         'Logout'),
     );
+
+    displayquickstats($userid);
+
     print start_div {-class => 'search'};
     print start_form {-method => 'get',
                       -action => '/maps/bin/search.cgi',
@@ -316,8 +343,6 @@ sub NavigationBar($) {
     print end_form;
     print end_div;
 
-    displayquickstats;
-
     print start_div {-class => 'search'};
     print start_form {-method => 'post',
                 -action   => 'javascript://',
@@ -331,11 +356,14 @@ sub NavigationBar($) {
                  -maxlength => 255,
                  -value     => '',
                  -onclick   => "document.address.email.value = '';"};
+    print p "";
     print end_form;
     print end_div;
   } # if
 
   print end_div;
+
+  return;
 } # NavigationBar
 
 1;