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

    File:               alg_edit_ruimte_multi_save.asp
    Description:        save script van alg_edit_ruimte_multi.asp
    Globalen:
    Context:
    Note:
*/
var JSON_Result = true;
%>

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

<%
protectRequest.validateToken();
var alg_key_arr = getQParamIntArray("alg_keys");
var warning = "";
var result = {};
var nr_edited = 0;
var fields = [];

if (Request.Form("room_srt").Count == 1 && getFParam("check_room_srt", "off") == "on")
    fields.push({ dbs: "alg_srtruimte_key",  typ: "key",  frm: "room_srt" });
if (Request.Form("dienstniveau").Count == 1 && getFParam("check_dienstniveau", "off") == "on")
    fields.push({ dbs: "mld_dienstniveau_key", typ: "key", frm: "dienstniveau", track: L("lcl_mld_dienst_niveau"), foreign: "mld_dienstniveau" });
if (Request.Form("room_oms").Count == 1 && getFParam("check_room_oms", "off") == "on")
    fields.push({ dbs: "alg_ruimte_omschrijving", typ: "varchar", frm: "room_oms", track: L("lcl_estate_ruimte_man_descr") });
if (Request.Form("room_beginuur").Count == 1 && getFParam("check_room_beginuur", "off") == "on")
    fields.push({ dbs: "alg_ruimte_beginuur", typ: "float", frm: "room_beginuur", track: L("lcl_estate_gebouw_beginuur") });
if (Request.Form("room_einduur").Count == 1 && getFParam("check_room_einduur", "off") == "on")
    fields.push({ dbs: "alg_ruimte_einduur", typ: "float", frm: "room_einduur", track: L("lcl_estate_gebouw_einduur") });
if (Request.Form("room_werkdagen").Count == 1 && getFParam("check_room_werkdagen", "off") == "on")
    fields.push({ dbs: "alg_ruimte_werkdagen",  typ: "key",  frm: "room_werkdagen" });

for (var i = 0; i < alg_key_arr.length; i++)
{
    var alg_key = alg_key_arr[i];
    var this_alg = alg.func_enabled(alg_key, "R");
    if (this_alg.writeman || this_alg.writeuse)
    {
        // Ik mag de ruimte wijzigen dus voer wijziging uit
        var algUpd = buildTrackingUpdate("alg_ruimte", " alg_ruimte_key = " + alg_key, fields);
        // Submit the changed data
        var err = Oracle.Execute(algUpd.sql, true);
        if (err.friendlyMsg)
            warning = err.friendlyMsg;

        currentKenmerkenSQL = "SELECT k.alg_kenmerk_key"
                            + "     , ok.alg_onrgoedkenmerk_waarde"
                            + "     , k.alg_kenmerk_toonbaar"
                            + "     , k.fac_functie_key"
                            + "  FROM alg_onrgoedkenmerk ok"
                            + "     , alg_kenmerk k"
                            + " WHERE ok.alg_kenmerk_key = k.alg_kenmerk_key"
                            + "   AND ok.alg_onrgoedkenmerk_verwijder IS NULL"
                            + "   AND ok.alg_onrgoed_niveau = 'R'"
                            + "   AND ok.alg_onrgoed_key = " + alg_key;


        allKenmerkenSQL     = "SELECT " + lcl.xsql('k.alg_kenmerk_omschrijving', 'k.alg_kenmerk_key') + " kenmerk_omschrijving"
                            + "     , k.alg_kenmerk_kenmerktype kenmerk_kenmerktype"
                            + "     , k.alg_kenmerk_systeem     kenmerk_systeem"
                            + "     , k.alg_kenmerk_toonbaar    kenmerk_readonly"
                            + "     , k.alg_kenmerk_uniek       kenmerk_uniek"
                            + "     , fac_kenmerkdomein_key"
                            + "  FROM alg_kenmerk k"
                            + " WHERE k.alg_kenmerk_key = "; /* wordt in saveFlexkenmerken uitgebreid */

        var flextrack = saveFlexKenmerken(alg_key,
                                          { kenmerkTable: "alg_onrgoedkenmerk",
                                            kenmerkParentKey : "alg_onrgoed_key",
                                            kenmerkWaarde: "alg_onrgoedkenmerk_waarde",
                                            kenmerkKey: "alg_kenmerk_key",
                                            kenmerkToonbaar: "alg_kenmerk_toonbaar",
                                            currentKenmerkenSQL: currentKenmerkenSQL,
                                            allKenmerkenSQL: allKenmerkenSQL,
                                            requestQF: Request.Form,
                                            flexPath: "ALG/R",
                                            multiMode: true,
                                            tracking: true,
                                            module: "ALG",
                                            moduleName: "alg_onrgoed_niveau",
                                            moduleVal: "R"
                                          });

        if (flextrack && flextrack.length)
        {
            var update_string = L("lcl_alg_is_algrup") + "\n" + flextrack.join("\n");
            shared.trackaction("ALGRUP", alg_key, update_string);
            nr_edited++;
        }
    }
}

result = { success : true, refresh: true };

Response.Write(JSON.stringify(result));

ASPPAGE_END();
%>
