New help file to cover new additions to uploadusers format (for teachers)
[moodle.git] / mod / forum / view.php
CommitLineData
41905731 1<?php // $Id$
f93f848a 2
b0e3a925 3 require_once("../../config.php");
4 require_once("lib.php");
48b29ba4 5 require_once("$CFG->libdir/rsslib.php");
f93f848a 6
c7e65290 7 $id = optional_param('id', 0, PARAM_INT); // Course Module ID
8 $f = optional_param('f', 0, PARAM_INT); // Forum ID
9 $mode = optional_param('mode', 0, PARAM_INT); // Display mode (for single forum)
10 $showall = optional_param('showall', '', PARAM_INT); // show all discussions on one page
11 $group = optional_param('group', -1, PARAM_INT); // choose the current group
12 $page = optional_param('page', 0, PARAM_INT); // which page to show
13 $search = optional_param('search', ''); // search string
f93f848a 14
15 if ($id) {
16 if (! $cm = get_record("course_modules", "id", $id)) {
17 error("Course Module ID was incorrect");
18 }
19 if (! $course = get_record("course", "id", $cm->course)) {
20 error("Course is misconfigured");
21 }
22 if (! $forum = get_record("forum", "id", $cm->instance)) {
23 error("Forum ID was incorrect");
24 }
59c71151 25
26 $strforums = get_string("modulenameplural", "forum");
27 $strforum = get_string("modulename", "forum");
28
09aebc94 29 $buttontext = update_module_button($cm->id, $course->id, $strforum);
f93f848a 30
31 } else if ($f) {
32 if (! $forum = get_record("forum", "id", $f)) {
94361e02 33 error("Forum ID was incorrect or no longer exists");
f93f848a 34 }
35 if (! $course = get_record("course", "id", $forum->course)) {
36 error("Forum is misconfigured - don't know what course it's from");
37 }
59c71151 38
39 $strforums = get_string("modulenameplural", "forum");
40 $strforum = get_string("modulename", "forum");
41
d9bf513d 42 if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
09aebc94 43 $buttontext = update_module_button($cm->id, $course->id, $strforum);
d9bf513d 44 } else {
67bbc9b7 45 $cm->id = 0;
56c0715e 46 $cm->visible = 1;
47 $cm->course = $course->id;
d9bf513d 48 $buttontext = "";
49 }
f93f848a 50
51 } else {
52 error("Must specify a course module or a forum ID");
53 }
54
97485d07 55 if (!$buttontext) {
6f1cc8d6 56 $buttontext = forum_search_form($course, $search);
680afe2e 57 }
31d160d3 58
ec81373f 59 require_course_login($course, true, $cm);
68ddf8bc 60
90fcc576 61 $navigation = "<a href=\"index.php?id=$course->id\">$strforums</a> ->";
f93f848a 62
82aa0e8d 63 if ($forum->type == "teacher") {
64 if (!isteacher($course->id)) {
65 error("You must be a $course->teacher to view this forum");
66 }
67 }
68
67bbc9b7 69 if ($cm->id) {
69d79bc3 70 add_to_log($course->id, "forum", "view forum", "view.php?id=$cm->id", "$forum->id", $cm->id);
e2c4f8e4 71 } else {
72 add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id");
73 }
f93f848a 74
3849dae8 75 print_header_simple(format_string($forum->name), "",
76 "$navigation ".format_string($forum->name), "", "", true, $buttontext, navmenu($course, $cm));
f93f848a 77
fb83bd50 78 if (empty($cm->visible) and !isteacher($course->id)) {
3a4c2fd0 79 notice(get_string("activityiscurrentlyhidden"));
80 }
81
9197e147 82
83/// Check to see if groups are being used in this forum
84/// and if so, set $currentgroup to reflect the current group
85
70e3da07 86 $changegroup = isset_param('group') ? $group : -1; // Group change requested?
52b201ee 87
88 if ($forum->type == "teacher") {
89 $groupmode = NOGROUPS;
90 } else {
91 $groupmode = groupmode($course, $cm); // Groups are being used
92 }
2ab76925 93 $currentgroup = get_and_set_current_group($course, $groupmode, $changegroup);
9197e147 94
2ab76925 95 if ($groupmode and ($currentgroup === false) and !isteacheredit($course->id)) {
96 print_heading(get_string("notingroup", "forum"));
97 print_footer($course);
9197e147 98 exit;
99 }
100
101
102/// Print settings and things in a table across the top
103
104 echo '<table width="100%" border="0" cellpadding="3" cellspacing="0"><tr valign="top">';
105
106 if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
107 if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
108 echo '<td>';
6ff27f32 109 print_group_menu($groups, $groupmode, $currentgroup, "view.php?id=$cm->id");
9197e147 110 echo '</td>';
111 }
112 }
113
114
f4646b44 115 if (!empty($USER->id)) {
41b47dd4 116 echo '<td align="right" class="subscription">';
501cdbd8 117 $SESSION->fromdiscussion = "$FULLME";
118 if (forum_is_forcesubscribed($forum->id)) {
41b47dd4 119 $streveryoneissubscribed = get_string('everyoneissubscribed', 'forum');
120 $strallowchoice = get_string('allowchoice', 'forum');
8a387206 121 helpbutton("subscription", $streveryoneissubscribed, "forum");
122 echo '&nbsp;<span class="helplink">';
501cdbd8 123 if (isteacher($course->id)) {
839f2456 124 echo "<a title=\"$strallowchoice\" href=\"subscribe.php?id=$forum->id&amp;force=no\">$streveryoneissubscribed</a>";
501cdbd8 125 } else {
c032b59d 126 echo $streveryoneissubscribed;
501cdbd8 127 }
41b47dd4 128 echo '</span>';
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
8a387206 135 helpbutton("subscription", $streveryonecanchoose, "forum");
136 echo '&nbsp;';
501cdbd8 137 if (isteacher($course->id)) {
41b47dd4 138 echo "<span class=\"helplink\"><a title=\"$strforcesubscribe\" href=\"subscribe.php?id=$forum->id&amp;force=yes\">$streveryonecanchoose</a></span>";
139 echo "<br />";
140 echo "<span class=\"helplink\"><a href=\"subscribers.php?id=$forum->id\">$strshowsubscribers</a></span>";
310da166 141 } else {
41b47dd4 142 echo '<span class="helplink">'.$streveryonecanchoose.'</span>';
501cdbd8 143 }
c032b59d 144
501cdbd8 145 if (forum_is_subscribed($USER->id, $forum->id)) {
6687be17 146 $subtexttitle = get_string("subscribestop", "forum");
31d160d3 147 $subtext = get_string("unsubscribe", "forum");
501cdbd8 148 } else {
6687be17 149 $subtexttitle = get_string("subscribestart", "forum");
31d160d3 150 $subtext = get_string("subscribe", "forum");
501cdbd8 151 }
9197e147 152 echo "<br />";
41b47dd4 153 echo "<span class=\"helplink\"><a title=\"$subtexttitle\" href=\"subscribe.php?id=$forum->id\">$subtext</a></span>";
bffb106d 154 }
8adcb49f 155
eaf50aef 156 if (forum_tp_can_track_forums($forum) && ($forum->trackingtype == FORUM_TRACKING_OPTIONAL)) {
157 if (forum_tp_is_tracked($forum, $USER->id)) {
45293cd3 158 $trtitle = get_string('notrackforum', 'forum');
159 $trackedlink = '<a title="'.get_string('notrackforum', 'forum').'" href="settracking.php?id='.
160 $forum->id.'&returnpage=view.php">'.get_string('notrackforum', 'forum').'</a>';
161 } else {
162 $trtitle = get_string('trackforum', 'forum');
163 $trackedlink = '<a title="'.get_string('trackforum', 'forum').'" href="settracking.php?id='.
164 $forum->id.'&returnpage=view.php">'.get_string('trackforum', 'forum').'</a>';
165 }
166 echo "<br />";
167 echo "<span class=\"helplink\">$trackedlink</span>";
168 }
169
f4646b44 170 echo '</td>';
171 }
8adcb49f 172
f4646b44 173 //If rss are activated at site and forum level and this forum has rss defined, show link
174 if (isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) &&
175 $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds && $forum->rsstype and $forum->rssarticles) {
176 echo '</tr><tr><td align="right">';
177 if ($forum->rsstype == 1) {
3849dae8 178 $tooltiptext = get_string("rsssubscriberssdiscussions","forum",format_string($forum->name));
680afe2e 179 } else {
3849dae8 180 $tooltiptext = get_string("rsssubscriberssposts","forum",format_string($forum->name));
f4646b44 181 }
182 if (empty($USER->id)) {
183 $userid = 0;
184 } else {
185 $userid = $USER->id;
186 }
187 rss_print_link($course->id, $userid, "forum", $forum->id, $tooltiptext);
9197e147 188 echo '</td>';
f93f848a 189 }
190
9197e147 191 echo '</tr></table>';
192
f064a3df 193 $forum->intro = trim($forum->intro);
e07635f4 194
195 switch ($forum->type) {
9197e147 196 case 'single':
501cdbd8 197 if (! $discussion = get_record("forum_discussions", "forum", $forum->id)) {
198 if ($discussions = get_records("forum_discussions", "forum", $forum->id, "timemodified ASC")) {
199 notify("Warning! There is more than one discussion in this forum - using the most recent");
200 $discussion = array_pop($discussions);
201 } else {
202 error("Could not find the discussion in this forum");
203 }
204 }
11b0c469 205 if (! $post = forum_get_post_full($discussion->firstpost)) {
501cdbd8 206 error("Could not find the first post in this forum");
207 }
5476a93d 208 if ($mode) {
209 set_user_preference("forum_displaymode", $mode);
210 }
211 $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
212 forum_print_discussion($course, $forum, $discussion, $post, $displaymode);
501cdbd8 213 break;
214
9197e147 215 case 'eachuser':
f064a3df 216 if (!empty($forum->intro)) {
b846ac39 217 print_simple_box(format_text($forum->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
c6ee38d0 218 }
9197e147 219 echo '<p align="center">';
11b0c469 220 if (forum_user_can_post_discussion($forum)) {
31d160d3 221 print_string("allowsdiscussions", "forum");
e07635f4 222 } else {
9197e147 223 echo '&nbsp';
e07635f4 224 }
9197e147 225 echo '</p>';
c6ee38d0 226 if (!empty($showall)) {
af328e4b 227 forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode);
c6ee38d0 228 } else {
af328e4b 229 forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page);
c6ee38d0 230 }
231 break;
232
9197e147 233 case 'teacher':
3c8a606d 234 if (!empty($showall)) {
af328e4b 235 forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode);
3c8a606d 236 } else {
af328e4b 237 forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page);
3c8a606d 238 }
e07635f4 239 break;
240
241 default:
f064a3df 242 if (!empty($forum->intro)) {
b846ac39 243 print_simple_box(format_text($forum->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
c6ee38d0 244 }
61242972 245 echo '<br />';
3c8a606d 246 if (!empty($showall)) {
af328e4b 247 forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode);
3c8a606d 248 } else {
af328e4b 249 forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page);
3c8a606d 250 }
e07635f4 251 break;
252 }
253
f93f848a 254 print_footer($course);
255
41b47dd4 256?>