From: michaelpenne Date: Fri, 4 Feb 2005 19:39:18 +0000 (+0000) Subject: re-arranged a lot of code. Only branch tables appear in slide show mode. Display... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5aeebbc8942f8266909613ef9c2e92140c2229ca;p=moodle.git re-arranged a lot of code. Only branch tables appear in slide show mode. Display left and slideshow works with tables now instead of stylesheets (helps with browser compatibility). Some XHTML fixes. Fixed grading essay questions for non-custom scoreing. Reformated a lot of output --- diff --git a/mod/lesson/view.php b/mod/lesson/view.php index 2150826579..24767a3db4 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -108,30 +108,6 @@ /************** navigation **************************************/ if ($action == 'navigation') { - //CDC Chris Berri added this echo call for left menu. must match that in lesson.php for styles - if ($lesson->displayleft) { - echo '
'; - if($page = get_record_select('lesson_pages', 'lessonid = '. $lesson->id .' AND prevpageid = 0')) { - // print the pages - echo '
'; - echo ''; - echo ''; - echo ''; - echo "'; //close lmlinks - echo '
'; - } - echo '
'; //close left menu - echo "
"; //CDC chris berri for styles - } elseif ($lesson->slideshow) { - echo '
'; - } - /// CDC-FLAG /// password protected lesson code if ($lesson->usepassword && !isteacher($course->id)) { $correctpass = false; @@ -165,41 +141,17 @@ } } - /// CDC-FLAG /// Slideshow styles - if($lesson->slideshow) { - //echo "
\n";//CDC Chris Berri. add the left menu theme stuff here. must match on lesson.php - 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"; - } // this is called if a student leaves during a lesson if($pageid == LESSON_UNSEENBRANCHPAGE) { $pageid = lesson_unseen_question_jump($lesson->id, $USER->id, $pageid); } - /// CDC-FLAG /// - - /// CDC-FLAG /// 6/21/04 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) .'
'; - } - } - /// CDC-FLAG /// // 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 @@ -210,7 +162,7 @@ $retries = 0; } if ($retries) { - print_heading(get_string('attempt', 'lesson', $retries + 1)); + $attemptflag = true; } if (isset($USER->modattempts[$lesson->id])) { @@ -327,13 +279,14 @@ error('Error: could not insert row into lesson_timer table'); } } + $timedflag = true; } /// CDC-FLAG /// } + if ($pageid != LESSON_EOL) { - /// CDC-FLAG /// 6/15/04 -- This is the code updates the lessontime for a timed test - // NoticeFix - if (isset($_POST['startlastseen'])) { /// this deletes old records + /// 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')) { @@ -350,10 +303,86 @@ } } } + + 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 "
\n"; + } else { + 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') .'
'; + 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) @@ -405,14 +434,13 @@ echo "\n"; echo "

"; print_simple_box_end(); - echo "



"; + 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'). - '
'; + echo "

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

"; } unset($newtime); @@ -423,48 +451,16 @@ error('Error: could not update lesson_timer table'); } - // I dont like this... seems like there should be a better way... - if (!$firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, - 'prevpageid', 0)) { - error('Navigation: first page not found'); - } - if ($pageid == $firstpageid && !isset($USER->modattempts[$lesson->id])) { - print_simple_box(get_string('maxtimewarning', 'lesson', $lesson->maxtime), 'center'); + if ($timedflag) { + print_simple_box(get_string('maxtimewarning', 'lesson', $lesson->maxtime), 'center'); } } } - /// CDC-FLAG /// - - 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'); - } - /// CDC-FLAG 6/21/04 /// - 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'); - } - } 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')); - } - /// CDC-FLAG /// - + + 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) { @@ -497,11 +493,20 @@ error('Navigation: No answers on EOB'); } } - - /// CDC-FLAG 6/21/04 /// this calculates the ongoing score + + /// 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').'
'; + echo "

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

'; } else { $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); if (isset($USER->modattempts[$lesson->id])) { @@ -510,15 +515,7 @@ lesson_calculate_ongoing_score($lesson, $USER->id, $ntries); } } - /// CDC-FLAG /// - // it's not a EOB process it... - /// CDC-FLAG /// - if ($lesson->slideshow) { - echo "
\n"; - } else { - echo "
\n"; - } - /// CDC-FLAG /// + 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 @@ -550,25 +547,21 @@ } } - /// CDC-FLAG /// moved name and title down here for Flow style, michaelp + // now starting to print the page's contents echo "
"; - echo ""; - echo ($lesson->name) . ""; + echo ""; + echo ($lesson->name) . ""; if ($page->qtype == LESSON_BRANCHTABLE) { - echo ":
"; + echo ":
"; print_heading($page->title); } - echo "

"; + echo "
"; - /// CDC-FLAG /// if ($lesson->slideshow) { - echo "
"; echo format_text($page->contents); - echo "
"; } else { print_simple_box(format_text($page->contents), 'center'); } - /// CDC-FLAG /// echo "
\n"; // this is for modattempts option. Find the users previous answer to this page, @@ -589,12 +582,10 @@ echo ""; echo ""; echo "sesskey."\" />"; - /// CDC-FLAG /// - if (!$lesson->slideshow || $page->qtype != 20) { + if (!$lesson->slideshow) { print_simple_box_start("center"); + echo ''; } - /// CDC-FLAG /// - echo '
'; switch ($page->qtype) { case LESSON_SHORTANSWER : case LESSON_NUMERICAL : @@ -607,17 +598,15 @@ ": \n"; //CDC hidden label added. echo '
'; print_simple_box_end(); - if (!$lesson->slideshow) { - echo "

\n"; - } + 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 = "checked=\"checked\""; } else { $checked = ""; } @@ -632,10 +621,8 @@ } echo '
'; print_simple_box_end(); - if (!$lesson->slideshow) { - echo "

\n"; - } + echo "

\n"; break; case LESSON_MULTICHOICE : $i = 0; @@ -647,7 +634,7 @@ if (isset($USER->modattempts[$lesson->id])) { $answerids = explode(",", $attempt->useranswer); if (in_array($answer->id, $answerids)) { - $checked = "CHECKED"; + $checked = "checked=\"checked\""; } else { $checked = ""; } @@ -656,7 +643,7 @@ echo "id}\" $checked />"; //CDC hidden label added. } else { if (isset($USER->modattempts[$lesson->id]) && $answer->id == $attempt->answerid) { - $checked = "CHECKED"; + $checked = "checked=\"checked\""; } else { $checked = ""; } @@ -674,17 +661,13 @@ } echo '
'; print_simple_box_end(); - /// CDC-FLAG /// - if (!$lesson->slideshow) { - if ($page->qoption) { - echo "

\n"; - } else { - echo "

\n"; - } - } - /// CDC-FLAG /// + if ($page->qoption) { + echo "

\n"; + } else { + echo "

\n"; + } break; /// CDC-FLAG /// 6/14/04 --- changed how matching works @@ -733,30 +716,81 @@ } echo '
'; print_simple_box_end(); - if (!$lesson->slideshow) { - echo "

\n"; - } + echo "

\n"; break; - /// CDC-FLAG /// - case LESSON_BRANCHTABLE : - echo "
"; + if ($lesson->slideshow) { + echo "
"; + } else { + echo "
"; + } echo ""; - // don't suffle answers - /// CDC-FLAG /// - if(!$lesson->slideshow) { - foreach ($answers as $answer) { + + $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 ""; } - } - - /// CDC-FLAG /// - 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(); + }*/ + if (!$lesson->slideshow) { + echo '
'; + print_simple_box_end(); + } break; case LESSON_ESSAY : if (isset($USER->modattempts[$lesson->id])) { @@ -769,17 +803,11 @@ "\n"; //CDC hidden label added. echo "
"; print_simple_box_end(); - if (!$lesson->slideshow) { - echo "

\n"; - } + echo "

\n"; break; } - /// CDC-FLAG /// - if (!$lesson->slideshow) { - echo "\n"; - } - /// CDC-FLAG /// + echo "\n"; } else { // a page without answers - find the next (logical) page echo "
\n"; @@ -1076,109 +1104,10 @@ echo "

id\">".get_string("mainmenu", "lesson")."

\n"; //CDC Back to the menu (course view). echo "

id\">".get_string("viewgrades", "lesson")."

\n"; //CDC view grades } - /// CDC-FLAG /// - if($lesson->slideshow) { - echo "
\n"; //Closes Mark's big div tag? - } - - if($lesson->slideshow && $pageid != LESSON_EOL) { - if (!$lesson->displayleft) { - echo "width\" cellpadding=\"5\" cellspacing=\"5\" align=\"center\">\n"; - } else { - echo "
width\" cellpadding=\"5\" cellspacing=\"5\">\n"; - } - switch ($page->qtype) { - case LESSON_SHORTANSWER : - case LESSON_NUMERICAL : - echo "\n"; - break; - case LESSON_TRUEFALSE : - echo "\n"; - break; - case LESSON_MULTICHOICE : - if ($page->qoption) { - echo "\n"; - } else { - echo "\n"; - } - break; - case LESSON_MATCHING : - echo "\n"; - break; - case LESSON_ESSAY : - echo "\n"; - break; - case LESSON_BRANCHTABLE : - if (!empty($answers)) { - $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 ""; - } - } - } - } - break; - } - 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\" />
\n"; - } - if ($lesson->displayleft) { - echo ""; //CDC Chris Berri for styles, closes slidepos. - } elseif ($lesson->slideshow) { - echo ""; - } - /// CDC-FLAG /// + if ($lesson->displayleft || $lesson->slideshow) { // this ends the table cell and table for the leftmenu or for slideshow + echo ""; + } } @@ -1666,10 +1595,10 @@ elseif ($action == 'essaygrade') { print_heading_with_help($lesson->name, "overview", "lesson"); - $attemptid = require_variable('attemptid'); + $attemptid = required_param('attemptid', PARAM_INT); if (!$essay = get_record("lesson_attempts", "id", $attemptid)) { - error("Error: could not find essay"); + error("Error: could not find attempt"); } if (!$page = get_record("lesson_pages", "id", $essay->pageid)) { error("Error: could not find lesson pages"); @@ -1720,7 +1649,8 @@ $options[$i] = $i; } } else { - $options[0] = "incorrect"; $options[1] = "correct"; + $options[0] = "incorrect"; + $options[1] = "correct"; } $table->data[] = array(get_string("essayscore", "lesson").": ".lesson_choose_from_menu($options, "score", $essayinfo->score, "", "", "", true)); @@ -1760,6 +1690,11 @@ $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)); @@ -1770,10 +1705,10 @@ $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->grade = lesson_calculate_ongoing_score($lesson, $essay->userid, $essay->retry, true); $updategrade->id = $grade->id; - if(update_record("lesson_attempts", $essay) && update_record("lesson_grades", $updategrade)) { + if(update_record("lesson_grades", $updategrade)) { redirect("view.php?id=$cm->id&action=essayview", get_string("updatesuccess", "lesson")); } else { echo get_string("updatefailed", "lesson")."!
";