<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%
    com.ferienclub.admin.valueobjs.UserContainer cont = (com.ferienclub.admin.valueobjs.UserContainer)request.getSession().getAttribute("userTableDataModel");
    java.util.Iterator itor = cont.getUsers().entrySet().iterator();
%>

<html>
  <head>
   <title>Club Administration V0.1 -- Customer Administration</title>
  <script type="text/javascript">
   function enterValue(UserId)
   {
     document.forms[0].elements[0].value = UserId;
   } 
   
   function checkIn(UserId)
   {
     document.forms[0].elements[0].value = UserId;
     document.forms[0].action = "CustomerAdm.do?mode=checkIn";
     document.forms[0].submit();
   }

   function checkOut(UserId)
   {
     document.forms[0].elements[0].value = UserId;
     document.forms[0].action = "CustomerAdm.do?mode=checkOut";
     document.forms[0].submit();
   }

   function deleteUser()
   {
     document.forms[0].action = "CustomerAdm.do?mode=deleteUser";
     document.forms[0].submit();
   }

   function createUser()
   {
     document.forms[0].action = "CreateUser.do";
     document.forms[0].submit();
   }

   function userDetail()
   {
     document.forms[0].action = "CustomerAdm.do?mode=userDetail";
     document.forms[0].submit();
   }
  </script>
  </head>
<body>
 <center>
 <h1>Customer Administration</h1><br><br>
 <html:errors/></p>

 <table border="1">
   <tr><th>Select</th><th>Username</th><th>CheckIn/Out</th></tr>
   <% while (itor.hasNext())
      {
         java.util.Map.Entry entry = (java.util.Map.Entry)itor.next();
         com.ferienclub.custadmin.beans.User u = (com.ferienclub.custadmin.beans.User)entry.getKey();
         java.lang.Boolean b = ((java.lang.Boolean)entry.getValue());
	 String userName = u.getFirstName() + " " + u.getName();
         String buttonLabel = "N/A";
	 if (b != null)
         {
            if (b.booleanValue()) buttonLabel = "<input type=\"button\" value=\"Check In\" onClick=\"checkIn('" + u.getUserId() + "')\"/>";
              else buttonLabel = "<input type=\"button\" value=\"Check Out\" onClick=\"checkOut('" + u.getUserId() + "')\"/>";
         }
         %>
   <tr><td><input type="radio" name="UserChoice" value="<%= u.getUserId() %>" onClick="enterValue('<%= u.getUserId() %>')"></td><td><%= userName %></td><td><%= buttonLabel %></td></tr> 
   <%
      }  %>
 </table>
 <p>
 <input type="button" value="Delete User" onClick="deleteUser()"/>
 <input type="button" value="Create User" onClick="createUser()"/>
 <input type="button" value="User Detail" onClick="userDetail()"/>
 <html:link href="/ClubAdministration">Back to Start</html:link>

 <html:form action="CustomerAdm.do">
   <html:hidden property="userId" name="userForm"/>
 </html:form>
 </center>
</body>
</html>
