Skip to content

Commit

Permalink
Added 'studentview' button functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
thepurpleblob committed Aug 15, 2005
1 parent c56707d commit 367b841
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 7 deletions.
20 changes: 18 additions & 2 deletions lib/moodlelib.php
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions lib/pagelib.php
Expand Up @@ -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
Expand Down
41 changes: 38 additions & 3 deletions lib/weblib.php
Expand Up @@ -3064,9 +3064,39 @@ function update_course_icon($courseid) {
$edit = 'on';
}
return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/view.php\">".
"<input type=\"hidden\" name=\"id\" value=\"$courseid\" />".
"<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
"<input type=\"submit\" value=\"$string\" /></form>";
"<input type=\"hidden\" name=\"id\" value=\"$courseid\" />".
"<input type=\"hidden\" name=\"edit\" value=\"$edit\" />".
"<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />".
"<input type=\"submit\" value=\"$string\" /></form>";
}
}

/**
* 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 = "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/view.php\">".
"<input type=\"hidden\" name=\"id\" value=\"$courseid\" />".
"<input type=\"hidden\" name=\"studentview\" value=\"$svedit\" />".
"<input type=\"hidden\" name=\"sesskey\" value=\"".sesskey()."\" />".
"<input type=\"submit\" value=\"$svstring\" /></form>";
return $button;
}
}

Expand All @@ -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 "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/mod.php\">".
Expand Down

0 comments on commit 367b841

Please sign in to comment.