Fixed hit_count to contain the actual hit count when adding or modifying records
[clearscm.git] / maps / bin / processaction.cgi
index d294bc8..493020b 100755 (executable)
@@ -26,13 +26,13 @@ use MAPSWeb;
 use CGI qw (:standard *table start_Tr end_Tr);
 use CGI::Carp 'fatalsToBrowser';
 
-my $type       = param 'type';
-my $action     = param 'action';
-my $next       = param 'next';
-my $userid     = cookie 'MAPSUser';
+my $type   = param 'type';
+my $action = param 'action';
+my $next   = param 'next';
+my $userid = cookie 'MAPSUser';
 my $lines;
 my $total;
-my $table_name = 'list';
+my $table_name = 'list';
 
 my @scripts = ('ListActions.js');
 
@@ -64,12 +64,12 @@ sub DeleteEntries {
     $count += DeleteList $type, $_;
   } # foreach
 
-  if ($count eq 0) {
+  if ($count == 0) {
     DisplayError 'Nothing to delete!';
   } else {
     ResequenceList $userid, $type;
 
-    if ($count eq 1) {
+    if ($count == 1) {
       print redirect ("/maps/php/list.php?type=$type&next=$next&message=Deleted entry");
     } else {
       print redirect ("/maps/php/list.php?type=$type&next=$next&message=Deleted $count entries");
@@ -82,52 +82,65 @@ sub DeleteEntries {
 sub PrintInputLine ($$$$$) {
   my ($nextseq, $email_nbr, $leftclass, $dataclass, $rightclass) = @_;
 
-  my $email    = '';
-  my $pattern  = '';
-  my $domain   = '';
+  my $email     = '';
+  my $pattern   = '';
+  my $domain    = '';
+  my $hit_count = 0;
 
   if (defined $email_nbr && $email_nbr ne '') {
     $email = param "email$email_nbr";
     if ($email && $email ne '') {
       ($pattern, $domain) = split /\@/, $email;
     } # if
+
+    $hit_count = CountMsg $email;
   } # if
 
   print Tr [
-    td {-class                 => $leftclass,
-       -align                  => 'center'}, "$nextseq",
-    td {-class                 => $dataclass,
-       -align                  => 'right'},
-      (textfield {-class       => 'inputfield',
-                 -style        => 'width:100%',
-                 -align        => 'right',
-                 -size         => 25,
-                 -maxlength    => '255',
-                 -name         => "pattern$nextseq",
-                 -value        => $pattern}),
-    td {-class                 => $dataclass,
-       -align                  => 'center'}, '@',
-    td {-class                 => $dataclass},
-      (textfield {-class       => 'inputfield',
-                 -style        => 'width:100%',
-                 -align        => 'left',
-                 -size         => 25,
-                 -maxlength    => '255',
-                 -name         => "domain$nextseq",
-                 -value        => $domain}),
-    td {-class                 => $rightclass},
-      (textfield {-class       => 'inputfield',
-                 -style        => 'width:100%',
-                 -align        => 'left',
-                 -size         => 25,
-                 -maxlength    => '255',
-                 -name         => "comment$nextseq",
-                 -value        => ''}),
+    td {-class      => $leftclass,
+        -align      => 'center'}, "$nextseq",
+    td {-class      => $dataclass,
+        -align      => 'right'},
+      (textfield {-class     => 'inputfield',
+                  -style     => 'width:100%',
+                  -align     => 'right',
+                  -size      => 25,
+                  -maxlength => '255',
+                  -name      => "pattern$nextseq",
+                  -value     => $pattern}),
+    td {-class      => $dataclass,
+        -align      => 'center'}, '@',
+    td {-class      => $dataclass},
+      (textfield {-class      => 'inputfield',
+                  -style      => 'width:100%',
+                  -align      => 'left',
+                  -size       => 25,
+                  -maxlength  => '255',
+                  -name       => "domain$nextseq",
+                  -value      => $domain}),
+    td {-class      => $dataclass},
+      (textfield {-class     => 'inputfield',
+                  -style     => 'width:100%',
+                  -align     => 'left',
+                  -size      => 25,
+                  -maxlength => '255',
+                  -name      => "comment$nextseq",
+                  -value     => ''}),
+    td {-class      => $rightclass},
+      (textfield {-class     => 'inputfield',
+                  -style     => 'width:100%',
+                  -align     => 'left',
+                  -size      => 25,
+                  -maxlength => '255',
+                  -name      => "hit_count$nextseq",
+                  -value     => $hit_count}),
   ];
+
+  return;
 } # PrintInputLine
 
 sub AddNewEntry {
-  my ($type, @selected)        = @_;
+  my ($type, @selected)  = @_;
 
   # First display the last page and add the appropriate number of
   # empty, editable entries (possibly filled in) for the user to add
@@ -155,23 +168,24 @@ sub AddNewEntry {
 
   # Now display table and new entry
   print start_form {
-    -method    => 'post',
-    -action    => 'add2' . $type . 'list.cgi',
-    -name      => 'list'
+    -method => 'post',
+    -action => 'add2' . $type . 'list.cgi',
+    -name   => 'list'
   };
 
-  print start_table {-align            => 'center',
-                    -id                => $table_name,
-                    -border            => 0,
-                    -cellspacing       => 0,
-                    -cellpadding       => 4,
-                    -width             => '100%'};
+  print start_table {-align       => 'center',
+                     -id          => $table_name,
+                     -border      => 0,
+                     -cellspacing => 0,
+                     -cellpadding => 4,
+                     -width       => '100%'};
   print Tr [
-    th {-class => 'tableleftend'},     'Seq',
-    th {-class => 'tableheader'},      'Username',
-    th {-class => 'tableheader'},      '@',
-    th {-class => 'tableheader'},      'Domain',
-    th {-class => 'tablerightend'},    'Comments'
+    th {-class => 'tableleftend'},  'Seq',
+    th {-class => 'tableheader'},   'Username',
+    th {-class => 'tableheader'},   '@',
+    th {-class => 'tableheader'},   'Domain',
+    th {-class => 'tableheader'},   'Comments',
+    th {-class => 'tablerightend'}, 'Hit Count'
   ];
 
   my @list = ReturnList $type, $next, $lines;
@@ -184,27 +198,30 @@ sub AddNewEntry {
     %record = %{$_};
 
     # Normalize fields
-    my $sequence = $record{sequence};
-    my $pattern  = $record{pattern} ? $record{pattern} : ' ';
-    my $domain   = $record{domain}  ? $record{domain}  : ' ';
-    my $comment  = $record{comment} ? $record{comment} : ' ';
+    my $sequence  = $record{sequence};
+    my $pattern   = $record{pattern}   ? $record{pattern}   : ' ';
+    my $domain    = $record{domain}    ? $record{domain}    : ' ';
+    my $comment   = $record{comment}   ? $record{comment}   : ' ';
+    my $hit_count = $record{hit_count} ? $record{hit_count} : ' ';
 
     print Tr [
-      td {-class       => 'tableleftdata',
-         -align        => 'center'}, $sequence,
-      td {-class       => 'tabledata',
-         -align        => 'right'}, $pattern,
-      td {-class       => 'tabledata',
-         -align        => 'center'}, '@',
-      td {-class       => 'tabledata',
-         -align        => 'left'}, $domain,
-      td {-class       => 'tablerightdata',
-         -align        => 'left'}, $comment
+      td {-class  => 'tableleftdata',
+          -align  => 'center'}, $sequence,
+      td {-class  => 'tabledata',
+          -align  => 'right'}, $pattern,
+      td {-class  => 'tabledata',
+          -align  => 'center'}, '@',
+      td {-class  => 'tabledata',
+          -align  => 'left'}, $domain,
+      td {-class  => 'tabledata',
+          -align  => 'left'}, $comment,
+      td {-class  => 'tablerightdata',
+          -align  => 'right'}, $hit_count,
     ];
   } # foreach
 
   # Now the input line(s)
-  if (@selected eq 0) {
+  if (@selected == 0) {
     PrintInputLine $nextseq, undef, 'tablebottomleft', 'tablebottomdata',
                                     'tablebottomright';
   } else {
@@ -220,14 +237,16 @@ sub AddNewEntry {
   print end_table;
   print br,
     '<center>',
-      submit ({-name   => 'update',
-              -value   => 'Update',
-              -onClick => 'return CheckEntry (document.list);'}),
-      submit ({-name   => 'Reset',
-              -value   => 'Reset',
-              -onClick => 'history.back(); return false'}),
+      submit ({-name    => 'update',
+               -value   => 'Update',
+               -onClick => 'return CheckEntry (document.list);'}),
+      submit ({-name    => 'Reset',
+               -value   => 'Reset',
+               -onClick => 'history.back(); return false'}),
     '</center>';
   print end_form;
+
+  return;
 } # AddNewEntry
 
 sub ModifyEntries {
@@ -251,30 +270,31 @@ sub ModifyEntries {
 
   # Redisplay the page but open up the lines that are getting modified
   print start_form {
-    -method    => 'post',
-    -action    => 'modifyentries.cgi',
-    -name      => 'list'
+    -method  => 'post',
+    -action  => 'modifyentries.cgi',
+    -name    => 'list'
   };
 
   # Print some hidden fields to pass along
   print
-    hidden ({-name     => 'type',
-            -default   => $type}),
-    hidden ({-name     => 'next',
-            -default   => $next});
-
-  print start_table {-align            => 'center',
-                    -id                => $table_name,
-                    -border            => 0,
-                    -cellspacing       => 0,
-                    -cellpadding       => 4,
-                    -width             => '100%'};
+    hidden ({-name    => 'type',
+             -default => $type}),
+    hidden ({-name    => 'next',
+             -default => $next});
+
+  print start_table {-align       => 'center',
+                     -id          => $table_name,
+                     -border      => 0,
+                     -cellspacing => 0,
+                     -cellpadding => 4,
+                     -width       => '100%'};
   print Tr [
-    th {-class => 'tableleftend'},     'Seq',
-    th {-class => 'tableheader'},      'Username',
-    th {-class => 'tableheader'},      '@',
-    th {-class => 'tableheader'},      'Domain',
-    th {-class => 'tablerightend'},    'Comments'
+    th {-class => 'tableleftend'},  'Seq',
+    th {-class => 'tableheader'},   'Username',
+    th {-class => 'tableheader'},   '@',
+    th {-class => 'tableheader'},   'Domain',
+    th {-class => 'tableheader'},   'Comments',
+    th {-class => 'tablerightend'}, 'Hit Count',
   ];
 
   my @list = ReturnList $type, $next, $lines;
@@ -296,59 +316,71 @@ sub ModifyEntries {
     $i++;
 
     print start_Tr,
-      td {-class       => $leftclass,
-         -align        => 'center'}, $record{sequence};
+      td {-class  => $leftclass,
+          -align  => 'center'}, $record{sequence};
 
     if ($record{sequence} eq $selected[$s]) {
       $s++;
       # Normalize fields
-      my $pattern = $record{pattern} ? $record{pattern} : '';
-      my $domain  = $record{domain}  ? $record{domain}  : '';
-      my $comment = $record{comment} ? $record{comment} : '';
+      my $pattern   = $record{pattern}   ? $record{pattern}   : '';
+      my $domain    = $record{domain}    ? $record{domain}    : '';
+      my $comment   = $record{comment}   ? $record{comment}   : '';
+      my $hit_count = $record{hit_count} ? $record{hit_count} : '';
 
       print
-        td {-class                     => $dataclass,
-           -align                      => 'right'},
-          (textfield {-class           => 'inputfield',
-                     -style            => 'width:100%',
-                     -align            => 'right',
-                     -size             => 25,
-                     -maxlength        => '255',
-                     -name             => "pattern$sequence",
-                     -value            => $pattern}),
-        td {-class                     => $dataclass,
-           -align                      => 'center'}, '@',
-        td {-class                     => $dataclass},
-          (textfield {-class           => 'inputfield',
-                     -style            => 'width:100%',
-                     -align            => 'left',
-                     -size             => 25,
-                     -maxlength        => '255',
-                     -name             => "domain$sequence",
-                     -value            => $domain}),
-        td {-class                     => $rightclass},
-           (textfield {-class          => 'inputfield',
-                      -style           => 'width:100%',
-                      -align           => 'left',
-                      -size            => 25,
-                      -maxlength       => '255',
-                      -name            => "comment$sequence",
-                      -value           => $comment});
+        td {-class      => $dataclass,
+            -align      => 'right'},
+          (textfield {-class     => 'inputfield',
+                      -style     => 'width:100%',
+                      -align     => 'right',
+                      -size      => 25,
+                      -maxlength => '255',
+                      -name      => "pattern$sequence",
+                      -value     => $pattern}),
+        td {-class      => $dataclass,
+            -align      => 'center'}, '@',
+        td {-class      => $dataclass},
+          (textfield {-class     => 'inputfield',
+                      -style     => 'width:100%',
+                      -align     => 'left',
+                      -size      => 25,
+                      -maxlength => '255',
+                      -name      => "domain$sequence",
+                      -value     => $domain}),
+        td {-class      => $dataclass},
+           (textfield {-class     => 'inputfield',
+                       -style     => 'width:100%',
+                       -align     => 'left',
+                       -size      => 25,
+                       -maxlength => '255',
+                       -name      => "comment$sequence",
+                       -value     => $comment}),
+        td {-class      => $rightclass},
+           (textfield {-class     => 'inputfield',
+                       -style     => 'width:100%',
+                       -align     => 'left',
+                       -size      => 25,
+                       -maxlength => '255',
+                       -name      => "hit_count$sequence",
+                       -value     => $hit_count});
     } else {
       # Put in '&nbsp;' for undefined fields
-      my $pattern = $record{pattern} ? $record{pattern} : '&nbsp;';
-      my $domain  = $record{domain}  ? $record{domain}  : '&nbsp;';
-      my $comment = $record{comment} ? $record{comment} : '&nbsp;';
+      my $pattern   = $record{pattern}   ? $record{pattern}   : '&nbsp;';
+      my $domain    = $record{domain}    ? $record{domain}    : '&nbsp;';
+      my $comment   = $record{comment}   ? $record{comment}   : '&nbsp;';
+      my $hit_count = $record{hit_count} ? $record{hit_count} : '&nbsp;';
 
       print
         td {-class => $dataclass,
-           -align => 'right'}, $pattern,
+            -align => 'right'}, $pattern,
+        td {-class => $dataclass,
+            -align => 'center'}, '@',
         td {-class => $dataclass,
-           -align => 'center'}, '@',
+            -align => 'left'}, $domain,
         td {-class => $dataclass,
-           -align => 'left'}, $domain,
+            -align => 'left'}, $comment,
         td {-class => $rightclass,
-           -align => 'left'}, $comment;
+            -align => 'left'}, $hit_count;
     } # if
 
     print end_Tr;
@@ -357,14 +389,16 @@ sub ModifyEntries {
   print end_table;
   print br,
     '<center>',
-      submit ({-name   => 'update',
-              -value   => 'Update',
-              -onClick => 'return CheckEntry (document.list);'}),
-      submit ({-name   => 'Reset',
-              -value   => 'Reset',
-              -onClick => 'history.back(); return false'}),
+      submit ({-name    => 'update',
+               -value   => 'Update',
+               -onClick => 'return CheckEntry (document.list);'}),
+      submit ({-name    => 'Reset',
+               -value   => 'Reset',
+               -onClick => 'history.back(); return false'}),
     '</center>';
   print end_form;
+
+  return;
 } # ModifyEntries
 
 sub WhitelistMarked {