Commit | Line | Data |
---|---|---|
1adbd2c3 | 1 | <?php |
501cdbd8 | 2 | |
8f685009 SH |
3 | // This file is part of Moodle - http://moodle.org/ |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * Displays a post, and all the posts below it. | |
20 | * If no post is given, displays all posts in a discussion | |
21 | * | |
22 | * @package mod-forum | |
23 | * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} | |
24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
25 | */ | |
501cdbd8 | 26 | |
65bcf17b | 27 | require_once('../../config.php'); |
65bcf17b | 28 | |
83da3d28 | 29 | $d = required_param('d', PARAM_INT); // Discussion ID |
30 | $parent = optional_param('parent', 0, PARAM_INT); // If set, then display this post and all children. | |
31 | $mode = optional_param('mode', 0, PARAM_INT); // If set, changes the layout of the thread | |
32 | $move = optional_param('move', 0, PARAM_INT); // If set, moves this discussion to another forum | |
87b0b499 | 33 | $mark = optional_param('mark', '', PARAM_ALPHA); // Used for tracking read posts if user initiated. |
83da3d28 | 34 | $postid = optional_param('postid', 0, PARAM_INT); // Used for tracking read posts if user initiated. |
501cdbd8 | 35 | |
a6855934 | 36 | $url = new moodle_url('/mod/forum/discuss.php', array('d'=>$d)); |
8a876913 SH |
37 | if ($parent !== 0) { |
38 | $url->param('parent', $parent); | |
39 | } | |
40 | if ($mode !== 0) { | |
41 | $url->param('mode', $mode); | |
42 | } | |
43 | if ($move !== 0) { | |
44 | $url->param('move', $move); | |
45 | } | |
46 | if ($mark !== '') { | |
47 | $url->param('mark', $mark); | |
48 | } | |
49 | if ($postid !== 0) { | |
50 | $url->param('postid', $postid); | |
51 | } | |
52 | $PAGE->set_url($url); | |
d3558659 | 53 | |
4e445355 | 54 | if (!$discussion = $DB->get_record('forum_discussions', array('id' => $d))) { |
12e57b92 | 55 | print_error('invaliddiscussionid', 'forum'); |
501cdbd8 | 56 | } |
57 | ||
4e445355 | 58 | if (!$course = $DB->get_record('course', array('id' => $discussion->course))) { |
12e57b92 | 59 | print_error('invalidcourseid'); |
501cdbd8 | 60 | } |
61 | ||
4e445355 | 62 | if (!$forum = $DB->get_record('forum', array('id' => $discussion->forum))) { |
9146b979 | 63 | echo $OUTPUT->notification("Bad forum ID stored in this discussion"); |
68258534 | 64 | } |
65 | ||
0fa18d5a | 66 | if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) { |
12e57b92 | 67 | print_error('invalidcoursemodule'); |
bbbf2d40 | 68 | } |
bf553d9e | 69 | require_course_login($course, true, $cm); |
50e07a49 | 70 | |
12f6d016 | 71 | /// Add ajax-related libs |
f44b10ed PS |
72 | $PAGE->requires->yui2_lib('event'); |
73 | $PAGE->requires->yui2_lib('connection'); | |
74 | $PAGE->requires->yui2_lib('json'); | |
12f6d016 | 75 | |
4cabf99f | 76 | // move this down fix for MDL-6926 |
77 | require_once('lib.php'); | |
78 | ||
9af1611a | 79 | $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); |
65bcf17b | 80 | require_capability('mod/forum:viewdiscussion', $modcontext, NULL, true, 'noviewdiscussionspermission', 'forum'); |
81 | ||
9e86f2e7 AD |
82 | if (!empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds) && $forum->rsstype && $forum->rssarticles) { |
83 | require_once("$CFG->libdir/rsslib.php"); | |
84 | ||
85 | $rsstitle = format_string($course->shortname) . ': %fullname%'; | |
43b92251 | 86 | rss_add_http_header($modcontext, 'mod_forum', $forum, $rsstitle); |
9e86f2e7 AD |
87 | } |
88 | ||
65bcf17b | 89 | if ($forum->type == 'news') { |
49a0ba94 | 90 | if (!($USER->id == $discussion->userid || (($discussion->timestart == 0 |
91 | || $discussion->timestart <= time()) | |
fbc21e82 | 92 | && ($discussion->timeend == 0 || $discussion->timeend > time())))) { |
12e57b92 | 93 | print_error('invaliddiscussionid', 'forum', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id"); |
fbc21e82 | 94 | } |
68ddf8bc | 95 | } |
96 | ||
65bcf17b | 97 | /// move discussion if requested |
98 | if ($move > 0 and confirm_sesskey()) { | |
a5f77de6 | 99 | $return = $CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->id; |
65bcf17b | 100 | |
101 | require_capability('mod/forum:movediscussions', $modcontext); | |
1fc49f00 | 102 | |
65bcf17b | 103 | if ($forum->type == 'single') { |
12e57b92 | 104 | print_error('cannotmovefromsingleforum', 'forum', $return); |
83da3d28 | 105 | } |
65bcf17b | 106 | |
4e445355 | 107 | if (!$forumto = $DB->get_record('forum', array('id' => $move))) { |
12e57b92 | 108 | print_error('cannotmovetonotexist', 'forum', $return); |
83da3d28 | 109 | } |
7c900d5d | 110 | |
65bcf17b | 111 | if (!$cmto = get_coursemodule_from_instance('forum', $forumto->id, $course->id)) { |
12e57b92 | 112 | print_error('cannotmovetonotfound', 'forum', $return); |
65bcf17b | 113 | } |
114 | ||
115 | if (!coursemodule_visible_for_user($cmto)) { | |
12e57b92 | 116 | print_error('cannotmovenotvisible', 'forum', $return); |
1fc49f00 | 117 | } |
65bcf17b | 118 | |
ee8d825f | 119 | require_capability('mod/forum:startdiscussion', |
120 | get_context_instance(CONTEXT_MODULE,$cmto->id)); | |
121 | ||
0faf6791 | 122 | if (!forum_move_attachments($discussion, $forum->id, $forumto->id)) { |
9146b979 | 123 | echo $OUTPUT->notification("Errors occurred while moving attachment directories - check your file permissions"); |
65bcf17b | 124 | } |
4e445355 | 125 | $DB->set_field('forum_discussions', 'forum', $forumto->id, array('id' => $discussion->id)); |
126 | $DB->set_field('forum_read', 'forumid', $forumto->id, array('discussionid' => $discussion->id)); | |
65bcf17b | 127 | add_to_log($course->id, 'forum', 'move discussion', "discuss.php?d=$discussion->id", $discussion->id, $cmto->id); |
128 | ||
129 | require_once($CFG->libdir.'/rsslib.php'); | |
130 | require_once('rsslib.php'); | |
131 | ||
a74bea12 AD |
132 | // Delete the RSS files for the 2 forums to force regeneration of the feeds |
133 | forum_rss_delete_file($forum); | |
134 | forum_rss_delete_file($forumto); | |
65bcf17b | 135 | |
e4c5abdc | 136 | redirect($return.'&moved=-1&sesskey='.sesskey()); |
1fc49f00 | 137 | } |
138 | ||
1fc49f00 | 139 | $logparameters = "d=$discussion->id"; |
140 | if ($parent) { | |
839f2456 | 141 | $logparameters .= "&parent=$parent"; |
501cdbd8 | 142 | } |
69d79bc3 | 143 | |
65bcf17b | 144 | add_to_log($course->id, 'forum', 'view discussion', "discuss.php?$logparameters", $discussion->id, $cm->id); |
501cdbd8 | 145 | |
146 | unset($SESSION->fromdiscussion); | |
147 | ||
279826e2 | 148 | if ($mode) { |
f2d042c4 | 149 | set_user_preference('forum_displaymode', $mode); |
279826e2 | 150 | } |
501cdbd8 | 151 | |
acb50c1b | 152 | $displaymode = get_user_preferences('forum_displaymode', $CFG->forum_displaymode); |
501cdbd8 | 153 | |
e92ea3d8 | 154 | if ($parent) { |
65bcf17b | 155 | // If flat AND parent, then force nested display this time |
156 | if ($displaymode == FORUM_MODE_FLATOLDEST or $displaymode == FORUM_MODE_FLATNEWEST) { | |
157 | $displaymode = FORUM_MODE_NESTED; | |
e92ea3d8 | 158 | } |
159 | } else { | |
501cdbd8 | 160 | $parent = $discussion->firstpost; |
501cdbd8 | 161 | } |
162 | ||
11b0c469 | 163 | if (! $post = forum_get_post_full($parent)) { |
12e57b92 | 164 | print_error("notexists", 'forum', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id"); |
501cdbd8 | 165 | } |
166 | ||
c15b86dc | 167 | |
65bcf17b | 168 | if (!forum_user_can_view_post($post, $course, $cm, $forum, $discussion)) { |
12e57b92 | 169 | print_error('nopermissiontoview', 'forum', "$CFG->wwwroot/mod/forum/view.php?id=$forum->id"); |
f37da850 | 170 | } |
171 | ||
65bcf17b | 172 | if ($mark == 'read' or $mark == 'unread') { |
90f4745c | 173 | if ($CFG->forum_usermarksread && forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) { |
65bcf17b | 174 | if ($mark == 'read') { |
90f4745c | 175 | forum_tp_add_read_record($USER->id, $postid); |
65bcf17b | 176 | } else { |
177 | // unread | |
178 | forum_tp_delete_read_records($USER->id, $postid); | |
179 | } | |
180 | } | |
181 | } | |
cef1ce6a | 182 | |
6f1cc8d6 | 183 | $searchform = forum_search_form($course); |
39790bd8 | 184 | |
87a462ea | 185 | if ($parent != $discussion->firstpost) { |
15ca5e5e | 186 | $PAGE->navbar->add(format_string($post->subject)); |
87a462ea | 187 | } |
15ca5e5e | 188 | $PAGE->set_title("$course->shortname: ".format_string($discussion->name)); |
189 | $PAGE->set_heading($course->fullname); | |
190 | $PAGE->set_button($searchform); | |
191 | echo $OUTPUT->header(); | |
c6d691dc | 192 | |
9197e147 | 193 | /// Check to see if groups are being used in this forum |
194 | /// If so, make sure the current person is allowed to see this discussion | |
8b79a625 | 195 | /// Also, if we know they should be able to reply, then explicitly set $canreply for performance reasons |
c6d691dc | 196 | |
4f0c2d00 | 197 | if (isguestuser() or !isloggedin() or (!is_enrolled($modcontext) and !is_viewing($modcontext))) { |
525041df | 198 | // allow guests and not-logged-in to see the link - they are prompted to log in after clicking the link |
4f0c2d00 | 199 | // normal users with temporary guest access see this link too, they are asked to enrol instead |
525041df | 200 | $canreply = ($forum->type != 'news'); // no reply in news forums |
201 | ||
8b79a625 | 202 | } else { |
203 | $canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext); | |
9197e147 | 204 | } |
205 | ||
c6d691dc | 206 | /// Print the controls across the top |
c00037cd | 207 | echo '<div class="discussioncontrols clearfix">'; |
c6d691dc | 208 | |
87b0b499 | 209 | // groups selector not needed here |
12a24e00 | 210 | echo '<div class="displaymode">'; |
ec9c0d44 | 211 | forum_print_mode_form($discussion->id, $displaymode); |
12a24e00 | 212 | echo "</div>"; |
cef1ce6a | 213 | |
12a24e00 RW |
214 | if (has_capability('mod/forum:exportdiscussion', $modcontext) && (!empty($CFG->enableportfolios))) { |
215 | echo '<div class="exporttoportfolio">'; | |
24ba58ee | 216 | require_once($CFG->libdir.'/portfoliolib.php'); |
0d06b6fd | 217 | $button = new portfolio_add_button(); |
24ba58ee | 218 | $button->set_callback_options('forum_portfolio_caller', array('discussionid' => $discussion->id), '/mod/forum/locallib.php'); |
39790bd8 PS |
219 | $button->render(); |
220 | echo '</div>'; | |
10ae55f9 | 221 | } |
222 | ||
cef1ce6a | 223 | if ($forum->type != 'single' |
224 | && has_capability('mod/forum:movediscussions', $modcontext)) { | |
65bcf17b | 225 | |
12a24e00 | 226 | echo '<div class="movediscussion">'; |
cef1ce6a | 227 | // Popup menu to move discussions to other forums. The discussion in a |
228 | // single discussion forum can't be moved. | |
65bcf17b | 229 | $modinfo = get_fast_modinfo($course); |
230 | if (isset($modinfo->instances['forum'])) { | |
65bcf17b | 231 | $forummenu = array(); |
7487c856 | 232 | $sections = get_all_sections($course->id); |
65bcf17b | 233 | foreach ($modinfo->instances['forum'] as $forumcm) { |
ee8d825f | 234 | if (!$forumcm->uservisible || !has_capability('mod/forum:startdiscussion', |
235 | get_context_instance(CONTEXT_MODULE,$forumcm->id))) { | |
65bcf17b | 236 | continue; |
fcc69042 | 237 | } |
65bcf17b | 238 | |
65bcf17b | 239 | $section = $forumcm->sectionnum; |
7487c856 | 240 | $sectionname = get_section_name($course, $sections[$section]); |
f1a3e072 | 241 | if (empty($forummenu[$section])) { |
7487c856 | 242 | $forummenu[$section] = array($sectionname => array()); |
f1a3e072 | 243 | } |
65bcf17b | 244 | if ($forumcm->instance != $forum->id) { |
f1a3e072 | 245 | $url = "/mod/forum/discuss.php?d=$discussion->id&move=$forumcm->instance&sesskey=".sesskey(); |
7487c856 | 246 | $forummenu[$section][$sectionname][$url] = format_string($forumcm->name); |
1fc49f00 | 247 | } |
248 | } | |
249 | if (!empty($forummenu)) { | |
12a24e00 | 250 | echo '<div class="movediscussionoption">'; |
f1a3e072 PS |
251 | $select = new url_select($forummenu, '', array(''=>get_string("movethisdiscussionto", "forum")), 'forummenu'); |
252 | echo $OUTPUT->render($select); | |
1fc49f00 | 253 | echo "</div>"; |
254 | } | |
255 | } | |
12a24e00 | 256 | echo "</div>"; |
1fc49f00 | 257 | } |
12a24e00 RW |
258 | echo '<div class="clearfloat"> </div>'; |
259 | echo "</div>"; | |
1fc49f00 | 260 | |
a4f495bf | 261 | if (!empty($forum->blockafter) && !empty($forum->blockperiod)) { |
39790bd8 | 262 | $a = new stdClass(); |
65bcf17b | 263 | $a->blockafter = $forum->blockafter; |
a4f495bf | 264 | $a->blockperiod = get_string('secondstotime'.$forum->blockperiod); |
9146b979 | 265 | echo $OUTPUT->notification(get_string('thisforumisthrottled','forum',$a)); |
a4f495bf | 266 | } |
267 | ||
0468976c | 268 | if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $modcontext) && |
bbbf2d40 | 269 | !forum_user_has_posted($forum->id,$discussion->id,$USER->id)) { |
9146b979 | 270 | echo $OUTPUT->notification(get_string('qandanotify','forum')); |
098d27d4 | 271 | } |
272 | ||
65bcf17b | 273 | if ($move == -1 and confirm_sesskey()) { |
9146b979 | 274 | echo $OUTPUT->notification(get_string('discussionmoved', 'forum', format_string($forum->name,true))); |
8de14dc7 | 275 | } |
276 | ||
65bcf17b | 277 | $canrate = has_capability('mod/forum:rate', $modcontext); |
278 | forum_print_discussion($course, $cm, $forum, $discussion, $post, $displaymode, $canreply, $canrate); | |
c6d691dc | 279 | |
396fb912 | 280 | echo $OUTPUT->footer(); |
65bcf17b | 281 | |
501cdbd8 | 282 | |
1adbd2c3 | 283 |