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


     File:         alg_edit_ruimtefunctie_save.asp
     Description:  SUBMIT-form
     Parameters:
     Context:
     Note:
*/ %>

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

<% FCLTHeader.Requires({ plugins:["jQuery"],
                         js: []
                       }) %>
<%
var autfunction = 'WEB_ALGMAN';
var authparams = user.checkAutorisation(autfunction)

  var srtruimte_lg_key = getQParamInt("srtruimte_lg_key", -1);
  var srtruimte_key = getFParamInt("srtruimte", -1);
  var loc_key = getFParamInt("locatiekey", -1);
  var bld_key = getFParamInt("gebouwkey", -1);

  var fields = [{ dbs: "alg_srtruimte_key", typ: "key",  frm: "srtruimte" },
                { dbs: "alg_srtruimte_lg_prijs", typ: "float",  frm: "prijs" },
                { dbs: "alg_srtruimte_lg_prijs2", typ: "float",  frm: "prijs2" },
                { dbs: "alg_srtruimte_lg_prijs3", typ: "float",  frm: "prijs3" },
                { dbs: "alg_srtruimte_lg_prijs4", typ: "float",  frm: "prijs4" },
                { dbs: "alg_srtruimte_lg_prijs5", typ: "float",  frm: "prijs5" },
                { dbs: "alg_gebouw_key", typ: "key", frm: "gebouwkey"}
               ];

  if (bld_key > 0)
    fields.push({dbs: "alg_locatie_key", typ: "key", val: -1}); // alg_locatie_key wordt dan null
  else
    fields.push({dbs: "alg_locatie_key", typ: "key", frm: "locatiekey"});

  var warning = "";

  if (srtruimte_lg_key == -1)
  {
    sql = "SELECT *"
        + " FROM alg_srtruimte_locatiegebouw"
        + " WHERE alg_srtruimte_key = " + srtruimte_key
        + (bld_key > 0
          ? " AND alg_gebouw_key = " + bld_key
          : " AND alg_gebouw_key IS NULL")
        + (loc_key > 0
          ? " AND alg_locatie_key = " + loc_key
          : " AND alg_locatie_key IS NULL");
    oRs = Oracle.Execute(sql);
    if (!oRs.eof)
    {
      warning = L("lcl_alg_room_type_exists");
    }
  }
__Log("srtruimte_lg_key = " + srtruimte_lg_key);

  if (warning == "")
  {
    if (srtruimte_lg_key > 0)
    {
      sql = buildUpdate("alg_srtruimte_locatiegebouw", fields)
          + " alg_srtruimte_lg_key = " + srtruimte_lg_key;

      var err = Oracle.Execute(sql, true);
      if (err.friendlyMsg)
         warning = err.friendlyMsg;
    }
    else
    {
      fields.push({  dbs: "alg_srtruimte_lg_key", typ: "key", seq: "alg_s_alg_srtruimte_lg_key" });
      var regIns = buildInsert("alg_srtruimte_locatiegebouw", fields);
      var srtruimte_lg_key = regIns.sequences["alg_srtruimte_lg_key"];

      sql = regIns.sql;
      var err = Oracle.Execute(sql, true);
      if (err.friendlyMsg)
          warning = err.friendlyMsg
    }
  }
%>
<html>
  <head>
    <%  FCLTHeader.Generate() %>
    <script>
        $(document).ready(function () {
            FcltMgr.closeDetail(window, { warning: "<%=safe.jsstring(warning)%>",
                                          refresh: true
                                         });
         } );
    </script>
  </head>
  <body>
  </body>
</html>
