diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 7805584738b71..821a25a8851c8 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2017,6 +2017,10 @@ function isadmin($userid=0) { global $USER; static $admins, $nonadmins; +// if (!empty($USER->studentview)) { +// return false; +// } + if (!isset($admins)) { $admins = array(); $nonadmins = array(); @@ -2066,7 +2070,13 @@ function isteacher($courseid=0, $userid=0, $includeadmin=true) { } if (!empty($USER->teacher) and $courseid) { // look in session cache if (!empty($USER->teacher[$courseid])) { // Explicitly a teacher, good - return true; + // normally return 'true', but override if 'studentview' on + if (!empty($USER->studentview)) { + return false; + } + else { + return true; + } } } $userid = $USER->id; // we need to make further checks @@ -2123,11 +2133,17 @@ function isteacherinanycourse($userid=0, $includeadmin=true) { * @uses $USER * @param int $courseid The id of the course that is being edited * @param int $userid The id of the user that is being tested against. Set this to 0 if you would just like to test against the currently logged in user. + * @param bool $ignorestudentview true = don't do check for studentview mode * @return boo */ -function isteacheredit($courseid, $userid=0) { +function isteacheredit($courseid, $userid=0, $ignorestudentview=false) { global $USER; + // we can't edit in studentview + if (!empty($USER->studentview) and !$ignorestudentview) { + return false; + } + if (isadmin($userid)) { // admins can do anything return true; } diff --git a/lib/pagelib.php b/lib/pagelib.php index 26c9047b9dbcc..faea879812403 100644 --- a/lib/pagelib.php +++ b/lib/pagelib.php @@ -388,10 +388,11 @@ function print_header($title, $morebreadcrumbs = NULL) { // The "Editing On" button will be appearing only in the "main" course screen // (i.e., no breadcrumbs other than the default one added inside this function) - $button = empty($morebreadcrumbs) ? update_course_icon($this->courserecord->id) : ' '; + $buttons = update_course_icon($this->courserecord->id ) . update_studentview_button( $this->courserecord->id ); + $buttons = empty($morebreadcrumbs) ? $buttons : ' '; print_header($title, $this->courserecord->fullname, $crumbtext, - '', '', true, $button, user_login_string($this->courserecord, $USER)); + '', '', true, $buttons, user_login_string($this->courserecord, $USER)); } // SELF-REPORTING SECTION diff --git a/lib/weblib.php b/lib/weblib.php index 98182a035ff5f..4c047428d382a 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -3064,9 +3064,39 @@ function update_course_icon($courseid) { $edit = 'on'; } return "
framename\" method=\"get\" action=\"$CFG->wwwroot/course/view.php\">". - "". - "". - "
"; + "". + "". + "". + ""; + } +} + +/** + * Returns a turn student view on/off button for course in a self contained form. + * + * @uses $CFG + * @uses $USER + * @param int $courseid The course to update by id as found in 'course' table + * @return string + */ +function update_studentview_button($courseid) { + + global $CFG, $USER; + + if (isteacheredit($courseid,0,true)) { + if (!empty($USER->studentview)) { + $svstring = get_string('studentviewoff'); + $svedit = 'off'; + } else { + $svstring = get_string('studentviewon'); + $svedit = 'on'; + } + $button = "
framename\" method=\"get\" action=\"$CFG->wwwroot/course/view.php\">". + "". + "". + "". + "
"; + return $button; } } @@ -3080,6 +3110,11 @@ function update_course_icon($courseid) { function update_module_button($moduleid, $courseid, $string) { global $CFG, $USER; + // do not display if studentview is on + if (!empty($USER->studentview)) { + return ''; + } + if (isteacheredit($courseid)) { $string = get_string('updatethis', '', $string); return "
framename\" method=\"get\" action=\"$CFG->wwwroot/course/mod.php\">".