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

    File:               alg_edit_locatie_multi_save.asp
    Description:        save script van alg_edit_locatie_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 loc_key_arr = getQParamIntArray("loc_keys");
var warning = "";
var result = {};
var nr_edited = 0;
var fields = [];

if (Request.Form("vervaldatum").Count == 1 && getFParam("check_vervaldatum", "off") == "on")
    fields.push({ dbs: "alg_locatie_vervaldatum",  typ: "date",   frm: "vervaldatum", track: L("lcl_alg_vervaldatum") });
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("loc_vw").Count == 1 && getFParam("check_loc_vw", "off") == "on")
    fields.push({ dbs: "alg_locatie_verantw", typ: "varchar", frm: "loc_vw", track: L("lcl_estate_locatie_man_verantw") });
if (Request.Form("loc_vwtel").Count == 1 && getFParam("check_loc_vwtel", "off") == "on")
    fields.push({ dbs: "alg_locatie_verantw_tel", typ: "varchar", frm: "loc_vwtel", track: L("lcl_estate_locatie_man_verantw_tel") });

for (var i = 0; i < loc_key_arr.length; i++)
{
    var alg_key = loc_key_arr[i];
    var this_alg = alg.func_enabled(alg_key, "L");
    if (this_alg.writeman || this_alg.writeuse)
    {
        var algUpd = buildTrackingUpdate("alg_locatie", " alg_locatie_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 = 'L'"
                            + "   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/L",
                            multiMode: true,
                            tracking: true,
                            module: "ALG",
                            moduleName: "alg_onrgoed_niveau",
                            moduleVal: "L",
                            isNew: false
                          });

        if (flextrack && flextrack.length)
        {
            var update_string = L("lcl_alg_is_alglup") + "\n" + algUpd.trackarray.join("\n");
            if (flextrack && flextrack.length)
                update_string += flextrack.join("\n");
            shared.trackaction("ALGLUP", alg_key, update_string);
        }
    }
}

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

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

ASPPAGE_END();
%>
