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