%# 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 { $Item->Id } %>">
<input type="hidden" name="Action-Upload" value="1">

  <table width="100%" border="0" cellspacing="1" cellpadding="2" class="poptable" bgcolor="#AAE3DE">
    <tr> 
      <td colspan="4" class="tableTitle"><nobr><&|/l&>New File</&></nobr></td>
    </tr>
    <tr><td align="left" colspan="4">
	<&|/l&>File</&>: <input <% $disabled %> type="file" name="Attach"><br>
	<&|/l&>Description</&>: <input <% $disabled %> name="Description" size=10>
	<input <% $disabled %> type="submit" value="<&|/l&>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 (%url, %description);

if ($Item) {
    my %documents;
    my $transactions = $Item->Transactions();
    while (my $trans = $transactions->Next()) {
	my $attachments = $trans->Attachments;
	my $subject = $trans->Subject;
	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} = join(
		'/',
		"/Ticket/Attachment",
		$trans->Id,
		$attach->Id,
		$attach->Filename
	    );
	}
    }

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

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

