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

File:               fac_prsfaq_save.asp
Description:        Save productgroup/standard-item 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 bdr_key = -1;
var afd_key = -1;
var bdr_keys = [];
var afd_keys = [];
for (var i = 0; i < nrRows; i++)
{
  bdr_key = getFParamInt("bdr" + i, -1);
  afd_key = getFParamInt("afd" + i, -1);
  if (bdr_key > 0) {
    bdr_keys.push(bdr_key);
    afd_keys.push(afd_key);
  }
}

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

// Alle regels uit de popup toevoegen.
for (var i = 0; i < bdr_keys.length; i++)
{
  {
    var sql = "INSERT INTO prs_prsfaq "
            + "        (fac_faq_key, prs_bedrijf_key, prs_afdeling_key)"
            + " VALUES (" + faq_key
            +         "," + bdr_keys[i]
            +         "," + ((afd_keys[i] > 0) ? afd_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(); %>
