Started to rework the overall page editing interface for teachers.

This commit is contained in:
mark-nielsen 2006-09-10 22:47:57 +00:00
parent 82c57929b0
commit 68a1e8fbba
4 changed files with 430 additions and 431 deletions

View File

@ -14,32 +14,34 @@
$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);
$pageid = optional_param('pageid', 0, PARAM_INT);
set_user_preference('lesson_view', $mode);
// set collapsed flag
if ($mode == 'collapsed') {
$collapsed = true;
} else {
$collapsed = false;
if ($mode != 'single') {
set_user_preference('lesson_view', $mode);
}
list($cm, $course, $lesson) = lesson_get_basics($id);
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');
}
}
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');
lesson_print_header($cm, $course, $lesson, $mode);
// get number of pages
$npages = count_records('lesson_pages', 'lessonid', $lesson->id);
if (!$page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) {
// if there are no pages give teacher the option to create a new page or a new branch table
echo "<div align=\"center\">";
if (empty($firstpage)) {
// There are no pages; give teacher some options
if (has_capability('mod/lesson:edit', $context)) {
print_simple_box( "<table cellpadding=\"5\" border=\"0\">\n<tr><th>".get_string("whatdofirst", "lesson")."</th></tr><tr><td>".
"<a href=\"import.php?id=$cm->id&amp;pageid=0\">".
@ -49,344 +51,244 @@
"<a href=\"lesson.php?id=$cm->id&amp;action=addbranchtable&amp;pageid=0&amp;firstpage=1\">".
get_string("addabranchtable", "lesson")."</a></td></tr><tr><td>".
"<a href=\"lesson.php?id=$cm->id&amp;action=addpage&amp;pageid=0&amp;firstpage=1\">".
get_string("addaquestionpage", "lesson")." ".get_string("here","lesson").
"</a></td></tr></table>\n");
get_string("addaquestionpage", "lesson").
"</a></td></tr></table>\n", 'center');
}
echo '</div>';
} else {
// print the pages
echo "<form name=\"lessonpages\" method=\"post\" action=\"$CFG->wwwroot/mod/lesson/view.php\">\n";
echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
echo "<input type=\"hidden\" name=\"pageid\" />\n";
$branch = false;
$singlePage = false;
if($collapsed and !$display) {
echo "<div align=\"center\">\n";
echo "<table><tr><td>\n";
lesson_print_tree($page->id, $lesson, $cm->id);
echo "</td></tr></table>\n";
echo "</div>\n";
} else {
if($display) {
while(true)
{
if($page->id == $display && $page->qtype == LESSON_BRANCHTABLE) {
$branch = true;
$singlePage = false;
break;
} elseif($page->id == $display) {
$branch = false;
$singlePage = true;
break;
} elseif ($page->nextpageid) {
if (!$page = get_record("lesson_pages", "id", $page->nextpageid)) {
error("Teacher view: Next page not found!");
}
} else {
// last page reached
break;
}
}
echo "<table align=\"center\" cellpadding=\"5\" border=\"0\" width=\"80%\">\n";
if (has_capability('mod/lesson:edit', $context)) {
echo "<tr><td align=\"left\"><small><a href=\"import.php?id=$cm->id&amp;pageid=$page->prevpageid\">".
get_string("importquestions", "lesson")."</a> | ".
"<a href=\"lesson.php?id=$cm->id&amp;sesskey=".$USER->sesskey."&amp;action=addcluster&amp;pageid=$page->prevpageid\">".
get_string("addcluster", "lesson")."</a> | ".
"<a href=\"lesson.php?id=$cm->id&amp;sesskey=".$USER->sesskey."&amp;action=addendofcluster&amp;pageid=$page->prevpageid\">".
get_string("addendofcluster", "lesson")."</a> | ".
"<a href=\"lesson.php?id=$cm->id&amp;action=addbranchtable&amp;pageid=$page->prevpageid\">".
get_string("addabranchtable", "lesson")."</a> | ".
"<a href=\"lesson.php?id=$cm->id&amp;action=addpage&amp;pageid=$page->prevpageid\">".
get_string("addaquestionpage", "lesson")." ".get_string("here","lesson").
"</a></small></td></tr>\n";
}
} else {
echo "<table align=\"center\" cellpadding=\"5\" border=\"0\" width=\"80%\">\n";
if (has_capability('mod/lesson:edit', $context)) {
echo "<tr><td align=\"left\"><small><a href=\"import.php?id=$cm->id&amp;pageid=0\">".
get_string("importquestions", "lesson")."</a> | ".
"<a href=\"lesson.php?id=$cm->id&amp;sesskey=".$USER->sesskey."&amp;action=addcluster&amp;pageid=0\">".
get_string("addcluster", "lesson")."</a> | ".
"<a href=\"lesson.php?id=$cm->id&amp;action=addbranchtable&amp;pageid=0\">".
get_string("addabranchtable", "lesson")."</a> | ".
"<a href=\"lesson.php?id=$cm->id&amp;action=addpage&amp;pageid=0\">".
get_string("addaquestionpage", "lesson")." ".get_string("here","lesson").
"</a></small></td></tr>\n";
}
}
/// end collapsed code (note, there is an "}" below for an else above)
while (true) {
echo "<tr><td>\n";
echo "<table width=\"100%\" border=\"1\" class=\"generalbox\"><tr><th colspan=\"2\">".format_string($page->title)."&nbsp;&nbsp;\n";
if (has_capability('mod/lesson:edit', $context)) {
if ($npages > 1) {
echo "<a title=\"".get_string("move")."\" href=\"lesson.php?id=$cm->id&amp;action=move&amp;pageid=$page->id\">\n".
"<img src=\"$CFG->pixpath/t/move.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\" alt=\"move\" /></a>\n";
}
echo "<a title=\"".get_string("update")."\" href=\"lesson.php?id=$cm->id&amp;action=editpage&amp;pageid=$page->id\">\n".
"<img src=\"$CFG->pixpath/t/edit.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\" alt=\"edit\" /></a>\n".
"<a title=\"".get_string("delete")."\" href=\"lesson.php?id=$cm->id&amp;sesskey=".$USER->sesskey."&amp;action=confirmdelete&amp;pageid=$page->id\">\n".
"<img src=\"$CFG->pixpath/t/delete.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\" alt=\"delete\" /></a>\n";
}
echo "</th></tr>\n";
echo "<tr><td colspan=\"2\">\n";
$options = new stdClass;
$options->noclean = true;
print_simple_box(format_text($page->contents, FORMAT_MOODLE, $options), "center");
echo "</td></tr>\n";
// get the answers in a set order, the id order
if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) {
echo "<tr><td colspan=\"2\" align=\"center\"><b>\n";
switch ($page->qtype) {
case LESSON_ESSAY :
echo $LESSON_QUESTION_TYPE[$page->qtype];
break;
case LESSON_SHORTANSWER :
echo $LESSON_QUESTION_TYPE[$page->qtype];
if ($page->qoption) {
echo " - ".get_string("casesensitive", "lesson");
}
break;
case LESSON_MULTICHOICE :
echo $LESSON_QUESTION_TYPE[$page->qtype];
if ($page->qoption) {
echo " - ".get_string("multianswer", "lesson");
}
break;
case LESSON_MATCHING :
echo $LESSON_QUESTION_TYPE[$page->qtype];
echo get_string("firstanswershould", "lesson");
break;
case LESSON_TRUEFALSE :
case LESSON_NUMERICAL :
echo $LESSON_QUESTION_TYPE[$page->qtype];
break;
case LESSON_BRANCHTABLE :
echo get_string("branchtable", "lesson");
break;
case LESSON_ENDOFBRANCH :
echo get_string("endofbranch", "lesson");
break;
case LESSON_CLUSTER :
echo get_string("clustertitle", "lesson");
break;
case LESSON_ENDOFCLUSTER :
echo get_string("endofclustertitle", "lesson");
break;
}
echo "</b></td></tr>\n";
$i = 1;
$n = 0;
foreach ($answers as $answer) {
switch ($page->qtype) {
case LESSON_MULTICHOICE:
case LESSON_TRUEFALSE:
case LESSON_SHORTANSWER:
case LESSON_NUMERICAL:
echo "<tr><td align=\"right\" valign=\"top\" width=\"20%\">\n";
if ($lesson->custom) {
// if the score is > 0, then it is correct
if ($answer->score > 0) {
echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
} else {
echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
}
} else {
if (lesson_iscorrect($page->id, $answer->jumpto)) {
// underline correct answers
echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
} else {
echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
}
}
$options = new stdClass;
$options->noclean = true;
echo "</td><td width=\"80%\">\n";
echo format_text($answer->answer, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
echo "<tr><td align=\"right\" valign=\"top\"><b>".get_string("response", "lesson")." $i:</b> \n";
echo "</td><td>\n";
echo format_text($answer->response, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
break;
case LESSON_MATCHING:
$options = new stdClass;
$options->noclean = true;
if ($n < 2) {
if ($answer->answer != NULL) {
if ($n == 0) {
echo "<tr><td align=\"right\" valign=\"top\"><b>".get_string("correctresponse", "lesson").":</b> \n";
echo "</td><td>\n";
echo format_text($answer->answer, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
} else {
echo "<tr><td align=\"right\" valign=\"top\"><b>".get_string("wrongresponse", "lesson").":</b> \n";
echo "</td><td>\n";
echo format_text($answer->answer, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
}
}
$n++;
$i--;
} else {
echo "<tr><td align=\"right\" valign=\"top\" width=\"20%\">\n";
if ($lesson->custom) {
// if the score is > 0, then it is correct
if ($answer->score > 0) {
echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
} else {
echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
}
} else {
if (lesson_iscorrect($page->id, $answer->jumpto)) {
// underline correct answers
echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
} else {
echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
}
}
echo "</td><td width=\"80%\">\n";
echo format_text($answer->answer, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
echo "<tr><td align=\"right\" valign=\"top\"><b>".get_string("matchesanswer", "lesson")." $i:</b> \n";
echo "</td><td>\n";
echo format_text($answer->response, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
}
break;
case LESSON_BRANCHTABLE:
$options = new stdClass;
$options->noclean = true;
echo "<tr><td align=\"right\" valign=\"top\" width=\"20%\">\n";
echo "<b>".get_string("description", "lesson")." $i:</b> \n";
echo "</td><td width=\"80%\">\n";
echo format_text($answer->answer, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
break;
}
if ($answer->jumpto == 0) {
$jumptitle = get_string("thispage", "lesson");
} elseif ($answer->jumpto == LESSON_NEXTPAGE) {
$jumptitle = get_string("nextpage", "lesson");
} elseif ($answer->jumpto == LESSON_EOL) {
$jumptitle = get_string("endoflesson", "lesson");
} elseif ($answer->jumpto == LESSON_UNSEENBRANCHPAGE) {
$jumptitle = get_string("unseenpageinbranch", "lesson");
} elseif ($answer->jumpto == LESSON_PREVIOUSPAGE) {
$jumptitle = get_string("previouspage", "lesson");
} elseif ($answer->jumpto == LESSON_RANDOMPAGE) {
$jumptitle = get_string("randompageinbranch", "lesson");
} elseif ($answer->jumpto == LESSON_RANDOMBRANCH) {
$jumptitle = get_string("randombranch", "lesson");
} elseif ($answer->jumpto == LESSON_CLUSTERJUMP) {
$jumptitle = get_string("clusterjump", "lesson");
} else {
if (!$jumptitle = get_field("lesson_pages", "title", "id", $answer->jumpto)) {
$jumptitle = "<b>".get_string("notdefined", "lesson")."</b>";
// TODO: Check to make sure pages is set?
// 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();
$table->width = '70%';
$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);
}
}
$jumptitle = format_string($jumptitle,true);
if ($page->qtype == LESSON_MATCHING) {
if ($i == 1) {
echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("correctanswerscore", "lesson").":";
echo "</b></td><td width=\"80%\">\n";
echo "$answer->score</td></tr>\n";
echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("correctanswerjump", "lesson").":";
echo "</b></td><td width=\"80%\">\n";
echo "$jumptitle</td></tr>\n";
} elseif ($i == 2) {
echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("wronganswerscore", "lesson").":";
echo "</b></td><td width=\"80%\">\n";
echo "$answer->score</td></tr>\n";
echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("wronganswerjump", "lesson").":";
echo "</b></td><td width=\"80%\">\n";
echo "$jumptitle</td></tr>\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 "<tr><td align=\"right\" width=\"20%\"><b>".get_string("score", "lesson")." $i:";
echo "</b></td><td width=\"80%\">\n";
echo "$answer->score</td></tr>\n";
}
echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("jump", "lesson")." $i:";
echo "</b></td><td width=\"80%\">\n";
echo "$jumptitle</td></tr>\n";
}
$i++;
$table->data[] = array("<a href=\"$CFG->wwwroot/mod/lesson/edit.php?id=$cm->id&amp;mode=single&amp;pageid=".$page->id."\">".format_string($pages[$pageid]->title,true).'</a>',
lesson_get_qtype_name($page->qtype),
implode("<br />\n", $jumps),
lesson_print_page_actions($cm->id, $page->id, $npages, true)
);
$pageid = $page->nextpageid;
}
// print_simple_box_end(); // not sure if i commented this out... hehe
echo "<tr><td colspan=\"2\" align=\"center\">";
if ($page->qtype != LESSON_ENDOFBRANCH) {
echo "<input type=\"button\" value=\"";
if ($page->qtype == LESSON_BRANCHTABLE) {
echo get_string("checkbranchtable", "lesson");
} else {
echo get_string("checkquestion", "lesson");
}
echo "\" onclick=\"document.lessonpages.pageid.value=$page->id;".
"document.lessonpages.submit();\" />";
}
echo "&nbsp;</td></tr>\n";
}
echo "</table></td></tr>\n";
if (has_capability('mod/lesson:edit', $context)) {
echo "<tr><td align=\"left\"><small><a href=\"import.php?id=$cm->id&amp;pageid=$page->id\">".
get_string("importquestions", "lesson")."</a> | ".
"<a href=\"lesson.php?id=$cm->id&amp;sesskey=".$USER->sesskey."&amp;action=addcluster&amp;pageid=$page->id\">".
get_string("addcluster", "lesson")."</a> | ".
"<a href=\"lesson.php?id=$cm->id&amp;sesskey=".$USER->sesskey."&amp;action=addendofcluster&amp;pageid=$page->id\">".
get_string("addendofcluster", "lesson")."</a> | ".
"<a href=\"lesson.php?id=$cm->id&amp;action=addbranchtable&amp;pageid=$page->id\">".
get_string("addabranchtable", "lesson")."</a><br />";
// the current page or the next page is an end of branch don't show EOB link
$nextqtype = 0; // set to anything else EOB
if ($page->nextpageid) {
$nextqtype = get_field("lesson_pages", "qtype", "id", $page->nextpageid);
}
if (($page->qtype != LESSON_ENDOFBRANCH) and ($nextqtype != LESSON_ENDOFBRANCH)) {
echo "<a href=\"lesson.php?id=$cm->id&amp;sesskey=".$USER->sesskey."&amp;action=addendofbranch&amp;pageid=$page->id\">".
get_string("addanendofbranch", "lesson")."</a> | ";
}
echo "<a href=\"lesson.php?id=$cm->id&amp;action=addpage&amp;pageid=$page->id\">".
get_string("addaquestionpage", "lesson")." ".get_string("here","lesson").
"</a></small></td></tr>\n";
}
// echo "<tr><td>\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 (isset($prevpageid)) {
if ($page->prevpageid != $prevpageid) {
// fix it
set_field("lesson_pages", "prevpageid", $prevpageid, "id", $page->id);
if ($CFG->debug) {
echo "<p>***prevpageid of page $page->id set to $prevpageid***";
}
}
}
$prevpageid = $page->id;
// move to next page
if($singlePage) { // this will make sure only one page is displayed if needed
print_table($table);
break;
} elseif($branch && $page->qtype == LESSON_ENDOFBRANCH) { // this will display a branch table and its contents
break;
} elseif ($page->nextpageid) {
if (!$page = get_record("lesson_pages", "id", $page->nextpageid)) {
error("Teacher view: Next page not found!");
}
} else {
// last page reached
break;
}
}
} // end of else from above collapsed code!!!
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 '<table align="center" cellpadding="5" border="0" width="80%">
<tr>
<td align="left">';
lesson_print_add_links($cm->id, $prevpageid);
echo ' </td>
</tr>';
echo "</table></form>\n";
while ($pageid != 0) {
$page = $pages[$pageid];
echo "<tr><td>\n";
echo "<table width=\"100%\" border=\"1\" class=\"generalbox\"><tr><th colspan=\"2\">".format_string($page->title)."&nbsp;&nbsp;\n";
lesson_print_page_actions($cm->id, $page->id, $npages);
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")) {
echo "<tr><td colspan=\"2\" align=\"center\"><b>\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 "</b></td></tr>\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 "<tr><td align=\"right\" valign=\"top\" width=\"20%\">\n";
if ($lesson->custom) {
// if the score is > 0, then it is correct
if ($answer->score > 0) {
echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
} else {
echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
}
} else {
if (lesson_iscorrect($page->id, $answer->jumpto)) {
// underline correct answers
echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
} else {
echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
}
}
echo "</td><td width=\"80%\">\n";
echo format_text($answer->answer, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
echo "<tr><td align=\"right\" valign=\"top\"><b>".get_string("response", "lesson")." $i:</b> \n";
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) {
echo "<tr><td align=\"right\" valign=\"top\"><b>".get_string("correctresponse", "lesson").":</b> \n";
echo "</td><td>\n";
echo format_text($answer->answer, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
} else {
echo "<tr><td align=\"right\" valign=\"top\"><b>".get_string("wrongresponse", "lesson").":</b> \n";
echo "</td><td>\n";
echo format_text($answer->answer, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
}
}
$n++;
$i--;
} else {
echo "<tr><td align=\"right\" valign=\"top\" width=\"20%\">\n";
if ($lesson->custom) {
// if the score is > 0, then it is correct
if ($answer->score > 0) {
echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
} else {
echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
}
} else {
if (lesson_iscorrect($page->id, $answer->jumpto)) {
// underline correct answers
echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
} else {
echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
}
}
echo "</td><td width=\"80%\">\n";
echo format_text($answer->answer, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
echo "<tr><td align=\"right\" valign=\"top\"><b>".get_string("matchesanswer", "lesson")." $i:</b> \n";
echo "</td><td>\n";
echo format_text($answer->response, FORMAT_MOODLE, $options);
echo "</td></tr>\n";
}
break;
case LESSON_BRANCHTABLE:
echo "<tr><td align=\"right\" valign=\"top\" width=\"20%\">\n";
echo "<b>".get_string("description", "lesson")." $i:</b> \n";
echo "</td><td width=\"80%\">\n";
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) {
echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("correctanswerscore", "lesson").":";
echo "</b></td><td width=\"80%\">\n";
echo "$answer->score</td></tr>\n";
echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("correctanswerjump", "lesson").":";
echo "</b></td><td width=\"80%\">\n";
echo "$jumptitle</td></tr>\n";
} elseif ($i == 2) {
echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("wronganswerscore", "lesson").":";
echo "</b></td><td width=\"80%\">\n";
echo "$answer->score</td></tr>\n";
echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("wronganswerjump", "lesson").":";
echo "</b></td><td width=\"80%\">\n";
echo "$jumptitle</td></tr>\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 "<tr><td align=\"right\" width=\"20%\"><b>".get_string("score", "lesson")." $i:";
echo "</b></td><td width=\"80%\">\n";
echo "$answer->score</td></tr>\n";
}
echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("jump", "lesson")." $i:";
echo "</b></td><td width=\"80%\">\n";
echo "$jumptitle</td></tr>\n";
}
$i++;
}
}
echo "</table></td></tr>\n<tr><td align=\"left\">";
lesson_print_add_links($cm->id, $page->id);
echo "<tr><td>\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);
if ($CFG->debug) {
echo "<p>***prevpageid of page $page->id set to $prevpageid***";
}
}
if (count($pages) == 1) {
break;
}
$prevpageid = $page->id;
$pageid = $page->nextpageid;
}
echo "</table>";
break;
}
}
print_footer($course);

View File

@ -210,12 +210,13 @@ if (!defined("LESSON_RESPONSE_EDITOR")) {
/**
* Print the standard header for lesson module
*
* @uses $CFG
* @uses $USER
* @param object $cm Course module record object
* @param object $course Couse record object
* @param object $lesson Lesson module record object
* @param string $currenttab Current tab for the lesson tabs
* @param boolean $printheading Print the a heading with the lesson name
* @return void
* @return boolean
**/
function lesson_print_header($cm, $course, $lesson, $currenttab = '') {
global $CFG, $USER;
@ -289,6 +290,8 @@ function lesson_print_header($cm, $course, $lesson, $currenttab = '') {
}
lesson_print_messages();
return true;
}
/**
@ -382,6 +385,13 @@ function lesson_print_messages() {
*
* If Javascript is disabled, then a regular submit button is printed
*
* @param string $name Name of the link or button
* @param string $form The name of the form to be submitted
* @param string $align Alignment of the button
* @param string $class Class names to add to the div wrapper
* @param string $title Title for the link (Not used if javascript is disabled)
* @param string $id ID tag
* @param boolean $return Return flag
* @return mixed boolean/html
**/
function lesson_print_submit_link($name, $form, $align = 'center', $class='standardbutton', $title = '', $id = '', $return = false) {
@ -448,6 +458,169 @@ function lesson_print_time_remaining($starttime, $maxtime, $return = false) {
}
}
/**
* Prints the page action buttons
*
* Move/Edit/Preview/Delete
*
* @uses $CFG
* @param int $cmid Course Module ID
* @param int $pageid Page record ID for which the actions affect
* @param boolean $printmove Flag to print the move button or not
* @param boolean $return Return flag
* @return mixed boolean/string
**/
function lesson_print_page_actions($cmid, $pageid, $printmove, $return = false) {
global $CFG;
$context = get_context_instance(CONTEXT_MODULE, $cmid);
$actions = array();
if (has_capability('mod/lesson:edit', $context)) {
if ($printmove) {
$actions[] = "<a title=\"".get_string('move')."\" href=\"$CFG->wwwroot/mod/lesson/lesson.php?id=$cmid&action=move&pageid=$pageid\">
<img src=\"$CFG->pixpath/t/move.gif\" height=\"11\" width=\"11\" alt=\"".get_string('move')."\" border=\"0\" /></a>\n";
}
$actions[] = "<a title=\"".get_string('update')."\" href=\"$CFG->wwwroot/mod/lesson/lesson.php?id=$cmid&amp;action=editpage&amp;pageid=$pageid\">
<img src=\"$CFG->pixpath/t/edit.gif\" height=\"11\" width=\"11\" alt=\"".get_string('update')."\" border=\"0\" /></a>\n";
$actions[] = "<a title=\"".get_string('preview')."\" href=\"$CFG->wwwroot/mod/lesson/view.php?id=$cmid&amp;pageid=$pageid\">
<img src=\"$CFG->pixpath/t/preview.gif\" height=\"11\" width=\"11\" alt=\"".get_string('preview')."\" border=\"0\" /></a>\n";
$actions[] = "<a title=\"".get_string('delete')."\" href=\"$CFG->wwwroot/mod/lesson/lesson.php?id=$cmid&amp;sesskey=".sesskey()."&amp;action=confirmdelete&amp;pageid=$pageid\">
<img src=\"$CFG->pixpath/t/delete.gif\" height=\"11\" width=\"11\" alt=\"".get_string('delete')."\" border=\"0\" /></a>\n";
}
$actions = implode(' ', $actions);
if ($return) {
return $actions;
} else {
echo $actions;
return false;
}
}
/**
* Prints the add links in expanded view or single view when editing
*
* @uses $CFG
* @param int $cmid Course Module ID
* @param int $prevpageid Previous page id
* @param boolean $return Return flag
* @return mixed boolean/string
* @todo &amp;pageid does not make sense, it is prevpageid
**/
function lesson_print_add_links($cmid, $prevpageid, $return = false) {
global $CFG;
$context = get_context_instance(CONTEXT_MODULE, $cmid);
$links = '';
if (has_capability('mod/lesson:edit', $context)) {
$links = array();
$links[] = "<a href=\"$CFG->wwwroot/mod/lesson/import.php?id=$cmid&amp;pageid=$prevpageid\">".
get_string('importquestions', 'lesson').'</a>';
$links[] = "<a href=\"$CFG->wwwroot/mod/lesson/lesson.php?id=$cmid&amp;sesskey=".sesskey()."&amp;action=addcluster&amp;pageid=$prevpageid\">".
get_string('addcluster', 'lesson').'</a>';
if ($prevpageid != 0) {
$links[] = "<a href=\"$CFG->wwwroot/mod/lesson/lesson.php?id=$cmid&amp;sesskey=".sesskey()."&amp;action=addendofcluster&amp;pageid=$prevpageid\">".
get_string('addendofcluster', 'lesson').'</a>';
}
$links[] = "<a href=\"$CFG->wwwroot/mod/lesson/lesson.php?id=$cmid&amp;action=addbranchtable&amp;pageid=$prevpageid\">".
get_string('addabranchtable', 'lesson').'</a>';
if ($prevpageid != 0) {
$links[] = "<a href=\"$CFG->wwwroot/mod/lesson/lesson.php?id=$cmid&amp;sesskey=".sesskey()."&amp;action=addendofbranch&amp;pageid=$prevpageid\">".
get_string('addanendofbranch', 'lesson').'</a>';
}
$links[] = "<a href=\"$CFG->wwwroot/mod/lesson/lesson.php?id=$cmid&amp;action=addpage&amp;pageid=$prevpageid\">".
get_string('addaquestionpagehere', 'lesson').'</a>';
$links = implode(" | \n", $links);
$links = "\n<div class=\"addlinks\">\n$links\n</div>\n";
}
if ($return) {
return $links;
} else {
echo $links;
return true;
}
}
/**
* Returns the string for a page type
*
* @uses $LESSON_QUESTION_TYPE
* @param int $qtype Page type
* @return string
**/
function lesson_get_qtype_name($qtype) {
global $LESSON_QUESTION_TYPE;
switch ($qtype) {
case LESSON_ESSAY :
case LESSON_SHORTANSWER :
case LESSON_MULTICHOICE :
case LESSON_MATCHING :
case LESSON_TRUEFALSE :
case LESSON_NUMERICAL :
return $LESSON_QUESTION_TYPE[$qtype];
break;
case LESSON_BRANCHTABLE :
return get_string("branchtable", "lesson");
break;
case LESSON_ENDOFBRANCH :
return get_string("endofbranch", "lesson");
break;
case LESSON_CLUSTER :
return get_string("clustertitle", "lesson");
break;
case LESSON_ENDOFCLUSTER :
return get_string("endofclustertitle", "lesson");
break;
default:
return '';
break;
}
}
/**
* Returns the string for a jump name
*
* @param int $jumpto Jump code or page ID
* @return string
**/
function lesson_get_jump_name($jumpto) {
if ($jumpto == 0) {
$jumptitle = get_string('thispage', 'lesson');
} elseif ($jumpto == LESSON_NEXTPAGE) {
$jumptitle = get_string('nextpage', 'lesson');
} elseif ($jumpto == LESSON_EOL) {
$jumptitle = get_string('endoflesson', 'lesson');
} elseif ($jumpto == LESSON_UNSEENBRANCHPAGE) {
$jumptitle = get_string('unseenpageinbranch', 'lesson');
} elseif ($jumpto == LESSON_PREVIOUSPAGE) {
$jumptitle = get_string('previouspage', 'lesson');
} elseif ($jumpto == LESSON_RANDOMPAGE) {
$jumptitle = get_string('randompageinbranch', 'lesson');
} elseif ($jumpto == LESSON_RANDOMBRANCH) {
$jumptitle = get_string('randombranch', 'lesson');
} elseif ($jumpto == LESSON_CLUSTERJUMP) {
$jumptitle = get_string('clusterjump', 'lesson');
} else {
if (!$jumptitle = get_field('lesson_pages', 'title', 'id', $jumpto)) {
$jumptitle = '<strong>'.get_string('notdefined', 'lesson').'</strong>';
}
}
return format_string($jumptitle,true);
}
/**
* Given some question info and some data about the the answers
* this function parses, organises and saves the question
@ -1362,85 +1535,6 @@ function lesson_print_tree_link_menu($page, $id, $showpages=false) {
$output .= "</li>";
echo $output;
}
/**
* Prints out the tree view list.
*
* Each page in the lesson is printed out as a link. If the page is a branch table
* or an end of branch then the link color changes and the answer jumps are also printed
* alongside the links. Also, the editing buttons (move, update, delete) are printed
* next to the links.
*
* @uses $USER
* @uses $CFG
* @param int $pageid Page id of the first page of the lesson.
* @param object $lesson Object of the current lesson.
* @param int $cmid The course module id of the lesson.
* @param string $pixpath Path to the pictures.
* @todo $pageid does not need to be passed. Can be found in the function.
* This function is only called once. It should be removed and the code inside it moved to view.php
*/
function lesson_print_tree($pageid, $lesson, $cmid) {
global $USER, $CFG;
$context = get_context_instance(CONTEXT_MODULE, $cmid);
if(!$pages = get_records_select("lesson_pages", "lessonid = $lesson->id")) {
error("Error: could not find lesson pages");
}
echo "<table>";
while ($pageid != 0) {
echo "<tr><td>";
if(($pages[$pageid]->qtype != LESSON_BRANCHTABLE) && ($pages[$pageid]->qtype != LESSON_ENDOFBRANCH)) {
$output = "<a style='color:#DF041E;' href=\"$CFG->wwwroot/mod/lesson/edit.php?id=$cmid&display=".$pages[$pageid]->id."\">".format_string($pages[$pageid]->title,true)."</a>\n";
} else {
$output = "<a href=\"$CFG->wwwroot/mod/lesson/edit.php?id=$cmid&display=".$pages[$pageid]->id."\">".format_string($pages[$pageid]->title,true)."</a>\n";
if($answers = get_records_select("lesson_answers", "lessonid = $lesson->id and pageid = $pageid")) {
$output .= "Jumps to: ";
$end = end($answers);
foreach ($answers as $answer) {
if ($answer->jumpto == 0) {
$output .= get_string("thispage", "lesson");
} elseif ($answer->jumpto == LESSON_NEXTPAGE) {
$output .= get_string("nextpage", "lesson");
} elseif ($answer->jumpto == LESSON_EOL) {
$output .= get_string("endoflesson", "lesson");
} elseif ($answer->jumpto == LESSON_UNSEENBRANCHPAGE) {
$output .= get_string("unseenpageinbranch", "lesson");
} elseif ($answer->jumpto == LESSON_PREVIOUSPAGE) {
$output .= get_string("previouspage", "lesson");
} elseif ($answer->jumpto == LESSON_RANDOMPAGE) {
$output .= get_string("randompageinbranch", "lesson");
} elseif ($answer->jumpto == LESSON_RANDOMBRANCH) {
$output .= get_string("randombranch", "lesson");
} elseif ($answer->jumpto == LESSON_CLUSTERJUMP) {
$output .= get_string("clusterjump", "lesson");
} else {
$output .= format_string($pages[$answer->jumpto]->title);
}
if ($answer->id != $end->id) {
$output .= ", ";
}
}
}
}
echo $output;
if (has_capability('mod/lesson:edit', $context)) {
if (count($pages) > 1) {
echo "<a title=\"move\" href=\"lesson.php?id=$cmid&action=move&pageid=".$pages[$pageid]->id."\">\n".
"<img src=\"$CFG->pixpath/t/move.gif\" hspace=\"2\" height=11 width=11 alt=\"move\" border=0></a>\n";
}
echo "<a title=\"update\" href=\"lesson.php?id=$cmid&amp;action=editpage&amp;pageid=".$pages[$pageid]->id."\">\n".
"<img src=\"$CFG->pixpath/t/edit.gif\" hspace=\"2\" height=11 width=11 alt=\"edit\" border=0></a>\n".
"<a title=\"delete\" href=\"lesson.php?id=$cmid&amp;sesskey=".$USER->sesskey."&amp;action=confirmdelete&amp;pageid=".$pages[$pageid]->id."\">\n".
"<img src=\"$CFG->pixpath/t/delete.gif\" hspace=\"2\" height=11 width=11 alt=\"delete\" border=0></a>\n";
}
echo "</tr></td>";
$pageid = $pages[$pageid]->nextpageid;
}
echo "</table>";
}
/**
@ -1654,7 +1748,6 @@ function lesson_check_nickname($name) {
* @param object $lesson The lesson that the user is currently taking.
* @param object $course The course that the to which the lesson belongs.
* @return boolean The return is not significant as of yet. Will return true/false.
* @author Mark Nielsen
**/
function lesson_print_progress_bar($lesson, $course) {
global $CFG, $USER;
@ -1763,7 +1856,6 @@ function lesson_print_progress_bar($lesson, $course) {
*
* @param object $lesson Lesson object of the current lesson
* @return boolean 0 if the user cannot see, or $lesson->displayleft to keep displayleft unchanged
* @author Mark Nielsen
**/
function lesson_displayleftif($lesson) {
global $CFG, $USER;

View File

@ -1,11 +1,15 @@
/***
*** Style for page contents (display to student)
*** General styles (scope: all of lesson)
***/
.mod-lesson .contents {
text-align: left;
}
.mod-lesson .addlinks {
font-size: .8em;
}
/***
*** Style for view.php
***/

View File

@ -61,6 +61,7 @@
break;
case 'collapsed':
case 'full':
case 'single':
/// sub tabs for edit view (collapsed and expanded aka full)
$inactive[] = 'edit';