<% local data, viewlibrary, page_info, session = ... %>
<% htmlviewfunctions = require("htmlviewfunctions") %>
<% html = require("acf.html") %>

<script type="text/javascript">
	if (typeof jQuery == 'undefined') {
		document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"><\/script>');
	}
</script>

<script type="text/javascript">
	if (typeof $.tablesorter == 'undefined') {
		document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery.tablesorter.js"><\/script>');
	}
</script>

<script type="text/javascript">
	$(document).ready(function() {
		<% if data.value.groupby.value == "clientip" then %>
		$("#audit").tablesorter({headers: {0:{sorter:'ipAddress'}, 1:{sorter:'digit'}, 2:{sorter:'digit'}, 3:{sorter:'digit'}, 4:{sorter:'digit'}, 5:{sorter:'digit'}, 6:{sorter:'digit'}}, widgets: ['zebra']});
		<% else %>
		$("#audit").tablesorter({widgets: ['zebra']});
		<% end %>
	});
</script>

<% htmlviewfunctions.displaycommandresults({"completeaudit"}, session) %>

<H1>Audit Parameters</H1>
<DL>
<% htmlviewfunctions.displayitem(data.value.auditstart) %>
<% htmlviewfunctions.displayitem(data.value.auditend) %>
</DL>

<H1><%= html.html_escape(data.label) %></H1>
<DL>
<TABLE id="audit" class="tablesorter"><THEAD>
	<TR>
		<TH><% if data.value.groupby.value == "clientip" then %>Client IP<% else %>User ID<% end %></TH>
		<TH>Total Requests</TH>
		<TH>Flagged Requests</TH>
		<TH>Total Score</TH>
		<TH>Blocked</TH>
		<TH>Overridden</TH>
		<TH>Maximum Score</TH>
	</TR>
</THEAD><TBODY>
<% for i,stat in ipairs(data.value.stats.value) do %>
	<TR><TD><%= html.link{value = "viewweblog?"..data.value.groupby.value.."="..stat[data.value.groupby.value], label=stat[data.value.groupby.value]} %></TD>
	<TD><%= html.html_escape(stat.numrecords) %></TD>
	<TD><%= html.html_escape(stat.numflagged) %></TD>
	<TD><%= html.html_escape(stat.numhits) %></TD>
	<TD><%= html.html_escape(stat.numdenied) %></TD>
	<TD><%= html.html_escape(stat.numbypassed) %></TD>
	<TD><%= html.html_escape(stat.maxscore) %></TD></TR>
<% end %>
</TBODY></TABLE>

<% if data.errtxt then %>
<p class='error'><%= html.html_escape(data.errtxt) %></p>
<% end %>
<% if #data.value.stats.value == 0 then %>
<p>No flagged records, try adjusting the audit dates</p>
<% end %>

<form action="<%= html.html_escape(page_info.script .. page_info.prefix .. page_info.controller .. "/completeaudit") %>">
<DT>Complete Audit</DT>
<DD><input class="submit" type="submit" name="submit" value="Complete"></DD>
</form>
</DL>
