summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics_reporting
diff options
context:
space:
mode:
authorSimon Rettberg2017-02-08 12:13:57 +0100
committerSimon Rettberg2017-02-08 12:13:57 +0100
commit5a6575b1c07997ba1af20952f435290ce8ce970c (patch)
tree0c98a876934bb3dbed01549bb814a1c480b5750e /modules-available/statistics_reporting
parent[statistics_reporting] Fix location highlighting (do it server side) (diff)
downloadslx-admin-5a6575b1c07997ba1af20952f435290ce8ce970c.tar.gz
slx-admin-5a6575b1c07997ba1af20952f435290ce8ce970c.tar.xz
slx-admin-5a6575b1c07997ba1af20952f435290ce8ce970c.zip
[statistics_reporting] Nag user if statistics reporting is disabled
Diffstat (limited to 'modules-available/statistics_reporting')
-rw-r--r--modules-available/statistics_reporting/hooks/main-warning.inc.php5
-rw-r--r--modules-available/statistics_reporting/inc/remotereport.inc.php2
-rw-r--r--modules-available/statistics_reporting/lang/de/template-tags.json4
-rw-r--r--modules-available/statistics_reporting/lang/en/template-tags.json4
-rw-r--r--modules-available/statistics_reporting/page.inc.php26
-rw-r--r--modules-available/statistics_reporting/templates/columnChooser.html43
6 files changed, 60 insertions, 24 deletions
diff --git a/modules-available/statistics_reporting/hooks/main-warning.inc.php b/modules-available/statistics_reporting/hooks/main-warning.inc.php
new file mode 100644
index 00000000..33381c9f
--- /dev/null
+++ b/modules-available/statistics_reporting/hooks/main-warning.inc.php
@@ -0,0 +1,5 @@
+<?php
+
+if (!RemoteReport::isReportingEnabled()) {
+ Message::addInfo('statistics_reporting.remote-report-disabled', true);
+}
diff --git a/modules-available/statistics_reporting/inc/remotereport.inc.php b/modules-available/statistics_reporting/inc/remotereport.inc.php
index e00e6758..7aad8b3a 100644
--- a/modules-available/statistics_reporting/inc/remotereport.inc.php
+++ b/modules-available/statistics_reporting/inc/remotereport.inc.php
@@ -24,7 +24,7 @@ class RemoteReport
*/
public static function isReportingEnabled()
{
- return Property::get(self::ENABLED_ID, false);
+ return Property::get(self::ENABLED_ID, false) === 'on';
}
/**
diff --git a/modules-available/statistics_reporting/lang/de/template-tags.json b/modules-available/statistics_reporting/lang/de/template-tags.json
index 379e2030..315837de 100644
--- a/modules-available/statistics_reporting/lang/de/template-tags.json
+++ b/modules-available/statistics_reporting/lang/de/template-tags.json
@@ -2,6 +2,7 @@
"lang_apply": "Anwenden",
"lang_displayColumns": "Auswahl angezeigter Spalten",
"lang_displaySelection": "Anzeigemodus, Auswahl Zeitfenster",
+ "lang_downloadReport": "Report herunterladen",
"lang_export": "Exportieren",
"lang_hostname": "Hostname",
"lang_lastLogout": "Letzter Logout",
@@ -9,7 +10,8 @@
"lang_location": "Ort",
"lang_longSessions": "Sitzungen \u2265 60s",
"lang_medianSessionLength": "Sitzungsdauer Median",
- "lang_reportingDescription": "Helfen Sie uns bwLehrpool, durch das w\u00f6chentliche, automatische Verschicken eines anonymisierten Statistikberichts, zu verbessern.",
+ "lang_reportingDescription": "Helfen Sie uns bwLehrpool durch das w\u00f6chentliche Verschicken eines anonymisierten Statistikberichts zu verbessern. Wenn Sie den Inhalt eines solchen Reports genauer inspizieren wollen, k\u00f6nnen Sie \u00fcber den untenstehenden Button einen aktuellen Report ihres Servers herunterladen.",
+ "lang_reportingLabel": "Anonymisierte Nutzungsstatistiken herunterladen",
"lang_sessions": "Sitzungen",
"lang_shortSessions": "Sitzungen < 60s",
"lang_total": "Gesamt",
diff --git a/modules-available/statistics_reporting/lang/en/template-tags.json b/modules-available/statistics_reporting/lang/en/template-tags.json
index 466a8530..a4865931 100644
--- a/modules-available/statistics_reporting/lang/en/template-tags.json
+++ b/modules-available/statistics_reporting/lang/en/template-tags.json
@@ -2,6 +2,7 @@
"lang_apply": "Apply",
"lang_displayColumns": "Select columns to display",
"lang_displaySelection": "Select display mode and specify time span",
+ "lang_downloadReport": "Download report",
"lang_export": "Export",
"lang_hostname": "Hostname",
"lang_lastLogout": "Last logout",
@@ -9,7 +10,8 @@
"lang_location": "Location",
"lang_longSessions": "Sessions \u2265 60s",
"lang_medianSessionLength": "Median Session Length",
- "lang_reportingDescription": "Help us improve bwLehrpool by automatically sending an anonymized statistics report once per week.",
+ "lang_reportingDescription": "Help us improve bwLehrpool by automatically sending an anonymized statistics report once a week. If you want to check what data the report contains, you can download such a report for reference below.",
+ "lang_reportingLabel": "Send anonymized usage statistics",
"lang_sessions": "Sessions",
"lang_shortSessions": "Sessions < 60s",
"lang_total": "Total",
diff --git a/modules-available/statistics_reporting/page.inc.php b/modules-available/statistics_reporting/page.inc.php
index 90188121..f0614d35 100644
--- a/modules-available/statistics_reporting/page.inc.php
+++ b/modules-available/statistics_reporting/page.inc.php
@@ -55,6 +55,14 @@ class Page_Statistics_Reporting extends Page
$this->doExport();
// Does not return
}
+ // Get report - fetch data exactly the way it would automatically be reported
+ // so the user can know what is going on
+ if ($this->action === 'getreport') {
+ $report = RemoteReport::generateReport(strtotime('-7 days'), time('now'));
+ Header('Content-Disposition: attachment; filename=remote-report.json');
+ Header('Content-Type: application/json; charset=utf-8');
+ die(json_encode($report));
+ }
}
/**
@@ -105,6 +113,13 @@ class Page_Statistics_Reporting extends Page
$data['lower'] = $this->lower;
$data['upper'] = $this->upper;
+ if (RemoteReport::isReportingEnabled()) {
+ $data['settingsButtonClass'] = 'default';
+ $data['reportChecked'] = 'checked';
+ } else {
+ $data['settingsButtonClass'] = 'danger';
+ }
+
Render::addTemplate('columnChooser', $data);
$data['data'] = $this->fetchData(GETDATA_PRINTABLE);
@@ -124,8 +139,15 @@ class Page_Statistics_Reporting extends Page
die('Missing setting value.');
}
RemoteReport::setReportingEnabled($state);
- } elseif ($this->action === 'getReporting') {
- echo RemoteReport::isReportingEnabled() ? 'on' : '';
+ $data = array();
+ if (RemoteReport::isReportingEnabled()) {
+ $data['class'] = 'default';
+ $data['checked'] = true;
+ } else {
+ $data['class'] = 'danger';
+ }
+ Header('Content-Type: application/json; charset=utf-8');
+ die(json_encode($data));
} else {
echo 'Invalid action.';
}
diff --git a/modules-available/statistics_reporting/templates/columnChooser.html b/modules-available/statistics_reporting/templates/columnChooser.html
index efc1f355..9707c970 100644
--- a/modules-available/statistics_reporting/templates/columnChooser.html
+++ b/modules-available/statistics_reporting/templates/columnChooser.html
@@ -2,7 +2,7 @@
<input type="hidden" name="do" value="statistics_reporting">
<div class="row">
<div class="col-md-12">
- <button id="button-settings" type="button" class="pull-right btn btn-default" data-toggle="modal" data-target="#modal-settings" onclick="loadSettings()"><span class="glyphicon glyphicon-cog"></span></button>
+ <button id="button-settings" type="button" class="pull-right btn btn-{{settingsButtonClass}}" data-toggle="modal" data-target="#modal-settings"><span class="glyphicon glyphicon-cog"></span></button>
<strong class="text-capitalize">{{lang_displaySelection}}</strong>
</div>
</div>
@@ -72,8 +72,12 @@
</div>
<div class="modal-body">
<div class="checkbox">
- <input id="checkbox-reporting" type="checkbox" value="on" style="margin-top: 0; margin-left: -30px">
- <label for="checkbox-reporting" style="padding-left: 40px">{{lang_reportingDescription}}</label>
+ <input id="checkbox-reporting" type="checkbox" value="on" {{reportChecked}}>
+ <label for="checkbox-reporting" style="padding-left: 40px">{{lang_reportingLabel}}</label>
+ </div>
+ <div>
+ <p>{{lang_reportingDescription}}</p>
+ <a class="btn btn-success" href="?do=statistics_reporting&amp;action=getreport">{{lang_downloadReport}}</a>
</div>
</div>
<div class="modal-footer">
@@ -120,10 +124,14 @@
$(".locationLink").click(function(e) {
e.preventDefault();
var form = $('#controlsForm');
- $('<input />').attr('type', 'hidden')
- .attr('name', "location")
- .attr('value', $(this).data('lid'))
- .appendTo(form);
+ var inp = $('#location-id');
+ if (inp.length === 0) {
+ inp = $('<input />').attr('type', 'hidden')
+ .attr('name', "location")
+ .attr('id', 'location-id')
+ .appendTo(form);
+ }
+ inp.attr('value', $(this).data('lid'));
form.find('#select-table').val("location");
form.submit();
});
@@ -150,22 +158,19 @@
}
}
- function loadSettings() {
- $.ajax({
- url: '?do=statistics_reporting',
- type: 'GET',
- data: { action: "getReporting"},
- success: function(value) {
- $("#checkbox-reporting").prop("checked", value == "on");
- }
- });
- }
-
function saveSettings() {
$.ajax({
url: '?do=statistics_reporting',
type: 'POST',
- data: { action: "setReporting", reporting: $("#checkbox-reporting").is(":checked") ? "on" : "off", token: TOKEN }
+ data: { action: "setReporting", reporting: $("#checkbox-reporting").is(":checked") ? "on" : "off", token: TOKEN },
+ success: function(value) {
+ if (typeof(value) === 'object') {
+ $("#checkbox-reporting").prop('checked', !!value['checked']);
+ $("#button-settings").removeClass('btn-default btn-danger').addClass('btn-' + value['class']);
+ } else {
+ alert('Invalid reply when setting value: ' + value + ' (' + typeof(value) + ')');
+ }
+ }
});
}
</script> \ No newline at end of file