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

     File:      mld/kpi_search.asp
*/ %>

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

<%
FCLTHeader.Requires({ plugins:["jQuery"] });

var l_bijwerken = "Bijwerken";
var l_toon = "Toon";
var l_onderdelen_per_proces = "Onderdelen per proces";
var l_processen_per_onderdeel = "Processen per onderdeel";
/***** Get webform parameters *****/
var fclt_key = getQParamInt("fclt_key", -1);
var periode  = getQParam("periode", "");
var toon     = getQParam("toon", 0);

var freeze = getQParamInt("freeze", 0);

if (freeze == 1)
{
    var sql = "BEGIN "
            + "  akza_select_mld_kpi('MLD_KPI', TO_CHAR(sysdate,'yyyy-mm-dd hh:mi:ss'), 0);"
            + "END;";
    Oracle.Execute(sql);
}

/***** Selector sql *****/
var sql = "SELECT ins_srtdiscipline_key"
        + "  FROM ins_srtdiscipline"
        + " WHERE ins_srtdiscipline_module = 'MLD'"
        + "   AND ins_srtdiscipline_OMSCHRIJVING = 'KPI'";
var oRs = Oracle.Execute(sql);
var v_srtdiscipline_key = oRs("ins_srtdiscipline_key").Value;
oRs.Close();

var sql_l = " SELECT DISTINCT l.alg_locatie_key"
          + "      , " + S("alg_loc_string")
          + "   FROM fac_functie f"
          + "      , fac_v_webgebruiker wg"
          + "      , mld_discipline d"
          + "      , alg_v_my_location ml"
          + "      , alg_locatie l"
          + "  WHERE f.fac_functie_code = 'WEB_MLDBAC'"
          + "    AND wg.fac_functie_key = f.fac_functie_key"
          + "    AND d.ins_discipline_key = wg.ins_discipline_key"
          + "    AND d.ins_srtdiscipline_key = " + v_srtdiscipline_key
          + "    AND wg.fac_gebruiker_alg_level_read <=2"
          + "    AND ml.prs_perslid_key = wg.prs_perslid_key"
          + "    AND ml.alg_locatie_key = l.alg_locatie_key"
          + "    AND ml.prs_perslid_key = " + user_key
          + "  ORDER BY 2";

var sql_p = "SELECT d.fac_usrdata_code"
          + "     , d.fac_usrdata_omschr"
          + "  FROM fac_usrtab t"
          + "     , fac_usrdata d"
          + " WHERE t.fac_usrtab_key = d.fac_usrtab_key"
          + "   AND t.fac_usrtab_object = 'USR_KPI PERIODE'"
          + "   AND d.fac_usrdata_verwijder IS NULL"
          + "   AND COALESCE(d.fac_usrdata_vervaldatum, SYSDATE+1) > SYSDATE"
          + "   AND TO_DATE(d.fac_usrdata_code, 'YYYYMM') >"
                + " (SELECT ADD_MONTHS(TO_DATE(MAX(d1.fac_usrdata_code), 'yyyymm'), -12)"
                + "    FROM fac_usrdata d1"
                + "       , fac_usrtab t1"
                + "   WHERE d1.fac_usrtab_key = t1.fac_usrtab_key"
                + "     AND t1.fac_usrtab_object = 'USR_KPI PERIODE')"
          + " ORDER BY d.fac_usrdata_code 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 -->
              <tr class="primsearch">
<%
                FCLTselector("fclt_key",
                             sql_l,
                             { trclass: "primsearch",
                               label: L("lcl_location"),
                               initKey: fclt_key,
                               emptyKey: "-1",
                               emptyOption: ""
                             });
%>
              </tr>
              <tr>
<%
                FCLTselector("periode",
                             sql_p,
                             { trclass: "primsearch",
                               label: L("lcl_ins_controle_period"),
                               initKey: periode
                             });
%>
              </tr>
              <tr class="primsearch">
                <td class="label">
                  <label><%=l_toon%>:</label>
                </td>
                <td>
                    <label for="mld_opdr_p"><input type="radio" name="toon" id="mld_opdr_p" value="0" <%=toon==0?"checked":""%>><%=l_onderdelen_per_proces%>
                    <label for="mld_opdr_o"><input type="radio" name="toon" id="mld_opdr_o" value="1" <%=toon==1?"checked":""%>><%=l_processen_per_onderdeel%>
                </td>
              </tr>
            </table>
          </td><!-- end column 1 -->

          <!-- Second column -->
          <td valign=top>
            <table>
              <tr class="primsearch">
              </tr>
            </table>
          </td><!-- end column 2-->
        </tr>

        <tr class="primsearch">
          <td colspan="2">
          </td>
        </tr>
        </table>

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

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