  [% META title="Images &amp; Data Files" %]
<!-- BEGIN images/default.tt -->	

  [% # PROCESS dumper.tt dump = contents %]
  [% # PROCESS dumper.tt dump = data %]
  [% # PROCESS dumper.tt dump = c.query %]
  
  <h3 class="header">Image &amp; data files for [% PROCESS site/lab_number.tt %]</h3>

  [% IF contents.images.size %]
    <p class="title">Images:</p>
  	[% FOREACH file IN contents.images;
        parts = [ data.year, mini_dir, data.request_number, file ];
        file_src = parts.join('/');
    %]
		<div class="figure">
			<div class="photo">
        <a class="image" href="/image_server/[% file_src %]" title="[% file %]">
          <img src="/image_server/[% file_src %]" alt="" width="100" height="100" />
        </a>
			</div>
      
      [% IF c.user_can('upload_data_files') %]
		<p>        
        [ <a href="[% app_url %]/image/delete/[% data.id %]/[% file %]"
            alt="delete" title="delete [% file %]"><span class="red">x</span>
        </a> ]
		</p>
      [% END %]
		</div>
    [% END %]	
    <br class="clearboth" />
  [% END %]

  [% IF contents.files.size %]
    <p class="title">Data files:</p>
    [% FOREACH file IN contents.files; # show unrestricted only unless permissions allow:
        NEXT UNLESS unrestricted.item(file) OR c.user_can('upload_data_files');
        parts = [ data.year, mini_dir, data.request_number, file ];
        file_src = parts.join('/');
    %] 
      <p class="indent">
        <a href="/image_server/[% file_src %]" target="_blank">[% file %]</a>
        [% IF c.user_can('upload_data_files');
            NEXT IF file.match('request_form') AND NOT c.user_can('delete_record');
        %]
        [ <a href="[% app_url %]/image/delete/[%data.id %]/[% file %]"
            alt="delete" title="delete file"><span class="red">x</span>
        </a> ]
        [% END %]
      </p>
    [% END %]
  [% END %]

  [% IF confirm_delete %]
	<form method="post" action="[% app_url %]/image/delete/[% data.id %]/[% marked_file %]"
        enctype="multipart/form-data">
    <p class="warning">
      Confirm you wish to permanently delete [% marked_file %]:
      <input type="checkbox" name="confirm_delete" value="1" />
      [% site.html.submit %]
    </p>
  </form>
  [% END %]

  [% IF c.user_can('upload_data_files') %]
	<form method="post" action="[% app_url %]/image/update/[% data.id %]"
        enctype="multipart/form-data">
	[% IF confirm_overwrite %]
	  <p class="warning">
		File already exists - confirm overwrite:
		<input type="checkbox" name="confirm_overwrite" value="1" />
	  </p>
		[TODO: re-display path - not available in query()]
	[% END %]
  
	[% UNLESS data.id.match('_') # disabled for pre_registration requests %]
	<p class="title">
	  [% div_name = 'new'; INCLUDE site/snippets/toggleview.tt %]
		  Upload new file
	  </p>
	[% END %]
  
	<div class="item[% confirm_overwrite ? 'visible' : 'hidden' %]" id="[% div_name %]">
      <p class="indent">
        <input type="file" name="image_file" size="30" />
        [% site.html.submit %]
      </p>
	</div>

	</form>
  [% END %]
  
  <p>[% site.html.back_button %]</p>
<!-- END images/default.tt -->
