The teacher can now move selected questions to a chosen category or delete them,...
[moodle.git] / mod / forum / discuss.php
CommitLineData
41905731 1<?php // $Id$
501cdbd8 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
f37da850 13 optional_variable($mark); // Used for tracking read posts if user initiated.
14 optional_variable($postid); // Used for tracking read posts if user initiated.
501cdbd8 15
16 if (! $discussion = get_record("forum_discussions", "id", $d)) {
94361e02 17 error("Discussion ID was incorrect or no longer exists");
501cdbd8 18 }
19
20 if (! $course = get_record("course", "id", $discussion->course)) {
21 error("Course ID is incorrect - discussion is faulty");
22 }
23
ec81373f 24 if (! $cm = get_coursemodule_from_instance("forum", $discussion->forum, $course->id)) {
25 error("Course Module ID was incorrect");
68ddf8bc 26 }
27
ec81373f 28 require_course_login($course, false, $cm);
1fc49f00 29
8f0cd6ef 30 if (!empty($move)) {
1fc49f00 31 if (!isteacher($course->id)) {
32 error("Only teachers can do that!");
33 }
34 if ($forum = get_record("forum", "id", $move)) {
cc2b7ea5 35 if (!forum_move_attachments($discussion, $move)) {
36 notify("Errors occurred while moving attachment directories - check your file permissions");
37 }
1fc49f00 38 set_field("forum_discussions", "forum", $forum->id, "id", $discussion->id);
39 $discussion->forum = $forum->id;
69d79bc3 40 if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
41 add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id",
42 $cm->id);
43 } else {
44 add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id");
45 }
8de14dc7 46 $discussionmoved = true;
1fc49f00 47 } else {
48 error("You can't move to that forum - it doesn't exist!");
49 }
50 }
51
52 if (empty($forum)) {
53 if (! $forum = get_record("forum", "id", $discussion->forum)) {
54 notify("Bad forum ID stored in this discussion");
55 }
501cdbd8 56 }
57
fce9c67b 58 if ($forum->type == "teacher") {
59 if (!isteacher($course->id)) {
60 error("You must be a $course->teacher to view this forum");
61 }
62 }
63
1fc49f00 64 $logparameters = "d=$discussion->id";
65 if ($parent) {
839f2456 66 $logparameters .= "&amp;parent=$parent";
501cdbd8 67 }
69d79bc3 68
69 if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
70 add_to_log($course->id, "forum", "view discussion", "discuss.php?$logparameters", "$discussion->id", $cm->id);
71 } else {
72 add_to_log($course->id, "forum", "view discussion", "discuss.php?$logparameters", "$discussion->id");
73 }
501cdbd8 74
75 unset($SESSION->fromdiscussion);
76
279826e2 77 if ($mode) {
78 set_user_preference("forum_displaymode", $mode);
79 }
501cdbd8 80
279826e2 81 $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
501cdbd8 82
e92ea3d8 83 if ($parent) {
279826e2 84 if (abs($displaymode) == 1) { // If flat AND parent, then force nested display this time
e92ea3d8 85 $displaymode = 3;
86 }
87 } else {
501cdbd8 88 $parent = $discussion->firstpost;
89 $navtail = "$discussion->name";
90 }
91
11b0c469 92 if (! $post = forum_get_post_full($parent)) {
501cdbd8 93 error("Discussion no longer exists", "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
94 }
95
f37da850 96 if ($CFG->forum_trackreadposts && $CFG->forum_usermarksread) {
97 if ($mark == 'read') {
98 forum_tp_add_read_record($USER->id, $postid, $discussion->id, $forum->id);
99 } else if ($mark == 'unread') {
100 forum_tp_delete_read_records($USER->id, $postid);
101 }
102 }
103
61e96406 104 if (empty($navtail)) {
41905731 105 $navtail = "<a href=\"discuss.php?d=$discussion->id\">$discussion->name</a> -> $post->subject";
501cdbd8 106 }
107
41905731 108 $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 109
f0b8884d 110 $searchform = forum_print_search_form($course, "", true, "navbar");
97485d07 111
501cdbd8 112 if ($course->category) {
113 print_header("$course->shortname: $discussion->name", "$course->fullname",
72b4e283 114 "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->
8f0cd6ef 115 $navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm));
501cdbd8 116 } else {
117 print_header("$course->shortname: $discussion->name", "$course->fullname",
8f0cd6ef 118 "$navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm));
501cdbd8 119 }
120
f37da850 121 echo '<div id="forum-discuss" class="forum">'; // forum-discuss wrapper start
122
c6d691dc 123
9197e147 124/// Check to see if groups are being used in this forum
125/// If so, make sure the current person is allowed to see this discussion
c6d691dc 126/// Also, if we know they should be able to reply, then explicitly set $canreply
127
128 $canreply = NULL; /// No override one way or the other
9197e147 129
52b201ee 130 if ($forum->type == "teacher") {
131 $groupmode = NOGROUPS;
132 } else {
133 $groupmode = groupmode($course, $cm);
134 }
9197e147 135
c6d691dc 136 if ($groupmode and !isteacheredit($course->id)) { // Groups must be kept separate
c6d691dc 137 if ($groupmode == SEPARATEGROUPS) {
138 require_login();
139
02509fe6 140 if (mygroupid($course->id) == $discussion->groupid) {
c6d691dc 141 $canreply = true;
2862b309 142 } elseif ($discussion->groupid == -1) {
143 $canreply = false;
c6d691dc 144 } else {
145 print_heading("Sorry, you can't see this discussion because you are not in this group");
146 print_footer();
147 die;
148 }
149
150 } else if ($groupmode == VISIBLEGROUPS) {
02509fe6 151 $canreply = (mygroupid($course->id) == $discussion->groupid);
9197e147 152 }
153 }
154
155
c6d691dc 156/// Print the controls across the top
157
d5bbc556 158 echo '<table width="100%"><tr><td width="33%">';
c6d691dc 159
160 if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
d5bbc556 161 if ($groups = get_records_menu('groups', 'courseid', $course->id, 'name ASC', 'id,name')) {
839f2456 162 print_group_menu($groups, $groupmode, $discussion->groupid, "view.php?id=$cm->id&amp;group=");
c6d691dc 163 }
164 }
165
166 echo "</td><td width=\"33%\">";
ec9c0d44 167 forum_print_mode_form($discussion->id, $displaymode);
c6d691dc 168
02ebf404 169 echo "</td><td width=\"33%\">";
1fc49f00 170 if (isteacher($course->id)) { // Popup menu to allow discussions to be moved to other forums
cccb016a 171 if ($forums = get_all_instances_in_course("forum", $course)) {
fcc69042 172 if ($course->format == 'weeks') {
173 $strsection = get_string("week");
174 } else {
175 $strsection = get_string("topic");
176 }
177 $section = -1;
1fc49f00 178 foreach ($forums as $courseforum) {
fcc69042 179 if (!empty($courseforum->section) and $section != $courseforum->section) {
180 $forummenu[] = "-------------- $strsection $courseforum->section --------------";
181 }
182 $section = $courseforum->section;
1fc49f00 183 if ($courseforum->id != $forum->id) {
839f2456 184 $url = "discuss.php?d=$discussion->id&amp;move=$courseforum->id";
1fc49f00 185 $forummenu[$url] = $courseforum->name;
186 }
187 }
188 if (!empty($forummenu)) {
189 echo "<div align=\"right\">";
8f0cd6ef 190 echo popup_form("$CFG->wwwroot/mod/forum/", $forummenu, "forummenu", "",
1fc49f00 191 get_string("movethisdiscussionto", "forum"), "", "", true);
192 echo "</div>";
193 }
194 }
195 }
02ebf404 196 echo "</td></tr></table>";
1fc49f00 197
8de14dc7 198 if (isset($discussionmoved)) {
199 notify(get_string("discussionmoved", "forum", $forum->name));
200 }
201
c6d691dc 202
203/// Print the actual discussion
204
205 forum_print_discussion($course, $forum, $discussion, $post, $displaymode, $canreply);
206
680afe2e 207 echo '</div>'; // forum-discuss wrapper end
501cdbd8 208
209 print_footer($course);
210
211?>