-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfreeplayview.php
226 lines (210 loc) · 7.39 KB
/
freeplayview.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
<?php
/**
* This view allows free playing with a deck
*
* @package mod-flashcard
* @category mod
* @author Gustav Delius
* @contributors Valery Fremaux
*/
// Security
if (!defined('MOODLE_INTERNAL')) {
error("Illegal direct access to this screen");
}
echo $out;
$subquestions = $DB->get_records('flashcard_deckdata', array('flashcardid' => $flashcard->id));
if (empty($subquestions)) {
notice(get_string('nosubquestions', 'flashcard'));
return;
}
$subquestions = draw_rand_array($subquestions, count($subquestions));
?>
<script language="javascript">
//<![CDATA[
currentitem = 0;
maxitems = <?php echo count($subquestions); ?>;
remaining = maxitems;
var qtype = "<?php echo $flashcard->questionsmediatype ?>";
var atype = "<?php echo $flashcard->answersmediatype ?>";
var cards = new Array(maxitems);
for(i = 0 ; i < maxitems ; i++){
cards[i] = true;
}
function clicked(type, item){
document.getElementById(type + item).style.display = "none";
if (type == 'f'){
oldtype = 'b';
}
else{
oldtype = 'f';
}
document.getElementById(oldtype + item).style.display = "block";
if (type == 'f'){
if (atype > 2){
alert('item ' + item);
qtobj = document.getElementById('bell_b' + item);
qtobj.SetControllerVisible(true);
}
}
if (type == 'b'){
if (qtype > 2){
qtobj = document.getElementById('bell_f' + item);
qtobj.SetControllerVisible(true);
}
}
}
function next() {
document.getElementById('f' + currentitem).style.display = "none";
document.getElementById('b' + currentitem).style.display = "none";
do {
currentitem++;
if (currentitem >= maxitems) currentitem = 0;
}
while (cards[currentitem] != true){
document.getElementById('f' + currentitem).style.display = "block";
qtobj = document.getElementById('bell_f' + currentitem);
qtobj.SetControllerVisible(true);
}
}
function previous() {
document.getElementById('f' + currentitem).style.display = "none";
document.getElementById('b' + currentitem).style.display = "none";
do {
currentitem--;
if(currentitem < 0) currentitem = maxitems - 1;
}
while (cards[currentitem] != true){
document.getElementById('f' + currentitem).style.display = "block";
qtobj = document.getElementById('bell_f' + currentitem);
qtobj.SetControllerVisible(true);
}
}
function disable(){
remaining--;
document.getElementById('remain').innerHTML = remaining;
if (remaining == 0){
document.getElementById('f' + currentitem).style.display = "none";
document.getElementById('b' + currentitem).style.display = "none";
document.getElementById('finished').style.display = "block";
document.getElementById('next').disabled = true;
document.getElementById('previous').disabled = true;
document.getElementById('remove').disabled = true;
}
else{
cards[currentitem] = false;
next();
}
}
//]]>
</script>
<p>
<?php print_string('freeplayinstructions',
'flashcard');
?>.
</p>
<table class="flashcard_board" width="100%">
<tr>
<td rowspan="6">
<?php
$i = 0;
if ($flashcard->flipdeck) {
// flip media types once
$tmp = $flashcard->answersmediatype;
$flashcard->answersmediatype = $flashcard->questionsmediatype;
$flashcard->questionsmediatype = $tmp;
}
foreach ($subquestions as $subquestion) {
echo '<center>';
$divid = "f$i";
$divstyle = ($i > 0) ? 'display:none' : '';
echo "<div id=\"{$divid}\" style=\"{$divstyle}\" class=\"frontside card\"";
echo " onclick=\"javascript:clicked('f', '{$i}')\">";
echo "<div class=\"cardcaption\"></div>";
echo "<div class=\"cardcontent\">";
if ($flashcard->flipdeck) {
// flip card side values
$tmp = $subquestion->answertext;
$subquestion->answertext = $subquestion->questiontext;
$subquestion->questiontext = $tmp;
}
$questiontext = file_rewrite_pluginfile_urls($subquestion->questiontext, 'pluginfile.php',
$context->id, 'mod_flashcard', 'question', $subquestion->id);
$options = new stdClass();
$options->noclean = true;
$options->overflowdiv = true;
echo format_text($questiontext, FORMAT_HTML);
?>
</div>
</div>
</center>
<center>
<?php
echo "<div id=\"b{$i}\" style=\"display: none\" class=\"backside card\"";
echo " onclick=\"javascript:clicked('b', '{$i}')\">";
echo "<div class=\"cardcaption\"></div>";
echo "<div class=\"cardcontent\">";
$answertext = file_rewrite_pluginfile_urls($subquestion->answertext, 'pluginfile.php',
$context->id, 'mod_flashcard', 'answer', $subquestion->id);
$options = new stdClass();
$options->noclean = true;
$options->overflowdiv = true;
echo format_text($answertext, FORMAT_HTML);
?>
</div>
</div>
</center>
<?php
$i++;
}
?>
<center>
<div id="finished" style="display: none;">
<?php echo "<img src=\"{$CFG->wwwroot}/mod/flashcard/pix/emptydeck.png\"/>"; ?>
<p><b><?php print_string('emptyset', 'flashcard')?></b><p>
</div>
</center>
</td>
</tr>
<tr>
<td width="200px">
<p><?php print_string('cardsremaining',
'flashcard');
?>: <span id="remain"><?php echo count($subquestions); ?></span></p>
</td>
</tr>
<tr>
<td width="200px">
<input id="next" type="button" value="<?php print_string('next',
'flashcard')
?>" onclick="javascript:next()" />
</td>
</tr>
<tr>
<td width="200px">
<input id="previous" type="button" value="<?php print_string('previous',
'flashcard')
?>" onclick="javascript:previous()" />
</td>
</tr>
<tr>
<td width="200px">
<input id="remove" type="button" value="<?php print_string('removecard',
'flashcard')
?>" onclick="javascript:disable()" />
</td>
</tr>
<tr>
<td width="200px">
<input type="button" value="<?php print_string('reset',
'flashcard')
?>" onclick="javascript:location.reload()" />
</td>
</tr>
<tr>
<td width="200px" align="center" colspan="2">
<br/><a href="<?php echo $CFG->wwwroot ?>/course/view.php?id=<?php echo $course->id ?>"><?php print_string('backtocourse',
'flashcard')
?></a>
</td>
</tr>
</table>