Undo one line inserted by error in my previous commit
[moodle.git] / mod / forum / discuss.php
CommitLineData
501cdbd8 1<?PHP // $Id$
2
3// Displays a post, and all the posts below it.
4// If no post is given, displays all posts in a discussion
5
b0e3a925 6 require_once("../../config.php");
7 require_once("lib.php");
501cdbd8 8
9 require_variable($d); // Discussion ID
10 optional_variable($parent); // If set, then display this post and all children.
11 optional_variable($mode); // If set, changes the layout of the thread
1fc49f00 12 optional_variable($move); // If set, moves this discussion to another forum
501cdbd8 13
14 if (! $discussion = get_record("forum_discussions", "id", $d)) {
94361e02 15 error("Discussion ID was incorrect or no longer exists");
501cdbd8 16 }
17
18 if (! $course = get_record("course", "id", $discussion->course)) {
19 error("Course ID is incorrect - discussion is faulty");
20 }
21
1fc49f00 22 if ($course->category) {
23 require_login($course->id);
24 }
25
26 if (!empty($move)) {
27 if (!isteacher($course->id)) {
28 error("Only teachers can do that!");
29 }
30 if ($forum = get_record("forum", "id", $move)) {
cc2b7ea5 31 if (!forum_move_attachments($discussion, $move)) {
32 notify("Errors occurred while moving attachment directories - check your file permissions");
33 }
1fc49f00 34 set_field("forum_discussions", "forum", $forum->id, "id", $discussion->id);
35 $discussion->forum = $forum->id;
69d79bc3 36 if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
37 add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id",
38 $cm->id);
39 } else {
40 add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id");
41 }
8de14dc7 42 $discussionmoved = true;
1fc49f00 43 } else {
44 error("You can't move to that forum - it doesn't exist!");
45 }
46 }
47
48 if (empty($forum)) {
49 if (! $forum = get_record("forum", "id", $discussion->forum)) {
50 notify("Bad forum ID stored in this discussion");
51 }
501cdbd8 52 }
53
1fc49f00 54 $logparameters = "d=$discussion->id";
55 if ($parent) {
56 $logparameters .= "&parent=$parent";
501cdbd8 57 }
69d79bc3 58
59 if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
60 add_to_log($course->id, "forum", "view discussion", "discuss.php?$logparameters", "$discussion->id", $cm->id);
61 } else {
62 add_to_log($course->id, "forum", "view discussion", "discuss.php?$logparameters", "$discussion->id");
63 }
501cdbd8 64
65 unset($SESSION->fromdiscussion);
66
279826e2 67 if ($mode) {
68 set_user_preference("forum_displaymode", $mode);
69 }
501cdbd8 70
279826e2 71 $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
501cdbd8 72
e92ea3d8 73 if ($parent) {
279826e2 74 if (abs($displaymode) == 1) { // If flat AND parent, then force nested display this time
e92ea3d8 75 $displaymode = 3;
76 }
77 } else {
501cdbd8 78 $parent = $discussion->firstpost;
79 $navtail = "$discussion->name";
80 }
81
11b0c469 82 if (! $post = forum_get_post_full($parent)) {
501cdbd8 83 error("Discussion no longer exists", "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
84 }
85
61e96406 86 if (empty($navtail)) {
501cdbd8 87 $navtail = "<A HREF=\"discuss.php?d=$discussion->id\">$discussion->name</A> -> $post->subject";
88 }
89
f781b794 90 $navmiddle = "<A HREF=\"../forum/index.php?id=$course->id\">".get_string("forums", "forum")."</A> -> <A HREF=\"../forum/view.php?f=$forum->id\">$forum->name</A>";
501cdbd8 91
9c9f7d77 92 $searchform = forum_print_search_form($course, "", true, "plain");
97485d07 93
501cdbd8 94 if ($course->category) {
95 print_header("$course->shortname: $discussion->name", "$course->fullname",
96 "<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> ->
97485d07 97 $navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm));
501cdbd8 98 } else {
99 print_header("$course->shortname: $discussion->name", "$course->fullname",
97485d07 100 "$navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm));
501cdbd8 101 }
102
c6d691dc 103
9197e147 104/// Check to see if groups are being used in this forum
105/// If so, make sure the current person is allowed to see this discussion
c6d691dc 106/// Also, if we know they should be able to reply, then explicitly set $canreply
107
108 $canreply = NULL; /// No override one way or the other
9197e147 109
110 $groupmode = groupmode($course, $cm);
111
c6d691dc 112 if ($groupmode and !isteacheredit($course->id)) { // Groups must be kept separate
c6d691dc 113 if ($groupmode == SEPARATEGROUPS) {
114 require_login();
115
02509fe6 116 if (mygroupid($course->id) == $discussion->groupid) {
c6d691dc 117 $canreply = true;
118 } else {
119 print_heading("Sorry, you can't see this discussion because you are not in this group");
120 print_footer();
121 die;
122 }
123
124 } else if ($groupmode == VISIBLEGROUPS) {
02509fe6 125 $canreply = (mygroupid($course->id) == $discussion->groupid);
9197e147 126 }
127 }
128
129
c6d691dc 130/// Print the controls across the top
131
132 echo "<table width=\"100%\"><tr><td width=\"33%\">";
133
134 if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
135 if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
2ab76925 136 print_group_menu($groups, $groupmode, $discussion->groupid, "view.php?id=$cm->id&group=");
c6d691dc 137 }
138 }
139
140 echo "</td><td width=\"33%\">";
ec9c0d44 141 forum_print_mode_form($discussion->id, $displaymode);
c6d691dc 142
02ebf404 143 echo "</td><td width=\"33%\">";
1fc49f00 144 if (isteacher($course->id)) { // Popup menu to allow discussions to be moved to other forums
cccb016a 145 if ($forums = get_all_instances_in_course("forum", $course)) {
1fc49f00 146 foreach ($forums as $courseforum) {
147 if ($courseforum->id != $forum->id) {
148 $url = "discuss.php?d=$discussion->id&move=$courseforum->id";
149 $forummenu[$url] = $courseforum->name;
150 }
151 }
152 if (!empty($forummenu)) {
153 echo "<div align=\"right\">";
154 echo popup_form("$CFG->wwwroot/mod/forum/", $forummenu, "forummenu", "",
155 get_string("movethisdiscussionto", "forum"), "", "", true);
156 echo "</div>";
157 }
158 }
159 }
02ebf404 160 echo "</td></tr></table>";
1fc49f00 161
8de14dc7 162 if (isset($discussionmoved)) {
163 notify(get_string("discussionmoved", "forum", $forum->name));
164 }
165
c6d691dc 166
167/// Print the actual discussion
168
169 forum_print_discussion($course, $forum, $discussion, $post, $displaymode, $canreply);
170
501cdbd8 171
172 print_footer($course);
173
174?>