  [% META title = 'Admin &raquo; Request Audit &raquo; Options' -%]  

	[% request_audit_options_dfv_js %]

	[% PROCESS admin/request_nav.tt page = 'audit-options' %]
	
	<h2 align="center">Request Audit Options</h2>

    [% IF dfv_errors %]
        <p class="error">[% c.config('msg').dfv_errors %]</p>
    [% END %]

	[% # PROCESS dumper.tt dump = dfv_errors %]

    <p class="title">
		[% div_name = 'new'; INCLUDE site/snippets/toggleview.tt %]
		Add new entry
	</p>

	<div class="[% dfv_errors ? 'visible' : 'itemhidden' %]" id="[% div_name %]">

        <form method="get" action="[% app_url %]/config/request-audit-options/update"
            name="new_options" id="new_options" [% request_audit_options_onsubmit %]>
            <div class="indent">
                <table>
                    <tr>
                        <td class="label">Reason for Request:</td>
                        <td class="content">
							[% PROCESS site/ajax_input.tt field = 'description'
								id = "audit_options" size = 40 %]
                            [% error_description %]
                        </td>
                    </tr>
                    <tr>
                        <td class="label">Category:</td>
                        <td>
                            <select name="category_id">
                                <option value="">-- select one --</option>
                                [% FOREACH entry IN request_categories %]
                                <option value="[% entry.id %]"
                                    [% 'selected' IF entry.id == c.query.param('category_id') %]>
                                    [% entry.description | html %]
                                </option>
                                [% END %]
                            </select>
							[% IF error_category_id %]
							  [% error_category_id %]
							[% ELSE %]
							  [ <a href="[% app_url %]/config/request-audit-categories">
								new</a> ]
							[% END %]
                        </td>
                    </tr>
					<tr>
						<td class="label">Active:</td>
						<td class="content">
							<select name="active" [% site.html.onfocus %]>
							[% FOREACH option IN ['yes', 'no'] %]
							 <option value="[% option %]">[% option %]</option>
							[% END %]
							</select>
							[% error_active %]
						</td>
					</tr>
                    <tr>
                        <td class="borderless" colspan="2" align="center">[% site.html.submit %]</td>
                    </tr>
                </table>
            </div>
        </form>
    </div>
    
	<p class="spacer">&nbsp;</p>

	[% IF request_options.size # only empty if new db %]
	<div class="[% dfv_errors ? 'itemhidden' : 'visible' %]">
		[% PROCESS site/page_count.tt %]
		<table>
			<tr>
				<th></th>
				<th>
                    <a href="[% url_with_path %]?sort_by=audit_request_options.description">Reason for Request</a>
                </th>
				<th>
                    <a href="[% url_with_path %]?sort_by=audit_request_categories.description,audit_request_options.description">Category</a>
                 </th>
				<th>Active</th>
			</tr>

			[% FOREACH entry IN request_options %]
			<tr>
				<td>
                    [% IF cgi_pager; cgi_pager.first_pos_displayed + loop.count - 1; ELSE; loop.count; END %]
                </td>
				<td>
					<input type="text" size="40" name="description"
                            value="[% entry.description | html %]"
						[% site.html.disabled %] />
				</td>
				<td>
    				<input type="text" size="20" name="category"
                        value="[% entry.category.description | html %]"
                        [% site.html.disabled %] />
				</td>
				<td>
					<select name="active" [% site.html.disabled %]>
					[% FOREACH option IN ['yes', 'no'] %]
						 <option value="[% option %]" [% 'selected' IF option == entry.active %]>
							[% option %]
						</option>
					[% END %]
					</select>
				</td>
				<td align="center">
					<a href="[% app_url %]/config/request-audit-options/edit/[% entry.id %]">Edit</a>
				</td>
			 </tr>
			[% END %]

		</table>
	</div>
	[% END %]

    [% PROCESS site/cgi_pager.tt %]