<%@ LANGUAGE = JavaScript %>
<% /*
     $Revision$
     $Id$

    File:        mld_stdmelding_search.asp
    Description: Zoekscherm stdmeldingen
    Parameters:  urole
    Context:
    Note:

*/ %>

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

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

var authparams = user.checkAutorisation("WEB_MLDMGT");

var srtdisc_key = getQParamInt("srtdisc_key", -1);
var disc_key = getQParamInt("disc_key", -1);
var stdm_key = getQParamInt("stdm_key", -1);
var mldgrp_key = getQParamInt("mldgrp_key", -1);
var show_expired = getQParamInt("show_expired", 0) == 1;
var simple = getQParamInt("simple", 0);

if (disc_key > -1 && srtdisc_key < 0)
{
  var sql = "SELECT ins_srtdiscipline_key FROM mld_v_aanwezigdiscipline WHERE ins_discipline_key = " + disc_key;
  oRs = Oracle.Execute(sql);
  if (!oRs.eof)
    srtdisc_key = oRs("ins_srtdiscipline_key").value;
}
%>

<html>
  <head>
    <% FCLTHeader.Generate(); %>
    <script type="text/javascript">
      function doSubmit()
      {
        document.forms.u2.submit();
      }

      function onChangeVakgroep(vakgroep_key)
      {
        sgStdm.setValue(-1, "", true, false, null, true);
        sgStdm.CheckJustOne();

        // Zet de srtdiscipline indien niet ingevuld.
        if (vakgroep_key > 0)
        {
          $.getJSON("./get_mld_info_ajax.asp",
                    { req_info: "mld_discipline",
                      mld_ins_discipline_key: vakgroep_key },
                    callback_disc_info);
        }
      }

      function onChangeShowExpired()
      { // Is de juiste waarde nog geldig i.v.m. wijzigen van de checkbox "Toon vervallen".
        sgStdm.setValue($("#stdm").val(), $("#show_stdm").val(), true, true);
      }

      function callback_disc_info(disc_info, textStatus, jqXHR)
      {
        if ($("#srtdisc_key").val() <= 0)
          $("#srtdisc_key").val(disc_info.ins_srtdiscipline_key);
      }

      function onChangeDiscipline(disc_key, txt, params)
      { // Zet de srtdiscipline indien niet ingevuld.
        if (disc_key > 0)
        {
          $.getJSON("./get_mld_info_ajax.asp",
                    { req_info: "mld_discipline",
                      mld_ins_discipline_key: disc_key },
                    callback_disc_info);
        }
      }

      function callback_stdm_info(stdm_info, textStatus, jqXHR)
      {
        sgDisc.setValue(stdm_info.ins_discipline_key, (stdm_info.ins_srtdiscipline_prefix != null ? stdm_info.ins_srtdiscipline_prefix + "-" : "") + stdm_info.discipline_omschrijving, false /*doonChange*/, true /*checkExist*/);
        if ($("#srtdisc_key").val() <= 0)
          $("#srtdisc_key").val(stdm_info.ins_srtdiscipline_key);
      }

      function onChangeStdMelding(stdmelding_key, txt, params)
      { // Zet de (srt)discipline indien niet ingevuld.
        if (stdmelding_key > 0 && $("#disc_key").val() <= 0 && typeof sgDisc != "undefined")
        {
          $.getJSON("./get_mld_info_ajax.asp",
                    { req_info: "mld_stdmelding",
                      mld_stdmelding_key: stdmelding_key,
                      //mld_key: mld_key,
                      caller_key: -1 },
                      callback_stdm_info);
        }
      }
    </script>
  </head>

  <body id="searchbody">
    <div id="search">
      <form name="u2" target="workFrame" action="mld_stdmelding_search_list.asp" method="get">
        <input type="hidden" name="simple" value="<%=simple%>">
<%      BLOCK_START("searchtable", L("lcl_filterblok"));%>
        <tr>
          <td class="searchkolom1">
            <table><!-- x rijen, 2 kolommen: label + veld -->
<%          // Vakgroeptype / Srtdiscipline / Soort melding
            // Als een srtdisc meegegeven dan geen lege optie
            var sql = "SELECT sd.ins_srtdiscipline_key"
                    + ", "+ lcl.xsqla('sd.ins_srtdiscipline_omschrijving', 'sd.ins_srtdiscipline_key')
                    + " FROM ins_srtdiscipline sd"
                    + (disc_key > -1
                      ? "  , mld_v_aanwezigdiscipline md"
                      : "")
                    + " WHERE EXISTS (SELECT 'x'"
                      + " FROM mld_stdmelding ms"
                      + ", mld_v_aanwezigdiscipline m1"
                      + " WHERE m1.ins_discipline_key = ms.mld_ins_discipline_key"
                      + "   AND ms.mld_stdmelding_verwijder IS NULL)"
                      + "   AND ins_srtdiscipline_verwijder IS NULL"
                    + (srtdisc_key > -1
                      ? "   AND sd.ins_srtdiscipline_key = " + srtdisc_key
                      : " ")
                    + (disc_key > -1
                      ? "   AND sd.ins_srtdiscipline_key = md.ins_srtdiscipline_key"
                        + " AND md.ins_discipline_key = " + disc_key
                      : "")
                    + " ORDER BY 2"
            FCLTselector("srtdisc_key",
                         sql,
                         { initKey: srtdisc_key,
                           label: L("lcl_mld_vakgroeptype"),
                           trclass: "primsearch",
                           emptyOption: "",
                           selectjustone: true,
                           onChange: "sgDisc.setValue(-1, '');sgStdm.setValue(-1, '')",
                           readonly: srtdisc_key > -1 || disc_key > -1
                         });

            // Vakgroep / Productgroep
            FCLTdisciplineselector("disc_key",
                                   "sgDisc",
                                   { disc_key: disc_key,
                                     label: L("lcl_mld_vakgroep"),
                                     trclass: "primsearch",
                                     module: "MLDA", // Module MLD en daarnaast ook de vakgroepen tonen zonder stdmeldingen (MLDA).
                                     perslidKey: user_key,
                                     autfunctionKey: -1, // alles is toegestaan! authparams.autfunctionkey,
                                     //srtdisc_key: S("mld_forward_all") == 1? null : srt_disc,
                                     urlAdd: [{urlParam: "srtdisc_key", field: "srtdisc_key"}],
                                     onChange: "onChangeVakgroep",
                                     readonly: disc_key > -1
                                   });
            // Melding / Stdmelding
            FCLTstdmeldingselector("stdm",
                                   "sgStdm",
                                   { stdmelding_key: stdm_key,
                                     label: L("lcl_complain"),
                                     trclass: "primsearch",
                                     perslidKey: user_key,
                                     autfunctionKey: -1, // alles is toegestaan! authparams.autfunctionkey,
                                     urlAdd: [{urlParam: "disc_key", field: "disc_key"},
                                              {urlParam: "srtdisc_key", field: "srtdisc_key"},
                                              {urlParam: "show_expired", field: "show_expired"}],
                                     onChange: "onChangeStdMelding",
                                     whenEmpty: L("lcl_search_generic")  // blijkt niet supported
                                   });

%>
            </table>
          </td><!-- end column 1 -->

          <td class="searchkolom2">
            <table><!-- x rijen, 2 kolommen: label + veld -->
<%          // Meldinggroep
            // Laat alle meldinggroepen zien die voorkomen onder de disciplines die ik mag zien.
            var grpsql = "SELECT g.mld_stdmeldinggroep_key akey"
                       + ", " + lcl.xsqla('g.mld_stdmeldinggroep_naam', 'g.mld_stdmeldinggroep_key')
                       + " FROM mld_stdmelding m"
                       + "    , mld_stdmeldinggroep g"
                       + " WHERE m.mld_stdmeldinggroep_key = g.mld_stdmeldinggroep_key"
                       + "   AND m.mld_stdmelding_verwijder IS NULL"
                       + " AND m.mld_stdmeldinggroep_key IS NOT NULL"
                       + (srtdisc_key > -1
                         ? " AND mld_ins_discipline_key IN (SELECT ins_discipline_key"
                           + " FROM mld_discipline"
                           + " WHERE ins_srtdiscipline_key = " + srtdisc_key + ")"
                         : "")
                       + (disc_key > -1
                         ? " AND mld_ins_discipline_key = " + disc_key
                         : "")
                       + " GROUP BY g.mld_stdmeldinggroep_key, g.mld_stdmeldinggroep_naam"
                       + " ORDER BY 2";

            FCLTselector("mldgrp_key",
                          grpsql,
                          { initKey: mldgrp_key,
                            label: L("lcl_mld_meldinggroep"),
                            trclass: "primsearch",
                            emptyOption: ""
                          });

            CHECKBOXTR(L("lcl_mld_show_expired"), "fldmldshowexpired", "show_expired", show_expired, {html: "onChange='onChangeShowExpired()'"})
%>
            </table>
          </td><!-- end column 1 -->
        </tr>
<%      BLOCK_END();

        var buttons =  [ {title: L("lcl_search"), action: "doSubmit()", id: "bSearch" } ];
        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>
