whitespace fixes
[moodle.git] / mod / forum / view.php
CommitLineData
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
65bcf17b 17 $buttontext = '';
f93f848a 18
19 if ($id) {
f9d5371b 20 if (! $cm = get_coursemodule_from_id('forum', $id)) {
90f4745c 21 error("Course Module ID was incorrect");
f93f848a 22 }
4e445355 23 if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
90f4745c 24 error("Course is misconfigured");
f93f848a 25 }
4e445355 26 if (! $forum = $DB->get_record("forum", array("id" => $cm->instance))) {
90f4745c 27 error("Forum ID was incorrect");
f93f848a 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
4e445355 35 if (! $forum = $DB->get_record("forum", array("id" => $f))) {
90f4745c 36 error("Forum ID was incorrect or no longer exists");
f93f848a 37 }
4e445355 38 if (! $course = $DB->get_record("course", array("id" => $forum->course))) {
90f4745c 39 error("Forum is misconfigured - don't know what course it's from");
f93f848a 40 }
59c71151 41
42 $strforums = get_string("modulenameplural", "forum");
43 $strforum = get_string("modulename", "forum");
44
65bcf17b 45 if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
90f4745c 46 error("Course Module missing");
d9bf513d 47 }
65bcf17b 48
49 $buttontext = update_module_button($cm->id, $course->id, $strforum);
50
f93f848a 51 } else {
90f4745c 52 error('Must specify a course module or a forum ID');
f93f848a 53 }
54
97485d07 55 if (!$buttontext) {
6f1cc8d6 56 $buttontext = forum_search_form($course, $search);
680afe2e 57 }
31d160d3 58
49a0ba94 59
ec81373f 60 require_course_login($course, true, $cm);
83da3d28 61 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
49a0ba94 62
63
64/// Print header.
0bf0e321 65 $navigation = build_navigation('', $cm);
49a0ba94 66 print_header_simple(format_string($forum->name), "",
e3f58dfb 67 $navigation, "", "", true, $buttontext, navmenu($course, $cm));
49a0ba94 68
83da3d28 69/// Some capability checks.
f0da6b85 70 if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) {
3a4c2fd0 71 notice(get_string("activityiscurrentlyhidden"));
72 }
65bcf17b 73
b32c8dda 74 if (!has_capability('mod/forum:viewdiscussion', $context)) {
49a0ba94 75 notice(get_string('noviewdiscussionspermission', 'forum'));
76 }
65bcf17b 77
3b27b0fe 78/// find out current groups mode
13534ef7
ML
79 groups_print_activity_menu($cm, 'view.php?id=' . $cm->id);
80 $currentgroup = groups_get_activity_group($cm);
81 $groupmode = groups_get_activity_groupmode($cm);
9197e147 82
49a0ba94 83/// Okay, we can show the discussions. Log the forum view.
84 if ($cm->id) {
85 add_to_log($course->id, "forum", "view forum", "view.php?id=$cm->id", "$forum->id", $cm->id);
86 } else {
87 add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id");
88 }
89
90
91
83da3d28 92/// Print settings and things across the top
93
94 // If it's a simple single discussion forum, we need to print the display
95 // mode control.
96 if ($forum->type == 'single') {
4e445355 97 if (! $discussion = $DB->get_record("forum_discussions", array("forum" => $forum->id))) {
98 if ($discussions = $DB->get_records("forum_discussions", array("forum", $forum->id), "timemodified ASC")) {
83da3d28 99 $discussion = array_pop($discussions);
100 }
101 }
102 if ($discussion) {
103 if ($mode) {
104 set_user_preference("forum_displaymode", $mode);
105 }
106 $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
107 forum_print_mode_form($forum->id, $displaymode, $forum->type);
108 }
109 }
110
0be4d8bf 111
52ea8aa0 112// print_box_start('forumcontrol clearfix');
9197e147 113
52ea8aa0 114// print_box_start('subscription clearfix');
115 echo '<div class="subscription">';
0be4d8bf 116
a321d42b 117 if (!empty($USER->id) && !has_capability('moodle/legacy:guest', $context, NULL, false)) {
501cdbd8 118 $SESSION->fromdiscussion = "$FULLME";
90f4745c 119 if (forum_is_forcesubscribed($forum)) {
cdfe4875 120 $streveryoneisnowsubscribed = get_string('everyoneisnowsubscribed', 'forum');
41b47dd4 121 $strallowchoice = get_string('allowchoice', 'forum');
cdfe4875 122 echo '<span class="helplink">' . get_string("forcessubscribe", 'forum') . '</span><br />';
123 helpbutton("subscription", $strallowchoice, "forum");
8a387206 124 echo '&nbsp;<span class="helplink">';
5d49ff35 125 if (has_capability('mod/forum:managesubscriptions', $context)) {
cdfe4875 126 echo "<a title=\"$strallowchoice\" href=\"subscribe.php?id=$forum->id&amp;force=no\">$strallowchoice</a>";
501cdbd8 127 } else {
cdfe4875 128 echo $streveryoneisnowsubscribed;
501cdbd8 129 }
a365ee56 130 echo '</span><br />';
501cdbd8 131
098d27d4 132 } else if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) {
133 $strsubscriptionsoff = get_string('disallowsubscribe','forum');
134 echo $strsubscriptionsoff;
135 helpbutton("subscription", $strsubscriptionsoff, "forum");
f93f848a 136 } else {
cdfe4875 137 $streveryonecannowchoose = get_string("everyonecannowchoose", "forum");
31d160d3 138 $strforcesubscribe = get_string("forcesubscribe", "forum");
139 $strshowsubscribers = get_string("showsubscribers", "forum");
cdfe4875 140 echo '<span class="helplink">' . get_string("allowsallsubscribe", 'forum') . '</span><br />';
141 helpbutton("subscription", $strforcesubscribe, "forum");
8a387206 142 echo '&nbsp;';
5d49ff35 143
144 if (has_capability('mod/forum:managesubscriptions', $context)) {
cdfe4875 145 echo "<span class=\"helplink\"><a title=\"$strforcesubscribe\" href=\"subscribe.php?id=$forum->id&amp;force=yes\">$strforcesubscribe</a></span>";
310da166 146 } else {
cdfe4875 147 echo '<span class="helplink">'.$streveryonecannowchoose.'</span>';
501cdbd8 148 }
c032b59d 149
5d49ff35 150 if(has_capability('mod/forum:viewsubscribers', $context)){
151 echo "<br />";
152 echo "<span class=\"helplink\"><a href=\"subscribers.php?id=$forum->id\">$strshowsubscribers</a></span>";
153 }
154
65bcf17b 155 echo '<div class="helplink" id="subscriptionlink">', forum_get_subscribe_link($forum, $context,
a365ee56 156 array('forcesubscribed' => '', 'cantsubscribe' => '')), '</div>';
bffb106d 157 }
8adcb49f 158
90f4745c 159 if (forum_tp_can_track_forums($forum)) {
a113acdd 160 echo '<div class="helplink" id="trackinglink">'. forum_get_tracking_link($forum). '</div>';
45293cd3 161 }
162
f4646b44 163 }
8adcb49f 164
49a0ba94 165 /// If rss are activated at site and forum level and this forum has rss defined, show link
f4646b44 166 if (isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) &&
167 $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds && $forum->rsstype and $forum->rssarticles) {
0be4d8bf 168
f4646b44 169 if ($forum->rsstype == 1) {
3849dae8 170 $tooltiptext = get_string("rsssubscriberssdiscussions","forum",format_string($forum->name));
680afe2e 171 } else {
3849dae8 172 $tooltiptext = get_string("rsssubscriberssposts","forum",format_string($forum->name));
f4646b44 173 }
174 if (empty($USER->id)) {
175 $userid = 0;
176 } else {
177 $userid = $USER->id;
178 }
52ea8aa0 179// print_box_start('rsslink');
180 echo '<span class="wrap rsslink">';
f4646b44 181 rss_print_link($course->id, $userid, "forum", $forum->id, $tooltiptext);
52ea8aa0 182 echo '</span>';
183// print_box_end(); // subscription
0be4d8bf 184
f93f848a 185 }
52ea8aa0 186// print_box_end(); // subscription
187 echo '</div>';
0be4d8bf 188
52ea8aa0 189// print_box_end(); // forumcontrol
0be4d8bf 190
65bcf17b 191// print_box('&nbsp;', 'clearer');
f93f848a 192
9197e147 193
a4f495bf 194 if (!empty($forum->blockafter) && !empty($forum->blockperiod)) {
195 $a->blockafter = $forum->blockafter;
196 $a->blockperiod = get_string('secondstotime'.$forum->blockperiod);
197 notify(get_string('thisforumisthrottled','forum',$a));
198 }
199
0468976c 200 if ($forum->type == 'qanda' && !has_capability('moodle/course:manageactivities', $context)) {
098d27d4 201 notify(get_string('qandanotify','forum'));
202 }
203
f064a3df 204 $forum->intro = trim($forum->intro);
e07635f4 205
206 switch ($forum->type) {
9197e147 207 case 'single':
4e445355 208 if (! $discussion = $DB->get_record("forum_discussions", array("forum" => $forum->id))) {
209 if ($discussions = $DB->get_records("forum_discussions", array("forum" => $forum->id), "timemodified ASC")) {
501cdbd8 210 notify("Warning! There is more than one discussion in this forum - using the most recent");
211 $discussion = array_pop($discussions);
212 } else {
90f4745c 213 error("Could not find the discussion in this forum");
501cdbd8 214 }
215 }
11b0c469 216 if (! $post = forum_get_post_full($discussion->firstpost)) {
90f4745c 217 error("Could not find the first post in this forum");
501cdbd8 218 }
5476a93d 219 if ($mode) {
220 set_user_preference("forum_displaymode", $mode);
221 }
62b04e08 222
8b79a625 223 $canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $context);
224 $canrate = has_capability('mod/forum:rate', $context);
5476a93d 225 $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
8b79a625 226
8675df6f 227 echo '&nbsp;'; // this should fix the floating in FF
62b04e08 228 forum_print_discussion($course, $cm, $forum, $discussion, $post, $displaymode, $canreply, $canrate);
501cdbd8 229 break;
230
9197e147 231 case 'eachuser':
f064a3df 232 if (!empty($forum->intro)) {
9f7f1a74 233 print_box(format_text($forum->intro), 'generalbox', 'intro');
c6ee38d0 234 }
9197e147 235 echo '<p align="center">';
89d35c49 236 if (forum_user_can_post_discussion($forum, null, -1, $cm)) {
31d160d3 237 print_string("allowsdiscussions", "forum");
e07635f4 238 } else {
e746e4dd 239 echo '&nbsp;';
e07635f4 240 }
9197e147 241 echo '</p>';
c6ee38d0 242 if (!empty($showall)) {
90f4745c 243 forum_print_latest_discussions($course, $forum, 0, 'header', '', -1, -1, -1, 0, $cm);
c6ee38d0 244 } else {
90f4745c 245 forum_print_latest_discussions($course, $forum, -1, 'header', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm);
c6ee38d0 246 }
247 break;
248
9197e147 249 case 'teacher':
3c8a606d 250 if (!empty($showall)) {
90f4745c 251 forum_print_latest_discussions($course, $forum, 0, 'header', '', -1, -1, -1, 0, $cm);
3c8a606d 252 } else {
90f4745c 253 forum_print_latest_discussions($course, $forum, -1, 'header', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm);
3c8a606d 254 }
e07635f4 255 break;
256
257 default:
f064a3df 258 if (!empty($forum->intro)) {
9f7f1a74 259 print_box(format_text($forum->intro), 'generalbox', 'intro');
c6ee38d0 260 }
61242972 261 echo '<br />';
3c8a606d 262 if (!empty($showall)) {
90f4745c 263 forum_print_latest_discussions($course, $forum, 0, 'header', '', -1, -1, -1, 0, $cm);
3c8a606d 264 } else {
90f4745c 265 forum_print_latest_discussions($course, $forum, -1, 'header', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm);
3c8a606d 266 }
65bcf17b 267
268
e07635f4 269 break;
270 }
f93f848a 271 print_footer($course);
272
b32c8dda 273?>