41905731 |
1 | <?php // $Id$ |
f93f848a |
2 | |
b0e3a925 |
3 | require_once("../../config.php"); |
4 | require_once("lib.php"); |
8adcb49f |
5 | require_once("$CFG->dirroot/rss/rsslib.php"); |
f93f848a |
6 | |
3c8a606d |
7 | optional_variable($id); // Course Module ID |
8 | optional_variable($f); // Forum ID |
9 | optional_variable($mode); // Display mode (for single forum) |
61e96406 |
10 | optional_variable($search, ""); // search string |
3c8a606d |
11 | optional_variable($showall, ""); // show all discussions on one page |
2ab76925 |
12 | optional_variable($group, -1); // choose the current group |
f6bb7eaa |
13 | optional_variable($page, "0"); // which page to show |
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 { |
69d79bc3 |
45 | $cm->id = NULL; |
d9bf513d |
46 | $buttontext = ""; |
47 | } |
f93f848a |
48 | |
49 | } else { |
50 | error("Must specify a course module or a forum ID"); |
51 | } |
52 | |
97485d07 |
53 | if (!$buttontext) { |
54 | $buttontext = forum_print_search_form($course, $search, true, "plain"); |
55 | } |
31d160d3 |
56 | |
68ddf8bc |
57 | if ($CFG->forcelogin) { |
58 | require_login(); |
59 | } |
60 | |
f93f848a |
61 | if ($course->category) { |
62 | require_login($course->id); |
90fcc576 |
63 | } |
64 | $navigation = "<a href=\"index.php?id=$course->id\">$strforums</a> ->"; |
f93f848a |
65 | |
82aa0e8d |
66 | if ($forum->type == "teacher") { |
67 | if (!isteacher($course->id)) { |
68 | error("You must be a $course->teacher to view this forum"); |
69 | } |
70 | } |
71 | |
e2c4f8e4 |
72 | if ($cm) { |
69d79bc3 |
73 | add_to_log($course->id, "forum", "view forum", "view.php?id=$cm->id", "$forum->id", $cm->id); |
e2c4f8e4 |
74 | } else { |
75 | add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id"); |
76 | } |
f93f848a |
77 | |
90fcc576 |
78 | print_header_simple("$forum->name", "", |
c6d234a0 |
79 | "$navigation $forum->name", "", "", true, $buttontext, navmenu($course, $cm)); |
f93f848a |
80 | |
3a4c2fd0 |
81 | if (!$cm->visible and !isteacher($course->id)) { |
82 | notice(get_string("activityiscurrentlyhidden")); |
83 | } |
84 | |
9197e147 |
85 | |
86 | /// Check to see if groups are being used in this forum |
87 | /// and if so, set $currentgroup to reflect the current group |
88 | |
2ab76925 |
89 | $changegroup = isset($_GET['group']) ? $_GET['group'] : -1; // Group change requested? |
52b201ee |
90 | |
91 | if ($forum->type == "teacher") { |
92 | $groupmode = NOGROUPS; |
93 | } else { |
94 | $groupmode = groupmode($course, $cm); // Groups are being used |
95 | } |
2ab76925 |
96 | $currentgroup = get_and_set_current_group($course, $groupmode, $changegroup); |
9197e147 |
97 | |
2ab76925 |
98 | if ($groupmode and ($currentgroup === false) and !isteacheredit($course->id)) { |
99 | print_heading(get_string("notingroup", "forum")); |
100 | print_footer($course); |
9197e147 |
101 | exit; |
102 | } |
103 | |
104 | |
105 | /// Print settings and things in a table across the top |
106 | |
107 | echo '<table width="100%" border="0" cellpadding="3" cellspacing="0"><tr valign="top">'; |
108 | |
109 | if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) { |
110 | if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) { |
111 | echo '<td>'; |
6ff27f32 |
112 | print_group_menu($groups, $groupmode, $currentgroup, "view.php?id=$cm->id"); |
9197e147 |
113 | echo '</td>'; |
114 | } |
115 | } |
116 | |
117 | |
f93f848a |
118 | if ($USER) { |
9197e147 |
119 | echo '<td align="right">'; |
501cdbd8 |
120 | $SESSION->fromdiscussion = "$FULLME"; |
121 | if (forum_is_forcesubscribed($forum->id)) { |
31d160d3 |
122 | $streveryoneissubscribed = get_string("everyoneissubscribed", "forum"); |
123 | $strallowchoice = get_string("allowchoice", "forum"); |
c032b59d |
124 | helpbutton("subscription", $streveryoneissubscribed, "forum"); |
41905731 |
125 | echo "<font size=\"1\">"; |
501cdbd8 |
126 | if (isteacher($course->id)) { |
839f2456 |
127 | echo "<a title=\"$strallowchoice\" href=\"subscribe.php?id=$forum->id&force=no\">$streveryoneissubscribed</a>"; |
501cdbd8 |
128 | } else { |
c032b59d |
129 | echo $streveryoneissubscribed; |
501cdbd8 |
130 | } |
9197e147 |
131 | echo "</font>"; |
501cdbd8 |
132 | |
f93f848a |
133 | } else { |
31d160d3 |
134 | $streveryonecanchoose = get_string("everyonecanchoose", "forum"); |
135 | $strforcesubscribe = get_string("forcesubscribe", "forum"); |
136 | $strshowsubscribers = get_string("showsubscribers", "forum"); |
c032b59d |
137 | |
c032b59d |
138 | helpbutton("subscription", $streveryonecanchoose, "forum"); |
41905731 |
139 | echo "<font size=\"1\">"; |
c032b59d |
140 | |
501cdbd8 |
141 | if (isteacher($course->id)) { |
839f2456 |
142 | echo "<a title=\"$strforcesubscribe\" href=\"subscribe.php?id=$forum->id&force=yes\">$streveryonecanchoose</a>"; |
41905731 |
143 | echo "</font><br /><font size=\"1\">"; |
c032b59d |
144 | echo "<a href=\"subscribers.php?id=$forum->id\">$strshowsubscribers</a>"; |
310da166 |
145 | } else { |
c032b59d |
146 | echo $streveryonecanchoose; |
501cdbd8 |
147 | } |
9197e147 |
148 | echo "</font>"; |
c032b59d |
149 | |
501cdbd8 |
150 | if (forum_is_subscribed($USER->id, $forum->id)) { |
6687be17 |
151 | $subtexttitle = get_string("subscribestop", "forum"); |
31d160d3 |
152 | $subtext = get_string("unsubscribe", "forum"); |
501cdbd8 |
153 | } else { |
6687be17 |
154 | $subtexttitle = get_string("subscribestart", "forum"); |
31d160d3 |
155 | $subtext = get_string("subscribe", "forum"); |
501cdbd8 |
156 | } |
9197e147 |
157 | echo "<br />"; |
41905731 |
158 | echo "<font size=\"1\"><a title=\"$subtexttitle\" href=\"subscribe.php?id=$forum->id\">$subtext</a></font>"; |
bffb106d |
159 | } |
8adcb49f |
160 | |
161 | //If rss are activated at site and forum level and this forum has rss defined, show link |
2e506e60 |
162 | if (isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) && |
163 | $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds && $forum->rsstype and $forum->rssarticles) { |
8adcb49f |
164 | echo "<br />"; |
165 | if ($forum->rsstype == 1) { |
166 | $tooltiptext = get_string("rsssubscriberssdiscussions","forum",$forum->name); |
167 | } else { |
168 | $tooltiptext = get_string("rsssubscriberssposts","forum",$forum->name); |
169 | } |
170 | rss_print_link($course->id, $USER->id, "forum", $forum->id, $tooltiptext); |
171 | } |
172 | |
9197e147 |
173 | echo '</td>'; |
f93f848a |
174 | } |
175 | |
9197e147 |
176 | echo '</tr></table>'; |
177 | |
f064a3df |
178 | $forum->intro = trim($forum->intro); |
e07635f4 |
179 | |
180 | switch ($forum->type) { |
9197e147 |
181 | case 'single': |
501cdbd8 |
182 | if (! $discussion = get_record("forum_discussions", "forum", $forum->id)) { |
183 | if ($discussions = get_records("forum_discussions", "forum", $forum->id, "timemodified ASC")) { |
184 | notify("Warning! There is more than one discussion in this forum - using the most recent"); |
185 | $discussion = array_pop($discussions); |
186 | } else { |
187 | error("Could not find the discussion in this forum"); |
188 | } |
189 | } |
11b0c469 |
190 | if (! $post = forum_get_post_full($discussion->firstpost)) { |
501cdbd8 |
191 | error("Could not find the first post in this forum"); |
192 | } |
5476a93d |
193 | if ($mode) { |
194 | set_user_preference("forum_displaymode", $mode); |
195 | } |
196 | $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode); |
197 | forum_print_discussion($course, $forum, $discussion, $post, $displaymode); |
501cdbd8 |
198 | break; |
199 | |
9197e147 |
200 | case 'eachuser': |
f064a3df |
201 | if (!empty($forum->intro)) { |
51a55508 |
202 | print_simple_box(format_text($forum->intro), 'center'); |
c6ee38d0 |
203 | } |
9197e147 |
204 | echo '<p align="center">'; |
11b0c469 |
205 | if (forum_user_can_post_discussion($forum)) { |
31d160d3 |
206 | print_string("allowsdiscussions", "forum"); |
e07635f4 |
207 | } else { |
9197e147 |
208 | echo ' '; |
e07635f4 |
209 | } |
9197e147 |
210 | echo '</p>'; |
c6ee38d0 |
211 | if (!empty($showall)) { |
2862b309 |
212 | forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup, $groupmode); |
c6ee38d0 |
213 | } else { |
f6bb7eaa |
214 | forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page); |
c6ee38d0 |
215 | } |
216 | break; |
217 | |
9197e147 |
218 | case 'teacher': |
3c8a606d |
219 | if (!empty($showall)) { |
2862b309 |
220 | forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup, $groupmode); |
3c8a606d |
221 | } else { |
f6bb7eaa |
222 | forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page); |
3c8a606d |
223 | } |
e07635f4 |
224 | break; |
225 | |
226 | default: |
f064a3df |
227 | if (!empty($forum->intro)) { |
51a55508 |
228 | print_simple_box(format_text($forum->intro), 'center'); |
c6ee38d0 |
229 | } |
9197e147 |
230 | echo '<p> </p>'; |
3c8a606d |
231 | if (!empty($showall)) { |
2862b309 |
232 | forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup, $groupmode); |
3c8a606d |
233 | } else { |
f6bb7eaa |
234 | forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page); |
3c8a606d |
235 | } |
e07635f4 |
236 | break; |
237 | } |
238 | |
f93f848a |
239 | |
240 | print_footer($course); |
241 | |
242 | ?> |