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( "\n
".get_string("whatdofirst", "lesson")."
". "id&pageid=0\">". get_string("importquestions", "lesson")."
". "id&pageid=0\">". get_string("importppt", "lesson")."
". "id&action=addbranchtable&pageid=0&firstpage=1\">". get_string("addabranchtable", "lesson")."
". "id&action=addpage&pageid=0&firstpage=1\">". get_string("addaquestionpage", "lesson"). "
\n", 'center', '20%'); } } 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]; if ($page->qtype == LESSON_MATCHING) { // The jumps for matching question type is stored // in the 3rd and 4rth answer record. $limitfrom = $limitnum = 2; } else { $limitfrom = $limitnum = ''; } $jumps = array(); if($answers = get_records_select("lesson_answers", "lessonid = $lesson->id and pageid = $pageid", 'id', '*', $limitfrom, $limitnum)) { foreach ($answers as $answer) { $jumps[] = lesson_get_jump_name($answer->jumpto); } } $table->data[] = array("wwwroot/mod/lesson/edit.php?id=$cm->id&mode=single&pageid=".$page->id."\">".format_string($pages[$pageid]->title,true).'', lesson_get_qtype_name($page->qtype), implode("
\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 ''; while ($pageid != 0) { $page = $pages[$pageid]; echo "\n"; break; } $prevpageid = $page->id; $pageid = $page->nextpageid; echo ""; } echo "
'; lesson_print_add_links($cm->id, $prevpageid); echo '
\n"; echo "\n"; echo "\n"; // get the answers in a set order, the id order if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { echo "\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 "\n"; echo "\n"; break; case LESSON_MATCHING: if ($n < 2) { if ($answer->answer != NULL) { if ($n == 0) { echo "\n"; } else { echo "\n"; } } $n++; $i--; } else { echo "\n"; echo "\n"; } break; case LESSON_BRANCHTABLE: echo "\n"; break; } $jumptitle = lesson_get_jump_name($answer->jumpto); if ($page->qtype == LESSON_MATCHING) { if ($i == 1) { echo "\n"; echo "\n"; } elseif ($i == 2) { echo "\n"; echo "\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 "\n"; } echo "\n"; } $i++; } } echo "
".format_string($page->title)."  \n"; lesson_print_page_actions($cm->id, $page, $npages); echo "
\n"; $options = new stdClass; $options->noclean = true; echo format_text($page->contents, FORMAT_MOODLE, $options); echo "
\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 "
\n"; if ($lesson->custom) { // if the score is > 0, then it is correct if ($answer->score > 0) { echo ''.get_string("answer", "lesson")." $i: \n"; } else { echo ''.get_string("answer", "lesson")." $i: \n"; } } else { if (lesson_iscorrect($page->id, $answer->jumpto)) { // underline correct answers echo ''.get_string("answer", "lesson")." $i: \n"; } else { echo ''.get_string("answer", "lesson")." $i: \n"; } } echo "\n"; echo format_text($answer->answer, FORMAT_MOODLE, $options); echo "
".get_string("response", "lesson")." $i: \n"; echo "\n"; echo format_text($answer->response, FORMAT_MOODLE, $options); echo "
".get_string("correctresponse", "lesson").": \n"; echo "\n"; echo format_text($answer->answer, FORMAT_MOODLE, $options); echo "
".get_string("wrongresponse", "lesson").": \n"; echo "\n"; echo format_text($answer->answer, FORMAT_MOODLE, $options); echo "
\n"; if ($lesson->custom) { // if the score is > 0, then it is correct if ($answer->score > 0) { echo ''.get_string("answer", "lesson")." $i: \n"; } else { echo ''.get_string("answer", "lesson")." $i: \n"; } } else { if (lesson_iscorrect($page->id, $answer->jumpto)) { // underline correct answers echo ''.get_string("answer", "lesson")." $i: \n"; } else { echo ''.get_string("answer", "lesson")." $i: \n"; } } echo "\n"; echo format_text($answer->answer, FORMAT_MOODLE, $options); echo "
".get_string("matchesanswer", "lesson")." $i: \n"; echo "\n"; echo format_text($answer->response, FORMAT_MOODLE, $options); echo "
\n"; echo ''.get_string("description", "lesson")." $i: \n"; echo "\n"; echo format_text($answer->answer, FORMAT_MOODLE, $options); echo "
".get_string("correctanswerscore", "lesson"); echo ": \n"; echo "$answer->score
".get_string("correctanswerjump", "lesson"); echo ":\n"; echo "$jumptitle
".get_string("wronganswerscore", "lesson"); echo ": \n"; echo "$answer->score
".get_string("wronganswerjump", "lesson"); echo ": \n"; echo "$jumptitle
".get_string("score", "lesson")." $i"; echo ": \n"; echo "$answer->score
".get_string("jump", "lesson")." $i"; echo ": \n"; echo "$jumptitle
"; lesson_print_add_links($cm->id, $page->id); echo "
\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("

***prevpageid of page $page->id set to $prevpageid***"); } if (count($pages) == 1) { echo "

"; break; } } print_footer($course); ?>