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