From: mark-nielsen Date: Sat, 25 Mar 2006 21:38:57 +0000 (+0000) Subject: [New Feature] Tabbed navigation added to lesson (similar to quiz) X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=97d2756c65f516ab75e3801e5d9d0c4269266968;p=moodle.git [New Feature] Tabbed navigation added to lesson (similar to quiz) [Added] Graceful fails added to view.php, essay grading, and reports [Changed] got rid of a lot of references to $_POST/GET/REQUEST [Fixed] In reports, it required teacheredit, should only be teacher [Changed] High scores - teachers can actually see them! Also, improved output by using print_table and print_heading [Changed] Grade essays now uses fullname() to print user names --- diff --git a/mod/lesson/action/addbranchtable.php b/mod/lesson/action/addbranchtable.php index 01a2babd58..e9218305e3 100644 --- a/mod/lesson/action/addbranchtable.php +++ b/mod/lesson/action/addbranchtable.php @@ -14,8 +14,8 @@ $jump[0] = get_string("thispage", "lesson"); $jump[LESSON_NEXTPAGE] = get_string("nextpage", "lesson"); $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson"); - if (!isset($_GET['firstpage'])) { - $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); + $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); + if (!optional_param('firstpage', 0, PARAM_INT)) { if (!$apageid = get_field("lesson_pages", "id", "lessonid", $lesson->id, "prevpageid", 0)) { error("Add page: first page not found"); } diff --git a/mod/lesson/action/addpage.php b/mod/lesson/action/addpage.php index cef9ef0c65..be77ccc5c3 100644 --- a/mod/lesson/action/addpage.php +++ b/mod/lesson/action/addpage.php @@ -9,12 +9,14 @@ // first get the preceeding page $pageid = required_param('pageid', PARAM_INT); + $qtype = optional_param('qtype', LESSON_MULTICHOICE, PARAM_INT); // set of jump array $jump = array(); $jump[0] = get_string("thispage", "lesson"); $jump[LESSON_NEXTPAGE] = get_string("nextpage", "lesson"); $jump[LESSON_PREVIOUSPAGE] = get_string("previouspage", "lesson"); + $jump[LESSON_EOL] = get_string("endoflesson", "lesson"); if(lesson_display_branch_jumps($lesson->id, $pageid)) { $jump[LESSON_UNSEENBRANCHPAGE] = get_string("unseenpageinbranch", "lesson"); $jump[LESSON_RANDOMPAGE] = get_string("randompageinbranch", "lesson"); @@ -22,9 +24,8 @@ if(lesson_display_cluster_jump($lesson->id, $pageid)) { $jump[LESSON_CLUSTERJUMP] = get_string("clusterjump", "lesson"); } - if (!isset($_GET['firstpage'])) { + if (!optional_param('firstpage', 0, PARAM_INT)) { $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"); } @@ -54,28 +55,19 @@ '.get_string("questiontype", "lesson").": \n"; echo helpbutton("questiontypes", get_string("questiontype", "lesson"), "lesson")."
"; - if (isset($_GET['qtype'])) { - $qtype = clean_param($_GET['qtype'], PARAM_INT); - lesson_qtype_menu($LESSON_QUESTION_TYPE, $qtype, - "lesson.php?id=$cm->id&action=addpage&pageid=".$pageid.$linkadd); - // NoticeFix rearraged - if ( $qtype == LESSON_SHORTANSWER || $qtype == LESSON_MULTICHOICE ) { // only display this option for Multichoice and shortanswer - echo '

'; - if ($qtype == LESSON_SHORTANSWER) { - echo "".get_string("casesensitive", "lesson").": \n"; - } else { - echo "".get_string("multianswer", "lesson").": \n"; - } - echo " "; - helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); - echo '

'; + lesson_qtype_menu($LESSON_QUESTION_TYPE, $qtype, + "lesson.php?id=$cm->id&action=addpage&pageid=".$pageid.$linkadd); + + if ( $qtype == LESSON_SHORTANSWER || $qtype == LESSON_MULTICHOICE ) { // only display this option for Multichoice and shortanswer + echo '

'; + if ($qtype == LESSON_SHORTANSWER) { + echo "".get_string("casesensitive", "lesson").": \n"; + } else { + echo "".get_string("multianswer", "lesson").": \n"; } - } else { - lesson_qtype_menu($LESSON_QUESTION_TYPE, LESSON_MULTICHOICE, - "lesson.php?id=$cm->id&action=addpage&pageid=".$pageid.$linkadd); - echo "

".get_string("multianswer", "lesson").": \n"; echo " "; helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson"); + echo '

'; } ?> @@ -88,142 +80,113 @@ print_textarea($usehtmleditor, 25,70, 630, 400, "contents"); use_html_editor("contents"); 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"; + 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"; - } + 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"; - echo "\n"; + } elseif ($i == 3) { + echo "\n"; } - break; - } - } else { - for ($i = 0; $i < $lesson->maxanswers; $i++) { - $iplus1 = $i + 1; - echo "\n"; - echo "\n"; - echo "\n"; + echo "\n"; + echo "\n"; } - echo "\n"; - } + break; } // close table and form ?> diff --git a/mod/lesson/action/continue.php b/mod/lesson/action/continue.php index 3c97eb6ad3..261de15984 100644 --- a/mod/lesson/action/continue.php +++ b/mod/lesson/action/continue.php @@ -89,9 +89,6 @@ } // record answer (if necessary) and show response (if none say if answer is correct or not) - if (empty($_POST['pageid'])) { - error("Continue: pageid missing"); - } $pageid = required_param('pageid', PARAM_INT); if (!$page = get_record("lesson_pages", "id", $pageid)) { error("Continue: Page record not found"); diff --git a/mod/lesson/action/delete.php b/mod/lesson/action/delete.php index 9d3d902193..23fa1b84bd 100644 --- a/mod/lesson/action/delete.php +++ b/mod/lesson/action/delete.php @@ -8,9 +8,6 @@ confirm_sesskey(); - if (empty($_GET['pageid'])) { - error("Delete: pageid missing"); - } $pageid = required_param('pageid', PARAM_INT); if (!$thispage = get_record("lesson_pages", "id", $pageid)) { error("Delete: page record not found"); diff --git a/mod/lesson/action/editpage.php b/mod/lesson/action/editpage.php index 3bb6d34562..5cb772fc67 100644 --- a/mod/lesson/action/editpage.php +++ b/mod/lesson/action/editpage.php @@ -14,9 +14,7 @@ error("Edit page: page record not found"); } - if (isset($_GET['qtype'])) { - $page->qtype = required_param('qtype', PARAM_INT); - } + $page->qtype = optional_param('qtype', $page->qtype, PARAM_INT); // set of jump array $jump = array(); diff --git a/mod/lesson/backuplib.php b/mod/lesson/backuplib.php index 72a4e0e32c..fa75381333 100644 --- a/mod/lesson/backuplib.php +++ b/mod/lesson/backuplib.php @@ -88,7 +88,6 @@ fwrite ($bf,full_tag("TIMED",4,false,$lesson->timed)); fwrite ($bf,full_tag("MAXTIME",4,false,$lesson->maxtime)); fwrite ($bf,full_tag("RETAKE",4,false,$lesson->retake)); - fwrite ($bf,full_tag("TREE",4,false,$lesson->tree)); fwrite ($bf,full_tag("MEDIAFILE",4,false,$lesson->mediafile)); fwrite ($bf,full_tag("SLIDESHOW",4,false,$lesson->slideshow)); fwrite ($bf,full_tag("WIDTH",4,false,$lesson->width)); @@ -404,7 +403,6 @@ fwrite ($bf,full_tag("TIMED",5,false,$default->timed)); fwrite ($bf,full_tag("MAXTIME",5,false,$default->maxtime)); fwrite ($bf,full_tag("RETAKE",5,false,$default->retake)); - fwrite ($bf,full_tag("TREE",5,false,$default->tree)); fwrite ($bf,full_tag("SLIDESHOW",5,false,$default->slideshow)); fwrite ($bf,full_tag("WIDTH",5,false,$default->width)); fwrite ($bf,full_tag("HEIGHT",5,false,$default->height)); diff --git a/mod/lesson/db/mysql.php b/mod/lesson/db/mysql.php index 480e68f5b4..38efc8c149 100644 --- a/mod/lesson/db/mysql.php +++ b/mod/lesson/db/mysql.php @@ -216,6 +216,11 @@ function lesson_upgrade($oldversion) { if ($oldversion < 2005110200) { table_column('lesson', '', 'activitylink', 'int', '10', 'unsigned', '0', 'not null', 'tree'); } + + if ($oldversion < 2006031900) { + execute_sql('ALTER TABLE '. $CFG->prefix . 'lesson DROP COLUMN tree'); + execute_sql('ALTER TABLE '. $CFG->prefix . 'lesson_default DROP COLUMN tree'); + } return true; } diff --git a/mod/lesson/db/mysql.sql b/mod/lesson/db/mysql.sql index 35f07d2179..ab2e46aa68 100644 --- a/mod/lesson/db/mysql.sql +++ b/mod/lesson/db/mysql.sql @@ -27,7 +27,6 @@ CREATE TABLE `prefix_lesson` ( `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', `activitylink` INT(10) UNSIGNED NOT NULL default '0', `mediafile` varchar(255) NOT NULL default '', `mediaheight` INT(10) UNSIGNED NOT NULL DEFAULT '100', @@ -136,7 +135,6 @@ CREATE TABLE `prefix_lesson_default` `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', diff --git a/mod/lesson/db/postgres7.php b/mod/lesson/db/postgres7.php index 39a5248c8a..f903f2b32f 100644 --- a/mod/lesson/db/postgres7.php +++ b/mod/lesson/db/postgres7.php @@ -297,6 +297,11 @@ function lesson_upgrade($oldversion) { if ($oldversion < 2005110200) { table_column('lesson', '', 'activitylink', 'INT', '10', 'unsigned', '0', 'not null', 'tree'); } + + if ($oldversion < 2006031900) { + execute_sql('ALTER TABLE '. $CFG->prefix . 'lesson DROP COLUMN tree'); + execute_sql('ALTER TABLE '. $CFG->prefix . 'lesson_default DROP COLUMN tree'); + } return true; } diff --git a/mod/lesson/db/postgres7.sql b/mod/lesson/db/postgres7.sql index 295a741925..85cbba1a6f 100644 --- a/mod/lesson/db/postgres7.sql +++ b/mod/lesson/db/postgres7.sql @@ -21,7 +21,6 @@ CREATE TABLE prefix_lesson ( timed INT NOT NULL DEFAULT '0', maxtime INT8 NOT NULL DEFAULT '0', retake INT NOT NULL default '1', - tree INT NOT NULL DEFAULT '0', activitylink INT8 NOT NULL default '0', mediafile varchar(255) NOT NULL default '', mediaheight INT NOT NULL DEFAULT '100', @@ -124,7 +123,6 @@ CREATE TABLE prefix_lesson_default timed INT NOT NULL default '0', maxtime INT8 NOT NULL default '0', retake INT NOT NULL default '1', - tree INT NOT NULL default '0', slideshow INT NOT NULL default '0', width INT8 NOT NULL default '640', height INT8 NOT NULL default '480', diff --git a/mod/lesson/import.php b/mod/lesson/import.php index a5363130f3..bbc3d25254 100644 --- a/mod/lesson/import.php +++ b/mod/lesson/import.php @@ -79,7 +79,7 @@ /// Print upload form $fileformats = get_list_of_plugins("mod/quiz/format"); - $fileformatname = array(); + $fileformatnames = array(); foreach ($fileformats as $key => $fileformat) { $formatname = get_string($fileformat, 'lesson'); if ($formatname == "[[$fileformat]]") { diff --git a/mod/lesson/lesson.php b/mod/lesson/lesson.php index 16f07f5f87..5b7e4c1ca8 100644 --- a/mod/lesson/lesson.php +++ b/mod/lesson/lesson.php @@ -57,6 +57,11 @@ "$navigation id>$strlessons -> id\">".format_string($lesson->name,true)."", "", "", true); + if ($action == 'continue' and isteacher($course->id)) { + $currenttab = 'navigation'; + include('tabs.php'); + } + // include the appropriate action (check to make sure the file is there first) if (file_exists($CFG->dirroot.'/mod/lesson/action/'.$action.'.php')) { include($CFG->dirroot.'/mod/lesson/action/'.$action.'.php'); diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index fde0e2a59a..79b31b7021 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -1110,11 +1110,9 @@ function lesson_print_tree_link_menu($page, $id, $showpages=false) { $output = ""; $class = ' class="leftmenu_not_selected_link" '; - if (isset($_REQUEST['pageid'])) { - if($page->id == $_REQUEST['pageid']) { - $class = ' class="leftmenu_selected_link" '; - } - } + if($page->id == optional_param('pageid', 0, PARAM_INT)) { + $class = ' class="leftmenu_selected_link" '; + } $output .= '
  • '; @@ -1140,6 +1138,7 @@ function lesson_print_tree_link_menu($page, $id, $showpages=false) { * @param string $pixpath Path to the pictures. * @todo $pageid does not need to be passed. Can be found in the function. $pixpath is just * $CFG->pixpath. So $CFG should be declaired globally and be used instead of passed. + * This function is only called once. It should be removed and the code inside it moved to view.php */ function lesson_print_tree($pageid, $lessonid, $cmid, $pixpath) { global $USER; diff --git a/mod/lesson/mod.html b/mod/lesson/mod.html index 487b7ab142..120f6ce6f6 100644 --- a/mod/lesson/mod.html +++ b/mod/lesson/mod.html @@ -62,9 +62,6 @@ if ($form->mode == "add") { if (!isset($form->maxtime)) { $form->maxtime = 20; } - if (!isset($form->tree)) { - $form->tree = 0; - } if (!isset($form->slideshow)) { $form->slideshow = 0; } @@ -527,18 +524,6 @@ if ($form->mode == "add") {
  • - - - - -
    ".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"; + switch ($qtype) { + case LESSON_TRUEFALSE : + for ($i = 0; $i < 2; $i++) { + $iplus1 = $i + 1; + 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"); + if($lesson->custom) { if ($i) { - // answers 2, 3, 4... jumpto this page - lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); + echo get_string("score", "lesson")." $iplus1: "; } else { - // answer 1 jumpto next page - lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); + echo get_string("score", "lesson")." $iplus1: "; } - helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); - if($lesson->custom) { - if ($i) { - echo get_string("score", "lesson")." $iplus1: "; - } else { - echo get_string("score", "lesson")." $iplus1: "; - } - } - 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("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").": "; } - break; - case LESSON_SHORTANSWER : - case LESSON_NUMERICAL : - case LESSON_MULTICHOICE : - // default code - for ($i = 0; $i < $lesson->maxanswers; $i++) { - $iplus1 = $i + 1; - echo "
    ".get_string("answer", "lesson")." $iplus1:
    \n"; + 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("response", "lesson")." $iplus1:
    \n"; + echo "
    ".get_string("matchesanswer", "lesson")." $icorrected:
    \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, ""); + } + if ($i == 2) { + 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) { - if ($i) { - echo get_string("score", "lesson")." $iplus1: "; - } else { - echo get_string("score", "lesson")." $iplus1: "; - } + 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"); - if($lesson->custom) { + break; + case LESSON_SHORTANSWER : + case LESSON_NUMERICAL : + case LESSON_MULTICHOICE : + // default code + for ($i = 0; $i < $lesson->maxanswers; $i++) { + $iplus1 = $i + 1; + 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) { - echo get_string("score", "lesson")." $iplus1: "; + // answers 2, 3, 4... jumpto this page + lesson_choose_from_menu($jump, "jumpto[$i]", 0, ""); } else { - echo get_string("score", "lesson")." $iplus1: "; + // answer 1 jumpto next page + lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, ""); } + helpbutton("jumpto", get_string("jump", "lesson"), "lesson"); + if($lesson->custom) { + if ($i) { + echo get_string("score", "lesson")." $iplus1: "; + } else { + echo get_string("score", "lesson")." $iplus1: "; + } + } + echo "
    : - tree, ""); - helpbutton("tree", get_string("treeview", "lesson"), "lesson"); - ?> -
    : diff --git a/mod/lesson/report.php b/mod/lesson/report.php index 2da379e597..dee4eba8b5 100644 --- a/mod/lesson/report.php +++ b/mod/lesson/report.php @@ -9,7 +9,8 @@ $id = required_param('id', PARAM_INT); // Course Module ID $pageid = optional_param('pageid', NULL, PARAM_INT); // Lesson Page ID - $action = optional_param('action'); // action to take + $action = optional_param('action', 'view', PARAM_ALPHA); // action to take + $nothingtodisplay = false; if (! $cm = get_record('course_modules', 'id', $id)) { error('Course Module ID was incorrect'); @@ -24,7 +25,7 @@ } if (! $attempts = get_records('lesson_attempts', 'lessonid', $lesson->id, 'timeseen')) { - error('Could not find any attempts for this lesson'); + $nothingtodisplay = true; } if (! $students = get_records_sql("SELECT DISTINCT u.* @@ -33,7 +34,7 @@ WHERE a.lessonid = '$lesson->id' and u.id = a.userid ORDER BY u.lastname")) { - error("Error: could not find users"); + $nothingtodisplay = true; } @@ -48,7 +49,7 @@ // make sure people are where they should be require_login($course->id, false); - if (!isteacheredit($course->id)) { + if (!isteacher($course->id)) { error("Must be teacher to view Reports"); } @@ -64,24 +65,37 @@ ''. ''; + if ($action == 'view') { + $navigationend = get_string("reports", "lesson"); + } else if ($action == 'detail' and !optional_param('userid', 0, PARAM_INT)) { + $navigationend = "id\">".get_string("reports", "lesson").' -> '.get_string('detailedstats', 'lesson'); + } else { + $navigationend = "id\">".get_string("reports", "lesson").' -> '.get_string('review', 'lesson'); + } + print_header($course->shortname .': '. format_string($lesson->name), $course->fullname, "$navigation id>$strlessons -> id\">".format_string($lesson->name,true)." - -> id\">".get_string("report", "lesson")."", - '', '', true, $button, - navmenu($course, $cm)); - - print_heading(get_string("lesson", "lesson", format_string($lesson->name)), "center", 5); - - // navigational links - $detaillink = "id&action=detail\">".get_string("detailedstats", "lesson").""; - $overviewlink = "id\">".get_string("overview", "lesson").""; - print_heading($overviewlink."   ".$detaillink); + -> $navigationend", '', '', true, $button, navmenu($course, $cm)); + + if (!optional_param('userid', 0, PARAM_INT)) { + $currenttab = 'reports'; + $mode = $action; + } + include('tabs.php'); + + print_heading_with_help(format_string($lesson->name,true), "overview", "lesson"); + + if ($nothingtodisplay) { + notify(get_string('nolessonattempts', 'lesson')); + print_footer($course); + exit(); + } /************************************************************************** this action is for default view and overview view **************************************************************************/ - if (empty($action) || $action == 'view') { + if ($action == 'view') { $studentdata = array(); // build an array for output diff --git a/mod/lesson/restorelib.php b/mod/lesson/restorelib.php index 53f5993732..94533e646e 100644 --- a/mod/lesson/restorelib.php +++ b/mod/lesson/restorelib.php @@ -73,7 +73,6 @@ $lesson->timed = backup_todb($info['MOD']['#']['TIMED']['0']['#']); $lesson->maxtime = backup_todb($info['MOD']['#']['MAXTIME']['0']['#']); $lesson->retake = backup_todb($info['MOD']['#']['RETAKE']['0']['#']); - $lesson->tree = backup_todb($info['MOD']['#']['TREE']['0']['#']); $lesson->mediafile = backup_todb($info['MOD']['#']['MEDIAFILE']['0']['#']); $lesson->slideshow = backup_todb($info['MOD']['#']['SLIDESHOW']['0']['#']); $lesson->width = backup_todb($info['MOD']['#']['WIDTH']['0']['#']); @@ -644,7 +643,6 @@ $default->timed = backup_todb($default_info['#']['TIMED']['0']['#']); $default->maxtime = backup_todb($default_info['#']['MAXTIME']['0']['#']); $default->retake = backup_todb($default_info['#']['RETAKE']['0']['#']); - $default->tree = backup_todb($default_info['#']['TREE']['0']['#']); $default->slideshow = backup_todb($default_info['#']['SLIDESHOW']['0']['#']); $default->width = backup_todb($default_info['#']['WIDTH']['0']['#']); $default->height = backup_todb($default_info['#']['HEIGHT']['0']['#']); diff --git a/mod/lesson/tabs.php b/mod/lesson/tabs.php new file mode 100644 index 0000000000..d00c72113a --- /dev/null +++ b/mod/lesson/tabs.php @@ -0,0 +1,80 @@ +id); + } + if (!isset($course)) { + $course = get_record('course', 'id', $lesson->course); + } + + $tabs = array(); + $row = array(); + $inactive = array(); + + +/// user attempt count for reports link hover (completed attempts - much faster) + $counts = new stdClass; + $counts->attempts = count_records('lesson_grades', 'lessonid', $lesson->id); + $counts->student = $course->student; + + $row[] = new tabobject('teacherview', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id", get_string('edit'), get_string('editlesson', 'lesson', format_string($lesson->name))); + $row[] = new tabobject('navigation', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&action=navigation", get_string('preview', 'lesson'), get_string('previewlesson', 'lesson', format_string($lesson->name))); + $row[] = new tabobject('reports', "$CFG->wwwroot/mod/lesson/report.php?id=$cm->id", get_string('reports', 'lesson'), get_string('viewreports', 'lesson', $counts)); + if (isteacheredit($course->id)) { + $row[] = new tabobject('essayview', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&action=essayview", get_string('manualgrading', 'lesson')); + } + if ($lesson->highscores) { + $row[] = new tabobject('highscores', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&action=highscores", get_string('highscores', 'lesson')); + } + + $tabs[] = $row; + +/// sub tabs for reports (overview and detail) + if ($currenttab == 'reports' and isset($mode)) { + $inactive[] = 'reports'; + $currenttab = $mode; + + $row = array(); + $row[] = new tabobject('view', "$CFG->wwwroot/mod/lesson/report.php?id=$cm->id&action=view", get_string('overview', 'lesson')); + $row[] = new tabobject('detail', "$CFG->wwwroot/mod/lesson/report.php?id=$cm->id&action=detail", get_string('detailedstats', 'lesson')); + $tabs[] = $row; + } + +/// sub tabs for teacher view (collapsed and expanded aka full) + if ($currenttab == 'teacherview') { + // use user preferences to remember which edit mode the user has selected + if (empty($mode)) { + $mode = get_user_preferences('lesson_view', 'collapsed'); + } else { + set_user_preference('lesson_view', $mode); + } + + $inactive[] = 'teacherview'; + $currenttab = $mode; + + $row = array(); + $row[] = new tabobject('collapsed', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&action=teacherview&mode=collapsed", get_string('collapsed', 'lesson')); + $row[] = new tabobject('full', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&=teacherview&mode=full", get_string('full', 'lesson')); + $tabs[] = $row; + } + + print_tabs($tabs, $currenttab, $inactive); + +?> diff --git a/mod/lesson/version.php b/mod/lesson/version.php index c446ccab64..9e09a356c7 100644 --- a/mod/lesson/version.php +++ b/mod/lesson/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2005110200; // The current module version (Date: YYYYMMDDXX) +$module->version = 2006031900; // The current module version (Date: YYYYMMDDXX) $module->requires = 2005021600; // 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 c292572093..90a6aa40c5 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -9,6 +9,9 @@ $id = required_param('id', PARAM_INT); // Course Module ID $pageid = optional_param('pageid', NULL, PARAM_INT); // Lesson Page ID + $display = optional_param('display', 0, PARAM_INT); // for teacherview action + $mode = optional_param('mode', '', PARAM_ALPHA); // for eacherview action todo use user pref + if (! $cm = get_record('course_modules', 'id', $id)) { error('Course Module ID was incorrect'); @@ -82,17 +85,17 @@ if ($action == 'navigation' && $pageid != LESSON_EOL) { $currentpageid = $pageid; // very important not to alter $pageid. if (empty($currentpageid)) { - if (!$currentpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { - error('Navigation: first page not found'); - } + $currentpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0); + } + if (!empty($currentpageid)) { // if still empty, then something is wrong + $button .= ''. + '
    '. + ''. + ''. + ''. + ''. + '
    '; } - $button .= '
    '. - '
    '. - ''. - ''. - ''. - ''. - '
    '; } $button .= '
    '; } else { @@ -104,6 +107,17 @@ $button, // took out update_module_button($cm->id, $course->id, $strlesson) and replaced it with $button navmenu($course, $cm)); + if (isteacher($course->id)) { + + if ($action == 'teacherview' and $display) { + // teacherview tab not selected when displaying a single page/question + $currenttab = ''; + } else { + $currenttab = $action; + } + include('tabs.php'); + } + // set up some general variables $usehtmleditor = can_use_html_editor(); $path = $CFG->wwwroot .'/course'; @@ -113,8 +127,8 @@ // password protected lesson code if ($lesson->usepassword && !isteacher($course->id)) { $correctpass = false; - if (isset($_POST['userpassword'])) { - if ($lesson->password == md5(trim(clean_param($_POST['userpassword'], PARAM_CLEAN)))) { + if ($password = optional_param('userpassword', '', PARAM_CLEAN)) { + if ($lesson->password == md5(trim($password))) { $USER->lessonloggedin[$lesson->id] = true; $correctpass = true; } @@ -127,17 +141,16 @@ echo '
    ' . "\n"; echo '' . "\n"; echo '' . "\n"; - echo ''; - if (isset($_POST['userpassword'])) { - echo "'; + if (optional_param('userpassword', 0, PARAM_CLEAN)) { + notify(get_string('loginfail', 'lesson')); } - echo ''; - echo ''; - - echo '
    ".get_string('loginfail', 'lesson') .'
    '. get_string('passwordprotectedlesson', 'lesson', format_string($lesson->name)) .'
    '. get_string('enterpassword', 'lesson').'
    '; - echo ''. get_string('cancel', 'lesson') .' '; - echo ' '. get_string('continue', 'lesson') .''; - echo '
    '; + echo "
    \n". + get_string('passwordprotectedlesson', 'lesson', format_string($lesson->name))."

    \n". + get_string('enterpassword', 'lesson')."

    \n"; + + echo ''. get_string('cancel', 'lesson') .' '. + ' '. get_string('continue', 'lesson') .''. + "
    \n"; print_simple_box_end(); exit(); } @@ -154,7 +167,22 @@ $timedflag = false; $attemptflag = false; if (empty($pageid)) { - // check for dependencies first + // make sure there are pages to view + if (!get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { + if (isstudent($course->id)) { + notify(get_string('lessonnotready', 'lesson', $course->teacher)); // a nice message to the student + } else { + if (!count_records('lesson_pages', 'lessonid', $lesson->id)) { + redirect('view.php?id='.$cm->id); // no pages - redirect to add pages + } else { + notify(get_string('lessonpagelinkingbroken', 'lesson')); // ok, bad mojo + } + } + print_footer($course); + exit(); + } + + // check for dependencies if ($lesson->dependency and !isteacher($course->id)) { if ($dependentlesson = get_record('lesson', 'id', $lesson->dependency)) { // lesson exists, so we can proceed @@ -495,15 +523,14 @@ } } - if (isset($_POST['startlastseen'])) { - if ($_POST['startlastseen'] == 'yes') { // continue a previous test, need to update the clock (think this option is disabled atm) - $timer->starttime = time() - ($timer->lessontime - $timer->starttime); - $timer->lessontime = time(); - } elseif ($_POST['startlastseen'] == 'no') { // starting over - // starting over, so reset the clock - $timer->starttime = time(); - $timer->lessontime = time(); - } + $startlastseen = optional_param('startlastseen', '', PARAM_ALPHA); + if ($startlastseen == 'yes') { // continue a previous test, need to update the clock (think this option is disabled atm) + $timer->starttime = time() - ($timer->lessontime - $timer->starttime); + $timer->lessontime = time(); + } else if ($startlastseen == 'no') { // starting over + // starting over, so reset the clock + $timer->starttime = time(); + $timer->lessontime = time(); } // for timed lessons, display clock @@ -879,9 +906,9 @@ echo ''; echo '
    ' . $fullbuttonhtml . '
    '; } else { - print_simple_box_start('center'); - echo $fullbuttonhtml; - print_simple_box_end(); + echo ''; + print_simple_box($fullbuttonhtml, 'center'); + echo ''; // ends the answers table } echo ''; @@ -960,11 +987,12 @@ echo "\n"; } else { // end of lesson reached work out grade + + // check to see if the student ran out of time + $outoftime = optional_param('outoftime', '', PARAM_ALPHA); if ($lesson->timed && !isteacher($course->id)) { - if (isset($_GET["outoftime"])) { - if ($_GET["outoftime"] == "normal") { - print_simple_box(get_string("eolstudentoutoftime", "lesson"), "center"); - } + if ($outoftime == 'normal') { + print_simple_box(get_string("eolstudentoutoftime", "lesson"), "center"); } } @@ -1118,20 +1146,18 @@ } } else { if ($lesson->timed) { - if (isset($_GET["outoftime"])) { - if ($_GET["outoftime"] == "normal") { - $grade = new stdClass; - $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"); - } + if ($outoftime == 'normal') { + $grade = new stdClass; + $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"); } + echo get_string("eolstudentoutoftimenoanswers", "lesson"); } } else { echo get_string("welldone", "lesson"); @@ -1223,77 +1249,17 @@ /*******************teacher view **************************************/ elseif ($action == 'teacherview') { - // link to grade essay questions and to report - if ($userattempts = get_records("lesson_attempts", "lessonid", $lesson->id)) { // just check to see if anyone has answered any questions. - $usercount = array(); - foreach ($userattempts as $userattempts) { - $usercount[$userattempts->userid] = 0; - } - $a = new stdClass; - $a->users = count($usercount); - $a->usersname = $course->students; - echo "
    id\">".get_string("viewlessonstats", "lesson", $a)."
    "; - } - if ($essaypages = get_records_select("lesson_pages", "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { // get pages that are essay - // get only the attempts that are in response to essay questions - $essaypageids = implode(",", array_keys($essaypages)); // all the pageids in comma seperated list - if ($essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($essaypageids)")) { - $studentessays = array(); - // makes an array that organizes essayattempts by grouping userid, then pageid, then try count - foreach ($essayattempts as $essayattempt) { - $studentessays[$essayattempt->userid][$essayattempt->pageid][$essayattempt->retry][] = $essayattempt; - } - $a = new stdClass; - $a->notgradedcount = 0; - $a->notsentcount = 0; - foreach ($studentessays as $studentid => $pages) { // students - $attempts = count_records('lesson_grades', 'userid', $studentid, 'lessonid', $lesson->id); - $count = 0; - foreach ($pages as $tries) { // pages - // go through each essay per page - foreach($tries as $try) { // actual attempts - if ($attempts == $count) { - break; // dont count unfinnished attempts - } - $count++; - - // make sure they didn't answer it more than the max number of attmepts - if (count($try) > $lesson->maxattempts) { - $essay = $try[$lesson->maxattempts-1]; - } else { - $essay = end($try); - } - $essayinfo = unserialize($essay->useranswer); - if ($essayinfo->graded == 0) { - $a->notgradedcount++; - } - if ($essayinfo->sent == 0) { - $a->notsentcount++; - } - } - } - } - echo "
    id&action=essayview\">".get_string("gradeessay", "lesson", $a)."

    "; - } + // set collapsed flag + if ($mode == 'collapsed') { + $collapsed = true; + } else { + $collapsed = false; } print_heading_with_help(format_string($lesson->name,true), "overview", "lesson"); // get number of pages - if ($page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) { - $npages = 1; - while (true) { - if ($page->nextpageid) { - if (!$page = get_record("lesson_pages", "id", $page->nextpageid)) { - error("Teacher view: Next page not found!"); - } - } else { - // last page reached - break; - } - $npages++; - } - } + $npages = count_records('lesson_pages', 'lessonid', $lesson->id); if (!$page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) { // if there are no pages give teacher the option to create a new page or a new branch table @@ -1312,8 +1278,6 @@ } echo ''; } else { - print_heading("id&action=navigation\">".get_string("checknavigation", - "lesson")."\n"); // print the pages echo "\n"; echo "id\" />\n"; @@ -1321,18 +1285,14 @@ echo "\n"; $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 "
    "; + if($collapsed and !$display) { + echo "
    \n"; + echo "
    \n"; lesson_print_tree($page->id, $lesson->id, $cm->id, $CFG->pixpath); - echo "
    "; - echo "
    ".get_string("viewallpages", "lesson")."\n"; - echo "
    "; + echo "
    \n"; + echo "
    \n"; } else { - if(isset($_GET['display']) && !isset($_GET['viewAll'])) { - $display = clean_param($_GET['display'], PARAM_INT); + if($display) { while(true) { if($page->id == $display && $page->qtype == LESSON_BRANCHTABLE) { @@ -1352,9 +1312,7 @@ break; } } - echo "
    ".get_string("viewallpages", "lesson")."
    \n"; - echo "".get_string("backtreeview", "lesson")."
    \n"; - echo "\n"; + echo "
    \n"; if (isteacheredit($course->id)) { echo "\n"; } - } else { - if($lesson->tree) { - echo "
    ".get_string("backtreeview", "lesson")."
    \n"; - } + } else { echo "
    id&pageid=$page->prevpageid\">". get_string("importquestions", "lesson")." | ". @@ -1368,10 +1326,7 @@ get_string("addaquestionpage", "lesson")." ".get_string("here","lesson"). "
    \n"; if (isteacheredit($course->id)) { echo "\n"; } } - /// end tree code (note, there is an "}" below for an else above) + /// end collapsed code (note, there is an "}" below for an else above) while (true) { echo "
    id&pageid=0\">". @@ -1385,7 +1340,7 @@ "
    \n"; echo "
    ".format_string($page->title)."  \n"; @@ -1644,17 +1599,9 @@ break; } } - } // end of else from above tree code!!! + } // end of else from above collapsed code!!! echo "
    \n"; - 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"; - } - print_heading("id&action=navigation\">".get_string("checknavigation", - "lesson")."\n"); } } @@ -1664,7 +1611,17 @@ // get lesson pages that are essay if (!$pages = get_records_select("lesson_pages", "lessonid = $lesson->id AND qtype = ".LESSON_ESSAY)) { - error("Error: could not find lesson pages"); + notify(get_string('noessayquestionsfound', 'lesson')); + print_footer($course); + exit(); + } + + // get only the attempts that are in response to essay questions + $pageids = implode(",", array_keys($pages)); // all the pageids in comma seperated list + if (!$essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($pageids)")) { + notify(get_string('noonehasanswered', 'lesson'));//error ("No one has answered essay questions yet..."); + print_footer($course); + exit(); } // get all the users who have taken this lesson, order by their last name @@ -1677,12 +1634,6 @@ error("Error: could not find users"); } - // get only the attempts that are in response to essay questions - $pageids = implode(",", array_keys($pages)); // all the pageids in comma seperated list - if (!$essayattempts = get_records_select("lesson_attempts", "lessonid = $lesson->id AND pageid IN($pageids)")) { - error ("No one has answered essay questions yet..."); - } - // group all the essays by userid $studentessays = array(); foreach ($essayattempts as $essay) { @@ -1691,7 +1642,6 @@ $studentessays[$essay->userid][$essay->pageid][$essay->retry][] = $essay; } - print_heading("id\">".get_string("gobacktolesson", "lesson").""); $table = new stdClass; $table->head = array($course->students, get_string("essays", "lesson"), get_string("email", "lesson")); $table->align = array("left", "left", "left"); @@ -1704,7 +1654,7 @@ // cycle through all the ids foreach ($studentids as $id) { - $studentname = $users[$id]->lastname.", ".$users[$id]->firstname; + $studentname = fullname($users[$id], true); $essaylinks = array(); // number of attempts on the lesson @@ -1783,7 +1733,7 @@ $table->align = array("left"); $table->wrap = array(); $table->width = "70%"; - $table->size = array("100%"); + $table->size = array("100%"); $table->head = array(get_string("question", "lesson")); @@ -1889,8 +1839,7 @@ confirm_sesskey(); - if (isset($_GET['userid'])) { - $userid = clean_param($_GET['userid'], PARAM_INT); + if ($userid = optional_param('userid', 0, PARAM_INT)) { $queryadd = " AND userid = ".$userid; if (! $users = get_records("user", "id", $userid)) { error("Error: could not find users"); @@ -1972,11 +1921,8 @@ if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id", "completed")) { $grades = array(); } - - echo "
    "; - $titleinfo->maxhighscores = $lesson->maxhighscores; - $titleinfo->name = format_string($lesson->name); - echo get_string("topscorestitle", "lesson", $titleinfo)."

    "; + + print_heading(get_string("topscorestitle", "lesson", $lesson->maxhighscores), 'center', 4); if (!$highscores = get_records_select("lesson_high_scores", "lessonid = $lesson->id")) { echo get_string("nohighscores", "lesson")."
    "; @@ -1986,9 +1932,16 @@ $topscores[$grade][] = $highscore->nickname; } krsort($topscores); + + $table = new stdClass; + $table->align = array('center', 'left', 'right'); + $table->wrap = array(); + $table->width = "30%"; + $table->cellspacing = '10px'; + $table->size = array('*', '*', '*'); + + $table->head = array(get_string("rank", "lesson"), $course->students, get_string("scores", "lesson")); - echo ""; - echo ""; $printed = 0; while (true) { $temp = current($topscores); @@ -1996,24 +1949,26 @@ $rank = $printed + 1; sort($temp); foreach ($temp as $student) { - echo ""; - + $table->data[] = array($rank, $student, $score); } $printed++; if (!next($topscores) || !($printed < $lesson->maxhighscores)) { break; } } - echo "
    ".get_string("rank", "lesson")."$course->students".get_string("scores", "lesson")."
    $rank$student$score
    "; + print_table($table); } - if (isset($_GET['link'])) { - echo "
    "; - } else { - echo "
    id\">".get_string("cancel", "lesson").' '. - " id&action=navigation\">".get_string("startlesson", "lesson").''; + + if (!isteacher($course->id)) { // teachers don't need the links + echo '
    '; + if (optional_param('link', 0, PARAM_INT)) { + echo "
    "; + } else { + echo "
    id\">".get_string("cancel", "lesson").' '. + " id&action=navigation\">".get_string("startlesson", "lesson").''; + } + echo "
    "; } - echo "
    "; - } /*******************update high scores **************************************/ elseif ($action == 'updatehighscores') { @@ -2084,9 +2039,8 @@ $newhighscore->lessonid = $lesson->id; $newhighscore->userid = $USER->id; $newhighscore->gradeid = $newgrade->id; - if (isset($_GET['name'])) { - $newhighscore->nickname = clean_param($_GET['name'], PARAM_CLEAN); - } + $newhighscore->nickname = optional_param('name', '', PARAM_CLEAN); + if (!insert_record("lesson_high_scores", $newhighscore)) { error("Insert of new high score Failed!"); } @@ -2098,12 +2052,11 @@ elseif ($action == 'nameforhighscores') { print_heading_with_help(format_string($lesson->name,true), "overview", "lesson"); echo "
    "; - if (isset($_POST['name'])) { - $name = trim(clean_param($_POST['name'], PARAM_CLEAN)); + if ($name = trim(optional_param('name', '', PARAM_CLEAN))) { if (lesson_check_nickname($name)) { redirect("view.php?id=$cm->id&action=updatehighscores&name=$name&sesskey=".$USER->sesskey, get_string("nameapproved", "lesson")); } else { - echo get_string("namereject", "lesson")."

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

    "; } }