<%@ page import="oracle.jsp.webutil.personalization.Item" errorPage="error.jsp" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://xmlns.oracle.com/j2ee/jsp/tld/ojsp/personalization.tld" prefix="op" %>

<html>
<head><title>Personalization Demo</title></head>
<body>
<b><font size=+1>getCrossSellRecommendations Tag</font></b>
<p>
<%
   String inputItemList = request.getParameter("inputItemList");
   String forItem = request.getParameter("forItem");
   String itemType = request.getParameter("itemType");
   String itemListIDStrs[] = request.getParameterValues("itemListID");
   String forItemIDStrs[] = request.getParameterValues("forItemID");
   String tuningName = request.getParameter("tuningName");
   String dfltTuning = request.getParameter("dfltTuning");
   String filteringName = request.getParameter("filteringName");
   String dfltFiltering = request.getParameter("dfltFiltering");
   String sortOrder = request.getParameter("sortOrder");
   String maxQ = request.getParameter("maxQ");
   String fromHPG = request.getParameter("fromHPG");

   long[] itemIDs = null;
   Item[] items = null;
   String Dim = Item.INT_DIM_NAVIGATION;
   if( itemListIDStrs != null ) {
       itemIDs = new long[itemListIDStrs.length];
       for( int i=0; i<itemListIDStrs.length;i++) {
          try {
              itemIDs[i] = Long.parseLong(itemListIDStrs[i]);
          } catch(Exception e) {}
       }
   }

   if( inputItemList != null || forItem != null ) {
      if( inputItemList != null ) {
         items = new Item[2];
         for(int i=0; i<2; i++) {
            items[i] = new Item(itemType, itemIDs[i]);
         }
  
%>
<font color="#FF0000">Using inputItemList, elements:
<%=items[0].getID()%> ; <%=items[1].getID()%> 
</font><br>
<%
      }

      if( forItem != null ) {
         if( forItemIDStrs != null ) {
           itemIDs = new long[forItemIDStrs.length];
           for( int i=0; i<forItemIDStrs.length;i++) {
              try {
                itemIDs[i] = Long.parseLong(forItemIDStrs[i]);
              } catch(Exception e) {}
           }
         }
%>
<font color="#FF0000">Using forItem<br></font>
<%
      }
if(fromHPG!=null&& !fromHPG.equals("")) {
%>
<font color="#FF0000">Using fromHotPicksGroups<br></font>
<%}%>
</p>
<% if(dfltTuning != null && dfltFiltering != null) { %>
<op:getCrossSellRecommendations inputItemList="<%=items%>"
                                storeResultsIn="results"
                                storeInterestDimensionIn="intDim"
                                fromHotPicksGroups="<%=fromHPG%>"
                                maxQuantity="<%=maxQ%>"
                                sortOrder="<%=sortOrder%>" >
   <op:forItem type="<%=itemType%>" ID="<%=itemIDs[0]%>"/>
   <op:forItem type="<%=itemType%>" ID="<%=itemIDs[1]%>"/>
</op:getCrossSellRecommendations>
<% items = results; Dim=intDim; 
} else if(dfltTuning != null) { %>
<op:getCrossSellRecommendations inputItemList="<%=items%>"
                                storeResultsIn="results"
                                storeInterestDimensionIn="intDim"
                                fromHotPicksGroups="<%=fromHPG%>"
                                maxQuantity="<%=maxQ%>"
                                filteringName="<%=filteringName%>" 
                                sortOrder="<%=sortOrder%>" >
   <op:forItem type="<%=itemType%>" ID="<%=itemIDs[0]%>"/>
   <op:forItem type="<%=itemType%>" ID="<%=itemIDs[1]%>"/>
</op:getCrossSellRecommendations>
<% items = results; Dim=intDim; 
} else if(dfltFiltering != null) { %>
<op:getCrossSellRecommendations inputItemList="<%=items%>"
                                storeResultsIn="results"
                                storeInterestDimensionIn="intDim"
                                maxQuantity="<%=maxQ%>"
                                fromHotPicksGroups="<%=fromHPG%>"
                                tuningName="<%=tuningName%>"
                                sortOrder="<%=sortOrder%>" >
   <op:forItem type="<%=itemType%>" ID="<%=itemIDs[0]%>"/>
   <op:forItem type="<%=itemType%>" ID="<%=itemIDs[1]%>"/>
</op:getCrossSellRecommendations>
<%  items = results; Dim=intDim; 
} else { %>
<op:getCrossSellRecommendations inputItemList="<%=items%>"
                                storeResultsIn="results"
                                storeInterestDimensionIn="intDim"
                                fromHotPicksGroups="<%=fromHPG%>"
                                maxQuantity="<%=maxQ%>"
                                tuningName="<%=tuningName%>"
                                filteringName="<%=filteringName%>" 
                                sortOrder="<%=sortOrder%>" >
   <op:forItem type="<%=itemType%>" ID="<%=itemIDs[0]%>"/>
   <op:forItem type="<%=itemType%>" ID="<%=itemIDs[1]%>"/>
</op:getCrossSellRecommendations>
<%  items = results; Dim=intDim; 
} %>

<p>Here are items we found for you according to interest dimension <b><%=Dim%></b> :</p>

<table border=1>
<tr><td><b>&nbsp;Type</b></td><td><b>&nbsp;ID</b></td>
<td><b>&nbsp;Prediction</b></td></tr>
<%
for(int i=0; i<items.length; i++) {
%>
<tr><td><%=items[i].getType()%></td><td><%=items[i].getID()%></td>
<td><%=items[i].getPrediction()%></td></tr>
<%
}
%>
</table>
<hr>

<form action="tagdemodriver.jsp" method="post">
<input type="hidden" name="target" value="Return"/>
<input type="submit" name="Choose another tag" value="Choose another tag"/>
</form>

<% }
%>

<p>
<form action="getcrosssellrecommendations.jsp" method="post">
<table>

<tr><td><label><b> fromHotPicksGroups</b><input type="text" name="fromHPG" ></label>

<tr><td><b>Use inputItemList:</b> </td><td><input type="checkbox" name="inputItemList" value="true" checked/></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;<font size=-1>Item ID:</font> </td><td><input type="text" name="itemListID"/></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;<font size=-1>Item ID:</font> </td><td><input type="text" name="itemListID"/></td></tr>
<tr><td><b>Use forItem:</b> </td><td><input type="checkbox" name="forItem" value="true"/></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;<font size=-1>Item ID:</font> </td><td><input type="text" name="forItemID"/></td></tr>
<tr><td>&nbsp;&nbsp;&nbsp;<font size=-1>Item ID:</font> </td><td><input type="text" name="forItemID"/></td></tr>
<tr><td><b>Item Type:</b> </td><td><input type="text" name="itemType"/></td></tr>
<tr><td><b>Tuning Name:</b> </td><td><input type="text" name="tuningName"/>
</td><td><b> or Use Default Tuning:</b> </td><td><input type="checkbox" name="dfltTuning" value="true" /></td></tr>
<tr><td><b>Filtering Name:</b> </td><td><input type="text" name="filteringName"/></td><td><b> or Use Default Filtering:</b> </td><td><input type="checkbox" name="dfltFiltering" value="true" /></td>
</tr>
<tr><td><b>sortOrder:</b> </td><td><select name="sortOrder">
<option value="NONE">NONE</option>
<option value="">no value</option>
<option value="DESCEND">DESCEND</option>
<option value="ASCEND">ASCEND</option>
</select></td>
<td><b>maxQuantity:</b> <input type="text" size=2 name="maxQ" /> </td>
</tr>
</table>
<input type="submit" name="submit" value="Submit"/>
</form>


</body>
</html>
