Made rt-shredder local.
[usit-rt.git] / share / html / Search / Results.html
CommitLineData
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',
72 BaseURL => $BaseURL
73
74 &>
01e3b242 75% }
403d7b0b
MKG
76% $m->callback( ARGSRef => \%ARGS, CallbackName => 'AfterResults' );
77
84fb5b46
MKG
78% my %hiddens = (Query => $Query, Format => $Format, Rows => $Rows, OrderBy => $OrderBy, Order => $Order, HideResults => $HideResults, Page => $Page, SavedChartSearchId => $SavedChartSearchId );
79<div align="right" class="refresh">
80<form method="get" action="<%RT->Config->Get('WebPath')%>/Search/Results.html">
81% foreach my $key (keys(%hiddens)) {
82<input type="hidden" class="hidden" name="<%$key%>" value="<% defined($hiddens{$key})?$hiddens{$key}:'' %>" />
83% }
84<& /Elements/Refresh, Name => 'TicketsRefreshInterval', Default => $session{'tickets_refresh_interval'}||RT->Config->Get('SearchResultsRefreshInterval', $session{'CurrentUser'}) &>
85<input type="submit" class="button" value="<&|/l&>Change</&>" />
86</form>
87</div>
88<%INIT>
89$m->callback( ARGSRef => \%ARGS, CallbackName => 'Initial' );
90
91# Read from user preferences
92my $prefs = $session{'CurrentUser'}->UserObj->Preferences("SearchDisplay") || {};
93
94# These variables are what define a search_hash; this is also
95# where we give sane defaults.
96$Format ||= $prefs->{'Format'} || RT->Config->Get('DefaultSearchResultFormat');
97$Order ||= $prefs->{'Order'} || 'ASC';
98$OrderBy ||= $prefs->{'OrderBy'} || 'id';
99
100# Some forms pass in "RowsPerPage" rather than "Rows"
101# We call it RowsPerPage everywhere else.
102
103if ( !defined($Rows) ) {
104 if (defined $ARGS{'RowsPerPage'} ) {
105 $Rows = $ARGS{'RowsPerPage'};
106 } elsif ( defined $prefs->{'RowsPerPage'} ) {
107 $Rows = $prefs->{'RowsPerPage'};
108 } else {
109 $Rows = 50;
110 }
111}
112$Page = 1 unless $Page && $Page > 0;
113
114my ($title, $ticketcount);
115$session{'i'}++;
116$session{'tickets'} = RT::Tickets->new($session{'CurrentUser'}) ;
117my ($ok, $msg) = $Query ? $session{'tickets'}->FromSQL($Query) : (1, "Vacuously OK");
118# Provide an empty search if parsing failed
119$session{'tickets'}->FromSQL("id < 0") unless ($ok);
120
121if ($OrderBy =~ /\|/) {
122 # Multiple Sorts
123 my @OrderBy = split /\|/,$OrderBy;
124 my @Order = split /\|/,$Order;
125 $session{'tickets'}->OrderByCols(
126 map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } } ( 0
127 .. $#OrderBy ) );;
128} else {
129 $session{'tickets'}->OrderBy(FIELD => $OrderBy, ORDER => $Order);
130}
131$session{'tickets'}->RowsPerPage( $Rows ) if $Rows;
132$session{'tickets'}->GotoPage( $Page - 1 );
133
134$session{'CurrentSearchHash'} = {
135 Format => $Format,
136 Query => $Query,
137 Page => $Page,
138 Order => $Order,
139 OrderBy => $OrderBy,
140 RowsPerPage => $Rows
141};
142
143
144if ( $session{'tickets'}->Query()) {
145 $ticketcount = $session{tickets}->CountAll();
146 $title = loc('Found [quant,_1,ticket]', $ticketcount);
147} else {
148 $title = loc("Find tickets");
149}
150
151my $QueryString = "?".$m->comp('/Elements/QueryString',
152 Query => $Query,
153 Format => $Format,
154 Rows => $Rows,
155 OrderBy => $OrderBy,
156 Order => $Order,
157 Page => $Page);
158my $ShortQueryString = "?".$m->comp('/Elements/QueryString', Query => $Query);
159
160if ($ARGS{'TicketsRefreshInterval'}) {
161 $session{'tickets_refresh_interval'} = $ARGS{'TicketsRefreshInterval'};
162}
163
35ef43cf
MKG
164my $refresh = $session{'tickets_refresh_interval'}
165 || RT->Config->Get('SearchResultsRefreshInterval', $session{'CurrentUser'} );
166
dab09ea8 167# Check $m->request_args, not $DECODED_ARGS, to avoid creating a new CSRF token on each refresh
35ef43cf
MKG
168if (RT->Config->Get('RestrictReferrer') and $refresh and not $m->request_args->{CSRF_Token}) {
169 my $token = RT::Interface::Web::StoreRequestToken( $session{'CurrentSearchHash'} );
170 $m->notes->{RefreshURL} = RT->Config->Get('WebURL')
171 . "Search/Results.html?CSRF_Token="
172 . $token;
173}
174
84fb5b46
MKG
175my %link_rel;
176my $genpage = sub {
177 return $m->comp(
178 '/Elements/QueryString',
179 Query => $Query,
180 Format => $Format,
181 Rows => $Rows,
182 OrderBy => $OrderBy,
183 Order => $Order,
184 Page => shift(@_),
185 );
186};
187
188if ( RT->Config->Get('SearchResultsAutoRedirect') && $ticketcount == 1 &&
189 $session{tickets}->First ) {
190# $ticketcount is not always precise unless $UseSQLForACLChecks is set to true,
191# check $session{tickets}->First here is to make sure the ticket is there.
192 RT::Interface::Web::Redirect( RT->Config->Get('WebURL')
193 ."Ticket/Display.html?id=". $session{tickets}->First->id );
194}
195
196my $BaseURL = RT->Config->Get('WebPath')."/Search/Results.html?";
197$link_rel{first} = $BaseURL . $genpage->(1) if $Page > 1;
198$link_rel{prev} = $BaseURL . $genpage->($Page - 1) if $Page > 1;
199$link_rel{next} = $BaseURL . $genpage->($Page + 1) if ($Page * $Rows) < $ticketcount;
200$link_rel{last} = $BaseURL . $genpage->(POSIX::ceil($ticketcount/$Rows)) if $Rows and ($Page * $Rows) < $ticketcount;
201</%INIT>
202<%CLEANUP>
203$session{'tickets'}->PrepForSerialization();
204</%CLEANUP>
205<%ARGS>
206$Query => undef
207$Format => undef
208$HideResults => 0
209$Rows => undef
210$Page => 1
211$OrderBy => undef
212$Order => undef
213$SavedSearchId => undef
214$SavedChartSearchId => undef
215</%ARGS>