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 | |
65bcf17b |
6 | require_once('../../config.php'); |
65bcf17b |
7 | |
83da3d28 |
8 | $d = required_param('d', PARAM_INT); // Discussion ID |
9 | $parent = optional_param('parent', 0, PARAM_INT); // If set, then display this post and all children. |
10 | $mode = optional_param('mode', 0, PARAM_INT); // If set, changes the layout of the thread |
11 | $move = optional_param('move', 0, PARAM_INT); // If set, moves this discussion to another forum |
87b0b499 |
12 | $mark = optional_param('mark', '', PARAM_ALPHA); // Used for tracking read posts if user initiated. |
83da3d28 |
13 | $postid = optional_param('postid', 0, PARAM_INT); // Used for tracking read posts if user initiated. |
501cdbd8 |
14 | |
4e445355 |
15 | if (!$discussion = $DB->get_record('forum_discussions', array('id' => $d))) { |
12e57b92 |
16 | print_error('invaliddiscussionid', 'forum'); |
501cdbd8 |
17 | } |
18 | |
4e445355 |
19 | if (!$course = $DB->get_record('course', array('id' => $discussion->course))) { |
12e57b92 |
20 | print_error('invalidcourseid'); |
501cdbd8 |
21 | } |
22 | |
4e445355 |
23 | if (!$forum = $DB->get_record('forum', array('id' => $discussion->forum))) { |
68258534 |
24 | notify("Bad forum ID stored in this discussion"); |
25 | } |
26 | |
0fa18d5a |
27 | if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) { |
12e57b92 |
28 | print_error('invalidcoursemodule'); |
bbbf2d40 |
29 | } |
65bcf17b |
30 | |
bf553d9e |
31 | require_course_login($course, true, $cm); |
50e07a49 |
32 | |
12f6d016 |
33 | /// Add ajax-related libs |
c28bf5c9 |
34 | $PAGE->requires->yui_lib('event'); |
35 | $PAGE->requires->yui_lib('connection'); |
36 | $PAGE->requires->yui_lib('json'); |
37 | $PAGE->requires->js('mod/forum/rate_ajax.js'); |
12f6d016 |
38 | |
4cabf99f |
39 | // move this down fix for MDL-6926 |
40 | require_once('lib.php'); |
41 | |
9af1611a |
42 | $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); |
65bcf17b |
43 | require_capability('mod/forum:viewdiscussion', $modcontext, NULL, true, 'noviewdiscussionspermission', 'forum'); |
44 | |
45 | if ($forum->type == 'news') { |
49a0ba94 |
46 | if (!($USER->id == $discussion->userid || (($discussion->timestart == 0 |
47 | || $discussion->timestart <= time()) |
fbc21e82 |
48 | && ($discussion->timeend == 0 || $discussion->timeend > time())))) { |
12e57b92 |
49 | print_error('invaliddiscussionid', 'forum', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id"); |
fbc21e82 |
50 | } |
68ddf8bc |
51 | } |
52 | |
65bcf17b |
53 | /// move discussion if requested |
54 | if ($move > 0 and confirm_sesskey()) { |
a5f77de6 |
55 | $return = $CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->id; |
65bcf17b |
56 | |
57 | require_capability('mod/forum:movediscussions', $modcontext); |
1fc49f00 |
58 | |
65bcf17b |
59 | if ($forum->type == 'single') { |
12e57b92 |
60 | print_error('cannotmovefromsingleforum', 'forum', $return); |
83da3d28 |
61 | } |
65bcf17b |
62 | |
4e445355 |
63 | if (!$forumto = $DB->get_record('forum', array('id' => $move))) { |
12e57b92 |
64 | print_error('cannotmovetonotexist', 'forum', $return); |
83da3d28 |
65 | } |
7c900d5d |
66 | |
65bcf17b |
67 | if (!$cmto = get_coursemodule_from_instance('forum', $forumto->id, $course->id)) { |
12e57b92 |
68 | print_error('cannotmovetonotfound', 'forum', $return); |
65bcf17b |
69 | } |
70 | |
71 | if (!coursemodule_visible_for_user($cmto)) { |
12e57b92 |
72 | print_error('cannotmovenotvisible', 'forum', $return); |
1fc49f00 |
73 | } |
65bcf17b |
74 | |
ee8d825f |
75 | require_capability('mod/forum:startdiscussion', |
76 | get_context_instance(CONTEXT_MODULE,$cmto->id)); |
77 | |
0faf6791 |
78 | if (!forum_move_attachments($discussion, $forum->id, $forumto->id)) { |
65bcf17b |
79 | notify("Errors occurred while moving attachment directories - check your file permissions"); |
80 | } |
4e445355 |
81 | $DB->set_field('forum_discussions', 'forum', $forumto->id, array('id' => $discussion->id)); |
82 | $DB->set_field('forum_read', 'forumid', $forumto->id, array('discussionid' => $discussion->id)); |
65bcf17b |
83 | add_to_log($course->id, 'forum', 'move discussion', "discuss.php?d=$discussion->id", $discussion->id, $cmto->id); |
84 | |
85 | require_once($CFG->libdir.'/rsslib.php'); |
86 | require_once('rsslib.php'); |
87 | |
88 | // Delete the RSS files for the 2 forums because we want to force |
89 | // the regeneration of the feeds since the discussions have been |
90 | // moved. |
b9973acc |
91 | if (!forum_rss_delete_file($forum) || !forum_rss_delete_file($forumto)) { |
12e57b92 |
92 | print_error('cannotpurgecachedrss', 'forum', $return); |
65bcf17b |
93 | } |
94 | |
e4c5abdc |
95 | redirect($return.'&moved=-1&sesskey='.sesskey()); |
1fc49f00 |
96 | } |
97 | |
1fc49f00 |
98 | $logparameters = "d=$discussion->id"; |
99 | if ($parent) { |
839f2456 |
100 | $logparameters .= "&parent=$parent"; |
501cdbd8 |
101 | } |
69d79bc3 |
102 | |
65bcf17b |
103 | add_to_log($course->id, 'forum', 'view discussion', "discuss.php?$logparameters", $discussion->id, $cm->id); |
501cdbd8 |
104 | |
105 | unset($SESSION->fromdiscussion); |
106 | |
279826e2 |
107 | if ($mode) { |
f2d042c4 |
108 | set_user_preference('forum_displaymode', $mode); |
279826e2 |
109 | } |
501cdbd8 |
110 | |
acb50c1b |
111 | $displaymode = get_user_preferences('forum_displaymode', $CFG->forum_displaymode); |
501cdbd8 |
112 | |
e92ea3d8 |
113 | if ($parent) { |
65bcf17b |
114 | // If flat AND parent, then force nested display this time |
115 | if ($displaymode == FORUM_MODE_FLATOLDEST or $displaymode == FORUM_MODE_FLATNEWEST) { |
116 | $displaymode = FORUM_MODE_NESTED; |
e92ea3d8 |
117 | } |
118 | } else { |
501cdbd8 |
119 | $parent = $discussion->firstpost; |
501cdbd8 |
120 | } |
121 | |
11b0c469 |
122 | if (! $post = forum_get_post_full($parent)) { |
12e57b92 |
123 | print_error("notexists", 'forum', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id"); |
501cdbd8 |
124 | } |
125 | |
c15b86dc |
126 | |
65bcf17b |
127 | if (!forum_user_can_view_post($post, $course, $cm, $forum, $discussion)) { |
12e57b92 |
128 | print_error('nopermissiontoview', 'forum', "$CFG->wwwroot/mod/forum/view.php?id=$forum->id"); |
f37da850 |
129 | } |
130 | |
65bcf17b |
131 | if ($mark == 'read' or $mark == 'unread') { |
90f4745c |
132 | if ($CFG->forum_usermarksread && forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) { |
65bcf17b |
133 | if ($mark == 'read') { |
90f4745c |
134 | forum_tp_add_read_record($USER->id, $postid); |
65bcf17b |
135 | } else { |
136 | // unread |
137 | forum_tp_delete_read_records($USER->id, $postid); |
138 | } |
139 | } |
140 | } |
cef1ce6a |
141 | |
6f1cc8d6 |
142 | $searchform = forum_search_form($course); |
87a462ea |
143 | |
144 | $navlinks = array(); |
65bcf17b |
145 | $navlinks[] = array('name' => format_string($discussion->name), 'link' => "discuss.php?d=$discussion->id", 'type' => 'title'); |
87a462ea |
146 | if ($parent != $discussion->firstpost) { |
65bcf17b |
147 | $navlinks[] = array('name' => format_string($post->subject), 'type' => 'title'); |
87a462ea |
148 | } |
65bcf17b |
149 | |
150 | $navigation = build_navigation($navlinks, $cm); |
e3f58dfb |
151 | print_header("$course->shortname: ".format_string($discussion->name), $course->fullname, |
152 | $navigation, "", "", true, $searchform, navmenu($course, $cm)); |
65bcf17b |
153 | |
c6d691dc |
154 | |
9197e147 |
155 | /// Check to see if groups are being used in this forum |
156 | /// If so, make sure the current person is allowed to see this discussion |
8b79a625 |
157 | /// Also, if we know they should be able to reply, then explicitly set $canreply for performance reasons |
c6d691dc |
158 | |
7214101b |
159 | if (isguestuser() or !isloggedin() or has_capability('moodle/legacy:guest', $modcontext, NULL, false)) { |
525041df |
160 | // allow guests and not-logged-in to see the link - they are prompted to log in after clicking the link |
161 | $canreply = ($forum->type != 'news'); // no reply in news forums |
162 | |
8b79a625 |
163 | } else { |
164 | $canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext); |
9197e147 |
165 | } |
166 | |
c6d691dc |
167 | /// Print the controls across the top |
168 | |
a1857045 |
169 | echo '<table width="100%" class="discussioncontrols"><tr><td>'; |
c6d691dc |
170 | |
87b0b499 |
171 | // groups selector not needed here |
c6d691dc |
172 | |
c7a049a3 |
173 | echo "</td><td>"; |
ec9c0d44 |
174 | forum_print_mode_form($discussion->id, $displaymode); |
c7a049a3 |
175 | echo "</td><td>"; |
cef1ce6a |
176 | |
0d06b6fd |
177 | if (has_capability('mod/forum:exportdiscussion', $modcontext)) { |
178 | $button = new portfolio_add_button(); |
179 | $button->set_callback_options('forum_portfolio_caller', array('discussionid' => $discussion->id), '/mod/forum/lib.php'); |
180 | $button->render(); |
181 | echo '</td><td>'; |
10ae55f9 |
182 | } |
183 | |
cef1ce6a |
184 | if ($forum->type != 'single' |
185 | && has_capability('mod/forum:movediscussions', $modcontext)) { |
65bcf17b |
186 | |
cef1ce6a |
187 | // Popup menu to move discussions to other forums. The discussion in a |
188 | // single discussion forum can't be moved. |
65bcf17b |
189 | $modinfo = get_fast_modinfo($course); |
190 | if (isset($modinfo->instances['forum'])) { |
fcc69042 |
191 | if ($course->format == 'weeks') { |
192 | $strsection = get_string("week"); |
193 | } else { |
194 | $strsection = get_string("topic"); |
195 | } |
196 | $section = -1; |
65bcf17b |
197 | $forummenu = array(); |
198 | foreach ($modinfo->instances['forum'] as $forumcm) { |
ee8d825f |
199 | if (!$forumcm->uservisible || !has_capability('mod/forum:startdiscussion', |
200 | get_context_instance(CONTEXT_MODULE,$forumcm->id))) { |
65bcf17b |
201 | continue; |
fcc69042 |
202 | } |
65bcf17b |
203 | |
204 | if (!empty($forumcm->sectionnum) and $section != $forumcm->sectionnum) { |
205 | $forummenu[] = "-------------- $strsection $forumcm->sectionnum --------------"; |
206 | } |
207 | $section = $forumcm->sectionnum; |
208 | if ($forumcm->instance != $forum->id) { |
e4c5abdc |
209 | $url = $CFG->wwwroot . "/mod/forum/discuss.php?d=$discussion->id&move=$forumcm->instance&sesskey=".sesskey(); |
65bcf17b |
210 | $forummenu[$url] = format_string($forumcm->name); |
1fc49f00 |
211 | } |
212 | } |
213 | if (!empty($forummenu)) { |
41a22032 |
214 | echo "<div style=\"float:right;\">"; |
7b1f2c82 |
215 | $select = html_select::make_popup_form('', '', $forummenu, 'forummenu'); |
9fc666e5 |
216 | $select->nothinglabel = get_string("movethisdiscussionto", "forum"); |
217 | $select->form->button->text = get_string('move'); |
218 | |
219 | $select->override_option_values($forummenu); |
220 | |
221 | echo $OUTPUT->select($select); |
1fc49f00 |
222 | echo "</div>"; |
223 | } |
224 | } |
225 | } |
02ebf404 |
226 | echo "</td></tr></table>"; |
1fc49f00 |
227 | |
a4f495bf |
228 | if (!empty($forum->blockafter) && !empty($forum->blockperiod)) { |
65bcf17b |
229 | $a = new object(); |
230 | $a->blockafter = $forum->blockafter; |
a4f495bf |
231 | $a->blockperiod = get_string('secondstotime'.$forum->blockperiod); |
232 | notify(get_string('thisforumisthrottled','forum',$a)); |
233 | } |
234 | |
0468976c |
235 | if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $modcontext) && |
bbbf2d40 |
236 | !forum_user_has_posted($forum->id,$discussion->id,$USER->id)) { |
098d27d4 |
237 | notify(get_string('qandanotify','forum')); |
238 | } |
239 | |
65bcf17b |
240 | if ($move == -1 and confirm_sesskey()) { |
241 | notify(get_string('discussionmoved', 'forum', format_string($forum->name,true))); |
8de14dc7 |
242 | } |
243 | |
65bcf17b |
244 | $canrate = has_capability('mod/forum:rate', $modcontext); |
245 | forum_print_discussion($course, $cm, $forum, $discussion, $post, $displaymode, $canreply, $canrate); |
c6d691dc |
246 | |
396fb912 |
247 | echo $OUTPUT->footer(); |
65bcf17b |
248 | |
501cdbd8 |
249 | |
50e07a49 |
250 | ?> |