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

    File:               SuggestFlexfile.asp
    Description:        Suggereer flexfiles
    Parameters:         k             De eerste paar letters
                        filtcode beperk de lijst met getoonde functies (not used)
    Globals:
    Context:
    Note:
*/ %>

<%
JSON_Result = true;
%>

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

<%
protectQS.verify({ allowparams: ["k", "SuggestAll"]}); // tamper check

var chars = getQParam("k", "");
var bAll = getQParamInt("SuggestAll", 0) == 1;
var pModule = getQParam("flexmodule");

var regchars = chars.replace(/[\-\[\]\/\{\}\(\)\+\.\\\^\$\|]/g, "\\$&"); // Let op: ? en * mag blijven

var flexparam = flexProps(pModule, -1, null, null,
                        { getFiles: true, api2name: null, filter: regchars.replace(/\*/g, '.*').replace(/\?/g, '.') });

var params = { bAll: bAll };
var jsonResult = { } ;

var lijst = [];
for (var cnt = 0; cnt < flexparam.files.length && cnt < (params.bAll? maxFull : maxNormal); cnt++)
{
    var file = flexparam.files[cnt];

    var result = [ file.name,
                   file.name,
                   "({0} kB) {1}".format(Math.round(file.size / 1024), toDateTimeString(file.date)),
                   null
                 ];
    lijst.push(result);
};
if (pModule == 'MENU')
{
    var sql = "SELECT DISTINCT fac_menuitems_image"
            + "  FROM fac_menuitems"
            + " WHERE fac_menuitems_image IS NOT NULL"
            + " ORDER BY fac_menuitems_image";
    var oRs = Oracle.Execute(sql);
    while(!oRs.Eof && cnt < (params.bAll? maxFull : maxNormal))
    {
        cnt ++;
        var result = [ oRs("fac_menuitems_image").Value,
                       oRs("fac_menuitems_image").Value,
                       L("lcl_builtin_menu_image"),
                       null
                     ];
        lijst.push(result);
        oRs.MoveNext();
    }
}

  jsonResult.result = lijst;
  if (cnt < flexparam.files.length)
  {
      jsonResult.hasMore = true;
    if (params.bAll)
      jsonResult.hasMoreMsg = L("lcl_shared_suggest_toomany");
    else
      jsonResult.hasMoreMsg = L("lcl_shared_suggest_more");
  }

  if (params.bAll)
     jsonResult.isAll = true;
  if (params.checkExist)
    jsonResult.checkExist = true;

  if (callback)
      Response.Write(callback + "(" + JSON.stringify(jsonResult) + ")");
  else
      Response.Write(JSON.stringify(jsonResult));

%>
