Got a bit slash-happy
[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
67 if ($USER) {
501cdbd8 68 $SESSION->fromdiscussion = "$FULLME";
69 if (forum_is_forcesubscribed($forum->id)) {
31d160d3 70 $streveryoneissubscribed = get_string("everyoneissubscribed", "forum");
71 $strallowchoice = get_string("allowchoice", "forum");
501cdbd8 72 if (isteacher($course->id)) {
73 echo "<DIV ALIGN=RIGHT><FONT SIZE=1>";
31d160d3 74 echo "<A TITLE=\"$strallowchoice\" HREF=\"subscribe.php?id=$forum->id&force=no\">$streveryoneissubscribed</A>";
501cdbd8 75 echo "</FONT></DIV>";
76 } else {
31d160d3 77 echo "<DIV ALIGN=RIGHT><FONT SIZE=1>$streveryoneissubscribed</FONT></DIV>";
501cdbd8 78 }
79
f93f848a 80 } else {
31d160d3 81 $streveryonecanchoose = get_string("everyonecanchoose", "forum");
82 $strforcesubscribe = get_string("forcesubscribe", "forum");
83 $strshowsubscribers = get_string("showsubscribers", "forum");
501cdbd8 84 if (isteacher($course->id)) {
85 echo "<DIV ALIGN=RIGHT><FONT SIZE=1>";
31d160d3 86 echo "<A TITLE=\"$strforcesubscribe\" HREF=\"subscribe.php?id=$forum->id&force=yes\">$streveryonecanchoose</A>";
501cdbd8 87 echo "</FONT></DIV>";
31d160d3 88 $subtext = "<A HREF=\"subscribers.php?id=$forum->id\">$strshowsubscribers</A>";
501cdbd8 89 echo "<DIV ALIGN=RIGHT><FONT SIZE=1>$subtext</FONT></DIV>";
310da166 90 } else {
31d160d3 91 echo "<DIV ALIGN=RIGHT><FONT SIZE=1>$streveryonecanchoose</FONT></DIV>";
501cdbd8 92 }
93 if (forum_is_subscribed($USER->id, $forum->id)) {
31d160d3 94 $subtext = get_string("unsubscribe", "forum");
501cdbd8 95 } else {
31d160d3 96 $subtext = get_string("subscribe", "forum");
501cdbd8 97 }
31d160d3 98 $subtext = "<A HREF=\"subscribe.php?id=$forum->id\">$subtext</A>";
501cdbd8 99 echo "<DIV ALIGN=RIGHT><FONT SIZE=1>$subtext</FONT></DIV>";
bffb106d 100 }
f93f848a 101 }
102
e07635f4 103
104 switch ($forum->type) {
501cdbd8 105 case "single":
106 if (! $discussion = get_record("forum_discussions", "forum", $forum->id)) {
107 if ($discussions = get_records("forum_discussions", "forum", $forum->id, "timemodified ASC")) {
108 notify("Warning! There is more than one discussion in this forum - using the most recent");
109 $discussion = array_pop($discussions);
110 } else {
111 error("Could not find the discussion in this forum");
112 }
113 }
11b0c469 114 if (! $post = forum_get_post_full($discussion->firstpost)) {
501cdbd8 115 error("Could not find the first post in this forum");
116 }
117 forum_set_display_mode($mode);
fe25fc9b 118 forum_print_discussion($course, $forum, $discussion, $post, $USER->mode);
501cdbd8 119 break;
120
e07635f4 121 case "eachuser":
501cdbd8 122 print_simple_box(text_to_html($forum->intro), "CENTER");
e07635f4 123 echo "<P ALIGN=CENTER>";
11b0c469 124 if (forum_user_can_post_discussion($forum)) {
31d160d3 125 print_string("allowsdiscussions", "forum");
e07635f4 126 } else {
127 echo "&nbsp";
128 }
129 echo "</P>";
3c8a606d 130 if (!empty($showall)) {
131 forum_print_latest_discussions($forum->id, 0, "header");
132 } else {
133 forum_print_latest_discussions($forum->id, FORUM_MANY_DISCUSSIONS, "header");
134 }
e07635f4 135 break;
136
137 default:
501cdbd8 138 print_simple_box(text_to_html($forum->intro), "CENTER");
e07635f4 139 echo "<P>&nbsp;</P>";
3c8a606d 140 if (!empty($showall)) {
141 forum_print_latest_discussions($forum->id, 0, "header");
142 } else {
143 forum_print_latest_discussions($forum->id, FORUM_MANY_DISCUSSIONS, "header");
144 }
e07635f4 145 break;
146 }
147
f93f848a 148
149 print_footer($course);
150
151?>