3 require_once('../../config.php');
4 require_once('lib.php');
5 require_once("$CFG->libdir/rsslib.php");
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
20 if (! $cm = get_coursemodule_from_id('forum', $id)) {
21 error("Course Module ID was incorrect");
23 if (! $course = get_record("course", "id", $cm->course
)) {
24 error("Course is misconfigured");
26 if (! $forum = get_record("forum", "id", $cm->instance
)) {
27 error("Forum ID was incorrect");
29 $strforums = get_string("modulenameplural", "forum");
30 $strforum = get_string("modulename", "forum");
31 $buttontext = update_module_button($cm->id
, $course->id
, $strforum);
35 if (! $forum = get_record("forum", "id", $f)) {
36 error("Forum ID was incorrect or no longer exists");
38 if (! $course = get_record("course", "id", $forum->course
)) {
39 error("Forum is misconfigured - don't know what course it's from");
42 $strforums = get_string("modulenameplural", "forum");
43 $strforum = get_string("modulename", "forum");
45 if ($cm = get_coursemodule_from_instance("forum", $forum->id
, $course->id
)) {
46 $buttontext = update_module_button($cm->id
, $course->id
, $strforum);
50 $cm->course
= $course->id
;
54 error('Must specify a course module or a forum ID');
58 $buttontext = forum_search_form($course, $search);
62 require_course_login($course, true, $cm);
63 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
68 $navlinks[] = array('name' => $strforums, 'link' => "index.php?id=$course->id", 'type' => 'activity');
69 $navlinks[] = array('name' => format_string($forum->name
), 'link' => "view.php?f=$forum->id", 'type' => 'activityinstance');
71 $navigation = build_navigation($navlinks);
73 print_header_simple(format_string($forum->name
), "",
74 $navigation, "", "", true, $buttontext, navmenu($course, $cm));
77 /// Some capability checks.
78 if (empty($cm->visible
) and !has_capability('moodle/course:viewhiddenactivities', $context)) {
79 notice(get_string("activityiscurrentlyhidden"));
82 if (!has_capability('mod/forum:viewdiscussion', $context)) {
83 notice(get_string('noviewdiscussionspermission', 'forum'));
86 /// find out current groups mode
87 $groupmode = groupmode($course, $cm);
88 $currentgroup = setup_and_print_groups($course, $groupmode, 'view.php?id=' . $cm->id
);
90 /// Okay, we can show the discussions. Log the forum view.
92 add_to_log($course->id
, "forum", "view forum", "view.php?id=$cm->id", "$forum->id", $cm->id
);
94 add_to_log($course->id
, "forum", "view forum", "view.php?f=$forum->id", "$forum->id");
99 /// Print settings and things across the top
101 // If it's a simple single discussion forum, we need to print the display
103 if ($forum->type
== 'single') {
104 if (! $discussion = get_record("forum_discussions", "forum", $forum->id
)) {
105 if ($discussions = get_records("forum_discussions", "forum", $forum->id
, "timemodified ASC")) {
106 $discussion = array_pop($discussions);
111 set_user_preference("forum_displaymode", $mode);
113 $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode
);
114 forum_print_mode_form($forum->id
, $displaymode, $forum->type
);
119 print_box_start('forumcontrol');
121 print_box_start('subscription');
123 if (!empty($USER->id
) && !has_capability('moodle/legacy:guest', $context, NULL, false)) {
124 $SESSION->fromdiscussion
= "$FULLME";
125 if (forum_is_forcesubscribed($forum->id
)) {
126 $streveryoneisnowsubscribed = get_string('everyoneisnowsubscribed', 'forum');
127 $strallowchoice = get_string('allowchoice', 'forum');
128 echo '<span class="helplink">' . get_string("forcessubscribe", 'forum') . '</span><br />';
129 helpbutton("subscription", $strallowchoice, "forum");
130 echo ' <span class="helplink">';
131 if (has_capability('moodle/course:manageactivities', $context)) {
132 echo "<a title=\"$strallowchoice\" href=\"subscribe.php?id=$forum->id&force=no\">$strallowchoice</a>";
134 echo $streveryoneisnowsubscribed;
138 } else if ($forum->forcesubscribe
== FORUM_DISALLOWSUBSCRIBE
) {
139 $strsubscriptionsoff = get_string('disallowsubscribe','forum');
140 echo $strsubscriptionsoff;
141 helpbutton("subscription", $strsubscriptionsoff, "forum");
143 $streveryonecannowchoose = get_string("everyonecannowchoose", "forum");
144 $strforcesubscribe = get_string("forcesubscribe", "forum");
145 $strshowsubscribers = get_string("showsubscribers", "forum");
146 echo '<span class="helplink">' . get_string("allowsallsubscribe", 'forum') . '</span><br />';
147 helpbutton("subscription", $strforcesubscribe, "forum");
149 if (has_capability('moodle/course:manageactivities', $context)) {
150 echo "<span class=\"helplink\"><a title=\"$strforcesubscribe\" href=\"subscribe.php?id=$forum->id&force=yes\">$strforcesubscribe</a></span>";
152 echo "<span class=\"helplink\"><a href=\"subscribers.php?id=$forum->id\">$strshowsubscribers</a></span>";
154 echo '<span class="helplink">'.$streveryonecannowchoose.'</span>';
157 echo '<br /><span class="helplink">', forum_get_subscribe_link($forum, $context,
158 array('forcesubscribed' => '', 'cantsubscribe' => '')), '</span>';
161 if (forum_tp_can_track_forums($forum) && ($forum->trackingtype
== FORUM_TRACKING_OPTIONAL
)) {
162 if (forum_tp_is_tracked($forum, $USER->id
)) {
163 $trtitle = get_string('notrackforum', 'forum');
164 $trackedlink = '<a title="'.get_string('notrackforum', 'forum').'" href="settracking.php?id='.
165 $forum->id
.'&returnpage=view.php">'.get_string('forumtracked', 'forum').'</a>';
167 $trtitle = get_string('trackforum', 'forum');
168 $trackedlink = '<a title="'.get_string('trackforum', 'forum').'" href="settracking.php?id='.
169 $forum->id
.'&returnpage=view.php">'.get_string('forumtrackednot', 'forum').'</a>';
172 echo "<span class=\"helplink\">$trackedlink</span>";
177 /// If rss are activated at site and forum level and this forum has rss defined, show link
178 if (isset($CFG->enablerssfeeds
) && isset($CFG->forum_enablerssfeeds
) &&
179 $CFG->enablerssfeeds
&& $CFG->forum_enablerssfeeds
&& $forum->rsstype
and $forum->rssarticles
) {
181 if ($forum->rsstype
== 1) {
182 $tooltiptext = get_string("rsssubscriberssdiscussions","forum",format_string($forum->name
));
184 $tooltiptext = get_string("rsssubscriberssposts","forum",format_string($forum->name
));
186 if (empty($USER->id
)) {
191 print_box_start('rsslink');
192 rss_print_link($course->id
, $userid, "forum", $forum->id
, $tooltiptext);
193 print_box_end(); // subscription
196 print_box_end(); // subscription
198 print_box_end(); // forumcontrol
200 print_box(' ', 'clearer');
203 if (!empty($forum->blockafter
) && !empty($forum->blockperiod
)) {
204 $a->blockafter
= $forum->blockafter
;
205 $a->blockperiod
= get_string('secondstotime'.$forum->blockperiod
);
206 notify(get_string('thisforumisthrottled','forum',$a));
209 if ($forum->type
== 'qanda' && !has_capability('moodle/course:manageactivities', $context)) {
210 notify(get_string('qandanotify','forum'));
213 $forum->intro
= trim($forum->intro
);
215 switch ($forum->type
) {
217 if (! $discussion = get_record("forum_discussions", "forum", $forum->id
)) {
218 if ($discussions = get_records("forum_discussions", "forum", $forum->id
, "timemodified ASC")) {
219 notify("Warning! There is more than one discussion in this forum - using the most recent");
220 $discussion = array_pop($discussions);
222 error("Could not find the discussion in this forum");
225 if (! $post = forum_get_post_full($discussion->firstpost
)) {
226 error("Could not find the first post in this forum");
229 set_user_preference("forum_displaymode", $mode);
231 $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode
);
232 $canrate = has_capability('mod/forum:rate', $context);
233 forum_print_discussion($course, $forum, $discussion, $post, $displaymode, NULL, $canrate);
237 if (!empty($forum->intro
)) {
238 print_box(format_text($forum->intro
), 'generalbox', 'intro');
240 echo '<p align="center">';
241 if (forum_user_can_post_discussion($forum)) {
242 print_string("allowsdiscussions", "forum");
247 if (!empty($showall)) {
248 forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode);
250 forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions
, 'header', '', $currentgroup, $groupmode, $page);
255 if (!empty($showall)) {
256 forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode);
258 forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions
, 'header', '', $currentgroup, $groupmode, $page);
263 if (!empty($forum->intro
)) {
264 print_box(format_text($forum->intro
), 'generalbox', 'intro');
267 if (!empty($showall)) {
268 forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode);
270 forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions
, 'header', '', $currentgroup, $groupmode, $page);
276 print_footer($course);