Permalink
Browse files

QuizTimer modifications added plus necessary files along.

  • Loading branch information...
1 parent 2d9b4f4 commit f41e824f33414e6184611a6d1708cd3a58ec9058 julmis committed Jun 2, 2004
View
@@ -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);
View
@@ -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;
}
View
@@ -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';
# --------------------------------------------------------
@@ -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;
}
@@ -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'
);
# --------------------------------------------------------
View
@@ -0,0 +1,54 @@
+<?php // $Id$
+// QuizTimer main routines.
+// This will produce a floating timer that counts
+// how much time is left to answer the quiz.
+//
+ ?>
+<script language="javascript" type="text/javascript">
+<!--
+
+var timesup = "<?php print_string("timesup","quiz");?>";
+var quizclose = <?php echo ($quiz->timeclose - time()) - $timerstartvalue; ?>; // in seconds
+var quizTimerValue = <? echo $timerstartvalue; ?>; // in seconds
+// -->
+</script>
+<script language="javascript" type="text/javascript" src="timer.js"></script>
+<div id="timer" style="position: absolute; top: 100; left: 10;">
+<!--EDIT BELOW CODE TO YOUR OWN MENU-->
+<table class="generalbox" border="0" cellpadding="0" cellspacing="0" width="150">
+<tr>
+ <td class="generalboxcontent" bgcolor="#ffffff" width="100%">
+ <table class="generaltable" border="0" width="150" cellspacing="0" cellpadding="0">
+ <tr>
+ <th class="generaltableheader" width="100%"><?php print_string("timeleft","quiz");?></th>
+ </tr>
+ <tr>
+ <td id="QuizTimer" class="generaltablecell" align="center" width="100%">
+ <form name="clock"><input onfocus="blur()" type="text" name="time"
+ style="background-color: transparent; border: none; width: 70%; font-family: sans-serif; font-size: 14pt; font-weight: bold; text-align: center;" />
+ </form>
+ </td>
+ </tr>
+ </table>
+ </td>
+</tr>
+</table>
+<!--END OF EDIT-->
+</div>
+<script language="javascript" type="text/javascript">
+<!--
+function changecolor(col) {
+ // Changes the timers background color
+ var d = document.getElementById('QuizTimer');
+ d.style.backgroundColor = col;
+}
+
+var timerbox = getObjectById('timer');
+var theTop = 100;
+var old = theTop;
+movecounter(this);
+
+document.onload = countdown_clock();
+// -->
+</script>
+
Oops, something went wrong.

0 comments on commit f41e824

Please sign in to comment.