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

<%
DOCTYPE_Disable = true;
%>

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

<%
// Build a building list
var locatie_key_arr = getFParamIntArray("locatie_key_arr", []); // Locatie: -2 als lege waarde meegegeven omdat -1 een geldige waarde is
var autlevel = getFParamInt("autlevel", -1);
var terrein = (getFParam("terrein", 0) == 1);

var filtClause = "";
if (autlevel > -1) // Efficiente versie van FAC_V_MY_PR**S_AFDELINGEN_WRITE
{
  filtClause +=" AND l.alg_locatie_key IN"
             + " (SELECT alg_locatie_key FROM fac_v_my_locations"
             + " WHERE prs_perslid_key = " + user_key
             + " AND niveau = " + autlevel + ")";
}

var sql = "SELECT g.alg_gebouw_key alg_key"
       //+ ", g.alg_gebouw_naam naam"
       + ", l.alg_locatie_code || ' - ' || g.alg_gebouw_code || ' ' || g.alg_gebouw_naam"
       + ", 1 niveau"
       + ", l.alg_locatie_omschrijving loc_text"
       + ", 'G' bttype"
       + " FROM alg_v_aanweziggebouw g, alg_locatie l"
       + " WHERE l.alg_locatie_key = g.alg_locatie_key"
       + (locatie_key_arr.length != 0 ? " AND g.alg_locatie_key IN (" + locatie_key_arr.join(",") + ")" : "")
       + filtClause;

if (terrein)
  sql += " UNION "
       + " SELECT t.alg_terreinsector_key alg_key"
       + ", alg_terreinsector_code || ' - ' || alg_terreinsector_naam naam"
       + ", 3 niveau"
       + ", l.alg_locatie_omschrijving loc_text"
       + ", 'T' bttype"
       + " FROM alg_v_aanwezigterreinsector t, alg_locatie l"
       + " WHERE l.alg_locatie_key = t.alg_locatie_key"
       + (locatie_key_arr.length != 0 ? " AND t.alg_locatie_key IN (" + locatie_key_arr.join(",") + ")" : "")
       + filtClause;

sql += " ORDER BY 3, 2";

FCLTselector("blds",
             sql,
             { initKey: -1,
               startmulti: true,
               size: 10,
               extraParamValue: "loc_text, bttype",
               emptyOption: "",
               initEmpty: true
             });
%>

