diff --git a/gui/ajax.php b/gui/ajax.php new file mode 100644 index 0000000..77c52dd --- /dev/null +++ b/gui/ajax.php @@ -0,0 +1,54 @@ + + +
+

Orari

+
+ + + +
+
+
+
+
Visibilità per orario
+
+
+
+ +
+
+
+
+
+ + + +
+
+
+
+
Visibilità per giorno
+
+
+
+ +
+
+
+
+
+ + + + + img{ width: 40px; +} + +.clickable{ + cursor: pointer; } \ No newline at end of file diff --git a/gui/js/util.js b/gui/js/util.js new file mode 100644 index 0000000..fde0b08 --- /dev/null +++ b/gui/js/util.js @@ -0,0 +1,51 @@ +// Modal +function openModal(title, href) { + // Fix - Select2 does not function properly when I use it inside a Bootstrap modal. + $.fn.modal.Constructor.prototype.enforceFocus = function () { + }; + + // Generazione dinamica modal + do { + id = '#bs-popup-' + Math.floor(Math.random() * 100); + } while ($(id).length != 0); + + if ($(id).length == 0) { + $('#modals').append(''); + } + + $(id).on('hidden.bs.modal', function () { + if ($('.modal-backdrop').length < 1) { + $(this).html(''); + $(this).data('modal', null); + } + }); + + var content = ''; + + // Lettura contenuto div + if (href.substr(0, 1) == '#') { + var data = $(href).html(); + + $(id).html(content.replace("|data|", data)); + $(id).modal('show'); + } else { + $.get(href, function (data, response) { + if (response == 'success') { + $(id).html(content.replace("|data|", data)); + $(id).modal('show'); + } + }); + } +} \ No newline at end of file diff --git a/gui/js/wifi-probe-aggregator.js b/gui/js/wifi-probe-aggregator.js index 0c4afc1..d8a59ff 100644 --- a/gui/js/wifi-probe-aggregator.js +++ b/gui/js/wifi-probe-aggregator.js @@ -29,9 +29,9 @@ function leggi_devices(interval){ // Aggiungo il dispositivo in lista se ancora non c'è row_id = 'mac_' + (result.records[i].mac).replace(/:/g, '_'); - if( $('#devices-table > tbody').find('tr[data-id="' + row_id + '"]').length == 0 ){ + if( $('#devices-table > tbody').find('tr[id="' + row_id + '"]').length == 0 ){ $('#devices-table > tbody').prepend( - '' + + '' + '' + '' + device + '' + '' + result.records[i].ssid + '' + @@ -39,6 +39,11 @@ function leggi_devices(interval){ '
' + '' ); + + // Bind modal + $('#' + row_id).on('click', function(){ + openModal( 'Dettagli su ' + $(this).data('name') + ' ' + $(this).data('mac'), 'ajax.php?op=get-details&mac=' + $(this).data('mac') ); + }); } } @@ -95,8 +100,8 @@ Date.prototype.formatMMDDYYYY = function() { "/" + this.getFullYear(); } -function drawBarChart( id, resource ) { - $.post( reader_url, { op: resource }, function(response){ +function drawBarChart( id, resource, mac ) { + $.post( reader_url, { op: resource, mac: mac }, function(response){ response = $.parseJSON(response); // Split timestamp and data into separate arrays @@ -182,7 +187,7 @@ function drawBarChart( id, resource ) { callbacks: { label: function(tooltipItem, chart) { var datasetLabel = chart.datasets[tooltipItem.datasetIndex].label || ''; - return tooltipItem.yLabel + ' devices'; + return tooltipItem.yLabel; } } }, diff --git a/gui/lib/util.php b/gui/lib/util.php new file mode 100644 index 0000000..f0a43c8 --- /dev/null +++ b/gui/lib/util.php @@ -0,0 +1,16 @@ + $('#menu-orari').addClass('active'); - drawBarChart( 'chart-orari', 'get-devices-by-hour' ); - drawBarChart( 'chart-giorno', 'get-devices-by-weekday' ); + drawBarChart( 'chart-orari', 'get-devices-by-hour', '' ); + drawBarChart( 'chart-giorno', 'get-devices-by-weekday', '' ); - - +
\ No newline at end of file diff --git a/gui/parts/header.php b/gui/parts/header.php index e52bae2..ddbf493 100644 --- a/gui/parts/header.php +++ b/gui/parts/header.php @@ -35,6 +35,7 @@ $config = parse_ini_file('../config.ini'); + diff --git a/ws/reader.php b/ws/reader.php index c94671e..a6682f5 100644 --- a/ws/reader.php +++ b/ws/reader.php @@ -280,6 +280,128 @@ switch( $_POST['op'] ){ $mysqli->close(); break; + case 'get-activity-by-hour': + // Connessione al database + $mysqli = mysqli_connect($config['db_host'], $config['db_user'], $config['db_pass'], $config['db_name']); + + // Errore nella connessione a database + if (mysqli_connect_errno($mysqli)) { + + $result = [ + 'status' => 'ERR', + 'message' => mysqli_connect_error(), + ]; + } else { + // Lettura numero di device unico nell'intervallo di date + $sql = " + SELECT + CONCAT( DATE_FORMAT(received_at, '%H'), ':00' ) AS indice, + COUNT(id) AS valore + FROM + `logs` + WHERE + mac='".$_POST['mac']."' + GROUP BY + DATE_FORMAT(received_at, '%H')"; + + $stmt = $mysqli->prepare($sql); + + // Errore nella preparazione query + if (!$stmt) { + $result = [ + 'status' => 'ERR', + 'message' => $mysqli->error, + ]; + } else { + // Esecuzione statement + $stmt->execute(); + + $rs = $stmt->get_result(); + + while ($row = $rs->fetch_assoc()) { + $records[] = $row; + } + + $result = [ + 'status' => 'OK', + 'records' => $records, + ]; + } + } + + echo json_encode($result); + + $stmt->close(); + $mysqli->close(); + break; + + + case 'get-activity-by-weekday': + $weekdays = [ + 0 => 'domenica', + 1 => 'lunedì', + 2 => 'martedì', + 3 => 'mercoledì', + 4 => 'giovedì', + 5 => 'venerdì', + 6 => 'sabato', + ]; + + // Connessione al database + $mysqli = mysqli_connect($config['db_host'], $config['db_user'], $config['db_pass'], $config['db_name']); + + // Errore nella connessione a database + if (mysqli_connect_errno($mysqli)) { + + $result = [ + 'status' => 'ERR', + 'message' => mysqli_connect_error(), + ]; + } else { + // Lettura numero di device unico nell'intervallo di date + $sql = " + SELECT + DATE_FORMAT(received_at, '%w') AS indice, + COUNT(id) AS valore + FROM + `logs` + WHERE + mac='".$_POST['mac']."' + GROUP BY + DATE_FORMAT(received_at, '%w')"; + + $stmt = $mysqli->prepare($sql); + + // Errore nella preparazione query + if (!$stmt) { + $result = [ + 'status' => 'ERR', + 'message' => $mysqli->error, + ]; + } else { + // Esecuzione statement + $stmt->execute(); + + $rs = $stmt->get_result(); + + while ($row = $rs->fetch_assoc()) { + $row['indice'] = $weekdays[ $row['indice'] ]; + $records[] = $row; + } + + $result = [ + 'status' => 'OK', + 'records' => $records, + ]; + } + } + + echo json_encode($result); + + $stmt->close(); + $mysqli->close(); + break; + case 'get-devices-by-vendor': // Vendor cache