For the group functions, a group 0 means everyone
[moodle.git] / mod / forum / view.php
CommitLineData
f93f848a 1<?PHP // $Id$
2
b0e3a925 3 require_once("../../config.php");
4 require_once("lib.php");
f93f848a 5
3c8a606d 6 optional_variable($id); // Course Module ID
7 optional_variable($f); // Forum ID
8 optional_variable($mode); // Display mode (for single forum)
61e96406 9 optional_variable($search, ""); // search string
3c8a606d 10 optional_variable($showall, ""); // show all discussions on one page
9197e147 11 optional_variable($group, ""); // choose the current group
f93f848a 12
09aebc94 13 $strforums = get_string("modulenameplural", "forum");
14 $strforum = get_string("modulename", "forum");
15
f93f848a 16 if ($id) {
17 if (! $cm = get_record("course_modules", "id", $id)) {
18 error("Course Module ID was incorrect");
19 }
20 if (! $course = get_record("course", "id", $cm->course)) {
21 error("Course is misconfigured");
22 }
23 if (! $forum = get_record("forum", "id", $cm->instance)) {
24 error("Forum ID was incorrect");
25 }
09aebc94 26 $buttontext = update_module_button($cm->id, $course->id, $strforum);
f93f848a 27
28 } else if ($f) {
29 if (! $forum = get_record("forum", "id", $f)) {
94361e02 30 error("Forum ID was incorrect or no longer exists");
f93f848a 31 }
32 if (! $course = get_record("course", "id", $forum->course)) {
33 error("Forum is misconfigured - don't know what course it's from");
34 }
d9bf513d 35 if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
09aebc94 36 $buttontext = update_module_button($cm->id, $course->id, $strforum);
d9bf513d 37 } else {
69d79bc3 38 $cm->id = NULL;
d9bf513d 39 $buttontext = "";
40 }
f93f848a 41
42 } else {
43 error("Must specify a course module or a forum ID");
44 }
45
97485d07 46 if (!$buttontext) {
47 $buttontext = forum_print_search_form($course, $search, true, "plain");
48 }
31d160d3 49
f93f848a 50 if ($course->category) {
51 require_login($course->id);
e2c4f8e4 52 $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
53 <a href=\"index.php?id=$course->id\">$strforums</a> ->";
bffb106d 54 } else {
e2c4f8e4 55 $navigation = "<a href=\"index.php?id=$course->id\">$strforums</a> ->";
f93f848a 56 }
57
82aa0e8d 58 if ($forum->type == "teacher") {
59 if (!isteacher($course->id)) {
60 error("You must be a $course->teacher to view this forum");
61 }
62 }
63
e2c4f8e4 64 if ($cm) {
69d79bc3 65 add_to_log($course->id, "forum", "view forum", "view.php?id=$cm->id", "$forum->id", $cm->id);
e2c4f8e4 66 } else {
67 add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id");
68 }
f93f848a 69
70 print_header("$course->shortname: $forum->name", "$course->fullname",
d897cae4 71 "$navigation $forum->name", "", "", true, $buttontext, navmenu($course, $cm));
f93f848a 72
3a4c2fd0 73 if (!$cm->visible and !isteacher($course->id)) {
74 notice(get_string("activityiscurrentlyhidden"));
75 }
76
9197e147 77
78/// Check to see if groups are being used in this forum
79/// and if so, set $currentgroup to reflect the current group
80
81 $groupmode = groupmode($course, $cm); // Groups are being used
82 $currentgroup = get_and_set_current_group($course, $groupmode, $_GET['group']);
83
a33ba136 84 if (!isteacheredit($course->id) and $groupmode and !$currentgroup) {
9197e147 85 print_heading("Sorry, but you need to be part of a group to see this forum.");
86 print_footer();
87 exit;
88 }
89
90
91/// Print settings and things in a table across the top
92
93 echo '<table width="100%" border="0" cellpadding="3" cellspacing="0"><tr valign="top">';
94
95 if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
96 if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
97 echo '<td>';
98
99 echo '<table><tr><td>';
100 if ($groupmode == VISIBLEGROUPS) {
101 print_string('groupsvisible');
102 } else {
103 print_string('groupsseparate');
104 }
105 echo ':';
106 echo '</td><td nowrap="nowrap" align="left" width="50%">';
107 popup_form("view.php?id=$cm->id&group=", $groups, 'selectgroup', $currentgroup, "", "", "", false, "self");
108 echo '</tr></table>';
109
110 echo '</td>';
111 }
112 }
113
114
f93f848a 115 if ($USER) {
9197e147 116 echo '<td align="right">';
501cdbd8 117 $SESSION->fromdiscussion = "$FULLME";
118 if (forum_is_forcesubscribed($forum->id)) {
31d160d3 119 $streveryoneissubscribed = get_string("everyoneissubscribed", "forum");
120 $strallowchoice = get_string("allowchoice", "forum");
c032b59d 121 helpbutton("subscription", $streveryoneissubscribed, "forum");
122 echo "<font size=1>";
501cdbd8 123 if (isteacher($course->id)) {
c032b59d 124 echo "<a title=\"$strallowchoice\" href=\"subscribe.php?id=$forum->id&force=no\">$streveryoneissubscribed</a>";
501cdbd8 125 } else {
c032b59d 126 echo $streveryoneissubscribed;
501cdbd8 127 }
9197e147 128 echo "</font>";
501cdbd8 129
f93f848a 130 } else {
31d160d3 131 $streveryonecanchoose = get_string("everyonecanchoose", "forum");
132 $strforcesubscribe = get_string("forcesubscribe", "forum");
133 $strshowsubscribers = get_string("showsubscribers", "forum");
c032b59d 134
c032b59d 135 helpbutton("subscription", $streveryonecanchoose, "forum");
136 echo "<font size=1>";
137
501cdbd8 138 if (isteacher($course->id)) {
c032b59d 139 echo "<a title=\"$strforcesubscribe\" href=\"subscribe.php?id=$forum->id&force=yes\">$streveryonecanchoose</a>";
9197e147 140 echo "</font><br /><font size=1>";
c032b59d 141 echo "<a href=\"subscribers.php?id=$forum->id\">$strshowsubscribers</a>";
310da166 142 } else {
c032b59d 143 echo $streveryonecanchoose;
501cdbd8 144 }
9197e147 145 echo "</font>";
c032b59d 146
501cdbd8 147 if (forum_is_subscribed($USER->id, $forum->id)) {
6687be17 148 $subtexttitle = get_string("subscribestop", "forum");
31d160d3 149 $subtext = get_string("unsubscribe", "forum");
501cdbd8 150 } else {
6687be17 151 $subtexttitle = get_string("subscribestart", "forum");
31d160d3 152 $subtext = get_string("subscribe", "forum");
501cdbd8 153 }
9197e147 154 echo "<br />";
6687be17 155 echo "<font size=1><a title=\"$subtexttitle\" href=\"subscribe.php?id=$forum->id\">$subtext</a></font>";
bffb106d 156 }
9197e147 157 echo '</td>';
f93f848a 158 }
159
9197e147 160 echo '</tr></table>';
161
f064a3df 162 $forum->intro = trim($forum->intro);
e07635f4 163
164 switch ($forum->type) {
9197e147 165 case 'single':
501cdbd8 166 if (! $discussion = get_record("forum_discussions", "forum", $forum->id)) {
167 if ($discussions = get_records("forum_discussions", "forum", $forum->id, "timemodified ASC")) {
168 notify("Warning! There is more than one discussion in this forum - using the most recent");
169 $discussion = array_pop($discussions);
170 } else {
171 error("Could not find the discussion in this forum");
172 }
173 }
11b0c469 174 if (! $post = forum_get_post_full($discussion->firstpost)) {
501cdbd8 175 error("Could not find the first post in this forum");
176 }
5476a93d 177 if ($mode) {
178 set_user_preference("forum_displaymode", $mode);
179 }
180 $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
181 forum_print_discussion($course, $forum, $discussion, $post, $displaymode);
501cdbd8 182 break;
183
9197e147 184 case 'eachuser':
f064a3df 185 if (!empty($forum->intro)) {
51a55508 186 print_simple_box(format_text($forum->intro), 'center');
c6ee38d0 187 }
9197e147 188 echo '<p align="center">';
11b0c469 189 if (forum_user_can_post_discussion($forum)) {
31d160d3 190 print_string("allowsdiscussions", "forum");
e07635f4 191 } else {
9197e147 192 echo '&nbsp';
e07635f4 193 }
9197e147 194 echo '</p>';
c6ee38d0 195 if (!empty($showall)) {
9197e147 196 forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup);
c6ee38d0 197 } else {
9197e147 198 forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup);
c6ee38d0 199 }
200 break;
201
9197e147 202 case 'teacher':
3c8a606d 203 if (!empty($showall)) {
9197e147 204 forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup);
3c8a606d 205 } else {
9197e147 206 forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup);
3c8a606d 207 }
e07635f4 208 break;
209
210 default:
f064a3df 211 if (!empty($forum->intro)) {
51a55508 212 print_simple_box(format_text($forum->intro), 'center');
c6ee38d0 213 }
9197e147 214 echo '<p>&nbsp;</p>';
3c8a606d 215 if (!empty($showall)) {
9197e147 216 forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup);
3c8a606d 217 } else {
9197e147 218 forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup);
3c8a606d 219 }
e07635f4 220 break;
221 }
222
f93f848a 223
224 print_footer($course);
225
226?>