2009-11-01 14:55:15 +00:00
|
|
|
<?php
|
2002-06-20 15:15:22 +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/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
|
2006-09-21 05:42:35 +00:00
|
|
|
require_once('../../config.php');
|
|
|
|
require_once('lib.php');
|
2010-11-17 06:23:56 +00:00
|
|
|
require_once($CFG->libdir.'/completionlib.php');
|
2006-09-21 05:42:35 +00:00
|
|
|
|
|
|
|
$id = optional_param('id', 0, PARAM_INT); // Course Module ID
|
|
|
|
$f = optional_param('f', 0, PARAM_INT); // Forum ID
|
|
|
|
$mode = optional_param('mode', 0, PARAM_INT); // Display mode (for single forum)
|
|
|
|
$showall = optional_param('showall', '', PARAM_INT); // show all discussions on one page
|
|
|
|
$changegroup = optional_param('group', -1, PARAM_INT); // choose the current group
|
|
|
|
$page = optional_param('page', 0, PARAM_INT); // which page to show
|
2009-08-27 18:37:53 +00:00
|
|
|
$search = optional_param('search', '', PARAM_CLEAN);// search string
|
2006-09-21 05:42:35 +00:00
|
|
|
|
2009-07-14 09:36:02 +00:00
|
|
|
$params = array();
|
|
|
|
if ($id) {
|
|
|
|
$params['id'] = $id;
|
|
|
|
} else {
|
|
|
|
$params['f'] = $f;
|
|
|
|
}
|
|
|
|
if ($page) {
|
|
|
|
$params['page'] = $page;
|
|
|
|
}
|
|
|
|
if ($search) {
|
|
|
|
$params['search'] = $search;
|
|
|
|
}
|
2010-01-16 15:39:56 +00:00
|
|
|
$PAGE->set_url('/mod/forum/view.php', $params);
|
2006-09-21 05:42:35 +00:00
|
|
|
|
2002-06-20 15:15:22 +00:00
|
|
|
if ($id) {
|
2006-08-08 22:09:55 +00:00
|
|
|
if (! $cm = get_coursemodule_from_id('forum', $id)) {
|
2008-07-21 08:03:42 +00:00
|
|
|
print_error('invalidcoursemodule');
|
2002-06-20 15:15:22 +00:00
|
|
|
}
|
2008-06-05 20:16:09 +00:00
|
|
|
if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
|
2008-07-21 08:03:42 +00:00
|
|
|
print_error('coursemisconf');
|
2002-06-20 15:15:22 +00:00
|
|
|
}
|
2008-06-05 20:16:09 +00:00
|
|
|
if (! $forum = $DB->get_record("forum", array("id" => $cm->instance))) {
|
2008-07-21 08:03:42 +00:00
|
|
|
print_error('invalidforumid', 'forum');
|
2002-06-20 15:15:22 +00:00
|
|
|
}
|
2009-01-14 05:01:11 +00:00
|
|
|
// move require_course_login here to use forced language for course
|
|
|
|
// fix for MDL-6926
|
|
|
|
require_course_login($course, true, $cm);
|
2004-02-20 02:29:30 +00:00
|
|
|
$strforums = get_string("modulenameplural", "forum");
|
|
|
|
$strforum = get_string("modulename", "forum");
|
2002-06-20 15:15:22 +00:00
|
|
|
} else if ($f) {
|
2006-09-21 05:42:35 +00:00
|
|
|
|
2008-06-05 20:16:09 +00:00
|
|
|
if (! $forum = $DB->get_record("forum", array("id" => $f))) {
|
2008-07-21 08:03:42 +00:00
|
|
|
print_error('invalidforumid', 'forum');
|
2002-06-20 15:15:22 +00:00
|
|
|
}
|
2008-06-05 20:16:09 +00:00
|
|
|
if (! $course = $DB->get_record("course", array("id" => $forum->course))) {
|
2008-07-21 08:03:42 +00:00
|
|
|
print_error('coursemisconf');
|
2002-06-20 15:15:22 +00:00
|
|
|
}
|
2004-02-20 02:29:30 +00:00
|
|
|
|
2008-02-13 17:03:25 +00:00
|
|
|
if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
|
2008-07-21 08:03:42 +00:00
|
|
|
print_error('missingparameter');
|
2002-07-29 08:11:12 +00:00
|
|
|
}
|
2009-01-14 05:01:11 +00:00
|
|
|
// move require_course_login here to use forced language for course
|
|
|
|
// fix for MDL-6926
|
|
|
|
require_course_login($course, true, $cm);
|
|
|
|
$strforums = get_string("modulenameplural", "forum");
|
|
|
|
$strforum = get_string("modulename", "forum");
|
2002-06-20 15:15:22 +00:00
|
|
|
} else {
|
2008-07-21 08:03:42 +00:00
|
|
|
print_error('missingparameter');
|
2002-06-20 15:15:22 +00:00
|
|
|
}
|
|
|
|
|
2009-07-15 02:54:40 +00:00
|
|
|
if (!$PAGE->button) {
|
|
|
|
$PAGE->set_button(forum_search_form($course, $search));
|
2005-01-19 13:16:29 +00:00
|
|
|
}
|
2002-08-15 17:41:24 +00:00
|
|
|
|
2006-09-26 08:37:56 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2009-07-15 02:54:40 +00:00
|
|
|
$PAGE->set_context($context);
|
2006-09-21 05:42:35 +00:00
|
|
|
|
2010-05-13 08:44:35 +00:00
|
|
|
if (!empty($CFG->enablerssfeeds) && !empty($CFG->forum_enablerssfeeds) && $forum->rsstype && $forum->rssarticles) {
|
|
|
|
require_once("$CFG->libdir/rsslib.php");
|
|
|
|
|
|
|
|
$rsstitle = format_string($course->shortname) . ': %fullname%';
|
2010-07-21 02:11:53 +00:00
|
|
|
rss_add_http_header($context, 'mod_forum', $forum, $rsstitle);
|
2010-05-13 08:44:35 +00:00
|
|
|
}
|
|
|
|
|
2011-04-06 18:05:43 +01:00
|
|
|
// Mark viewed if required
|
|
|
|
$completion = new completion_info($course);
|
|
|
|
$completion->set_module_viewed($cm);
|
|
|
|
|
2006-09-21 05:42:35 +00:00
|
|
|
/// Print header.
|
2009-11-02 06:38:52 +00:00
|
|
|
|
2009-07-15 02:54:40 +00:00
|
|
|
$PAGE->set_title(format_string($forum->name));
|
2010-05-17 16:00:36 +00:00
|
|
|
$PAGE->add_body_class('forumtype-'.$forum->type);
|
2009-07-15 02:54:40 +00:00
|
|
|
$PAGE->set_heading(format_string($course->fullname));
|
2010-05-17 16:00:36 +00:00
|
|
|
|
2009-09-08 02:23:00 +00:00
|
|
|
echo $OUTPUT->header();
|
2006-09-21 05:42:35 +00:00
|
|
|
|
2006-09-26 08:37:56 +00:00
|
|
|
/// Some capability checks.
|
2006-08-21 06:56:04 +00:00
|
|
|
if (empty($cm->visible) and !has_capability('moodle/course:viewhiddenactivities', $context)) {
|
2003-05-15 18:03:22 +00:00
|
|
|
notice(get_string("activityiscurrentlyhidden"));
|
|
|
|
}
|
2008-02-13 17:03:25 +00:00
|
|
|
|
2006-09-21 14:05:58 +00:00
|
|
|
if (!has_capability('mod/forum:viewdiscussion', $context)) {
|
2006-09-21 05:42:35 +00:00
|
|
|
notice(get_string('noviewdiscussionspermission', 'forum'));
|
|
|
|
}
|
2008-02-13 17:03:25 +00:00
|
|
|
|
2007-07-05 04:40:48 +00:00
|
|
|
/// find out current groups mode
|
2009-11-30 17:12:48 +00:00
|
|
|
groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/forum/view.php?id=' . $cm->id);
|
2007-08-20 10:52:59 +00:00
|
|
|
$currentgroup = groups_get_activity_group($cm);
|
|
|
|
$groupmode = groups_get_activity_groupmode($cm);
|
2004-01-11 17:46:57 +00:00
|
|
|
|
2006-09-21 05:42:35 +00:00
|
|
|
/// Okay, we can show the discussions. Log the forum view.
|
|
|
|
if ($cm->id) {
|
|
|
|
add_to_log($course->id, "forum", "view forum", "view.php?id=$cm->id", "$forum->id", $cm->id);
|
|
|
|
} else {
|
|
|
|
add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id");
|
|
|
|
}
|
|
|
|
|
2010-05-17 16:00:36 +00:00
|
|
|
$SESSION->fromdiscussion = $FULLME; // Return here if we post or set subscription etc
|
2006-09-21 05:42:35 +00:00
|
|
|
|
|
|
|
|
2006-09-26 08:37:56 +00:00
|
|
|
/// Print settings and things across the top
|
|
|
|
|
|
|
|
// If it's a simple single discussion forum, we need to print the display
|
|
|
|
// mode control.
|
|
|
|
if ($forum->type == 'single') {
|
2008-06-05 20:16:09 +00:00
|
|
|
if (! $discussion = $DB->get_record("forum_discussions", array("forum" => $forum->id))) {
|
|
|
|
if ($discussions = $DB->get_records("forum_discussions", array("forum", $forum->id), "timemodified ASC")) {
|
2006-09-26 08:37:56 +00:00
|
|
|
$discussion = array_pop($discussions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($discussion) {
|
|
|
|
if ($mode) {
|
|
|
|
set_user_preference("forum_displaymode", $mode);
|
|
|
|
}
|
|
|
|
$displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
|
|
|
|
forum_print_mode_form($forum->id, $displaymode, $forum->type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-16 08:42:09 +00:00
|
|
|
if (!empty($forum->blockafter) && !empty($forum->blockperiod)) {
|
|
|
|
$a->blockafter = $forum->blockafter;
|
|
|
|
$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('moodle/course:manageactivities', $context)) {
|
2009-08-18 05:14:39 +00:00
|
|
|
echo $OUTPUT->notification(get_string('qandanotify','forum'));
|
2006-01-16 04:57:48 +00:00
|
|
|
}
|
|
|
|
|
2002-06-25 06:47:34 +00:00
|
|
|
switch ($forum->type) {
|
2004-01-11 17:46:57 +00:00
|
|
|
case 'single':
|
2008-06-05 20:16:09 +00:00
|
|
|
if (! $discussion = $DB->get_record("forum_discussions", array("forum" => $forum->id))) {
|
|
|
|
if ($discussions = $DB->get_records("forum_discussions", array("forum" => $forum->id), "timemodified ASC")) {
|
2009-08-18 05:14:39 +00:00
|
|
|
echo $OUTPUT->notification("Warning! There is more than one discussion in this forum - using the most recent");
|
2002-07-31 14:19:35 +00:00
|
|
|
$discussion = array_pop($discussions);
|
|
|
|
} else {
|
2008-07-21 08:03:42 +00:00
|
|
|
print_error('nodiscussions', 'forum');
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-01 03:50:27 +00:00
|
|
|
if (! $post = forum_get_post_full($discussion->firstpost)) {
|
2008-07-21 08:03:42 +00:00
|
|
|
print_error('cannotfindfirstpost', 'forum');
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2004-01-30 08:45:11 +00:00
|
|
|
if ($mode) {
|
|
|
|
set_user_preference("forum_displaymode", $mode);
|
|
|
|
}
|
2008-04-14 09:38:50 +00:00
|
|
|
|
2008-04-19 10:49:53 +00:00
|
|
|
$canreply = forum_user_can_post($forum, $discussion, $USER, $cm, $course, $context);
|
|
|
|
$canrate = has_capability('mod/forum:rate', $context);
|
2004-01-30 08:45:11 +00:00
|
|
|
$displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
|
2008-04-19 10:49:53 +00:00
|
|
|
|
2008-04-14 09:31:25 +00:00
|
|
|
echo ' '; // this should fix the floating in FF
|
2008-04-14 09:38:50 +00:00
|
|
|
forum_print_discussion($course, $cm, $forum, $discussion, $post, $displaymode, $canreply, $canrate);
|
2002-07-31 14:19:35 +00:00
|
|
|
break;
|
|
|
|
|
2004-01-11 17:46:57 +00:00
|
|
|
case 'eachuser':
|
2004-02-13 15:20:06 +00:00
|
|
|
if (!empty($forum->intro)) {
|
2009-08-10 04:59:43 +00:00
|
|
|
echo $OUTPUT->box(format_module_intro('forum', $forum, $cm->id), 'generalbox', 'intro');
|
2003-08-12 16:37:52 +00:00
|
|
|
}
|
2009-01-16 04:52:30 +00:00
|
|
|
echo '<p class="mdl-align">';
|
2008-04-14 19:05:36 +00:00
|
|
|
if (forum_user_can_post_discussion($forum, null, -1, $cm)) {
|
2002-08-15 17:41:24 +00:00
|
|
|
print_string("allowsdiscussions", "forum");
|
2002-06-25 06:47:34 +00:00
|
|
|
} else {
|
2006-01-16 04:29:41 +00:00
|
|
|
echo ' ';
|
2002-06-25 06:47:34 +00:00
|
|
|
}
|
2004-01-11 17:46:57 +00:00
|
|
|
echo '</p>';
|
2003-08-12 16:37:52 +00:00
|
|
|
if (!empty($showall)) {
|
2008-04-13 19:15:02 +00:00
|
|
|
forum_print_latest_discussions($course, $forum, 0, 'header', '', -1, -1, -1, 0, $cm);
|
2003-08-12 16:37:52 +00:00
|
|
|
} else {
|
2008-04-13 19:15:02 +00:00
|
|
|
forum_print_latest_discussions($course, $forum, -1, 'header', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm);
|
2003-08-12 16:37:52 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-01-11 17:46:57 +00:00
|
|
|
case 'teacher':
|
2003-04-18 05:54:18 +00:00
|
|
|
if (!empty($showall)) {
|
2008-04-13 19:15:02 +00:00
|
|
|
forum_print_latest_discussions($course, $forum, 0, 'header', '', -1, -1, -1, 0, $cm);
|
2003-04-18 05:54:18 +00:00
|
|
|
} else {
|
2008-04-13 19:15:02 +00:00
|
|
|
forum_print_latest_discussions($course, $forum, -1, 'header', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm);
|
2003-04-18 05:54:18 +00:00
|
|
|
}
|
2002-06-25 06:47:34 +00:00
|
|
|
break;
|
|
|
|
|
2009-10-30 07:25:50 +00:00
|
|
|
case 'blog':
|
|
|
|
if (!empty($forum->intro)) {
|
|
|
|
echo $OUTPUT->box(format_module_intro('forum', $forum, $cm->id), 'generalbox', 'intro');
|
|
|
|
}
|
|
|
|
echo '<br />';
|
|
|
|
if (!empty($showall)) {
|
|
|
|
forum_print_latest_discussions($course, $forum, 0, 'plain', '', -1, -1, -1, 0, $cm);
|
|
|
|
} else {
|
|
|
|
forum_print_latest_discussions($course, $forum, -1, 'plain', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-06-25 06:47:34 +00:00
|
|
|
default:
|
2004-02-13 15:20:06 +00:00
|
|
|
if (!empty($forum->intro)) {
|
2009-08-10 04:59:43 +00:00
|
|
|
echo $OUTPUT->box(format_module_intro('forum', $forum, $cm->id), 'generalbox', 'intro');
|
2003-08-12 16:37:52 +00:00
|
|
|
}
|
2004-12-14 08:52:33 +00:00
|
|
|
echo '<br />';
|
2003-04-18 05:54:18 +00:00
|
|
|
if (!empty($showall)) {
|
2008-04-13 19:15:02 +00:00
|
|
|
forum_print_latest_discussions($course, $forum, 0, 'header', '', -1, -1, -1, 0, $cm);
|
2003-04-18 05:54:18 +00:00
|
|
|
} else {
|
2008-04-13 19:15:02 +00:00
|
|
|
forum_print_latest_discussions($course, $forum, -1, 'header', '', -1, -1, $page, $CFG->forum_manydiscussions, $cm);
|
2003-04-18 05:54:18 +00:00
|
|
|
}
|
2008-02-13 17:03:25 +00:00
|
|
|
|
|
|
|
|
2002-06-25 06:47:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-04-06 18:05:43 +01:00
|
|
|
|
2009-07-15 02:54:40 +00:00
|
|
|
echo $OUTPUT->footer($course);
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2009-11-01 14:55:15 +00:00
|
|
|
|