<%@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" -->

<% FCLTHeader.Requires({ plugins:["jQuery"],
                      js: []
                    }) %>
<%
  var mld_key = getQParamInt( "mld_key" );
  var fac_link = ( getFParam( "fac_link", "off" ) == "on" );
  var autfunction = "WEB_FAQFOF";
  var authparams = user.checkAutorisation(autfunction);
  user.auth_required_or_abort(authparams.PRSwritelevel<9);

  var sqlm = "SELECT mm.mld_stdmelding_key"
           + "     , 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_source",   typ: "varchar",  val: "Servicedesk" },
                  { dbs: "fac_faq_url",      typ: "varchar",  frm: "fac_url" },
                  { 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 }
                  // 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
{
  fields =[];
  if (fac_link) {
    fields.push({ dbs: "mld_stdmelding_key",    typ: "number", val: oRs("mld_stdmelding_key").value });
    fields.push({ dbs: "ins_discipline_key",    typ: "number", val: oRs("mld_ins_discipline_key").value });
    fields.push({ dbs: "fac_faq_key",           typ: "number", 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>
        $(document).ready(function () {
            FcltMgr.closeDetail(window, { faq_key: <%=faq_key%>,
                                          warning: "<%=safe.jsstring(warning)%>",
                                          keepForm: <%=warning?"true":"false"%>,
                                          refresh: true
                                         }); } );
    </script>
  </head>
  <body>
  </body>
</html>
