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

     SUBMIT-form
*/ %>

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

<% FCLTHeader.Requires({ plugins:["jQuery"],
                      js: []
                    }) %>
<%
var flr_key = getQParamInt( "flr_key" );

var onrgoedlvl = "V";
var this_alg = alg.func_enabled(flr_key, onrgoedlvl);
user.auth_required_or_abort(this_alg.writeman || (flr_key>0&&this_alg.writeuse));

  var fields =  [ { dbs: "alg_verdieping_omschrijving", typ: "varchar", frm: "flr_omschr" },
                  { dbs: "alg_verdieping_volgnr",       typ: "number",  frm: "flr_volgnr" },
                  { dbs: "alg_verdieping_code",         typ: "varchar", frm: "flr_code" },
                  { dbs: "alg_gebouw_key",              typ: "key",     frm: "gebouwkey" },
                  { dbs: "MLD_DIENSTNIVEAU_KEY",        typ: "key",     frm: "dienstniveau" }
                ];

var warning = "";
if (flr_key > 0)
  {
    sql = buildUpdate("alg_verdieping", fields)
        + "     alg_verdieping_key = " + flr_key;

    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
        warning = err.friendlyMsg;
  }
else
  {
    fields.push({  dbs: "alg_verdieping_key",         typ: "key",      seq: "alg_s_alg_onroerendgoed_keys" });
    var regIns = buildInsert("alg_verdieping", fields);
    var flr_key = regIns.sequences["alg_verdieping_key"];

    sql = regIns.sql;
    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
        warning = err.friendlyMsg;
  }

  if (!warning)
  {
      currentKenmerkenSQL = " SELECT k.ALG_kenmerk_key " +
                            "      , ok.alg_onrgoedkenmerk_waarde" +
                            "   FROM ALG_ONRGOEDKENMERK ok, ALG_KENMERK k " +
                            "  WHERE  k.ALG_KENMERK_KEY = ok.ALG_KENMERK_KEY " +
                            "    AND ALG_ONRGOEDKENMERK_VERWIJDER IS NULL " +
                            "    AND ALG_ONRGOED_NIVEAU = 'V' " +
                            "    AND ALG_ONRGOED_KEY = " + flr_key;
      saveFlexKenmerken(flr_key, "ALG_ONRGOEDKENMERK", "ALG_ONRGOED_KEY",
                                "ALG_ONRGOEDKENMERK_WAARDE", "ALG_KENMERK_KEY",
                                currentKenmerkenSQL, false,  //QueryForm, rest QueryString
                                "ALG_ONRGOED_NIVEAU", "V",
                                (flr_key<0),"ALG/V")
  }
  %>

<html>
  <head>
    <%  FCLTHeader.Generate() %>
    <script>
        $(document).ready(function ()
          { FcltMgr.closeDetail(window, { flr_key: <%=flr_key%>,
                                          warning: "<%=safe.jsstring(warning)%>",
                                          keepForm: <%=warning?"true":"false"%> }); } );
    </script>
  </head>
  <body>
  </body>
</html>
