-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.php
365 lines (295 loc) · 14.9 KB
/
view.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version information
*
* @package mod_evoting
* @copyright 2016 Cyberlearn
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once ("../../config.php");
require_once ("lib.php");
require_once ("locallib.php");
$PAGE->requires->jquery();
$PAGE->requires->js('/mod/evoting/js/google-jsapi.js');
// Get URL QRCODE (client poll)
$path = dirname($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
$id = required_param('id', PARAM_INT);
if (!$cm = get_coursemodule_from_id('evoting', $id)) {
print_error('invalidcoursemodule');
}
if (!$course = $DB -> get_record("course", array("id" => $cm -> course))) {
print_error('coursemisconf');
}
if (!$evoting = evoting_get_evoting($cm -> instance)) {
print_error('invalidcoursemodule');
}
require_course_login($course, false, $cm);
// Lang course
$lang = current_language();
// HTTP or HTTPS
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ||
$_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
// QR CODE URL
define('QRCODE_URL_LINK', "client_poll.php?id=" . $evoting->idpoll . '&lang=' . $lang);
// Hack Cyberlearn QR Code
if(strpos($path, 'cyberlearn') !== false){
define('QRCODE_URL', evoting_get_tiny_url($protocol . $path ."/". QRCODE_URL_LINK));
} else {
define('QRCODE_URL', $protocol . $path ."/". QRCODE_URL_LINK);
}
// Get Contexts
$context = context_module::instance($cm->id);
$context_course = context_course::instance($course -> id);
// If the user is not at least a teacher show the vote page
if(!has_capability('mod/evoting:openevoting', $context_course)){
header("Location:". QRCODE_URL_LINK);
exit();
} else{
// Print the page header.
$PAGE -> set_url('/mod/evoting/view.php', array('id' => $id));
$PAGE -> set_title(format_string($evoting -> name));
$PAGE -> set_heading(format_string($course -> fullname));
// Output starts here
$PAGE->requires->jquery();
$PAGE->requires->strings_for_js(array('countvote', 'end', 'endvote', 'seconds', 'choice', 'start', 'timechoice', 'msgShowQrCode', 'msgHideQrCode', 'totalvote', 'second', 'goodanswer'), 'evoting');
$PAGE->requires->js('/mod/evoting/js/mdl_poll.js');
echo $OUTPUT -> header();
// Title Poll
$divTitle = html_writer::start_tag('div', array('id' => 'divTitle', 'style' => 'float:left; text-align: center;'));
$divTitle .= html_writer::start_tag('h2', array('id'=>'namePoll'));
$divTitle .= $evoting -> name;
$divTitle .= html_writer::end_tag('h2');
$divTitle .= html_writer::empty_tag('span', array('id'=>'introPoll'));
$divTitle .= file_rewrite_pluginfile_urls($evoting -> intro, 'pluginfile.php', $context->id, 'mod_evoting', "intro", null);
$divTitle .= html_writer::end_tag('div');
echo $divTitle;
// QR Code and Link
$qrCodeS = "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=" . urlencode(QRCODE_URL) . "&choe=UTF-8";
$imgQrCodeS = html_writer::empty_tag('img', array('src'=>$qrCodeS, 'alt'=>'QrCode'));
$votelinkText = html_writer::start_tag('h5', array('style' => 'text-align: center; margin:0 auto')).get_string('vote', 'evoting') . html_writer::end_tag('h5');
$divButtonQRCode = html_writer::start_div('div', array('id' => 'divQrCode', 'style' => 'float:right'));
$divButtonQRCode .= html_writer::link('#', $imgQrCodeS, array('onclick' => 'M.mod_evoting.poll_init.showQrCode()', 'title' => get_string('msgShowQrCode', 'evoting')));
$divButtonQRCode .= html_writer::link(QRCODE_URL_LINK, $votelinkText, array('target'=>'_blank'));
$divButtonQRCode .= html_writer::end_div();
echo $divButtonQRCode;
echo html_writer::start_tag('div', array('style' => 'clear: both;'));
echo html_writer::end_tag('div');
echo $OUTPUT -> heading("<span style='display:none' id='numberQuestion'>" . $evoting -> questions -> number. "</span>", 5);
echo html_writer::start_tag('div', array('id' => 'questionName'));
echo file_rewrite_pluginfile_urls($evoting->questions->name, 'pluginfile.php', $context->id, 'mod_evoting', "questioneditor", $evoting->questions->id);
echo html_writer::end_tag('div');
// Count the options of the current question
$countOptions = count($evoting -> questions-> options);
$sumOptions = 0;
for ($i = 0; $i < $countOptions; $i++) {
$idOption = $evoting -> questions -> options[$i] -> id;
$obj = evoting_get_count_answer($idOption);
$sumOptions += intval($obj->{'count'}) ;
}
// Set to null the html futures options
$options = '';
$divOptionListContext = '';
// Array color
$arrayColor = array("#007cb7");
// Array from intitiate graphic
$arrayDataGraphic = array();
// Loop to create dynamic options
for ($i = 0; $i < $countOptions; $i++) {
$idOption = $evoting -> questions -> options[$i] -> id;
$nameOption = $evoting -> questions -> options[$i] -> text;
$obj = evoting_get_count_answer($idOption);
$currentOption = $obj->{'count'} ;
$options .= html_writer::empty_tag('p', array('class' => 'answerName', 'style' => 'display:inline-block'));
$options .= ($i+1) . ") " . $nameOption . ' ';
$options .= html_writer::start_span('answerCount', array('id' => $idOption, 'style' => 'display:none')) . $currentOption . html_writer::end_span();
$options .='</p>';
// Create html option list
$divOptionListContext .= html_writer::start_tag('div', array('id' => 'evotingOption', 'class'=>'evotingOption'));
$divOptionListContext .= html_writer::start_tag('div', array('id' => 'optionNo', 'class'=>'optionNo'));
$divOptionListContext .= $i+1;
$divOptionListContext .= html_writer::end_tag('div');
$divOptionListContext .= html_writer::start_tag('div', array('id' => 'optionText', 'class'=>'optionText'));
$divOptionListContext .= html_writer::start_tag('span');
$divOptionListContext .= $nameOption;
$divOptionListContext .= html_writer::end_tag('span');
$divOptionListContext .= html_writer::end_tag('div');
$divOptionListContext .= html_writer::end_tag('div');
// Create array for Graphic chart
$currentOption = intval($currentOption);
if($sumOptions > 0){
$percent = round($currentOption/$sumOptions*100);
} else {
$percent = 0;
}
// Set the true answer
$correctAnswer = $evoting -> questions -> options[$i] -> correct;
if($correctAnswer == 1 ){
$trueAnswer = true;
} else {
$trueAnswer = false;
}
if($sumOptions > 29){
$nameOption = $nameOption . " - " . $percent . " %" ;
} else {
if($currentOption == 0 && $sumOptions == 0){
$nameOption = $nameOption;
} else {
$nameOption = $nameOption . " - " . $currentOption . "/" . $sumOptions;
}
}
$arrayOptions = array(" " . ($i+1) . " ", $currentOption, $arrayColor[0], $nameOption , $idOption, ' <h5> '.get_string('countvote','evoting').' <b> '.$currentOption.'</b> </h5>', $trueAnswer);
array_push($arrayDataGraphic,$arrayOptions);
}
if($countOptions% 2 != 0)
{
$divOptionListContext .= html_writer::start_tag('div', array('id' => 'evotingOptionEmpty', 'class'=>'evotingOption'));
$divOptionListContext .= html_writer::start_tag('div', array('id' => 'optionNo', 'class'=>'optionNo')).' ';
$divOptionListContext .= html_writer::end_tag('div');
$divOptionListContext .= html_writer::start_tag('div', array('id' => 'optionText', 'class'=>'optionText'));
$divOptionListContext .= html_writer::start_tag('span').' ';
$divOptionListContext .= html_writer::end_tag('span');
$divOptionListContext .= html_writer::end_tag('div');
$divOptionListContext .= html_writer::end_tag('div');
}
// Div Chart
$divChart = html_writer::start_div('div', array('id' => 'chartContainer', 'style' => 'text-align:center')) . html_writer::end_div();
// Countdown Div
$divCountDown = html_writer::start_div('div', array('id' => 'divCountDown', 'class' => 'pie degree'));
$divCountDown .= html_writer::empty_tag('span', array('class'=>'block_time'));
$divCountDown .= html_writer::empty_tag('span', array('id'=>'time'));
$divCountDown .= html_writer::end_div();
$divCountDown .= html_writer::start_div('div', array('id' => 'divCountText'));
$divCountDown .= html_writer::end_div();
// Init option list
$divOptionList = html_writer::start_tag('div', array('id' => 'divOptions'));
$divOptionList .= $divOptionListContext;
$divOptionList .= html_writer::start_tag('div', array('style' => 'clear: both;'));
$divOptionList .= html_writer::end_tag('div');
$divOptionList .= html_writer::end_tag('div');
// Container Chart and countdown div
$divContainerChartCountDown = html_writer::start_div('div', array('id' => 'divContainerChartCountDown', "style" => "height:450px ; position:relative"));
$divContainerChartCountDown .= $divCountDown;
$divContainerChartCountDown .= $divChart;
$divContainerChartCountDown .= $divOptionList;
$divContainerChartCountDown .= html_writer::end_div();
echo $divContainerChartCountDown;
// Historique
$historyList = evoting_get_history_list($evoting -> questions -> id);
$countHistory = count($historyList);
if($countHistory > 0) {
$refHistorique = html_writer::start_tag('div', array('id' => 'divHistorique', 'style' => 'width: 100%; text-align: right;'));
} else {
$refHistorique = html_writer::start_tag('div', array('id' => 'divHistorique', 'style' => 'width: 100%; text-align: right; visibility:hidden'));
}
$refHistorique .= html_writer::start_tag('a', array( 'href' => 'history.php?id='.$id. '&idQ='.$evoting -> questions -> id.'&ts=0','class' => 'refHistoric', 'style'=> 'cursor:pointer;')) . get_string('history', 'evoting');
$refHistorique .= html_writer::end_tag('a');
$refHistorique .= html_writer::end_tag('div');
echo $refHistorique;
// Number Question
$questionslist = evoting_get_questions($evoting -> idpoll);
$questionslistlength = count($questionslist);
echo html_writer::start_tag('ul', array('class' => 'pagination'));
$disabled = 'disabled';
$html = html_writer::span('');
if($evoting -> questions -> number > 1 )
{
$disabled = '';
$html = html_writer::start_tag('a', array('href' => '#',
'title' => get_string('previous', 'evoting'), 'data-value' => -2, 'class' => 'pagenum'));
$html .= html_writer::end_tag('a');
}
echo html_writer::start_tag('li', array('class' => $disabled));
echo $html;
echo html_writer::end_tag('li');
foreach ($questionslist as $question) {
$current = '';
$htmlpage = html_writer::start_tag('a', array('href' => '#',
'class' => 'pagenum', 'data-value' => $question->number));
$htmlpage .= $question->number;
$htmlpage .= html_writer::end_tag('a');
if($question->number == $evoting -> questions -> number)
{
$current = "active";
$htmlpage = html_writer::span($question->number);
}
echo html_writer::start_tag('li', array('class' => $current));
echo $htmlpage;
echo html_writer::end_tag('li');
}
$disabled = 'disabled';
$html = html_writer::span('');
if($evoting -> questions -> number < $questionslistlength )
{
$disabled = '';
$html = html_writer::start_tag('a', array('href' => '#',
'title' => get_string('next', 'evoting'), 'data-value' => -1, 'class' => 'pagenum'));
$html .= html_writer::end_tag('a');
}
echo html_writer::start_tag('li', array('class' => $disabled));
echo $html;
echo html_writer::end_tag('li');
echo html_writer::end_tag('ul');
// Button and statut Start / Stop Poll
$divButtonActivPoll = html_writer::start_div('div', array('id' => 'divButtonActivPoll'));
$divButtonActivPoll .= html_writer::empty_tag('input', array('type'=>'button', 'class' => 'btn btn-lg btn-success', 'id'=>'buttonStatutPoll', 'value'=>get_string('start', 'evoting')));
$divButtonActivPoll .= html_writer::end_div();
// Button Reset
$divButtonResetQuestion = html_writer::start_div('', array('id' => 'divButtonNavigate'));
$divButtonResetQuestion .= html_writer::empty_tag('input', array('type'=>'button', 'id'=>'buttonResetQuestion', 'value'=>get_string('reset')));
$divButtonResetQuestion .= html_writer::end_div();
// Options
$divOptions = html_writer::start_div('', array('id' => 'divOptions', 'style' => 'display: none;'));
$divOptions .= $options;;
$divOptions .= html_writer::end_div();
echo $divOptions;
// Dropdown list Time voting
$divDropDownListQuestion = html_writer::start_div('', array('id' => 'divDropDownList'));
$options = array(
'1' => get_string('disable'),
'10' => ' 10 sec',
'20' => ' 20 sec',
'30' => ' 30 sec',
'60' => ' 1 min'
);
$selectTime = html_writer::start_div('', array('id' => 'selectZone'));
$selectTime .= html_writer::select($options, 'selectTime', 1);
$selectTime .= html_writer::end_div();
$divDropDownListQuestion .= html_writer::start_div('', array('id' => 'textSelect')).get_string('timevote', 'evoting');
$divDropDownListQuestion .= html_writer::end_div('');
$divDropDownListQuestion .= $selectTime;
$divDropDownListQuestion .= html_writer::end_div();
// Command panel
$divRowControl = html_writer::start_div('div', array('id' => 'divTableControl'));
$divRowControl .= $divButtonResetQuestion;
$divRowControl .= $divDropDownListQuestion;
$divRowControl .= $divButtonActivPoll;
$divRowControl .= html_writer::end_div();
$divTableControl = html_writer::start_div('div', array('id' => 'divTableControl', 'style' => 'display: table; width: 100%;text-align:center;'));
$divTableControl .= $divRowControl;
$divTableControl .= html_writer::end_div();
// Display Button
echo $divRowControl;
// Field ID Poll and ID Question next
echo $inputIdPoll = html_writer::empty_tag('input', array('type'=>'hidden', 'id'=>'inputIdPoll', 'value'=> $evoting->idpoll));
echo $inputIdCourse = html_writer::empty_tag('input', array('type'=>'hidden', 'id'=>'inputIdCourse', 'value'=> $course->id));
echo $inputIdQuestion = html_writer::empty_tag('input', array('type'=>'hidden', 'id'=>'inputIdQuestion', 'value'=> $evoting -> questions -> id));
echo $inputIdQuestionNext = html_writer::empty_tag('input', array('type'=>'hidden', 'id'=>'inputIdQuestionNext', 'value'=> $evoting->idquestionnext));
echo $div = html_writer::start_div('div', array('id' => 'affichage', 'style' => 'text-align:center')) . html_writer::end_div();
// Finish the page.
$PAGE->requires->js_init_call('M.mod_evoting.poll_init', array(json_encode($arrayDataGraphic)));
echo $OUTPUT -> footer();
}