In order to ensure that when a teacher hides a resource or an activity that students...
authorgustav_delius <gustav_delius>
Wed, 16 Feb 2005 10:40:48 +0000 (10:40 +0000)
committergustav_delius <gustav_delius>
Wed, 16 Feb 2005 10:40:48 +0000 (10:40 +0000)
(While I was at it I also turned the autologinguests off for most module pages, except on the index.php pages and the view.php pages for those modules that allow guests)

96 files changed:
lib/moodlelib.php
mod/assignment/submissions.php
mod/assignment/upload.php
mod/assignment/version.php
mod/assignment/view.php
mod/attendance/add.php
mod/attendance/version.php
mod/attendance/view.php
mod/chat/gui_header_js/index.php
mod/chat/gui_sockets/index.php
mod/chat/report.php
mod/chat/version.php
mod/chat/view.php
mod/choice/report.php
mod/choice/version.php
mod/choice/view.php
mod/dialogue/dialogues.php
mod/dialogue/version.php
mod/dialogue/view.php
mod/exercise/assessments.php
mod/exercise/submissions.php
mod/exercise/upload.php
mod/exercise/version.php
mod/exercise/view.php
mod/forum/discuss.php
mod/forum/index.php
mod/forum/lib.php
mod/forum/post.php
mod/forum/search.php
mod/forum/subscribe.php
mod/forum/subscribers.php
mod/forum/version.php
mod/forum/view.php
mod/glossary/approve.php
mod/glossary/comment.php
mod/glossary/comments.php
mod/glossary/deleteentry.php
mod/glossary/edit.php
mod/glossary/editcategories.php
mod/glossary/export.php
mod/glossary/formats.php
mod/glossary/import.php
mod/glossary/print.php
mod/glossary/rate.php
mod/glossary/showentry.php
mod/glossary/version.php
mod/journal/edit.php
mod/journal/report.php
mod/journal/version.php
mod/journal/view.php
mod/lesson/import.php
mod/lesson/lesson.php
mod/lesson/report.php
mod/lesson/version.php
mod/lesson/view.php
mod/quiz/attempt.php
mod/quiz/category.php
mod/quiz/edit.php
mod/quiz/export.php
mod/quiz/import.php
mod/quiz/multiple.php
mod/quiz/question.php
mod/quiz/questiontypes/datasetdependent/categorydatasetdefinitions.php
mod/quiz/report.php
mod/quiz/review.php
mod/quiz/version.php
mod/quiz/view.php
mod/resource/fetch.php
mod/resource/lib.php
mod/resource/version.php
mod/scorm/cmi.php
mod/scorm/index.php
mod/scorm/playscorm.php
mod/scorm/report.php
mod/scorm/scormAPI.php
mod/scorm/version.php
mod/scorm/view.php
mod/survey/details.php
mod/survey/download.php
mod/survey/graph.php
mod/survey/report.php
mod/survey/save.php
mod/survey/version.php
mod/survey/view.php
mod/wiki/admin.php
mod/wiki/version.php
mod/wiki/view.php
mod/workshop/assess.php
mod/workshop/assessments.php
mod/workshop/index.php
mod/workshop/submissions.php
mod/workshop/upload.php
mod/workshop/version.php
mod/workshop/view.php
mod/workshop/viewassessment.php
version.php

index 0565dc3..c82050c 100644 (file)
@@ -899,11 +899,19 @@ function sesskey() {
 }
 
 /**
+ * This function checks that the current user is logged in and has the
+ * required privileges
+ *
  * This function checks that the current user is logged in, and optionally
- * whether they are "logged in" or allowed to be in a particular course.
- * If not, then it redirects them to the site login or course enrolment.
- * $autologinguest determines whether visitors should automatically be
- * logged in as guests provide {@link $CFG}->autologinguests is set to 1
+ * whether they are allowed to be in a particular course and view a particular
+ * course module.
+ * If they are not logged in, then it redirects them to the site login unless
+ * $autologinguest is set and {@link $CFG}->autologinguests is set to 1 in which 
+ * case they are automatically logged in as guests.
+ * If $courseid is given and the user is not enrolled in that course then the
+ * user is redirected to the course enrolment page.
+ * If $cm is given and the coursemodule is hidden and the user is not a teacher
+ * in the course then the user is redirected to the course home page.
  *
  * @uses $CFG
  * @uses $SESSION
@@ -911,11 +919,11 @@ function sesskey() {
  * @uses $FULLME
  * @uses SITEID
  * @uses $MoodleSession
- * @param int $courseid The course in question
- * @param boolean $autologinguest ?
- * @todo Finish documenting this function
+ * @param int $courseid id of the course
+ * @param boolean $autologinguest 
+ * @param $cm course module object
  */
-function require_login($courseid=0, $autologinguest=true) {
+function require_login($courseid=0, $autologinguest=true, $cm=null) {
 
     global $CFG, $SESSION, $USER, $FULLME, $MoodleSession;
 
@@ -988,8 +996,11 @@ function require_login($courseid=0, $autologinguest=true) {
 
     // Next, check if the user can be in a particular course
     if ($courseid) {
-        if ($courseid == SITEID) {
-            return;   // Anyone can be in the site course
+        if ($courseid == SITEID) { // Anyone can be in the site course
+            if (isset($cm) and !$cm->visible and !isteacher(SITEID)) { // Not allowed to see module, send to course page
+                redirect($CFG->wwwroot.'/course/view.php?id='.$cm->course, get_string('activityiscurrentlyhidden'));
+            }
+            return;   
         }
         if (!empty($USER->student[$courseid]) or !empty($USER->teacher[$courseid]) or !empty($USER->admin)) {
             if (isset($USER->realuser)) {   // Make sure the REAL person can also access this course
@@ -998,6 +1009,9 @@ function require_login($courseid=0, $autologinguest=true) {
                     notice(get_string('studentnotallowed', '', fullname($USER, true)), $CFG->wwwroot .'/');
                 }
             }
+            if (isset($cm) and !$cm->visible and !isteacher($courseid)) { // Not allowed to see module, send to course page
+                redirect($CFG->wwwroot.'/course/view.php?id='.$cm->course, get_string('activityiscurrentlyhidden'));
+            }
             return;   // user is a member of this course.
         }
         if (! $course = get_record('course', 'id', $courseid)) {
@@ -1014,6 +1028,9 @@ function require_login($courseid=0, $autologinguest=true) {
                     notice(get_string('guestsnotallowed', '', $course->fullname), "$CFG->wwwroot/login/index.php");
                     break;
                 case 1: // Guests allowed
+                    if (isset($cm) and !$cm->visible) { // Not allowed to see module, send to course page
+                        redirect($CFG->wwwroot.'/course/view.php?id='.$cm->course, get_string('activityiscurrentlyhidden'));
+                    }
                     return;
                 case 2: // Guests allowed with key (drop through)
                     break;
@@ -1036,6 +1053,9 @@ function require_login($courseid=0, $autologinguest=true) {
             }
             $guest_name = fullname($USER, true);
             add_to_log($course->id, "course", "loginas", "../user/view.php?id=$course->id&$USER->id$", "$realname -> $guest_name");
+            if (isset($cm) and !$cm->visible) { // Not allowed to see module, send to course page
+                redirect($CFG->wwwroot.'/course/view.php?id='.$cm->course, get_string('activityiscurrentlyhidden'));
+            }
             return;
         }
 
@@ -1055,13 +1075,13 @@ function require_login($courseid=0, $autologinguest=true) {
  * @param int $courseid The course in question
  * @param boolean $autologinguest Allow autologin guests if that is wanted
  */
-function require_course_login($course, $autologinguest=true) {
+function require_course_login($course, $autologinguest=true, $cm=null) {
     global $CFG;
     if ($CFG->forcelogin) {
         require_login();
     }
     if ($course->category) {
-        require_login($course->id, $autologinguest);
+        require_login($course->id, $autologinguest, $cm);
     }
 }
 
index b80603b..13910fb 100644 (file)
@@ -4,7 +4,7 @@
     require_once("lib.php");
 
     require_variable($id);    // Assignment
-    optional_variable($sort, "timemodified"); 
+    optional_variable($sort, "timemodified");
     optional_variable($dir, "DESC");
     optional_variable($timenow, 0);
 
@@ -21,7 +21,7 @@
         error("Course Module ID was incorrect");
     }
 
-    require_login($course->id);
+    require_login($course->id, false, $cm);
 
     if (!isteacher($course->id)) {
         error("Only teachers can look at this page");
@@ -33,8 +33,8 @@
     $strsaveallfeedback = get_string("saveallfeedback", "assignment");
 
     print_header_simple($assignment->name, "",
-                 "<a href=\"index.php?id=$course->id\">$strassignments</a> -> 
-                  <a href=\"view.php?a=$assignment->id\">$assignment->name</a> -> $strsubmissions", 
+                 "<a href=\"index.php?id=$course->id\">$strassignments</a> ->
+                  <a href=\"view.php?a=$assignment->id\">$assignment->name</a> -> $strsubmissions",
                   "", "", true, update_module_button($cm->id, $course->id, $strassignment), navmenu($course, $cm));
 
 /// Check to see if groups are being used in this assignment
 
 /// If data is being submitted, then process it
     if ($data = data_submitted()) {
-       
+
         $feedback = array();
         // Peel out all the data from variable names.
         foreach ($data as $key => $val) {
             if (!in_array($key, array("id", "timenow"))) {
                 $type = substr($key,0,1);
-                $num  = substr($key,1); 
+                $num  = substr($key,1);
                 $feedback[$num][$type] = $val;
             }
         }
                 // Make sure that we aren't overwriting any recent feedback from other teachers. (see bug #324)
                 if ($timewas < $submission->timemarked && (!empty($submission->grade)) && (!empty($submission->comment))) {
                     notify(get_string("failedupdatefeedback", "assignment", fullname($users[$submission->userid]))
-                    . "<br />" . get_string("grade") . ": $newsubmission->grade" 
+                    . "<br />" . get_string("grade") . ": $newsubmission->grade"
                     . "<br />" . get_string("feedback", "assignment") . ": $newsubmission->comment\n");
                 } else { //print out old feedback and grade
                     if (empty($submission->timemodified)) {   // eg for offline assignments
         echo "<input type=\"submit\" value=\"$strsaveallfeedback\" />";
         echo "</center>";
     }
-    
+
     $grades = make_grades_menu($assignment->grade);
 
     foreach ($submissions as $submission) {
         echo "</center>";
         echo "</form>";
     }
-    
+
     print_footer($course);
+
 ?>
index b8bbe01..fb73f96 100644 (file)
         error("Course Module ID was incorrect");
     }
 
-    require_login($course->id);
+    require_login($course->id, false, $cm);
 
     $strassignments = get_string("modulenameplural", "assignment");
     $strassignment  = get_string("modulename", "assignment");
     $strupload      = get_string("upload");
 
     print_header_simple("$assignment->name : $strupload", "",
-                 "<a href=index.php?id=$course->id>$strassignments</a> -> 
-                  <a href=\"view.php?a=$assignment->id\">$assignment->name</a> -> $strupload", 
+                 "<a href=index.php?id=$course->id>$strassignments</a> ->
+                  <a href=\"view.php?a=$assignment->id\">$assignment->name</a> -> $strupload",
                   "", "", true);
 
     if ($submission = get_record("assignment_submissions", "assignment", $assignment->id, "userid", $USER->id)) {
@@ -62,7 +62,7 @@
             } else {
                 notify(get_string("uploadnotregistered", "assignment", $newfile_name) );
             }
-        } 
+        }
     }
     // upload class will take care of printing out errors.
 
index 972f962..fd2ff23 100644 (file)
@@ -5,8 +5,8 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2005010500;
-$module->requires = 2004091700;  // Requires this Moodle version
+$module->version  = 2005021600;
+$module->requires = 2005021600;  // Requires this Moodle version
 $module->cron     = 60;
 
 ?>
index 351c14f..62e1abe 100644 (file)
@@ -14,7 +14,7 @@
         if (! $course = get_record("course", "id", $cm->course)) {
             error("Course is misconfigured");
         }
-    
+
         if (! $assignment = get_record("assignment", "id", $cm->instance)) {
             error("Course module is incorrect");
         }
@@ -31,7 +31,7 @@
         }
     }
 
-    require_course_login($course);
+    require_course_login($course, true, $cm);
 
     add_to_log($course->id, "assignment", "view", "view.php?id=$cm->id", $assignment->id, $cm->id);
 
@@ -39,7 +39,7 @@
     $strassignment  = get_string("modulename", "assignment");
 
     print_header_simple($assignment->name, "",
-                 "<a href=\"index.php?id=$course->id\">$strassignments</a> -> $assignment->name", 
+                 "<a href=\"index.php?id=$course->id\">$strassignments</a> -> $assignment->name",
                   "", "", true, update_module_button($cm->id, $course->id, $strassignment), navmenu($course, $cm));
 
     if (isteacher($course->id)) {
             } else {
                 print_heading(get_string("notsubmittedyet","assignment"));
             }
-        
+
             echo '<hr size="1" noshade="noshade" />';
-        
+
             if ($submission and $submission->timemarked) {
                 print_heading(get_string("submissionfeedback", "assignment").":", "center");
                 if (isset($scalegrades)) {
             }
         }
     }
-    
+
     print_footer($course);
 
 ?>
index 0950961..e4bc654 100644 (file)
@@ -17,7 +17,7 @@ if (isset($_POST["course"]))  {
       $mod = (object)$_POST;
   }
 
-  if (isset($cancel)) {  
+  if (isset($cancel)) {
       if (!empty($SESSION->returnpage)) {
           $return = $SESSION->returnpage;
           unset($SESSION->returnpage);
@@ -40,30 +40,30 @@ if (isset($_POST["course"]))  {
 
 /* // set the information for the new instances
      $attendance->dynsection = !empty($attendance->dynsection) ? 1 : 0;
-     $attendance->day = make_timestamp($attendance->theyear, 
-                       $attendance->themonth, $attendance->theday); 
+     $attendance->day = make_timestamp($attendance->theyear,
+            $attendance->themonth, $attendance->theday);
      $attendance->name=userdate($attendance->day, get_string("strftimedate"));
-        if ($attendance->notes) { 
-               $attendance->name = $attendance->name . " - " . $attendance->notes;
-        }
+     if ($attendance->notes) {
+        $attendance->name = $attendance->name . " - " . $attendance->notes;
+     }
 */
   $curdate = make_timestamp($mod->startyear, $mod->startmonth, $mod->startday);
   $stopdate = make_timestamp($mod->endyear, $mod->endmonth, $mod->endday);
-  $enddate = $curdate + $mod->numsections * 604800;  
+  $enddate = $curdate + $mod->numsections * 604800;
   if ($curdate > $stopdate) {
-       error(get_string("endbeforestart", "attendance"));
-       }
+    error(get_string("endbeforestart", "attendance"));
+    }
   if ($enddate < $curdate) {
-       error(get_string("startafterend", "attendance"));
-       }
+    error(get_string("startafterend", "attendance"));
+    }
   if ($stopdate > $enddate) {
       // if stop date is after end of course, just move it to end of course
-                       $stopdate = $enddate;
-       }
+            $stopdate = $enddate;
+    }
   while ($curdate <= $stopdate) {
     $mod->day = $curdate;
     $mod->name=userdate($mod->day, get_string("strftimedate"));
-         if (isset($mod->notes)) {$mod->name = $mod->name . " - " . $mod->notes;}
+      if (isset($mod->notes)) {$mod->name = $mod->name . " - " . $mod->notes;}
     switch(userdate($curdate, "%u")) {
       case 1: if (!empty($mod->mon)) {attendance_add_module($mod);}break;
       case 2: if (!empty($mod->tue)) {attendance_add_module($mod);}break;
@@ -75,7 +75,7 @@ if (isset($_POST["course"]))  {
     } // switch
     $curdate = $curdate + 86400; // add one day to the date
   } // while for days
-      
+
   if (!empty($SESSION->returnpage)) {
       $return = $SESSION->returnpage;
       unset($SESSION->returnpage);
@@ -84,13 +84,13 @@ if (isset($_POST["course"]))  {
       redirect("index.php?id=$mod->course");
   }
   exit;
-  
+
 } else {
 /// -----------------------------------------------------------------------------------
 /// ------------------ SECTION FOR MAKING THE FORM TO BE POSTED -----------------------
 /// -----------------------------------------------------------------------------------
 
-/// @include_once("$CFG->dirroot/mod/attendance/lib.php"); 
+/// @include_once("$CFG->dirroot/mod/attendance/lib.php");
 /// error_reporting(E_ALL);
 
         require_variable($id);
@@ -132,8 +132,8 @@ if (isset($_POST["course"]))  {
 
     if ($course->category) {
         print_header("$course->shortname: $streditinga", "$course->fullname",
-                     "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> -> 
-                      <a href=\"$CFG->wwwroot/mod/$module->name/index.php?id=$course->id\">$strmodulenameplural</a> -> 
+                     "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</a> ->
+                      <a href=\"$CFG->wwwroot/mod/$module->name/index.php?id=$course->id\">$strmodulenameplural</a> ->
                       $streditinga", "form.name", "", false);
     } else {
         print_header("$course->shortname: $streditinga", "$course->fullname",
@@ -148,7 +148,7 @@ if (isset($_POST["course"]))  {
         print_heading_with_help($pageheading, "mods", $module->name, $icon);
         print_simple_box_start('center');
 
+
 /// Print the main part of the page
 
    // adaptation of mod code to view code needs this:
@@ -255,7 +255,7 @@ for ($i=2;$i<=24;$i++){ $opt[$i] = $i; } ?>
 for ($i=0;$i<=100;$i++){ $opt2[$i] = $i; } ?>
 <tr valign=top>
     <td align=right><p><b><?php print_string("maxgradevalue", "attendance") ?>:</b></p></td>
-    <td  colspan="3" align="left"><?php choose_from_menu($opt2, "maxgrade", $form->maxgrade, "0","","0"); 
+    <td  colspan="3" align="left"><?php choose_from_menu($opt2, "maxgrade", $form->maxgrade, "0","","0");
    helpbutton("maxgrade", get_string("maxgradevalue","attendance"), "attendance");
 ?></td>
 </tr>
index a908468..eecfc99 100644 (file)
@@ -5,8 +5,8 @@
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2004111200;  // The current module version (Date: YYYYMMDDXX)
-$module->requires = 2004052505;  // Requires this Moodle version
+$module->version  = 2005021600;  // The current module version (Date: YYYYMMDDXX)
+$module->requires = 2005021600;  // Requires this Moodle version
 $module->cron     = 3600;        // Period for cron to check this module (secs)
 
 ?>
index 1097176..1555cff 100644 (file)
@@ -9,7 +9,7 @@
     if ($id) {
         if (! $cm = get_record("course_modules", "id", $id)) {
             error("Course Module ID was incorrect");
-        }   
+        }
         if (! $course = get_record("course", "id", $cm->course)) {
             error("Course is misconfigured");
         }
@@ -28,7 +28,7 @@
         }
     }
 
-    require_login($course->id);
+    require_login($course->id, true, $cm);
 
     add_to_log($course->id, "attendance", "view", "view.php?id=$cm->id", $attendance->id, $cm->id);
 
@@ -39,8 +39,8 @@
     $strteacheredit = get_string("teacheredit", "attendance");
 
     print_header_simple($attendance->name, "",
-                 "<a href=index.php?id=$course->id>$strattendances</a> -> $attendance->name", 
-                  "", "", true, update_module_button($cm->id, $course->id, $strattendance), 
+                 "<a href=index.php?id=$course->id>$strattendances</a> -> $attendance->name",
+                  "", "", true, update_module_button($cm->id, $course->id, $strattendance),
                   navmenu($course, $cm));
 
 /// Print the main part of the page
@@ -66,9 +66,9 @@
      }
    } else {
        $sroll = array(); //just to set default value
-   }    
+   }
 
-   // get the list of attendance records for all hours of the given day and 
+   // get the list of attendance records for all hours of the given day and
    // put it in the array for use in the attendance table
     $strviewall = get_string("viewall", "attendance");
     $strviewweek = get_string("viewweek", "attendance");
   $i=0;
   $A = get_string("absentshort","attendance");
   $T = get_string("tardyshort","attendance");
-  $P = get_string("presentshort","attendance");  
-  
+  $P = get_string("presentshort","attendance");
+
 
   if ($students) foreach ($students as $student) {
     echo "<tr><td align=\"left\" nowrap class=\"generaltablecell\" style=\"border-top: 1px solid;\">".$student->lastname."</td>\n";
   }
   /// ending for the table
   echo "</table></td></tr></table>\n";
-  
-  
+
+
   /// print the miscellaneous settings information before the attendance roll
   echo "<center><table align=\"center\" width=\"80\" class=\"generalbox\"".
     "border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>".
index 330ab95..daad433 100644 (file)
@@ -18,7 +18,7 @@
         error('Course Module ID was incorrect');
     }
 
-    require_login($course->id);
+    require_login($course->id, false, $cm);
 
     if (isguest()) {
         error('Guest does not have access to chat rooms');
index 8280f99..94f322c 100644 (file)
@@ -18,7 +18,7 @@
         error('Course Module ID was incorrect');
     }
 
-    require_login($course->id);
+    require_login($course->id, false, $cm);
 
     if (isguest()) {
         error('Guest does not have access to chat rooms');
index 46f6f1e..44ad5f6 100644 (file)
@@ -21,7 +21,7 @@
         error('Course is misconfigured');
     }
 
-    require_login($course->id);
+    require_login($course->id, false, $cm);
 
     $isteacher     = isteacher($course->id);
     $isteacheredit = isteacheredit($course->id);
index 7884466..adfc8fd 100644 (file)
@@ -5,8 +5,8 @@
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2005020300;   // The (date) version of this module
-$module->requires = 2004052505;  // Requires this Moodle version
+$module->version  = 2005021600;   // The (date) version of this module
+$module->requires = 2005021600;  // Requires this Moodle version
 $module->cron     = 300;          // How often should cron check this module (seconds)?
 
 ?>
index f291a41..83e6b29 100644 (file)
         }
     }
 
-    require_course_login($course);
-
-    if (!$cm->visible and !isteacher($course->id)) {
-        print_header();
-        notice(get_string("activityiscurrentlyhidden"));
-    }
+    require_course_login($course, true, $cm);
 
     add_to_log($course->id, 'chat', 'view', "view.php?id=$cm->id", $chat->id, $cm->id);
 
@@ -59,7 +54,7 @@
         blocks_execute_url_action($PAGE, $pageblocks);
         $pageblocks = blocks_get_by_page($PAGE);
     }
-    
+
     $blocks_preferred_width = bounded_number(180, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]), 210);
 
 
index fe1cace..59b018f 100644 (file)
@@ -13,7 +13,7 @@
         error("Course module is misconfigured");
     }
 
-    require_login($course->id);
+    require_login($course->id, false, $cm);
 
     if (!isteacher($course->id)) {
         error("Only teachers can look at this page");
@@ -62,7 +62,7 @@
 
     $timenow = time();
 
-    foreach ($choice->answer as $key => $answer) {  
+    foreach ($choice->answer as $key => $answer) {
         $useranswer[$key] = array();
     }
     foreach ($users as $user) {
@@ -73,7 +73,7 @@
         }
         $useranswer[(int)$answer->answer][] = $user;
     }
-    foreach ($choice->answer as $key => $answer) {  
+    foreach ($choice->answer as $key => $answer) {
         if (!$choice->answer[$key]) {
             unset($useranswer[$key]);     // Throw away any data that doesn't apply
         }
 
     print_footer($course);
 
+
 ?>
 
index d5c7b29..8db702d 100644 (file)
@@ -5,8 +5,8 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2004111200;
-$module->requires = 2004052505;  // Requires this Moodle version
+$module->version  = 2005021600;
+$module->requires = 2005021600;  // Requires this Moodle version
 $module->cron     = 0;
 
 ?>
index 912a9e3..b92b68d 100644 (file)
@@ -13,7 +13,7 @@
         error("Course is misconfigured");
     }
 
-    require_course_login($course);
+    require_course_login($course, false, $cm);
 
     if (!$choice = choice_get_choice($cm->instance)) {
         error("Course module is incorrect");
 
 
     // print the form
-    
+
     if ($choice->timeopen > time() ) {
         print_simple_box(get_string("notopenyet", "choice", userdate($choice->timeopen)), "center");
         print_footer();
         exit;
     }
 
-    if ( (!$current or $choice->allowupdate) and ($choice->timeclose >= time() or $choice->timeclose == 0) ) { 
+    if ( (!$current or $choice->allowupdate) and ($choice->timeclose >= time() or $choice->timeclose == 0) ) {
     // They haven't made their choice yet or updates allowed and choice is open
-    
+
         echo "<form name=\"form\" method=\"post\" action=\"view.php\">";
         echo "<table cellpadding=\"20\" cellspacing=\"20\" align=\"center\"><tr>";
 
                 echo "</td>";
             }
         }
-    
+
         echo "</tr></table>";
         echo "<center>";
         echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />";
 
     }
 
-    
+
 
     // print the results
 
     if (  $choice->release == CHOICE_RELEASE_ALWAYS or
         ( $choice->release == CHOICE_RELEASE_AFTER_ANSWER and $current ) or
         ( $choice->release == CHOICE_RELEASE_AFTER_CLOSE and $choice->timeclose <= time() ) )  {
-    
+
         print_heading(get_string("responses", "choice"));
 
         if ($currentgroup) {
 
         $timenow = time();
 
-        foreach ($choice->answer as $key => $answer) {  
+        foreach ($choice->answer as $key => $answer) {
             $useranswer[$key] = array();
         }
         foreach ($users as $user) {
                 $useranswer[0][] = $user;
             }
         }
-        foreach ($choice->answer as $key => $answer) {  
+        foreach ($choice->answer as $key => $answer) {
             if (!$choice->answer[$key]) {
                 unset($useranswer[$key]);     // Throw away any data that doesn't apply
             }
                 echo "</th>";
             }
             echo "</tr><tr>";
-        
+
             foreach ($useranswer as $key => $answer) {
                 if ($key) {
                     echo "<td class=\"col$key\" width=\"$tablewidth%\" valign=\"top\" nowrap=\"nowrap\">";
                 } else {
                     continue;
                 }
-    
+
                 echo "<table width=\"100%\">";
                 foreach ($answer as $user) {
                     echo "<tr><td width=\"10\" nowrap=\"nowrap\">";
                     echo "</td></tr>";
                 }
                 echo "</table>";
-        
+
                 echo "</td>";
             }
             echo "</tr></table>";
             break;
         }
     }
-    
+
     print_footer($course);
 
 
index 65576be..9f16942 100644 (file)
@@ -11,7 +11,7 @@
     printdialogue
     showdialogues
     updatesubject
-    
+
 ************************************************/
 
     require_once("../../config.php");
         error("Course module dialogue is incorrect");
     }
 
-    require_login($course->id);
-    
+    require_login($course->id, false, $cm);
+
     // set up some general variables
     $usehtmleditor = can_use_html_editor();
 
     $strdialogues = get_string("modulenameplural", "dialogue");
     $strdialogue  = get_string("modulename", "dialogue");
-    
+
     // ... print the header and...
     print_header_simple("$dialogue->name", "",
-                 "<a href=\"index.php?id=$course->id\">$strdialogues</a> -> 
-                  <a hre=\"view.php?id=$cm->id\">$dialogue->name</a>", 
+                 "<a href=\"index.php?id=$course->id\">$strdialogues</a> ->
+                  <a hre=\"view.php?id=$cm->id\">$dialogue->name</a>",
                   "", "", true);
 
 
@@ -79,8 +79,8 @@
         add_to_log($course->id, "dialogue", "closed", "view.php?id=$cm->id", "$conversationid");
         redirect("view.php?id=$cm->id&amp;pane=$pane", get_string("dialogueclosed", "dialogue"));
     }
-    
-    
+
+
     /****************** confirm close ************************************/
     elseif ($action == 'confirmclose' ) {
 
             }
         }
         $pane = $_GET['pane'];
-        notice_yesno(get_string("confirmclosure", "dialogue", fullname($user)), 
-             "dialogues.php?action=closeconversation&amp;id=$cm->id&amp;cid=$conversation->id&amp;pane=$pane", 
+        notice_yesno(get_string("confirmclosure", "dialogue", fullname($user)),
+             "dialogues.php?action=closeconversation&amp;id=$cm->id&amp;cid=$conversation->id&amp;pane=$pane",
              "view.php?id=$cm->id&amp;pane=$pane");
     }
-    
+
     /****************** get subject ************************************/
     elseif ($action == 'getsubject' ) {
 
         echo "<input type=\"hidden\" name=\"pane\" value=\"".p($_GET[pane])."\"/>\n";
         echo "<table align=\"center\" border=\"1\" width=\"60%\">\n";
         echo "<tr><td align=\"right\"><b>".get_string("subject", "dialogue")."</b></td>";
-        echo "<td><input type=\"text\" size=\"50\" maxsize=\"100\" name=\"subject\" 
+        echo "<td><input type=\"text\" size=\"50\" maxsize=\"100\" name=\"subject\"
                 value=\"\" /></td></tr>\n";
         echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" value=\"".
             get_string("addsubject", "dialogue")."\" /></td></tr>\n";
         echo "</table></form>\n";
     }
-    
-        
+
+
     /****************** insert conversation entries ******************************/
     elseif ($action == 'insertentries' ) {
 
                     $item->dialogueid = $dialogue->id;
                     $item->conversationid = $conversation->id;
                     $item->userid = $USER->id;
-                    $item->timecreated = time(); 
-                    // reverse the dialogue mail default 
+                    $item->timecreated = time();
+                    // reverse the dialogue mail default
                     $item->mailed = !$dialogue->maildefault;
                     $item->text = clean_text($_POST[$textarea_name]);
                     if (!$item->id = insert_record("dialogue_entries", $item)) {
                     if (!set_field("dialogue_conversations", "lastid", $USER->id, "id", $conversation->id)) {
                         error("Insert Dialogue Entries: could not set lastid");
                     }
-                    if (!set_field("dialogue_conversations", "timemodified", $timenow, "id", 
+                    if (!set_field("dialogue_conversations", "timemodified", $timenow, "id",
                             $conversation->id)) {
                         error("Insert Dialogue Entries: could not set lastid");
                     }
                     // reset seenon time
-                    if (!set_field("dialogue_conversations", "seenon", 0, "id", 
+                    if (!set_field("dialogue_conversations", "seenon", 0, "id",
                             $conversation->id)) {
                         error("Insert Dialogue Entries: could not reset seenon");
                     }
                 }
             }
         }
-        redirect("view.php?id=$cm->id&amp;pane={$_POST['pane']}", get_string("numberofentriesadded", 
+        redirect("view.php?id=$cm->id&amp;pane={$_POST['pane']}", get_string("numberofentriesadded",
                     "dialogue", $n));
     }
-    
+
     /****************** list closed conversations *********************************/
     elseif ($action == 'listclosed') {
-    
+
         print_simple_box( text_to_html($dialogue->intro) , "center");
         echo "<br />";
-        
+
         dialogue_list_closed_conversations($dialogue);
     }
-        
+
     /****************** open conversation ************************************/
     elseif ($action == 'openconversation' ) {
 
             }
             if ($recipients) {
                 $n = 0;
-                foreach ($recipients as $recipient) { 
+                foreach ($recipients as $recipient) {
                     if ($recipient->id == $USER->id) { // teacher could be member of a group
                         continue;
                     }
                     $entry->dialogueid = $dialogue->id;
                     $entry->conversationid = $conversation->id;
                     $entry->userid = $USER->id;
-                    $entry->timecreated = time(); 
+                    $entry->timecreated = time();
                     // reverse the dialogue default value
                     $entry->mailed = !$dialogue->maildefault;
                     $entry->text = clean_text($_POST['firstentry']);
                     }
                     redirect("view.php?id=$cm->id", get_string("dialogueopened", "dialogue", $group->name));
                 } else { // all participants
-                    redirect("view.php?id=$cm->id", get_string("dialogueopened", "dialogue", 
+                    redirect("view.php?id=$cm->id", get_string("dialogueopened", "dialogue",
                                 get_string("allparticipants")));
                 }
             } else {
             }
         }
     }
-    
+
 
     /****************** print dialogue (allowing new entry)********************/
     elseif ($action == 'printdialogue') {
-    
+
         // if (!$conversation = get_record("dialogue_conversations", "id", $_GET['cid'])) {
         //     error("Print Dialogue: can not get conversation record");
         // }
-            
+
         print_simple_box( text_to_html($dialogue->intro) , "center");
         echo "<br />";
-        
+
         dialogue_print_conversation($dialogue, $conversation);
     }
-    
+
 
     /****************** show dialogues ****************************************/
     elseif ($action == 'showdialogues') {
-    
+
         if (!$conversation = get_record("dialogue_conversations", "id", $_GET['cid'])) {
             error("Show Dialogue: can not get conversation record");
         }
-            
+
         print_simple_box( text_to_html($dialogue->intro) , "center");
         echo "<br />";
-        
+
         dialogue_show_conversation($dialogue, $conversation);
         dialogue_show_other_conversations($dialogue, $conversation);
     }
-    
+
 
     /****************** update subject ****************************************/
     elseif ($action == 'updatesubject') {
-    
+
         if (!$conversation = get_record("dialogue_conversations", "id", $_POST['cid'])) {
             error("Update Subject: can not get conversation record");
         }
-            
+
         if (!$_POST['subject']) {
             redirect("view.php?id=$cm->id&amp;pane=$_POST[pane]", get_string("nosubject", "dialogue"));
         } elseif (!set_field("dialogue_conversations", "subject", clean_text($_POST['subject']), "id", $_POST['cid'])) {
         }
         redirect("view.php?id=$cm->id&amp;pane=$_POST[pane]", get_string("subjectadded", "dialogue"));
     }
-    
+
 
     /*************** no man's land **************************************/
     else {
index 93615a2..fd2ff23 100644 (file)
@@ -5,8 +5,8 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2004111000;
-$module->requires = 2004052505;  // Requires this Moodle version
+$module->version  = 2005021600;
+$module->requires = 2005021600;  // Requires this Moodle version
 $module->cron     = 60;
 
 ?>
index 10b9835..fd96b07 100644 (file)
@@ -18,7 +18,7 @@
         error("Course module is incorrect");
     }
 
-    require_login($course->id);
+    require_login($course->id, false, $cm);
 
     add_to_log($course->id, "dialogue", "view", "view.php?id=$cm->id", $dialogue->id, $cm->id);
 
                  "", "", true,
                   update_module_button($cm->id, $course->id, $strdialogue), navmenu($course, $cm));
 
-    // ...and if necessary set default action 
-    
+    // ...and if necessary set default action
+
     optional_variable($action);
-    
+
     if (!isguest()) { // it's a teacher or student
         if (!$cm->visible and isstudent($course->id)) {
             $action = 'notavailable';
@@ -52,7 +52,7 @@
     else { // it's a guest, oh no!
         $action = 'notavailable';
     }
-    
+
 
 
 /*********************** dialogue not available (for gusets mainly)***********************/
@@ -63,7 +63,7 @@
 
     /************ view **************************************************/
     elseif ($action == 'view') {
-    
+
         print_simple_box( format_text($dialogue->intro) , "center");
         echo "<br />";
         // get some stats
                 $pane =1;
             }
         }
+
         // override pane setting if teacher has changed group
         if (isset($_GET['group'])) {
             $pane = 0;
         }
-         
+
         // set up tab table
         $tabs->names[0] = get_string("pane0", "dialogue");
         if ($countneedingrepliesself == 1) {
             $tabs->names[2] = get_string("pane2one", "dialogue");
         } else {
             $tabs->names[2] = get_string("pane2", "dialogue", $countneedingrepliesother);
-        } 
+        }
         if ($countclosed == 1) {
             $tabs->names[3] = get_string("pane3one", "dialogue");
         } else {
         $tabs->highlight = $pane;
         dialogue_print_tabbed_heading($tabs);
         echo "<br />\n";
-        
-       
+
+
         switch ($pane) {
             case 0:
                 if (isteacher($course->id)) {
                     echo "<td align=\"right\"><b>".get_string("openadialoguewith", "dialogue").
                         " : </b></td>\n";
                     echo "<td>";
-                    
+
                     choose_from_menu($names, "recipientid");
                     echo "</td></tr>\n";
                     echo "<tr><td align=\"right\"><b>".get_string("subject", "dialogue")." : </b></td>\n";
-                    echo "<td><input type=\"text\" size=\"50\" maxsize=\"100\" name=\"subject\" 
+                    echo "<td><input type=\"text\" size=\"50\" maxsize=\"100\" name=\"subject\"
                         value=\"\" /></td></tr>\n";
                     echo "<tr><td colspan=\"2\" align=\"center\" valign=\"top\"><i>".
                         get_string("typefirstentry", "dialogue")."</i></td></tr>\n";
                 dialogue_list_conversations_closed($dialogue, $USER);
         }
     }
-        
+
     /*************** no man's land **************************************/
     else {
         error("Fatal Error: Unknown Action: ".$action."\n");
index fda1f26..a076b4e 100644 (file)
@@ -33,7 +33,7 @@
     require("locallib.php");
 
     require_variable($id);    // Course Module ID
+
     // get some esential stuff...
     if (! $cm = get_record("course_modules", "id", $id)) {
         error("Course Module ID was incorrect");
 
     exercise_add_custom_scales($exercise);
 
-    require_login($course->id);
+    require_login($course->id, false, $cm);
 
     $strexercises = get_string("modulenameplural", "exercise");
     $strexercise  = get_string("modulename", "exercise");
     $strassessments = get_string("assessments", "exercise");
-    
+
     // ... print the header and...
     print_header_simple("$exercise->name", "",
-                 "<a href=\"index.php?id=$course->id\">$strexercises</a> -> 
-                  <a href=\"view.php?id=$cm->id\">$exercise->name</a> -> $strassessments", 
+                 "<a href=\"index.php?id=$course->id\">$strexercises</a> ->
+                  <a href=\"view.php?id=$cm->id\">$exercise->name</a> -> $strassessments",
                   "", "", true);
 
-    //...get the action 
+    //...get the action
     require_variable($action);
-    
+
 
     /******************* admin amend Grading Grade ************************************/
     if ($action == 'adminamendgradinggrade' ) {
         if (empty($_GET['aid'])) {
             error("Admin Amend Grading grade: assessment id missing");
             }
-            
+
         if (!$assessment = get_record("exercise_assessments", "id", $_GET['aid'])) {
             error("Amin Amend Grading grade: assessment not found");
         }
-        print_heading(get_string("amend", "exercise")." ".get_string("gradeforstudentsassessment", 
+        print_heading(get_string("amend", "exercise")." ".get_string("gradeforstudentsassessment",
                     "exercise", $course->student));
         echo "<form name=\"amendgrade\" method=\"post\" action=\"assessments.php\">\n";
         echo "<input type=\"hidden\" name=\"aid\" value=\"$_GET[aid]\" />\n";
         echo "<input type=\"hidden\" name=\"action\" value=\"updategradinggrade\" />\n";
         echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
         echo "<table width=\"50%\" align=\"center\" border=\"1\" />\n";
-        echo "<tr><td align=\"right\"><b>".get_string("gradeforstudentsassessment", "exercise", 
+        echo "<tr><td align=\"right\"><b>".get_string("gradeforstudentsassessment", "exercise",
                 $course->student)." :</td><td>\n";
         // set up coment scale
         for ($i=$exercise->gradinggrade; $i>=0; $i--) {
             $num[$i] = $i;
             }
-        choose_from_menu($num, "gradinggrade", 
+        choose_from_menu($num, "gradinggrade",
                 number_format($exercise->gradinggrade * $assessment->gradinggrade / 100, 0), "");
         echo "</td></tr>\n";
-        echo "<tr><td colspan=\"2\" align=\"center\">"; 
+        echo "<tr><td colspan=\"2\" align=\"center\">";
         echo "<input type=\"submit\" value=\"".get_string("amend", "exercise")."\" />\n";
         echo "</td></tr>\n";
         echo "</table>\n";
         echo "</center>";
         echo "</form>\n";
     }
-    
+
 
     /******************* admin confirm delete ************************************/
     elseif ($action == 'adminconfirmdelete' ) {
         if (empty($_GET['aid'])) {
             error("Admin confirm delete: assessment id missing");
             }
-            
-        notice_yesno(get_string("confirmdeletionofthisitem","exercise", get_string("assessment", "exercise")), 
-             "assessments.php?action=admindelete&amp;id=$cm->id&amp;aid=$_GET[aid]", 
+
+        notice_yesno(get_string("confirmdeletionofthisitem","exercise", get_string("assessment", "exercise")),
+             "assessments.php?action=admindelete&amp;id=$cm->id&amp;aid=$_GET[aid]",
              "submissions.php?action=adminlist&amp;id=$cm->id");
         }
-    
+
 
     /******************* admin delete ************************************/
     elseif ($action == 'admindelete' ) {
         if (empty($_GET['aid'])) {
             error("Admin delete: submission id missing");
             }
-            
+
         print_string("deleting", "exercise");
         // first delete all the associated records...
         delete_records("exercise_grades", "assessmentid", $_GET['aid']);
         // ...now delete the assessment...
         delete_records("exercise_assessments", "id", $_GET['aid']);
-        
+
         print_continue("submissions.php?id=$cm->id&amp;action=adminlist");
         }
-    
+
 
     /*********************** admin list of asssessments (of a submission) (by teachers)**************/
     elseif ($action == 'adminlist') {
         if (!isteacher($course->id)) {
             error("Only teachers can look at this page");
             }
-            
+
         if (empty($_GET['sid'])) {
             error ("exercise asssessments: adminlist called with no sid");
             }
         if (!isteacher($course->id)) {
             error("Only teachers can look at this page");
             }
-            
+
         if (empty($_GET['userid'])) {
             error ("exercise asssessments: adminlistbystudent called with no userid");
             }
     elseif ($action == 'assessresubmission') {
 
         require_variable($sid);
-        
+
         if (! $submission = get_record("exercise_submissions", "id", $sid)) {
             error("Assess submission is misconfigured - no submission record!");
         }
         if (!$submissionowner = get_record("user", "id", $submission->userid)) {
             error("Assess resubmission: user record not found");
         }
-        
+
         // there can be an assessment record, if there isn't...
         if (!$assessment = exercise_get_submission_assessment($submission, $USER)) {
             if (!$submissions = exercise_get_user_submissions($exercise, $submissionowner)) {
             // copy this assessment with comments...
             $assessment = exercise_copy_assessment($prevassessment, $submission, true);
         }
-        
-        print_heading(get_string("thisisaresubmission", "exercise", 
+
+        print_heading(get_string("thisisaresubmission", "exercise",
             fullname($submissionowner)));
         // show assessment and allow changes
         exercise_print_assessment_form($exercise, $assessment, true, $_SERVER["HTTP_REFERER"]);
     elseif ($action == 'assesssubmission') {
 
         require_variable($sid);
-        
+
         if (! $submission = get_record("exercise_submissions", "id", $sid)) {
             error("Assess submission is misconfigured - no submission record!");
         }
-        
+
         // there can be an assessment record (for teacher submissions), if there isn't...
         if (!$assessment = exercise_get_submission_assessment($submission, $USER)) {
             $yearfromnow = time() + 365 * 86400;
                 error("Could not insert exercise assessment!");
             }
         }
-        
+
         // show assessment and allow changes
         exercise_print_assessment_form($exercise, $assessment, true, $_SERVER["HTTP_REFERER"]);
     }
     elseif ($action == 'displaygradingform') {
 
     print_heading_with_help(get_string("specimenassessmentform", "exercise"), "specimen", "exercise");
-    
+
     exercise_print_assessment_form($exercise); // called with no assessment
     print_continue("view.php?id=$cm->id");
     }
         <input type="hidden" name="action" value="insertelements" />
         <center><table cellpadding="5" border="1">
         <?php
-        
+
         // get existing elements, if none set up appropriate default ones
         if ($elementsraw = get_records("exercise_elements", "exerciseid", $exercise->id, "elementno ASC" )) {
             foreach ($elementsraw as $element) {
                 $elements[] = $element;   // to renumber index 0,1,2...
             }
         }
-        // check for missing elements (this happens either the first time round or when the number 
+        // check for missing elements (this happens either the first time round or when the number
         // of elements is icreased)
         for ($i=0; $i<$exercise->nelements; $i++) {
             if (!isset($elements[$i])) {
                 foreach ($EXERCISE_SCALES as $KEY => $SCALE) {
                     $SCALES[] = $SCALE['name'];
                 }
-                     
+
                 for ($i=0; $i<$exercise->nelements; $i++) {
                     $iplus1 = $i+1;
                     echo "<tr valign=\"top\">\n";
                     echo "</tr>\n";
                 }
                 break;
-                
+
             case 2: // error banded grading
                 for ($i=0; $i<$exercise->nelements; $i++) {
                     $iplus1 = $i+1;
                     echo "</td></tr>\n";
                 }
                 break;
-                
+
             case 3: // criterion grading
                 for ($j = $exercise->grade; $j >= 0; $j--) {
                     $numbers[$j] = $j;
         </form>
         <?php
     }
-    
-    
+
+
     /****************** insert/update assignment elements (for teachers)***********************/
     elseif ($action == 'insertelements') {
 
         }
 
         $form = data_submitted();
-        
+
         // let's not fool around here, dump the junk!
         delete_records("exercise_elements", "exerciseid", $exercise->id);
-        
+
         // determine wich type of grading
         switch ($exercise->gradingstrategy) {
             case 0: // no grading
                     }
                 }
                 break;
-                
+
             case 1: // accumulative grading
                 // Insert all the elements that contain something
                 foreach ($form->description as $key => $description) {
                     }
                 }
                 break;
-                
+
             case 2: // error banded grading...
             case 3: // ...and criterion grading
-                // Insert all the elements that contain something, the number of descriptions is 
+                // Insert all the elements that contain something, the number of descriptions is
                 // one less than the number of grades
                 foreach ($form->maxscore as $key => $themaxscore) {
                     unset($element);
                     }
                 }
                 break;
-                
+
             case 4: // ...and criteria grading
                 // Insert all the elements that contain something
                 foreach ($form->description as $key => $description) {
     }
 
 
-    /***************** list assessments for grading student assessments ( linked to the 
+    /***************** list assessments for grading student assessments ( linked to the
     ******************Teacher's submissions) (by teachers)****/
     elseif ($action == 'listungradedstudentassessments') {
 
         if ($assessments = exercise_get_teacher_submission_assessments($exercise)) {
             foreach ($assessments as $studentassessment) {
                 if ($studentassessment->timegraded > 0) {
-                    if (!$submissions = get_records_select("exercise_submissions", 
+                    if (!$submissions = get_records_select("exercise_submissions",
                            "userid = $studentassessment->userid AND exerciseid = $exercise->id", "timecreated ASC")) {
                         error("Regrade student assessments: student submission not found");
                     }
                     foreach ($submissions as $submission) { // only the first one is relavant
-                        if (!$teacherassessments = get_records("exercise_assessments", "submissionid", 
+                        if (!$teacherassessments = get_records("exercise_assessments", "submissionid",
                                     $submission->id, "timecreated ASC")) {
                             error("Regrade student assessments: teacher assessment(s) not found");
                         }
                             $newgrade = exercise_compare_assessments($exercise, $studentassessment, $teacherassessment);
                             set_field("exercise_assessments", "gradinggrade", $newgrade, "id", $studentassessment->id);
                             break;
-                        } 
+                        }
                         break;
                     }
                 }
         }
         redirect("submissions.php?id=$cm->id&amp;action=adminlist");
     }
-    
+
 
     /****************** teacher assessment : grading of assessment and submission (from student) ************/
     elseif ($action == 'teacherassessment') {
-        
+
         if (!isteacher($course->id)) {
             error("Only teachers can look at this page");
         }
 
     /****************** teacher table : show assessments by exercise and teacher ************/
     elseif ($action == 'teachertable') {
-        
+
         if (!isteacher($course->id)) {
             error("Only teachers can look at this page");
         }
 
         // don't fiddle about, delete all the old and then add the new!
         delete_records("exercise_grades", "assessmentid",  $assessment->id);
-        
+
         //determine what kind of grading we have
         switch ($exercise->gradingstrategy) {
             case 0: // no grading
                     }
                 $grade = 0; // set to satisfy save to db
                 break;
-                
+
             case 1: // accumulative grading
                 // Insert all the elements that contain something
                 foreach ($form->grade as $key => $thegrade) {
                 foreach ($form->grade as $key => $grade) {
                     $maxscore = $elements[$key]->maxscore;
                     $weight = $EXERCISE_EWEIGHTS[$elements[$key]->weight];
-                    if ($weight > 0) { 
+                    if ($weight > 0) {
                         $totalweight += $weight;
                     }
                     $rawgrade += ($grade / $maxscore) * $weight;
 
             case 2: // error banded graded
                 // Insert all the elements that contain something
-                $error = 0.0; 
+                $error = 0.0;
                 for ($i =0; $i < $exercise->nelements; $i++) {
                     unset($element);
                     $element->exerciseid = $exercise->id;
                     $grade = 0.0;
                 }
                 break;
-            
+
             case 3: // criteria grading
-                // save in the selected criteria value in element zero, 
+                // save in the selected criteria value in element zero,
                 unset($element);
                 $element->exerciseid = $exercise->id;
                 $element->assessmentid = $assessment->id;
                 foreach ($form->grade as $key => $grade) {
                     $maxscore = $elements[$key]->maxscore;
                     $weight = $EXERCISE_EWEIGHTS[$elements[$key]->weight];
-                    if ($weight > 0) { 
+                    if ($weight > 0) {
                         $totalweight += $weight;
                     }
                     $rawgrade += ($grade / $maxscore) * $weight;
                 break;
 
         } // end of switch
-            
+
         // update the time of the assessment record (may be re-edited)...
         set_field("exercise_assessments", "timecreated", $timenow, "id", $assessment->id);
         set_field("exercise_assessments", "grade", $grade, "id", $assessment->id);
         // ...and clear any grading of this assessment (these assessments are never graded but...)
         set_field("exercise_assessments", "timegraded", 0, "id", $assessment->id);
         set_field("exercise_assessments", "gradinggrade", 0, "id", $assessment->id);
-        
+
         // any comment?
         if (!empty($form->generalcomment)) {
             set_field("exercise_assessments", "generalcomment", $form->generalcomment, "id", $assessment->id);
         }
-            
+
         // is user allowed to resubmit?
         if (isteacher($course->id)) {
             if (!$submission = get_record("exercise_submissions", "id", $assessment->submissionid)) {
                 set_field("exercise_submissions", "resubmit", 0, "id", $submission->id);
             }
         }
-        
+
         add_to_log($course->id, "exercise", "assess", "view.php?id=$cm->id", "$assessment->id");
-        
+
         // set up return address
         if (!$returnto = $form->returnto) {
             $returnto = "view.php?id=$cm->id";
         }
-            
+
         // show grade if grading strategy is not zero
         if ($exercise->gradingstrategy) {
             redirect($returnto, "<p align=\"center\"><b>".get_string("thegradeis", "exercise").": ".
         $timenow = time();
         $form = (object)$HTTP_POST_VARS;
 
-    
+
         // first do the (teacher's) assessment of the student's submission
         if (! $submission = get_record("exercise_submissions", "id", $form->sid)) {
             error("Update teacher assessment: student's submission record not found");
 
         // don't fiddle about, delete all the old and then add the new!
         delete_records("exercise_grades", "assessmentid",  $assessment->id);
-        
+
         //determine what kind of grading we have
         switch ($exercise->gradingstrategy) {
             case 0: // no grading
                 }
                 $grade = 0; // set to satisfy save to db
                 break;
-                
+
             case 1: // accumulative grading
                 // Insert all the elements that contain something
                 foreach ($form->grade as $key => $thegrade) {
                 foreach ($form->grade as $key => $grade) {
                     $maxscore = $elements[$key]->maxscore;
                     $weight = $EXERCISE_EWEIGHTS[$elements[$key]->weight];
-                    if ($weight > 0) { 
+                    if ($weight > 0) {
                         $totalweight += $weight;
                     }
                     $rawgrade += ($grade / $maxscore) * $weight;
 
             case 2: // error banded graded
                 // Insert all the elements that contain something
-                $error = 0.0; 
+                $error = 0.0;
                 for ($i =0; $i < $exercise->nelements; $i++) {
                     unset($element);
                     $element->exerciseid = $exercise->id;
                 $grade = ($elements[intval($error + 0.5)]->maxscore + $form->grade[$i]) * 100 / $exercise->grade;
                 echo "<p><b>".get_string("weightederrorcount", "exercise", intval($error + 0.5))."</b>\n";
                 break;
-            
+
             case 3: // criteria grading
-                // save in the selected criteria value in element zero, 
+                // save in the selected criteria value in element zero,
                 unset($element);
                 $element->exerciseid = $exercise->id;
                 $element->assessmentid = $assessment->id;
                 foreach ($form->grade as $key => $grade) {
                     $maxscore = $elements[$key]->maxscore;
                     $weight = $EXERCISE_EWEIGHTS[$elements[$key]->weight];
-                    if ($weight > 0) { 
+                    if ($weight > 0) {
                         $totalweight += $weight;
                     }
                     $rawgrade += ($grade / $maxscore) * $weight;
                 break;
 
         } // end of switch
-            
+
         // update the time of the assessment record (may be re-edited)...
         set_field("exercise_assessments", "timecreated", $timenow, "id", $assessment->id);
         set_field("exercise_assessments", "grade", $grade, "id", $assessment->id);
         // ...and clear any grading of this assessment (never needed but...)
         set_field("exercise_assessments", "timegraded", 0, "id", $assessment->id);
         set_field("exercise_assessments", "gradinggrade", 0, "id", $assessment->id);
-        
+
         // any comment?
         if (!empty($form->generalcomment)) {
             set_field("exercise_assessments", "generalcomment", $form->generalcomment, "id", $assessment->id);
         }
-            
+
         // now calculate the (grading) grade of the student's assessment...
         if (!$stassessment = get_record("exercise_assessments", "id", $form->said)) {
             error("Update teacher assessment: student's assessment record not found");
         }
         $gradinggrade = exercise_compare_assessments($exercise, $assessment, $stassessment);
-        // ...and save the grade for the assessment 
+        // ...and save the grade for the assessment
         set_field("exercise_assessments", "gradinggrade", $gradinggrade, "id", $stassessment->id);
         set_field("exercise_assessments", "timegraded", $timenow, "id", $stassessment->id);
         set_field("exercise_assessments", "mailed", 0, "id", $stassessment->id);
         echo "<centre><b>".get_string("savedok", "exercise")."</b></centre><br />\n";
 
         add_to_log($course->id, "exercise", "grade", "view.php?id=$cm->id", "$stassessment->id");
-        
+
         // is user allowed to resubmit?
         if ($form->resubmit == 1) {
             set_field("exercise_submissions", "resubmit", 1, "id", $submission->id);
             // clear resubmit flag
             set_field("exercise_submissions", "resubmit", 0, "id", $submission->id);
         }
-        
+
         add_to_log($course->id, "exercise", "assess", "view.php?id=$cm->id", "$assessment->id");
-        
+
         // set up return address
         if (!$returnto = $form->returnto) {
             $returnto = "view.php?id=$cm->id";
         }
-            
+
         // show grade if grading strategy is not zero
         if ($exercise->gradingstrategy) {
-            redirect($returnto, "<p align=\"center\"><b>".get_string("gradeforstudentsassessment", 
+            redirect($returnto, "<p align=\"center\"><b>".get_string("gradeforstudentsassessment",
                 "exercise", $course->student).": ".number_format($gradinggrade * $exercise->gradinggrade / 100.0, 1).
                 " (".get_string("maximumgrade")." ".number_format($exercise->gradinggrade, 1).")</b></p><p><b>".
                 get_string("thegradeis", "exercise").": ".number_format($grade * $exercise->grade / 100.0, 1).
         require_variable($aid);
         // normalise gradinggrade
         $gradinggrade = $_POST['gradinggrade'] * 100 / $exercise->gradinggrade;
-        if (!set_field("exercise_assessments", "gradinggrade", $gradinggrade, "id", 
+        if (!set_field("exercise_assessments", "gradinggrade", $gradinggrade, "id",
                     $_POST['aid'])) {
             error("Update grading grade: asseesment not updated");
         }
         if (empty($_GET['aid'])) {
             error("User confirm delete: assessment id missing");
         }
-            
-        notice_yesno(get_string("confirmdeletionofthisitem","exercise", get_string("assessment", "exercise")), 
+
+        notice_yesno(get_string("confirmdeletionofthisitem","exercise", get_string("assessment", "exercise")),
              "assessments.php?action=userdelete&amp;id=$cm->id&amp;aid=$_GET[aid]", "view.php?id=$cm->id");
     }
-    
+
 
     /****************** user delete ************************************/
     elseif ($action == 'userdelete' ) {
         if (empty($_GET['aid'])) {
             error("User delete: assessment id missing");
         }
-            
+
         print_string("deleting", "exercise");
         // first delete all the associated records...
         delete_records("exercise_grades", "assessmentid", $_GET['aid']);
         // ...now delete the assessment...
         delete_records("exercise_assessments", "id", $_GET['aid']);
-        
+
         print_continue("view.php?id=$cm->id");
     }
-    
+
 
     /****************** view assessment ***********************/
     elseif ($action == 'viewassessment') {
         // get the assessment record
         if (!$assessment = get_record("exercise_assessments", "id", $_GET['aid'])) {
             error("Assessment record not found");
-        }       
+        }
 
         // show assessment but don't allow changes
         exercise_print_assessment_form($exercise, $assessment);
-        
+
         print_continue("view.php?id=$cm->id");
     }
 
     }
 
     print_footer($course);
+
 ?>
 
index 8f7c563..4822cd6 100644 (file)
@@ -15,7 +15,7 @@
     saveweights
     userconfirmdelete
     userdelete
-    
+
 
 ************************************************/
 
@@ -25,7 +25,7 @@
     require("version.php");
 
     require_variable($id);    // Course Module ID
-    
+
     // get some essential stuff...
     if (! $cm = get_record("course_modules", "id", $id)) {
         error("Course Module ID was incorrect");
@@ -39,7 +39,7 @@
         error("Course module is incorrect");
     }
 
-    require_login($course->id);
+    require_login($course->id, false, $cm);
 
     $strexercises = get_string("modulenameplural", "exercise");
     $strexercise  = get_string("modulename", "exercise");
 
     // ... print the header and...
     print_header_simple("$exercise->name", "",
-                 "<a href=\"index.php?id=$course->id\">$strexercises</a> -> 
-                  <a href=\"view.php?id=$cm->id\">$exercise->name</a> -> $strsubmissions", 
+                 "<a href=\"index.php?id=$course->id\">$strexercises</a> ->
+                  <a href=\"view.php?id=$cm->id\">$exercise->name</a> -> $strsubmissions",
                   "", "", true);
 
     //...get the action!
     require_variable($action);
-    
+
 
     /******************* admin amend title ************************************/
     if ($action == 'adminamendtitle' ) {
@@ -64,7 +64,7 @@
         if (empty($_GET['sid'])) {
             error("Admin Amend Title: submission id missing");
             }
-        
+
         $submission = get_record("exercise_submissions", "id", $_GET['sid']);
         print_heading(get_string("amendtitle", "exercise"));
         ?>
@@ -86,7 +86,7 @@
         echo "</center></form>\n";
 
         }
-    
+
 
     /******************* admin clear late (flag) ************************************/
     elseif ($action == 'adminclearlate' ) {
         if (empty($_GET['sid'])) {
             error("Admin clear late flag: submission id missing");
         }
-    
+
         if (!$submission = get_record("exercise_submissions", "id", $_GET['sid'])) {
             error("Admin clear late flag: can not get submission record");
         }
         if (set_field("exercise_submissions", "late", 0, "id", $_GET['sid'])) {
             print_heading(get_string("clearlateflag", "exercise")." ".get_string("ok"));
         }
-        
+
         add_to_log($course->id, "exercise", "late flag cleared", "view.php?id=$cm->id", "submission $submission->id");
-        
+
         redirect("submissions.php?id=$cm->id&amp;action=adminlist");
     }
-    
+
 
     /******************* admin confirm delete ************************************/
     elseif ($action == 'adminconfirmdelete' ) {
                     "</p>\n";
             }
         }
-        notice_yesno(get_string("confirmdeletionofthisitem","exercise", get_string("submission", "exercise")), 
+        notice_yesno(get_string("confirmdeletionofthisitem","exercise", get_string("submission", "exercise")),
              "submissions.php?action=admindelete&amp;id=$cm->id&amp;sid=$_GET[sid]", "submissions.php?id=$cm->id&amp;action=adminlist");
         }
-    
+
 
     /******************* admin delete ************************************/
     elseif ($action == 'admindelete' ) {
         if (empty($_GET['sid'])) {
             error("Admin delete: submission id missing");
             }
-    
+
         if (!$submission = get_record("exercise_submissions", "id", $_GET['sid'])) {
             error("Admin delete: can not get submission record");
             }
         // ..and finally the submitted file
         exercise_delete_submitted_files($exercise, $submission);
         add_to_log($course->id, "exercise", "delete", "view.php?id=$cm->id", "submission $submission->id");
-        
+
         print_continue("submissions.php?id=$cm->id&amp;action=adminlist");
         }
-    
+
 
     /******************* admin (confirm) late flag ************************************/
     elseif ($action == 'adminlateflag' ) {
             error("Admin confirm late flag: can not get submission record");
             }
 
-        notice_yesno(get_string("clearlateflag","exercise")."?", 
-             "submissions.php?action=adminclearlate&amp;id=$cm->id&amp;sid=$_GET[sid]", 
+        notice_yesno(get_string("clearlateflag","exercise")."?",
+             "submissions.php?action=adminclearlate&amp;id=$cm->id&amp;sid=$_GET[sid]",
              "submissions.php?id=$cm->id&amp;action=adminlist");
         }
-    
+
 
     /******************* list all submissions ************************************/
     elseif ($action == 'adminlist' ) {
         if (!isteacher($course->id)) {
             error("Only teachers can look at this page");
         }
-    
+
         echo "<p><small>Exercise Version-> $module->version</small></p>";
         exercise_list_submissions_for_admin($exercise);
         print_continue("view.php?id=$cm->id");
-        
+
     }
-    
+
 
     /******************* admin update title ************************************/
     elseif ($action == 'adminupdatetitle' ) {
         if (empty($_POST['sid'])) {
             error("Admin Update Title: submission id missing");
             }
-    
+
         if (set_field("exercise_submissions", "title", $_POST['title'], "id", $_POST['sid'])) {
             print_heading(get_string("amendtitle", "exercise")." ".get_string("ok"));
             }
         redirect("submissions.php?id=$cm->id&amp;action=adminlist");
         }
-    
+
 
     /*************** display final grades (by teacher) ***************************/
     elseif ($action == 'displayfinalgrades') {
             print_footer($course);
             exit;
         }
-        
+
         // show the final grades as stored in the tables...
         print_heading_with_help(get_string("displayoffinalgrades", "exercise"), "finalgrades", "exercise");
         echo "<center><table border=\"1\" width=\"90%\"><tr>\n";
                             $gradinggrade = number_format($ownassessment->gradinggrade * $exercise->gradinggrade /
                                     100.0, 1);
                             $grade = number_format($assessment->grade * $exercise->grade / 100.0, 1);
-                            $overallgrade = number_format(($assessment->grade * $exercise->grade / 100.0) + 
+                            $overallgrade = number_format(($assessment->grade * $exercise->grade / 100.0) +
                                 ($ownassessment->gradinggrade * $exercise->gradinggrade / 100.0), 1);
                             if ($submission->late) {
                                 $grade = "<font color=\"red\">(".$grade.")</font>";
             }
         exercise_list_unassessed_student_submissions($exercise, $USER);
         print_continue("view.php?id=$cm->id");
-        
+
         }
-    
+
 
     /******************* list for assessment teacher (submissions) ************************************/
     elseif ($action == 'listforassessmentteacher' ) {
             }
         exercise_list_unassessed_teacher_submissions($exercise, $USER);
         print_continue("view.php?id=$cm->id");
-        
+
         }
-    
+
 
     /****************** save league table entries and anonimity setting (by teacher) **************/
     elseif ($action == 'saveleaguetable') {
 
         $form = (object)$_POST;
-        
+
         if (!isteacher($course->id)) {
             error("Only teachers can look at this page");
             }
         } else {
             $nentries = $form->nentries;
         }
-        // ...and save it 
+        // ...and save it
         set_field("exercise", "showleaguetable", $nentries, "id", "$exercise->id");
-        
-        // ...and save the anonimity setting 
+
+        // ...and save the anonimity setting
         set_field("exercise", "anonymous", $form->anonymous, "id", "$exercise->id");
-    
+
         redirect("submissions.php?id=$cm->id&amp;action=adminlist", get_string("entriessaved", "exercise"));
         }
-                
+
         /*************** save weights (by teacher) ***************************/
     elseif ($action == 'saveweights') {
 
         $form = (object)$_POST;
-        
+
         if (!isteacher($course->id)) {
             error("Only teachers can look at this page");
             }
         // save the weights from the form...
         if (isset($form->teacherweight)) {
             $teacherweight = $form->teacherweight;
-            // ...and save them 
+            // ...and save them
             set_field("exercise", "teacherweight", $teacherweight, "id", "$exercise->id");
             }
-        
+
         if (isset($form->gradingweight)) {
             $gradingweight = $form->gradingweight;
-            // ...and save them 
+            // ...and save them
             set_field("exercise", "gradingweight", $gradingweight, "id", "$exercise->id");
             }
-    
+
         redirect("submissions.php?id=$cm->id&amp;action=adminlist", get_string("weightssaved", "exercise"));
         }
-                
-    
+
+
     /******************* user confirm delete ************************************/
     elseif ($action == 'userconfirmdelete' ) {
 
         if (empty($_GET['sid'])) {
             error("User Confirm Delete: submission id missing");
             }
-            
-        notice_yesno(get_string("confirmdeletionofthisitem","exercise", get_string("submission", "exercise")), 
+
+        notice_yesno(get_string("confirmdeletionofthisitem","exercise", get_string("submission", "exercise")),
              "submissions.php?action=userdelete&amp;id=$cm->id&amp;sid=$_GET[sid]", "view.php?id=$cm->id");
         }
-    
+
 
     /******************* user delete ************************************/
     elseif ($action == 'userdelete' ) {
         if (empty($_GET['sid'])) {
             error("User Delete: submission id missing");
             }
-    
+
         if (!$submission = get_record("exercise_submissions", "id", $_GET['sid'])) {
             error("User Delete: can not get submission record");
             }
         // ..and finally the submitted file
         exercise_delete_submitted_files($exercise, $submission);
         add_to_log($course->id, "exercise", "delete", "view.php?id=$cm->id", "submission $submission->id");
-        
+
         print_continue("view.php?id=$cm->id");
         }
-    
+
 
     /*************** no man's land **************************************/
 
 
 
     print_footer($course);
+
 ?>
index ef2efa9..f59b30a 100644 (file)
         error("Course module is incorrect");
     }
 
-    require_login($course->id);
+    require_login($course->id, false, $cm);
 
     $strexercises = get_string("modulenameplural", "exercise");
     $strexercise  = get_string("modulename", "exercise");
     $strupload      = get_string("upload");
 
     print_header_simple("$exercise->name : $strupload", "",
-                 "<a href=\"index.php?id=$course->id\">$strexercises</a> -> 
-                  <a href=\"view.php?id=$cm->id\">$exercise->name</a> -> $strupload", 
+                 "<a href=\"index.php?id=$course->id\">$strexercises</a> ->
+                  <a href=\"view.php?id=$cm->id\">$exercise->name</a> -> $strupload",
                   "", "", true);
 
     // check that this is not a "rapid" second submission, caused by using the back button
             }
         }
     }
-                    
+
     // check existence of title
     if (!$title = $_POST['title']) {
         notify(get_string("notitlegiven", "exercise") );
     }
-    else {  
+    else {
         require_once($CFG->dirroot.'/lib/uploadlib.php');
         $um = new upload_manager('newfile',false,false,$course,false,$exercise->maxbytes);
         if ($um->preprocess_files()) {
@@ -82,7 +82,7 @@
             if (!set_field("exercise_submissions", "resubmit", 0, "exerciseid", $exercise->id, "userid", $USER->id)) {
                 error("Exercise Upload: unable to reset resubmit flag");
             }
-        } 
+        }
         // upload manager will print errors.
     }
     print_continue("view.php?id=$cm->id");
index 41abc36..fd2ff23 100644 (file)
@@ -5,8 +5,8 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2004111200;
-$module->requires = 2004091700;  // Requires this Moodle version
+$module->version  = 2005021600;
+$module->requires = 2005021600;  // Requires this Moodle version
 $module->cron     = 60;
 
 ?>
index 52d28b0..ccecc23 100644 (file)
     setupassignment (for teachers)
     showsubmissions (for students)
     studentsview
-    submitassignment 
+    submitassignment
     teachersview
-    
+
 ************************************************/
 
     require("../../config.php");
     require("lib.php");
     require("locallib.php");
-    
+
     require_variable($id);    // Course Module ID
 
     // get some esential stuff...
@@ -34,7 +34,7 @@
         error("Course module is incorrect");
     }
 
-    require_login($course->id);
+    require_login($course->id, false, $cm);
 
     // ...log activity...
     add_to_log($course->id, "exercise", "view", "view.php?id=$cm->id", $exercise->id, $cm->id);
 
     // ...display header...
     print_header_simple("$exercise->name", "",
-                 "<a href=\"index.php?id=$course->id\">$strexercises</a> -> $exercise->name", 
+                 "<a href=\"index.php?id=$course->id\">$strexercises</a> -> $exercise->name",
                   "", "", true, update_module_button($cm->id, $course->id, $strexercise), navmenu($course, $cm));
 
-    // ...and if necessary set default action 
-    
+    // ...and if necessary set default action
+
     optional_variable($action);
     if (isteacher($course->id)) {
         if (empty($action)) { // no action specified, either go straight to elements page else the admin page
@@ -75,8 +75,8 @@
     else { // it's a guest, oh no!
         $action = 'notavailable';
     }
-    
-    
+
+
     /****************** display final grade (for students) ************************************/
     if ($action == 'displayfinalgrade' ) {
 
                         $gradinggrade = number_format($ownassessment->gradinggrade * $exercise->gradinggrade / 100.0,
                                 1);
                         $grade = number_format($assessment->grade * $exercise->grade / 100.0, 1);
-                        $overallgrade = number_format(($assessment->grade * $exercise->grade / 100.0) + 
+                        $overallgrade = number_format(($assessment->grade * $exercise->grade / 100.0) +
                             ($ownassessment->gradinggrade * $exercise->gradinggrade / 100.0 ), 1);
                         if ($submission->late) {
                             $grade = "<font color=\"red\">(".$grade.")</font>";
         add_to_log($course->id, "exercise", "display", "view.php?id=$cm->id", "$exercise->id", $cm->id);
         redirect("view.php?id=$cm->id", get_string("movingtophase", "exercise", 3));
     }
-    
-    
+
+
     /*********************** assignment not available (for students)***********************/
     elseif ($action == 'notavailable') {
         print_heading(get_string("notavailable", "exercise"));
         add_to_log($course->id, "exercise", "set up", "view.php?id=$cm->id", "$exercise->id", $cm->id);
         redirect("view.php?id=$cm->id", get_string("movingtophase", "exercise", 1));
     }
-    
-    
+
+
     /****************** showsubmissions (for students, in phase 3)***********************/
     elseif ($action == 'showsubmissions') {
         exercise_print_assignment_info($exercise);
                 if ($assessments = exercise_get_assessments($submission)) {
                     // should only be one but we'll loop anyway
                     foreach ($assessments as $assessment) {
-                        $table->data[] = array(exercise_print_submission_title($exercise, $submission), 
-                                userdate($submission->timecreated), userdate($assessment->timecreated), 
+                        $table->data[] = array(exercise_print_submission_title($exercise, $submission),
+                                userdate($submission->timecreated), userdate($assessment->timecreated),
                                 "<a href=\"assessments.php?action=viewassessment&amp;id=$cm->id&amp;aid=$assessment->id\">".$assessment->grade * $exercise->grade / 100.0."</a>");
                     }
                 } else {
                     // submission not yet assessed (by teacher)
-                    $table->data[] = array(exercise_print_submission_title($exercise, $submission), 
+                    $table->data[] = array(exercise_print_submission_title($exercise, $submission),
                             userdate($submission->timecreated), get_string("notassessedyet", "exercise"), 0);
                 }
             }
     elseif ($action == 'studentsview') {
         exercise_print_assignment_info($exercise);
         // is a password needed?
-               if ($exercise->usepassword) {
-                       $correctpass = false;
-                       if (isset($_POST['userpassword'])) {
-                               if ($exercise->password == md5(trim($_POST['userpassword']))) {
-                                       $USER->exerciseloggedin[$exercise->id] = true;
-                                       $correctpass = true;
-                               }
-                       } elseif (isset($USER->exerciseloggedin[$exercise->id])) {
-                               $correctpass = true;
-                       }
-
-                       if (!$correctpass) {
-                               print_simple_box_start("center");
-                               echo "<form name=\"password\" method=\"post\" action=\"view.php\">\n";
-                               echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
-                               echo "<table cellpadding=\"7px\">";
-                               if (isset($_POST['userpassword'])) {
-                                       echo "<tr align=\"center\" style='color:#DF041E;'><td>".get_string("wrongpassword", "exercise").
+        if ($exercise->usepassword) {
+            $correctpass = false;
+            if (isset($_POST['userpassword'])) {
+                if ($exercise->password == md5(trim($_POST['userpassword']))) {
+                    $USER->exerciseloggedin[$exercise->id] = true;
+                    $correctpass = true;
+                }
+            } elseif (isset($USER->exerciseloggedin[$exercise->id])) {
+                $correctpass = true;
+            }
+
+            if (!$correctpass) {
+                print_simple_box_start("center");
+                echo "<form name=\"password\" method=\"post\" action=\"view.php\">\n";
+                echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
+                echo "<table cellpadding=\"7px\">";
+                if (isset($_POST['userpassword'])) {
+                    echo "<tr align=\"center\" style='color:#DF041E;'><td>".get_string("wrongpassword", "exercise").
                         "</td></tr>";
-                               }
-                               echo "<tr align=\"center\"><td>".get_string("passwordprotectedexercise", "exercise", $exercise->name).
+                }
+                echo "<tr align=\"center\"><td>".get_string("passwordprotectedexercise", "exercise", $exercise->name).
                     "</td></tr>";
-                               echo "<tr align=\"center\"><td>".get_string("enterpassword", "exercise").
+                echo "<tr align=\"center\"><td>".get_string("enterpassword", "exercise").
                     " <input type=\"password\" name=\"userpassword\" /></td></tr>";
-                                               
-                               echo "<tr align=\"center\"><td>";
-                               echo "<input type=\"button\" value=\"".get_string("cancel").
+
+                echo "<tr align=\"center\"><td>";
+                echo "<input type=\"button\" value=\"".get_string("cancel").
                     "\" onclick=\"parent.location='../../course/view.php?id=$course->id';\">  ";
-                               echo "<input type=\"button\" value=\"".get_string("continue").
+                echo "<input type=\"button\" value=\"".get_string("continue").
                     "\" onclick=\"document.password.submit();\" />";
-                               echo "</td></tr></table>";
-                               print_simple_box_end();
-                               exit();
-                       }
-               }
-           // in Stage 1 - the student must make an assessment (linked to the teacher's exercise/submission
+                echo "</td></tr></table>";
+                print_simple_box_end();
+                exit();
+            }
+        }
+        // in Stage 1 - the student must make an assessment (linked to the teacher's exercise/submission
         if (!exercise_test_user_assessments($exercise, $USER)) {
             print_heading(get_string("pleaseviewtheexercise", "exercise", $course->teacher));
             exercise_list_teacher_submissions($exercise, $USER);
                 print_heading(get_string("pleasesubmityourwork", "exercise").":");
                 exercise_print_upload_form($exercise);
             }
-            // in stage 3? - awaiting grading of assessment and assessment of work by teacher, 
+            // in stage 3? - awaiting grading of assessment and assessment of work by teacher,
             // may resubmit if allowed
             else {
                 exercise_list_teacher_submissions($exercise, $USER);
 
     /****************** submission of assignment by teacher only***********************/
     elseif ($action == 'submitassignment') {
-    
+
         if (!isteacheredit($course->id)) {
             error("Only teachers with editing permissions can do this.");
         }
-            
+
         exercise_print_assignment_info($exercise);
-        
+
         // list previous submissions from this user
         exercise_list_user_submissions($exercise, $USER);
-    
+
         echo "<hr size=\"1\" NOSHADE>";
-    
+
         // print upload form
         print_heading(get_string("submitexercisedescription", "exercise").":");
         exercise_print_upload_form($exercise);
         $changegroup = isset($_GET['group']) ? $_GET['group'] : -1;  // Group change requested?
         $groupmode = groupmode($course, $cm);   // Groups are being used?
         $currentgroup = get_and_set_current_group($course, $groupmode, $changegroup);
-        
+
         /// Allow the teacher to change groups (for this session)
         if ($groupmode) {
             if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
                 print_group_menu($groups, $groupmode, $currentgroup, "view.php?id=$cm->id");
             }
         }
-        
+
         print_heading_with_help(get_string("managingassignment", "exercise"), "managing", "exercise");
-    
+
         exercise_print_assignment_info($exercise);
-        $tabs->names = array("1. ".get_string("phase1", "exercise"), 
-            "2. ".get_string("phase2", "exercise", $course->student), 
-            "3. ".get_string("phase3", "exercise", $course->student)); 
+        $tabs->names = array("1. ".get_string("phase1", "exercise"),
+            "2. ".get_string("phase2", "exercise", $course->student),
+            "3. ".get_string("phase3", "exercise", $course->student));
         if (isteacheredit($course->id)) {
-            $tabs->urls = array("view.php?id=$cm->id&amp;action=setupassignment", 
+            $tabs->urls = array("view.php?id=$cm->id&amp;action=setupassignment",
                 "view.php?id=$cm->id&amp;action=openexercise",
                 "view.php?id=$cm->id&amp;action=makeleaguetableavailable");
         } else {
             // don't allow non-editing teacher to change phase
-            $tabs->urls = array("view.php?id=$cm->id", 
+            $tabs->urls = array("view.php?id=$cm->id",
                 "view.php?id=$cm->id",
                 "view.php?id=$cm->id");
         }
             $tabs->highlight = 0; // phase is zero
             }
         exercise_print_tabbed_heading($tabs);
-       
+
         echo "<center>\n";
             switch ($exercise->phase) {
                 case 0:
                         helpbutton("submissionofdescriptions", get_string("submitexercisedescription", "exercise"), "exercise");
                     }
                     break;
-                    
+
                 case 2: // submissions and assessments
-                    // just show student submissions link, the (self) assessments are show above the assessment form for 
+                    // just show student submissions link, the (self) assessments are show above the assessment form for
                     // the submissions
                     echo "<p><b><a href=\"submissions.php?id=$cm->id&amp;action=listforassessmentstudent\">".
-                          get_string("studentsubmissionsforassessment", "exercise", 
+                          get_string("studentsubmissionsforassessment", "exercise",
                           exercise_count_unassessed_student_submissions($exercise))."</a></b> \n";
-                    helpbutton("grading", get_string("studentsubmissionsforassessment", "exercise"), 
+                    helpbutton("grading", get_string("studentsubmissionsforassessment", "exercise"),
                             "exercise");
                     break;
-                    
+
                 case 3: // show final grades
                     echo "<p><b><a href=\"submissions.php?id=$cm->id&amp;action=listforassessmentstudent\">".
-                          get_string("studentsubmissionsforassessment", "exercise", 
+                          get_string("studentsubmissionsforassessment", "exercise",
                           exercise_count_unassessed_student_submissions($exercise))."</a></b> \n";
-                    helpbutton("grading", get_string("studentsubmissionsforassessment", "exercise"), 
+                    helpbutton("grading", get_string("studentsubmissionsforassessment", "exercise"),
                             "exercise");
                     print_heading("<a href=\"submissions.php?id=$cm->id&amp;action=displayfinalgrades\">".
                           get_string("displayoffinalgrades", "exercise")."</a>");
         print_heading("<a href=\"submissions.php?id=$cm->id&amp;action=adminlist\">".
             get_string("administration")."</a>");
     }
-    
-    
+
+
     /*************** no man's land **************************************/
     else {
         error("Fatal Error: Unknown Action: ".$action."\n");
     }
 
     print_footer($course);
-    
+
 ?>
index 825059b..1578588 100644 (file)
         error("Course ID is incorrect - discussion is faulty");
     }
 
-    if ($CFG->forcelogin) {
-        require_login();
+    if (! $cm = get_coursemodule_from_instance("forum", $discussion->forum, $course->id)) {
+        error("Course Module ID was incorrect");
     }
 
-    if ($course->category) {
-        require_login($course->id);
-    }
+    require_course_login($course, false, $cm);
 
     if (!empty($move)) {
         if (!isteacher($course->id)) {
index f3ed044..3453719 100644 (file)
         }
     }
 
-    if ($CFG->forcelogin) {
-        require_login();
-    }
-
-    if ($course->category) {
-        require_login($course->id);
-    }
+    require_course_login($course->id);
 
     $currentgroup = get_current_group($course->id);
 
@@ -56,7 +50,7 @@
         $generaltable->align[] = 'center';
     }
 
-    if ($show_rss = (($can_subscribe || $course->id == SITEID) && 
+    if ($show_rss = (($can_subscribe || $course->id == SITEID) &&
                      isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) &&
                      $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds)) {
         $generaltable->head[] = $strrss;
         $learningtable->align[] = 'center';
     }
 
-    if ($show_rss = (($can_subscribe || $course->id == SITEID) && 
+    if ($show_rss = (($can_subscribe || $course->id == SITEID) &&
                      isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) &&
                      $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds)) {
         $learningtable->head[] = $strrss;
                         $rsslink = rss_get_link($course->id, $userid, "forum", $forum->id, $tooltiptext);
                     }
                 }
-    
+
                 if ($can_subscribe) {
                     if (forum_is_forcesubscribed($forum->id)) {
                         $sublink = get_string("yes");
index 76d01b9..bb0e680 100644 (file)
@@ -2551,10 +2551,10 @@ function forum_print_latest_discussions($forum_id=0, $forum_numdiscussions=5,
         if (! $course = get_record("course", "id", $forum->course)) {
             error("Could not find the course this forum belongs to!");
         }
-
-        if ($course->category) {
-            require_login($course->id);
+        if (! $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
+            error("Course Module ID was incorrect");
         }
+        require_course_login($course, true, $cm);
 
     } else {
         if (! $course = get_record("course", "category", 0)) {
index eb962de..7981a9a 100644 (file)
 
     // $course, $forum are defined.  $discussion is for edit and reply only.
 
-    require_login($course->id);
+    $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id);
+
+    require_login($course->id, false, $cm);
 
 
     if ($post->discussion) {
 
     $navmiddle = "<a href=\"../forum/index.php?id=$course->id\">$strforums</a> -> <a href=\"view.php?f=$forum->id\">$forum->name</a>";
 
-    $cm = get_coursemodule_from_instance("forum", $forum->id, $course->id);
-
     if (empty($discussion->name)) {
         $discussion->name = $forum->name;
     }
index 1a63cf7..0a42a99 100644 (file)
@@ -24,9 +24,7 @@
         error("Course id is incorrect.");
     }
 
-    if ($course->category or $CFG->forcelogin) {
-        require_login($course->id);
-    }
+    require_course_login($course);
 
     add_to_log($course->id, "forum", "search", "search.php?id=$course->id&amp;search=".urlencode($search), $search);
 
index d3df1ec..0386dd2 100644 (file)
@@ -7,11 +7,7 @@
 
     require_variable($id);      // The forum to subscribe or unsubscribe to
     optional_variable($force);  // Force everyone to be subscribed to this forum?
-    optional_variable($user);  
-
-    if (isguest()) {
-        error("Guests are not allowed to subscribe to forums.", $_SERVER["HTTP_REFERER"]);
-    }
+    optional_variable($user);
 
     if (! $forum = get_record("forum", "id", $id)) {
         error("Forum ID was incorrect");
         error("Forum doesn't belong to a course!");
     }
 
+    if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
+        if (groupmode($course, $cm) and !isteacheredit($course->id)) {   // Make sure user is allowed
+            if (! mygroupid($course->id)) {
+                error("Sorry, but you must be a group member to subscribe.");
+            }
+        }
+    } else {
+        $cm->id = NULL;
+    }
+
     if ($user) {
         if (!isteacher($course->id)) {
             error("Only teachers can subscribe/unsubscribe other people!");
         $user = $USER;
     }
 
-    if ($course->category) {
-        require_login($forum->course);
-    } else {
-        require_login();
+    require_course_login($course, false, $cm);
+
+    if (isguest()) {
+        error("Guests are not allowed to subscribe to forums.", $_SERVER["HTTP_REFERER"]);
     }
 
     if ($forum->type == "teacher") {
         }
     }
 
-    if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
-        if (groupmode($course, $cm) and !isteacheredit($course->id)) {   // Make sure user is allowed
-            if (! mygroupid($course->id)) {
-                error("Sorry, but you must be a group member to subscribe.");
-            }
-        }
-    } else {
-        $cm->id = NULL;
-    }
-
     $returnto = forum_go_back_to("index.php?id=$course->id");
 
     if ($force and isteacher($course->id)) {
@@ -80,7 +76,7 @@
         } else {
             error("Could not unsubscribe you from that forum", $_SERVER["HTTP_REFERER"]);
         }
-        
+
     } else { // subscribe
         if (forum_subscribe($user->id, $forum->id) ) {
             add_to_log($course->id, "forum", "subscribe", "view.php?f=$forum->id", $forum->id, $cm->id);
index 97cd9db..7e7e85f 100644 (file)
@@ -20,7 +20,7 @@
         $cm->id = 0;
     }
 
-    require_login($course->id);
+    require_login($course->id, false, $cm);
 
     if (!isteacher($course->id)) {
         error("This page is for teachers only");
index 2c411dc..fd2ff23 100644 (file)
@@ -5,8 +5,8 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2005011500;
-$module->requires = 2004091700;  // Requires this Moodle version
+$module->version  = 2005021600;
+$module->requires = 2005021600;  // Requires this Moodle version
 $module->cron     = 60;
 
 ?>
index 32f8097..6b7d9d7 100644 (file)
         $buttontext = forum_print_search_form($course, $search, true, "plain");
     }
 
-    if ($CFG->forcelogin) {
-        require_login();
-    }
+    require_course_login($course, true, $cm);
 
-    if ($course->category) {
-        require_login($course->id);
-    }
     $navigation = "<a href=\"index.php?id=$course->id\">$strforums</a> ->";
 
     if ($forum->type == "teacher") {
index 22ac3c2..f5f01c2 100644 (file)
@@ -2,7 +2,7 @@
 
     require_once("../../config.php");
     require_once("lib.php");
-    
+
     require_variable($id);           // Course Module ID
     optional_variable($eid);         // Entry ID
 
 
     if (! $cm = get_record("course_modules", "id", $id)) {
         error("Course Module ID was incorrect");
-    } 
-    
+    }
+
     if (! $course = get_record("course", "id", $cm->course)) {
         error("Course is misconfigured");
-    } 
-    
+    }
+
     if (! $glossary = get_record("glossary", "id", $cm->instance)) {
         error("Course module is incorrect");
-    } 
-    
-    require_login($course->id);    
+    }
+
+    require_login($course->id, false, $cm);
     if (!isteacher($course->id)) {
         error("You must be a teacher to use this page.");
-    } 
+    }
     $newentry->id = $eid;
     $newentry->approved = 1;
 
index 5a2c8d2..8ae572f 100644 (file)
 
     if (! $cm = get_record("course_modules", "id", $id)) {
         error("Course Module ID was incorrect");
-    } 
+    }
 
     if (! $course = get_record("course", "id", $cm->course)) {
         error("Course is misconfigured");
-    } 
+    }
 
     if (! $glossary = get_record("glossary", "id", $cm->instance)) {
         error("Course module is incorrect");
-    } 
+    }
 
     if (! $entry = get_record("glossary_entries", "id", $eid)) {
         error("Entry is incorrect");
         if (! $comment = get_record("glossary_comments", "id", $cid)) {
             error("Comment is incorrect");
         }
-    } 
+    }
+
+    require_login($course->id, false, $cm);
 
-    require_login($course->id);    
-    if (!$cm->visible and !isteacher($course->id)) {
-        notice(get_string("activityiscurrentlyhidden"));
-    } 
     if (isguest()) {
         error("Guests are not allowed to post comments", $_SERVER["HTTP_REFERER"]);
-    }    
+    }
     add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id",$cm->id);
 
     switch ( $action ){
@@ -70,7 +68,7 @@
             "<a href=index.php?id=$course->id>$strglossaries</a> -> <a href=view.php?id=$cm->id>$glossary->name</a> -> <a href=comments.php?id=$cm->id&amp;eid=$entry->id>$strcomments</a> -> " . $straction,
             "", "", true, update_module_button($cm->id, $course->id, $strglossary),
             navmenu($course, $cm));
-    
+
     echo "<center>";
 
 /// Input section
@@ -83,7 +81,7 @@
                 error("You can't delete comments in this glossary!");
             }
         if ( $confirm ) {
-            delete_records("glossary_comments","id", $cid);             
+            delete_records("glossary_comments","id", $cid);
 
             print_simple_box_start("center","40%", "#FFBBBB");
             echo "<center>" . get_string("commentdeleted","glossary") . "</center>";
             }
             include("comment.html");
 
-            if ($usehtmleditor) { 
+            if ($usehtmleditor) {
                 use_html_editor("text");
             }
         }
index 3fa6f08..ca027d6 100644 (file)
@@ -3,36 +3,33 @@
 /// This page prints a particular instance of glossary
     require_once("../../config.php");
     require_once("lib.php");
-    
+
     require_variable($id);           // Course Module ID
     require_variable($eid);         // Entry ID
-    
+
     global $THEME, $USER, $CFG;
-    
+
     if (! $cm = get_record("course_modules", "id", $id)) {
         error("Course Module ID was incorrect");
-    } 
-    
+    }
+
     if (! $course = get_record("course", "id", $cm->course)) {
         error("Course is misconfigured");
-    } 
-    
+    }
+
     if (! $glossary = get_record("glossary", "id", $cm->instance)) {
         error("Course module is incorrect");
-    } 
-    
+    }
+
     if (! $entry = get_record("glossary_entries", "id", $eid)) {
         error("Entry is incorrect");
-    } 
+    }
+
 
+    require_login($course->id, false, $cm);
 
-    require_login($course->id);    
-    if (!$cm->visible and !isteacher($course->id)) {
-        notice(get_string("activityiscurrentlyhidden"));
-    } 
-    
     add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id",$cm->id);
-    
+
     $strglossaries = get_string("modulenameplural", "glossary");
     $strglossary = get_string("modulename", "glossary");
     $strallcategories = get_string("allcategories", "glossary");
     $strsearch = get_string("search");
     $strcomments = get_string("comments", "glossary");
     $straddcomment = get_string("addcomment", "glossary");
-    
+
     print_header_simple(strip_tags("$strcomments: $entry->concept"), "",
         "<a href=index.php?id=$course->id>$strglossaries</a> -> <a href=view.php?id=$cm->id>$glossary->name</a> -> $strcomments",
         "", "", true, update_module_button($cm->id, $course->id, $strglossary),
         navmenu($course, $cm));
-    
+
 /// original glossary entry
 
     echo "<center>";
@@ -59,7 +56,7 @@
 
     print_heading(get_string('commentson','glossary')." <b>\"$entry->concept\"</b>");
 
-    if ($glossary->allowcomments || isteacher($glossary->course)) { 
+    if ($glossary->allowcomments || isteacher($glossary->course)) {
         print_heading("<a href=\"comment.php?id=$cm->id&amp;eid=$entry->id\">$straddcomment</a> <img title=\"$straddcomment\" src=\"comment.gif\" height=\"11\" width=\"11\" border=\"0\" alt=\"\" />");
     }
 
index e1ea1fd..a104b2d 100644 (file)
@@ -28,7 +28,7 @@
         error("Entry ID was incorrect");
     }
 
-    require_login($course->id);
+    require_login($course->id, false, $cm);
 
     if (isguest()) {
         error("Guests are not allowed to edit or delete entries", $_SERVER["HTTP_REFERER"]);
@@ -45,8 +45,8 @@
     $strareyousuredelete = get_string("areyousuredelete","glossary");
 
     print_header_simple("$glossary->name", "",
-                 "<a href=\"index.php?id=$course->id\">$strglossaries</a> -> $glossary->name", 
-                  "", "", true, update_module_button($cm->id, $course->id, $strglossary), 
+                 "<a href=\"index.php?id=$course->id\">$strglossaries</a> -> $glossary->name",
+                  "", "", true, update_module_button($cm->id, $course->id, $strglossary),
                   navmenu($course, $cm));
 
 
@@ -59,7 +59,7 @@
     }
 
 /// If data submitted, then process and store.
-    
+
     if ($confirm) { // the operation was confirmed.
         // if it is an imported entry, just delete the relation
 
@@ -77,7 +77,7 @@
             delete_records("glossary_comments", "entryid",$entry->id);
             delete_records("glossary_alias", "entryid", $entry->id);
             delete_records("glossary_ratings", "entryid", $entry->id);
-            delete_records("glossary_entries","id", $entry->id);                
+            delete_records("glossary_entries","id", $entry->id);
         }
 
         add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&amp;mode=$prevmode&amp;hook=$hook", $entry->id,$cm->id);
index 7293685..549de7d 100644 (file)
@@ -20,7 +20,7 @@ if (! $course = get_record("course", "id", $cm->course)) {
     error("Course is misconfigured");
 }
 
-require_login($course->id);
+require_login($course->id, false, $cm);
 
 if ( isguest() ) {
     error("Guests are not allowed to edit glossaries", $_SERVER["HTTP_REFERER"]);
index 421461c..c372d9c 100644 (file)
@@ -18,7 +18,7 @@
     $mode   = optional_param('mode');   // cat
 
     $action = strtolower($action);
-        
+
     if (! $cm = get_record("course_modules", "id", $id)) {
         error("Course Module ID was incorrect");
     }
@@ -42,7 +42,7 @@
         }
     }
 
-    require_login($course->id);
+    require_login($course->id, false);
 
     if ( !isteacher($course->id) ) {
         error("You must be a teacher to use this page.");
                 print_footer($course);
 
                 add_to_log($course->id, "glossary", "delete category", "editcategories.php?id=$cm->id", $hook,$cm->id);
-                    
+
                 redirect("editcategories.php?id=$cm->id");
             } else {
                 echo "<p align=\"center\">" . get_string("delete"). " " . get_string("category","glossary") . "<font size=\"3\">";
 
                 print_simple_box_start("center","40%", "#FFBBBB");
                 echo "<center><b>".format_text($category->name)."</b><br>";
-                
+
                 $num_entries = count_records("glossary_entries_categories","categoryid",$category->id);
                 if ( $num_entries ) {
                     print_string("deletingnoneemptycategory","glossary");
             $dupcategory = get_record("glossary_categories","$lcase(name)",strtolower($name),"glossaryid",$glossary->id);
             if ( $dupcategory ) {
                 echo "<p align=\"center\">" . get_string("add"). " " . get_string("category","glossary") . "<font size=\"3\">";
-                    
+
                 print_simple_box_start("center","40%", "#FFBBBB");
                 echo "<center>" . get_string("duplicatedcategory","glossary") ."</center>";
                 echo "</center>";
                 print_simple_box_end();
-                
+
                 print_footer($course);
 
                 redirect("editcategories.php?id=$cm->id&amp;action=add&&amp;name=$name");
 
                 if ( ! $cat->id = insert_record("glossary_categories", $cat) ) {
                     error("Weird error. The category was not inserted.");
-                        
+
                     redirect("editcategories.php?id=$cm->id");
                 } else {
                     add_to_log($course->id, "glossary", "add category", "editcategories.php?id=$cm->id", $cat->id,$cm->id);
             require "editcategories.html";
         }
     }
-     
+
     if ( $action ) {
         print_footer();
         die;
           <?php p(get_string("action")) ?></b></td>
         </tr>
         <tr><td width="100%" colspan="2"  bgcolor="<?php p($THEME->cellheading2)?>">
-        
+
         <table width="100%">
 
 <?php
                ?>
                </b></td>
              </tr>
-             
+
              <?php
           }
      }
 ?>
         </table>
-        
+
         </td>
         <tr>
         <td width="100%" colspan="2"  align="center" bgcolor="<?php p($THEME->cellheading2)?>">
             <?php
-            
+
              $options['id'] = $cm->id;
              $options['action'] = "add";
-             
+
              echo "<table border=\"0\"><tr><td align=\"right\">";
              echo print_single_button("editcategories.php", $options, get_string("add") . " " . get_string("category","glossary"), "get");
              echo "</td><td align=\"left\">";
index c0332b4..284307e 100644 (file)
@@ -21,7 +21,7 @@
         error("Course module is incorrect");
     }
 
-    require_login($course->id);
+    require_login($course->id, false);
     if (!isteacher($course->id)) {
         error("You must be a teacher to use this page.");
     }
@@ -45,7 +45,7 @@
         "$navigation <a href=\"index.php?id=$course->id\">$strglossaries</a> -> $glossary->name",
         "", "", true, update_module_button($cm->id, $course->id, $strglossary),
         navmenu($course, $cm));
-    
+
     echo '<div id="glossary-export" class="glossary">';  // glossary-export wrapper start
 
     echo '<p align="center"><font size="3"><b>' . stripslashes_safe($glossary->name);
index cc8a7c1..0bf8859 100644 (file)
@@ -1,14 +1,14 @@
 <?php    // $Id$
-    /// This file allows to manage the default behave of the display formats
-    
+    /// This file allows to manage the default behaviour of the display formats
+
     require_once("../../config.php");
     require_once("lib.php");
     global $CFG, $THEME;
-        
-    require_variable($id);    
-  
+
+    require_variable($id);
+
     $mode = optional_param('mode');
-        
+
     require_login();
     if ( !isadmin() ) {
         error("You must be an admin to use this page.");
@@ -16,7 +16,7 @@
     if (!$site = get_site()) {
         error("Site isn't defined!");
     }
-    
+
     if ( !$displayformat = get_record("glossary_formats","id",$id) ) {
         error ("Invalid Glossary Format");
     }
         redirect("../../$CFG->admin/module.php?sesskey=$USER->sesskey&module=glossary#formats");
         die;
     } elseif ( $mode == 'edit' and $form) {
-        
+
         $displayformat->popupformatname = $form->popupformatname;
         $displayformat->showgroup   = $form->showgroup;
         $displayformat->defaultmode = $form->defaultmode;
         $displayformat->defaulthook = $form->defaulthook;
         $displayformat->sortkey     = $form->sortkey;
         $displayformat->sortorder   = $form->sortorder;
-        
+
         update_record("glossary_formats",$displayformat);
         redirect("../../$CFG->admin/module.php?sesskey=$USER->sesskey&module=glossary#formats");
         die;
     }
-    
+
     $stradmin = get_string("administration");
     $strconfiguration = get_string("configuration");
     $strmanagemodules = get_string("managemodules");
         $recformats = glossary_get_available_formats();
 
         $formats = array();
-    
+
         //Take names
         foreach ($recformats as $format) {
            $formats[$format->name] = get_string("displayformat$format->name", "glossary");
         }
         //Sort it
         asort($formats);
-        
+
         choose_from_menu($formats,'popupformatname',$displayformat->popupformatname);
      ?>
         </td>
         <td align="right" width="20%"><?php print_string('defaultmode','glossary'); ?></td>
         <td>
         <select size="1" name="defaultmode">
-    <?php 
+    <?php
         $sletter = '';
         $scat = '';
         $sauthor = '';
         $sdate = '';
         switch ( strtolower($displayformat->defaultmode) ) {
-        case 'letter': 
+        case 'letter':
             $sletter = ' selected="selected" ';
         break;
-        
-        case 'cat': 
+
+        case 'cat':
             $scat = ' selected="selected" ';
         break;
-        
-        case 'date': 
+
+        case 'date':
             $sdate = ' selected="selected" ';
         break;
 
-        case 'author': 
+        case 'author':
             $sauthor = ' selected="selected" ';
         break;
         }
         <td align="right" width="20%"><?php print_string('defaulthook','glossary'); ?></td>
         <td>
         <select size="1" name="defaulthook">
-    <?php 
+    <?php
         $sall = '';
         $sspecial = '';
         $sallcategories = '';
         $snocategorised = '';
         switch ( strtolower($displayformat->defaulthook) ) {
-        case 'all': 
+        case 'all':
             $sall = ' selected="selected" ';
         break;
-        
-        case 'special': 
+
+        case 'special':
             $sspecial = ' selected="selected" ';
         break;
-        
-        case '0': 
+
+        case '0':
             $sallcategories = ' selected="selected" ';
         break;
 
-        case '-1': 
+        case '-1':
             $snocategorised = ' selected="selected" ';
         break;
         }
         <td align="right" width="20%"><?php print_string('defaultsortkey','glossary'); ?></td>
         <td>
         <select size="1" name="sortkey">
-    <?php 
+    <?php
         $sfname = '';
         $slname = '';
         $supdate = '';
         $screation = '';
         switch ( strtolower($displayformat->sortkey) ) {
-        case 'firstname': 
+        case 'firstname':
             $sfname = ' selected="selected" ';
         break;
-        
-        case 'lastname': 
+
+        case 'lastname':
             $slname = ' selected="selected" ';
         break;
-        
-        case 'creation': 
+
+        case 'creation':
             $screation = ' selected="selected" ';
         break;
 
-        case 'update': 
+        case 'update':
             $supdate = ' selected="selected" ';
         break;
         }
         <td align="right" width="20%"><?php print_string('defaultsortorder','glossary'); ?></td>
         <td>
         <select size="1" name="sortorder">
-    <?php 
+    <?php
         $sasc = '';
         $sdesc = '';
         switch ( strtolower($displayformat->sortorder) ) {
-        case 'asc': 
+        case 'asc':
             $sasc = ' selected="selected" ';
         break;
-        
-        case 'desc': 
+
+        case 'desc':
             $sdesc = ' selected="selected" ';
         break;
         }
     <input type="hidden" name="id"    value="<?php p($id) ?>" />
     <input type="hidden" name="mode"    value="edit" />
     <?php
-    
-    print_simple_box_end();    
+
+    print_simple_box_end();
     echo '</form>';
 
     print_footer();
index a0bcc08..af1e607 100644 (file)
@@ -27,7 +27,7 @@
         error("Course module is incorrect");
     }
 
-    require_login($course->id);
+    require_login($course->id, false);
     if (!isteacher($course->id)) {
         error("You must be a teacher to use this page.");
     }
index 6c40b7b..764cdab 100644 (file)
@@ -4,11 +4,11 @@
 
     require_once("../../config.php");
     require_once("lib.php");
-    
+
     require_variable($id);                         // Course Module ID
-    optional_variable($sortorder,"asc");           // Sorting order 
+    optional_variable($sortorder,"asc");           // Sorting order
     optional_variable($offset,0,PARAM_INT);        // number of entries to bypass
-    optional_variable($displayformat,-1); 
+    optional_variable($displayformat,-1);
 
     $mode    = required_param('mode');             // mode to show the entries
     $hook    = optional_param('hook','ALL');       // what to show
 
     if (! $cm = get_record("course_modules", "id", $id)) {
         error("Course Module ID was incorrect");
-    } 
-    
+    }
+
     if (! $course = get_record("course", "id", $cm->course)) {
         error("Course is misconfigured");
-    } 
-    
+    }
+
     if (! $glossary = get_record("glossary", "id", $cm->instance)) {
         error("Course module is incorrect");
-    } 
-    
+    }
+
     if ( !$entriesbypage = $glossary->entbypage ) {
         $entriesbypage = $CFG->glossary_entbypage;
     }
 
     print_header();
 
-    if ($CFG->forcelogin) {
-        require_login();
-    }
-
-    require_course_login($course);
-
-    if (!$cm->visible and !isteacher($course->id)) {
-        notice(get_string("activityiscurrentlyhidden"));
-    }
+    require_course_login($course, true, $cm);
 
     if (!isteacher($course->id) and !$glossary->allowprintview) {
         notice(get_string('printviewnotallowed', 'glossary'));
@@ -75,9 +67,9 @@
         }
     }
     if ( $sortkey = strtoupper($sortkey) ) {
-        if ($sortkey != 'CREATION' and 
-            $sortkey != 'UPDATE' and 
-            $sortkey != 'FIRSTNAME' and 
+        if ($sortkey != 'CREATION' and
+            $sortkey != 'UPDATE' and
+            $sortkey != 'FIRSTNAME' and
             $sortkey != 'LASTNAME'
             ) {
             $sortkey = '';
@@ -88,7 +80,7 @@
     case 'entry':  /// Looking for a certain entry id
         $tab = GLOSSARY_STANDARD_VIEW;
     break;
-    
+
     case 'cat':    /// Looking for a certain cat
         $tab = GLOSSARY_CATEGORY_VIEW;
         if ( $hook > 0 ) {
         $tab = GLOSSARY_DATE_VIEW;
         if ( !$sortkey ) {
             $sortkey = 'UPDATE';
-        } 
+        }
         if ( !$sortorder ) {
             $sortorder = 'desc';
         }
     break;
-    
+
     case 'author':  /// Looking for entries, browsed by author
         $tab = GLOSSARY_AUTHOR_VIEW;
         if ( !$hook ) {
             $hook = 'ALL';
-        } 
+        }
         if ( !$sortkey ) {
             $sortkey = 'FIRSTNAME';
-        } 
+        }
         if ( !$sortorder ) {
             $sortorder = 'asc';
         }
     default:
         $tab = GLOSSARY_STANDARD_VIEW;
         if ( !$hook ) {
-            $hook = 'ALL';  
-        } 
+            $hook = 'ALL';
+        }
     break;
-    }  
+    }
 
     include_once("sql.php");
-    
+
     $entriesshown = 0;
     $currentpivot = '';
     if ( $hook == 'SPECIAL' ) {
             $pivot = $entry->pivot;
             if ( !$fullpivot ) {
                 $pivot = $pivot[0];
-            }            
-            
+            }
+
             // If there's  group break
-            if ( $currentpivot != strtoupper($pivot) ) {  
+            if ( $currentpivot != strtoupper($pivot) ) {
 
                 // print the group break if apply
                 if ( $printpivot )  {
index 7f95fbf..4f5d116 100644 (file)
@@ -6,9 +6,6 @@
     require_once("../../config.php");
     require_once("lib.php");
 
-    if (isguest()) {
-        error("Guests are not allowed to rate entries.", $_SERVER["HTTP_REFERER"]);
-    }
 
     require_variable($id);  // The course these ratings are part of
 
 
     require_login($course->id);
 
+    if (isguest()) {
+        error("Guests are not allowed to rate entries.", $_SERVER["HTTP_REFERER"]);
+    }
+
     if ($data = data_submitted("$CFG->wwwroot/mod/glossary/view.php")) {    // form submitted
 
         foreach ($data as $entry => $rating) {
index 93b8ec7..416dbe6 100644 (file)
@@ -4,7 +4,7 @@
 
     optional_variable($concept);
     optional_variable($courseid,0);
-    optional_variable($eid,0);
+    optional_variable($eid,0); // glossary entry id
     optional_variable($displayformat,-1);
 
     if ($CFG->forcelogin) {
         $glossary = get_record('glossary','id',$entry->glossaryid);
         $entry->glossaryname = $glossary->name;
         $entries[] = $entry;
-
+        if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id)) {
+            error("Could not determine which course module this belonged to!");
+        }
+        if (!$cm->visible and !isteacher($cm->course)) {
+            redirect($CFG->wwwroot.'/course/view.php?id='.$cm->course, get_string('activityiscurrentlyhidden'));
+        }
     } else if ($concept) {
         $entries = glossary_get_entries_search($concept, $courseid);
+    } else {
+        error('No valid entry specified');
     }
 
-    foreach ($entries as $key => $entry) {
-        //$entries[$key]->footer = "<p align=\"right\">&raquo;&nbsp;<a onClick=\"if (window.opener) {window.opener.location.href='$CFG->wwwroot/mod/glossary/view.php?g=$entry->glossaryid'; return false;} else {openpopup('/mod/glossary/view.php?g=$entry->glossaryid', 'glossary', 'menubar=1,location=1,toolbar=1,scrollbars=1,directories=1,status=1,resizable=1', 0); return false;}\" href=\"$CFG->wwwroot/mod/glossary/view.php?g=$entry->glossaryid\" target=\"_blank\">$entry->glossaryname</a></p>";  // Could not get this to work satisfactorily in all cases  - Martin
-        $entries[$key]->footer = "<p align=\"right\">&raquo;&nbsp;<a target=\"_blank\" href=\"$CFG->wwwroot/mod/glossary/view.php?g=$entry->glossaryid\">$entry->glossaryname</a></p>";
+    if ($entries) {
+        foreach ($entries as $key => $entry) {
+            //$entries[$key]->footer = "<p align=\"right\">&raquo;&nbsp;<a onClick=\"if (window.opener) {window.opener.location.href='$CFG->wwwroot/mod/glossary/view.php?g=$entry->glossaryid'; return false;} else {openpopup('/mod/glossary/view.php?g=$entry->glossaryid', 'glossary', 'menubar=1,location=1,toolbar=1,scrollbars=1,directories=1,status=1,resizable=1', 0); return false;}\" href=\"$CFG->wwwroot/mod/glossary/view.php?g=$entry->glossaryid\" target=\"_blank\">$entry->glossaryname</a></p>";  // Could not get this to work satisfactorily in all cases  - Martin
+            $entries[$key]->footer = "<p align=\"right\">&raquo;&nbsp;<a target=\"_blank\" href=\"$CFG->wwwroot/mod/glossary/view.php?g=$entry->glossaryid\">$entry->glossaryname</a></p>";
+        }
     }
 
     if (!empty($courseid)) {
@@ -50,8 +59,8 @@
 
     if ($entries) {
         glossary_print_dynaentry($courseid, $entries, $displayformat);
-    }    
-    
+    }
+
     close_window_button();
 
 ?>
index 08ee97a..a017f72 100644 (file)
@@ -5,8 +5,8 @@
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2005011200;
-$module->requires = 2004112300;  // Requires this Moodle version
+$module->version  = 2005021600;
+$module->requires = 2005021600;  // Requires this Moodle version
 $module->cron     = 0;           // Period for cron to check this module (secs)
 
 $release = "1.5 development";   // User-friendly version number
index 9b33b65..cf4796c 100644 (file)
@@ -12,7 +12,7 @@
         error("Course is misconfigured");
     }
 
-    require_login($course->id);
+    require_login($course->id, false, $cm);
 
     if (isguest()) {
         error("Guests are not allowed to edit journals", $_SERVER["HTTP_REFERER"]);
@@ -52,8 +52,8 @@
                 error("Could not insert a new journal entry");
             }
             add_to_log($course->id, "journal", "add entry", "view.php?id=$cm->id", "$newentry->id", $cm->id);
-        } 
-        
+        }
+
         redirect("view.php?id=$cm->id");
         die;
     }
     } else {
         $defaultformat = FORMAT_MOODLE;
     }
-    
+
     if (empty($entry)) {
         $entry->text = "";
         $entry->format = $defaultformat;
     }
 
     print_header_simple("$journal->name", "",
-                 "<a href=\"index.php?id=$course->id\">$strjournals</a> -> 
+                 "<a href=\"index.php?id=$course->id\">$strjournals</a> ->
                   <a href=\"view.php?id=$cm->id\">$journal->name</a> -> $stredit", "",
                   "", true, "", navmenu($course, $cm));
 
index 37fa407..5779937 100644 (file)
@@ -13,7 +13,7 @@
         error("Course module is misconfigured");
     }
 
-    require_login($course->id);
+    require_login($course->id, false);
 
     if (!isteacher($course->id)) {
         error("Only teachers can look at this page");
@@ -29,7 +29,7 @@
             $entrybyuser[$ee->userid] = $ee;
             $entrybyentry[$ee->id]  = $ee;
         }
-        
+
     } else {
         $entrybyuser  = array () ;
         $entrybyentry = array () ;
@@ -52,7 +52,7 @@
 
 /// Process incoming data if there is any
     if ($data = data_submitted()) {
-       
+
         $feedback = array();
         $data = (array)$data;
 
@@ -60,7 +60,7 @@
         foreach ($data as $key => $val) {
             if ($key <> "id") {
                 $type = substr($key,0,1);
-                $num  = substr($key,1); 
+                $num  = substr($key,1);
                 $feedback[$num][$type] = $val;
             }
         }
             echo "</form>";
         }
     }
-    
+
     print_footer($course);
+
 ?>
 
index 7160d69..fd2ff23 100644 (file)
@@ -5,8 +5,8 @@
 //  This fragment is called by /admin/index.php
 ////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2004111200;
-$module->requires = 2004052505;  // Requires this Moodle version
+$module->version  = 2005021600;
+$module->requires = 2005021600;  // Requires this Moodle version
 $module->cron     = 60;
 
 ?>
index caace7a..0d557fb 100644 (file)
@@ -13,7 +13,7 @@
         error("Course is misconfigured");
     }
 
-    require_login($course->id);
+    require_login($course->id, true, $cm);
 
     if (! $journal = get_record("journal", "id", $cm->instance)) {
         error("Course module is incorrect");
@@ -50,7 +50,7 @@
     }
 
     echo "<center>\n";
-    
+
     $journal->intro = trim($journal->intro);
 
     if (!empty($journal->intro)) {
@@ -96,7 +96,7 @@
             } else {
                 echo format_text($entry->text, $entry->format);
             }
-            
+
         } else {
             echo "<b><i>".get_string("notstarted","journal")."</i></b>";
         }
index 0066969..8392d3a 100644 (file)
@@ -20,7 +20,7 @@
     }
 
 
-    require_login($course->id);
+    require_login($course->id, false);
 
     if (!isteacher($course->id)) {
         error("Only the teacher can import questions!");
@@ -39,7 +39,7 @@
         if (empty($_FILES['newfile'])) {      // file was just uploaded
             notify(get_string("uploadproblem") );
         }
-        
+
         if ((!is_uploaded_file($_FILES['newfile']['tmp_name']) or $_FILES['newfile']['size'] == 0)) {
             notify(get_string("uploadnofilefound") );
 
@@ -72,7 +72,7 @@
             print_footer($course);
             exit;
         }
-    } 
+    }
 
     /// Print upload form
 
index 80e5cda..2eb187f 100644 (file)
@@ -1,49 +1,49 @@
 <?PHP  // $Id: lesson.php, v 1.0 25 Jan 2004
 
 /*************************************************
-       ACTIONS handled are:
+    ACTIONS handled are:
 
-       addbranchtable
+    addbranchtable
     addendofbranch
-       addcluster      /// CDC-FLAG /// added two new items
-       addendofcluster
+    addcluster      /// CDC-FLAG /// added two new items
+    addendofcluster
     addpage
     confirmdelete
     continue
-       delete
-       editpage
+    delete
+    editpage
     insertpage
     move
-       moveit
-       updatepage
+    moveit
+    updatepage
 
 ************************************************/
 
     require("../../config.php");
-       require("locallib.php");
-       require_once("styles.php");
+    require("locallib.php");
+    require_once("styles.php");
+
+
+    $id = required_param('id', PARAM_INT);    // Course Module ID
 
-       
-       $id = required_param('id', PARAM_INT);    // Course Module ID
     // get some esential stuff...
-       if (! $cm = get_record("course_modules", "id", $id)) {
-               error("Course Module ID was incorrect");
-       }
+    if (! $cm = get_record("course_modules", "id", $id)) {
+        error("Course Module ID was incorrect");
+    }
+
+    if (! $course = get_record("course", "id", $cm->course)) {
+        error("Course is misconfigured");
+    }
 
-       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");
+    }
 
-       if (! $lesson = get_record("lesson", "id", $cm->instance)) {
-               error("Course module is incorrect");
-       }
+    require_login($course->id, false, $cm);
 
-    require_login($course->id);
-       
     // 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 the header and...
     print_header("$course->shortname: $lesson->name", "$course->fullname",
-                 "$navigation <A HREF=index.php?id=$course->id>$strlessons</A> -> 
-                  <A HREF=\"view.php?id=$cm->id\">$lesson->name</A>", 
+                 "$navigation <A HREF=index.php?id=$course->id>$strlessons</A> ->
+                  <A HREF=\"view.php?id=$cm->id\">$lesson->name</A>",
                   "", "", true);
 
-       //...get the action 
-       $action = required_param('action');
-       
-       /************** add branch table ************************************/
-       if ($action == 'addbranchtable' ) {
+    //...get the action
+    $action = required_param('action');
 
-               if (!isteacher($course->id)) {
-               error("Only teachers can look at this page");
-           }
+    /************** add branch table ************************************/
+    if ($action == 'addbranchtable' ) {
+
+        if (!isteacher($course->id)) {
+            error("Only teachers can look at this page");
+        }
 
         // first get the preceeding page
         $pageid = required_param('pageid', PARAM_INT);
-            
+
         // set of jump array
         $jump = array();
-               $jump[0] = get_string("thispage", "lesson");
+        $jump[0] = get_string("thispage", "lesson");
         $jump[LESSON_NEXTPAGE] = get_string("nextpage", "lesson");
-               //// 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 /////
+        //// 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");
+        print_heading_with_help(get_string("addabranchtable", "lesson"), "overview", "lesson");
         ?>
         <form name="form" method="post" action="lesson.php" />
         <input type="hidden" name="id" value="<?PHP echo $cm->id ?>" />
         <input type="hidden" name="action" value="insertpage">
         <input type="hidden" name="pageid" value="<?PHP echo $pageid ?>" />
         <input type="hidden" name="qtype" value="<?PHP echo LESSON_BRANCHTABLE ?>" />
-               <input type="hidden" name="sesskey" value="<?PHP echo $USER->sesskey ?>" />
+        <input type="hidden" name="sesskey" value="<?PHP echo $USER->sesskey ?>" />
         <center><table cellpadding=5 border=1>
         <tr><td align="center">
         <tr valign="top">
         echo get_string("pagecontents", "lesson").":</b><br />\n";
         print_textarea($usehtmleditor, 25,70, 630, 400, "contents");
         use_html_editor("contents");
-               echo "</td></tr>\n";
-               /// CDC-FLAG /// 6/16/04
-               echo "<tr><td>\n";
-               echo "<center><input name=\"layout\" type=\"checkbox\" value=\"1\" checked=\"checked\" />";
-               echo get_string("arrangebuttonshorizontally", "lesson")."\n";
-               echo "<br><input name=\"display\" type=\"checkbox\" value=\"1\" checked=\"checked\" />";
-               echo get_string("displayinleftmenu", "lesson");
-               echo "</center>\n";
-               echo "</td></tr>\n";
-               /// CDC-FLAG ///                                
+        echo "</td></tr>\n";
+        /// CDC-FLAG /// 6/16/04
+        echo "<tr><td>\n";
+        echo "<center><input name=\"layout\" type=\"checkbox\" value=\"1\" checked=\"checked\" />";
+        echo get_string("arrangebuttonshorizontally", "lesson")."\n";
+        echo "<br><input name=\"display\" type=\"checkbox\" value=\"1\" checked=\"checked\" />";
+        echo get_string("displayinleftmenu", "lesson");
+        echo "</center>\n";
+        echo "</td></tr>\n";
+        /// CDC-FLAG ///
         for ($i = 0; $i < $lesson->maxanswers; $i++) {
             $iplus1 = $i + 1;
             echo "<tr><td><b>".get_string("description", "lesson")." $iplus1:</b><br />\n";
             print_textarea(false, 10, 70, 630, 300, "answer[$i]");  // made the default set to off also removed use_html_editor(); line from down below, which made all textareas turn into html editors
-                       echo "</td></tr>\n";
+            echo "</td></tr>\n";
             echo "<tr><td><B>".get_string("jump", "lesson")." $iplus1:</b> \n";
             if ($i) {
                 // answers 2, 3, 4... jumpto this page
         </center>
         </form>
         <?PHP
-       }
-       
+    }
 
-       /************** add end of branch ************************************/
+
+    /************** add end of branch ************************************/
     elseif ($action == 'addendofbranch' ) {
 
-               if (!isteacher($course->id)) {
-               error("Only teachers can look at this page");
-           }
+        if (!isteacher($course->id)) {
+            error("Only teachers can look at this page");
+        }
 
-               confirm_sesskey();
+        confirm_sesskey();
 
         // first get the preceeding page
         $pageid = required_param('pageid', PARAM_INT);
-            
+
         $timenow = time();
-        
+
         // the new page is not the first page (end of branch always comes after an existing page)
         if (!$page = get_record("lesson_pages", "id", $pageid)) {
             error("Add end of branch: page record not found");
             }
         }
         if ($btpage->qtype == LESSON_BRANCHTABLE) {
-                       $newpage = new stdClass;
+            $newpage = new stdClass;
             $newpage->lessonid = $lesson->id;
             $newpage->prevpageid = $pageid;
             $newpage->nextpageid = $page->nextpageid;
                 }
             }
             // ..and the single "answer"
-                       $newanswer = new stdClass;
+            $newanswer = new stdClass;
             $newanswer->lessonid = $lesson->id;
             $newanswer->pageid = $newpageid;
             $newanswer->timecreated = $timenow;
         } else {
             notice(get_string("nobranchtablefound", "lesson"), "view.php?id=$cm->id");
         }
-       }
+    }
 
-/// CDC-FLAG 6/17/04 ///       
-       /************** add cluster ************************************/
+/// CDC-FLAG 6/17/04 ///
+    /************** add cluster ************************************/
     elseif ($action == 'addcluster' ) {
 
-               if (!isteacher($course->id)) {
-               error("Only teachers can look at this page");
-           }
-               
-               confirm_sesskey();
+        if (!isteacher($course->id)) {
+            error("Only teachers can look at this page");
+        }
+
+        confirm_sesskey();
 
         // first get the preceeding page
-               // if $pageid = 0, then we are inserting a new page at the beginning of the lesson
+        // if $pageid = 0, then we are inserting a new page at the beginning of the lesson
         $pageid = required_param('pageid', PARAM_INT);
-            
+
         $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");
-               }
-               }
+
+        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 = new stdClass;
-               $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 = new stdClass;
-               $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('addedcluster', 'lesson'));
-       }
-/// CDC-FLAG ///       
-
-/// CDC-FLAG 6/17/04 ///       
-       /************** add end of cluster ************************************/
+        $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 = new stdClass;
+        $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('addedcluster', 'lesson'));
+    }
+/// 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");
-           }
+        if (!isteacher($course->id)) {
+            error("Only teachers can look at this page");
+        }
 
-               confirm_sesskey();
+        confirm_sesskey();
 
         // first get the preceeding page
         $pageid = required_param('pageid', PARAM_INT);
-            
+
         $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 = new stdClass;
-               $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 = new stdClass;
-               $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('addedendofcluster', 'lesson'));
-       }
+            error("Error: Could not find page");
+        }
+
+        // could put code in here to check if the user really can insert an end of cluster
+
+        $newpage = new stdClass;
+        $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 = new stdClass;
+        $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('addedendofcluster', 'lesson'));
+    }
 /// CDC-FLAG ///
-       
-       /************** add page ************************************/
+
+    /************** add page ************************************/
     elseif ($action == 'addpage' ) {
 
-               if (!isteacher($course->id)) {
-               error("Only teachers can look at this page");
-           }
+        if (!isteacher($course->id)) {
+            error("Only teachers can look at this page");
+        }
 
         // first get the preceeding page
         $pageid = required_param('pageid', PARAM_INT);
-            
+
         // set of jump array
-               $jump = array();
+        $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, $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";
-               }
+        //// 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");
+        print_heading_with_help(get_string("addaquestionpage", "lesson"), "overview", "lesson");
         ?>
         <form name="form" method="post" action="lesson.php">
         <input type="hidden" name="id" value="<?PHP echo $cm->id ?>">
         <input type="hidden" name="action" value="insertpage">
         <input type="hidden" name="pageid" value="<?PHP echo $pageid ?>">
         <input type="hidden" name="sesskey" value="<?PHP echo $USER->sesskey ?>">
-               <center><table cellpadding=5 border=1>
-               <?php
-                   echo "<tr><td align=\"center\"><b>";
-                       echo get_string("questiontype", "lesson").":</b> \n";
-                       echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."<br>";
-                       if (isset($_GET['qtype'])) {
-                               $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
-                                       if ($qtype == LESSON_SHORTANSWER) {
-                                               echo "<br><br><b>".get_string("casesensitive", "lesson").":</b> \n";
-                                       } else {
-                                               echo "<br><br><b>".get_string("multianswer", "lesson").":</b> \n";
-                                       }
-                                       echo " <label for=\"qoption\" class=\"hidden-label\">Question Option</label><input type=\"checkbox\" id=\"qoption\" name=\"qoption\" value=\"1\"/>"; //CDC hidden label added.
-                                       helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson");
-                               }
-                       } else {
-                               lesson_qtype_menu($LESSON_QUESTION_TYPE, LESSON_MULTICHOICE, 
-                                                                 "lesson.php?id=$cm->id&action=addpage&pageid=".$pageid.$linkadd);
-                               echo "<br><br><b>".get_string("multianswer", "lesson").":</b> \n";
-                               echo " <label for=\"qoption\" class=\"hidden-label\">Question Option</label><input type=\"checkbox\" id=\"qoption\" name=\"qoption\" value=\"1\"/>"; //CDC hidden label added.
-                               helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson");
-                       }
-                       echo "</td></tr>\n";
-               ?>
+        <center><table cellpadding=5 border=1>
+        <?php
+            echo "<tr><td align=\"center\"><b>";
+            echo get_string("questiontype", "lesson").":</b> \n";
+            echo helpbutton("questiontype", get_string("questiontype", "lesson"), "lesson")."<br>";
+            if (isset($_GET['qtype'])) {
+                $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
+                    if ($qtype == LESSON_SHORTANSWER) {
+                        echo "<br><br><b>".get_string("casesensitive", "lesson").":</b> \n";
+                    } else {
+                        echo "<br><br><b>".get_string("multianswer", "lesson").":</b> \n";
+                    }
+                    echo " <label for=\"qoption\" class=\"hidden-label\">Question Option</label><input type=\"checkbox\" id=\"qoption\" name=\"qoption\" value=\"1\"/>"; //CDC hidden label added.
+                    helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson");
+                }
+            } else {
+                lesson_qtype_menu($LESSON_QUESTION_TYPE, LESSON_MULTICHOICE,
+                                  "lesson.php?id=$cm->id&action=addpage&pageid=".$pageid.$linkadd);
+                echo "<br><br><b>".get_string("multianswer", "lesson").":</b> \n";
+                echo " <label for=\"qoption\" class=\"hidden-label\">Question Option</label><input type=\"checkbox\" id=\"qoption\" name=\"qoption\" value=\"1\"/>"; //CDC hidden label added.
+                helpbutton("questionoption", get_string("questionoption", "lesson"), "lesson");
+            }
+            echo "</td></tr>\n";
+        ?>
         <tr><td align="center">
         <tr valign="top">
         <td><b><?php print_string("pagetitle", "lesson"); ?>:</b><br />
         print_textarea($usehtmleditor, 25,70, 630, 400, "contents");
         use_html_editor("contents");
         echo "</td></tr>\n";
-               if (isset($_GET['qtype'])) {
-                       switch ($_GET['qtype']) {
-                               case LESSON_TRUEFALSE :
-                                       for ($i = 0; $i < 2; $i++) {
-                                               $iplus1 = $i + 1;
-                                               echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b><br />\n";
-                                               print_textarea(false, 6, 70, 630, 300, "answer[$i]");
-                                               echo "</td></tr>\n";
-                                               echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b><br />\n";
-                                               print_textarea(false, 6, 70, 630, 300, "response[$i]");
-                                               echo "</td></tr>\n";
-                                               echo "<tr><td><B>".get_string("jump", "lesson")." $iplus1:</b> \n";
-                                               if ($i) {
-                                                       // answers 2, 3, 4... jumpto this page
-                                                       lesson_choose_from_menu($jump, "jumpto[$i]", 0, "");
-                                               } else {
-                                                       // answer 1 jumpto next page
-                                                       lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, "");
-                                               }
-                                               helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
-                                               /// CDC-FLAG ///
-                                               if($lesson->custom) {
-                                                       if ($i) {
-                                                               echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"0\" size=\"5\">";
-                                                       } else {
-                                                               echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\">";
-                                                       }
-                                               }
-                                               /// CDC-FLAG ///
-                                               echo "</td></tr>\n";
-                                       }
-                                       break;
-                               case LESSON_ESSAY :
-                                               echo "<tr><td><B>".get_string("jump", "lesson").":</b> \n";
-                                               lesson_choose_from_menu($jump, "jumpto[0]", LESSON_NEXTPAGE, "");
-                                               helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
-                                               if ($lesson->custom) {
-                                                       echo get_string("score", "lesson").": <input type=\"text\" name=\"score[0]\" value=\"1\" size=\"5\">";
-                                               }
-                                               echo "</td></tr>\n";
-                                       break;
-                               case LESSON_MATCHING :
-                                       for ($i = 0; $i < $lesson->maxanswers+2; $i++) {
-                                               $icorrected = $i - 1;
-                                               if ($i == 0) {
-                                                       echo "<tr><td><b>".get_string("correctresponse", "lesson").":</b><br />\n";
-                                                       print_textarea(false, 6, 70, 630, 300, "answer[$i]");
-                                                       echo "</td></tr>\n";
-                                               } elseif ($i == 1) {
-                                                       echo "<tr><td><b>".get_string("wrongresponse", "lesson").":</b><br />\n";
-                                                       print_textarea(false, 6, 70, 630, 300, "answer[$i]");
-                                                       echo "</td></tr>\n";
-                                               } else {                                                                                                
-                                                       echo "<tr><td><b>".get_string("answer", "lesson")." $icorrected:</b><br />\n";
-                                                       print_textarea(false, 6, 70, 630, 300, "answer[$i]");
-                                                       echo "</td></tr>\n";
-                                                       echo "<tr><td><b>".get_string("matchesanswer", "lesson")." $icorrected:</b><br />\n";
-                                                       print_textarea(false, 6, 70, 630, 300, "response[$i]");
-                                                       echo "</td></tr>\n";
-                                               }
-                                               if ($i == 2) {
-                                                       echo "<tr><td><B>".get_string("correctanswerjump", "lesson").":</b> \n";
-                                                       lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, "");
-                                                       helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
-                                                       if($lesson->custom) {
-                                                               echo get_string("correctanswerscore", "lesson").": <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\">";
-                                                       }
-                                                       echo "</td></tr>\n";
-                                               } elseif ($i == 3) {
-                                                       echo "<tr><td><B>".get_string("wronganswerjump", "lesson").":</b> \n";
-                                                       lesson_choose_from_menu($jump, "jumpto[$i]", 0, "");
-                                                       helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
-                                                       if($lesson->custom) {
-                                                               echo get_string("wronganswerscore", "lesson").": <input type=\"text\" name=\"score[$i]\" value=\"0\" size=\"5\">";
-                                                       }
-                                                       echo "</td></tr>\n";
-                                               }
-                                       }
-                                       break;
-                               case LESSON_SHORTANSWER :
-                               case LESSON_NUMERICAL :
-                               case LESSON_MULTICHOICE :
-                                       // default code
-                                       for ($i = 0; $i < $lesson->maxanswers; $i++) {
-                                               $iplus1 = $i + 1;
-                                               echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b><br />\n";
-                                               print_textarea(false, 6, 70, 630, 300, "answer[$i]");
-                                               echo "</td></tr>\n";
-                                               echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b><br />\n";
-                                               print_textarea(false, 6, 70, 630, 300, "response[$i]");
-                                               echo "</td></tr>\n";
-                                               echo "<tr><td><B>".get_string("jump", "lesson")." $iplus1:</b> \n";
-                                               if ($i) {
-                                                       // answers 2, 3, 4... jumpto this page
-                                                       lesson_choose_from_menu($jump, "jumpto[$i]", 0, "");
-                                               } else {
-                                                       // answer 1 jumpto next page
-                                                       lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, "");
-                                               }
-                                               helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
-                                               /// CDC-FLAG ///
-                                               if($lesson->custom) {
-                                                       if ($i) {
-                                                               echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"0\" size=\"5\">";
-                                                       } else {
-                                                               echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\">";
-                                                       }
-                                               }
-                                               /// CDC-FLAG ///
-                                               echo "</td></tr>\n";
-                                       }
-                                       break;
-                       }
-               } else {
-                       for ($i = 0; $i < $lesson->maxanswers; $i++) {
-                               $iplus1 = $i + 1;
-                               echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b><br />\n";
-                               print_textarea(false, 6, 70, 630, 300, "answer[$i]");
-                               echo "</td></tr>\n";
-                               echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b><br />\n";
-                               print_textarea(false, 6, 70, 630, 300, "response[$i]");
-                               echo "</td></tr>\n";
-                               echo "<tr><td><B>".get_string("jump", "lesson")." $iplus1:</b> \n";
-                               if ($i) {
-                                       // answers 2, 3, 4... jumpto this page
-                                       lesson_choose_from_menu($jump, "jumpto[$i]", 0, "");
-                               } else {
-                                       // answer 1 jumpto next page
-                                       lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, "");
-                               }
-                               helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
-                               /// CDC-FLAG ///
-                               if($lesson->custom) {
-                                       if ($i) {
-                                               echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"0\" size=\"5\">";
-                                       } else {
-                                               echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\">";
-                                       }
-                               }
-                               /// CDC-FLAG ///
-                               echo "</td></tr>\n";
-                       }
-               }
+        if (isset($_GET['qtype'])) {
+            switch ($_GET['qtype']) {
+                case LESSON_TRUEFALSE :
+                    for ($i = 0; $i < 2; $i++) {
+                        $iplus1 = $i + 1;
+                        echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b><br />\n";
+                        print_textarea(false, 6, 70, 630, 300, "answer[$i]");
+                        echo "</td></tr>\n";
+                        echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b><br />\n";
+                        print_textarea(false, 6, 70, 630, 300, "response[$i]");
+                        echo "</td></tr>\n";
+                        echo "<tr><td><B>".get_string("jump", "lesson")." $iplus1:</b> \n";
+                        if ($i) {
+                            // answers 2, 3, 4... jumpto this page
+                            lesson_choose_from_menu($jump, "jumpto[$i]", 0, "");
+                        } else {
+                            // answer 1 jumpto next page
+                            lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, "");
+                        }
+                        helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
+                        /// CDC-FLAG ///
+                        if($lesson->custom) {
+                            if ($i) {
+                                echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"0\" size=\"5\">";
+                            } else {
+                                echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\">";
+                            }
+                        }
+                        /// CDC-FLAG ///
+                        echo "</td></tr>\n";
+                    }
+                    break;
+                case LESSON_ESSAY :
+                        echo "<tr><td><B>".get_string("jump", "lesson").":</b> \n";
+                        lesson_choose_from_menu($jump, "jumpto[0]", LESSON_NEXTPAGE, "");
+                        helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
+                        if ($lesson->custom) {
+                            echo get_string("score", "lesson").": <input type=\"text\" name=\"score[0]\" value=\"1\" size=\"5\">";
+                        }
+                        echo "</td></tr>\n";
+                    break;
+                case LESSON_MATCHING :
+                    for ($i = 0; $i < $lesson->maxanswers+2; $i++) {
+                        $icorrected = $i - 1;
+                        if ($i == 0) {
+                            echo "<tr><td><b>".get_string("correctresponse", "lesson").":</b><br />\n";
+                            print_textarea(false, 6, 70, 630, 300, "answer[$i]");
+                            echo "</td></tr>\n";
+                        } elseif ($i == 1) {
+                            echo "<tr><td><b>".get_string("wrongresponse", "lesson").":</b><br />\n";
+                            print_textarea(false, 6, 70, 630, 300, "answer[$i]");
+                            echo "</td></tr>\n";
+                        } else {
+                            echo "<tr><td><b>".get_string("answer", "lesson")." $icorrected:</b><br />\n";
+                            print_textarea(false, 6, 70, 630, 300, "answer[$i]");
+                            echo "</td></tr>\n";
+                            echo "<tr><td><b>".get_string("matchesanswer", "lesson")." $icorrected:</b><br />\n";
+                            print_textarea(false, 6, 70, 630, 300, "response[$i]");
+                            echo "</td></tr>\n";
+                        }
+                        if ($i == 2) {
+                            echo "<tr><td><B>".get_string("correctanswerjump", "lesson").":</b> \n";
+                            lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, "");
+                            helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
+                            if($lesson->custom) {
+                                echo get_string("correctanswerscore", "lesson").": <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\">";
+                            }
+                            echo "</td></tr>\n";
+                        } elseif ($i == 3) {
+                            echo "<tr><td><B>".get_string("wronganswerjump", "lesson").":</b> \n";
+                            lesson_choose_from_menu($jump, "jumpto[$i]", 0, "");
+                            helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
+                            if($lesson->custom) {
+                                echo get_string("wronganswerscore", "lesson").": <input type=\"text\" name=\"score[$i]\" value=\"0\" size=\"5\">";
+                            }
+                            echo "</td></tr>\n";
+                        }
+                    }
+                    break;
+                case LESSON_SHORTANSWER :
+                case LESSON_NUMERICAL :
+                case LESSON_MULTICHOICE :
+                    // default code
+                    for ($i = 0; $i < $lesson->maxanswers; $i++) {
+                        $iplus1 = $i + 1;
+                        echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b><br />\n";
+                        print_textarea(false, 6, 70, 630, 300, "answer[$i]");
+                        echo "</td></tr>\n";
+                        echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b><br />\n";
+                        print_textarea(false, 6, 70, 630, 300, "response[$i]");
+                        echo "</td></tr>\n";
+                        echo "<tr><td><B>".get_string("jump", "lesson")." $iplus1:</b> \n";
+                        if ($i) {
+                            // answers 2, 3, 4... jumpto this page
+                            lesson_choose_from_menu($jump, "jumpto[$i]", 0, "");
+                        } else {
+                            // answer 1 jumpto next page
+                            lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, "");
+                        }
+                        helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
+                        /// CDC-FLAG ///
+                        if($lesson->custom) {
+                            if ($i) {
+                                echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"0\" size=\"5\">";
+                            } else {
+                                echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\">";
+                            }
+                        }
+                        /// CDC-FLAG ///
+                        echo "</td></tr>\n";
+                    }
+                    break;
+            }
+        } else {
+            for ($i = 0; $i < $lesson->maxanswers; $i++) {
+                $iplus1 = $i + 1;
+                echo "<tr><td><b>".get_string("answer", "lesson")." $iplus1:</b><br />\n";
+                print_textarea(false, 6, 70, 630, 300, "answer[$i]");
+                echo "</td></tr>\n";
+                echo "<tr><td><b>".get_string("response", "lesson")." $iplus1:</b><br />\n";
+                print_textarea(false, 6, 70, 630, 300, "response[$i]");
+                echo "</td></tr>\n";
+                echo "<tr><td><B>".get_string("jump", "lesson")." $iplus1:</b> \n";
+                if ($i) {
+                    // answers 2, 3, 4... jumpto this page
+                    lesson_choose_from_menu($jump, "jumpto[$i]", 0, "");
+                } else {
+                    // answer 1 jumpto next page
+                    lesson_choose_from_menu($jump, "jumpto[$i]", LESSON_NEXTPAGE, "");
+                }
+                helpbutton("jumpto", get_string("jump", "lesson"), "lesson");
+                /// CDC-FLAG ///
+                if($lesson->custom) {
+                    if ($i) {
+                        echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"0\" size=\"5\">";
+                    } else {
+                        echo get_string("score", "lesson")." $iplus1: <input type=\"text\" name=\"score[$i]\" value=\"1\" size=\"5\">";
+                    }
+                }
+                /// CDC-FLAG ///
+                echo "</td></tr>\n";
+            }
+        }
         // close table and form
         ?>
         </table><br />
         <input type="submit" name="cancel" value="<?php  print_string("cancel") ?>">
         </center>
         </form>
-        <?PHP 
-               }
-       
+        <?PHP
+        }
+
 
-       /******************* confirm delete ************************************/
+    /******************* confirm delete ************************************/
     elseif ($action == 'confirmdelete' ) {
 
-               if (!isteacher($course->id)) {
-               error("Only teachers can look at this page");
-           }
-               
-               confirm_sesskey();
+        if (!isteacher($course->id)) {
+            error("Only teachers can look at this page");
+        }
+
+        confirm_sesskey();
 
         $pageid = required_param('pageid', PARAM_INT);
         if (!$thispage = get_record("lesson_pages", "id", $pageid)) {
                 echo $title."<br />\n";
             }
         }
-               notice_yesno(get_string("confirmdeletionofthispage","lesson"), 
-                        "lesson.php?action=delete&amp;id=$cm->id&amp;pageid=$pageid&amp;sesskey=".$USER->sesskey, 
+        notice_yesno(get_string("confirmdeletionofthispage","lesson"),
+             "lesson.php?action=delete&amp;id=$cm->id&amp;pageid=$pageid&amp;sesskey=".$USER->sesskey,
              "view.php?id=$cm->id");
-               }
-       
-
-       /****************** continue ************************************/
-       elseif ($action == 'continue' ) {
-
-               confirm_sesskey();
-
-               // left menu code
-               if ($lesson->displayleft) {
-                  if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) {
-                               echo '<table><tr valign="top"><td>';
-                               // print the pages
-                               echo "<form name=\"lessonpages2\" method=\"post\" action=\"view.php\">\n";
-                               echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">\n";
-                               echo "<input type=\"hidden\" name=\"action\" value=\"navigation\">\n";
-                               echo "<input type=\"hidden\" name=\"pageid\">\n";
-                                               echo "<table class=\"lessonside\" width=\"140px\">";
-                                               echo "<tr><td>".get_string("lessonmenu", "lesson")."</td></tr>";
-                                               echo '<tr><td class="lessonmain">';
-                                               echo "<a href=\"../../course/view.php?id=$course->id\">".get_string("mainmenu", "lesson")."</a></td></tr>";
-                                               echo "<td class=\"leftmenu\">"; 
-                                               lesson_print_tree_menu($lesson->id, $firstpageid, $cm->id);
-                                               echo "</td></tr></table>"; 
-                               echo "</form>";
-                               echo '</td><td align="center" width="100%">';
-                       }
-               }
-               
-               /// 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 "<p align=\"center\">".get_string("teacherjumpwarning", "lesson", $warningvars)."</p>";
-                       }
-               }               
-               /// 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 "<p align=\"center\">".get_string("teachertimerwarning", "lesson")."</p>";
-                       } 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
-                                               print_simple_box_start("right", "150px", "#ffffff", 0);
+        }
+
+
+    /****************** continue ************************************/
+    elseif ($action == 'continue' ) {
+
+        confirm_sesskey();
+
+        // left menu code
+        if ($lesson->displayleft) {
+           if($firstpageid = get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) {
+                echo '<table><tr valign="top"><td>';
+                // print the pages
+                echo "<form name=\"lessonpages2\" method=\"post\" action=\"view.php\">\n";
+                echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\">\n";
+                echo "<input type=\"hidden\" name=\"action\" value=\"navigation\">\n";
+                echo "<input type=\"hidden\" name=\"pageid\">\n";
+                        echo "<table class=\"lessonside\" width=\"140px\">";
+                        echo "<tr><td>".get_string("lessonmenu", "lesson")."</td></tr>";
+                        echo '<tr><td class="lessonmain">';
+                        echo "<a href=\"../../course/view.php?id=$course->id\">".get_string("mainmenu", "lesson")."</a></td></tr>";
+                        echo "<td class=\"leftmenu\">";
+                        lesson_print_tree_menu($lesson->id, $firstpageid, $cm->id);
+                        echo "</td></tr></table>";
+                echo "</form>";
+                echo '</td><td align="center" width="100%">';
+            }
+        }
+
+        /// 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 "<p align=\"center\">".get_string("teacherjumpwarning", "lesson", $warningvars)."</p>";
+            }
+        }
+        /// 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 "<p align=\"center\">".get_string("teachertimerwarning", "lesson")."</p>";
+            } 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
+                        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\">";
+                            "<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 "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 ((($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>";
-                                       $outoftime = true;
-                               }
-                               $newtime = new stdClass;
-                               $newtime->id = $timer->id;
-                               $newtime->lessontime = time();
-                               
-                               if (!update_record("lesson_timer", $newtime)) {
-                                       error("Error: could not update lesson_timer table");
-                               }
-                       }
-               }
-               /// CDC-FLAG ///                        
+                        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 ((($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>";
+                    $outoftime = true;
+                }
+                $newtime = new stdClass;
+                $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");
-               }
+            error("Continue: pageid missing");
+        }
         $pageid = required_param('pageid', PARAM_INT);
         if (!$page = get_record("lesson_pages", "id", $pageid)) {
             error("Continue: Page record not found");
         $correctanswer = false;
         $newpageid = 0; // stay on the page
         switch ($page->qtype) {
-                       /// CDC-FLAG ///
-                        case LESSON_ESSAY :
+            /// CDC-FLAG ///
+             case LESSON_ESSAY :
                 if (!$useranswer = $_POST['answer']) {
                     $noanswer = true;
                     break;
                 }
-                               $useranswer = clean_param($useranswer, PARAM_CLEAN);
-                               
-                   if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) {
+                $useranswer = clean_param($useranswer, PARAM_CLEAN);
+
+                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 //
-                               $userresponse->sent=0;
-                               $userresponse->graded = 0;
-                               $userresponse->score = 0;
-                               $userresponse->answer = $useranswer;
-                               $userresponse->response = "";
-                               $userresponse = addslashes(serialize($userresponse));
-                               
-                               break;
-                       /// CDC-FLAG ///
-                    case LESSON_SHORTANSWER :
+                $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 //
+                $userresponse->sent=0;
+                $userresponse->graded = 0;
+                $userresponse->score = 0;
+                $userresponse->answer = $useranswer;
+                $userresponse->response = "";
+                $userresponse = addslashes(serialize($userresponse));
+
+                break;
+            /// CDC-FLAG ///
+             case LESSON_SHORTANSWER :
                 if (!$useranswer = $_POST['answer']) {
                     $noanswer = true;
                     break;
                 }
-                               $useranswer = clean_param($useranswer, PARAM_CLEAN);
-                               $userresponse = addslashes($useranswer);
-                               
+                $useranswer = clean_param($useranswer, PARAM_CLEAN);
+                $userresponse = addslashes($useranswer);
+
                 if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) {
                     error("Continue: No answers found");
                 }
                 foreach ($answers as $answer) {
-                                       /// CDC-FLAG ///
-                                       if ($lesson->custom && $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) && !$lesson->custom) {  /// CDC-FLAG 6/21/04 ///
+                    /// CDC-FLAG ///
+                    if ($lesson->custom && $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) && !$lesson->custom) {  /// CDC-FLAG 6/21/04 ///
                         if ($page->qoption) {
                             // case sensitive
                             if ($answer->answer == $useranswer) {
                         // don't worry about case
                         if (strcasecmp($answer->answer, $useranswer) == 0) {
                             $newpageid = $answer->jumpto;
-                                                       $answerid = $answer->id;
+                            $answerid = $answer->id;
                             if (trim(strip_tags($answer->response))) {
                                 $response = $answer->response;
                             }
                     }
                 }
                 break;
-                
+
             case LESSON_TRUEFALSE :
                 if (empty($_POST['answerid'])) {
                     $noanswer = true;
                     break;
                 }
-                $answerid = required_param('answerid', PARAM_INT); 
+                $answerid = required_param('answerid', PARAM_INT);
                 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 6/21/04 ///
+                }
+                /* 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) {
                     }
                 }
                 break;
-                
+
             case LESSON_MULTICHOICE :
                 if ($page->qoption) {
                     // MULTIANSWER allowed, user's answer is an array
                         $noanswer = true;
                         break;
                     }
-                                       // get what the user answered
-                                       $userresponse = implode(",", $useranswers);
+                    // get what the user answered
+                    $userresponse = implode(",", $useranswers);
                     // get the answers in a set order, the id order
                     if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) {
                         error("Continue: No answers found");
                     $nhits = 0;
                     $correctresponse = '';
                     $wrongresponse = '';
-                                       /// 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 ///
+                    /// 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) {
                         $noanswer = true;
                         break;
                     }
-                                       $answerid = required_param('answerid', PARAM_INT); 
+                    $answerid = required_param('answerid', PARAM_INT);
                     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 ///
+                    }
+                    /* CDC-FLAG */
+                    if ($lesson->custom) {
+                        if ($answer->score > 0) {
+                            $correctanswer = true;
+                        } else {
+                            $correctanswer = false;
+                        }
+                    }
+                    /// CDC-FLAG ///
                     $newpageid = $answer->jumpto;
                     if (!$response = trim($answer->response)) {
                         if ($correctanswer) {
                     }
                 }
                 break;
-                
-            /// CDC-FLAG /// 6/14/04  -- added responses    
+
+            /// CDC-FLAG /// 6/14/04  -- added responses
             case LESSON_MATCHING :
                 if (isset($_POST['response']) && is_array($_POST['response'])) { // only arrays should be submitted
                     $response = $_POST['response'];
                 $ncorrect = 0;
                 $i = 0;
                 foreach ($answers as $answer) {
-                                       if ($i == 0 || $i == 1) {
-                                               // ignore first two answers, they are correct response
-                                               // and wrong response
-                                               $i++;
-                                               continue;
-                                       }
+                    if ($i == 0 || $i == 1) {
+                        // ignore first two answers, they are correct response
+                        // and wrong response
+                        $i++;
+                        continue;
+                    }
                     if ($answer->response == $response[$answer->id]) {
                         $ncorrect++;
                     }
                     if ($i == 2) {
                         $correctpageid = $answer->jumpto;
-                                               $correctanswerid = $answer->id;
+                        $correctanswerid = $answer->id;
                     }
                     if ($i == 3) {
                         $wrongpageid = $answer->jumpto;
-                                               $wronganswerid = $answer->id;                                           
+                        $wronganswerid = $answer->id;
                     }
                     $i++;
                 }
-                               // get he users exact responses for record keeping
-                               foreach ($response as $value) {
-                                       foreach($answers as $answer) {
-                                               if ($value == $answer->response) {
-                                                       $userresponse[] = $answer->id;
-                                               }
-                                       }
-                               }
-                               $userresponse = implode(",", $userresponse);
+                // get he users exact responses for record keeping
+                foreach ($response as $value) {
+                    foreach($answers as $answer) {
+                        if ($value == $answer->response) {
+                            $userresponse[] = $answer->id;
+                        }
+                    }
+                }
+                $userresponse = implode(",", $userresponse);
 
                 if ($ncorrect == count($answers)-2) {  // dont count correct/wrong responses in the total.
-                       $response = get_string("thatsthecorrectanswer", "lesson");
-                                       foreach ($answers as $answer) {
-                                               if ($answer->response == NULL && $answer->answer != NULL) {
-                                   $response = $answer->answer;
-                                                       break;
-                                               }
-                                       }
-                                       // NoticeFix
+                    $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($correctanswerid)) {
-                                               $answerid = $correctanswerid;
-                                       }
+                        $newpageid = $correctpageid;
+                    }
+                    if (isset($correctanswerid)) {
+                        $answerid = $correctanswerid;
+                    }
                     $correctanswer = true;
                 } else {
-                       $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++;
-                                               }
-                                       }
+                    $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;
+                    $answerid = $wronganswerid;
                 }
                 break;
-                               /// CDC-FLAG ///
+                /// CDC-FLAG ///
 
             case LESSON_NUMERICAL :
                 // set defaults
                 $newpageid = 0;
 
                 if (isset($_POST['answer'])) {
-                                       $useranswer = (float) optional_param('answer');  // just doing default PARAM_CLEAN, not doing PARAM_INT because it could be a float
-                               } else {
+                    $useranswer = (float) optional_param('answer');  // just doing default PARAM_CLEAN, not doing PARAM_INT because it could be a float
+                } else {
                     $noanswer = true;
                     break;
-                               }
-                               $userresponse = $useranswer;
+                }
+                $userresponse = $useranswer;
                 if (!$answers = get_records("lesson_answers", "pageid", $pageid, "id")) {
                     error("Continue: No answers found");
                 }
                         if (lesson_iscorrect($pageid, $newpageid)) {
                             $correctanswer = true;
                         }
-                                               /// CDC-FLAG ///
-                                               if ($lesson->custom) {
-                                                       if ($answer->score > 0) {
-                                                               $correctanswer = true;
-                                                               $answerid = $answer->id;
-                                                       } else {
-                                                               $correctanswer = false;
-                                                       }
-                                               }
-                                               /// CDC-FLAG ///
+                        /// CDC-FLAG ///
+                        if ($lesson->custom) {
+                            if ($answer->score > 0) {
+                                $correctanswer = true;
+                                $answerid = $answer->id;
+                            } else {
+                                $correctanswer = false;
+                            }
+                        }
+                        /// CDC-FLAG ///
                         break;
                     }
                 }
                     if (!$response) {
                         $response = get_string("thatsthewronganswer", "lesson");
                     }
-                }           
+                }
                 break;
 
             case LESSON_BRANCHTABLE:
                 $noanswer = false;
                 $newpageid = optional_param('jumpto', NULL, PARAM_INT);
-                               /// 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;