41905731 |
1 | <?php // $Id$ |
f93f848a |
2 | |
49a0ba94 |
3 | require_once('../../config.php'); |
4 | require_once('lib.php'); |
48b29ba4 |
5 | require_once("$CFG->libdir/rsslib.php"); |
f93f848a |
6 | |
49a0ba94 |
7 | |
8 | $id = optional_param('id', 0, PARAM_INT); // Course Module ID |
9 | $f = optional_param('f', 0, PARAM_INT); // Forum ID |
10 | $mode = optional_param('mode', 0, PARAM_INT); // Display mode (for single forum) |
11 | $showall = optional_param('showall', '', PARAM_INT); // show all discussions on one page |
12 | $changegroup = optional_param('group', -1, PARAM_INT); // choose the current group |
13 | $page = optional_param('page', 0, PARAM_INT); // which page to show |
14 | $search = optional_param('search', ''); // search string |
15 | |
16 | |
f93f848a |
17 | |
18 | if ($id) { |
49a0ba94 |
19 | |
f9d5371b |
20 | if (! $cm = get_coursemodule_from_id('forum', $id)) { |
f93f848a |
21 | error("Course Module ID was incorrect"); |
22 | } |
23 | if (! $course = get_record("course", "id", $cm->course)) { |
24 | error("Course is misconfigured"); |
25 | } |
26 | if (! $forum = get_record("forum", "id", $cm->instance)) { |
27 | error("Forum ID was incorrect"); |
28 | } |
59c71151 |
29 | $strforums = get_string("modulenameplural", "forum"); |
30 | $strforum = get_string("modulename", "forum"); |
09aebc94 |
31 | $buttontext = update_module_button($cm->id, $course->id, $strforum); |
f93f848a |
32 | |
33 | } else if ($f) { |
49a0ba94 |
34 | |
f93f848a |
35 | if (! $forum = get_record("forum", "id", $f)) { |
94361e02 |
36 | error("Forum ID was incorrect or no longer exists"); |
f93f848a |
37 | } |
38 | if (! $course = get_record("course", "id", $forum->course)) { |
39 | error("Forum is misconfigured - don't know what course it's from"); |
40 | } |
59c71151 |
41 | |
42 | $strforums = get_string("modulenameplural", "forum"); |
43 | $strforum = get_string("modulename", "forum"); |
44 | |
d9bf513d |
45 | if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { |
09aebc94 |
46 | $buttontext = update_module_button($cm->id, $course->id, $strforum); |
d9bf513d |
47 | } else { |
67bbc9b7 |
48 | $cm->id = 0; |
56c0715e |
49 | $cm->visible = 1; |
50 | $cm->course = $course->id; |
d9bf513d |
51 | $buttontext = ""; |
52 | } |
f93f848a |
53 | |
54 | } else { |
49a0ba94 |
55 | error('Must specify a course module or a forum ID'); |
f93f848a |
56 | } |
57 | |
97485d07 |
58 | if (!$buttontext) { |
6f1cc8d6 |
59 | $buttontext = forum_search_form($course, $search); |
680afe2e |
60 | } |
31d160d3 |
61 | |
49a0ba94 |
62 | |
ec81373f |
63 | require_course_login($course, true, $cm); |
68ddf8bc |
64 | |
49a0ba94 |
65 | |
66 | |
67 | /// Print header. |
90fcc576 |
68 | $navigation = "<a href=\"index.php?id=$course->id\">$strforums</a> ->"; |
49a0ba94 |
69 | print_header_simple(format_string($forum->name), "", |
70 | "$navigation ".format_string($forum->name), "", "", true, $buttontext, navmenu($course, $cm)); |
71 | |
f93f848a |
72 | |
82aa0e8d |
73 | |
f0da6b85 |
74 | /// Check whether the user should be able to view this forum. |
bbbf2d40 |
75 | $context = get_context_instance(CONTEXT_MODULE, $cm->id); |
76 | |
f0da6b85 |
77 | if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) { |
3a4c2fd0 |
78 | notice(get_string("activityiscurrentlyhidden")); |
79 | } |
fa22fd5f |
80 | |
b32c8dda |
81 | if (!has_capability('mod/forum:viewdiscussion', $context)) { |
49a0ba94 |
82 | notice(get_string('noviewdiscussionspermission', 'forum')); |
83 | } |
84 | |
85 | $groupmode = groupmode($course, $cm); |
2ab76925 |
86 | $currentgroup = get_and_set_current_group($course, $groupmode, $changegroup); |
fa22fd5f |
87 | |
bbbf2d40 |
88 | if ($groupmode and ($currentgroup === false) and |
0468976c |
89 | !has_capability('moodle/site:accessallgroups', $context)) { |
49a0ba94 |
90 | notice(get_string('notingroup', 'forum')); |
9197e147 |
91 | } |
92 | |
93 | |
9197e147 |
94 | |
49a0ba94 |
95 | /// Okay, we can show the discussions. Log the forum view. |
96 | if ($cm->id) { |
97 | add_to_log($course->id, "forum", "view forum", "view.php?id=$cm->id", "$forum->id", $cm->id); |
98 | } else { |
99 | add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id"); |
100 | } |
101 | |
102 | |
103 | |
104 | /// Print settings and things in a table across the top |
9197e147 |
105 | echo '<table width="100%" border="0" cellpadding="3" cellspacing="0"><tr valign="top">'; |
106 | |
49a0ba94 |
107 | /// 2 ways to do this, 1. we can changed the setup_and_print_groups functions |
108 | /// in moodlelib, taking in 1 more parameter, and tell the function when to |
109 | /// allow student menus, 2, we can just use this code to explicitly print this |
110 | /// menu for students in forums. |
fa22fd5f |
111 | |
49a0ba94 |
112 | /// Now we need a menu for separategroups as well! |
113 | if ($groupmode == VISIBLEGROUPS || ($groupmode |
114 | && has_capability('moodle/site:accessallgroups', $context))) { |
bbbf2d40 |
115 | |
fa22fd5f |
116 | //the following query really needs to change |
9197e147 |
117 | if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) { |
118 | echo '<td>'; |
6ff27f32 |
119 | print_group_menu($groups, $groupmode, $currentgroup, "view.php?id=$cm->id"); |
9197e147 |
120 | echo '</td>'; |
121 | } |
122 | } |
123 | |
49a0ba94 |
124 | /// Only print menus the student is in any course |
fa22fd5f |
125 | else if ($groupmode == SEPARATEGROUPS){ |
126 | $validgroups = array(); |
49a0ba94 |
127 | // Get all the groups this guy is in in this course |
fa22fd5f |
128 | |
129 | if ($p = user_group($course->id,$USER->id)){ |
49a0ba94 |
130 | /// Extract the name and id for the group |
fa22fd5f |
131 | foreach ($p as $index => $object){ |
132 | $validgroups[$object->id] = $object->name; |
133 | } |
fa22fd5f |
134 | echo '<td>'; |
49a0ba94 |
135 | /// Print them in the menu |
fa22fd5f |
136 | print_group_menu($validgroups, $groupmode, $currentgroup, "view.php?id=$cm->id",0); |
137 | echo '</td>'; |
138 | } |
49a0ba94 |
139 | } |
9197e147 |
140 | |
f4646b44 |
141 | if (!empty($USER->id)) { |
41b47dd4 |
142 | echo '<td align="right" class="subscription">'; |
501cdbd8 |
143 | $SESSION->fromdiscussion = "$FULLME"; |
144 | if (forum_is_forcesubscribed($forum->id)) { |
41b47dd4 |
145 | $streveryoneissubscribed = get_string('everyoneissubscribed', 'forum'); |
146 | $strallowchoice = get_string('allowchoice', 'forum'); |
8a387206 |
147 | helpbutton("subscription", $streveryoneissubscribed, "forum"); |
148 | echo ' <span class="helplink">'; |
0468976c |
149 | if (has_capability('moodle/course:manageactivities', $context)) { |
839f2456 |
150 | echo "<a title=\"$strallowchoice\" href=\"subscribe.php?id=$forum->id&force=no\">$streveryoneissubscribed</a>"; |
501cdbd8 |
151 | } else { |
c032b59d |
152 | echo $streveryoneissubscribed; |
501cdbd8 |
153 | } |
41b47dd4 |
154 | echo '</span>'; |
501cdbd8 |
155 | |
098d27d4 |
156 | } else if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) { |
157 | $strsubscriptionsoff = get_string('disallowsubscribe','forum'); |
158 | echo $strsubscriptionsoff; |
159 | helpbutton("subscription", $strsubscriptionsoff, "forum"); |
f93f848a |
160 | } else { |
31d160d3 |
161 | $streveryonecanchoose = get_string("everyonecanchoose", "forum"); |
162 | $strforcesubscribe = get_string("forcesubscribe", "forum"); |
163 | $strshowsubscribers = get_string("showsubscribers", "forum"); |
c032b59d |
164 | |
8a387206 |
165 | helpbutton("subscription", $streveryonecanchoose, "forum"); |
166 | echo ' '; |
0468976c |
167 | if (has_capability('moodle/course:manageactivities', $context)) { |
41b47dd4 |
168 | echo "<span class=\"helplink\"><a title=\"$strforcesubscribe\" href=\"subscribe.php?id=$forum->id&force=yes\">$streveryonecanchoose</a></span>"; |
169 | echo "<br />"; |
170 | echo "<span class=\"helplink\"><a href=\"subscribers.php?id=$forum->id\">$strshowsubscribers</a></span>"; |
310da166 |
171 | } else { |
41b47dd4 |
172 | echo '<span class="helplink">'.$streveryonecanchoose.'</span>'; |
501cdbd8 |
173 | } |
c032b59d |
174 | |
501cdbd8 |
175 | if (forum_is_subscribed($USER->id, $forum->id)) { |
6687be17 |
176 | $subtexttitle = get_string("subscribestop", "forum"); |
31d160d3 |
177 | $subtext = get_string("unsubscribe", "forum"); |
501cdbd8 |
178 | } else { |
6687be17 |
179 | $subtexttitle = get_string("subscribestart", "forum"); |
31d160d3 |
180 | $subtext = get_string("subscribe", "forum"); |
501cdbd8 |
181 | } |
9197e147 |
182 | echo "<br />"; |
41b47dd4 |
183 | echo "<span class=\"helplink\"><a title=\"$subtexttitle\" href=\"subscribe.php?id=$forum->id\">$subtext</a></span>"; |
bffb106d |
184 | } |
8adcb49f |
185 | |
eaf50aef |
186 | if (forum_tp_can_track_forums($forum) && ($forum->trackingtype == FORUM_TRACKING_OPTIONAL)) { |
187 | if (forum_tp_is_tracked($forum, $USER->id)) { |
45293cd3 |
188 | $trtitle = get_string('notrackforum', 'forum'); |
189 | $trackedlink = '<a title="'.get_string('notrackforum', 'forum').'" href="settracking.php?id='. |
1a030f51 |
190 | $forum->id.'&returnpage=view.php">'.get_string('forumtracked', 'forum').'</a>'; |
45293cd3 |
191 | } else { |
192 | $trtitle = get_string('trackforum', 'forum'); |
193 | $trackedlink = '<a title="'.get_string('trackforum', 'forum').'" href="settracking.php?id='. |
1a030f51 |
194 | $forum->id.'&returnpage=view.php">'.get_string('forumtrackednot', 'forum').'</a>'; |
45293cd3 |
195 | } |
196 | echo "<br />"; |
197 | echo "<span class=\"helplink\">$trackedlink</span>"; |
198 | } |
199 | |
f4646b44 |
200 | echo '</td>'; |
201 | } |
8adcb49f |
202 | |
49a0ba94 |
203 | /// If rss are activated at site and forum level and this forum has rss defined, show link |
f4646b44 |
204 | if (isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) && |
205 | $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds && $forum->rsstype and $forum->rssarticles) { |
206 | echo '</tr><tr><td align="right">'; |
207 | if ($forum->rsstype == 1) { |
3849dae8 |
208 | $tooltiptext = get_string("rsssubscriberssdiscussions","forum",format_string($forum->name)); |
680afe2e |
209 | } else { |
3849dae8 |
210 | $tooltiptext = get_string("rsssubscriberssposts","forum",format_string($forum->name)); |
f4646b44 |
211 | } |
212 | if (empty($USER->id)) { |
213 | $userid = 0; |
214 | } else { |
215 | $userid = $USER->id; |
216 | } |
217 | rss_print_link($course->id, $userid, "forum", $forum->id, $tooltiptext); |
9197e147 |
218 | echo '</td>'; |
f93f848a |
219 | } |
220 | |
9197e147 |
221 | echo '</tr></table>'; |
222 | |
a4f495bf |
223 | if (!empty($forum->blockafter) && !empty($forum->blockperiod)) { |
224 | $a->blockafter = $forum->blockafter; |
225 | $a->blockperiod = get_string('secondstotime'.$forum->blockperiod); |
226 | notify(get_string('thisforumisthrottled','forum',$a)); |
227 | } |
228 | |
0468976c |
229 | if ($forum->type == 'qanda' && !has_capability('moodle/course:manageactivities', $context)) { |
098d27d4 |
230 | notify(get_string('qandanotify','forum')); |
231 | } |
232 | |
f064a3df |
233 | $forum->intro = trim($forum->intro); |
e07635f4 |
234 | |
235 | switch ($forum->type) { |
9197e147 |
236 | case 'single': |
501cdbd8 |
237 | if (! $discussion = get_record("forum_discussions", "forum", $forum->id)) { |
238 | if ($discussions = get_records("forum_discussions", "forum", $forum->id, "timemodified ASC")) { |
239 | notify("Warning! There is more than one discussion in this forum - using the most recent"); |
240 | $discussion = array_pop($discussions); |
241 | } else { |
242 | error("Could not find the discussion in this forum"); |
243 | } |
244 | } |
11b0c469 |
245 | if (! $post = forum_get_post_full($discussion->firstpost)) { |
501cdbd8 |
246 | error("Could not find the first post in this forum"); |
247 | } |
5476a93d |
248 | if ($mode) { |
249 | set_user_preference("forum_displaymode", $mode); |
250 | } |
251 | $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode); |
0468976c |
252 | $canrate = has_capability('mod/forum:rate', $context); |
bbbf2d40 |
253 | forum_print_discussion($course, $forum, $discussion, $post, $displaymode, NULL, $canrate); |
501cdbd8 |
254 | break; |
255 | |
9197e147 |
256 | case 'eachuser': |
f064a3df |
257 | if (!empty($forum->intro)) { |
b846ac39 |
258 | print_simple_box(format_text($forum->intro), 'center', '70%', '', 5, 'generalbox', 'intro'); |
c6ee38d0 |
259 | } |
9197e147 |
260 | echo '<p align="center">'; |
11b0c469 |
261 | if (forum_user_can_post_discussion($forum)) { |
31d160d3 |
262 | print_string("allowsdiscussions", "forum"); |
e07635f4 |
263 | } else { |
e746e4dd |
264 | echo ' '; |
e07635f4 |
265 | } |
9197e147 |
266 | echo '</p>'; |
c6ee38d0 |
267 | if (!empty($showall)) { |
af328e4b |
268 | forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode); |
c6ee38d0 |
269 | } else { |
af328e4b |
270 | forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page); |
c6ee38d0 |
271 | } |
272 | break; |
273 | |
9197e147 |
274 | case 'teacher': |
3c8a606d |
275 | if (!empty($showall)) { |
af328e4b |
276 | forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode); |
3c8a606d |
277 | } else { |
af328e4b |
278 | forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page); |
3c8a606d |
279 | } |
e07635f4 |
280 | break; |
281 | |
282 | default: |
f064a3df |
283 | if (!empty($forum->intro)) { |
b846ac39 |
284 | print_simple_box(format_text($forum->intro), 'center', '70%', '', 5, 'generalbox', 'intro'); |
c6ee38d0 |
285 | } |
61242972 |
286 | echo '<br />'; |
3c8a606d |
287 | if (!empty($showall)) { |
af328e4b |
288 | forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode); |
3c8a606d |
289 | } else { |
af328e4b |
290 | forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page); |
3c8a606d |
291 | } |
fa22fd5f |
292 | |
293 | |
e07635f4 |
294 | break; |
295 | } |
f93f848a |
296 | print_footer($course); |
297 | |
b32c8dda |
298 | ?> |