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); |
f93f848a |
23 | |
f781b794 |
24 | add_to_log($course->id, "forum", "view forums", "index.php?id=$course->id"); |
25 | |
26 | $strforums = get_string("forums", "forum"); |
f93f848a |
27 | |
28 | if ($course->category) { |
f781b794 |
29 | print_header("$course->shortname: $strforums", "$course->fullname", |
30 | "<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> -> $strforums"); |
f93f848a |
31 | } else { |
f781b794 |
32 | print_header("$course->shortname: $strforums", "$course->fullname", "$strforums"); |
f93f848a |
33 | } |
f781b794 |
34 | $strforum = get_string("forum", "forum"); |
35 | $strdescription = get_string("description", "forum"); |
36 | $strdiscussions = get_string("discussions", "forum"); |
37 | $strsubscribed = get_string("subscribed", "forum"); |
38 | |
39 | $table->head = array ($strforum, $strdescription, $strdiscussions); |
40 | $table->align = array ("LEFT", "LEFT", "CENTER"); |
41 | |
42 | $can_subscribe = (isstudent($course->id) or isteacher($course->id) or isadmin()); |
f93f848a |
43 | |
f93f848a |
44 | if ($can_subscribe) { |
f781b794 |
45 | $table->head[] = $strsubscribed; |
46 | $table->align[] = "CENTER"; |
f93f848a |
47 | } |
f93f848a |
48 | |
49 | if ($forums = get_records("forum", "course", $id, "name ASC")) { |
71fb9630 |
50 | foreach ($forums as $forum) { |
37b15514 |
51 | switch ($forum->type) { |
0872b023 |
52 | case "news": |
53 | case "social": |
54 | $generalforums[] = $forum; |
37b15514 |
55 | break; |
56 | case "teacher": |
57 | if (isteacher($course->id)) { |
58 | $generalforums[] = $forum; |
59 | } |
60 | break; |
71fb9630 |
61 | } |
37b15514 |
62 | } |
63 | } |
71fb9630 |
64 | |
37b15514 |
65 | if ($generalforums) { |
66 | foreach ($generalforums as $forum) { |
501cdbd8 |
67 | $count = count_records("forum_discussions", "forum", "$forum->id"); |
71fb9630 |
68 | |
69 | if ($can_subscribe) { |
501cdbd8 |
70 | if (forum_is_forcesubscribed($forum->id)) { |
f781b794 |
71 | $sublink = get_string("yes"); |
71fb9630 |
72 | } else { |
501cdbd8 |
73 | if (forum_is_subscribed($USER->id, $forum->id)) { |
f781b794 |
74 | $subscribed = get_string("yes"); |
75 | $subtitle = get_string("unsubscribe", "forum"); |
501cdbd8 |
76 | } else { |
f781b794 |
77 | $subscribed = get_string("no"); |
78 | $subtitle = get_string("subscribe", "forum"); |
501cdbd8 |
79 | } |
f781b794 |
80 | $sublink = "<A TITLE=\"$subtitle\" HREF=\"subscribe.php?id=$forum->id\">$subscribed</A>"; |
71fb9630 |
81 | } |
82 | $table->data[] = array ("<A HREF=\"view.php?f=$forum->id\">$forum->name</A>", |
501cdbd8 |
83 | "$forum->intro", "$count", "$sublink"); |
71fb9630 |
84 | } else { |
85 | $table->data[] = array ("<A HREF=\"view.php?f=$forum->id\">$forum->name</A>", |
501cdbd8 |
86 | "$forum->intro", "$count"); |
71fb9630 |
87 | } |
88 | } |
f781b794 |
89 | print_heading(get_string("generalforums", "forum")); |
37b15514 |
90 | print_table($table); |
91 | unset($table->data); |
92 | } |
71fb9630 |
93 | |
f781b794 |
94 | // Add extra field for section number, at the front |
95 | array_unshift($table->head, ""); |
96 | array_unshift($table->align, "CENTER"); |
0872b023 |
97 | |
f781b794 |
98 | if ($learningforums = get_all_instances_in_course("forum", $course->id)) { |
99 | foreach ($learningforums as $forum) { |
501cdbd8 |
100 | $count = count_records("forum_discussions", "forum", "$forum->id"); |
f93f848a |
101 | |
aa153f29 |
102 | $forum->intro = forum_shorten_post($forum->intro); |
103 | |
f93f848a |
104 | if ($can_subscribe) { |
501cdbd8 |
105 | if (forum_is_forcesubscribed($forum->id)) { |
f781b794 |
106 | $sublink = get_string("yes"); |
f93f848a |
107 | } else { |
501cdbd8 |
108 | if (forum_is_subscribed($USER->id, $forum->id)) { |
f781b794 |
109 | $subscribed = get_string("yes"); |
110 | $subtitle = get_string("unsubscribe", "forum"); |
501cdbd8 |
111 | } else { |
f781b794 |
112 | $subscribed = get_string("no"); |
113 | $subtitle = get_string("subscribe", "forum"); |
501cdbd8 |
114 | } |
f781b794 |
115 | $sublink = "<A TITLE=\"$subtitle\" HREF=\"subscribe.php?id=$forum->id\">$subscribed</A>"; |
f93f848a |
116 | } |
0872b023 |
117 | $table->data[] = array ("$forum->section", "<A HREF=\"view.php?f=$forum->id\">$forum->name</A>", |
501cdbd8 |
118 | "$forum->intro", "$count", "$sublink"); |
f93f848a |
119 | } else { |
0872b023 |
120 | $table->data[] = array ("$forum->section", "<A HREF=\"view.php?f=$forum->id\">$forum->name</A>", |
501cdbd8 |
121 | "$forum->intro", "$count"); |
f93f848a |
122 | } |
123 | } |
f781b794 |
124 | print_heading(get_string("learningforums", "forum")); |
37b15514 |
125 | print_table($table); |
f93f848a |
126 | } |
127 | |
bec7ff3e |
128 | echo "<DIV ALIGN=CENTER>"; |
7a12aab4 |
129 | forum_print_search_form($course, $search); |
bec7ff3e |
130 | echo "</DIV>"; |
f93f848a |
131 | |
132 | print_footer($course); |
133 | |
134 | ?> |