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.
$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;
}
$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");
}
$teacher->userid = $user->id;
$teacher->course = $course->id;
+ $teacher->editall = 1;
if (!empty($teachers)) {
$teacher->authority = 2;
} else {
error("Could not add that teacher to this course!");
}
$user->authority = $teacher->authority;
+ $user->editall = $teacher->editall;
$teachers[] = $user;
}
} 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 "<form action=teacher.php method=post>";
$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 = "<input name=\"e$teacher->id\" type=\"hidden\" value=\"1\">$stryes";
+ } else {
+ $editall = choose_from_menu ($editmenu, "e$teacher->id", $teacher->editall, "", "", "", true);
+ }
$removelink = "<a href=\"teacher.php?id=$course->id&remove=$teacher->id\">$strremoveteacher</a>";
$table->data[] = array ($picture, "$teacher->firstname $teacher->lastname", $authority,
"<input type=text name=\"r$teacher->id\" value=\"$teacher->role\" size=30>",
- $removelink);
+ $editall, $removelink);
}
$teacherlist = implode(",",$teacherarray);
unset($teacherarray);
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;
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;
+ }
}
}
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'
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;
`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)
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;
}
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);
/// 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
$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;
}
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;
// 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