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 '
'; echo get_string('lessonopen', 'lesson', userdate($lesson->available)).'
'; echo ''. get_string('returnmainmenu', 'lesson') .''; echo '
'; print_simple_box_end(); print_footer($course); exit(); } elseif (time() > $lesson->deadline) { print_header($course->shortname .': '. $lesson->name, $course->fullname, "$navigation id\">$strlessons -> id\">$lesson->name", '', "", true, '', navmenu($course, $cm)); print_simple_box_start('center'); echo '
'; echo get_string('lessonclosed', 'lesson', userdate($lesson->deadline)) .'
'; echo ''. get_string('returnmainmenu', 'lesson') .''; echo '
'; print_simple_box_end(); print_footer($course); exit(); } elseif ($lesson->highscores) { $action = 'highscores'; } else { $action = 'navigation'; } } /// CDC-FLAG changed the update_module_button and added another button when a teacher is checking the navigation of the lesson if (isteacheredit($course->id)) { $button = '
'; $button .= '
'. ''. ''. ''. '
'; if ($action == 'navigation' && $pageid != LESSON_EOL) { $button .= '
'. '
'. ''. ''. ''. '
'; } $button .= '
'; } else { $button = ''; } print_header($course->shortname .': '. $lesson->name, $course->fullname, "$navigation id\">$strlessons -> id\">$lesson->name", '', "", true, $button, // took out update_module_button($cm->id, $course->id, $strlesson) and replaced it with $button 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'; } /************** navigation **************************************/ if ($action == 'navigation') { /// CDC-FLAG /// password protected lesson code if ($lesson->usepassword && !isteacher($course->id)) { $correctpass = false; if (isset($_POST['userpassword'])) { if ($lesson->password == md5(trim(clean_param($_POST['userpassword'], PARAM_CLEAN)))) { $USER->lessonloggedin[$lesson->id] = true; $correctpass = true; } } elseif (isset($USER->lessonloggedin[$lesson->id])) { $correctpass = true; } if (!$correctpass) { print_simple_box_start('center'); echo '
' . "\n"; echo '' . "\n"; echo '' . "\n"; echo ''; if (isset($_POST['userpassword'])) { echo "'; } echo ''; echo ''; echo '
".get_string('loginfail', 'lesson') .'
'. get_string('passwordprotectedlesson', 'lesson', $lesson->name) .'
'. get_string('enterpassword', 'lesson').'
'; echo ' '; echo ''; echo '
'; print_simple_box_end(); exit(); } } // this is called if a student leaves during a lesson if($pageid == LESSON_UNSEENBRANCHPAGE) { $pageid = lesson_unseen_question_jump($lesson->id, $USER->id, $pageid); } // display individual pages and their sets of answers // if pageid is EOL then the end of the lesson has been reached // for flow, changed to simple echo for flow styles, michaelp, moved lesson name and page title down //print_heading($lesson->name); $timedflag = false; $attemptflag = false; 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) { $attemptflag = true; } if (isset($USER->modattempts[$lesson->id])) { unset($USER->modattempts[$lesson->id]); // if no pageid, then student is NOT reviewing } // 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) { if (count_records('lesson_attempts', 'lessonid', $lesson->id, 'userid', $USER->id, 'retry', $retries) > 0) { /// CDC-FLAG /// if ($lesson->timed) { if ($lesson->retake) { echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; /// CDC-FLAG added this line print_simple_box('

'. get_string('leftduringtimed', 'lesson') .'

', 'center'); echo '

\n"; /// CDC-FLAG added document.queryform.startlastseen.value='yes' echo '
' . "\n"; echo '';///CDC Chris Berri added close div tag } else { print_simple_box_start('center'); echo '
'; echo get_string('leftduringtimednoretake', 'lesson'); echo '

'. get_string('returntocourse', 'lesson') .''; echo '
'; print_simple_box_end(); } } else { echo "
\n"; echo "id\" />\n"; echo "\n"; echo "\n"; echo "\n"; /// CDC-FLAG added this line print_simple_box("

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

', "center"); echo "

   

\n"; /// CDC-FLAG added document.queryform.startlastseen.value='yes' echo "
\n"; echo "";///CDC Chris Berri added close div tag } print_footer($course); exit(); } } if ($grades) { foreach ($grades as $grade) { $bestgrade = $grade->grade; break; } if (!$lesson->retake) { print_simple_box_start('center'); echo "
"; echo get_string("noretake", "lesson"); echo "

id\">".get_string('returntocourse', 'lesson').''; echo "
"; print_simple_box_end(); print_footer($course); exit(); //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'); } /// CDC-FLAG /// -- This is the code for starting a timed test if($lesson->timed && !isset($USER->startlesson[$lesson->id])) { unset($startlesson); $USER->startlesson[$lesson->id] = true; if($timeid = get_field('lesson_timer', 'id', 'lessonid', $lesson->id, 'userid', $USER->id)) { $startlesson->id = $timeid; } $startlesson->lessonid = $lesson->id; $startlesson->userid = $USER->id; $startlesson->starttime = time(); $startlesson->lessontime = time(); if (!update_record('lesson_timer', $startlesson)) { if (!insert_record('lesson_timer', $startlesson)) { error('Error: could not insert row into lesson_timer table'); } } $timedflag = true; } /// CDC-FLAG /// } if ($pageid != LESSON_EOL) { /// This is the code updates the lessontime for a timed test if (isset($_POST['startlastseen'])) { /// this deletes old records not totally sure if this is necessary anymore if ($_POST['startlastseen'] == 'no') { if ($grades = get_records_select('lesson_grades', "lessonid = $lesson->id AND userid = $USER->id", 'grade DESC')) { $retries = count($grades); } else { $retries = 0; } // NoticeFix big fix on the two delete_records if (!delete_records('lesson_attempts', 'userid', $USER->id, 'lessonid', $lesson->id, 'retry', $retries)) { error('Error: could not delete old attempts'); } if (!delete_records('lesson_branch', 'userid', $USER->id, 'lessonid', $lesson->id, 'retry', $retries)) { error('Error: could not delete old seen branches'); } } } 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'); } if ($page->qtype == LESSON_CLUSTER) { //this only gets called when a user starts up a new lesson and the first page is a cluster page if (!isteacher($course->id)) { // get new id $pageid = lesson_cluster_jump($lesson->id, $USER->id, $pageid); // get new page info if (!$page = get_record('lesson_pages', 'id', $pageid)) { error('Navigation: the page record not found'); } add_to_log($course->id, 'lesson', 'view', 'view.php?id='. $cm->id, $pageid, $cm->id); } else { // get the next page $pageid = $page->nextpageid; if (!$page = get_record('lesson_pages', 'id', $pageid)) { error('Navigation: the page record not found'); } } } elseif ($page->qtype == LESSON_ENDOFCLUSTER) { if ($page->nextpageid == 0) { $nextpageid = LESSON_EOL; } else { $nextpageid = $page->nextpageid; } redirect("view.php?id=$cm->id&action=navigation&pageid=$nextpageid", get_string('endofclustertitle', 'lesson')); } // start of left menu if ($lesson->displayleft) { echo '
'; if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { // print the pages echo '
'; echo ''; echo ''; echo ''; echo "cellheading\" width=\"140px\">"; echo "'; echo ""; echo '
".get_string('lessonmenu', 'lesson') .'
"; echo "id\">".get_string("mainmenu", "lesson")."
'; lesson_print_tree_menu($lesson->id, $firstpageid, $cm->id); echo '
'; //close lmlinks echo '
'; } echo '
'; } elseif ($lesson->slideshow && $page->qtype == LESSON_BRANCHTABLE) { echo '
'; // only want this if no left menu } // starts the slideshow div if($lesson->slideshow && $page->qtype == LESSON_BRANCHTABLE) { echo "
bgcolor; height: ".$lesson->height."px; width: ".$lesson->width."px; overflow: auto; border: 0px solid #ccc; padding-right: 16px; /* for the benefit of macIE5 only */ /* \ commented backslash hack - recover from macIE5 workarounds, it will ignore the following rule */ padding-right: 0; padding: 15px; \">\n"; echo ""; if ($answer != end($answers)) { echo ""; } $i++; } echo '
\n"; } else { echo ""; if ($answer != end($answers)) { echo ""; } } echo '
\n"; $lesson->slideshow = false; // turn off slide show for all pages other than LESSON_BRANTCHTABLE } // This is where several messages (usually warnings) are displayed // all of this is displayed above the actual page // clock code if($lesson->timed) { if(isteacher($course->id)) { echo '

'. get_string('teachertimerwarning', 'lesson') .'

'; } else { if (isset($_POST['startlastseen'])) { if ($_POST['startlastseen'] == 'yes') { // continue a previous test, need to update the clock (think this option is disabled atm) // get time information for this user if (!$timer = get_record('lesson_timer', 'lessonid', $lesson->id, 'userid', $USER->id)) { error('Error: could not find record'); } unset($continuelesson); $continuelesson->id = $timer->id; $continuelesson->starttime = time() - ($timer->lessontime - $timer->starttime); $continuelesson->lessontime = time(); if (!update_record('lesson_timer', $continuelesson)) { error("Error: could not update record in the lesson_timer table"); } } elseif ($_POST['startlastseen'] == 'no') { // starting over // get time information for this user if (!$timer = get_record('lesson_timer', 'lessonid', $lesson->id, 'userid', $USER->id)) { error('Error: could not find record'); } // starting over, so reset the clock unset($startlesson); $startlesson->id = $timer->id; $startlesson->starttime = time(); $startlesson->lessontime = time(); if (!update_record('lesson_timer', $startlesson)) { error('Error: could not update record in the lesson_timer table'); } } } // get time information for this user if (!$timer = get_record('lesson_timer', 'lessonid', $lesson->id, 'userid', $USER->id)) { error('Error: could not find record'); } if ((($timer->starttime + $lesson->maxtime * 60) - time()) > 0) { // code for the clock print_simple_box_start("right", "150px", "#ffffff", 0); echo "". "
".get_string("timeremaining", "lesson"). "
"; echo "\n"; echo "
"; print_simple_box_end(); echo "


"; } else { redirect("view.php?id=$cm->id&action=navigation&pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson")); } // update clock when viewing a new page... no special treatment if ((($timer->starttime + $lesson->maxtime * 60) - time()) < 60) { echo "

".get_string('studentoneminwarning', 'lesson')."

"; } unset($newtime); $newtime->id = $timer->id; $newtime->lessontime = time(); if (!update_record('lesson_timer', $newtime)) { error('Error: could not update lesson_timer table'); } if ($timedflag) { print_simple_box(get_string('maxtimewarning', 'lesson', $lesson->maxtime), 'center'); } } } if ($attemptflag) { print_heading(get_string('attempt', 'lesson', $retries + 1)); } // 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 /// CDC-FLAG 6/21/04 /// if ($answer->jumpto == LESSON_RANDOMBRANCH) { $answer->jumpto = lesson_unseen_branch_jump($lesson->id, $USER->id); } elseif ($answer->jumpto == LESSON_CLUSTERJUMP) { if (!isteacher($course->id)) { $answer->jumpto = lesson_cluster_jump($lesson->id, $USER->id, $pageid); } else { if ($page->nextpageid == 0) { $answer->jumpto = LESSON_EOL; } else { $answer->jumpto = $page->nextpageid; } } } /// CDC-FLAG /// 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'); } } /// This is the warning msg for teachers to inform them that cluster and unseen does not work while logged in as a teacher if(isteacher($course->id)) { if (execute_teacherwarning($lesson->id)) { $warningvars->cluster = get_string('clusterjump', 'lesson'); $warningvars->unseen = get_string('unseenpageinbranch', 'lesson'); echo '

'. get_string('teacherjumpwarning', 'lesson', $warningvars) .'

'; } } /// this calculates the ongoing score if ($lesson->ongoing && !empty($pageid)) { if (isteacher($course->id)) { echo "

".get_string('teacherongoingwarning', 'lesson').'

'; } else { $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); if (isset($USER->modattempts[$lesson->id])) { $ntries--; } lesson_calculate_ongoing_score($lesson, $USER->id, $ntries); } } 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"; } } } // now starting to print the page's contents echo "
"; echo ""; echo ($lesson->name) . ""; if ($page->qtype == LESSON_BRANCHTABLE) { echo ":
"; print_heading($page->title); } echo "

"; if ($lesson->slideshow) { echo format_text($page->contents); } else { print_simple_box(format_text($page->contents), 'center'); } echo "
\n"; // this is for modattempts option. Find the users previous answer to this page, // and then display it below in answer processing if (isset($USER->modattempts[$lesson->id])) { $retries = count_records('lesson_grades', "lessonid", $lesson->id, "userid", $USER->id); $retries--; if (! $attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND pageid = $page->id AND retry = $retries", "timeseen")) { error("Previous attempt record could not be found!"); } $attempt = end($attempts); } // 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 ""; echo "sesskey."\" />"; if (!$lesson->slideshow) { print_simple_box_start("center"); echo ''; } switch ($page->qtype) { case LESSON_SHORTANSWER : case LESSON_NUMERICAL : if (isset($USER->modattempts[$lesson->id])) { $value = "value=\"$attempt->useranswer\""; } else { $value = ""; } echo "
".get_string("youranswer", "lesson"). ": \n"; //CDC hidden label added. echo '
'; print_simple_box_end(); echo "

\n"; break; case LESSON_TRUEFALSE : shuffle($answers); foreach ($answers as $answer) { echo "
"; if (isset($USER->modattempts[$lesson->id]) && $answer->id == $attempt->answerid) { $checked = "checked=\"checked\""; } else { $checked = ""; } echo "id}\" $checked />"; //CDC hidden label added. 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) { $checked = ""; if (isset($USER->modattempts[$lesson->id])) { $answerids = explode(",", $attempt->useranswer); if (in_array($answer->id, $answerids)) { $checked = "checked=\"checked\""; } else { $checked = ""; } } // more than one answer allowed echo "id}\" $checked />"; //CDC hidden label added. } else { if (isset($USER->modattempts[$lesson->id]) && $answer->id == $attempt->answerid) { $checked = "checked=\"checked\""; } else { $checked = ""; } // only one answer allowed echo "id}\" $checked />"; //CDC hidden label added. } echo ""; $options->para = false; // no

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

'; print_simple_box_end(); if ($page->qoption) { echo "

\n"; } else { echo "

\n"; } break; /// CDC-FLAG /// 6/14/04 --- changed how matching works case LESSON_MATCHING : echo "
"; // don't suffle answers (could be an option??) foreach ($answers as $answer) { // get all the response if ($answer->response != NULL) { $responses[] = trim($answer->response); } } shuffle($responses); $responses = array_unique($responses); if (isset($USER->modattempts[$lesson->id])) { $useranswers = explode(",", $attempt->useranswer); $t = 0; } foreach ($answers as $answer) { if ($answer->response != NULL) { echo ""; if ($answer != end($answers)) { echo ""; } } } echo '
"; echo "$answer->answer: "; echo ""; echo "

'; print_simple_box_end(); echo "

\n"; break; case LESSON_BRANCHTABLE : if ($lesson->slideshow) { echo "
"; } else { echo "
"; } echo ""; $nextprevious = array(); $otherjumps = array(); // seperate out next and previous jumps from the other jumps foreach ($answers as $answer) { if($answer->jumpto == LESSON_NEXTPAGE || $answer->jumpto == LESSON_PREVIOUSPAGE) { $nextprevious[] = $answer; } else { $otherjumps[] = $answer; } } if ($page->layout) { echo ""; // next 3 foreach loops print out the links in correct order foreach ($nextprevious as $jump) { if ($jump->jumpto == LESSON_PREVIOUSPAGE) { echo ""; } } echo ""; foreach ($nextprevious as $jump) { if ($jump->jumpto == LESSON_NEXTPAGE) { echo ""; } } echo ""; } else { // next 3 foreach loops print out the links in correct order foreach ($nextprevious as $jump) { if ($jump->jumpto == LESSON_NEXTPAGE) { echo ""; } } foreach ($otherjumps as $otherjump) { echo ""; } foreach ($nextprevious as $jump) { if ($jump->jumpto == LESSON_PREVIOUSPAGE) { echo ""; } } } /* if(!$lesson->slideshow) { foreach ($answers as $answer) { echo ""; } }*/ if (!$lesson->slideshow) { echo '
jumpto;document.answerform.submit();\"". "value = \"$jump->answer\" />"; foreach ($otherjumps as $otherjump) { echo ""; } echo "
jumpto;document.answerform.submit();\"". "value = \"$otherjump->answer\" />
jumpto;document.answerform.submit();\"". "value = \"$jump->answer\" />
jumpto;document.answerform.submit();\"". "value = \"$jump->answer\" />
jumpto;document.answerform.submit();\"". "value = \"$otherjump->answer\" />
jumpto;document.answerform.submit();\"". "value = \"$jump->answer\" />
"; echo "answer\""; echo "onclick=\"document.answerform.jumpto.value=$answer->jumpto;document.answerform.submit();\" />"; echo "
'; print_simple_box_end(); } break; case LESSON_ESSAY : if (isset($USER->modattempts[$lesson->id])) { $essayinfo = unserialize($attempt->useranswer); $value = $essayinfo->answer; } else { $value = ""; } echo "
".get_string("youranswer", "lesson").":". "\n"; //CDC hidden label added. echo "
"; print_simple_box_end(); echo "

\n"; 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 /// CDC-FLAG /// if ($lesson->timed && !isteacher($course->id)) { unset($USER->startlesson[$lesson->id]); // take this variable out that I put in for timed tests if (isset($_GET["outoftime"])) { if ($_GET["outoftime"] == "normal") { print_simple_box(get_string("eolstudentoutoftime", "lesson"), "center"); } } } if (isset($USER->lessonloggedin[$lesson->id])) { unset($USER->lessonloggedin[$lesson->id]); } 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 (isset($USER->modattempts[$lesson->id])) { $ntries--; // need to look at the old attempts :) } if (isstudent($course->id)) { if ($nviewed = count_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, "retry", $ntries)) { /// CDC-FLAG /// 6/11/04 if (!$lesson->custom) { $ncorrect = 0; if ($pagesanswered = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries order by timeseen")) { foreach ($pagesanswered as $pageanswered) { if (@!array_key_exists($pageanswered->pageid, $temp)) { $temp[$pageanswered->pageid] = array($pageanswered->correct, 1); } else { if ($temp[$pageanswered->pageid][1] < $lesson->maxattempts) { $n = $temp[$pageanswered->pageid][1] + 1; $temp[$pageanswered->pageid] = array($pageanswered->correct, $n); } } } foreach ($temp as $value => $key) { if ($key[0] == 1) { $ncorrect += 1; } } } $nviewed = count($temp); // this counts number of Questions the user viewed 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("displayscorewithessays", "lesson", $a)."
"; } else { $a->score = $score; $a->grade = $bestscore; echo "
".get_string("displayscorewithoutessays", "lesson", $a)."
"; } 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 "

"; if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id", "completed")) { echo get_string("youmadehighscore", "lesson", $lesson->maxhighscores)."
"; echo "id&action=nameforhighscores\">".get_string("clicktopost", "lesson")."
"; } else { if (!$highscores = get_records_select("lesson_high_scores", "lessonid = $lesson->id")) { echo get_string("youmadehighscore", "lesson", $lesson->maxhighsores)."
"; echo "id&action=nameforhighscores\">".get_string("clicktopost", "lesson")."
"; } else { // get all the high scores into an array foreach ($highscores as $highscore) { $grade = $grades[$highscore->gradeid]->grade; $topscores[] = $grade; } // sort to find the lowest score sort($topscores); $lowscore = $topscores[0]; if ($thegrade >= $lowscore || count($topscores) <= $lesson->maxhighscores) { echo get_string("youmadehighscore", "lesson", $lesson->maxhighscores)."
"; echo "id&action=nameforhighscores\">".get_string("clicktopost", "lesson")."
"; } else { echo get_string("nothighscore", "lesson", $lesson->maxhighscores)."
"; } } } echo "
id&action=highscores&link=1\">".get_string("viewhighscores", "lesson").""; echo "
"; } /// CDC-FLAG /// if ($lesson->modattempts && !isteacher($course->id)) { // make sure if the student is reviewing, that he/she sees the same pages/page path that he/she saw the first time // look at the attempt records to find the first QUESTION page that the user answered, then use that page id // to pass to view again. This is slick cause it wont call the empty($pageid) code // $ntries is decremented above $attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries", "timeseen"); $firstattempt = current($attempts); $pageid = $firstattempt->pageid; // IF the student wishes to review, need to know the last question page that the student answered. This will help to make // sure that the student can leave the lesson via pushing the continue button. $lastattempt = end($attempts); $USER->modattempts[$lesson->id] = $lastattempt->pageid; echo "
id\">"; echo ""; echo "
"; 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 "
"; if (isteacheredit($course->id)) { print_simple_box( "\n"; //CDC Chris Berri added. /// CDC-FLAG /// } else { // print the pages echo "\n"; echo "id\" />\n"; echo "\n"; echo "\n"; /// CDC-FLAG /// link to grade essay questions and to report if ($testattempts = get_records("lesson_attempts", "lessonid", $lesson->id)) { // just check to see if anyone has answered any questions. echo "
id\">".get_string("viewlessonstats", "lesson")."
"; } if ($essaypages = get_records_select("lesson_pages", "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { // get pages that are essay // get only the attempts that are in response to essay questions $essaypageids = implode(",", array_keys($essaypages)); // all the pageids in comma seperated list if ($essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($essaypageids)")) { echo "
id&action=essayview\">".get_string("gradeessay", "lesson")."

"; } } /// CDC-FLAG /// tree code - in final release, will use lang file for all text output. // NoticeFix next two lines and bowth viewAlls $branch = false; $singlePage = false; if($lesson->tree && !isset($_GET['display']) && !isset($_GET['viewAll'])) { echo "
"; echo get_string("treeview", "lesson")."

"; echo "".get_string("viewallpages", "lesson")."

\n"; echo "
".get_string("whatdofirst", "lesson")."
". "id&pageid=0\">". get_string("importquestions", "lesson")."
". "id&action=addbranchtable&pageid=0&firstpage=1\">". get_string("addabranchtable", "lesson")."
". "id&action=addpage&pageid=0&firstpage=1\">". get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). "
"; lesson_print_tree($page->id, $lesson->id, $cm->id, $pixpath); echo "
"; echo "
".get_string("viewallpages", "lesson")."\n"; echo "
"; } else { if(isset($_GET['display']) && !isset($_GET['viewAll'])) { $display = clean_param($_GET['display'], PARAM_INT); 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 "
".get_string("viewallpages", "lesson")."
\n"; echo "".get_string("backtreeview", "lesson")."
\n"; echo "\n"; if (isteacheredit($course->id)) { /// CDC-FLAG 6/16/04 /// echo "\n"; /// CDC-FLAG /// } } else { if($lesson->tree) { echo "
".get_string("backtreeview", "lesson")."
\n"; } echo "
id&pageid=$page->prevpageid\">". get_string("importquestions", "lesson")." | ". "id&sesskey=".$USER->sesskey."&action=addcluster&pageid=$page->prevpageid\">". get_string("addcluster", "lesson")." | ". "id&sesskey=".$USER->sesskey."&action=addendofcluster&pageid=$page->prevpageid\">". get_string("addendofcluster", "lesson")." | ". "id&action=addbranchtable&pageid=$page->prevpageid\">". get_string("addabranchtable", "lesson")." | ". "id&action=addpage&pageid=$page->prevpageid\">". get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). "
\n"; if (isteacheredit($course->id)) { /// CDC-FLAG 6/16/04 /// echo "\n"; /// CDC-FLAG /// } } /// CDC-FLAG /// end tree code (note, there is an "}" below for an else above) while (true) { echo "\n"; if (isteacheredit($course->id)) { /// CDC-FLAG /// 6/16/04 echo "\n"; } // echo "
id&pageid=0\">". get_string("importquestions", "lesson")." | ". "id&sesskey=".$USER->sesskey."&action=addcluster&pageid=0\">". get_string("addcluster", "lesson")." | ". "id&action=addbranchtable&pageid=0\">". get_string("addabranchtable", "lesson")." | ". "id&action=addpage&pageid=0\">". get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). "
\n"; 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; $n = 0; foreach ($answers as $answer) { switch ($page->qtype) { case LESSON_MULTICHOICE: case LESSON_TRUEFALSE: case LESSON_SHORTANSWER: case LESSON_NUMERICAL: echo "\n"; echo "\n"; break; case LESSON_MATCHING: if ($n < 2) { if ($answer->answer != NULL) { if ($n == 0) { echo "\n"; } else { echo "\n"; } } $n++; $i--; } else { 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"); /* CDC-FLAG 6/17/04 */ } elseif ($answer->jumpto == LESSON_UNSEENBRANCHPAGE) { $jumptitle = get_string("unseenpageinbranch", "lesson"); // a better way is get_string("unseenbranchpage", "lesson"); and define in lang file } 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"); /// CDC-FLAG /// } else { if (!$jumptitle = get_field("lesson_pages", "title", "id", $answer->jumpto)) { $jumptitle = "".get_string("notdefined", "lesson").""; } } /// CDC-FLAG /// if ($page->qtype == LESSON_MATCHING) { if ($i == 1) { echo "\n"; echo "\n"; } elseif ($i == 2) { echo "\n"; echo "\n"; } } else { if ($lesson->custom && $page->qtype != LESSON_BRANCHTABLE && $page->qtype != LESSON_ENDOFBRANCH) { echo "\n"; } echo "\n"; } $i++; } // print_simple_box_end(); /// CDC-FLAG /// not sure if i commented this out... hehe echo "\n"; } echo "
cellheading2\" colspan=\"2\">$page->title  \n"; if (isteacheredit($course->id)) { if ($npages > 1) { echo "id&action=move&pageid=$page->id\">\n". "\"move\"\n"; } echo "id&action=editpage&pageid=$page->id\">\n". "\"edit\"\n". "id&sesskey=".$USER->sesskey."&action=confirmdelete&pageid=$page->id\">\n". "\"delete\"\n"; } echo "
\n"; print_simple_box(format_text($page->contents), "center"); echo "
cellheading2\" colspan=\"2\" align=\"center\">\n"; switch ($page->qtype) { case LESSON_ESSAY : /// CDC-FLAG /// 6/16/04 this line and the next 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; } echo "
cellheading2\" align=\"right\" valign=\"top\" width=\"20%\">\n"; /// CDC-FLAG /// 6/11/04 if ($lesson->custom) { // if the score is > 0, then it is correct if ($answer->score > 0) { echo "".get_string("answer", "lesson")." $i: \n"; } else { echo "".get_string("answer", "lesson")." $i: \n"; } } else { 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"; } } /// CDC-FLAG /// echo "\n"; echo format_text($answer->answer); echo "
".get_string("response", "lesson")." $i: \n"; echo "\n"; echo format_text($answer->response); echo "
".get_string("correctresponse", "lesson").": \n"; echo "\n"; echo format_text($answer->answer); echo "
".get_string("wrongresponse", "lesson").": \n"; echo "\n"; echo format_text($answer->answer); echo "
cellheading2\" align=\"right\" valign=\"top\" width=\"20%\">\n"; if ($lesson->custom) { // if the score is > 0, then it is correct if ($answer->score > 0) { echo "".get_string("answer", "lesson")." $i: \n"; } else { echo "".get_string("answer", "lesson")." $i: \n"; } } else { 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("matchesanswer", "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("correctanswerscore", "lesson").":"; echo "\n"; echo "$answer->score
".get_string("correctanswerjump", "lesson").":"; echo "\n"; echo "$jumptitle
".get_string("wronganswerscore", "lesson").":"; echo "\n"; echo "$answer->score
".get_string("wronganswerjump", "lesson").":"; echo "\n"; echo "$jumptitle
".get_string("score", "lesson")." $i:"; echo "\n"; echo "$answer->score
".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&sesskey=".$USER->sesskey."&action=addcluster&pageid=$page->id\">". get_string("addcluster", "lesson")." | ". "id&sesskey=".$USER->sesskey."&action=addendofcluster&pageid=$page->id\">". get_string("addendofcluster", "lesson")." | ". "id&action=addbranchtable&pageid=$page->id\">". get_string("addabranchtable", "lesson")."
"; /// CDC-FLAG /// // 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&sesskey=".$USER->sesskey."&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 /// CDC-FLAG /// if($singlePage) { // this will make sure only one page is displayed if needed break; } elseif($branch && $page->qtype == LESSON_ENDOFBRANCH) { // this will display a branch table and its contents break; } elseif ($page->nextpageid) { /// CDC-FLAG /// if (!$page = get_record("lesson_pages", "id", $page->nextpageid)) { error("Teacher view: Next page not found!"); } } else { // last page reached break; } } } /// CDC-FLAG /// end of else from above tree code!!! echo "

\n"; /// CDC-FLAG /// // NoticeFix both viewAll's if(isset($_GET['display']) && !isset($_GET['viewAll'])) { echo "
".get_string("viewallpages", "lesson")."
\n"; } if($lesson->tree && (isset($_GET['display']) || isset($_GET['viewAll']))) { echo "
".get_string("backtreeview", "lesson")."
\n"; } /// CDC-FLAG /// print_heading("id&action=navigation\">".get_string("checknavigation", "lesson")."\n"); } } /*******************essay view **************************************/ // 6/29/04 elseif ($action == 'essayview') { print_heading_with_help($lesson->name, "overview", "lesson"); // get lesson pages that are essay if (!$pages = get_records_select("lesson_pages", "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { error("Error: could not find lesson pages"); } // get all the users who have taken this lesson, order by their last name if (!$users = get_records_sql("SELECT DISTINCT u.* FROM {$CFG->prefix}user u, {$CFG->prefix}lesson_attempts a WHERE a.lessonid = '$lesson->id' and u.id = a.userid ORDER BY u.lastname")) { error("Error: could not find users"); } // get only the attempts that are in response to essay questions $pageids = implode(",", array_keys($pages)); // all the pageids in comma seperated list if (!$essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($pageids)")) { error ("No one has answered essay questions yet..."); } // group all the essays by userid foreach ($essayattempts as $essay) { // not very nice :) but basically // this organizes the essays so I know how many times a student answered an essay per try and per page $studentessays[$essay->userid][$essay->pageid][$essay->retry][] = $essay; } print_heading("id\">".get_string("gobacktolesson", "lesson").""); $table->head = array($course->students, get_string("essays", "lesson"), get_string("email", "lesson")); $table->align = array("left", "left", "left"); $table->wrap = array("nowrap", "wrap", "nowrap"); $table->width = "90%"; $table->size = array("*", "70%", "*"); // get the student ids of the students who have answered the essay question $studentids = array_keys($studentessays); // cycle through all the ids foreach ($studentids as $id) { $studentname = $users[$id]->lastname.", ".$users[$id]->firstname; unset($essaylinks); // go through each essay foreach ($studentessays[$id] as $page => $tries) { // go through each essay per page foreach($tries as $try) { // make sure they didn't answer it more than the max number of attmepts if (count($try) > $lesson->maxattempts) { $essay = $try[$lesson->maxattempts-1]; } else { $essay = end($try); } $essayinfo = unserialize($essay->useranswer); // different colors for all the states of an essay (graded, if sent, not graded) if (!$essayinfo->graded) { $style = "style='color:#DF041E;text-decoration:underline;'"; } elseif (!$essayinfo->sent) { $style = "style='color:#006600;text-decoration:underline;'"; } else { $style = "style='color:#999999;'"; } // link for each essay $essaylinks[] = "id&action=essaygrade&attemptid=$essay->id\">".$pages[$essay->pageid]->title.""; } } // email link for this user $emaillink = "id&action=emailessay&userid=".$id."&sesskey=".$USER->sesskey."\">".get_string("emailgradedessays", "lesson").""; $table->data[] = array($studentname, implode(", ", $essaylinks), $emaillink); } // email link for all users $emailalllink = "id&action=emailessay&sesskey=".$USER->sesskey."\">".get_string("emailallgradedessays", "lesson").""; $table->data[] = array(" ", " ", $emailalllink); print_table($table); } /*******************grade essays **************************************/ // 6/29/04 elseif ($action == 'essaygrade') { print_heading_with_help($lesson->name, "overview", "lesson"); $attemptid = required_param('attemptid', PARAM_INT); if (!$essay = get_record("lesson_attempts", "id", $attemptid)) { error("Error: could not find attempt"); } if (!$page = get_record("lesson_pages", "id", $essay->pageid)) { error("Error: could not find lesson pages"); } if (!$student = get_record("user", "id", $essay->userid)) { error("Error: could not find users"); } if (!$answer = get_record("lesson_answers", "lessonid", $lesson->id, "pageid", $page->id)) { error("Error: could not find answer"); } echo "
\n"; echo "id\" />\n"; echo "\n"; echo "\n"; echo "sesskey."\" />\n"; // all tables will have these $table->align = array("left"); $table->wrap = array("wrap"); $table->width = "70%"; $table->size = array("100%"); $table->head = array(get_string("question", "lesson")); $table->data[] = array(format_text($page->contents)); print_table($table); echo "
"; unset($table->data); $essayinfo = unserialize($essay->useranswer); $studentname = $student->firstname." ".$student->lastname; $table->head = array(get_string("studentresponse", "lesson", $studentname)); $table->data[] = array(format_text($essayinfo->answer)); print_table($table); echo "
"; unset($table->data); $table->head = array(get_string("comments", "lesson")); $table->data[] = array("\n"); if ($lesson->custom) { for ($i=$answer->score; $i>=0; $i--) { $options[$i] = $i; } } else { $options[0] = "incorrect"; $options[1] = "correct"; } $table->data[] = array(get_string("essayscore", "lesson").": ".lesson_choose_from_menu($options, "score", $essayinfo->score, "", "", "", true)); print_table($table); echo "
"; echo "
"; echo ""; echo ""; echo ""; echo "
"; echo "
"; } /*******************update grade**************************************/ // 6/29/04 elseif ($action == 'updategrade') { print_heading_with_help($lesson->name, "overview", "lesson"); confirm_sesskey(); $form = lesson_clean_data_submitted(); if (!$essay = get_record("lesson_attempts", "id", $form->attemptid)) { error("Error: could not find essay"); } if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid = $essay->userid", "completed", "*", $essay->retry, 1)) { error("Error: could not find grades"); } $essayinfo = unserialize($essay->useranswer); $essayinfo->graded = 1; $essayinfo->score = $form->score; $essayinfo->response = stripslashes_safe($form->response); $essayinfo->sent = 0; if (!$lesson->custom && $form->score == 1) { $essay->correct = 1; } else { $essay->correct = 0; } $essay->useranswer = addslashes(serialize($essayinfo)); if (!update_record("lesson_attempts", $essay)) { error("Could not update essay score"); } $grade = current($grades); // I modded this function a bit so it would work here... :) ;) :P $updategrade->grade = lesson_calculate_ongoing_score($lesson, $essay->userid, $essay->retry, true); $updategrade->id = $grade->id; if(update_record("lesson_grades", $updategrade)) { redirect("view.php?id=$cm->id&action=essayview", get_string("updatesuccess", "lesson")); } else { echo get_string("updatefailed", "lesson")."!
"; echo "id&action=essayview\">".get_string("continue", "lesson").""; exit(); } } /*******************email essay **************************************/ // 6/29/04 elseif ($action == 'emailessay') { print_heading_with_help($lesson->name, "overview", "lesson"); confirm_sesskey(); if (isset($_GET['userid'])) { $userid = clean_param($_GET['userid'], PARAM_INT); $queryadd = " AND userid = ".$userid; if (! $users = get_records("user", "id", $userid)) { error("Error: could not find users"); } } else { $queryadd = ""; if (!$users = lesson_get_participants($lesson->id)) { error("Error: could not find users"); } } // get lesson pages that are essay if (!$pages = get_records_select("lesson_pages", "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { error("Error: could not find lesson pages"); } // get only the attempts that are in response to essay questions $pageids = implode(",", array_keys($pages)); // all the pageids in comma seperated list if (!$essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($pageids)".$queryadd)) { error ("No one has answered essay questions yet..."); } if (!$essayanswers = get_records_select("lesson_answers", "lessonid = $lesson->id AND pageid IN($pageids)", "", "pageid, score")) { error ("Could not find answer records."); } // NoticeFix big fix, change $essay[]'s that use $USER to just $USER foreach ($essayattempts as $essay) { $essayinfo = unserialize($essay->useranswer); if ($essayinfo->graded && !$essayinfo->sent) { $subject = get_string('essayemailsubject', 'lesson', $pages[$essay->pageid]->title); $message = get_string('question', 'lesson').":
"; $message .= $pages[$essay->pageid]->contents; $message .= "

"; $message .= get_string('yourresponse', 'lesson').":
"; $message .= $essayinfo->answer; $message .= "

"; $message .= get_string('commentswithname', 'lesson', $USER).":
"; $message .= $essayinfo->response; $message .= "

"; $grades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid = $essay->userid", "completed", "*", $essay->retry, 1); $grade = current($grades); if ($lesson->custom) { $points->score = $essayinfo->score; $points->outof = $essayanswers[$essay->pageid]->score; $message .= get_string("youhavereceived", "lesson", $points); } else { $points->score = $essayinfo->score; $points->outof = 1; $message .= get_string("youhavereceived", "lesson", $points); } $message .= "

"; $message .= get_string("yourgradeisnow", "lesson", $grade->grade)."%."; $plaintxt = format_text_email($message, FORMAT_HTML); if(email_to_user($users[$essay->userid], $USER, $subject, $plaintxt, $message)) { $essayinfo->sent = 1; $essay->useranswer = addslashes(serialize($essayinfo)); update_record("lesson_attempts", $essay); } else { echo "Email Failed!
"; echo "id&action=essayview\">".get_string("continue", "lesson").""; echo ""; exit(); } } } redirect("view.php?id=$cm->id&action=essayview", get_string("emailsuccess", "lesson")); } /*******************high scores **************************************/ elseif ($action == 'highscores') { print_heading_with_help($lesson->name, "overview", "lesson"); if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id", "completed")) { $grades = array(); } echo "
"; $titleinfo->maxhighscores = $lesson->maxhighscores; $titleinfo->name = $lesson->name; echo get_string("topscorestitle", "lesson", $titleinfo)."

"; if (!$highscores = get_records_select("lesson_high_scores", "lessonid = $lesson->id")) { echo get_string("nohighscores", "lesson")."
"; } else { foreach ($highscores as $highscore) { $grade = $grades[$highscore->gradeid]->grade; $topscores[$grade][] = $highscore->nickname; } krsort($topscores); echo ""; echo "cellheading2\">"; $printed = 0; while (true) { $temp = current($topscores); $score = key($topscores); $rank = $printed + 1; sort($temp); foreach ($temp as $student) { echo ""; } $printed++; if (!next($topscores) || !($printed < $lesson->maxhighscores)) { break; } } echo "
".get_string("rank", "lesson")."$course->students".get_string("scores", "lesson")."
$rank$student$score
"; } if (isset($_GET['link'])) { echo "
id\">".get_string("returntocourse", "lesson").""; } else { echo "
id\">".get_string("cancel", "lesson")." | id&action=navigation\">".get_string("startlesson", "lesson").""; } echo "
"; } /*******************update high scores **************************************/ elseif ($action == 'updatehighscores') { print_heading_with_help($lesson->name, "overview", "lesson"); confirm_sesskey(); if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id", "completed")) { error("Error: could not find grades"); } if (!$usergrades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid = $USER->id", "completed DESC")) { error("Error: could not find grades"); } echo "
"; echo get_string("waitpostscore", "lesson")."
"; foreach ($usergrades as $usergrade) { // get their latest grade $newgrade = $usergrade; break; } if ($pasthighscore = get_record_select("lesson_high_scores", "lessonid = $lesson->id and userid = $USER->id")) { $pastgrade = $grades[$pasthighscore->gradeid]->grade; if ($pastgrade >= $newgrade->grade) { redirect("view.php?id=$cm->id&action=highscores&link=1", "Update Successful"); } else { // delete old and find out where new one goes if (!delete_records("lesson_high_scores", "id", $pasthighscore->id)) { error("Error: could not delete old high score"); } } } // find out if we need to delete any records if ($highscores = get_records_select("lesson_high_scores", "lessonid = $lesson->id")) { // if no high scores... then just insert our new one foreach ($highscores as $highscore) { $grade = $grades[$highscore->gradeid]->grade; $topscores[$grade][] = $highscore->userid; } if (!(count($topscores) < $lesson->maxhighscores)) { // if the top scores list is not full then dont need to worry about removing old scores $scores = array_keys($topscores); $flag = true; // see if the new score is already listed in the top scores list // if it is listed, then dont need to delete any records foreach ($scores as $score) { if ($score = $newgrade->grade) { $flag = false; } } if ($flag) { // if the score does not exist in the top scores list, then the lowest scores get thrown out. ksort($topscores); // sort so the lowest score is first element $lowscore = current($topscores); // making a delete statement to delete all users with the lowest score $deletestmt = 'lessonid = '. $lesson->id .' and userid = '; $deletestmt .= current($lowscore); while (next($lowscore)) { $deletestmt .= " or userid = ".current($lowscore); } if (!delete_records_select('lesson_high_scores', $deletestmt)) { /// not a big deal... error('Did not delete extra high score(s)'); } } } } $newhighscore->lessonid = $lesson->id; $newhighscore->userid = $USER->id; $newhighscore->gradeid = $newgrade->id; if (isset($_GET['name'])) { $newhighscore->nickname = clean_param($_GET['name'], PARAM_CLEAN); } if (!insert_record("lesson_high_scores", $newhighscore)) { error("Insert of new high score Failed!"); } redirect("view.php?id=$cm->id&action=highscores&link=1", get_string("postsuccess", "lesson")); echo "
"; } /*******************name for highscores **************************************/ elseif ($action == 'nameforhighscores') { print_heading_with_help($lesson->name, "overview", "lesson"); echo "
"; if (isset($_POST['name'])) { $name = trim(param_clean($_POST['name'], PARAM_CLEAN)); if (lesson_check_nickname($name)) { redirect("view.php?id=$cm->id&action=updatehighscores&name=$name&sesskey=".$USER->sesskey, get_string("nameapproved", "lesson")); } else { echo get_string("namereject", "lesson")."

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