Tweak
[moodle.git] / mod / forum / view.php
CommitLineData
f93f848a 1<?PHP // $Id$
2
b0e3a925 3 require_once("../../config.php");
4 require_once("lib.php");
f93f848a 5
3c8a606d 6 optional_variable($id); // Course Module ID
7 optional_variable($f); // Forum ID
8 optional_variable($mode); // Display mode (for single forum)
61e96406 9 optional_variable($search, ""); // search string
3c8a606d 10 optional_variable($showall, ""); // show all discussions on one page
f93f848a 11
09aebc94 12 $strforums = get_string("modulenameplural", "forum");
13 $strforum = get_string("modulename", "forum");
14
f93f848a 15 if ($id) {
16 if (! $cm = get_record("course_modules", "id", $id)) {
17 error("Course Module ID was incorrect");
18 }
19 if (! $course = get_record("course", "id", $cm->course)) {
20 error("Course is misconfigured");
21 }
22 if (! $forum = get_record("forum", "id", $cm->instance)) {
23 error("Forum ID was incorrect");
24 }
09aebc94 25 $buttontext = update_module_button($cm->id, $course->id, $strforum);
f93f848a 26
27 } else if ($f) {
28 if (! $forum = get_record("forum", "id", $f)) {
94361e02 29 error("Forum ID was incorrect or no longer exists");
f93f848a 30 }
31 if (! $course = get_record("course", "id", $forum->course)) {
32 error("Forum is misconfigured - don't know what course it's from");
33 }
d9bf513d 34 if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
09aebc94 35 $buttontext = update_module_button($cm->id, $course->id, $strforum);
d9bf513d 36 } else {
37 $buttontext = "";
38 }
f93f848a 39
40 } else {
41 error("Must specify a course module or a forum ID");
42 }
43
97485d07 44 if (!$buttontext) {
45 $buttontext = forum_print_search_form($course, $search, true, "plain");
46 }
31d160d3 47
f93f848a 48 if ($course->category) {
49 require_login($course->id);
50 $navigation = "<A HREF=\"../../course/view.php?id=$course->id\">$course->shortname</A> ->
31d160d3 51 <A HREF=\"index.php?id=$course->id\">$strforums</A> ->";
bffb106d 52 } else {
31d160d3 53 $navigation = "<A HREF=\"index.php?id=$course->id\">$strforums</A> ->";
f93f848a 54 }
55
82aa0e8d 56 if ($forum->type == "teacher") {
57 if (!isteacher($course->id)) {
58 error("You must be a $course->teacher to view this forum");
59 }
60 }
61
dd831125 62 add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id");
f93f848a 63
64 print_header("$course->shortname: $forum->name", "$course->fullname",
d897cae4 65 "$navigation $forum->name", "", "", true, $buttontext, navmenu($course, $cm));
f93f848a 66
3a4c2fd0 67 if (!$cm->visible and !isteacher($course->id)) {
68 notice(get_string("activityiscurrentlyhidden"));
69 }
70
f93f848a 71 if ($USER) {
501cdbd8 72 $SESSION->fromdiscussion = "$FULLME";
73 if (forum_is_forcesubscribed($forum->id)) {
31d160d3 74 $streveryoneissubscribed = get_string("everyoneissubscribed", "forum");
75 $strallowchoice = get_string("allowchoice", "forum");
c032b59d 76 echo "<div align=right>";
77 helpbutton("subscription", $streveryoneissubscribed, "forum");
78 echo "<font size=1>";
501cdbd8 79 if (isteacher($course->id)) {
c032b59d 80 echo "<a title=\"$strallowchoice\" href=\"subscribe.php?id=$forum->id&force=no\">$streveryoneissubscribed</a>";
501cdbd8 81 } else {
c032b59d 82 echo $streveryoneissubscribed;
501cdbd8 83 }
c032b59d 84 echo "</font></div>";
501cdbd8 85
f93f848a 86 } else {
31d160d3 87 $streveryonecanchoose = get_string("everyonecanchoose", "forum");
88 $strforcesubscribe = get_string("forcesubscribe", "forum");
89 $strshowsubscribers = get_string("showsubscribers", "forum");
c032b59d 90
91 echo "<div align=right>";
92 helpbutton("subscription", $streveryonecanchoose, "forum");
93 echo "<font size=1>";
94
501cdbd8 95 if (isteacher($course->id)) {
c032b59d 96 echo "<a title=\"$strforcesubscribe\" href=\"subscribe.php?id=$forum->id&force=yes\">$streveryonecanchoose</a>";
97 echo "</font></div><div align=right><font size=1>";
98 echo "<a href=\"subscribers.php?id=$forum->id\">$strshowsubscribers</a>";
310da166 99 } else {
c032b59d 100 echo $streveryonecanchoose;
501cdbd8 101 }
c032b59d 102 echo "</font></div>";
103
501cdbd8 104 if (forum_is_subscribed($USER->id, $forum->id)) {
6687be17 105 $subtexttitle = get_string("subscribestop", "forum");
31d160d3 106 $subtext = get_string("unsubscribe", "forum");
501cdbd8 107 } else {
6687be17 108 $subtexttitle = get_string("subscribestart", "forum");
31d160d3 109 $subtext = get_string("subscribe", "forum");
501cdbd8 110 }
c032b59d 111 echo "<div align=right>";
6687be17 112 echo "<font size=1><a title=\"$subtexttitle\" href=\"subscribe.php?id=$forum->id\">$subtext</a></font>";
c032b59d 113 echo "</div>";
bffb106d 114 }
f93f848a 115 }
116
e07635f4 117
118 switch ($forum->type) {
501cdbd8 119 case "single":
120 if (! $discussion = get_record("forum_discussions", "forum", $forum->id)) {
121 if ($discussions = get_records("forum_discussions", "forum", $forum->id, "timemodified ASC")) {
122 notify("Warning! There is more than one discussion in this forum - using the most recent");
123 $discussion = array_pop($discussions);
124 } else {
125 error("Could not find the discussion in this forum");
126 }
127 }
11b0c469 128 if (! $post = forum_get_post_full($discussion->firstpost)) {
501cdbd8 129 error("Could not find the first post in this forum");
130 }
131 forum_set_display_mode($mode);
fe25fc9b 132 forum_print_discussion($course, $forum, $discussion, $post, $USER->mode);
501cdbd8 133 break;
134
e07635f4 135 case "eachuser":
501cdbd8 136 print_simple_box(text_to_html($forum->intro), "CENTER");
e07635f4 137 echo "<P ALIGN=CENTER>";
11b0c469 138 if (forum_user_can_post_discussion($forum)) {
31d160d3 139 print_string("allowsdiscussions", "forum");
e07635f4 140 } else {
141 echo "&nbsp";
142 }
143 echo "</P>";
3c8a606d 144 if (!empty($showall)) {
145 forum_print_latest_discussions($forum->id, 0, "header");
146 } else {
147 forum_print_latest_discussions($forum->id, FORUM_MANY_DISCUSSIONS, "header");
148 }
e07635f4 149 break;
150
151 default:
501cdbd8 152 print_simple_box(text_to_html($forum->intro), "CENTER");
e07635f4 153 echo "<P>&nbsp;</P>";
3c8a606d 154 if (!empty($showall)) {
155 forum_print_latest_discussions($forum->id, 0, "header");
156 } else {
157 forum_print_latest_discussions($forum->id, FORUM_MANY_DISCUSSIONS, "header");
158 }
e07635f4 159 break;
160 }
161
f93f848a 162
163 print_footer($course);
164
165?>