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

     SUBMIT-form
*/ %>
<%
var JSON_Result = true;
%>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../API2/api2.inc" -->
<%
protectRequest.validateToken();

user.checkAutorisation('WEB_RESMSU');

var ruimte_key_arr = getQParamIntArray("ruimte_keys");
var scope_key_arr = getFParamIntArray("objcatmulti");
var scopemode = getFParamSafe("scopemode"); // A=Add, D=Delete

var toaster;
if (scopemode == 'A')
{
    var sql = "INSERT INTO res_srtartikel_onrgoed"
            + "  (alg_onrgoed_niveau, alg_onrgoed_key, res_discipline_key)"
            + " SELECT 'R', alg_ruimte_key, ins_discipline_key"
            + "  FROM alg_ruimte,"
            + "       res_discipline"
            + " WHERE alg_ruimte_key IN ({0})".format(ruimte_key_arr.join(", "))
            + "   AND ins_discipline_key IN ({0})".format(scope_key_arr.join(", "))
            + "   AND NOT EXISTS ("
            + "       SELECT 1 FROM res_srtartikel_onrgoed"
            + "        WHERE res_srtartikel_og_verwijder IS NULL"
            + "          AND alg_onrgoed_niveau = 'R'"
            + "          AND alg_onrgoed_key = alg_ruimte_key"
            + "          AND res_discipline_key = ins_discipline_key"
            + "       )";
    Oracle.Execute(sql);
    //var toaster = L("lcl_scf_is_added").format(L("res_srtartikel_onrgoed_m"));
}
else if (scopemode == 'D')
{
    var sql = "UPDATE res_srtartikel_onrgoed"
            + "   SET res_srtartikel_og_verwijder = SYSDATE"
            + " WHERE res_srtartikel_og_verwijder IS NULL"
            + "   AND alg_onrgoed_niveau = 'R'"
            + "   AND alg_onrgoed_key IN ({0})".format(ruimte_key_arr.join(", "))
            + "   AND res_discipline_key IN ({0})".format(scope_key_arr.join(", "));
    Oracle.Execute(sql);
    var toaster = L("lcl_scf_is_deleted").format(L("res_srtartikel_onrgoed_m"));
}

var result = { toaster: toaster,
               success: true };
Response.Write(JSON.stringify(result));
%><% ASPPAGE_END(); %> 
