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"; 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"); } echo "\n";
print_heading($page->title);
print_simple_box(format_text($page->contents), 'center');
echo " \n"; if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { echo " |
"; echo "$answer->answer: | "; echo ""; echo " |
\$thispageid: $thispageid; \$attempt->pageid: $attempt->pageid
\n"; $check = false; break; } if (!$answer = get_record("lesson_answers", "id", $attempt->answerid)) { error("Navigation Check: answer not found"); } if ($answer->jumpto) { if ($answer->jumpto == LESSON_NEXTPAGE) { if (!$thispageid = get_field("lesson_pages", "nextpageid", "id", $thispageid)) { $thispageid = LESSON_EOL; // end of foreach loop should have been reached } } else { $thispageid = $answer->jumpto; } } } } if ($check) { $ncorrect = count_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries AND correct = 1"); $nviewed = count_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, "retry", $ntries); if ($nviewed) { $thegrade = intval(100 * $ncorrect / $nviewed); } else { $thegrade = 0; } echo "".get_string("numberofpagesviewed", "lesson", $nviewed). "
\n"; echo "".get_string("numberofcorrectanswers", "lesson", $ncorrect). "
\n"; 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("sanitycheckfailed", "lesson"); delete_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, "retry", $ntries); } } else { print_string("noattemptrecordsfound", "lesson"); } } 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 ?> id&pageid=0\">".get_string("importquestions", "lesson")."\n"); } else { // print the pages 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); ?>