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

    File:           appl/fac/about.asp
    Description:    Info about license, usercount etc.
    Parameters:
    Context:        Manual call
    Note:           WEB_PRSSYS authorization is required

*/
%>
<!--#include file="../Shared/common.inc"-->
<!--#include file="../Shared/iface.inc"-->
<%
var autfunction = "WEB_PRSSYS";
var authparams = user.checkAutorisation(autfunction);
%>
<html>
<head><%
FCLTHeader.Title(L("lcl_facilitor_appl")+" "+L("lcl_about"));
FCLTHeader.Generate(); %>
</head>
<body id="aboutbody">
<%  SUBFRAME_START();

    sql = "SELECT COALESCE(fac_version_otap, 'P') otap, "
          + "       fac.getdbversion() dbversion,"
          + "       fac_version_cust, "
          + "       fac_version_schema "
          + "  FROM fac_version";
    oRs = Oracle.Execute(sql);
    var otap = oRs("otap").value;
    var dbversion = oRs("dbversion").value;
    var schemaversion = oRs("fac_version_schema").Value;
    var facilitorversion = FCLTVersion + "@" + dbversion;
    oRs.Close();

    sql = "SELECT fac_usrrap_key FROM fac_usrrap WHERE UPPER(fac_usrrap_view_name)='FAC_V_LCRAP_FE_VS_KEY_DATA'";
    var btns = [];
    oRs = Oracle.Execute(sql);
    if (!oRs.eof) { // Geen LCL nog
        btns.push({ title: "Bron voor key/fe user telling", icon: "fa-map-pin", action: "FcltMgr.openDetail('appl/fac/fac_report.asp?scf_pivot=0&usrrap_key=" + oRs("fac_usrrap_key").Value + "')", importance: 2});
    }
    oRs.Close();

   sql = "SELECT tijdstip, "
           + "all_users,"
           + "fe_users,"
           + "key_users,"
           + "devices,"
           + "passive_users,"
           + "recent_login"
           + " FROM fac_v_lcrap_fe_vs_key";
    // yields only one record
    oRs = Oracle.Execute(sql);

    BLOCK_START("aboutInfo", L("lcl_facilitor_appl")+' '+facilitorversion+' '+ toDateTimeString(oRs("tijdstip").value), { wide: true, icon: "fa-tally", buttons: btns });

    // users
    ROFIELDTR("fld", L("lcl_key_users"), L("lcl_usrs_actual")+": "+ safe.showFloat(oRs("key_users").value||0,0));
    ROFIELDTR("fld", L("lcl_fe_users"), L("lcl_usrs_actual")+": "  + safe.showFloat(oRs("fe_users").value||0,0));
    ROFIELDTR("fld", L("lcl_sys_users"), L("lcl_usrs_actual")+": "  + safe.showFloat(oRs("devices").value,0));
    ROFIELDTR("fld", L("lcl_passive_users"), L("lcl_usrs_actual")+": "  + safe.showFloat(oRs("passive_users").value,0));
    oRs.Close();

    sql = "SELECT apiuser, apinaam, modules"
        + "  FROM fac_v_lcrap_apiusers"
        + " ORDER BY apinaam";
    oRs = Oracle.Execute(sql);
    var i = 1;
    while (!oRs.eof)
    {
      ROFIELDTR("fld", (i==1 ? L("lcl_api_users") : ""), oRs("apinaam").Value + " [" + (oRs("apiuser").Value || "") + "]: " + oRs("modules").Value);
      i += 1;
      oRs.moveNext();
    }
    oRs.Close();

    sql = "SELECT w.prs_perslid_key, f.prs_perslid_naam_full, p.prs_perslid_oslogin"
        + "  FROM fac_v_webgebruiker w,"
        + "       prs_v_perslid_fullnames f,"
        + "       prs_v_aanwezigperslid p"
        + " WHERE w.fac_functie_key = ( SELECT fac_functie_key FROM fac_functie WHERE fac_functie_code = 'WEB_PRSSYS' )"
        + "   AND w.prs_perslid_key = f.prs_perslid_key"
        + (user.has("WEB_FACFAC") ? "" : "  AND SUBSTR(p.prs_perslid_oslogin, 0, 1) <> '_'")
        + "   AND w.prs_perslid_key = p.prs_perslid_key";
    oRs = Oracle.Execute(sql);
    var i = 1;
    while (!oRs.eof)
    {
      var infoPointer = { Url:"appl/fac/fac_user.asp?prs_key=" + oRs("prs_perslid_key").Value };
      ROFIELDTR("fld", (i==1 ? L("lcl_admin_users") : ""), oRs("prs_perslid_naam_full").Value + " [" + (oRs("prs_perslid_oslogin").Value || "") + "]", { infoPointer: infoPointer });
      i += 1;
      oRs.moveNext();
    }
    oRs.Close();

    // an approximation of the modules used.
    // UDR is a pseudosubmodule from FAC
    // FAQ is not a pseudosubmodule from FAC, but is formally enabled by a setting, as is Mobile
    sql = "SELECT m.fac_module_remark, fac_module_name, COUNT (fac_groep_key)"
       + "   FROM fac_groeprechten gr, fac_functie f, fac_module m"
       +  " WHERE gr.fac_functie_key = f.fac_functie_key"
       + "    AND (fac_gebruiker_alg_level_write < 9 OR fac_gebruiker_prs_level_write < 9)"
       + "    AND f.fac_functie_module = m.fac_module_name"
       + "    AND f.fac_functie_module NOT IN ('FAC', 'FAQ', 'UDR')"
       + "    AND NOT EXISTS"
       + "           (SELECT ''"
       + "              FROM fac_groeprechten gr1, fac_functie f1"
       + "             WHERE     gr1.fac_functie_key = f1.fac_functie_key"
       + "                   AND f1.fac_functie_code IN ('WEB_FACFAC', 'WEB_PRSSYS', 'WEB_FINMSU')"
       + "                   AND gr1.fac_groep_key = gr.fac_groep_key)"
       + "  GROUP BY fac_module_name, m.fac_module_remark"
       + " UNION"
       + " SELECT m.fac_module_remark, fac_module_name, 1"
       + "   FROM fac_module m"
       + "  WHERE fac.getsetting ('faq_enabled') = 1 AND m.fac_module_name = 'FAQ'"
       + " UNION"
       + " SELECT m.fac_module_remark, fac_module_name, 1"
       + "   FROM fac_module m"
       + "  WHERE fac.getsetting ('fac_usrrap_mode') = 1 AND m.fac_module_name = 'UDR'"
       + " UNION"
       + " SELECT m.fac_module_remark, fac_module_name, 1"
       + "   FROM fac_module m"
       + "  WHERE BITAND(fac.getsetting ('mobile_enabled'), 255) > 0 AND m.fac_module_name = 'PDA'"
       + " UNION"
       + " SELECT 'lcl_module_MJB', 'MJB', 1"
       + "   FROM DUAL"
       + "  WHERE fac.getsetting ('mjb_enabled') = 1"
       + " UNION"
       + " SELECT 'lcl_module_CND', 'CND', 1"
       + "     FROM user_objects"
       + " WHERE fac.getsetting ('ins_score_enabled') = 1"
       + " UNION"
       + " SELECT 'lcl_module_MAIL', 'MAIL', 1"
       + "   FROM prs_perslid"
       + "  WHERE prs_perslid_oslogin = '_HMAIL'"
       + "    AND prs_perslid_login > SYSDATE-60"
       + " ORDER BY 1";
    oRs = Oracle.Execute(sql);
    var i = 1;
    while (!oRs.eof) {
        ROFIELDTR("fld", (i==1 ? L("lcl_modules_inuse") : ""),  i + ". " + L(oRs("fac_module_remark").value) + " [" + oRs("fac_module_name").value + "]");
        i += 1;
        oRs.moveNext();
    }
    oRs.Close();

    BLOCK_END();
    SUBFRAME_END();
    if (user.has("WEB_FACFAC"))
    {       sql = "SELECT fac_usrrap_key FROM fac_usrrap WHERE UPPER(fac_usrrap_view_name)='FAC_V_USAGE_STATISTICS'";
            oRs = Oracle.Execute(sql);
            if (!oRs.eof) {
              var page = "../fac/fac_report.asp?mode=list&scf_pivot=0&usrrap_key=" + oRs("fac_usrrap_key").Value;
              IFRAMER("facUsageFrame", page, { title: L("lcl_fac_usage_frame") } );
            }
            oRs.Close();
            sql = "SELECT fac_usrrap_key FROM fac_usrrap WHERE UPPER(fac_usrrap_view_name)='FAC_V_USAGE_STATISTICS_ALL'";
            oRs = Oracle.Execute(sql);
            if (!oRs.eof) {
              var page = "../fac/fac_report.asp?mode=list&scf_pivot=0&showall=1&usrrap_key=" + oRs("fac_usrrap_key").Value;
              IFRAMER("facUsageFrame", page, { title: L("lcl_fac_usage_frame") } );
            }
            oRs.Close();
    }
%>
    <p class="aboutfooter"><%=L("lcl_about_footer")%></p>
</body>
</html><% ASPPAGE_END(); %>
