[% META title="User Manager" -%]
<!-- BEGIN [% template.name %] -->

<script type="text/javascript">
  user_return = function(){
   document.getElementById('user_fname').value    = arguments[0];
   document.getElementById('user_pwd').value      = arguments[1];
   document.getElementById('user_role').value     = arguments[2];
   document.getElementById('user_email').value    = arguments[3];
   document.getElementById('user_active').value   = arguments[4];
   document.getElementById('user_location').value = arguments[5];
  }
</script>

	[% # PROCESS dumper.tt dump = user_permissions %]
	[% # PROCESS dumper.tt dump = c.stash.errs %]
	[% # PROCESS dumper.tt dump = login_count %]

    [% PROCESS admin/user_nav.tt page = 'user_list' %]

    [% user_details_dfv_js %]

	<h2>Select a registered user or create new user:</h2>

    [% IF dfv_errors %]
        <p class="error">[% c.cfg('msg').dfv_errors %]</p>
        [% IF error_full_name.match('already exists') %]
        <p class="warning">* combination of first &amp; last names already used</p>
        [% END %]
    [% END %]

    [% IF selected_user; # load GMC number field (in details.tt) if user can report:
        FOREACH function IN user_permissions;
            NEXT UNLESS function.name.match('^report$');
            IF function.selected.match(1);
                user_can_report = 1;
                LAST;
            END;
        END;
    %]
    [% IF user_can_report AND NOT user_registration_number %]
        <p class="warning">WARNING: user has reporting permissions and requires
            a GMC/HCPC registration number</p>
    [% END %]
    <p class="title">Current user permissions:
        [% class = permissions_type.match('custom') ? 'highlight' : 'maroon' %]
		<span class="[% class %]">[% permissions_type | upper %]</span> settings
        [ <a href="[% app_url %]/admin/user/edit_permissions/[% selected_user.id %]">
            change user permissions
            </a> ]
        [ <span class="maroon">[% login_count || 'no' %] logins</span> ]
        [% IF NOT login_count %][ <a href="[% app_url %]/admin/user/delete_user/[%
                selected_user.id %]">delete user</a> ][% END %]
        [ <a href="[% app_url %]/admin/user">reset/new user</a> ]
    </p>
    [% END %]

    <table>
        <tr>
            <td class="admin-user">
                [% PROCESS admin/user/list.tt %]
            </td>
            <th valign="top">OR</th>
            <td class="admin-user">
                [% PROCESS admin/user/details.tt %]
            </td>
            <td class="admin-user">
                [% PROCESS admin/user/functions.tt IF user_permissions %]
            </td>
        </tr>
    </table>
<!-- END [% template.name %] -->
