From: julmis Date: Wed, 2 Jun 2004 18:03:05 +0000 (+0000) Subject: QuizTimer modifications added plus necessary files along. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=f41e824f33414e6184611a6d1708cd3a58ec9058;p=moodle.git QuizTimer modifications added plus necessary files along. --- diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index 5046524dab..b16adfeac6 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -74,6 +74,25 @@ error("Sorry, you've had $quiz->attempts attempts already.", "view.php?id=$cm->id"); } +/// BEGIN EDIT Get time limit if any. + + $timelimit = $quiz->timelimit * 60; + + if($timelimit > 0) { + $unattempt = quiz_get_user_attempt_unfinished($quiz->id, $USER->id); + $timestart = $unattempt->timestart; + if($timestart) { + $timesincestart = time() - $timestart; + $timerstartvalue = $timelimit - $timesincestart; + } else { + $timerstartvalue = $timelimit; + } + } + + if($timelimit and $timerstartvalue <= 0) { + $timerstartvalue = 1; + } +/// END EDIT $timenow = time(); $available = ($quiz->timeopen < $timenow and $timenow < $quiz->timeclose); @@ -85,7 +104,7 @@ $shuffleorder = NULL; unset($rawanswers["q"]); // quiz id - if (! count($rawanswers)) { + if (! count($rawanswers) and ! $timelimit) { print_heading(get_string("noanswers", "quiz")); print_continue("attempt.php?q=$quiz->id"); exit; @@ -246,7 +265,13 @@ print_continue("view.php?id=$cm->id"); } +/// BEGIN EDIT if quiz is available and time limit is set +/// include floating timer. + if($available and $timelimit > 0) { + require('jstimer.php'); + } +/// END EDIT /// Finish the page print_footer($course); diff --git a/mod/quiz/db/mysql.php b/mod/quiz/db/mysql.php index 41003a0b32..380f97b8ca 100644 --- a/mod/quiz/db/mysql.php +++ b/mod/quiz/db/mysql.php @@ -54,7 +54,7 @@ function quiz_upgrade($oldversion) { table_column("quiz_questions", "", "defaultgrade", "INTEGER", "6", "UNSIGNED", "1", "NOT NULL", "image"); } - if ($oldversion < 2003032601) { + if ($oldversion < 2003032601) { execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_answers` ADD INDEX(question) "); execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_attempts` ADD INDEX(quiz) "); execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_attempts` ADD INDEX(userid) "); @@ -67,7 +67,7 @@ function quiz_upgrade($oldversion) { execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_responses` ADD INDEX(question) "); } - if ($oldversion < 2003033100) { + if ($oldversion < 2003033100) { modify_database ("", "ALTER TABLE prefix_quiz_randommatch RENAME prefix_quiz_randomsamatch "); modify_database ("", "CREATE TABLE `prefix_quiz_match` ( `id` int(10) unsigned NOT NULL auto_increment, @@ -175,7 +175,7 @@ function quiz_upgrade($oldversion) { set_field("quiz_questions","stamp",$duplicate->id.$add,"id",$question->id); $add++; } - } + } } else { notify("Checked your quiz questions for stamp duplication errors, but no problems were found.", "green"); } @@ -195,6 +195,10 @@ function quiz_upgrade($oldversion) { quiz_refresh_events(); } + if ($oldversion < 2004060200) { + execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD timelimit INT(2) UNSIGNED DEFAULT '0' NOT NULL "); + } + return true; } diff --git a/mod/quiz/db/mysql.sql b/mod/quiz/db/mysql.sql index bbda452dad..14475cc455 100644 --- a/mod/quiz/db/mysql.sql +++ b/mod/quiz/db/mysql.sql @@ -33,6 +33,7 @@ CREATE TABLE `prefix_quiz` ( `grade` int(10) NOT NULL default '0', `timecreated` int(10) unsigned NOT NULL default '0', `timemodified` int(10) unsigned NOT NULL default '0', + `timelimit` int(2) unsigned NOT NULL default '0', PRIMARY KEY (`id`) ) TYPE=MyISAM COMMENT='Main information about each quiz'; # -------------------------------------------------------- diff --git a/mod/quiz/db/postgres7.php b/mod/quiz/db/postgres7.php index fae9afd505..c9a179c720 100644 --- a/mod/quiz/db/postgres7.php +++ b/mod/quiz/db/postgres7.php @@ -27,7 +27,7 @@ function quiz_upgrade($oldversion) { table_column("quiz_questions", "", "defaultgrade", "INTEGER", "6", "UNSIGNED", "1", "NOT NULL", "image"); } - if ($oldversion < 2003033100) { + if ($oldversion < 2003033100) { modify_database ("", "ALTER TABLE prefix_quiz_randommatch RENAME prefix_quiz_randomsamatch "); modify_database ("", "CREATE TABLE prefix_quiz_match_sub ( id SERIAL PRIMARY KEY, @@ -70,7 +70,7 @@ function quiz_upgrade($oldversion) { modify_database ("", "CREATE INDEX prefix_quiz_numerical_answer_idx ON prefix_quiz_numerical (answer);"); } - if ($oldversion < 2003072400) { + if ($oldversion < 2003072400) { execute_sql(" INSERT INTO {$CFG->prefix}log_display VALUES ('quiz', 'review', 'quiz', 'name') "); } @@ -130,7 +130,7 @@ function quiz_upgrade($oldversion) { set_field("quiz_questions","stamp",$duplicate->id.$add,"id",$question->id); $add++; } - } + } } else { notify("Checked your quiz questions for stamp duplication errors, but no problems were found.", "green"); } @@ -149,6 +149,9 @@ function quiz_upgrade($oldversion) { include_once("$CFG->dirroot/mod/quiz/lib.php"); quiz_refresh_events(); } + if ($oldversion < 2004060200) { + execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD timelimit integer DEFAULT '0' NOT NULL "); + } return true; } diff --git a/mod/quiz/db/postgres7.sql b/mod/quiz/db/postgres7.sql index 77143c3109..1c60d050e7 100644 --- a/mod/quiz/db/postgres7.sql +++ b/mod/quiz/db/postgres7.sql @@ -32,7 +32,8 @@ CREATE TABLE prefix_quiz ( sumgrades integer NOT NULL default '0', grade integer NOT NULL default '0', timecreated integer NOT NULL default '0', - timemodified integer NOT NULL default '0' + timemodified integer NOT NULL default '0', + timelimit integer NOT NULL default '0' ); # -------------------------------------------------------- diff --git a/mod/quiz/jstimer.php b/mod/quiz/jstimer.php new file mode 100644 index 0000000000..21f1079193 --- /dev/null +++ b/mod/quiz/jstimer.php @@ -0,0 +1,54 @@ + + + +
+ + + + + +
+ + + + + + + +
+
+
+
+
+ +
+ + diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index c35c7816cd..691f5f8f14 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -45,9 +45,9 @@ define("QUIZ_MAX_EVENT_LENGTH", "432000"); // 5 days maximum /// FUNCTIONS /////////////////////////////////////////////////////////////////// function quiz_add_instance($quiz) { -/// Given an object containing all the necessary data, -/// (defined by the form in mod.html) this function -/// will create a new instance and return the id number +/// Given an object containing all the necessary data, +/// (defined by the form in mod.html) this function +/// will create a new instance and return the id number /// of the new instance. global $SESSION; @@ -56,9 +56,9 @@ function quiz_add_instance($quiz) { $quiz->created = time(); $quiz->timemodified = time(); - $quiz->timeopen = make_timestamp($quiz->openyear, $quiz->openmonth, $quiz->openday, + $quiz->timeopen = make_timestamp($quiz->openyear, $quiz->openmonth, $quiz->openday, $quiz->openhour, $quiz->openminute, 0); - $quiz->timeclose = make_timestamp($quiz->closeyear, $quiz->closemonth, $quiz->closeday, + $quiz->timeclose = make_timestamp($quiz->closeyear, $quiz->closemonth, $quiz->closeday, $quiz->closehour, $quiz->closeminute, 0); if (!$quiz->id = insert_record("quiz", $quiz)) { @@ -116,8 +116,8 @@ function quiz_add_instance($quiz) { function quiz_update_instance($quiz) { -/// Given an object containing all the necessary data, -/// (defined by the form in mod.html) this function +/// Given an object containing all the necessary data, +/// (defined by the form in mod.html) this function /// will update an existing instance with new data. global $SESSION; @@ -125,9 +125,9 @@ function quiz_update_instance($quiz) { unset($SESSION->modform); $quiz->timemodified = time(); - $quiz->timeopen = make_timestamp($quiz->openyear, $quiz->openmonth, $quiz->openday, + $quiz->timeopen = make_timestamp($quiz->openyear, $quiz->openmonth, $quiz->openday, $quiz->openhour, $quiz->openminute, 0); - $quiz->timeclose = make_timestamp($quiz->closeyear, $quiz->closemonth, $quiz->closeday, + $quiz->timeclose = make_timestamp($quiz->closeyear, $quiz->closemonth, $quiz->closeday, $quiz->closehour, $quiz->closeminute, 0); $quiz->id = $quiz->instance; @@ -200,9 +200,9 @@ function quiz_update_instance($quiz) { function quiz_delete_instance($id) { -/// Given an ID of an instance of this module, -/// this function will permanently delete the instance -/// and any data that depends on it. +/// Given an ID of an instance of this module, +/// this function will permanently delete the instance +/// and any data that depends on it. if (! $quiz = get_record("quiz", "id", "$id")) { return false; @@ -271,13 +271,13 @@ function quiz_delete_course($course) { function quiz_user_outline($course, $user, $mod, $quiz) { -/// Return a small object with summary information about what a +/// Return a small object with summary information about what a /// user has done with a given particular instance of this module /// Used for user activity reports. /// $return->time = the time they did it /// $return->info = a short text description if ($grade = get_record("quiz_grades", "userid", $user->id, "quiz", $quiz->id)) { - + if ($grade->grade) { $result->info = get_string("grade").": $grade->grade"; } @@ -290,7 +290,7 @@ function quiz_user_outline($course, $user, $mod, $quiz) { } function quiz_user_complete($course, $user, $mod, $quiz) { -/// Print a detailed representation of what a user has done with +/// Print a detailed representation of what a user has done with /// a given particular instance of this module, for user activity reports. return true; @@ -298,8 +298,8 @@ function quiz_user_complete($course, $user, $mod, $quiz) { function quiz_cron () { /// Function to be run periodically according to the moodle cron -/// This function searches for things that need to be done, such -/// as sending out mail, toggling flags etc ... +/// This function searches for things that need to be done, such +/// as sending out mail, toggling flags etc ... global $CFG; @@ -328,7 +328,7 @@ function quiz_get_participants($quizid) { return get_records_sql("SELECT DISTINCT u.* FROM {$CFG->prefix}user u, {$CFG->prefix}quiz_attempts a - WHERE a.quiz = '$quizid' and + WHERE a.quiz = '$quizid' and u.id = a.userid"); } @@ -349,7 +349,7 @@ function quiz_refresh_events($courseid = 0) { } } $moduleid = get_field('modules', 'id', 'name', 'quiz'); - + foreach ($quizzes as $quiz) { $event = NULL; $event2 = NULL; @@ -416,32 +416,32 @@ function quiz_refresh_events($courseid = 0) { function quiz_move_questions($category1, $category2) { global $CFG; - return execute_sql("UPDATE {$CFG->prefix}quiz_questions - SET category = '$category2' - WHERE category = '$category1'", + return execute_sql("UPDATE {$CFG->prefix}quiz_questions + SET category = '$category2' + WHERE category = '$category1'", false); } function quiz_get_question_grades($quizid, $questionlist) { global $CFG; - return get_records_sql("SELECT question,grade - FROM {$CFG->prefix}quiz_question_grades - WHERE quiz = '$quizid' + return get_records_sql("SELECT question,grade + FROM {$CFG->prefix}quiz_question_grades + WHERE quiz = '$quizid' AND question IN ($questionlist)"); } function quiz_get_random_categories($questionlist) { /// Given an array of questions, this function looks for random -/// questions among them and returns a list of categories with +/// questions among them and returns a list of categories with /// an associated count of random questions for each. global $CFG; - return get_records_sql_menu("SELECT category,count(*) - FROM {$CFG->prefix}quiz_questions - WHERE id IN ($questionlist) - AND qtype = '".RANDOM."' + return get_records_sql_menu("SELECT category,count(*) + FROM {$CFG->prefix}quiz_questions + WHERE id IN ($questionlist) + AND qtype = '".RANDOM."' GROUP BY category "); } @@ -450,8 +450,8 @@ function quiz_get_grade_records($quiz) { /// for report.php global $CFG; - return get_records_sql("SELECT qg.*, u.firstname, u.lastname, u.picture - FROM {$CFG->prefix}quiz_grades qg, + return get_records_sql("SELECT qg.*, u.firstname, u.lastname, u.picture + FROM {$CFG->prefix}quiz_grades qg, {$CFG->prefix}user u WHERE qg.quiz = '$quiz->id' AND qg.userid = u.id"); @@ -470,9 +470,9 @@ function quiz_get_answers($question, $answerids=NULL) { switch ($question->qtype) { case SHORTANSWER: // Could be multiple answers return get_records_sql("SELECT a.*, sa.usecase - FROM {$CFG->prefix}quiz_shortanswer sa, + FROM {$CFG->prefix}quiz_shortanswer sa, {$CFG->prefix}quiz_answers a - WHERE sa.question = '$question->id' + WHERE sa.question = '$question->id' AND sa.question = a.question " . $answeridconstraint); @@ -481,9 +481,9 @@ function quiz_get_answers($question, $answerids=NULL) { case MULTICHOICE: // Should be multiple answers return get_records_sql("SELECT a.*, mc.single - FROM {$CFG->prefix}quiz_multichoice mc, + FROM {$CFG->prefix}quiz_multichoice mc, {$CFG->prefix}quiz_answers a - WHERE mc.question = '$question->id' + WHERE mc.question = '$question->id' AND mc.question = a.question " . $answeridconstraint); @@ -492,9 +492,9 @@ function quiz_get_answers($question, $answerids=NULL) { case RANDOMSAMATCH: // Could be any of many answers, return them all return get_records_sql("SELECT a.* - FROM {$CFG->prefix}quiz_questions q, + FROM {$CFG->prefix}quiz_questions q, {$CFG->prefix}quiz_answers a - WHERE q.category = '$question->category' + WHERE q.category = '$question->category' AND q.qtype = ".SHORTANSWER." AND q.id = a.question "); @@ -515,7 +515,7 @@ function quiz_get_answers($question, $answerids=NULL) { case MULTIANSWER: // Includes subanswers $answers = array(); - + $virtualquestion->id = $question->id; if ($multianswers = get_records('quiz_multianswers', 'question', $question->id)) { @@ -535,16 +535,16 @@ function quiz_get_answers($question, $answerids=NULL) { function quiz_get_attempt_responses($attempt) { -// Given an attempt object, this function gets all the +// Given an attempt object, this function gets all the // stored responses and returns them in a format suitable // for regrading using quiz_grade_attempt_results() global $CFG; - - if (!$responses = get_records_sql("SELECT q.id, q.qtype, q.category, q.questiontext, - q.defaultgrade, q.image, r.answer - FROM {$CFG->prefix}quiz_responses r, + + if (!$responses = get_records_sql("SELECT q.id, q.qtype, q.category, q.questiontext, + q.defaultgrade, q.image, r.answer + FROM {$CFG->prefix}quiz_responses r, {$CFG->prefix}quiz_questions q - WHERE r.attempt = '$attempt->id' + WHERE r.attempt = '$attempt->id' AND q.id = r.question")) { notify("Could not find any responses for that attempt!"); return false; @@ -585,7 +585,7 @@ function get_list_of_questions($questionlist) { global $CFG; - return get_records_sql("SELECT q.*,c.course + return get_records_sql("SELECT q.*,c.course FROM {$CFG->prefix}quiz_questions q, {$CFG->prefix}quiz_categories c WHERE q.id in ($questionlist) @@ -593,7 +593,7 @@ function get_list_of_questions($questionlist) { } ////////////////////////////////////////////////////////////////////////////////////// -/// Any other quiz functions go here. Each of them must have a name that +/// Any other quiz functions go here. Each of them must have a name that /// starts with quiz_ function quiz_print_comment($text) { @@ -672,7 +672,7 @@ function quiz_print_possible_question_image($quizid, $question) { } } -function quiz_print_question($number, $question, $grade, $quizid, +function quiz_print_question($number, $question, $grade, $quizid, $feedback=NULL, $response=NULL, $actualgrade=NULL, $correct=NULL, $realquestion=NULL, $shuffleanswers=false, $showgrades=true, $courseid=0) { @@ -709,7 +709,7 @@ function quiz_print_question($number, $question, $grade, $quizid, } } print_spacer(1,100); - + if (isset($question->recentlyadded) and $question->recentlyadded) { echo ''; // Notify the user of this recently added question @@ -723,7 +723,7 @@ function quiz_print_question($number, $question, $grade, $quizid, } - if (empty($realquestion)) { + if (empty($realquestion)) { $realquestion->id = $question->id; } else { // Add a marker to connect this question to the actual random parent echo "id}rq$question->id\" value=\"x\" />\n"; @@ -731,7 +731,7 @@ function quiz_print_question($number, $question, $grade, $quizid, switch ($question->qtype) { - case SHORTANSWER: + case SHORTANSWER: case NUMERICAL: echo format_text($question->questiontext, $question->questiontextformat, NULL, $courseid); quiz_print_possible_question_image($quizid, $question); @@ -854,7 +854,7 @@ function quiz_print_question($number, $question, $grade, $quizid, echo ""; break; - case MATCH: + case MATCH: if (!$options = get_record("quiz_match", "question", $question->id)) { notify("Error: Missing question options!"); } @@ -907,7 +907,7 @@ function quiz_print_question($number, $question, $grade, $quizid, break; - case RANDOMSAMATCH: + case RANDOMSAMATCH: if (!$options = get_record("quiz_randomsamatch", "question", $question->id)) { notify("Error: Missing question options!"); } @@ -916,7 +916,7 @@ function quiz_print_question($number, $question, $grade, $quizid, /// First, get all the questions available - $allquestions = get_records_select("quiz_questions", + $allquestions = get_records_select("quiz_questions", "category = $question->category AND qtype = ".SHORTANSWER); if (count($allquestions) < $options->choose) { notify("Error: could not find enough Short Answer questions in the database!"); @@ -937,7 +937,7 @@ function quiz_print_question($number, $question, $grade, $quizid, $responseanswer[$key] = $rrr[1]; } } - + /// For each selected, find the best matching answers foreach ($randomquestions as $randomquestion) { @@ -999,7 +999,7 @@ function quiz_print_question($number, $question, $grade, $quizid, $qtextremaining = format_text($question->questiontext, $question->questiontextformat, NULL, $courseid); - // The regex will recognize text snippets of type {#X} + // The regex will recognize text snippets of type {#X} // where the X can be any text not containg } or white-space characters. $strfeedback = get_string('feedback', 'quiz'); @@ -1024,7 +1024,7 @@ function quiz_print_question($number, $question, $grade, $quizid, } else if ('' != $actualresponse) { // The response must have been totally wrong: $style = 'style="background-color:red"'; - } else { + } else { // There was no response given $style = ''; } @@ -1050,7 +1050,7 @@ function quiz_print_question($number, $question, $grade, $quizid, case MULTICHOICE: $outputoptions = ''; $answers = get_records_list("quiz_answers", "id", $multianswer->answers); - $outputoptions .= ''; // Default empty option + $outputoptions .= ''; // Default empty option foreach ($answers as $answer) { if ($answer->id == $actualresponse) { $selected = 'selected'; @@ -1087,7 +1087,7 @@ function quiz_print_question($number, $question, $grade, $quizid, echo '

' . get_string('random', 'quiz') . '

'; break; - default: + default: notify("Error: Unknown question type!"); } @@ -1143,7 +1143,7 @@ function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL, $shuff } - /// Examine the set of questions for random questions, and retrieve them + /// Examine the set of questions for random questions, and retrieve them if (empty($results)) { // Choose some new random questions if ($randomcats = quiz_get_random_categories($quiz->questions)) { @@ -1178,8 +1178,22 @@ function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL, $shuff } else { $onsubmit = "onsubmit=\"return confirm('$strconfirmattempt');\""; } - + // BEGIN EDIT + if($quiz->timelimit > 0) { + ?> + + + \n"; + } + // END EDIT echo "id\" />\n"; $count = 0; @@ -1228,8 +1242,8 @@ function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL, $shuff } print_simple_box_start("center", "90%"); - quiz_print_question($count, $question, $grades[$question->id]->grade, $quiz->id, - $feedback, $response, $actualgrades, $correct, + quiz_print_question($count, $question, $grades[$question->id]->grade, $quiz->id, + $feedback, $response, $actualgrades, $correct, $randomquestion, $quiz->shuffleanswers, $quiz->grade, $quiz->course); print_simple_box_end(); echo "
"; @@ -1250,7 +1264,7 @@ function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL, $shuff } - + function quiz_get_default_category($courseid) { /// Returns the current category @@ -1310,7 +1324,7 @@ function quiz_print_category_form($course, $current) { echo ""; popup_form ("edit.php?cat=", $catmenu, "catmenu", $current, "choose", "", "", false, "self"); echo ""; - echo "
"; + echo ""; echo "id\" />"; echo ""; echo "
"; @@ -1323,10 +1337,10 @@ function quiz_choose_random_questions($category, $draws, $excluded=0) { /// Given a question category and a number of draws, this function /// creates a random subset of that size - returned as an array of questions - if (!$pool = get_records_select_menu("quiz_questions", - "category = '$category' AND id NOT IN ($excluded) - AND qtype <> ".RANDOM." - AND qtype <> ".DESCRIPTION, + if (!$pool = get_records_select_menu("quiz_questions", + "category = '$category' AND id NOT IN ($excluded) + AND qtype <> ".RANDOM." + AND qtype <> ".DESCRIPTION, "", "id,qtype")) { return false; } @@ -1347,7 +1361,7 @@ function quiz_choose_random_questions($category, $draws, $excluded=0) { function quiz_get_all_question_grades($questionlist, $quizid) { -// Given a list of question IDs, finds grades or invents them to +// Given a list of question IDs, finds grades or invents them to // create an array of matching grades if (empty($questionlist)) { @@ -1441,13 +1455,13 @@ function quiz_print_question_list($questionlist, $grades) { echo "$count"; echo ""; if ($count != 1) { - echo ""; } echo ""; echo ""; if ($count != $total) { - echo ""; } echo ""; @@ -1463,10 +1477,10 @@ function quiz_print_question_list($questionlist, $grades) { "q$qnum", (string)$grades[$qnum], ""); } echo ""; - echo " "; if ($canedit) { - echo "\n"; } echo ""; @@ -1528,14 +1542,14 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true) { echo ''; echo ""; echo ''; echo ''; echo '\n"; if ($canedit) { echo "\n";// deleted jm } @@ -1612,7 +1626,7 @@ function quiz_start_attempt($quizid, $userid, $numattempt) { $attempt->userid = $userid; $attempt->attempt = $numattempt; $attempt->timestart = time(); - $attempt->timefinish = 0; + $attempt->timefinish = 0; $attempt->timemodified = time(); return insert_record("quiz_attempts", $attempt); @@ -1625,13 +1639,13 @@ function quiz_get_user_attempt_unfinished($quizid, $userid) { function quiz_get_user_attempts($quizid, $userid) { // Returns a list of all attempts by a user - return get_records_select("quiz_attempts", "quiz = '$quizid' AND userid = '$userid' AND timefinish > 0", + return get_records_select("quiz_attempts", "quiz = '$quizid' AND userid = '$userid' AND timefinish > 0", "attempt ASC"); } function quiz_get_user_attempts_string($quiz, $attempts, $bestgrade) { -/// Returns a simple little comma-separated list of all attempts, +/// Returns a simple little comma-separated list of all attempts, /// with each grade linked to the feedback report and with the best grade highlighted $bestgrade = format_float($bestgrade); @@ -1760,7 +1774,7 @@ function quiz_calculate_best_attempt($quiz, $attempts) { function quiz_save_attempt($quiz, $questions, $result, $attemptnum) { -/// Given a quiz, a list of attempted questions and a total grade +/// Given a quiz, a list of attempted questions and a total grade /// this function saves EVERYTHING so it can be reconstructed later /// if necessary. @@ -1888,7 +1902,7 @@ function quiz_grade_attempt_question_result($question, && (float)$answer->fraction > (float)$grade // Do we need to bother? and // and has lower procedence than && and ||. strtolower($question->answer) == strtolower($answer->answer) - || '' != trim($answer->min) + || '' != trim($answer->min) && ((float)$question->answer >= (float)$answer->min) && ((float)$question->answer <= (float)$answer->max)) { @@ -1948,9 +1962,9 @@ function quiz_grade_attempt_question_result($question, $qarr = explode('-', $questionanswer); // Extract subquestion/answer. $subquestionid = $qarr[0]; $subanswerid = $qarr[1]; - if ($subquestionid and $subanswerid and (($subquestionid == $subanswerid) or - ($answers[$subquestionid]->answertext == $answers[$subanswerid]->answertext))) { - // Either the ids match exactly, or the answertexts match exactly + if ($subquestionid and $subanswerid and (($subquestionid == $subanswerid) or + ($answers[$subquestionid]->answertext == $answers[$subanswerid]->answertext))) { + // Either the ids match exactly, or the answertexts match exactly // (in case two subquestions had the same answer) $matchcount++; $correct[$subquestionid] = true; @@ -1983,7 +1997,7 @@ function quiz_grade_attempt_question_result($question, $ranswer = $rqarr[1]; $response[$rquestion] = $questionanswer; if (isset($answers[$ranswer])) { // If the answer exists in the list - $answer = $answers[$ranswer]; + $answer = $answers[$ranswer]; $feedback[$rquestion] = $answer->feedback; if ($answer->question == $rquestion) { // Check that this answer matches the question $grade += (float)$answer->fraction * $question->grade * $answerfraction; @@ -1997,7 +2011,7 @@ function quiz_grade_attempt_question_result($question, $subquestion->grade = 1.0; foreach ($question->answer as $questionanswer) { - + // Resetting default values for subresult: $subresult->grade = 0.0; $subresult->correct = array(); @@ -2054,9 +2068,9 @@ function quiz_grade_attempt_question_result($question, function quiz_grade_attempt_results($quiz, $questions) { /// Given a list of questions (including answers for each one) -/// this function does all the hard work of calculating the -/// grades for each question, as well as a total grade for -/// for the whole quiz. It returns everything in a structure +/// this function does all the hard work of calculating the +/// grades for each question, as well as a total grade for +/// for the whole quiz. It returns everything in a structure /// that looks like: /// $result->sumgrades (sum of all grades for all questions) /// $result->percentage (Percentage of grades that were correct) @@ -2079,7 +2093,7 @@ function quiz_grade_attempt_results($quiz, $questions) { foreach ($questions as $question) { $question->grade = $grades[$question->id]; - + if (!$answers = quiz_get_answers($question)) { error("No answers defined for question id $question->id!"); } @@ -2106,18 +2120,18 @@ function quiz_grade_attempt_results($quiz, $questions) { function quiz_save_question_options($question) { /// Given some question info and some data about the the answers /// this function parses, organises and saves the question -/// It is used by question.php when saving new data from a +/// It is used by question.php when saving new data from a /// form, and also by import.php when importing questions -/// +/// /// If this is an update, and old answers already exist, then -/// these are overwritten using an update(). To do this, it +/// these are overwritten using an update(). To do this, it /// it is assumed that the IDs in quiz_answers are in the same /// sort order as the new answers being saved. This should always /// be true, but it's something to keep in mind if fiddling with /// question.php /// /// Returns $result->error or $result->noticeyesno or $result->notice - + switch ($question->qtype) { case SHORTANSWER: @@ -2324,7 +2338,7 @@ function quiz_save_question_options($question) { if (!$oldanswers = get_records("quiz_answers", "question", $question->id, "id ASC")) { $oldanswers = array(); } - + // following hack to check at least two answers exist $answercount = 0; @@ -2338,8 +2352,8 @@ function quiz_save_question_options($question) { $result->notice = get_string("notenoughanswers", "quiz", "2"); return $result; } - - + + // Insert all the new answers @@ -2437,7 +2451,7 @@ function quiz_save_question_options($question) { } - + $subquestions = array(); // Insert all the new question+answer pairs @@ -2653,7 +2667,7 @@ function quiz_save_multianswer_alternatives // Removal of obsolete alternatives from answers and quiz_numerical: while ($altobsolete = array_shift($oldalternatives)) { delete_records("quiz_answers", "id", $altobsolete->id); - + // Possibly obsolute numerical options are also to be deleted: delete_records("quiz_numerical", 'answer', $altobsolete->id); } @@ -2662,15 +2676,15 @@ function quiz_save_multianswer_alternatives switch ($answertype) { case NUMERICAL: if (!empty($oldalternativeids)) { - delete_records('quiz_shortanswer', 'answers', + delete_records('quiz_shortanswer', 'answers', $oldalternativeids); - delete_records('quiz_multichoice', 'answers', + delete_records('quiz_multichoice', 'answers', $oldalternativeids); } break; case SHORTANSWER: if (!empty($oldalternativeids)) { - delete_records('quiz_multichoice', 'answers', + delete_records('quiz_multichoice', 'answers', $oldalternativeids); $options = get_record('quiz_shortanswer', 'answers', $oldalternativeids); @@ -2695,7 +2709,7 @@ $oldalternativeids); break; case MULTICHOICE: if (!empty($oldalternativeids)) { - delete_records('quiz_shortanswer', 'answers', + delete_records('quiz_shortanswer', 'answers', $oldalternativeids); $options = get_record('quiz_multichoice', 'answers', $oldalternativeids); @@ -2722,7 +2736,7 @@ $oldalternativeids); default: return false; } - return $answers; + return $answers; } function quiz_get_recent_mod_activity(&$activities, &$index, $sincetime, $courseid, $quiz="0", $user="", $groupid="") { diff --git a/mod/quiz/mod.html b/mod/quiz/mod.html index 0f5df5bcc4..aa6d6a144a 100644 --- a/mod/quiz/mod.html +++ b/mod/quiz/mod.html @@ -94,6 +94,19 @@ ?> + + + + + +
$strcreatenewquestion:'; - popup_form ("question.php?category=$category->id&qtype=", $QUIZ_QUESTION_TYPE, "addquestion", + popup_form ("question.php?category=$category->id&qtype=", $QUIZ_QUESTION_TYPE, "addquestion", "", "choose", "", "", false, "self"); echo ''; helpbutton("questiontypes", $strcreatenewquestion, "quiz"); echo '
'; - echo '
'; + echo ''; echo "id\" />"; echo ""; helpbutton("import", $strimportquestions, "quiz"); @@ -1543,7 +1557,7 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true) { echo '
'; - echo ''; + echo ''; echo "id\" />"; echo ""; helpbutton("createmultiple", $strcreatemultiple, "quiz"); @@ -1587,9 +1601,9 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true) { echo "\n"; - echo "id&delete=$question->id\">\nid&delete=$question->id\">\n "; - echo "id\">id\">"; echo "

:

+ timelimit); + echo " "; + print_string("minutes","quiz"); + helpbutton("timelimit", get_string("quiztimer","quiz"), "quiz"); + ?> +

:

diff --git a/mod/quiz/timer.js b/mod/quiz/timer.js new file mode 100644 index 0000000000..91774a7e33 --- /dev/null +++ b/mod/quiz/timer.js @@ -0,0 +1,75 @@ +// $Id$ +// +// QuizTimer +// Provides a counter that keeps track how much +// time user have left to check in started quiz. +// +function countdown_clock() { + var timeout_id = null; + quizTimerValue = quizTimerValue - 1; + + if(quizTimerValue == 0) { + clearTimeout(timeout_id); + //alert(timesup); + document.forms[0].submit(); + } + + now = quizTimerValue; + var hours = Math.floor( now / 3600 ); + now = now - (hours * 3600); + var minutes = Math.floor(now / 60); + now = now - (minutes * 60); + var seconds = now; + + var t = "" + hours; + t += ((minutes < 10) ? ":0" : ":") + minutes; + t += ((seconds < 10) ? ":0" : ":") + seconds; + window.status = t; + + if(hours == 0 && minutes == 0 && seconds <= 15) { + //go from fff0f0 to ffe0e0 to ffd0d0...ff2020, ff1010, ff0000 in 15 steps + var hexascii = "0123456789ABCDEF"; + var col = 'ff' + hexascii.charAt(seconds) + '0' + hexascii.charAt(seconds) + 0; + changecolor(col); + } + document.forms['clock'].time.value = t; + timeout_id = setTimeout("countdown_clock()", 1000); +} + +function movecounter() { + + var pos; + + if (window.innerHeight) { + pos = window.pageYOffset + } else if (document.documentElement && document.documentElement.scrollTop) { + pos = document.documentElement.scrollTop + } else if (document.body) { + pos = document.body.scrollTop + } + + if (pos < theTop) { + pos = theTop; + } else { + pos += 100; + } + if (pos == old) { + this.style.top = pos; + } + old = pos; + temp = setTimeout('movecounter()',100); +} + +function getObjectById (name) { + + if (document.getElementById) { + this.obj = document.getElementById(name); + this.style = document.getElementById(name).style; + } else if (document.all) { + this.obj = document.all[name]; + this.style = document.all[name].style; + } else if (document.layers) { + this.obj = document.layers[name]; + this.style = document.layers[name]; + } +} diff --git a/mod/quiz/version.php b/mod/quiz/version.php index 85a13d3074..a9ac318ff4 100644 --- a/mod/quiz/version.php +++ b/mod/quiz/version.php @@ -5,7 +5,7 @@ // This fragment is called by moodle_needs_upgrading() and /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2004051700; // The (date) version of this module +$module->version = 2004060200; // The (date) version of this module $module->requires = 2004013101; // Requires this Moodle version $module->cron = 0; // How often should cron check this module (seconds)? diff --git a/mod/quiz/view.php b/mod/quiz/view.php index 483f49d413..f79c038042 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -140,12 +140,17 @@ print_table($table); } + // BEGIN EDIT + if($available and $quiz->timelimit) { + echo "

".get_string("quiztimelimit","quiz", format_time($quiz->timelimit * 60))."

"; + } + // END EDIT if ($available) { - echo "

".get_string("quizavailable", "quiz", userdate($quiz->timeclose)); + echo "

".get_string("quizavailable", "quiz", userdate($quiz->timeclose)); } else if ($timenow < $quiz->timeopen) { - echo "

".get_string("quiznotavailable", "quiz", userdate($quiz->timeopen)); + echo "

".get_string("quiznotavailable", "quiz", userdate($quiz->timeopen)); } else { - echo "

".get_string("quizclosed", "quiz", userdate($quiz->timeclose)); + echo "

".get_string("quizclosed", "quiz", userdate($quiz->timeclose)); } @@ -158,10 +163,18 @@ if ($numattempts and $quiz->grade) { print_heading("$strbestgrade: $mygrade / $quiz->grade."); } - echo "
"; - echo "

"; + $strconfirmstartattempt = addslashes(get_string("confirmstartattempt","quiz")); + echo "
"; + echo "
"; + // BEGIN EDIT + if($quiz->timelimit) { + include("view_js.php"); + } else { print_single_button("attempt.php", $options, get_string("attemptquiznow","quiz")); - echo "

"; + } + echo "
\n"; + // END EDIT + echo "

"; } } else { print_heading(get_string("nomoreattempts", "quiz")); diff --git a/mod/quiz/view_js.php b/mod/quiz/view_js.php new file mode 100644 index 0000000000..3f99b4fc66 --- /dev/null +++ b/mod/quiz/view_js.php @@ -0,0 +1,9 @@ + + \ No newline at end of file