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 | } | |
8a876913 | 40 | $PAGE->set_url($url); |
d3558659 | 41 | |
01d0aceb SH |
42 | $discussion = $DB->get_record('forum_discussions', array('id' => $d), '*', MUST_EXIST); |
43 | $course = $DB->get_record('course', array('id' => $discussion->course), '*', MUST_EXIST); | |
44 | $forum = $DB->get_record('forum', array('id' => $discussion->forum), '*', MUST_EXIST); | |
45 | $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST); | |
68258534 | 46 | |
bf553d9e | 47 | require_course_login($course, true, $cm); |
50e07a49 | 48 | |
12f6d016 | 49 | /// Add ajax-related libs |
f44b10ed PS |
50 | $PAGE->requires->yui2_lib('event'); |
51 | $PAGE->requires->yui2_lib('connection'); | |
52 | $PAGE->requires->yui2_lib('json'); | |
12f6d016 | 53 | |
4cabf99f | 54 | // move this down fix for MDL-6926 |
01d0aceb | 55 | require_once($CFG->dirroot.'/mod/forum/lib.php'); |
4cabf99f | 56 | |
9af1611a | 57 | $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); |
65bcf17b | 58 | require_capability('mod/forum:viewdiscussion', $modcontext, NULL, true, 'noviewdiscussionspermission', 'forum'); |
59 | ||
9e86f2e7 AD |
60 | if (!empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds) && $forum->rsstype && $forum->rssarticles) { |
61 | require_once("$CFG->libdir/rsslib.php"); | |
62 | ||
63 | $rsstitle = format_string($course->shortname) . ': %fullname%'; | |
43b92251 | 64 | rss_add_http_header($modcontext, 'mod_forum', $forum, $rsstitle); |
9e86f2e7 AD |
65 | } |
66 | ||
65bcf17b | 67 | if ($forum->type == 'news') { |
49a0ba94 | 68 | if (!($USER->id == $discussion->userid || (($discussion->timestart == 0 |
69 | || $discussion->timestart <= time()) | |
fbc21e82 | 70 | && ($discussion->timeend == 0 || $discussion->timeend > time())))) { |
12e57b92 | 71 | print_error('invaliddiscussionid', 'forum', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id"); |
fbc21e82 | 72 | } |
68ddf8bc | 73 | } |
74 | ||
65bcf17b | 75 | /// move discussion if requested |
76 | if ($move > 0 and confirm_sesskey()) { | |
a5f77de6 | 77 | $return = $CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->id; |
65bcf17b | 78 | |
79 | require_capability('mod/forum:movediscussions', $modcontext); | |
1fc49f00 | 80 | |
65bcf17b | 81 | if ($forum->type == 'single') { |
12e57b92 | 82 | print_error('cannotmovefromsingleforum', 'forum', $return); |
83da3d28 | 83 | } |
65bcf17b | 84 | |
4e445355 | 85 | if (!$forumto = $DB->get_record('forum', array('id' => $move))) { |
12e57b92 | 86 | print_error('cannotmovetonotexist', 'forum', $return); |
83da3d28 | 87 | } |
7c900d5d | 88 | |
65bcf17b | 89 | if (!$cmto = get_coursemodule_from_instance('forum', $forumto->id, $course->id)) { |
12e57b92 | 90 | print_error('cannotmovetonotfound', 'forum', $return); |
65bcf17b | 91 | } |
92 | ||
93 | if (!coursemodule_visible_for_user($cmto)) { | |
12e57b92 | 94 | print_error('cannotmovenotvisible', 'forum', $return); |
1fc49f00 | 95 | } |
65bcf17b | 96 | |
01d0aceb | 97 | require_capability('mod/forum:startdiscussion', get_context_instance(CONTEXT_MODULE,$cmto->id)); |
ee8d825f | 98 | |
0faf6791 | 99 | if (!forum_move_attachments($discussion, $forum->id, $forumto->id)) { |
9146b979 | 100 | echo $OUTPUT->notification("Errors occurred while moving attachment directories - check your file permissions"); |
65bcf17b | 101 | } |
4e445355 | 102 | $DB->set_field('forum_discussions', 'forum', $forumto->id, array('id' => $discussion->id)); |
103 | $DB->set_field('forum_read', 'forumid', $forumto->id, array('discussionid' => $discussion->id)); | |
65bcf17b | 104 | add_to_log($course->id, 'forum', 'move discussion', "discuss.php?d=$discussion->id", $discussion->id, $cmto->id); |
105 | ||
106 | require_once($CFG->libdir.'/rsslib.php'); | |
01d0aceb | 107 | require_once($CFG->dirroot.'/mod/forum/rsslib.php'); |
65bcf17b | 108 | |
a74bea12 AD |
109 | // Delete the RSS files for the 2 forums to force regeneration of the feeds |
110 | forum_rss_delete_file($forum); | |
111 | forum_rss_delete_file($forumto); | |
65bcf17b | 112 | |
e4c5abdc | 113 | redirect($return.'&moved=-1&sesskey='.sesskey()); |
1fc49f00 | 114 | } |
115 | ||
01d0aceb | 116 | add_to_log($course->id, 'forum', 'view discussion', $PAGE->url->out(false), $discussion->id, $cm->id); |
501cdbd8 | 117 | |
118 | unset($SESSION->fromdiscussion); | |
119 | ||
279826e2 | 120 | if ($mode) { |
f2d042c4 | 121 | set_user_preference('forum_displaymode', $mode); |
279826e2 | 122 | } |
501cdbd8 | 123 | |
acb50c1b | 124 | $displaymode = get_user_preferences('forum_displaymode', $CFG->forum_displaymode); |
501cdbd8 | 125 | |
e92ea3d8 | 126 | if ($parent) { |
65bcf17b | 127 | // If flat AND parent, then force nested display this time |
128 | if ($displaymode == FORUM_MODE_FLATOLDEST or $displaymode == FORUM_MODE_FLATNEWEST) { | |
129 | $displaymode = FORUM_MODE_NESTED; | |
e92ea3d8 | 130 | } |
131 | } else { | |
501cdbd8 | 132 | $parent = $discussion->firstpost; |
501cdbd8 | 133 | } |
134 | ||
11b0c469 | 135 | if (! $post = forum_get_post_full($parent)) { |
12e57b92 | 136 | print_error("notexists", 'forum', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id"); |
501cdbd8 | 137 | } |
138 | ||
c15b86dc | 139 | |
65bcf17b | 140 | if (!forum_user_can_view_post($post, $course, $cm, $forum, $discussion)) { |
12e57b92 | 141 | print_error('nopermissiontoview', 'forum', "$CFG->wwwroot/mod/forum/view.php?id=$forum->id"); |
f37da850 | 142 | } |
143 | ||
65bcf17b | 144 | if ($mark == 'read' or $mark == 'unread') { |
90f4745c | 145 | if ($CFG->forum_usermarksread && forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) { |
65bcf17b | 146 | if ($mark == 'read') { |
90f4745c | 147 | forum_tp_add_read_record($USER->id, $postid); |
65bcf17b | 148 | } else { |
149 | // unread | |
150 | forum_tp_delete_read_records($USER->id, $postid); | |
151 | } | |
152 | } | |
153 | } | |
cef1ce6a | 154 | |
6f1cc8d6 | 155 | $searchform = forum_search_form($course); |
39790bd8 | 156 | |
01d0aceb SH |
157 | $forumnode = $PAGE->navigation->find($cm->id, navigation_node::TYPE_ACTIVITY); |
158 | if (empty($forumnode)) { | |
159 | $forumnode = $PAGE->navbar; | |
160 | } else { | |
161 | $forumnode->display = false; | |
87a462ea | 162 | } |
01d0aceb SH |
163 | $node = $forumnode->add(format_string($discussion->name), new moodle_url('/mod/forum/discuss.php', array('d'=>$discussion->id))); |
164 | if ($node && $post->id != $discussion->firstpost) { | |
165 | $node->add(format_string($post->subject), $PAGE->url); | |
166 | } | |
167 | ||
15ca5e5e | 168 | $PAGE->set_title("$course->shortname: ".format_string($discussion->name)); |
169 | $PAGE->set_heading($course->fullname); | |
170 | $PAGE->set_button($searchform); | |
171 | echo $OUTPUT->header(); | |
c6d691dc | 172 | |
9197e147 | 173 | /// Check to see if groups are being used in this forum |
174 | /// If so, make sure the current person is allowed to see this discussion | |
8b79a625 | 175 | /// Also, if we know they should be able to reply, then explicitly set $canreply for performance reasons |
c6d691dc | 176 | |
8e18e1ec PS |
177 | $canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext); |
178 | if (!$canreply and $forum->type !== 'news') { | |
179 | if (isguestuser() or !isloggedin()) { | |
180 | $canreply = true; | |
181 | } | |
182 | if (!is_enrolled($modcontext) and !is_viewing($modcontext)) { | |
183 | // allow guests and not-logged-in to see the link - they are prompted to log in after clicking the link | |
184 | // normal users with temporary guest access see this link too, they are asked to enrol instead | |
185 | $canreply = enrol_selfenrol_available($course->id); | |
186 | } | |
9197e147 | 187 | } |
188 | ||
c6d691dc | 189 | /// Print the controls across the top |
c00037cd | 190 | echo '<div class="discussioncontrols clearfix">'; |
c6d691dc | 191 | |
87b0b499 | 192 | // groups selector not needed here |
12a24e00 | 193 | echo '<div class="displaymode">'; |
ec9c0d44 | 194 | forum_print_mode_form($discussion->id, $displaymode); |
12a24e00 | 195 | echo "</div>"; |
cef1ce6a | 196 | |
12a24e00 RW |
197 | if (has_capability('mod/forum:exportdiscussion', $modcontext) && (!empty($CFG->enableportfolios))) { |
198 | echo '<div class="exporttoportfolio">'; | |
24ba58ee | 199 | require_once($CFG->libdir.'/portfoliolib.php'); |
0d06b6fd | 200 | $button = new portfolio_add_button(); |
24ba58ee | 201 | $button->set_callback_options('forum_portfolio_caller', array('discussionid' => $discussion->id), '/mod/forum/locallib.php'); |
39790bd8 PS |
202 | $button->render(); |
203 | echo '</div>'; | |
10ae55f9 | 204 | } |
205 | ||
cef1ce6a | 206 | if ($forum->type != 'single' |
207 | && has_capability('mod/forum:movediscussions', $modcontext)) { | |
65bcf17b | 208 | |
12a24e00 | 209 | echo '<div class="movediscussion">'; |
cef1ce6a | 210 | // Popup menu to move discussions to other forums. The discussion in a |
211 | // single discussion forum can't be moved. | |
65bcf17b | 212 | $modinfo = get_fast_modinfo($course); |
213 | if (isset($modinfo->instances['forum'])) { | |
65bcf17b | 214 | $forummenu = array(); |
7487c856 | 215 | $sections = get_all_sections($course->id); |
65bcf17b | 216 | foreach ($modinfo->instances['forum'] as $forumcm) { |
ee8d825f | 217 | if (!$forumcm->uservisible || !has_capability('mod/forum:startdiscussion', |
218 | get_context_instance(CONTEXT_MODULE,$forumcm->id))) { | |
65bcf17b | 219 | continue; |
fcc69042 | 220 | } |
65bcf17b | 221 | |
65bcf17b | 222 | $section = $forumcm->sectionnum; |
7487c856 | 223 | $sectionname = get_section_name($course, $sections[$section]); |
f1a3e072 | 224 | if (empty($forummenu[$section])) { |
7487c856 | 225 | $forummenu[$section] = array($sectionname => array()); |
f1a3e072 | 226 | } |
65bcf17b | 227 | if ($forumcm->instance != $forum->id) { |
f1a3e072 | 228 | $url = "/mod/forum/discuss.php?d=$discussion->id&move=$forumcm->instance&sesskey=".sesskey(); |
7487c856 | 229 | $forummenu[$section][$sectionname][$url] = format_string($forumcm->name); |
1fc49f00 | 230 | } |
231 | } | |
232 | if (!empty($forummenu)) { | |
12a24e00 | 233 | echo '<div class="movediscussionoption">'; |
f1a3e072 PS |
234 | $select = new url_select($forummenu, '', array(''=>get_string("movethisdiscussionto", "forum")), 'forummenu'); |
235 | echo $OUTPUT->render($select); | |
1fc49f00 | 236 | echo "</div>"; |
237 | } | |
238 | } | |
12a24e00 | 239 | echo "</div>"; |
1fc49f00 | 240 | } |
12a24e00 RW |
241 | echo '<div class="clearfloat"> </div>'; |
242 | echo "</div>"; | |
1fc49f00 | 243 | |
a4f495bf | 244 | if (!empty($forum->blockafter) && !empty($forum->blockperiod)) { |
39790bd8 | 245 | $a = new stdClass(); |
65bcf17b | 246 | $a->blockafter = $forum->blockafter; |
a4f495bf | 247 | $a->blockperiod = get_string('secondstotime'.$forum->blockperiod); |
9146b979 | 248 | echo $OUTPUT->notification(get_string('thisforumisthrottled','forum',$a)); |
a4f495bf | 249 | } |
250 | ||
0468976c | 251 | if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $modcontext) && |
bbbf2d40 | 252 | !forum_user_has_posted($forum->id,$discussion->id,$USER->id)) { |
9146b979 | 253 | echo $OUTPUT->notification(get_string('qandanotify','forum')); |
098d27d4 | 254 | } |
255 | ||
65bcf17b | 256 | if ($move == -1 and confirm_sesskey()) { |
9146b979 | 257 | echo $OUTPUT->notification(get_string('discussionmoved', 'forum', format_string($forum->name,true))); |
8de14dc7 | 258 | } |
259 | ||
65bcf17b | 260 | $canrate = has_capability('mod/forum:rate', $modcontext); |
261 | forum_print_discussion($course, $cm, $forum, $discussion, $post, $displaymode, $canreply, $canrate); | |
c6d691dc | 262 | |
396fb912 | 263 | echo $OUTPUT->footer(); |
65bcf17b | 264 | |
501cdbd8 | 265 | |
1adbd2c3 | 266 |