<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="js" uri="net.sourceforge.jsurveyor.jsurveyorlib" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="net.sourceforge.jsurveyor.*" %>
<jsp:useBean id="Data" class="net.sourceforge.jsurveyor.DataAccess">
</jsp:useBean>
<js:noCache />
<js:login access="admin" />
<js:border title="jSurveyor - Questionnaires">
<form action='admin_save_redirect.jsp' method='post'>
<input name='location' type='hidden' value='secondTab' />
<%
int questionnaireID = Integer.parseInt(request.getParameter("QuestionnaireID"));
Questionnaire editQ = DataAccess.retrieveQuestionnaire(questionnaireID);
User owner = (User)session.getAttribute("userInfo");
%>
<input name='QuestionnaireID' type='hidden' value='<%= editQ.getQuestionnaireID() %>' />

	<tr>
	  <td class='mainmenu_headline_unselected'><input class='tab' name='button' type='submit' value='Edit questionnaire' title='Here you can edit this questionnaire' /> <!-- <a class='tab' href='admin_questionnaire.jsp' title='Here you can edit this questionnaire'>Edit questionnaire</a> --></td>
	  <td class='mainmenu_headline' title='Here you can add and remove usergroups'>Add/remove usergroups</td>
	  <td class='mainmenu_headline_unselected'><input class='tab' name='button' type='submit' value='Activate' title='Here you can set the status of the questionnaire to active' /><!-- <a class='tab' href='admin_activate.jsp' title='Here you can set the status of the questionnaire to active'>Activate</a> --></td>

	<td class='mainmenu_headline_emptyfield'>&nbsp;</td>
	</tr>

	<tr>
	  <td colspan='4' class='mainmenu_blueframe'>
	    <table border='0' cellspacing='0' cellpadding='0'>
		  <tr>
			
		  <td class='mainmenu_inner_workframe' colspan='3'>
			If you wish to select usergroups to answer this questionnarie, please choose below. Otherwise click next.
		  </td>
		  </tr>  
		<tr>
		  <td class='mainmenu_workframe' align='center' style='width:45%;'><br />
		  Select the usergroups you want to add from here:</td>
		  <td class='mainmenu_workframe' align='center' style='width:10%;'>&nbsp;</td>
		  <td class='mainmenu_workframe' align='center' style='width:45%;'><br />The usergroups that can answer this questionnaire:</td>
		 </tr>  
		 <tr>
		   <td class='mainmenu_workframe' colspan='3'>
		    <table>
		      <tr><td> <!-- Makes space above selectboxes -->
			  </td></tr>
			</table> 
		   </td>
		 </tr>

		 <tr>
		  	<td class='mainmenu_workframe' align='center'>
		  	<select name='userGroups' size='18' style='width:90%;' title='Select usergroups' multiple>
		  	<% 
		  	ArrayList groups = owner.getAccessControl().getAdminUserGroup();
			for(int i = 0; i < groups.size(); i++) {
			
				UserGroup tempG = DataAccess.retrieveUserGroup(Integer.parseInt(((String)groups.get(i)).substring(1)));
			
			%>
				<option value='<%= tempG.getUserGroupID() %>'><%= tempG.getGroupName() %></option>
			<%
			}
		  	%>
		  	</select>  
		  	</td>
			<td class='mainmenu_inner_workframe' valign='middle'>
			<input type='submit' class='stdbutton' name='button' title='Click to add a selected usergroup from the left box' value='Add &rarr;' />  <!-- 'button' skiftes til 'submit', n�r JSPen skal k�re -->
			<br />
			<br />
			<input type='submit' class='stdbutton' name='button' title='Click to remove a selected usergroup from the right box' value='&larr; Remove' />  <!-- 'button' skiftes til 'submit', n�r JSPen skal k�re -->
			</td>
		  	<td class='mainmenu_workframe' align='center'>
		  	<select name='attechedUserGroups' size='18' style='width:90%;' title='This is the usergroups, that can answer this questionnaire' multiple>
		  	<% 
		  	ArrayList QGroups = editQ.getRefUserGroups();
			for(int i = 0; i < QGroups.size(); i++) {
			
				UserGroup tempG = DataAccess.retrieveUserGroup(Integer.parseInt(((String)QGroups.get(i)).substring(1)));
			
			%>
				<option value='<%= tempG.getUserGroupID() %>'><%= tempG.getGroupName() %></option>
			<%
			}
		  	%>
		  	</select>
			</td> 
		  </tr>
		  <tr>
		    <td class='mainmenu_workframe' colspan='3'>
			  <br />
			</td>
		  </tr>
	    </table>
      </td>
	</tr>


	<tr>
	<td>
	  <table><tr><td> <!-- Makes space between blue border and top of buttons -->
	  </td></tr>
	  </table>
	</td>
	</tr>

	<tr>
	  <td></td>
	  <td class='mainmenu_buttonline' colspan='4'><input class='stdbutton' name='button' type='submit' title='Move back to Edit questionnaire' value='Previous'/> <input class='stdbutton' name='button' type='submit' title='Move on to activate' value='Next'/> <input class='stdbutton' name='button' type='submit' title='Save this questionnaire and return to Questionnaire list page' value='Save & Exit' />
    </tr>
</form>
</js:border>