-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathview.php
More file actions
executable file
·555 lines (436 loc) · 19 KB
/
view.php
File metadata and controls
executable file
·555 lines (436 loc) · 19 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
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
<?php
/**
* This page prints a particular instance of exagames
*
* @author
* @version $Id: view.php,v 1.6 2007/09/03 12:23:36 jamiesensei Exp $
* @package exagames
**/
require_once("inc.php");
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
$a = optional_param('a', 0, PARAM_INT); // exagames ID
$action = optional_param('action', '', PARAM_TEXT);
// Moodle has many Notice|Deprecation errors in the own code, so disable PHP errors if it is an ajax requests for Flash or other...
// useful id the Moodle is configured in 'developer' mode
if (in_array($action, ['data', 'translations', ])) {
ini_set('display_errors', '0');
error_reporting(E_ERROR);
define('NO_DEBUG_DISPLAY', true);
}
// from moodle 2.2 on we have to use optional_param_array, optional_param won't accept arrays
$out = array();
global $COURSE, $CFG, $DB, $USER, $PAGE;
$img_files = array();
$responses = function_exists('optional_param_array') ? optional_param_array('responses', array(), PARAM_TEXT) : optional_param('responses', array(), PARAM_RAW);
if ($id) {
if (! $cm = $DB->get_record("course_modules", array("id" => $id))) {
print_error("Course Module ID was incorrect");
}
if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
print_error("Course is misconfigured");
}
if (! $game = exagames_get_game_instance($cm->instance)) {
print_error("Game not found");
}
} else {
$exagame = $DB->get_record('exagames', ['id' => @$PAGE->cm->instance]);
if (! $game = $DB->get_record("exagames", array("id" => $exagame->id))) {
print_error("Course module is incorrect");
}
if (! $course = $DB->get_record("course", array("id" => $game->course))) {
print_error("Course is misconfigured");
}
if (! $cm = get_coursemodule_from_instance("exagames", $game->id, $course->id)) {
print_error("Course Module ID was incorrect");
}
}
require_login($course->id);
if($game->gametype != "gamelabs")
$quiz = exagames_load_quiz($game->quizid);
if ($action == 'translations') {
require dirname(__FILE__).'/lib/Pro/SimpleXMLElement.php';
$xmlResult = Pro_SimpleXMLElement::create('translations');
$strings = array('true', 'false', 'question', 'startagain', 'mark');
foreach ($strings as $string) {
$xmlResult->$string = exagames_get_string($string, 'quiz');
}
$xmlResult->continue = exagames_get_string('continue');
$xmlResult->savingdata = exagames_get_string('savingdata');
$xmlResult->score = exagames_get_string('score', 'search');
$xmlResult->returntocourse = exagames_get_string('returntocourse', 'lesson');
header('Content-Type: text/xml; charset=utf-8');
echo $xmlResult->asPrettyXml();
exit;
}
if ($action == 'data') {
// flash handlers
$isguest = isguestuser();
//not working at the moment
if (!isguestuser() && $responses) {
// save game responses
// calc grade
$grade = exagames_calc_grade_from_responses($quiz, $responses);
require_once $CFG->dirroot.'/mod/quiz/locallib.php';
$attemptgrade = quiz_rescale_grade($grade, $quiz);
// save grade
$updateGrade = new StdClass;
$updateGrade->rawgrade = $grade;
$updateGrade->userid = $USER->id;
echo "<script>alert('$grade')</script>";
exagames_grade_item_update($game, $updateGrade);
exagames_quiz_attempt($game, $updateGrade);
/*
<result>
<score percent="0.5" sumgrades="44" grade="22" />
<feedback>text</feedback>
</result>
*/
require dirname(__FILE__).'/lib/Pro/SimpleXMLElement.php';
$xmlResult = Pro_SimpleXMLElement::create('result');
$xmlResult->addChild('score')->setAttributes(array(
'percent' => $grade / $quiz->sumgrades * 100,
'sumgrades' => $quiz->sumgrades,
'grade' => $grade
));
// Todo: Feedback
$context = context_block::instance(CONTEXT_MODULE, $cm->id);
$xmlResult->feedback = quiz_feedback_for_grade($attemptgrade, $quiz, $context);
echo "<script>console.log('$xmlResult->feedback')</script>";
$json = json_encode($xmlResult);
$xmlArr = json_decode($json,TRUE);
$scoreDb = new stdClass();
$scoreDb->userid = $USER->id;
$scoreDb->gameid = $game->id;
$scoreDb->gametype = $game->gametype;
$scoreDb->score = $xmlArr['score']['@attributes']['percent'];
$scoreDb->time = time();
$DB->insert_record('exagames_scores', $scoreDb);
header('Content-Type: text/xml; charset=utf-8');
echo $xmlResult->asPrettyXML();
exit;
} elseif (!isguestuser() && $game->hasHighscore && (($score = optional_param('score', -9999, PARAM_FLOAT)) != -9999)) {
$scoreDb = new stdClass();
$scoreDb->userid = $USER->id;
$scoreDb->gameid = $game->id;
$scoreDb->gametype = $game->gametype;
$scoreDb->score = intval($score*100);
$scoreDb->time = time();
$DB->insert_record('exagames_scores', $scoreDb);
echo 'ok=1';
exit;
} else {
// output gamedata as xml for flash
require dirname(__FILE__).'/lib/Pro/SimpleXMLElement.php';
$xmlQuiz = Pro_SimpleXMLElement::create('quiz');
$xmlQuiz->setAttribute('sumgrades', $quiz->sumgrades);
$xmlUser = $xmlQuiz->addChild('user')->setAttribute('id', $USER->id);
$xmlUser->addChild('name', fullname($USER));
$xmlQuiz->intro = exagames_html_to_text(@$quiz->intro);
if ($game->gametype == 'tiles') {
$xmlQuiz->rules = null;
$xmlQuiz->rules->addCData(get_string("game_tiles_rules", "exagames"));
}
$xmlQuestions = $xmlQuiz->addChild('questions');
foreach ($quiz->questions as $question) {
$xmlQuestion = $xmlQuestions->addChild('question');
$xmlQuestion->setAttributes(array(
'id' => $question->id,
'type' => $question->get_type_name(),
'grade' => $question->maxmark
));
// $xmlQuestion->name = $question->name;
$xmlQuestion->text = exagames_html_to_text($question->questiontext);
if ($game->gametype == 'tiles') {
$xmlQuestion->config->tile_size = $question->tile_size;
$xmlQuestion->config->difficulty = $question->difficulty;
$xmlQuestion->config->content_url = $question->content_url;
$xmlQuestion->config->display_order = $question->display_order;
}
$xmlQuestion->feedbacks->general = exagames_html_to_text($question->generalfeedback);
if ($question->get_type_name() == 'multichoice') {
$xmlQuestion->setAttributes(array(
'single' => (int) ($question instanceof qtype_multichoice_single_question)
));
$answers = $xmlQuestion->addChild('answers');
foreach ($question->answers as $answer) {
$xmlAnswer = $answers->addChild('answer')->setAttributes(array('id'=>$answer->id, 'fraction'=>$answer->fraction));
$xmlAnswer->text = exagames_html_to_text($answer->answer);
$xmlAnswer->feedback = exagames_html_to_text($answer->feedback);
}
$xmlQuestion->feedbacks->correct = exagames_html_to_text($question->correctfeedback);
$xmlQuestion->feedbacks->partiallycorrect = exagames_html_to_text($question->partiallycorrectfeedback);
$xmlQuestion->feedbacks->incorrect = exagames_html_to_text($question->incorrectfeedback);
} elseif ($question->get_type_name() == 'truefalse') {
$xmlQuestion->setAttributes(array(
'correctanswer' => (int) $question->rightanswer
));
$xmlQuestion->feedbacks->truefeedback = exagames_html_to_text($question->truefeedback);
$xmlQuestion->feedbacks->falsefeedback = exagames_html_to_text($question->falsefeedback);
} else {
print_error("Questiontype is not supported! Please use truefalse, or multichoice!");
}
}
header('Content-Type: text/xml; charset=utf-8');
echo $xmlQuiz->asXML();
exit;
}
}
$context = context_module::instance($cm->id);
/*if (has_capability('moodle/course:manageactivities', $context) && ($action == 'configure_questions') && ($questionId = optional_param('questionid', '', PARAM_INT)) && isset($quiz->questions[$questionId]) && ($content_url = optional_param('content_url', '', PARAM_TEXT))) {
$questionConfig = new stdClass();
$questionConfig->id = $questionId;
$questionConfig->content_url = $content_url;
$questionConfig->tile_size = optional_param('tile_size', '', PARAM_TEXT);
$questionConfig->difficulty = optional_param('difficulty', '', PARAM_TEXT);
$questionConfig->display_order = optional_param('display_order', '', PARAM_TEXT);
if (!$DB->record_exists('exagames_question', array('id'=>$questionId))) {
$DB->Execute("INSERT INTO {$CFG->prefix}exagames_question (id, tile_size, content_url, difficulty, display_order) VALUES ({$questionConfig->id}, '', '', '', '')");
}
$DB->update_record('exagames_question', $questionConfig);
echo "ok=1";
exit;
}*/
/// Print the page header
$strexagamess = get_string("modulenameplural", "exagames");
$strexagames = get_string("modulename", "exagames");
$navlinks = array();
$navlinks[] = array('name' => $strexagamess, 'link' => "index.php?id=$course->id", 'type' => 'activity');
$navlinks[] = array('name' => format_string($game->name), 'link' => '', 'type' => 'activityinstance');
//$navigation = build_navigation($navlinks);
$partUrl = explode("/", $_SERVER['PHP_SELF'], 2);
$pos = strpos($partUrl[1], "/");
$url = new moodle_url(substr($partUrl[1], $pos), array('id'=>$id));
$PAGE->set_url($url);
$PAGE->requires->js('/mod/exagames/js/swfobject.js', true);
$stringman = get_string_manager();
$strings = $stringman->load_component_strings('mod_exagames', 'en');
$PAGE->requires->strings_for_js(array_keys($strings), 'mod_exagames');
echo $OUTPUT->header();
//$context = get_context_instance(CONTEXT_COURSE, $game->course);
$context = context_module::instance($cm->id);
/*
if (has_capability('moodle/course:manageactivities', $context) && $action == 'configure_question_file') {
$questionId = optional_param('questionid', '', PARAM_INT);
if (!isset($quiz->questions[$questionId])) {
print_error('wrong question');
}
$question = $quiz->questions[$questionId];
require_once($CFG->dirroot.'/lib/formslib.php');
class configure_question_file_form extends moodleform {
// Define the form
function definition () {
global $CFG, $COURSE;
$mform =& $this->_form;
/// Print the required moodle fields first
$mform->addElement('filemanager', 'file', 'File', null, array('maxfiles' => 1));
$this->add_action_buttons();
}
}
$questionform = new configure_question_file_form($_SERVER['REQUEST_URI'], null);
$draftitemid = file_get_submitted_draft_itemid('file');
file_prepare_draft_area($draftitemid, $context->id, 'mod_exagames', 'questions', $question->id);
$question->file = $draftitemid;
if ($questionform->is_cancelled()) {
if ($question->content_url)
redirect(new moodle_url('/mod/exagames/view.php?action=configure_questions&id='.$id.'&questionid='.$question->id));
else
redirect(new moodle_url('/mod/exagames/view.php?action=configure_questions&id='.$id));
} else if ($formdata = $questionform->get_data()) {
var_dump($formdata);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
file_save_draft_area_files($formdata->file, $context->id, 'mod_exagames', 'questions', $question->id);
$fs = get_file_storage();
$file = $fs->get_area_files($context->id, 'mod_exagames', 'questions', $question->id);
$file = reset($file);
$path = '/'.$file->get_contextid().'/mod_exagames/questions/'.$file->get_filepath().$file->get_filename();
$fullurl = file_encode_url($CFG->wwwroot.'/pluginfile.php', $path, false);
echo $fullurl;
var_dump($file);
exit;
} else {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$fs = get_file_storage();
$file = $fs->get_area_files($context->id, 'mod_exagames', 'questions', $question->id);
$file = reset($file);
if ($file) {
var_dump($file->get_filesize());
var_dump(get_class_methods($file));
var_dump($file);
$path = '/'.$file->get_contextid().'/mod_exagames/file/'.$file->get_filepath().$file->get_filename();
var_dump($path);
$fullurl = file_encode_url($CFG->wwwroot.'/pluginfile.php', $path, false);
echo $fullurl;
}
$questionform->set_data($question);
print_header_simple(format_string($game->name), "", $navigation, "", "", true,
update_module_button($cm->id, $course->id, $strexagames), navmenu($course, $cm));
exagames_print_tabs($game, 'configure_questions');
$questionform->display();
/// Finish the page
echo $OUTPUT->footer();
}
exit;
}
*/
//print_header_simple(format_string($game->name), "", $navigation, "", "", true,
// update_module_button($cm->id, $course->id, $strexagames), navmenu($course, $cm));
//$moduleId = $DB->get_field('modules', 'id', array('name'=>'exagames'));
//$courseContextId = context_course::instance($COURSE->id)->id;
//$result = $DB->get_records('folder', array('course'=> $COURSE->id));
//echo "SELECT * FROM mdl_files f JOIN mdl_context ctx ON f.contextid = ctx.id having f.contextid IN ($ids)";
//$fs = get_file_storage();
/*$files = $fs->get_area_files(, 'mod_folder', 'content');
//var_dump($files);
foreach ($files as $f) {
// $f is an instance of stored_file
$fName = $f->get_filename();
if(substr($fName, -3) == 'jpg' || substr($fName, -3) == 'png' || substr($fName, -3) == 'gif')
}*/
/*
if (has_capability('moodle/course:manageactivities', $context) && $action == 'configure_questions') {
exagames_print_tabs($game, 'configure_questions');
$questionId = optional_param('questionid', '', PARAM_INT);
if (isset($quiz->questions[$questionId])) {
$question = $quiz->questions[$questionId];
$flashvars = array(
'save_url' => $_SERVER['REQUEST_URI'],
'back_url' => $_SERVER['PHP_SELF'].'?action=configure_questions&id='.$cm->id,
'content_url' => $question->content_url,
'tile_size' => $question->tile_size,
'difficulty' => $question->difficulty,
'display_order' => $question->display_order,
'selectable_images' => $img_files
);
?>
<script src="html5/js/jquery.min.js"></script>
<script type="text/javascript">
var flashvars = <?php echo json_encode($flashvars) ?>;
var params = {};
var attributes = {};
//swfobject.embedSWF(<?php echo json_encode($CFG->wwwroot.'/mod/exagames/swf/tiles_editor.swf'); ?>, "GameContent", "940", "535", "9.0.0", false, flashvars, params, attributes);
$(document).ready(function(){
$( "#GameContent" ).empty();
//$( "#GameContent" ).append('<iframe height="900" width= "1200" src="./html5/tiles_editor/tiles.html">Could not load iframe</iframe>');
$( "#GameContent" ).load('./html5/tiles_editor/tiles.html');
});
</script>
<div id="Game" style="width: 940px; margin: 0 auto;">
<div id="GameContent" style="width: 940px; margin: 0 auto;">
<a href="http://www.adobe.com/go/getflashplayer" style="display: block; padding: 40px; text-align: center;">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
</div>
</div>
<?php
} else {
// list questions
echo '<table border="0" align="center" cellspacing="0" cellpadding="2">';
echo '<b>'.get_string('questions', 'quiz').':</b><br />';
foreach ($quiz->questions as $question) {
echo '<tr><td>';
echo '<a href="'.$CFG->wwwroot.'/mod/exagames/view.php?action=configure_questions&id='.$cm->id.'&questionid='.$question->id.'">'.$question->name.'</a><br />';
echo '</td><td>';
echo get_string($question->content_url?'question_configured':'question_not_configured', 'exagames');
echo '</td></tr>';
}
echo '</table>';
}
/// Finish the page
echo $OUTPUT->footer();
exit;
}
*/
/*
$globalTopScore = get_field_sql("SELECT MAX(score) FROM {$CFG->prefix}exagames_scores WHERE score>0 AND gameid='".$game->id."' AND gametype='".$game->gametype."'");
$myBestScore = get_field_sql("SELECT MAX(score) AS score FROM {$CFG->prefix}exagames_scores WHERE score>0 AND gameid='".$game->id."' AND gametype='".$game->gametype."' AND userid=".$USER->id);
*/
exagames_print_tabs($game, 'show');
/// Print the main part of the page
if($game->gametype != 'gamelabs') {
$partUrl = explode("/", $_SERVER['PHP_SELF'], 2);
$pos = strpos($partUrl[1], "/");
$url = new moodle_url(substr($partUrl[1], $pos), array('id'=>$id));
$flashvars = array(
'gameurl' => $CFG->wwwroot.'/mod/exagames/view.php?id='.$id,
'gamedataurl' => $CFG->wwwroot.'/mod/exagames/view.php?id='.$cm->id.'&action=data&rand='.time(),
'courseurl' => $CFG->wwwroot.'/course/view.php?id='.$course->id,
'translationsurl' => $CFG->wwwroot.'/mod/exagames/view.php?id='.$cm->id.'&action=translations'
);
$gametype = $game->gametype;
?>
<!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>-->
<script src="html5/js/jquery.min.js"></script>
<script src="html5/js/phaser.js"></script>
<script type="text/javascript">
var flashvars = <?php echo json_encode($flashvars) ?>;
var gameType = <?php echo json_encode($gametype) ?>;
//var flashvars = <?php echo json_encode(array_map('urlencode', $flashvars)) ?>;
var params = {};
var attributes = {};
//swfobject.embedSWF(<?php echo json_encode($game->swf); ?>, "GameContent", <?php echo $game->width; ?>, <?php echo $game->height; ?>, "9.0.0", false, flashvars, params, attributes);
if(gameType == 'braingame') {
$(document).ready(function(){
$( "#GameContent" ).empty();
$( "#GameContent" ).load('./html5/braingame/braingame.html');
});
} else if (gameType == 'tiles') {
$(document).ready(function(){
$( "#GameContent" ).empty();
$( "#GameContent" ).load('./html5/blurrygame/blurrygame.html');
});
}
</script>
<div id="Game" style="width: 1200px; margin: 0 auto;">
<div id="GameContent" style="width: 1200px; margin: 0 auto;">
<a href="http://www.adobe.com/go/getflashplayer" style="display: block; padding: 40px; text-align: center;">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
</div>
</div>
<?php
}
// Gameslab.at Frame einbinden
else {
/*
$gameslab = file_get_contents($game->url);
$pos1 = strpos($gameslab,'<div id="Adventure_Player" class="Adventure_Player">');
$pos2 = strpos($gameslab,'so.write("Adventure_Player");
</script>
</div>');
$aplay_pos = strpos($gameslab,'Adventure_Player');
$jsbegin = strpos($gameslab,'<script type="text/javascript">',$aplay_pos);
$jsend = strpos($gameslab,'</script>',$jsbegin) + strlen('</script>');
echo '<script type="text/javascript" src="http://gamelabs.at/fileadmin/gamelabs/tmpl/js/swfobject.js"></script>';
echo '<div id="Adventure_Player" class="Adventure_Player"></div>';
$flashcontent = substr($gameslab,$jsbegin,$jsend-$jsbegin);
$flashcontent = str_replace('new SWFObject("fileadmin/', 'new SWFObject("http://gamelabs.at/fileadmin/', $flashcontent);
//$flashcontent = str_replace('fileadmin/', 'http://gamelabs.at/fileadmin/', $flashcontent);
echo $flashcontent;
*/
echo '
<iframe src="'.$game->url.'&type=5" width="740" height="520" name="gamelabs.at">
<p>iframe is not working</p>
</iframe>';
}
$sql = "SELECT s.id, s.score, u.firstname, u.lastname ".
"FROM {exagames_scores} s JOIN {user} u ON u.id=s.userid ".
"WHERE score>0 AND gameid='".$game->id."' AND gametype='".$game->gametype."' ORDER BY score DESC LIMIT 0,5";
$res = $DB->get_records_sql($sql);
if ($res):
?>
<div style="text-align: center; font-size: 18px;margin-top:15px;">
5 Top Scores:
</div>
<div style="text-align: center;margin:10px 0;">
<table "align=center" style="margin: 0 auto;">
<?php
foreach ($res as $rs) {
echo "<tr><td align=left style='padding-right:15px;'>".$rs->firstname." ".$rs->lastname."</td><td align=right>".$rs->score."</td></tr>";
}
?>
</table>
</div>
<?php
endif;
/// Finish the page
echo $OUTPUT->footer();