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 | |
c992ff85 |
9 | $d = required_param('d', PARAM_INT); // Discussion ID |
10 | $parent = optional_param('parent', 0, PARAM_INT); // If set, then display this post and all children. |
11 | $mode = optional_param('mode', 0, PARAM_INT); // If set, changes the layout of the thread |
12 | $move = optional_param('move', 0, PARAM_INT); // If set, moves this discussion to another forum |
13 | $mark = optional_param('mark', 0, PARAM_INT); // Used for tracking read posts if user initiated. |
14 | $postid = optional_param('postid', 0, PARAM_INT); // Used for tracking read posts if user initiated. |
501cdbd8 |
15 | |
0fa18d5a |
16 | if (!$discussion = get_record("forum_discussions", "id", $d)) { |
94361e02 |
17 | error("Discussion ID was incorrect or no longer exists"); |
501cdbd8 |
18 | } |
19 | |
0fa18d5a |
20 | if (!$course = get_record("course", "id", $discussion->course)) { |
501cdbd8 |
21 | error("Course ID is incorrect - discussion is faulty"); |
22 | } |
23 | |
0fa18d5a |
24 | if (!$forum = get_record("forum", "id", $discussion->forum)) { |
68258534 |
25 | notify("Bad forum ID stored in this discussion"); |
26 | } |
27 | |
0fa18d5a |
28 | if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) { |
bbbf2d40 |
29 | error('Course Module ID was incorrect'); |
30 | } |
9af1611a |
31 | $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); |
0468976c |
32 | $canviewdiscussion = has_capability('mod/forum:viewdiscussion', $modcontext); |
0fa18d5a |
33 | |
bbbf2d40 |
34 | |
35 | if ($forum->type == "news") { |
36 | if (!($canviewdiscussion || $USER->id == $discussion->userid |
fbc21e82 |
37 | || (($discussion->timestart == 0 || $discussion->timestart <= time()) |
38 | && ($discussion->timeend == 0 || $discussion->timeend > time())))) { |
39 | error('Discussion ID was incorrect or no longer exists', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id"); |
40 | } |
41 | |
68258534 |
42 | } else { |
43 | if (! $cm = get_coursemodule_from_instance("forum", $discussion->forum, $course->id)) { |
44 | error("Course Module ID was incorrect"); |
45 | } |
46 | require_course_login($course, false, $cm); |
68ddf8bc |
47 | } |
48 | |
1fc49f00 |
49 | |
8f0cd6ef |
50 | if (!empty($move)) { |
0468976c |
51 | if (has_capability('mod/forum:movediscussions', $modcontext)) { |
bbbf2d40 |
52 | error("You do not have the permission to move this discussion!"); |
1fc49f00 |
53 | } |
54 | if ($forum = get_record("forum", "id", $move)) { |
cc2b7ea5 |
55 | if (!forum_move_attachments($discussion, $move)) { |
56 | notify("Errors occurred while moving attachment directories - check your file permissions"); |
57 | } |
bbbf2d40 |
58 | set_field("forum_discussions", "forum", $forum->id, "id", $discussion->id); |
1fc49f00 |
59 | $discussion->forum = $forum->id; |
69d79bc3 |
60 | if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { |
61 | add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id", |
62 | $cm->id); |
63 | } else { |
64 | add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id"); |
65 | } |
8de14dc7 |
66 | $discussionmoved = true; |
5a39def9 |
67 | require_once('rsslib.php'); |
68 | require_once($CFG->libdir.'/rsslib.php'); |
69 | |
70 | // Delete the RSS files for the 2 forums because we want to force |
71 | // the regeneration of the feeds since the discussions have been |
72 | // moved. |
73 | if (!forum_rss_delete_file($forum) || !forum_rss_delete_file($fromforum)) { |
74 | notify('Could not purge the cached RSS feeds for the source and/or'. |
75 | 'destination forum(s) - check your file permissionsforums'); |
76 | } |
1fc49f00 |
77 | } else { |
78 | error("You can't move to that forum - it doesn't exist!"); |
79 | } |
80 | } |
81 | |
1fc49f00 |
82 | $logparameters = "d=$discussion->id"; |
83 | if ($parent) { |
839f2456 |
84 | $logparameters .= "&parent=$parent"; |
501cdbd8 |
85 | } |
69d79bc3 |
86 | |
87 | if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { |
88 | add_to_log($course->id, "forum", "view discussion", "discuss.php?$logparameters", "$discussion->id", $cm->id); |
89 | } else { |
90 | add_to_log($course->id, "forum", "view discussion", "discuss.php?$logparameters", "$discussion->id"); |
91 | } |
501cdbd8 |
92 | |
93 | unset($SESSION->fromdiscussion); |
94 | |
279826e2 |
95 | if ($mode) { |
acb50c1b |
96 | if (isguest()) { |
97 | $USER->preference['forum_displaymode'] = $mode; // don't save it in database |
98 | } else { |
99 | set_user_preference('forum_displaymode', $mode); |
100 | } |
279826e2 |
101 | } |
501cdbd8 |
102 | |
acb50c1b |
103 | $displaymode = get_user_preferences('forum_displaymode', $CFG->forum_displaymode); |
501cdbd8 |
104 | |
e92ea3d8 |
105 | if ($parent) { |
279826e2 |
106 | if (abs($displaymode) == 1) { // If flat AND parent, then force nested display this time |
e92ea3d8 |
107 | $displaymode = 3; |
108 | } |
109 | } else { |
501cdbd8 |
110 | $parent = $discussion->firstpost; |
c78ac798 |
111 | $navtail = format_string($discussion->name); |
501cdbd8 |
112 | } |
073286f0 |
113 | |
ff1dc046 |
114 | if (!forum_user_can_view_post($parent, $course, $cm, $forum, $discussion)) { |
115 | error('You do not have permissions to view this post', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id"); |
073286f0 |
116 | } |
501cdbd8 |
117 | |
11b0c469 |
118 | if (! $post = forum_get_post_full($parent)) { |
501cdbd8 |
119 | error("Discussion no longer exists", "$CFG->wwwroot/mod/forum/view.php?f=$forum->id"); |
120 | } |
121 | |
eaf50aef |
122 | if (forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum) && |
123 | $CFG->forum_usermarksread) { |
f37da850 |
124 | if ($mark == 'read') { |
125 | forum_tp_add_read_record($USER->id, $postid, $discussion->id, $forum->id); |
126 | } else if ($mark == 'unread') { |
127 | forum_tp_delete_read_records($USER->id, $postid); |
128 | } |
129 | } |
130 | |
61e96406 |
131 | if (empty($navtail)) { |
c78ac798 |
132 | $navtail = "<a href=\"discuss.php?d=$discussion->id\">".format_string($discussion->name,true)."</a> -> ".format_string($post->subject); |
501cdbd8 |
133 | } |
134 | |
3849dae8 |
135 | $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 |
136 | |
6f1cc8d6 |
137 | $searchform = forum_search_form($course); |
97485d07 |
138 | |
501cdbd8 |
139 | if ($course->category) { |
c78ac798 |
140 | print_header("$course->shortname: ".format_string($discussion->name), "$course->fullname", |
72b4e283 |
141 | "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> -> |
8f0cd6ef |
142 | $navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm)); |
501cdbd8 |
143 | } else { |
c78ac798 |
144 | print_header("$course->shortname: ".format_string($discussion->name), "$course->fullname", |
8f0cd6ef |
145 | "$navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm)); |
501cdbd8 |
146 | } |
147 | |
c6d691dc |
148 | |
9197e147 |
149 | /// Check to see if groups are being used in this forum |
150 | /// If so, make sure the current person is allowed to see this discussion |
c6d691dc |
151 | /// Also, if we know they should be able to reply, then explicitly set $canreply |
152 | |
153 | $canreply = NULL; /// No override one way or the other |
45c38eef |
154 | $groupmode = groupmode($course, $cm); |
155 | |
d0087b2f |
156 | |
0468976c |
157 | if ($groupmode and !has_capability('moodle/site:accessallgroups', $modcontext)) { // Groups must be kept separate |
fa22fd5f |
158 | //change this to ismember |
bbbf2d40 |
159 | $mygroupid = mygroupid($course->id); //only useful if 0, otherwise it's an array now |
c6d691dc |
160 | if ($groupmode == SEPARATEGROUPS) { |
161 | require_login(); |
162 | |
fa22fd5f |
163 | if ((empty($mygroupid) and $discussion->groupid == -1) || (ismember($discussion->groupid) || $mygroupid == $discussion->groupid)) { |
c6d691dc |
164 | $canreply = true; |
2862b309 |
165 | } elseif ($discussion->groupid == -1) { |
166 | $canreply = false; |
c6d691dc |
167 | } else { |
168 | print_heading("Sorry, you can't see this discussion because you are not in this group"); |
cd8d4471 |
169 | print_footer($course); |
c6d691dc |
170 | die; |
171 | } |
172 | |
173 | } else if ($groupmode == VISIBLEGROUPS) { |
bbbf2d40 |
174 | $canreply = ( (empty($mygroupid) && $discussion->groupid == -1) || |
175 | (ismember($discussion->groupid) || $mygroupid == $discussion->groupid) && |
0468976c |
176 | has_capability('mod/forum:replypost', $modcontext) ); |
9197e147 |
177 | } |
178 | } |
179 | |
d0087b2f |
180 | |
9197e147 |
181 | |
c6d691dc |
182 | /// Print the controls across the top |
183 | |
d5bbc556 |
184 | echo '<table width="100%"><tr><td width="33%">'; |
c6d691dc |
185 | |
0468976c |
186 | if ($groupmode == VISIBLEGROUPS or ($groupmode and has_capability('moodle/site:accessallgroups', $modcontext))) { |
d5bbc556 |
187 | if ($groups = get_records_menu('groups', 'courseid', $course->id, 'name ASC', 'id,name')) { |
839f2456 |
188 | print_group_menu($groups, $groupmode, $discussion->groupid, "view.php?id=$cm->id&group="); |
c6d691dc |
189 | } |
190 | } |
191 | |
192 | echo "</td><td width=\"33%\">"; |
ec9c0d44 |
193 | forum_print_mode_form($discussion->id, $displaymode); |
c6d691dc |
194 | |
02ebf404 |
195 | echo "</td><td width=\"33%\">"; |
0468976c |
196 | if (has_capability('mod/forum:movediscussions', $modcontext)) { // Popup menu to move discussions to other forums |
cccb016a |
197 | if ($forums = get_all_instances_in_course("forum", $course)) { |
fcc69042 |
198 | if ($course->format == 'weeks') { |
199 | $strsection = get_string("week"); |
200 | } else { |
201 | $strsection = get_string("topic"); |
202 | } |
203 | $section = -1; |
1fc49f00 |
204 | foreach ($forums as $courseforum) { |
fcc69042 |
205 | if (!empty($courseforum->section) and $section != $courseforum->section) { |
206 | $forummenu[] = "-------------- $strsection $courseforum->section --------------"; |
207 | } |
208 | $section = $courseforum->section; |
1fc49f00 |
209 | if ($courseforum->id != $forum->id) { |
839f2456 |
210 | $url = "discuss.php?d=$discussion->id&move=$courseforum->id"; |
3849dae8 |
211 | $forummenu[$url] = format_string($courseforum->name,true); |
1fc49f00 |
212 | } |
213 | } |
214 | if (!empty($forummenu)) { |
215 | echo "<div align=\"right\">"; |
8f0cd6ef |
216 | echo popup_form("$CFG->wwwroot/mod/forum/", $forummenu, "forummenu", "", |
1fc49f00 |
217 | get_string("movethisdiscussionto", "forum"), "", "", true); |
218 | echo "</div>"; |
219 | } |
220 | } |
221 | } |
02ebf404 |
222 | echo "</td></tr></table>"; |
1fc49f00 |
223 | |
a4f495bf |
224 | if (!empty($forum->blockafter) && !empty($forum->blockperiod)) { |
225 | $a->blockafter = $forum->blockafter; |
226 | $a->blockperiod = get_string('secondstotime'.$forum->blockperiod); |
227 | notify(get_string('thisforumisthrottled','forum',$a)); |
228 | } |
229 | |
0468976c |
230 | if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $modcontext) && |
bbbf2d40 |
231 | !forum_user_has_posted($forum->id,$discussion->id,$USER->id)) { |
098d27d4 |
232 | notify(get_string('qandanotify','forum')); |
233 | } |
234 | |
8de14dc7 |
235 | if (isset($discussionmoved)) { |
3849dae8 |
236 | notify(get_string("discussionmoved", "forum", format_string($forum->name,true))); |
8de14dc7 |
237 | } |
238 | |
c6d691dc |
239 | /// Print the actual discussion |
0468976c |
240 | $canrate = has_capability('mod/forum:rate', $modcontext); |
bbbf2d40 |
241 | forum_print_discussion($course, $forum, $discussion, $post, $displaymode, $canreply, $canrate); |
c6d691dc |
242 | |
501cdbd8 |
243 | print_footer($course); |
244 | |
0468976c |
245 | ?> |