2002-07-31 14:19:35 +00:00
|
|
|
<?PHP // $Id$
|
|
|
|
|
|
|
|
// Displays a post, and all the posts below it.
|
|
|
|
// If no post is given, displays all posts in a discussion
|
|
|
|
|
2003-01-05 14:19:20 +00:00
|
|
|
require_once("../../config.php");
|
|
|
|
require_once("lib.php");
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
require_variable($d); // Discussion ID
|
|
|
|
optional_variable($parent); // If set, then display this post and all children.
|
|
|
|
optional_variable($mode); // If set, changes the layout of the thread
|
2003-04-24 08:45:27 +00:00
|
|
|
optional_variable($move); // If set, moves this discussion to another forum
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
if (! $discussion = get_record("forum_discussions", "id", $d)) {
|
2002-08-03 08:16:31 +00:00
|
|
|
error("Discussion ID was incorrect or no longer exists");
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! $course = get_record("course", "id", $discussion->course)) {
|
|
|
|
error("Course ID is incorrect - discussion is faulty");
|
|
|
|
}
|
|
|
|
|
2003-04-24 08:45:27 +00:00
|
|
|
if ($course->category) {
|
|
|
|
require_login($course->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($move)) {
|
|
|
|
if (!isteacher($course->id)) {
|
|
|
|
error("Only teachers can do that!");
|
|
|
|
}
|
|
|
|
if ($forum = get_record("forum", "id", $move)) {
|
2003-08-17 14:46:44 +00:00
|
|
|
if (!forum_move_attachments($discussion, $move)) {
|
|
|
|
notify("Errors occurred while moving attachment directories - check your file permissions");
|
|
|
|
}
|
2003-04-24 08:45:27 +00:00
|
|
|
set_field("forum_discussions", "forum", $forum->id, "id", $discussion->id);
|
|
|
|
$discussion->forum = $forum->id;
|
2004-01-31 14:47:57 +00:00
|
|
|
if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
|
|
|
|
add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id",
|
|
|
|
$cm->id);
|
|
|
|
} else {
|
|
|
|
add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id");
|
|
|
|
}
|
2003-04-28 15:27:44 +00:00
|
|
|
$discussionmoved = true;
|
2003-04-24 08:45:27 +00:00
|
|
|
} else {
|
|
|
|
error("You can't move to that forum - it doesn't exist!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($forum)) {
|
|
|
|
if (! $forum = get_record("forum", "id", $discussion->forum)) {
|
|
|
|
notify("Bad forum ID stored in this discussion");
|
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
2003-04-24 08:45:27 +00:00
|
|
|
$logparameters = "d=$discussion->id";
|
|
|
|
if ($parent) {
|
|
|
|
$logparameters .= "&parent=$parent";
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
2004-01-31 14:47:57 +00:00
|
|
|
|
|
|
|
if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
|
|
|
|
add_to_log($course->id, "forum", "view discussion", "discuss.php?$logparameters", "$discussion->id", $cm->id);
|
|
|
|
} else {
|
|
|
|
add_to_log($course->id, "forum", "view discussion", "discuss.php?$logparameters", "$discussion->id");
|
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
unset($SESSION->fromdiscussion);
|
|
|
|
|
2004-01-28 14:48:49 +00:00
|
|
|
if ($mode) {
|
|
|
|
set_user_preference("forum_displaymode", $mode);
|
|
|
|
}
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2004-01-28 14:48:49 +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) {
|
2004-01-28 14:48:49 +00:00
|
|
|
if (abs($displaymode) == 1) { // If flat AND parent, then force nested display this time
|
2002-09-02 05:03:54 +00:00
|
|
|
$displaymode = 3;
|
|
|
|
}
|
|
|
|
} else {
|
2002-07-31 14:19:35 +00:00
|
|
|
$parent = $discussion->firstpost;
|
|
|
|
$navtail = "$discussion->name";
|
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
if (! $post = forum_get_post_full($parent)) {
|
2002-07-31 14:19:35 +00:00
|
|
|
error("Discussion no longer exists", "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
|
|
|
|
}
|
|
|
|
|
2003-01-02 10:35:11 +00:00
|
|
|
if (empty($navtail)) {
|
2002-07-31 14:19:35 +00:00
|
|
|
$navtail = "<A HREF=\"discuss.php?d=$discussion->id\">$discussion->name</A> -> $post->subject";
|
|
|
|
}
|
|
|
|
|
2002-08-02 09:19:45 +00:00
|
|
|
$navmiddle = "<A HREF=\"../forum/index.php?id=$course->id\">".get_string("forums", "forum")."</A> -> <A HREF=\"../forum/view.php?f=$forum->id\">$forum->name</A>";
|
2002-07-31 14:19:35 +00:00
|
|
|
|
2002-12-29 17:32:32 +00:00
|
|
|
$searchform = forum_print_search_form($course, "", true, "plain");
|
2002-12-23 15:33:40 +00:00
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
if ($course->category) {
|
|
|
|
print_header("$course->shortname: $discussion->name", "$course->fullname",
|
|
|
|
"<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> ->
|
2002-12-23 15:33:40 +00:00
|
|
|
$navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm));
|
2002-07-31 14:19:35 +00:00
|
|
|
} else {
|
|
|
|
print_header("$course->shortname: $discussion->name", "$course->fullname",
|
2002-12-23 15:33:40 +00:00
|
|
|
"$navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm));
|
2002-07-31 14:19:35 +00:00
|
|
|
}
|
|
|
|
|
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
|
2004-01-20 13:51:27 +00:00
|
|
|
/// Also, if we know they should be able to reply, then explicitly set $canreply
|
|
|
|
|
|
|
|
$canreply = NULL; /// No override one way or the other
|
2004-01-11 17:46:57 +00:00
|
|
|
|
|
|
|
$groupmode = groupmode($course, $cm);
|
|
|
|
|
2004-01-20 13:51:27 +00:00
|
|
|
if ($groupmode and !isteacheredit($course->id)) { // Groups must be kept separate
|
|
|
|
if ($groupmode == SEPARATEGROUPS) {
|
|
|
|
require_login();
|
|
|
|
|
2004-01-23 12:09:25 +00:00
|
|
|
if (mygroupid($course->id) == $discussion->groupid) {
|
2004-01-20 13:51:27 +00:00
|
|
|
$canreply = true;
|
|
|
|
} else {
|
|
|
|
print_heading("Sorry, you can't see this discussion because you are not in this group");
|
|
|
|
print_footer();
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if ($groupmode == VISIBLEGROUPS) {
|
2004-01-23 12:09:25 +00:00
|
|
|
$canreply = (mygroupid($course->id) == $discussion->groupid);
|
2004-01-11 17:46:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-20 13:51:27 +00:00
|
|
|
/// Print the controls across the top
|
|
|
|
|
|
|
|
echo "<table width=\"100%\"><tr><td width=\"33%\">";
|
|
|
|
|
|
|
|
if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
|
|
|
|
if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
|
2004-02-19 17:57:22 +00:00
|
|
|
print_group_menu($groups, $groupmode, $discussion->groupid, "view.php?id=$cm->id&group=");
|
2004-01-20 13:51:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "</td><td width=\"33%\">";
|
2003-08-16 06:20:39 +00:00
|
|
|
forum_print_mode_form($discussion->id, $displaymode);
|
2004-01-20 13:51:27 +00:00
|
|
|
|
2003-08-15 13:59:24 +00:00
|
|
|
echo "</td><td width=\"33%\">";
|
2003-04-24 08:45:27 +00:00
|
|
|
if (isteacher($course->id)) { // Popup menu to allow discussions to be moved to other forums
|
2003-07-12 05:19:18 +00:00
|
|
|
if ($forums = get_all_instances_in_course("forum", $course)) {
|
2003-04-24 08:45:27 +00:00
|
|
|
foreach ($forums as $courseforum) {
|
|
|
|
if ($courseforum->id != $forum->id) {
|
|
|
|
$url = "discuss.php?d=$discussion->id&move=$courseforum->id";
|
|
|
|
$forummenu[$url] = $courseforum->name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty($forummenu)) {
|
|
|
|
echo "<div align=\"right\">";
|
|
|
|
echo popup_form("$CFG->wwwroot/mod/forum/", $forummenu, "forummenu", "",
|
|
|
|
get_string("movethisdiscussionto", "forum"), "", "", true);
|
|
|
|
echo "</div>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-08-15 13:59:24 +00:00
|
|
|
echo "</td></tr></table>";
|
2003-04-24 08:45:27 +00:00
|
|
|
|
2003-04-28 15:27:44 +00:00
|
|
|
if (isset($discussionmoved)) {
|
|
|
|
notify(get_string("discussionmoved", "forum", $forum->name));
|
|
|
|
}
|
|
|
|
|
2004-01-20 13:51:27 +00:00
|
|
|
|
|
|
|
/// Print the actual discussion
|
|
|
|
|
|
|
|
forum_print_discussion($course, $forum, $discussion, $post, $displaymode, $canreply);
|
|
|
|
|
2002-07-31 14:19:35 +00:00
|
|
|
|
|
|
|
print_footer($course);
|
|
|
|
|
|
|
|
?>
|