diff --git a/views/default.handlebars b/views/default.handlebars index 187a4850..5fad222b 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -1187,6 +1187,9 @@ +
+   +
@@ -14909,6 +14912,8 @@ // MY REPORTS // + var reportCSV = null; + function generateReportDialog() { if (xxdialogMode) return; var y = '', x = '', settings = JSON.parse(getstore('_ReportSettings', '{}')); @@ -14962,81 +14967,98 @@ } function renderReport(r) { - //console.log('renderReport', r); var colTranslation = { time: "Time", device: "Device", session: "Session", user: "User", length: "Length" } - var x = ''; + var x = '
', firstItem; var sumByCol = null; // Indicate by what colum we sum by var sumByValues = []; // Indicate by what values we sum by - x += '' - for (var i in r.columns) { - var coltitle; - if (colTranslation[r.columns[i].title] != null) { coltitle = colTranslation[r.columns[i].title]; } else { coltitle = EscapeHtml(r.columns[i].title); } - var style = ''; - if (r.columns[i].align) { style += ';text-align:' + EscapeHtml(r.columns[i].align); } else { style += ';text-align:left'; } - if ((i == 0) && ((r.columns[i].format == 'datetime') || (r.columns[i].format == 'time'))) { style += ';width:1%'; } - x += ''; - } - x += '' - for (var i in r.groups) { - x += '' - x += '' - for (var j in r.groups[i].entries) { - var e = r.groups[i].entries[j]; - x += '' - for (var k in r.columns) { - var style = ''; - if (r.columns[k].align) { style = 'text-align:' + EscapeHtml(r.columns[k].align); } - if (e[r.columns[k].id] != null) { x += ''; } else { x += ''; } - if (r.columns[k].sumBy != null) { - var v1 = e[r.columns[k].sumBy]; - var v2 = e[r.columns[k].id]; - sumByCol = r.columns[k].sumBy; - if (v2 != null) { - if (sumByValues.indexOf(v1) == -1) { sumByValues.push(v1); } - if (r.columns[k].subtotals == null) { r.columns[k].subtotals = {}; r.columns[k].totals = {}; } - if (r.columns[k].subtotals[v1] == null) { r.columns[k].subtotals[v1] = v2; } else { r.columns[k].subtotals[v1] += v2; } - if (r.columns[k].totals[v1] == null) { r.columns[k].totals[v1] = v2; } else { r.columns[k].totals[v1] += v2; } - } - } - } - x += '' + if (Object.keys(r.groups).length == 0) { + reportCSV = null; + QV('p60downloadReportDiv', false); + x += ''; + } else { + reportCSV = '"' + "Group" + '"'; + x += '' + for (var i in r.columns) { + var coltitle; + if (colTranslation[r.columns[i].title] != null) { coltitle = colTranslation[r.columns[i].title]; } else { coltitle = EscapeHtml(r.columns[i].title); } + var style = ''; + if (r.columns[i].align) { style += ';text-align:' + EscapeHtml(r.columns[i].align); } else { style += ';text-align:left'; } + if ((i == 0) && ((r.columns[i].format == 'datetime') || (r.columns[i].format == 'time'))) { style += ';width:1%'; } + x += ''; + reportCSV += ',"' + csvClean(coltitle) + '"'; + firstItem = false; } - } - - // Display totals - if (sumByCol != null) { - var sumByColNum = -1; - for (var i in r.columns) { if (r.columns[i].id == sumByCol) { sumByColNum = i; } } - if (sumByColNum >= 0) { - sumByValues.sort(); - var firstRow = true; + x += '' + reportCSV += '\r\n'; + for (var i in r.groups) { x += '' - for (var j in sumByValues) { + x += '' + for (var j in r.groups[i].entries) { + var e = r.groups[i].entries[j]; x += '' - for (var i in r.columns) { - if (i == sumByColNum) { - var style = ''; - if (r.columns[k].align) { style += ';text-align:' + EscapeHtml(r.columns[k].align); } - if (firstRow) { style += ';border-top:1pt solid #777'; } - x += ''; - } else if (r.columns[i].totals != null) { - var style = ''; - if (r.columns[k].align) { style += ';text-align:' + EscapeHtml(r.columns[k].align); } - if (firstRow) { style += ';border-top:1pt solid #777'; } - x += ''; + reportCSV += '"' + csvClean(renderReportFormatCSV(i, r.groupFormat)) + '"'; + for (var k in r.columns) { + var style = ''; + if (r.columns[k].align) { style = 'text-align:' + EscapeHtml(r.columns[k].align); } + if (e[r.columns[k].id] != null) { + x += ''; + reportCSV += ',"' + csvClean(renderReportFormatCSV(e[r.columns[k].id], r.columns[k].format)) + '"'; } else { x += ''; + reportCSV += ','; + } + if (r.columns[k].sumBy != null) { + var v1 = e[r.columns[k].sumBy]; + var v2 = e[r.columns[k].id]; + sumByCol = r.columns[k].sumBy; + if (v2 != null) { + if (sumByValues.indexOf(v1) == -1) { sumByValues.push(v1); } + if (r.columns[k].subtotals == null) { r.columns[k].subtotals = {}; r.columns[k].totals = {}; } + if (r.columns[k].subtotals[v1] == null) { r.columns[k].subtotals[v1] = v2; } else { r.columns[k].subtotals[v1] += v2; } + if (r.columns[k].totals[v1] == null) { r.columns[k].totals[v1] = v2; } else { r.columns[k].totals[v1] += v2; } + } } } x += '' - firstRow = false; + reportCSV += '\r\n'; } } - } + // Display totals + if (sumByCol != null) { + var sumByColNum = -1; + for (var i in r.columns) { if (r.columns[i].id == sumByCol) { sumByColNum = i; } } + if (sumByColNum >= 0) { + sumByValues.sort(); + var firstRow = true; + x += '' + for (var j in sumByValues) { + x += '' + for (var i in r.columns) { + if (i == sumByColNum) { + var style = ''; + if (r.columns[k].align) { style += ';text-align:' + EscapeHtml(r.columns[k].align); } + if (firstRow) { style += ';border-top:1pt solid #777'; } + x += ''; + } else if (r.columns[i].totals != null) { + var style = ''; + if (r.columns[k].align) { style += ';text-align:' + EscapeHtml(r.columns[k].align); } + if (firstRow) { style += ';border-top:1pt solid #777'; } + x += ''; + } else { + x += ''; + } + } + x += '' + firstRow = false; + } + } + } + QV('p60downloadReportDiv', true); + } x += '
' + coltitle + '
' - x += renderReportFormat(i, r.groupFormat); - x += '
' + renderReportFormat(e[r.columns[k].id], r.columns[k].format) + '
' + "Report returned no entires." + '
' + coltitle + '
' + x += renderReportFormat(i, r.groupFormat); + x += '
' + renderReportFormat(sumByValues[j], r.columns[i].format); + '' + renderReportFormat(r.columns[i].totals[sumByValues[j]], r.columns[i].format); + '' + renderReportFormat(e[r.columns[k].id], r.columns[k].format) + '
' + renderReportFormat(sumByValues[j], r.columns[i].format); + '' + renderReportFormat(r.columns[i].totals[sumByValues[j]], r.columns[i].format); + '
'; QH('p60report', x); } @@ -15048,7 +15070,7 @@ if (v == 1) return "Terminal"; if (v == 2) return "Desktop"; if (v == 5) return "Files"; - EscapeHtml(v); + return "Unknown"; } if (f == 'seconds') { var seconds = v % 60; @@ -15074,6 +15096,38 @@ return EscapeHtml(v); } + function renderReportFormatCSV(v, f) { + if (f == 'datetime') { return printDateTime(new Date(v)); } + if (f == 'time') { return printTime(new Date(v)); } + if (f == 'protocol') { + if (v == 1) return "Terminal"; + if (v == 2) return "Desktop"; + if (v == 5) return "Files"; + return "Unknown"; + } + if (f == 'node') { + var node = getNodeFromId(v); + if (node != null) { return node.name; } + } + if (f == 'user') { + var user = null; + if (v == userinfo._id) { user = userinfo; } else { if (users != null) { user = users[v]; } } + if (user != null) { + var name = user.name; + if (user.realname != null) { name += ' - ' + user.realname; } + return name; + } else { + return "Unknown User"; + } + } + return '' + v; + } + + function p60downloadReport() { + if (xxdialogMode || (reportCSV == null)) return; + saveAs(stringToUtf8Blob(reportCSV), "Report.csv"); + } + // // NOTIFICATIONS //