From 02ebf404c8ce01916ad158d24b41e25e7cd3b492 Mon Sep 17 00:00:00 2001
From: moodler creatornewcourse: $strnoexistingteachers";
$teacherlist = "";
} 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", "", "", "", "");
+
+ $option[0] = get_string("hide");
+ for ($i=1; $i<=8; $i++) {
+ $option[$i] = $i;
+ }
+
$teacherarray = array();
+
+ echo " id&add=$user->id\"".
- "title=\"$straddteacher\"> The following update will automatically convert all your existing teachers into course creators, to maintain backward compatibility. Make sure you look at your upgraded site carefully and understand these new changes.", "center", "50%", "$THEME->cellheading", "20", "noticebox");
+
+ $count = 0;
+ $errorcount = 0;
+ if ($teachers = get_records("user_teachers")) {
+ foreach ($teachers as $teacher) {
+ if (! record_exists("user_coursecreators", "userid", $teacher->userid)) {
+ $creator = NULL;
+ $creator->userid = $teacher->userid;
+ if (!insert_record("user_coursecreators", $creator)) {
+ $errorcount++;
+ } else {
+ $count++;
+ }
+ }
+ }
+ }
+ print_simple_box("$count teachers were upgraded to course creators (with $errorcount errors)", "center", "50%", "$THEME->cellheading", "20", "noticebox");
+
+ }
+
return $result;
}
diff --git a/lib/defaults.php b/lib/defaults.php
index 3669c721e19..84245b74c12 100644
--- a/lib/defaults.php
+++ b/lib/defaults.php
@@ -7,6 +7,7 @@
"auth" => "email",
"changepassword" => true,
"country" => "",
+ "creatornewcourse" => false,
"debug" => 7,
"framename" => "_top",
"frontpage" => 0,
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index e150041b542..8662c923f60 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -1584,6 +1584,17 @@ function microtime_diff($a, $b) {
return $b_sec - $a_sec + $b_dec - $a_dec;
}
+function make_menu_from_list($list, $separator=",") {
+/// Given a list (eg a,b,c,d,e) this function returns
+/// an array of 1->a, 2->b, 3->c etc
+
+ $array = array_reverse(explode($separator, $list), true);
+ foreach ($array as $key => $item) {
+ $outarray[$key+1] = trim($item);
+ }
+ return $outarray;
+}
+
// vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
?>
diff --git a/lib/weblib.php b/lib/weblib.php
index bf4445a8433..b019c8fb6b3 100644
--- a/lib/weblib.php
+++ b/lib/weblib.php
@@ -1273,6 +1273,41 @@ function print_time_selector($hour, $minute, $currenttime=0) {
choose_from_menu($minutes, $minute, $currentdate['minutes'], "");
}
+function print_scale_menu($courseid, $name, $current) {
+/// Prints a scale menu (as part of an existing form) including help button
+
+ global $CFG, $THEME;
+
+ $strscales = get_string("scales");
+ choose_from_menu(get_scales_menu($courseid), "$name", $current, "");
+ if (empty($THEME->custompix)) {
+ $helpicon = "$CFG->wwwroot/pix/help.gif";
+ } else {
+ $helpicon = "$CFG->wwwroot/theme/$CFG->theme/pix/help.gif";
+ }
+ $linkobject = "
+
+
+
+ creatornewcourse, "", "", "");
+ ?>
+
+
+
+
+
diff --git a/course/category.php b/course/category.php
index 92370d0d1cb..137976f3e2b 100644
--- a/course/category.php
+++ b/course/category.php
@@ -267,7 +267,7 @@
if ($creatorediting) {
echo " ";
print_footer();
diff --git a/course/teachers.php b/course/teachers.php
deleted file mode 100644
index b065d56f908..00000000000
--- a/course/teachers.php
+++ /dev/null
@@ -1,92 +0,0 @@
-id)) {
- error("Only teachers can edit the course!");
- }
-
-
-/// If data submitted, then process and store.
-
- if ($form = data_submitted()) {
-
- $rank = array();
-
- // Peel out all the data from variable names.
- foreach ($form as $key => $val) {
- if ($key <> "id") {
- $type = substr($key,0,1);
- $num = substr($key,1);
- $rank[$num][$type] = $val;
- }
- }
-
- foreach ($rank as $num => $vals) {
- if (! $teacher = get_record("user_teachers", "course", "$course->id", "userid", "$num")) {
- error("No such teacher in course $course->shortname with user id $num");
- }
- $teacher->role = $vals['r'];
- $teacher->authority = $vals['a'];
- if (!update_record("user_teachers", $teacher)) {
- error("Could not update teacher entry id = $teacher->id");
- }
- }
- redirect("teachers.php?id=$course->id", get_string("changessaved"));
- }
-
-/// Otherwise fill and print the form.
-
- print_header("$course->shortname: $course->teachers", "$course->fullname",
- "wwwroot/course/view.php?id=$course->id\">$course->shortname
- -> $course->teachers");
-
- if (!$teachers = get_course_teachers($course->id)) {
- error("No teachers found in this course!");
- }
-
- print_heading($course->teachers);
-
- $table->head = array ("", get_string("name"), get_string("order"), get_string("role"));
- $table->align = array ("RIGHT", "LEFT", "CENTER", "CENTER");
- $table->size = array ("35", "", "", "");
-
- $option[0] = get_string("hide");
- for ($i=1; $i<=8; $i++) {
- $option[$i] = $i;
- }
-
- echo "";
-
- print_footer($course);
-
-?>
diff --git a/lib/datalib.php b/lib/datalib.php
index 4dc94bfaf37..83678de18dd 100644
--- a/lib/datalib.php
+++ b/lib/datalib.php
@@ -830,160 +830,6 @@ function adminlogin($username, $md5password) {
}
-function get_site () {
-/// Returns $course object of the top-level site.
-
- if ( $course = get_record("course", "category", 0)) {
- return $course;
- } else {
- return false;
- }
-}
-
-function get_courses($categoryid="all", $sort="sortorder ASC", $fields="*") {
-/// Returns list of courses, for whole site, or category
-
- if ($categoryid == "all") {
- $courses = get_records("course", "", "", $sort, $fields);
- } else {
- $courses = get_records("course", "category", "$categoryid", $sort, $fields);
- }
-
- if ($courses) { /// Remove unavailable courses from the list
- foreach ($courses as $key => $course) {
- if (!$course->visible) {
- if (!isteacher($course->id)) {
- unset($courses[$key]);
- }
- }
- }
- }
- return $courses;
-}
-
-
-function get_my_courses($userid, $sort="c.fullname ASC") {
- global $CFG;
-
- return get_records_sql("SELECT c.*
- FROM {$CFG->prefix}course c,
- {$CFG->prefix}user_students s,
- {$CFG->prefix}user_teachers t
- WHERE (s.userid = '$userid' AND s.course = c.id)
- OR (t.userid = '$userid' AND t.course = c.id)
- GROUP BY c.id
- ORDER BY $sort");
-}
-
-function get_courses_search($search, $sort="fullname ASC", $page=0, $recordsperpage=50) {
-/// Returns a list of courses that match a search
-
- global $CFG;
-
- switch ($CFG->dbtype) {
- case "mysql":
- $limit = "LIMIT $page,$recordsperpage";
- break;
- case "postgres7":
- $limit = "LIMIT $recordsperpage OFFSET ".($page * $recordsperpage);
- break;
- default:
- $limit = "LIMIT $recordsperpage,$page";
- }
-
- //to allow caseinsensitive search for postgesql
- if ($CFG->dbtype == "postgres7") {
- $LIKE = "ILIKE";
- } else {
- $LIKE = "LIKE";
- }
-
- $fullnamesearch = "";
- $summarysearch = "";
-
- $searchterms = explode(" ", $search); // Search for words independently
-
- foreach ($searchterms as $searchterm) {
- if ($fullnamesearch) {
- $fullnamesearch .= " AND ";
- }
- $fullnamesearch .= " fullname $LIKE '%$searchterm%' ";
-
- if ($summarysearch) {
- $summarysearch .= " AND ";
- }
- $summarysearch .= " summary $LIKE '%$searchterm%' ";
- }
-
-
- $courses = get_records_sql("SELECT *
- FROM {$CFG->prefix}course
- WHERE ($fullnamesearch OR $summarysearch)
- ORDER BY $sort $limit");
-
- if ($courses) { /// Remove unavailable courses from the list
- foreach ($courses as $key => $course) {
- if (!$course->visible) {
- if (!isteacher($course->id)) {
- unset($courses[$key]);
- }
- }
- }
- }
-
- return $courses;
-}
-
-
-function get_categories($parent="none", $sort="sortorder ASC") {
-/// Returns a sorted list of categories
-
- if ($parent == "none") {
- $categories = get_records("course_categories", "", "", $sort);
- } else {
- $categories = get_records("course_categories", "parent", $parent, $sort);
- }
- if ($categories) { /// Remove unavailable categories from the list
- $admin = isadmin();
- foreach ($categories as $key => $category) {
- if (!$category->visible) {
- if (!$admin) {
- unset($categories[$key]);
- }
- }
- }
- }
- return $categories;
-}
-
-
-function fix_course_sortorder($categoryid, $sort="sortorder ASC") {
-/// Given a category object, this function makes sure the courseorder
-/// variable reflects the real world.
-
- if (!$courses = get_records("course", "category", "$categoryid", "$sort", "id, sortorder")) {
- return true;
- }
-
- $count = 0;
- $modified = false;
-
- foreach ($courses as $course) {
- if ($course->sortorder != $count) {
- set_field("course", "sortorder", $count, "id", $course->id);
- $modified = true;
- }
- $count++;
- }
-
- if ($modified) {
- set_field("course_categories", "timemodified", time(), "id", $categoryid);
- }
-
- return true;
-}
-
-
function get_guest() {
return get_user_info_from_db("username", "guest");
}
@@ -1223,6 +1069,222 @@ function get_users_longtimenosee($cutofftime) {
}
+
+/// OTHER SITE AND COURSE FUNCTIONS /////////////////////////////////////////////
+
+
+function get_site () {
+/// Returns $course object of the top-level site.
+
+ if ( $course = get_record("course", "category", 0)) {
+ return $course;
+ } else {
+ return false;
+ }
+}
+
+
+function get_courses($categoryid="all", $sort="sortorder ASC", $fields="*") {
+/// Returns list of courses, for whole site, or category
+
+ if ($categoryid == "all") {
+ $courses = get_records("course", "", "", $sort, $fields);
+ } else {
+ $courses = get_records("course", "category", "$categoryid", $sort, $fields);
+ }
+
+ if ($courses) { /// Remove unavailable courses from the list
+ foreach ($courses as $key => $course) {
+ if (!$course->visible) {
+ if (!isteacher($course->id)) {
+ unset($courses[$key]);
+ }
+ }
+ }
+ }
+ return $courses;
+}
+
+
+function get_my_courses($userid, $sort="c.fullname ASC") {
+ global $CFG;
+
+ return get_records_sql("SELECT c.*
+ FROM {$CFG->prefix}course c,
+ {$CFG->prefix}user_students s,
+ {$CFG->prefix}user_teachers t
+ WHERE (s.userid = '$userid' AND s.course = c.id)
+ OR (t.userid = '$userid' AND t.course = c.id)
+ GROUP BY c.id
+ ORDER BY $sort");
+}
+
+
+function get_courses_search($search, $sort="fullname ASC", $page=0, $recordsperpage=50) {
+/// Returns a list of courses that match a search
+
+ global $CFG;
+
+ switch ($CFG->dbtype) {
+ case "mysql":
+ $limit = "LIMIT $page,$recordsperpage";
+ break;
+ case "postgres7":
+ $limit = "LIMIT $recordsperpage OFFSET ".($page * $recordsperpage);
+ break;
+ default:
+ $limit = "LIMIT $recordsperpage,$page";
+ }
+
+ //to allow caseinsensitive search for postgesql
+ if ($CFG->dbtype == "postgres7") {
+ $LIKE = "ILIKE";
+ } else {
+ $LIKE = "LIKE";
+ }
+
+ $fullnamesearch = "";
+ $summarysearch = "";
+
+ $searchterms = explode(" ", $search); // Search for words independently
+
+ foreach ($searchterms as $searchterm) {
+ if ($fullnamesearch) {
+ $fullnamesearch .= " AND ";
+ }
+ $fullnamesearch .= " fullname $LIKE '%$searchterm%' ";
+
+ if ($summarysearch) {
+ $summarysearch .= " AND ";
+ }
+ $summarysearch .= " summary $LIKE '%$searchterm%' ";
+ }
+
+
+ $courses = get_records_sql("SELECT *
+ FROM {$CFG->prefix}course
+ WHERE ($fullnamesearch OR $summarysearch)
+ ORDER BY $sort $limit");
+
+ if ($courses) { /// Remove unavailable courses from the list
+ foreach ($courses as $key => $course) {
+ if (!$course->visible) {
+ if (!isteacher($course->id)) {
+ unset($courses[$key]);
+ }
+ }
+ }
+ }
+
+ return $courses;
+}
+
+
+function get_categories($parent="none", $sort="sortorder ASC") {
+/// Returns a sorted list of categories
+
+ if ($parent == "none") {
+ $categories = get_records("course_categories", "", "", $sort);
+ } else {
+ $categories = get_records("course_categories", "parent", $parent, $sort);
+ }
+ if ($categories) { /// Remove unavailable categories from the list
+ $admin = isadmin();
+ foreach ($categories as $key => $category) {
+ if (!$category->visible) {
+ if (!$admin) {
+ unset($categories[$key]);
+ }
+ }
+ }
+ }
+ return $categories;
+}
+
+
+function fix_course_sortorder($categoryid, $sort="sortorder ASC") {
+/// Given a category object, this function makes sure the courseorder
+/// variable reflects the real world.
+
+ if (!$courses = get_records("course", "category", "$categoryid", "$sort", "id, sortorder")) {
+ return true;
+ }
+
+ $count = 0;
+ $modified = false;
+
+ foreach ($courses as $course) {
+ if ($course->sortorder != $count) {
+ set_field("course", "sortorder", $count, "id", $course->id);
+ $modified = true;
+ }
+ $count++;
+ }
+
+ if ($modified) {
+ set_field("course_categories", "timemodified", time(), "id", $categoryid);
+ }
+
+ return true;
+}
+
+function make_default_scale() {
+/// This function creates a default separated/connected scale
+/// so there's something in the database. The locations of
+/// strings and files is a bit odd, but this is because we
+/// need to maintain backward compatibility with many different
+/// existing language translations and older sites.
+
+ global $CFG;
+
+ $defaultscale = NULL;
+ $defaultscale->courseid = 0;
+ $defaultscale->userid = 0;
+ $defaultscale->name = get_string("separateandconnected");
+ $defaultscale->scale = get_string("postrating1", "forum").",".
+ get_string("postrating2", "forum").",".
+ get_string("postrating3", "forum");
+ $defaultscale->timemodified = time();
+
+ /// Read in the big description from the file. Note this is not
+ /// HTML (despite the file extension) but Moodle format text.
+ $parentlang = get_string("parentlang");
+ if (is_readable("$CFG->dirroot/lang/$CFG->lang/help/forum/ratings.html")) {
+ $file = file("$CFG->dirroot/lang/$CFG->lang/help/forum/ratings.html");
+ } else if ($parentlang and is_readable("$CFG->dirroot/lang/$parentlang/help/forum/ratings.html")) {
+ $file = file("$CFG->dirroot/lang/$parentlang/help/forum/ratings.html");
+ } else if (is_readable("$CFG->dirroot/lang/en/help/forum/ratings.html")) {
+ $file = file("$CFG->dirroot/lang/en/help/forum/ratings.html");
+ } else {
+ $file = "";
+ }
+
+ $defaultscale->description = addslashes(implode("", $file));
+
+ if ($defaultscale->id = insert_record("scale", $defaultscale)) {
+ execute_sql("UPDATE {$CFG->prefix}forum SET scale = '$defaultscale->id'");
+ }
+}
+
+function get_scales_menu($courseid=0) {
+/// Returns a menu of all available scales
+/// from the site as well as the given course
+
+ global $CFG;
+
+ $sql = "SELECT id, name FROM {$CFG->prefix}scale
+ WHERE courseid = '0' or courseid = '$courseid'
+ ORDER BY courseid ASC, name ASC";
+
+ if ($scales = get_records_sql_menu("$sql")) {
+ return $scales;
+ }
+
+ make_default_scale();
+
+ return get_records_sql_menu("$sql");
+}
+
/// MODULE FUNCTIONS /////////////////////////////////////////////////
function get_course_mods($courseid) {
diff --git a/lib/db/mysql.php b/lib/db/mysql.php
index 3f37f322dd4..3a597c3e9ed 100644
--- a/lib/db/mysql.php
+++ b/lib/db/mysql.php
@@ -440,6 +440,28 @@ function main_upgrade($oldversion=0) {
table_column("course", "format", "format", "varchar", "10", "", "topics");
}
+ if ($oldversion < 2003081500) {
+ print_simple_box("Some important changes have been made to how course creators work. Formerly, they could create new courses and assign teachers, and teachers could edit courses. Now, ordinary teachers can no longer edit courses - they need to be a teacher of a course AND a course creator. A new site-wide configuration variable allows you to choose whether to allow course creators to create new courses as well (by default this is off). ";
if ($adminediting) {
- echo "wwwroot/$CFG->admin/teacher.php?id=$course->id\"> wwwroot/course/teacher.php?id=$course->id\">
";
echo "id\">
";
@@ -311,7 +311,7 @@
} else if (isteacher($course->id)) {
echo "
";
- echo "wwwroot/$CFG->admin/teacher.php?id=$course->id\"> ";
diff --git a/course/edit.php b/course/edit.php
index d2e3be879a5..fc1f7423f62 100644
--- a/course/edit.php
+++ b/course/edit.php
@@ -66,7 +66,7 @@
add_to_log($newcourseid, "course", "new", "view.php?id=$newcourseid", "");
if (isadmin()) { // Redirect admin to add teachers
- redirect("../$CFG->admin/teacher.php?id=$newcourseid", get_string("changessaved"));
+ redirect("teacher.php?id=$newcourseid", get_string("changessaved"));
} else { // Add current teacher and send to course
diff --git a/course/lib.php b/course/lib.php
index f8d9e8999a7..caa2327dec8 100644
--- a/course/lib.php
+++ b/course/lib.php
@@ -742,19 +742,32 @@ function print_course_admin_links($course, $width=180) {
$modpixpath = "$CFG->wwwroot/theme/$CFG->theme/pix/mod";
}
if (isteacher($course->id)) {
- $adminicon[]="wwwroot/course/teacher.php?id=$course->id\">
";
}
echo "
";
- if (isediting($course->id)) {
- $admindata[]="id&edit=off\">".get_string("turneditingoff")."";
- } else {
- $admindata[]="id&edit=on\">".get_string("turneditingon")."";
+ if (iscreator()) {
+ $adminicon[]="
";
+ if (isediting($course->id)) {
+ $admindata[]="id&edit=off\">".get_string("turneditingoff")."";
+ } else {
+ $admindata[]="id&edit=on\">".get_string("turneditingon")."";
+ }
+ $admindata[]="id\">".get_string("settings")."...";
+ $adminicon[]="
";
+ if (!$course->teachers) {
+ $course->teachers = get_string("defaultcourseteachers");
+ }
+ $admindata[]="id\">$course->teachers...";
+ $adminicon[]="
";
+
+ $admindata[]="wwwroot/backup/backup.php?id=$course->id\">".get_string("backup")."...";
+ $adminicon[]="
";
+
+ //Only showed if "backupdata" dir exists
+ if (is_dir("$CFG->dataroot/$course->id/backupdata")) {
+ $admindata[]="wwwroot/files/index.php?id=$course->id&wdir=/backupdata\">".get_string("restore")."...";
+ $adminicon[]="
";
+ }
+ $admindata[]="id\">".get_string("scales")."...";
+ $adminicon[]="
";
}
- $admindata[]="id\">".get_string("settings")."...";
- $adminicon[]="
";
- if (!$course->teachers) {
- $course->teachers = get_string("defaultcourseteachers");
- }
- $admindata[]="id\">$course->teachers...";
- $adminicon[]="
";
$admindata[]="id\">".get_string("grades")."...";
$adminicon[]="
";
@@ -765,14 +778,6 @@ function print_course_admin_links($course, $width=180) {
$admindata[]="wwwroot/files/index.php?id=$course->id\">".get_string("files")."...";
$adminicon[]="
";
- $admindata[]="wwwroot/backup/backup.php?id=$course->id\">".get_string("backup")."...";
- $adminicon[]="
";
-
- //Only showed if "backupdata" dir exists
- if (is_dir("$CFG->dataroot/$course->id/backupdata")) {
- $admindata[]="wwwroot/files/index.php?id=$course->id&wdir=/backupdata\">".get_string("restore")."...";
- $adminicon[]="
";
- }
$admindata[]="wwwroot/doc/view.php?id=$course->id&file=teacher.html\">".get_string("help")."...";
$adminicon[]="
";
diff --git a/admin/teacher.php b/course/teacher.php
similarity index 52%
rename from admin/teacher.php
rename to course/teacher.php
index f2bb4e498cf..c67042aac57 100644
--- a/admin/teacher.php
+++ b/course/teacher.php
@@ -10,18 +10,19 @@
optional_variable($remove, "");
optional_variable($search, ""); // search string
- if (! $site = get_site()) {
- redirect("$CFG->wwwroot/$CFG->admin/index.php");
- }
-
require_login();
- if (!iscreator()) {
+ if (! $course = get_record("course", "id", $id)) {
+ error("Course ID was incorrect (can't find it)");
+ }
+
+ if (!iscreator() and isteacher($course->id)) {
error("You must be an administrator or course creator to use this page.");
}
$strassignteachers = get_string("assignteachers");
$strcourses = get_string("courses");
+ $strteachers = get_string("teachers");
$stradministration = get_string("administration");
$strexistingteachers = get_string("existingteachers");
$strnoexistingteachers = get_string("noexistingteachers");
@@ -40,32 +41,63 @@
$searchstring = $strsearch;
}
-
- if (! $course = get_record("course", "id", $id)) {
- error("Course ID was incorrect (can't find it)");
+ if ($course->teachers != $strteachers) {
+ $parateachers = " ($course->teachers)";
+ } else {
+ $parateachers = "";
}
- print_header("$site->shortname: $course->shortname: $strassignteachers",
- "$site->fullname",
- "$strcourses -> ".
- "id\">$course->fullname -> ".
+
+/// Print headers
+
+ print_header("$course->shortname: $strassignteachers",
+ "$course->fullname",
+ "$strcourses -> ".
+ "id\">$course->shortname -> ".
"$strassignteachers", "");
- print_heading("wwwroot/course/view.php?id=$course->id\">$course->fullname ($course->shortname)");
+
+/// If data submitted, then process and store.
+
+ if ($form = data_submitted()) {
+ $rank = array();
+
+ // Peel out all the data from variable names.
+ foreach ($form as $key => $val) {
+ if ($key <> "id") {
+ $type = substr($key,0,1);
+ $num = substr($key,1);
+ $rank[$num][$type] = $val;
+ }
+ }
+
+ foreach ($rank as $num => $vals) {
+ if (! $teacher = get_record("user_teachers", "course", "$course->id", "userid", "$num")) {
+ error("No such teacher in course $course->shortname with user id $num");
+ }
+ $teacher->role = $vals['r'];
+ $teacher->authority = $vals['a'];
+ if (!update_record("user_teachers", $teacher)) {
+ error("Could not update teacher entry id = $teacher->id");
+ }
+ }
+ redirect("teacher.php?id=$course->id", get_string("changessaved"));
+ }
/// Get all existing teachers for this course.
$teachers = get_course_teachers($course->id);
+
/// Add a teacher if one is specified
- if (!empty($add)) {
+ if (!empty($_GET['add'])) {
if (!isteacher($course->id)){
error("You must be an administrator or teacher to modify this course.");
}
- if (! $user = get_record("user", "id", $add)) {
+ if (! $user = get_record("user", "id", $_GET['add'])) {
error("That teacher (id = $add) doesn't exist", "teacher.php?id=$course->id");
}
@@ -88,17 +120,19 @@
if (empty($teacher->id)) {
error("Could not add that teacher to this course!");
}
+ $user->authority = $teacher->authority;
$teachers[] = $user;
+
}
/// Remove a teacher if one is specified.
- if (!empty($remove)) {
+ if (!empty($_GET['remove'])) {
if (!isteacher($course->id)){
error("You must be an administrator or teacher to modify this course.");
}
- if (! $user = get_record("user", "id", $remove)) {
+ if (! $user = get_record("user", "id", $_GET['remove'])) {
error("That teacher (id = $remove) doesn't exist", "teacher.php?id=$course->id");
}
if (!empty($teachers)) {
@@ -111,35 +145,59 @@
}
}
+ print_heading_with_help("$strexistingteachers $parateachers", "teachers");
-/// Print the lists of existing and potential teachers
-
- echo "
";
- echo "
";
+ echo " ";
- echo "$strexistingteachers $strpotentialteachers ";
-
-/// First, show existing teachers for this course
-
- if (empty($teachers)) {
+ if (empty($teachers)) {
echo "
";
}
- echo "";
/// Print list of potential teachers
+ print_heading("$strpotentialteachers $parateachers");
+
$usercount = get_users(false, $search, true, $teacherlist);
if ($usercount == 0) {
@@ -158,24 +216,29 @@
error("Could not get users!");
}
+ unset($table);
+ $table->head = array ("", get_string("name"), get_string("email"), "");
+ $table->align = array ("right", "left", "center", "center");
+ $table->size = array ("35", "", "", "");
+
+
foreach ($users as $user) {
- echo " ";
- print_user_picture($user->id, $site->id, $user->picture, false, false, false);
- echo " $user->firstname $user->lastname, $user->email";
+ $addlink = "id&add=$user->id\">$straddteacher";
+ $picture = print_user_picture($user->id, $course->id, $user->picture, false, true);
+ $table->data[] = array ($picture, "$user->firstname $user->lastname", $user->email, $addlink);
}
+ print_table($table);
}
if ($search or $usercount > MAX_USERS_PER_PAGE) {
- echo "
";
+ link_to_popup_window ("/course/scales.php?id=$courseid&list=true", "ratingscales",
+ $linkobject, 400, 500, $strscales);
+}
+
+function print_scale_menu_helpbutton($courseid, $scale) {
+/// Prints a help button about a scale
+/// scale is an object
+
+ global $CFG, $THEME;
+
+ $strscales = get_string("scales");
+ if (empty($THEME->custompix)) {
+ $helpicon = "$CFG->wwwroot/pix/help.gif";
+ } else {
+ $helpicon = "$CFG->wwwroot/theme/$CFG->theme/pix/help.gif";
+ }
+ $linkobject = "
name\" src=\"$helpicon\">";
+ link_to_popup_window ("/course/scales.php?id=$courseid&list=true&scale=$scale->id", "ratingscale",
+ $linkobject, 400, 500, $scale->name);
+}
+
+
function error ($message, $link="") {
global $CFG, $SESSION;
diff --git a/mod/forum/db/mysql.php b/mod/forum/db/mysql.php
index 347849df963..4f8655093e7 100644
--- a/mod/forum/db/mysql.php
+++ b/mod/forum/db/mysql.php
@@ -61,6 +61,16 @@ function forum_upgrade($oldversion) {
if ($oldversion < 2003042402) {
execute_sql("INSERT INTO {$CFG->prefix}log_display VALUES ('forum', 'move discussion', 'forum_discussions', 'name')");
}
+
+ if ($oldversion < 2003081300) {
+ table_column("forum", "assessed", "assessed", "integer", "10", "unsigned", "0");
+ table_column("forum", "", "scale", "integer", "10", "unsigned", "0", "", "assessed");
+ }
+
+ if ($oldversion < 2003081403) {
+ get_scales_menu(); /// This function will create a new default scale
+ }
+
return true;
}
diff --git a/mod/forum/db/mysql.sql b/mod/forum/db/mysql.sql
index e5bda210d49..730cf625c41 100644
--- a/mod/forum/db/mysql.sql
+++ b/mod/forum/db/mysql.sql
@@ -9,7 +9,8 @@ CREATE TABLE prefix_forum (
name varchar(255) NOT NULL default '',
intro text NOT NULL,
open tinyint(2) unsigned NOT NULL default '2',
- assessed tinyint(1) unsigned NOT NULL default '0',
+ assessed int(10) unsigned NOT NULL default '0',
+ scale int(10) unsigned NOT NULL default '0',
forcesubscribe tinyint(1) unsigned NOT NULL default '0',
timemodified int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id),
diff --git a/mod/forum/db/postgres7.php b/mod/forum/db/postgres7.php
index 71e4f6700f1..87546f205ed 100644
--- a/mod/forum/db/postgres7.php
+++ b/mod/forum/db/postgres7.php
@@ -10,6 +10,10 @@ function forum_upgrade($oldversion) {
execute_sql("INSERT INTO {$CFG->prefix}log_display VALUES ('forum', 'move discussion', 'forum_discussions', 'name')");
}
+ if ($oldversion < 2003081300) {
+ table_column("forum", "", "scale", "integer", "10", "unsigned", "0", "", "assessed");
+ }
+
return true;
}
diff --git a/mod/forum/db/postgres7.sql b/mod/forum/db/postgres7.sql
index 90ca99219aa..1cfad41b887 100644
--- a/mod/forum/db/postgres7.sql
+++ b/mod/forum/db/postgres7.sql
@@ -10,6 +10,7 @@ CREATE TABLE prefix_forum (
intro text NOT NULL default '',
open integer NOT NULL default '2',
assessed integer NOT NULL default '0',
+ scale integer NOT NULL default '0',
forcesubscribe integer NOT NULL default '0',
timemodified integer NOT NULL default '0'
);
diff --git a/mod/forum/discuss.php b/mod/forum/discuss.php
index a5f24a3fce3..415ff154835 100644
--- a/mod/forum/discuss.php
+++ b/mod/forum/discuss.php
@@ -89,6 +89,9 @@
"$navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm));
}
+ echo "
";
if (isset($discussionmoved)) {
notify(get_string("discussionmoved", "forum", $forum->name));
diff --git a/mod/forum/lib.php b/mod/forum/lib.php
index 162e194ba12..f68c8ff014c 100644
--- a/mod/forum/lib.php
+++ b/mod/forum/lib.php
@@ -405,7 +405,6 @@ function forum_print_recent_instance_activity($forum, $timestart, $detail=false)
function forum_grades($forumid) {
/// Must return an array of grades, indexed by user, and a max grade.
- global $FORUM_POST_RATINGS;
if (!$forum = get_record("forum", "id", $forumid)) {
return false;
@@ -413,19 +412,33 @@ function forum_grades($forumid) {
if (!$forum->assessed) {
return false;
}
+ if (!$scale = get_record("scale", "id", $forum->scale)) {
+ return false;
+ }
+ $scalemenu = make_menu_from_list($scale->scale);
+
+ $currentuser = 0;
+ $ratingsuser = array();
+
if ($ratings = forum_get_user_grades($forumid)) {
- foreach ($ratings as $rating) {
- $u = $rating->userid;
- $r = $rating->rating;
- if (!isset($sumrating[$u])) {
- $sumrating[$u][1] = 0;
- $sumrating[$u][2] = 0;
- $sumrating[$u][3] = 0;
+ foreach ($ratings as $rating) { // Ordered by user
+ if ($currentuser and $rating->userid != $currentuser) {
+ if (!empty($ratingsuser)) {
+ $return->grades[$currentuser] = forum_get_ratings_median(0, $scalemenu, $ratingsuser);
+ $return->grades[$currentuser] .= " ";
+ forum_print_mode_form($discussion->id, $mode);
+ echo " ";
if (isteacher($course->id)) { // Popup menu to allow discussions to be moved to other forums
if ($forums = get_all_instances_in_course("forum", $course)) {
foreach ($forums as $courseforum) {
@@ -105,6 +108,7 @@
}
}
}
+ echo "
".forum_get_ratings_summary(0, $scalemenu, $ratingsuser);
+ } else {
+ $return->grades[$currentuser] = "";
+ }
+ $ratingsuser = array();
}
- $sumrating[$u][$r]++;
+ $ratingsuser[] = $rating->rating;
+ $currentuser = $rating->userid;
}
- foreach ($sumrating as $user => $rating) {
- $return->grades[$user] = $rating[1]."s/".$rating[2]."/".$rating[3]."c";
+ if (!empty($ratingsuser)) {
+ $return->grades[$currentuser] = forum_get_ratings_median(0, $scalemenu, $ratingsuser);
+ $return->grades[$currentuser] .= "
".forum_get_ratings_summary(0, $scalemenu, $ratingsuser);
+ } else {
+ $return->grades[$currentuser] = "";
}
} else {
$return->grades = array();
@@ -631,7 +644,8 @@ function forum_get_user_grades($forumid) {
{$CFG->prefix}forum_ratings r
WHERE d.forum = '$forumid'
AND p.discussion = d.id
- AND r.post = p.id");
+ AND r.post = p.id
+ ORDER by p.userid ");
}
@@ -945,7 +959,7 @@ function forum_make_mail_post(&$post, $user, $touser, $course,
}
-function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link=false, $rate=false, $footer="", $highlight="") {
+function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link=false, $ratings=NULL, $footer="", $highlight="") {
global $THEME, $USER, $CFG;
echo "id\">";
@@ -1025,16 +1039,16 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
echo "
"; - if ($rate && $USER->id) { + if (!empty($ratings) and !empty($USER->id)) { if (isteacher($courseid)) { - forum_print_ratings($post->id); + forum_print_ratings_median($post->id, $ratings->scale); if ($USER->id != $post->userid) { - forum_print_rating($post->id, $USER->id); + forum_print_rating_menu($post->id, $USER->id, $ratings->scale); } } else if ($USER->id == $post->userid) { - forum_print_ratings($post->id); - } else { - forum_print_rating($post->id, $USER->id); + forum_print_ratings_median($post->id, $ratings->scale); + } else if (!empty($ratings->allow) ) { + forum_print_rating_menu($post->id, $USER->id, $ratings->scale); } } @@ -1142,33 +1156,106 @@ function forum_shorten_post($message) { } -function forum_print_ratings($post) { - if ($ratings = get_records("forum_ratings", "post", $post)) { - $sumrating[1] = 0; - $sumrating[2] = 0; - $sumrating[3] = 0; - foreach ($ratings as $rating) { - $sumrating[$rating->rating]++; - } - $summary = $sumrating[1]."s/".$sumrating[2]."/".$sumrating[3]."c"; +function forum_print_ratings_median($postid, $scale) { +/// Print the multiple ratings on a post given to the current user by others. +/// Scale is an array of ratings - echo get_string("ratings", "forum").": "; - link_to_popup_window ("/mod/forum/report.php?id=$post", "ratings", $summary, 400, 550); + static $strrate; + + if ($median = forum_get_ratings_median($postid, $scale)) { + + if (empty($strratings)) { + $strratings = get_string("ratings", "forum"); + } + + echo "$strratings: "; + link_to_popup_window ("/mod/forum/report.php?id=$postid", "ratings", $median, 400, 600); } } -function forum_print_rating($post, $user) { - global $FORUM_POST_RATINGS; - if ($rating = get_record("forum_ratings", "userid", $user, "post", $post)) { - if ($FORUM_POST_RATINGS[$rating->rating]) { - echo "".get_string("youratedthis", "forum").": "; - echo $FORUM_POST_RATINGS[$rating->rating]; - echo ""; - return; +function forum_get_ratings_median($postid, $scale, $ratings=NULL) { +/// Return the median rating of a post given to the current user by others. +/// Scale is an array of possible ratings in the scale +/// Ratings is an optional simple array of actual ratings (just integers) + + if (!$ratings) { + $ratings = array(); + if ($rates = get_records("forum_ratings", "post", $postid)) { + foreach ($rates as $rate) { + $ratings[] = $rate->rating; + } } } - choose_from_menu($FORUM_POST_RATINGS, $post, "", get_string("rate", "forum")."..."); + + if (!$count = count($ratings)) { + return ""; + } + + sort($ratings, SORT_NUMERIC); + + if ($count == 1) { + return $scale[$ratings[0]]." (1)"; + } else { + $median = $ratings[ceil($count/2)]; + return $scale[$median]." ($count)"; + } +} + +function forum_get_ratings_summary($postid, $scale, $ratings=NULL) { +/// Return a summary of post ratings given to the current user by others. +/// Scale is an array of possible ratings in the scale +/// Ratings is an optional simple array of actual ratings (just integers) + + if (!$ratings) { + $ratings = array(); + if ($rates = get_records("forum_ratings", "post", $postid)) { + foreach ($rates as $rate) { + $rating[] = $rate->rating; + } + } + } + + + if (!$count = count($ratings)) { + return ""; + } + + + foreach ($scale as $key => $scaleitem) { + $sumrating[$key] = 0; + } + + foreach ($ratings as $rating) { + $sumrating[$rating]++; + } + + $summary = ""; + foreach ($scale as $key => $scaleitem) { + $summary = $sumrating[$key].$summary; + if ($key > 1) { + $summary = "/$summary"; + } + } + return $summary; +} + +function forum_print_rating_menu($postid, $userid, $scale) { +/// Print the menu of ratings as part of a larger form. +/// If the post has already been - set that value. +/// Scale is an array of ratings + + static $strrate; + + if (!$rating = get_record("forum_ratings", "userid", $userid, "post", $postid)) { + $rating->rating = 0; + } + + if (empty($strrate)) { + $strrate = get_string("rate", "forum"); + } + + choose_from_menu($scale, $postid, $rating->rating, "$strrate..."); } function forum_print_mode_form($discussion, $mode) { @@ -1772,50 +1859,49 @@ function forum_print_discussion($course, $forum, $discussion, $post, $mode) { } $reply = forum_user_can_post($forum); - forum_print_post($post, $course->id, $ownpost, $reply, $link=false, $rate=false); - - forum_print_mode_form($discussion->id, $mode); - - $ratingform = false; + $ratings = NULL; if ($forum->assessed and !empty($USER->id)) { - $unrated = forum_count_unrated_posts($discussion->id, $USER->id); - if ($unrated > 0) { - $ratingform = true; + if ($scale = get_record("scale", "id", $forum->scale)) { + $ratings->scale = make_menu_from_list($scale->scale); + if ($forum->assessed == 2 and !isteacher($course->id)) { + $ratings->allow = false; + } else { + $ratings->allow = true; + } + echo "
"; + if ($ratings) { + echo ":
:
"; + print_string("scale"); + echo ": "; + print_scale_menu($course->id, "scale", $form->scale); + echo "
"; + ?>:
"; - echo " | id&sort=u.firstname>Name"; - echo " | id&sort=r.rating>Rating"; - echo " | id&sort=r.time>Date";
+ echo "
|
---|