3 * Action for editing a page. Prints an HTML form.
6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
11 $pageid = required_param('pageid', PARAM_INT
);
12 $redirect = optional_param('redirect', '', PARAM_ALPHA
);
14 if (!$page = get_record("lesson_pages", "id", $pageid)) {
15 error("Edit page: page record not found");
18 $page->qtype
= optional_param('qtype', $page->qtype
, PARAM_INT
);
22 $jump[0] = get_string("thispage", "lesson");
23 $jump[LESSON_NEXTPAGE
] = get_string("nextpage", "lesson");
24 $jump[LESSON_PREVIOUSPAGE
] = get_string("previouspage", "lesson");
25 if(lesson_display_branch_jumps($lesson->id
, $page->id
)) {
26 $jump[LESSON_UNSEENBRANCHPAGE
] = get_string("unseenpageinbranch", "lesson");
27 $jump[LESSON_RANDOMPAGE
] = get_string("randompageinbranch", "lesson");
29 if ($page->qtype
== LESSON_ENDOFBRANCH ||
$page->qtype
== LESSON_BRANCHTABLE
) {
30 $jump[LESSON_RANDOMBRANCH
] = get_string("randombranch", "lesson");
32 if(lesson_display_cluster_jump($lesson->id
, $page->id
) && $page->qtype
!= LESSON_BRANCHTABLE
&& $page->qtype
!= LESSON_ENDOFCLUSTER
) {
33 $jump[LESSON_CLUSTERJUMP
] = get_string("clusterjump", "lesson");
35 $jump[LESSON_EOL
] = get_string("endoflesson", "lesson");
36 if (!$apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id
, "prevpageid", 0)) {
37 error("Edit page: first page not found");
41 if (!$apage = get_record("lesson_pages", "id", $apageid)) {
42 error("Edit page: apage record not found");
44 // removed != LESSON_ENDOFBRANCH...
45 if (trim($page->title
)) { // ...nor nuffin pages
46 $jump[$apageid] = strip_tags(format_string($apage->title
,true));
48 $apageid = $apage->nextpageid
;
54 // give teacher a proforma
56 <form id
="editpage" method
="post" action
="lesson.php">
57 <fieldset
class="invisiblefieldset fieldsetfix">
58 <input type
="hidden" name
="id" value
="<?php echo $cm->id ?>" />
59 <input type
="hidden" name
="action" value
="updatepage" />
60 <input type
="hidden" name
="pageid" value
="<?php echo $pageid ?>" />
61 <input type
="hidden" name
="sesskey" value
="<?php echo $USER->sesskey ?>" />
62 <input type
="hidden" name
="redirect" value
="<?php echo $redirect ?>" />
63 <input type
="hidden" name
="redisplay" value
="0" />
66 switch ($page->qtype
) {
67 case LESSON_MULTICHOICE
:
68 echo '<b>'.get_string("questiontype", "lesson").":</b> \n";
69 echo helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson")."<br />";
70 lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype
,
71 "lesson.php?id=$cm->id&action=editpage&pageid=$page->id",
72 "getElementById('editpage').redisplay.value=1;getElementById('editpage').submit();");
73 echo "<p><b><label for=\"qoption\">".get_string('multianswer', 'lesson').":</label></b> \n";
75 echo "<input type=\"checkbox\" id=\"qoption\" name=\"qoption\" value=\"1\" checked=\"checked\" />";
77 echo "<input type=\"checkbox\" id=\"qoption\" name=\"qoption\" value=\"1\" />";
79 helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson");
82 case LESSON_SHORTANSWER
:
83 echo '<b>'.get_string("questiontype", "lesson").":</b> \n";
84 echo helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson")."<br />";
85 lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype
,
86 "lesson.php?id=$cm->id&action=editpage&pageid=$page->id",
87 "getElementById('editpage').redisplay.value=1;getElementById('editpage').submit();");
88 echo "<p><b><label for=\"qoption\">".get_string('casesensitive', 'lesson').":</label></b> \n";
90 echo "<input type=\"checkbox\" id=\"qoption\" name=\"qoption\" value=\"1\" checked=\"checked\" />";
92 echo "<input type=\"checkbox\" id=\"qoption\" name=\"qoption\" value=\"1\" />";
94 helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson");
97 case LESSON_TRUEFALSE
:
99 case LESSON_MATCHING
:
100 case LESSON_NUMERICAL
:
101 echo '<b>'.get_string("questiontype", "lesson").":</b> \n";
102 echo helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson")."<br />";
103 lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype
,
104 "lesson.php?id=$cm->id&action=editpage&pageid=$page->id",
105 "getElementById('editpage').redisplay.value=1;getElementById('editpage').submit();");
109 <table cellpadding
="5" class="generalbox" border
="1">
111 <td
><b
><label
for="title"><?php
print_string('pagetitle', 'lesson'); ?
>:</label
></b
><br
/>
112 <input type
="text" id
="title" name
="title" size
="80" maxsize
="255" value
="<?php p($page->title) ?>" /></td
>
116 echo get_string("pagecontents", "lesson").":</b><br />\n";
117 print_textarea($usehtmleditor, 25, 70, 630, 400, "contents", $page->contents
);
118 if ($usehtmleditor) {
119 use_html_editor("contents");
123 switch ($page->qtype
) {
124 case LESSON_BRANCHTABLE
:
125 echo "<input type=\"hidden\" name=\"qtype\" value=\"$page->qtype\" />\n";
129 echo "<input checked=\"checked\" name=\"layout\" type=\"checkbox\" value=\"1\" />";
131 echo "<input name=\"layout\" type=\"checkbox\" value=\"1\" />";
133 echo get_string("arrangebuttonshorizontally", "lesson")."\n";
135 if ($page->display
) {
136 echo "<input name=\"display\" type=\"checkbox\" value=\"1\" checked=\"checked\" />";
138 echo "<input name=\"display\" type=\"checkbox\" value=\"1\" />";
140 echo get_string("displayinleftmenu", "lesson")."\n";
141 echo "</center></td></tr>\n";
142 echo "<tr><td><b>".get_string("branchtable", "lesson")."</b> \n";
144 case LESSON_CLUSTER
:
145 echo "<input type=\"hidden\" name=\"qtype\" value=\"$page->qtype\" />\n";
146 echo "<tr><td><b>".get_string("clustertitle", "lesson")."</b> \n";
148 case LESSON_ENDOFCLUSTER
:
149 echo "<input type=\"hidden\" name=\"qtype\" value=\"$page->qtype\" />\n";
150 echo "<tr><td><b>".get_string("endofclustertitle", "lesson")."</b> \n";
152 case LESSON_ENDOFBRANCH
:
153 echo "<input type=\"hidden\" name=\"qtype\" value=\"$page->qtype\" />\n";
154 echo "<tr><td><b>".get_string("endofbranch", "lesson")."</b> \n";
162 // get the answers in a set order, the id order
164 if ($answers = get_records("lesson_answers", "pageid", $page->id
, "id")) {
165 foreach ($answers as $answer) {
166 $flags = intval($answer->flags
); // force into an integer
168 echo "<input type=\"hidden\" name=\"answerid[$n]\" value=\"$answer->id\" />\n";
169 switch ($page->qtype
) {
170 case LESSON_MATCHING
:
172 echo "<tr><td><b><label for=\"edit-answer[$n]\">".get_string('correctresponse', 'lesson').":</label></b>\n";
173 if ($flags & LESSON_ANSWER_EDITOR
) {
174 echo " [<label for=\"answereditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
175 "<input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" checked=\"checked\" />";
176 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
178 print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer
);
179 use_html_editor("answer[$n]"); // switch on the editor
181 echo " [<label for=\"answereditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
182 "<input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" />";
183 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
185 print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer
);
188 echo "<tr><td><b><label for=\"edit-answer[$n]\">".get_string('wrongresponse', 'lesson').":</label></b>\n";
189 if ($flags & LESSON_ANSWER_EDITOR
) {
190 echo " [<label for=\"answereditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
191 "<input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" checked=\"checked\" />";
192 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
194 print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer
);
195 use_html_editor("answer[$n]"); // switch on the editor
197 echo " [<label for=\"answereditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
198 "<input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" />";
199 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
201 print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer
);
204 $ncorrected = $n - 1;
205 echo "<tr><td><b><label for=\"edit-answer[$n]\">".get_string('answer', 'lesson')." $ncorrected:</label></b>\n";
206 if ($flags & LESSON_ANSWER_EDITOR
) {
207 echo " [<label for=\"answereditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
208 "<input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" checked=\"checked\" />";
209 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
211 print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer
);
212 use_html_editor("answer[$n]"); // switch on the editor
214 echo " [<label for=\"answereditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
215 "<input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" />";
216 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
218 print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer
);
221 echo "<tr><td><b><label for=\"edit-response[$n]\">".get_string('matchesanswer', 'lesson')." $ncorrected:</label></b>\n";
222 if ($flags & LESSON_RESPONSE_EDITOR
) {
223 echo " [<label for=\"responseeditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
224 "<input type=\"checkbox\" id=\"responseeditor[$n]\" name=\"responseeditor[$n]\" value=\"1\" checked=\"checked\" />";
225 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
227 print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$n]", $answer->response
);
228 use_html_editor("response[$n]"); // switch on the editor
230 echo " [<label for=\"responseeditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
231 "<input type=\"checkbox\" id=\"responseeditor[$n]\" name=\"responseeditor[$n]\" value=\"1\" />";
232 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
234 print_textarea(false, 6, 70, 630, 300, "response[$n]", $answer->response
);
239 case LESSON_TRUEFALSE
:
240 case LESSON_MULTICHOICE
:
241 case LESSON_SHORTANSWER
:
242 case LESSON_NUMERICAL
:
243 echo "<tr><td><b><label for=\"edit-answer[$n]\">".get_string('answer', 'lesson')." $nplus1:</label></b>\n";
244 if ($flags & LESSON_ANSWER_EDITOR
and $page->qtype
!= LESSON_SHORTANSWER
and $page->qtype
!= LESSON_NUMERICAL
) {
245 echo " [<label for=\"answereditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
246 "<input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" checked=\"checked\" />";
247 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
249 print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer
);
250 use_html_editor("answer[$n]"); // switch on the editor
252 if ($page->qtype
!= LESSON_SHORTANSWER
and $page->qtype
!= LESSON_NUMERICAL
) {
253 echo " [<label for=\"answereditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
254 "<input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" />";
255 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
257 print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer
);
260 print_textarea(false, 1, 70, 630, 300, "answer[$n]", $answer->answer
);
264 echo "<tr><td><b><label for=\"edit-response[$n]\">".get_string('response', 'lesson')." $nplus1:</label></b>\n";
265 if ($flags & LESSON_RESPONSE_EDITOR
) {
266 echo " [<label for=\"responseeditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
267 "<input type=\"checkbox\" id=\"responseeditor[$n]\" name=\"responseeditor[$n]\" value=\"1\" checked=\"checked\" />";
268 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
270 print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$n]", $answer->response
);
271 use_html_editor("response[$n]"); // switch on the editor
273 echo " [<label for=\"responseeditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
274 "<input type=\"checkbox\" id=\"responseeditor[$n]\" name=\"responseeditor[$n]\" value=\"1\" />";
275 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
277 print_textarea(false, 6, 70, 630, 300, "response[$n]", $answer->response
);
281 case LESSON_BRANCHTABLE
:
282 echo "<tr><td><b><label for=\"edit-answer[$n]\">".get_string("description", "lesson")." $nplus1:</label></b>\n";
283 if ($flags & LESSON_ANSWER_EDITOR
) {
284 echo " [<label for=\"answereditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
285 "<input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" checked=\"checked\" />";
286 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
288 print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer
);
289 use_html_editor("answer[$n]"); // switch on the editor
291 echo " [<label for=\"answereditor[$n]\">".get_string("useeditor", "lesson")."</label>: ".
292 "<input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" />";
293 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
295 print_textarea(false, 10, 70, 630, 300, "answer[$n]", $answer->answer
);
300 switch ($page->qtype
) {
301 case LESSON_MATCHING
:
303 echo "<tr><td><b>".get_string("correctanswerjump", "lesson").":</b> \n";
304 choose_from_menu($jump, "jumpto[$n]", $answer->jumpto
, "");
305 helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
307 echo get_string("correctanswerscore", "lesson").": <input type=\"text\" name=\"score[$n]\" value=\"$answer->score\" size=\"5\" />";
311 echo "<tr><td><b>".get_string("wronganswerjump", "lesson").":</b> \n";
312 choose_from_menu($jump, "jumpto[$n]", $answer->jumpto
, "");
313 helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
315 echo get_string("wronganswerscore", "lesson").": <input type=\"text\" name=\"score[$n]\" value=\"$answer->score\" size=\"5\" />";
318 //echo "</td></tr>\n";
321 echo "<tr><td><b>".get_string("jump", "lesson").":</b> \n";
322 choose_from_menu($jump, "jumpto[$n]", $answer->jumpto
, "");
323 helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
324 if($lesson->custom
) {
325 echo get_string("score", "lesson").": <input type=\"text\" name=\"score[$n]\" value=\"$answer->score\" size=\"5\" />";
329 case LESSON_TRUEFALSE
:
330 case LESSON_MULTICHOICE
:
331 case LESSON_SHORTANSWER
:
332 case LESSON_NUMERICAL
:
333 echo "<tr><td><b>".get_string("jump", "lesson")." $nplus1:</b> \n";
334 choose_from_menu($jump, "jumpto[$n]", $answer->jumpto
, "");
335 helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
336 if($lesson->custom
) {
337 echo get_string("score", "lesson")." $nplus1: <input type=\"text\" name=\"score[$n]\" value=\"$answer->score\" size=\"5\" />";
341 case LESSON_BRANCHTABLE
:
343 case LESSON_ENDOFCLUSTER
:
344 case LESSON_ENDOFBRANCH
:
345 echo "<tr><td><b>".get_string("jump", "lesson")." $nplus1:</b> \n";
346 choose_from_menu($jump, "jumpto[$n]", $answer->jumpto
, "");
347 helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
352 if ($page->qtype
== LESSON_ESSAY
) {
353 break; // only one answer for essays
357 if ($page->qtype
!= LESSON_ENDOFBRANCH
&& $page->qtype
!= LESSON_CLUSTER
&& $page->qtype
!= LESSON_ENDOFCLUSTER
) {
358 if ($page->qtype
== LESSON_MATCHING
) {
359 $maxanswers = $lesson->maxanswers +
2;
361 $maxanswers = $lesson->maxanswers
;
363 for ($i = $n; $i < $maxanswers; $i++
) {
364 if ($page->qtype
== LESSON_TRUEFALSE
&& $i > 1) {
365 break; // stop printing answers... only need two for true/false
368 echo "<input type=\"hidden\" name=\"answerid[$i]\" value=\"0\" />\n";
369 switch ($page->qtype
) {
370 case LESSON_MATCHING
:
371 $icorrected = $i - 1;
372 echo "<tr><td><b>".get_string("answer", "lesson")." $icorrected:</b>\n";
373 echo " [".get_string("useeditor", "lesson").": ".
374 "<input type=\"checkbox\" name=\"answereditor[$i]\" value=\"1\" />";
375 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
377 print_textarea(false, 10, 70, 630, 300, "answer[$i]");
379 echo "<tr><td><b>".get_string("matchesanswer", "lesson")." $icorrected:</b>\n";
380 echo " [".get_string("useeditor", "lesson").": ".
381 "<input type=\"checkbox\" name=\"responseeditor[$i]\" value=\"1\" />";
382 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
384 print_textarea(false, 10, 70, 630, 300, "response[$i]");
387 case LESSON_TRUEFALSE
:
388 case LESSON_MULTICHOICE
:
389 case LESSON_SHORTANSWER
:
390 case LESSON_NUMERICAL
:
391 echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b>\n";
392 if ($page->qtype
!= LESSON_SHORTANSWER
and $page->qtype
!= LESSON_NUMERICAL
) {
393 echo " [".get_string("useeditor", "lesson").": ".
394 "<input type=\"checkbox\" name=\"answereditor[$i]\" value=\"1\" />";
395 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
397 print_textarea(false, 10, 70, 630, 300, "answer[$i]");
400 print_textarea(false, 1, 70, 630, 300, "answer[$i]");
403 echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b>\n";
404 echo " [".get_string("useeditor", "lesson").": ".
405 "<input type=\"checkbox\" name=\"responseeditor[$i]\" value=\"1\" />";
406 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
408 print_textarea(false, 10, 70, 630, 300, "response[$i]");
411 case LESSON_BRANCHTABLE
:
412 echo "<tr><td><b>".get_string("description", "lesson")." $iplus1:</b>\n";
413 echo " [".get_string("useeditor", "lesson").": ".
414 "<input type=\"checkbox\" name=\"answereditor[$i]\" value=\"1\" />";
415 helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
417 print_textarea(false, 10, 70, 630, 300, "answer[$i]");
421 switch ($page->qtype
) {
424 echo "<tr><td><b>".get_string("jump", "lesson").":</b> \n";
425 choose_from_menu($jump, "jumpto[$i]", 0, "");
426 helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
427 if($lesson->custom
) {
428 echo get_string("score", "lesson").": <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\" />";
433 case LESSON_MATCHING
:
435 echo "<tr><td><b>".get_string("correctanswerjump", "lesson").":</b> \n";
436 choose_from_menu($jump, "jumpto[$i]", $answer->jumpto
, "");
437 helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
438 if ($lesson->custom
) {
439 echo get_string("correctanswerscore", "lesson").": <input type=\"text\" name=\"score[$i]\" value=\"$answer->score\" size=\"5\" />";
444 echo "<tr><td><b>".get_string("wronganswerjump", "lesson").":</b> \n";
445 choose_from_menu($jump, "jumpto[$i]", $answer->jumpto
, "");
446 helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
447 if ($lesson->custom
) {
448 echo get_string("wronganswerscore", "lesson").": <input type=\"text\" name=\"score[$i]\" value=\"$answer->score\" size=\"5\" />";
454 case LESSON_TRUEFALSE
:
455 case LESSON_MULTICHOICE
:
456 case LESSON_SHORTANSWER
:
457 case LESSON_NUMERICAL
:
458 echo "<tr><td><b>".get_string("jump", "lesson")." $iplus1:</b> \n";
459 choose_from_menu($jump, "jumpto[$i]", 0, "");
460 helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
461 if($lesson->custom
) {
462 echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"0\" size=\"5\" />";
466 case LESSON_BRANCHTABLE
:
467 echo "<tr><td><b>".get_string("jump", "lesson")." $iplus1:</b> \n";
468 choose_from_menu($jump, "jumpto[$i]", 0, "");
469 helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
475 // close table and form
478 <input type
="button" value
="<?php print_string("redisplaypage
", "lesson
") ?>"
479 onclick
="getElementById('editpage').redisplay.value=1;getElementById('editpage').submit();" />
480 <input type
="submit" value
="<?php print_string("savepage
", "lesson
") ?>" />
481 <input type
="submit" name
="cancel" value
="<?php print_string("cancel
") ?>" />