I've recoded Farsi from Numeric Character References to Windows-1256
[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
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) {
66 $logparameters .= "&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)) {
501cdbd8 97 $navtail = "<A HREF=\"discuss.php?d=$discussion->id\">$discussion->name</A> -> $post->subject";
98 }
99
f781b794 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",
106 "<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> ->
97485d07 107 $navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm));
501cdbd8 108 } else {
109 print_header("$course->shortname: $discussion->name", "$course->fullname",
97485d07 110 "$navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm));
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
120 $groupmode = groupmode($course, $cm);
121
c6d691dc 122 if ($groupmode and !isteacheredit($course->id)) { // Groups must be kept separate
c6d691dc 123 if ($groupmode == SEPARATEGROUPS) {
124 require_login();
125
02509fe6 126 if (mygroupid($course->id) == $discussion->groupid) {
c6d691dc 127 $canreply = true;
128 } else {
129 print_heading("Sorry, you can't see this discussion because you are not in this group");
130 print_footer();
131 die;
132 }
133
134 } else if ($groupmode == VISIBLEGROUPS) {
02509fe6 135 $canreply = (mygroupid($course->id) == $discussion->groupid);
9197e147 136 }
137 }
138
139
c6d691dc 140/// Print the controls across the top
141
142 echo "<table width=\"100%\"><tr><td width=\"33%\">";
143
144 if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
145 if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
2ab76925 146 print_group_menu($groups, $groupmode, $discussion->groupid, "view.php?id=$cm->id&group=");
c6d691dc 147 }
148 }
149
150 echo "</td><td width=\"33%\">";
ec9c0d44 151 forum_print_mode_form($discussion->id, $displaymode);
c6d691dc 152
02ebf404 153 echo "</td><td width=\"33%\">";
1fc49f00 154 if (isteacher($course->id)) { // Popup menu to allow discussions to be moved to other forums
cccb016a 155 if ($forums = get_all_instances_in_course("forum", $course)) {
fcc69042 156 if ($course->format == 'weeks') {
157 $strsection = get_string("week");
158 } else {
159 $strsection = get_string("topic");
160 }
161 $section = -1;
1fc49f00 162 foreach ($forums as $courseforum) {
fcc69042 163 if (!empty($courseforum->section) and $section != $courseforum->section) {
164 $forummenu[] = "-------------- $strsection $courseforum->section --------------";
165 }
166 $section = $courseforum->section;
1fc49f00 167 if ($courseforum->id != $forum->id) {
168 $url = "discuss.php?d=$discussion->id&move=$courseforum->id";
169 $forummenu[$url] = $courseforum->name;
170 }
171 }
172 if (!empty($forummenu)) {
173 echo "<div align=\"right\">";
174 echo popup_form("$CFG->wwwroot/mod/forum/", $forummenu, "forummenu", "",
175 get_string("movethisdiscussionto", "forum"), "", "", true);
176 echo "</div>";
177 }
178 }
179 }
02ebf404 180 echo "</td></tr></table>";
1fc49f00 181
8de14dc7 182 if (isset($discussionmoved)) {
183 notify(get_string("discussionmoved", "forum", $forum->name));
184 }
185
c6d691dc 186
187/// Print the actual discussion
188
189 forum_print_discussion($course, $forum, $discussion, $post, $displaymode, $canreply);
190
501cdbd8 191
192 print_footer($course);
193
194?>