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