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)
This commit is contained in:
mark-nielsen
2006-09-06 04:04:42 +00:00
parent 9fcf51d9bf
commit c5a2e12f08
15 changed files with 186 additions and 221 deletions
+1 -5
View File
@@ -1,11 +1,7 @@
<?php
<?php // $Id$
/************** add branch table ************************************/
$CFG->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);
+1 -5
View File
@@ -1,11 +1,7 @@
<?php
<?php // $Id$
/************** add cluster ************************************/
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
confirm_sesskey();
// first get the preceeding page
+1 -5
View File
@@ -1,11 +1,7 @@
<?php
<?php // $Id$
/************** add end of branch ************************************/
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
confirm_sesskey();
// first get the preceeding page
+1 -5
View File
@@ -1,11 +1,7 @@
<?php
<?php // $Id$
/************** add end of cluster ************************************/
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
confirm_sesskey();
// first get the preceeding page
+1 -5
View File
@@ -1,12 +1,8 @@
<?php
<?php // $Id$
/************** add page ************************************/
$CFG->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);
+1 -5
View File
@@ -1,11 +1,7 @@
<?php
<?php // $Id$
/******************* confirm delete ************************************/
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
confirm_sesskey();
$pageid = required_param('pageid', PARAM_INT);
+107
View File
@@ -0,0 +1,107 @@
<?php // $Id$
/**
* HTML template for continue.php
*
* @version $Id$
* @package lesson
**/
?>
<?php
if ($lesson->displayleft) {
if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) {
?>
<table>
<tr valign="top">
<td>
<a href="#maincontent" class="skip"><?php print_string('skip', 'lesson') ?></a>
<div class="leftmenu_container">
<div class="leftmenu_title"><?php print_string('lessonmenu', 'lesson') ?></div>
<div class="leftmenu_courselink">
<a href="<?php echo "$CFG->wwwroot/course/view.php?id=$course->id"; ?>"><?php print_string("mainmenu", "lesson") ?></a>
</div>
<div class="leftmenu_links">
<?php lesson_print_tree_menu($lesson->id, $firstpageid, $cm->id) ?>
</div>
</div>
</td>
<td align="center" width="100%">';
<a name="maincontent" id="maincontent" title="<?php print_string('anchortitle', 'lesson') ?>"></a>
<?php
} // End if($firstpageid = get...
} // End if ($lesson->displayleft)
?>
<?php if($lesson->timed and !isteacher($course->id)) {
// code for the clock
print_simple_box_start("right", "150px", "#ffffff", 0);
?>
<table border="0" valign="top" align="center" class="generaltable" width="100%" cellspacing="0">
<tr>
<th valign="top" class="generaltableheader"><?php print_string("timeremaining", "lesson") ?></th>
</tr>
<tr>
<td align="center" class="generaltablecell">
<script language="javascript">
var starttime = "<?php echo $timer->starttime ?>";
var servertime = "<?php echo time()?>";
var testlength = "<?php echo $lesson->maxtime * 60 ?>";
document.write('<SCRIPT LANGUAGE="JavaScript" SRC="timer.js"></SCRIPT>');
window.onload = function () { show_clock(); }
</script>
</td>
</tr>
</table>";
<?php print_simple_box_end(); ?>
<br /><br /><br /><br />
<?php } //end if($lesson->timed) {
// This calculates and prints the ongoing score message
if ($lesson->ongoing) {
lesson_print_ongoing_score($lesson);
}
?>
<table border="0" align="center">
<tr>
<td><?php echo $feedback ?></td>
</tr>
</table>
<form name="pageform" method ="post" action="view.php">
<input type="hidden" name="id" value="<?php echo $cm->id ?>" />
<input type="hidden" name="action" value="navigation" />
<input type="hidden" name="pageid" value="<?php $newpageid ?>" />
<?php if (isset($USER->modattempts[$lesson->id])) { ?>
<p align="center"><?php print_string("savechangesandeol", "lesson") ?> <br /><br />
<div align="center" class="lessonbutton standardbutton">
<a href="javascript:document.pageform.pageid.value=<?php echo LESSON_EOL ?>;document.pageform.submit();"><?php print_string("savechanges", "lesson") ?></a>
</div>
</p>
<p align="center">
<?php print_string("or", "lesson") ?>
<br /><br />
<?php print_string("continuetoanswer", "lesson") ?>
</p>
<?php }
if ($lesson->review && !$correctanswer && !$noanswer && !$isessayquestion) { ?>
<p>
<div align="center" class="lessonbutton standardbutton">
<a href="javascript:document.pageform.pageid.value=<?php echo $pageid ?>;document.pageform.submit();"><?php print_string("reviewquestionback", "lesson") ?></a>
</div>
</p>
<p><div align="center" class="lessonbutton standardbutton">
<a href="javascript:document.pageform.submit();"><?php print_string("reviewquestioncontinue", "lesson") ?></a>
</div>
</p>
<?php } else { ?>
<p>
<div align="center" class="lessonbutton standardbutton">
<a href="javascript:document.pageform.submit();"><?php print_string("continue", "lesson") ?></a>
</div>
</p>
<?php } ?>
</form>
<?php if ($lesson->displayleft) { ?>
</td></tr></table>
<?php } ?>
+41 -112
View File
@@ -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 '<table><tr valign="top"><td>';
// skip navigation link
echo '<a href="#maincontent" class="skip">'.get_string('skip', 'lesson').'</a>';
echo "<div class=\"leftmenu_container\">\n";
echo '<div class="leftmenu_title">'.get_string('lessonmenu', 'lesson')."</div>\n";
echo "<div class=\"leftmenu_courselink\">\n";
echo "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">".get_string("mainmenu", "lesson")."</a>\n";
echo "</div>\n";
echo "<div class=\"leftmenu_links\">\n";
lesson_print_tree_menu($lesson->id, $firstpageid, $cm->id);
echo "</div>\n";
echo "</div>\n";
echo '</td><td align="center" width="100%">';
// skip to anchor
echo '<a name="maincontent" id="maincontent" title="'.get_string('anchortitle', 'lesson').'"></a>';
}
}
// 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 "<p align=\"center\">".get_string("teacherjumpwarning", "lesson", $warningvars)."</p>";
}
}
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 "<p align=\"center\">".get_string("teachertimerwarning", "lesson")."</p>";
} else {
if ((($timer->starttime + $lesson->maxtime * 60) - time()) > 0) {
// code for the clock
print_simple_box_start("right", "150px", "#ffffff", 0);
echo "<table border=\"0\" valign=\"top\" align=\"center\" class=\"generaltable\" width=\"100%\" cellspacing=\"0\">".
"<tr><th valign=\"top\" class=\"generaltableheader\">".get_string("timeremaining", "lesson").
"</th></tr><tr><td align=\"center\" class=\"generaltablecell\">";
echo "<script language=\"javascript\">\n";
echo "var starttime = ". $timer->starttime . ";\n";
echo "var servertime = ". time() . ";\n";
echo "var testlength = ". $lesson->maxtime * 60 .";\n";
echo "document.write('<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"timer.js\"><\/SCRIPT>');\n";
echo "window.onload = function () { show_clock(); }\n";
echo "</script>\n";
echo "</td></tr></table>";
print_simple_box_end();
echo "<br /><br /><br /><br />";
} 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 "<p align=\"center\">".get_string("studentoneminwarning", "lesson")."</p>";
} elseif (($timer->starttime + $lesson->maxtime * 60) < time()) {
echo "<p align=\"center\">".get_string("studentoutoftime", "lesson")."</p>";
$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&amp;action=navigation&amp;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 "<table width=\"80%\" border=\"0\" align=\"center\"><tr><td>\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 "<br /><br />";
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 '<br />';
print_simple_box('<em>'.get_string("youranswer", "lesson").'</em> : '.format_text($studentanswer, FORMAT_MOODLE, $options).
"<div class=\"$class\">".format_text($response, FORMAT_MOODLE, $options), 'center').'</div>';
$feedback = format_text($page->contents, FORMAT_MOODLE, $options);
$feedback .= '<em>'.get_string("youranswer", "lesson").'</em> : '.format_text($studentanswer, FORMAT_MOODLE, $options).
"<div class=\"$class\">".format_text($response, FORMAT_MOODLE, $options).'</div>';
}
echo "</td></tr></table>\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 "<form name=\"pageform\" method =\"post\" action=\"view.php\">\n";
echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"navigation\">\n";
echo "<input type=\"hidden\" name=\"pageid\" value=\"$newpageid\">\n";
if (isset($USER->modattempts[$lesson->id])) {
echo "<p align=\"center\">".
get_string("savechangesandeol", "lesson")."<br /><br />".
"<div align=\"center\" class=\"lessonbutton standardbutton\"><a href=\"javascript:document.pageform.pageid.value=".LESSON_EOL.";document.pageform.submit();\">".
get_string("savechanges", "lesson")."</a></div></p>\n";
echo "<p align=\"center\">".get_string("or", "lesson")."<br /><br />".
get_string("continuetoanswer", "lesson")."</p>\n";
}
if ($lesson->review && !$correctanswer && !$noanswer && !$isessayquestion) {
echo "<p><div align=\"center\" class=\"lessonbutton standardbutton\"><a href=\"javascript:document.pageform.pageid.value=$pageid;document.pageform.submit();\">".
get_string("reviewquestionback", "lesson")."</a></div></p>\n";
echo "<p><div align=\"center\" class=\"lessonbutton standardbutton\"><a href=\"javascript:document.pageform.submit();\">".
get_string("reviewquestioncontinue", "lesson")."</a></div></p>\n";
} else {
echo "<p><div align=\"center\" class=\"lessonbutton standardbutton\"><a href=\"javascript:document.pageform.submit();\">".
get_string("continue", "lesson")."</a></div></p>\n";
}
echo "</form>\n";
/// Report attempts remaining
// Report attempts remaining
if ($attemptsremaining != 0) {
echo "<p align=\"center\">".get_string('attemptsremaining', 'lesson', $attemptsremaining);
$messages[] = get_string('attemptsremaining', 'lesson', $attemptsremaining);
}
/// Report if max attempts reached
if ($maxattemptsreached != 0) {
echo "<p align=\"center\">(".get_string("maximumnumberofattemptsreached", "lesson").")</p>\n";
}
if ($lesson->displayleft) {
echo "</td></tr></table>";
// 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');
?>
+1 -7
View File
@@ -1,11 +1,6 @@
<?php
<?php // $Id$
/******************* delete ************************************/
if (!isteacher($course->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...
+1 -5
View File
@@ -1,11 +1,7 @@
<?php
<?php // $Id$
/************** edit page ************************************/
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
// get the page
$pageid = required_param('pageid', PARAM_INT);
$redirect = optional_param('redirect', '', PARAM_ALPHA);
+1 -5
View File
@@ -1,11 +1,7 @@
<?php
<?php // $Id$
/****************** insert page ************************************/
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
confirm_sesskey();
// check to see if the cancel button was pushed
+1 -5
View File
@@ -1,11 +1,7 @@
<?php
<?php // $Id$
/****************** move ************************************/
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
$pageid = required_param('pageid', PARAM_INT);
$title = get_field("lesson_pages", "title", "id", $pageid);
print_heading(get_string("moving", "lesson", format_string($title)));
+1 -7
View File
@@ -1,11 +1,7 @@
<?php
<?php // $Id$
/****************** moveit ************************************/
if (!isteacher($course->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) {
+1 -5
View File
@@ -1,11 +1,7 @@
<?php
<?php // $Id$
/****************** update page ************************************/
if (!isteacher($course->id)) {
error("Only teachers can look at this page");
}
confirm_sesskey();
$redirect = optional_param('redirect', '', PARAM_ALPHA);
+26 -45
View File
@@ -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 = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->";
}
$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 <a href=index.php?id=$course->id>$strlessons</a> ->
<a href=\"view.php?id=$cm->id\">".format_string($lesson->name,true)."</a>", "", "", 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);