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

     SUBMIT-form
*/ %>

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

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

var virtueel = (getFParamInt("has_wp_virt", 0) == 1) && (Request.Form("wp_virt").count == 1); // virtueel

// Bij impliciet altijd flex
var wp_type = (S("prs_werkplek_implicit") == 1)?1:getFParamInt("wp_type");

var authparams = alg.checkAutorisation();

var fields =  [// { dbs: "PRS_WERKPLEK_MODULE", typ: "varchar",  frm: "" },
                { dbs: "PRS_WERKPLEK_VOLGNR", typ: "number",  frm: "wp_volgnr" },
                { dbs: "PRS_WERKPLEK_OMSCHRIJVING", typ: "varchar",  frm: "wp_oms" },
                { dbs: "PRS_WERKPLEK_VASTOPP", typ: "number",  frm: "wp_vstopp_v" },
                { dbs: "PRS_WERKPLEK_OPP", typ: "number",  frm: "wp_opp" },
                { dbs: "PRS_WERKPLEK_VIRTUEEL", typ: "number",  val: (virtueel? 1 : 0) },
                { dbs: "PRS_WERKPLEK_TYPE", typ: "number",  val: wp_type },
                { dbs: "PRS_ALG_RUIMTE_KEY", typ: "key",  frm: "ruimtekey" } /*,
                { dbs: "PRS_WERKPLEK_GETEKEND", typ: "date",  frm: "" },
                { dbs: "PRS_WERKPLEK_DWGX", typ: "number",  frm: "" },
                { dbs: "PRS_WERKPLEK_DWGY", typ: "number",  frm: "" },
                { dbs: "PRS_WERKPLEK_DWGZ", typ: "number",  frm: "" },
                { dbs: "PRS_WERKPLEK_DWGROTATIE", typ: "number",  frm: "" },
                { dbs: "PRS_WERKPLEK_DWGSCHAAL", typ: "number",  frm: "" }*/ ];

var warning = "";
if (wp_key > 0)
  {
    sql = buildUpdate("prs_werkplek", fields)
        + "     prs_werkplek_key = " + wp_key;

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

    // Is de ruimte aangepast?
    var room_key_new = getFParamInt("ruimtekey");
    var sql = "SELECT prs_alg_ruimte_key"
            + "  FROM prs_werkplek"
            + " WHERE prs_werkplek_key = " + wp_key;
    var oRs = Oracle.Execute(sql);
    var room_key_old = oRs("prs_alg_ruimte_key").Value;
    oRs.Close();

    if (room_key_old != room_key_new)
    { // Werkplek verplaatsen
      wp_key = WPMove_PRS_WERKPLEK(wp_key, room_key_new);
    }

  }
else
  {
    fields.push({  dbs: "prs_werkplek_key",         typ: "key",      seq: "prs_s_prs_werkplek_key" });
    var regIns = buildInsert("prs_werkplek", fields);
    var wp_key = regIns.sequences["prs_werkplek_key"];

    sql = regIns.sql;
    var err = Oracle.Execute(sql, true);
    if (err.friendlyMsg)
        warning = err.friendlyMsg;
  }
  %>
// TODO: checkboxen ook saven? Jos?
<html>
  <head>
    <%  FCLTHeader.Generate() %>
    <script>
        $(document).ready(function () {
            FcltMgr.closeDetail(window, { wp_key: <%=wp_key%>,
                                          warning: "<%=safe.jsstring(warning)%>",
                                          keepForm: <%=warning? "true" : "false"%>
                                          }); } );
    </script>
  </head>
  <body>
  </body>
</html>
