From: michaelpenne Date: Wed, 15 Sep 2004 20:32:24 +0000 (+0000) Subject: Added a lot of new features to lesson mod. Check them out :) X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5e7856af581ab4554e66bba692575f42ab495ad3;p=moodle.git Added a lot of new features to lesson mod. Check them out :) MarkNielsen --- diff --git a/mod/lesson/backuplib.php b/mod/lesson/backuplib.php index 888c03865b..8f9be96a04 100644 --- a/mod/lesson/backuplib.php +++ b/mod/lesson/backuplib.php @@ -1,4 +1,4 @@ -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 diff --git a/mod/lesson/db/mysql.sql b/mod/lesson/db/mysql.sql index 195782e7d6..69b02164b2 100644 --- a/mod/lesson/db/mysql.sql +++ b/mod/lesson/db/mysql.sql @@ -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'); diff --git a/mod/lesson/db/postgres7.php b/mod/lesson/db/postgres7.php index 7d8e7a21b4..1f52e6fe04 100644 --- a/mod/lesson/db/postgres7.php +++ b/mod/lesson/db/postgres7.php @@ -1,4 +1,4 @@ - \ No newline at end of file diff --git a/mod/lesson/format.php b/mod/lesson/format.php index a0662ae1f5..34bc2523bf 100644 --- a/mod/lesson/format.php +++ b/mod/lesson/format.php @@ -1,4 +1,4 @@ -

$count. ".stripslashes($question->questiontext)."

"; + echo "

$count. ".stripslashes($question->questiontext)."

"; unset($newpage); $newpage->lessonid = $lesson->id; $newpage->qtype = $question->qtype; diff --git a/mod/lesson/import.php b/mod/lesson/import.php index 9a7c8a974b..0752a76582 100644 --- a/mod/lesson/import.php +++ b/mod/lesson/import.php @@ -1,8 +1,8 @@ -id\">$strlessons -> id\">$lesson->name-> $strimportquestions"); + print_header("$course->shortname: $strimportquestions", "$course->shortname: $strimportquestions", + "wwwroot/course/view.php?id=$course->id\">$course->shortname -> ". + "id>$strlessons -> id\">$lesson->name-> $strimportquestions"); if ($form = data_submitted()) { /// Filename @@ -59,7 +60,20 @@ 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 "
"; + echo "
"; print_continue("view.php?id=$cm->id"); print_footer($course); exit; @@ -96,23 +110,23 @@ print_heading_with_help($strimportquestions, "import", "lesson"); print_simple_box_start("center", "", "$THEME->cellheading"); - echo "
"; - echo "id\" />\n"; - echo "\n"; - echo ""; + echo ""; + echo "id\">\n"; + echo "\n"; + echo "
"; - echo ""; - echo ""; echo "
"; + echo "
"; print_string("fileformat", "lesson"); echo ":"; choose_from_menu($fileformatnames, "format", "gift", ""); echo "
"; + echo "
"; print_string("upload"); echo ":"; - echo " "; + echo " "; echo "
 "; - echo " "; + echo " "; echo "
"; diff --git a/mod/lesson/index.php b/mod/lesson/index.php index 5e8ef38fb2..2838cfc68d 100644 --- a/mod/lesson/index.php +++ b/mod/lesson/index.php @@ -1,9 +1,9 @@ -id); add_to_log($course->id, "lesson", "view all", "index.php?id=$course->id", ""); @@ -24,7 +24,11 @@ /// Print the header - print_header_simple("$strlessons", "", "$strlessons", "", "", true, "", navmenu($course)); + if ($course->category) { + $navigation = "id\">$course->shortname ->"; + } + + print_header("$course->shortname: $strlessons", "$course->fullname", "$navigation $strlessons", "", "", true, "", navmenu($course)); /// Get all the appropriate data @@ -56,23 +60,22 @@ foreach ($lessons as $lesson) { if (!$lesson->visible) { //Show dimmed if the mod is hidden - $link = "coursemodule\">$lesson->name"; + $link = "coursemodule\">$lesson->name"; } else { //Show normal if the mod is visible - $link = "coursemodule\">$lesson->name"; + $link = "coursemodule\">$lesson->name"; } if ($lesson->deadline > $timenow) { $due = userdate($lesson->deadline); } else { - $due = "".userdate($lesson->deadline).""; + $due = "".userdate($lesson->deadline).""; } - $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 "
"; + echo "
"; print_table($table); diff --git a/mod/lesson/lesson.php b/mod/lesson/lesson.php index 4ef5ad4913..a8cc503d6f 100644 --- a/mod/lesson/lesson.php +++ b/mod/lesson/lesson.php @@ -1,10 +1,12 @@ -category) { - $navigation = "id\">$course->shortname ->"; + $navigation = "id\">$course->shortname ->"; } $strlessons = get_string("modulenameplural", "lesson"); @@ -51,14 +55,13 @@ // ... print the header and... print_header("$course->shortname: $lesson->name", "$course->fullname", - "$navigation id\">$strlessons -> - id\">$lesson->name", + "$navigation id>$strlessons -> + id\">$lesson->name", "", "", true); //...get the action require_variable($action); - /************** add branch table ************************************/ if ($action == 'addbranchtable' ) { @@ -72,45 +75,59 @@ // 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"); ?> - - - - -
+ + + + +
- + \n"; + use_html_editor("contents"); + echo "\n"; + /// CDC-FLAG /// 6/16/04 + echo "\n"; + /// CDC-FLAG /// for ($i = 0; $i < $lesson->maxanswers; $i++) { $iplus1 = $i + 1; echo "\n"; - echo "\n"; + echo "\n"; } - use_html_editor(); // close table and form ?>
:
-
"; echo get_string("pagecontents", "lesson").":
\n"; print_textarea($usehtmleditor, 25,70, 630, 400, "contents"); - echo "
\n"; + echo "
"; + echo get_string("arrangebuttonshorizontally", "lesson")."\n"; + echo "
"; + echo get_string("displayinleftmenu", "lesson"); + echo "
\n"; + echo "
".get_string("description", "lesson")." $iplus1:
\n"; - print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$i]"); - echo "
".get_string("jump", "lesson")." $iplus1: \n"; + print_textarea(false, 10, 70, 630, 300, "answer[$i]"); // made the default set to off also removed use_html_editor(); line from down below, which made all textareas turn into html editors + echo "
".get_string("jump", "lesson")." $iplus1: \n"; if ($i) { // answers 2, 3, 4... jumpto this page lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); @@ -121,15 +138,14 @@ helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); echo "

- " /> - " /> + "> + ">
- 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' ) { @@ -209,73 +342,228 @@ // 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"); ?>
- - - -
+ + + +
+ \n"; + ?> - + \n"; - echo "\n"; - for ($i = 0; $i < $lesson->maxanswers; $i++) { - $iplus1 = $i + 1; - echo "\n"; - echo "\n"; - echo "\n"; - } + if (isset($_GET['qtype'])) { + switch ($_GET['qtype']) { + case LESSON_TRUEFALSE : + for ($i = 0; $i < 2; $i++) { + $iplus1 = $i + 1; + echo "\n"; + echo "\n"; + echo "\n"; + } + break; + case LESSON_ESSAY : + echo "\n"; + break; + case LESSON_MATCHING : + for ($i = 0; $i < $lesson->maxanswers+2; $i++) { + $icorrected = $i - 1; + if ($i == 0) { + echo "\n"; + } elseif ($i == 1) { + echo "\n"; + } else { + echo "\n"; + echo "\n"; + } + if ($i == 2) { + echo "\n"; + } elseif ($i == 3) { + echo "\n"; + } + } + break; + case LESSON_SHORTANSWER : + case LESSON_NUMERICAL : + case LESSON_MULTICHOICE : + // default code + for ($i = 0; $i < $lesson->maxanswers; $i++) { + $iplus1 = $i + 1; + echo "\n"; + echo "\n"; + echo "\n"; + } + break; + } + } else { + for ($i = 0; $i < $lesson->maxanswers; $i++) { + $iplus1 = $i + 1; + echo "\n"; + echo "\n"; + echo "\n"; + } + } // close table and form ?>
"; + echo get_string("questiontype", "lesson").": \n"; + echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; + if (isset($_GET['qtype'])) { + 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 "

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

".get_string("multianswer", "lesson").": \n"; + } + echo " "; //CDC hidden label added. + helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); + } + } else { + lesson_qtype_menu($LESSON_QUESTION_TYPE, LESSON_MULTICHOICE, + "lesson.php?id=$cm->id&action=addpage&pageid=".$_GET['pageid'].$linkadd); + } + echo "
:
-
"; echo get_string("pagecontents", "lesson").":
\n"; print_textarea($usehtmleditor, 25,70, 630, 400, "contents"); use_html_editor("contents"); echo "
".get_string("questiontype", "lesson").": \n"; - choose_from_menu($LESSON_QUESTION_TYPE, "qtype", LESSON_MULTICHOICE, ""); - helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson"); - echo "
".get_string("questionoption", "lesson").":\n"; - echo " "; - helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); - echo "
".get_string("answer", "lesson")." $iplus1:
\n"; - print_textarea(false, 6, 70, 630, 300, "answer[$i]"); - echo "
".get_string("response", "lesson")." $iplus1:
\n"; - print_textarea(false, 6, 70, 630, 300, "response[$i]"); - echo "
".get_string("jump", "lesson")." $iplus1: \n"; - if ($i) { - // answers 2, 3, 4... jumpto this page - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - } else { - // answer 1 jumpto next page - lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); - } - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - echo "
".get_string("answer", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("response", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "response[$i]"); + echo "
".get_string("jump", "lesson")." $iplus1: \n"; + if ($i) { + // answers 2, 3, 4... jumpto this page + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + } else { + // answer 1 jumpto next page + lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); + } + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + /// CDC-FLAG /// + if($lesson->custom) { + if ($i) { + echo get_string("score", "lesson")." $iplus1: "; + } else { + echo get_string("score", "lesson")." $iplus1: "; + } + } + /// CDC-FLAG /// + echo "
".get_string("jump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[0]", LESSON_NEXTPAGE, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if ($lesson->custom) { + echo get_string("score", "lesson").": "; + } + echo "
".get_string("correctresponse", "lesson").":
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("wrongresponse", "lesson").":
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("answer", "lesson")." $icorrected:
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("matchesanswer", "lesson")." $icorrected:
\n"; + print_textarea(false, 6, 70, 630, 300, "response[$i]"); + echo "
".get_string("correctanswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("correctanswerscore", "lesson").": "; + } + echo "
".get_string("wronganswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("wronganswerscore", "lesson").": "; + } + echo "
".get_string("answer", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("response", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "response[$i]"); + echo "
".get_string("jump", "lesson")." $iplus1: \n"; + if ($i) { + // answers 2, 3, 4... jumpto this page + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + } else { + // answer 1 jumpto next page + lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); + } + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + /// CDC-FLAG /// + if($lesson->custom) { + if ($i) { + echo get_string("score", "lesson")." $iplus1: "; + } else { + echo get_string("score", "lesson")." $iplus1: "; + } + } + /// CDC-FLAG /// + echo "
".get_string("answer", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$i]"); + echo "
".get_string("response", "lesson")." $iplus1:
\n"; + print_textarea(false, 6, 70, 630, 300, "response[$i]"); + echo "
".get_string("jump", "lesson")." $iplus1: \n"; + if ($i) { + // answers 2, 3, 4... jumpto this page + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + } else { + // answer 1 jumpto next page + lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); + } + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + /// CDC-FLAG /// + if($lesson->custom) { + if ($i) { + echo get_string("score", "lesson")." $iplus1: "; + } else { + echo get_string("score", "lesson")." $iplus1: "; + } + } + /// CDC-FLAG /// + echo "

- " /> - " /> + "> + ">
- 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 '
'; + if ($page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) { + // print the pages + echo "
\n"; + echo "id\">\n"; + echo "\n"; + echo "\n"; + echo ""; + echo "
"; + } + echo "
"; //close leftmenu1 + echo "
"; //CDC slidepos + } elseif ($lesson->slideshow) { + echo "
"; + } + /// CDC-FLAG /// Slideshow styles + if($lesson->slideshow) { + echo "
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 "
".get_string("teacherjumpwarning", "lesson", $warningvars)."

"; + } + } + /// 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 "
".get_string("teachertimerwarning", "lesson")."
"; + } 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 "
"; + echo "\n"; + echo "


"; + } else { + redirect("view.php?id=$cm->id&action=navigation&pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson")); + } + if ((($timer->starttime + $lesson->maxtime * 60) - time()) < 60 && !((($timer->starttime + $lesson->maxtime * 60) - time()) < 0)) { + echo "
".get_string("studentoneminwarning", "lesson")."
"; + } elseif (($timer->starttime + $lesson->maxtime * 60) < time()) { + echo "
".get_string("studentoutoftime", "lesson")."
"; + $outoftime = true; + } + 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"); } @@ -329,7 +701,39 @@ $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; @@ -338,44 +742,60 @@ 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; } } } @@ -399,7 +819,16 @@ } if (lesson_iscorrect($pageid, $answer->jumpto)) { $correctanswer = true; - } + } + /* CDC-FLAG */ + if ($lesson->custom) { + if ($answer->score > 0) { + $correctanswer = true; + } else { + $correctanswer = false; + } + } + /// CDC-FLAG 6/21/04 /// $newpageid = $answer->jumpto; if (!$response = trim($answer->response)) { if ($correctanswer) { @@ -427,35 +856,72 @@ $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) { @@ -477,10 +943,19 @@ $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) { @@ -492,6 +967,7 @@ } break; + /// CDC-FLAG /// 6/14/04 -- added responses case LESSON_MATCHING : if (isset($_POST['response'])) { $response = $_POST['response']; @@ -508,23 +984,49 @@ 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 @@ -555,6 +1057,14 @@ if (lesson_iscorrect($pageid, $newpageid)) { $correctanswer = true; } + /// CDC-FLAG /// + if ($lesson->custom) { + if ($answer->score > 0) { + $correctanswer = true; + $answerid = $answer->id; + } + } + /// CDC-FLAG /// break; } } @@ -573,6 +1083,41 @@ 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; @@ -581,8 +1126,15 @@ // 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(); @@ -603,9 +1155,13 @@ $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 @@ -667,22 +1223,114 @@ } } + /// CDC-FLAG 6/21/04 /// this calculates the ongoing score + if ($lesson->ongoing) { + if (isteacher($course->id)) { + echo "
".get_string("teacherongoingwarning", "lesson")."

"; + } 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 "
\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 "

"; + if ($qattempts == 1) { + print_simple_box(get_string("firstwrong", "lesson"), "center"); + } else { + print_simple_box(get_string("secondpluswrong", "lesson"), "center"); + } + } else { + print_simple_box(format_text($response), 'center'); + } echo "
\n"; - } + } } + + + /// CDC-FLAG 6/18/04 /// - this is where some jump numbers are interpreted + if ($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 "
\n"; - echo "id\" />\n"; - echo "\n"; - echo "\n"; - echo "

\n"; - echo "
\n"; + echo "id\">\n"; + echo "\n"; + echo "\n"; + /// CDC-FLAG /// + if ($lesson->slideshow) { + echo "
"; //Close Mark's big div tag??? + + echo "width\" cellpadding=\"5\" cellspacing=\"5\">
\n"; + if ($lesson->review && !$correctanswer && !$noanswer) { + echo "

\n"; + echo "

\n"; + } else { + echo "

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

\n"; + echo "

\n"; + } else { + echo "

\n"; + } + } + echo "\n"; + + if ($lesson->displayleft) { + echo "
"; //CDC Chris Berri for styles, closes slidepos. + } elseif ($lesson->slideshow) { + echo "
"; + } } @@ -758,9 +1406,27 @@ 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"); @@ -770,33 +1436,78 @@ 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 ?>
- - - - -
- "; + } + } + + /// CDC-FLAG /// + echo '
+ + + + +
+ qtype) { + case LESSON_MULTICHOICE : + echo "\n"; + break; + case LESSON_SHORTANSWER : + echo "\n"; + break; + case LESSON_TRUEFALSE : + case LESSON_ESSAY : + case LESSON_MATCHING : + case LESSON_NUMERICAL : + echo "\n"; + break; + } + ?> + + - \n"; $n = 0; switch ($page->qtype) { - case LESSON_SHORTANSWER : - echo "\n"; + /// CDC-FLAG /// echo "\n"; // get the answers in a set order, the id order if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { - foreach ($answers as $answer) { + foreach ($answers as $answer) { $flags = intval($answer->flags); // force into an integer $nplus1 = $n + 1; - echo "id\" />\n"; + echo "id\">\n"; switch ($page->qtype) { - case LESSON_MULTICHOICE: + case LESSON_MATCHING: + if ($n == 0) { + echo "\n"; + echo "\n"; + break; case LESSON_TRUEFALSE: + case LESSON_MULTICHOICE: case LESSON_SHORTANSWER: - case LESSON_NUMERICAL: - case LESSON_MATCHING: + case LESSON_NUMERICAL: echo "\n"; break; } - echo "\n"; + switch ($page->qtype) { + case LESSON_MATCHING : + if ($n == 2) { + echo "\n"; + break; + case LESSON_ESSAY : + echo "\n"; + break; + case LESSON_TRUEFALSE: + case LESSON_MULTICHOICE: + case LESSON_SHORTANSWER: + case LESSON_NUMERICAL: + echo "\n"; + break; + case LESSON_BRANCHTABLE: + case LESSON_CLUSTER: + case LESSON_ENDOFCLUSTER: + case LESSON_ENDOFBRANCH: + echo "\n"; + break; + } $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 "\n"; + echo "\n"; switch ($page->qtype) { - case LESSON_MULTICHOICE: + case LESSON_MATCHING: + $icorrected = $i - 1; + echo "\n"; + echo "\n"; + break; case LESSON_TRUEFALSE: + case LESSON_MULTICHOICE: case LESSON_SHORTANSWER: case LESSON_NUMERICAL: - case LESSON_MATCHING: echo "\n"; echo "\n"; break; } - echo "\n"; + switch ($page->qtype) { + case LESSON_ESSAY : + if ($i < 1) { + echo "\n"; + } + break; + case LESSON_MATCHING : + if ($i == 2) { + echo "\n"; + break; + case LESSON_TRUEFALSE: + case LESSON_MULTICHOICE: + case LESSON_SHORTANSWER: + case LESSON_NUMERICAL: + echo "\n"; + break; + case LESSON_BRANCHTABLE : + echo "\n"; + break; + } } } // close table and form ?>
"; + echo get_string("questiontype", "lesson").": \n"; + echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; + lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype, + "lesson.php?id=$cm->id&action=editpage&pageid=$page->id", + "document.editpage.redisplay.value=1;document.editpage.submit();"); + echo "

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

".get_string("casesensitive", "lesson").": \n"; + if ($page->qoption) { + echo ""; //CDC hidden label added. + } else { + echo ""; //CDC hidden label added. + } + helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); + echo "
"; + echo get_string("questiontype", "lesson").": \n"; + echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."
"; + lesson_qtype_menu($LESSON_QUESTION_TYPE, $page->qtype, + "lesson.php?id=$cm->id&action=editpage&pageid=$page->id", + "document.editpage.redisplay.value=1;document.editpage.submit();"); + echo "
:
-
"; echo get_string("pagecontents", "lesson").":
\n"; print_textarea($usehtmleditor, 25, 70, 630, 400, "contents", $page->contents); @@ -804,71 +1515,138 @@ echo "
".get_string("questiontype", "lesson").": \n"; - choose_from_menu($LESSON_QUESTION_TYPE, "qtype", $page->qtype, ""); - echo "  "; - echo " ".get_string("casesensitive", "lesson").": \n"; - if ($page->qoption) { - echo ""; - } else { - echo ""; - } - helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson"); - break; - case LESSON_MULTICHOICE : - echo "
".get_string("questiontype", "lesson").": \n"; - choose_from_menu($LESSON_QUESTION_TYPE, "qtype", $page->qtype, ""); - echo "  "; - echo " ".get_string("multianswer", "lesson").": \n"; - if ($page->qoption) { - echo ""; - } else { - echo ""; - } - helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson"); - break; - case LESSON_TRUEFALSE : - case LESSON_MATCHING : - case LESSON_NUMERICAL : - echo "
".get_string("questiontype", "lesson").": \n"; - choose_from_menu($LESSON_QUESTION_TYPE, "qtype", $page->qtype, ""); - helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson"); - break; case LESSON_BRANCHTABLE : - echo "qtype\" />\n"; + echo "qtype\">\n"; + /// CDC-FLAG /// 6/16/04 + echo "
\n"; + echo "
"; + if ($page->layout) { + echo ""; + } else { + echo ""; + } + echo get_string("arrangebuttonshorizontally", "lesson")."
\n"; + echo "
"; + if ($page->display) { + echo "
"; + } else { + echo "
"; + } + echo get_string("displayinleftmenu", "lesson")."
\n"; + echo "
".get_string("branchtable", "lesson")." \n"; break; + case LESSON_CLUSTER : + echo "qtype\">\n"; + echo "
".get_string("clustertitle", "lesson")." \n"; + break; + case LESSON_ENDOFCLUSTER : + echo "qtype\">\n"; + echo "
".get_string("endofclustertitle", "lesson")." \n"; + break; case LESSON_ENDOFBRANCH : - echo "qtype\" />\n"; + echo "qtype\">\n"; echo "
".get_string("endofbranch", "lesson")." \n"; break; } echo "
".get_string("correctresponse", "lesson").":\n"; + if ($flags & LESSON_ANSWER_EDITOR) { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label added. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); + use_html_editor("answer[$n]"); // switch on the editor + } else { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer); + } + } elseif ($n == 1) { + echo "
".get_string("wrongresponse", "lesson").":\n"; + if ($flags & LESSON_ANSWER_EDITOR) { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label added. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); + use_html_editor("answer[$n]"); // switch on the editor + } else { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer); + } + } else { + $ncorrected = $n - 1; + echo "
".get_string("answer", "lesson")." $ncorrected:\n"; + if ($flags & LESSON_ANSWER_EDITOR) { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label added. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); + use_html_editor("answer[$n]"); // switch on the editor + } else { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer); + } + echo "
".get_string("matchesanswer", "lesson")." $ncorrected:\n"; + if ($flags & LESSON_RESPONSE_EDITOR) { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label added. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$n]", $answer->response); + use_html_editor("response[$n]"); // switch on the editor + } else { + echo " [".get_string("useeditor", "lesson").": ". + ""; //CDC hidden label added. + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea(false, 6, 70, 630, 300, "response[$n]", $answer->response); + } + } + echo "
".get_string("answer", "lesson")." $nplus1:\n"; if ($flags & LESSON_ANSWER_EDITOR) { echo " [".get_string("useeditor", "lesson").": ". - ""; + ""; //CDC hidden label added. helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); echo "]
\n"; print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); use_html_editor("answer[$n]"); // switch on the editor } else { echo " [".get_string("useeditor", "lesson").": ". - ""; + ""; //CDC hidden label. helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); echo "]
\n"; print_textarea(false, 6, 70, 630, 300, "answer[$n]", $answer->answer); @@ -877,15 +1655,15 @@ echo "
".get_string("response", "lesson")." $nplus1:\n"; if ($flags & LESSON_RESPONSE_EDITOR) { echo " [".get_string("useeditor", "lesson").": ". - ""; + ""; //CDC hidden label added. helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); echo "]
\n"; print_textarea($usehtmleditor, 20, 70, 630, 300, "response[$n]", $answer->response); use_html_editor("response[$n]"); // switch on the editor } else { echo " [".get_string("useeditor", "lesson").": ". - ""; + ""; //CDC hidden label added. helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); echo "]
\n"; print_textarea(false, 6, 70, 630, 300, "response[$n]", $answer->response); @@ -896,14 +1674,15 @@ echo "
".get_string("description", "lesson")." $nplus1:\n"; if ($flags & LESSON_ANSWER_EDITOR) { echo " [".get_string("useeditor", "lesson").": ". - ""; + ""; //CDC hidden label added. helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); echo "]
\n"; print_textarea($usehtmleditor, 20, 70, 630, 300, "answer[$n]", $answer->answer); + use_html_editor("answer[$n]"); // switch on the editor CDC-FLAG added in this line... editor would not turn on w/o it } else { echo " [".get_string("useeditor", "lesson").": ". - ""; + ""; helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); echo "]
\n"; print_textarea(false, 10, 70, 630, 300, "answer[$n]", $answer->answer); @@ -911,33 +1690,105 @@ echo "
".get_string("jump", "lesson")." $nplus1: \n"; - lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - echo "
".get_string("correctanswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) + echo get_string("correctanswerscore", "lesson").": score\" size=\"5\">"; + } + if ($n == 3) { + echo "
".get_string("wronganswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) + echo get_string("wronganswerscore", "lesson").": score\" size=\"5\">"; + } + echo "
".get_string("jump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("score", "lesson").": score\" size=\"5\">"; + } + echo "
".get_string("jump", "lesson")." $nplus1: \n"; + lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("score", "lesson")." $nplus1: score\" size=\"5\">"; + } + echo "
".get_string("jump", "lesson")." $nplus1: \n"; + lesson_choose_from_menu($jump, "jumpto[$n]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + echo "
".get_string("answer", "lesson")." $icorrected:\n"; + echo " [".get_string("useeditor", "lesson").": ". + ""; + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea(false, 10, 70, 630, 300, "answer[$i]"); + echo "
".get_string("matchesanswer", "lesson")." $icorrected:\n"; + echo " [".get_string("useeditor", "lesson").": ". + ""; + helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); + echo "]
\n"; + print_textarea(false, 10, 70, 630, 300, "response[$i]"); + echo "
".get_string("answer", "lesson")." $iplus1:\n"; echo " [".get_string("useeditor", "lesson").": ". - ""; + ""; helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); echo "]
\n"; print_textarea(false, 10, 70, 630, 300, "answer[$i]"); echo "
".get_string("response", "lesson")." $iplus1:\n"; echo " [".get_string("useeditor", "lesson").": ". - ""; + ""; helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); echo "]
\n"; print_textarea(false, 10, 70, 630, 300, "response[$i]"); @@ -946,29 +1797,74 @@ case LESSON_BRANCHTABLE: echo "
".get_string("description", "lesson")." $iplus1:\n"; echo " [".get_string("useeditor", "lesson").": ". - ""; + ""; helpbutton("useeditor", get_string("useeditor", "lesson"), "lesson"); echo "]
\n"; print_textarea(false, 10, 70, 630, 300, "answer[$i]"); echo "
".get_string("jump", "lesson")." $iplus1: \n"; - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - echo "
".get_string("jump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("score", "lesson").": "; + } + echo "
".get_string("correctanswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) + echo get_string("correctanswerscore", "lesson").": score\" size=\"5\">"; + } + if ($i == 3) { + echo "
".get_string("wronganswerjump", "lesson").": \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", $answer->jumpto, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) + echo get_string("wronganswerscore", "lesson").": score\" size=\"5\">"; + } + + echo "
".get_string("jump", "lesson")." $iplus1: \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + echo get_string("score", "lesson")." $iplus1: "; + } + echo "
".get_string("jump", "lesson")." $iplus1: \n"; + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + echo "

" - onclick="document.editpage.redisplay.value=1;document.editpage.submit();" /> - " /> - " /> + onClick="document.editpage.redisplay.value=1;document.editpage.submit();"> + "> + ">
- 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); @@ -1028,6 +1936,18 @@ } else { $newpage->qoption = 0; } + /// CDC-FLAG /// 6/16/04 + if (isset($form->layout)) { + $newpage->layout = $form->layout; + } else { + $newpage->layout = 0; + } + if (isset($form->display)) { + $newpage->display = $form->display; + } else { + $newpage->display = 0; + } + /// CDC-FLAG /// $newpage->title = $form->title; $newpage->contents = trim($form->contents); $newpageid = insert_record("lesson_pages", $newpage); @@ -1046,6 +1966,18 @@ } else { $newpage->qoption = 0; } + /// CDC-FLAG /// 6/16/04 + if (isset($form->layout)) { + $newpage->layout = $form->layout; + } else { + $newpage->layout = 0; + } + if (isset($form->display)) { + $newpage->display = $form->display; + } else { + $newpage->display = 0; + } + /// CDC-FLAG /// $newpage->title = $form->title; $newpage->contents = trim($form->contents); $newpageid = insert_record("lesson_pages", $newpage); @@ -1059,26 +1991,63 @@ } } // 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


... - $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


... + $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")); } @@ -1242,16 +2211,43 @@ } 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"); } @@ -1260,12 +2256,6 @@ for ($i = 0; $i < $lesson->maxanswers; $i++) { // strip tags because the editor gives


... // also save any answers where the editor is (going to be) used - 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); @@ -1278,6 +2268,11 @@ $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"); } @@ -1294,13 +2289,35 @@ $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"); @@ -1321,7 +2338,6 @@ else { error("Fatal Error: Unknown Action: ".$action."\n"); } - print_footer($course); ?> diff --git a/mod/lesson/lib.php b/mod/lesson/lib.php index 07b0b62d3e..29aec7a63a 100644 --- a/mod/lesson/lib.php +++ b/mod/lesson/lib.php @@ -1,149 +1,55 @@ - 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 = "\n"; //CDC hidden label added. + if ($nothing) { + $output .= "

"; + } + if (($page->qtype!=LESSON_BRANCHTABLE)||($page->qtype==LESSON_ENDOFBRANCH)||($page->qtype==21)) { + $output .= ""; + } else { + $output .= "
  • id\">".$title."
  • \n"; + } + if($close) { + $output.="
    "; + } + 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 ""; + while ($pageid != 0) { + echo ""; + $pageid = $pages[$pageid]->nextpageid; + } + echo "
    "; + if(($pages[$pageid]->qtype != LESSON_BRANCHTABLE) && ($pages[$pageid]->qtype != LESSON_ENDOFBRANCH)) { + $output = "id."\">".$pages[$pageid]->title."\n"; + } else { + $output = "id."\">".$pages[$pageid]->title."\n"; + + if($answers = get_records_select("lesson_answers", "lessonid = $lessonid and pageid = $pageid")) { + $output .= "Jumps to: "; + $end = end($answers); + foreach ($answers as $answer) { + if ($answer->jumpto == 0) { + $output .= get_string("thispage", "lesson"); + } elseif ($answer->jumpto == LESSON_NEXTPAGE) { + $output .= get_string("nextpage", "lesson"); + } elseif ($answer->jumpto == LESSON_EOL) { + $output .= get_string("endoflesson", "lesson"); + } elseif ($answer->jumpto == LESSON_UNSEENBRANCHPAGE) { + $output .= get_string("unseenpageinbranch", "lesson"); + } elseif ($answer->jumpto == LESSON_PREVIOUSPAGE) { + $output .= get_string("previouspage", "lesson"); + } elseif ($answer->jumpto == LESSON_RANDOMPAGE) { + $output .= get_string("randompageinbranch", "lesson"); + } elseif ($answer->jumpto == LESSON_RANDOMBRANCH) { + $output .= get_string("randombranch", "lesson"); + } elseif ($answer->jumpto == LESSON_CLUSTERJUMP) { + $output .= get_string("clusterjump", "lesson"); + } else { + $output .= $pages[$answer->jumpto]->title; + } + if ($answer->id != $end->id) { + $output .= ", "; + } + } + } + } + + echo $output; + if (count($pages) > 1) { + echo "id."\">\n". + "\"move\"\n"; //CDC alt text added. + } + echo "id."\">\n". + "\"edit\"\n". + "id."\">\n". + "\"delete\"\n"; //CDC alt text added. + + echo "
    "; +} + +/*******************************************************************/ +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 .= "$label"; + $output .= " \n"; + } else { + $output .= "$label"; + } + 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 diff --git a/mod/lesson/mod.html b/mod/lesson/mod.html index ead3e6ef42..a1f4f20772 100644 --- a/mod/lesson/mod.html +++ b/mod/lesson/mod.html @@ -1,9 +1,17 @@ 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)) { @@ -19,10 +27,10 @@ $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; @@ -31,29 +39,111 @@ $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 /// ?>
    - - - +

    :

    + + - - + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + - - + + + - + + + + + + + - - + + - - + + + - + + + + + + + + + + + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + +

    :

    - +

    :

    :

    + practice, ""); + helpbutton("practice", get_string("practice", "lesson"), "lesson"); + ?> +

    :

    + usepassword, ""); + helpbutton("usepassword", get_string("usepassword", "lesson"), "lesson"); + ?> +

    :

    + + +

    :

    =0; $i--) { @@ -65,11 +155,35 @@

    :

    :

    + custom, ""); + helpbutton("custom", get_string("customscoring", "lesson"), "lesson"); + ?> +

    :

    + ongoing, ""); + helpbutton("ongoing", get_string("ongoing", "lesson"), "lesson"); + ?> +

    :

    1; $i--) { + for ($i=20; $i>1; $i--) { $numbers[$i] = $i; } choose_from_menu($numbers, "maxanswers", "$form->maxanswers", ""); @@ -78,8 +192,8 @@

    :

    :

    :

    :

    - review, ""); + helpbutton("review", get_string("displayreview", "lesson"), "lesson"); + ?> +

    :

    + nextpagedefault, ""); helpbutton("nextpageaction", get_string("actionaftercorrectanswer", "lesson"), "lesson"); ?>

    :

    :

    :

    :

    student) ?>:

    :

    - timed, ""); + helpbutton("timed", get_string("timed", "lesson"), "lesson"); + ?> +

    :

    + + +

    student) ?>:

    + retake, ""); helpbutton("retake", get_string("canretake", "lesson", $course->student), "lesson"); @@ -142,9 +290,9 @@

    :

    :

    - usemaxgrade, ""); helpbutton("handlingofretakes", get_string("handlingofretakes", "lesson"), "lesson"); @@ -152,8 +300,87 @@

    :

    :

    + tree, ""); + helpbutton("tree", get_string("treeview", "lesson"), "lesson"); + ?> +

    :

    + slideshow, ""); + helpbutton("slideshow", get_string("slideshow", "lesson"), "lesson"); + ?> +

    :

    + px + +

    :

    + px + +

    :

    + + + +

    :

    + displayleft, ""); + helpbutton("displayleft", get_string("displayleftmenu", "lesson"), "lesson"); + ?> +

    :

    + highscores, ""); + helpbutton("highscores", get_string("displayhighscores", "lesson"), "lesson"); + ?> +

    :

    + + +

    :

    available); echo " - "; @@ -161,24 +388,35 @@ ?>

    :

    :

    deadline); echo " - "; - print_time_selector("deadlinehour", "deadlineminute", $form->deadline); + print_time_selector("deadlinehour", "deadlineminute", $form->deadline); ?>

    :

    + lessondefault, ""); + helpbutton("lessondefault", get_string("lessondefault", "lesson"), "lesson"); + ?> +
    - - - - - - - -" /> + + + + + + + +">
    diff --git a/mod/lesson/reformat.php b/mod/lesson/reformat.php new file mode 100644 index 0000000000..4a4f8b438d --- /dev/null +++ b/mod/lesson/reformat.php @@ -0,0 +1,177 @@ + tags +// so that instructors can have newlines wherever they like as long as the overall format is in Aiken + + $filearray = file($filename); + /// Check for Macintosh OS line returns (ie file on one line), and fix + if (ereg("\r", $filearray[0]) AND !ereg("\n", $filearray[0])) { + $outfile = explode("\r", $filearray[0]); + } else { + $outfile = $filearray; + } + + foreach ($outfile as $line) { + // remove leading and trailing whitespace + trim($line); + // check it's length, if 0 do not output... if it is > 0 output + if ($line[0] == "\n" OR strlen($line)==0 ) { + if (count($outarray) ) { + // get the last item in the outarray + $cur_pos = (count($outarray) - 1); + $outarray[$cur_pos] = trim($outarray[$cur_pos])."
    \n"; + } + } + else { + $length=strlen($line); + if ($length==0) { + // don't do anything + } + else { + if ($line[$length-1] == "\n") { + $outarray[] = $line; + } + else { + $outarray[] = $line."\n"; + } + } + } + } + // output modified file to original + if ( is_writable($filename) ) { + + 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 diff --git a/mod/lesson/restorelib.php b/mod/lesson/restorelib.php index 5c8149fc4c..c19399a130 100644 --- a/mod/lesson/restorelib.php +++ b/mod/lesson/restorelib.php @@ -1,4 +1,4 @@ -
  • ".get_string("modulename","lesson")." \"".$lesson->name."\"
    "; + echo "
    • ".get_string("modulename","lesson")." \"".$lesson->name."\"
      "; backup_flush(300); if ($newid) { @@ -143,7 +143,7 @@ if (($i+1) % 10 == 0) { echo "."; if (($i+1) % 200 == 0) { - echo "
      "; + echo "
      "; } backup_flush(300); } @@ -213,7 +213,7 @@ if (($i+1) % 10 == 0) { echo "."; if (($i+1) % 200 == 0) { - echo "
      "; + echo "
      "; } backup_flush(300); } @@ -274,7 +274,7 @@ if (($i+1) % 50 == 0) { echo "."; if (($i+1) % 1000 == 0) { - echo "
      "; + echo "
      "; } backup_flush(300); } @@ -325,7 +325,7 @@ if (($i+1) % 50 == 0) { echo "."; if (($i+1) % 1000 == 0) { - echo "
      "; + echo "
      "; } backup_flush(300); } @@ -407,7 +407,7 @@ } break; default: - echo "action (".$log->module."-".$log->action.") unknow. Not restored
      "; //Debug + echo "action (".$log->module."-".$log->action.") unknow. Not restored
      "; //Debug break; } diff --git a/mod/lesson/styles.php b/mod/lesson/styles.php new file mode 100644 index 0000000000..74b29d4e51 --- /dev/null +++ b/mod/lesson/styles.php @@ -0,0 +1,64 @@ + diff --git a/mod/lesson/timer.js b/mod/lesson/timer.js new file mode 100644 index 0000000000..9746deeb91 --- /dev/null +++ b/mod/lesson/timer.js @@ -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 "\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(''); } + else if (document.layers) { document.write(''); } + else { old = "true"; show_clock(); } + + /*function leave() { // feable attempt to run a script when someone leaves a timed test early, failed so far + window.onunload = window.open('http://www.google.com','','toolbar=no,menubar=no,location=no,height=500,width=500'); + } + leave();*/ + + function show_clock() { + + //show clock in NS 4 + if (document.layers) + 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 += ''; + myclock += "Time is up"; + myclock += ''; + 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 += ''; + myclock += "Time remaining: "; + if (hours > 0) { + myclock += hours+":"; + } + myclock += minutes+":"+secs; + myclock += ''; + } + + if (old == "true") { + document.write(myclock); + old = "die"; return; + } + + if (document.layers) { + clockpos = document.ClockPosNS; + liveclock = clockpos.document.LiveClockNS; + liveclock.document.write(myclock); + liveclock.document.close(); + } else if (document.all) { + LiveClockIE.innerHTML = myclock; + } else if (document.getElementById) { + document.getElementById("LiveClockIE").innerHTML = myclock; + } + + if (stopclock == 0) { + setTimeout("show_clock()",1000); + } +} + diff --git a/mod/lesson/version.php b/mod/lesson/version.php index 96249faf88..64633ebdf3 100644 --- a/mod/lesson/version.php +++ b/mod/lesson/version.php @@ -1,12 +1,12 @@ -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) ?> diff --git a/mod/lesson/view.php b/mod/lesson/view.php index 3cc2dcc22c..6ac444f96b 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -1,11 +1,12 @@ -category) { + $navigation = "id\">$course->shortname ->"; + } + $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 id>$strlessons -> id\">$lesson->name", + "", "", true, "", navmenu($course, $cm)); + print_simple_box_start("center"); + echo "
      "; + echo get_string("lessonopen", "lesson", userdate($lesson->available))."
      "; + echo "id\">".get_string("returnmainmenu", "lesson").""; + echo "
      "; + print_simple_box_end(); + print_footer($course); + exit(); + } elseif (time() > $lesson->deadline) { + print_header("$course->shortname: $lesson->name", "$course->fullname", + "$navigation id>$strlessons -> id\">$lesson->name", + "", "", true, "", navmenu($course, $cm)); + print_simple_box_start("center"); + echo "
      "; + echo get_string("lessonclosed", "lesson", userdate($lesson->deadline))."
      "; + echo "id\">".get_string("returnmainmenu", "lesson").""; + echo "
      "; + 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 = "
      "; + $button .= "
      framename\" method=\"get\" action=\"$CFG->wwwroot/course/mod.php\">". + "id\" />". + "". + "
      "; + if ($action == "navigation" && $pageid != LESSON_EOL) { + $button .= "
      ". + "
      framename\" method=\"get\" action=\"$CFG->wwwroot/mod/lesson/lesson.php\">". + "id\" />". + "". + "". + "
      "; + } + $button .= "
      "; + } else { + $button = ""; + } - print_header_simple("$lesson->name", "", - "id>$strlessons -> id\">$lesson->name", - "", "", true, update_module_button($cm->id, $course->id, $strlesson), + print_header("$course->shortname: $lesson->name", "$course->fullname", + "$navigation id>$strlessons -> id\">$lesson->name", + "", "", 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 @@ -42,24 +102,105 @@ } 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 '
      '; + if($page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) { + // print the pages + echo "
      "; + echo "id\">"; + echo ""; + echo ""; + echo ""; //close lmlinks + echo"
      "; + } + echo "
      "; //close left menu + echo "
      "; //CDC chris berri for styles + } elseif ($lesson->slideshow) { + echo "
      "; + } + + /// 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 "
      \n"; + echo "id\">\n"; + echo "\n"; + echo ""; + if (isset($_POST['userpassword'])) { + echo ""; + } + echo ""; + echo ""; + + echo "
      ".get_string("loginfail", "lesson")."
      ".get_string("passwordprotectedlesson", "lesson", $lesson->name)."
      ".get_string("enterpassword", "lesson")."
      "; + echo "id';\"> "; + echo ""; + echo "
      "; + print_simple_box_end(); + exit(); + } + } + + /// CDC-FLAG /// Slideshow styles + if($lesson->slideshow) { + //echo "
      \n";//CDC Chris Berri. add the left menu theme stuff here. must match on lesson.php + echo "
      bgcolor; + height: ".$lesson->height."px; + width: ".$lesson->width."px; + overflow: auto; + border: 0px solid #ccc; + padding-right: 16px; /* for the benefit of macIE5 only */ + /* \ commented backslash hack - recover from macIE5 workarounds, it will ignore the following rule */ + padding-right: 0; + padding: 15px; + \">\n"; + } + // 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 "
      ".get_string("teacherjumpwarning", "lesson", $warningvars)."
      "; + } + } + /// 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 { @@ -69,8 +210,8 @@ 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, @@ -83,7 +224,7 @@ 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; @@ -91,19 +232,43 @@ } else { $lastpageseen = $jumpto; } - break; // only look at the latest correct attempt + break; // only look at the latest correct attempt } - if ($lastpageseen != $firstpageid) { - echo "\n"; - echo "id\" />\n"; - echo "\n"; - echo "\n"; - print_simple_box("

      ".get_string("youhaveseen","lesson")."

      ", - "center"); - echo "

         

      \n"; - echo "\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 "
      \n"; + echo "id\">\n"; + echo "\n"; + echo "\n"; + echo "\n"; /// CDC-FLAG added this line + print_simple_box("

      ".get_string("leftduringtimed", "lesson")."

      ", "center"); + echo "

      \n"; /// CDC-FLAG added document.queryform.startlastseen.value='yes' + echo "
      \n"; echo "
      ";///CDC Chris Berri added close div tag + } else { + print_simple_box_start("center"); + echo "
      "; + echo get_string("leftduringtimednoretake", "lesson"); + echo "

      id\">".get_string("returntocourse", "lesson").""; + echo "
      "; + print_simple_box_end(); + } + } else { + echo "
      \n"; + echo "id\">\n"; + echo "\n"; + echo "\n"; + echo "\n"; /// CDC-FLAG added this line + print_simple_box("

      ".get_string("youhaveseen","lesson")."

      ", + "center"); + echo "

         

      \n"; /// CDC-FLAG added document.queryform.startlastseen.value='yes' + echo "
      \n"; echo "";///CDC Chris Berri added close div tag + } print_footer($course); exit(); } @@ -114,10 +279,18 @@ break; } if (!$lesson->retake) { - redirect("../../course/view.php?id=$course->id", get_string("alreadytaken", "lesson")); + print_simple_box_start("center"); + echo "
      "; + echo get_string("noretake", "lesson"); + echo "

      id\">".get_string("returntocourse", "lesson").""; + echo "
      "; + 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")); } } @@ -125,36 +298,213 @@ 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 "
      ".get_string("teachertimerwarning", "lesson")."
      "; + } 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 "
      "; + echo "\n"; + echo "


      "; + } else { + redirect("view.php?id=$cm->id&action=navigation&pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson")); + } + // update clock when viewing a new page... no special treatment + if ((($timer->starttime + $lesson->maxtime * 60) - time()) < 60) { + echo "
      ".get_string("studentoneminwarning", "lesson"). + "
      "; + } + + 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 "
      ".get_string("teacherongoingwarning", "lesson")."
      "; + } else { + lesson_calculate_ongoing_score($lesson, $USER); + } + } + /// CDC-FLAG /// // it's not a EOB process it... - echo "
      \n"; + /// CDC-FLAG /// + if ($lesson->slideshow) { + echo ""; + if ($answer != end($answers)) { + echo ""; + } $i++; } echo '
      \n"; + } else { + echo ""; + if ($answer != end($answers)) { + echo ""; + } } echo '
      \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 "

      ".get_string("numberofpagesviewed", "lesson", $nviewed). @@ -174,134 +524,196 @@ } echo get_string("numberofcorrectanswers", "lesson", $ncorrect)."
      \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).")

      \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 "
      "; + echo ""; + echo ($lesson->name) . ""; + echo "

      "; + + /// CDC-FLAG /// + if ($lesson->slideshow) { + echo "
      "; + echo format_text($page->contents); + echo "
      "; + } else { + print_simple_box(format_text($page->contents), 'center'); + } + /// CDC-FLAG /// echo "
      \n"; // get the answers in a set order, the id order if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { echo "
      "; - echo "id\" />"; - echo ""; - echo ""; - print_simple_box_start("center"); + echo "id\">"; + echo ""; + echo ""; + /// CDC-FLAG /// + if (!$lesson->slideshow || $page->qtype != 20) { + print_simple_box_start("center"); + } + /// CDC-FLAG /// echo ''; switch ($page->qtype) { case LESSON_SHORTANSWER : case LESSON_NUMERICAL : echo "
      ".get_string("youranswer", "lesson"). - ": \n"; + ": \n"; //CDC hidden label added. echo '
      '; print_simple_box_end(); - echo "

      \n"; + if (!$lesson->slideshow) { + echo "

      \n"; + } break; case LESSON_TRUEFALSE : shuffle($answers); foreach ($answers as $answer) { - echo "
      "; - echo "id}\" />"; - echo ""; + echo "
      "; + echo "id}\">"; //CDC hidden label added. + echo ""; $options->para = false; // no

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

      '; print_simple_box_end(); - echo "

      \n"; + if (!$lesson->slideshow) { + echo "

      \n"; + } break; case LESSON_MULTICHOICE : $i = 0; shuffle($answers); foreach ($answers as $answer) { - echo "
      "; + echo "
      "; if ($page->qoption) { - // more than one answer allowed - echo "id}\" />"; + // more than one answer allowed + echo "id}\">"; //CDC hidden label added. } else { // only one answer allowed - echo "id}\" />"; + echo "id}\">"; //CDC hidden label added. } echo ""; $options->para = false; // no

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

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

      \n"; - } else { - echo "

      \n"; - } + /// CDC-FLAG /// + if (!$lesson->slideshow) { + if ($page->qoption) { + echo "

      \n"; + } else { + echo "

      \n"; + } + } + /// CDC-FLAG /// break; - + + /// CDC-FLAG /// 6/14/04 --- changed how matching works case LESSON_MATCHING : echo "
      "; // 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 ""; - } + if ($answer->response != NULL) { + echo ""; + if ($answer != end($answers)) { + echo ""; + } + } + } echo '
      "; - echo "$answer->answer: "; - echo ""; - echo "
      "; + echo "$answer->answer: "; + echo ""; + echo "

      '; print_simple_box_end(); - echo "

      \n"; + if (!$lesson->slideshow) { + echo "

      \n"; + } break; + /// CDC-FLAG /// case LESSON_BRANCHTABLE : echo "
      "; - echo ""; + echo ""; // don't suffle answers - foreach ($answers as $answer) { - echo ""; - } - echo '
      "; - echo "answer\""; - echo "onclick=\"document.answerform.jumpto.value=$answer->jumpto;document.answerform.submit();\" />"; - echo "
      '; + /// CDC-FLAG /// + if(!$lesson->slideshow) { + foreach ($answers as $answer) { + echo "
  • "; + echo "answer\""; + echo "onclick=\"document.answerform.jumpto.value=$answer->jumpto;document.answerform.submit();\">"; + echo "
    '; print_simple_box_end(); break; - + case LESSON_ESSAY : + echo "".get_string("youranswer", "lesson").":". + "\n"; //CDC hidden label added. + echo ""; + print_simple_box_end(); + if (!$lesson->slideshow) { + echo "

    \n"; + } + break; } - echo "\n"; + /// CDC-FLAG /// + if (!$lesson->slideshow) { + echo "\n"; + } + /// CDC-FLAG /// } else { // a page without answers - find the next (logical) page echo "
    \n"; - echo "id\" />\n"; - echo "\n"; + echo "id\">\n"; + echo "\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; @@ -335,72 +747,325 @@ $newpageid = LESSON_EOL; } } - echo "\n"; - echo "

    \n"; + echo "\n"; + echo "

    \n"; echo "
    \n"; } - echo "\n"; + echo "\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 "

    ".get_string("numberofpagesviewed", "lesson", $nviewed). - "

    \n"; - if ($lesson->minquestions) { - if ($nviewed < $lesson->minquestions) { - // print a warning and set nviewed to minquestions - echo "

    ".get_string("youshouldview", "lesson", - $lesson->minquestions)." ".get_string("pages", "lesson")."

    \n"; - $nviewed = $lesson->minquestions; - } - } - echo "

    ".get_string("numberofcorrectanswers", "lesson", $ncorrect). - "

    \n"; - $thegrade = intval(100 * $ncorrect / $nviewed); - echo "

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

    \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 "

    ".get_string("numberofpagesviewed", "lesson", $nviewed). + "

    \n"; + if ($lesson->minquestions) { + if ($nviewed < $lesson->minquestions) { + // print a warning and set nviewed to minquestions + echo "

    ".get_string("youshouldview", "lesson", + $lesson->minquestions)." ".get_string("pages", "lesson")."

    \n"; + $nviewed = $lesson->minquestions; + } + } + echo "

    ".get_string("numberofcorrectanswers", "lesson", $ncorrect). + "

    \n"; + $thegrade = intval(100 * $ncorrect / $nviewed); + echo "

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

    \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 "
    "; + echo get_string("displayscorewithessays", "lesson", $a); + echo "
    "; + } else { + $a->score = $score; + $a->grade = $lesson->grade; + echo "
    ".get_string("displayscorewithoutessays", "lesson", $a)."
    "; + } + } + /// 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 "

    ".get_string("displayofgrade", "lesson")."

    \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 "

    "; + if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id", "completed")) { + echo get_string("youmadehighscore", "lesson", $lesson->maxhighscores)."
    "; + echo "id&action=nameforhighscores\">".get_string("clicktopost", "lesson")."
    "; + } else { + if (!$highscores = get_records_select("lesson_high_scores", "lessonid = $lesson->id")) { + echo get_string("youmadehighscore", "lesson", $lesson->maxhighsores)."
    "; + echo "id&action=nameforhighscores\">".get_string("clicktopost", "lesson")."
    "; + } 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)."
    "; + echo "id&action=nameforhighscores\">".get_string("clicktopost", "lesson")."
    "; + } else { + echo get_string("nothighscore", "lesson", $lesson->maxhighscores)."
    "; + } + } + } + echo "
    id&action=highscores&link=1\">".get_string("viewhighscores", "lesson").""; + echo "
    "; + } + /// CDC-FLAG /// + echo "

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

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

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

    \n"; //CDC Back to the menu (course view). } + /// CDC-FLAG /// + if($lesson->slideshow) { + echo "
    \n"; //Closes Mark's big div tag? + } + + if($lesson->slideshow && $pageid != LESSON_EOL) { + if (!$lesson->displayleft) { + echo "width\" cellpadding=\"5\" cellspacing=\"5\" align=\"center\">\n"; + } else { + echo "
    width\" cellpadding=\"5\" cellspacing=\"5\">\n"; + } + switch ($page->qtype) { + case LESSON_SHORTANSWER : + case LESSON_NUMERICAL : + echo "\n"; + break; + case LESSON_TRUEFALSE : + echo "\n"; + break; + case LESSON_MULTICHOICE : + if ($page->qoption) { + echo "\n"; + } else { + echo "\n"; + } + break; + case LESSON_MATCHING : + echo "\n"; + break; + case LESSON_ESSAY : + echo "\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 ""; + // next 3 foreach loops print out the links in correct order + foreach ($nextprevious as $jump) { + if ($jump->jumpto == LESSON_PREVIOUSPAGE) { + echo ""; + } + } + echo ""; + foreach ($nextprevious as $jump) { + if ($jump->jumpto == LESSON_NEXTPAGE) { + echo ""; + } + } + echo ""; + } else { + // next 3 foreach loops print out the links in correct order + foreach ($nextprevious as $jump) { + if ($jump->jumpto == LESSON_NEXTPAGE) { + echo ""; + } + } + foreach ($otherjumps as $otherjump) { + echo ""; + } + foreach ($nextprevious as $jump) { + if ($jump->jumpto == LESSON_PREVIOUSPAGE) { + echo ""; + } + } + } + break; + } + echo "

    jumpto;document.answerform.submit();\"". + "value = \"$jump->answer\">"; + foreach ($otherjumps as $otherjump) { + echo ""; + } + echo "
    jumpto;document.answerform.submit();\"". + "value = \"$otherjump->answer\">
    jumpto;document.answerform.submit();\"". + "value = \"$jump->answer\">
    jumpto;document.answerform.submit();\"". + "value = \"$jump->answer\">
    jumpto;document.answerform.submit();\"". + "value = \"$otherjump->answer\">
    jumpto;document.answerform.submit();\"". + "value = \"$jump->answer\">
    \n"; + } + + if ($lesson->displayleft) { + echo ""; //CDC Chris Berri for styles, closes slidepos. + } elseif ($lesson->slideshow) { + echo ""; + } + /// 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; @@ -418,87 +1083,118 @@ } if (!$page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) { - // if there are no pages give teacher a blank proforma - ?> -
    - - - -
    - - - - \n"; - echo "\n"; - for ($i = 0; $i < $lesson->maxanswers; $i++) { - $iplus1 = $i + 1; - echo "\n"; - echo "\n"; - if ($i) { - // answers 2,3,4... jump to this page - echo "\n"; - } else { - // answer 1 jumps to next page - echo "\n"; - } - } - // close table and form - ?> -
    -

    :

    "; - echo get_string("pagecontents", "lesson").":
    \n"; - print_textarea($usehtmleditor, 25, 70, 630, 400, "contents"); - echo "
    ".get_string("questiontype", "lesson").": \n"; - choose_from_menu($LESSON_QUESTION_TYPE, "qtype", LESSON_MULTICHOICE, ""); - helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson"); - echo "
    ".get_string("questionoption", "lesson").":\n"; - echo " "; - helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); - echo "
    ".get_string("answer", "lesson")." $iplus1:
    \n"; - print_textarea(false, 6, 70, 630, 100, "answer[$i]"); - echo "
    ".get_string("response", "lesson")." $iplus1:
    \n"; - print_textarea(false, 6, 70, 630, 100, "response[$i]"); - echo "

    - " /> - " /> -
    -
    - id&pageid=0\">".get_string("importquestions", - "lesson")."\n"); + /// CDC-FLAG /// + // if there are no pages give teacher the option to create a new page or a new branch table + echo "
    "; + if (isteacheredit($course->id)) { + print_simple_box( "\n"; //CDC Chris Berri added. + /// CDC-FLAG /// } else { // print the pages echo "\n"; echo "id\">\n"; - echo "\n"; - echo "\n"; - echo "
    ".get_string("whatdofirst", "lesson")."
    ". + "id&pageid=0\">". + get_string("importquestions", "lesson")."
    ". + "id&action=addbranchtable&pageid=0&firstpage=1\">". + get_string("addabranchtable", "lesson")."
    ". + "id&action=addpage&pageid=0&firstpage=1\">". + get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). + "
    \n"; - if (isteacheredit($course->id)) { - echo "\n"; - } + echo "\n"; + echo "\n"; + /// CDC-FLAG /// link to grade essay questions + if (count_records("lesson_pages", "lessonid", $lesson->id, "qtype", LESSON_ESSAY) > 0) { + echo "
    id&action=essayview\">".get_string("gradeessay", "lesson")."

    "; + } + /// CDC-FLAG /// tree code - in final release, will use lang file for all text output. + // NoticeFix next two lines and bowth viewAlls + $branch = false; + $singlePage = false; + if($lesson->tree && !isset($_GET['display']) && !isset($_GET['viewAll'])) { + echo "
    "; + echo get_string("treeview", "lesson")."

    "; + echo "".get_string("viewallpages", "lesson")."

    \n"; + echo "
    id&pageid=0\">". - get_string("importquestions", "lesson")." | ". - "id&action=addbranchtable&pageid=0\">". - get_string("addabranchtable", "lesson")." | ". - "id&action=addpage&pageid=0\">". - get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). - "
    "; + lesson_print_tree($page->id, $lesson->id, $cm->id, $pixpath); + echo "
    "; + echo "
    ".get_string("viewallpages", "lesson")."\n"; + echo "
    "; + } 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 "
    ".get_string("viewallpages", "lesson")."
    \n"; + echo "".get_string("backtreeview", "lesson")."
    \n"; + echo "\n"; + if (isteacheredit($course->id)) { + /// CDC-FLAG 6/16/04 /// + echo "\n"; + /// CDC-FLAG /// + } + } else { + if($lesson->tree) { + echo "
    ".get_string("backtreeview", "lesson")."
    \n"; + } + echo "
    id&pageid=$page->prevpageid\">". + get_string("importquestions", "lesson")." | ". + "id&action=addcluster&pageid=$page->prevpageid\">". + get_string("addcluster", "lesson")." | ". + "id&action=addendofcluster&pageid=$page->prevpageid\">". + get_string("addendofcluster", "lesson")." | ". + "id&action=addbranchtable&pageid=$page->prevpageid\">". + get_string("addabranchtable", "lesson")." | ". + "id&action=addpage&pageid=$page->prevpageid\">". + get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). + "
    \n"; + if (isteacheredit($course->id)) { + /// CDC-FLAG 6/16/04 /// + echo "\n"; + /// CDC-FLAG /// + } + } + /// CDC-FLAG /// end tree code (note, there is an "}" below for an else above) echo "\n"; if (isteacheredit($course->id)) { - echo "
    id&pageid=0\">". + get_string("importquestions", "lesson")." | ". + "id&action=addcluster&pageid=0\">". + get_string("addendofcluster", "lesson")." | ". + "id&action=addbranchtable&pageid=0\">". + get_string("addabranchtable", "lesson")." | ". + "id&action=addpage&pageid=0\">". + get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). + "
    \n"; while (true) { echo "\n"; + echo "\n"; echo "\n"; @@ -506,6 +1202,9 @@ if ($answers = get_records("lesson_answers", "pageid", $page->id, "id")) { echo "\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 "\n"; echo "\n"; - break; + break; + case LESSON_MATCHING: + if ($n < 2) { + if ($answer->answer != NULL) { + if ($n == 0) { + echo "\n"; + } else { + echo "\n"; + } + } + $n++; + $i--; + } else { + echo "\n"; + echo "\n"; + } + break; case LESSON_BRANCHTABLE: echo "\n"; + /// CDC-FLAG /// + if ($page->qtype == LESSON_MATCHING) { + if ($i == 1) { + echo "\n"; + echo "\n"; + } elseif ($i == 2) { + echo "\n"; + echo "\n"; + } + } else { + if ($lesson->custom && $page->qtype != LESSON_BRANCHTABLE && $page->qtype != LESSON_ENDOFBRANCH) { + echo "\n"; + } + echo "\n"; + } $i++; } - // print_simple_box_end(); + // print_simple_box_end(); /// CDC-FLAG /// not sure if i commented this out... hehe echo "\n"; } echo "
    cellheading2\" colspan=\"2\">$page->title  \n"; if (isteacheredit($course->id)) { if ($npages > 1) { echo "id&action=move&pageid=$page->id\">\n". - "\n"; + "\"move\"\n"; //CDC alt text added. } echo "id&action=editpage&pageid=$page->id\">\n". - "\n". + "\"edit\"\n". "id&action=confirmdelete&pageid=$page->id\">\n". - "\n"; + "\"delete\"\n"; //CDC alt text added. } - echo "
    \n"; print_simple_box(format_text($page->contents), "center"); echo "
    cellheading2\" colspan=\"2\" align=\"center\">\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) { @@ -528,7 +1227,7 @@ 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 : @@ -537,28 +1236,82 @@ } echo "
    cellheading2\" align=\"right\" valign=\"top\" width=\"20%\">\n"; - if (lesson_iscorrect($page->id, $answer->jumpto)) { - // underline correct answers - echo "".get_string("answer", "lesson")." $i: \n"; - } else { - echo "".get_string("answer", "lesson")." $i: \n"; - } + /// CDC-FLAG /// 6/11/04 + if ($lesson->custom) { + // if the score is > 0, then it is correct + if ($answer->score > 0) { + echo "".get_string("answer", "lesson")." $i: \n"; + } else { + echo "".get_string("answer", "lesson")." $i: \n"; + } + } else { + if (lesson_iscorrect($page->id, $answer->jumpto)) { + // underline correct answers + echo "".get_string("answer", "lesson")." $i: \n"; + } else { + echo "".get_string("answer", "lesson")." $i: \n"; + } + } + /// CDC-FLAG /// echo "\n"; echo format_text($answer->answer); echo "
    ".get_string("response", "lesson")." $i: \n"; echo "\n"; - echo format_text($answer->response); + echo format_text($answer->response); echo "
    ".get_string("correctresponse", "lesson").": \n"; + echo "\n"; + echo format_text($answer->answer); + echo "
    ".get_string("wrongresponse", "lesson").": \n"; + echo "\n"; + echo format_text($answer->answer); + echo "
    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 "".get_string("answer", "lesson")." $i: \n"; + } else { + echo "".get_string("answer", "lesson")." $i: \n"; + } + } else { + if (lesson_iscorrect($page->id, $answer->jumpto)) { + // underline correct answers + echo "".get_string("answer", "lesson")." $i: \n"; + } else { + echo "".get_string("answer", "lesson")." $i: \n"; + } + } + echo "\n"; + echo format_text($answer->answer); + echo "
    ".get_string("matchesanswer", "lesson")." $i: \n"; + echo "\n"; + echo format_text($answer->response); + echo "
    \n"; echo "".get_string("description", "lesson")." $i: \n"; @@ -573,17 +1326,51 @@ $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 = "".get_string("notdefined", "lesson").""; } } - echo "
    ".get_string("jump", "lesson")." $i:"; - echo "\n"; - echo "$jumptitle
    ".get_string("correctanswerscore", "lesson").":"; + echo "\n"; + echo "$answer->score
    ".get_string("correctanswerjump", "lesson").":"; + echo "\n"; + echo "$jumptitle
    ".get_string("wronganswerscore", "lesson").":"; + echo "\n"; + echo "$answer->score
    ".get_string("wronganswerjump", "lesson").":"; + echo "\n"; + echo "$jumptitle
    ".get_string("score", "lesson")." $i:"; + echo "\n"; + echo "$answer->score
    ".get_string("jump", "lesson")." $i:"; + echo "\n"; + echo "$jumptitle
    cellheading2\" colspan=\"2\" align=\"center\">"; if ($page->qtype != LESSON_ENDOFBRANCH) { echo "id;". - "document.lessonpages.submit();\" />"; + "document.lessonpages.submit();\">"; } echo " 
    id&pageid=$page->id\">". - get_string("importquestions", "lesson")." | ". - "id&action=addbranchtable&pageid=$page->id\">". - get_string("addabranchtable", "lesson")." | "; + /// CDC-FLAG /// 6/16/04 + echo "
    id&pageid=$page->id\">". + get_string("importquestions", "lesson")." | ". + "id&action=addcluster&pageid=$page->id\">". + get_string("addcluster", "lesson")." | ". + "id&action=addendofcluster&pageid=$page->id\">". + get_string("addendofcluster", "lesson")." | ". + "id&action=addbranchtable&pageid=$page->id\">". + get_string("addabranchtable", "lesson")."
    "; + /// 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); } @@ -631,7 +1424,12 @@ } $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!"); } @@ -640,18 +1438,404 @@ break; } } + } /// CDC-FLAG /// end of else from above tree code!!! + echo "
    \n"; + /// CDC-FLAG /// + // NoticeFix both viewAll's + if(isset($_GET['display']) && !isset($_GET['viewAll'])) { + echo "
    ".get_string("viewallpages", "lesson")."
    \n"; + } + if($lesson->tree && (isset($_GET['display']) || isset($_GET['viewAll']))) { + echo "
    ".get_string("backtreeview", "lesson")."
    \n"; + } + /// CDC-FLAG /// print_heading("id&action=navigation\">".get_string("checknavigation", "lesson")."\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 "
    id\">Go Back to Lesson

    "; - /*************** 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 ""; + echo "cellheading2\">"; + foreach ($temp as $student) { + echo ""; + } + echo ""; + echo "
    $course->students".get_string("essays", "lesson")."".get_string("email", "lesson")."
    ".$student[0]->studentname.""; + $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 = "id&action=essaygrade&essayid=$essay->id\">".$pages[$essay->pageid]->title.""; + if ($essay->id != $end->id) { + $output .= ", "; + } + echo $output; + } + echo "id&action=emailessay&userid=".$essay->userid."\">".get_string("emailgradedessays", "lesson")."
    id&action=emailessay\">".get_string("emailallgradedessays", "lesson")."
    "; + + } + + /*******************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 "
    \n"; + echo "id\">\n"; + echo "\n"; + echo "\n"; + echo "userid."\">\n"; + + $style = "style=\"padding-left:40px;\""; + + + echo ""; + echo ""; + + $studentname = $users[$essays[$essayid]->userid]->firstname." ".$users[$essays[$essayid]->userid]->lastname; + echo ""; + echo ""; + echo ""; + + echo ""; + echo "
    ".get_string("question", "lesson").":
    "; + print_simple_box_start("left"); + echo $pages[$essays[$essayid]->pageid]->contents; + print_simple_box_end(); + echo "
    ".get_string("studentresponse", "lesson", $studentname).":
    "; + print_simple_box_start("left"); + echo $essays[$essayid]->answer; + print_simple_box_end(); + echo "
    ".get_string("comments", "lesson").":
    "; + echo "\n"; + echo "
    ".get_string("essayscore", "lesson").":
    "; + 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 "
    "; + + echo "
    "; + echo ""; + echo ""; + echo ""; + echo "
    "; + echo "
    "; + } + + /*******************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 "
    "; + echo "Please wait while updating...
    "; + + $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")."!
    "; + echo "id&action=essayview\">".get_string("continue", "lesson").""; + exit(); + } + echo "
    "; + } + + /*******************email essay **************************************/ // 6/29/04 + elseif ($action == 'emailessay') { + print_heading_with_help($lesson->name, "overview", "lesson"); + + echo "
    "; + echo "Please wait while emailing...
    "; + + 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:
    \r\n"; + $message .= $pages[$essay->pageid]->contents; + $message .= "

    \r\n\r\n"; + $message .= "Your response:
    \r\n"; + $message .= $essay->answer; + $message .= "

    \r\n\r\n"; + $message .= $USER->firstname." ".$USER->lastname."'s comments:
    \r\n"; + $message .= $essay->response; + $message .= "

    \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".".
    \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!
    "; + echo "id&action=essayview\">".get_string("continue", "lesson").""; + echo "
    "; + 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 "
    "; + $titleinfo->maxhighscores = $lesson->maxhighscores; + $titleinfo->name = $lesson->name; + echo get_string("topscorestitle", "lesson", $titleinfo)."

    "; + + if (!$highscores = get_records_select("lesson_high_scores", "lessonid = $lesson->id")) { + echo get_string("nohighscores", "lesson")."
    "; + } else { + foreach ($highscores as $highscore) { + $grade = $grades[$highscore->gradeid]->grade; + $topscores[$grade][] = $highscore->nickname; + } + krsort($topscores); + + echo ""; + echo "cellheading2\">"; + $printed = 0; + while (true) { + $temp = current($topscores); + $score = key($topscores); + $rank = $printed + 1; + sort($temp); + foreach ($temp as $student) { + echo ""; + + } + $printed++; + if (!next($topscores) || !($printed < $lesson->maxhighscores)) { + break; + } + } + echo "
    ".get_string("rank", "lesson")."$course->students".get_string("scores", "lesson")."
    $rank$student$score
    "; + } + if (isset($_GET['link'])) { + echo "
    id\">".get_string("returntocourse", "lesson").""; + } else { + echo "
    id\">".get_string("cancel", "lesson")." | id&action=navigation\">".get_string("startlesson", "lesson").""; + } + echo "
    "; + + } + /*******************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 "
    "; + echo get_string("waitpostscore", "lesson")."
    "; + + 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 "
    "; + } + /*******************name for highscores **************************************/ + elseif ($action == 'nameforhighscores') { + print_heading_with_help($lesson->name, "overview", "lesson"); + echo "
    "; + 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")."

    "; + } + } + + echo "
    "; + echo "id\">"; + echo ""; + + echo get_string("entername", "lesson").":
    "; + echo ""; + echo "
    "; + echo "
    "; + } + /*************** no man's land **************************************/ + else { + error("Fatal Error: Unknown Action: ".$action."\n"); + } /// Finish the page print_footer($course);