<%@ include file="/includes.jsp"%>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>
<jsp:useBean id="auditLogSearchPD" class="com.ardeo.util.PaginationData" scope="session" />
<c:if test="${param.pageSize != null}">
	<jsp:setProperty name="auditLogSearchPD" property="pageSize"  value="${param.pageSize}" />
</c:if>
<jsp:setProperty name="auditLogSearchPD" property="size"  value="${fn:length(auditLogDTO.auditLogRecords)}" />
<c:choose>
	<c:when test="${param.page != null}">
		<jsp:setProperty name="auditLogSearchPD" property="currentPage"  value="${param.page}" />
	</c:when>
	<c:otherwise>
		<jsp:setProperty name="auditLogSearchPD" property="currentPage" value="1" />
	</c:otherwise>
</c:choose>

<script src="../js/jquery/jquery-3.7.1.min.js"></script>
<script>
function changePageSize(el) {
		document.location = '../emdt/patientAuditLog.jsp?pageSize=' + el.options[el.selectedIndex].value;
 }
</script>
<smvc:form name="patientAuditLog" modelAttribute="auditLogDTO" method="post" onsubmit="return submitTheForm();" action="../emdt/patientAuditLog.form">
	<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
	<br />

	<div id="audit" class="auditTitle">Patient Audit Log: '<c:out value="${emdt.patient.forename}"/>&nbsp;&nbsp;<c:out value="${emdt.patient.surname}"/>'</div>


	<c:choose>
		<c:when test="${(fn:length(auditLogDTO.auditLogRecords) gt 0)}">

			<div class="auditNavigation" style="text-align: right; margin-top: 0; margin-bottom: 4px;">
				Page <c:out value="${auditLogSearchPD.currentPage }"/> of <c:out value="${auditLogSearchPD.numberOfPages }"/>
				<c:choose>
					<c:when test="${auditLogSearchPD.previousPageNum != null}">
						<a title="Previous Page" href="patientAuditLog.jsp?page=<c:out value="${auditLogSearchPD.previousPageNum}"/>"><img src="../images/16x16/action_back.png" /></a>
					</c:when>
					<c:otherwise>
						<img src="../images/16x16/action_back_disabled.png" />
					</c:otherwise>
				</c:choose>
				<c:choose>
					<c:when test="${auditLogSearchPD.nextPageNum != null}">
						<a title="Next Page" href="patientAuditLog.jsp?page=<c:out value="${auditLogSearchPD.nextPageNum}"/>"><img src="../images/16x16/action_forward.png" /></a>
					</c:when>
					<c:otherwise>
						<img src="../images/16x16/action_forward_disabled.png" />
					</c:otherwise>
				</c:choose>
			</div>

			<table class="auditResults">
				<tr>
					<th>Date and Time</th>
					<th>Event</th>
					<th>User</th>
					<th>Message</th>
					<th>Severity</th>
				</tr>
				<c:forEach items="${auditLogDTO.auditLogRecords}" var="auditLogRecord" varStatus="s" begin="${auditLogSearchPD.startOfPageIndex}" end="${auditLogSearchPD.endOfPageIndex}">
					<tr>
						<td width="120px"><c:out value="${auditLogRecord.dateOfAction}"/>&nbsp;<c:out value="${auditLogRecord.timeOfAction}"/></td>
						<td><c:out value="${auditLogRecord.auditAction}"/></td>
						<td><c:out value="${auditLogRecord.auditUserFullName}"/></td>
						<td><c:out value="${auditLogRecord.auditMessage}"/></td>

						<c:if test="${auditLogRecord.alertType eq 'Info'}">
							<td><img src="../emdt/images/Circle-Info.png" width="23px" />&nbsp;<c:out value="${auditLogRecord.alertType}"/></td>
						</c:if>
						<c:if test="${auditLogRecord.alertType eq 'Error'}">
							<td><img src="../emdt/images/Circle_Red.png" width="23px" />&nbsp;<c:out value="${auditLogRecord.alertType}"/></td>
						</c:if>
						<c:if test="${auditLogRecord.alertType eq 'Warning'}">
							<td><img src="../emdt/images/Circle_Yellow.png" width="23px" />&nbsp;<c:out value="${auditLogRecord.alertType}"/></td>
						</c:if>
					</tr>
				</c:forEach>
			</table>

			<table class="auditNavigation">
				<tr>
					<td align="left">Show <select name="selectPageSize" onchange="changePageSize(this)">
							<webapp:option value="10" currentValue="${auditLogSearchPD.pageSize }">10</webapp:option>
							<webapp:option value="20" currentValue="${auditLogSearchPD.pageSize }">20</webapp:option>
							<webapp:option value="50" currentValue="${auditLogSearchPD.pageSize }">50</webapp:option>
							<webapp:option value="100" currentValue="${auditLogSearchPD.pageSize }">100</webapp:option>
							<webapp:option value="${auditLogSearchPD.size }" currentValue="${auditLogSearchPD.pageSize }">All</webapp:option>
					</select> items per page
					</td>
					<td align="right" width="100">Page<c:out value=" ${auditLogSearchPD.currentPage }"/> of <c:out value="${auditLogSearchPD.numberOfPages }"/></td>
					<td width="1"><c:choose>
							<c:when test="${auditLogSearchPD.previousPageNum != null}">
								<a title="Previous Page" href="patientAuditLog.jsp?page=<c:out value="${auditLogSearchPD.previousPageNum}"/>"><img src="../images/16x16/action_back.png" /></a>
							</c:when>
							<c:otherwise>
								<img src="../images/16x16/action_back_disabled.png" />
							</c:otherwise>
						</c:choose></td>
					<td width="1" align="right"><c:choose>
							<c:when test="${auditLogSearchPD.nextPageNum != null}">
								<a title="Next Page" href="patientAuditLog.jsp?page=<c:out value="${auditLogSearchPD.nextPageNum}"/>"><img src="../images/16x16/action_forward.png" /></a>
							</c:when>
							<c:otherwise>
								<img src="../images/16x16/action_forward_disabled.png" />
							</c:otherwise>
						</c:choose></td>
				</tr>
			</table>

		</c:when>

		<c:otherwise>
			<br />
			<br />
			<c:choose>
				<c:when test="${requestScope.errorMsg != null and fn:length(requestScope.errorMsg) != 0}">
					<div class="dialogBox" style="height: 50px; width: 420px; color: red;">
						<br /> <img src="../images/16x16/error.png" alt="i" />&nbsp;${requestScope.errorMsg}<br /> <br />
					</div>
				</c:when>
				<c:otherwise>
					<br />
					<br />
					<div class="dialogBox" style="height: 80px; width: 420px;">
						<br> <br> <img src="../images/16x16/information.png" alt="i" /> <b>No audit events for patient <c:out value="${emdt.patient.forename}"/>&nbsp;&nbsp;<c:out value="${emdt.patient.surname}"/></b>
					</div>
				</c:otherwise>
			</c:choose>
		</c:otherwise>
	</c:choose>

	<br />
	<br />
</smvc:form>

