fix typo
[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)) {
dde78cb8 21 print_error('invalidcoursemodule');
f93f848a 22 }
4e445355 23 if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
dde78cb8 24 print_error('coursemisconf');
f93f848a 25 }
4e445355 26 if (! $forum = $DB->get_record("forum", array("id" => $cm->instance))) {
dde78cb8 27 print_error('invalidforumid', 'forum');
f93f848a 28 }
4cabf99f 29 // move require_course_login here to use forced language for course
30 // fix for MDL-6926
31 require_course_login($course, true, $cm);
59c71151 32 $strforums = get_string("modulenameplural", "forum");
33 $strforum = get_string("modulename", "forum");
09aebc94 34 $buttontext = update_module_button($cm->id, $course->id, $strforum);
f93f848a 35
36 } else if ($f) {
49a0ba94 37
4e445355 38 if (! $forum = $DB->get_record("forum", array("id" => $f))) {
dde78cb8 39 print_error('invalidforumid', 'forum');
f93f848a 40 }
4e445355 41 if (! $course = $DB->get_record("course", array("id" => $forum->course))) {
dde78cb8 42 print_error('coursemisconf');
f93f848a 43 }
59c71151 44
65bcf17b 45 if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
dde78cb8 46 print_error('missingparameter');
d9bf513d 47 }
4cabf99f 48 // move require_course_login here to use forced language for course
49 // fix for MDL-6926
50 require_course_login($course, true, $cm);
51 $strforums = get_string("modulenameplural", "forum");
52 $strforum = get_string("modulename", "forum");
65bcf17b 53 $buttontext = update_module_button($cm->id, $course->id, $strforum);
54
f93f848a 55 } else {
dde78cb8 56 print_error('missingparameter');
f93f848a 57 }
58
97485d07 59 if (!$buttontext) {
6f1cc8d6 60 $buttontext = forum_search_form($course, $search);
680afe2e 61 }
31d160d3 62
83da3d28 63 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
49a0ba94 64
65
66/// Print header.
0bf0e321 67 $navigation = build_navigation('', $cm);
49a0ba94 68 print_header_simple(format_string($forum->name), "",
e3f58dfb 69 $navigation, "", "", true, $buttontext, navmenu($course, $cm));
49a0ba94 70
83da3d28 71/// Some capability checks.
f0da6b85 72 if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) {
3a4c2fd0 73 notice(get_string("activityiscurrentlyhidden"));
74 }
65bcf17b 75
b32c8dda 76 if (!has_capability('mod/forum:viewdiscussion', $context)) {
49a0ba94 77 notice(get_string('noviewdiscussionspermission', 'forum'));
78 }
65bcf17b 79
3b27b0fe 80/// find out current groups mode
13534ef7
ML
81 groups_print_activity_menu($cm, 'view.php?id=' . $cm->id);
82 $currentgroup = groups_get_activity_group($cm);
83 $groupmode = groups_get_activity_groupmode($cm);
9197e147 84
49a0ba94 85/// Okay, we can show the discussions. Log the forum view.
86 if ($cm->id) {
87 add_to_log($course->id, "forum", "view forum", "view.php?id=$cm->id", "$forum->id", $cm->id);
88 } else {
89 add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id");
90 }
91
92
93
83da3d28 94/// Print settings and things across the top
95
96 // If it's a simple single discussion forum, we need to print the display
97 // mode control.
98 if ($forum->type == 'single') {
4e445355 99 if (! $discussion = $DB->get_record("forum_discussions", array("forum" => $forum->id))) {
100 if ($discussions = $DB->get_records("forum_discussions", array("forum", $forum->id), "timemodified ASC")) {
83da3d28 101 $discussion = array_pop($discussions);
102 }
103 }
104 if ($discussion) {
105 if ($mode) {
106 set_user_preference("forum_displaymode", $mode);
107 }
108 $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
109 forum_print_mode_form($forum->id, $displaymode, $forum->type);
110 }
111 }
112
0be4d8bf 113
52ea8aa0 114// print_box_start('forumcontrol clearfix');
9197e147 115
52ea8aa0 116// print_box_start('subscription clearfix');
117 echo '<div class="subscription">';
0be4d8bf 118
a321d42b 119 if (!empty($USER->id) && !has_capability('moodle/legacy:guest', $context, NULL, false)) {
501cdbd8 120 $SESSION->fromdiscussion = "$FULLME";
90f4745c 121 if (forum_is_forcesubscribed($forum)) {
cdfe4875 122 $streveryoneisnowsubscribed = get_string('everyoneisnowsubscribed', 'forum');
41b47dd4 123 $strallowchoice = get_string('allowchoice', 'forum');
cdfe4875 124 echo '<span class="helplink">' . get_string("forcessubscribe", 'forum') . '</span><br />';
125 helpbutton("subscription", $strallowchoice, "forum");
8a387206 126 echo '&nbsp;<span class="helplink">';
5d49ff35 127 if (has_capability('mod/forum:managesubscriptions', $context)) {
cdfe4875 128 echo "<a title=\"$strallowchoice\" href=\"subscribe.php?id=$forum->id&amp;force=no\">$strallowchoice</a>";
501cdbd8 129 } else {
cdfe4875 130 echo $streveryoneisnowsubscribed;
501cdbd8 131 }
a365ee56 132 echo '</span><br />';
501cdbd8 133
098d27d4 134 } else if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) {
135 $strsubscriptionsoff = get_string('disallowsubscribe','forum');
136 echo $strsubscriptionsoff;
137 helpbutton("subscription", $strsubscriptionsoff, "forum");
f93f848a 138 } else {
cdfe4875 139 $streveryonecannowchoose = get_string("everyonecannowchoose", "forum");
31d160d3 140 $strforcesubscribe = get_string("forcesubscribe", "forum");
141 $strshowsubscribers = get_string("showsubscribers", "forum");
cdfe4875 142 echo '<span class="helplink">' . get_string("allowsallsubscribe", 'forum') . '</span><br />';
143 helpbutton("subscription", $strforcesubscribe, "forum");
8a387206 144 echo '&nbsp;';
5d49ff35 145
146 if (has_capability('mod/forum:managesubscriptions', $context)) {
cdfe4875 147 echo "<span class=\"helplink\"><a title=\"$strforcesubscribe\" href=\"subscribe.php?id=$forum->id&amp;force=yes\">$strforcesubscribe</a></span>";
310da166 148 } else {
cdfe4875 149 echo '<span class="helplink">'.$streveryonecannowchoose.'</span>';
501cdbd8 150 }
c032b59d 151
5d49ff35 152 if(has_capability('mod/forum:viewsubscribers', $context)){
153 echo "<br />";
154 echo "<span class=\"helplink\"><a href=\"subscribers.php?id=$forum->id\">$strshowsubscribers</a></span>";
155 }
156
65bcf17b 157 echo '<div class="helplink" id="subscriptionlink">', forum_get_subscribe_link($forum, $context,
a365ee56 158 array('forcesubscribed' => '', 'cantsubscribe' => '')), '</div>';
bffb106d 159 }
8adcb49f 160
90f4745c 161 if (forum_tp_can_track_forums($forum)) {
a113acdd 162 echo '<div class="helplink" id="trackinglink">'. forum_get_tracking_link($forum). '</div>';
45293cd3 163 }
164
f4646b44 165 }
8adcb49f 166
49a0ba94 167 /// If rss are activated at site and forum level and this forum has rss defined, show link
f4646b44 168 if (isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) &&
169 $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds && $forum->rsstype and $forum->rssarticles) {
0be4d8bf 170
f4646b44 171 if ($forum->rsstype == 1) {
3849dae8 172 $tooltiptext = get_string("rsssubscriberssdiscussions","forum",format_string($forum->name));
680afe2e 173 } else {
3849dae8 174 $tooltiptext = get_string("rsssubscriberssposts","forum",format_string($forum->name));
f4646b44 175 }
176 if (empty($USER->id)) {
177 $userid = 0;
178 } else {
179 $userid = $USER->id;
180 }
52ea8aa0 181// print_box_start('rsslink');
182 echo '<span class="wrap rsslink">';
f4646b44 183 rss_print_link($course->id, $userid, "forum", $forum->id, $tooltiptext);
52ea8aa0 184 echo '</span>';
185// print_box_end(); // subscription
0be4d8bf 186
f93f848a 187 }
52ea8aa0 188// print_box_end(); // subscription
189 echo '</div>';
0be4d8bf 190
52ea8aa0 191// print_box_end(); // forumcontrol
0be4d8bf 192
65bcf17b 193// print_box('&nbsp;', 'clearer');
f93f848a 194
9197e147 195
a4f495bf 196 if (!empty($forum->blockafter) && !empty($forum->blockperiod)) {
197 $a->blockafter = $forum->blockafter;
198 $a->blockperiod = get_string('secondstotime'.$forum->blockperiod);
199 notify(get_string('thisforumisthrottled','forum',$a));
200 }
201
0468976c 202 if ($forum->type == 'qanda' && !has_capability('moodle/course:manageactivities', $context)) {
098d27d4 203 notify(get_string('qandanotify','forum'));
204 }
205
e07635f4 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 {
dde78cb8 213 print_error('nodiscussions', 'forum');
501cdbd8 214 }
215 }
11b0c469 216 if (! $post = forum_get_post_full($discussion->firstpost)) {
dde78cb8 217 print_error('cannotfindfirstpost', '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)) {
4ba2221a 233 print_box(format_module_intro('forum', $forum, $cm->id), 'generalbox', 'intro');
c6ee38d0 234 }
a6e13ccc 235 echo '<p class="mdl-align">';
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)) {
4ba2221a 259 print_box(format_module_intro('forum', $forum, $cm->id), '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 }
4e781c7b 271 $completion=new completion_info($course);
272 $completion->set_module_viewed($cm);
f93f848a 273 print_footer($course);
274
b32c8dda 275?>