Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit e5adb8b

Browse files
committed
new visual form, possibility to change time range
1 parent bd528a0 commit e5adb8b

14 files changed

+429
-246
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
All notable changes to this project will be documented in this file.
33

44
## [Unreleased]
5+
[Added]
6+
- Possibility to change the time range of displayed data
7+
58
[Changed]
6-
- DB commands work for apostrophe in IdP/SP names
9+
- DB commands work with apostrophes in IdP/SP names
10+
- New visual form of the site
711

812
## [v1.3.0]
913
[Added]

dictionaries/Proxystatistics.definition.json

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,33 @@
33
"en": "Summary",
44
"cs": "Shrnutí"
55
},
6-
"templates/statistics-tpl_graphs": {
7-
"en": "Graphs",
8-
"cs": "Grafy"
6+
"templates/statistics-tpl_idpsDetail": {
7+
"en": "Identity providers detail",
8+
"cs": "Detail poskytovatelů identity"
99
},
10-
"templates/statistics-tpl_tables": {
11-
"en": "Tables",
12-
"cs": "Tabulky"
10+
"templates/statistics-tpl_spsDetail": {
11+
"en": "Service providers detail",
12+
"cs": "Detail služeb"
13+
},
14+
"templates_time_range": {
15+
"en": "Select the time range:",
16+
"cs": "Vyberte časový interval:"
17+
},
18+
"templates/statistics-tpl_all": {
19+
"en": "All",
20+
"cs": "Vše"
21+
},
22+
"templates/statistics-tpl_week": {
23+
"en": "Last 7 days",
24+
"cs": "Posledních 7 dnů"
25+
},
26+
"templates/statistics-tpl_month": {
27+
"en": "Last 30 days",
28+
"cs": "Posledních 30 dnů"
29+
},
30+
"templates/statistics-tpl_year": {
31+
"en": "Last year",
32+
"cs": "Poslední rok"
1333
},
1434
"templates/summary_overall_logins": {
1535
"en": "Overall number of logins",

lib/Auth/Process/DatabaseCommand.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@ public static function insertLogin(&$request, &$date)
5757
$conn->close();
5858
}
5959

60-
public static function getLoginCountPerDay()
60+
public static function getLoginCountPerDay($days)
6161
{
6262
$databaseConnector = new DatabaseConnector();
6363
$conn = $databaseConnector->getConnection();
6464
assert($conn != NULL);
6565
$table_name = $databaseConnector->getIdentityProvidersTableName();
66-
$stmt = $conn->prepare("SELECT year, month, day, SUM(count) AS count FROM ".$table_name." GROUP BY year DESC,month DESC,day DESC");
66+
if($days == 0) { // 0 = all time
67+
$stmt = $conn->prepare("SELECT year, month, day, SUM(count) AS count FROM ".$table_name." GROUP BY year DESC,month DESC,day DESC");
68+
} else {
69+
$stmt = $conn->prepare("SELECT year, month, day, SUM(count) AS count FROM ".$table_name." WHERE CONCAT(year,'-',LPAD(month,2,'00'),'-',LPAD(day,2,'00')) BETWEEN CURDATE() - INTERVAL ".$days." DAY AND CURDATE() GROUP BY year DESC,month DESC,day DESC");
70+
}
6771
$stmt->execute();
6872
$result = $stmt->get_result();
6973
while($row = $result->fetch_assoc()) {
@@ -148,14 +152,18 @@ public static function getCountOfAllLoginsForToday()
148152
}
149153

150154

151-
public static function getAccessCountPerService()
155+
public static function getAccessCountPerService($days)
152156
{
153157
$databaseConnector = new DatabaseConnector();
154158
$conn = $databaseConnector->getConnection();
155159
assert($conn != NULL);
156160
$serviceProvidersTableName = $databaseConnector->getServiceProvidersTableName();
157161
$serviceProvidersMapTableName = $databaseConnector->getServiceProvidersMapTableName();
158-
$stmt = $conn->prepare("SELECT IFNULL(name,service) AS spName, SUM(count) AS count FROM ".$serviceProvidersTableName." LEFT OUTER JOIN " . $serviceProvidersMapTableName . " ON service = identifier GROUP BY service HAVING service != ''");
162+
if($days == 0) { // 0 = all time
163+
$stmt = $conn->prepare("SELECT IFNULL(name,service) AS spName, SUM(count) AS count FROM " . $serviceProvidersTableName . " LEFT OUTER JOIN " . $serviceProvidersMapTableName . " ON service = identifier GROUP BY service HAVING service != ''");
164+
} else {
165+
$stmt = $conn->prepare("SELECT year, month, day, IFNULL(name,service) AS spName, SUM(count) AS count FROM " . $serviceProvidersTableName . " LEFT OUTER JOIN " . $serviceProvidersMapTableName . " ON service = identifier WHERE CONCAT(year,'-',LPAD(month,2,'00'),'-',LPAD(day,2,'00')) BETWEEN CURDATE() - INTERVAL ".$days." DAY AND CURDATE() GROUP BY service HAVING service != ''");
166+
}
159167
$stmt->execute();
160168
$result = $stmt->get_result();
161169
while($row = $result->fetch_assoc()) {
@@ -164,14 +172,18 @@ public static function getAccessCountPerService()
164172
$conn->close();
165173
}
166174

167-
public static function getLoginCountPerIdp()
175+
public static function getLoginCountPerIdp($days)
168176
{
169177
$databaseConnector = new DatabaseConnector();
170178
$conn = $databaseConnector->getConnection();
171179
assert($conn != NULL);
172180
$identityProvidersTableName = $databaseConnector->getIdentityProvidersTableName();
173181
$identityProvidersMapTableName = $databaseConnector->getIdentityProvidersMapTableName();
174-
$stmt = $conn->prepare("SELECT IFNULL(name,sourceIdp) AS idPName, SUM(count) AS count FROM ".$identityProvidersTableName. " LEFT OUTER JOIN " . $identityProvidersMapTableName . " ON sourceIdp = entityId GROUP BY sourceIdp HAVING sourceIdp != ''");
182+
if($days == 0) { // 0 = all time
183+
$stmt = $conn->prepare("SELECT IFNULL(name,sourceIdp) AS idPName, SUM(count) AS count FROM ".$identityProvidersTableName. " LEFT OUTER JOIN " . $identityProvidersMapTableName . " ON sourceIdp = entityId GROUP BY sourceIdp HAVING sourceIdp != ''");
184+
} else {
185+
$stmt = $conn->prepare("SELECT year, month, day, IFNULL(name,sourceIdp) AS idPName, SUM(count) AS count FROM ".$identityProvidersTableName. " LEFT OUTER JOIN " . $identityProvidersMapTableName . " ON sourceIdp = entityId WHERE CONCAT(year,'-',LPAD(month,2,'00'),'-',LPAD(day,2,'00')) BETWEEN CURDATE() - INTERVAL ".$days." DAY AND CURDATE() GROUP BY sourceIdp HAVING sourceIdp != ''");
186+
}
175187
$stmt->execute();
176188
$result = $stmt->get_result();
177189
while($row = $result->fetch_assoc()) {

templates/graphs-tpl.php

Lines changed: 0 additions & 107 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
include dirname(__DIR__)."/lib/Auth/Process/DatabaseCommand.php";
3+
/**
4+
* @author Pavel Vyskočil <[email protected]>
5+
* @author Dominik Baránek <[email protected]>
6+
*/
7+
$lastDays = $this->data['lastDays'];
8+
9+
?>
10+
<link rel="stylesheet" media="screen" type="text/css" href="<?php SimpleSAML_Module::getModuleUrl('proxystatistics/statisticsproxy.css')?>" />
11+
<script type="text/javascript">
12+
google.charts.load('current', {'packages':['corechart', 'table']});
13+
google.charts.setOnLoadCallback(drawIdpsChart);
14+
google.charts.setOnLoadCallback(drawIdpsTable);
15+
16+
function drawIdpsChart() {
17+
var data = google.visualization.arrayToDataTable([
18+
['sourceIdp', 'Count'],
19+
<?php DatabaseCommand::getLoginCountPerIdp($lastDays)?>
20+
]);
21+
22+
var options = {
23+
pieSliceText: 'value',
24+
chartArea:{left:20,top:0,width:'100%',height:'100%'},
25+
};
26+
27+
var chart = new google.visualization.PieChart(document.getElementById('idpsChartDetail'));
28+
29+
data.sort([{column: 1, desc: true}]);
30+
chart.draw(data, options);
31+
}
32+
33+
function drawIdpsTable() {
34+
var data = new google.visualization.DataTable();
35+
data.addColumn('date', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/tables_month}'); ?>');
36+
data.addColumn('string', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/tables_identity_provider}'); ?>');
37+
data.addColumn('number', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/count}'); ?>');
38+
data.addRows([<?php DatabaseCommand::getLoginCountPerDeyPerService()?>]);
39+
40+
var table = new google.visualization.Table(document.getElementById('idpsTable'));
41+
42+
var formatter = new google.visualization.DateFormat({pattern:"MMMM yyyy"});
43+
formatter.format(data, 0); // Apply formatter to second column
44+
45+
table.draw(data);
46+
}
47+
48+
</script>
49+
</head>
50+
51+
<body>
52+
<div class="timeRange">
53+
<h4><?php echo $this->t('{proxystatistics:Proxystatistics:templates_time_range}'); ?></h4>
54+
<form id="dateSelector" method="post" >
55+
<input name="tab" value="2" hidden>
56+
<label>
57+
<input id="1" type="radio" name="lastDays" value=0 onclick="this.form.submit()" <?php echo ($lastDays == 0) ? "checked=true" : "" ?> > <?php echo $this->t('{proxystatistics:Proxystatistics:templates/statistics-tpl_all}'); ?>
58+
</label>
59+
<label>
60+
<input id="2" type="radio" name="lastDays" value=7 onclick="this.form.submit()" <?php echo ($lastDays == 7) ? "checked=true" : "" ?>> <?php echo $this->t('{proxystatistics:Proxystatistics:templates/statistics-tpl_week}'); ?>
61+
</label>
62+
<label>
63+
<input id="3" type="radio" name="lastDays" value=30 onclick="this.form.submit()" <?php echo ($lastDays == 30) ? "checked=true" : "" ?>> <?php echo $this->t('{proxystatistics:Proxystatistics:templates/statistics-tpl_month}'); ?>
64+
</label>
65+
<label>
66+
<input id="4" type="radio" name="lastDays" value=365 onclick="this.form.submit()" <?php echo ($lastDays == 365) ? "checked=true" : "" ?>> <?php echo $this->t('{proxystatistics:Proxystatistics:templates/statistics-tpl_year}'); ?>
67+
</label>
68+
</form>
69+
</div>
70+
71+
<h2><?php echo $this->t('{proxystatistics:Proxystatistics:templates/graphs_id_providers}'); ?></h2>
72+
<div class="row">
73+
<div class="col-md-8">
74+
<div id="idpsChartDetail" ></div>
75+
</div>
76+
<div class="col-md-4">
77+
<div id="idpsTable" ></div>
78+
</div>
79+
</div>
80+
</body>

templates/serviceProviders-tpl.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
include dirname(__DIR__)."/lib/Auth/Process/DatabaseCommand.php";
3+
4+
/**
5+
* @author Pavel Vyskočil <[email protected]>
6+
* @author Dominik Baránek <[email protected]>
7+
*/
8+
9+
$lastDays = $this->data['lastDays'];
10+
11+
?>
12+
<script type="text/javascript">
13+
google.charts.load('current', {'packages':['corechart', 'table']});
14+
google.charts.setOnLoadCallback(drawSpsChart);
15+
google.charts.setOnLoadCallback(drawSpsTable);
16+
17+
function drawSpsChart() {
18+
var data = google.visualization.arrayToDataTable([
19+
['service', 'Count'],
20+
<?php DatabaseCommand::getAccessCountPerService($lastDays)?>
21+
]);
22+
23+
var options = {
24+
pieSliceText: 'value',
25+
chartArea:{left:20,top:0,width:'100%',height:'100%'}
26+
};
27+
28+
var chart = new google.visualization.PieChart(document.getElementById('spsChartDetail'));
29+
30+
data.sort([{column: 1, desc: true}]);
31+
chart.draw(data, options);
32+
}
33+
34+
function drawSpsTable() {
35+
var data = new google.visualization.DataTable();
36+
data.addColumn('date', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/tables_month}'); ?>');
37+
data.addColumn('string', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/tables_service_provider}'); ?>');
38+
data.addColumn('number', '<?php echo $this->t('{proxystatistics:Proxystatistics:templates/count}'); ?>');
39+
data.addRows([<?php DatabaseCommand::getAccessToServicesPerMonth()?>]);
40+
41+
var table = new google.visualization.Table(document.getElementById('spsTable'));
42+
43+
var formatter = new google.visualization.DateFormat({pattern:"MMMM yyyy"});
44+
formatter.format(data, 0); // Apply formatter to second column
45+
46+
table.draw(data);
47+
}
48+
</script>
49+
</head>
50+
51+
<body>
52+
<div class="timeRange">
53+
<h4><?php echo $this->t('{proxystatistics:Proxystatistics:templates_time_range}'); ?></h4>
54+
<form id="dateSelector" method="post" >
55+
<input name="tab" value="3" hidden>
56+
<label>
57+
<input id="1" type="radio" name="lastDays" value=0 onclick="this.form.submit()" <?php echo ($lastDays == 0) ? "checked=true" : "" ?> > <?php echo $this->t('{proxystatistics:Proxystatistics:templates/statistics-tpl_all}'); ?>
58+
</label>
59+
<label>
60+
<input id="2" type="radio" name="lastDays" value=7 onclick="this.form.submit()" <?php echo ($lastDays == 7) ? "checked=true" : "" ?>> <?php echo $this->t('{proxystatistics:Proxystatistics:templates/statistics-tpl_week}'); ?>
61+
</label>
62+
<label>
63+
<input id="3" type="radio" name="lastDays" value=30 onclick="this.form.submit()" <?php echo ($lastDays == 30) ? "checked=true" : "" ?>> <?php echo $this->t('{proxystatistics:Proxystatistics:templates/statistics-tpl_month}'); ?>
64+
</label>
65+
<label>
66+
<input id="4" type="radio" name="lastDays" value=365 onclick="this.form.submit()" <?php echo ($lastDays == 365) ? "checked=true" : "" ?>> <?php echo $this->t('{proxystatistics:Proxystatistics:templates/statistics-tpl_year}'); ?>
67+
</label>
68+
</form>
69+
</div>
70+
71+
<h2><?php echo $this->t('{proxystatistics:Proxystatistics:templates/graphs_service_providers}'); ?></h2>
72+
<div class="row">
73+
<div class="col-md-8">
74+
<div id="spsChartDetail" ></div>
75+
</div>
76+
<div class="col-md-4">
77+
<div id="spsTable" ></div>
78+
</div>
79+
</div>
80+
</body>

0 commit comments

Comments
 (0)