<%@include file="utils.jsp"%>
<html>
<head><title>Intranet biura podróży</title></head>
<body>
<h1>Intranet biura podróży</h1>
<table>
<%
URL rpcRouter = new URL(request.getParameter("rpcrouter"));
String stStart = request.getParameter("start"),
       stEnd = request.getParameter("end");
Vector params = null;
if(stStart != null && stEnd != null) {
    params = new Vector();
    DateFormat dateFormat =
         DateFormat.getDateInstance(DateFormat.MEDIUM,Locale.US);
    dateFormat.setLenient(true);
    try {
        Date start = dateFormat.parse(stStart),
             end = dateFormat.parse(stEnd);
        params.addElement(new Parameter("start",
                                        Date.class,start,null));
        params.addElement(new Parameter("end",
                                        Date.class,end,null));
    }
    catch(java.text.ParseException e) {
        params = null;
    }
}
Response rsp = null;
if(params == null) {
    rsp = rpcCall(rpcRouter,"getAllResources",null);
%>
<tr><td colspan="3">Wszystkie pomieszczenia, niezależnie od dostępności.</td></tr>
<%
}
else {
    rsp = rpcCall(rpcRouter,"getFreeResourcesOn",params);
%>
<tr><td colspan="3">Pomieszczenia dostępne od <%= stStart %>
    do <%= stEnd %>.</tr></td>
<%
}
if(!rsp.generatedFault()) {
    Resource[] resources =
        (Resource[])rsp.getReturnValue().getValue();
    for(int i = 0;i < resources.length;i++) {
%>
   <tr><td valign="top"><form action="book.jsp" method="post">
         <input type="hidden" name="resource"
          value="<%= resources[i].getName() %>">
         <input type="hidden" name="rpcrouter"
          value="<%= rpcRouter.toExternalForm() %>">
         <input type="hidden" name="start" value="<%= stStart %>">
         <input type="hidden" name="end" value="<%= stEnd %>">
         <input type="submit" value="Zarezerwuj"></form></td>
      <td valign="top"
        bgcolor="#bbbbbb"><%= resources[i].getName() %></td>
      <td valign="top"><%= resources[i].getDescription() %></td>
   </tr>
<%
    }
}
else {
    Fault fault = rsp.getFault();
%>
<tr><td>Error:</td><td><%= fault.getFaultString() %></td></tr>
<tr><td>Code:</td><td><%= fault.getFaultCode() %></td></tr>
<%
}
%>
</table>
</body>
</html>
