]> git.mjollnir.org Git - moodle.git/commitdiff
Optional use of the HTML editor.
authorrkingdon <rkingdon>
Thu, 1 Apr 2004 16:56:56 +0000 (16:56 +0000)
committerrkingdon <rkingdon>
Thu, 1 Apr 2004 16:56:56 +0000 (16:56 +0000)
lang/en/lesson.php
mod/lesson/backuplib.php
mod/lesson/db/mysql.php
mod/lesson/db/mysql.sql
mod/lesson/db/postgres7.php
mod/lesson/db/postgres7.sql
mod/lesson/lesson.php
mod/lesson/lib.php
mod/lesson/restorelib.php
mod/lesson/version.php
mod/lesson/view.php

index afbd3dd3148fd2471dc8a86a8be36e5f08cc1e45..e98e88eff23ff46cb7130cd325f39bf052abfb1d 100644 (file)
@@ -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.<br />Do you want to start at the last page you saw?";
index e44928285e83ed03376ed81e0ceb65d97b67c476..8f9be96a0463640c2fe608b1f638b2674b6908a1 100644 (file)
 
         $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) {
                 //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));
index b8f7893a006a30014ecab5e5965ec9eb3dbe5174..e43acd56625a516bee87e579b1685c4c4ed32c0c 100644 (file)
@@ -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;
 }
 
index aa19296c33c30c26bd428b35b63e4e39fe8ae6bb..195782e7d6ec8bf9f470ff1a6249e26fbdd99573 100644 (file)
@@ -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 '',
index 34a2e411248d10e25530fa22ec1483c5ff2676b3..551a6ce3f9ff86fc58b4d4c998f64458f6f78c6e 100644 (file)
@@ -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;
 }
 
index 9bd7671c3690ffc2c475a7104afc2192021a8ec1..f6ff75e2a32551d78d679d9d32048d996f68f206 100644 (file)
@@ -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 '',
index 4e29e94d26274bcb3a12789602215542d56bf5d1..9f9cee9cdb54c7f6c0a24d831a2279086ac732ca 100644 (file)
             echo "<tr><td><b>".get_string("description", "lesson")." $iplus1:</b><br />\n";
             print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$i]");
             echo "</td></tr>\n";
-            echo "<tr><td><B>".get_string("jumpto", "lesson").":</b> \n";
+            echo "<tr><td><B>".get_string("jump", "lesson")." $iplus1:</b> \n";
             if ($i) {
                 // answers 2, 3, 4... jumpto this page
                 lesson_choose_from_menu($jump, "jumpto[$i]", 0, "");
                 // 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 "</td></tr>\n";
         }
         use_html_editor();
         echo "<tr><td><b>";
         echo get_string("pagecontents", "lesson").":</b><br />\n";
         print_textarea($usehtmleditor, 25,70, 630, 400, "contents");
+        use_html_editor("contents");
         echo "</td></tr>\n";
         echo "<tr><td><b>".get_string("questiontype", "lesson").":</b> \n";
         choose_from_menu($LESSON_QUESTION_TYPE, "qtype", LESSON_MULTICHOICE, "");
         for ($i = 0; $i < $lesson->maxanswers; $i++) {
             $iplus1 = $i + 1;
             echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b><br />\n";
-            print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$i]");
+            print_textarea(false, 6, 70, 630, 300, "answer[$i]");
             echo "</td></tr>\n";
             echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b><br />\n";
-            print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$i]");
+            print_textarea(false, 6, 70, 630, 300, "response[$i]");
             echo "</td></tr>\n";
-            echo "<tr><td><B>".get_string("jumpto", "lesson").":</b> \n";
+            echo "<tr><td><B>".get_string("jump", "lesson")." $iplus1:</b> \n";
             if ($i) {
                 // answers 2, 3, 4... jumpto this page
                 lesson_choose_from_menu($jump, "jumpto[$i]", 0, "");
                 // 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 "</td></tr>\n";
         }
-        use_html_editor();
         // close table and form
         ?>
         </table><br />
                         $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");
                     }
             $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)) {
                     // 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")."<br />".
-                                get_string("movingtonextpage", "lesson"));
+                        if ($lesson->maxattempts > 1) { // don't bother with message if only one attempt
+                            echo "<p align=\"center\">(".get_string("maximumnumberofattempts", "lesson").
+                                " ".get_string("reached", "lesson")." - ".
+                                get_string("movingtonextpage", "lesson").")</p>\n";
+                        }
                         $newpageid = LESSON_NEXTPAGE;
                     }
                 }
                     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;
                             }
                     } 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;
                             }
                         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;
                             }
                         }
         
         // give teacher a proforma
         ?>
-        <form name="form" method="post" action="lesson.php">
+        <form name="editpage" method="post" action="lesson.php">
         <input type="hidden" name="id" value="<?PHP echo $cm->id ?>">
         <input type="hidden" name="action" value="updatepage">
         <input type="hidden" name="pageid" value="<?PHP echo $_GET['pageid'] ?>">
+        <input type="hidden" name="redisplay" value="0">
         <center><table cellpadding=5 border=1>
         <tr><td align="center">
         <tr valign="top">
         echo "<tr><td><b>";
         echo get_string("pagecontents", "lesson").":</b><br />\n";
         print_textarea($usehtmleditor, 25, 70, 630, 400, "contents", $page->contents);
+        use_html_editor("contents"); // always the editor
         echo "</td></tr>\n";
         $n = 0;
         switch ($page->qtype) {
                 echo "<tr><td><b>".get_string("questiontype", "lesson").":</b> \n";
                 choose_from_menu($LESSON_QUESTION_TYPE, "qtype", $page->qtype, "");
                 echo "&nbsp;&nbsp;";
+                echo " <b>".get_string("casesensitive", "lesson").":</b> \n";
                 if ($page->qoption) {
                     echo "<input type=\"checkbox\" name=\"qoption\" value=\"1\" checked=\"checked\"/>";
                 } else {
                     echo "<input type=\"checkbox\" name=\"qoption\" value=\"1\"/>";
                 }
-                echo " <b>".get_string("casesensitive", "lesson")."</b>\n";
                 helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson");
                 break;
             case LESSON_MULTICHOICE :
                 echo "<tr><td><b>".get_string("questiontype", "lesson").":</b> \n";
                 choose_from_menu($LESSON_QUESTION_TYPE, "qtype", $page->qtype, "");
                 echo "&nbsp;&nbsp;";
+                echo " <b>".get_string("multianswer", "lesson").":</b> \n";
                 if ($page->qoption) {
                     echo "<input type=\"checkbox\" name=\"qoption\" value=\"1\" checked=\"checked\"/>";
                 } else {
                     echo "<input type=\"checkbox\" name=\"qoption\" value=\"1\"/>";
                 }
-                echo " <b>".get_string("multianswer", "lesson")."</b>\n";
                 helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson");
                 break;
             case LESSON_TRUEFALSE :
                 break;                
         }       
         echo "</td></tr>\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 "<input type=\"hidden\" name=\"answerid[$n]\" value=\"$answer->id\">\n";
                 switch ($page->qtype) {
                     case LESSON_SHORTANSWER:
                     case LESSON_NUMERICAL:
                     case LESSON_MATCHING:
-                        echo "<tr><td><b>".get_string("answer", "lesson")." $nplus1:</b><br />\n";
-                        print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer);
+                        echo "<tr><td><b>".get_string("answer", "lesson")." $nplus1:</b>\n";
+                        if ($flags & LESSON_ANSWER_EDITOR) {
+                            echo " [".get_string("useeditor", "lesson").": ".
+                                "<input type=\"checkbox\" name=\"answereditor[$n]\" value=\"1\" 
+                                checked=\"checked\">";
+                            helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                            echo "]<br />\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").": ".
+                                "<input type=\"checkbox\" name=\"answereditor[$n]\" value=\"1\">";
+                            helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                            echo "]<br />\n";
+                            print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer);
+                        }
                         echo "</td></tr>\n";
-                        echo "<tr><td><b>".get_string("response", "lesson")." $nplus1:</b><br />\n";
-                        print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$n]", $answer->response);
+                        echo "<tr><td><b>".get_string("response", "lesson")." $nplus1:</b>\n";
+                        if ($flags & LESSON_RESPONSE_EDITOR) {
+                            echo " [".get_string("useeditor", "lesson").": ".
+                                "<input type=\"checkbox\" name=\"responseeditor[$n]\" value=\"1\" 
+                                checked=\"checked\">";
+                            helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                            echo "]<br />\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").": ".
+                                "<input type=\"checkbox\" name=\"responseeditor[$n]\" value=\"1\">";
+                            helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                            echo "]<br />\n";
+                            print_textarea(false, 6, 70, 630, 300, "response[$n]", $answer->response);
+                        }
                         echo "</td></tr>\n";
                         break;
                     case LESSON_BRANCHTABLE:
-                        echo "<tr><td><b>".get_string("description", "lesson")." $nplus1:</b><br />\n";
-                        print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer);
+                        echo "<tr><td><b>".get_string("description", "lesson")." $nplus1:</b>\n";
+                        if ($flags & LESSON_ANSWER_EDITOR) {
+                            echo " [".get_string("useeditor", "lesson").": ".
+                                "<input type=\"checkbox\" name=\"answereditor[$n]\" value=\"1\" 
+                                checked=\"checked\">";
+                            helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                            echo "]<br />\n";
+                            print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer);
+                        } else {
+                            echo " [".get_string("useeditor", "lesson").": ".
+                                "<input type=\"checkbox\" name=\"answereditor[$n]\" value=\"1\">";
+                            helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                            echo "]<br />\n";
+                            print_textarea(false, 10, 70, 630, 300, "answer[$n]", $answer->answer);
+                        }
                         echo "</td></tr>\n";
                         break;
                 }
-                echo "<tr><td><b>".get_string("jumpto", "lesson").":</b> \n";
+                echo "<tr><td><b>".get_string("jump", "lesson")." $nplus1:</b> \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 "</td></tr>\n";
                 $n++;
             }
                     case LESSON_SHORTANSWER:
                     case LESSON_NUMERICAL:
                     case LESSON_MATCHING:
-                        echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b><br />\n";
-                        print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$i]");
+                        echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b>\n";
+                        echo " [".get_string("useeditor", "lesson").": ".
+                            "<input type=\"checkbox\" name=\"answereditor[$i]\" value=\"1\">";
+                        helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                        echo "]<br />\n";
+                        print_textarea(false, 10, 70, 630, 300, "answer[$i]");
                         echo "</td></tr>\n";
-                        echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b><br />\n";
-                        print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$i]");
+                        echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b>\n";
+                        echo " [".get_string("useeditor", "lesson").": ".
+                            "<input type=\"checkbox\" name=\"responseeditor[$i]\" value=\"1\">";
+                        helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                        echo "]<br />\n";
+                        print_textarea(false, 10, 70, 630, 300, "response[$i]");
                         echo "</td></tr>\n";
                         break;
                     case LESSON_BRANCHTABLE:
-                        echo "<tr><td><b>".get_string("description", "lesson")." $iplus1:</b><br />\n";
-                        print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$i]");
+                        echo "<tr><td><b>".get_string("description", "lesson")." $iplus1:</b>\n";
+                        echo " [".get_string("useeditor", "lesson").": ".
+                            "<input type=\"checkbox\" name=\"answereditor[$i]\" value=\"1\">";
+                        helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                        echo "]<br />\n";
+                        print_textarea(false, 10, 70, 630, 300, "answer[$i]");
                         echo "</td></tr>\n";
                         break;
                 }
-                echo "<tr><td><B>".get_string("jumpto", "lesson").":</b> \n";
+                echo "<tr><td><B>".get_string("jump", "lesson")." $iplus1:</b> \n";
                 lesson_choose_from_menu($jump, "jumpto[$i]", 0, "");
-                helpbutton("jumpto", get_string("jumpto", "lesson"), "lesson");
+                helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
                 echo "</td></tr>\n";
             }
         }
-        use_html_editor();
         // close table and form
         ?>
         </table><br />
+        <input type="button" value="<?php print_string("redisplaypage", "lesson") ?>" 
+            onclick="document.editpage.redisplay.value=1;document.editpage.submit();">
         <input type="submit" value="<?php  print_string("savepage", "lesson") ?>">
         <input type="submit" name="cancel" value="<?php  print_string("cancel") ?>">
         </center>
         } 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 <p><br />...
+                // strip tags because the editor gives <p><br />...
+                // 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])) {
                         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])) {
                 }
             }
         }
-               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"));
+        }
     }
        
 
index 8fe287e8ff23a33640b7aef52b0ea879b88555bd..7f9259139594cc20b2bb4c5c8fa7e99a28a22d14 100644 (file)
@@ -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
index e8cb74d786ac5fad0411f7bf441ad5dbdcbc8c88..c19399a130170f6a9e8e70440afc5ad79ffbc19f 100644 (file)
                 // 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']['#']);
index a263869380790b6deae7bc4eedc784e8380e3363..45896bdd5137600736cba2e22701dab81d6928c1 100644 (file)
@@ -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)
 
index fb2f7baf011f949b72027847c6bfaabd746a1107..cfadfffe06e718b097cfb86c87971830006398ba 100644 (file)
             print_heading($page->title);
             print_simple_box(format_text($page->contents), 'center');
             echo "<br />\n";
+            // get the answers in a set order, the id order
             if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) {
                 echo "<form name=\"answerform\" method =\"post\" action=\"lesson.php\">";
                 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">";
                 echo "<form name=\"pageform\" method =\"post\" action=\"view.php\">\n";
                 echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">\n";
                 echo "<input type=\"hidden\" name=\"action\" value=\"navigation\">\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 "<input type=\"hidden\" name=\"pageid\" value=\"$newpageid\">\n";
                 echo "<p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
             echo "<tr><td><b>";
             echo get_string("pagecontents", "lesson").":</b><br />\n";
             print_textarea($usehtmleditor, 25, 70, 630, 400, "contents");
+            use_html_editor("contents");
             echo "</td></tr>\n";
             echo "<tr><td><b>".get_string("questiontype", "lesson").":</b> \n";
             choose_from_menu($LESSON_QUESTION_TYPE, "qtype", LESSON_MULTICHOICE, "");
             for ($i = 0; $i < $lesson->maxanswers; $i++) {
                 $iplus1 = $i + 1;
                 echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b><br />\n";
-                print_textarea($usehtmleditor, 20, 70, 630, 100, "answer[$i]");
+                print_textarea(false, 6, 70, 630, 100, "answer[$i]");
                 echo "</td></tr>\n";
                 echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b><br />\n";
-                print_textarea($usehtmleditor, 20, 70, 630, 100, "response[$i]");
+                print_textarea(false, 6, 70, 630, 100, "response[$i]");
                 echo "</td></tr>\n";
                 if ($i) {
                     // answers 2,3,4... jump to this page
                     echo "<input type=\"hidden\" name=\"jumpto[$i]\" value =\"".LESSON_NEXTPAGE."\">\n";
                 }
             }
-            use_html_editor();
             // close table and form
             ?>
             </table><br />
                     get_string("importquestions", "lesson")."</a> | ".
                     "<a href=\"lesson.php?id=$cm->id&action=addbranchtable&pageid=0\">".
                     get_string("addabranchtable", "lesson")."</a> | ".
-                    "<a href=\"lesson.php?id=$cm->id&action=addendofbranch&pageid=0\">".
+                    "<a href=\"lesson.php?id=$cm->id&action=addpage&pageid=0\">".
                     get_string("addaquestionpage", "lesson")." ".get_string("here","lesson").
                     "</a></small></td></tr>\n";
             }
                 echo "<tr><td colspan=\"2\">\n";
                 print_simple_box(format_text($page->contents), "center");
                 echo "</td></tr>\n";
+                // get the answers in a set order, the id order
                 if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) {
+                    echo "<tr><td bgcolor=\"$THEME->cellheading2\" colspan=\"2\" align=\"center\"><b>\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 "</td></tr>\n";
                     $i = 1;
                     foreach ($answers as $answer) {
-                        echo "<tr><td bgcolor=\"$THEME->cellheading2\" colspan=\"2\" align=\"center\"><b>\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 "&nbsp;";
-                        }
-                        echo "</b></td></tr>\n";
                         switch ($page->qtype) {
                             case LESSON_MULTICHOICE:
                             case LESSON_TRUEFALSE:
                             case LESSON_SHORTANSWER:
                             case LESSON_NUMERICAL:
                             case LESSON_MATCHING:
-                                echo "<tr><td align=\"right\" valign=\"top\" width=\"20%\">\n";
+                                echo "<tr><td bgcolor=\"$THEME->cellheading2\" align=\"right\" valign=\"top\" width=\"20%\">\n";
                                 if (lesson_iscorrect($page->id, $answer->jumpto)) {
                                     // underline correct answers
                                     echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
                                 $jumptitle = "<b>".get_string("notdefined", "lesson")."</b>";
                             }
                         }
-                        echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("jumpto", "lesson").": ";
+                        echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("jump", "lesson")." $i:";
                         echo "</b></td><td width=\"80%\">\n";
                         echo "$jumptitle</td></tr>\n";
                         $i++;