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 | |
3b0fb381 |
54 | //Obtains all the forum data and visible field |
55 | if ($forums = get_records_sql("SELECT f.*,cm.visible as visible |
56 | FROM {$CFG->prefix}course_modules cm, |
f99d2368 |
57 | {$CFG->prefix}forum f, |
58 | {$CFG->prefix}modules md |
3b0fb381 |
59 | WHERE cm.course = '$id' AND |
60 | f.course = '$id' AND |
f99d2368 |
61 | md.name = 'forum' AND |
62 | md.id = cm.module AND |
3b0fb381 |
63 | f.id = cm.instance |
f99d2368 |
64 | ORDER BY f.name")) |
3b0fb381 |
65 | { |
71fb9630 |
66 | foreach ($forums as $forum) { |
37b15514 |
67 | switch ($forum->type) { |
0872b023 |
68 | case "news": |
69 | case "social": |
70 | $generalforums[] = $forum; |
37b15514 |
71 | break; |
72 | case "teacher": |
73 | if (isteacher($course->id)) { |
74 | $generalforums[] = $forum; |
75 | } |
76 | break; |
94361e02 |
77 | default: |
78 | if (!$course->category) { |
79 | $generalforums[] = $forum; |
80 | } |
81 | break; |
71fb9630 |
82 | } |
37b15514 |
83 | } |
84 | } |
71fb9630 |
85 | |
37b15514 |
86 | if ($generalforums) { |
87 | foreach ($generalforums as $forum) { |
501cdbd8 |
88 | $count = count_records("forum_discussions", "forum", "$forum->id"); |
71fb9630 |
89 | |
3b0fb381 |
90 | //Calculate the href |
91 | if (!$forum->visible) { |
92 | //Show dimmed if the mod is hidden |
93 | $tt_href = "<A class=\"dimmed\" HREF=\"view.php?f=$forum->id\">$forum->name</A>"; |
94 | } else { |
95 | //Show normal if the mod is visible |
96 | $tt_href = "<A HREF=\"view.php?f=$forum->id\">$forum->name</A>"; |
97 | } |
98 | |
71fb9630 |
99 | if ($can_subscribe) { |
501cdbd8 |
100 | if (forum_is_forcesubscribed($forum->id)) { |
f781b794 |
101 | $sublink = get_string("yes"); |
71fb9630 |
102 | } else { |
501cdbd8 |
103 | if (forum_is_subscribed($USER->id, $forum->id)) { |
f781b794 |
104 | $subscribed = get_string("yes"); |
105 | $subtitle = get_string("unsubscribe", "forum"); |
501cdbd8 |
106 | } else { |
f781b794 |
107 | $subscribed = get_string("no"); |
108 | $subtitle = get_string("subscribe", "forum"); |
501cdbd8 |
109 | } |
f781b794 |
110 | $sublink = "<A TITLE=\"$subtitle\" HREF=\"subscribe.php?id=$forum->id\">$subscribed</A>"; |
71fb9630 |
111 | } |
3b0fb381 |
112 | $table->data[] = array ($tt_href, "$forum->intro", "$count", "$sublink"); |
71fb9630 |
113 | } else { |
3b0fb381 |
114 | $table->data[] = array ($tt_href, "$forum->intro", "$count"); |
71fb9630 |
115 | } |
116 | } |
f781b794 |
117 | print_heading(get_string("generalforums", "forum")); |
37b15514 |
118 | print_table($table); |
119 | unset($table->data); |
120 | } |
71fb9630 |
121 | |
94361e02 |
122 | if ($course->category) { // Only real courses have learning forums |
123 | // Add extra field for section number, at the front |
124 | array_unshift($table->head, ""); |
125 | array_unshift($table->align, "CENTER"); |
126 | |
127 | if ($learningforums = get_all_instances_in_course("forum", $course->id)) { |
86c5e69a |
128 | foreach ($learningforums as $key => $forum) { |
129 | if ($forum->type == "news" or $forum->type == "social") { |
130 | unset($learningforums[$key]); // Remove these |
131 | } |
132 | } |
133 | } |
134 | if ($learningforums) { |
94361e02 |
135 | foreach ($learningforums as $forum) { |
136 | $count = count_records("forum_discussions", "forum", "$forum->id"); |
137 | |
138 | $forum->intro = forum_shorten_post($forum->intro); |
139 | |
140 | if (!$forum->section) { // some forums are in the "0" section |
141 | $forum->section = ""; |
142 | } |
3b0fb381 |
143 | |
144 | //Calculate the href |
145 | if (!$forum->visible) { |
146 | //Show dimmed if the mod is hidden |
147 | $tt_href = "<A class=\"dimmed\" HREF=\"view.php?f=$forum->id\">$forum->name</A>"; |
148 | } else { |
149 | //Show normal if the mod is visible |
150 | $tt_href = "<A HREF=\"view.php?f=$forum->id\">$forum->name</A>"; |
151 | } |
152 | |
94361e02 |
153 | if ($can_subscribe) { |
154 | if (forum_is_forcesubscribed($forum->id)) { |
155 | $sublink = get_string("yes"); |
501cdbd8 |
156 | } else { |
94361e02 |
157 | if (forum_is_subscribed($USER->id, $forum->id)) { |
158 | $subscribed = get_string("yes"); |
159 | $subtitle = get_string("unsubscribe", "forum"); |
160 | } else { |
161 | $subscribed = get_string("no"); |
162 | $subtitle = get_string("subscribe", "forum"); |
163 | } |
164 | $sublink = "<A TITLE=\"$subtitle\" HREF=\"subscribe.php?id=$forum->id\">$subscribed</A>"; |
501cdbd8 |
165 | } |
3b0fb381 |
166 | $table->data[] = array ("$forum->section", $tt_href, "$forum->intro", "$count", "$sublink"); |
94361e02 |
167 | } else { |
3b0fb381 |
168 | $table->data[] = array ("$forum->section", $tt_href, "$forum->intro", "$count"); |
f93f848a |
169 | } |
f93f848a |
170 | } |
94361e02 |
171 | print_heading(get_string("learningforums", "forum")); |
172 | print_table($table); |
f93f848a |
173 | } |
174 | } |
175 | |
f93f848a |
176 | |
177 | print_footer($course); |
178 | |
179 | ?> |