<!-- BEGIN site/request_links.tt -->
	[% # PROCESS dumper.tt dump = is_locked %]
	[% # PROCESS dumper.tt dump = data.status_option %]

	[%
        # initialise array for active links:
        all_links = [];
        # either auth not required, or authorised:
		can_view_if_reported = status_options.authorised.is_active.match('no') OR 
			( status_options.authorised.is_active.match('yes') AND history.authorised )
		? 1 : 0;
	%]

	[% IF c.user_can('view_history');
        url = app_url _ '/history/=/' _ data.id;
        link = c.html_link(url, 'History');
        all_links.push(link) %]
	[% END %]

	[% IF c.user_can('modify_results'); # AND NOT is_locked # moved to results tmpl
        url = app_url _ '/result/=/' _ data.id;
        link = c.html_link(url, 'Results');
        all_links.push(link) %]
	[% END %]

	[% PROCESS site/report_link_options.tt # Report link - complex options %]

	[% IF c.user_can('log_errors');
        url = app_url _ '/error/=/' _ data.id;
        link = c.html_link(url, 'Errors');
        all_links.push(link) %]
    [% END %]
    
	[% IF c.user_can('phone_log');
		class = has_phonelog ? 'red' : 'normal';
        url = app_url _ '/phone-log/=/' _ data.id;
        link = c.html_link(url, 'PhoneLog', class);
        all_links.push(link) %]
	[% END %]

	[% IF c.user_can('view_history');
        url = app_url _ '/image/=/' _ data.id;
        link = c.html_link(url, 'DataFiles');
        all_links.push(link) %]
	[% END %]
	
	[% IF c.user_can('view_clinical_data') AND clinical_data_link.is_elegible;
		class = clinical_data_link.has_data ? 'red' : 'normal';
        url = app_url _ '/hmrn_data/=/' _ data.id;
        link = c.html_link(url, 'HMRN', class);
        all_links.push(link) %]
	[% END %]

	[% IF c.user_can('print_one');
        link = ''; # reset - may not get a value:
        
        IF report_link.match('outreach') AND c.user_can('report'); # allowed interim report
            url = app_url _ '/request/print_record/' _ data.id;
            link = can_view_if_reported
                ? c.html_link(url, 'Print')
                : c.html_link(url, 'Interim'); # allowed to print incomplete report
        ELSIF has_optional.report; # must be reported
            IF can_view_if_reported;
                url = app_url _ '/request/print_record/' _ data.id;
                link = c.html_link(url, 'Print');
            ELSIF c.user_can('report'); # reported but not authorised:
                url = app_url _ '/request/print_draft/' _ data.id;
                link = c.html_link(url, 'Draft');
            END;
        END;
        all_links.push(link) IF link; %]
	[% END %]
	
	[% IF c.user_can('email_report') AND (
            ( has_optional.report AND can_view_if_reported ) OR
            ( report_link.match('outreach') AND c.user_can('report') )
        );
        url = app_url _ '/request/email_report/' _ data.id;
        link = c.html_link(url, 'Email');
        all_links.push(link) %]
	[% END %]
    
<p id="navbar">
	[% IF c.query.param('_return'); site.html.back_button; END %]
    
    [% IF c.is_lab_staff %]
    <span style="margin-right: 1em">
      <i>Record status:</i>
      [%
        IF is_locked;
            IF c.user_can('edit_pid');
                url = app_url _ '/request/unlock_request/' _ data.id;
                title =
                    '<img class="href" src="/images/locked.png" alt="" title="unlock record" />';
                c.html_link(url, title);
            ELSE;
                '<img src="/images/locked.png" alt="" />';
            END;
        ELSE;
            '<img src="/images/unlocked.png" alt="" />';
        END;
    %]
    </span>
    [% END %]
    
    [% all_links.join(' :: ') %]
</p>
<!-- END site/request_links.tt -->