f93f848a |
1 | <?PHP // $Id$ |
2 | |
b0e3a925 |
3 | require_once("../../config.php"); |
4 | require_once("lib.php"); |
f93f848a |
5 | |
6 | optional_variable($id); // course |
7 | |
8 | if ($id) { |
9 | if (! $course = get_record("course", "id", $id)) { |
10 | error("Course ID is incorrect"); |
11 | } |
12 | } else { |
f781b794 |
13 | if (! $course = get_site()) { |
f93f848a |
14 | error("Could not find a top-level course!"); |
15 | } |
16 | } |
17 | |
18 | if ($course->category) { |
19 | require_login($course->id); |
20 | } |
21 | |
501cdbd8 |
22 | unset($SESSION->fromdiscussion); |
f93f848a |
23 | |
f781b794 |
24 | add_to_log($course->id, "forum", "view forums", "index.php?id=$course->id"); |
25 | |
26 | $strforums = get_string("forums", "forum"); |
97485d07 |
27 | $strforum = get_string("forum", "forum"); |
28 | $strdescription = get_string("description"); |
29 | $strdiscussions = get_string("discussions", "forum"); |
30 | $strsubscribed = get_string("subscribed", "forum"); |
31 | |
32 | $searchform = forum_print_search_form($course, "", true, "plain"); |
f93f848a |
33 | |
f781b794 |
34 | |
fa5a5b52 |
35 | // Build up the tables |
f781b794 |
36 | |
fa5a5b52 |
37 | $generaltable->head = array ($strforum, $strdescription, $strdiscussions); |
38 | $generaltable->align = array ("LEFT", "LEFT", "CENTER"); |
f93f848a |
39 | |
fa5a5b52 |
40 | if ($can_subscribe = (isstudent($course->id) or isteacher($course->id) or isadmin())) { |
41 | $generaltable->head[] = $strsubscribed; |
42 | $generaltable->align[] = "CENTER"; |
f93f848a |
43 | } |
f93f848a |
44 | |
fa5a5b52 |
45 | $learningtable = $generaltable; // Headers etc are the same |
46 | |
47 | // Parse the forums |
48 | |
580f2fbc |
49 | if ($forums = get_records("forum", "course", $id, "name ASC")) { |
71fb9630 |
50 | foreach ($forums as $forum) { |
580f2fbc |
51 | $forum->visible = true; |
37b15514 |
52 | switch ($forum->type) { |
0872b023 |
53 | case "news": |
54 | case "social": |
580f2fbc |
55 | $forum->visible = instance_is_visible("forum", $forum); |
0872b023 |
56 | $generalforums[] = $forum; |
37b15514 |
57 | break; |
58 | case "teacher": |
59 | if (isteacher($course->id)) { |
60 | $generalforums[] = $forum; |
61 | } |
62 | break; |
94361e02 |
63 | default: |
64 | if (!$course->category) { |
65 | $generalforums[] = $forum; |
66 | } |
67 | break; |
71fb9630 |
68 | } |
37b15514 |
69 | } |
70 | } |
71fb9630 |
71 | |
94361e02 |
72 | if ($course->category) { // Only real courses have learning forums |
73 | // Add extra field for section number, at the front |
fa5a5b52 |
74 | array_unshift($learningtable->head, ""); |
75 | array_unshift($learningtable->align, "center"); |
94361e02 |
76 | |
cccb016a |
77 | if ($learningforums = get_all_instances_in_course("forum", $course)) { |
86c5e69a |
78 | foreach ($learningforums as $key => $forum) { |
79 | if ($forum->type == "news" or $forum->type == "social") { |
80 | unset($learningforums[$key]); // Remove these |
81 | } |
82 | } |
83 | } |
a0b9571f |
84 | |
86c5e69a |
85 | if ($learningforums) { |
a0b9571f |
86 | $currentsection = ""; |
87 | |
94361e02 |
88 | foreach ($learningforums as $forum) { |
89 | $count = count_records("forum_discussions", "forum", "$forum->id"); |
90 | |
4b2b7a71 |
91 | $forum->intro = forum_shorten_post($forum->intro); |
92 | replace_smilies($forum->intro); |
ef6a649b |
93 | $forum->intro = "<span style=\"font-size:x-small;\">$forum->intro</span>"; |
94361e02 |
94 | |
fa5a5b52 |
95 | if (!$forum->section) { // forums in the "0" section => generaltable |
96 | $generalforums[] = $forum; |
97 | continue; |
94361e02 |
98 | } |
3b0fb381 |
99 | |
a0b9571f |
100 | if ($forum->section != $currentsection) { |
101 | $printsection = $forum->section; |
ef6a649b |
102 | if ($currentsection) { |
103 | $learningtable->data[] = 'hr'; |
104 | } |
a0b9571f |
105 | $currentsection = $forum->section; |
106 | } else { |
107 | $printsection = ""; |
108 | } |
109 | |
580f2fbc |
110 | if ($forum->visible) { |
111 | $forumlink = "<a href=\"view.php?f=$forum->id\">$forum->name</a>"; |
3b0fb381 |
112 | } else { |
580f2fbc |
113 | $forumlink = "<a class=\"dimmed\" href=\"view.php?f=$forum->id\">$forum->name</a>"; |
3b0fb381 |
114 | } |
580f2fbc |
115 | |
94361e02 |
116 | if ($can_subscribe) { |
117 | if (forum_is_forcesubscribed($forum->id)) { |
118 | $sublink = get_string("yes"); |
501cdbd8 |
119 | } else { |
c585ba8b |
120 | if (groupmode($course, $forum) and !isteacheredit($course->id) and !mygroupid($course->id)) { |
a0b9571f |
121 | $sublink = get_string("no"); // Can't subscribe to a group forum (not in a group) |
c585ba8b |
122 | $forumlink = $forum->name; |
94361e02 |
123 | } else { |
a0b9571f |
124 | if (forum_is_subscribed($USER->id, $forum->id)) { |
125 | $subscribed = get_string("yes"); |
126 | $subtitle = get_string("unsubscribe", "forum"); |
127 | } else { |
128 | $subscribed = get_string("no"); |
129 | $subtitle = get_string("subscribe", "forum"); |
130 | } |
131 | $sublink = "<a title=\"$subtitle\" href=\"subscribe.php?id=$forum->id\">$subscribed</a>"; |
94361e02 |
132 | } |
501cdbd8 |
133 | } |
a0b9571f |
134 | $learningtable->data[] = array ($printsection, $forumlink, "$forum->intro", "$count", "$sublink"); |
94361e02 |
135 | } else { |
a0b9571f |
136 | $learningtable->data[] = array ($printsection, $forumlink, "$forum->intro", "$count"); |
f93f848a |
137 | } |
f93f848a |
138 | } |
139 | } |
140 | } |
141 | |
fa5a5b52 |
142 | if ($generalforums) { |
143 | foreach ($generalforums as $forum) { |
144 | $count = count_records("forum_discussions", "forum", "$forum->id"); |
145 | |
146 | $forum->intro = forum_shorten_post($forum->intro); |
147 | replace_smilies($forum->intro); |
36c23cd6 |
148 | $forum->intro = "<span style=\"font-size:x-small;\">$forum->intro</span>";; |
fa5a5b52 |
149 | |
150 | if ($forum->visible) { |
151 | $forumlink = "<a href=\"view.php?f=$forum->id\">$forum->name</a>"; |
152 | } else { |
153 | $forumlink = "<a class=\"dimmed\" href=\"view.php?f=$forum->id\">$forum->name</a>"; |
154 | } |
155 | |
156 | if ($can_subscribe) { |
157 | if (forum_is_forcesubscribed($forum->id)) { |
158 | $sublink = get_string("yes"); |
159 | } else { |
c585ba8b |
160 | if (groupmode($course, $forum) and !isteacheredit($course->id) and !mygroupid($course->id)) { |
a0b9571f |
161 | $sublink = get_string("no"); // Can't subscribe to a group forum (not in a group) |
c585ba8b |
162 | $forumlink = $forum->name; |
fa5a5b52 |
163 | } else { |
a0b9571f |
164 | if (forum_is_subscribed($USER->id, $forum->id)) { |
165 | $subscribed = get_string("yes"); |
166 | $subtitle = get_string("unsubscribe", "forum"); |
167 | } else { |
168 | $subscribed = get_string("no"); |
169 | $subtitle = get_string("subscribe", "forum"); |
170 | } |
171 | $sublink = "<a title=\"$subtitle\" href=\"subscribe.php?id=$forum->id\">$subscribed</a>"; |
fa5a5b52 |
172 | } |
fa5a5b52 |
173 | } |
174 | $generaltable->data[] = array ($forumlink, "$forum->intro", "$count", $sublink); |
175 | } else { |
176 | $generaltable->data[] = array ($forumlink, "$forum->intro", "$count"); |
177 | } |
178 | } |
179 | } |
180 | |
181 | |
182 | /// Output the page |
183 | |
184 | if ($course->category) { |
185 | print_header("$course->shortname: $strforums", "$course->fullname", |
186 | "<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> -> $strforums", |
187 | "", "", true, $searchform, navmenu($course)); |
188 | } else { |
189 | print_header("$course->shortname: $strforums", "$course->fullname", "$strforums", |
190 | "", "", true, $searchform, navmenu($course)); |
191 | } |
192 | |
6031fe85 |
193 | if ($generalforums) { |
194 | print_heading(get_string("generalforums", "forum")); |
195 | print_table($generaltable); |
196 | } |
fa5a5b52 |
197 | |
6031fe85 |
198 | if ($learningforums) { |
199 | print_heading(get_string("learningforums", "forum")); |
200 | print_table($learningtable); |
201 | } |
f93f848a |
202 | |
203 | print_footer($course); |
204 | |
205 | ?> |