3 * Provides the interface for overall authoring of lessons
6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
10 require_once('../../config.php');
11 require_once('locallib.php');
12 require_once('lib.php');
14 $id = required_param('id', PARAM_INT
); // Course Module ID
15 $display = optional_param('display', 0, PARAM_INT
);
16 $mode = optional_param('mode', get_user_preferences('lesson_view', 'collapsed'), PARAM_ALPHA
);
17 $pageid = optional_param('pageid', 0, PARAM_INT
);
19 if ($mode != 'single') {
20 set_user_preference('lesson_view', $mode);
23 list($cm, $course, $lesson) = lesson_get_basics($id);
25 if ($firstpage = get_record('lesson_pages', 'lessonid', $lesson->id
, 'prevpageid', 0)) {
26 if (!$pages = get_records('lesson_pages', 'lessonid', $lesson->id
)) {
27 error('Could not find lesson pages');
32 if (!$singlepage = get_record('lesson_pages', 'id', $pageid)) {
33 error('Could not find page ID: '.$pageid);
37 require_login($course->id
, false, $cm);
38 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
39 require_capability('mod/lesson:manage', $context);
41 lesson_print_header($cm, $course, $lesson, $mode);
43 if (empty($firstpage)) {
44 // There are no pages; give teacher some options
45 if (has_capability('mod/lesson:edit', $context)) {
46 print_simple_box( "<table cellpadding=\"5\" border=\"0\">\n<tr><th scope=\"col\">".get_string("whatdofirst", "lesson")."</th></tr><tr><td>".
47 "<a href=\"import.php?id=$cm->id&pageid=0\">".
48 get_string("importquestions", "lesson")."</a></td></tr><tr><td>".
49 "<a href=\"importppt.php?id=$cm->id&pageid=0\">".
50 get_string("importppt", "lesson")."</a></td></tr><tr><td>".
51 "<a href=\"lesson.php?id=$cm->id&action=addbranchtable&pageid=0&firstpage=1\">".
52 get_string("addabranchtable", "lesson")."</a></td></tr><tr><td>".
53 "<a href=\"lesson.php?id=$cm->id&action=addpage&pageid=0&firstpage=1\">".
54 get_string("addaquestionpage", "lesson").
55 "</a></td></tr></table>\n", 'center', '20%');
58 // Set some standard variables
59 $pageid = $firstpage->id
;
61 $npages = count($pages);
65 $table = new stdClass
;
66 $table->head
= array(get_string('pagetitle', 'lesson'), get_string('qtype', 'lesson'), get_string('jumps', 'lesson'), get_string('actions', 'lesson'));
67 $table->align
= array('left', 'left', 'left', 'center');
68 $table->wrap
= array('', 'nowrap', '', 'nowrap');
69 $table->tablealign
= 'center';
70 $table->cellspacing
= 0;
71 $table->cellpadding
= '2px';
72 $table->data
= array();
74 while ($pageid != 0) {
75 $page = $pages[$pageid];
77 if ($page->qtype
== LESSON_MATCHING
) {
78 // The jumps for matching question type is stored
79 // in the 3rd and 4rth answer record.
80 $limitfrom = $limitnum = 2;
82 $limitfrom = $limitnum = '';
86 if($answers = get_records_select("lesson_answers", "lessonid = $lesson->id and pageid = $pageid", 'id', '*', $limitfrom, $limitnum)) {
87 foreach ($answers as $answer) {
88 $jumps[] = lesson_get_jump_name($answer->jumpto
);
92 $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>',
93 lesson_get_qtype_name($page->qtype
),
94 implode("<br />\n", $jumps),
95 lesson_print_page_actions($cm->id
, $page, $npages, true, true)
97 $pageid = $page->nextpageid
;
104 // Only viewing a single page in full - change some variables to display just one
105 $prevpageid = $singlepage->prevpageid
;
106 $pageid = $singlepage->id
;
109 $pages[$singlepage->id
] = $singlepage;
112 echo '<table class="boxaligncenter" cellpadding="5" border="0" style="width:80%;">
115 lesson_print_add_links($cm->id
, $prevpageid);
119 while ($pageid != 0) {
120 $page = $pages[$pageid];
123 echo "<table style=\"width:100%;\" border=\"1\" class=\"generalbox\"><tr><th colspan=\"2\" scope=\"col\">".format_string($page->title
)." \n";
124 lesson_print_page_actions($cm->id
, $page, $npages);
126 echo "<tr><td colspan=\"2\">\n";
127 $options = new stdClass
;
128 $options->noclean
= true;
129 echo format_text($page->contents
, FORMAT_MOODLE
, $options);
131 // get the answers in a set order, the id order
132 if ($answers = get_records("lesson_answers", "pageid", $page->id
, "id")) {
133 echo "<tr><td colspan=\"2\" align=\"center\"><strong>\n";
134 echo lesson_get_qtype_name($page->qtype
);
135 switch ($page->qtype
) {
136 case LESSON_SHORTANSWER
:
137 if ($page->qoption
) {
138 echo " - ".get_string("casesensitive", "lesson");
141 case LESSON_MULTICHOICE
:
142 if ($page->qoption
) {
143 echo " - ".get_string("multianswer", "lesson");
146 case LESSON_MATCHING
:
147 echo get_string("firstanswershould", "lesson");
150 echo "</strong></td></tr>\n";
153 $options = new stdClass
;
154 $options->noclean
= true;
155 $options->para
= false;
156 foreach ($answers as $answer) {
157 switch ($page->qtype
) {
158 case LESSON_MULTICHOICE
:
159 case LESSON_TRUEFALSE
:
160 case LESSON_SHORTANSWER
:
161 case LESSON_NUMERICAL
:
162 echo "<tr><td align=\"right\" valign=\"top\" style=\"width:20%;\">\n";
163 if ($lesson->custom
) {
164 // if the score is > 0, then it is correct
165 if ($answer->score
> 0) {
166 echo '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
168 echo '<span class="label">'.get_string("answer", "lesson")." $i</span>: \n";
171 if (lesson_iscorrect($page->id
, $answer->jumpto
)) {
172 // underline correct answers
173 echo '<span class="correct">'.get_string("answer", "lesson")." $i</span>: \n";
175 echo '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
178 echo "</td><td style=\"width:80%;\">\n";
179 echo format_text($answer->answer
, FORMAT_MOODLE
, $options);
181 echo "<tr><td align=\"right\" valign=\"top\"><span class=\"label\">".get_string("response", "lesson")." $i</span>: \n";
183 echo format_text($answer->response
, FORMAT_MOODLE
, $options);
186 case LESSON_MATCHING
:
188 if ($answer->answer
!= NULL) {
190 echo "<tr><td align=\"right\" valign=\"top\"><span class=\"label\">".get_string("correctresponse", "lesson")."</span>: \n";
192 echo format_text($answer->answer
, FORMAT_MOODLE
, $options);
195 echo "<tr><td align=\"right\" valign=\"top\"><span class=\"label\">".get_string("wrongresponse", "lesson")."</span>: \n";
197 echo format_text($answer->answer
, FORMAT_MOODLE
, $options);
204 echo "<tr><td align=\"right\" valign=\"top\" style=\"width:20%;\">\n";
205 if ($lesson->custom
) {
206 // if the score is > 0, then it is correct
207 if ($answer->score
> 0) {
208 echo '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
210 echo '<span class="label">'.get_string("answer", "lesson")." $i</span>: \n";
213 if (lesson_iscorrect($page->id
, $answer->jumpto
)) {
214 // underline correct answers
215 echo '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
217 echo '<span class="label">'.get_string("answer", "lesson")." $i</span>: \n";
220 echo "</td><td style=\"width:80%;\">\n";
221 echo format_text($answer->answer
, FORMAT_MOODLE
, $options);
223 echo "<tr><td align=\"right\" valign=\"top\"><span class=\"label\">".get_string("matchesanswer", "lesson")." $i</span>: \n";
225 echo format_text($answer->response
, FORMAT_MOODLE
, $options);
229 case LESSON_BRANCHTABLE
:
230 echo "<tr><td align=\"right\" valign=\"top\" style=\"width:20%;\">\n";
231 echo '<span class="label">'.get_string("description", "lesson")." $i</span>: \n";
232 echo "</td><td style=\"width:80%;\">\n";
233 echo format_text($answer->answer
, FORMAT_MOODLE
, $options);
238 $jumptitle = lesson_get_jump_name($answer->jumpto
);
239 if ($page->qtype
== LESSON_MATCHING
) {
241 echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("correctanswerscore", "lesson");
242 echo "</span>: </td><td style=\"width:80%;\">\n";
243 echo "$answer->score</td></tr>\n";
244 echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("correctanswerjump", "lesson");
245 echo "</span>:</td><td style=\"width:80%;\">\n";
246 echo "$jumptitle</td></tr>\n";
248 echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("wronganswerscore", "lesson");
249 echo "</span>: </td><td style=\"width:80%;\">\n";
250 echo "$answer->score</td></tr>\n";
251 echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("wronganswerjump", "lesson");
252 echo "</span>: </td><td style=\"width:80%;\">\n";
253 echo "$jumptitle</td></tr>\n";
256 if ($lesson->custom
and
257 $page->qtype
!= LESSON_BRANCHTABLE
and
258 $page->qtype
!= LESSON_ENDOFBRANCH
and
259 $page->qtype
!= LESSON_CLUSTER
and
260 $page->qtype
!= LESSON_ENDOFCLUSTER
) {
261 echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("score", "lesson")." $i";
262 echo "</span>: </td><td style=\"width:80%;\">\n";
263 echo "$answer->score</td></tr>\n";
265 echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("jump", "lesson")." $i";
266 echo "</span>: </td><td style=\"width:80%;\">\n";
267 echo "$jumptitle</td></tr>\n";
272 echo "</table></td></tr>\n<tr><td align=\"left\">";
273 lesson_print_add_links($cm->id
, $page->id
);
274 echo "</td></tr><tr><td>\n";
275 // check the prev links - fix (silently) if necessary - there was a bug in
276 // versions 1 and 2 when add new pages. Not serious then as the backwards
277 // links were not used in those versions
278 if ($page->prevpageid
!= $prevpageid) {
280 set_field("lesson_pages", "prevpageid", $prevpageid, "id", $page->id
);
281 debugging("<p>***prevpageid of page $page->id set to $prevpageid***");
284 if (count($pages) == 1) {
289 $prevpageid = $page->id
;
290 $pageid = $page->nextpageid
;
298 print_footer($course);