1 %# false laziness with Results.html; basically this is the same thing but with
2 %# a hardcoded RT::Tickets object instead of a Query param
4 <& /Elements/Header, Title => $title,
6 LinkRel => \%link_rel &>
8 % $m->callback( ARGSRef => \%ARGS, Format => \$Format, CallbackName => 'BeforeResults' );
10 <& /Elements/CollectionList,
11 Class => 'RT::Tickets',
12 Collection => $session{tickets},
13 TotalFound => $ticketcount,
21 SavedSearchId => $ARGS{'SavedSearchId'},
22 SavedChartSearchId => $ARGS{'SavedChartSearchId'},
23 PassArguments => [qw(Format Rows Page Order OrderBy SavedSearchId SavedChartSearchId)],
25 % $m->callback( ARGSRef => \%ARGS, CallbackName => 'AfterResults' );
27 % my %hiddens = (Format => $Format, Rows => $Rows, OrderBy => $OrderBy, Order => $Order, HideResults => $HideResults, Page => $Page, SavedChartSearchId => $SavedChartSearchId );
28 <div align="right" class="refresh">
29 <form method="get" action="<%RT->Config->Get('WebPath')%>/Search/UnrepliedTickets.html">
30 % foreach my $key (keys(%hiddens)) {
31 <input type="hidden" class="hidden" name="<%$key%>" value="<% defined($hiddens{$key})?$hiddens{$key}:'' %>" />
33 <& /Elements/Refresh, Name => 'TicketsRefreshInterval', Default => $session{'tickets_refresh_interval'}||RT->Config->Get('SearchResultsRefreshInterval', $session{'CurrentUser'}) &>
34 <input type="submit" class="button" value="<&|/l&>Change</&>" />
38 $m->callback( ARGSRef => \%ARGS, CallbackName => 'Initial' );
40 # Read from user preferences
41 my $prefs = $session{'CurrentUser'}->UserObj->Preferences("SearchDisplay") || {};
43 # These variables are what define a search_hash; this is also
44 # where we give sane defaults.
45 $Format ||= $prefs->{'Format'} || RT->Config->Get('DefaultSearchResultFormat');
46 $Order ||= $prefs->{'Order'} || RT->Config->Get('DefaultSearchResultOrder');
47 $OrderBy ||= $prefs->{'OrderBy'} || RT->Config->Get('DefaultSearchResultOrderBy');
49 # In this case the search UI isn't available, so trust the defaults.
51 # Some forms pass in "RowsPerPage" rather than "Rows"
52 # We call it RowsPerPage everywhere else.
54 if ( defined $prefs->{'RowsPerPage'} ) {
55 $Rows = $prefs->{'RowsPerPage'};
59 $Page = 1 unless $Page && $Page > 0;
61 use RT::Search::UnrepliedTickets;
64 $session{'tickets'} = RT::Tickets->new($session{'CurrentUser'}) ;
65 my $search = RT::Search::UnrepliedTickets->new( TicketsObj => $session{'tickets'} );
68 if ($OrderBy =~ /\|/) {
70 my @OrderBy = split /\|/,$OrderBy;
71 my @Order = split /\|/,$Order;
72 $session{'tickets'}->OrderByCols(
73 map { { FIELD => $OrderBy[$_], ORDER => $Order[$_] } } ( 0
76 $session{'tickets'}->OrderBy(FIELD => $OrderBy, ORDER => $Order);
78 $session{'tickets'}->RowsPerPage( $Rows ) if $Rows;
79 $session{'tickets'}->GotoPage( $Page - 1 );
81 # use this to set a CSRF token applying to the search, so that the user can come
82 # back to this page without triggering a referrer check
83 $session{'CurrentSearchHash'} = {
92 my $ticketcount = $session{tickets}->CountAll();
93 my $title = loc('New activity on [quant,_1,ticket,tickets]', $ticketcount);
95 # pass this through on pagination links
96 my $QueryString = "?".$m->comp('/Elements/QueryString',
103 if ($ARGS{'TicketsRefreshInterval'}) {
104 $session{'tickets_refresh_interval'} = $ARGS{'TicketsRefreshInterval'};
107 my $refresh = $session{'tickets_refresh_interval'}
108 || RT->Config->Get('SearchResultsRefreshInterval', $session{'CurrentUser'} );
110 # Check $m->request_args, not $DECODED_ARGS, to avoid creating a new CSRF token on each refresh
111 if (RT->Config->Get('RestrictReferrer') and $refresh and not $m->request_args->{CSRF_Token}) {
112 my $token = RT::Interface::Web::StoreRequestToken( $session{'CurrentSearchHash'} );
113 $m->notes->{RefreshURL} = RT->Config->Get('WebURL')
114 . "Search/UnrepliedTickets.html?CSRF_Token="
121 '/Elements/QueryString',
130 if ( RT->Config->Get('SearchResultsAutoRedirect') && $ticketcount == 1 &&
131 $session{tickets}->First ) {
132 # $ticketcount is not always precise unless $UseSQLForACLChecks is set to true,
133 # check $session{tickets}->First here is to make sure the ticket is there.
134 RT::Interface::Web::Redirect( RT->Config->Get('WebURL')
135 ."Ticket/Display.html?id=". $session{tickets}->First->id );
138 my $BaseURL = RT->Config->Get('WebPath')."/Search/UnrepliedTickets.html?";
139 $link_rel{first} = $BaseURL . $genpage->(1) if $Page > 1;
140 $link_rel{prev} = $BaseURL . $genpage->($Page - 1) if $Page > 1;
141 $link_rel{next} = $BaseURL . $genpage->($Page + 1) if ($Page * $Rows) < $ticketcount;
142 $link_rel{last} = $BaseURL . $genpage->(POSIX::ceil($ticketcount/$Rows)) if $Rows and ($Page * $Rows) < $ticketcount;
145 $session{'tickets'}->PrepForSerialization();
153 $SavedSearchId => undef
154 $SavedChartSearchId => undef