<!--
 * BISalesAnalysis.jsp
 *
 * Copyright © 1994-2004, Oracle. All rights reserved. Oracle grants
 * you ("Licensee") a non-exclusive, royalty-free, worldwide license to use,
 * modify and redistribute this software in source and binary code form, provided
 * that (i) this copyright notice and license appear on all copies of the
 * software; (ii) Licensee does not utilize the software in a manner disparaging
 * to Oracle; and (iii) Licensee does not utilize the software in a manner that
 * violates the terms of any Licensee agreement with Oracle.
 -->

<%@ taglib uri="http://xmlns.oracle.com/bibeans/jsp" prefix="orabi" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ page errorPage="cabo/bi/jsp/error.jsp" %>
<%@ page contentType="text/html;charset=windows-1252"%>

<%@ page import="oracle.dss.dataSource.client.QueryClient"%>
<%@ page import="oracle.dss.graph.Graph"%>
<%@ page import="oracle.dss.selection.Selection"%>
<%@ page import="oracle.dss.selection.step.FamilyLevelStep"%>
<%@ page import="oracle.dss.selection.step.MemberStep"%>
<%@ page import="oracle.dss.thin.beans.dataView.Presentation" %>
<%@ page import="oracle.dss.thin.beans.graph.ThinGraph" %>
<%@ page import="oracle.dss.util.DataAccess"%>
<%@ page import="oracle.dss.util.DataDirector"%>
<%@ page import="oracle.dss.util.DataMap"%>
<%@ page import="oracle.dss.util.MetadataMap"%>
<%@ page import="modeling.ZoomExecutor"%>

<jsp:useBean id="zoomExecutor1" scope="session" class="modeling.ZoomExecutor"></jsp:useBean><%-- Start synchronization of the BI tags --%>

<!-- Start synchronization of the BI tags -->
<% synchronized(session){ %>
<orabi:BIThinSession id="bisession1"  configuration="/executiveInsightOLAPConfig1.xml" >
  <!--  Business Intelligence definition tags here -->
  <orabi:Presentation pagingControlVisible="False" location="Local Computer Sales/Sales Analysis/Bubble Graph" id="BISalesAnalysis_pres1" imageHeight="250" imageWidth="700"/>
  <orabi:Presentation imageHeight="250" pagingControlVisible="False" location="Local Computer Sales/Sales Analysis/Forecast Graph" imageWidth="700" id="BISalesAnalysis_pres2"/>
  <orabi:PageList id="pageList1"/>
  <orabi:MeasureList targetPresentationIds="BISalesAnalysis_pres2" multiSelect="True" 
  measures="Electronics - Trend Calculations/Revenue;Electronics - Trend Calculations/Revenue 6 Mo MV Avg;Electronics - Trend Calculations/Revenue 12 Mo MV Avg;Electronics - Trend Calculations/Revenue Fcst Linear;Electronics - Trend Calculations/Revenue Fcst Non-Linear;Electronics - Trend Calculations/Revenue Fcst Exponential;Electronics - Trend Calculations/Revenue Fcst Trend;Electronics - Trend Calculations/Revenue Fcst Seasonal;Electronics - Trend Calculations/Revenue Fcst Best Fit;" id="BISalesAnalysis_measureList1" itemLabelFormat="__SHORT__"/>
  <orabi:CascadingDimensionMemberList targetPresentationIds="BISalesAnalysis_pres1;BISalesAnalysis_pres2" multiSelectLevels="MDM!D_CS_OLAP.SHAWPRODUCTS.PRODUCTS.L.PRODUCT" hierarchy="MDM!D_CS_OLAP.SHAWPRODUCTS.PRODUCTS" applyLevels="MDM!D_CS_OLAP.SHAWPRODUCTS.PRODUCTS.L.PRODUCT" levels="MDM!D_CS_OLAP.SHAWPRODUCTS.PRODUCTS.L.CATEGORY;MDM!D_CS_OLAP.SHAWPRODUCTS.PRODUCTS.L.PRODUCT" dimension="MDM!D_CS_OLAP.SHAWPRODUCTS" id="BISalesAnalysis_cascDimMems1" partialTargets="ForecastRegion" />
</orabi:BIThinSession>

<% 
  // Retrieve the two Graphs from the page context
  Presentation graph1 = (Presentation)pageContext.findAttribute("BISalesAnalysis_pres1");
  Presentation graph2 = (Presentation)pageContext.findAttribute("BISalesAnalysis_pres2");

  ThinGraph bubbleGraph = (ThinGraph)graph1.getView();
  ThinGraph forecastGraph = (ThinGraph)graph2.getView();

  // Set the URLs on the bubbles in the Graph
  DataAccess da = bubbleGraph.getModel().getDataAccess();
  int count = da.getEdgeExtent(DataDirector.ROW_EDGE);
  
  // Clicking on a Graph bubble will submit a BUBBLE_EVENT with the information about the bubble
  for (int row=0; row < count; row++)
  {
    String memberValue = (String)da.getMemberMetadata(DataDirector.ROW_EDGE, 0, row, MetadataMap.METADATA_VALUE);
    bubbleGraph.setImagemapAction(Graph.DATAMARKER, row, 0, "javascript:submitForm(0,0,{'event':'BUBBLE_EVENT', 'bubble':'" + row + "', 'PROD':'" + memberValue + "'});void(0);");
  }
 
  // ----- Process the zoom/reset events -----
  // Get the value of 'event' Parameter from the request object   
  String event = request.getParameter("event"); 
  
  // Retrieve the parameters from request
  String product = request.getParameter("PROD");
  String bubble = request.getParameter("bubble"); 
  String zoom = request.getParameter("zoom");
  int zoomStatus = (zoom != null && zoom.length() > 0)? Integer.parseInt(zoom) : ZoomExecutor.ZOOM_OFF;
  int bubbleSlice = (bubble != null && bubble.length() > 0)? Integer.parseInt(bubble) : 0;
  zoomExecutor1.setCurrentBubble(bubbleSlice);
  zoomExecutor1.setZoomStatus(zoomStatus);

  if (event != null) 
  {
    // This event will appear if the user clicked on a bubble of the Graph
    if (event.equals("BUBBLE_EVENT"))
    {  
      if (zoomStatus != ZoomExecutor.ZOOM_OFF)
      {
        // If zooming is on, zoom the graph
        zoomExecutor1.setZoom(bubbleGraph, bubbleSlice);
      } 
      else
      {
        // Zooming is off. Update the forecast graph to 
        // show data for the clicked product bubble
        zoomExecutor1.updateGraphProductSelection(forecastGraph, product);
      }
    }
    // This event will appear if the user pressed Reset button to reset Graph zoom
    else if (event.equals("RESET_EVENT"))
    {
      zoomExecutor1.resetGraphAxis(bubbleGraph);
    }
  }
%>


<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>
      Sales Growth and Margin Analysis
    </title>
  </head>

  <orabi:BIBody>
    <form name="BIForm" method="POST"  action="BISalesAnalysis.jsp" >
      <orabi:InitBITags parentForm="BIForm"/>
      <table cellspacing="2" cellpadding="3" border="0">
        <tr>
          <td>
            <img src="images/developer1.gif" width="180" height="40"/>
          </td>
          <td>
            <img src="images/SalesMarginAnalysis.gif" width="468" height="60" alt="Sales Growth and Margin Analysis"/>
          </td>
          <td>
            <table>
              <!--BI_TAGS_METADATA llt;;1;;dtn;;PageList;;dti;;pageList1;;lgfdv;;2;;llissbc;;_EMP_VAL_;;ldlib;;false;;lscm;;1;;lhvs;;_EMP_VAL_;;llp;;1;;lscil;;_EMP_VAL_;;llv;;_EMP_VAL_;;llibc;;_EMP_VAL_;;lti;;DEFAULT;;lrt;;10;;lgfd;;1;;lsct;;_L_T_D_;;llilp;;3;;-->
              <tr>
                <td class="OraBIListDefaultContent">
                  <orabi:ListNavigator biList="${pageList1_data}"/>
                </td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      <!-- Insert your Business Intelligence tags here -->
      <p/>
      <table cellspacing="2" cellpadding="3" border="0" width="100%">
        <tr>
          <td rowspan="4" vAlign="top">
            <table>
              <tr>
                <td class="OraBIListVioletHeader">
                  <c:out value="${BISalesAnalysis_cascDimMems1_data.listLabel}"/>
                </td>
              </tr>
              <tr>
                <td class="OraBIListVioletContent">
                  <table width="100%">
                    <tr>
                      <td>
                        <table width="100%" id="<c:out value="${BISalesAnalysis_cascDimMems1_data.levelList[0].listName}"/>">
                          <tr>
                            <td class="OraBICascadingListVioletSubHeader">Product Category</td>
                          </tr>
                          <tr>
                            <td>
                              <orabi:ListCombo renderWhenEmpty="false" autoSubmit="true" biList="${BISalesAnalysis_cascDimMems1_data.levelList[0]}" showNoneItem="No" renderAs="combo" inlineStyle="width: 130pt;"/>
                            </td>
                          </tr>
                          <c:if test="${BISalesAnalysis_cascDimMems1_data.levelList[0].count == 0}">
                            <tr>
                              <td class="OraFieldText">
                                <c:out value="${bisession1_bundle_data.noItemsAvailable}"/>
                              </td>
                            </tr>
                          </c:if>
                        </table>
                      </td>
                    </tr>
                    <tr>
                      <td>
                        <table width="100%" id="<c:out value="${BISalesAnalysis_cascDimMems1_data.levelList[1].listName}"/>">
                          <tr>
                            <td class="OraBICascadingListVioletSubHeader">
                              <c:out value="${BISalesAnalysis_cascDimMems1_data.levelList[1].listLabel}"/>
                            </td>
                          </tr>
                          <tr>
                            <td>
                              <orabi:ListCombo renderWhenEmpty="false" autoSubmit="false" biList="${BISalesAnalysis_cascDimMems1_data.levelList[1]}" renderAs="list" inlineStyle="width: 130pt; height: 150pt" showNoneItem="Auto"/>
                            </td>
                          </tr>
                          <c:if test="${BISalesAnalysis_cascDimMems1_data.levelList[1].count == 0}">
                            <tr>
                              <td class="OraFieldText">
                                <c:out value="${bisession1_bundle_data.noItemsAvailable}"/>
                              </td>
                            </tr>
                          </c:if>
                          <c:if test="${BISalesAnalysis_cascDimMems1_data.levelList[1].count > 0}">
                            <tr>
                              <td>
                                <orabi:Button text="Go" onClick="${BISalesAnalysis_cascDimMems1_data.applyReplace}"/>
                              </td>
                            </tr>
                          </c:if>
                        </table>
                      </td>
                    </tr>
                  </table>
                </td>
              </tr>
            </table>
          </td>
          <td>
            <orabi:Render parentForm="BIForm" targetId="BISalesAnalysis_pres1"/>
          </td>
        </tr>
        <tr>
          <td>
           <table>
            <tr class="OraBIListVioletContent">
              <td class="OraBIListVioletHeader"> Zoom </td>
  
              <td nowrap class="OraBIListVioletItems">
                <input type="radio"  name="zoom" value="<%= zoomExecutor1.ZOOM_IN %>" 
                <%= (zoomExecutor1.getCurrentZoom() == ZoomExecutor.ZOOM_IN)? "checked" : "" %> />
                Zoom In 
              
                <input type="radio" name="zoom" value="<%= zoomExecutor1.ZOOM_OUT %>"  
                <%= (zoomExecutor1.getCurrentZoom() == ZoomExecutor.ZOOM_OUT)? "checked" : "" %> />
                Zoom Out
              
                <input type="radio" name="zoom" value="<%= zoomExecutor1.ZOOM_OFF %>"  
                <%= (zoomExecutor1.getCurrentZoom() == ZoomExecutor.ZOOM_OFF)? "checked" : "" %> />
                Zoom Off
              </td>
              <td class="OraBIListVioletItems" width="5" />
              <td nowrap class="OraBIListVioletItems">
                <orabi:Button onClick="submitForm(0, 0, {'event':'RESET_EVENT'});" text="Reset"/>
              </td>
            </tr>
          </table>
        </td>
        </tr>
        <tr>
          <td>
            <table id="ForecastRegion">
              <!--BI_TAGS_METADATA llt;;4;;dtn;;MeasureList;;dti;;BISalesAnalysis_measureList1;;lgfdv;;2;;llissbc;;_EMP_VAL_;;ldlib;;false;;lscm;;3;;lhvs;;&amp;lt;none&amp;gt;;llp;;2;;lscil;;_EMP_VAL_;;llv;;Forecast;;llibc;;_EMP_VAL_;;lti;;DEFAULT;;lrt;;8;;lgfd;;1;;lsct;;Go;;llilp;;3;;-->
              <tr>
                <td class="OraBIListVioletHeader"> Forecast Sales for Product: <%= zoomExecutor1.getProductLabel(forecastGraph) %> </td>
              </tr>
              <tr>
                 <td class="OraBIListVioletHeader"> Sales Revenue:  <%= zoomExecutor1.getSalesRevenue(bubbleGraph) %>, Sales Revenue % Change Year Ago: <%= zoomExecutor1.getSalesPercentChange(bubbleGraph) %>, Margin: <%= zoomExecutor1.getMargin(bubbleGraph)%>
                </td>
              </tr>
              <tr>
                <td class="OraBIListVioletContent">
                  <orabi:GridListIterator biList="${BISalesAnalysis_measureList1_data}" numRows="3">
                    <orabi:ListItem renderAs="checkBox" autoSubmit="false" styleClass="OraBIListDefaultItems"/>
                  </orabi:GridListIterator>
                </td>
              </tr>
              <tr>
                <td class="OraBIListVioletActions">
                  <orabi:Button onClick="${BISalesAnalysis_measureList1_data.applyReplace}" text="Go"/>
                </td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td>
            <orabi:Render targetId="BISalesAnalysis_pres2" parentForm="BIForm"/>
          </td>
        </tr>
        
      </table>
      <p/>

      <!-- The InsertHiddenFields tag adds state fields to the parent form tag -->
      <orabi:InsertHiddenFields parentForm="BIForm"  biThinSessionId="bisession1" />
      <input type="HIDDEN" name="bubble" />
      <input type="HIDDEN" name="PROD" />
    </form>

  </orabi:BIBody>
</html>
<% } %>
<!-- End synchronization of the BI tags -->
