From: moodler Date: Fri, 15 Aug 2003 13:59:24 +0000 (+0000) Subject: WARNING: BIG CHANGES! X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=02ebf404c8ce01916ad158d24b41e25e7cd3b492;p=moodle.git WARNING: BIG CHANGES! OK, this is a big check-in with some big changes, and needs work still. It seems relatively stable, but I need help identifying the rough patches. 1) First grading scales support. There is a now a new table called "scale" that contains grading scales. There can be site scales (course=0) and custom course scales. These can be used in modules - I've only done forums for now but that was the hard one. Scales can be edited via the new item in the course admin menu. There is one default scale - the connected/separate knowing one that used to be in forum. To build this I pull data from the language packs to create one during the upgrade, or anytime a scales menu is called and no scales are found. 2) New roles for course creator and teachers. I've fixed up the course menus and some other things but there's a lot left to do on this to make it all smooth. The idea is that teachers no longer can edit courses unless they are also course creators. The interface for this needs to be smoothed out a fair bit and I need help with this. The upgrade will upgrade all teachers to be creators, but will default the new site config "creatornewcourses" to "no", so that effectively these new teachers have the same privileges. 3) Simplified teacher management. There is no longer an "assign teachers" and a "teacher roles" page - it's all on one page in course/teacher.html. Phew ... time for a shower and then back into it. --- diff --git a/admin/config.html b/admin/config.html index c9ca73f39e..a78344a60b 100644 --- a/admin/config.html +++ b/admin/config.html @@ -300,6 +300,22 @@ + +

creatornewcourse: + + creatornewcourse, "", "", ""); + ?> + + + + + + diff --git a/course/category.php b/course/category.php index 92370d0d1c..137976f3e2 100644 --- a/course/category.php +++ b/course/category.php @@ -267,7 +267,7 @@ if ($creatorediting) { echo ""; 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\">wwwroot/course/teacher.php?id=$course->id\"> "; } echo ""; diff --git a/course/edit.php b/course/edit.php index d2e3be879a..fc1f7423f6 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 f8d9e8999a..caa2327dec 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[]="\"\""; - 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"); + 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\">$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 f2bb4e498c..c67042aac5 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 "
$strexistingteachers$strpotentialteachers
"; - -/// First, show existing teachers for this course - - if (empty($teachers)) { + if (empty($teachers)) { echo "

$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 "

"; foreach ($teachers as $teacher) { $teacherarray[] = $teacher->id; - echo "

$teacher->firstname $teacher->lastname, $teacher->email  "; - print_user_picture($teacher->id, $site->id, $teacher->picture, false, false, false); - echo "  id&remove=$teacher->id\" title=\"$strremoveteacher\">

"; + + $picture = print_user_picture($teacher->id, $course->id, $teacher->picture, false, true); + + $authority = choose_from_menu ($option, "a$teacher->id", $teacher->authority, "", "", "", true); + + $removelink = "id&remove=$teacher->id\">$strremoveteacher"; + + if (!$teacher->role) { + $teacher->role = $course->teacher; + } + + $table->data[] = array ($picture, "$teacher->firstname $teacher->lastname", $authority, + "id\" value=\"$teacher->role\" size=30>", + $removelink); } $teacherlist = implode(",",$teacherarray); unset($teacherarray); + + print_table($table); + echo "id\">"; + echo "
"; + echo "
"; + echo "
"; + 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 "

id&add=$user->id\"". - "title=\"$straddteacher\">  "; - 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 "

"; + echo ""; echo "id\">"; echo ""; echo ""; echo "
"; } - echo "
"; + echo ""; print_footer(); diff --git a/course/teachers.php b/course/teachers.php deleted file mode 100644 index b065d56f90..0000000000 --- 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 "

"; - foreach ($teachers as $teacher) { - - $picture = print_user_picture($teacher->id, $course->id, $teacher->picture, false, true); - - $authority = choose_from_menu ($option, "a$teacher->id", $teacher->authority, "", "", "", true); - - if (!$teacher->role) { - $teacher->role = $course->teacher; - } - - $table->data[] = array ($picture, "$teacher->firstname $teacher->lastname", $authority, - "id\" VALUE=\"$teacher->role\" SIZE=30>"); - } - print_table($table); - echo "id\">"; - echo "

"; - helpbutton("teachers", $course->teachers); - echo "
"; - echo "
"; - - print_footer($course); - -?> diff --git a/lib/datalib.php b/lib/datalib.php index 4dc94bfaf3..83678de18d 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 3f37f322dd..3a597c3e9e 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).

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 3669c721e1..84245b74c1 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 e150041b54..8662c923f6 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 bf4445a843..b019c8fb6b 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 = "\"$strscales\""; + 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 = "\"$scale-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 347849df96..4f8655093e 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 e5bda210d4..730cf625c4 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 71e4f6700f..87546f205e 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 90ca99219a..1cfad41b88 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 a5f24a3fce..415ff15483 100644 --- a/mod/forum/discuss.php +++ b/mod/forum/discuss.php @@ -89,6 +89,9 @@ "$navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm)); } + echo "
 "; + 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 "
"; if (isset($discussionmoved)) { notify(get_string("discussionmoved", "forum", $forum->name)); diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 162e194ba1..f68c8ff014 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_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 "

"; 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]++; +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 + + static $strrate; + + if ($median = forum_get_ratings_median($postid, $scale)) { + + if (empty($strratings)) { + $strratings = get_string("ratings", "forum"); } - $summary = $sumrating[1]."s/".$sumrating[2]."/".$sumrating[3]."c"; - echo get_string("ratings", "forum").": "; - link_to_popup_window ("/mod/forum/report.php?id=$post", "ratings", $summary, 400, 550); + 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 "

"; + echo "id\">"; } } - if ($ratingform) { - echo ""; - echo "id\">"; - } + forum_print_post($post, $course->id, $ownpost, $reply, $link=false, $ratings); switch ($mode) { case 1 : // Flat ascending case -1 : // Flat descending default: - echo "
    "; - forum_print_posts_flat($post->discussion, $course->id, $mode, $forum->assessed, $reply); - echo "
"; + echo "
    "; + forum_print_posts_flat($post->discussion, $course->id, $mode, $ratings, $reply); + echo "
"; break; case 2 : // Threaded - forum_print_posts_threaded($post->id, $course->id, 0, $forum->assessed, $reply); + forum_print_posts_threaded($post->id, $course->id, 0, $ratings, $reply); break; case 3 : // Nested - forum_print_posts_nested($post->id, $course->id, $forum->assessed, $reply); + forum_print_posts_nested($post->id, $course->id, $ratings, $reply); break; } - if ($ratingform) { - echo "

"; - helpbutton("ratings", get_string("separateandconnected"), "forum"); - echo "

"; - echo "
"; + if ($ratings) { + echo "
"; + print_scale_menu_helpbutton($course->id, $scale); + echo "
"; + echo ""; } } -function forum_print_posts_flat($discussion, $course, $direction, $assessed, $reply) { +function forum_print_posts_flat($discussion, $course, $direction, $ratings, $reply) { global $USER; $link = false; @@ -1829,14 +1915,14 @@ function forum_print_posts_flat($discussion, $course, $direction, $assessed, $re if ($posts = forum_get_discussion_posts($discussion, $sort)) { foreach ($posts as $post) { $ownpost = ($USER->id == $post->userid); - forum_print_post($post, $course, $ownpost, $reply, $link, $assessed); + forum_print_post($post, $course, $ownpost, $reply, $link, $ratings); } } else { return; } } -function forum_print_posts_threaded($parent, $course, $depth, $assessed, $reply) { +function forum_print_posts_threaded($parent, $course, $depth, $ratings, $reply) { global $USER; $link = false; @@ -1847,7 +1933,7 @@ function forum_print_posts_threaded($parent, $course, $depth, $assessed, $reply) echo "\n"; } } else { @@ -1865,7 +1951,7 @@ function forum_print_posts_threaded($parent, $course, $depth, $assessed, $reply) } } -function forum_print_posts_nested($parent, $course, $assessed, $reply) { +function forum_print_posts_nested($parent, $course, $ratings, $reply) { global $USER; $link = false; @@ -1880,9 +1966,9 @@ function forum_print_posts_nested($parent, $course, $assessed, $reply) { } echo "\n"; } } else { diff --git a/mod/forum/mod.html b/mod/forum/mod.html index 6df4c01afe..449a7f08f4 100644 --- a/mod/forum/mod.html +++ b/mod/forum/mod.html @@ -75,19 +75,29 @@ open, ""); helpbutton("allowdiscussions", get_string("allowdiscussions", - "forum", strtolower("$course->student")), "forum"); + "forum", moodle_strtolower("$course->student")), "forum"); ?> -

:

+

:

teachers)); + $options[1] = get_string("ratingeveryone", "forum"); + choose_from_menu($options, "assessed", $form->assessed, ""); helpbutton("ratings", get_string("allowratings", "forum"), "forum"); + echo "

"; + print_string("scale"); + echo ": "; + print_scale_menu($course->id, "scale", $form->scale); + echo "

"; + ?> @@ -95,6 +105,9 @@

:

forcesubscribe, ""); helpbutton("subscription", get_string("forcesubscribeq", "forum"), "forum"); ?> diff --git a/mod/forum/rate.php b/mod/forum/rate.php index 7ff53c035c..e91c43ec30 100644 --- a/mod/forum/rate.php +++ b/mod/forum/rate.php @@ -24,20 +24,24 @@ if ($post == "id") { continue; } - if ($rating) { - if (record_exists("forum_ratings", "userid", $USER->id, "post", $post)) { - error("You've rated this question before ($post)"); - } else { - unset($newrating); - $newrating->userid = $USER->id; - $newrating->time = time(); - $newrating->post = $post; - $newrating->rating = $rating; - - if (! insert_record("forum_ratings", $newrating)) { - error("Could not insert a new rating ($post = $rating)"); + if ($oldrating = get_record("forum_ratings", "userid", $USER->id, "post", $post)) { + if ($rating != $oldrating->rating) { + $oldrating->rating = $rating; + $oldrating->time = time(); + if (! update_record("forum_ratings", $oldrating)) { + error("Could not update an old rating ($post = $rating)"); } } + } else if ($rating) { + unset($newrating); + $newrating->userid = $USER->id; + $newrating->time = time(); + $newrating->post = $post; + $newrating->rating = $rating; + + if (! insert_record("forum_ratings", $newrating)) { + error("Could not insert a new rating ($post = $rating)"); + } } } redirect($_SERVER["HTTP_REFERER"], get_string("ratingssaved", "forum")); diff --git a/mod/forum/report.php b/mod/forum/report.php index 799200e67c..8fd9bbff61 100644 --- a/mod/forum/report.php +++ b/mod/forum/report.php @@ -31,32 +31,44 @@ $sort = "r.time"; } - print_header("Ratings for: $post->subject"); + if (!$scale = get_record("scale", "id", $forum->scale)) { + error("Scale not found!"); + } + + $scalemenu = make_menu_from_list($scale->scale); + + $strratings = get_string("ratings", "forum"); + $strrating = get_string("rating", "forum"); + $strname = get_string("name"); + $strtime = get_string("time"); + + print_header("$strratings: $post->subject"); if (!$ratings = forum_get_ratings($post->id, $sort)) { - echo "No ratings for this post: \"$post->subject\""; - die; + error("No ratings for this post: \"$post->subject\""); + } else { - echo ""; - echo ""; - echo ""; - echo "
 id&sort=u.firstname>Name"; - echo "id&sort=r.rating>Rating"; - echo "id&sort=r.time>Date"; + echo ""; + echo ""; + echo ""; + echo "cellcontent2\">"; + echo "cellcontent2\">"; } else { - echo "cellcontent\">"; + echo "cellcontent\">"; } - echo "\n"; + echo "\n"; } - echo "
 id&sort=u.firstname>$strname"; + echo "id&sort=r.rating>$strrating"; + echo "id&sort=r.time>$strtime"; foreach ($ratings as $rating) { if (isteacher($discussion->course, $rating->id)) { - echo "
"; + echo ""; print_user_picture($rating->id, $forum->course, $rating->picture); - echo "

$rating->firstname $rating->lastname

"; - echo "

".$FORUM_POST_RATINGS[$rating->rating]."

"; - echo "

".userdate($rating->time)."

"; - echo "

$rating->firstname $rating->lastname

"; + echo "

".$scalemenu[$rating->rating]."

"; + echo "

".userdate($rating->time)."

"; + echo "
"; + echo "
"; + echo "
"; } close_window_button(); diff --git a/mod/forum/version.php b/mod/forum/version.php index a30e2d961a..1521d42679 100644 --- a/mod/forum/version.php +++ b/mod/forum/version.php @@ -5,7 +5,7 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2003042402; +$module->version = 2003081403; $module->cron = 60; ?>