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

     File:         prs_edit_afdeling_save.asp
     Description:  SUBMIT-form

*/ %>

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

<% FCLTHeader.Requires({ plugins:["jQuery"] }) %>
<%
  var afd_key = getQParamInt( "afd_key", -1 );
  var isNew = (afd_key<0);

  var fields =  [ { dbs: "prs_bedrijf_key", typ: "key",  frm: "bdr_key" },
                  { dbs: "prs_afdeling_parentkey", typ: "key",  frm: "afd_parkey" },
                  { dbs: "prs_afdeling_naam", typ: "varchar",  frm: "afd_naam" },
                  { dbs: "prs_afdeling_omschrijving", typ: "varchar",  frm: "afd_oms" },
                  { dbs: "prs_kostenplaats_key", typ: "key",  frm: "kstpl_key" },
                  { dbs: "mld_adres_key", typ: "key",  frm: "mld_adres" }];

var warning = "";
if (afd_key > 0)
  {
    sql = buildUpdate("prs_afdeling", fields)
        + "     prs_afdeling_key = " + afd_key;

    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
        warning = err.friendlyMsg;
  }
else
  {
    fields.push({  dbs: "prs_afdeling_key",         typ: "key",      seq: "prs_s_prs_afdeling_key" });
    var regIns = buildInsert("prs_afdeling", fields);
    var afd_key = regIns.sequences["prs_afdeling_key"];
    sql = regIns.sql;
    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
        warning = err.friendlyMsg;
  }

    if (!warning)
    {
       currentKenmerkenSQL = "SELECT kl.prs_kenmerk_key " +
                                "  , kl.prs_kenmerklink_waarde" +
                                "  FROM PRS_KENMERKLINK kl, PRS_KENMERK k " +
                                " WHERE  k.PRS_KENMERK_KEY = kl.PRS_KENMERK_KEY " +
                                "   AND PRS_KENMERKLINK_VERWIJDER IS NULL " +
                                "   AND PRS_LINK_KEY = " + afd_key;

       saveFlexKenmerken(afd_key, { kenmerkTable: "PRS_KENMERKLINK",
                                    kenmerkParentKey : "PRS_LINK_KEY",
                                    kenmerkWaarde: "prs_kenmerklink_waarde",
                                    kenmerkKey: "PRS_KENMERK_KEY",
                                    currentKenmerkenSQL: currentKenmerkenSQL,
                                    requestQF: Request.Form,
                                    moduleName: "PRS_KENMERKLINK_NIVEAU",
                                    moduleVal: "A",
                                    isNew: isNew,
                                    flexPath: "PRS/A"
                              });
    }
%>
<html>
  <head>
    <%  FCLTHeader.Generate() %>
    <script>
        $(document).ready(function () {
            FcltMgr.closeDetail(window, { afd_key: <%=afd_key%>,
                                          warning: "<%=safe.jsstring(warning)%>",
                                          keepForm: <%=warning?"true":"false"%>
                                         }); } );
    </script>
  </head>
  <body>
  </body>
</html>
