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