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 | |
34 | if ($course->category) { |
f781b794 |
35 | print_header("$course->shortname: $strforums", "$course->fullname", |
dfc9ba9b |
36 | "<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> -> $strforums", |
97485d07 |
37 | "", "", true, $searchform, navmenu($course)); |
f93f848a |
38 | } else { |
97485d07 |
39 | print_header("$course->shortname: $strforums", "$course->fullname", "$strforums", |
40 | "", "", true, $searchform, navmenu($course)); |
f93f848a |
41 | } |
97485d07 |
42 | |
f781b794 |
43 | |
44 | $table->head = array ($strforum, $strdescription, $strdiscussions); |
45 | $table->align = array ("LEFT", "LEFT", "CENTER"); |
46 | |
47 | $can_subscribe = (isstudent($course->id) or isteacher($course->id) or isadmin()); |
f93f848a |
48 | |
f93f848a |
49 | if ($can_subscribe) { |
f781b794 |
50 | $table->head[] = $strsubscribed; |
51 | $table->align[] = "CENTER"; |
f93f848a |
52 | } |
f93f848a |
53 | |
580f2fbc |
54 | if ($forums = get_records("forum", "course", $id, "name ASC")) { |
71fb9630 |
55 | foreach ($forums as $forum) { |
580f2fbc |
56 | $forum->visible = true; |
37b15514 |
57 | switch ($forum->type) { |
0872b023 |
58 | case "news": |
59 | case "social": |
580f2fbc |
60 | $forum->visible = instance_is_visible("forum", $forum); |
0872b023 |
61 | $generalforums[] = $forum; |
37b15514 |
62 | break; |
63 | case "teacher": |
64 | if (isteacher($course->id)) { |
65 | $generalforums[] = $forum; |
66 | } |
67 | break; |
94361e02 |
68 | default: |
69 | if (!$course->category) { |
70 | $generalforums[] = $forum; |
71 | } |
72 | break; |
71fb9630 |
73 | } |
37b15514 |
74 | } |
75 | } |
71fb9630 |
76 | |
37b15514 |
77 | if ($generalforums) { |
78 | foreach ($generalforums as $forum) { |
501cdbd8 |
79 | $count = count_records("forum_discussions", "forum", "$forum->id"); |
71fb9630 |
80 | |
580f2fbc |
81 | if ($forum->visible) { |
82 | $forumlink = "<a href=\"view.php?f=$forum->id\">$forum->name</a>"; |
3b0fb381 |
83 | } else { |
580f2fbc |
84 | $forumlink = "<a class=\"dimmed\" href=\"view.php?f=$forum->id\">$forum->name</a>"; |
3b0fb381 |
85 | } |
86 | |
71fb9630 |
87 | if ($can_subscribe) { |
501cdbd8 |
88 | if (forum_is_forcesubscribed($forum->id)) { |
f781b794 |
89 | $sublink = get_string("yes"); |
71fb9630 |
90 | } else { |
501cdbd8 |
91 | if (forum_is_subscribed($USER->id, $forum->id)) { |
f781b794 |
92 | $subscribed = get_string("yes"); |
93 | $subtitle = get_string("unsubscribe", "forum"); |
501cdbd8 |
94 | } else { |
f781b794 |
95 | $subscribed = get_string("no"); |
96 | $subtitle = get_string("subscribe", "forum"); |
501cdbd8 |
97 | } |
580f2fbc |
98 | $sublink = "<a title=\"$subtitle\" href=\"subscribe.php?id=$forum->id\">$subscribed</a>"; |
71fb9630 |
99 | } |
580f2fbc |
100 | $table->data[] = array ($forumlink, "$forum->intro", "$count", $sublink); |
71fb9630 |
101 | } else { |
580f2fbc |
102 | $table->data[] = array ($forumlink, "$forum->intro", "$count"); |
71fb9630 |
103 | } |
104 | } |
f781b794 |
105 | print_heading(get_string("generalforums", "forum")); |
37b15514 |
106 | print_table($table); |
107 | unset($table->data); |
108 | } |
71fb9630 |
109 | |
94361e02 |
110 | if ($course->category) { // Only real courses have learning forums |
111 | // Add extra field for section number, at the front |
112 | array_unshift($table->head, ""); |
f5ca7ebe |
113 | array_unshift($table->align, "center"); |
94361e02 |
114 | |
115 | if ($learningforums = get_all_instances_in_course("forum", $course->id)) { |
86c5e69a |
116 | foreach ($learningforums as $key => $forum) { |
117 | if ($forum->type == "news" or $forum->type == "social") { |
118 | unset($learningforums[$key]); // Remove these |
119 | } |
120 | } |
121 | } |
122 | if ($learningforums) { |
94361e02 |
123 | foreach ($learningforums as $forum) { |
124 | $count = count_records("forum_discussions", "forum", "$forum->id"); |
125 | |
f5ca7ebe |
126 | $forum->intro = format_text(forum_shorten_post($forum->intro)); |
94361e02 |
127 | |
128 | if (!$forum->section) { // some forums are in the "0" section |
129 | $forum->section = ""; |
130 | } |
3b0fb381 |
131 | |
580f2fbc |
132 | if ($forum->visible) { |
133 | $forumlink = "<a href=\"view.php?f=$forum->id\">$forum->name</a>"; |
3b0fb381 |
134 | } else { |
580f2fbc |
135 | $forumlink = "<a class=\"dimmed\" href=\"view.php?f=$forum->id\">$forum->name</a>"; |
3b0fb381 |
136 | } |
580f2fbc |
137 | |
94361e02 |
138 | if ($can_subscribe) { |
139 | if (forum_is_forcesubscribed($forum->id)) { |
140 | $sublink = get_string("yes"); |
501cdbd8 |
141 | } else { |
94361e02 |
142 | if (forum_is_subscribed($USER->id, $forum->id)) { |
143 | $subscribed = get_string("yes"); |
144 | $subtitle = get_string("unsubscribe", "forum"); |
145 | } else { |
146 | $subscribed = get_string("no"); |
147 | $subtitle = get_string("subscribe", "forum"); |
148 | } |
580f2fbc |
149 | $sublink = "<a title=\"$subtitle\" href=\"subscribe.php?id=$forum->id\">$subscribed</a>"; |
501cdbd8 |
150 | } |
580f2fbc |
151 | $table->data[] = array ("$forum->section", $forumlink, "$forum->intro", "$count", "$sublink"); |
94361e02 |
152 | } else { |
580f2fbc |
153 | $table->data[] = array ("$forum->section", $forumlink, "$forum->intro", "$count"); |
f93f848a |
154 | } |
f93f848a |
155 | } |
94361e02 |
156 | print_heading(get_string("learningforums", "forum")); |
157 | print_table($table); |
f93f848a |
158 | } |
159 | } |
160 | |
f93f848a |
161 | |
162 | print_footer($course); |
163 | |
164 | ?> |