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 | |
1390f203 |
88 | foreach ($learningforums as $key => $forum) { |
94361e02 |
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; |
1390f203 |
97 | unset($learningforums[$key]); |
fa5a5b52 |
98 | continue; |
94361e02 |
99 | } |
3b0fb381 |
100 | |
a0b9571f |
101 | if ($forum->section != $currentsection) { |
102 | $printsection = $forum->section; |
ef6a649b |
103 | if ($currentsection) { |
104 | $learningtable->data[] = 'hr'; |
105 | } |
a0b9571f |
106 | $currentsection = $forum->section; |
107 | } else { |
108 | $printsection = ""; |
109 | } |
110 | |
580f2fbc |
111 | if ($forum->visible) { |
112 | $forumlink = "<a href=\"view.php?f=$forum->id\">$forum->name</a>"; |
3b0fb381 |
113 | } else { |
580f2fbc |
114 | $forumlink = "<a class=\"dimmed\" href=\"view.php?f=$forum->id\">$forum->name</a>"; |
3b0fb381 |
115 | } |
580f2fbc |
116 | |
94361e02 |
117 | if ($can_subscribe) { |
118 | if (forum_is_forcesubscribed($forum->id)) { |
119 | $sublink = get_string("yes"); |
501cdbd8 |
120 | } else { |
c585ba8b |
121 | if (groupmode($course, $forum) and !isteacheredit($course->id) and !mygroupid($course->id)) { |
a0b9571f |
122 | $sublink = get_string("no"); // Can't subscribe to a group forum (not in a group) |
c585ba8b |
123 | $forumlink = $forum->name; |
94361e02 |
124 | } else { |
a0b9571f |
125 | if (forum_is_subscribed($USER->id, $forum->id)) { |
126 | $subscribed = get_string("yes"); |
127 | $subtitle = get_string("unsubscribe", "forum"); |
128 | } else { |
129 | $subscribed = get_string("no"); |
130 | $subtitle = get_string("subscribe", "forum"); |
131 | } |
132 | $sublink = "<a title=\"$subtitle\" href=\"subscribe.php?id=$forum->id\">$subscribed</a>"; |
94361e02 |
133 | } |
501cdbd8 |
134 | } |
a0b9571f |
135 | $learningtable->data[] = array ($printsection, $forumlink, "$forum->intro", "$count", "$sublink"); |
94361e02 |
136 | } else { |
a0b9571f |
137 | $learningtable->data[] = array ($printsection, $forumlink, "$forum->intro", "$count"); |
f93f848a |
138 | } |
f93f848a |
139 | } |
140 | } |
141 | } |
142 | |
fa5a5b52 |
143 | if ($generalforums) { |
144 | foreach ($generalforums as $forum) { |
145 | $count = count_records("forum_discussions", "forum", "$forum->id"); |
146 | |
147 | $forum->intro = forum_shorten_post($forum->intro); |
148 | replace_smilies($forum->intro); |
36c23cd6 |
149 | $forum->intro = "<span style=\"font-size:x-small;\">$forum->intro</span>";; |
fa5a5b52 |
150 | |
151 | if ($forum->visible) { |
152 | $forumlink = "<a href=\"view.php?f=$forum->id\">$forum->name</a>"; |
153 | } else { |
154 | $forumlink = "<a class=\"dimmed\" href=\"view.php?f=$forum->id\">$forum->name</a>"; |
155 | } |
156 | |
157 | if ($can_subscribe) { |
158 | if (forum_is_forcesubscribed($forum->id)) { |
159 | $sublink = get_string("yes"); |
160 | } else { |
c585ba8b |
161 | if (groupmode($course, $forum) and !isteacheredit($course->id) and !mygroupid($course->id)) { |
a0b9571f |
162 | $sublink = get_string("no"); // Can't subscribe to a group forum (not in a group) |
c585ba8b |
163 | $forumlink = $forum->name; |
fa5a5b52 |
164 | } else { |
a0b9571f |
165 | if (forum_is_subscribed($USER->id, $forum->id)) { |
166 | $subscribed = get_string("yes"); |
167 | $subtitle = get_string("unsubscribe", "forum"); |
168 | } else { |
169 | $subscribed = get_string("no"); |
170 | $subtitle = get_string("subscribe", "forum"); |
171 | } |
172 | $sublink = "<a title=\"$subtitle\" href=\"subscribe.php?id=$forum->id\">$subscribed</a>"; |
fa5a5b52 |
173 | } |
fa5a5b52 |
174 | } |
175 | $generaltable->data[] = array ($forumlink, "$forum->intro", "$count", $sublink); |
176 | } else { |
177 | $generaltable->data[] = array ($forumlink, "$forum->intro", "$count"); |
178 | } |
179 | } |
180 | } |
181 | |
182 | |
183 | /// Output the page |
184 | |
185 | if ($course->category) { |
186 | print_header("$course->shortname: $strforums", "$course->fullname", |
187 | "<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> -> $strforums", |
188 | "", "", true, $searchform, navmenu($course)); |
189 | } else { |
190 | print_header("$course->shortname: $strforums", "$course->fullname", "$strforums", |
191 | "", "", true, $searchform, navmenu($course)); |
192 | } |
193 | |
6031fe85 |
194 | if ($generalforums) { |
195 | print_heading(get_string("generalforums", "forum")); |
196 | print_table($generaltable); |
197 | } |
fa5a5b52 |
198 | |
6031fe85 |
199 | if ($learningforums) { |
200 | print_heading(get_string("learningforums", "forum")); |
201 | print_table($learningtable); |
202 | } |
f93f848a |
203 | |
204 | print_footer($course); |
205 | |
206 | ?> |