...And now it works
[moodle.git] / mod / forum / discuss.php
CommitLineData
501cdbd8 1<?PHP // $Id$
2
3// Displays a post, and all the posts below it.
4// If no post is given, displays all posts in a discussion
5
b0e3a925 6 require_once("../../config.php");
7 require_once("lib.php");
501cdbd8 8
9 require_variable($d); // Discussion ID
10 optional_variable($parent); // If set, then display this post and all children.
11 optional_variable($mode); // If set, changes the layout of the thread
1fc49f00 12 optional_variable($move); // If set, moves this discussion to another forum
501cdbd8 13
14 if (! $discussion = get_record("forum_discussions", "id", $d)) {
94361e02 15 error("Discussion ID was incorrect or no longer exists");
501cdbd8 16 }
17
18 if (! $course = get_record("course", "id", $discussion->course)) {
19 error("Course ID is incorrect - discussion is faulty");
20 }
21
1fc49f00 22 if ($course->category) {
23 require_login($course->id);
24 }
25
26 if (!empty($move)) {
27 if (!isteacher($course->id)) {
28 error("Only teachers can do that!");
29 }
30 if ($forum = get_record("forum", "id", $move)) {
31 set_field("forum_discussions", "forum", $forum->id, "id", $discussion->id);
32 $discussion->forum = $forum->id;
33 add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id");
34 } else {
35 error("You can't move to that forum - it doesn't exist!");
36 }
37 }
38
39 if (empty($forum)) {
40 if (! $forum = get_record("forum", "id", $discussion->forum)) {
41 notify("Bad forum ID stored in this discussion");
42 }
501cdbd8 43 }
44
dfc9ba9b 45 if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
b20f74c9 46 //notify("Bad coursemodule for this discussion"); // Only affects navmenu
dfc9ba9b 47 }
48
1fc49f00 49 $logparameters = "d=$discussion->id";
50 if ($parent) {
51 $logparameters .= "&parent=$parent";
501cdbd8 52 }
1fc49f00 53 add_to_log($course->id, "forum", "view discussion", "discuss.php?$logparameters", "$discussion->id");
501cdbd8 54
55 unset($SESSION->fromdiscussion);
56
57 forum_set_display_mode($mode);
58
e92ea3d8 59 $displaymode = $USER->mode;
501cdbd8 60
e92ea3d8 61 if ($parent) {
62 if (abs($USER->mode) == 1) { // If flat AND parent, then force nested display this time
63 $displaymode = 3;
64 }
65 } else {
501cdbd8 66 $parent = $discussion->firstpost;
67 $navtail = "$discussion->name";
68 }
69
11b0c469 70 if (! $post = forum_get_post_full($parent)) {
501cdbd8 71 error("Discussion no longer exists", "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
72 }
73
61e96406 74 if (empty($navtail)) {
501cdbd8 75 $navtail = "<A HREF=\"discuss.php?d=$discussion->id\">$discussion->name</A> -> $post->subject";
76 }
77
f781b794 78 $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>";
501cdbd8 79
9c9f7d77 80 $searchform = forum_print_search_form($course, "", true, "plain");
97485d07 81
501cdbd8 82 if ($course->category) {
83 print_header("$course->shortname: $discussion->name", "$course->fullname",
84 "<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> ->
97485d07 85 $navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm));
501cdbd8 86 } else {
87 print_header("$course->shortname: $discussion->name", "$course->fullname",
97485d07 88 "$navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm));
501cdbd8 89 }
90
1fc49f00 91 if (isteacher($course->id)) { // Popup menu to allow discussions to be moved to other forums
92 if ($forums = get_all_instances_in_course("forum", $course->id, "cw.section ASC")) {
93 foreach ($forums as $courseforum) {
94 if ($courseforum->id != $forum->id) {
95 $url = "discuss.php?d=$discussion->id&move=$courseforum->id";
96 $forummenu[$url] = $courseforum->name;
97 }
98 }
99 if (!empty($forummenu)) {
100 echo "<div align=\"right\">";
101 echo popup_form("$CFG->wwwroot/mod/forum/", $forummenu, "forummenu", "",
102 get_string("movethisdiscussionto", "forum"), "", "", true);
103 echo "</div>";
104 }
105 }
106 }
107
e92ea3d8 108 forum_print_discussion($course, $forum, $discussion, $post, $displaymode);
501cdbd8 109
110 print_footer($course);
111
112?>