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