2 ################################################################################
4 # File: $RCSfile: search.cgi,v $
5 # Revision: $Revision: 1.1 $
6 # Description: Search by sender and subject
7 # Author: Andrew@DeFaria.com
8 # Created: Mon Jan 16 20:25:32 PST 2006
9 # Modified: $Date: 2013/06/12 14:05:47 $
12 # (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
14 ################################################################################
19 local $0 = $FindBin::Script;
21 use lib "$FindBin::Bin/../lib";
26 use CGI qw (:standard *table start_Tr start_td start_div end_Tr end_td end_div);
27 use CGI::Carp "fatalsToBrowser";
29 my $str = param('str');
30 my $next = param('next');
31 my $lines = param('lines');
33 my ($userid, $prev, $total, $last);
35 my $table_name = 'searchresults';
38 my $prev_button = $prev >= 0 ?
39 a ({-href => "search.cgi?str=$str;next=$prev"},
40 "<img src=/maps/images/previous.gif border=0 alt=Previous align=middle>") : "";
41 my $next_button = ($next + $lines) < $total ?
42 a {-href => "search.cgi?str=$str;next=" . ($next + $lines)},
43 "<img src=/maps/images/next.gif border=0 alt=Next align=middle>" : "";
45 my $buttons = $prev_button;
48 submit ({-name => "action",
49 -value => "Whitelist",
50 -onClick => "return CheckAtLeast1Checked (document.detail);"}) .
51 submit ({-name => "action",
52 -value => "Blacklist",
53 -onClick => "return CheckAtLeast1Checked (document.detail);"}) .
54 submit ({-name => "action",
56 -onClick => "return CheckAtLeast1Checked (document.detail);"}) .
57 submit ({-name => "action",
59 -onClick => "return ClearAll (document.detail);"});
61 return $buttons . $next_button;
64 sub HighlightSearchStr {
67 my $highlighted_str = font {-class => "found"}, $str;
69 s/$str/<font class=\"found\">$&<\/font>/gi;
72 } # HighlightSearchStr
75 my @emails = SearchEmails(
80 my $current = $next + 1;
82 print div {-align => "center"}, b (
83 "(" . $current . "-" . $last . " of " . $total . ")");
86 -action => "processaction.cgi",
89 my $buttons = MakeButtons;
90 print div {-align => "center",
91 -class => "toolbar"}, $buttons;
92 print start_table ({-align => "center",
97 -width => "100%"}) . "\n";
100 th {-class => "tableleftend"},
101 th {-class => "tableheader"}, "Sender",
102 th {-class => "tableheader"}, "Subject",
103 th {-class => "tablerightend"}, "Date"
106 for my $rec (@emails) {
107 my $display_sender = HighlightSearchStr $rec->{sender};
109 $rec->{subject} //= '<Unspecified>';
110 $rec->{subject} = HighlightSearchStr $rec->{subject};
115 td {-class => "tableleftdata",
117 (checkbox {-name => "action$next",
119 hidden ({-name => "email$next",
120 -default => $rec->{sender}}),
121 td {-class => "sender"},
122 a {-href => "mailto:$rec->{sender}"}, $display_sender,
123 td {-class => "subject"},
124 a {-href => "display.cgi?sender=$rec->{sender}"}, $rec->{subject},
125 td {-class => "dateright",
126 -width => "115"}, SQLDatetime2UnixDatetime $rec->{date},
135 my @scripts = ("ListActions.js");
141 "Search Results for \"$str\"",
147 $userid //= $ENV{USER};
150 NavigationBar $userid;
152 DisplayError "No search string specified" if !defined $str;
155 my %options = GetUserOptions $userid;
156 $lines = $options{"Page"};
161 additional => "(subject like '%$str%' or sender like '%$str%')",
164 DisplayError "Nothing matching!" if $total eq 0;
167 $last = $next + $lines < $total ? $next + $lines : $total;
169 if (($next - $lines) > 0) {
170 $prev = $next - $lines;
172 $prev = $next eq 0 ? -1 : 0;