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

    File:               edit_room.asp
    Description:        Toon het popupschermpje om een ruimte te bewerken
    Parameters:
        room_key        existing prj_ruimte.prj_ruimte_key
    Context:            Verhuizingen, wijzig ruimtefunctie of ruimteomschrijving
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../CAD/FGII.inc" -->

<%
var autfunction = "WEB_PRJBOF";
var authparams = user.checkAutorisation(autfunction);
%>
<html>
  <head>
<%  FCLTHeader.Generate(); %>
<%  var room_key = getQParamInt("room_key");
    var doUpdate = getFParamInt("doUpdate", 0) == 1;        // Moet ik bijwerken? (dan autoclose)

    if (doUpdate)
    {
        protectRequest.validateToken();
        srtruimte_key = getFParamInt("srt_room_key");
        room_descr = getFParam("room_descr", "");
        sql = "UPDATE prj_ruimte"
            + "   SET alg_srtruimte_key = " + srtruimte_key
            + "     , prj_ruimte_omschrijving = " + safe.quoted_sql(room_descr)
            + " WHERE prj_ruimte_key = " + room_key;
      	oRs = Oracle.Execute(sql); // Update the room
        %><script>FcltMgr.closeDetail(window, { refresh: true } );</script><%
    }
%>
  </head>

  <body class="modal" id="prjeditroom">
    <form name=u2 method=post>
<%
      var sql = "";

      if (room_key !=-1)
      {
        sql = " SELECT prj_ruimte_key"
            + ", r.alg_ruimte_aanduiding"
            + ", r.alg_srtruimte_omschrijving"
            + ", r.alg_srtruimte_key"
            + ", r.prj_ruimte_omschrijving"
            + "  FROM (SELECT alg_r.prj_ruimte_key,"
            + "               alg_r.prj_ruimte_omschrijving,"
            +      lcl.xsqla("alg_s.alg_srtruimte_omschrijving", "alg_s.alg_srtruimte_key")+","
            + "               alg_s.alg_srtruimte_key ,"
            + "               alg_g.alg_gebouw_code"
            + "               || '-'"
            + "               || TO_CHAR (alg_v.alg_verdieping_code)"
            + "               || '-'"
            + "               || alg_r.prj_ruimte_nr alg_ruimte_aanduiding"
            + "          FROM alg_gebouw alg_g,"
            + "               alg_verdieping alg_v,"
            + "               prj_ruimte alg_r,"
            + "               alg_srtruimte alg_s"
            + "         WHERE alg_v.alg_verdieping_key = alg_r.alg_verdieping_key"
            + "           AND alg_g.alg_gebouw_key = alg_v.alg_gebouw_key"
            + "           AND alg_r.alg_srtruimte_key = alg_s.alg_srtruimte_key(+)) r"
            + " WHERE r.prj_ruimte_key IN (" + room_key + ")"
            + " ORDER BY 1";
      }
      else
      {
        sql = "SELECT * FROM DUAL WHERE 1 = 0";
      }
      oRs = Oracle.Execute(sql);

      var room_key = oRs("prj_ruimte_key").value;                 // ruimte_key
      var room_aanduiding = oRs("alg_ruimte_aanduiding").value;          // ruimte aanduiding
      var srt_ruimte_descr = "" + oRs("alg_srtruimte_omschrijving").value;    // soort ruimte omschrijving
      var srt_ruimte_key = oRs("alg_srtruimte_key").value;           // soort ruimte key
      var room_descr = "" + oRs("prj_ruimte_omschrijving").value;          // ruimte omschrijving

      oRs.close();

      BLOCK_START("prjRoom", L("lcl_prj_room_edit"));
      ROFIELDTR("fld", L("lcl_room"), room_aanduiding);

      // Ruimte functie
      sql  = "SELECT   alg_srtruimte_key, "
           + lcl.xsqla("alg_srtruimte_omschrijving", "alg_srtruimte_key")
           + "    FROM alg_v_aanwezigsrtruimte "
           + "ORDER BY UPPER("+lcl.xsql("alg_srtruimte_omschrijving", "alg_srtruimte_key")+")";

      FCLTselector("srt_room_key", sql,
                  {  label: L("lcl_prj_room_srt"),
                     initKey: srt_ruimte_key,
                     emptyOption: "",
                     readonly: false,
                     required: true
                  });

      RWFIELDTR('room_descr', "fld", L("lcl_prj_room_descr"), room_descr);

      BLOCK_END();
      buttons = [{ title: L("lcl_submit"), action: "document.forms.u2.submit()"},
                 { title: L("lcl_cancel"), action:"FcltMgr.closeDetail(window, {refresh: false})"} ];
      CreateButtons(buttons)
%>

      <input type="hidden" name="room_key" id="room_key" value="<%=room_key%>">
      <input type="hidden" name="doUpdate" id="doUpdate" value="1">
<% IFACE.FORM_END(); %>
    </form>
  </body>
</html>
