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

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

  var fields =  [ { dbs: "alg_district_key", typ: "number",  frm: "districtkey" },
                  { dbs: "alg_locatie_code", typ: "varchar",  frm: "loc_code" },
                  { dbs: "alg_locatie_omschrijving", typ: "varchar",  frm: "loc_omsch" },
                  { dbs: "alg_locatie_adres", typ: "varchar",  frm: "bez_adres" },
                  { dbs: "alg_locatie_postcode", typ: "varchar",  frm: "bez_postc" },
                  { dbs: "alg_locatie_plaats", typ: "varchar",  frm: "bez_plaats" },
                  { dbs: "alg_locatie_land", typ: "varchar",  frm: "bez_land" },
                  { dbs: "alg_locatie_post_adres", typ: "varchar",  frm: "pst_adres" },
                  { dbs: "alg_locatie_post_postcode", typ: "varchar",  frm: "pst_postc" },
                  { dbs: "alg_locatie_post_plaats", typ: "varchar",  frm: "pst_plaats" },
                  { dbs: "alg_locatie_post_land", typ: "varchar",  frm: "pst_land" },
                  { dbs: "alg_locatie_verantw", typ: "varchar",  frm: "loc_vw" },
                  { dbs: "alg_locatie_verantw_tel", typ: "varchar",  frm: "loc_vwtel" },
                  { dbs: "MLD_DIENSTNIVEAU_KEY",          typ: "key",      frm: "dienstniveau" },
                  { dbs: "alg_locatie_x", typ: "float",  frm: "loc_x" },
                  { dbs: "alg_locatie_y", typ: "float",  frm: "loc_y" },
                  { dbs: "alg_locatie_email", typ: "varchar",  frm: "loc_mail" }];

var warning = "";
if (loc_key > 0)
  {
    sql = buildUpdate("alg_locatie", fields)
        + "     alg_locatie_key = " + loc_key;

    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
        warning = err.friendlyMsg;
  }
else
  {
    fields.push({  dbs: "alg_locatie_key",         typ: "key",      seq: "alg_s_alg_locatie_key" });
    var regIns = buildInsert("alg_locatie", fields);
    var loc_key = regIns.sequences["alg_locatie_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 = 'L' " +
                            "    AND ALG_ONRGOED_KEY = " + loc_key;
      saveFlexKenmerken(loc_key, "ALG_ONRGOEDKENMERK", "ALG_ONRGOED_KEY",
                                "ALG_ONRGOEDKENMERK_WAARDE", "ALG_KENMERK_KEY",
                                currentKenmerkenSQL, false,
                                "ALG_ONRGOED_NIVEAU", "L",
                                (loc_key<0),"ALG/L")
}
  %>

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