<%@language = "javascript" %>
<% /*
     $Revision$
     $Id$

     File:      kpi/kpi_search_list.asp

     Note: de trendlijn reageert niet op de periode.
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../fac/fac_usrgraph.inc" -->

<%

FCLTHeader.Requires({ plugins:["jQuery"],
                      js: ["jquery-ui.js"]
                    });

/***** Constants *****/
var init_height = "200px";
// Deze view zijn predefined.
var graph_view_names = [ {name: "kpi_v_graph_tot_tot",    hastext1: 1, hastext2: 0},
                         {name: "kpi_v_graph_tot_trend",  hastext1: 0, hastext2: 0},
                         {name: "kpi_v_graph_proc_tot",   hastext1: 1, hastext2: 1},
                         {name: "kpi_v_graph_proc_ond",   hastext1: 1, hastext2: 1},
                         {name: "kpi_v_graph_proc_trend", hastext1: 0, hastext2: 1},
                         {name: "kpi_v_graph_ond_tot",    hastext1: 1, hastext2: 1},
                         {name: "kpi_v_graph_ond_proc",   hastext1: 1, hastext2: 1},
                         {name: "kpi_v_graph_ond_trend",  hastext1: 0, hastext2: 1}
                       ];

/***** Get webform parameters *****/
var loc_key       = getQParamInt("loc_key", -1);
var widget_height = getQParamInt("widget_height", 100);
var periode       = getQParam("periode", "");
var toon          = getQParamInt("toon", 0);

if (loc_key > -1) {
    var sql_l = " SELECT alg_locatie_code"
              + "   FROM alg_locatie l"
              + "  WHERE alg_locatie_key = " + loc_key;
    var oRs = Oracle.Execute(sql_l);
    var locatie = oRs(0).Value;
}
else
    var locatie = L("lcl_all");

if (periode == "") {
    // Neem de laatste periode als er geen periode is opgegeven.
    var sql_p = "SELECT TO_CHAR(MAX(kpi_score_datum), 'yyyymm') periode"
              + "  FROM kpi_score";
    var oRs_p = Oracle.Execute(sql_p);
    user.anything_todo_or_abort(oRs_p.eof);
    periode = oRs_p("periode").Value;
    oRs_p.Close();
}

var params = { initHeight: init_height,
               widget_height: widget_height,
               view_names: graph_view_names,
               fclt_text: [locatie, periode, "", ""]  // locatie, periode, kpi_definitie_categorie1 of kpi_definitie_categorie2, ?
             };

for (var i=0; i<8; i++)
{
    // Voeg aan de view namen de keys toe.
    var graphId = -1;
    var name = graph_view_names[i].name;
    if (name != "")
    {
        var sql = "SELECT fac_usrgraph_key"
                + "  FROM fac_usrgraph"
                + " WHERE fac_usrgraph_view_name = " + safe.quoted_sql(name);
        var oRs = Oracle.Execute(sql);
        if (!oRs.eof)
            graphId = oRs("fac_usrgraph_key").Value;
        oRs.Close();
        //user.anything_todo_or_abort(graphId > 0);
    }
    params.view_names[i].graph_key = graphId;
}

function loadGraph(nr, params)
{
    var fclt_text = (JSON.parse(JSON.stringify(params.fclt_text)));

    if (params.view_names[nr].hastext1 == 0)
        fclt_text[1] = "";
    if (params.view_names[nr].hastext2 == 0)
        fclt_text[2] = "";

    var url = "../fac/fac_usrgraph.asp"
            + "?usrgraph_key="  + params.view_names[nr].graph_key
            + "&fclt_text="     + fclt_text.join(",")
            + "&widget_height=" + params.widget_height;
    var id = "kpiGraph";

// ***** IFRAMER zonder scrollbars.
%>
  <div id="frm_<%=id%>" class="fcltframe">
    <div class="inside">
      <iframe id="<%=id%>" name="<%=id%>" frameborder="0" width="100%" height="<%=params.initHeight||'20px'%>"
              src="<%=url%>" scrolling="no"
              onload="FcltMgr.iframeLoaded(this);">
      </iframe>
    </div>
  </div>
<%
// ***** IFRAMER END.
}
%>
<html>
  <head>
<%  FCLTHeader.Generate() %>
    <script>
        // Normaal niet nodig maar in dit geval maken de clientside dat het veel te laat komt anders
        $(function() { FcltMgr.resized(); } );
    </script>
  </head>

  <body id="listbody">
    <div id="searchlist">
<%
%>
      <input type="hidden" id="fclt_key"      name="fclt_key"      value="<%=loc_key%>">
      <input type="hidden" id="widget_height" name="widget_height" value="<%=widget_height%>">

      <table class="fcltblocktab" cols="3" width="100%">
        <tr onclick="$(this).next().toggle();$(this).toggleClass('collapsed');FcltMgr.resized(window)">
          <td colspan="3">
            <div class="fcltframeheader">
              <span style="float:left"><nobr><%=L("lcl_Total")%>&nbsp;<span id="extratitle_0"></span></nobr></span>
            </div>
          </td>
        </tr>
        <tr>
          <td colspan="1" class="kpitcol1"><% loadGraph(0, params); %></td>
          <td colspan="2" class="kpitcol2"><% loadGraph(1, params); %></td>
        </tr>

<%
    var sql = "SELECT DISTINCT " + (toon==0 ? "kpi_definitie_categorie1" : "kpi_definitie_categorie2") + " fclt_text2"
          + "  FROM kpi_v_kpi_scores"
    var oRs = Oracle.Execute(sql);
    while (!oRs.eof)
    {
        var proces = oRs("fclt_text2").Value;
        params.fclt_text[2] = proces;
%>
        <tr onclick="$(this).next().toggle();$(this).toggleClass('collapsed');FcltMgr.resized(window)">
          <td colspan="3">
            <div class="fcltframeheader">
              <span style="float:left"><nobr><%=proces %>&nbsp;<span id="extratitle"></span></nobr></span>
            </div>
          </td>
        </tr>
        <tr>
          <td class="kpicol1"><% loadGraph( (toon==0?2:5), params); %></td>
          <td class="kpicol2"><% loadGraph( (toon==0?3:6), params); %></td>
          <td class="kpicol3"><% loadGraph( (toon==0?4:7), params); %></td>
        </tr>
<%
        oRs.MoveNext();
    }
    oRs.Close();
%>
      </table>
    </div>
  </body>
</html>
