Check for existence of directory as well to avoid PHP warnings
[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
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)) {
31 set_field("forum_discussions", "forum", $forum->id, "id", $discussion->id);
32 $discussion->forum = $forum->id;
33 add_to_log($course->id, "forum", "move discussion", "discuss.php?d=$discussion->id", "$discussion->id");
8de14dc7 34 $discussionmoved = true;
1fc49f00 35 } else {
36 error("You can't move to that forum - it doesn't exist!");
37 }
38 }
39
40 if (empty($forum)) {
41 if (! $forum = get_record("forum", "id", $discussion->forum)) {
42 notify("Bad forum ID stored in this discussion");
43 }
501cdbd8 44 }
45
dfc9ba9b 46 if (!$cm = get_coursemodule_from_instance("forum", $forum->id, $course->id)) {
b20f74c9 47 //notify("Bad coursemodule for this discussion"); // Only affects navmenu
dfc9ba9b 48 }
49
1fc49f00 50 $logparameters = "d=$discussion->id";
51 if ($parent) {
52 $logparameters .= "&parent=$parent";
501cdbd8 53 }
1fc49f00 54 add_to_log($course->id, "forum", "view discussion", "discuss.php?$logparameters", "$discussion->id");
501cdbd8 55
56 unset($SESSION->fromdiscussion);
57
58 forum_set_display_mode($mode);
59
e92ea3d8 60 $displaymode = $USER->mode;
501cdbd8 61
e92ea3d8 62 if ($parent) {
63 if (abs($USER->mode) == 1) { // If flat AND parent, then force nested display this time
64 $displaymode = 3;
65 }
66 } else {
501cdbd8 67 $parent = $discussion->firstpost;
68 $navtail = "$discussion->name";
69 }
70
11b0c469 71 if (! $post = forum_get_post_full($parent)) {
501cdbd8 72 error("Discussion no longer exists", "$CFG->wwwroot/mod/forum/view.php?f=$forum->id");
73 }
74
61e96406 75 if (empty($navtail)) {
501cdbd8 76 $navtail = "<A HREF=\"discuss.php?d=$discussion->id\">$discussion->name</A> -> $post->subject";
77 }
78
f781b794 79 $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 80
9c9f7d77 81 $searchform = forum_print_search_form($course, "", true, "plain");
97485d07 82
501cdbd8 83 if ($course->category) {
84 print_header("$course->shortname: $discussion->name", "$course->fullname",
85 "<A HREF=../../course/view.php?id=$course->id>$course->shortname</A> ->
97485d07 86 $navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm));
501cdbd8 87 } else {
88 print_header("$course->shortname: $discussion->name", "$course->fullname",
97485d07 89 "$navmiddle -> $navtail", "", "", true, $searchform, navmenu($course, $cm));
501cdbd8 90 }
91
02ebf404 92 echo "<table width=\"100%\"><tr><td width=\"33%\">&nbsp;</td><td width=\"33%\">";
ec9c0d44 93 forum_print_mode_form($discussion->id, $displaymode);
02ebf404 94 echo "</td><td width=\"33%\">";
1fc49f00 95 if (isteacher($course->id)) { // Popup menu to allow discussions to be moved to other forums
cccb016a 96 if ($forums = get_all_instances_in_course("forum", $course)) {
1fc49f00 97 foreach ($forums as $courseforum) {
98 if ($courseforum->id != $forum->id) {
99 $url = "discuss.php?d=$discussion->id&move=$courseforum->id";
100 $forummenu[$url] = $courseforum->name;
101 }
102 }
103 if (!empty($forummenu)) {
104 echo "<div align=\"right\">";
105 echo popup_form("$CFG->wwwroot/mod/forum/", $forummenu, "forummenu", "",
106 get_string("movethisdiscussionto", "forum"), "", "", true);
107 echo "</div>";
108 }
109 }
110 }
02ebf404 111 echo "</td></tr></table>";
1fc49f00 112
8de14dc7 113 if (isset($discussionmoved)) {
114 notify(get_string("discussionmoved", "forum", $forum->name));
115 }
116
e92ea3d8 117 forum_print_discussion($course, $forum, $discussion, $post, $displaymode);
501cdbd8 118
119 print_footer($course);
120
121?>