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

    File:        fac_admtracking_list.asp
    Description: Toont db-upgrade (en settings) tracking
    Parameters:  zoek: optioneel filenaam (wildcard)
    Context:     INTERNAL USE
    Requires:    WEB_FACTAB autorisatie voor alle-tracking (vanuit fac_admtracking_search)
                 WEB_PRSSYS autorisatie voor alleen de settings-tracking (vanuit fac_setting)
                 (Veronderstelt dat FACTAB ook PRSSYS heeft)
    Note:

*/ %>
<!--#include file="../Shared/common.inc" -->
<!--#include file="../Shared/resultset_table_v2.inc" -->
<!-- #include file="../Shared/calendar.inc" -->

<%
  var zoek = getQParam("zoek", -1);
  var since = getQParamDate("date_from", null);
  var laatste = getQParam("laatste", "off")=="on";
  var showall = getQParamInt("showall", 0) == 1;
  var outputmode = getQParamInt("outputmode", 0);

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

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

  <body id="listbody">
<%
    var authPRSSYS = user.checkAutorisation("WEB_PRSSYS");
    var authFACTAB = user.checkAutorisation("WEB_FACTAB", true);

    var sqln = "SELECT UPPER(adm_tracking_name) adm_tracking_name, "
             + "       adm_tracking_revision, "
             + "       adm_tracking_date, "
             + "       UPPER(adm_tracking_osuser) adm_tracking_osuser,"
             + "       prs_perslid_naam_full"
             + "  FROM adm_tracking at1, prs_v_perslid_fullnames pp"
             + " WHERE pp.prs_perslid_key(+) = fac.safe_to_number(adm_tracking_osuser)" // Als via de interface bewerkt dan wordt key in adm_tracking_osuser gestopt
             + (zoek != -1
               ? " AND UPPER(adm_tracking_name) LIKE " + safe.quoted_sql_wild("%" + zoek + "%")
               : "")
             + (!authFACTAB
               ? " AND UPPER(adm_tracking_name) LIKE 'S(%'"
               : "")
             + (since?" AND adm_tracking_date >= " + since.toSQL():"")
             + (laatste? " AND adm_tracking_date = (SELECT MAX(adm_tracking_date) FROM adm_tracking at2 WHERE at2.adm_tracking_name = at1.adm_tracking_name)":"")
             + " ORDER BY adm_tracking_date DESC, adm_tracking_key DESC, UPPER(adm_tracking_name)";

    settings.overrule_setting("qp_maxrows", Math.max(S("qp_maxrows"), 1000));
    settings.overrule_setting("qp_maxrows2", Math.max(S("qp_maxrows2"), 99999)); // serieus veel!

   function fncolFile(oRs)
      {
        if (!oRs("adm_tracking_name").Value.match(/^S\(.*\)$/))
            return safe.html(oRs("adm_tracking_name").Value);
        return  "";
      }
   function fncolSettingName(oRs)
      {
        if (oRs("adm_tracking_name").Value.match(/^S\(.*\)$/))
            return safe.html(oRs("adm_tracking_name").Value);
        return  "";
      }
   function fncolRevision(oRs)
      {
        if (!oRs("adm_tracking_name").Value.match(/^S\(.*\)$/))
            return safe.html(oRs("adm_tracking_revision").Value);
        return  "";
      }
   function fncolSetting(oRs)
      {
        if (oRs("adm_tracking_name").Value.match(/^S\(.*\)$/))
            return safe.html(oRs("adm_tracking_revision").Value);
        return  "";
      }
   function fncolOS(oRs)
      {
        if (!oRs("adm_tracking_name").Value.match(/^S\(.*\)$/))
            return safe.html(oRs("adm_tracking_osuser").Value);
        return  "";
      }
   function fncolFCLT(oRs)
      {
        if (oRs("adm_tracking_name").Value.match(/^S\(.*\)$/))
            return safe.html(oRs("prs_perslid_naam_full").Value || "Unknown (sql script?)");
        return  "";
      }

    var rst = new ResultsetTable({ ID: "trackingtable",
                                   title : "Tracking"  + (since?" sinds " + toDateString(since):""),
                                   showAll: showall,
                                   outputmode: outputmode,
                                   sql: sqln
                                 });
    rst.addColumn(new Column( {caption: "Run at", content: "adm_tracking_date", datatype: "datetime"} ));
    rst.addColumn(new Column( {caption: "File", content: fncolFile} ));
    rst.addColumn(new Column( {caption: "Revision", content: fncolRevision} ));
    rst.addColumn(new Column( {caption: "OS user", content: fncolOS} ));
    rst.addColumn(new Column( {caption: "Setting", content: fncolSettingName} ));
    rst.addColumn(new Column( {caption: "New value", content: fncolSetting} ));
    rst.addColumn(new Column( {caption: "Facilitor user", content: fncolFCLT} ));

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