import rt 3.6.6
[freeside.git] / rt / html / Elements / TicketList
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2007 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/copyleft/gpl.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 <table border="0" cellspacing="0" cellpadding="1" width="100%">
49
50 % if ($ShowHeader) {
51 <& /Elements/CollectionAsTable/Header, 
52     Format => \@Format, 
53     FormatString => $Format,
54     AllowSorting => $AllowSorting, 
55     Order => $Order, 
56     Query => $Query,
57     Rows => $Rows,
58     Page => $Page,
59     OrderBy => $OrderBy , 
60     BaseURL => $BaseURL,
61     maxitems => $maxitems &> 
62 % }
63
64 %   my $i;
65 %   while (my $record = $Collection->Next) {
66 %   $i++;
67 % # Every ten rows, flush the buffer and put something on the page.
68 % $m->flush_buffer() unless ($i % 10);
69 <&   /Elements/CollectionAsTable/Row, Format => \@Format, i => $i, record => $record, maxitems => $maxitems &>
70 %   }
71
72 </table>
73
74 % if ($Rows && $ShowNavigation) {
75 <hr>
76 % my $oddRows;
77 % if (($TotalFound % $Rows) == 0) {
78 % $oddRows = 0;
79 % } else { $oddRows = 1; }
80 % my $pages = int($TotalFound/$Rows)+$oddRows;
81 % $pages = 1 if $pages < 1;
82 <&|/l, $Page, $pages &>Page [_1] of [_2]</&>
83
84 <%perl>
85 my $prev = $m->comp(
86     '/Elements/QueryString',
87     Query   => $Query,
88     Format  => $Format,
89     Rows    => $Rows,
90     OrderBy => $OrderBy,
91     Order   => $Order,
92     Page    => ( $Page - 1 )
93 );
94 my $next = $m->comp(
95     '/Elements/QueryString',
96     Query   => $Query,
97     Format  => $Format,
98     Rows    => $Rows,
99     OrderBy => $OrderBy,
100     Order   => $Order,
101     Page    => ( $Page + 1 )
102 );
103 </%perl>
104 % if ($Page > 1) {
105 <a href="<%$BaseURL%><%$prev%>"><&|/l&>Previous Page</&></a>
106 % }
107 % if (($Page * $Rows) < $TotalFound) {
108 <a href="<%$BaseURL%><%$next%>"><&|/l&>Next Page</&></a>
109 % }
110 % }
111 <%INIT>
112 my $maxitems = 0;
113
114 $Format ||= $RT::DefaultSearchResultFormat;
115
116 # DisplayFormat lets us use a "temporary" format for display, while 
117 # still using our original format for next/prev page links.
118 # bulk update uses this feature to add checkboxes
119
120
121 $DisplayFormat ||= $Format;
122
123 # Scrub the html of the format string to remove any potential nasties.
124 $Format = $m->comp('/Elements/ScrubHTML', Content => $Format);
125 $DisplayFormat = $m->comp('/Elements/ScrubHTML', Content => $DisplayFormat);
126
127
128 unless ($Collection) {
129         $Collection = RT::Tickets->new($session{'CurrentUser'});
130         $Collection->FromSQL($Query);
131 }
132
133 my (@Format) = $m->comp('/Elements/CollectionAsTable/ParseFormat', Format => $DisplayFormat);
134
135 # Find the maximum number of items in any row, so we can pad the table.
136 my $item = 0;
137 foreach my $col (@Format) {
138     $item++;
139     if ( $col->{title} && ($col->{title} eq 'NEWLINE') ) {
140         $item = 0;
141     }
142     else {
143         $maxitems = $item if $item > $maxitems;
144     }
145 }
146
147 if ($OrderBy =~ /\|/) {
148     # Multiple Sorts
149     my @OrderBy = split /\|/,$OrderBy;
150     my @Order = split /\|/,$Order;
151     $Collection->OrderByCols(
152         map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } } ( 0
153         .. $#OrderBy ) );; 
154 } else {
155     $Collection->OrderBy(FIELD => $OrderBy, ORDER => $Order); 
156 }
157
158 $Collection->RowsPerPage($Rows) if ($Rows);
159 $Page = 1 unless $Page > 0; # workaround problems with Page = '' or undef
160 $Collection->GotoPage( $Page - 1 ); # SB uses page 0 as the first page
161 my $TotalFound =  $Collection->CountAll();
162
163 </%INIT>
164 <%ARGS>
165 $Query => undef
166 $Rows => 50
167 $Page => 1
168 $Title => 'Ticket Search'
169 $Collection => undef
170 $AllowSorting => undef
171 $Order => undef
172 $OrderBy => undef
173 $BaseURL => undef
174 $Format => $RT::DefaultSearchResultFormat
175 $DisplayFormat => undef
176 $ShowNavigation => 1
177 $ShowHeader => 1
178 </%ARGS>