/
index.php
executable file
·179 lines (155 loc) · 5.4 KB
/
index.php
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
require_once "../../config.php";
//echo('1');
use \Tsugi\Core\Settings;
use \Tsugi\Core\LTIX;
// Retrieve required launch data from session
$LTI = LTIX::requireData();
$p = $CFG->dbprefix;
date_default_timezone_set("America/New_York");
$today = date("Y-m-d");
//Handling post data
function addChoice($choice,$PDOX,$p,$LINK,$USER){
$PDOX->queryDie("INSERT INTO {$p}clicker
(link_id, user_id, guess, attend, ipaddr, count)
VALUES ( :LI, :UI, :GU, NOW(), :IP, 1)
ON DUPLICATE KEY UPDATE guess = :GU, ipaddr = :IP, count = count + 1",
array(
':LI' => $LINK->id,
':UI' => $USER->id,
':GU' => $choice,
':IP' => $_SERVER["REMOTE_ADDR"]
));
$_SESSION['success'] = 'Guess Recorded';
header('Location: '.addSession('index.php') ) ;
}
$numA = 0;
$numB = 0;
$numC = 0;
$numD = 0;
$numE = 0;
$taken = 0;
$results = $PDOX->allRowsDie("SELECT guess, COUNT(guess) AS total FROM {$p}clicker WHERE attend = :TODAY GROUP BY guess ORDER BY guess ASC",
array(':TODAY' => $today
));
$size = sizeof($results);
while($taken < $size){
if(@$results[$taken]['total'] != null){
$totalTaken = $results[$taken]['total'];
$choice = @$results[$taken]['guess'];
switch($choice){
case 0:
$numA = 0 + $results[$taken]['total'];
break;
case 1:
$numB = 0 + $results[$taken]['total'];
break;
case 2:
$numC = 0 + $results[$taken]['total'];
break;
case 3:
$numD = 0 + $results[$taken]['total'];
break;
case 4:
$numE = 0 + $results[$taken]['total'];
break;
}
}
$taken ++;
}
if(!isset($_POST['reset']) ){
if(isset($_POST['sendA']) ){
echo("!!!!!!!!!!");
addChoice(0,$PDOX,$p,$LINK,$USER);
return;
}else if(isset($_POST['sendB']) ){
addChoice(1,$PDOX,$p,$LINK,$USER);
return;
}else if(isset($_POST['sendC']) ){
addChoice(2,$PDOX,$p,$LINK,$USER);
return;
}
else if(isset($_POST['sendD']) ){
addChoice(3,$PDOX,$p,$LINK,$USER);
return;
}
else if(isset($_POST['sendE']) ){
addChoice(4,$PDOX,$p,$LINK,$USER);
return;
}
}
else{
$PDOX->queryDie("UPDATE {$p}clicker SET guess = 5 WHERE attend = :TODAY",
array(':TODAY' => $today
));
$PDOX->queryDie("UPDATE {$p}clicker SET count = count - 1 WHERE count > 0 AND attend = :TODAY",
array(':TODAY' => $today
));
header('Location: '.addSession('index.php') ) ;
return;
}
$OUTPUT->header(); // Start the document and begin the <head>
$OUTPUT->bodyStart(); // Finish the </head> and start the <body>
$OUTPUT->flashMessages(); // Print out the $_SESSION['success'] and error messages
// A partial form styled using Twitter Bootstrap; button setup
echo('<form method="post">');
echo("Enter your answer:\n");
echo('<input type="submit" class="btn btn-primary" name="sendA" value="'._('A').'"> ');
echo('<input type="submit" class="btn btn-primary" name="sendB" value="'._('B').'"> ');
echo('<input type="submit" class="btn btn-primary" name="sendC" value="'._('C').'"> ');
echo('<input type="submit" class="btn btn-primary" name="sendD" value="'._('D').'"> ');
echo('<input type="submit" class="btn btn-primary" name="sendE" value="'._('E').'"> ');
$table = array();
// convert data into JSON format
$jsonTable = json_encode($table);
if ( $USER->instructor) {
?>
<input type="submit" name="reset" class="btn btn-danger" value="Reset" >
</form>
<script type="text/javascript" src = "script.js?x=<?= time() ?>"></script>
<div style = "position:absolute; top:0px; right:0px">
<button type="submit" class="btn btn-success" name="toggle" id = "showAnswer" onclick="toggle('chart_div');"> Chart</button>
<a href="attendance.php" class="btn btn-info">Check Attendance</a>
</div>
<!---Google chart-->
<script type="text/javascript" src = "https://www.google.com/jsapi"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Element', 'Quantity', { role: 'style' }, {role:'annotation'}],
['A', <?=$numA?>, 'red', 'A'],
['B', <?=$numB?>, 'blue', 'B'],
['C', <?=$numC?>, 'grey', 'C'],
['D', <?=$numD?>, 'green', 'D'],
['E', <?=$numE?>, 'purple', 'E'],
]);
// Set chart options
var options = {
legend:'none',
title: 'Answer Distribution',
width: 800,
height: 600,
bar:{groupwidth:'95%'},
vAxis:{title:'Quantity', viewWindow:{min:0}},
hAxis:{title:'Answers',}
};
// Instantiate and draw our chart, passing in some options.
// Do not forget to check your div ID
var colchart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
colchart.draw(data, options);
}
</script>
<div id="chart_div" style="display:none"></div>
<!--End of Google chart-->
<?
}
// Finish the body (including loading JavaScript for JQUery and Bootstrap)
// And put out the common footer material
$OUTPUT->footer();