]> git.uio.no Git - usit-rt.git/blob - share/html/Search/Results.html
0040d2a7781d0ae740fab01ebbfe271b87d6043e
[usit-rt.git] / share / html / Search / Results.html
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,
49     Refresh => $session{'tickets_refresh_interval'} || RT->Config->Get('SearchResultsRefreshInterval', $session{'CurrentUser'} ),
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
79 my $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
90 if ( !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
101 my ($title, $ticketcount);
102 $session{'i'}++;
103 $session{'tickets'} = RT::Tickets->new($session{'CurrentUser'}) ;
104 my ($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
108 if ($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
131 if ( $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
138 my $QueryString = "?".$m->comp('/Elements/QueryString',
139                                Query => $Query,
140                                Format => $Format,
141                                Rows => $Rows,
142                                OrderBy => $OrderBy,
143                                Order => $Order,
144                                Page => $Page);
145 my $ShortQueryString = "?".$m->comp('/Elements/QueryString', Query => $Query);
146
147 if ($ARGS{'TicketsRefreshInterval'}) {
148         $session{'tickets_refresh_interval'} = $ARGS{'TicketsRefreshInterval'};
149 }
150
151 my %link_rel;
152 my $genpage = sub {
153     return $m->comp(
154         '/Elements/QueryString',
155         Query   => $Query,
156         Format  => $Format,
157         Rows    => $Rows,
158         OrderBy => $OrderBy,
159         Order   => $Order,
160         Page    => shift(@_),
161     );
162 };
163
164 if ( RT->Config->Get('SearchResultsAutoRedirect') && $ticketcount == 1 &&
165     $session{tickets}->First ) {
166 # $ticketcount is not always precise unless $UseSQLForACLChecks is set to true,
167 # check $session{tickets}->First here is to make sure the ticket is there.
168     RT::Interface::Web::Redirect( RT->Config->Get('WebURL')
169             ."Ticket/Display.html?id=". $session{tickets}->First->id );
170 }
171
172 my $BaseURL = RT->Config->Get('WebPath')."/Search/Results.html?";
173 $link_rel{first} = $BaseURL . $genpage->(1)         if $Page > 1;
174 $link_rel{prev}  = $BaseURL . $genpage->($Page - 1) if $Page > 1;
175 $link_rel{next}  = $BaseURL . $genpage->($Page + 1) if ($Page * $Rows) < $ticketcount;
176 $link_rel{last}  = $BaseURL . $genpage->(POSIX::ceil($ticketcount/$Rows)) if $Rows and ($Page * $Rows) < $ticketcount;
177 </%INIT>
178 <%CLEANUP>
179 $session{'tickets'}->PrepForSerialization();
180 </%CLEANUP>
181 <%ARGS>
182 $Query => undef
183 $Format => undef 
184 $HideResults => 0
185 $Rows => undef
186 $Page => 1
187 $OrderBy => undef
188 $Order => undef
189 $SavedSearchId => undef
190 $SavedChartSearchId => undef
191 </%ARGS>