%# BEGIN LICENSE BLOCK
%# 
%#  Copyright (c) 2002-2003 Jesse Vincent <jesse@bestpractical.com>
%#  
%#  This program is free software; you can redistribute it and/or modify
%#  it under the terms of version 2 of the GNU General Public License 
%#  as published by the Free Software Foundation.
%# 
%#  A copy of that license should have arrived with this
%#  software, but in any event can be snarfed from www.gnu.org.
%# 
%#  This program 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.
%# 
%# END LICENSE 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>
