2006-09-10 02:09:14 +00:00
|
|
|
<?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);
|
2006-09-10 22:47:57 +00:00
|
|
|
$pageid = optional_param('pageid', 0, PARAM_INT);
|
2006-09-10 02:09:14 +00:00
|
|
|
|
2006-09-10 22:47:57 +00:00
|
|
|
if ($mode != 'single') {
|
|
|
|
set_user_preference('lesson_view', $mode);
|
2006-09-10 02:09:14 +00:00
|
|
|
}
|
2006-09-10 22:47:57 +00:00
|
|
|
|
2006-09-10 02:09:14 +00:00
|
|
|
list($cm, $course, $lesson) = lesson_get_basics($id);
|
|
|
|
|
2006-09-10 22:47:57 +00:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
2006-09-10 02:09:14 +00:00
|
|
|
|
2006-09-10 22:47:57 +00:00
|
|
|
if ($pageid) {
|
|
|
|
if (!$singlepage = get_record('lesson_pages', 'id', $pageid)) {
|
|
|
|
error('Could not find page ID: '.$pageid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
require_login($course->id, false, $cm);
|
2006-09-10 02:09:14 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2006-10-31 22:02:49 +00:00
|
|
|
require_capability('mod/lesson:manage', $context);
|
2006-09-10 02:09:14 +00:00
|
|
|
|
|
|
|
lesson_print_header($cm, $course, $lesson, $mode);
|
|
|
|
|
2006-09-10 22:47:57 +00:00
|
|
|
if (empty($firstpage)) {
|
|
|
|
// There are no pages; give teacher some options
|
2006-09-10 02:09:14 +00:00
|
|
|
if (has_capability('mod/lesson:edit', $context)) {
|
2006-12-13 08:24:23 +00:00
|
|
|
print_simple_box( "<table cellpadding=\"5\" border=\"0\">\n<tr><th scope=\"col\">".get_string("whatdofirst", "lesson")."</th></tr><tr><td>".
|
2006-09-10 02:09:14 +00:00
|
|
|
"<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\">".
|
2006-09-10 22:47:57 +00:00
|
|
|
get_string("addaquestionpage", "lesson").
|
2007-02-23 20:20:50 +00:00
|
|
|
"</a></td></tr></table>\n", 'center', '20%');
|
2006-09-10 02:09:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
2006-09-10 22:47:57 +00:00
|
|
|
// 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');
|
2006-09-19 05:57:57 +00:00
|
|
|
$table->wrap = array('', 'nowrap', '', 'nowrap');
|
2006-09-10 22:47:57 +00:00
|
|
|
$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);
|
2006-09-10 02:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-10 22:47:57 +00:00
|
|
|
|
|
|
|
$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),
|
2006-09-13 03:42:16 +00:00
|
|
|
lesson_print_page_actions($cm->id, $page, $npages, true, true)
|
2006-09-10 22:47:57 +00:00
|
|
|
);
|
|
|
|
$pageid = $page->nextpageid;
|
2006-09-10 02:09:14 +00:00
|
|
|
}
|
2006-09-10 22:47:57 +00:00
|
|
|
|
|
|
|
print_table($table);
|
|
|
|
break;
|
2006-09-10 22:50:43 +00:00
|
|
|
|
2006-09-10 22:47:57 +00:00
|
|
|
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;
|
2006-09-10 22:50:43 +00:00
|
|
|
|
2006-09-10 22:47:57 +00:00
|
|
|
case 'full':
|
2007-01-11 08:51:46 +00:00
|
|
|
echo '<table class="boxaligncenter" cellpadding="5" border="0" style="width:80%;">
|
2006-09-10 22:47:57 +00:00
|
|
|
<tr>
|
|
|
|
<td align="left">';
|
|
|
|
lesson_print_add_links($cm->id, $prevpageid);
|
|
|
|
echo ' </td>
|
|
|
|
</tr>';
|
|
|
|
|
|
|
|
while ($pageid != 0) {
|
|
|
|
$page = $pages[$pageid];
|
|
|
|
|
|
|
|
echo "<tr><td>\n";
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "<table style=\"width:100%;\" border=\"1\" class=\"generalbox\"><tr><th colspan=\"2\" scope=\"col\">".format_string($page->title)." \n";
|
2006-09-13 03:42:16 +00:00
|
|
|
lesson_print_page_actions($cm->id, $page, $npages);
|
2006-09-10 22:47:57 +00:00
|
|
|
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")) {
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "<tr><td colspan=\"2\" align=\"center\"><strong>\n";
|
2006-09-10 22:47:57 +00:00
|
|
|
echo lesson_get_qtype_name($page->qtype);
|
|
|
|
switch ($page->qtype) {
|
|
|
|
case LESSON_SHORTANSWER :
|
|
|
|
if ($page->qoption) {
|
|
|
|
echo " - ".get_string("casesensitive", "lesson");
|
2006-09-10 02:09:14 +00:00
|
|
|
}
|
2006-09-10 22:47:57 +00:00
|
|
|
break;
|
|
|
|
case LESSON_MULTICHOICE :
|
|
|
|
if ($page->qoption) {
|
|
|
|
echo " - ".get_string("multianswer", "lesson");
|
2006-09-10 02:09:14 +00:00
|
|
|
}
|
2006-09-10 22:47:57 +00:00
|
|
|
break;
|
|
|
|
case LESSON_MATCHING :
|
|
|
|
echo get_string("firstanswershould", "lesson");
|
|
|
|
break;
|
|
|
|
}
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "</strong></td></tr>\n";
|
2006-09-10 22:47:57 +00:00
|
|
|
$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:
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "<tr><td align=\"right\" valign=\"top\" style=\"width:20%;\">\n";
|
2006-09-10 22:47:57 +00:00
|
|
|
if ($lesson->custom) {
|
|
|
|
// if the score is > 0, then it is correct
|
|
|
|
if ($answer->score > 0) {
|
2007-01-11 08:51:46 +00:00
|
|
|
echo '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
|
2006-09-10 22:47:57 +00:00
|
|
|
} else {
|
2007-01-11 08:51:46 +00:00
|
|
|
echo '<span class="label">'.get_string("answer", "lesson")." $i</span>: \n";
|
2006-09-10 22:47:57 +00:00
|
|
|
}
|
2006-09-10 02:09:14 +00:00
|
|
|
} else {
|
2006-09-10 22:47:57 +00:00
|
|
|
if (lesson_iscorrect($page->id, $answer->jumpto)) {
|
|
|
|
// underline correct answers
|
2007-01-11 08:51:46 +00:00
|
|
|
echo '<span class="correct">'.get_string("answer", "lesson")." $i</span>: \n";
|
2006-09-10 22:47:57 +00:00
|
|
|
} else {
|
2007-01-11 08:51:46 +00:00
|
|
|
echo '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
|
2006-09-10 22:47:57 +00:00
|
|
|
}
|
|
|
|
}
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "</td><td style=\"width:80%;\">\n";
|
2006-09-10 22:47:57 +00:00
|
|
|
echo format_text($answer->answer, FORMAT_MOODLE, $options);
|
|
|
|
echo "</td></tr>\n";
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "<tr><td align=\"right\" valign=\"top\"><span class=\"label\">".get_string("response", "lesson")." $i</span>: \n";
|
2006-09-10 22:47:57 +00:00
|
|
|
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) {
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "<tr><td align=\"right\" valign=\"top\"><span class=\"label\">".get_string("correctresponse", "lesson")."</span>: \n";
|
2006-09-10 22:47:57 +00:00
|
|
|
echo "</td><td>\n";
|
|
|
|
echo format_text($answer->answer, FORMAT_MOODLE, $options);
|
|
|
|
echo "</td></tr>\n";
|
|
|
|
} else {
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "<tr><td align=\"right\" valign=\"top\"><span class=\"label\">".get_string("wrongresponse", "lesson")."</span>: \n";
|
2006-09-10 22:47:57 +00:00
|
|
|
echo "</td><td>\n";
|
|
|
|
echo format_text($answer->answer, FORMAT_MOODLE, $options);
|
|
|
|
echo "</td></tr>\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$n++;
|
|
|
|
$i--;
|
|
|
|
} else {
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "<tr><td align=\"right\" valign=\"top\" style=\"width:20%;\">\n";
|
2006-09-10 22:47:57 +00:00
|
|
|
if ($lesson->custom) {
|
|
|
|
// if the score is > 0, then it is correct
|
|
|
|
if ($answer->score > 0) {
|
2007-01-11 08:51:46 +00:00
|
|
|
echo '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
|
2006-09-10 22:47:57 +00:00
|
|
|
} else {
|
2007-01-11 08:51:46 +00:00
|
|
|
echo '<span class="label">'.get_string("answer", "lesson")." $i</span>: \n";
|
2006-09-10 22:47:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (lesson_iscorrect($page->id, $answer->jumpto)) {
|
|
|
|
// underline correct answers
|
2007-01-11 08:51:46 +00:00
|
|
|
echo '<span class="labelcorrect">'.get_string("answer", "lesson")." $i</span>: \n";
|
2006-09-10 22:47:57 +00:00
|
|
|
} else {
|
2007-01-11 08:51:46 +00:00
|
|
|
echo '<span class="label">'.get_string("answer", "lesson")." $i</span>: \n";
|
2006-09-10 22:47:57 +00:00
|
|
|
}
|
|
|
|
}
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "</td><td style=\"width:80%;\">\n";
|
2006-09-10 22:47:57 +00:00
|
|
|
echo format_text($answer->answer, FORMAT_MOODLE, $options);
|
|
|
|
echo "</td></tr>\n";
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "<tr><td align=\"right\" valign=\"top\">'<span class=\"label\">'.".get_string("matchesanswer", "lesson")." $i</span>: \n";
|
2006-09-10 02:09:14 +00:00
|
|
|
echo "</td><td>\n";
|
2006-09-10 22:47:57 +00:00
|
|
|
echo format_text($answer->response, FORMAT_MOODLE, $options);
|
2006-09-10 02:09:14 +00:00
|
|
|
echo "</td></tr>\n";
|
|
|
|
}
|
2006-09-10 22:47:57 +00:00
|
|
|
break;
|
|
|
|
case LESSON_BRANCHTABLE:
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "<tr><td align=\"right\" valign=\"top\" style=\"width:20%;\">\n";
|
|
|
|
echo '<span class="label">'.get_string("description", "lesson")." $i</span>: \n";
|
|
|
|
echo "</td><td style=\"width:80%;\">\n";
|
2006-09-10 22:47:57 +00:00
|
|
|
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) {
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("correctanswerscore", "lesson");
|
|
|
|
echo "</span>: </td><td style=\"width:80%;\">\n";
|
2006-09-10 22:47:57 +00:00
|
|
|
echo "$answer->score</td></tr>\n";
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("correctanswerjump", "lesson");
|
|
|
|
echo "</span>:</td><td style=\"width:80%;\">\n";
|
2006-09-10 22:47:57 +00:00
|
|
|
echo "$jumptitle</td></tr>\n";
|
|
|
|
} elseif ($i == 2) {
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("wronganswerscore", "lesson");
|
|
|
|
echo "</span>: </td><td style=\"width:80%;\">\n";
|
2006-09-10 22:47:57 +00:00
|
|
|
echo "$answer->score</td></tr>\n";
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("wronganswerjump", "lesson");
|
|
|
|
echo "</span>: </td><td style=\"width:80%;\">\n";
|
2006-09-10 22:47:57 +00:00
|
|
|
echo "$jumptitle</td></tr>\n";
|
2006-09-10 02:09:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
2006-09-10 22:47:57 +00:00
|
|
|
if ($lesson->custom and
|
|
|
|
$page->qtype != LESSON_BRANCHTABLE and
|
|
|
|
$page->qtype != LESSON_ENDOFBRANCH and
|
|
|
|
$page->qtype != LESSON_CLUSTER and
|
|
|
|
$page->qtype != LESSON_ENDOFCLUSTER) {
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("score", "lesson")." $i";
|
|
|
|
echo "</span>: </td><td style=\"width:80%;\">\n";
|
2006-09-10 22:47:57 +00:00
|
|
|
echo "$answer->score</td></tr>\n";
|
2006-09-10 02:09:14 +00:00
|
|
|
}
|
2007-01-11 08:51:46 +00:00
|
|
|
echo "<tr><td align=\"right\" style=\"width:20%;\"><span class=\"label\">".get_string("jump", "lesson")." $i";
|
|
|
|
echo "</span>: </td><td style=\"width:80%;\">\n";
|
2006-09-10 22:47:57 +00:00
|
|
|
echo "$jumptitle</td></tr>\n";
|
2006-09-10 02:09:14 +00:00
|
|
|
}
|
2006-09-10 22:47:57 +00:00
|
|
|
$i++;
|
2006-09-10 02:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-10 22:47:57 +00:00
|
|
|
echo "</table></td></tr>\n<tr><td align=\"left\">";
|
|
|
|
lesson_print_add_links($cm->id, $page->id);
|
2006-12-22 05:58:28 +00:00
|
|
|
echo "</td></tr><tr><td>\n";
|
2006-09-10 22:47:57 +00:00
|
|
|
// 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);
|
2006-09-18 09:13:04 +00:00
|
|
|
debugging("<p>***prevpageid of page $page->id set to $prevpageid***");
|
2006-09-10 02:09:14 +00:00
|
|
|
}
|
2006-09-10 22:47:57 +00:00
|
|
|
|
|
|
|
if (count($pages) == 1) {
|
2006-12-20 02:17:13 +00:00
|
|
|
echo "</td></tr>";
|
2006-09-10 22:47:57 +00:00
|
|
|
break;
|
2006-09-10 02:09:14 +00:00
|
|
|
}
|
2006-09-10 22:47:57 +00:00
|
|
|
|
|
|
|
$prevpageid = $page->id;
|
|
|
|
$pageid = $page->nextpageid;
|
2006-12-20 02:17:13 +00:00
|
|
|
echo "</td></tr>";
|
2006-09-10 02:09:14 +00:00
|
|
|
}
|
2006-12-22 05:58:28 +00:00
|
|
|
echo "</table>";
|
2006-09-10 02:09:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print_footer($course);
|
2006-09-18 09:13:04 +00:00
|
|
|
?>
|