From 6e1ff5c8fb87171cf43db4e1969fae07d61b9cd7 Mon Sep 17 00:00:00 2001 From: mark-nielsen Date: Fri, 8 Sep 2006 23:17:18 +0000 Subject: [PATCH] MDL-6477: Added roles support. Also added lesson_set_message() and lesson_print_message() to locallib.php Also fixed problem in continue.html with not printing nextpageid --- mod/lesson/action/continue.html | 4 +- mod/lesson/action/continue.php | 18 ++++----- mod/lesson/db/access.php | 50 ++++++++++++++++++++++++ mod/lesson/import.php | 6 +-- mod/lesson/importppt.php | 6 +-- mod/lesson/index.php | 4 +- mod/lesson/lesson.php | 5 +-- mod/lesson/locallib.php | 68 ++++++++++++++++++++++++++++++--- mod/lesson/mediafile.php | 2 + mod/lesson/report.php | 46 ++++++++++++---------- mod/lesson/styles.php | 16 ++++++++ mod/lesson/tabs.php | 6 ++- mod/lesson/version.php | 2 +- mod/lesson/view.php | 67 +++++++++++++++++++------------- 14 files changed, 221 insertions(+), 79 deletions(-) create mode 100644 mod/lesson/db/access.php diff --git a/mod/lesson/action/continue.html b/mod/lesson/action/continue.html index e503a4ee39..0a3f50a62c 100644 --- a/mod/lesson/action/continue.html +++ b/mod/lesson/action/continue.html @@ -32,7 +32,7 @@ if ($lesson->displayleft) { } // End if ($lesson->displayleft) ?> -timed and !isteacher($course->id)) { +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) {
- + modattempts[$lesson->id])) { ?>



diff --git a/mod/lesson/action/continue.php b/mod/lesson/action/continue.php index 7517373fb8..1ae0b1c2ee 100644 --- a/mod/lesson/action/continue.php +++ b/mod/lesson/action/continue.php @@ -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"); } @@ -536,7 +536,7 @@ // 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 @@ -570,7 +570,7 @@ $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; @@ -744,7 +744,7 @@ } } } elseif ($newpageid == LESSON_UNSEENBRANCHPAGE) { - if (isteacher($course->id)) { + if (has_capability('mod/lesson:manage', $context)) { if ($page->nextpageid == 0) { $newpageid = LESSON_EOL; } else { @@ -758,7 +758,7 @@ } 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 { @@ -779,6 +779,6 @@ } 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 index 0000000000..2f0f1e1cd6 --- /dev/null +++ b/mod/lesson/db/access.php @@ -0,0 +1,50 @@ + 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 + ) + ) +); diff --git a/mod/lesson/import.php b/mod/lesson/import.php index c78f32ed13..a5fd6e812c 100644 --- a/mod/lesson/import.php +++ b/mod/lesson/import.php @@ -23,10 +23,8 @@ 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"); diff --git a/mod/lesson/importppt.php b/mod/lesson/importppt.php index f13b083a30..758b83c730 100644 --- a/mod/lesson/importppt.php +++ b/mod/lesson/importppt.php @@ -32,10 +32,8 @@ } 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"); diff --git a/mod/lesson/index.php b/mod/lesson/index.php index 6e538115c4..e354cc5297 100644 --- a/mod/lesson/index.php +++ b/mod/lesson/index.php @@ -68,6 +68,8 @@ //Show normal if the mod is visible $link = "coursemodule\">".format_string($lesson->name,true).""; } + $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 diff --git a/mod/lesson/lesson.php b/mod/lesson/lesson.php index a930ef46bc..08cb72eb91 100644 --- a/mod/lesson/lesson.php +++ b/mod/lesson/lesson.php @@ -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; diff --git a/mod/lesson/locallib.php b/mod/lesson/locallib.php index 5e4f1e4a54..380170e3d1 100644 --- a/mod/lesson/locallib.php +++ b/mod/lesson/locallib.php @@ -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 "id."\">\n". "pixpath/t/move.gif\" hspace=\"2\" height=11 width=11 alt=\"move\" border=0>\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 "

".get_string('teacherongoingwarning', 'lesson').'

'; } 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; } diff --git a/mod/lesson/mediafile.php b/mod/lesson/mediafile.php index 4d5dec9971..084424b2a4 100644 --- a/mod/lesson/mediafile.php +++ b/mod/lesson/mediafile.php @@ -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 diff --git a/mod/lesson/report.php b/mod/lesson/report.php index 845140c062..fe7fa07d51 100644 --- a/mod/lesson/report.php +++ b/mod/lesson/report.php @@ -35,13 +35,11 @@ // 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 @@ -222,8 +220,13 @@ $studentname = "{$student->lastname}, $student->firstname"; foreach ($tries as $try) { // start to build up the checkbox and link - $temp = ' '. - "id&action=detail&userid=".$try['userid'].'&try='.$try['try'].'">'; + if (has_capability('mod/lesson:edit', $context)) { + $temp = ' '; + } else { + $temp = ''; + } + + $temp .= "id&action=detail&userid=".$try['userid'].'&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"]; @@ -270,23 +273,26 @@ } } // print it all out ! - echo "\n - \n - id\" />\n - id\" />\n"; - + if (has_capability('mod/lesson:edit', $context)) { + echo "\n + \n + id\" />\n + id\" />\n"; + } print_table($table); - echo '
'. - ''.get_string('selectall').' / '. - ''.get_string('deselectall').' '; + if (has_capability('mod/lesson:edit', $context)) { + echo '
'. + ''.get_string('selectall').' / '. + ''.get_string('deselectall').' '; - $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 '
'; + } - echo '
'; - // some stat calculations if ($numofattempts == 0) { $avescore = get_string("notcompleted", "lesson"); diff --git a/mod/lesson/styles.php b/mod/lesson/styles.php index 7f62f4b1e9..55de0e5a72 100644 --- a/mod/lesson/styles.php +++ b/mod/lesson/styles.php @@ -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 ***/ diff --git a/mod/lesson/tabs.php b/mod/lesson/tabs.php index d00c72113a..8a456bb76c 100644 --- a/mod/lesson/tabs.php +++ b/mod/lesson/tabs.php @@ -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); @@ -34,11 +35,12 @@ $counts->attempts = count_records('lesson_grades', 'lessonid', $lesson->id); $counts->student = $course->student; + $row[] = new tabobject('teacherview', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id", get_string('edit'), get_string('editlesson', 'lesson', format_string($lesson->name))); $row[] = new tabobject('navigation', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&action=navigation", get_string('preview', 'lesson'), get_string('previewlesson', 'lesson', format_string($lesson->name))); $row[] = new tabobject('reports', "$CFG->wwwroot/mod/lesson/report.php?id=$cm->id", get_string('reports', 'lesson'), get_string('viewreports', 'lesson', $counts)); - if (isteacheredit($course->id)) { - $row[] = new tabobject('essayview', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&action=essayview", get_string('manualgrading', 'lesson')); + if (has_capability('mod/lesson:edit', $context)) { + $row[] = new tabobject('essayview', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&action=essayview", get_string('manualgrading', 'lesson')); } if ($lesson->highscores) { $row[] = new tabobject('highscores', "$CFG->wwwroot/mod/lesson/view.php?id=$cm->id&action=highscores", get_string('highscores', 'lesson')); diff --git a/mod/lesson/version.php b/mod/lesson/version.php index a03a8c1b37..d5ace47412 100644 --- a/mod/lesson/version.php +++ b/mod/lesson/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 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) diff --git a/mod/lesson/view.php b/mod/lesson/view.php index 5da2ef7899..d2306150ca 100644 --- a/mod/lesson/view.php +++ b/mod/lesson/view.php @@ -27,6 +27,19 @@ } 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 = '
'; $button .= '
'. ''. @@ -108,7 +121,7 @@ $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 @@ -126,7 +139,7 @@ /************** 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))) { @@ -170,7 +183,7 @@ 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)) { @@ -184,7 +197,7 @@ } // 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); @@ -376,7 +389,7 @@ 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; @@ -430,7 +443,7 @@ } 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 @@ -456,7 +469,7 @@ // 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); } @@ -516,7 +529,7 @@ } // 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 { @@ -536,7 +549,7 @@ // for timed lessons, display clock if ($lesson->timed) { - if(isteacher($course->id)) { + if(has_capability('mod/lesson:manage', $context)) { echo '

'. get_string('teachertimerwarning', 'lesson') .'

'; } else { if ((($timer->starttime + $lesson->maxtime * 60) - time()) > 0) { @@ -570,7 +583,7 @@ } // 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'); @@ -591,7 +604,7 @@ 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) { @@ -622,7 +635,7 @@ } /// 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'); @@ -636,7 +649,7 @@ } 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); @@ -973,14 +986,14 @@ // 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'); @@ -1001,7 +1014,7 @@ 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); @@ -1089,7 +1102,7 @@ } // high scores code - if ($lesson->highscores && !isteacher($course->id) && !$lesson->practice) { + if ($lesson->highscores && !has_capability('mod/lesson:manage', $context) && !$lesson->practice) { echo "


"; if (!$grades = get_records_select("lesson_grades", "lessonid = $lesson->id", "completed")) { echo get_string("youmadehighscore", "lesson", $lesson->maxhighscores)."
"; @@ -1120,7 +1133,7 @@ echo "
"; } - 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 @@ -1135,7 +1148,7 @@ $lastattempt = end($attempts); $USER->modattempts[$lesson->id] = $lastattempt->pageid; echo "\n"; - } elseif ($lesson->modattempts && isteacher($course->id)) { + } elseif ($lesson->modattempts && has_capability('mod/lesson:manage', $context)) { echo "

".get_string("modattemptsnoteacher", "lesson")."

"; } @@ -1177,7 +1190,7 @@ 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 "
"; - if (isteacheredit($course->id)) { + if (has_capability('mod/lesson:edit', $context)) { print_simple_box( "\n
".get_string("whatdofirst", "lesson")."
". "id&pageid=0\">". get_string("importquestions", "lesson")."
". @@ -1226,7 +1239,7 @@ } } echo "\n"; - if (isteacheredit($course->id)) { + if (has_capability('mod/lesson:edit', $context)) { echo "
id&pageid=$page->prevpageid\">". get_string("importquestions", "lesson")." | ". "id&sesskey=".$USER->sesskey."&action=addcluster&pageid=$page->prevpageid\">". @@ -1241,7 +1254,7 @@ } } else { echo "\n"; - if (isteacheredit($course->id)) { + if (has_capability('mod/lesson:edit', $context)) { echo "\n"; - if (isteacheredit($course->id)) { + if (has_capability('mod/lesson:edit', $context)) { echo "
id&pageid=0\">". get_string("importquestions", "lesson")." | ". "id&sesskey=".$USER->sesskey."&action=addcluster&pageid=0\">". @@ -1257,7 +1270,7 @@ while (true) { echo "
\n"; echo "\n"; } echo "
".format_string($page->title)."  \n"; - if (isteacheredit($course->id)) { + if (has_capability('mod/lesson:edit', $context)) { if ($npages > 1) { echo "id&action=move&pageid=$page->id\">\n". "pixpath/t/move.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\" alt=\"move\" />\n"; @@ -1472,7 +1485,7 @@ echo " 
id&pageid=$page->id\">". get_string("importquestions", "lesson")." | ". "id&sesskey=".$USER->sesskey."&action=addcluster&pageid=$page->id\">". @@ -1882,7 +1895,7 @@ 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 '