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

<%
DOCTYPE_Disable = true;
%>

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

<%
// Build a kenmerken list
var init_key = getQParamInt("init_key", -1); // Initiële waarde
var kdomein_key = getQParamInt("kdomein_key", -1); // Key van eigen tabel
var parent_key = getQParamInt("parent_key", -1); // Parent_key
var hideVervallen = getQParamInt("hideVervallen", 0) == 1; // hideVervallen
var required = getQParamInt("required", 0); // Required

var wheres = [];
var dsql = "SELECT fac_kenmerkdomein_objectnaam"
         + "     , fac_kenmerkdomein_kolomnaam"
         + "     , fac_kenmerkdomein_kolomtxt"
         + "     , fac_kenmerkdomein_verval"
         + "     , fac_usrtab_key"
         + " FROM fac_kenmerkdomein"
         + " WHERE fac_kenmerkdomein_key = " + kdomein_key;
var oRs_d = Oracle.Execute(dsql);
var facusrtab_key = oRs_d("fac_usrtab_key").value;

var fac_obj = oRs_d("fac_kenmerkdomein_objectnaam").value;
var fac_naam = oRs_d("fac_kenmerkdomein_kolomnaam").value;
var fac_kolom = oRs_d("fac_kenmerkdomein_kolomtxt").value;
var fac_verval = oRs_d("fac_kenmerkdomein_verval").value;
oRs_d.Close();

if (fac_obj == "FAC_USRDATA")
{
  var fsql = "SELECT fac_usrdata_key"
           + "     , " + lcl.xsql('fac_usrdata_omschr', 'fac_usrdata_key')
             + "     || CASE WHEN fac_usrdata_vervaldatum < SYSDATE THEN " + safe.quoted_sql(L("lcl_inactive_data_suffix")) + " END"
             + "     fac_usrdata_omschr"
           + "     , fac_usrdata_vervaldatum"
           + "  FROM fac_usrdata "
           + " WHERE fac_usrtab_key = " + facusrtab_key
           + "   AND fac_usrdata_verwijder IS NULL"   // gaat nooit om readonly, dus altijd niet-verwijderden
           + (parent_key > 0
             ? " AND fac_usrdata_parentkey = " + parent_key
             : "")
           + (hideVervallen
             ? " AND (fac_usrdata_vervaldatum IS NULL OR fac_usrdata_vervaldatum > SYSDATE)"
             : "")
           + " ORDER BY fac_usrdata_volgnr, 2";
}
else
{
  var fsql = "SELECT " + fac_naam + " fac_usrdata_key"
           + "     , " + fac_kolom
                       + (fac_verval
                         ? " || CASE WHEN  " + fac_verval + " < SYSDATE THEN " + safe.quoted_sql(L("lcl_inactive_data_suffix")) + " END"
                         : ""
                         )
                       + " fac_usrdata_omschr"
           + "     , " + (fac_verval
                         ? fac_verval
                         : "NULL"
                         )
                       + " fac_usrdata_vervaldatum"
           + "  FROM " + fac_obj
           + " WHERE 1=1"
           + ((hideVervallen && fac_verval)
             ? " AND (" + fac_verval + " IS NULL OR " + fac_verval + " > SYSDATE)"
             : "")
           + "  ORDER BY 2, 1";
}

FCLTselectorOptions(fsql,
                    { initKey: init_key,
                      emptyOption: "",
                      selectjustone: required == 1, // Als required en er is maar 1 waarde beschikbaar dan deze selecteren
                      required: required
                    });
%>

<% ASPPAGE_END(); %> 
