From 45c27c7e4b48f98a54707d7fe61b427394caae2d Mon Sep 17 00:00:00 2001 From: rkingdon Date: Thu, 1 Apr 2004 16:56:56 +0000 Subject: [PATCH] Optional use of the HTML editor. --- lang/en/lesson.php | 5 +- mod/lesson/backuplib.php | 4 +- mod/lesson/db/mysql.php | 6 +- mod/lesson/db/mysql.sql | 1 + mod/lesson/db/postgres7.php | 6 +- mod/lesson/db/postgres7.sql | 1 + mod/lesson/lesson.php | 147 +++++++++++++++++++++++++++--------- mod/lesson/lib.php | 19 +++-- mod/lesson/restorelib.php | 1 + mod/lesson/version.php | 2 +- mod/lesson/view.php | 128 ++++++++++++++++++++----------- 11 files changed, 227 insertions(+), 93 deletions(-) diff --git a/lang/en/lesson.php b/lang/en/lesson.php index afbd3dd314..e98e88eff2 100644 --- a/lang/en/lesson.php +++ b/lang/en/lesson.php @@ -33,7 +33,7 @@ $string['gradeis'] = "Grade is \$a"; $string['handlingofretakes'] = "Handling of Re-takes"; $string['here'] = "here"; $string['importquestions'] = "Import Questions"; -$string['jumpto'] = "Jump to"; +$string['jump'] = "Jump"; $string['maximumnumberofanswersbranches'] = "Maximum number of answers/branches"; $string['maximumnumberofattempts'] = "Maximum number of Attempts"; $string['minimumnumberofquestions'] = "Minimum number of Questions"; @@ -66,6 +66,8 @@ $string['pleasecheckoneanswer'] = "Please check one Answer"; $string['pleasecheckoneormoreanswers'] = "Please check one or more Answers"; $string['pleaseenteryouranswerinthebox'] = "Please enter your Answer in the Box"; $string['pleasematchtheabovepairs'] = "Please match the above Pairs"; +$string['reached'] = "reached"; +$string['redisplaypage'] = "Redisplay Page"; $string['response'] = "Response"; $string['sanitycheckfailed'] = "Sanity Check Failed: This attempt has been deleted"; $string['savepage'] = "Save page"; @@ -76,6 +78,7 @@ $string['thatsthecorrectanswer'] = "That's the Correct Answer"; $string['thatsthewronganswer'] = "That's the Wrong Answer"; $string['thefollowingpagesjumptothispage'] = "The following Pages jump to this Page"; $string['thispage'] = "This page"; +$string['useeditor'] = "Use Editor"; $string['usemaximum'] = "Use Maximum"; $string['usemean'] = "Use Mean"; $string['youhaveseen'] = "You have seen more than one page of this lesson already.
Do you want to start at the last page you saw?"; diff --git a/mod/lesson/backuplib.php b/mod/lesson/backuplib.php index e44928285e..8f9be96a04 100644 --- a/mod/lesson/backuplib.php +++ b/mod/lesson/backuplib.php @@ -125,7 +125,8 @@ $status = true; - $lesson_answers = get_records("lesson_answers", "pageid", $pageno); + // get the answers in a set order, the id order + $lesson_answers = get_records("lesson_answers", "pageid", $pageno, "id"); //If there is lesson_answers if ($lesson_answers) { @@ -138,6 +139,7 @@ //Print answer contents fwrite ($bf,full_tag("JUMPTO",8,false,$answer->jumpto)); fwrite ($bf,full_tag("GRADE",8,false,$answer->grade)); + fwrite ($bf,full_tag("FLAGS",8,false,$answer->flags)); fwrite ($bf,full_tag("TIMECREATED",8,false,$answer->timecreated)); fwrite ($bf,full_tag("TIMEMODIFIED",8,false,$answer->timemodified)); fwrite ($bf,full_tag("ANSWERTEXT",8,false,$answer->answer)); diff --git a/mod/lesson/db/mysql.php b/mod/lesson/db/mysql.php index b8f7893a00..e43acd5662 100644 --- a/mod/lesson/db/mysql.php +++ b/mod/lesson/db/mysql.php @@ -35,7 +35,11 @@ function lesson_upgrade($oldversion) { execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `usegrademax` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER grade"); execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `minquestions` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER nextpagedefault"); } - + + if ($oldversion < 2004032700) { + table_column("lesson_answers", "", "flags", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade"); + } + return true; } diff --git a/mod/lesson/db/mysql.sql b/mod/lesson/db/mysql.sql index aa19296c33..195782e7d6 100644 --- a/mod/lesson/db/mysql.sql +++ b/mod/lesson/db/mysql.sql @@ -44,6 +44,7 @@ CREATE TABLE `prefix_lesson_answers` ( `pageid` int(10) unsigned NOT NULL default '0', `jumpto` int(11) NOT NULL default '0', `grade` tinyint(3) unsigned NOT NULL default '0', + `flags` tinyint(3) unsigned NOT NULL default '0', `timecreated` int(10) unsigned NOT NULL default '0', `timemodified` int(10) unsigned NOT NULL default '0', `answer` text NOT NULL default '', diff --git a/mod/lesson/db/postgres7.php b/mod/lesson/db/postgres7.php index 34a2e41124..551a6ce3f9 100644 --- a/mod/lesson/db/postgres7.php +++ b/mod/lesson/db/postgres7.php @@ -35,7 +35,11 @@ function lesson_upgrade($oldversion) { table_column("lesson", "", "usegrademax", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade"); table_column("lesson", "", "minquestions", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "nextpagedefault"); } - + + if ($oldversion < 2004032700) { + table_column("lesson_answers", "", "flags", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade"); + } + return true; } diff --git a/mod/lesson/db/postgres7.sql b/mod/lesson/db/postgres7.sql index 9bd7671c36..f6ff75e2a3 100644 --- a/mod/lesson/db/postgres7.sql +++ b/mod/lesson/db/postgres7.sql @@ -42,6 +42,7 @@ CREATE TABLE prefix_lesson_answers ( pageid INT8 NOT NULL default '0', jumpto INT8 NOT NULL default '0', grade INT8 NOT NULL default '0', + flags INT8 NOT NULL default '0', timecreated INT8 NOT NULL default '0', timemodified INT8 NOT NULL default '0', answer text NOT NULL default '', diff --git a/mod/lesson/lesson.php b/mod/lesson/lesson.php index 4e29e94d26..9f9cee9cdb 100644 --- a/mod/lesson/lesson.php +++ b/mod/lesson/lesson.php @@ -110,7 +110,7 @@ echo "".get_string("description", "lesson")." $iplus1:
\n"; print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$i]"); echo "\n"; - echo "".get_string("jumpto", "lesson").": \n"; + echo "".get_string("jump", "lesson")." $iplus1: \n"; if ($i) { // answers 2, 3, 4... jumpto this page lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); @@ -118,7 +118,7 @@ // answer 1 jumpto next page lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); } - helpbutton("jumpto", get_string("jumpto", "lesson"), "lesson"); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); echo "\n"; } use_html_editor(); @@ -240,6 +240,7 @@ echo ""; echo get_string("pagecontents", "lesson").":
\n"; print_textarea($usehtmleditor, 25,70, 630, 400, "contents"); + use_html_editor("contents"); echo "\n"; echo "".get_string("questiontype", "lesson").": \n"; choose_from_menu($LESSON_QUESTION_TYPE, "qtype", LESSON_MULTICHOICE, ""); @@ -251,12 +252,12 @@ for ($i = 0; $i < $lesson->maxanswers; $i++) { $iplus1 = $i + 1; echo "".get_string("answer", "lesson")." $iplus1:
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$i]"); + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); echo "\n"; echo "".get_string("response", "lesson")." $iplus1:
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$i]"); + print_textarea(false, 6, 70, 630, 300, "response[$i]"); echo "\n"; - echo "".get_string("jumpto", "lesson").": \n"; + echo "".get_string("jump", "lesson")." $iplus1: \n"; if ($i) { // answers 2, 3, 4... jumpto this page lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); @@ -264,10 +265,9 @@ // answer 1 jumpto next page lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); } - helpbutton("jumpto", get_string("jumpto", "lesson"), "lesson"); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); echo "\n"; } - use_html_editor(); // close table and form ?>
@@ -409,6 +409,7 @@ $noanswer = true; break; } + // get the answers in a set order, the id order if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { error("Continue: No answers found"); } @@ -582,14 +583,14 @@ $newpageid = $pageid; // display same page again print_simple_box(get_string("noanswer", "lesson"), "center"); } else { - $ntries = 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->lessonid = $lesson->id; $attempt->pageid = $pageid; $attempt->userid = $USER->id; $attempt->answerid = $answerid; - $attempt->retry = $ntries; + $attempt->retry = $nretakes; $attempt->correct = $correctanswer; $attempt->timeseen = time(); if (!$newattemptid = insert_record("lesson_attempts", $attempt)) { @@ -599,11 +600,14 @@ // 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", $ntries); + "retry", $nretakes); if ($nattempts >= $lesson->maxattempts) { - print_heading(get_string("maximumnumberofattempts", "lesson")."
". - get_string("movingtonextpage", "lesson")); + 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; } } @@ -621,7 +625,7 @@ if ($lesson->nextpagedefault == LESSON_UNSEENPAGE) { foreach ($allpages as $thispage) { if (!count_records("lesson_attempts", "pageid", $thispage->id, "userid", - $USER->id, "retry", $ntries)) { + $USER->id, "retry", $nretakes)) { $found = true; break; } @@ -629,7 +633,7 @@ } elseif ($lesson->nextpagedefault == LESSON_UNANSWEREDPAGE) { foreach ($allpages as $thispage) { if (!count_records_select("lesson_attempts", "pageid = $thispage->id AND - userid = $USER->id AND correct = 1 AND retry = $ntries")) { + userid = $USER->id AND correct = 1 AND retry = $nretakes")) { $found = true; break; } @@ -640,7 +644,7 @@ if ($lesson->maxpages) { // check number of pages viewed (in the lesson) if (count_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, - "retry", $ntries) >= $lesson->maxpages) { + "retry", $nretakes) >= $lesson->maxpages) { $newpageid = LESSON_EOL; } } @@ -771,10 +775,11 @@ // give teacher a proforma ?> -
+ +
@@ -785,6 +790,7 @@ echo "\n"; $n = 0; switch ($page->qtype) { @@ -792,24 +798,24 @@ 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) { @@ -839,22 +847,63 @@ case LESSON_SHORTANSWER: case LESSON_NUMERICAL: case LESSON_MATCHING: - echo "\n"; - echo "\n"; break; case LESSON_BRANCHTABLE: - echo "\n"; break; } - echo "\n"; $n++; } @@ -869,29 +918,42 @@ case LESSON_SHORTANSWER: case LESSON_NUMERICAL: case LESSON_MATCHING: - echo "\n"; - echo "\n"; break; case LESSON_BRANCHTABLE: - echo "\n"; break; } - echo "\n"; } } - use_html_editor(); // close table and form ?>
"; echo get_string("pagecontents", "lesson").":
\n"; print_textarea($usehtmleditor, 25, 70, 630, 400, "contents", $page->contents); + use_html_editor("contents"); // always the editor echo "
".get_string("questiontype", "lesson").": \n"; choose_from_menu($LESSON_QUESTION_TYPE, "qtype", $page->qtype, ""); echo "  "; + echo " ".get_string("casesensitive", "lesson").": \n"; if ($page->qoption) { echo ""; } else { echo ""; } - echo " ".get_string("casesensitive", "lesson")."\n"; helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson"); break; case LESSON_MULTICHOICE : echo "
".get_string("questiontype", "lesson").": \n"; choose_from_menu($LESSON_QUESTION_TYPE, "qtype", $page->qtype, ""); echo "  "; + echo " ".get_string("multianswer", "lesson").": \n"; if ($page->qoption) { echo ""; } else { echo ""; } - echo " ".get_string("multianswer", "lesson")."\n"; helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson"); break; case LESSON_TRUEFALSE : @@ -829,8 +835,10 @@ break; } echo "
".get_string("answer", "lesson")." $nplus1:
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); + echo "
".get_string("answer", "lesson")." $nplus1:\n"; + if ($flags & LESSON_ANSWER_EDITOR) { + echo " [".get_string("useeditor", "lesson").": ". + ""; + 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").": ". + ""; + 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"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$n]", $answer->response); + echo "
".get_string("response", "lesson")." $nplus1:\n"; + if ($flags & LESSON_RESPONSE_EDITOR) { + echo " [".get_string("useeditor", "lesson").": ". + ""; + 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").": ". + ""; + 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"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); + echo "
".get_string("description", "lesson")." $nplus1:\n"; + if ($flags & LESSON_ANSWER_EDITOR) { + echo " [".get_string("useeditor", "lesson").": ". + ""; + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); + } 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("jumpto", "lesson").": \n"; + echo "
".get_string("jump", "lesson")." $nplus1: \n"; lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); - helpbutton("jumpto", get_string("jumpto", "lesson"), "lesson"); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); echo "
".get_string("answer", "lesson")." $iplus1:
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$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"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$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"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$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("jumpto", "lesson").": \n"; + echo "
".get_string("jump", "lesson")." $iplus1: \n"; lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - helpbutton("jumpto", get_string("jumpto", "lesson"), "lesson"); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); echo "

+ " + onclick="document.editpage.redisplay.value=1;document.editpage.submit();"> "> ">
@@ -1186,9 +1248,14 @@ } else { // it's an "ordinary" page for ($i = 0; $i < $lesson->maxanswers; $i++) { - if (trim(strip_tags($form->answer[$i]))) { // strip_tags because the HTML gives


... + // 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]) { + unset($oldanswer); $oldanswer->id = $form->answerid[$i]; + $oldanswer->flags = $form->answereditor[$i] * LESSON_ANSWER_EDITOR + + $form->responseeditor[$i] * LESSON_RESPONSE_EDITOR; $oldanswer->timemodified = $timenow; $oldanswer->answer = trim($form->answer[$i]); if (isset($form->response[$i])) { @@ -1203,6 +1270,8 @@ unset($newanswer); // need to clear id if more than one new answer is ben added $newanswer->lessonid = $lesson->id; $newanswer->pageid = $page->id; + $newanswer->flags = $form->answereditor[$i] * LESSON_ANSWER_EDITOR + + $form->responseeditor[$i] * LESSON_RESPONSE_EDITOR; $newanswer->timecreated = $timenow; $newanswer->answer = trim($form->answer[$i]); if (isset($form->response[$i])) { @@ -1224,7 +1293,11 @@ } } } - redirect("view.php?id=$cm->id", get_string("ok")); + if ($form->redisplay) { + redirect("lesson.php?id=$cm->id&action=editpage&pageid=$page->id"); + } else { + redirect("view.php?id=$cm->id", get_string("ok")); + } } diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index 8fe287e8ff..7f92591395 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -53,12 +53,7 @@ if (!defined("LESSON_NUMERICAL")) { if (!defined("LESSON_MULTIANSWER")) { define("LESSON_MULTIANSWER", "9"); } -if (!defined("LESSON_BRANCHTABLE")) { - define("LESSON_BRANCHTABLE", "20"); -} -if (!defined("LESSON_ENDOFBRANCH")) { - define("LESSON_ENDOFBRANCH", "21"); -} + $LESSON_QUESTION_TYPE = array ( LESSON_MULTICHOICE => get_string("multichoice", "quiz"), LESSON_TRUEFALSE => get_string("truefalse", "quiz"), LESSON_SHORTANSWER => get_string("shortanswer", "quiz"), @@ -70,7 +65,19 @@ $LESSON_QUESTION_TYPE = array ( LESSON_MULTICHOICE => get_string("multichoice", // LESSON_MULTIANSWER => get_string("multianswer", "quiz"), ); +if (!defined("LESSON_BRANCHTABLE")) { + define("LESSON_BRANCHTABLE", "20"); +} +if (!defined("LESSON_ENDOFBRANCH")) { + define("LESSON_ENDOFBRANCH", "21"); +} +if (!defined("LESSON_ANSWER_EDITOR")) { + define("LESSON_ANSWER_EDITOR", "1"); +} +if (!defined("LESSON_RESPONSE_EDITOR")) { + define("LESSON_RESPONSE_EDITOR", "2"); +} /*******************************************************************/ function lesson_choose_from_menu ($options, $name, $selected="", $nothing="choose", $script="", $nothingvalue="0", $return=false) { /// Given an array of value, creates a popup menu to be part of a form diff --git a/mod/lesson/restorelib.php b/mod/lesson/restorelib.php index e8cb74d786..c19399a130 100644 --- a/mod/lesson/restorelib.php +++ b/mod/lesson/restorelib.php @@ -200,6 +200,7 @@ // the absolute jumps will need fixing $answer->jumpto = backup_todb($answer_info['#']['JUMPTO']['0']['#']); $answer->grade = backup_todb($answer_info['#']['GRADE']['0']['#']); + $answer->flags = backup_todb($answer_info['#']['FLAGS']['0']['#']); $answer->timecreated = backup_todb($answer_info['#']['TIMECREATED']['0']['#']); $answer->timemodified = backup_todb($answer_info['#']['TIMEMODIFIED']['0']['#']); $answer->answer = backup_todb($answer_info['#']['ANSWERTEXT']['0']['#']); diff --git a/mod/lesson/version.php b/mod/lesson/version.php index a263869380..45896bdd51 100644 --- a/mod/lesson/version.php +++ b/mod/lesson/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2004032400; // The current module version (Date: YYYYMMDDXX) +$module->version = 2004032700; // The current module version (Date: YYYYMMDDXX) $module->requires = 2004013101; // Requires this Moodle version $module->cron = 0; // Period for cron to check this module (secs) diff --git a/mod/lesson/view.php b/mod/lesson/view.php index fb2f7baf01..cfadfffe06 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -187,6 +187,7 @@ print_heading($page->title); print_simple_box(format_text($page->contents), 'center'); echo "
\n"; + // get the answers in a set order, the id order if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { echo ""; echo "id\">"; @@ -294,9 +295,49 @@ echo "\n"; echo "id\">\n"; echo "\n"; - if (!$newpageid = get_field("lesson_pages", "nextpageid", "id", $pageid)) { - // this is the last page - flag end of lesson - $newpageid = EOL; + if ($lesson->nextpagedefault) { + // in Flash Card mode... + // ...first get number of retakes + $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); + // ...then get the page ids (lessonid the 5th param is needed to make get_records play) + $allpages = get_records("lesson_pages", "lessonid", $lesson->id, "id", "id,lessonid"); + shuffle ($allpages); + $found = false; + if ($lesson->nextpagedefault == LESSON_UNSEENPAGE) { + foreach ($allpages as $thispage) { + if (!count_records("lesson_attempts", "pageid", $thispage->id, "userid", + $USER->id, "retry", $nretakes)) { + $found = true; + break; + } + } + } elseif ($lesson->nextpagedefault == LESSON_UNANSWEREDPAGE) { + foreach ($allpages as $thispage) { + if (!count_records_select("lesson_attempts", "pageid = $thispage->id AND + userid = $USER->id AND correct = 1 AND retry = $nretakes")) { + $found = true; + break; + } + } + } + if ($found) { + $newpageid = $thispage->id; + if ($lesson->maxpages) { + // check number of pages viewed (in the lesson) + if (count_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, + "retry", $nretakes) >= $lesson->maxpages) { + $newpageid = LESSON_EOL; + } + } + } else { + $newpageid = LESSON_EOL; + } + } else { + // in normal lesson mode... + if (!$newpageid = get_field("lesson_pages", "nextpageid", "id", $pageid)) { + // this is the last page - flag end of lesson + $newpageid = EOL; + } } echo "\n"; echo "

"; echo get_string("pagecontents", "lesson").":
\n"; print_textarea($usehtmleditor, 25, 70, 630, 400, "contents"); + use_html_editor("contents"); echo "\n"; echo "".get_string("questiontype", "lesson").": \n"; choose_from_menu($LESSON_QUESTION_TYPE, "qtype", LESSON_MULTICHOICE, ""); @@ -407,10 +449,10 @@ for ($i = 0; $i < $lesson->maxanswers; $i++) { $iplus1 = $i + 1; echo "".get_string("answer", "lesson")." $iplus1:
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 100, "answer[$i]"); + print_textarea(false, 6, 70, 630, 100, "answer[$i]"); echo "\n"; echo "".get_string("response", "lesson")." $iplus1:
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 100, "response[$i]"); + print_textarea(false, 6, 70, 630, 100, "response[$i]"); echo "\n"; if ($i) { // answers 2,3,4... jump to this page @@ -420,7 +462,6 @@ echo "\n"; } } - use_html_editor(); // close table and form ?>
@@ -444,7 +485,7 @@ get_string("importquestions", "lesson")." | ". "id&action=addbranchtable&pageid=0\">". get_string("addabranchtable", "lesson")." | ". - "id&action=addendofbranch&pageid=0\">". + "id&action=addpage&pageid=0\">". get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). "\n"; } @@ -465,52 +506,49 @@ echo "\n"; print_simple_box(format_text($page->contents), "center"); echo "\n"; + // get the answers in a set order, the id order if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { + echo "cellheading2\" colspan=\"2\" align=\"center\">\n"; + switch ($page->qtype) { + case LESSON_SHORTANSWER : + echo $LESSON_QUESTION_TYPE[$page->qtype]; + if ($page->qoption) { + echo " - ".get_string("casesensitive", "lesson"); + } + break; + case LESSON_MULTICHOICE : + echo $LESSON_QUESTION_TYPE[$page->qtype]; + if ($page->qoption) { + echo " - ".get_string("multianswer", "lesson"); + } + break; + case LESSON_MATCHING : + echo $LESSON_QUESTION_TYPE[$page->qtype]; + if (!lesson_iscorrect($page->id, $answer->jumpto)) { + echo " - ".get_string("firstanswershould", "lesson"); + } + break; + case LESSON_TRUEFALSE : + case LESSON_NUMERICAL : + echo $LESSON_QUESTION_TYPE[$page->qtype]; + break; + case LESSON_BRANCHTABLE : + echo get_string("branchtable", "lesson"); + break; + case LESSON_ENDOFBRANCH : + echo get_string("endofbranch", "lesson"); + break; + } + echo "\n"; $i = 1; foreach ($answers as $answer) { - echo "cellheading2\" colspan=\"2\" align=\"center\">\n"; - if ($i == 1) { - switch ($page->qtype) { - case LESSON_SHORTANSWER : - echo $LESSON_QUESTION_TYPE[$page->qtype]; - if ($page->qoption) { - echo " - ".get_string("casesensitive", "lesson"); - } - break; - case LESSON_MULTICHOICE : - echo $LESSON_QUESTION_TYPE[$page->qtype]; - if ($page->qoption) { - echo " - ".get_string("multianswer", "lesson"); - } - break; - case LESSON_MATCHING : - echo $LESSON_QUESTION_TYPE[$page->qtype]; - if (!lesson_iscorrect($page->id, $answer->jumpto)) { - echo " - ".get_string("firstanswershould", "lesson"); - } - break; - case LESSON_TRUEFALSE : - case LESSON_NUMERICAL : - echo $LESSON_QUESTION_TYPE[$page->qtype]; - break; - case LESSON_BRANCHTABLE : - echo get_string("branchtable", "lesson"); - break; - case LESSON_ENDOFBRANCH : - echo get_string("endofbranch", "lesson"); - break; - } - } else { - echo " "; - } - echo "\n"; switch ($page->qtype) { case LESSON_MULTICHOICE: case LESSON_TRUEFALSE: case LESSON_SHORTANSWER: case LESSON_NUMERICAL: case LESSON_MATCHING: - echo "\n"; + echo "cellheading2\" align=\"right\" valign=\"top\" width=\"20%\">\n"; if (lesson_iscorrect($page->id, $answer->jumpto)) { // underline correct answers echo "".get_string("answer", "lesson")." $i: \n"; @@ -544,7 +582,7 @@ $jumptitle = "".get_string("notdefined", "lesson").""; } } - echo "".get_string("jumpto", "lesson").": "; + echo "".get_string("jump", "lesson")." $i:"; echo "\n"; echo "$jumptitle\n"; $i++; -- 2.39.5