course)) { error("Course is misconfigured"); } if (! $lesson = get_record("lesson", "id", $cm->instance)) { error("Course module is incorrect"); } require_login($course->id); /// Print the page header if ($course->category) { $navigation = "id\">$course->shortname ->"; } $strlessons = get_string("modulenameplural", "lesson"); $strlesson = get_string("modulename", "lesson"); print_header("$course->shortname: $lesson->name", "$course->fullname", "$navigation id>$strlessons -> id\">$lesson->name", "", "", true, update_module_button($cm->id, $course->id, $strlesson), navmenu($course, $cm)); // set up some general variables $usehtmleditor = can_use_html_editor(); $path = "$CFG->wwwroot/course"; if (empty($THEME->custompix)) { $pixpath = "$path/../pix"; } else { $pixpath = "$path/../theme/$CFG->theme/pix"; } if (empty($action)) { if (isteacher($course->id)) { $action = 'teacherview'; } else { $action = 'navigation'; } } /************** navigation **************************************/ if ($action == 'navigation') { // display individual pages and their sets of answers // if pageid is EOL then the end of the lesson has been reached print_heading($lesson->name); if (empty($pageid)) { add_to_log($course->id, "lesson", "start", "view.php?id=$cm->id", "$lesson->id", $cm->id); // if no pageid given see if the lesson has been started if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND userid = $USER->id", "grade DESC")) { $retries = count($grades); } else { $retries = 0; } if ($retries) { print_heading(get_string("attempt", "lesson", $retries + 1)); } // if there are any questions have been answered correctly in this attempt if ($attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $retries AND correct = 1", "timeseen DESC")) { // get the first page if (!$firstpageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { error("Navigation: first page not found"); } foreach ($attempts as $attempt) { $jumpto = get_field("lesson_answers", "jumpto", "id", $attempt->answerid); // convert the jumpto to a proper page id if ($jumpto == 0) { // unlikely value! $lastpageseen = $attempt->pageid; } elseif ($jumpto == LESSON_NEXTPAGE) { if (!$lastpageseen = get_field("lesson_pages", "nextpageid", "id", $attempt->pageid)) { // no nextpage go to end of lesson $lastpageseen = LESSON_EOL; } } else { $lastpageseen = $jumpto; } break; // only look at the latest correct attempt } if ($lastpageseen != $firstpageid) { echo "
\n"; echo "id\">\n"; echo "\n"; echo "\n"; print_simple_box("

".get_string("youhaveseen","lesson")."

", "center"); echo "

   

\n"; echo "
\n"; print_footer($course); exit(); } } if ($grades) { foreach ($grades as $grade) { $bestgrade = $grade->grade; break; } if (!$lesson->retake) { redirect("../../course/view.php?id=$course->id", get_string("alreadytaken", "lesson")); // allow student to retake course even if they have the maximum grade // } elseif ($bestgrade == 100) { // redirect("../../course/view.php?id=$course->id", get_string("maximumgradeachieved", // "lesson")); } } // start at the first page if (!$pageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { error("Navigation: first page not found"); } } if ($pageid != LESSON_EOL) { add_to_log($course->id, "lesson", "view", "view.php?id=$cm->id", "$pageid", $cm->id); if (!$page = get_record("lesson_pages", "id", $pageid)) { error("Navigation: the page record not found"); } // before we output everything check to see if the page is a EOB, if so jump directly // to it's associated branch table if ($page->qtype == LESSON_ENDOFBRANCH) { if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { // print_heading(get_string("endofbranch", "lesson")); foreach ($answers as $answer) { // just need the first answer redirect("view.php?id=$cm->id&action=navigation&pageid=$answer->jumpto", get_string("endofbranch", "lesson")); break; } print_footer($course); exit(); } else { error("Navigation: No answers on EOB"); } } // it's not a EOB process it... echo ""; } echo '
\n"; if ($page->qtype == LESSON_BRANCHTABLE) { if ($lesson->minquestions and isstudent($course->id)) { // tell student how many questions they have seen, how many are required and their grade $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); $nviewed = count_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, "retry", $ntries); if ($nviewed) { echo "

".get_string("numberofpagesviewed", "lesson", $nviewed). "; (".get_string("youshouldview", "lesson", $lesson->minquestions).")
"; // count the number of distinct correct pages if ($correctpages = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries AND correct = 1")) { foreach ($correctpages as $correctpage) { $temp[$correctpage->pageid] = 1; } $ncorrect = count($temp); } else { $nccorrect = 0; } if ($nviewed < $lesson->minquestions) { $nviewed = $lesson->minquestions; } echo get_string("numberofcorrectanswers", "lesson", $ncorrect)."
\n"; $thegrade = intval(100 * $ncorrect / $nviewed); echo get_string("yourcurrentgradeis", "lesson", number_format($thegrade * $lesson->grade / 100, 1)). " (".get_string("outof", "lesson", $lesson->grade).")

\n"; } } } print_heading($page->title); print_simple_box(format_text($page->contents), 'center'); echo "
\n"; // get the answers in a set order, the id order if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { echo "
"; echo "id\">"; echo ""; echo ""; print_simple_box_start("center"); echo ''; switch ($page->qtype) { case LESSON_SHORTANSWER : case LESSON_NUMERICAL : echo "
".get_string("youranswer", "lesson"). ": \n"; echo '
'; print_simple_box_end(); echo "

\n"; break; case LESSON_TRUEFALSE : shuffle($answers); foreach ($answers as $answer) { echo "
"; echo "id}\">"; echo ""; $options->para = false; // no

echo format_text(trim($answer->answer), FORMAT_MOODLE, $options); echo "
'; print_simple_box_end(); echo "

\n"; break; case LESSON_MULTICHOICE : $i = 0; shuffle($answers); foreach ($answers as $answer) { echo ""; if ($page->qoption) { // more than one answer allowed echo "id}\">"; } else { // only one answer allowed echo "id}\">"; } echo ""; $options->para = false; // no

echo format_text(trim($answer->answer), FORMAT_MOODLE, $options); echo ""; $i++; } echo ''; print_simple_box_end(); if ($page->qoption) { echo "

\n"; } else { echo "

\n"; } break; case LESSON_MATCHING : echo ""; // don't suffle answers (could be an option??) foreach ($answers as $answer) { // get all the responses $responses[] = trim($answer->response); } shuffle($responses); foreach ($answers as $answer) { echo ""; } echo '
"; echo "$answer->answer: "; echo ""; echo "
'; print_simple_box_end(); echo "

\n"; break; case LESSON_BRANCHTABLE : echo ""; echo ""; // don't suffle answers foreach ($answers as $answer) { echo ""; } echo '
"; echo "answer\""; echo "onclick=\"document.answerform.jumpto.value=$answer->jumpto;document.answerform.submit();\">"; echo "
'; print_simple_box_end(); break; } echo "\n"; } else { // a page without answers - find the next (logical) page echo "
\n"; echo "id\">\n"; echo "\n"; if ($lesson->nextpagedefault) { // in Flash Card mode... // ...first get number of retakes $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); // ...then get the page ids (lessonid the 5th param is needed to make get_records play) $allpages = get_records("lesson_pages", "lessonid", $lesson->id, "id", "id,lessonid"); shuffle ($allpages); $found = false; if ($lesson->nextpagedefault == LESSON_UNSEENPAGE) { foreach ($allpages as $thispage) { if (!count_records("lesson_attempts", "pageid", $thispage->id, "userid", $USER->id, "retry", $nretakes)) { $found = true; break; } } } elseif ($lesson->nextpagedefault == LESSON_UNANSWEREDPAGE) { foreach ($allpages as $thispage) { if (!count_records_select("lesson_attempts", "pageid = $thispage->id AND userid = $USER->id AND correct = 1 AND retry = $nretakes")) { $found = true; break; } } } if ($found) { $newpageid = $thispage->id; if ($lesson->maxpages) { // check number of pages viewed (in the lesson) if (count_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, "retry", $nretakes) >= $lesson->maxpages) { $newpageid = LESSON_EOL; } } } else { $newpageid = LESSON_EOL; } } else { // in normal lesson mode... if (!$newpageid = get_field("lesson_pages", "nextpageid", "id", $pageid)) { // this is the last page - flag end of lesson $newpageid = LESSON_EOL; } } echo "\n"; echo "

\n"; echo "
\n"; } echo "\n"; } else { // end of lesson reached work out grade add_to_log($course->id, "lesson", "end", "view.php?id=$cm->id", "$lesson->id", $cm->id); print_heading(get_string("congratulations", "lesson")); print_simple_box_start("center"); $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); if (isstudent($course->id)) { if ($nviewed = count_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, "retry", $ntries)) { // count the number of distinct correct pages if ($correctpages = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries AND correct = 1")) { foreach ($correctpages as $correctpage) { $temp[$correctpage->pageid] = 1; } $ncorrect = count($temp); } else { $ncorrect = 0; } echo "

".get_string("numberofpagesviewed", "lesson", $nviewed). "

\n"; if ($lesson->minquestions) { if ($nviewed < $lesson->minquestions) { // print a warning and set nviewed to minquestions echo "

".get_string("youshouldview", "lesson", $lesson->minquestions)." ".get_string("pages", "lesson")."

\n"; $nviewed = $lesson->minquestions; } } echo "

".get_string("numberofcorrectanswers", "lesson", $ncorrect). "

\n"; $thegrade = intval(100 * $ncorrect / $nviewed); echo "

".get_string("gradeis", "lesson", number_format($thegrade * $lesson->grade / 100, 1)). " (".get_string("outof", "lesson", $lesson->grade).")

\n"; $grade->lessonid = $lesson->id; $grade->userid = $USER->id; $grade->grade = $thegrade; $grade->completed = time(); if (!$newgradeid = insert_record("lesson_grades", $grade)) { error("Navigation: grade not inserted"); } } else { print_string("noattemptrecordsfound", "lesson"); $thegrade = 0; } } else { // display for teacher echo "

".get_string("displayofgrade", "lesson")."

\n"; } print_simple_box_end(); print_continue("../../course/view.php?id=$course->id"); } } /*******************teacher view **************************************/ elseif ($action == 'teacherview') { print_heading_with_help($lesson->name, "overview", "lesson"); // get number of pages if ($page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) { $npages = 1; while (true) { if ($page->nextpageid) { if (!$page = get_record("lesson_pages", "id", $page->nextpageid)) { error("Teacher view: Next page not found!"); } } else { // last page reached break; } $npages++; } } if (!$page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) { // if there are no pages give teacher a blank proforma ?>
\n"; echo "\n"; for ($i = 0; $i < $lesson->maxanswers; $i++) { $iplus1 = $i + 1; echo "\n"; echo "\n"; if ($i) { // answers 2,3,4... jump to this page echo "\n"; } else { // answer 1 jumps to next page echo "\n"; } } // close table and form ?>

:

"; echo get_string("pagecontents", "lesson").":
\n"; print_textarea($usehtmleditor, 25, 70, 630, 400, "contents"); use_html_editor("contents"); echo "
".get_string("questiontype", "lesson").": \n"; choose_from_menu($LESSON_QUESTION_TYPE, "qtype", LESSON_MULTICHOICE, ""); helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson"); echo "
".get_string("questionoption", "lesson").":\n"; echo " "; helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); echo "
".get_string("answer", "lesson")." $iplus1:
\n"; print_textarea(false, 6, 70, 630, 100, "answer[$i]"); echo "
".get_string("response", "lesson")." $iplus1:
\n"; print_textarea(false, 6, 70, 630, 100, "response[$i]"); echo "

"> ">
id&pageid=0\">".get_string("importquestions", "lesson")."\n"); } else { // print the pages echo "
\n"; echo "id\">\n"; echo "\n"; echo "\n"; echo "
\n"; if (isteacheredit($course->id)) { echo "\n"; } echo "\n"; if (isteacheredit($course->id)) { echo "\n"; } echo "
id&pageid=0\">". get_string("importquestions", "lesson")." | ". "id&action=addbranchtable&pageid=0\">". get_string("addabranchtable", "lesson")." | ". "id&action=addpage&pageid=0\">". get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). "
\n"; while (true) { 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; foreach ($answers as $answer) { switch ($page->qtype) { case LESSON_MULTICHOICE: case LESSON_TRUEFALSE: case LESSON_SHORTANSWER: case LESSON_NUMERICAL: case LESSON_MATCHING: echo "\n"; echo "\n"; break; case LESSON_BRANCHTABLE: echo "\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"); } else { if (!$jumptitle = get_field("lesson_pages", "title", "id", $answer->jumpto)) { $jumptitle = "".get_string("notdefined", "lesson").""; } } echo "\n"; $i++; } // print_simple_box_end(); echo "\n"; } echo "
cellheading2\" colspan=\"2\">$page->title  \n"; if (isteacheredit($course->id)) { if ($npages > 1) { echo "id&action=move&pageid=$page->id\">\n". "\n"; } echo "id&action=editpage&pageid=$page->id\">\n". "\n". "id&action=confirmdelete&pageid=$page->id\">\n". "\n"; } echo "
\n"; print_simple_box(format_text($page->contents), "center"); echo "
cellheading2\" colspan=\"2\" align=\"center\">\n"; switch ($page->qtype) { 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]; if (!lesson_iscorrect($page->id, $answer->jumpto)) { 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; } echo "
cellheading2\" align=\"right\" valign=\"top\" width=\"20%\">\n"; 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); echo "
".get_string("response", "lesson")." $i: \n"; echo "\n"; echo format_text($answer->response); echo "
\n"; echo "".get_string("description", "lesson")." $i: \n"; echo "\n"; echo format_text($answer->answer); echo "
".get_string("jump", "lesson")." $i:"; echo "\n"; echo "$jumptitle
cellheading2\" colspan=\"2\" align=\"center\">"; if ($page->qtype != LESSON_ENDOFBRANCH) { echo "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 " 
id&pageid=$page->id\">". get_string("importquestions", "lesson")." | ". "id&action=addbranchtable&pageid=$page->id\">". get_string("addabranchtable", "lesson")." | "; // 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 "id&action=addendofbranch&pageid=$page->id\">". get_string("addanendofbranch", "lesson")." | "; } echo "id&action=addpage&pageid=$page->id\">". get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). "
\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 "

***prevpageid of page $page->id set to $prevpageid***"; } } } $prevpageid = $page->id; // move to next page if ($page->nextpageid) { if (!$page = get_record("lesson_pages", "id", $page->nextpageid)) { error("Teacher view: Next page not found!"); } } else { // last page reached break; } } echo "

\n"; print_heading("id&action=navigation\">".get_string("checknavigation", "lesson")."\n"); } } /*************** no man's land **************************************/ else { error("Fatal Error: Unknown Action: ".$action."\n"); } /// Finish the page print_footer($course); ?>