2004-09-12 16:24:41 +00:00
|
|
|
<?php // $Id$
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2003-01-05 14:19:20 +00:00
|
|
|
require_once("../../config.php");
|
|
|
|
require_once("lib.php");
|
2005-01-25 06:09:31 +00:00
|
|
|
require_once("$CFG->libdir/rsslib.php");
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2004-12-14 11:08:04 +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
|
2006-02-12 11:27:22 +00:00
|
|
|
$changegroup = optional_param('group', -1, PARAM_INT); // choose the current group
|
2004-12-14 11:08:04 +00:00
|
|
|
$page = optional_param('page', 0, PARAM_INT); // which page to show
|
|
|
|
$search = optional_param('search', ''); // search string
|
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)) {
|
2002-06-20 15:15:22 +00:00
|
|
|
error("Course Module ID was incorrect");
|
|
|
|
}
|
|
|
|
if (! $course = get_record("course", "id", $cm->course)) {
|
|
|
|
error("Course is misconfigured");
|
|
|
|
}
|
|
|
|
if (! $forum = get_record("forum", "id", $cm->instance)) {
|
|
|
|
error("Forum ID was incorrect");
|
|
|
|
}
|
2004-02-20 02:29:30 +00:00
|
|
|
|
|
|
|
$strforums = get_string("modulenameplural", "forum");
|
|
|
|
$strforum = get_string("modulename", "forum");
|
|
|
|
|
2002-10-16 04:51:55 +00:00
|
|
|
$buttontext = update_module_button($cm->id, $course->id, $strforum);
|
2002-06-20 15:15:22 +00:00
|
|
|
|
|
|
|
} else if ($f) {
|
|
|
|
if (! $forum = get_record("forum", "id", $f)) {
|
2002-08-03 08:16:31 +00:00
|
|
|
error("Forum ID was incorrect or no longer exists");
|
2002-06-20 15:15:22 +00:00
|
|
|
}
|
|
|
|
if (! $course = get_record("course", "id", $forum->course)) {
|
|
|
|
error("Forum is misconfigured - don't know what course it's from");
|
|
|
|
}
|
2004-02-20 02:29:30 +00:00
|
|
|
|
|
|
|
$strforums = get_string("modulenameplural", "forum");
|
|
|
|
$strforum = get_string("modulename", "forum");
|
|
|
|
|
2002-07-29 08:11:12 +00:00
|
|
|
if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
|
2002-10-16 04:51:55 +00:00
|
|
|
$buttontext = update_module_button($cm->id, $course->id, $strforum);
|
2002-07-29 08:11:12 +00:00
|
|
|
} else {
|
2005-08-02 22:48:20 +00:00
|
|
|
$cm->id = 0;
|
2005-02-18 06:41:12 +00:00
|
|
|
$cm->visible = 1;
|
|
|
|
$cm->course = $course->id;
|
2002-07-29 08:11:12 +00:00
|
|
|
$buttontext = "";
|
|
|
|
}
|
2002-06-20 15:15:22 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
error("Must specify a course module or a forum ID");
|
|
|
|
}
|
|
|
|
|
2002-12-23 15:33:40 +00:00
|
|
|
if (!$buttontext) {
|
2005-03-09 20:50:37 +00:00
|
|
|
$buttontext = forum_search_form($course, $search);
|
2005-01-19 13:16:29 +00:00
|
|
|
}
|
2002-08-15 17:41:24 +00:00
|
|
|
|
2005-02-16 10:40:48 +00:00
|
|
|
require_course_login($course, true, $cm);
|
2004-03-12 01:54:10 +00:00
|
|
|
|
2004-08-21 20:20:58 +00:00
|
|
|
$navigation = "<a href=\"index.php?id=$course->id\">$strforums</a> ->";
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2002-07-04 08:30:36 +00:00
|
|
|
|
2006-08-21 06:56:04 +00:00
|
|
|
/// Check whether the user should be able to view this forum.
|
2006-08-08 05:13:06 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
|
|
|
|
2006-08-14 05:55:40 +00:00
|
|
|
if (!has_capability('mod/forum:viewforum', $context)) {
|
2006-08-08 05:13:06 +00:00
|
|
|
error('You do not have the permission to view this forum');
|
|
|
|
}
|
|
|
|
|
2005-08-02 22:48:20 +00:00
|
|
|
if ($cm->id) {
|
2004-01-31 14:47:57 +00:00
|
|
|
add_to_log($course->id, "forum", "view forum", "view.php?id=$cm->id", "$forum->id", $cm->id);
|
2004-01-15 07:26:52 +00:00
|
|
|
} else {
|
|
|
|
add_to_log($course->id, "forum", "view forum", "view.php?f=$forum->id", "$forum->id");
|
|
|
|
}
|
2002-06-20 15:15:22 +00:00
|
|
|
|
2005-03-26 01:57:40 +00:00
|
|
|
print_header_simple(format_string($forum->name), "",
|
|
|
|
"$navigation ".format_string($forum->name), "", "", true, $buttontext, navmenu($course, $cm));
|
2002-06-20 15:15:22 +00:00
|
|
|
|
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"));
|
|
|
|
}
|
|
|
|
|
2004-01-11 17:46:57 +00:00
|
|
|
|
2006-08-22 07:38:01 +00:00
|
|
|
$groupmode = groupmode($course, $cm);
|
2005-11-08 07:19:27 +00:00
|
|
|
|
2004-02-19 17:57:22 +00:00
|
|
|
$currentgroup = get_and_set_current_group($course, $groupmode, $changegroup);
|
2005-11-08 07:19:27 +00:00
|
|
|
|
2006-08-08 05:13:06 +00:00
|
|
|
if ($groupmode and ($currentgroup === false) and
|
2006-08-14 05:55:40 +00:00
|
|
|
!has_capability('moodle/site:accessallgroups', $context)) {
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2004-02-19 17:57:22 +00:00
|
|
|
print_heading(get_string("notingroup", "forum"));
|
|
|
|
print_footer($course);
|
2004-01-11 17:46:57 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Print settings and things in a table across the top
|
|
|
|
|
|
|
|
echo '<table width="100%" border="0" cellpadding="3" cellspacing="0"><tr valign="top">';
|
|
|
|
|
2005-11-08 07:19:27 +00:00
|
|
|
///2 ways to do this, 1. we can changed the setup_and_print_groups functions
|
|
|
|
///in moodlelib, taking in 1 more parameter, and tell the function when to
|
|
|
|
///allow student menus, 2, we can just use this code to explicitly print this
|
|
|
|
///menu for students in forums.
|
|
|
|
|
|
|
|
//now we need a menu for separategroups as well!
|
2006-08-08 05:13:06 +00:00
|
|
|
if ($groupmode == VISIBLEGROUPS or ($groupmode and
|
2006-08-14 05:55:40 +00:00
|
|
|
has_capability('moodle/site:accessallgroups', $context))) {
|
2006-08-08 05:13:06 +00:00
|
|
|
|
2005-11-08 07:19:27 +00:00
|
|
|
//the following query really needs to change
|
2004-01-11 17:46:57 +00:00
|
|
|
if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
|
|
|
|
echo '<td>';
|
2004-03-02 22:11:48 +00:00
|
|
|
print_group_menu($groups, $groupmode, $currentgroup, "view.php?id=$cm->id");
|
2004-01-11 17:46:57 +00:00
|
|
|
echo '</td>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-08 07:19:27 +00:00
|
|
|
//only print menus the student is in any course
|
|
|
|
else if ($groupmode == SEPARATEGROUPS){
|
|
|
|
$validgroups = array();
|
|
|
|
//get all the groups this guy is in in this course
|
|
|
|
|
|
|
|
if ($p = user_group($course->id,$USER->id)){
|
|
|
|
//extract the name and id for the group
|
|
|
|
foreach ($p as $index => $object){
|
|
|
|
$validgroups[$object->id] = $object->name;
|
|
|
|
}
|
|
|
|
//print_r($validgroups);
|
|
|
|
echo '<td>';
|
|
|
|
//print them in the menu
|
|
|
|
print_group_menu($validgroups, $groupmode, $currentgroup, "view.php?id=$cm->id",0);
|
|
|
|
echo '</td>';
|
|
|
|
}
|
|
|
|
}
|
2004-01-11 17:46:57 +00:00
|
|
|
|
2004-10-05 23:21:38 +00:00
|
|
|
if (!empty($USER->id)) {
|
2005-03-07 05:00:58 +00:00
|
|
|
echo '<td align="right" class="subscription">';
|
2002-07-31 14:19:35 +00:00
|
|
|
$SESSION->fromdiscussion = "$FULLME";
|
|
|
|
if (forum_is_forcesubscribed($forum->id)) {
|
2005-03-07 05:00:58 +00:00
|
|
|
$streveryoneissubscribed = get_string('everyoneissubscribed', 'forum');
|
|
|
|
$strallowchoice = get_string('allowchoice', 'forum');
|
2005-03-07 05:03:48 +00:00
|
|
|
helpbutton("subscription", $streveryoneissubscribed, "forum");
|
|
|
|
echo ' <span class="helplink">';
|
2006-08-14 05:55:40 +00:00
|
|
|
if (has_capability('moodle/course:manageactivities', $context)) {
|
2004-09-16 17:13:57 +00:00
|
|
|
echo "<a title=\"$strallowchoice\" href=\"subscribe.php?id=$forum->id&force=no\">$streveryoneissubscribed</a>";
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
2003-04-23 15:19:01 +00:00
|
|
|
echo $streveryoneissubscribed;
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2005-03-07 05:00:58 +00:00
|
|
|
echo '</span>';
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2006-01-16 04:57:48 +00:00
|
|
|
} else if ($forum->forcesubscribe == FORUM_DISALLOWSUBSCRIBE) {
|
|
|
|
$strsubscriptionsoff = get_string('disallowsubscribe','forum');
|
|
|
|
echo $strsubscriptionsoff;
|
|
|
|
helpbutton("subscription", $strsubscriptionsoff, "forum");
|
2002-06-20 15:15:22 +00:00
|
|
|
} else {
|
2002-08-15 17:41:24 +00:00
|
|
|
$streveryonecanchoose = get_string("everyonecanchoose", "forum");
|
|
|
|
$strforcesubscribe = get_string("forcesubscribe", "forum");
|
|
|
|
$strshowsubscribers = get_string("showsubscribers", "forum");
|
2003-04-23 15:19:01 +00:00
|
|
|
|
2005-03-07 05:03:48 +00:00
|
|
|
helpbutton("subscription", $streveryonecanchoose, "forum");
|
|
|
|
echo ' ';
|
2006-08-14 05:55:40 +00:00
|
|
|
if (has_capability('moodle/course:manageactivities', $context)) {
|
2005-03-07 05:00:58 +00:00
|
|
|
echo "<span class=\"helplink\"><a title=\"$strforcesubscribe\" href=\"subscribe.php?id=$forum->id&force=yes\">$streveryonecanchoose</a></span>";
|
|
|
|
echo "<br />";
|
|
|
|
echo "<span class=\"helplink\"><a href=\"subscribers.php?id=$forum->id\">$strshowsubscribers</a></span>";
|
2002-07-31 15:09:39 +00:00
|
|
|
} else {
|
2005-03-07 05:00:58 +00:00
|
|
|
echo '<span class="helplink">'.$streveryonecanchoose.'</span>';
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2003-04-23 15:19:01 +00:00
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
if (forum_is_subscribed($USER->id, $forum->id)) {
|
2003-05-23 05:00:58 +00:00
|
|
|
$subtexttitle = get_string("subscribestop", "forum");
|
2002-08-15 17:41:24 +00:00
|
|
|
$subtext = get_string("unsubscribe", "forum");
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
2003-05-23 05:00:58 +00:00
|
|
|
$subtexttitle = get_string("subscribestart", "forum");
|
2002-08-15 17:41:24 +00:00
|
|
|
$subtext = get_string("subscribe", "forum");
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2004-01-11 17:46:57 +00:00
|
|
|
echo "<br />";
|
2005-03-07 05:00:58 +00:00
|
|
|
echo "<span class=\"helplink\"><a title=\"$subtexttitle\" href=\"subscribe.php?id=$forum->id\">$subtext</a></span>";
|
2002-07-14 13:32:51 +00:00
|
|
|
}
|
2004-05-02 23:08:19 +00:00
|
|
|
|
2005-04-26 16:27:51 +00:00
|
|
|
if (forum_tp_can_track_forums($forum) && ($forum->trackingtype == FORUM_TRACKING_OPTIONAL)) {
|
|
|
|
if (forum_tp_is_tracked($forum, $USER->id)) {
|
2005-04-25 14:02:00 +00:00
|
|
|
$trtitle = get_string('notrackforum', 'forum');
|
|
|
|
$trackedlink = '<a title="'.get_string('notrackforum', 'forum').'" href="settracking.php?id='.
|
|
|
|
$forum->id.'&returnpage=view.php">'.get_string('notrackforum', 'forum').'</a>';
|
|
|
|
} else {
|
|
|
|
$trtitle = get_string('trackforum', 'forum');
|
|
|
|
$trackedlink = '<a title="'.get_string('trackforum', 'forum').'" href="settracking.php?id='.
|
|
|
|
$forum->id.'&returnpage=view.php">'.get_string('trackforum', 'forum').'</a>';
|
|
|
|
}
|
|
|
|
echo "<br />";
|
|
|
|
echo "<span class=\"helplink\">$trackedlink</span>";
|
|
|
|
}
|
|
|
|
|
2004-10-05 23:21:38 +00:00
|
|
|
echo '</td>';
|
|
|
|
}
|
2004-05-02 23:08:19 +00:00
|
|
|
|
2004-10-05 23:21:38 +00:00
|
|
|
//If rss are activated at site and forum level and this forum has rss defined, show link
|
|
|
|
if (isset($CFG->enablerssfeeds) && isset($CFG->forum_enablerssfeeds) &&
|
|
|
|
$CFG->enablerssfeeds && $CFG->forum_enablerssfeeds && $forum->rsstype and $forum->rssarticles) {
|
|
|
|
echo '</tr><tr><td align="right">';
|
|
|
|
if ($forum->rsstype == 1) {
|
2005-03-26 01:57:40 +00:00
|
|
|
$tooltiptext = get_string("rsssubscriberssdiscussions","forum",format_string($forum->name));
|
2005-01-19 13:16:29 +00:00
|
|
|
} else {
|
2005-03-26 01:57:40 +00:00
|
|
|
$tooltiptext = get_string("rsssubscriberssposts","forum",format_string($forum->name));
|
2004-10-05 23:21:38 +00:00
|
|
|
}
|
|
|
|
if (empty($USER->id)) {
|
|
|
|
$userid = 0;
|
|
|
|
} else {
|
|
|
|
$userid = $USER->id;
|
|
|
|
}
|
|
|
|
rss_print_link($course->id, $userid, "forum", $forum->id, $tooltiptext);
|
2004-01-11 17:46:57 +00:00
|
|
|
echo '</td>';
|
2002-06-20 15:15:22 +00:00
|
|
|
}
|
|
|
|
|
2004-01-11 17:46:57 +00:00
|
|
|
echo '</tr></table>';
|
|
|
|
|
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);
|
|
|
|
notify(get_string('thisforumisthrottled','forum',$a));
|
|
|
|
}
|
|
|
|
|
2006-08-14 05:55:40 +00:00
|
|
|
if ($forum->type == 'qanda' && !has_capability('moodle/course:manageactivities', $context)) {
|
2006-01-16 04:57:48 +00:00
|
|
|
notify(get_string('qandanotify','forum'));
|
|
|
|
}
|
|
|
|
|
2004-02-13 15:20:06 +00:00
|
|
|
$forum->intro = trim($forum->intro);
|
2002-06-25 06:47:34 +00:00
|
|
|
|
|
|
|
switch ($forum->type) {
|
2004-01-11 17:46:57 +00:00
|
|
|
case 'single':
|
2002-07-31 14:19:35 +00:00
|
|
|
if (! $discussion = get_record("forum_discussions", "forum", $forum->id)) {
|
|
|
|
if ($discussions = get_records("forum_discussions", "forum", $forum->id, "timemodified ASC")) {
|
|
|
|
notify("Warning! There is more than one discussion in this forum - using the most recent");
|
|
|
|
$discussion = array_pop($discussions);
|
|
|
|
} else {
|
|
|
|
error("Could not find the discussion in this forum");
|
|
|
|
}
|
|
|
|
}
|
2002-08-01 03:50:27 +00:00
|
|
|
if (! $post = forum_get_post_full($discussion->firstpost)) {
|
2002-07-31 14:19:35 +00:00
|
|
|
error("Could not find the first post in this forum");
|
|
|
|
}
|
2004-01-30 08:45:11 +00:00
|
|
|
if ($mode) {
|
|
|
|
set_user_preference("forum_displaymode", $mode);
|
|
|
|
}
|
|
|
|
$displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode);
|
2006-08-14 05:55:40 +00:00
|
|
|
$canrate = has_capability('mod/forum:rate', $context);
|
2006-08-08 05:13:06 +00:00
|
|
|
forum_print_discussion($course, $forum, $discussion, $post, $displaymode, NULL, $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)) {
|
2005-03-13 16:17:55 +00:00
|
|
|
print_simple_box(format_text($forum->intro), 'center', '70%', '', 5, 'generalbox', 'intro');
|
2003-08-12 16:37:52 +00:00
|
|
|
}
|
2004-01-11 17:46:57 +00:00
|
|
|
echo '<p align="center">';
|
2002-08-01 03:50:27 +00:00
|
|
|
if (forum_user_can_post_discussion($forum)) {
|
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)) {
|
2005-03-08 17:32:08 +00:00
|
|
|
forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode);
|
2003-08-12 16:37:52 +00:00
|
|
|
} else {
|
2005-03-08 17:32:08 +00:00
|
|
|
forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page);
|
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)) {
|
2005-03-08 17:32:08 +00:00
|
|
|
forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode);
|
2003-04-18 05:54:18 +00:00
|
|
|
} else {
|
2005-03-08 17:32:08 +00:00
|
|
|
forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page);
|
2003-04-18 05:54:18 +00:00
|
|
|
}
|
2002-06-25 06:47:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2004-02-13 15:20:06 +00:00
|
|
|
if (!empty($forum->intro)) {
|
2005-03-13 16:17:55 +00:00
|
|
|
print_simple_box(format_text($forum->intro), 'center', '70%', '', 5, '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)) {
|
2005-03-08 17:32:08 +00:00
|
|
|
forum_print_latest_discussions($course, $forum, 0, 'header', '', $currentgroup, $groupmode);
|
2003-04-18 05:54:18 +00:00
|
|
|
} else {
|
2005-03-08 17:32:08 +00:00
|
|
|
forum_print_latest_discussions($course, $forum, $CFG->forum_manydiscussions, 'header', '', $currentgroup, $groupmode, $page);
|
2003-04-18 05:54:18 +00:00
|
|
|
}
|
2005-11-08 07:19:27 +00:00
|
|
|
|
|
|
|
|
2002-06-25 06:47:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-06-20 15:15:22 +00:00
|
|
|
print_footer($course);
|
|
|
|
|
2005-03-07 05:00:58 +00:00
|
|
|
?>
|