<%-- 
/**
  * Copyright (c) 2004 Red Hat, Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  * USA
  *
  * Component of: Red Hat Application Server
  * 
  * Initial Developers: Aizaz Ahmed
  *                     Vivek Lakshmanan
  *                     Andrew Overholt
  *                     Matthew Wringe
  *
  */
--%>

<%@ page contentType="text/html"
         import="olstore.entity.UserLocalHome"
         import="olstore.entity.UserLocal"
         import="olstore.dto.ItemValue"
         import="olstore.dto.PictureValue"
         import="olstore.util.WebUtils"
         import="olstore.framework.EJBHomeFactory"
 %>
         
    <%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic" %>


    <jsp:include page="../nav/Header.jsp" >
        <jsp:param name="page_title" value="View All Items" />
    </jsp:include>

    <%-- remove this when the UserValue is written --%>
<%
    EJBHomeFactory factory=EJBHomeFactory.getInstance();
    UserLocalHome userHome = (UserLocalHome)factory.getLocalHome(EJBHomeFactory.USER);
    UserLocal user = userHome.findByUsername ( request.getRemoteUser() );
%>


    <!-- Content begins here -->
    <div id="form" >

    <jsp:include page="../general/Messages.jsp" />

        <logic:present name="item" >
<%
    ItemValue item = (ItemValue) request.getAttribute ( "item" );

    java.util.HashMap interestMap = new java.util.HashMap();
    interestMap.put("itemId",item.getItemId() );
    interestMap.put("interest","true");
    pageContext.setAttribute("interestMap", interestMap, PageContext.REQUEST_SCOPE);
                                                                                                                            
    java.util.HashMap purchaseMap = new java.util.HashMap();
    purchaseMap.put("itemId",item.getItemId() );
    purchaseMap.put("purchase","true");
    pageContext.setAttribute("purchaseMap", purchaseMap, PageContext.REQUEST_SCOPE);
%>

        <div class="ItemView">
<%      
        PictureValue pic = (PictureValue) request.getAttribute ( "pic" );
        if ( pic != null ) {
%>
        <html:img page="<%="/"+ pic.getLocation()%>" title="<%=pic.getText()%>" alt="<%=pic.getText()%>" />
<%      }   %>

        <div class="ImageAdj">
            <p class="label"><bean:write name="item" property="name" /></p>
            <p class="price">Price: $<span class="price"><%=WebUtils.costDisplay(item.getPrice())%></span></p><br />
            <p class="shortDesc"><bean:write name="item" property="shortDesc" /></p>


            <html:link action="/views/Item.do" name="purchaseMap" >[Purchase this Item]</html:link> <br />
            <html:link action="/views/Item.do" name="interestMap" >[Mark this Item as Interesting]</html:link> <br />
<%
            if ( user.isAdmin() ) {
%>
		<html:link action="/admin/createItem.do" paramId="itemId" paramName="item" paramProperty="itemId" > [Admin - Edit this Item] </html:link>

<%
            }
%>
            <div class="spacer" ></div>
        </div>


        <div class="details" >
            <div class="formHeader"> Details </div>
            <p class="longDesc"><bean:write name="item" property="longDesc" /></p>

            <div class="properties">
                <div class="propertiesView">
                <div class="spacer" ></div>
                <logic:iterate name="item" property="properties" id="prop" >
                    <div class="propRow">
                        <span class="label"><bean:write name="prop" property="name" /></span>
                        <span class="formw"><bean:write name="prop" property="value" /></span>
                        <div class="spacer"></div>
                    </div>
                </logic:iterate>
                <div class="spacer"></div>
                </div>
                <div class="spacer"></div>
            </div>
            <div class="spacer"></div>
        </div>



        <div class="spacer" ></div>
        </div>
    </logic:present>

    <br style="clear:both" />
    </div>
    <jsp:include page="../nav/Footer.jsp" />
