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

    File:        fac_locale_list_std.asp
    Description: zoekt op basis van de zoekvelden in de vertaaltabel
    Parameters:  search: zoekstring
                 taal
    Context:     Vanuit fac_locale_search_std.asp
    Note:        Variant op fac_locale_list.asp die het voor dialect-teksten doet
    */
%>

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

<%
  FCLTHeader.Requires({plugins:["jQuery"], js: ["jquery-ui.js"]});

var autfunction = "WEB_LCLSYS";
var authparams = user.checkAutorisation(autfunction);

var vTaal = getQParam("sTaal", "-1");
var vSearchString = getQParam("sString", "");
var vModule = getQParam("sModule", "-1");
var outputmode = getQParamInt("outputmode", 0);
var showall = getQParamInt("showall", 0) == 1;
var overruled = (getQParam("lcl_overrule", "") == "on")
var lcl_undefined = (getQParam("lcl_undefined", "") == "on")
var SorteerKolommen = [];
var vWhere = "";

// Bepaal de verschillende talen of dialecten die er gebruikt worden
// en maak daar kolommen voor.

  for (var l in S("language_toggles"))
  {
      if (vTaal == "-1" || vTaal == S("language_toggles")[l])
      {
       SorteerKolommen.push("MAX(CASE WHEN fac_locale_xsl_lang = " + safe.quoted_sql(S("language_toggles")[l]) + " THEN fac_locale_xsl_tekst END) LANG_" + S("language_toggles")[l]);
       SorteerKolommen.push("MAX(CASE WHEN fac_locale_xsl_lang = " + safe.quoted_sql(S("language_toggles")[l]) + " THEN fac_locale_xsl_cust END) CUST_" + S("language_toggles")[l]);
      }
  }

  var sqln = "SELECT l.fac_locale_xsl_label, fac_locale_xsl_module"
           + "     , " + SorteerKolommen.join(',')
           + "     , COUNT(DISTINCT fac_locale_xref_filepath) n_file"
           + "  FROM fac_locale_xsl l,"
           + "       fac_locale_xref x"
           + " WHERE x.fac_locale_xsl_key(+) = l.fac_locale_xsl_key";

  var filters = [];
  if (overruled)
    filters.push("fac_locale_xsl_cust IS NOT NULL");

  if (lcl_undefined)
    filters.push("fac_locale_xsl_isvalid = 0");

  if (vTaal != "-1")
    filters.push("fac_locale_xsl_lang = " + safe.quoted_sql(vTaal));

  if (vSearchString != "")
  {
    filters.push(" (   UPPER(fac_locale_xsl_label) LIKE "+safe.quoted_sql_wild("%"+vSearchString+"%")
                 + "OR UPPER(fac_locale_xsl_tekst) LIKE "+safe.quoted_sql_wild("%"+vSearchString+"%")
                 + "OR UPPER(fac_locale_xsl_cust)  LIKE "+safe.quoted_sql_wild("%"+vSearchString+"%")
                 + ")");
  }

  if (filters.length)
  {
    sqln +=" AND l.fac_locale_xsl_label IN "
         + "    (SELECT l2.fac_locale_xsl_label "
         + "       FROM fac_locale_xsl l2"
         + "      WHERE " + filters.join(" AND ")
         + "     ) ";
  }

  if (vModule != "-1")
  {
    sqln +=" AND (l.fac_locale_xsl_label, l.fac_locale_xsl_module) IN "
         + "    (SELECT l2.fac_locale_xsl_label, l2.fac_locale_xsl_module "
         + "       FROM fac_locale_xsl l2,"
         + "            fac_locale_xref x2"
         + "      WHERE x2.fac_locale_xsl_key(+) = l2.fac_locale_xsl_key"
         + "        AND (x2.fac_locale_xref_filepath LIKE "+safe.quoted_sql("%/" + vModule + "/%")
         + "             OR l2.fac_locale_xsl_module = " + safe.quoted_sql_upper(vModule) + ")"
         + "     ) ";
  }

  sqln += " GROUP BY fac_locale_xsl_label, fac_locale_xsl_module"
       +  " ORDER BY REPLACE(fac_locale_xsl_label, 'lcl_', ''), fac_locale_xsl_module";

%>

<html>
  <head>
    <% FCLTHeader.Generate(); %>
    <script type="text/javascript">
      function localeedit(row)
      {
        $(row).addClass('dirty');
        var lclData = JSON.parse(row.getAttribute("ROWDATA"));
        var lcl_label = row.getAttribute("ROWKEY");

        var url = '../fac/fac_locale_edit_std.asp?lcl_label={0}&module={1}'.format(encodeURIComponent(lcl_label), lclData.module);
        FcltMgr.openModalDetail(url, L("lcl_lcl_vertaling"), { callback: FcltMgr.reload } );
      }
    </script>
  </head>

  <body id="listbody">
<%
    function fnrowData(oRs)
    {
      var data = { module : oRs("fac_locale_xsl_module").Value };
      return JSON.stringify(data);
    }

    function fnNaam (oRs)
    {
        return "<div class='locn'>"+oRs("fac_locale_xsl_label").value+"</div>";
    }

    var rst = new ResultsetTable({ sql: sqln,
                                   keyColumn: "fac_locale_xsl_label",
                                   ID: "localetable",
                                   rowData: fnrowData,
                                   showAll: showall,
                                   buttons: []
                                });

    rst.addColumn(new Column({hasActions: true, caption:L("lcl_fac_module"), content:"fac_locale_xsl_module"}));
    rst.addColumn(new Column({hasActions: true, caption:L("lcl_lcl_xsl_label"), content:fnNaam}));
    rst.addColumn(new Column({hasActions: true, caption:L("lcl_lcl_n_file"), content:"n_file", datatype: "number"}));

    // Toon het variabel aantal kolommen voor Taal/Dialect
    for (var l in S("language_toggles"))
    {
        if (vTaal == "-1" || vTaal == S("language_toggles")[l])
        {
         rst.addColumn(new Column({caption: S("language_toggles")[l], content: "LANG_" + S("language_toggles")[l]}));
         rst.addColumn(new Column({caption: "CUST_" + S("language_toggles")[l], content: "CUST_" + S("language_toggles")[l]}));
        }
    }

    rst.addAction({action: "localeedit", caption: L("lcl_edit"), isDefault: true});
    rst.processResultset();
%>
  </body>
</html>

<% ASPPAGE_END(); %>
