This file is not linked to or used by anything yet, but I've found it
[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
501cdbd8 22 unset($SESSION->fromdiscussion);
f93f848a 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) {
37b15514 35 $table->head = array ("Forum", "Description", "Topics", "Subscribed");
f93f848a 36 } else {
37b15514 37 $table->head = array ("Forum", "Description", "Topics");
f93f848a 38 }
37b15514 39 $table->align = array ("LEFT", "LEFT", "CENTER", "CENTER");
71fb9630 40
f93f848a 41
42 if ($forums = get_records("forum", "course", $id, "name ASC")) {
71fb9630 43 foreach ($forums as $forum) {
37b15514 44 switch ($forum->type) {
0872b023 45 case "news":
46 case "social":
47 $generalforums[] = $forum;
37b15514 48 break;
49 case "teacher":
50 if (isteacher($course->id)) {
51 $generalforums[] = $forum;
52 }
53 break;
71fb9630 54 }
37b15514 55 }
56 }
71fb9630 57
37b15514 58 if ($generalforums) {
59 foreach ($generalforums as $forum) {
501cdbd8 60 $count = count_records("forum_discussions", "forum", "$forum->id");
71fb9630 61
62 if ($can_subscribe) {
501cdbd8 63 if (forum_is_forcesubscribed($forum->id)) {
64 $sublink = "YES";
71fb9630 65 } else {
501cdbd8 66 if (forum_is_subscribed($USER->id, $forum->id)) {
67 $subscribed = "YES";
68 } else {
69 $subscribed = "NO";
70 }
71 $sublink = "<A TITLE=\"Change your subscription\" HREF=\"subscribe.php?id=$forum->id\">$subscribed</A>";
71fb9630 72 }
73 $table->data[] = array ("<A HREF=\"view.php?f=$forum->id\">$forum->name</A>",
501cdbd8 74 "$forum->intro", "$count", "$sublink");
71fb9630 75 } else {
76 $table->data[] = array ("<A HREF=\"view.php?f=$forum->id\">$forum->name</A>",
501cdbd8 77 "$forum->intro", "$count");
71fb9630 78 }
79 }
37b15514 80 print_heading("General Forums");
81 print_table($table);
82 unset($table->data);
83 }
71fb9630 84
0872b023 85 if ($can_subscribe) {
86 $table->head = array ("", "Forum", "Description", "Topics", "Subscribed");
87 } else {
88 $table->head = array ("", "Forum", "Description", "Topics");
89 }
90 $table->align = array ("CENTER", "LEFT", "LEFT", "CENTER", "CENTER");
91
92 if ($moduleforums = get_all_instances_in_course("forum", $course->id)) {
93 foreach ($moduleforums as $forum) {
501cdbd8 94 $count = count_records("forum_discussions", "forum", "$forum->id");
f93f848a 95
aa153f29 96 $forum->intro = forum_shorten_post($forum->intro);
97
f93f848a 98 if ($can_subscribe) {
501cdbd8 99 if (forum_is_forcesubscribed($forum->id)) {
100 $sublink = "YES";
f93f848a 101 } else {
501cdbd8 102 if (forum_is_subscribed($USER->id, $forum->id)) {
103 $subscribed = "YES";
104 } else {
105 $subscribed = "NO";
106 }
107 $sublink = "<A TITLE=\"Change your subscription\" HREF=\"subscribe.php?id=$forum->id\">$subscribed</A>";
f93f848a 108 }
0872b023 109 $table->data[] = array ("$forum->section", "<A HREF=\"view.php?f=$forum->id\">$forum->name</A>",
501cdbd8 110 "$forum->intro", "$count", "$sublink");
f93f848a 111 } else {
0872b023 112 $table->data[] = array ("$forum->section", "<A HREF=\"view.php?f=$forum->id\">$forum->name</A>",
501cdbd8 113 "$forum->intro", "$count");
f93f848a 114 }
115 }
37b15514 116 print_heading("Course content");
117 print_table($table);
f93f848a 118 }
119
bec7ff3e 120 echo "<DIV ALIGN=CENTER>";
501cdbd8 121 print_forum_search_form($course, $search);
bec7ff3e 122 echo "</DIV>";
f93f848a 123
124 print_footer($course);
125
126?>