]> git.mjollnir.org Git - moodle.git/commitdiff
Added a lot of new features to lesson mod. Check them out :)
authormichaelpenne <michaelpenne>
Wed, 15 Sep 2004 20:32:24 +0000 (20:32 +0000)
committermichaelpenne <michaelpenne>
Wed, 15 Sep 2004 20:32:24 +0000 (20:32 +0000)
MarkNielsen

18 files changed:
mod/lesson/backuplib.php
mod/lesson/db/mysql.php
mod/lesson/db/mysql.sql
mod/lesson/db/postgres7.php
mod/lesson/filter.php [new file with mode: 0644]
mod/lesson/format.php
mod/lesson/import.php
mod/lesson/index.php
mod/lesson/lesson.php
mod/lesson/lib.php
mod/lesson/locallib.php [new file with mode: 0644]
mod/lesson/mod.html
mod/lesson/reformat.php [new file with mode: 0644]
mod/lesson/restorelib.php
mod/lesson/styles.php [new file with mode: 0644]
mod/lesson/timer.js [new file with mode: 0644]
mod/lesson/version.php
mod/lesson/view.php

index 888c03865b17181fa963929b509e3283f24013c4..8f9be96a0463640c2fe608b1f638b2674b6908a1 100644 (file)
@@ -1,4 +1,4 @@
-<?php //$Id$
+<?PHP //$Id$
     //This php script contains all the stuff to backup/restore
     //lesson mods
 
index e866eb05e49d61eae787967dd3cbb16826e272c4..40bac55b4b184c502d0543e57e1c70e915b742f7 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?PHP
 
 function lesson_upgrade($oldversion) {
 /// This function does anything necessary to upgrade 
@@ -6,6 +6,115 @@ function lesson_upgrade($oldversion) {
 
     global $CFG;
 
+       // CDC-FLAG
+       if ($oldversion < 2004081700) {
+               execute_sql("CREATE TABLE `mdl_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 < 2004072100) {
+               execute_sql(" create table mdl_lesson_high_scores
+                                       ( id int(10) unsigned not null auto_increment primary key,
+                                         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 mdl_lesson_essay
+                                       ( id int(10) unsigned not null auto_increment primary key,
+                                         lessonid int(10) unsigned not null,
+                                         userid int(10) unsigned not null,
+                                         pageid int(10) unsigned not null,
+                                         answerid int(10) unsigned not null,
+                                         try int(10) unsigned not null,
+                                         answer text not null,
+                                         graded tinyint(3) unsigned not null default 0,
+                                         score int(10) unsigned not null default 0,
+                                         response text not null,
+                                         sent tinyint(3) unsigned not null default 0,
+                                         timesubmitted int(10) unsigned not null,
+                                         PRIMARY KEY  (`id`)
+                                       )");
+
+               execute_sql(" create table mdl_lesson_branch
+                                       ( id int(10) unsigned not null auto_increment primary key,
+                                         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 mdl_lesson_timer
+                                       ( id int(10) unsigned not null auto_increment primary key,
+                                       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_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");
+
+       }
+       // CDC-FLAG end 
+
     if ($oldversion < 2004021600) {
 
        delete_records("log_display", "module", "lesson");
@@ -43,4 +152,4 @@ function lesson_upgrade($oldversion) {
     return true;
 }
 
-?>
+?>
\ No newline at end of file
index 195782e7d6ec8bf9f470ff1a6249e26fbdd99573..69b02164b28fcb2ebd382c831e01fcce5574a6f0 100644 (file)
@@ -8,14 +8,30 @@ CREATE TABLE `prefix_lesson` (
   `id` int(10) unsigned NOT NULL auto_increment,
   `course` int(10) unsigned NOT NULL default '0',
   `name` varchar(255) NOT NULL default '',
+  `practice` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
+  `usepassword` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
+  `password` VARCHAR(32) NOT NULL default '',
   `grade` tinyint(3) NOT NULL default '0',
+  `custom` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
+  `ongoing` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
   `usemaxgrade` tinyint(3) 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` int(3) unsigned NOT NULL default '0',
   `maxpages` int(3) unsigned NOT NULL default '0',
+  `timed` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
+  `maxtime` INT(10) UNSIGNED NOT NULL DEFAULT '0',
   `retake` int(3) unsigned NOT NULL default '1',
+  `tree` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
+  `slideshow` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
+  `width` INT(10) UNSIGNED NOT NULL DEFAULT '640',
+  `height` INT(10) UNSIGNED NOT NULL DEFAULT '480',
+  `bgcolor` CHAR(7) NOT NULL DEFAULT '#FFFFFF',
+  `displayleft` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
+  `highscores` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0',
+  `maxhighscores` INT(10) UNSIGNED NOT NULL DEFAULT '0',
   `available` int(10) unsigned NOT NULL default '0',
   `deadline` int(10) unsigned NOT NULL default '0',
   `timemodified` int(10) unsigned NOT NULL default '0',
@@ -30,6 +46,8 @@ CREATE TABLE `prefix_lesson_pages` (
   `nextpageid` int(10) unsigned NOT NULL default '0',
   `qtype` tinyint(3) unsigned NOT NULL default '0',
   `qoption` tinyint(3) unsigned NOT NULL default '0',
+  `layout` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1',
+  `display` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1',
   `timecreated` int(10) unsigned NOT NULL default '0',
   `timemodified` int(10) unsigned NOT NULL default '0',
   `title` varchar(255) NOT NULL default '',
@@ -44,6 +62,7 @@ CREATE TABLE `prefix_lesson_answers` (
   `pageid` int(10) unsigned NOT NULL default '0',
   `jumpto` int(11) NOT NULL default '0',
   `grade` tinyint(3) unsigned NOT NULL default '0',
+  `score` INT(10) NOT NULL DEFAULT '0',
   `flags` tinyint(3) unsigned NOT NULL default '0',
   `timecreated` int(10) unsigned NOT NULL default '0',
   `timemodified` int(10) unsigned NOT NULL default '0',
@@ -79,6 +98,86 @@ CREATE TABLE `prefix_lesson_grades` (
 ) COMMENT='Defines 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',
+                 `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`)
+       );
+# --------------------------------------------------------
+
+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`)
+       );
+# --------------------------------------------------------
+
+CREATE TABLE `prefix_lesson_essay`
+       ( `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,
+         `answerid` int(10) unsigned not null,
+         `try` int(10) unsigned not null,
+         `answer` text not null,
+         `graded` tinyint(3) unsigned not null default 0,
+         `score` int(10) unsigned not null default 0,
+         `response` text not null,
+         `sent` tinyint(3) unsigned not null default 0,
+         `timesubmitted` 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`)
+       );
+# --------------------------------------------------------
+
 
 INSERT INTO prefix_log_display VALUES ('lesson', 'start', 'lesson', 'name');
 INSERT INTO prefix_log_display VALUES ('lesson', 'end', 'lesson', 'name');
index 7d8e7a21b40f77242e5d94cb1ed1ece1caa88f03..1f52e6fe04d80f78e7e5bafaf42e72845ac328f6 100644 (file)
@@ -1,4 +1,4 @@
-<?php
+<?PHP
 
 function lesson_upgrade($oldversion) {
 /// This function does anything necessary to upgrade 
diff --git a/mod/lesson/filter.php b/mod/lesson/filter.php
new file mode 100644 (file)
index 0000000..c8f2f3e
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+       // bad words < 5 characters long
+       $filterwords = array (
+                                       "shit",
+                                       "fuck",
+                                       "dick",
+                                       "cunt",
+                                       "pussy",
+                                       "hore",
+                                       "whore",
+                                       "damn"
+                                       );
+?>
\ No newline at end of file
index a0662ae1f529825ee326afc7c060bcb47e611a43..34bc2523bf5ab4e7fc1ec5ca8bb245d7578a3764 100644 (file)
@@ -1,4 +1,4 @@
-<?php  // $Id$ 
+<?PHP  // $Id$ 
 
 ////////////////////////////////////////////////////////////////////
 /// format.php  - Default format class for file imports/exports.  //
@@ -50,7 +50,7 @@ class quiz_default_format {
                 case MATCH :
                     $count++;
 
-                    echo "<hr /><p><b>$count</b>. ".stripslashes($question->questiontext)."</p>";
+                    echo "<hr><p><b>$count</b>. ".stripslashes($question->questiontext)."</p>";
                     unset($newpage);
                     $newpage->lessonid = $lesson->id;
                     $newpage->qtype = $question->qtype;
index 9a7c8a974be5c2d8c7fd17fc8b0f6ed1eaebbd90..0752a765820af71f185791520e448f87af002c68 100644 (file)
@@ -1,8 +1,8 @@
-<?php // $Id$
+<?PHP // $Id$
       // Import quiz questions into the given category
 
     require_once("../../config.php");
-    require_once("lib.php");
+       require_once("locallib.php");
 
     optional_variable($format);
     require_variable($id);    // Course Module ID
@@ -29,8 +29,9 @@
     $strimportquestions = get_string("importquestions", "lesson");
     $strlessons = get_string("modulenameplural", "lesson");
 
-    print_header_simple("$strimportquestions", " $strimportquestions",
-                 "<a href=\"index.php?id=$course->id\">$strlessons</a> -> <a href=\"view.php?id=$cm->id\">$lesson->name</a>-> $strimportquestions");
+    print_header("$course->shortname: $strimportquestions", "$course->shortname: $strimportquestions",
+                 "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> -> ". 
+                 "<A HREF=index.php?id=$course->id>$strlessons</A> -> <a href=\"view.php?id=$cm->id\">$lesson->name</a>-> $strimportquestions");
 
     if ($form = data_submitted()) {   /// Filename
 
             require("../quiz/format/$form->format/format.php");
 
             $format = new quiz_file_format();
-
+                       
+                       
+                       // jjg7:8/9/2004 remove double '\n' from a file if the format is aiken and reformat Brusca's to Aiken
+                       if ($form->format == 'aiken')
+                       {
+                               require("reformat.php"); // include functions to reformat styles
+                               if (removedoublecr($newfile['tmp_name']) === FALSE) {
+                                       error("Error occurred while replacing double carriage returns");
+                               }
+                               if (importmodifiedaikenstyle($newfile['tmp_name']) === FALSE) {
+                                       error("Error occurred while converting to Aiken");
+                               }
+                       }
+                       
             if (! $format->importpreprocess()) {             // Do anything before that we need to
                 error("Error occurred during pre-processing!");
             }
@@ -72,7 +86,7 @@
                 error("Error occurred during post-processing!");
             }
 
-            echo "<hr />";
+            echo "<hr>";
             print_continue("view.php?id=$cm->id");
             print_footer($course);
             exit;
     print_heading_with_help($strimportquestions, "import", "lesson");
 
     print_simple_box_start("center", "", "$THEME->cellheading");
-    echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"import.php\">";
-    echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
-    echo "<input type=\"hidden\" name=\"pageid\" value=\"".$_GET['pageid']."\" />\n";
-    echo "<table cellpadding=\"5\">";
+    echo "<form enctype=\"multipart/form-data\" method=\"post\" action=import.php>";
+    echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">\n";
+    echo "<input type=\"hidden\" name=\"pageid\" value=\"".$_GET['pageid']."\">\n";
+    echo "<table cellpadding=5>";
 
-    echo "<tr><td align=\"right\">";
+    echo "<tr><td align=right>";
     print_string("fileformat", "lesson");
     echo ":</td><td>";
     choose_from_menu($fileformatnames, "format", "gift", "");
     echo "</tr>";
 
-    echo "<tr><td align=\"right\">";
+    echo "<tr><td align=right>";
     print_string("upload");
     echo ":</td><td>";
-    echo " <input name=\"newfile\" type=\"file\" size=\"50\" />";
+    echo " <input name=\"newfile\" type=\"file\" size=\"50\">";
     echo "</tr><tr><td>&nbsp;</td><td>";
-    echo " <input type=\"submit\" name=\"save\" value=\"".get_string("uploadthisfile")."\" />";
+    echo " <input type=submit name=save value=\"".get_string("uploadthisfile")."\">";
     echo "</td></tr>";
 
     echo "</table>";
index 5e8ef38fb236d3733fd4f2f8e73d9d351ec97af4..2838cfc68d3e0735448c0f9842115e63859954f0 100644 (file)
@@ -1,9 +1,9 @@
-<?php // $Id$
+<?PHP // $Id$
 
 /// This page lists all the instances of lesson in a particular course
 
     require_once("../../config.php");
-    require_once("lib.php");
+       require_once("locallib.php");
 
     require_variable($id);   // course
 
@@ -11,7 +11,7 @@
         error("Course ID is incorrect");
     }
 
-    require_course_login($course);
+    require_login($course->id);
 
     add_to_log($course->id, "lesson", "view all", "index.php?id=$course->id", "");
 
 
 /// Print the header
 
-    print_header_simple("$strlessons", "", "$strlessons", "", "", true, "", navmenu($course));
+    if ($course->category) {
+        $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
+    }
+
+    print_header("$course->shortname: $strlessons", "$course->fullname", "$navigation $strlessons", "", "", true, "", navmenu($course));
 
 /// Get all the appropriate data
 
     foreach ($lessons as $lesson) {
         if (!$lesson->visible) {
             //Show dimmed if the mod is hidden
-            $link = "<a class=\"dimmed\" href=\"view.php?id=$lesson->coursemodule\">$lesson->name</a>";
+            $link = "<A class=\"dimmed\" HREF=\"view.php?id=$lesson->coursemodule\">$lesson->name</A>";
         } else {
             //Show normal if the mod is visible
-            $link = "<a href=\"view.php?id=$lesson->coursemodule\">$lesson->name</a>";
+            $link = "<A HREF=\"view.php?id=$lesson->coursemodule\">$lesson->name</A>";
         }
 
         if ($lesson->deadline > $timenow) {
             $due = userdate($lesson->deadline);
         } else {
-            $due = "<font color=\"red\">".userdate($lesson->deadline)."</font>";
+            $due = "<FONT COLOR=\"red\">".userdate($lesson->deadline)."</FONT>";
         }
 
-        $grade_value = '';
         if ($course->format == "weeks" or $course->format == "topics") {
             if (isteacher($course->id)) {
                 $grade_value = $lesson->grade;
-            } elseif (isstudent($course->id)) {
+            } else {
                 // it's a student, show their mean or maximum grade
                 if ($lesson->usemaxgrade) {
                     $grade = get_record_sql("SELECT MAX(grade) as grade FROM {$CFG->prefix}lesson_grades 
@@ -84,6 +87,8 @@
                 if ($grade) {
                     // grades are stored as percentages
                     $grade_value = number_format($grade->grade * $lesson->grade / 100, 1);
+                } else {
+                    $grade_value = 0;
                 }
             }
             $table->data[] = array ($lesson->section, $link, $grade_value, $due);
@@ -92,7 +97,7 @@
         }
     }
 
-    echo "<br />";
+    echo "<BR>";
 
     print_table($table);
 
index 4ef5ad491312bec2cfb05129a8295c3eb465fa18..a8cc503d6f1c2414acc16f6c28f7a3df4744bd3e 100644 (file)
@@ -1,10 +1,12 @@
-<?php  // $Id: lesson.php, v 1.0 25 Jan 2004
+<?PHP  // $Id: lesson.php, v 1.0 25 Jan 2004
 
 /*************************************************
        ACTIONS handled are:
 
        addbranchtable
     addendofbranch
+       addcluster      /// CDC-FLAG /// added two new items
+       addendofcluster
     addpage
     confirmdelete
     continue
 ************************************************/
 
     require("../../config.php");
-       require("lib.php");
+       require("locallib.php");
+       require_once("styles.php");
 
+       
        require_variable($id);    // Course Module ID
  
     // get some esential stuff...
@@ -42,7 +46,7 @@
     
     $navigation = "";
     if ($course->category) {
-        $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
+        $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->";
     }
 
     $strlessons = get_string("modulenameplural", "lesson");
        
        // ... print the header and...
     print_header("$course->shortname: $lesson->name", "$course->fullname",
-                 "$navigation <a href=\"index.php?id=$course->id\">$strlessons</a> -> 
-                  <a href=\"view.php?id=$cm->id\">$lesson->name</a>", 
+                 "$navigation <A HREF=index.php?id=$course->id>$strlessons</A> -> 
+                  <A HREF=\"view.php?id=$cm->id\">$lesson->name</A>", 
                   "", "", true);
 
        //...get the action 
        require_variable($action);
        
-
        /************** add branch table ************************************/
        if ($action == 'addbranchtable' ) {
 
         // set of jump array
         $jump[0] = get_string("thispage", "lesson");
         $jump[LESSON_NEXTPAGE] = get_string("nextpage", "lesson");
-        $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 /////
+               $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");
         ?>
         <form name="form" method="post" action="lesson.php">
-        <input type="hidden" name="id" value="<?php echo $cm->id ?>" />
-        <input type="hidden" name="action" value="insertpage" />
-        <input type="hidden" name="pageid" value="<?php echo $_GET['pageid'] ?>" />
-        <input type="hidden" name="qtype" value="<?php echo LESSON_BRANCHTABLE ?>" />
-        <center><table cellpadding="5" border="1">
+        <input type="hidden" name="id" value="<?PHP echo $cm->id ?>">
+        <input type="hidden" name="action" value="insertpage">
+        <input type="hidden" name="pageid" value="<?PHP echo $_GET['pageid'] ?>">
+        <input type="hidden" name="qtype" value="<?PHP echo LESSON_BRANCHTABLE ?>">
+        <center><table cellpadding=5 border=1>
         <tr><td align="center">
         <tr valign="top">
         <td><b><?php print_string("pagetitle", "lesson"); ?>:</b><br />
-        <input type="text" name="title" size="80" maxsize="255" value="" /></td></tr>
-        <?php
+        <!-- //CDC hidden-label added.--><label for="title" class="hidden-label">Title</label><input type="text" id="title" name="title" size="80" maxsize="255" value=""></td></tr>
+        <?PHP
         echo "<tr><td><b>";
         echo get_string("pagecontents", "lesson").":</b><br />\n";
         print_textarea($usehtmleditor, 25,70, 630, 400, "contents");
-        echo "</td></tr>\n";
+        use_html_editor("contents");
+               echo "</td></tr>\n";
+               /// CDC-FLAG /// 6/16/04
+               echo "<tr><td>\n";
+               echo "<center><input name=\"layout\" type=\"checkbox\" value=\"1\" CHECKED>";
+               echo get_string("arrangebuttonshorizontally", "lesson")."\n";
+               echo "<br><input name=\"display\" type=\"checkbox\" value=\"1\" CHECKED>";
+               echo get_string("displayinleftmenu", "lesson");
+               echo "</center>\n";
+               echo "</td></tr>\n";
+               /// CDC-FLAG ///                                
         for ($i = 0; $i < $lesson->maxanswers; $i++) {
             $iplus1 = $i + 1;
             echo "<tr><td><b>".get_string("description", "lesson")." $iplus1:</b><br />\n";
-            print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$i]");
-            echo "</td></tr>\n";
-            echo "<tr><td><b>".get_string("jump", "lesson")." $iplus1:</b> \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 "</td></tr>\n";
+            echo "<tr><td><B>".get_string("jump", "lesson")." $iplus1:</b> \n";
             if ($i) {
                 // answers 2, 3, 4... jumpto this page
                 lesson_choose_from_menu($jump, "jumpto[$i]", 0, "");
             helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
             echo "</td></tr>\n";
         }
-        use_html_editor();
         // close table and form
         ?>
         </table><br />
-        <input type="submit" value="<?php  print_string("addabranchtable", "lesson") ?>" />
-        <input type="submit" name="cancel" value="<?php  print_string("cancel") ?>" />
+        <input type="submit" value="<?php  print_string("addabranchtable", "lesson") ?>">
+        <input type="submit" name="cancel" value="<?php  print_string("cancel") ?>">
         </center>
         </form>
-        <?php
+        <?PHP
        }
        
 
             notice(get_string("nobranchtablefound", "lesson"), "view.php?id=$cm->id");
         }
        }
-       
 
+/// CDC-FLAG 6/17/04 ///       
+       /************** add cluster ************************************/
+    elseif ($action == 'addcluster' ) {
+
+               if (!isteacher($course->id)) {
+               error("Only teachers can look at this page");
+           }
+
+        // first get the preceeding page
+               // if $pageid = 0, then we are inserting a new page at the beginning of the lesson
+        $pageid = $_GET['pageid'];
+            
+        $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");
+               }
+               }
+        
+               $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->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("ok"));
+       }
+/// CDC-FLAG ///       
+
+/// CDC-FLAG 6/17/04 ///       
+       /************** add end of cluster ************************************/
+    elseif ($action == 'addendofcluster' ) {
+
+               if (!isteacher($course->id)) {
+               error("Only teachers can look at this page");
+           }
+
+        // first get the preceeding page
+        $pageid = $_GET['pageid'];
+            
+        $timenow = time();
+        
+        // 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");
+        }
+               
+               // could put code in here to check if the user really can insert an end of cluster
+               
+               $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->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("ok"));
+       }
+/// CDC-FLAG ///
+       
        /************** add page ************************************/
     elseif ($action == 'addpage' ) {
 
         // set of jump array
         $jump[0] = get_string("thispage", "lesson");
         $jump[LESSON_NEXTPAGE] = get_string("nextpage", "lesson");
-        $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 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");
         ?>
         <form name="form" method="post" action="lesson.php">
-        <input type="hidden" name="id" value="<?php echo $cm->id ?>" />
-        <input type="hidden" name="action" value="insertpage" />
-        <input type="hidden" name="pageid" value="<?php echo $_GET['pageid'] ?>" />
-        <center><table cellpadding="5" border="1">
+        <input type="hidden" name="id" value="<?PHP echo $cm->id ?>">
+        <input type="hidden" name="action" value="insertpage">
+        <input type="hidden" name="pageid" value="<?PHP echo $_GET['pageid'] ?>">
+               <center><table cellpadding=5 border=1>
+               <?php
+                   echo "<tr><td align=\"center\"><b>";
+                       echo get_string("questiontype", "lesson").":</b> \n";
+                       echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."<br>";
+                       if (isset($_GET['qtype'])) {
+                               lesson_qtype_menu($LESSON_QUESTION_TYPE, $_GET['qtype'], 
+                                                                 "lesson.php?id=$cm->id&action=addpage&pageid=".$_GET['pageid'].$linkadd);
+                               // NoticeFix rearraged
+                               if ( $_GET['qtype'] == LESSON_SHORTANSWER || $_GET['qtype'] == LESSON_MULTICHOICE || !isset($_GET['qtype']) ) {  // only display this option for Multichoice and shortanswer
+                                       if ($_GET['qtype'] == LESSON_SHORTANSWER) {
+                                               echo "<br><br><b>".get_string("casesensitive", "lesson").":</b> \n";
+                                       } else {
+                                               echo "<br><br><b>".get_string("multianswer", "lesson").":</b> \n";
+                                       }
+                                       echo " <label for=\"qoption\" class=\"hidden-label\">Question Option</label><input type=\"checkbox\" id=\"qoption\" name=\"qoption\" value=\"1\"/>"; //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=".$_GET['pageid'].$linkadd);
+                       }
+                       echo "</td></tr>\n";
+               ?>
         <tr><td align="center">
         <tr valign="top">
         <td><b><?php print_string("pagetitle", "lesson"); ?>:</b><br />
-        <input type="text" name="title" size="80" maxsize="255" value="" /></td></tr>
-        <?php
+        <!-- //CDC hidden-label added.--><label for="title" class="hidden-label">Title</label><input type="text" id="title" name="title" size="80" maxsize="255" value=""></td></tr>
+        <?PHP
         echo "<tr><td><b>";
         echo get_string("pagecontents", "lesson").":</b><br />\n";
         print_textarea($usehtmleditor, 25,70, 630, 400, "contents");
         use_html_editor("contents");
         echo "</td></tr>\n";
-        echo "<tr><td><b>".get_string("questiontype", "lesson").":</b> \n";
-        choose_from_menu($LESSON_QUESTION_TYPE, "qtype", LESSON_MULTICHOICE, "");
-        helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson");
-        echo "<br /><b>".get_string("questionoption", "lesson").":</b>\n";
-        echo " <input type=\"checkbox\" name=\"qoption\" value=\"1\"/ />";
-        helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson");
-        echo "</td></tr>\n";
-        for ($i = 0; $i < $lesson->maxanswers; $i++) {
-            $iplus1 = $i + 1;
-            echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b><br />\n";
-            print_textarea(false, 6, 70, 630, 300, "answer[$i]");
-            echo "</td></tr>\n";
-            echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b><br />\n";
-            print_textarea(false, 6, 70, 630, 300, "response[$i]");
-            echo "</td></tr>\n";
-            echo "<tr><td><b>".get_string("jump", "lesson")." $iplus1:</b> \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");
-            echo "</td></tr>\n";
-        }
+               if (isset($_GET['qtype'])) {
+                       switch ($_GET['qtype']) {
+                               case LESSON_TRUEFALSE :
+                                       for ($i = 0; $i < 2; $i++) {
+                                               $iplus1 = $i + 1;
+                                               echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b><br />\n";
+                                               print_textarea(false, 6, 70, 630, 300, "answer[$i]");
+                                               echo "</td></tr>\n";
+                                               echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b><br />\n";
+                                               print_textarea(false, 6, 70, 630, 300, "response[$i]");
+                                               echo "</td></tr>\n";
+                                               echo "<tr><td><B>".get_string("jump", "lesson")." $iplus1:</b> \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: <input type=\"text\" name=\"score[$i]\" value=\"-1\" size=\"5\">";
+                                                       } else {
+                                                               echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\">";
+                                                       }
+                                               }
+                                               /// CDC-FLAG ///
+                                               echo "</td></tr>\n";
+                                       }
+                                       break;
+                               case LESSON_ESSAY :
+                                               echo "<tr><td><B>".get_string("jump", "lesson").":</b> \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").": <input type=\"text\" name=\"score[0]\" value=\"1\" size=\"5\">";
+                                               }
+                                               echo "</td></tr>\n";
+                                       break;
+                               case LESSON_MATCHING :
+                                       for ($i = 0; $i < $lesson->maxanswers+2; $i++) {
+                                               $icorrected = $i - 1;
+                                               if ($i == 0) {
+                                                       echo "<tr><td><b>".get_string("correctresponse", "lesson").":</b><br />\n";
+                                                       print_textarea(false, 6, 70, 630, 300, "answer[$i]");
+                                                       echo "</td></tr>\n";
+                                               } elseif ($i == 1) {
+                                                       echo "<tr><td><b>".get_string("wrongresponse", "lesson").":</b><br />\n";
+                                                       print_textarea(false, 6, 70, 630, 300, "answer[$i]");
+                                                       echo "</td></tr>\n";
+                                               } else {                                                                                                
+                                                       echo "<tr><td><b>".get_string("answer", "lesson")." $icorrected:</b><br />\n";
+                                                       print_textarea(false, 6, 70, 630, 300, "answer[$i]");
+                                                       echo "</td></tr>\n";
+                                                       echo "<tr><td><b>".get_string("matchesanswer", "lesson")." $icorrected:</b><br />\n";
+                                                       print_textarea(false, 6, 70, 630, 300, "response[$i]");
+                                                       echo "</td></tr>\n";
+                                               }
+                                               if ($i == 2) {
+                                                       echo "<tr><td><B>".get_string("correctanswerjump", "lesson").":</b> \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").": <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\">";
+                                                       }
+                                                       echo "</td></tr>\n";
+                                               } elseif ($i == 3) {
+                                                       echo "<tr><td><B>".get_string("wronganswerjump", "lesson").":</b> \n";
+                                                       lesson_choose_from_menu($jump, "jumpto[$i]", 0, "");
+                                                       helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
+                                                       if($lesson->custom) {
+                                                               echo get_string("wronganswerscore", "lesson").": <input type=\"text\" name=\"score[$i]\" value=\"-1\" size=\"5\">";
+                                                       }
+                                                       echo "</td></tr>\n";
+                                               }
+                                       }
+                                       break;
+                               case LESSON_SHORTANSWER :
+                               case LESSON_NUMERICAL :
+                               case LESSON_MULTICHOICE :
+                                       // default code
+                                       for ($i = 0; $i < $lesson->maxanswers; $i++) {
+                                               $iplus1 = $i + 1;
+                                               echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b><br />\n";
+                                               print_textarea(false, 6, 70, 630, 300, "answer[$i]");
+                                               echo "</td></tr>\n";
+                                               echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b><br />\n";
+                                               print_textarea(false, 6, 70, 630, 300, "response[$i]");
+                                               echo "</td></tr>\n";
+                                               echo "<tr><td><B>".get_string("jump", "lesson")." $iplus1:</b> \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: <input type=\"text\" name=\"score[$i]\" value=\"-1\" size=\"5\">";
+                                                       } else {
+                                                               echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\">";
+                                                       }
+                                               }
+                                               /// CDC-FLAG ///
+                                               echo "</td></tr>\n";
+                                       }
+                                       break;
+                       }
+               } else {
+                       for ($i = 0; $i < $lesson->maxanswers; $i++) {
+                               $iplus1 = $i + 1;
+                               echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b><br />\n";
+                               print_textarea(false, 6, 70, 630, 300, "answer[$i]");
+                               echo "</td></tr>\n";
+                               echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b><br />\n";
+                               print_textarea(false, 6, 70, 630, 300, "response[$i]");
+                               echo "</td></tr>\n";
+                               echo "<tr><td><B>".get_string("jump", "lesson")." $iplus1:</b> \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: <input type=\"text\" name=\"score[$i]\" value=\"-1\" size=\"5\">";
+                                       } else {
+                                               echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\">";
+                                       }
+                               }
+                               /// CDC-FLAG ///
+                               echo "</td></tr>\n";
+                       }
+               }
         // close table and form
         ?>
         </table><br />
-        <input type="submit" value="<?php  print_string("addaquestionpage", "lesson") ?>" />
-        <input type="submit" name="cancel" value="<?php  print_string("cancel") ?>" />
+        <input type="submit" value="<?php  print_string("addaquestionpage", "lesson") ?>">
+        <input type="submit" name="cancel" value="<?php  print_string("cancel") ?>">
         </center>
         </form>
-        <?php
+        <?PHP 
                }
        
 
             }
         }
                notice_yesno(get_string("confirmdeletionofthispage","lesson"), 
-                        "lesson.php?action=delete&id=$cm->id&pageid=$pageid", 
+                        "lesson.php?action=delete&id=$cm->id&pageid=$pageid]", 
              "view.php?id=$cm->id");
                }
        
 
        /****************** continue ************************************/
        elseif ($action == 'continue' ) {
-        // record answer (if necessary) and show response (if none say if answer is correct or not)
+               //CDC Chris Berri added this echo call for left menu.  must match that in view.php for styles
+               if ($lesson->displayleft) {
+                       echo '<div class="leftmenu1">'; 
+                                       if ($page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) {
+                                               // print the pages
+                                               echo "<form name=\"lessonpages2\" method=\"post\" action=\"view.php\">\n";
+                                               echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">\n";
+                                               echo "<input type=\"hidden\" name=\"action\" value=\"navigation\">\n";
+                                               echo "<input type=\"hidden\" name=\"pageid\">\n";
+                                                               echo "<div class='lmlinks'><table bgcolor=\"$THEME->cellheading\"><tr></tr>";
+                                                               echo "<tr><td class='lmheading'>".get_string("lessonmenu", "lesson")."</td></tr><br>";
+                                                               echo "<tr><td class='lmMainlinks'>";
+                                                               echo "<a href=\"../../course/view.php?id=$course->id\">".get_string("mainmenu", "lesson")."</a></td></tr>";
+                                                               echo "<td>"; 
+                                                               lesson_print_tree_menu($lesson->id, $page->id, $cm->id);
+                                                               echo "</td></tr></table></div>"; 
+                                               echo "</form>";
+                                       }
+                       echo   "</div>"; //close leftmenu1              
+                       echo "<div class='slidepos'>"; //CDC slidepos 
+               } elseif ($lesson->slideshow) {
+                       echo "<table align=\"center\"><tr><td>";
+               }
+               /// CDC-FLAG /// Slideshow styles
+               if($lesson->slideshow) {
+                       echo "<div style=\"
+                                       background-color: $lesson->bgcolor;
+                                       height: ".$lesson->height."px;
+                                       width: ".$lesson->width."px;
+                                       overflow: auto;
+                                       border: 0px solid #ccc;
+                                       padding: 8px;
+                                       \">\n";
+               }
+               /// CDC-FLAG ///        
+               
+               /// 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 "<div align=\"center\">".get_string("teacherjumpwarning", "lesson", $warningvars)."<div><br>";
+                       }
+               }               
+               /// CDC-FLAG ///
 
+               /// CDC-FLAG /// 6/14/04 -- This is the code updates the lesson time for a timed test
+               $outoftime = false;
+               if($lesson->timed) {
+                       if(isteacher($course->id)) {
+                               echo "<div align=\"center\">".get_string("teachertimerwarning", "lesson")."</div>";
+                       } else {
+                               if (!$timer = get_record("lesson_timer", "lessonid", $lesson->id, "userid", $USER->id)) {
+                                       error("Error: could not find record");
+                               }
+                               if ((($timer->starttime + $lesson->maxtime * 60) - time()) > 0) {
+                                       // code for the clock
+                                       echo "<table align=\"right\"><tr><td>";
+                                       echo "<script language=\"javascript\">\n";
+                                               echo "var starttime = ". $timer->starttime . ";\n";
+                                               echo "var servertime = ". time() . ";\n";
+                                               echo "var testlength = ". $lesson->maxtime * 60 .";\n";
+                                               echo "document.write('<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"timer.js\"><\/SCRIPT>');\n";
+                                               echo "window.onload = function () { show_clock(); }";
+                                       echo "</script>\n";
+                                       echo "</td></tr></table><br><br>";
+                               } 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 "<div align=\"center\">".get_string("studentoneminwarning", "lesson")."<div>";
+                               } elseif (($timer->starttime + $lesson->maxtime * 60) < time()) {
+                                       echo "<div align=\"center\">".get_string("studentoutoftime", "lesson")."</div>";
+                                       $outoftime = true;
+                               }
+                               unset($newtime);
+                               $newtime->id = $timer->id;
+                               $newtime->lessontime = time();
+                               
+                               if (!update_record("lesson_timer", $newtime)) {
+                                       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");
                }
         $correctanswer = false;
         $newpageid = 0; // stay on the page
         switch ($page->qtype) {
-            case LESSON_SHORTANSWER :
+                       /// CDC-FLAG ///
+                        case LESSON_ESSAY :
+                if (!$useranswer = $_POST['answer']) {
+                    $noanswer = true;
+                    break;
+                }
+                   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 //
+                   $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); 
+
+                               $newessay->lessonid = $lesson->id;
+                               $newessay->pageid = $pageid;
+                               $newessay->answerid = $answerid;
+                               $newessay->try = $nretakes;
+                               $newessay->userid = $USER->id;
+                               $newessay->answer = $useranswer;
+                               $newessay->timesubmitted = time();
+                               if (!isteacher($course->id)) {
+                                       if (!insert_record("lesson_essay", $newessay)) {
+                                               error("Error: could not submit essay");
+                                       }
+                               }
+                               break;
+                       /// CDC-FLAG ///
+                    case LESSON_SHORTANSWER :
                 if (!$useranswer = $_POST['answer']) {
                     $noanswer = true;
                     break;
                     error("Continue: No answers found");
                 }
                 foreach ($answers as $answer) {
-                    // massage the wild cards (if present)
-                    if (strpos(' '.$answer->answer, '*')) {
-                        $answer->answer = str_replace('\*','@@@@@@', $answer->answer);
-                        $answer->answer = str_replace('*','.*', $answer->answer);
-                        $answer->answer = str_replace('@@@@@@', '\*', $answer->answer);
-                        $answer->answer = str_replace('+', '\+', $answer->answer);
-                    }
-                    if (lesson_iscorrect($pageid, $answer->jumpto)) {
+                                       /// CDC-FLAG ///
+                                       if ($lesson->custom) {
+                                               if($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)) {  /// CDC-FLAG 6/21/04 ///
                         if ($page->qoption) {
                             // case sensitive
-                            if (ereg('^'.$answer->answer.'$', $useranswer)) {
+                            if ($answer->answer == $useranswer) {
                                 $correctanswer = true;
                                 $newpageid = $answer->jumpto;
                                 if (trim(strip_tags($answer->response))) {
                                     $response = $answer->response;
                                 }
-                                break;
                             }
                         } else {
                             // case insensitive
-                            if (eregi('^'.$answer->answer.'$', $useranswer)) {
+                            if (strcasecmp($answer->answer, $useranswer) == 0) {
                                 $correctanswer = true;
                                 $newpageid = $answer->jumpto;
                                 if (trim(strip_tags($answer->response))) {
                                     $response = $answer->response;
                                 }
-                                break;
                             }
                         }
                     } else {
                         // see if user typed in any of the wrong answers
                         // don't worry about case
-                        if (eregi('^'.$answer->answer.'$', $useranswer)) {
+                        if (strcasecmp($answer->answer, $useranswer) == 0) {
                             $newpageid = $answer->jumpto;
+                                                       $answerid = $answer->id;
                             if (trim(strip_tags($answer->response))) {
                                 $response = $answer->response;
                             }
-                            break;
                         }
                     }
                 }
                 } 
                 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 ///
                 $newpageid = $answer->jumpto;
                 if (!$response = trim($answer->response)) {
                     if ($correctanswer) {
                     $nhits = 0;
                     $correctresponse = '';
                     $wrongresponse = '';
-                    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 /// 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) {
                     $answerid = $_POST['answerid']; 
                     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 ///
                     $newpageid = $answer->jumpto;
                     if (!$response = trim($answer->response)) {
                         if ($correctanswer) {
                 }
                 break;
                 
+            /// CDC-FLAG /// 6/14/04  -- added responses    
             case LESSON_MATCHING :
                 if (isset($_POST['response'])) {
                     $response = $_POST['response'];
                     if ($answer->response == $response[$answer->id]) {
                         $ncorrect++;
                     }
-                    if ($i == 0) {
+                    if ($i == 2) {
                         $correctpageid = $answer->jumpto;
+                                               $correctanswerid = $answer->id;
                     }
-                    if ($i == 1) {
+                    if ($i == 3) {
                         $wrongpageid = $answer->jumpto;
+                                               $wronganswerid = $answer->id;                                           
                     }
                     $i++;
                 }
                 if ($ncorrect == count($answers)) {
-                    $response = get_string("thatsthecorrectanswer", "lesson");
-                    $newpageid = $correctpageid;
+                       $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($correctasnwerid)) {
+                                               $answerid = $correctanswerid;
+                                       }
                     $correctanswer = true;
                 } else {
-                    $response = get_string("numberofcorrectmatches", "lesson", $ncorrect);
+                       $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;
                 }
                 break;
+                               /// CDC-FLAG ///
 
             case LESSON_NUMERICAL :
                 // set defaults
                         if (lesson_iscorrect($pageid, $newpageid)) {
                             $correctanswer = true;
                         }
+                                               /// CDC-FLAG ///
+                                               if ($lesson->custom) {
+                                                       if ($answer->score > 0) {
+                                                               $correctanswer = true;
+                                                               $answerid = $answer->id;
+                                                       }
+                                               }
+                                               /// CDC-FLAG ///
                         break;
                     }
                 }
             case LESSON_BRANCHTABLE:
                 $noanswer = false;
                 $newpageid = $_POST['jumpto'];
+                               /// 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;
+                               }
+                               unset($branch);
+                               $branch->lessonid = $lesson->id;
+                               $branch->userid = $USER->id;
+                               $branch->pageid = $_POST['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, $_POST['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;
                         // no nextpage go to end of lesson
                         $newpageid = LESSON_EOL;
                     }
-                }
-                // no need to record anything in lesson_attempts 
+/* CDC-FLAG */  } elseif ($newpageid == LESSON_PREVIOUSPAGE) {
+                                       $newpageid = $page->prevpageid;
+                               } elseif ($newpageid == LESSON_RANDOMPAGE) {
+                                       $newpageid = lesson_random_question_jump($lesson->id, $_POST['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);
                 exit();
                 $attempt->retry = $nretakes;
                 $attempt->correct = $correctanswer;
                 $attempt->timeseen = time();
-                if (!$newattemptid = insert_record("lesson_attempts", $attempt)) {
-                    error("Continue: attempt not inserted");
-                }
+                               /// CDC-FLAG /// -- dont want to insert the attempt if they ran out of time
+                               if (!$outoftime) {
+                                       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
                 }
             }
             
+                       /// CDC-FLAG 6/21/04 ///  this calculates the ongoing score
+                       if ($lesson->ongoing) {
+                               if (isteacher($course->id)) {
+                                       echo "<div align=\"center\">".get_string("teacherongoingwarning", "lesson")."</div><br>";
+                               } else {
+                                       lesson_calculate_ongoing_score($lesson, $USER);
+                               }
+                       }
+                       /// CDC-FLAG ///
+               
             // display response (if there is one - there should be!)
             if ($response) {
-                $title = get_field("lesson_pages", "title", "id", $pageid);
-                print_heading($title);
+                //$title = get_field("lesson_pages", "title", "id", $pageid);
+                //print_heading($title);
                 echo "<table width=\"80%\" border=\"0\" align=\"center\"><tr><td>\n";
-                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 "<br><br>";
+                                       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 "</td></tr></table>\n";
-            }
+                       }
         }
+
+               
+               /// CDC-FLAG 6/18/04 ///  - this is where some jump numbers are interpreted
+               if ($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;
+                               $pageid = $page->id;
+                       }
+               }
+               if($outoftime) {
+                       $newpageid = LESSON_EOL;  // ran out of time for the test, so go to eol
+               } 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 ///                
         echo "<form name=\"pageform\" method =\"post\" action=\"view.php\">\n";
-        echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
-        echo "<input type=\"hidden\" name=\"action\" value=\"navigation\" />\n";
-        echo "<input type=\"hidden\" name=\"pageid\" value=\"$newpageid\" />\n";
-        echo "<p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
-            get_string("continue", "lesson")."\" /></p>\n";
-        echo "</form>\n";
+        echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">\n";
+        echo "<input type=\"hidden\" name=\"action\" value=\"navigation\">\n";
+        echo "<input type=\"hidden\" name=\"pageid\" value=\"$newpageid\">\n";
+               /// CDC-FLAG ///
+               if ($lesson->slideshow) {
+                       echo "</div>"; //Close Mark's big div tag???
+                       
+                       echo "<table width=\"$lesson->width\" cellpadding=\"5\" cellspacing=\"5\"><tr><td>\n";
+                       if ($lesson->review && !$correctanswer && !$noanswer) {
+                               echo "<p class=\"lessonAbutton\" align=\"center\"><input type=\"submit\" onClick='pageform.pageid.value=$pageid;' name=\"review\" value=\"".
+                                       get_string("reviewquestionback", "lesson")."\"></p>\n";
+                               echo "<p class=\"lessonAbutton\" align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                                       get_string("reviewquestioncontinue", "lesson")."\"></p>\n";
+                       } else {
+                               echo "<p class=\"lessonAbutton\" align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                                       get_string("continue", "lesson")."\"></p>\n";
+                       }
+                       echo "</td></tr></table>";
+
+               } else {
+                       if ($lesson->review && !$correctanswer && !$noanswer) {
+                               echo "<p class=\"lessonAbutton\" align=\"center\"><input type=\"submit\" onClick='pageform.pageid.value=$pageid;' name=\"review\" value=\"".
+                                       get_string("reviewquestionback", "lesson")."\"></p>\n";
+                               echo "<p class=\"lessonAbutton\" align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                                       get_string("reviewquestioncontinue", "lesson")."\"></p>\n";
+                       } else {
+                               echo "<p class=\"lessonAbutton\" align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                                       get_string("continue", "lesson")."\"></p>\n";
+                       }
+               }
+               echo "</form>\n";
+               
+               if ($lesson->displayleft) {
+                       echo "</div><!-- close slidepos class -->"; //CDC Chris Berri for styles, closes slidepos.
+               } elseif ($lesson->slideshow) {
+                       echo "</td></tr></table>";
+               }
        }
        
 
         if (!$page = get_record("lesson_pages", "id", $_GET['pageid'])) {
             error("Edit page: page record not found");
         }
+               
+               if (isset($_GET['qtype'])) {
+                       $page->qtype = $_GET['qtype'];
+               }
+               
         // set of 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 /////         
         $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");
                 if (!$apage = get_record("lesson_pages", "id", $apageid)) {
                     error("Edit page: apage record not found");
                 }
-                if ($apage->qtype != LESSON_ENDOFBRANCH) {
-                    // don't include EOB's in the list...
-                    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
                 break;
             }
         }
-        
         // give teacher a proforma
         ?>
         <form name="editpage" method="post" action="lesson.php">
-        <input type="hidden" name="id" value="<?php echo $cm->id ?>" />
-        <input type="hidden" name="action" value="updatepage" />
-        <input type="hidden" name="pageid" value="<?php echo $_GET['pageid'] ?>" />
-        <input type="hidden" name="redisplay" value="0" />
-        <center><table cellpadding="5" border="1">
-        <tr><td align="center">
+        <input type="hidden" name="id" value="<?PHP echo $cm->id ?>">
+        <input type="hidden" name="action" value="updatepage">
+        <input type="hidden" name="pageid" value="<?PHP echo $_GET['pageid'] ?>">
+        <input type="hidden" name="redisplay" value="0">
+        <center><table cellpadding=5 border=1>
+               <?php
+                   switch ($page->qtype) {
+                               case LESSON_MULTICHOICE :
+                                       echo "<tr><td align=\"center\"><b>";
+                                       echo get_string("questiontype", "lesson").":</b> \n";
+                                       echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."<br>";
+                                       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 "<br><br><b>".get_string("multianswer", "lesson").":</b> \n";
+                                       if ($page->qoption) {
+                                               echo "<label for=\"qoption\" class=\"hidden-label\">Question Option</label><input type=\"checkbox\" id=\"qoption\" name=\"qoption\" value=\"1\" checked=\"checked\"/>"; //CDC hidden label added.
+                                       } else {
+                                               echo "<label for=\"qoption\" class=\"hidden-label\">Question Option</label><input type=\"checkbox\" id=\"qoption\" name=\"qoption\" value=\"1\"/>"; //CDC hidden label added.
+                                       }
+                                       helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson");
+                                       echo "</td></tr>\n";
+                                       break;
+                               case LESSON_SHORTANSWER :
+                                       echo "<tr><td align=\"center\"><b>";
+                                       echo get_string("questiontype", "lesson").":</b> \n";
+                                       echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."<br>";
+                                       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 "<br><br><b>".get_string("casesensitive", "lesson").":</b> \n";
+                                       if ($page->qoption) {
+                                               echo "<label for=\"qoption\" class=\"hidden-label\">Question Option</label><input type=\"checkbox\" id=\"qoption\" name=\"qoption\" value=\"1\" checked=\"checked\"/>"; //CDC hidden label added.
+                                       } else {
+                                               echo "<label for=\"qoption\" class=\"hidden-label\">Question Option</label><input type=\"checkbox\" id=\"qoption\" name=\"qoption\" value=\"1\"/>"; //CDC hidden label added.
+                                       }
+                                       helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson");
+                                       echo "</td></tr>\n";
+                                       break;
+                               case LESSON_TRUEFALSE :
+                               case LESSON_ESSAY :
+                               case LESSON_MATCHING :
+                               case LESSON_NUMERICAL :
+                                       echo "<tr><td align=\"center\"><b>";
+                                       echo get_string("questiontype", "lesson").":</b> \n";
+                                       echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."<br>";
+                                       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 "</td></tr>\n";
+                                       break;
+                       }
+               ?>
+               <tr><td align="center">
         <tr valign="top">
         <td><b><?php print_string("pagetitle", "lesson"); ?>:</b><br />
-        <input type="text" name="title" size="80" maxsize="255" value="<?php echo $page->title ?>" /></td>
+        <!-- //CDC hidden-label added.--><label for="title" class="hidden-label">Title</label><input type="text" id="title" name="title" size="80" maxsize="255" value="<?PHP echo $page->title ?>"></td>
         </tr>
-        <?php
+        <?PHP
         echo "<tr><td><b>";
         echo get_string("pagecontents", "lesson").":</b><br />\n";
         print_textarea($usehtmleditor, 25, 70, 630, 400, "contents", $page->contents);
         echo "</td></tr>\n";
         $n = 0;
         switch ($page->qtype) {
-            case LESSON_SHORTANSWER :
-                echo "<tr><td><b>".get_string("questiontype", "lesson").":</b> \n";
-                choose_from_menu($LESSON_QUESTION_TYPE, "qtype", $page->qtype, "");
-                echo "&nbsp;&nbsp;";
-                echo " <b>".get_string("casesensitive", "lesson").":</b> \n";
-                if ($page->qoption) {
-                    echo "<input type=\"checkbox\" name=\"qoption\" value=\"1\" checked=\"checked\" />";
-                } else {
-                    echo "<input type=\"checkbox\" name=\"qoption\" value=\"1\" />";
-                }
-                helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson");
-                break;
-            case LESSON_MULTICHOICE :
-                echo "<tr><td><b>".get_string("questiontype", "lesson").":</b> \n";
-                choose_from_menu($LESSON_QUESTION_TYPE, "qtype", $page->qtype, "");
-                echo "&nbsp;&nbsp;";
-                echo " <b>".get_string("multianswer", "lesson").":</b> \n";
-                if ($page->qoption) {
-                    echo "<input type=\"checkbox\" name=\"qoption\" value=\"1\" checked=\"checked\" />";
-                } else {
-                    echo "<input type=\"checkbox\" name=\"qoption\" value=\"1\" />";
-                }
-                helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson");
-                break;
-            case LESSON_TRUEFALSE :
-            case LESSON_MATCHING :
-            case LESSON_NUMERICAL :
-                echo "<tr><td><b>".get_string("questiontype", "lesson").":</b> \n";
-                choose_from_menu($LESSON_QUESTION_TYPE, "qtype", $page->qtype, "");
-                helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson");
-                break;
             case LESSON_BRANCHTABLE :
-                echo "<input type=\"hidden\" name=\"qtype\" value=\"$page->qtype\" />\n";
+                echo "<input type=\"hidden\" name=\"qtype\" value=\"$page->qtype\">\n";
+                               /// CDC-FLAG /// 6/16/04
+                               echo "<tr><td>\n";
+                               echo "<center>";
+                               if ($page->layout) {
+                                       echo "<input CHECKED name=\"layout\" type=\"checkbox\" value=\"1\">";
+                               } else {
+                                       echo "<input name=\"layout\" type=\"checkbox\" value=\"1\">";
+                               }
+                               echo get_string("arrangebuttonshorizontally", "lesson")."<center>\n";
+                               echo "<br>";
+                               if ($page->display) {
+                                       echo "<center><input name=\"display\" type=\"checkbox\" value=\"1\" CHECKED>";
+                               } else {
+                                       echo "<center><input name=\"display\" type=\"checkbox\" value=\"1\">";
+                               }                               
+                               echo get_string("displayinleftmenu", "lesson")."<center>\n";
+                               echo "</td></tr>\n";
+                               /// CDC-FLAG ///                                                                
                 echo "<tr><td><b>".get_string("branchtable", "lesson")."</b> \n";
                 break;
+                       case LESSON_CLUSTER :
+                echo "<input type=\"hidden\" name=\"qtype\" value=\"$page->qtype\">\n";
+                echo "<tr><td><b>".get_string("clustertitle", "lesson")."</b> \n";
+                break;                
+                       case LESSON_ENDOFCLUSTER :
+                echo "<input type=\"hidden\" name=\"qtype\" value=\"$page->qtype\">\n";
+                echo "<tr><td><b>".get_string("endofclustertitle", "lesson")."</b> \n";
+                break;                                 
             case LESSON_ENDOFBRANCH :
-                echo "<input type=\"hidden\" name=\"qtype\" value=\"$page->qtype\" />\n";
+                echo "<input type=\"hidden\" name=\"qtype\" value=\"$page->qtype\">\n";
                 echo "<tr><td><b>".get_string("endofbranch", "lesson")."</b> \n";
                 break;                
         }       
         echo "</td></tr>\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 "<input type=\"hidden\" name=\"answerid[$n]\" value=\"$answer->id\" />\n";
+                echo "<input type=\"hidden\" name=\"answerid[$n]\" value=\"$answer->id\">\n";
                 switch ($page->qtype) {
-                    case LESSON_MULTICHOICE:
+                    case LESSON_MATCHING:
+                                               if ($n == 0) {
+                                                       echo "<tr><td><b>".get_string("correctresponse", "lesson").":</b>\n";
+                                                       if ($flags & LESSON_ANSWER_EDITOR) {
+                                                               echo " [".get_string("useeditor", "lesson").": ".
+                                                                       "<label for=\"answereditor[$n]\" class=\"hidden-label\">answereditor[$n]</label><input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" 
+                                                                       checked=\"checked\">"; //CDC hidden label added.
+                                                               helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                                                               echo "]<br />\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").": ".
+                                                                       "<label for=\"answereditor[$n]\" class=\"hidden-label\">answereditor[$n]</label><input type=\"checkbox\" id=\answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\">"; //CDC hidden label.
+                                                               helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                                                               echo "]<br />\n";
+                                                               print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer);
+                                                       }
+                                               } elseif ($n == 1) {
+                                                       echo "<tr><td><b>".get_string("wrongresponse", "lesson").":</b>\n";
+                                                       if ($flags & LESSON_ANSWER_EDITOR) {
+                                                               echo " [".get_string("useeditor", "lesson").": ".
+                                                                       "<label for=\"answereditor[$n]\" class=\"hidden-label\">answereditor[$n]</label><input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" 
+                                                                       checked=\"checked\">"; //CDC hidden label added.
+                                                               helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                                                               echo "]<br />\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").": ".
+                                                                       "<label for=\"answereditor[$n]\" class=\"hidden-label\">answereditor[$n]</label><input type=\"checkbox\" id=\answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\">"; //CDC hidden label.
+                                                               helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                                                               echo "]<br />\n";
+                                                               print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer);
+                                                       }
+                                               } else {
+                                                       $ncorrected = $n - 1;
+                                                       echo "<tr><td><b>".get_string("answer", "lesson")." $ncorrected:</b>\n";
+                                                       if ($flags & LESSON_ANSWER_EDITOR) {
+                                                               echo " [".get_string("useeditor", "lesson").": ".
+                                                                       "<label for=\"answereditor[$n]\" class=\"hidden-label\">answereditor[$n]</label><input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" 
+                                                                       checked=\"checked\">"; //CDC hidden label added.
+                                                               helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                                                               echo "]<br />\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").": ".
+                                                                       "<label for=\"answereditor[$n]\" class=\"hidden-label\">answereditor[$n]</label><input type=\"checkbox\" id=\answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\">"; //CDC hidden label.
+                                                               helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                                                               echo "]<br />\n";
+                                                               print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer);
+                                                       }
+                                                       echo "</td></tr>\n";
+                                                       echo "<tr><td><b>".get_string("matchesanswer", "lesson")." $ncorrected:</b>\n";
+                                                       if ($flags & LESSON_RESPONSE_EDITOR) {
+                                                               echo " [".get_string("useeditor", "lesson").": ".
+                                                                       "<label for=\"responseeditor[$n]\" class=\"hidden-label\">responseeditor[$n]</label><input type=\"checkbox\" id=\"responseeditor[$n]\" name=\"responseeditor[$n]\" value=\"1\" 
+                                                                       checked=\"checked\">"; //CDC hidden label added.
+                                                               helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                                                               echo "]<br />\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").": ".
+                                                                       "<label for=\"responseeditor[$n]\" class=\"hidden-label\">responseeditor[$n]</label><input type=\"checkbox\" id=\"responseeditor[$n]\" name=\"responseeditor[$n]\" value=\"1\">"; //CDC hidden label added.
+                                                               helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                                                               echo "]<br />\n";
+                                                               print_textarea(false, 6, 70, 630, 300, "response[$n]", $answer->response);
+                                                       }
+                                               }
+                                               echo "</td></tr>\n";
+                        break;
                     case LESSON_TRUEFALSE:
+                    case LESSON_MULTICHOICE:
                     case LESSON_SHORTANSWER:
-                    case LESSON_NUMERICAL:
-                    case LESSON_MATCHING:
+                    case LESSON_NUMERICAL:                                     
                         echo "<tr><td><b>".get_string("answer", "lesson")." $nplus1:</b>\n";
                         if ($flags & LESSON_ANSWER_EDITOR) {
                             echo " [".get_string("useeditor", "lesson").": ".
-                                "<input type=\"checkbox\" name=\"answereditor[$n]\" value=\"1\" 
-                                checked=\"checked\" />";
+                                "<label for=\"answereditor[$n]\" class=\"hidden-label\">answereditor[$n]</label><input type=\"checkbox\" id=\"answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\" 
+                                checked=\"checked\">"; //CDC hidden label added.
                             helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
                             echo "]<br />\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").": ".
-                                "<input type=\"checkbox\" name=\"answereditor[$n]\" value=\"1\" />";
+                                "<label for=\"answereditor[$n]\" class=\"hidden-label\">answereditor[$n]</label><input type=\"checkbox\" id=\answereditor[$n]\" name=\"answereditor[$n]\" value=\"1\">"; //CDC hidden label.
                             helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
                             echo "]<br />\n";
                             print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer);
                         echo "<tr><td><b>".get_string("response", "lesson")." $nplus1:</b>\n";
                         if ($flags & LESSON_RESPONSE_EDITOR) {
                             echo " [".get_string("useeditor", "lesson").": ".
-                                "<input type=\"checkbox\" name=\"responseeditor[$n]\" value=\"1\" 
-                                checked=\"checked\" />";
+                                "<label for=\"responseeditor[$n]\" class=\"hidden-label\">responseeditor[$n]</label><input type=\"checkbox\" id=\"responseeditor[$n]\" name=\"responseeditor[$n]\" value=\"1\" 
+                                checked=\"checked\">"; //CDC hidden label added.
                             helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
                             echo "]<br />\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").": ".
-                                "<input type=\"checkbox\" name=\"responseeditor[$n]\" value=\"1\" />";
+                                "<label for=\"responseeditor[$n]\" class=\"hidden-label\">responseeditor[$n]</label><input type=\"checkbox\" id=\"responseeditor[$n]\" name=\"responseeditor[$n]\" value=\"1\">"; //CDC hidden label added.
                             helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
                             echo "]<br />\n";
                             print_textarea(false, 6, 70, 630, 300, "response[$n]", $answer->response);
                         echo "<tr><td><b>".get_string("description", "lesson")." $nplus1:</b>\n";
                         if ($flags & LESSON_ANSWER_EDITOR) {
                             echo " [".get_string("useeditor", "lesson").": ".
-                                "<input type=\"checkbox\" name=\"answereditor[$n]\" value=\"1\" 
-                                checked=\"checked\" />";
+                                "<label for=\"answereditor[$n]\" class=\"hidden-label\">answereditor[$n]</label><input type=\"checkbox\" name=\"answereditor[$n]\" value=\"1\" 
+                                checked=\"checked\">"; //CDC hidden label added.
                             helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
                             echo "]<br />\n";
                             print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer);
+                            use_html_editor("answer[$n]"); // switch on the editor  CDC-FLAG added in this line... editor would not turn on w/o it
                         } else {
                             echo " [".get_string("useeditor", "lesson").": ".
-                                "<input type=\"checkbox\" name=\"answereditor[$n]\" value=\"1\" />";
+                                "<input type=\"checkbox\" name=\"answereditor[$n]\" value=\"1\">";
                             helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
                             echo "]<br />\n";
                             print_textarea(false, 10, 70, 630, 300, "answer[$n]", $answer->answer);
                         echo "</td></tr>\n";
                         break;
                 }
-                echo "<tr><td><b>".get_string("jump", "lesson")." $nplus1:</b> \n";
-                lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, "");
-                helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
-                echo "</td></tr>\n";
+                               switch ($page->qtype) {
+                                       case LESSON_MATCHING :
+                                               if ($n == 2) {
+                                                       echo "<tr><td><b>".get_string("correctanswerjump", "lesson").":</b> \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").": <input type=\"text\" name=\"score[$n]\" value=\"$answer->score\" size=\"5\">";
+                                                       }
+                                               if ($n == 3) {
+                                                       echo "<tr><td><b>".get_string("wronganswerjump", "lesson").":</b> \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").": <input type=\"text\" name=\"score[$n]\" value=\"$answer->score\" size=\"5\">";
+                                                       }
+                                               echo "</td></tr>\n";
+                                               break;
+                                       case LESSON_ESSAY :
+                                               echo "<tr><td><b>".get_string("jump", "lesson").":</b> \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").": <input type=\"text\" name=\"score[$n]\" value=\"$answer->score\" size=\"5\">";
+                                               }
+                                               echo "</td></tr>\n";
+                                               break;
+                    case LESSON_TRUEFALSE:
+                    case LESSON_MULTICHOICE:
+                    case LESSON_SHORTANSWER:
+                    case LESSON_NUMERICAL:
+                                               echo "<tr><td><b>".get_string("jump", "lesson")." $nplus1:</b> \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: <input type=\"text\" name=\"score[$n]\" value=\"$answer->score\" size=\"5\">";
+                                               }
+                                               echo "</td></tr>\n";
+                                               break;
+                                       case LESSON_BRANCHTABLE:
+                                       case LESSON_CLUSTER:
+                                       case LESSON_ENDOFCLUSTER:
+                                       case LESSON_ENDOFBRANCH:
+                                               echo "<tr><td><b>".get_string("jump", "lesson")." $nplus1:</b> \n";
+                                               lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, "");
+                                               helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
+                                               echo "</td></tr>\n";
+                                               break;
+                               }
                 $n++;
+                               if ($page->qtype == LESSON_ESSAY) {
+                                       break; // only one answer for essays
+                               }                               
             }
         }
-        if ($page->qtype != LESSON_ENDOFBRANCH) {
-            for ($i = $n; $i < $lesson->maxanswers; $i++) {
+        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;
+                       }
+            for ($i = $n; $i < $maxanswers; $i++) {
+                               if ($page->qtype == LESSON_TRUEFALSE && $i > 1) {
+                                       break; // stop printing answers... only need two for true/false
+                               }
                 $iplus1 = $i + 1;
-                echo "<input type=\"hidden\" name=\"answerid[$i]\" value=\"0\" />\n";
+                echo "<input type=\"hidden\" name=\"answerid[$i]\" value=\"0\">\n";
                 switch ($page->qtype) {
-                    case LESSON_MULTICHOICE:
+                    case LESSON_MATCHING:
+                                               $icorrected = $i - 1;
+                        echo "<tr><td><b>".get_string("answer", "lesson")." $icorrected:</b>\n";
+                        echo " [".get_string("useeditor", "lesson").": ".
+                            "<input type=\"checkbox\" name=\"answereditor[$i]\" value=\"1\">";
+                        helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                        echo "]<br />\n";
+                        print_textarea(false, 10, 70, 630, 300, "answer[$i]");
+                        echo "</td></tr>\n";
+                        echo "<tr><td><b>".get_string("matchesanswer", "lesson")." $icorrected:</b>\n";
+                        echo " [".get_string("useeditor", "lesson").": ".
+                            "<input type=\"checkbox\" name=\"responseeditor[$i]\" value=\"1\">";
+                        helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
+                        echo "]<br />\n";
+                        print_textarea(false, 10, 70, 630, 300, "response[$i]");
+                        echo "</td></tr>\n";
+                        break;
                     case LESSON_TRUEFALSE:
+                    case LESSON_MULTICHOICE:
                     case LESSON_SHORTANSWER:
                     case LESSON_NUMERICAL:
-                    case LESSON_MATCHING:
                         echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b>\n";
                         echo " [".get_string("useeditor", "lesson").": ".
-                            "<input type=\"checkbox\" name=\"answereditor[$i]\" value=\"1\" />";
+                            "<input type=\"checkbox\" name=\"answereditor[$i]\" value=\"1\">";
                         helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
                         echo "]<br />\n";
                         print_textarea(false, 10, 70, 630, 300, "answer[$i]");
                         echo "</td></tr>\n";
                         echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b>\n";
                         echo " [".get_string("useeditor", "lesson").": ".
-                            "<input type=\"checkbox\" name=\"responseeditor[$i]\" value=\"1\" />";
+                            "<input type=\"checkbox\" name=\"responseeditor[$i]\" value=\"1\">";
                         helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
                         echo "]<br />\n";
                         print_textarea(false, 10, 70, 630, 300, "response[$i]");
                     case LESSON_BRANCHTABLE:
                         echo "<tr><td><b>".get_string("description", "lesson")." $iplus1:</b>\n";
                         echo " [".get_string("useeditor", "lesson").": ".
-                            "<input type=\"checkbox\" name=\"answereditor[$i]\" value=\"1\" />";
+                            "<input type=\"checkbox\" name=\"answereditor[$i]\" value=\"1\">";
                         helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson");
                         echo "]<br />\n";
                         print_textarea(false, 10, 70, 630, 300, "answer[$i]");
                         echo "</td></tr>\n";
                         break;
                 }
-                echo "<tr><td><b>".get_string("jump", "lesson")." $iplus1:</b> \n";
-                lesson_choose_from_menu($jump, "jumpto[$i]", 0, "");
-                helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
-                echo "</td></tr>\n";
+                               switch ($page->qtype) {
+                                       case LESSON_ESSAY :
+                                               if ($i < 1) {
+                                                       echo "<tr><td><B>".get_string("jump", "lesson").":</b> \n";
+                                                       lesson_choose_from_menu($jump, "jumpto[$i]", 0, "");
+                                                       helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
+                                                       if($lesson->custom) {
+                                                               echo get_string("score", "lesson").": <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\">";
+                                                       }
+                                                       echo "</td></tr>\n";
+                                               }
+                                               break;
+                                       case LESSON_MATCHING :
+                                               if ($i == 2) {
+                                                       echo "<tr><td><b>".get_string("correctanswerjump", "lesson").":</b> \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").": <input type=\"text\" name=\"score[$i]\" value=\"$answer->score\" size=\"5\">";
+                                                       }
+                                               if ($i == 3) {
+                                                       echo "<tr><td><b>".get_string("wronganswerjump", "lesson").":</b> \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").": <input type=\"text\" name=\"score[$i]\" value=\"$answer->score\" size=\"5\">";
+                                                       }
+
+                                               echo "</td></tr>\n";
+                                               break;
+                    case LESSON_TRUEFALSE:
+                    case LESSON_MULTICHOICE:
+                    case LESSON_SHORTANSWER:
+                    case LESSON_NUMERICAL:
+                                               echo "<tr><td><B>".get_string("jump", "lesson")." $iplus1:</b> \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: <input type=\"text\" name=\"score[$i]\" value=\"-1\" size=\"5\">";
+                                               }
+                                               echo "</td></tr>\n";
+                                               break;
+                                       case LESSON_BRANCHTABLE :
+                                               echo "<tr><td><B>".get_string("jump", "lesson")." $iplus1:</b> \n";
+                                               lesson_choose_from_menu($jump, "jumpto[$i]", 0, "");
+                                               helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
+                                               echo "</td></tr>\n";
+                                               break;
+                               }
             }
         }
         // close table and form
         ?>
         </table><br />
         <input type="button" value="<?php print_string("redisplaypage", "lesson") ?>" 
-            onclick="document.editpage.redisplay.value=1;document.editpage.submit();" />
-        <input type="submit" value="<?php  print_string("savepage", "lesson") ?>" />
-        <input type="submit" name="cancel" value="<?php  print_string("cancel") ?>" />
+            onClick="document.editpage.redisplay.value=1;document.editpage.submit();">
+        <input type="submit" value="<?php  print_string("savepage", "lesson") ?>">
+        <input type="submit" name="cancel" value="<?php  print_string("cancel") ?>">
         </center>
         </form>
-        <?php
+        <?PHP
                }
        
 
             } 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 ///
             $newpage->title = $form->title;
             $newpage->contents = trim($form->contents);
             $newpageid = insert_record("lesson_pages", $newpage);
                 } 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 ///
                 $newpage->title = $form->title;
                 $newpage->contents = trim($form->contents);
                 $newpageid = insert_record("lesson_pages", $newpage);
                 } 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 ///
                 $newpage->title = $form->title;
                 $newpage->contents = trim($form->contents);
                 $newpageid = insert_record("lesson_pages", $newpage);
             }
         }
         // now add the answers
-        for ($i = 0; $i < $lesson->maxanswers; $i++) {
-            if (trim(strip_tags($form->answer[$i]))) { // strip_tags because the HTML editor adds <p><br />...
-                $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];
-                }
-                $newanswerid = insert_record("lesson_answers", $newanswer);
-                if (!$newanswerid) {
-                    error("Insert Page: answer record $i not inserted");
-                }
-            } else {
-                break;
-            }
-        }
+               /// 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 {
+                       for ($i = 0; $i < $lesson->maxanswers; $i++) {
+                               if (trim(strip_tags($form->answer[$i]))) { // strip_tags because the HTML editor adds <p><br />...
+                                       $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("ok"));
        }
        
         } 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 ///                
         $page->title = $form->title;
         $page->contents = trim($form->contents);
         if (!update_record("lesson_pages", $page)) {
             error("Update page: page not updated");
         }
-        if ($page->qtype == LESSON_ENDOFBRANCH) {
+        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->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 (!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");
             }
             for ($i = 0; $i < $lesson->maxanswers; $i++) {
                 // strip tags because the editor gives <p><br />...
                 // also save any answers where the editor is (going to be) used
-                if (!isset($form->answereditor[$i])) { // clean up check box
-                    $form->answereditor[$i] = 0;
-                }
-                if (!isset($form->responseeditor[$i])) { // clean up check box
-                    $form->responseeditor[$i] = 0;
-                }
                 if (trim(strip_tags($form->answer[$i])) or $form->answereditor[$i] or $form->responseeditor[$i]) {
                     if ($form->answerid[$i]) {
                         unset($oldanswer);
                             $oldanswer->response = trim($form->response[$i]);
                         }
                         $oldanswer->jumpto = $form->jumpto[$i];
+                                               /// 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");
                         }
                             $newanswer->response = trim($form->response[$i]);
                         }
                         $newanswer->jumpto = $form->jumpto[$i];
+                                               /// 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->answerid[$i]) {
+                                       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 {
+                                                       unset($oldanswer);
+                                                       $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])) {
                             error("Update page: unable to delete answer record");
        else {
                error("Fatal Error: Unknown Action: ".$action."\n");
        }
-
        print_footer($course);
  
 ?>
index 07b0b62d3ee06505290f23a9b7a6bb38c91edb1c..29aec7a63aee736f638fcedddc6c2708cbd2cf4c 100644 (file)
-<?php  // $Id$
+<?PHP  // $Id$ 
+               // modified by mnielsen @ CDC
+               /// Update:  The lib.php now contains only the functions that are
+               /// used outside of the lesson module.  All functions (I hope) that are only local
+               /// are now in locallib.php.  All the constants moved there as well.
+
 
 /// Library of functions and constants for module lesson
 /// (replace lesson with the name of your module and delete this line)
 
-
-if (!defined("LESSON_UNSEENPAGE")) {
-    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
-    }
-
-$LESSON_NEXTPAGE_ACTION = array (0 => get_string("normal", "lesson"),
-                          LESSON_UNSEENPAGE => get_string("showanunseenpage", "lesson"),
-                          LESSON_UNANSWEREDPAGE => get_string("showanunansweredpage", "lesson") );
-
-
-if (!defined("LESSON_NEXTPAGE")) {
-    define("LESSON_NEXTPAGE", -1); // Next page
-    }
-if (!defined("LESSON_EOL")) {
-    define("LESSON_EOL", -9); // End of Lesson
-    }
-if (!defined("LESSON_UNDEFINED")) {
-    define("LESSON_UNDEFINED", -99); // undefined
-    }
-
-if (!defined("LESSON_SHORTANSWER")) {
-    define("LESSON_SHORTANSWER",   "1");
-}        
-if (!defined("LESSON_TRUEFALSE")) {
-    define("LESSON_TRUEFALSE",     "2");
-}
-if (!defined("LESSON_MULTICHOICE")) {
-    define("LESSON_MULTICHOICE",   "3");
-}
-if (!defined("LESSON_RANDOM")) {
-    define("LESSON_RANDOM",        "4");
-}
-if (!defined("LESSON_MATCHING")) {
-    define("LESSON_MATCHING",         "5");
-}
-if (!defined("LESSON_RANDOMSAMATCH")) {
-    define("LESSON_RANDOMSAMATCH", "6");
-}
-if (!defined("LESSON_DESCRIPTION")) {
-    define("LESSON_DESCRIPTION",   "7");
-}
-if (!defined("LESSON_NUMERICAL")) {
-    define("LESSON_NUMERICAL",     "8");
-}
-if (!defined("LESSON_MULTIANSWER")) {
-    define("LESSON_MULTIANSWER",   "9");
-}
-
-$LESSON_QUESTION_TYPE = array ( LESSON_MULTICHOICE => get_string("multichoice", "quiz"),
-                              LESSON_TRUEFALSE     => get_string("truefalse", "quiz"),
-                              LESSON_SHORTANSWER   => get_string("shortanswer", "quiz"),
-                              LESSON_NUMERICAL     => get_string("numerical", "quiz"),
-                              LESSON_MATCHING      => get_string("match", "quiz")
-//                            LESSON_DESCRIPTION   => get_string("description", "quiz"),
-//                            LESSON_RANDOM        => get_string("random", "quiz"),
-//                            LESSON_RANDOMSAMATCH => get_string("randomsamatch", "quiz"),
-//                            LESSON_MULTIANSWER   => get_string("multianswer", "quiz"),
-                              );
-
-if (!defined("LESSON_BRANCHTABLE")) {
-    define("LESSON_BRANCHTABLE",   "20");
-}
-if (!defined("LESSON_ENDOFBRANCH")) {
-    define("LESSON_ENDOFBRANCH",   "21");
-}
-
-if (!defined("LESSON_ANSWER_EDITOR")) {
-    define("LESSON_ANSWER_EDITOR",   "1");
-}
-if (!defined("LESSON_RESPONSE_EDITOR")) {
-    define("LESSON_RESPONSE_EDITOR",   "2");
-}
-/*******************************************************************/
-function lesson_choose_from_menu ($options, $name, $selected="", $nothing="choose", $script="", $nothingvalue="0", $return=false) {
-/// Given an array of value, creates a popup menu to be part of a form
-/// $options["value"]["label"]
-    
-    if ($nothing == "choose") {
-        $nothing = get_string("choose")."...";
-    }
-
-    if ($script) {
-        $javascript = "onChange=\"$script\"";
-    } else {
-        $javascript = "";
-    }
-
-    $output = "<select name=$name $javascript>\n";
-    if ($nothing) {
-        $output .= "   <option value=\"$nothingvalue\"\n";
-        if ($nothingvalue == $selected) {
-            $output .= " selected=\"selected\"";
-        }
-        $output .= ">$nothing</option>\n";
-    }
-    if (!empty($options)) {
-        foreach ($options as $value => $label) {
-            $output .= "   <option value=\"$value\"";
-            if ($value == $selected) {
-                $output .= " selected=\"selected\"";
-            }
-            // stop zero label being replaced by array index value
-            // if ($label) {
-            //    $output .= ">$label</option>\n";
-            // } else {
-            //     $output .= ">$value</option>\n";
-            //  }
-            $output .= ">$label</option>\n";
-            
-        }
-    }
-    $output .= "</select>\n";
-
-    if ($return) {
-        return $output;
-    } else {
-        echo $output;
-    }
-}   
-
-
 /*******************************************************************/
 function lesson_add_instance($lesson) {
 /// Given an object containing all the necessary data, 
 /// (defined by the form in mod.html) this function 
 /// will create a new instance and return the id number 
 /// of the new instance.
+       global $SESSION;
 
     $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);
+       
+       /// 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);
+       }
+       
     return insert_record("lesson", $lesson);
 }
 
@@ -156,12 +62,35 @@ 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 ///
+
+       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 update_record("lesson", $lesson);
 }
@@ -233,27 +162,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) {
@@ -261,13 +190,13 @@ function lesson_user_complete($course, $user, $mod, $lesson) {
                 } else {
                     $ncorrect = 0;
                 }
-            }
-        }
+                       }
+               }
         if ($npages) {
-                $table->data[] = array($retry + 1, $npages, $ncorrect, userdate($timeseen));
+                           $table->data[] = array($retry + 1, $npages, $ncorrect, userdate($timeseen));
         }
-        print_table($table);
-        print_simple_box_end();
+               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")) {
@@ -318,13 +247,10 @@ function lesson_grades($lessonid) {
 /// indexed by user.  It also returns a maximum allowed grade.
     global $CFG;
 
-    if (!$lesson = get_record("lesson", "id", $lessonid)) {
-        error("Lesson record not found");
-    }
-    if (!$return->maxgrade = $lesson->grade) {
-        return NULL;
-    }
-    if (!empty($lesson->usemaxgrade)) {
+       if (!$lesson = get_record("lesson", "id", $lessonid)) {
+               error("Lesson record not found");
+       }
+    if ($lesson->usemaxgrade) {
         $grades = get_records_sql_menu("SELECT userid,MAX(grade) FROM {$CFG->prefix}lesson_grades WHERE
                 lessonid = $lessonid GROUP BY userid");
     } else {
@@ -333,13 +259,18 @@ function lesson_grades($lessonid) {
     }
     
     // convert grades from percentages and tidy the numbers
-    if ($grades) {
-        foreach ($grades as $userid => $grade) {
-            $return->grades[$userid] = number_format($grade * $lesson->grade / 100.0, 1);
-        }
-    }
-
-    return $return;
+       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;
+       }
 }
 
 /*******************************************************************/
@@ -360,337 +291,4 @@ function lesson_get_participants($lessonid) {
     //Return students array (it contains an array of unique users)
     return ($students);
 }
-
-//////////////////////////////////////////////////////////////////////////////////////
-/// Any other lesson functions go here.  Each of them must have a name that 
-/// starts with lesson_
-
-/*******************************************************************/
-function lesson_iscorrect($pageid, $jumpto) {
-    // returns true is jumpto page is (logically) after the pageid page, other returns false
-    
-    // first test the special values
-    if (!$jumpto) {
-        // same page
-        return false;
-    } elseif ($jumpto == LESSON_NEXTPAGE) {
-        return true;
-    } elseif ($jumpto == LESSON_EOL) {
-        return true;
-    }
-    // we have to run through the pages from pageid looking for jumpid
-    $apageid = get_field("lesson_pages", "nextpageid", "id", $pageid);
-    while (true) {
-        if ($jumpto == $apageid) {
-            return true;
-        }
-        if ($apageid) {
-            $apageid = get_field("lesson_pages", "nextpageid", "id", $apageid);
-        } else {
-            return false;
-        }
-    }
-    return false; // should never be reached
-}
-
-
-/*******************************************************************/
-function lesson_save_question_options($question) {
-/// Given some question info and some data about the the answers
-/// this function parses, organises and saves the question
-/// This is only used when IMPORTING questions and is only called
-/// from format.php
-/// Lifted from mod/quiz/lib.php - 
-///    1. all reference to oldanswers removed
-///    2. all reference to quiz_multichoice table removed
-///    3. In SHORTANSWER questions usecase is store in the qoption field
-///    4. In NUMERIC questions store the range as two answers
-///    5. TRUEFALSE options are ignored
-///    6. For MULTICHOICE questions with more than one answer the qoption field is true
-///
-/// Returns $result->error or $result->notice
-    
-    $timenow = time();
-    switch ($question->qtype) {
-        case LESSON_SHORTANSWER:
-
-            $answers = array();
-            $maxfraction = -1;
-
-            // Insert all the new answers
-            foreach ($question->answer as $key => $dataanswer) {
-                if ($dataanswer != "") {
-                    unset($answer);
-                    $answer->lessonid   = $question->lessonid;
-                    $answer->pageid   = $question->id;
-                    if ($question->fraction[$key] >=0.5) {
-                        $answer->jumpto = LESSON_NEXTPAGE;
-                    }
-                    $answer->timecreated   = $timenow;
-                    $answer->grade = $question->fraction[$key] * 100;
-                    $answer->answer   = $dataanswer;
-                    $answer->feedback = $question->feedback[$key];
-                    if (!$answer->id = insert_record("lesson_answers", $answer)) {
-                        $result->error = "Could not insert shortanswer quiz answer!";
-                        return $result;
-                    }
-                    $answers[] = $answer->id;
-                    if ($question->fraction[$key] > $maxfraction) {
-                        $maxfraction = $question->fraction[$key];
-                    }
-                }
-            }
-
-
-            /// Perform sanity checks on fractional grades
-            if ($maxfraction != 1) {
-                $maxfraction = $maxfraction * 100;
-                $result->notice = get_string("fractionsnomax", "quiz", $maxfraction);
-                return $result;
-            }
-            break;
-
-        case LESSON_NUMERICAL:   // Note similarities to SHORTANSWER
-
-            $answers = array();
-            $maxfraction = -1;
-
-            
-            // for each answer store the pair of min and max values even if they are the same 
-            foreach ($question->answer as $key => $dataanswer) {
-                if ($dataanswer != "") {
-                    unset($answer);
-                    $answer->lessonid   = $question->lessonid;
-                    $answer->pageid   = $question->id;
-                    $answer->jumpto = LESSON_NEXTPAGE;
-                    $answer->timecreated   = $timenow;
-                    $answer->grade = $question->fraction[$key] * 100;
-                    $answer->answer   = $question->min[$key].":".$question->max[$key];
-                    $answer->response = $question->feedback[$key];
-                    if (!$answer->id = insert_record("lesson_answers", $answer)) {
-                        $result->error = "Could not insert numerical quiz answer!";
-                        return $result;
-                    }
-                    
-                    $answers[] = $answer->id;
-                    if ($question->fraction[$key] > $maxfraction) {
-                        $maxfraction = $question->fraction[$key];
-                    }
-                }
-            }
-
-            /// Perform sanity checks on fractional grades
-            if ($maxfraction != 1) {
-                $maxfraction = $maxfraction * 100;
-                $result->notice = get_string("fractionsnomax", "quiz", $maxfraction);
-                return $result;
-            }
-        break;
-
-
-        case LESSON_TRUEFALSE:
-
-            // the truth
-            $answer->lessonid   = $question->lessonid;
-            $answer->pageid = $question->id;
-            $answer->timecreated   = $timenow;
-            $answer->answer = get_string("true", "quiz");
-            $answer->grade = $question->answer * 100;
-            if ($answer->grade > 50 ) {
-                $answer->jumpto = LESSON_NEXTPAGE;
-            }
-            if (isset($question->feedbacktrue)) {
-                $answer->response = $question->feedbacktrue;
-            }
-            if (!$true->id = insert_record("lesson_answers", $answer)) {
-                $result->error = "Could not insert quiz answer \"true\")!";
-                return $result;
-            }
-
-            // the lie    
-            unset($answer);
-            $answer->lessonid   = $question->lessonid;
-            $answer->pageid = $question->id;
-            $answer->timecreated   = $timenow;
-            $answer->answer = get_string("false", "quiz");
-            $answer->grade = (1 - (int)$question->answer) * 100;
-            if ($answer->grade > 50 ) {
-                $answer->jumpto = LESSON_NEXTPAGE;
-            }
-            if (isset($question->feedbackfalse)) {
-                $answer->response = $question->feedbackfalse;
-            }
-            if (!$false->id = insert_record("lesson_answers", $answer)) {
-                $result->error = "Could not insert quiz answer \"false\")!";
-                return $result;
-            }
-
-          break;
-
-
-        case LESSON_MULTICHOICE:
-
-            $totalfraction = 0;
-            $maxfraction = -1;
-
-            $answers = array();
-
-            // Insert all the new answers
-            foreach ($question->answer as $key => $dataanswer) {
-                if ($dataanswer != "") {
-                    unset($answer);
-                    $answer->lessonid   = $question->lessonid;
-                    $answer->pageid   = $question->id;
-                    $answer->timecreated   = $timenow;
-                    $answer->grade = $question->fraction[$key] * 100;
-                    if ($answer->grade > 50 ) {
-                        $answer->jumpto = LESSON_NEXTPAGE;
-                    }
-                    $answer->answer   = $dataanswer;
-                    $answer->response = $question->feedback[$key];
-                    if (!$answer->id = insert_record("lesson_answers", $answer)) {
-                        $result->error = "Could not insert multichoice quiz answer! ";
-                        return $result;
-                    }
-                    // for Sanity checks
-                    if ($question->fraction[$key] > 0) {                 
-                        $totalfraction += $question->fraction[$key];
-                    }
-                    if ($question->fraction[$key] > $maxfraction) {
-                        $maxfraction = $question->fraction[$key];
-                    }
-                }
-            }
-
-            /// Perform sanity checks on fractional grades
-            if ($question->single) {
-                if ($maxfraction != 1) {
-                    $maxfraction = $maxfraction * 100;
-                    $result->notice = get_string("fractionsnomax", "quiz", $maxfraction);
-                    return $result;
-                }
-            } else {
-                $totalfraction = round($totalfraction,2);
-                if ($totalfraction != 1) {
-                    $totalfraction = $totalfraction * 100;
-                    $result->notice = get_string("fractionsaddwrong", "quiz", $totalfraction);
-                    return $result;
-                }
-            }
-        break;
-
-        case LESSON_MATCHING:
-
-            $subquestions = array();
-
-            $i = 0;
-            // Insert all the new question+answer pairs
-            foreach ($question->subquestions as $key => $questiontext) {
-                $answertext = $question->subanswers[$key];
-                if (!empty($questiontext) and !empty($answertext)) {
-                    unset($answer);
-                    $answer->lessonid   = $question->lessonid;
-                    $answer->pageid   = $question->id;
-                    $answer->timecreated   = $timenow;
-                    $answer->answer = $questiontext;
-                    $answer->response   = $answertext;
-                    if ($i == 0) {
-                        // first answer contains the correct answer jump
-                        $answer->jumpto = LESSON_NEXTPAGE;
-                    }
-                    if (!$subquestion->id = insert_record("lesson_answers", $answer)) {
-                        $result->error = "Could not insert quiz match subquestion!";
-                        return $result;
-                    }
-                    $subquestions[] = $subquestion->id;
-                    $i++;
-                }
-            }
-
-            if (count($subquestions) < 3) {
-                $result->notice = get_string("notenoughsubquestions", "quiz");
-                return $result;
-            }
-
-            break;
-
-
-        case LESSON_RANDOMSAMATCH:
-            $options->question = $question->id;
-            $options->choose = $question->choose;
-            if ($existing = get_record("quiz_randomsamatch", "question", $options->question)) {
-                $options->id = $existing->id;
-                if (!update_record("quiz_randomsamatch", $options)) {
-                    $result->error = "Could not update quiz randomsamatch options!";
-                    return $result;
-                }
-            } else {
-                if (!insert_record("quiz_randomsamatch", $options)) {
-                    $result->error = "Could not insert quiz randomsamatch options!";
-                    return $result;
-                }
-            }
-        break;
-
-        case LESSON_MULTIANSWER:
-            if (!$oldmultianswers = get_records("quiz_multianswers", "question", $question->id, "id ASC")) {
-                $oldmultianswers = array();
-            }
-
-            // Insert all the new multi answers
-            foreach ($question->answers as $dataanswer) {
-                if ($oldmultianswer = array_shift($oldmultianswers)) {  // Existing answer, so reuse it
-                    $multianswer = $oldmultianswer;
-                    $multianswer->positionkey = $dataanswer->positionkey;
-                    $multianswer->norm = $dataanswer->norm;
-                    $multianswer->answertype = $dataanswer->answertype;
-
-                    if (! $multianswer->answers = quiz_save_multianswer_alternatives
-                            ($question->id, $dataanswer->answertype,
-                             $dataanswer->alternatives, $oldmultianswer->answers))
-                    {
-                        $result->error = "Could not update multianswer alternatives! (id=$multianswer->id)";
-                        return $result;
-                    }
-                    if (!update_record("quiz_multianswers", $multianswer)) {
-                        $result->error = "Could not update quiz multianswer! (id=$multianswer->id)";
-                        return $result;
-                    }
-                } else {    // This is a completely new answer
-                    unset($multianswer);
-                    $multianswer->question = $question->id;
-                    $multianswer->positionkey = $dataanswer->positionkey;
-                    $multianswer->norm = $dataanswer->norm;
-                    $multianswer->answertype = $dataanswer->answertype;
-
-                    if (! $multianswer->answers = quiz_save_multianswer_alternatives
-                            ($question->id, $dataanswer->answertype,
-                             $dataanswer->alternatives))
-                    {
-                        $result->error = "Could not insert multianswer alternatives! (questionid=$question->id)";
-                        return $result;
-                    }
-                    if (!insert_record("quiz_multianswers", $multianswer)) {
-                        $result->error = "Could not insert quiz multianswer!";
-                        return $result;
-                    }
-                }
-            }
-        break;
-
-        case LESSON_RANDOM:
-        break;
-
-        case LESSON_DESCRIPTION:
-        break;
-
-        default:
-            $result->error = "Unsupported question type ($question->qtype)!";
-            return $result;
-        break;
-    }
-    return true;
-}
-
-
-?>
+?>
\ No newline at end of file
diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php
new file mode 100644 (file)
index 0000000..fa8eae6
--- /dev/null
@@ -0,0 +1,1131 @@
+<?php
+/// 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
+       }
+if (!defined("LESSON_UNANSWEREDPAGE")) {
+       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"),
+                          LESSON_UNANSWEREDPAGE => get_string("showanunansweredpage", "lesson") );
+
+
+if (!defined("LESSON_NEXTPAGE")) {
+       define("LESSON_NEXTPAGE", -1); // Next page
+       }
+if (!defined("LESSON_EOL")) {
+       define("LESSON_EOL", -9); // End of Lesson
+       }
+/// CDC-FLAG 6/14/04 ///
+if (!defined("LESSON_UNSEENBRANCHPAGE")) {
+       define("LESSON_UNSEENBRANCHPAGE", -50); // Unseen branch page
+       }
+if (!defined("LESSON_PREVIOUSPAGE")) {
+       define("LESSON_PREVIOUSPAGE", -40); // previous page
+       }
+if (!defined("LESSON_RANDOMPAGE")) {
+       define("LESSON_RANDOMPAGE", -60); // random branch page
+       }
+if (!defined("LESSON_RANDOMBRANCH")) {
+       define("LESSON_RANDOMBRANCH", -70); // random branch
+       }
+if (!defined("LESSON_CLUSTERJUMP")) {
+       define("LESSON_CLUSTERJUMP", -80); // random within a cluster
+       }
+/// CDC-FLAG ///       
+if (!defined("LESSON_UNDEFINED")) {
+       define("LESSON_UNDEFINED", -99); // undefined
+       }
+
+if (!defined("LESSON_SHORTANSWER")) {
+    define("LESSON_SHORTANSWER",   "1");
+}        
+if (!defined("LESSON_TRUEFALSE")) {
+    define("LESSON_TRUEFALSE",     "2");
+}
+if (!defined("LESSON_MULTICHOICE")) {
+    define("LESSON_MULTICHOICE",   "3");
+}
+if (!defined("LESSON_RANDOM")) {
+    define("LESSON_RANDOM",        "4");
+}
+if (!defined("LESSON_MATCHING")) {
+    define("LESSON_MATCHING",         "5");
+}
+if (!defined("LESSON_RANDOMSAMATCH")) {
+    define("LESSON_RANDOMSAMATCH", "6");
+}
+if (!defined("LESSON_DESCRIPTION")) {
+    define("LESSON_DESCRIPTION",   "7");
+}
+if (!defined("LESSON_NUMERICAL")) {
+    define("LESSON_NUMERICAL",     "8");
+}
+if (!defined("LESSON_MULTIANSWER")) {
+    define("LESSON_MULTIANSWER",   "9");
+}
+/// CDC-FLAG /// 6/16/04
+if (!defined("LESSON_ESSAY")) {
+       define("LESSON_ESSAY", "10");
+}
+if (!defined("LESSON_CLUSTER")) {
+    define("LESSON_CLUSTER",   "30");
+}
+if (!defined("LESSON_ENDOFCLUSTER")) {
+    define("LESSON_ENDOFCLUSTER",   "31");
+}
+/// CDC-FLAG ///
+
+$LESSON_QUESTION_TYPE = array ( LESSON_MULTICHOICE => get_string("multichoice", "quiz"),
+                              LESSON_TRUEFALSE     => get_string("truefalse", "quiz"),
+                              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_DESCRIPTION   => get_string("description", "quiz"),
+//                            LESSON_RANDOM        => get_string("random", "quiz"),
+//                            LESSON_RANDOMSAMATCH => get_string("randomsamatch", "quiz"),
+//                            LESSON_MULTIANSWER   => get_string("multianswer", "quiz"),
+                              );
+
+if (!defined("LESSON_BRANCHTABLE")) {
+    define("LESSON_BRANCHTABLE",   "20");
+}
+if (!defined("LESSON_ENDOFBRANCH")) {
+    define("LESSON_ENDOFBRANCH",   "21");
+}
+
+if (!defined("LESSON_ANSWER_EDITOR")) {
+    define("LESSON_ANSWER_EDITOR",   "1");
+}
+if (!defined("LESSON_RESPONSE_EDITOR")) {
+    define("LESSON_RESPONSE_EDITOR",   "2");
+}
+
+//////////////////////////////////////////////////////////////////////////////////////
+/// Any other lesson functions go here.  Each of them must have a name that 
+/// starts with lesson_
+
+/*******************************************************************/
+function lesson_save_question_options($question) {
+/// Given some question info and some data about the the answers
+/// this function parses, organises and saves the question
+/// This is only used when IMPORTING questions and is only called
+/// from format.php
+/// Lifted from mod/quiz/lib.php - 
+///    1. all reference to oldanswers removed
+///    2. all reference to quiz_multichoice table removed
+///    3. In SHORTANSWER questions usecase is store in the qoption field
+///    4. In NUMERIC questions store the range as two answers
+///    5. TRUEFALSE options are ignored
+///    6. For MULTICHOICE questions with more than one answer the qoption field is true
+///
+/// Returns $result->error or $result->notice
+    
+    $timenow = time();
+    switch ($question->qtype) {
+        case LESSON_SHORTANSWER:
+
+            $answers = array();
+            $maxfraction = -1;
+
+            // Insert all the new answers
+            foreach ($question->answer as $key => $dataanswer) {
+                if ($dataanswer != "") {
+                    unset($answer);
+                    $answer->lessonid   = $question->lessonid;
+                    $answer->pageid   = $question->id;
+                    if ($question->fraction[$key] >=0.5) {
+                        $answer->jumpto = LESSON_NEXTPAGE;
+                    }
+                    $answer->timecreated   = $timenow;
+                    $answer->grade = $question->fraction[$key] * 100;
+                    $answer->answer   = $dataanswer;
+                    $answer->feedback = $question->feedback[$key];
+                    if (!$answer->id = insert_record("lesson_answers", $answer)) {
+                        $result->error = "Could not insert shortanswer quiz answer!";
+                        return $result;
+                    }
+                    $answers[] = $answer->id;
+                    if ($question->fraction[$key] > $maxfraction) {
+                        $maxfraction = $question->fraction[$key];
+                    }
+                }
+            }
+
+
+            /// Perform sanity checks on fractional grades
+            if ($maxfraction != 1) {
+                $maxfraction = $maxfraction * 100;
+                $result->notice = get_string("fractionsnomax", "quiz", $maxfraction);
+                return $result;
+            }
+            break;
+
+        case LESSON_NUMERICAL:   // Note similarities to SHORTANSWER
+
+            $answers = array();
+            $maxfraction = -1;
+
+            
+            // for each answer store the pair of min and max values even if they are the same 
+            foreach ($question->answer as $key => $dataanswer) {
+                if ($dataanswer != "") {
+                    unset($answer);
+                    $answer->lessonid   = $question->lessonid;
+                    $answer->pageid   = $question->id;
+                    $answer->jumpto = LESSON_NEXTPAGE;
+                    $answer->timecreated   = $timenow;
+                    $answer->grade = $question->fraction[$key] * 100;
+                    $answer->answer   = $question->min[$key].":".$question->max[$key];
+                    $answer->response = $question->feedback[$key];
+                    if (!$answer->id = insert_record("lesson_answers", $answer)) {
+                        $result->error = "Could not insert numerical quiz answer!";
+                        return $result;
+                    }
+                    
+                    $answers[] = $answer->id;
+                    if ($question->fraction[$key] > $maxfraction) {
+                        $maxfraction = $question->fraction[$key];
+                    }
+                }
+            }
+
+            /// Perform sanity checks on fractional grades
+            if ($maxfraction != 1) {
+                $maxfraction = $maxfraction * 100;
+                $result->notice = get_string("fractionsnomax", "quiz", $maxfraction);
+                return $result;
+            }
+        break;
+
+
+        case LESSON_TRUEFALSE:
+
+            // the truth
+            $answer->lessonid   = $question->lessonid;
+            $answer->pageid = $question->id;
+            $answer->timecreated   = $timenow;
+            $answer->answer = get_string("true", "quiz");
+            $answer->grade = $question->answer * 100;
+            if ($answer->grade > 50 ) {
+                $answer->jumpto = LESSON_NEXTPAGE;
+            }
+            if (isset($question->feedbacktrue)) {
+                $answer->response = $question->feedbacktrue;
+            }
+            if (!$true->id = insert_record("lesson_answers", $answer)) {
+                $result->error = "Could not insert quiz answer \"true\")!";
+                return $result;
+            }
+
+            // the lie    
+            unset($answer);
+            $answer->lessonid   = $question->lessonid;
+            $answer->pageid = $question->id;
+            $answer->timecreated   = $timenow;
+            $answer->answer = get_string("false", "quiz");
+            $answer->grade = (1 - (int)$question->answer) * 100;
+            if ($answer->grade > 50 ) {
+                $answer->jumpto = LESSON_NEXTPAGE;
+            }
+            if (isset($question->feedbackfalse)) {
+                $answer->response = $question->feedbackfalse;
+            }
+            if (!$false->id = insert_record("lesson_answers", $answer)) {
+                $result->error = "Could not insert quiz answer \"false\")!";
+                return $result;
+            }
+
+          break;
+
+
+        case LESSON_MULTICHOICE:
+
+            $totalfraction = 0;
+            $maxfraction = -1;
+
+            $answers = array();
+
+            // Insert all the new answers
+            foreach ($question->answer as $key => $dataanswer) {
+                if ($dataanswer != "") {
+                    unset($answer);
+                    $answer->lessonid   = $question->lessonid;
+                    $answer->pageid   = $question->id;
+                    $answer->timecreated   = $timenow;
+                    $answer->grade = $question->fraction[$key] * 100;
+                    /// CDC-FLAG changed some defaults
+                                       /* Original Code
+                                       if ($answer->grade > 50 ) {
+                        $answer->jumpto = LESSON_NEXTPAGE;
+                    }
+                                       Replaced with:                    */
+                                       if ($answer->grade > 50 ) {
+                           $answer->jumpto = LESSON_NEXTPAGE;
+                        $answer->score = 1;
+                    }
+                                       // end Replace
+                    $answer->answer   = $dataanswer;
+                    $answer->response = $question->feedback[$key];
+                    if (!$answer->id = insert_record("lesson_answers", $answer)) {
+                        $result->error = "Could not insert multichoice quiz answer! ";
+                        return $result;
+                    }
+                    // for Sanity checks
+                    if ($question->fraction[$key] > 0) {                 
+                        $totalfraction += $question->fraction[$key];
+                    }
+                    if ($question->fraction[$key] > $maxfraction) {
+                        $maxfraction = $question->fraction[$key];
+                    }
+                }
+            }
+
+            /// Perform sanity checks on fractional grades
+            if ($question->single) {
+                if ($maxfraction != 1) {
+                    $maxfraction = $maxfraction * 100;
+                    $result->notice = get_string("fractionsnomax", "quiz", $maxfraction);
+                    return $result;
+                }
+            } else {
+                $totalfraction = round($totalfraction,2);
+                if ($totalfraction != 1) {
+                    $totalfraction = $totalfraction * 100;
+                    $result->notice = get_string("fractionsaddwrong", "quiz", $totalfraction);
+                    return $result;
+                }
+            }
+        break;
+
+        case LESSON_MATCHING:
+
+            $subquestions = array();
+
+            $i = 0;
+            // Insert all the new question+answer pairs
+            foreach ($question->subquestions as $key => $questiontext) {
+                $answertext = $question->subanswers[$key]; echo $answertext; echo "<br>"; exit;
+                if (!empty($questiontext) and !empty($answertext)) {
+                    unset($answer);
+                    $answer->lessonid   = $question->lessonid;
+                    $answer->pageid   = $question->id;
+                    $answer->timecreated   = $timenow;
+                    $answer->answer = $questiontext;
+                    $answer->response   = $answertext; 
+                    if ($i == 0) {
+                        // first answer contains the correct answer jump
+                        $answer->jumpto = LESSON_NEXTPAGE;
+                    }
+                    if (!$subquestion->id = insert_record("lesson_answers", $answer)) {
+                        $result->error = "Could not insert quiz match subquestion!";
+                        return $result;
+                    }
+                    $subquestions[] = $subquestion->id;
+                    $i++;
+                }
+            }
+
+            if (count($subquestions) < 3) {
+                $result->notice = get_string("notenoughsubquestions", "quiz");
+                return $result;
+            }
+
+            break;
+
+
+        case LESSON_RANDOMSAMATCH:
+            $options->question = $question->id;
+            $options->choose = $question->choose;
+            if ($existing = get_record("quiz_randomsamatch", "question", $options->question)) {
+                $options->id = $existing->id;
+                if (!update_record("quiz_randomsamatch", $options)) {
+                    $result->error = "Could not update quiz randomsamatch options!";
+                    return $result;
+                }
+            } else {
+                if (!insert_record("quiz_randomsamatch", $options)) {
+                    $result->error = "Could not insert quiz randomsamatch options!";
+                    return $result;
+                }
+            }
+        break;
+
+        case LESSON_MULTIANSWER:
+            if (!$oldmultianswers = get_records("quiz_multianswers", "question", $question->id, "id ASC")) {
+                $oldmultianswers = array();
+            }
+
+            // Insert all the new multi answers
+            foreach ($question->answers as $dataanswer) {
+                if ($oldmultianswer = array_shift($oldmultianswers)) {  // Existing answer, so reuse it
+                    $multianswer = $oldmultianswer;
+                    $multianswer->positionkey = $dataanswer->positionkey;
+                    $multianswer->norm = $dataanswer->norm;
+                    $multianswer->answertype = $dataanswer->answertype;
+
+                    if (! $multianswer->answers = quiz_save_multianswer_alternatives
+                            ($question->id, $dataanswer->answertype,
+                             $dataanswer->alternatives, $oldmultianswer->answers))
+                    {
+                        $result->error = "Could not update multianswer alternatives! (id=$multianswer->id)";
+                        return $result;
+                    }
+                    if (!update_record("quiz_multianswers", $multianswer)) {
+                        $result->error = "Could not update quiz multianswer! (id=$multianswer->id)";
+                        return $result;
+                    }
+                } else {    // This is a completely new answer
+                    unset($multianswer);
+                    $multianswer->question = $question->id;
+                    $multianswer->positionkey = $dataanswer->positionkey;
+                    $multianswer->norm = $dataanswer->norm;
+                    $multianswer->answertype = $dataanswer->answertype;
+
+                    if (! $multianswer->answers = quiz_save_multianswer_alternatives
+                            ($question->id, $dataanswer->answertype,
+                             $dataanswer->alternatives))
+                    {
+                        $result->error = "Could not insert multianswer alternatives! (questionid=$question->id)";
+                        return $result;
+                    }
+                    if (!insert_record("quiz_multianswers", $multianswer)) {
+                        $result->error = "Could not insert quiz multianswer!";
+                        return $result;
+                    }
+                }
+            }
+        break;
+
+        case LESSON_RANDOM:
+        break;
+
+        case LESSON_DESCRIPTION:
+        break;
+
+        default:
+            $result->error = "Unsupported question type ($question->qtype)!";
+            return $result;
+        break;
+    }
+    return true;
+}
+/*******************************************************************/
+function lesson_choose_from_menu ($options, $name, $selected="", $nothing="choose", $script="", $nothingvalue="0", $return=false) {
+/// Given an array of value, creates a popup menu to be part of a form
+/// $options["value"]["label"]
+    
+    if ($nothing == "choose") {
+        $nothing = get_string("choose")."...";
+    }
+
+    if ($script) {
+        $javascript = "onChange=\"$script\"";
+    } else {
+        $javascript = "";
+    }
+
+    $output = "<label for=$name class=hidden-label>$name</label><SELECT id=$name NAME=$name $javascript>\n"; //CDC hidden label added.
+    if ($nothing) {
+        $output .= "   <OPTION VALUE=\"$nothingvalue\"\n";
+        if ($nothingvalue == $selected) {
+            $output .= " SELECTED";
+        }
+        $output .= ">$nothing</OPTION>\n";
+    }
+    if (!empty($options)) {
+        foreach ($options as $value => $label) {
+            $output .= "   <OPTION VALUE=\"$value\"";
+            if ($value == $selected) {
+                $output .= " SELECTED";
+            }
+                       // stop zero label being replaced by array index value
+            // if ($label) {
+            //    $output .= ">$label</OPTION>\n";
+            // } else {
+            //     $output .= ">$value</OPTION>\n";
+                       //  }
+                       $output .= ">$label</OPTION>\n";
+            
+        }
+    }
+    $output .= "</SELECT>\n";
+
+    if ($return) {
+        return $output;
+    } else {
+        echo $output;
+    }
+}   
+
+/*******************************************************************/
+function lesson_iscorrect($pageid, $jumpto) {
+    // returns true is jumpto page is (logically) after the pageid page, other returns false
+    
+    // first test the special values
+    if (!$jumpto) {
+        // same page
+        return false;
+    } elseif ($jumpto == LESSON_NEXTPAGE) {
+        return true;
+       /// 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 ///
+    } elseif ($jumpto == LESSON_EOL) {
+        return true;
+    }
+    // we have to run through the pages from pageid looking for jumpid
+    $apageid = get_field("lesson_pages", "nextpageid", "id", $pageid);
+    while (true) {
+        if ($jumpto == $apageid) {
+            return true;
+        }
+        if ($apageid) {
+            $apageid = get_field("lesson_pages", "nextpageid", "id", $apageid);
+        } else {
+            return false;
+        }
+    }
+    return false; // should never be reached
+}
+
+/// CDC-FLAG ///
+/*******************************************************************/
+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;
+       }
+
+       if ($lessonpages[$pageid]->qtype == LESSON_BRANCHTABLE) {
+               return true;
+       }
+       
+       return lesson_is_page_in_branch($lessonpages, $pageid);
+}
+
+/*******************************************************************/
+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;
+       }
+
+       if ($lessonpages[$pageid]->qtype == LESSON_CLUSTER) {
+               return true;
+       }
+       
+       return lesson_is_page_in_cluster($lessonpages, $pageid);
+
+}
+
+// 6/21/04
+/*******************************************************************/
+function execute_teacherwarning($lesson) {
+// this function checks to see if a LESSON_CLUSTERJUMP or 
+// a LESSON_UNSEENBRANCHPAGE is used in a 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;
+}
+
+
+// 6/18/04
+/*******************************************************************/
+function lesson_cluster_jump($lesson, $user, $pageid) {
+// this fucntion interprets LESSON_CLUSTERJUMP
+// it will select a page randomly
+// and the page selected will be inbetween a cluster page and endofcluter/eol
+// and the page selected will be a page that has not been viewed already
+// 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
+    if (!$retakes = count_records("lesson_grades", "lessonid", $lesson, "userid", $user)) {
+               $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 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
+
+       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", $pages[$count][0], "lessonid", $lesson);
+                       if ($exitjump == LESSON_NEXTPAGE) {
+                               $exitjump = $pages[$count][2];
+                       }
+                       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
+       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 (isset($unseen)) { // if not set, 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;
+}
+
+/*******************************************************************/
+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
+    if (!$retakes = count_records("lesson_grades", "lessonid", $lesson, "userid", $user)) {
+               $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 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
+       foreach($pagesinbranch as $page) {      
+               if (!in_array($page->id, $seenpages)) {
+                       $unseen[] = $page->id;
+               }
+       }
+
+       if(!isset($unseen)) {
+               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
+/*******************************************************************/
+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;
+       }
+
+       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;
+       }
+       
+       foreach ($branchtables as $branchtable) {
+               // load all of the unseen branch tables into unseen
+               if (!array_key_exists($branchtable, $seen)) {
+                       $unseen[] = $branchtable;
+               }
+       }
+       if (isset($unseen)) {
+               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
+       }
+}
+
+/*******************************************************************/
+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");
+       }
+
+       // 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;
+       }
+
+       // get the pages within the branch      
+       $pagesinbranch = lesson_pages_in_branch($lessonpages, $pageid);
+       
+       if(!isset($pagesinbranch)) {
+               // 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
+/*******************************************************************/
+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
+
+       // 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;
+       }
+
+}
+
+/*******************************************************************/
+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
+
+       // 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) {
+// 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);                      
+               $pageid = $pages[$pageid]->nextpageid;
+       }
+}
+
+/*******************************************************************/
+function lesson_print_tree_link_menu($page, $id) { 
+// prints the actual link for the left menu
+
+       if ($page->qtype == LESSON_BRANCHTABLE && !$page->display) {
+               return false;
+       }
+       
+       // set up some variables  NoticeFix  changed whole function
+       $output = "";
+       $close = false;
+       $title=$page->title;  //CDC Chris Berri took out parsing of title in left menu on 6/11
+       $link="id=$id&action=navigation&pageid=".$page->id;
+       
+       if($_SERVER['QUERY_STRING']==$link) { 
+               $close=true; 
+               $output.="<div class='active'><em>"; 
+       } 
+       if (($page->qtype!=LESSON_BRANCHTABLE)||($page->qtype==LESSON_ENDOFBRANCH)||($page->qtype==21)) {
+               $output .= "";
+       } else {
+               $output .= "<li><a href=\"view.php?id=$id&action=navigation&pageid=$page->id\">".$title."</a></li>\n"; 
+       }
+       if($close) {
+               $output.="</em></div>";
+       }
+       echo $output;
+
+} 
+
+/*******************************************************************/
+function lesson_print_tree($pageid, $lessonid, $cmid, $pixpath) {
+// this function prints out the tree view list
+
+       if(!$pages = get_records_select("lesson_pages", "lessonid = $lessonid")) {
+               error("Error: could not find lesson pages");
+       }
+       echo "<table>";
+       while ($pageid != 0) {
+               echo "<tr><td>";
+               if(($pages[$pageid]->qtype != LESSON_BRANCHTABLE) && ($pages[$pageid]->qtype != LESSON_ENDOFBRANCH)) {
+                       $output = "<a style='color:#DF041E;' href=\"view.php?id=$cmid&display=".$pages[$pageid]->id."\">".$pages[$pageid]->title."</a>\n";
+               } else {
+                       $output = "<a href=\"view.php?id=$cmid&display=".$pages[$pageid]->id."\">".$pages[$pageid]->title."</a>\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 "<a title=\"move\" href=\"lesson.php?id=$cmid&action=move&pageid=".$pages[$pageid]->id."\">\n".
+                               "<img src=\"$pixpath/t/move.gif\" hspace=\"2\" height=11 width=11 alt=\"move\" border=0></a>\n"; //CDC alt text added.
+               }
+               echo "<a title=\"update\" href=\"lesson.php?id=$cmid&action=editpage&pageid=".$pages[$pageid]->id."\">\n".
+                       "<img src=\"$pixpath/t/edit.gif\" hspace=\"2\" height=11 width=11 alt=\"edit\" border=0></a>\n".
+                       "<a title=\"delete\" href=\"lesson.php?id=$cmid&action=confirmdelete&pageid=".$pages[$pageid]->id."\">\n".
+                       "<img src=\"$pixpath/t/delete.gif\" hspace=\"2\" height=11 width=11 alt=\"delete\" border=0></a>\n"; //CDC alt text added.
+
+               echo "</tr></td>";
+               $pageid = $pages[$pageid]->nextpageid;
+       }
+       echo "</table>";
+}
+
+/*******************************************************************/
+function lesson_calculate_ongoing_score($lesson, $USER) {
+// this calculates and prints the ongoing score for students
+
+       // get the number of retries
+    if (!$retries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id)) {
+               $retries = 0;
+       }
+
+       if (!$lesson->custom) {
+               $ncorrect = 0;                                          
+               if ($pagesanswered = get_records_select("lesson_attempts",  "lessonid = $lesson->id AND 
+                               userid = $USER->id 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
+               
+               $output->correct = $ncorrect;
+               $output->viewed = $nviewed;
+               print_simple_box(get_string("ongoingnormal", "lesson", $output), "center");
+
+       } else {
+               $score = 0;
+               $currenthigh = 0;
+               if ($useranswers = get_records_select("lesson_attempts",  "lessonid = $lesson->id AND 
+                               userid = $USER->id AND retry = $retries", "timeseen")) {
+
+                       foreach ($useranswers as $useranswer) {
+                               if (@!array_key_exists($useranswer->pageid, $temp)) {
+                                       $temp[$useranswer->pageid] = array($useranswer->answerid, 1);
+                               } else {
+                                       if ($temp[$useranswer->pageid][1] < $lesson->maxattempts) {
+                                               $n = $temp[$useranswer->pageid][1] + 1;
+                                               $temp[$useranswer->pageid] = array($useranswer->answerid, $n);
+                                       }
+                               }
+                       }
+                       if ($answervalues = get_records_select("lesson_answers",  "lessonid = $lesson->id")) {
+                               if ($pages = get_records_select("lesson_pages", "lessonid = $lesson->id")) {
+                                       foreach ($pages as $page) {
+                                               $questions[$page->id] = $page->qtype;
+                                       }
+                               } else {
+                                       $questions = array();
+                               }
+                               $currenthighscore = array();
+                               foreach ($answervalues as $answervalue) {
+                                       if (array_key_exists($answervalue->pageid, $temp)) {
+                                               if ($temp[$answervalue->pageid][0] == $answervalue->id && $questions[$answervalue->pageid] != LESSON_ESSAY) {
+                                                       $score = $score + $answervalue->score;
+                                                       if (isset($currenthighscore[$answervalue->pageid])) {
+                                                               if ($currenthighscore[$answervalue->pageid] < $answervalue->score) {
+                                                                       $currenthighscore[$answervalue->pageid] = $answervalue->score;
+                                                               }
+                                                       } else {
+                                                               $currenthighscore[$answervalue->pageid] = $answervalue->score;
+                                                       }
+                                               } elseif ($questions[$answervalue->pageid] != LESSON_ESSAY) {
+                                                       if (isset($currenthighscore[$answervalue->pageid])) {
+                                                               if ($currenthighscore[$answervalue->pageid] < $answervalue->score) {
+                                                                       $currenthighscore[$answervalue->pageid] = $answervalue->score;
+                                                               }
+                                                       } else {
+                                                               $currenthighscore[$answervalue->pageid] = $answervalue->score;
+                                                       }
+                                               }
+                                       }
+                               }
+                               // add up the current high score
+                               foreach ($currenthighscore as $value) {
+                                       $currenthigh += $value;
+                               }
+                       } else {
+                               error("Error: Could not find answers!");
+                       }
+               }
+               if ($score > $lesson->grade) {
+                       $score = $lesson->grade;
+               } elseif ($score < 0) {
+                       $score = 0;
+               }
+               
+               $ongoingoutput->grade = $lesson->grade;
+               $ongoingoutput->score = $score;
+               $ongoingoutput->currenthigh = $currenthigh;
+               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 .= "<b>$label</b>";
+                       $output .= "<input type=\"hidden\" name=\"qtype\" value=\"$value\"> \n";
+               } else {
+                       $output .= "<a onClick=\"$onclick\" href=\"$link"."&qtype=$value\">$label</a>";
+               }
+               if ($label != end($qtypes)) {
+                       $output .= " | ";
+               }
+       }
+       echo $output;
+}
+
+/*******************************************************************/
+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;
+}
+/// CDC-FLAG ///
+
+?>
\ No newline at end of file
index ead3e6ef42219f0c958c07017b17a8b30ed42a20..a1f4f2077229a34e7c46d23835dba9647949dea6 100644 (file)
@@ -1,9 +1,17 @@
 <!-- define a new instance of lesson -->
 <!-- It is used from /course/mod.php.  The whole instance is available as $form. -->
 <?php
-
-    require_once("$CFG->dirroot/mod/lesson/lib.php");  // for parameter array
-    $nohtmleditorneeded = true;
+require_once("styles.php");
+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;
+                       }
+               }
+       }
+}
 
 // set the defaults
     if (empty($form->name)) {
         $form->maxanswers = 4;
     }
     if (!isset($form->maxattempts)) {
-        $form->maxattempts = 5;
+        $form->maxattempts = 1;
     }
     if (!isset($form->nextpagedefault)) {
-        $form->nextpagedefault = 0;
+        $form->nextpagedefault = 1;
     }
     if (!isset($form->minquestions)) {
         $form->minquestions = 0;
         $form->maxpages = 0;
     }
     if (!isset($form->retake)) {
-        $form->retake = 1;
+        $form->retake = 0;
     }
     if (!isset($form->available)) {
         $form->available = 0;
     }
     if (!isset($form->deadline)) {
-        $form->deadline = 0;
+               $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)) {
+        $form->usepassword = 1;
+    }
+    if (!isset($form->custom)) {
+        $form->custom = 1;
+    }
+    if (!isset($form->ongoing)) {
+        $form->ongoing = 1;
+    }
+    if (!isset($form->timed)) {
+        $form->timed = 1;
+    }
+    if (!isset($form->maxtime)) {
+        $form->maxtime = 20;
+    }
+    if (!isset($form->tree)) {
+        $form->tree = 0;
+    }
+    if (!isset($form->slideshow)) {
+        $form->slideshow = 0;
+    }
+    if (!isset($form->width)) {
+        $form->width = 640;
+    }
+    if (!isset($form->height)) {
+        $form->height = 400;
+    }
+    if (!isset($form->bgcolor)) {
+        $form->bgcolor = "#FFFFFF";
+    }
+       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 = 1;
+       }
+       if (!isset($form->lessondefault)) {
+               $form->lessondefault = 0;
+       }
+       /// CDC-FLAG ///
 ?>
 
 <form name="form" method="post" action="<?php echo $ME ?>">
 <center>
-<table cellpadding="5">
-<tr valign="top">
-    <td align="right"><p><b><?php  print_string("name") ?>:</b></p></td>
+<table cellpadding=5>
+<tr valign=top>
+    <td align=right><p><b><?php  print_string("name") ?>:</b></p></td>
     <td>
-        <input type="text" name="name" size="30" value="<?php  p($form->name) ?>" />
+        <!-- //CDC hidden label added. --><label for="name" class="hidden-label">Name</label><input type="text" id="name" name="name" size=30 value="<?php  p($form->name) ?>">
     </td>
 </tr>
 
-<tr valign="top">
-    <td align="right"><p><b><?php  print_string("maximumgrade") ?>:</b></p></td>
+<!-- CDC-FLAG -->
+<tr>
+    <td align=right><p><b><?php  print_string("practice", "lesson"); ?>:</b></p></td>
+    <td>
+    <?PHP 
+        $options[0] = get_string("no"); $options[1] = get_string("yes");
+               choose_from_menu($options, "practice", $form->practice, "");
+        helpbutton("practice", get_string("practice", "lesson"), "lesson");
+    ?>
+    </td>
+</tr>
+
+<tr>
+    <td align=right><p><b><?php  print_string("usepassword", "lesson"); ?>:</b></p></td>
+    <td>
+    <?PHP 
+        $options[0] = get_string("no"); $options[1] = get_string("yes");
+               choose_from_menu($options, "usepassword", $form->usepassword, "");
+        helpbutton("usepassword", get_string("usepassword", "lesson"), "lesson");
+    ?>
+    </td>
+</tr>
+
+<tr>
+    <td align=right><p><b><?php  print_string("password", "lesson"); ?>:</b></p></td>
+    <td>
+        <input type="text" name="password" size=7 value=""> <?php echo " (".get_string("leavetokeep").")"; ?>
+               <?php helpbutton("password", get_string("password", "lesson"), "lesson"); ?>
+    </td>
+</tr>
+<!-- CDC-FLAG -->
+
+<tr valign=top>
+    <td align=right><p><b><?php  print_string("maximumgrade") ?>:</b></p></td>
     <td>
         <?php
         for ($i=100; $i>=0; $i--) {
     </td>
 </tr>
 
-<tr valign="top">
-    <td align="right"><p><b><?php  print_string("maximumnumberofanswersbranches", "lesson") ?>:</b></p></td>
+<!-- CDC-FLAG -->
+<tr>
+    <td align=right><p><b><?php  print_string("customscoring", "lesson"); ?>:</b></p></td>
+    <td>
+    <?PHP 
+        $options[0] = get_string("no"); $options[1] = get_string("yes");
+               choose_from_menu($options, "custom", $form->custom, "");
+        helpbutton("custom", get_string("customscoring", "lesson"), "lesson");
+    ?>
+    </td>
+</tr>
+
+<tr>
+    <td align=right><p><b><?php  print_string("ongoing", "lesson"); ?>:</b></p></td>
+    <td>
+    <?PHP 
+        $options[0] = get_string("no"); $options[1] = get_string("yes");
+               choose_from_menu($options, "ongoing", $form->ongoing, "");
+        helpbutton("ongoing", get_string("ongoing", "lesson"), "lesson");
+    ?>
+    </td>
+</tr>
+<!-- CDC-FLAG -->
+
+<tr valign=top>
+    <td align=right><p><b><?php  print_string("maximumnumberofanswersbranches", "lesson") ?>:</b></p></td>
     <td>
         <?php
-        for ($i=10; $i>1; $i--) {
+        for ($i=20; $i>1; $i--) {
             $numbers[$i] = $i;
         }
         choose_from_menu($numbers, "maxanswers", "$form->maxanswers", "");
     </td>
 </tr>
 
-<tr valign="top">
-    <td align="right"><p><b><?php  print_string("maximumnumberofattempts", "lesson") ?>:</b></p></td>
+<tr valign=top>
+    <td align=right><p><b><?php  print_string("maximumnumberofattempts", "lesson") ?>:</b></p></td>
     <td>
         <?php
         unset($numbers);
     </td>
 </tr>
 
+<!-- CDC-FLAG -->
 <tr>
-    <td align="right"><p><b><?php  print_string("actionaftercorrectanswer", "lesson") ?>:</b></p></td>
+    <td align=right><p><b><?php print_string("displayreview", "lesson"); ?>:</b></p></td>
     <td>
-    <?php 
+    <?PHP 
+        $options[0] = get_string("no"); $options[1] = get_string("yes");
+               choose_from_menu($options, "review", $form->review, "");
+        helpbutton("review", get_string("displayreview", "lesson"), "lesson");
+    ?>
+    </td>
+</tr>
+<!-- CDC-FLAG -->
+
+<tr>
+    <td align=right><p><b><?php  print_string("actionaftercorrectanswer", "lesson") ?>:</b></p></td>
+    <td>
+    <?PHP 
         choose_from_menu($LESSON_NEXTPAGE_ACTION, "nextpagedefault", $form->nextpagedefault, "");
         helpbutton("nextpageaction", get_string("actionaftercorrectanswer", "lesson"), "lesson");
     ?>
     </td>
 </tr>
 
-<tr valign="top">
-    <td align="right"><p><b><?php  print_string("minimumnumberofquestions", "lesson") ?>:</b></p></td>
+<tr valign=top>
+    <td align=right><p><b><?php  print_string("minimumnumberofquestions", "lesson") ?>:</b></p></td>
     <td>
         <?php
         unset($numbers);
     </td>
 </tr>
 
-<tr valign="top">
-    <td align="right"><p><b><?php  print_string("numberofpagestoshow", "lesson") ?>:</b></p></td>
+<tr valign=top>
+    <td align=right><p><b><?php  print_string("numberofpagestoshow", "lesson") ?>:</b></p></td>
     <td>
         <?php
         unset($numbers);
     </td>
 </tr>
 
+<!-- CDC-FLAG -->
 <tr>
-    <td align="right"><p><b><?php  print_string("canretake", "lesson", $course->student) ?>:</b></p></td>
+    <td align=right><p><b><?php print_string("timed", "lesson"); ?>:</b></p></td>
     <td>
-    <?php 
+    <?PHP 
+        $options[0] = get_string("no"); $options[1] = get_string("yes");
+               choose_from_menu($options, "timed", $form->timed, "");
+        helpbutton("timed", get_string("timed", "lesson"), "lesson");
+    ?>
+    </td>
+</tr>
+
+<tr>
+    <td align=right><p><b><?php print_string("maxtime", "lesson"); ?>:</b></p></td>
+    <td>
+        <input type="text" name="maxtime" maxlength="7" size=7 value="<?php  p($form->maxtime) ?>">
+               <?php helpbutton("maxtime", get_string("maxtime", "lesson"), "lesson"); ?>
+    </td>
+</tr>
+<!-- CDC-FLAG -->
+
+<tr>
+    <td align=right><p><b><?php  print_string("canretake", "lesson", $course->student) ?>:</b></p></td>
+    <td>
+    <?PHP 
         $options[0] = get_string("no"); $options[1] = get_string("yes");
         choose_from_menu($options, "retake", $form->retake, "");
         helpbutton("retake", get_string("canretake", "lesson", $course->student), "lesson");
 </tr>
 
 <tr>
-    <td align="right"><p><b><?php  print_string("handlingofretakes", "lesson") ?>:</b></p></td>
+    <td align=right><p><b><?php  print_string("handlingofretakes", "lesson") ?>:</b></p></td>
     <td>
-    <?php 
+    <?PHP 
         $options[0] = get_string("usemean", "lesson"); $options[1] = get_string("usemaximum", "lesson");
         choose_from_menu($options, "usemaxgrade", $form->usemaxgrade, "");
         helpbutton("handlingofretakes", get_string("handlingofretakes", "lesson"), "lesson");
     </td>
 </tr>
 
-<tr valign="top">
-    <td align="right"><p><b><?php  print_string("available", "lesson") ?>:</b></td>
+<!-- CDC-FLAG -->
+<tr>
+    <td align=right><p><b><?php print_string("treeview", "lesson"); ?>:</b></p></td>
+    <td>
+    <?PHP 
+        $options[0] = get_string("no"); $options[1] = get_string("yes");
+               choose_from_menu($options, "tree", $form->tree, "");
+        helpbutton("tree", get_string("treeview", "lesson"), "lesson");
+    ?>
+    </td>
+</tr>
+
+<tr>
+    <td align=right><p><b><?php print_string("slideshow", "lesson"); ?>:</b></p></td>
+    <td>
+    <?PHP 
+        $options[0] = get_string("no"); $options[1] = get_string("yes");
+               choose_from_menu($options, "slideshow", $form->slideshow, "");
+        helpbutton("slideshow", get_string("slideshow", "lesson"), "lesson");
+    ?>
+    </td>
+</tr>
+
+<tr>
+    <td align=right><p><b><?php print_string("slideshowwidth", "lesson"); ?>:</b></p></td>
+    <td>
+        <input type="text" name="width" maxlength="7" size=7 value="<?php  p($form->width) ?>">px
+               <?php helpbutton("width", get_string("slideshowwidth", "lesson"), "lesson"); ?>
+    </td>
+</tr>
+
+<tr>
+    <td align=right><p><b><?php print_string("slideshowheight", "lesson"); ?>:</b></p></td>
+    <td>
+        <input type="text" name="height" maxlength="7" size=7 value="<?php  p($form->height) ?>">px
+               <?php helpbutton("height", get_string("slideshowheight", "lesson"), "lesson"); ?>
+    </td>
+</tr>
+
+<tr>
+    <td align=right><p><b><?php print_string("slideshowbgcolor", "lesson"); ?>:</b></p></td>
+    <td>
+        <input type="text" name="bgcolor" maxlength="7" size=7 value="<?php  p($form->bgcolor) ?>">
+               <?php helpbutton("bgcolor", get_string("slideshowbgcolor", "lesson"), "lesson"); ?>
+
+    </td>
+</tr>
+
+<tr>
+    <td align=right><p><b><?php  print_string("displayleftmenu", "lesson"); ?>:</b></p></td>
+    <td>
+    <?PHP 
+        $options[0] = get_string("no"); $options[1] = get_string("yes");
+               choose_from_menu($options, "displayleft", $form->displayleft, "");
+        helpbutton("displayleft", get_string("displayleftmenu", "lesson"), "lesson");
+    ?>
+    </td>
+</tr>
+
+<tr>
+    <td align=right><p><b><?php print_string("displayhighscores", "lesson"); ?>:</b></p></td>
+    <td>
+    <?PHP 
+        $options[0] = get_string("no"); $options[1] = get_string("yes");
+               choose_from_menu($options, "highscores", $form->highscores, "");
+        helpbutton("highscores", get_string("displayhighscores", "lesson"), "lesson");
+    ?>
+    </td>
+</tr>
+
+<tr>
+    <td align=right><p><b><?php print_string("maxhighscores", "lesson"); ?>:</b></p></td>
+    <td>
+        <input type="text" name="maxhighscores" maxlength="7" size=7 value="<?php  p($form->maxhighscores) ?>">
+               <?php helpbutton("maxhighscores", get_string("maxhighscores", "lesson"), "lesson"); ?>
+    </td>
+</tr>
+<!-- CDC-FLAG -->
+
+<tr valign=top>
+    <td align=right><p><b><?php  print_string("available", "lesson") ?>:</b></td>
     <td><?php
            print_date_selector("availableday", "availablemonth", "availableyear", $form->available);
            echo "&nbsp;-&nbsp;";
     ?></td>
 </tr>
 
-<tr valign="top">
-    <td align="right"><p><b><?php  print_string("deadline", "lesson") ?>:</b></td>
+<tr valign=top>
+    <td align=right><p><b><?php  print_string("deadline", "lesson") ?>:</b></td>
     <td><?php
            print_date_selector("deadlineday", "deadlinemonth", "deadlineyear", $form->deadline);
            echo "&nbsp;-&nbsp;";
-           print_time_selector("deadlinehour", "deadlineminute", $form->deadline);
+                  print_time_selector("deadlinehour", "deadlineminute", $form->deadline);
     ?></td>
 </tr>
 
+<tr>
+    <td align=right><p><b><?php print_string("lessondefault", "lesson"); ?>:</b></p></td>
+    <td>
+    <?PHP 
+        $options[0] = get_string("no"); $options[1] = get_string("yes");
+               choose_from_menu($options, "lessondefault", $form->lessondefault, "");
+        helpbutton("lessondefault", get_string("lessondefault", "lesson"), "lesson");
+    ?>
+    </td>
+</tr>
+
 </table>
 <!-- These hidden variables are always the same -->
-<input type="hidden" name="course"        value="<?php  p($form->course) ?>" />
-<input type="hidden" name="coursemodule"  value="<?php  p($form->coursemodule) ?>" />
-<input type="hidden" name="section"       value="<?php  p($form->section) ?>" />
-<input type="hidden" name="module"        value="<?php  p($form->module) ?>" />
-<input type="hidden" name="modulename"    value="<?php  p($form->modulename) ?>" />
-<input type="hidden" name="instance"      value="<?php  p($form->instance) ?>" />
-<input type="hidden" name="mode"          value="<?php  p($form->mode) ?>" />
-<input type="submit" value="<?php  print_string("savechanges") ?>" />
+<input type="hidden" name=course        value="<?php  p($form->course) ?>">
+<input type="hidden" name=coursemodule  value="<?php  p($form->coursemodule) ?>">
+<input type="hidden" name=section       value="<?php  p($form->section) ?>">
+<input type="hidden" name=module        value="<?php  p($form->module) ?>">
+<input type="hidden" name=modulename    value="<?php  p($form->modulename) ?>">
+<input type="hidden" name=instance      value="<?php  p($form->instance) ?>">
+<input type="hidden" name=mode          value="<?php  p($form->mode) ?>">
+<input type="submit" value="<?php  print_string("savechanges") ?>">
 </center>
 </form>
diff --git a/mod/lesson/reformat.php b/mod/lesson/reformat.php
new file mode 100644 (file)
index 0000000..4a4f8b4
--- /dev/null
@@ -0,0 +1,177 @@
+<?php 
+// jjg7:8/9/2004
+function removedoublecr($filename) {
+// This function will adjust a file in roughly Aiken style by replacing extra newlines with <BR> 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])."<br>\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
+       }
+}
+
+// jjg7:8/9/2004
+function importmodifiedaikenstyle($filename) {
+// This function converts from Brusca style to Aiken
+       $lines = file($filename);
+       $answer_found = 0;
+       $responses = 0;
+       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];
+                       }
+               }
+
+               $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";
+                       }
+
+               
+                       $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";
+                                       }
+
+                                       // 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
+
+       // 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
index 5c8149fc4c03b2ccc749c12440e046e96d4e44ea..c19399a130170f6a9e8e70440afc5ad79ffbc19f 100644 (file)
@@ -1,4 +1,4 @@
-<?php //$Id$
+<?PHP //$Id$
     //This php script contains all the stuff to backup/restore
     //lesson mods
 
@@ -67,7 +67,7 @@
             $newid = insert_record("lesson", $lesson);
 
             //Do some output     
-            echo "<ul><li>".get_string("modulename","lesson")." \"".$lesson->name."\"<br />";
+            echo "<ul><li>".get_string("modulename","lesson")." \"".$lesson->name."\"<br>";
             backup_flush(300);
 
             if ($newid) {
             if (($i+1) % 10 == 0) {
                 echo ".";
                 if (($i+1) % 200 == 0) {
-                    echo "<br />";
+                    echo "<br>";
                 }
                 backup_flush(300);
             }
                 if (($i+1) % 10 == 0) {
                     echo ".";
                     if (($i+1) % 200 == 0) {
-                        echo "<br />";
+                        echo "<br>";
                     }
                     backup_flush(300);
                 }
                 if (($i+1) % 50 == 0) {
                     echo ".";
                     if (($i+1) % 1000 == 0) {
-                        echo "<br />";
+                        echo "<br>";
                     }
                     backup_flush(300);
                 }
                 if (($i+1) % 50 == 0) {
                     echo ".";
                     if (($i+1) % 1000 == 0) {
-                        echo "<br />";
+                        echo "<br>";
                     }
                     backup_flush(300);
                 }
             }
             break;
         default:
-            echo "action (".$log->module."-".$log->action.") unknow. Not restored<br />";                 //Debug
+            echo "action (".$log->module."-".$log->action.") unknow. Not restored<br>";                 //Debug
             break;
         }
 
diff --git a/mod/lesson/styles.php b/mod/lesson/styles.php
new file mode 100644 (file)
index 0000000..74b29d4
--- /dev/null
@@ -0,0 +1,64 @@
+<style type="text/css">
+
+img {
+       border:0;
+}
+
+.hidden-label {
+       display: none;
+}
+
+.footer {
+  background-image: url(<?PHP echo "$themeurl"?>/footer.jpg);
+  color: <?PHP echo $THEME->body?>;
+  padding-top:40px; margin-top:40px;
+}
+.footer a:link, .footer v:link, .footer a:visited { 
+       color: <?PHP echo $THEME->body?>; 
+}
+
+.leftmenu { <?php //in view.php in lesson mod ?>
+       width:140px;
+       height:530px;
+       margin-top:-18px;
+       white-space:nowrap;
+}
+
+.leftmenu1 { <?php //in lesson.php in lesson mod ?>
+       background: no-repeat url(<?PHP echo "$themeurl"?>/leftmenu.jpg); 
+       width:140px;
+       height:530px;
+       margin-top:-6px;
+
+       white-space:nowrap;
+}
+
+.lmlinks {
+       width:140px;
+       height:400px;
+       overflow:auto;
+       <?php //white-space:nowrap; ?>
+       padding-left:7px;
+       padding-top:4px;
+       
+}
+
+
+.leftmenu a:link, .leftmenu a:active, .leftmenu a:visited, .leftmenu1 a:link, .leftmenu1 a:active, .leftmenu1 a:visited{
+font-size:.7em; 
+}
+
+.lmMainlinks a:link, .lmMainlinks a:active, .lmMainlinks a:visited{
+font-size:.9em; 
+}
+
+.slidepos {
+padding-left:153px; margin-top:-480px;
+ font-family:Arial;
+}
+
+.viewpos {
+}
+
+</style>
diff --git a/mod/lesson/timer.js b/mod/lesson/timer.js
new file mode 100644 (file)
index 0000000..9746dee
--- /dev/null
@@ -0,0 +1,104 @@
+/*/////////////////////////////////////////////////////////
+// This code is based off of
+// "Live Clock Lite" script - Version 1.0
+// By Mark Plachetta (astroboy@zip.com.au)
+//
+// The original script displayed a clock.
+// 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 "<script language=\"javascript\">\n";
+//             echo "var starttime = ". $timer->starttime . ";\n";
+//             echo "var servertime = ". time() . ";\n";
+//             echo "var testlength = ". $lesson->maxtime * 60 .";\n";
+//             echo "document.write('<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"liveclock_lite.js\"><\/SCRIPT>');\n";
+//             echo "window.onload = function () { show_clock(); }";
+//     echo "</script>\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 dn = ""; var old = "";
+
+       if (document.all||document.getElementById) { document.write('<span id="LiveClockIE" style="width:'+mywidth+'px; background-color:'+myback_color+'"></span>'); }
+       else if (document.layers) { document.write('<ilayer bgColor="'+myback_color+'" id="ClockPosNS"><layer width="'+mywidth+'" id="LiveClockNS"></layer></ilayer>'); }
+       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)
+                document.ClockPosNS.visibility="show"
+               if (old == "die") { return; }
+
+               currentDate = new Date();
+               current = currentDate.getTime();
+               current = Math.floor(current/1000);
+               
+               if (current > starttime + testlength) {
+                       myclock = '';
+                       myclock += '<font style="color:'+myfont_color+'; font-family:'+myfont_face+'; font-size:'+myfont_size+'pt;">';
+                       myclock += "Time is up";
+                       myclock += '</font>';
+                       stopclock = 1;
+               } else {
+                       timeleft = starttime + testlength - current;
+                       hours = Math.floor(timeleft/(60*60));
+                       minutes = Math.floor((timeleft-hours*60)/60);
+                       secs = Math.floor((timeleft-hours*60*60-minutes*60));
+                       
+                       if (secs < 10) {
+                               secs = "0"+secs;
+                       }
+                       
+                       myclock = '';
+                       myclock += '<font style="color:'+myfont_color+'; font-family:'+myfont_face+'; font-size:'+myfont_size+'pt;">';
+                       myclock += "Time remaining: ";
+                       if (hours > 0) {
+                               myclock += hours+":";
+                       }
+                       myclock += minutes+":"+secs;
+                       myclock += '</font>';
+               }
+               
+               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 (stopclock == 0) {
+                       setTimeout("show_clock()",1000);
+               }
+}
+
index 96249faf88b2bd34681e9e8112bf1d6acbd95c9e..64633ebdf38d1e1aefeec8f6de56746cfa944c22 100644 (file)
@@ -1,12 +1,12 @@
-<?php // $Id$
+<?PHP // $Id$
 
 /////////////////////////////////////////////////////////////////////////////////
 ///  Code fragment to define the version of lesson
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2004060400;  // The current module version (Date: YYYYMMDDXX)
-$module->requires = 2004052505;  // Requires this Moodle version
+$module->version  = 2004081700;  // The current module version (Date: YYYYMMDDXX)
+$module->requires = 2004013101;  // Requires this Moodle version
 $module->cron     = 0;           // Period for cron to check this module (secs)
 
 ?>
index 3cc2dcc22c3e2b49fffca3f4d7d3a7a8caee0859..6ac444f96bb066d3350e0253403f917f4b0451b7 100644 (file)
@@ -1,11 +1,12 @@
-<?php  // $Id$
+<?PHP  // $Id$
 
 /// This page prints a particular instance of lesson
 /// (Replace lesson with the name of your module)
 
     require_once("../../config.php");
-    require_once("lib.php");
-
+       require_once("locallib.php");
+       require_once("styles.php");
+       
     require_variable($id);    // Course Module ID
     optional_variable($pageid);    // Lesson Page ID
 
 
 /// Print the page header
 
+    if ($course->category) {
+        $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
+    }
+
     $strlessons = get_string("modulenameplural", "lesson");
     $strlesson  = get_string("modulename", "lesson");
+       
+       /// CDC-FLAG moved the action up because I needed to know what the action will be before the header is printed
+       if (empty($action)) {
+        if (isteacher($course->id)) {
+            $action = 'teacherview';
+               } elseif  (time() < $lesson->available) {
+                       print_header("$course->shortname: $lesson->name", "$course->fullname",
+                                                "$navigation <A HREF=index.php?id=$course->id>$strlessons</A> -> <a href=\"view.php?id=$cm->id\">$lesson->name</a>", 
+                                                 "", "", true, "", navmenu($course, $cm));
+                       print_simple_box_start("center");
+                       echo "<div align=\"center\">";
+                       echo get_string("lessonopen", "lesson", userdate($lesson->available))."<br>";
+                       echo "<a href=\"../../course/view.php?id=$course->id\">".get_string("returnmainmenu", "lesson")."</a>";
+                       echo "</div>";
+                       print_simple_box_end();
+                   print_footer($course);
+                       exit();
+               } elseif (time() > $lesson->deadline) {
+                       print_header("$course->shortname: $lesson->name", "$course->fullname",
+                                                "$navigation <A HREF=index.php?id=$course->id>$strlessons</A> -> <a href=\"view.php?id=$cm->id\">$lesson->name</a>", 
+                                                 "", "", true, "", navmenu($course, $cm));
+                       print_simple_box_start("center");
+                       echo "<div align=\"center\">";
+                       echo get_string("lessonclosed", "lesson", userdate($lesson->deadline))."<br>";
+                       echo "<a href=\"../../course/view.php?id=$course->id\">".get_string("returnmainmenu", "lesson")."</a>";                 
+                       echo "</div>";
+                       print_simple_box_end();
+                   print_footer($course);
+                       exit();
+               } elseif ($lesson->highscores) {
+                       $action = 'highscores';
+        } else {
+            $action = 'navigation';
+        }
+    } 
+
+       /// CDC-FLAG changed the update_module_button and added another button when a teacher is checking the navigation of the lesson
+    if (isteacheredit($course->id)) {
+               $button = "<table><tr><td>";
+        $button .= "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/mod.php\">".
+               "<input type=\"hidden\" name=\"update\" value=\"$cm->id\" />".
+               "<input type=\"hidden\" name=\"return\" value=\"true\" />".
+               "<input type=\"submit\" value=\"".get_string("editlessonsettings", "lesson")."\" /></form>";
+               if ($action == "navigation" && $pageid != LESSON_EOL) {
+                       $button .= "</td><td>".
+                                  "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/mod/lesson/lesson.php\">".
+                                  "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />".
+                                  "<input type=\"hidden\" name=\"action\" value=\"editpage\" />".
+                                  "<input type=\"hidden\" name=\"pageid\" value=\"$pageid\" />".                          
+                                  "<input type=\"submit\" value=\"".get_string("editpagecontent", "lesson")."\" /></form>";
+               }
+               $button .= "</td></tr></table>";
+       } else {
+               $button = "";
+       }
 
-    print_header_simple("$lesson->name", "",
-                 "<a href=index.php?id=$course->id>$strlessons</a> -> <a href=\"view.php?id=$cm->id\">$lesson->name</a>",
-                  "", "", true, update_module_button($cm->id, $course->id, $strlesson),
+    print_header("$course->shortname: $lesson->name", "$course->fullname",
+                 "$navigation <A HREF=index.php?id=$course->id>$strlessons</A> -> <a href=\"view.php?id=$cm->id\">$lesson->name</a>", 
+                  "", "", true, $button, // took out update_module_button($cm->id, $course->id, $strlesson) and replaced it with $button
                   navmenu($course, $cm));
 
     // set up some general variables
     } else {
         $pixpath = "$path/../theme/$CFG->theme/pix";
     }
-
-    if (empty($action)) {
-        if (isteacher($course->id)) {
-            $action = 'teacherview';
-        } else {
-            $action = 'navigation';
-        }
-    }
-
+                               
     /************** navigation **************************************/
     if ($action == 'navigation') {
+               //CDC Chris Berri added this echo call for left menu.  must match that in lesson.php for styles
+               if ($lesson->displayleft) {
+                       echo '<div class="leftmenu">';
+                          if($page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) {
+                                               // print the pages
+                                               echo "<form name=\"lessonpages2\" method=\"post\" action=\"view.php\">";
+                                               echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">";
+                                               echo "<input type=\"hidden\" name=\"action\" value=\"navigation\">";
+                                               echo "<input type=\"hidden\" name=\"pageid\">";
+                                                               echo "<div class='lmlinks'><table bgcolor=\"$THEME->cellheading\"><tr></tr>";
+                                                               echo "<tr><td class='lmheading'>".get_string("lessonmenu", "lesson")."</td></tr><br>";
+                                                               echo "<tr><td class='lmMainlinks'>";
+                                                               echo "<a href=\"../../course/view.php?id=$course->id\">".get_string("mainmenu", "lesson")."</a></td></tr>";
+                                                               echo "<td>";
+                                                               lesson_print_tree_menu($lesson->id, $page->id, $cm->id);
+                                                               echo "</td></tr></table></div>"; //close lmlinks
+                                               echo"</form>";
+                                       }
+                       echo   "</div>"; //close left menu
+                       echo "<div class='slidepos'>"; //CDC chris berri for styles
+               } elseif ($lesson->slideshow) {
+                       echo "<table align=\"center\"><tr><td>";
+               }
+
+               /// CDC-FLAG /// password protected lesson code
+               if ($lesson->usepassword) {
+                       $correctpass = false;
+                       if (isset($_POST['userpassword'])) {
+                               if ($lesson->password == md5(trim($_POST['userpassword']))) {
+                                       $USER->lessonloggedin[$lesson->id] = true;
+                                       $correctpass = true;
+                               }
+                       } elseif (isset($USER->lessonloggedin[$lesson->id])) {
+                               $correctpass = true;
+                       }
+
+                       if (!$correctpass) {
+                               print_simple_box_start("center");
+                               echo "<form name=\"password\" method=\"post\" action=\"view.php\">\n";
+                               echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">\n";
+                               echo "<input type=\"hidden\" name=\"action\" value=\"navigation\">\n";
+                               echo "<table cellpadding=\"7px\">";
+                               if (isset($_POST['userpassword'])) {
+                                       echo "<tr align=\"center\" style='color:#DF041E;'><td>".get_string("loginfail", "lesson")."</td></tr>";
+                               }
+                               echo "<tr align=\"center\"><td>".get_string("passwordprotectedlesson", "lesson", $lesson->name)."</td></tr>";
+                               echo "<tr align=\"center\"><td>".get_string("enterpassword", "lesson")." <input type=\"password\" name=\"userpassword\"></td></tr>";
+                                               
+                               echo "<tr align=\"center\"><td>";
+                               echo "<input type=\"button\" value=\"".get_string("cancel", "lesson")."\" onclick=\"parent.location='../../course/view.php?id=$course->id';\">  ";
+                               echo "<input type=\"button\" value=\"".get_string("continue", "lesson")."\" onclick=\"document.password.submit();\">";
+                               echo "</td></tr></table>";
+                               print_simple_box_end();
+                               exit();
+                       }
+               }
+       
+               /// CDC-FLAG /// Slideshow styles
+               if($lesson->slideshow) { 
+                       //echo "<div class=\"slidepos\">\n";//CDC Chris Berri.  add the left menu theme stuff here.  must match on lesson.php
+                       echo "<div style=\"
+                                       background-color: $lesson->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";
+               }
+               // this is called if a student leaves during a lesson
+               if($pageid == LESSON_UNSEENBRANCHPAGE) {
+                               $pageid = lesson_unseen_question_jump($lesson->id, $USER->id, $pageid);
+               }
+               /// CDC-FLAG ///                
+                               
+               /// 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 "<div align=\"center\"><table><tr><td align=\"center\">".get_string("teacherjumpwarning", "lesson", $warningvars)."</td></tr></table></div>";
+                       }
+               }               
+               /// CDC-FLAG ///
+               
         // display individual pages and their sets of answers
         // if pageid is EOL then the end of the lesson has been reached
-        print_heading($lesson->name);
-        if (empty($pageid)) {
+                       // for flow, changed to simple echo for flow styles, michaelp, moved lesson name and page title down
+          //print_heading($lesson->name);
+       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
-            if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND userid = $USER->id",
+                       if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND userid = $USER->id",
                         "grade DESC")) {
                 $retries = count($grades);
             } else {
                 print_heading(get_string("attempt", "lesson", $retries + 1));
             }
             // 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
+            if ($attempts = get_records_select("lesson_attempts", 
+                        "lessonid = $lesson->id AND userid = $USER->id AND retry = $retries AND 
                         correct = 1", "timeseen DESC")) {
                 // get the first page
                 if (!$firstpageid = get_field("lesson_pages", "id", "lessonid", $lesson->id,
                     if ($jumpto == 0) { // unlikely value!
                         $lastpageseen = $attempt->pageid;
                     } elseif ($jumpto == LESSON_NEXTPAGE) {
-                        if (!$lastpageseen = get_field("lesson_pages", "nextpageid", "id",
+                        if (!$lastpageseen = get_field("lesson_pages", "nextpageid", "id", 
                                     $attempt->pageid)) {
                             // no nextpage go to end of lesson
                             $lastpageseen = LESSON_EOL;
                     } else {
                         $lastpageseen = $jumpto;
                     }
-                    break; // only look at the latest correct attempt
+                    break; // only look at the latest correct attempt 
                 }
-                if ($lastpageseen != $firstpageid) {
-                    echo "<form name=\"queryform\" method =\"post\" action=\"view.php\">\n";
-                    echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
-                    echo "<input type=\"hidden\" name=\"action\" value=\"navigation\" />\n";
-                    echo "<input type=\"hidden\" name=\"pageid\" />\n";
-                    print_simple_box("<p align=\"center\">".get_string("youhaveseen","lesson")."</p>",
-                            "center");
-                    echo "<p align=\"center\"><input type=\"button\" value=\"".get_string("yes").
-                        "\" onclick=\"document.queryform.pageid.value='$lastpageseen';document.queryform.submit();\">&nbsp;&nbsp;&nbsp;<input type=\"button\" value=\"".get_string("no").
-                        "\" onclick=\"document.queryform.pageid.value='$firstpageid';document.queryform.submit();\" /></p>\n";
-                    echo "</form>\n";
+                //if ($lastpageseen != $firstpageid) {
+                               if (count_records("lesson_attempts", "lessonid", $lesson->id, "userid", $USER->id, "retry", $retries) > 0) {
+                                       /// CDC-FLAG ///
+                                       if ($lesson->timed) {
+                                               if ($lesson->retake) {
+                                                       echo "<form name=\"queryform\" method =\"post\" action=\"view.php\">\n";
+                                                       echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">\n";
+                                                       echo "<input type=\"hidden\" name=\"action\" value=\"navigation\">\n";
+                                                       echo "<input type=\"hidden\" name=\"pageid\">\n";
+                                                       echo "<input type=\"hidden\" name=\"startlastseen\">\n";  /// CDC-FLAG added this line
+                                                       print_simple_box("<p align=\"center\">".get_string("leftduringtimed", "lesson")."</p>", "center");
+                                                       echo "<p align=\"center\"><input type=\"button\" value=\"".get_string("continue", "lesson").
+                                                               "\" onclick=\"document.queryform.pageid.value='$firstpageid';document.queryform.startlastseen.value='no';document.queryform.submit();\"></p>\n";  /// CDC-FLAG added document.queryform.startlastseen.value='yes'
+                                                       echo "</form>\n"; echo "</div></div>";///CDC Chris Berri added close div tag
+                                               } else {
+                                                       print_simple_box_start("center");
+                                                       echo "<div align=\"center\">";
+                                                       echo get_string("leftduringtimednoretake", "lesson");
+                                                       echo "<br><br><a href=\"../../course/view.php?id=$course->id\">".get_string("returntocourse", "lesson")."</a>";
+                                                       echo "</div>";
+                                                       print_simple_box_end();
+                                               }
+                                       } else {
+                                               echo "<form name=\"queryform\" method =\"post\" action=\"view.php\">\n";
+                                               echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">\n";
+                                               echo "<input type=\"hidden\" name=\"action\" value=\"navigation\">\n";
+                                               echo "<input type=\"hidden\" name=\"pageid\">\n";
+                                               echo "<input type=\"hidden\" name=\"startlastseen\">\n";  /// CDC-FLAG added this line
+                                               print_simple_box("<p align=\"center\">".get_string("youhaveseen","lesson")."</p>",
+                                                               "center");
+                                               echo "<p align=\"center\"><input type=\"button\" value=\"".get_string("yes").
+                                                       "\" onclick=\"document.queryform.pageid.value='$lastpageseen';document.queryform.startlastseen.value='yes';document.queryform.submit();\">&nbsp;&nbsp;&nbsp;<input type=\"button\" value=\"".get_string("no").  /// CDC-FLAG 6/11/04 ///
+                                                       "\" onclick=\"document.queryform.pageid.value='$firstpageid';document.queryform.startlastseen.value='no';document.queryform.submit();\"></p>\n";  /// CDC-FLAG added document.queryform.startlastseen.value='yes'
+                                               echo "</form>\n"; echo "</div></div>";///CDC Chris Berri added close div tag
+                                       }
                     print_footer($course);
                     exit();
                 }
                     break;
                 }
                 if (!$lesson->retake) {
-                    redirect("../../course/view.php?id=$course->id", get_string("alreadytaken", "lesson"));
+                                       print_simple_box_start("center");
+                                       echo "<div align=\"center\">";
+                                       echo get_string("noretake", "lesson");
+                                       echo "<br><br><a href=\"../../course/view.php?id=$course->id\">".get_string("returntocourse", "lesson")."</a>";
+                                       echo "</div>";
+                                       print_simple_box_end();
+                                   print_footer($course);
+                                       exit();                                 
+                           //redirect("../../course/view.php?id=$course->id", get_string("alreadytaken", "lesson"));
                 // allow student to retake course even if they have the maximum grade
                 // } elseif ($bestgrade == 100) {
-                //     redirect("../../course/view.php?id=$course->id", get_string("maximumgradeachieved",
+                       //     redirect("../../course/view.php?id=$course->id", get_string("maximumgradeachieved",
                 //                 "lesson"));
                 }
             }
             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($lesson->timed && !isset($USER->startlesson[$lesson->id])) {
+                               unset($startlesson);
+                               $USER->startlesson[$lesson->id] = true;
+                               if($timeid = get_field("lesson_timer", "id", "lessonid", $lesson->id, "userid", $USER->id)) {
+                                       $startlesson->id = $timeid;
+                               }
+               
+                               $startlesson->lessonid = $lesson->id;
+                               $startlesson->userid = $USER->id;
+                               $startlesson->starttime = time();
+                               $startlesson->lessontime = time();
+                               
+                               if (!update_record("lesson_timer", $startlesson)) {
+                                       if (!insert_record("lesson_timer", $startlesson)) {
+                                               error("Error: could not insert row into lesson_timer table");
+                                       }
+                               }
+                       }
+                       /// CDC-FLAG ///                        
         }
         if ($pageid != LESSON_EOL) {
+                       /// CDC-FLAG /// 6/15/04 -- This is the code updates the lessontime for a timed test
+                       // NoticeFix
+                       if (isset($_POST["startlastseen"])) {  /// this deletes old records
+                               if ($_POST["startlastseen"] == "no") {
+                                       if ($grades = get_records_select("lesson_grades", "lessonid = $lesson->id AND userid = $USER->id",
+                                                               "grade DESC")) {
+                                               $retries = count($grades);
+                                       } else {
+                                               $retries = 0;
+                                       }
+                                       // NoticeFix  big fix on the two delete_records
+                                       if (!delete_records("lesson_attempts", "userid", $USER->id, "lessonid", $lesson->id, "retry", $retries)) {
+                                               error("Error: could not delete old attempts");
+                                       }
+                                       if (!delete_records("lesson_branch", "userid", $USER->id, "lessonid", $lesson->id, "retry", $retries)) {
+                                               error("Error: could not delete old seen branches");
+                                       }
+                               }
+                       }
+
+                       if($lesson->timed) {
+                               if(isteacher($course->id)) {
+                                       echo "<div align=\"center\"><table><tr><td align=\"center\">".get_string("teachertimerwarning", "lesson")."</td></tr></table></div>";
+                               } else {
+                                       if (isset($_POST["startlastseen"])) {
+                                               if ($_POST["startlastseen"] == "yes") {  // continue a previous test, need to update the clock  (think this option is disabled atm)
+                                                       // get time information for this user
+                                                       if (!$timer = get_record("lesson_timer", "lessonid", $lesson->id, "userid", $USER->id)) {
+                                                               error("Error: could not find record");
+                                                       }
+       
+                                                       unset($continuelesson);
+                                                       $continuelesson->id = $timer->id;
+                                                       $continuelesson->starttime = time() - ($timer->lessontime - $timer->starttime);
+                                                       $continuelesson->lessontime = time();
+                                                       if (!update_record("lesson_timer", $continuelesson)) {
+                                                               error("Error: could not update record in the lesson_timer table");
+                                                       }       
+                                               } elseif ($_POST["startlastseen"] == "no") {  // starting over
+                                                       // get time information for this user
+                                                       if (!$timer = get_record("lesson_timer", "lessonid", $lesson->id, "userid", $USER->id)) {
+                                                               error("Error: could not find record");
+                                                       }
+       
+                                                       // starting over, so reset the clock
+                                                       unset($startlesson);
+                                                       $startlesson->id = $timer->id;
+                                                       $startlesson->starttime = time();
+                                                       $startlesson->lessontime = time();
+                                                       
+                                                       if (!update_record("lesson_timer", $startlesson)) {
+                                                               error("Error: could not update record in the lesson_timer table");
+                                                       }
+                                               }
+                                       }
+                                       // get time information for this user
+                                       if (!$timer = get_record("lesson_timer", "lessonid", $lesson->id, "userid", $USER->id)) {
+                                               error("Error: could not find record");
+                                       }
+                                       if ((($timer->starttime + $lesson->maxtime * 60) - time()) > 0) {
+                                               // code for the clock
+                                               echo "<table align=\"right\"><tr><td>";
+                                               echo "<script language=\"javascript\">\n";
+                                                       echo "var starttime = ". $timer->starttime . ";\n";
+                                                       echo "var servertime = ". time() . ";\n";
+                                                       echo "var testlength = ". $lesson->maxtime * 60 .";\n";
+                                                       echo "document.write('<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"timer.js\"><\/SCRIPT>');\n";
+                                                       echo "window.onload = function () { show_clock(); }\n";
+                                               echo "</script>\n";
+                                               echo "</td></tr></table><br><br>";
+                                       } 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 "<div align=\"center\"><table><tr><td align=\"center\">".get_string("studentoneminwarning", "lesson").
+                                                        "</td></tr></table></div>";
+                                       }       
+                                                                       
+                                       unset($newtime);
+                                       $newtime->id = $timer->id;
+                                       $newtime->lessontime = time();
+                                       
+                                       if (!update_record("lesson_timer", $newtime)) {
+                                               error("Error: could not update lesson_timer table");
+                                       }
+                                       
+                                       // I dont like this... seems like there should be a better way...
+                                       if (!$firstpageid = get_field("lesson_pages", "id", "lessonid", $lesson->id,
+                            "prevpageid", 0)) {
+                       error("Navigation: first page not found");
+                       }
+                                       if ($pageid == $firstpageid) {
+                                               print_simple_box(get_string("maxtimewarning", "lesson", $lesson->maxtime), "center");
+                                       }
+
+                               }
+                       }
+                       /// CDC-FLAG ///
+                                               
             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");
             }
-            // before we output everything check to see if the page is a EOB, if so jump directly
+                       /// CDC-FLAG 6/21/04 /// - this only gets called when a user starts up a new lesson and the first page is a cluster page
+                       if ($page->qtype == LESSON_CLUSTER) {
+                               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");
+                                       }
+                               } else {
+                                       // get the next page
+                                       $pageid = $page->nextpageid;
+                                       if (!$page = get_record("lesson_pages", "id", $pageid)) {
+                                               error("Navigation: the page record not found");
+                                       }
+                               }
+                       } elseif ($page->qtype == LESSON_ENDOFCLUSTER) {
+                               if ($page->nextpageid == 0) {
+                                       $nextpageid = LESSON_EOL;
+                               } else {
+                                       $nextpageid = $page->nextpageid;
+                               }
+                               redirect("view.php?id=$cm->id&action=navigation&pageid=$nextpageid", get_string("endofclustertitle", "lesson"));
+                       }
+                       /// CDC-FLAG ///
+
+            // 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) {
                 if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) {
                     // print_heading(get_string("endofbranch", "lesson"));
                     foreach ($answers as $answer) {
                         // just need the first answer
+                                               /// CDC-FLAG 6/21/04 ///
+                                               if ($answer->jumpto == LESSON_RANDOMBRANCH) {
+                                                       $answer->jumpto = lesson_unseen_branch_jump($lesson->id, $USER->id);
+                                               } elseif ($answer->jumpto == LESSON_CLUSTERJUMP) {
+                                                       if (!isteacher($course->id)) {
+                                                               $answer->jumpto = lesson_cluster_jump($lesson->id, $USER->id, $pageid);
+                                                       } else {
+                                                               if ($page->nextpageid == 0) {  
+                                                                       $answer->jumpto = LESSON_EOL;
+                                                               } else {
+                                                                       $answer->jumpto = $page->nextpageid;
+                                                               }
+                                                       }
+                                               }
+                                               /// CDC-FLAG ///
                         redirect("view.php?id=$cm->id&action=navigation&pageid=$answer->jumpto",
                                 get_string("endofbranch", "lesson"));
                         break;
-                    }
+                    } 
                     print_footer($course);
                     exit();
                 } else {
                     error("Navigation: No answers on EOB");
                 }
             }
+
+                       /// CDC-FLAG 6/21/04 ///  this calculates the ongoing score
+                       if ($lesson->ongoing && !empty($pageid)) {
+                               if (isteacher($course->id)) {
+                                       echo "<div align=\"center\">".get_string("teacherongoingwarning", "lesson")."<br></div>";
+                               } else {
+                                       lesson_calculate_ongoing_score($lesson, $USER);
+                               }
+                       }
+                       /// CDC-FLAG ///
             // it's not a EOB process it...
-            echo "<table align=\"center\" width=\"80%\" border=\"0\"><tr><td>\n";
+                       /// CDC-FLAG ///
+                       if ($lesson->slideshow) {
+                   echo "<table align=\"center\" width=\"100%\" border=\"0\"><tr><td>\n";
+                       } else {
+                   echo "<table align=\"center\" width=\"80%\" border=\"0\"><tr><td>\n";
+                       }
+                       /// CDC-FLAG ///
             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
                     $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id);
-                    $nviewed = count_records("lesson_attempts", "lessonid", $lesson->id, "userid",
+                    $nviewed = count_records("lesson_attempts", "lessonid", $lesson->id, "userid", 
                             $USER->id, "retry", $ntries);
                     if ($nviewed) {
                         echo "<p align=\"center\">".get_string("numberofpagesviewed", "lesson", $nviewed).
                         }
                         echo get_string("numberofcorrectanswers", "lesson", $ncorrect)."<br />\n";
                         $thegrade = intval(100 * $ncorrect / $nviewed);
-                        echo get_string("yourcurrentgradeis", "lesson",
+                        echo get_string("yourcurrentgradeis", "lesson", 
                                 number_format($thegrade * $lesson->grade / 100, 1)).
                             " (".get_string("outof", "lesson", $lesson->grade).")</p>\n";
                     }
                 }
             }
-            print_heading($page->title);
-            print_simple_box(format_text($page->contents), 'center');
+          
+                       //print_heading($page->title);
+                       /// CDC-FLAG /// moved name and title down here for Flow style, michaelp
+                       echo "<div align=\"center\">";                  
+                       echo "<i><strong>";
+                       echo ($lesson->name) . "</strong></i>";
+                       echo "<br><br></div>";
+                       
+                       /// CDC-FLAG ///
+                       if ($lesson->slideshow) {
+                               echo "<table><tr><td>";
+               echo format_text($page->contents);
+                               echo "</td></tr></table>";
+                       } else {
+                               print_simple_box(format_text($page->contents), 'center');
+                       }
+                       /// CDC-FLAG ///
             echo "<br />\n";
             // get the answers in a set order, the id order
             if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) {
                 echo "<form name=\"answerform\" method =\"post\" action=\"lesson.php\">";
-                echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />";
-                echo "<input type=\"hidden\" name=\"action\" value=\"continue\" />";
-                echo "<input type=\"hidden\" name=\"pageid\" value=\"$pageid\" />";
-                print_simple_box_start("center");
+                echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">";
+                echo "<input type=\"hidden\" name=\"action\" value=\"continue\">";
+                echo "<input type=\"hidden\" name=\"pageid\" value=\"$pageid\">";
+                /// CDC-FLAG ///
+                               if (!$lesson->slideshow || $page->qtype != 20) {
+                                       print_simple_box_start("center");
+                               }
+                               /// CDC-FLAG ///
                 echo '<table width="100%">';
                 switch ($page->qtype) {
                     case LESSON_SHORTANSWER :
                     case LESSON_NUMERICAL :
                         echo "<tr><td align=\"center\">".get_string("youranswer", "lesson").
-                            ": <input type=\"text\" name=\"answer\" size=\"50\" maxlength=\"200\" />\n";
+                            ": <label for=\"answer\" class=\"hidden-label\">Answer</label><input type=\"text\" id=\"answer\" name=\"answer\" size=\"50\" maxlength=\"200\">\n"; //CDC hidden label added.
                         echo '</table>';
                         print_simple_box_end();
-                        echo "<p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
-                            get_string("pleaseenteryouranswerinthebox", "lesson")."\" /></p>\n";
+                                               if (!$lesson->slideshow) {
+                                                       echo "<p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                                                                get_string("pleaseenteryouranswerinthebox", "lesson")."\"></p>\n";
+                                               }
                         break;
                     case LESSON_TRUEFALSE :
                         shuffle($answers);
                         foreach ($answers as $answer) {
-                            echo "<tr><td>";
-                            echo "<input type=\"radio\" name=\"answerid\" value=\"{$answer->id}\" />";
-                            echo "</td><td>";
+                            echo "<tr><td valign=\"top\">";
+                            echo "<label for=\"answerid\" class=\"hidden-label\">Answer ID</label><input type=\"radio\" id=\"answerid\" name=\"answerid\" value=\"{$answer->id}\">"; //CDC hidden label added.
+                                                       echo "</td><td>";
                             $options->para = false; // no <p></p>
                             echo format_text(trim($answer->answer), FORMAT_MOODLE, $options);
                             echo "</td></tr>";
+                                                       if ($answer != end($answers)) {
+                                                               echo "<tr><td><br></td></tr>";                                                  
+                                                       } 
                         }
                         echo '</table>';
                         print_simple_box_end();
-                        echo "<p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
-                            get_string("pleasecheckoneanswer", "lesson")."\" /></p>\n";
+                                               if (!$lesson->slideshow) {
+                                                       echo "<p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                                                               get_string("pleasecheckoneanswer", "lesson")."\"></p>\n"; 
+                                               }
                         break;
                     case LESSON_MULTICHOICE :
                         $i = 0;
                         shuffle($answers);
                         foreach ($answers as $answer) {
-                            echo "<tr><td>";
+                            echo "<tr><td valign=\"top\">";
                             if ($page->qoption) {
-                                // more than one answer allowed
-                                echo "<input type=\"checkbox\" name=\"answer[$i]\" value=\"{$answer->id}\" />";
+                                // more than one answer allowed 
+                                echo "<label for=\"answer[$i]\" class=\"hidden-label\">answer[$i]</label><input type=\"checkbox\" id=\"answer[$i]\" name=\"answer[$i]\" value=\"{$answer->id}\">"; //CDC hidden label added.
                             } else {
                                 // only one answer allowed
-                                echo "<input type=\"radio\" name=\"answerid\" value=\"{$answer->id}\" />";
+                                echo "<label for=\"answerid\" class=\"hidden-label\">answer id</label><input type=\"radio\" id=\"answerid\" name=\"answerid\" value=\"{$answer->id}\">"; //CDC hidden label added.
                             }
                             echo "</td><td>";
                             $options->para = false; // no <p></p>
-                            echo format_text(trim($answer->answer), FORMAT_MOODLE, $options);
+                            echo format_text(trim($answer->answer), FORMAT_MOODLE, $options); 
                             echo "</td></tr>";
+                                                       if ($answer != end($answers)) {
+                                                               echo "<tr><td><br></td></tr>";                                                  
+                                                       } 
                             $i++;
                         }
                         echo '</table>';
                         print_simple_box_end();
-                        if ($page->qoption) {
-                            echo "<p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
-                                get_string("pleasecheckoneormoreanswers", "lesson")."\" /></p>\n";
-                        } else {
-                            echo "<p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
-                                get_string("pleasecheckoneanswer", "lesson")."\" /></p>\n";
-                        }
+                                               /// CDC-FLAG ///
+                                               if (!$lesson->slideshow) {
+                                                       if ($page->qoption) {
+                                                               echo "<p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                                                                       get_string("pleasecheckoneormoreanswers", "lesson")."\"></p>\n";
+                                                       } else {
+                                                               echo "<p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                                                                       get_string("pleasecheckoneanswer", "lesson")."\"></p>\n";
+                                                       }
+                                               }
+                                               /// CDC-FLAG ///
                         break;
-
+                        
+                    /// CDC-FLAG /// 6/14/04  --- changed how matching works    
                     case LESSON_MATCHING :
                         echo "<tr><td><table width=\"100%\">";
                         // don't suffle answers (could be an option??)
                         foreach ($answers as $answer) {
-                            // get all the responses
-                            $responses[] = trim($answer->response);
+                            // get all the response
+                                                       if ($answer->response != NULL) {
+                               $responses[] = trim($answer->response);
+                                                       }
                         }
                         shuffle($responses);
                         foreach ($answers as $answer) {
-                            echo "<tr><td align=\"right\">";
-                            echo "<b>$answer->answer: </b></td><td>";
-                            echo "<select name=\"response[$answer->id]\">";
-                            echo "<option value=\"0\" selected=\"selected\">Choose...</option>";
-                            foreach ($responses as $response) {
-                                echo "<option value=\"$response\">$response</option>";
-                            }
-                            echo "</select>";
-                            echo "</td></tr>";
-                        }
+                                                       if ($answer->response != NULL) {
+                                                               echo "<tr><td align=\"right\">";
+                                                               echo "<b>$answer->answer: </b></td><td valign=\"bottom\">";
+                                                               echo "<label for=\"response[$answer->id]\" class=\"hidden-label\">response[$answer->id]</label><select id=\"response[$answer->id]\" name=\"response[$answer->id]\">"; //CDC hidden label added.
+                                                               echo "<option value=\"0\" selected=\"selected\">Choose...</option>";
+                                                               foreach ($responses as $response) {
+                                                                       echo "<option value=\"$response\">$response</option>";
+                                                               }
+                                                               echo "</select>";
+                                                               echo "</td></tr>";
+                                                               if ($answer != end($answers)) {
+                                                                       echo "<tr><td><br></td></tr>";                                                  
+                                                               } 
+                                                       }
+                                               }
                         echo '</table></table>';
                         print_simple_box_end();
-                        echo "<p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
-                            get_string("pleasematchtheabovepairs", "lesson")."\" /></p>\n";
+                                               if (!$lesson->slideshow) {                                              
+                                                       echo "<p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                                                               get_string("pleasematchtheabovepairs", "lesson")."\"></p>\n";
+                                               }
                         break;
+                                       /// CDC-FLAG ///
 
                     case LESSON_BRANCHTABLE :
                         echo "<tr><td><table width=\"100%\">";
-                        echo "<input type=\"hidden\" name=\"jumpto\" />";
+                        echo "<input type=\"hidden\" name=\"jumpto\">";
                         // don't suffle answers
-                        foreach ($answers as $answer) {
-                            echo "<tr><td align=\"center\">";
-                            echo "<input type=\"button\" value=\"$answer->answer\"";
-                            echo "onclick=\"document.answerform.jumpto.value=$answer->jumpto;document.answerform.submit();\" />";
-                            echo "</td></tr>";
-                        }
-                        echo '</table></table>';
+                                               /// CDC-FLAG ///
+                                               if(!$lesson->slideshow) {
+                                                       foreach ($answers as $answer) {
+                                                               echo "<tr><td align=\"center\">";
+                                                               echo "<input type=\"button\" value=\"$answer->answer\"";
+                                                               echo "onclick=\"document.answerform.jumpto.value=$answer->jumpto;document.answerform.submit();\">";
+                                                               echo "</td></tr>";
+                                                       }
+                                               }
+                                               
+                                               /// CDC-FLAG ///
+                                               echo '</table></table>';
                         print_simple_box_end();
                         break;
-
+                                       case LESSON_ESSAY :
+                                               echo "<tr><td align=\"center\" valign=\"top\" nowrap>".get_string("youranswer", "lesson").":</td><td>".
+                                                        "<label for=\"answer\" class=\"hidden-label\">Answer</label><textarea id=\"answer\" name=\"answer\" rows=\"15\" cols=\"60\"></textarea>\n"; //CDC hidden label added.
+                                               echo "</td></tr></table>";
+                                               print_simple_box_end();
+                                               if (!$lesson->slideshow) {
+                                                       echo "<p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                                                                get_string("pleaseenteryouranswerinthebox", "lesson")."\"></p>\n";
+                                               }
+                                               break;
                 }
-                echo "</form>\n";
+                               /// CDC-FLAG ///
+                               if (!$lesson->slideshow) {
+                       echo "</form>\n"; 
+                               }
+                               /// CDC-FLAG ///
             } else {
                 // a page without answers - find the next (logical) page
                 echo "<form name=\"pageform\" method =\"post\" action=\"view.php\">\n";
-                echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
-                echo "<input type=\"hidden\" name=\"action\" value=\"navigation\" />\n";
+                echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">\n";
+                echo "<input type=\"hidden\" name=\"action\" value=\"navigation\">\n";
                 if ($lesson->nextpagedefault) {
                     // in Flash Card mode...
                     // ...first get number of retakes
-                    $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id);
+                    $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); 
                     // ...then get the page ids (lessonid the 5th param is needed to make get_records play)
                     $allpages = get_records("lesson_pages", "lessonid", $lesson->id, "id", "id,lessonid");
                     shuffle ($allpages);
                     $found = false;
                     if ($lesson->nextpagedefault == LESSON_UNSEENPAGE) {
                         foreach ($allpages as $thispage) {
-                            if (!count_records("lesson_attempts", "pageid", $thispage->id, "userid",
+                            if (!count_records("lesson_attempts", "pageid", $thispage->id, "userid", 
                                         $USER->id, "retry", $nretakes)) {
                                 $found = true;
                                 break;
                         $newpageid = LESSON_EOL;
                     }
                 }
-                echo "<input type=\"hidden\" name=\"pageid\" value=\"$newpageid\" />\n";
-                echo "<p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
-                    get_string("continue", "lesson")."\" /></p>\n";
+                echo "<input type=\"hidden\" name=\"pageid\" value=\"$newpageid\">\n";
+                           echo "<p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                     get_string("continue", "lesson")."\"></p>\n";
                 echo "</form>\n";
             }
-            echo "</table>\n";
+            echo "</table>\n"; 
         } else {
             // end of lesson reached work out grade
+                       /// CDC-FLAG ///
+                       if ($lesson->timed) {
+                               unset($USER->startlesson[$lesson->id]);  // take this variable out that I put in for timed tests
+                               if (isset($_GET["outoftime"])) {
+                                       if ($_GET["outoftime"] == "normal") {
+                                               print_simple_box(get_string("eolstudentoutoftime", "lesson"), "center");
+                                       }
+                               }
+                       }
+                       if (isset($USER->lessonloggedin[$lesson->id])) {
+                               unset($USER->lessonloggedin[$lesson->id]);
+                       }
             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 (isstudent($course->id)) {
-                if ($nviewed = count_records("lesson_attempts", "lessonid", $lesson->id, "userid",
+                if ($nviewed = count_records("lesson_attempts", "lessonid", $lesson->id, "userid", 
                         $USER->id, "retry", $ntries)) {
-                    // count the number of distinct correct pages
-                    if ($correctpages = get_records_select("lesson_attempts",  "lessonid = $lesson->id AND
-                            userid = $USER->id AND retry = $ntries AND correct = 1")) {
-                        foreach ($correctpages as $correctpage) {
-                            $temp[$correctpage->pageid] = 1;
-                        }
-                        $ncorrect = count($temp);
-                    } else {
-                        $ncorrect = 0;
-                    }
-                    echo "<p align=\"center\">".get_string("numberofpagesviewed", "lesson", $nviewed).
-                        "</p>\n";
-                    if ($lesson->minquestions) {
-                        if ($nviewed < $lesson->minquestions) {
-                            // print a warning and set nviewed to minquestions
-                            echo "<p align=\"center\">".get_string("youshouldview", "lesson",
-                                    $lesson->minquestions)." ".get_string("pages", "lesson")."</p>\n";
-                            $nviewed = $lesson->minquestions;
-                        }
-                    }
-                    echo "<p align=\"center\">".get_string("numberofcorrectanswers", "lesson", $ncorrect).
-                        "</p>\n";
-                    $thegrade = intval(100 * $ncorrect / $nviewed);
-                    echo "<p align=\"center\">".get_string("gradeis", "lesson",
-                            number_format($thegrade * $lesson->grade / 100, 1)).
-                        " (".get_string("outof", "lesson", $lesson->grade).")</p>\n";
-                    $grade->lessonid = $lesson->id;
-                    $grade->userid = $USER->id;
-                    $grade->grade = $thegrade;
-                    $grade->completed = time();
-                    if (!$newgradeid = insert_record("lesson_grades", $grade)) {
-                        error("Navigation: grade not inserted");
-                    }
+                                       /// CDC-FLAG /// 6/11/04
+                                       if (!$lesson->custom) {
+                                               $ncorrect = 0;                                          
+                                               if ($pagesanswered = get_records_select("lesson_attempts",  "lessonid = $lesson->id AND 
+                                                               userid = $USER->id AND retry = $ntries 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
+
+                                               echo "<p align=\"center\">".get_string("numberofpagesviewed", "lesson", $nviewed).
+                                                       "</p>\n";
+                                               if ($lesson->minquestions) {
+                                                       if ($nviewed < $lesson->minquestions) {
+                                                               // print a warning and set nviewed to minquestions
+                                                               echo "<p align=\"center\">".get_string("youshouldview", "lesson", 
+                                                                               $lesson->minquestions)." ".get_string("pages", "lesson")."</p>\n";
+                                                               $nviewed = $lesson->minquestions;
+                                                       }
+                                               }
+                                               echo "<p align=\"center\">".get_string("numberofcorrectanswers", "lesson", $ncorrect).
+                                                       "</p>\n";
+                                               $thegrade = intval(100 * $ncorrect / $nviewed);
+                                               echo "<p align=\"center\">".get_string("gradeis", "lesson", 
+                                                               number_format($thegrade * $lesson->grade / 100, 1)).
+                                                       " (".get_string("outof", "lesson", $lesson->grade).")</p>\n";
+                                               
+                                       } else {
+                                               $score = 0;
+                                               if ($useranswers = get_records_select("lesson_attempts",  "lessonid = $lesson->id AND 
+                                                               userid = $USER->id AND retry = $ntries", "timeseen")) {
+
+                                                       foreach ($useranswers as $useranswer) {
+                                                               if (@!array_key_exists($useranswer->pageid, $temp)) {
+                                                                       $temp[$useranswer->pageid] = array($useranswer->answerid, 1);
+                                                               } else {
+                                                                       if ($temp[$useranswer->pageid][1] < $lesson->maxattempts) {
+                                                                               $n = $temp[$useranswer->pageid][1] + 1;
+                                                                               $temp[$useranswer->pageid] = array($useranswer->answerid, $n);
+                                                                       }
+                                                               }
+                                                       }
+                                                       if ($answervalues = get_records_select("lesson_answers",  "lessonid = $lesson->id")) {
+                                                               if ($pages = get_records_select("lesson_pages", "lessonid = $lesson->id")) {
+                                                                       foreach ($pages as $page) {
+                                                                               $questions[$page->id] = $page->qtype;
+                                                                       }
+                                                               } else {
+                                                                       $questions = array();
+                                                               }
+                                                               $tempmaxgrade = $lesson->grade;
+                                                               $essayquestions = 0;
+                                                               foreach ($answervalues as $answervalue) {
+                                                                       if (array_key_exists($answervalue->pageid, $temp)) {
+                                                                               if ($temp[$answervalue->pageid][0] == $answervalue->id) {
+                                                                                       if ($questions[$answervalue->pageid] == LESSON_ESSAY) {
+                                                                                               $tempmaxgrade = $tempmaxgrade - $answervalue->score;
+                                                                                               $essayquestions++;
+                                                                                       } else {
+                                                                                               $score = $score + $answervalue->score;
+                                                                                       }
+                                                                               }
+                                                                       }
+                                                               }
+                                                       } else {
+                                                               error("Error: Could not find answers!");
+                                                       }
+                                               }
+                                               if ($score > $lesson->grade) {
+                                                       $thegrade = 100;
+                                                       $score = $lesson->grade;
+                                               } elseif ($score < 0) {
+                                                       $thegrade = 0;
+                                                       $score = 0;
+                                               } else {
+                                                       $thegrade = intval(100 * $score / $lesson->grade);
+                                               }
+
+                                               unset($a);
+                                               if ($essayquestions > 0) {
+                                                       $a->score = $score;
+                                                       $a->tempmaxgrade = $tempmaxgrade;
+                                                       $a->essayquestions = $essayquestions;
+                                                       $a->grade = $lesson->grade;
+                                                       echo "<div align=\"center\">";
+                                                       echo get_string("displayscorewithessays", "lesson", $a);
+                                                       echo "</div>";
+                                               } else {
+                                                       $a->score = $score;
+                                                       $a->grade = $lesson->grade;
+                                                       echo "<div align=\"center\">".get_string("displayscorewithoutessays", "lesson", $a)."</div>";                                           
+                                               }
+                                       }
+                                       /// CDC-FLAG ///                                                
+                                       $grade->lessonid = $lesson->id;
+                                       $grade->userid = $USER->id;
+                                       $grade->grade = $thegrade;
+                                       $grade->completed = time();
+                                       if (!$lesson->practice) {
+                                               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");
-                    $thegrade = 0;
-                }
-            } else {
+                    //print_string("noattemptrecordsfound", "lesson");                                 
+                                       if ($lesson->timed) {
+                                               if (isset($_GET["outoftime"])) {
+                                                       if ($_GET["outoftime"] == "normal") {
+                                                               $grade->lessonid = $lesson->id;
+                                                               $grade->userid = $USER->id;
+                                                               $grade->grade = 0;
+                                                               $grade->completed = time();
+                                                               if (!$lesson->practice) {
+                                                                       if (!$newgradeid = insert_record("lesson_grades", $grade)) {
+                                                                               error("Navigation: grade not inserted");
+                                                                       }
+                                                               }
+                                                               echo get_string("eolstudentoutoftimenoanswers", "lesson");
+                                                       }
+                                               }
+                                       } else {
+                                               echo get_string("welldone", "lesson");
+                                       }
+
+
+                }   
+            } else { 
                 // display for teacher
                 echo "<p align=\"center\">".get_string("displayofgrade", "lesson")."</p>\n";
             }
-            print_simple_box_end();
-            print_continue("../../course/view.php?id=$course->id");
+            print_simple_box_end(); //End of Lesson button to Continue.
+                       ///CDC-FLAG /// high scores code
+                       if ($lesson->highscores && !isteacher($course->id)) {
+                               echo "<div align=\"center\"><br>";
+                               if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id", "completed")) {
+                                       echo get_string("youmadehighscore", "lesson", $lesson->maxhighscores)."<br>";
+                                       echo "<a href=\"view.php?id=$cm->id&action=nameforhighscores\">".get_string("clicktopost", "lesson")."</a><br>";
+                               } else {
+                                       if (!$highscores = get_records_select("lesson_high_scores", "lessonid = $lesson->id")) {
+                                               echo get_string("youmadehighscore", "lesson", $lesson->maxhighsores)."<br>";
+                                               echo "<a href=\"view.php?id=$cm->id&action=nameforhighscores\">".get_string("clicktopost", "lesson")."</a><br>";
+                                       } else {
+                                               // get all the high scores into an array
+                                               foreach ($highscores as $highscore) {
+                                                       $grade = $grades[$highscore->gradeid]->grade;
+                                                       $topscores[] = $grade;
+                                               }
+                                               // sort to find the lowest score
+                                               sort($topscores);
+                                               $lowscore = $topscores[0];
+                                               
+                                               if ($thegrade >= $lowscore || count($topscores) <= $lesson->maxhighscores) {
+                                                       echo get_string("youmadehighscore", "lesson", $lesson->maxhighscores)."<br>";
+                                                       echo "<a href=\"view.php?id=$cm->id&action=nameforhighscores\">".get_string("clicktopost", "lesson")."</a><br>";
+                                               } else {
+                                                       echo get_string("nothighscore", "lesson", $lesson->maxhighscores)."<br>";
+                                               }
+                                       }
+                               }
+                               echo "<br><a href=\"view.php?id=$cm->id&action=highscores&link=1\">".get_string("viewhighscores", "lesson")."</a>";
+                               echo "</div>";                                                  
+                       }
+                       /// CDC-FLAG ///                        
+                       echo "<p align=\"center\"><a href=\"../../course/view.php?id=$course->id\">".get_string("mainmenu", "lesson")."</a></p>\n"; //CDC Back to the menu (course view).
+                       echo "<p align=\"center\"><a href=\"../../course/grade.php?id=$course->id\">".get_string("viewgrades", "lesson")."</a></p>\n"; //CDC Back to the menu (course view).
         }
 
+               /// CDC-FLAG ///
+               if($lesson->slideshow) {
+                       echo "</td></tr></table></div>\n"; //Closes Mark's big div tag?
+               }
+               
+               if($lesson->slideshow && $pageid != LESSON_EOL) {
+                       if (!$lesson->displayleft) {
+                               echo "<table width=\"$lesson->width\" cellpadding=\"5\" cellspacing=\"5\" align=\"center\">\n";
+                       } else {
+                               echo "<table width=\"$lesson->width\" cellpadding=\"5\" cellspacing=\"5\">\n";
+                       }
+                       switch ($page->qtype) {
+                               case LESSON_SHORTANSWER :
+                               case LESSON_NUMERICAL :
+                                       echo "<tr><td><p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                                                get_string("pleaseenteryouranswerinthebox", "lesson")."\"></p></td></tr>\n";
+                                       break;
+                               case LESSON_TRUEFALSE :
+                                       echo "<tr><td><p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                                               get_string("pleasecheckoneanswer", "lesson")."\"></p></td></tr>\n"; 
+                                       break;
+                               case LESSON_MULTICHOICE :
+                                       if ($page->qoption) {
+                                               echo "<tr><td><p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                                                       get_string("pleasecheckoneormoreanswers", "lesson")."\"></p></td></tr>\n";
+                                       } else {
+                                               echo "<tr><td><p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                                                        get_string("pleasecheckoneanswer", "lesson")."\"></p></td></tr>\n";
+                                       }
+                                       break;
+                               case LESSON_MATCHING :
+                                       echo "<tr><td><p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                                               get_string("pleasematchtheabovepairs", "lesson")."\"></p></td></tr>\n";
+                                       break;
+                               case LESSON_ESSAY :
+                                       echo "<tr><td><p align=\"center\"><input type=\"submit\" name=\"continue\" value=\"".
+                                                get_string("pleaseenteryouranswerinthebox", "lesson")."\"></p></td></tr>\n";
+                                       break;
+                               case LESSON_BRANCHTABLE : 
+                                       $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 "<tr>";
+                                               // next 3 foreach loops print out the links in correct order
+                                               foreach ($nextprevious as $jump) {
+                                                       if ($jump->jumpto == LESSON_PREVIOUSPAGE) {
+                                                               echo "<td align=\"left\"><input type=\"button\" onclick=\"document.answerform.jumpto.value=$jump->jumpto;document.answerform.submit();\"".
+                                                                        "value = \"$jump->answer\"></td>";
+                                                       }
+                                               }
+                                               echo "<td align=\"center\"><table><tr>";
+                                               foreach ($otherjumps as $otherjump) {
+                                                               echo "<td><input type=\"button\" onclick=\"document.answerform.jumpto.value=$otherjump->jumpto;document.answerform.submit();\"".
+                                                                        "value = \"$otherjump->answer\"></td>";
+                                               }
+                                               echo "</tr></table></td>";
+                                               foreach ($nextprevious as $jump) {
+                                                       if ($jump->jumpto == LESSON_NEXTPAGE) {
+                                                               echo "<td align=\"right\"><input type=\"button\" onclick=\"document.answerform.jumpto.value=$jump->jumpto;document.answerform.submit();\"".
+                                                                        "value = \"$jump->answer\"></td>";
+                                                       }
+                                               }
+                                               echo "</tr>";
+                                       } else {
+                                               // next 3 foreach loops print out the links in correct order
+                                               foreach ($nextprevious as $jump) {
+                                                       if ($jump->jumpto == LESSON_NEXTPAGE) {
+                                                               echo "<tr><td><input type=\"button\" onclick=\"document.answerform.jumpto.value=$jump->jumpto;document.answerform.submit();\"".
+                                                                        "value = \"$jump->answer\"></td></tr>";
+                                                       }
+                                               }
+                                               foreach ($otherjumps as $otherjump) {
+                                                               echo "<tr><td><input type=\"button\" onclick=\"document.answerform.jumpto.value=$otherjump->jumpto;document.answerform.submit();\"".
+                                                                        "value = \"$otherjump->answer\"></td></tr>";
+                                               }
+                                               foreach ($nextprevious as $jump) {
+                                                       if ($jump->jumpto == LESSON_PREVIOUSPAGE) {
+                                                               echo "<tr><td><input type=\"button\" onclick=\"document.answerform.jumpto.value=$jump->jumpto;document.answerform.submit();\"".
+                                                                        "value = \"$jump->answer\"></td></tr>";
+                                                       }
+                                               }
+                                       }
+                                       break;
+                       }                               
+                       echo "</table></form>\n";
+               }
+
+               if ($lesson->displayleft) {
+                       echo "</div><!-- close slidepos class -->"; //CDC Chris Berri for styles, closes slidepos.
+               } elseif ($lesson->slideshow) {
+                       echo "</td></tr></table>";
+               }
+               /// CDC-FLAG ///            
     }
 
 
     /*******************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;
         }
 
         if (!$page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) {
-            // if there are no pages give teacher a blank proforma
-            ?>
-            <form name="form" method="post" action="lesson.php">
-            <input type="hidden" name="id" value="<?php echo $cm->id ?>" />
-            <input type="hidden" name="action" value="insertpage" />
-            <input type="hidden" name="pageid" value="0" />
-            <center><table cellpadding="5" border="1">
-            <tr><td align="center">
-            <tr valign="top">
-            <td><p><b><?php print_string("pagetitle", "lesson"); ?>:</b></p></td></tr>
-            <tr><td><input type="text" name="title" size="80" maxsize="255" value="" /></td></tr>
-            <?php
-            echo "<tr><td><b>";
-            echo get_string("pagecontents", "lesson").":</b><br />\n";
-            print_textarea($usehtmleditor, 25, 70, 630, 400, "contents");
-            echo "</td></tr>\n";
-            echo "<tr><td><b>".get_string("questiontype", "lesson").":</b> \n";
-            choose_from_menu($LESSON_QUESTION_TYPE, "qtype", LESSON_MULTICHOICE, "");
-            helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson");
-            echo "<br /><b>".get_string("questionoption", "lesson").":</b>\n";
-            echo " <input type=\"checkbox\" name=\"qoption\" value=\"1\" />";
-            helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson");
-            echo "</td></tr>\n";
-            for ($i = 0; $i < $lesson->maxanswers; $i++) {
-                $iplus1 = $i + 1;
-                echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b><br />\n";
-                print_textarea(false, 6, 70, 630, 100, "answer[$i]");
-                echo "</td></tr>\n";
-                echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b><br />\n";
-                print_textarea(false, 6, 70, 630, 100, "response[$i]");
-                echo "</td></tr>\n";
-                if ($i) {
-                    // answers 2,3,4... jump to this page
-                    echo "<input type=\"hidden\" name=\"jumpto[$i]\" value =\"0\" />\n";
-                } else {
-                    // answer 1 jumps to next page
-                    echo "<input type=\"hidden\" name=\"jumpto[$i]\" value =\"".LESSON_NEXTPAGE."\" />\n";
-                }
-            }
-            // close table and form
-            ?>
-            </table><br />
-            <input type="submit" value="<?php  print_string("savepage", "lesson") ?>" />
-            <input type="submit" name="cancel" value="<?php  print_string("cancel") ?>" />
-            </center>
-            </form>
-            <?php
-            use_html_editor("contents"); // Lets give IE more time load the page before replacing textarea.
-            // show import link
-            print_heading("<a href=\"import.php?id=$cm->id&pageid=0\">".get_string("importquestions",
-                    "lesson")."</a>\n");
+                       /// CDC-FLAG ///
+            // if there are no pages give teacher the option to create a new page or a new branch table
+                       echo "<div align=\"center\">";
+                       if (isteacheredit($course->id)) {
+                               print_simple_box( "<table cellpadding=\"5\" border=\"0\">\n<tr><th>".get_string("whatdofirst", "lesson")."</th></tr><tr><td>".
+                                       "<a href=\"import.php?id=$cm->id&pageid=0\">".
+                                       get_string("importquestions", "lesson")."</a></td></tr><tr><td>".
+                                       "<a href=\"lesson.php?id=$cm->id&action=addbranchtable&pageid=0&firstpage=1\">".
+                                       get_string("addabranchtable", "lesson")."</a></td></tr><tr><td>".
+                                       "<a href=\"lesson.php?id=$cm->id&action=addpage&pageid=0&firstpage=1\">".
+                                       get_string("addaquestionpage", "lesson")." ".get_string("here","lesson").
+                                       "</a></td></tr></table\n");
+                       }
+                       print_simple_box_end();
+                       echo "</div>"; //CDC Chris Berri added.
+                       /// CDC-FLAG ///                
         } else {
             // print the pages
             echo "<form name=\"lessonpages\" method=\"post\" action=\"view.php\">\n";
             echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">\n";
-            echo "<input type=\"hidden\" name=\"action\" value=\"navigation\" />\n";
-            echo "<input type=\"hidden\" name=\"pageid\" />\n";
-            echo "<center><table cellpadding=\"5\" border=\"0\" width=\"80%\">\n";
-            if (isteacheredit($course->id)) {
-                echo "<tr><td align=\"right\"><small><a href=\"import.php?id=$cm->id&pageid=0\">".
-                    get_string("importquestions", "lesson")."</a> | ".
-                    "<a href=\"lesson.php?id=$cm->id&action=addbranchtable&pageid=0\">".
-                    get_string("addabranchtable", "lesson")."</a> | ".
-                    "<a href=\"lesson.php?id=$cm->id&action=addpage&pageid=0\">".
-                    get_string("addaquestionpage", "lesson")." ".get_string("here","lesson").
-                    "</a></small></td></tr>\n";
-            }
+            echo "<input type=\"hidden\" name=\"action\" value=\"navigation\">\n";
+            echo "<input type=\"hidden\" name=\"pageid\">\n";
+                       /// CDC-FLAG /// link to grade essay questions
+                       if (count_records("lesson_pages", "lessonid", $lesson->id, "qtype", LESSON_ESSAY) > 0) {
+                               echo "<div align=\"center\"><a href=\"view.php?id=$cm->id&action=essayview\">".get_string("gradeessay", "lesson")."</a></div><br>";
+                       }
+                       /// CDC-FLAG /// tree code - in final release, will use lang file for all text output.
+                       // NoticeFix next two lines and bowth viewAlls
+                       $branch = false;
+                       $singlePage = false;
+                       if($lesson->tree && !isset($_GET['display']) && !isset($_GET['viewAll'])) {  
+                               echo "<div align=\"center\">";
+                                       echo get_string("treeview", "lesson")."<br><br>";
+                                       echo "<a href=\"view.php?id=$id&viewAll=1\">".get_string("viewallpages", "lesson")."</a><br><br>\n";
+                                       echo "<table><tr><td>";
+                                       lesson_print_tree($page->id, $lesson->id, $cm->id, $pixpath);
+                                       echo "</td></tr></table>";
+                                       echo "<br><a href=\"view.php?id=$id&viewAll=1\">".get_string("viewallpages", "lesson")."</a>\n";
+                               echo "</div>";
+                       } else {
+                               if(isset($_GET['display']) && !isset($_GET['viewAll'])) {
+                                       while(true)
+                                       {
+                                               if($page->id == $_GET['display'] && $page->qtype == LESSON_BRANCHTABLE) {
+                                                       $branch = true;
+                                                       $singlePage = false;
+                                                       break;
+                                               } elseif($page->id == $_GET['display']) {
+                                                       $branch = false;
+                                                       $singlePage = true;     
+                                                       break;
+                                               } elseif ($page->nextpageid) {
+                                                       if (!$page = get_record("lesson_pages", "id", $page->nextpageid)) {
+                                                                       error("Teacher view: Next page not found!");
+                                                       }
+                                               } else {
+                                                       // last page reached
+                                                       break;
+                                               }
+                                        }
+                                       echo "<center><a href=\"view.php?id=$id&viewAll=1\">".get_string("viewallpages", "lesson")."</a><br>\n";
+                                       echo "<a href=\"view.php?id=$id\">".get_string("backtreeview", "lesson")."</a><br>\n";
+                                       echo "<table cellpadding=\"5\" border=\"0\" width=\"80%\">\n";
+                                       if (isteacheredit($course->id)) {
+                                               /// CDC-FLAG 6/16/04 ///                                        
+                                               echo "<tr><td align=\"right\"><small><a href=\"import.php?id=$cm->id&pageid=$page->prevpageid\">".
+                                                       get_string("importquestions", "lesson")."</a> | ".
+                                               "<a href=\"lesson.php?id=$cm->id&action=addcluster&pageid=$page->prevpageid\">".
+                               get_string("addcluster", "lesson")."</a> | ".
+                                                       "<a href=\"lesson.php?id=$cm->id&action=addendofcluster&pageid=$page->prevpageid\">".
+                           get_string("addendofcluster", "lesson")."</a> | ".
+                                                       "<a href=\"lesson.php?id=$cm->id&action=addbranchtable&pageid=$page->prevpageid\">".
+                                                       get_string("addabranchtable", "lesson")."</a> | ".
+                                                       "<a href=\"lesson.php?id=$cm->id&action=addpage&pageid=$page->prevpageid\">".
+                                                       get_string("addaquestionpage", "lesson")." ".get_string("here","lesson").
+                                                       "</a></small></td></tr>\n";
+                                               /// CDC-FLAG ///                                                        
+                                       }                                
+                               } else {
+                                       if($lesson->tree) {
+                                               echo "<center><a href=\"view.php?id=$id\">".get_string("backtreeview", "lesson")."</a><br></center>\n";
+                                       }       
+                                       echo "<center><table cellpadding=\"5\" border=\"0\" width=\"80%\">\n";
+                                       if (isteacheredit($course->id)) {
+                                               /// CDC-FLAG 6/16/04 ///
+                                               echo "<tr><td align=\"left\"><small><a href=\"import.php?id=$cm->id&pageid=0\">".
+                                                       get_string("importquestions", "lesson")."</a> | ".
+                                                       "<a href=\"lesson.php?id=$cm->id&action=addcluster&pageid=0\">".
+                               get_string("addendofcluster", "lesson")."</a> | ".
+                                                       "<a href=\"lesson.php?id=$cm->id&action=addbranchtable&pageid=0\">".
+                                                       get_string("addabranchtable", "lesson")."</a> | ".
+                                                       "<a href=\"lesson.php?id=$cm->id&action=addpage&pageid=0\">".
+                                                       get_string("addaquestionpage", "lesson")." ".get_string("here","lesson").
+                                                       "</a></small></td></tr>\n";
+                                               /// CDC-FLAG ///
+                                       }
+                               }
+                               /// CDC-FLAG /// end tree code  (note, there is an "}" below for an else above)
             echo "<tr><td>\n";
             while (true) {
                 echo "<table width=\"100%\" border=\"1\"><tr><td bgcolor=\"$THEME->cellheading2\" colspan=\"2\"><b>$page->title</b>&nbsp;&nbsp;\n";
                 if (isteacheredit($course->id)) {
                     if ($npages > 1) {
                         echo "<a title=\"".get_string("move")."\" href=\"lesson.php?id=$cm->id&action=move&pageid=$page->id\">\n".
-                            "<img src=\"$pixpath/t/move.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\"></a>\n";
+                            "<img src=\"$pixpath/t/move.gif\" hspace=\"2\" height=11 width=11 alt=\"move\" border=0></a>\n"; //CDC alt text added.
                     }
                     echo "<a title=\"".get_string("update")."\" href=\"lesson.php?id=$cm->id&action=editpage&pageid=$page->id\">\n".
-                        "<img src=\"$pixpath/t/edit.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\"></a>\n".
+                        "<img src=\"$pixpath/t/edit.gif\" hspace=\"2\" height=11 width=11 alt=\"edit\" border=0></a>\n".
                         "<a title=\"".get_string("delete")."\" href=\"lesson.php?id=$cm->id&action=confirmdelete&pageid=$page->id\">\n".
-                        "<img src=\"$pixpath/t/delete.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\"></a>\n";
+                        "<img src=\"$pixpath/t/delete.gif\" hspace=\"2\" height=11 width=11 alt=\"delete\" border=0></a>\n"; //CDC alt text added.
                     }
-                    echo "</td></tr>\n";
+                    echo "</td></tr>\n";             
                 echo "<tr><td colspan=\"2\">\n";
                 print_simple_box(format_text($page->contents), "center");
                 echo "</td></tr>\n";
                 if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) {
                     echo "<tr><td bgcolor=\"$THEME->cellheading2\" colspan=\"2\" align=\"center\"><b>\n";
                     switch ($page->qtype) {
+                                               case LESSON_ESSAY :  /// CDC-FLAG /// 6/16/04  this line and the next
+                                                       echo $LESSON_QUESTION_TYPE[$page->qtype];
+                                                       break;
                         case LESSON_SHORTANSWER :
                             echo $LESSON_QUESTION_TYPE[$page->qtype];
                             if ($page->qoption) {
                         case LESSON_NUMERICAL :
                             echo $LESSON_QUESTION_TYPE[$page->qtype];
                             break;
-                        case LESSON_BRANCHTABLE :
+                        case LESSON_BRANCHTABLE :    
                             echo get_string("branchtable", "lesson");
                             break;
                         case LESSON_ENDOFBRANCH :
                     }
                     echo "</td></tr>\n";
                     $i = 1;
+                                       $n = 0;
                     foreach ($answers as $answer) {
                         switch ($page->qtype) {
                             case LESSON_MULTICHOICE:
                             case LESSON_TRUEFALSE:
                             case LESSON_SHORTANSWER:
                             case LESSON_NUMERICAL:
-                            case LESSON_MATCHING:
                                 echo "<tr><td bgcolor=\"$THEME->cellheading2\" align=\"right\" valign=\"top\" width=\"20%\">\n";
-                                if (lesson_iscorrect($page->id, $answer->jumpto)) {
-                                    // underline correct answers
-                                    echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
-                                } else {
-                                    echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
-                                }
+                                /// CDC-FLAG /// 6/11/04
+                                                               if ($lesson->custom) {
+                                                                       // if the score is > 0, then it is correct
+                                                                       if ($answer->score > 0) {
+                                                                               echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
+                                                                       } else {
+                                                                               echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
+                                                                       }
+                                                               } else {
+                                                                       if (lesson_iscorrect($page->id, $answer->jumpto)) {
+                                                                               // underline correct answers
+                                                                               echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
+                                                                       } else {
+                                                                               echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
+                                                                       }
+                                                               }
+                                                               /// CDC-FLAG ///
                                 echo "</td><td width=\"80%\">\n";
                                 echo format_text($answer->answer);
                                 echo "</td></tr>\n";
                                echo "<tr><td align=\"right\" valign=\"top\"><b>".get_string("response", "lesson")." $i:</b> \n";
                                 echo "</td><td>\n";
-                                echo format_text($answer->response);
+                                echo format_text($answer->response); 
                                 echo "</td></tr>\n";
-                                break;
+                                break;                                                 
+                                                       case LESSON_MATCHING:
+                                                               if ($n < 2) {
+                                                                       if ($answer->answer != NULL) {
+                                                                               if ($n == 0) {
+                                                                                       echo "<tr><td align=\"right\" valign=\"top\"><b>".get_string("correctresponse", "lesson").":</b> \n";
+                                                                                       echo "</td><td>\n";
+                                                                                       echo format_text($answer->answer); 
+                                                                                       echo "</td></tr>\n";
+                                                                               } else {
+                                                                                       echo "<tr><td align=\"right\" valign=\"top\"><b>".get_string("wrongresponse", "lesson").":</b> \n";
+                                                                                       echo "</td><td>\n";
+                                                                                       echo format_text($answer->answer); 
+                                                                                       echo "</td></tr>\n";
+                                                                               }
+                                                                       }
+                                                                       $n++;
+                                                                       $i--;
+                                                               } else {
+                                       echo "<tr><td bgcolor=\"$THEME->cellheading2\" align=\"right\" valign=\"top\" width=\"20%\">\n";
+                                                                       if ($lesson->custom) {
+                                                                               // if the score is > 0, then it is correct
+                                                                               if ($answer->score > 0) {
+                                                                                       echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
+                                                                               } else {
+                                                                                       echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
+                                                                               }
+                                                                       } else {
+                                                                               if (lesson_iscorrect($page->id, $answer->jumpto)) {
+                                                                                       // underline correct answers
+                                                                                       echo "<b><u>".get_string("answer", "lesson")." $i:</u></b> \n";
+                                                                               } else {
+                                                                                       echo "<b>".get_string("answer", "lesson")." $i:</b> \n";
+                                                                               }
+                                                                       }
+                                                                       echo "</td><td width=\"80%\">\n";
+                                                                       echo format_text($answer->answer);
+                                                                       echo "</td></tr>\n";
+                                                                  echo "<tr><td align=\"right\" valign=\"top\"><b>".get_string("matchesanswer", "lesson")." $i:</b> \n";
+                                                                       echo "</td><td>\n";
+                                                                       echo format_text($answer->response); 
+                                                                       echo "</td></tr>\n";
+                                                               }
+                                                               break;
                             case LESSON_BRANCHTABLE:
                                 echo "<tr><td align=\"right\" valign=\"top\" width=\"20%\">\n";
                                 echo "<b>".get_string("description", "lesson")." $i:</b> \n";
                             $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) {
+                            $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");
+                                               } elseif ($answer->jumpto == LESSON_RANDOMPAGE) {
+                                                       $jumptitle = get_string("randompageinbranch", "lesson");
+                                               } elseif ($answer->jumpto == LESSON_RANDOMBRANCH) {
+                                                       $jumptitle = get_string("randombranch", "lesson");
+                                               } elseif ($answer->jumpto == LESSON_CLUSTERJUMP) {
+                                                       $jumptitle = get_string("clusterjump", "lesson");               /// CDC-FLAG ///                                                                                                                        
                         } else {
                             if (!$jumptitle = get_field("lesson_pages", "title", "id", $answer->jumpto)) {
                                 $jumptitle = "<b>".get_string("notdefined", "lesson")."</b>";
                             }
                         }
-                        echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("jump", "lesson")." $i:";
-                        echo "</b></td><td width=\"80%\">\n";
-                        echo "$jumptitle</td></tr>\n";
+                                               /// CDC-FLAG ///
+                                               if ($page->qtype == LESSON_MATCHING) {
+                                                       if ($i == 1) {
+                                                               echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("correctanswerscore", "lesson").":";
+                                                               echo "</b></td><td width=\"80%\">\n";
+                                                               echo "$answer->score</td></tr>\n";
+                                                               echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("correctanswerjump", "lesson").":";
+                                                               echo "</b></td><td width=\"80%\">\n";
+                                                               echo "$jumptitle</td></tr>\n";
+                                                       } elseif ($i == 2) {
+                                                               echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("wronganswerscore", "lesson").":";
+                                                               echo "</b></td><td width=\"80%\">\n";
+                                                               echo "$answer->score</td></tr>\n";
+                                                               echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("wronganswerjump", "lesson").":";
+                                                               echo "</b></td><td width=\"80%\">\n";
+                                                               echo "$jumptitle</td></tr>\n";
+                                                       }
+                                               } else {
+                                                       if ($lesson->custom && $page->qtype != LESSON_BRANCHTABLE && $page->qtype != LESSON_ENDOFBRANCH) {                                              
+                                                               echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("score", "lesson")." $i:";
+                                                               echo "</b></td><td width=\"80%\">\n";
+                                                               echo "$answer->score</td></tr>\n";
+                                                       }
+                                                       echo "<tr><td align=\"right\" width=\"20%\"><b>".get_string("jump", "lesson")." $i:";
+                                                       echo "</b></td><td width=\"80%\">\n";
+                                                       echo "$jumptitle</td></tr>\n";
+                                               }
                         $i++;
                     }
-                    // print_simple_box_end();
+                    // print_simple_box_end();  /// CDC-FLAG /// not sure if i commented this out... hehe
                     echo "<tr><td bgcolor=\"$THEME->cellheading2\" colspan=\"2\" align=\"center\">";
                     if ($page->qtype != LESSON_ENDOFBRANCH) {
                         echo "<input type=\"button\" value=\"";
                             echo get_string("checkquestion", "lesson");
                         }
                         echo "\" onclick=\"document.lessonpages.pageid.value=$page->id;".
-                            "document.lessonpages.submit();\" />";
+                            "document.lessonpages.submit();\">";
                     }
                     echo "&nbsp;</td></tr>\n";
                 }
                 echo "</td></tr></table></td></tr>\n";
                 if (isteacheredit($course->id)) {
-                    echo "<tr><td align=\"right\"><small><a href=\"import.php?id=$cm->id&pageid=$page->id\">".
-                        get_string("importquestions", "lesson")."</a> | ".
-                        "<a href=\"lesson.php?id=$cm->id&action=addbranchtable&pageid=$page->id\">".
-                        get_string("addabranchtable", "lesson")."</a> | ";
+                                       /// CDC-FLAG /// 6/16/04                                
+                    echo "<tr><td align=\"left\"><small><a href=\"import.php?id=$cm->id&pageid=$page->id\">".
+                        get_string("importquestions", "lesson")."</a> | ".    
+                                            "<a href=\"lesson.php?id=$cm->id&action=addcluster&pageid=$page->id\">".
+                         get_string("addcluster", "lesson")."</a> | ".
+                                                "<a href=\"lesson.php?id=$cm->id&action=addendofcluster&pageid=$page->id\">".
+                         get_string("addendofcluster", "lesson")."</a> | ".
+                                                "<a href=\"lesson.php?id=$cm->id&action=addbranchtable&pageid=$page->id\">".
+                        get_string("addabranchtable", "lesson")."</a><br>";
+                                       /// 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
+                                       $nextqtype = 0; // set to anything else EOB
                     if ($page->nextpageid) {
                         $nextqtype = get_field("lesson_pages", "qtype", "id", $page->nextpageid);
                     }
                 }
                 $prevpageid = $page->id;
                 // move to next page
-                if ($page->nextpageid) {
+                               /// CDC-FLAG ///
+                               if($singlePage) {  // this will make sure only one page is displayed if needed
+                                       break;
+                               } elseif($branch && $page->qtype == LESSON_ENDOFBRANCH) {  // this will display a branch table and its contents
+                                       break;
+                } elseif ($page->nextpageid) {  /// CDC-FLAG ///
                     if (!$page = get_record("lesson_pages", "id", $page->nextpageid)) {
                         error("Teacher view: Next page not found!");
                     }
                     break;
                 }
             }
+               } /// CDC-FLAG /// end of else from above tree code!!!
+               
             echo "</table></form>\n";
+                       /// CDC-FLAG ///
+                       // NoticeFix both viewAll's
+                       if(isset($_GET['display']) && !isset($_GET['viewAll'])) {
+                               echo "<center><a href=\"view.php?id=$id&viewAll=1\">".get_string("viewallpages", "lesson")."</a><br>\n";
+                       }
+                       if($lesson->tree && (isset($_GET['display']) || isset($_GET['viewAll']))) {
+                               echo "<center><a href=\"view.php?id=$id\">".get_string("backtreeview", "lesson")."</a><br></center>\n";
+                       }
+                       /// CDC-FLAG ///                        
             print_heading("<a href=\"view.php?id=$cm->id&action=navigation\">".get_string("checknavigation",
                         "lesson")."</a>\n");
-        }
+        } 
     }
 
+    /*******************essay view **************************************/ // 6/29/04
+    elseif ($action == 'essayview') {
+               print_heading_with_help($lesson->name, "overview", "lesson");
+               if (!$essays = get_records_select("lesson_essay", "lessonid = $lesson->id", "timesubmitted")) {
+                       error("Error: could not find essays");
+               }
+               if (!$pages = get_records_select("lesson_pages", "lessonid = $lesson->id")) {
+                       error("Error: could not find lesson pages");
+               }
+               if (!$users = lesson_get_participants($lesson->id)) {
+                       error("Error: could not find users");
+               }
+               
+               echo "<div align=\"center\"><a href=\"view.php?id=$cm->id\">Go Back to Lesson</a></div><br>";
 
-    /*************** no man's land **************************************/
-    else {
-        error("Fatal Error: Unknown Action: ".$action."\n");
-    }
+               foreach ($essays as $essay) {
+                       $studentname = $users[$essay->userid]->lastname.", ".$users[$essay->userid]->firstname;
+                       $essay->studentname = $studentname;
+                       $temp[$studentname][] = $essay;
+               }
+               ksort($temp);
+
+               echo "<table width=\"100%\" align=\"center\" cellspacing=\"10\">";
+               echo "<tr align=\"center\" bgcolor=\"$THEME->cellheading2\"><td width=\"100px\"><b>$course->students</b></td><td><b>".get_string("essays", "lesson")."</b></td><td width=\"155px\"><b>".get_string("email", "lesson")."</b></td></tr>";
+               foreach ($temp as $student) {
+                       echo "<tr><td>".$student[0]->studentname."</td><td>";
+                       $end = end($student);
+                       foreach ($student as $essay) {
+                               if (!$essay->graded) {
+                                       $style = "style='color:#DF041E;text-decoration:underline;'";
+                               } elseif (!$essay->sent) {
+                                       $style = "style='color:#006600;text-decoration:underline;'";
+                               } else {
+                                       $style = "style='color:#999999;'";
+                               }
+                               $output = "<a $style href=\"view.php?id=$cm->id&action=essaygrade&essayid=$essay->id\">".$pages[$essay->pageid]->title."</a>";
+                               if ($essay->id != $end->id) {
+                                       $output .= ", ";
+                               }
+                               echo $output;
+                       }
+                       echo "</td><td><a href=\"view.php?id=$cm->id&action=emailessay&userid=".$essay->userid."\">".get_string("emailgradedessays", "lesson")."</a></td></tr>";
+               }
+               echo "<td><td><td><a href=\"view.php?id=$cm->id&action=emailessay\">".get_string("emailallgradedessays", "lesson")."</a></td>";
+               echo "</table>";
+
+       }
+       
+       /*******************grade essays **************************************/ // 6/29/04
+    elseif ($action == 'essaygrade') {
+               print_heading_with_help($lesson->name, "overview", "lesson");
+               if (!$essays = get_records_select("lesson_essay", "lessonid = $lesson->id", "timesubmitted")) {
+                       error("Error: could not find essays");
+               }
+               if (!$pages = get_records_select("lesson_pages", "lessonid = $lesson->id")) {
+                       error("Error: could not find lesson pages");
+               }
+               if (!$users = lesson_get_participants($lesson->id)) {
+                       error("Error: could not find users");
+               }
+               if (!$answers = get_records_select("lesson_answers", "lessonid = $lesson->id")) {
+                       error("Error: could not find essays");
+               }
+
+               $essayid = $_GET['essayid'];
+
+               echo "<form name=\"essaygrade\" method=\"post\" action=\"view.php\">\n";
+               echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">\n";
+               echo "<input type=\"hidden\" name=\"action\">\n";
+               echo "<input type=\"hidden\" name=\"essayid\" value=\"$essayid\">\n";
+               echo "<input type=\"hidden\" name=\"userid\" value=\"".$essays[$essayid]->userid."\">\n";
+               
+               $style = "style=\"padding-left:40px;\"";
+               
+               
+               echo "<table cellspacing=\"10\" align=\"center\">";
+               echo "<tr><td>".get_string("question", "lesson").":</td></tr><tr><td $style>";
+               print_simple_box_start("left");
+               echo $pages[$essays[$essayid]->pageid]->contents;
+               print_simple_box_end();
+               echo "</td></tr>";
+
+               $studentname = $users[$essays[$essayid]->userid]->firstname." ".$users[$essays[$essayid]->userid]->lastname;
+               echo "<tr><td>".get_string("studentresponse", "lesson", $studentname).":</td></tr><tr><td $style>";
+               print_simple_box_start("left");
+               echo $essays[$essayid]->answer;
+               print_simple_box_end();
+               echo "</td></tr>";
+               echo "<tr><td>".get_string("comments", "lesson").":<br></td></tr>";
+               echo "<tr><td $style>";
+               echo "<textarea id=\"answer\" name=\"response\" align=\"center\" rows=\"10\" cols=\"50\">".$essays[$essayid]->response."</textarea>\n"; 
+               echo "</td></tr>";
+               
+               echo "<tr><td>".get_string("essayscore", "lesson").": </td></tr><tr><td $style>";               
+               if ($lesson->custom) {
+                       for ($i=$answers[$essays[$essayid]->answerid]->score; $i>=0; $i--) {
+               $grades[$i] = $i;
+               }
+               lesson_choose_from_menu($grades, "score", $essays[$essayid]->score, "");
+               } else {
+                       $options[0] = "incorrect"; $options[1] = "correct";
+                       lesson_choose_from_menu($options, "score", $essays[$essayid]->score, "");
+               }
+               echo "</td></tr>";              
+               echo "</table>";
+               
+               echo "<table align=\"center\"><tr><td>";
+               echo "<input type=\"button\" value=\"Cancel\" onclick=\"document.essaygrade.action.value='essayview';".
+                        "document.essaygrade.submit();\">";
+               echo "</td><td>";
+               echo "<input type=\"button\" value=\"Submit Grade\" onclick=\"document.essaygrade.action.value='updategrade';".
+                        "document.essaygrade.submit();\">";
+               echo "</td></tr></table>";
+               echo "</form>";
+       }
+
+       /*******************update grade**************************************/ // 6/29/04
+    elseif ($action == 'updategrade') {
+               print_heading_with_help($lesson->name, "overview", "lesson");
+               
+               $userid = $_POST['userid'];
+               
+               if (!$essays = get_records_select("lesson_essay", "lessonid = $lesson->id", "timesubmitted")) {
+                       error("Error: could not find essays");
+               }
+               if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid= $userid", "completed")) {
+                       error("Error: could not find grades");
+               }
 
+               echo "<div align=\"center\">";
+               echo "Please wait while updating...<br>"; 
+
+               $form = data_submitted();
+               
+               $update->id = $form->essayid;
+               $update->graded = true;
+               $update->score = $form->score;
+               $update->response = $form->response;
+               $update->sent = false;
+               
+               for ($i = 0; $i < $essays[$form->essayid]->try; $i++) {
+                       next($grades);
+               }
+               $grade = current($grades);
+               // if teacher goes back and changes score, then need to take the old score off
+               $resetgrade = $grade->grade - ($essays[$form->essayid]->score / $lesson->grade * 100);
+               // now add the new score
+               $newgrade = ($form->score / $lesson->grade * 100) + $resetgrade;
+               if ($newgrade > 100) {
+                       $newgrade = 100;
+               } elseif ($newgrade < 0) {
+                       $newgrade = 0;
+               }
+               $updategrade->id = $grade->id;
+               $updategrade->grade = $newgrade;
+
+               if(update_record("lesson_essay", $update) && update_record("lesson_grades", $updategrade)) {
+                       redirect("view.php?id=$cm->id&action=essayview", get_string("updatesuccess", "lesson"));
+               } else {
+                       echo get_string("updatefailed", "lesson")."!<br>";
+                       echo "<a href=\"view.php?id=$cm->id&action=essayview\">".get_string("continue", "lesson")."</a>";
+                       exit();
+               }
+               echo "</div>";
+       }
+
+       /*******************email essay **************************************/ // 6/29/04
+    elseif ($action == 'emailessay') {
+               print_heading_with_help($lesson->name, "overview", "lesson");
+       
+               echo "<div align=\"center\">";
+               echo "Please wait while emailing...<br>"; 
+
+               if (isset($_GET['userid'])) {           
+                       $queryadd = "and userid = ".$_GET['userid'];
+               } else {
+                       $queryadd = "";
+               }
+
+               if (!$essays = get_records_select("lesson_essay", "lessonid = $lesson->id $queryadd", "timesubmitted")) {
+                       error("Error: could not find essays");
+               }
+               if (!$pages = get_records_select("lesson_pages", "lessonid = $lesson->id")) {
+                       error("Error: could not find lesson pages");
+               }
+               if (!$users = lesson_get_participants($lesson->id)) {
+                       error("Error: could not find users");
+               }
+               if (!$answers = get_records_select("lesson_answers", "lessonid = $lesson->id")) {
+                       error("Error: could not find essays");
+               }
+               // NoticeFix  big fix, change $essay[]'s that use $USER to just $USER
+               foreach ($essays as $essay) {
+                       if ($essay->graded && !$essay->sent) {
+                               $subject = "Your grade for ".$pages[$essay->pageid]->title." question";
+                               $message = "Question:<br>\r\n";
+                               $message .= $pages[$essay->pageid]->contents;
+                               $message .= "<br><br>\r\n\r\n";
+                               $message .= "Your response:<br>\r\n";
+                               $message .= $essay->answer;
+                               $message .= "<br><br>\r\n\r\n";
+                               $message .= $USER->firstname." ".$USER->lastname."'s comments:<br>\r\n";
+                               $message .= $essay->response;
+                               $message .= "<br><br>\r\n\r\n";
+                               $grades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid = $essay->userid", "completed");
+                               for ($i = 0; $i < $essay->try; $i++) {
+                                       next($grades);
+                               }
+                               $grade = current($grades);
+                               reset($grades);
+                               if ($lesson->custom) {
+                                       $message .= "You have received $essay->score points out of $lesson->grade".".<br>\r\n";
+                                       $message .= "Your grade for the lesson has been changed to $grade->grade"."%.\r\n";
+                               } else {
+                                       // cannot think of a way to update if not custom...
+                               }
+                               if(email_to_user($users[$essay->userid], $USER, $subject, $message, $message)) {
+                                       $updateessay->id = $essay->id;
+                                       $updateessay->sent = true;
+                                       update_record("lesson_essay", $updateessay);
+                               } else {
+                                       echo "Email Failed!<br>";
+                                       echo "<a href=\"view.php?id=$cm->id&action=essayview\">".get_string("continue", "lesson")."</a>";
+                                       echo "</div>";
+                                       exit();
+                               }
+                       }
+               }
+               redirect("view.php?id=$cm->id&action=essayview", get_string("emailsuccess", "lesson"));
+       }
+
+       /*******************high scores **************************************/
+    elseif ($action == 'highscores') {
+               print_heading_with_help($lesson->name, "overview", "lesson");
+
+               if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id", "completed")) {
+                       $grades = array();
+               }
+       
+               echo "<div align=\"center\">";
+               $titleinfo->maxhighscores = $lesson->maxhighscores;
+               $titleinfo->name = $lesson->name;
+               echo get_string("topscorestitle", "lesson", $titleinfo)."<br><br>";
+
+               if (!$highscores = get_records_select("lesson_high_scores", "lessonid = $lesson->id")) {
+                       echo get_string("nohighscores", "lesson")."<br>";
+               } else {
+                       foreach ($highscores as $highscore) {
+                               $grade = $grades[$highscore->gradeid]->grade;
+                               $topscores[$grade][] = $highscore->nickname;
+                       }
+                       krsort($topscores);
+                       
+                       echo "<table cellspacing=\"10px\">";
+                       echo "<tr align=\"center\" bgcolor=\"$THEME->cellheading2\"><td>".get_string("rank", "lesson")."</td><td>$course->students</td><td>".get_string("scores", "lesson")."</td></tr>";
+                       $printed = 0;
+                       while (true) {
+                               $temp = current($topscores);
+                               $score = key($topscores);
+                               $rank = $printed + 1;
+                               sort($temp); 
+                               foreach ($temp as $student) {
+                                       echo "<tr><td align=\"right\">$rank</td><td>$student</td><td align=\"right\">$score</td></tr>";
+                                       
+                               }
+                               $printed++;
+                               if (!next($topscores) || !($printed < $lesson->maxhighscores)) { 
+                                       break;
+                               }
+                       }
+                       echo "</table>";
+               }
+               if (isset($_GET['link'])) {
+                       echo "<br><a href=\"../../course/view.php?id=$course->id\">".get_string("returntocourse", "lesson")."</a>";
+               } else {
+                       echo "<br><a href=\"../../course/view.php?id=$course->id\">".get_string("cancel", "lesson")."</a> | <a href=\"view.php?id=$cm->id&action=navigation\">".get_string("startlesson", "lesson")."</a>";
+               }
+               echo "</div>";
+                       
+       }
+       /*******************update high scores **************************************/
+    elseif ($action == 'updatehighscores') {
+               print_heading_with_help($lesson->name, "overview", "lesson");
+
+               if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id", "completed")) {
+                       error("Error: could not find grades");
+               }
+               if (!$usergrades = get_records_select("lesson_grades", "lessonid = $lesson->id and userid = $USER->id", "completed DESC")) {
+                       error("Error: could not find grades");
+               }
+               echo "<div align=\"center\">";
+               echo get_string("waitpostscore", "lesson")."<br>";
+               
+               foreach ($usergrades as $usergrade) {
+                       // get their latest grade
+                       $newgrade = $usergrade;
+                       break;
+               }
+               
+               if ($pasthighscore = get_record_select("lesson_high_scores", "lessonid = $lesson->id and userid = $USER->id")) {
+                       $pastgrade = $grades[$pasthighscore->gradeid]->grade;
+                       if ($pastgrade >= $newgrade->grade) {
+                               redirect("view.php?id=$cm->id&action=highscores&link=1", "Update Successful");
+                       } else {
+                               // delete old and find out where new one goes
+                               if (!delete_records("lesson_high_scores", "id", $pasthighscore->id)) {
+                                       error("Error: could not delete old high score");
+                               }
+                       }
+               }
+               // find out if we need to delete any records
+               if ($highscores = get_records_select("lesson_high_scores", "lessonid = $lesson->id")) {  // if no high scores... then just insert our new one
+                       foreach ($highscores as $highscore) {
+                               $grade = $grades[$highscore->gradeid]->grade;
+                               $topscores[$grade][] = $highscore->userid;
+                       }
+                       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;                           
+                               // 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);
+                                       // making a delete statement to delete all users with the lowest score
+                                       $deletestmt = "lessonid = $lesson-> id and userid = ";
+                                       $deletestmt .= current($lowscore);
+                                       while (next($lowscore)) {
+                                               $deletestmt .= " or userid = ".current($lowscore);
+                                       }
+                                       if (!delete_records_select("lesson_high_scores", $deletestmt)) {
+                                               /// not a big deal...
+                                               error("Did not delete extra high score(s)");
+                                       }
+                               }
+                       }
+               }
+               
+               $newhighscore->lessonid = $lesson->id;
+               $newhighscore->userid = $USER->id;
+               $newhighscore->gradeid = $newgrade->id;
+               if (isset($_GET['name'])) {
+                       $newhighscore->nickname = $_GET['name'];
+               }
+               if (!insert_record("lesson_high_scores", $newhighscore)) {
+                       error("Insert of new high score Failed!");
+               }
+               
+               redirect("view.php?id=$cm->id&action=highscores&link=1", get_string("postsuccess", "lesson"));
+               echo "</div>";
+       }
+       /*******************name for highscores **************************************/
+    elseif ($action == 'nameforhighscores') {
+               print_heading_with_help($lesson->name, "overview", "lesson");
+               echo "<div align=\"center\">";
+               if (isset($_POST['name'])) {
+                       if (lesson_check_nickname(trim($_POST['name']))) {
+                               redirect("view.php?id=$cm->id&action=updatehighscores&name=".trim($_POST['name']), get_string("nameapproved", "lesson"));
+                       } else {
+                               echo get_string("namereject", "lesson")."<br><br>";
+                       }
+               }
+                               
+               echo "<form name=\"nickname\" method =\"post\" action=\"view.php\">";
+               echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">";
+               echo "<input type=\"hidden\" name=\"action\" value=\"nameforhighscores\">";
+               
+               echo get_string("entername", "lesson").": <input type=\"text\" name=\"name\" maxlength=\"5\"><br>";
+               echo "<input type=\"submit\" value=\"".get_string("submitname", "lesson")."\">";
+               echo "</form>";
+               echo "</div>";
+       }       
+    /*************** no man's land **************************************/
+       else {
+               error("Fatal Error: Unknown Action: ".$action."\n");
+       }
 /// Finish the page
     print_footer($course);