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

    File:               mld_2faq_save.asp
    Description:        SUBMIT-form

    Parameters:
    Context:
    Note:

     SUBMIT-form
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../shared/save2db.inc" -->
<!-- #include file="../Shared/kenmerk_common.inc"-->
<!-- #include file="../fac/fac.inc" -->

<% FCLTHeader.Requires({ plugins:["jQuery"],
                      js: []
                    }) %>
<%
var mld_key = getQParamInt( "mld_key" );
var fac_link = ( getFParam( "fac_link", "off" ) == "on" );

var faq_disc = getFParamInt("fac_disc"); // Verplicht
var this_faq = fac.func_enabled_faq(-1, { "disc_key": faq_disc }); // Wat heb ik zoal aan rechten op deze specifieke kennisbankitem.
user.auth_required_or_abort(this_faq.canAdd);

var sqlm = "SELECT mm.mld_stdmelding_key"
         + "     , msm.mld_ins_discipline_key"
         + "  FROM mld_melding mm, mld_stdmelding msm"
         + " WHERE mld_melding_key = " + mld_key
         + "   AND mm.mld_stdmelding_key = msm.mld_stdmelding_key";
var oRs = Oracle.Execute(sqlm);

var fields =  [ { dbs: "fac_faq_question",       typ: "varchar",  frm: "fac_question",  len: 4000 },
                { dbs: "fac_faq_answer",         typ: "varchar",  frm: "fac_answer",    len: 4000 },
                { dbs: "fac_faq_answer2",        typ: "varchar",  frm: "fac_answer2",   len: 4000 },
                { dbs: "fac_faq_source",         typ: "varchar",  val: shared.mld_prefix(mld_key) + mld_key },
                { dbs: "fac_faq_url",            typ: "varchar",  frm: "fac_url" },
                { dbs: "fac_faq_hint",           typ: "varchar",  frm: "fac_hint",      len: 1000 },
                { dbs: "fac_faq_level",          typ: "number",   frm: "fac_level" },
                { dbs: "prs_perslid_key",        typ: "key",      val: user_key },
                { dbs: "fac_faq_lang",           typ: "varchar",  val: user_lang },
                { dbs: "faq_ins_discipline_key", typ: "key",      val: faq_disc,        foreign: "faq_discipline" }
                // datum leeg==> Concept
              ];

var warning = "";
fields.push({  dbs: "fac_faq_key",         typ: "key",      seq: "fac_s_fac_faq_key" });
var regIns = buildInsert("fac_faq", fields);
var faq_key = regIns.sequences["fac_faq_key"];
sql = regIns.sql;
var err = Oracle.Execute(sql, true);
if (err.friendlyMsg)
  warning = err.friendlyMsg;
else
{
  // HIER WORDEN DE SAVEFLEXKENMERKEN GEREGELD
  currentKenmerkenSQL = "SELECT kf.faq_kenmerk_key"
                      + "     , kf.faq_kenmerkwaarde_waarde"
                      + "     , k.faq_kenmerk_toonbaar"
                      + "     , k.fac_functie_key"
                      + "  FROM faq_kenmerkwaarde kf"
                      + "     , faq_kenmerk k"
                      + " WHERE k.faq_kenmerk_key = kf.faq_kenmerk_key"
                      + "   AND faq_kenmerkwaarde_verwijder IS NULL"
                      + "   AND fac_faq_key = " + faq_key;

  var allKenmerkenSQL = " SELECT " + lcl.xsql('k.faq_kenmerk_omschrijving', 'k.faq_kenmerk_key') + " kenmerk_omschrijving"
                       + "      , k.faq_kenmerk_kenmerktype    kenmerk_kenmerktype"
                       + "      , k.faq_kenmerk_systeem        kenmerk_systeem"
                       + "      , k.faq_kenmerk_toonbaar       kenmerk_readonly"
                       + "      , k.faq_kenmerk_uniek          kenmerk_uniek"
                       + "      , fac_kenmerkdomein_key"
                       + "   FROM faq_kenmerk k "
                       + "  WHERE k.faq_kenmerk_verwijder IS NULL"
                       + "    AND k.faq_kenmerk_key = "; /* wordt in saveFlexkenmerken uitgebreid */

  var flextrack = saveFlexKenmerken(faq_key,
                                    { kenmerkTable: "faq_kenmerkwaarde",
                                      kenmerkParentKey : "fac_faq_key",
                                      kenmerkWaarde: "faq_kenmerkwaarde_waarde",
                                      kenmerkKey: "faq_kenmerk_key",
                                      kenmerkToonbaar: "faq_kenmerk_toonbaar",
                                      currentKenmerkenSQL: currentKenmerkenSQL,
                                      allKenmerkenSQL: allKenmerkenSQL,
                                      requestQF: Request.Form,
                                      isNew: true,
                                      tracking: true,
                                      module: "FAQ",
                                      flexPath: "FAQ/F"
                                    });

  // Kennisbankitem koppelen aan de melding.
  fields =[];
  if (fac_link) {
    fields.push({ dbs: "mld_stdmelding_key",    typ: "key", val: oRs("mld_stdmelding_key").value });
    fields.push({ dbs: "ins_discipline_key",    typ: "key", val: oRs("mld_ins_discipline_key").value });
    fields.push({ dbs: "fac_faq_key",           typ: "key", val: faq_key });
    fields.push({ dbs: "mld_stdmeldingfaq_key", typ: "key",    seq: "mld_s_mld_stdmeldingfaq_key" });
    var regIns = buildInsert("mld_stdmeldingfaq", fields);
    var mld_stdmeldingfaq_key = regIns.sequences["mld_stdmeldingfaq_key"];
    sql = regIns.sql;
    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
      warning = err.friendlyMsg;
  }
}
%>
<html>
  <head>
    <%  FCLTHeader.Generate() %>
    <script>
        $(function ()
        {
          FcltMgr.closeDetail(window, { faq_key: <%=faq_key%>,
                                        warning: "<%=safe.jsstring(warning)%>",
                                        keepForm: <%=warning?"true" : "false"%>,
                                        refresh: true
                                      });
        });
    </script>
  </head>
  <body>
  </body>
</html>
<% ASPPAGE_END(); %>
