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

    File:               fac_stdmeldingfaq_save.asp
    Description:        Save places for faq-item
    Parameters:         fac_faq_key

    Context:
    Note:
*/ %>

<%
var JSON_Result = true;
%>

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

<%
protectRequest.validateToken();

var faq_key = getQParamInt("faq_key");
var nrRows = getFParamInt("nrRows", 0);

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;
var disc_keys = [];
var stdm_keys = [];
for (var i = 0; i < nrRows; i++)
{
  disc_key = getFParamInt("disc" + i, 0);
  stdm_key = getFParamInt("stdm" + i, 0);

  if (disc_key > 0)
  {
    disc_keys.push(disc_key);
    stdm_keys.push(stdm_key);
  }
}

// Alles van deze kennisbank-item Verwijderen
var sql = "DELETE mld_stdmeldingfaq"
        + " WHERE fac_faq_key = " + faq_key;
Oracle.Execute(sql);

// Alle regels uit de popup toevoegen.
for (var i = 0; i < disc_keys.length; i++)
{
  {
    var sql = "INSERT INTO mld_stdmeldingfaq "
            + "        (fac_faq_key, ins_discipline_key, mld_stdmelding_key)"
            + " VALUES (" + faq_key
            +         "," + disc_keys[i]
            +         "," + ((stdm_keys[i] > 0) ? stdm_keys[i] : "NULL")
            +         ")";
    Oracle.Execute(sql);
  }
}
// Set kennisbank-item wijzigdatum
var sql = "UPDATE fac_faq"
        + " SET fac_faq_wijzigdatum = systimestamp"
        + " WHERE fac_faq_key = " + faq_key;
Oracle.Execute(sql);
var result = {success: true};
Response.Write(JSON.stringify(result));
%>
<% ASPPAGE_END(); %>
