  [% META title = 'User &raquo; Report notification' -%]
<!-- BEGIN [% template.name %] -->
  [%
    service_email = c.cfg('settings').service_email;
    user_profile  = c.session.param('UserProfile'); # PROCESS dumper.tt dump = user_profile;
    referrer_gmc  = c.query.param('gmc') || referrer.national_code;
    # PROCESS dumper.tt dump = referrer.as_tree;
    # PROCESS dumper.tt dump = registered_user;
    # PROCESS dumper.tt dump = c.cfg('settings');
  %]

	<h2>Register for report available notifications</h2>

    [% IF NOT user_profile.email.match('@nhs.net') %]
        <div class="error">To register for report notifications you need to have
            an nhs.net address registered on HILIS.</div>
        <div class="error">Please <a href="[% app_url %]/user/change_email">change
            your email address</a> to an nhs.net address.</div>
    [% ELSIF NOT c.session.param('UserProfile').designation.match('Consultant') %]
        <div class="warning">*** this function is only suitable for consultant
            grade staff ***</div>
    [% END %]

    [% BLOCK select_status %]
		[% IF registered_user %]
		<div class="indent">
			<span class="warning">* your notifications are:</span>
			<label for="active">
				 <input type="radio" name="is_active" id="active" value="yes"
					[% IF registered_user.is_active.match('yes') %]
					   checked="checked"[% END %] /> active
			</label>
			<label for="inactive">
				 <input type="radio" name="is_active" id="inactive" value="no"
					[% IF registered_user.is_active.match('no') %]
					   checked="checked"[% END %] /> inactive
			</label>
		</div>
		[% END %]
        <div class="indent indent">
			<span class="warning">* select to receive all notifications or just
				new diagnoses:</span>
			<label for="all">
				<input type="radio" name="status" id="all" value="all"
					[% UNLESS registered_user.status.match('new') # default value %]
						checked="checked"[% END %] /> all
			</label>
			<label for="new">
				 <input type="radio" name="status" id="new" value="new"
					[% IF registered_user.status.match('new') %]
					   checked="checked"[% END %] /> new
			</label>[% site.html.go_btn %]
		</div>
    [% END %]

    <form name="[% c.query.self_url %]" method="get">
        [% IF registered_user; # already registered for notifications
            IF referrer.name.lower.match(user_profile.last_name.lower); # matches HILIS user %]
                <div class="indent info">
                    [% registered_user.name %] / [% referrer_gmc %] is
                    registered for [% registered_user.status.upper %] notifications.
                </div>
                <input type="hidden" name="confirm_identity" value="1" />
                <input type="hidden" name="gmc" value="[% referrer_gmc %]" />
                [% INCLUDE select_status %]
            [% ELSE %]
                <div class="indent warning">Your registered HILIS username does
                    not appear to correspond to the registered name for
                    [% referrer_gmc %] [[% referrer.name %]] in our
                    referrer records
                </div>
                 <div class="indent info">Please inform [% service_email %].</div>
            [% END %]
        [% ELSIF identity_confirmed %]
            <input type="hidden" name="confirm_identity" value="1" />
			<input type="hidden" name="gmc" value="[% referrer_gmc %]" />
            [% INCLUDE select_status %]
        [% ELSIF referrer; # found gmc number
            IF referrer.name.lower.match(user_profile.last_name.lower); # matches HILIS user
        %]
            <p class="indent">
                <span class="info">Please confirm your registered details are correct:</span>
                [% referrer.name %] :: [% referrer.national_code %]
                <input type="checkbox" name="confirm_identity" value="1" />
				<input type="hidden" name="gmc" value="[% referrer_gmc %]" />
                [% site.html.go_btn %]</p>
            </div>
            [% ELSE # referrer.name doesn't looks like hilis user last_name %]
            <div class="indent warning">Your registered HILIS username does not appear to
                correspond to your registered name in our referrer records:
                [% referrer.name %]</div>
            <div class="indent info">Please inform [% service_email %].</div>
            [% END %]
        [% ELSE # can't find gmc, or not yet tried %]
            [% IF referrer_gmc # can't find it: %]
                <div class="indent warning">Cannot find GMC number [% referrer_gmc %]
                    in our referrer records.</div>
                <div class="indent info">Please inform [% service_email %].</div>
            [% END %]
            [% IF user_profile.email.match('@nhs.net') %]
                <p class="info">Please enter your GMC number
                    <input type="text" name="gmc" />
                    [% site.html.go_btn %]
                </p>
            [% END %]
        [% END %]
    </form>
<!-- END [% template.name %] -->
