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

     File:         kpn_edit_kpncat_save.asp
     Status:
     Description:  SUBMIT-form
*/ %>

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

<% FCLTHeader.Requires({ plugins:["jQuery"] }) %>
<%
var autfunction = 'WEB_FINMSU';
var authparams = user.checkAutorisation(autfunction)
user.auth_required_or_abort(authparams.ALGwritelevel < 9);

var kpn_key = getFParamInt( "kpn_key");
var kpndisc_key = getFParamInt("kpndisc_key");

var fields =  [ { dbs: "prs_kostenplaats_key",        typ: "key",   frm: "kpn_key" }
              , { dbs: "ins_discipline_key",          typ: "key",   frm: "kpn_disc" }
              , { dbs: "prs_kostenplaatsdisc_limiet", typ: "float", frm: "kpn_limiet" }
              ];

var warning = "";
if (kpndisc_key > 0)
  {
    sql = buildUpdate("prs_kostenplaatsdisc", fields)
        + "     prs_kostenplaatsdisc_key = " + kpndisc_key;

    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
        warning = err.friendlyMsg;
  }
else
  {
    fields.push({ dbs: "prs_kostenplaatsdisc_key", typ: "key", seq: "prs_s_prs_kostenplaatsdisc_key" });
    var regIns = buildInsert("prs_kostenplaatsdisc", fields);
    kpndisc_key = regIns.sequences["prs_kostenplaatsdisc_key"];
    sql = regIns.sql;
    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
        warning = err.friendlyMsg;
  }
%>
<html>
  <head>
    <%  FCLTHeader.Generate() %>
    <script>
        $(document).ready(function () {
            FcltMgr.closeDetail(window, { kpndisc_key: <%=kpndisc_key%>,
                                          warning: "<%=safe.jsstring(warning)%>",
                                          keepForm: <%=warning?"true":"false"%>
                                         });
         } );
    </script>
  </head>
  <body>
  </body>
</html>
