--- C:\Documents and Settings\bertoli\Desktop\quiz l8test\db\postgres7.sql	Sun May 14 21:19:22 2006
+++ C:\Documents and Settings\bertoli\Desktop\quiz me\db\postgres7.sql	Wed Aug 30 15:29:30 2006
@@ -1,304 +1,316 @@
-# phpMyAdmin MySQL-Dump
-# version 2.3.2-dev
-# http://www.phpmyadmin.net/ (download page)
-#
-# Host: localhost
-# Generation Time: Oct 16, 2002 at 01:12 AM
-# Server version: 3.23.49
-# PHP Version: 4.2.3
-# Database : moodle
-# --------------------------------------------------------
-
-#
-# Table structure for table prefix_quiz
-#
-
-CREATE TABLE prefix_quiz (
-  id SERIAL PRIMARY KEY,
-  course integer NOT NULL default '0',
-  name varchar(255) NOT NULL default '',
-  intro text NOT NULL default '',
-  timeopen integer NOT NULL default '0',
-  timeclose integer NOT NULL default '0',
-  optionflags integer NOT NULL default '0',
-  penaltyscheme integer NOT NULL default '0',
-  attempts integer NOT NULL default '0',
-  attemptonlast integer NOT NULL default '0',
-  grademethod integer NOT NULL default '1',
-  decimalpoints integer NOT NULL default '2',
-  review integer NOT NULL default '0',
-  questionsperpage integer NOT NULL default '0',
-  shufflequestions integer NOT NULL default '0',
-  shuffleanswers integer NOT NULL default '0',
-  questions text NOT NULL default '',
-  sumgrades integer NOT NULL default '0',
-  grade integer NOT NULL default '0',
-  timecreated integer NOT NULL default '0',
-  timemodified integer NOT NULL default '0',
-  timelimit integer NOT NULL default '0',
-  password varchar(255) NOT NULL default '',
-  subnet varchar(255) NOT NULL default '',
-  popup integer NOT NULL default '0',
-  delay1 integer NOT NULL default '0',
-  delay2 integer NOT NULL default '0'
-);
-
-CREATE INDEX prefix_quiz_course_idx ON prefix_quiz (course);
-
-# --------------------------------------------------------
-
-#
-# Table structure for table prefix_question_answers
-#
-
-CREATE TABLE prefix_question_answers (
-  id SERIAL PRIMARY KEY,
-  question integer NOT NULL default '0',
-  answer text NOT NULL default '',
-  fraction real NOT NULL default '0',
-  feedback text NOT NULL default ''
-);
-
-CREATE INDEX prefix_question_answers_question_idx ON prefix_question_answers (question);
-
-
-# --------------------------------------------------------
-#
-# Table structure for table prefix_quiz_attempts
-#
-
-CREATE TABLE prefix_quiz_attempts (
-  id SERIAL PRIMARY KEY,
-  uniqueid integer NOT NULL default '0',
-  quiz integer NOT NULL default '0',
-  userid integer NOT NULL default '0',
-  attempt integer NOT NULL default '0',
-  sumgrades real NOT NULL default '0',
-  timestart integer NOT NULL default '0',
-  timefinish integer NOT NULL default '0',
-  timemodified integer NOT NULL default '0',
-  layout text NOT NULL default '',
-  preview integer NOT NULL default '0'
-);
-
-CREATE INDEX prefix_quiz_attempts_quiz_idx ON prefix_quiz_attempts (quiz);
-CREATE INDEX prefix_quiz_attempts_userid_idx ON prefix_quiz_attempts (userid);
-CREATE UNIQUE INDEX prefix_quiz_attempts_uniqueid_uk ON prefix_quiz_attempts (uniqueid);
-
-# --------------------------------------------------------
-
-#
-# Table structure for table prefix_question_categories
-#
-
-CREATE TABLE prefix_question_categories (
-  id SERIAL PRIMARY KEY,
-  course integer NOT NULL default '0',
-  name varchar(255) NOT NULL default '',
-  info text NOT NULL default '',
-  publish integer NOT NULL default '0',
-  stamp varchar(255) NOT NULL default '',
-  parent integer NOT NULL default '0',
-  sortorder integer NOT NULL default '999'
-);
-
-CREATE INDEX prefix_question_categories_course_idx ON prefix_question_categories (course);
-
-# --------------------------------------------------------
-#
-# Table structure for table prefix_question_dataset_definitions
-#
-
-
-CREATE TABLE prefix_question_dataset_definitions (
-    id SERIAL8 PRIMARY KEY,
-    category INT8  NOT NULL default '0',
-    name varchar(255) NOT NULL default '',
-    type INT8 NOT NULL default '0',
-    options varchar(255) NOT NULL default '',
-    itemcount INT8  NOT NULL default '0'
-);
-
-CREATE INDEX prefix_question_dataset_definitions_category_idx ON prefix_question_dataset_definitions (category);
-
-# --------------------------------------------------------
-#
-# Table structure for table prefix_question_dataset_items
-#
-
-CREATE TABLE prefix_question_dataset_items (
-    id SERIAL8 PRIMARY KEY,
-    definition INT8  NOT NULL default '0',
-    number INT8  NOT NULL default '0',
-    value varchar(255) NOT NULL default ''
-);
-
-CREATE INDEX prefix_question_dataset_items_definition_idx  ON prefix_question_dataset_items (definition);
-
-# --------------------------------------------------------
-
-#
-# Table structure for table prefix_quiz_grades
-#
-
-CREATE TABLE prefix_quiz_grades (
-  id SERIAL PRIMARY KEY,
-  quiz integer NOT NULL default '0',
-  userid integer NOT NULL default '0',
-  grade real NOT NULL default '0',
-  timemodified integer NOT NULL default '0'
-);
-
-CREATE INDEX prefix_quiz_grades_quiz_idx ON prefix_quiz_grades (quiz);
-CREATE INDEX prefix_quiz_grades_userid_idx ON prefix_quiz_grades (userid);
-
-# --------------------------------------------------------
-
-#
-# Table structure for table prefix_question_sessions
-#
-
-
-CREATE TABLE prefix_question_sessions (
-  id SERIAL PRIMARY KEY,
-  attemptid integer NOT NULL default '0',
-  questionid integer NOT NULL default '0',
-  newest integer NOT NULL default '0',
-  newgraded integer NOT NULL default '0',
-  sumpenalty real NOT NULL default '0',
-  comment text NOT NULL default ''
-);
-
-CREATE UNIQUE INDEX prefix_question_sessions_attempt_idx ON prefix_question_sessions (attemptid,questionid);
-
-# --------------------------------------------------------
-#
-# Table structure for table prefix_question_numerical_units
-#
-
-CREATE TABLE prefix_question_numerical_units (
-    id SERIAL8 PRIMARY KEY,
-    question INT8  NOT NULL default '0',
-    multiplier decimal(40,20) NOT NULL default '1.00000000000000000000',
-    unit varchar(50) NOT NULL default ''
-);
-
-CREATE INDEX prefix_question_numerical_units_question_idx ON prefix_question_numerical_units (question);
-
-# --------------------------------------------------------
-#
-# Table structure for table prefix_question_datasets
-#
-
-CREATE TABLE prefix_question_datasets (
-    id SERIAL8 PRIMARY KEY,
-    question INT8  NOT NULL default '0',
-    datasetdefinition INT8  NOT NULL default '0'
-);
-
-CREATE INDEX prefix_question_datasets_question_datasetdefinition_idx  ON prefix_question_datasets (question,datasetdefinition);
-
-# --------------------------------------------------------
-
-#
-# Table structure for table prefix_quiz_question_instances
-#
-
-CREATE TABLE prefix_quiz_question_instances (
-  id SERIAL PRIMARY KEY,
-  quiz integer NOT NULL default '0',
-  question integer NOT NULL default '0',
-  grade integer NOT NULL default '0'
-);
-
-CREATE INDEX prefix_quiz_question_instances_quiz_idx ON prefix_quiz_question_instances (quiz);
-CREATE INDEX prefix_quiz_question_instances_question_idx ON prefix_quiz_question_instances (question);
-
-# --------------------------------------------------------
-
-#
-# Table structure for table prefix_quiz_question_versions
-#
-
-CREATE TABLE prefix_quiz_question_versions (
-  id SERIAL PRIMARY KEY,
-  quiz integer NOT NULL default '0',
-  oldquestion integer NOT NULL default '0',
-  newquestion integer NOT NULL default '0',
-  originalquestion integer NOT NULL default '0',
-  userid integer NOT NULL default '0',
-  timestamp integer NOT NULL default '0'
-);
-
-# --------------------------------------------------------
-
-#
-# Table structure for table prefix_question
-#
-
-CREATE TABLE prefix_question (
-  id SERIAL PRIMARY KEY,
-  category integer NOT NULL default '0',
-  parent integer NOT NULL default '0',
-  name varchar(255) NOT NULL default '',
-  questiontext text NOT NULL default '',
-  questiontextformat integer NOT NULL default '0',
-  image varchar(255) NOT NULL default '',
-  defaultgrade integer NOT NULL default '1',
-  penalty real NOT NULL default '0.1',
-  qtype varchar(20) NOT NULL default '0',
-  length integer NOT NULL DEFAULT '1',
-  stamp varchar(255) NOT NULL default '',
-  version varchar(255) NOT NULL default '',
-  hidden integer NOT NULL default '0'
-);
-
-CREATE INDEX prefix_question_category_idx ON prefix_question (category);
-
-# --------------------------------------------------------
-
-#
-# Table structure for table prefix_question_attempts
-#
-
-CREATE TABLE prefix_question_attempts (
-  id SERIAL PRIMARY KEY,
-  modulename varchar(20) NOT NULL default 'quiz'
-);
-
-# --------------------------------------------------------
-
-#
-# Table structure for table prefix_question_states
-#
-
-CREATE TABLE prefix_question_states (
-  id SERIAL PRIMARY KEY,
-  attempt integer NOT NULL default '0',
-  question integer NOT NULL default '0',
-  originalquestion integer NOT NULL default '0',
-  seq_number integer NOT NULL default '0',
-  answer text NOT NULL default '',
-  timestamp integer NOT NULL default '0',
-  event integer NOT NULL default '0',
-  grade real NOT NULL default '0',
-  raw_grade real NOT NULL default '0',
-  penalty real NOT NULL default '0'
-);
-
-CREATE INDEX prefix_question_states_attempt_idx ON prefix_question_states (attempt);
-CREATE INDEX prefix_question_states_question_idx ON prefix_question_states (question);;
-
-
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'add', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'update', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'view', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'report', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'attempt', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'submit', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'review', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'editquestions', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'preview', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'start attempt', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'close attempt', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'continue attempt', 'quiz', 'name');
+# phpMyAdmin MySQL-Dump
+# version 2.4.2-dev
+# http://www.phpmyadmin.net/ (download page)
+#
+# Host: localhost
+# Generation Time: Oct 16, 2002 at 01:12 AM
+# Server version: 3.23.49
+# PHP Version: 4.2.3
+# Database : moodle
+# --------------------------------------------------------
+
+#
+# Table structure for table prefix_quiz
+#
+
+CREATE TABLE prefix_quiz (
+  id SERIAL PRIMARY KEY,
+  course integer NOT NULL default '0',
+  name varchar(255) NOT NULL default '',
+  intro text NOT NULL default '',
+  timeopen integer NOT NULL default '0',
+  timeclose integer NOT NULL default '0',
+  optionflags integer NOT NULL default '0',
+  penaltyscheme integer NOT NULL default '0',
+  attempts integer NOT NULL default '0',
+  attemptonlast integer NOT NULL default '0',
+  grademethod integer NOT NULL default '1',
+  decimalpoints integer NOT NULL default '2',
+  review integer NOT NULL default '0',
+  questionsperpage integer NOT NULL default '0',
+  shufflequestions integer NOT NULL default '0',
+  shuffleanswers integer NOT NULL default '0',
+  questions text NOT NULL default '',
+  sumgrades integer NOT NULL default '0',
+  grade integer NOT NULL default '0',
+  timecreated integer NOT NULL default '0',
+  timemodified integer NOT NULL default '0',
+  timelimit integer NOT NULL default '0',
+  password varchar(255) NOT NULL default '',
+  subnet varchar(255) NOT NULL default '',
+  popup integer NOT NULL default '0',
+  delay1 integer NOT NULL default '0',
+  delay2 integer NOT NULL default '0',
+  email_ret int(1) NOT NULL default '0',
+  pass_mark int(3) NOT NULL default '0',
+  email_to_pass varchar(255) NOT NULL default '',
+  cc_to_pass varchar(255) NOT NULL default '',
+  subject_pass varchar(255) NOT NULL default '',
+  body_pass varchar(255) NOT NULL default '',
+  email_to_fail varchar(255) NOT NULL default '',
+  cc_to_fail varchar(255) NOT NULL default '',
+  subject_fail varchar(255) NOT NULL default '',
+  body_fail varchar(255) NOT NULL default '',
+  det_add varchar(255) NOT NULL default ''  
+);
+
+CREATE INDEX prefix_quiz_course_idx ON prefix_quiz (course);
+
+# --------------------------------------------------------
+
+#
+# Table structure for table prefix_question_answers
+#
+
+CREATE TABLE prefix_question_answers (
+  id SERIAL PRIMARY KEY,
+  question integer NOT NULL default '0',
+  answer text NOT NULL default '',
+  fraction real NOT NULL default '0',
+  feedback text NOT NULL default ''
+);
+
+CREATE INDEX prefix_question_answers_question_idx ON prefix_question_answers (question);
+
+
+# --------------------------------------------------------
+#
+# Table structure for table prefix_quiz_attempts
+#
+
+CREATE TABLE prefix_quiz_attempts (
+  id SERIAL PRIMARY KEY,
+  uniqueid integer NOT NULL default '0',
+  quiz integer NOT NULL default '0',
+  userid integer NOT NULL default '0',
+  attempt integer NOT NULL default '0',
+  sumgrades real NOT NULL default '0',
+  timestart integer NOT NULL default '0',
+  timefinish integer NOT NULL default '0',
+  timemodified integer NOT NULL default '0',
+  layout text NOT NULL default '',
+  preview integer NOT NULL default '0',
+  email_sent int(1) NOT NULL default '0'  
+);
+
+CREATE INDEX prefix_quiz_attempts_quiz_idx ON prefix_quiz_attempts (quiz);
+CREATE INDEX prefix_quiz_attempts_userid_idx ON prefix_quiz_attempts (userid);
+CREATE UNIQUE INDEX prefix_quiz_attempts_uniqueid_uk ON prefix_quiz_attempts (uniqueid);
+
+# --------------------------------------------------------
+
+#
+# Table structure for table prefix_question_categories
+#
+
+CREATE TABLE prefix_question_categories (
+  id SERIAL PRIMARY KEY,
+  course integer NOT NULL default '0',
+  name varchar(255) NOT NULL default '',
+  info text NOT NULL default '',
+  publish integer NOT NULL default '0',
+  stamp varchar(255) NOT NULL default '',
+  parent integer NOT NULL default '0',
+  sortorder integer NOT NULL default '999'
+);
+
+CREATE INDEX prefix_question_categories_course_idx ON prefix_question_categories (course);
+
+# --------------------------------------------------------
+#
+# Table structure for table prefix_question_dataset_definitions
+#
+
+
+CREATE TABLE prefix_question_dataset_definitions (
+    id SERIAL8 PRIMARY KEY,
+    category INT8  NOT NULL default '0',
+    name varchar(255) NOT NULL default '',
+    type INT8 NOT NULL default '0',
+    options varchar(255) NOT NULL default '',
+    itemcount INT8  NOT NULL default '0'
+);
+
+CREATE INDEX prefix_question_dataset_definitions_category_idx ON prefix_question_dataset_definitions (category);
+
+# --------------------------------------------------------
+#
+# Table structure for table prefix_question_dataset_items
+#
+
+CREATE TABLE prefix_question_dataset_items (
+    id SERIAL8 PRIMARY KEY,
+    definition INT8  NOT NULL default '0',
+    number INT8  NOT NULL default '0',
+    value varchar(255) NOT NULL default ''
+);
+
+CREATE INDEX prefix_question_dataset_items_definition_idx  ON prefix_question_dataset_items (definition);
+
+# --------------------------------------------------------
+
+#
+# Table structure for table prefix_quiz_grades
+#
+
+CREATE TABLE prefix_quiz_grades (
+  id SERIAL PRIMARY KEY,
+  quiz integer NOT NULL default '0',
+  userid integer NOT NULL default '0',
+  grade real NOT NULL default '0',
+  timemodified integer NOT NULL default '0'
+);
+
+CREATE INDEX prefix_quiz_grades_quiz_idx ON prefix_quiz_grades (quiz);
+CREATE INDEX prefix_quiz_grades_userid_idx ON prefix_quiz_grades (userid);
+
+# --------------------------------------------------------
+
+#
+# Table structure for table prefix_question_sessions
+#
+
+
+CREATE TABLE prefix_question_sessions (
+  id SERIAL PRIMARY KEY,
+  attemptid integer NOT NULL default '0',
+  questionid integer NOT NULL default '0',
+  newest integer NOT NULL default '0',
+  newgraded integer NOT NULL default '0',
+  sumpenalty real NOT NULL default '0',
+  comment text NOT NULL default ''
+);
+
+CREATE UNIQUE INDEX prefix_question_sessions_attempt_idx ON prefix_question_sessions (attemptid,questionid);
+
+# --------------------------------------------------------
+#
+# Table structure for table prefix_question_numerical_units
+#
+
+CREATE TABLE prefix_question_numerical_units (
+    id SERIAL8 PRIMARY KEY,
+    question INT8  NOT NULL default '0',
+    multiplier decimal(40,20) NOT NULL default '1.00000000000000000000',
+    unit varchar(50) NOT NULL default ''
+);
+
+CREATE INDEX prefix_question_numerical_units_question_idx ON prefix_question_numerical_units (question);
+
+# --------------------------------------------------------
+#
+# Table structure for table prefix_question_datasets
+#
+
+CREATE TABLE prefix_question_datasets (
+    id SERIAL8 PRIMARY KEY,
+    question INT8  NOT NULL default '0',
+    datasetdefinition INT8  NOT NULL default '0'
+);
+
+CREATE INDEX prefix_question_datasets_question_datasetdefinition_idx  ON prefix_question_datasets (question,datasetdefinition);
+
+# --------------------------------------------------------
+
+#
+# Table structure for table prefix_quiz_question_instances
+#
+
+CREATE TABLE prefix_quiz_question_instances (
+  id SERIAL PRIMARY KEY,
+  quiz integer NOT NULL default '0',
+  question integer NOT NULL default '0',
+  grade integer NOT NULL default '0'
+);
+
+CREATE INDEX prefix_quiz_question_instances_quiz_idx ON prefix_quiz_question_instances (quiz);
+CREATE INDEX prefix_quiz_question_instances_question_idx ON prefix_quiz_question_instances (question);
+
+# --------------------------------------------------------
+
+#
+# Table structure for table prefix_quiz_question_versions
+#
+
+CREATE TABLE prefix_quiz_question_versions (
+  id SERIAL PRIMARY KEY,
+  quiz integer NOT NULL default '0',
+  oldquestion integer NOT NULL default '0',
+  newquestion integer NOT NULL default '0',
+  originalquestion integer NOT NULL default '0',
+  userid integer NOT NULL default '0',
+  timestamp integer NOT NULL default '0'
+);
+
+# --------------------------------------------------------
+
+#
+# Table structure for table prefix_question
+#
+
+CREATE TABLE prefix_question (
+  id SERIAL PRIMARY KEY,
+  category integer NOT NULL default '0',
+  parent integer NOT NULL default '0',
+  name varchar(255) NOT NULL default '',
+  questiontext text NOT NULL default '',
+  questiontextformat integer NOT NULL default '0',
+  image varchar(255) NOT NULL default '',
+  defaultgrade integer NOT NULL default '1',
+  penalty real NOT NULL default '0.1',
+  qtype varchar(20) NOT NULL default '0',
+  length integer NOT NULL DEFAULT '1',
+  stamp varchar(255) NOT NULL default '',
+  version varchar(255) NOT NULL default '',
+  hidden integer NOT NULL default '0'
+);
+
+CREATE INDEX prefix_question_category_idx ON prefix_question (category);
+
+# --------------------------------------------------------
+
+#
+# Table structure for table prefix_question_attempts
+#
+
+CREATE TABLE prefix_question_attempts (
+  id SERIAL PRIMARY KEY,
+  modulename varchar(20) NOT NULL default 'quiz'
+);
+
+# --------------------------------------------------------
+
+#
+# Table structure for table prefix_question_states
+#
+
+CREATE TABLE prefix_question_states (
+  id SERIAL PRIMARY KEY,
+  attempt integer NOT NULL default '0',
+  question integer NOT NULL default '0',
+  originalquestion integer NOT NULL default '0',
+  seq_number integer NOT NULL default '0',
+  answer text NOT NULL default '',
+  timestamp integer NOT NULL default '0',
+  event integer NOT NULL default '0',
+  grade real NOT NULL default '0',
+  raw_grade real NOT NULL default '0',
+  penalty real NOT NULL default '0'
+);
+
+CREATE INDEX prefix_question_states_attempt_idx ON prefix_question_states (attempt);
+CREATE INDEX prefix_question_states_question_idx ON prefix_question_states (question);;
+
+
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'add', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'update', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'view', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'report', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'attempt', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'submit', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'review', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'editquestions', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'preview', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'start attempt', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'close attempt', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'continue attempt', 'quiz', 'name');


--- C:\Documents and Settings\bertoli\Desktop\quiz l8test\db\mysql.sql	Sun May 14 21:19:22 2006
+++ C:\Documents and Settings\bertoli\Desktop\quiz me\db\mysql.sql	Thu Aug 31 13:56:12 2006
@@ -1,313 +1,329 @@
--- phpMyAdmin SQL Dump
--- version 2.6.0-pl1
--- http://www.phpmyadmin.net
--- 
--- Host: localhost
--- Generation Time: Jun 05, 2005 at 04:32 PM
--- Server version: 4.0.15
--- PHP Version: 4.3.3
--- 
--- Database: `moodle15`
--- 
-
--- --------------------------------------------------------
-
--- 
--- Table structure for table `prefix_quiz`
--- 
-
-CREATE TABLE prefix_quiz (
-  id int(10) unsigned NOT NULL auto_increment,
-  course int(10) unsigned NOT NULL default '0',
-  name varchar(255) NOT NULL default '',
-  intro text NOT NULL default '',
-  timeopen int(10) unsigned NOT NULL default '0',
-  timeclose int(10) unsigned NOT NULL default '0',
-  optionflags int(10) unsigned NOT NULL default '0',
-  penaltyscheme int(4) unsigned NOT NULL default '0',
-  attempts smallint(6) NOT NULL default '0',
-  attemptonlast tinyint(4) NOT NULL default '0',
-  grademethod tinyint(4) NOT NULL default '1',
-  decimalpoints int(4) NOT NULL default '2',
-  review int(10) unsigned NOT NULL default '0',
-  questionsperpage int(10) NOT NULL default '0',
-  shufflequestions tinyint(4) NOT NULL default '0',
-  shuffleanswers tinyint(4) NOT NULL default '0',
-  questions text NOT NULL default '',
-  sumgrades int(10) NOT NULL default '0',
-  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',
-  password varchar(255) NOT NULL default '',
-  subnet varchar(255) NOT NULL default '',
-  popup tinyint(4) NOT NULL default '0',
-  delay1 int(10) NOT NULL default '0',
-  delay2 int(10) NOT NULL default '0',
-  PRIMARY KEY  (id),
-  KEY course (course)
-) TYPE=MyISAM COMMENT='Main information about each quiz';
-
--- --------------------------------------------------------
-
--- 
--- Table structure for table `prefix_question_answers`
--- 
-
-CREATE TABLE prefix_question_answers (
-  id int(10) unsigned NOT NULL auto_increment,
-  question int(10) unsigned NOT NULL default '0',
-  answer text NOT NULL default '',
-  fraction float NOT NULL default '0',
-  feedback text NOT NULL default '',
-  PRIMARY KEY  (id),
-  KEY question (question)
-) TYPE=MyISAM COMMENT='Answers, with a fractional grade (0-1) and feedback';
-
--- --------------------------------------------------------
-
--- 
--- Table structure for table `prefix_quiz_attempts`
--- 
-
-CREATE TABLE prefix_quiz_attempts (
-  id int(10) unsigned NOT NULL auto_increment,
-  uniqueid int(10) unsigned NOT NULL default '0',
-  quiz int(10) unsigned NOT NULL default '0', 
-  userid int(10) unsigned NOT NULL default '0',
-  attempt smallint(6) NOT NULL default '0',
-  sumgrades float NOT NULL default '0',
-  timestart int(10) unsigned NOT NULL default '0',
-  timefinish int(10) unsigned NOT NULL default '0',
-  timemodified int(10) unsigned NOT NULL default '0',
-  layout text NOT NULL default '',
-  preview tinyint(3) unsigned NOT NULL default '0',
-  PRIMARY KEY  (id),
-  UNIQUE KEY `uniqueid` (`uniqueid`),
-  KEY quiz (quiz),
-  KEY userid (userid)
-) TYPE=MyISAM COMMENT='Stores various attempts on a quiz';
-
--- --------------------------------------------------------
-
--- 
--- Table structure for table `prefix_question_categories`
--- 
-
-CREATE TABLE prefix_question_categories (
-  id int(10) unsigned NOT NULL auto_increment,
-  course int(10) unsigned NOT NULL default '0',
-  name varchar(255) NOT NULL default '',
-  info text NOT NULL default '',
-  publish tinyint(4) NOT NULL default '0',
-  stamp varchar(255) NOT NULL default '',
-  parent int(10) unsigned NOT NULL default '0',
-  sortorder int(10) unsigned NOT NULL default '999',
-  PRIMARY KEY  (id),
-  KEY course (course)
-) TYPE=MyISAM COMMENT='Categories are for grouping questions';
-
--- --------------------------------------------------------
-
--- 
--- Table structure for table `prefix_question_dataset_definitions`
--- 
-
-CREATE TABLE prefix_question_dataset_definitions (
-  id int(10) unsigned NOT NULL auto_increment,
-  category int(10) unsigned NOT NULL default '0',
-  name varchar(255) NOT NULL default '',
-  type int(10) NOT NULL default '0',
-  options varchar(255) NOT NULL default '',
-  itemcount int(10) unsigned NOT NULL default '0',
-  PRIMARY KEY  (id),
-  KEY category (category)
-) TYPE=MyISAM COMMENT='Organises and stores properties for dataset items';
-
--- --------------------------------------------------------
-
--- 
--- Table structure for table `prefix_question_dataset_items`
--- 
-
-CREATE TABLE prefix_question_dataset_items (
-  id int(10) unsigned NOT NULL auto_increment,
-  definition int(10) unsigned NOT NULL default '0',
-  number int(10) unsigned NOT NULL default '0',
-  value varchar(255) NOT NULL default '',
-  PRIMARY KEY  (id),
-  KEY definition (definition)
-) TYPE=MyISAM COMMENT='Individual dataset items';
-
--- --------------------------------------------------------
-
--- 
--- Table structure for table `prefix_quiz_grades`
--- 
-
-CREATE TABLE prefix_quiz_grades (
-  id int(10) unsigned NOT NULL auto_increment,
-  quiz int(10) unsigned NOT NULL default '0',
-  userid int(10) unsigned NOT NULL default '0',
-  grade double NOT NULL default '0',
-  timemodified int(10) unsigned NOT NULL default '0',
-  PRIMARY KEY  (id),
-  KEY quiz (quiz),
-  KEY userid (userid)
-) TYPE=MyISAM COMMENT='Final quiz grade (may be best of several attempts)';
-
--- --------------------------------------------------------
-
--- 
--- Table structure for table `prefix_question_sessions`
--- 
-
-CREATE TABLE prefix_question_sessions (
-  id int(10) unsigned NOT NULL auto_increment,
-  attemptid int(10) unsigned NOT NULL default '0',
-  questionid int(10) unsigned NOT NULL default '0',
-  newest int(10) unsigned NOT NULL default '0',
-  newgraded int(10) unsigned NOT NULL default '0',
-  sumpenalty float NOT NULL default '0',
-  comment text NOT NULL default '',
-  PRIMARY KEY  (id),
-  UNIQUE KEY attemptid (attemptid,questionid)
-) TYPE=MyISAM COMMENT='Gives ids of the newest open and newest graded states';
-
--- --------------------------------------------------------
-
--- 
--- Table structure for table `prefix_question_numerical_units`
--- 
-
-CREATE TABLE prefix_question_numerical_units (
-  id int(10) unsigned NOT NULL auto_increment,
-  question int(10) unsigned NOT NULL default '0',
-  multiplier decimal(40,20) NOT NULL default '1.00000000000000000000',
-  unit varchar(50) NOT NULL default '',
-  PRIMARY KEY  (id),
-  KEY question (question)
-) TYPE=MyISAM COMMENT='Optional unit options for numerical questions';
-
--- --------------------------------------------------------
-
--- 
--- Table structure for table `prefix_question_datasets`
--- 
-
-CREATE TABLE prefix_question_datasets (
-  id int(10) unsigned NOT NULL auto_increment,
-  question int(10) unsigned NOT NULL default '0',
-  datasetdefinition int(10) unsigned NOT NULL default '0',
-  PRIMARY KEY  (id),
-  KEY question (question,datasetdefinition)
-) TYPE=MyISAM COMMENT='Many-many relation between questions and dataset definitions';
-
--- --------------------------------------------------------
-
--- 
--- Table structure for table `prefix_quiz_question_instances`
--- 
-
-CREATE TABLE prefix_quiz_question_instances (
-  id int(10) unsigned NOT NULL auto_increment,
-  quiz int(10) unsigned NOT NULL default '0',
-  question int(10) unsigned NOT NULL default '0',
-  grade smallint(6) NOT NULL default '0',
-  PRIMARY KEY  (id),
-  KEY quiz (quiz),
-  KEY question (question)
-) TYPE=MyISAM COMMENT='The grade for a question in a quiz';
-
--- --------------------------------------------------------
-
--- 
--- Table structure for table `prefix_quiz_question_versions`
--- 
-
-CREATE TABLE prefix_quiz_question_versions (
-  id int(10) unsigned NOT NULL auto_increment,
-  quiz int(10) unsigned NOT NULL default '0',
-  oldquestion int(10) unsigned NOT NULL default '0',
-  newquestion int(10) unsigned NOT NULL default '0',
-  originalquestion int(10) unsigned NOT NULL default '0',
-  userid int(10) unsigned NOT NULL default '0',
-  timestamp int(10) unsigned NOT NULL default '0',
-  PRIMARY KEY  (id)
-) TYPE=MyISAM COMMENT='The mapping between old and new versions of a question';
-
--- --------------------------------------------------------
-
--- 
--- Table structure for table `prefix_question`
--- 
-
-CREATE TABLE prefix_question (
-  id int(10) NOT NULL auto_increment,
-  category int(10) NOT NULL default '0',
-  parent int(10) unsigned NOT NULL default '0',
-  name varchar(255) NOT NULL default '',
-  questiontext text NOT NULL,
-  questiontextformat tinyint(2) NOT NULL default '0',
-  image varchar(255) NOT NULL default '',
-  defaultgrade int(10) unsigned NOT NULL default '1',
-  penalty float NOT NULL default '0.1',
-  qtype varchar(20) NOT NULL default '',
-  length int(10) unsigned NOT NULL default '1',
-  stamp varchar(255) NOT NULL default '',
-  version varchar(255) NOT NULL default '',
-  hidden int(1) unsigned NOT NULL default '0',
-  PRIMARY KEY  (id),
-  KEY category (category)
-) TYPE=MyISAM COMMENT='The quiz questions themselves';
-
--- --------------------------------------------------------
-
--- 
--- Table structure for table `prefix_question_states`
--- 
-
-CREATE TABLE prefix_question_states (
-  id int(10) unsigned NOT NULL auto_increment,
-  attempt int(10) unsigned NOT NULL default '0',
-  question int(10) unsigned NOT NULL default '0',
-  originalquestion int(10) unsigned NOT NULL default '0',
-  seq_number int(6) unsigned NOT NULL default '0',
-  answer text NOT NULL default '',
-  timestamp int(10) unsigned NOT NULL default '0',
-  event int(4) unsigned NOT NULL default '0',
-  grade float NOT NULL default '0',
-  raw_grade float NOT NULL default '0',
-  penalty float NOT NULL default '0',
-  PRIMARY KEY  (id),
-  KEY attempt (attempt),
-  KEY question (question)
-) TYPE=MyISAM COMMENT='Stores user responses to a quiz, and percentage grades';
-
--- --------------------------------------------------------
-
--- 
--- Table structure for table `prefix_question_attempts`
--- 
-
-CREATE TABLE prefix_question_attempts (
-  id int(10) unsigned NOT NULL auto_increment,
-  modulename varchar(20) NOT NULL default 'quiz',
-  PRIMARY KEY  (id)
-) TYPE=MyISAM COMMENT='Student attempts. This table gets extended by the modules';
-
--- --------------------------------------------------------
-
-
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'add', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'update', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'view', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'report', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'attempt', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'submit', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'review', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'editquestions', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'preview', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'start attempt', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'close attempt', 'quiz', 'name');
-INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'continue attempt', 'quiz', 'name');
+-- phpMyAdmin SQL Dump
+-- version 2.7.0-pl1
+-- http://www.phpmyadmin.net
+-- 
+-- Host: localhost
+-- Generation Time: Jun 05, 2005 at 04:32 PM
+-- Server version: 4.0.15
+-- PHP Version: 4.3.3
+-- 
+-- Database: `moodle15`
+-- 
+
+-- --------------------------------------------------------
+
+-- 
+-- Table structure for table `prefix_quiz`
+-- 
+
+CREATE TABLE prefix_quiz (
+  id int(10) unsigned NOT NULL auto_increment,
+  course int(10) unsigned NOT NULL default '0',
+  name varchar(255) NOT NULL default '',
+  intro text NOT NULL default '',
+  timeopen int(10) unsigned NOT NULL default '0',
+  timeclose int(10) unsigned NOT NULL default '0',
+  optionflags int(10) unsigned NOT NULL default '0',
+  penaltyscheme int(4) unsigned NOT NULL default '0',
+  attempts smallint(6) NOT NULL default '0',
+  attemptonlast tinyint(4) NOT NULL default '0',
+  grademethod tinyint(4) NOT NULL default '1',
+  decimalpoints int(4) NOT NULL default '2',
+  review int(10) unsigned NOT NULL default '0',
+  questionsperpage int(10) NOT NULL default '0',
+  shufflequestions tinyint(4) NOT NULL default '0',
+  shuffleanswers tinyint(4) NOT NULL default '0',
+  questions text NOT NULL default '',
+  sumgrades int(10) NOT NULL default '0',
+  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',
+  password varchar(255) NOT NULL default '',
+  subnet varchar(255) NOT NULL default '',
+  popup tinyint(4) NOT NULL default '0',
+  delay1 int(10) NOT NULL default '0',
+  delay2 int(10) NOT NULL default '0',
+  email_ret int(1) NOT NULL default '0',
+  pass_mark int(3) NOT NULL default '0',
+  email_to_pass varchar(255) NOT NULL default '',
+  cc_to_pass varchar(255) NOT NULL default '',
+  subject_pass varchar(255) NOT NULL default '',
+  body_pass varchar(255) NOT NULL default '',
+  email_to_fail varchar(255) NOT NULL default '',
+  cc_to_fail varchar(255) NOT NULL default '',
+  subject_fail varchar(255) NOT NULL default '',
+  body_fail varchar(255) NOT NULL default '',
+  det_add varchar(255) NOT NULL default '',  
+  PRIMARY KEY  (id),
+  KEY course (course)
+) TYPE=MyISAM COMMENT='Main information about each quiz';
+
+
+-- --------------------------------------------------------
+
+-- 
+-- Table structure for table `prefix_question_answers`
+-- 
+
+CREATE TABLE prefix_question_answers (
+  id int(10) unsigned NOT NULL auto_increment,
+  question int(10) unsigned NOT NULL default '0',
+  answer text NOT NULL default '',
+  fraction float NOT NULL default '0',
+  feedback text NOT NULL default '',
+  PRIMARY KEY  (id),
+  KEY question (question)
+) TYPE=MyISAM COMMENT='Answers, with a fractional grade (0-1) and feedback';
+
+-- --------------------------------------------------------
+
+-- 
+-- Table structure for table `prefix_quiz_attempts`
+-- 
+
+
+
+
+CREATE TABLE prefix_quiz_attempts (
+  id int(10) unsigned NOT NULL auto_increment,
+  uniqueid int(10) unsigned NOT NULL default '0',
+  quiz int(10) unsigned NOT NULL default '0', 
+  userid int(10) unsigned NOT NULL default '0',
+  attempt smallint(6) NOT NULL default '0',
+  sumgrades float NOT NULL default '0',
+  timestart int(10) unsigned NOT NULL default '0',
+  timefinish int(10) unsigned NOT NULL default '0',
+  timemodified int(10) unsigned NOT NULL default '0',
+  layout text NOT NULL default '',
+  preview tinyint(3) unsigned NOT NULL default '0',
+  email_sent int(1) unsigned NOT NULL default '0',  
+  PRIMARY KEY  (id),
+  UNIQUE KEY `uniqueid` (`uniqueid`),
+  KEY quiz (quiz),
+  KEY userid (userid)
+) TYPE=MyISAM COMMENT='Stores various attempts on a quiz';
+
+-- --------------------------------------------------------
+
+-- 
+-- Table structure for table `prefix_question_categories`
+-- 
+
+CREATE TABLE prefix_question_categories (
+  id int(10) unsigned NOT NULL auto_increment,
+  course int(10) unsigned NOT NULL default '0',
+  name varchar(255) NOT NULL default '',
+  info text NOT NULL default '',
+  publish tinyint(4) NOT NULL default '0',
+  stamp varchar(255) NOT NULL default '',
+  parent int(10) unsigned NOT NULL default '0',
+  sortorder int(10) unsigned NOT NULL default '999',
+  PRIMARY KEY  (id),
+  KEY course (course)
+) TYPE=MyISAM COMMENT='Categories are for grouping questions';
+
+-- --------------------------------------------------------
+
+-- 
+-- Table structure for table `prefix_question_dataset_definitions`
+-- 
+
+CREATE TABLE prefix_question_dataset_definitions (
+  id int(10) unsigned NOT NULL auto_increment,
+  category int(10) unsigned NOT NULL default '0',
+  name varchar(255) NOT NULL default '',
+  type int(10) NOT NULL default '0',
+  options varchar(255) NOT NULL default '',
+  itemcount int(10) unsigned NOT NULL default '0',
+  PRIMARY KEY  (id),
+  KEY category (category)
+) TYPE=MyISAM COMMENT='Organises and stores properties for dataset items';
+
+-- --------------------------------------------------------
+
+-- 
+-- Table structure for table `prefix_question_dataset_items`
+-- 
+
+CREATE TABLE prefix_question_dataset_items (
+  id int(10) unsigned NOT NULL auto_increment,
+  definition int(10) unsigned NOT NULL default '0',
+  number int(10) unsigned NOT NULL default '0',
+  value varchar(255) NOT NULL default '',
+  PRIMARY KEY  (id),
+  KEY definition (definition)
+) TYPE=MyISAM COMMENT='Individual dataset items';
+
+-- --------------------------------------------------------
+
+-- 
+-- Table structure for table `prefix_quiz_grades`
+-- 
+
+CREATE TABLE prefix_quiz_grades (
+  id int(10) unsigned NOT NULL auto_increment,
+  quiz int(10) unsigned NOT NULL default '0',
+  userid int(10) unsigned NOT NULL default '0',
+  grade double NOT NULL default '0',
+  timemodified int(10) unsigned NOT NULL default '0',
+  PRIMARY KEY  (id),
+  KEY quiz (quiz),
+  KEY userid (userid)
+) TYPE=MyISAM COMMENT='Final quiz grade (may be best of several attempts)';
+
+-- --------------------------------------------------------
+
+-- 
+-- Table structure for table `prefix_question_sessions`
+-- 
+
+CREATE TABLE prefix_question_sessions (
+  id int(10) unsigned NOT NULL auto_increment,
+  attemptid int(10) unsigned NOT NULL default '0',
+  questionid int(10) unsigned NOT NULL default '0',
+  newest int(10) unsigned NOT NULL default '0',
+  newgraded int(10) unsigned NOT NULL default '0',
+  sumpenalty float NOT NULL default '0',
+  comment text NOT NULL default '',
+  PRIMARY KEY  (id),
+  UNIQUE KEY attemptid (attemptid,questionid)
+) TYPE=MyISAM COMMENT='Gives ids of the newest open and newest graded states';
+
+-- --------------------------------------------------------
+
+-- 
+-- Table structure for table `prefix_question_numerical_units`
+-- 
+
+CREATE TABLE prefix_question_numerical_units (
+  id int(10) unsigned NOT NULL auto_increment,
+  question int(10) unsigned NOT NULL default '0',
+  multiplier decimal(40,20) NOT NULL default '1.00000000000000000000',
+  unit varchar(50) NOT NULL default '',
+  PRIMARY KEY  (id),
+  KEY question (question)
+) TYPE=MyISAM COMMENT='Optional unit options for numerical questions';
+
+-- --------------------------------------------------------
+
+-- 
+-- Table structure for table `prefix_question_datasets`
+-- 
+
+CREATE TABLE prefix_question_datasets (
+  id int(10) unsigned NOT NULL auto_increment,
+  question int(10) unsigned NOT NULL default '0',
+  datasetdefinition int(10) unsigned NOT NULL default '0',
+  PRIMARY KEY  (id),
+  KEY question (question,datasetdefinition)
+) TYPE=MyISAM COMMENT='Many-many relation between questions and dataset definitions';
+
+-- --------------------------------------------------------
+
+-- 
+-- Table structure for table `prefix_quiz_question_instances`
+-- 
+
+CREATE TABLE prefix_quiz_question_instances (
+  id int(10) unsigned NOT NULL auto_increment,
+  quiz int(10) unsigned NOT NULL default '0',
+  question int(10) unsigned NOT NULL default '0',
+  grade smallint(6) NOT NULL default '0',
+  PRIMARY KEY  (id),
+  KEY quiz (quiz),
+  KEY question (question)
+) TYPE=MyISAM COMMENT='The grade for a question in a quiz';
+
+-- --------------------------------------------------------
+
+-- 
+-- Table structure for table `prefix_quiz_question_versions`
+-- 
+
+CREATE TABLE prefix_quiz_question_versions (
+  id int(10) unsigned NOT NULL auto_increment,
+  quiz int(10) unsigned NOT NULL default '0',
+  oldquestion int(10) unsigned NOT NULL default '0',
+  newquestion int(10) unsigned NOT NULL default '0',
+  originalquestion int(10) unsigned NOT NULL default '0',
+  userid int(10) unsigned NOT NULL default '0',
+  timestamp int(10) unsigned NOT NULL default '0',
+  PRIMARY KEY  (id)
+) TYPE=MyISAM COMMENT='The mapping between old and new versions of a question';
+
+-- --------------------------------------------------------
+
+-- 
+-- Table structure for table `prefix_question`
+-- 
+
+CREATE TABLE prefix_question (
+  id int(10) NOT NULL auto_increment,
+  category int(10) NOT NULL default '0',
+  parent int(10) unsigned NOT NULL default '0',
+  name varchar(255) NOT NULL default '',
+  questiontext text NOT NULL,
+  questiontextformat tinyint(2) NOT NULL default '0',
+  image varchar(255) NOT NULL default '',
+  defaultgrade int(10) unsigned NOT NULL default '1',
+  penalty float NOT NULL default '0.1',
+  qtype varchar(20) NOT NULL default '',
+  length int(10) unsigned NOT NULL default '1',
+  stamp varchar(255) NOT NULL default '',
+  version varchar(255) NOT NULL default '',
+  hidden int(1) unsigned NOT NULL default '0',
+  PRIMARY KEY  (id),
+  KEY category (category)
+) TYPE=MyISAM COMMENT='The quiz questions themselves';
+
+-- --------------------------------------------------------
+
+-- 
+-- Table structure for table `prefix_question_states`
+-- 
+
+CREATE TABLE prefix_question_states (
+  id int(10) unsigned NOT NULL auto_increment,
+  attempt int(10) unsigned NOT NULL default '0',
+  question int(10) unsigned NOT NULL default '0',
+  originalquestion int(10) unsigned NOT NULL default '0',
+  seq_number int(6) unsigned NOT NULL default '0',
+  answer text NOT NULL default '',
+  timestamp int(10) unsigned NOT NULL default '0',
+  event int(4) unsigned NOT NULL default '0',
+  grade float NOT NULL default '0',
+  raw_grade float NOT NULL default '0',
+  penalty float NOT NULL default '0',
+  PRIMARY KEY  (id),
+  KEY attempt (attempt),
+  KEY question (question)
+) TYPE=MyISAM COMMENT='Stores user responses to a quiz, and percentage grades';
+
+-- --------------------------------------------------------
+
+-- 
+-- Table structure for table `prefix_question_attempts`
+-- 
+
+CREATE TABLE prefix_question_attempts (
+  id int(10) unsigned NOT NULL auto_increment,
+  modulename varchar(20) NOT NULL default 'quiz',
+  PRIMARY KEY  (id)
+) TYPE=MyISAM COMMENT='Student attempts. This table gets extended by the modules';
+
+-- --------------------------------------------------------
+
+
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'add', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'update', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'view', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'report', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'attempt', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'submit', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'review', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'editquestions', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'preview', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'start attempt', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'close attempt', 'quiz', 'name');
+INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'continue attempt', 'quiz', 'name');


--- C:\Documents and Settings\bertoli\Desktop\quiz l8test\db\mysql.php	Wed Jul 19 10:08:36 2006
+++ C:\Documents and Settings\bertoli\Desktop\quiz me\db\mysql.php	Tue Sep 12 15:42:46 2006
@@ -1,1100 +1,1077 @@
-<?php // $Id: mysql.php,v 1.100.2.4 2006/07/18 10:58:40 tjhunt Exp $
-
-function quiz_upgrade($oldversion) {
-// This function does anything necessary to upgrade
-// older versions to match current functionality
-
-    global $CFG, $QTYPES, $db;
-    require_once("$CFG->dirroot/mod/quiz/locallib.php");
-
-    if ($oldversion < 2002101800) {
-        execute_sql(" ALTER TABLE `quiz_attempts` ".
-                    " ADD `timestart` INT(10) UNSIGNED DEFAULT '0' NOT NULL AFTER `sumgrades` , ".
-                    " ADD `timefinish` INT(10) UNSIGNED DEFAULT '0' NOT NULL AFTER `timestart` ");
-        execute_sql(" UPDATE `quiz_attempts` SET timestart = timemodified ");
-        execute_sql(" UPDATE `quiz_attempts` SET timefinish = timemodified ");
-    }
-    if ($oldversion < 2002102101) {
-        execute_sql(" DELETE FROM log_display WHERE module = 'quiz' ");
-        execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('quiz', 'view', 'quiz', 'name') ");
-        execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('quiz', 'report', 'quiz', 'name') ");
-        execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('quiz', 'attempt', 'quiz', 'name') ");
-        execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('quiz', 'submit', 'quiz', 'name') ");
-    }
-    if ($oldversion < 2002102600) {
-        execute_sql(" ALTER TABLE `quiz_answers` CHANGE `feedback` `feedback` TEXT NOT NULL ");
-    }
-
-    if ($oldversion < 2002122300) {
-        execute_sql("ALTER TABLE `quiz_grades` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
-        execute_sql("ALTER TABLE `quiz_attempts` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
-    }
-
-    // prefixes required from here on, or use table_column()
-
-    if ($oldversion < 2003010100) {
-        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD review TINYINT(4) UNSIGNED DEFAULT '0' NOT NULL AFTER `grademethod` ");
-    }
-
-    if ($oldversion < 2003010301) {
-        table_column("quiz_truefalse", "true", "trueanswer", "INTEGER", "10", "UNSIGNED", "0", "NOT NULL", "");
-        table_column("quiz_truefalse", "false", "falseanswer", "INTEGER", "10", "UNSIGNED", "0", "NOT NULL", "");
-        table_column("quiz_questions", "type", "qtype", "INTEGER", "10", "UNSIGNED", "0", "NOT NULL", "");
-    }
-
-    if ($oldversion < 2003022303) {
-        modify_database ("", "CREATE TABLE `prefix_quiz_randommatch` (
-                             `id` int(10) unsigned NOT NULL auto_increment,
-                             `question` int(10) unsigned NOT NULL default '0',
-                             `choose` INT UNSIGNED DEFAULT '4' NOT NULL,
-                             PRIMARY KEY ( `id` )
-                          );");
-    }
-
-    if ($oldversion < 2003030303) {
-        table_column("quiz_questions", "", "defaultgrade", "INTEGER", "6", "UNSIGNED", "1", "NOT NULL", "image");
-    }
-
-    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) ");
-        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_grades` ADD INDEX(quiz) ");
-        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_grades` ADD INDEX(userid) ");
-        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_question_grades` ADD INDEX(quiz) ");
-        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_question_grades` ADD INDEX(question) ");
-        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_randommatch` ADD INDEX(question) ");
-        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_responses` ADD INDEX(attempt) ");
-        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_responses` ADD INDEX(question) ");
-    }
-
-    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,
-                             `question` int(10) unsigned NOT NULL default '0',
-                             `subquestions` varchar(255) NOT NULL default '',
-                             PRIMARY KEY  (`id`),
-                             KEY `question` (`question`)
-                           );");
-
-        modify_database ("", "CREATE TABLE `prefix_quiz_match_sub` (
-                             `id` int(10) unsigned NOT NULL auto_increment,
-                             `question` int(10) unsigned NOT NULL default '0',
-                             `questiontext` text NOT NULL,
-                             `answertext` varchar(255) NOT NULL default '',
-                             PRIMARY KEY  (`id`),
-                             KEY `question` (`question`)
-                           );");
-    }
-
-    if ($oldversion < 2003040901) {
-        table_column("quiz", "", "shufflequestions", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "review");
-        table_column("quiz", "", "shuffleanswers", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "shufflequestions");
-    }
-
-    if ($oldversion < 2003071001) {
-
-        modify_database ("", " CREATE TABLE `prefix_quiz_numerical` (
-                               `id` int(10) unsigned NOT NULL auto_increment,
-                               `question` int(10) unsigned NOT NULL default '0',
-                               `answer` int(10) unsigned NOT NULL default '0',
-                               `min` varchar(255) NOT NULL default '',
-                               `max` varchar(255) NOT NULL default '',
-                               PRIMARY KEY  (`id`),
-                               KEY `answer` (`answer`)
-                             ) TYPE=MyISAM COMMENT='Options for numerical questions'; ");
-    }
-
-    if ($oldversion < 2003072400) {
-        execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('quiz', 'review', 'quiz', 'name') ");
-    }
-
-    if ($oldversion < 2003072901) {
-        modify_database ("", " CREATE TABLE `prefix_quiz_multianswers` (
-                               `id` int(10) unsigned NOT NULL auto_increment,
-                                `question` int(10) unsigned NOT NULL default '0',
-                                `answers` varchar(255) NOT NULL default '',
-                                `positionkey` varchar(255) NOT NULL default '',
-                                `answertype` smallint(6) NOT NULL default '0',
-                                `norm` int(10) unsigned NOT NULL default '1',
-                                PRIMARY KEY  (`id`),
-                                KEY `question` (`question`)
-                              ) TYPE=MyISAM COMMENT='Options for multianswer questions'; ");
-    }
-
-    if ($oldversion < 2003080301) {
-        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD eachattemptbuildsonthelast TINYINT(4) DEFAULT '0' NOT NULL AFTER `attempts` ");
-    }
-
-    if ($oldversion < 2003080400) {
-        table_column("quiz", "eachattemptbuildsonthelast", "attemptonlast", "TINYINT", "4", "UNSIGNED", "0", "NOT NULL", "");
-    }
-
-    if ($oldversion < 2003082300) {
-        table_column("quiz_questions", "", "stamp", "varchar", "255", "", "", "not null", "qtype");
-    }
-
-    if ($oldversion < 2003082301) {
-        table_column("quiz_questions", "stamp", "stamp", "varchar", "255", "", "", "not null");
-        table_column("quiz_questions", "", "version", "integer", "10", "", "1", "not null", "stamp");
-        if ($questions = get_records("quiz_questions")) {
-            foreach ($questions as $question) {
-                $stamp = make_unique_id_code();
-                if (!set_field("quiz_questions", "stamp", $stamp, "id", $question->id)) {
-                    notify("Error while adding stamp to question id = $question->id");
-                }
-            }
-        }
-    }
-
-    if ($oldversion < 2003082700) {
-        table_column("quiz_categories", "", "stamp", "varchar", "255", "", "", "not null");
-        if ($categories = get_records("quiz_categories")) {
-            foreach ($categories as $category) {
-                $stamp = make_unique_id_code();
-                if (!set_field("quiz_categories", "stamp", $stamp, "id", $category->id)) {
-                    notify("Error while adding stamp to category id = $category->id");
-                }
-            }
-        }
-    }
-
-    if ($oldversion < 2003111100) {
-        $duplicates = get_records_sql("SELECT stamp as id,count(*) as cuenta
-                                       FROM {$CFG->prefix}quiz_questions
-                                       GROUP BY stamp
-                                       HAVING count(*)>1");
-
-        if ($duplicates) {
-            notify("You have some quiz questions with duplicate stamps IDs.  Cleaning these up.");
-            foreach ($duplicates as $duplicate) {
-                $questions = get_records("quiz_questions","stamp",$duplicate->id);
-                $add = 1;
-                foreach ($questions as $question) {
-                    echo "Changing question id $question->id stamp to ".$duplicate->id.$add."<br />";
-                    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");
-        }
-    }
-
-    if ($oldversion < 2004021300) {
-        table_column("quiz_questions", "", "questiontextformat", "integer", "2", "", "0", "not null", "questiontext");
-    }
-
-    if ($oldversion < 2004021900) {
-        modify_database("","INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'add', 'quiz', 'name');");
-        modify_database("","INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'update', 'quiz', 'name');");
-    }
-
-    if ($oldversion < 2004051700) {
-        include_once("$CFG->dirroot/mod/quiz/lib.php");
-        quiz_refresh_events();
-    }
-
-    if ($oldversion < 2004060200) {
-        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD timelimit INT(2) UNSIGNED DEFAULT '0' NOT NULL ");
-    }
-
-    if ($oldversion < 2004070700) {
-        table_column("quiz", "", "password", "varchar", "255", "", "", "not null", "");
-        table_column("quiz", "", "subnet", "varchar", "255", "", "", "not null", "");
-    }
-
-    if ($oldversion < 2004073001) {
-        // Six new tables:
-
-        // One table for handling units for numerical questions
-        modify_database ("", " CREATE TABLE `prefix_quiz_numerical_units` (
-                               `id` int(10) unsigned NOT NULL auto_increment,
-                               `question` int(10) unsigned NOT NULL default '0',
-                               `multiplier` decimal(40,20) NOT NULL default '1.00000000000000000000',
-                               `unit` varchar(50) NOT NULL default '',
-                               PRIMARY KEY  (`id`)
-                ) TYPE=MyISAM COMMENT='Optional unit options for numerical questions'; ");
-
-        // Four tables for handling distribution and storage of
-        // individual data for dataset dependent question types
-        modify_database ("", " CREATE TABLE `prefix_quiz_attemptonlast_datasets` (
-                               `id` int(10) unsigned NOT NULL auto_increment,
-                               `category` int(10) unsigned NOT NULL default '0',
-                               `userid` int(10) unsigned NOT NULL default '0',
-                               `datasetnumber` int(10) unsigned NOT NULL default '0',
-                               PRIMARY KEY  (`id`),
-                               UNIQUE KEY `category` (`category`,`userid`)
-            ) TYPE=MyISAM COMMENT='Dataset number for attemptonlast attempts per user'; ");
-        modify_database ("", " CREATE TABLE `prefix_quiz_dataset_definitions` (
-                               `id` int(10) unsigned NOT NULL auto_increment,
-                               `category` int(10) unsigned NOT NULL default '0',
-                               `name` varchar(255) NOT NULL default '',
-                               `type` int(10) NOT NULL default '0',
-                               `options` varchar(255) NOT NULL default '',
-                               `itemcount` int(10) unsigned NOT NULL default '0',
-                               PRIMARY KEY  (`id`)
-            ) TYPE=MyISAM COMMENT='Organises and stores properties for dataset items'; ");
-        modify_database ("", " CREATE TABLE `prefix_quiz_dataset_items` (
-                               `id` int(10) unsigned NOT NULL auto_increment,
-                               `definition` int(10) unsigned NOT NULL default '0',
-                               `number` int(10) unsigned NOT NULL default '0',
-                               `value` varchar(255) NOT NULL default '',
-                               PRIMARY KEY  (`id`),
-                               KEY `definition` (`definition`)
-                             ) TYPE=MyISAM COMMENT='Individual dataset items'; ");
-        modify_database ("", " CREATE TABLE `prefix_quiz_question_datasets` (
-                               `id` int(10) unsigned NOT NULL auto_increment,
-                               `question` int(10) unsigned NOT NULL default '0',
-                               `datasetdefinition` int(10) unsigned NOT NULL default '0',
-                               PRIMARY KEY  (`id`),
-                               KEY `question` (`question`,`datasetdefinition`)
-            ) TYPE=MyISAM COMMENT='Many-many relation between questions and dataset definitions'; ");
-
-        // One table for new question type calculated
-        //  - the first dataset dependent question type
-        modify_database ("", " CREATE TABLE `prefix_quiz_calculated` (
-                               `id` int(10) unsigned NOT NULL auto_increment,
-                               `question` int(10) unsigned NOT NULL default '0',
-                               `answer` int(10) unsigned NOT NULL default '0',
-                               `tolerance` varchar(20) NOT NULL default '0.0',
-                               `tolerancetype` int(10) NOT NULL default '1',
-                               `correctanswerlength` int(10) NOT NULL default '2',
-                               PRIMARY KEY  (`id`),
-                               KEY `question` (`question`)
-                ) TYPE=MyISAM COMMENT='Options for questions of type calculated'; ");
-    }
-
-    if ($oldversion < 2004111400) {
-        table_column("quiz_responses", "answer", "answer", "text", "", "", "", "not null");
-    }
-
-    if ($oldversion < 2004111700) {
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz DROP INDEX course;",false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_calculated DROP INDEX answer;",false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_categories DROP INDEX course;",false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_dataset_definitions DROP INDEX category;",false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_numerical DROP INDEX question;",false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_numerical_units DROP INDEX question;",false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_questions DROP INDEX category;",false);
-
-        modify_database('','ALTER TABLE prefix_quiz ADD INDEX course (course);');
-        modify_database('','ALTER TABLE prefix_quiz_calculated ADD INDEX answer (answer);');
-        modify_database('','ALTER TABLE prefix_quiz_categories ADD INDEX course (course);');
-        modify_database('','ALTER TABLE prefix_quiz_dataset_definitions ADD INDEX category (category);');
-        modify_database('','ALTER TABLE prefix_quiz_numerical ADD INDEX question (question);');
-        modify_database('','ALTER TABLE prefix_quiz_numerical_units ADD INDEX question (question);');
-        modify_database('','ALTER TABLE prefix_quiz_questions ADD INDEX category (category);');
-    }
-
-    if ($oldversion < 2004120501) {
-        table_column("quiz_calculated", "", "correctanswerformat", "integer", "10", "", "2", "not null", "correctanswerlength");
-    }
-
-    if ($oldversion < 2004121400) {  // New field to determine popup window behaviour
-        table_column("quiz", "", "popup", "integer", "4", "", "0", "not null", "subnet");
-    }
-
-    if ($oldversion < 2005010201) {
-        table_column('quiz_categories', '', 'parent');
-        table_column('quiz_categories', '', 'sortorder', 'integer', '10', '', '999');
-    }
-
-    if ($oldversion < 2005010300) {
-        table_column("quiz", "", "questionsperpage", "integer", "10", "", "0", "not null", "review");
-    }
-
-    if ($oldversion < 2005012700) {
-        table_column('quiz_grades', 'grade', 'grade', 'real', 2, '');
-    }
-
-    if ($oldversion < 2005021400) {
-        table_column("quiz", "", "decimalpoints", "integer", "4", "", "2", "not null", "grademethod");
-    }
-
-    if($oldversion < 2005022800) {
-        table_column('quiz_questions', '', 'hidden', 'integer', '1', 'unsigned', '0', 'not null', 'version');
-        table_column('quiz_responses', '', 'originalquestion', 'integer', '10', 'unsigned', '0', 'not null', 'question');
-        modify_database ('', "CREATE TABLE `prefix_quiz_question_version` (
-                              `id` int(10) unsigned NOT NULL auto_increment,
-                              `quiz` int(10) unsigned NOT NULL default '0',
-                              `oldquestion` int(10) unsigned NOT NULL default '0',
-                              `newquestion` int(10) unsigned NOT NULL default '0',
-                              `userid` int(10) unsigned NOT NULL default '0',
-                              `timestamp` int(10) unsigned NOT NULL default '0',
-                              PRIMARY KEY  (`id`)
-                            ) TYPE=MyISAM COMMENT='The mapping between old and new versions of a question';");
-    }
-
-    if ($oldversion < 2005032000) {
-        execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('quiz', 'editquestions', 'quiz', 'name') ");
-    }
-
-    if ($oldversion < 2005032300) {
-        modify_database ('', 'ALTER TABLE prefix_quiz_question_version RENAME prefix_quiz_question_versions;');
-    }
-
-    if ($oldversion < 2005041200) { // replace wiki-like with markdown
-        include_once( "$CFG->dirroot/lib/wiki_to_markdown.php" );
-        $wtm = new WikiToMarkdown();
-        $sql = "select course from {$CFG->prefix}quiz_categories c, {$CFG->prefix}quiz_questions q ";
-        $sql .= "where c.id = q.category ";
-        $sql .= "and q.id = ";
-        $wtm->update( 'quiz_questions', 'questiontext', 'questiontextformat', $sql );
-    }
-
-    if ($oldversion < 2005041304) {
-        // make random questions hidden
-        modify_database('', "UPDATE prefix_quiz_questions SET hidden = '1' WHERE qtype ='".RANDOM."';");
-    }
-
-    if ($oldversion < 2005042002) {
-        table_column('quiz_answers', 'answer', 'answer', 'text', '', '', '', 'not null', '');
-    }
-
-    if ($oldversion < 2005042400) {
-
-    // Changes to quiz table
-
-        // The bits of the optionflags field will hold various option flags
-        table_column('quiz', '', 'optionflags', 'integer', '10', 'unsigned', '0', 'not null', 'timeclose');
-
-        // The penalty scheme
-        table_column('quiz', '', 'penaltyscheme', 'integer', '4', 'unsigned', '0', 'not null', 'optionflags');
-
-        // The review options are now all stored in the bits of the review field
-        table_column('quiz', 'review', 'review', 'integer', 10, 'unsigned', 0, 'not null', '');
-
-    /// Changes to quiz_attempts table
-
-        // The preview flag marks teacher previews
-        table_column('quiz_attempts', '', 'preview', 'tinyint', '2', 'unsigned', '0', 'not null', 'timemodified');
-
-        // The layout is the list of questions with inserted page breaks.
-        table_column('quiz_attempts', '', 'layout', 'text', '', '', '', 'not null', 'timemodified');
-        // For old quiz attempts we will set this to the repaginated question list from $quiz->questions
-
-    /// The following updates of field values require a loop through all quizzes
-        // This is because earlier versions of mysql don't allow joins in UPDATE
-        if ($quizzes = get_records('quiz')) {
-
-            // turn reporting off temporarily to avoid one line output per set_field
-            $olddebug = $db->debug;
-            $db->debug = false;
-            echo 'Now updating '.count($quizzes).' quizzes';
-            foreach ($quizzes as $quiz) {
-
-                // repaginate
-                if ($quiz->questionsperpage) {
-                    $quiz->questions = quiz_repaginate($quiz->questions, $quiz->questionsperpage);
-                    set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->id);
-                }
-                set_field('quiz_attempts', 'layout', $quiz->questions, 'quiz', $quiz->id);
-
-                // set preview flag
-                if ($teachers = get_course_teachers($quiz->course)) {
-                    $teacherids = implode(',', array_keys($teachers));
-                    execute_sql("UPDATE {$CFG->prefix}quiz_attempts SET preview = 1 WHERE userid IN ($teacherids)");
-                }
-
-                // set review flags in quiz table
-                $review = (QUIZ_REVIEW_IMMEDIATELY & (QUIZ_REVIEW_RESPONSES + QUIZ_REVIEW_SCORES));
-                if ($quiz->feedback) {
-                    $review += (QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_FEEDBACK);
-                }
-                if ($quiz->correctanswers) {
-                    $review += (QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_ANSWERS);
-                }
-                if ($quiz->review & 1) {
-                    $review += QUIZ_REVIEW_CLOSED;
-                }
-                if ($quiz->review & 2) {
-                    $review += QUIZ_REVIEW_OPEN;
-                }
-                set_field('quiz', 'review', $review, 'id', $quiz->id);
-            }
-            $db->debug = $olddebug;
-        }
-
-        // We can now drop the fields whose data has been moved to the review field
-        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz` DROP feedback");
-        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz` DROP correctanswers");
-
-    /// Renaming tables
-
-        // rename the quiz_question_grades table to quiz_question_instances
-        modify_database ('', 'ALTER TABLE prefix_quiz_question_grades RENAME prefix_quiz_question_instances;');
-
-        // rename the quiz_responses table quiz_states
-        modify_database ('', 'ALTER TABLE prefix_quiz_responses RENAME prefix_quiz_states;');
-
-    /// add columns to quiz_states table
-
-        // The sequence number of the state.
-        table_column('quiz_states', '', 'seq_number', 'integer', '6', 'unsigned', '0', 'not null', 'originalquestion');
-        // For existing states we leave this at 0 because in the old quiz code there was only one response allowed
-
-        // The time the state was created.
-        table_column('quiz_states', '', 'timestamp', 'integer', '10', 'unsigned', '0', 'not null', 'answer');
-        // For existing states we will below set this to the timemodified field of the attempt
-
-        // The type of event that led to the creation of the state
-        table_column('quiz_states', '', 'event', 'integer', '4', 'unsigned', '0', 'not null', 'timestamp');
-
-        // The raw grade
-        table_column('quiz_states', '', 'raw_grade', 'varchar', '10', '', '', 'not null', 'grade');
-        // For existing states (no penalties) this is equal to the grade
-        execute_sql("UPDATE {$CFG->prefix}quiz_states SET raw_grade = grade");
-
-        // The penalty that the response attracted
-        table_column('quiz_states', '', 'penalty', 'varchar', '10', '', '0.0', 'not null', 'raw_grade');
-        // For existing states this can stay at 0 because penalties did not exist previously.
-
-    /// New table for pointers to newest and newest graded states
-
-        modify_database('', "CREATE TABLE `prefix_quiz_newest_states` (
-                             `id` int(10) unsigned NOT NULL auto_increment,
-                             `attemptid` int(10) unsigned NOT NULL default '0',
-                             `questionid` int(10) unsigned NOT NULL default '0',
-                             `new` int(10) unsigned NOT NULL default '0',
-                             `newgraded` int(10) unsigned NOT NULL default '0',
-                             `sumpenalty` varchar(10) NOT NULL default '0.0',
-                             PRIMARY KEY  (`id`),
-                             UNIQUE KEY `attemptid` (`attemptid`,`questionid`)
-                           ) TYPE=MyISAM COMMENT='Gives ids of the newest open and newest graded states';");
-
-    /// Now upgrade some fields in states and newest_states tables where necessary
-        // to save time on large sites only do this for attempts that have not yet been finished.
-        if ($attempts = get_records_select('quiz_attempts', 'timefinish = 0')) {
-            echo 'Update the states for the '.count($attempts).' open attempts';
-            // turn reporting off temporarily to avoid one line output per set_field
-            $olddebug = $db->debug;
-            $db->debug = false;
-            foreach ($attempts as $attempt) {
-                quiz_upgrade_states($attempt);
-            }
-            $db->debug = $olddebug;
-        }
-
-    /// Entries for the log_display table
-
-        modify_database('', " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'preview', 'quiz', 'name');");
-        modify_database('', " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'start attempt', 'quiz', 'name');");
-        modify_database('', " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'close attempt', 'quiz', 'name');");
-
-    /// update the default settings in $CFG
-        $review = (QUIZ_REVIEW_IMMEDIATELY & (QUIZ_REVIEW_RESPONSES + QUIZ_REVIEW_SCORES));
-        if (!empty($CFG->quiz_feedback)) {
-            $review += (QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_FEEDBACK);
-        }
-        if (!empty($CFG->quiz_correctanswers)) {
-            $review += (QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_ANSWERS);
-        }
-        if (isset($CFG->quiz_review) and ($CFG->quiz_review & 1)) {
-            $review += QUIZ_REVIEW_CLOSED;
-        }
-        if (isset($CFG->quiz_review) and ($CFG->quiz_review & 2)) {
-            $review += QUIZ_REVIEW_OPEN;
-        }
-        set_config('quiz_review', $review);
-
-    /// Use tolerance instead of min and max in numerical question type
-        table_column('quiz_numerical', '', 'tolerance', 'varchar', '255', '', '0.0', 'not null', 'answer');
-        execute_sql("UPDATE {$CFG->prefix}quiz_numerical SET tolerance = (max-min)/2");
-        modify_database('', 'ALTER TABLE `prefix_quiz_numerical` DROP `min`'); // Replaced by tolerance
-        modify_database('', 'ALTER TABLE `prefix_quiz_numerical` DROP `max`'); // Replaced by tolerance
-
-    /// Tables for Remote Questions
-        modify_database ('', "CREATE TABLE `prefix_quiz_rqp` (
-                              `id` int(10) unsigned NOT NULL auto_increment,
-                              `question` int(10) unsigned NOT NULL default '0',
-                              `type` int(10) unsigned NOT NULL default '0',
-                              `source` longblob NOT NULL default '',
-                              `format` varchar(255) NOT NULL default '',
-                              `flags` tinyint(3) unsigned NOT NULL default '0',
-                              `maxscore` int(10) unsigned NOT NULL default '1',
-                              PRIMARY KEY  (`id`),
-                              KEY `question` (`question`)
-                              ) TYPE=MyISAM COMMENT='Options for RQP questions';");
-
-        modify_database ('', "CREATE TABLE `prefix_quiz_rqp_type` (
-                              `id` int(10) unsigned NOT NULL auto_increment,
-                              `name` varchar(255) NOT NULL default '',
-                              `rendering_server` varchar(255) NOT NULL default '',
-                              `cloning_server` varchar(255) NOT NULL default '',
-                              `flags` tinyint(3) NOT NULL default '0',
-                              PRIMARY KEY  (`id`),
-                              UNIQUE KEY `name` (`name`)
-                              ) TYPE=MyISAM COMMENT='RQP question types and the servers to be used to process them';");
-
-        modify_database ('', "CREATE TABLE `prefix_quiz_rqp_states` (
-                              `id` int(10) unsigned NOT NULL auto_increment,
-                              `stateid` int(10) unsigned NOT NULL default '0',
-                              `responses` text NOT NULL default '',
-                              `persistent_data` text NOT NULL default '',
-                              `template_vars` text NOT NULL default '',
-                              PRIMARY KEY  (`id`)
-                              ) TYPE=MyISAM COMMENT='RQP question type specific state information';");
-    }
-
-    if ($oldversion < 2005050300) {
-        // length of question determines question numbering. Currently all questions require one
-        // question number except for DESCRIPTION questions.
-        table_column('quiz_questions', '', 'length', 'integer', '10', 'unsigned', '1', 'not null', 'qtype');
-        execute_sql("UPDATE {$CFG->prefix}quiz_questions SET length = 0 WHERE qtype = ".DESCRIPTION);
-    }
-
-    if ($oldversion < 2005050408) {
-        table_column('quiz_questions', '', 'penalty', 'float', '', '', '0.1', 'not null', 'defaultgrade');
-        table_column('quiz_newest_states', 'new', 'newest', 'integer', '10', 'unsigned', '0', 'not null');
-    }
-
-    if ($oldversion < 2005051400) {
-        modify_database('', 'ALTER TABLE prefix_quiz_rqp_type RENAME prefix_quiz_rqp_types;');
-    	modify_database('', "CREATE TABLE `prefix_quiz_rqp_servers` (
-    			      id int(10) unsigned NOT NULL auto_increment,
-    			      typeid int(10) unsigned NOT NULL default '0',
-    			      url varchar(255) NOT NULL default '',
-    			      can_render tinyint(2) unsigned NOT NULL default '0',
-    			      can_author tinyint(2) unsigned NOT NULL default '0',
-    			      PRIMARY KEY  (id)
-    			    ) TYPE=MyISAM COMMENT='Information about RQP servers';");
-    	if ($types = get_records('quiz_rqp_types')) {
-    	    foreach($types as $type) {
-        		$server->typeid = $type->id;
-        		$server->url = $type->rendering_server;
-        		$server->can_render = 1;
-        		insert_record('quiz_rqp_servers', $server);
-    	    }
-    	}
-        modify_database('', 'ALTER TABLE prefix_quiz_rqp_types DROP rendering_server');
-        modify_database('', 'ALTER TABLE prefix_quiz_rqp_types DROP cloning_server');
-        modify_database('', 'ALTER TABLE prefix_quiz_rqp_types DROP flags');
-    }
-
-    if ($oldversion < 2005051401) {
-        // Some earlier changes are undone here, so we need another condition
-        if ($oldversion >= 2005042900) {
-            // Restore the answer field
-            table_column('quiz_numerical', '', 'answer', 'integer', '10', 'unsigned', '0', 'not null', 'answers');
-            $singleanswer = array();
-            if ($numericals = get_records('quiz_numerical')) {
-                $numericals = array_values($numericals);
-                $n = count($numericals);
-                for ($i = 0; $i < $n; $i++) {
-                    $numerical =& $numericals[$i];
-                    if (strpos($numerical->answers, ',')) { // comma separated list?
-                        // Back this up to delete the record after the new ones are created
-                        $id = $numerical->id;
-                        unset($numerical->id);
-                        // We need to create a record for each answer id
-                        $answers = explode(',', $numerical->answers);
-                        foreach ($answers as $answer) {
-                            $numerical->answer = $answer;
-                            insert_record('quiz_numerical', $numerical);
-                        }
-                        // ... and get rid of the old record
-                        delete_records('quiz_numerical', 'id', $id);
-                    } else {
-                        $singleanswer[] = $numerical->id;
-                    }
-                }
-            }
-
-            // Do all of these at once
-            if (!empty($singleanswer)) {
-                $singleanswer = implode(',', $singleanswer);
-                modify_database('', "UPDATE prefix_quiz_numerical SET answer = answers WHERE id IN ($singleanswer);");
-            }
-
-            // All answer fields are set, so we can delete the answers field
-            modify_database('', 'ALTER TABLE `prefix_quiz_numerical` DROP `answers`');
-
-        // If the earlier changes weren't made we can safely do only the
-        // bits here.
-        } else {
-            // Comma separated questionids will be stored as sequence
-            table_column('quiz_multianswers', '', 'sequence',  'varchar', '255', '', '', 'not null', 'question');
-            // Change the type of positionkey to int, so that the sorting works!
-            table_column('quiz_multianswers', 'positionkey', 'positionkey',  'integer', '10', 'unsigned', '0', 'not null', '');
-            table_column('quiz_questions', '', 'parent', 'integer', '10', 'unsigned', '0', 'not null', 'category');
-            modify_database('', "UPDATE prefix_quiz_questions SET parent = id WHERE qtype ='".RANDOM."';");
-
-            // Each multianswer record is converted to a question object and then
-            // inserted as a new question into the quiz_questions table.
-            // After that the question fields in the quiz_answers table and the
-            // qtype specific tables are updated to point to the new question id.
-            // Note: The quiz_numerical table is different as it stores one record
-            //       per defined answer (to allow different tolerance values for
-            //       different possible answers. (Currently multiple answers are
-            //       not supported by the numerical editing interface, but
-            //       all processing code does support that possibility.
-            if ($multianswers = get_records_sql("SELECT m.id, q.category, " .
-                                            "q.id AS parent, " . // question id (of multianswer question) as parent
-                                            "q.name, q.questiontextformat, " .
-                                            "m.norm AS defaultgrade, " . // norm is snow stored as defaultgrade
-                                            "m.answertype AS qtype, " .  // just rename this
-                                            "q.version, q.hidden, m.answers, " .
-                                            "m.positionkey " .
-                                            "FROM {$CFG->prefix}quiz_questions q, " .
-                                            "     {$CFG->prefix}quiz_multianswers m " .
-                                            "WHERE q.qtype = '".MULTIANSWER."' " .
-                                            "AND   q.id = m.question " .
-                                            "ORDER BY q.id ASC, m.positionkey ASC")) { // ordered by positionkey
-                $multianswers = array_values($multianswers);
-                $n        = count($multianswers);
-                $parent   = $multianswers[0]->parent;
-                $sequence = array();
-                $positions = array();
-
-                // Turn reporting off temporarily to avoid one line output per set_field
-                global $db;
-                $olddebug = $db->debug;
-                $db->debug = false;
-                echo 'Now updating '.$n.' cloze questions.';
-                for ($i = 0; $i < $n; $i++) {
-                    // Backup these two values before unsetting the object fields
-                    $answers = $multianswers[$i]->answers; unset($multianswers[$i]->answers);
-                    $pos = $multianswers[$i]->positionkey; unset($multianswers[$i]->positionkey);
-
-                    // Needed for substituting multianswer ids with position keys in the $state->answer field
-                    $positions[$multianswers[$i]->id] = $pos;
-
-                // Create questions for all the multianswer victims
-                    unset($multianswers[$i]->id);
-                    $multianswers[$i]->length = 0;
-                    $multianswers[$i]->questiontext = '';
-                    $multianswers[$i]->stamp = make_unique_id_code();
-                    $multianswers[$i]->name = addslashes($multianswers[$i]->name);
-                    // $multianswers[$i]->parent is set in the query
-                    // $multianswers[$i]->defaultgrade is set in the query
-                    // $multianswers[$i]->qtype is set in the query
-                    $id = insert_record('quiz_questions', $multianswers[$i]);
-                    $sequence[$pos] = $id;
-
-                // Update the quiz_answers table to point to these new questions
-                execute_sql("UPDATE {$CFG->prefix}quiz_answers SET question = '$id' WHERE id IN ($answers)", false);
-                // Update the questiontype tables to point to these new questions
-
-                    if (SHORTANSWER == $multianswers[$i]->qtype) {
-                        execute_sql("UPDATE {$CFG->prefix}quiz_shortanswer SET question = '$id' WHERE answers = '$answers'", false);
-                    } else if (MULTICHOICE == $multianswers[$i]->qtype) {
-                        execute_sql("UPDATE {$CFG->prefix}quiz_multichoice SET question = '$id' WHERE answers = '$answers'", false);
-                    } else if (NUMERICAL == $multianswers[$i]->qtype) {
-                        execute_sql("UPDATE {$CFG->prefix}quiz_numerical SET question = '$id' WHERE answer IN ($answers)", false);
-                    }
-
-                    // Whenever we're through with the subquestions of one multianswer
-                    // question we delete the old records in the multianswers table,
-                    // store a new record with the sequence in the multianswers table
-                    // and point $parent to the next multianswer question.
-                    if (!isset($multianswers[$i+1]) || $parent != $multianswers[$i+1]->parent) {
-
-                        // Substituting multianswer ids with position keys in the $state->answer field
-                        if ($states = get_records('quiz_states', 'question', $parent)) {
-                            foreach ($states as $state) {
-                                $reg = array();
-                                preg_match_all('/(?:^|,)([0-9]+)-([^,]*)/', $state->answer, $reg);
-                                $state->answer = '';
-                                $m = count($reg[1]);
-                                for ($j = 0; $j < $m; $j++) {
-                                    if (isset($positions[$reg[1][$j]])) {
-                                        $state->answer .= $positions[$reg[1][$j]] . '-' . $reg[2][$j] . ',';
-                                    } else {
-                                        notify("Undefined multianswer id ({$reg[1][$j]}) used in state #{$state->id}!");
-                                        $state->answer .= $j+1 . '-' . $reg[2][$j] . ',';
-                                    }
-                                }
-                                $state->answer = rtrim($state->answer, ','); // strip trailing comma
-                                update_record('quiz_states', $state);
-                            }
-                        }
-
-                        delete_records('quiz_multianswers', 'question', $parent);
-                        $multi = new stdClass;
-                        $multi->question = $parent;
-                        $multi->sequence = implode(',', $sequence);
-                        insert_record('quiz_multianswers', $multi);
-
-                        if (isset($multianswers[$i+1])) {
-                            $parent    = $multianswers[$i+1]->parent;
-                            $sequence  = array();
-                            $positions = array();
-                        }
-                    }
-                }
-                $db->debug = $olddebug;
-            }
-
-            // Remove redundant fields from quiz_multianswers
-            modify_database('', 'ALTER TABLE `prefix_quiz_multianswers` DROP `answers`');
-            modify_database('', 'ALTER TABLE `prefix_quiz_multianswers` DROP `positionkey`');
-            modify_database('', 'ALTER TABLE `prefix_quiz_multianswers` DROP `answertype`');
-            modify_database('', 'ALTER TABLE `prefix_quiz_multianswers` DROP `norm`');
-        }
-    }
-
-    if ($oldversion < 2005052004) {
-        // We need to remove some duplicate entries that may be present in some databases
-        // due to a faulty restore script
-
-        // Remove duplicate entries from quiz_numerical
-        if ($dups = get_records_sql("
-                SELECT question, answer, count(*) as num
-                FROM {$CFG->prefix}quiz_numerical
-                GROUP BY question, answer
-                HAVING count(*) > 1"
-            )) {
-            foreach ($dups as $dup) {
-                $ids = get_records_sql("
-                    SELECT id, id
-                    FROM {$CFG->prefix}quiz_numerical
-                    WHERE question = '$dup->question'
-                    AND answer = '$dup->answer'"
-                );
-                $skip = true;
-                foreach ($ids as $id) {
-                    if ($skip) {
-                        $skip = false;
-                    } else {
-                        delete_records('quiz_numerical','id', $id->id);
-                    }
-                }
-            }
-        }
-
-        // Remove duplicate entries from quiz_shortanswer
-        if ($dups = get_records_sql("
-                SELECT question, answers, count(*) as num
-                FROM {$CFG->prefix}quiz_shortanswer
-                GROUP BY question, answers
-                HAVING count(*) > 1"
-            )) {
-            foreach ($dups as $dup) {
-                $ids = get_records_sql("
-                    SELECT id, id
-                    FROM {$CFG->prefix}quiz_shortanswer
-                    WHERE question = '$dup->question'
-                    AND answers = '$dup->answers'"
-                );
-                $skip = true;
-                foreach ($ids as $id) {
-                    if ($skip) {
-                        $skip = false;
-                    } else {
-                        delete_records('quiz_shortanswer','id', $id->id);
-                    }
-                }
-            }
-        }
-
-        // Remove duplicate entries from quiz_multichoice
-        if ($dups = get_records_sql("
-                SELECT question, answers, count(*) as num
-                FROM {$CFG->prefix}quiz_multichoice
-                GROUP BY question, answers
-                HAVING count(*) > 1"
-            )) {
-            foreach ($dups as $dup) {
-                $ids = get_records_sql("
-                    SELECT id, id
-                    FROM {$CFG->prefix}quiz_multichoice
-                    WHERE question = '$dup->question'
-                    AND answers = '$dup->answers'"
-                );
-                $skip = true;
-                foreach ($ids as $id) {
-                    if ($skip) {
-                        $skip = false;
-                    } else {
-                        delete_records('quiz_multichoice','id', $id->id);
-                    }
-                }
-            }
-        }
-    }
-
-    if ($oldversion < 2005060300) {
-        //Search all the orphan categories (those whose course doesn't exist)
-        //and process them, deleting or moving them to site course - Bug 2459
-
-        //Set debug to false
-        $olddebug = $db->debug;
-        $db->debug = false;
-
-        //Iterate over all the quiz_categories records to get their course id
-        if ($courses = get_records_sql ("SELECT DISTINCT course as id, course
-                                         FROM {$CFG->prefix}quiz_categories")) {
-            //Iterate over courses
-            foreach ($courses as $course) {
-                //If the course doesn't exist, orphan category found!
-                //Process it with question_delete_course(). It will do all the hard work.
-                if (!record_exists('course', 'id', $course->id)) {
-                    require_once("$CFG->libdir/questionlib.php ");
-                    question_delete_course($course);
-                }
-            }
-        }
-        //Reset rebug to its original state
-        $db->debug = $olddebug;
-    }
-
-    if ($oldversion < 2005062600) {
-        modify_database ('', "
-            CREATE TABLE `prefix_quiz_essay` (
-                `id` int(10) unsigned NOT NULL auto_increment,
-                `question` int(10) unsigned NOT NULL default '0',
-                `answer` varchar(255) NOT NULL default '',
-                PRIMARY KEY  (`id`),
-                KEY `question` (`question`)
-           ) TYPE=MyISAM COMMENT='Options for essay questions'");
-    
-        modify_database ('', "
-            CREATE TABLE `prefix_quiz_essay_states` (
-              `id` int(10) unsigned NOT NULL auto_increment,
-              `stateid` int(10) unsigned NOT NULL default '0',
-              `graded` tinyint(4) unsigned NOT NULL default '0',
-              `fraction` varchar(10) NOT NULL default '0.0',
-              `response` text NOT NULL,
-              PRIMARY KEY  (`id`)
-            ) TYPE=MyISAM COMMENT='essay question type specific state information'");
-    }
-
-    if ($oldversion < 2005070202) {
-        // add new unique id to prepare the way for lesson module to have its own attempts table
-        table_column('quiz_attempts', '', 'uniqueid', 'integer', '10', 'unsigned', '0', 'not null', 'id');
-        // initially we can use the id as the unique id because no other modules use attempts yet.
-        execute_sql("UPDATE {$CFG->prefix}quiz_attempts SET uniqueid = id", false);
-        // we set $CFG->attemptuniqueid to the next available id
-        $record = get_record_sql("SELECT max(id)+1 AS nextid FROM {$CFG->prefix}quiz_attempts");
-        set_config('attemptuniqueid', empty($record->nextid) ? 1 : $record->nextid);
-    }
-    
-    if ($oldversion < 2006020801) {
-        // add new field to store time delay between the first and second quiz attempt
-        table_column('quiz', '', 'delay1', 'integer', '10', 'unsigned', '0', 'not null', 'popup');
-        // add new field to store time delay between the second and any additional quizes
-        table_column('quiz', '', 'delay2', 'integer', '10', 'unsigned', '0', 'not null', 'delay1');
-    }
-
-    if ($oldversion < 2006021101) {
-        // set defaultgrade field properly (probably not necessary, but better make sure)
-        execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '1' WHERE defaultgrade = '0'", false);
-        execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '0' WHERE qtype = '".DESCRIPTION."'", false);
-    }
-
-    if ($oldversion < 2006021103) {
-        // add new field to store the question-level shuffleanswers option
-        table_column('quiz_match', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'subquestions');
-        table_column('quiz_multichoice', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'single');
-        table_column('quiz_randomsamatch', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'choose');
-    }
-
-    if ($oldversion < 2006021104) {
-        // add originalversion field for the new versioning mechanism
-        table_column('quiz_question_versions', '', 'originalquestion', 'int', '10', 'unsigned', '0', 'not null', 'newquestion');
-    }
-
-    if ($oldversion < 2006021301) {
-        modify_database('','ALTER TABLE prefix_quiz_attempts ADD UNIQUE INDEX uniqueid (uniqueid);');
-    }
-
-    if ($oldversion < 2006021302) {
-        table_column('quiz_match_sub', '', 'code', 'int', '10', 'unsigned', '0', 'not null', 'id');
-        execute_sql("UPDATE {$CFG->prefix}quiz_match_sub SET code = id", false);
-    }
-    if ($oldversion < 2006021304) {
-        // convert sequence field to text to accomodate very long sequences, see bug 4257
-        table_column('quiz_multianswers', 'sequence', 'sequence',  'text', '', '', '', 'not null', 'question');
-    }
-
-    if ($oldversion < 2006021501) {
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_newest_states RENAME {$CFG->prefix}question_sessions", false);
-    }
-
-    if ($oldversion < 2006022200) {
-        // convert grade fields to float
-        set_field('quiz_attempts', 'sumgrades', 0, 'sumgrades', '');
-        table_column('quiz_attempts', 'sumgrades', 'sumgrades',  'float', '', '', '0', 'not null');
-
-        set_field('quiz_answers', 'fraction', 0, 'fraction', '');
-        table_column('quiz_answers', 'fraction', 'fraction',  'float', '', '', '0', 'not null');
-
-        set_field('quiz_essay_states', 'fraction', 0, 'fraction', '');
-        table_column('quiz_essay_states', 'fraction', 'fraction',  'float', '', '', '0', 'not null');
-
-        set_field('quiz_states', 'grade', 0, 'grade', '');
-        table_column('quiz_states', 'grade', 'grade',  'float', '', '', '0', 'not null');
-
-        set_field('quiz_states', 'raw_grade', 0, 'raw_grade', '');
-        table_column('quiz_states', 'raw_grade', 'raw_grade',  'float', '', '', '0', 'not null');
-
-        set_field('quiz_states', 'penalty', 0, 'penalty', '');
-        table_column('quiz_states', 'penalty', 'penalty',  'float', '', '', '0', 'not null');
-
-        set_field('question_sessions', 'sumpenalty', 0, 'sumpenalty', '');
-        table_column('question_sessions', 'sumpenalty', 'sumpenalty',  'float', '', '', '0', 'not null');
-    }
-
-    if ($oldversion < 2006022400) {
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_questions RENAME {$CFG->prefix}question", false);
-    }
-
-    if ($oldversion < 2006022402) {
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_states RENAME {$CFG->prefix}question_states", false);
-    }
-
-    if ($oldversion < 2006022800) {
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_answers RENAME {$CFG->prefix}question_answers", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_categories RENAME {$CFG->prefix}question_categories", false);
-    }
-
-    if ($oldversion < 2006031202) {
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_truefalse RENAME {$CFG->prefix}question_truefalse", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_shortanswer RENAME {$CFG->prefix}question_shortanswer", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_multianswers RENAME {$CFG->prefix}question_multianswer", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_multichoice RENAME {$CFG->prefix}question_multichoice", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_numerical RENAME {$CFG->prefix}question_numerical", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_numerical_units RENAME {$CFG->prefix}question_numerical_units", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_randomsamatch RENAME {$CFG->prefix}question_randomsamatch", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_match RENAME {$CFG->prefix}question_match", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_match_sub RENAME {$CFG->prefix}question_match_sub", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_calculated RENAME {$CFG->prefix}question_calculated", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_dataset_definitions RENAME {$CFG->prefix}question_dataset_definitions", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_dataset_items RENAME {$CFG->prefix}question_dataset_items", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_question_datasets RENAME {$CFG->prefix}question_datasets", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_rqp RENAME {$CFG->prefix}question_rqp", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_rqp_servers RENAME {$CFG->prefix}question_rqp_servers", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_rqp_states RENAME {$CFG->prefix}question_rqp_states", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_rqp_types RENAME {$CFG->prefix}question_rqp_types", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_essay RENAME {$CFG->prefix}question_essay", false);
-        execute_sql("ALTER TABLE {$CFG->prefix}quiz_essay_states RENAME {$CFG->prefix}question_essay_states", false);
-    }
-
-    if ($oldversion < 2006032100) {
-        // change from the old questiontype numbers to using the questiontype names
-        table_column('question', 'qtype', 'qtype',  'varchar', 20, '', '', 'not null');
-        set_field('question', 'qtype', 'shortanswer', 'qtype', 1);
-        set_field('question', 'qtype', 'truefalse', 'qtype', 2);
-        set_field('question', 'qtype', 'multichoice', 'qtype', 3);
-        set_field('question', 'qtype', 'random', 'qtype', 4);
-        set_field('question', 'qtype', 'match', 'qtype', 5);
-        set_field('question', 'qtype', 'randomsamatch', 'qtype', 6);
-        set_field('question', 'qtype', 'description', 'qtype', 7);
-        set_field('question', 'qtype', 'numerical', 'qtype', 8);
-        set_field('question', 'qtype', 'multianswer', 'qtype', 9);
-        set_field('question', 'qtype', 'calculated', 'qtype', 10);
-        set_field('question', 'qtype', 'rqp', 'qtype', 11);
-        set_field('question', 'qtype', 'essay', 'qtype', 12);
-    }
-
-    if ($oldversion < 2006032200) {
-        // set version for all questiontypes that already have their tables installed
-        set_config('qtype_calculated_version', 2006032100);
-        set_config('qtype_essay_version', 2006032100);
-        set_config('qtype_match_version', 2006032100);
-        set_config('qtype_multianswer_version', 2006032100);
-        set_config('qtype_multichoice_version', 2006032100);
-        set_config('qtype_numerical_version', 2006032100);
-        set_config('qtype_randomsamatch_version', 2006032100);
-        set_config('qtype_rqp_version', 2006032100);
-        set_config('qtype_shortanswer_version', 2006032100);
-        set_config('qtype_truefalse_version', 2006032100);
-    }
-
-    if ($oldversion < 2006040600) {
-        table_column('question_sessions', '', 'comment', 'text', '', '', '', 'not null', 'sumpenalty');
-    }
-
-    if ($oldversion < 2006040900) {
-        modify_database('', "UPDATE prefix_question SET parent = id WHERE qtype ='random';");
-    }
-
-    if ($oldversion < 2006041000) {
-        modify_database('', " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'continue attempt', 'quiz', 'name');");
-    }
-
-    if ($oldversion < 2006041001) {
-        table_column('question', 'version', 'version', 'varchar', 255);
-    }
-
-    if ($oldversion < 2006042800) {
-        // Check we have some un-renamed tables (verified in some servers)
-        if ($tables = $db->MetaTables('TABLES')) {
-            if (in_array($CFG->prefix.'quiz_randommatch', $tables) &&
-                !in_array($CFG->prefix.'question_randomsamatch', $tables)) {
-                modify_database ("", "ALTER TABLE prefix_quiz_randommatch RENAME prefix_question_randomsamatch ");
-            }
-            // Check for one possible missing field in one table
-            if ($columns = $db->MetaColumnNames($CFG->prefix.'question_randomsamatch')) {
-                if (!in_array('shuffleanswers', $columns)) {
-                    table_column('question_randomsamatch', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'choose');
-                }
-            }
-        }
-    }
-
-    if ($oldversion < 2006042801) {
-        // The newgraded field must always point to a valid state
-        modify_database("","UPDATE prefix_question_sessions SET newgraded = newest where newgraded = '0'");
-
-        // The following table is discussed in bug 5468
-        modify_database ("", "CREATE TABLE prefix_question_attempts (
-                                  id int(10) unsigned NOT NULL auto_increment,
-                                  modulename varchar(20) NOT NULL default 'quiz',
-                                  PRIMARY KEY  (id)
-                                ) TYPE=MyISAM COMMENT='Student attempts. This table gets extended by the modules';");
-        // create one entry for all the existing quiz attempts
-        modify_database ("", "INSERT INTO prefix_question_attempts (id)
-                                   SELECT uniqueid
-                                   FROM prefix_quiz_attempts;");
-    }
-
-    if ($oldversion < 2006060700) { // fix for 5720
-
-        // Copy the teacher comments from the question_essay_states table to the new
-        // question_sessions table.
-
-        // Get the attempt unique ID, teacher comment, graded flag, state ID, and question ID
-        // based on the quesiont_essay_states
-        if ($results = get_records_sql("SELECT a.uniqueid, es.response AS essaycomment, es.graded AS isgraded, 
-                                               qs.id AS stateid, qs.question AS questionid 
-                                        FROM {$CFG->prefix}question_states as qs,
-                                             {$CFG->prefix}question_essay_states es, 
-                                             {$CFG->prefix}quiz_attempts a 
-                                        WHERE es.stateid = qs.id AND a.uniqueid = qs.attempt")) {
-            foreach ($results as $result) {
-                // Create a state object to be used for updating
-                $state = new stdClass;
-                $state->id = $result->stateid;
-
-                if ($result->isgraded) {
-                    // Graded - save comment to the sessions and change state event to QUESTION_EVENTMANUALGRADE
-                    if (!set_field('question_sessions', 'comment', $result->essaycomment, 'attemptid', $result->uniqueid, 'questionid', $result->questionid)) {
-                        notify("Essay Table Migration: Cannot save comment");
-                    }
-                    $state->event = 9; //QUESTION_EVENTMANUALGRADE;
-                } else {
-                    // Not graded
-                    $state->event = 7; //QUESTION_EVENTSUBMIT;
-                }
-
-                // Save the event
-                if (!update_record('question_states', $state)) {
-                    notify("Essay Table Migration: Cannot update state");
-                }
-            }
-        }
-        
-        // dropping unused tables
-        execute_sql('DROP TABLE '.$CFG->prefix.'question_essay_states');
-        execute_sql('DROP TABLE '.$CFG->prefix.'question_essay');
-        execute_sql('DROP TABLE '.$CFG->prefix.'quiz_attemptonlast_datasets', false);
-    }
-
-
-    return true;
-}
-
-?>
+function quiz_upgrade($oldversion) {
+// This function does anything necessary to upgrade
+// older versions to match current functionality
+
+    global $CFG, $QTYPES, $db;
+    require_once("$CFG->dirroot/mod/quiz/locallib.php");
+
+    if ($oldversion < 2002101800) {
+        execute_sql(" ALTER TABLE `quiz_attempts` ".
+                    " ADD `timestart` INT(10) UNSIGNED DEFAULT '0' NOT NULL AFTER `sumgrades` , ".
+                    " ADD `timefinish` INT(10) UNSIGNED DEFAULT '0' NOT NULL AFTER `timestart` ");
+        execute_sql(" UPDATE `quiz_attempts` SET timestart = timemodified ");
+        execute_sql(" UPDATE `quiz_attempts` SET timefinish = timemodified ");
+    }
+    if ($oldversion < 2002102101) {
+        execute_sql(" DELETE FROM log_display WHERE module = 'quiz' ");
+        execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('quiz', 'view', 'quiz', 'name') ");
+        execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('quiz', 'report', 'quiz', 'name') ");
+        execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('quiz', 'attempt', 'quiz', 'name') ");
+        execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('quiz', 'submit', 'quiz', 'name') ");
+    }
+    if ($oldversion < 2002102600) {
+        execute_sql(" ALTER TABLE `quiz_answers` CHANGE `feedback` `feedback` TEXT NOT NULL ");
+    }
+
+    if ($oldversion < 2002122300) {
+        execute_sql("ALTER TABLE `quiz_grades` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
+        execute_sql("ALTER TABLE `quiz_attempts` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL ");
+    }
+
+    // prefixes required from here on, or use table_column()
+
+    if ($oldversion < 2003010100) {
+        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD review TINYINT(4) UNSIGNED DEFAULT '0' NOT NULL AFTER `grademethod` ");
+    }
+
+    if ($oldversion < 2003010301) {
+        table_column("quiz_truefalse", "true", "trueanswer", "INTEGER", "10", "UNSIGNED", "0", "NOT NULL", "");
+        table_column("quiz_truefalse", "false", "falseanswer", "INTEGER", "10", "UNSIGNED", "0", "NOT NULL", "");
+        table_column("quiz_questions", "type", "qtype", "INTEGER", "10", "UNSIGNED", "0", "NOT NULL", "");
+    }
+
+    if ($oldversion < 2003022303) {
+        modify_database ("", "CREATE TABLE `prefix_quiz_randommatch` (
+                             `id` int(10) unsigned NOT NULL auto_increment,
+                             `question` int(10) unsigned NOT NULL default '0',
+                             `choose` INT UNSIGNED DEFAULT '4' NOT NULL,
+                             PRIMARY KEY ( `id` )
+                          );");
+    }
+
+    if ($oldversion < 2003030303) {
+        table_column("quiz_questions", "", "defaultgrade", "INTEGER", "6", "UNSIGNED", "1", "NOT NULL", "image");
+    }
+
+    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) ");
+        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_grades` ADD INDEX(quiz) ");
+        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_grades` ADD INDEX(userid) ");
+        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_question_grades` ADD INDEX(quiz) ");
+        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_question_grades` ADD INDEX(question) ");
+        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_randommatch` ADD INDEX(question) ");
+        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_responses` ADD INDEX(attempt) ");
+        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz_responses` ADD INDEX(question) ");
+    }
+
+    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,
+                             `question` int(10) unsigned NOT NULL default '0',
+                             `subquestions` varchar(255) NOT NULL default '',
+                             PRIMARY KEY  (`id`),
+                             KEY `question` (`question`)
+                           );");
+
+        modify_database ("", "CREATE TABLE `prefix_quiz_match_sub` (
+                             `id` int(10) unsigned NOT NULL auto_increment,
+                             `question` int(10) unsigned NOT NULL default '0',
+                             `questiontext` text NOT NULL,
+                             `answertext` varchar(255) NOT NULL default '',
+                             PRIMARY KEY  (`id`),
+                             KEY `question` (`question`)
+                           );");
+    }
+
+    if ($oldversion < 2003040901) {
+        table_column("quiz", "", "shufflequestions", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "review");
+        table_column("quiz", "", "shuffleanswers", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "shufflequestions");
+    }
+
+    if ($oldversion < 2003071001) {
+
+        modify_database ("", " CREATE TABLE `prefix_quiz_numerical` (
+                               `id` int(10) unsigned NOT NULL auto_increment,
+                               `question` int(10) unsigned NOT NULL default '0',
+                               `answer` int(10) unsigned NOT NULL default '0',
+                               `min` varchar(255) NOT NULL default '',
+                               `max` varchar(255) NOT NULL default '',
+                               PRIMARY KEY  (`id`),
+                               KEY `answer` (`answer`)
+                             ) TYPE=MyISAM COMMENT='Options for numerical questions'; ");
+    }
+
+    if ($oldversion < 2003072400) {
+        execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('quiz', 'review', 'quiz', 'name') ");
+    }
+
+    if ($oldversion < 2003072901) {
+        modify_database ("", " CREATE TABLE `prefix_quiz_multianswers` (
+                               `id` int(10) unsigned NOT NULL auto_increment,
+                                `question` int(10) unsigned NOT NULL default '0',
+                                `answers` varchar(255) NOT NULL default '',
+                                `positionkey` varchar(255) NOT NULL default '',
+                                `answertype` smallint(6) NOT NULL default '0',
+                                `norm` int(10) unsigned NOT NULL default '1',
+                                PRIMARY KEY  (`id`),
+                                KEY `question` (`question`)
+                              ) TYPE=MyISAM COMMENT='Options for multianswer questions'; ");
+    }
+
+    if ($oldversion < 2003080301) {
+        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD eachattemptbuildsonthelast TINYINT(4) DEFAULT '0' NOT NULL AFTER `attempts` ");
+    }
+
+    if ($oldversion < 2003080400) {
+        table_column("quiz", "eachattemptbuildsonthelast", "attemptonlast", "TINYINT", "4", "UNSIGNED", "0", "NOT NULL", "");
+    }
+
+    if ($oldversion < 2003082300) {
+        table_column("quiz_questions", "", "stamp", "varchar", "255", "", "", "not null", "qtype");
+    }
+
+    if ($oldversion < 2003082301) {
+        table_column("quiz_questions", "stamp", "stamp", "varchar", "255", "", "", "not null");
+        table_column("quiz_questions", "", "version", "integer", "10", "", "1", "not null", "stamp");
+        if ($questions = get_records("quiz_questions")) {
+            foreach ($questions as $question) {
+                $stamp = make_unique_id_code();
+                if (!set_field("quiz_questions", "stamp", $stamp, "id", $question->id)) {
+                    notify("Error while adding stamp to question id = $question->id");
+                }
+            }
+        }
+    }
+
+    if ($oldversion < 2003082700) {
+        table_column("quiz_categories", "", "stamp", "varchar", "255", "", "", "not null");
+        if ($categories = get_records("quiz_categories")) {
+            foreach ($categories as $category) {
+                $stamp = make_unique_id_code();
+                if (!set_field("quiz_categories", "stamp", $stamp, "id", $category->id)) {
+                    notify("Error while adding stamp to category id = $category->id");
+                }
+            }
+        }
+    }
+
+    if ($oldversion < 2003111100) {
+        $duplicates = get_records_sql("SELECT stamp as id,count(*) as cuenta
+                                       FROM {$CFG->prefix}quiz_questions
+                                       GROUP BY stamp
+                                       HAVING count(*)>1");
+
+        if ($duplicates) {
+            notify("You have some quiz questions with duplicate stamps IDs.  Cleaning these up.");
+            foreach ($duplicates as $duplicate) {
+                $questions = get_records("quiz_questions","stamp",$duplicate->id);
+                $add = 1;
+                foreach ($questions as $question) {
+                    echo "Changing question id $question->id stamp to ".$duplicate->id.$add."<br />";
+                    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");
+        }
+    }
+
+    if ($oldversion < 2004021300) {
+        table_column("quiz_questions", "", "questiontextformat", "integer", "2", "", "0", "not null", "questiontext");
+    }
+
+    if ($oldversion < 2004021900) {
+        modify_database("","INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'add', 'quiz', 'name');");
+        modify_database("","INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'update', 'quiz', 'name');");
+    }
+
+    if ($oldversion < 2004051700) {
+        include_once("$CFG->dirroot/mod/quiz/lib.php");
+        quiz_refresh_events();
+    }
+
+    if ($oldversion < 2004060200) {
+        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD timelimit INT(2) UNSIGNED DEFAULT '0' NOT NULL ");
+    }
+
+    if ($oldversion < 2004070700) {
+        table_column("quiz", "", "password", "varchar", "255", "", "", "not null", "");
+        table_column("quiz", "", "subnet", "varchar", "255", "", "", "not null", "");
+    }
+
+    if ($oldversion < 2004073001) {
+        // Six new tables:
+
+        // One table for handling units for numerical questions
+        modify_database ("", " CREATE TABLE `prefix_quiz_numerical_units` (
+                               `id` int(10) unsigned NOT NULL auto_increment,
+                               `question` int(10) unsigned NOT NULL default '0',
+                               `multiplier` decimal(40,20) NOT NULL default '1.00000000000000000000',
+                               `unit` varchar(50) NOT NULL default '',
+                               PRIMARY KEY  (`id`)
+                ) TYPE=MyISAM COMMENT='Optional unit options for numerical questions'; ");
+
+        // Four tables for handling distribution and storage of
+        // individual data for dataset dependent question types
+        modify_database ("", " CREATE TABLE `prefix_quiz_attemptonlast_datasets` (
+                               `id` int(10) unsigned NOT NULL auto_increment,
+                               `category` int(10) unsigned NOT NULL default '0',
+                               `userid` int(10) unsigned NOT NULL default '0',
+                               `datasetnumber` int(10) unsigned NOT NULL default '0',
+                               PRIMARY KEY  (`id`),
+                               UNIQUE KEY `category` (`category`,`userid`)
+            ) TYPE=MyISAM COMMENT='Dataset number for attemptonlast attempts per user'; ");
+        modify_database ("", " CREATE TABLE `prefix_quiz_dataset_definitions` (
+                               `id` int(10) unsigned NOT NULL auto_increment,
+                               `category` int(10) unsigned NOT NULL default '0',
+                               `name` varchar(255) NOT NULL default '',
+                               `type` int(10) NOT NULL default '0',
+                               `options` varchar(255) NOT NULL default '',
+                               `itemcount` int(10) unsigned NOT NULL default '0',
+                               PRIMARY KEY  (`id`)
+            ) TYPE=MyISAM COMMENT='Organises and stores properties for dataset items'; ");
+        modify_database ("", " CREATE TABLE `prefix_quiz_dataset_items` (
+                               `id` int(10) unsigned NOT NULL auto_increment,
+                               `definition` int(10) unsigned NOT NULL default '0',
+                               `number` int(10) unsigned NOT NULL default '0',
+                               `value` varchar(255) NOT NULL default '',
+                               PRIMARY KEY  (`id`),
+                               KEY `definition` (`definition`)
+                             ) TYPE=MyISAM COMMENT='Individual dataset items'; ");
+        modify_database ("", " CREATE TABLE `prefix_quiz_question_datasets` (
+                               `id` int(10) unsigned NOT NULL auto_increment,
+                               `question` int(10) unsigned NOT NULL default '0',
+                               `datasetdefinition` int(10) unsigned NOT NULL default '0',
+                               PRIMARY KEY  (`id`),
+                               KEY `question` (`question`,`datasetdefinition`)
+            ) TYPE=MyISAM COMMENT='Many-many relation between questions and dataset definitions'; ");
+
+        // One table for new question type calculated
+        //  - the first dataset dependent question type
+        modify_database ("", " CREATE TABLE `prefix_quiz_calculated` (
+                               `id` int(10) unsigned NOT NULL auto_increment,
+                               `question` int(10) unsigned NOT NULL default '0',
+                               `answer` int(10) unsigned NOT NULL default '0',
+                               `tolerance` varchar(20) NOT NULL default '0.0',
+                               `tolerancetype` int(10) NOT NULL default '1',
+                               `correctanswerlength` int(10) NOT NULL default '2',
+                               PRIMARY KEY  (`id`),
+                               KEY `question` (`question`)
+                ) TYPE=MyISAM COMMENT='Options for questions of type calculated'; ");
+    }
+
+    if ($oldversion < 2004111400) {
+        table_column("quiz_responses", "answer", "answer", "text", "", "", "", "not null");
+    }
+
+    if ($oldversion < 2004111700) {
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz DROP INDEX course;",false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_calculated DROP INDEX answer;",false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_categories DROP INDEX course;",false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_dataset_definitions DROP INDEX category;",false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_numerical DROP INDEX question;",false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_numerical_units DROP INDEX question;",false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_questions DROP INDEX category;",false);
+
+        modify_database('','ALTER TABLE prefix_quiz ADD INDEX course (course);');
+        modify_database('','ALTER TABLE prefix_quiz_calculated ADD INDEX answer (answer);');
+        modify_database('','ALTER TABLE prefix_quiz_categories ADD INDEX course (course);');
+        modify_database('','ALTER TABLE prefix_quiz_dataset_definitions ADD INDEX category (category);');
+        modify_database('','ALTER TABLE prefix_quiz_numerical ADD INDEX question (question);');
+        modify_database('','ALTER TABLE prefix_quiz_numerical_units ADD INDEX question (question);');
+        modify_database('','ALTER TABLE prefix_quiz_questions ADD INDEX category (category);');
+    }
+
+    if ($oldversion < 2004120501) {
+        table_column("quiz_calculated", "", "correctanswerformat", "integer", "10", "", "2", "not null", "correctanswerlength");
+    }
+
+    if ($oldversion < 2004121400) {  // New field to determine popup window behaviour
+        table_column("quiz", "", "popup", "integer", "4", "", "0", "not null", "subnet");
+    }
+
+    if ($oldversion < 2005010201) {
+        table_column('quiz_categories', '', 'parent');
+        table_column('quiz_categories', '', 'sortorder', 'integer', '10', '', '999');
+    }
+
+    if ($oldversion < 2005010300) {
+        table_column("quiz", "", "questionsperpage", "integer", "10", "", "0", "not null", "review");
+    }
+
+    if ($oldversion < 2005012700) {
+        table_column('quiz_grades', 'grade', 'grade', 'real', 2, '');
+    }
+
+    if ($oldversion < 2005021400) {
+        table_column("quiz", "", "decimalpoints", "integer", "4", "", "2", "not null", "grademethod");
+    }
+
+    if($oldversion < 2005022800) {
+        table_column('quiz_questions', '', 'hidden', 'integer', '1', 'unsigned', '0', 'not null', 'version');
+        table_column('quiz_responses', '', 'originalquestion', 'integer', '10', 'unsigned', '0', 'not null', 'question');
+        modify_database ('', "CREATE TABLE `prefix_quiz_question_version` (
+                              `id` int(10) unsigned NOT NULL auto_increment,
+                              `quiz` int(10) unsigned NOT NULL default '0',
+                              `oldquestion` int(10) unsigned NOT NULL default '0',
+                              `newquestion` int(10) unsigned NOT NULL default '0',
+                              `userid` int(10) unsigned NOT NULL default '0',
+                              `timestamp` int(10) unsigned NOT NULL default '0',
+                              PRIMARY KEY  (`id`)
+                            ) TYPE=MyISAM COMMENT='The mapping between old and new versions of a question';");
+    }
+
+    if ($oldversion < 2005032000) {
+        execute_sql(" INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('quiz', 'editquestions', 'quiz', 'name') ");
+    }
+
+    if ($oldversion < 2005032300) {
+        modify_database ('', 'ALTER TABLE prefix_quiz_question_version RENAME prefix_quiz_question_versions;');
+    }
+
+    if ($oldversion < 2005041200) { // replace wiki-like with markdown
+        include_once( "$CFG->dirroot/lib/wiki_to_markdown.php" );
+        $wtm = new WikiToMarkdown();
+        $sql = "select course from {$CFG->prefix}quiz_categories c, {$CFG->prefix}quiz_questions q ";
+        $sql .= "where c.id = q.category ";
+        $sql .= "and q.id = ";
+        $wtm->update( 'quiz_questions', 'questiontext', 'questiontextformat', $sql );
+    }
+
+    if ($oldversion < 2005041304) {
+        // make random questions hidden
+        modify_database('', "UPDATE prefix_quiz_questions SET hidden = '1' WHERE qtype ='".RANDOM."';");
+    }
+
+    if ($oldversion < 2005042002) {
+        table_column('quiz_answers', 'answer', 'answer', 'text', '', '', '', 'not null', '');
+    }
+
+    if ($oldversion < 2005042400) {
+
+    // Changes to quiz table
+
+        // The bits of the optionflags field will hold various option flags
+        table_column('quiz', '', 'optionflags', 'integer', '10', 'unsigned', '0', 'not null', 'timeclose');
+
+        // The penalty scheme
+        table_column('quiz', '', 'penaltyscheme', 'integer', '4', 'unsigned', '0', 'not null', 'optionflags');
+
+        // The review options are now all stored in the bits of the review field
+        table_column('quiz', 'review', 'review', 'integer', 10, 'unsigned', 0, 'not null', '');
+
+    /// Changes to quiz_attempts table
+
+        // The preview flag marks teacher previews
+        table_column('quiz_attempts', '', 'preview', 'tinyint', '2', 'unsigned', '0', 'not null', 'timemodified');
+
+        // The layout is the list of questions with inserted page breaks.
+        table_column('quiz_attempts', '', 'layout', 'text', '', '', '', 'not null', 'timemodified');
+        // For old quiz attempts we will set this to the repaginated question list from $quiz->questions
+
+    /// The following updates of field values require a loop through all quizzes
+        // This is because earlier versions of mysql don't allow joins in UPDATE
+        if ($quizzes = get_records('quiz')) {
+
+            // turn reporting off temporarily to avoid one line output per set_field
+            $olddebug = $db->debug;
+            $db->debug = false;
+            echo 'Now updating '.count($quizzes).' quizzes';
+            foreach ($quizzes as $quiz) {
+
+                // repaginate
+                if ($quiz->questionsperpage) {
+                    $quiz->questions = quiz_repaginate($quiz->questions, $quiz->questionsperpage);
+                    set_field('quiz', 'questions', $quiz->questions, 'id', $quiz->id);
+                }
+                set_field('quiz_attempts', 'layout', $quiz->questions, 'quiz', $quiz->id);
+
+                // set preview flag
+                if ($teachers = get_course_teachers($quiz->course)) {
+                    $teacherids = implode(',', array_keys($teachers));
+                    execute_sql("UPDATE {$CFG->prefix}quiz_attempts SET preview = 1 WHERE userid IN ($teacherids)");
+                }
+
+                // set review flags in quiz table
+                $review = (QUIZ_REVIEW_IMMEDIATELY & (QUIZ_REVIEW_RESPONSES + QUIZ_REVIEW_SCORES));
+                if ($quiz->feedback) {
+                    $review += (QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_FEEDBACK);
+                }
+                if ($quiz->correctanswers) {
+                    $review += (QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_ANSWERS);
+                }
+                if ($quiz->review & 1) {
+                    $review += QUIZ_REVIEW_CLOSED;
+                }
+                if ($quiz->review & 2) {
+                    $review += QUIZ_REVIEW_OPEN;
+                }
+                set_field('quiz', 'review', $review, 'id', $quiz->id);
+            }
+            $db->debug = $olddebug;
+        }
+
+        // We can now drop the fields whose data has been moved to the review field
+        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz` DROP feedback");
+        execute_sql(" ALTER TABLE `{$CFG->prefix}quiz` DROP correctanswers");
+
+    /// Renaming tables
+
+        // rename the quiz_question_grades table to quiz_question_instances
+        modify_database ('', 'ALTER TABLE prefix_quiz_question_grades RENAME prefix_quiz_question_instances;');
+
+        // rename the quiz_responses table quiz_states
+        modify_database ('', 'ALTER TABLE prefix_quiz_responses RENAME prefix_quiz_states;');
+
+    /// add columns to quiz_states table
+
+        // The sequence number of the state.
+        table_column('quiz_states', '', 'seq_number', 'integer', '6', 'unsigned', '0', 'not null', 'originalquestion');
+        // For existing states we leave this at 0 because in the old quiz code there was only one response allowed
+
+        // The time the state was created.
+        table_column('quiz_states', '', 'timestamp', 'integer', '10', 'unsigned', '0', 'not null', 'answer');
+        // For existing states we will below set this to the timemodified field of the attempt
+
+        // The type of event that led to the creation of the state
+        table_column('quiz_states', '', 'event', 'integer', '4', 'unsigned', '0', 'not null', 'timestamp');
+
+        // The raw grade
+        table_column('quiz_states', '', 'raw_grade', 'varchar', '10', '', '', 'not null', 'grade');
+        // For existing states (no penalties) this is equal to the grade
+        execute_sql("UPDATE {$CFG->prefix}quiz_states SET raw_grade = grade");
+
+        // The penalty that the response attracted
+        table_column('quiz_states', '', 'penalty', 'varchar', '10', '', '0.0', 'not null', 'raw_grade');
+        // For existing states this can stay at 0 because penalties did not exist previously.
+
+    /// New table for pointers to newest and newest graded states
+
+        modify_database('', "CREATE TABLE `prefix_quiz_newest_states` (
+                             `id` int(10) unsigned NOT NULL auto_increment,
+                             `attemptid` int(10) unsigned NOT NULL default '0',
+                             `questionid` int(10) unsigned NOT NULL default '0',
+                             `new` int(10) unsigned NOT NULL default '0',
+                             `newgraded` int(10) unsigned NOT NULL default '0',
+                             `sumpenalty` varchar(10) NOT NULL default '0.0',
+                             PRIMARY KEY  (`id`),
+                             UNIQUE KEY `attemptid` (`attemptid`,`questionid`)
+                           ) TYPE=MyISAM COMMENT='Gives ids of the newest open and newest graded states';");
+
+    /// Now upgrade some fields in states and newest_states tables where necessary
+        // to save time on large sites only do this for attempts that have not yet been finished.
+        if ($attempts = get_records_select('quiz_attempts', 'timefinish = 0')) {
+            echo 'Update the states for the '.count($attempts).' open attempts';
+            // turn reporting off temporarily to avoid one line output per set_field
+            $olddebug = $db->debug;
+            $db->debug = false;
+            foreach ($attempts as $attempt) {
+                quiz_upgrade_states($attempt);
+            }
+            $db->debug = $olddebug;
+        }
+
+    /// Entries for the log_display table
+
+        modify_database('', " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'preview', 'quiz', 'name');");
+        modify_database('', " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'start attempt', 'quiz', 'name');");
+        modify_database('', " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'close attempt', 'quiz', 'name');");
+
+    /// update the default settings in $CFG
+        $review = (QUIZ_REVIEW_IMMEDIATELY & (QUIZ_REVIEW_RESPONSES + QUIZ_REVIEW_SCORES));
+        if (!empty($CFG->quiz_feedback)) {
+            $review += (QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_FEEDBACK);
+        }
+        if (!empty($CFG->quiz_correctanswers)) {
+            $review += (QUIZ_REVIEW_IMMEDIATELY & QUIZ_REVIEW_ANSWERS);
+        }
+        if (isset($CFG->quiz_review) and ($CFG->quiz_review & 1)) {
+            $review += QUIZ_REVIEW_CLOSED;
+        }
+        if (isset($CFG->quiz_review) and ($CFG->quiz_review & 2)) {
+            $review += QUIZ_REVIEW_OPEN;
+        }
+        set_config('quiz_review', $review);
+
+    /// Use tolerance instead of min and max in numerical question type
+        table_column('quiz_numerical', '', 'tolerance', 'varchar', '255', '', '0.0', 'not null', 'answer');
+        execute_sql("UPDATE {$CFG->prefix}quiz_numerical SET tolerance = (max-min)/2");
+        modify_database('', 'ALTER TABLE `prefix_quiz_numerical` DROP `min`'); // Replaced by tolerance
+        modify_database('', 'ALTER TABLE `prefix_quiz_numerical` DROP `max`'); // Replaced by tolerance
+
+    /// Tables for Remote Questions
+        modify_database ('', "CREATE TABLE `prefix_quiz_rqp` (
+                              `id` int(10) unsigned NOT NULL auto_increment,
+                              `question` int(10) unsigned NOT NULL default '0',
+                              `type` int(10) unsigned NOT NULL default '0',
+                              `source` longblob NOT NULL default '',
+                              `format` varchar(255) NOT NULL default '',
+                              `flags` tinyint(3) unsigned NOT NULL default '0',
+                              `maxscore` int(10) unsigned NOT NULL default '1',
+                              PRIMARY KEY  (`id`),
+                              KEY `question` (`question`)
+                              ) TYPE=MyISAM COMMENT='Options for RQP questions';");
+
+        modify_database ('', "CREATE TABLE `prefix_quiz_rqp_type` (
+                              `id` int(10) unsigned NOT NULL auto_increment,
+                              `name` varchar(255) NOT NULL default '',
+                              `rendering_server` varchar(255) NOT NULL default '',
+                              `cloning_server` varchar(255) NOT NULL default '',
+                              `flags` tinyint(3) NOT NULL default '0',
+                              PRIMARY KEY  (`id`),
+                              UNIQUE KEY `name` (`name`)
+                              ) TYPE=MyISAM COMMENT='RQP question types and the servers to be used to process them';");
+
+        modify_database ('', "CREATE TABLE `prefix_quiz_rqp_states` (
+                              `id` int(10) unsigned NOT NULL auto_increment,
+                              `stateid` int(10) unsigned NOT NULL default '0',
+                              `responses` text NOT NULL default '',
+                              `persistent_data` text NOT NULL default '',
+                              `template_vars` text NOT NULL default '',
+                              PRIMARY KEY  (`id`)
+                              ) TYPE=MyISAM COMMENT='RQP question type specific state information';");
+    }
+
+    if ($oldversion < 2005050300) {
+        // length of question determines question numbering. Currently all questions require one
+        // question number except for DESCRIPTION questions.
+        table_column('quiz_questions', '', 'length', 'integer', '10', 'unsigned', '1', 'not null', 'qtype');
+        execute_sql("UPDATE {$CFG->prefix}quiz_questions SET length = 0 WHERE qtype = ".DESCRIPTION);
+    }
+
+    if ($oldversion < 2005050408) {
+        table_column('quiz_questions', '', 'penalty', 'float', '', '', '0.1', 'not null', 'defaultgrade');
+        table_column('quiz_newest_states', 'new', 'newest', 'integer', '10', 'unsigned', '0', 'not null');
+    }
+
+    if ($oldversion < 2005051400) {
+        modify_database('', 'ALTER TABLE prefix_quiz_rqp_type RENAME prefix_quiz_rqp_types;');
+    	modify_database('', "CREATE TABLE `prefix_quiz_rqp_servers` (
+    			      id int(10) unsigned NOT NULL auto_increment,
+    			      typeid int(10) unsigned NOT NULL default '0',
+    			      url varchar(255) NOT NULL default '',
+    			      can_render tinyint(2) unsigned NOT NULL default '0',
+    			      can_author tinyint(2) unsigned NOT NULL default '0',
+    			      PRIMARY KEY  (id)
+    			    ) TYPE=MyISAM COMMENT='Information about RQP servers';");
+    	if ($types = get_records('quiz_rqp_types')) {
+    	    foreach($types as $type) {
+        		$server->typeid = $type->id;
+        		$server->url = $type->rendering_server;
+        		$server->can_render = 1;
+        		insert_record('quiz_rqp_servers', $server);
+    	    }
+    	}
+        modify_database('', 'ALTER TABLE prefix_quiz_rqp_types DROP rendering_server');
+        modify_database('', 'ALTER TABLE prefix_quiz_rqp_types DROP cloning_server');
+        modify_database('', 'ALTER TABLE prefix_quiz_rqp_types DROP flags');
+    }
+
+    if ($oldversion < 2005051401) {
+        // Some earlier changes are undone here, so we need another condition
+        if ($oldversion >= 2005042900) {
+            // Restore the answer field
+            table_column('quiz_numerical', '', 'answer', 'integer', '10', 'unsigned', '0', 'not null', 'answers');
+            $singleanswer = array();
+            if ($numericals = get_records('quiz_numerical')) {
+                $numericals = array_values($numericals);
+                $n = count($numericals);
+                for ($i = 0; $i < $n; $i++) {
+                    $numerical =& $numericals[$i];
+                    if (strpos($numerical->answers, ',')) { // comma separated list?
+                        // Back this up to delete the record after the new ones are created
+                        $id = $numerical->id;
+                        unset($numerical->id);
+                        // We need to create a record for each answer id
+                        $answers = explode(',', $numerical->answers);
+                        foreach ($answers as $answer) {
+                            $numerical->answer = $answer;
+                            insert_record('quiz_numerical', $numerical);
+                        }
+                        // ... and get rid of the old record
+                        delete_records('quiz_numerical', 'id', $id);
+                    } else {
+                        $singleanswer[] = $numerical->id;
+                    }
+                }
+            }
+
+            // Do all of these at once
+            if (!empty($singleanswer)) {
+                $singleanswer = implode(',', $singleanswer);
+                modify_database('', "UPDATE prefix_quiz_numerical SET answer = answers WHERE id IN ($singleanswer);");
+            }
+
+            // All answer fields are set, so we can delete the answers field
+            modify_database('', 'ALTER TABLE `prefix_quiz_numerical` DROP `answers`');
+
+        // If the earlier changes weren't made we can safely do only the
+        // bits here.
+        } else {
+            // Comma separated questionids will be stored as sequence
+            table_column('quiz_multianswers', '', 'sequence',  'varchar', '255', '', '', 'not null', 'question');
+            // Change the type of positionkey to int, so that the sorting works!
+            table_column('quiz_multianswers', 'positionkey', 'positionkey',  'integer', '10', 'unsigned', '0', 'not null', '');
+            table_column('quiz_questions', '', 'parent', 'integer', '10', 'unsigned', '0', 'not null', 'category');
+            modify_database('', "UPDATE prefix_quiz_questions SET parent = id WHERE qtype ='".RANDOM."';");
+
+            // Each multianswer record is converted to a question object and then
+            // inserted as a new question into the quiz_questions table.
+            // After that the question fields in the quiz_answers table and the
+            // qtype specific tables are updated to point to the new question id.
+            // Note: The quiz_numerical table is different as it stores one record
+            //       per defined answer (to allow different tolerance values for
+            //       different possible answers. (Currently multiple answers are
+            //       not supported by the numerical editing interface, but
+            //       all processing code does support that possibility.
+            if ($multianswers = get_records_sql("SELECT m.id, q.category, " .
+                                            "q.id AS parent, " . // question id (of multianswer question) as parent
+                                            "q.name, q.questiontextformat, " .
+                                            "m.norm AS defaultgrade, " . // norm is snow stored as defaultgrade
+                                            "m.answertype AS qtype, " .  // just rename this
+                                            "q.version, q.hidden, m.answers, " .
+                                            "m.positionkey " .
+                                            "FROM {$CFG->prefix}quiz_questions q, " .
+                                            "     {$CFG->prefix}quiz_multianswers m " .
+                                            "WHERE q.qtype = '".MULTIANSWER."' " .
+                                            "AND   q.id = m.question " .
+                                            "ORDER BY q.id ASC, m.positionkey ASC")) { // ordered by positionkey
+                $multianswers = array_values($multianswers);
+                $n        = count($multianswers);
+                $parent   = $multianswers[0]->parent;
+                $sequence = array();
+                $positions = array();
+
+                // Turn reporting off temporarily to avoid one line output per set_field
+                global $db;
+                $olddebug = $db->debug;
+                $db->debug = false;
+                echo 'Now updating '.$n.' cloze questions.';
+                for ($i = 0; $i < $n; $i++) {
+                    // Backup these two values before unsetting the object fields
+                    $answers = $multianswers[$i]->answers; unset($multianswers[$i]->answers);
+                    $pos = $multianswers[$i]->positionkey; unset($multianswers[$i]->positionkey);
+
+                    // Needed for substituting multianswer ids with position keys in the $state->answer field
+                    $positions[$multianswers[$i]->id] = $pos;
+
+                // Create questions for all the multianswer victims
+                    unset($multianswers[$i]->id);
+                    $multianswers[$i]->length = 0;
+                    $multianswers[$i]->questiontext = '';
+                    $multianswers[$i]->stamp = make_unique_id_code();
+                    $multianswers[$i]->name = addslashes($multianswers[$i]->name);
+                    // $multianswers[$i]->parent is set in the query
+                    // $multianswers[$i]->defaultgrade is set in the query
+                    // $multianswers[$i]->qtype is set in the query
+                    $id = insert_record('quiz_questions', $multianswers[$i]);
+                    $sequence[$pos] = $id;
+
+                // Update the quiz_answers table to point to these new questions
+                execute_sql("UPDATE {$CFG->prefix}quiz_answers SET question = '$id' WHERE id IN ($answers)", false);
+                // Update the questiontype tables to point to these new questions
+
+                    if (SHORTANSWER == $multianswers[$i]->qtype) {
+                        execute_sql("UPDATE {$CFG->prefix}quiz_shortanswer SET question = '$id' WHERE answers = '$answers'", false);
+                    } else if (MULTICHOICE == $multianswers[$i]->qtype) {
+                        execute_sql("UPDATE {$CFG->prefix}quiz_multichoice SET question = '$id' WHERE answers = '$answers'", false);
+                    } else if (NUMERICAL == $multianswers[$i]->qtype) {
+                        execute_sql("UPDATE {$CFG->prefix}quiz_numerical SET question = '$id' WHERE answer IN ($answers)", false);
+                    }
+
+                    // Whenever we're through with the subquestions of one multianswer
+                    // question we delete the old records in the multianswers table,
+                    // store a new record with the sequence in the multianswers table
+                    // and point $parent to the next multianswer question.
+                    if (!isset($multianswers[$i+1]) || $parent != $multianswers[$i+1]->parent) {
+
+                        // Substituting multianswer ids with position keys in the $state->answer field
+                        if ($states = get_records('quiz_states', 'question', $parent)) {
+                            foreach ($states as $state) {
+                                $reg = array();
+                                preg_match_all('/(?:^|,)([0-9]+)-([^,]*)/', $state->answer, $reg);
+                                $state->answer = '';
+                                $m = count($reg[1]);
+                                for ($j = 0; $j < $m; $j++) {
+                                    if (isset($positions[$reg[1][$j]])) {
+                                        $state->answer .= $positions[$reg[1][$j]] . '-' . $reg[2][$j] . ',';
+                                    } else {
+                                        notify("Undefined multianswer id ({$reg[1][$j]}) used in state #{$state->id}!");
+                                        $state->answer .= $j+1 . '-' . $reg[2][$j] . ',';
+                                    }
+                                }
+                                $state->answer = rtrim($state->answer, ','); // strip trailing comma
+                                update_record('quiz_states', $state);
+                            }
+                        }
+
+                        delete_records('quiz_multianswers', 'question', $parent);
+                        $multi = new stdClass;
+                        $multi->question = $parent;
+                        $multi->sequence = implode(',', $sequence);
+                        insert_record('quiz_multianswers', $multi);
+
+                        if (isset($multianswers[$i+1])) {
+                            $parent    = $multianswers[$i+1]->parent;
+                            $sequence  = array();
+                            $positions = array();
+                        }
+                    }
+                }
+                $db->debug = $olddebug;
+            }
+
+            // Remove redundant fields from quiz_multianswers
+            modify_database('', 'ALTER TABLE `prefix_quiz_multianswers` DROP `answers`');
+            modify_database('', 'ALTER TABLE `prefix_quiz_multianswers` DROP `positionkey`');
+            modify_database('', 'ALTER TABLE `prefix_quiz_multianswers` DROP `answertype`');
+            modify_database('', 'ALTER TABLE `prefix_quiz_multianswers` DROP `norm`');
+        }
+    }
+
+    if ($oldversion < 2005052004) {
+        // We need to remove some duplicate entries that may be present in some databases
+        // due to a faulty restore script
+
+        // Remove duplicate entries from quiz_numerical
+        if ($dups = get_records_sql("
+                SELECT question, answer, count(*) as num
+                FROM {$CFG->prefix}quiz_numerical
+                GROUP BY question, answer
+                HAVING count(*) > 1"
+            )) {
+            foreach ($dups as $dup) {
+                $ids = get_records_sql("
+                    SELECT id, id
+                    FROM {$CFG->prefix}quiz_numerical
+                    WHERE question = '$dup->question'
+                    AND answer = '$dup->answer'"
+                );
+                $skip = true;
+                foreach ($ids as $id) {
+                    if ($skip) {
+                        $skip = false;
+                    } else {
+                        delete_records('quiz_numerical','id', $id->id);
+                    }
+                }
+            }
+        }
+
+        // Remove duplicate entries from quiz_shortanswer
+        if ($dups = get_records_sql("
+                SELECT question, answers, count(*) as num
+                FROM {$CFG->prefix}quiz_shortanswer
+                GROUP BY question, answers
+                HAVING count(*) > 1"
+            )) {
+            foreach ($dups as $dup) {
+                $ids = get_records_sql("
+                    SELECT id, id
+                    FROM {$CFG->prefix}quiz_shortanswer
+                    WHERE question = '$dup->question'
+                    AND answers = '$dup->answers'"
+                );
+                $skip = true;
+                foreach ($ids as $id) {
+                    if ($skip) {
+                        $skip = false;
+                    } else {
+                        delete_records('quiz_shortanswer','id', $id->id);
+                    }
+                }
+            }
+        }
+
+        // Remove duplicate entries from quiz_multichoice
+        if ($dups = get_records_sql("
+                SELECT question, answers, count(*) as num
+                FROM {$CFG->prefix}quiz_multichoice
+                GROUP BY question, answers
+                HAVING count(*) > 1"
+            )) {
+            foreach ($dups as $dup) {
+                $ids = get_records_sql("
+                    SELECT id, id
+                    FROM {$CFG->prefix}quiz_multichoice
+                    WHERE question = '$dup->question'
+                    AND answers = '$dup->answers'"
+                );
+                $skip = true;
+                foreach ($ids as $id) {
+                    if ($skip) {
+                        $skip = false;
+                    } else {
+                        delete_records('quiz_multichoice','id', $id->id);
+                    }
+                }
+            }
+        }
+    }
+
+    if ($oldversion < 2005060300) {
+        //Search all the orphan categories (those whose course doesn't exist)
+        //and process them, deleting or moving them to site course - Bug 2459
+
+        //Set debug to false
+        $olddebug = $db->debug;
+        $db->debug = false;
+
+        //Iterate over all the quiz_categories records to get their course id
+        if ($courses = get_records_sql ("SELECT DISTINCT course as id, course
+                                         FROM {$CFG->prefix}quiz_categories")) {
+            //Iterate over courses
+            foreach ($courses as $course) {
+                //If the course doesn't exist, orphan category found!
+                //Process it with quiz_delete_course(). It will do all the hard work.
+                if (!record_exists('course', 'id', $course->id)) {
+                    require_once("$CFG->dirroot/mod/quiz/lib.php");
+                    quiz_delete_course($course);
+                }
+            }
+        }
+        //Reset rebug to its original state
+        $db->debug = $olddebug;
+    }
+
+    if ($oldversion < 2005062600) {
+        modify_database ('', "
+            CREATE TABLE `prefix_quiz_essay` (
+                `id` int(10) unsigned NOT NULL auto_increment,
+                `question` int(10) unsigned NOT NULL default '0',
+                `answer` varchar(255) NOT NULL default '',
+                PRIMARY KEY  (`id`),
+                KEY `question` (`question`)
+           ) TYPE=MyISAM COMMENT='Options for essay questions'");
+    
+        modify_database ('', "
+            CREATE TABLE `prefix_quiz_essay_states` (
+              `id` int(10) unsigned NOT NULL auto_increment,
+              `stateid` int(10) unsigned NOT NULL default '0',
+              `graded` tinyint(4) unsigned NOT NULL default '0',
+              `fraction` varchar(10) NOT NULL default '0.0',
+              `response` text NOT NULL,
+              PRIMARY KEY  (`id`)
+            ) TYPE=MyISAM COMMENT='essay question type specific state information'");
+    }
+
+    if ($oldversion < 2005070202) {
+        // add new unique id to prepare the way for lesson module to have its own attempts table
+        table_column('quiz_attempts', '', 'uniqueid', 'integer', '10', 'unsigned', '0', 'not null', 'id');
+        // initially we can use the id as the unique id because no other modules use attempts yet.
+        execute_sql("UPDATE {$CFG->prefix}quiz_attempts SET uniqueid = id", false);
+        // we set $CFG->attemptuniqueid to the next available id
+        $record = get_record_sql("SELECT max(id)+1 AS nextid FROM {$CFG->prefix}quiz_attempts");
+        set_config('attemptuniqueid', empty($record->nextid) ? 1 : $record->nextid);
+    }
+    
+    if ($oldversion < 2006020801) {
+        // add new field to store time delay between the first and second quiz attempt
+        table_column('quiz', '', 'delay1', 'integer', '10', 'unsigned', '0', 'not null', 'popup');
+        // add new field to store time delay between the second and any additional quizes
+        table_column('quiz', '', 'delay2', 'integer', '10', 'unsigned', '0', 'not null', 'delay1');
+    }
+
+    if ($oldversion < 2006021101) {
+        // set defaultgrade field properly (probably not necessary, but better make sure)
+        execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '1' WHERE defaultgrade = '0'", false);
+        execute_sql("UPDATE {$CFG->prefix}quiz_questions SET defaultgrade = '0' WHERE qtype = '".DESCRIPTION."'", false);
+    }
+
+    if ($oldversion < 2006021103) {
+        // add new field to store the question-level shuffleanswers option
+        table_column('quiz_match', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'subquestions');
+        table_column('quiz_multichoice', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'single');
+        table_column('quiz_randomsamatch', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'choose');
+    }
+
+    if ($oldversion < 2006021104) {
+        // add originalversion field for the new versioning mechanism
+        table_column('quiz_question_versions', '', 'originalquestion', 'int', '10', 'unsigned', '0', 'not null', 'newquestion');
+    }
+
+    if ($oldversion < 2006021301) {
+        modify_database('','ALTER TABLE prefix_quiz_attempts ADD UNIQUE INDEX uniqueid (uniqueid);');
+    }
+
+    if ($oldversion < 2006021302) {
+        table_column('quiz_match_sub', '', 'code', 'int', '10', 'unsigned', '0', 'not null', 'id');
+        execute_sql("UPDATE {$CFG->prefix}quiz_match_sub SET code = id", false);
+    }
+    if ($oldversion < 2006021304) {
+        // convert sequence field to text to accomodate very long sequences, see bug 4257
+        table_column('quiz_multianswers', 'sequence', 'sequence',  'text', '', '', '', 'not null', 'question');
+    }
+
+    if ($oldversion < 2006021501) {
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_newest_states RENAME {$CFG->prefix}question_sessions", false);
+    }
+
+    if ($oldversion < 2006022200) {
+        // convert grade fields to float
+        set_field('quiz_attempts', 'sumgrades', 0, 'sumgrades', '');
+        table_column('quiz_attempts', 'sumgrades', 'sumgrades',  'float', '', '', '0', 'not null');
+
+        set_field('quiz_answers', 'fraction', 0, 'fraction', '');
+        table_column('quiz_answers', 'fraction', 'fraction',  'float', '', '', '0', 'not null');
+
+        set_field('quiz_essay_states', 'fraction', 0, 'fraction', '');
+        table_column('quiz_essay_states', 'fraction', 'fraction',  'float', '', '', '0', 'not null');
+
+        set_field('quiz_states', 'grade', 0, 'grade', '');
+        table_column('quiz_states', 'grade', 'grade',  'float', '', '', '0', 'not null');
+
+        set_field('quiz_states', 'raw_grade', 0, 'raw_grade', '');
+        table_column('quiz_states', 'raw_grade', 'raw_grade',  'float', '', '', '0', 'not null');
+
+        set_field('quiz_states', 'penalty', 0, 'penalty', '');
+        table_column('quiz_states', 'penalty', 'penalty',  'float', '', '', '0', 'not null');
+
+        set_field('question_sessions', 'sumpenalty', 0, 'sumpenalty', '');
+        table_column('question_sessions', 'sumpenalty', 'sumpenalty',  'float', '', '', '0', 'not null');
+    }
+
+    if ($oldversion < 2006022400) {
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_questions RENAME {$CFG->prefix}question", false);
+    }
+
+    if ($oldversion < 2006022402) {
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_states RENAME {$CFG->prefix}question_states", false);
+    }
+
+    if ($oldversion < 2006022800) {
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_answers RENAME {$CFG->prefix}question_answers", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_categories RENAME {$CFG->prefix}question_categories", false);
+    }
+
+    if ($oldversion < 2006031202) {
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_truefalse RENAME {$CFG->prefix}question_truefalse", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_shortanswer RENAME {$CFG->prefix}question_shortanswer", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_multianswers RENAME {$CFG->prefix}question_multianswer", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_multichoice RENAME {$CFG->prefix}question_multichoice", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_numerical RENAME {$CFG->prefix}question_numerical", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_numerical_units RENAME {$CFG->prefix}question_numerical_units", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_randomsamatch RENAME {$CFG->prefix}question_randomsamatch", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_match RENAME {$CFG->prefix}question_match", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_match_sub RENAME {$CFG->prefix}question_match_sub", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_calculated RENAME {$CFG->prefix}question_calculated", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_dataset_definitions RENAME {$CFG->prefix}question_dataset_definitions", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_dataset_items RENAME {$CFG->prefix}question_dataset_items", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_question_datasets RENAME {$CFG->prefix}question_datasets", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_rqp RENAME {$CFG->prefix}question_rqp", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_rqp_servers RENAME {$CFG->prefix}question_rqp_servers", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_rqp_states RENAME {$CFG->prefix}question_rqp_states", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_rqp_types RENAME {$CFG->prefix}question_rqp_types", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_essay RENAME {$CFG->prefix}question_essay", false);
+        execute_sql("ALTER TABLE {$CFG->prefix}quiz_essay_states RENAME {$CFG->prefix}question_essay_states", false);
+    }
+
+    if ($oldversion < 2006032100) {
+        // change from the old questiontype numbers to using the questiontype names
+        table_column('question', 'qtype', 'qtype',  'varchar', 20, '', '', 'not null');
+        set_field('question', 'qtype', 'shortanswer', 'qtype', 1);
+        set_field('question', 'qtype', 'truefalse', 'qtype', 2);
+        set_field('question', 'qtype', 'multichoice', 'qtype', 3);
+        set_field('question', 'qtype', 'random', 'qtype', 4);
+        set_field('question', 'qtype', 'match', 'qtype', 5);
+        set_field('question', 'qtype', 'randomsamatch', 'qtype', 6);
+        set_field('question', 'qtype', 'description', 'qtype', 7);
+        set_field('question', 'qtype', 'numerical', 'qtype', 8);
+        set_field('question', 'qtype', 'multianswer', 'qtype', 9);
+        set_field('question', 'qtype', 'calculated', 'qtype', 10);
+        set_field('question', 'qtype', 'rqp', 'qtype', 11);
+        set_field('question', 'qtype', 'essay', 'qtype', 12);
+    }
+
+    if ($oldversion < 2006032200) {
+        // set version for all questiontypes that already have their tables installed
+        set_config('qtype_calculated_version', 2006032100);
+        set_config('qtype_essay_version', 2006032100);
+        set_config('qtype_match_version', 2006032100);
+        set_config('qtype_multianswer_version', 2006032100);
+        set_config('qtype_multichoice_version', 2006032100);
+        set_config('qtype_numerical_version', 2006032100);
+        set_config('qtype_randomsamatch_version', 2006032100);
+        set_config('qtype_rqp_version', 2006032100);
+        set_config('qtype_shortanswer_version', 2006032100);
+        set_config('qtype_truefalse_version', 2006032100);
+    }
+
+    if ($oldversion < 2006040600) {
+        table_column('question_sessions', '', 'comment', 'text', '', '', '', 'not null', 'sumpenalty');
+    }
+
+    if ($oldversion < 2006040900) {
+        modify_database('', "UPDATE prefix_question SET parent = id WHERE qtype ='random';");
+    }
+
+    if ($oldversion < 2006041000) {
+        modify_database('', " INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('quiz', 'continue attempt', 'quiz', 'name');");
+    }
+
+    if ($oldversion < 2006041001) {
+        table_column('question', 'version', 'version', 'varchar', 255);
+    }
+
+    if ($oldversion < 2006042800) {
+        // Check we have some un-renamed tables (verified in some servers)
+        if ($tables = $db->MetaTables('TABLES')) {
+            if (in_array($CFG->prefix.'quiz_randommatch', $tables) &&
+                !in_array($CFG->prefix.'question_randomsamatch', $tables)) {
+                modify_database ("", "ALTER TABLE prefix_quiz_randommatch RENAME prefix_question_randomsamatch ");
+            }
+            // Check for one possible missing field in one table
+            if ($columns = $db->MetaColumnNames($CFG->prefix.'question_randomsamatch')) {
+                if (!in_array('shuffleanswers', $columns)) {
+                    table_column('question_randomsamatch', '', 'shuffleanswers', 'tinyint', '4', 'unsigned', '1', 'not null', 'choose');
+                }
+            }
+        }
+    }
+
+    if ($oldversion < 2006042801) {
+        // The newgraded field must always point to a valid state
+        modify_database("","UPDATE prefix_question_sessions SET newgraded = newest where newgraded = '0'");
+
+        // The following table is discussed in bug 5468
+        modify_database ("", "CREATE TABLE prefix_question_attempts (
+                                  id int(10) unsigned NOT NULL auto_increment,
+                                  modulename varchar(20) NOT NULL default 'quiz',
+                                  PRIMARY KEY  (id)
+                                ) TYPE=MyISAM COMMENT='Student attempts. This table gets extended by the modules';");
+        // create one entry for all the existing quiz attempts
+        modify_database ("", "INSERT INTO prefix_question_attempts (id)
+                                   SELECT uniqueid
+                                   FROM prefix_quiz_attempts;");
+    }
+
+    if ($oldversion < 2006060700) { // fix for 5720
+        execute_sql('DROP TABLE '.$CFG->prefix.'question_essay_states', false);
+        execute_sql('DROP TABLE '.$CFG->prefix.'question_essay', false);
+        execute_sql('DROP TABLE '.$CFG->prefix.'quiz_attemptonlast_datasets', false);
+    }
+	
+    if ($oldversion < 2006122200) { 
+        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD email_ret int(1) NOT NULL default '' ");
+        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD pass_mark int(3) NOT NULL default '' ");
+        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD email_to_pass varchar(255) NOT NULL default '' ");
+        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD cc_to_pass varchar(255) NOT NULL default '' ");
+        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD subject_pass varchar(255) NOT NULL default '' ");
+        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD body_pass varchar(255) NOT NULL default '' ");
+        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD email_to_fail varchar(255) NOT NULL default '' ");
+        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD cc_to_fail varchar(255) NOT NULL default '' ");
+        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD subject_fail varchar(255) NOT NULL default '' ");
+        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD body_fail varchar(255) NOT NULL default '' ");
+        execute_sql(" ALTER TABLE {$CFG->prefix}quiz ADD det_add varchar(255) NOT NULL default '' ");														
+        execute_sql(" ALTER TABLE {$CFG->prefix}quiz_attempts ADD email_sent int(1) NOT NULL default '0' ");						
+      }	
+
+
+    return true;
+}
+
+?>


--- C:\Documents and Settings\bertoli\Desktop\quiz l8test\mod.html	Thu May 04 13:42:08 2006
+++ C:\Documents and Settings\bertoli\Desktop\quiz me\mod.html	Thu Aug 24 13:00:40 2006
@@ -1,679 +1,621 @@
-<!-- This page defines the form to create or edit an instance of this module -->
-<!-- It is used from /course/mod.php.  The whole instance is available as $form. -->
-
-<?php
-    require_once("$CFG->dirroot/mod/quiz/locallib.php");
-/// Ensure that all form variables are initialized
-    if (!isset($form->name)) {
-        $form->name = "";
-    }
-    if (!isset($form->intro)) {
-        $form->intro = "";
-    }
-    if (!isset($form->timeopen)) {
-        $form->timeopen = "";
-    }
-    if (!isset($form->timeclose)) {
-        $form->timeclose = "";
-    }
-    if (!isset($form->attempts)) {
-        $form->attempts = $CFG->quiz_attempts;
-    }
-    if (!isset($form->attemptonlast)) {
-        $form->attemptonlast = $CFG->quiz_attemptonlast;
-    }
-    if (!isset($form->grademethod)) {
-        $form->grademethod = $CFG->quiz_grademethod;
-    }
-    if (!isset($form->decimalpoints)) {
-        $form->decimalpoints = $CFG->quiz_decimalpoints;
-    }
-    if (!isset($form->review)) {
-        $form->review = $CFG->quiz_review;
-    }
-    if (!isset($form->questionsperpage)) {
-        $form->questionsperpage = $CFG->quiz_questionsperpage;
-    }
-    if (!isset($form->shufflequestions)) {
-        $form->shufflequestions = $CFG->quiz_shufflequestions;
-    }
-    if (!isset($form->shuffleanswers)) {
-        $form->shuffleanswers = $CFG->quiz_shuffleanswers;
-    }
-    if (!isset($form->grade)) {
-        $form->grade = $CFG->quiz_maximumgrade;
-    }
-    if (!isset($form->questions)) {
-        $form->questions = "";
-    }
-    if (!isset($form->password)) {
-        $form->password = $CFG->quiz_password;
-    }
-    if (!isset($form->subnet)) {
-        $form->subnet = $CFG->quiz_subnet;
-    }
-    if (!isset($form->timelimit)) {
-        $form->timelimit = $CFG->quiz_timelimit;
-    }
-    if (!isset($form->popup)) {
-        $form->popup = $CFG->quiz_popup;
-    }
-    if (!isset($form->optionflags)) {
-        $form->optionflags = $CFG->quiz_optionflags;
-    }
-    if (!isset($form->penaltyscheme)) {
-        $form->penaltyscheme = $CFG->quiz_penaltyscheme;
-    }
-    if (empty($form->timedue)) {
-        $form->timedue = "";
-    }
-    //enforced time delay between quiz attempts add-on
-    //delay1: time delay between first and second attempt
-    //delay2: time delay between second and additional quiz attempt
-    //enforced delay attempt between quiz
-    if (!isset($form->delay1)) {
-         $form->delay1 = $CFG->quiz_delay1;
-    }
-    if (!isset($form->delay2)) {
-         $form->delay2 = $CFG->quiz_delay2;
-    }
-
-    $fix = 0; // This will later be set to 1 if some of the variables have been fixed by the admin.
-
-    // the following are used for drop-down menus
-
-    $yesnooptions = array();
-    $yesnooptions[0] = get_string("no");
-    $yesnooptions[1] = get_string("yes");
-    
-    $attemptoptions = array();
-    $attemptoptions[0] = get_string("attemptsunlimited", "quiz");
-    $attemptoptions[1] = "1 ".strtolower(get_string("attempt", "quiz"));
-    for ($i=2;$i<=6;$i++) {
-        $attemptoptions[$i] = "$i ".strtolower(get_string("attempts", "quiz"));
-    }
-
-    //enforced time delay between quiz attempts add-on
-    $timedelayoptions = array();
-    $timedelayoptions[0] = get_string('none');
-    $timedelayoptions[1800] = get_string('numminutes', '', 30);
-    $timedelayoptions[3600] = get_string('numminutes', '', 60);
-    for($i=2; $i<=23; $i++) {
-         $seconds  = $i*3600;
-         $timedelayoptions[$seconds] = get_string('numhours', '', $i);
-    }
-    $timedelayoptions[86400] = get_string('numhours', '', 24);
-    for($i=2; $i<=7; $i++) {
-         $seconds = $i*86400;
-         $timedelayoptions[$seconds] = get_string('numdays', '', $i);
-    }
-
-?>
-<script type="text/javascript" language="javascript">
-    var dueitems = ['dueday','duemonth','dueyear','duehour', 'dueminute'];
-    var availableitems = ['availableday','availablemonth','availableyear','availablehour', 'availableminute'];
-    var timelimititems = ['timelimit'];
-</script>
-
-<form name="form" method="post" action="mod.php">
-
-<center>
-
-<!-- Now comes a table with all the options that have not been fixed by the admin -->
-<table cellpadding="5">
-
-<tr valign="top">
-    <td align="right"><b><?php print_string("name") ?>:</b></td>
-    <td align="left">
-        <input type="text" name="name" size="40" value="<?php p($form->name) ?>" />
-    </td>
-</tr>
-
-<tr valign="top">
-    <td align="right"><b><?php print_string("introduction", "quiz") ?>:</b><br /><br />
-     <?php
-        if ($usehtmleditor) {
-           helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
-        } else {
-           helpbutton("text", get_string("helptext"), "moodle", true, true);
-           echo '<br />';
-           emoticonhelpbutton("form", "description");
-           echo '<br />';
-        }
-      ?>
-    </td>
-    <td align="left">
-        <?php
-           print_textarea($usehtmleditor, 20, 50, 680, 400, "intro", $form->intro);
-        ?>
-    </td>
-</tr>
-
-<tr valign="top">
-   <td align="right"><b><?php print_string("quizopen", "quiz") ?>:</b></td>
-    <td align="left">
-        <input name="availableenable" type="checkbox" value="1" alt="<?php print_string("quizopen", "quiz") ?>" onclick="return lockoptions('form', 'availableenable', availableitems)" <?php if ($form->timeopen) echo 'checked="checked"' ?> />
-    <?php
-           print_date_selector("availableday", "availablemonth", "availableyear", $form->timeopen);
-           echo "&nbsp;-&nbsp;";
-           print_time_selector("availablehour", "availableminute", $form->timeopen);
-           helpbutton('timeopen', get_string('quizopens', 'quiz'), 'quiz');
-     ?>
-        <input type="hidden" name="havailableday"    value="0" />
-        <input type="hidden" name="havailablemonth"  value="0" />
-        <input type="hidden" name="havailableyear"   value="0" />
-        <input type="hidden" name="havailablehour"   value="0" />
-        <input type="hidden" name="havailableminute" value="0" />
-    </td>
-</tr>
-
-<tr valign="top">
-    <td align="right"><b><?php print_string("quizclose", "quiz") ?>:</b></td>
-    <td align="left">
-        <input name="dueenable" type="checkbox" value="1" alt="<?php print_string("quizclose", "quiz") ?>" onclick="return lockoptions('form', 'dueenable', dueitems)" <?php if ($form->timeclose) echo 'checked="checked"' ?> />
-    <?php
-           print_date_selector("dueday", "duemonth", "dueyear", $form->timeclose);
-           echo "&nbsp;-&nbsp;";
-           print_time_selector("duehour", "dueminute", $form->timeclose);
-           helpbutton('timeopen', get_string('quizcloses', 'quiz'), 'quiz');
-     ?>
-        <input type="hidden" name="hdueday"    value="0" />
-        <input type="hidden" name="hduemonth"  value="0" />
-        <input type="hidden" name="hdueyear"   value="0" />
-        <input type="hidden" name="hduehour"   value="0" />
-        <input type="hidden" name="hdueminute" value="0" />
-    </td>
-</tr>
-
-<?php if (!$CFG->quiz_fix_timelimit) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("timelimit", "quiz") ?>:</b></td>
-        <td align="left">
-            <input name="timelimitenable" type="checkbox" value="1" alt="<?php print_string('timelimit', 'quiz') ?>" onclick="return lockoptions('form', 'timelimitenable', timelimititems)" <?php if ($form->timelimit) echo 'checked="checked"' ?> />
-            <input type="text" name="timelimit" size="3" value="<?php p($form->timelimit ? $form->timelimit : '') ?>" />
-            <?php 
-                print_string('minutes');
-                helpbutton("timelimit", get_string("quiztimer","quiz"), "quiz");
-            ?>
-            <input type="hidden" name="htimelimit"    value="0" />
-        </td>
-    </tr>
-<?php } else $fix=1 ?>
-
-<?php if (!$CFG->quiz_fix_questionsperpage) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string('questionsperpage', 'quiz') ?>:</b></td>
-         <td align="left">
-        <?php
-            $perpage= array();
-            for ($i=0; $i<=50; ++$i) {
-                $perpage[$i] = $i;
-            }
-            $perpage[0] = get_string('allinone', 'quiz');
-
-            choose_from_menu($perpage, 'questionsperpage', $form->questionsperpage, '');
-            helpbutton('questionsperpage', get_string('questionsperpage', 'quiz'), 'quiz');
-         ?>
-        </td>
-    </tr>
-<?php } else $fix=1 ?>
-
-<?php if (!$CFG->quiz_fix_shufflequestions) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("shufflequestions", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "shufflequestions", "$form->shufflequestions", "");
-            helpbutton("shufflequestions", get_string("shufflequestions","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } else $fix=1 ?>
-
-<?php if (!$CFG->quiz_fix_shuffleanswers) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("shufflewithin", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "shuffleanswers", "$form->shuffleanswers", "");
-            helpbutton("shufflewithin", get_string("shufflewithin","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } else $fix=1 ?>
-
-<?php if (!$CFG->quiz_fix_attempts) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("attemptsallowed", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($attemptoptions, "attempts", "$form->attempts", "");
-            helpbutton("attempts", get_string("attemptsallowed","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } else $fix=1 ?>
-
-<?php if (!$CFG->quiz_fix_attemptonlast) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("eachattemptbuildsonthelast", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "attemptonlast",
-                             "$form->attemptonlast", "");
-            helpbutton("repeatattempts",
-                       get_string("eachattemptbuildsonthelast", "quiz"),
-                       "quiz");
-        ?>
-        </td>
-    </tr>
-<?php } else $fix=1 ?>
-
-<?php if (!$CFG->quiz_fix_grademethod) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("grademethod", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($QUIZ_GRADE_METHOD, "grademethod", "$form->grademethod", "");
-            helpbutton("grademethod", get_string("grademethod","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } else $fix=1 ?>
-
-<?php if (!$CFG->quiz_fix_adaptive) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("adaptive", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "adaptive", ($form->optionflags & QUESTION_ADAPTIVE) ? 1 : 0, "");
-            helpbutton("adaptive", get_string("adaptive","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } else $fix=1 ?>
-
-<?php if (!$CFG->quiz_fix_penaltyscheme) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("penaltyscheme", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "penaltyscheme", "$form->penaltyscheme", "");
-            helpbutton("penaltyscheme", get_string("penaltyscheme","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } ?>
-
-<?php if (!$CFG->quiz_fix_decimalpoints) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("decimaldigits", "quiz") ?>:</b></td>
-         <td align="left">
-         <?php
-            unset($options);
-            $options[0] = '0';
-            $options[1] = '1';
-            $options[2] = '2';
-            $options[3] = '3';
-            choose_from_menu($options, "decimalpoints", "$form->decimalpoints", "");
-            helpbutton("decimalpoints", get_string("decimaldigits","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } else $fix=1 ?>
-
-<?php if (!$CFG->quiz_fix_review) {
-    echo '<tr valign="top">';
-    include($CFG->dirroot . '/mod/quiz/reviewoptions.html');
-    echo '</tr>';
-} else $fix=1 ?>
-
-<?php if (!$CFG->quiz_fix_popup) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("popup", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "popup", "$form->popup", "");
-            helpbutton("popup", get_string("popup","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } else $fix=1 ?>
-
-<?php if (!$CFG->quiz_fix_delay1) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("delay1", "quiz") ?>:</b></td>
-        <td align="left">
-        <?php
-             choose_from_menu($timedelayoptions, "delay1", "$form->delay1", "");
-             helpbutton("timedelay1", get_string("delay1","quiz"), "quiz");
-        ?>
-        </td>
-        </tr>
-<?php } else $fix=1 ?>
-
-<?php if (!$CFG->quiz_fix_delay2) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("delay2", "quiz") ?>:</b></td>
-        <td align="left">
-        <?php
-             choose_from_menu($timedelayoptions, "delay2", "$form->delay2", "");
-             helpbutton("timedelay2", get_string("delay2","quiz"), "quiz");
-        ?>
-        </td>
-        </tr>
-<?php } else $fix=1 ?>
-
-<?php if (!$CFG->quiz_fix_password) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("requirepassword", "quiz") ?>:</b></td>
-         <td align="left">
-            <input type="text" name="password" size="40" value="<?php p($form->password) ?>" />
-            <?php helpbutton("requirepassword", get_string("requirepassword", "quiz"), "quiz"); ?>
-        </td>
-    </tr>
-<?php } else $fix=1 ?>
-
-<?php if (!$CFG->quiz_fix_subnet) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("requiresubnet", "quiz") ?>:</b></td>
-         <td align="left">
-            <input type="text" name="subnet" size="40" value="<?php p($form->subnet) ?>" />
-            <?php helpbutton("requiresubnet", get_string("requiresubnet", "quiz"), "quiz"); ?>
-        </td>
-    </tr>
-<?php } else $fix=1 ?>
-
-<?php print_standard_coursemodule_settings($form); ?>
-
-
-
-
-<?php if ($fix) { ?>
-
-<tr>
-    <td align="right"><b><?php print_string('advancedsettings') ?>:</b>
-        <!-- Some javascript to allow for the hiding of advanced options
-         This code was derived from mod.html in the resource module -->
-        <script language="javascript" type="text/javascript">
-            function showhide (id, set) {
-                divobj = document.getElementById(id);
-                butobj = document.getElementById(id+'button');
-                prefobj = document.getElementById(id+'pref');
-                if (set == true) {
-                    if (prefobj.value == '1') {
-                        divobj.style.display = 'block';
-                        butobj.value = '<?php print_string("hideadvancedsettings") ?>';
-                    } else {
-                        divobj.style.display = 'none';
-                        butobj.value = '<?php print_string("showadvancedsettings") ?>...';
-                    }
-                } else {
-                    if (prefobj.value == '1') {
-                        divobj.style.display = 'none';
-                        butobj.value = '<?php print_string("showadvancedsettings") ?>...';
-                        prefobj.value = '0';
-                    } else {
-                        divobj.style.display = 'block';
-                        butobj.value = '<?php print_string("hideadvancedsettings") ?>';
-                        prefobj.value = '1';
-                    }
-                }
-            }
-        </script>
-    </td>
-     <td align="left">
-        <input type="button" value="hide settings" id="optionsettingsbutton" onclick="javascript: return showhide('optionsettings');" />
-        <input type="hidden" name="optionsettingspref" id="optionsettingspref" value="<?php echo get_user_preferences('quiz_optionsettingspref', 0); ?>" />
-        <br />
-    </td>
-</tr>
-
-<!-- Now comes a copy of the options fields in a div with id optionsettings and with
-     the conditions reversed, so that it shows exactly the options that are usually hidden.
-     The visibility of this div is controlled by javascript. -->
-
-<tr><td colspan="2">
-
-<div id="optionsettings">
-
-<table align="center">
-
-<?php if ($CFG->quiz_fix_timelimit) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("timelimit", "quiz") ?>:</b></td>
-        <td align="left">
-            <input name="timelimitenable" type="checkbox" value="1" alt="<?php print_string('timelimit', 'quiz') ?>" onclick="return lockoptions('form', 'timelimitenable', timelimititems)" <?php if ($form->timelimit) echo 'checked="checked"' ?> />
-            <input type="text" name="timelimit" size="3" value="<?php p($form->timelimit ? $form->timelimit : '') ?>" />
-            <?php 
-                print_string('minutes');
-                helpbutton("timelimit", get_string("quiztimer","quiz"), "quiz");
-            ?>
-            <input type="hidden" name="htimelimit"    value="0" />
-        </td>
-    </tr>
-<?php } ?>
-
-<?php if ($CFG->quiz_fix_questionsperpage) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string('questionsperpage', 'quiz') ?>:</b></td>
-         <td align="left">
-        <?php
-            $perpage= array();
-            for ($i=0; $i<=50; ++$i) {
-                $perpage[$i] = $i;
-            }
-            $perpage[0] = get_string('allinone', 'quiz');
-
-            choose_from_menu($perpage, 'questionsperpage', $form->questionsperpage, '');
-            helpbutton('questionsperpage', get_string('questionsperpage'), 'quiz');
-         ?>
-        </td>
-    </tr>
-<?php } ?>
-
-<?php if ($CFG->quiz_fix_shufflequestions) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("shufflequestions", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "shufflequestions", "$form->shufflequestions", "");
-            helpbutton("shufflequestions", get_string("shufflequestions","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } ?>
-
-<?php if ($CFG->quiz_fix_shuffleanswers) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("shufflewithin", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "shuffleanswers", "$form->shuffleanswers", "");
-            helpbutton("shufflewithin", get_string("shufflewithin","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } ?>
-
-<?php if ($CFG->quiz_fix_attempts) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("attemptsallowed", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($attemptoptions, "attempts", "$form->attempts", "");
-            helpbutton("attempts", get_string("attemptsallowed","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } ?>
-<?php if ($CFG->quiz_fix_attemptonlast) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("eachattemptbuildsonthelast", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "attemptonlast",
-                             "$form->attemptonlast", "");
-            helpbutton("repeatattempts",
-                       get_string("eachattemptbuildsonthelast", "quiz"),
-                       "quiz");
-        ?>
-        </td>
-    </tr>
-<?php } ?>
-<?php if ($CFG->quiz_fix_grademethod) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("grademethod", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($QUIZ_GRADE_METHOD, "grademethod", "$form->grademethod", "");
-            helpbutton("grademethod", get_string("grademethod","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } ?>
-
-<?php if ($CFG->quiz_fix_adaptive) { $fix = 1; ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("adaptive", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "adaptive", ($form->optionflags & QUESTION_ADAPTIVE) ? 1 : 0, "");
-            helpbutton("adaptive", get_string("adaptive","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } ?>
-
-<?php if ($CFG->quiz_fix_penaltyscheme) { $fix = 1; ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("penaltyscheme", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "penaltyscheme", "$form->penaltyscheme", "");
-            helpbutton("penaltyscheme", get_string("penaltyscheme","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } ?>
-
-<?php if ($CFG->quiz_fix_decimalpoints) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("decimaldigits", "quiz") ?>:</b></td>
-         <td align="left">
-         <?php
-            unset($options);
-            $options[0] = '0';
-            $options[1] = '1';
-            $options[2] = '2';
-            $options[3] = '3';
-            choose_from_menu($options, "decimalpoints", "$form->decimalpoints", "");
-            helpbutton("decimalpoints", get_string("decimaldigits","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } ?>
-
-<?php if ($CFG->quiz_fix_review) {
-    echo '<tr valign="top">';
-    include($CFG->dirroot . '/mod/quiz/reviewoptions.html');
-    echo '</tr>';
-} ?>
-
-<?php if ($CFG->quiz_fix_delay1) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("delay1", "quiz") ?>:</b></td>
-        <td align="left">
-        <?php
-             choose_from_menu($timedelayoptions, "delay1", "$form->delay1", "");
-             helpbutton("timedelay1", get_string("delay1","quiz"), "quiz");
-        ?>
-        </td>
-        </tr>
-<?php } ?>
-
-<?php if ($CFG->quiz_fix_delay2) { ?>
-     <tr valign="top">
-         <td align="right"><b><?php print_string("delay2", "quiz") ?>:</b></td>
-         <td align="left">
-         <?php
-             choose_from_menu($timedelayoptions, "delay2", "$form->delay2", "");
-             helpbutton("timedelay2", get_string("delay2","quiz"), "quiz");
-         ?>
-         </td>
-         </tr>
-<?php } ?>
-
-<?php if ($CFG->quiz_fix_popup) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("popup", "quiz") ?>:</b></td>
-         <td align="left">
-        <?php
-            choose_from_menu($yesnooptions, "popup", "$form->popup", "");
-            helpbutton("popup", get_string("popup","quiz"), "quiz");
-         ?>
-        </td>
-    </tr>
-<?php } ?>
-
-<?php if ($CFG->quiz_fix_password) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("requirepassword", "quiz") ?>:</b></td>
-         <td align="left">
-            <input type="text" name="password" size="40" value="<?php p($form->password) ?>" />
-            <?php helpbutton("requirepassword", get_string("requirepassword", "quiz"), "quiz"); ?>
-        </td>
-    </tr>
-<?php } ?>
-
-<?php if ($CFG->quiz_fix_subnet) { ?>
-    <tr valign="top">
-        <td align="right"><b><?php print_string("requiresubnet", "quiz") ?>:</b></td>
-         <td align="left">
-            <input type="text" name="subnet" size="40" value="<?php p($form->subnet) ?>" />
-            <?php helpbutton("requiresubnet", get_string("requiresubnet", "quiz"), "quiz"); ?>
-        </td>
-    </tr>
-<?php } ?>
-
-
-
-</table>
-<script language="javascript" type="text/javascript">
-    showhide('optionsettings', true);
-</script>
-</div></td></tr>
-
-<?php } ?>
-
-</table>
-<br />
-<input type="hidden" name="grade" value="<?php echo $form->grade; ?>" />
-
-<!-- these hidden variables are always the same -->
-<input type="hidden" name="course"        value="<?php p($form->course) ?>" />
-<input type="hidden" name="sesskey"       value="<?php p($form->sesskey) ?>" />
-<input type="hidden" name="coursemodule"  value="<?php p($form->coursemodule) ?>" />
-<input type="hidden" name="section"       value="<?php p($form->section) ?>" />
-<input type="hidden" name="module"        value="<?php p($form->module) ?>" />
-<input type="hidden" name="modulename"    value="<?php p($form->modulename) ?>" />
-<input type="hidden" name="instance"      value="<?php p($form->instance) ?>" />
-<input type="hidden" name="mode"          value="<?php p($form->mode) ?>" />
-<!-- provide an additional button to edit questions -->
-<?php if ($form->instance) { ?>
-<input type="hidden" name="redirecturl" value="<?php p("$CFG->wwwroot/mod/quiz/edit.php?quizid=$form->instance") ?>" />
-<input type="submit" name="redirect" value="<?php print_string("savechanges") ?>" />
-<?php } else { ?>
-<input type="submit" value="<?php  print_string("savechanges") ?>" />
-<?php } ?>
-<input type="submit" name="cancel" value="<?php  print_string("cancel") ?>" />
-</center>
+<!-- This page defines the form to create or edit an instance of this module -->
+<!-- It is used from /course/mod.php.  The whole instance is available as $form. -->
+
+<?php
+    require_once("$CFG->dirroot/mod/quiz/locallib.php");
+/// Ensure that all form variables are initialized
+    if (!isset($form->name)) {
+        $form->name = '';
+    }
+    if (!isset($form->intro)) {
+        $form->intro = '';
+    }
+    if (!isset($form->timeopen)) {
+        $form->timeopen = '';
+    }
+    if (!isset($form->timeclose)) {
+        $form->timeclose = '';
+    }
+    if (!isset($form->attempts)) {
+        $form->attempts = $CFG->quiz_attempts;
+    }
+    if (!isset($form->attemptonlast)) {
+        $form->attemptonlast = $CFG->quiz_attemptonlast;
+    }
+    if (!isset($form->grademethod)) {
+        $form->grademethod = $CFG->quiz_grademethod;
+    }
+    if (!isset($form->decimalpoints)) {
+        $form->decimalpoints = $CFG->quiz_decimalpoints;
+    }
+    if (!isset($form->review)) {
+        $form->review = $CFG->quiz_review;
+    }
+    if (!isset($form->questionsperpage)) {
+        $form->questionsperpage = $CFG->quiz_questionsperpage;
+    }
+    if (!isset($form->shufflequestions)) {
+        $form->shufflequestions = $CFG->quiz_shufflequestions;
+    }
+    if (!isset($form->shuffleanswers)) {
+        $form->shuffleanswers = $CFG->quiz_shuffleanswers;
+    }
+    if (!isset($form->grade)) {
+        $form->grade = $CFG->quiz_maximumgrade;
+    }
+    if (!isset($form->questions)) {
+        $form->questions = '';
+    }
+    if (!isset($form->password)) {
+        $form->password = $CFG->quiz_password;
+    }
+    if (!isset($form->subnet)) {
+        $form->subnet = $CFG->quiz_subnet;
+    }
+    if (!isset($form->timelimit)) {
+        $form->timelimit = $CFG->quiz_timelimit;
+    }
+    if (!isset($form->popup)) {
+        $form->popup = $CFG->quiz_popup;
+    }
+    if (!isset($form->optionflags)) {
+        $form->optionflags = $CFG->quiz_optionflags;
+    }
+    if (!isset($form->penaltyscheme)) {
+        $form->penaltyscheme = $CFG->quiz_penaltyscheme;
+    }
+
+    $fix = 0; // This will later be set to 1 if some of the variables have been fixed by the admin.
+
+    // the following are used for drop-down menus
+
+    $yesnooptions = array();
+    $yesnooptions[0] = get_string("no");
+    $yesnooptions[1] = get_string("yes");
+
+    $attemptoptions = array();
+    $attemptoptions[0] = get_string("attemptsunlimited", "quiz");
+    $attemptoptions[1] = "1 ".strtolower(get_string("attempt", "quiz"));
+    for ($i=2;$i<=6;$i++) {
+        $attemptoptions[$i] = "$i ".strtolower(get_string("attempts", "quiz"));
+    }
+
+?>
+
+
+<form name="form" method="post" action="mod.php">
+
+<center>
+
+<!-- Now comes a table with all the options that have not been fixed by the admin -->
+<table cellpadding="5">
+
+<tr valign="top">
+    <td align="right"><b><?php print_string("name") ?>:</b></td>
+    <td align="left">
+        <input type="text" name="name" size="40" value="<?php p($form->name) ?>" />    </td>
+</tr>
+
+<tr valign="top">
+    <td align="right"><b><?php print_string("introduction", "quiz") ?>:</b><br /><br />
+     <?php
+        if ($usehtmleditor) {
+           helpbutton("richtext", get_string("helprichtext"), "moodle", true, true);
+        } else {
+           helpbutton("text", get_string("helptext"), "moodle", true, true);
+           echo '<br />';
+           emoticonhelpbutton("form", "description");
+           echo '<br />';
+        }
+      ?>    </td>
+    <td align="left">
+        <?php
+           print_textarea($usehtmleditor, 20, 50, 680, 400, "intro", $form->intro);
+        ?>    </td>
+</tr>
+
+<tr valign="top">
+    <td align="right"><b><?php print_string("quizopen", "quiz") ?>:</b></td>
+     <td align="left"><?php
+        if (!$form->timeopen and $course->format == "weeks") {
+            $form->timeopen  = $course->startdate + (($form->section - 1) * 608400);
+        }
+        print_date_selector("openday", "openmonth", "openyear", $form->timeopen);
+        print_time_selector("openhour", "openminute", $form->timeopen);
+        helpbutton("timeopen", get_string("quizopen","quiz"), "quiz");
+     ?></td>
+</tr>
+
+<tr valign="top">
+    <td align="right"><b><?php print_string("quizclose", "quiz") ?>:</b></td>
+     <td align="left">
+    <?php
+        if (!$form->timeclose and $course->format == "weeks") {
+            $form->timeclose  = $course->startdate + (($form->section) * 608400);
+        }
+        print_date_selector("closeday", "closemonth", "closeyear", $form->timeclose);
+        print_time_selector("closehour", "closeminute", $form->timeclose);
+        helpbutton("timeopen", get_string("quizclose","quiz"), "quiz");
+     ?>    </td>
+</tr>
+
+<?php if (!$CFG->quiz_fix_timelimit) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("timelimit", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            print_timer_selector($form->timelimit, get_string("minutes","quiz"));
+            helpbutton("timelimit", get_string("quiztimer","quiz"), "quiz");
+        ?>        </td>
+    </tr>
+<?php } else $fix=1 ?>
+
+<?php if (!$CFG->quiz_fix_questionsperpage) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string('questionsperpage', 'quiz') ?>:</b></td>
+         <td align="left">
+        <?php
+            $perpage= array();
+            for ($i=0; $i<=50; ++$i) {
+                $perpage[$i] = $i;
+            }
+            $perpage[0] = get_string('allinone', 'quiz');
+            choose_from_menu($perpage, 'questionsperpage', $form->questionsperpage, '');
+            helpbutton('questionsperpage', get_string('questionsperpage'), 'quiz');
+         ?>        </td>
+    </tr>
+<?php } else $fix=1 ?>
+
+<?php if (!$CFG->quiz_fix_shufflequestions) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("shufflequestions", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            choose_from_menu($yesnooptions, "shufflequestions", "$form->shufflequestions", '');
+            helpbutton("shufflequestions", get_string("shufflequestions","quiz"), "quiz");
+         ?>        </td>
+    </tr>
+<?php } else $fix=1 ?>
+
+<?php if (!$CFG->quiz_fix_shuffleanswers) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("shuffleanswers", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            choose_from_menu($yesnooptions, "shuffleanswers", "$form->shuffleanswers", '');
+            helpbutton("shuffleanswers", get_string("shuffleanswers","quiz"), "quiz");
+         ?>        </td>
+    </tr>
+<?php } else $fix=1 ?>
+
+<?php if (!$CFG->quiz_fix_attempts) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("attemptsallowed", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            choose_from_menu($attemptoptions, "attempts", "$form->attempts", '');
+            helpbutton("attempts", get_string("attemptsallowed","quiz"), "quiz");
+         ?>        </td>
+    </tr>
+<?php } else $fix=1 ?>
+
+<?php if (!$CFG->quiz_fix_attemptonlast) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("eachattemptbuildsonthelast", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            choose_from_menu($yesnooptions, "attemptonlast",
+                             "$form->attemptonlast", '');
+            helpbutton("repeatattempts",
+                       get_string("eachattemptbuildsonthelast", "quiz"),
+                       "quiz");
+        ?>        </td>
+    </tr>
+<?php } else $fix=1 ?>
+
+<?php if (!$CFG->quiz_fix_grademethod) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("grademethod", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            choose_from_menu($QUIZ_GRADE_METHOD, "grademethod", "$form->grademethod", '');
+            helpbutton("grademethod", get_string("grademethod","quiz"), "quiz");
+         ?>        </td>
+    </tr>
+<?php } else $fix=1 ?>
+
+<?php if (!$CFG->quiz_fix_adaptive) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("adaptive", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            choose_from_menu($yesnooptions, "adaptive", $form->optionflags & QUIZ_ADAPTIVE, '');
+            helpbutton("adaptive", get_string("adaptive","quiz"), "quiz");
+         ?>        </td>
+    </tr>
+<?php } else $fix=1 ?>
+
+<?php if (!$CFG->quiz_fix_penaltyscheme) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("penaltyscheme", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            choose_from_menu($yesnooptions, "penaltyscheme", "$form->penaltyscheme", '');
+            helpbutton("penaltyscheme", get_string("penaltyscheme","quiz"), "quiz");
+         ?>        </td>
+    </tr>
+<?php } ?>
+
+<?php if (!$CFG->quiz_fix_decimalpoints) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("decimalpoints", "quiz") ?>:</b></td>
+         <td align="left">
+         <?php
+            unset($options);
+            $options[0] = '0';
+            $options[1] = '1';
+            $options[2] = '2';
+            $options[3] = '3';
+            choose_from_menu($options, "decimalpoints", "$form->decimalpoints", '');
+            helpbutton("decimalpoints", get_string("decimalpoints","quiz"), "quiz");
+         ?>        </td>
+    </tr>
+<?php } else $fix=1 ?>
+
+<?php if (!$CFG->quiz_fix_review) {
+    echo '<tr valign="top">';
+    include($CFG->dirroot . '/mod/quiz/reviewoptions.html');
+    echo '</tr>';
+} else $fix=1 ?>
+
+<?php if (!$CFG->quiz_fix_popup) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("popup", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            choose_from_menu($yesnooptions, "popup", "$form->popup", '');
+            helpbutton("popup", get_string("popup","quiz"), "quiz");
+         ?>        </td>
+    </tr>
+<?php } else $fix=1 ?>
+
+<?php if (!$CFG->quiz_fix_password) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("requirepassword", "quiz") ?>:</b></td>
+         <td align="left">
+            <input type="text" name="password" size="40" value="<?php p($form->password) ?>" />
+            <?php helpbutton("requirepassword", get_string("requirepassword", "quiz"), "quiz"); ?>        </td>
+    </tr>
+<?php } else $fix=1 ?>
+
+<?php if (!$CFG->quiz_fix_subnet) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("requiresubnet", "quiz") ?>:</b></td>
+         <td align="left">
+            <input type="text" name="subnet" size="40" value="<?php p($form->subnet) ?>" />
+            <?php helpbutton("requiresubnet", get_string("requiresubnet", "quiz"), "quiz"); ?>        </td>
+    </tr>
+    
+<tr valign="top">
+  <td height="5" align="center" colspan = "2"><hr /></td>
+</tr>
+    <td align="right"><b>Email quiz results?</b></td>
+        <td align="left">
+            <?php choose_from_menu($yesnooptions, "email_ret", "$form->email_ret", '');?>
+            <?php helpbutton("emailreturn", get_string("emailreturn", "quiz"), "quiz"); ?>
+        </td>
+    <tr valign="top">
+    <td align="right"><b>User details to include:</b></td>
+    <td align="left"><label>
+    <?php
+        $bdetails = explode(",", $form->det_add);
+        $categories = array(get_string("date"), get_string("name"), get_string("email"), get_string("institution"), get_string("department"), get_string("phone"), get_string("address"), get_string("currentpicture"));
+        echo "<select size=\"6\" name=\"categories[]\" multiple=\"multiple\" >";
+        echo "<option>Ctrl + click for multiple</option>";
+        echo "<option>- - - - - - - - - - - - - - - - - - -</option>\n";
+        $num = 0;
+       
+	    if ($categories) {
+            foreach ($categories as $category) {
+                echo "  <option value=\"$num\" ";
+                if (in_array($num, $bdetails)) {
+                    $dupe = "true";
+                    echo " selected=\"selected\"";
+                }
+                echo ">".$category."</option>\n"; 
+                $num += 1;
+            }
+        }
+        echo "</select>\n";
+    ?>
+    </label>
+  
+    </td></tr>
+    <tr valign="top">
+        <td align="right"><b>Pass mark (%):</b></td>
+        <td align="left"><input type="text" name="pass_mark" size="3" value="<?php p($form->pass_mark) ?>" /></td>
+    </tr> 
+    <tr valign="top">
+        <td align="right"><b>PASS &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; To:</b></td>
+        <td align="left">
+        <input type="text" name="email_to_pass" size="40" value="<?php p($form->email_to_pass) ?>" />   </td>
+    </tr>
+        <td align="right"><b>CC:</b></td>
+        <td align="left">
+        <input type="text" name="cc_to_pass" size="40" value="<?php p($form->cc_to_pass) ?>" />   </td>
+    </tr>
+    <tr valign="top">
+        <td align="right"><b>Subject:</b></td>
+        <td align="left">
+        <input type="text" name="subject_pass" size="40" value="<?php p($form->subject_pass) ?>" />   </td>
+     </tr>
+
+    <tr valign="top">
+        <td align="right"><b>Message:</b>
+        </td><td align="left">
+        <textarea name="body_pass" rows="10"><?php p($form->body_pass) ?></textarea>
+    </td>
+    </tr>
+    <tr valign="top">
+        <td align="right"><b>FAIL &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; To:</b></td>
+        <td align="left">
+        <input type="text" name="email_to_fail" size="40" value="<?php p($form->email_to_fail) ?>" />   </td>
+    </tr>
+        <td align="right"><b>CC:</b></td>
+        <td align="left">
+        <input type="text" name="cc_to_fail" size="40" value="<?php p($form->cc_to_fail) ?>" />   </td>
+    </tr>
+        <tr valign="top">
+        <td align="right"><b>Subject:</b></td>
+        <td align="left">
+        <input type="text" name="subject_fail" size="40" value="<?php p($form->subject_fail) ?>" />   </td>
+    </tr>
+    <tr valign="top">
+        <td align="right"><b>Message:</b>
+        </td><td align="left">
+        <textarea name="body_fail" rows="10"><?php p($form->body_fail) ?></textarea>
+    </td>
+    </tr><tr valign="top">
+       <td height="15" align="center" colspan = "2"><hr /></td>
+    </tr>
+
+<?php } else $fix=1 ?>
+
+<?php print_standard_coursemodule_settings($form); ?>
+
+
+
+
+<?php if ($fix) { ?>
+
+<tr>
+    <td align="right"><b><?php print_string('advancedsettings') ?>:</b>
+        <!-- Some javascript to allow for the hiding of advanced options
+         This code was derived from mod.html in the resource module -->
+        <script language="javascript" type="text/javascript">
+            function showhide (id, set) {
+                divobj = document.getElementById(id);
+                butobj = document.getElementById(id+'button');
+                prefobj = document.getElementById(id+'pref');
+                if (set == true) {
+                    if (prefobj.value == '1') {
+                        divobj.style.display = 'block';
+                        butobj.value = '<?php print_string("hideadvancedsettings") ?>';
+                    } else {
+                        divobj.style.display = 'none';
+                        butobj.value = '<?php print_string("showadvancedsettings") ?>...';
+                    }
+                } else {
+                    if (prefobj.value == '1') {
+                        divobj.style.display = 'none';
+                        butobj.value = '<?php print_string("showadvancedsettings") ?>...';
+                        prefobj.value = '0';
+                    } else {
+                        divobj.style.display = 'block';
+                        butobj.value = '<?php print_string("hideadvancedsettings") ?>';
+                        prefobj.value = '1';
+                    }
+                }
+            }
+        </script>    </td>
+     <td align="left">
+        <input type="button" value="hide settings" id="optionsettingsbutton" onClick="javascript: return showhide('optionsettings');" />
+        <input type="hidden" name="optionsettingspref" id="optionsettingspref" value="<?php echo get_user_preferences('quiz_optionsettingspref', 0); ?>" />
+        <br />    </td>
+</tr>
+
+<!-- Now comes a copy of the options fields in a div with id optionsettings and with
+     the conditions reversed, so that it shows exactly the options that are usually hidden.
+     The visibility of this div is controlled by javascript. -->
+
+<tr><td colspan="2">
+
+<div id="optionsettings">
+
+<table align="center">
+
+<?php if ($CFG->quiz_fix_timelimit) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("timelimit", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            print_timer_selector($form->timelimit, get_string("minutes","quiz"));
+            helpbutton("timelimit", get_string("quiztimer","quiz"), "quiz");
+        ?>        </td>
+    </tr>
+<?php } ?>
+
+<?php if ($CFG->quiz_fix_questionsperpage) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string('questionsperpage', 'quiz') ?>:</b></td>
+         <td align="left">
+        <?php
+            $perpage= array();
+            for ($i=0; $i<=50; ++$i) {
+                $perpage[$i] = $i;
+            }
+            $perpage[0] = get_string('allinone', 'quiz');
+
+            choose_from_menu($perpage, 'questionsperpage', $form->questionsperpage, '');
+            helpbutton('questionsperpage', get_string('questionsperpage'), 'quiz');
+         ?>        </td>
+    </tr>
+<?php } ?>
+
+<?php if ($CFG->quiz_fix_shufflequestions) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("shufflequestions", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            choose_from_menu($yesnooptions, "shufflequestions", "$form->shufflequestions", '');
+            helpbutton("shufflequestions", get_string("shufflequestions","quiz"), "quiz");
+         ?>        </td>
+    </tr>
+<?php } ?>
+
+<?php if ($CFG->quiz_fix_shuffleanswers) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("shuffleanswers", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            choose_from_menu($yesnooptions, "shuffleanswers", "$form->shuffleanswers", '');
+            helpbutton("shuffleanswers", get_string("shuffleanswers","quiz"), "quiz");
+         ?>        </td>
+    </tr>
+<?php } ?>
+
+<?php if ($CFG->quiz_fix_attempts) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("attemptsallowed", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            choose_from_menu($attemptoptions, "attempts", "$form->attempts", '');
+            helpbutton("attempts", get_string("attemptsallowed","quiz"), "quiz");
+         ?>        </td>
+    </tr>
+<?php } ?>
+<?php if ($CFG->quiz_fix_attemptonlast) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("eachattemptbuildsonthelast", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            choose_from_menu($yesnooptions, "attemptonlast",
+                             "$form->attemptonlast", '');
+            helpbutton("repeatattempts",
+                       get_string("eachattemptbuildsonthelast", "quiz"),
+                       "quiz");
+        ?>        </td>
+    </tr>
+<?php } ?>
+<?php if ($CFG->quiz_fix_grademethod) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("grademethod", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            choose_from_menu($QUIZ_GRADE_METHOD, "grademethod", "$form->grademethod", '');
+            helpbutton("grademethod", get_string("grademethod","quiz"), "quiz");
+         ?>        </td>
+    </tr>
+<?php } ?>
+
+<?php if ($CFG->quiz_fix_adaptive) { $fix = 1; ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("adaptive", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            choose_from_menu($yesnooptions, "adaptive", $form->optionflags & QUIZ_ADAPTIVE, '');
+            helpbutton("adaptive", get_string("adaptive","quiz"), "quiz");
+         ?>        </td>
+    </tr>
+<?php } ?>
+
+<?php if ($CFG->quiz_fix_penaltyscheme) { $fix = 1; ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("penaltyscheme", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            choose_from_menu($yesnooptions, "penaltyscheme", "$form->penaltyscheme", '');
+            helpbutton("penaltyscheme", get_string("penaltyscheme","quiz"), "quiz");
+         ?>        </td>
+    </tr>
+<?php } ?>
+
+<?php if ($CFG->quiz_fix_decimalpoints) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("decimalpoints", "quiz") ?>:</b></td>
+         <td align="left">
+         <?php
+            unset($options);
+            $options[0] = '0';
+            $options[1] = '1';
+            $options[2] = '2';
+            $options[3] = '3';
+            choose_from_menu($options, "decimalpoints", "$form->decimalpoints", '');
+            helpbutton("decimalpoints", get_string("decimalpoints","quiz"), "quiz");
+         ?>        </td>
+    </tr>
+<?php } ?>
+
+<?php if ($CFG->quiz_fix_review) {
+    echo '<tr valign="top">';
+    include($CFG->dirroot . '/mod/quiz/reviewoptions.html');
+    echo '</tr>';
+} ?>
+
+<?php if ($CFG->quiz_fix_popup) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("popup", "quiz") ?>:</b></td>
+         <td align="left">
+        <?php
+            choose_from_menu($yesnooptions, "popup", "$form->popup", '');
+            helpbutton("popup", get_string("popup","quiz"), "quiz");
+         ?>        </td>
+    </tr>
+<?php } ?>
+
+<?php if ($CFG->quiz_fix_password) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("requirepassword", "quiz") ?>:</b></td>
+         <td align="left">
+            <input type="text" name="password" size="40" value="<?php p($form->password) ?>" />
+            <?php helpbutton("requirepassword", get_string("requirepassword", "quiz"), "quiz"); ?>        </td>
+    </tr>
+<?php } ?>
+
+<?php if ($CFG->quiz_fix_subnet) { ?>
+    <tr valign="top">
+        <td align="right"><b><?php print_string("requiresubnet", "quiz") ?>:</b></td>
+         <td align="left">
+            <input type="text" name="subnet" size="40" value="<?php p($form->subnet) ?>" />
+            <?php helpbutton("requiresubnet", get_string("requiresubnet", "quiz"), "quiz"); ?>        </td>
+    </tr>
+<?php } ?>
+</table>
+<script language="javascript" type="text/javascript">
+    showhide('optionsettings', true);
+</script>
+</div></td></tr>
+
+<?php } ?>
+</table>
+<br />
+<input type="hidden" name="grade" value="<?php echo $form->grade; ?>" />
+
+<!-- these hidden variables are always the same -->
+<input type="hidden" name="course"        value="<?php p($form->course) ?>" />
+<input type="hidden" name="sesskey"       value="<?php p($form->sesskey) ?>" />
+<input type="hidden" name="coursemodule"  value="<?php p($form->coursemodule) ?>" />
+<input type="hidden" name="section"       value="<?php p($form->section) ?>" />
+<input type="hidden" name="module"        value="<?php p($form->module) ?>" />
+<input type="hidden" name="modulename"    value="<?php p($form->modulename) ?>" />
+<input type="hidden" name="instance"      value="<?php p($form->instance) ?>" />
+<input type="hidden" name="mode"          value="<?php p($form->mode) ?>" />
+<input type="submit" value="<?php  print_string("savechanges") ?>" />
+<!-- provide an additional button to edit questions -->
+<?php if ($form->instance) { ?>
+<input type="hidden" name="redirecturl" value="<?php p("$CFG->wwwroot/mod/quiz/edit.php?quizid=$form->instance") ?>" />
+<input type="submit" name="redirect" value="<?php print_string('saveandedit', 'quiz') ?>" />
+<?php } ?>
+<input type="submit" name="cancel" value="<?php  print_string("cancel") ?>" />
+</center>
 </form>
-
-<script type="text/javascript">
-<?php 
-    if (!$form->timeclose) echo "lockoptions('form','dueenable', dueitems);";
-    if (!$form->timeopen) echo "lockoptions('form','availableenable', availableitems);";
-    if (!$form->timelimit) echo "lockoptions('form','timelimitenable', timelimititems);";
-?>
-</script>


--- C:\Documents and Settings\bertoli\Desktop\quiz l8test\version.php	Thu Jun 08 10:08:10 2006
+++ C:\Documents and Settings\bertoli\Desktop\quiz me\version.php	Wed Sep 13 09:56:17 2006
@@ -1,12 +1,12 @@
-<?php // $Id: version.php,v 1.104.2.3 2006/06/07 05:56:59 toyomoyo Exp $
-
-////////////////////////////////////////////////////////////////////////////////
-//  Code fragment to define the version of quiz
-//  This fragment is called by moodle_needs_upgrading() and /admin/index.php
-////////////////////////////////////////////////////////////////////////////////
-
-$module->version  = 2006060700;   // The (date) version of this module
-$module->requires = 2006022400;   // Requires this Moodle version
-$module->cron     = 0;            // How often should cron check this module (seconds)?
-
-?>
+<?php // $Id: version.php,v 1.104.2.3 2006/06/07 05:56:59 toyomoyo Exp $
+
+////////////////////////////////////////////////////////////////////////////////
+//  Code fragment to define the version of quiz
+//  This fragment is called by moodle_needs_upgrading() and /admin/index.php
+////////////////////////////////////////////////////////////////////////////////
+
+$module->version  = 2006090500;   // The (date) version of this module
+$module->requires = 2006022400;   // Requires this Moodle version
+$module->cron     = 0;            // How often should cron check this module (seconds)?
+
+?>
