################################################################################
#
# File: $RCSfile: search.cgi,v $
-# Revision: $Revision: 1.1 $
-# Description: Search by sender and subject
+# Revision: $Revision: 1.1 $
+# Description: Search by sender and subject
# Author: Andrew@DeFaria.com
# Created: Mon Jan 16 20:25:32 PST 2006
# Modified: $Date: 2013/06/12 14:05:47 $
use warnings;
use FindBin;
-$0 = $FindBin::Script;
+local $0 = $FindBin::Script;
-use lib $FindBin::Bin;
+use lib "$FindBin::Bin/../lib";
+use lib "$FindBin::Bin/../../lib";
+use DateUtils;
use MAPS;
use MAPSWeb;
-use MAPSUtil;
+
use CGI qw (:standard *table start_Tr start_td start_div end_Tr end_td end_div);
use CGI::Carp "fatalsToBrowser";
-my $str = param ("str");
-my $next = param ("next");
-my $lines = param ("lines");
-my $userid;
-my $prev;
-my $total;
-my $last;
-my $table_name = "searchresults";
+my $str = param('str');
+my $next = param('next');
+my $lines = param('lines');
+
+my ($userid, $prev, $total, $last);
+
+my $table_name = 'searchresults';
sub MakeButtons {
my $prev_button = $prev >= 0 ?
my $buttons = $prev_button;
$buttons = $buttons .
- submit ({-name => "action",
- -value => "Whitelist Marked",
- -onClick => "return CheckAtLeast1Checked (document.detail);"}) .
- submit ({-name => "action",
- -value => "Blacklist Marked",
- -onClick => "return CheckAtLeast1Checked (document.detail);"}) .
- submit ({-name => "action",
- -value => "Nulllist Marked",
- -onClick => "return CheckAtLeast1Checked (document.detail);"}) .
- submit ({-name => "action",
- -value => "Reset Marks",
- -onClick => "return ClearAll (document.detail);"});
+ submit ({-name => "action",
+ -value => "Whitelist",
+ -onClick => "return CheckAtLeast1Checked (document.detail);"}) .
+ submit ({-name => "action",
+ -value => "Blacklist",
+ -onClick => "return CheckAtLeast1Checked (document.detail);"}) .
+ submit ({-name => "action",
+ -value => "Nulllist",
+ -onClick => "return CheckAtLeast1Checked (document.detail);"}) .
+ submit ({-name => "action",
+ -value => "Reset",
+ -onClick => "return ClearAll (document.detail);"});
return $buttons . $next_button;
} # MakeButtons
} # HighlightSearchStr
sub Body {
- my @emails;
-
- @emails = SearchEmails $userid, $str;
+ my @emails = SearchEmails(
+ userid => $userid,
+ search => $str,
+ );
my $current = $next + 1;
print div {-align => "center"}, b (
"(" . $current . "-" . $last . " of " . $total . ")");
print start_form {
- -method => "post",
- -action => "processaction.cgi",
- -name => "detail"
+ -method => "post",
+ -action => "processaction.cgi",
+ -name => "detail"
};
my $buttons = MakeButtons;
- print div {-align => "center",
- -class => "toolbar"}, $buttons;
- print start_table ({-align => "center",
- -id => $table_name,
- -border => 0,
- -cellspacing => 0,
- -cellpadding => 0,
- -width => "100%"}) . "\n";
+ print div {-align => "center",
+ -class => "toolbar"}, $buttons;
+ print start_table ({-align => "center",
+ -id => $table_name,
+ -border => 0,
+ -cellspacing => 0,
+ -cellpadding => 0,
+ -width => "100%"}) . "\n";
print
Tr [
th {-class => "tableleftend"},
- th {-class => "tableheader"}, "Sender",
- th {-class => "tableheader"}, "Subject",
- th {-class => "tablerightend"}, "Date"
+ th {-class => "tableheader"}, "Sender",
+ th {-class => "tableheader"}, "Subject",
+ th {-class => "tablerightend"}, "Date"
];
- foreach (@emails) {
- my $sender = shift @{$_};
- my $subject = shift @{$_};
- my $date = shift @{$_};
+ for my $rec (@emails) {
+ my $display_sender = HighlightSearchStr $rec->{sender};
- my $display_sender = HighlightSearchStr $sender;
- $subject = HighlightSearchStr $subject;
- $subject = $subject eq "" ? "<Unspecified>" : $subject;
+ $rec->{subject} //= '<Unspecified>';
+ $rec->{subject} = HighlightSearchStr $rec->{subject};
$next++;
print Tr [
td {-class => "tableleftdata",
- -align => "center"},
- (checkbox {-name => "action$next",
- -label => ""}),
- hidden ({-name => "email$next",
- -default => $sender}),
- td {-class => "sender"},
- a {-href => "mailto:$sender"}, $display_sender,
- td {-class => "subject"},
- a {-href => "display.cgi?sender=$sender"}, $subject,
- td {-class => "dateright",
- -width => "115"}, SQLDatetime2UnixDatetime $date
+ -align => "center"},
+ (checkbox {-name => "action$next",
+ -label => ""}),
+ hidden ({-name => "email$next",
+ -default => $rec->{sender}}),
+ td {-class => "sender"},
+ a {-href => "mailto:$rec->{sender}"}, $display_sender,
+ td {-class => "subject"},
+ a {-href => "display.cgi?sender=$rec->{sender}"}, $rec->{subject},
+ td {-class => "dateright",
+ -width => "115"}, SQLDatetime2UnixDatetime $rec->{timestamp},
+ ];
+ } # for
+
+ print
+ Tr [
+ td {-class => 'tableborderbottomleft'}, ' ',
+ td {-class => 'tableborder'}, ' ',
+ td {-class => 'tableborder'}, ' ',
+ td {-class => 'tableborderbottomright'}, ' '
];
- } # foreach
print end_table;
+
+ return;
} # Body
# Main
@scripts
);
+$userid //= $ENV{USER};
+
SetContext $userid;
NavigationBar $userid;
DisplayError "No search string specified" if !defined $str;
-if (!defined $lines) {
+if (!$lines) {
my %options = GetUserOptions $userid;
$lines = $options{"Page"};
} # if
-$total = MAPSDB::count "email",
- "userid = \"$userid\" and (subject like \"%$str%\" or sender like \"%$str%\")";
+$total = CountEmail(
+ userid => $userid,
+ additional => "(subject like '%$str%' or sender like '%$str%')",
+);
DisplayError "Nothing matching!" if $total eq 0;
-$next = !defined $next ? 0 : $next;
+$next //= 0;
$last = $next + $lines < $total ? $next + $lines : $total;
if (($next - $lines) > 0) {