From: moodler Date: Sat, 16 Aug 2003 05:19:24 +0000 (+0000) Subject: OK, this is a new scheme to allow some teachers to edit and others to not X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=73047f2f76d91a319d3fd803e84869e78315ed62;p=moodle.git OK, this is a new scheme to allow some teachers to edit and others to not that is much better than the proposal to change the role of course creators. There is a new field in user_teachers called "editall", which is ON BY DEFAULT, and allows teachers to edit courses. It can be modified on the teacher editing screen (formerly assign teachers). The value is cached in the session. To test for it, there is a new function isteacheredit($course->id) which works much like isteacher did. I'm going through now and applying this new function wherever it is needed. --- diff --git a/course/teacher.php b/course/teacher.php index c67042aac5..4d0622157a 100644 --- a/course/teacher.php +++ b/course/teacher.php @@ -34,6 +34,12 @@ $strsearchresults = get_string("searchresults"); $strsearchagain = get_string("searchagain"); $strtoomanytoshow = get_string("toomanytoshow"); + $strname = get_string("name"); + $strorder = get_string("order"); + $strrole = get_string("role"); + $stredit = get_string("edit"); + $stryes = get_string("yes"); + $strno = get_string("no"); if ($search) { $searchstring = $strsearchagain; @@ -78,6 +84,7 @@ } $teacher->role = $vals['r']; $teacher->authority = $vals['a']; + $teacher->editall = $vals['e']; if (!update_record("user_teachers", $teacher)) { error("Could not update teacher entry id = $teacher->id"); } @@ -111,6 +118,7 @@ $teacher->userid = $user->id; $teacher->course = $course->id; + $teacher->editall = 1; if (!empty($teachers)) { $teacher->authority = 2; } else { @@ -121,6 +129,7 @@ error("Could not add that teacher to this course!"); } $user->authority = $teacher->authority; + $user->editall = $teacher->editall; $teachers[] = $user; } @@ -153,15 +162,20 @@ } else { - $table->head = array ("", get_string("name"), get_string("order"), get_string("role"), " "); - $table->align = array ("right", "left", "center", "center", "center"); - $table->size = array ("35", "", "", "", ""); + $table->head = array ("", $strname, $strorder, $strrole, $stredit, " "); + $table->align = array ("right", "left", "center", "center", "center", "center"); + $table->size = array ("35", "", "", "", "10", ""); - $option[0] = get_string("hide"); + $ordermenu = NULL; + $ordermenu[0] = get_string("hide"); for ($i=1; $i<=8; $i++) { - $option[$i] = $i; + $ordermenu[$i] = $i; } + $editmenu = NULL; + $editmenu[0] = $strno; + $editmenu[1] = $stryes; + $teacherarray = array(); echo "
"; @@ -170,7 +184,13 @@ $picture = print_user_picture($teacher->id, $course->id, $teacher->picture, false, true); - $authority = choose_from_menu ($option, "a$teacher->id", $teacher->authority, "", "", "", true); + $authority = choose_from_menu ($ordermenu, "a$teacher->id", $teacher->authority, "", "", "", true); + + if ($USER->id == $teacher->id) { + $editall = "id\" type=\"hidden\" value=\"1\">$stryes"; + } else { + $editall = choose_from_menu ($editmenu, "e$teacher->id", $teacher->editall, "", "", "", true); + } $removelink = "id&remove=$teacher->id\">$strremoveteacher"; @@ -180,7 +200,7 @@ $table->data[] = array ($picture, "$teacher->firstname $teacher->lastname", $authority, "id\" value=\"$teacher->role\" size=30>", - $removelink); + $editall, $removelink); } $teacherlist = implode(",",$teacherarray); unset($teacherarray); diff --git a/course/view.php b/course/view.php index c6525771e6..bef7ceb145 100644 --- a/course/view.php +++ b/course/view.php @@ -26,7 +26,7 @@ add_to_log($course->id, "course", "view", "view.php?id=$course->id", "$course->id"); - if (isteacher($course->id) and iscreator()) { + if (isteacheredit($course->id)) { if (isset($edit)) { if ($edit == "on") { $USER->editing = true; diff --git a/lib/datalib.php b/lib/datalib.php index 83678de18d..4fc6334e9c 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -779,6 +779,9 @@ function get_user_info_from_db($field, $value) { if ($teachers = get_records("user_teachers", "userid", $user->id)) { foreach ($teachers as $teacher) { $user->teacher[$teacher->course] = true; + if ($teacher->editall) { + $user->teacheredit[$teacher->course] = true; + } } } @@ -909,7 +912,7 @@ function get_course_teachers($courseid, $sort="t.authority ASC") { global $CFG; - return get_records_sql("SELECT u.*,t.authority,t.role + return get_records_sql("SELECT u.*,t.authority,t.role,t.editall FROM {$CFG->prefix}user u, {$CFG->prefix}user_teachers t WHERE t.course = '$courseid' AND t.userid = u.id AND u.deleted = '0' diff --git a/lib/db/mysql.php b/lib/db/mysql.php index 9ee9564079..0973745577 100644 --- a/lib/db/mysql.php +++ b/lib/db/mysql.php @@ -481,6 +481,10 @@ function main_upgrade($oldversion=0) { get_scales_menu(0); // Just to force the default scale to be created } + if ($oldversion < 2003081600) { + table_column("user_teachers", "", "editall", "integer", "1", "unsigned", "1", "", "role"); + table_column("user_teachers", "", "timemodified", "integer", "10", "unsigned", "0", "", "editall"); + } return $result; diff --git a/lib/db/mysql.sql b/lib/db/mysql.sql index 3a93114782..a770ca226f 100644 --- a/lib/db/mysql.sql +++ b/lib/db/mysql.sql @@ -274,6 +274,8 @@ CREATE TABLE `prefix_user_teachers` ( `course` int(10) unsigned NOT NULL default '0', `authority` int(10) NOT NULL default '3', `role` varchar(40) NOT NULL default '', + `editall` int(1) unsigned NOT NULL default '1', + `timemodified` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`), KEY `courseuserid` (course,userid) diff --git a/lib/db/postgres7.php b/lib/db/postgres7.php index 44f4f01654..38a2f5e5d7 100644 --- a/lib/db/postgres7.php +++ b/lib/db/postgres7.php @@ -225,6 +225,10 @@ function main_upgrade($oldversion=0) { get_scales_menu(0); // Just to force the default scale to be created } + if ($oldversion < 2003081600) { + table_column("user_teachers", "", "editall", "integer", "1", "unsigned", "1", "", "role"); + table_column("user_teachers", "", "timemodified", "integer", "10", "unsigned", "0", "", "editall"); + } return $result; } diff --git a/lib/db/postgres7.sql b/lib/db/postgres7.sql index 466717a324..bc615cbb52 100644 --- a/lib/db/postgres7.sql +++ b/lib/db/postgres7.sql @@ -171,7 +171,9 @@ CREATE TABLE prefix_user_teachers ( userid integer NOT NULL default '0', course integer NOT NULL default '0', authority integer NOT NULL default '3', - role varchar(40) NOT NULL default '' + role varchar(40) NOT NULL default '', + editall integer NOT NULL default '1', + timemodified integer NOT NULL default '0' ); CREATE INDEX prefix_user_teachers_courseuserid_idx ON prefix_user_teachers (course,userid); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 8662c923f6..2473912f5b 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -268,7 +268,7 @@ function require_login($courseid=0) { /// whether they are "logged in" or allowed to be in a particular course. /// If not, then it redirects them to the site login or course enrolment. - global $CFG, $SESSION, $USER, $FULLME, $PHPSESSID; + global $CFG, $SESSION, $USER, $FULLME, $MoodleSession; // First check that the user is logged in to the site. if (! (isset($USER->loggedin) and $USER->confirmed and ($USER->site == $CFG->wwwroot)) ) { // They're not @@ -277,11 +277,7 @@ function require_login($courseid=0) { $SESSION->fromurl = $_SERVER["HTTP_REFERER"]; } $USER = NULL; - if ($PHPSESSID) { // Cookies not enabled. - redirect("$CFG->wwwroot/login/index.php?PHPSESSID=$PHPSESSID"); - } else { - redirect("$CFG->wwwroot/login/index.php"); - } + redirect("$CFG->wwwroot/login/index.php"); die; } @@ -416,6 +412,21 @@ function isteacher($courseid, $userid=0) { return record_exists("user_teachers", "userid", $userid, "course", $courseid); } +function isteacheredit($courseid, $userid=0) { +/// Is the user allowed to edit this course? + global $USER; + + if (isadmin($userid)) { // admins can do anything + return true; + } + + if (!$userid) { + return !empty($USER->teacheredit[$courseid]); + } + + return get_field("user_teachers", "editall", "userid", $userid, "course", $courseid); +} + function iscreator ($userid=0) { /// Can user create new courses? global $USER; diff --git a/version.php b/version.php index c8f312e1cd..18bfa24e85 100644 --- a/version.php +++ b/version.php @@ -5,7 +5,7 @@ // database to determine whether upgrades should // be performed (see lib/db/*.php) -$version = 2003081503; // The current version is a date (YYYYMMDDXX) +$version = 2003081600; // The current version is a date (YYYYMMDDXX) $release = "1.1 development"; // User-friendly version number