-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathviews.php
More file actions
115 lines (98 loc) · 3.26 KB
/
views.php
File metadata and controls
115 lines (98 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
require_once "../config.php";
// The Tsugi PHP API Documentation is available at:
// http://do1.dr-chuck.com/tsugi/phpdoc/
use \Tsugi\Util\Net;
use \Tsugi\Util\U;
use \Tsugi\Core\LTIX;
use \Tsugi\Core\Settings;
use \Tsugi\Core\User;
use \Tsugi\UI\SettingsForm;
// Allow this to just be launched as a naked URL w/o LTI
$LTI = LTIX::requireData();
$user_id = U::get($_GET, 'user_id', 0);
if ( ! $USER->id || ! $LINK->id ) {
Net::send403();
return;
}
if ( $USER->instructor ) {
// OK
} else if ( $USER->id == $user_id && $user_id > 0 ) {
// OK
} else {
Net::send403();
return;
}
$rows = array();
if ( $USER->instructor ) {
$sql = "SELECT V.user_id AS user_id, displayname, email
FROM {$CFG->dbprefix}youtube_views_user AS V
JOIN {$CFG->dbprefix}lti_user AS U ON V.user_id = U.user_id
WHERE link_id = :link_id
ORDER BY displayname, email";
$rows = $PDOX->allRowsDie($sql, array(
':link_id' => $LINK->id
));
}
$menu = new \Tsugi\UI\MenuSet();
$menu->addLeft(__('Back'), 'index.php');
// Render view
$OUTPUT->header();
$OUTPUT->bodyStart();
$OUTPUT->topNav($menu);
// https://codepen.io/team/css-tricks/pen/pvamy
// https://css-tricks.com/seamless-responsive-photo-grid/
if ( count($rows) > 0 ) {
echo("<form>\n");
echo('<select name="user_id" onchange="this.form.submit()">'."\n");
echo(' <option value="0">All Users</option>'."\n");
foreach($rows as $row) {
$display = User::getDisplay($row['user_id'], $row['displayname'], $row['email']);
echo(' <option value="'.$row['user_id'].'"');
if ( $row['user_id'] == $user_id ) echo (" selected ");
echo('>'.htmlentities($display).'</option>'."\n");
}
echo("</select><form>\n");
}
?>
<div id="chartWrapper"><div id="chart_div" style="width: 90%; height: 400px;">Loading View Stats</div></div>
<?php
$data_url = 'viewdata.php';
if ( $user_id > 0 ) $data_url .= '?user_id=' . $user_id;
$data_url = addSession($data_url);
$OUTPUT->footerStart();
?>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script>
function drawBasic() {
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
var graphData = [['% Video Time', 'Views']];
$.getJSON("<?= $data_url ?>", function(functionData) {
console.log(functionData);
if ( functionData.error ) {
$('#chart_div').text(functionData.error);
return;
}
if ( ! functionData.vector ) {
$('#chart_div').text('No data returned');
return;
}
var vector = functionData.vector;
console.log(vector);
var options = {
title: functionData.title,
hAxis: {title: functionData.hAxis},
vAxis: {title: functionData.vaxis},
legend: 'none'
};
chart.draw(google.visualization.arrayToDataTable(vector), options);
setInterval(drawBasic, 15000); // Auto refresh
});
}
$(document).ready(function() {
google.charts.load('current', {packages: ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawBasic);
});
</script>
<?php
$OUTPUT->footerEnd();