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

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

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="./ins.inc" -->
<!-- #include file="../shared/save2db.inc" -->
<!-- #include file="../Shared/kenmerk_common.inc" -->
<%
FCLTHeader.Requires({ plugins:["jQuery"],
                      js: []
                    });

var authparams = user.checkAutorisation("WEB_INSMGT");
user.auth_required_or_abort(authparams.ALGwritelevel < 9 && authparams.PRSwritelevel < 9);

var srtdeel_key = getQParamInt("srtdeel_key", -1);
var isNew = (srtdeel_key < 0);

var binding = (getFParam("bindR", "off") == "on" ? BIND_RUIMTE : 0) +
              (getFParam("bindW", "off") == "on" ? BIND_WERKPL : 0) +
              (getFParam("bindT", "off") == "on" ? BIND_TERREI : 0) +
              (getFParam("bindA", "off") == "on" ? BIND_AFDELI : 0) +
              (getFParam("bindP", "off") == "on" ? BIND_PERSOO : 0) +
              (getFParam("bindI", "off") == "on" ? BIND_INSDEE : 0);

var fields =  [ { dbs: "ins_srtgroep_key",           typ: "key",          frm: "srtgroep" },
                { dbs: "ins_srtdeel_code",           typ: "varchar",      frm: "srtcode" },
                { dbs: "ins_srtdeel_omschrijving",   typ: "varchar",      frm: "srtomschr" },
                { dbs: "ins_srtdeel_volgnr",         typ: "number",       frm: "srtdeel_volgnr" },
                { dbs: "ins_srtdeel_eenheid",        typ: "varchar",      frm: "srtdeel_eenheid" },
                //{ dbs: "ins_srtdeel_dimensie",       typ: "varchar",      frm: "srtdeel_dimensie" },
                { dbs: "ins_srtdeel_acadsymbol",     typ: "varchar",      frm: "srtdeel_acadsymbol" },
                { dbs: "ins_srtdeel_uitleenbaar",    typ: "check",        frm: "srtdeel_uitleenbaar" },
                { dbs: "ins_srtdeel_nr",             typ: "varchar",      frm: "srtdeel_nr" },
                { dbs: "prs_bedrijf_key",            typ: "key",          frm: "prs_bedrijf_key" },
                { dbs: "ins_srtdeel_vervaldatum",    typ: "date",         frm: "vervaldatum" },
                { dbs: "ins_srtdeel_image",          typ: "varchar",      frm: "srtdeel_image" },
                { dbs: "ins_srtdeel_module",         typ: "varchar",      val: "INS" },
                { dbs: "ins_srtdeel_binding",        typ: "number",       val: binding }];

var warning = "";

if (srtdeel_key > 0)
{
    sql = buildUpdate("ins_srtdeel", fields) + " ins_srtdeel_key = " + srtdeel_key;

    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
      warning = err.friendlyMsg;
}
else
{ // nieuw objectsoort
    fields.push({ dbs: "ins_srtdeel_key",            typ: "key",          seq: "ins_s_ins_srtinst_keys" });
    var regIns = buildInsert("ins_srtdeel", fields);
    var srtdeel_key = regIns.sequences["ins_srtdeel_key"];
    var err = Oracle.Execute(regIns.sql, true);

    if (err.friendlyMsg)
      warning = err.friendlyMsg;
}

if (!warning)
{
    var currentKenmerkenSQL = "SELECT v.ins_kenmerk_key, v.ins_kenmerkdeel_waarde"
                            + "  FROM ins_kenmerkdeel v, ins_kenmerk ik"
                            + " WHERE v.ins_kenmerkdeel_verwijder IS NULL"
                            + "   AND v.ins_kenmerk_key = ik.ins_kenmerk_key"
                            + "   AND ik.ins_kenmerk_bewerkniveau = 'S'"
                            + "   AND v.ins_deel_key = " + srtdeel_key; // herge/misbruik ins_deel_key

    saveFlexKenmerken(srtdeel_key,
                      { kenmerkTable: "ins_kenmerkdeel",
                        kenmerkParentKey : "ins_deel_key", // zal in de praktijk srtdeel_key zijn
                        kenmerkWaarde: "ins_kenmerkdeel_waarde",
                        kenmerkKey: "ins_kenmerk_key",
                        currentKenmerkenSQL: currentKenmerkenSQL,
                        requestQF: Request.Form,
                        isNew: isNew,
                        flexPath: "INS/S",
                        module: "INS"
                      });
}
%>
<html>
  <head>
    <%  FCLTHeader.Generate() %>
    <script>
        $(document).ready(function()
                          {FcltMgr.closeDetail(window, { srtdeel_key: <%=srtdeel_key%>,
                                                         warning: "<%=safe.jsstring(warning)%>",
                                                         keepForm: <%=warning != ""? "true" : "false"%>,
                                                         refresh: true
                                                       });
                          });
    </script>
  </head>
  <body>
  </body>
</html>
