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

     File:      mld/kpi_search.asp

     Noot: vereist een storedprocedure cust.refreshscore(userkey) om de kpi_score tabel te verversen
*/ %>

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

<%
FCLTHeader.Requires({ plugins:["jQuery"] });
/***** Get webform parameters *****/
var fclt_key = getQParamInt("fclt_key", -1);
var periode  = getQParam("periode", "");
var toon     = getQParam("toon", 0);

var sql_configcheck = "SELECT COUNT(*) FROM kpi_definitie";
var oRs = Oracle.Execute(sql_configcheck);
user.anything_todo_or_abort(oRs(0).value > 0);

var freeze = getQParamInt("freeze", 0);
if (freeze == 1)
{    // Mag best een tikje robuuster, maar hoe he?
    var sql = "BEGIN " + customerId + ".refreshscore("+user_key+"); END;";
    Oracle.Execute(sql);
}

/***** Selector sql *****/

var sql_l = " SELECT DISTINCT l.alg_locatie_key"
          + "      , " + S("alg_loc_string")
          + "   FROM alg_v_my_location ml"
          + "      , alg_locatie l"
          + "  WHERE ml.alg_locatie_key = l.alg_locatie_key"       // moet hier een functie bij?
          + "    AND ml.prs_perslid_key = " + user_key
          + "  ORDER BY 2";

var sql_p = "SELECT DISTINCT to_char(kpi_score_datum, 'YYYYMM'), to_char(kpi_score_datum, 'YYYY-MM')"
          + "  FROM kpi_score"
          + " ORDER BY 1 DESC";
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>

    <script type="text/javascript">
      function doSubmit()
      {
          document.forms.u2.submit();
      }
      function doBijwerken()
      {
          var url = "kpi_search.asp?freeze=1&" + $("[name=u2]").serialize();
          window.location.href = url;
      }
    </script>

  </head>

  <body id="searchbody">
    <div id="search">
      <form name="u2" target="workFrame" action="kpi_search_list.asp" method="get">
        <input type="hidden" id="widget_height" name="widget_height" value="200">

<%    BLOCK_START("searchtable", L("lcl_filterblok"));%>
        <tr>
          <td class="searchkolom1"><!-- start column 1 -->
            <table><!-- x rijen, 2 kolommen: label + veld -->
<%              // gewoon plaatsselector met filtercode KPI = komt voor in kpi_score
                FCLTselector("loc_key",
                             sql_l,
                             { trclass: "primsearch",
                               label: L("lcl_location"),
                               initKey: fclt_key,
                               emptyKey: "-1",
                               emptyOption: ""
                             });
%>
              <tr class="primsearch">
                <td class="label">
                  <label><%=L("lcl_kpi_toon")%>:</label>
                </td>
                <td>
                    <label for="mld_opdr_p"><input type="radio" name="toon" id="mld_opdr_p" value="0" <%=toon==0?"checked":""%>><%=L("lcl_kpi_cat2_per_cat1")%>
                    <label for="mld_opdr_o"><input type="radio" name="toon" id="mld_opdr_o" value="1" <%=toon==1?"checked":""%>><%=L("lcl_kpi_cat1_per_cat2")%>
                </td>
              </tr>
            </table>
          </td><!-- end column 1 -->

          <!-- Second column -->
          <td>
            <table>
<%
                FCLTselector("periode",
                             sql_p,
                             { trclass: "primsearch",
                               label: L("lcl_ins_controle_period"),
                               initKey: periode
                             });
%>
            </table>
          </td><!-- end column 2-->
        </tr>
        </table>

<%    BLOCK_END()
      var buttons = [{ title: L("lcl_show"), action: "doSubmit();"},
                     { title: L("lcl_kpi_bijwerken"), action: "doBijwerken();"}
                    ];
      CreateButtons(buttons, { entersubmit: true });
%>
      </form>
    </div> <!-- search -->

    <div id="result">
      <iframe width="100%" height="100%"
              src="../Shared/empty.asp"
              name="workFrame" id="workFrame"
              onload='FcltMgr.iframeLoaded(this)'
              frameborder="0" scrolling="no">
      </iframe>
    </div>
  </body>
</html>
