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