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 = ''. $course->shortname .' ->'; } $strlessons = get_string('modulenameplural', 'lesson'); $strlesson = get_string('modulename', 'lesson'); /// CDC-FLAG moved the action up because I needed to know what the action will be before the header is printed if (empty($action)) { if (isteacher($course->id)) { $action = 'teacherview'; } elseif (time() < $lesson->available) { print_header($course->shortname .': '. $lesson->name, $course->fullname, $navigation .''. $strlessons .' -> '. $lesson->name .'', '', "", true, '', navmenu($course, $cm)); print_simple_box_start('center'); echo '
'; $button .= ''; if ($action == 'navigation' && $pageid != LESSON_EOL) { $button .= ' | '. ''; } $button .= ' |
'; if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { // print the pages echo ''; } echo ' | ';
} elseif ($lesson->slideshow && $page->qtype == LESSON_BRANCHTABLE) {
echo '
|
| ||||||||
".get_string("youranswer", "lesson").": | ". "\n"; //CDC hidden label added. 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"; } else { $score = 0; $essayquestions = 0; $essayquestionpoints = 0; if ($useranswers = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries", "timeseen")) { // group each try with its page foreach ($useranswers as $useranswer) { $attemptset[$useranswer->pageid][] = $useranswer; } $pageids = array_keys($attemptset); $pageids = implode(",", $pageids); // get only the pages and their answers that the user answered $answeredpages = get_records_select("lesson_pages", "lessonid = $lesson->id AND id IN($pageids)"); $pageanswers = get_records_select("lesson_answers", "lessonid = $lesson->id AND pageid IN($pageids)"); foreach ($attemptset as $attempts) { if(count($attempts) > $lesson->maxattempts) { // if there are more tries than the max that is allowed, grab the last "legal" attempt $attempt = $attempts[$lesson->maxattempts - 1]; } else { // else, user attempted the question less than the max, so grab the last one $attempt = end($attempts); } // if essay question, handle it, otherwise add to score if ($answeredpages[$attempt->pageid]->qtype == LESSON_ESSAY) { $essayinfo = unserialize($attempt->useranswer); $score += $essayinfo->score; $essayquestions++; $essayquestionpoints += $pageanswers[$attempt->answerid]->score; } else { $score += $pageanswers[$attempt->answerid]->score; } } $bestscores = array(); // find the highest possible score per page foreach ($pageanswers as $pageanswer) { if(isset($bestscores[$pageanswer->pageid])) { if ($bestscores[$pageanswer->pageid] < $pageanswer->score) { $bestscores[$pageanswer->pageid] = $pageanswer->score; } } else { $bestscores[$pageanswer->pageid] = $pageanswer->score; } } $bestscore = array_sum($bestscores); } $thegrade = intval(100 * $score / $bestscore); unset($a); if ($essayquestions > 0) { $a->score = $score; $a->tempmaxgrade = $bestscore - $essayquestionpoints; $a->essayquestions = $essayquestions; $a->grade = $bestscore; echo "".get_string("gradeis", "lesson", number_format($thegrade * $lesson->grade / 100, 1)). " (".get_string("outof", "lesson", $lesson->grade).")
\n"; } /// CDC-FLAG /// $grade->lessonid = $lesson->id; $grade->userid = $USER->id; $grade->grade = $thegrade; $grade->completed = time(); if (!$lesson->practice) { if (isset($USER->modattempts[$lesson->id])) { // if reviewing, make sure update old grade record if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid = $USER->id", "completed")) { error("Could not find Grade Records"); } $oldgrade = end($grades); $grade->id = $oldgrade->id; if (!$update = update_record("lesson_grades", $grade)) { error("Navigation: grade not updated"); } } else { if (!$newgradeid = insert_record("lesson_grades", $grade)) { error("Navigation: grade not inserted"); } } } else { if (!delete_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, "retry", $ntries)) { error("Could not delete lesson attempts"); } } } else { //print_string("noattemptrecordsfound", "lesson"); if ($lesson->timed) { if (isset($_GET["outoftime"])) { if ($_GET["outoftime"] == "normal") { $grade->lessonid = $lesson->id; $grade->userid = $USER->id; $grade->grade = 0; $grade->completed = time(); if (!$lesson->practice) { if (!$newgradeid = insert_record("lesson_grades", $grade)) { error("Navigation: grade not inserted"); } } echo get_string("eolstudentoutoftimenoanswers", "lesson"); } } } else { echo get_string("welldone", "lesson"); } } } else { // display for teacher echo "".get_string("displayofgrade", "lesson")."
\n"; } print_simple_box_end(); //End of Lesson button to Continue. ///CDC-FLAG /// high scores code if ($lesson->highscores && !isteacher($course->id)) { echo "".get_string("reviewlesson", "lesson")."
\n"; } elseif ($lesson->modattempts && isteacher($course->id)) { echo "".get_string("modattemptsnoteacher", "lesson")."
"; } echo "id\">".get_string("mainmenu", "lesson")."
\n"; //CDC Back to the menu (course view). echo "id\">".get_string("viewgrades", "lesson")."
\n"; //CDC view grades } if ($lesson->displayleft || $lesson->slideshow) { // this ends the table cell and table for the leftmenu or for slideshow echo ""; } } /*******************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")) { /// CDC-FLAG /// // if there are no pages give teacher the option to create a new page or a new branch table echo "