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

     File:               PRJ/rap_prj8_save.asp
     Description:
     Parameters:
     Note:
*/ %>

<%
var JSON_Result = true;
%>
<!--#include file="../Shared/common.inc"-->
<%

protectRequest.validateToken();
/***** Get webform parameters *****/
var actie = getFParam("actie");
/***** End get webform parameters *****/


function doPlace()
{
  note_key = getFParamInt("note_key");
  room_key = getFParamInt("room_key", -1);
  dwgX = getFParam("dwgX");
  dwgY = getFParam("dwgY");

  // buiten de plattegrond gedropt doen we niks mee.
  // overweging had ook kunnen zijn dat we de ruimte niet aanpassen maar de xy wel
  // hiervoor kwam er echter een Aiai, dus dan is dit zeker beter.
  if (room_key > 0)
  {
      var sql = "SELECT 'x'"
              + "  FROM prj_scenario_note"
              + " WHERE prj_scenario_note_key = " + note_key;

      if (Oracle.Execute(sql).eof)
        sql = "INSERT INTO prj_scenario_note "
            + " ( prj_scenario_note_key"
            + " , prj_scenario_note_dwgX"
            + " , prj_scenario_note_dwgY"
            + " , alg_verdieping_key"
            + " , prj_ruimte_key"
            + ") VALUES"
            + " (" + prj_scenario_note_key
            + " ," + dwgX
            + " ," + dwgY
            + " ," + floorKey
            + " ," + room_key
            + " )"
      else
        sql = "UPDATE prj_scenario_note"
            + "   SET prj_scenario_note_dwgX = " + dwgX
            + "     , prj_scenario_note_dwgY = " + dwgY
            + "     , prj_ruimte_key = " + room_key
            + "     , prj_scenario_note_aanmaak = SYSDATE"  // mutatiedatum is relevanter dan ooit aangemaakt
            + " WHERE prj_scenario_note_key = " + note_key
      Oracle.Execute(sql)
  }
}

var message = "";
switch (actie)
{
  case 'doplace': doPlace();
       break;
}
var result = {message: message, success: true};
Response.Write(JSON.stringify(result));

ASPPAGE_END();
%>
