From ac8e16be13cc70e742397080345e33b2ddfaaf4e Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sat, 5 Mar 2005 00:09:39 +0000 Subject: [PATCH] Bye. Now all those tabs are out --- mod/lesson/db/mysql.php | 214 +-- mod/lesson/db/mysql.sql | 104 +- mod/lesson/db/postgres7.php | 226 +-- mod/lesson/db/postgres7.sql | 122 +- mod/lesson/filter.php | 24 +- mod/lesson/index.php | 4 +- mod/lesson/lesson.php | 2696 +++++++++++++++++------------------ mod/lesson/lib.php | 268 ++-- mod/lesson/locallib.php | 1108 +++++++------- mod/lesson/mod.html | 176 +-- mod/lesson/reformat.php | 316 ++-- mod/lesson/report.php | 52 +- mod/lesson/styles.php | 24 +- mod/lesson/timer.js | 172 +-- mod/lesson/view.php | 1168 +++++++-------- 15 files changed, 3337 insertions(+), 3337 deletions(-) diff --git a/mod/lesson/db/mysql.php b/mod/lesson/db/mysql.php index 0a4f6f738d1..2c102533dc2 100644 --- a/mod/lesson/db/mysql.php +++ b/mod/lesson/db/mysql.php @@ -18,133 +18,133 @@ function lesson_upgrade($oldversion) { if ($oldversion < 2004022200) { - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `maxattempts` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxanswers"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `nextpagedefault` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxattempts"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `maxpages` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER nextpagedefault"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_pages` ADD `qtype` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER lessonid"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_pages` ADD `qoption` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER qtype"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_answers` ADD `grade` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER jumpto"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `maxattempts` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxanswers"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `nextpagedefault` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxattempts"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `maxpages` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER nextpagedefault"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_pages` ADD `qtype` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER lessonid"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_pages` ADD `qoption` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER qtype"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_answers` ADD `grade` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER jumpto"); } if ($oldversion < 2004032000) { // Upgrade some old beta lessons - execute_sql(" UPDATE `{$CFG->prefix}lesson_pages` SET qtype = 3 WHERE qtype = 0"); + execute_sql(" UPDATE `{$CFG->prefix}lesson_pages` SET qtype = 3 WHERE qtype = 0"); } if ($oldversion < 2004032400) { - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `usemaxgrade` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER grade"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `minquestions` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER nextpagedefault"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `usemaxgrade` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER grade"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `minquestions` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER nextpagedefault"); } if ($oldversion < 2004032700) { - table_column("lesson_answers", "", "flags", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade"); + table_column("lesson_answers", "", "flags", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade"); } - // CDC-FLAG - if ($oldversion < 2004072100) { - execute_sql(" create table ".$CFG->prefix."lesson_high_scores - ( id int(10) unsigned not null auto_increment, - lessonid int(10) unsigned not null, - userid int(10) unsigned not null, - gradeid int(10) unsigned not null, - nickname varchar(5) not null, - PRIMARY KEY (`id`) - )"); + // CDC-FLAG + if ($oldversion < 2004072100) { + execute_sql(" create table ".$CFG->prefix."lesson_high_scores + ( id int(10) unsigned not null auto_increment, + lessonid int(10) unsigned not null, + userid int(10) unsigned not null, + gradeid int(10) unsigned not null, + nickname varchar(5) not null, + PRIMARY KEY (`id`) + )"); - execute_sql(" create table ".$CFG->prefix."lesson_branch - ( id int(10) unsigned not null auto_increment, - lessonid int(10) unsigned not null, - userid int(10) unsigned not null, - pageid int(10) unsigned not null, - retry int(10) unsigned not null, - flag tinyint(3) unsigned not null, - timeseen int(10) unsigned not null, - PRIMARY KEY (`id`) - )"); + execute_sql(" create table ".$CFG->prefix."lesson_branch + ( id int(10) unsigned not null auto_increment, + lessonid int(10) unsigned not null, + userid int(10) unsigned not null, + pageid int(10) unsigned not null, + retry int(10) unsigned not null, + flag tinyint(3) unsigned not null, + timeseen int(10) unsigned not null, + PRIMARY KEY (`id`) + )"); - - execute_sql(" create table ".$CFG->prefix."lesson_timer - ( id int(10) unsigned not null auto_increment, - lessonid int(10) unsigned not null, - userid int(10) unsigned not null, - starttime int(10) unsigned not null, - lessontime int(10) unsigned not null, - PRIMARY KEY (`id`) - )"); + + execute_sql(" create table ".$CFG->prefix."lesson_timer + ( id int(10) unsigned not null auto_increment, + lessonid int(10) unsigned not null, + userid int(10) unsigned not null, + starttime int(10) unsigned not null, + lessontime int(10) unsigned not null, + PRIMARY KEY (`id`) + )"); - - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_pages` ADD `layout` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' AFTER qoption"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_pages` ADD `display` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' AFTER layout"); + + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_pages` ADD `layout` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' AFTER qoption"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_pages` ADD `display` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' AFTER layout"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_answers` ADD `score` INT(10) NOT NULL DEFAULT '0' AFTER grade"); - - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `usepassword` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER name"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `password` VARCHAR(32) NOT NULL DEFAULT '' AFTER usepassword"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `custom` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER grade"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `ongoing` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER custom"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `timed` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxpages"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `maxtime` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER timed"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `tree` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER retake"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `slideshow` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER tree"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `width` INT(10) UNSIGNED NOT NULL DEFAULT '640' AFTER slideshow"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `height` INT(10) UNSIGNED NOT NULL DEFAULT '480' AFTER width"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `bgcolor` CHAR(7) NOT NULL DEFAULT '#FFFFFF' AFTER height"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `displayleft` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER bgcolor"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `highscores` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER displayleft"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `maxhighscores` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER highscores"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_answers` ADD `score` INT(10) NOT NULL DEFAULT '0' AFTER grade"); + + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `usepassword` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER name"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `password` VARCHAR(32) NOT NULL DEFAULT '' AFTER usepassword"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `custom` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER grade"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `ongoing` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER custom"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `timed` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxpages"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `maxtime` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER timed"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `tree` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER retake"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `slideshow` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER tree"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `width` INT(10) UNSIGNED NOT NULL DEFAULT '640' AFTER slideshow"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `height` INT(10) UNSIGNED NOT NULL DEFAULT '480' AFTER width"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `bgcolor` CHAR(7) NOT NULL DEFAULT '#FFFFFF' AFTER height"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `displayleft` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER bgcolor"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `highscores` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER displayleft"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `maxhighscores` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER highscores"); - } + } - if ($oldversion < 2004081100) { - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `practice` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER name"); - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `review` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxattempts"); - } - - if ($oldversion < 2004081700) { - execute_sql("CREATE TABLE `{$CFG->prefix}lesson_default` - ( `id` int(10) unsigned NOT NULL auto_increment, - `course` int(10) unsigned NOT NULL default '0', - `practice` tinyint(3) unsigned NOT NULL default '0', - `password` varchar(32) NOT NULL default '', - `usepassword` int(3) unsigned NOT NULL default '0', - `grade` tinyint(3) NOT NULL default '0', - `custom` int(3) unsigned NOT NULL default '0', - `ongoing` int(3) unsigned NOT NULL default '0', - `usemaxgrade` tinyint(3) unsigned NOT NULL default '0', - `maxanswers` int(3) unsigned NOT NULL default '4', - `maxattempts` int(3) unsigned NOT NULL default '5', - `review` tinyint(3) unsigned NOT NULL default '0', - `nextpagedefault` int(3) unsigned NOT NULL default '0', - `minquestions` tinyint(3) unsigned NOT NULL default '0', - `maxpages` int(3) unsigned NOT NULL default '0', - `timed` int(3) unsigned NOT NULL default '0', - `maxtime` int(10) unsigned NOT NULL default '0', - `retake` int(3) unsigned NOT NULL default '1', - `tree` int(3) unsigned NOT NULL default '0', - `slideshow` int(3) unsigned NOT NULL default '0', - `width` int(10) unsigned NOT NULL default '640', - `height` int(10) unsigned NOT NULL default '480', - `bgcolor` varchar(7) default '#FFFFFF', - `displayleft` int(3) unsigned NOT NULL default '0', - `highscores` int(3) unsigned NOT NULL default '0', - `maxhighscores` int(10) NOT NULL default '0', - PRIMARY KEY (`id`) - ) COMMENT = 'Defines lesson_default'"); - } + if ($oldversion < 2004081100) { + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `practice` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER name"); + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `review` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxattempts"); + } + + if ($oldversion < 2004081700) { + execute_sql("CREATE TABLE `{$CFG->prefix}lesson_default` + ( `id` int(10) unsigned NOT NULL auto_increment, + `course` int(10) unsigned NOT NULL default '0', + `practice` tinyint(3) unsigned NOT NULL default '0', + `password` varchar(32) NOT NULL default '', + `usepassword` int(3) unsigned NOT NULL default '0', + `grade` tinyint(3) NOT NULL default '0', + `custom` int(3) unsigned NOT NULL default '0', + `ongoing` int(3) unsigned NOT NULL default '0', + `usemaxgrade` tinyint(3) unsigned NOT NULL default '0', + `maxanswers` int(3) unsigned NOT NULL default '4', + `maxattempts` int(3) unsigned NOT NULL default '5', + `review` tinyint(3) unsigned NOT NULL default '0', + `nextpagedefault` int(3) unsigned NOT NULL default '0', + `minquestions` tinyint(3) unsigned NOT NULL default '0', + `maxpages` int(3) unsigned NOT NULL default '0', + `timed` int(3) unsigned NOT NULL default '0', + `maxtime` int(10) unsigned NOT NULL default '0', + `retake` int(3) unsigned NOT NULL default '1', + `tree` int(3) unsigned NOT NULL default '0', + `slideshow` int(3) unsigned NOT NULL default '0', + `width` int(10) unsigned NOT NULL default '640', + `height` int(10) unsigned NOT NULL default '480', + `bgcolor` varchar(7) default '#FFFFFF', + `displayleft` int(3) unsigned NOT NULL default '0', + `highscores` int(3) unsigned NOT NULL default '0', + `maxhighscores` int(10) NOT NULL default '0', + PRIMARY KEY (`id`) + ) COMMENT = 'Defines lesson_default'"); + } - if ($oldversion < 2004100400) { - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_attempts` ADD `useranswer` text NOT NULL AFTER correct"); - } - - if ($oldversion < 2004100700) { - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `modattempts` tinyint(3) unsigned NOT NULL default '0' AFTER practice"); - } + if ($oldversion < 2004100400) { + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_attempts` ADD `useranswer` text NOT NULL AFTER correct"); + } + + if ($oldversion < 2004100700) { + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `modattempts` tinyint(3) unsigned NOT NULL default '0' AFTER practice"); + } - if ($oldversion < 2004102600) { - execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_default` ADD `modattempts` tinyint(3) unsigned NOT NULL default '0' AFTER practice"); - } + if ($oldversion < 2004102600) { + execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_default` ADD `modattempts` tinyint(3) unsigned NOT NULL default '0' AFTER practice"); + } - // CDC-FLAG end + // CDC-FLAG end if ($oldversion < 2004111200) { execute_sql("ALTER TABLE {$CFG->prefix}lesson DROP INDEX course;",false); @@ -165,7 +165,7 @@ function lesson_upgrade($oldversion) { } - + return true; } diff --git a/mod/lesson/db/mysql.sql b/mod/lesson/db/mysql.sql index 0a3bd1cd20d..866079db9ad 100644 --- a/mod/lesson/db/mysql.sql +++ b/mod/lesson/db/mysql.sql @@ -108,67 +108,67 @@ CREATE TABLE `prefix_lesson_grades` ( # -------------------------------------------------------- CREATE TABLE `prefix_lesson_default` - ( `id` int(10) unsigned NOT NULL auto_increment, - `course` int(10) unsigned NOT NULL default '0', - `practice` tinyint(3) unsigned NOT NULL default '0', - `modattempts` tinyint(3) unsigned NOT NULL default '0', - `password` varchar(32) NOT NULL default '', - `usepassword` int(3) unsigned NOT NULL default '0', - `grade` tinyint(3) NOT NULL default '0', - `custom` int(3) unsigned NOT NULL default '0', - `ongoing` int(3) unsigned NOT NULL default '0', - `usemaxgrade` tinyint(3) unsigned NOT NULL default '0', - `maxanswers` int(3) unsigned NOT NULL default '4', - `maxattempts` int(3) unsigned NOT NULL default '5', - `review` tinyint(3) unsigned NOT NULL default '0', - `nextpagedefault` int(3) unsigned NOT NULL default '0', - `minquestions` tinyint(3) unsigned NOT NULL default '0', - `maxpages` int(3) unsigned NOT NULL default '0', - `timed` int(3) unsigned NOT NULL default '0', - `maxtime` int(10) unsigned NOT NULL default '0', - `retake` int(3) unsigned NOT NULL default '1', - `tree` int(3) unsigned NOT NULL default '0', - `slideshow` int(3) unsigned NOT NULL default '0', - `width` int(10) unsigned NOT NULL default '640', - `height` int(10) unsigned NOT NULL default '480', - `bgcolor` varchar(7) default '#FFFFFF', - `displayleft` int(3) unsigned NOT NULL default '0', - `highscores` int(3) unsigned NOT NULL default '0', - `maxhighscores` int(10) NOT NULL default '0', - PRIMARY KEY (`id`) - ) COMMENT = 'Defines lesson_default'; + ( `id` int(10) unsigned NOT NULL auto_increment, + `course` int(10) unsigned NOT NULL default '0', + `practice` tinyint(3) unsigned NOT NULL default '0', + `modattempts` tinyint(3) unsigned NOT NULL default '0', + `password` varchar(32) NOT NULL default '', + `usepassword` int(3) unsigned NOT NULL default '0', + `grade` tinyint(3) NOT NULL default '0', + `custom` int(3) unsigned NOT NULL default '0', + `ongoing` int(3) unsigned NOT NULL default '0', + `usemaxgrade` tinyint(3) unsigned NOT NULL default '0', + `maxanswers` int(3) unsigned NOT NULL default '4', + `maxattempts` int(3) unsigned NOT NULL default '5', + `review` tinyint(3) unsigned NOT NULL default '0', + `nextpagedefault` int(3) unsigned NOT NULL default '0', + `minquestions` tinyint(3) unsigned NOT NULL default '0', + `maxpages` int(3) unsigned NOT NULL default '0', + `timed` int(3) unsigned NOT NULL default '0', + `maxtime` int(10) unsigned NOT NULL default '0', + `retake` int(3) unsigned NOT NULL default '1', + `tree` int(3) unsigned NOT NULL default '0', + `slideshow` int(3) unsigned NOT NULL default '0', + `width` int(10) unsigned NOT NULL default '640', + `height` int(10) unsigned NOT NULL default '480', + `bgcolor` varchar(7) default '#FFFFFF', + `displayleft` int(3) unsigned NOT NULL default '0', + `highscores` int(3) unsigned NOT NULL default '0', + `maxhighscores` int(10) NOT NULL default '0', + PRIMARY KEY (`id`) + ) COMMENT = 'Defines lesson_default'; # -------------------------------------------------------- CREATE TABLE `prefix_lesson_timer` - ( `id` int(10) unsigned NOT NULL auto_increment, - `lessonid` int(10) unsigned not null, - `userid` int(10) unsigned not null, - `starttime` int(10) unsigned not null, - `lessontime` int(10) unsigned not null, - PRIMARY KEY (`id`) - ); + ( `id` int(10) unsigned NOT NULL auto_increment, + `lessonid` int(10) unsigned not null, + `userid` int(10) unsigned not null, + `starttime` int(10) unsigned not null, + `lessontime` int(10) unsigned not null, + PRIMARY KEY (`id`) + ); # -------------------------------------------------------- CREATE TABLE `prefix_lesson_branch` - ( `id` int(10) unsigned not null auto_increment, - `lessonid` int(10) unsigned not null, - `userid` int(10) unsigned not null, - `pageid` int(10) unsigned not null, - `retry` int(10) unsigned not null, - `flag` tinyint(3) unsigned not null, - `timeseen` int(10) unsigned not null, - PRIMARY KEY (`id`) - ); + ( `id` int(10) unsigned not null auto_increment, + `lessonid` int(10) unsigned not null, + `userid` int(10) unsigned not null, + `pageid` int(10) unsigned not null, + `retry` int(10) unsigned not null, + `flag` tinyint(3) unsigned not null, + `timeseen` int(10) unsigned not null, + PRIMARY KEY (`id`) + ); # -------------------------------------------------------- CREATE TABLE `prefix_lesson_high_scores` - ( `id` int(10) unsigned not null auto_increment, - `lessonid` int(10) unsigned not null, - `userid` int(10) unsigned not null, - `gradeid` int(10) unsigned not null, - `nickname` varchar(5) not null, - PRIMARY KEY (`id`) - ); + ( `id` int(10) unsigned not null auto_increment, + `lessonid` int(10) unsigned not null, + `userid` int(10) unsigned not null, + `gradeid` int(10) unsigned not null, + `nickname` varchar(5) not null, + PRIMARY KEY (`id`) + ); # -------------------------------------------------------- diff --git a/mod/lesson/db/postgres7.php b/mod/lesson/db/postgres7.php index 7a1bf0e82c1..986cc88b076 100644 --- a/mod/lesson/db/postgres7.php +++ b/mod/lesson/db/postgres7.php @@ -18,177 +18,177 @@ function lesson_upgrade($oldversion) { if ($oldversion < 2004022200) { - table_column("lesson", "", "maxattempts", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "maxanswers"); - table_column("lesson", "", "nextpagedefault", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "maxattempts"); - table_column("lesson", "", "maxpages", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "nextpagedefault"); - table_column("lesson_pages", "", "qtype", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "lessonid"); - table_column("lesson_pages", "", "qoption", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "qtype"); - table_column("lesson_answers", "", "grade", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "jumpto"); + table_column("lesson", "", "maxattempts", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "maxanswers"); + table_column("lesson", "", "nextpagedefault", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "maxattempts"); + table_column("lesson", "", "maxpages", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "nextpagedefault"); + table_column("lesson_pages", "", "qtype", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "lessonid"); + table_column("lesson_pages", "", "qoption", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "qtype"); + table_column("lesson_answers", "", "grade", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "jumpto"); } if ($oldversion < 2004032000) { // Upgrade some old beta lessons - execute_sql(" UPDATE \"{$CFG->prefix}lesson_pages\" SET qtype = 3 WHERE qtype = 0"); + execute_sql(" UPDATE \"{$CFG->prefix}lesson_pages\" SET qtype = 3 WHERE qtype = 0"); } if ($oldversion < 2004032400) { - table_column("lesson", "", "usemaxgrade", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade"); - table_column("lesson", "", "minquestions", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "nextpagedefault"); + table_column("lesson", "", "usemaxgrade", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade"); + table_column("lesson", "", "minquestions", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "nextpagedefault"); } if ($oldversion < 2004032700) { - table_column("lesson_answers", "", "flags", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade"); + table_column("lesson_answers", "", "flags", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade"); } // CDC-FLAG - if ($oldversion < 2004072100) { - execute_sql(" create table ".$CFG->prefix."lesson_high_scores - ( id serial8 primary key, - lessonid int8 not null, - userid int8 not null, - gradeid int8 not null, - nickname varchar(5) not null - )"); + if ($oldversion < 2004072100) { + execute_sql(" create table ".$CFG->prefix."lesson_high_scores + ( id serial8 primary key, + lessonid int8 not null, + userid int8 not null, + gradeid int8 not null, + nickname varchar(5) not null + )"); - execute_sql(" create table ".$CFG->prefix."lesson_essay - ( id serial8 primary key, - lessonid int8 not null, - userid int8 not null, - pageid int8 not null, - answerid int8 not null, - try int8 not null, - answer text not null, - graded int4 not null default 0, - score int8 not null default 0, - response text not null, - sent int4 not null default 0, - timesubmitted int8 not null - )"); + execute_sql(" create table ".$CFG->prefix."lesson_essay + ( id serial8 primary key, + lessonid int8 not null, + userid int8 not null, + pageid int8 not null, + answerid int8 not null, + try int8 not null, + answer text not null, + graded int4 not null default 0, + score int8 not null default 0, + response text not null, + sent int4 not null default 0, + timesubmitted int8 not null + )"); - execute_sql(" create table ".$CFG->prefix."lesson_branch - ( id serial8 primary key, - lessonid int8 not null, - userid int8 not null, - pageid int8 not null, - retry int8 not null, - flag int4 not null, - timeseen int8 not null - )"); + execute_sql(" create table ".$CFG->prefix."lesson_branch + ( id serial8 primary key, + lessonid int8 not null, + userid int8 not null, + pageid int8 not null, + retry int8 not null, + flag int4 not null, + timeseen int8 not null + )"); - - execute_sql(" create table ".$CFG->prefix."lesson_timer - ( id serial8 primary key, - lessonid int8 not null, - userid int8 not null, - starttime int8 not null, - lessontime int8 not null - )"); + + execute_sql(" create table ".$CFG->prefix."lesson_timer + ( id serial8 primary key, + lessonid int8 not null, + userid int8 not null, + starttime int8 not null, + lessontime int8 not null + )"); - + - //execute_sql(" ALTER TABLE {$CFG->prefix}lesson_pages ADD layout TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' AFTER qoption"); + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson_pages ADD layout TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' AFTER qoption"); table_column('lesson_pages','','layout','int','3','unsigned', '1', 'not null', 'qoption'); - //execute_sql(" ALTER TABLE {$CFG->prefix}lesson_pages ADD display TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' AFTER layout"); + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson_pages ADD display TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' AFTER layout"); table_column('lesson_pages','','display','int','3','unsigned', '1', 'not null', 'layout'); - //execute_sql(" ALTER TABLE {$CFG->prefix}lesson_answers ADD score INT(10) NOT NULL DEFAULT '0' AFTER grade"); + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson_answers ADD score INT(10) NOT NULL DEFAULT '0' AFTER grade"); table_column('lesson_answers','','score','int','10','unsigned', '1', 'not null', 'grade'); - //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD usepassword TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER name"); + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD usepassword TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER name"); table_column('lesson','','usepassword','int','3','unsigned', '0', 'not null', 'name'); - + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD password VARCHAR(32) NOT NULL DEFAULT '' AFTER usepassword"); table_column('lesson','','password','varchar','32','', '', 'not null', 'usepassword'); - + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD custom TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER grade"); table_column('lesson','','custom','int','3','unsigned', '0', 'not null', 'grade'); - + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD ongoing TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER custom"); table_column('lesson','','ongoing','int','3','unsigned', '0', 'not null', 'custom'); - + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD timed TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxpages"); table_column('lesson','','timed','int','3','unsigned', '0', 'not null', 'maxpages'); - + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD maxtime INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER timed"); table_column('lesson','','maxtime','int','10','unsigned', '0', 'not null', 'timed'); - + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD tree TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER retake"); table_column('lesson','','tree','int','3','unsigned', '0', 'not null', 'retake'); - + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD slideshow TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER tree"); table_column('lesson','','slideshow','int','3','unsigned', '0', 'not null', 'tree'); - + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD width INT(10) UNSIGNED NOT NULL DEFAULT '640' AFTER slideshow"); table_column('lesson','','width','int','10','unsigned', '640', 'not null', 'slideshow'); - + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD height INT(10) UNSIGNED NOT NULL DEFAULT '480' AFTER width"); table_column('lesson','','height','int','10','unsigned', '480', 'not null', 'width'); - + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD bgcolor CHAR(7) NOT NULL DEFAULT '#FFFFFF' AFTER height"); table_column('lesson','','bgcolor','varchar','7','unsigned', '#FFFFFF', 'not null', 'height'); - + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD displayleft TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER bgcolor"); table_column('lesson','','displayleft','int','3','unsigned', '0', 'not null', 'bgcolor'); - + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD highscores TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER displayleft"); table_column('lesson','','highscores','int','3','unsigned', '0', 'not null', 'displayleft'); - + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD maxhighscores INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER highscores"); table_column('lesson','','maxhighscores','int','10','unsigned', '0', 'not null', 'highscores'); - } + } - if ($oldversion < 2004081100) { - //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD practice TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER name"); + if ($oldversion < 2004081100) { + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD practice TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER name"); table_column('lesson','','practice','int','3','unsigned', '0', 'not null', 'name'); - //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD review TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxattempts"); + //execute_sql(" ALTER TABLE {$CFG->prefix}lesson ADD review TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' AFTER maxattempts"); table_column('lesson','','review','int','3','unsigned', '0', 'not null', 'maxattempts'); - } - - if ($oldversion < 2004081700) { - execute_sql("CREATE TABLE {$CFG->prefix}lesson_default - ( id serial8 primary key, - course int8 NOT NULL default '0', - practice int4 NOT NULL default '0', - password varchar(32) NOT NULL default '', - usepassword int4 NOT NULL default '0', - grade int4 NOT NULL default '0', - custom int4 NOT NULL default '0', - ongoing int4 NOT NULL default '0', - usemaxgrade int4 NOT NULL default '0', - maxanswers int4 NOT NULL default '4', - maxattempts int4 NOT NULL default '5', - review int4 NOT NULL default '0', - nextpagedefault int4 NOT NULL default '0', - minquestions int4 NOT NULL default '0', - maxpages int4 NOT NULL default '0', - timed int4 NOT NULL default '0', - maxtime int8 NOT NULL default '0', - retake int4 NOT NULL default '1', - tree int4 NOT NULL default '0', - slideshow int4 NOT NULL default '0', - width int8 NOT NULL default '640', - height int8 NOT NULL default '480', - bgcolor varchar(7) default '#FFFFFF', - displayleft int4 NOT NULL default '0', - highscores int4 NOT NULL default '0', - maxhighscores int8 NOT NULL default '0' - )"); - } - // CDC-FLAG end + } + + if ($oldversion < 2004081700) { + execute_sql("CREATE TABLE {$CFG->prefix}lesson_default + ( id serial8 primary key, + course int8 NOT NULL default '0', + practice int4 NOT NULL default '0', + password varchar(32) NOT NULL default '', + usepassword int4 NOT NULL default '0', + grade int4 NOT NULL default '0', + custom int4 NOT NULL default '0', + ongoing int4 NOT NULL default '0', + usemaxgrade int4 NOT NULL default '0', + maxanswers int4 NOT NULL default '4', + maxattempts int4 NOT NULL default '5', + review int4 NOT NULL default '0', + nextpagedefault int4 NOT NULL default '0', + minquestions int4 NOT NULL default '0', + maxpages int4 NOT NULL default '0', + timed int4 NOT NULL default '0', + maxtime int8 NOT NULL default '0', + retake int4 NOT NULL default '1', + tree int4 NOT NULL default '0', + slideshow int4 NOT NULL default '0', + width int8 NOT NULL default '640', + height int8 NOT NULL default '480', + bgcolor varchar(7) default '#FFFFFF', + displayleft int4 NOT NULL default '0', + highscores int4 NOT NULL default '0', + maxhighscores int8 NOT NULL default '0' + )"); + } + // CDC-FLAG end if ($oldversion < 2004100400) { - //execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_attempts` ADD `useranswer` text NOT NULL AFTER correct"); + //execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_attempts` ADD `useranswer` text NOT NULL AFTER correct"); table_column('lesson_attempts', '', 'useranswer', 'text', '', '', '', 'NOT NULL', 'correct'); - } - - if ($oldversion < 2004100700) { - //execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `modattempts` tinyint(3) unsigned NOT NULL default '0' AFTER practice"); + } + + if ($oldversion < 2004100700) { + //execute_sql(" ALTER TABLE `{$CFG->prefix}lesson` ADD `modattempts` tinyint(3) unsigned NOT NULL default '0' AFTER practice"); table_column('lesson', '', 'modattempts', 'INT', '4', 'unsigned', '0', 'NOT NULL', 'practice'); - } + } - if ($oldversion < 2004102600) { - //execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_default` ADD `modattempts` tinyint(3) unsigned NOT NULL default '0' AFTER practice"); + if ($oldversion < 2004102600) { + //execute_sql(" ALTER TABLE `{$CFG->prefix}lesson_default` ADD `modattempts` tinyint(3) unsigned NOT NULL default '0' AFTER practice"); table_column('lesson_default', '', 'modattempts', 'INT', '4', 'unsigned', '0', 'NOT NULL', 'practice'); - } + } if ($oldversion < 2004111200) { execute_sql("DROP INDEX {$CFG->prefix}lesson_course_idx;",false); diff --git a/mod/lesson/db/postgres7.sql b/mod/lesson/db/postgres7.sql index c4ecbbac62b..c7d285aa525 100644 --- a/mod/lesson/db/postgres7.sql +++ b/mod/lesson/db/postgres7.sql @@ -96,75 +96,75 @@ CREATE INDEX prefix_lesson_grades_lessonid_idx ON prefix_lesson_grades (lessonid CREATE INDEX prefix_lesson_grades_userid_idx ON prefix_lesson_grades (userid); CREATE TABLE prefix_lesson_default - ( id SERIAL8 PRIMARY KEY, - course INT8 NOT NULL default '0', - practice INT NOT NULL default '0', - modattempts INT4 NOT NULL default '0', - password varchar(32) NOT NULL default '', - usepassword INT NOT NULL default '0', - grade INT NOT NULL default '0', - custom INT NOT NULL default '0', - ongoing INT NOT NULL default '0', - usemaxgrade INT NOT NULL default '0', - maxanswers INT NOT NULL default '4', - maxattempts INT NOT NULL default '5', - review INT NOT NULL default '0', - nextpagedefault INT NOT NULL default '0', - minquestions INT NOT NULL default '0', - maxpages INT NOT NULL default '0', - timed INT NOT NULL default '0', - maxtime INT8 NOT NULL default '0', - retake INT NOT NULL default '1', - tree INT NOT NULL default '0', - slideshow INT NOT NULL default '0', - width INT8 NOT NULL default '640', - height INT8 NOT NULL default '480', - bgcolor varchar(7) default '#FFFFFF', - displayleft INT NOT NULL default '0', - highscores INT NOT NULL default '0', - maxhighscores INT8 NOT NULL default '0' - ) ; + ( id SERIAL8 PRIMARY KEY, + course INT8 NOT NULL default '0', + practice INT NOT NULL default '0', + modattempts INT4 NOT NULL default '0', + password varchar(32) NOT NULL default '', + usepassword INT NOT NULL default '0', + grade INT NOT NULL default '0', + custom INT NOT NULL default '0', + ongoing INT NOT NULL default '0', + usemaxgrade INT NOT NULL default '0', + maxanswers INT NOT NULL default '4', + maxattempts INT NOT NULL default '5', + review INT NOT NULL default '0', + nextpagedefault INT NOT NULL default '0', + minquestions INT NOT NULL default '0', + maxpages INT NOT NULL default '0', + timed INT NOT NULL default '0', + maxtime INT8 NOT NULL default '0', + retake INT NOT NULL default '1', + tree INT NOT NULL default '0', + slideshow INT NOT NULL default '0', + width INT8 NOT NULL default '640', + height INT8 NOT NULL default '480', + bgcolor varchar(7) default '#FFFFFF', + displayleft INT NOT NULL default '0', + highscores INT NOT NULL default '0', + maxhighscores INT8 NOT NULL default '0' + ) ; CREATE TABLE prefix_lesson_timer - ( id SERIAL8 PRIMARY KEY, - lessonid INT8 not null, - userid INT8 not null, - starttime INT8 not null, - lessontime INT8 not null - ); + ( id SERIAL8 PRIMARY KEY, + lessonid INT8 not null, + userid INT8 not null, + starttime INT8 not null, + lessontime INT8 not null + ); CREATE TABLE prefix_lesson_branch - ( id SERIAL8 PRIMARY KEY, - lessonid INT8 not null, - userid INT8 not null, - pageid INT8 not null, - retry INT8 not null, - flag INT not null, - timeseen INT8 not null - ); + ( id SERIAL8 PRIMARY KEY, + lessonid INT8 not null, + userid INT8 not null, + pageid INT8 not null, + retry INT8 not null, + flag INT not null, + timeseen INT8 not null + ); CREATE TABLE prefix_lesson_essay - ( id SERIAL8 PRIMARY KEY, - lessonid INT8 not null, - userid INT8 not null, - pageid INT8 not null, - answerid INT8 not null, - try INT8 not null, - answer text not null, - graded INT not null default 0, - score INT8 not null default 0, - response text not null, - sent INT not null default 0, - timesubmitted INT8 not null - ); + ( id SERIAL8 PRIMARY KEY, + lessonid INT8 not null, + userid INT8 not null, + pageid INT8 not null, + answerid INT8 not null, + try INT8 not null, + answer text not null, + graded INT not null default 0, + score INT8 not null default 0, + response text not null, + sent INT not null default 0, + timesubmitted INT8 not null + ); CREATE TABLE prefix_lesson_high_scores - ( id SERIAL8 PRIMARY KEY, - lessonid INT8 not null, - userid INT8 not null, - gradeid INT8 not null, - nickname varchar(5) not null - ); + ( id SERIAL8 PRIMARY KEY, + lessonid INT8 not null, + userid INT8 not null, + gradeid INT8 not null, + nickname varchar(5) not null + ); INSERT INTO prefix_log_display VALUES ('lesson', 'start', 'lesson', 'name'); diff --git a/mod/lesson/filter.php b/mod/lesson/filter.php index c8f2f3e4d06..862bb160363 100644 --- a/mod/lesson/filter.php +++ b/mod/lesson/filter.php @@ -1,13 +1,13 @@ \ No newline at end of file + // bad words < 5 characters long + $filterwords = array ( + "shit", + "fuck", + "dick", + "cunt", + "pussy", + "hore", + "whore", + "damn" + ); +?> diff --git a/mod/lesson/index.php b/mod/lesson/index.php index ba5641d2bf2..e9611ddc66a 100644 --- a/mod/lesson/index.php +++ b/mod/lesson/index.php @@ -3,7 +3,7 @@ /// This page lists all the instances of lesson in a particular course require_once("../../config.php"); - require_once("locallib.php"); + require_once("locallib.php"); require_variable($id); // course @@ -45,7 +45,7 @@ $strdeadline = get_string("deadline", "lesson"); $strweek = get_string("week"); $strtopic = get_string("topic"); - $table = new stdClass; + $table = new stdClass; if ($course->format == "weeks") { $table->head = array ($strweek, $strname, $strgrade, $strdeadline); diff --git a/mod/lesson/lesson.php b/mod/lesson/lesson.php index 0a14e049399..ea97191a4f6 100644 --- a/mod/lesson/lesson.php +++ b/mod/lesson/lesson.php @@ -1,44 +1,44 @@ course)) { - error("Course is misconfigured"); - } + if (! $course = get_record("course", "id", $cm->course)) { + error("Course is misconfigured"); + } - if (! $lesson = get_record("lesson", "id", $cm->instance)) { - error("Course module is incorrect"); - } + if (! $lesson = get_record("lesson", "id", $cm->instance)) { + error("Course module is incorrect"); + } require_login($course->id); - + // set up some general variables $usehtmleditor = can_use_html_editor(); @@ -50,58 +50,58 @@ $strlessons = get_string("modulenameplural", "lesson"); $strlesson = get_string("modulename", "lesson"); $strlessonname = $lesson->name; - - // ... print the header and... + + // ... print the header and... print_header("$course->shortname: $lesson->name", "$course->fullname", "$navigation id>$strlessons -> id\">$lesson->name", "", "", true); - //...get the action - $action = required_param('action'); - - /************** add branch table ************************************/ - if ($action == 'addbranchtable' ) { + //...get the action + $action = required_param('action'); + + /************** add branch table ************************************/ + if ($action == 'addbranchtable' ) { - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } // first get the preceeding page $pageid = required_param('pageid', PARAM_INT); // set of jump array $jump = array(); - $jump[0] = get_string("thispage", "lesson"); + $jump[0] = get_string("thispage", "lesson"); $jump[LESSON_NEXTPAGE] = get_string("nextpage", "lesson"); - //// CDC-FLAG ///// - $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson"); - if (!isset($_GET['firstpage'])) { - $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); - if (!$apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { - error("Add page: first page not found"); - } - while (true) { - if ($apageid) { - $title = get_field("lesson_pages", "title", "id", $apageid); - $jump[$apageid] = $title; - $apageid = get_field("lesson_pages", "nextpageid", "id", $apageid); - } else { - // last page reached - break; - } - } - } - //// CDC-FLAG ///// + //// CDC-FLAG ///// + $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson"); + if (!isset($_GET['firstpage'])) { + $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); + if (!$apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { + error("Add page: first page not found"); + } + while (true) { + if ($apageid) { + $title = get_field("lesson_pages", "title", "id", $apageid); + $jump[$apageid] = $title; + $apageid = get_field("lesson_pages", "nextpageid", "id", $apageid); + } else { + // last page reached + break; + } + } + } + //// CDC-FLAG ///// // give teacher a blank proforma - print_heading_with_help(get_string("addabranchtable", "lesson"), "overview", "lesson"); + print_heading_with_help(get_string("addabranchtable", "lesson"), "overview", "lesson"); ?>
- +
@@ -112,21 +112,21 @@ echo get_string("pagecontents", "lesson").":
\n"; print_textarea($usehtmleditor, 25,70, 630, 400, "contents"); use_html_editor("contents"); - echo "\n"; - /// CDC-FLAG /// 6/16/04 - echo "\n"; - /// CDC-FLAG /// + echo "\n"; + /// CDC-FLAG /// 6/16/04 + echo "\n"; + /// CDC-FLAG /// for ($i = 0; $i < $lesson->maxanswers; $i++) { $iplus1 = $i + 1; echo "\n"; + echo "\n"; echo "
\n"; - echo "
"; - echo get_string("arrangebuttonshorizontally", "lesson")."\n"; - echo "
"; - echo get_string("displayinleftmenu", "lesson"); - echo "
\n"; - echo "
\n"; + echo "
"; + echo get_string("arrangebuttonshorizontally", "lesson")."\n"; + echo "
"; + echo get_string("displayinleftmenu", "lesson"); + echo "
\n"; + echo "
".get_string("description", "lesson")." $iplus1:
\n"; print_textarea(false, 10, 70, 630, 300, "answer[$i]"); // made the default set to off also removed use_html_editor(); line from down below, which made all textareas turn into html editors - echo "
".get_string("jump", "lesson")." $iplus1: \n"; if ($i) { // answers 2, 3, 4... jumpto this page @@ -146,17 +146,17 @@ id)) { - error("Only teachers can look at this page"); - } + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } - confirm_sesskey(); + confirm_sesskey(); // first get the preceeding page $pageid = required_param('pageid', PARAM_INT); @@ -179,7 +179,7 @@ } } if ($btpage->qtype == LESSON_BRANCHTABLE) { - $newpage = new stdClass; + $newpage = new stdClass; $newpage->lessonid = $lesson->id; $newpage->prevpageid = $pageid; $newpage->nextpageid = $page->nextpageid; @@ -201,7 +201,7 @@ } } // ..and the single "answer" - $newanswer = new stdClass; + $newanswer = new stdClass; $newanswer->lessonid = $lesson->id; $newanswer->pageid = $newpageid; $newanswer->timecreated = $timenow; @@ -213,86 +213,86 @@ } else { notice(get_string("nobranchtablefound", "lesson"), "view.php?id=$cm->id"); } - } + } -/// CDC-FLAG 6/17/04 /// - /************** add cluster ************************************/ +/// CDC-FLAG 6/17/04 /// + /************** add cluster ************************************/ elseif ($action == 'addcluster' ) { - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } - - confirm_sesskey(); + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } + + confirm_sesskey(); // first get the preceeding page - // if $pageid = 0, then we are inserting a new page at the beginning of the lesson + // if $pageid = 0, then we are inserting a new page at the beginning of the lesson $pageid = required_param('pageid', PARAM_INT); $timenow = time(); - if ($pageid == 0) { - if (!$page = get_record("lesson_pages", "prevpageid", 0, "lessonid", $lesson->id)) { - error("Error: Add cluster: page record not found"); - } - } else { - if (!$page = get_record("lesson_pages", "id", $pageid)) { - error("Error: Add cluster: page record not found"); - } - } + if ($pageid == 0) { + if (!$page = get_record("lesson_pages", "prevpageid", 0, "lessonid", $lesson->id)) { + error("Error: Add cluster: page record not found"); + } + } else { + if (!$page = get_record("lesson_pages", "id", $pageid)) { + error("Error: Add cluster: page record not found"); + } + } $newpage = new stdClass; - $newpage->lessonid = $lesson->id; - $newpage->prevpageid = $pageid; - if ($pageid != 0) { - $newpage->nextpageid = $page->nextpageid; - } else { - $newpage->nextpageid = $page->id; - } - $newpage->qtype = LESSON_CLUSTER; - $newpage->timecreated = $timenow; - $newpage->title = get_string("clustertitle", "lesson"); - $newpage->contents = get_string("clustertitle", "lesson"); - if (!$newpageid = insert_record("lesson_pages", $newpage)) { - error("Insert page: new page not inserted"); - } - // update the linked list... - if ($pageid != 0) { - if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $pageid)) { - error("Add cluster: unable to update link"); - } - } - - if ($pageid == 0) { - $page->nextpageid = $page->id; - } - if ($page->nextpageid) { - // the new page is not the last page - if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->nextpageid)) { - error("Insert page: unable to update previous link"); - } - } - // ..and the single "answer" - $newanswer = new stdClass; - $newanswer->lessonid = $lesson->id; - $newanswer->pageid = $newpageid; - $newanswer->timecreated = $timenow; - $newanswer->jumpto = LESSON_CLUSTERJUMP; - if(!$newanswerid = insert_record("lesson_answers", $newanswer)) { - error("Add cluster: answer record not inserted"); - } - redirect("view.php?id=$cm->id", get_string('addedcluster', 'lesson')); - } -/// CDC-FLAG /// + $newpage->lessonid = $lesson->id; + $newpage->prevpageid = $pageid; + if ($pageid != 0) { + $newpage->nextpageid = $page->nextpageid; + } else { + $newpage->nextpageid = $page->id; + } + $newpage->qtype = LESSON_CLUSTER; + $newpage->timecreated = $timenow; + $newpage->title = get_string("clustertitle", "lesson"); + $newpage->contents = get_string("clustertitle", "lesson"); + if (!$newpageid = insert_record("lesson_pages", $newpage)) { + error("Insert page: new page not inserted"); + } + // update the linked list... + if ($pageid != 0) { + if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $pageid)) { + error("Add cluster: unable to update link"); + } + } + + if ($pageid == 0) { + $page->nextpageid = $page->id; + } + if ($page->nextpageid) { + // the new page is not the last page + if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->nextpageid)) { + error("Insert page: unable to update previous link"); + } + } + // ..and the single "answer" + $newanswer = new stdClass; + $newanswer->lessonid = $lesson->id; + $newanswer->pageid = $newpageid; + $newanswer->timecreated = $timenow; + $newanswer->jumpto = LESSON_CLUSTERJUMP; + if(!$newanswerid = insert_record("lesson_answers", $newanswer)) { + error("Add cluster: answer record not inserted"); + } + redirect("view.php?id=$cm->id", get_string('addedcluster', 'lesson')); + } +/// CDC-FLAG /// -/// CDC-FLAG 6/17/04 /// - /************** add end of cluster ************************************/ +/// CDC-FLAG 6/17/04 /// + /************** add end of cluster ************************************/ elseif ($action == 'addendofcluster' ) { - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } - confirm_sesskey(); + confirm_sesskey(); // first get the preceeding page $pageid = required_param('pageid', PARAM_INT); @@ -301,125 +301,125 @@ // the new page is not the first page (end of cluster always comes after an existing page) if (!$page = get_record("lesson_pages", "id", $pageid)) { - error("Error: Could not find page"); + error("Error: Could not find page"); } - - // could put code in here to check if the user really can insert an end of cluster - - $newpage = new stdClass; - $newpage->lessonid = $lesson->id; - $newpage->prevpageid = $pageid; - $newpage->nextpageid = $page->nextpageid; - $newpage->qtype = LESSON_ENDOFCLUSTER; - $newpage->timecreated = $timenow; - $newpage->title = get_string("endofclustertitle", "lesson"); - $newpage->contents = get_string("endofclustertitle", "lesson"); - if (!$newpageid = insert_record("lesson_pages", $newpage)) { - error("Insert page: end of cluster page not inserted"); - } - // update the linked list... - if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $pageid)) { - error("Add end of cluster: unable to update link"); - } - if ($page->nextpageid) { - // the new page is not the last page - if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->nextpageid)) { - error("Insert end of cluster: unable to update previous link"); - } - } - // ..and the single "answer" - $newanswer = new stdClass; - $newanswer->lessonid = $lesson->id; - $newanswer->pageid = $newpageid; - $newanswer->timecreated = $timenow; - $newanswer->jumpto = LESSON_NEXTPAGE; - if(!$newanswerid = insert_record("lesson_answers", $newanswer)) { - error("Add end of cluster: answer record not inserted"); - } - redirect("view.php?id=$cm->id", get_string('addedendofcluster', 'lesson')); - } + + // could put code in here to check if the user really can insert an end of cluster + + $newpage = new stdClass; + $newpage->lessonid = $lesson->id; + $newpage->prevpageid = $pageid; + $newpage->nextpageid = $page->nextpageid; + $newpage->qtype = LESSON_ENDOFCLUSTER; + $newpage->timecreated = $timenow; + $newpage->title = get_string("endofclustertitle", "lesson"); + $newpage->contents = get_string("endofclustertitle", "lesson"); + if (!$newpageid = insert_record("lesson_pages", $newpage)) { + error("Insert page: end of cluster page not inserted"); + } + // update the linked list... + if (!set_field("lesson_pages", "nextpageid", $newpageid, "id", $pageid)) { + error("Add end of cluster: unable to update link"); + } + if ($page->nextpageid) { + // the new page is not the last page + if (!set_field("lesson_pages", "prevpageid", $newpageid, "id", $page->nextpageid)) { + error("Insert end of cluster: unable to update previous link"); + } + } + // ..and the single "answer" + $newanswer = new stdClass; + $newanswer->lessonid = $lesson->id; + $newanswer->pageid = $newpageid; + $newanswer->timecreated = $timenow; + $newanswer->jumpto = LESSON_NEXTPAGE; + if(!$newanswerid = insert_record("lesson_answers", $newanswer)) { + error("Add end of cluster: answer record not inserted"); + } + redirect("view.php?id=$cm->id", get_string('addedendofcluster', 'lesson')); + } /// CDC-FLAG /// - - /************** add page ************************************/ + + /************** add page ************************************/ elseif ($action == 'addpage' ) { - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } // first get the preceeding page $pageid = required_param('pageid', PARAM_INT); // set of jump array - $jump = array(); + $jump = array(); $jump[0] = get_string("thispage", "lesson"); $jump[LESSON_NEXTPAGE] = get_string("nextpage", "lesson"); - //// CDC-FLAG 6/18/04 ///// - $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson"); - if(lesson_display_branch_jumps($lesson->id, $pageid)) { - $jump[LESSON_UNSEENBRANCHPAGE] = get_string("unseenpageinbranch", "lesson"); - $jump[LESSON_RANDOMPAGE] = get_string("randompageinbranch", "lesson"); - } - if(lesson_display_cluster_jump($lesson->id, $pageid)) { - $jump[LESSON_CLUSTERJUMP] = get_string("clusterjump", "lesson"); - } - /// CDC-FLAG /// - if (!isset($_GET['firstpage'])) { - $linkadd = ""; - $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); - if (!$apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { - error("Add page: first page not found"); - } - while (true) { - if ($apageid) { - $title = get_field("lesson_pages", "title", "id", $apageid); - $jump[$apageid] = $title; - $apageid = get_field("lesson_pages", "nextpageid", "id", $apageid); - } else { - // last page reached - break; - } - } - } else { - $linkadd = "&firstpage=1"; - } + //// CDC-FLAG 6/18/04 ///// + $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson"); + if(lesson_display_branch_jumps($lesson->id, $pageid)) { + $jump[LESSON_UNSEENBRANCHPAGE] = get_string("unseenpageinbranch", "lesson"); + $jump[LESSON_RANDOMPAGE] = get_string("randompageinbranch", "lesson"); + } + if(lesson_display_cluster_jump($lesson->id, $pageid)) { + $jump[LESSON_CLUSTERJUMP] = get_string("clusterjump", "lesson"); + } + /// CDC-FLAG /// + if (!isset($_GET['firstpage'])) { + $linkadd = ""; + $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); + if (!$apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { + error("Add page: first page not found"); + } + while (true) { + if ($apageid) { + $title = get_field("lesson_pages", "title", "id", $apageid); + $jump[$apageid] = $title; + $apageid = get_field("lesson_pages", "nextpageid", "id", $apageid); + } else { + // last page reached + break; + } + } + } else { + $linkadd = "&firstpage=1"; + } // give teacher a blank proforma - print_heading_with_help(get_string("addaquestionpage", "lesson"), "overview", "lesson"); + print_heading_with_help(get_string("addaquestionpage", "lesson"), "overview", "lesson"); ?>
-
- \n"; - ?> +
"; - echo get_string("questiontype", "lesson").": \n"; - echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; - if (isset($_GET['qtype'])) { - $qtype = clean_param($_GET['qtype'], PARAM_INT); - lesson_qtype_menu($LESSON_QUESTION_TYPE, $qtype, - "lesson.php?id=$cm->id&action=addpage&pageid=".$pageid.$linkadd); - // NoticeFix rearraged - if ( $qtype == LESSON_SHORTANSWER || $qtype == LESSON_MULTICHOICE ) { // only display this option for Multichoice and shortanswer - if ($qtype == LESSON_SHORTANSWER) { - echo "

".get_string("casesensitive", "lesson").": \n"; - } else { - echo "

".get_string("multianswer", "lesson").": \n"; - } - echo " "; //CDC hidden label added. - helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); - } - } else { - lesson_qtype_menu($LESSON_QUESTION_TYPE, LESSON_MULTICHOICE, - "lesson.php?id=$cm->id&action=addpage&pageid=".$pageid.$linkadd); - echo "

".get_string("multianswer", "lesson").": \n"; - echo " "; //CDC hidden label added. - helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); - } - echo "
+ \n"; + ?> \n"; - if (isset($_GET['qtype'])) { - switch ($_GET['qtype']) { - case LESSON_TRUEFALSE : - for ($i = 0; $i < 2; $i++) { - $iplus1 = $i + 1; - echo "\n"; - echo "\n"; - echo "\n"; - } - break; - case LESSON_ESSAY : - echo "\n"; - break; - case LESSON_MATCHING : - for ($i = 0; $i < $lesson->maxanswers+2; $i++) { - $icorrected = $i - 1; - if ($i == 0) { - echo "\n"; - } elseif ($i == 1) { - echo "\n"; - } else { - echo "\n"; - echo "\n"; - } - if ($i == 2) { - echo "\n"; - } elseif ($i == 3) { - echo "\n"; - } - } - break; - case LESSON_SHORTANSWER : - case LESSON_NUMERICAL : - case LESSON_MULTICHOICE : - // default code - for ($i = 0; $i < $lesson->maxanswers; $i++) { - $iplus1 = $i + 1; - echo "\n"; - echo "\n"; - echo "\n"; - } - break; - } - } else { - for ($i = 0; $i < $lesson->maxanswers; $i++) { - $iplus1 = $i + 1; - echo "\n"; - echo "\n"; - echo "\n"; - } - } + if (isset($_GET['qtype'])) { + switch ($_GET['qtype']) { + case LESSON_TRUEFALSE : + for ($i = 0; $i < 2; $i++) { + $iplus1 = $i + 1; + echo "\n"; + echo "\n"; + echo "\n"; + } + break; + case LESSON_ESSAY : + echo "\n"; + break; + case LESSON_MATCHING : + for ($i = 0; $i < $lesson->maxanswers+2; $i++) { + $icorrected = $i - 1; + if ($i == 0) { + echo "\n"; + } elseif ($i == 1) { + echo "\n"; + } else { + echo "\n"; + echo "\n"; + } + if ($i == 2) { + echo "\n"; + } elseif ($i == 3) { + echo "\n"; + } + } + break; + case LESSON_SHORTANSWER : + case LESSON_NUMERICAL : + case LESSON_MULTICHOICE : + // default code + for ($i = 0; $i < $lesson->maxanswers; $i++) { + $iplus1 = $i + 1; + echo "\n"; + echo "\n"; + echo "\n"; + } + break; + } + } else { + for ($i = 0; $i < $lesson->maxanswers; $i++) { + $iplus1 = $i + 1; + echo "\n"; + echo "\n"; + echo "\n"; + } + } // close table and form ?>
"; + echo get_string("questiontype", "lesson").": \n"; + echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; + if (isset($_GET['qtype'])) { + $qtype = clean_param($_GET['qtype'], PARAM_INT); + lesson_qtype_menu($LESSON_QUESTION_TYPE, $qtype, + "lesson.php?id=$cm->id&action=addpage&pageid=".$pageid.$linkadd); + // NoticeFix rearraged + if ( $qtype == LESSON_SHORTANSWER || $qtype == LESSON_MULTICHOICE ) { // only display this option for Multichoice and shortanswer + if ($qtype == LESSON_SHORTANSWER) { + echo "

".get_string("casesensitive", "lesson").": \n"; + } else { + echo "

".get_string("multianswer", "lesson").": \n"; + } + echo " "; //CDC hidden label added. + helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); + } + } else { + lesson_qtype_menu($LESSON_QUESTION_TYPE, LESSON_MULTICHOICE, + "lesson.php?id=$cm->id&action=addpage&pageid=".$pageid.$linkadd); + echo "

".get_string("multianswer", "lesson").": \n"; + echo " "; //CDC hidden label added. + helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); + } + echo "
:
@@ -430,149 +430,149 @@ print_textarea($usehtmleditor, 25,70, 630, 400, "contents"); use_html_editor("contents"); echo "
".get_string("answer", "lesson")." $iplus1:
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$i]"); - echo "
".get_string("response", "lesson")." $iplus1:
\n"; - print_textarea(false, 6, 70, 630, 300, "response[$i]"); - echo "
".get_string("jump", "lesson")." $iplus1: \n"; - if ($i) { - // answers 2, 3, 4... jumpto this page - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - } else { - // answer 1 jumpto next page - lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); - } - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - /// CDC-FLAG /// - if($lesson->custom) { - if ($i) { - echo get_string("score", "lesson")." $iplus1: "; - } else { - echo get_string("score", "lesson")." $iplus1: "; - } - } - /// CDC-FLAG /// - echo "
".get_string("jump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[0]", LESSON_NEXTPAGE, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if ($lesson->custom) { - echo get_string("score", "lesson").": "; - } - echo "
".get_string("correctresponse", "lesson").":
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$i]"); - echo "
".get_string("wrongresponse", "lesson").":
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$i]"); - echo "
".get_string("answer", "lesson")." $icorrected:
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$i]"); - echo "
".get_string("matchesanswer", "lesson")." $icorrected:
\n"; - print_textarea(false, 6, 70, 630, 300, "response[$i]"); - echo "
".get_string("correctanswerjump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) { - echo get_string("correctanswerscore", "lesson").": "; - } - echo "
".get_string("wronganswerjump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) { - echo get_string("wronganswerscore", "lesson").": "; - } - echo "
".get_string("answer", "lesson")." $iplus1:
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$i]"); - echo "
".get_string("response", "lesson")." $iplus1:
\n"; - print_textarea(false, 6, 70, 630, 300, "response[$i]"); - echo "
".get_string("jump", "lesson")." $iplus1: \n"; - if ($i) { - // answers 2, 3, 4... jumpto this page - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - } else { - // answer 1 jumpto next page - lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); - } - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - /// CDC-FLAG /// - if($lesson->custom) { - if ($i) { - echo get_string("score", "lesson")." $iplus1: "; - } else { - echo get_string("score", "lesson")." $iplus1: "; - } - } - /// CDC-FLAG /// - echo "
".get_string("answer", "lesson")." $iplus1:
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$i]"); - echo "
".get_string("response", "lesson")." $iplus1:
\n"; - print_textarea(false, 6, 70, 630, 300, "response[$i]"); - echo "
".get_string("jump", "lesson")." $iplus1: \n"; - if ($i) { - // answers 2, 3, 4... jumpto this page - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - } else { - // answer 1 jumpto next page - lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); - } - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - /// CDC-FLAG /// - if($lesson->custom) { - if ($i) { - echo get_string("score", "lesson")." $iplus1: "; - } else { - echo get_string("score", "lesson")." $iplus1: "; - } - } - /// CDC-FLAG /// - echo "
".get_string("answer", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("response", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "response[$i]"); + echo "
".get_string("jump", "lesson")." $iplus1: \n"; + if ($i) { + // answers 2, 3, 4... jumpto this page + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + } else { + // answer 1 jumpto next page + lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); + } + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + /// CDC-FLAG /// + if($lesson->custom) { + if ($i) { + echo get_string("score", "lesson")." $iplus1: "; + } else { + echo get_string("score", "lesson")." $iplus1: "; + } + } + /// CDC-FLAG /// + echo "
".get_string("jump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[0]", LESSON_NEXTPAGE, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if ($lesson->custom) { + echo get_string("score", "lesson").": "; + } + echo "
".get_string("correctresponse", "lesson").":
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("wrongresponse", "lesson").":
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("answer", "lesson")." $icorrected:
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("matchesanswer", "lesson")." $icorrected:
\n"; + print_textarea(false, 6, 70, 630, 300, "response[$i]"); + echo "
".get_string("correctanswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("correctanswerscore", "lesson").": "; + } + echo "
".get_string("wronganswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("wronganswerscore", "lesson").": "; + } + echo "
".get_string("answer", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("response", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "response[$i]"); + echo "
".get_string("jump", "lesson")." $iplus1: \n"; + if ($i) { + // answers 2, 3, 4... jumpto this page + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + } else { + // answer 1 jumpto next page + lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); + } + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + /// CDC-FLAG /// + if($lesson->custom) { + if ($i) { + echo get_string("score", "lesson")." $iplus1: "; + } else { + echo get_string("score", "lesson")." $iplus1: "; + } + } + /// CDC-FLAG /// + echo "
".get_string("answer", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("response", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "response[$i]"); + echo "
".get_string("jump", "lesson")." $iplus1: \n"; + if ($i) { + // answers 2, 3, 4... jumpto this page + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + } else { + // answer 1 jumpto next page + lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); + } + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + /// CDC-FLAG /// + if($lesson->custom) { + if ($i) { + echo get_string("score", "lesson")." $iplus1: "; + } else { + echo get_string("score", "lesson")." $iplus1: "; + } + } + /// CDC-FLAG /// + echo "

@@ -581,17 +581,17 @@
id)) { - error("Only teachers can look at this page"); - } - - confirm_sesskey(); + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } + + confirm_sesskey(); $pageid = required_param('pageid', PARAM_INT); if (!$thispage = get_record("lesson_pages", "id", $pageid)) { @@ -609,102 +609,102 @@ echo $title."
\n"; } } - notice_yesno(get_string("confirmdeletionofthispage","lesson"), - "lesson.php?action=delete&id=$cm->id&pageid=$pageid&sesskey=".$USER->sesskey, + notice_yesno(get_string("confirmdeletionofthispage","lesson"), + "lesson.php?action=delete&id=$cm->id&pageid=$pageid&sesskey=".$USER->sesskey, "view.php?id=$cm->id"); - } - + } + - /****************** continue ************************************/ - elseif ($action == 'continue' ) { + /****************** continue ************************************/ + elseif ($action == 'continue' ) { - confirm_sesskey(); + confirm_sesskey(); - // left menu code - if ($lesson->displayleft) { - if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { - echo '
'; - // print the pages - echo '
'; - echo ''; - echo ''; - echo ''; - echo "
"; - echo "
".get_string('lessonmenu', 'lesson')."
"; - echo ""; - echo '
'; - lesson_print_tree_menu($lesson->id, $firstpageid, $cm->id); - echo '
'; //close lmlinks - echo '
'; - echo '
'; - } - } - - /// CDC-FLAG /// 6/21/04 This is the warning msg for teachers to inform them that cluster and unseen does not work while logged in as a teacher - if(isteacher($course->id)) { - if (execute_teacherwarning($lesson->id)) { - $warningvars->cluster = get_string("clusterjump", "lesson"); - $warningvars->unseen = get_string("unseenpageinbranch", "lesson"); - echo "

".get_string("teacherjumpwarning", "lesson", $warningvars)."

"; - } - } - /// CDC-FLAG /// + // left menu code + if ($lesson->displayleft) { + if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { + echo '
'; + // print the pages + echo '
'; + echo ''; + echo ''; + echo ''; + echo "
"; + echo "
".get_string('lessonmenu', 'lesson')."
"; + echo ""; + echo '
'; + lesson_print_tree_menu($lesson->id, $firstpageid, $cm->id); + echo '
'; //close lmlinks + echo '
'; + echo '
'; + } + } + + /// CDC-FLAG /// 6/21/04 This is the warning msg for teachers to inform them that cluster and unseen does not work while logged in as a teacher + if(isteacher($course->id)) { + if (execute_teacherwarning($lesson->id)) { + $warningvars->cluster = get_string("clusterjump", "lesson"); + $warningvars->unseen = get_string("unseenpageinbranch", "lesson"); + echo "

".get_string("teacherjumpwarning", "lesson", $warningvars)."

"; + } + } + /// CDC-FLAG /// - /// CDC-FLAG /// 6/14/04 -- This is the code updates the lesson time for a timed test - // get time information for this user - if (!isteacher($course->id)) { - if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) { - error('Error: could not find records'); - } else { - $timer = array_pop($timer); // this will get the latest start time record - } - } - $outoftime = false; - if($lesson->timed) { - if(isteacher($course->id)) { - echo "

".get_string("teachertimerwarning", "lesson")."

"; - } else { - if ((($timer->starttime + $lesson->maxtime * 60) - time()) > 0) { - // code for the clock - print_simple_box_start("right", "150px", "#ffffff", 0); - echo "". - "
".get_string("timeremaining", "lesson"). - "
"; - echo "\n"; - echo "
"; - print_simple_box_end(); - echo "



"; - } else { - redirect("view.php?id=$cm->id&action=navigation&pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson")); - } - if ((($timer->starttime + $lesson->maxtime * 60) - time()) < 60 && !((($timer->starttime + $lesson->maxtime * 60) - time()) < 0)) { - echo "

".get_string("studentoneminwarning", "lesson")."

"; - } elseif (($timer->starttime + $lesson->maxtime * 60) < time()) { - echo "

".get_string("studentoutoftime", "lesson")."

"; - $outoftime = true; - } - } - } - // update the clock - if (!isteacher($course->id)) { - $timer->lessontime = time(); - if (!update_record("lesson_timer", $timer)) { - error("Error: could not update lesson_timer table"); - } - } - /// CDC-FLAG /// + /// CDC-FLAG /// 6/14/04 -- This is the code updates the lesson time for a timed test + // get time information for this user + if (!isteacher($course->id)) { + if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) { + error('Error: could not find records'); + } else { + $timer = array_pop($timer); // this will get the latest start time record + } + } + $outoftime = false; + if($lesson->timed) { + if(isteacher($course->id)) { + echo "

".get_string("teachertimerwarning", "lesson")."

"; + } else { + if ((($timer->starttime + $lesson->maxtime * 60) - time()) > 0) { + // code for the clock + print_simple_box_start("right", "150px", "#ffffff", 0); + echo "". + "
".get_string("timeremaining", "lesson"). + "
"; + echo "\n"; + echo "
"; + print_simple_box_end(); + echo "



"; + } else { + redirect("view.php?id=$cm->id&action=navigation&pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson")); + } + if ((($timer->starttime + $lesson->maxtime * 60) - time()) < 60 && !((($timer->starttime + $lesson->maxtime * 60) - time()) < 0)) { + echo "

".get_string("studentoneminwarning", "lesson")."

"; + } elseif (($timer->starttime + $lesson->maxtime * 60) < time()) { + echo "

".get_string("studentoutoftime", "lesson")."

"; + $outoftime = true; + } + } + } + // update the clock + if (!isteacher($course->id)) { + $timer->lessontime = time(); + if (!update_record("lesson_timer", $timer)) { + error("Error: could not update lesson_timer table"); + } + } + /// CDC-FLAG /// // record answer (if necessary) and show response (if none say if answer is correct or not) if (empty($_POST['pageid'])) { - error("Continue: pageid missing"); - } + error("Continue: pageid missing"); + } $pageid = required_param('pageid', PARAM_INT); if (!$page = get_record("lesson_pages", "id", $pageid)) { error("Continue: Page record not found"); @@ -715,69 +715,69 @@ $correctanswer = false; $newpageid = 0; // stay on the page switch ($page->qtype) { - /// CDC-FLAG /// - case LESSON_ESSAY : + /// CDC-FLAG /// + case LESSON_ESSAY : if (!$useranswer = $_POST['answer']) { $noanswer = true; break; } - $useranswer = clean_param($useranswer, PARAM_CLEAN); - - if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { + $useranswer = clean_param($useranswer, PARAM_CLEAN); + + if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { error("Continue: No answers found"); } - $correctanswer = false; - $response = "Your essay will be graded by the course instructor."; - foreach ($answers as $answer) { - $answerid = $answer->id; - $newpageid = $answer->jumpto; - } - /// 6/29/04 // - $userresponse->sent=0; - $userresponse->graded = 0; - $userresponse->score = 0; - $userresponse->answer = $useranswer; - $userresponse->response = ""; - $userresponse = addslashes(serialize($userresponse)); - - break; - /// CDC-FLAG /// - case LESSON_SHORTANSWER : + $correctanswer = false; + $response = "Your essay will be graded by the course instructor."; + foreach ($answers as $answer) { + $answerid = $answer->id; + $newpageid = $answer->jumpto; + } + /// 6/29/04 // + $userresponse->sent=0; + $userresponse->graded = 0; + $userresponse->score = 0; + $userresponse->answer = $useranswer; + $userresponse->response = ""; + $userresponse = addslashes(serialize($userresponse)); + + break; + /// CDC-FLAG /// + case LESSON_SHORTANSWER : if (!$useranswer = $_POST['answer']) { $noanswer = true; break; } - $useranswer = clean_param($useranswer, PARAM_CLEAN); - $userresponse = addslashes($useranswer); - + $useranswer = clean_param($useranswer, PARAM_CLEAN); + $userresponse = addslashes($useranswer); + if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { error("Continue: No answers found"); } foreach ($answers as $answer) { - /// CDC-FLAG /// - if ($lesson->custom && $answer->score > 0) { - if ($page->qoption) { - // case sensitive - if ($answer->answer == $useranswer) { - $correctanswer = true; - $answerid = $answer->id; - $newpageid = $answer->jumpto; - if (trim(strip_tags($answer->response))) { - $response = $answer->response; - } - } - } else { - // case insensitive - if (strcasecmp($answer->answer, $useranswer) == 0) { - $correctanswer = true; - $answerid = $answer->id; - $newpageid = $answer->jumpto; - if (trim(strip_tags($answer->response))) { - $response = $answer->response; - } - } - } - } elseif (lesson_iscorrect($pageid, $answer->jumpto) && !$lesson->custom) { /// CDC-FLAG 6/21/04 /// + /// CDC-FLAG /// + if ($lesson->custom && $answer->score > 0) { + if ($page->qoption) { + // case sensitive + if ($answer->answer == $useranswer) { + $correctanswer = true; + $answerid = $answer->id; + $newpageid = $answer->jumpto; + if (trim(strip_tags($answer->response))) { + $response = $answer->response; + } + } + } else { + // case insensitive + if (strcasecmp($answer->answer, $useranswer) == 0) { + $correctanswer = true; + $answerid = $answer->id; + $newpageid = $answer->jumpto; + if (trim(strip_tags($answer->response))) { + $response = $answer->response; + } + } + } + } elseif (lesson_iscorrect($pageid, $answer->jumpto) && !$lesson->custom) { /// CDC-FLAG 6/21/04 /// if ($page->qoption) { // case sensitive if ($answer->answer == $useranswer) { @@ -802,7 +802,7 @@ // don't worry about case if (strcasecmp($answer->answer, $useranswer) == 0) { $newpageid = $answer->jumpto; - $answerid = $answer->id; + $answerid = $answer->id; if (trim(strip_tags($answer->response))) { $response = $answer->response; } @@ -829,16 +829,16 @@ } if (lesson_iscorrect($pageid, $answer->jumpto)) { $correctanswer = true; - } - /* CDC-FLAG */ - if ($lesson->custom) { - if ($answer->score > 0) { - $correctanswer = true; - } else { - $correctanswer = false; - } - } - /// CDC-FLAG 6/21/04 /// + } + /* CDC-FLAG */ + if ($lesson->custom) { + if ($answer->score > 0) { + $correctanswer = true; + } else { + $correctanswer = false; + } + } + /// CDC-FLAG 6/21/04 /// $newpageid = $answer->jumpto; if (!$response = trim($answer->response)) { if ($correctanswer) { @@ -858,8 +858,8 @@ $noanswer = true; break; } - // get what the user answered - $userresponse = implode(",", $useranswers); + // get what the user answered + $userresponse = implode(",", $useranswers); // get the answers in a set order, the id order if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { error("Continue: No answers found"); @@ -868,72 +868,72 @@ $nhits = 0; $correctresponse = ''; $wrongresponse = ''; - /// CDC-FLAG /// 6/11/04 this is for custom scores. If score on answer is positive, it is correct - if ($lesson->custom) { - $ncorrect = 0; - $nhits = 0; - foreach ($answers as $answer) { - if ($answer->score > 0) { - $ncorrect++; - - foreach ($useranswers as $key => $answerid) { - if ($answerid == $answer->id) { - $nhits++; - } - } - // save the first jumpto page id, may be needed!... - if (!isset($correctpageid)) { - // leave in its "raw" state - will converted into a proper page id later - $correctpageid = $answer->jumpto; - } - // ...also save any response from the correct answers... - if (trim(strip_tags($answer->response))) { - $correctresponse = $answer->response; - } - } else { - // save the first jumpto page id, may be needed!... - if (!isset($wrongpageid)) { - // leave in its "raw" state - will converted into a proper page id later - $wrongpageid = $answer->jumpto; - } - // ...and from the incorrect ones, don't know which to use at this stage - if (trim(strip_tags($answer->response))) { - $wrongresponse = $answer->response; - } - } - } - } else { - foreach ($answers as $answer) { - if (lesson_iscorrect($pageid, $answer->jumpto)) { - $ncorrect++; - foreach ($useranswers as $key => $answerid) { - if ($answerid == $answer->id) { - $nhits++; - } - } - // save the first jumpto page id, may be needed!... - if (!isset($correctpageid)) { - // leave in its "raw" state - will converted into a proper page id later - $correctpageid = $answer->jumpto; - } - // ...also save any response from the correct answers... - if (trim(strip_tags($answer->response))) { - $correctresponse = $answer->response; - } - } else { - // save the first jumpto page id, may be needed!... - if (!isset($wrongpageid)) { - // leave in its "raw" state - will converted into a proper page id later - $wrongpageid = $answer->jumpto; - } - // ...and from the incorrect ones, don't know which to use at this stage - if (trim(strip_tags($answer->response))) { - $wrongresponse = $answer->response; - } - } - } - } - /// CDC-FLAG /// + /// CDC-FLAG /// 6/11/04 this is for custom scores. If score on answer is positive, it is correct + if ($lesson->custom) { + $ncorrect = 0; + $nhits = 0; + foreach ($answers as $answer) { + if ($answer->score > 0) { + $ncorrect++; + + foreach ($useranswers as $key => $answerid) { + if ($answerid == $answer->id) { + $nhits++; + } + } + // save the first jumpto page id, may be needed!... + if (!isset($correctpageid)) { + // leave in its "raw" state - will converted into a proper page id later + $correctpageid = $answer->jumpto; + } + // ...also save any response from the correct answers... + if (trim(strip_tags($answer->response))) { + $correctresponse = $answer->response; + } + } else { + // save the first jumpto page id, may be needed!... + if (!isset($wrongpageid)) { + // leave in its "raw" state - will converted into a proper page id later + $wrongpageid = $answer->jumpto; + } + // ...and from the incorrect ones, don't know which to use at this stage + if (trim(strip_tags($answer->response))) { + $wrongresponse = $answer->response; + } + } + } + } else { + foreach ($answers as $answer) { + if (lesson_iscorrect($pageid, $answer->jumpto)) { + $ncorrect++; + foreach ($useranswers as $key => $answerid) { + if ($answerid == $answer->id) { + $nhits++; + } + } + // save the first jumpto page id, may be needed!... + if (!isset($correctpageid)) { + // leave in its "raw" state - will converted into a proper page id later + $correctpageid = $answer->jumpto; + } + // ...also save any response from the correct answers... + if (trim(strip_tags($answer->response))) { + $correctresponse = $answer->response; + } + } else { + // save the first jumpto page id, may be needed!... + if (!isset($wrongpageid)) { + // leave in its "raw" state - will converted into a proper page id later + $wrongpageid = $answer->jumpto; + } + // ...and from the incorrect ones, don't know which to use at this stage + if (trim(strip_tags($answer->response))) { + $wrongresponse = $answer->response; + } + } + } + } + /// CDC-FLAG /// if ((count($useranswers) == $ncorrect) and ($nhits == $ncorrect)) { $correctanswer = true; if (!$response = $correctresponse) { @@ -952,22 +952,22 @@ $noanswer = true; break; } - $answerid = required_param('answerid', PARAM_INT); + $answerid = required_param('answerid', PARAM_INT); if (!$answer = get_record("lesson_answers", "id", $answerid)) { error("Continue: answer record not found"); } if (lesson_iscorrect($pageid, $answer->jumpto)) { $correctanswer = true; - } - /* CDC-FLAG */ - if ($lesson->custom) { - if ($answer->score > 0) { - $correctanswer = true; - } else { - $correctanswer = false; - } - } - /// CDC-FLAG /// + } + /* CDC-FLAG */ + if ($lesson->custom) { + if ($answer->score > 0) { + $correctanswer = true; + } else { + $correctanswer = false; + } + } + /// CDC-FLAG /// $newpageid = $answer->jumpto; if (!$response = trim($answer->response)) { if ($correctanswer) { @@ -994,68 +994,68 @@ $ncorrect = 0; $i = 0; foreach ($answers as $answer) { - if ($i == 0 || $i == 1) { - // ignore first two answers, they are correct response - // and wrong response - $i++; - continue; - } + if ($i == 0 || $i == 1) { + // ignore first two answers, they are correct response + // and wrong response + $i++; + continue; + } if ($answer->response == $response[$answer->id]) { $ncorrect++; } if ($i == 2) { $correctpageid = $answer->jumpto; - $correctanswerid = $answer->id; + $correctanswerid = $answer->id; } if ($i == 3) { $wrongpageid = $answer->jumpto; - $wronganswerid = $answer->id; + $wronganswerid = $answer->id; } $i++; } - // get he users exact responses for record keeping - foreach ($response as $value) { - foreach($answers as $answer) { - if ($value == $answer->response) { - $userresponse[] = $answer->id; - } - } - } - $userresponse = implode(",", $userresponse); + // get he users exact responses for record keeping + foreach ($response as $value) { + foreach($answers as $answer) { + if ($value == $answer->response) { + $userresponse[] = $answer->id; + } + } + } + $userresponse = implode(",", $userresponse); if ($ncorrect == count($answers)-2) { // dont count correct/wrong responses in the total. - $response = get_string("thatsthecorrectanswer", "lesson"); - foreach ($answers as $answer) { - if ($answer->response == NULL && $answer->answer != NULL) { - $response = $answer->answer; - break; - } - } - // NoticeFix + $response = get_string("thatsthecorrectanswer", "lesson"); + foreach ($answers as $answer) { + if ($answer->response == NULL && $answer->answer != NULL) { + $response = $answer->answer; + break; + } + } + // NoticeFix if (isset($correctpageid)) { - $newpageid = $correctpageid; - } - if (isset($correctanswerid)) { - $answerid = $correctanswerid; - } + $newpageid = $correctpageid; + } + if (isset($correctanswerid)) { + $answerid = $correctanswerid; + } $correctanswer = true; } else { - $response = get_string("thatsthewronganswer", "lesson"); - $t = 0; - foreach ($answers as $answer) { - if ($answer->response == NULL && $answer->answer != NULL) { - if ($t == 1) { - $response = $answer->answer; - break; - } - $t++; - } - } + $response = get_string("thatsthewronganswer", "lesson"); + $t = 0; + foreach ($answers as $answer) { + if ($answer->response == NULL && $answer->answer != NULL) { + if ($t == 1) { + $response = $answer->answer; + break; + } + $t++; + } + } $newpageid = $wrongpageid; - $answerid = $wronganswerid; + $answerid = $wronganswerid; } break; - /// CDC-FLAG /// + /// CDC-FLAG /// case LESSON_NUMERICAL : // set defaults @@ -1063,12 +1063,12 @@ $newpageid = 0; if (isset($_POST['answer'])) { - $useranswer = (float) optional_param('answer'); // just doing default PARAM_CLEAN, not doing PARAM_INT because it could be a float - } else { + $useranswer = (float) optional_param('answer'); // just doing default PARAM_CLEAN, not doing PARAM_INT because it could be a float + } else { $noanswer = true; break; - } - $userresponse = $useranswer; + } + $userresponse = $useranswer; if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) { error("Continue: No answers found"); } @@ -1089,16 +1089,16 @@ if (lesson_iscorrect($pageid, $newpageid)) { $correctanswer = true; } - /// CDC-FLAG /// - if ($lesson->custom) { - if ($answer->score > 0) { - $correctanswer = true; - $answerid = $answer->id; - } else { - $correctanswer = false; - } - } - /// CDC-FLAG /// + /// CDC-FLAG /// + if ($lesson->custom) { + if ($answer->score > 0) { + $correctanswer = true; + $answerid = $answer->id; + } else { + $correctanswer = false; + } + } + /// CDC-FLAG /// break; } } @@ -1116,40 +1116,40 @@ case LESSON_BRANCHTABLE: $noanswer = false; $newpageid = optional_param('jumpto', NULL, PARAM_INT); - /// CDC-FLAG /// 6/15/04 going to insert into lesson_branch - if ($newpageid == LESSON_RANDOMBRANCH) { - $branchflag = 1; - } else { - $branchflag = 0; - } - if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND userid = $USER->id", - "grade DESC")) { - $retries = count($grades); - } else { - $retries = 0; - } - $branch = new stdClass; - $branch->lessonid = $lesson->id; - $branch->userid = $USER->id; - $branch->pageid = $pageid; - $branch->retry = $retries; - $branch->flag = $branchflag; - $branch->timeseen = time(); - - if (!insert_record("lesson_branch", $branch)) { - error("Error: could not insert row into lesson_branch table"); - } - /// CDC-FLAG /// + /// CDC-FLAG /// 6/15/04 going to insert into lesson_branch + if ($newpageid == LESSON_RANDOMBRANCH) { + $branchflag = 1; + } else { + $branchflag = 0; + } + if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND userid = $USER->id", + "grade DESC")) { + $retries = count($grades); + } else { + $retries = 0; + } + $branch = new stdClass; + $branch->lessonid = $lesson->id; + $branch->userid = $USER->id; + $branch->pageid = $pageid; + $branch->retry = $retries; + $branch->flag = $branchflag; + $branch->timeseen = time(); + + if (!insert_record("lesson_branch", $branch)) { + error("Error: could not insert row into lesson_branch table"); + } + /// CDC-FLAG /// - /// CDC-FLAG /// this is called when jumping to random from a branch table - if($newpageid == LESSON_UNSEENBRANCHPAGE) { - if (isteacher($course->id)) { - $newpageid = LESSON_NEXTPAGE; - } else { - $newpageid = lesson_unseen_question_jump($lesson->id, $USER->id, $pageid); // this may return 0 //CDC Chris Berri.....this is where it sets the next page id for unseen? - } - } - /// CDC-FLAG 6/15/04 /// + /// CDC-FLAG /// this is called when jumping to random from a branch table + if($newpageid == LESSON_UNSEENBRANCHPAGE) { + if (isteacher($course->id)) { + $newpageid = LESSON_NEXTPAGE; + } else { + $newpageid = lesson_unseen_question_jump($lesson->id, $USER->id, $pageid); // this may return 0 //CDC Chris Berri.....this is where it sets the next page id for unseen? + } + } + /// CDC-FLAG 6/15/04 /// // convert jumpto page into a proper page id if ($newpageid == 0) { $newpageid = $pageid; @@ -1159,16 +1159,16 @@ $newpageid = LESSON_EOL; } /* CDC-FLAG */ } elseif ($newpageid == LESSON_PREVIOUSPAGE) { - $newpageid = $page->prevpageid; - } elseif ($newpageid == LESSON_RANDOMPAGE) { - $newpageid = lesson_random_question_jump($lesson->id, $pageid); - } elseif ($newpageid == LESSON_RANDOMBRANCH) { // 6/15/04 - $newpageid = lesson_unseen_branch_jump($lesson->id, $USER->id); - } - /// CDC-FLAG /// - // no need to record anything in lesson_attempts + $newpageid = $page->prevpageid; + } elseif ($newpageid == LESSON_RANDOMPAGE) { + $newpageid = lesson_random_question_jump($lesson->id, $pageid); + } elseif ($newpageid == LESSON_RANDOMBRANCH) { // 6/15/04 + $newpageid = lesson_unseen_branch_jump($lesson->id, $USER->id); + } + /// CDC-FLAG /// + // no need to record anything in lesson_attempts redirect("view.php?id=$cm->id&action=navigation&pageid=$newpageid"); - print_footer($course); + print_footer($course); exit(); break; @@ -1180,28 +1180,28 @@ $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); if (isstudent($course->id)) { // record student's attempt - $attempt = new stdClass; + $attempt = new stdClass; $attempt->lessonid = $lesson->id; $attempt->pageid = $pageid; $attempt->userid = $USER->id; $attempt->answerid = $answerid; $attempt->retry = $nretakes; $attempt->correct = $correctanswer; - if(isset($userresponse)) { - $attempt->useranswer = $userresponse; - } + if(isset($userresponse)) { + $attempt->useranswer = $userresponse; + } $attempt->timeseen = time(); - /// CDC-FLAG /// -- dont want to insert the attempt if they ran out of time - if (!$outoftime) { - // if allow modattempts, then update the old attempt record, otherwise, insert new answer record + /// CDC-FLAG /// -- dont want to insert the attempt if they ran out of time + if (!$outoftime) { + // if allow modattempts, then update the old attempt record, otherwise, insert new answer record if (isset($USER->modattempts[$lesson->id])) { - $attempt->retry = $nretakes - 1; // they are going through on review, $nretakes will be too high - } - if (!$newattemptid = insert_record("lesson_attempts", $attempt)) { - error("Continue: attempt not inserted"); - } - } - /// CDC-FLAG /// + $attempt->retry = $nretakes - 1; // they are going through on review, $nretakes will be too high + } + if (!$newattemptid = insert_record("lesson_attempts", $attempt)) { + error("Continue: attempt not inserted"); + } + } + /// CDC-FLAG /// if (!$correctanswer and ($newpageid == 0)) { // wrong answer and student is stuck on this page - check how many attempts // the student has had at this page/question @@ -1239,18 +1239,18 @@ } elseif ($lesson->nextpagedefault == LESSON_UNANSWEREDPAGE) { foreach ($allpages as $thispage) { if ($thispage->qtype == LESSON_ESSAY) { - if (!count_records_select("lesson_attempts", "pageid = $thispage->id AND - userid = $USER->id AND retry = $nretakes")) { - $found = true; - break; - } - } else { - if (!count_records_select("lesson_attempts", "pageid = $thispage->id AND - userid = $USER->id AND correct = 1 AND retry = $nretakes")) { - $found = true; - break; - } - } + if (!count_records_select("lesson_attempts", "pageid = $thispage->id AND + userid = $USER->id AND retry = $nretakes")) { + $found = true; + break; + } + } else { + if (!count_records_select("lesson_attempts", "pageid = $thispage->id AND + userid = $USER->id AND correct = 1 AND retry = $nretakes")) { + $found = true; + break; + } + } } } if ($found) { @@ -1271,165 +1271,165 @@ } } - /// CDC-FLAG 6/21/04 /// this calculates the ongoing score - if ($lesson->ongoing) { - if (isteacher($course->id)) { - echo "
".get_string("teacherongoingwarning", "lesson")."

"; - } else { - $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); - if (isset($USER->modattempts[$lesson->id])) { - $ntries--; - } - lesson_calculate_ongoing_score($lesson, $USER->id, $ntries); - } - } - /// CDC-FLAG /// - + /// CDC-FLAG 6/21/04 /// this calculates the ongoing score + if ($lesson->ongoing) { + if (isteacher($course->id)) { + echo "
".get_string("teacherongoingwarning", "lesson")."

"; + } else { + $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); + if (isset($USER->modattempts[$lesson->id])) { + $ntries--; + } + lesson_calculate_ongoing_score($lesson, $USER->id, $ntries); + } + } + /// CDC-FLAG /// + // display response (if there is one - there should be!) if ($response) { //$title = get_field("lesson_pages", "title", "id", $pageid); //print_heading($title); echo "
\n"; - if ($lesson->review && !$correctanswer) { - $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); - $qattempts = count_records("lesson_attempts", "userid", $USER->id, "retry", $nretakes, "pageid", $pageid); - echo "

"; - if ($qattempts == 1) { - print_simple_box(get_string("firstwrong", "lesson"), "center"); - } else { - print_simple_box(get_string("secondpluswrong", "lesson"), "center"); - } - } else { - print_simple_box(format_text($response), 'center'); - } + if ($lesson->review && !$correctanswer) { + $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); + $qattempts = count_records("lesson_attempts", "userid", $USER->id, "retry", $nretakes, "pageid", $pageid); + echo "

"; + if ($qattempts == 1) { + print_simple_box(get_string("firstwrong", "lesson"), "center"); + } else { + print_simple_box(get_string("secondpluswrong", "lesson"), "center"); + } + } else { + print_simple_box(format_text($response), 'center'); + } echo "
\n"; - } + } } - - /// CDC-FLAG 6/18/04 /// - this is where some jump numbers are interpreted - if($outoftime) { - $newpageid = LESSON_EOL; // ran out of time for the test, so go to eol - } elseif (isset($USER->modattempts[$lesson->id])) { - // make sure if the student is reviewing, that he/she sees the same pages/page path that he/she saw the first time - if ($USER->modattempts[$lesson->id] == $pageid) { // remember, this session variable holds the pageid of the last page that the user saw - $newpageid = LESSON_EOL; - } else { - $nretakes--; // make sure we are looking at the right try. - $attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $nretakes", "timeseen", "id, pageid"); - $found = false; - $temppageid = 0; - foreach($attempts as $attempt) { - if ($found && $temppageid != $attempt->pageid) { // now try to find the next page, make sure next few attempts do no belong to current page - $newpageid = $attempt->pageid; - break; - } - if ($attempt->pageid == $pageid) { - $found = true; // if found current page - $temppageid = $attempt->pageid; - } - } - } - } elseif ($newpageid != LESSON_CLUSTERJUMP && $pageid != 0 && $newpageid > 0) { // going to check to see if the page that the user is going to view next, is a cluster page. If so, dont display, go into the cluster. The $newpageid > 0 is used to filter out all of the negative code jumps. - if (!$page = get_record("lesson_pages", "id", $newpageid)) { - error("Error: could not find page"); - } - if ($page->qtype == LESSON_CLUSTER) { - $newpageid = LESSON_CLUSTERJUMP; - } elseif ($page->qtype == LESSON_ENDOFCLUSTER) { - $jump = get_field("lesson_answers", "jumpto", "pageid", $page->id, "lessonid", $lesson->id); - if ($jump == LESSON_NEXTPAGE) { - if ($page->nextpageid == 0) { - $newpageid = LESSON_EOL; - } else { - $newpageid = $page->nextpageid; - } - } else { - $newpageid = $jump; - } - } - } elseif ($newpageid == LESSON_UNSEENBRANCHPAGE) { - if (isteacher($course->id)) { - if ($page->nextpageid == 0) { - $newpageid = LESSON_EOL; - } else { - $newpageid = $page->nextpageid; - } - } else { - $newpageid = lesson_unseen_question_jump($lesson->id, $USER->id, $pageid); - } - } elseif ($newpageid == LESSON_PREVIOUSPAGE) { - $newpageid = $page->prevpageid; - } elseif ($newpageid == LESSON_RANDOMPAGE) { - $newpageid = lesson_random_question_jump($lesson->id, $pageid); - } elseif ($newpageid == LESSON_CLUSTERJUMP) { - if (isteacher($course->id)) { - if ($page->nextpageid == 0) { // if teacher, go to next page - $newpageid = LESSON_EOL; - } else { - $newpageid = $page->nextpageid; - } - } else { - $newpageid = lesson_cluster_jump($lesson->id, $USER->id, $pageid); - } - } + + /// CDC-FLAG 6/18/04 /// - this is where some jump numbers are interpreted + if($outoftime) { + $newpageid = LESSON_EOL; // ran out of time for the test, so go to eol + } elseif (isset($USER->modattempts[$lesson->id])) { + // make sure if the student is reviewing, that he/she sees the same pages/page path that he/she saw the first time + if ($USER->modattempts[$lesson->id] == $pageid) { // remember, this session variable holds the pageid of the last page that the user saw + $newpageid = LESSON_EOL; + } else { + $nretakes--; // make sure we are looking at the right try. + $attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $nretakes", "timeseen", "id, pageid"); + $found = false; + $temppageid = 0; + foreach($attempts as $attempt) { + if ($found && $temppageid != $attempt->pageid) { // now try to find the next page, make sure next few attempts do no belong to current page + $newpageid = $attempt->pageid; + break; + } + if ($attempt->pageid == $pageid) { + $found = true; // if found current page + $temppageid = $attempt->pageid; + } + } + } + } elseif ($newpageid != LESSON_CLUSTERJUMP && $pageid != 0 && $newpageid > 0) { // going to check to see if the page that the user is going to view next, is a cluster page. If so, dont display, go into the cluster. The $newpageid > 0 is used to filter out all of the negative code jumps. + if (!$page = get_record("lesson_pages", "id", $newpageid)) { + error("Error: could not find page"); + } + if ($page->qtype == LESSON_CLUSTER) { + $newpageid = LESSON_CLUSTERJUMP; + } elseif ($page->qtype == LESSON_ENDOFCLUSTER) { + $jump = get_field("lesson_answers", "jumpto", "pageid", $page->id, "lessonid", $lesson->id); + if ($jump == LESSON_NEXTPAGE) { + if ($page->nextpageid == 0) { + $newpageid = LESSON_EOL; + } else { + $newpageid = $page->nextpageid; + } + } else { + $newpageid = $jump; + } + } + } elseif ($newpageid == LESSON_UNSEENBRANCHPAGE) { + if (isteacher($course->id)) { + if ($page->nextpageid == 0) { + $newpageid = LESSON_EOL; + } else { + $newpageid = $page->nextpageid; + } + } else { + $newpageid = lesson_unseen_question_jump($lesson->id, $USER->id, $pageid); + } + } elseif ($newpageid == LESSON_PREVIOUSPAGE) { + $newpageid = $page->prevpageid; + } elseif ($newpageid == LESSON_RANDOMPAGE) { + $newpageid = lesson_random_question_jump($lesson->id, $pageid); + } elseif ($newpageid == LESSON_CLUSTERJUMP) { + if (isteacher($course->id)) { + if ($page->nextpageid == 0) { // if teacher, go to next page + $newpageid = LESSON_EOL; + } else { + $newpageid = $page->nextpageid; + } + } else { + $newpageid = lesson_cluster_jump($lesson->id, $USER->id, $pageid); + } + } echo "
\n"; echo "id\">\n"; echo "\n"; echo "\n"; - if (isset($USER->modattempts[$lesson->id])) { - echo "

". - get_string("savechangesandeol", "lesson")."

". - "

\n"; - echo "

".get_string("or", "lesson")."

". - get_string("continuetoanswer", "lesson")."

\n"; - } - if ($lesson->review && !$correctanswer && !$noanswer) { - echo "

\n"; - echo "

\n"; - } else { - echo "

\n"; - } - echo "
\n"; + if (isset($USER->modattempts[$lesson->id])) { + echo "

". + get_string("savechangesandeol", "lesson")."

". + "

\n"; + echo "

".get_string("or", "lesson")."

". + get_string("continuetoanswer", "lesson")."

\n"; + } + if ($lesson->review && !$correctanswer && !$noanswer) { + echo "

\n"; + echo "

\n"; + } else { + echo "

\n"; + } + echo "\n"; - if ($lesson->displayleft) { - echo "
"; - } - } - + if ($lesson->displayleft) { + echo "
"; + } + } + - /******************* delete ************************************/ - elseif ($action == 'delete' ) { + /******************* delete ************************************/ + elseif ($action == 'delete' ) { - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } - - confirm_sesskey(); + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } + + confirm_sesskey(); - if (empty($_GET['pageid'])) { - error("Delete: pageid missing"); - } + if (empty($_GET['pageid'])) { + error("Delete: pageid missing"); + } $pageid = required_param('pageid', PARAM_INT); - if (!$thispage = get_record("lesson_pages", "id", $pageid)) { - error("Delete: page record not found"); + if (!$thispage = get_record("lesson_pages", "id", $pageid)) { + error("Delete: page record not found"); } print_string("deleting", "lesson"); - // first delete all the associated records... - delete_records("lesson_attempts", "pageid", $pageid); - // ...now delete the answers... - delete_records("lesson_answers", "pageid", $pageid); + // first delete all the associated records... + delete_records("lesson_attempts", "pageid", $pageid); + // ...now delete the answers... + delete_records("lesson_answers", "pageid", $pageid); // ..and the page itself delete_records("lesson_pages", "id", $pageid); - + // repair the hole in the linkage if (!$thispage->prevpageid) { // this is the first page... @@ -1462,45 +1462,45 @@ error("Delete: unable to set prev link"); } } - redirect("view.php?id=$cm->id", get_string('deletedpage', 'lesson')); - } - + redirect("view.php?id=$cm->id", get_string('deletedpage', 'lesson')); + } + - /************** edit page ************************************/ + /************** edit page ************************************/ elseif ($action == 'editpage' ) { - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } // get the page - $pageid = required_param('pageid', PARAM_INT); + $pageid = required_param('pageid', PARAM_INT); if (!$page = get_record("lesson_pages", "id", $pageid)) { error("Edit page: page record not found"); } - - if (isset($_GET['qtype'])) { - $page->qtype = required_param('qtype', PARAM_INT); - } - + + if (isset($_GET['qtype'])) { + $page->qtype = required_param('qtype', PARAM_INT); + } + // set of jump array - $jump = array(); + $jump = array(); $jump[0] = get_string("thispage", "lesson"); $jump[LESSON_NEXTPAGE] = get_string("nextpage", "lesson"); - //// CDC-FLAG 6/18/04 ///// - $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson"); - if(lesson_display_branch_jumps($lesson->id, $page->id)) { - $jump[LESSON_UNSEENBRANCHPAGE] = get_string("unseenpageinbranch", "lesson"); - $jump[LESSON_RANDOMPAGE] = get_string("randompageinbranch", "lesson"); - } - if ($page->qtype == LESSON_ENDOFBRANCH || $page->qtype == LESSON_BRANCHTABLE) { - $jump[LESSON_RANDOMBRANCH] = get_string("randombranch", "lesson"); - } - if(lesson_display_cluster_jump($lesson->id, $page->id) && $page->qtype != LESSON_BRANCHTABLE && $page->qtype != LESSON_ENDOFCLUSTER) { - $jump[LESSON_CLUSTERJUMP] = get_string("clusterjump", "lesson"); - } - //// CDC-FLAG ///// + //// CDC-FLAG 6/18/04 ///// + $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson"); + if(lesson_display_branch_jumps($lesson->id, $page->id)) { + $jump[LESSON_UNSEENBRANCHPAGE] = get_string("unseenpageinbranch", "lesson"); + $jump[LESSON_RANDOMPAGE] = get_string("randompageinbranch", "lesson"); + } + if ($page->qtype == LESSON_ENDOFBRANCH || $page->qtype == LESSON_BRANCHTABLE) { + $jump[LESSON_RANDOMBRANCH] = get_string("randombranch", "lesson"); + } + if(lesson_display_cluster_jump($lesson->id, $page->id) && $page->qtype != LESSON_BRANCHTABLE && $page->qtype != LESSON_ENDOFCLUSTER) { + $jump[LESSON_CLUSTERJUMP] = get_string("clusterjump", "lesson"); + } + //// CDC-FLAG ///// $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); if (!$apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { error("Edit page: first page not found"); @@ -1510,10 +1510,10 @@ if (!$apage = get_record("lesson_pages", "id", $apageid)) { error("Edit page: apage record not found"); } - /// CDC-FLAG /// 6/15/04 removed != LESSON_ENDOFBRANCH... - if (trim($page->title)) { // ...nor nuffin pages - $jump[$apageid] = $apage->title; - } + /// CDC-FLAG /// 6/15/04 removed != LESSON_ENDOFBRANCH... + if (trim($page->title)) { // ...nor nuffin pages + $jump[$apageid] = $apage->title; + } $apageid = $apage->nextpageid; } else { // last page reached @@ -1526,58 +1526,58 @@ - +
- qtype) { - case LESSON_MULTICHOICE : - echo "\n"; - break; - case LESSON_SHORTANSWER : - echo "\n"; - break; - case LESSON_TRUEFALSE : - case LESSON_ESSAY : - case LESSON_MATCHING : - case LESSON_NUMERICAL : - echo "\n"; - break; - } - ?> - \n"; + break; + case LESSON_SHORTANSWER : + echo "\n"; + break; + case LESSON_TRUEFALSE : + case LESSON_ESSAY : + case LESSON_MATCHING : + case LESSON_NUMERICAL : + echo "\n"; + break; + } + ?> + @@ -1592,34 +1592,34 @@ switch ($page->qtype) { case LESSON_BRANCHTABLE : echo "qtype\">\n"; - /// CDC-FLAG /// 6/16/04 - echo "\n"; - /// CDC-FLAG /// + /// CDC-FLAG /// 6/16/04 + echo "\n"; + /// CDC-FLAG /// echo "\n"; // get the answers in a set order, the id order if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { - foreach ($answers as $answer) { + foreach ($answers as $answer) { $flags = intval($answer->flags); // force into an integer $nplus1 = $n + 1; echo "id\">\n"; switch ($page->qtype) { case LESSON_MATCHING: - if ($n == 0) { - echo "\n"; - echo "\n"; + if ($n == 0) { + echo "\n"; + echo "\n"; break; case LESSON_TRUEFALSE: case LESSON_MULTICHOICE: case LESSON_SHORTANSWER: - case LESSON_NUMERICAL: + case LESSON_NUMERICAL: echo "\n"; break; } - switch ($page->qtype) { - case LESSON_MATCHING : - if ($n == 2) { - echo "\n"; - break; - case LESSON_ESSAY : - echo "\n"; - break; + switch ($page->qtype) { + case LESSON_MATCHING : + if ($n == 2) { + echo "\n"; + break; + case LESSON_ESSAY : + echo "\n"; + break; case LESSON_TRUEFALSE: case LESSON_MULTICHOICE: case LESSON_SHORTANSWER: case LESSON_NUMERICAL: - echo "\n"; - break; - case LESSON_BRANCHTABLE: - case LESSON_CLUSTER: - case LESSON_ENDOFCLUSTER: - case LESSON_ENDOFBRANCH: - echo "\n"; - break; - } + echo "\n"; + break; + case LESSON_BRANCHTABLE: + case LESSON_CLUSTER: + case LESSON_ENDOFCLUSTER: + case LESSON_ENDOFBRANCH: + echo "\n"; + break; + } $n++; - if ($page->qtype == LESSON_ESSAY) { - break; // only one answer for essays - } + if ($page->qtype == LESSON_ESSAY) { + break; // only one answer for essays + } } } if ($page->qtype != LESSON_ENDOFBRANCH && $page->qtype != LESSON_CLUSTER && $page->qtype != LESSON_ENDOFCLUSTER) { /// CDC-FLAG 6/17/04 added to the condition /// - if ($page->qtype == LESSON_MATCHING) { - $maxanswers = $lesson->maxanswers + 2; - } else { - $maxanswers = $lesson->maxanswers; - } + if ($page->qtype == LESSON_MATCHING) { + $maxanswers = $lesson->maxanswers + 2; + } else { + $maxanswers = $lesson->maxanswers; + } for ($i = $n; $i < $maxanswers; $i++) { - if ($page->qtype == LESSON_TRUEFALSE && $i > 1) { - break; // stop printing answers... only need two for true/false - } + if ($page->qtype == LESSON_TRUEFALSE && $i > 1) { + break; // stop printing answers... only need two for true/false + } $iplus1 = $i + 1; echo "\n"; switch ($page->qtype) { case LESSON_MATCHING: - $icorrected = $i - 1; + $icorrected = $i - 1; echo "\n"; break; } - switch ($page->qtype) { - case LESSON_ESSAY : - if ($i < 1) { - echo "\n"; - } - break; - case LESSON_MATCHING : - if ($i == 2) { - echo "\n"; + } + break; + case LESSON_MATCHING : + if ($i == 2) { + echo "\n"; - break; + echo "\n"; + break; case LESSON_TRUEFALSE: case LESSON_MULTICHOICE: case LESSON_SHORTANSWER: case LESSON_NUMERICAL: - echo "\n"; - break; - case LESSON_BRANCHTABLE : - echo "\n"; - break; - } + echo "\n"; + break; + case LESSON_BRANCHTABLE : + echo "\n"; + break; + } } } // close table and form @@ -1940,23 +1940,23 @@ id)) { - error("Only teachers can look at this page"); - } + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } - confirm_sesskey(); + confirm_sesskey(); $timenow = time(); - - $form = lesson_clean_data_submitted(); - $newpage = new stdClass; - $newanswer = new stdClass; + + $form = lesson_clean_data_submitted(); + $newpage = new stdClass; + $newanswer = new stdClass; if ($form->pageid) { // the new page is not the first page if (!$page = get_record("lesson_pages", "id", $form->pageid)) { @@ -1972,18 +1972,18 @@ } else { $newpage->qoption = 0; } - /// CDC-FLAG /// 6/16/04 - if (isset($form->layout)) { - $newpage->layout = $form->layout; - } else { - $newpage->layout = 0; - } - if (isset($form->display)) { - $newpage->display = $form->display; - } else { - $newpage->display = 0; - } - /// CDC-FLAG /// + /// CDC-FLAG /// 6/16/04 + if (isset($form->layout)) { + $newpage->layout = $form->layout; + } else { + $newpage->layout = 0; + } + if (isset($form->display)) { + $newpage->display = $form->display; + } else { + $newpage->display = 0; + } + /// CDC-FLAG /// $newpage->title = $form->title; $newpage->contents = trim($form->contents); $newpageid = insert_record("lesson_pages", $newpage); @@ -2015,18 +2015,18 @@ } else { $newpage->qoption = 0; } - /// CDC-FLAG /// 6/16/04 - if (isset($form->layout)) { - $newpage->layout = $form->layout; - } else { - $newpage->layout = 0; - } - if (isset($form->display)) { - $newpage->display = $form->display; - } else { - $newpage->display = 0; - } - /// CDC-FLAG /// + /// CDC-FLAG /// 6/16/04 + if (isset($form->layout)) { + $newpage->layout = $form->layout; + } else { + $newpage->layout = 0; + } + if (isset($form->display)) { + $newpage->display = $form->display; + } else { + $newpage->display = 0; + } + /// CDC-FLAG /// $newpage->title = $form->title; $newpage->contents = trim($form->contents); $newpageid = insert_record("lesson_pages", $newpage); @@ -2045,18 +2045,18 @@ } else { $newpage->qoption = 0; } - /// CDC-FLAG /// 6/16/04 - if (isset($form->layout)) { - $newpage->layout = $form->layout; - } else { - $newpage->layout = 0; - } - if (isset($form->display)) { - $newpage->display = $form->display; - } else { - $newpage->display = 0; - } - /// CDC-FLAG /// + /// CDC-FLAG /// 6/16/04 + if (isset($form->layout)) { + $newpage->layout = $form->layout; + } else { + $newpage->layout = 0; + } + if (isset($form->display)) { + $newpage->display = $form->display; + } else { + $newpage->display = 0; + } + /// CDC-FLAG /// $newpage->title = $form->title; $newpage->contents = trim($form->contents); $newpageid = insert_record("lesson_pages", $newpage); @@ -2070,77 +2070,77 @@ } } // now add the answers - /// CDC-FLAG 6/16/04 added new code to handle essays - if ($form->qtype == LESSON_ESSAY) { - $newanswer->lessonid = $lesson->id; - $newanswer->pageid = $newpageid; - $newanswer->timecreated = $timenow; - if (isset($form->jumpto[0])) { - $newanswer->jumpto = $form->jumpto[0]; - } - if (isset($form->score[0])) { - $newanswer->score = $form->score[0]; - } - $newanswerid = insert_record("lesson_answers", $newanswer); - if (!$newanswerid) { - error("Insert Page: answer record $i not inserted"); - } - } else { - if ($form->qtype == LESSON_MATCHING) { - // need to add two to offset correct response and wrong response - $lesson->maxanswers = $lesson->maxanswers + 2; - } - for ($i = 0; $i < $lesson->maxanswers; $i++) { - if (trim(strip_tags($form->answer[$i]))) { // strip_tags because the HTML editor adds


... - $newanswer->lessonid = $lesson->id; - $newanswer->pageid = $newpageid; - $newanswer->timecreated = $timenow; - $newanswer->answer = trim($form->answer[$i]); - if (isset($form->response[$i])) { - $newanswer->response = trim($form->response[$i]); - } - if (isset($form->jumpto[$i])) { - $newanswer->jumpto = $form->jumpto[$i]; - } - /// CDC-FLAG /// - if ($lesson->custom) { - if (isset($form->score[$i])) { - $newanswer->score = $form->score[$i]; - } - } - /// CDC-FLAG /// - $newanswerid = insert_record("lesson_answers", $newanswer); - if (!$newanswerid) { - error("Insert Page: answer record $i not inserted"); - } - } else { - if ($form->qtype == LESSON_MATCHING) { - if ($i < 2) { - $newanswer->lessonid = $lesson->id; - $newanswer->pageid = $newpageid; - $newanswer->timecreated = $timenow; - $newanswerid = insert_record("lesson_answers", $newanswer); - if (!$newanswerid) { - error("Insert Page: answer record $i not inserted"); - } - } - } else { - break; - } - } - } - } - /// CDC-FLAG /// - redirect("view.php?id=$cm->id", get_string('insertedpage', 'lesson')); - } - + /// CDC-FLAG 6/16/04 added new code to handle essays + if ($form->qtype == LESSON_ESSAY) { + $newanswer->lessonid = $lesson->id; + $newanswer->pageid = $newpageid; + $newanswer->timecreated = $timenow; + if (isset($form->jumpto[0])) { + $newanswer->jumpto = $form->jumpto[0]; + } + if (isset($form->score[0])) { + $newanswer->score = $form->score[0]; + } + $newanswerid = insert_record("lesson_answers", $newanswer); + if (!$newanswerid) { + error("Insert Page: answer record $i not inserted"); + } + } else { + if ($form->qtype == LESSON_MATCHING) { + // need to add two to offset correct response and wrong response + $lesson->maxanswers = $lesson->maxanswers + 2; + } + for ($i = 0; $i < $lesson->maxanswers; $i++) { + if (trim(strip_tags($form->answer[$i]))) { // strip_tags because the HTML editor adds


... + $newanswer->lessonid = $lesson->id; + $newanswer->pageid = $newpageid; + $newanswer->timecreated = $timenow; + $newanswer->answer = trim($form->answer[$i]); + if (isset($form->response[$i])) { + $newanswer->response = trim($form->response[$i]); + } + if (isset($form->jumpto[$i])) { + $newanswer->jumpto = $form->jumpto[$i]; + } + /// CDC-FLAG /// + if ($lesson->custom) { + if (isset($form->score[$i])) { + $newanswer->score = $form->score[$i]; + } + } + /// CDC-FLAG /// + $newanswerid = insert_record("lesson_answers", $newanswer); + if (!$newanswerid) { + error("Insert Page: answer record $i not inserted"); + } + } else { + if ($form->qtype == LESSON_MATCHING) { + if ($i < 2) { + $newanswer->lessonid = $lesson->id; + $newanswer->pageid = $newpageid; + $newanswer->timecreated = $timenow; + $newanswerid = insert_record("lesson_answers", $newanswer); + if (!$newanswerid) { + error("Insert Page: answer record $i not inserted"); + } + } + } else { + break; + } + } + } + } + /// CDC-FLAG /// + redirect("view.php?id=$cm->id", get_string('insertedpage', 'lesson')); + } + - /****************** move ************************************/ + /****************** move ************************************/ elseif ($action == 'move') { - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } $pageid = required_param('pageid', PARAM_INT); $title = get_field("lesson_pages", "title", "id", $pageid); @@ -2173,16 +2173,16 @@ } echo "

"; - echo get_string("questiontype", "lesson").": \n"; - echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; - lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype, - "lesson.php?id=$cm->id&action=editpage&pageid=$page->id", - "document.editpage.redisplay.value=1;document.editpage.submit();"); - echo "

".get_string("multianswer", "lesson").": \n"; - if ($page->qoption) { - echo ""; //CDC hidden label added. - } else { - echo ""; //CDC hidden label added. - } - helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); - echo "
"; - echo get_string("questiontype", "lesson").": \n"; - echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; - lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype, - "lesson.php?id=$cm->id&action=editpage&pageid=$page->id", - "document.editpage.redisplay.value=1;document.editpage.submit();"); - echo "

".get_string("casesensitive", "lesson").": \n"; - if ($page->qoption) { - echo ""; //CDC hidden label added. - } else { - echo ""; //CDC hidden label added. - } - helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); - echo "
"; - echo get_string("questiontype", "lesson").": \n"; - echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; - lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype, - "lesson.php?id=$cm->id&action=editpage&pageid=$page->id", - "document.editpage.redisplay.value=1;document.editpage.submit();"); - echo "
+ qtype) { + case LESSON_MULTICHOICE : + echo "
"; + echo get_string("questiontype", "lesson").": \n"; + echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; + lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype, + "lesson.php?id=$cm->id&action=editpage&pageid=$page->id", + "document.editpage.redisplay.value=1;document.editpage.submit();"); + echo "

".get_string("multianswer", "lesson").": \n"; + if ($page->qoption) { + echo ""; //CDC hidden label added. + } else { + echo ""; //CDC hidden label added. + } + helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); + echo "
"; + echo get_string("questiontype", "lesson").": \n"; + echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; + lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype, + "lesson.php?id=$cm->id&action=editpage&pageid=$page->id", + "document.editpage.redisplay.value=1;document.editpage.submit();"); + echo "

".get_string("casesensitive", "lesson").": \n"; + if ($page->qoption) { + echo ""; //CDC hidden label added. + } else { + echo ""; //CDC hidden label added. + } + helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); + echo "
"; + echo get_string("questiontype", "lesson").": \n"; + echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; + lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype, + "lesson.php?id=$cm->id&action=editpage&pageid=$page->id", + "document.editpage.redisplay.value=1;document.editpage.submit();"); + echo "
:
\n"; - echo "
"; - if ($page->layout) { - echo ""; - } else { - echo ""; - } - echo get_string("arrangebuttonshorizontally", "lesson")."
\n"; - echo "
"; - if ($page->display) { - echo "
"; - } else { - echo "
"; - } - echo get_string("displayinleftmenu", "lesson")."
\n"; - echo "
\n"; + echo "
"; + if ($page->layout) { + echo ""; + } else { + echo ""; + } + echo get_string("arrangebuttonshorizontally", "lesson")."
\n"; + echo "
"; + if ($page->display) { + echo "
"; + } else { + echo "
"; + } + echo get_string("displayinleftmenu", "lesson")."
\n"; + echo "
".get_string("branchtable", "lesson")." \n"; break; - case LESSON_CLUSTER : + case LESSON_CLUSTER : echo "qtype\">\n"; echo "
".get_string("clustertitle", "lesson")." \n"; break; - case LESSON_ENDOFCLUSTER : + case LESSON_ENDOFCLUSTER : echo "qtype\">\n"; echo "
".get_string("endofclustertitle", "lesson")." \n"; - break; + break; case LESSON_ENDOFBRANCH : echo "qtype\">\n"; echo "
".get_string("endofbranch", "lesson")." \n"; @@ -1628,88 +1628,88 @@ echo "
".get_string("correctresponse", "lesson").":\n"; - if ($flags & LESSON_ANSWER_EDITOR) { - echo " [".get_string("useeditor", "lesson").": ". - ""; //CDC hidden label added. - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); - use_html_editor("answer[$n]"); // switch on the editor - } else { - echo " [".get_string("useeditor", "lesson").": ". - ""; //CDC hidden label. - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer); - } - } elseif ($n == 1) { - echo "
".get_string("wrongresponse", "lesson").":\n"; - if ($flags & LESSON_ANSWER_EDITOR) { - echo " [".get_string("useeditor", "lesson").": ". - ""; //CDC hidden label added. - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); - use_html_editor("answer[$n]"); // switch on the editor - } else { - echo " [".get_string("useeditor", "lesson").": ". - ""; //CDC hidden label. - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer); - } - } else { - $ncorrected = $n - 1; - echo "
".get_string("answer", "lesson")." $ncorrected:\n"; - if ($flags & LESSON_ANSWER_EDITOR) { - echo " [".get_string("useeditor", "lesson").": ". - ""; //CDC hidden label added. - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); - use_html_editor("answer[$n]"); // switch on the editor - } else { - echo " [".get_string("useeditor", "lesson").": ". - ""; //CDC hidden label. - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer); - } - echo "
".get_string("matchesanswer", "lesson")." $ncorrected:\n"; - if ($flags & LESSON_RESPONSE_EDITOR) { - echo " [".get_string("useeditor", "lesson").": ". - ""; //CDC hidden label added. - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$n]", $answer->response); - use_html_editor("response[$n]"); // switch on the editor - } else { - echo " [".get_string("useeditor", "lesson").": ". - ""; //CDC hidden label added. - helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); - echo "]
\n"; - print_textarea(false, 6, 70, 630, 300, "response[$n]", $answer->response); - } - } - echo "
".get_string("correctresponse", "lesson").":\n"; + if ($flags & LESSON_ANSWER_EDITOR) { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label added. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); + use_html_editor("answer[$n]"); // switch on the editor + } else { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer); + } + } elseif ($n == 1) { + echo "
".get_string("wrongresponse", "lesson").":\n"; + if ($flags & LESSON_ANSWER_EDITOR) { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label added. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); + use_html_editor("answer[$n]"); // switch on the editor + } else { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer); + } + } else { + $ncorrected = $n - 1; + echo "
".get_string("answer", "lesson")." $ncorrected:\n"; + if ($flags & LESSON_ANSWER_EDITOR) { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label added. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); + use_html_editor("answer[$n]"); // switch on the editor + } else { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer); + } + echo "
".get_string("matchesanswer", "lesson")." $ncorrected:\n"; + if ($flags & LESSON_RESPONSE_EDITOR) { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label added. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$n]", $answer->response); + use_html_editor("response[$n]"); // switch on the editor + } else { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label added. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea(false, 6, 70, 630, 300, "response[$n]", $answer->response); + } + } + echo "
".get_string("answer", "lesson")." $nplus1:\n"; if ($flags & LESSON_ANSWER_EDITOR) { echo " [".get_string("useeditor", "lesson").": ". @@ -1765,76 +1765,76 @@ echo "
".get_string("correctanswerjump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) - echo get_string("correctanswerscore", "lesson").": score\" size=\"5\">"; - } - if ($n == 3) { - echo "
".get_string("wronganswerjump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) - echo get_string("wronganswerscore", "lesson").": score\" size=\"5\">"; - } - echo "
".get_string("jump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) { - echo get_string("score", "lesson").": score\" size=\"5\">"; - } - echo "
".get_string("correctanswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) + echo get_string("correctanswerscore", "lesson").": score\" size=\"5\">"; + } + if ($n == 3) { + echo "
".get_string("wronganswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) + echo get_string("wronganswerscore", "lesson").": score\" size=\"5\">"; + } + echo "
".get_string("jump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("score", "lesson").": score\" size=\"5\">"; + } + echo "
".get_string("jump", "lesson")." $nplus1: \n"; - lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) { - echo get_string("score", "lesson")." $nplus1: score\" size=\"5\">"; - } - echo "
".get_string("jump", "lesson")." $nplus1: \n"; - lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - echo "
".get_string("jump", "lesson")." $nplus1: \n"; + lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("score", "lesson")." $nplus1: score\" size=\"5\">"; + } + echo "
".get_string("jump", "lesson")." $nplus1: \n"; + lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + echo "
".get_string("answer", "lesson")." $icorrected:\n"; echo " [".get_string("useeditor", "lesson").": ". ""; @@ -1879,55 +1879,55 @@ echo "
".get_string("jump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) { - echo get_string("score", "lesson").": "; - } - echo "
".get_string("correctanswerjump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$i]", $answer->jumpto, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) - echo get_string("correctanswerscore", "lesson").": score\" size=\"5\">"; - } - if ($i == 3) { - echo "
".get_string("wronganswerjump", "lesson").": \n"; - lesson_choose_from_menu($jump, "jumpto[$i]", $answer->jumpto, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) - echo get_string("wronganswerscore", "lesson").": score\" size=\"5\">"; - } + switch ($page->qtype) { + case LESSON_ESSAY : + if ($i < 1) { + echo "
".get_string("jump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("score", "lesson").": "; + } + echo "
".get_string("correctanswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) + echo get_string("correctanswerscore", "lesson").": score\" size=\"5\">"; + } + if ($i == 3) { + echo "
".get_string("wronganswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) + echo get_string("wronganswerscore", "lesson").": score\" size=\"5\">"; + } - echo "
".get_string("jump", "lesson")." $iplus1: \n"; - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) { - echo get_string("score", "lesson")." $iplus1: "; - } - echo "
".get_string("jump", "lesson")." $iplus1: \n"; - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - echo "
".get_string("jump", "lesson")." $iplus1: \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("score", "lesson")." $iplus1: "; + } + echo "
".get_string("jump", "lesson")." $iplus1: \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + echo "
\n"; } - + - /****************** moveit ************************************/ + /****************** moveit ************************************/ elseif ($action == 'moveit') { - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } - confirm_sesskey(); + confirm_sesskey(); $pageid = required_param('pageid', PARAM_INT); // page to move if (!$page = get_record("lesson_pages", "id", $pageid)) { @@ -2274,23 +2274,23 @@ if (!set_field("lesson_pages", "nextpageid", 0, "id", $newlastpageid)) { error("Moveit: unable to update link"); } - redirect("view.php?id=$cm->id", get_string('movedpage', 'lesson')); + redirect("view.php?id=$cm->id", get_string('movedpage', 'lesson')); } - + - /****************** update page ************************************/ + /****************** update page ************************************/ elseif ($action == 'updatepage' ) { - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } + if (!isteacher($course->id)) { + error("Only teachers can look at this page"); + } - confirm_sesskey(); + confirm_sesskey(); $timenow = time(); - $form = lesson_clean_data_submitted(); - - $page = new stdClass; + $form = lesson_clean_data_submitted(); + + $page = new stdClass; $page->id = $form->pageid; $page->timemodified = $timenow; $page->qtype = $form->qtype; @@ -2299,18 +2299,18 @@ } else { $page->qoption = 0; } - /// CDC-FLAG /// 6/16/04 - if (isset($form->layout)) { - $page->layout = $form->layout; - } else { - $page->layout = 0; - } - if (isset($form->display)) { - $page->display = $form->display; - } else { - $page->display = 0; - } - /// CDC-FLAG /// + /// CDC-FLAG /// 6/16/04 + if (isset($form->layout)) { + $page->layout = $form->layout; + } else { + $page->layout = 0; + } + if (isset($form->display)) { + $page->display = $form->display; + } else { + $page->display = 0; + } + /// CDC-FLAG /// $page->title = $form->title; $page->contents = trim($form->contents); if (!update_record("lesson_pages", $page)) { @@ -2318,34 +2318,34 @@ } if ($page->qtype == LESSON_ENDOFBRANCH || $page->qtype == LESSON_ESSAY || $page->qtype == LESSON_CLUSTER || $page->qtype == LESSON_ENDOFCLUSTER) { // there's just a single answer with a jump - $oldanswer = new stdClass; + $oldanswer = new stdClass; $oldanswer->id = $form->answerid[0]; $oldanswer->timemodified = $timenow; $oldanswer->jumpto = $form->jumpto[0]; - if (isset($form->score[0])) { - $oldanswer->score = $form->score[0]; - } - // delete other answers this if mainly for essay questions. If one switches from using a qtype like Multichoice, - // then switches to essay, the old answers need to be removed because essay is - // supposed to only have one answer record - if ($answers = get_records_select("lesson_answers", "pageid = $form->pageid")) { - foreach ($answers as $answer) { - if ($answer->id != $form->answerid[0]) { + if (isset($form->score[0])) { + $oldanswer->score = $form->score[0]; + } + // delete other answers this if mainly for essay questions. If one switches from using a qtype like Multichoice, + // then switches to essay, the old answers need to be removed because essay is + // supposed to only have one answer record + if ($answers = get_records_select("lesson_answers", "pageid = $form->pageid")) { + foreach ($answers as $answer) { + if ($answer->id != $form->answerid[0]) { if (!delete_records("lesson_answers", "id", $answer->id)) { error("Update page: unable to delete answer record"); - } - } - } - } + } + } + } + } if (!update_record("lesson_answers", $oldanswer)) { error("Update page: EOB not updated"); } } else { // it's an "ordinary" page - if ($form->qtype == LESSON_MATCHING) { - // need to add two to offset correct response and wrong response - $lesson->maxanswers = $lesson->maxanswers + 2; - } + if ($form->qtype == LESSON_MATCHING) { + // need to add two to offset correct response and wrong response + $lesson->maxanswers = $lesson->maxanswers + 2; + } for ($i = 0; $i < $lesson->maxanswers; $i++) { // strip tags because the editor gives


... // also save any answers where the editor is (going to be) used @@ -2361,11 +2361,11 @@ $oldanswer->response = trim($form->response[$i]); } $oldanswer->jumpto = $form->jumpto[$i]; - /// CDC-FLAG /// - if ($lesson->custom) { - $oldanswer->score = $form->score[$i]; - } - /// CDC-FLAG /// + /// CDC-FLAG /// + if ($lesson->custom) { + $oldanswer->score = $form->score[$i]; + } + /// CDC-FLAG /// if (!update_record("lesson_answers", $oldanswer)) { error("Update page: answer $i not updated"); } @@ -2382,34 +2382,34 @@ $newanswer->response = trim($form->response[$i]); } $newanswer->jumpto = $form->jumpto[$i]; - /// CDC-FLAG /// - $newanswer->score = $form->score[$i]; - /// CDC-FLAG /// + /// CDC-FLAG /// + $newanswer->score = $form->score[$i]; + /// CDC-FLAG /// $newanswerid = insert_record("lesson_answers", $newanswer); if (!$newanswerid) { error("Update page: answer record not inserted"); } } } else { - if ($form->qtype == LESSON_MATCHING) { - if ($i >= 2) { - if ($form->answerid[$i]) { - // need to delete blanked out answer - if (!delete_records("lesson_answers", "id", $form->answerid[$i])) { - error("Update page: unable to delete answer record"); - } - } - } else { - $oldanswer = new stdClass; - $oldanswer->id = $form->answerid[$i]; - $oldanswer->flags = $form->answereditor[$i] * LESSON_ANSWER_EDITOR + - $form->responseeditor[$i] * LESSON_RESPONSE_EDITOR; - $oldanswer->timemodified = $timenow; - $oldanswer->answer = NULL; - if (!update_record("lesson_answers", $oldanswer)) { - error("Update page: answer $i not updated"); - } - } + if ($form->qtype == LESSON_MATCHING) { + if ($i >= 2) { + if ($form->answerid[$i]) { + // need to delete blanked out answer + if (!delete_records("lesson_answers", "id", $form->answerid[$i])) { + error("Update page: unable to delete answer record"); + } + } + } else { + $oldanswer = new stdClass; + $oldanswer->id = $form->answerid[$i]; + $oldanswer->flags = $form->answereditor[$i] * LESSON_ANSWER_EDITOR + + $form->responseeditor[$i] * LESSON_RESPONSE_EDITOR; + $oldanswer->timemodified = $timenow; + $oldanswer->answer = NULL; + if (!update_record("lesson_answers", $oldanswer)) { + error("Update page: answer $i not updated"); + } + } } elseif ($form->answerid[$i]) { // need to delete blanked out answer if (!delete_records("lesson_answers", "id", $form->answerid[$i])) { @@ -2422,15 +2422,15 @@ if ($form->redisplay) { redirect("lesson.php?id=$cm->id&action=editpage&pageid=$page->id"); } else { - redirect("view.php?id=$cm->id", get_string('updatedpage', 'lesson')); + redirect("view.php?id=$cm->id", get_string('updatedpage', 'lesson')); } } - + - /*************** no man's land **************************************/ - else { - error("Fatal Error: Unknown Action: ".$action."\n"); - } - print_footer($course); + /*************** no man's land **************************************/ + else { + error("Fatal Error: Unknown Action: ".$action."\n"); + } + print_footer($course); ?> diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index ddfd6ad22c1..eb8f2e67e65 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -1,8 +1,8 @@ timemodified = time(); $lesson->available = make_timestamp($lesson->availableyear, - $lesson->availablemonth, $lesson->availableday, $lesson->availablehour, - $lesson->availableminute); + $lesson->availablemonth, $lesson->availableday, $lesson->availablehour, + $lesson->availableminute); $lesson->deadline = make_timestamp($lesson->deadlineyear, - $lesson->deadlinemonth, $lesson->deadlineday, $lesson->deadlinehour, - $lesson->deadlineminute); - - /// CDC-FLAG /// - if (!empty($lesson->password)) { - $lesson->password = md5($lesson->password); - } else { - unset($lesson->password); - } - /// CDC-FLAG /// + $lesson->deadlinemonth, $lesson->deadlineday, $lesson->deadlinehour, + $lesson->deadlineminute); + + /// CDC-FLAG /// + if (!empty($lesson->password)) { + $lesson->password = md5($lesson->password); + } else { + unset($lesson->password); + } + /// CDC-FLAG /// - if ($lesson->lessondefault) { - $lessondefault = $lesson; - unset($lessondefault->lessondefault); - unset($lessondefault->name); - unset($lessondefault->timemodified); - unset($lessondefault->available); - unset($lessondefault->deadline); - if ($lessondefault->id = get_field("lesson_default", "id", "course", $lessondefault->course)) { - update_record("lesson_default", $lessondefault); - } else { - insert_record("lesson_default", $lessondefault); - } - } else { - unset($lesson->lessondefault); - } - + if ($lesson->lessondefault) { + $lessondefault = $lesson; + unset($lessondefault->lessondefault); + unset($lessondefault->name); + unset($lessondefault->timemodified); + unset($lessondefault->available); + unset($lessondefault->deadline); + if ($lessondefault->id = get_field("lesson_default", "id", "course", $lessondefault->course)) { + update_record("lesson_default", $lessondefault); + } else { + insert_record("lesson_default", $lessondefault); + } + } else { + unset($lesson->lessondefault); + } + return insert_record("lesson", $lesson); } @@ -61,81 +61,81 @@ function lesson_update_instance($lesson) { $lesson->timemodified = time(); $lesson->available = make_timestamp($lesson->availableyear, - $lesson->availablemonth, $lesson->availableday, $lesson->availablehour, - $lesson->availableminute); + $lesson->availablemonth, $lesson->availableday, $lesson->availablehour, + $lesson->availableminute); $lesson->deadline = make_timestamp($lesson->deadlineyear, - $lesson->deadlinemonth, $lesson->deadlineday, $lesson->deadlinehour, - $lesson->deadlineminute); + $lesson->deadlinemonth, $lesson->deadlineday, $lesson->deadlinehour, + $lesson->deadlineminute); $lesson->id = $lesson->instance; - /// CDC-FLAG /// - if (!empty($lesson->password)) { - $lesson->password = md5($lesson->password); - } else { - unset($lesson->password); - } - /// CDC-FLAG /// + /// CDC-FLAG /// + if (!empty($lesson->password)) { + $lesson->password = md5($lesson->password); + } else { + unset($lesson->password); + } + /// CDC-FLAG /// - if ($lesson->lessondefault) { - $lessondefault = $lesson; - unset($lessondefault->lessondefault); - unset($lessondefault->name); - unset($lessondefault->timemodified); - unset($lessondefault->available); - unset($lessondefault->deadline); - if ($lessondefault->id = get_field("lesson_default", "id", "course", $lessondefault->course)) { - update_record("lesson_default", $lessondefault); - } else { - insert_record("lesson_default", $lessondefault); - } - } else { - unset($lesson->lessondefault); - } - - if (!empty($lesson->deleteattempts)) { - $subject = "Delete User Attempts"; - $message = ""; + if ($lesson->lessondefault) { + $lessondefault = $lesson; + unset($lessondefault->lessondefault); + unset($lessondefault->name); + unset($lessondefault->timemodified); + unset($lessondefault->available); + unset($lessondefault->deadline); + if ($lessondefault->id = get_field("lesson_default", "id", "course", $lessondefault->course)) { + update_record("lesson_default", $lessondefault); + } else { + insert_record("lesson_default", $lessondefault); + } + } else { + unset($lesson->lessondefault); + } + + if (!empty($lesson->deleteattempts)) { + $subject = "Delete User Attempts"; + $message = ""; - if ($userid = get_field("user", "id", "username", $lesson->deleteattempts)) { - if (delete_records("lesson_attempts", "lessonid", $lesson->id, "userid", $userid)) { - // email good - $message .= "Successfully deleted attempts from \"$lesson->name\" lesson!
"; - } else { - // email couldnt delete - $message .= "Failed to delete attempts from \"$lesson->name\" lesson!
"; - } - if (delete_records("lesson_grades", "lessonid", $lesson->id, "userid", $userid)) { - // email good - $message .= "Successfully deleted grades from \"$lesson->name\" lesson!
"; - } else { - // email couldnt delete - $message .= "Failed to delete grades from \"$lesson->name\" lesson!
"; - } - if (delete_records("lesson_timer", "lessonid", $lesson->id, "userid", $userid)) { - // email good - $message .= "Successfully deleted time records from \"$lesson->name\" lesson!
"; - } else { - // email couldnt delete - $message .= "Failed to delete time records from \"$lesson->name\" lesson!
"; - } + if ($userid = get_field("user", "id", "username", $lesson->deleteattempts)) { + if (delete_records("lesson_attempts", "lessonid", $lesson->id, "userid", $userid)) { + // email good + $message .= "Successfully deleted attempts from \"$lesson->name\" lesson!
"; + } else { + // email couldnt delete + $message .= "Failed to delete attempts from \"$lesson->name\" lesson!
"; + } + if (delete_records("lesson_grades", "lessonid", $lesson->id, "userid", $userid)) { + // email good + $message .= "Successfully deleted grades from \"$lesson->name\" lesson!
"; + } else { + // email couldnt delete + $message .= "Failed to delete grades from \"$lesson->name\" lesson!
"; + } + if (delete_records("lesson_timer", "lessonid", $lesson->id, "userid", $userid)) { + // email good + $message .= "Successfully deleted time records from \"$lesson->name\" lesson!
"; + } else { + // email couldnt delete + $message .= "Failed to delete time records from \"$lesson->name\" lesson!
"; + } - } else { - // email couldnt find user - $message .= "Could not find user in database.
"; - } - $message .= "
User ID used: $lesson->deleteattempts
"; - - $txt = format_text_email($message, FORMAT_HTML); - - if ($currentuser = get_record("user", "id", $lesson->deleteattemptsid)) { - email_to_user($currentuser, $currentuser, $subject, $txt, $message); - } - // unset lessondefault - } - unset($lesson->deleteattempts); - unset($lesson->deleteattemptsid); - - return update_record("lesson", $lesson); + } else { + // email couldnt find user + $message .= "Could not find user in database.
"; + } + $message .= "
User ID used: $lesson->deleteattempts
"; + + $txt = format_text_email($message, FORMAT_HTML); + + if ($currentuser = get_record("user", "id", $lesson->deleteattemptsid)) { + email_to_user($currentuser, $currentuser, $subject, $txt, $message); + } + // unset lessondefault + } + unset($lesson->deleteattempts); + unset($lesson->deleteattemptsid); + + return update_record("lesson", $lesson); } @@ -205,27 +205,27 @@ function lesson_user_complete($course, $user, $mod, $lesson) { if ($attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $user->id", "retry, timeseen")) { print_simple_box_start(); - $table->head = array (get_string("attempt", "lesson"), get_string("numberofpagesviewed", "lesson"), - get_string("numberofcorrectanswers", "lesson"), get_string("time")); - $table->width = "100%"; - $table->align = array ("center", "center", "center", "center"); - $table->size = array ("*", "*", "*", "*"); - $table->cellpadding = 2; - $table->cellspacing = 0; + $table->head = array (get_string("attempt", "lesson"), get_string("numberofpagesviewed", "lesson"), + get_string("numberofcorrectanswers", "lesson"), get_string("time")); + $table->width = "100%"; + $table->align = array ("center", "center", "center", "center"); + $table->size = array ("*", "*", "*", "*"); + $table->cellpadding = 2; + $table->cellspacing = 0; $retry = 0; $npages = 0; $ncorrect = 0; - foreach ($attempts as $attempt) { - if ($attempt->retry == $retry) { - $npages++; + foreach ($attempts as $attempt) { + if ($attempt->retry == $retry) { + $npages++; if ($attempt->correct) { $ncorrect++; } $timeseen = $attempt->timeseen; } else { - $table->data[] = array($retry + 1, $npages, $ncorrect, userdate($timeseen)); + $table->data[] = array($retry + 1, $npages, $ncorrect, userdate($timeseen)); $retry++; $npages = 1; if ($attempt->correct) { @@ -233,13 +233,13 @@ function lesson_user_complete($course, $user, $mod, $lesson) { } else { $ncorrect = 0; } - } - } - if ($npages) { - $table->data[] = array($retry + 1, $npages, $ncorrect, userdate($timeseen)); + } } - print_table($table); - print_simple_box_end(); + if ($npages) { + $table->data[] = array($retry + 1, $npages, $ncorrect, userdate($timeseen)); + } + print_table($table); + print_simple_box_end(); // also print grade summary if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND userid = $user->id", "grade DESC")) { @@ -290,9 +290,9 @@ function lesson_grades($lessonid) { /// indexed by user. It also returns a maximum allowed grade. global $CFG; - if (!$lesson = get_record("lesson", "id", $lessonid)) { - return NULL; - } + if (!$lesson = get_record("lesson", "id", $lessonid)) { + return NULL; + } if ($lesson->usemaxgrade) { $grades = get_records_sql_menu("SELECT userid,MAX(grade) FROM {$CFG->prefix}lesson_grades WHERE lessonid = $lessonid GROUP BY userid"); @@ -302,18 +302,18 @@ function lesson_grades($lessonid) { } // convert grades from percentages and tidy the numbers - if (!$lesson->practice) { // dont display practice lessons CDC-FLAG - if ($grades) { - foreach ($grades as $userid => $grade) { - $return->grades[$userid] = number_format($grade * $lesson->grade / 100.0, 1); - } - } - $return->maxgrade = $lesson->grade; - - return $return; - } else { - return NULL; - } + if (!$lesson->practice) { // dont display practice lessons CDC-FLAG + if ($grades) { + foreach ($grades as $userid => $grade) { + $return->grades[$userid] = number_format($grade * $lesson->grade / 100.0, 1); + } + } + $return->maxgrade = $lesson->grade; + + return $return; + } else { + return NULL; + } } /*******************************************************************/ diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index af921766379..b8b8902d035 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -2,13 +2,13 @@ /// mnielsen @ CDC /// locallib.php is the new lib file for lesson module. /// including locallib.php is the same as including the old lib.php - + if (!defined("LESSON_UNSEENPAGE")) { - define("LESSON_UNSEENPAGE", 1); // Next page -> any page not seen before - } + define("LESSON_UNSEENPAGE", 1); // Next page -> any page not seen before + } if (!defined("LESSON_UNANSWEREDPAGE")) { - define("LESSON_UNANSWEREDPAGE", 2); // Next page -> any page not answered correctly - } + define("LESSON_UNANSWEREDPAGE", 2); // Next page -> any page not answered correctly + } $LESSON_NEXTPAGE_ACTION = array (0 => get_string("normal", "lesson"), LESSON_UNSEENPAGE => get_string("showanunseenpage", "lesson"), @@ -16,31 +16,31 @@ $LESSON_NEXTPAGE_ACTION = array (0 => get_string("normal", "lesson"), if (!defined("LESSON_NEXTPAGE")) { - define("LESSON_NEXTPAGE", -1); // Next page - } + define("LESSON_NEXTPAGE", -1); // Next page + } if (!defined("LESSON_EOL")) { - define("LESSON_EOL", -9); // End of Lesson - } + define("LESSON_EOL", -9); // End of Lesson + } /// CDC-FLAG 6/14/04 /// if (!defined("LESSON_UNSEENBRANCHPAGE")) { - define("LESSON_UNSEENBRANCHPAGE", -50); // Unseen branch page - } + define("LESSON_UNSEENBRANCHPAGE", -50); // Unseen branch page + } if (!defined("LESSON_PREVIOUSPAGE")) { - define("LESSON_PREVIOUSPAGE", -40); // previous page - } + define("LESSON_PREVIOUSPAGE", -40); // previous page + } if (!defined("LESSON_RANDOMPAGE")) { - define("LESSON_RANDOMPAGE", -60); // random branch page - } + define("LESSON_RANDOMPAGE", -60); // random branch page + } if (!defined("LESSON_RANDOMBRANCH")) { - define("LESSON_RANDOMBRANCH", -70); // random branch - } + define("LESSON_RANDOMBRANCH", -70); // random branch + } if (!defined("LESSON_CLUSTERJUMP")) { - define("LESSON_CLUSTERJUMP", -80); // random within a cluster - } -/// CDC-FLAG /// + define("LESSON_CLUSTERJUMP", -80); // random within a cluster + } +/// CDC-FLAG /// if (!defined("LESSON_UNDEFINED")) { - define("LESSON_UNDEFINED", -99); // undefined - } + define("LESSON_UNDEFINED", -99); // undefined + } if (!defined("LESSON_SHORTANSWER")) { define("LESSON_SHORTANSWER", "1"); @@ -71,7 +71,7 @@ if (!defined("LESSON_MULTIANSWER")) { } /// CDC-FLAG /// 6/16/04 if (!defined("LESSON_ESSAY")) { - define("LESSON_ESSAY", "10"); + define("LESSON_ESSAY", "10"); } if (!defined("LESSON_CLUSTER")) { define("LESSON_CLUSTER", "30"); @@ -86,7 +86,7 @@ $LESSON_QUESTION_TYPE = array ( LESSON_MULTICHOICE => get_string("multichoice", LESSON_SHORTANSWER => get_string("shortanswer", "quiz"), LESSON_NUMERICAL => get_string("numerical", "quiz"), LESSON_MATCHING => get_string("match", "quiz"), - LESSON_ESSAY => get_string("essay", "lesson") /// CDC-FLAG 6/16/04 + LESSON_ESSAY => get_string("essay", "lesson") /// CDC-FLAG 6/16/04 // LESSON_DESCRIPTION => get_string("description", "quiz"), // LESSON_RANDOM => get_string("random", "quiz"), // LESSON_RANDOMSAMATCH => get_string("randomsamatch", "quiz"), @@ -261,16 +261,16 @@ function lesson_save_question_options($question) { $answer->timecreated = $timenow; $answer->grade = $question->fraction[$key] * 100; /// CDC-FLAG changed some defaults - /* Original Code - if ($answer->grade > 50 ) { + /* Original Code + if ($answer->grade > 50 ) { $answer->jumpto = LESSON_NEXTPAGE; } - Replaced with: */ - if ($answer->grade > 50 ) { - $answer->jumpto = LESSON_NEXTPAGE; + Replaced with: */ + if ($answer->grade > 50 ) { + $answer->jumpto = LESSON_NEXTPAGE; $answer->score = 1; } - // end Replace + // end Replace $answer->answer = $dataanswer; $answer->response = $question->feedback[$key]; if (!$answer->id = insert_record("lesson_answers", $answer)) { @@ -445,13 +445,13 @@ function lesson_choose_from_menu ($options, $name, $selected="", $nothing="choos if ($value == $selected) { $output .= " SELECTED"; } - // stop zero label being replaced by array index value + // stop zero label being replaced by array index value // if ($label) { // $output .= ">$label\n"; // } else { // $output .= ">$value\n"; - // } - $output .= ">$label\n"; + // } + $output .= ">$label\n"; } } @@ -474,14 +474,14 @@ function lesson_iscorrect($pageid, $jumpto) { return false; } elseif ($jumpto == LESSON_NEXTPAGE) { return true; - /// CDC-FLAG 6/21/04 /// - } elseif ($jumpto == LESSON_UNSEENBRANCHPAGE) { + /// CDC-FLAG 6/21/04 /// + } elseif ($jumpto == LESSON_UNSEENBRANCHPAGE) { return true; } elseif ($jumpto == LESSON_RANDOMPAGE) { return true; } elseif ($jumpto == LESSON_CLUSTERJUMP) { return true; - /// CDC-FLAG /// + /// CDC-FLAG /// } elseif ($jumpto == LESSON_EOL) { return true; } @@ -506,22 +506,22 @@ function lesson_display_branch_jumps($lesson_id, $pageid) { // this fucntion checks to see if a page is a branch or is // a page that is enclosed by a branch table and an endofbranch/eol - // NoticeFix ... this may cause problems... not sure - if($pageid == 0) { - // first page - return false; - } - // get all of the lesson pages - if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lesson_id")) { - // adding first page - return false; - } + // NoticeFix ... this may cause problems... not sure + if($pageid == 0) { + // first page + return false; + } + // get all of the lesson pages + if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lesson_id")) { + // adding first page + return false; + } - if ($lessonpages[$pageid]->qtype == LESSON_BRANCHTABLE) { - return true; - } - - return lesson_is_page_in_branch($lessonpages, $pageid); + if ($lessonpages[$pageid]->qtype == LESSON_BRANCHTABLE) { + return true; + } + + return lesson_is_page_in_branch($lessonpages, $pageid); } /*******************************************************************/ @@ -529,22 +529,22 @@ function lesson_display_cluster_jump($lesson_id, $pageid) { // this fucntion checks to see if a page is a cluster page or is // a page that is enclosed by a cluster page and an endofcluster/eol - // NoticeFix ... this may cause problems... not sure - if($pageid == 0) { - // first page - return false; - } - // get all of the lesson pages - if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lesson_id")) { - // adding first page - return false; - } + // NoticeFix ... this may cause problems... not sure + if($pageid == 0) { + // first page + return false; + } + // get all of the lesson pages + if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lesson_id")) { + // adding first page + return false; + } - if ($lessonpages[$pageid]->qtype == LESSON_CLUSTER) { - return true; - } - - return lesson_is_page_in_cluster($lessonpages, $pageid); + if ($lessonpages[$pageid]->qtype == LESSON_CLUSTER) { + return true; + } + + return lesson_is_page_in_cluster($lessonpages, $pageid); } @@ -556,20 +556,20 @@ function execute_teacherwarning($lesson) { // This function is only executed when a teacher is // checking the navigation for a lesson. - // get all of the lesson answers - if (!$lessonanswers = get_records_select("lesson_answers", "lessonid = $lesson")) { - // no answers, then not useing cluster or unseen - return false; - } - // just check for the first one that fulfills the requirements - foreach ($lessonanswers as $lessonanswer) { - if ($lessonanswer->jumpto == LESSON_CLUSTERJUMP || $lessonanswer->jumpto == LESSON_UNSEENBRANCHPAGE) { - return true; - } - } - - // if no answers use either of the two jumps - return false; + // get all of the lesson answers + if (!$lessonanswers = get_records_select("lesson_answers", "lessonid = $lesson")) { + // no answers, then not useing cluster or unseen + return false; + } + // just check for the first one that fulfills the requirements + foreach ($lessonanswers as $lessonanswer) { + if ($lessonanswer->jumpto == LESSON_CLUSTERJUMP || $lessonanswer->jumpto == LESSON_UNSEENBRANCHPAGE) { + return true; + } + } + + // if no answers use either of the two jumps + return false; } @@ -583,116 +583,116 @@ function lesson_cluster_jump($lesson, $user, $pageid) { // and if any pages are within a branchtable/endofbranch then only 1 page within // the branchtable/endofbranch will be randomly selected (sub clustering) - // get the number of retakes + // get the number of retakes if (!$retakes = count_records("lesson_grades", "lessonid", $lesson, "userid", $user)) { - $retakes = 0; - } + $retakes = 0; + } - // get all the lesson_attempts aka what the user has seen - if ($seen = get_records_select("lesson_attempts", "lessonid = $lesson AND userid = $user AND retry = $retakes", "timeseen DESC")) { - foreach ($seen as $value) { // load it into an array that I can more easily use - $seenpages[$value->pageid] = $value->pageid; - } - } else { - $seenpages = array(); - } + // get all the lesson_attempts aka what the user has seen + if ($seen = get_records_select("lesson_attempts", "lessonid = $lesson AND userid = $user AND retry = $retakes", "timeseen DESC")) { + foreach ($seen as $value) { // load it into an array that I can more easily use + $seenpages[$value->pageid] = $value->pageid; + } + } else { + $seenpages = array(); + } - // get the lesson pages - if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lesson")) { - error("Error: could not find records in lesson_pages table"); - } - // find the start of the cluster - while ($pageid != 0) { // this condition should not be satisfied... should be a cluster page - if ($lessonpages[$pageid]->qtype == LESSON_CLUSTER) { - break; - } - $pageid = $lessonpages[$pageid]->prevpageid; - } + // get the lesson pages + if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lesson")) { + error("Error: could not find records in lesson_pages table"); + } + // find the start of the cluster + while ($pageid != 0) { // this condition should not be satisfied... should be a cluster page + if ($lessonpages[$pageid]->qtype == LESSON_CLUSTER) { + break; + } + $pageid = $lessonpages[$pageid]->prevpageid; + } - $pageid = $lessonpages[$pageid]->nextpageid; // move down from the cluster page - - $clusterpages = array(); - while (true) { // now load all the pages into the cluster that are not already inside of a branch table. - if ($lessonpages[$pageid]->qtype == LESSON_ENDOFCLUSTER) { - // store the endofcluster page's jump - $exitjump = get_field("lesson_answers", "jumpto", "pageid", $pageid, "lessonid", $lesson); - if ($exitjump == LESSON_NEXTPAGE) { - $exitjump = $lessonpages[$pageid]->nextpageid; - } - if ($exitjump == 0) { - $exitjump = LESSON_EOL; - } - break; - } elseif (!lesson_is_page_in_branch($lessonpages, $pageid) && $lessonpages[$pageid]->qtype != LESSON_ENDOFBRANCH) { - // load page into array when it is not in a branch table and when it is not an endofbranch - $clusterpages[] = $lessonpages[$pageid]; - } - if ($lessonpages[$pageid]->nextpageid == 0) { - // shouldn't ever get here... should be using endofcluster - $exitjump = LESSON_EOL; - break; - } else { - $pageid = $lessonpages[$pageid]->nextpageid; - } - } + $pageid = $lessonpages[$pageid]->nextpageid; // move down from the cluster page + + $clusterpages = array(); + while (true) { // now load all the pages into the cluster that are not already inside of a branch table. + if ($lessonpages[$pageid]->qtype == LESSON_ENDOFCLUSTER) { + // store the endofcluster page's jump + $exitjump = get_field("lesson_answers", "jumpto", "pageid", $pageid, "lessonid", $lesson); + if ($exitjump == LESSON_NEXTPAGE) { + $exitjump = $lessonpages[$pageid]->nextpageid; + } + if ($exitjump == 0) { + $exitjump = LESSON_EOL; + } + break; + } elseif (!lesson_is_page_in_branch($lessonpages, $pageid) && $lessonpages[$pageid]->qtype != LESSON_ENDOFBRANCH) { + // load page into array when it is not in a branch table and when it is not an endofbranch + $clusterpages[] = $lessonpages[$pageid]; + } + if ($lessonpages[$pageid]->nextpageid == 0) { + // shouldn't ever get here... should be using endofcluster + $exitjump = LESSON_EOL; + break; + } else { + $pageid = $lessonpages[$pageid]->nextpageid; + } + } - // filter out the ones we have seen - $unseen = array(); - foreach ($clusterpages as $clusterpage) { - if ($clusterpage->qtype == LESSON_BRANCHTABLE) { // if branchtable, check to see if any pages inside have been viewed - $branchpages = lesson_pages_in_branch($lessonpages, $clusterpage->id); // get the pages in the branchtable - $flag = true; - foreach ($branchpages as $branchpage) { - if (array_key_exists($branchpage->id, $seenpages)) { // check if any of the pages have been viewed - $flag = false; - } - } - if ($flag && count($branchpages) > 0) { - // add branch table - $unseen[] = $clusterpage; - } - } else { - // add any other type of page that has not already been viewed - if (!array_key_exists($clusterpage->id, $seenpages)) { - $unseen[] = $clusterpage; - } - } - } + // filter out the ones we have seen + $unseen = array(); + foreach ($clusterpages as $clusterpage) { + if ($clusterpage->qtype == LESSON_BRANCHTABLE) { // if branchtable, check to see if any pages inside have been viewed + $branchpages = lesson_pages_in_branch($lessonpages, $clusterpage->id); // get the pages in the branchtable + $flag = true; + foreach ($branchpages as $branchpage) { + if (array_key_exists($branchpage->id, $seenpages)) { // check if any of the pages have been viewed + $flag = false; + } + } + if ($flag && count($branchpages) > 0) { + // add branch table + $unseen[] = $clusterpage; + } + } else { + // add any other type of page that has not already been viewed + if (!array_key_exists($clusterpage->id, $seenpages)) { + $unseen[] = $clusterpage; + } + } + } - if (count($unseen) > 0) { // it does not contain elements, then use exitjump, otherwise find out next page/branch - $nextpage = $unseen[rand(0, count($unseen)-1)]; - } else { - return $exitjump; // seen all there is to see, leave the cluster - } - - if ($nextpage->qtype == LESSON_BRANCHTABLE) { // if branch table, then pick a random page inside of it - $branchpages = lesson_pages_in_branch($lessonpages, $nextpage->id); - return $branchpages[rand(0, count($branchpages)-1)]->id; - } else { // otherwise, return the page's id - return $nextpage->id; - } + if (count($unseen) > 0) { // it does not contain elements, then use exitjump, otherwise find out next page/branch + $nextpage = $unseen[rand(0, count($unseen)-1)]; + } else { + return $exitjump; // seen all there is to see, leave the cluster + } + + if ($nextpage->qtype == LESSON_BRANCHTABLE) { // if branch table, then pick a random page inside of it + $branchpages = lesson_pages_in_branch($lessonpages, $nextpage->id); + return $branchpages[rand(0, count($branchpages)-1)]->id; + } else { // otherwise, return the page's id + return $nextpage->id; + } } /*******************************************************************/ function lesson_pages_in_branch($lessonpages, $branchid) { // returns pages that are within a branch - - $pageid = $lessonpages[$branchid]->nextpageid; // move to the first page after the branch table - $pagesinbranch = array(); - - while (true) { - if ($pageid == 0) { // EOL - break; - } elseif ($lessonpages[$pageid]->qtype == LESSON_BRANCHTABLE) { - break; - } elseif ($lessonpages[$pageid]->qtype == LESSON_ENDOFBRANCH) { - break; - } - $pagesinbranch[] = $lessonpages[$pageid]; - $pageid = $lessonpages[$pageid]->nextpageid; - } - - return $pagesinbranch; + + $pageid = $lessonpages[$branchid]->nextpageid; // move to the first page after the branch table + $pagesinbranch = array(); + + while (true) { + if ($pageid == 0) { // EOL + break; + } elseif ($lessonpages[$pageid]->qtype == LESSON_BRANCHTABLE) { + break; + } elseif ($lessonpages[$pageid]->qtype == LESSON_ENDOFBRANCH) { + break; + } + $pagesinbranch[] = $lessonpages[$pageid]; + $pageid = $lessonpages[$pageid]->nextpageid; + } + + return $pagesinbranch; } /*******************************************************************/ @@ -700,63 +700,63 @@ function lesson_unseen_question_jump($lesson, $user, $pageid) { // This function interprets the LESSON_UNSEENBRANCHPAGE jump. // will return the pageid of a random unseen page that is within a branch - // get the number of retakes + // get the number of retakes if (!$retakes = count_records("lesson_grades", "lessonid", $lesson, "userid", $user)) { - $retakes = 0; - } + $retakes = 0; + } - // get all the lesson_attempts aka what the user has seen - if ($viewedpages = get_records_select("lesson_attempts", "lessonid = $lesson AND userid = $user AND retry = $retakes", "timeseen DESC")) { - foreach($viewedpages as $viewed) { - $seenpages[] = $viewed->pageid; - } - } else { - $seenpages = array(); - } + // get all the lesson_attempts aka what the user has seen + if ($viewedpages = get_records_select("lesson_attempts", "lessonid = $lesson AND userid = $user AND retry = $retakes", "timeseen DESC")) { + foreach($viewedpages as $viewed) { + $seenpages[] = $viewed->pageid; + } + } else { + $seenpages = array(); + } - // get the lesson pages - if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lesson")) { - error("Error: could not find records in lesson_pages table"); - } - - if ($pageid == LESSON_UNSEENBRANCHPAGE) { // this only happens when a student leaves in the middle of an unseen question within a branch series - $pageid = $seenpages[0]; // just change the pageid to the last page viewed inside the branch table - } + // get the lesson pages + if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lesson")) { + error("Error: could not find records in lesson_pages table"); + } + + if ($pageid == LESSON_UNSEENBRANCHPAGE) { // this only happens when a student leaves in the middle of an unseen question within a branch series + $pageid = $seenpages[0]; // just change the pageid to the last page viewed inside the branch table + } - // go up the pages till branch table - while ($pageid != 0) { // this condition should never be satisfied... only happens if there are no branch tables above this page - if ($lessonpages[$pageid]->qtype == LESSON_BRANCHTABLE) { - break; - } - $pageid = $lessonpages[$pageid]->prevpageid; - } - - $pagesinbranch = lesson_pages_in_branch($lessonpages, $pageid); - - // this foreach loop stores all the pages that are within the branch table but are not in the $seenpages array - $unseen = array(); - foreach($pagesinbranch as $page) { - if (!in_array($page->id, $seenpages)) { - $unseen[] = $page->id; - } - } + // go up the pages till branch table + while ($pageid != 0) { // this condition should never be satisfied... only happens if there are no branch tables above this page + if ($lessonpages[$pageid]->qtype == LESSON_BRANCHTABLE) { + break; + } + $pageid = $lessonpages[$pageid]->prevpageid; + } + + $pagesinbranch = lesson_pages_in_branch($lessonpages, $pageid); + + // this foreach loop stores all the pages that are within the branch table but are not in the $seenpages array + $unseen = array(); + foreach($pagesinbranch as $page) { + if (!in_array($page->id, $seenpages)) { + $unseen[] = $page->id; + } + } - if(count($unseen) == 0) { - if(isset($pagesinbranch)) { - $temp = end($pagesinbranch); - $nextpage = $temp->nextpageid; // they have seen all the pages in the branch, so go to EOB/next branch table/EOL - } else { - // there are no pages inside the branch, so return the next page - $nextpage = $lessonpages[$pageid]->nextpageid; - } - if ($nextpage == 0) { - return LESSON_EOL; - } else { - return $nextpage; - } - } else { - return $unseen[rand(0, count($unseen)-1)]; // returns a random page id for the next page - } + if(count($unseen) == 0) { + if(isset($pagesinbranch)) { + $temp = end($pagesinbranch); + $nextpage = $temp->nextpageid; // they have seen all the pages in the branch, so go to EOB/next branch table/EOL + } else { + // there are no pages inside the branch, so return the next page + $nextpage = $lessonpages[$pageid]->nextpageid; + } + if ($nextpage == 0) { + return LESSON_EOL; + } else { + return $nextpage; + } + } else { + return $unseen[rand(0, count($unseen)-1)]; // returns a random page id for the next page + } } // 6/15/04 @@ -765,51 +765,51 @@ function lesson_unseen_branch_jump($lesson, $user) { // This will return a random unseen branch table if (!$retakes = count_records("lesson_grades", "lessonid", $lesson, "userid", $user)) { - $retakes = 0; - } + $retakes = 0; + } - if (!$seenbranches = get_records_select("lesson_branch", "lessonid = $lesson AND userid = $user AND retry = $retakes", - "timeseen DESC")) { - error("Error: could not find records in lesson_branch table"); - } + if (!$seenbranches = get_records_select("lesson_branch", "lessonid = $lesson AND userid = $user AND retry = $retakes", + "timeseen DESC")) { + error("Error: could not find records in lesson_branch table"); + } - // get the lesson pages - if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lesson")) { - error("Error: could not find records in lesson_pages table"); - } - - // this loads all the viewed branch tables into $seen untill it finds the branch table with the flag - // which is the branch table that starts the unseenbranch function - $seen = array(); - foreach ($seenbranches as $seenbranch) { - if (!$seenbranch->flag) { - $seen[$seenbranch->pageid] = $seenbranch->pageid; - } else { - $start = $seenbranch->pageid; - break; - } - } - // this function searches through the lesson pages to find all the branch tables - // that follow the flagged branch table - $pageid = $lessonpages[$start]->nextpageid; // move down from the flagged branch table - while ($pageid != 0) { // grab all of the branch table till eol - if ($lessonpages[$pageid]->qtype == LESSON_BRANCHTABLE) { - $branchtables[] = $lessonpages[$pageid]->id; - } - $pageid = $lessonpages[$pageid]->nextpageid; - } - $unseen = array(); - foreach ($branchtables as $branchtable) { - // load all of the unseen branch tables into unseen - if (!array_key_exists($branchtable, $seen)) { - $unseen[] = $branchtable; - } - } - if (count($unseen) > 0) { - return $unseen[rand(0, count($unseen)-1)]; // returns a random page id for the next page - } else { - return LESSON_EOL; // has viewed all of the branch tables - } + // get the lesson pages + if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lesson")) { + error("Error: could not find records in lesson_pages table"); + } + + // this loads all the viewed branch tables into $seen untill it finds the branch table with the flag + // which is the branch table that starts the unseenbranch function + $seen = array(); + foreach ($seenbranches as $seenbranch) { + if (!$seenbranch->flag) { + $seen[$seenbranch->pageid] = $seenbranch->pageid; + } else { + $start = $seenbranch->pageid; + break; + } + } + // this function searches through the lesson pages to find all the branch tables + // that follow the flagged branch table + $pageid = $lessonpages[$start]->nextpageid; // move down from the flagged branch table + while ($pageid != 0) { // grab all of the branch table till eol + if ($lessonpages[$pageid]->qtype == LESSON_BRANCHTABLE) { + $branchtables[] = $lessonpages[$pageid]->id; + } + $pageid = $lessonpages[$pageid]->nextpageid; + } + $unseen = array(); + foreach ($branchtables as $branchtable) { + // load all of the unseen branch tables into unseen + if (!array_key_exists($branchtable, $seen)) { + $unseen[] = $branchtable; + } + } + if (count($unseen) > 0) { + return $unseen[rand(0, count($unseen)-1)]; // returns a random page id for the next page + } else { + return LESSON_EOL; // has viewed all of the branch tables + } } /*******************************************************************/ @@ -817,29 +817,29 @@ function lesson_random_question_jump($lesson, $pageid) { // This function will return the pageid of a random page // that is within a branch table - // get the lesson pages - if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lesson")) { - error("Error: could not find records in lesson_pages table"); - } + // get the lesson pages + if (!$lessonpages = get_records_select("lesson_pages", "lessonid = $lesson")) { + error("Error: could not find records in lesson_pages table"); + } - // go up the pages till branch table - while ($pageid != 0) { // this condition should never be satisfied... only happens if there are no branch tables above this page + // go up the pages till branch table + while ($pageid != 0) { // this condition should never be satisfied... only happens if there are no branch tables above this page - if ($lessonpages[$pageid]->qtype == LESSON_BRANCHTABLE) { - break; - } - $pageid = $lessonpages[$pageid]->prevpageid; - } + if ($lessonpages[$pageid]->qtype == LESSON_BRANCHTABLE) { + break; + } + $pageid = $lessonpages[$pageid]->prevpageid; + } - // get the pages within the branch - $pagesinbranch = lesson_pages_in_branch($lessonpages, $pageid); - - if(count($pagesinbranch) == 0) { - // there are no pages inside the branch, so return the next page - return $lessonpages[$pageid]->nextpageid; - } else { - return $pagesinbranch[rand(0, count($pagesinbranch)-1)]->id; // returns a random page id for the next page - } + // get the pages within the branch + $pagesinbranch = lesson_pages_in_branch($lessonpages, $pageid); + + if(count($pagesinbranch) == 0) { + // there are no pages inside the branch, so return the next page + return $lessonpages[$pageid]->nextpageid; + } else { + return $pagesinbranch[rand(0, count($pagesinbranch)-1)]->id; // returns a random page id for the next page + } } // 6/15/04 @@ -847,21 +847,21 @@ function lesson_random_question_jump($lesson, $pageid) { function lesson_is_page_in_branch($pages, $pageid) { // This function's purpose is to check if a page is within a branch or not - $pageid = $pages[$pageid]->prevpageid; // move up one + $pageid = $pages[$pageid]->prevpageid; // move up one - // go up the pages till branch table - while (true) { - if ($pageid == 0) { // ran into the beginning of the lesson - return false; - } elseif ($pages[$pageid]->qtype == LESSON_ENDOFBRANCH) { // ran into the end of another branch table - return false; - } elseif ($pages[$pageid]->qtype == LESSON_CLUSTER) { // do not look beyond a cluster - return false; - } elseif ($pages[$pageid]->qtype == LESSON_BRANCHTABLE) { // hit a branch table - return true; - } - $pageid = $pages[$pageid]->prevpageid; - } + // go up the pages till branch table + while (true) { + if ($pageid == 0) { // ran into the beginning of the lesson + return false; + } elseif ($pages[$pageid]->qtype == LESSON_ENDOFBRANCH) { // ran into the end of another branch table + return false; + } elseif ($pages[$pageid]->qtype == LESSON_CLUSTER) { // do not look beyond a cluster + return false; + } elseif ($pages[$pageid]->qtype == LESSON_BRANCHTABLE) { // hit a branch table + return true; + } + $pageid = $pages[$pageid]->prevpageid; + } } @@ -869,259 +869,259 @@ function lesson_is_page_in_branch($pages, $pageid) { function lesson_is_page_in_cluster($pages, $pageid) { // This function checks to see if a page is within a cluster or not - $pageid = $pages[$pageid]->prevpageid; // move up one + $pageid = $pages[$pageid]->prevpageid; // move up one - // go up the pages till branch table - while (true) { - if ($pageid == 0) { // ran into the beginning of the lesson - return false; - } elseif ($pages[$pageid]->qtype == LESSON_ENDOFCLUSTER) { // ran into the end of another branch table - return false; - } elseif ($pages[$pageid]->qtype == LESSON_CLUSTER) { // hit a branch table - return true; - } - $pageid = $pages[$pageid]->prevpageid; - } + // go up the pages till branch table + while (true) { + if ($pageid == 0) { // ran into the beginning of the lesson + return false; + } elseif ($pages[$pageid]->qtype == LESSON_ENDOFCLUSTER) { // ran into the end of another branch table + return false; + } elseif ($pages[$pageid]->qtype == LESSON_CLUSTER) { // hit a branch table + return true; + } + $pageid = $pages[$pageid]->prevpageid; + } } /*******************************************************************/ function lesson_print_tree_menu($lessonid, $pageid, $id, $showpages=false) { // prints the contents of the left menu - if(!$pages = get_records_select("lesson_pages", "lessonid = $lessonid")) { - error("Error: could not find lesson pages"); - } - while ($pageid != 0) { - lesson_print_tree_link_menu($pages[$pageid], $id, true); - $pageid = $pages[$pageid]->nextpageid; - } + if(!$pages = get_records_select("lesson_pages", "lessonid = $lessonid")) { + error("Error: could not find lesson pages"); + } + while ($pageid != 0) { + lesson_print_tree_link_menu($pages[$pageid], $id, true); + $pageid = $pages[$pageid]->nextpageid; + } } /*******************************************************************/ function lesson_print_tree_link_menu($page, $id, $showpages=false) { // prints the actual link for the left menu - if ($page->qtype == LESSON_BRANCHTABLE && !$page->display) { - return false; - } elseif ($page->qtype != LESSON_BRANCHTABLE) { - return false; - } - - /*elseif ($page->qtype != LESSON_BRANCHTABLE && !$showpages) { - return false; - } elseif (!in_array($page->qtype, $LESSON_QUESTION_TYPE)) { - return false; - }*/ - - // set up some variables NoticeFix changed whole function - $output = ""; - $close = false; - $link="id=$id&action=navigation&pageid=".$page->id; - - $output = "

  • "; - - if (isset($_REQUEST['pageid'])) { - if($page->id == $_REQUEST['pageid']) { - $close=true; - $output.=""; - } - } - - $output .= "id\">".$page->title."\n"; - - if($close) { - $output.=""; - } - $output .= "
  • "; - - - echo $output; + if ($page->qtype == LESSON_BRANCHTABLE && !$page->display) { + return false; + } elseif ($page->qtype != LESSON_BRANCHTABLE) { + return false; + } + + /*elseif ($page->qtype != LESSON_BRANCHTABLE && !$showpages) { + return false; + } elseif (!in_array($page->qtype, $LESSON_QUESTION_TYPE)) { + return false; + }*/ + + // set up some variables NoticeFix changed whole function + $output = ""; + $close = false; + $link="id=$id&action=navigation&pageid=".$page->id; + + $output = "
  • "; + + if (isset($_REQUEST['pageid'])) { + if($page->id == $_REQUEST['pageid']) { + $close=true; + $output.=""; + } + } + + $output .= "id\">".$page->title."\n"; + + if($close) { + $output.=""; + } + $output .= "
  • "; + + + echo $output; } /*******************************************************************/ function lesson_print_tree($pageid, $lessonid, $cmid, $pixpath) { // this function prints out the tree view list - global $USER; + global $USER; - if(!$pages = get_records_select("lesson_pages", "lessonid = $lessonid")) { - error("Error: could not find lesson pages"); - } - echo ""; - while ($pageid != 0) { - echo ""; + $pageid = $pages[$pageid]->nextpageid; + } + echo "
    "; - if(($pages[$pageid]->qtype != LESSON_BRANCHTABLE) && ($pages[$pageid]->qtype != LESSON_ENDOFBRANCH)) { - $output = "id."\">".$pages[$pageid]->title."\n"; - } else { - $output = "id."\">".$pages[$pageid]->title."\n"; - - if($answers = get_records_select("lesson_answers", "lessonid = $lessonid and pageid = $pageid")) { - $output .= "Jumps to: "; - $end = end($answers); - foreach ($answers as $answer) { - if ($answer->jumpto == 0) { - $output .= get_string("thispage", "lesson"); - } elseif ($answer->jumpto == LESSON_NEXTPAGE) { - $output .= get_string("nextpage", "lesson"); - } elseif ($answer->jumpto == LESSON_EOL) { - $output .= get_string("endoflesson", "lesson"); - } elseif ($answer->jumpto == LESSON_UNSEENBRANCHPAGE) { - $output .= get_string("unseenpageinbranch", "lesson"); - } elseif ($answer->jumpto == LESSON_PREVIOUSPAGE) { - $output .= get_string("previouspage", "lesson"); - } elseif ($answer->jumpto == LESSON_RANDOMPAGE) { - $output .= get_string("randompageinbranch", "lesson"); - } elseif ($answer->jumpto == LESSON_RANDOMBRANCH) { - $output .= get_string("randombranch", "lesson"); - } elseif ($answer->jumpto == LESSON_CLUSTERJUMP) { - $output .= get_string("clusterjump", "lesson"); - } else { - $output .= $pages[$answer->jumpto]->title; - } - if ($answer->id != $end->id) { - $output .= ", "; - } - } - } - } - - echo $output; - if (count($pages) > 1) { - echo "id."\">\n". - "\"move\"\n"; //CDC alt text added. - } - echo "id."\">\n". - "\"edit\"\n". - "sesskey."&action=confirmdelete&pageid=".$pages[$pageid]->id."\">\n". - "\"delete\"\n"; //CDC alt text added. + if(!$pages = get_records_select("lesson_pages", "lessonid = $lessonid")) { + error("Error: could not find lesson pages"); + } + echo ""; + while ($pageid != 0) { + echo ""; - $pageid = $pages[$pageid]->nextpageid; - } - echo "
    "; + if(($pages[$pageid]->qtype != LESSON_BRANCHTABLE) && ($pages[$pageid]->qtype != LESSON_ENDOFBRANCH)) { + $output = "id."\">".$pages[$pageid]->title."\n"; + } else { + $output = "id."\">".$pages[$pageid]->title."\n"; + + if($answers = get_records_select("lesson_answers", "lessonid = $lessonid and pageid = $pageid")) { + $output .= "Jumps to: "; + $end = end($answers); + foreach ($answers as $answer) { + if ($answer->jumpto == 0) { + $output .= get_string("thispage", "lesson"); + } elseif ($answer->jumpto == LESSON_NEXTPAGE) { + $output .= get_string("nextpage", "lesson"); + } elseif ($answer->jumpto == LESSON_EOL) { + $output .= get_string("endoflesson", "lesson"); + } elseif ($answer->jumpto == LESSON_UNSEENBRANCHPAGE) { + $output .= get_string("unseenpageinbranch", "lesson"); + } elseif ($answer->jumpto == LESSON_PREVIOUSPAGE) { + $output .= get_string("previouspage", "lesson"); + } elseif ($answer->jumpto == LESSON_RANDOMPAGE) { + $output .= get_string("randompageinbranch", "lesson"); + } elseif ($answer->jumpto == LESSON_RANDOMBRANCH) { + $output .= get_string("randombranch", "lesson"); + } elseif ($answer->jumpto == LESSON_CLUSTERJUMP) { + $output .= get_string("clusterjump", "lesson"); + } else { + $output .= $pages[$answer->jumpto]->title; + } + if ($answer->id != $end->id) { + $output .= ", "; + } + } + } + } + + echo $output; + if (count($pages) > 1) { + echo "id."\">\n". + "\"move\"\n"; //CDC alt text added. + } + echo "id."\">\n". + "\"edit\"\n". + "sesskey."&action=confirmdelete&pageid=".$pages[$pageid]->id."\">\n". + "\"delete\"\n"; //CDC alt text added. - echo "
    "; + echo "
    "; } /*******************************************************************/ function lesson_calculate_ongoing_score($lesson, $userid, $retries, $return=false) { -// this calculates and prints the ongoing score for students - if (!$lesson->custom) { - $ncorrect = 0; - $temp = array(); - if ($pagesanswered = get_records_select("lesson_attempts", "lessonid = $lesson->id AND - userid = $userid AND retry = $retries order by timeseen")) { +// this calculates and prints the ongoing score for students + if (!$lesson->custom) { + $ncorrect = 0; + $temp = array(); + if ($pagesanswered = get_records_select("lesson_attempts", "lessonid = $lesson->id AND + userid = $userid AND retry = $retries order by timeseen")) { - foreach ($pagesanswered as $pageanswered) { - if (!array_key_exists($pageanswered->pageid, $temp)) { - $temp[$pageanswered->pageid] = array($pageanswered->correct, 1); - } else { - if ($temp[$pageanswered->pageid][1] < $lesson->maxattempts) { - $n = $temp[$pageanswered->pageid][1] + 1; - $temp[$pageanswered->pageid] = array($pageanswered->correct, $n); - } - } - } - foreach ($temp as $value => $key) { - if ($key[0] == 1) { - $ncorrect += 1; - } - } - } - $nviewed = count($temp); // this counts number of Questions the user viewed - $thegrade = intval(100 * $ncorrect / $nviewed); + foreach ($pagesanswered as $pageanswered) { + if (!array_key_exists($pageanswered->pageid, $temp)) { + $temp[$pageanswered->pageid] = array($pageanswered->correct, 1); + } else { + if ($temp[$pageanswered->pageid][1] < $lesson->maxattempts) { + $n = $temp[$pageanswered->pageid][1] + 1; + $temp[$pageanswered->pageid] = array($pageanswered->correct, $n); + } + } + } + foreach ($temp as $value => $key) { + if ($key[0] == 1) { + $ncorrect += 1; + } + } + } + $nviewed = count($temp); // this counts number of Questions the user viewed + $thegrade = intval(100 * $ncorrect / $nviewed); - if ($return) { - return $thegrade; - } else { - $output = new stdClass; - $output->correct = $ncorrect; - $output->viewed = $nviewed; - print_simple_box(get_string("ongoingnormal", "lesson", $output), "center"); - } + if ($return) { + return $thegrade; + } else { + $output = new stdClass; + $output->correct = $ncorrect; + $output->viewed = $nviewed; + print_simple_box(get_string("ongoingnormal", "lesson", $output), "center"); + } - } else { - $score = 0; - $essayquestions = 0; - $essayquestionpoints = 0; - $bestscore = 0; - $thegrade = 0; + } else { + $score = 0; + $essayquestions = 0; + $essayquestionpoints = 0; + $bestscore = 0; + $thegrade = 0; - if ($useranswers = get_records_select("lesson_attempts", "lessonid = $lesson->id AND - userid = $userid AND retry = $retries", "timeseen")) { - // group each try with its page - foreach ($useranswers as $useranswer) { - $attemptset[$useranswer->pageid][] = $useranswer; - } - - $pageids = array_keys($attemptset); - $pageids = implode(",", $pageids); - - // get only the pages and their answers that the user answered - $answeredpages = get_records_select("lesson_pages", "lessonid = $lesson->id AND id IN($pageids)"); - $pageanswers = get_records_select("lesson_answers", "lessonid = $lesson->id AND pageid IN($pageids)"); + if ($useranswers = get_records_select("lesson_attempts", "lessonid = $lesson->id AND + userid = $userid AND retry = $retries", "timeseen")) { + // group each try with its page + foreach ($useranswers as $useranswer) { + $attemptset[$useranswer->pageid][] = $useranswer; + } + + $pageids = array_keys($attemptset); + $pageids = implode(",", $pageids); + + // get only the pages and their answers that the user answered + $answeredpages = get_records_select("lesson_pages", "lessonid = $lesson->id AND id IN($pageids)"); + $pageanswers = get_records_select("lesson_answers", "lessonid = $lesson->id AND pageid IN($pageids)"); - foreach ($attemptset as $attempts) { - if(count($attempts) > $lesson->maxattempts) { // if there are more tries than the max that is allowed, grab the last "legal" attempt - $attempt = $attempts[$lesson->maxattempts - 1]; - } else { - // else, user attempted the question less than the max, so grab the last one - $attempt = end($attempts); - } - // if essay question, handle it, otherwise add to score - if ($answeredpages[$attempt->pageid]->qtype == LESSON_ESSAY) { - $essayinfo = unserialize($attempt->useranswer); - $score += $essayinfo->score; - $essayquestions++; - $essayquestionpoints += $pageanswers[$attempt->answerid]->score; - } else { - $score += $pageanswers[$attempt->answerid]->score; - } - } - $bestscores = array(); - // find the highest possible score per page - foreach ($pageanswers as $pageanswer) { - if(isset($bestscores[$pageanswer->pageid])) { - if ($bestscores[$pageanswer->pageid] < $pageanswer->score) { - $bestscores[$pageanswer->pageid] = $pageanswer->score; - } - } else { - $bestscores[$pageanswer->pageid] = $pageanswer->score; - } - } - - $bestscore = array_sum($bestscores); - $thegrade = intval(100 * $score / $bestscore); - } - - - if ($return) { - return $thegrade; - } else { - // not taking into account essay questions... may want to? - $ongoingoutput = new stdClass; - $ongoingoutput->score = $score; - $ongoingoutput->currenthigh = $bestscore; - print_simple_box(get_string("ongoingcustom", "lesson", $ongoingoutput), "center"); - } - } + foreach ($attemptset as $attempts) { + if(count($attempts) > $lesson->maxattempts) { // if there are more tries than the max that is allowed, grab the last "legal" attempt + $attempt = $attempts[$lesson->maxattempts - 1]; + } else { + // else, user attempted the question less than the max, so grab the last one + $attempt = end($attempts); + } + // if essay question, handle it, otherwise add to score + if ($answeredpages[$attempt->pageid]->qtype == LESSON_ESSAY) { + $essayinfo = unserialize($attempt->useranswer); + $score += $essayinfo->score; + $essayquestions++; + $essayquestionpoints += $pageanswers[$attempt->answerid]->score; + } else { + $score += $pageanswers[$attempt->answerid]->score; + } + } + $bestscores = array(); + // find the highest possible score per page + foreach ($pageanswers as $pageanswer) { + if(isset($bestscores[$pageanswer->pageid])) { + if ($bestscores[$pageanswer->pageid] < $pageanswer->score) { + $bestscores[$pageanswer->pageid] = $pageanswer->score; + } + } else { + $bestscores[$pageanswer->pageid] = $pageanswer->score; + } + } + + $bestscore = array_sum($bestscores); + $thegrade = intval(100 * $score / $bestscore); + } + + + if ($return) { + return $thegrade; + } else { + // not taking into account essay questions... may want to? + $ongoingoutput = new stdClass; + $ongoingoutput->score = $score; + $ongoingoutput->currenthigh = $bestscore; + print_simple_box(get_string("ongoingcustom", "lesson", $ongoingoutput), "center"); + } + } } /*******************************************************************/ function lesson_qtype_menu($qtypes, $selected="", $link="", $onclick="") { // prints the question types for when editing and adding a page - $output = ""; - foreach ($qtypes as $value => $label) { - if ($value == $selected) { - $output .= "$label"; - $output .= " \n"; - } else { - $output .= "$label"; - } - if ($label != end($qtypes)) { - $output .= " | "; - } - } - echo $output; + $output = ""; + foreach ($qtypes as $value => $label) { + if ($value == $selected) { + $output .= "$label"; + $output .= " \n"; + } else { + $output .= "$label"; + } + if ($label != end($qtypes)) { + $output .= " | "; + } + } + echo $output; } /*******************************************************************/ @@ -1129,18 +1129,18 @@ function lesson_check_nickname($name) { // used to check high score nicknames. // checks nickname agains a list of "bad words" in filter.php - if ($name == NULL) { - return false; - } - - require_once('filter.php'); - - foreach ($filterwords as $filterword) { - if (strstr($name, $filterword)) { - return false; - } - } - return true; + if ($name == NULL) { + return false; + } + + require_once('filter.php'); + + foreach ($filterwords as $filterword) { + if (strstr($name, $filterword)) { + return false; + } + } + return true; } /*******************************************************************/ @@ -1149,23 +1149,23 @@ function lesson_clean_data_submitted() { // and runs clean_param on each // returns an object - // get the data - if ($form = data_submitted()) { - // run through and clean each form value - // detect arrays as well and process them accordingly - foreach ($form as $valuename => $formvalue) { - if (is_array($formvalue)) { - foreach ($formvalue as $index => $formsubvalue) { - $formvalue[$index] = clean_param($formsubvalue, PARAM_CLEAN); - } - $form->$valuename = $formvalue; - } else { - $form->$valuename = clean_param($formvalue, PARAM_CLEAN); - } - } - } - - return $form; + // get the data + if ($form = data_submitted()) { + // run through and clean each form value + // detect arrays as well and process them accordingly + foreach ($form as $valuename => $formvalue) { + if (is_array($formvalue)) { + foreach ($formvalue as $index => $formsubvalue) { + $formvalue[$index] = clean_param($formsubvalue, PARAM_CLEAN); + } + $form->$valuename = $formvalue; + } else { + $form->$valuename = clean_param($formvalue, PARAM_CLEAN); + } + } + } + + return $form; } /// CDC-FLAG /// diff --git a/mod/lesson/mod.html b/mod/lesson/mod.html index 071bf2b9106..d16dc907709 100644 --- a/mod/lesson/mod.html +++ b/mod/lesson/mod.html @@ -4,13 +4,13 @@ echo ""; require("$CFG->dirroot/mod/lesson/locallib.php"); // for parameter array if ($form->mode == "add") { - if ($defaults = get_record("lesson_default", "course", $form->course)) { - foreach ($defaults as $name => $value) { - if (!is_numeric($name)) { - $form->$name = $value; - } - } - } + if ($defaults = get_record("lesson_default", "course", $form->course)) { + foreach ($defaults as $name => $value) { + if (!is_numeric($name)) { + $form->$name = $value; + } + } + } } // set the defaults @@ -45,11 +45,11 @@ if ($form->mode == "add") { $form->available = 0; } if (!isset($form->deadline)) { - $currentdate = usergetdate(time()); + $currentdate = usergetdate(time()); $form->deadline = gmmktime($currentdate["hours"], $currentdate["minutes"], $currentdate["seconds"], $currentdate["mon"]+1, $currentdate["mday"], $currentdate["year"]); } - /// CDC-FLAG /// - if (!isset($form->usepassword)) { + /// CDC-FLAG /// + if (!isset($form->usepassword)) { $form->usepassword = 0; } if (!isset($form->custom)) { @@ -79,32 +79,32 @@ if ($form->mode == "add") { if (!isset($form->bgcolor)) { $form->bgcolor = "#FFFFFF"; } - if (!isset($form->displayleft)) { - $form->displayleft = 0; - } - if (!isset($form->highscores)) { - $form->highscores = 0; - } + if (!isset($form->displayleft)) { + $form->displayleft = 0; + } + if (!isset($form->highscores)) { + $form->highscores = 0; + } if (!isset($form->maxhighscores)) { $form->maxhighscores = 10; } - if (!isset($form->practice)) { - $form->practice = 0; - } - if (!isset($form->review)) { - $form->review = 0; - } - if (!isset($form->lessondefault)) { - $form->lessondefault = 0; - } - if (!isset($form->modattempts)) { - $form->modattempts = 0; - } + if (!isset($form->practice)) { + $form->practice = 0; + } + if (!isset($form->review)) { + $form->review = 0; + } + if (!isset($form->lessondefault)) { + $form->lessondefault = 0; + } + if (!isset($form->modattempts)) { + $form->modattempts = 0; + } - - $form->deleteattempts = ""; + + $form->deleteattempts = ""; - /// CDC-FLAG /// + /// CDC-FLAG /// ?>
    @@ -113,9 +113,9 @@ if ($form->mode == "add") { - + @@ -129,9 +129,9 @@ if ($form->mode == "add") { @@ -141,7 +141,7 @@ if ($form->mode == "add") { @@ -149,7 +149,7 @@ if ($form->mode == "add") { - + @@ -181,9 +181,9 @@ if ($form->mode == "add") { @@ -193,7 +193,7 @@ if ($form->mode == "add") { - + @@ -261,9 +261,9 @@ if ($form->mode == "add") { @@ -322,18 +322,18 @@ if ($form->mode == "add") { - + @@ -343,7 +343,7 @@ if ($form->mode == "add") { @@ -351,7 +351,7 @@ if ($form->mode == "add") { @@ -359,7 +359,7 @@ if ($form->mode == "add") { @@ -368,27 +368,27 @@ if ($form->mode == "add") { - + @@ -398,7 +398,7 @@ if ($form->mode == "add") { @@ -416,23 +416,23 @@ if ($form->mode == "add") { - + @@ -442,9 +442,9 @@ if ($form->mode == "add") { @@ -454,7 +454,7 @@ if ($form->mode == "add") { @@ -462,26 +462,26 @@ if ($form->mode == "add") { mode != "add") { + if ($form->mode != "add") { ?> mode != "add") { + } // end if statement if ($form->mode != "add") { ?>
    - - + +
    : timed, ""); + choose_from_menu($options, "timed", $form->timed, ""); helpbutton("timed", get_string("timed", "lesson"), "lesson"); ?> : - +
    : 1; $i--) { $numbers[$i] = $i; } @@ -160,18 +160,18 @@ if ($form->mode == "add") {
    -
    -
    +
    +
    : practice, ""); + choose_from_menu($options, "practice", $form->practice, ""); helpbutton("practice", get_string("practice", "lesson"), "lesson"); ?> : custom, ""); + choose_from_menu($options, "custom", $form->custom, ""); helpbutton("custom", get_string("customscoring", "lesson"), "lesson"); ?> : =0; $i--) { $grades[$i] = $i; } @@ -207,7 +207,7 @@ if ($form->mode == "add") { student) ?>: retake, ""); helpbutton("retake", get_string("canretake", "lesson", $course->student), "lesson"); @@ -219,7 +219,7 @@ if ($form->mode == "add") { : usemaxgrade, ""); helpbutton("handlingofretakes", get_string("handlingofretakes", "lesson"), "lesson"); @@ -231,27 +231,27 @@ if ($form->mode == "add") { : ongoing, ""); + choose_from_menu($options, "ongoing", $form->ongoing, ""); helpbutton("ongoing", get_string("ongoing", "lesson"), "lesson"); ?>
    -
    -
    +
    +
    : modattempts, ""); + choose_from_menu($options, "modattempts", $form->modattempts, ""); helpbutton("modattempts", get_string("modattempts", "lesson"), "lesson"); ?> : review, ""); + choose_from_menu($options, "review", $form->review, ""); helpbutton("review", get_string("displayreview", "lesson"), "lesson"); ?>
    -
    -
    +
    +
    : slideshow, ""); + choose_from_menu($options, "slideshow", $form->slideshow, ""); helpbutton("slideshow", get_string("slideshow", "lesson"), "lesson"); ?> : px - +
    : px - +
    : - +
    : displayleft, ""); + choose_from_menu($options, "displayleft", $form->displayleft, ""); helpbutton("displayleft", get_string("displayleftmenu", "lesson"), "lesson"); ?>
    -
    -
    +
    +
    : usepassword, ""); + choose_from_menu($options, "usepassword", $form->usepassword, ""); helpbutton("usepassword", get_string("usepassword", "lesson"), "lesson"); ?> : - +
    deadline); echo " - "; - print_time_selector("deadlinehour", "deadlineminute", $form->deadline); + print_time_selector("deadlinehour", "deadlineminute", $form->deadline); ?>
    -
    -
    +
    +
    : tree, ""); + choose_from_menu($options, "tree", $form->tree, ""); helpbutton("tree", get_string("treeview", "lesson"), "lesson"); ?> : highscores, ""); + choose_from_menu($options, "highscores", $form->highscores, ""); helpbutton("highscores", get_string("displayhighscores", "lesson"), "lesson"); ?> : - +
    : lessondefault, ""); + choose_from_menu($options, "lessondefault", $form->lessondefault, ""); helpbutton("lessondefault", get_string("lessondefault", "lesson"), "lesson"); ?>
    : - - + +
    diff --git a/mod/lesson/reformat.php b/mod/lesson/reformat.php index 5e4b9c026dd..8501c7e145a 100644 --- a/mod/lesson/reformat.php +++ b/mod/lesson/reformat.php @@ -3,176 +3,176 @@ function removedoublecr($filename) { // This function will adjust a file in roughly Aiken style by replacing extra newlines with
    tags // so that instructors can have newlines wherever they like as long as the overall format is in Aiken - - $filearray = file($filename); - /// Check for Macintosh OS line returns (ie file on one line), and fix - if (ereg("\r", $filearray[0]) AND !ereg("\n", $filearray[0])) { - $outfile = explode("\r", $filearray[0]); - } else { - $outfile = $filearray; - } - - foreach ($outfile as $line) { - // remove leading and trailing whitespace - trim($line); - // check it's length, if 0 do not output... if it is > 0 output - if ($line[0] == "\n" OR strlen($line)==0 ) { - if (count($outarray) ) { - // get the last item in the outarray - $cur_pos = (count($outarray) - 1); - $outarray[$cur_pos] = trim($outarray[$cur_pos])."
    \n"; - } - } - else { - $length=strlen($line); - if ($length==0) { - // don't do anything - } - else { - if ($line[$length-1] == "\n") { - $outarray[] = $line; - } - else { - $outarray[] = $line."\n"; - } - } - } - } - // output modified file to original - if ( is_writable($filename) ) { + + $filearray = file($filename); + /// Check for Macintosh OS line returns (ie file on one line), and fix + if (ereg("\r", $filearray[0]) AND !ereg("\n", $filearray[0])) { + $outfile = explode("\r", $filearray[0]); + } else { + $outfile = $filearray; + } + + foreach ($outfile as $line) { + // remove leading and trailing whitespace + trim($line); + // check it's length, if 0 do not output... if it is > 0 output + if ($line[0] == "\n" OR strlen($line)==0 ) { + if (count($outarray) ) { + // get the last item in the outarray + $cur_pos = (count($outarray) - 1); + $outarray[$cur_pos] = trim($outarray[$cur_pos])."
    \n"; + } + } + else { + $length=strlen($line); + if ($length==0) { + // don't do anything + } + else { + if ($line[$length-1] == "\n") { + $outarray[] = $line; + } + else { + $outarray[] = $line."\n"; + } + } + } + } + // output modified file to original + if ( is_writable($filename) ) { - if (! $handle =fopen ($filename ,'w' )) { - echo "Cannot open file ($filename)" ; - exit; - } - foreach ($outarray as $outline) { - fwrite($handle, $outline); - } - fclose($handle); - } - else { - // file not writeable - } + if (! $handle =fopen ($filename ,'w' )) { + echo "Cannot open file ($filename)" ; + exit; + } + foreach ($outarray as $outline) { + fwrite($handle, $outline); + } + fclose($handle); + } + else { + // file not writeable + } } // jjg7:8/9/2004 function importmodifiedaikenstyle($filename) { // This function converts from Brusca style to Aiken - $lines = file($filename); - $answer_found = 0; - $responses = 0; - $outlines = array(); - foreach ($lines as $line) { - // strip leading and trailing whitespace - $line = trim($line); - // add a space at the end, quick hack to make sure words from different lines don't run together - $line = $line. ' '; - - // ignore lines less than 2 characters - if (strlen($line) < 2) { - continue; - } + $lines = file($filename); + $answer_found = 0; + $responses = 0; + $outlines = array(); + foreach ($lines as $line) { + // strip leading and trailing whitespace + $line = trim($line); + // add a space at the end, quick hack to make sure words from different lines don't run together + $line = $line. ' '; + + // ignore lines less than 2 characters + if (strlen($line) < 2) { + continue; + } - - // see if we have the answer line - if ($line[0] =='*') { - if ($line[0] == '*') { - $answer_found = 1; - $line[0]="\t"; - $line = ltrim($line); - $answer = $line[0]; - } - } + + // see if we have the answer line + if ($line[0] =='*') { + if ($line[0] == '*') { + $answer_found = 1; + $line[0]="\t"; + $line = ltrim($line); + $answer = $line[0]; + } + } - $leadin = substr($line, 0,2); - if (strpos(".A)B)C)D)E)F)G)H)I)J)a)b)c)d)e)f)g)h)i)j)A.B.C.D.E.F.G.H.I.J.a.b.c.d.e.f.g.h.i.j.", $leadin)>0) { + $leadin = substr($line, 0,2); + if (strpos(".A)B)C)D)E)F)G)H)I)J)a)b)c)d)e)f)g)h)i)j)A.B.C.D.E.F.G.H.I.J.a.b.c.d.e.f.g.h.i.j.", $leadin)>0) { - // re-add newline to indicate end of previous question/response - if (count($outlines)) { - $cur_pos = (count($outlines) - 1); - $outlines[$cur_pos] = $outlines[$cur_pos]."\n"; - } + // re-add newline to indicate end of previous question/response + if (count($outlines)) { + $cur_pos = (count($outlines) - 1); + $outlines[$cur_pos] = $outlines[$cur_pos]."\n"; + } - - $responses = 1; - // make character uppercase - $line[0]=strtoupper($line[0]); - - // make entry followed by '.' - $line[1]='.'; - } - elseif ( ($responses AND $answer_found) OR (count(outlines)<=1) ) { - // we have found responses and an answer and the current line is not an answer - switch ($line[0]) { - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: + + $responses = 1; + // make character uppercase + $line[0]=strtoupper($line[0]); + + // make entry followed by '.' + $line[1]='.'; + } + elseif ( ($responses AND $answer_found) OR (count(outlines)<=1) ) { + // we have found responses and an answer and the current line is not an answer + switch ($line[0]) { + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: - // re-add newline to indicate end of previous question/response - if (count($outlines)) { - $cur_pos = (count($outlines) - 1); - $outlines[$cur_pos] = $outlines[$cur_pos]."\n"; - } + // re-add newline to indicate end of previous question/response + if (count($outlines)) { + $cur_pos = (count($outlines) - 1); + $outlines[$cur_pos] = $outlines[$cur_pos]."\n"; + } - // this next ugly block is to strip out the numbers at the beginning - $np = 0; - // this probably could be done cleaner... it escapes me at the moment - while ($line[$np] == '0' OR $line[$np] == '1' OR $line[$np] == '2' - OR $line[$np] == '3' OR $line[$np] == '4' OR $line[$np] == '5' - OR $line[$np] == '6' OR $line[$np] == '7' OR $line[$np] == '8' - OR $line[$np] == '9' ) { - $np++; - } - // grab everything after '###.' - $line = substr($line, $np+1, strlen($line)); + // this next ugly block is to strip out the numbers at the beginning + $np = 0; + // this probably could be done cleaner... it escapes me at the moment + while ($line[$np] == '0' OR $line[$np] == '1' OR $line[$np] == '2' + OR $line[$np] == '3' OR $line[$np] == '4' OR $line[$np] == '5' + OR $line[$np] == '6' OR $line[$np] == '7' OR $line[$np] == '8' + OR $line[$np] == '9' ) { + $np++; + } + // grab everything after '###.' + $line = substr($line, $np+1, strlen($line)); - if ($responses AND $answer_found) { - $responses = 0; - $answer_found = 0; - $answer = strtoupper($answer); - $outlines[] = "ANSWER: $answer\n\n"; - } - break; - } - } - if (substr($line, 0, 14) == 'ANSWER CHOICES') { - // don't output this line - } - else { - $outlines[]=$line; - } - } // close for each line + if ($responses AND $answer_found) { + $responses = 0; + $answer_found = 0; + $answer = strtoupper($answer); + $outlines[] = "ANSWER: $answer\n\n"; + } + break; + } + } + if (substr($line, 0, 14) == 'ANSWER CHOICES') { + // don't output this line + } + else { + $outlines[]=$line; + } + } // close for each line - // re-add newline to indicate end of previous question/response - if (count($outlines)) { - $cur_pos = (count($outlines) - 1); - $outlines[$cur_pos] = $outlines[$cur_pos]."\n"; - } + // re-add newline to indicate end of previous question/response + if (count($outlines)) { + $cur_pos = (count($outlines) - 1); + $outlines[$cur_pos] = $outlines[$cur_pos]."\n"; + } - // output the last answer - $answer = strtoupper($answer); - $outlines[] = "ANSWER: $answer\n\n"; - - // output modified file to original - if ( is_writable($filename) ) { - if (! $handle =fopen ($filename ,'w' )) { - echo "Cannot open file ($filename)" ; - exit; - } - foreach ($outlines as $outline) { - fwrite($handle, $outline); - } - fclose($handle); - return true; - } - else { - return false; - } -} -?> \ No newline at end of file + // output the last answer + $answer = strtoupper($answer); + $outlines[] = "ANSWER: $answer\n\n"; + + // output modified file to original + if ( is_writable($filename) ) { + if (! $handle =fopen ($filename ,'w' )) { + echo "Cannot open file ($filename)" ; + exit; + } + foreach ($outlines as $outline) { + fwrite($handle, $outline); + } + fclose($handle); + return true; + } + else { + return false; + } +} +?> diff --git a/mod/lesson/report.php b/mod/lesson/report.php index 66872fa52c2..77dd4888133 100644 --- a/mod/lesson/report.php +++ b/mod/lesson/report.php @@ -40,7 +40,7 @@ if (! $grades = get_records('lesson_grades', 'lessonid', $lesson->id, 'completed')) { $grades = array(); } - + if (! $times = get_records('lesson_timer', 'lessonid', $lesson->id, 'starttime')) { $times = array(); } @@ -90,7 +90,7 @@ if (!array_key_exists($attempt->userid, $studentdata) || !array_key_exists($attempt->retry, $studentdata[$attempt->userid])) { // restore/setup defaults $n = 0; - $timestart = 0; + $timestart = 0; $timeend = 0; $usergrade = NULL; @@ -107,7 +107,7 @@ $n++; // if not equal, then increment n } } - $n = 0; + $n = 0; // search for the time record for this try. if not there, the nulls defined above will be used. foreach($times as $time) { // check to see if the grade matches the correct user @@ -239,32 +239,32 @@ // some stat calculations if ($numofattempts == 0) { - $avescore = get_string("notcompleted", "lesson"); - } else { - $avescore = format_float($avescore/$numofattempts, 2, ".", ","); - } - if ($avetime == NULL) { - $avetime = get_string("notcompleted", "lesson"); - } else { - $avetime = format_float($avetime/$numofattempts, 0, ".", ","); - $avetime = format_time($avetime); - } + $avescore = get_string("notcompleted", "lesson"); + } else { + $avescore = format_float($avescore/$numofattempts, 2, ".", ","); + } + if ($avetime == NULL) { + $avetime = get_string("notcompleted", "lesson"); + } else { + $avetime = format_float($avetime/$numofattempts, 0, ".", ","); + $avetime = format_time($avetime); + } if ($hightime == NULL) { - $hightime = get_string("notcompleted", "lesson"); + $hightime = get_string("notcompleted", "lesson"); } else { - $hightime = format_time($hightime); - } - if ($lowtime == NULL) { - $lowtime = get_string("notcompleted", "lesson"); + $hightime = format_time($hightime); + } + if ($lowtime == NULL) { + $lowtime = get_string("notcompleted", "lesson"); } else { - $lowtime = format_time($lowtime); - } - if ($highscore == NULL) { - $highscore = get_string("notcompleted", "lesson"); - } - if ($lowscore == NULL) { - $lowscore = get_string("notcompleted", "lesson"); - } + $lowtime = format_time($lowtime); + } + if ($highscore == NULL) { + $highscore = get_string("notcompleted", "lesson"); + } + if ($lowscore == NULL) { + $lowscore = get_string("notcompleted", "lesson"); + } // output the stats print_heading(get_string('lessonstats', 'lesson')); diff --git a/mod/lesson/styles.php b/mod/lesson/styles.php index d4c2c6c4490..aa9a1c3d030 100644 --- a/mod/lesson/styles.php +++ b/mod/lesson/styles.php @@ -1,13 +1,13 @@ img { - border:0; + border:0; } .hidden-label { - display: none; + display: none; } .footer { @@ -18,21 +18,21 @@ img { } .leftmenutable { - width:170px; - height:400px; - overflow:auto; - background-color: cellheading2 ?>; - vertical-align:top; + width:170px; + height:400px; + overflow:auto; + background-color: cellheading2 ?>; + vertical-align:top; } .leftmenu a:link, .leftmenu a:active, .leftmenu a:visited, .leftmenu1 a:link, .leftmenu1 a:active, .leftmenu1 a:visited{ - font-size:.7em; - vertical-align:top; + font-size:.7em; + vertical-align:top; } .main a:link, .main a:active, .main a:visited{ - font-size:.9em; - vertical-align:top; + font-size:.9em; + vertical-align:top; } .viewpos { diff --git a/mod/lesson/timer.js b/mod/lesson/timer.js index bb16d1810c5..4d129a311e0 100644 --- a/mod/lesson/timer.js +++ b/mod/lesson/timer.js @@ -7,101 +7,101 @@ // Mark Nielsen modified it to be a countdown timer // for the lesson module in moodle. // -// Below is the code that is used to call this page. -// echo "\n"; +// Below is the code that is used to call this page. +// echo "\n"; // //////////////////////////////////////////////////////////*/ - var myfont_face = "Arial"; - var myfont_size = "12"; - var myfont_color = "#000000"; - var myback_color = "#FFFFFF"; - var mywidth = 80; - var my12_hour = 1; - var stopclock = 0; - - var javatimeDate = new Date(); - var javatime = javatimeDate.getTime(); - javatime = Math.floor(javatime/1000); - - difference = javatime - servertime; - starttime = starttime + difference; + var myfont_face = "Arial"; + var myfont_size = "12"; + var myfont_color = "#000000"; + var myback_color = "#FFFFFF"; + var mywidth = 80; + var my12_hour = 1; + var stopclock = 0; + + var javatimeDate = new Date(); + var javatime = javatimeDate.getTime(); + javatime = Math.floor(javatime/1000); + + difference = javatime - servertime; + starttime = starttime + difference; - var dn = ""; var old = ""; + var dn = ""; var old = ""; - if (document.all||document.getElementById) { document.write(''); } - else if (document.layers) { document.write(''); } - else { old = "true"; show_clock(); } - - /*function leave() { // feable attempt to run a script when someone leaves a timed test early, failed so far - window.onunload = window.open('http://www.google.com','','toolbar=no,menubar=no,location=no,height=500,width=500'); - } - leave();*/ - - function show_clock() { + if (document.all||document.getElementById) { document.write(''); } + else if (document.layers) { document.write(''); } + else { old = "true"; show_clock(); } + + /*function leave() { // feable attempt to run a script when someone leaves a timed test early, failed so far + window.onunload = window.open('http://www.google.com','','toolbar=no,menubar=no,location=no,height=500,width=500'); + } + leave();*/ + + function show_clock() { - //show clock in NS 4 - if (document.layers) + //show clock in NS 4 + if (document.layers) document.ClockPosNS.visibility="show" - if (old == "die") { return; } + if (old == "die") { return; } - currentDate = new Date(); - current = currentDate.getTime(); - current = Math.floor(current/1000); - - if (current > starttime + testlength) { - myclock = ''; - myclock += ''; - myclock += "Time is up"; - myclock += ''; - stopclock = 1; - } else { - timeleft = starttime + testlength - current; - dateobj = new Date(null, null, null, null, null, timeleft, null); - hours = dateobj.getHours(); - minutes = dateobj.getMinutes(); - secs = dateobj.getSeconds(); - - if (secs < 10) { - secs = "0"+secs; - } - - myclock = ''; - myclock += ''; - if (hours > 0) { - myclock += hours+":"; - if (minutes < 10) { - minutes = "0"+minutes; - } - } - myclock += minutes+":"+secs; - myclock += ''; - } - - if (old == "true") { - document.write(myclock); - old = "die"; return; - } + currentDate = new Date(); + current = currentDate.getTime(); + current = Math.floor(current/1000); + + if (current > starttime + testlength) { + myclock = ''; + myclock += ''; + myclock += "Time is up"; + myclock += ''; + stopclock = 1; + } else { + timeleft = starttime + testlength - current; + dateobj = new Date(null, null, null, null, null, timeleft, null); + hours = dateobj.getHours(); + minutes = dateobj.getMinutes(); + secs = dateobj.getSeconds(); + + if (secs < 10) { + secs = "0"+secs; + } + + myclock = ''; + myclock += ''; + if (hours > 0) { + myclock += hours+":"; + if (minutes < 10) { + minutes = "0"+minutes; + } + } + myclock += minutes+":"+secs; + myclock += ''; + } + + if (old == "true") { + document.write(myclock); + old = "die"; return; + } - if (document.layers) { - clockpos = document.ClockPosNS; - liveclock = clockpos.document.LiveClockNS; - liveclock.document.write(myclock); - liveclock.document.close(); - } else if (document.all) { - LiveClockIE.innerHTML = myclock; - } else if (document.getElementById) { - document.getElementById("LiveClockIE").innerHTML = myclock; - } + if (document.layers) { + clockpos = document.ClockPosNS; + liveclock = clockpos.document.LiveClockNS; + liveclock.document.write(myclock); + liveclock.document.close(); + } else if (document.all) { + LiveClockIE.innerHTML = myclock; + } else if (document.getElementById) { + document.getElementById("LiveClockIE").innerHTML = myclock; + } - if (stopclock == 0) { - setTimeout("show_clock()",1000); - } + if (stopclock == 0) { + setTimeout("show_clock()",1000); + } } diff --git a/mod/lesson/view.php b/mod/lesson/view.php index 2425890e4fa..5bb6b14c7de 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -145,8 +145,8 @@ // if pageid is EOL then the end of the lesson has been reached // for flow, changed to simple echo for flow styles, michaelp, moved lesson name and page title down //print_heading($lesson->name); - $timedflag = false; - $attemptflag = false; + $timedflag = false; + $attemptflag = false; if (empty($pageid)) { add_to_log($course->id, 'lesson', 'start', 'view.php?id='. $cm->id, $lesson->id, $cm->id); // if no pageid given see if the lesson has been started @@ -157,13 +157,13 @@ $retries = 0; } if ($retries) { - $attemptflag = true; + $attemptflag = true; } - - if (isset($USER->modattempts[$lesson->id])) { - unset($USER->modattempts[$lesson->id]); // if no pageid, then student is NOT reviewing - } - + + if (isset($USER->modattempts[$lesson->id])) { + unset($USER->modattempts[$lesson->id]); // if no pageid, then student is NOT reviewing + } + // if there are any questions have been answered correctly in this attempt if ($attempts = get_records_select('lesson_attempts', "lessonid = $lesson->id AND userid = $USER->id AND retry = $retries AND @@ -203,7 +203,7 @@ echo '

    \n"; /// CDC-FLAG added document.queryform.startlastseen.value='yes' echo '
    ' . "\n"; - echo '';///CDC Chris Berri added close div tag + echo '';///CDC Chris Berri added close div tag } else { print_simple_box_start('center'); echo '
    '; @@ -227,10 +227,10 @@ echo "\n"; echo "
    ";///CDC Chris Berri added close div tag } print_footer($course); - exit(); + exit(); } } - + if ($grades) { foreach ($grades as $grade) { $bestgrade = $grade->grade; @@ -253,9 +253,9 @@ } } // start at the first page - if (!$pageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { - error('Navigation: first page not found'); - } + if (!$pageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { + error('Navigation: first page not found'); + } /// CDC-FLAG /// -- This is the code for starting a timed test if(!isset($USER->startlesson[$lesson->id]) && !isteacher($course->id)) { $USER->startlesson[$lesson->id] = true; @@ -265,16 +265,16 @@ $startlesson->starttime = time(); $startlesson->lessontime = time(); - if (!insert_record('lesson_timer', $startlesson)) { - error('Error: could not insert row into lesson_timer table'); - } - if ($lesson->timed) { - $timedflag = true; - } + if (!insert_record('lesson_timer', $startlesson)) { + error('Error: could not insert row into lesson_timer table'); + } + if ($lesson->timed) { + $timedflag = true; + } } /// CDC-FLAG /// } - + if ($pageid != LESSON_EOL) { /// This is the code updates the lessontime for a timed test if (isset($_POST['startlastseen'])) { /// this deletes old records not totally sure if this is necessary anymore @@ -294,21 +294,21 @@ } } } - + add_to_log($course->id, 'lesson', 'view', 'view.php?id='. $cm->id, $pageid, $cm->id); if (!$page = get_record('lesson_pages', 'id', $pageid)) { error('Navigation: the page record not found'); } if ($page->qtype == LESSON_CLUSTER) { //this only gets called when a user starts up a new lesson and the first page is a cluster page - if (!isteacher($course->id)) { - // get new id - $pageid = lesson_cluster_jump($lesson->id, $USER->id, $pageid); - // get new page info - if (!$page = get_record('lesson_pages', 'id', $pageid)) { - error('Navigation: the page record not found'); - } - add_to_log($course->id, 'lesson', 'view', 'view.php?id='. $cm->id, $pageid, $cm->id); + if (!isteacher($course->id)) { + // get new id + $pageid = lesson_cluster_jump($lesson->id, $USER->id, $pageid); + // get new page info + if (!$page = get_record('lesson_pages', 'id', $pageid)) { + error('Navigation: the page record not found'); + } + add_to_log($course->id, 'lesson', 'view', 'view.php?id='. $cm->id, $pageid, $cm->id); } else { // get the next page $pageid = $page->nextpageid; @@ -324,120 +324,120 @@ } redirect("view.php?id=$cm->id&action=navigation&pageid=$nextpageid", get_string('endofclustertitle', 'lesson')); } - - // start of left menu - if ($lesson->displayleft) { - echo '
    '; - if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { - // print the pages - echo '
    '; - echo ''; - echo ''; - echo ''; - echo "
    "; - echo "
    ".get_string('lessonmenu', 'lesson')."
    "; - echo ""; - echo '
    '; - lesson_print_tree_menu($lesson->id, $firstpageid, $cm->id); - echo '
    '; //close lmlinks - echo '
    '; - } - echo '
    '; - } elseif ($lesson->slideshow && $page->qtype == LESSON_BRANCHTABLE) { - echo '
    '; // only want this if no left menu - } + + // start of left menu + if ($lesson->displayleft) { + echo '
    '; + if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { + // print the pages + echo '
    '; + echo ''; + echo ''; + echo ''; + echo "
    "; + echo "
    ".get_string('lessonmenu', 'lesson')."
    "; + echo ""; + echo '
    '; + lesson_print_tree_menu($lesson->id, $firstpageid, $cm->id); + echo '
    '; //close lmlinks + echo '
    '; + } + echo '
    '; + } elseif ($lesson->slideshow && $page->qtype == LESSON_BRANCHTABLE) { + echo '"; if ($answer != end($answers)) { - echo ""; + echo ""; } } } echo '
    '; // only want this if no left menu + } - // starts the slideshow div - if($lesson->slideshow && $page->qtype == LESSON_BRANCHTABLE) { - echo "
    bgcolor; - height: ".$lesson->height."px; - width: ".$lesson->width."px; - overflow: auto; - border: 0px solid #ccc; - padding-right: 16px; /* for the benefit of macIE5 only */ - /* \ commented backslash hack - recover from macIE5 workarounds, it will ignore the following rule */ - padding-right: 0; - padding: 15px; - \">\n"; + // starts the slideshow div + if($lesson->slideshow && $page->qtype == LESSON_BRANCHTABLE) { + echo "
    bgcolor; + height: ".$lesson->height."px; + width: ".$lesson->width."px; + overflow: auto; + border: 0px solid #ccc; + padding-right: 16px; /* for the benefit of macIE5 only */ + /* \ commented backslash hack - recover from macIE5 workarounds, it will ignore the following rule */ + padding-right: 0; + padding: 15px; + \">\n"; echo ""; if ($answer != end($answers)) { - echo ""; + echo ""; } $i++; } echo '
    \n"; - } else { + } else { echo ""; if ($answer != end($answers)) { - echo ""; + echo ""; } } echo '
    \n"; - $lesson->slideshow = false; // turn off slide show for all pages other than LESSON_BRANTCHTABLE - } + $lesson->slideshow = false; // turn off slide show for all pages other than LESSON_BRANTCHTABLE + } - // This is where several messages (usually warnings) are displayed - // all of this is displayed above the actual page + // This is where several messages (usually warnings) are displayed + // all of this is displayed above the actual page - // clock code - // get time information for this user - if(!isteacher($course->id)) { - if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) { - error('Error: could not find records'); - } else { - $timer = array_pop($timer); // this will get the latest start time record - } - } - - if (isset($_POST['startlastseen'])) { - if ($_POST['startlastseen'] == 'yes') { // continue a previous test, need to update the clock (think this option is disabled atm) - $timer->starttime = time() - ($timer->lessontime - $timer->starttime); - $timer->lessontime = time(); - } elseif ($_POST['startlastseen'] == 'no') { // starting over - // starting over, so reset the clock - $timer->starttime = time(); - $timer->lessontime = time(); - } - } - - // for timed lessons, display clock - if ($lesson->timed) { - if(isteacher($course->id)) { - echo '

    '. get_string('teachertimerwarning', 'lesson') .'

    '; - } else { - if ((($timer->starttime + $lesson->maxtime * 60) - time()) > 0) { - // code for the clock - print_simple_box_start("right", "150px", "#ffffff", 0); - echo "". - "
    ".get_string("timeremaining", "lesson"). - "
    "; - echo "\n"; - echo "
    "; - print_simple_box_end(); - echo "


    "; - } else { - redirect("view.php?id=$cm->id&action=navigation&pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson")); - } - // update clock when viewing a new page... no special treatment - if ((($timer->starttime + $lesson->maxtime * 60) - time()) < 60) { - echo "

    ".get_string('studentoneminwarning', 'lesson')."

    "; - } - - if ($timedflag) { - print_simple_box(get_string('maxtimewarning', 'lesson', $lesson->maxtime), 'center'); - } - } - } + // clock code + // get time information for this user + if(!isteacher($course->id)) { + if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) { + error('Error: could not find records'); + } else { + $timer = array_pop($timer); // this will get the latest start time record + } + } + + if (isset($_POST['startlastseen'])) { + if ($_POST['startlastseen'] == 'yes') { // continue a previous test, need to update the clock (think this option is disabled atm) + $timer->starttime = time() - ($timer->lessontime - $timer->starttime); + $timer->lessontime = time(); + } elseif ($_POST['startlastseen'] == 'no') { // starting over + // starting over, so reset the clock + $timer->starttime = time(); + $timer->lessontime = time(); + } + } + + // for timed lessons, display clock + if ($lesson->timed) { + if(isteacher($course->id)) { + echo '

    '. get_string('teachertimerwarning', 'lesson') .'

    '; + } else { + if ((($timer->starttime + $lesson->maxtime * 60) - time()) > 0) { + // code for the clock + print_simple_box_start("right", "150px", "#ffffff", 0); + echo "". + "
    ".get_string("timeremaining", "lesson"). + "
    "; + echo "\n"; + echo "
    "; + print_simple_box_end(); + echo "


    "; + } else { + redirect("view.php?id=$cm->id&action=navigation&pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson")); + } + // update clock when viewing a new page... no special treatment + if ((($timer->starttime + $lesson->maxtime * 60) - time()) < 60) { + echo "

    ".get_string('studentoneminwarning', 'lesson')."

    "; + } + + if ($timedflag) { + print_simple_box(get_string('maxtimewarning', 'lesson', $lesson->maxtime), 'center'); + } + } + } - // update the clock - if (!isteacher($course->id)) { - $timer->lessontime = time(); - if (!update_record('lesson_timer', $timer)) { - error('Error: could not update lesson_timer table'); - } - } - - if ($attemptflag) { - print_heading(get_string('attempt', 'lesson', $retries + 1)); - } - + // update the clock + if (!isteacher($course->id)) { + $timer->lessontime = time(); + if (!update_record('lesson_timer', $timer)) { + error('Error: could not update lesson_timer table'); + } + } + + if ($attemptflag) { + print_heading(get_string('attempt', 'lesson', $retries + 1)); + } + // before we output everything check to see if the page is a EOB, if so jump directly // to it's associated branch table if ($page->qtype == LESSON_ENDOFBRANCH) { @@ -470,29 +470,29 @@ error('Navigation: No answers on EOB'); } } - - /// This is the warning msg for teachers to inform them that cluster and unseen does not work while logged in as a teacher - if(isteacher($course->id)) { - if (execute_teacherwarning($lesson->id)) { - $warningvars->cluster = get_string('clusterjump', 'lesson'); - $warningvars->unseen = get_string('unseenpageinbranch', 'lesson'); - echo '

    '. get_string('teacherjumpwarning', 'lesson', $warningvars) .'

    '; - } - } - + + /// This is the warning msg for teachers to inform them that cluster and unseen does not work while logged in as a teacher + if(isteacher($course->id)) { + if (execute_teacherwarning($lesson->id)) { + $warningvars->cluster = get_string('clusterjump', 'lesson'); + $warningvars->unseen = get_string('unseenpageinbranch', 'lesson'); + echo '

    '. get_string('teacherjumpwarning', 'lesson', $warningvars) .'

    '; + } + } + /// this calculates the ongoing score if ($lesson->ongoing && !empty($pageid)) { if (isteacher($course->id)) { echo "

    ".get_string('teacherongoingwarning', 'lesson').'

    '; } else { - $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); - if (isset($USER->modattempts[$lesson->id])) { - $ntries--; - } - lesson_calculate_ongoing_score($lesson, $USER->id, $ntries); + $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); + if (isset($USER->modattempts[$lesson->id])) { + $ntries--; + } + lesson_calculate_ongoing_score($lesson, $USER->id, $ntries); } } - + if ($page->qtype == LESSON_BRANCHTABLE) { if ($lesson->minquestions and isstudent($course->id)) { // tell student how many questions they have seen, how many are required and their grade @@ -524,8 +524,8 @@ } } - // now starting to print the page's contents - echo "
    "; + // now starting to print the page's contents + echo "
    "; echo ""; echo ($lesson->name) . ""; if ($page->qtype == LESSON_BRANCHTABLE) { @@ -540,66 +540,66 @@ print_simple_box(format_text($page->contents), 'center'); } echo "
    \n"; - - // this is for modattempts option. Find the users previous answer to this page, - // and then display it below in answer processing - if (isset($USER->modattempts[$lesson->id])) { - $retries = count_records('lesson_grades', "lessonid", $lesson->id, "userid", $USER->id); - $retries--; - if (! $attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND pageid = $page->id AND retry = $retries", "timeseen")) { - error("Previous attempt record could not be found!"); - } - $attempt = end($attempts); - } - + + // this is for modattempts option. Find the users previous answer to this page, + // and then display it below in answer processing + if (isset($USER->modattempts[$lesson->id])) { + $retries = count_records('lesson_grades', "lessonid", $lesson->id, "userid", $USER->id); + $retries--; + if (! $attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND pageid = $page->id AND retry = $retries", "timeseen")) { + error("Previous attempt record could not be found!"); + } + $attempt = end($attempts); + } + // get the answers in a set order, the id order if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { echo "
    "; echo "id\" />"; echo ""; echo ""; - echo "sesskey."\" />"; + echo "sesskey."\" />"; if (!$lesson->slideshow) { print_simple_box_start("center"); - echo ''; + echo '
    '; } switch ($page->qtype) { case LESSON_SHORTANSWER : case LESSON_NUMERICAL : - if (isset($USER->modattempts[$lesson->id])) { - $value = "value=\"$attempt->useranswer\""; - } else { - $value = ""; - } + if (isset($USER->modattempts[$lesson->id])) { + $value = "value=\"$attempt->useranswer\""; + } else { + $value = ""; + } echo "
    ".get_string("youranswer", "lesson"). ": \n"; //CDC hidden label added. echo '
    '; print_simple_box_end(); - echo "

    \n"; + echo "

    \n"; break; case LESSON_TRUEFALSE : shuffle($answers); foreach ($answers as $answer) { echo "
    "; - if (isset($USER->modattempts[$lesson->id]) && $answer->id == $attempt->answerid) { - $checked = "checked=\"checked\""; - } else { - $checked = ""; - } + if (isset($USER->modattempts[$lesson->id]) && $answer->id == $attempt->answerid) { + $checked = "checked=\"checked\""; + } else { + $checked = ""; + } echo "id}\" $checked />"; //CDC hidden label added. echo ""; $options->para = false; // no

    echo format_text(trim($answer->answer), FORMAT_MOODLE, $options); echo "


    '; print_simple_box_end(); - echo "

    \n"; + echo "

    \n"; break; case LESSON_MULTICHOICE : $i = 0; @@ -607,23 +607,23 @@ foreach ($answers as $answer) { echo "
    "; if ($page->qoption) { - $checked = ""; - if (isset($USER->modattempts[$lesson->id])) { - $answerids = explode(",", $attempt->useranswer); - if (in_array($answer->id, $answerids)) { - $checked = "checked=\"checked\""; - } else { - $checked = ""; - } - } + $checked = ""; + if (isset($USER->modattempts[$lesson->id])) { + $answerids = explode(",", $attempt->useranswer); + if (in_array($answer->id, $answerids)) { + $checked = "checked=\"checked\""; + } else { + $checked = ""; + } + } // more than one answer allowed echo "id}\" $checked />"; //CDC hidden label added. } else { - if (isset($USER->modattempts[$lesson->id]) && $answer->id == $attempt->answerid) { - $checked = "checked=\"checked\""; - } else { - $checked = ""; - } + if (isset($USER->modattempts[$lesson->id]) && $answer->id == $attempt->answerid) { + $checked = "checked=\"checked\""; + } else { + $checked = ""; + } // only one answer allowed echo "id}\" $checked />"; //CDC hidden label added. } @@ -632,19 +632,19 @@ echo format_text(trim($answer->answer), FORMAT_MOODLE, $options); echo "


    '; print_simple_box_end(); - if ($page->qoption) { - echo "

    \n"; - } else { - echo "

    \n"; - } + if ($page->qoption) { + echo "

    \n"; + } else { + echo "

    \n"; + } break; /// CDC-FLAG /// 6/14/04 --- changed how matching works @@ -659,105 +659,105 @@ } shuffle($responses); $responses = array_unique($responses); - + if (isset($USER->modattempts[$lesson->id])) { - $useranswers = explode(",", $attempt->useranswer); - $t = 0; - } + $useranswers = explode(",", $attempt->useranswer); + $t = 0; + } foreach ($answers as $answer) { if ($answer->response != NULL) { echo "
    "; echo "$answer->answer: "; echo ""; echo "


    '; print_simple_box_end(); - echo "

    \n"; + echo "

    \n"; break; case LESSON_BRANCHTABLE : - if ($lesson->slideshow) { - echo "
    "; - } else { - echo "
    "; - } + if ($lesson->slideshow) { + echo "
    "; + } else { + echo "
    "; + } echo ""; - $nextprevious = array(); - $otherjumps = array(); - // seperate out next and previous jumps from the other jumps - foreach ($answers as $answer) { - if($answer->jumpto == LESSON_NEXTPAGE || $answer->jumpto == LESSON_PREVIOUSPAGE) { - $nextprevious[] = $answer; - } else { - $otherjumps[] = $answer; - } - } - if ($page->layout) { - echo ""; - // next 3 foreach loops print out the links in correct order - foreach ($nextprevious as $jump) { - if ($jump->jumpto == LESSON_PREVIOUSPAGE) { - echo ""; - } - } - echo ""; - foreach ($nextprevious as $jump) { - if ($jump->jumpto == LESSON_NEXTPAGE) { - echo ""; - } - } - echo ""; - } else { - // next 3 foreach loops print out the links in correct order - foreach ($nextprevious as $jump) { - if ($jump->jumpto == LESSON_NEXTPAGE) { - echo ""; - } - } - foreach ($otherjumps as $otherjump) { - echo ""; - } - foreach ($nextprevious as $jump) { - if ($jump->jumpto == LESSON_PREVIOUSPAGE) { - echo ""; - } - } - } - + $nextprevious = array(); + $otherjumps = array(); + // seperate out next and previous jumps from the other jumps + foreach ($answers as $answer) { + if($answer->jumpto == LESSON_NEXTPAGE || $answer->jumpto == LESSON_PREVIOUSPAGE) { + $nextprevious[] = $answer; + } else { + $otherjumps[] = $answer; + } + } + if ($page->layout) { + echo ""; + // next 3 foreach loops print out the links in correct order + foreach ($nextprevious as $jump) { + if ($jump->jumpto == LESSON_PREVIOUSPAGE) { + echo ""; + } + } + echo ""; + foreach ($nextprevious as $jump) { + if ($jump->jumpto == LESSON_NEXTPAGE) { + echo ""; + } + } + echo ""; + } else { + // next 3 foreach loops print out the links in correct order + foreach ($nextprevious as $jump) { + if ($jump->jumpto == LESSON_NEXTPAGE) { + echo ""; + } + } + foreach ($otherjumps as $otherjump) { + echo ""; + } + foreach ($nextprevious as $jump) { + if ($jump->jumpto == LESSON_PREVIOUSPAGE) { + echo ""; + } + } + } + /* if(!$lesson->slideshow) { - foreach ($answers as $answer) { + foreach ($answers as $answer) { echo "
    jumpto;document.answerform.submit();\"". - "value = \"$jump->answer\" />"; - foreach ($otherjumps as $otherjump) { - echo ""; - } - echo "
    jumpto;document.answerform.submit();\"". - "value = \"$otherjump->answer\" />
    jumpto;document.answerform.submit();\"". - "value = \"$jump->answer\" />
    jumpto;document.answerform.submit();\"". - "value = \"$jump->answer\" />
    jumpto;document.answerform.submit();\"". - "value = \"$otherjump->answer\" />
    jumpto;document.answerform.submit();\"". - "value = \"$jump->answer\" />
    jumpto;document.answerform.submit();\"". + "value = \"$jump->answer\" />"; + foreach ($otherjumps as $otherjump) { + echo ""; + } + echo "
    jumpto;document.answerform.submit();\"". + "value = \"$otherjump->answer\" />
    jumpto;document.answerform.submit();\"". + "value = \"$jump->answer\" />
    jumpto;document.answerform.submit();\"". + "value = \"$jump->answer\" />
    jumpto;document.answerform.submit();\"". + "value = \"$otherjump->answer\" />
    jumpto;document.answerform.submit();\"". + "value = \"$jump->answer\" />
    "; echo "answer\""; echo "onclick=\"document.answerform.jumpto.value=$answer->jumpto;document.answerform.submit();\" />"; @@ -765,26 +765,26 @@ } }*/ if (!$lesson->slideshow) { - echo '
    '; - print_simple_box_end(); - } + echo '
    '; + print_simple_box_end(); + } break; case LESSON_ESSAY : if (isset($USER->modattempts[$lesson->id])) { - $essayinfo = unserialize($attempt->useranswer); - $value = $essayinfo->answer; - } else { - $value = ""; - } + $essayinfo = unserialize($attempt->useranswer); + $value = $essayinfo->answer; + } else { + $value = ""; + } echo "
    ".get_string("youranswer", "lesson").":". "\n"; //CDC hidden label added. echo "
    "; print_simple_box_end(); - echo "

    \n"; + echo "

    \n"; break; } - echo "\n"; + echo "\n"; } else { // a page without answers - find the next (logical) page echo "
    \n"; @@ -853,35 +853,35 @@ if (isset($USER->lessonloggedin[$lesson->id])) { unset($USER->lessonloggedin[$lesson->id]); } - // Update the clock / get time information for this user - if (!isteacher($course->id)) { - unset($USER->startlesson[$lesson->id]); - if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) { - error('Error: could not find records'); - } else { - $timer = array_pop($timer); // this will get the latest start time record - } - $timer->lessontime = time(); - - if (!update_record("lesson_timer", $timer)) { - error("Error: could not update lesson_timer table"); - } - } - + // Update the clock / get time information for this user + if (!isteacher($course->id)) { + unset($USER->startlesson[$lesson->id]); + if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) { + error('Error: could not find records'); + } else { + $timer = array_pop($timer); // this will get the latest start time record + } + $timer->lessontime = time(); + + if (!update_record("lesson_timer", $timer)) { + error("Error: could not update lesson_timer table"); + } + } + add_to_log($course->id, "lesson", "end", "view.php?id=$cm->id", "$lesson->id", $cm->id); print_heading(get_string("congratulations", "lesson")); print_simple_box_start("center"); $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); - if (isset($USER->modattempts[$lesson->id])) { - $ntries--; // need to look at the old attempts :) - } + if (isset($USER->modattempts[$lesson->id])) { + $ntries--; // need to look at the old attempts :) + } if (isstudent($course->id)) { if ($nviewed = count_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, "retry", $ntries)) { /// CDC-FLAG /// 6/11/04 if (!$lesson->custom) { - $ncorrect = 0; - $temp = array(); + $ncorrect = 0; + $temp = array(); if ($pagesanswered = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries order by timeseen")) { @@ -923,55 +923,55 @@ } else { $score = 0; $essayquestions = 0; - $essayquestionpoints = 0; + $essayquestionpoints = 0; if ($useranswers = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries", "timeseen")) { - // group each try with its page + // group each try with its page foreach ($useranswers as $useranswer) { - $attemptset[$useranswer->pageid][] = $useranswer; - } - - $pageids = array_keys($attemptset); - $pageids = implode(",", $pageids); - - // get only the pages and their answers that the user answered - $answeredpages = get_records_select("lesson_pages", "lessonid = $lesson->id AND id IN($pageids)"); - $pageanswers = get_records_select("lesson_answers", "lessonid = $lesson->id AND pageid IN($pageids)"); + $attemptset[$useranswer->pageid][] = $useranswer; + } + + $pageids = array_keys($attemptset); + $pageids = implode(",", $pageids); + + // get only the pages and their answers that the user answered + $answeredpages = get_records_select("lesson_pages", "lessonid = $lesson->id AND id IN($pageids)"); + $pageanswers = get_records_select("lesson_answers", "lessonid = $lesson->id AND pageid IN($pageids)"); - foreach ($attemptset as $attempts) { - if(count($attempts) > $lesson->maxattempts) { // if there are more tries than the max that is allowed, grab the last "legal" attempt - $attempt = $attempts[$lesson->maxattempts - 1]; - } else { - // else, user attempted the question less than the max, so grab the last one - $attempt = end($attempts); - } - // if essay question, handle it, otherwise add to score - if ($answeredpages[$attempt->pageid]->qtype == LESSON_ESSAY) { - $essayinfo = unserialize($attempt->useranswer); - $score += $essayinfo->score; - $essayquestions++; - $essayquestionpoints += $pageanswers[$attempt->answerid]->score; - } else { - $score += $pageanswers[$attempt->answerid]->score; - } - } - $bestscores = array(); - // find the highest possible score per page - foreach ($pageanswers as $pageanswer) { - if(isset($bestscores[$pageanswer->pageid])) { - if ($bestscores[$pageanswer->pageid] < $pageanswer->score) { - $bestscores[$pageanswer->pageid] = $pageanswer->score; - } - } else { - $bestscores[$pageanswer->pageid] = $pageanswer->score; - } - } - - $bestscore = array_sum($bestscores); - } - - $thegrade = intval(100 * $score / $bestscore); + foreach ($attemptset as $attempts) { + if(count($attempts) > $lesson->maxattempts) { // if there are more tries than the max that is allowed, grab the last "legal" attempt + $attempt = $attempts[$lesson->maxattempts - 1]; + } else { + // else, user attempted the question less than the max, so grab the last one + $attempt = end($attempts); + } + // if essay question, handle it, otherwise add to score + if ($answeredpages[$attempt->pageid]->qtype == LESSON_ESSAY) { + $essayinfo = unserialize($attempt->useranswer); + $score += $essayinfo->score; + $essayquestions++; + $essayquestionpoints += $pageanswers[$attempt->answerid]->score; + } else { + $score += $pageanswers[$attempt->answerid]->score; + } + } + $bestscores = array(); + // find the highest possible score per page + foreach ($pageanswers as $pageanswer) { + if(isset($bestscores[$pageanswer->pageid])) { + if ($bestscores[$pageanswer->pageid] < $pageanswer->score) { + $bestscores[$pageanswer->pageid] = $pageanswer->score; + } + } else { + $bestscores[$pageanswer->pageid] = $pageanswer->score; + } + } + + $bestscore = array_sum($bestscores); + } + + $thegrade = intval(100 * $score / $bestscore); $a = new stdClass; if ($essayquestions > 0) { $a->score = $score; @@ -982,44 +982,44 @@ } else { $a->score = $score; $a->grade = $bestscore; - echo "
    ".get_string("displayscorewithoutessays", "lesson", $a)."
    "; + echo "
    ".get_string("displayscorewithoutessays", "lesson", $a)."
    "; } - echo "

    ".get_string("gradeis", "lesson", + echo "

    ".get_string("gradeis", "lesson", number_format($thegrade * $lesson->grade / 100, 1)). " (".get_string("outof", "lesson", $lesson->grade).")

    \n"; } - /// CDC-FLAG /// + /// CDC-FLAG /// $grade->lessonid = $lesson->id; $grade->userid = $USER->id; $grade->grade = $thegrade; $grade->completed = time(); if (!$lesson->practice) { - if (isset($USER->modattempts[$lesson->id])) { // if reviewing, make sure update old grade record - if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid = $USER->id", "completed")) { - error("Could not find Grade Records"); - } - $oldgrade = end($grades); - $grade->id = $oldgrade->id; - if (!$update = update_record("lesson_grades", $grade)) { - error("Navigation: grade not updated"); - } - } else { - if (!$newgradeid = insert_record("lesson_grades", $grade)) { - error("Navigation: grade not inserted"); - } - } + if (isset($USER->modattempts[$lesson->id])) { // if reviewing, make sure update old grade record + if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid = $USER->id", "completed")) { + error("Could not find Grade Records"); + } + $oldgrade = end($grades); + $grade->id = $oldgrade->id; + if (!$update = update_record("lesson_grades", $grade)) { + error("Navigation: grade not updated"); + } + } else { + if (!$newgradeid = insert_record("lesson_grades", $grade)) { + error("Navigation: grade not inserted"); + } + } } else { if (!delete_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, "retry", $ntries)) { error("Could not delete lesson attempts"); } } } else { - //print_string("noattemptrecordsfound", "lesson"); + //print_string("noattemptrecordsfound", "lesson"); if ($lesson->timed) { if (isset($_GET["outoftime"])) { if ($_GET["outoftime"] == "normal") { - $grade = new stdClass; + $grade = new stdClass; $grade->lessonid = $lesson->id; $grade->userid = $USER->id; $grade->grade = 0; @@ -1070,41 +1070,41 @@ } } echo "
    id&action=highscores&link=1\">".get_string("viewhighscores", "lesson").""; - echo ""; + echo ""; + } + /// CDC-FLAG /// + if ($lesson->modattempts && !isteacher($course->id)) { + // make sure if the student is reviewing, that he/she sees the same pages/page path that he/she saw the first time + // look at the attempt records to find the first QUESTION page that the user answered, then use that page id + // to pass to view again. This is slick cause it wont call the empty($pageid) code + // $ntries is decremented above + $attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries", "timeseen"); + $firstattempt = current($attempts); + $pageid = $firstattempt->pageid; + // IF the student wishes to review, need to know the last question page that the student answered. This will help to make + // sure that the student can leave the lesson via pushing the continue button. + $lastattempt = end($attempts); + $USER->modattempts[$lesson->id] = $lastattempt->pageid; + echo "id\">"; + echo ""; + echo "
    "; + echo "

    ".get_string("reviewlesson", "lesson")."

    \n"; + } elseif ($lesson->modattempts && isteacher($course->id)) { + echo "

    ".get_string("modattemptsnoteacher", "lesson")."

    "; } - /// CDC-FLAG /// - if ($lesson->modattempts && !isteacher($course->id)) { - // make sure if the student is reviewing, that he/she sees the same pages/page path that he/she saw the first time - // look at the attempt records to find the first QUESTION page that the user answered, then use that page id - // to pass to view again. This is slick cause it wont call the empty($pageid) code - // $ntries is decremented above - $attempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND userid = $USER->id AND retry = $ntries", "timeseen"); - $firstattempt = current($attempts); - $pageid = $firstattempt->pageid; - // IF the student wishes to review, need to know the last question page that the student answered. This will help to make - // sure that the student can leave the lesson via pushing the continue button. - $lastattempt = end($attempts); - $USER->modattempts[$lesson->id] = $lastattempt->pageid; - echo "
    id\">"; - echo ""; - echo "
    "; - echo "

    ".get_string("reviewlesson", "lesson")."

    \n"; - } elseif ($lesson->modattempts && isteacher($course->id)) { - echo "

    ".get_string("modattemptsnoteacher", "lesson")."

    "; - } echo "

    id\">".get_string("mainmenu", "lesson")."

    \n"; //CDC Back to the menu (course view). echo "

    id\">".get_string("viewgrades", "lesson")."

    \n"; //CDC view grades } if ($lesson->displayleft || $lesson->slideshow) { // this ends the table cell and table for the leftmenu or for slideshow - echo ""; + echo ""; } } /*******************teacher view **************************************/ elseif ($action == 'teacherview') { - print_heading_with_help($lesson->name, "overview", "lesson"); + print_heading_with_help($lesson->name, "overview", "lesson"); // get number of pages if ($page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) { $npages = 1; @@ -1137,26 +1137,26 @@ } print_simple_box_end(); echo ""; //CDC Chris Berri added. - /// CDC-FLAG /// + /// CDC-FLAG /// } else { - print_heading("id&action=navigation\">".get_string("checknavigation", - "lesson")."\n"); + print_heading("id&action=navigation\">".get_string("checknavigation", + "lesson")."\n"); // print the pages echo "
    \n"; echo "id\" />\n"; echo "\n"; echo "\n"; /// CDC-FLAG /// link to grade essay questions and to report - if ($testattempts = get_records("lesson_attempts", "lessonid", $lesson->id)) { // just check to see if anyone has answered any questions. - echo "
    id\">".get_string("viewlessonstats", "lesson")."
    "; - } - if ($essaypages = get_records_select("lesson_pages", "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { // get pages that are essay - // get only the attempts that are in response to essay questions - $essaypageids = implode(",", array_keys($essaypages)); // all the pageids in comma seperated list - if ($essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($essaypageids)")) { - echo "
    id&action=essayview\">".get_string("gradeessay", "lesson")."

    "; - } - } + if ($testattempts = get_records("lesson_attempts", "lessonid", $lesson->id)) { // just check to see if anyone has answered any questions. + echo "
    id\">".get_string("viewlessonstats", "lesson")."
    "; + } + if ($essaypages = get_records_select("lesson_pages", "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { // get pages that are essay + // get only the attempts that are in response to essay questions + $essaypageids = implode(",", array_keys($essaypages)); // all the pageids in comma seperated list + if ($essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($essaypageids)")) { + echo "
    id&action=essayview\">".get_string("gradeessay", "lesson")."

    "; + } + } /// CDC-FLAG /// tree code - in final release, will use lang file for all text output. // NoticeFix next two lines and bowth viewAlls $branch = false; @@ -1172,7 +1172,7 @@ echo ""; } else { if(isset($_GET['display']) && !isset($_GET['viewAll'])) { - $display = clean_param($_GET['display'], PARAM_INT); + $display = clean_param($_GET['display'], PARAM_INT); while(true) { if($page->id == $display && $page->qtype == LESSON_BRANCHTABLE) { @@ -1181,7 +1181,7 @@ break; } elseif($page->id == $display) { $branch = false; - $singlePage = true; + $singlePage = true; break; } elseif ($page->nextpageid) { if (!$page = get_record("lesson_pages", "id", $page->nextpageid)) { @@ -1196,7 +1196,7 @@ echo "".get_string("backtreeview", "lesson")."
    \n"; echo "\n"; if (isteacheredit($course->id)) { - /// CDC-FLAG 6/16/04 /// + /// CDC-FLAG 6/16/04 /// echo "\n"; - /// CDC-FLAG /// - } + /// CDC-FLAG /// + } } else { if($lesson->tree) { echo "
    ".get_string("backtreeview", "lesson")."
    \n"; - } + } echo "
    id&pageid=$page->prevpageid\">". get_string("importquestions", "lesson")." | ". "id&sesskey=".$USER->sesskey."&action=addcluster&pageid=$page->prevpageid\">". @@ -1208,12 +1208,12 @@ "id&action=addpage&pageid=$page->prevpageid\">". get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). "
    \n"; if (isteacheredit($course->id)) { /// CDC-FLAG 6/16/04 /// @@ -1229,9 +1229,9 @@ /// CDC-FLAG /// } } - /// CDC-FLAG /// end tree code (note, there is an "}" below for an else above) + /// CDC-FLAG /// end tree code (note, there is an "}" below for an else above) while (true) { - echo "\n"; if (isteacheredit($course->id)) { - /// CDC-FLAG /// 6/16/04 + /// CDC-FLAG /// 6/16/04 echo "
    \n"; + echo "
    \n"; echo "\n"; - break; + break; case LESSON_MATCHING: if ($n < 2) { if ($answer->answer != NULL) { @@ -1373,7 +1373,7 @@ $jumptitle = get_string("nextpage", "lesson"); } elseif ($answer->jumpto == LESSON_EOL) { $jumptitle = get_string("endoflesson", "lesson"); -/* CDC-FLAG 6/17/04 */ } elseif ($answer->jumpto == LESSON_UNSEENBRANCHPAGE) { +/* CDC-FLAG 6/17/04 */ } elseif ($answer->jumpto == LESSON_UNSEENBRANCHPAGE) { $jumptitle = get_string("unseenpageinbranch", "lesson"); // a better way is get_string("unseenbranchpage", "lesson"); and define in lang file } elseif ($answer->jumpto == LESSON_PREVIOUSPAGE) { $jumptitle = get_string("previouspage", "lesson"); @@ -1382,7 +1382,7 @@ } elseif ($answer->jumpto == LESSON_RANDOMBRANCH) { $jumptitle = get_string("randombranch", "lesson"); } elseif ($answer->jumpto == LESSON_CLUSTERJUMP) { - $jumptitle = get_string("clusterjump", "lesson"); /// CDC-FLAG /// + $jumptitle = get_string("clusterjump", "lesson"); /// CDC-FLAG /// } else { if (!$jumptitle = get_field("lesson_pages", "title", "id", $answer->jumpto)) { $jumptitle = "".get_string("notdefined", "lesson").""; @@ -1406,7 +1406,7 @@ echo "$jumptitle\n"; } } else { - if ($lesson->custom && $page->qtype != LESSON_BRANCHTABLE && $page->qtype != LESSON_ENDOFBRANCH) { + if ($lesson->custom && $page->qtype != LESSON_BRANCHTABLE && $page->qtype != LESSON_ENDOFBRANCH) { echo "\n"; @@ -1433,7 +1433,7 @@ } echo "
    $page->title  \n"; if (isteacheredit($course->id)) { if ($npages > 1) { @@ -1315,7 +1315,7 @@ echo "\n"; echo format_text($answer->response); echo "
    ".get_string("score", "lesson")." $i:"; echo "\n"; echo "$answer->score
    id&pageid=$page->id\">". get_string("importquestions", "lesson")." | ". "id&sesskey=".$USER->sesskey."&action=addcluster&pageid=$page->id\">". @@ -1442,7 +1442,7 @@ get_string("addendofcluster", "lesson")." | ". "id&action=addbranchtable&pageid=$page->id\">". get_string("addabranchtable", "lesson")."
    "; - /// CDC-FLAG /// + /// CDC-FLAG /// // the current page or the next page is an end of branch don't show EOB link $nextqtype = 0; // set to anything else EOB if ($page->nextpageid) { @@ -1496,7 +1496,7 @@ if($lesson->tree && (isset($_GET['display']) || isset($_GET['viewAll']))) { echo "
    ".get_string("backtreeview", "lesson")."
    \n"; } - /// CDC-FLAG /// + /// CDC-FLAG /// print_heading("id&action=navigation\">".get_string("checknavigation", "lesson")."\n"); } @@ -1506,90 +1506,90 @@ elseif ($action == 'essayview') { print_heading_with_help($lesson->name, "overview", "lesson"); - // get lesson pages that are essay + // get lesson pages that are essay if (!$pages = get_records_select("lesson_pages", "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { error("Error: could not find lesson pages"); } - - // get all the users who have taken this lesson, order by their last name - if (!$users = get_records_sql("SELECT DISTINCT u.* + + // get all the users who have taken this lesson, order by their last name + if (!$users = get_records_sql("SELECT DISTINCT u.* FROM {$CFG->prefix}user u, {$CFG->prefix}lesson_attempts a WHERE a.lessonid = '$lesson->id' and u.id = a.userid - ORDER BY u.lastname")) { + ORDER BY u.lastname")) { error("Error: could not find users"); } - - // get only the attempts that are in response to essay questions - $pageids = implode(",", array_keys($pages)); // all the pageids in comma seperated list - if (!$essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($pageids)")) { - error ("No one has answered essay questions yet..."); - } - // group all the essays by userid - $studentessays = array(); - foreach ($essayattempts as $essay) { - // not very nice :) but basically - // this organizes the essays so I know how many times a student answered an essay per try and per page - $studentessays[$essay->userid][$essay->pageid][$essay->retry][] = $essay; + + // get only the attempts that are in response to essay questions + $pageids = implode(",", array_keys($pages)); // all the pageids in comma seperated list + if (!$essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($pageids)")) { + error ("No one has answered essay questions yet..."); + } + // group all the essays by userid + $studentessays = array(); + foreach ($essayattempts as $essay) { + // not very nice :) but basically + // this organizes the essays so I know how many times a student answered an essay per try and per page + $studentessays[$essay->userid][$essay->pageid][$essay->retry][] = $essay; } - print_heading("id\">".get_string("gobacktolesson", "lesson").""); - $table = new stdClass; - $table->head = array($course->students, get_string("essays", "lesson"), get_string("email", "lesson")); + print_heading("id\">".get_string("gobacktolesson", "lesson").""); + $table = new stdClass; + $table->head = array($course->students, get_string("essays", "lesson"), get_string("email", "lesson")); $table->align = array("left", "left", "left"); $table->wrap = array("nowrap", "wrap", "nowrap"); $table->width = "90%"; - $table->size = array("*", "70%", "*"); + $table->size = array("*", "70%", "*"); - // get the student ids of the students who have answered the essay question - $studentids = array_keys($studentessays); - - // cycle through all the ids + // get the student ids of the students who have answered the essay question + $studentids = array_keys($studentessays); + + // cycle through all the ids foreach ($studentids as $id) { $studentname = $users[$id]->lastname.", ".$users[$id]->firstname; - $essaylinks = array(); - // go through each essay + $essaylinks = array(); + // go through each essay foreach ($studentessays[$id] as $page => $tries) { - // go through each essay per page - foreach($tries as $try) { - // make sure they didn't answer it more than the max number of attmepts - if (count($try) > $lesson->maxattempts) { - $essay = $try[$lesson->maxattempts-1]; - } else { - $essay = end($try); - } - $essayinfo = unserialize($essay->useranswer); - // different colors for all the states of an essay (graded, if sent, not graded) - if (!$essayinfo->graded) { - $style = "style='color:#DF041E;text-decoration:underline;'"; - } elseif (!$essayinfo->sent) { - $style = "style='color:#006600;text-decoration:underline;'"; - } else { - $style = "style='color:#999999;'"; - } - // link for each essay - $essaylinks[] = "id&action=essaygrade&attemptid=$essay->id\">".$pages[$essay->pageid]->title.""; - } + // go through each essay per page + foreach($tries as $try) { + // make sure they didn't answer it more than the max number of attmepts + if (count($try) > $lesson->maxattempts) { + $essay = $try[$lesson->maxattempts-1]; + } else { + $essay = end($try); + } + $essayinfo = unserialize($essay->useranswer); + // different colors for all the states of an essay (graded, if sent, not graded) + if (!$essayinfo->graded) { + $style = "style='color:#DF041E;text-decoration:underline;'"; + } elseif (!$essayinfo->sent) { + $style = "style='color:#006600;text-decoration:underline;'"; + } else { + $style = "style='color:#999999;'"; + } + // link for each essay + $essaylinks[] = "id&action=essaygrade&attemptid=$essay->id\">".$pages[$essay->pageid]->title.""; + } } - // email link for this user - $emaillink = "id&action=emailessay&userid=".$id."&sesskey=".$USER->sesskey."\">".get_string("emailgradedessays", "lesson").""; + // email link for this user + $emaillink = "id&action=emailessay&userid=".$id."&sesskey=".$USER->sesskey."\">".get_string("emailgradedessays", "lesson").""; - $table->data[] = array($studentname, implode(", ", $essaylinks), $emaillink); - } - // email link for all users - $emailalllink = "id&action=emailessay&sesskey=".$USER->sesskey."\">".get_string("emailallgradedessays", "lesson").""; + $table->data[] = array($studentname, implode(", ", $essaylinks), $emaillink); + } + // email link for all users + $emailalllink = "id&action=emailessay&sesskey=".$USER->sesskey."\">".get_string("emailallgradedessays", "lesson").""; - $table->data[] = array(" ", " ", $emailalllink); - - print_table($table); + $table->data[] = array(" ", " ", $emailalllink); + + print_table($table); } /*******************grade essays **************************************/ // 6/29/04 elseif ($action == 'essaygrade') { print_heading_with_help($lesson->name, "overview", "lesson"); - - $attemptid = required_param('attemptid', PARAM_INT); + + $attemptid = required_param('attemptid', PARAM_INT); if (!$essay = get_record("lesson_attempts", "id", $attemptid)) { error("Error: could not find attempt"); @@ -1609,48 +1609,48 @@ echo "id\" />\n"; echo "\n"; echo "\n"; - echo "sesskey."\" />\n"; - - // all tables will have these - $table = new stdClass; + echo "sesskey."\" />\n"; + + // all tables will have these + $table = new stdClass; $table->align = array("left"); $table->wrap = array("wrap"); $table->width = "70%"; - $table->size = array("100%"); + $table->size = array("100%"); - - $table->head = array(get_string("question", "lesson")); + + $table->head = array(get_string("question", "lesson")); $table->data[] = array(format_text($page->contents)); - print_table($table); - echo "
    "; + print_table($table); + echo "
    "; - unset($table->data); - $essayinfo = unserialize($essay->useranswer); + unset($table->data); + $essayinfo = unserialize($essay->useranswer); $studentname = $student->firstname." ".$student->lastname; $table->head = array(get_string("studentresponse", "lesson", $studentname)); - $table->data[] = array(format_text($essayinfo->answer)); - - print_table($table); - echo "
    "; - - unset($table->data); + $table->data[] = array(format_text($essayinfo->answer)); + + print_table($table); + echo "
    "; + + unset($table->data); - $table->head = array(get_string("comments", "lesson")); - $table->data[] = array("\n"); + $table->head = array(get_string("comments", "lesson")); + $table->data[] = array("\n"); if ($lesson->custom) { for ($i=$answer->score; $i>=0; $i--) { $options[$i] = $i; } } else { $options[0] = "incorrect"; - $options[1] = "correct"; + $options[1] = "correct"; } - $table->data[] = array(get_string("essayscore", "lesson").": ".lesson_choose_from_menu($options, "score", $essayinfo->score, "", "", "", true)); - - print_table($table); - echo "
    "; + $table->data[] = array(get_string("essayscore", "lesson").": ".lesson_choose_from_menu($options, "score", $essayinfo->score, "", "", "", true)); + + print_table($table); + echo "
    "; echo "
    "; echo ""; @@ -1658,17 +1658,17 @@ echo ""; echo "
    "; - echo ""; - - + echo ""; + + } /*******************update grade**************************************/ // 6/29/04 elseif ($action == 'updategrade') { print_heading_with_help($lesson->name, "overview", "lesson"); - confirm_sesskey(); - + confirm_sesskey(); + $form = lesson_clean_data_submitted(); if (!$essay = get_record("lesson_attempts", "id", $form->attemptid)) { @@ -1679,31 +1679,31 @@ error("Error: could not find grades"); } - $essayinfo = new stdClass; - $essayinfo = unserialize($essay->useranswer); + $essayinfo = new stdClass; + $essayinfo = unserialize($essay->useranswer); - $essayinfo->graded = 1; + $essayinfo->graded = 1; $essayinfo->score = $form->score; $essayinfo->response = stripslashes_safe($form->response); - $essayinfo->sent = 0; - if (!$lesson->custom && $form->score == 1) { - $essay->correct = 1; - } else { - $essay->correct = 0; - } + $essayinfo->sent = 0; + if (!$lesson->custom && $form->score == 1) { + $essay->correct = 1; + } else { + $essay->correct = 0; + } - $essay->useranswer = addslashes(serialize($essayinfo)); + $essay->useranswer = addslashes(serialize($essayinfo)); - if (!update_record("lesson_attempts", $essay)) { - error("Could not update essay score"); - } + if (!update_record("lesson_attempts", $essay)) { + error("Could not update essay score"); + } - $grade = current($grades); + $grade = current($grades); - // I modded this function a bit so it would work here... :) ;) :P - $updategrade->grade = lesson_calculate_ongoing_score($lesson, $essay->userid, $essay->retry, true); - $updategrade->id = $grade->id; - + // I modded this function a bit so it would work here... :) ;) :P + $updategrade->grade = lesson_calculate_ongoing_score($lesson, $essay->userid, $essay->retry, true); + $updategrade->id = $grade->id; + if(update_record("lesson_grades", $updategrade)) { redirect("view.php?id=$cm->id&action=essayview", get_string("updatesuccess", "lesson")); } else { @@ -1717,69 +1717,69 @@ elseif ($action == 'emailessay') { print_heading_with_help($lesson->name, "overview", "lesson"); - confirm_sesskey(); - + confirm_sesskey(); + if (isset($_GET['userid'])) { - $userid = clean_param($_GET['userid'], PARAM_INT); + $userid = clean_param($_GET['userid'], PARAM_INT); $queryadd = " AND userid = ".$userid; - if (! $users = get_records("user", "id", $userid)) { - error("Error: could not find users"); - } + if (! $users = get_records("user", "id", $userid)) { + error("Error: could not find users"); + } } else { $queryadd = ""; - if (!$users = lesson_get_participants($lesson->id)) { - error("Error: could not find users"); - } + if (!$users = lesson_get_participants($lesson->id)) { + error("Error: could not find users"); + } } - - // get lesson pages that are essay + + // get lesson pages that are essay if (!$pages = get_records_select("lesson_pages", "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { error("Error: could not find lesson pages"); } - - // get only the attempts that are in response to essay questions - $pageids = implode(",", array_keys($pages)); // all the pageids in comma seperated list - if (!$essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($pageids)".$queryadd)) { - error ("No one has answered essay questions yet..."); - } - - if (!$essayanswers = get_records_select("lesson_answers", "lessonid = $lesson->id AND pageid IN($pageids)", "", "pageid, score")) { - error ("Could not find answer records."); - } + + // get only the attempts that are in response to essay questions + $pageids = implode(",", array_keys($pages)); // all the pageids in comma seperated list + if (!$essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($pageids)".$queryadd)) { + error ("No one has answered essay questions yet..."); + } + + if (!$essayanswers = get_records_select("lesson_answers", "lessonid = $lesson->id AND pageid IN($pageids)", "", "pageid, score")) { + error ("Could not find answer records."); + } // NoticeFix big fix, change $essay[]'s that use $USER to just $USER foreach ($essayattempts as $essay) { - $essayinfo = unserialize($essay->useranswer); + $essayinfo = unserialize($essay->useranswer); if ($essayinfo->graded && !$essayinfo->sent) { $subject = get_string('essayemailsubject', 'lesson', $pages[$essay->pageid]->title); $message = get_string('question', 'lesson').":
    "; $message .= $pages[$essay->pageid]->contents; - $message .= "

    "; + $message .= "

    "; $message .= get_string('yourresponse', 'lesson').":
    "; $message .= $essayinfo->answer; - $message .= "

    "; - $message .= get_string('commentswithname', 'lesson', $USER).":
    "; + $message .= "

    "; + $message .= get_string('commentswithname', 'lesson', $USER).":
    "; $message .= $essayinfo->response; - $message .= "

    "; - $grades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid = $essay->userid", "completed", "*", $essay->retry, 1); - $grade = current($grades); + $message .= "

    "; + $grades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid = $essay->userid", "completed", "*", $essay->retry, 1); + $grade = current($grades); if ($lesson->custom) { - $points->score = $essayinfo->score; - $points->outof = $essayanswers[$essay->pageid]->score; + $points->score = $essayinfo->score; + $points->outof = $essayanswers[$essay->pageid]->score; $message .= get_string("youhavereceived", "lesson", $points); - } else { - $points->score = $essayinfo->score; - $points->outof = 1; + } else { + $points->score = $essayinfo->score; + $points->outof = 1; $message .= get_string("youhavereceived", "lesson", $points); - } - $message .= "

    "; - $message .= get_string("yourgradeisnow", "lesson", $grade->grade)."%."; - - $plaintxt = format_text_email($message, FORMAT_HTML); + } + $message .= "

    "; + $message .= get_string("yourgradeisnow", "lesson", $grade->grade)."%."; + + $plaintxt = format_text_email($message, FORMAT_HTML); - if(email_to_user($users[$essay->userid], $USER, $subject, $plaintxt, $message)) { - $essayinfo->sent = 1; - $essay->useranswer = addslashes(serialize($essayinfo)); + if(email_to_user($users[$essay->userid], $USER, $subject, $plaintxt, $message)) { + $essayinfo->sent = 1; + $essay->useranswer = addslashes(serialize($essayinfo)); update_record("lesson_attempts", $essay); } else { echo "Email Failed!
    "; @@ -1844,8 +1844,8 @@ /*******************update high scores **************************************/ elseif ($action == 'updatehighscores') { print_heading_with_help($lesson->name, "overview", "lesson"); - - confirm_sesskey(); + + confirm_sesskey(); if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id", "completed")) { error("Error: could not find grades"); @@ -1881,14 +1881,14 @@ } if (!(count($topscores) < $lesson->maxhighscores)) { // if the top scores list is not full then dont need to worry about removing old scores $scores = array_keys($topscores); - $flag = true; + $flag = true; // see if the new score is already listed in the top scores list // if it is listed, then dont need to delete any records foreach ($scores as $score) { if ($score = $newgrade->grade) { $flag = false; } - } + } if ($flag) { // if the score does not exist in the top scores list, then the lowest scores get thrown out. ksort($topscores); // sort so the lowest score is first element $lowscore = current($topscores); @@ -1906,7 +1906,7 @@ } } - $newhighscore = new stdClass; + $newhighscore = new stdClass; $newhighscore->lessonid = $lesson->id; $newhighscore->userid = $USER->id; $newhighscore->gradeid = $newgrade->id; @@ -1925,7 +1925,7 @@ print_heading_with_help($lesson->name, "overview", "lesson"); echo "
    "; if (isset($_POST['name'])) { - $name = trim(clean_param($_POST['name'], PARAM_CLEAN)); + $name = trim(clean_param($_POST['name'], PARAM_CLEAN)); if (lesson_check_nickname($name)) { redirect("view.php?id=$cm->id&action=updatehighscores&name=$name&sesskey=".$USER->sesskey, get_string("nameapproved", "lesson")); } else { @@ -1941,7 +1941,7 @@ echo ""; echo ""; echo "
    "; - } + } /*************** no man's land **************************************/ else { error("Fatal Error: Unknown Action: ".$action."\n");