
    [% # INCLUDE dumper.tt dump = user_can_report %]
    <form method="post" action="[% app_url %]/admin/user/update_user_details/[% selected_user.id %]"
        [% user_details_onsubmit %] name="user_update" id="user_update">
		<!-- required field - uses same validation as 'register_new_user': -->
		<input type="hidden" name="service" value="[% c.cfg('settings').item('_centre') %]" />
		[%# need to supply param 'full_name' but validation done with lname + fname %]
		<input type="hidden" name="full_name" value="1" />
	<table>
		<tr>
			<th colspan="2">[% selected_user ? 'User details' : 'New user' %]</th>
		</tr>

        <tr>
			<td align="right">Username:</td>
			<td>
                <input type="text" name="username" value="[% selected_user.username %]" id="username"
                    [%- IF c.cfg('use_cgi_ajax') -%]
                        onChange="do_ajax(['username'], ['bad_username']); return true;"
                    [%- END -%] [% site.html.on_focus %] size="12" />
                <span class="ajax_error"><em id="bad_username"></em></span>
                [% error_username %]
            </td>
		</tr>

        <tr>
			<td align="right">First name:</td>
			<td><input type="text" name="first_name" value="[% selected_user.first_name %]"
                id="user_fname" size="12" [% site.html.on_focus %] />
                [% UNLESS error_first_name.match('already exists'); # fname + lname constraint
                    error_first_name; END %]
            </td>
		</tr>

        <tr>
			<td align="right">Last name:</td>
			<td><input type="text" name="last_name" value="[% selected_user.last_name %]"
                id="user_lname" size="12" [% site.html.on_focus %] />
                [% error_last_name %]
            </td>
		</tr>

        <tr>
			<td align="right">Password:</td>
			<td><input type="text" name="password" value="[% selected_user.password %]"
                size="35" id="user_pwd" [% site.html.on_focus %] />
                [% error_password %]
            </td>
		</tr>

        <tr>
			<td align="right">Location:</td>
			<td>
				<!--
                <input type="text" name="location" value="$profile.location" size="12" [% on_focus %] />
                -->
				<select name="user_location_id" id="user_location" [% site.html.on_focus %]>
					<option value="">&nbsp;</option>
					[% FOREACH location IN locations %]
					<option [% 'selected' IF location.id == selected_user.user_location_id %]
                        value="[% location.id %]">[% location.location_name %]</option>
					[% END %]
				</select>
                [% IF error_user_location_id %]
                    [% error_user_location_id %]
                [% ELSE %]
                  [ <a href="[% app_url %]/admin/user_location">new</a> ]
                [% END %]
            </td>
		</tr>

        <tr>
			<td align="right">Designation:</td>
			<td>
                <input type="text" name="designation" value="[% selected_user.designation %]"
                    id="user_role" size="20" [% site.html.on_focus %] />
                [% error_designation %]
            </td>
		</tr>

        <tr>
			<td align="right">E-mail:</td>
            <td><input type="text" name="email" size="35" value="[% selected_user.email %]"
                id="user_email" [% site.html.on_focus %] />
                [% error_email %]
            </td>
		</tr>

        <tr>
			<td align="right">Group:</td>
			<td>
				<select name="group_id" id="user_group" [% site.html.on_focus %]>
					<option value="">&nbsp;</option>
					[% FOREACH group IN groups %]
					<option [% 'selected' IF group.id == selected_user.group_id %]
                        value="[% group.id %]">[% group.group_label %]</option>
					[% END %]
				</select>
                [% IF error_group_id %]
                    [% error_group_id %]
                [% ELSE %]
                    [ <a href="[% app_url %]/admin/user_group">new</a> ]
                [% END %]
            </td>
		</tr>
        [% IF user_can_report;
                class = NOT user_registration_number ? 'red' : 'normal'; %]
			<td class="[% class %]" align="right">
                <span class="acronym" title="GMC or HCPC registration number">
                    GMC/HCPC</span>:
            </td>
            <td>
                <input type="text" name="reg_num" size="35" id="reg_num"
                    value="[% user_registration_number %]" [% site.html.on_focus %] />
                [% error_reg_num %]</td>
        [% END %]
        <tr>
			<td align="right">Last login:</td>
			<td>
                <input type="text" name="last_login" readonly="readonly" [% # ignored in validation %]
                    value="[% selected_user.last_login.strftime('%d.%b.%Y @ %T') %]" />
                [% IF selected_user.last_login.strftime('%T').match('00:00:00') %]
                    <span class="warning">[never]</span>
                [% ELSIF selected_user;
                    USE date; calc = date.calc; now = date.now;
                    ll = selected_user.last_login;

                    days = calc.Delta_Days(
                        ll.strftime('%Y'),
                        ll.strftime('%m'),
                        ll.strftime('%d'),
                        date.format(now, '%Y'),
                        date.format(now, '%m'),
                        date.format(now, '%d')
                    );
                %]
                    <span class="info">[% days ? ( days _ ' days ago' ) : 'today' %]</span>
                [% END %]
            </td>
        </tr>

        <tr>
			<td align="right">Active:</td>
			<td>
                [% FOREACH option IN ['yes' 'no'] %]
                <input type="radio" name="active" [% 'checked' IF selected_user.active == option %]
                    value="[% option %]" />[% option %]
                [% END %]
                [% error_active %]
            </td>
        </tr>

        <tr>
            <td colspan="2" align="center" style="border: none">
            <input type="submit" name=".submit" value="Insert/Update User" class="button" />
            [% site.html.reset %]
            </td>
        </tr>
	</table>

    </form>
