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

    File:        fac_kenmerkdomein_search_list.asp
    Description: Vangt de parameters van fac_kenmerkdomein_search op en verwerkt die tot een lijst
    Parameters:
    Context:     Vanuit fac_kenmerkdomein_search.asp
    Note:
*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/resultset_table_v2.inc" -->
<%

var searchtext = getQParam("searchtext", null);
var fkdmodule = getQParamSafe("fkdmodule", -1);

var outputmode = getQParamInt("outputmode", 0); //  0 = screen, 1 = print, 2 = excel etc
var showall = getQParamInt("showall", 0) == 1;

var authparams = user.checkAutorisation("WEB_PRSSYS");  // lager

%>
<html>
  <head>
<%  FCLTHeader.Generate({outputmode: outputmode}); %>
    <script>
        function fkd_edit(row)
        {
          var domein_key = row.getAttribute("ROWKEY");
          var url = "appl/fac/fac_kenmerkdomein.asp?domein_key="+domein_key;
          FcltMgr.openDetail(url, "<%=L("lcl_kenmerkdomein")%>", {callback: FcltMgr.reload } );
        }
    </script>
  </head>

  <body>
<%
    var sql = "SELECT fkd.fac_kenmerkdomein_key,"
            + "       fkd.fac_kenmerkdomein_module,"
            + "       fkd.fac_kenmerkdomein_omschrijving,"
            + "       fkd.fac_kenmerkdomein_upper,"
            + "       fkd.fac_kenmerkdomein_objectnaam,"
            + "       fkd.fac_kenmerkdomein_kolomnaam,"
            + "       fkd.fac_kenmerkdomein_kolomtxt,"
//            + "       fkd.fac_usrtab_key,"
            + "       fut.fac_usrtab_omschrijving,"
            + "       COUNT(fud.fac_usrdata_key) aantal"
            + "  FROM fac_kenmerkdomein fkd, fac_usrtab fut, fac_usrdata fud"
            + " WHERE     fkd.fac_kenmerkdomein_verwijder IS NULL"
            + "   AND     fkd.fac_usrtab_key = fut.fac_usrtab_key(+)"
            + "   AND     fut.fac_usrtab_key = fud.fac_usrtab_key(+)"
            + (searchtext?" AND fac_kenmerkdomein_upper LIKE " + safe.quoted_sql_wild("%"+searchtext + "%") :"")
            + (fkdmodule!=-1 ? " AND fac_kenmerkdomein_module = " + safe.quoted_sql(fkdmodule) :"")
            + " GROUP BY fkd.fac_kenmerkdomein_key,"
            + "       fkd.fac_kenmerkdomein_module,"
            + "       fkd.fac_kenmerkdomein_omschrijving,"
            + "       fkd.fac_kenmerkdomein_upper,"
            + "       fkd.fac_kenmerkdomein_objectnaam,"
            + "       fkd.fac_kenmerkdomein_kolomnaam,"
            + "       fkd.fac_kenmerkdomein_kolomtxt,"
 //           + "       fkd.fac_usrtab_key,"
            + "       fut.fac_usrtab_omschrijving"
            + "   ORDER BY fac_kenmerkdomein_upper";

    function fnDomeinTabel(oRs)
    {
        return oRs("fac_kenmerkdomein_objectnaam").value != "FAC_USRDATA" ? oRs("fac_kenmerkdomein_objectnaam").value : oRs("fac_usrtab_omschrijving").value;
    }
    function fnDomeinKeyKolom(oRs)
    {
        return oRs("fac_kenmerkdomein_kolomnaam").value != "FAC_USRDATA_KEY" ? oRs("fac_kenmerkdomein_kolomnaam").value : "";
    }
    function fnDomeinTxtKolom(oRs)
    {
        return oRs("fac_kenmerkdomein_kolomtxt").value != "FAC_USRDATA_OMSCHR" ? oRs("fac_kenmerkdomein_kolomtxt").value : "";
    }


    buttons = {};
    //if (canAdd)
    {
      var addurl = "appl/fac/fac_kenmerkdomein.asp?mode=edit&module=" +fkdmodule;
      buttons = [{ icon: "plus.png", title: L("lcl_add"), action: "FcltMgr.openDetail('" + addurl + "', '" + L("lcl_add") + "', {callback: FcltMgr.reload })" }]
    }

    var rst = new ResultsetTable({ sql: sql,
                                   keyColumn: "fac_kenmerkdomein_key",
                                   ID: "fackenmerkdomeintable",
                                   showAll: showall,
                                   outputmode: outputmode,
                                   title: L("lcl_kenmerkdomeinen"),
                                   buttons: buttons
                                 });

    rst.addColumn(new Column({caption: "Key",                            content: "fac_kenmerkdomein_key"}));
    if (fkdmodule==-1)
        rst.addColumn(new Column({caption: L("lcl_fac_module"),                 content: "fac_kenmerkdomein_module"}));
    rst.addColumn(new Column({caption: L("lcl_kenmerkdomein_omschrijving"), content: "fac_kenmerkdomein_omschrijving"}));
    rst.addColumn(new Column({caption: L("lcl_kenmerkdomein_objectnaam"),   content: fnDomeinTabel}));
    rst.addColumn(new Column({caption: L("lcl_kenmerkdomein_kolomnaam"),    content: fnDomeinKeyKolom}));
    rst.addColumn(new Column({caption: L("lcl_kenmerkdomein_kolomtxt"),     content: fnDomeinTxtKolom}));
//    rst.addColumn(new Column({caption: L("lcl_usrtab_omschrijving"),        content: "fac_usrtab_omschrijving"}));
    rst.addColumn(new Column({caption: L("lcl_usrdata_aantal"),             content: "aantal"}));

    rst.addAction({ action: "fkd_edit", caption: L("lcl_edit"), isDefault: true});

// TODO: een doorlink naar fac_usrdata vanuit de Aantal kolom
    var cnt = rst.processResultset();

%>
  </body>
</html>
