<%@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);

  //track wel toegevoegd maar wordt nog niks mee gedaan
  var fields =  [ { dbs: "prs_bedrijf_key",           typ: "key",     frm: "bdr_key",       track: L("lcl_prs_dept_company"), foreign: "prs_bedrijf" },
                  { dbs: "prs_afdeling_parentkey",    typ: "key",     frm: "afd_parkey",    track: L("lcl_prs_organisatie"),  foreign: "prs_afdeling" },
                  { dbs: "prs_afdeling_naam",         typ: "varchar", frm: "afd_naam",      track: L("lcl_prs_dept_name") },
                  { dbs: "prs_afdeling_omschrijving", typ: "varchar", frm: "afd_oms",       track: L("lcl_prs_dept_desc") },
                  { dbs: "prs_kostenplaats_key",      typ: "key",     frm: "kstpl_key",     track: L("lcl_prs_dept_kosten"),  foreign: "prs_kostenplaats" },
                  { dbs: "prs_perslid_key_verantw",   typ: "key",     frm: "prs_verantwkey",track: L("lcl_prs_dept_verantw"), foreign: "prs_perslid" },
                  { dbs: "mld_adres_key",             typ: "key",     frm: "mld_adres",     track: L("lcl_delivery_address"), foreign: "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"
                           + "     , k.prs_kenmerk_toonbaar"
                           + "     , k.fac_functie_key"
                           + "  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",
                                    kenmerkToonbaar: "prs_kenmerk_toonbaar",
                                    currentKenmerkenSQL: currentKenmerkenSQL,
                                    requestQF: Request.Form,
                                    module: "PRS",
                                    moduleName: "prs_kenmerklink_niveau",
                                    moduleVal: "A",
                                    isNew: isNew,
                                    flexPath: "PRS/A"
                              });
    }
%>
<html>
  <head>
    <%  FCLTHeader.Generate() %>
    <script>
        $(function ()
        {
          FcltMgr.closeDetail(window, { afd_key: <%=afd_key%>,
                                        warning: "<%=safe.jsstring(warning)%>",
                                        keepForm: <%=warning?"true":"false"%>
                                       });
        });
    </script>
  </head>
  <body>
  </body>
</html>
<% ASPPAGE_END(); %>
