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

    File:        fac_settings_list.asp
    Description: Toont alle menu-opties, met de mogelijkheid deze van/naar het eigen menu te zetten
    Parameters:  groep (0,1,2): filtert het resultaat
                 module (MLD etc): filtert het resultaat
                 inuse (0, 1): filtert het resultaat
    Context:     INTERNAL USE
    Requires:    WEB_PRSSYS autorisatie
    Note:        Eerste opzet

*/ %>

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

<%
var smodule = getQParam("smodule", "-1");
var zoek = getQParam("zoek", "");
var showall = getQParamInt("showall", 0) == 1;
var outputmode = getQParamInt("outputmode", 0);

var autfunction = "WEB_PRSSYS";
var authparams = user.checkAutorisation(autfunction);
var hasFACFAC = user.checkAutorisation("WEB_FACFAC", true);
var hasFACTAB = user.checkAutorisation("WEB_FACTAB", true);
var overruled = (getQParam("is_overrule", "") == "on")

FCLTHeader.Requires({ plugins: ["jQuery"] })
%>

<html>
  <head>
<% FCLTHeader.Generate({outputmode: outputmode}) %>
  </head>

  <body id="listbody">

    <script type="text/javascript">
      function doZet(row)
      {
        var url = "appl/fac/fac_setting.asp?fac_key=" + row.getAttribute("ROWKEY");
        FcltMgr.openDetail(url, 'Set!');
      }
    </script>
<%
    var sqln = "SELECT *"
             + "  FROM fac_setting s, "
             + "       fac_functie f, "
             + "       prs_v_perslid_fullnames pf"
             + " WHERE s.prs_perslid_key = pf.prs_perslid_key(+)"
             + "   AND s.fac_functie_key = f.fac_functie_key"
             + (zoek 	? " AND (UPPER(fac_setting_name)        LIKE " + safe.quoted_sql_wild("%" + zoek + "%")
                          + " OR UPPER(fac_setting_description) LIKE " + safe.quoted_sql_wild("%" + zoek + "%")
                          + " OR UPPER(fac_setting_default)     LIKE " + safe.quoted_sql_wild("%" + zoek + "%")
                          + " OR UPPER(fac_setting_pvalue)      LIKE " + safe.quoted_sql_wild("%" + zoek + "%")
                          + ")"
    					: "")
    if (smodule != "-1")
        sqln += " AND fac_setting_module = " + safe.quoted_sql(smodule);
    if (!hasFACFAC)
        sqln += " AND (BITAND (fac_setting_flags, 1) = 1" // zichtbaar voor PRSSYS
              + (hasFACTAB? " OR fac_functie_code = 'WEB_FACTAB' OR fac_setting_name = 'flexfilespath'":"")
              +       ")"
    if (overruled)
        sqln += " AND fac_setting_pvalue IS NOT NULL";
    sqln += " ORDER BY fac_setting_name";



function prettyJson(j)
{
  try
  {
    var xx = JSON.stringify(JSON.parse(j), null, 2);
    if (xx == "null")
        return "";
    return xx;
  }
  catch (e)
  {
    return j;
  };
};

    function fncolpval(oRs)
    {
        if (oRs("fac_setting_type").Value == "json")
            return "<pre>" + safe.html( prettyJson(oRs("fac_setting_pvalue").Value)) + "</pre>";
        else
            return safe.html(oRs("fac_setting_pvalue").Value);
    }
    function fnprotected(oRs)
    {
        if (oRs("fac_functie_code").Value == 'WEB_PRSSYS')
            return "";
        return "<span class='facsetreado' title='Protected setting'>Protected</span>";
    }
    var rst = new ResultsetTable({ sql: sqln,
                                   keyColumn: "fac_setting_key",
                                   ID: "settingstable",
                                   title : "Settings (cache {0})".format(toDateTimeString(new Date(Application("SET_TM_" + customerId)))),
                                   showAll: showall,
                                   outputmode: outputmode
                                 });

    rst.addColumn(new Column({caption: L("lcl_fac_module"), content: "fac_setting_module"}));
    rst.addColumn(new Column({caption: L("lcl_fac_setting"), content: "fac_setting_name"}));
    rst.addColumn(new Column({caption: L("lcl_fac_default"), content: "fac_setting_default"}));
    rst.addColumn(new Column({caption: L("lcl_fac_value"), content: fncolpval}));
    rst.addColumn(new Column({caption: L("lcl_fac_set"), content: "prs_perslid_naam_full"}));
    rst.addColumn(new Column({caption: L("lcl_fac_setting_fcltonly"), content: fnprotected }));
    rst.addColumn(new Column({caption: L("lcl_fac_time"), content: "fac_setting_datum", datatype: "datetime"}));
    rst.addColumn(new Column({caption: L("lcl_fac_descr"), content: "fac_setting_description"}));

    rst.addAction({ action: "doZet", isDefault: true });

    var cnt = rst.processResultset();
%>
  </body>
</html>
<% ASPPAGE_END(); %> 
