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

    File:               tek_file_save.asp
    Description:        Update filename of drawing.
    Parameters:
        file            required, new name of drawing.
        cad_tek_key     optional, cad_tek_key of table cad_tekening which has to be changed.
    Note:               De tekening wordt direct gescant nadat is opgeslagen.

*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file='../CAD/FGII.inc' -->
<!-- #include file="../shared/save2db.inc" -->
<!-- #include file='./cad_scan_dwf.inc' -->

<%
protectRequest.validateToken();
FCLTHeader.Requires({ plugins:["jQuery"] })
%>

<%
var file = getFParam("file", "");
var cad_tek_key = getFParamInt("cad_tek_key", -1);
var loc_key = getFParamInt("loc_key", -1);
var flr_key = getFParamInt("flr_key", -1);

var warning = "";

if (cad_tek_key > 0)
{
  if (file != "")
    sql = "UPDATE cad_tekening"
        + "   SET cad_tekening_filenaam = " + safe.quoted_sql(file)
        + " WHERE cad_tekening_key = " + cad_tek_key;
  else
    sql = "DELETE FROM cad_tekening"
        + " WHERE cad_tekening_key = " + cad_tek_key;

  var err = Oracle.Execute(sql, true);
  if (err.friendlyMsg)
    warning = err.friendlyMsg;
}
else
  if (file != "")
  {
    var cadfields = [ { dbs: "cad_tekening_key",      typ: "key",     seq: "cad_s_cad_tekening_key" },
                      { dbs: "cad_tekening_filenaam", typ: "varchar", val: file },
                      { dbs: "alg_locatie_key",       typ: "key",     val: loc_key },
                      { dbs: "cad_tekening_type",     typ: "varchar", val: "P" }
                    ];
    if (flr_key > 0)
        cadfields.push({ dbs: "alg_verdieping_key",   typ: "key",     val: flr_key });
    var cadIns = buildInsert("cad_tekening", cadfields);
    var cad_tek_key = cadIns.sequences["cad_tekening_key"];
    var err = Oracle.Execute(cadIns.sql, true);
    if (err.friendlyMsg)
      warning = err.friendlyMsg;
  }
if (file != "" && warning == "")
{
  var warning = scanDWF(cad_tek_key, 1);
}
%>
<html>
  <head>
<%  FCLTHeader.Generate() %>
    <script>
      $(document).ready(function () {
          FcltMgr.closeDetail(window, { warning: "<%=safe.jsstring(warning)%>",
                                        keepForm: <%=warning?"true":"false"%>
                                      }); } );
    </script>
  </head>
  <body>
  </body>
</html>
