This commit was generated by cvs2svn to compensate for changes in r9232,
[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     Collection => $session{'tickets'},
88     QueryString => $QueryString,
89     Query => $Query,
90     Format => $Format,
91     Rows => $Rows,
92     OrderBy => $OrderBy,
93     Order => $Order,
94     RSSFeedURL => $RSSFeedURL,
95     ShortQueryString => $ShortQueryString,
96 &>
97
98 % $m->callback( QueryString => $QueryString, CallbackName => 'SearchActions' );
99 </div>
100 <%INIT>
101 # Read from user preferences
102 my $prefs = $session{'CurrentUser'}->UserObj->Preferences("SearchDisplay") || {};
103
104 # These variables are what define a search_hash; this is also
105 # where we give sane defaults.
106 $Format      ||= $prefs->{'Format'} || RT->Config->Get('DefaultSearchResultFormat');
107 $Order       ||= $prefs->{'Order'} || 'ASC';
108 $OrderBy     ||= $prefs->{'OrderBy'} || 'id';
109
110 # Some forms pass in "RowsPerPage" rather than "Rows"
111 # We call it RowsPerPage everywhere else.
112
113 if ( !defined($Rows) ) {
114     if (defined $ARGS{'RowsPerPage'} ) {
115         $Rows = $ARGS{'RowsPerPage'};
116     } elsif ( defined $prefs->{'RowsPerPage'} ) {
117         $Rows = $prefs->{'RowsPerPage'};
118     } else {
119         $Rows = 50;
120     }
121 }
122 $Page = 1 unless $Page && $Page > 0;
123
124 my ($title, $ticketcount);
125 $session{'i'}++;
126 $session{'tickets'} = RT::Tickets->new($session{'CurrentUser'}) ;
127 $session{'tickets'}->FromSQL($Query) if ($Query);
128
129 if ($OrderBy =~ /\|/) {
130     # Multiple Sorts
131     my @OrderBy = split /\|/,$OrderBy;
132     my @Order = split /\|/,$Order;
133     $session{'tickets'}->OrderByCols(
134         map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } } ( 0
135         .. $#OrderBy ) );; 
136 } else {
137     $session{'tickets'}->OrderBy(FIELD => $OrderBy, ORDER => $Order); 
138 }
139 $session{'tickets'}->RowsPerPage( $Rows ) if $Rows;
140 $session{'tickets'}->GotoPage( $Page - 1 );
141
142 $session{'CurrentSearchHash'} = {
143     Format      => $Format,
144     Query       => $Query,
145     Page       => $Page,
146     Order       => $Order,
147     OrderBy     => $OrderBy,
148     RowsPerPage => $Rows
149 };
150
151
152 if ( $session{'tickets'}->Query()) {
153     $ticketcount = $session{tickets}->CountAll();
154     $title = loc('Found [quant,_1,ticket]', $ticketcount);
155 } else {
156     $title = loc("Find tickets");
157 }
158
159 my $QueryString = "?".$m->comp('/Elements/QueryString',
160                                Query => $Query,
161                                Format => $Format,
162                                Rows => $Rows,
163                                OrderBy => $OrderBy,
164                                Order => $Order,
165                                Page => $Page);
166 my $ShortQueryString = "?".$m->comp('/Elements/QueryString', Query => $Query);
167 my $RSSQueryString = "?".$m->comp('/Elements/QueryString', Query => $Query, Order => $Order, OrderBy => $OrderBy);
168 my $RSSPath  = join '/', map $m->interp->apply_escapes($_, 'u'),
169     $session{'CurrentUser'}->UserObj->Name,
170     $session{'CurrentUser'}->UserObj->GenerateAuthString( $Query.$Order.$OrderBy );
171 my $RSSFeedURL = RT->Config->Get('WebPath')."/NoAuth/rss/$RSSPath/$RSSQueryString";
172
173 if ($ARGS{'TicketsRefreshInterval'}) {
174         $session{'tickets_refresh_interval'} = $ARGS{'TicketsRefreshInterval'};
175 }
176
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 my $BaseURL = RT->Config->Get('WebPath')."/Search/Results.html?";
190 $link_rel{first} = $BaseURL . $genpage->(1)         if $Page > 1;
191 $link_rel{prev}  = $BaseURL . $genpage->($Page - 1) if $Page > 1;
192 $link_rel{next}  = $BaseURL . $genpage->($Page + 1) if ($Page * $Rows) < $ticketcount;
193 $link_rel{last}  = $BaseURL . $genpage->(POSIX::ceil($ticketcount/$Rows)) if $Rows and ($Page * $Rows) < $ticketcount;
194 </%INIT>
195 <%CLEANUP>
196 $session{'tickets'}->PrepForSerialization();
197 </%CLEANUP>
198 <%ARGS>
199 $Query => undef
200 $Format => undef 
201 $HideResults => 0
202 $Rows => undef
203 $Page => 1
204 $OrderBy => undef
205 $Order => undef
206 $SavedSearchId => undef
207 $SavedChartSearchId => undef
208 </%ARGS>