<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="js" uri="net.sourceforge.jsurveyor.jsurveyorlib" %>
<%@ page import="net.sourceforge.jsurveyor.*" %>
<js:noCache />
<js:login access="root" />

<c:if test="${param.Ubutton == 'Create...'}">
	<%
	session.setAttribute("create", "yes");
	response.sendRedirect("root_user_edit.jsp");
	session.setAttribute("firstLoad", "yes");
	//<jsp:forward page="root_user_edit.jsp" />
	%>
	
</c:if>

<c:if test="${param.Ubutton == 'Edit...'}">
	<%
		int count = 0;
	%>
	<c:forEach items="${paramValues.userName}" var="current">
		<%
		count++;
		%>
		<c:out value="${current}"/>
	</c:forEach> 
	<% if (count != 1 ) {
		session.setAttribute("error", "Please select one and only one user when editing.");
		session.setAttribute("errorPosition", "user");
		%>
		<c:redirect url="root_user_list.jsp" />
		<%
	}
	session.setAttribute("firstLoad", "yes");
	%>
	<jsp:forward page="root_user_edit.jsp" />
</c:if>

<c:if test="${param.Ubutton == 'Delete'}">
	%>
	<c:forEach items="${paramValues.userName}" var="current">
		<%
		String  current = (String) pageContext.getAttribute("current");
		DataAccess.deleteUser(current);
		%>
		<c:out value="${current}"/>
	</c:forEach>
	
	
	<c:redirect url="root_user_list.jsp">
	</c:redirect>
</c:if>

<c:if test="${param.Gbutton == 'Create...'}">
	<%
	session.setAttribute("firstLoad", "yes");
	%>
	<jsp:forward page="root_usergroup_edit.jsp?create=yes" />
	
</c:if>

<c:if test="${param.Gbutton == 'Edit...'}">
	<%
	int count = 0;
	%>
	<c:forEach items="${paramValues.userGroupID}" var="current">
		<%
		count++;
		%>
	</c:forEach> 
	<% if (count != 1 ) {
		session.setAttribute("error", "Please select one and only one usergroup when editing.");
		session.setAttribute("errorPosition", "usergroup");
		%>
		<c:redirect url="root_usergroup_list.jsp" />
		<%
	}
	
	session.setAttribute("firstLoad", "yes");
	%>
	<jsp:forward page="root_usergroup_edit.jsp" />
</c:if>

<c:if test="${param.Gbutton == 'Delete'}">
	<c:forEach items="${paramValues.userGroupID}" var="current">
	<%
	String  current = (String) pageContext.getAttribute("current");
	DataAccess.deleteUserGroup(Integer.parseInt(current));
	%>
	<c:out value="${current}"/>
	</c:forEach>
	<c:redirect url="root_usergroup_list.jsp">
	</c:redirect>
</c:if>
