translated strings changed based on /en/moodle.php
[moodle.git] / mod / forum / index.php
CommitLineData
41905731 1<?php // $Id$
f93f848a 2
b0e3a925 3 require_once("../../config.php");
4 require_once("lib.php");
33f48f03 5 require_once("$CFG->dirroot/rss/rsslib.php");
f93f848a 6
7 optional_variable($id); // course
8
9 if ($id) {
10 if (! $course = get_record("course", "id", $id)) {
11 error("Course ID is incorrect");
12 }
13 } else {
f781b794 14 if (! $course = get_site()) {
f93f848a 15 error("Could not find a top-level course!");
16 }
17 }
18
68ddf8bc 19 if ($CFG->forcelogin) {
20 require_login();
21 }
22
f93f848a 23 if ($course->category) {
24 require_login($course->id);
25 }
26
ecc8403e 27 $currentgroup = get_current_group($course->id);
28
501cdbd8 29 unset($SESSION->fromdiscussion);
f93f848a 30
f781b794 31 add_to_log($course->id, "forum", "view forums", "index.php?id=$course->id");
32
33 $strforums = get_string("forums", "forum");
97485d07 34 $strforum = get_string("forum", "forum");
35 $strdescription = get_string("description");
36 $strdiscussions = get_string("discussions", "forum");
37 $strsubscribed = get_string("subscribed", "forum");
33f48f03 38 $strrss = get_string("rss");
97485d07 39
40 $searchform = forum_print_search_form($course, "", true, "plain");
f93f848a 41
f781b794 42
38fcc215 43 // Start of the table for General Forums
f781b794 44
fa5a5b52 45 $generaltable->head = array ($strforum, $strdescription, $strdiscussions);
839f2456 46 $generaltable->align = array ("left", "left", "center");
f93f848a 47
fa5a5b52 48 if ($can_subscribe = (isstudent($course->id) or isteacher($course->id) or isadmin())) {
49 $generaltable->head[] = $strsubscribed;
839f2456 50 $generaltable->align[] = "center";
f93f848a 51 }
f93f848a 52
33f48f03 53 if ($show_rss = ($can_subscribe && isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) &&
54 $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds)) {
55 $generaltable->head[] = $strrss;
839f2456 56 $generaltable->align[] = "center";
33f48f03 57 }
58
fa5a5b52 59
ecc8403e 60 // Parse and organise all the forums. Most forums are course modules but
61 // some special ones are not. These get placed in the general forums
62 // category with the forums in section 0.
63
64 $generalforums = array(); // For now
65 $learningforums = get_all_instances_in_course("forum", $course);
66
67 if ($forums = get_records("forum", "course", $id, "name ASC")) { // All known forums
68
69 if ($learningforums) { // Copy "full" data into this complete array
bd83d0a3 70 foreach ($learningforums as $key => $learningforum) {
71 $learningforum->keyreference = $key;
a0a4a3c9 72 $forums[$learningforum->id] = $learningforum;
ecc8403e 73 }
74 }
fa5a5b52 75
71fb9630 76 foreach ($forums as $forum) {
a0a4a3c9 77 if (!isset($forum->visible)) {
9c8b8eee 78 $forum->visible = instance_is_visible("forum", $forum);
79 if (!$forum->visible and !isteacher($course->id)) {
80 if (isset($forum->keyreference)) {
81 unset($learningforums[$forum->keyreference]);
82 }
83 continue;
84 }
a0a4a3c9 85 }
37b15514 86 switch ($forum->type) {
0872b023 87 case "news":
88 case "social":
89 $generalforums[] = $forum;
bd83d0a3 90 if (isset($forum->keyreference)) { // Should always be
91 unset($learningforums[$forum->keyreference]);
ecc8403e 92 }
37b15514 93 break;
94 case "teacher":
95 if (isteacher($course->id)) {
ecc8403e 96 $forum->visible = true;
37b15514 97 $generalforums[] = $forum;
98 }
99 break;
94361e02 100 default:
a0a4a3c9 101 if (!$course->category or empty($forum->section)) { // Site level or section 0
94361e02 102 $generalforums[] = $forum;
bd83d0a3 103 if (isset($forum->keyreference)) {
104 unset($learningforums[$forum->keyreference]);
a0a4a3c9 105 }
106 }
94361e02 107 break;
71fb9630 108 }
37b15514 109 }
110 }
71fb9630 111
ecc8403e 112 /// First, let's process the general forums and build up a display
113
114 if ($generalforums) {
115 foreach ($generalforums as $forum) {
116 if (isset($forum->groupmode)) {
117 $groupmode = groupmode($course, $forum); /// Can do this because forum->groupmode is defined
118 } else {
119 $groupmode = NOGROUPS;
120 }
121
122 if ($groupmode == SEPARATEGROUPS and !isteacheredit($course->id)) {
2862b309 123 $count = count_records_select("forum_discussions", "forum = '$forum->id' AND (groupid = '$currentgroup' OR groupid = '-1')");
ecc8403e 124 } else {
125 $count = count_records("forum_discussions", "forum", "$forum->id");
126 }
127
128 $forum->intro = forum_shorten_post($forum->intro);
129 replace_smilies($forum->intro);
130 $forum->intro = "<span style=\"font-size:x-small;\">$forum->intro</span>";;
131
132 if ($forum->visible) {
133 $forumlink = "<a href=\"view.php?f=$forum->id\">$forum->name</a>";
134 } else {
135 $forumlink = "<a class=\"dimmed\" href=\"view.php?f=$forum->id\">$forum->name</a>";
136 }
137
138 if ($can_subscribe) {
139 if (forum_is_forcesubscribed($forum->id)) {
140 $sublink = get_string("yes");
141 } else {
142 if ($groupmode and !isteacheredit($course->id) and !mygroupid($course->id)) {
143 $sublink = get_string("no"); // Can't subscribe to a group forum (not in a group)
144 $forumlink = $forum->name;
145 } else {
146 if (forum_is_subscribed($USER->id, $forum->id)) {
147 $subscribed = get_string("yes");
148 $subtitle = get_string("unsubscribe", "forum");
149 } else {
150 $subscribed = get_string("no");
151 $subtitle = get_string("subscribe", "forum");
152 }
153 $sublink = "<a title=\"$subtitle\" href=\"subscribe.php?id=$forum->id\">$subscribed</a>";
154 }
155 }
33f48f03 156 //If this forum has RSS activated, calculate it
157 if ($show_rss) {
158 $rsslink = '';
159 if ($forum->rsstype and $forum->rssarticles) {
160 //Calculate the tolltip text
161 if ($forum->rsstype == 1) {
162 $tooltiptext = get_string("rsssubscriberssdiscussions","forum",$forum->name);
163 } else {
164 $tooltiptext = get_string("rsssubscriberssposts","forum",$forum->name);
165 }
166 //Get html code for RSS link
167 $rsslink = rss_get_link($course->id, $USER->id, "forum", $forum->id, $tooltiptext);
168 }
169 //Save data
170 $generaltable->data[] = array ($forumlink, "$forum->intro", "$count", $sublink,$rsslink);
171 } else {
172 $generaltable->data[] = array ($forumlink, "$forum->intro", "$count", $sublink);
173 }
ecc8403e 174 } else {
175 $generaltable->data[] = array ($forumlink, "$forum->intro", "$count");
176 }
177 }
178 }
179
38fcc215 180
181 // Start of the table for Learning Forums
182 $learningtable->head = array ($strforum, $strdescription, $strdiscussions);
183 $learningtable->align = array ("left", "left", "center");
184
185 if ($can_subscribe = (isstudent($course->id) or isteacher($course->id) or isadmin())) {
186 $learningtable->head[] = $strsubscribed;
187 $learningtable->align[] = "center";
188 }
189
190 if ($show_rss = ($can_subscribe && isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) &&
191 $CFG->enablerssfeeds && $CFG->forum_enablerssfeeds)) {
192 $learningtable->head[] = $strrss;
193 $learningtable->align[] = "center";
194 }
195
bd83d0a3 196 /// Now let's process the learning forums
ecc8403e 197
94361e02 198 if ($course->category) { // Only real courses have learning forums
199 // Add extra field for section number, at the front
fa5a5b52 200 array_unshift($learningtable->head, "");
201 array_unshift($learningtable->align, "center");
94361e02 202
a0b9571f 203
86c5e69a 204 if ($learningforums) {
a0b9571f 205 $currentsection = "";
206
1390f203 207 foreach ($learningforums as $key => $forum) {
ecc8403e 208 $groupmode = groupmode($course, $forum); /// Can do this because forum->groupmode is defined
209
210 if ($groupmode == SEPARATEGROUPS and !isteacheredit($course->id)) {
5b5f2971 211 $count = count_records("forum_discussions", "forum", "$forum->id", "groupid", $currentgroup);
ecc8403e 212 } else {
213 $count = count_records("forum_discussions", "forum", "$forum->id");
214 }
94361e02 215
4b2b7a71 216 $forum->intro = forum_shorten_post($forum->intro);
217 replace_smilies($forum->intro);
ef6a649b 218 $forum->intro = "<span style=\"font-size:x-small;\">$forum->intro</span>";
94361e02 219
a0b9571f 220 if ($forum->section != $currentsection) {
221 $printsection = $forum->section;
ef6a649b 222 if ($currentsection) {
223 $learningtable->data[] = 'hr';
224 }
a0b9571f 225 $currentsection = $forum->section;
226 } else {
227 $printsection = "";
228 }
229
580f2fbc 230 if ($forum->visible) {
231 $forumlink = "<a href=\"view.php?f=$forum->id\">$forum->name</a>";
3b0fb381 232 } else {
580f2fbc 233 $forumlink = "<a class=\"dimmed\" href=\"view.php?f=$forum->id\">$forum->name</a>";
3b0fb381 234 }
580f2fbc 235
94361e02 236 if ($can_subscribe) {
237 if (forum_is_forcesubscribed($forum->id)) {
238 $sublink = get_string("yes");
501cdbd8 239 } else {
ecc8403e 240 if ($groupmode and !isteacheredit($course->id) and !mygroupid($course->id)) {
a0b9571f 241 $sublink = get_string("no"); // Can't subscribe to a group forum (not in a group)
bd83d0a3 242 if ($groupmode == SEPARATEGROUPS) {
243 $forumlink = $forum->name;
244 }
94361e02 245 } else {
a0b9571f 246 if (forum_is_subscribed($USER->id, $forum->id)) {
247 $subscribed = get_string("yes");
248 $subtitle = get_string("unsubscribe", "forum");
249 } else {
250 $subscribed = get_string("no");
251 $subtitle = get_string("subscribe", "forum");
252 }
253 $sublink = "<a title=\"$subtitle\" href=\"subscribe.php?id=$forum->id\">$subscribed</a>";
94361e02 254 }
501cdbd8 255 }
33f48f03 256 //If this forum has RSS activated, calculate it
257 if ($show_rss) {
258 $rsslink = '';
259 if ($forum->rsstype and $forum->rssarticles) {
260 //Calculate the tolltip text
261 if ($forum->rsstype == 1) {
262 $tooltiptext = get_string("rsssubscriberssdiscussions","forum",$forum->name);
263 } else {
264 $tooltiptext = get_string("rsssubscriberssposts","forum",$forum->name);
265 }
266 //Get html code for RSS link
267 $rsslink = rss_get_link($course->id, $USER->id, "forum", $forum->id, $tooltiptext);
268 }
269 //Save data
270 $learningtable->data[] = array ($printsection,$forumlink, "$forum->intro", "$count", $sublink,$rsslink);
271 } else {
272 $learningtable->data[] = array ($printsection,$forumlink, "$forum->intro", "$count", $sublink);
273 }
94361e02 274 } else {
a0b9571f 275 $learningtable->data[] = array ($printsection, $forumlink, "$forum->intro", "$count");
f93f848a 276 }
f93f848a 277 }
278 }
279 }
280
fa5a5b52 281
282 /// Output the page
283
284 if ($course->category) {
285 print_header("$course->shortname: $strforums", "$course->fullname",
38fcc215 286 "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> -> $strforums",
fa5a5b52 287 "", "", true, $searchform, navmenu($course));
288 } else {
289 print_header("$course->shortname: $strforums", "$course->fullname", "$strforums",
290 "", "", true, $searchform, navmenu($course));
291 }
292
6031fe85 293 if ($generalforums) {
294 print_heading(get_string("generalforums", "forum"));
295 print_table($generaltable);
296 }
fa5a5b52 297
6031fe85 298 if ($learningforums) {
299 print_heading(get_string("learningforums", "forum"));
300 print_table($learningtable);
301 }
f93f848a 302
303 print_footer($course);
304
305?>