%# BEGIN BPS TAGGED BLOCK {{{
%# 
%# COPYRIGHT:
%#  
%# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC 
%#                                          <sales@bestpractical.com>
%# 
%# (Except where explicitly superseded by other copyright notices)
%# 
%# 
%# LICENSE:
%# 
%# This work is made available to you under the terms of Version 2 of
%# the GNU General Public License. A copy of that license should have
%# been provided with this software, but in any event can be snarfed
%# from www.gnu.org.
%# 
%# This work is distributed in the hope that it will be useful, but
%# WITHOUT ANY WARRANTY; without even the implied warranty of
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
%# General Public License for more details.
%# 
%# You should have received a copy of the GNU General Public License
%# along with this program; if not, write to the Free Software
%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
%# 02110-1301 or visit their web page on the internet at
%# http://www.gnu.org/copyleft/gpl.html.
%# 
%# 
%# CONTRIBUTION SUBMISSION POLICY:
%# 
%# (The following paragraph is not intended to limit the rights granted
%# to you to modify and distribute this software under the terms of
%# the GNU General Public License and is only of importance to you if
%# you choose to contribute your changes and enhancements to the
%# community by submitting them to Best Practical Solutions, LLC.)
%# 
%# By intentionally submitting any modifications, corrections or
%# derivatives to this work, or any other work intended for use with
%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
%# you are the copyright holder for those contributions and you grant
%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
%# royalty-free, perpetual, license to use, copy, create derivative
%# works based on those contributions, and sublicense and distribute
%# those contributions and any derivatives thereof.
%# 
%# END BPS TAGGED BLOCK }}}
% # THIS IS A HORRIBLE HACK TO SEE IF WE TRIED TO SEARCH
% # IT CAN GO AWAY WHEN SEARCHBUILDER'S _isLimited IS 
% # PROMOTED TO A PUBLIC API XXX TODO
% if ($articles->BuildSelectCountQuery =~ /WHERE/i) {
<h2><&|/l&>Search results</&></h2>
% if ($articles->Count){

<table width="100%" border="0" cellpadding="2" cellspacing="0">
<tr class="collection-as-table">
<th style="text-align: left" class="collection-as-table"><% $sort_link->( loc('id'), 'id') |n %></th>
<th style="text-align: left" class="collection-as-table"><% $sort_link->( loc('Name'), 'Name') |n %></th>
<th style="text-align: left" class="collection-as-table"><&|/l&>Class</&></th>
<th style="text-align: left" class="collection-as-table"><% $sort_link->( loc('Created'), 'Created') |n %></th>
<th style="text-align: left" class="collection-as-table"><% $sort_link->( loc('Modified'), 'LastUpdated') |n %></th>
</tr>
<tr class="collection-as-table">
<th class="collection-as-table"></th>
<th style="text-align: left" class="collection-as-table"><% $sort_link->( loc('Summary'), 'Summary') |n %></th>
<th style="text-align: left" class="collection-as-table" colspan="3"><&|/l&>Topics</&></th>
</tr>

% while (my $article = $articles->Next) {
%$i++;
<tr \
% if ($i%2) {
class="oddline" \
% } else {
class="evenline" \
% }
>
<td rowspan="2"><b><a href="Display.html?id=<%$article->Id%>">#<%$article->id%></a></b></td>
<td>            <b><a href="Display.html?id=<%$article->Id%>"><%$article->Name || loc('(no name)')%></a></b></td>
<td>            <%$article->ClassObj->Name%></td>
<td><small>     <%$article->CreatedObj->AgeAsString || '-'%></small></td>
<td><small>     <%$article->LastUpdatedObj->AgeAsString || '-'%></small></td>
</tr>
<tr \
% if ($i%2) {
class="oddline" \
% } else {
class="evenline" \
% }
>
<td><small>     <%$article->Summary%></small></td>
<td colspan="3"><small>
% my $Topics = $article->Topics;
% while (my $t = $Topics->Next) {
<& /RTFM/Elements/ShowTopic, topic => $t->TopicObj &><br />
% }
</small></td>
</tr>
% }
</table>
% }
% else {
<i><&|/l&>No articles found.</&></i>
% }
% }
<%init>
my $i;

my @OrderBy = $query{'OrderBy'}? @{ $query{'OrderBy'} }: ();
my @Order = $query{'Order'}? @{ $query{'Order'} }: ();

my $sort_link = sub {
    my ($title, $column) = @_;
    my $res = qq{<a href="$RT::WebPath/RTFM/Article/Search.html?};
    my $order;
    for ( grep $OrderBy[$_] eq $column, 0..$#OrderBy ) {
        $order = 'DESC' if !$Order[$_] || $Order[$_] =~ /^ASC/i;
    }
    $res .= $m->comp('/Elements/QueryString', %query, OrderBy => $column, Order => ($order || 'ASC'));

    $res .= q{">} . $m->interp->apply_escapes($title, 'h')
         . q{</a>};
    return $res;
};
</%init>
<%args>
$articles => undef
$did_search => 1
%query => ()
</%args>
