Changed listing of forums
[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) {
71fb9630 35 $newtable->head = array ("Forum", "Description", "Topics", "Subscribed");
f93f848a 36 } else {
71fb9630 37 $newtable->head = array ("Forum", "Description", "Topics");
f93f848a 38 }
71fb9630 39 $newtable->align = array ("LEFT", "LEFT", "CENTER", "CENTER");
40
f93f848a 41
42 if ($forums = get_records("forum", "course", $id, "name ASC")) {
71fb9630 43 $table = $newtable;
44 foreach ($forums as $forum) {
45 if ($forum->type == "teacher") {
46 if (!isteacher($course->id)) {
47 continue;
48 }
49 }
50 if ($forum->type == "eachuser" or $forum->type == "discussion") {
51 continue; // Display these later on.
52 }
53
54 $count = count_records("discuss", "forum", "$forum->id");
55
56 if ($can_subscribe) {
57 if (is_subscribed($USER->id, $forum->id)) {
58 $subscribed = "YES";
59 } else {
60 $subscribed = "NO";
61 }
62 $table->data[] = array ("<A HREF=\"view.php?f=$forum->id\">$forum->name</A>",
63 "$forum->intro",
64 "$count",
65 "<A HREF=\"subscribe.php?id=$forum->id\">$subscribed</A>");
66 } else {
67 $table->data[] = array ("<A HREF=\"view.php?f=$forum->id\">$forum->name</A>",
68 "$forum->intro",
69 "$count");
70 }
71 }
72 if ($table) {
73 print_heading("General Forums");
74 print_table($table);
75 $table = $newtable;
76 }
77
f93f848a 78 foreach ($forums as $forum) {
82aa0e8d 79 if ($forum->type == "teacher") {
80 if (!isteacher($course->id)) {
81 continue;
82 }
83 }
71fb9630 84 if ($forum->type != "eachuser" and $forum->type != "discussion") {
85 continue;
86 }
87
f93f848a 88 $count = count_records("discuss", "forum", "$forum->id");
89
90 if ($can_subscribe) {
91 if (is_subscribed($USER->id, $forum->id)) {
92 $subscribed = "YES";
93 } else {
94 $subscribed = "NO";
95 }
96 $table->data[] = array ("<A HREF=\"view.php?f=$forum->id\">$forum->name</A>",
97 "$forum->intro",
98 "$count",
99 "<A HREF=\"subscribe.php?id=$forum->id\">$subscribed</A>");
100 } else {
101 $table->data[] = array ("<A HREF=\"view.php?f=$forum->id\">$forum->name</A>",
102 "$forum->intro",
103 "$count");
104 }
105 }
71fb9630 106 if ($table) {
107 print_heading("Forums about course content");
108 print_table($table);
109 }
f93f848a 110 }
111
bec7ff3e 112 echo "<DIV ALIGN=CENTER>";
113 print_discussion_search_form($course, $search);
114 echo "</DIV>";
f93f848a 115
116 print_footer($course);
117
118?>