%# This life is a test.  It is only a test.  Had this been an actual life,
%# you would have received further instructions as to what to do and where
%# to go.
</form><form action="index.html" method="post" enctype="multipart/form-data">
<input type="hidden" name="Queue" value="<% $Queue %>">
<input type="hidden" name="id" value="<% eval { $Parent->Id } %>">
<input type="hidden" name="Action-Upload" value="1">

  <table width="100%" border="0" cellspacing="1" cellpadding="2" bgcolor="#AAE3DE">
    <tr> 
      <td colspan="4" class="tableTitle"><nobr><&|/l&>File</&></nobr></td>
    </tr>
    <tr><td align="left" colspan="4">
	<nobr><&|/l&>File</&>:
% if ($Item) {
	<input readonly name="Filename" size=10 value="<% $Item->Filename %>">
	<input type="hidden" name="File" value="<% eval { $Transaction->Id } %>">
% } else {
	<input <% $disabled %> type="file" name="Attach" size=10>
% }
	</nobr>
	<nobr><&|/l&>Description</&>:
	<input <% $disabled %> name="Description" size=10 value="<% $Description %>"></nobr>
% if ($Item) {
	<br>
	<nobr>
	<&|/l&>Status</&>:
	<select name="FileStatus">
	    <option value="open" selected><&|/l&>uploaded</&></option>
	    <option value="deleted" selected><&|/l&>deleted</&></option>
	</select></nobr>
% }
	<input <% $disabled %> type="submit" value="<&|/l&>Submit</&>"
	    onclick="this.disabled = true; this.form.submit();">
    </td></tr>
    <tr> 
      <td colspan="4" class="tableTitle"><nobr><&|/l&>Existing Files</&></nobr></td>
    </tr>
    <tr> 
      <td class="tableTitle" width="40"><nobr><&|/l&>File Name</&></nobr></td>
      <td class="tableTitle" width="120"><nobr><&|/l&>Description</&></nobr></td>
      <td class="tableTitle" width="100"><nobr><&|/l&>Size</&></nobr></td>
    </tr>
% foreach my $item (@{$List}[$Begin .. $Begin + $Size - 1]) {
%     my $bg = (($Item and $item and $item->Id == $Item->Id) ? '#ffffcc' : 'ffffff');
    <tr bgcolor='<% $bg %>'
%     if ($item) {
	onMouseOver="this.style.backgroundColor='#D1FAFC'" 
        onMouseOut="this.style.backgroundColor='<% $bg %>'"
	style="cursor:hand" 
	onClick="MM_goToURL('self','<% $url{$item->Id} %>');return document.MM_returnValue"
%     } else { $item = $RT::Nothing }
    > 
      <td height="20">
% if ($item->Id) {
      <a style="color:black" href="<% $url{$item->Id} %>"><% $item->Filename %></a>
% }
      </td>
      <td height="20"><% $description{$item->Id} %></td>
% my $size = $item->ContentLength if $item->Id;
% $size =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g if $size;
      <td height="20" align="right"><% $size %></td>
    </tr>
% }
  </table>
<%INIT>
my $List = [];
my ($Item, $Description);
my (%url, %description);

if ($Parent) {
    my %documents;
    my $transactions = $Parent->Transactions();
    while (my $trans = $transactions->Next()) {
	my $subject = $trans->Subject;
	my $attachments = $trans->Attachments;
	$attachments->Columns( qw( Id Filename ContentType Headers ) )
	    unless $ARGS->{'Action-Upload'};
	while (my $attach = $attachments->Next()) {
	    next unless ($attach->Filename);
	    # most recent at the top
	    # unshift (@{$documents{$attach->Filename}}, $attach);
	    $documents{$attach->Filename} = $attach;
	    $description{$attach->Id} = $subject;
	    $url{$attach->Id} = "?Queue=$Queue&id=" . $Parent->Id . "&File=" . $trans->Id;
	    next unless $Transaction and $Transaction->Id == $trans->Id and !$ARGS->{'Action-Upload'};
	    $Item ||= $attach;
	    $Description ||= $subject;
	}
    }

    foreach my $key (sort keys %documents) {
	push @$List, $documents{$key};
    }
}
$Size = @$List if @$List > $Size;

my $disabled = 'disabled' unless $Parent and $Parent->Id;
</%INIT>
<%ARGS>
$Size	=> 14
$Role	=> ''
$Begin	=> 0
$IDMap	=> {}
$URL	=> ''
$ARGS	=> {}
$Parent	=> undef
$Transaction => 0
$Queue
</%ARGS>
