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 $0 = $FindBin::Script;
21 use lib $FindBin::Bin;
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");
36 my $table_name = "searchresults";
39 my $prev_button = $prev >= 0 ?
40 a ({-href => "search.cgi?str=$str;next=$prev"},
41 "<img src=/maps/images/previous.gif border=0 alt=Previous align=middle>") : "";
42 my $next_button = ($next + $lines) < $total ?
43 a {-href => "search.cgi?str=$str;next=" . ($next + $lines)},
44 "<img src=/maps/images/next.gif border=0 alt=Next align=middle>" : "";
46 my $buttons = $prev_button;
49 submit ({-name => "action",
50 -value => "Whitelist Marked",
51 -onClick => "return CheckAtLeast1Checked (document.detail);"}) .
52 submit ({-name => "action",
53 -value => "Blacklist Marked",
54 -onClick => "return CheckAtLeast1Checked (document.detail);"}) .
55 submit ({-name => "action",
56 -value => "Nulllist Marked",
57 -onClick => "return CheckAtLeast1Checked (document.detail);"}) .
58 submit ({-name => "action",
59 -value => "Reset Marks",
60 -onClick => "return ClearAll (document.detail);"});
62 return $buttons . $next_button;
65 sub HighlightSearchStr {
68 my $highlighted_str = font {-class => "found"}, $str;
70 s/$str/<font class=\"found\">$&<\/font>/gi;
73 } # HighlightSearchStr
78 @emails = SearchEmails $userid, $str;
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"
107 my $sender = shift @{$_};
108 my $subject = shift @{$_};
109 my $date = shift @{$_};
111 my $display_sender = HighlightSearchStr $sender;
112 $subject = HighlightSearchStr $subject;
113 $subject = $subject eq "" ? "<Unspecified>" : $subject;
118 td {-class => "tableleftdata",
120 (checkbox {-name => "action$next",
122 hidden ({-name => "email$next",
123 -default => $sender}),
124 td {-class => "sender"},
125 a {-href => "mailto:$sender"}, $display_sender,
126 td {-class => "subject"},
127 a {-href => "display.cgi?sender=$sender"}, $subject,
128 td {-class => "dateright",
129 -width => "115"}, SQLDatetime2UnixDatetime $date
136 my @scripts = ("ListActions.js");
142 "Search Results for \"$str\"",
149 NavigationBar $userid;
151 DisplayError "No search string specified" if !defined $str;
153 if (!defined $lines) {
154 my %options = GetUserOptions $userid;
155 $lines = $options{"Page"};
158 $total = MAPSDB::count "email",
159 "userid = \"$userid\" and (subject like \"%$str%\" or sender like \"%$str%\")";
161 DisplayError "Nothing matching!" if $total eq 0;
163 $next = !defined $next ? 0 : $next;
164 $last = $next + $lines < $total ? $next + $lines : $total;
166 if (($next - $lines) > 0) {
167 $prev = $next - $lines;
169 $prev = $next eq 0 ? -1 : 0;