<%@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 bld_key = getQParamInt( "bld_key" );;

  var beginuur = getFParamFloat("bld_beginuur", -2);
  if (beginuur == -1)
    beginuur = "";

  var einduur = getFParamFloat("bld_einduur", -2);
  if (einduur == -1)
    einduur = "";

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

  var fields =  [ { dbs: "alg_locatie_key",           typ: "key",     frm: "locatiekey" },
                  { dbs: "alg_srtgebouw_key",         typ: "key",     frm: "bld_srtkey" },
                  { dbs: "alg_gebouw_naam",           typ: "varchar", frm: "bld_naam" },
                  { dbs: "alg_gebouw_code",           typ: "varchar", frm: "bld_code" },
                  { dbs: "alg_gebouw_omschrijving",   typ: "varchar", frm: "bld_descr" },
                  { dbs: "alg_gebouw_email",          typ: "varchar", frm: "bld_email" },
                  { dbs: "alg_gebouw_getekend",       typ: "date",    frm: "bld_teken" },
                  { dbs: "alg_gebouw_bruto_vloeropp", typ: "float",  frm: "bld_opp" },
                  { dbs: "alg_gebouw_omtrek",         typ: "number",  frm: "bld_omtrek" },
                  { dbs: "alg_gebouw_inhoud",         typ: "number",  frm: "bld_inhoud" },
                  { dbs: "alg_gebouw_opmerking",      typ: "varchar", frm: "bld_opmerk" },
                  { dbs: "mld_adres_key",             typ: "key",     frm: "mld_adres" },
                  { dbs: "prs_kostenplaats_key",      typ: "key",     frm: "prs_kstpl" },
                  { dbs: "mld_dienstniveau_key",      typ: "key",     frm: "dienstniveau" },
                  { dbs: "alg_gebouw_ordernr",        typ: "varchar", frm: "bld_ordrnr" },
                  { dbs: "alg_gebouw_dwgx",           typ: "float",   frm: "bld_dwgx" },
                  { dbs: "alg_gebouw_dwgy",           typ: "float",   frm: "bld_dwgy" },
                  { dbs: "alg_gebouw_x",              typ: "float",   frm: "bld_x" },
                  { dbs: "alg_gebouw_y",              typ: "float",   frm: "bld_y" },
                  { dbs: "alg_gebouw_bez",            typ: "check",   frm: "bld_bez" },
                  { dbs: "alg_gebouw_werkdagen",      typ: "check0",  frm: "bld_werkdagen" },
                  { dbs: "prs_perslid_key_verantw",   typ: "key",     frm: "verantw" }];

  if (beginuur != -2)
    fields.push({ dbs: "alg_gebouw_beginuur",       typ: "float",   val: beginuur });
  if (einduur != -2)
    fields.push({ dbs: "alg_gebouw_einduur",        typ: "float",   val: einduur });

  var warning = "";
  if (bld_key > 0)
  {
    sql = buildUpdate("alg_gebouw", fields)
        + "     alg_gebouw_key = " + bld_key;

    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
        warning = err.friendlyMsg;
  }
  else
  {
    fields.push({  dbs: "alg_gebouw_key",         typ: "key",      seq: "alg_s_alg_onroerendgoed_keys" });
    var regIns = buildInsert("alg_gebouw", fields);
    var bld_key = regIns.sequences["alg_gebouw_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 = 'G' " +
                            "    AND ALG_ONRGOED_KEY = " + bld_key;
      saveFlexKenmerken(bld_key, "ALG_ONRGOEDKENMERK", "ALG_ONRGOED_KEY",
                                "ALG_ONRGOEDKENMERK_WAARDE", "ALG_KENMERK_KEY",
                                currentKenmerkenSQL, false,  //QueryForm, rest QueryString
                                "ALG_ONRGOED_NIVEAU", "G",
                                (bld_key<0),"ALG/G")
  }
%>

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