<%@ include file="/includes.jsp" %>
<%@ taglib prefix="smvc" uri="http://www.springframework.org/tags/form"%>

<br/>
<sec:authorize access="hasRole('ADMIN')">
<smvc:form action="../admin/updateRoles.form" modelAttribute="rolesForm">
	<input type="hidden" name="redirectParams" value="<c:out value="${requestScope['javax.servlet.forward.query_string']}" />" />
	<c:if test="${successMsg ne null }">
       <span class="info"><c:out value="${successMsg}"/></span><br>
    </c:if>
	<c:if test="${errorMsg ne null}">
		<div class="error"><img src="../images/16x16/error.png" alt="!"
			border="0" />&nbsp;&nbsp;<c:out value="${errorMsg}"/></div>
	</c:if>
	<table width="700">
		<tr>
			<td>
				<fieldset class="nobg" >
					<legend>Roles</legend>
					<fieldset >
						<table width="100%">
							<tr>
								<th>Name</th>
								<th>Enabled?</th>
								<th>Description</th>
							</tr>
							<c:forEach var="role" items="${rolesForm.roles }" varStatus="s">
								<tr>
									<td valign="top">
										<c:choose>
											<c:when test="${role.enabled}">
												<c:out value="${role.value}"/>
											</c:when>
											<c:otherwise>
												<s><c:out value="${role.value}"/></s>
											</c:otherwise>
										</c:choose>
									</td>
									<td valign="top">
										<c:choose>
											<c:when test="${role.value != 'ROLE_ADMIN' }">
												<smvc:select path="roles[${s.index}].enabled">
													<smvc:option value="true">Yes</smvc:option>
													<smvc:option value="false">No</smvc:option>
												</smvc:select>
											</c:when>
											<c:otherwise>
												<c:out value="${role.enabled ?'Yes' :'No' }"/>
											</c:otherwise>
										</c:choose>
									</td>
									<td><c:out value="${role.description }"/></td>
								</tr>
							</c:forEach>
						</table>
						<hr/>
						<b>Create New Role</b><br/>
						<table width="100%">
							<tr>
								<th>Name</th>
								<th>Enabled?</th>
								<th>Description</th>
							</tr>
							<tr>
								<td valign="top" align="center"><smvc:input path="newRole.value"/></td>
								<td valign="top" align="center">
									<smvc:select path="newRole.enabled">
										<option value="true">Yes</option>
										<option value="false">No</option>
									</smvc:select>
								</td>
								<td align="center"><smvc:textarea path="newRole.description"/></td>
							</tr>
						</table>
					</fieldset>
					<fieldset class="buttonFieldset">
						<input type="reset" value="Reset"/>&nbsp;<input type="submit" value="Update"/>
					</fieldset>
				</fieldset>
			</td>
		</tr>
		<tr>
			<td align="center">
				Show which Roles are used by which Users: <input type="button" value="Go" title="Go to Roles Inventory" onmouseover="this.style.cursor = cursorPointer; " onclick="location.href='../admin/rolesInventory.form?inventory=true'" />			
			</td>
		</tr>
	</table>
</smvc:form></sec:authorize>
