X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=maps%2Fbin%2Fdetail.cgi;h=53fc47e2e24ace7d0336f7b66ded9ce27048c75e;hb=24352d115ade3e1f4916df9c0102b1edb804f0c6;hp=55c9cbde98df17f3b81aacb4298686de120e6c0b;hpb=7ad5fd1a2d54b940018de904485ce560562af176;p=clearscm.git diff --git a/maps/bin/detail.cgi b/maps/bin/detail.cgi index 55c9cbd..53fc47e 100755 --- a/maps/bin/detail.cgi +++ b/maps/bin/detail.cgi @@ -16,30 +16,31 @@ use strict; use warnings; use MIME::Words qw(:all); + +use CGI qw(:standard *table start_td end_td start_Tr end_Tr start_div end_div); +use CGI::Carp 'fatalsToBrowser'; + use FindBin; -$0 = $FindBin::Script; + +local $0 = $FindBin::Script; use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../lib"; use MAPS; use MAPSLog; -use MAPSUtil; use MAPSWeb; -use CGI qw(:standard *table start_td end_td start_Tr end_Tr start_div end_div); -use CGI::Carp 'fatalsToBrowser'; +use DateUtils; -my $type = param('type'); -my $next = param('next'); -my $lines = param('lines'); -my $date = param('date'); +my $type = param 'type'; +my $next = param 'next'; +my $lines = param 'lines'; +my $date = param 'date'; $date ||= ''; -my $userid; -my $current; -my $last; -my $prev; -my $total; +my ($userid, $current, $last, $prev, $total); + my $table_name = 'detail'; my %types = ( @@ -73,7 +74,7 @@ my %types = ( ] ); -sub MakeButtons { +sub MakeButtons($) { my ($type) = @_; my $prev_button = $prev >= 0 ? @@ -91,10 +92,10 @@ sub MakeButtons { $buttons = $buttons . submit ({-name => 'action', -value => 'Blacklist', - -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . + -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . ' ' . submit ({-name => 'action', -value => 'Nulllist', - -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . + -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . ' ' . submit ({-name => 'action', -value => 'Reset', -onClick => 'return ClearAll (document.detail);'}); @@ -102,10 +103,10 @@ sub MakeButtons { $buttons = $buttons . submit ({-name => 'action', -value => 'Whitelist', - -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . + -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . ' ' . submit ({-name => 'action', -value => 'Nulllist', - -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . + -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . ' ' . submit ({-name => 'action', -value => 'Reset', -onClick => 'return ClearAll (document.detail);'}); @@ -113,10 +114,10 @@ sub MakeButtons { $buttons = $buttons . submit ({-name => 'action', -value => 'Whitelist', - -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . + -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . ' ' . submit ({-name => 'action', -value => 'Blacklist', - -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . + -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . ' ' . submit ({-name => 'action', -value => 'Reset', -onClick => 'return ClearAll (document.detail);'}); @@ -124,22 +125,27 @@ sub MakeButtons { $buttons = $buttons . submit ({-name => 'action', -value => 'Whitelist', - -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . + -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . ' ' . submit ({-name => 'action', -value => 'Blacklist', - -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . + -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . ' ' . submit ({-name => 'action', -value => 'Nulllist', - -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . + -onClick => 'return CheckAtLeast1Checked (document.detail);'}) . ' ' . submit ({-name => 'action', -value => 'Reset', -onClick => 'return ClearAll (document.detail);'}); } # if - return $buttons . $next_button; + print div { + -align => 'center', + -class => 'toolbar', + }, $buttons . $next_button; + + return; } # MakeButtons -sub PrintTable { +sub Body($) { my ($type) = @_; my $current = $next + 1; @@ -151,6 +157,9 @@ sub PrintTable { -action => 'processaction.cgi', -name => 'detail' }; + + MakeButtons $type; + print start_table({-align => 'center', -id => $table_name, -border => 0, @@ -158,22 +167,42 @@ sub PrintTable { -cellpadding => 0, -width => '100%'}) . "\n"; - my $buttons = MakeButtons $type; - - print start_div {-class => 'toolbar'}; print Tr [ - td {-class => 'tablebordertopleft', - -valign => 'middle'}, - td {-class => 'tablebordertopright', - -valign => 'middle', - -align => 'center'}, $buttons, + td {-class => 'tablebordertopleft'}, ' ', + th {-class => 'tableborder'}, 'Sender', + th {-class => 'tableborder'}, 'List', + th {-class => 'tableborder'}, 'Hit Count', + th {-class => 'tableborder'}, 'Rule', + th {-class => 'tablebordertopright'}, 'Comment', ]; - print end_div; - for my $sender (ReturnSenders($userid, $type, $next, $lines, $date)) { - my @msgs = ReturnMessages($userid, $sender); - my @msgs2 = @msgs; + for my $sender (ReturnSenders( + userid => $userid, + type => $type, + start_at => $next, + lines => $lines, + date => $date + )) { + my $msgs = ReturnMessages( + userid => $userid, + sender => $sender, + ); + + # This is for the purposes of supplying a subject line if the mailto address + # is clicked on. It's kludgy because we are simply grabbing the subject line + # of the first email sent where there may be many emails from this sender. + # Still it is often the right subject (or a good enough one) + # + # A little tricky here because of transliteration. If I test for + # $msg->[0]{subject} when $msg->[0] is essentially empty I create the hash + # making it non empty. Therefore I need to first test if $msgs->[0] exists + # first. + my $heading = ''; + + if ($msgs->[0]) { + $heading = $msgs->[0]{subject} if $msgs->[0]{subject}; + } # if my ($onlist, $seq); @@ -190,130 +219,130 @@ sub PrintTable { } # unless } # unless - if ($rule) { - $rule =~ s/Matching rule: \(//; - $rule =~ s/\)//; - - if ($rule =~ /(\w+):(\d+)/) { - my $list = $1; - my $sequence = $2 - 1; - my $link = "$list:$2/$hit_count"; + my ($list, $sequence, $comment); - $rule =~ s/\w+:\d+/$link/; + # Parse rule + if ($rule) { + if ($rule =~ /\((\w+):(\d+)\)\s+"(\S*)"/) { + $list = $1; + $sequence = $2; + $rule = $3; + $comment = ''; + } elsif ($rule =~ /\((\w+):(\d+)\)\s+"(\S*) - (.*)"/) { + $list = $1; + $sequence = $2; + $rule = $3; + $comment = $4; } # if + + $rule =~ s/\\@/\@/; } # if $next++; - print - start_Tr {-valign => 'middle'}; - print - td {-class => 'tableborder'}, small ($next, - checkbox {-name => "action$next", - -label => ''}), - hidden ({-name => "email$next", - -default => $sender}); - print - start_td {-align => 'left'}; - print - start_table {-class => 'tablerightdata', - -cellpadding => 2, - -callspacing => 0, - -border => 0, - -width => '100%', - -bgcolor => '#d4d0c8'}; + + # Start Sender line + my $rowspan = @$msgs + 1; + + print start_Tr {-valign => 'middle'}; + print td { + -class => 'tableborder', + -rowspan => $rowspan, + }, small ($next, + checkbox { + -name => "action$next", + -label => '' + }), hidden({ + -name => "email$next", + -default => $sender + }); # Get subject line - my $heading = $msgs2[0][0] || ''; $heading = "?subject=$heading" if $heading; - print - td {-class => 'tablelabel', - -valign => 'middle', - -width => '40'}, 'Sender:', - td {-class => 'sender', - -valign => 'middle', - -width => '40%'}, - a {-href => "mailto:$sender$heading"}, $sender, - td { - -valign => 'middle'}, - $rule; - print - end_table; - - my $messages = 1; - - for (@msgs) { - my $msg_date = pop @{$_}; - my $link_date = $msg_date; - my $subject = pop @{$_}; - - if ($date eq substr ($msg_date, 0, 10)) { - $msg_date = b font {-color => 'green'}, SQLDatetime2UnixDatetime $msg_date; + + print td { + -class => 'sender', + }, a { + -href => "mailto:$sender$heading", + }, " $sender"; + + my $listlink = ($list and $sequence) ? "$list:$sequence" : ' '; + + print td { + -class => 'tabledata', + -align => 'right', + }, a { + href => "/maps/php/list.php?type=$list&next=" . ($sequence - 1), + }, $listlink, + td { + -class => 'tabledata', + -align => 'right', + }, "$hit_count ", + td { + -class => 'tabledata', + }, $rule, + td { + -class => 'tablerightdata', + }, $comment; + print end_Tr; + + for my $rec (@$msgs) { + if ($date eq substr ($rec->{timestamp}, 0, 10)) { + $rec->{date} = b font {-color => 'green'}, SQLDatetime2UnixDatetime $rec->{timestamp}; } else { - $msg_date = SQLDatetime2UnixDatetime $msg_date; + $rec->{date} = SQLDatetime2UnixDatetime $rec->{timestamp}; } # if - $subject = $subject eq '' ? '<Unspecified>' : $subject; - $subject = decode_mimewords ($subject); - $subject =~ s/\>/>/g; - $subject =~ s/\{subject} //= '<Unspecified>'; + $rec->{subject} = decode_mimewords ($rec->{subject}); + $rec->{subject} =~ s/\>/>/g; + $rec->{subject} =~ s/\ 'tablerightdata', - -cellpadding => 2, - -cellspacing => 2, - -border => 0, - -width => '100%'}; print Tr [ - td {-class => 'msgnbr', - -valign => 'middle', - -rowspan => 2, - -width => '2%'}, $messages++, - td {-class => 'tablelabel', - -valign => 'middle', - -width => '45'}, 'Subject:', - td {-class => 'subject', - -valign => 'middle', - -bgcolor => '#ffffff'}, - a {-href => "display.cgi?sender=$sender;msg_date=$link_date"}, $subject, - td {-class => 'date', + td { + -class => 'subject', + -valign => 'middle', + -bgcolor => '#ffffff', + -colspan => 4, + }, a {-href => "display.cgi?sender=$sender;msg_date=$rec->{timestamp}" + }, '    ' . $rec->{subject}, + td {-class => 'tablerightdata', -width => '150', - -valign => 'middle'}, $msg_date + -valign => 'middle', + -align => 'right'}, span {-class => 'date'}, $rec->{date}, ]; - print end_table; } # for - print end_td; - print end_Tr; } # for - print start_div {-class => 'toolbar'}; print Tr [ - td {-class => 'tableborderbottomleft', - -valign => 'middle'}, - td {-class => 'tableborderbottomright', - -valign => 'middle'}, - $buttons + td {-class => 'tableborderbottomleft'}, ' ', + th {-class => 'tableborder'}, ' ', + th {-class => 'tableborder'}, ' ', + th {-class => 'tableborder'}, ' ', + th {-class => 'tableborder'}, ' ', + th {-class => 'tableborderbottomright'}, ' ' ]; - print end_div; print end_table; print end_form; + MakeButtons $type; + return; -} # PrintTable +} # Body # Main my $condition; my @scripts = ('ListActions.js'); -my $heading_date =$date ne '' ? ' on ' . FormatDate ($date) : ''; +my $heading_date =$date ne '' ? ' on ' . FormatDate ($date, 1) : ''; $userid = Heading( 'getcookie', '', (ucfirst ($type) . ' Report'), - $types {$type} [0], - $types {$type} [1] . $heading_date, + $types{$type} [0], + $types{$type} [1] . $heading_date, $table_name, @scripts ); @@ -329,16 +358,18 @@ unless ($lines) { } # unless if ($date eq '') { - $condition .= "userid = '$userid' and type = '$type'"; + $condition .= "type = '$type'"; } else { my $sod = $date . ' 00:00:00'; my $eod = $date . ' 23:59:59'; - $condition .= "userid = '$userid' and type = '$type' " - . "and timestamp > '$sod' and timestamp < '$eod' "; + $condition .= "type = '$type' and timestamp > '$sod' and timestamp < '$eod'"; } # if -$total = count_distinct('log', 'sender', $condition); +$total = CountLog( + userid => $userid, + additional => $condition, +); $next ||= 0; @@ -350,7 +381,7 @@ if (($next - $lines) > 0) { $prev = $next == 0 ? -1 : 0; } # if -PrintTable($type); +Body($type); Footing($table_name);