- Testing new permissions...
[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
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
580f2fbc 54 if ($forums = get_records("forum", "course", $id, "name ASC")) {
71fb9630 55 foreach ($forums as $forum) {
580f2fbc 56 $forum->visible = true;
37b15514 57 switch ($forum->type) {
0872b023 58 case "news":
59 case "social":
580f2fbc 60 $forum->visible = instance_is_visible("forum", $forum);
0872b023 61 $generalforums[] = $forum;
37b15514 62 break;
63 case "teacher":
64 if (isteacher($course->id)) {
65 $generalforums[] = $forum;
66 }
67 break;
94361e02 68 default:
69 if (!$course->category) {
70 $generalforums[] = $forum;
71 }
72 break;
71fb9630 73 }
37b15514 74 }
75 }
71fb9630 76
37b15514 77 if ($generalforums) {
78 foreach ($generalforums as $forum) {
501cdbd8 79 $count = count_records("forum_discussions", "forum", "$forum->id");
71fb9630 80
4b2b7a71 81 $forum->intro = forum_shorten_post($forum->intro);
82 replace_smilies($forum->intro);
83
580f2fbc 84 if ($forum->visible) {
85 $forumlink = "<a href=\"view.php?f=$forum->id\">$forum->name</a>";
3b0fb381 86 } else {
580f2fbc 87 $forumlink = "<a class=\"dimmed\" href=\"view.php?f=$forum->id\">$forum->name</a>";
3b0fb381 88 }
89
71fb9630 90 if ($can_subscribe) {
501cdbd8 91 if (forum_is_forcesubscribed($forum->id)) {
f781b794 92 $sublink = get_string("yes");
71fb9630 93 } else {
501cdbd8 94 if (forum_is_subscribed($USER->id, $forum->id)) {
f781b794 95 $subscribed = get_string("yes");
96 $subtitle = get_string("unsubscribe", "forum");
501cdbd8 97 } else {
f781b794 98 $subscribed = get_string("no");
99 $subtitle = get_string("subscribe", "forum");
501cdbd8 100 }
580f2fbc 101 $sublink = "<a title=\"$subtitle\" href=\"subscribe.php?id=$forum->id\">$subscribed</a>";
71fb9630 102 }
580f2fbc 103 $table->data[] = array ($forumlink, "$forum->intro", "$count", $sublink);
71fb9630 104 } else {
580f2fbc 105 $table->data[] = array ($forumlink, "$forum->intro", "$count");
71fb9630 106 }
107 }
f781b794 108 print_heading(get_string("generalforums", "forum"));
37b15514 109 print_table($table);
110 unset($table->data);
111 }
71fb9630 112
94361e02 113 if ($course->category) { // Only real courses have learning forums
114 // Add extra field for section number, at the front
115 array_unshift($table->head, "");
f5ca7ebe 116 array_unshift($table->align, "center");
94361e02 117
cccb016a 118 if ($learningforums = get_all_instances_in_course("forum", $course)) {
86c5e69a 119 foreach ($learningforums as $key => $forum) {
120 if ($forum->type == "news" or $forum->type == "social") {
121 unset($learningforums[$key]); // Remove these
122 }
123 }
124 }
125 if ($learningforums) {
94361e02 126 foreach ($learningforums as $forum) {
127 $count = count_records("forum_discussions", "forum", "$forum->id");
128
4b2b7a71 129 $forum->intro = forum_shorten_post($forum->intro);
130 replace_smilies($forum->intro);
94361e02 131
132 if (!$forum->section) { // some forums are in the "0" section
133 $forum->section = "";
134 }
3b0fb381 135
580f2fbc 136 if ($forum->visible) {
137 $forumlink = "<a href=\"view.php?f=$forum->id\">$forum->name</a>";
3b0fb381 138 } else {
580f2fbc 139 $forumlink = "<a class=\"dimmed\" href=\"view.php?f=$forum->id\">$forum->name</a>";
3b0fb381 140 }
580f2fbc 141
94361e02 142 if ($can_subscribe) {
143 if (forum_is_forcesubscribed($forum->id)) {
144 $sublink = get_string("yes");
501cdbd8 145 } else {
94361e02 146 if (forum_is_subscribed($USER->id, $forum->id)) {
147 $subscribed = get_string("yes");
148 $subtitle = get_string("unsubscribe", "forum");
149 } else {
150 $subscribed = get_string("no");
151 $subtitle = get_string("subscribe", "forum");
152 }
580f2fbc 153 $sublink = "<a title=\"$subtitle\" href=\"subscribe.php?id=$forum->id\">$subscribed</a>";
501cdbd8 154 }
580f2fbc 155 $table->data[] = array ("$forum->section", $forumlink, "$forum->intro", "$count", "$sublink");
94361e02 156 } else {
580f2fbc 157 $table->data[] = array ("$forum->section", $forumlink, "$forum->intro", "$count");
f93f848a 158 }
f93f848a 159 }
94361e02 160 print_heading(get_string("learningforums", "forum"));
161 print_table($table);
f93f848a 162 }
163 }
164
f93f848a 165
166 print_footer($course);
167
168?>