%# A cynic is a person searching for an honest man, with a stolen lantern.
%# 		-- Edgar A. Shoaff

<& /Edit/Elements/104Header,
    Buttons => [
        Add => ( $session{CurrentUser}->HasRight(
	    Right => 'CreateReport', Object => $RTx::Reports	
	) ? "/RG/Report/index.html?Action-Add=1" : ''),
        Save => '',
        Delete => 1,
        Copy => '',
        Search => '',
        Lot => '',
        Count => '',
        Check => '',
        Import => '',
        Export => '',
        TransIn => '',
        TransOut => '',
        Info => '',
        Report => '',
        Help => '1',
    ],
    Method => 'POST',
    BGColor => '#ADD6D6',
    Top =>'/RG/Elements/Top',
&>
<& /RG/Elements/ToggleSave, no_parent => 1, toggle => 0 &>

<table width="97%" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr> 
	<td><& /RG/Elements/Tab, Text => 'Template Base' &></td>
    </tr>
    <tr><td>
      <table border="0" cellspacing="2" cellpadding="0" class="poptable" width="100%">
	<tr> 
	  <td><&|/l&>Category</&> 
	    <select name="Category" style="width:250px">
	      <option value=''><&|/l&>All</&></option>
% foreach my $type (grep length, sort keys %Categories) {
	      <option <% $Category eq $type and 'selected' %>><% $type %></option>
% }
	    </select>
	    <input type="image" border="0" name="Action-Search" src="/img/Go.png" width="23" height="19" align="middle" alt="[Go]">
	  </td>
	</tr>
      </table>
    </td></tr>
    <tr> 
	<td class="poptable" bgcolor="#C4E1F0"> 
	    <& List, Delete => 1, List => $List, Begin => $Begin, ARGS => \%ARGS &>
	</td>
    </tr>
</table>
<%INIT>
my $height = 440;
$Action = 'New' if $Action eq 'Add';
$session{PAGE} = 'File';

if ($Action eq 'Delete') {
    foreach my $Id (@ListDelete) {
	my $item = RTx::Report->new($session{'CurrentUser'});
	$item->Load( $Id );
	$item->Delete;
    }
    $Begin = 0;
}

my %Categories;
my $Reports = RTx::Reports->new($session{'CurrentUser'});
$Reports->UnLimit;
my $List = [];
while (my $report = $Reports->Next) {
    my $descr = $report->Category;
    $Categories{$descr}++ if length $descr;
    next if length $Category and $descr ne $Category;
    push @$List, $report;
}
@$List = sort { $a->Name cmp $b->Name } @$List;
</%INIT>
<%ARGS>
$Action	    => 'New'
$Begin	    => 0
$Id	    => undef
$Category   => ''
@ListDelete => ()
</%ARGS>
