any page not seen before } if (!defined("LESSON_UNANSWEREDPAGE")) { define("LESSON_UNANSWEREDPAGE", 2); // Next page -> any page not answered correctly } $LESSON_NEXTPAGE_ACTION = array (0 => get_string("normal", "lesson"), LESSON_UNSEENPAGE => get_string("showanunseenpage", "lesson"), LESSON_UNANSWEREDPAGE => get_string("showanunansweredpage", "lesson") ); if (!defined("LESSON_NEXTPAGE")) { define("LESSON_NEXTPAGE", -1); // Next page } if (!defined("LESSON_EOL")) { define("LESSON_EOL", -9); // End of Lesson } /// CDC-FLAG 6/14/04 /// if (!defined("LESSON_UNSEENBRANCHPAGE")) { define("LESSON_UNSEENBRANCHPAGE", -50); // Unseen branch page } if (!defined("LESSON_PREVIOUSPAGE")) { define("LESSON_PREVIOUSPAGE", -40); // previous page } if (!defined("LESSON_RANDOMPAGE")) { define("LESSON_RANDOMPAGE", -60); // random branch page } if (!defined("LESSON_RANDOMBRANCH")) { define("LESSON_RANDOMBRANCH", -70); // random branch } if (!defined("LESSON_CLUSTERJUMP")) { define("LESSON_CLUSTERJUMP", -80); // random within a cluster } /// CDC-FLAG /// if (!defined("LESSON_UNDEFINED")) { define("LESSON_UNDEFINED", -99); // undefined } if (!defined("LESSON_SHORTANSWER")) { define("LESSON_SHORTANSWER", "1"); } if (!defined("LESSON_TRUEFALSE")) { define("LESSON_TRUEFALSE", "2"); } if (!defined("LESSON_MULTICHOICE")) { // if you change the value of this (WHICH YOU SHOULDNT) then you need to change it in restorelib.php as well define("LESSON_MULTICHOICE", "3"); } if (!defined("LESSON_RANDOM")) { define("LESSON_RANDOM", "4"); } if (!defined("LESSON_MATCHING")) { // if you change the value of this (WHICH YOU SHOULDNT) then you need to change it in restorelib.php as well define("LESSON_MATCHING", "5"); } if (!defined("LESSON_RANDOMSAMATCH")) { define("LESSON_RANDOMSAMATCH", "6"); } if (!defined("LESSON_DESCRIPTION")) { define("LESSON_DESCRIPTION", "7"); } if (!defined("LESSON_NUMERICAL")) { define("LESSON_NUMERICAL", "8"); } if (!defined("LESSON_MULTIANSWER")) { define("LESSON_MULTIANSWER", "9"); } /// CDC-FLAG /// 6/16/04 if (!defined("LESSON_ESSAY")) { define("LESSON_ESSAY", "10"); } if (!defined("LESSON_CLUSTER")) { define("LESSON_CLUSTER", "30"); } if (!defined("LESSON_ENDOFCLUSTER")) { define("LESSON_ENDOFCLUSTER", "31"); } /// CDC-FLAG /// $LESSON_QUESTION_TYPE = array ( LESSON_MULTICHOICE => get_string("multichoice", "quiz"), LESSON_TRUEFALSE => get_string("truefalse", "quiz"), LESSON_SHORTANSWER => get_string("shortanswer", "quiz"), LESSON_NUMERICAL => get_string("numerical", "quiz"), LESSON_MATCHING => get_string("match", "quiz"), LESSON_ESSAY => get_string("essay", "lesson") /// CDC-FLAG 6/16/04 // LESSON_DESCRIPTION => get_string("description", "quiz"), // LESSON_RANDOM => get_string("random", "quiz"), // LESSON_RANDOMSAMATCH => get_string("randomsamatch", "quiz"), // 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"); } ////////////////////////////////////////////////////////////////////////////////////// /// Any other lesson functions go here. Each of them must have a name that /// starts with lesson_ /*******************************************************************/ function lesson_save_question_options($question) { /// Given some question info and some data about the the answers /// this function parses, organises and saves the question /// This is only used when IMPORTING questions and is only called /// from format.php /// Lifted from mod/quiz/lib.php - /// 1. all reference to oldanswers removed /// 2. all reference to quiz_multichoice table removed /// 3. In SHORTANSWER questions usecase is store in the qoption field /// 4. In NUMERIC questions store the range as two answers /// 5. TRUEFALSE options are ignored /// 6. For MULTICHOICE questions with more than one answer the qoption field is true /// /// Returns $result->error or $result->notice $timenow = time(); switch ($question->qtype) { case LESSON_SHORTANSWER: $answers = array(); $maxfraction = -1; // Insert all the new answers foreach ($question->answer as $key => $dataanswer) { if ($dataanswer != "") { unset($answer); $answer->lessonid = $question->lessonid; $answer->pageid = $question->id; if ($question->fraction[$key] >=0.5) { $answer->jumpto = LESSON_NEXTPAGE; } $answer->timecreated = $timenow; $answer->grade = $question->fraction[$key] * 100; $answer->answer = $dataanswer; $answer->feedback = $question->feedback[$key]; if (!$answer->id = insert_record("lesson_answers", $answer)) { $result->error = "Could not insert shortanswer quiz answer!"; return $result; } $answers[] = $answer->id; if ($question->fraction[$key] > $maxfraction) { $maxfraction = $question->fraction[$key]; } } } /// Perform sanity checks on fractional grades if ($maxfraction != 1) { $maxfraction = $maxfraction * 100; $result->notice = get_string("fractionsnomax", "quiz", $maxfraction); return $result; } break; case LESSON_NUMERICAL: // Note similarities to SHORTANSWER $answers = array(); $maxfraction = -1; // for each answer store the pair of min and max values even if they are the same foreach ($question->answer as $key => $dataanswer) { if ($dataanswer != "") { unset($answer); $answer->lessonid = $question->lessonid; $answer->pageid = $question->id; $answer->jumpto = LESSON_NEXTPAGE; $answer->timecreated = $timenow; $answer->grade = $question->fraction[$key] * 100; $answer->answer = $question->min[$key].":".$question->max[$key]; $answer->response = $question->feedback[$key]; if (!$answer->id = insert_record("lesson_answers", $answer)) { $result->error = "Could not insert numerical quiz answer!"; return $result; } $answers[] = $answer->id; if ($question->fraction[$key] > $maxfraction) { $maxfraction = $question->fraction[$key]; } } } /// Perform sanity checks on fractional grades if ($maxfraction != 1) { $maxfraction = $maxfraction * 100; $result->notice = get_string("fractionsnomax", "quiz", $maxfraction); return $result; } break; case LESSON_TRUEFALSE: // the truth $answer->lessonid = $question->lessonid; $answer->pageid = $question->id; $answer->timecreated = $timenow; $answer->answer = get_string("true", "quiz"); $answer->grade = $question->answer * 100; if ($answer->grade > 50 ) { $answer->jumpto = LESSON_NEXTPAGE; } if (isset($question->feedbacktrue)) { $answer->response = $question->feedbacktrue; } if (!$true->id = insert_record("lesson_answers", $answer)) { $result->error = "Could not insert quiz answer \"true\")!"; return $result; } // the lie unset($answer); $answer->lessonid = $question->lessonid; $answer->pageid = $question->id; $answer->timecreated = $timenow; $answer->answer = get_string("false", "quiz"); $answer->grade = (1 - (int)$question->answer) * 100; if ($answer->grade > 50 ) { $answer->jumpto = LESSON_NEXTPAGE; } if (isset($question->feedbackfalse)) { $answer->response = $question->feedbackfalse; } if (!$false->id = insert_record("lesson_answers", $answer)) { $result->error = "Could not insert quiz answer \"false\")!"; return $result; } break; case LESSON_MULTICHOICE: $totalfraction = 0; $maxfraction = -1; $answers = array(); // Insert all the new answers foreach ($question->answer as $key => $dataanswer) { if ($dataanswer != "") { unset($answer); $answer->lessonid = $question->lessonid; $answer->pageid = $question->id; $answer->timecreated = $timenow; $answer->grade = $question->fraction[$key] * 100; /// CDC-FLAG changed some defaults /* Original Code if ($answer->grade > 50 ) { $answer->jumpto = LESSON_NEXTPAGE; } Replaced with: */ if ($answer->grade > 50 ) { $answer->jumpto = LESSON_NEXTPAGE; $answer->score = 1; } // end Replace $answer->answer = $dataanswer; $answer->response = $question->feedback[$key]; if (!$answer->id = insert_record("lesson_answers", $answer)) { $result->error = "Could not insert multichoice quiz answer! "; return $result; } // for Sanity checks if ($question->fraction[$key] > 0) { $totalfraction += $question->fraction[$key]; } if ($question->fraction[$key] > $maxfraction) { $maxfraction = $question->fraction[$key]; } } } /// Perform sanity checks on fractional grades if ($question->single) { if ($maxfraction != 1) { $maxfraction = $maxfraction * 100; $result->notice = get_string("fractionsnomax", "quiz", $maxfraction); return $result; } } else { $totalfraction = round($totalfraction,2); if ($totalfraction != 1) { $totalfraction = $totalfraction * 100; $result->notice = get_string("fractionsaddwrong", "quiz", $totalfraction); return $result; } } break; case LESSON_MATCHING: $subquestions = array(); $i = 0; // Insert all the new question+answer pairs foreach ($question->subquestions as $key => $questiontext) { $answertext = $question->subanswers[$key]; echo $answertext; echo "
"; exit; if (!empty($questiontext) and !empty($answertext)) { unset($answer); $answer->lessonid = $question->lessonid; $answer->pageid = $question->id; $answer->timecreated = $timenow; $answer->answer = $questiontext; $answer->response = $answertext; if ($i == 0) { // first answer contains the correct answer jump $answer->jumpto = LESSON_NEXTPAGE; } if (!$subquestion->id = insert_record("lesson_answers", $answer)) { $result->error = "Could not insert quiz match subquestion!"; return $result; } $subquestions[] = $subquestion->id; $i++; } } if (count($subquestions) < 3) { $result->notice = get_string("notenoughsubquestions", "quiz"); return $result; } break; case LESSON_RANDOMSAMATCH: $options->question = $question->id; $options->choose = $question->choose; if ($existing = get_record("quiz_randomsamatch", "question", $options->question)) { $options->id = $existing->id; if (!update_record("quiz_randomsamatch", $options)) { $result->error = "Could not update quiz randomsamatch options!"; return $result; } } else { if (!insert_record("quiz_randomsamatch", $options)) { $result->error = "Could not insert quiz randomsamatch options!"; return $result; } } break; case LESSON_MULTIANSWER: if (!$oldmultianswers = get_records("quiz_multianswers", "question", $question->id, "id ASC")) { $oldmultianswers = array(); } // Insert all the new multi answers foreach ($question->answers as $dataanswer) { if ($oldmultianswer = array_shift($oldmultianswers)) { // Existing answer, so reuse it $multianswer = $oldmultianswer; $multianswer->positionkey = $dataanswer->positionkey; $multianswer->norm = $dataanswer->norm; $multianswer->answertype = $dataanswer->answertype; if (! $multianswer->answers = quiz_save_multianswer_alternatives ($question->id, $dataanswer->answertype, $dataanswer->alternatives, $oldmultianswer->answers)) { $result->error = "Could not update multianswer alternatives! (id=$multianswer->id)"; return $result; } if (!update_record("quiz_multianswers", $multianswer)) { $result->error = "Could not update quiz multianswer! (id=$multianswer->id)"; return $result; } } else { // This is a completely new answer unset($multianswer); $multianswer->question = $question->id; $multianswer->positionkey = $dataanswer->positionkey; $multianswer->norm = $dataanswer->norm; $multianswer->answertype = $dataanswer->answertype; if (! $multianswer->answers = quiz_save_multianswer_alternatives ($question->id, $dataanswer->answertype, $dataanswer->alternatives)) { $result->error = "Could not insert multianswer alternatives! (questionid=$question->id)"; return $result; } if (!insert_record("quiz_multianswers", $multianswer)) { $result->error = "Could not insert quiz multianswer!"; return $result; } } } break; case LESSON_RANDOM: break; case LESSON_DESCRIPTION: break; default: $result->error = "Unsupported question type ($question->qtype)!"; return $result; break; } return true; } /*******************************************************************/ 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 /// $options["value"]["label"] if ($nothing == "choose") { $nothing = get_string("choose")."..."; } if ($script) { $javascript = "onChange=\"$script\""; } else { $javascript = ""; } $output = " \n"; } else { $output .= "$label"; } if ($label != end($qtypes)) { $output .= " | "; } } echo $output; } /*******************************************************************/ function lesson_check_nickname($name) { // used to check high score nicknames. // checks nickname agains a list of "bad words" in filter.php if ($name == NULL) { return false; } require_once('filter.php'); foreach ($filterwords as $filterword) { if (strstr($name, $filterword)) { return false; } } return true; } /// CDC-FLAG /// ?>