mirrored from git://git.moodle.org/moodle.git
/
edit.php
290 lines (266 loc) · 16 KB
/
edit.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
<?php // $Id$
/**
* Provides the interface for overall authoring of lessons
*
* @version $Id$
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package lesson
**/
require_once('../../config.php');
require_once('locallib.php');
require_once('lib.php');
$id = required_param('id', PARAM_INT); // Course Module ID
$display = optional_param('display', 0, PARAM_INT);
$mode = optional_param('mode', get_user_preferences('lesson_view', 'collapsed'), PARAM_ALPHA);
$pageid = optional_param('pageid', 0, PARAM_INT);
if ($mode != 'single') {
set_user_preference('lesson_view', $mode);
}
list($cm, $course, $lesson) = lesson_get_basics($id);
if ($firstpage = get_record('lesson_pages', 'lessonid', $lesson->id, 'prevpageid', 0)) {
if (!$pages = get_records('lesson_pages', 'lessonid', $lesson->id)) {
error('Could not find lesson pages');
}
}
if ($pageid) {
if (!$singlepage = get_record('lesson_pages', 'id', $pageid)) {
error('Could not find page ID: '.$pageid);
}
}
require_login($course->id, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/lesson:manage', $context);
lesson_print_header($cm, $course, $lesson, $mode);
if (empty($firstpage)) {
// There are no pages; give teacher some options
if (has_capability('mod/lesson:edit', $context)) {
print_simple_box( "<table cellpadding=\"5\" border=\"0\">\n<tr><th scope=\"col\">".get_string("whatdofirst", "lesson")."</th></tr><tr><td>".
"<a href=\"import.php?id=$cm->id&pageid=0\">".
get_string("importquestions", "lesson")."</a></td></tr><tr><td>".
"<a href=\"importppt.php?id=$cm->id&pageid=0\">".
get_string("importppt", "lesson")."</a></td></tr><tr><td>".
"<a href=\"lesson.php?id=$cm->id&action=addbranchtable&pageid=0&firstpage=1\">".
get_string("addabranchtable", "lesson")."</a></td></tr><tr><td>".
"<a href=\"lesson.php?id=$cm->id&action=addpage&pageid=0&firstpage=1\">".
get_string("addaquestionpage", "lesson").
"</a></td></tr></table>\n", 'center');
}
} else {
// Set some standard variables
$pageid = $firstpage->id;
$prevpageid = 0;
$npages = count($pages);
switch ($mode) {
case 'collapsed':
$table = new stdClass;
$table->head = array(get_string('pagetitle', 'lesson'), get_string('qtype', 'lesson'), get_string('jumps', 'lesson'), get_string('actions', 'lesson'));
$table->align = array('left', 'left', 'left', 'center');
$table->wrap = array('', 'nowrap', '', 'nowrap');
$table->tablealign = 'center';
$table->cellspacing = 0;
$table->cellpadding = '2px';
$table->data = array();
while ($pageid != 0) {
$page = $pages[$pageid];
$jumps = array();
if($answers = get_records_select("lesson_answers", "lessonid = $lesson->id and pageid = $pageid")) {
foreach ($answers as $answer) {
$jumps[] = lesson_get_jump_name($answer->jumpto);
}
}
$table->data[] = array("<a href=\"$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id&mode=single&pageid=".$page->id."\">".format_string($pages[$pageid]->title,true).'</a>',
lesson_get_qtype_name($page->qtype),
implode("<br />\n", $jumps),
lesson_print_page_actions($cm->id, $page, $npages, true, true)
);
$pageid = $page->nextpageid;
}
print_table($table);
break;
case 'single':
// Only viewing a single page in full - change some variables to display just one
$prevpageid = $singlepage->prevpageid;
$pageid = $singlepage->id;
$pages = array();
$pages[$singlepage->id] = $singlepage;
case 'full':
echo '<table align="center" cellpadding="5" border="0" width="80%">
<tr>
<td align="left">';
lesson_print_add_links($cm->id, $prevpageid);
echo ' </td>
</tr>';
while ($pageid != 0) {
$page = $pages[$pageid];
echo "<tr><td>\n";
echo "<table width=\"100%\" border=\"1\" class=\"generalbox\"><tr><th colspan=\"2\" scope=\"col\">".format_string($page->title)." \n";
lesson_print_page_actions($cm->id, $page, $npages);
echo "</th></tr>\n";
echo "<tr><td colspan=\"2\">\n";
$options = new stdClass;
$options->noclean = true;
echo format_text($page->contents, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
// get the answers in a set order, the id order
if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) {
echo "<tr><td colspan=\"2\" align=\"center\"><b>\n";
echo lesson_get_qtype_name($page->qtype);
switch ($page->qtype) {
case LESSON_SHORTANSWER :
if ($page->qoption) {
echo " - ".get_string("casesensitive", "lesson");
}
break;
case LESSON_MULTICHOICE :
if ($page->qoption) {
echo " - ".get_string("multianswer", "lesson");
}
break;
case LESSON_MATCHING :
echo get_string("firstanswershould", "lesson");
break;
}
echo "</b></td></tr>\n";
$i = 1;
$n = 0;
$options = new stdClass;
$options->noclean = true;
$options->para = false;
foreach ($answers as $answer) {
switch ($page->qtype) {
case LESSON_MULTICHOICE:
case LESSON_TRUEFALSE:
case LESSON_SHORTANSWER:
case LESSON_NUMERICAL:
echo "<tr><td align=\"right\" valign=\"top\" width=\"20%\">\n";
if ($lesson->custom) {
// if the score is > 0, then it is correct
if ($answer->score > 0) {
echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
} else {
echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
}
} else {
if (lesson_iscorrect($page->id, $answer->jumpto)) {
// underline correct answers
echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
} else {
echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
}
}
echo "</td><td width=\"80%\">\n";
echo format_text($answer->answer, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
echo "<tr><td align=\"right\" valign=\"top\"><b>".get_string("response", "lesson")." $i:</b> \n";
echo "</td><td>\n";
echo format_text($answer->response, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
break;
case LESSON_MATCHING:
if ($n < 2) {
if ($answer->answer != NULL) {
if ($n == 0) {
echo "<tr><td align=\"right\" valign=\"top\"><b>".get_string("correctresponse", "lesson").":</b> \n";
echo "</td><td>\n";
echo format_text($answer->answer, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
} else {
echo "<tr><td align=\"right\" valign=\"top\"><b>".get_string("wrongresponse", "lesson").":</b> \n";
echo "</td><td>\n";
echo format_text($answer->answer, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
}
}
$n++;
$i--;
} else {
echo "<tr><td align=\"right\" valign=\"top\" width=\"20%\">\n";
if ($lesson->custom) {
// if the score is > 0, then it is correct
if ($answer->score > 0) {
echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
} else {
echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
}
} else {
if (lesson_iscorrect($page->id, $answer->jumpto)) {
// underline correct answers
echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
} else {
echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
}
}
echo "</td><td width=\"80%\">\n";
echo format_text($answer->answer, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
echo "<tr><td align=\"right\" valign=\"top\"><b>".get_string("matchesanswer", "lesson")." $i:</b> \n";
echo "</td><td>\n";
echo format_text($answer->response, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
}
break;
case LESSON_BRANCHTABLE:
echo "<tr><td align=\"right\" valign=\"top\" width=\"20%\">\n";
echo "<b>".get_string("description", "lesson")." $i:</b> \n";
echo "</td><td width=\"80%\">\n";
echo format_text($answer->answer, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
break;
}
$jumptitle = lesson_get_jump_name($answer->jumpto);
if ($page->qtype == LESSON_MATCHING) {
if ($i == 1) {
echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("correctanswerscore", "lesson").":";
echo "</b></td><td width=\"80%\">\n";
echo "$answer->score</td></tr>\n";
echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("correctanswerjump", "lesson").":";
echo "</b></td><td width=\"80%\">\n";
echo "$jumptitle</td></tr>\n";
} elseif ($i == 2) {
echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("wronganswerscore", "lesson").":";
echo "</b></td><td width=\"80%\">\n";
echo "$answer->score</td></tr>\n";
echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("wronganswerjump", "lesson").":";
echo "</b></td><td width=\"80%\">\n";
echo "$jumptitle</td></tr>\n";
}
} else {
if ($lesson->custom and
$page->qtype != LESSON_BRANCHTABLE and
$page->qtype != LESSON_ENDOFBRANCH and
$page->qtype != LESSON_CLUSTER and
$page->qtype != LESSON_ENDOFCLUSTER) {
echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("score", "lesson")." $i:";
echo "</b></td><td width=\"80%\">\n";
echo "$answer->score</td></tr>\n";
}
echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("jump", "lesson")." $i:";
echo "</b></td><td width=\"80%\">\n";
echo "$jumptitle</td></tr>\n";
}
$i++;
}
}
echo "</table></td></tr>\n<tr><td align=\"left\">";
lesson_print_add_links($cm->id, $page->id);
echo "<tr><td>\n";
// check the prev links - fix (silently) if necessary - there was a bug in
// versions 1 and 2 when add new pages. Not serious then as the backwards
// links were not used in those versions
if ($page->prevpageid != $prevpageid) {
// fix it
set_field("lesson_pages", "prevpageid", $prevpageid, "id", $page->id);
debugging("<p>***prevpageid of page $page->id set to $prevpageid***");
}
if (count($pages) == 1) {
break;
}
$prevpageid = $page->id;
$pageid = $page->nextpageid;
}
echo "</table>";
break;
}
}
print_footer($course);
?>