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

    File:               fac_stdmelding_list.asp
    Description:        Show an overview of mld_stdmeldingfaq items in list-form,
                        which meets with the given requirements
    Parameters:
    Context:            Include frame for fac_show_faq.
    Note:
*/ %>

<!-- #include file="../Shared/json2.js" -->
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/resultset_table_v2.inc" -->
<!-- #include file="../MLD/mld.inc" -->

<%
var outputmode = getQParamInt("outputmode", 0); //  0 = screen, 1 = print, 2 = excel etc
var showall    = getQParamInt("showall", 0) == 1;
var faq_key    = getQParamInt("faq_key");

var sql = "SELECT fac_faq_level"
        + "     , fac_faq_datum"
        + "  FROM fac_faq f"
        + " WHERE fac_faq_key = " + faq_key;
var oRs = Oracle.Execute(sql);
if (oRs.Eof)
    shared.record_not_found("<!--" + faq_key + "-->");

var level = oRs("fac_faq_level").Value;
var datum = oRs("fac_faq_datum").Value;
var mustProf = (level & 1) == 0; // Alleen professionals
oRs.close();

var authparamsFAQUSE = user.checkAutorisation("WEB_FAQUSE", true); // Frontend mag ingevoerde items bekijken
var authparamsFAQFOF = user.checkAutorisation("WEB_FAQFOF", true); // Frontoffice mag items aanmaken en bewerken
var authparamsFAQBOF = user.checkAutorisation("WEB_FAQBOF", true); // Backoffice mag ingevoerde items publiceren (publicatie datum zetten/aanpassen)

user.auth_required_or_abort(authparamsFAQBOF || authparamsFAQFOF || (!mustProf && authparamsFAQUSE));

var canWriteFAQFOF = authparamsFAQFOF && authparamsFAQFOF.PRSwritelevel < 9 && authparamsFAQFOF.ALGwritelevel < 9;
var canWriteFAQBOF = authparamsFAQBOF && authparamsFAQBOF.PRSwritelevel < 9 && authparamsFAQBOF.ALGwritelevel < 9;
var canChange = canWriteFAQBOF || (canWriteFAQFOF && datum == null)

var addButton = [];

%>
<html>
  <head>
<%  FCLTHeader.Generate({outputmode:outputmode}) %>
    <script type="text/javascript">
      var autosearch = 1; //automatisch laden van resultaat op search pagina

      function mld_stdmeldingfaq()
      {
        FcltMgr.openModalDetail("../fac/fac_stdmeldingfaq.asp?faq_key=<%=faq_key%>",
                                L("lcl_faq_stdmeldingfaq"),
                                { callback: FcltMgr.reload });
      }

      function faq_newmld(row)
      {
        var faqData = eval('(' + row.getAttribute("ROWDATA") + ')');
        var discParam = "&disc="+faqData.disc_key;
        var stdmParam = (faqData.stdm_key? "&mld_defaultstdmelding=" + faqData.stdm_key : "");
        FcltMgr.openDetail("appl/mld/mld_melding.asp?fromkb=1"+discParam+stdmParam, "<%=L("lcl_add")%>");
      }

    </script>
  </head>
  <body id="listbody">
<%
  function fnrowData(oRs)
  {
    var disc_key = oRs("disc_key").value;
    var stdm_key = oRs("mld_stdmelding_key").value;

    var data = {disc_key:disc_key, stdm_key:stdm_key };
    return JSON.stringify(data);
  }

  function fnrowActionEnabler(oRs)
  {
    var notfrontend = oRs("mld_stdmelding_notfrontend").value;
    return { eMelding: canWriteFAQFOF || canWriteFAQBOF || !notfrontend
           };
  }

  if (canChange)
  {
    addButton = [{icon: "wijzigen.png", title: L("lcl_change"), action: "mld_stdmeldingfaq()"}];
  }

  var sql = "SELECT f.mld_stdmeldingfaq_key"
          + "     , stdm.mld_stdmelding_key"
          + "     , mld_stdmelding_notfrontend"
          + "     , " + 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;

  var rst = new ResultsetTable({ sql: sql
                               , keyColumn: "mld_stdmeldingfaq_key"
                               , ID: "mldstdmeldingfaqtable"
                               , noPrint: true
                               , showAll: showall
                               , rowData: fnrowData
                               , rowActionEnabler: fnrowActionEnabler
                               , outputmode: outputmode
                               , title: L("lcl_faq_voor_stdmelding")
                               , buttons: addButton
                               });

  rst.addColumn(new Column({caption: L("lcl_vakgroup"), content: "vakgroep"}));
  rst.addColumn(new Column({caption: L("lcl_complain"), content: "mld_stdmelding_omschrijving"}));

  rst.addAction({action: "faq_newmld", caption: L("lcl_do_amelding_hint"), enabler: "eMelding" });

  var cnt = rst.processResultset();
%>
    </body>
  </html>

