]>
Commit | Line | Data |
---|---|---|
84fb5b46 MKG |
1 | %# BEGIN BPS TAGGED BLOCK {{{ |
2 | %# | |
3 | %# COPYRIGHT: | |
4 | %# | |
403d7b0b | 5 | %# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC |
84fb5b46 MKG |
6 | %# <sales@bestpractical.com> |
7 | %# | |
8 | %# (Except where explicitly superseded by other copyright notices) | |
9 | %# | |
10 | %# | |
11 | %# LICENSE: | |
12 | %# | |
13 | %# This work is made available to you under the terms of Version 2 of | |
14 | %# the GNU General Public License. A copy of that license should have | |
15 | %# been provided with this software, but in any event can be snarfed | |
16 | %# from www.gnu.org. | |
17 | %# | |
18 | %# This work is distributed in the hope that it will be useful, but | |
19 | %# WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
21 | %# General Public License for more details. | |
22 | %# | |
23 | %# You should have received a copy of the GNU General Public License | |
24 | %# along with this program; if not, write to the Free Software | |
25 | %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
26 | %# 02110-1301 or visit their web page on the internet at | |
27 | %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. | |
28 | %# | |
29 | %# | |
30 | %# CONTRIBUTION SUBMISSION POLICY: | |
31 | %# | |
32 | %# (The following paragraph is not intended to limit the rights granted | |
33 | %# to you to modify and distribute this software under the terms of | |
34 | %# the GNU General Public License and is only of importance to you if | |
35 | %# you choose to contribute your changes and enhancements to the | |
36 | %# community by submitting them to Best Practical Solutions, LLC.) | |
37 | %# | |
38 | %# By intentionally submitting any modifications, corrections or | |
39 | %# derivatives to this work, or any other work intended for use with | |
40 | %# Request Tracker, to Best Practical Solutions, LLC, you confirm that | |
41 | %# you are the copyright holder for those contributions and you grant | |
42 | %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, | |
43 | %# royalty-free, perpetual, license to use, copy, create derivative | |
44 | %# works based on those contributions, and sublicense and distribute | |
45 | %# those contributions and any derivatives thereof. | |
46 | %# | |
47 | %# END BPS TAGGED BLOCK }}} | |
48 | <& /Elements/Header, Title => $title, | |
35ef43cf | 49 | Refresh => $refresh, |
84fb5b46 MKG |
50 | LinkRel => \%link_rel &> |
51 | <& /Elements/Tabs &> | |
403d7b0b MKG |
52 | |
53 | % $m->callback( ARGSRef => \%ARGS, CallbackName => 'BeforeResults' ); | |
54 | ||
01e3b242 MKG |
55 | % unless ($ok) { |
56 | % $msg =~ s{ at .*? line .*}{}s; | |
57 | <&| /Widgets/TitleBox, title => loc("Error"), class => "error" &> | |
58 | <&|/l_unsafe, "<i>".$m->interp->apply_escapes($msg, "h")."</i>" &>There was an error parsing your search query: [_1]. Your RT admin can find more information in the error logs.</&> | |
59 | </&> | |
60 | % } else { | |
61 | ||
84fb5b46 MKG |
62 | <& /Elements/CollectionList, |
63 | Query => $Query, | |
64 | TotalFound => $ticketcount, | |
65 | AllowSorting => 1, | |
66 | OrderBy => $OrderBy, | |
67 | Order => $Order, | |
68 | Rows => $Rows, | |
69 | Page => $Page, | |
70 | Format => $Format, | |
71 | Class => 'RT::Tickets', | |
af59614d MKG |
72 | BaseURL => $BaseURL, |
73 | SavedSearchId => $ARGS{'SavedSearchId'}, | |
74 | SavedChartSearchId => $ARGS{'SavedChartSearchId'}, | |
75 | PassArguments => [qw(Query Format Rows Page Order OrderBy SavedSearchId SavedChartSearchId)], | |
76 | &> | |
01e3b242 | 77 | % } |
403d7b0b MKG |
78 | % $m->callback( ARGSRef => \%ARGS, CallbackName => 'AfterResults' ); |
79 | ||
84fb5b46 MKG |
80 | % my %hiddens = (Query => $Query, Format => $Format, Rows => $Rows, OrderBy => $OrderBy, Order => $Order, HideResults => $HideResults, Page => $Page, SavedChartSearchId => $SavedChartSearchId ); |
81 | <div align="right" class="refresh"> | |
82 | <form method="get" action="<%RT->Config->Get('WebPath')%>/Search/Results.html"> | |
83 | % foreach my $key (keys(%hiddens)) { | |
84 | <input type="hidden" class="hidden" name="<%$key%>" value="<% defined($hiddens{$key})?$hiddens{$key}:'' %>" /> | |
85 | % } | |
86 | <& /Elements/Refresh, Name => 'TicketsRefreshInterval', Default => $session{'tickets_refresh_interval'}||RT->Config->Get('SearchResultsRefreshInterval', $session{'CurrentUser'}) &> | |
87 | <input type="submit" class="button" value="<&|/l&>Change</&>" /> | |
88 | </form> | |
89 | </div> | |
90 | <%INIT> | |
91 | $m->callback( ARGSRef => \%ARGS, CallbackName => 'Initial' ); | |
92 | ||
93 | # Read from user preferences | |
94 | my $prefs = $session{'CurrentUser'}->UserObj->Preferences("SearchDisplay") || {}; | |
95 | ||
96 | # These variables are what define a search_hash; this is also | |
97 | # where we give sane defaults. | |
98 | $Format ||= $prefs->{'Format'} || RT->Config->Get('DefaultSearchResultFormat'); | |
99 | $Order ||= $prefs->{'Order'} || 'ASC'; | |
100 | $OrderBy ||= $prefs->{'OrderBy'} || 'id'; | |
101 | ||
102 | # Some forms pass in "RowsPerPage" rather than "Rows" | |
103 | # We call it RowsPerPage everywhere else. | |
104 | ||
105 | if ( !defined($Rows) ) { | |
106 | if (defined $ARGS{'RowsPerPage'} ) { | |
107 | $Rows = $ARGS{'RowsPerPage'}; | |
108 | } elsif ( defined $prefs->{'RowsPerPage'} ) { | |
109 | $Rows = $prefs->{'RowsPerPage'}; | |
110 | } else { | |
111 | $Rows = 50; | |
112 | } | |
113 | } | |
114 | $Page = 1 unless $Page && $Page > 0; | |
115 | ||
116 | my ($title, $ticketcount); | |
117 | $session{'i'}++; | |
118 | $session{'tickets'} = RT::Tickets->new($session{'CurrentUser'}) ; | |
119 | my ($ok, $msg) = $Query ? $session{'tickets'}->FromSQL($Query) : (1, "Vacuously OK"); | |
120 | # Provide an empty search if parsing failed | |
121 | $session{'tickets'}->FromSQL("id < 0") unless ($ok); | |
122 | ||
123 | if ($OrderBy =~ /\|/) { | |
124 | # Multiple Sorts | |
125 | my @OrderBy = split /\|/,$OrderBy; | |
126 | my @Order = split /\|/,$Order; | |
127 | $session{'tickets'}->OrderByCols( | |
128 | map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } } ( 0 | |
129 | .. $#OrderBy ) );; | |
130 | } else { | |
131 | $session{'tickets'}->OrderBy(FIELD => $OrderBy, ORDER => $Order); | |
132 | } | |
133 | $session{'tickets'}->RowsPerPage( $Rows ) if $Rows; | |
134 | $session{'tickets'}->GotoPage( $Page - 1 ); | |
135 | ||
136 | $session{'CurrentSearchHash'} = { | |
137 | Format => $Format, | |
138 | Query => $Query, | |
139 | Page => $Page, | |
140 | Order => $Order, | |
141 | OrderBy => $OrderBy, | |
142 | RowsPerPage => $Rows | |
143 | }; | |
144 | ||
145 | ||
146 | if ( $session{'tickets'}->Query()) { | |
147 | $ticketcount = $session{tickets}->CountAll(); | |
148 | $title = loc('Found [quant,_1,ticket]', $ticketcount); | |
149 | } else { | |
150 | $title = loc("Find tickets"); | |
151 | } | |
152 | ||
153 | my $QueryString = "?".$m->comp('/Elements/QueryString', | |
154 | Query => $Query, | |
155 | Format => $Format, | |
156 | Rows => $Rows, | |
157 | OrderBy => $OrderBy, | |
158 | Order => $Order, | |
159 | Page => $Page); | |
160 | my $ShortQueryString = "?".$m->comp('/Elements/QueryString', Query => $Query); | |
161 | ||
162 | if ($ARGS{'TicketsRefreshInterval'}) { | |
af59614d | 163 | $session{'tickets_refresh_interval'} = $ARGS{'TicketsRefreshInterval'}; |
84fb5b46 MKG |
164 | } |
165 | ||
35ef43cf MKG |
166 | my $refresh = $session{'tickets_refresh_interval'} |
167 | || RT->Config->Get('SearchResultsRefreshInterval', $session{'CurrentUser'} ); | |
168 | ||
dab09ea8 | 169 | # Check $m->request_args, not $DECODED_ARGS, to avoid creating a new CSRF token on each refresh |
35ef43cf MKG |
170 | if (RT->Config->Get('RestrictReferrer') and $refresh and not $m->request_args->{CSRF_Token}) { |
171 | my $token = RT::Interface::Web::StoreRequestToken( $session{'CurrentSearchHash'} ); | |
172 | $m->notes->{RefreshURL} = RT->Config->Get('WebURL') | |
173 | . "Search/Results.html?CSRF_Token=" | |
174 | . $token; | |
175 | } | |
176 | ||
84fb5b46 MKG |
177 | my %link_rel; |
178 | my $genpage = sub { | |
179 | return $m->comp( | |
180 | '/Elements/QueryString', | |
181 | Query => $Query, | |
182 | Format => $Format, | |
183 | Rows => $Rows, | |
184 | OrderBy => $OrderBy, | |
185 | Order => $Order, | |
186 | Page => shift(@_), | |
187 | ); | |
188 | }; | |
189 | ||
190 | if ( RT->Config->Get('SearchResultsAutoRedirect') && $ticketcount == 1 && | |
191 | $session{tickets}->First ) { | |
192 | # $ticketcount is not always precise unless $UseSQLForACLChecks is set to true, | |
193 | # check $session{tickets}->First here is to make sure the ticket is there. | |
194 | RT::Interface::Web::Redirect( RT->Config->Get('WebURL') | |
195 | ."Ticket/Display.html?id=". $session{tickets}->First->id ); | |
196 | } | |
197 | ||
198 | my $BaseURL = RT->Config->Get('WebPath')."/Search/Results.html?"; | |
199 | $link_rel{first} = $BaseURL . $genpage->(1) if $Page > 1; | |
200 | $link_rel{prev} = $BaseURL . $genpage->($Page - 1) if $Page > 1; | |
201 | $link_rel{next} = $BaseURL . $genpage->($Page + 1) if ($Page * $Rows) < $ticketcount; | |
202 | $link_rel{last} = $BaseURL . $genpage->(POSIX::ceil($ticketcount/$Rows)) if $Rows and ($Page * $Rows) < $ticketcount; | |
203 | </%INIT> | |
204 | <%CLEANUP> | |
205 | $session{'tickets'}->PrepForSerialization(); | |
206 | </%CLEANUP> | |
207 | <%ARGS> | |
208 | $Query => undef | |
209 | $Format => undef | |
210 | $HideResults => 0 | |
211 | $Rows => undef | |
212 | $Page => 1 | |
213 | $OrderBy => undef | |
214 | $Order => undef | |
215 | $SavedSearchId => undef | |
216 | $SavedChartSearchId => undef | |
217 | </%ARGS> |