moodle/mod/forum/index.php

169 lines
6.2 KiB
PHP
Raw Normal View History

<?PHP // $Id$
require_once("../../config.php");
require_once("lib.php");
optional_variable($id); // course
if ($id) {
if (! $course = get_record("course", "id", $id)) {
error("Course ID is incorrect");
}
} else {
if (! $course = get_site()) {
error("Could not find a top-level course!");
}
}
if ($course->category) {
require_login($course->id);
}
unset($SESSION->fromdiscussion);
add_to_log($course->id, "forum", "view forums", "index.php?id=$course->id");
$strforums = get_string("forums", "forum");
$strforum = get_string("forum", "forum");
$strdescription = get_string("description");
$strdiscussions = get_string("discussions", "forum");
$strsubscribed = get_string("subscribed", "forum");
$searchform = forum_print_search_form($course, "", true, "plain");
if ($course->category) {
print_header("$course->shortname: $strforums", "$course->fullname",
2002-11-10 08:43:44 +00:00
"<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> -> $strforums",
"", "", true, $searchform, navmenu($course));
} else {
print_header("$course->shortname: $strforums", "$course->fullname", "$strforums",
"", "", true, $searchform, navmenu($course));
}
$table->head = array ($strforum, $strdescription, $strdiscussions);
$table->align = array ("LEFT", "LEFT", "CENTER");
$can_subscribe = (isstudent($course->id) or isteacher($course->id) or isadmin());
if ($can_subscribe) {
$table->head[] = $strsubscribed;
$table->align[] = "CENTER";
}
if ($forums = get_records("forum", "course", $id, "name ASC")) {
2002-07-20 17:56:21 +00:00
foreach ($forums as $forum) {
$forum->visible = true;
2002-07-20 18:20:19 +00:00
switch ($forum->type) {
2002-07-31 16:13:55 +00:00
case "news":
case "social":
$forum->visible = instance_is_visible("forum", $forum);
2002-07-31 16:13:55 +00:00
$generalforums[] = $forum;
2002-07-20 18:20:19 +00:00
break;
case "teacher":
if (isteacher($course->id)) {
$generalforums[] = $forum;
}
break;
default:
if (!$course->category) {
$generalforums[] = $forum;
}
break;
2002-07-20 17:56:21 +00:00
}
2002-07-20 18:20:19 +00:00
}
}
2002-07-20 17:56:21 +00:00
2002-07-20 18:20:19 +00:00
if ($generalforums) {
foreach ($generalforums as $forum) {
$count = count_records("forum_discussions", "forum", "$forum->id");
2002-07-20 17:56:21 +00:00
$forum->intro = forum_shorten_post($forum->intro);
replace_smilies($forum->intro);
if ($forum->visible) {
$forumlink = "<a href=\"view.php?f=$forum->id\">$forum->name</a>";
} else {
$forumlink = "<a class=\"dimmed\" href=\"view.php?f=$forum->id\">$forum->name</a>";
}
2002-07-20 17:56:21 +00:00
if ($can_subscribe) {
if (forum_is_forcesubscribed($forum->id)) {
$sublink = get_string("yes");
2002-07-20 17:56:21 +00:00
} else {
if (forum_is_subscribed($USER->id, $forum->id)) {
$subscribed = get_string("yes");
$subtitle = get_string("unsubscribe", "forum");
} else {
$subscribed = get_string("no");
$subtitle = get_string("subscribe", "forum");
}
$sublink = "<a title=\"$subtitle\" href=\"subscribe.php?id=$forum->id\">$subscribed</a>";
2002-07-20 17:56:21 +00:00
}
$table->data[] = array ($forumlink, "$forum->intro", "$count", $sublink);
2002-07-20 17:56:21 +00:00
} else {
$table->data[] = array ($forumlink, "$forum->intro", "$count");
2002-07-20 17:56:21 +00:00
}
}
print_heading(get_string("generalforums", "forum"));
2002-07-20 18:20:19 +00:00
print_table($table);
unset($table->data);
}
2002-07-20 17:56:21 +00:00
if ($course->category) { // Only real courses have learning forums
// Add extra field for section number, at the front
array_unshift($table->head, "");
2003-05-23 04:51:28 +00:00
array_unshift($table->align, "center");
if ($learningforums = get_all_instances_in_course("forum", $course)) {
foreach ($learningforums as $key => $forum) {
if ($forum->type == "news" or $forum->type == "social") {
unset($learningforums[$key]); // Remove these
}
}
}
if ($learningforums) {
foreach ($learningforums as $forum) {
$count = count_records("forum_discussions", "forum", "$forum->id");
$forum->intro = forum_shorten_post($forum->intro);
replace_smilies($forum->intro);
if (!$forum->section) { // some forums are in the "0" section
$forum->section = "";
}
if ($forum->visible) {
$forumlink = "<a href=\"view.php?f=$forum->id\">$forum->name</a>";
} else {
$forumlink = "<a class=\"dimmed\" href=\"view.php?f=$forum->id\">$forum->name</a>";
}
if ($can_subscribe) {
if (forum_is_forcesubscribed($forum->id)) {
$sublink = get_string("yes");
} else {
if (forum_is_subscribed($USER->id, $forum->id)) {
$subscribed = get_string("yes");
$subtitle = get_string("unsubscribe", "forum");
} else {
$subscribed = get_string("no");
$subtitle = get_string("subscribe", "forum");
}
$sublink = "<a title=\"$subtitle\" href=\"subscribe.php?id=$forum->id\">$subscribed</a>";
}
$table->data[] = array ("$forum->section", $forumlink, "$forum->intro", "$count", "$sublink");
} else {
$table->data[] = array ("$forum->section", $forumlink, "$forum->intro", "$count");
}
}
print_heading(get_string("learningforums", "forum"));
print_table($table);
}
}
print_footer($course);
?>