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

    File:               fac_edit_faq_save
    Description:        SUBMIT-form

    Parameters:
    Context:
    Note:

     SUBMIT-form
*/ %>

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

<%
FCLTHeader.Requires({ plugins:["jQuery"],
                      js: []
                    }) %>
<%
var faq_key = getQParamInt( "faq_key", -1 );
var isNew = (faq_key == -1);

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)
var canWriteFAQFOF = authparamsFAQFOF && authparamsFAQFOF.PRSwritelevel < 9 && authparamsFAQFOF.ALGwritelevel < 9;
var canWriteFAQBOF = authparamsFAQBOF && authparamsFAQBOF.PRSwritelevel < 9 && authparamsFAQBOF.ALGwritelevel < 9;

var fields =  [ { dbs: "fac_faq_question",    typ: "varchar",  frm: "fac_question", len: 200 },
                { dbs: "fac_faq_answer",      typ: "varchar",  frm: "fac_answer" },
                { dbs: "fac_faq_source",      typ: "varchar",  frm: "fac_bron",     len: 60 },
                { dbs: "fac_faq_url",         typ: "varchar",  frm: "fac_url" },
                { dbs: "fac_faq_level",       typ: "number",   frm: "fac_faq_level" },
                { dbs: "fac_faq_displaymode", typ: "check0",   frm: "fac_faq_displaymode" },
                { dbs: "prs_perslid_key",     typ: "key",      val: user_key },
                { dbs: "fac_faq_datum",       typ: "date",     frm: "date_from" },
                { dbs: "fac_faq_lang",        typ: "varchar",  frm: "fac_faq_lang" },
                { dbs: "fac_faq_hint",        typ: "varchar",  frm: "fac_hint", len: 1000 }
              ];

var warning = "";

if (faq_key > 0)
{
  user.auth_required_or_abort(canWriteFAQFOF || canWriteFAQBOF); // Frontoffice en backoffice mogen wijzigen
  sql = buildUpdate("fac_faq", fields)
      + "     fac_faq_key = " + faq_key;

  var err = Oracle.Execute(sql, true);
  if (err.friendlyMsg)
    warning = err.friendlyMsg;
}
else
{
  user.auth_required_or_abort(canWriteFAQFOF); // Frontoffice mag alleen toevoegen
  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;
}

// HIER WORDEN DE SAVEFLEXKENMERKEN GEREGELD
currentKenmerkenSQL = " SELECT kf.faq_kenmerk_key"
                    + "     , kf.faq_kenmerkwaarde_waarde"
                    + " 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;

saveFlexKenmerken(faq_key, { kenmerkTable: "faq_kenmerkwaarde",
                             kenmerkParentKey : "fac_faq_key",
                             kenmerkWaarde: "faq_kenmerkwaarde_waarde",
                             kenmerkKey: "faq_kenmerk_key",
                             currentKenmerkenSQL: currentKenmerkenSQL,
                             requestQF: Request.Form,
                             isNew: isNew,
                             flexPath: "FAQ/F"
                       });
%>
<html>
  <head>
    <%  FCLTHeader.Generate() %>
    <script type="text/javascript">
        $(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>
