diff --git a/mod/lesson/lesson.php b/mod/lesson/lesson.php index 2eb187ff9ea..ec5ab916e58 100644 --- a/mod/lesson/lesson.php +++ b/mod/lesson/lesson.php @@ -1,49 +1,49 @@ course)) { - error("Course is misconfigured"); - } + if (! $course = get_record("course", "id", $cm->course)) { + error("Course is misconfigured"); + } - if (! $lesson = get_record("lesson", "id", $cm->instance)) { - error("Course module is incorrect"); - } - - require_login($course->id, false, $cm); + if (! $lesson = get_record("lesson", "id", $cm->instance)) { + error("Course module is incorrect"); + } + require_login($course->id); + // set up some general variables $usehtmleditor = can_use_html_editor(); - + $navigation = ""; if ($course->category) { $navigation = "id\">$course->shortname ->"; @@ -52,58 +52,58 @@ $strlessons = get_string("modulenameplural", "lesson"); $strlesson = get_string("modulename", "lesson"); $strlessonname = $lesson->name; - - // ... print the header and... + + // ... print the header and... print_header("$course->shortname: $lesson->name", "$course->fullname", - "$navigation id>$strlessons -> - id\">$lesson->name", - "", "", true); + "$navigation id>$strlessons -> + id\">$lesson->name", + "", "", true); - //...get the action - $action = required_param('action'); + //...get the action + $action = required_param('action'); + + /************** add branch table ************************************/ + if ($action == 'addbranchtable' ) { - /************** add branch table ************************************/ - if ($action == 'addbranchtable' ) { - - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } // first get the preceeding page $pageid = required_param('pageid', PARAM_INT); - + // set of jump array $jump = array(); - $jump[0] = get_string("thispage", "lesson"); + $jump[0] = get_string("thispage", "lesson"); $jump[LESSON_NEXTPAGE] = get_string("nextpage", "lesson"); - //// CDC-FLAG ///// - $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson"); - if (!isset($_GET['firstpage'])) { - $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); - if (!$apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { - error("Add page: first page not found"); - } - while (true) { - if ($apageid) { - $title = get_field("lesson_pages", "title", "id", $apageid); - $jump[$apageid] = $title; - $apageid = get_field("lesson_pages", "nextpageid", "id", $apageid); - } else { - // last page reached - break; - } - } - } - //// CDC-FLAG ///// + //// CDC-FLAG ///// + $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson"); + if (!isset($_GET['firstpage'])) { + $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); + if (!$apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { + error("Add page: first page not found"); + } + while (true) { + if ($apageid) { + $title = get_field("lesson_pages", "title", "id", $apageid); + $jump[$apageid] = $title; + $apageid = get_field("lesson_pages", "nextpageid", "id", $apageid); + } else { + // last page reached + break; + } + } + } + //// CDC-FLAG ///// // give teacher a blank proforma - print_heading_with_help(get_string("addabranchtable", "lesson"), "overview", "lesson"); + print_heading_with_help(get_string("addabranchtable", "lesson"), "overview", "lesson"); ?>
- +
@@ -114,21 +114,21 @@ echo get_string("pagecontents", "lesson").":
\n"; print_textarea($usehtmleditor, 25,70, 630, 400, "contents"); use_html_editor("contents"); - echo "\n"; - /// CDC-FLAG /// 6/16/04 - echo "\n"; - /// CDC-FLAG /// + echo "\n"; + /// CDC-FLAG /// 6/16/04 + echo "\n"; + /// CDC-FLAG /// for ($i = 0; $i < $lesson->maxanswers; $i++) { $iplus1 = $i + 1; echo "\n"; + echo "\n"; echo "
\n"; - echo "
"; - echo get_string("arrangebuttonshorizontally", "lesson")."\n"; - echo "
"; - echo get_string("displayinleftmenu", "lesson"); - echo "
\n"; - echo "
\n"; + echo "
"; + echo get_string("arrangebuttonshorizontally", "lesson")."\n"; + echo "
"; + echo get_string("displayinleftmenu", "lesson"); + echo "
\n"; + echo "
".get_string("description", "lesson")." $iplus1:
\n"; print_textarea(false, 10, 70, 630, 300, "answer[$i]"); // made the default set to off also removed use_html_editor(); line from down below, which made all textareas turn into html editors - echo "
".get_string("jump", "lesson")." $iplus1: \n"; if ($i) { // answers 2, 3, 4... jumpto this page @@ -148,23 +148,23 @@ id)) { - error("Only teachers can look at this page"); - } + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } - confirm_sesskey(); + confirm_sesskey(); // first get the preceeding page $pageid = required_param('pageid', PARAM_INT); - + $timenow = time(); - + // the new page is not the first page (end of branch always comes after an existing page) if (!$page = get_record("lesson_pages", "id", $pageid)) { error("Add end of branch: page record not found"); @@ -181,7 +181,7 @@ } } if ($btpage->qtype == LESSON_BRANCHTABLE) { - $newpage = new stdClass; + $newpage = new stdClass; $newpage->lessonid = $lesson->id; $newpage->prevpageid = $pageid; $newpage->nextpageid = $page->nextpageid; @@ -203,7 +203,7 @@ } } // ..and the single "answer" - $newanswer = new stdClass; + $newanswer = new stdClass; $newanswer->lessonid = $lesson->id; $newanswer->pageid = $newpageid; $newanswer->timecreated = $timenow; @@ -215,213 +215,213 @@ } else { notice(get_string("nobranchtablefound", "lesson"), "view.php?id=$cm->id"); } - } + } -/// CDC-FLAG 6/17/04 /// - /************** add cluster ************************************/ +/// CDC-FLAG 6/17/04 /// + /************** add cluster ************************************/ elseif ($action == 'addcluster' ) { - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } - - confirm_sesskey(); + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } + + confirm_sesskey(); // first get the preceeding page - // if $pageid = 0, then we are inserting a new page at the beginning of the lesson + // if $pageid = 0, then we are inserting a new page at the beginning of the lesson $pageid = required_param('pageid', PARAM_INT); - + $timenow = time(); - - if ($pageid == 0) { - if (!$page = get_record("lesson_pages", "prevpageid", 0, "lessonid", $lesson->id)) { - error("Error: Add cluster: page record not found"); - } - } else { - if (!$page = get_record("lesson_pages", "id", $pageid)) { - error("Error: Add cluster: page record not found"); - } - } + + if ($pageid == 0) { + if (!$page = get_record("lesson_pages", "prevpageid", 0, "lessonid", $lesson->id)) { + error("Error: Add cluster: page record not found"); + } + } else { + if (!$page = get_record("lesson_pages", "id", $pageid)) { + error("Error: Add cluster: page record not found"); + } + } $newpage = new stdClass; - $newpage->lessonid = $lesson->id; - $newpage->prevpageid = $pageid; - if ($pageid != 0) { - $newpage->nextpageid = $page->nextpageid; - } else { - $newpage->nextpageid = $page->id; - } - $newpage->qtype = LESSON_CLUSTER; - $newpage->timecreated = $timenow; - $newpage->title = get_string("clustertitle", "lesson"); - $newpage->contents = get_string("clustertitle", "lesson"); - if (!$newpageid = insert_record("lesson_pages", $newpage)) { - error("Insert page: new page not inserted"); - } - // update the linked list... - if ($pageid != 0) { - if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $pageid)) { - error("Add cluster: unable to update link"); - } - } + $newpage->lessonid = $lesson->id; + $newpage->prevpageid = $pageid; + if ($pageid != 0) { + $newpage->nextpageid = $page->nextpageid; + } else { + $newpage->nextpageid = $page->id; + } + $newpage->qtype = LESSON_CLUSTER; + $newpage->timecreated = $timenow; + $newpage->title = get_string("clustertitle", "lesson"); + $newpage->contents = get_string("clustertitle", "lesson"); + if (!$newpageid = insert_record("lesson_pages", $newpage)) { + error("Insert page: new page not inserted"); + } + // update the linked list... + if ($pageid != 0) { + if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $pageid)) { + error("Add cluster: unable to update link"); + } + } + + if ($pageid == 0) { + $page->nextpageid = $page->id; + } + if ($page->nextpageid) { + // the new page is not the last page + if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->nextpageid)) { + error("Insert page: unable to update previous link"); + } + } + // ..and the single "answer" + $newanswer = new stdClass; + $newanswer->lessonid = $lesson->id; + $newanswer->pageid = $newpageid; + $newanswer->timecreated = $timenow; + $newanswer->jumpto = LESSON_CLUSTERJUMP; + if(!$newanswerid = insert_record("lesson_answers", $newanswer)) { + error("Add cluster: answer record not inserted"); + } + redirect("view.php?id=$cm->id", get_string('addedcluster', 'lesson')); + } +/// CDC-FLAG /// - if ($pageid == 0) { - $page->nextpageid = $page->id; - } - if ($page->nextpageid) { - // the new page is not the last page - if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->nextpageid)) { - error("Insert page: unable to update previous link"); - } - } - // ..and the single "answer" - $newanswer = new stdClass; - $newanswer->lessonid = $lesson->id; - $newanswer->pageid = $newpageid; - $newanswer->timecreated = $timenow; - $newanswer->jumpto = LESSON_CLUSTERJUMP; - if(!$newanswerid = insert_record("lesson_answers", $newanswer)) { - error("Add cluster: answer record not inserted"); - } - redirect("view.php?id=$cm->id", get_string('addedcluster', 'lesson')); - } -/// CDC-FLAG /// - -/// CDC-FLAG 6/17/04 /// - /************** add end of cluster ************************************/ +/// CDC-FLAG 6/17/04 /// + /************** add end of cluster ************************************/ elseif ($action == 'addendofcluster' ) { - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } - confirm_sesskey(); + confirm_sesskey(); // first get the preceeding page $pageid = required_param('pageid', PARAM_INT); - + $timenow = time(); - + // the new page is not the first page (end of cluster always comes after an existing page) if (!$page = get_record("lesson_pages", "id", $pageid)) { - error("Error: Could not find page"); + error("Error: Could not find page"); } - - // could put code in here to check if the user really can insert an end of cluster - - $newpage = new stdClass; - $newpage->lessonid = $lesson->id; - $newpage->prevpageid = $pageid; - $newpage->nextpageid = $page->nextpageid; - $newpage->qtype = LESSON_ENDOFCLUSTER; - $newpage->timecreated = $timenow; - $newpage->title = get_string("endofclustertitle", "lesson"); - $newpage->contents = get_string("endofclustertitle", "lesson"); - if (!$newpageid = insert_record("lesson_pages", $newpage)) { - error("Insert page: end of cluster page not inserted"); - } - // update the linked list... - if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $pageid)) { - error("Add end of cluster: unable to update link"); - } - if ($page->nextpageid) { - // the new page is not the last page - if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->nextpageid)) { - error("Insert end of cluster: unable to update previous link"); - } - } - // ..and the single "answer" - $newanswer = new stdClass; - $newanswer->lessonid = $lesson->id; - $newanswer->pageid = $newpageid; - $newanswer->timecreated = $timenow; - $newanswer->jumpto = LESSON_NEXTPAGE; - if(!$newanswerid = insert_record("lesson_answers", $newanswer)) { - error("Add end of cluster: answer record not inserted"); - } - redirect("view.php?id=$cm->id", get_string('addedendofcluster', 'lesson')); - } + + // could put code in here to check if the user really can insert an end of cluster + + $newpage = new stdClass; + $newpage->lessonid = $lesson->id; + $newpage->prevpageid = $pageid; + $newpage->nextpageid = $page->nextpageid; + $newpage->qtype = LESSON_ENDOFCLUSTER; + $newpage->timecreated = $timenow; + $newpage->title = get_string("endofclustertitle", "lesson"); + $newpage->contents = get_string("endofclustertitle", "lesson"); + if (!$newpageid = insert_record("lesson_pages", $newpage)) { + error("Insert page: end of cluster page not inserted"); + } + // update the linked list... + if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $pageid)) { + error("Add end of cluster: unable to update link"); + } + if ($page->nextpageid) { + // the new page is not the last page + if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->nextpageid)) { + error("Insert end of cluster: unable to update previous link"); + } + } + // ..and the single "answer" + $newanswer = new stdClass; + $newanswer->lessonid = $lesson->id; + $newanswer->pageid = $newpageid; + $newanswer->timecreated = $timenow; + $newanswer->jumpto = LESSON_NEXTPAGE; + if(!$newanswerid = insert_record("lesson_answers", $newanswer)) { + error("Add end of cluster: answer record not inserted"); + } + redirect("view.php?id=$cm->id", get_string('addedendofcluster', 'lesson')); + } /// CDC-FLAG /// - - /************** add page ************************************/ + + /************** add page ************************************/ elseif ($action == 'addpage' ) { - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } // first get the preceeding page $pageid = required_param('pageid', PARAM_INT); - + // set of jump array - $jump = array(); + $jump = array(); $jump[0] = get_string("thispage", "lesson"); $jump[LESSON_NEXTPAGE] = get_string("nextpage", "lesson"); - //// CDC-FLAG 6/18/04 ///// - $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson"); - if(lesson_display_branch_jumps($lesson->id, $pageid)) { - $jump[LESSON_UNSEENBRANCHPAGE] = get_string("unseenpageinbranch", "lesson"); - $jump[LESSON_RANDOMPAGE] = get_string("randompageinbranch", "lesson"); - } - if(lesson_display_cluster_jump($lesson->id, $pageid)) { - $jump[LESSON_CLUSTERJUMP] = get_string("clusterjump", "lesson"); - } - /// CDC-FLAG /// - if (!isset($_GET['firstpage'])) { - $linkadd = ""; - $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); - if (!$apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { - error("Add page: first page not found"); - } - while (true) { - if ($apageid) { - $title = get_field("lesson_pages", "title", "id", $apageid); - $jump[$apageid] = $title; - $apageid = get_field("lesson_pages", "nextpageid", "id", $apageid); - } else { - // last page reached - break; - } - } - } else { - $linkadd = "&firstpage=1"; - } - + //// CDC-FLAG 6/18/04 ///// + $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson"); + if(lesson_display_branch_jumps($lesson->id, $pageid)) { + $jump[LESSON_UNSEENBRANCHPAGE] = get_string("unseenpageinbranch", "lesson"); + $jump[LESSON_RANDOMPAGE] = get_string("randompageinbranch", "lesson"); + } + if(lesson_display_cluster_jump($lesson->id, $pageid)) { + $jump[LESSON_CLUSTERJUMP] = get_string("clusterjump", "lesson"); + } + /// CDC-FLAG /// + if (!isset($_GET['firstpage'])) { + $linkadd = ""; + $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); + if (!$apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { + error("Add page: first page not found"); + } + while (true) { + if ($apageid) { + $title = get_field("lesson_pages", "title", "id", $apageid); + $jump[$apageid] = $title; + $apageid = get_field("lesson_pages", "nextpageid", "id", $apageid); + } else { + // last page reached + break; + } + } + } else { + $linkadd = "&firstpage=1"; + } + // give teacher a blank proforma - print_heading_with_help(get_string("addaquestionpage", "lesson"), "overview", "lesson"); + print_heading_with_help(get_string("addaquestionpage", "lesson"), "overview", "lesson"); ?>
-
- \n"; - ?> +
"; - echo get_string("questiontype", "lesson").": \n"; - echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; - if (isset($_GET['qtype'])) { - $qtype = clean_param($_GET['qtype'], PARAM_INT); - lesson_qtype_menu($LESSON_QUESTION_TYPE, $qtype, - "lesson.php?id=$cm->id&action=addpage&pageid=".$pageid.$linkadd); - // NoticeFix rearraged - if ( $qtype == LESSON_SHORTANSWER || $qtype == LESSON_MULTICHOICE ) { // only display this option for Multichoice and shortanswer - if ($qtype == LESSON_SHORTANSWER) { - echo "

".get_string("casesensitive", "lesson").": \n"; - } else { - echo "

".get_string("multianswer", "lesson").": \n"; - } - echo " "; //CDC hidden label added. - helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); - } - } else { - lesson_qtype_menu($LESSON_QUESTION_TYPE, LESSON_MULTICHOICE, - "lesson.php?id=$cm->id&action=addpage&pageid=".$pageid.$linkadd); - echo "

".get_string("multianswer", "lesson").": \n"; - echo " "; //CDC hidden label added. - helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); - } - echo "
+ \n"; + ?> \n"; - if (isset($_GET['qtype'])) { - switch ($_GET['qtype']) { - case LESSON_TRUEFALSE : - for ($i = 0; $i < 2; $i++) { - $iplus1 = $i + 1; - echo "\n"; - echo "\n"; - echo "\n"; - } - break; - case LESSON_ESSAY : - echo "\n"; - break; - case LESSON_MATCHING : - for ($i = 0; $i < $lesson->maxanswers+2; $i++) { - $icorrected = $i - 1; - if ($i == 0) { - echo "\n"; - } elseif ($i == 1) { - echo "\n"; - } else { - echo "\n"; - echo "\n"; - } - if ($i == 2) { - echo "\n"; - } elseif ($i == 3) { - echo "\n"; - } - } - break; - case LESSON_SHORTANSWER : - case LESSON_NUMERICAL : - case LESSON_MULTICHOICE : - // default code - for ($i = 0; $i < $lesson->maxanswers; $i++) { - $iplus1 = $i + 1; - echo "\n"; - echo "\n"; - echo "\n"; - } - break; - } - } else { - for ($i = 0; $i < $lesson->maxanswers; $i++) { - $iplus1 = $i + 1; - echo "\n"; - echo "\n"; - echo "\n"; - } - } + if (isset($_GET['qtype'])) { + switch ($_GET['qtype']) { + case LESSON_TRUEFALSE : + for ($i = 0; $i < 2; $i++) { + $iplus1 = $i + 1; + echo "\n"; + echo "\n"; + echo "\n"; + } + break; + case LESSON_ESSAY : + echo "\n"; + break; + case LESSON_MATCHING : + for ($i = 0; $i < $lesson->maxanswers+2; $i++) { + $icorrected = $i - 1; + if ($i == 0) { + echo "\n"; + } elseif ($i == 1) { + echo "\n"; + } else { + echo "\n"; + echo "\n"; + } + if ($i == 2) { + echo "\n"; + } elseif ($i == 3) { + echo "\n"; + } + } + break; + case LESSON_SHORTANSWER : + case LESSON_NUMERICAL : + case LESSON_MULTICHOICE : + // default code + for ($i = 0; $i < $lesson->maxanswers; $i++) { + $iplus1 = $i + 1; + echo "\n"; + echo "\n"; + echo "\n"; + } + break; + } + } else { + for ($i = 0; $i < $lesson->maxanswers; $i++) { + $iplus1 = $i + 1; + echo "\n"; + echo "\n"; + echo "\n"; + } + } // close table and form ?>
"; + echo get_string("questiontype", "lesson").": \n"; + echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; + if (isset($_GET['qtype'])) { + $qtype = clean_param($_GET['qtype'], PARAM_INT); + lesson_qtype_menu($LESSON_QUESTION_TYPE, $qtype, + "lesson.php?id=$cm->id&action=addpage&pageid=".$pageid.$linkadd); + // NoticeFix rearraged + if ( $qtype == LESSON_SHORTANSWER || $qtype == LESSON_MULTICHOICE ) { // only display this option for Multichoice and shortanswer + if ($qtype == LESSON_SHORTANSWER) { + echo "

".get_string("casesensitive", "lesson").": \n"; + } else { + echo "

".get_string("multianswer", "lesson").": \n"; + } + echo " "; //CDC hidden label added. + helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); + } + } else { + lesson_qtype_menu($LESSON_QUESTION_TYPE, LESSON_MULTICHOICE, + "lesson.php?id=$cm->id&action=addpage&pageid=".$pageid.$linkadd); + echo "

".get_string("multianswer", "lesson").": \n"; + echo " "; //CDC hidden label added. + helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); + } + echo "
:
@@ -432,149 +432,149 @@ print_textarea($usehtmleditor, 25,70, 630, 400, "contents"); use_html_editor("contents"); echo "
".get_string("answer", "lesson")." $iplus1:
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$i]"); - echo "
".get_string("response", "lesson")." $iplus1:
\n"; - print_textarea(false, 6, 70, 630, 300, "response[$i]"); - echo "
".get_string("jump", "lesson")." $iplus1: \n"; - if ($i) { - // answers 2, 3, 4... jumpto this page - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - } else { - // answer 1 jumpto next page - lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); - } - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - /// CDC-FLAG /// - if($lesson->custom) { - if ($i) { - echo get_string("score", "lesson")." $iplus1: "; - } else { - echo get_string("score", "lesson")." $iplus1: "; - } - } - /// CDC-FLAG /// - echo "
".get_string("jump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[0]", LESSON_NEXTPAGE, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if ($lesson->custom) { - echo get_string("score", "lesson").": "; - } - echo "
".get_string("correctresponse", "lesson").":
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$i]"); - echo "
".get_string("wrongresponse", "lesson").":
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$i]"); - echo "
".get_string("answer", "lesson")." $icorrected:
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$i]"); - echo "
".get_string("matchesanswer", "lesson")." $icorrected:
\n"; - print_textarea(false, 6, 70, 630, 300, "response[$i]"); - echo "
".get_string("correctanswerjump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) { - echo get_string("correctanswerscore", "lesson").": "; - } - echo "
".get_string("wronganswerjump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) { - echo get_string("wronganswerscore", "lesson").": "; - } - echo "
".get_string("answer", "lesson")." $iplus1:
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$i]"); - echo "
".get_string("response", "lesson")." $iplus1:
\n"; - print_textarea(false, 6, 70, 630, 300, "response[$i]"); - echo "
".get_string("jump", "lesson")." $iplus1: \n"; - if ($i) { - // answers 2, 3, 4... jumpto this page - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - } else { - // answer 1 jumpto next page - lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); - } - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - /// CDC-FLAG /// - if($lesson->custom) { - if ($i) { - echo get_string("score", "lesson")." $iplus1: "; - } else { - echo get_string("score", "lesson")." $iplus1: "; - } - } - /// CDC-FLAG /// - echo "
".get_string("answer", "lesson")." $iplus1:
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$i]"); - echo "
".get_string("response", "lesson")." $iplus1:
\n"; - print_textarea(false, 6, 70, 630, 300, "response[$i]"); - echo "
".get_string("jump", "lesson")." $iplus1: \n"; - if ($i) { - // answers 2, 3, 4... jumpto this page - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - } else { - // answer 1 jumpto next page - lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); - } - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - /// CDC-FLAG /// - if($lesson->custom) { - if ($i) { - echo get_string("score", "lesson")." $iplus1: "; - } else { - echo get_string("score", "lesson")." $iplus1: "; - } - } - /// CDC-FLAG /// - echo "
".get_string("answer", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("response", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "response[$i]"); + echo "
".get_string("jump", "lesson")." $iplus1: \n"; + if ($i) { + // answers 2, 3, 4... jumpto this page + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + } else { + // answer 1 jumpto next page + lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); + } + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + /// CDC-FLAG /// + if($lesson->custom) { + if ($i) { + echo get_string("score", "lesson")." $iplus1: "; + } else { + echo get_string("score", "lesson")." $iplus1: "; + } + } + /// CDC-FLAG /// + echo "
".get_string("jump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[0]", LESSON_NEXTPAGE, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if ($lesson->custom) { + echo get_string("score", "lesson").": "; + } + echo "
".get_string("correctresponse", "lesson").":
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("wrongresponse", "lesson").":
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("answer", "lesson")." $icorrected:
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("matchesanswer", "lesson")." $icorrected:
\n"; + print_textarea(false, 6, 70, 630, 300, "response[$i]"); + echo "
".get_string("correctanswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("correctanswerscore", "lesson").": "; + } + echo "
".get_string("wronganswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("wronganswerscore", "lesson").": "; + } + echo "
".get_string("answer", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("response", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "response[$i]"); + echo "
".get_string("jump", "lesson")." $iplus1: \n"; + if ($i) { + // answers 2, 3, 4... jumpto this page + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + } else { + // answer 1 jumpto next page + lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); + } + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + /// CDC-FLAG /// + if($lesson->custom) { + if ($i) { + echo get_string("score", "lesson")." $iplus1: "; + } else { + echo get_string("score", "lesson")." $iplus1: "; + } + } + /// CDC-FLAG /// + echo "
".get_string("answer", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("response", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "response[$i]"); + echo "
".get_string("jump", "lesson")." $iplus1: \n"; + if ($i) { + // answers 2, 3, 4... jumpto this page + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + } else { + // answer 1 jumpto next page + lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); + } + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + /// CDC-FLAG /// + if($lesson->custom) { + if ($i) { + echo get_string("score", "lesson")." $iplus1: "; + } else { + echo get_string("score", "lesson")." $iplus1: "; + } + } + /// CDC-FLAG /// + echo "

@@ -582,18 +582,18 @@ ">
- id)) { - error("Only teachers can look at this page"); - } - - confirm_sesskey(); + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } + + confirm_sesskey(); $pageid = required_param('pageid', PARAM_INT); if (!$thispage = get_record("lesson_pages", "id", $pageid)) { @@ -611,63 +611,63 @@ echo $title."
\n"; } } - notice_yesno(get_string("confirmdeletionofthispage","lesson"), - "lesson.php?action=delete&id=$cm->id&pageid=$pageid&sesskey=".$USER->sesskey, + notice_yesno(get_string("confirmdeletionofthispage","lesson"), + "lesson.php?action=delete&id=$cm->id&pageid=$pageid&sesskey=".$USER->sesskey, "view.php?id=$cm->id"); - } + } + + /****************** continue ************************************/ + elseif ($action == 'continue' ) { - /****************** continue ************************************/ - elseif ($action == 'continue' ) { + confirm_sesskey(); - confirm_sesskey(); + // left menu code + if ($lesson->displayleft) { + if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { + echo '
'; + // print the pages + echo '
'; + echo ''; + echo ''; + echo ''; + echo "
"; + echo "
".get_string('lessonmenu', 'lesson')."
"; + echo ""; + echo '
'; + lesson_print_tree_menu($lesson->id, $firstpageid, $cm->id); + echo '
'; //close lmlinks + echo '
'; + echo '
'; + } + } + + /// 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 /// - // left menu code - if ($lesson->displayleft) { - if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { - echo '
'; - // print the pages - echo "
\n"; - echo "id\">\n"; - echo "\n"; - echo "\n"; - echo ""; - echo ""; - echo '"; - echo "
".get_string("lessonmenu", "lesson")."
'; - echo "id\">".get_string("mainmenu", "lesson")."
"; - lesson_print_tree_menu($lesson->id, $firstpageid, $cm->id); - echo "
"; - echo "
"; - echo '
'; - } - } - - /// 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 /// - - /// CDC-FLAG /// 6/14/04 -- This is the code updates the lesson time for a timed test - $outoftime = false; - if($lesson->timed) { - if(isteacher($course->id)) { - echo "

".get_string("teachertimerwarning", "lesson")."

"; - } else { - 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); + /// CDC-FLAG /// 6/14/04 -- This is the code updates the lesson time for a timed test + $outoftime = false; + if($lesson->timed) { + if(isteacher($course->id)) { + echo "

".get_string("teachertimerwarning", "lesson")."

"; + } else { + 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"). - "
"; + "
".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")); - } - if ((($timer->starttime + $lesson->maxtime * 60) - time()) < 60 && !((($timer->starttime + $lesson->maxtime * 60) - time()) < 0)) { - echo "

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

"; - } elseif (($timer->starttime + $lesson->maxtime * 60) < time()) { - echo "

".get_string("studentoutoftime", "lesson")."

"; - $outoftime = true; - } - $newtime = new stdClass; - $newtime->id = $timer->id; - $newtime->lessontime = time(); - - if (!update_record("lesson_timer", $newtime)) { - error("Error: could not update lesson_timer table"); - } - } - } - /// CDC-FLAG /// + print_simple_box_end(); + echo "



"; + } else { + redirect("view.php?id=$cm->id&action=navigation&pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson")); + } + if ((($timer->starttime + $lesson->maxtime * 60) - time()) < 60 && !((($timer->starttime + $lesson->maxtime * 60) - time()) < 0)) { + echo "

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

"; + } elseif (($timer->starttime + $lesson->maxtime * 60) < time()) { + echo "

".get_string("studentoutoftime", "lesson")."

"; + $outoftime = true; + } + $newtime = new stdClass; + $newtime->id = $timer->id; + $newtime->lessontime = time(); + + if (!update_record("lesson_timer", $newtime)) { + error("Error: could not update lesson_timer table"); + } + } + } + /// CDC-FLAG /// // record answer (if necessary) and show response (if none say if answer is correct or not) if (empty($_POST['pageid'])) { - error("Continue: pageid missing"); - } + error("Continue: pageid missing"); + } $pageid = required_param('pageid', PARAM_INT); if (!$page = get_record("lesson_pages", "id", $pageid)) { error("Continue: Page record not found"); @@ -712,69 +712,69 @@ $correctanswer = false; $newpageid = 0; // stay on the page switch ($page->qtype) { - /// CDC-FLAG /// - case LESSON_ESSAY : + /// CDC-FLAG /// + case LESSON_ESSAY : if (!$useranswer = $_POST['answer']) { $noanswer = true; break; } - $useranswer = clean_param($useranswer, PARAM_CLEAN); - - if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { + $useranswer = clean_param($useranswer, PARAM_CLEAN); + + if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { error("Continue: No answers found"); } - $correctanswer = false; - $response = "Your essay will be graded by the course instructor."; - foreach ($answers as $answer) { - $answerid = $answer->id; - $newpageid = $answer->jumpto; - } - /// 6/29/04 // - $userresponse->sent=0; - $userresponse->graded = 0; - $userresponse->score = 0; - $userresponse->answer = $useranswer; - $userresponse->response = ""; - $userresponse = addslashes(serialize($userresponse)); - - break; - /// CDC-FLAG /// - case LESSON_SHORTANSWER : + $correctanswer = false; + $response = "Your essay will be graded by the course instructor."; + foreach ($answers as $answer) { + $answerid = $answer->id; + $newpageid = $answer->jumpto; + } + /// 6/29/04 // + $userresponse->sent=0; + $userresponse->graded = 0; + $userresponse->score = 0; + $userresponse->answer = $useranswer; + $userresponse->response = ""; + $userresponse = addslashes(serialize($userresponse)); + + break; + /// CDC-FLAG /// + case LESSON_SHORTANSWER : if (!$useranswer = $_POST['answer']) { $noanswer = true; break; } - $useranswer = clean_param($useranswer, PARAM_CLEAN); - $userresponse = addslashes($useranswer); - + $useranswer = clean_param($useranswer, PARAM_CLEAN); + $userresponse = addslashes($useranswer); + if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { error("Continue: No answers found"); } foreach ($answers as $answer) { - /// CDC-FLAG /// - if ($lesson->custom && $answer->score > 0) { - if ($page->qoption) { - // case sensitive - if ($answer->answer == $useranswer) { - $correctanswer = true; - $answerid = $answer->id; - $newpageid = $answer->jumpto; - if (trim(strip_tags($answer->response))) { - $response = $answer->response; - } - } - } else { - // case insensitive - if (strcasecmp($answer->answer, $useranswer) == 0) { - $correctanswer = true; - $answerid = $answer->id; - $newpageid = $answer->jumpto; - if (trim(strip_tags($answer->response))) { - $response = $answer->response; - } - } - } - } elseif (lesson_iscorrect($pageid, $answer->jumpto) && !$lesson->custom) { /// CDC-FLAG 6/21/04 /// + /// CDC-FLAG /// + if ($lesson->custom && $answer->score > 0) { + if ($page->qoption) { + // case sensitive + if ($answer->answer == $useranswer) { + $correctanswer = true; + $answerid = $answer->id; + $newpageid = $answer->jumpto; + if (trim(strip_tags($answer->response))) { + $response = $answer->response; + } + } + } else { + // case insensitive + if (strcasecmp($answer->answer, $useranswer) == 0) { + $correctanswer = true; + $answerid = $answer->id; + $newpageid = $answer->jumpto; + if (trim(strip_tags($answer->response))) { + $response = $answer->response; + } + } + } + } elseif (lesson_iscorrect($pageid, $answer->jumpto) && !$lesson->custom) { /// CDC-FLAG 6/21/04 /// if ($page->qoption) { // case sensitive if ($answer->answer == $useranswer) { @@ -799,7 +799,7 @@ // don't worry about case if (strcasecmp($answer->answer, $useranswer) == 0) { $newpageid = $answer->jumpto; - $answerid = $answer->id; + $answerid = $answer->id; if (trim(strip_tags($answer->response))) { $response = $answer->response; } @@ -814,28 +814,28 @@ } } break; - + case LESSON_TRUEFALSE : if (empty($_POST['answerid'])) { $noanswer = true; break; } - $answerid = required_param('answerid', PARAM_INT); + $answerid = required_param('answerid', PARAM_INT); if (!$answer = get_record("lesson_answers", "id", $answerid)) { error("Continue: answer record not found"); - } + } if (lesson_iscorrect($pageid, $answer->jumpto)) { $correctanswer = true; - } - /* CDC-FLAG */ - if ($lesson->custom) { - if ($answer->score > 0) { - $correctanswer = true; - } else { - $correctanswer = false; - } - } - /// CDC-FLAG 6/21/04 /// + } + /* CDC-FLAG */ + if ($lesson->custom) { + if ($answer->score > 0) { + $correctanswer = true; + } else { + $correctanswer = false; + } + } + /// CDC-FLAG 6/21/04 /// $newpageid = $answer->jumpto; if (!$response = trim($answer->response)) { if ($correctanswer) { @@ -845,7 +845,7 @@ } } break; - + case LESSON_MULTICHOICE : if ($page->qoption) { // MULTIANSWER allowed, user's answer is an array @@ -855,8 +855,8 @@ $noanswer = true; break; } - // get what the user answered - $userresponse = implode(",", $useranswers); + // get what the user answered + $userresponse = implode(",", $useranswers); // get the answers in a set order, the id order if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { error("Continue: No answers found"); @@ -865,72 +865,72 @@ $nhits = 0; $correctresponse = ''; $wrongresponse = ''; - /// CDC-FLAG /// 6/11/04 this is for custom scores. If score on answer is positive, it is correct - if ($lesson->custom) { - $ncorrect = 0; - $nhits = 0; - foreach ($answers as $answer) { - if ($answer->score > 0) { - $ncorrect++; - - foreach ($useranswers as $key => $answerid) { - if ($answerid == $answer->id) { - $nhits++; - } - } - // save the first jumpto page id, may be needed!... - if (!isset($correctpageid)) { - // leave in its "raw" state - will converted into a proper page id later - $correctpageid = $answer->jumpto; - } - // ...also save any response from the correct answers... - if (trim(strip_tags($answer->response))) { - $correctresponse = $answer->response; - } - } else { - // save the first jumpto page id, may be needed!... - if (!isset($wrongpageid)) { - // leave in its "raw" state - will converted into a proper page id later - $wrongpageid = $answer->jumpto; - } - // ...and from the incorrect ones, don't know which to use at this stage - if (trim(strip_tags($answer->response))) { - $wrongresponse = $answer->response; - } - } - } - } else { - foreach ($answers as $answer) { - if (lesson_iscorrect($pageid, $answer->jumpto)) { - $ncorrect++; - foreach ($useranswers as $key => $answerid) { - if ($answerid == $answer->id) { - $nhits++; - } - } - // save the first jumpto page id, may be needed!... - if (!isset($correctpageid)) { - // leave in its "raw" state - will converted into a proper page id later - $correctpageid = $answer->jumpto; - } - // ...also save any response from the correct answers... - if (trim(strip_tags($answer->response))) { - $correctresponse = $answer->response; - } - } else { - // save the first jumpto page id, may be needed!... - if (!isset($wrongpageid)) { - // leave in its "raw" state - will converted into a proper page id later - $wrongpageid = $answer->jumpto; - } - // ...and from the incorrect ones, don't know which to use at this stage - if (trim(strip_tags($answer->response))) { - $wrongresponse = $answer->response; - } - } - } - } - /// CDC-FLAG /// + /// CDC-FLAG /// 6/11/04 this is for custom scores. If score on answer is positive, it is correct + if ($lesson->custom) { + $ncorrect = 0; + $nhits = 0; + foreach ($answers as $answer) { + if ($answer->score > 0) { + $ncorrect++; + + foreach ($useranswers as $key => $answerid) { + if ($answerid == $answer->id) { + $nhits++; + } + } + // save the first jumpto page id, may be needed!... + if (!isset($correctpageid)) { + // leave in its "raw" state - will converted into a proper page id later + $correctpageid = $answer->jumpto; + } + // ...also save any response from the correct answers... + if (trim(strip_tags($answer->response))) { + $correctresponse = $answer->response; + } + } else { + // save the first jumpto page id, may be needed!... + if (!isset($wrongpageid)) { + // leave in its "raw" state - will converted into a proper page id later + $wrongpageid = $answer->jumpto; + } + // ...and from the incorrect ones, don't know which to use at this stage + if (trim(strip_tags($answer->response))) { + $wrongresponse = $answer->response; + } + } + } + } else { + foreach ($answers as $answer) { + if (lesson_iscorrect($pageid, $answer->jumpto)) { + $ncorrect++; + foreach ($useranswers as $key => $answerid) { + if ($answerid == $answer->id) { + $nhits++; + } + } + // save the first jumpto page id, may be needed!... + if (!isset($correctpageid)) { + // leave in its "raw" state - will converted into a proper page id later + $correctpageid = $answer->jumpto; + } + // ...also save any response from the correct answers... + if (trim(strip_tags($answer->response))) { + $correctresponse = $answer->response; + } + } else { + // save the first jumpto page id, may be needed!... + if (!isset($wrongpageid)) { + // leave in its "raw" state - will converted into a proper page id later + $wrongpageid = $answer->jumpto; + } + // ...and from the incorrect ones, don't know which to use at this stage + if (trim(strip_tags($answer->response))) { + $wrongresponse = $answer->response; + } + } + } + } + /// CDC-FLAG /// if ((count($useranswers) == $ncorrect) and ($nhits == $ncorrect)) { $correctanswer = true; if (!$response = $correctresponse) { @@ -949,22 +949,22 @@ $noanswer = true; break; } - $answerid = required_param('answerid', PARAM_INT); + $answerid = required_param('answerid', PARAM_INT); if (!$answer = get_record("lesson_answers", "id", $answerid)) { error("Continue: answer record not found"); } if (lesson_iscorrect($pageid, $answer->jumpto)) { $correctanswer = true; - } - /* CDC-FLAG */ - if ($lesson->custom) { - if ($answer->score > 0) { - $correctanswer = true; - } else { - $correctanswer = false; - } - } - /// CDC-FLAG /// + } + /* CDC-FLAG */ + if ($lesson->custom) { + if ($answer->score > 0) { + $correctanswer = true; + } else { + $correctanswer = false; + } + } + /// CDC-FLAG /// $newpageid = $answer->jumpto; if (!$response = trim($answer->response)) { if ($correctanswer) { @@ -975,8 +975,8 @@ } } break; - - /// CDC-FLAG /// 6/14/04 -- added responses + + /// CDC-FLAG /// 6/14/04 -- added responses case LESSON_MATCHING : if (isset($_POST['response']) && is_array($_POST['response'])) { // only arrays should be submitted $response = $_POST['response']; @@ -991,68 +991,68 @@ $ncorrect = 0; $i = 0; foreach ($answers as $answer) { - if ($i == 0 || $i == 1) { - // ignore first two answers, they are correct response - // and wrong response - $i++; - continue; - } + if ($i == 0 || $i == 1) { + // ignore first two answers, they are correct response + // and wrong response + $i++; + continue; + } if ($answer->response == $response[$answer->id]) { $ncorrect++; } if ($i == 2) { $correctpageid = $answer->jumpto; - $correctanswerid = $answer->id; + $correctanswerid = $answer->id; } if ($i == 3) { $wrongpageid = $answer->jumpto; - $wronganswerid = $answer->id; + $wronganswerid = $answer->id; } $i++; } - // get he users exact responses for record keeping - foreach ($response as $value) { - foreach($answers as $answer) { - if ($value == $answer->response) { - $userresponse[] = $answer->id; - } - } - } - $userresponse = implode(",", $userresponse); + // get he users exact responses for record keeping + foreach ($response as $value) { + foreach($answers as $answer) { + if ($value == $answer->response) { + $userresponse[] = $answer->id; + } + } + } + $userresponse = implode(",", $userresponse); if ($ncorrect == count($answers)-2) { // dont count correct/wrong responses in the total. - $response = get_string("thatsthecorrectanswer", "lesson"); - foreach ($answers as $answer) { - if ($answer->response == NULL && $answer->answer != NULL) { - $response = $answer->answer; - break; - } - } - // NoticeFix + $response = get_string("thatsthecorrectanswer", "lesson"); + foreach ($answers as $answer) { + if ($answer->response == NULL && $answer->answer != NULL) { + $response = $answer->answer; + break; + } + } + // NoticeFix if (isset($correctpageid)) { - $newpageid = $correctpageid; - } - if (isset($correctanswerid)) { - $answerid = $correctanswerid; - } + $newpageid = $correctpageid; + } + if (isset($correctanswerid)) { + $answerid = $correctanswerid; + } $correctanswer = true; } else { - $response = get_string("thatsthewronganswer", "lesson"); - $t = 0; - foreach ($answers as $answer) { - if ($answer->response == NULL && $answer->answer != NULL) { - if ($t == 1) { - $response = $answer->answer; - break; - } - $t++; - } - } + $response = get_string("thatsthewronganswer", "lesson"); + $t = 0; + foreach ($answers as $answer) { + if ($answer->response == NULL && $answer->answer != NULL) { + if ($t == 1) { + $response = $answer->answer; + break; + } + $t++; + } + } $newpageid = $wrongpageid; - $answerid = $wronganswerid; + $answerid = $wronganswerid; } break; - /// CDC-FLAG /// + /// CDC-FLAG /// case LESSON_NUMERICAL : // set defaults @@ -1060,12 +1060,12 @@ $newpageid = 0; if (isset($_POST['answer'])) { - $useranswer = (float) optional_param('answer'); // just doing default PARAM_CLEAN, not doing PARAM_INT because it could be a float - } else { + $useranswer = (float) optional_param('answer'); // just doing default PARAM_CLEAN, not doing PARAM_INT because it could be a float + } else { $noanswer = true; break; - } - $userresponse = $useranswer; + } + $userresponse = $useranswer; if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { error("Continue: No answers found"); } @@ -1086,16 +1086,16 @@ if (lesson_iscorrect($pageid, $newpageid)) { $correctanswer = true; } - /// CDC-FLAG /// - if ($lesson->custom) { - if ($answer->score > 0) { - $correctanswer = true; - $answerid = $answer->id; - } else { - $correctanswer = false; - } - } - /// CDC-FLAG /// + /// CDC-FLAG /// + if ($lesson->custom) { + if ($answer->score > 0) { + $correctanswer = true; + $answerid = $answer->id; + } else { + $correctanswer = false; + } + } + /// CDC-FLAG /// break; } } @@ -1107,46 +1107,46 @@ if (!$response) { $response = get_string("thatsthewronganswer", "lesson"); } - } + } break; case LESSON_BRANCHTABLE: $noanswer = false; $newpageid = optional_param('jumpto', NULL, PARAM_INT); - /// CDC-FLAG /// 6/15/04 going to insert into lesson_branch - if ($newpageid == LESSON_RANDOMBRANCH) { - $branchflag = 1; - } else { - $branchflag = 0; - } - if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND userid = $USER->id", - "grade DESC")) { - $retries = count($grades); - } else { - $retries = 0; - } - $branch = new stdClass; - $branch->lessonid = $lesson->id; - $branch->userid = $USER->id; - $branch->pageid = $pageid; - $branch->retry = $retries; - $branch->flag = $branchflag; - $branch->timeseen = time(); + /// CDC-FLAG /// 6/15/04 going to insert into lesson_branch + if ($newpageid == LESSON_RANDOMBRANCH) { + $branchflag = 1; + } else { + $branchflag = 0; + } + if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND userid = $USER->id", + "grade DESC")) { + $retries = count($grades); + } else { + $retries = 0; + } + $branch = new stdClass; + $branch->lessonid = $lesson->id; + $branch->userid = $USER->id; + $branch->pageid = $pageid; + $branch->retry = $retries; + $branch->flag = $branchflag; + $branch->timeseen = time(); + + if (!insert_record("lesson_branch", $branch)) { + error("Error: could not insert row into lesson_branch table"); + } + /// CDC-FLAG /// - if (!insert_record("lesson_branch", $branch)) { - error("Error: could not insert row into lesson_branch table"); - } - /// CDC-FLAG /// - - /// CDC-FLAG /// this is called when jumping to random from a branch table - if($newpageid == LESSON_UNSEENBRANCHPAGE) { - if (isteacher($course->id)) { - $newpageid = LESSON_NEXTPAGE; - } else { - $newpageid = lesson_unseen_question_jump($lesson->id, $USER->id, $pageid); // this may return 0 //CDC Chris Berri.....this is where it sets the next page id for unseen? - } - } - /// CDC-FLAG 6/15/04 /// + /// CDC-FLAG /// this is called when jumping to random from a branch table + if($newpageid == LESSON_UNSEENBRANCHPAGE) { + if (isteacher($course->id)) { + $newpageid = LESSON_NEXTPAGE; + } else { + $newpageid = lesson_unseen_question_jump($lesson->id, $USER->id, $pageid); // this may return 0 //CDC Chris Berri.....this is where it sets the next page id for unseen? + } + } + /// CDC-FLAG 6/15/04 /// // convert jumpto page into a proper page id if ($newpageid == 0) { $newpageid = $pageid; @@ -1155,53 +1155,53 @@ // no nextpage go to end of lesson $newpageid = LESSON_EOL; } - echo $newpageid; + echo $newpageid; /* CDC-FLAG */ } elseif ($newpageid == LESSON_PREVIOUSPAGE) { - $newpageid = $page->prevpageid; - } elseif ($newpageid == LESSON_RANDOMPAGE) { - $newpageid = lesson_random_question_jump($lesson->id, $pageid); - } elseif ($newpageid == LESSON_RANDOMBRANCH) { // 6/15/04 - $newpageid = lesson_unseen_branch_jump($lesson->id, $USER->id); - } - /// CDC-FLAG /// - // no need to record anything in lesson_attempts + $newpageid = $page->prevpageid; + } elseif ($newpageid == LESSON_RANDOMPAGE) { + $newpageid = lesson_random_question_jump($lesson->id, $pageid); + } elseif ($newpageid == LESSON_RANDOMBRANCH) { // 6/15/04 + $newpageid = lesson_unseen_branch_jump($lesson->id, $USER->id); + } + /// CDC-FLAG /// + // no need to record anything in lesson_attempts redirect("view.php?id=$cm->id&action=navigation&pageid=$newpageid"); - print_footer($course); + print_footer($course); exit(); break; - + } if ($noanswer) { $newpageid = $pageid; // display same page again print_simple_box(get_string("noanswer", "lesson"), "center"); } else { - $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); + $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); if (isstudent($course->id)) { // record student's attempt - $attempt = new stdClass; + $attempt = new stdClass; $attempt->lessonid = $lesson->id; $attempt->pageid = $pageid; $attempt->userid = $USER->id; $attempt->answerid = $answerid; $attempt->retry = $nretakes; $attempt->correct = $correctanswer; - if(isset($userresponse)) { - $attempt->useranswer = $userresponse; - } + if(isset($userresponse)) { + $attempt->useranswer = $userresponse; + } $attempt->timeseen = time(); - /// CDC-FLAG /// -- dont want to insert the attempt if they ran out of time - if (!$outoftime) { - // if allow modattempts, then update the old attempt record, otherwise, insert new answer record + /// CDC-FLAG /// -- dont want to insert the attempt if they ran out of time + if (!$outoftime) { + // if allow modattempts, then update the old attempt record, otherwise, insert new answer record if (isset($USER->modattempts[$lesson->id])) { - $attempt->retry = $nretakes - 1; // they are going through on review, $nretakes will be too high - } - if (!$newattemptid = insert_record("lesson_attempts", $attempt)) { - error("Continue: attempt not inserted"); - } - } - /// CDC-FLAG /// + $attempt->retry = $nretakes - 1; // they are going through on review, $nretakes will be too high + } + if (!$newattemptid = insert_record("lesson_attempts", $attempt)) { + error("Continue: attempt not inserted"); + } + } + /// CDC-FLAG /// if (!$correctanswer and ($newpageid == 0)) { - // wrong answer and student is stuck on this page - check how many attempts + // wrong answer and student is stuck on this page - check how many attempts // the student has had at this page/question $nattempts = count_records("lesson_attempts", "pageid", $pageid, "userid", $USER->id, "retry", $nretakes); @@ -1228,7 +1228,7 @@ $found = false; if ($lesson->nextpagedefault == LESSON_UNSEENPAGE) { foreach ($allpages as $thispage) { - if (!count_records("lesson_attempts", "pageid", $thispage->id, "userid", + if (!count_records("lesson_attempts", "pageid", $thispage->id, "userid", $USER->id, "retry", $nretakes)) { $found = true; break; @@ -1237,18 +1237,18 @@ } elseif ($lesson->nextpagedefault == LESSON_UNANSWEREDPAGE) { foreach ($allpages as $thispage) { if ($thispage->qtype == LESSON_ESSAY) { - if (!count_records_select("lesson_attempts", "pageid = $thispage->id AND - userid = $USER->id AND retry = $nretakes")) { - $found = true; - break; - } - } else { - if (!count_records_select("lesson_attempts", "pageid = $thispage->id AND - userid = $USER->id AND correct = 1 AND retry = $nretakes")) { - $found = true; - break; - } - } + if (!count_records_select("lesson_attempts", "pageid = $thispage->id AND + userid = $USER->id AND retry = $nretakes")) { + $found = true; + break; + } + } else { + if (!count_records_select("lesson_attempts", "pageid = $thispage->id AND + userid = $USER->id AND correct = 1 AND retry = $nretakes")) { + $found = true; + break; + } + } } } if ($found) { @@ -1268,166 +1268,166 @@ $newpageid = LESSON_EOL; } } - - /// CDC-FLAG 6/21/04 /// this calculates the ongoing score - if ($lesson->ongoing) { - 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); - } - } - /// CDC-FLAG /// - + + /// CDC-FLAG 6/21/04 /// this calculates the ongoing score + if ($lesson->ongoing) { + 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); + } + } + /// CDC-FLAG /// + // display response (if there is one - there should be!) if ($response) { //$title = get_field("lesson_pages", "title", "id", $pageid); //print_heading($title); echo "
\n"; - if ($lesson->review && !$correctanswer) { - $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); - $qattempts = count_records("lesson_attempts", "userid", $USER->id, "retry", $nretakes, "pageid", $pageid); - echo "

"; - if ($qattempts == 1) { - print_simple_box(get_string("firstwrong", "lesson"), "center"); - } else { - print_simple_box(get_string("secondpluswrong", "lesson"), "center"); - } - } else { - print_simple_box(format_text($response), 'center'); - } + if ($lesson->review && !$correctanswer) { + $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); + $qattempts = count_records("lesson_attempts", "userid", $USER->id, "retry", $nretakes, "pageid", $pageid); + echo "

"; + if ($qattempts == 1) { + print_simple_box(get_string("firstwrong", "lesson"), "center"); + } else { + print_simple_box(get_string("secondpluswrong", "lesson"), "center"); + } + } else { + print_simple_box(format_text($response), 'center'); + } echo "
\n"; - } + } } - - /// CDC-FLAG 6/18/04 /// - this is where some jump numbers are interpreted - if($outoftime) { - $newpageid = LESSON_EOL; // ran out of time for the test, so go to eol - } elseif (isset($USER->modattempts[$lesson->id])) { - // make sure if the student is reviewing, that he/she sees the same pages/page path that he/she saw the first time - if ($USER->modattempts[$lesson->id] == $pageid) { // remember, this session variable holds the pageid of the last page that the user saw - $newpageid = LESSON_EOL; - } else { - $nretakes--; // make sure we are looking at the right try. - $attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $nretakes", "timeseen", "id, pageid"); - $found = false; - $temppageid = 0; - foreach($attempts as $attempt) { - if ($found && $temppageid != $attempt->pageid) { // now try to find the next page, make sure next few attempts do no belong to current page - $newpageid = $attempt->pageid; - break; - } - if ($attempt->pageid == $pageid) { - $found = true; // if found current page - $temppageid = $attempt->pageid; - } - } - } - } elseif ($newpageid != LESSON_CLUSTERJUMP && $pageid != 0 && $newpageid > 0) { // going to check to see if the page that the user is going to view next, is a cluster page. If so, dont display, go into the cluster. The $newpageid > 0 is used to filter out all of the negative code jumps. - if (!$page = get_record("lesson_pages", "id", $newpageid)) { - error("Error: could not find page"); - } - if ($page->qtype == LESSON_CLUSTER) { - $newpageid = LESSON_CLUSTERJUMP; - } elseif ($page->qtype == LESSON_ENDOFCLUSTER) { - $jump = get_field("lesson_answers", "jumpto", "pageid", $page->id, "lessonid", $lesson->id); - if ($jump == LESSON_NEXTPAGE) { - if ($page->nextpageid == 0) { - $newpageid = LESSON_EOL; - } else { - $newpageid = $page->nextpageid; - } - } else { - $newpageid = $jump; - } - } - } elseif ($newpageid == LESSON_UNSEENBRANCHPAGE) { - if (isteacher($course->id)) { - if ($page->nextpageid == 0) { - $newpageid = LESSON_EOL; - } else { - $newpageid = $page->nextpageid; - } - } else { - $newpageid = lesson_unseen_question_jump($lesson->id, $USER->id, $pageid); - } - } elseif ($newpageid == LESSON_PREVIOUSPAGE) { - $newpageid = $page->prevpageid; - } elseif ($newpageid == LESSON_RANDOMPAGE) { - $newpageid = lesson_random_question_jump($lesson->id, $pageid); - } elseif ($newpageid == LESSON_CLUSTERJUMP) { - if (isteacher($course->id)) { - if ($page->nextpageid == 0) { // if teacher, go to next page - $newpageid = LESSON_EOL; - } else { - $newpageid = $page->nextpageid; - } - } else { - $newpageid = lesson_cluster_jump($lesson->id, $USER->id, $pageid); - } - } + + /// CDC-FLAG 6/18/04 /// - this is where some jump numbers are interpreted + if($outoftime) { + $newpageid = LESSON_EOL; // ran out of time for the test, so go to eol + } elseif (isset($USER->modattempts[$lesson->id])) { + // make sure if the student is reviewing, that he/she sees the same pages/page path that he/she saw the first time + if ($USER->modattempts[$lesson->id] == $pageid) { // remember, this session variable holds the pageid of the last page that the user saw + $newpageid = LESSON_EOL; + } else { + $nretakes--; // make sure we are looking at the right try. + $attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $nretakes", "timeseen", "id, pageid"); + $found = false; + $temppageid = 0; + foreach($attempts as $attempt) { + if ($found && $temppageid != $attempt->pageid) { // now try to find the next page, make sure next few attempts do no belong to current page + $newpageid = $attempt->pageid; + break; + } + if ($attempt->pageid == $pageid) { + $found = true; // if found current page + $temppageid = $attempt->pageid; + } + } + } + } elseif ($newpageid != LESSON_CLUSTERJUMP && $pageid != 0 && $newpageid > 0) { // going to check to see if the page that the user is going to view next, is a cluster page. If so, dont display, go into the cluster. The $newpageid > 0 is used to filter out all of the negative code jumps. + if (!$page = get_record("lesson_pages", "id", $newpageid)) { + error("Error: could not find page"); + } + if ($page->qtype == LESSON_CLUSTER) { + $newpageid = LESSON_CLUSTERJUMP; + } elseif ($page->qtype == LESSON_ENDOFCLUSTER) { + $jump = get_field("lesson_answers", "jumpto", "pageid", $page->id, "lessonid", $lesson->id); + if ($jump == LESSON_NEXTPAGE) { + if ($page->nextpageid == 0) { + $newpageid = LESSON_EOL; + } else { + $newpageid = $page->nextpageid; + } + } else { + $newpageid = $jump; + } + } + } elseif ($newpageid == LESSON_UNSEENBRANCHPAGE) { + if (isteacher($course->id)) { + if ($page->nextpageid == 0) { + $newpageid = LESSON_EOL; + } else { + $newpageid = $page->nextpageid; + } + } else { + $newpageid = lesson_unseen_question_jump($lesson->id, $USER->id, $pageid); + } + } elseif ($newpageid == LESSON_PREVIOUSPAGE) { + $newpageid = $page->prevpageid; + } elseif ($newpageid == LESSON_RANDOMPAGE) { + $newpageid = lesson_random_question_jump($lesson->id, $pageid); + } elseif ($newpageid == LESSON_CLUSTERJUMP) { + if (isteacher($course->id)) { + if ($page->nextpageid == 0) { // if teacher, go to next page + $newpageid = LESSON_EOL; + } else { + $newpageid = $page->nextpageid; + } + } else { + $newpageid = lesson_cluster_jump($lesson->id, $USER->id, $pageid); + } + } echo "
\n"; echo "id\">\n"; echo "\n"; echo "\n"; - if (isset($USER->modattempts[$lesson->id])) { - echo "

". - get_string("savechangesandeol", "lesson")."

". - "

\n"; - echo "

".get_string("or", "lesson")."

". - get_string("continuetoanswer", "lesson")."

\n"; - } - if ($lesson->review && !$correctanswer && !$noanswer) { - echo "

\n"; - echo "

\n"; - } else { - echo "

\n"; - } - echo "
\n"; + if (isset($USER->modattempts[$lesson->id])) { + echo "

". + get_string("savechangesandeol", "lesson")."

". + "

\n"; + echo "

".get_string("or", "lesson")."

". + get_string("continuetoanswer", "lesson")."

\n"; + } + if ($lesson->review && !$correctanswer && !$noanswer) { + echo "

\n"; + echo "

\n"; + } else { + echo "

\n"; + } + echo "\n"; - if ($lesson->displayleft) { - echo "
"; - } - } + if ($lesson->displayleft) { + echo "
"; + } + } + + /******************* delete ************************************/ + elseif ($action == 'delete' ) { - /******************* delete ************************************/ - elseif ($action == 'delete' ) { + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } + + confirm_sesskey(); - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } - - confirm_sesskey(); - - if (empty($_GET['pageid'])) { - error("Delete: pageid missing"); - } + if (empty($_GET['pageid'])) { + error("Delete: pageid missing"); + } $pageid = required_param('pageid', PARAM_INT); - if (!$thispage = get_record("lesson_pages", "id", $pageid)) { - error("Delete: page record not found"); + if (!$thispage = get_record("lesson_pages", "id", $pageid)) { + error("Delete: page record not found"); } - + print_string("deleting", "lesson"); - // first delete all the associated records... - delete_records("lesson_attempts", "pageid", $pageid); - // ...now delete the answers... - delete_records("lesson_answers", "pageid", $pageid); + // first delete all the associated records... + delete_records("lesson_attempts", "pageid", $pageid); + // ...now delete the answers... + delete_records("lesson_answers", "pageid", $pageid); // ..and the page itself delete_records("lesson_pages", "id", $pageid); - + // repair the hole in the linkage if (!$thispage->prevpageid) { // this is the first page... @@ -1460,45 +1460,45 @@ error("Delete: unable to set prev link"); } } - redirect("view.php?id=$cm->id", get_string('deletedpage', 'lesson')); - } + redirect("view.php?id=$cm->id", get_string('deletedpage', 'lesson')); + } + - - /************** edit page ************************************/ + /************** edit page ************************************/ elseif ($action == 'editpage' ) { - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } // get the page - $pageid = required_param('pageid', PARAM_INT); + $pageid = required_param('pageid', PARAM_INT); if (!$page = get_record("lesson_pages", "id", $pageid)) { error("Edit page: page record not found"); } - - if (isset($_GET['qtype'])) { - $page->qtype = required_param('qtype', PARAM_INT); - } - + + if (isset($_GET['qtype'])) { + $page->qtype = required_param('qtype', PARAM_INT); + } + // set of jump array - $jump = array(); + $jump = array(); $jump[0] = get_string("thispage", "lesson"); $jump[LESSON_NEXTPAGE] = get_string("nextpage", "lesson"); - //// CDC-FLAG 6/18/04 ///// - $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson"); - if(lesson_display_branch_jumps($lesson->id, $page->id)) { - $jump[LESSON_UNSEENBRANCHPAGE] = get_string("unseenpageinbranch", "lesson"); - $jump[LESSON_RANDOMPAGE] = get_string("randompageinbranch", "lesson"); - } - if ($page->qtype == LESSON_ENDOFBRANCH || $page->qtype == LESSON_BRANCHTABLE) { - $jump[LESSON_RANDOMBRANCH] = get_string("randombranch", "lesson"); - } - if(lesson_display_cluster_jump($lesson->id, $page->id) && $page->qtype != LESSON_BRANCHTABLE && $page->qtype != LESSON_ENDOFCLUSTER) { - $jump[LESSON_CLUSTERJUMP] = get_string("clusterjump", "lesson"); - } - //// CDC-FLAG ///// + //// CDC-FLAG 6/18/04 ///// + $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson"); + if(lesson_display_branch_jumps($lesson->id, $page->id)) { + $jump[LESSON_UNSEENBRANCHPAGE] = get_string("unseenpageinbranch", "lesson"); + $jump[LESSON_RANDOMPAGE] = get_string("randompageinbranch", "lesson"); + } + if ($page->qtype == LESSON_ENDOFBRANCH || $page->qtype == LESSON_BRANCHTABLE) { + $jump[LESSON_RANDOMBRANCH] = get_string("randombranch", "lesson"); + } + if(lesson_display_cluster_jump($lesson->id, $page->id) && $page->qtype != LESSON_BRANCHTABLE && $page->qtype != LESSON_ENDOFCLUSTER) { + $jump[LESSON_CLUSTERJUMP] = get_string("clusterjump", "lesson"); + } + //// CDC-FLAG ///// $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); if (!$apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { error("Edit page: first page not found"); @@ -1508,10 +1508,10 @@ if (!$apage = get_record("lesson_pages", "id", $apageid)) { error("Edit page: apage record not found"); } - /// CDC-FLAG /// 6/15/04 removed != LESSON_ENDOFBRANCH... - if (trim($page->title)) { // ...nor nuffin pages - $jump[$apageid] = $apage->title; - } + /// CDC-FLAG /// 6/15/04 removed != LESSON_ENDOFBRANCH... + if (trim($page->title)) { // ...nor nuffin pages + $jump[$apageid] = $apage->title; + } $apageid = $apage->nextpageid; } else { // last page reached @@ -1524,58 +1524,58 @@ - +
- qtype) { - case LESSON_MULTICHOICE : - echo "\n"; - break; - case LESSON_SHORTANSWER : - echo "\n"; - break; - case LESSON_TRUEFALSE : - case LESSON_ESSAY : - case LESSON_MATCHING : - case LESSON_NUMERICAL : - echo "\n"; - break; - } - ?> - \n"; + break; + case LESSON_SHORTANSWER : + echo "\n"; + break; + case LESSON_TRUEFALSE : + case LESSON_ESSAY : + case LESSON_MATCHING : + case LESSON_NUMERICAL : + echo "\n"; + break; + } + ?> + @@ -1590,128 +1590,128 @@ switch ($page->qtype) { case LESSON_BRANCHTABLE : echo "qtype\">\n"; - /// CDC-FLAG /// 6/16/04 - echo "\n"; - /// CDC-FLAG /// + /// CDC-FLAG /// 6/16/04 + echo "\n"; + /// CDC-FLAG /// echo "\n"; // get the answers in a set order, the id order if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { - foreach ($answers as $answer) { + foreach ($answers as $answer) { $flags = intval($answer->flags); // force into an integer $nplus1 = $n + 1; echo "id\">\n"; switch ($page->qtype) { case LESSON_MATCHING: - if ($n == 0) { - echo "\n"; - echo "\n"; + if ($n == 0) { + echo "\n"; + echo "\n"; break; case LESSON_TRUEFALSE: case LESSON_MULTICHOICE: case LESSON_SHORTANSWER: - case LESSON_NUMERICAL: + case LESSON_NUMERICAL: echo "\n"; break; } - switch ($page->qtype) { - case LESSON_MATCHING : - if ($n == 2) { - echo "\n"; - break; - case LESSON_ESSAY : - echo "\n"; - break; + switch ($page->qtype) { + case LESSON_MATCHING : + if ($n == 2) { + echo "\n"; + break; + case LESSON_ESSAY : + echo "\n"; + break; case LESSON_TRUEFALSE: case LESSON_MULTICHOICE: case LESSON_SHORTANSWER: case LESSON_NUMERICAL: - echo "\n"; - break; - case LESSON_BRANCHTABLE: - case LESSON_CLUSTER: - case LESSON_ENDOFCLUSTER: - case LESSON_ENDOFBRANCH: - echo "\n"; - break; - } + echo "\n"; + break; + case LESSON_BRANCHTABLE: + case LESSON_CLUSTER: + case LESSON_ENDOFCLUSTER: + case LESSON_ENDOFBRANCH: + echo "\n"; + break; + } $n++; - if ($page->qtype == LESSON_ESSAY) { - break; // only one answer for essays - } + if ($page->qtype == LESSON_ESSAY) { + break; // only one answer for essays + } } } if ($page->qtype != LESSON_ENDOFBRANCH && $page->qtype != LESSON_CLUSTER && $page->qtype != LESSON_ENDOFCLUSTER) { /// CDC-FLAG 6/17/04 added to the condition /// - if ($page->qtype == LESSON_MATCHING) { - $maxanswers = $lesson->maxanswers + 2; - } else { - $maxanswers = $lesson->maxanswers; - } + if ($page->qtype == LESSON_MATCHING) { + $maxanswers = $lesson->maxanswers + 2; + } else { + $maxanswers = $lesson->maxanswers; + } for ($i = $n; $i < $maxanswers; $i++) { - if ($page->qtype == LESSON_TRUEFALSE && $i > 1) { - break; // stop printing answers... only need two for true/false - } + if ($page->qtype == LESSON_TRUEFALSE && $i > 1) { + break; // stop printing answers... only need two for true/false + } $iplus1 = $i + 1; echo "\n"; switch ($page->qtype) { case LESSON_MATCHING: - $icorrected = $i - 1; + $icorrected = $i - 1; echo "\n"; break; } - switch ($page->qtype) { - case LESSON_ESSAY : - if ($i < 1) { - echo "\n"; - } - break; - case LESSON_MATCHING : - if ($i == 2) { - echo "\n"; + } + break; + case LESSON_MATCHING : + if ($i == 2) { + echo "\n"; - break; + echo "\n"; + break; case LESSON_TRUEFALSE: case LESSON_MULTICHOICE: case LESSON_SHORTANSWER: case LESSON_NUMERICAL: - echo "\n"; - break; - case LESSON_BRANCHTABLE : - echo "\n"; - break; - } + echo "\n"; + break; + case LESSON_BRANCHTABLE : + echo "\n"; + break; + } } } // close table and form ?>
"; - echo get_string("questiontype", "lesson").": \n"; - echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; - lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype, - "lesson.php?id=$cm->id&action=editpage&pageid=$page->id", - "document.editpage.redisplay.value=1;document.editpage.submit();"); - echo "

".get_string("multianswer", "lesson").": \n"; - if ($page->qoption) { - echo ""; //CDC hidden label added. - } else { - echo ""; //CDC hidden label added. - } - helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); - echo "
"; - echo get_string("questiontype", "lesson").": \n"; - echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; - lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype, - "lesson.php?id=$cm->id&action=editpage&pageid=$page->id", - "document.editpage.redisplay.value=1;document.editpage.submit();"); - echo "

".get_string("casesensitive", "lesson").": \n"; - if ($page->qoption) { - echo ""; //CDC hidden label added. - } else { - echo ""; //CDC hidden label added. - } - helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); - echo "
"; - echo get_string("questiontype", "lesson").": \n"; - echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; - lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype, - "lesson.php?id=$cm->id&action=editpage&pageid=$page->id", - "document.editpage.redisplay.value=1;document.editpage.submit();"); - echo "
+ qtype) { + case LESSON_MULTICHOICE : + echo "
"; + echo get_string("questiontype", "lesson").": \n"; + echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; + lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype, + "lesson.php?id=$cm->id&action=editpage&pageid=$page->id", + "document.editpage.redisplay.value=1;document.editpage.submit();"); + echo "

".get_string("multianswer", "lesson").": \n"; + if ($page->qoption) { + echo ""; //CDC hidden label added. + } else { + echo ""; //CDC hidden label added. + } + helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); + echo "
"; + echo get_string("questiontype", "lesson").": \n"; + echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; + lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype, + "lesson.php?id=$cm->id&action=editpage&pageid=$page->id", + "document.editpage.redisplay.value=1;document.editpage.submit();"); + echo "

".get_string("casesensitive", "lesson").": \n"; + if ($page->qoption) { + echo ""; //CDC hidden label added. + } else { + echo ""; //CDC hidden label added. + } + helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); + echo "
"; + echo get_string("questiontype", "lesson").": \n"; + echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; + lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype, + "lesson.php?id=$cm->id&action=editpage&pageid=$page->id", + "document.editpage.redisplay.value=1;document.editpage.submit();"); + echo "
:
\n"; - echo "
"; - if ($page->layout) { - echo ""; - } else { - echo ""; - } - echo get_string("arrangebuttonshorizontally", "lesson")."
\n"; - echo "
"; - if ($page->display) { - echo "
"; - } else { - echo "
"; - } - echo get_string("displayinleftmenu", "lesson")."
\n"; - echo "
\n"; + echo "
"; + if ($page->layout) { + echo ""; + } else { + echo ""; + } + echo get_string("arrangebuttonshorizontally", "lesson")."
\n"; + echo "
"; + if ($page->display) { + echo "
"; + } else { + echo "
"; + } + echo get_string("displayinleftmenu", "lesson")."
\n"; + echo "
".get_string("branchtable", "lesson")." \n"; break; - case LESSON_CLUSTER : + case LESSON_CLUSTER : echo "qtype\">\n"; echo "
".get_string("clustertitle", "lesson")." \n"; - break; - case LESSON_ENDOFCLUSTER : + break; + case LESSON_ENDOFCLUSTER : echo "qtype\">\n"; echo "
".get_string("endofclustertitle", "lesson")." \n"; - break; + break; case LESSON_ENDOFBRANCH : echo "qtype\">\n"; echo "
".get_string("endofbranch", "lesson")." \n"; - break; - } + break; + } echo "
".get_string("correctresponse", "lesson").":\n"; - if ($flags & LESSON_ANSWER_EDITOR) { - echo " [".get_string("useeditor", "lesson").": ". - ""; //CDC hidden label added. - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); - use_html_editor("answer[$n]"); // switch on the editor - } else { - echo " [".get_string("useeditor", "lesson").": ". - ""; //CDC hidden label. - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer); - } - } elseif ($n == 1) { - echo "
".get_string("wrongresponse", "lesson").":\n"; - if ($flags & LESSON_ANSWER_EDITOR) { - echo " [".get_string("useeditor", "lesson").": ". - ""; //CDC hidden label added. - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); - use_html_editor("answer[$n]"); // switch on the editor - } else { - echo " [".get_string("useeditor", "lesson").": ". - ""; //CDC hidden label. - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer); - } - } else { - $ncorrected = $n - 1; - echo "
".get_string("answer", "lesson")." $ncorrected:\n"; - if ($flags & LESSON_ANSWER_EDITOR) { - echo " [".get_string("useeditor", "lesson").": ". - ""; //CDC hidden label added. - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); - use_html_editor("answer[$n]"); // switch on the editor - } else { - echo " [".get_string("useeditor", "lesson").": ". - ""; //CDC hidden label. - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer); - } - echo "
".get_string("matchesanswer", "lesson")." $ncorrected:\n"; - if ($flags & LESSON_RESPONSE_EDITOR) { - echo " [".get_string("useeditor", "lesson").": ". - ""; //CDC hidden label added. - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$n]", $answer->response); - use_html_editor("response[$n]"); // switch on the editor - } else { - echo " [".get_string("useeditor", "lesson").": ". - ""; //CDC hidden label added. - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea(false, 6, 70, 630, 300, "response[$n]", $answer->response); - } - } - echo "
".get_string("correctresponse", "lesson").":\n"; + if ($flags & LESSON_ANSWER_EDITOR) { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label added. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); + use_html_editor("answer[$n]"); // switch on the editor + } else { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer); + } + } elseif ($n == 1) { + echo "
".get_string("wrongresponse", "lesson").":\n"; + if ($flags & LESSON_ANSWER_EDITOR) { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label added. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); + use_html_editor("answer[$n]"); // switch on the editor + } else { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer); + } + } else { + $ncorrected = $n - 1; + echo "
".get_string("answer", "lesson")." $ncorrected:\n"; + if ($flags & LESSON_ANSWER_EDITOR) { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label added. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); + use_html_editor("answer[$n]"); // switch on the editor + } else { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer); + } + echo "
".get_string("matchesanswer", "lesson")." $ncorrected:\n"; + if ($flags & LESSON_RESPONSE_EDITOR) { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label added. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$n]", $answer->response); + use_html_editor("response[$n]"); // switch on the editor + } else { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label added. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea(false, 6, 70, 630, 300, "response[$n]", $answer->response); + } + } + echo "
".get_string("answer", "lesson")." $nplus1:\n"; if ($flags & LESSON_ANSWER_EDITOR) { echo " [".get_string("useeditor", "lesson").": ". - "answereditor[$n]"; //CDC hidden label added. helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); echo "]
\n"; @@ -1728,7 +1728,7 @@ echo "
".get_string("response", "lesson")." $nplus1:\n"; if ($flags & LESSON_RESPONSE_EDITOR) { echo " [".get_string("useeditor", "lesson").": ". - "responseeditor[$n]"; //CDC hidden label added. helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); echo "]
\n"; @@ -1747,7 +1747,7 @@ echo "
".get_string("description", "lesson")." $nplus1:\n"; if ($flags & LESSON_ANSWER_EDITOR) { echo " [".get_string("useeditor", "lesson").": ". - "answereditor[$n]"; //CDC hidden label added. helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); echo "]
\n"; @@ -1763,76 +1763,76 @@ echo "
".get_string("correctanswerjump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) - echo get_string("correctanswerscore", "lesson").": score\" size=\"5\">"; - } - if ($n == 3) { - echo "
".get_string("wronganswerjump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) - echo get_string("wronganswerscore", "lesson").": score\" size=\"5\">"; - } - echo "
".get_string("jump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) { - echo get_string("score", "lesson").": score\" size=\"5\">"; - } - echo "
".get_string("correctanswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) + echo get_string("correctanswerscore", "lesson").": score\" size=\"5\">"; + } + if ($n == 3) { + echo "
".get_string("wronganswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) + echo get_string("wronganswerscore", "lesson").": score\" size=\"5\">"; + } + echo "
".get_string("jump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("score", "lesson").": score\" size=\"5\">"; + } + echo "
".get_string("jump", "lesson")." $nplus1: \n"; - lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) { - echo get_string("score", "lesson")." $nplus1: score\" size=\"5\">"; - } - echo "
".get_string("jump", "lesson")." $nplus1: \n"; - lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - echo "
".get_string("jump", "lesson")." $nplus1: \n"; + lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("score", "lesson")." $nplus1: score\" size=\"5\">"; + } + echo "
".get_string("jump", "lesson")." $nplus1: \n"; + lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + echo "
".get_string("answer", "lesson")." $icorrected:\n"; echo " [".get_string("useeditor", "lesson").": ". ""; @@ -1877,84 +1877,84 @@ echo "
".get_string("jump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) { - echo get_string("score", "lesson").": "; - } - echo "
".get_string("correctanswerjump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$i]", $answer->jumpto, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) - echo get_string("correctanswerscore", "lesson").": score\" size=\"5\">"; - } - if ($i == 3) { - echo "
".get_string("wronganswerjump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$i]", $answer->jumpto, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) - echo get_string("wronganswerscore", "lesson").": score\" size=\"5\">"; - } + switch ($page->qtype) { + case LESSON_ESSAY : + if ($i < 1) { + echo "
".get_string("jump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("score", "lesson").": "; + } + echo "
".get_string("correctanswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) + echo get_string("correctanswerscore", "lesson").": score\" size=\"5\">"; + } + if ($i == 3) { + echo "
".get_string("wronganswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) + echo get_string("wronganswerscore", "lesson").": score\" size=\"5\">"; + } - echo "
".get_string("jump", "lesson")." $iplus1: \n"; - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) { - echo get_string("score", "lesson")." $iplus1: "; - } - echo "
".get_string("jump", "lesson")." $iplus1: \n"; - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - echo "
".get_string("jump", "lesson")." $iplus1: \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("score", "lesson")." $iplus1: "; + } + echo "
".get_string("jump", "lesson")." $iplus1: \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + echo "

- " + " onClick="document.editpage.redisplay.value=1;document.editpage.submit();" /> " /> " />
id)) { + error("Only teachers can look at this page"); + } - /****************** insert page ************************************/ - elseif ($action == 'insertpage' ) { - - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } - - confirm_sesskey(); + confirm_sesskey(); $timenow = time(); - - $form = lesson_clean_data_submitted(); - $newpage = new stdClass; - $newanswer = new stdClass; + + $form = lesson_clean_data_submitted(); + $newpage = new stdClass; + $newanswer = new stdClass; if ($form->pageid) { // the new page is not the first page if (!$page = get_record("lesson_pages", "id", $form->pageid)) { @@ -1970,18 +1970,18 @@ } else { $newpage->qoption = 0; } - /// CDC-FLAG /// 6/16/04 - if (isset($form->layout)) { - $newpage->layout = $form->layout; - } else { - $newpage->layout = 0; - } - if (isset($form->display)) { - $newpage->display = $form->display; - } else { - $newpage->display = 0; - } - /// CDC-FLAG /// + /// CDC-FLAG /// 6/16/04 + if (isset($form->layout)) { + $newpage->layout = $form->layout; + } else { + $newpage->layout = 0; + } + if (isset($form->display)) { + $newpage->display = $form->display; + } else { + $newpage->display = 0; + } + /// CDC-FLAG /// $newpage->title = $form->title; $newpage->contents = trim($form->contents); $newpageid = insert_record("lesson_pages", $newpage); @@ -2013,18 +2013,18 @@ } else { $newpage->qoption = 0; } - /// CDC-FLAG /// 6/16/04 - if (isset($form->layout)) { - $newpage->layout = $form->layout; - } else { - $newpage->layout = 0; - } - if (isset($form->display)) { - $newpage->display = $form->display; - } else { - $newpage->display = 0; - } - /// CDC-FLAG /// + /// CDC-FLAG /// 6/16/04 + if (isset($form->layout)) { + $newpage->layout = $form->layout; + } else { + $newpage->layout = 0; + } + if (isset($form->display)) { + $newpage->display = $form->display; + } else { + $newpage->display = 0; + } + /// CDC-FLAG /// $newpage->title = $form->title; $newpage->contents = trim($form->contents); $newpageid = insert_record("lesson_pages", $newpage); @@ -2043,18 +2043,18 @@ } else { $newpage->qoption = 0; } - /// CDC-FLAG /// 6/16/04 - if (isset($form->layout)) { - $newpage->layout = $form->layout; - } else { - $newpage->layout = 0; - } - if (isset($form->display)) { - $newpage->display = $form->display; - } else { - $newpage->display = 0; - } - /// CDC-FLAG /// + /// CDC-FLAG /// 6/16/04 + if (isset($form->layout)) { + $newpage->layout = $form->layout; + } else { + $newpage->layout = 0; + } + if (isset($form->display)) { + $newpage->display = $form->display; + } else { + $newpage->display = 0; + } + /// CDC-FLAG /// $newpage->title = $form->title; $newpage->contents = trim($form->contents); $newpageid = insert_record("lesson_pages", $newpage); @@ -2068,82 +2068,82 @@ } } // now add the answers - /// CDC-FLAG 6/16/04 added new code to handle essays - if ($form->qtype == LESSON_ESSAY) { - $newanswer->lessonid = $lesson->id; - $newanswer->pageid = $newpageid; - $newanswer->timecreated = $timenow; - if (isset($form->jumpto[0])) { - $newanswer->jumpto = $form->jumpto[0]; - } - if (isset($form->score[0])) { - $newanswer->score = $form->score[0]; - } - $newanswerid = insert_record("lesson_answers", $newanswer); - if (!$newanswerid) { - error("Insert Page: answer record $i not inserted"); - } - } else { - if ($form->qtype == LESSON_MATCHING) { - // need to add two to offset correct response and wrong response - $lesson->maxanswers = $lesson->maxanswers + 2; - } - for ($i = 0; $i < $lesson->maxanswers; $i++) { - if (trim(strip_tags($form->answer[$i]))) { // strip_tags because the HTML editor adds


... - $newanswer->lessonid = $lesson->id; - $newanswer->pageid = $newpageid; - $newanswer->timecreated = $timenow; - $newanswer->answer = trim($form->answer[$i]); - if (isset($form->response[$i])) { - $newanswer->response = trim($form->response[$i]); - } - if (isset($form->jumpto[$i])) { - $newanswer->jumpto = $form->jumpto[$i]; - } - /// CDC-FLAG /// - if ($lesson->custom) { - if (isset($form->score[$i])) { - $newanswer->score = $form->score[$i]; - } - } - /// CDC-FLAG /// - $newanswerid = insert_record("lesson_answers", $newanswer); - if (!$newanswerid) { - error("Insert Page: answer record $i not inserted"); - } - } else { - if ($form->qtype == LESSON_MATCHING) { - if ($i < 2) { - $newanswer->lessonid = $lesson->id; - $newanswer->pageid = $newpageid; - $newanswer->timecreated = $timenow; - $newanswerid = insert_record("lesson_answers", $newanswer); - if (!$newanswerid) { - error("Insert Page: answer record $i not inserted"); - } - } - } else { - break; - } - } - } - } - /// CDC-FLAG /// - redirect("view.php?id=$cm->id", get_string('insertedpage', 'lesson')); - } + /// CDC-FLAG 6/16/04 added new code to handle essays + if ($form->qtype == LESSON_ESSAY) { + $newanswer->lessonid = $lesson->id; + $newanswer->pageid = $newpageid; + $newanswer->timecreated = $timenow; + if (isset($form->jumpto[0])) { + $newanswer->jumpto = $form->jumpto[0]; + } + if (isset($form->score[0])) { + $newanswer->score = $form->score[0]; + } + $newanswerid = insert_record("lesson_answers", $newanswer); + if (!$newanswerid) { + error("Insert Page: answer record $i not inserted"); + } + } else { + if ($form->qtype == LESSON_MATCHING) { + // need to add two to offset correct response and wrong response + $lesson->maxanswers = $lesson->maxanswers + 2; + } + for ($i = 0; $i < $lesson->maxanswers; $i++) { + if (trim(strip_tags($form->answer[$i]))) { // strip_tags because the HTML editor adds


... + $newanswer->lessonid = $lesson->id; + $newanswer->pageid = $newpageid; + $newanswer->timecreated = $timenow; + $newanswer->answer = trim($form->answer[$i]); + if (isset($form->response[$i])) { + $newanswer->response = trim($form->response[$i]); + } + if (isset($form->jumpto[$i])) { + $newanswer->jumpto = $form->jumpto[$i]; + } + /// CDC-FLAG /// + if ($lesson->custom) { + if (isset($form->score[$i])) { + $newanswer->score = $form->score[$i]; + } + } + /// CDC-FLAG /// + $newanswerid = insert_record("lesson_answers", $newanswer); + if (!$newanswerid) { + error("Insert Page: answer record $i not inserted"); + } + } else { + if ($form->qtype == LESSON_MATCHING) { + if ($i < 2) { + $newanswer->lessonid = $lesson->id; + $newanswer->pageid = $newpageid; + $newanswer->timecreated = $timenow; + $newanswerid = insert_record("lesson_answers", $newanswer); + if (!$newanswerid) { + error("Insert Page: answer record $i not inserted"); + } + } + } else { + break; + } + } + } + } + /// CDC-FLAG /// + redirect("view.php?id=$cm->id", get_string('insertedpage', 'lesson')); + } + - - /****************** move ************************************/ + /****************** move ************************************/ elseif ($action == 'move') { - - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } + + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } $pageid = required_param('pageid', PARAM_INT); $title = get_field("lesson_pages", "title", "id", $pageid); print_heading(get_string("moving", "lesson", $title)); - + if (!$page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) { error("Move: first page not found"); } @@ -2171,16 +2171,16 @@ } echo "

\n"; } + - - /****************** moveit ************************************/ + /****************** moveit ************************************/ elseif ($action == 'moveit') { + + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } - - confirm_sesskey(); + confirm_sesskey(); $pageid = required_param('pageid', PARAM_INT); // page to move if (!$page = get_record("lesson_pages", "id", $pageid)) { @@ -2189,13 +2189,13 @@ $after = required_param('after', PARAM_INT); // target page print_heading(get_string("moving", "lesson", $page->title)); - + // first step. determine the new first page // (this is done first as the current first page will be lost in the next step) if (!$after) { // the moved page is the new first page $newfirstpageid = $pageid; - // reset $after so that is points to the last page + // reset $after so that is points to the last page // (when the pages are in a ring this will in effect be the first page) if ($page->nextpageid) { if (!$after = get_field("lesson_pages", "id", "lessonid", $lesson->id, "nextpageid", 0)) { @@ -2215,8 +2215,8 @@ } } // the rest is all unconditional... - - // second step. join pages into a ring + + // second step. join pages into a ring if (!$firstpageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { error("Moveit: firstpageid not found"); } @@ -2243,7 +2243,7 @@ if (!set_field("lesson_pages", "prevpageid", $prevpageid, "id", $nextpageid)) { error("Moveit: unable to update link"); } - + // fourth step. insert page to be moved in new place... if (!$nextpageid = get_field("lesson_pages", "nextpageid", "id", $after)) { error("Movit: nextpageid not found"); @@ -2261,7 +2261,7 @@ if (!set_field("lesson_pages", "nextpageid", $nextpageid, "id", $pageid)) { error("Moveit: unable to update link"); } - + // fifth step. break the ring if (!$newlastpageid = get_field("lesson_pages", "prevpageid", "id", $newfirstpageid)) { error("Moveit: newlastpageid not found"); @@ -2272,23 +2272,23 @@ if (!set_field("lesson_pages", "nextpageid", 0, "id", $newlastpageid)) { error("Moveit: unable to update link"); } - redirect("view.php?id=$cm->id", get_string('movedpage', 'lesson')); + redirect("view.php?id=$cm->id", get_string('movedpage', 'lesson')); } + - - /****************** update page ************************************/ + /****************** update page ************************************/ elseif ($action == 'updatepage' ) { + + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } - - confirm_sesskey(); + confirm_sesskey(); $timenow = time(); - $form = lesson_clean_data_submitted(); - - $page = new stdClass; + $form = lesson_clean_data_submitted(); + + $page = new stdClass; $page->id = $form->pageid; $page->timemodified = $timenow; $page->qtype = $form->qtype; @@ -2297,18 +2297,18 @@ } else { $page->qoption = 0; } - /// CDC-FLAG /// 6/16/04 - if (isset($form->layout)) { - $page->layout = $form->layout; - } else { - $page->layout = 0; - } - if (isset($form->display)) { - $page->display = $form->display; - } else { - $page->display = 0; - } - /// CDC-FLAG /// + /// CDC-FLAG /// 6/16/04 + if (isset($form->layout)) { + $page->layout = $form->layout; + } else { + $page->layout = 0; + } + if (isset($form->display)) { + $page->display = $form->display; + } else { + $page->display = 0; + } + /// CDC-FLAG /// $page->title = $form->title; $page->contents = trim($form->contents); if (!update_record("lesson_pages", $page)) { @@ -2316,34 +2316,34 @@ } if ($page->qtype == LESSON_ENDOFBRANCH || $page->qtype == LESSON_ESSAY || $page->qtype == LESSON_CLUSTER || $page->qtype == LESSON_ENDOFCLUSTER) { // there's just a single answer with a jump - $oldanswer = new stdClass; + $oldanswer = new stdClass; $oldanswer->id = $form->answerid[0]; $oldanswer->timemodified = $timenow; $oldanswer->jumpto = $form->jumpto[0]; - if (isset($form->score[0])) { - $oldanswer->score = $form->score[0]; - } - // delete other answers this if mainly for essay questions. If one switches from using a qtype like Multichoice, - // then switches to essay, the old answers need to be removed because essay is - // supposed to only have one answer record - if ($answers = get_records_select("lesson_answers", "pageid = $form->pageid")) { - foreach ($answers as $answer) { - if ($answer->id != $form->answerid[0]) { + if (isset($form->score[0])) { + $oldanswer->score = $form->score[0]; + } + // delete other answers this if mainly for essay questions. If one switches from using a qtype like Multichoice, + // then switches to essay, the old answers need to be removed because essay is + // supposed to only have one answer record + if ($answers = get_records_select("lesson_answers", "pageid = $form->pageid")) { + foreach ($answers as $answer) { + if ($answer->id != $form->answerid[0]) { if (!delete_records("lesson_answers", "id", $answer->id)) { error("Update page: unable to delete answer record"); - } - } - } - } + } + } + } + } if (!update_record("lesson_answers", $oldanswer)) { error("Update page: EOB not updated"); } } else { // it's an "ordinary" page - if ($form->qtype == LESSON_MATCHING) { - // need to add two to offset correct response and wrong response - $lesson->maxanswers = $lesson->maxanswers + 2; - } + if ($form->qtype == LESSON_MATCHING) { + // need to add two to offset correct response and wrong response + $lesson->maxanswers = $lesson->maxanswers + 2; + } for ($i = 0; $i < $lesson->maxanswers; $i++) { // strip tags because the editor gives


... // also save any answers where the editor is (going to be) used @@ -2359,11 +2359,11 @@ $oldanswer->response = trim($form->response[$i]); } $oldanswer->jumpto = $form->jumpto[$i]; - /// CDC-FLAG /// - if ($lesson->custom) { - $oldanswer->score = $form->score[$i]; - } - /// CDC-FLAG /// + /// CDC-FLAG /// + if ($lesson->custom) { + $oldanswer->score = $form->score[$i]; + } + /// CDC-FLAG /// if (!update_record("lesson_answers", $oldanswer)) { error("Update page: answer $i not updated"); } @@ -2380,34 +2380,34 @@ $newanswer->response = trim($form->response[$i]); } $newanswer->jumpto = $form->jumpto[$i]; - /// CDC-FLAG /// - $newanswer->score = $form->score[$i]; - /// CDC-FLAG /// + /// CDC-FLAG /// + $newanswer->score = $form->score[$i]; + /// CDC-FLAG /// $newanswerid = insert_record("lesson_answers", $newanswer); if (!$newanswerid) { error("Update page: answer record not inserted"); } } } else { - if ($form->qtype == LESSON_MATCHING) { - if ($i >= 2) { - if ($form->answerid[$i]) { - // need to delete blanked out answer - if (!delete_records("lesson_answers", "id", $form->answerid[$i])) { - error("Update page: unable to delete answer record"); - } - } - } else { - $oldanswer = new stdClass; - $oldanswer->id = $form->answerid[$i]; - $oldanswer->flags = $form->answereditor[$i] * LESSON_ANSWER_EDITOR + - $form->responseeditor[$i] * LESSON_RESPONSE_EDITOR; - $oldanswer->timemodified = $timenow; - $oldanswer->answer = NULL; - if (!update_record("lesson_answers", $oldanswer)) { - error("Update page: answer $i not updated"); - } - } + if ($form->qtype == LESSON_MATCHING) { + if ($i >= 2) { + if ($form->answerid[$i]) { + // need to delete blanked out answer + if (!delete_records("lesson_answers", "id", $form->answerid[$i])) { + error("Update page: unable to delete answer record"); + } + } + } else { + $oldanswer = new stdClass; + $oldanswer->id = $form->answerid[$i]; + $oldanswer->flags = $form->answereditor[$i] * LESSON_ANSWER_EDITOR + + $form->responseeditor[$i] * LESSON_RESPONSE_EDITOR; + $oldanswer->timemodified = $timenow; + $oldanswer->answer = NULL; + if (!update_record("lesson_answers", $oldanswer)) { + error("Update page: answer $i not updated"); + } + } } elseif ($form->answerid[$i]) { // need to delete blanked out answer if (!delete_records("lesson_answers", "id", $form->answerid[$i])) { @@ -2420,15 +2420,15 @@ if ($form->redisplay) { redirect("lesson.php?id=$cm->id&action=editpage&pageid=$page->id"); } else { - redirect("view.php?id=$cm->id", get_string('updatedpage', 'lesson')); + redirect("view.php?id=$cm->id", get_string('updatedpage', 'lesson')); } } + - - /*************** no man's land **************************************/ - else { - error("Fatal Error: Unknown Action: ".$action."\n"); - } - print_footer($course); - + /*************** no man's land **************************************/ + else { + error("Fatal Error: Unknown Action: ".$action."\n"); + } + print_footer($course); + ?> diff --git a/mod/lesson/mod.html b/mod/lesson/mod.html index 7b1453dcf67..70fa8474cf5 100644 --- a/mod/lesson/mod.html +++ b/mod/lesson/mod.html @@ -1,16 +1,16 @@ @import url($CFG->wwwroot/mod/lesson/styles.php);"; require("$CFG->dirroot/mod/lesson/locallib.php"); // for parameter array if ($form->mode == "add") { - if ($defaults = get_record("lesson_default", "course", $form->course)) { - foreach ($defaults as $name => $value) { - if (!is_numeric($name)) { - $form->$name = $value; - } - } - } + if ($defaults = get_record("lesson_default", "course", $form->course)) { + foreach ($defaults as $name => $value) { + if (!is_numeric($name)) { + $form->$name = $value; + } + } + } } // set the defaults @@ -45,11 +45,11 @@ if ($form->mode == "add") { $form->available = 0; } if (!isset($form->deadline)) { - $currentdate = usergetdate(time()); + $currentdate = usergetdate(time()); $form->deadline = gmmktime($currentdate["hours"], $currentdate["minutes"], $currentdate["seconds"], $currentdate["mon"]+1, $currentdate["mday"], $currentdate["year"]); } - /// CDC-FLAG /// - if (!isset($form->usepassword)) { + /// CDC-FLAG /// + if (!isset($form->usepassword)) { $form->usepassword = 0; } if (!isset($form->custom)) { @@ -79,32 +79,32 @@ if ($form->mode == "add") { if (!isset($form->bgcolor)) { $form->bgcolor = "#FFFFFF"; } - if (!isset($form->displayleft)) { - $form->displayleft = 0; - } - if (!isset($form->highscores)) { - $form->highscores = 0; - } + if (!isset($form->displayleft)) { + $form->displayleft = 0; + } + if (!isset($form->highscores)) { + $form->highscores = 0; + } if (!isset($form->maxhighscores)) { $form->maxhighscores = 10; } - if (!isset($form->practice)) { - $form->practice = 0; - } - if (!isset($form->review)) { - $form->review = 0; - } - if (!isset($form->lessondefault)) { - $form->lessondefault = 0; - } - if (!isset($form->modattempts)) { - $form->modattempts = 0; - } + if (!isset($form->practice)) { + $form->practice = 0; + } + if (!isset($form->review)) { + $form->review = 0; + } + if (!isset($form->lessondefault)) { + $form->lessondefault = 0; + } + if (!isset($form->modattempts)) { + $form->modattempts = 0; + } - - $form->deleteattempts = ""; + + $form->deleteattempts = ""; - /// CDC-FLAG /// + /// CDC-FLAG /// ?>

@@ -113,9 +113,9 @@ if ($form->mode == "add") { - + @@ -129,9 +129,9 @@ if ($form->mode == "add") { @@ -141,7 +141,7 @@ if ($form->mode == "add") { @@ -149,7 +149,7 @@ if ($form->mode == "add") { - + @@ -181,9 +181,9 @@ if ($form->mode == "add") { @@ -193,7 +193,7 @@ if ($form->mode == "add") { - + @@ -261,9 +261,9 @@ if ($form->mode == "add") { @@ -322,18 +322,18 @@ if ($form->mode == "add") { - + @@ -343,7 +343,7 @@ if ($form->mode == "add") { @@ -351,7 +351,7 @@ if ($form->mode == "add") { @@ -359,7 +359,7 @@ if ($form->mode == "add") { @@ -368,27 +368,27 @@ if ($form->mode == "add") { - + @@ -398,7 +398,7 @@ if ($form->mode == "add") { @@ -416,23 +416,23 @@ if ($form->mode == "add") { - + @@ -442,9 +442,9 @@ if ($form->mode == "add") { @@ -454,7 +454,7 @@ if ($form->mode == "add") { @@ -462,28 +462,28 @@ if ($form->mode == "add") { mode != "add") { + if ($form->mode != "add") { ?> mode != "add") { + } // end if statement if ($form->mode != "add") { ?> - +
- - + +
: timed, ""); + choose_from_menu($options, "timed", $form->timed, ""); helpbutton("timed", get_string("timed", "lesson"), "lesson"); ?> : - +
: 1; $i--) { $numbers[$i] = $i; } @@ -160,18 +160,18 @@ if ($form->mode == "add") {
-
-
+
+
: practice, ""); + choose_from_menu($options, "practice", $form->practice, ""); helpbutton("practice", get_string("practice", "lesson"), "lesson"); ?> : custom, ""); + choose_from_menu($options, "custom", $form->custom, ""); helpbutton("custom", get_string("customscoring", "lesson"), "lesson"); ?> : =0; $i--) { $grades[$i] = $i; } @@ -207,7 +207,7 @@ if ($form->mode == "add") { student) ?>: retake, ""); helpbutton("retake", get_string("canretake", "lesson", $course->student), "lesson"); @@ -219,7 +219,7 @@ if ($form->mode == "add") { : usemaxgrade, ""); helpbutton("handlingofretakes", get_string("handlingofretakes", "lesson"), "lesson"); @@ -231,27 +231,27 @@ if ($form->mode == "add") { : ongoing, ""); + choose_from_menu($options, "ongoing", $form->ongoing, ""); helpbutton("ongoing", get_string("ongoing", "lesson"), "lesson"); ?>
-
-
+
+
: modattempts, ""); + choose_from_menu($options, "modattempts", $form->modattempts, ""); helpbutton("modattempts", get_string("modattempts", "lesson"), "lesson"); ?> : review, ""); + choose_from_menu($options, "review", $form->review, ""); helpbutton("review", get_string("displayreview", "lesson"), "lesson"); ?>
-
-
+
+
: slideshow, ""); + choose_from_menu($options, "slideshow", $form->slideshow, ""); helpbutton("slideshow", get_string("slideshow", "lesson"), "lesson"); ?> : px - +
: px - +
: - +
: displayleft, ""); + choose_from_menu($options, "displayleft", $form->displayleft, ""); helpbutton("displayleft", get_string("displayleftmenu", "lesson"), "lesson"); ?>
-
-
+
+
: usepassword, ""); + choose_from_menu($options, "usepassword", $form->usepassword, ""); helpbutton("usepassword", get_string("usepassword", "lesson"), "lesson"); ?> : - +
deadline); echo " - "; - print_time_selector("deadlinehour", "deadlineminute", $form->deadline); + print_time_selector("deadlinehour", "deadlineminute", $form->deadline); ?>
-
-
+
+
: tree, ""); + choose_from_menu($options, "tree", $form->tree, ""); helpbutton("tree", get_string("treeview", "lesson"), "lesson"); ?> : highscores, ""); + choose_from_menu($options, "highscores", $form->highscores, ""); helpbutton("highscores", get_string("displayhighscores", "lesson"), "lesson"); ?> : - +
: lessondefault, ""); + choose_from_menu($options, "lessondefault", $form->lessondefault, ""); helpbutton("lessondefault", get_string("lessondefault", "lesson"), "lesson"); ?>
: - - + +
diff --git a/mod/lesson/styles.php b/mod/lesson/styles.php index 68a48063772..d4c2c6c4490 100644 --- a/mod/lesson/styles.php +++ b/mod/lesson/styles.php @@ -1,4 +1,6 @@ - diff --git a/mod/lesson/view.php b/mod/lesson/view.php index e5ee55897e9..d6a599718cd 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -22,7 +22,7 @@ error('Course module is incorrect'); } - require_login($course->id, true, $cm); + require_login($course->id); /// Print the page header @@ -32,7 +32,7 @@ $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)) { @@ -68,7 +68,7 @@ } 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)) { @@ -126,7 +126,7 @@ } echo ''. get_string('passwordprotectedlesson', 'lesson', $lesson->name) .''; echo ''. get_string('enterpassword', 'lesson').' '; - + echo ''; echo ' '; echo ''; @@ -135,18 +135,18 @@ 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; + $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 @@ -157,16 +157,16 @@ $retries = 0; } if ($retries) { - $attemptflag = true; + $attemptflag = true; } - - if (isset($USER->modattempts[$lesson->id])) { - unset($USER->modattempts[$lesson->id]); // if no pageid, then student is NOT reviewing - } - + + 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 + 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, @@ -179,7 +179,7 @@ if ($jumpto == 0) { // unlikely value! $lastpageseen = $attempt->pageid; } elseif ($jumpto == LESSON_NEXTPAGE) { - if (!$lastpageseen = get_field('lesson_pages', 'nextpageid', 'id', + if (!$lastpageseen = get_field('lesson_pages', 'nextpageid', 'id', $attempt->pageid)) { // no nextpage go to end of lesson $lastpageseen = LESSON_EOL; @@ -187,7 +187,7 @@ } else { $lastpageseen = $jumpto; } - break; // only look at the latest correct attempt + 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) { @@ -202,8 +202,8 @@ 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 + echo '' . "\n"; + echo '';///CDC Chris Berri added close div tag } else { print_simple_box_start('center'); echo '
'; @@ -212,7 +212,7 @@ echo '
'; print_simple_box_end(); } - + } else { echo "
\n"; echo "id\" />\n"; @@ -227,10 +227,10 @@ echo "
\n"; echo "";///CDC Chris Berri added close div tag } print_footer($course); - exit(); + exit(); } } - + if ($grades) { foreach ($grades as $grade) { $bestgrade = $grade->grade; @@ -253,9 +253,9 @@ } } // 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 = 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])) { $startlesson = new stdClass; @@ -263,22 +263,22 @@ 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; + $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 @@ -298,21 +298,21 @@ } } } - + 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); + 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; @@ -328,53 +328,53 @@ } 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 "
"; + echo "
".get_string('lessonmenu', 'lesson')."
"; + echo ""; + echo '
'; + 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 + } - // 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 ""; - 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"; + // 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 ""; - } + echo ""; + } $i++; } echo '
\n"; - } else { + } else { echo ""; if ($answer != end($answers)) { - echo ""; - } + echo ""; + } } echo '
\n"; - $lesson->slideshow = false; // turn off slide show for all pages other than LESSON_BRANTCHTABLE - } + $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 + // This is where several messages (usually warnings) are displayed + // all of this is displayed above the actual page - // clock code + // clock code if($lesson->timed) { if(isteacher($course->id)) { echo '

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

'; @@ -385,26 +385,26 @@ if (!$timer = get_record('lesson_timer', 'lessonid', $lesson->id, 'userid', $USER->id)) { error('Error: could not find record'); } - + $continuelesson = new stdClass; $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 $startlesson = new stdClass; $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'); } @@ -416,10 +416,10 @@ } if ((($timer->starttime + $lesson->maxtime * 60) - time()) > 0) { // code for the clock - print_simple_box_start("right", "150px", "#ffffff", 0); + print_simple_box_start("right", "150px", "#ffffff", 0); echo "". - "
".get_string("timeremaining", "lesson"). - "
"; + "
".get_string("timeremaining", "lesson"). + "
"; echo "\n"; echo "
"; - print_simple_box_end(); - 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')."

"; - } - + } + $newtime = new stdClass; $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'); + 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 + + 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')) { @@ -470,7 +470,7 @@ if (!isteacher($course->id)) { $answer->jumpto = lesson_cluster_jump($lesson->id, $USER->id, $pageid); } else { - if ($page->nextpageid == 0) { + if ($page->nextpageid == 0) { $answer->jumpto = LESSON_EOL; } else { $answer->jumpto = $page->nextpageid; @@ -481,41 +481,41 @@ 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 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); + $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", + $nviewed = count_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, "retry", $ntries); if ($nviewed) { echo "

".get_string("numberofpagesviewed", "lesson", $nviewed). @@ -535,15 +535,15 @@ } echo get_string("numberofcorrectanswers", "lesson", $ncorrect)."
\n"; $thegrade = intval(100 * $ncorrect / $nviewed); - echo get_string("yourcurrentgradeis", "lesson", + 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 "
"; + + // now starting to print the page's contents + echo "
"; echo ""; echo ($lesson->name) . ""; if ($page->qtype == LESSON_BRANCHTABLE) { @@ -551,73 +551,73 @@ 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); - } - + + // 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."\" />"; + echo "sesskey."\" />"; if (!$lesson->slideshow) { print_simple_box_start("center"); - echo ''; + echo '
'; } switch ($page->qtype) { case LESSON_SHORTANSWER : case LESSON_NUMERICAL : - if (isset($USER->modattempts[$lesson->id])) { - $value = "value=\"$attempt->useranswer\""; - } else { - $value = ""; - } + 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"; + 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 = ""; - } + 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"; + echo "

\n"; break; case LESSON_MULTICHOICE : $i = 0; @@ -625,47 +625,47 @@ 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 + $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 = ""; - } + 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 format_text(trim($answer->answer), FORMAT_MOODLE, $options); echo "


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

\n"; - } else { - echo "

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

\n"; + } else { + echo "

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


'; print_simple_box_end(); - echo "

\n"; + echo "

\n"; break; case LESSON_BRANCHTABLE : - if ($lesson->slideshow) { - echo "
"; - } else { - echo "
"; - } + 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 ""; - } - } - } - + $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) { + foreach ($answers as $answer) { 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\" />
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();\" />"; @@ -783,26 +783,26 @@ } }*/ if (!$lesson->slideshow) { - echo '
'; - print_simple_box_end(); - } + echo '
'; + print_simple_box_end(); + } break; case LESSON_ESSAY : if (isset($USER->modattempts[$lesson->id])) { - $essayinfo = unserialize($attempt->useranswer); - $value = $essayinfo->answer; - } else { - $value = ""; - } + $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"; + echo "

\n"; break; } - echo "\n"; + echo "\n"; } else { // a page without answers - find the next (logical) page echo "
\n"; @@ -811,14 +811,14 @@ if ($lesson->nextpagedefault) { // in Flash Card mode... // ...first get number of retakes - $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); + $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", + if (!count_records("lesson_attempts", "pageid", $thispage->id, "userid", $USER->id, "retry", $nretakes)) { $found = true; break; @@ -857,7 +857,7 @@ get_string("continue", "lesson")."\" />

\n"; echo "
\n"; } - echo "
\n"; + echo "\n"; } else { // end of lesson reached work out grade /// CDC-FLAG /// @@ -876,17 +876,17 @@ 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 (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", + if ($nviewed = count_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, "retry", $ntries)) { /// CDC-FLAG /// 6/11/04 if (!$lesson->custom) { - $ncorrect = 0; - $temp = array(); - if ($pagesanswered = get_records_select("lesson_attempts", "lessonid = $lesson->id AND + $ncorrect = 0; + $temp = array(); + if ($pagesanswered = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries order by timeseen")) { foreach ($pagesanswered as $pageanswered) { @@ -912,7 +912,7 @@ if ($lesson->minquestions) { if ($nviewed < $lesson->minquestions) { // print a warning and set nviewed to minquestions - echo "

".get_string("youshouldview", "lesson", + echo "

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

\n"; $nviewed = $lesson->minquestions; } @@ -920,62 +920,62 @@ echo "

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

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

".get_string("gradeis", "lesson", + 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; + $essayquestionpoints = 0; - if ($useranswers = get_records_select("lesson_attempts", "lessonid = $lesson->id AND + if ($useranswers = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries", "timeseen")) { - // group each try with its page + // group each try with its page foreach ($useranswers as $useranswer) { - $attemptset[$useranswer->pageid][] = $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)"); - $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); + 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); $a = new stdClass; if ($essayquestions > 0) { $a->score = $score; @@ -986,44 +986,44 @@ } else { $a->score = $score; $a->grade = $bestscore; - echo "
".get_string("displayscorewithoutessays", "lesson", $a)."
"; + echo "
".get_string("displayscorewithoutessays", "lesson", $a)."
"; } - echo "

".get_string("gradeis", "lesson", + echo "

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

\n"; } - /// CDC-FLAG /// + /// 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"); - } - } + 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"); + //print_string("noattemptrecordsfound", "lesson"); if ($lesson->timed) { if (isset($_GET["outoftime"])) { if ($_GET["outoftime"] == "normal") { - $grade = new stdClass; + $grade = new stdClass; $grade->lessonid = $lesson->id; $grade->userid = $USER->id; $grade->grade = 0; @@ -1041,8 +1041,8 @@ } - } - } else { + } + } else { // display for teacher echo "

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

\n"; } @@ -1066,7 +1066,7 @@ // 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")."
"; @@ -1076,41 +1076,41 @@ } } 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 ""; } + /// 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 ""; - } + echo ""; + } } /*******************teacher view **************************************/ elseif ($action == 'teacherview') { - print_heading_with_help($lesson->name, "overview", "lesson"); + print_heading_with_help($lesson->name, "overview", "lesson"); print_heading("id&action=navigation\">".get_string("checknavigation", "lesson")."\n"); // get number of pages @@ -1145,7 +1145,7 @@ } print_simple_box_end(); echo ""; //CDC Chris Berri added. - /// CDC-FLAG /// + /// CDC-FLAG /// } else { // print the pages echo "
\n"; @@ -1153,21 +1153,21 @@ 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")."

"; - } - } + 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'])) { + if($lesson->tree && !isset($_GET['display']) && !isset($_GET['viewAll'])) { echo "
"; echo get_string("treeview", "lesson")."

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

\n"; @@ -1178,7 +1178,7 @@ echo "
"; } else { if(isset($_GET['display']) && !isset($_GET['viewAll'])) { - $display = clean_param($_GET['display'], PARAM_INT); + $display = clean_param($_GET['display'], PARAM_INT); while(true) { if($page->id == $display && $page->qtype == LESSON_BRANCHTABLE) { @@ -1187,7 +1187,7 @@ break; } elseif($page->id == $display) { $branch = false; - $singlePage = true; + $singlePage = true; break; } elseif ($page->nextpageid) { if (!$page = get_record("lesson_pages", "id", $page->nextpageid)) { @@ -1202,7 +1202,7 @@ echo "".get_string("backtreeview", "lesson")."
\n"; echo "\n"; if (isteacheredit($course->id)) { - /// CDC-FLAG 6/16/04 /// + /// CDC-FLAG 6/16/04 /// echo "\n"; - /// CDC-FLAG /// - } + /// 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\">". @@ -1214,12 +1214,12 @@ "id&action=addpage&pageid=$page->prevpageid\">". get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). "
\n"; if (isteacheredit($course->id)) { /// CDC-FLAG 6/16/04 /// @@ -1235,9 +1235,9 @@ /// CDC-FLAG /// } } - /// CDC-FLAG /// end tree code (note, there is an "}" below for an else above) + /// 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 + /// CDC-FLAG /// 6/16/04 echo "
\n"; + echo "
\n"; echo "\n"; + echo "\n"; echo "\n"; @@ -1280,7 +1280,7 @@ case LESSON_NUMERICAL : echo $LESSON_QUESTION_TYPE[$page->qtype]; break; - case LESSON_BRANCHTABLE : + case LESSON_BRANCHTABLE : echo get_string("branchtable", "lesson"); break; case LESSON_ENDOFBRANCH : @@ -1319,21 +1319,21 @@ echo "\n"; echo "\n"; - break; + break; case LESSON_MATCHING: if ($n < 2) { if ($answer->answer != NULL) { if ($n == 0) { echo "\n"; } else { echo "\n"; } } @@ -1361,7 +1361,7 @@ echo "\n"; echo "\n"; } break; @@ -1379,8 +1379,8 @@ $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 +/* 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) { @@ -1388,7 +1388,7 @@ } elseif ($answer->jumpto == LESSON_RANDOMBRANCH) { $jumptitle = get_string("randombranch", "lesson"); } elseif ($answer->jumpto == LESSON_CLUSTERJUMP) { - $jumptitle = get_string("clusterjump", "lesson"); /// CDC-FLAG /// + $jumptitle = get_string("clusterjump", "lesson"); /// CDC-FLAG /// } else { if (!$jumptitle = get_field("lesson_pages", "title", "id", $answer->jumpto)) { $jumptitle = "".get_string("notdefined", "lesson").""; @@ -1412,7 +1412,7 @@ echo "$jumptitle\n"; } } else { - if ($lesson->custom && $page->qtype != LESSON_BRANCHTABLE && $page->qtype != LESSON_ENDOFBRANCH) { + if ($lesson->custom && $page->qtype != LESSON_BRANCHTABLE && $page->qtype != LESSON_ENDOFBRANCH) { echo "\n"; @@ -1439,16 +1439,16 @@ } echo "
$page->title  \n"; if (isteacheredit($course->id)) { if ($npages > 1) { @@ -1249,7 +1249,7 @@ "id&sesskey=".$USER->sesskey."&action=confirmdelete&pageid=$page->id\">\n". "pixpath/t/delete.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\" alt=\"delete\" />\n"; } - echo "
\n"; print_simple_box(format_text($page->contents), "center"); echo "
".get_string("response", "lesson")." $i: \n"; echo "\n"; - echo format_text($answer->response); + echo format_text($answer->response); echo "
".get_string("correctresponse", "lesson").": \n"; echo "\n"; - echo format_text($answer->answer); + echo format_text($answer->answer); echo "
".get_string("wrongresponse", "lesson").": \n"; echo "\n"; - echo format_text($answer->answer); + echo format_text($answer->answer); echo "
".get_string("matchesanswer", "lesson")." $i: \n"; echo "\n"; - echo format_text($answer->response); + echo format_text($answer->response); echo "
".get_string("score", "lesson")." $i:"; echo "\n"; echo "$answer->score
id&pageid=$page->id\">". - get_string("importquestions", "lesson")." | ". + 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 /// + /// 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) { @@ -1492,7 +1492,7 @@ } } } /// CDC-FLAG /// end of else from above tree code!!! - + echo "
\n"; /// CDC-FLAG /// // NoticeFix both viewAll's @@ -1502,100 +1502,100 @@ if($lesson->tree && (isset($_GET['display']) || isset($_GET['viewAll']))) { echo "
".get_string("backtreeview", "lesson")."
\n"; } - /// CDC-FLAG /// + /// 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 + // 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.* + + // 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")) { + 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 - $studentessays = array(); - 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; + + // 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 + $studentessays = array(); + 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 = new stdClass; - $table->head = array($course->students, get_string("essays", "lesson"), get_string("email", "lesson")); + print_heading("id\">".get_string("gobacktolesson", "lesson").""); + $table = new stdClass; + $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%", "*"); + $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 + // 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; - $essaylinks = array(); - // go through each essay + $essaylinks = array(); + // 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.""; - } + // 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").""; + // 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); + $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); + + $attemptid = required_param('attemptid', PARAM_INT); if (!$essay = get_record("lesson_attempts", "id", $attemptid)) { error("Error: could not find attempt"); @@ -1615,48 +1615,48 @@ echo "id\" />\n"; echo "\n"; echo "\n"; - echo "sesskey."\" />\n"; - - // all tables will have these - $table = new stdClass; + echo "sesskey."\" />\n"; + + // all tables will have these + $table = new stdClass; $table->align = array("left"); $table->wrap = array("wrap"); $table->width = "70%"; - $table->size = array("100%"); - - - $table->head = array(get_string("question", "lesson")); + $table->size = array("100%"); + + + $table->head = array(get_string("question", "lesson")); $table->data[] = array(format_text($page->contents)); - print_table($table); - echo "
"; + print_table($table); + echo "
"; - unset($table->data); - $essayinfo = unserialize($essay->useranswer); + 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)); + $table->data[] = array(format_text($essayinfo->answer)); + + print_table($table); + echo "
"; + + unset($table->data); - print_table($table); - echo "
"; - - unset($table->data); - - $table->head = array(get_string("comments", "lesson")); - $table->data[] = array("\n"); + $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"; + $options[1] = "correct"; } - $table->data[] = array(get_string("essayscore", "lesson").": ".lesson_choose_from_menu($options, "score", $essayinfo->score, "", "", "", true)); - - print_table($table); - echo "
"; + $table->data[] = array(get_string("essayscore", "lesson").": ".lesson_choose_from_menu($options, "score", $essayinfo->score, "", "", "", true)); + + print_table($table); + echo "
"; echo "
"; echo ""; @@ -1664,19 +1664,19 @@ echo ""; echo "
"; - echo ""; - - + echo ""; + + } /*******************update grade**************************************/ // 6/29/04 elseif ($action == 'updategrade') { print_heading_with_help($lesson->name, "overview", "lesson"); - - confirm_sesskey(); - + + confirm_sesskey(); + $form = lesson_clean_data_submitted(); - + if (!$essay = get_record("lesson_attempts", "id", $form->attemptid)) { error("Error: could not find essay"); } @@ -1684,32 +1684,32 @@ 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 = new stdClass; + $essayinfo = unserialize($essay->useranswer); - $essayinfo = new stdClass; - $essayinfo = unserialize($essay->useranswer); - - $essayinfo->graded = 1; + $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; - } + $essayinfo->sent = 0; + if (!$lesson->custom && $form->score == 1) { + $essay->correct = 1; + } else { + $essay->correct = 0; + } - $essay->useranswer = addslashes(serialize($essayinfo)); + $essay->useranswer = addslashes(serialize($essayinfo)); - if (!update_record("lesson_attempts", $essay)) { - error("Could not update essay score"); - } + 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; + $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 { @@ -1722,70 +1722,70 @@ /*******************email essay **************************************/ // 6/29/04 elseif ($action == 'emailessay') { print_heading_with_help($lesson->name, "overview", "lesson"); - - confirm_sesskey(); - + + confirm_sesskey(); + if (isset($_GET['userid'])) { - $userid = clean_param($_GET['userid'], PARAM_INT); + $userid = clean_param($_GET['userid'], PARAM_INT); $queryadd = " AND userid = ".$userid; - if (! $users = get_records("user", "id", $userid)) { - error("Error: could not find users"); - } + 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"); - } + if (!$users = lesson_get_participants($lesson->id)) { + error("Error: could not find users"); + } } - - // get lesson pages that are essay + + // 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."); - } + + // 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); + $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 .= "

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

"; - $message .= get_string('commentswithname', 'lesson', $USER).":
"; + $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); + $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; + $points->score = $essayinfo->score; + $points->outof = $essayanswers[$essay->pageid]->score; $message .= get_string("youhavereceived", "lesson", $points); - } else { - $points->score = $essayinfo->score; - $points->outof = 1; + } else { + $points->score = $essayinfo->score; + $points->outof = 1; $message .= get_string("youhavereceived", "lesson", $points); - } - $message .= "

"; - $message .= get_string("yourgradeisnow", "lesson", $grade->grade)."%."; + } + $message .= "

"; + $message .= get_string("yourgradeisnow", "lesson", $grade->grade)."%."; + + $plaintxt = format_text_email($message, FORMAT_HTML); - $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)); + 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!
"; @@ -1805,7 +1805,7 @@ if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id", "completed")) { $grades = array(); } - + echo "
"; $titleinfo->maxhighscores = $lesson->maxhighscores; $titleinfo->name = $lesson->name; @@ -1819,7 +1819,7 @@ $topscores[$grade][] = $highscore->nickname; } krsort($topscores); - + echo ""; echo ""; $printed = 0; @@ -1827,13 +1827,13 @@ $temp = current($topscores); $score = key($topscores); $rank = $printed + 1; - sort($temp); + sort($temp); foreach ($temp as $student) { echo ""; - + } $printed++; - if (!next($topscores) || !($printed < $lesson->maxhighscores)) { + if (!next($topscores) || !($printed < $lesson->maxhighscores)) { break; } } @@ -1845,13 +1845,13 @@ 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(); + + confirm_sesskey(); if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id", "completed")) { error("Error: could not find grades"); @@ -1861,13 +1861,13 @@ } 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) { @@ -1887,14 +1887,14 @@ } 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; + $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); @@ -1911,8 +1911,8 @@ } } } - - $newhighscore = new stdClass; + + $newhighscore = new stdClass; $newhighscore->lessonid = $lesson->id; $newhighscore->userid = $USER->id; $newhighscore->gradeid = $newgrade->id; @@ -1922,7 +1922,7 @@ 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 "
"; } @@ -1931,23 +1931,23 @@ print_heading_with_help($lesson->name, "overview", "lesson"); echo "
"; if (isset($_POST['name'])) { - $name = trim(param_clean($_POST['name'], PARAM_CLEAN)); + $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");
".get_string("rank", "lesson")."$course->students".get_string("scores", "lesson")."
$rank$student$score