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];
78 if($answers = get_records_select("lesson_answers", "lessonid = $lesson->id and pageid = $pageid")) {
80 foreach ($answers as $answer) {
81 $jumps[] = lesson_get_jump_name($answer->jumpto
);
85 $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>',
86 lesson_get_qtype_name($page->qtype
),
87 implode("<br />\n", $jumps),
88 lesson_print_page_actions($cm->id
, $page, $npages, true, true)
90 $pageid = $page->nextpageid
;
97 // Only viewing a single page in full - change some variables to display just one
98 $prevpageid = $singlepage->prevpageid
;
99 $pageid = $singlepage->id
;
102 $pages[$singlepage->id
] = $singlepage;
105 echo '<table class="boxaligncenter" cellpadding="5" border="0" style="width:80%;">
108 lesson_print_add_links($cm->id
, $prevpageid);
112 while ($pageid != 0) {
113 $page = $pages[$pageid];
116 echo "<table style=\"width:100%;\" border=\"1\" class=\"generalbox\"><tr><th colspan=\"2\" scope=\"col\">".format_string($page->title
)." \n";
117 lesson_print_page_actions($cm->id
, $page, $npages);
119 echo "<tr><td colspan=\"2\">\n";
120 $options = new stdClass
;
121 $options->noclean
= true;
122 echo format_text($page->contents
, FORMAT_MOODLE
, $options);
124 // get the answers in a set order, the id order
125 if ($answers = get_records("lesson_answers", "pageid", $page->id
, "id")) {
126 echo "<tr><td colspan=\"2\" align=\"center\"><strong>\n";
127 echo lesson_get_qtype_name($page->qtype
);
128 switch ($page->qtype
) {
129 case LESSON_SHORTANSWER
:
130 if ($page->qoption
) {
131 echo " - ".get_string("casesensitive", "lesson");
134 case LESSON_MULTICHOICE
:
135 if ($page->qoption
) {
136 echo " - ".get_string("multianswer", "lesson");
139 case LESSON_MATCHING
:
140 echo get_string("firstanswershould", "lesson");
143 echo "</strong></td></tr>\n";
146 $options = new stdClass
;
147 $options->noclean
= true;
148 $options->para
= false;
149 foreach ($answers as $answer) {
150 switch ($page->qtype
) {
151 case LESSON_MULTICHOICE
:
152 case LESSON_TRUEFALSE
:
153 case LESSON_SHORTANSWER
:
154 case LESSON_NUMERICAL
:
155 echo "<tr><td align=\"right\" valign=\"top\" style=\"width:20%;\">\n";
156 if ($lesson->custom
) {
157 // if the score is > 0, then it is correct
158 if ($answer->score
> 0) {
159 echo '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
161 echo '<span class="label">'.get_string("answer", "lesson")." $i</span>: \n";
164 if (lesson_iscorrect($page->id
, $answer->jumpto
)) {
165 // underline correct answers
166 echo '<span class="correct">'.get_string("answer", "lesson")." $i</span>: \n";
168 echo '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
171 echo "</td><td style=\"width:80%;\">\n";
172 echo format_text($answer->answer
, FORMAT_MOODLE
, $options);
174 echo "<tr><td align=\"right\" valign=\"top\"><span class=\"label\">".get_string("response", "lesson")." $i</span>: \n";
176 echo format_text($answer->response
, FORMAT_MOODLE
, $options);
179 case LESSON_MATCHING
:
181 if ($answer->answer
!= NULL) {
183 echo "<tr><td align=\"right\" valign=\"top\"><span class=\"label\">".get_string("correctresponse", "lesson")."</span>: \n";
185 echo format_text($answer->answer
, FORMAT_MOODLE
, $options);
188 echo "<tr><td align=\"right\" valign=\"top\"><span class=\"label\">".get_string("wrongresponse", "lesson")."</span>: \n";
190 echo format_text($answer->answer
, FORMAT_MOODLE
, $options);
197 echo "<tr><td align=\"right\" valign=\"top\" style=\"width:20%;\">\n";
198 if ($lesson->custom
) {
199 // if the score is > 0, then it is correct
200 if ($answer->score
> 0) {
201 echo '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
203 echo '<span class="label">'.get_string("answer", "lesson")." $i</span>: \n";
206 if (lesson_iscorrect($page->id
, $answer->jumpto
)) {
207 // underline correct answers
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 echo "</td><td style=\"width:80%;\">\n";
214 echo format_text($answer->answer
, FORMAT_MOODLE
, $options);
216 echo "<tr><td align=\"right\" valign=\"top\">'<span class=\"label\">'.".get_string("matchesanswer", "lesson")." $i</span>: \n";
218 echo format_text($answer->response
, FORMAT_MOODLE
, $options);
222 case LESSON_BRANCHTABLE
:
223 echo "<tr><td align=\"right\" valign=\"top\" style=\"width:20%;\">\n";
224 echo '<span class="label">'.get_string("description", "lesson")." $i</span>: \n";
225 echo "</td><td style=\"width:80%;\">\n";
226 echo format_text($answer->answer
, FORMAT_MOODLE
, $options);
231 $jumptitle = lesson_get_jump_name($answer->jumpto
);
232 if ($page->qtype
== LESSON_MATCHING
) {
234 echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("correctanswerscore", "lesson");
235 echo "</span>: </td><td style=\"width:80%;\">\n";
236 echo "$answer->score</td></tr>\n";
237 echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("correctanswerjump", "lesson");
238 echo "</span>:</td><td style=\"width:80%;\">\n";
239 echo "$jumptitle</td></tr>\n";
241 echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("wronganswerscore", "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("wronganswerjump", "lesson");
245 echo "</span>: </td><td style=\"width:80%;\">\n";
246 echo "$jumptitle</td></tr>\n";
249 if ($lesson->custom
and
250 $page->qtype
!= LESSON_BRANCHTABLE
and
251 $page->qtype
!= LESSON_ENDOFBRANCH
and
252 $page->qtype
!= LESSON_CLUSTER
and
253 $page->qtype
!= LESSON_ENDOFCLUSTER
) {
254 echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("score", "lesson")." $i";
255 echo "</span>: </td><td style=\"width:80%;\">\n";
256 echo "$answer->score</td></tr>\n";
258 echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("jump", "lesson")." $i";
259 echo "</span>: </td><td style=\"width:80%;\">\n";
260 echo "$jumptitle</td></tr>\n";
265 echo "</table></td></tr>\n<tr><td align=\"left\">";
266 lesson_print_add_links($cm->id
, $page->id
);
267 echo "</td></tr><tr><td>\n";
268 // check the prev links - fix (silently) if necessary - there was a bug in
269 // versions 1 and 2 when add new pages. Not serious then as the backwards
270 // links were not used in those versions
271 if ($page->prevpageid
!= $prevpageid) {
273 set_field("lesson_pages", "prevpageid", $prevpageid, "id", $page->id
);
274 debugging("<p>***prevpageid of page $page->id set to $prevpageid***");
277 if (count($pages) == 1) {
282 $prevpageid = $page->id
;
283 $pageid = $page->nextpageid
;
291 print_footer($course);