2009-11-01 14:55:15 +00:00
|
|
|
<?php
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2009-12-10 03:11:18 +00:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays a post, and all the posts below it.
|
|
|
|
* If no post is given, displays all posts in a discussion
|
|
|
|
*
|
|
|
|
* @package mod-forum
|
|
|
|
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2008-02-13 17:03:25 +00:00
|
|
|
require_once('../../config.php');
|
|
|
|
|
2006-09-26 08:37:56 +00:00
|
|
|
$d = required_param('d', PARAM_INT); // Discussion ID
|
|
|
|
$parent = optional_param('parent', 0, PARAM_INT); // If set, then display this post and all children.
|
|
|
|
$mode = optional_param('mode', 0, PARAM_INT); // If set, changes the layout of the thread
|
|
|
|
$move = optional_param('move', 0, PARAM_INT); // If set, moves this discussion to another forum
|
2007-05-21 14:43:09 +00:00
|
|
|
$mark = optional_param('mark', '', PARAM_ALPHA); // Used for tracking read posts if user initiated.
|
2006-09-26 08:37:56 +00:00
|
|
|
$postid = optional_param('postid', 0, PARAM_INT); // Used for tracking read posts if user initiated.
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2009-12-07 04:00:38 +00:00
|
|
|
$url = new moodle_url($CFG->wwwroot.'/mod/forum/discuss.php', array('d'=>$d));
|
|
|
|
if ($parent !== 0) {
|
|
|
|
$url->param('parent', $parent);
|
|
|
|
}
|
|
|
|
if ($mode !== 0) {
|
|
|
|
$url->param('mode', $mode);
|
|
|
|
}
|
|
|
|
if ($move !== 0) {
|
|
|
|
$url->param('move', $move);
|
|
|
|
}
|
|
|
|
if ($mark !== '') {
|
|
|
|
$url->param('mark', $mark);
|
|
|
|
}
|
|
|
|
if ($postid !== 0) {
|
|
|
|
$url->param('postid', $postid);
|
|
|
|
}
|
|
|
|
$PAGE->set_url($url);
|
2009-09-11 03:21:37 +00:00
|
|
|
|
2008-06-05 20:16:09 +00:00
|
|
|
if (!$discussion = $DB->get_record('forum_discussions', array('id' => $d))) {
|
2008-12-12 02:30:56 +00:00
|
|
|
print_error('invaliddiscussionid', 'forum');
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
2008-06-05 20:16:09 +00:00
|
|
|
if (!$course = $DB->get_record('course', array('id' => $discussion->course))) {
|
2008-12-12 02:30:56 +00:00
|
|
|
print_error('invalidcourseid');
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
2008-06-05 20:16:09 +00:00
|
|
|
if (!$forum = $DB->get_record('forum', array('id' => $discussion->forum))) {
|
2009-08-18 05:14:39 +00:00
|
|
|
echo $OUTPUT->notification("Bad forum ID stored in this discussion");
|
2005-03-08 09:53:23 +00:00
|
|
|
}
|
|
|
|
|
2006-08-09 06:59:28 +00:00
|
|
|
if (!$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id)) {
|
2008-12-12 02:30:56 +00:00
|
|
|
print_error('invalidcoursemodule');
|
2006-08-08 05:13:06 +00:00
|
|
|
}
|
2006-10-24 15:58:34 +00:00
|
|
|
require_course_login($course, true, $cm);
|
2006-10-03 01:19:35 +00:00
|
|
|
|
2009-01-17 19:14:37 +00:00
|
|
|
/// Add ajax-related libs
|
2009-12-16 20:25:14 +00:00
|
|
|
$PAGE->requires->yui2_lib('event');
|
|
|
|
$PAGE->requires->yui2_lib('connection');
|
|
|
|
$PAGE->requires->yui2_lib('json');
|
2009-06-15 05:37:57 +00:00
|
|
|
$PAGE->requires->js('mod/forum/rate_ajax.js');
|
2009-01-17 19:14:37 +00:00
|
|
|
|
2009-01-14 05:01:11 +00:00
|
|
|
// move this down fix for MDL-6926
|
|
|
|
require_once('lib.php');
|
|
|
|
|
2006-08-08 06:56:09 +00:00
|
|
|
$modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2008-02-13 17:03:25 +00:00
|
|
|
require_capability('mod/forum:viewdiscussion', $modcontext, NULL, true, 'noviewdiscussionspermission', 'forum');
|
|
|
|
|
|
|
|
if ($forum->type == 'news') {
|
2006-09-21 05:42:35 +00:00
|
|
|
if (!($USER->id == $discussion->userid || (($discussion->timestart == 0
|
|
|
|
|| $discussion->timestart <= time())
|
2005-11-10 22:50:03 +00:00
|
|
|
&& ($discussion->timeend == 0 || $discussion->timeend > time())))) {
|
2008-12-12 02:30:56 +00:00
|
|
|
print_error('invaliddiscussionid', 'forum', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
|
2005-11-10 22:50:03 +00:00
|
|
|
}
|
2004-03-12 01:54:10 +00:00
|
|
|
}
|
|
|
|
|
2008-02-13 17:03:25 +00:00
|
|
|
/// move discussion if requested
|
|
|
|
if ($move > 0 and confirm_sesskey()) {
|
2008-02-15 00:51:44 +00:00
|
|
|
$return = $CFG->wwwroot.'/mod/forum/discuss.php?d='.$discussion->id;
|
2008-02-13 17:03:25 +00:00
|
|
|
|
|
|
|
require_capability('mod/forum:movediscussions', $modcontext);
|
2003-04-24 08:45:27 +00:00
|
|
|
|
2008-02-13 17:03:25 +00:00
|
|
|
if ($forum->type == 'single') {
|
2008-12-12 02:30:56 +00:00
|
|
|
print_error('cannotmovefromsingleforum', 'forum', $return);
|
2006-09-26 08:37:56 +00:00
|
|
|
}
|
2008-02-13 17:03:25 +00:00
|
|
|
|
2008-06-05 20:16:09 +00:00
|
|
|
if (!$forumto = $DB->get_record('forum', array('id' => $move))) {
|
2008-12-12 02:30:56 +00:00
|
|
|
print_error('cannotmovetonotexist', 'forum', $return);
|
2006-09-26 08:37:56 +00:00
|
|
|
}
|
2006-09-25 13:14:50 +00:00
|
|
|
|
2008-02-13 17:03:25 +00:00
|
|
|
if (!$cmto = get_coursemodule_from_instance('forum', $forumto->id, $course->id)) {
|
2008-12-12 02:30:56 +00:00
|
|
|
print_error('cannotmovetonotfound', 'forum', $return);
|
2008-02-13 17:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!coursemodule_visible_for_user($cmto)) {
|
2008-12-12 02:30:56 +00:00
|
|
|
print_error('cannotmovenotvisible', 'forum', $return);
|
2003-04-24 08:45:27 +00:00
|
|
|
}
|
2008-02-13 17:03:25 +00:00
|
|
|
|
2009-01-19 14:20:36 +00:00
|
|
|
require_capability('mod/forum:startdiscussion',
|
|
|
|
get_context_instance(CONTEXT_MODULE,$cmto->id));
|
|
|
|
|
2008-08-16 21:24:05 +00:00
|
|
|
if (!forum_move_attachments($discussion, $forum->id, $forumto->id)) {
|
2009-08-18 05:14:39 +00:00
|
|
|
echo $OUTPUT->notification("Errors occurred while moving attachment directories - check your file permissions");
|
2008-02-13 17:03:25 +00:00
|
|
|
}
|
2008-06-05 20:16:09 +00:00
|
|
|
$DB->set_field('forum_discussions', 'forum', $forumto->id, array('id' => $discussion->id));
|
|
|
|
$DB->set_field('forum_read', 'forumid', $forumto->id, array('discussionid' => $discussion->id));
|
2008-02-13 17:03:25 +00:00
|
|
|
add_to_log($course->id, 'forum', 'move discussion', "discuss.php?d=$discussion->id", $discussion->id, $cmto->id);
|
|
|
|
|
|
|
|
require_once($CFG->libdir.'/rsslib.php');
|
|
|
|
require_once('rsslib.php');
|
|
|
|
|
|
|
|
// Delete the RSS files for the 2 forums because we want to force
|
|
|
|
// the regeneration of the feeds since the discussions have been
|
|
|
|
// moved.
|
2008-02-21 10:31:55 +00:00
|
|
|
if (!forum_rss_delete_file($forum) || !forum_rss_delete_file($forumto)) {
|
2008-12-12 02:30:56 +00:00
|
|
|
print_error('cannotpurgecachedrss', 'forum', $return);
|
2008-02-13 17:03:25 +00:00
|
|
|
}
|
|
|
|
|
2009-08-13 01:43:57 +00:00
|
|
|
redirect($return.'&moved=-1&sesskey='.sesskey());
|
2003-04-24 08:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$logparameters = "d=$discussion->id";
|
|
|
|
if ($parent) {
|
2004-09-16 17:13:57 +00:00
|
|
|
$logparameters .= "&parent=$parent";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2004-01-31 14:47:57 +00:00
|
|
|
|
2008-02-13 17:03:25 +00:00
|
|
|
add_to_log($course->id, 'forum', 'view discussion', "discuss.php?$logparameters", $discussion->id, $cm->id);
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
unset($SESSION->fromdiscussion);
|
|
|
|
|
2004-01-28 14:48:49 +00:00
|
|
|
if ($mode) {
|
2007-03-06 10:45:49 +00:00
|
|
|
set_user_preference('forum_displaymode', $mode);
|
2004-01-28 14:48:49 +00:00
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2005-05-13 02:06:16 +00:00
|
|
|
$displaymode = get_user_preferences('forum_displaymode', $CFG->forum_displaymode);
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-09-02 05:03:54 +00:00
|
|
|
if ($parent) {
|
2008-02-13 17:03:25 +00:00
|
|
|
// If flat AND parent, then force nested display this time
|
|
|
|
if ($displaymode == FORUM_MODE_FLATOLDEST or $displaymode == FORUM_MODE_FLATNEWEST) {
|
|
|
|
$displaymode = FORUM_MODE_NESTED;
|
2002-09-02 05:03:54 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-07-31 14:19:35 +00:00
|
|
|
$parent = $discussion->firstpost;
|
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
if (! $post = forum_get_post_full($parent)) {
|
2008-12-12 02:30:56 +00:00
|
|
|
print_error("notexists", 'forum', "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
2007-10-05 07:26:02 +00:00
|
|
|
|
2008-02-13 17:03:25 +00:00
|
|
|
if (!forum_user_can_view_post($post, $course, $cm, $forum, $discussion)) {
|
2008-12-12 02:30:56 +00:00
|
|
|
print_error('nopermissiontoview', 'forum', "$CFG->wwwroot/mod/forum/view.php?id=$forum->id");
|
2005-01-29 09:49:42 +00:00
|
|
|
}
|
|
|
|
|
2008-02-13 17:03:25 +00:00
|
|
|
if ($mark == 'read' or $mark == 'unread') {
|
2008-04-13 19:15:02 +00:00
|
|
|
if ($CFG->forum_usermarksread && forum_tp_can_track_forums($forum) && forum_tp_is_tracked($forum)) {
|
2008-02-13 17:03:25 +00:00
|
|
|
if ($mark == 'read') {
|
2008-04-13 19:15:02 +00:00
|
|
|
forum_tp_add_read_record($USER->id, $postid);
|
2008-02-13 17:03:25 +00:00
|
|
|
} else {
|
|
|
|
// unread
|
|
|
|
forum_tp_delete_read_records($USER->id, $postid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-09-28 07:29:50 +00:00
|
|
|
|
2005-03-09 20:50:37 +00:00
|
|
|
$searchform = forum_search_form($course);
|
2007-08-17 03:35:34 +00:00
|
|
|
|
2009-12-07 04:00:38 +00:00
|
|
|
$PAGE->navbar->add(format_string($discussion->name), new moodle_url($CFG->wwwroot.'/mod/forum/discuss.php', array('d'=>$discussion->id)));
|
2007-08-17 03:35:34 +00:00
|
|
|
if ($parent != $discussion->firstpost) {
|
2009-09-04 05:50:21 +00:00
|
|
|
$PAGE->navbar->add(format_string($post->subject));
|
2007-08-17 03:35:34 +00:00
|
|
|
}
|
2009-09-04 05:50:21 +00:00
|
|
|
$PAGE->set_title("$course->shortname: ".format_string($discussion->name));
|
|
|
|
$PAGE->set_heading($course->fullname);
|
|
|
|
$PAGE->set_button($searchform);
|
|
|
|
echo $OUTPUT->header();
|
2004-01-20 13:51:27 +00:00
|
|
|
|
2004-01-11 17:46:57 +00:00
|
|
|
/// Check to see if groups are being used in this forum
|
|
|
|
/// If so, make sure the current person is allowed to see this discussion
|
2008-04-19 10:49:53 +00:00
|
|
|
/// Also, if we know they should be able to reply, then explicitly set $canreply for performance reasons
|
2004-01-20 13:51:27 +00:00
|
|
|
|
2008-03-18 17:08:15 +00:00
|
|
|
if (isguestuser() or !isloggedin() or has_capability('moodle/legacy:guest', $modcontext, NULL, false)) {
|
2008-02-26 21:36:48 +00:00
|
|
|
// allow guests and not-logged-in to see the link - they are prompted to log in after clicking the link
|
|
|
|
$canreply = ($forum->type != 'news'); // no reply in news forums
|
|
|
|
|
2008-04-19 10:49:53 +00:00
|
|
|
} else {
|
|
|
|
$canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $modcontext);
|
2004-01-11 17:46:57 +00:00
|
|
|
}
|
|
|
|
|
2004-01-20 13:51:27 +00:00
|
|
|
/// Print the controls across the top
|
|
|
|
|
2007-01-04 15:58:55 +00:00
|
|
|
echo '<table width="100%" class="discussioncontrols"><tr><td>';
|
2004-01-20 13:51:27 +00:00
|
|
|
|
2007-05-21 14:43:09 +00:00
|
|
|
// groups selector not needed here
|
2004-01-20 13:51:27 +00:00
|
|
|
|
2007-01-04 15:31:05 +00:00
|
|
|
echo "</td><td>";
|
2003-08-16 06:20:39 +00:00
|
|
|
forum_print_mode_form($discussion->id, $displaymode);
|
2007-01-04 15:31:05 +00:00
|
|
|
echo "</td><td>";
|
2006-09-28 07:29:50 +00:00
|
|
|
|
2008-09-11 13:42:58 +00:00
|
|
|
if (has_capability('mod/forum:exportdiscussion', $modcontext)) {
|
2009-12-12 11:27:07 +00:00
|
|
|
require_once($CFG->libdir.'/portfoliolib.php');
|
2008-09-11 13:42:58 +00:00
|
|
|
$button = new portfolio_add_button();
|
2009-12-12 11:27:07 +00:00
|
|
|
$button->set_callback_options('forum_portfolio_caller', array('discussionid' => $discussion->id), '/mod/forum/locallib.php');
|
2008-09-11 13:42:58 +00:00
|
|
|
$button->render();
|
|
|
|
echo '</td><td>';
|
2008-07-25 12:30:08 +00:00
|
|
|
}
|
|
|
|
|
2006-09-28 07:29:50 +00:00
|
|
|
if ($forum->type != 'single'
|
|
|
|
&& has_capability('mod/forum:movediscussions', $modcontext)) {
|
2008-02-13 17:03:25 +00:00
|
|
|
|
2006-09-28 07:29:50 +00:00
|
|
|
// Popup menu to move discussions to other forums. The discussion in a
|
|
|
|
// single discussion forum can't be moved.
|
2008-02-13 17:03:25 +00:00
|
|
|
$modinfo = get_fast_modinfo($course);
|
|
|
|
if (isset($modinfo->instances['forum'])) {
|
2004-03-13 13:56:29 +00:00
|
|
|
if ($course->format == 'weeks') {
|
|
|
|
$strsection = get_string("week");
|
|
|
|
} else {
|
|
|
|
$strsection = get_string("topic");
|
|
|
|
}
|
|
|
|
$section = -1;
|
2008-02-13 17:03:25 +00:00
|
|
|
$forummenu = array();
|
|
|
|
foreach ($modinfo->instances['forum'] as $forumcm) {
|
2009-01-19 14:20:36 +00:00
|
|
|
if (!$forumcm->uservisible || !has_capability('mod/forum:startdiscussion',
|
|
|
|
get_context_instance(CONTEXT_MODULE,$forumcm->id))) {
|
2008-02-13 17:03:25 +00:00
|
|
|
continue;
|
2004-03-13 13:56:29 +00:00
|
|
|
}
|
2008-02-13 17:03:25 +00:00
|
|
|
|
|
|
|
if (!empty($forumcm->sectionnum) and $section != $forumcm->sectionnum) {
|
|
|
|
$forummenu[] = "-------------- $strsection $forumcm->sectionnum --------------";
|
|
|
|
}
|
|
|
|
$section = $forumcm->sectionnum;
|
|
|
|
if ($forumcm->instance != $forum->id) {
|
2009-08-13 01:43:57 +00:00
|
|
|
$url = $CFG->wwwroot . "/mod/forum/discuss.php?d=$discussion->id&move=$forumcm->instance&sesskey=".sesskey();
|
2008-02-13 17:03:25 +00:00
|
|
|
$forummenu[$url] = format_string($forumcm->name);
|
2003-04-24 08:45:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty($forummenu)) {
|
2009-11-04 02:46:18 +00:00
|
|
|
|
|
|
|
// Check for empty groups... This can occur if there is the forum we are in is
|
|
|
|
// the only forum within its course section.
|
|
|
|
foreach ($forummenu as $key=>$item) {
|
|
|
|
// If this option is a group and the next option is a group OR it is
|
|
|
|
// the last item in the array then remove it... or we get an exception
|
|
|
|
if (strpos($item, '--------------')===0 && (!array_key_exists($key+1, $forummenu) || strpos($forummenu[$key+1], '--------------')===0)) {
|
|
|
|
// Remember foreach acts on a copy of the array so things
|
|
|
|
// will not get out of order
|
|
|
|
unset($forummenu[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-07 10:19:01 +00:00
|
|
|
echo "<div style=\"float:right;\">";
|
2009-08-10 08:38:45 +00:00
|
|
|
$select = html_select::make_popup_form('', '', $forummenu, 'forummenu');
|
2009-08-10 03:36:42 +00:00
|
|
|
$select->nothinglabel = get_string("movethisdiscussionto", "forum");
|
|
|
|
$select->form->button->text = get_string('move');
|
|
|
|
|
|
|
|
$select->override_option_values($forummenu);
|
|
|
|
|
|
|
|
echo $OUTPUT->select($select);
|
2003-04-24 08:45:27 +00:00
|
|
|
echo "</div>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-08-15 13:59:24 +00:00
|
|
|
echo "</td></tr></table>";
|
2003-04-24 08:45:27 +00:00
|
|
|
|
2006-01-16 08:42:09 +00:00
|
|
|
if (!empty($forum->blockafter) && !empty($forum->blockperiod)) {
|
2008-02-13 17:03:25 +00:00
|
|
|
$a = new object();
|
|
|
|
$a->blockafter = $forum->blockafter;
|
2006-01-16 08:42:09 +00:00
|
|
|
$a->blockperiod = get_string('secondstotime'.$forum->blockperiod);
|
2009-08-18 05:14:39 +00:00
|
|
|
echo $OUTPUT->notification(get_string('thisforumisthrottled','forum',$a));
|
2006-01-16 08:42:09 +00:00
|
|
|
}
|
|
|
|
|
2006-08-14 05:55:40 +00:00
|
|
|
if ($forum->type == 'qanda' && !has_capability('mod/forum:viewqandawithoutposting', $modcontext) &&
|
2006-08-08 05:13:06 +00:00
|
|
|
!forum_user_has_posted($forum->id,$discussion->id,$USER->id)) {
|
2009-08-18 05:14:39 +00:00
|
|
|
echo $OUTPUT->notification(get_string('qandanotify','forum'));
|
2006-01-16 04:57:48 +00:00
|
|
|
}
|
|
|
|
|
2008-02-13 17:03:25 +00:00
|
|
|
if ($move == -1 and confirm_sesskey()) {
|
2009-08-18 05:14:39 +00:00
|
|
|
echo $OUTPUT->notification(get_string('discussionmoved', 'forum', format_string($forum->name,true)));
|
2003-04-28 15:27:44 +00:00
|
|
|
}
|
|
|
|
|
2008-02-13 17:03:25 +00:00
|
|
|
$canrate = has_capability('mod/forum:rate', $modcontext);
|
|
|
|
forum_print_discussion($course, $cm, $forum, $discussion, $post, $displaymode, $canreply, $canrate);
|
2004-01-20 13:51:27 +00:00
|
|
|
|
2009-08-06 14:14:09 +00:00
|
|
|
echo $OUTPUT->footer();
|
2008-02-13 17:03:25 +00:00
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2009-11-01 14:55:15 +00:00
|
|
|
|