f93f848a |
1 | <?PHP // $Id$ |
2 | |
b0e3a925 |
3 | require_once("../../config.php"); |
4 | require_once("lib.php"); |
f93f848a |
5 | |
3c8a606d |
6 | optional_variable($id); // Course Module ID |
7 | optional_variable($f); // Forum ID |
8 | optional_variable($mode); // Display mode (for single forum) |
61e96406 |
9 | optional_variable($search, ""); // search string |
3c8a606d |
10 | optional_variable($showall, ""); // show all discussions on one page |
2ab76925 |
11 | optional_variable($group, -1); // choose the current group |
f93f848a |
12 | |
13 | if ($id) { |
14 | if (! $cm = get_record("course_modules", "id", $id)) { |
15 | error("Course Module ID was incorrect"); |
16 | } |
17 | if (! $course = get_record("course", "id", $cm->course)) { |
18 | error("Course is misconfigured"); |
19 | } |
20 | if (! $forum = get_record("forum", "id", $cm->instance)) { |
21 | error("Forum ID was incorrect"); |
22 | } |
59c71151 |
23 | |
24 | $strforums = get_string("modulenameplural", "forum"); |
25 | $strforum = get_string("modulename", "forum"); |
26 | |
09aebc94 |
27 | $buttontext = update_module_button($cm->id, $course->id, $strforum); |
f93f848a |
28 | |
29 | } else if ($f) { |
30 | if (! $forum = get_record("forum", "id", $f)) { |
94361e02 |
31 | error("Forum ID was incorrect or no longer exists"); |
f93f848a |
32 | } |
33 | if (! $course = get_record("course", "id", $forum->course)) { |
34 | error("Forum is misconfigured - don't know what course it's from"); |
35 | } |
59c71151 |
36 | |
37 | $strforums = get_string("modulenameplural", "forum"); |
38 | $strforum = get_string("modulename", "forum"); |
39 | |
d9bf513d |
40 | if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { |
09aebc94 |
41 | $buttontext = update_module_button($cm->id, $course->id, $strforum); |
d9bf513d |
42 | } else { |
69d79bc3 |
43 | $cm->id = NULL; |
d9bf513d |
44 | $buttontext = ""; |
45 | } |
f93f848a |
46 | |
47 | } else { |
48 | error("Must specify a course module or a forum ID"); |
49 | } |
50 | |
97485d07 |
51 | if (!$buttontext) { |
52 | $buttontext = forum_print_search_form($course, $search, true, "plain"); |
53 | } |
31d160d3 |
54 | |
68ddf8bc |
55 | if ($CFG->forcelogin) { |
56 | require_login(); |
57 | } |
58 | |
f93f848a |
59 | if ($course->category) { |
60 | require_login($course->id); |
e2c4f8e4 |
61 | $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> -> |
62 | <a href=\"index.php?id=$course->id\">$strforums</a> ->"; |
bffb106d |
63 | } else { |
e2c4f8e4 |
64 | $navigation = "<a href=\"index.php?id=$course->id\">$strforums</a> ->"; |
f93f848a |
65 | } |
66 | |
82aa0e8d |
67 | if ($forum->type == "teacher") { |
68 | if (!isteacher($course->id)) { |
69 | error("You must be a $course->teacher to view this forum"); |
70 | } |
71 | } |
72 | |
e2c4f8e4 |
73 | if ($cm) { |
69d79bc3 |
74 | add_to_log($course->id, "forum", "view forum", "view.php?id=$cm->id", "$forum->id", $cm->id); |
e2c4f8e4 |
75 | } else { |
76 | add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id"); |
77 | } |
f93f848a |
78 | |
79 | print_header("$course->shortname: $forum->name", "$course->fullname", |
d897cae4 |
80 | "$navigation $forum->name", "", "", true, $buttontext, navmenu($course, $cm)); |
f93f848a |
81 | |
3a4c2fd0 |
82 | if (!$cm->visible and !isteacher($course->id)) { |
83 | notice(get_string("activityiscurrentlyhidden")); |
84 | } |
85 | |
9197e147 |
86 | |
87 | /// Check to see if groups are being used in this forum |
88 | /// and if so, set $currentgroup to reflect the current group |
89 | |
2ab76925 |
90 | $changegroup = isset($_GET['group']) ? $_GET['group'] : -1; // Group change requested? |
9197e147 |
91 | $groupmode = groupmode($course, $cm); // Groups are being used |
2ab76925 |
92 | $currentgroup = get_and_set_current_group($course, $groupmode, $changegroup); |
9197e147 |
93 | |
2ab76925 |
94 | if ($groupmode and ($currentgroup === false) and !isteacheredit($course->id)) { |
95 | print_heading(get_string("notingroup", "forum")); |
96 | print_footer($course); |
9197e147 |
97 | exit; |
98 | } |
99 | |
100 | |
101 | /// Print settings and things in a table across the top |
102 | |
103 | echo '<table width="100%" border="0" cellpadding="3" cellspacing="0"><tr valign="top">'; |
104 | |
105 | if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) { |
106 | if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) { |
107 | echo '<td>'; |
6ff27f32 |
108 | print_group_menu($groups, $groupmode, $currentgroup, "view.php?id=$cm->id"); |
9197e147 |
109 | echo '</td>'; |
110 | } |
111 | } |
112 | |
113 | |
f93f848a |
114 | if ($USER) { |
9197e147 |
115 | echo '<td align="right">'; |
501cdbd8 |
116 | $SESSION->fromdiscussion = "$FULLME"; |
117 | if (forum_is_forcesubscribed($forum->id)) { |
31d160d3 |
118 | $streveryoneissubscribed = get_string("everyoneissubscribed", "forum"); |
119 | $strallowchoice = get_string("allowchoice", "forum"); |
c032b59d |
120 | helpbutton("subscription", $streveryoneissubscribed, "forum"); |
121 | echo "<font size=1>"; |
501cdbd8 |
122 | if (isteacher($course->id)) { |
c032b59d |
123 | echo "<a title=\"$strallowchoice\" href=\"subscribe.php?id=$forum->id&force=no\">$streveryoneissubscribed</a>"; |
501cdbd8 |
124 | } else { |
c032b59d |
125 | echo $streveryoneissubscribed; |
501cdbd8 |
126 | } |
9197e147 |
127 | echo "</font>"; |
501cdbd8 |
128 | |
f93f848a |
129 | } else { |
31d160d3 |
130 | $streveryonecanchoose = get_string("everyonecanchoose", "forum"); |
131 | $strforcesubscribe = get_string("forcesubscribe", "forum"); |
132 | $strshowsubscribers = get_string("showsubscribers", "forum"); |
c032b59d |
133 | |
c032b59d |
134 | helpbutton("subscription", $streveryonecanchoose, "forum"); |
135 | echo "<font size=1>"; |
136 | |
501cdbd8 |
137 | if (isteacher($course->id)) { |
c032b59d |
138 | echo "<a title=\"$strforcesubscribe\" href=\"subscribe.php?id=$forum->id&force=yes\">$streveryonecanchoose</a>"; |
9197e147 |
139 | echo "</font><br /><font size=1>"; |
c032b59d |
140 | echo "<a href=\"subscribers.php?id=$forum->id\">$strshowsubscribers</a>"; |
310da166 |
141 | } else { |
c032b59d |
142 | echo $streveryonecanchoose; |
501cdbd8 |
143 | } |
9197e147 |
144 | echo "</font>"; |
c032b59d |
145 | |
501cdbd8 |
146 | if (forum_is_subscribed($USER->id, $forum->id)) { |
6687be17 |
147 | $subtexttitle = get_string("subscribestop", "forum"); |
31d160d3 |
148 | $subtext = get_string("unsubscribe", "forum"); |
501cdbd8 |
149 | } else { |
6687be17 |
150 | $subtexttitle = get_string("subscribestart", "forum"); |
31d160d3 |
151 | $subtext = get_string("subscribe", "forum"); |
501cdbd8 |
152 | } |
9197e147 |
153 | echo "<br />"; |
6687be17 |
154 | echo "<font size=1><a title=\"$subtexttitle\" href=\"subscribe.php?id=$forum->id\">$subtext</a></font>"; |
bffb106d |
155 | } |
9197e147 |
156 | echo '</td>'; |
f93f848a |
157 | } |
158 | |
9197e147 |
159 | echo '</tr></table>'; |
160 | |
f064a3df |
161 | $forum->intro = trim($forum->intro); |
e07635f4 |
162 | |
163 | switch ($forum->type) { |
9197e147 |
164 | case 'single': |
501cdbd8 |
165 | if (! $discussion = get_record("forum_discussions", "forum", $forum->id)) { |
166 | if ($discussions = get_records("forum_discussions", "forum", $forum->id, "timemodified ASC")) { |
167 | notify("Warning! There is more than one discussion in this forum - using the most recent"); |
168 | $discussion = array_pop($discussions); |
169 | } else { |
170 | error("Could not find the discussion in this forum"); |
171 | } |
172 | } |
11b0c469 |
173 | if (! $post = forum_get_post_full($discussion->firstpost)) { |
501cdbd8 |
174 | error("Could not find the first post in this forum"); |
175 | } |
5476a93d |
176 | if ($mode) { |
177 | set_user_preference("forum_displaymode", $mode); |
178 | } |
179 | $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode); |
180 | forum_print_discussion($course, $forum, $discussion, $post, $displaymode); |
501cdbd8 |
181 | break; |
182 | |
9197e147 |
183 | case 'eachuser': |
f064a3df |
184 | if (!empty($forum->intro)) { |
51a55508 |
185 | print_simple_box(format_text($forum->intro), 'center'); |
c6ee38d0 |
186 | } |
9197e147 |
187 | echo '<p align="center">'; |
11b0c469 |
188 | if (forum_user_can_post_discussion($forum)) { |
31d160d3 |
189 | print_string("allowsdiscussions", "forum"); |
e07635f4 |
190 | } else { |
9197e147 |
191 | echo ' '; |
e07635f4 |
192 | } |
9197e147 |
193 | echo '</p>'; |
c6ee38d0 |
194 | if (!empty($showall)) { |
9197e147 |
195 | forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup); |
c6ee38d0 |
196 | } else { |
9197e147 |
197 | forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup); |
c6ee38d0 |
198 | } |
199 | break; |
200 | |
9197e147 |
201 | case 'teacher': |
3c8a606d |
202 | if (!empty($showall)) { |
9197e147 |
203 | forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup); |
3c8a606d |
204 | } else { |
9197e147 |
205 | forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup); |
3c8a606d |
206 | } |
e07635f4 |
207 | break; |
208 | |
209 | default: |
f064a3df |
210 | if (!empty($forum->intro)) { |
51a55508 |
211 | print_simple_box(format_text($forum->intro), 'center'); |
c6ee38d0 |
212 | } |
9197e147 |
213 | echo '<p> </p>'; |
3c8a606d |
214 | if (!empty($showall)) { |
9197e147 |
215 | forum_print_latest_discussions($forum->id, 0, 'header', '', $currentgroup); |
3c8a606d |
216 | } else { |
9197e147 |
217 | forum_print_latest_discussions($forum->id, $CFG->forum_manydiscussions, 'header', '', $currentgroup); |
3c8a606d |
218 | } |
e07635f4 |
219 | break; |
220 | } |
221 | |
f93f848a |
222 | |
223 | print_footer($course); |
224 | |
225 | ?> |