<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="js" uri="net.sourceforge.jsurveyor.jsurveyorlib" %>
<%@ page import="java.util.*" %>
<%@ page import="net.sourceforge.jsurveyor.*" %>
<jsp:useBean id="Data" class="net.sourceforge.jsurveyor.DataAccess">
</jsp:useBean>
<js:noCache />
<js:login access="root" />
<js:border title="jSurveyor - Users">
<form name='form' action='root_redirect.jsp' method='post'>
   <c:if test="${errorPosition == 'user'}">
	  <tr>
	<td class='mainmenu_spacer' colspan='3' align='center'><font color='red'>
	  <c:out value="${error}" />
	  </font>
	  </td>
	  </tr>
	  </c:if>
	<tr>
	  <td class='mainmenu_headline'>Users</td>
	  <td class='mainmenu_headline_unselected' title='Click to manage usergroups here'><a class='tab' href='root_usergroup_list.jsp'>Usergroups</a></td>
	  <td class='mainmenu_headline_emptyfield'>&nbsp;</td>
	</tr>
	<tr>
	  <td colspan='3' class='mainmenu_blueframe'>
	    <script language='javascript' type='text/javascript'>
		function checkall( elem ){
			var form = document.form;
			for( i  =0; i<form.length; i++ ){
				if( form.elements[ i ].type == 'checkbox' ) {
					form.elements[ i ].checked = elem.checked;
				} //end if
			} //end for
		} //end function
		</script>	
	    
	    <table border='0' cellspacing='0' cellpadding='0'>
		  <tr>
		  <td class='mainmenu_workframe'> <!-- Main workframe start -->
            <table border='0' cellspacing='0'>
			  <tr>
			  <!-- Do something about the questionnaire_top -->
			    <td class='title'  width='5%'><input type='checkbox' title='Check this box to select all users' onClick='checkall(this)'/></td>
   			    <td class='title'>Username</td>
   			    <td class='title'>Fullname</td>
			    <td class='title'>Usertype</td>
			    <td class='title'>E-mail</td>
			  </tr>
			<%
            ArrayList users = Data.retrieveAllUsers();
            String tdClass = "body_odd";
            for(int i = 0; i < users.size(); i++) {
            	tdClass = ( i%2 == 0 ) ?  "body_even" : "body_odd";
            	User tempUser = (User)users.get(i);
            %>
			  <tr>
			    <td class='<%= tdClass %>'><input type='checkbox' title='Check this box in order to edit or delete this user, using the buttons below' name='userName' value='<%= tempUser.getUserName() %>' /></td>
			    <td class='<%= tdClass %>'><a href='root_redirect.jsp?userName=<%= tempUser.getUserName() %>&Ubutton=Edit...' title='Click to edit this user'><%= tempUser.getUserName() %></a>&nbsp;</td>
			    <td class='<%= tdClass %>'><%= tempUser.getFullName() %>&nbsp;</td>
  			    <td class='<%= tdClass %>'><%= (tempUser.getAccessControl()).getUserType() %>&nbsp;</td>
			    <td class='<%= tdClass %>'><%= tempUser.getEmail() %>&nbsp;</td>
			   </tr>
            <%
            }
            %>
            </table>
            <!-- <select name='userName' style='width:100%' size='20' multiple>
            <%
            /*
            //ArrayList users = Data.retrieveAllUsers();            
            //for(int i = 0; i < users.size(); i++) {
            //	User tempUser = (User)users.get(i);
            //	out.print("<option value='" + tempUser.getUserName() + "'>" + tempUser.getUserName() + "/" + (tempUser.getAccessControl()).getUserType()+ "</option>");
            //}
            */
            %>
            </select> -->
            </td> <!-- Main workframe end -->
		  </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><input class='stdbutton'  title='Click to delete selected users' name='Ubutton' type='submit' value='Delete'/></td>
	  <td class='mainmenu_buttonline' colspan='3'><input class='stdbutton' title='Click to create a new user' name='Ubutton' type='submit' value='Create...'/> <input class='stdbutton' title='Click to edit the selected user' name='Ubutton' type='submit' value='Edit...'/></td>
    </tr>
<%
session.setAttribute("error", "");
session.setAttribute("errorPosition", "");
%>
</form>
</js:border>
