Mass change related to separating forum from discuss and making it a
[moodle.git] / mod / forum / index.php
CommitLineData
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 {
13 if (! $course = get_record("course", "category", 0)) {
14 error("Could not find a top-level course!");
15 }
16 }
17
18 if ($course->category) {
19 require_login($course->id);
20 }
21
22 unset($SESSION->fromdiscuss);
23
24 add_to_log($course->id, "forum", "view forums", "index.php?id=$course->id", "");
25
26 if ($course->category) {
27 print_header("$course->shortname: Forums", "$course->fullname",
28 "<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> -> Forums", "");
29 } else {
30 print_header("$course->shortname: Forums", "$course->fullname", "Forums", "");
31 }
32
33 $can_subscribe = (isstudent($course->id) || isteacher($course->id) || isadmin());
34 if ($can_subscribe) {
35 $table->head = array ("Forum", "Description", "Topics", "Subscribed");
36 } else {
37 $table->head = array ("Forum", "Description", "Topics");
38 }
39 $table->align = array ("LEFT", "LEFT", "CENTER", "CENTER");
40
41 if ($forums = get_records("forum", "course", $id, "name ASC")) {
42 foreach ($forums as $forum) {
43 $count = count_records("discuss", "forum", "$forum->id");
44
45 if ($can_subscribe) {
46 if (is_subscribed($USER->id, $forum->id)) {
47 $subscribed = "YES";
48 } else {
49 $subscribed = "NO";
50 }
51 $table->data[] = array ("<A HREF=\"view.php?f=$forum->id\">$forum->name</A>",
52 "$forum->intro",
53 "$count",
54 "<A HREF=\"subscribe.php?id=$forum->id\">$subscribed</A>");
55 } else {
56 $table->data[] = array ("<A HREF=\"view.php?f=$forum->id\">$forum->name</A>",
57 "$forum->intro",
58 "$count");
59 }
60 }
61 }
62
63 print_table($table);
64
65 print_footer($course);
66
67?>