<%@ 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="admin" />

<c:if test="${param.button == 'Activate'}">
	<% 
		Questionnaire editQ = DataAccess.retrieveQuestionnaire(Integer.parseInt(request.getParameter("QuestionnaireID")));
		editQ.setActive();
		DataAccess.storeQuestionnaire(editQ);
	%>
	<c:redirect url="admin_main.jsp">
	</c:redirect>
</c:if>

<c:if test="${param.button == 'Deactivate'}">
	<% 
		Questionnaire editQ = DataAccess.retrieveQuestionnaire(Integer.parseInt(request.getParameter("QuestionnaireID")));
		DataAccess.deleteEvaluationsForQuestionnaire(editQ.getQuestionnaireID());
		editQ.setInactive();
		DataAccess.storeQuestionnaire(editQ);
	%>
	<c:redirect url="admin_main.jsp">
	</c:redirect>
</c:if>

<c:if test="${param.button == 'Create'}">
	Der blev trykket paa create... so do something
</c:if>

<c:if test="${param.button == 'Edit'}">
	<%
		int count = 0;
	%>
	<c:forEach items="${paramValues.QuestionnaireID}" var="current">
		<%
		count++;
		%>
	</c:forEach> 
	<% if (count != 1 ) {
		session.setAttribute("error", "Please select one and only one questionnaire for editing.");
		session.setAttribute("errorPosition", "questionnaire");
		%>
		<c:redirect url="admin_main.jsp" />
		<%
	}
	%>
	<jsp:forward page="admin_questionnaire.jsp" />
</c:if>

<c:if test="${param.button == 'Delete'}">
	<%
		int count = 0;
	%>
	<c:forEach items="${paramValues.QuestionnaireID}" var="current">
		<%
		count++;
		%>
	</c:forEach> 
	<% if (count == 0 ) {
		session.setAttribute("error", "Please indicate which questionnaires you wish to delete by using the checkboxes.");
		session.setAttribute("errorPosition", "questionnaire");
		%>
		<c:redirect url="admin_main.jsp" />
		<%
	}
	%>
	<jsp:forward page="admin_delete.jsp" />
</c:if>