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