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

    File:           mld_kenmerk_save.asp
    Description:    save_script van mld_kenmerk.asp
    Parameters:     kenmerk_key


    Context:
    Note:

*/ %>
<%
var JSON_Result = true;
%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/save2db.inc" -->
<!-- #include file="../Shared/json2.js" -->

<%
var mode=getQParam("mode", "show");
var kenmerk_key  = getQParamInt("kenmerk_key", -1);
var kenmerk_niveau = getQParam("niveau", "-1");

var authparams = user.checkAutorisation("WEB_MLDMGT");

var fields =  [ { dbs: "mld_kenmerk_volgnummer",        typ: "number",  frm: "volgnummer" },
                { dbs: "mld_kenmerk_niveau",            typ: "varchar", frm: "niveau" }, // kan ook een vakgroep of srtdisc zijn!
                { dbs: "mld_stdmelding_key",            typ: "key",     frm: "stdmelding_key" }, // kan ook een vakgroep of srtdisc zijn!
                { dbs: "mld_srtkenmerk_key",            typ: "key",     frm: "srtkenmerk_key" },
                { dbs: "mld_kenmerk_verplicht",         typ: "key",     frm: "verplicht" },
                { dbs: "mld_kenmerk_groep",             typ: "number",  frm: "groep" },
                { dbs: "mld_kenmerk_verplicht_status",  typ: "key",     frm: "verplicht_status" },
                { dbs: "mld_kenmerk_hint",              typ: "varchar", frm: "hint" },
                { dbs: "mld_kenmerk_regexp",            typ: "varchar", frm: "regexp" },
                { dbs: "mld_kenmerk_toonbaar",          typ: "check",   frm: "toonbaar" },
                { dbs: "mld_kenmerk_default",           typ: "varchar", frm: "kenmerk_default" }
              ];

if (kenmerk_key > 0 && mode=="save")
{
    var sql = buildUpdate("mld_kenmerk", fields) + " mld_kenmerk_key = " + kenmerk_key;
    var err = Oracle.Execute(sql, true);
}
else if (kenmerk_key > 0 && mode=="delete")
{
    sql = "UPDATE mld_kenmerk"
        + "   SET mld_kenmerk_VERWIJDER=SYSDATE"
        + " WHERE mld_kenmerk_key = " + kenmerk_key;
    var err = Oracle.Execute(sql, true);
}
else
{
    fields.push({  dbs: "mld_kenmerk_key",      typ: "key",    seq: "mld_s_mld_kenmerk_key" });
    var mldIns = buildInsert("mld_kenmerk", fields);
    var kenmerk_key = mldIns.sequences["mld_kenmerk_key"];
    var err = Oracle.Execute(mldIns.sql, true);
}
if (err.friendlyMsg)
    abort_with_warning(err.friendlyMsg);

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