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";
22 use lib "$FindBin::Bin/../../lib";
28 use CGI qw (:standard *table start_Tr start_td start_div end_Tr end_td end_div);
29 use CGI::Carp "fatalsToBrowser";
31 my $str = param('str');
32 my $next = param('next');
33 my $lines = param('lines');
35 my ($userid, $prev, $total, $last);
37 my $table_name = 'searchresults';
40 my $prev_button = $prev >= 0 ?
41 a ({-href => "search.cgi?str=$str;next=$prev"},
42 "<img src=/maps/images/previous.gif border=0 alt=Previous align=middle>") : "";
43 my $next_button = ($next + $lines) < $total ?
44 a {-href => "search.cgi?str=$str;next=" . ($next + $lines)},
45 "<img src=/maps/images/next.gif border=0 alt=Next align=middle>" : "";
47 my $buttons = $prev_button;
50 submit ({-name => "action",
51 -value => "Whitelist",
52 -onClick => "return CheckAtLeast1Checked (document.detail);"}) .
53 submit ({-name => "action",
54 -value => "Blacklist",
55 -onClick => "return CheckAtLeast1Checked (document.detail);"}) .
56 submit ({-name => "action",
58 -onClick => "return CheckAtLeast1Checked (document.detail);"}) .
59 submit ({-name => "action",
61 -onClick => "return ClearAll (document.detail);"});
63 return $buttons . $next_button;
66 sub HighlightSearchStr {
69 my $highlighted_str = font {-class => "found"}, $str;
71 s/$str/<font class=\"found\">$&<\/font>/gi;
74 } # HighlightSearchStr
77 my @emails = SearchEmails(
82 my $current = $next + 1;
84 print div {-align => "center"}, b (
85 "(" . $current . "-" . $last . " of " . $total . ")");
88 -action => "processaction.cgi",
91 my $buttons = MakeButtons;
92 print div {-align => "center",
93 -class => "toolbar"}, $buttons;
94 print start_table ({-align => "center",
99 -width => "100%"}) . "\n";
102 th {-class => "tableleftend"},
103 th {-class => "tableheader"}, "Sender",
104 th {-class => "tableheader"}, "Subject",
105 th {-class => "tablerightend"}, "Date"
108 for my $rec (@emails) {
109 my $display_sender = HighlightSearchStr $rec->{sender};
111 $rec->{subject} //= '<Unspecified>';
112 $rec->{subject} = HighlightSearchStr $rec->{subject};
117 td {-class => "tableleftdata",
119 (checkbox {-name => "action$next",
121 hidden ({-name => "email$next",
122 -default => $rec->{sender}}),
123 td {-class => "sender"},
124 a {-href => "mailto:$rec->{sender}"}, $display_sender,
125 td {-class => "subject"},
126 a {-href => "display.cgi?sender=$rec->{sender}"}, $rec->{subject},
127 td {-class => "dateright",
128 -width => "115"}, SQLDatetime2UnixDatetime $rec->{timestamp},
134 td {-class => 'tableborderbottomleft'}, ' ',
135 td {-class => 'tableborder'}, ' ',
136 td {-class => 'tableborder'}, ' ',
137 td {-class => 'tableborderbottomright'}, ' '
145 my @scripts = ("ListActions.js");
151 "Search Results for \"$str\"",
157 $userid //= $ENV{USER};
160 NavigationBar $userid;
162 DisplayError "No search string specified" if !defined $str;
165 my %options = GetUserOptions $userid;
166 $lines = $options{"Page"};
171 additional => "(subject like '%$str%' or sender like '%$str%')",
174 DisplayError "Nothing matching!" if $total eq 0;
177 $last = $next + $lines < $total ? $next + $lines : $total;
179 if (($next - $lines) > 0) {
180 $prev = $next - $lines;
182 $prev = $next eq 0 ? -1 : 0;