From 845a17e6f0db22f6f37ed7400a2b0c0577786c99 Mon Sep 17 00:00:00 2001 From: michaelpenne Date: Wed, 30 Mar 2005 00:49:18 +0000 Subject: [PATCH] all the actions in lesson.php are now defined in mod/lesson/lessonactions/ --- mod/lesson/lesson.php | 2383 +---------------------------------------- 1 file changed, 8 insertions(+), 2375 deletions(-) diff --git a/mod/lesson/lesson.php b/mod/lesson/lesson.php index 8209612281e..6defbafa01e 100644 --- a/mod/lesson/lesson.php +++ b/mod/lesson/lesson.php @@ -59,2381 +59,14 @@ //...get the action $action = required_param('action'); - - /************** add branch table ************************************/ - if ($action == 'addbranchtable' ) { - 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[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 ///// - // give teacher a blank proforma - print_heading_with_help(get_string("addabranchtable", "lesson"), "overview", "lesson"); - ?> -
- - - - - -
- - - \n"; - /// CDC-FLAG /// 6/16/04 - echo "\n"; - /// CDC-FLAG /// - for ($i = 0; $i < $lesson->maxanswers; $i++) { - $iplus1 = $i + 1; - echo "\n"; - echo "\n"; - } - // close table and form - ?> -
-
:
-
"; - echo get_string("pagecontents", "lesson").":
\n"; - print_textarea($usehtmleditor, 25,70, 630, 400, "contents"); - use_html_editor("contents"); - 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 - 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"); - echo "

- " /> - " /> -
-
- id)) { - error("Only teachers can look at this page"); - } - - 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"); - } - // chain back up to find the (nearest branch table) - $btpageid = $pageid; - if (!$btpage = get_record("lesson_pages", "id", $btpageid)) { - error("Add end of branch: btpage record not found"); - } - while (($btpage->qtype != LESSON_BRANCHTABLE) AND ($btpage->prevpageid > 0)) { - $btpageid = $btpage->prevpageid; - if (!$btpage = get_record("lesson_pages", "id", $btpageid)) { - error("Add end of branch: btpage record not found"); - } - } - if ($btpage->qtype == LESSON_BRANCHTABLE) { - $newpage = new stdClass; - $newpage->lessonid = $lesson->id; - $newpage->prevpageid = $pageid; - $newpage->nextpageid = $page->nextpageid; - $newpage->qtype = LESSON_ENDOFBRANCH; - $newpage->timecreated = $timenow; - $newpage->title = get_string("endofbranch", "lesson"); - $newpage->contents = get_string("endofbranch", "lesson"); - if (!$newpageid = insert_record("lesson_pages", $newpage)) { - error("Insert page: new page not inserted"); - } - // update the linked list... - if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $pageid)) { - error("Add end of branch: 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 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 = $btpageid; - if(!$newanswerid = insert_record("lesson_answers", $newanswer)) { - error("Add end of branch: answer record not inserted"); - } - redirect("view.php?id=$cm->id", get_string('addedanendofbranch', 'lesson')); - } else { - notice(get_string("nobranchtablefound", "lesson"), "view.php?id=$cm->id"); - } - } - -/// CDC-FLAG 6/17/04 /// - /************** add cluster ************************************/ - elseif ($action == 'addcluster' ) { - - 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 - $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"); - } - } - $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"); - } - } - - 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 ************************************/ - elseif ($action == 'addendofcluster' ) { - - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } - - 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"); - } - - // 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 ************************************/ - elseif ($action == 'addpage' ) { - - 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[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"; - } - - // give teacher a blank proforma - print_heading_with_help(get_string("addaquestionpage", "lesson"), "overview", "lesson"); - ?> -
- - - - -
- \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"; - } - } - // 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 "
-
:
-
"; - echo get_string("pagecontents", "lesson").":
\n"; - 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 "

- "> - "> -
-
- 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)) { - error("Confirm delete: the page record not found"); - } - print_heading(get_string("deletingpage", "lesson", $thispage->title)); - // print the jumps to this page - if ($answers = get_records_select("lesson_answers", "lessonid = $lesson->id AND jumpto = $pageid + 1")) { - print_heading(get_string("thefollowingpagesjumptothispage", "lesson")); - echo "

\n"; - foreach ($answers as $answer) { - if (!$title = get_field("lesson_pages", "title", "id", $answer->pageid)) { - error("Confirm delete: page title not found"); - } - echo $title."
\n"; - } - } - 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' ) { - - 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 /// - - /// CDC-FLAG /// 6/14/04 -- This is the code updates the lesson time for a timed test - // get time information for this user - if (!isteacher($course->id)) { - if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) { - error('Error: could not find records'); - } else { - $timer = array_pop($timer); // this will get the latest start time record - } - } - $outoftime = false; - if($lesson->timed) { - if(isteacher($course->id)) { - echo "

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

"; - } else { - if ((($timer->starttime + $lesson->maxtime * 60) - time()) > 0) { - // code for the clock - print_simple_box_start("right", "150px", "#ffffff", 0); - echo "". - "
".get_string("timeremaining", "lesson"). - "
"; - echo "\n"; - echo "
"; - print_simple_box_end(); - echo "



"; - } else { - redirect("view.php?id=$cm->id&action=navigation&pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson")); - } - 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; - } - } - } - // update the clock - if (!isteacher($course->id)) { - $timer->lessontime = time(); - if (!update_record("lesson_timer", $timer)) { - 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"); - } - $pageid = required_param('pageid', PARAM_INT); - if (!$page = get_record("lesson_pages", "id", $pageid)) { - error("Continue: Page record not found"); - } - // set up some defaults - $answerid = 0; - $noanswer = false; - $correctanswer = false; - $newpageid = 0; // stay on the page - switch ($page->qtype) { - /// 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")) { - 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 : - if (!$useranswer = $_POST['answer']) { - $noanswer = true; - break; - } - $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 /// - if ($page->qoption) { - // case sensitive - if ($answer->answer == $useranswer) { - $correctanswer = true; - $newpageid = $answer->jumpto; - if (trim(strip_tags($answer->response))) { - $response = $answer->response; - } - } - } else { - // case insensitive - if (strcasecmp($answer->answer, $useranswer) == 0) { - $correctanswer = true; - $newpageid = $answer->jumpto; - if (trim(strip_tags($answer->response))) { - $response = $answer->response; - } - } - } - } else { - // see if user typed in any of the wrong answers - // don't worry about case - if (strcasecmp($answer->answer, $useranswer) == 0) { - $newpageid = $answer->jumpto; - $answerid = $answer->id; - if (trim(strip_tags($answer->response))) { - $response = $answer->response; - } - } - } - } - if (!isset($response)) { - if ($correctanswer) { - $response = get_string("thatsthecorrectanswer", "lesson"); - } else { - $response = get_string("thatsthewronganswer", "lesson"); - } - } - break; - - case LESSON_TRUEFALSE : - if (empty($_POST['answerid'])) { - $noanswer = true; - break; - } - $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 /// - $newpageid = $answer->jumpto; - if (!$response = trim($answer->response)) { - if ($correctanswer) { - $response = get_string("thatsthecorrectanswer", "lesson"); - } else { - $response = get_string("thatsthewronganswer", "lesson"); - } - } - break; - - case LESSON_MULTICHOICE : - if ($page->qoption) { - // MULTIANSWER allowed, user's answer is an array - if (isset($_POST['answer'])) { - $useranswers = $_POST['answer']; - foreach ($useranswers as $key => $useranswer) { - $useranswers[$key] = clean_param($useranswer, PARAM_INT); - } - } else { - $noanswer = true; - break; - } - // 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"); - } - $ncorrect = 0; - $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 /// - if ((count($useranswers) == $ncorrect) and ($nhits == $ncorrect)) { - $correctanswer = true; - if (!$response = $correctresponse) { - $response = get_string("thatsthecorrectanswer", "lesson"); - } - $newpageid = $correctpageid; - } else { - if (!$response = $wrongresponse) { - $response = get_string("thatsthewronganswer", "lesson"); - } - $newpageid = $wrongpageid; - } - } else { - // only one answer allowed - if (empty($_POST['answerid'])) { - $noanswer = true; - break; - } - $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 /// - $newpageid = $answer->jumpto; - if (!$response = trim($answer->response)) { - if ($correctanswer) { - $response = get_string("thatsthecorrectanswer", "lesson"); - } else { - $response = get_string("thatsthewronganswer", "lesson"); - } - } - } - break; - - /// 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']; - } else { - $noanswer = true; - break; - } - - if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { - error("Continue: No answers found"); - } - $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 ($answer->response == $response[$answer->id]) { - $ncorrect++; - } - if ($i == 2) { - $correctpageid = $answer->jumpto; - $correctanswerid = $answer->id; - } - if ($i == 3) { - $wrongpageid = $answer->jumpto; - $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); - - 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 - if (isset($correctpageid)) { - $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++; - } - } - $newpageid = $wrongpageid; - $answerid = $wronganswerid; - } - break; - /// CDC-FLAG /// - - case LESSON_NUMERICAL : - // set defaults - $response = ''; - $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 { - $noanswer = true; - break; - } - $userresponse = $useranswer; - if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { - error("Continue: No answers found"); - } - foreach ($answers as $answer) { - if (strpos($answer->answer, ':')) { - // there's a pairs of values - list($min, $max) = explode(':', $answer->answer); - $minimum = (float) $min; - $maximum = (float) $max; - } else { - // there's only one value - $minimum = (float) $answer->answer; - $maximum = $minimum; - } - if (($useranswer >= $minimum) and ($useranswer <= $maximum)) { - $newpageid = $answer->jumpto; - $response = trim($answer->response); - 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 /// - break; - } - } - if ($correctanswer) { - if (!$response) { - $response = get_string("thatsthecorrectanswer", "lesson"); - } - } else { - 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(); - - 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 /// - // convert jumpto page into a proper page id - if ($newpageid == 0) { - $newpageid = $pageid; - } elseif ($newpageid == LESSON_NEXTPAGE) { - if (!$newpageid = $page->nextpageid) { - // no nextpage go to end of lesson - $newpageid = LESSON_EOL; - } -/* 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 - redirect("view.php?id=$cm->id&action=navigation&pageid=$newpageid"); - 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); - if (isstudent($course->id)) { - // record student's attempt - $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; - } - $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 - 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 /// - if (!$correctanswer and ($newpageid == 0)) { - // 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); - - if ($nattempts >= $lesson->maxattempts) { - if ($lesson->maxattempts > 1) { // don't bother with message if only one attempt - echo "

(".get_string("maximumnumberofattempts", "lesson"). - " ".get_string("reached", "lesson")." - ". - get_string("movingtonextpage", "lesson").")

\n"; - } - $newpageid = LESSON_NEXTPAGE; - } - } - } - // convert jumpto page into a proper page id - if ($newpageid == 0) { - $newpageid = $pageid; - } elseif ($newpageid == LESSON_NEXTPAGE) { - if ($lesson->nextpagedefault) { - // in Flash Card mode... - // ... first 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,qtype"); - shuffle ($allpages); - $found = false; - if ($lesson->nextpagedefault == LESSON_UNSEENPAGE) { - foreach ($allpages as $thispage) { - if (!count_records("lesson_attempts", "pageid", $thispage->id, "userid", - $USER->id, "retry", $nretakes)) { - $found = true; - break; - } - } - } elseif ($lesson->nextpagedefault == LESSON_UNANSWEREDPAGE) { - foreach ($allpages as $thispage) { - if ($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 ($found) { - $newpageid = $thispage->id; - if ($lesson->maxpages) { - // check number of pages viewed (in the lesson) - if (count_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, - "retry", $nretakes) >= $lesson->maxpages) { - $newpageid = LESSON_EOL; - } - } - } else { - $newpageid = LESSON_EOL; - } - } elseif (!$newpageid = $page->nextpageid) { - // no nextpage go to end of lesson - $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 /// - - // 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'); - } - 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); - } - } - - 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 ($lesson->displayleft) { - echo "
"; - } - } - - - - /******************* delete ************************************/ - elseif ($action == 'delete' ) { - - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } - - confirm_sesskey(); - - 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"); - } - - 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); - // ..and the page itself - delete_records("lesson_pages", "id", $pageid); - - // repair the hole in the linkage - if (!$thispage->prevpageid) { - // this is the first page... - if (!$page = get_record("lesson_pages", "id", $thispage->nextpageid)) { - error("Delete: next page not found"); - } - if (!set_field("lesson_pages", "prevpageid", 0, "id", $page->id)) { - error("Delete: unable to set prevpage link"); - } - } elseif (!$thispage->nextpageid) { - // this is the last page... - if (!$page = get_record("lesson_pages", "id", $thispage->prevpageid)) { - error("Delete: prev page not found"); - } - if (!set_field("lesson_pages", "nextpageid", 0, "id", $page->id)) { - error("Delete: unable to set nextpage link"); - } - } else { - // page is in the middle... - if (!$prevpage = get_record("lesson_pages", "id", $thispage->prevpageid)) { - error("Delete: prev page not found"); - } - if (!$nextpage = get_record("lesson_pages", "id", $thispage->nextpageid)) { - error("Delete: next page not found"); - } - if (!set_field("lesson_pages", "nextpageid", $nextpage->id, "id", $prevpage->id)) { - error("Delete: unable to set next link"); - } - if (!set_field("lesson_pages", "prevpageid", $prevpage->id, "id", $nextpage->id)) { - error("Delete: unable to set prev link"); - } - } - redirect("view.php?id=$cm->id", get_string('deletedpage', 'lesson')); - } - - - - /************** edit page ************************************/ - elseif ($action == 'editpage' ) { - - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } - - // get the page - $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); - } - - // set of 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 ///// - $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"); - } - while (true) { - if ($apageid) { - 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; - } - $apageid = $apage->nextpageid; - } else { - // last page reached - break; - } - } - // give teacher a proforma - ?> -

- - - - - -
- 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"; - $n = 0; - switch ($page->qtype) { - case LESSON_BRANCHTABLE : - echo "qtype\">\n"; - /// 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) { - $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"; - break; - case LESSON_TRUEFALSE: - case LESSON_MULTICHOICE: - case LESSON_SHORTANSWER: - case LESSON_NUMERICAL: - echo "\n"; - echo "\n"; - break; - case LESSON_BRANCHTABLE: - 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; - } - $n++; - 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; - } - for ($i = $n; $i < $maxanswers; $i++) { - 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; - echo "\n"; - echo "\n"; - break; - case LESSON_TRUEFALSE: - case LESSON_MULTICHOICE: - case LESSON_SHORTANSWER: - case LESSON_NUMERICAL: - echo "\n"; - echo "\n"; - break; - case LESSON_BRANCHTABLE: - 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_TRUEFALSE: - case LESSON_MULTICHOICE: - case LESSON_SHORTANSWER: - case LESSON_NUMERICAL: - 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 "
-
:
-
"; - echo get_string("pagecontents", "lesson").":
\n"; - print_textarea($usehtmleditor, 25, 70, 630, 400, "contents", $page->contents); - use_html_editor("contents"); // always the editor - 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 : - echo "qtype\">\n"; - echo "
".get_string("clustertitle", "lesson")." \n"; - break; - case LESSON_ENDOFCLUSTER : - echo "qtype\">\n"; - echo "
".get_string("endofclustertitle", "lesson")." \n"; - break; - case LESSON_ENDOFBRANCH : - echo "qtype\">\n"; - echo "
".get_string("endofbranch", "lesson")." \n"; - 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("answer", "lesson")." $nplus1:\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("response", "lesson")." $nplus1:\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("description", "lesson")." $nplus1:\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 CDC-FLAG added in this line... editor would not turn on w/o it - } else { - echo " [".get_string("useeditor", "lesson").": ". - ""; - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea(false, 10, 70, 630, 300, "answer[$n]", $answer->answer); - } - 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("answer", "lesson")." $icorrected:\n"; - echo " [".get_string("useeditor", "lesson").": ". - ""; - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea(false, 10, 70, 630, 300, "answer[$i]"); - echo "
".get_string("matchesanswer", "lesson")." $icorrected:\n"; - echo " [".get_string("useeditor", "lesson").": ". - ""; - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea(false, 10, 70, 630, 300, "response[$i]"); - echo "
".get_string("answer", "lesson")." $iplus1:\n"; - echo " [".get_string("useeditor", "lesson").": ". - ""; - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea(false, 10, 70, 630, 300, "answer[$i]"); - echo "
".get_string("response", "lesson")." $iplus1:\n"; - echo " [".get_string("useeditor", "lesson").": ". - ""; - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea(false, 10, 70, 630, 300, "response[$i]"); - echo "
".get_string("description", "lesson")." $iplus1:\n"; - echo " [".get_string("useeditor", "lesson").": ". - ""; - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea(false, 10, 70, 630, 300, "answer[$i]"); - 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 "

- " - onClick="document.editpage.redisplay.value=1;document.editpage.submit();" /> - " /> - " /> -
-
- id)) { - error("Only teachers can look at this page"); - } - - confirm_sesskey(); - - $timenow = time(); - - $form = 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)) { - error("Insert page: page record not found"); - } - $newpage->lessonid = clean_param($lesson->id, PARAM_INT); - $newpage->prevpageid = clean_param($form->pageid, PARAM_INT); - $newpage->nextpageid = clean_param($page->nextpageid, PARAM_INT); - $newpage->timecreated = $timenow; - $newpage->qtype = $form->qtype; - if (isset($form->qoption)) { - $newpage->qoption = clean_param($form->qoption, PARAM_INT); - } else { - $newpage->qoption = 0; - } - /// CDC-FLAG /// 6/16/04 - if (isset($form->layout)) { - $newpage->layout = clean_param($form->layout, PARAM_INT); - } else { - $newpage->layout = 0; - } - if (isset($form->display)) { - $newpage->display = clean_param($form->display, PARAM_INT); - } else { - $newpage->display = 0; - } - /// CDC-FLAG /// - $newpage->title = clean_param($form->title, PARAM_CLEAN); - $newpage->contents = clean_param(trim($form->contents), PARAM_CLEANHTML); - $newpageid = insert_record("lesson_pages", $newpage); - if (!$newpageid) { - error("Insert page: new page not inserted"); - } - // update the linked list (point the previous page to this new one) - if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $newpage->prevpageid)) { - error("Insert page: unable to update next link"); - } - if ($page->nextpageid) { - // 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"); - } - } - } else { - // new page is the first page - // get the existing (first) page (if any) - if (!$page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) { - // there are no existing pages - $newpage->lessonid = $lesson->id; - $newpage->prevpageid = 0; // this is a first page - $newpage->nextpageid = 0; // this is the only page - $newpage->timecreated = $timenow; - $newpage->qtype = clean_param($form->qtype, PARAM_INT); - if (isset($form->qoption)) { - $newpage->qoption = clean_param($form->qoption, PARAM_INT); - } else { - $newpage->qoption = 0; - } - /// CDC-FLAG /// 6/16/04 - if (isset($form->layout)) { - $newpage->layout = clean_param($form->layout, PARAM_INT); - } else { - $newpage->layout = 0; - } - if (isset($form->display)) { - $newpage->display = clean_param($form->display, PARAM_INT); - } else { - $newpage->display = 0; - } - /// CDC-FLAG /// - $newpage->title = clean_param($form->title, PARAM_CLEAN); - $newpage->contents = clean_param(trim($form->contents), PARAM_CLEANHTML); - $newpageid = insert_record("lesson_pages", $newpage); - if (!$newpageid) { - error("Insert page: new first page not inserted"); - } - } else { - // there are existing pages put this at the start - $newpage->lessonid = $lesson->id; - $newpage->prevpageid = 0; // this is a first page - $newpage->nextpageid = $page->id; - $newpage->timecreated = $timenow; - $newpage->qtype = clean_param($form->qtype, PARAM_INT); - if (isset($form->qoption)) { - $newpage->qoption = clean_param($form->qoption, PARAM_INT); - } else { - $newpage->qoption = 0; - } - /// CDC-FLAG /// 6/16/04 - if (isset($form->layout)) { - $newpage->layout = clean_param($form->layout, PARAM_INT); - } else { - $newpage->layout = 0; - } - if (isset($form->display)) { - $newpage->display = clean_param($form->display, PARAM_INT); - } else { - $newpage->display = 0; - } - /// CDC-FLAG /// - $newpage->title = clean_param($form->title, PARAM_CLEAN); - $newpage->contents = clean_param(trim($form->contents), PARAM_CLEANHTML); - $newpageid = insert_record("lesson_pages", $newpage); - if (!$newpageid) { - error("Insert page: first page not inserted"); - } - // update the linked list - if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $newpage->nextpageid)) { - error("Insert page: unable to update link"); - } - } - } - // 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 = clean_param($form->jumpto[0], PARAM_INT); - } - if (isset($form->score[0])) { - $newanswer->score = clean_param($form->score[0], PARAM_INT); - } - $newanswerid = insert_record("lesson_answers", $newanswer); - if (!$newanswerid) { - error("Insert Page: answer record 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 = clean_param(trim($form->answer[$i]), PARAM_CLEANHTML); - if (isset($form->response[$i])) { - $newanswer->response = clean_param(trim($form->response[$i]), PARAM_CLEANHTML); - } - if (isset($form->jumpto[$i])) { - $newanswer->jumpto = clean_param($form->jumpto[$i], PARAM_INT); - } - /// CDC-FLAG /// - if ($lesson->custom) { - if (isset($form->score[$i])) { - $newanswer->score = clean_param($form->score[$i], PARAM_INT); - } - } - /// 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 ************************************/ - elseif ($action == 'move') { - - 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"); - } - - echo "

\n"; - echo "\n"; - while (true) { - if ($page->id != $pageid) { - if (!$title = trim($page->title)) { - $title = "<< ".get_string("notitle", "lesson")." >>"; - } - echo "\n"; - echo "\n"; - } - if ($page->nextpageid) { - if (!$page = get_record("lesson_pages", "id", $page->nextpageid)) { - error("Teacher view: Next page not found!"); - } - } else { - // last page reached - break; - } - } - echo "
id&sesskey=".$USER->sesskey."&action=moveit&pageid=$pageid&after=0\">". - get_string("movepagehere", "lesson")."
$title
id&sesskey=".$USER->sesskey."&action=moveit&pageid=$pageid&after={$page->id}\">". - get_string("movepagehere", "lesson")."
\n"; - } - - - /****************** moveit ************************************/ - elseif ($action == 'moveit') { - - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } - - confirm_sesskey(); - - $pageid = required_param('pageid', PARAM_INT); // page to move - if (!$page = get_record("lesson_pages", "id", $pageid)) { - error("Moveit: page not found"); - } - $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 - // (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)) { - error("Moveit: last page id not found"); - } - } else { - // the page being moved is the last page, so the new last page will be - $after = $page->prevpageid; - } - } elseif (!$page->prevpageid) { - // the page to be moved was the first page, so the following page must be the new first page - $newfirstpageid = $page->nextpageid; - } else { - // the current first page remains the first page - if (!$newfirstpageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { - error("Moveit: current first page id not found"); - } - } - // the rest is all unconditional... - - // second step. join pages into a ring - if (!$firstpageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { - error("Moveit: firstpageid not found"); - } - if (!$lastpageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "nextpageid", 0)) { - error("Moveit: lastpage not found"); - } - if (!set_field("lesson_pages", "prevpageid", $lastpageid, "id", $firstpageid)) { - error("Moveit: unable to update link"); - } - if (!set_field("lesson_pages", "nextpageid", $firstpageid, "id", $lastpageid)) { - error("Moveit: unable to update link"); - } - - // third step. remove the page to be moved - if (!$prevpageid = get_field("lesson_pages", "prevpageid", "id", $pageid)) { - error("Moveit: prevpageid not found"); - } - if (!$nextpageid = get_field("lesson_pages", "nextpageid", "id", $pageid)) { - error("Moveit: nextpageid not found"); - } - if (!set_field("lesson_pages", "nextpageid", $nextpageid, "id", $prevpageid)) { - error("Moveit: unable to update link"); - } - 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"); - } - if (!set_field("lesson_pages", "nextpageid", $pageid, "id", $after)) { - error("Moveit: unable to update link"); - } - if (!set_field("lesson_pages", "prevpageid", $pageid, "id", $nextpageid)) { - error("Moveit: unable to update link"); - } - // ...and set the links in the moved page - if (!set_field("lesson_pages", "prevpageid", $after, "id", $pageid)) { - error("Moveit: unable to update link"); - } - 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"); - } - if (!set_field("lesson_pages", "prevpageid", 0, "id", $newfirstpageid)) { - error("Moveit: unable to update link"); - } - 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')); - } - - - /****************** update page ************************************/ - elseif ($action == 'updatepage' ) { - - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } - - confirm_sesskey(); - - $timenow = time(); - $form = data_submitted(); - - $page = new stdClass; - $page->id = clean_param($form->pageid, PARAM_INT); - $page->timemodified = $timenow; - $page->qtype = clean_param($form->qtype, PARAM_INT); - if (isset($form->qoption)) { - $page->qoption = clean_param($form->qoption, PARAM_INT); - } else { - $page->qoption = 0; - } - /// CDC-FLAG /// 6/16/04 - if (isset($form->layout)) { - $page->layout = clean_param($form->layout, PARAM_INT); - } else { - $page->layout = 0; - } - if (isset($form->display)) { - $page->display = clean_param($form->display, PARAM_INT); - } else { - $page->display = 0; - } - /// CDC-FLAG /// - $page->title = clean_param($form->title, PARAM_CLEAN); - $page->contents = clean_param(trim($form->contents), PARAM_CLEANHTML); - if (!update_record("lesson_pages", $page)) { - error("Update page: page not updated"); - } - 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->id = $form->answerid[0]; - $oldanswer->timemodified = $timenow; - $oldanswer->jumpto = clean_param($form->jumpto[0], PARAM_INT); - if (isset($form->score[0])) { - $oldanswer->score = clean_param($form->score[0], PARAM_INT); - } - // 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 = ".$page->id)) { - foreach ($answers as $answer) { - if ($answer->id != clean_param($form->answerid[0], PARAM_INT)) { - 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 ($page->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 - if (trim(strip_tags($form->answer[$i])) or $form->answereditor[$i] or $form->responseeditor[$i]) { - if ($form->answerid[$i]) { - $oldanswer = new stdClass; - $oldanswer->id = clean_param($form->answerid[$i], PARAM_INT); - $oldanswer->flags = clean_param($form->answereditor[$i], PARAM_INT) * LESSON_ANSWER_EDITOR + - clean_param($form->responseeditor[$i], PARAM_INT) * LESSON_RESPONSE_EDITOR; - $oldanswer->timemodified = $timenow; - $oldanswer->answer = clean_param(trim($form->answer[$i]), PARAM_CLEANHTML); - if (isset($form->response[$i])) { - $oldanswer->response = clean_param(trim($form->response[$i]), PARAM_CLEANHTML); - } - $oldanswer->jumpto = clean_param($form->jumpto[$i], PARAM_INT); - /// CDC-FLAG /// - if ($lesson->custom) { - $oldanswer->score = clean_param($form->score[$i], PARAM_INT); - } - /// CDC-FLAG /// - if (!update_record("lesson_answers", $oldanswer)) { - error("Update page: answer $i not updated"); - } - } else { - // it's a new answer - $newanswer = new stdClass; // need to clear id if more than one new answer is ben added - $newanswer->lessonid = $lesson->id; - $newanswer->pageid = $page->id; - $newanswer->flags = clean_param($form->answereditor[$i], PARAM_INT) * LESSON_ANSWER_EDITOR + - clean_param($form->responseeditor[$i], PARAM_INT) * LESSON_RESPONSE_EDITOR; - $newanswer->timecreated = $timenow; - $newanswer->answer = clean_param(trim($form->answer[$i]), PARAM_CLEANHTML); - if (isset($form->response[$i])) { - $newanswer->response = clean_param(trim($form->response[$i]), PARAM_CLEANHTML); - } - $newanswer->jumpto = clean_param($form->jumpto[$i], PARAM_INT); - /// CDC-FLAG /// - $newanswer->score = clean_param($form->score[$i], PARAM_INT); - /// 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", clean_param($form->answerid[$i], PARAM_INT))) { - error("Update page: unable to delete answer record"); - } - } - } else { - $oldanswer = new stdClass; - $oldanswer->id = clean_param($form->answerid[$i], PARAM_INT); - $oldanswer->flags = clean_param($form->answereditor[$i], PARAM_INT) * LESSON_ANSWER_EDITOR + - clean_param($form->responseeditor[$i], PARAM_INT) * 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", clean_param($form->answerid[$i], PARAM_INT))) { - error("Update page: unable to delete answer record"); - } - } - } - } - } - 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')); - } - } - - - /*************** no man's land **************************************/ - else { - error("Fatal Error: Unknown Action: ".$action."\n"); - } + // include the appropriate action (check to make sure the file is there first) + if (file_exists('lessonactions/'.$action.'.php')) { + include('lessonactions/'.$action.'.php'); + } else { + error("Fatal Error: Unknown Action: ".$action."\n"); + } + print_footer($course); -?> +?> \ No newline at end of file