From: mark-nielsen Date: Wed, 6 Sep 2006 04:04:42 +0000 (+0000) Subject: Added $Id$ to files X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c5a2e12f086aabb9cfc2140bd320ebbe99a64ff1;p=moodle.git Added $Id$ to files Header is not printed for all actions. Related to MDL-5403 Some redundant code removed First attempt at separating logic and presentation in action continue (continue.html) --- diff --git a/mod/lesson/action/addbranchtable.php b/mod/lesson/action/addbranchtable.php index e9218305e3..2d96d0f876 100644 --- a/mod/lesson/action/addbranchtable.php +++ b/mod/lesson/action/addbranchtable.php @@ -1,11 +1,7 @@ -pagepath = 'mod/lesson/addbranchtable'; - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } - // first get the preceeding page $pageid = required_param('pageid', PARAM_INT); diff --git a/mod/lesson/action/addcluster.php b/mod/lesson/action/addcluster.php index 887b5f8eee..2c4384025a 100644 --- a/mod/lesson/action/addcluster.php +++ b/mod/lesson/action/addcluster.php @@ -1,11 +1,7 @@ -id)) { - error("Only teachers can look at this page"); - } - confirm_sesskey(); // first get the preceeding page diff --git a/mod/lesson/action/addendofbranch.php b/mod/lesson/action/addendofbranch.php index da248dcbd7..330413fc34 100644 --- a/mod/lesson/action/addendofbranch.php +++ b/mod/lesson/action/addendofbranch.php @@ -1,11 +1,7 @@ -id)) { - error("Only teachers can look at this page"); - } - confirm_sesskey(); // first get the preceeding page diff --git a/mod/lesson/action/addendofcluster.php b/mod/lesson/action/addendofcluster.php index a949edf385..20b3bf00c5 100644 --- a/mod/lesson/action/addendofcluster.php +++ b/mod/lesson/action/addendofcluster.php @@ -1,11 +1,7 @@ -id)) { - error("Only teachers can look at this page"); - } - confirm_sesskey(); // first get the preceeding page diff --git a/mod/lesson/action/addpage.php b/mod/lesson/action/addpage.php index be77ccc5c3..395204d054 100644 --- a/mod/lesson/action/addpage.php +++ b/mod/lesson/action/addpage.php @@ -1,12 +1,8 @@ -pagepath = 'mod/lesson/addpage'; - if (!isteacher($course->id)) { - error("Only teachers can look at this page"); - } - // first get the preceeding page $pageid = required_param('pageid', PARAM_INT); $qtype = optional_param('qtype', LESSON_MULTICHOICE, PARAM_INT); diff --git a/mod/lesson/action/confirmdelete.php b/mod/lesson/action/confirmdelete.php index a0225767b2..38c737e35f 100644 --- a/mod/lesson/action/confirmdelete.php +++ b/mod/lesson/action/confirmdelete.php @@ -1,11 +1,7 @@ -id)) { - error("Only teachers can look at this page"); - } - confirm_sesskey(); $pageid = required_param('pageid', PARAM_INT); diff --git a/mod/lesson/action/continue.html b/mod/lesson/action/continue.html new file mode 100644 index 0000000000..e503a4ee39 --- /dev/null +++ b/mod/lesson/action/continue.html @@ -0,0 +1,107 @@ + + +displayleft) { + if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { +?> + + + +
+ +
+
+ + +
+
'; + +displayleft) +?> + +timed and !isteacher($course->id)) { + // code for the clock + print_simple_box_start("right", "150px", "#ffffff", 0); +?> + + + + + + + +
+ '); + window.onload = function () { show_clock(); } + +
"; + +



+timed) { + +// This calculates and prints the ongoing score message +if ($lesson->ongoing) { + lesson_print_ongoing_score($lesson); +} +?> + + + + +
+
+ + + + +modattempts[$lesson->id])) { ?> +



+

+ +
+

+

+ +

+ +

+review && !$correctanswer && !$noanswer && !$isessayquestion) { ?> +

+

+ +
+

+

+ +
+

+ +

+

+ +
+

+ +
+ +displayleft) { ?> +
+ \ No newline at end of file diff --git a/mod/lesson/action/continue.php b/mod/lesson/action/continue.php index 2cfaae70e4..7517373fb8 100644 --- a/mod/lesson/action/continue.php +++ b/mod/lesson/action/continue.php @@ -4,89 +4,54 @@ confirm_sesskey(); + $messages = array(); + // left menu code // check to see if the user can see the left menu if (!isteacher($course->id)) { $lesson->displayleft = lesson_displayleftif($lesson); } - if ($lesson->displayleft) { - if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) { - // print the pages - echo '
'; - // skip navigation link - echo ''; - echo "
\n"; - echo '
'.get_string('lessonmenu', 'lesson')."
\n"; - echo "\n"; - echo "
\n"; - lesson_print_tree_menu($lesson->id, $firstpageid, $cm->id); - echo "
\n"; - echo "
\n"; - echo '
'; - // skip to anchor - echo ''; - } - } - + // 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 (lesson_display_teacher_warning($lesson->id)) { - $warningvars->cluster = get_string("clusterjump", "lesson"); - $warningvars->unseen = get_string("unseenpageinbranch", "lesson"); - echo "

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

"; - } - } + if(isteacher($course->id) and lesson_display_teacher_warning($lesson->id)) { + $warningvars->cluster = get_string("clusterjump", "lesson"); + $warningvars->unseen = get_string("unseenpageinbranch", "lesson"); + $messages[] = get_string("teacherjumpwarning", "lesson", $warningvars); + } // This is the code updates the lesson time for a timed test // get time information for this user + $outoftime = false; if (!isteacher($course->id)) { if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) { error('Error: could not find records'); } else { $timer = array_pop($timer); // this will get the latest start time record } - } - $outoftime = false; - if($lesson->timed) { - if(isteacher($course->id)) { - echo "

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

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



"; - } else { - redirect("view.php?id=$cm->id&action=navigation&pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson")); - } + + if ($lesson->timed) { 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")."

"; + $messages[] = get_string("studentoneminwarning", "lesson"); + } else if (($timer->starttime + $lesson->maxtime * 60) < time()) { + $messages[] = get_string("studentoutoftime", "lesson"); $outoftime = true; } + if ((($timer->starttime + $lesson->maxtime * 60) - time()) <= 0) { + // Out of time + redirect("view.php?id=$cm->id&action=navigation&pageid=".LESSON_EOL."&outoftime=normal", get_string("outoftime", "lesson")); + } } - } - // update the clock - if (!isteacher($course->id)) { + $timer->lessontime = time(); if (!update_record("lesson_timer", $timer)) { error("Error: could not update lesson_timer table"); } } + + // Inform teacher that s/he will not see the timer + if ($lesson->timed and isteacher($course->id)) { + $messages[] = get_string("teachertimerwarning", "lesson"); + } // record answer (if necessary) and show response (if none say if answer is correct or not) $pageid = required_param('pageid', PARAM_INT); @@ -594,8 +559,6 @@ } // no need to record anything in lesson_attempts redirect("view.php?id=$cm->id&action=navigation&pageid=$newpageid"); - print_footer($course); - exit(); break; } @@ -605,7 +568,6 @@ if ($noanswer) { $newpageid = $pageid; // display same page again - print_simple_box(get_string("noanswer", "lesson"), "center"); } else { $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); if (isstudent($course->id)) { @@ -703,28 +665,24 @@ $newpageid = LESSON_EOL; } } - - // This calculates and prints the ongoing score message - if ($lesson->ongoing) { - lesson_print_ongoing_score($lesson); - } // display response (if there is one - there should be!) // display: lesson title, page title, question text, student's answer(s) before feedback message - if ($response) { + + if ($noanswer) { + $feedback = get_string("noanswer", "lesson"); + } else if ($response) { //optionally display question page title //if ($title = get_field("lesson_pages", "title", "id", $pageid)) { // print_heading($title); //} - echo "
\n"; if ($lesson->review && !$correctanswer && !$isessayquestion) { $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"); + $feedback = get_string("firstwrong", "lesson"); } else { - print_simple_box(get_string("secondpluswrong", "lesson"), "center"); + $feedback = get_string("secondpluswrong", "lesson"); } } else { if ($correctanswer) { @@ -737,12 +695,10 @@ $options = new stdClass; $options->noclean = true; $options->para = false; - print_simple_box(format_text($page->contents, FORMAT_MOODLE, $options), 'center'); - echo '
'; - print_simple_box(''.get_string("youranswer", "lesson").' : '.format_text($studentanswer, FORMAT_MOODLE, $options). - "
".format_text($response, FORMAT_MOODLE, $options), 'center').'
'; + $feedback = format_text($page->contents, FORMAT_MOODLE, $options); + $feedback .= ''.get_string("youranswer", "lesson").' : '.format_text($studentanswer, FORMAT_MOODLE, $options). + "
".format_text($response, FORMAT_MOODLE, $options).'
'; } - echo "
\n"; } } @@ -812,44 +768,17 @@ $newpageid = lesson_cluster_jump($lesson->id, $USER->id, $pageid); } } - - // NOTE: Should this code be coverted from form/javascript to just longer links with the variables in the url? - echo "
\n"; - echo "id\">\n"; - echo "\n"; - echo "\n"; - - if (isset($USER->modattempts[$lesson->id])) { - echo "

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

". - "

\n"; - echo "

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

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

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

\n"; - echo "

\n"; - } else { - echo "

\n"; - } - echo "
\n"; -/// Report attempts remaining + // Report attempts remaining if ($attemptsremaining != 0) { - echo "

".get_string('attemptsremaining', 'lesson', $attemptsremaining); - } -/// Report if max attempts reached - if ($maxattemptsreached != 0) { - echo "

(".get_string("maximumnumberofattemptsreached", "lesson").")

\n"; + $messages[] = get_string('attemptsremaining', 'lesson', $attemptsremaining); } - - if ($lesson->displayleft) { - echo "
"; + // Report if max attempts reached + if ($maxattemptsreached != 0) { + $messages[] = '('.get_string("maximumnumberofattemptsreached", "lesson").')'; } + lesson_print_header($cm, $course, $lesson, 'navigation', false); + + include($CFG->wwwroot.'/mod/lesson/action/continue.html'); ?> diff --git a/mod/lesson/action/delete.php b/mod/lesson/action/delete.php index 23fa1b84bd..2e29da39ce 100644 --- a/mod/lesson/action/delete.php +++ b/mod/lesson/action/delete.php @@ -1,11 +1,6 @@ -id)) { - error("Only teachers can look at this page"); - } - confirm_sesskey(); $pageid = required_param('pageid', PARAM_INT); @@ -13,7 +8,6 @@ error("Delete: page record not found"); } - print_string("deleting", "lesson"); // first delete all the associated records... delete_records("lesson_attempts", "pageid", $pageid); // ...now delete the answers... diff --git a/mod/lesson/action/editpage.php b/mod/lesson/action/editpage.php index 5cb772fc67..9344c1360a 100644 --- a/mod/lesson/action/editpage.php +++ b/mod/lesson/action/editpage.php @@ -1,11 +1,7 @@ -id)) { - error("Only teachers can look at this page"); - } - // get the page $pageid = required_param('pageid', PARAM_INT); $redirect = optional_param('redirect', '', PARAM_ALPHA); diff --git a/mod/lesson/action/insertpage.php b/mod/lesson/action/insertpage.php index 9643b80b69..af9e2464bb 100644 --- a/mod/lesson/action/insertpage.php +++ b/mod/lesson/action/insertpage.php @@ -1,11 +1,7 @@ -id)) { - error("Only teachers can look at this page"); - } - confirm_sesskey(); // check to see if the cancel button was pushed diff --git a/mod/lesson/action/move.php b/mod/lesson/action/move.php index 270ac8cb9e..832ef2d3f3 100644 --- a/mod/lesson/action/move.php +++ b/mod/lesson/action/move.php @@ -1,11 +1,7 @@ -id)) { - error("Only teachers can look at this page"); - } - $pageid = required_param('pageid', PARAM_INT); $title = get_field("lesson_pages", "title", "id", $pageid); print_heading(get_string("moving", "lesson", format_string($title))); diff --git a/mod/lesson/action/moveit.php b/mod/lesson/action/moveit.php index 7b0a67d837..2eaf851725 100644 --- a/mod/lesson/action/moveit.php +++ b/mod/lesson/action/moveit.php @@ -1,11 +1,7 @@ -id)) { - error("Only teachers can look at this page"); - } - confirm_sesskey(); $pageid = required_param('pageid', PARAM_INT); // page to move @@ -14,8 +10,6 @@ } $after = required_param('after', PARAM_INT); // target page - print_heading(get_string("moving", "lesson", format_string($page->title))); - // first step. determine the new first page // (this is done first as the current first page will be lost in the next step) if (!$after) { diff --git a/mod/lesson/action/updatepage.php b/mod/lesson/action/updatepage.php index e0376bb9e8..2a7da3c582 100644 --- a/mod/lesson/action/updatepage.php +++ b/mod/lesson/action/updatepage.php @@ -1,11 +1,7 @@ -id)) { - error("Only teachers can look at this page"); - } - confirm_sesskey(); $redirect = optional_param('redirect', '', PARAM_ALPHA); diff --git a/mod/lesson/lesson.php b/mod/lesson/lesson.php index c5bd8fae5e..a930ef46bc 100644 --- a/mod/lesson/lesson.php +++ b/mod/lesson/lesson.php @@ -24,56 +24,37 @@ $id = required_param('id', PARAM_INT); // Course Module ID $action = required_param('action', PARAM_ALPHA); // Action - - // get some esential stuff... - if (! $cm = get_coursemodule_from_id('lesson', $id)) { - error("Course Module ID was incorrect"); - } - - if (! $course = get_record("course", "id", $cm->course)) { - error("Course is misconfigured"); - } - - if (! $lesson = get_record("lesson", "id", $cm->instance)) { - error("Course module is incorrect"); - } + + list($cm, $course, $lesson) = lesson_get_basics($id); require_login($course->id); - if ($action != 'continue') { - // All pages except for continue.php require teacher editing privs - if (!isteacheredit($lesson->course)) { - error('You must be a teacher with editing privileges to access this page.'); - } - } - - // set up some general variables +/// Set up some general variables $usehtmleditor = can_use_html_editor(); - $navigation = ""; - if ($course->category) { - $navigation = "id\">$course->shortname ->"; - } - - $strlessons = get_string("modulenameplural", "lesson"); - $strlesson = get_string("modulename", "lesson"); - $strlessonname = $lesson->name; - - // ... print the header and... - print_header("$course->shortname: ".format_string($lesson->name), "$course->fullname", - "$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'); - } else { - error("Fatal Error: Unknown action\n"); +/// Process the action + switch ($action) { + case 'addbranchtable': + case 'addpage': + case 'confirmdelete': + case 'editpage': + case 'move': + lesson_print_header($cm, $course, $lesson, '', false); + case 'addcluster': + case 'addendofbranch': + case 'addendofcluster': + case 'delete': + case 'insertpage': + case 'updatepage': + case 'moveit': + if (!isteacheredit($course->id)) { + error('You must be a teacher with editing privileges to access this page.'); + } + case 'continue': + include($CFG->dirroot.'/mod/lesson/action/'.$action.'.php'); + break; + default: + error("Fatal Error: Unknown action\n"); } print_footer($course);