]> git.mjollnir.org Git - moodle.git/commitdiff
OK, this is a new scheme to allow some teachers to edit and others to not
authormoodler <moodler>
Sat, 16 Aug 2003 05:19:24 +0000 (05:19 +0000)
committermoodler <moodler>
Sat, 16 Aug 2003 05:19:24 +0000 (05:19 +0000)
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.

course/teacher.php
course/view.php
lib/datalib.php
lib/db/mysql.php
lib/db/mysql.sql
lib/db/postgres7.php
lib/db/postgres7.sql
lib/moodlelib.php
version.php

index c67042aac57fe115b36d51a8a3133ab48cdd0138..4d0622157a82d64e344b6193a1ef079f79f01b9d 100644 (file)
     $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");
             }
 
         $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"), "&nbsp");
-        $table->align = array ("right", "left", "center", "center", "center");
-        $table->size  = array ("35", "", "", "", "");
+        $table->head  = array ("", $strname, $strorder, $strrole, $stredit, "&nbsp");
+        $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);
index c6525771e665e8a00247648dbdcc528de89ea7d0..bef7ceb145db844fda92ac4979962d726c38ba82 100644 (file)
@@ -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;
index 83678de18dd1bd3c2d544406de1192b5576107c9..4fc6334e9c672d9b4c87654997b7be95e950f9cc 100644 (file)
@@ -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'
index 9ee9564079a39c5d7f9fe004fb46a85d0c2bb13f..097374557793e7a0f581ba754e03e7d4d3da9f79 100644 (file)
@@ -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;
 
index 3a9311478240a150b45e48d1c973bc7fe7cc93b8..a770ca226fb8e1279d94cdbf5564dc375cd34a7b 100644 (file)
@@ -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)
index 44f4f016548a1b64c9c0e6b55084fc3836916527..38a2f5e5d75745a63abec5ac9c20e00687d7d7ae 100644 (file)
@@ -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;
 }
index 466717a324098492688a9a1bb5041449d8395e2f..bc615cbb52e8239d95b63b131928ba3b63b460d1 100644 (file)
@@ -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);
index 8662c923f607104ef700ee09b727e080b8248658..2473912f5ba28619d6c7e8ae5c1112342314b911 100644 (file)
@@ -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;
index c8f312e1cde4cb94dee4f578044e850d49c48165..18bfa24e85347c66e2ccb3f0bd147b3e9f30375e 100644 (file)
@@ -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