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

    File:               SuggestOutlet.asp
    Description:        Suggereer outlets
    Parameters:         k               De eerste paar letters
                        alg_level_read  Autorisatie level
    Globals:
    Context:
    Note:
*/ %>
<%
JSON_Result = true;
%>
<!--#include file="../../Shared/common.inc"-->
<!--#include file="./suggest.inc"-->

<%
var chars = getQParam("k", "");
var bAll = getQParamInt("SuggestAll", 0) == 1;
var alg_level_read = getQParamInt("alg_level_read");
srtdeel_key_wallplate = 645;
srtdeel_key_outlet = 646;

chars = chars.replace(/\*/g,"%");

sql = " SELECT id.ins_deel_key"
    + ", id.ins_deel_omschrijving"
    + ", alg_l.alg_locatie_code"
      + " || '-'"
      + " || alg_g.alg_gebouw_code"
      + " || '-'"
      + " || alg_v.alg_verdieping_code"
      + " || '-'"
      + " || alg_r.alg_ruimte_nr plaats"
    + ", id.ins_deel_parent_key"
    + "  FROM ins_deel id, alg_ruimte alg_r"
    + "     , alg_verdieping alg_v"
    + "     , alg_gebouw alg_g"
    + "     , alg_locatie alg_l"
    + " WHERE id.ins_srtdeel_key = " + srtdeel_key_outlet
    + "   AND id.ins_deel_upper like " + safe.quoted_sql_wild(chars + "%")
    + "   AND id.ins_alg_ruimte_key = alg_r.alg_ruimte_key"
    + "   AND id.ins_deel_verwijder IS NULL"
    + "   AND alg_r.alg_verdieping_key = alg_v.alg_verdieping_key"
    + "   AND alg_v.alg_gebouw_key = alg_g.alg_gebouw_key"
    + "   AND alg_g.alg_locatie_key = alg_l.alg_locatie_key"

if (alg_level_read >= 0)
  sql += " AND id.ins_alg_ruimte_key IN (SELECT alg_ruimte_key FROM fac_v_my_rooms"
       + " WHERE prs_perslid_key = " + user_key + " AND niveau = " + alg_level_read + ")";

WriteResult(sql, bAll, "ins_deel_omschrijving", "ins_deel_key", "plaats");
%>
