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 | |
68ddf8bc |
22 | if ($CFG->forcelogin) { |
23 | require_login(); |
24 | } |
25 | |
1fc49f00 |
26 | if ($course->category) { |
27 | require_login($course->id); |
28 | } |
29 | |
30 | if (!empty($move)) { |
31 | if (!isteacher($course->id)) { |
32 | error("Only teachers can do that!"); |
33 | } |
34 | if ($forum = get_record("forum", "id", $move)) { |
cc2b7ea5 |
35 | if (!forum_move_attachments($discussion, $move)) { |
36 | notify("Errors occurred while moving attachment directories - check your file permissions"); |
37 | } |
1fc49f00 |
38 | set_field("forum_discussions", "forum", $forum->id, "id", $discussion->id); |
39 | $discussion->forum = $forum->id; |
69d79bc3 |
40 | if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { |
41 | add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id", |
42 | $cm->id); |
43 | } else { |
44 | add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id"); |
45 | } |
8de14dc7 |
46 | $discussionmoved = true; |
1fc49f00 |
47 | } else { |
48 | error("You can't move to that forum - it doesn't exist!"); |
49 | } |
50 | } |
51 | |
52 | if (empty($forum)) { |
53 | if (! $forum = get_record("forum", "id", $discussion->forum)) { |
54 | notify("Bad forum ID stored in this discussion"); |
55 | } |
501cdbd8 |
56 | } |
57 | |
1fc49f00 |
58 | $logparameters = "d=$discussion->id"; |
59 | if ($parent) { |
60 | $logparameters .= "&parent=$parent"; |
501cdbd8 |
61 | } |
69d79bc3 |
62 | |
63 | if ($cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) { |
64 | add_to_log($course->id, "forum", "view discussion", "discuss.php?$logparameters", "$discussion->id", $cm->id); |
65 | } else { |
66 | add_to_log($course->id, "forum", "view discussion", "discuss.php?$logparameters", "$discussion->id"); |
67 | } |
501cdbd8 |
68 | |
69 | unset($SESSION->fromdiscussion); |
70 | |
279826e2 |
71 | if ($mode) { |
72 | set_user_preference("forum_displaymode", $mode); |
73 | } |
501cdbd8 |
74 | |
279826e2 |
75 | $displaymode = get_user_preferences("forum_displaymode", $CFG->forum_displaymode); |
501cdbd8 |
76 | |
e92ea3d8 |
77 | if ($parent) { |
279826e2 |
78 | if (abs($displaymode) == 1) { // If flat AND parent, then force nested display this time |
e92ea3d8 |
79 | $displaymode = 3; |
80 | } |
81 | } else { |
501cdbd8 |
82 | $parent = $discussion->firstpost; |
83 | $navtail = "$discussion->name"; |
84 | } |
85 | |
11b0c469 |
86 | if (! $post = forum_get_post_full($parent)) { |
501cdbd8 |
87 | error("Discussion no longer exists", "$CFG->wwwroot/mod/forum/view.php?f=$forum->id"); |
88 | } |
89 | |
61e96406 |
90 | if (empty($navtail)) { |
501cdbd8 |
91 | $navtail = "<A HREF=\"discuss.php?d=$discussion->id\">$discussion->name</A> -> $post->subject"; |
92 | } |
93 | |
f781b794 |
94 | $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 |
95 | |
9c9f7d77 |
96 | $searchform = forum_print_search_form($course, "", true, "plain"); |
97485d07 |
97 | |
501cdbd8 |
98 | if ($course->category) { |
99 | print_header("$course->shortname: $discussion->name", "$course->fullname", |
100 | "<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> -> |
97485d07 |
101 | $navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm)); |
501cdbd8 |
102 | } else { |
103 | print_header("$course->shortname: $discussion->name", "$course->fullname", |
97485d07 |
104 | "$navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm)); |
501cdbd8 |
105 | } |
106 | |
c6d691dc |
107 | |
9197e147 |
108 | /// Check to see if groups are being used in this forum |
109 | /// If so, make sure the current person is allowed to see this discussion |
c6d691dc |
110 | /// Also, if we know they should be able to reply, then explicitly set $canreply |
111 | |
112 | $canreply = NULL; /// No override one way or the other |
9197e147 |
113 | |
114 | $groupmode = groupmode($course, $cm); |
115 | |
c6d691dc |
116 | if ($groupmode and !isteacheredit($course->id)) { // Groups must be kept separate |
c6d691dc |
117 | if ($groupmode == SEPARATEGROUPS) { |
118 | require_login(); |
119 | |
02509fe6 |
120 | if (mygroupid($course->id) == $discussion->groupid) { |
c6d691dc |
121 | $canreply = true; |
122 | } else { |
123 | print_heading("Sorry, you can't see this discussion because you are not in this group"); |
124 | print_footer(); |
125 | die; |
126 | } |
127 | |
128 | } else if ($groupmode == VISIBLEGROUPS) { |
02509fe6 |
129 | $canreply = (mygroupid($course->id) == $discussion->groupid); |
9197e147 |
130 | } |
131 | } |
132 | |
133 | |
c6d691dc |
134 | /// Print the controls across the top |
135 | |
136 | echo "<table width=\"100%\"><tr><td width=\"33%\">"; |
137 | |
138 | if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) { |
139 | if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) { |
2ab76925 |
140 | print_group_menu($groups, $groupmode, $discussion->groupid, "view.php?id=$cm->id&group="); |
c6d691dc |
141 | } |
142 | } |
143 | |
144 | echo "</td><td width=\"33%\">"; |
ec9c0d44 |
145 | forum_print_mode_form($discussion->id, $displaymode); |
c6d691dc |
146 | |
02ebf404 |
147 | echo "</td><td width=\"33%\">"; |
1fc49f00 |
148 | if (isteacher($course->id)) { // Popup menu to allow discussions to be moved to other forums |
cccb016a |
149 | if ($forums = get_all_instances_in_course("forum", $course)) { |
1fc49f00 |
150 | foreach ($forums as $courseforum) { |
151 | if ($courseforum->id != $forum->id) { |
152 | $url = "discuss.php?d=$discussion->id&move=$courseforum->id"; |
153 | $forummenu[$url] = $courseforum->name; |
154 | } |
155 | } |
156 | if (!empty($forummenu)) { |
157 | echo "<div align=\"right\">"; |
158 | echo popup_form("$CFG->wwwroot/mod/forum/", $forummenu, "forummenu", "", |
159 | get_string("movethisdiscussionto", "forum"), "", "", true); |
160 | echo "</div>"; |
161 | } |
162 | } |
163 | } |
02ebf404 |
164 | echo "</td></tr></table>"; |
1fc49f00 |
165 | |
8de14dc7 |
166 | if (isset($discussionmoved)) { |
167 | notify(get_string("discussionmoved", "forum", $forum->name)); |
168 | } |
169 | |
c6d691dc |
170 | |
171 | /// Print the actual discussion |
172 | |
173 | forum_print_discussion($course, $forum, $discussion, $post, $displaymode, $canreply); |
174 | |
501cdbd8 |
175 | |
176 | print_footer($course); |
177 | |
178 | ?> |