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

    File:        fac_bookmark_list.asp
    Status:      REVISEREN!
                  Eindsituatie moet een generiek beheer-UI voor bookmarks zijn
                  Die API-spullen moeten hier dan uit geisoleerd worden, of generiek.


    Description: Toon alle bookmarks, behalve onze systeembookmarks (met xmlnode)
    Parameters:
    Context:     Vanuit menu
    */
%>
<!--#include file="../Shared/common.inc" -->
<!--#include file="../Shared/resultset_table_v2.inc" -->
<!--#include file="fac.inc" -->

<%
FCLTHeader.Requires({js: []});

var autfunction = "WEB_HLPADM";
var authparams = user.checkAutorisation(autfunction);
var showall = getQParamInt("showall", 0) == 1;
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script>
      function bmk_show(row)
      {
        $(row).addClass('dirty');
        var bkm_id = row.getAttribute("ROWKEY");
        var facData = JSON.parse(row.getAttribute("ROWDATA"));
        if (facData)
        {
          var bkm_naam = facData.naam;
          url = "appl/fac/fac_bookmark.asp?bkm_id=" + bkm_id;
          FcltMgr.openDetail(url, L("lcl_fac_bookmark") + ' ' + bkm_naam);
        }
      }
    </script>
  </head>
  <body id="listbody">
<%
    function fnrowData(oRs)
    {
      var data = { path: oRs("fac_bookmark_path").value,
                   query: oRs("fac_bookmark_query").value,
                   naam: oRs("fac_bookmark_naam").value
                 };
      return JSON.stringify(data);
    }

    var has_report_api = "";
    var sql = "SELECT fac_api_name"
            + "  FROM fac_api"
            + " WHERE fac_api_name = " + safe.quoted_sql("REPORT");
    var oRs = Oracle.Execute(sql);
    if (!oRs.Eof)
        has_report_api = "???";
    oRs.Close();

    function fncolDeep(oRs)
    {
      var deep = HTTP.urlzelf() + "?fac_id=" + customerId
               + "&API=REPORT&APIKEY=" + has_report_api + "&BOOKMARK=" + oRs("fac_bookmark_id").value;
      return "<input class='fld' style='width:600px' onfocus='this.select()' onclick='FcltMgr.stopPropagation(event);' value='" + safe.htmlattr(deep)+"'>";
    }

    buttons = [];
    buttons.push({ icon: "fa-fclt-refresh", title: L("lcl_refresh"), action: "FcltMgr.reload()" });
    var authparamsPRSSYS = user.checkAutorisation("WEB_PRSSYS", true);
    var hasPRSSYS = authparamsPRSSYS && authparamsPRSSYS.PRSwritelevel < 9 && authparamsPRSSYS.ALGwritelevel < 9;
    if (hasPRSSYS)
    {
      var addurl = "appl/fac/fac_bookmark.asp";
      buttons.push({ icon: "fa-plus", title: L("lcl_add"), action: "FcltMgr.openDetail('" + addurl + "', '" + safe.jsstring(L("lcl_add")) + "')" });
    }
    var flags = 2; // Zichtbaar voor FE
    var userbm = getQParamInt("userbm", 1) == 1; // Ook user-bookmarks?
    var systembm = getQParamInt("systembm", 1) == 1; // Ook systeem-bookmarks?
    if (hasPRSSYS && systembm)
        flags += 1; // of zichtbaar PRSSYS

    var sql = "SELECT fac_bookmark_id"
            + "     , fac_bookmark_path"
            + "     , fac_bookmark_query"
            + "     , fac_bookmark_naam"
            + "     , fac_bookmark_aanmaak"
            + "     , prs_perslid_naam_full"
            + "     , prs_perslid_flags"
            + "     , prs_perslid_key_auth"
            + "  FROM fac_bookmark,"
            + "       prs_v_perslid_fullnames pf,"
            + "       prs_perslid pp"
            + " WHERE (fac_bookmark_expire IS NULL OR fac_bookmark_expire > SYSDATE)"
            + "   AND (fac_bookmark_query NOT LIKE 'session=%' OR fac_bookmark_query IS NULL)"
            + "   AND prs_perslid_key_auth = pf.prs_perslid_key(+)"
            + "   AND prs_perslid_key_auth = pp.prs_perslid_key(+)"
            + "   AND BITAND(fac_bookmark_flags, " + flags + ") <> 0"
            + (!userbm?"   AND BITAND(fac_bookmark_flags, 2) = 0":"")
            + "   AND fac_bookmark_xmlnode IS NULL"  // die zijn van ons zelf en worden niet geacht beheerd te worden.
            + " ORDER BY fac_bookmark_naam";

    var rst = new ResultsetTable({ sql: sql,
                                   keyColumn: "fac_bookmark_id",
                                   ID: "bookmarktable",
                                   rowData: fnrowData,
                                   noPrint: true,
                                   title: L("lcl_fac_bookmarkitems"),
                                   showAll: showall,
                                   buttons: buttons
                                  });

    function fncolnaam(oRs)
    {
        if (!oRs("prs_perslid_key_auth").Value)
            return "";
        if ((oRs("prs_perslid_flags").Value & 4) == 4) // netjes grouped
            return safe.html(oRs("prs_perslid_naam_full").Value);
        else
            return safe.html(oRs("prs_perslid_naam_full").Value) + "<br><span style='background-color:#f88'>{0}</span>".format(L("lcl_bkm_prskey_auth_warn"));
    }

    rst.addColumn(new Column({caption: L("lcl_fac_bookmarkid"), content:"fac_bookmark_id"}));
    rst.addColumn(new Column({caption: L("lcl_fac_bookmark"), content:"fac_bookmark_naam"}));
    rst.addColumn(new Column({caption: L("lcl_fac_bookmarkpath"), content:"fac_bookmark_path"}));
    rst.addColumn(new Column({caption: L("lcl_fac_bookmarkcreate"), content:"fac_bookmark_aanmaak", datatype: "datetime"}));
    //rst.addColumn(new Column({caption: L("lcl_fac_bookmarkquery"), content:"fac_bookmark_query"}));
    if (systembm)
        rst.addColumn(new Column({caption: L("lcl_bkm_prskey_auth"), content: fncolnaam}));

    if (has_report_api) // dan is een deeplink mogelijk
      rst.addColumn(new Column({caption: L("lcl_fac_bookmarkdeep"), content: fncolDeep}));

    if (authparamsPRSSYS && authparamsPRSSYS.PRSwritelevel < 9 && authparamsPRSSYS.ALGwritelevel < 9)
        rst.addAction({ action: "bmk_show", caption: L("lcl_edit"), isDefault: true } );

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

<% ASPPAGE_END(); %>
