This commit was generated by cvs2svn to compensate for changes in r8690,
[freeside.git] / rt / share / html / Search / Results.html
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %# 
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 %#                                          <jesse@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     RSSAutoDiscovery => $RSSFeedURL,
51     LinkRel => \%link_rel &>
52 <& /Ticket/Elements/Tabs, 
53     current_tab => "Search/Results.html".$QueryString, 
54     Title => $title,
55     Format => $Format,
56     Query => $Query,
57     Rows => $Rows,
58     OrderBy => $OrderBy,
59     Order => $Order,
60     SavedSearchId => $SavedSearchId,
61     SavedChartSearchId => $SavedChartSearchId,
62     &>
63 <& /Elements/CollectionList, 
64     Query => $Query,
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    &>
75 % my %hiddens = (Query => $Query, Format => $Format, Rows => $Rows, OrderBy => $OrderBy, Order => $Order, HideResults => $HideResults, Page => $Page, SavedChartSearchId => $SavedChartSearchId );
76 <div align="right" class="refresh">
77 <form method="get" action="<%RT->Config->Get('WebPath')%>/Search/Results.html">
78 % foreach my $key (keys(%hiddens)) {
79 <input type="hidden" class="hidden" name="<%$key%>" value="<% defined($hiddens{$key})?$hiddens{$key}:'' %>" />
80 % }
81 <& /Elements/Refresh, Name => 'TicketsRefreshInterval', Default => $session{'tickets_refresh_interval'}||RT->Config->Get('SearchResultsRefreshInterval', $session{'CurrentUser'}) &>
82 <input type="submit" class="button" value="<&|/l&>Change</&>" />
83 </form>
84 </div>
85 <div align="right" class="search-result-actions">
86 <& Elements/ResultViews,
87     QueryString => $QueryString,
88     Query => $Query,
89     Format => $Format,
90     Rows => $Rows,
91     OrderBy => $OrderBy,
92     Order => $Order,
93     RSSFeedURL => $RSSFeedURL,
94     ShortQueryString => $ShortQueryString,
95 &>
96
97 % $m->callback( QueryString => $QueryString, CallbackName => 'SearchActions' );
98 </div>
99 <%INIT>
100 # Read from user preferences
101 my $prefs = $session{'CurrentUser'}->UserObj->Preferences("SearchDisplay") || {};
102
103 # These variables are what define a search_hash; this is also
104 # where we give sane defaults.
105 $Format      ||= $prefs->{'Format'} || RT->Config->Get('DefaultSearchResultFormat');
106 $Order       ||= $prefs->{'Order'} || 'ASC';
107 $OrderBy     ||= $prefs->{'OrderBy'} || 'id';
108
109 # Some forms pass in "RowsPerPage" rather than "Rows"
110 # We call it RowsPerPage everywhere else.
111
112 if ( !defined($Rows) ) {
113     if (defined $ARGS{'RowsPerPage'} ) {
114         $Rows = $ARGS{'RowsPerPage'};
115     } elsif ( defined $prefs->{'RowsPerPage'} ) {
116         $Rows = $prefs->{'RowsPerPage'};
117     } else {
118         $Rows = 50;
119     }
120 }
121
122 my ($title, $ticketcount);
123 $session{'i'}++;
124 $session{'tickets'} = RT::Tickets->new($session{'CurrentUser'}) ;
125 $session{'tickets'}->FromSQL($Query) if ($Query);
126
127 if ($OrderBy =~ /\|/) {
128     # Multiple Sorts
129     my @OrderBy = split /\|/,$OrderBy;
130     my @Order = split /\|/,$Order;
131     $session{'tickets'}->OrderByCols(
132         map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } } ( 0
133         .. $#OrderBy ) );; 
134 } else {
135     $session{'tickets'}->OrderBy(FIELD => $OrderBy, ORDER => $Order); 
136 }
137
138 $session{'CurrentSearchHash'} = {
139     Format      => $Format,
140     Query       => $Query,
141     Page       => $Page,
142     Order       => $Order,
143     OrderBy     => $OrderBy,
144     RowsPerPage => $Rows
145     };
146
147
148 if ( $session{'tickets'}->Query()) {
149     $ticketcount = $session{tickets}->CountAll();
150     $title = loc('Found [quant,_1,ticket]', $ticketcount);
151 } else {
152     $title = loc("Find tickets");
153 }
154
155 my $QueryString = "?".$m->comp('/Elements/QueryString',
156                                Query => $Query,
157                                Format => $Format,
158                                Rows => $Rows,
159                                OrderBy => $OrderBy,
160                                Order => $Order,
161                                Page => $Page);
162 my $ShortQueryString = "?".$m->comp('/Elements/QueryString', Query => $Query);
163 my $RSSQueryString = "?".$m->comp('/Elements/QueryString', Query => $Query, Order => $Order, OrderBy => $OrderBy);
164 my $RSSFeedURL = RT->Config->Get('WebPath')."/Search/Results.rdf$RSSQueryString";
165
166 if ($ARGS{'TicketsRefreshInterval'}) {
167         $session{'tickets_refresh_interval'} = $ARGS{'TicketsRefreshInterval'};
168 }
169
170 my %link_rel;
171 my $genpage = sub {
172     return $m->comp(
173         '/Elements/QueryString',
174         Query   => $Query,
175         Format  => $Format,
176         Rows    => $Rows,
177         OrderBy => $OrderBy,
178         Order   => $Order,
179         Page    => shift(@_),
180     );
181 };
182 my $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>