Put $themename back again
[moodle.git] / mod / forum / index.php
CommitLineData
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
f781b794 34
fa5a5b52 35 // Build up the tables
f781b794 36
fa5a5b52 37 $generaltable->head = array ($strforum, $strdescription, $strdiscussions);
38 $generaltable->align = array ("LEFT", "LEFT", "CENTER");
f93f848a 39
fa5a5b52 40 if ($can_subscribe = (isstudent($course->id) or isteacher($course->id) or isadmin())) {
41 $generaltable->head[] = $strsubscribed;
42 $generaltable->align[] = "CENTER";
f93f848a 43 }
f93f848a 44
fa5a5b52 45 $learningtable = $generaltable; // Headers etc are the same
46
47 // Parse the forums
48
580f2fbc 49 if ($forums = get_records("forum", "course", $id, "name ASC")) {
71fb9630 50 foreach ($forums as $forum) {
580f2fbc 51 $forum->visible = true;
37b15514 52 switch ($forum->type) {
0872b023 53 case "news":
54 case "social":
580f2fbc 55 $forum->visible = instance_is_visible("forum", $forum);
0872b023 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
94361e02 72 if ($course->category) { // Only real courses have learning forums
73 // Add extra field for section number, at the front
fa5a5b52 74 array_unshift($learningtable->head, "");
75 array_unshift($learningtable->align, "center");
94361e02 76
cccb016a 77 if ($learningforums = get_all_instances_in_course("forum", $course)) {
86c5e69a 78 foreach ($learningforums as $key => $forum) {
79 if ($forum->type == "news" or $forum->type == "social") {
80 unset($learningforums[$key]); // Remove these
81 }
82 }
83 }
84 if ($learningforums) {
94361e02 85 foreach ($learningforums as $forum) {
86 $count = count_records("forum_discussions", "forum", "$forum->id");
87
4b2b7a71 88 $forum->intro = forum_shorten_post($forum->intro);
89 replace_smilies($forum->intro);
94361e02 90
fa5a5b52 91 if (!$forum->section) { // forums in the "0" section => generaltable
92 $generalforums[] = $forum;
93 continue;
94361e02 94 }
3b0fb381 95
580f2fbc 96 if ($forum->visible) {
97 $forumlink = "<a href=\"view.php?f=$forum->id\">$forum->name</a>";
3b0fb381 98 } else {
580f2fbc 99 $forumlink = "<a class=\"dimmed\" href=\"view.php?f=$forum->id\">$forum->name</a>";
3b0fb381 100 }
580f2fbc 101
94361e02 102 if ($can_subscribe) {
103 if (forum_is_forcesubscribed($forum->id)) {
104 $sublink = get_string("yes");
501cdbd8 105 } else {
94361e02 106 if (forum_is_subscribed($USER->id, $forum->id)) {
107 $subscribed = get_string("yes");
108 $subtitle = get_string("unsubscribe", "forum");
109 } else {
110 $subscribed = get_string("no");
111 $subtitle = get_string("subscribe", "forum");
112 }
580f2fbc 113 $sublink = "<a title=\"$subtitle\" href=\"subscribe.php?id=$forum->id\">$subscribed</a>";
501cdbd8 114 }
fa5a5b52 115 $learningtable->data[] = array ("$forum->section", $forumlink, "$forum->intro", "$count", "$sublink");
94361e02 116 } else {
fa5a5b52 117 $learningtable->data[] = array ("$forum->section", $forumlink, "$forum->intro", "$count");
f93f848a 118 }
f93f848a 119 }
120 }
121 }
122
fa5a5b52 123 if ($generalforums) {
124 foreach ($generalforums as $forum) {
125 $count = count_records("forum_discussions", "forum", "$forum->id");
126
127 $forum->intro = forum_shorten_post($forum->intro);
128 replace_smilies($forum->intro);
129
130 if ($forum->visible) {
131 $forumlink = "<a href=\"view.php?f=$forum->id\">$forum->name</a>";
132 } else {
133 $forumlink = "<a class=\"dimmed\" href=\"view.php?f=$forum->id\">$forum->name</a>";
134 }
135
136 if ($can_subscribe) {
137 if (forum_is_forcesubscribed($forum->id)) {
138 $sublink = get_string("yes");
139 } else {
140 if (forum_is_subscribed($USER->id, $forum->id)) {
141 $subscribed = get_string("yes");
142 $subtitle = get_string("unsubscribe", "forum");
143 } else {
144 $subscribed = get_string("no");
145 $subtitle = get_string("subscribe", "forum");
146 }
147 $sublink = "<a title=\"$subtitle\" href=\"subscribe.php?id=$forum->id\">$subscribed</a>";
148 }
149 $generaltable->data[] = array ($forumlink, "$forum->intro", "$count", $sublink);
150 } else {
151 $generaltable->data[] = array ($forumlink, "$forum->intro", "$count");
152 }
153 }
154 }
155
156
157 /// Output the page
158
159 if ($course->category) {
160 print_header("$course->shortname: $strforums", "$course->fullname",
161 "<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> -> $strforums",
162 "", "", true, $searchform, navmenu($course));
163 } else {
164 print_header("$course->shortname: $strforums", "$course->fullname", "$strforums",
165 "", "", true, $searchform, navmenu($course));
166 }
167
6031fe85 168 if ($generalforums) {
169 print_heading(get_string("generalforums", "forum"));
170 print_table($generaltable);
171 }
fa5a5b52 172
6031fe85 173 if ($learningforums) {
174 print_heading(get_string("learningforums", "forum"));
175 print_table($learningtable);
176 }
f93f848a 177
178 print_footer($course);
179
180?>