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

    File:               fac_typeopdrfaq_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 typeopdr_key = -1;
  var typeopdr_keys = [];
  for (var i = 0; i < nrRows; i++)
  {
    typeopdr_key = getFParamInt("typeopdr" + i, 0);

    if (typeopdr_key > 0)
    {
      typeopdr_keys.push(typeopdr_key);
    }
  }

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

  // Alle regels uit de popup toevoegen.
  for (var i = 0; i < typeopdr_keys.length; i++)
  {
    {
      var sql = "INSERT INTO mld_typeopdrfaq "
              + "        (fac_faq_key, mld_typeopdr_key)"
              + " VALUES (" + faq_key
              + "      ,  " + typeopdr_keys[i]
              + "        )";
      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(); %>
