From 7b5944cdb30153d5bb31a394a42954a52fbc55e1 Mon Sep 17 00:00:00 2001 From: gustav_delius <gustav_delius> Date: Sun, 29 Aug 2004 19:17:27 +0000 Subject: [PATCH] Can now force subscribe INITIALLY, implementing suggestion by Howard in bug 1084 --- lang/en/forum.php | 2 ++ lib/moodlelib.php | 8 +++----- mod/forum/lib.php | 15 ++++++++------- mod/forum/mod.html | 5 +++-- mod/forum/post.html | 2 +- mod/forum/subscribe.php | 4 ++-- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lang/en/forum.php b/lang/en/forum.php index 8ef3c04200..a5f51c5ab4 100644 --- a/lang/en/forum.php +++ b/lang/en/forum.php @@ -150,6 +150,8 @@ $string['subscriptions'] = 'Subscriptions'; $string['unsubscribe'] = 'Unsubscribe from this forum'; $string['unsubscribed'] = 'Unsubscribed'; $string['unsubscribeshort'] = 'Unsubscribe'; +$string['yesinitially'] = 'Yes, initially'; +$string['yesforever'] = 'Yes, forever'; $string['youratedthis'] = 'You rated this'; $string['yournewtopic'] = 'Your new discussion topic'; $string['yourreply'] = 'Your reply'; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index d77f565e5e..72dfc073bb 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -879,6 +879,7 @@ function unenrol_student($userid, $courseid=0) { function add_teacher($userid, $courseid, $editall=1, $role="", $timestart=0, $timeend=0) { /// Add a teacher to a given course + global $CFG; if ($teacher = get_record('user_teachers', 'userid', $userid, 'course', $courseid)) { $newteacher = NULL; @@ -918,11 +919,8 @@ function add_teacher($userid, $courseid, $editall=1, $role="", $timestart=0, $ti delete_records("user_students", "userid", $userid, "course", $courseid); // Unenrol as student /// Add forum subscriptions for new users - if ($forums = get_records('forum', 'course', $courseid, 'forcesubscribe', 2)) { - foreach ($forums as $forum) { - forum_subscribe($userid, $forum->id); - } - } + require_once('../mod/forum/lib.php'); + forum_add_user($userid, $courseid); return insert_record("user_teachers", $teacher); diff --git a/mod/forum/lib.php b/mod/forum/lib.php index cc5754b1fd..8b7e688c99 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -1214,14 +1214,10 @@ function forum_subscribed_users($course, $forum, $groupid=0) { } if (forum_is_forcesubscribed($forum->id)) { - if ($course->category) { - if ($forum->type == "teacher") { - return get_course_teachers($course->id); // Only teachers can be subscribed to teacher forums - } else { - return get_course_users($course->id); // Otherwise get everyone in the course - } + if ($forum->type == "teacher") { + return get_course_teachers($course->id); // Only teachers can be subscribed to teacher forums } else { - return get_site_users(); + return get_course_users($course->id); // Otherwise get everyone in the course } } return get_records_sql("SELECT u.id, u.username, u.firstname, u.lastname, u.maildisplay, u.mailformat, u.maildigest, u.emailstop, @@ -2849,6 +2845,11 @@ function forum_add_user($userid, $courseid) { forum_subscribe($userid, $forum->id); } } + if ($forums = get_records_select('forum', "course = '".SITEID."' AND forcesubscribe = '2'")) { + foreach ($forums as $forum) { + forum_subscribe($userid, $forum->id); + } + } } ?> diff --git a/mod/forum/mod.html b/mod/forum/mod.html index 35217c4672..12ef1e2bec 100644 --- a/mod/forum/mod.html +++ b/mod/forum/mod.html @@ -106,9 +106,10 @@ <?php unset($options); $options[0] = get_string("no"); - $options[1] = get_string("yes"); + $options[1] = get_string('yesforever', 'forum'); + $options[FORUM_INITIALSUBSCRIBE] = get_string('yesinitially', 'forum'); choose_from_menu($options, "forcesubscribe", $form->forcesubscribe, ""); - helpbutton("subscription", get_string("forcesubscribeq", "forum"), "forum"); + helpbutton("subscription2", get_string("forcesubscribeq", "forum"), "forum"); ?> </td> </tr> diff --git a/mod/forum/post.html b/mod/forum/post.html index 9391f6e32b..398b0bc7e9 100644 --- a/mod/forum/post.html +++ b/mod/forum/post.html @@ -59,7 +59,7 @@ <td align=right><p><b><?php print_string("subscription", "forum") ?>:</b></p></td> <td> <?php - if ($forum->forcesubscribe) { + if (forum_is_forcesubscribed($forum->id)) { print_string("everyoneissubscribed", "forum"); } else { unset($options); diff --git a/mod/forum/subscribe.php b/mod/forum/subscribe.php index 84704423d0..de9ece0a7e 100644 --- a/mod/forum/subscribe.php +++ b/mod/forum/subscribe.php @@ -7,10 +7,10 @@ require_variable($id); // The forum to subscribe or unsubscribe to optional_variable($force); // Force everyone to be subscribed to this forum? - optional_variable($user); // Force everyone to be subscribed to this forum? + optional_variable($user); if (isguest()) { - error("Guests are not allowed to subscribe to posts.", $_SERVER["HTTP_REFERER"]); + error("Guests are not allowed to subscribe to forums.", $_SERVER["HTTP_REFERER"]); } if (! $forum = get_record("forum", "id", $id)) { -- 2.39.5