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

     File:               fac_stdmeldingfaq.asp
     Description:        Laat aan een FAQ meerdere standaardmeldingen toevoegen
     Parameters:         faq_key: fac_faq_key waaraan de standaardmeldingen gekoppeld moeten worden
     Context:
     Note:

k
*/ %>

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

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

var faq_key = getQParamInt("faq_key");

var this_faq = fac.func_enabled_faq(faq_key); // Wat heb ik zoal aan rechten op deze specifieke kennisbankitem.

user.auth_required_or_abort(this_faq.canChange);

var disc_key = -1;
var stdm_key = -1;
%>
  <html>
    <head>
<%    FCLTHeader.Generate(); %>
      <script type="text/javascript">
        function onChangeVakgroep(vakgroep_key)
        {
          // Melding leegmaken
          sgStdm.setValue(-1, "", true, false, null, true);
          sgStdm.CheckJustOne();
        }

        function process_stdm_info(data, textStatus)
        {
          // Zet de discipline indien niet ingevuld
          if ($("#disc").val() <= 0)
            sgDisc.setValue(data.ins_discipline_key, (data.ins_srtdiscipline_prefix != null ? data.ins_srtdiscipline_prefix + "-" : "") + data.discipline_omschrijving, false /*doonChange*/, true /*checkExist*/);
        }

        function onChangeStdMelding(stdmelding_key)
        {
          if (stdmelding_key > 0)
          {
            $.getJSON("../mld/get_mld_info_ajax.asp",
                      { req_info: "mld_stdmelding",
                        mld_stdmelding_key: stdmelding_key,
                        mld_key: -1,
                        caller_key: -1 },
                        process_stdm_info);
          }
        }
      </script>
    </head>

    <body class="fclt-modal" id="mod_stdmeldingfaq">
      <% MODAL_START(); %>
        <form name="u2" method="post" action="fac_stdmeldingfaq_save.asp?faq_key=<%=faq_key%>">
        <% MODAL_BLOCK_START(); %>
          <input type="hidden" id="nrRows" name="nrRows" value="0">
<%
          // <!-- Toevoegen -->
          // Vakgroep
          FCLTdisciplineselector("disc",
                                 "sgDisc",
                                 { label: L("lcl_vakgroup"),
                                   disc_key: disc_key,
                                   module: "MLDP",
                                   perslidKey: user_key,
                                   autfunctionKey: -1, // alles is toegestaan! authparams.autfunctionkey,
                                   srtdisc_key: null, // alles mag
                                   onChange: "onChangeVakgroep",
                                   multitoggle: true,
                                   sgRelType: "stdmelding"
                                 });
          // Discipline
          FCLTstdmeldingselector("stdm",
                                 "sgStdm",
                                 { label: L("lcl_complain"),
                                   perslidKey: user_key,
                                   autfunctionKey: -1, // alles is toegestaan! authparams.autfunctionkey,
                                   srtdisc_key: null, // alles mag
                                   urlAdd: [{urlParam: "disc_key", field: "disc"}],
                                   onChange: "onChangeStdMelding",
                                   multitoggle: true,
                                   stdmelding_key: stdm_key
                                 });
%>
          <tr>
            <td></td> <!-- jQuery 3.5 does not auto-convert xhtml (<td/>) to html (<td></td>) anymore -->
            <td>
              <div id="addroomfaqbuttons">
<%
              var buttons =  [ {title: L("lcl_add"), icon: "fa-plus", action: "fac_add()", id: "btn_faq_add_stdm", importance: 1  }];
              CreateButtons(buttons, { showIcons: true });
%>
              </div>
            </td>
          </tr>
          <tr>
            <td class="label" colspan="2">
              <label for="stdmeldingfaqtable" style="white-space: nowrap"><%=L("lcl_faq_voor_stdmelding")%></label>
            </td>
          </tr>
          <tr>
            <td colspan="2">
              <table id="stdmeldingfaqtable" cellspacing=0 cellpadding=0 class="rstable no-floating">
                <thead>
                  <tr>
                    <th style='width:15px'></th>
                    <th><%=L("lcl_vakgroup")%></th>
                    <th colspan="2"><%=L("lcl_complain")%></th>
                  </tr>
                </thead>
                <tbody>


<%
  var sql = "SELECT f.mld_stdmeldingfaq_key"
          + "     , stdm.mld_stdmelding_key"
          + "     , " + lcl.xsqla('stdm.mld_stdmelding_omschrijving', 'stdm.mld_stdmelding_key')
          + "     , (SELECT m1.ins_discipline_key"
            + "        FROM mld_v_aanwezigdiscipline m1"
            + "           , ins_srtdiscipline sd"
            + "       WHERE m1.ins_srtdiscipline_key = sd.ins_srtdiscipline_key"
            + "         AND m1.ins_discipline_key = COALESCE(f.ins_discipline_key, stdm.mld_ins_discipline_key)"
            + "     ) disc_key"
          + "     , (SELECT CASE"
            + "             WHEN sd.ins_srtdiscipline_prefix IS NULL"
            + "             THEN ''"
            + "             ELSE sd.ins_srtdiscipline_prefix || '-'"
            + "             END"
            + "             ||" + lcl.xsqla('m1.ins_discipline_omschrijving', 'm1.ins_discipline_key')
            + "        FROM mld_v_aanwezigdiscipline m1"
            + "           , ins_srtdiscipline sd"
            + "       WHERE m1.ins_srtdiscipline_key = sd.ins_srtdiscipline_key"
            + "         AND m1.ins_discipline_key = COALESCE(f.ins_discipline_key, stdm.mld_ins_discipline_key)"
            + "     ) vakgroep"
          + "  FROM mld_stdmeldingfaq f"
          + "     , mld_stdmelding stdm"
          + " WHERE f.mld_stdmelding_key = stdm.mld_stdmelding_key(+)"
          + "   AND fac_faq_key = " + faq_key;

                oRs = Oracle.Execute(sql);
                var teller = 0;
                while (!oRs.eof)
                {
                  teller++;
%>
                  <script type="text/javascript">
                    CreateRow(<%=oRs("disc_key").value%>
                             ,<%=oRs("mld_stdmelding_key").value || -1%>
                             ,'<%=safe.jsstring(oRs("vakgroep").value)%>'
                             ,'<%=safe.jsstring(oRs("mld_stdmelding_omschrijving").value)%>'
                             );

                  </script>
<%
                  oRs.MoveNext();
                }
%>
                </tbody>
              </table>
            </td>
          </tr>
<%
          MODAL_BLOCK_END();
          SIMPLE_BLOCK_START();
          var buttons1 =  [{title: L("lcl_submit"), icon: "fa-fclt-save",   action: "fac_submit()", importance: 1 }];
          CreateButtons(buttons1);
          SIMPLE_BLOCK_END();
          IFACE.FORM_END();
%>
        </form>
        <% MODAL_END(); %>
    </body>
  </html>
<%

%><% ASPPAGE_END(); %>
