3 function lesson_upgrade($oldversion) {
4 /// This function does anything necessary to upgrade
5 /// older versions to match current functionality
9 if ($oldversion < 2004021600) {
11 delete_records("log_display", "module", "lesson");
13 modify_database ("", "INSERT INTO prefix_log_display VALUES ('lesson', 'start', 'lesson', 'name');");
14 modify_database ("", "INSERT INTO prefix_log_display VALUES ('lesson', 'end', 'lesson', 'name');");
15 modify_database ("", "INSERT INTO prefix_log_display VALUES ('lesson', 'view', 'lesson_pages', 'title');");
19 if ($oldversion < 2004022200) {
21 table_column("lesson", "", "maxattempts", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "maxanswers");
22 table_column("lesson", "", "nextpagedefault", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "maxattempts");
23 table_column("lesson", "", "maxpages", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "nextpagedefault");
24 table_column("lesson_pages", "", "qtype", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "lessonid");
25 table_column("lesson_pages", "", "qoption", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "qtype");
26 table_column("lesson_answers", "", "grade", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "jumpto");
30 if ($oldversion < 2004032000) { // Upgrade some old beta lessons
31 execute_sql(" UPDATE \"{$CFG->prefix}lesson_pages\" SET qtype = 3 WHERE qtype = 0");
34 if ($oldversion < 2004032400) {
35 table_column("lesson", "", "usemaxgrade", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade");
36 table_column("lesson", "", "minquestions", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "nextpagedefault");
39 if ($oldversion < 2004032700) {
40 table_column("lesson_answers", "", "flags", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade");
43 if ($oldversion < 2004072100) {
44 execute_sql(" create table ".$CFG->prefix
."lesson_high_scores
45 ( id serial8 primary key,
46 lessonid int8 not null,
48 gradeid int8 not null,
49 nickname varchar(5) not null
52 execute_sql(" create table ".$CFG->prefix
."lesson_essay
53 ( id serial8 primary key,
54 lessonid int8 not null,
57 answerid int8 not null,
60 graded int4 not null default 0,
61 score int8 not null default 0,
62 response text not null,
63 sent int4 not null default 0,
64 timesubmitted int8 not null
67 execute_sql(" create table ".$CFG->prefix
."lesson_branch
68 ( id serial8 primary key,
69 lessonid int8 not null,
74 timeseen int8 not null
78 execute_sql(" create table ".$CFG->prefix
."lesson_timer
79 ( id serial8 primary key,
80 lessonid int8 not null,
82 starttime int8 not null,
83 lessontime int8 not null
88 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson_pages ADD layout TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' AFTER qoption");
89 table_column('lesson_pages','','layout','int','3','unsigned', '1', 'not null', 'qoption');
90 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson_pages ADD display TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' AFTER layout");
91 table_column('lesson_pages','','display','int','3','unsigned', '1', 'not null', 'layout');
93 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson_answers ADD score INT(10) NOT NULL DEFAULT '0' AFTER grade");
94 table_column('lesson_answers','','score','int','10','unsigned', '1', 'not null', 'grade');
96 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD usepassword TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER name");
97 table_column('lesson','','usepassword','int','3','unsigned', '0', 'not null', 'name');
99 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD password VARCHAR(32) NOT NULL DEFAULT '' AFTER usepassword");
100 table_column('lesson','','password','varchar','32','', '', 'not null', 'usepassword');
102 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD custom TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER grade");
103 table_column('lesson','','custom','int','3','unsigned', '0', 'not null', 'grade');
105 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD ongoing TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER custom");
106 table_column('lesson','','ongoing','int','3','unsigned', '0', 'not null', 'custom');
108 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD timed TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxpages");
109 table_column('lesson','','timed','int','3','unsigned', '0', 'not null', 'maxpages');
111 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD maxtime INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER timed");
112 table_column('lesson','','maxtime','int','10','unsigned', '0', 'not null', 'timed');
114 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD tree TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER retake");
115 table_column('lesson','','tree','int','3','unsigned', '0', 'not null', 'retake');
117 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD slideshow TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER tree");
118 table_column('lesson','','slideshow','int','3','unsigned', '0', 'not null', 'tree');
120 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD width INT(10) UNSIGNED NOT NULL DEFAULT '640' AFTER slideshow");
121 table_column('lesson','','width','int','10','unsigned', '640', 'not null', 'slideshow');
123 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD height INT(10) UNSIGNED NOT NULL DEFAULT '480' AFTER width");
124 table_column('lesson','','height','int','10','unsigned', '480', 'not null', 'width');
126 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD bgcolor CHAR(7) NOT NULL DEFAULT '#FFFFFF' AFTER height");
127 table_column('lesson','','bgcolor','varchar','7','unsigned', '#FFFFFF', 'not null', 'height');
129 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD displayleft TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER bgcolor");
130 table_column('lesson','','displayleft','int','3','unsigned', '0', 'not null', 'bgcolor');
132 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD highscores TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER displayleft");
133 table_column('lesson','','highscores','int','3','unsigned', '0', 'not null', 'displayleft');
135 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD maxhighscores INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER highscores");
136 table_column('lesson','','maxhighscores','int','10','unsigned', '0', 'not null', 'highscores');
140 if ($oldversion < 2004081100) {
141 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD practice TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER name");
142 table_column('lesson','','practice','int','3','unsigned', '0', 'not null', 'name');
143 //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD review TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxattempts");
144 table_column('lesson','','review','int','3','unsigned', '0', 'not null', 'maxattempts');
147 if ($oldversion < 2004081700) {
148 execute_sql("CREATE TABLE {$CFG->prefix}lesson_default
149 ( id serial8 primary key,
150 course int8 NOT NULL default '0',
151 practice int4 NOT NULL default '0',
152 password varchar(32) NOT NULL default '',
153 usepassword int4 NOT NULL default '0',
154 grade int4 NOT NULL default '0',
155 custom int4 NOT NULL default '0',
156 ongoing int4 NOT NULL default '0',
157 usemaxgrade int4 NOT NULL default '0',
158 maxanswers int4 NOT NULL default '4',
159 maxattempts int4 NOT NULL default '5',
160 review int4 NOT NULL default '0',
161 nextpagedefault int4 NOT NULL default '0',
162 minquestions int4 NOT NULL default '0',
163 maxpages int4 NOT NULL default '0',
164 timed int4 NOT NULL default '0',
165 maxtime int8 NOT NULL default '0',
166 retake int4 NOT NULL default '1',
167 tree int4 NOT NULL default '0',
168 slideshow int4 NOT NULL default '0',
169 width int8 NOT NULL default '640',
170 height int8 NOT NULL default '480',
171 bgcolor varchar(7) default '#FFFFFF',
172 displayleft int4 NOT NULL default '0',
173 highscores int4 NOT NULL default '0',
174 maxhighscores int8 NOT NULL default '0'
178 if ($oldversion < 2004100400) {
179 //execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_attempts` ADD `useranswer` text NOT NULL AFTER correct");
180 table_column('lesson_attempts', '', 'useranswer', 'text', '', '', '', 'NOT NULL', 'correct');
183 if ($oldversion < 2004100700) {
184 //execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `modattempts` tinyint(3) unsigned NOT NULL default '0' AFTER practice");
185 table_column('lesson', '', 'modattempts', 'INT', '4', 'unsigned', '0', 'NOT NULL', 'practice');
188 if ($oldversion < 2004102600) {
189 //execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_default` ADD `modattempts` tinyint(3) unsigned NOT NULL default '0' AFTER practice");
190 table_column('lesson_default', '', 'modattempts', 'INT', '4', 'unsigned', '0', 'NOT NULL', 'practice');
193 if ($oldversion < 2004111200) {
194 execute_sql("DROP INDEX {$CFG->prefix}lesson_course_idx;",false);
195 execute_sql("DROP INDEX {$CFG->prefix}lesson_answers_lessonid_idx;",false);
196 execute_sql("DROP INDEX {$CFG->prefix}lesson_answers_pageid_idx;",false);
197 execute_sql("DROP INDEX {$CFG->prefix}lesson_attempts_lessonid_idx;",false);
198 execute_sql("DROP INDEX {$CFG->prefix}lesson_attempts_pageid_idx;",false);
199 execute_sql("DROP INDEX {$CFG->prefix}lesson_attempts_userid_idx;",false);
200 execute_sql("DROP INDEX {$CFG->prefix}lesson_grades_lessonid_idx;",false);
201 execute_sql("DROP INDEX {$CFG->prefix}lesson_grades_userid_idx;",false);
202 execute_sql("DROP INDEX {$CFG->prefix}lesson_pages_lessonid_idx;",false);
204 modify_database('','CREATE INDEX prefix_lesson_course_idx ON prefix_lesson (course);');
205 modify_database('','CREATE INDEX prefix_lesson_answers_lessonid_idx ON prefix_lesson_answers (lessonid);');
206 modify_database('','CREATE INDEX prefix_lesson_answers_pageid_idx ON prefix_lesson_answers (pageid);');
207 modify_database('','CREATE INDEX prefix_lesson_attempts_lessonid_idx ON prefix_lesson_attempts (lessonid);');
208 modify_database('','CREATE INDEX prefix_lesson_attempts_pageid_idx ON prefix_lesson_attempts (pageid);');
209 modify_database('','CREATE INDEX prefix_lesson_attempts_userid_idx ON prefix_lesson_attempts (userid);');
210 modify_database('','CREATE INDEX prefix_lesson_grades_lessonid_idx ON prefix_lesson_grades (lessonid);');
211 modify_database('','CREATE INDEX prefix_lesson_grades_userid_idx ON prefix_lesson_grades (userid);');
212 modify_database('','CREATE INDEX prefix_lesson_pages_lessonid_idx ON prefix_lesson_pages (lessonid);');