[% META title = 'Request &raquo; Email Report' %]
<!-- BEGIN [% template.name %] -->
    [% # PROCESS dumper.tt dump = request.as_tree %]
    [% # PROCESS dumper.tt dump = c.stash.errs %]

    [% IF requests.size;
        INCLUDE record/multiple_patient_summary.tt;
        ELSE; INCLUDE record/patient_summary.tt; END;
    %]
    [% UNLESS c.query.param('multi_messages_sent') # don't load if multi messages sent %]
    <h3 class="header">E-mail report</h3>

    [% IF error_mailto %]
        <p class="error">[% c.cfg('msg').dfv_errors %]
            [% # c.cfg('msg').dfv_msgs.invalid_domain # allowing anon reports now %]
        </p>
    [% END %]

    [% PROCESS site/autosuggest.tt
    	varname         = 'address'
#		param_id        = '' # for callback function - not needed here
		param_name      = 'mailto'
		method_name     = 'get_email_addresses'
		watermark       = 'no';
    %]

    <script language="JavaScript" type="text/javascript">
    <!-- // Begin
     function submitForm(s) {
        s.value = "  Sending...  ";
        return true;
     }
    // End -->
    </script>

  <form method="post" action="[% app_url %]/request/do_email_report/[% request.id %]"
        onsubmit="return submitForm(this.mail_report)">
    [% DEFAULT email_type = 'individual'; # will be overridden if multi email %]
    [% FOREACH id IN c.query.param('multi_email_request_id'); email_type = 'multi' %]
        <input type="hidden" name="multi_email_request_id" value="[% id %]" />
    [% END %]
        <input type="hidden" name="email_type" value="[% email_type %]" />
        <input type="hidden" name="return_url" value="[% c.query.self_url %]" />
    [% IF require_anon_report_confirmation %]
        <p class="indent warning">
            Non-secure recipient address - OK to send anonymised report ?
            <input type="checkbox" name="anon_report_ok" value="1" />
        </p>
    [% END %]
    <div class="indent">
        <strong>Destination e-mail address:</strong>
		<input style="width: 300px" type="text" name="mailto" id="mailto"
            value="[% c.query.param('mailto') %]" />
        [% error_mailto %]
        <input type="hidden" name="sender" value="[% sender %]" />
        <input type="submit" name="mail_report" value="Go" />
        [% site.html.reset %]
        [% IF c.user_can('do_admin') AND NOT requests.size # multi-email too complex %]
            <input type="submit" name="_delete_address" value="DELETE" />
        [% END %]
    </div>
  [% END %]
  </form>
<!-- END [% template.name %] -->
