]> git.mjollnir.org Git - moodle.git/commitdiff
Addition of * wild card to Short Answers.
authorrkingdon <rkingdon>
Wed, 16 Jun 2004 17:18:08 +0000 (17:18 +0000)
committerrkingdon <rkingdon>
Wed, 16 Jun 2004 17:18:08 +0000 (17:18 +0000)
mod/lesson/lesson.php

index 9f9cee9cdb54c7f6c0a24d831a2279086ac732ca..bc392355bfdc2d88584c35d06014cad15560a0e4 100644 (file)
                     error("Continue: No answers found");
                 }
                 foreach ($answers as $answer) {
+                    // massage the wild cards (if present)
+                    if (strpos(' '.$answer->answer, '*')) {
+                        $answer->answer = str_replace('\*','@@@@@@', $answer->answer);
+                        $answer->answer = str_replace('*','.*', $answer->answer);
+                        $answer->answer = str_replace('@@@@@@', '\*', $answer->answer);
+                        $answer->answer = str_replace('+', '\+', $answer->answer);
+                    }
                     if (lesson_iscorrect($pageid, $answer->jumpto)) {
                         if ($page->qoption) {
                             // case sensitive
-                            if ($answer->answer == $useranswer) {
+                            if (ereg('^'.$answer->answer.'$', $useranswer)) {
                                 $correctanswer = true;
                                 $newpageid = $answer->jumpto;
                                 if (trim(strip_tags($answer->response))) {
                             }
                         } else {
                             // case insensitive
-                            if (strcasecmp($answer->answer, $useranswer) == 0) {
+                            if (eregi('^'.$answer->answer.'$', $useranswer)) {
                                 $correctanswer = true;
                                 $newpageid = $answer->jumpto;
                                 if (trim(strip_tags($answer->response))) {
                     } else {
                         // see if user typed in any of the wrong answers
                         // don't worry about case
-                        if (strcasecmp($answer->answer, $useranswer) == 0) {
+                        if (eregi('^'.$answer->answer.'$', $useranswer)) {
                             $newpageid = $answer->jumpto;
                             if (trim(strip_tags($answer->response))) {
                                 $response = $answer->response;
             for ($i = 0; $i < $lesson->maxanswers; $i++) {
                 // strip tags because the editor gives <p><br />...
                 // also save any answers where the editor is (going to be) used
+                if (!isset($form->answereditor[$i])) { // clean up check box
+                    $form->answereditor[$i] = 0;
+                }
+                if (!isset($form->responseeditor[$i])) { // clean up check box
+                    $form->responseeditor[$i] = 0;
+                }
                 if (trim(strip_tags($form->answer[$i])) or $form->answereditor[$i] or $form->responseeditor[$i]) {
                     if ($form->answerid[$i]) {
                         unset($oldanswer);