]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-6477: Added roles support.
authormark-nielsen <mark-nielsen>
Fri, 8 Sep 2006 23:17:18 +0000 (23:17 +0000)
committermark-nielsen <mark-nielsen>
Fri, 8 Sep 2006 23:17:18 +0000 (23:17 +0000)
Also added lesson_set_message() and lesson_print_message() to locallib.php
Also fixed problem in continue.html with not printing nextpageid

14 files changed:
mod/lesson/action/continue.html
mod/lesson/action/continue.php
mod/lesson/db/access.php [new file with mode: 0644]
mod/lesson/import.php
mod/lesson/importppt.php
mod/lesson/index.php
mod/lesson/lesson.php
mod/lesson/locallib.php
mod/lesson/mediafile.php
mod/lesson/report.php
mod/lesson/styles.php
mod/lesson/tabs.php
mod/lesson/version.php
mod/lesson/view.php

index e503a4ee391e8156ad47bc230c8f157c42a58692..0a3f50a62c4f902637d2566be84a2349d8ec746c 100644 (file)
@@ -32,7 +32,7 @@ if ($lesson->displayleft) {
 } // End if ($lesson->displayleft)
 ?>
 
-<?php if($lesson->timed and !isteacher($course->id)) {
+<?php if($lesson->timed and !has_capability('mod/lesson:manage', $context)) {
         // code for the clock
         print_simple_box_start("right", "150px", "#ffffff", 0);
 ?>
@@ -69,7 +69,7 @@ if ($lesson->ongoing) {
 <form name="pageform" method ="post" action="view.php">
 <input type="hidden" name="id" value="<?php echo $cm->id ?>" />
 <input type="hidden" name="action" value="navigation" />
-<input type="hidden" name="pageid" value="<?php $newpageid ?>" />
+<input type="hidden" name="pageid" value="<?php echo $newpageid ?>" />
 
 <?php if (isset($USER->modattempts[$lesson->id])) { ?>
 <p align="center"><?php print_string("savechangesandeol", "lesson") ?> <br /><br />
index 7517373fb87e7131afd65409795b404ea2b303f0..1ae0b1c2ee7f63126c58511ef36d4e2283106cfe 100644 (file)
@@ -8,12 +8,12 @@
 
     // left menu code
     // check to see if the user can see the left menu
-    if (!isteacher($course->id)) {
+    if (!has_capability('mod/lesson:manage', $context)) {
         $lesson->displayleft = lesson_displayleftif($lesson);
     }
     
     // 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) and lesson_display_teacher_warning($lesson->id)) {
+    if(has_capability('mod/lesson:manage', $context) and lesson_display_teacher_warning($lesson->id)) {
         $warningvars->cluster = get_string("clusterjump", "lesson");
         $warningvars->unseen = get_string("unseenpageinbranch", "lesson");
         $messages[] = get_string("teacherjumpwarning", "lesson", $warningvars);
@@ -22,7 +22,7 @@
     // This is the code updates the lesson time for a timed test
     // get time information for this user
     $outoftime = false;
-    if (!isteacher($course->id)) {
+    if (!has_capability('mod/lesson:manage', $context)) {
         if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) {
             error('Error: could not find records');
         } else {
@@ -49,7 +49,7 @@
     }
     
     // Inform teacher that s/he will not see the timer
-    if ($lesson->timed and isteacher($course->id)) {
+    if ($lesson->timed and has_capability('mod/lesson:manage', $context)) {
         $messages[] = get_string("teachertimerwarning", "lesson");
     }
 
 
             //  this is called when jumping to random from a branch table
             if($newpageid == LESSON_UNSEENBRANCHPAGE) {
-                if (isteacher($course->id)) {
+                if (has_capability('mod/lesson:manage', $context)) {
                      $newpageid = LESSON_NEXTPAGE;
                 } else {
                      $newpageid = lesson_unseen_question_jump($lesson->id, $USER->id, $pageid);  // this may return 0
         $newpageid = $pageid; // display same page again
     } else {
         $nretakes = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id); 
-        if (isstudent($course->id)) {
+        if (!has_capability('mod/lesson:manage', $context)) {
             // record student's attempt
             $attempt = new stdClass;
             $attempt->lessonid = $lesson->id;
             }
         }
     } elseif ($newpageid == LESSON_UNSEENBRANCHPAGE) {
-        if (isteacher($course->id)) {
+        if (has_capability('mod/lesson:manage', $context)) {
             if ($page->nextpageid == 0) {
                 $newpageid = LESSON_EOL;
             } else {
     } elseif ($newpageid == LESSON_RANDOMPAGE) {
         $newpageid = lesson_random_question_jump($lesson->id, $pageid);
     } elseif ($newpageid == LESSON_CLUSTERJUMP) {
-        if (isteacher($course->id)) {
+        if (has_capability('mod/lesson:manage', $context)) {
             if ($page->nextpageid == 0) {  // if teacher, go to next page
                 $newpageid = LESSON_EOL;
             } else {
     }
     
     lesson_print_header($cm, $course, $lesson, 'navigation', false);
-    
+
     include($CFG->wwwroot.'/mod/lesson/action/continue.html');
 ?>
diff --git a/mod/lesson/db/access.php b/mod/lesson/db/access.php
new file mode 100644 (file)
index 0000000..2f0f1e1
--- /dev/null
@@ -0,0 +1,50 @@
+<?php // $Id$
+/**
+ * Capability definitions for the lesson module.
+ * 
+ * For naming conventions, see lib/db/access.php.
+ */
+$mod_lesson_capabilities = array(
+
+    'mod/lesson:view' => array(
+    
+        'captype' => 'read',
+        'contextlevel' => CONTEXT_MODULE,
+        'legacy' => array(
+            'guest' => CAP_PREVENT,
+            'student' => CAP_ALLOW,
+            'teacher' => CAP_ALLOW,
+            'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
+    ),
+
+    'mod/lesson:edit' => array(
+    
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_MODULE,
+        'legacy' => array(
+            'guest' => CAP_PREVENT,
+            'student' => CAP_PREVENT,
+            'teacher' => CAP_PREVENT,
+            'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
+    ),
+
+    'mod/lesson:manage' => array(
+    
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_MODULE,
+        'legacy' => array(
+            'guest' => CAP_PREVENT,
+            'student' => CAP_PREVENT,
+            'teacher' => CAP_ALLOW,
+            'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
+    )
+);
index c78f32ed137a55b3a0855d37a71697753d844e27..a5fd6e812c277902fae6009aeaccc935651a5037 100644 (file)
 
 
     require_login($course->id, false);
-
-    if (!isteacher($course->id)) {
-        error("Only the teacher can import questions!");
-    }
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+    require_capability('mod/lesson:edit', $context);
 
     $strimportquestions = get_string("importquestions", "lesson");
     $strlessons = get_string("modulenameplural", "lesson");
index f13b083a30544108b1ccb6813ef0e567e23d4324..758b83c73019bdb89b25f911bff9b7188300aa15 100644 (file)
     }
 
     require_login($course->id, false);
-
-    if (!isteacher($course->id)) {
-        error("Only the teacher can import questions!");
-    }
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+    require_capability('mod/lesson:edit', $context);
 
     $strimportppt = get_string("importppt", "lesson");
     $strlessons = get_string("modulenameplural", "lesson");
index 6e538115c475e28f898b0635b634414ff5efe98c..e354cc52979d8625a613fcc04a85af56756dc599 100644 (file)
@@ -68,6 +68,8 @@
             //Show normal if the mod is visible
             $link = "<a href=\"view.php?id=$lesson->coursemodule\">".format_string($lesson->name,true)."</a>";
         }
+        $cm = get_coursemodule_from_instance('lesson', $lesson->id);
+        $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
         if ($lesson->deadline > $timenow) {
             $due = userdate($lesson->deadline);
@@ -76,7 +78,7 @@
         }
 
         if ($course->format == "weeks" or $course->format == "topics") {
-            if (isteacher($course->id)) {
+            if (has_capability('mod/lesson:manage', $context)) {
                 $grade_value = $lesson->grade;
             } else {
                 // it's a student, show their mean or maximum grade
index a930ef46bcad3e2bc12731c9fb958db90cb6434d..08cb72eb91f4e3ae031eb9d40dab2c81441f9d52 100644 (file)
@@ -28,6 +28,7 @@
     list($cm, $course, $lesson) = lesson_get_basics($id);
 
     require_login($course->id);
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     
 /// Set up some general variables
     $usehtmleditor = can_use_html_editor();
@@ -47,9 +48,7 @@
         case 'insertpage':
         case 'updatepage':
         case 'moveit':
-            if (!isteacheredit($course->id)) {
-                error('You must be a teacher with editing privileges to access this page.');
-            }
+            require_capability('mod/lesson:edit', $context);
         case 'continue':
             include($CFG->dirroot.'/mod/lesson/action/'.$action.'.php');
             break;
index 5e4f1e4a54ac69103f0b0e0ae717e20febae285e..380170e3d139dbadff699f4a88b39383af2cecdb 100644 (file)
@@ -219,6 +219,7 @@ if (!defined("LESSON_RESPONSE_EDITOR")) {
  **/
 function lesson_print_header($cm, $course, $lesson, $currenttab = '', $printheading = true) {
     global $CFG, $USER;
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     
 /// Header setup
     if ($course->category) {
@@ -241,7 +242,7 @@ function lesson_print_header($cm, $course, $lesson, $currenttab = '', $printhead
         print_heading_with_help(format_string($lesson->name, true), "overview", "lesson");
     }
     
-    if (!empty($currenttab) and isteacher($course->id)) {
+    if (!empty($currenttab) and has_capability('mod/lesson:manage', $context)) {
         include($CFG->dirroot.'/mod/lesson/tabs.php');
     }
 }
@@ -282,6 +283,56 @@ function lesson_get_basics($cmid = 0, $lessonid = 0) {
     return array($cm, $course, $lesson);
 }
 
+/**
+ * Sets a message to be printed.  Messages are printed
+ * by calling {@link lesson_print_messages()}.
+ *
+ * @uses $SESSION
+ * @param string $message The message to be printed
+ * @param string $class Class to be passed to {@link notify()}.  Usually notifyproblem or notifysuccess.
+ * @param string $align Alignment of the message
+ * @return boolean
+ **/
+function lesson_set_message($message, $class="notifyproblem", $align='center') {
+    global $SESSION;
+    
+    if (empty($SESSION->lesson_messages) or !is_array($SESSION->lesson_messages)) {
+        $SESSION->lesson_messages = array();
+    }
+    
+    $SESSION->lesson_messages[] = array($message, $class, $align);
+    
+    return true;
+}
+
+/**
+ * Print all set messages.
+ *
+ * See {@link lesson_set_message()} for setting messages.
+ *
+ * Uses {@link notify()} to print the messages.
+ *
+ * @uses $SESSION
+ * @return boolean
+ **/
+function lesson_print_messages() {
+    global $SESSION;
+    
+    if (empty($SESSION->lesson_messages)) {
+        // No messages to print
+        return true;
+    }
+    
+    foreach($SESSION->lesson_messages as $message) {
+        notify($message[0], $message[1], $message[2]);
+    }
+    
+    // Reset
+    unset($SESSION->lesson_messages);
+    
+    return true;
+}
+
 /**
  * Given some question info and some data about the the answers
  * this function parses, organises and saves the question
@@ -1217,6 +1268,7 @@ function lesson_print_tree_link_menu($page, $id, $showpages=false) {
  */
 function lesson_print_tree($pageid, $lesson, $cmid) {
     global $USER, $CFG;
+    $context = get_context_instance(CONTEXT_MODULE, $cmid);
 
     if(!$pages = get_records_select("lesson_pages", "lessonid = $lesson->id")) {
         error("Error: could not find lesson pages");
@@ -1260,7 +1312,7 @@ function lesson_print_tree($pageid, $lesson, $cmid) {
         }
         
         echo $output;        
-        if (isteacheredit($lesson->course)) {
+        if (has_capability('mod/lesson:edit', $context)) {
           if (count($pages) > 1) {
               echo "<a title=\"move\" href=\"lesson.php?id=$cmid&action=move&pageid=".$pages[$pageid]->id."\">\n".
                   "<img src=\"$CFG->pixpath/t/move.gif\" hspace=\"2\" height=11 width=11 alt=\"move\" border=0></a>\n";
@@ -1409,8 +1461,10 @@ function lesson_grade($lesson, $ntries, $userid = 0) {
  **/
 function lesson_print_ongoing_score($lesson) {
     global $USER;
-    
-    if (isteacher($lesson->course)) {
+    $cm = get_coursemodule_from_instance('lesson', $lesson->id);
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+    if (has_capability('mod/lesson:manage', $context)) {
         echo "<p align=\"center\">".get_string('teacherongoingwarning', 'lesson').'</p>';
     } else {
         $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id);
@@ -1489,14 +1543,16 @@ function lesson_check_nickname($name) {
  **/
 function lesson_print_progress_bar($lesson, $course) {
     global $CFG, $USER;
-    
+    $cm = get_coursemodule_from_instance('lesson', $lesson->id);
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+
     // lesson setting to turn progress bar on or off
     if (!$lesson->progressbar) {
         return false;
     }
     
     // catch teachers
-    if (isteacher($course->id)) {
+    if (has_capability('mod/lesson:manage', $context)) {
         notify(get_string('progressbarteacherwarning', 'lesson', $course->teachers));
         return false;
     }
index 4d5dec9971bedb4b1f9f46fbb91b0ccdadadfa50..084424b2a4e6ccee1a54cb31948d071931e30b4f 100644 (file)
@@ -34,6 +34,8 @@
     }
 
     require_login($course->id, false, $cm);
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+    require_capability('mod/lesson:view', $context);
     
     // get the mimetype
     //$path_parts = pathinfo('http://www.apple.com');  //$lesson->mediafile
index 845140c062304207a8e9a8b6f4e5e2d4cf163c50..fe7fa07d51c5ec900b61190bc2be0d7909a56488 100644 (file)
     
 // make sure people are where they should be
     require_login($course->id, false);
-
-    if (!isteacher($course->id)) {
-        error("Must be teacher to view Reports");
-    }
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+    require_capability('mod/lesson:manage', $context);
 
 /// Process any form data before fetching attempts, grades and times
-    if ($form = data_submitted()) {
+    if (has_capability('mod/lesson:edit', $context) and $form = data_submitted()) {
         confirm_sesskey();
                 
     /// Cycle through array of userids with nested arrays of tries
                 $studentname = "{$student->lastname},&nbsp;$student->firstname";
                 foreach ($tries as $try) {
                 // start to build up the checkbox and link
-                    $temp = '<input type="checkbox" id="attempts" name="attempts['.$try['userid'].']['.$try['try'].']" /> '.
-                            "<a href=\"report.php?id=$cm->id&amp;action=detail&amp;userid=".$try['userid'].'&amp;try='.$try['try'].'">';
+                    if (has_capability('mod/lesson:edit', $context)) {
+                        $temp = '<input type="checkbox" id="attempts" name="attempts['.$try['userid'].']['.$try['try'].']" /> ';
+                    } else {
+                        $temp = '';
+                    }
+                    
+                    $temp .= "<a href=\"report.php?id=$cm->id&amp;action=detail&amp;userid=".$try['userid'].'&amp;try='.$try['try'].'">';
                     if ($try["grade"] !== NULL) { // if NULL then not done yet
                         // this is what the link does when the user has completed the try
                         $timetotake = $try["timeend"] - $try["timestart"];
             }
         }
         // print it all out !
-        echo  "<form id=\"theform\" name=\"theform\" method=\"post\" action=\"report.php\">\n
-               <input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />\n
-               <input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n
-               <input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
-        
+        if (has_capability('mod/lesson:edit', $context)) {
+            echo  "<form id=\"theform\" name=\"theform\" method=\"post\" action=\"report.php\">\n
+                   <input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />\n
+                   <input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n
+                   <input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n";
+        }
         print_table($table);
         
-        echo '<br /><table width="90%" align="center"><tr><td>'.
-             '<a href="javascript: checkall();">'.get_string('selectall').'</a> / '.
-             '<a href="javascript: checknone();">'.get_string('deselectall').'</a> ';
+        if (has_capability('mod/lesson:edit', $context)) {
+            echo '<br /><table width="90%" align="center"><tr><td>'.
+                 '<a href="javascript: checkall();">'.get_string('selectall').'</a> / '.
+                 '<a href="javascript: checknone();">'.get_string('deselectall').'</a> ';
              
-        $options = array();
-        $options['delete'] = get_string('deleteselected');
-        choose_from_menu($options, 'attemptaction', 0, 'choose', 'submitFormById(\'theform\')');
+            $options = array();
+            $options['delete'] = get_string('deleteselected');
+            choose_from_menu($options, 'attemptaction', 0, 'choose', 'submitFormById(\'theform\')');
+        
+            echo '</td></tr></table></form>';
+        }
         
-        echo '</td></tr></table></form>';
-
         // some stat calculations
         if ($numofattempts == 0) {
             $avescore = get_string("notcompleted", "lesson");
index 7f62f4b1e9706d274dabd3fa2a1e36cd160d848d..55de0e5a72a7963c354e4890a7c0311ca372c2f3 100644 (file)
@@ -6,6 +6,22 @@
     text-align: left;
 }
 
+/***
+ *** Style for essay.php
+ ***/
+
+#mod-lesson-essay .graded {
+    color:#DF041E;
+}
+
+#mod-lesson-essay .sent {
+    color:#006600;
+}
+
+#mod-lesson-essay .ungraded {
+    color:#999999;
+}
+
 /***
  *** Style for responses
  ***/
index d00c72113a08c5e0ea7b560d3a1068c5122c5581..8a456bb76ce4461127800ef6062f3c0f706ac089 100644 (file)
@@ -19,6 +19,7 @@
     }
     if (!isset($cm)) {
         $cm = get_coursemodule_from_instance('lesson', $lesson->id);
+        $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     }
     if (!isset($course)) {
         $course = get_record('course', 'id', $lesson->course);
     $counts->attempts = count_records('lesson_grades', 'lessonid', $lesson->id);
     $counts->student  = $course->student;
 
+
     $row[] = new tabobject('teacherview', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id", get_string('edit'), get_string('editlesson', 'lesson', format_string($lesson->name)));
     $row[] = new tabobject('navigation', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&amp;action=navigation", get_string('preview', 'lesson'), get_string('previewlesson', 'lesson', format_string($lesson->name)));
     $row[] = new tabobject('reports', "$CFG->wwwroot/mod/lesson/report.php?id=$cm->id", get_string('reports', 'lesson'), get_string('viewreports', 'lesson', $counts));
-    if (isteacheredit($course->id)) {
-        $row[] = new tabobject('essayview', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&amp;action=essayview", get_string('manualgrading', 'lesson')); 
+    if (has_capability('mod/lesson:edit', $context)) {
+        $row[] = new tabobject('essayview', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&amp;action=essayview", get_string('manualgrading', 'lesson'));
     }
     if ($lesson->highscores) {
         $row[] = new tabobject('highscores', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&amp;action=highscores", get_string('highscores', 'lesson'));
index a03a8c1b37939d2845da4d82af47412814411102..d5ace47412faf926dec7253b946f83e9c1a96eca 100644 (file)
@@ -5,7 +5,7 @@
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2006080900;  // The current module version (Date: YYYYMMDDXX)
+$module->version  = 2006090700;  // The current module version (Date: YYYYMMDDXX)
 $module->requires = 2006080900;  // Requires this Moodle version
 $module->cron     = 0;           // Period for cron to check this module (secs)
 
index 5da2ef78996da09d58c29b363923e416e8908f57..d2306150ca62fd58a9f95e38348568d95f7a365d 100644 (file)
     }
 
     require_login($course->id, false, $cm);
+    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+    
+    switch ($action) {
+        case 'essayview':
+        case 'essaygrade':
+        case 'updategrade':
+        case 'emailessay':
+            require_capability('mod/lesson:edit', $context);
+            break;
+        default:
+            require_capability('mod/lesson:view', $context);
+            break;
+    }
 
 /// Print the page header
 
@@ -41,7 +54,7 @@
     
     // moved the action up because I needed to know what the action will be before the header is printed
     if (empty($action)) {
-        if (isteacher($course->id)) {
+        if (has_capability('mod/lesson:manage', $context)) {
             $action = 'teacherview';
         } elseif  (time() < $lesson->available) {
             print_header($course->shortname .': '. format_string($lesson->name), $course->fullname,
@@ -76,7 +89,7 @@
     } 
 
     // changed the update_module_button and added another button when a teacher is checking the navigation of the lesson
-    if (isteacheredit($course->id)) {
+    if (has_capability('mod/lesson:edit', $context)) {
         $button = '<table><tr><td>';
         $button .= '<form target="'. $CFG->framename .'" method="get" action="'. $CFG->wwwroot .'/course/mod.php">'.
                '<input type="hidden" name="sesskey" value="'. $USER->sesskey .'" />'.
                  $button, // took out update_module_button($cm->id, $course->id, $strlesson) and replaced it with $button
                   navmenu($course, $cm));
 
-    if (isteacher($course->id)) {
+    if (has_capability('mod/lesson:manage', $context)) {
         
         if ($action == 'teacherview' and $display) {
             // teacherview tab not selected when displaying a single page/question
     /************** navigation **************************************/
     if ($action == 'navigation') {
         // password protected lesson code
-        if ($lesson->usepassword && !isteacher($course->id)) {
+        if ($lesson->usepassword && !has_capability('mod/lesson:manage', $context)) {
             $correctpass = false;
             if ($password = optional_param('userpassword', '', PARAM_CLEAN)) {
                 if ($lesson->password == md5(trim($password))) {
         if (empty($pageid)) {
             // make sure there are pages to view
             if (!get_field('lesson_pages', 'id', 'lessonid', $lesson->id, 'prevpageid', 0)) {
-                if (isstudent($course->id)) {
+                if (!has_capability('mod/lesson:manage', $context)) {
                     notify(get_string('lessonnotready', 'lesson', $course->teacher)); // a nice message to the student
                 } else {
                     if (!count_records('lesson_pages', 'lessonid', $lesson->id)) {
             }
             
             // check for dependencies
-            if ($lesson->dependency and !isteacher($course->id)) {
+            if ($lesson->dependency and !has_capability('mod/lesson:manage', $context)) {
                 if ($dependentlesson = get_record('lesson', 'id', $lesson->dependency)) {
                     // lesson exists, so we can proceed            
                     $conditions = unserialize($lesson->conditions);
                     error('Navigation: first page not found');
             }
             /// This is the code for starting a timed test
-            if(!isset($USER->startlesson[$lesson->id]) && !isteacher($course->id)) {
+            if(!isset($USER->startlesson[$lesson->id]) && !has_capability('mod/lesson:manage', $context)) {
                 $USER->startlesson[$lesson->id] = true;
                 $startlesson = new stdClass;
                 $startlesson->lessonid = $lesson->id;
             }
 
             if ($page->qtype == LESSON_CLUSTER) {  //this only gets called when a user starts up a new lesson and the first page is a cluster page
-                if (!isteacher($course->id)) {
+                if (!has_capability('mod/lesson:manage', $context)) {
                     // get new id
                     $pageid = lesson_cluster_jump($lesson->id, $USER->id, $pageid);
                     // get new page info
             
             
             // check to see if the user can see the left menu
-            if (!isteacher($course->id)) {
+            if (!has_capability('mod/lesson:manage', $context)) {
                 $lesson->displayleft = lesson_displayleftif($lesson);
             }
             
             }
             // clock code
             // get time information for this user
-            if(!isteacher($course->id)) {
+            if(!has_capability('mod/lesson:manage', $context)) {
                 if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) {
                     error('Error: could not find records');
                 } else {
                 
             // for timed lessons, display clock
             if ($lesson->timed) {
-                if(isteacher($course->id)) {
+                if(has_capability('mod/lesson:manage', $context)) {
                     echo '<p align="center">'. get_string('teachertimerwarning', 'lesson') .'<p>';
                 } else {
                     if ((($timer->starttime + $lesson->maxtime * 60) - time()) > 0) {
             }
 
             // update the clock
-            if (!isteacher($course->id)) {
+            if (!has_capability('mod/lesson:manage', $context)) {
                 $timer->lessontime = time();
                 if (!update_record('lesson_timer', $timer)) {
                     error('Error: could not update lesson_timer table');
                         if ($answer->jumpto == LESSON_RANDOMBRANCH) {
                             $answer->jumpto = lesson_unseen_branch_jump($lesson->id, $USER->id);
                         } elseif ($answer->jumpto == LESSON_CLUSTERJUMP) {
-                            if (!isteacher($course->id)) {
+                            if (!has_capability('mod/lesson:manage', $context)) {
                                 $answer->jumpto = lesson_cluster_jump($lesson->id, $USER->id, $pageid);
                             } else {
                                 if ($page->nextpageid == 0) {  
             }
                         
              ///  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(has_capability('mod/lesson:manage', $context)) {
                 if (lesson_display_teacher_warning($lesson->id)) {
                     $warningvars->cluster = get_string('clusterjump', 'lesson');
                     $warningvars->unseen = get_string('unseenpageinbranch', 'lesson');
             }
             
             if ($page->qtype == LESSON_BRANCHTABLE) {
-                if ($lesson->minquestions and isstudent($course->id)) {
+                if ($lesson->minquestions and !has_capability('mod/lesson:manage', $context)) {
                     // tell student how many questions they have seen, how many are required and their grade
                     $ntries = count_records("lesson_grades", "lessonid", $lesson->id, "userid", $USER->id);
                     
             
             // check to see if the student ran out of time
             $outoftime = optional_param('outoftime', '', PARAM_ALPHA);
-            if ($lesson->timed && !isteacher($course->id)) {
+            if ($lesson->timed && !has_capability('mod/lesson:manage', $context)) {
                 if ($outoftime == 'normal') {
                     print_simple_box(get_string("eolstudentoutoftime", "lesson"), "center");
                 }
             }
 
             // Update the clock / get time information for this user
-            if (!isteacher($course->id)) {
+            if (!has_capability('mod/lesson:manage', $context)) {
                 unset($USER->startlesson[$lesson->id]);
                 if (!$timer = get_records_select('lesson_timer', "lessonid = $lesson->id AND userid = $USER->id", 'starttime')) {
                     error('Error: could not find records');
             if (isset($USER->modattempts[$lesson->id])) {
                 $ntries--;  // need to look at the old attempts :)
             }
-            if (isstudent($course->id)) {
+            if (!has_capability('mod/lesson:manage', $context)) {
                 
                 $gradeinfo = lesson_grade($lesson, $ntries);
                 
             }
 
             // high scores code
-            if ($lesson->highscores && !isteacher($course->id) && !$lesson->practice) {
+            if ($lesson->highscores && !has_capability('mod/lesson:manage', $context) && !$lesson->practice) {
                 echo "<div align=\"center\"><br>";
                 if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id", "completed")) {
                     echo get_string("youmadehighscore", "lesson", $lesson->maxhighscores)."<br>";
                 echo "</div>";                            
             }
 
-            if ($lesson->modattempts && !isteacher($course->id)) {
+            if ($lesson->modattempts && !has_capability('mod/lesson:manage', $context)) {
                 // make sure if the student is reviewing, that he/she sees the same pages/page path that he/she saw the first time
                 // look at the attempt records to find the first QUESTION page that the user answered, then use that page id
                 // to pass to view again.  This is slick cause it wont call the empty($pageid) code
                 $lastattempt = end($attempts);
                 $USER->modattempts[$lesson->id] = $lastattempt->pageid;
                 echo "<div align=\"center\" style=\"padding: 5px;\" class=\"lessonbutton standardbutton\"><a href=\"view.php?id=$cm->id&amp;pageid=$pageid\">".get_string("reviewlesson", "lesson")."</a></div>\n"; 
-            } elseif ($lesson->modattempts && isteacher($course->id)) {
+            } elseif ($lesson->modattempts && has_capability('mod/lesson:manage', $context)) {
                 echo "<p align=\"center\">".get_string("modattemptsnoteacher", "lesson")."</p>";                
             }
             
         if (!$page = get_record_select("lesson_pages", "lessonid = $lesson->id AND prevpageid = 0")) {
             // if there are no pages give teacher the option to create a new page or a new branch table
             echo "<div align=\"center\">";
-            if (isteacheredit($course->id)) {
+            if (has_capability('mod/lesson:edit', $context)) {
                 print_simple_box( "<table cellpadding=\"5\" border=\"0\">\n<tr><th>".get_string("whatdofirst", "lesson")."</th></tr><tr><td>".
                     "<a href=\"import.php?id=$cm->id&amp;pageid=0\">".
                     get_string("importquestions", "lesson")."</a></td></tr><tr><td>".
                         }
                     }
                     echo "<table align=\"center\" cellpadding=\"5\" border=\"0\" width=\"80%\">\n";
-                    if (isteacheredit($course->id)) {
+                    if (has_capability('mod/lesson:edit', $context)) {
                         echo "<tr><td align=\"left\"><small><a href=\"import.php?id=$cm->id&amp;pageid=$page->prevpageid\">".
                             get_string("importquestions", "lesson")."</a> | ".
                             "<a href=\"lesson.php?id=$cm->id&amp;sesskey=".$USER->sesskey."&amp;action=addcluster&amp;pageid=$page->prevpageid\">".
                     }                  
                 } else {   
                     echo "<table align=\"center\" cellpadding=\"5\" border=\"0\" width=\"80%\">\n";
-                    if (isteacheredit($course->id)) {
+                    if (has_capability('mod/lesson:edit', $context)) {
                         echo "<tr><td align=\"left\"><small><a href=\"import.php?id=$cm->id&amp;pageid=0\">".
                             get_string("importquestions", "lesson")."</a> | ".
                             "<a href=\"lesson.php?id=$cm->id&amp;sesskey=".$USER->sesskey."&amp;action=addcluster&amp;pageid=0\">".
             while (true) {
                 echo "<tr><td>\n";
                 echo "<table width=\"100%\" border=\"1\" class=\"generalbox\"><tr><th colspan=\"2\">".format_string($page->title)."&nbsp;&nbsp;\n";
-                if (isteacheredit($course->id)) {
+                if (has_capability('mod/lesson:edit', $context)) {
                     if ($npages > 1) {
                         echo "<a title=\"".get_string("move")."\" href=\"lesson.php?id=$cm->id&amp;action=move&amp;pageid=$page->id\">\n".
                             "<img src=\"$CFG->pixpath/t/move.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\" alt=\"move\" /></a>\n";
                     echo "&nbsp;</td></tr>\n";
                 }
                 echo "</table></td></tr>\n";
-                if (isteacheredit($course->id)) {
+                if (has_capability('mod/lesson:edit', $context)) {
                     echo "<tr><td align=\"left\"><small><a href=\"import.php?id=$cm->id&amp;pageid=$page->id\">".
                         get_string("importquestions", "lesson")."</a> | ".    
                          "<a href=\"lesson.php?id=$cm->id&amp;sesskey=".$USER->sesskey."&amp;action=addcluster&amp;pageid=$page->id\">".
             print_table($table);
         }
         
-        if (!isteacher($course->id)) {  // teachers don't need the links
+        if (!has_capability('mod/lesson:manage', $context)) {  // teachers don't need the links
             echo '<div align="center">';
             if (optional_param('link', 0, PARAM_INT)) {
                 echo "<br /><div class=\"lessonbutton standardbutton\"><a href=\"../../course/view.php?id=$course->id\">".get_string("returntocourse", "lesson")."</a></div>";