Added 'studentview' button functionality.

This commit is contained in:
thepurpleblob
2005-08-15 12:53:57 +00:00
parent c56707d80b
commit 367b841305
3 changed files with 59 additions and 7 deletions
+18 -2
View File
@@ -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;
}
+3 -2
View File
@@ -388,10 +388,11 @@ class page_course extends page_base {
// 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
+38 -3
View File
@@ -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;
}
}
@@ -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\">".