<%@ language = "JavaScript" %>
<% /*
    $Revision$
    $Id$
    File:               estate.asp
    Description:        A webservice call to fill real estate listsboxes in a remote system
    Parameters:
        action          Action: getLocations, getBuildings, getFloors, getRooms
        districtCode    Optional, Limits the locations to the locations connected to the district.
        locatieCode     Required for the getGebouw, getVerdieping en getRuimte actions, limits the buildings, floors and rooms
        gebouwCode      Required for the getVerdieping and getRuimte actions. Limits the floors and rooms.
        verdiepingCode  Required for the getRuimte actions. Limits the rooms.
    Context:            Client specific file to display room information from Facilitor
    Note:               Authorization is not checked (yet).
*/ %>

<%
ANONYMOUS_Allowed = 1;
DOCTYPE_Disable = 1;
Session("customerId") = 'PZHO';
Response.expires = -1
Response.contenttype = "text/xml"

var action           = getQParam("action", "");
var districtCode     = getQParam("districtCode", "");
var locatieCode      = getQParam("locatieCode", "-1");
var gebouwCode       = getQParam("gebouwCode", "-1");
var verdiepingCode   = getQParam("verdiepingCode", "-1");

%>

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

<%
tagName = "";
if (action == "getLocatie")
{
  tagName = "locatie";
  codeTag = "code";
  descTag = "omschrijving";
  sql = "SELECT alg_locatie_code code, alg_locatie_omschrijving description FROM alg_v_locatie_gegevens"
  if (districtCode != "")
  {
    sql += " WHERE alg_district_upper = UPPER (" + safe.quoted_sql(districtCode) + ")";
  }
  sql += " ORDER BY alg_locatie_omschrijving";
}
else if (action == "getGebouw")
{
  tagName = "gebouw";
  codeTag = "code";
  descTag = "naam";
  sql = "SELECT alg_gebouw_code code, alg_gebouw_naam description FROM alg_v_gebouw_gegevens"
      + " WHERE UPPER(alg_locatie_code) = UPPER (" + safe.quoted_sql(locatieCode) + ")"
      + " ORDER BY alg_gebouw_code";
}
else if (action == "getVerdieping")
{
  tagName = "verdieping";
  codeTag = "code";
  descTag = "omschrijving";
  sql = "SELECT alg_verdieping_code code, alg_verdieping_omschrijving description FROM alg_v_verdieping_gegevens vg, alg_gebouw g"
      + " WHERE g.alg_gebouw_key = vg.alg_gebouw_key "
      + "   AND UPPER(alg_locatie_code) = UPPER (" + safe.quoted_sql(locatieCode) + ")"
      + "   AND UPPER(alg_gebouw_code) = UPPER (" + safe.quoted_sql(gebouwCode) + ")"
      + " ORDER BY alg_verdieping_volgnr";
}
else if (action == "getRuimte")
{
  tagName = "ruimte";
  codeTag = "nr";
  descTag = "omschrijving";
  sql = "SELECT alg_ruimte_nr code, nvl(alg_ruimte_omschrijving,' ') description FROM alg_v_ruimte_gegevens rg, alg_gebouw g"
      + " WHERE g.alg_gebouw_key = rg.alg_gebouw_key "
      + "   AND UPPER(alg_locatie_code) = UPPER (" + safe.quoted_sql(locatieCode) + ")"
      + "   AND UPPER(alg_gebouw_code) = UPPER (" + safe.quoted_sql(gebouwCode) + ")"
      + "   AND UPPER(alg_verdieping_code) = UPPER (" + safe.quoted_sql(verdiepingCode) + ")"
      + " ORDER BY alg_ruimte_nr";
}
else
{
  Response.Status="500 Server error";
  Response.Write(Response.Status);
  Response.End;
}

Response.write("<?xml version='1.0' encoding='ISO-8859-1'?>");
Response.write("<facilitor>");

oRs = Oracle.Execute(sql);
while (!oRs.eof)
{
  Response.write("<" + tagName
                     + "><" + codeTag + ">"
                     + oRs('code').value
                     + "</" + codeTag + "><" + descTag + ">"
                     + oRs('description').value
                     + "</" + descTag + "></" + tagName + ">");
  oRs.MoveNext();
}
oRs.close();

Response.write("</facilitor>")
Response.end;
%>
