<%--
 
 * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
 * 
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 * 
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 * 
 * - Redistribution in binary form must reproduce the above
 *   copyright notice, this list of conditions and the following
 *   disclaimer in the documentation and/or other materials
 *   provided with the distribution.
 * 
 * Neither the name of Sun Microsystems, Inc. or the names of
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 * 
 * This software is provided "AS IS," without a warranty of any
 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
 * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
 * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
 * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
 * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE
 * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,
 * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF
 * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS
 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 * 
 * You acknowledge that this software is not designed, licensed or
 * intended for use in the design, construction, operation or
 * maintenance of any nuclear facility.
  
--%>

<%@ page errorPage="errorpage.jsp" %>
<%@ taglib uri="/jstl-fmt" prefix="fmt" %>
<%@ include file="parseBooks.jsp" %>

<jsp:useBean id="cart" class="cart.ShoppingCart" scope="session"/>
  
<c:if test="${!empty param.Add}">
  <x:set var="book" select="$applicationScope:booklist/books/book[@id=$param:Add]" />
  <c:set var="bid" value="${param.Add}"/>
  <c:set var="title">
    <x:out select="$book/title"/>
  </c:set>
  <c:set var="surname">
    <x:out select="$book/surname"/>
  </c:set>
  <c:set var="firstName">
    <x:out select="$book/firstname"/>
  </c:set>
  <c:set var="price">
    <x:out select="$book/price"/>
  </c:set>	
  <c:set var="year">
    <x:out select="$book/year"/>
  </c:set>
  <c:set var="description">
    <x:out select="$book/description"/>
  </c:set> 
  <c:set var="inventory">
    <x:out select="$book/inventory"/>
  </c:set>
  <jsp:useBean id="addedBook" class="database.BookDetails" scope="page" />
    <jsp:setProperty name="addedBook" property="bookId" value='<%=pageContext.getAttribute("bid")%>' />
    <jsp:setProperty name="addedBook" property="surname" value='<%=pageContext.getAttribute("surname")%>' />
    <jsp:setProperty name="addedBook" property="firstName" value='<%=pageContext.getAttribute("firstname")%>' />
    <jsp:setProperty name="addedBook" property="title" value='<%=pageContext.getAttribute("title")%>' />
    <jsp:setProperty name="addedBook" property="price" value='<%=(new Float((String)pageContext.getAttribute("price"))).floatValue()%>' />
    <jsp:setProperty name="addedBook" property="year" value='<%=(new Integer((String)pageContext.getAttribute("year"))).intValue()%>' />
    <jsp:setProperty name="addedBook" property="description" value='<%=pageContext.getAttribute("bid")%>' />
    <jsp:setProperty name="addedBook" property="inventory" value='<%=(new Integer((String)pageContext.getAttribute("inventory"))).intValue()%>' />
  </jsp:useBean >
  <jsp:useBean id="bid" class="java.lang.String" scope="page" />

  <% cart.add(bid, addedBook); %>

  <p><h3><font color="red" size="+2"> 
  <fmt:message key="CartAdded1"/> <em><x:out select="$book/title"/></em> <fmt:message key="CartAdded2"/></font></h3>
</c:if>

<c:if test="${sessionScope.cart.numberOfItems > 0}">     
  <c:url var="url" value="/showcart" >
    <c:param name="Clear" value="0" />
    <c:param name="Remove" value="0" />
  </c:url>
  <p><strong><a href="<c:out value='${url}'/>"><fmt:message key="CartCheck"/></a>&nbsp;&nbsp;&nbsp;
  <c:url var="url" value="/cashier" />
  <a href="<c:out value='${url}'/>"><fmt:message key="Buy"/></a></p></strong>
</c:if>

<br>&nbsp;
<br>&nbsp;
<h3><fmt:message key="Choose"/></h3>
<center>
<table>


  <x:forEach var="book" select="$applicationScope:booklist/books/*">     
    <tr>
    <c:set var="bookId">
      <x:out select="$book/@id"/>
    </c:set>

    <td bgcolor="#ffffaa"> 
        <c:url var="url" value="/bookdetails" >
          <c:param name="bookId" value="${bookId}" />
      		<c:param name="Clear" value="0" />
        </c:url>
        <a href="<c:out value='${url}'/>"><strong><x:out select="$book/title"/>&nbsp;</strong></a></td> 
    <td bgcolor="#ffffaa" rowspan=2> 
    <c:set var="price">
      <x:out select="$book/price"/>
    </c:set><fmt:formatNumber value="${price}" type="currency"/> 
    &nbsp;</td> 

    <td bgcolor="#ffffaa" rowspan=2> 
    <c:url var="url" value="/catalog" >
      <c:param name="Add" value="${bookId}" />
    </c:url> 
    <p><strong><a href="<c:out value='${url}'/>">&nbsp;<fmt:message key="CartAdd"/>&nbsp;</a></td></tr> 

    <tr> 
    <td bgcolor="#ffffff"> 
    &nbsp;&nbsp;<fmt:message key="By"/> <em><x:out select="$book/firstname"/>&nbsp;<x:out select="$book/surname"/></em></td></tr>
  </x:forEach>

</table>
</center>

